This source file includes following definitions.
- ax25_set_timer
- ax25_reset_timer
- ax25_timer
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->dead) || ax25->sk == NULL) {
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 ax25_send_control(ax25, RR, POLLOFF, C_RESPONSE);
115 ax25->condition &= ~ACK_PENDING_CONDITION;
116 break;
117 }
118 }
119
120
121
122 ax25_kick(ax25);
123 break;
124
125 default:
126 break;
127 }
128
129 if (ax25->t2timer > 0 && --ax25->t2timer == 0) {
130 if (ax25->state == AX25_STATE_3 || ax25->state == AX25_STATE_4) {
131 if (ax25->condition & ACK_PENDING_CONDITION) {
132 ax25->condition &= ~ACK_PENDING_CONDITION;
133 ax25_enquiry_response(ax25);
134 }
135 }
136 }
137
138 if (ax25->t3timer > 0 && --ax25->t3timer == 0) {
139 if (ax25->state == AX25_STATE_3) {
140 ax25->n2count = 0;
141 ax25_transmit_enquiry(ax25);
142 ax25->state = AX25_STATE_4;
143 }
144 ax25->t3timer = ax25->t3;
145 }
146
147 if (ax25->t1timer == 0 || --ax25->t1timer > 0) {
148 ax25_reset_timer(ax25);
149 return;
150 }
151
152 switch (ax25->state) {
153 case AX25_STATE_1:
154 if (ax25->n2count == ax25->n2) {
155 if (ax25->modulus == MODULUS) {
156 #ifdef CONFIG_NETROM
157 nr_link_failed(&ax25->dest_addr, ax25->device);
158 #endif
159 ax25_clear_queues(ax25);
160 ax25->state = AX25_STATE_0;
161 if (ax25->sk != NULL) {
162 ax25->sk->state = TCP_CLOSE;
163 ax25->sk->err = ETIMEDOUT;
164 if (!ax25->sk->dead)
165 ax25->sk->state_change(ax25->sk);
166 ax25->sk->dead = 1;
167 }
168 } else {
169 ax25->modulus = MODULUS;
170 ax25->n2count = 0;
171 }
172 } else {
173 ax25->n2count++;
174 if (ax25->modulus == MODULUS) {
175 ax25_send_control(ax25, SABM, POLLON, C_COMMAND);
176 } else {
177 ax25_send_control(ax25, SABME, POLLON, C_COMMAND);
178 }
179 }
180 break;
181
182 case AX25_STATE_2:
183 if (ax25->n2count == ax25->n2) {
184 #ifdef CONFIG_NETROM
185 nr_link_failed(&ax25->dest_addr, ax25->device);
186 #endif
187 ax25_clear_queues(ax25);
188 ax25->state = AX25_STATE_0;
189 if (ax25->sk != NULL) {
190 ax25->sk->state = TCP_CLOSE;
191 ax25->sk->err = ETIMEDOUT;
192 if (!ax25->sk->dead)
193 ax25->sk->state_change(ax25->sk);
194 ax25->sk->dead = 1;
195 }
196 } else {
197 ax25->n2count++;
198 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
199 }
200 break;
201
202 case AX25_STATE_3:
203 ax25->n2count = 1;
204 ax25_transmit_enquiry(ax25);
205 ax25->state = AX25_STATE_4;
206 break;
207
208 case AX25_STATE_4:
209 if (ax25->n2count == ax25->n2) {
210 #ifdef CONFIG_NETROM
211 nr_link_failed(&ax25->dest_addr, ax25->device);
212 #endif
213 ax25_clear_queues(ax25);
214 ax25_send_control(ax25, DM, POLLON, C_RESPONSE);
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->n2count++;
225 ax25_transmit_enquiry(ax25);
226 }
227 break;
228 }
229
230 ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
231
232 ax25_set_timer(ax25);
233 }
234
235 #endif