1 /* $Id: isdnl2.c,v 2.30.2.4 2004/02/11 13:21:34 keil Exp $
4 * based on the teles driver from Jan den Ouden
5 * Copyright by Karsten Keil <keil@isdn4linux.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
10 * For changes and modifications please read
11 * Documentation/isdn/HiSax.cert
13 * Thanks to Jan den Ouden
18 #include <linux/init.h>
19 #include <linux/gfp.h>
23 const char *l2_revision
= "$Revision: 2.30.2.4 $";
25 static void l2m_debug(struct FsmInst
*fi
, char *fmt
, ...);
27 static struct Fsm l2fsm
;
40 #define L2_STATE_COUNT (ST_L2_8+1)
42 static char *strL2State
[] =
66 EV_L2_DL_ESTABLISH_REQ
,
79 #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR+1)
81 static char *strL2Event
[] =
94 "EV_L2_DL_ESTABLISH_REQ",
95 "EV_L2_DL_RELEASE_REQ",
102 "EV_L2_SET_OWN_BUSY",
103 "EV_L2_CLEAR_OWN_BUSY",
107 static int l2addrsize(struct Layer2
*l2
);
110 set_peer_busy(struct Layer2
*l2
) {
111 test_and_set_bit(FLG_PEER_BUSY
, &l2
->flag
);
112 if (!skb_queue_empty(&l2
->i_queue
) ||
113 !skb_queue_empty(&l2
->ui_queue
))
114 test_and_set_bit(FLG_L2BLOCK
, &l2
->flag
);
118 clear_peer_busy(struct Layer2
*l2
) {
119 if (test_and_clear_bit(FLG_PEER_BUSY
, &l2
->flag
))
120 test_and_clear_bit(FLG_L2BLOCK
, &l2
->flag
);
124 InitWin(struct Layer2
*l2
)
128 for (i
= 0; i
< MAX_WINDOW
; i
++)
129 l2
->windowar
[i
] = NULL
;
133 freewin1(struct Layer2
*l2
)
137 for (i
= 0; i
< MAX_WINDOW
; i
++) {
138 if (l2
->windowar
[i
]) {
140 dev_kfree_skb(l2
->windowar
[i
]);
141 l2
->windowar
[i
] = NULL
;
148 freewin(struct PStack
*st
)
154 ReleaseWin(struct Layer2
*l2
)
158 if((cnt
= freewin1(l2
)))
159 printk(KERN_WARNING
"isdl2 freed %d skbuffs in release\n", cnt
);
162 static inline unsigned int
163 cansend(struct PStack
*st
)
167 if(test_bit(FLG_MOD128
, &st
->l2
.flag
))
168 p1
= (st
->l2
.vs
- st
->l2
.va
) % 128;
170 p1
= (st
->l2
.vs
- st
->l2
.va
) % 8;
171 return ((p1
< st
->l2
.window
) && !test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
));
175 clear_exception(struct Layer2
*l2
)
177 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
178 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
179 test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
);
184 l2headersize(struct Layer2
*l2
, int ui
)
186 return (((test_bit(FLG_MOD128
, &l2
->flag
) && (!ui
)) ? 2 : 1) +
187 (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1));
191 l2addrsize(struct Layer2
*l2
)
193 return (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1);
197 sethdraddr(struct Layer2
*l2
, u_char
* header
, int rsp
)
199 u_char
*ptr
= header
;
202 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
203 *ptr
++ = (l2
->sap
<< 2) | (rsp
? 2 : 0);
204 *ptr
++ = (l2
->tei
<< 1) | 1;
207 if (test_bit(FLG_ORIG
, &l2
->flag
))
218 enqueue_super(struct PStack
*st
,
221 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
222 st
->l1
.bcs
->tx_cnt
+= skb
->len
;
223 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, skb
);
226 #define enqueue_ui(a, b) enqueue_super(a, b)
231 return ((data
[0] & 0xef) == UI
);
237 return ((data
[0] & 0xef) == UA
);
243 return ((data
[0] & 0xef) == DM
);
247 IsDISC(u_char
* data
)
249 return ((data
[0] & 0xef) == DISC
);
253 IsSFrame(u_char
* data
, struct PStack
*st
)
255 register u_char d
= *data
;
257 if (!test_bit(FLG_MOD128
, &st
->l2
.flag
))
259 return(((d
& 0xf3) == 1) && ((d
& 0x0c) != 0x0c));
263 IsSABME(u_char
* data
, struct PStack
*st
)
265 u_char d
= data
[0] & ~0x10;
267 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? d
== SABME
: d
== SABM
);
271 IsREJ(u_char
* data
, struct PStack
*st
)
273 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == REJ
: (data
[0] & 0xf) == REJ
);
277 IsFRMR(u_char
* data
)
279 return ((data
[0] & 0xef) == FRMR
);
283 IsRNR(u_char
* data
, struct PStack
*st
)
285 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == RNR
: (data
[0] & 0xf) == RNR
);
289 iframe_error(struct PStack
*st
, struct sk_buff
*skb
)
291 int i
= l2addrsize(&st
->l2
) + (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1);
292 int rsp
= *skb
->data
& 0x2;
294 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
304 if ((skb
->len
- i
) > st
->l2
.maxlen
)
312 super_error(struct PStack
*st
, struct sk_buff
*skb
)
314 if (skb
->len
!= l2addrsize(&st
->l2
) +
315 (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1))
322 unnum_error(struct PStack
*st
, struct sk_buff
*skb
, int wantrsp
)
324 int rsp
= (*skb
->data
& 0x2) >> 1;
325 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
331 if (skb
->len
!= l2addrsize(&st
->l2
) + 1)
338 UI_error(struct PStack
*st
, struct sk_buff
*skb
)
340 int rsp
= *skb
->data
& 0x2;
341 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
347 if (skb
->len
> st
->l2
.maxlen
+ l2addrsize(&st
->l2
) + 1)
354 FRMR_error(struct PStack
*st
, struct sk_buff
*skb
)
356 int headers
= l2addrsize(&st
->l2
) + 1;
357 u_char
*datap
= skb
->data
+ headers
;
358 int rsp
= *skb
->data
& 0x2;
360 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
366 if (test_bit(FLG_MOD128
, &st
->l2
.flag
)) {
367 if (skb
->len
< headers
+ 5)
370 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x %2x %2x",
371 datap
[0], datap
[1], datap
[2],
374 if (skb
->len
< headers
+ 3)
377 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x",
378 datap
[0], datap
[1], datap
[2]);
385 legalnr(struct PStack
*st
, unsigned int nr
)
387 struct Layer2
*l2
= &st
->l2
;
389 if(test_bit(FLG_MOD128
, &l2
->flag
))
390 return ((nr
- l2
->va
) % 128) <= ((l2
->vs
- l2
->va
) % 128);
392 return ((nr
- l2
->va
) % 8) <= ((l2
->vs
- l2
->va
) % 8);
396 setva(struct PStack
*st
, unsigned int nr
)
398 struct Layer2
*l2
= &st
->l2
;
402 spin_lock_irqsave(&l2
->lock
, flags
);
403 while (l2
->va
!= nr
) {
405 if(test_bit(FLG_MOD128
, &l2
->flag
))
409 len
= l2
->windowar
[l2
->sow
]->len
;
410 if (PACKET_NOACK
== l2
->windowar
[l2
->sow
]->pkt_type
)
412 dev_kfree_skb(l2
->windowar
[l2
->sow
]);
413 l2
->windowar
[l2
->sow
] = NULL
;
414 l2
->sow
= (l2
->sow
+ 1) % l2
->window
;
415 spin_unlock_irqrestore(&l2
->lock
, flags
);
416 if (test_bit(FLG_LLI_L2WAKEUP
, &st
->lli
.flag
) && (len
>=0))
417 lli_writewakeup(st
, len
);
418 spin_lock_irqsave(&l2
->lock
, flags
);
420 spin_unlock_irqrestore(&l2
->lock
, flags
);
424 send_uframe(struct PStack
*st
, u_char cmd
, u_char cr
)
427 u_char tmp
[MAX_HEADER_LEN
];
430 i
= sethdraddr(&st
->l2
, tmp
, cr
);
432 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
433 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for send_uframe\n");
436 memcpy(skb_put(skb
, i
), tmp
, i
);
437 enqueue_super(st
, skb
);
441 get_PollFlag(struct PStack
* st
, struct sk_buff
* skb
)
443 return (skb
->data
[l2addrsize(&(st
->l2
))] & 0x10);
447 get_PollFlagFree(struct PStack
*st
, struct sk_buff
*skb
)
451 PF
= get_PollFlag(st
, skb
);
457 start_t200(struct PStack
*st
, int i
)
459 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
460 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
464 restart_t200(struct PStack
*st
, int i
)
466 FsmRestartTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
467 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
471 stop_t200(struct PStack
*st
, int i
)
473 if(test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
))
474 FsmDelTimer(&st
->l2
.t200
, i
);
478 st5_dl_release_l2l3(struct PStack
*st
)
482 if(test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
483 pr
= DL_RELEASE
| CONFIRM
;
485 pr
= DL_RELEASE
| INDICATION
;
487 st
->l2
.l2l3(st
, pr
, NULL
);
491 lapb_dl_release_l2l3(struct PStack
*st
, int f
)
493 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
494 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
495 st
->l2
.l2l3(st
, DL_RELEASE
| f
, NULL
);
499 establishlink(struct FsmInst
*fi
)
501 struct PStack
*st
= fi
->userdata
;
504 clear_exception(&st
->l2
);
506 cmd
= (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
) | 0x10;
507 send_uframe(st
, cmd
, CMD
);
508 FsmDelTimer(&st
->l2
.t203
, 1);
510 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
512 FsmChangeState(fi
, ST_L2_5
);
516 l2_mdl_error_ua(struct FsmInst
*fi
, int event
, void *arg
)
518 struct sk_buff
*skb
= arg
;
519 struct PStack
*st
= fi
->userdata
;
521 if (get_PollFlagFree(st
, skb
))
522 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'C');
524 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'D');
528 l2_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
530 struct sk_buff
*skb
= arg
;
531 struct PStack
*st
= fi
->userdata
;
533 if (get_PollFlagFree(st
, skb
))
534 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'B');
536 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'E');
538 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
543 l2_st8_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
545 struct sk_buff
*skb
= arg
;
546 struct PStack
*st
= fi
->userdata
;
548 if (get_PollFlagFree(st
, skb
))
549 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'B');
551 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'E');
554 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
558 l2_go_st3(struct FsmInst
*fi
, int event
, void *arg
)
560 FsmChangeState(fi
, ST_L2_3
);
564 l2_mdl_assign(struct FsmInst
*fi
, int event
, void *arg
)
566 struct PStack
*st
= fi
->userdata
;
568 FsmChangeState(fi
, ST_L2_3
);
569 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
573 l2_queue_ui_assign(struct FsmInst
*fi
, int event
, void *arg
)
575 struct PStack
*st
= fi
->userdata
;
576 struct sk_buff
*skb
= arg
;
578 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
579 FsmChangeState(fi
, ST_L2_2
);
580 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
584 l2_queue_ui(struct FsmInst
*fi
, int event
, void *arg
)
586 struct PStack
*st
= fi
->userdata
;
587 struct sk_buff
*skb
= arg
;
589 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
593 tx_ui(struct PStack
*st
)
596 u_char header
[MAX_HEADER_LEN
];
599 i
= sethdraddr(&(st
->l2
), header
, CMD
);
601 while ((skb
= skb_dequeue(&st
->l2
.ui_queue
))) {
602 memcpy(skb_push(skb
, i
), header
, i
);
608 l2_send_ui(struct FsmInst
*fi
, int event
, void *arg
)
610 struct PStack
*st
= fi
->userdata
;
611 struct sk_buff
*skb
= arg
;
613 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
618 l2_got_ui(struct FsmInst
*fi
, int event
, void *arg
)
620 struct PStack
*st
= fi
->userdata
;
621 struct sk_buff
*skb
= arg
;
623 skb_pull(skb
, l2headersize(&st
->l2
, 1));
624 st
->l2
.l2l3(st
, DL_UNIT_DATA
| INDICATION
, skb
);
625 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
626 * in states 1-3 for broadcast
633 l2_establish(struct FsmInst
*fi
, int event
, void *arg
)
635 struct PStack
*st
= fi
->userdata
;
638 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
642 l2_discard_i_setl3(struct FsmInst
*fi
, int event
, void *arg
)
644 struct PStack
*st
= fi
->userdata
;
646 skb_queue_purge(&st
->l2
.i_queue
);
647 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
648 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
652 l2_l3_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
654 struct PStack
*st
= fi
->userdata
;
656 skb_queue_purge(&st
->l2
.i_queue
);
658 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
662 l2_release(struct FsmInst
*fi
, int event
, void *arg
)
664 struct PStack
*st
= fi
->userdata
;
666 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
670 l2_pend_rel(struct FsmInst
*fi
, int event
, void *arg
)
672 struct PStack
*st
= fi
->userdata
;
674 test_and_set_bit(FLG_PEND_REL
, &st
->l2
.flag
);
678 l2_disconnect(struct FsmInst
*fi
, int event
, void *arg
)
680 struct PStack
*st
= fi
->userdata
;
682 skb_queue_purge(&st
->l2
.i_queue
);
684 FsmChangeState(fi
, ST_L2_6
);
686 send_uframe(st
, DISC
| 0x10, CMD
);
687 FsmDelTimer(&st
->l2
.t203
, 1);
692 l2_start_multi(struct FsmInst
*fi
, int event
, void *arg
)
694 struct PStack
*st
= fi
->userdata
;
695 struct sk_buff
*skb
= arg
;
697 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
699 clear_exception(&st
->l2
);
704 FsmChangeState(fi
, ST_L2_7
);
705 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
707 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
711 l2_send_UA(struct FsmInst
*fi
, int event
, void *arg
)
713 struct PStack
*st
= fi
->userdata
;
714 struct sk_buff
*skb
= arg
;
716 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
720 l2_send_DM(struct FsmInst
*fi
, int event
, void *arg
)
722 struct PStack
*st
= fi
->userdata
;
723 struct sk_buff
*skb
= arg
;
725 send_uframe(st
, DM
| get_PollFlagFree(st
, skb
), RSP
);
729 l2_restart_multi(struct FsmInst
*fi
, int event
, void *arg
)
731 struct PStack
*st
= fi
->userdata
;
732 struct sk_buff
*skb
= arg
;
737 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
739 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'F');
741 if (st
->l2
.vs
!= st
->l2
.va
) {
742 skb_queue_purge(&st
->l2
.i_queue
);
746 clear_exception(&st
->l2
);
751 FsmChangeState(fi
, ST_L2_7
);
753 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
756 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
758 if ((ST_L2_7
==state
) || (ST_L2_8
== state
))
759 if (!skb_queue_empty(&st
->l2
.i_queue
) && cansend(st
))
760 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
764 l2_stop_multi(struct FsmInst
*fi
, int event
, void *arg
)
766 struct PStack
*st
= fi
->userdata
;
767 struct sk_buff
*skb
= arg
;
769 FsmChangeState(fi
, ST_L2_4
);
770 FsmDelTimer(&st
->l2
.t203
, 3);
773 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
775 skb_queue_purge(&st
->l2
.i_queue
);
777 lapb_dl_release_l2l3(st
, INDICATION
);
781 l2_connected(struct FsmInst
*fi
, int event
, void *arg
)
783 struct PStack
*st
= fi
->userdata
;
784 struct sk_buff
*skb
= arg
;
787 if (!get_PollFlag(st
, skb
)) {
788 l2_mdl_error_ua(fi
, event
, arg
);
793 if (test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
794 l2_disconnect(fi
, event
, arg
);
796 if (test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
)) {
797 pr
= DL_ESTABLISH
| CONFIRM
;
798 } else if (st
->l2
.vs
!= st
->l2
.va
) {
799 skb_queue_purge(&st
->l2
.i_queue
);
800 pr
= DL_ESTABLISH
| INDICATION
;
809 FsmChangeState(fi
, ST_L2_7
);
810 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 4);
813 st
->l2
.l2l3(st
, pr
, NULL
);
815 if (!skb_queue_empty(&st
->l2
.i_queue
) && cansend(st
))
816 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
820 l2_released(struct FsmInst
*fi
, int event
, void *arg
)
822 struct PStack
*st
= fi
->userdata
;
823 struct sk_buff
*skb
= arg
;
825 if (!get_PollFlag(st
, skb
)) {
826 l2_mdl_error_ua(fi
, event
, arg
);
832 lapb_dl_release_l2l3(st
, CONFIRM
);
833 FsmChangeState(fi
, ST_L2_4
);
837 l2_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
839 struct PStack
*st
= fi
->userdata
;
840 struct sk_buff
*skb
= arg
;
842 if (!get_PollFlagFree(st
, skb
)) {
844 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
849 l2_st5_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
851 struct PStack
*st
= fi
->userdata
;
852 struct sk_buff
*skb
= arg
;
854 if (get_PollFlagFree(st
, skb
)) {
856 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
857 skb_queue_purge(&st
->l2
.i_queue
);
858 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
859 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
860 st5_dl_release_l2l3(st
);
861 FsmChangeState(fi
, ST_L2_4
);
866 l2_st6_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
868 struct PStack
*st
= fi
->userdata
;
869 struct sk_buff
*skb
= arg
;
871 if (get_PollFlagFree(st
, skb
)) {
873 lapb_dl_release_l2l3(st
, CONFIRM
);
874 FsmChangeState(fi
, ST_L2_4
);
879 enquiry_cr(struct PStack
*st
, u_char typ
, u_char cr
, u_char pf
)
883 u_char tmp
[MAX_HEADER_LEN
];
887 i
= sethdraddr(l2
, tmp
, cr
);
888 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
890 tmp
[i
++] = (l2
->vr
<< 1) | (pf
? 1 : 0);
892 tmp
[i
++] = (l2
->vr
<< 5) | typ
| (pf
? 0x10 : 0);
893 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
894 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for enquiry_cr\n");
897 memcpy(skb_put(skb
, i
), tmp
, i
);
898 enqueue_super(st
, skb
);
902 enquiry_response(struct PStack
*st
)
904 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
905 enquiry_cr(st
, RNR
, RSP
, 1);
907 enquiry_cr(st
, RR
, RSP
, 1);
908 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
912 transmit_enquiry(struct PStack
*st
)
914 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
915 enquiry_cr(st
, RNR
, CMD
, 1);
917 enquiry_cr(st
, RR
, CMD
, 1);
918 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
924 nrerrorrecovery(struct FsmInst
*fi
)
926 struct PStack
*st
= fi
->userdata
;
928 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'J');
930 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
934 invoke_retransmission(struct PStack
*st
, unsigned int nr
)
936 struct Layer2
*l2
= &st
->l2
;
940 spin_lock_irqsave(&l2
->lock
, flags
);
942 while (l2
->vs
!= nr
) {
944 if(test_bit(FLG_MOD128
, &l2
->flag
)) {
946 p1
= (l2
->vs
- l2
->va
) % 128;
949 p1
= (l2
->vs
- l2
->va
) % 8;
951 p1
= (p1
+ l2
->sow
) % l2
->window
;
952 if (test_bit(FLG_LAPB
, &l2
->flag
))
953 st
->l1
.bcs
->tx_cnt
+= l2
->windowar
[p1
]->len
+ l2headersize(l2
, 0);
954 skb_queue_head(&l2
->i_queue
, l2
->windowar
[p1
]);
955 l2
->windowar
[p1
] = NULL
;
957 spin_unlock_irqrestore(&l2
->lock
, flags
);
958 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
961 spin_unlock_irqrestore(&l2
->lock
, flags
);
965 l2_st7_got_super(struct FsmInst
*fi
, int event
, void *arg
)
967 struct PStack
*st
= fi
->userdata
;
968 struct sk_buff
*skb
= arg
;
969 int PollFlag
, rsp
, typ
= RR
;
971 struct Layer2
*l2
= &st
->l2
;
973 rsp
= *skb
->data
& 0x2;
974 if (test_bit(FLG_ORIG
, &l2
->flag
))
977 skb_pull(skb
, l2addrsize(l2
));
978 if (IsRNR(skb
->data
, st
)) {
983 if (IsREJ(skb
->data
, st
))
986 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
987 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
988 nr
= skb
->data
[1] >> 1;
990 PollFlag
= (skb
->data
[0] & 0x10);
991 nr
= (skb
->data
[0] >> 5) & 0x7;
997 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'A');
999 enquiry_response(st
);
1001 if (legalnr(st
, nr
)) {
1004 invoke_retransmission(st
, nr
);
1006 if (FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
,
1007 EV_L2_T203
, NULL
, 6))
1008 l2m_debug(&st
->l2
.l2m
, "Restart T203 ST7 REJ");
1009 } else if ((nr
== l2
->vs
) && (typ
== RR
)) {
1012 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1013 EV_L2_T203
, NULL
, 7);
1014 } else if ((l2
->va
!= nr
) || (typ
== RNR
)) {
1016 if(typ
!= RR
) FsmDelTimer(&st
->l2
.t203
, 9);
1017 restart_t200(st
, 12);
1019 if (!skb_queue_empty(&st
->l2
.i_queue
) && (typ
== RR
))
1020 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1022 nrerrorrecovery(fi
);
1026 l2_feed_i_if_reest(struct FsmInst
*fi
, int event
, void *arg
)
1028 struct PStack
*st
= fi
->userdata
;
1029 struct sk_buff
*skb
= arg
;
1031 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1032 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1033 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
1034 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1040 l2_feed_i_pull(struct FsmInst
*fi
, int event
, void *arg
)
1042 struct PStack
*st
= fi
->userdata
;
1043 struct sk_buff
*skb
= arg
;
1045 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1046 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1047 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1048 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1052 l2_feed_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1054 struct PStack
*st
= fi
->userdata
;
1055 struct sk_buff
*skb
= arg
;
1057 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1058 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1059 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1063 l2_got_iframe(struct FsmInst
*fi
, int event
, void *arg
)
1065 struct PStack
*st
= fi
->userdata
;
1066 struct sk_buff
*skb
= arg
;
1067 struct Layer2
*l2
= &(st
->l2
);
1068 int PollFlag
, ns
, i
;
1072 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1073 PollFlag
= ((skb
->data
[i
+ 1] & 0x1) == 0x1);
1074 ns
= skb
->data
[i
] >> 1;
1075 nr
= (skb
->data
[i
+ 1] >> 1) & 0x7f;
1077 PollFlag
= (skb
->data
[i
] & 0x10);
1078 ns
= (skb
->data
[i
] >> 1) & 0x7;
1079 nr
= (skb
->data
[i
] >> 5) & 0x7;
1081 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1083 if(PollFlag
) enquiry_response(st
);
1084 } else if (l2
->vr
== ns
) {
1086 if(test_bit(FLG_MOD128
, &l2
->flag
))
1090 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
1093 enquiry_response(st
);
1095 test_and_set_bit(FLG_ACK_PEND
, &l2
->flag
);
1096 skb_pull(skb
, l2headersize(l2
, 0));
1097 st
->l2
.l2l3(st
, DL_DATA
| INDICATION
, skb
);
1101 if (test_and_set_bit(FLG_REJEXC
, &l2
->flag
)) {
1103 enquiry_response(st
);
1105 enquiry_cr(st
, REJ
, RSP
, PollFlag
);
1106 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1110 if (legalnr(st
, nr
)) {
1111 if (!test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
) && (fi
->state
== ST_L2_7
)) {
1112 if (nr
== st
->l2
.vs
) {
1114 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1115 EV_L2_T203
, NULL
, 7);
1116 } else if (nr
!= st
->l2
.va
)
1117 restart_t200(st
, 14);
1121 nrerrorrecovery(fi
);
1125 if (!skb_queue_empty(&st
->l2
.i_queue
) && (fi
->state
== ST_L2_7
))
1126 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1127 if (test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
))
1128 enquiry_cr(st
, RR
, RSP
, 0);
1132 l2_got_tei(struct FsmInst
*fi
, int event
, void *arg
)
1134 struct PStack
*st
= fi
->userdata
;
1136 st
->l2
.tei
= (long) arg
;
1138 if (fi
->state
== ST_L2_3
) {
1140 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1142 FsmChangeState(fi
, ST_L2_4
);
1143 if (!skb_queue_empty(&st
->l2
.ui_queue
))
1148 l2_st5_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1150 struct PStack
*st
= fi
->userdata
;
1152 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1153 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1154 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1155 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1156 FsmChangeState(fi
, ST_L2_4
);
1157 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1158 skb_queue_purge(&st
->l2
.i_queue
);
1159 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'G');
1160 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1161 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1162 st5_dl_release_l2l3(st
);
1165 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1166 send_uframe(st
, (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
)
1172 l2_st6_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1174 struct PStack
*st
= fi
->userdata
;
1176 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1177 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1178 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1179 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1180 FsmChangeState(fi
, ST_L2_4
);
1181 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1182 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'H');
1183 lapb_dl_release_l2l3(st
, CONFIRM
);
1186 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
,
1188 send_uframe(st
, DISC
| 0x10, CMD
);
1193 l2_st7_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1195 struct PStack
*st
= fi
->userdata
;
1197 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1198 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1199 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1202 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1204 FsmChangeState(fi
, ST_L2_8
);
1206 transmit_enquiry(st
);
1211 l2_st8_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1213 struct PStack
*st
= fi
->userdata
;
1215 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1216 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1217 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1220 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1221 if (st
->l2
.rc
== st
->l2
.N200
) {
1222 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'I');
1224 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1226 transmit_enquiry(st
);
1232 l2_st7_tout_203(struct FsmInst
*fi
, int event
, void *arg
)
1234 struct PStack
*st
= fi
->userdata
;
1236 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1237 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1238 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 9);
1241 FsmChangeState(fi
, ST_L2_8
);
1242 transmit_enquiry(st
);
1247 l2_pull_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1249 struct PStack
*st
= fi
->userdata
;
1250 struct sk_buff
*skb
;
1251 struct Layer2
*l2
= &st
->l2
;
1252 u_char header
[MAX_HEADER_LEN
];
1253 int i
, hdr_space_needed
;
1260 skb
= skb_dequeue(&l2
->i_queue
);
1264 hdr_space_needed
= l2headersize(l2
, 0);
1265 if (hdr_space_needed
> skb_headroom(skb
)) {
1266 struct sk_buff
*orig_skb
= skb
;
1268 skb
= skb_realloc_headroom(skb
, hdr_space_needed
);
1270 dev_kfree_skb(orig_skb
);
1274 spin_lock_irqsave(&l2
->lock
, flags
);
1275 if(test_bit(FLG_MOD128
, &l2
->flag
))
1276 p1
= (l2
->vs
- l2
->va
) % 128;
1278 p1
= (l2
->vs
- l2
->va
) % 8;
1279 p1
= (p1
+ l2
->sow
) % l2
->window
;
1280 if (l2
->windowar
[p1
]) {
1281 printk(KERN_WARNING
"isdnl2 try overwrite ack queue entry %d\n",
1283 dev_kfree_skb(l2
->windowar
[p1
]);
1285 l2
->windowar
[p1
] = skb_clone(skb
, GFP_ATOMIC
);
1287 i
= sethdraddr(&st
->l2
, header
, CMD
);
1289 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1290 header
[i
++] = l2
->vs
<< 1;
1291 header
[i
++] = l2
->vr
<< 1;
1292 l2
->vs
= (l2
->vs
+ 1) % 128;
1294 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1295 l2
->vs
= (l2
->vs
+ 1) % 8;
1297 spin_unlock_irqrestore(&l2
->lock
, flags
);
1298 memcpy(skb_push(skb
, i
), header
, i
);
1299 st
->l2
.l2l1(st
, PH_PULL
| INDICATION
, skb
);
1300 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1301 if (!test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
)) {
1302 FsmDelTimer(&st
->l2
.t203
, 13);
1303 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 11);
1305 if (!skb_queue_empty(&l2
->i_queue
) && cansend(st
))
1306 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1310 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1312 struct PStack
*st
= fi
->userdata
;
1313 struct sk_buff
*skb
= arg
;
1314 int PollFlag
, rsp
, rnr
= 0;
1316 struct Layer2
*l2
= &st
->l2
;
1318 rsp
= *skb
->data
& 0x2;
1319 if (test_bit(FLG_ORIG
, &l2
->flag
))
1322 skb_pull(skb
, l2addrsize(l2
));
1324 if (IsRNR(skb
->data
, st
)) {
1328 clear_peer_busy(l2
);
1330 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1331 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1332 nr
= skb
->data
[1] >> 1;
1334 PollFlag
= (skb
->data
[0] & 0x10);
1335 nr
= (skb
->data
[0] >> 5) & 0x7;
1339 if (rsp
&& PollFlag
) {
1340 if (legalnr(st
, nr
)) {
1342 restart_t200(st
, 15);
1345 FsmAddTimer(&l2
->t203
, l2
->T203
,
1346 EV_L2_T203
, NULL
, 5);
1349 invoke_retransmission(st
, nr
);
1350 FsmChangeState(fi
, ST_L2_7
);
1351 if (!skb_queue_empty(&l2
->i_queue
) && cansend(st
))
1352 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1354 nrerrorrecovery(fi
);
1356 if (!rsp
&& PollFlag
)
1357 enquiry_response(st
);
1358 if (legalnr(st
, nr
)) {
1361 nrerrorrecovery(fi
);
1366 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1368 struct PStack
*st
= fi
->userdata
;
1369 struct sk_buff
*skb
= arg
;
1371 skb_pull(skb
, l2addrsize(&st
->l2
) + 1);
1373 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1374 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1375 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'K');
1377 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1383 l2_st24_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1385 struct PStack
*st
= fi
->userdata
;
1387 skb_queue_purge(&st
->l2
.ui_queue
);
1389 FsmChangeState(fi
, ST_L2_1
);
1393 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1395 struct PStack
*st
= fi
->userdata
;
1397 skb_queue_purge(&st
->l2
.ui_queue
);
1399 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1400 FsmChangeState(fi
, ST_L2_1
);
1404 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1406 struct PStack
*st
= fi
->userdata
;
1408 skb_queue_purge(&st
->l2
.i_queue
);
1409 skb_queue_purge(&st
->l2
.ui_queue
);
1413 st5_dl_release_l2l3(st
);
1414 FsmChangeState(fi
, ST_L2_1
);
1418 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1420 struct PStack
*st
= fi
->userdata
;
1422 skb_queue_purge(&st
->l2
.ui_queue
);
1425 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1426 FsmChangeState(fi
, ST_L2_1
);
1430 l2_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1432 struct PStack
*st
= fi
->userdata
;
1434 skb_queue_purge(&st
->l2
.i_queue
);
1435 skb_queue_purge(&st
->l2
.ui_queue
);
1439 FsmDelTimer(&st
->l2
.t203
, 19);
1440 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1441 FsmChangeState(fi
, ST_L2_1
);
1445 l2_st14_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1447 struct PStack
*st
= fi
->userdata
;
1449 skb_queue_purge(&st
->l2
.i_queue
);
1450 skb_queue_purge(&st
->l2
.ui_queue
);
1451 if (test_and_clear_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
))
1452 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1456 l2_st5_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1458 struct PStack
*st
= fi
->userdata
;
1460 skb_queue_purge(&st
->l2
.i_queue
);
1461 skb_queue_purge(&st
->l2
.ui_queue
);
1464 st5_dl_release_l2l3(st
);
1465 FsmChangeState(fi
, ST_L2_4
);
1469 l2_st6_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1471 struct PStack
*st
= fi
->userdata
;
1473 skb_queue_purge(&st
->l2
.ui_queue
);
1475 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1476 FsmChangeState(fi
, ST_L2_4
);
1480 l2_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1482 struct PStack
*st
= fi
->userdata
;
1484 skb_queue_purge(&st
->l2
.i_queue
);
1485 skb_queue_purge(&st
->l2
.ui_queue
);
1488 FsmDelTimer(&st
->l2
.t203
, 19);
1489 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1490 FsmChangeState(fi
, ST_L2_4
);
1494 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1496 struct PStack
*st
= fi
->userdata
;
1498 if(!test_and_set_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1499 enquiry_cr(st
, RNR
, RSP
, 0);
1500 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1505 l2_clear_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1507 struct PStack
*st
= fi
->userdata
;
1509 if(!test_and_clear_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1510 enquiry_cr(st
, RR
, RSP
, 0);
1511 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1516 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1518 struct PStack
*st
= fi
->userdata
;
1520 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1524 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1526 struct PStack
*st
= fi
->userdata
;
1528 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1530 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1533 static struct FsmNode L2FnList
[] __initdata
=
1535 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1536 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1537 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1538 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1539 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1540 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1541 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1542 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1543 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1544 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1545 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1546 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1547 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1548 {ST_L2_1
, EV_L2_DL_UNIT_DATA
, l2_queue_ui_assign
},
1549 {ST_L2_2
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1550 {ST_L2_3
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1551 {ST_L2_4
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1552 {ST_L2_5
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1553 {ST_L2_6
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1554 {ST_L2_7
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1555 {ST_L2_8
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1556 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1557 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1558 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1559 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1560 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1561 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1562 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1563 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1564 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1565 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1566 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1567 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1568 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1569 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1570 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1571 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1572 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1573 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1574 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1575 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1576 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1577 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1578 {ST_L2_6
, EV_L2_UA
, l2_released
},
1579 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1580 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1581 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1582 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1583 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1584 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1585 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1586 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1587 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1588 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1589 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1590 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1591 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1592 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1593 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1594 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1595 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1596 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1597 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1598 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1599 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1600 {ST_L2_5
, EV_L2_T200
, l2_st5_tout_200
},
1601 {ST_L2_6
, EV_L2_T200
, l2_st6_tout_200
},
1602 {ST_L2_7
, EV_L2_T200
, l2_st7_tout_200
},
1603 {ST_L2_8
, EV_L2_T200
, l2_st8_tout_200
},
1604 {ST_L2_7
, EV_L2_T203
, l2_st7_tout_203
},
1605 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1606 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1607 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1608 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1609 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1610 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1611 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1612 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1613 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1614 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1615 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1616 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1617 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1618 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1619 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistent_da
},
1620 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistent_da
},
1621 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1622 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1626 isdnl2_l1l2(struct PStack
*st
, int pr
, void *arg
)
1628 struct sk_buff
*skb
= arg
;
1634 case (PH_DATA
| INDICATION
):
1636 len
= l2addrsize(&st
->l2
);
1640 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
1644 if (!(*datap
& 1)) { /* I-Frame */
1645 if(!(c
= iframe_error(st
, skb
)))
1646 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_I
, skb
);
1647 } else if (IsSFrame(datap
, st
)) { /* S-Frame */
1648 if(!(c
= super_error(st
, skb
)))
1649 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_SUPER
, skb
);
1650 } else if (IsUI(datap
)) {
1651 if(!(c
= UI_error(st
, skb
)))
1652 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_UI
, skb
);
1653 } else if (IsSABME(datap
, st
)) {
1654 if(!(c
= unnum_error(st
, skb
, CMD
)))
1655 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_SABME
, skb
);
1656 } else if (IsUA(datap
)) {
1657 if(!(c
= unnum_error(st
, skb
, RSP
)))
1658 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_UA
, skb
);
1659 } else if (IsDISC(datap
)) {
1660 if(!(c
= unnum_error(st
, skb
, CMD
)))
1661 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_DISC
, skb
);
1662 } else if (IsDM(datap
)) {
1663 if(!(c
= unnum_error(st
, skb
, RSP
)))
1664 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_DM
, skb
);
1665 } else if (IsFRMR(datap
)) {
1666 if(!(c
= FRMR_error(st
,skb
)))
1667 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_FRMR
, skb
);
1669 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'L');
1675 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1681 case (PH_PULL
| CONFIRM
):
1682 FsmEvent(&st
->l2
.l2m
, EV_L2_ACK_PULL
, arg
);
1684 case (PH_PAUSE
| INDICATION
):
1685 test_and_set_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
1687 case (PH_PAUSE
| CONFIRM
):
1688 test_and_clear_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
1690 case (PH_ACTIVATE
| CONFIRM
):
1691 case (PH_ACTIVATE
| INDICATION
):
1692 test_and_set_bit(FLG_L1_ACTIV
, &st
->l2
.flag
);
1693 if (test_and_clear_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
))
1694 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_ESTABLISH_REQ
, arg
);
1696 case (PH_DEACTIVATE
| INDICATION
):
1697 case (PH_DEACTIVATE
| CONFIRM
):
1698 test_and_clear_bit(FLG_L1_ACTIV
, &st
->l2
.flag
);
1699 FsmEvent(&st
->l2
.l2m
, EV_L1_DEACTIVATE
, arg
);
1702 l2m_debug(&st
->l2
.l2m
, "l2 unknown pr %04x", pr
);
1708 isdnl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1711 case (DL_DATA
| REQUEST
):
1712 if (FsmEvent(&st
->l2
.l2m
, EV_L2_DL_DATA
, arg
)) {
1713 dev_kfree_skb((struct sk_buff
*) arg
);
1716 case (DL_UNIT_DATA
| REQUEST
):
1717 if (FsmEvent(&st
->l2
.l2m
, EV_L2_DL_UNIT_DATA
, arg
)) {
1718 dev_kfree_skb((struct sk_buff
*) arg
);
1721 case (DL_ESTABLISH
| REQUEST
):
1722 if (test_bit(FLG_L1_ACTIV
, &st
->l2
.flag
)) {
1723 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) ||
1724 test_bit(FLG_ORIG
, &st
->l2
.flag
)) {
1725 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_ESTABLISH_REQ
, arg
);
1728 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) ||
1729 test_bit(FLG_ORIG
, &st
->l2
.flag
)) {
1730 test_and_set_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
);
1732 st
->l2
.l2l1(st
, PH_ACTIVATE
, NULL
);
1735 case (DL_RELEASE
| REQUEST
):
1736 if (test_bit(FLG_LAPB
, &st
->l2
.flag
)) {
1737 st
->l2
.l2l1(st
, PH_DEACTIVATE
, NULL
);
1739 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_RELEASE_REQ
, arg
);
1741 case (MDL_ASSIGN
| REQUEST
):
1742 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ASSIGN
, arg
);
1744 case (MDL_REMOVE
| REQUEST
):
1745 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_REMOVE
, arg
);
1747 case (MDL_ERROR
| RESPONSE
):
1748 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ERROR
, arg
);
1754 releasestack_isdnl2(struct PStack
*st
)
1756 FsmDelTimer(&st
->l2
.t200
, 21);
1757 FsmDelTimer(&st
->l2
.t203
, 16);
1758 skb_queue_purge(&st
->l2
.i_queue
);
1759 skb_queue_purge(&st
->l2
.ui_queue
);
1760 ReleaseWin(&st
->l2
);
1764 l2m_debug(struct FsmInst
*fi
, char *fmt
, ...)
1767 struct PStack
*st
= fi
->userdata
;
1769 va_start(args
, fmt
);
1770 VHiSax_putstatus(st
->l1
.hardware
, st
->l2
.debug_id
, fmt
, args
);
1775 setstack_isdnl2(struct PStack
*st
, char *debug_id
)
1777 spin_lock_init(&st
->l2
.lock
);
1778 st
->l1
.l1l2
= isdnl2_l1l2
;
1779 st
->l3
.l3l2
= isdnl2_l3l2
;
1781 skb_queue_head_init(&st
->l2
.i_queue
);
1782 skb_queue_head_init(&st
->l2
.ui_queue
);
1786 st
->l2
.l2m
.fsm
= &l2fsm
;
1787 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1788 st
->l2
.l2m
.state
= ST_L2_4
;
1790 st
->l2
.l2m
.state
= ST_L2_1
;
1791 st
->l2
.l2m
.debug
= 0;
1792 st
->l2
.l2m
.userdata
= st
;
1793 st
->l2
.l2m
.userint
= 0;
1794 st
->l2
.l2m
.printdebug
= l2m_debug
;
1795 strcpy(st
->l2
.debug_id
, debug_id
);
1797 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t200
);
1798 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t203
);
1802 transl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1805 case (DL_DATA
| REQUEST
):
1806 case (DL_UNIT_DATA
| REQUEST
):
1807 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, arg
);
1809 case (DL_ESTABLISH
| REQUEST
):
1810 st
->l2
.l2l1(st
, PH_ACTIVATE
| REQUEST
, NULL
);
1812 case (DL_RELEASE
| REQUEST
):
1813 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1819 setstack_transl2(struct PStack
*st
)
1821 st
->l3
.l3l2
= transl2_l3l2
;
1825 releasestack_transl2(struct PStack
*st
)
1832 l2fsm
.state_count
= L2_STATE_COUNT
;
1833 l2fsm
.event_count
= L2_EVENT_COUNT
;
1834 l2fsm
.strEvent
= strL2Event
;
1835 l2fsm
.strState
= strL2State
;
1836 return FsmNew(&l2fsm
, L2FnList
, ARRAY_SIZE(L2FnList
));