timer.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*********************************************************************
  2. *
  3. * Filename: timer.c
  4. * Version:
  5. * Description:
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Sat Aug 16 00:59:29 1997
  9. * Modified at: Wed Dec 8 12:50:34 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1997, 1999 Dag Brattli <dagb@cs.uit.no>,
  13. * All Rights Reserved.
  14. * Copyright (c) 2000-2002 Jean Tourrilhes <jt@hpl.hp.com>
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * Neither Dag Brattli nor University of Tromsø admit liability nor
  22. * provide warranty for any of this software. This material is
  23. * provided "AS-IS" and at no charge.
  24. *
  25. ********************************************************************/
  26. #include <asm/system.h>
  27. #include <linux/config.h>
  28. #include <linux/delay.h>
  29. #include <net/irda/timer.h>
  30. #include <net/irda/irda.h>
  31. #include <net/irda/irda_device.h>
  32. #include <net/irda/irlap.h>
  33. #include <net/irda/irlmp.h>
  34. extern int sysctl_slot_timeout;
  35. static void irlap_slot_timer_expired(void* data);
  36. static void irlap_query_timer_expired(void* data);
  37. static void irlap_final_timer_expired(void* data);
  38. static void irlap_wd_timer_expired(void* data);
  39. static void irlap_backoff_timer_expired(void* data);
  40. static void irlap_media_busy_expired(void* data);
  41. void irlap_start_slot_timer(struct irlap_cb *self, int timeout)
  42. {
  43. irda_start_timer(&self->slot_timer, timeout, (void *) self,
  44. irlap_slot_timer_expired);
  45. }
  46. void irlap_start_query_timer(struct irlap_cb *self, int S, int s)
  47. {
  48. int timeout;
  49. /* Calculate when the peer discovery should end. Normally, we
  50. * get the end-of-discovery frame, so this is just in case
  51. * we miss it.
  52. * Basically, we multiply the number of remaining slots by our
  53. * slot time, plus add some extra time to properly receive the last
  54. * discovery packet (which is longer due to extra discovery info),
  55. * to avoid messing with for incomming connections requests and
  56. * to accomodate devices that perform discovery slower than us.
  57. * Jean II */
  58. timeout = ((sysctl_slot_timeout * HZ / 1000) * (S - s)
  59. + XIDEXTRA_TIMEOUT + SMALLBUSY_TIMEOUT);
  60. /* Set or re-set the timer. We reset the timer for each received
  61. * discovery query, which allow us to automatically adjust to
  62. * the speed of the peer discovery (faster or slower). Jean II */
  63. irda_start_timer( &self->query_timer, timeout, (void *) self,
  64. irlap_query_timer_expired);
  65. }
  66. void irlap_start_final_timer(struct irlap_cb *self, int timeout)
  67. {
  68. irda_start_timer(&self->final_timer, timeout, (void *) self,
  69. irlap_final_timer_expired);
  70. }
  71. void irlap_start_wd_timer(struct irlap_cb *self, int timeout)
  72. {
  73. irda_start_timer(&self->wd_timer, timeout, (void *) self,
  74. irlap_wd_timer_expired);
  75. }
  76. void irlap_start_backoff_timer(struct irlap_cb *self, int timeout)
  77. {
  78. irda_start_timer(&self->backoff_timer, timeout, (void *) self,
  79. irlap_backoff_timer_expired);
  80. }
  81. void irlap_start_mbusy_timer(struct irlap_cb *self, int timeout)
  82. {
  83. irda_start_timer(&self->media_busy_timer, timeout,
  84. (void *) self, irlap_media_busy_expired);
  85. }
  86. void irlap_stop_mbusy_timer(struct irlap_cb *self)
  87. {
  88. /* If timer is activated, kill it! */
  89. del_timer(&self->media_busy_timer);
  90. /* If we are in NDM, there is a bunch of events in LAP that
  91. * that be pending due to the media_busy condition, such as
  92. * CONNECT_REQUEST and SEND_UI_FRAME. If we don't generate
  93. * an event, they will wait forever...
  94. * Jean II */
  95. if (self->state == LAP_NDM)
  96. irlap_do_event(self, MEDIA_BUSY_TIMER_EXPIRED, NULL, NULL);
  97. }
  98. void irlmp_start_watchdog_timer(struct lsap_cb *self, int timeout)
  99. {
  100. irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
  101. irlmp_watchdog_timer_expired);
  102. }
  103. void irlmp_start_discovery_timer(struct irlmp_cb *self, int timeout)
  104. {
  105. irda_start_timer(&self->discovery_timer, timeout, (void *) self,
  106. irlmp_discovery_timer_expired);
  107. }
  108. void irlmp_start_idle_timer(struct lap_cb *self, int timeout)
  109. {
  110. irda_start_timer(&self->idle_timer, timeout, (void *) self,
  111. irlmp_idle_timer_expired);
  112. }
  113. void irlmp_stop_idle_timer(struct lap_cb *self)
  114. {
  115. /* If timer is activated, kill it! */
  116. del_timer(&self->idle_timer);
  117. }
  118. /*
  119. * Function irlap_slot_timer_expired (data)
  120. *
  121. * IrLAP slot timer has expired
  122. *
  123. */
  124. static void irlap_slot_timer_expired(void *data)
  125. {
  126. struct irlap_cb *self = (struct irlap_cb *) data;
  127. IRDA_ASSERT(self != NULL, return;);
  128. IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
  129. irlap_do_event(self, SLOT_TIMER_EXPIRED, NULL, NULL);
  130. }
  131. /*
  132. * Function irlap_query_timer_expired (data)
  133. *
  134. * IrLAP query timer has expired
  135. *
  136. */
  137. static void irlap_query_timer_expired(void *data)
  138. {
  139. struct irlap_cb *self = (struct irlap_cb *) data;
  140. IRDA_ASSERT(self != NULL, return;);
  141. IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
  142. irlap_do_event(self, QUERY_TIMER_EXPIRED, NULL, NULL);
  143. }
  144. /*
  145. * Function irda_final_timer_expired (data)
  146. *
  147. *
  148. *
  149. */
  150. static void irlap_final_timer_expired(void *data)
  151. {
  152. struct irlap_cb *self = (struct irlap_cb *) data;
  153. IRDA_ASSERT(self != NULL, return;);
  154. IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
  155. irlap_do_event(self, FINAL_TIMER_EXPIRED, NULL, NULL);
  156. }
  157. /*
  158. * Function irda_wd_timer_expired (data)
  159. *
  160. *
  161. *
  162. */
  163. static void irlap_wd_timer_expired(void *data)
  164. {
  165. struct irlap_cb *self = (struct irlap_cb *) data;
  166. IRDA_ASSERT(self != NULL, return;);
  167. IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
  168. irlap_do_event(self, WD_TIMER_EXPIRED, NULL, NULL);
  169. }
  170. /*
  171. * Function irda_backoff_timer_expired (data)
  172. *
  173. *
  174. *
  175. */
  176. static void irlap_backoff_timer_expired(void *data)
  177. {
  178. struct irlap_cb *self = (struct irlap_cb *) data;
  179. IRDA_ASSERT(self != NULL, return;);
  180. IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
  181. irlap_do_event(self, BACKOFF_TIMER_EXPIRED, NULL, NULL);
  182. }
  183. /*
  184. * Function irtty_media_busy_expired (data)
  185. *
  186. *
  187. */
  188. void irlap_media_busy_expired(void* data)
  189. {
  190. struct irlap_cb *self = (struct irlap_cb *) data;
  191. IRDA_ASSERT(self != NULL, return;);
  192. irda_device_set_media_busy(self->netdev, FALSE);
  193. /* Note : the LAP event will be send in irlap_stop_mbusy_timer(),
  194. * to catch other cases where the flag is cleared (for example
  195. * after a discovery) - Jean II */
  196. }