diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/isdn/hisax/isdnl2.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/isdn/hisax/isdnl2.c')
-rw-r--r-- | drivers/isdn/hisax/isdnl2.c | 1860 |
1 files changed, 1860 insertions, 0 deletions
diff --git a/drivers/isdn/hisax/isdnl2.c b/drivers/isdn/hisax/isdnl2.c new file mode 100644 index 000000000000..d311b5fbf895 --- /dev/null +++ b/drivers/isdn/hisax/isdnl2.c | |||
@@ -0,0 +1,1860 @@ | |||
1 | /* $Id: isdnl2.c,v 2.30.2.4 2004/02/11 13:21:34 keil Exp $ | ||
2 | * | ||
3 | * Author Karsten Keil | ||
4 | * based on the teles driver from Jan den Ouden | ||
5 | * Copyright by Karsten Keil <keil@isdn4linux.de> | ||
6 | * | ||
7 | * This software may be used and distributed according to the terms | ||
8 | * of the GNU General Public License, incorporated herein by reference. | ||
9 | * | ||
10 | * For changes and modifications please read | ||
11 | * Documentation/isdn/HiSax.cert | ||
12 | * | ||
13 | * Thanks to Jan den Ouden | ||
14 | * Fritz Elfert | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include "hisax.h" | ||
20 | #include "isdnl2.h" | ||
21 | |||
22 | const char *l2_revision = "$Revision: 2.30.2.4 $"; | ||
23 | |||
24 | static void l2m_debug(struct FsmInst *fi, char *fmt, ...); | ||
25 | |||
26 | static struct Fsm l2fsm; | ||
27 | |||
28 | enum { | ||
29 | ST_L2_1, | ||
30 | ST_L2_2, | ||
31 | ST_L2_3, | ||
32 | ST_L2_4, | ||
33 | ST_L2_5, | ||
34 | ST_L2_6, | ||
35 | ST_L2_7, | ||
36 | ST_L2_8, | ||
37 | }; | ||
38 | |||
39 | #define L2_STATE_COUNT (ST_L2_8+1) | ||
40 | |||
41 | static char *strL2State[] = | ||
42 | { | ||
43 | "ST_L2_1", | ||
44 | "ST_L2_2", | ||
45 | "ST_L2_3", | ||
46 | "ST_L2_4", | ||
47 | "ST_L2_5", | ||
48 | "ST_L2_6", | ||
49 | "ST_L2_7", | ||
50 | "ST_L2_8", | ||
51 | }; | ||
52 | |||
53 | enum { | ||
54 | EV_L2_UI, | ||
55 | EV_L2_SABME, | ||
56 | EV_L2_DISC, | ||
57 | EV_L2_DM, | ||
58 | EV_L2_UA, | ||
59 | EV_L2_FRMR, | ||
60 | EV_L2_SUPER, | ||
61 | EV_L2_I, | ||
62 | EV_L2_DL_DATA, | ||
63 | EV_L2_ACK_PULL, | ||
64 | EV_L2_DL_UNIT_DATA, | ||
65 | EV_L2_DL_ESTABLISH_REQ, | ||
66 | EV_L2_DL_RELEASE_REQ, | ||
67 | EV_L2_MDL_ASSIGN, | ||
68 | EV_L2_MDL_REMOVE, | ||
69 | EV_L2_MDL_ERROR, | ||
70 | EV_L1_DEACTIVATE, | ||
71 | EV_L2_T200, | ||
72 | EV_L2_T203, | ||
73 | EV_L2_SET_OWN_BUSY, | ||
74 | EV_L2_CLEAR_OWN_BUSY, | ||
75 | EV_L2_FRAME_ERROR, | ||
76 | }; | ||
77 | |||
78 | #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR+1) | ||
79 | |||
80 | static char *strL2Event[] = | ||
81 | { | ||
82 | "EV_L2_UI", | ||
83 | "EV_L2_SABME", | ||
84 | "EV_L2_DISC", | ||
85 | "EV_L2_DM", | ||
86 | "EV_L2_UA", | ||
87 | "EV_L2_FRMR", | ||
88 | "EV_L2_SUPER", | ||
89 | "EV_L2_I", | ||
90 | "EV_L2_DL_DATA", | ||
91 | "EV_L2_ACK_PULL", | ||
92 | "EV_L2_DL_UNIT_DATA", | ||
93 | "EV_L2_DL_ESTABLISH_REQ", | ||
94 | "EV_L2_DL_RELEASE_REQ", | ||
95 | "EV_L2_MDL_ASSIGN", | ||
96 | "EV_L2_MDL_REMOVE", | ||
97 | "EV_L2_MDL_ERROR", | ||
98 | "EV_L1_DEACTIVATE", | ||
99 | "EV_L2_T200", | ||
100 | "EV_L2_T203", | ||
101 | "EV_L2_SET_OWN_BUSY", | ||
102 | "EV_L2_CLEAR_OWN_BUSY", | ||
103 | "EV_L2_FRAME_ERROR", | ||
104 | }; | ||
105 | |||
106 | static int l2addrsize(struct Layer2 *l2); | ||
107 | |||
108 | static void | ||
109 | set_peer_busy(struct Layer2 *l2) { | ||
110 | test_and_set_bit(FLG_PEER_BUSY, &l2->flag); | ||
111 | if (skb_queue_len(&l2->i_queue) || skb_queue_len(&l2->ui_queue)) | ||
112 | test_and_set_bit(FLG_L2BLOCK, &l2->flag); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | clear_peer_busy(struct Layer2 *l2) { | ||
117 | if (test_and_clear_bit(FLG_PEER_BUSY, &l2->flag)) | ||
118 | test_and_clear_bit(FLG_L2BLOCK, &l2->flag); | ||
119 | } | ||
120 | |||
121 | static void | ||
122 | InitWin(struct Layer2 *l2) | ||
123 | { | ||
124 | int i; | ||
125 | |||
126 | for (i = 0; i < MAX_WINDOW; i++) | ||
127 | l2->windowar[i] = NULL; | ||
128 | } | ||
129 | |||
130 | static int | ||
131 | freewin1(struct Layer2 *l2) | ||
132 | { | ||
133 | int i, cnt = 0; | ||
134 | |||
135 | for (i = 0; i < MAX_WINDOW; i++) { | ||
136 | if (l2->windowar[i]) { | ||
137 | cnt++; | ||
138 | dev_kfree_skb(l2->windowar[i]); | ||
139 | l2->windowar[i] = NULL; | ||
140 | } | ||
141 | } | ||
142 | return cnt; | ||
143 | } | ||
144 | |||
145 | inline void | ||
146 | freewin(struct PStack *st) | ||
147 | { | ||
148 | freewin1(&st->l2); | ||
149 | } | ||
150 | |||
151 | static void | ||
152 | ReleaseWin(struct Layer2 *l2) | ||
153 | { | ||
154 | int cnt; | ||
155 | |||
156 | if((cnt = freewin1(l2))) | ||
157 | printk(KERN_WARNING "isdl2 freed %d skbuffs in release\n", cnt); | ||
158 | } | ||
159 | |||
160 | inline unsigned int | ||
161 | cansend(struct PStack *st) | ||
162 | { | ||
163 | unsigned int p1; | ||
164 | |||
165 | if(test_bit(FLG_MOD128, &st->l2.flag)) | ||
166 | p1 = (st->l2.vs - st->l2.va) % 128; | ||
167 | else | ||
168 | p1 = (st->l2.vs - st->l2.va) % 8; | ||
169 | return ((p1 < st->l2.window) && !test_bit(FLG_PEER_BUSY, &st->l2.flag)); | ||
170 | } | ||
171 | |||
172 | inline void | ||
173 | clear_exception(struct Layer2 *l2) | ||
174 | { | ||
175 | test_and_clear_bit(FLG_ACK_PEND, &l2->flag); | ||
176 | test_and_clear_bit(FLG_REJEXC, &l2->flag); | ||
177 | test_and_clear_bit(FLG_OWN_BUSY, &l2->flag); | ||
178 | clear_peer_busy(l2); | ||
179 | } | ||
180 | |||
181 | inline int | ||
182 | l2headersize(struct Layer2 *l2, int ui) | ||
183 | { | ||
184 | return (((test_bit(FLG_MOD128, &l2->flag) && (!ui)) ? 2 : 1) + | ||
185 | (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1)); | ||
186 | } | ||
187 | |||
188 | inline int | ||
189 | l2addrsize(struct Layer2 *l2) | ||
190 | { | ||
191 | return (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1); | ||
192 | } | ||
193 | |||
194 | static int | ||
195 | sethdraddr(struct Layer2 *l2, u_char * header, int rsp) | ||
196 | { | ||
197 | u_char *ptr = header; | ||
198 | int crbit = rsp; | ||
199 | |||
200 | if (test_bit(FLG_LAPD, &l2->flag)) { | ||
201 | *ptr++ = (l2->sap << 2) | (rsp ? 2 : 0); | ||
202 | *ptr++ = (l2->tei << 1) | 1; | ||
203 | return (2); | ||
204 | } else { | ||
205 | if (test_bit(FLG_ORIG, &l2->flag)) | ||
206 | crbit = !crbit; | ||
207 | if (crbit) | ||
208 | *ptr++ = 1; | ||
209 | else | ||
210 | *ptr++ = 3; | ||
211 | return (1); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | inline static void | ||
216 | enqueue_super(struct PStack *st, | ||
217 | struct sk_buff *skb) | ||
218 | { | ||
219 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
220 | st->l1.bcs->tx_cnt += skb->len; | ||
221 | st->l2.l2l1(st, PH_DATA | REQUEST, skb); | ||
222 | } | ||
223 | |||
224 | #define enqueue_ui(a, b) enqueue_super(a, b) | ||
225 | |||
226 | inline int | ||
227 | IsUI(u_char * data) | ||
228 | { | ||
229 | return ((data[0] & 0xef) == UI); | ||
230 | } | ||
231 | |||
232 | inline int | ||
233 | IsUA(u_char * data) | ||
234 | { | ||
235 | return ((data[0] & 0xef) == UA); | ||
236 | } | ||
237 | |||
238 | inline int | ||
239 | IsDM(u_char * data) | ||
240 | { | ||
241 | return ((data[0] & 0xef) == DM); | ||
242 | } | ||
243 | |||
244 | inline int | ||
245 | IsDISC(u_char * data) | ||
246 | { | ||
247 | return ((data[0] & 0xef) == DISC); | ||
248 | } | ||
249 | |||
250 | inline int | ||
251 | IsRR(u_char * data, struct PStack *st) | ||
252 | { | ||
253 | if (test_bit(FLG_MOD128, &st->l2.flag)) | ||
254 | return (data[0] == RR); | ||
255 | else | ||
256 | return ((data[0] & 0xf) == 1); | ||
257 | } | ||
258 | |||
259 | inline int | ||
260 | IsSFrame(u_char * data, struct PStack *st) | ||
261 | { | ||
262 | register u_char d = *data; | ||
263 | |||
264 | if (!test_bit(FLG_MOD128, &st->l2.flag)) | ||
265 | d &= 0xf; | ||
266 | return(((d & 0xf3) == 1) && ((d & 0x0c) != 0x0c)); | ||
267 | } | ||
268 | |||
269 | inline int | ||
270 | IsSABME(u_char * data, struct PStack *st) | ||
271 | { | ||
272 | u_char d = data[0] & ~0x10; | ||
273 | |||
274 | return (test_bit(FLG_MOD128, &st->l2.flag) ? d == SABME : d == SABM); | ||
275 | } | ||
276 | |||
277 | inline int | ||
278 | IsREJ(u_char * data, struct PStack *st) | ||
279 | { | ||
280 | return (test_bit(FLG_MOD128, &st->l2.flag) ? data[0] == REJ : (data[0] & 0xf) == REJ); | ||
281 | } | ||
282 | |||
283 | inline int | ||
284 | IsFRMR(u_char * data) | ||
285 | { | ||
286 | return ((data[0] & 0xef) == FRMR); | ||
287 | } | ||
288 | |||
289 | inline int | ||
290 | IsRNR(u_char * data, struct PStack *st) | ||
291 | { | ||
292 | return (test_bit(FLG_MOD128, &st->l2.flag) ? data[0] == RNR : (data[0] & 0xf) == RNR); | ||
293 | } | ||
294 | |||
295 | int | ||
296 | iframe_error(struct PStack *st, struct sk_buff *skb) | ||
297 | { | ||
298 | int i = l2addrsize(&st->l2) + (test_bit(FLG_MOD128, &st->l2.flag) ? 2 : 1); | ||
299 | int rsp = *skb->data & 0x2; | ||
300 | |||
301 | if (test_bit(FLG_ORIG, &st->l2.flag)) | ||
302 | rsp = !rsp; | ||
303 | |||
304 | if (rsp) | ||
305 | return 'L'; | ||
306 | |||
307 | |||
308 | if (skb->len < i) | ||
309 | return 'N'; | ||
310 | |||
311 | if ((skb->len - i) > st->l2.maxlen) | ||
312 | return 'O'; | ||
313 | |||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | int | ||
319 | super_error(struct PStack *st, struct sk_buff *skb) | ||
320 | { | ||
321 | if (skb->len != l2addrsize(&st->l2) + | ||
322 | (test_bit(FLG_MOD128, &st->l2.flag) ? 2 : 1)) | ||
323 | return 'N'; | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | int | ||
329 | unnum_error(struct PStack *st, struct sk_buff *skb, int wantrsp) | ||
330 | { | ||
331 | int rsp = (*skb->data & 0x2) >> 1; | ||
332 | if (test_bit(FLG_ORIG, &st->l2.flag)) | ||
333 | rsp = !rsp; | ||
334 | |||
335 | if (rsp != wantrsp) | ||
336 | return 'L'; | ||
337 | |||
338 | if (skb->len != l2addrsize(&st->l2) + 1) | ||
339 | return 'N'; | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | int | ||
345 | UI_error(struct PStack *st, struct sk_buff *skb) | ||
346 | { | ||
347 | int rsp = *skb->data & 0x2; | ||
348 | if (test_bit(FLG_ORIG, &st->l2.flag)) | ||
349 | rsp = !rsp; | ||
350 | |||
351 | if (rsp) | ||
352 | return 'L'; | ||
353 | |||
354 | if (skb->len > st->l2.maxlen + l2addrsize(&st->l2) + 1) | ||
355 | return 'O'; | ||
356 | |||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | int | ||
361 | FRMR_error(struct PStack *st, struct sk_buff *skb) | ||
362 | { | ||
363 | int headers = l2addrsize(&st->l2) + 1; | ||
364 | u_char *datap = skb->data + headers; | ||
365 | int rsp = *skb->data & 0x2; | ||
366 | |||
367 | if (test_bit(FLG_ORIG, &st->l2.flag)) | ||
368 | rsp = !rsp; | ||
369 | |||
370 | if (!rsp) | ||
371 | return 'L'; | ||
372 | |||
373 | if (test_bit(FLG_MOD128, &st->l2.flag)) { | ||
374 | if (skb->len < headers + 5) | ||
375 | return 'N'; | ||
376 | else | ||
377 | l2m_debug(&st->l2.l2m, "FRMR information %2x %2x %2x %2x %2x", | ||
378 | datap[0], datap[1], datap[2], | ||
379 | datap[3], datap[4]); | ||
380 | } else { | ||
381 | if (skb->len < headers + 3) | ||
382 | return 'N'; | ||
383 | else | ||
384 | l2m_debug(&st->l2.l2m, "FRMR information %2x %2x %2x", | ||
385 | datap[0], datap[1], datap[2]); | ||
386 | } | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | static unsigned int | ||
392 | legalnr(struct PStack *st, unsigned int nr) | ||
393 | { | ||
394 | struct Layer2 *l2 = &st->l2; | ||
395 | |||
396 | if(test_bit(FLG_MOD128, &l2->flag)) | ||
397 | return ((nr - l2->va) % 128) <= ((l2->vs - l2->va) % 128); | ||
398 | else | ||
399 | return ((nr - l2->va) % 8) <= ((l2->vs - l2->va) % 8); | ||
400 | } | ||
401 | |||
402 | static void | ||
403 | setva(struct PStack *st, unsigned int nr) | ||
404 | { | ||
405 | struct Layer2 *l2 = &st->l2; | ||
406 | int len; | ||
407 | u_long flags; | ||
408 | |||
409 | spin_lock_irqsave(&l2->lock, flags); | ||
410 | while (l2->va != nr) { | ||
411 | (l2->va)++; | ||
412 | if(test_bit(FLG_MOD128, &l2->flag)) | ||
413 | l2->va %= 128; | ||
414 | else | ||
415 | l2->va %= 8; | ||
416 | len = l2->windowar[l2->sow]->len; | ||
417 | if (PACKET_NOACK == l2->windowar[l2->sow]->pkt_type) | ||
418 | len = -1; | ||
419 | dev_kfree_skb(l2->windowar[l2->sow]); | ||
420 | l2->windowar[l2->sow] = NULL; | ||
421 | l2->sow = (l2->sow + 1) % l2->window; | ||
422 | spin_unlock_irqrestore(&l2->lock, flags); | ||
423 | if (test_bit(FLG_LLI_L2WAKEUP, &st->lli.flag) && (len >=0)) | ||
424 | lli_writewakeup(st, len); | ||
425 | spin_lock_irqsave(&l2->lock, flags); | ||
426 | } | ||
427 | spin_unlock_irqrestore(&l2->lock, flags); | ||
428 | } | ||
429 | |||
430 | static void | ||
431 | send_uframe(struct PStack *st, u_char cmd, u_char cr) | ||
432 | { | ||
433 | struct sk_buff *skb; | ||
434 | u_char tmp[MAX_HEADER_LEN]; | ||
435 | int i; | ||
436 | |||
437 | i = sethdraddr(&st->l2, tmp, cr); | ||
438 | tmp[i++] = cmd; | ||
439 | if (!(skb = alloc_skb(i, GFP_ATOMIC))) { | ||
440 | printk(KERN_WARNING "isdl2 can't alloc sbbuff for send_uframe\n"); | ||
441 | return; | ||
442 | } | ||
443 | memcpy(skb_put(skb, i), tmp, i); | ||
444 | enqueue_super(st, skb); | ||
445 | } | ||
446 | |||
447 | inline u_char | ||
448 | get_PollFlag(struct PStack * st, struct sk_buff * skb) | ||
449 | { | ||
450 | return (skb->data[l2addrsize(&(st->l2))] & 0x10); | ||
451 | } | ||
452 | |||
453 | inline void | ||
454 | FreeSkb(struct sk_buff *skb) | ||
455 | { | ||
456 | dev_kfree_skb(skb); | ||
457 | } | ||
458 | |||
459 | |||
460 | inline u_char | ||
461 | get_PollFlagFree(struct PStack *st, struct sk_buff *skb) | ||
462 | { | ||
463 | u_char PF; | ||
464 | |||
465 | PF = get_PollFlag(st, skb); | ||
466 | FreeSkb(skb); | ||
467 | return (PF); | ||
468 | } | ||
469 | |||
470 | inline void | ||
471 | start_t200(struct PStack *st, int i) | ||
472 | { | ||
473 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, i); | ||
474 | test_and_set_bit(FLG_T200_RUN, &st->l2.flag); | ||
475 | } | ||
476 | |||
477 | inline void | ||
478 | restart_t200(struct PStack *st, int i) | ||
479 | { | ||
480 | FsmRestartTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, i); | ||
481 | test_and_set_bit(FLG_T200_RUN, &st->l2.flag); | ||
482 | } | ||
483 | |||
484 | inline void | ||
485 | stop_t200(struct PStack *st, int i) | ||
486 | { | ||
487 | if(test_and_clear_bit(FLG_T200_RUN, &st->l2.flag)) | ||
488 | FsmDelTimer(&st->l2.t200, i); | ||
489 | } | ||
490 | |||
491 | inline void | ||
492 | st5_dl_release_l2l3(struct PStack *st) | ||
493 | { | ||
494 | int pr; | ||
495 | |||
496 | if(test_and_clear_bit(FLG_PEND_REL, &st->l2.flag)) | ||
497 | pr = DL_RELEASE | CONFIRM; | ||
498 | else | ||
499 | pr = DL_RELEASE | INDICATION; | ||
500 | |||
501 | st->l2.l2l3(st, pr, NULL); | ||
502 | } | ||
503 | |||
504 | inline void | ||
505 | lapb_dl_release_l2l3(struct PStack *st, int f) | ||
506 | { | ||
507 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
508 | st->l2.l2l1(st, PH_DEACTIVATE | REQUEST, NULL); | ||
509 | st->l2.l2l3(st, DL_RELEASE | f, NULL); | ||
510 | } | ||
511 | |||
512 | static void | ||
513 | establishlink(struct FsmInst *fi) | ||
514 | { | ||
515 | struct PStack *st = fi->userdata; | ||
516 | u_char cmd; | ||
517 | |||
518 | clear_exception(&st->l2); | ||
519 | st->l2.rc = 0; | ||
520 | cmd = (test_bit(FLG_MOD128, &st->l2.flag) ? SABME : SABM) | 0x10; | ||
521 | send_uframe(st, cmd, CMD); | ||
522 | FsmDelTimer(&st->l2.t203, 1); | ||
523 | restart_t200(st, 1); | ||
524 | test_and_clear_bit(FLG_PEND_REL, &st->l2.flag); | ||
525 | freewin(st); | ||
526 | FsmChangeState(fi, ST_L2_5); | ||
527 | } | ||
528 | |||
529 | static void | ||
530 | l2_mdl_error_ua(struct FsmInst *fi, int event, void *arg) | ||
531 | { | ||
532 | struct sk_buff *skb = arg; | ||
533 | struct PStack *st = fi->userdata; | ||
534 | |||
535 | if (get_PollFlagFree(st, skb)) | ||
536 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'C'); | ||
537 | else | ||
538 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'D'); | ||
539 | } | ||
540 | |||
541 | static void | ||
542 | l2_mdl_error_dm(struct FsmInst *fi, int event, void *arg) | ||
543 | { | ||
544 | struct sk_buff *skb = arg; | ||
545 | struct PStack *st = fi->userdata; | ||
546 | |||
547 | if (get_PollFlagFree(st, skb)) | ||
548 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'B'); | ||
549 | else { | ||
550 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'E'); | ||
551 | establishlink(fi); | ||
552 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | static void | ||
557 | l2_st8_mdl_error_dm(struct FsmInst *fi, int event, void *arg) | ||
558 | { | ||
559 | struct sk_buff *skb = arg; | ||
560 | struct PStack *st = fi->userdata; | ||
561 | |||
562 | if (get_PollFlagFree(st, skb)) | ||
563 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'B'); | ||
564 | else { | ||
565 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'E'); | ||
566 | } | ||
567 | establishlink(fi); | ||
568 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
569 | } | ||
570 | |||
571 | static void | ||
572 | l2_go_st3(struct FsmInst *fi, int event, void *arg) | ||
573 | { | ||
574 | FsmChangeState(fi, ST_L2_3); | ||
575 | } | ||
576 | |||
577 | static void | ||
578 | l2_mdl_assign(struct FsmInst *fi, int event, void *arg) | ||
579 | { | ||
580 | struct PStack *st = fi->userdata; | ||
581 | |||
582 | FsmChangeState(fi, ST_L2_3); | ||
583 | st->l2.l2tei(st, MDL_ASSIGN | INDICATION, NULL); | ||
584 | } | ||
585 | |||
586 | static void | ||
587 | l2_queue_ui_assign(struct FsmInst *fi, int event, void *arg) | ||
588 | { | ||
589 | struct PStack *st = fi->userdata; | ||
590 | struct sk_buff *skb = arg; | ||
591 | |||
592 | skb_queue_tail(&st->l2.ui_queue, skb); | ||
593 | FsmChangeState(fi, ST_L2_2); | ||
594 | st->l2.l2tei(st, MDL_ASSIGN | INDICATION, NULL); | ||
595 | } | ||
596 | |||
597 | static void | ||
598 | l2_queue_ui(struct FsmInst *fi, int event, void *arg) | ||
599 | { | ||
600 | struct PStack *st = fi->userdata; | ||
601 | struct sk_buff *skb = arg; | ||
602 | |||
603 | skb_queue_tail(&st->l2.ui_queue, skb); | ||
604 | } | ||
605 | |||
606 | static void | ||
607 | tx_ui(struct PStack *st) | ||
608 | { | ||
609 | struct sk_buff *skb; | ||
610 | u_char header[MAX_HEADER_LEN]; | ||
611 | int i; | ||
612 | |||
613 | i = sethdraddr(&(st->l2), header, CMD); | ||
614 | header[i++] = UI; | ||
615 | while ((skb = skb_dequeue(&st->l2.ui_queue))) { | ||
616 | memcpy(skb_push(skb, i), header, i); | ||
617 | enqueue_ui(st, skb); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | static void | ||
622 | l2_send_ui(struct FsmInst *fi, int event, void *arg) | ||
623 | { | ||
624 | struct PStack *st = fi->userdata; | ||
625 | struct sk_buff *skb = arg; | ||
626 | |||
627 | skb_queue_tail(&st->l2.ui_queue, skb); | ||
628 | tx_ui(st); | ||
629 | } | ||
630 | |||
631 | static void | ||
632 | l2_got_ui(struct FsmInst *fi, int event, void *arg) | ||
633 | { | ||
634 | struct PStack *st = fi->userdata; | ||
635 | struct sk_buff *skb = arg; | ||
636 | |||
637 | skb_pull(skb, l2headersize(&st->l2, 1)); | ||
638 | st->l2.l2l3(st, DL_UNIT_DATA | INDICATION, skb); | ||
639 | /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
640 | * in states 1-3 for broadcast | ||
641 | */ | ||
642 | |||
643 | |||
644 | } | ||
645 | |||
646 | static void | ||
647 | l2_establish(struct FsmInst *fi, int event, void *arg) | ||
648 | { | ||
649 | struct PStack *st = fi->userdata; | ||
650 | |||
651 | establishlink(fi); | ||
652 | test_and_set_bit(FLG_L3_INIT, &st->l2.flag); | ||
653 | } | ||
654 | |||
655 | static void | ||
656 | l2_discard_i_setl3(struct FsmInst *fi, int event, void *arg) | ||
657 | { | ||
658 | struct PStack *st = fi->userdata; | ||
659 | |||
660 | skb_queue_purge(&st->l2.i_queue); | ||
661 | test_and_set_bit(FLG_L3_INIT, &st->l2.flag); | ||
662 | test_and_clear_bit(FLG_PEND_REL, &st->l2.flag); | ||
663 | } | ||
664 | |||
665 | static void | ||
666 | l2_l3_reestablish(struct FsmInst *fi, int event, void *arg) | ||
667 | { | ||
668 | struct PStack *st = fi->userdata; | ||
669 | |||
670 | skb_queue_purge(&st->l2.i_queue); | ||
671 | establishlink(fi); | ||
672 | test_and_set_bit(FLG_L3_INIT, &st->l2.flag); | ||
673 | } | ||
674 | |||
675 | static void | ||
676 | l2_release(struct FsmInst *fi, int event, void *arg) | ||
677 | { | ||
678 | struct PStack *st = fi->userdata; | ||
679 | |||
680 | st->l2.l2l3(st, DL_RELEASE | CONFIRM, NULL); | ||
681 | } | ||
682 | |||
683 | static void | ||
684 | l2_pend_rel(struct FsmInst *fi, int event, void *arg) | ||
685 | { | ||
686 | struct PStack *st = fi->userdata; | ||
687 | |||
688 | test_and_set_bit(FLG_PEND_REL, &st->l2.flag); | ||
689 | } | ||
690 | |||
691 | static void | ||
692 | l2_disconnect(struct FsmInst *fi, int event, void *arg) | ||
693 | { | ||
694 | struct PStack *st = fi->userdata; | ||
695 | |||
696 | skb_queue_purge(&st->l2.i_queue); | ||
697 | freewin(st); | ||
698 | FsmChangeState(fi, ST_L2_6); | ||
699 | st->l2.rc = 0; | ||
700 | send_uframe(st, DISC | 0x10, CMD); | ||
701 | FsmDelTimer(&st->l2.t203, 1); | ||
702 | restart_t200(st, 2); | ||
703 | } | ||
704 | |||
705 | static void | ||
706 | l2_start_multi(struct FsmInst *fi, int event, void *arg) | ||
707 | { | ||
708 | struct PStack *st = fi->userdata; | ||
709 | struct sk_buff *skb = arg; | ||
710 | |||
711 | send_uframe(st, UA | get_PollFlagFree(st, skb), RSP); | ||
712 | |||
713 | clear_exception(&st->l2); | ||
714 | st->l2.vs = 0; | ||
715 | st->l2.va = 0; | ||
716 | st->l2.vr = 0; | ||
717 | st->l2.sow = 0; | ||
718 | FsmChangeState(fi, ST_L2_7); | ||
719 | FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 3); | ||
720 | |||
721 | st->l2.l2l3(st, DL_ESTABLISH | INDICATION, NULL); | ||
722 | } | ||
723 | |||
724 | static void | ||
725 | l2_send_UA(struct FsmInst *fi, int event, void *arg) | ||
726 | { | ||
727 | struct PStack *st = fi->userdata; | ||
728 | struct sk_buff *skb = arg; | ||
729 | |||
730 | send_uframe(st, UA | get_PollFlagFree(st, skb), RSP); | ||
731 | } | ||
732 | |||
733 | static void | ||
734 | l2_send_DM(struct FsmInst *fi, int event, void *arg) | ||
735 | { | ||
736 | struct PStack *st = fi->userdata; | ||
737 | struct sk_buff *skb = arg; | ||
738 | |||
739 | send_uframe(st, DM | get_PollFlagFree(st, skb), RSP); | ||
740 | } | ||
741 | |||
742 | static void | ||
743 | l2_restart_multi(struct FsmInst *fi, int event, void *arg) | ||
744 | { | ||
745 | struct PStack *st = fi->userdata; | ||
746 | struct sk_buff *skb = arg; | ||
747 | int est = 0, state; | ||
748 | |||
749 | state = fi->state; | ||
750 | |||
751 | send_uframe(st, UA | get_PollFlagFree(st, skb), RSP); | ||
752 | |||
753 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'F'); | ||
754 | |||
755 | if (st->l2.vs != st->l2.va) { | ||
756 | skb_queue_purge(&st->l2.i_queue); | ||
757 | est = 1; | ||
758 | } | ||
759 | |||
760 | clear_exception(&st->l2); | ||
761 | st->l2.vs = 0; | ||
762 | st->l2.va = 0; | ||
763 | st->l2.vr = 0; | ||
764 | st->l2.sow = 0; | ||
765 | FsmChangeState(fi, ST_L2_7); | ||
766 | stop_t200(st, 3); | ||
767 | FsmRestartTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 3); | ||
768 | |||
769 | if (est) | ||
770 | st->l2.l2l3(st, DL_ESTABLISH | INDICATION, NULL); | ||
771 | |||
772 | if ((ST_L2_7==state) || (ST_L2_8 == state)) | ||
773 | if (skb_queue_len(&st->l2.i_queue) && cansend(st)) | ||
774 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
775 | } | ||
776 | |||
777 | static void | ||
778 | l2_stop_multi(struct FsmInst *fi, int event, void *arg) | ||
779 | { | ||
780 | struct PStack *st = fi->userdata; | ||
781 | struct sk_buff *skb = arg; | ||
782 | |||
783 | FsmChangeState(fi, ST_L2_4); | ||
784 | FsmDelTimer(&st->l2.t203, 3); | ||
785 | stop_t200(st, 4); | ||
786 | |||
787 | send_uframe(st, UA | get_PollFlagFree(st, skb), RSP); | ||
788 | |||
789 | skb_queue_purge(&st->l2.i_queue); | ||
790 | freewin(st); | ||
791 | lapb_dl_release_l2l3(st, INDICATION); | ||
792 | } | ||
793 | |||
794 | static void | ||
795 | l2_connected(struct FsmInst *fi, int event, void *arg) | ||
796 | { | ||
797 | struct PStack *st = fi->userdata; | ||
798 | struct sk_buff *skb = arg; | ||
799 | int pr=-1; | ||
800 | |||
801 | if (!get_PollFlag(st, skb)) { | ||
802 | l2_mdl_error_ua(fi, event, arg); | ||
803 | return; | ||
804 | } | ||
805 | FreeSkb(skb); | ||
806 | |||
807 | if (test_and_clear_bit(FLG_PEND_REL, &st->l2.flag)) | ||
808 | l2_disconnect(fi, event, arg); | ||
809 | |||
810 | if (test_and_clear_bit(FLG_L3_INIT, &st->l2.flag)) { | ||
811 | pr = DL_ESTABLISH | CONFIRM; | ||
812 | } else if (st->l2.vs != st->l2.va) { | ||
813 | skb_queue_purge(&st->l2.i_queue); | ||
814 | pr = DL_ESTABLISH | INDICATION; | ||
815 | } | ||
816 | |||
817 | stop_t200(st, 5); | ||
818 | |||
819 | st->l2.vr = 0; | ||
820 | st->l2.vs = 0; | ||
821 | st->l2.va = 0; | ||
822 | st->l2.sow = 0; | ||
823 | FsmChangeState(fi, ST_L2_7); | ||
824 | FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 4); | ||
825 | |||
826 | if (pr != -1) | ||
827 | st->l2.l2l3(st, pr, NULL); | ||
828 | |||
829 | if (skb_queue_len(&st->l2.i_queue) && cansend(st)) | ||
830 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
831 | } | ||
832 | |||
833 | static void | ||
834 | l2_released(struct FsmInst *fi, int event, void *arg) | ||
835 | { | ||
836 | struct PStack *st = fi->userdata; | ||
837 | struct sk_buff *skb = arg; | ||
838 | |||
839 | if (!get_PollFlag(st, skb)) { | ||
840 | l2_mdl_error_ua(fi, event, arg); | ||
841 | return; | ||
842 | } | ||
843 | FreeSkb(skb); | ||
844 | |||
845 | stop_t200(st, 6); | ||
846 | lapb_dl_release_l2l3(st, CONFIRM); | ||
847 | FsmChangeState(fi, ST_L2_4); | ||
848 | } | ||
849 | |||
850 | static void | ||
851 | l2_reestablish(struct FsmInst *fi, int event, void *arg) | ||
852 | { | ||
853 | struct PStack *st = fi->userdata; | ||
854 | struct sk_buff *skb = arg; | ||
855 | |||
856 | if (!get_PollFlagFree(st, skb)) { | ||
857 | establishlink(fi); | ||
858 | test_and_set_bit(FLG_L3_INIT, &st->l2.flag); | ||
859 | } | ||
860 | } | ||
861 | |||
862 | static void | ||
863 | l2_st5_dm_release(struct FsmInst *fi, int event, void *arg) | ||
864 | { | ||
865 | struct PStack *st = fi->userdata; | ||
866 | struct sk_buff *skb = arg; | ||
867 | |||
868 | if (get_PollFlagFree(st, skb)) { | ||
869 | stop_t200(st, 7); | ||
870 | if (!test_bit(FLG_L3_INIT, &st->l2.flag)) | ||
871 | skb_queue_purge(&st->l2.i_queue); | ||
872 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
873 | st->l2.l2l1(st, PH_DEACTIVATE | REQUEST, NULL); | ||
874 | st5_dl_release_l2l3(st); | ||
875 | FsmChangeState(fi, ST_L2_4); | ||
876 | } | ||
877 | } | ||
878 | |||
879 | static void | ||
880 | l2_st6_dm_release(struct FsmInst *fi, int event, void *arg) | ||
881 | { | ||
882 | struct PStack *st = fi->userdata; | ||
883 | struct sk_buff *skb = arg; | ||
884 | |||
885 | if (get_PollFlagFree(st, skb)) { | ||
886 | stop_t200(st, 8); | ||
887 | lapb_dl_release_l2l3(st, CONFIRM); | ||
888 | FsmChangeState(fi, ST_L2_4); | ||
889 | } | ||
890 | } | ||
891 | |||
892 | inline void | ||
893 | enquiry_cr(struct PStack *st, u_char typ, u_char cr, u_char pf) | ||
894 | { | ||
895 | struct sk_buff *skb; | ||
896 | struct Layer2 *l2; | ||
897 | u_char tmp[MAX_HEADER_LEN]; | ||
898 | int i; | ||
899 | |||
900 | l2 = &st->l2; | ||
901 | i = sethdraddr(l2, tmp, cr); | ||
902 | if (test_bit(FLG_MOD128, &l2->flag)) { | ||
903 | tmp[i++] = typ; | ||
904 | tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0); | ||
905 | } else | ||
906 | tmp[i++] = (l2->vr << 5) | typ | (pf ? 0x10 : 0); | ||
907 | if (!(skb = alloc_skb(i, GFP_ATOMIC))) { | ||
908 | printk(KERN_WARNING "isdl2 can't alloc sbbuff for enquiry_cr\n"); | ||
909 | return; | ||
910 | } | ||
911 | memcpy(skb_put(skb, i), tmp, i); | ||
912 | enqueue_super(st, skb); | ||
913 | } | ||
914 | |||
915 | inline void | ||
916 | enquiry_response(struct PStack *st) | ||
917 | { | ||
918 | if (test_bit(FLG_OWN_BUSY, &st->l2.flag)) | ||
919 | enquiry_cr(st, RNR, RSP, 1); | ||
920 | else | ||
921 | enquiry_cr(st, RR, RSP, 1); | ||
922 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | ||
923 | } | ||
924 | |||
925 | inline void | ||
926 | transmit_enquiry(struct PStack *st) | ||
927 | { | ||
928 | if (test_bit(FLG_OWN_BUSY, &st->l2.flag)) | ||
929 | enquiry_cr(st, RNR, CMD, 1); | ||
930 | else | ||
931 | enquiry_cr(st, RR, CMD, 1); | ||
932 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | ||
933 | start_t200(st, 9); | ||
934 | } | ||
935 | |||
936 | |||
937 | static void | ||
938 | nrerrorrecovery(struct FsmInst *fi) | ||
939 | { | ||
940 | struct PStack *st = fi->userdata; | ||
941 | |||
942 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'J'); | ||
943 | establishlink(fi); | ||
944 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
945 | } | ||
946 | |||
947 | static void | ||
948 | invoke_retransmission(struct PStack *st, unsigned int nr) | ||
949 | { | ||
950 | struct Layer2 *l2 = &st->l2; | ||
951 | u_int p1; | ||
952 | u_long flags; | ||
953 | |||
954 | spin_lock_irqsave(&l2->lock, flags); | ||
955 | if (l2->vs != nr) { | ||
956 | while (l2->vs != nr) { | ||
957 | (l2->vs)--; | ||
958 | if(test_bit(FLG_MOD128, &l2->flag)) { | ||
959 | l2->vs %= 128; | ||
960 | p1 = (l2->vs - l2->va) % 128; | ||
961 | } else { | ||
962 | l2->vs %= 8; | ||
963 | p1 = (l2->vs - l2->va) % 8; | ||
964 | } | ||
965 | p1 = (p1 + l2->sow) % l2->window; | ||
966 | if (test_bit(FLG_LAPB, &l2->flag)) | ||
967 | st->l1.bcs->tx_cnt += l2->windowar[p1]->len + l2headersize(l2, 0); | ||
968 | skb_queue_head(&l2->i_queue, l2->windowar[p1]); | ||
969 | l2->windowar[p1] = NULL; | ||
970 | } | ||
971 | spin_unlock_irqrestore(&l2->lock, flags); | ||
972 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
973 | return; | ||
974 | } | ||
975 | spin_unlock_irqrestore(&l2->lock, flags); | ||
976 | } | ||
977 | |||
978 | static void | ||
979 | l2_st7_got_super(struct FsmInst *fi, int event, void *arg) | ||
980 | { | ||
981 | struct PStack *st = fi->userdata; | ||
982 | struct sk_buff *skb = arg; | ||
983 | int PollFlag, rsp, typ = RR; | ||
984 | unsigned int nr; | ||
985 | struct Layer2 *l2 = &st->l2; | ||
986 | |||
987 | rsp = *skb->data & 0x2; | ||
988 | if (test_bit(FLG_ORIG, &l2->flag)) | ||
989 | rsp = !rsp; | ||
990 | |||
991 | skb_pull(skb, l2addrsize(l2)); | ||
992 | if (IsRNR(skb->data, st)) { | ||
993 | set_peer_busy(l2); | ||
994 | typ = RNR; | ||
995 | } else | ||
996 | clear_peer_busy(l2); | ||
997 | if (IsREJ(skb->data, st)) | ||
998 | typ = REJ; | ||
999 | |||
1000 | if (test_bit(FLG_MOD128, &l2->flag)) { | ||
1001 | PollFlag = (skb->data[1] & 0x1) == 0x1; | ||
1002 | nr = skb->data[1] >> 1; | ||
1003 | } else { | ||
1004 | PollFlag = (skb->data[0] & 0x10); | ||
1005 | nr = (skb->data[0] >> 5) & 0x7; | ||
1006 | } | ||
1007 | FreeSkb(skb); | ||
1008 | |||
1009 | if (PollFlag) { | ||
1010 | if (rsp) | ||
1011 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'A'); | ||
1012 | else | ||
1013 | enquiry_response(st); | ||
1014 | } | ||
1015 | if (legalnr(st, nr)) { | ||
1016 | if (typ == REJ) { | ||
1017 | setva(st, nr); | ||
1018 | invoke_retransmission(st, nr); | ||
1019 | stop_t200(st, 10); | ||
1020 | if (FsmAddTimer(&st->l2.t203, st->l2.T203, | ||
1021 | EV_L2_T203, NULL, 6)) | ||
1022 | l2m_debug(&st->l2.l2m, "Restart T203 ST7 REJ"); | ||
1023 | } else if ((nr == l2->vs) && (typ == RR)) { | ||
1024 | setva(st, nr); | ||
1025 | stop_t200(st, 11); | ||
1026 | FsmRestartTimer(&st->l2.t203, st->l2.T203, | ||
1027 | EV_L2_T203, NULL, 7); | ||
1028 | } else if ((l2->va != nr) || (typ == RNR)) { | ||
1029 | setva(st, nr); | ||
1030 | if(typ != RR) FsmDelTimer(&st->l2.t203, 9); | ||
1031 | restart_t200(st, 12); | ||
1032 | } | ||
1033 | if (skb_queue_len(&st->l2.i_queue) && (typ == RR)) | ||
1034 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
1035 | } else | ||
1036 | nrerrorrecovery(fi); | ||
1037 | } | ||
1038 | |||
1039 | static void | ||
1040 | l2_feed_i_if_reest(struct FsmInst *fi, int event, void *arg) | ||
1041 | { | ||
1042 | struct PStack *st = fi->userdata; | ||
1043 | struct sk_buff *skb = arg; | ||
1044 | |||
1045 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
1046 | st->l1.bcs->tx_cnt += skb->len + l2headersize(&st->l2, 0); | ||
1047 | if (!test_bit(FLG_L3_INIT, &st->l2.flag)) | ||
1048 | skb_queue_tail(&st->l2.i_queue, skb); | ||
1049 | else | ||
1050 | FreeSkb(skb); | ||
1051 | } | ||
1052 | |||
1053 | static void | ||
1054 | l2_feed_i_pull(struct FsmInst *fi, int event, void *arg) | ||
1055 | { | ||
1056 | struct PStack *st = fi->userdata; | ||
1057 | struct sk_buff *skb = arg; | ||
1058 | |||
1059 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
1060 | st->l1.bcs->tx_cnt += skb->len + l2headersize(&st->l2, 0); | ||
1061 | skb_queue_tail(&st->l2.i_queue, skb); | ||
1062 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
1063 | } | ||
1064 | |||
1065 | static void | ||
1066 | l2_feed_iqueue(struct FsmInst *fi, int event, void *arg) | ||
1067 | { | ||
1068 | struct PStack *st = fi->userdata; | ||
1069 | struct sk_buff *skb = arg; | ||
1070 | |||
1071 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
1072 | st->l1.bcs->tx_cnt += skb->len + l2headersize(&st->l2, 0); | ||
1073 | skb_queue_tail(&st->l2.i_queue, skb); | ||
1074 | } | ||
1075 | |||
1076 | static void | ||
1077 | l2_got_iframe(struct FsmInst *fi, int event, void *arg) | ||
1078 | { | ||
1079 | struct PStack *st = fi->userdata; | ||
1080 | struct sk_buff *skb = arg; | ||
1081 | struct Layer2 *l2 = &(st->l2); | ||
1082 | int PollFlag, ns, i; | ||
1083 | unsigned int nr; | ||
1084 | |||
1085 | i = l2addrsize(l2); | ||
1086 | if (test_bit(FLG_MOD128, &l2->flag)) { | ||
1087 | PollFlag = ((skb->data[i + 1] & 0x1) == 0x1); | ||
1088 | ns = skb->data[i] >> 1; | ||
1089 | nr = (skb->data[i + 1] >> 1) & 0x7f; | ||
1090 | } else { | ||
1091 | PollFlag = (skb->data[i] & 0x10); | ||
1092 | ns = (skb->data[i] >> 1) & 0x7; | ||
1093 | nr = (skb->data[i] >> 5) & 0x7; | ||
1094 | } | ||
1095 | if (test_bit(FLG_OWN_BUSY, &l2->flag)) { | ||
1096 | FreeSkb(skb); | ||
1097 | if(PollFlag) enquiry_response(st); | ||
1098 | } else if (l2->vr == ns) { | ||
1099 | (l2->vr)++; | ||
1100 | if(test_bit(FLG_MOD128, &l2->flag)) | ||
1101 | l2->vr %= 128; | ||
1102 | else | ||
1103 | l2->vr %= 8; | ||
1104 | test_and_clear_bit(FLG_REJEXC, &l2->flag); | ||
1105 | |||
1106 | if (PollFlag) | ||
1107 | enquiry_response(st); | ||
1108 | else | ||
1109 | test_and_set_bit(FLG_ACK_PEND, &l2->flag); | ||
1110 | skb_pull(skb, l2headersize(l2, 0)); | ||
1111 | st->l2.l2l3(st, DL_DATA | INDICATION, skb); | ||
1112 | } else { | ||
1113 | /* n(s)!=v(r) */ | ||
1114 | FreeSkb(skb); | ||
1115 | if (test_and_set_bit(FLG_REJEXC, &l2->flag)) { | ||
1116 | if (PollFlag) | ||
1117 | enquiry_response(st); | ||
1118 | } else { | ||
1119 | enquiry_cr(st, REJ, RSP, PollFlag); | ||
1120 | test_and_clear_bit(FLG_ACK_PEND, &l2->flag); | ||
1121 | } | ||
1122 | } | ||
1123 | |||
1124 | if (legalnr(st, nr)) { | ||
1125 | if (!test_bit(FLG_PEER_BUSY, &st->l2.flag) && (fi->state == ST_L2_7)) { | ||
1126 | if (nr == st->l2.vs) { | ||
1127 | stop_t200(st, 13); | ||
1128 | FsmRestartTimer(&st->l2.t203, st->l2.T203, | ||
1129 | EV_L2_T203, NULL, 7); | ||
1130 | } else if (nr != st->l2.va) | ||
1131 | restart_t200(st, 14); | ||
1132 | } | ||
1133 | setva(st, nr); | ||
1134 | } else { | ||
1135 | nrerrorrecovery(fi); | ||
1136 | return; | ||
1137 | } | ||
1138 | |||
1139 | if (skb_queue_len(&st->l2.i_queue) && (fi->state == ST_L2_7)) | ||
1140 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
1141 | if (test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag)) | ||
1142 | enquiry_cr(st, RR, RSP, 0); | ||
1143 | } | ||
1144 | |||
1145 | static void | ||
1146 | l2_got_tei(struct FsmInst *fi, int event, void *arg) | ||
1147 | { | ||
1148 | struct PStack *st = fi->userdata; | ||
1149 | |||
1150 | st->l2.tei = (long) arg; | ||
1151 | |||
1152 | if (fi->state == ST_L2_3) { | ||
1153 | establishlink(fi); | ||
1154 | test_and_set_bit(FLG_L3_INIT, &st->l2.flag); | ||
1155 | } else | ||
1156 | FsmChangeState(fi, ST_L2_4); | ||
1157 | if (skb_queue_len(&st->l2.ui_queue)) | ||
1158 | tx_ui(st); | ||
1159 | } | ||
1160 | |||
1161 | static void | ||
1162 | l2_st5_tout_200(struct FsmInst *fi, int event, void *arg) | ||
1163 | { | ||
1164 | struct PStack *st = fi->userdata; | ||
1165 | |||
1166 | if (test_bit(FLG_LAPD, &st->l2.flag) && | ||
1167 | test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) { | ||
1168 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9); | ||
1169 | } else if (st->l2.rc == st->l2.N200) { | ||
1170 | FsmChangeState(fi, ST_L2_4); | ||
1171 | test_and_clear_bit(FLG_T200_RUN, &st->l2.flag); | ||
1172 | skb_queue_purge(&st->l2.i_queue); | ||
1173 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'G'); | ||
1174 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
1175 | st->l2.l2l1(st, PH_DEACTIVATE | REQUEST, NULL); | ||
1176 | st5_dl_release_l2l3(st); | ||
1177 | } else { | ||
1178 | st->l2.rc++; | ||
1179 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9); | ||
1180 | send_uframe(st, (test_bit(FLG_MOD128, &st->l2.flag) ? SABME : SABM) | ||
1181 | | 0x10, CMD); | ||
1182 | } | ||
1183 | } | ||
1184 | |||
1185 | static void | ||
1186 | l2_st6_tout_200(struct FsmInst *fi, int event, void *arg) | ||
1187 | { | ||
1188 | struct PStack *st = fi->userdata; | ||
1189 | |||
1190 | if (test_bit(FLG_LAPD, &st->l2.flag) && | ||
1191 | test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) { | ||
1192 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9); | ||
1193 | } else if (st->l2.rc == st->l2.N200) { | ||
1194 | FsmChangeState(fi, ST_L2_4); | ||
1195 | test_and_clear_bit(FLG_T200_RUN, &st->l2.flag); | ||
1196 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'H'); | ||
1197 | lapb_dl_release_l2l3(st, CONFIRM); | ||
1198 | } else { | ||
1199 | st->l2.rc++; | ||
1200 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, | ||
1201 | NULL, 9); | ||
1202 | send_uframe(st, DISC | 0x10, CMD); | ||
1203 | } | ||
1204 | } | ||
1205 | |||
1206 | static void | ||
1207 | l2_st7_tout_200(struct FsmInst *fi, int event, void *arg) | ||
1208 | { | ||
1209 | struct PStack *st = fi->userdata; | ||
1210 | |||
1211 | if (test_bit(FLG_LAPD, &st->l2.flag) && | ||
1212 | test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) { | ||
1213 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9); | ||
1214 | return; | ||
1215 | } | ||
1216 | test_and_clear_bit(FLG_T200_RUN, &st->l2.flag); | ||
1217 | st->l2.rc = 0; | ||
1218 | FsmChangeState(fi, ST_L2_8); | ||
1219 | |||
1220 | transmit_enquiry(st); | ||
1221 | st->l2.rc++; | ||
1222 | } | ||
1223 | |||
1224 | static void | ||
1225 | l2_st8_tout_200(struct FsmInst *fi, int event, void *arg) | ||
1226 | { | ||
1227 | struct PStack *st = fi->userdata; | ||
1228 | |||
1229 | if (test_bit(FLG_LAPD, &st->l2.flag) && | ||
1230 | test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) { | ||
1231 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 9); | ||
1232 | return; | ||
1233 | } | ||
1234 | test_and_clear_bit(FLG_T200_RUN, &st->l2.flag); | ||
1235 | if (st->l2.rc == st->l2.N200) { | ||
1236 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'I'); | ||
1237 | establishlink(fi); | ||
1238 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
1239 | } else { | ||
1240 | transmit_enquiry(st); | ||
1241 | st->l2.rc++; | ||
1242 | } | ||
1243 | } | ||
1244 | |||
1245 | static void | ||
1246 | l2_st7_tout_203(struct FsmInst *fi, int event, void *arg) | ||
1247 | { | ||
1248 | struct PStack *st = fi->userdata; | ||
1249 | |||
1250 | if (test_bit(FLG_LAPD, &st->l2.flag) && | ||
1251 | test_bit(FLG_DCHAN_BUSY, &st->l2.flag)) { | ||
1252 | FsmAddTimer(&st->l2.t203, st->l2.T203, EV_L2_T203, NULL, 9); | ||
1253 | return; | ||
1254 | } | ||
1255 | FsmChangeState(fi, ST_L2_8); | ||
1256 | transmit_enquiry(st); | ||
1257 | st->l2.rc = 0; | ||
1258 | } | ||
1259 | |||
1260 | static void | ||
1261 | l2_pull_iqueue(struct FsmInst *fi, int event, void *arg) | ||
1262 | { | ||
1263 | struct PStack *st = fi->userdata; | ||
1264 | struct sk_buff *skb, *oskb; | ||
1265 | struct Layer2 *l2 = &st->l2; | ||
1266 | u_char header[MAX_HEADER_LEN]; | ||
1267 | int i; | ||
1268 | int unsigned p1; | ||
1269 | u_long flags; | ||
1270 | |||
1271 | if (!cansend(st)) | ||
1272 | return; | ||
1273 | |||
1274 | skb = skb_dequeue(&l2->i_queue); | ||
1275 | if (!skb) | ||
1276 | return; | ||
1277 | |||
1278 | spin_lock_irqsave(&l2->lock, flags); | ||
1279 | if(test_bit(FLG_MOD128, &l2->flag)) | ||
1280 | p1 = (l2->vs - l2->va) % 128; | ||
1281 | else | ||
1282 | p1 = (l2->vs - l2->va) % 8; | ||
1283 | p1 = (p1 + l2->sow) % l2->window; | ||
1284 | if (l2->windowar[p1]) { | ||
1285 | printk(KERN_WARNING "isdnl2 try overwrite ack queue entry %d\n", | ||
1286 | p1); | ||
1287 | dev_kfree_skb(l2->windowar[p1]); | ||
1288 | } | ||
1289 | l2->windowar[p1] = skb_clone(skb, GFP_ATOMIC); | ||
1290 | |||
1291 | i = sethdraddr(&st->l2, header, CMD); | ||
1292 | |||
1293 | if (test_bit(FLG_MOD128, &l2->flag)) { | ||
1294 | header[i++] = l2->vs << 1; | ||
1295 | header[i++] = l2->vr << 1; | ||
1296 | l2->vs = (l2->vs + 1) % 128; | ||
1297 | } else { | ||
1298 | header[i++] = (l2->vr << 5) | (l2->vs << 1); | ||
1299 | l2->vs = (l2->vs + 1) % 8; | ||
1300 | } | ||
1301 | spin_unlock_irqrestore(&l2->lock, flags); | ||
1302 | p1 = skb->data - skb->head; | ||
1303 | if (p1 >= i) | ||
1304 | memcpy(skb_push(skb, i), header, i); | ||
1305 | else { | ||
1306 | printk(KERN_WARNING | ||
1307 | "isdl2 pull_iqueue skb header(%d/%d) too short\n", i, p1); | ||
1308 | oskb = skb; | ||
1309 | skb = alloc_skb(oskb->len + i, GFP_ATOMIC); | ||
1310 | memcpy(skb_put(skb, i), header, i); | ||
1311 | memcpy(skb_put(skb, oskb->len), oskb->data, oskb->len); | ||
1312 | FreeSkb(oskb); | ||
1313 | } | ||
1314 | st->l2.l2l1(st, PH_PULL | INDICATION, skb); | ||
1315 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | ||
1316 | if (!test_and_set_bit(FLG_T200_RUN, &st->l2.flag)) { | ||
1317 | FsmDelTimer(&st->l2.t203, 13); | ||
1318 | FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 11); | ||
1319 | } | ||
1320 | if (skb_queue_len(&l2->i_queue) && cansend(st)) | ||
1321 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
1322 | } | ||
1323 | |||
1324 | static void | ||
1325 | l2_st8_got_super(struct FsmInst *fi, int event, void *arg) | ||
1326 | { | ||
1327 | struct PStack *st = fi->userdata; | ||
1328 | struct sk_buff *skb = arg; | ||
1329 | int PollFlag, rsp, rnr = 0; | ||
1330 | unsigned int nr; | ||
1331 | struct Layer2 *l2 = &st->l2; | ||
1332 | |||
1333 | rsp = *skb->data & 0x2; | ||
1334 | if (test_bit(FLG_ORIG, &l2->flag)) | ||
1335 | rsp = !rsp; | ||
1336 | |||
1337 | skb_pull(skb, l2addrsize(l2)); | ||
1338 | |||
1339 | if (IsRNR(skb->data, st)) { | ||
1340 | set_peer_busy(l2); | ||
1341 | rnr = 1; | ||
1342 | } else | ||
1343 | clear_peer_busy(l2); | ||
1344 | |||
1345 | if (test_bit(FLG_MOD128, &l2->flag)) { | ||
1346 | PollFlag = (skb->data[1] & 0x1) == 0x1; | ||
1347 | nr = skb->data[1] >> 1; | ||
1348 | } else { | ||
1349 | PollFlag = (skb->data[0] & 0x10); | ||
1350 | nr = (skb->data[0] >> 5) & 0x7; | ||
1351 | } | ||
1352 | FreeSkb(skb); | ||
1353 | |||
1354 | if (rsp && PollFlag) { | ||
1355 | if (legalnr(st, nr)) { | ||
1356 | if (rnr) { | ||
1357 | restart_t200(st, 15); | ||
1358 | } else { | ||
1359 | stop_t200(st, 16); | ||
1360 | FsmAddTimer(&l2->t203, l2->T203, | ||
1361 | EV_L2_T203, NULL, 5); | ||
1362 | setva(st, nr); | ||
1363 | } | ||
1364 | invoke_retransmission(st, nr); | ||
1365 | FsmChangeState(fi, ST_L2_7); | ||
1366 | if (skb_queue_len(&l2->i_queue) && cansend(st)) | ||
1367 | st->l2.l2l1(st, PH_PULL | REQUEST, NULL); | ||
1368 | } else | ||
1369 | nrerrorrecovery(fi); | ||
1370 | } else { | ||
1371 | if (!rsp && PollFlag) | ||
1372 | enquiry_response(st); | ||
1373 | if (legalnr(st, nr)) { | ||
1374 | setva(st, nr); | ||
1375 | } else | ||
1376 | nrerrorrecovery(fi); | ||
1377 | } | ||
1378 | } | ||
1379 | |||
1380 | static void | ||
1381 | l2_got_FRMR(struct FsmInst *fi, int event, void *arg) | ||
1382 | { | ||
1383 | struct PStack *st = fi->userdata; | ||
1384 | struct sk_buff *skb = arg; | ||
1385 | |||
1386 | skb_pull(skb, l2addrsize(&st->l2) + 1); | ||
1387 | |||
1388 | if (!(skb->data[0] & 1) || ((skb->data[0] & 3) == 1) || /* I or S */ | ||
1389 | (IsUA(skb->data) && (fi->state == ST_L2_7))) { | ||
1390 | st->ma.layer(st, MDL_ERROR | INDICATION, (void *) 'K'); | ||
1391 | establishlink(fi); | ||
1392 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
1393 | } | ||
1394 | FreeSkb(skb); | ||
1395 | } | ||
1396 | |||
1397 | static void | ||
1398 | l2_st24_tei_remove(struct FsmInst *fi, int event, void *arg) | ||
1399 | { | ||
1400 | struct PStack *st = fi->userdata; | ||
1401 | |||
1402 | skb_queue_purge(&st->l2.ui_queue); | ||
1403 | st->l2.tei = -1; | ||
1404 | FsmChangeState(fi, ST_L2_1); | ||
1405 | } | ||
1406 | |||
1407 | static void | ||
1408 | l2_st3_tei_remove(struct FsmInst *fi, int event, void *arg) | ||
1409 | { | ||
1410 | struct PStack *st = fi->userdata; | ||
1411 | |||
1412 | skb_queue_purge(&st->l2.ui_queue); | ||
1413 | st->l2.tei = -1; | ||
1414 | st->l2.l2l3(st, DL_RELEASE | INDICATION, NULL); | ||
1415 | FsmChangeState(fi, ST_L2_1); | ||
1416 | } | ||
1417 | |||
1418 | static void | ||
1419 | l2_st5_tei_remove(struct FsmInst *fi, int event, void *arg) | ||
1420 | { | ||
1421 | struct PStack *st = fi->userdata; | ||
1422 | |||
1423 | skb_queue_purge(&st->l2.i_queue); | ||
1424 | skb_queue_purge(&st->l2.ui_queue); | ||
1425 | freewin(st); | ||
1426 | st->l2.tei = -1; | ||
1427 | stop_t200(st, 17); | ||
1428 | st5_dl_release_l2l3(st); | ||
1429 | FsmChangeState(fi, ST_L2_1); | ||
1430 | } | ||
1431 | |||
1432 | static void | ||
1433 | l2_st6_tei_remove(struct FsmInst *fi, int event, void *arg) | ||
1434 | { | ||
1435 | struct PStack *st = fi->userdata; | ||
1436 | |||
1437 | skb_queue_purge(&st->l2.ui_queue); | ||
1438 | st->l2.tei = -1; | ||
1439 | stop_t200(st, 18); | ||
1440 | st->l2.l2l3(st, DL_RELEASE | CONFIRM, NULL); | ||
1441 | FsmChangeState(fi, ST_L2_1); | ||
1442 | } | ||
1443 | |||
1444 | static void | ||
1445 | l2_tei_remove(struct FsmInst *fi, int event, void *arg) | ||
1446 | { | ||
1447 | struct PStack *st = fi->userdata; | ||
1448 | |||
1449 | skb_queue_purge(&st->l2.i_queue); | ||
1450 | skb_queue_purge(&st->l2.ui_queue); | ||
1451 | freewin(st); | ||
1452 | st->l2.tei = -1; | ||
1453 | stop_t200(st, 17); | ||
1454 | FsmDelTimer(&st->l2.t203, 19); | ||
1455 | st->l2.l2l3(st, DL_RELEASE | INDICATION, NULL); | ||
1456 | FsmChangeState(fi, ST_L2_1); | ||
1457 | } | ||
1458 | |||
1459 | static void | ||
1460 | l2_st14_persistant_da(struct FsmInst *fi, int event, void *arg) | ||
1461 | { | ||
1462 | struct PStack *st = fi->userdata; | ||
1463 | |||
1464 | skb_queue_purge(&st->l2.i_queue); | ||
1465 | skb_queue_purge(&st->l2.ui_queue); | ||
1466 | if (test_and_clear_bit(FLG_ESTAB_PEND, &st->l2.flag)) | ||
1467 | st->l2.l2l3(st, DL_RELEASE | INDICATION, NULL); | ||
1468 | } | ||
1469 | |||
1470 | static void | ||
1471 | l2_st5_persistant_da(struct FsmInst *fi, int event, void *arg) | ||
1472 | { | ||
1473 | struct PStack *st = fi->userdata; | ||
1474 | |||
1475 | skb_queue_purge(&st->l2.i_queue); | ||
1476 | skb_queue_purge(&st->l2.ui_queue); | ||
1477 | freewin(st); | ||
1478 | stop_t200(st, 19); | ||
1479 | st5_dl_release_l2l3(st); | ||
1480 | FsmChangeState(fi, ST_L2_4); | ||
1481 | } | ||
1482 | |||
1483 | static void | ||
1484 | l2_st6_persistant_da(struct FsmInst *fi, int event, void *arg) | ||
1485 | { | ||
1486 | struct PStack *st = fi->userdata; | ||
1487 | |||
1488 | skb_queue_purge(&st->l2.ui_queue); | ||
1489 | stop_t200(st, 20); | ||
1490 | st->l2.l2l3(st, DL_RELEASE | CONFIRM, NULL); | ||
1491 | FsmChangeState(fi, ST_L2_4); | ||
1492 | } | ||
1493 | |||
1494 | static void | ||
1495 | l2_persistant_da(struct FsmInst *fi, int event, void *arg) | ||
1496 | { | ||
1497 | struct PStack *st = fi->userdata; | ||
1498 | |||
1499 | skb_queue_purge(&st->l2.i_queue); | ||
1500 | skb_queue_purge(&st->l2.ui_queue); | ||
1501 | freewin(st); | ||
1502 | stop_t200(st, 19); | ||
1503 | FsmDelTimer(&st->l2.t203, 19); | ||
1504 | st->l2.l2l3(st, DL_RELEASE | INDICATION, NULL); | ||
1505 | FsmChangeState(fi, ST_L2_4); | ||
1506 | } | ||
1507 | |||
1508 | static void | ||
1509 | l2_set_own_busy(struct FsmInst *fi, int event, void *arg) | ||
1510 | { | ||
1511 | struct PStack *st = fi->userdata; | ||
1512 | |||
1513 | if(!test_and_set_bit(FLG_OWN_BUSY, &st->l2.flag)) { | ||
1514 | enquiry_cr(st, RNR, RSP, 0); | ||
1515 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | ||
1516 | } | ||
1517 | } | ||
1518 | |||
1519 | static void | ||
1520 | l2_clear_own_busy(struct FsmInst *fi, int event, void *arg) | ||
1521 | { | ||
1522 | struct PStack *st = fi->userdata; | ||
1523 | |||
1524 | if(!test_and_clear_bit(FLG_OWN_BUSY, &st->l2.flag)) { | ||
1525 | enquiry_cr(st, RR, RSP, 0); | ||
1526 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | ||
1527 | } | ||
1528 | } | ||
1529 | |||
1530 | static void | ||
1531 | l2_frame_error(struct FsmInst *fi, int event, void *arg) | ||
1532 | { | ||
1533 | struct PStack *st = fi->userdata; | ||
1534 | |||
1535 | st->ma.layer(st, MDL_ERROR | INDICATION, arg); | ||
1536 | } | ||
1537 | |||
1538 | static void | ||
1539 | l2_frame_error_reest(struct FsmInst *fi, int event, void *arg) | ||
1540 | { | ||
1541 | struct PStack *st = fi->userdata; | ||
1542 | |||
1543 | st->ma.layer(st, MDL_ERROR | INDICATION, arg); | ||
1544 | establishlink(fi); | ||
1545 | test_and_clear_bit(FLG_L3_INIT, &st->l2.flag); | ||
1546 | } | ||
1547 | |||
1548 | static struct FsmNode L2FnList[] __initdata = | ||
1549 | { | ||
1550 | {ST_L2_1, EV_L2_DL_ESTABLISH_REQ, l2_mdl_assign}, | ||
1551 | {ST_L2_2, EV_L2_DL_ESTABLISH_REQ, l2_go_st3}, | ||
1552 | {ST_L2_4, EV_L2_DL_ESTABLISH_REQ, l2_establish}, | ||
1553 | {ST_L2_5, EV_L2_DL_ESTABLISH_REQ, l2_discard_i_setl3}, | ||
1554 | {ST_L2_7, EV_L2_DL_ESTABLISH_REQ, l2_l3_reestablish}, | ||
1555 | {ST_L2_8, EV_L2_DL_ESTABLISH_REQ, l2_l3_reestablish}, | ||
1556 | {ST_L2_4, EV_L2_DL_RELEASE_REQ, l2_release}, | ||
1557 | {ST_L2_5, EV_L2_DL_RELEASE_REQ, l2_pend_rel}, | ||
1558 | {ST_L2_7, EV_L2_DL_RELEASE_REQ, l2_disconnect}, | ||
1559 | {ST_L2_8, EV_L2_DL_RELEASE_REQ, l2_disconnect}, | ||
1560 | {ST_L2_5, EV_L2_DL_DATA, l2_feed_i_if_reest}, | ||
1561 | {ST_L2_7, EV_L2_DL_DATA, l2_feed_i_pull}, | ||
1562 | {ST_L2_8, EV_L2_DL_DATA, l2_feed_iqueue}, | ||
1563 | {ST_L2_1, EV_L2_DL_UNIT_DATA, l2_queue_ui_assign}, | ||
1564 | {ST_L2_2, EV_L2_DL_UNIT_DATA, l2_queue_ui}, | ||
1565 | {ST_L2_3, EV_L2_DL_UNIT_DATA, l2_queue_ui}, | ||
1566 | {ST_L2_4, EV_L2_DL_UNIT_DATA, l2_send_ui}, | ||
1567 | {ST_L2_5, EV_L2_DL_UNIT_DATA, l2_send_ui}, | ||
1568 | {ST_L2_6, EV_L2_DL_UNIT_DATA, l2_send_ui}, | ||
1569 | {ST_L2_7, EV_L2_DL_UNIT_DATA, l2_send_ui}, | ||
1570 | {ST_L2_8, EV_L2_DL_UNIT_DATA, l2_send_ui}, | ||
1571 | {ST_L2_1, EV_L2_MDL_ASSIGN, l2_got_tei}, | ||
1572 | {ST_L2_2, EV_L2_MDL_ASSIGN, l2_got_tei}, | ||
1573 | {ST_L2_3, EV_L2_MDL_ASSIGN, l2_got_tei}, | ||
1574 | {ST_L2_2, EV_L2_MDL_ERROR, l2_st24_tei_remove}, | ||
1575 | {ST_L2_3, EV_L2_MDL_ERROR, l2_st3_tei_remove}, | ||
1576 | {ST_L2_4, EV_L2_MDL_REMOVE, l2_st24_tei_remove}, | ||
1577 | {ST_L2_5, EV_L2_MDL_REMOVE, l2_st5_tei_remove}, | ||
1578 | {ST_L2_6, EV_L2_MDL_REMOVE, l2_st6_tei_remove}, | ||
1579 | {ST_L2_7, EV_L2_MDL_REMOVE, l2_tei_remove}, | ||
1580 | {ST_L2_8, EV_L2_MDL_REMOVE, l2_tei_remove}, | ||
1581 | {ST_L2_4, EV_L2_SABME, l2_start_multi}, | ||
1582 | {ST_L2_5, EV_L2_SABME, l2_send_UA}, | ||
1583 | {ST_L2_6, EV_L2_SABME, l2_send_DM}, | ||
1584 | {ST_L2_7, EV_L2_SABME, l2_restart_multi}, | ||
1585 | {ST_L2_8, EV_L2_SABME, l2_restart_multi}, | ||
1586 | {ST_L2_4, EV_L2_DISC, l2_send_DM}, | ||
1587 | {ST_L2_5, EV_L2_DISC, l2_send_DM}, | ||
1588 | {ST_L2_6, EV_L2_DISC, l2_send_UA}, | ||
1589 | {ST_L2_7, EV_L2_DISC, l2_stop_multi}, | ||
1590 | {ST_L2_8, EV_L2_DISC, l2_stop_multi}, | ||
1591 | {ST_L2_4, EV_L2_UA, l2_mdl_error_ua}, | ||
1592 | {ST_L2_5, EV_L2_UA, l2_connected}, | ||
1593 | {ST_L2_6, EV_L2_UA, l2_released}, | ||
1594 | {ST_L2_7, EV_L2_UA, l2_mdl_error_ua}, | ||
1595 | {ST_L2_8, EV_L2_UA, l2_mdl_error_ua}, | ||
1596 | {ST_L2_4, EV_L2_DM, l2_reestablish}, | ||
1597 | {ST_L2_5, EV_L2_DM, l2_st5_dm_release}, | ||
1598 | {ST_L2_6, EV_L2_DM, l2_st6_dm_release}, | ||
1599 | {ST_L2_7, EV_L2_DM, l2_mdl_error_dm}, | ||
1600 | {ST_L2_8, EV_L2_DM, l2_st8_mdl_error_dm}, | ||
1601 | {ST_L2_1, EV_L2_UI, l2_got_ui}, | ||
1602 | {ST_L2_2, EV_L2_UI, l2_got_ui}, | ||
1603 | {ST_L2_3, EV_L2_UI, l2_got_ui}, | ||
1604 | {ST_L2_4, EV_L2_UI, l2_got_ui}, | ||
1605 | {ST_L2_5, EV_L2_UI, l2_got_ui}, | ||
1606 | {ST_L2_6, EV_L2_UI, l2_got_ui}, | ||
1607 | {ST_L2_7, EV_L2_UI, l2_got_ui}, | ||
1608 | {ST_L2_8, EV_L2_UI, l2_got_ui}, | ||
1609 | {ST_L2_7, EV_L2_FRMR, l2_got_FRMR}, | ||
1610 | {ST_L2_8, EV_L2_FRMR, l2_got_FRMR}, | ||
1611 | {ST_L2_7, EV_L2_SUPER, l2_st7_got_super}, | ||
1612 | {ST_L2_8, EV_L2_SUPER, l2_st8_got_super}, | ||
1613 | {ST_L2_7, EV_L2_I, l2_got_iframe}, | ||
1614 | {ST_L2_8, EV_L2_I, l2_got_iframe}, | ||
1615 | {ST_L2_5, EV_L2_T200, l2_st5_tout_200}, | ||
1616 | {ST_L2_6, EV_L2_T200, l2_st6_tout_200}, | ||
1617 | {ST_L2_7, EV_L2_T200, l2_st7_tout_200}, | ||
1618 | {ST_L2_8, EV_L2_T200, l2_st8_tout_200}, | ||
1619 | {ST_L2_7, EV_L2_T203, l2_st7_tout_203}, | ||
1620 | {ST_L2_7, EV_L2_ACK_PULL, l2_pull_iqueue}, | ||
1621 | {ST_L2_7, EV_L2_SET_OWN_BUSY, l2_set_own_busy}, | ||
1622 | {ST_L2_8, EV_L2_SET_OWN_BUSY, l2_set_own_busy}, | ||
1623 | {ST_L2_7, EV_L2_CLEAR_OWN_BUSY, l2_clear_own_busy}, | ||
1624 | {ST_L2_8, EV_L2_CLEAR_OWN_BUSY, l2_clear_own_busy}, | ||
1625 | {ST_L2_4, EV_L2_FRAME_ERROR, l2_frame_error}, | ||
1626 | {ST_L2_5, EV_L2_FRAME_ERROR, l2_frame_error}, | ||
1627 | {ST_L2_6, EV_L2_FRAME_ERROR, l2_frame_error}, | ||
1628 | {ST_L2_7, EV_L2_FRAME_ERROR, l2_frame_error_reest}, | ||
1629 | {ST_L2_8, EV_L2_FRAME_ERROR, l2_frame_error_reest}, | ||
1630 | {ST_L2_1, EV_L1_DEACTIVATE, l2_st14_persistant_da}, | ||
1631 | {ST_L2_2, EV_L1_DEACTIVATE, l2_st24_tei_remove}, | ||
1632 | {ST_L2_3, EV_L1_DEACTIVATE, l2_st3_tei_remove}, | ||
1633 | {ST_L2_4, EV_L1_DEACTIVATE, l2_st14_persistant_da}, | ||
1634 | {ST_L2_5, EV_L1_DEACTIVATE, l2_st5_persistant_da}, | ||
1635 | {ST_L2_6, EV_L1_DEACTIVATE, l2_st6_persistant_da}, | ||
1636 | {ST_L2_7, EV_L1_DEACTIVATE, l2_persistant_da}, | ||
1637 | {ST_L2_8, EV_L1_DEACTIVATE, l2_persistant_da}, | ||
1638 | }; | ||
1639 | |||
1640 | #define L2_FN_COUNT (sizeof(L2FnList)/sizeof(struct FsmNode)) | ||
1641 | |||
1642 | static void | ||
1643 | isdnl2_l1l2(struct PStack *st, int pr, void *arg) | ||
1644 | { | ||
1645 | struct sk_buff *skb = arg; | ||
1646 | u_char *datap; | ||
1647 | int ret = 1, len; | ||
1648 | int c = 0; | ||
1649 | |||
1650 | switch (pr) { | ||
1651 | case (PH_DATA | INDICATION): | ||
1652 | datap = skb->data; | ||
1653 | len = l2addrsize(&st->l2); | ||
1654 | if (skb->len > len) | ||
1655 | datap += len; | ||
1656 | else { | ||
1657 | FsmEvent(&st->l2.l2m, EV_L2_FRAME_ERROR, (void *) 'N'); | ||
1658 | FreeSkb(skb); | ||
1659 | return; | ||
1660 | } | ||
1661 | if (!(*datap & 1)) { /* I-Frame */ | ||
1662 | if(!(c = iframe_error(st, skb))) | ||
1663 | ret = FsmEvent(&st->l2.l2m, EV_L2_I, skb); | ||
1664 | } else if (IsSFrame(datap, st)) { /* S-Frame */ | ||
1665 | if(!(c = super_error(st, skb))) | ||
1666 | ret = FsmEvent(&st->l2.l2m, EV_L2_SUPER, skb); | ||
1667 | } else if (IsUI(datap)) { | ||
1668 | if(!(c = UI_error(st, skb))) | ||
1669 | ret = FsmEvent(&st->l2.l2m, EV_L2_UI, skb); | ||
1670 | } else if (IsSABME(datap, st)) { | ||
1671 | if(!(c = unnum_error(st, skb, CMD))) | ||
1672 | ret = FsmEvent(&st->l2.l2m, EV_L2_SABME, skb); | ||
1673 | } else if (IsUA(datap)) { | ||
1674 | if(!(c = unnum_error(st, skb, RSP))) | ||
1675 | ret = FsmEvent(&st->l2.l2m, EV_L2_UA, skb); | ||
1676 | } else if (IsDISC(datap)) { | ||
1677 | if(!(c = unnum_error(st, skb, CMD))) | ||
1678 | ret = FsmEvent(&st->l2.l2m, EV_L2_DISC, skb); | ||
1679 | } else if (IsDM(datap)) { | ||
1680 | if(!(c = unnum_error(st, skb, RSP))) | ||
1681 | ret = FsmEvent(&st->l2.l2m, EV_L2_DM, skb); | ||
1682 | } else if (IsFRMR(datap)) { | ||
1683 | if(!(c = FRMR_error(st,skb))) | ||
1684 | ret = FsmEvent(&st->l2.l2m, EV_L2_FRMR, skb); | ||
1685 | } else { | ||
1686 | FsmEvent(&st->l2.l2m, EV_L2_FRAME_ERROR, (void *) 'L'); | ||
1687 | FreeSkb(skb); | ||
1688 | ret = 0; | ||
1689 | } | ||
1690 | if(c) { | ||
1691 | FreeSkb(skb); | ||
1692 | FsmEvent(&st->l2.l2m, EV_L2_FRAME_ERROR, (void *)(long)c); | ||
1693 | ret = 0; | ||
1694 | } | ||
1695 | if (ret) | ||
1696 | FreeSkb(skb); | ||
1697 | break; | ||
1698 | case (PH_PULL | CONFIRM): | ||
1699 | FsmEvent(&st->l2.l2m, EV_L2_ACK_PULL, arg); | ||
1700 | break; | ||
1701 | case (PH_PAUSE | INDICATION): | ||
1702 | test_and_set_bit(FLG_DCHAN_BUSY, &st->l2.flag); | ||
1703 | break; | ||
1704 | case (PH_PAUSE | CONFIRM): | ||
1705 | test_and_clear_bit(FLG_DCHAN_BUSY, &st->l2.flag); | ||
1706 | break; | ||
1707 | case (PH_ACTIVATE | CONFIRM): | ||
1708 | case (PH_ACTIVATE | INDICATION): | ||
1709 | test_and_set_bit(FLG_L1_ACTIV, &st->l2.flag); | ||
1710 | if (test_and_clear_bit(FLG_ESTAB_PEND, &st->l2.flag)) | ||
1711 | FsmEvent(&st->l2.l2m, EV_L2_DL_ESTABLISH_REQ, arg); | ||
1712 | break; | ||
1713 | case (PH_DEACTIVATE | INDICATION): | ||
1714 | case (PH_DEACTIVATE | CONFIRM): | ||
1715 | test_and_clear_bit(FLG_L1_ACTIV, &st->l2.flag); | ||
1716 | FsmEvent(&st->l2.l2m, EV_L1_DEACTIVATE, arg); | ||
1717 | break; | ||
1718 | default: | ||
1719 | l2m_debug(&st->l2.l2m, "l2 unknown pr %04x", pr); | ||
1720 | break; | ||
1721 | } | ||
1722 | } | ||
1723 | |||
1724 | static void | ||
1725 | isdnl2_l3l2(struct PStack *st, int pr, void *arg) | ||
1726 | { | ||
1727 | switch (pr) { | ||
1728 | case (DL_DATA | REQUEST): | ||
1729 | if (FsmEvent(&st->l2.l2m, EV_L2_DL_DATA, arg)) { | ||
1730 | dev_kfree_skb((struct sk_buff *) arg); | ||
1731 | } | ||
1732 | break; | ||
1733 | case (DL_UNIT_DATA | REQUEST): | ||
1734 | if (FsmEvent(&st->l2.l2m, EV_L2_DL_UNIT_DATA, arg)) { | ||
1735 | dev_kfree_skb((struct sk_buff *) arg); | ||
1736 | } | ||
1737 | break; | ||
1738 | case (DL_ESTABLISH | REQUEST): | ||
1739 | if (test_bit(FLG_L1_ACTIV, &st->l2.flag)) { | ||
1740 | if (test_bit(FLG_LAPD, &st->l2.flag) || | ||
1741 | test_bit(FLG_ORIG, &st->l2.flag)) { | ||
1742 | FsmEvent(&st->l2.l2m, EV_L2_DL_ESTABLISH_REQ, arg); | ||
1743 | } | ||
1744 | } else { | ||
1745 | if (test_bit(FLG_LAPD, &st->l2.flag) || | ||
1746 | test_bit(FLG_ORIG, &st->l2.flag)) { | ||
1747 | test_and_set_bit(FLG_ESTAB_PEND, &st->l2.flag); | ||
1748 | } | ||
1749 | st->l2.l2l1(st, PH_ACTIVATE, NULL); | ||
1750 | } | ||
1751 | break; | ||
1752 | case (DL_RELEASE | REQUEST): | ||
1753 | if (test_bit(FLG_LAPB, &st->l2.flag)) { | ||
1754 | st->l2.l2l1(st, PH_DEACTIVATE, NULL); | ||
1755 | } | ||
1756 | FsmEvent(&st->l2.l2m, EV_L2_DL_RELEASE_REQ, arg); | ||
1757 | break; | ||
1758 | case (MDL_ASSIGN | REQUEST): | ||
1759 | FsmEvent(&st->l2.l2m, EV_L2_MDL_ASSIGN, arg); | ||
1760 | break; | ||
1761 | case (MDL_REMOVE | REQUEST): | ||
1762 | FsmEvent(&st->l2.l2m, EV_L2_MDL_REMOVE, arg); | ||
1763 | break; | ||
1764 | case (MDL_ERROR | RESPONSE): | ||
1765 | FsmEvent(&st->l2.l2m, EV_L2_MDL_ERROR, arg); | ||
1766 | break; | ||
1767 | } | ||
1768 | } | ||
1769 | |||
1770 | void | ||
1771 | releasestack_isdnl2(struct PStack *st) | ||
1772 | { | ||
1773 | FsmDelTimer(&st->l2.t200, 21); | ||
1774 | FsmDelTimer(&st->l2.t203, 16); | ||
1775 | skb_queue_purge(&st->l2.i_queue); | ||
1776 | skb_queue_purge(&st->l2.ui_queue); | ||
1777 | ReleaseWin(&st->l2); | ||
1778 | } | ||
1779 | |||
1780 | static void | ||
1781 | l2m_debug(struct FsmInst *fi, char *fmt, ...) | ||
1782 | { | ||
1783 | va_list args; | ||
1784 | struct PStack *st = fi->userdata; | ||
1785 | |||
1786 | va_start(args, fmt); | ||
1787 | VHiSax_putstatus(st->l1.hardware, st->l2.debug_id, fmt, args); | ||
1788 | va_end(args); | ||
1789 | } | ||
1790 | |||
1791 | void | ||
1792 | setstack_isdnl2(struct PStack *st, char *debug_id) | ||
1793 | { | ||
1794 | spin_lock_init(&st->l2.lock); | ||
1795 | st->l1.l1l2 = isdnl2_l1l2; | ||
1796 | st->l3.l3l2 = isdnl2_l3l2; | ||
1797 | |||
1798 | skb_queue_head_init(&st->l2.i_queue); | ||
1799 | skb_queue_head_init(&st->l2.ui_queue); | ||
1800 | InitWin(&st->l2); | ||
1801 | st->l2.debug = 0; | ||
1802 | |||
1803 | st->l2.l2m.fsm = &l2fsm; | ||
1804 | if (test_bit(FLG_LAPB, &st->l2.flag)) | ||
1805 | st->l2.l2m.state = ST_L2_4; | ||
1806 | else | ||
1807 | st->l2.l2m.state = ST_L2_1; | ||
1808 | st->l2.l2m.debug = 0; | ||
1809 | st->l2.l2m.userdata = st; | ||
1810 | st->l2.l2m.userint = 0; | ||
1811 | st->l2.l2m.printdebug = l2m_debug; | ||
1812 | strcpy(st->l2.debug_id, debug_id); | ||
1813 | |||
1814 | FsmInitTimer(&st->l2.l2m, &st->l2.t200); | ||
1815 | FsmInitTimer(&st->l2.l2m, &st->l2.t203); | ||
1816 | } | ||
1817 | |||
1818 | static void | ||
1819 | transl2_l3l2(struct PStack *st, int pr, void *arg) | ||
1820 | { | ||
1821 | switch (pr) { | ||
1822 | case (DL_DATA | REQUEST): | ||
1823 | case (DL_UNIT_DATA | REQUEST): | ||
1824 | st->l2.l2l1(st, PH_DATA | REQUEST, arg); | ||
1825 | break; | ||
1826 | case (DL_ESTABLISH | REQUEST): | ||
1827 | st->l2.l2l1(st, PH_ACTIVATE | REQUEST, NULL); | ||
1828 | break; | ||
1829 | case (DL_RELEASE | REQUEST): | ||
1830 | st->l2.l2l1(st, PH_DEACTIVATE | REQUEST, NULL); | ||
1831 | break; | ||
1832 | } | ||
1833 | } | ||
1834 | |||
1835 | void | ||
1836 | setstack_transl2(struct PStack *st) | ||
1837 | { | ||
1838 | st->l3.l3l2 = transl2_l3l2; | ||
1839 | } | ||
1840 | |||
1841 | void | ||
1842 | releasestack_transl2(struct PStack *st) | ||
1843 | { | ||
1844 | } | ||
1845 | |||
1846 | int __init | ||
1847 | Isdnl2New(void) | ||
1848 | { | ||
1849 | l2fsm.state_count = L2_STATE_COUNT; | ||
1850 | l2fsm.event_count = L2_EVENT_COUNT; | ||
1851 | l2fsm.strEvent = strL2Event; | ||
1852 | l2fsm.strState = strL2State; | ||
1853 | return FsmNew(&l2fsm, L2FnList, L2_FN_COUNT); | ||
1854 | } | ||
1855 | |||
1856 | void | ||
1857 | Isdnl2Free(void) | ||
1858 | { | ||
1859 | FsmFree(&l2fsm); | ||
1860 | } | ||