lapb_timer.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * LAPB release 002
  3. *
  4. * This code REQUIRES 2.1.15 or higher/ NET3.038
  5. *
  6. * This module:
  7. * This module is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * History
  13. * LAPB 001 Jonathan Naylor Started Coding
  14. * LAPB 002 Jonathan Naylor New timer architecture.
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/types.h>
  18. #include <linux/socket.h>
  19. #include <linux/in.h>
  20. #include <linux/kernel.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/timer.h>
  23. #include <linux/string.h>
  24. #include <linux/sockios.h>
  25. #include <linux/net.h>
  26. #include <linux/inet.h>
  27. #include <linux/skbuff.h>
  28. #include <net/sock.h>
  29. #include <asm/uaccess.h>
  30. #include <linux/fcntl.h>
  31. #include <linux/mm.h>
  32. #include <linux/interrupt.h>
  33. #include <net/lapb.h>
  34. static void lapb_t1timer_expiry(unsigned long);
  35. static void lapb_t2timer_expiry(unsigned long);
  36. void lapb_start_t1timer(struct lapb_cb *lapb)
  37. {
  38. del_timer(&lapb->t1timer);
  39. lapb->t1timer.data = (unsigned long)lapb;
  40. lapb->t1timer.function = &lapb_t1timer_expiry;
  41. lapb->t1timer.expires = jiffies + lapb->t1;
  42. add_timer(&lapb->t1timer);
  43. }
  44. void lapb_start_t2timer(struct lapb_cb *lapb)
  45. {
  46. del_timer(&lapb->t2timer);
  47. lapb->t2timer.data = (unsigned long)lapb;
  48. lapb->t2timer.function = &lapb_t2timer_expiry;
  49. lapb->t2timer.expires = jiffies + lapb->t2;
  50. add_timer(&lapb->t2timer);
  51. }
  52. void lapb_stop_t1timer(struct lapb_cb *lapb)
  53. {
  54. del_timer(&lapb->t1timer);
  55. }
  56. void lapb_stop_t2timer(struct lapb_cb *lapb)
  57. {
  58. del_timer(&lapb->t2timer);
  59. }
  60. int lapb_t1timer_running(struct lapb_cb *lapb)
  61. {
  62. return timer_pending(&lapb->t1timer);
  63. }
  64. static void lapb_t2timer_expiry(unsigned long param)
  65. {
  66. struct lapb_cb *lapb = (struct lapb_cb *)param;
  67. if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
  68. lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
  69. lapb_timeout_response(lapb);
  70. }
  71. }
  72. static void lapb_t1timer_expiry(unsigned long param)
  73. {
  74. struct lapb_cb *lapb = (struct lapb_cb *)param;
  75. switch (lapb->state) {
  76. /*
  77. * If we are a DCE, keep going DM .. DM .. DM
  78. */
  79. case LAPB_STATE_0:
  80. if (lapb->mode & LAPB_DCE)
  81. lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
  82. break;
  83. /*
  84. * Awaiting connection state, send SABM(E), up to N2 times.
  85. */
  86. case LAPB_STATE_1:
  87. if (lapb->n2count == lapb->n2) {
  88. lapb_clear_queues(lapb);
  89. lapb->state = LAPB_STATE_0;
  90. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  91. #if LAPB_DEBUG > 0
  92. printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->dev);
  93. #endif
  94. return;
  95. } else {
  96. lapb->n2count++;
  97. if (lapb->mode & LAPB_EXTENDED) {
  98. #if LAPB_DEBUG > 1
  99. printk(KERN_DEBUG "lapb: (%p) S1 TX SABME(1)\n", lapb->dev);
  100. #endif
  101. lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
  102. } else {
  103. #if LAPB_DEBUG > 1
  104. printk(KERN_DEBUG "lapb: (%p) S1 TX SABM(1)\n", lapb->dev);
  105. #endif
  106. lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
  107. }
  108. }
  109. break;
  110. /*
  111. * Awaiting disconnection state, send DISC, up to N2 times.
  112. */
  113. case LAPB_STATE_2:
  114. if (lapb->n2count == lapb->n2) {
  115. lapb_clear_queues(lapb);
  116. lapb->state = LAPB_STATE_0;
  117. lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
  118. #if LAPB_DEBUG > 0
  119. printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
  120. #endif
  121. return;
  122. } else {
  123. lapb->n2count++;
  124. #if LAPB_DEBUG > 1
  125. printk(KERN_DEBUG "lapb: (%p) S2 TX DISC(1)\n", lapb->dev);
  126. #endif
  127. lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
  128. }
  129. break;
  130. /*
  131. * Data transfer state, restransmit I frames, up to N2 times.
  132. */
  133. case LAPB_STATE_3:
  134. if (lapb->n2count == lapb->n2) {
  135. lapb_clear_queues(lapb);
  136. lapb->state = LAPB_STATE_0;
  137. lapb_stop_t2timer(lapb);
  138. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  139. #if LAPB_DEBUG > 0
  140. printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
  141. #endif
  142. return;
  143. } else {
  144. lapb->n2count++;
  145. lapb_requeue_frames(lapb);
  146. }
  147. break;
  148. /*
  149. * Frame reject state, restransmit FRMR frames, up to N2 times.
  150. */
  151. case LAPB_STATE_4:
  152. if (lapb->n2count == lapb->n2) {
  153. lapb_clear_queues(lapb);
  154. lapb->state = LAPB_STATE_0;
  155. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  156. #if LAPB_DEBUG > 0
  157. printk(KERN_DEBUG "lapb: (%p) S4 -> S0\n", lapb->dev);
  158. #endif
  159. return;
  160. } else {
  161. lapb->n2count++;
  162. lapb_transmit_frmr(lapb);
  163. }
  164. break;
  165. }
  166. lapb_start_t1timer(lapb);
  167. }