This source file includes following definitions.
- ax25_set_timer
- ax25_reset_timer
- ax25_timer
- ax25_t1_timeout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/config.h>
25 #ifdef CONFIG_AX25
26 #include <linux/errno.h>
27 #include <linux/types.h>
28 #include <linux/socket.h>
29 #include <linux/in.h>
30 #include <linux/kernel.h>
31 #include <linux/sched.h>
32 #include <linux/timer.h>
33 #include <linux/string.h>
34 #include <linux/sockios.h>
35 #include <linux/net.h>
36 #include <net/ax25.h>
37 #include <linux/inet.h>
38 #include <linux/netdevice.h>
39 #include <linux/skbuff.h>
40 #include <net/sock.h>
41 #include <asm/segment.h>
42 #include <asm/system.h>
43 #include <linux/fcntl.h>
44 #include <linux/mm.h>
45 #include <linux/interrupt.h>
46 #ifdef CONFIG_NETROM
47 #include <net/netrom.h>
48 #endif
49
50 static void ax25_timer(unsigned long);
51
52
53
54
55 void ax25_set_timer(ax25_cb *ax25)
56 {
57 unsigned long flags;
58
59 save_flags(flags);
60 cli();
61 del_timer(&ax25->timer);
62 restore_flags(flags);
63
64 ax25->timer.next = ax25->timer.prev = NULL;
65 ax25->timer.data = (unsigned long)ax25;
66 ax25->timer.function = &ax25_timer;
67
68 ax25->timer.expires = jiffies + 10;
69 add_timer(&ax25->timer);
70 }
71
72 static void ax25_reset_timer(ax25_cb *ax25)
73 {
74 unsigned long flags;
75
76 save_flags(flags);
77 cli();
78 del_timer(&ax25->timer);
79 restore_flags(flags);
80
81 ax25->timer.data = (unsigned long)ax25;
82 ax25->timer.function = &ax25_timer;
83 ax25->timer.expires = jiffies + 10;
84 add_timer(&ax25->timer);
85 }
86
87
88
89
90
91
92
93 static void ax25_timer(unsigned long param)
94 {
95 ax25_cb *ax25 = (ax25_cb *)param;
96
97 switch (ax25->state) {
98 case AX25_STATE_0:
99
100
101 if (ax25->sk == NULL || ax25->sk->destroy || (ax25->sk->state == TCP_LISTEN && ax25->sk->dead)) {
102 del_timer(&ax25->timer);
103 ax25_destroy_socket(ax25);
104 return;
105 }
106 break;
107
108 case AX25_STATE_3:
109 case AX25_STATE_4:
110
111
112
113 if (ax25->sk != NULL) {
114 if (ax25->sk->rmem_alloc < (ax25->sk->rcvbuf / 2) && (ax25->condition & OWN_RX_BUSY_CONDITION)) {
115 ax25->condition &= ~OWN_RX_BUSY_CONDITION;
116 if (!ax25->dama_slave)
117 ax25_send_control(ax25, RR, POLLOFF, C_RESPONSE);
118 ax25->condition &= ~ACK_PENDING_CONDITION;
119 break;
120 }
121 }
122
123
124
125 if (!ax25->dama_slave)
126 ax25_kick(ax25);
127 break;
128
129 default:
130 break;
131 }
132
133 if (ax25->t2timer > 0 && --ax25->t2timer == 0) {
134 if (ax25->state == AX25_STATE_3 || ax25->state == AX25_STATE_4) {
135 if (ax25->condition & ACK_PENDING_CONDITION) {
136 ax25->condition &= ~ACK_PENDING_CONDITION;
137 if (!ax25->dama_slave)
138 ax25_timeout_response(ax25);
139 }
140 }
141 }
142
143 if (ax25->t3timer > 0 && --ax25->t3timer == 0) {
144
145
146 if (ax25->dama_slave) {
147 #ifdef CONFIG_NETROM
148 nr_link_failed(&ax25->dest_addr, ax25->device);
149 #endif
150 ax25_clear_queues(ax25);
151 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
152
153 ax25->state = AX25_STATE_0;
154 if (ax25->sk != NULL) {
155 if (ax25->sk->debug)
156 printk("T3 Timeout\n");
157 ax25->sk->state = TCP_CLOSE;
158 ax25->sk->err = ETIMEDOUT;
159 if (!ax25->sk->dead)
160 ax25->sk->state_change(ax25->sk);
161 ax25->sk->dead = 1;
162 }
163
164 ax25_reset_timer(ax25);
165 return;
166 }
167
168 if (ax25->state == AX25_STATE_3) {
169 ax25->n2count = 0;
170 ax25_transmit_enquiry(ax25);
171 ax25->state = AX25_STATE_4;
172 }
173 ax25->t3timer = ax25->t3;
174 }
175
176 if (ax25->idletimer > 0 && --ax25->idletimer == 0) {
177
178
179
180
181 ax25_clear_queues(ax25);
182
183 ax25->n2count = 0;
184 if (!ax25->dama_slave) {
185 ax25->t3timer = 0;
186 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
187 } else {
188 ax25->t3timer = ax25->t3;
189 }
190
191
192
193 if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2)
194 ax25->state = AX25_STATE_0;
195 else
196 ax25->state = AX25_STATE_2;
197
198 ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
199
200 if (ax25->sk != NULL)
201 {
202 ax25->sk->state = TCP_CLOSE;
203 ax25->sk->err = 0;
204 if (!ax25->sk->dead)
205 ax25->sk->state_change(ax25->sk);
206 ax25->sk->dead = 1;
207 ax25->sk->destroy = 1;
208 }
209 }
210
211
212
213
214
215 if (ax25->t1timer == 0 || --ax25->t1timer > 0) {
216 ax25_reset_timer(ax25);
217 return;
218 }
219
220 if (!ax25_dev_is_dama_slave(ax25->device)) {
221 if (ax25->dama_slave)
222 ax25->dama_slave = 0;
223 ax25_t1_timeout(ax25);
224 }
225 }
226
227
228
229
230
231
232
233
234
235
236 void ax25_t1_timeout(ax25_cb * ax25)
237 {
238 switch (ax25->state) {
239 case AX25_STATE_1:
240 if (ax25->n2count == ax25->n2) {
241 if (ax25->modulus == MODULUS) {
242 #ifdef CONFIG_NETROM
243 nr_link_failed(&ax25->dest_addr, ax25->device);
244 #endif
245 ax25_clear_queues(ax25);
246 ax25->state = AX25_STATE_0;
247 if (ax25->sk != NULL) {
248 ax25->sk->state = TCP_CLOSE;
249 ax25->sk->err = ETIMEDOUT;
250 if (!ax25->sk->dead)
251 ax25->sk->state_change(ax25->sk);
252 ax25->sk->dead = 1;
253 }
254 } else {
255 ax25->modulus = MODULUS;
256 ax25->window = ax25_dev_get_value(ax25->device, AX25_VALUES_WINDOW);
257 ax25->n2count = 0;
258 ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
259 }
260 } else {
261 ax25->n2count++;
262 if (ax25->modulus == MODULUS) {
263 ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
264 } else {
265 ax25_send_control(ax25, SABME, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
266 }
267 }
268 break;
269
270 case AX25_STATE_2:
271 if (ax25->n2count == ax25->n2) {
272 #ifdef CONFIG_NETROM
273 nr_link_failed(&ax25->dest_addr, ax25->device);
274 #endif
275 ax25_clear_queues(ax25);
276 ax25->state = AX25_STATE_0;
277 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
278
279 if (ax25->sk != NULL) {
280 ax25->sk->state = TCP_CLOSE;
281 ax25->sk->err = ETIMEDOUT;
282 if (!ax25->sk->dead)
283 ax25->sk->state_change(ax25->sk);
284 ax25->sk->dead = 1;
285 }
286 } else {
287 ax25->n2count++;
288 if (!ax25_dev_is_dama_slave(ax25->device))
289 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
290 }
291 break;
292
293 case AX25_STATE_3:
294 ax25->n2count = 1;
295 if (!ax25->dama_slave)
296 ax25_transmit_enquiry(ax25);
297 ax25->state = AX25_STATE_4;
298 break;
299
300 case AX25_STATE_4:
301 if (ax25->n2count == ax25->n2) {
302 #ifdef CONFIG_NETROM
303 nr_link_failed(&ax25->dest_addr, ax25->device);
304 #endif
305 ax25_clear_queues(ax25);
306 ax25_send_control(ax25, DM, POLLON, C_RESPONSE);
307 ax25->state = AX25_STATE_0;
308 if (ax25->sk != NULL) {
309 if (ax25->sk->debug)
310 printk("Link Failure\n");
311 ax25->sk->state = TCP_CLOSE;
312 ax25->sk->err = ETIMEDOUT;
313 if (!ax25->sk->dead)
314 ax25->sk->state_change(ax25->sk);
315 ax25->sk->dead = 1;
316 }
317 } else {
318 ax25->n2count++;
319 if (!ax25->dama_slave)
320 ax25_transmit_enquiry(ax25);
321 }
322 break;
323 }
324
325 ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
326
327 ax25_set_timer(ax25);
328 }
329
330 #endif