ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / irda / timer.c
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
27 #include <asm/system.h>
28 #include <linux/config.h>
29 #include <linux/delay.h>
30
31 #include <net/irda/timer.h>
32 #include <net/irda/irda.h>
33 #include <net/irda/irda_device.h>
34 #include <net/irda/irlap.h>
35 #include <net/irda/irlmp.h>
36
37 static void irlap_slot_timer_expired(void* data);
38 static void irlap_query_timer_expired(void* data);
39 static void irlap_final_timer_expired(void* data);
40 static void irlap_wd_timer_expired(void* data);
41 static void irlap_backoff_timer_expired(void* data);
42 static void irlap_media_busy_expired(void* data); 
43
44 void irlap_start_slot_timer(struct irlap_cb *self, int timeout)
45 {
46         irda_start_timer(&self->slot_timer, timeout, (void *) self, 
47                          irlap_slot_timer_expired);
48 }
49
50 void irlap_start_query_timer(struct irlap_cb *self, int timeout)
51 {
52         irda_start_timer( &self->query_timer, timeout, (void *) self, 
53                           irlap_query_timer_expired);
54 }
55
56 void irlap_start_final_timer(struct irlap_cb *self, int timeout)
57 {
58         irda_start_timer(&self->final_timer, timeout, (void *) self, 
59                          irlap_final_timer_expired);
60 }
61
62 void irlap_start_wd_timer(struct irlap_cb *self, int timeout)
63 {
64         irda_start_timer(&self->wd_timer, timeout, (void *) self, 
65                          irlap_wd_timer_expired);
66 }
67
68 void irlap_start_backoff_timer(struct irlap_cb *self, int timeout)
69 {
70         irda_start_timer(&self->backoff_timer, timeout, (void *) self, 
71                          irlap_backoff_timer_expired);
72 }
73
74 void irlap_start_mbusy_timer(struct irlap_cb *self, int timeout)
75 {
76         irda_start_timer(&self->media_busy_timer, timeout, 
77                          (void *) self, irlap_media_busy_expired);
78 }
79
80 void irlap_stop_mbusy_timer(struct irlap_cb *self)
81 {
82         /* If timer is activated, kill it! */
83         del_timer(&self->media_busy_timer);
84
85         /* If we are in NDM, there is a bunch of events in LAP that
86          * that be pending due to the media_busy condition, such as
87          * CONNECT_REQUEST and SEND_UI_FRAME. If we don't generate
88          * an event, they will wait forever...
89          * Jean II */
90         if (self->state == LAP_NDM)
91                 irlap_do_event(self, MEDIA_BUSY_TIMER_EXPIRED, NULL, NULL);
92 }
93
94 void irlmp_start_watchdog_timer(struct lsap_cb *self, int timeout) 
95 {
96         irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
97                          irlmp_watchdog_timer_expired);
98 }
99
100 void irlmp_start_discovery_timer(struct irlmp_cb *self, int timeout) 
101 {
102         irda_start_timer(&self->discovery_timer, timeout, (void *) self,
103                          irlmp_discovery_timer_expired);
104 }
105
106 void irlmp_start_idle_timer(struct lap_cb *self, int timeout) 
107 {
108         irda_start_timer(&self->idle_timer, timeout, (void *) self,
109                          irlmp_idle_timer_expired);
110 }
111
112 void irlmp_stop_idle_timer(struct lap_cb *self) 
113 {
114         /* If timer is activated, kill it! */
115         del_timer(&self->idle_timer);
116 }
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
128         ASSERT(self != NULL, return;);
129         ASSERT(self->magic == LAP_MAGIC, return;);
130
131         irlap_do_event(self, SLOT_TIMER_EXPIRED, NULL, NULL);
132
133
134 /*
135  * Function irlap_query_timer_expired (data)
136  *
137  *    IrLAP query timer has expired
138  *
139  */
140 static void irlap_query_timer_expired(void *data)
141 {
142         struct irlap_cb *self = (struct irlap_cb *) data;
143
144         ASSERT(self != NULL, return;);
145         ASSERT(self->magic == LAP_MAGIC, return;);
146
147         irlap_do_event(self, QUERY_TIMER_EXPIRED, NULL, NULL);
148
149
150 /*
151  * Function irda_final_timer_expired (data)
152  *
153  *    
154  *
155  */
156 static void irlap_final_timer_expired(void *data)
157 {
158         struct irlap_cb *self = (struct irlap_cb *) data;
159
160         ASSERT(self != NULL, return;);
161         ASSERT(self->magic == LAP_MAGIC, return;);
162
163         irlap_do_event(self, FINAL_TIMER_EXPIRED, NULL, NULL);
164 }
165
166 /*
167  * Function irda_wd_timer_expired (data)
168  *
169  *    
170  *
171  */
172 static void irlap_wd_timer_expired(void *data)
173 {
174         struct irlap_cb *self = (struct irlap_cb *) data;
175         
176         ASSERT(self != NULL, return;);
177         ASSERT(self->magic == LAP_MAGIC, return;);
178         
179         irlap_do_event(self, WD_TIMER_EXPIRED, NULL, NULL);
180 }
181
182 /*
183  * Function irda_backoff_timer_expired (data)
184  *
185  *    
186  *
187  */
188 static void irlap_backoff_timer_expired(void *data)
189 {
190         struct irlap_cb *self = (struct irlap_cb *) data;
191         
192         ASSERT(self != NULL, return;);
193         ASSERT(self->magic == LAP_MAGIC, return;);
194         
195         irlap_do_event(self, BACKOFF_TIMER_EXPIRED, NULL, NULL);
196 }
197
198
199 /*
200  * Function irtty_media_busy_expired (data)
201  *
202  *    
203  */
204 void irlap_media_busy_expired(void* data)
205 {
206         struct irlap_cb *self = (struct irlap_cb *) data;
207
208         ASSERT(self != NULL, return;);
209
210         irda_device_set_media_busy(self->netdev, FALSE);
211         /* Note : the LAP event will be send in irlap_stop_mbusy_timer(),
212         * to catch other cases where the flag is cleared (for example
213         * after a discovery) - Jean II */
214 }