lapb_timer.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/errno.h>
  18. #include <linux/types.h>
  19. #include <linux/socket.h>
  20. #include <linux/in.h>
  21. #include <linux/kernel.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/timer.h>
  24. #include <linux/string.h>
  25. #include <linux/sockios.h>
  26. #include <linux/net.h>
  27. #include <linux/inet.h>
  28. #include <linux/skbuff.h>
  29. #include <net/sock.h>
  30. #include <linux/uaccess.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(struct timer_list *);
  36. static void lapb_t2timer_expiry(struct timer_list *);
  37. void lapb_start_t1timer(struct lapb_cb *lapb)
  38. {
  39. del_timer(&lapb->t1timer);
  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.function = lapb_t2timer_expiry;
  48. lapb->t2timer.expires = jiffies + lapb->t2;
  49. add_timer(&lapb->t2timer);
  50. }
  51. void lapb_stop_t1timer(struct lapb_cb *lapb)
  52. {
  53. del_timer(&lapb->t1timer);
  54. }
  55. void lapb_stop_t2timer(struct lapb_cb *lapb)
  56. {
  57. del_timer(&lapb->t2timer);
  58. }
  59. int lapb_t1timer_running(struct lapb_cb *lapb)
  60. {
  61. return timer_pending(&lapb->t1timer);
  62. }
  63. static void lapb_t2timer_expiry(struct timer_list *t)
  64. {
  65. struct lapb_cb *lapb = from_timer(lapb, t, t2timer);
  66. if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
  67. lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
  68. lapb_timeout_response(lapb);
  69. }
  70. }
  71. static void lapb_t1timer_expiry(struct timer_list *t)
  72. {
  73. struct lapb_cb *lapb = from_timer(lapb, t, t1timer);
  74. switch (lapb->state) {
  75. /*
  76. * If we are a DCE, keep going DM .. DM .. DM
  77. */
  78. case LAPB_STATE_0:
  79. if (lapb->mode & LAPB_DCE)
  80. lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
  81. break;
  82. /*
  83. * Awaiting connection state, send SABM(E), up to N2 times.
  84. */
  85. case LAPB_STATE_1:
  86. if (lapb->n2count == lapb->n2) {
  87. lapb_clear_queues(lapb);
  88. lapb->state = LAPB_STATE_0;
  89. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  90. lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
  91. return;
  92. } else {
  93. lapb->n2count++;
  94. if (lapb->mode & LAPB_EXTENDED) {
  95. lapb_dbg(1, "(%p) S1 TX SABME(1)\n",
  96. lapb->dev);
  97. lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
  98. } else {
  99. lapb_dbg(1, "(%p) S1 TX SABM(1)\n",
  100. lapb->dev);
  101. lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
  102. }
  103. }
  104. break;
  105. /*
  106. * Awaiting disconnection state, send DISC, up to N2 times.
  107. */
  108. case LAPB_STATE_2:
  109. if (lapb->n2count == lapb->n2) {
  110. lapb_clear_queues(lapb);
  111. lapb->state = LAPB_STATE_0;
  112. lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
  113. lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
  114. return;
  115. } else {
  116. lapb->n2count++;
  117. lapb_dbg(1, "(%p) S2 TX DISC(1)\n", lapb->dev);
  118. lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
  119. }
  120. break;
  121. /*
  122. * Data transfer state, restransmit I frames, up to N2 times.
  123. */
  124. case LAPB_STATE_3:
  125. if (lapb->n2count == lapb->n2) {
  126. lapb_clear_queues(lapb);
  127. lapb->state = LAPB_STATE_0;
  128. lapb_stop_t2timer(lapb);
  129. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  130. lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
  131. return;
  132. } else {
  133. lapb->n2count++;
  134. lapb_requeue_frames(lapb);
  135. lapb_kick(lapb);
  136. }
  137. break;
  138. /*
  139. * Frame reject state, restransmit FRMR frames, up to N2 times.
  140. */
  141. case LAPB_STATE_4:
  142. if (lapb->n2count == lapb->n2) {
  143. lapb_clear_queues(lapb);
  144. lapb->state = LAPB_STATE_0;
  145. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  146. lapb_dbg(0, "(%p) S4 -> S0\n", lapb->dev);
  147. return;
  148. } else {
  149. lapb->n2count++;
  150. lapb_transmit_frmr(lapb);
  151. }
  152. break;
  153. }
  154. lapb_start_t1timer(lapb);
  155. }