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>
22 const char *l2_revision
= "$Revision: 2.30.2.4 $";
24 static void l2m_debug(struct FsmInst
*fi
, char *fmt
, ...);
26 static struct Fsm l2fsm
;
39 #define L2_STATE_COUNT (ST_L2_8+1)
41 static char *strL2State
[] =
65 EV_L2_DL_ESTABLISH_REQ
,
78 #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR+1)
80 static char *strL2Event
[] =
93 "EV_L2_DL_ESTABLISH_REQ",
94 "EV_L2_DL_RELEASE_REQ",
101 "EV_L2_SET_OWN_BUSY",
102 "EV_L2_CLEAR_OWN_BUSY",
106 static int l2addrsize(struct Layer2
*l2
);
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
);
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
);
122 InitWin(struct Layer2
*l2
)
126 for (i
= 0; i
< MAX_WINDOW
; i
++)
127 l2
->windowar
[i
] = NULL
;
131 freewin1(struct Layer2
*l2
)
135 for (i
= 0; i
< MAX_WINDOW
; i
++) {
136 if (l2
->windowar
[i
]) {
138 dev_kfree_skb(l2
->windowar
[i
]);
139 l2
->windowar
[i
] = NULL
;
146 freewin(struct PStack
*st
)
152 ReleaseWin(struct Layer2
*l2
)
156 if((cnt
= freewin1(l2
)))
157 printk(KERN_WARNING
"isdl2 freed %d skbuffs in release\n", cnt
);
161 cansend(struct PStack
*st
)
165 if(test_bit(FLG_MOD128
, &st
->l2
.flag
))
166 p1
= (st
->l2
.vs
- st
->l2
.va
) % 128;
168 p1
= (st
->l2
.vs
- st
->l2
.va
) % 8;
169 return ((p1
< st
->l2
.window
) && !test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
));
173 clear_exception(struct Layer2
*l2
)
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
);
182 l2headersize(struct Layer2
*l2
, int ui
)
184 return (((test_bit(FLG_MOD128
, &l2
->flag
) && (!ui
)) ? 2 : 1) +
185 (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1));
189 l2addrsize(struct Layer2
*l2
)
191 return (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1);
195 sethdraddr(struct Layer2
*l2
, u_char
* header
, int rsp
)
197 u_char
*ptr
= header
;
200 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
201 *ptr
++ = (l2
->sap
<< 2) | (rsp
? 2 : 0);
202 *ptr
++ = (l2
->tei
<< 1) | 1;
205 if (test_bit(FLG_ORIG
, &l2
->flag
))
216 enqueue_super(struct PStack
*st
,
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
);
224 #define enqueue_ui(a, b) enqueue_super(a, b)
229 return ((data
[0] & 0xef) == UI
);
235 return ((data
[0] & 0xef) == UA
);
241 return ((data
[0] & 0xef) == DM
);
245 IsDISC(u_char
* data
)
247 return ((data
[0] & 0xef) == DISC
);
251 IsRR(u_char
* data
, struct PStack
*st
)
253 if (test_bit(FLG_MOD128
, &st
->l2
.flag
))
254 return (data
[0] == RR
);
256 return ((data
[0] & 0xf) == 1);
260 IsSFrame(u_char
* data
, struct PStack
*st
)
262 register u_char d
= *data
;
264 if (!test_bit(FLG_MOD128
, &st
->l2
.flag
))
266 return(((d
& 0xf3) == 1) && ((d
& 0x0c) != 0x0c));
270 IsSABME(u_char
* data
, struct PStack
*st
)
272 u_char d
= data
[0] & ~0x10;
274 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? d
== SABME
: d
== SABM
);
278 IsREJ(u_char
* data
, struct PStack
*st
)
280 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == REJ
: (data
[0] & 0xf) == REJ
);
284 IsFRMR(u_char
* data
)
286 return ((data
[0] & 0xef) == FRMR
);
290 IsRNR(u_char
* data
, struct PStack
*st
)
292 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == RNR
: (data
[0] & 0xf) == RNR
);
296 iframe_error(struct PStack
*st
, struct sk_buff
*skb
)
298 int i
= l2addrsize(&st
->l2
) + (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1);
299 int rsp
= *skb
->data
& 0x2;
301 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
311 if ((skb
->len
- i
) > st
->l2
.maxlen
)
319 super_error(struct PStack
*st
, struct sk_buff
*skb
)
321 if (skb
->len
!= l2addrsize(&st
->l2
) +
322 (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1))
329 unnum_error(struct PStack
*st
, struct sk_buff
*skb
, int wantrsp
)
331 int rsp
= (*skb
->data
& 0x2) >> 1;
332 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
338 if (skb
->len
!= l2addrsize(&st
->l2
) + 1)
345 UI_error(struct PStack
*st
, struct sk_buff
*skb
)
347 int rsp
= *skb
->data
& 0x2;
348 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
354 if (skb
->len
> st
->l2
.maxlen
+ l2addrsize(&st
->l2
) + 1)
361 FRMR_error(struct PStack
*st
, struct sk_buff
*skb
)
363 int headers
= l2addrsize(&st
->l2
) + 1;
364 u_char
*datap
= skb
->data
+ headers
;
365 int rsp
= *skb
->data
& 0x2;
367 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
373 if (test_bit(FLG_MOD128
, &st
->l2
.flag
)) {
374 if (skb
->len
< headers
+ 5)
377 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x %2x %2x",
378 datap
[0], datap
[1], datap
[2],
381 if (skb
->len
< headers
+ 3)
384 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x",
385 datap
[0], datap
[1], datap
[2]);
392 legalnr(struct PStack
*st
, unsigned int nr
)
394 struct Layer2
*l2
= &st
->l2
;
396 if(test_bit(FLG_MOD128
, &l2
->flag
))
397 return ((nr
- l2
->va
) % 128) <= ((l2
->vs
- l2
->va
) % 128);
399 return ((nr
- l2
->va
) % 8) <= ((l2
->vs
- l2
->va
) % 8);
403 setva(struct PStack
*st
, unsigned int nr
)
405 struct Layer2
*l2
= &st
->l2
;
409 spin_lock_irqsave(&l2
->lock
, flags
);
410 while (l2
->va
!= nr
) {
412 if(test_bit(FLG_MOD128
, &l2
->flag
))
416 len
= l2
->windowar
[l2
->sow
]->len
;
417 if (PACKET_NOACK
== l2
->windowar
[l2
->sow
]->pkt_type
)
419 dev_kfree_skb(l2
->windowar
[l2
->sow
]);
420 l2
->windowar
[l2
->sow
] = NULL
;
421 l2
->sow
= (l2
->sow
+ 1) % l2
->window
;
422 spin_unlock_irqrestore(&l2
->lock
, flags
);
423 if (test_bit(FLG_LLI_L2WAKEUP
, &st
->lli
.flag
) && (len
>=0))
424 lli_writewakeup(st
, len
);
425 spin_lock_irqsave(&l2
->lock
, flags
);
427 spin_unlock_irqrestore(&l2
->lock
, flags
);
431 send_uframe(struct PStack
*st
, u_char cmd
, u_char cr
)
434 u_char tmp
[MAX_HEADER_LEN
];
437 i
= sethdraddr(&st
->l2
, tmp
, cr
);
439 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
440 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for send_uframe\n");
443 memcpy(skb_put(skb
, i
), tmp
, i
);
444 enqueue_super(st
, skb
);
448 get_PollFlag(struct PStack
* st
, struct sk_buff
* skb
)
450 return (skb
->data
[l2addrsize(&(st
->l2
))] & 0x10);
454 FreeSkb(struct sk_buff
*skb
)
461 get_PollFlagFree(struct PStack
*st
, struct sk_buff
*skb
)
465 PF
= get_PollFlag(st
, skb
);
471 start_t200(struct PStack
*st
, int i
)
473 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
474 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
478 restart_t200(struct PStack
*st
, int i
)
480 FsmRestartTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
481 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
485 stop_t200(struct PStack
*st
, int i
)
487 if(test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
))
488 FsmDelTimer(&st
->l2
.t200
, i
);
492 st5_dl_release_l2l3(struct PStack
*st
)
496 if(test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
497 pr
= DL_RELEASE
| CONFIRM
;
499 pr
= DL_RELEASE
| INDICATION
;
501 st
->l2
.l2l3(st
, pr
, NULL
);
505 lapb_dl_release_l2l3(struct PStack
*st
, int f
)
507 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
508 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
509 st
->l2
.l2l3(st
, DL_RELEASE
| f
, NULL
);
513 establishlink(struct FsmInst
*fi
)
515 struct PStack
*st
= fi
->userdata
;
518 clear_exception(&st
->l2
);
520 cmd
= (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
) | 0x10;
521 send_uframe(st
, cmd
, CMD
);
522 FsmDelTimer(&st
->l2
.t203
, 1);
524 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
526 FsmChangeState(fi
, ST_L2_5
);
530 l2_mdl_error_ua(struct FsmInst
*fi
, int event
, void *arg
)
532 struct sk_buff
*skb
= arg
;
533 struct PStack
*st
= fi
->userdata
;
535 if (get_PollFlagFree(st
, skb
))
536 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'C');
538 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'D');
542 l2_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
544 struct sk_buff
*skb
= arg
;
545 struct PStack
*st
= fi
->userdata
;
547 if (get_PollFlagFree(st
, skb
))
548 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'B');
550 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'E');
552 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
557 l2_st8_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
559 struct sk_buff
*skb
= arg
;
560 struct PStack
*st
= fi
->userdata
;
562 if (get_PollFlagFree(st
, skb
))
563 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'B');
565 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'E');
568 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
572 l2_go_st3(struct FsmInst
*fi
, int event
, void *arg
)
574 FsmChangeState(fi
, ST_L2_3
);
578 l2_mdl_assign(struct FsmInst
*fi
, int event
, void *arg
)
580 struct PStack
*st
= fi
->userdata
;
582 FsmChangeState(fi
, ST_L2_3
);
583 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
587 l2_queue_ui_assign(struct FsmInst
*fi
, int event
, void *arg
)
589 struct PStack
*st
= fi
->userdata
;
590 struct sk_buff
*skb
= arg
;
592 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
593 FsmChangeState(fi
, ST_L2_2
);
594 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
598 l2_queue_ui(struct FsmInst
*fi
, int event
, void *arg
)
600 struct PStack
*st
= fi
->userdata
;
601 struct sk_buff
*skb
= arg
;
603 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
607 tx_ui(struct PStack
*st
)
610 u_char header
[MAX_HEADER_LEN
];
613 i
= sethdraddr(&(st
->l2
), header
, CMD
);
615 while ((skb
= skb_dequeue(&st
->l2
.ui_queue
))) {
616 memcpy(skb_push(skb
, i
), header
, i
);
622 l2_send_ui(struct FsmInst
*fi
, int event
, void *arg
)
624 struct PStack
*st
= fi
->userdata
;
625 struct sk_buff
*skb
= arg
;
627 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
632 l2_got_ui(struct FsmInst
*fi
, int event
, void *arg
)
634 struct PStack
*st
= fi
->userdata
;
635 struct sk_buff
*skb
= arg
;
637 skb_pull(skb
, l2headersize(&st
->l2
, 1));
638 st
->l2
.l2l3(st
, DL_UNIT_DATA
| INDICATION
, skb
);
639 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
640 * in states 1-3 for broadcast
647 l2_establish(struct FsmInst
*fi
, int event
, void *arg
)
649 struct PStack
*st
= fi
->userdata
;
652 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
656 l2_discard_i_setl3(struct FsmInst
*fi
, int event
, void *arg
)
658 struct PStack
*st
= fi
->userdata
;
660 skb_queue_purge(&st
->l2
.i_queue
);
661 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
662 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
666 l2_l3_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
668 struct PStack
*st
= fi
->userdata
;
670 skb_queue_purge(&st
->l2
.i_queue
);
672 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
676 l2_release(struct FsmInst
*fi
, int event
, void *arg
)
678 struct PStack
*st
= fi
->userdata
;
680 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
684 l2_pend_rel(struct FsmInst
*fi
, int event
, void *arg
)
686 struct PStack
*st
= fi
->userdata
;
688 test_and_set_bit(FLG_PEND_REL
, &st
->l2
.flag
);
692 l2_disconnect(struct FsmInst
*fi
, int event
, void *arg
)
694 struct PStack
*st
= fi
->userdata
;
696 skb_queue_purge(&st
->l2
.i_queue
);
698 FsmChangeState(fi
, ST_L2_6
);
700 send_uframe(st
, DISC
| 0x10, CMD
);
701 FsmDelTimer(&st
->l2
.t203
, 1);
706 l2_start_multi(struct FsmInst
*fi
, int event
, void *arg
)
708 struct PStack
*st
= fi
->userdata
;
709 struct sk_buff
*skb
= arg
;
711 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
713 clear_exception(&st
->l2
);
718 FsmChangeState(fi
, ST_L2_7
);
719 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
721 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
725 l2_send_UA(struct FsmInst
*fi
, int event
, void *arg
)
727 struct PStack
*st
= fi
->userdata
;
728 struct sk_buff
*skb
= arg
;
730 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
734 l2_send_DM(struct FsmInst
*fi
, int event
, void *arg
)
736 struct PStack
*st
= fi
->userdata
;
737 struct sk_buff
*skb
= arg
;
739 send_uframe(st
, DM
| get_PollFlagFree(st
, skb
), RSP
);
743 l2_restart_multi(struct FsmInst
*fi
, int event
, void *arg
)
745 struct PStack
*st
= fi
->userdata
;
746 struct sk_buff
*skb
= arg
;
751 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
753 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'F');
755 if (st
->l2
.vs
!= st
->l2
.va
) {
756 skb_queue_purge(&st
->l2
.i_queue
);
760 clear_exception(&st
->l2
);
765 FsmChangeState(fi
, ST_L2_7
);
767 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
770 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
772 if ((ST_L2_7
==state
) || (ST_L2_8
== state
))
773 if (skb_queue_len(&st
->l2
.i_queue
) && cansend(st
))
774 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
778 l2_stop_multi(struct FsmInst
*fi
, int event
, void *arg
)
780 struct PStack
*st
= fi
->userdata
;
781 struct sk_buff
*skb
= arg
;
783 FsmChangeState(fi
, ST_L2_4
);
784 FsmDelTimer(&st
->l2
.t203
, 3);
787 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
789 skb_queue_purge(&st
->l2
.i_queue
);
791 lapb_dl_release_l2l3(st
, INDICATION
);
795 l2_connected(struct FsmInst
*fi
, int event
, void *arg
)
797 struct PStack
*st
= fi
->userdata
;
798 struct sk_buff
*skb
= arg
;
801 if (!get_PollFlag(st
, skb
)) {
802 l2_mdl_error_ua(fi
, event
, arg
);
807 if (test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
808 l2_disconnect(fi
, event
, arg
);
810 if (test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
)) {
811 pr
= DL_ESTABLISH
| CONFIRM
;
812 } else if (st
->l2
.vs
!= st
->l2
.va
) {
813 skb_queue_purge(&st
->l2
.i_queue
);
814 pr
= DL_ESTABLISH
| INDICATION
;
823 FsmChangeState(fi
, ST_L2_7
);
824 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 4);
827 st
->l2
.l2l3(st
, pr
, NULL
);
829 if (skb_queue_len(&st
->l2
.i_queue
) && cansend(st
))
830 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
834 l2_released(struct FsmInst
*fi
, int event
, void *arg
)
836 struct PStack
*st
= fi
->userdata
;
837 struct sk_buff
*skb
= arg
;
839 if (!get_PollFlag(st
, skb
)) {
840 l2_mdl_error_ua(fi
, event
, arg
);
846 lapb_dl_release_l2l3(st
, CONFIRM
);
847 FsmChangeState(fi
, ST_L2_4
);
851 l2_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
853 struct PStack
*st
= fi
->userdata
;
854 struct sk_buff
*skb
= arg
;
856 if (!get_PollFlagFree(st
, skb
)) {
858 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
863 l2_st5_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
865 struct PStack
*st
= fi
->userdata
;
866 struct sk_buff
*skb
= arg
;
868 if (get_PollFlagFree(st
, skb
)) {
870 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
871 skb_queue_purge(&st
->l2
.i_queue
);
872 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
873 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
874 st5_dl_release_l2l3(st
);
875 FsmChangeState(fi
, ST_L2_4
);
880 l2_st6_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
882 struct PStack
*st
= fi
->userdata
;
883 struct sk_buff
*skb
= arg
;
885 if (get_PollFlagFree(st
, skb
)) {
887 lapb_dl_release_l2l3(st
, CONFIRM
);
888 FsmChangeState(fi
, ST_L2_4
);
893 enquiry_cr(struct PStack
*st
, u_char typ
, u_char cr
, u_char pf
)
897 u_char tmp
[MAX_HEADER_LEN
];
901 i
= sethdraddr(l2
, tmp
, cr
);
902 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
904 tmp
[i
++] = (l2
->vr
<< 1) | (pf
? 1 : 0);
906 tmp
[i
++] = (l2
->vr
<< 5) | typ
| (pf
? 0x10 : 0);
907 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
908 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for enquiry_cr\n");
911 memcpy(skb_put(skb
, i
), tmp
, i
);
912 enqueue_super(st
, skb
);
916 enquiry_response(struct PStack
*st
)
918 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
919 enquiry_cr(st
, RNR
, RSP
, 1);
921 enquiry_cr(st
, RR
, RSP
, 1);
922 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
926 transmit_enquiry(struct PStack
*st
)
928 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
929 enquiry_cr(st
, RNR
, CMD
, 1);
931 enquiry_cr(st
, RR
, CMD
, 1);
932 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
938 nrerrorrecovery(struct FsmInst
*fi
)
940 struct PStack
*st
= fi
->userdata
;
942 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'J');
944 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
948 invoke_retransmission(struct PStack
*st
, unsigned int nr
)
950 struct Layer2
*l2
= &st
->l2
;
954 spin_lock_irqsave(&l2
->lock
, flags
);
956 while (l2
->vs
!= nr
) {
958 if(test_bit(FLG_MOD128
, &l2
->flag
)) {
960 p1
= (l2
->vs
- l2
->va
) % 128;
963 p1
= (l2
->vs
- l2
->va
) % 8;
965 p1
= (p1
+ l2
->sow
) % l2
->window
;
966 if (test_bit(FLG_LAPB
, &l2
->flag
))
967 st
->l1
.bcs
->tx_cnt
+= l2
->windowar
[p1
]->len
+ l2headersize(l2
, 0);
968 skb_queue_head(&l2
->i_queue
, l2
->windowar
[p1
]);
969 l2
->windowar
[p1
] = NULL
;
971 spin_unlock_irqrestore(&l2
->lock
, flags
);
972 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
975 spin_unlock_irqrestore(&l2
->lock
, flags
);
979 l2_st7_got_super(struct FsmInst
*fi
, int event
, void *arg
)
981 struct PStack
*st
= fi
->userdata
;
982 struct sk_buff
*skb
= arg
;
983 int PollFlag
, rsp
, typ
= RR
;
985 struct Layer2
*l2
= &st
->l2
;
987 rsp
= *skb
->data
& 0x2;
988 if (test_bit(FLG_ORIG
, &l2
->flag
))
991 skb_pull(skb
, l2addrsize(l2
));
992 if (IsRNR(skb
->data
, st
)) {
997 if (IsREJ(skb
->data
, st
))
1000 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1001 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1002 nr
= skb
->data
[1] >> 1;
1004 PollFlag
= (skb
->data
[0] & 0x10);
1005 nr
= (skb
->data
[0] >> 5) & 0x7;
1011 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'A');
1013 enquiry_response(st
);
1015 if (legalnr(st
, nr
)) {
1018 invoke_retransmission(st
, nr
);
1020 if (FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
,
1021 EV_L2_T203
, NULL
, 6))
1022 l2m_debug(&st
->l2
.l2m
, "Restart T203 ST7 REJ");
1023 } else if ((nr
== l2
->vs
) && (typ
== RR
)) {
1026 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1027 EV_L2_T203
, NULL
, 7);
1028 } else if ((l2
->va
!= nr
) || (typ
== RNR
)) {
1030 if(typ
!= RR
) FsmDelTimer(&st
->l2
.t203
, 9);
1031 restart_t200(st
, 12);
1033 if (skb_queue_len(&st
->l2
.i_queue
) && (typ
== RR
))
1034 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1036 nrerrorrecovery(fi
);
1040 l2_feed_i_if_reest(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 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
1048 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1054 l2_feed_i_pull(struct FsmInst
*fi
, int event
, void *arg
)
1056 struct PStack
*st
= fi
->userdata
;
1057 struct sk_buff
*skb
= arg
;
1059 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1060 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1061 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1062 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1066 l2_feed_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1068 struct PStack
*st
= fi
->userdata
;
1069 struct sk_buff
*skb
= arg
;
1071 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1072 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1073 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1077 l2_got_iframe(struct FsmInst
*fi
, int event
, void *arg
)
1079 struct PStack
*st
= fi
->userdata
;
1080 struct sk_buff
*skb
= arg
;
1081 struct Layer2
*l2
= &(st
->l2
);
1082 int PollFlag
, ns
, i
;
1086 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1087 PollFlag
= ((skb
->data
[i
+ 1] & 0x1) == 0x1);
1088 ns
= skb
->data
[i
] >> 1;
1089 nr
= (skb
->data
[i
+ 1] >> 1) & 0x7f;
1091 PollFlag
= (skb
->data
[i
] & 0x10);
1092 ns
= (skb
->data
[i
] >> 1) & 0x7;
1093 nr
= (skb
->data
[i
] >> 5) & 0x7;
1095 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1097 if(PollFlag
) enquiry_response(st
);
1098 } else if (l2
->vr
== ns
) {
1100 if(test_bit(FLG_MOD128
, &l2
->flag
))
1104 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
1107 enquiry_response(st
);
1109 test_and_set_bit(FLG_ACK_PEND
, &l2
->flag
);
1110 skb_pull(skb
, l2headersize(l2
, 0));
1111 st
->l2
.l2l3(st
, DL_DATA
| INDICATION
, skb
);
1115 if (test_and_set_bit(FLG_REJEXC
, &l2
->flag
)) {
1117 enquiry_response(st
);
1119 enquiry_cr(st
, REJ
, RSP
, PollFlag
);
1120 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1124 if (legalnr(st
, nr
)) {
1125 if (!test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
) && (fi
->state
== ST_L2_7
)) {
1126 if (nr
== st
->l2
.vs
) {
1128 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1129 EV_L2_T203
, NULL
, 7);
1130 } else if (nr
!= st
->l2
.va
)
1131 restart_t200(st
, 14);
1135 nrerrorrecovery(fi
);
1139 if (skb_queue_len(&st
->l2
.i_queue
) && (fi
->state
== ST_L2_7
))
1140 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1141 if (test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
))
1142 enquiry_cr(st
, RR
, RSP
, 0);
1146 l2_got_tei(struct FsmInst
*fi
, int event
, void *arg
)
1148 struct PStack
*st
= fi
->userdata
;
1150 st
->l2
.tei
= (long) arg
;
1152 if (fi
->state
== ST_L2_3
) {
1154 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1156 FsmChangeState(fi
, ST_L2_4
);
1157 if (skb_queue_len(&st
->l2
.ui_queue
))
1162 l2_st5_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1164 struct PStack
*st
= fi
->userdata
;
1166 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1167 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1168 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1169 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1170 FsmChangeState(fi
, ST_L2_4
);
1171 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1172 skb_queue_purge(&st
->l2
.i_queue
);
1173 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'G');
1174 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1175 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1176 st5_dl_release_l2l3(st
);
1179 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1180 send_uframe(st
, (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
)
1186 l2_st6_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1188 struct PStack
*st
= fi
->userdata
;
1190 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1191 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1192 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1193 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1194 FsmChangeState(fi
, ST_L2_4
);
1195 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1196 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'H');
1197 lapb_dl_release_l2l3(st
, CONFIRM
);
1200 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
,
1202 send_uframe(st
, DISC
| 0x10, CMD
);
1207 l2_st7_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1209 struct PStack
*st
= fi
->userdata
;
1211 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1212 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1213 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1216 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1218 FsmChangeState(fi
, ST_L2_8
);
1220 transmit_enquiry(st
);
1225 l2_st8_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1227 struct PStack
*st
= fi
->userdata
;
1229 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1230 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1231 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1234 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1235 if (st
->l2
.rc
== st
->l2
.N200
) {
1236 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'I');
1238 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1240 transmit_enquiry(st
);
1246 l2_st7_tout_203(struct FsmInst
*fi
, int event
, void *arg
)
1248 struct PStack
*st
= fi
->userdata
;
1250 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1251 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1252 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 9);
1255 FsmChangeState(fi
, ST_L2_8
);
1256 transmit_enquiry(st
);
1261 l2_pull_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1263 struct PStack
*st
= fi
->userdata
;
1264 struct sk_buff
*skb
, *oskb
;
1265 struct Layer2
*l2
= &st
->l2
;
1266 u_char header
[MAX_HEADER_LEN
];
1274 skb
= skb_dequeue(&l2
->i_queue
);
1278 spin_lock_irqsave(&l2
->lock
, flags
);
1279 if(test_bit(FLG_MOD128
, &l2
->flag
))
1280 p1
= (l2
->vs
- l2
->va
) % 128;
1282 p1
= (l2
->vs
- l2
->va
) % 8;
1283 p1
= (p1
+ l2
->sow
) % l2
->window
;
1284 if (l2
->windowar
[p1
]) {
1285 printk(KERN_WARNING
"isdnl2 try overwrite ack queue entry %d\n",
1287 dev_kfree_skb(l2
->windowar
[p1
]);
1289 l2
->windowar
[p1
] = skb_clone(skb
, GFP_ATOMIC
);
1291 i
= sethdraddr(&st
->l2
, header
, CMD
);
1293 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1294 header
[i
++] = l2
->vs
<< 1;
1295 header
[i
++] = l2
->vr
<< 1;
1296 l2
->vs
= (l2
->vs
+ 1) % 128;
1298 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1299 l2
->vs
= (l2
->vs
+ 1) % 8;
1301 spin_unlock_irqrestore(&l2
->lock
, flags
);
1302 p1
= skb
->data
- skb
->head
;
1304 memcpy(skb_push(skb
, i
), header
, i
);
1307 "isdl2 pull_iqueue skb header(%d/%d) too short\n", i
, p1
);
1309 skb
= alloc_skb(oskb
->len
+ i
, GFP_ATOMIC
);
1310 memcpy(skb_put(skb
, i
), header
, i
);
1311 memcpy(skb_put(skb
, oskb
->len
), oskb
->data
, oskb
->len
);
1314 st
->l2
.l2l1(st
, PH_PULL
| INDICATION
, skb
);
1315 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1316 if (!test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
)) {
1317 FsmDelTimer(&st
->l2
.t203
, 13);
1318 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 11);
1320 if (skb_queue_len(&l2
->i_queue
) && cansend(st
))
1321 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1325 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1327 struct PStack
*st
= fi
->userdata
;
1328 struct sk_buff
*skb
= arg
;
1329 int PollFlag
, rsp
, rnr
= 0;
1331 struct Layer2
*l2
= &st
->l2
;
1333 rsp
= *skb
->data
& 0x2;
1334 if (test_bit(FLG_ORIG
, &l2
->flag
))
1337 skb_pull(skb
, l2addrsize(l2
));
1339 if (IsRNR(skb
->data
, st
)) {
1343 clear_peer_busy(l2
);
1345 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1346 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1347 nr
= skb
->data
[1] >> 1;
1349 PollFlag
= (skb
->data
[0] & 0x10);
1350 nr
= (skb
->data
[0] >> 5) & 0x7;
1354 if (rsp
&& PollFlag
) {
1355 if (legalnr(st
, nr
)) {
1357 restart_t200(st
, 15);
1360 FsmAddTimer(&l2
->t203
, l2
->T203
,
1361 EV_L2_T203
, NULL
, 5);
1364 invoke_retransmission(st
, nr
);
1365 FsmChangeState(fi
, ST_L2_7
);
1366 if (skb_queue_len(&l2
->i_queue
) && cansend(st
))
1367 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1369 nrerrorrecovery(fi
);
1371 if (!rsp
&& PollFlag
)
1372 enquiry_response(st
);
1373 if (legalnr(st
, nr
)) {
1376 nrerrorrecovery(fi
);
1381 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1383 struct PStack
*st
= fi
->userdata
;
1384 struct sk_buff
*skb
= arg
;
1386 skb_pull(skb
, l2addrsize(&st
->l2
) + 1);
1388 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1389 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1390 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'K');
1392 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1398 l2_st24_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1400 struct PStack
*st
= fi
->userdata
;
1402 skb_queue_purge(&st
->l2
.ui_queue
);
1404 FsmChangeState(fi
, ST_L2_1
);
1408 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1410 struct PStack
*st
= fi
->userdata
;
1412 skb_queue_purge(&st
->l2
.ui_queue
);
1414 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1415 FsmChangeState(fi
, ST_L2_1
);
1419 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1421 struct PStack
*st
= fi
->userdata
;
1423 skb_queue_purge(&st
->l2
.i_queue
);
1424 skb_queue_purge(&st
->l2
.ui_queue
);
1428 st5_dl_release_l2l3(st
);
1429 FsmChangeState(fi
, ST_L2_1
);
1433 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1435 struct PStack
*st
= fi
->userdata
;
1437 skb_queue_purge(&st
->l2
.ui_queue
);
1440 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1441 FsmChangeState(fi
, ST_L2_1
);
1445 l2_tei_remove(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
);
1454 FsmDelTimer(&st
->l2
.t203
, 19);
1455 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1456 FsmChangeState(fi
, ST_L2_1
);
1460 l2_st14_persistant_da(struct FsmInst
*fi
, int event
, void *arg
)
1462 struct PStack
*st
= fi
->userdata
;
1464 skb_queue_purge(&st
->l2
.i_queue
);
1465 skb_queue_purge(&st
->l2
.ui_queue
);
1466 if (test_and_clear_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
))
1467 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1471 l2_st5_persistant_da(struct FsmInst
*fi
, int event
, void *arg
)
1473 struct PStack
*st
= fi
->userdata
;
1475 skb_queue_purge(&st
->l2
.i_queue
);
1476 skb_queue_purge(&st
->l2
.ui_queue
);
1479 st5_dl_release_l2l3(st
);
1480 FsmChangeState(fi
, ST_L2_4
);
1484 l2_st6_persistant_da(struct FsmInst
*fi
, int event
, void *arg
)
1486 struct PStack
*st
= fi
->userdata
;
1488 skb_queue_purge(&st
->l2
.ui_queue
);
1490 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1491 FsmChangeState(fi
, ST_L2_4
);
1495 l2_persistant_da(struct FsmInst
*fi
, int event
, void *arg
)
1497 struct PStack
*st
= fi
->userdata
;
1499 skb_queue_purge(&st
->l2
.i_queue
);
1500 skb_queue_purge(&st
->l2
.ui_queue
);
1503 FsmDelTimer(&st
->l2
.t203
, 19);
1504 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1505 FsmChangeState(fi
, ST_L2_4
);
1509 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1511 struct PStack
*st
= fi
->userdata
;
1513 if(!test_and_set_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1514 enquiry_cr(st
, RNR
, RSP
, 0);
1515 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1520 l2_clear_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1522 struct PStack
*st
= fi
->userdata
;
1524 if(!test_and_clear_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1525 enquiry_cr(st
, RR
, RSP
, 0);
1526 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1531 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1533 struct PStack
*st
= fi
->userdata
;
1535 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1539 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1541 struct PStack
*st
= fi
->userdata
;
1543 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1545 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1548 static struct FsmNode L2FnList
[] __initdata
=
1550 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1551 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1552 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1553 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1554 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1555 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1556 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1557 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1558 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1559 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1560 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1561 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1562 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1563 {ST_L2_1
, EV_L2_DL_UNIT_DATA
, l2_queue_ui_assign
},
1564 {ST_L2_2
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1565 {ST_L2_3
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1566 {ST_L2_4
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1567 {ST_L2_5
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1568 {ST_L2_6
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1569 {ST_L2_7
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1570 {ST_L2_8
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1571 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1572 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1573 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1574 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1575 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1576 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1577 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1578 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1579 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1580 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1581 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1582 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1583 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1584 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1585 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1586 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1587 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1588 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1589 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1590 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1591 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1592 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1593 {ST_L2_6
, EV_L2_UA
, l2_released
},
1594 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1595 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1596 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1597 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1598 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1599 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1600 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1601 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1602 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1603 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1604 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1605 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1606 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1607 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1608 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1609 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1610 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1611 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1612 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1613 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1614 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1615 {ST_L2_5
, EV_L2_T200
, l2_st5_tout_200
},
1616 {ST_L2_6
, EV_L2_T200
, l2_st6_tout_200
},
1617 {ST_L2_7
, EV_L2_T200
, l2_st7_tout_200
},
1618 {ST_L2_8
, EV_L2_T200
, l2_st8_tout_200
},
1619 {ST_L2_7
, EV_L2_T203
, l2_st7_tout_203
},
1620 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1621 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1622 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1623 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1624 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1625 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1626 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1627 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1628 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1629 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1630 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistant_da
},
1631 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1632 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1633 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistant_da
},
1634 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistant_da
},
1635 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistant_da
},
1636 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistant_da
},
1637 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistant_da
},
1640 #define L2_FN_COUNT (sizeof(L2FnList)/sizeof(struct FsmNode))
1643 isdnl2_l1l2(struct PStack
*st
, int pr
, void *arg
)
1645 struct sk_buff
*skb
= arg
;
1651 case (PH_DATA
| INDICATION
):
1653 len
= l2addrsize(&st
->l2
);
1657 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
1661 if (!(*datap
& 1)) { /* I-Frame */
1662 if(!(c
= iframe_error(st
, skb
)))
1663 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_I
, skb
);
1664 } else if (IsSFrame(datap
, st
)) { /* S-Frame */
1665 if(!(c
= super_error(st
, skb
)))
1666 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_SUPER
, skb
);
1667 } else if (IsUI(datap
)) {
1668 if(!(c
= UI_error(st
, skb
)))
1669 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_UI
, skb
);
1670 } else if (IsSABME(datap
, st
)) {
1671 if(!(c
= unnum_error(st
, skb
, CMD
)))
1672 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_SABME
, skb
);
1673 } else if (IsUA(datap
)) {
1674 if(!(c
= unnum_error(st
, skb
, RSP
)))
1675 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_UA
, skb
);
1676 } else if (IsDISC(datap
)) {
1677 if(!(c
= unnum_error(st
, skb
, CMD
)))
1678 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_DISC
, skb
);
1679 } else if (IsDM(datap
)) {
1680 if(!(c
= unnum_error(st
, skb
, RSP
)))
1681 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_DM
, skb
);
1682 } else if (IsFRMR(datap
)) {
1683 if(!(c
= FRMR_error(st
,skb
)))
1684 ret
= FsmEvent(&st
->l2
.l2m
, EV_L2_FRMR
, skb
);
1686 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'L');
1692 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1698 case (PH_PULL
| CONFIRM
):
1699 FsmEvent(&st
->l2
.l2m
, EV_L2_ACK_PULL
, arg
);
1701 case (PH_PAUSE
| INDICATION
):
1702 test_and_set_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
1704 case (PH_PAUSE
| CONFIRM
):
1705 test_and_clear_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
1707 case (PH_ACTIVATE
| CONFIRM
):
1708 case (PH_ACTIVATE
| INDICATION
):
1709 test_and_set_bit(FLG_L1_ACTIV
, &st
->l2
.flag
);
1710 if (test_and_clear_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
))
1711 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_ESTABLISH_REQ
, arg
);
1713 case (PH_DEACTIVATE
| INDICATION
):
1714 case (PH_DEACTIVATE
| CONFIRM
):
1715 test_and_clear_bit(FLG_L1_ACTIV
, &st
->l2
.flag
);
1716 FsmEvent(&st
->l2
.l2m
, EV_L1_DEACTIVATE
, arg
);
1719 l2m_debug(&st
->l2
.l2m
, "l2 unknown pr %04x", pr
);
1725 isdnl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1728 case (DL_DATA
| REQUEST
):
1729 if (FsmEvent(&st
->l2
.l2m
, EV_L2_DL_DATA
, arg
)) {
1730 dev_kfree_skb((struct sk_buff
*) arg
);
1733 case (DL_UNIT_DATA
| REQUEST
):
1734 if (FsmEvent(&st
->l2
.l2m
, EV_L2_DL_UNIT_DATA
, arg
)) {
1735 dev_kfree_skb((struct sk_buff
*) arg
);
1738 case (DL_ESTABLISH
| REQUEST
):
1739 if (test_bit(FLG_L1_ACTIV
, &st
->l2
.flag
)) {
1740 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) ||
1741 test_bit(FLG_ORIG
, &st
->l2
.flag
)) {
1742 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_ESTABLISH_REQ
, arg
);
1745 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) ||
1746 test_bit(FLG_ORIG
, &st
->l2
.flag
)) {
1747 test_and_set_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
);
1749 st
->l2
.l2l1(st
, PH_ACTIVATE
, NULL
);
1752 case (DL_RELEASE
| REQUEST
):
1753 if (test_bit(FLG_LAPB
, &st
->l2
.flag
)) {
1754 st
->l2
.l2l1(st
, PH_DEACTIVATE
, NULL
);
1756 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_RELEASE_REQ
, arg
);
1758 case (MDL_ASSIGN
| REQUEST
):
1759 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ASSIGN
, arg
);
1761 case (MDL_REMOVE
| REQUEST
):
1762 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_REMOVE
, arg
);
1764 case (MDL_ERROR
| RESPONSE
):
1765 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ERROR
, arg
);
1771 releasestack_isdnl2(struct PStack
*st
)
1773 FsmDelTimer(&st
->l2
.t200
, 21);
1774 FsmDelTimer(&st
->l2
.t203
, 16);
1775 skb_queue_purge(&st
->l2
.i_queue
);
1776 skb_queue_purge(&st
->l2
.ui_queue
);
1777 ReleaseWin(&st
->l2
);
1781 l2m_debug(struct FsmInst
*fi
, char *fmt
, ...)
1784 struct PStack
*st
= fi
->userdata
;
1786 va_start(args
, fmt
);
1787 VHiSax_putstatus(st
->l1
.hardware
, st
->l2
.debug_id
, fmt
, args
);
1792 setstack_isdnl2(struct PStack
*st
, char *debug_id
)
1794 spin_lock_init(&st
->l2
.lock
);
1795 st
->l1
.l1l2
= isdnl2_l1l2
;
1796 st
->l3
.l3l2
= isdnl2_l3l2
;
1798 skb_queue_head_init(&st
->l2
.i_queue
);
1799 skb_queue_head_init(&st
->l2
.ui_queue
);
1803 st
->l2
.l2m
.fsm
= &l2fsm
;
1804 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1805 st
->l2
.l2m
.state
= ST_L2_4
;
1807 st
->l2
.l2m
.state
= ST_L2_1
;
1808 st
->l2
.l2m
.debug
= 0;
1809 st
->l2
.l2m
.userdata
= st
;
1810 st
->l2
.l2m
.userint
= 0;
1811 st
->l2
.l2m
.printdebug
= l2m_debug
;
1812 strcpy(st
->l2
.debug_id
, debug_id
);
1814 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t200
);
1815 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t203
);
1819 transl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1822 case (DL_DATA
| REQUEST
):
1823 case (DL_UNIT_DATA
| REQUEST
):
1824 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, arg
);
1826 case (DL_ESTABLISH
| REQUEST
):
1827 st
->l2
.l2l1(st
, PH_ACTIVATE
| REQUEST
, NULL
);
1829 case (DL_RELEASE
| REQUEST
):
1830 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1836 setstack_transl2(struct PStack
*st
)
1838 st
->l3
.l3l2
= transl2_l3l2
;
1842 releasestack_transl2(struct PStack
*st
)
1849 l2fsm
.state_count
= L2_STATE_COUNT
;
1850 l2fsm
.event_count
= L2_EVENT_COUNT
;
1851 l2fsm
.strEvent
= strL2Event
;
1852 l2fsm
.strState
= strL2State
;
1853 return FsmNew(&l2fsm
, L2FnList
, L2_FN_COUNT
);