1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author Karsten Keil <kkeil@novell.com>
6 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
9 #include <linux/mISDNif.h>
10 #include <linux/slab.h>
18 struct Fsm l2fsm
= {NULL
, 0, 0, NULL
, NULL
};
20 static char *strL2State
[] =
44 EV_L2_DL_ESTABLISH_REQ
,
59 #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR + 1)
61 static char *strL2Event
[] =
74 "EV_L2_DL_ESTABLISH_REQ",
75 "EV_L2_DL_RELEASE_REQ",
85 "EV_L2_CLEAR_OWN_BUSY",
90 l2m_debug(struct FsmInst
*fi
, char *fmt
, ...)
92 struct layer2
*l2
= fi
->userdata
;
96 if (!(*debug
& DEBUG_L2_FSM
))
104 printk(KERN_DEBUG
"%s l2 (sapi %d tei %d): %pV\n",
105 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
, &vaf
);
111 l2headersize(struct layer2
*l2
, int ui
)
113 return ((test_bit(FLG_MOD128
, &l2
->flag
) && (!ui
)) ? 2 : 1) +
114 (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1);
118 l2addrsize(struct layer2
*l2
)
120 return test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1;
124 l2_newid(struct layer2
*l2
)
138 l2up(struct layer2
*l2
, u_int prim
, struct sk_buff
*skb
)
144 mISDN_HEAD_PRIM(skb
) = prim
;
145 mISDN_HEAD_ID(skb
) = (l2
->ch
.nr
<< 16) | l2
->ch
.addr
;
146 err
= l2
->up
->send(l2
->up
, skb
);
148 printk(KERN_WARNING
"%s: dev %s err=%d\n", __func__
,
149 mISDNDevName4ch(&l2
->ch
), err
);
155 l2up_create(struct layer2
*l2
, u_int prim
, int len
, void *arg
)
158 struct mISDNhead
*hh
;
163 skb
= mI_alloc_skb(len
, GFP_ATOMIC
);
166 hh
= mISDN_HEAD_P(skb
);
168 hh
->id
= (l2
->ch
.nr
<< 16) | l2
->ch
.addr
;
170 skb_put_data(skb
, arg
, len
);
171 err
= l2
->up
->send(l2
->up
, skb
);
173 printk(KERN_WARNING
"%s: dev %s err=%d\n", __func__
,
174 mISDNDevName4ch(&l2
->ch
), err
);
180 l2down_skb(struct layer2
*l2
, struct sk_buff
*skb
) {
183 ret
= l2
->ch
.recv(l2
->ch
.peer
, skb
);
184 if (ret
&& (*debug
& DEBUG_L2_RECV
))
185 printk(KERN_DEBUG
"l2down_skb: dev %s ret(%d)\n",
186 mISDNDevName4ch(&l2
->ch
), ret
);
191 l2down_raw(struct layer2
*l2
, struct sk_buff
*skb
)
193 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
195 if (hh
->prim
== PH_DATA_REQ
) {
196 if (test_and_set_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
197 skb_queue_tail(&l2
->down_queue
, skb
);
200 l2
->down_id
= mISDN_HEAD_ID(skb
);
202 return l2down_skb(l2
, skb
);
206 l2down(struct layer2
*l2
, u_int prim
, u_int id
, struct sk_buff
*skb
)
208 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
212 return l2down_raw(l2
, skb
);
216 l2down_create(struct layer2
*l2
, u_int prim
, u_int id
, int len
, void *arg
)
220 struct mISDNhead
*hh
;
222 skb
= mI_alloc_skb(len
, GFP_ATOMIC
);
225 hh
= mISDN_HEAD_P(skb
);
229 skb_put_data(skb
, arg
, len
);
230 err
= l2down_raw(l2
, skb
);
237 ph_data_confirm(struct layer2
*l2
, struct mISDNhead
*hh
, struct sk_buff
*skb
) {
238 struct sk_buff
*nskb
= skb
;
241 if (test_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
242 if (hh
->id
== l2
->down_id
) {
243 nskb
= skb_dequeue(&l2
->down_queue
);
245 l2
->down_id
= mISDN_HEAD_ID(nskb
);
246 if (l2down_skb(l2
, nskb
)) {
248 l2
->down_id
= MISDN_ID_NONE
;
251 l2
->down_id
= MISDN_ID_NONE
;
256 if (l2
->down_id
== MISDN_ID_NONE
) {
257 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
258 mISDN_FsmEvent(&l2
->l2m
, EV_L2_ACK_PULL
, NULL
);
262 if (!test_and_set_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
263 nskb
= skb_dequeue(&l2
->down_queue
);
265 l2
->down_id
= mISDN_HEAD_ID(nskb
);
266 if (l2down_skb(l2
, nskb
)) {
268 l2
->down_id
= MISDN_ID_NONE
;
269 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
272 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
278 l2_timeout(struct FsmInst
*fi
, int event
, void *arg
)
280 struct layer2
*l2
= fi
->userdata
;
282 struct mISDNhead
*hh
;
284 skb
= mI_alloc_skb(0, GFP_ATOMIC
);
286 printk(KERN_WARNING
"%s: L2(%d,%d) nr:%x timer %s no skb\n",
287 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
,
288 l2
->ch
.nr
, event
== EV_L2_T200
? "T200" : "T203");
291 hh
= mISDN_HEAD_P(skb
);
292 hh
->prim
= event
== EV_L2_T200
? DL_TIMER200_IND
: DL_TIMER203_IND
;
294 if (*debug
& DEBUG_TIMER
)
295 printk(KERN_DEBUG
"%s: L2(%d,%d) nr:%x timer %s expired\n",
296 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
,
297 l2
->ch
.nr
, event
== EV_L2_T200
? "T200" : "T203");
299 l2
->ch
.st
->own
.recv(&l2
->ch
.st
->own
, skb
);
303 l2mgr(struct layer2
*l2
, u_int prim
, void *arg
) {
306 printk(KERN_WARNING
"l2mgr: dev %s addr:%x prim %x %c\n",
307 mISDNDevName4ch(&l2
->ch
), l2
->id
, prim
, (char)c
);
308 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
309 !test_bit(FLG_FIXED_TEI
, &l2
->flag
)) {
315 l2_tei(l2
, prim
, (u_long
)arg
);
323 set_peer_busy(struct layer2
*l2
) {
324 test_and_set_bit(FLG_PEER_BUSY
, &l2
->flag
);
325 if (skb_queue_len(&l2
->i_queue
) || skb_queue_len(&l2
->ui_queue
))
326 test_and_set_bit(FLG_L2BLOCK
, &l2
->flag
);
330 clear_peer_busy(struct layer2
*l2
) {
331 if (test_and_clear_bit(FLG_PEER_BUSY
, &l2
->flag
))
332 test_and_clear_bit(FLG_L2BLOCK
, &l2
->flag
);
336 InitWin(struct layer2
*l2
)
340 for (i
= 0; i
< MAX_WINDOW
; i
++)
341 l2
->windowar
[i
] = NULL
;
345 freewin(struct layer2
*l2
)
349 for (i
= 0; i
< MAX_WINDOW
; i
++) {
350 if (l2
->windowar
[i
]) {
352 dev_kfree_skb(l2
->windowar
[i
]);
353 l2
->windowar
[i
] = NULL
;
360 ReleaseWin(struct layer2
*l2
)
362 int cnt
= freewin(l2
);
366 "isdnl2 freed %d skbuffs in release\n", cnt
);
370 cansend(struct layer2
*l2
)
374 if (test_bit(FLG_MOD128
, &l2
->flag
))
375 p1
= (l2
->vs
- l2
->va
) % 128;
377 p1
= (l2
->vs
- l2
->va
) % 8;
378 return (p1
< l2
->window
) && !test_bit(FLG_PEER_BUSY
, &l2
->flag
);
382 clear_exception(struct layer2
*l2
)
384 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
385 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
386 test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
);
391 sethdraddr(struct layer2
*l2
, u_char
*header
, int rsp
)
393 u_char
*ptr
= header
;
396 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
397 if (test_bit(FLG_LAPD_NET
, &l2
->flag
))
399 *ptr
++ = (l2
->sapi
<< 2) | (crbit
? 2 : 0);
400 *ptr
++ = (l2
->tei
<< 1) | 1;
403 if (test_bit(FLG_ORIG
, &l2
->flag
))
414 enqueue_super(struct layer2
*l2
, struct sk_buff
*skb
)
416 if (l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), skb
))
421 enqueue_ui(struct layer2
*l2
, struct sk_buff
*skb
)
424 l2_tei(l2
, MDL_STATUS_UI_IND
, 0);
425 if (l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), skb
))
432 return (data
[0] & 0xef) == UI
;
438 return (data
[0] & 0xef) == UA
;
444 return (data
[0] & 0xef) == DM
;
450 return (data
[0] & 0xef) == DISC
;
454 IsRR(u_char
*data
, struct layer2
*l2
)
456 if (test_bit(FLG_MOD128
, &l2
->flag
))
457 return data
[0] == RR
;
459 return (data
[0] & 0xf) == 1;
463 IsSFrame(u_char
*data
, struct layer2
*l2
)
465 register u_char d
= *data
;
467 if (!test_bit(FLG_MOD128
, &l2
->flag
))
469 return ((d
& 0xf3) == 1) && ((d
& 0x0c) != 0x0c);
473 IsSABME(u_char
*data
, struct layer2
*l2
)
475 u_char d
= data
[0] & ~0x10;
477 return test_bit(FLG_MOD128
, &l2
->flag
) ? d
== SABME
: d
== SABM
;
481 IsREJ(u_char
*data
, struct layer2
*l2
)
483 return test_bit(FLG_MOD128
, &l2
->flag
) ?
484 data
[0] == REJ
: (data
[0] & 0xf) == REJ
;
490 return (data
[0] & 0xef) == FRMR
;
494 IsRNR(u_char
*data
, struct layer2
*l2
)
496 return test_bit(FLG_MOD128
, &l2
->flag
) ?
497 data
[0] == RNR
: (data
[0] & 0xf) == RNR
;
501 iframe_error(struct layer2
*l2
, struct sk_buff
*skb
)
504 int rsp
= *skb
->data
& 0x2;
506 i
= l2addrsize(l2
) + (test_bit(FLG_MOD128
, &l2
->flag
) ? 2 : 1);
507 if (test_bit(FLG_ORIG
, &l2
->flag
))
513 if ((skb
->len
- i
) > l2
->maxlen
)
519 super_error(struct layer2
*l2
, struct sk_buff
*skb
)
521 if (skb
->len
!= l2addrsize(l2
) +
522 (test_bit(FLG_MOD128
, &l2
->flag
) ? 2 : 1))
528 unnum_error(struct layer2
*l2
, struct sk_buff
*skb
, int wantrsp
)
530 int rsp
= (*skb
->data
& 0x2) >> 1;
531 if (test_bit(FLG_ORIG
, &l2
->flag
))
535 if (skb
->len
!= l2addrsize(l2
) + 1)
541 UI_error(struct layer2
*l2
, struct sk_buff
*skb
)
543 int rsp
= *skb
->data
& 0x2;
544 if (test_bit(FLG_ORIG
, &l2
->flag
))
548 if (skb
->len
> l2
->maxlen
+ l2addrsize(l2
) + 1)
554 FRMR_error(struct layer2
*l2
, struct sk_buff
*skb
)
556 u_int headers
= l2addrsize(l2
) + 1;
557 u_char
*datap
= skb
->data
+ headers
;
558 int rsp
= *skb
->data
& 0x2;
560 if (test_bit(FLG_ORIG
, &l2
->flag
))
564 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
565 if (skb
->len
< headers
+ 5)
567 else if (*debug
& DEBUG_L2
)
569 "FRMR information %2x %2x %2x %2x %2x",
570 datap
[0], datap
[1], datap
[2], datap
[3], datap
[4]);
572 if (skb
->len
< headers
+ 3)
574 else if (*debug
& DEBUG_L2
)
576 "FRMR information %2x %2x %2x",
577 datap
[0], datap
[1], datap
[2]);
583 legalnr(struct layer2
*l2
, unsigned int nr
)
585 if (test_bit(FLG_MOD128
, &l2
->flag
))
586 return ((nr
- l2
->va
) % 128) <= ((l2
->vs
- l2
->va
) % 128);
588 return ((nr
- l2
->va
) % 8) <= ((l2
->vs
- l2
->va
) % 8);
592 setva(struct layer2
*l2
, unsigned int nr
)
596 while (l2
->va
!= nr
) {
598 if (test_bit(FLG_MOD128
, &l2
->flag
))
602 if (l2
->windowar
[l2
->sow
]) {
603 skb_trim(l2
->windowar
[l2
->sow
], 0);
604 skb_queue_tail(&l2
->tmp_queue
, l2
->windowar
[l2
->sow
]);
605 l2
->windowar
[l2
->sow
] = NULL
;
607 l2
->sow
= (l2
->sow
+ 1) % l2
->window
;
609 skb
= skb_dequeue(&l2
->tmp_queue
);
612 skb
= skb_dequeue(&l2
->tmp_queue
);
617 send_uframe(struct layer2
*l2
, struct sk_buff
*skb
, u_char cmd
, u_char cr
)
619 u_char tmp
[MAX_L2HEADER_LEN
];
622 i
= sethdraddr(l2
, tmp
, cr
);
627 skb
= mI_alloc_skb(i
, GFP_ATOMIC
);
629 printk(KERN_WARNING
"%s: can't alloc skbuff in %s\n",
630 mISDNDevName4ch(&l2
->ch
), __func__
);
634 skb_put_data(skb
, tmp
, i
);
635 enqueue_super(l2
, skb
);
640 get_PollFlag(struct layer2
*l2
, struct sk_buff
*skb
)
642 return skb
->data
[l2addrsize(l2
)] & 0x10;
646 get_PollFlagFree(struct layer2
*l2
, struct sk_buff
*skb
)
650 PF
= get_PollFlag(l2
, skb
);
656 start_t200(struct layer2
*l2
, int i
)
658 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, i
);
659 test_and_set_bit(FLG_T200_RUN
, &l2
->flag
);
663 restart_t200(struct layer2
*l2
, int i
)
665 mISDN_FsmRestartTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, i
);
666 test_and_set_bit(FLG_T200_RUN
, &l2
->flag
);
670 stop_t200(struct layer2
*l2
, int i
)
672 if (test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
))
673 mISDN_FsmDelTimer(&l2
->t200
, i
);
677 st5_dl_release_l2l3(struct layer2
*l2
)
681 if (test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
))
685 l2up_create(l2
, pr
, 0, NULL
);
689 lapb_dl_release_l2l3(struct layer2
*l2
, int f
)
691 if (test_bit(FLG_LAPB
, &l2
->flag
))
692 l2down_create(l2
, PH_DEACTIVATE_REQ
, l2_newid(l2
), 0, NULL
);
693 l2up_create(l2
, f
, 0, NULL
);
697 establishlink(struct FsmInst
*fi
)
699 struct layer2
*l2
= fi
->userdata
;
704 cmd
= (test_bit(FLG_MOD128
, &l2
->flag
) ? SABME
: SABM
) | 0x10;
705 send_uframe(l2
, NULL
, cmd
, CMD
);
706 mISDN_FsmDelTimer(&l2
->t203
, 1);
708 test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
);
710 mISDN_FsmChangeState(fi
, ST_L2_5
);
714 l2_mdl_error_ua(struct FsmInst
*fi
, int event
, void *arg
)
716 struct sk_buff
*skb
= arg
;
717 struct layer2
*l2
= fi
->userdata
;
719 if (get_PollFlagFree(l2
, skb
))
720 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'C');
722 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'D');
727 l2_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
729 struct sk_buff
*skb
= arg
;
730 struct layer2
*l2
= fi
->userdata
;
732 if (get_PollFlagFree(l2
, skb
))
733 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'B');
735 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'E');
737 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
742 l2_st8_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
744 struct sk_buff
*skb
= arg
;
745 struct layer2
*l2
= fi
->userdata
;
747 if (get_PollFlagFree(l2
, skb
))
748 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'B');
750 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'E');
752 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
756 l2_go_st3(struct FsmInst
*fi
, int event
, void *arg
)
758 dev_kfree_skb((struct sk_buff
*)arg
);
759 mISDN_FsmChangeState(fi
, ST_L2_3
);
763 l2_mdl_assign(struct FsmInst
*fi
, int event
, void *arg
)
765 struct layer2
*l2
= fi
->userdata
;
767 mISDN_FsmChangeState(fi
, ST_L2_3
);
768 dev_kfree_skb((struct sk_buff
*)arg
);
769 l2_tei(l2
, MDL_ASSIGN_IND
, 0);
773 l2_queue_ui_assign(struct FsmInst
*fi
, int event
, void *arg
)
775 struct layer2
*l2
= fi
->userdata
;
776 struct sk_buff
*skb
= arg
;
778 skb_queue_tail(&l2
->ui_queue
, skb
);
779 mISDN_FsmChangeState(fi
, ST_L2_2
);
780 l2_tei(l2
, MDL_ASSIGN_IND
, 0);
784 l2_queue_ui(struct FsmInst
*fi
, int event
, void *arg
)
786 struct layer2
*l2
= fi
->userdata
;
787 struct sk_buff
*skb
= arg
;
789 skb_queue_tail(&l2
->ui_queue
, skb
);
793 tx_ui(struct layer2
*l2
)
796 u_char header
[MAX_L2HEADER_LEN
];
799 i
= sethdraddr(l2
, header
, CMD
);
800 if (test_bit(FLG_LAPD_NET
, &l2
->flag
))
801 header
[1] = 0xff; /* tei 127 */
803 while ((skb
= skb_dequeue(&l2
->ui_queue
))) {
804 memcpy(skb_push(skb
, i
), header
, i
);
810 l2_send_ui(struct FsmInst
*fi
, int event
, void *arg
)
812 struct layer2
*l2
= fi
->userdata
;
813 struct sk_buff
*skb
= arg
;
815 skb_queue_tail(&l2
->ui_queue
, skb
);
820 l2_got_ui(struct FsmInst
*fi
, int event
, void *arg
)
822 struct layer2
*l2
= fi
->userdata
;
823 struct sk_buff
*skb
= arg
;
825 skb_pull(skb
, l2headersize(l2
, 1));
827 * in states 1-3 for broadcast
831 l2_tei(l2
, MDL_STATUS_UI_IND
, 0);
832 l2up(l2
, DL_UNITDATA_IND
, skb
);
836 l2_establish(struct FsmInst
*fi
, int event
, void *arg
)
838 struct sk_buff
*skb
= arg
;
839 struct layer2
*l2
= fi
->userdata
;
842 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
847 l2_discard_i_setl3(struct FsmInst
*fi
, int event
, void *arg
)
849 struct sk_buff
*skb
= arg
;
850 struct layer2
*l2
= fi
->userdata
;
852 skb_queue_purge(&l2
->i_queue
);
853 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
854 test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
);
859 l2_l3_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
861 struct sk_buff
*skb
= arg
;
862 struct layer2
*l2
= fi
->userdata
;
864 skb_queue_purge(&l2
->i_queue
);
866 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
871 l2_release(struct FsmInst
*fi
, int event
, void *arg
)
873 struct layer2
*l2
= fi
->userdata
;
874 struct sk_buff
*skb
= arg
;
877 l2up(l2
, DL_RELEASE_CNF
, skb
);
881 l2_pend_rel(struct FsmInst
*fi
, int event
, void *arg
)
883 struct sk_buff
*skb
= arg
;
884 struct layer2
*l2
= fi
->userdata
;
886 test_and_set_bit(FLG_PEND_REL
, &l2
->flag
);
891 l2_disconnect(struct FsmInst
*fi
, int event
, void *arg
)
893 struct layer2
*l2
= fi
->userdata
;
894 struct sk_buff
*skb
= arg
;
896 skb_queue_purge(&l2
->i_queue
);
898 mISDN_FsmChangeState(fi
, ST_L2_6
);
900 send_uframe(l2
, NULL
, DISC
| 0x10, CMD
);
901 mISDN_FsmDelTimer(&l2
->t203
, 1);
907 l2_start_multi(struct FsmInst
*fi
, int event
, void *arg
)
909 struct layer2
*l2
= fi
->userdata
;
910 struct sk_buff
*skb
= arg
;
917 send_uframe(l2
, NULL
, UA
| get_PollFlag(l2
, skb
), RSP
);
918 mISDN_FsmChangeState(fi
, ST_L2_7
);
919 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 3);
921 l2up(l2
, DL_ESTABLISH_IND
, skb
);
923 l2_tei(l2
, MDL_STATUS_UP_IND
, 0);
927 l2_send_UA(struct FsmInst
*fi
, int event
, void *arg
)
929 struct layer2
*l2
= fi
->userdata
;
930 struct sk_buff
*skb
= arg
;
932 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
936 l2_send_DM(struct FsmInst
*fi
, int event
, void *arg
)
938 struct layer2
*l2
= fi
->userdata
;
939 struct sk_buff
*skb
= arg
;
941 send_uframe(l2
, skb
, DM
| get_PollFlag(l2
, skb
), RSP
);
945 l2_restart_multi(struct FsmInst
*fi
, int event
, void *arg
)
947 struct layer2
*l2
= fi
->userdata
;
948 struct sk_buff
*skb
= arg
;
951 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
953 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'F');
955 if (l2
->vs
!= l2
->va
) {
956 skb_queue_purge(&l2
->i_queue
);
965 mISDN_FsmChangeState(fi
, ST_L2_7
);
967 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 3);
970 l2up_create(l2
, DL_ESTABLISH_IND
, 0, NULL
);
971 /* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
972 * MGR_SHORTSTATUS | INDICATION, SSTATUS_L2_ESTABLISHED,
975 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
976 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
980 l2_stop_multi(struct FsmInst
*fi
, int event
, void *arg
)
982 struct layer2
*l2
= fi
->userdata
;
983 struct sk_buff
*skb
= arg
;
985 mISDN_FsmChangeState(fi
, ST_L2_4
);
986 mISDN_FsmDelTimer(&l2
->t203
, 3);
989 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
990 skb_queue_purge(&l2
->i_queue
);
992 lapb_dl_release_l2l3(l2
, DL_RELEASE_IND
);
994 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
998 l2_connected(struct FsmInst
*fi
, int event
, void *arg
)
1000 struct layer2
*l2
= fi
->userdata
;
1001 struct sk_buff
*skb
= arg
;
1004 if (!get_PollFlag(l2
, skb
)) {
1005 l2_mdl_error_ua(fi
, event
, arg
);
1009 if (test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
))
1010 l2_disconnect(fi
, event
, NULL
);
1011 if (test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
)) {
1012 pr
= DL_ESTABLISH_CNF
;
1013 } else if (l2
->vs
!= l2
->va
) {
1014 skb_queue_purge(&l2
->i_queue
);
1015 pr
= DL_ESTABLISH_IND
;
1022 mISDN_FsmChangeState(fi
, ST_L2_7
);
1023 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 4);
1025 l2up_create(l2
, pr
, 0, NULL
);
1027 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
1028 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1031 l2_tei(l2
, MDL_STATUS_UP_IND
, 0);
1035 l2_released(struct FsmInst
*fi
, int event
, void *arg
)
1037 struct layer2
*l2
= fi
->userdata
;
1038 struct sk_buff
*skb
= arg
;
1040 if (!get_PollFlag(l2
, skb
)) {
1041 l2_mdl_error_ua(fi
, event
, arg
);
1046 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1047 mISDN_FsmChangeState(fi
, ST_L2_4
);
1049 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1053 l2_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
1055 struct layer2
*l2
= fi
->userdata
;
1056 struct sk_buff
*skb
= arg
;
1058 if (!get_PollFlagFree(l2
, skb
)) {
1060 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
1065 l2_st5_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
1067 struct layer2
*l2
= fi
->userdata
;
1068 struct sk_buff
*skb
= arg
;
1070 if (get_PollFlagFree(l2
, skb
)) {
1072 if (!test_bit(FLG_L3_INIT
, &l2
->flag
))
1073 skb_queue_purge(&l2
->i_queue
);
1074 if (test_bit(FLG_LAPB
, &l2
->flag
))
1075 l2down_create(l2
, PH_DEACTIVATE_REQ
,
1076 l2_newid(l2
), 0, NULL
);
1077 st5_dl_release_l2l3(l2
);
1078 mISDN_FsmChangeState(fi
, ST_L2_4
);
1080 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1085 l2_st6_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
1087 struct layer2
*l2
= fi
->userdata
;
1088 struct sk_buff
*skb
= arg
;
1090 if (get_PollFlagFree(l2
, skb
)) {
1092 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1093 mISDN_FsmChangeState(fi
, ST_L2_4
);
1095 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1100 enquiry_cr(struct layer2
*l2
, u_char typ
, u_char cr
, u_char pf
)
1102 struct sk_buff
*skb
;
1103 u_char tmp
[MAX_L2HEADER_LEN
];
1106 i
= sethdraddr(l2
, tmp
, cr
);
1107 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1109 tmp
[i
++] = (l2
->vr
<< 1) | (pf
? 1 : 0);
1111 tmp
[i
++] = (l2
->vr
<< 5) | typ
| (pf
? 0x10 : 0);
1112 skb
= mI_alloc_skb(i
, GFP_ATOMIC
);
1114 printk(KERN_WARNING
"%s: isdnl2 can't alloc sbbuff in %s\n",
1115 mISDNDevName4ch(&l2
->ch
), __func__
);
1118 skb_put_data(skb
, tmp
, i
);
1119 enqueue_super(l2
, skb
);
1123 enquiry_response(struct layer2
*l2
)
1125 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
))
1126 enquiry_cr(l2
, RNR
, RSP
, 1);
1128 enquiry_cr(l2
, RR
, RSP
, 1);
1129 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1133 transmit_enquiry(struct layer2
*l2
)
1135 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
))
1136 enquiry_cr(l2
, RNR
, CMD
, 1);
1138 enquiry_cr(l2
, RR
, CMD
, 1);
1139 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1145 nrerrorrecovery(struct FsmInst
*fi
)
1147 struct layer2
*l2
= fi
->userdata
;
1149 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'J');
1151 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1155 invoke_retransmission(struct layer2
*l2
, unsigned int nr
)
1160 while (l2
->vs
!= nr
) {
1162 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1164 p1
= (l2
->vs
- l2
->va
) % 128;
1167 p1
= (l2
->vs
- l2
->va
) % 8;
1169 p1
= (p1
+ l2
->sow
) % l2
->window
;
1170 if (l2
->windowar
[p1
])
1171 skb_queue_head(&l2
->i_queue
, l2
->windowar
[p1
]);
1174 "%s: windowar[%d] is NULL\n",
1175 mISDNDevName4ch(&l2
->ch
), p1
);
1176 l2
->windowar
[p1
] = NULL
;
1178 mISDN_FsmEvent(&l2
->l2m
, EV_L2_ACK_PULL
, NULL
);
1183 l2_st7_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1185 struct layer2
*l2
= fi
->userdata
;
1186 struct sk_buff
*skb
= arg
;
1187 int PollFlag
, rsp
, typ
= RR
;
1190 rsp
= *skb
->data
& 0x2;
1191 if (test_bit(FLG_ORIG
, &l2
->flag
))
1194 skb_pull(skb
, l2addrsize(l2
));
1195 if (IsRNR(skb
->data
, l2
)) {
1199 clear_peer_busy(l2
);
1200 if (IsREJ(skb
->data
, l2
))
1203 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1204 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1205 nr
= skb
->data
[1] >> 1;
1207 PollFlag
= (skb
->data
[0] & 0x10);
1208 nr
= (skb
->data
[0] >> 5) & 0x7;
1214 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'A');
1216 enquiry_response(l2
);
1218 if (legalnr(l2
, nr
)) {
1221 invoke_retransmission(l2
, nr
);
1223 if (mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
,
1224 EV_L2_T203
, NULL
, 6))
1225 l2m_debug(&l2
->l2m
, "Restart T203 ST7 REJ");
1226 } else if ((nr
== l2
->vs
) && (typ
== RR
)) {
1229 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
,
1230 EV_L2_T203
, NULL
, 7);
1231 } else if ((l2
->va
!= nr
) || (typ
== RNR
)) {
1234 mISDN_FsmDelTimer(&l2
->t203
, 9);
1235 restart_t200(l2
, 12);
1237 if (skb_queue_len(&l2
->i_queue
) && (typ
== RR
))
1238 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1240 nrerrorrecovery(fi
);
1244 l2_feed_i_if_reest(struct FsmInst
*fi
, int event
, void *arg
)
1246 struct layer2
*l2
= fi
->userdata
;
1247 struct sk_buff
*skb
= arg
;
1249 if (!test_bit(FLG_L3_INIT
, &l2
->flag
))
1250 skb_queue_tail(&l2
->i_queue
, skb
);
1256 l2_feed_i_pull(struct FsmInst
*fi
, int event
, void *arg
)
1258 struct layer2
*l2
= fi
->userdata
;
1259 struct sk_buff
*skb
= arg
;
1261 skb_queue_tail(&l2
->i_queue
, skb
);
1262 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1266 l2_feed_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1268 struct layer2
*l2
= fi
->userdata
;
1269 struct sk_buff
*skb
= arg
;
1271 skb_queue_tail(&l2
->i_queue
, skb
);
1275 l2_got_iframe(struct FsmInst
*fi
, int event
, void *arg
)
1277 struct layer2
*l2
= fi
->userdata
;
1278 struct sk_buff
*skb
= arg
;
1283 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1284 PollFlag
= ((skb
->data
[i
+ 1] & 0x1) == 0x1);
1285 ns
= skb
->data
[i
] >> 1;
1286 nr
= (skb
->data
[i
+ 1] >> 1) & 0x7f;
1288 PollFlag
= (skb
->data
[i
] & 0x10);
1289 ns
= (skb
->data
[i
] >> 1) & 0x7;
1290 nr
= (skb
->data
[i
] >> 5) & 0x7;
1292 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1295 enquiry_response(l2
);
1299 if (test_bit(FLG_MOD128
, &l2
->flag
))
1303 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
1305 enquiry_response(l2
);
1307 test_and_set_bit(FLG_ACK_PEND
, &l2
->flag
);
1308 skb_pull(skb
, l2headersize(l2
, 0));
1309 l2up(l2
, DL_DATA_IND
, skb
);
1313 if (test_and_set_bit(FLG_REJEXC
, &l2
->flag
)) {
1315 enquiry_response(l2
);
1317 enquiry_cr(l2
, REJ
, RSP
, PollFlag
);
1318 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1322 if (legalnr(l2
, nr
)) {
1323 if (!test_bit(FLG_PEER_BUSY
, &l2
->flag
) &&
1324 (fi
->state
== ST_L2_7
)) {
1327 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
,
1328 EV_L2_T203
, NULL
, 7);
1329 } else if (nr
!= l2
->va
)
1330 restart_t200(l2
, 14);
1334 nrerrorrecovery(fi
);
1337 if (skb_queue_len(&l2
->i_queue
) && (fi
->state
== ST_L2_7
))
1338 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1339 if (test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
))
1340 enquiry_cr(l2
, RR
, RSP
, 0);
1344 l2_got_tei(struct FsmInst
*fi
, int event
, void *arg
)
1346 struct layer2
*l2
= fi
->userdata
;
1349 l2
->tei
= (signed char)(long)arg
;
1350 set_channel_address(&l2
->ch
, l2
->sapi
, l2
->tei
);
1351 info
= DL_INFO_L2_CONNECT
;
1352 l2up_create(l2
, DL_INFORMATION_IND
, sizeof(info
), &info
);
1353 if (fi
->state
== ST_L2_3
) {
1355 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
1357 mISDN_FsmChangeState(fi
, ST_L2_4
);
1358 if (skb_queue_len(&l2
->ui_queue
))
1363 l2_st5_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1365 struct layer2
*l2
= fi
->userdata
;
1367 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1368 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1369 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1370 } else if (l2
->rc
== l2
->N200
) {
1371 mISDN_FsmChangeState(fi
, ST_L2_4
);
1372 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1373 skb_queue_purge(&l2
->i_queue
);
1374 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'G');
1375 if (test_bit(FLG_LAPB
, &l2
->flag
))
1376 l2down_create(l2
, PH_DEACTIVATE_REQ
,
1377 l2_newid(l2
), 0, NULL
);
1378 st5_dl_release_l2l3(l2
);
1380 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1383 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1384 send_uframe(l2
, NULL
, (test_bit(FLG_MOD128
, &l2
->flag
) ?
1385 SABME
: SABM
) | 0x10, CMD
);
1390 l2_st6_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1392 struct layer2
*l2
= fi
->userdata
;
1394 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1395 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1396 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1397 } else if (l2
->rc
== l2
->N200
) {
1398 mISDN_FsmChangeState(fi
, ST_L2_4
);
1399 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1400 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'H');
1401 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1403 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1406 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
,
1408 send_uframe(l2
, NULL
, DISC
| 0x10, CMD
);
1413 l2_st7_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1415 struct layer2
*l2
= fi
->userdata
;
1417 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1418 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1419 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1422 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1424 mISDN_FsmChangeState(fi
, ST_L2_8
);
1425 transmit_enquiry(l2
);
1430 l2_st8_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1432 struct layer2
*l2
= fi
->userdata
;
1434 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1435 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1436 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1439 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1440 if (l2
->rc
== l2
->N200
) {
1441 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'I');
1443 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1445 transmit_enquiry(l2
);
1451 l2_st7_tout_203(struct FsmInst
*fi
, int event
, void *arg
)
1453 struct layer2
*l2
= fi
->userdata
;
1455 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1456 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1457 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 9);
1460 mISDN_FsmChangeState(fi
, ST_L2_8
);
1461 transmit_enquiry(l2
);
1466 l2_pull_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1468 struct layer2
*l2
= fi
->userdata
;
1469 struct sk_buff
*skb
, *nskb
;
1470 u_char header
[MAX_L2HEADER_LEN
];
1476 skb
= skb_dequeue(&l2
->i_queue
);
1479 i
= sethdraddr(l2
, header
, CMD
);
1480 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1481 header
[i
++] = l2
->vs
<< 1;
1482 header
[i
++] = l2
->vr
<< 1;
1484 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1485 nskb
= skb_realloc_headroom(skb
, i
);
1487 printk(KERN_WARNING
"%s: no headroom(%d) copy for IFrame\n",
1488 mISDNDevName4ch(&l2
->ch
), i
);
1489 skb_queue_head(&l2
->i_queue
, skb
);
1492 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1493 p1
= (l2
->vs
- l2
->va
) % 128;
1494 l2
->vs
= (l2
->vs
+ 1) % 128;
1496 p1
= (l2
->vs
- l2
->va
) % 8;
1497 l2
->vs
= (l2
->vs
+ 1) % 8;
1499 p1
= (p1
+ l2
->sow
) % l2
->window
;
1500 if (l2
->windowar
[p1
]) {
1501 printk(KERN_WARNING
"%s: l2 try overwrite ack queue entry %d\n",
1502 mISDNDevName4ch(&l2
->ch
), p1
);
1503 dev_kfree_skb(l2
->windowar
[p1
]);
1505 l2
->windowar
[p1
] = skb
;
1506 memcpy(skb_push(nskb
, i
), header
, i
);
1507 l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), nskb
);
1508 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1509 if (!test_and_set_bit(FLG_T200_RUN
, &l2
->flag
)) {
1510 mISDN_FsmDelTimer(&l2
->t203
, 13);
1511 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 11);
1516 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1518 struct layer2
*l2
= fi
->userdata
;
1519 struct sk_buff
*skb
= arg
;
1520 int PollFlag
, rsp
, rnr
= 0;
1523 rsp
= *skb
->data
& 0x2;
1524 if (test_bit(FLG_ORIG
, &l2
->flag
))
1527 skb_pull(skb
, l2addrsize(l2
));
1529 if (IsRNR(skb
->data
, l2
)) {
1533 clear_peer_busy(l2
);
1535 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1536 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1537 nr
= skb
->data
[1] >> 1;
1539 PollFlag
= (skb
->data
[0] & 0x10);
1540 nr
= (skb
->data
[0] >> 5) & 0x7;
1543 if (rsp
&& PollFlag
) {
1544 if (legalnr(l2
, nr
)) {
1546 restart_t200(l2
, 15);
1549 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
,
1550 EV_L2_T203
, NULL
, 5);
1553 invoke_retransmission(l2
, nr
);
1554 mISDN_FsmChangeState(fi
, ST_L2_7
);
1555 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
1556 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1558 nrerrorrecovery(fi
);
1560 if (!rsp
&& PollFlag
)
1561 enquiry_response(l2
);
1562 if (legalnr(l2
, nr
))
1565 nrerrorrecovery(fi
);
1570 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1572 struct layer2
*l2
= fi
->userdata
;
1573 struct sk_buff
*skb
= arg
;
1575 skb_pull(skb
, l2addrsize(l2
) + 1);
1577 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1578 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1579 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'K');
1581 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1587 l2_st24_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1589 struct layer2
*l2
= fi
->userdata
;
1591 skb_queue_purge(&l2
->ui_queue
);
1592 l2
->tei
= GROUP_TEI
;
1593 mISDN_FsmChangeState(fi
, ST_L2_1
);
1597 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1599 struct layer2
*l2
= fi
->userdata
;
1601 skb_queue_purge(&l2
->ui_queue
);
1602 l2
->tei
= GROUP_TEI
;
1603 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1604 mISDN_FsmChangeState(fi
, ST_L2_1
);
1608 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1610 struct layer2
*l2
= fi
->userdata
;
1612 skb_queue_purge(&l2
->i_queue
);
1613 skb_queue_purge(&l2
->ui_queue
);
1615 l2
->tei
= GROUP_TEI
;
1617 st5_dl_release_l2l3(l2
);
1618 mISDN_FsmChangeState(fi
, ST_L2_1
);
1622 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1624 struct layer2
*l2
= fi
->userdata
;
1626 skb_queue_purge(&l2
->ui_queue
);
1627 l2
->tei
= GROUP_TEI
;
1629 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1630 mISDN_FsmChangeState(fi
, ST_L2_1
);
1634 l2_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1636 struct layer2
*l2
= fi
->userdata
;
1638 skb_queue_purge(&l2
->i_queue
);
1639 skb_queue_purge(&l2
->ui_queue
);
1641 l2
->tei
= GROUP_TEI
;
1643 mISDN_FsmDelTimer(&l2
->t203
, 19);
1644 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1645 /* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
1646 * MGR_SHORTSTATUS_IND, SSTATUS_L2_RELEASED,
1649 mISDN_FsmChangeState(fi
, ST_L2_1
);
1653 l2_st14_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1655 struct layer2
*l2
= fi
->userdata
;
1656 struct sk_buff
*skb
= arg
;
1658 skb_queue_purge(&l2
->i_queue
);
1659 skb_queue_purge(&l2
->ui_queue
);
1660 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1661 l2up(l2
, DL_RELEASE_IND
, skb
);
1667 l2_st5_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1669 struct layer2
*l2
= fi
->userdata
;
1670 struct sk_buff
*skb
= arg
;
1672 skb_queue_purge(&l2
->i_queue
);
1673 skb_queue_purge(&l2
->ui_queue
);
1676 st5_dl_release_l2l3(l2
);
1677 mISDN_FsmChangeState(fi
, ST_L2_4
);
1679 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1684 l2_st6_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1686 struct layer2
*l2
= fi
->userdata
;
1687 struct sk_buff
*skb
= arg
;
1689 skb_queue_purge(&l2
->ui_queue
);
1691 l2up(l2
, DL_RELEASE_CNF
, skb
);
1692 mISDN_FsmChangeState(fi
, ST_L2_4
);
1694 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1698 l2_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1700 struct layer2
*l2
= fi
->userdata
;
1701 struct sk_buff
*skb
= arg
;
1703 skb_queue_purge(&l2
->i_queue
);
1704 skb_queue_purge(&l2
->ui_queue
);
1707 mISDN_FsmDelTimer(&l2
->t203
, 19);
1708 l2up(l2
, DL_RELEASE_IND
, skb
);
1709 mISDN_FsmChangeState(fi
, ST_L2_4
);
1711 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1715 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1717 struct layer2
*l2
= fi
->userdata
;
1718 struct sk_buff
*skb
= arg
;
1720 if (!test_and_set_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1721 enquiry_cr(l2
, RNR
, RSP
, 0);
1722 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1728 l2_clear_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1730 struct layer2
*l2
= fi
->userdata
;
1731 struct sk_buff
*skb
= arg
;
1733 if (!test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1734 enquiry_cr(l2
, RR
, RSP
, 0);
1735 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1741 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1743 struct layer2
*l2
= fi
->userdata
;
1745 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1749 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1751 struct layer2
*l2
= fi
->userdata
;
1753 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1755 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1758 static struct FsmNode L2FnList
[] =
1760 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1761 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1762 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1763 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1764 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1765 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1766 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1767 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1768 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1769 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1770 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1771 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1772 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1773 {ST_L2_1
, EV_L2_DL_UNITDATA
, l2_queue_ui_assign
},
1774 {ST_L2_2
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1775 {ST_L2_3
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1776 {ST_L2_4
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1777 {ST_L2_5
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1778 {ST_L2_6
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1779 {ST_L2_7
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1780 {ST_L2_8
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1781 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1782 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1783 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1784 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1785 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1786 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1787 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1788 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1789 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1790 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1791 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1792 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1793 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1794 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1795 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1796 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1797 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1798 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1799 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1800 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1801 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1802 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1803 {ST_L2_6
, EV_L2_UA
, l2_released
},
1804 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1805 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1806 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1807 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1808 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1809 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1810 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1811 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1812 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1813 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1814 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1815 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1816 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1817 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1818 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1819 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1820 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1821 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1822 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1823 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1824 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1825 {ST_L2_5
, EV_L2_T200
, l2_timeout
},
1826 {ST_L2_6
, EV_L2_T200
, l2_timeout
},
1827 {ST_L2_7
, EV_L2_T200
, l2_timeout
},
1828 {ST_L2_8
, EV_L2_T200
, l2_timeout
},
1829 {ST_L2_7
, EV_L2_T203
, l2_timeout
},
1830 {ST_L2_5
, EV_L2_T200I
, l2_st5_tout_200
},
1831 {ST_L2_6
, EV_L2_T200I
, l2_st6_tout_200
},
1832 {ST_L2_7
, EV_L2_T200I
, l2_st7_tout_200
},
1833 {ST_L2_8
, EV_L2_T200I
, l2_st8_tout_200
},
1834 {ST_L2_7
, EV_L2_T203I
, l2_st7_tout_203
},
1835 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1836 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1837 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1838 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1839 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1840 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1841 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1842 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1843 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1844 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1845 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1846 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1847 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1848 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1849 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistent_da
},
1850 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistent_da
},
1851 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1852 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1856 ph_data_indication(struct layer2
*l2
, struct mISDNhead
*hh
, struct sk_buff
*skb
)
1858 u_char
*datap
= skb
->data
;
1865 if (skb
->len
<= l
) {
1866 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
1869 if (test_bit(FLG_LAPD
, &l2
->flag
)) { /* Maybe not needed */
1872 if ((psapi
& 1) || !(ptei
& 1)) {
1874 "%s l2 D-channel frame wrong EA0/EA1\n",
1875 mISDNDevName4ch(&l2
->ch
));
1880 if (psapi
!= l2
->sapi
) {
1881 /* not our business */
1882 if (*debug
& DEBUG_L2
)
1883 printk(KERN_DEBUG
"%s: sapi %d/%d mismatch\n",
1884 mISDNDevName4ch(&l2
->ch
), psapi
,
1889 if ((ptei
!= l2
->tei
) && (ptei
!= GROUP_TEI
)) {
1890 /* not our business */
1891 if (*debug
& DEBUG_L2
)
1892 printk(KERN_DEBUG
"%s: tei %d/%d mismatch\n",
1893 mISDNDevName4ch(&l2
->ch
), ptei
, l2
->tei
);
1899 if (!(*datap
& 1)) { /* I-Frame */
1900 c
= iframe_error(l2
, skb
);
1902 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_I
, skb
);
1903 } else if (IsSFrame(datap
, l2
)) { /* S-Frame */
1904 c
= super_error(l2
, skb
);
1906 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SUPER
, skb
);
1907 } else if (IsUI(datap
)) {
1908 c
= UI_error(l2
, skb
);
1910 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UI
, skb
);
1911 } else if (IsSABME(datap
, l2
)) {
1912 c
= unnum_error(l2
, skb
, CMD
);
1914 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SABME
, skb
);
1915 } else if (IsUA(datap
)) {
1916 c
= unnum_error(l2
, skb
, RSP
);
1918 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UA
, skb
);
1919 } else if (IsDISC(datap
)) {
1920 c
= unnum_error(l2
, skb
, CMD
);
1922 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DISC
, skb
);
1923 } else if (IsDM(datap
)) {
1924 c
= unnum_error(l2
, skb
, RSP
);
1926 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DM
, skb
);
1927 } else if (IsFRMR(datap
)) {
1928 c
= FRMR_error(l2
, skb
);
1930 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRMR
, skb
);
1934 printk(KERN_WARNING
"%s:l2 D-channel frame error %c\n",
1935 mISDNDevName4ch(&l2
->ch
), c
);
1936 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1942 l2_send(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1944 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
1945 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1948 if (*debug
& DEBUG_L2_RECV
)
1949 printk(KERN_DEBUG
"%s: %s prim(%x) id(%x) sapi(%d) tei(%d)\n",
1950 __func__
, mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
,
1952 if (hh
->prim
== DL_INTERN_MSG
) {
1953 struct mISDNhead
*chh
= hh
+ 1; /* saved copy */
1956 if (*debug
& DEBUG_L2_RECV
)
1957 printk(KERN_DEBUG
"%s: prim(%x) id(%x) internal msg\n",
1958 mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
);
1962 ret
= ph_data_indication(l2
, hh
, skb
);
1965 ret
= ph_data_confirm(l2
, hh
, skb
);
1967 case PH_ACTIVATE_IND
:
1968 test_and_set_bit(FLG_L1_ACTIV
, &l2
->flag
);
1969 l2up_create(l2
, MPH_ACTIVATE_IND
, 0, NULL
);
1970 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1971 ret
= mISDN_FsmEvent(&l2
->l2m
,
1972 EV_L2_DL_ESTABLISH_REQ
, skb
);
1974 case PH_DEACTIVATE_IND
:
1975 test_and_clear_bit(FLG_L1_ACTIV
, &l2
->flag
);
1976 l2up_create(l2
, MPH_DEACTIVATE_IND
, 0, NULL
);
1977 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L1_DEACTIVATE
, skb
);
1979 case MPH_INFORMATION_IND
:
1982 ret
= l2
->up
->send(l2
->up
, skb
);
1985 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_DATA
, skb
);
1987 case DL_UNITDATA_REQ
:
1988 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_UNITDATA
, skb
);
1990 case DL_ESTABLISH_REQ
:
1991 if (test_bit(FLG_LAPB
, &l2
->flag
))
1992 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
1993 if (test_bit(FLG_L1_ACTIV
, &l2
->flag
)) {
1994 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
1995 test_bit(FLG_ORIG
, &l2
->flag
))
1996 ret
= mISDN_FsmEvent(&l2
->l2m
,
1997 EV_L2_DL_ESTABLISH_REQ
, skb
);
1999 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
2000 test_bit(FLG_ORIG
, &l2
->flag
)) {
2001 test_and_set_bit(FLG_ESTAB_PEND
,
2004 ret
= l2down(l2
, PH_ACTIVATE_REQ
, l2_newid(l2
),
2008 case DL_RELEASE_REQ
:
2009 if (test_bit(FLG_LAPB
, &l2
->flag
))
2010 l2down_create(l2
, PH_DEACTIVATE_REQ
,
2011 l2_newid(l2
), 0, NULL
);
2012 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_RELEASE_REQ
,
2015 case DL_TIMER200_IND
:
2016 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T200I
, NULL
);
2018 case DL_TIMER203_IND
:
2019 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T203I
, NULL
);
2022 if (*debug
& DEBUG_L2
)
2023 l2m_debug(&l2
->l2m
, "l2 unknown pr %04x",
2034 tei_l2(struct layer2
*l2
, u_int cmd
, u_long arg
)
2038 if (*debug
& DEBUG_L2_TEI
)
2039 printk(KERN_DEBUG
"%s: cmd(%x) in %s\n",
2040 mISDNDevName4ch(&l2
->ch
), cmd
, __func__
);
2042 case (MDL_ASSIGN_REQ
):
2043 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ASSIGN
, (void *)arg
);
2045 case (MDL_REMOVE_REQ
):
2046 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_REMOVE
, NULL
);
2048 case (MDL_ERROR_IND
):
2049 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2051 case (MDL_ERROR_RSP
):
2052 /* ETS 300-125 5.3.2.1 Test: TC13010 */
2053 printk(KERN_NOTICE
"%s: MDL_ERROR|REQ (tei_l2)\n",
2054 mISDNDevName4ch(&l2
->ch
));
2055 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2062 release_l2(struct layer2
*l2
)
2064 mISDN_FsmDelTimer(&l2
->t200
, 21);
2065 mISDN_FsmDelTimer(&l2
->t203
, 16);
2066 skb_queue_purge(&l2
->i_queue
);
2067 skb_queue_purge(&l2
->ui_queue
);
2068 skb_queue_purge(&l2
->down_queue
);
2070 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2073 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
,
2074 CLOSE_CHANNEL
, NULL
);
2080 l2_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
2082 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
2085 if (*debug
& DEBUG_L2_CTRL
)
2086 printk(KERN_DEBUG
"%s: %s cmd(%x)\n",
2087 mISDNDevName4ch(ch
), __func__
, cmd
);
2091 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2092 set_channel_address(&l2
->ch
, l2
->sapi
, l2
->tei
);
2093 info
= DL_INFO_L2_CONNECT
;
2094 l2up_create(l2
, DL_INFORMATION_IND
,
2095 sizeof(info
), &info
);
2100 l2
->ch
.peer
->ctrl(l2
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
2108 create_l2(struct mISDNchannel
*ch
, u_int protocol
, u_long options
, int tei
,
2112 struct channel_req rq
;
2114 l2
= kzalloc(sizeof(struct layer2
), GFP_KERNEL
);
2116 printk(KERN_ERR
"kzalloc layer2 failed\n");
2120 l2
->down_id
= MISDN_ID_NONE
;
2123 l2
->ch
.send
= l2_send
;
2124 l2
->ch
.ctrl
= l2_ctrl
;
2126 case ISDN_P_LAPD_NT
:
2127 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2128 test_and_set_bit(FLG_LAPD_NET
, &l2
->flag
);
2129 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2131 l2
->maxlen
= MAX_DFRAME_LEN
;
2132 if (test_bit(OPTION_L2_PMX
, &options
))
2136 if (test_bit(OPTION_L2_PTP
, &options
))
2137 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2138 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2139 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2144 if (test_bit(OPTION_L2_PMX
, &options
))
2145 rq
.protocol
= ISDN_P_NT_E1
;
2147 rq
.protocol
= ISDN_P_NT_S0
;
2149 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2151 case ISDN_P_LAPD_TE
:
2152 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2153 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2154 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
2156 l2
->maxlen
= MAX_DFRAME_LEN
;
2157 if (test_bit(OPTION_L2_PMX
, &options
))
2161 if (test_bit(OPTION_L2_PTP
, &options
))
2162 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2163 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2164 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2169 if (test_bit(OPTION_L2_PMX
, &options
))
2170 rq
.protocol
= ISDN_P_TE_E1
;
2172 rq
.protocol
= ISDN_P_TE_S0
;
2174 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2176 case ISDN_P_B_X75SLP
:
2177 test_and_set_bit(FLG_LAPB
, &l2
->flag
);
2179 l2
->maxlen
= MAX_DATA_SIZE
;
2187 printk(KERN_ERR
"layer2 create failed prt %x\n",
2192 skb_queue_head_init(&l2
->i_queue
);
2193 skb_queue_head_init(&l2
->ui_queue
);
2194 skb_queue_head_init(&l2
->down_queue
);
2195 skb_queue_head_init(&l2
->tmp_queue
);
2197 l2
->l2m
.fsm
= &l2fsm
;
2198 if (test_bit(FLG_LAPB
, &l2
->flag
) ||
2199 test_bit(FLG_FIXED_TEI
, &l2
->flag
) ||
2200 test_bit(FLG_LAPD_NET
, &l2
->flag
))
2201 l2
->l2m
.state
= ST_L2_4
;
2203 l2
->l2m
.state
= ST_L2_1
;
2204 l2
->l2m
.debug
= *debug
;
2205 l2
->l2m
.userdata
= l2
;
2206 l2
->l2m
.userint
= 0;
2207 l2
->l2m
.printdebug
= l2m_debug
;
2209 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t200
);
2210 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t203
);
2215 x75create(struct channel_req
*crq
)
2219 if (crq
->protocol
!= ISDN_P_B_X75SLP
)
2220 return -EPROTONOSUPPORT
;
2221 l2
= create_l2(crq
->ch
, crq
->protocol
, 0, 0, 0);
2225 crq
->protocol
= ISDN_P_B_HDLC
;
2229 static struct Bprotocol X75SLP
= {
2230 .Bprotocols
= (1 << (ISDN_P_B_X75SLP
& ISDN_P_B_MASK
)),
2236 Isdnl2_Init(u_int
*deb
)
2240 mISDN_register_Bprotocol(&X75SLP
);
2241 l2fsm
.state_count
= L2_STATE_COUNT
;
2242 l2fsm
.event_count
= L2_EVENT_COUNT
;
2243 l2fsm
.strEvent
= strL2Event
;
2244 l2fsm
.strState
= strL2State
;
2245 res
= mISDN_FsmNew(&l2fsm
, L2FnList
, ARRAY_SIZE(L2FnList
));
2254 mISDN_FsmFree(&l2fsm
);
2256 mISDN_unregister_Bprotocol(&X75SLP
);
2261 Isdnl2_cleanup(void)
2263 mISDN_unregister_Bprotocol(&X75SLP
);
2265 mISDN_FsmFree(&l2fsm
);