Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / ax25 / ax25_timer.c
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
8  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
9  * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
10  * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
11  * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
12  * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
13  * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
14  */
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/types.h>
18 #include <linux/socket.h>
19 #include <linux/in.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/jiffies.h>
23 #include <linux/timer.h>
24 #include <linux/string.h>
25 #include <linux/sockios.h>
26 #include <linux/net.h>
27 #include <net/ax25.h>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/skbuff.h>
31 #include <net/sock.h>
32 #include <asm/uaccess.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
35 #include <linux/mm.h>
36 #include <linux/interrupt.h>
37
38 static void ax25_heartbeat_expiry(unsigned long);
39 static void ax25_t1timer_expiry(unsigned long);
40 static void ax25_t2timer_expiry(unsigned long);
41 static void ax25_t3timer_expiry(unsigned long);
42 static void ax25_idletimer_expiry(unsigned long);
43
44 void ax25_start_heartbeat(ax25_cb *ax25)
45 {
46         del_timer(&ax25->timer);
47
48         ax25->timer.data     = (unsigned long)ax25;
49         ax25->timer.function = &ax25_heartbeat_expiry;
50         ax25->timer.expires  = jiffies + 5 * HZ;
51
52         add_timer(&ax25->timer);
53 }
54
55 void ax25_start_t1timer(ax25_cb *ax25)
56 {
57         del_timer(&ax25->t1timer);
58
59         ax25->t1timer.data     = (unsigned long)ax25;
60         ax25->t1timer.function = &ax25_t1timer_expiry;
61         ax25->t1timer.expires  = jiffies + ax25->t1;
62
63         add_timer(&ax25->t1timer);
64 }
65
66 void ax25_start_t2timer(ax25_cb *ax25)
67 {
68         del_timer(&ax25->t2timer);
69
70         ax25->t2timer.data     = (unsigned long)ax25;
71         ax25->t2timer.function = &ax25_t2timer_expiry;
72         ax25->t2timer.expires  = jiffies + ax25->t2;
73
74         add_timer(&ax25->t2timer);
75 }
76
77 void ax25_start_t3timer(ax25_cb *ax25)
78 {
79         del_timer(&ax25->t3timer);
80
81         if (ax25->t3 > 0) {
82                 ax25->t3timer.data     = (unsigned long)ax25;
83                 ax25->t3timer.function = &ax25_t3timer_expiry;
84                 ax25->t3timer.expires  = jiffies + ax25->t3;
85
86                 add_timer(&ax25->t3timer);
87         }
88 }
89
90 void ax25_start_idletimer(ax25_cb *ax25)
91 {
92         del_timer(&ax25->idletimer);
93
94         if (ax25->idle > 0) {
95                 ax25->idletimer.data     = (unsigned long)ax25;
96                 ax25->idletimer.function = &ax25_idletimer_expiry;
97                 ax25->idletimer.expires  = jiffies + ax25->idle;
98
99                 add_timer(&ax25->idletimer);
100         }
101 }
102
103 void ax25_stop_heartbeat(ax25_cb *ax25)
104 {
105         del_timer(&ax25->timer);
106 }
107
108 void ax25_stop_t1timer(ax25_cb *ax25)
109 {
110         del_timer(&ax25->t1timer);
111 }
112
113 void ax25_stop_t2timer(ax25_cb *ax25)
114 {
115         del_timer(&ax25->t2timer);
116 }
117
118 void ax25_stop_t3timer(ax25_cb *ax25)
119 {
120         del_timer(&ax25->t3timer);
121 }
122
123 void ax25_stop_idletimer(ax25_cb *ax25)
124 {
125         del_timer(&ax25->idletimer);
126 }
127
128 int ax25_t1timer_running(ax25_cb *ax25)
129 {
130         return timer_pending(&ax25->t1timer);
131 }
132
133 unsigned long ax25_display_timer(struct timer_list *timer)
134 {
135         if (!timer_pending(timer))
136                 return 0;
137
138         return timer->expires - jiffies;
139 }
140
141 EXPORT_SYMBOL(ax25_display_timer);
142
143 static void ax25_heartbeat_expiry(unsigned long param)
144 {
145         int proto = AX25_PROTO_STD_SIMPLEX;
146         ax25_cb *ax25 = (ax25_cb *)param;
147
148         if (ax25->ax25_dev)
149                 proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
150
151         switch (proto) {
152         case AX25_PROTO_STD_SIMPLEX:
153         case AX25_PROTO_STD_DUPLEX:
154                 ax25_std_heartbeat_expiry(ax25);
155                 break;
156
157 #ifdef CONFIG_AX25_DAMA_SLAVE
158         case AX25_PROTO_DAMA_SLAVE:
159                 if (ax25->ax25_dev->dama.slave)
160                         ax25_ds_heartbeat_expiry(ax25);
161                 else
162                         ax25_std_heartbeat_expiry(ax25);
163                 break;
164 #endif
165         }
166 }
167
168 static void ax25_t1timer_expiry(unsigned long param)
169 {
170         ax25_cb *ax25 = (ax25_cb *)param;
171
172         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
173         case AX25_PROTO_STD_SIMPLEX:
174         case AX25_PROTO_STD_DUPLEX:
175                 ax25_std_t1timer_expiry(ax25);
176                 break;
177
178 #ifdef CONFIG_AX25_DAMA_SLAVE
179         case AX25_PROTO_DAMA_SLAVE:
180                 if (!ax25->ax25_dev->dama.slave)
181                         ax25_std_t1timer_expiry(ax25);
182                 break;
183 #endif
184         }
185 }
186
187 static void ax25_t2timer_expiry(unsigned long param)
188 {
189         ax25_cb *ax25 = (ax25_cb *)param;
190
191         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
192         case AX25_PROTO_STD_SIMPLEX:
193         case AX25_PROTO_STD_DUPLEX:
194                 ax25_std_t2timer_expiry(ax25);
195                 break;
196
197 #ifdef CONFIG_AX25_DAMA_SLAVE
198         case AX25_PROTO_DAMA_SLAVE:
199                 if (!ax25->ax25_dev->dama.slave)
200                         ax25_std_t2timer_expiry(ax25);
201                 break;
202 #endif
203         }
204 }
205
206 static void ax25_t3timer_expiry(unsigned long param)
207 {
208         ax25_cb *ax25 = (ax25_cb *)param;
209
210         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
211         case AX25_PROTO_STD_SIMPLEX:
212         case AX25_PROTO_STD_DUPLEX:
213                 ax25_std_t3timer_expiry(ax25);
214                 break;
215
216 #ifdef CONFIG_AX25_DAMA_SLAVE
217         case AX25_PROTO_DAMA_SLAVE:
218                 if (ax25->ax25_dev->dama.slave)
219                         ax25_ds_t3timer_expiry(ax25);
220                 else
221                         ax25_std_t3timer_expiry(ax25);
222                 break;
223 #endif
224         }
225 }
226
227 static void ax25_idletimer_expiry(unsigned long param)
228 {
229         ax25_cb *ax25 = (ax25_cb *)param;
230
231         switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
232         case AX25_PROTO_STD_SIMPLEX:
233         case AX25_PROTO_STD_DUPLEX:
234                 ax25_std_idletimer_expiry(ax25);
235                 break;
236
237 #ifdef CONFIG_AX25_DAMA_SLAVE
238         case AX25_PROTO_DAMA_SLAVE:
239                 if (ax25->ax25_dev->dama.slave)
240                         ax25_ds_idletimer_expiry(ax25);
241                 else
242                         ax25_std_idletimer_expiry(ax25);
243                 break;
244 #endif
245         }
246 }