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