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