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
175
176
177 if (ax25->t1timer == 0 || --ax25->t1timer > 0) {
178 ax25_reset_timer(ax25);
179 return;
180 }
181
182 if (!ax25_dev_is_dama_slave(ax25->device)) {
183 if (ax25->dama_slave)
184 ax25->dama_slave = 0;
185 ax25_t1_timeout(ax25);
186 }
187 }
188
189
190
191
192
193
194
195
196
197
198 void ax25_t1_timeout(ax25_cb * ax25)
199 {
200 switch (ax25->state) {
201 case AX25_STATE_1:
202 if (ax25->n2count == ax25->n2) {
203 if (ax25->modulus == MODULUS) {
204 #ifdef CONFIG_NETROM
205 nr_link_failed(&ax25->dest_addr, ax25->device);
206 #endif
207 ax25_clear_queues(ax25);
208 ax25->state = AX25_STATE_0;
209 if (ax25->sk != NULL) {
210 ax25->sk->state = TCP_CLOSE;
211 ax25->sk->err = ETIMEDOUT;
212 if (!ax25->sk->dead)
213 ax25->sk->state_change(ax25->sk);
214 ax25->sk->dead = 1;
215 }
216 } else {
217 ax25->modulus = MODULUS;
218 ax25->window = ax25_dev_get_value(ax25->device, AX25_VALUES_WINDOW);
219 ax25->n2count = 0;
220 ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
221 }
222 } else {
223 ax25->n2count++;
224 if (ax25->modulus == MODULUS) {
225 ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
226 } else {
227 ax25_send_control(ax25, SABME, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
228 }
229 }
230 break;
231
232 case AX25_STATE_2:
233 if (ax25->n2count == ax25->n2) {
234 #ifdef CONFIG_NETROM
235 nr_link_failed(&ax25->dest_addr, ax25->device);
236 #endif
237 ax25_clear_queues(ax25);
238 ax25->state = AX25_STATE_0;
239 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
240
241 if (ax25->sk != NULL) {
242 ax25->sk->state = TCP_CLOSE;
243 ax25->sk->err = ETIMEDOUT;
244 if (!ax25->sk->dead)
245 ax25->sk->state_change(ax25->sk);
246 ax25->sk->dead = 1;
247 }
248 } else {
249 ax25->n2count++;
250 if (!ax25_dev_is_dama_slave(ax25->device))
251 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
252 }
253 break;
254
255 case AX25_STATE_3:
256 ax25->n2count = 1;
257 if (!ax25->dama_slave)
258 ax25_transmit_enquiry(ax25);
259 ax25->state = AX25_STATE_4;
260 break;
261
262 case AX25_STATE_4:
263 if (ax25->n2count == ax25->n2) {
264 #ifdef CONFIG_NETROM
265 nr_link_failed(&ax25->dest_addr, ax25->device);
266 #endif
267 ax25_clear_queues(ax25);
268 ax25_send_control(ax25, DM, POLLON, C_RESPONSE);
269 ax25->state = AX25_STATE_0;
270 if (ax25->sk != NULL) {
271 if (ax25->sk->debug)
272 printk("Link Failure\n");
273 ax25->sk->state = TCP_CLOSE;
274 ax25->sk->err = ETIMEDOUT;
275 if (!ax25->sk->dead)
276 ax25->sk->state_change(ax25->sk);
277 ax25->sk->dead = 1;
278 }
279 } else {
280 ax25->n2count++;
281 if (!ax25->dama_slave)
282 ax25_transmit_enquiry(ax25);
283 }
284 break;
285 }
286
287 ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
288
289 ax25_set_timer(ax25);
290 }
291
292 #endif