import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.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-2001 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/irtty.h>
34 #include <net/irda/irlap.h>
35 #include <net/irda/irlmp_event.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
43 static void irlap_media_busy_expired(void* data); 
44 /*
45  * Function irda_start_timer (timer, timeout)
46  *
47  *    Start an IrDA timer
48  *
49  */
50 void irda_start_timer(struct timer_list *ptimer, int timeout, void *data,
51                       TIMER_CALLBACK callback) 
52 {
53         del_timer(ptimer);
54  
55         ptimer->data = (unsigned long) data;
56
57         /* 
58          * For most architectures void * is the same as unsigned long, but
59          * at least we try to use void * as long as possible. Since the 
60          * timer functions use unsigned long, we cast the function here
61          */
62         ptimer->function = (void (*)(unsigned long)) callback;
63         ptimer->expires = jiffies + timeout;
64         
65         add_timer(ptimer);
66 }
67
68 void irlap_start_slot_timer(struct irlap_cb *self, int timeout)
69 {
70         irda_start_timer(&self->slot_timer, timeout, (void *) self, 
71                          irlap_slot_timer_expired);
72 }
73
74 void irlap_start_query_timer(struct irlap_cb *self, int timeout)
75 {
76         irda_start_timer( &self->query_timer, timeout, (void *) self, 
77                           irlap_query_timer_expired);
78 }
79
80 void irlap_start_final_timer(struct irlap_cb *self, int timeout)
81 {
82         irda_start_timer(&self->final_timer, timeout, (void *) self, 
83                          irlap_final_timer_expired);
84 }
85
86 void irlap_start_wd_timer(struct irlap_cb *self, int timeout)
87 {
88         irda_start_timer(&self->wd_timer, timeout, (void *) self, 
89                          irlap_wd_timer_expired);
90 }
91
92 void irlap_start_backoff_timer(struct irlap_cb *self, int timeout)
93 {
94         irda_start_timer(&self->backoff_timer, timeout, (void *) self, 
95                          irlap_backoff_timer_expired);
96 }
97
98 void irlap_start_mbusy_timer(struct irlap_cb *self, int timeout)
99 {
100         irda_start_timer(&self->media_busy_timer, timeout, 
101                          (void *) self, irlap_media_busy_expired);
102 }
103
104 void irlap_stop_mbusy_timer(struct irlap_cb *self)
105 {
106         /* If timer is activated, kill it! */
107         del_timer(&self->media_busy_timer);
108
109         /* If we are in NDM, there is a bunch of events in LAP that
110          * that be pending due to the media_busy condition, such as
111          * CONNECT_REQUEST and SEND_UI_FRAME. If we don't generate
112          * an event, they will wait forever...
113          * Jean II */
114         if (self->state == LAP_NDM)
115                 irlap_do_event(self, MEDIA_BUSY_TIMER_EXPIRED, NULL, NULL);
116 }
117
118 void irlmp_start_watchdog_timer(struct lsap_cb *self, int timeout) 
119 {
120         irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
121                          irlmp_watchdog_timer_expired);
122 }
123
124 void irlmp_start_discovery_timer(struct irlmp_cb *self, int timeout) 
125 {
126         irda_start_timer(&self->discovery_timer, timeout, (void *) self,
127                          irlmp_discovery_timer_expired);
128 }
129
130 void irlmp_start_idle_timer(struct lap_cb *self, int timeout) 
131 {
132         irda_start_timer(&self->idle_timer, timeout, (void *) self,
133                          irlmp_idle_timer_expired);
134 }
135
136 void irlmp_stop_idle_timer(struct lap_cb *self) 
137 {
138         /* If timer is activated, kill it! */
139         if(timer_pending(&self->idle_timer))
140                 del_timer(&self->idle_timer);
141 }
142
143 /*
144  * Function irlap_slot_timer_expired (data)
145  *
146  *    IrLAP slot timer has expired
147  *
148  */
149 static void irlap_slot_timer_expired(void *data)
150 {
151         struct irlap_cb *self = (struct irlap_cb *) data;
152
153         ASSERT(self != NULL, return;);
154         ASSERT(self->magic == LAP_MAGIC, return;);
155
156         irlap_do_event(self, SLOT_TIMER_EXPIRED, NULL, NULL);
157
158
159 /*
160  * Function irlap_query_timer_expired (data)
161  *
162  *    IrLAP query timer has expired
163  *
164  */
165 static void irlap_query_timer_expired(void *data)
166 {
167         struct irlap_cb *self = (struct irlap_cb *) data;
168
169         ASSERT(self != NULL, return;);
170         ASSERT(self->magic == LAP_MAGIC, return;);
171
172         irlap_do_event(self, QUERY_TIMER_EXPIRED, NULL, NULL);
173
174
175 /*
176  * Function irda_final_timer_expired (data)
177  *
178  *    
179  *
180  */
181 static void irlap_final_timer_expired(void *data)
182 {
183         struct irlap_cb *self = (struct irlap_cb *) data;
184
185         ASSERT(self != NULL, return;);
186         ASSERT(self->magic == LAP_MAGIC, return;);
187
188         irlap_do_event(self, FINAL_TIMER_EXPIRED, NULL, NULL);
189 }
190
191 /*
192  * Function irda_wd_timer_expired (data)
193  *
194  *    
195  *
196  */
197 static void irlap_wd_timer_expired(void *data)
198 {
199         struct irlap_cb *self = (struct irlap_cb *) data;
200         
201         ASSERT(self != NULL, return;);
202         ASSERT(self->magic == LAP_MAGIC, return;);
203         
204         irlap_do_event(self, WD_TIMER_EXPIRED, NULL, NULL);
205 }
206
207 /*
208  * Function irda_backoff_timer_expired (data)
209  *
210  *    
211  *
212  */
213 static void irlap_backoff_timer_expired(void *data)
214 {
215         struct irlap_cb *self = (struct irlap_cb *) data;
216         
217         ASSERT(self != NULL, return;);
218         ASSERT(self->magic == LAP_MAGIC, return;);
219         
220         irlap_do_event(self, BACKOFF_TIMER_EXPIRED, NULL, NULL);
221 }
222
223
224 /*
225  * Function irtty_media_busy_expired (data)
226  *
227  *    
228  */
229 void irlap_media_busy_expired(void* data)
230 {
231         struct irlap_cb *self = (struct irlap_cb *) data;
232
233         ASSERT(self != NULL, return;);
234
235         irda_device_set_media_busy(self->netdev, FALSE);
236         /* Note : the LAP event will be send in irlap_stop_mbusy_timer(),
237         * to catch other cases where the flag is cleared (for example
238         * after a discovery) - Jean II */
239 }