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