3 * Author Karsten Keil <kkeil@novell.com>
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/mISDNif.h>
19 #include <linux/slab.h>
27 struct Fsm l2fsm
= {NULL
, 0, 0, NULL
, NULL
};
29 static char *strL2State
[] =
53 EV_L2_DL_ESTABLISH_REQ
,
68 #define L2_EVENT_COUNT (EV_L2_FRAME_ERROR + 1)
70 static char *strL2Event
[] =
83 "EV_L2_DL_ESTABLISH_REQ",
84 "EV_L2_DL_RELEASE_REQ",
94 "EV_L2_CLEAR_OWN_BUSY",
99 l2m_debug(struct FsmInst
*fi
, char *fmt
, ...)
101 struct layer2
*l2
= fi
->userdata
;
102 struct va_format vaf
;
105 if (!(*debug
& DEBUG_L2_FSM
))
113 printk(KERN_DEBUG
"%s l2 (sapi %d tei %d): %pV\n",
114 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
, &vaf
);
120 l2headersize(struct layer2
*l2
, int ui
)
122 return ((test_bit(FLG_MOD128
, &l2
->flag
) && (!ui
)) ? 2 : 1) +
123 (test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1);
127 l2addrsize(struct layer2
*l2
)
129 return test_bit(FLG_LAPD
, &l2
->flag
) ? 2 : 1;
133 l2_newid(struct layer2
*l2
)
147 l2up(struct layer2
*l2
, u_int prim
, struct sk_buff
*skb
)
153 mISDN_HEAD_PRIM(skb
) = prim
;
154 mISDN_HEAD_ID(skb
) = (l2
->ch
.nr
<< 16) | l2
->ch
.addr
;
155 err
= l2
->up
->send(l2
->up
, skb
);
157 printk(KERN_WARNING
"%s: dev %s err=%d\n", __func__
,
158 mISDNDevName4ch(&l2
->ch
), err
);
164 l2up_create(struct layer2
*l2
, u_int prim
, int len
, void *arg
)
167 struct mISDNhead
*hh
;
172 skb
= mI_alloc_skb(len
, GFP_ATOMIC
);
175 hh
= mISDN_HEAD_P(skb
);
177 hh
->id
= (l2
->ch
.nr
<< 16) | l2
->ch
.addr
;
179 memcpy(skb_put(skb
, len
), arg
, len
);
180 err
= l2
->up
->send(l2
->up
, skb
);
182 printk(KERN_WARNING
"%s: dev %s err=%d\n", __func__
,
183 mISDNDevName4ch(&l2
->ch
), err
);
189 l2down_skb(struct layer2
*l2
, struct sk_buff
*skb
) {
192 ret
= l2
->ch
.recv(l2
->ch
.peer
, skb
);
193 if (ret
&& (*debug
& DEBUG_L2_RECV
))
194 printk(KERN_DEBUG
"l2down_skb: dev %s ret(%d)\n",
195 mISDNDevName4ch(&l2
->ch
), ret
);
200 l2down_raw(struct layer2
*l2
, struct sk_buff
*skb
)
202 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
204 if (hh
->prim
== PH_DATA_REQ
) {
205 if (test_and_set_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
206 skb_queue_tail(&l2
->down_queue
, skb
);
209 l2
->down_id
= mISDN_HEAD_ID(skb
);
211 return l2down_skb(l2
, skb
);
215 l2down(struct layer2
*l2
, u_int prim
, u_int id
, struct sk_buff
*skb
)
217 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
221 return l2down_raw(l2
, skb
);
225 l2down_create(struct layer2
*l2
, u_int prim
, u_int id
, int len
, void *arg
)
229 struct mISDNhead
*hh
;
231 skb
= mI_alloc_skb(len
, GFP_ATOMIC
);
234 hh
= mISDN_HEAD_P(skb
);
238 memcpy(skb_put(skb
, len
), arg
, len
);
239 err
= l2down_raw(l2
, skb
);
246 ph_data_confirm(struct layer2
*l2
, struct mISDNhead
*hh
, struct sk_buff
*skb
) {
247 struct sk_buff
*nskb
= skb
;
250 if (test_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
251 if (hh
->id
== l2
->down_id
) {
252 nskb
= skb_dequeue(&l2
->down_queue
);
254 l2
->down_id
= mISDN_HEAD_ID(nskb
);
255 if (l2down_skb(l2
, nskb
)) {
257 l2
->down_id
= MISDN_ID_NONE
;
260 l2
->down_id
= MISDN_ID_NONE
;
265 if (l2
->down_id
== MISDN_ID_NONE
) {
266 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
267 mISDN_FsmEvent(&l2
->l2m
, EV_L2_ACK_PULL
, NULL
);
271 if (!test_and_set_bit(FLG_L1_NOTREADY
, &l2
->flag
)) {
272 nskb
= skb_dequeue(&l2
->down_queue
);
274 l2
->down_id
= mISDN_HEAD_ID(nskb
);
275 if (l2down_skb(l2
, nskb
)) {
277 l2
->down_id
= MISDN_ID_NONE
;
278 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
281 test_and_clear_bit(FLG_L1_NOTREADY
, &l2
->flag
);
287 l2_timeout(struct FsmInst
*fi
, int event
, void *arg
)
289 struct layer2
*l2
= fi
->userdata
;
291 struct mISDNhead
*hh
;
293 skb
= mI_alloc_skb(0, GFP_ATOMIC
);
295 printk(KERN_WARNING
"%s: L2(%d,%d) nr:%x timer %s no skb\n",
296 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
,
297 l2
->ch
.nr
, event
== EV_L2_T200
? "T200" : "T203");
300 hh
= mISDN_HEAD_P(skb
);
301 hh
->prim
= event
== EV_L2_T200
? DL_TIMER200_IND
: DL_TIMER203_IND
;
303 if (*debug
& DEBUG_TIMER
)
304 printk(KERN_DEBUG
"%s: L2(%d,%d) nr:%x timer %s expired\n",
305 mISDNDevName4ch(&l2
->ch
), l2
->sapi
, l2
->tei
,
306 l2
->ch
.nr
, event
== EV_L2_T200
? "T200" : "T203");
308 l2
->ch
.st
->own
.recv(&l2
->ch
.st
->own
, skb
);
312 l2mgr(struct layer2
*l2
, u_int prim
, void *arg
) {
315 printk(KERN_WARNING
"l2mgr: dev %s addr:%x prim %x %c\n",
316 mISDNDevName4ch(&l2
->ch
), l2
->id
, prim
, (char)c
);
317 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
318 !test_bit(FLG_FIXED_TEI
, &l2
->flag
)) {
324 l2_tei(l2
, prim
, (u_long
)arg
);
332 set_peer_busy(struct layer2
*l2
) {
333 test_and_set_bit(FLG_PEER_BUSY
, &l2
->flag
);
334 if (skb_queue_len(&l2
->i_queue
) || skb_queue_len(&l2
->ui_queue
))
335 test_and_set_bit(FLG_L2BLOCK
, &l2
->flag
);
339 clear_peer_busy(struct layer2
*l2
) {
340 if (test_and_clear_bit(FLG_PEER_BUSY
, &l2
->flag
))
341 test_and_clear_bit(FLG_L2BLOCK
, &l2
->flag
);
345 InitWin(struct layer2
*l2
)
349 for (i
= 0; i
< MAX_WINDOW
; i
++)
350 l2
->windowar
[i
] = NULL
;
354 freewin(struct layer2
*l2
)
358 for (i
= 0; i
< MAX_WINDOW
; i
++) {
359 if (l2
->windowar
[i
]) {
361 dev_kfree_skb(l2
->windowar
[i
]);
362 l2
->windowar
[i
] = NULL
;
369 ReleaseWin(struct layer2
*l2
)
371 int cnt
= freewin(l2
);
375 "isdnl2 freed %d skbuffs in release\n", cnt
);
379 cansend(struct layer2
*l2
)
383 if (test_bit(FLG_MOD128
, &l2
->flag
))
384 p1
= (l2
->vs
- l2
->va
) % 128;
386 p1
= (l2
->vs
- l2
->va
) % 8;
387 return (p1
< l2
->window
) && !test_bit(FLG_PEER_BUSY
, &l2
->flag
);
391 clear_exception(struct layer2
*l2
)
393 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
394 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
395 test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
);
400 sethdraddr(struct layer2
*l2
, u_char
*header
, int rsp
)
402 u_char
*ptr
= header
;
405 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
406 if (test_bit(FLG_LAPD_NET
, &l2
->flag
))
408 *ptr
++ = (l2
->sapi
<< 2) | (crbit
? 2 : 0);
409 *ptr
++ = (l2
->tei
<< 1) | 1;
412 if (test_bit(FLG_ORIG
, &l2
->flag
))
423 enqueue_super(struct layer2
*l2
, struct sk_buff
*skb
)
425 if (l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), skb
))
430 enqueue_ui(struct layer2
*l2
, struct sk_buff
*skb
)
433 l2_tei(l2
, MDL_STATUS_UI_IND
, 0);
434 if (l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), skb
))
441 return (data
[0] & 0xef) == UI
;
447 return (data
[0] & 0xef) == UA
;
453 return (data
[0] & 0xef) == DM
;
459 return (data
[0] & 0xef) == DISC
;
463 IsRR(u_char
*data
, struct layer2
*l2
)
465 if (test_bit(FLG_MOD128
, &l2
->flag
))
466 return data
[0] == RR
;
468 return (data
[0] & 0xf) == 1;
472 IsSFrame(u_char
*data
, struct layer2
*l2
)
474 register u_char d
= *data
;
476 if (!test_bit(FLG_MOD128
, &l2
->flag
))
478 return ((d
& 0xf3) == 1) && ((d
& 0x0c) != 0x0c);
482 IsSABME(u_char
*data
, struct layer2
*l2
)
484 u_char d
= data
[0] & ~0x10;
486 return test_bit(FLG_MOD128
, &l2
->flag
) ? d
== SABME
: d
== SABM
;
490 IsREJ(u_char
*data
, struct layer2
*l2
)
492 return test_bit(FLG_MOD128
, &l2
->flag
) ?
493 data
[0] == REJ
: (data
[0] & 0xf) == REJ
;
499 return (data
[0] & 0xef) == FRMR
;
503 IsRNR(u_char
*data
, struct layer2
*l2
)
505 return test_bit(FLG_MOD128
, &l2
->flag
) ?
506 data
[0] == RNR
: (data
[0] & 0xf) == RNR
;
510 iframe_error(struct layer2
*l2
, struct sk_buff
*skb
)
513 int rsp
= *skb
->data
& 0x2;
515 i
= l2addrsize(l2
) + (test_bit(FLG_MOD128
, &l2
->flag
) ? 2 : 1);
516 if (test_bit(FLG_ORIG
, &l2
->flag
))
522 if ((skb
->len
- i
) > l2
->maxlen
)
528 super_error(struct layer2
*l2
, struct sk_buff
*skb
)
530 if (skb
->len
!= l2addrsize(l2
) +
531 (test_bit(FLG_MOD128
, &l2
->flag
) ? 2 : 1))
537 unnum_error(struct layer2
*l2
, struct sk_buff
*skb
, int wantrsp
)
539 int rsp
= (*skb
->data
& 0x2) >> 1;
540 if (test_bit(FLG_ORIG
, &l2
->flag
))
544 if (skb
->len
!= l2addrsize(l2
) + 1)
550 UI_error(struct layer2
*l2
, struct sk_buff
*skb
)
552 int rsp
= *skb
->data
& 0x2;
553 if (test_bit(FLG_ORIG
, &l2
->flag
))
557 if (skb
->len
> l2
->maxlen
+ l2addrsize(l2
) + 1)
563 FRMR_error(struct layer2
*l2
, struct sk_buff
*skb
)
565 u_int headers
= l2addrsize(l2
) + 1;
566 u_char
*datap
= skb
->data
+ headers
;
567 int rsp
= *skb
->data
& 0x2;
569 if (test_bit(FLG_ORIG
, &l2
->flag
))
573 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
574 if (skb
->len
< headers
+ 5)
576 else if (*debug
& DEBUG_L2
)
578 "FRMR information %2x %2x %2x %2x %2x",
579 datap
[0], datap
[1], datap
[2], datap
[3], datap
[4]);
581 if (skb
->len
< headers
+ 3)
583 else if (*debug
& DEBUG_L2
)
585 "FRMR information %2x %2x %2x",
586 datap
[0], datap
[1], datap
[2]);
592 legalnr(struct layer2
*l2
, unsigned int nr
)
594 if (test_bit(FLG_MOD128
, &l2
->flag
))
595 return ((nr
- l2
->va
) % 128) <= ((l2
->vs
- l2
->va
) % 128);
597 return ((nr
- l2
->va
) % 8) <= ((l2
->vs
- l2
->va
) % 8);
601 setva(struct layer2
*l2
, unsigned int nr
)
605 while (l2
->va
!= nr
) {
607 if (test_bit(FLG_MOD128
, &l2
->flag
))
611 if (l2
->windowar
[l2
->sow
]) {
612 skb_trim(l2
->windowar
[l2
->sow
], 0);
613 skb_queue_tail(&l2
->tmp_queue
, l2
->windowar
[l2
->sow
]);
614 l2
->windowar
[l2
->sow
] = NULL
;
616 l2
->sow
= (l2
->sow
+ 1) % l2
->window
;
618 skb
= skb_dequeue(&l2
->tmp_queue
);
621 skb
= skb_dequeue(&l2
->tmp_queue
);
626 send_uframe(struct layer2
*l2
, struct sk_buff
*skb
, u_char cmd
, u_char cr
)
628 u_char tmp
[MAX_L2HEADER_LEN
];
631 i
= sethdraddr(l2
, tmp
, cr
);
636 skb
= mI_alloc_skb(i
, GFP_ATOMIC
);
638 printk(KERN_WARNING
"%s: can't alloc skbuff in %s\n",
639 mISDNDevName4ch(&l2
->ch
), __func__
);
643 memcpy(skb_put(skb
, i
), tmp
, i
);
644 enqueue_super(l2
, skb
);
649 get_PollFlag(struct layer2
*l2
, struct sk_buff
*skb
)
651 return skb
->data
[l2addrsize(l2
)] & 0x10;
655 get_PollFlagFree(struct layer2
*l2
, struct sk_buff
*skb
)
659 PF
= get_PollFlag(l2
, skb
);
665 start_t200(struct layer2
*l2
, int i
)
667 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, i
);
668 test_and_set_bit(FLG_T200_RUN
, &l2
->flag
);
672 restart_t200(struct layer2
*l2
, int i
)
674 mISDN_FsmRestartTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, i
);
675 test_and_set_bit(FLG_T200_RUN
, &l2
->flag
);
679 stop_t200(struct layer2
*l2
, int i
)
681 if (test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
))
682 mISDN_FsmDelTimer(&l2
->t200
, i
);
686 st5_dl_release_l2l3(struct layer2
*l2
)
690 if (test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
))
694 l2up_create(l2
, pr
, 0, NULL
);
698 lapb_dl_release_l2l3(struct layer2
*l2
, int f
)
700 if (test_bit(FLG_LAPB
, &l2
->flag
))
701 l2down_create(l2
, PH_DEACTIVATE_REQ
, l2_newid(l2
), 0, NULL
);
702 l2up_create(l2
, f
, 0, NULL
);
706 establishlink(struct FsmInst
*fi
)
708 struct layer2
*l2
= fi
->userdata
;
713 cmd
= (test_bit(FLG_MOD128
, &l2
->flag
) ? SABME
: SABM
) | 0x10;
714 send_uframe(l2
, NULL
, cmd
, CMD
);
715 mISDN_FsmDelTimer(&l2
->t203
, 1);
717 test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
);
719 mISDN_FsmChangeState(fi
, ST_L2_5
);
723 l2_mdl_error_ua(struct FsmInst
*fi
, int event
, void *arg
)
725 struct sk_buff
*skb
= arg
;
726 struct layer2
*l2
= fi
->userdata
;
728 if (get_PollFlagFree(l2
, skb
))
729 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'C');
731 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'D');
736 l2_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
738 struct sk_buff
*skb
= arg
;
739 struct layer2
*l2
= fi
->userdata
;
741 if (get_PollFlagFree(l2
, skb
))
742 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'B');
744 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'E');
746 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
751 l2_st8_mdl_error_dm(struct FsmInst
*fi
, int event
, void *arg
)
753 struct sk_buff
*skb
= arg
;
754 struct layer2
*l2
= fi
->userdata
;
756 if (get_PollFlagFree(l2
, skb
))
757 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'B');
759 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'E');
761 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
765 l2_go_st3(struct FsmInst
*fi
, int event
, void *arg
)
767 dev_kfree_skb((struct sk_buff
*)arg
);
768 mISDN_FsmChangeState(fi
, ST_L2_3
);
772 l2_mdl_assign(struct FsmInst
*fi
, int event
, void *arg
)
774 struct layer2
*l2
= fi
->userdata
;
776 mISDN_FsmChangeState(fi
, ST_L2_3
);
777 dev_kfree_skb((struct sk_buff
*)arg
);
778 l2_tei(l2
, MDL_ASSIGN_IND
, 0);
782 l2_queue_ui_assign(struct FsmInst
*fi
, int event
, void *arg
)
784 struct layer2
*l2
= fi
->userdata
;
785 struct sk_buff
*skb
= arg
;
787 skb_queue_tail(&l2
->ui_queue
, skb
);
788 mISDN_FsmChangeState(fi
, ST_L2_2
);
789 l2_tei(l2
, MDL_ASSIGN_IND
, 0);
793 l2_queue_ui(struct FsmInst
*fi
, int event
, void *arg
)
795 struct layer2
*l2
= fi
->userdata
;
796 struct sk_buff
*skb
= arg
;
798 skb_queue_tail(&l2
->ui_queue
, skb
);
802 tx_ui(struct layer2
*l2
)
805 u_char header
[MAX_L2HEADER_LEN
];
808 i
= sethdraddr(l2
, header
, CMD
);
809 if (test_bit(FLG_LAPD_NET
, &l2
->flag
))
810 header
[1] = 0xff; /* tei 127 */
812 while ((skb
= skb_dequeue(&l2
->ui_queue
))) {
813 memcpy(skb_push(skb
, i
), header
, i
);
819 l2_send_ui(struct FsmInst
*fi
, int event
, void *arg
)
821 struct layer2
*l2
= fi
->userdata
;
822 struct sk_buff
*skb
= arg
;
824 skb_queue_tail(&l2
->ui_queue
, skb
);
829 l2_got_ui(struct FsmInst
*fi
, int event
, void *arg
)
831 struct layer2
*l2
= fi
->userdata
;
832 struct sk_buff
*skb
= arg
;
834 skb_pull(skb
, l2headersize(l2
, 1));
836 * in states 1-3 for broadcast
840 l2_tei(l2
, MDL_STATUS_UI_IND
, 0);
841 l2up(l2
, DL_UNITDATA_IND
, skb
);
845 l2_establish(struct FsmInst
*fi
, int event
, void *arg
)
847 struct sk_buff
*skb
= arg
;
848 struct layer2
*l2
= fi
->userdata
;
851 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
856 l2_discard_i_setl3(struct FsmInst
*fi
, int event
, void *arg
)
858 struct sk_buff
*skb
= arg
;
859 struct layer2
*l2
= fi
->userdata
;
861 skb_queue_purge(&l2
->i_queue
);
862 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
863 test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
);
868 l2_l3_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
870 struct sk_buff
*skb
= arg
;
871 struct layer2
*l2
= fi
->userdata
;
873 skb_queue_purge(&l2
->i_queue
);
875 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
880 l2_release(struct FsmInst
*fi
, int event
, void *arg
)
882 struct layer2
*l2
= fi
->userdata
;
883 struct sk_buff
*skb
= arg
;
886 l2up(l2
, DL_RELEASE_CNF
, skb
);
890 l2_pend_rel(struct FsmInst
*fi
, int event
, void *arg
)
892 struct sk_buff
*skb
= arg
;
893 struct layer2
*l2
= fi
->userdata
;
895 test_and_set_bit(FLG_PEND_REL
, &l2
->flag
);
900 l2_disconnect(struct FsmInst
*fi
, int event
, void *arg
)
902 struct layer2
*l2
= fi
->userdata
;
903 struct sk_buff
*skb
= arg
;
905 skb_queue_purge(&l2
->i_queue
);
907 mISDN_FsmChangeState(fi
, ST_L2_6
);
909 send_uframe(l2
, NULL
, DISC
| 0x10, CMD
);
910 mISDN_FsmDelTimer(&l2
->t203
, 1);
917 l2_start_multi(struct FsmInst
*fi
, int event
, void *arg
)
919 struct layer2
*l2
= fi
->userdata
;
920 struct sk_buff
*skb
= arg
;
927 send_uframe(l2
, NULL
, UA
| get_PollFlag(l2
, skb
), RSP
);
928 mISDN_FsmChangeState(fi
, ST_L2_7
);
929 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 3);
931 l2up(l2
, DL_ESTABLISH_IND
, skb
);
933 l2_tei(l2
, MDL_STATUS_UP_IND
, 0);
937 l2_send_UA(struct FsmInst
*fi
, int event
, void *arg
)
939 struct layer2
*l2
= fi
->userdata
;
940 struct sk_buff
*skb
= arg
;
942 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
946 l2_send_DM(struct FsmInst
*fi
, int event
, void *arg
)
948 struct layer2
*l2
= fi
->userdata
;
949 struct sk_buff
*skb
= arg
;
951 send_uframe(l2
, skb
, DM
| get_PollFlag(l2
, skb
), RSP
);
955 l2_restart_multi(struct FsmInst
*fi
, int event
, void *arg
)
957 struct layer2
*l2
= fi
->userdata
;
958 struct sk_buff
*skb
= arg
;
961 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
963 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'F');
965 if (l2
->vs
!= l2
->va
) {
966 skb_queue_purge(&l2
->i_queue
);
975 mISDN_FsmChangeState(fi
, ST_L2_7
);
977 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 3);
980 l2up_create(l2
, DL_ESTABLISH_IND
, 0, NULL
);
981 /* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
982 * MGR_SHORTSTATUS | INDICATION, SSTATUS_L2_ESTABLISHED,
985 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
986 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
990 l2_stop_multi(struct FsmInst
*fi
, int event
, void *arg
)
992 struct layer2
*l2
= fi
->userdata
;
993 struct sk_buff
*skb
= arg
;
995 mISDN_FsmChangeState(fi
, ST_L2_4
);
996 mISDN_FsmDelTimer(&l2
->t203
, 3);
999 send_uframe(l2
, skb
, UA
| get_PollFlag(l2
, skb
), RSP
);
1000 skb_queue_purge(&l2
->i_queue
);
1002 lapb_dl_release_l2l3(l2
, DL_RELEASE_IND
);
1004 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1008 l2_connected(struct FsmInst
*fi
, int event
, void *arg
)
1010 struct layer2
*l2
= fi
->userdata
;
1011 struct sk_buff
*skb
= arg
;
1014 if (!get_PollFlag(l2
, skb
)) {
1015 l2_mdl_error_ua(fi
, event
, arg
);
1019 if (test_and_clear_bit(FLG_PEND_REL
, &l2
->flag
))
1020 l2_disconnect(fi
, event
, NULL
);
1021 if (test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
)) {
1022 pr
= DL_ESTABLISH_CNF
;
1023 } else if (l2
->vs
!= l2
->va
) {
1024 skb_queue_purge(&l2
->i_queue
);
1025 pr
= DL_ESTABLISH_IND
;
1032 mISDN_FsmChangeState(fi
, ST_L2_7
);
1033 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 4);
1035 l2up_create(l2
, pr
, 0, NULL
);
1037 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
1038 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1041 l2_tei(l2
, MDL_STATUS_UP_IND
, 0);
1045 l2_released(struct FsmInst
*fi
, int event
, void *arg
)
1047 struct layer2
*l2
= fi
->userdata
;
1048 struct sk_buff
*skb
= arg
;
1050 if (!get_PollFlag(l2
, skb
)) {
1051 l2_mdl_error_ua(fi
, event
, arg
);
1056 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1057 mISDN_FsmChangeState(fi
, ST_L2_4
);
1059 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1063 l2_reestablish(struct FsmInst
*fi
, int event
, void *arg
)
1065 struct layer2
*l2
= fi
->userdata
;
1066 struct sk_buff
*skb
= arg
;
1068 if (!get_PollFlagFree(l2
, skb
)) {
1070 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
1075 l2_st5_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
1077 struct layer2
*l2
= fi
->userdata
;
1078 struct sk_buff
*skb
= arg
;
1080 if (get_PollFlagFree(l2
, skb
)) {
1082 if (!test_bit(FLG_L3_INIT
, &l2
->flag
))
1083 skb_queue_purge(&l2
->i_queue
);
1084 if (test_bit(FLG_LAPB
, &l2
->flag
))
1085 l2down_create(l2
, PH_DEACTIVATE_REQ
,
1086 l2_newid(l2
), 0, NULL
);
1087 st5_dl_release_l2l3(l2
);
1088 mISDN_FsmChangeState(fi
, ST_L2_4
);
1090 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1095 l2_st6_dm_release(struct FsmInst
*fi
, int event
, void *arg
)
1097 struct layer2
*l2
= fi
->userdata
;
1098 struct sk_buff
*skb
= arg
;
1100 if (get_PollFlagFree(l2
, skb
)) {
1102 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1103 mISDN_FsmChangeState(fi
, ST_L2_4
);
1105 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1110 enquiry_cr(struct layer2
*l2
, u_char typ
, u_char cr
, u_char pf
)
1112 struct sk_buff
*skb
;
1113 u_char tmp
[MAX_L2HEADER_LEN
];
1116 i
= sethdraddr(l2
, tmp
, cr
);
1117 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1119 tmp
[i
++] = (l2
->vr
<< 1) | (pf
? 1 : 0);
1121 tmp
[i
++] = (l2
->vr
<< 5) | typ
| (pf
? 0x10 : 0);
1122 skb
= mI_alloc_skb(i
, GFP_ATOMIC
);
1124 printk(KERN_WARNING
"%s: isdnl2 can't alloc sbbuff in %s\n",
1125 mISDNDevName4ch(&l2
->ch
), __func__
);
1128 memcpy(skb_put(skb
, i
), tmp
, i
);
1129 enqueue_super(l2
, skb
);
1133 enquiry_response(struct layer2
*l2
)
1135 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
))
1136 enquiry_cr(l2
, RNR
, RSP
, 1);
1138 enquiry_cr(l2
, RR
, RSP
, 1);
1139 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1143 transmit_enquiry(struct layer2
*l2
)
1145 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
))
1146 enquiry_cr(l2
, RNR
, CMD
, 1);
1148 enquiry_cr(l2
, RR
, CMD
, 1);
1149 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1155 nrerrorrecovery(struct FsmInst
*fi
)
1157 struct layer2
*l2
= fi
->userdata
;
1159 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'J');
1161 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1165 invoke_retransmission(struct layer2
*l2
, unsigned int nr
)
1170 while (l2
->vs
!= nr
) {
1172 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1174 p1
= (l2
->vs
- l2
->va
) % 128;
1177 p1
= (l2
->vs
- l2
->va
) % 8;
1179 p1
= (p1
+ l2
->sow
) % l2
->window
;
1180 if (l2
->windowar
[p1
])
1181 skb_queue_head(&l2
->i_queue
, l2
->windowar
[p1
]);
1184 "%s: windowar[%d] is NULL\n",
1185 mISDNDevName4ch(&l2
->ch
), p1
);
1186 l2
->windowar
[p1
] = NULL
;
1188 mISDN_FsmEvent(&l2
->l2m
, EV_L2_ACK_PULL
, NULL
);
1193 l2_st7_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1195 struct layer2
*l2
= fi
->userdata
;
1196 struct sk_buff
*skb
= arg
;
1197 int PollFlag
, rsp
, typ
= RR
;
1200 rsp
= *skb
->data
& 0x2;
1201 if (test_bit(FLG_ORIG
, &l2
->flag
))
1204 skb_pull(skb
, l2addrsize(l2
));
1205 if (IsRNR(skb
->data
, l2
)) {
1209 clear_peer_busy(l2
);
1210 if (IsREJ(skb
->data
, l2
))
1213 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1214 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1215 nr
= skb
->data
[1] >> 1;
1217 PollFlag
= (skb
->data
[0] & 0x10);
1218 nr
= (skb
->data
[0] >> 5) & 0x7;
1224 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'A');
1226 enquiry_response(l2
);
1228 if (legalnr(l2
, nr
)) {
1231 invoke_retransmission(l2
, nr
);
1233 if (mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
,
1234 EV_L2_T203
, NULL
, 6))
1235 l2m_debug(&l2
->l2m
, "Restart T203 ST7 REJ");
1236 } else if ((nr
== l2
->vs
) && (typ
== RR
)) {
1239 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
,
1240 EV_L2_T203
, NULL
, 7);
1241 } else if ((l2
->va
!= nr
) || (typ
== RNR
)) {
1244 mISDN_FsmDelTimer(&l2
->t203
, 9);
1245 restart_t200(l2
, 12);
1247 if (skb_queue_len(&l2
->i_queue
) && (typ
== RR
))
1248 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1250 nrerrorrecovery(fi
);
1254 l2_feed_i_if_reest(struct FsmInst
*fi
, int event
, void *arg
)
1256 struct layer2
*l2
= fi
->userdata
;
1257 struct sk_buff
*skb
= arg
;
1259 if (!test_bit(FLG_L3_INIT
, &l2
->flag
))
1260 skb_queue_tail(&l2
->i_queue
, skb
);
1266 l2_feed_i_pull(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
);
1272 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1276 l2_feed_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1278 struct layer2
*l2
= fi
->userdata
;
1279 struct sk_buff
*skb
= arg
;
1281 skb_queue_tail(&l2
->i_queue
, skb
);
1285 l2_got_iframe(struct FsmInst
*fi
, int event
, void *arg
)
1287 struct layer2
*l2
= fi
->userdata
;
1288 struct sk_buff
*skb
= arg
;
1293 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1294 PollFlag
= ((skb
->data
[i
+ 1] & 0x1) == 0x1);
1295 ns
= skb
->data
[i
] >> 1;
1296 nr
= (skb
->data
[i
+ 1] >> 1) & 0x7f;
1298 PollFlag
= (skb
->data
[i
] & 0x10);
1299 ns
= (skb
->data
[i
] >> 1) & 0x7;
1300 nr
= (skb
->data
[i
] >> 5) & 0x7;
1302 if (test_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1305 enquiry_response(l2
);
1309 if (test_bit(FLG_MOD128
, &l2
->flag
))
1313 test_and_clear_bit(FLG_REJEXC
, &l2
->flag
);
1315 enquiry_response(l2
);
1317 test_and_set_bit(FLG_ACK_PEND
, &l2
->flag
);
1318 skb_pull(skb
, l2headersize(l2
, 0));
1319 l2up(l2
, DL_DATA_IND
, skb
);
1323 if (test_and_set_bit(FLG_REJEXC
, &l2
->flag
)) {
1325 enquiry_response(l2
);
1327 enquiry_cr(l2
, REJ
, RSP
, PollFlag
);
1328 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1332 if (legalnr(l2
, nr
)) {
1333 if (!test_bit(FLG_PEER_BUSY
, &l2
->flag
) &&
1334 (fi
->state
== ST_L2_7
)) {
1337 mISDN_FsmRestartTimer(&l2
->t203
, l2
->T203
,
1338 EV_L2_T203
, NULL
, 7);
1339 } else if (nr
!= l2
->va
)
1340 restart_t200(l2
, 14);
1344 nrerrorrecovery(fi
);
1347 if (skb_queue_len(&l2
->i_queue
) && (fi
->state
== ST_L2_7
))
1348 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1349 if (test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
))
1350 enquiry_cr(l2
, RR
, RSP
, 0);
1354 l2_got_tei(struct FsmInst
*fi
, int event
, void *arg
)
1356 struct layer2
*l2
= fi
->userdata
;
1359 l2
->tei
= (signed char)(long)arg
;
1360 set_channel_address(&l2
->ch
, l2
->sapi
, l2
->tei
);
1361 info
= DL_INFO_L2_CONNECT
;
1362 l2up_create(l2
, DL_INFORMATION_IND
, sizeof(info
), &info
);
1363 if (fi
->state
== ST_L2_3
) {
1365 test_and_set_bit(FLG_L3_INIT
, &l2
->flag
);
1367 mISDN_FsmChangeState(fi
, ST_L2_4
);
1368 if (skb_queue_len(&l2
->ui_queue
))
1373 l2_st5_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1375 struct layer2
*l2
= fi
->userdata
;
1377 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1378 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1379 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1380 } else if (l2
->rc
== l2
->N200
) {
1381 mISDN_FsmChangeState(fi
, ST_L2_4
);
1382 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1383 skb_queue_purge(&l2
->i_queue
);
1384 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'G');
1385 if (test_bit(FLG_LAPB
, &l2
->flag
))
1386 l2down_create(l2
, PH_DEACTIVATE_REQ
,
1387 l2_newid(l2
), 0, NULL
);
1388 st5_dl_release_l2l3(l2
);
1390 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1393 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1394 send_uframe(l2
, NULL
, (test_bit(FLG_MOD128
, &l2
->flag
) ?
1395 SABME
: SABM
) | 0x10, CMD
);
1400 l2_st6_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1402 struct layer2
*l2
= fi
->userdata
;
1404 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1405 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1406 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1407 } else if (l2
->rc
== l2
->N200
) {
1408 mISDN_FsmChangeState(fi
, ST_L2_4
);
1409 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1410 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'H');
1411 lapb_dl_release_l2l3(l2
, DL_RELEASE_CNF
);
1413 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1416 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
,
1418 send_uframe(l2
, NULL
, DISC
| 0x10, CMD
);
1423 l2_st7_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1425 struct layer2
*l2
= fi
->userdata
;
1427 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1428 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1429 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1432 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1434 mISDN_FsmChangeState(fi
, ST_L2_8
);
1435 transmit_enquiry(l2
);
1440 l2_st8_tout_200(struct FsmInst
*fi
, int event
, void *arg
)
1442 struct layer2
*l2
= fi
->userdata
;
1444 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1445 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1446 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 9);
1449 test_and_clear_bit(FLG_T200_RUN
, &l2
->flag
);
1450 if (l2
->rc
== l2
->N200
) {
1451 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'I');
1453 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1455 transmit_enquiry(l2
);
1461 l2_st7_tout_203(struct FsmInst
*fi
, int event
, void *arg
)
1463 struct layer2
*l2
= fi
->userdata
;
1465 if (test_bit(FLG_LAPD
, &l2
->flag
) &&
1466 test_bit(FLG_DCHAN_BUSY
, &l2
->flag
)) {
1467 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
, EV_L2_T203
, NULL
, 9);
1470 mISDN_FsmChangeState(fi
, ST_L2_8
);
1471 transmit_enquiry(l2
);
1476 l2_pull_iqueue(struct FsmInst
*fi
, int event
, void *arg
)
1478 struct layer2
*l2
= fi
->userdata
;
1479 struct sk_buff
*skb
, *nskb
, *oskb
;
1480 u_char header
[MAX_L2HEADER_LEN
];
1486 skb
= skb_dequeue(&l2
->i_queue
);
1490 if (test_bit(FLG_MOD128
, &l2
->flag
))
1491 p1
= (l2
->vs
- l2
->va
) % 128;
1493 p1
= (l2
->vs
- l2
->va
) % 8;
1494 p1
= (p1
+ l2
->sow
) % l2
->window
;
1495 if (l2
->windowar
[p1
]) {
1496 printk(KERN_WARNING
"%s: l2 try overwrite ack queue entry %d\n",
1497 mISDNDevName4ch(&l2
->ch
), p1
);
1498 dev_kfree_skb(l2
->windowar
[p1
]);
1500 l2
->windowar
[p1
] = skb
;
1501 i
= sethdraddr(l2
, header
, CMD
);
1502 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1503 header
[i
++] = l2
->vs
<< 1;
1504 header
[i
++] = l2
->vr
<< 1;
1505 l2
->vs
= (l2
->vs
+ 1) % 128;
1507 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1508 l2
->vs
= (l2
->vs
+ 1) % 8;
1511 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1512 p1
= skb_headroom(nskb
);
1514 memcpy(skb_push(nskb
, i
), header
, i
);
1517 "%s: L2 pull_iqueue skb header(%d/%d) too short\n",
1518 mISDNDevName4ch(&l2
->ch
), i
, p1
);
1520 nskb
= mI_alloc_skb(oskb
->len
+ i
, GFP_ATOMIC
);
1522 dev_kfree_skb(oskb
);
1523 printk(KERN_WARNING
"%s: no skb mem in %s\n",
1524 mISDNDevName4ch(&l2
->ch
), __func__
);
1527 memcpy(skb_put(nskb
, i
), header
, i
);
1528 memcpy(skb_put(nskb
, oskb
->len
), oskb
->data
, oskb
->len
);
1529 dev_kfree_skb(oskb
);
1531 l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), nskb
);
1532 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1533 if (!test_and_set_bit(FLG_T200_RUN
, &l2
->flag
)) {
1534 mISDN_FsmDelTimer(&l2
->t203
, 13);
1535 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 11);
1540 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1542 struct layer2
*l2
= fi
->userdata
;
1543 struct sk_buff
*skb
= arg
;
1544 int PollFlag
, rsp
, rnr
= 0;
1547 rsp
= *skb
->data
& 0x2;
1548 if (test_bit(FLG_ORIG
, &l2
->flag
))
1551 skb_pull(skb
, l2addrsize(l2
));
1553 if (IsRNR(skb
->data
, l2
)) {
1557 clear_peer_busy(l2
);
1559 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1560 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1561 nr
= skb
->data
[1] >> 1;
1563 PollFlag
= (skb
->data
[0] & 0x10);
1564 nr
= (skb
->data
[0] >> 5) & 0x7;
1567 if (rsp
&& PollFlag
) {
1568 if (legalnr(l2
, nr
)) {
1570 restart_t200(l2
, 15);
1573 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
,
1574 EV_L2_T203
, NULL
, 5);
1577 invoke_retransmission(l2
, nr
);
1578 mISDN_FsmChangeState(fi
, ST_L2_7
);
1579 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
1580 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1582 nrerrorrecovery(fi
);
1584 if (!rsp
&& PollFlag
)
1585 enquiry_response(l2
);
1586 if (legalnr(l2
, nr
))
1589 nrerrorrecovery(fi
);
1594 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1596 struct layer2
*l2
= fi
->userdata
;
1597 struct sk_buff
*skb
= arg
;
1599 skb_pull(skb
, l2addrsize(l2
) + 1);
1601 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1602 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1603 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'K');
1605 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1611 l2_st24_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1613 struct layer2
*l2
= fi
->userdata
;
1615 skb_queue_purge(&l2
->ui_queue
);
1616 l2
->tei
= GROUP_TEI
;
1617 mISDN_FsmChangeState(fi
, ST_L2_1
);
1621 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1623 struct layer2
*l2
= fi
->userdata
;
1625 skb_queue_purge(&l2
->ui_queue
);
1626 l2
->tei
= GROUP_TEI
;
1627 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1628 mISDN_FsmChangeState(fi
, ST_L2_1
);
1632 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1634 struct layer2
*l2
= fi
->userdata
;
1636 skb_queue_purge(&l2
->i_queue
);
1637 skb_queue_purge(&l2
->ui_queue
);
1639 l2
->tei
= GROUP_TEI
;
1641 st5_dl_release_l2l3(l2
);
1642 mISDN_FsmChangeState(fi
, ST_L2_1
);
1646 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1648 struct layer2
*l2
= fi
->userdata
;
1650 skb_queue_purge(&l2
->ui_queue
);
1651 l2
->tei
= GROUP_TEI
;
1653 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1654 mISDN_FsmChangeState(fi
, ST_L2_1
);
1658 l2_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1660 struct layer2
*l2
= fi
->userdata
;
1662 skb_queue_purge(&l2
->i_queue
);
1663 skb_queue_purge(&l2
->ui_queue
);
1665 l2
->tei
= GROUP_TEI
;
1667 mISDN_FsmDelTimer(&l2
->t203
, 19);
1668 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1669 /* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
1670 * MGR_SHORTSTATUS_IND, SSTATUS_L2_RELEASED,
1673 mISDN_FsmChangeState(fi
, ST_L2_1
);
1677 l2_st14_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1679 struct layer2
*l2
= fi
->userdata
;
1680 struct sk_buff
*skb
= arg
;
1682 skb_queue_purge(&l2
->i_queue
);
1683 skb_queue_purge(&l2
->ui_queue
);
1684 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1685 l2up(l2
, DL_RELEASE_IND
, skb
);
1691 l2_st5_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1693 struct layer2
*l2
= fi
->userdata
;
1694 struct sk_buff
*skb
= arg
;
1696 skb_queue_purge(&l2
->i_queue
);
1697 skb_queue_purge(&l2
->ui_queue
);
1700 st5_dl_release_l2l3(l2
);
1701 mISDN_FsmChangeState(fi
, ST_L2_4
);
1703 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1708 l2_st6_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1710 struct layer2
*l2
= fi
->userdata
;
1711 struct sk_buff
*skb
= arg
;
1713 skb_queue_purge(&l2
->ui_queue
);
1715 l2up(l2
, DL_RELEASE_CNF
, skb
);
1716 mISDN_FsmChangeState(fi
, ST_L2_4
);
1718 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1722 l2_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1724 struct layer2
*l2
= fi
->userdata
;
1725 struct sk_buff
*skb
= arg
;
1727 skb_queue_purge(&l2
->i_queue
);
1728 skb_queue_purge(&l2
->ui_queue
);
1731 mISDN_FsmDelTimer(&l2
->t203
, 19);
1732 l2up(l2
, DL_RELEASE_IND
, skb
);
1733 mISDN_FsmChangeState(fi
, ST_L2_4
);
1735 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1739 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1741 struct layer2
*l2
= fi
->userdata
;
1742 struct sk_buff
*skb
= arg
;
1744 if (!test_and_set_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1745 enquiry_cr(l2
, RNR
, RSP
, 0);
1746 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1753 l2_clear_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1755 struct layer2
*l2
= fi
->userdata
;
1756 struct sk_buff
*skb
= arg
;
1758 if (!test_and_clear_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1759 enquiry_cr(l2
, RR
, RSP
, 0);
1760 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1767 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1769 struct layer2
*l2
= fi
->userdata
;
1771 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1775 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1777 struct layer2
*l2
= fi
->userdata
;
1779 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1781 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1784 static struct FsmNode L2FnList
[] =
1786 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1787 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1788 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1789 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1790 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1791 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1792 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1793 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1794 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1795 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1796 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1797 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1798 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1799 {ST_L2_1
, EV_L2_DL_UNITDATA
, l2_queue_ui_assign
},
1800 {ST_L2_2
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1801 {ST_L2_3
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1802 {ST_L2_4
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1803 {ST_L2_5
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1804 {ST_L2_6
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1805 {ST_L2_7
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1806 {ST_L2_8
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1807 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1808 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1809 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1810 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1811 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1812 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1813 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1814 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1815 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1816 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1817 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1818 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1819 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1820 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1821 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1822 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1823 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1824 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1825 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1826 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1827 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1828 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1829 {ST_L2_6
, EV_L2_UA
, l2_released
},
1830 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1831 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1832 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1833 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1834 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1835 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1836 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1837 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1838 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1839 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1840 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1841 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1842 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1843 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1844 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1845 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1846 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1847 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1848 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1849 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1850 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1851 {ST_L2_5
, EV_L2_T200
, l2_timeout
},
1852 {ST_L2_6
, EV_L2_T200
, l2_timeout
},
1853 {ST_L2_7
, EV_L2_T200
, l2_timeout
},
1854 {ST_L2_8
, EV_L2_T200
, l2_timeout
},
1855 {ST_L2_7
, EV_L2_T203
, l2_timeout
},
1856 {ST_L2_5
, EV_L2_T200I
, l2_st5_tout_200
},
1857 {ST_L2_6
, EV_L2_T200I
, l2_st6_tout_200
},
1858 {ST_L2_7
, EV_L2_T200I
, l2_st7_tout_200
},
1859 {ST_L2_8
, EV_L2_T200I
, l2_st8_tout_200
},
1860 {ST_L2_7
, EV_L2_T203I
, l2_st7_tout_203
},
1861 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1862 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1863 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1864 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1865 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1866 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1867 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1868 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1869 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1870 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1871 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1872 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1873 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1874 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1875 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistent_da
},
1876 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistent_da
},
1877 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1878 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1882 ph_data_indication(struct layer2
*l2
, struct mISDNhead
*hh
, struct sk_buff
*skb
)
1884 u_char
*datap
= skb
->data
;
1891 if (skb
->len
<= l
) {
1892 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
1895 if (test_bit(FLG_LAPD
, &l2
->flag
)) { /* Maybe not needed */
1898 if ((psapi
& 1) || !(ptei
& 1)) {
1900 "%s l2 D-channel frame wrong EA0/EA1\n",
1901 mISDNDevName4ch(&l2
->ch
));
1906 if (psapi
!= l2
->sapi
) {
1907 /* not our business */
1908 if (*debug
& DEBUG_L2
)
1909 printk(KERN_DEBUG
"%s: sapi %d/%d mismatch\n",
1910 mISDNDevName4ch(&l2
->ch
), psapi
,
1915 if ((ptei
!= l2
->tei
) && (ptei
!= GROUP_TEI
)) {
1916 /* not our business */
1917 if (*debug
& DEBUG_L2
)
1918 printk(KERN_DEBUG
"%s: tei %d/%d mismatch\n",
1919 mISDNDevName4ch(&l2
->ch
), ptei
, l2
->tei
);
1925 if (!(*datap
& 1)) { /* I-Frame */
1926 c
= iframe_error(l2
, skb
);
1928 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_I
, skb
);
1929 } else if (IsSFrame(datap
, l2
)) { /* S-Frame */
1930 c
= super_error(l2
, skb
);
1932 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SUPER
, skb
);
1933 } else if (IsUI(datap
)) {
1934 c
= UI_error(l2
, skb
);
1936 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UI
, skb
);
1937 } else if (IsSABME(datap
, l2
)) {
1938 c
= unnum_error(l2
, skb
, CMD
);
1940 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SABME
, skb
);
1941 } else if (IsUA(datap
)) {
1942 c
= unnum_error(l2
, skb
, RSP
);
1944 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UA
, skb
);
1945 } else if (IsDISC(datap
)) {
1946 c
= unnum_error(l2
, skb
, CMD
);
1948 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DISC
, skb
);
1949 } else if (IsDM(datap
)) {
1950 c
= unnum_error(l2
, skb
, RSP
);
1952 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DM
, skb
);
1953 } else if (IsFRMR(datap
)) {
1954 c
= FRMR_error(l2
, skb
);
1956 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRMR
, skb
);
1960 printk(KERN_WARNING
"%s:l2 D-channel frame error %c\n",
1961 mISDNDevName4ch(&l2
->ch
), c
);
1962 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1968 l2_send(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1970 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
1971 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1974 if (*debug
& DEBUG_L2_RECV
)
1975 printk(KERN_DEBUG
"%s: %s prim(%x) id(%x) sapi(%d) tei(%d)\n",
1976 __func__
, mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
,
1978 if (hh
->prim
== DL_INTERN_MSG
) {
1979 struct mISDNhead
*chh
= hh
+ 1; /* saved copy */
1982 if (*debug
& DEBUG_L2_RECV
)
1983 printk(KERN_DEBUG
"%s: prim(%x) id(%x) internal msg\n",
1984 mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
);
1988 ret
= ph_data_indication(l2
, hh
, skb
);
1991 ret
= ph_data_confirm(l2
, hh
, skb
);
1993 case PH_ACTIVATE_IND
:
1994 test_and_set_bit(FLG_L1_ACTIV
, &l2
->flag
);
1995 l2up_create(l2
, MPH_ACTIVATE_IND
, 0, NULL
);
1996 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1997 ret
= mISDN_FsmEvent(&l2
->l2m
,
1998 EV_L2_DL_ESTABLISH_REQ
, skb
);
2000 case PH_DEACTIVATE_IND
:
2001 test_and_clear_bit(FLG_L1_ACTIV
, &l2
->flag
);
2002 l2up_create(l2
, MPH_DEACTIVATE_IND
, 0, NULL
);
2003 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L1_DEACTIVATE
, skb
);
2005 case MPH_INFORMATION_IND
:
2008 ret
= l2
->up
->send(l2
->up
, skb
);
2011 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_DATA
, skb
);
2013 case DL_UNITDATA_REQ
:
2014 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_UNITDATA
, skb
);
2016 case DL_ESTABLISH_REQ
:
2017 if (test_bit(FLG_LAPB
, &l2
->flag
))
2018 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
2019 if (test_bit(FLG_L1_ACTIV
, &l2
->flag
)) {
2020 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
2021 test_bit(FLG_ORIG
, &l2
->flag
))
2022 ret
= mISDN_FsmEvent(&l2
->l2m
,
2023 EV_L2_DL_ESTABLISH_REQ
, skb
);
2025 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
2026 test_bit(FLG_ORIG
, &l2
->flag
)) {
2027 test_and_set_bit(FLG_ESTAB_PEND
,
2030 ret
= l2down(l2
, PH_ACTIVATE_REQ
, l2_newid(l2
),
2034 case DL_RELEASE_REQ
:
2035 if (test_bit(FLG_LAPB
, &l2
->flag
))
2036 l2down_create(l2
, PH_DEACTIVATE_REQ
,
2037 l2_newid(l2
), 0, NULL
);
2038 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_RELEASE_REQ
,
2041 case DL_TIMER200_IND
:
2042 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T200I
, NULL
);
2044 case DL_TIMER203_IND
:
2045 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T203I
, NULL
);
2048 if (*debug
& DEBUG_L2
)
2049 l2m_debug(&l2
->l2m
, "l2 unknown pr %04x",
2060 tei_l2(struct layer2
*l2
, u_int cmd
, u_long arg
)
2064 if (*debug
& DEBUG_L2_TEI
)
2065 printk(KERN_DEBUG
"%s: cmd(%x) in %s\n",
2066 mISDNDevName4ch(&l2
->ch
), cmd
, __func__
);
2068 case (MDL_ASSIGN_REQ
):
2069 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ASSIGN
, (void *)arg
);
2071 case (MDL_REMOVE_REQ
):
2072 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_REMOVE
, NULL
);
2074 case (MDL_ERROR_IND
):
2075 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2077 case (MDL_ERROR_RSP
):
2078 /* ETS 300-125 5.3.2.1 Test: TC13010 */
2079 printk(KERN_NOTICE
"%s: MDL_ERROR|REQ (tei_l2)\n",
2080 mISDNDevName4ch(&l2
->ch
));
2081 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2088 release_l2(struct layer2
*l2
)
2090 mISDN_FsmDelTimer(&l2
->t200
, 21);
2091 mISDN_FsmDelTimer(&l2
->t203
, 16);
2092 skb_queue_purge(&l2
->i_queue
);
2093 skb_queue_purge(&l2
->ui_queue
);
2094 skb_queue_purge(&l2
->down_queue
);
2096 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2099 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
,
2100 CLOSE_CHANNEL
, NULL
);
2106 l2_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
2108 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
2111 if (*debug
& DEBUG_L2_CTRL
)
2112 printk(KERN_DEBUG
"%s: %s cmd(%x)\n",
2113 mISDNDevName4ch(ch
), __func__
, cmd
);
2117 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2118 set_channel_address(&l2
->ch
, l2
->sapi
, l2
->tei
);
2119 info
= DL_INFO_L2_CONNECT
;
2120 l2up_create(l2
, DL_INFORMATION_IND
,
2121 sizeof(info
), &info
);
2126 l2
->ch
.peer
->ctrl(l2
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
2134 create_l2(struct mISDNchannel
*ch
, u_int protocol
, u_long options
, int tei
,
2138 struct channel_req rq
;
2140 l2
= kzalloc(sizeof(struct layer2
), GFP_KERNEL
);
2142 printk(KERN_ERR
"kzalloc layer2 failed\n");
2146 l2
->down_id
= MISDN_ID_NONE
;
2149 l2
->ch
.send
= l2_send
;
2150 l2
->ch
.ctrl
= l2_ctrl
;
2152 case ISDN_P_LAPD_NT
:
2153 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2154 test_and_set_bit(FLG_LAPD_NET
, &l2
->flag
);
2155 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2157 l2
->maxlen
= MAX_DFRAME_LEN
;
2158 if (test_bit(OPTION_L2_PMX
, &options
))
2162 if (test_bit(OPTION_L2_PTP
, &options
))
2163 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2164 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2165 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2170 if (test_bit(OPTION_L2_PMX
, &options
))
2171 rq
.protocol
= ISDN_P_NT_E1
;
2173 rq
.protocol
= ISDN_P_NT_S0
;
2175 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2177 case ISDN_P_LAPD_TE
:
2178 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2179 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2180 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
2182 l2
->maxlen
= MAX_DFRAME_LEN
;
2183 if (test_bit(OPTION_L2_PMX
, &options
))
2187 if (test_bit(OPTION_L2_PTP
, &options
))
2188 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2189 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2190 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2195 if (test_bit(OPTION_L2_PMX
, &options
))
2196 rq
.protocol
= ISDN_P_TE_E1
;
2198 rq
.protocol
= ISDN_P_TE_S0
;
2200 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2202 case ISDN_P_B_X75SLP
:
2203 test_and_set_bit(FLG_LAPB
, &l2
->flag
);
2205 l2
->maxlen
= MAX_DATA_SIZE
;
2213 printk(KERN_ERR
"layer2 create failed prt %x\n",
2218 skb_queue_head_init(&l2
->i_queue
);
2219 skb_queue_head_init(&l2
->ui_queue
);
2220 skb_queue_head_init(&l2
->down_queue
);
2221 skb_queue_head_init(&l2
->tmp_queue
);
2223 l2
->l2m
.fsm
= &l2fsm
;
2224 if (test_bit(FLG_LAPB
, &l2
->flag
) ||
2225 test_bit(FLG_FIXED_TEI
, &l2
->flag
) ||
2226 test_bit(FLG_LAPD_NET
, &l2
->flag
))
2227 l2
->l2m
.state
= ST_L2_4
;
2229 l2
->l2m
.state
= ST_L2_1
;
2230 l2
->l2m
.debug
= *debug
;
2231 l2
->l2m
.userdata
= l2
;
2232 l2
->l2m
.userint
= 0;
2233 l2
->l2m
.printdebug
= l2m_debug
;
2235 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t200
);
2236 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t203
);
2241 x75create(struct channel_req
*crq
)
2245 if (crq
->protocol
!= ISDN_P_B_X75SLP
)
2246 return -EPROTONOSUPPORT
;
2247 l2
= create_l2(crq
->ch
, crq
->protocol
, 0, 0, 0);
2251 crq
->protocol
= ISDN_P_B_HDLC
;
2255 static struct Bprotocol X75SLP
= {
2256 .Bprotocols
= (1 << (ISDN_P_B_X75SLP
& ISDN_P_B_MASK
)),
2262 Isdnl2_Init(u_int
*deb
)
2265 mISDN_register_Bprotocol(&X75SLP
);
2266 l2fsm
.state_count
= L2_STATE_COUNT
;
2267 l2fsm
.event_count
= L2_EVENT_COUNT
;
2268 l2fsm
.strEvent
= strL2Event
;
2269 l2fsm
.strState
= strL2State
;
2270 mISDN_FsmNew(&l2fsm
, L2FnList
, ARRAY_SIZE(L2FnList
));
2276 Isdnl2_cleanup(void)
2278 mISDN_unregister_Bprotocol(&X75SLP
);
2280 mISDN_FsmFree(&l2fsm
);