1 /*********************************************************************
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Aug 16 00:59:29 1997
9 * Modified at: Thu Oct 7 12:30:19 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1997, 1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * Neither Dag Brattli nor University of Tromsø admit liability nor
21 * provide warranty for any of this software. This material is
22 * provided "AS-IS" and at no charge.
24 ********************************************************************/
26 #include <asm/system.h>
27 #include <linux/delay.h>
29 #include <net/irda/timer.h>
30 #include <net/irda/irda.h>
31 #include <net/irda/irtty.h>
32 #include <net/irda/irlap.h>
33 #include <net/irda/irlmp_event.h>
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
);
41 static void irlap_media_busy_expired(void* data
);
43 * Function irda_start_timer (timer, timeout)
48 void irda_start_timer(struct timer_list
*ptimer
, int timeout
, void *data
,
49 TIMER_CALLBACK callback
)
53 ptimer
->data
= (unsigned long) data
;
56 * For most architectures void * is the same as unsigned long, but
57 * at least we try to use void * as long as possible. Since the
58 * timer functions use unsigned long, we cast the function here
60 ptimer
->function
= (void (*)(unsigned long)) callback
;
61 ptimer
->expires
= jiffies
+ timeout
;
66 void irlap_start_slot_timer(struct irlap_cb
*self
, int timeout
)
68 irda_start_timer(&self
->slot_timer
, timeout
, (void *) self
,
69 irlap_slot_timer_expired
);
72 void irlap_start_query_timer(struct irlap_cb
*self
, int timeout
)
74 irda_start_timer( &self
->query_timer
, timeout
, (void *) self
,
75 irlap_query_timer_expired
);
78 void irlap_start_final_timer(struct irlap_cb
*self
, int timeout
)
80 irda_start_timer(&self
->final_timer
, timeout
, (void *) self
,
81 irlap_final_timer_expired
);
84 void irlap_start_wd_timer(struct irlap_cb
*self
, int timeout
)
86 irda_start_timer(&self
->wd_timer
, timeout
, (void *) self
,
87 irlap_wd_timer_expired
);
90 void irlap_start_backoff_timer(struct irlap_cb
*self
, int timeout
)
92 irda_start_timer(&self
->backoff_timer
, timeout
, (void *) self
,
93 irlap_backoff_timer_expired
);
96 void irlap_start_mbusy_timer(struct irlap_cb
*self
)
98 irda_start_timer(&self
->media_busy_timer
, MEDIABUSY_TIMEOUT
,
99 (void *) self
, irlap_media_busy_expired
);
102 void irlmp_start_watchdog_timer(struct lsap_cb
*self
, int timeout
)
104 irda_start_timer(&self
->watchdog_timer
, timeout
, (void *) self
,
105 irlmp_watchdog_timer_expired
);
108 void irlmp_start_discovery_timer(struct irlmp_cb
*self
, int timeout
)
110 irda_start_timer(&self
->discovery_timer
, timeout
, (void *) self
,
111 irlmp_discovery_timer_expired
);
114 void irlmp_start_idle_timer(struct lap_cb
*self
, int timeout
)
116 irda_start_timer(&self
->idle_timer
, timeout
, (void *) self
,
117 irlmp_idle_timer_expired
);
121 * Function irlap_slot_timer_expired (data)
123 * IrLAP slot timer has expired
126 static void irlap_slot_timer_expired(void *data
)
128 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
130 ASSERT(self
!= NULL
, return;);
131 ASSERT(self
->magic
== LAP_MAGIC
, return;);
133 irlap_do_event(self
, SLOT_TIMER_EXPIRED
, NULL
, NULL
);
137 * Function irlap_query_timer_expired (data)
139 * IrLAP query timer has expired
142 static void irlap_query_timer_expired(void *data
)
144 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
146 ASSERT(self
!= NULL
, return;);
147 ASSERT(self
->magic
== LAP_MAGIC
, return;);
149 irlap_do_event(self
, QUERY_TIMER_EXPIRED
, NULL
, NULL
);
153 * Function irda_final_timer_expired (data)
158 static void irlap_final_timer_expired(void *data
)
160 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
162 ASSERT(self
!= NULL
, return;);
163 ASSERT(self
->magic
== LAP_MAGIC
, return;);
165 irlap_do_event(self
, FINAL_TIMER_EXPIRED
, NULL
, NULL
);
169 * Function irda_wd_timer_expired (data)
174 static void irlap_wd_timer_expired(void *data
)
176 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
178 ASSERT(self
!= NULL
, return;);
179 ASSERT(self
->magic
== LAP_MAGIC
, return;);
181 irlap_do_event(self
, WD_TIMER_EXPIRED
, NULL
, NULL
);
185 * Function irda_backoff_timer_expired (data)
190 static void irlap_backoff_timer_expired(void *data
)
192 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
194 ASSERT(self
!= NULL
, return;);
195 ASSERT(self
->magic
== LAP_MAGIC
, return;);
197 irlap_do_event(self
, BACKOFF_TIMER_EXPIRED
, NULL
, NULL
);
202 * Function irtty_media_busy_expired (data)
206 void irlap_media_busy_expired(void* data
)
208 struct irlap_cb
*self
= (struct irlap_cb
*) data
;
210 ASSERT(self
!= NULL
, return;);
212 irda_device_set_media_busy(self
->netdev
, FALSE
);