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