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_empty(&l2
->i_queue
) ||
112 !skb_queue_empty(&l2
->ui_queue
))
113 test_and_set_bit(FLG_L2BLOCK
, &l2
->flag
);
117 clear_peer_busy(struct Layer2
*l2
) {
118 if (test_and_clear_bit(FLG_PEER_BUSY
, &l2
->flag
))
119 test_and_clear_bit(FLG_L2BLOCK
, &l2
->flag
);
123 InitWin(struct Layer2
*l2
)
127 for (i
= 0; i
< MAX_WINDOW
; i
++)
128 l2
->windowar
[i
] = NULL
;
132 freewin1(struct Layer2
*l2
)
136 for (i
= 0; i
< MAX_WINDOW
; i
++) {
137 if (l2
->windowar
[i
]) {
139 dev_kfree_skb(l2
->windowar
[i
]);
140 l2
->windowar
[i
] = NULL
;
147 freewin(struct PStack
*st
)
153 ReleaseWin(struct Layer2
*l2
)
157 if((cnt
= freewin1(l2
)))
158 printk(KERN_WARNING
"isdl2 freed %d skbuffs in release\n", cnt
);
161 static inline unsigned int
162 cansend(struct PStack
*st
)
166 if(test_bit(FLG_MOD128
, &st
->l2
.flag
))
167 p1
= (st
->l2
.vs
- st
->l2
.va
) % 128;
169 p1
= (st
->l2
.vs
- st
->l2
.va
) % 8;
170 return ((p1
< st
->l2
.window
) && !test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
));
174 clear_exception(struct Layer2
*l2
)
176 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
177 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
178 test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
);
183 l2headersize(struct Layer2
*l2
, int ui
)
185 return (((test_bit(FLG_MOD128
, &l2
->flag
) && (!ui
)) ? 2 : 1) +
186 (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1));
190 l2addrsize(struct Layer2
*l2
)
192 return (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1);
196 sethdraddr(struct Layer2
*l2
, u_char
* header
, int rsp
)
198 u_char
*ptr
= header
;
201 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
202 *ptr
++ = (l2
->sap
<< 2) | (rsp
? 2 : 0);
203 *ptr
++ = (l2
->tei
<< 1) | 1;
206 if (test_bit(FLG_ORIG
, &l2
->flag
))
217 enqueue_super(struct PStack
*st
,
220 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
221 st
->l1
.bcs
->tx_cnt
+= skb
->len
;
222 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, skb
);
225 #define enqueue_ui(a, b) enqueue_super(a, b)
230 return ((data
[0] & 0xef) == UI
);
236 return ((data
[0] & 0xef) == UA
);
242 return ((data
[0] & 0xef) == DM
);
246 IsDISC(u_char
* data
)
248 return ((data
[0] & 0xef) == DISC
);
252 IsSFrame(u_char
* data
, struct PStack
*st
)
254 register u_char d
= *data
;
256 if (!test_bit(FLG_MOD128
, &st
->l2
.flag
))
258 return(((d
& 0xf3) == 1) && ((d
& 0x0c) != 0x0c));
262 IsSABME(u_char
* data
, struct PStack
*st
)
264 u_char d
= data
[0] & ~0x10;
266 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? d
== SABME
: d
== SABM
);
270 IsREJ(u_char
* data
, struct PStack
*st
)
272 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == REJ
: (data
[0] & 0xf) == REJ
);
276 IsFRMR(u_char
* data
)
278 return ((data
[0] & 0xef) == FRMR
);
282 IsRNR(u_char
* data
, struct PStack
*st
)
284 return (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? data
[0] == RNR
: (data
[0] & 0xf) == RNR
);
288 iframe_error(struct PStack
*st
, struct sk_buff
*skb
)
290 int i
= l2addrsize(&st
->l2
) + (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1);
291 int rsp
= *skb
->data
& 0x2;
293 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
303 if ((skb
->len
- i
) > st
->l2
.maxlen
)
311 super_error(struct PStack
*st
, struct sk_buff
*skb
)
313 if (skb
->len
!= l2addrsize(&st
->l2
) +
314 (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? 2 : 1))
321 unnum_error(struct PStack
*st
, struct sk_buff
*skb
, int wantrsp
)
323 int rsp
= (*skb
->data
& 0x2) >> 1;
324 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
330 if (skb
->len
!= l2addrsize(&st
->l2
) + 1)
337 UI_error(struct PStack
*st
, struct sk_buff
*skb
)
339 int rsp
= *skb
->data
& 0x2;
340 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
346 if (skb
->len
> st
->l2
.maxlen
+ l2addrsize(&st
->l2
) + 1)
353 FRMR_error(struct PStack
*st
, struct sk_buff
*skb
)
355 int headers
= l2addrsize(&st
->l2
) + 1;
356 u_char
*datap
= skb
->data
+ headers
;
357 int rsp
= *skb
->data
& 0x2;
359 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
365 if (test_bit(FLG_MOD128
, &st
->l2
.flag
)) {
366 if (skb
->len
< headers
+ 5)
369 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x %2x %2x",
370 datap
[0], datap
[1], datap
[2],
373 if (skb
->len
< headers
+ 3)
376 l2m_debug(&st
->l2
.l2m
, "FRMR information %2x %2x %2x",
377 datap
[0], datap
[1], datap
[2]);
384 legalnr(struct PStack
*st
, unsigned int nr
)
386 struct Layer2
*l2
= &st
->l2
;
388 if(test_bit(FLG_MOD128
, &l2
->flag
))
389 return ((nr
- l2
->va
) % 128) <= ((l2
->vs
- l2
->va
) % 128);
391 return ((nr
- l2
->va
) % 8) <= ((l2
->vs
- l2
->va
) % 8);
395 setva(struct PStack
*st
, unsigned int nr
)
397 struct Layer2
*l2
= &st
->l2
;
401 spin_lock_irqsave(&l2
->lock
, flags
);
402 while (l2
->va
!= nr
) {
404 if(test_bit(FLG_MOD128
, &l2
->flag
))
408 len
= l2
->windowar
[l2
->sow
]->len
;
409 if (PACKET_NOACK
== l2
->windowar
[l2
->sow
]->pkt_type
)
411 dev_kfree_skb(l2
->windowar
[l2
->sow
]);
412 l2
->windowar
[l2
->sow
] = NULL
;
413 l2
->sow
= (l2
->sow
+ 1) % l2
->window
;
414 spin_unlock_irqrestore(&l2
->lock
, flags
);
415 if (test_bit(FLG_LLI_L2WAKEUP
, &st
->lli
.flag
) && (len
>=0))
416 lli_writewakeup(st
, len
);
417 spin_lock_irqsave(&l2
->lock
, flags
);
419 spin_unlock_irqrestore(&l2
->lock
, flags
);
423 send_uframe(struct PStack
*st
, u_char cmd
, u_char cr
)
426 u_char tmp
[MAX_HEADER_LEN
];
429 i
= sethdraddr(&st
->l2
, tmp
, cr
);
431 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
432 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for send_uframe\n");
435 memcpy(skb_put(skb
, i
), tmp
, i
);
436 enqueue_super(st
, skb
);
440 get_PollFlag(struct PStack
* st
, struct sk_buff
* skb
)
442 return (skb
->data
[l2addrsize(&(st
->l2
))] & 0x10);
446 get_PollFlagFree(struct PStack
*st
, struct sk_buff
*skb
)
450 PF
= get_PollFlag(st
, skb
);
456 start_t200(struct PStack
*st
, int i
)
458 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
459 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
463 restart_t200(struct PStack
*st
, int i
)
465 FsmRestartTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, i
);
466 test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
);
470 stop_t200(struct PStack
*st
, int i
)
472 if(test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
))
473 FsmDelTimer(&st
->l2
.t200
, i
);
477 st5_dl_release_l2l3(struct PStack
*st
)
481 if(test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
482 pr
= DL_RELEASE
| CONFIRM
;
484 pr
= DL_RELEASE
| INDICATION
;
486 st
->l2
.l2l3(st
, pr
, NULL
);
490 lapb_dl_release_l2l3(struct PStack
*st
, int f
)
492 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
493 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
494 st
->l2
.l2l3(st
, DL_RELEASE
| f
, NULL
);
498 establishlink(struct FsmInst
*fi
)
500 struct PStack
*st
= fi
->userdata
;
503 clear_exception(&st
->l2
);
505 cmd
= (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
) | 0x10;
506 send_uframe(st
, cmd
, CMD
);
507 FsmDelTimer(&st
->l2
.t203
, 1);
509 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
511 FsmChangeState(fi
, ST_L2_5
);
515 l2_mdl_error_ua(struct FsmInst
*fi
, int event
, void *arg
)
517 struct sk_buff
*skb
= arg
;
518 struct PStack
*st
= fi
->userdata
;
520 if (get_PollFlagFree(st
, skb
))
521 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'C');
523 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'D');
527 l2_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
529 struct sk_buff
*skb
= arg
;
530 struct PStack
*st
= fi
->userdata
;
532 if (get_PollFlagFree(st
, skb
))
533 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'B');
535 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'E');
537 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
542 l2_st8_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');
553 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
557 l2_go_st3(struct FsmInst
*fi
, int event
, void *arg
)
559 FsmChangeState(fi
, ST_L2_3
);
563 l2_mdl_assign(struct FsmInst
*fi
, int event
, void *arg
)
565 struct PStack
*st
= fi
->userdata
;
567 FsmChangeState(fi
, ST_L2_3
);
568 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
572 l2_queue_ui_assign(struct FsmInst
*fi
, int event
, void *arg
)
574 struct PStack
*st
= fi
->userdata
;
575 struct sk_buff
*skb
= arg
;
577 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
578 FsmChangeState(fi
, ST_L2_2
);
579 st
->l2
.l2tei(st
, MDL_ASSIGN
| INDICATION
, NULL
);
583 l2_queue_ui(struct FsmInst
*fi
, int event
, void *arg
)
585 struct PStack
*st
= fi
->userdata
;
586 struct sk_buff
*skb
= arg
;
588 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
592 tx_ui(struct PStack
*st
)
595 u_char header
[MAX_HEADER_LEN
];
598 i
= sethdraddr(&(st
->l2
), header
, CMD
);
600 while ((skb
= skb_dequeue(&st
->l2
.ui_queue
))) {
601 memcpy(skb_push(skb
, i
), header
, i
);
607 l2_send_ui(struct FsmInst
*fi
, int event
, void *arg
)
609 struct PStack
*st
= fi
->userdata
;
610 struct sk_buff
*skb
= arg
;
612 skb_queue_tail(&st
->l2
.ui_queue
, skb
);
617 l2_got_ui(struct FsmInst
*fi
, int event
, void *arg
)
619 struct PStack
*st
= fi
->userdata
;
620 struct sk_buff
*skb
= arg
;
622 skb_pull(skb
, l2headersize(&st
->l2
, 1));
623 st
->l2
.l2l3(st
, DL_UNIT_DATA
| INDICATION
, skb
);
624 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
625 * in states 1-3 for broadcast
632 l2_establish(struct FsmInst
*fi
, int event
, void *arg
)
634 struct PStack
*st
= fi
->userdata
;
637 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
641 l2_discard_i_setl3(struct FsmInst
*fi
, int event
, void *arg
)
643 struct PStack
*st
= fi
->userdata
;
645 skb_queue_purge(&st
->l2
.i_queue
);
646 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
647 test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
);
651 l2_l3_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
653 struct PStack
*st
= fi
->userdata
;
655 skb_queue_purge(&st
->l2
.i_queue
);
657 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
661 l2_release(struct FsmInst
*fi
, int event
, void *arg
)
663 struct PStack
*st
= fi
->userdata
;
665 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
669 l2_pend_rel(struct FsmInst
*fi
, int event
, void *arg
)
671 struct PStack
*st
= fi
->userdata
;
673 test_and_set_bit(FLG_PEND_REL
, &st
->l2
.flag
);
677 l2_disconnect(struct FsmInst
*fi
, int event
, void *arg
)
679 struct PStack
*st
= fi
->userdata
;
681 skb_queue_purge(&st
->l2
.i_queue
);
683 FsmChangeState(fi
, ST_L2_6
);
685 send_uframe(st
, DISC
| 0x10, CMD
);
686 FsmDelTimer(&st
->l2
.t203
, 1);
691 l2_start_multi(struct FsmInst
*fi
, int event
, void *arg
)
693 struct PStack
*st
= fi
->userdata
;
694 struct sk_buff
*skb
= arg
;
696 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
698 clear_exception(&st
->l2
);
703 FsmChangeState(fi
, ST_L2_7
);
704 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
706 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
710 l2_send_UA(struct FsmInst
*fi
, int event
, void *arg
)
712 struct PStack
*st
= fi
->userdata
;
713 struct sk_buff
*skb
= arg
;
715 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
719 l2_send_DM(struct FsmInst
*fi
, int event
, void *arg
)
721 struct PStack
*st
= fi
->userdata
;
722 struct sk_buff
*skb
= arg
;
724 send_uframe(st
, DM
| get_PollFlagFree(st
, skb
), RSP
);
728 l2_restart_multi(struct FsmInst
*fi
, int event
, void *arg
)
730 struct PStack
*st
= fi
->userdata
;
731 struct sk_buff
*skb
= arg
;
736 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
738 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'F');
740 if (st
->l2
.vs
!= st
->l2
.va
) {
741 skb_queue_purge(&st
->l2
.i_queue
);
745 clear_exception(&st
->l2
);
750 FsmChangeState(fi
, ST_L2_7
);
752 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 3);
755 st
->l2
.l2l3(st
, DL_ESTABLISH
| INDICATION
, NULL
);
757 if ((ST_L2_7
==state
) || (ST_L2_8
== state
))
758 if (!skb_queue_empty(&st
->l2
.i_queue
) && cansend(st
))
759 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
763 l2_stop_multi(struct FsmInst
*fi
, int event
, void *arg
)
765 struct PStack
*st
= fi
->userdata
;
766 struct sk_buff
*skb
= arg
;
768 FsmChangeState(fi
, ST_L2_4
);
769 FsmDelTimer(&st
->l2
.t203
, 3);
772 send_uframe(st
, UA
| get_PollFlagFree(st
, skb
), RSP
);
774 skb_queue_purge(&st
->l2
.i_queue
);
776 lapb_dl_release_l2l3(st
, INDICATION
);
780 l2_connected(struct FsmInst
*fi
, int event
, void *arg
)
782 struct PStack
*st
= fi
->userdata
;
783 struct sk_buff
*skb
= arg
;
786 if (!get_PollFlag(st
, skb
)) {
787 l2_mdl_error_ua(fi
, event
, arg
);
792 if (test_and_clear_bit(FLG_PEND_REL
, &st
->l2
.flag
))
793 l2_disconnect(fi
, event
, arg
);
795 if (test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
)) {
796 pr
= DL_ESTABLISH
| CONFIRM
;
797 } else if (st
->l2
.vs
!= st
->l2
.va
) {
798 skb_queue_purge(&st
->l2
.i_queue
);
799 pr
= DL_ESTABLISH
| INDICATION
;
808 FsmChangeState(fi
, ST_L2_7
);
809 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 4);
812 st
->l2
.l2l3(st
, pr
, NULL
);
814 if (!skb_queue_empty(&st
->l2
.i_queue
) && cansend(st
))
815 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
819 l2_released(struct FsmInst
*fi
, int event
, void *arg
)
821 struct PStack
*st
= fi
->userdata
;
822 struct sk_buff
*skb
= arg
;
824 if (!get_PollFlag(st
, skb
)) {
825 l2_mdl_error_ua(fi
, event
, arg
);
831 lapb_dl_release_l2l3(st
, CONFIRM
);
832 FsmChangeState(fi
, ST_L2_4
);
836 l2_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
838 struct PStack
*st
= fi
->userdata
;
839 struct sk_buff
*skb
= arg
;
841 if (!get_PollFlagFree(st
, skb
)) {
843 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
848 l2_st5_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
850 struct PStack
*st
= fi
->userdata
;
851 struct sk_buff
*skb
= arg
;
853 if (get_PollFlagFree(st
, skb
)) {
855 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
856 skb_queue_purge(&st
->l2
.i_queue
);
857 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
858 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
859 st5_dl_release_l2l3(st
);
860 FsmChangeState(fi
, ST_L2_4
);
865 l2_st6_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
867 struct PStack
*st
= fi
->userdata
;
868 struct sk_buff
*skb
= arg
;
870 if (get_PollFlagFree(st
, skb
)) {
872 lapb_dl_release_l2l3(st
, CONFIRM
);
873 FsmChangeState(fi
, ST_L2_4
);
878 enquiry_cr(struct PStack
*st
, u_char typ
, u_char cr
, u_char pf
)
882 u_char tmp
[MAX_HEADER_LEN
];
886 i
= sethdraddr(l2
, tmp
, cr
);
887 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
889 tmp
[i
++] = (l2
->vr
<< 1) | (pf
? 1 : 0);
891 tmp
[i
++] = (l2
->vr
<< 5) | typ
| (pf
? 0x10 : 0);
892 if (!(skb
= alloc_skb(i
, GFP_ATOMIC
))) {
893 printk(KERN_WARNING
"isdl2 can't alloc sbbuff for enquiry_cr\n");
896 memcpy(skb_put(skb
, i
), tmp
, i
);
897 enqueue_super(st
, skb
);
901 enquiry_response(struct PStack
*st
)
903 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
904 enquiry_cr(st
, RNR
, RSP
, 1);
906 enquiry_cr(st
, RR
, RSP
, 1);
907 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
911 transmit_enquiry(struct PStack
*st
)
913 if (test_bit(FLG_OWN_BUSY
, &st
->l2
.flag
))
914 enquiry_cr(st
, RNR
, CMD
, 1);
916 enquiry_cr(st
, RR
, CMD
, 1);
917 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
923 nrerrorrecovery(struct FsmInst
*fi
)
925 struct PStack
*st
= fi
->userdata
;
927 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'J');
929 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
933 invoke_retransmission(struct PStack
*st
, unsigned int nr
)
935 struct Layer2
*l2
= &st
->l2
;
939 spin_lock_irqsave(&l2
->lock
, flags
);
941 while (l2
->vs
!= nr
) {
943 if(test_bit(FLG_MOD128
, &l2
->flag
)) {
945 p1
= (l2
->vs
- l2
->va
) % 128;
948 p1
= (l2
->vs
- l2
->va
) % 8;
950 p1
= (p1
+ l2
->sow
) % l2
->window
;
951 if (test_bit(FLG_LAPB
, &l2
->flag
))
952 st
->l1
.bcs
->tx_cnt
+= l2
->windowar
[p1
]->len
+ l2headersize(l2
, 0);
953 skb_queue_head(&l2
->i_queue
, l2
->windowar
[p1
]);
954 l2
->windowar
[p1
] = NULL
;
956 spin_unlock_irqrestore(&l2
->lock
, flags
);
957 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
960 spin_unlock_irqrestore(&l2
->lock
, flags
);
964 l2_st7_got_super(struct FsmInst
*fi
, int event
, void *arg
)
966 struct PStack
*st
= fi
->userdata
;
967 struct sk_buff
*skb
= arg
;
968 int PollFlag
, rsp
, typ
= RR
;
970 struct Layer2
*l2
= &st
->l2
;
972 rsp
= *skb
->data
& 0x2;
973 if (test_bit(FLG_ORIG
, &l2
->flag
))
976 skb_pull(skb
, l2addrsize(l2
));
977 if (IsRNR(skb
->data
, st
)) {
982 if (IsREJ(skb
->data
, st
))
985 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
986 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
987 nr
= skb
->data
[1] >> 1;
989 PollFlag
= (skb
->data
[0] & 0x10);
990 nr
= (skb
->data
[0] >> 5) & 0x7;
996 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'A');
998 enquiry_response(st
);
1000 if (legalnr(st
, nr
)) {
1003 invoke_retransmission(st
, nr
);
1005 if (FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
,
1006 EV_L2_T203
, NULL
, 6))
1007 l2m_debug(&st
->l2
.l2m
, "Restart T203 ST7 REJ");
1008 } else if ((nr
== l2
->vs
) && (typ
== RR
)) {
1011 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1012 EV_L2_T203
, NULL
, 7);
1013 } else if ((l2
->va
!= nr
) || (typ
== RNR
)) {
1015 if(typ
!= RR
) FsmDelTimer(&st
->l2
.t203
, 9);
1016 restart_t200(st
, 12);
1018 if (!skb_queue_empty(&st
->l2
.i_queue
) && (typ
== RR
))
1019 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1021 nrerrorrecovery(fi
);
1025 l2_feed_i_if_reest(struct FsmInst
*fi
, int event
, void *arg
)
1027 struct PStack
*st
= fi
->userdata
;
1028 struct sk_buff
*skb
= arg
;
1030 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1031 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1032 if (!test_bit(FLG_L3_INIT
, &st
->l2
.flag
))
1033 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1039 l2_feed_i_pull(struct FsmInst
*fi
, int event
, void *arg
)
1041 struct PStack
*st
= fi
->userdata
;
1042 struct sk_buff
*skb
= arg
;
1044 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1045 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1046 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1047 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1051 l2_feed_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1053 struct PStack
*st
= fi
->userdata
;
1054 struct sk_buff
*skb
= arg
;
1056 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1057 st
->l1
.bcs
->tx_cnt
+= skb
->len
+ l2headersize(&st
->l2
, 0);
1058 skb_queue_tail(&st
->l2
.i_queue
, skb
);
1062 l2_got_iframe(struct FsmInst
*fi
, int event
, void *arg
)
1064 struct PStack
*st
= fi
->userdata
;
1065 struct sk_buff
*skb
= arg
;
1066 struct Layer2
*l2
= &(st
->l2
);
1067 int PollFlag
, ns
, i
;
1071 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1072 PollFlag
= ((skb
->data
[i
+ 1] & 0x1) == 0x1);
1073 ns
= skb
->data
[i
] >> 1;
1074 nr
= (skb
->data
[i
+ 1] >> 1) & 0x7f;
1076 PollFlag
= (skb
->data
[i
] & 0x10);
1077 ns
= (skb
->data
[i
] >> 1) & 0x7;
1078 nr
= (skb
->data
[i
] >> 5) & 0x7;
1080 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1082 if(PollFlag
) enquiry_response(st
);
1083 } else if (l2
->vr
== ns
) {
1085 if(test_bit(FLG_MOD128
, &l2
->flag
))
1089 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
1092 enquiry_response(st
);
1094 test_and_set_bit(FLG_ACK_PEND
, &l2
->flag
);
1095 skb_pull(skb
, l2headersize(l2
, 0));
1096 st
->l2
.l2l3(st
, DL_DATA
| INDICATION
, skb
);
1100 if (test_and_set_bit(FLG_REJEXC
, &l2
->flag
)) {
1102 enquiry_response(st
);
1104 enquiry_cr(st
, REJ
, RSP
, PollFlag
);
1105 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1109 if (legalnr(st
, nr
)) {
1110 if (!test_bit(FLG_PEER_BUSY
, &st
->l2
.flag
) && (fi
->state
== ST_L2_7
)) {
1111 if (nr
== st
->l2
.vs
) {
1113 FsmRestartTimer(&st
->l2
.t203
, st
->l2
.T203
,
1114 EV_L2_T203
, NULL
, 7);
1115 } else if (nr
!= st
->l2
.va
)
1116 restart_t200(st
, 14);
1120 nrerrorrecovery(fi
);
1124 if (!skb_queue_empty(&st
->l2
.i_queue
) && (fi
->state
== ST_L2_7
))
1125 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1126 if (test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
))
1127 enquiry_cr(st
, RR
, RSP
, 0);
1131 l2_got_tei(struct FsmInst
*fi
, int event
, void *arg
)
1133 struct PStack
*st
= fi
->userdata
;
1135 st
->l2
.tei
= (long) arg
;
1137 if (fi
->state
== ST_L2_3
) {
1139 test_and_set_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1141 FsmChangeState(fi
, ST_L2_4
);
1142 if (!skb_queue_empty(&st
->l2
.ui_queue
))
1147 l2_st5_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1149 struct PStack
*st
= fi
->userdata
;
1151 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1152 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1153 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1154 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1155 FsmChangeState(fi
, ST_L2_4
);
1156 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1157 skb_queue_purge(&st
->l2
.i_queue
);
1158 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'G');
1159 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1160 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1161 st5_dl_release_l2l3(st
);
1164 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1165 send_uframe(st
, (test_bit(FLG_MOD128
, &st
->l2
.flag
) ? SABME
: SABM
)
1171 l2_st6_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1173 struct PStack
*st
= fi
->userdata
;
1175 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1176 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1177 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1178 } else if (st
->l2
.rc
== st
->l2
.N200
) {
1179 FsmChangeState(fi
, ST_L2_4
);
1180 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1181 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'H');
1182 lapb_dl_release_l2l3(st
, CONFIRM
);
1185 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
,
1187 send_uframe(st
, DISC
| 0x10, CMD
);
1192 l2_st7_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1194 struct PStack
*st
= fi
->userdata
;
1196 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1197 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1198 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1201 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1203 FsmChangeState(fi
, ST_L2_8
);
1205 transmit_enquiry(st
);
1210 l2_st8_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1212 struct PStack
*st
= fi
->userdata
;
1214 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1215 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1216 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 9);
1219 test_and_clear_bit(FLG_T200_RUN
, &st
->l2
.flag
);
1220 if (st
->l2
.rc
== st
->l2
.N200
) {
1221 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'I');
1223 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1225 transmit_enquiry(st
);
1231 l2_st7_tout_203(struct FsmInst
*fi
, int event
, void *arg
)
1233 struct PStack
*st
= fi
->userdata
;
1235 if (test_bit(FLG_LAPD
, &st
->l2
.flag
) &&
1236 test_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
)) {
1237 FsmAddTimer(&st
->l2
.t203
, st
->l2
.T203
, EV_L2_T203
, NULL
, 9);
1240 FsmChangeState(fi
, ST_L2_8
);
1241 transmit_enquiry(st
);
1246 l2_pull_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1248 struct PStack
*st
= fi
->userdata
;
1249 struct sk_buff
*skb
, *oskb
;
1250 struct Layer2
*l2
= &st
->l2
;
1251 u_char header
[MAX_HEADER_LEN
];
1259 skb
= skb_dequeue(&l2
->i_queue
);
1263 spin_lock_irqsave(&l2
->lock
, flags
);
1264 if(test_bit(FLG_MOD128
, &l2
->flag
))
1265 p1
= (l2
->vs
- l2
->va
) % 128;
1267 p1
= (l2
->vs
- l2
->va
) % 8;
1268 p1
= (p1
+ l2
->sow
) % l2
->window
;
1269 if (l2
->windowar
[p1
]) {
1270 printk(KERN_WARNING
"isdnl2 try overwrite ack queue entry %d\n",
1272 dev_kfree_skb(l2
->windowar
[p1
]);
1274 l2
->windowar
[p1
] = skb_clone(skb
, GFP_ATOMIC
);
1276 i
= sethdraddr(&st
->l2
, header
, CMD
);
1278 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1279 header
[i
++] = l2
->vs
<< 1;
1280 header
[i
++] = l2
->vr
<< 1;
1281 l2
->vs
= (l2
->vs
+ 1) % 128;
1283 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1284 l2
->vs
= (l2
->vs
+ 1) % 8;
1286 spin_unlock_irqrestore(&l2
->lock
, flags
);
1287 p1
= skb
->data
- skb
->head
;
1289 memcpy(skb_push(skb
, i
), header
, i
);
1292 "isdl2 pull_iqueue skb header(%d/%d) too short\n", i
, p1
);
1294 skb
= alloc_skb(oskb
->len
+ i
, GFP_ATOMIC
);
1295 memcpy(skb_put(skb
, i
), header
, i
);
1296 skb_copy_from_linear_data(oskb
,
1297 skb_put(skb
, oskb
->len
), oskb
->len
);
1298 dev_kfree_skb(oskb
);
1300 st
->l2
.l2l1(st
, PH_PULL
| INDICATION
, skb
);
1301 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1302 if (!test_and_set_bit(FLG_T200_RUN
, &st
->l2
.flag
)) {
1303 FsmDelTimer(&st
->l2
.t203
, 13);
1304 FsmAddTimer(&st
->l2
.t200
, st
->l2
.T200
, EV_L2_T200
, NULL
, 11);
1306 if (!skb_queue_empty(&l2
->i_queue
) && cansend(st
))
1307 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1311 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1313 struct PStack
*st
= fi
->userdata
;
1314 struct sk_buff
*skb
= arg
;
1315 int PollFlag
, rsp
, rnr
= 0;
1317 struct Layer2
*l2
= &st
->l2
;
1319 rsp
= *skb
->data
& 0x2;
1320 if (test_bit(FLG_ORIG
, &l2
->flag
))
1323 skb_pull(skb
, l2addrsize(l2
));
1325 if (IsRNR(skb
->data
, st
)) {
1329 clear_peer_busy(l2
);
1331 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1332 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1333 nr
= skb
->data
[1] >> 1;
1335 PollFlag
= (skb
->data
[0] & 0x10);
1336 nr
= (skb
->data
[0] >> 5) & 0x7;
1340 if (rsp
&& PollFlag
) {
1341 if (legalnr(st
, nr
)) {
1343 restart_t200(st
, 15);
1346 FsmAddTimer(&l2
->t203
, l2
->T203
,
1347 EV_L2_T203
, NULL
, 5);
1350 invoke_retransmission(st
, nr
);
1351 FsmChangeState(fi
, ST_L2_7
);
1352 if (!skb_queue_empty(&l2
->i_queue
) && cansend(st
))
1353 st
->l2
.l2l1(st
, PH_PULL
| REQUEST
, NULL
);
1355 nrerrorrecovery(fi
);
1357 if (!rsp
&& PollFlag
)
1358 enquiry_response(st
);
1359 if (legalnr(st
, nr
)) {
1362 nrerrorrecovery(fi
);
1367 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1369 struct PStack
*st
= fi
->userdata
;
1370 struct sk_buff
*skb
= arg
;
1372 skb_pull(skb
, l2addrsize(&st
->l2
) + 1);
1374 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1375 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1376 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, (void *) 'K');
1378 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1384 l2_st24_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1386 struct PStack
*st
= fi
->userdata
;
1388 skb_queue_purge(&st
->l2
.ui_queue
);
1390 FsmChangeState(fi
, ST_L2_1
);
1394 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1396 struct PStack
*st
= fi
->userdata
;
1398 skb_queue_purge(&st
->l2
.ui_queue
);
1400 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1401 FsmChangeState(fi
, ST_L2_1
);
1405 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1407 struct PStack
*st
= fi
->userdata
;
1409 skb_queue_purge(&st
->l2
.i_queue
);
1410 skb_queue_purge(&st
->l2
.ui_queue
);
1414 st5_dl_release_l2l3(st
);
1415 FsmChangeState(fi
, ST_L2_1
);
1419 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1421 struct PStack
*st
= fi
->userdata
;
1423 skb_queue_purge(&st
->l2
.ui_queue
);
1426 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1427 FsmChangeState(fi
, ST_L2_1
);
1431 l2_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1433 struct PStack
*st
= fi
->userdata
;
1435 skb_queue_purge(&st
->l2
.i_queue
);
1436 skb_queue_purge(&st
->l2
.ui_queue
);
1440 FsmDelTimer(&st
->l2
.t203
, 19);
1441 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1442 FsmChangeState(fi
, ST_L2_1
);
1446 l2_st14_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1448 struct PStack
*st
= fi
->userdata
;
1450 skb_queue_purge(&st
->l2
.i_queue
);
1451 skb_queue_purge(&st
->l2
.ui_queue
);
1452 if (test_and_clear_bit(FLG_ESTAB_PEND
, &st
->l2
.flag
))
1453 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1457 l2_st5_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1459 struct PStack
*st
= fi
->userdata
;
1461 skb_queue_purge(&st
->l2
.i_queue
);
1462 skb_queue_purge(&st
->l2
.ui_queue
);
1465 st5_dl_release_l2l3(st
);
1466 FsmChangeState(fi
, ST_L2_4
);
1470 l2_st6_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1472 struct PStack
*st
= fi
->userdata
;
1474 skb_queue_purge(&st
->l2
.ui_queue
);
1476 st
->l2
.l2l3(st
, DL_RELEASE
| CONFIRM
, NULL
);
1477 FsmChangeState(fi
, ST_L2_4
);
1481 l2_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1483 struct PStack
*st
= fi
->userdata
;
1485 skb_queue_purge(&st
->l2
.i_queue
);
1486 skb_queue_purge(&st
->l2
.ui_queue
);
1489 FsmDelTimer(&st
->l2
.t203
, 19);
1490 st
->l2
.l2l3(st
, DL_RELEASE
| INDICATION
, NULL
);
1491 FsmChangeState(fi
, ST_L2_4
);
1495 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1497 struct PStack
*st
= fi
->userdata
;
1499 if(!test_and_set_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1500 enquiry_cr(st
, RNR
, RSP
, 0);
1501 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1506 l2_clear_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1508 struct PStack
*st
= fi
->userdata
;
1510 if(!test_and_clear_bit(FLG_OWN_BUSY
, &st
->l2
.flag
)) {
1511 enquiry_cr(st
, RR
, RSP
, 0);
1512 test_and_clear_bit(FLG_ACK_PEND
, &st
->l2
.flag
);
1517 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1519 struct PStack
*st
= fi
->userdata
;
1521 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1525 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1527 struct PStack
*st
= fi
->userdata
;
1529 st
->ma
.layer(st
, MDL_ERROR
| INDICATION
, arg
);
1531 test_and_clear_bit(FLG_L3_INIT
, &st
->l2
.flag
);
1534 static struct FsmNode L2FnList
[] __initdata
=
1536 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1537 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1538 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1539 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1540 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1541 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1542 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1543 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1544 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1545 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1546 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1547 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1548 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1549 {ST_L2_1
, EV_L2_DL_UNIT_DATA
, l2_queue_ui_assign
},
1550 {ST_L2_2
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1551 {ST_L2_3
, EV_L2_DL_UNIT_DATA
, l2_queue_ui
},
1552 {ST_L2_4
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1553 {ST_L2_5
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1554 {ST_L2_6
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1555 {ST_L2_7
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1556 {ST_L2_8
, EV_L2_DL_UNIT_DATA
, l2_send_ui
},
1557 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1558 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1559 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1560 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1561 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1562 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1563 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1564 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1565 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1566 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1567 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1568 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1569 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1570 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1571 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1572 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1573 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1574 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1575 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1576 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1577 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1578 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1579 {ST_L2_6
, EV_L2_UA
, l2_released
},
1580 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1581 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1582 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1583 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1584 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1585 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1586 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1587 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1588 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1589 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1590 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1591 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1592 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1593 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1594 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1595 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1596 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1597 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1598 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1599 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1600 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1601 {ST_L2_5
, EV_L2_T200
, l2_st5_tout_200
},
1602 {ST_L2_6
, EV_L2_T200
, l2_st6_tout_200
},
1603 {ST_L2_7
, EV_L2_T200
, l2_st7_tout_200
},
1604 {ST_L2_8
, EV_L2_T200
, l2_st8_tout_200
},
1605 {ST_L2_7
, EV_L2_T203
, l2_st7_tout_203
},
1606 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1607 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1608 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1609 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1610 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1611 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1612 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1613 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1614 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1615 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1616 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1617 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1618 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1619 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1620 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistent_da
},
1621 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistent_da
},
1622 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1623 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1627 isdnl2_l1l2(struct PStack
*st
, int pr
, void *arg
)
1629 struct sk_buff
*skb
= arg
;
1635 case (PH_DATA
| INDICATION
):
1637 len
= l2addrsize(&st
->l2
);
1641 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
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
);
1670 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *) 'L');
1676 FsmEvent(&st
->l2
.l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1682 case (PH_PULL
| CONFIRM
):
1683 FsmEvent(&st
->l2
.l2m
, EV_L2_ACK_PULL
, arg
);
1685 case (PH_PAUSE
| INDICATION
):
1686 test_and_set_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
1688 case (PH_PAUSE
| CONFIRM
):
1689 test_and_clear_bit(FLG_DCHAN_BUSY
, &st
->l2
.flag
);
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
);
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
);
1703 l2m_debug(&st
->l2
.l2m
, "l2 unknown pr %04x", pr
);
1709 isdnl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1712 case (DL_DATA
| REQUEST
):
1713 if (FsmEvent(&st
->l2
.l2m
, EV_L2_DL_DATA
, arg
)) {
1714 dev_kfree_skb((struct sk_buff
*) arg
);
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
);
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
);
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
);
1733 st
->l2
.l2l1(st
, PH_ACTIVATE
, NULL
);
1736 case (DL_RELEASE
| REQUEST
):
1737 if (test_bit(FLG_LAPB
, &st
->l2
.flag
)) {
1738 st
->l2
.l2l1(st
, PH_DEACTIVATE
, NULL
);
1740 FsmEvent(&st
->l2
.l2m
, EV_L2_DL_RELEASE_REQ
, arg
);
1742 case (MDL_ASSIGN
| REQUEST
):
1743 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ASSIGN
, arg
);
1745 case (MDL_REMOVE
| REQUEST
):
1746 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_REMOVE
, arg
);
1748 case (MDL_ERROR
| RESPONSE
):
1749 FsmEvent(&st
->l2
.l2m
, EV_L2_MDL_ERROR
, arg
);
1755 releasestack_isdnl2(struct PStack
*st
)
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
);
1765 l2m_debug(struct FsmInst
*fi
, char *fmt
, ...)
1768 struct PStack
*st
= fi
->userdata
;
1770 va_start(args
, fmt
);
1771 VHiSax_putstatus(st
->l1
.hardware
, st
->l2
.debug_id
, fmt
, args
);
1776 setstack_isdnl2(struct PStack
*st
, char *debug_id
)
1778 spin_lock_init(&st
->l2
.lock
);
1779 st
->l1
.l1l2
= isdnl2_l1l2
;
1780 st
->l3
.l3l2
= isdnl2_l3l2
;
1782 skb_queue_head_init(&st
->l2
.i_queue
);
1783 skb_queue_head_init(&st
->l2
.ui_queue
);
1787 st
->l2
.l2m
.fsm
= &l2fsm
;
1788 if (test_bit(FLG_LAPB
, &st
->l2
.flag
))
1789 st
->l2
.l2m
.state
= ST_L2_4
;
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
);
1798 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t200
);
1799 FsmInitTimer(&st
->l2
.l2m
, &st
->l2
.t203
);
1803 transl2_l3l2(struct PStack
*st
, int pr
, void *arg
)
1806 case (DL_DATA
| REQUEST
):
1807 case (DL_UNIT_DATA
| REQUEST
):
1808 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, arg
);
1810 case (DL_ESTABLISH
| REQUEST
):
1811 st
->l2
.l2l1(st
, PH_ACTIVATE
| REQUEST
, NULL
);
1813 case (DL_RELEASE
| REQUEST
):
1814 st
->l2
.l2l1(st
, PH_DEACTIVATE
| REQUEST
, NULL
);
1820 setstack_transl2(struct PStack
*st
)
1822 st
->l3
.l3l2
= transl2_l3l2
;
1826 releasestack_transl2(struct PStack
*st
)
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
, ARRAY_SIZE(L2FnList
));