This source file includes following definitions.
- nr_state1_machine
- nr_state2_machine
- nr_state3_machine
- nr_process_rx_frame
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <linux/config.h>
26 #ifdef CONFIG_NETROM
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
30 #include <linux/in.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/timer.h>
34 #include <linux/string.h>
35 #include <linux/sockios.h>
36 #include <linux/net.h>
37 #include <net/ax25.h>
38 #include <linux/inet.h>
39 #include <linux/netdevice.h>
40 #include <linux/skbuff.h>
41 #include <net/sock.h>
42 #include <net/ip.h>
43 #include <asm/segment.h>
44 #include <asm/system.h>
45 #include <linux/fcntl.h>
46 #include <linux/mm.h>
47 #include <linux/interrupt.h>
48 #include <net/netrom.h>
49
50
51
52
53
54
55 static int nr_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype)
56 {
57 switch (frametype) {
58
59 case NR_CONNACK:
60 nr_calculate_rtt(sk);
61 sk->window = skb->data[5];
62 sk->nr->your_index = skb->data[2];
63 sk->nr->your_id = skb->data[3];
64 sk->nr->t1timer = 0;
65 sk->nr->t2timer = 0;
66 sk->nr->t4timer = 0;
67 sk->nr->vs = 0;
68 sk->nr->va = 0;
69 sk->nr->vr = 0;
70 sk->nr->vl = 0;
71 sk->nr->state = NR_STATE_3;
72 sk->state = TCP_ESTABLISHED;
73 sk->nr->n2count = 0;
74
75 if (!sk->dead)
76 sk->state_change(sk);
77 break;
78
79 case NR_CONNACK + NR_CHOKE_FLAG:
80 nr_clear_tx_queue(sk);
81 sk->nr->state = NR_STATE_0;
82 sk->state = TCP_CLOSE;
83 sk->err = ECONNREFUSED;
84 if (!sk->dead)
85 sk->state_change(sk);
86 sk->dead = 1;
87 break;
88
89 default:
90 break;
91 }
92
93 return 0;
94 }
95
96
97
98
99
100
101 static int nr_state2_machine(struct sock *sk, struct sk_buff *skb, int frametype)
102 {
103 switch (frametype) {
104
105 case NR_DISCREQ:
106 nr_write_internal(sk, NR_DISCACK);
107 break;
108
109 case NR_DISCACK:
110 sk->nr->state = NR_STATE_0;
111 sk->state = TCP_CLOSE;
112 sk->err = 0;
113 if (!sk->dead)
114 sk->state_change(sk);
115 sk->dead = 1;
116 break;
117
118 default:
119 break;
120 }
121
122 return 0;
123 }
124
125
126
127
128
129
130 static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype)
131 {
132 struct sk_buff_head temp_queue;
133 struct sk_buff *skbn;
134 unsigned short save_vr;
135 unsigned short nr, ns;
136 int queued = 0;
137
138 nr = skb->data[3];
139 ns = skb->data[2];
140
141 switch (frametype) {
142
143 case NR_CONNREQ:
144 nr_write_internal(sk, NR_CONNACK);
145 sk->nr->condition = 0x00;
146 sk->nr->t1timer = 0;
147 sk->nr->t2timer = 0;
148 sk->nr->t4timer = 0;
149 sk->nr->vs = 0;
150 sk->nr->va = 0;
151 sk->nr->vr = 0;
152 sk->nr->vl = 0;
153 break;
154
155 case NR_DISCREQ:
156 nr_clear_tx_queue(sk);
157 nr_write_internal(sk, NR_DISCACK);
158 sk->nr->state = NR_STATE_0;
159 sk->state = TCP_CLOSE;
160 sk->err = 0;
161 if (!sk->dead)
162 sk->state_change(sk);
163 sk->dead = 1;
164 break;
165
166 case NR_DISCACK:
167 nr_clear_tx_queue(sk);
168 sk->nr->state = NR_STATE_0;
169 sk->state = TCP_CLOSE;
170 sk->err = ECONNRESET;
171 if (!sk->dead)
172 sk->state_change(sk);
173 sk->dead = 1;
174 break;
175
176 case NR_INFOACK:
177 case NR_INFOACK + NR_CHOKE_FLAG:
178 if (frametype & NR_CHOKE_FLAG) {
179 sk->nr->condition |= PEER_RX_BUSY_CONDITION;
180 sk->nr->t4timer = nr_default.busy_delay;
181 } else {
182 sk->nr->condition &= ~PEER_RX_BUSY_CONDITION;
183 sk->nr->t4timer = 0;
184 }
185 if (!nr_validate_nr(sk, nr)) {
186 nr_nr_error_recovery(sk);
187 sk->nr->state = NR_STATE_1;
188 break;
189 }
190 if (sk->nr->condition & PEER_RX_BUSY_CONDITION) {
191 nr_frames_acked(sk, nr);
192 } else {
193 nr_check_iframes_acked(sk, nr);
194 }
195 break;
196
197 case NR_INFOACK + NR_NAK_FLAG:
198 case NR_INFOACK + NR_NAK_FLAG + NR_CHOKE_FLAG:
199 if (frametype & NR_CHOKE_FLAG) {
200 sk->nr->condition |= PEER_RX_BUSY_CONDITION;
201 sk->nr->t4timer = nr_default.busy_delay;
202 } else {
203 sk->nr->condition &= ~PEER_RX_BUSY_CONDITION;
204 sk->nr->t4timer = 0;
205 }
206 if (nr_validate_nr(sk, nr)) {
207 nr_frames_acked(sk, nr);
208 nr_send_nak_frame(sk);
209 } else {
210 nr_nr_error_recovery(sk);
211 sk->nr->state = NR_STATE_1;
212 }
213 break;
214
215 case NR_INFO:
216 case NR_INFO + NR_CHOKE_FLAG:
217 case NR_INFO + NR_MORE_FLAG:
218 case NR_INFO + NR_CHOKE_FLAG + NR_MORE_FLAG:
219 if (frametype & NR_CHOKE_FLAG) {
220 sk->nr->condition |= PEER_RX_BUSY_CONDITION;
221 sk->nr->t4timer = nr_default.busy_delay;
222 } else {
223 sk->nr->condition &= ~PEER_RX_BUSY_CONDITION;
224 sk->nr->t4timer = 0;
225 }
226 if (!nr_validate_nr(sk, nr)) {
227 nr_nr_error_recovery(sk);
228 sk->nr->state = NR_STATE_1;
229 break;
230 }
231 if (sk->nr->condition & PEER_RX_BUSY_CONDITION) {
232 nr_frames_acked(sk, nr);
233 } else {
234 nr_check_iframes_acked(sk, nr);
235 }
236 queued = 1;
237 skb_queue_head(&sk->nr->reseq_queue, skb);
238 if (sk->nr->condition & OWN_RX_BUSY_CONDITION)
239 break;
240 skb_queue_head_init(&temp_queue);
241 do {
242 save_vr = sk->nr->vr;
243 while ((skbn = skb_dequeue(&sk->nr->reseq_queue)) != NULL) {
244 ns = skbn->data[2];
245 if (ns == sk->nr->vr) {
246 if (sock_queue_rcv_skb(sk, skbn) == 0) {
247 sk->nr->vr = (sk->nr->vr + 1) % NR_MODULUS;
248 } else {
249 sk->nr->condition |= OWN_RX_BUSY_CONDITION;
250 skb_queue_tail(&temp_queue, skbn);
251 }
252 } else if (nr_in_rx_window(sk, ns)) {
253 skb_queue_tail(&temp_queue, skbn);
254 } else {
255 skbn->free = 1;
256 kfree_skb(skbn, FREE_READ);
257 }
258 }
259 while ((skbn = skb_dequeue(&temp_queue)) != NULL) {
260 skb_queue_tail(&sk->nr->reseq_queue, skbn);
261 }
262 } while (save_vr != sk->nr->vr);
263
264
265
266 if (((sk->nr->vl + sk->window) % NR_MODULUS) == sk->nr->vr) {
267 nr_enquiry_response(sk);
268 } else {
269 if (!(sk->nr->condition & ACK_PENDING_CONDITION)) {
270 sk->nr->t2timer = sk->nr->t2;
271 sk->nr->condition |= ACK_PENDING_CONDITION;
272 }
273 }
274 break;
275
276 default:
277 break;
278 }
279
280 return queued;
281 }
282
283
284 int nr_process_rx_frame(struct sock *sk, struct sk_buff *skb)
285 {
286 int queued = 0, frametype;
287
288 if (sk->nr->state != NR_STATE_1 && sk->nr->state != NR_STATE_2 &&
289 sk->nr->state != NR_STATE_3) {
290 printk("nr_process_rx_frame: frame received - state: %d\n", sk->nr->state);
291 return queued;
292 }
293
294 del_timer(&sk->timer);
295
296 frametype = skb->data[4];
297
298 switch (sk->nr->state)
299 {
300 case NR_STATE_1:
301 queued = nr_state1_machine(sk, skb, frametype);
302 break;
303 case NR_STATE_2:
304 queued = nr_state2_machine(sk, skb, frametype);
305 break;
306 case NR_STATE_3:
307 queued = nr_state3_machine(sk, skb, frametype);
308 break;
309 }
310
311 nr_set_timer(sk);
312
313 return queued;
314 }
315
316 #endif