lapb_timer.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 <asm/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(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. lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
  93. return;
  94. } else {
  95. lapb->n2count++;
  96. if (lapb->mode & LAPB_EXTENDED) {
  97. lapb_dbg(1, "(%p) S1 TX SABME(1)\n",
  98. lapb->dev);
  99. lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
  100. } else {
  101. lapb_dbg(1, "(%p) S1 TX SABM(1)\n",
  102. lapb->dev);
  103. lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
  104. }
  105. }
  106. break;
  107. /*
  108. * Awaiting disconnection state, send DISC, up to N2 times.
  109. */
  110. case LAPB_STATE_2:
  111. if (lapb->n2count == lapb->n2) {
  112. lapb_clear_queues(lapb);
  113. lapb->state = LAPB_STATE_0;
  114. lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
  115. lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
  116. return;
  117. } else {
  118. lapb->n2count++;
  119. lapb_dbg(1, "(%p) S2 TX DISC(1)\n", lapb->dev);
  120. lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
  121. }
  122. break;
  123. /*
  124. * Data transfer state, restransmit I frames, up to N2 times.
  125. */
  126. case LAPB_STATE_3:
  127. if (lapb->n2count == lapb->n2) {
  128. lapb_clear_queues(lapb);
  129. lapb->state = LAPB_STATE_0;
  130. lapb_stop_t2timer(lapb);
  131. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  132. lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
  133. return;
  134. } else {
  135. lapb->n2count++;
  136. lapb_requeue_frames(lapb);
  137. lapb_kick(lapb);
  138. }
  139. break;
  140. /*
  141. * Frame reject state, restransmit FRMR frames, up to N2 times.
  142. */
  143. case LAPB_STATE_4:
  144. if (lapb->n2count == lapb->n2) {
  145. lapb_clear_queues(lapb);
  146. lapb->state = LAPB_STATE_0;
  147. lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
  148. lapb_dbg(0, "(%p) S4 -> S0\n", lapb->dev);
  149. return;
  150. } else {
  151. lapb->n2count++;
  152. lapb_transmit_frmr(lapb);
  153. }
  154. break;
  155. }
  156. lapb_start_t1timer(lapb);
  157. }