lapb_timer.c 4.5 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 <asm/system.h>
  31. #include <linux/fcntl.h>
  32. #include <linux/mm.h>
  33. #include <linux/interrupt.h>
  34. #include <net/lapb.h>
  35. static void lapb_t1timer_expiry(unsigned long);
  36. static void lapb_t2timer_expiry(unsigned long);
  37. void lapb_start_t1timer(struct lapb_cb *lapb)
  38. {
  39. del_timer(&lapb->t1timer);
  40. lapb->t1timer.data = (unsigned long)lapb;
  41. lapb->t1timer.function = &lapb_t1timer_expiry;
  42. lapb->t1timer.expires = jiffies + lapb->t1;
  43. add_timer(&lapb->t1timer);
  44. }
  45. void lapb_start_t2timer(struct lapb_cb *lapb)
  46. {
  47. del_timer(&lapb->t2timer);
  48. lapb->t2timer.data = (unsigned long)lapb;
  49. lapb->t2timer.function = &lapb_t2timer_expiry;
  50. lapb->t2timer.expires = jiffies + lapb->t2;
  51. add_timer(&lapb->t2timer);
  52. }
  53. void lapb_stop_t1timer(struct lapb_cb *lapb)
  54. {
  55. del_timer(&lapb->t1timer);
  56. }
  57. void lapb_stop_t2timer(struct lapb_cb *lapb)
  58. {
  59. del_timer(&lapb->t2timer);
  60. }
  61. int lapb_t1timer_running(struct lapb_cb *lapb)
  62. {
  63. return timer_pending(&lapb->t1timer);
  64. }
  65. static void lapb_t2timer_expiry(unsigned long param)
  66. {
  67. struct lapb_cb *lapb = (struct lapb_cb *)param;
  68. if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
  69. lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
  70. lapb_timeout_response(lapb);
  71. }
  72. }
  73. static void lapb_t1timer_expiry(unsigned long param)
  74. {
  75. struct lapb_cb *lapb = (struct lapb_cb *)param;
  76. switch (lapb->state) {
  77. /*
  78. * If we are a DCE, keep going DM .. DM .. DM
  79. */
  80. case LAPB_STATE_0:
  81. if (lapb->mode & LAPB_DCE)
  82. lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
  83. break;
  84. /*
  85. * Awaiting connection state, send SABM(E), up to N2 times.
  86. */
  87. case LAPB_STATE_1:
  88. if (lapb->n2count == lapb->n2) {
  89. lapb_clear_queues(lapb);
  90. lapb->state = LAPB_STATE_0;
  91. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  92. #if LAPB_DEBUG > 0
  93. printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->dev);
  94. #endif
  95. return;
  96. } else {
  97. lapb->n2count++;
  98. if (lapb->mode & LAPB_EXTENDED) {
  99. #if LAPB_DEBUG > 1
  100. printk(KERN_DEBUG "lapb: (%p) S1 TX SABME(1)\n", lapb->dev);
  101. #endif
  102. lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
  103. } else {
  104. #if LAPB_DEBUG > 1
  105. printk(KERN_DEBUG "lapb: (%p) S1 TX SABM(1)\n", lapb->dev);
  106. #endif
  107. lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
  108. }
  109. }
  110. break;
  111. /*
  112. * Awaiting disconnection state, send DISC, up to N2 times.
  113. */
  114. case LAPB_STATE_2:
  115. if (lapb->n2count == lapb->n2) {
  116. lapb_clear_queues(lapb);
  117. lapb->state = LAPB_STATE_0;
  118. lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
  119. #if LAPB_DEBUG > 0
  120. printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
  121. #endif
  122. return;
  123. } else {
  124. lapb->n2count++;
  125. #if LAPB_DEBUG > 1
  126. printk(KERN_DEBUG "lapb: (%p) S2 TX DISC(1)\n", lapb->dev);
  127. #endif
  128. lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
  129. }
  130. break;
  131. /*
  132. * Data transfer state, restransmit I frames, up to N2 times.
  133. */
  134. case LAPB_STATE_3:
  135. if (lapb->n2count == lapb->n2) {
  136. lapb_clear_queues(lapb);
  137. lapb->state = LAPB_STATE_0;
  138. lapb_stop_t2timer(lapb);
  139. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  140. #if LAPB_DEBUG > 0
  141. printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
  142. #endif
  143. return;
  144. } else {
  145. lapb->n2count++;
  146. lapb_requeue_frames(lapb);
  147. }
  148. break;
  149. /*
  150. * Frame reject state, restransmit FRMR frames, up to N2 times.
  151. */
  152. case LAPB_STATE_4:
  153. if (lapb->n2count == lapb->n2) {
  154. lapb_clear_queues(lapb);
  155. lapb->state = LAPB_STATE_0;
  156. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  157. #if LAPB_DEBUG > 0
  158. printk(KERN_DEBUG "lapb: (%p) S4 -> S0\n", lapb->dev);
  159. #endif
  160. return;
  161. } else {
  162. lapb->n2count++;
  163. lapb_transmit_frmr(lapb);
  164. }
  165. break;
  166. }
  167. lapb_start_t1timer(lapb);
  168. }