ax25_timer.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Copyright (C) Alan Cox GW4PTS ([email protected])
  5. * Copyright (C) Jonathan Naylor G4KLX ([email protected])
  6. * Copyright (C) Tomi Manninen OH2BNS ([email protected])
  7. * Copyright (C) Darryl Miles G7LED ([email protected])
  8. * Copyright (C) Joerg Reuter DL1BKE ([email protected])
  9. * Copyright (C) Frederic Rible F1OAT ([email protected])
  10. * Copyright (C) 2002 Ralf Baechle DO1GRB ([email protected])
  11. */
  12. #include <linux/errno.h>
  13. #include <linux/types.h>
  14. #include <linux/socket.h>
  15. #include <linux/in.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/timer.h>
  20. #include <linux/string.h>
  21. #include <linux/sockios.h>
  22. #include <linux/net.h>
  23. #include <net/ax25.h>
  24. #include <linux/inet.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/skbuff.h>
  27. #include <net/sock.h>
  28. #include <linux/uaccess.h>
  29. #include <linux/fcntl.h>
  30. #include <linux/mm.h>
  31. #include <linux/interrupt.h>
  32. static void ax25_heartbeat_expiry(struct timer_list *);
  33. static void ax25_t1timer_expiry(struct timer_list *);
  34. static void ax25_t2timer_expiry(struct timer_list *);
  35. static void ax25_t3timer_expiry(struct timer_list *);
  36. static void ax25_idletimer_expiry(struct timer_list *);
  37. void ax25_setup_timers(ax25_cb *ax25)
  38. {
  39. timer_setup(&ax25->timer, ax25_heartbeat_expiry, 0);
  40. timer_setup(&ax25->t1timer, ax25_t1timer_expiry, 0);
  41. timer_setup(&ax25->t2timer, ax25_t2timer_expiry, 0);
  42. timer_setup(&ax25->t3timer, ax25_t3timer_expiry, 0);
  43. timer_setup(&ax25->idletimer, ax25_idletimer_expiry, 0);
  44. }
  45. void ax25_start_heartbeat(ax25_cb *ax25)
  46. {
  47. mod_timer(&ax25->timer, jiffies + 5 * HZ);
  48. }
  49. void ax25_start_t1timer(ax25_cb *ax25)
  50. {
  51. mod_timer(&ax25->t1timer, jiffies + ax25->t1);
  52. }
  53. void ax25_start_t2timer(ax25_cb *ax25)
  54. {
  55. mod_timer(&ax25->t2timer, jiffies + ax25->t2);
  56. }
  57. void ax25_start_t3timer(ax25_cb *ax25)
  58. {
  59. if (ax25->t3 > 0)
  60. mod_timer(&ax25->t3timer, jiffies + ax25->t3);
  61. else
  62. del_timer(&ax25->t3timer);
  63. }
  64. void ax25_start_idletimer(ax25_cb *ax25)
  65. {
  66. if (ax25->idle > 0)
  67. mod_timer(&ax25->idletimer, jiffies + ax25->idle);
  68. else
  69. del_timer(&ax25->idletimer);
  70. }
  71. void ax25_stop_heartbeat(ax25_cb *ax25)
  72. {
  73. del_timer(&ax25->timer);
  74. }
  75. void ax25_stop_t1timer(ax25_cb *ax25)
  76. {
  77. del_timer(&ax25->t1timer);
  78. }
  79. void ax25_stop_t2timer(ax25_cb *ax25)
  80. {
  81. del_timer(&ax25->t2timer);
  82. }
  83. void ax25_stop_t3timer(ax25_cb *ax25)
  84. {
  85. del_timer(&ax25->t3timer);
  86. }
  87. void ax25_stop_idletimer(ax25_cb *ax25)
  88. {
  89. del_timer(&ax25->idletimer);
  90. }
  91. int ax25_t1timer_running(ax25_cb *ax25)
  92. {
  93. return timer_pending(&ax25->t1timer);
  94. }
  95. unsigned long ax25_display_timer(struct timer_list *timer)
  96. {
  97. long delta = timer->expires - jiffies;
  98. if (!timer_pending(timer))
  99. return 0;
  100. return max(0L, delta);
  101. }
  102. EXPORT_SYMBOL(ax25_display_timer);
  103. static void ax25_heartbeat_expiry(struct timer_list *t)
  104. {
  105. int proto = AX25_PROTO_STD_SIMPLEX;
  106. ax25_cb *ax25 = from_timer(ax25, t, timer);
  107. if (ax25->ax25_dev)
  108. proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
  109. switch (proto) {
  110. case AX25_PROTO_STD_SIMPLEX:
  111. case AX25_PROTO_STD_DUPLEX:
  112. ax25_std_heartbeat_expiry(ax25);
  113. break;
  114. #ifdef CONFIG_AX25_DAMA_SLAVE
  115. case AX25_PROTO_DAMA_SLAVE:
  116. if (ax25->ax25_dev->dama.slave)
  117. ax25_ds_heartbeat_expiry(ax25);
  118. else
  119. ax25_std_heartbeat_expiry(ax25);
  120. break;
  121. #endif
  122. }
  123. }
  124. static void ax25_t1timer_expiry(struct timer_list *t)
  125. {
  126. ax25_cb *ax25 = from_timer(ax25, t, t1timer);
  127. switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
  128. case AX25_PROTO_STD_SIMPLEX:
  129. case AX25_PROTO_STD_DUPLEX:
  130. ax25_std_t1timer_expiry(ax25);
  131. break;
  132. #ifdef CONFIG_AX25_DAMA_SLAVE
  133. case AX25_PROTO_DAMA_SLAVE:
  134. if (!ax25->ax25_dev->dama.slave)
  135. ax25_std_t1timer_expiry(ax25);
  136. break;
  137. #endif
  138. }
  139. }
  140. static void ax25_t2timer_expiry(struct timer_list *t)
  141. {
  142. ax25_cb *ax25 = from_timer(ax25, t, t2timer);
  143. switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
  144. case AX25_PROTO_STD_SIMPLEX:
  145. case AX25_PROTO_STD_DUPLEX:
  146. ax25_std_t2timer_expiry(ax25);
  147. break;
  148. #ifdef CONFIG_AX25_DAMA_SLAVE
  149. case AX25_PROTO_DAMA_SLAVE:
  150. if (!ax25->ax25_dev->dama.slave)
  151. ax25_std_t2timer_expiry(ax25);
  152. break;
  153. #endif
  154. }
  155. }
  156. static void ax25_t3timer_expiry(struct timer_list *t)
  157. {
  158. ax25_cb *ax25 = from_timer(ax25, t, t3timer);
  159. switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
  160. case AX25_PROTO_STD_SIMPLEX:
  161. case AX25_PROTO_STD_DUPLEX:
  162. ax25_std_t3timer_expiry(ax25);
  163. break;
  164. #ifdef CONFIG_AX25_DAMA_SLAVE
  165. case AX25_PROTO_DAMA_SLAVE:
  166. if (ax25->ax25_dev->dama.slave)
  167. ax25_ds_t3timer_expiry(ax25);
  168. else
  169. ax25_std_t3timer_expiry(ax25);
  170. break;
  171. #endif
  172. }
  173. }
  174. static void ax25_idletimer_expiry(struct timer_list *t)
  175. {
  176. ax25_cb *ax25 = from_timer(ax25, t, idletimer);
  177. switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
  178. case AX25_PROTO_STD_SIMPLEX:
  179. case AX25_PROTO_STD_DUPLEX:
  180. ax25_std_idletimer_expiry(ax25);
  181. break;
  182. #ifdef CONFIG_AX25_DAMA_SLAVE
  183. case AX25_PROTO_DAMA_SLAVE:
  184. if (ax25->ax25_dev->dama.slave)
  185. ax25_ds_idletimer_expiry(ax25);
  186. else
  187. ax25_std_idletimer_expiry(ax25);
  188. break;
  189. #endif
  190. }
  191. }