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 skb_put_data(skb
, 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 skb_put_data(skb
, 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 skb_put_data(skb
, 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 skb_put_data(skb
, 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
;
1480 u_char header
[MAX_L2HEADER_LEN
];
1486 skb
= skb_dequeue(&l2
->i_queue
);
1489 i
= sethdraddr(l2
, header
, CMD
);
1490 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1491 header
[i
++] = l2
->vs
<< 1;
1492 header
[i
++] = l2
->vr
<< 1;
1494 header
[i
++] = (l2
->vr
<< 5) | (l2
->vs
<< 1);
1495 nskb
= skb_realloc_headroom(skb
, i
);
1497 printk(KERN_WARNING
"%s: no headroom(%d) copy for IFrame\n",
1498 mISDNDevName4ch(&l2
->ch
), i
);
1499 skb_queue_head(&l2
->i_queue
, skb
);
1502 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1503 p1
= (l2
->vs
- l2
->va
) % 128;
1504 l2
->vs
= (l2
->vs
+ 1) % 128;
1506 p1
= (l2
->vs
- l2
->va
) % 8;
1507 l2
->vs
= (l2
->vs
+ 1) % 8;
1509 p1
= (p1
+ l2
->sow
) % l2
->window
;
1510 if (l2
->windowar
[p1
]) {
1511 printk(KERN_WARNING
"%s: l2 try overwrite ack queue entry %d\n",
1512 mISDNDevName4ch(&l2
->ch
), p1
);
1513 dev_kfree_skb(l2
->windowar
[p1
]);
1515 l2
->windowar
[p1
] = skb
;
1516 memcpy(skb_push(nskb
, i
), header
, i
);
1517 l2down(l2
, PH_DATA_REQ
, l2_newid(l2
), nskb
);
1518 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1519 if (!test_and_set_bit(FLG_T200_RUN
, &l2
->flag
)) {
1520 mISDN_FsmDelTimer(&l2
->t203
, 13);
1521 mISDN_FsmAddTimer(&l2
->t200
, l2
->T200
, EV_L2_T200
, NULL
, 11);
1526 l2_st8_got_super(struct FsmInst
*fi
, int event
, void *arg
)
1528 struct layer2
*l2
= fi
->userdata
;
1529 struct sk_buff
*skb
= arg
;
1530 int PollFlag
, rsp
, rnr
= 0;
1533 rsp
= *skb
->data
& 0x2;
1534 if (test_bit(FLG_ORIG
, &l2
->flag
))
1537 skb_pull(skb
, l2addrsize(l2
));
1539 if (IsRNR(skb
->data
, l2
)) {
1543 clear_peer_busy(l2
);
1545 if (test_bit(FLG_MOD128
, &l2
->flag
)) {
1546 PollFlag
= (skb
->data
[1] & 0x1) == 0x1;
1547 nr
= skb
->data
[1] >> 1;
1549 PollFlag
= (skb
->data
[0] & 0x10);
1550 nr
= (skb
->data
[0] >> 5) & 0x7;
1553 if (rsp
&& PollFlag
) {
1554 if (legalnr(l2
, nr
)) {
1556 restart_t200(l2
, 15);
1559 mISDN_FsmAddTimer(&l2
->t203
, l2
->T203
,
1560 EV_L2_T203
, NULL
, 5);
1563 invoke_retransmission(l2
, nr
);
1564 mISDN_FsmChangeState(fi
, ST_L2_7
);
1565 if (skb_queue_len(&l2
->i_queue
) && cansend(l2
))
1566 mISDN_FsmEvent(fi
, EV_L2_ACK_PULL
, NULL
);
1568 nrerrorrecovery(fi
);
1570 if (!rsp
&& PollFlag
)
1571 enquiry_response(l2
);
1572 if (legalnr(l2
, nr
))
1575 nrerrorrecovery(fi
);
1580 l2_got_FRMR(struct FsmInst
*fi
, int event
, void *arg
)
1582 struct layer2
*l2
= fi
->userdata
;
1583 struct sk_buff
*skb
= arg
;
1585 skb_pull(skb
, l2addrsize(l2
) + 1);
1587 if (!(skb
->data
[0] & 1) || ((skb
->data
[0] & 3) == 1) || /* I or S */
1588 (IsUA(skb
->data
) && (fi
->state
== ST_L2_7
))) {
1589 l2mgr(l2
, MDL_ERROR_IND
, (void *) 'K');
1591 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1597 l2_st24_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 mISDN_FsmChangeState(fi
, ST_L2_1
);
1607 l2_st3_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1609 struct layer2
*l2
= fi
->userdata
;
1611 skb_queue_purge(&l2
->ui_queue
);
1612 l2
->tei
= GROUP_TEI
;
1613 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1614 mISDN_FsmChangeState(fi
, ST_L2_1
);
1618 l2_st5_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1620 struct layer2
*l2
= fi
->userdata
;
1622 skb_queue_purge(&l2
->i_queue
);
1623 skb_queue_purge(&l2
->ui_queue
);
1625 l2
->tei
= GROUP_TEI
;
1627 st5_dl_release_l2l3(l2
);
1628 mISDN_FsmChangeState(fi
, ST_L2_1
);
1632 l2_st6_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1634 struct layer2
*l2
= fi
->userdata
;
1636 skb_queue_purge(&l2
->ui_queue
);
1637 l2
->tei
= GROUP_TEI
;
1639 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1640 mISDN_FsmChangeState(fi
, ST_L2_1
);
1644 l2_tei_remove(struct FsmInst
*fi
, int event
, void *arg
)
1646 struct layer2
*l2
= fi
->userdata
;
1648 skb_queue_purge(&l2
->i_queue
);
1649 skb_queue_purge(&l2
->ui_queue
);
1651 l2
->tei
= GROUP_TEI
;
1653 mISDN_FsmDelTimer(&l2
->t203
, 19);
1654 l2up_create(l2
, DL_RELEASE_IND
, 0, NULL
);
1655 /* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
1656 * MGR_SHORTSTATUS_IND, SSTATUS_L2_RELEASED,
1659 mISDN_FsmChangeState(fi
, ST_L2_1
);
1663 l2_st14_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1665 struct layer2
*l2
= fi
->userdata
;
1666 struct sk_buff
*skb
= arg
;
1668 skb_queue_purge(&l2
->i_queue
);
1669 skb_queue_purge(&l2
->ui_queue
);
1670 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1671 l2up(l2
, DL_RELEASE_IND
, skb
);
1677 l2_st5_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
);
1686 st5_dl_release_l2l3(l2
);
1687 mISDN_FsmChangeState(fi
, ST_L2_4
);
1689 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1694 l2_st6_persistent_da(struct FsmInst
*fi
, int event
, void *arg
)
1696 struct layer2
*l2
= fi
->userdata
;
1697 struct sk_buff
*skb
= arg
;
1699 skb_queue_purge(&l2
->ui_queue
);
1701 l2up(l2
, DL_RELEASE_CNF
, skb
);
1702 mISDN_FsmChangeState(fi
, ST_L2_4
);
1704 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1708 l2_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
->i_queue
);
1714 skb_queue_purge(&l2
->ui_queue
);
1717 mISDN_FsmDelTimer(&l2
->t203
, 19);
1718 l2up(l2
, DL_RELEASE_IND
, skb
);
1719 mISDN_FsmChangeState(fi
, ST_L2_4
);
1721 l2_tei(l2
, MDL_STATUS_DOWN_IND
, 0);
1725 l2_set_own_busy(struct FsmInst
*fi
, int event
, void *arg
)
1727 struct layer2
*l2
= fi
->userdata
;
1728 struct sk_buff
*skb
= arg
;
1730 if (!test_and_set_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1731 enquiry_cr(l2
, RNR
, RSP
, 0);
1732 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1739 l2_clear_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_clear_bit(FLG_OWN_BUSY
, &l2
->flag
)) {
1745 enquiry_cr(l2
, RR
, RSP
, 0);
1746 test_and_clear_bit(FLG_ACK_PEND
, &l2
->flag
);
1753 l2_frame_error(struct FsmInst
*fi
, int event
, void *arg
)
1755 struct layer2
*l2
= fi
->userdata
;
1757 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1761 l2_frame_error_reest(struct FsmInst
*fi
, int event
, void *arg
)
1763 struct layer2
*l2
= fi
->userdata
;
1765 l2mgr(l2
, MDL_ERROR_IND
, arg
);
1767 test_and_clear_bit(FLG_L3_INIT
, &l2
->flag
);
1770 static struct FsmNode L2FnList
[] =
1772 {ST_L2_1
, EV_L2_DL_ESTABLISH_REQ
, l2_mdl_assign
},
1773 {ST_L2_2
, EV_L2_DL_ESTABLISH_REQ
, l2_go_st3
},
1774 {ST_L2_4
, EV_L2_DL_ESTABLISH_REQ
, l2_establish
},
1775 {ST_L2_5
, EV_L2_DL_ESTABLISH_REQ
, l2_discard_i_setl3
},
1776 {ST_L2_7
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1777 {ST_L2_8
, EV_L2_DL_ESTABLISH_REQ
, l2_l3_reestablish
},
1778 {ST_L2_4
, EV_L2_DL_RELEASE_REQ
, l2_release
},
1779 {ST_L2_5
, EV_L2_DL_RELEASE_REQ
, l2_pend_rel
},
1780 {ST_L2_7
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1781 {ST_L2_8
, EV_L2_DL_RELEASE_REQ
, l2_disconnect
},
1782 {ST_L2_5
, EV_L2_DL_DATA
, l2_feed_i_if_reest
},
1783 {ST_L2_7
, EV_L2_DL_DATA
, l2_feed_i_pull
},
1784 {ST_L2_8
, EV_L2_DL_DATA
, l2_feed_iqueue
},
1785 {ST_L2_1
, EV_L2_DL_UNITDATA
, l2_queue_ui_assign
},
1786 {ST_L2_2
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1787 {ST_L2_3
, EV_L2_DL_UNITDATA
, l2_queue_ui
},
1788 {ST_L2_4
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1789 {ST_L2_5
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1790 {ST_L2_6
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1791 {ST_L2_7
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1792 {ST_L2_8
, EV_L2_DL_UNITDATA
, l2_send_ui
},
1793 {ST_L2_1
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1794 {ST_L2_2
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1795 {ST_L2_3
, EV_L2_MDL_ASSIGN
, l2_got_tei
},
1796 {ST_L2_2
, EV_L2_MDL_ERROR
, l2_st24_tei_remove
},
1797 {ST_L2_3
, EV_L2_MDL_ERROR
, l2_st3_tei_remove
},
1798 {ST_L2_4
, EV_L2_MDL_REMOVE
, l2_st24_tei_remove
},
1799 {ST_L2_5
, EV_L2_MDL_REMOVE
, l2_st5_tei_remove
},
1800 {ST_L2_6
, EV_L2_MDL_REMOVE
, l2_st6_tei_remove
},
1801 {ST_L2_7
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1802 {ST_L2_8
, EV_L2_MDL_REMOVE
, l2_tei_remove
},
1803 {ST_L2_4
, EV_L2_SABME
, l2_start_multi
},
1804 {ST_L2_5
, EV_L2_SABME
, l2_send_UA
},
1805 {ST_L2_6
, EV_L2_SABME
, l2_send_DM
},
1806 {ST_L2_7
, EV_L2_SABME
, l2_restart_multi
},
1807 {ST_L2_8
, EV_L2_SABME
, l2_restart_multi
},
1808 {ST_L2_4
, EV_L2_DISC
, l2_send_DM
},
1809 {ST_L2_5
, EV_L2_DISC
, l2_send_DM
},
1810 {ST_L2_6
, EV_L2_DISC
, l2_send_UA
},
1811 {ST_L2_7
, EV_L2_DISC
, l2_stop_multi
},
1812 {ST_L2_8
, EV_L2_DISC
, l2_stop_multi
},
1813 {ST_L2_4
, EV_L2_UA
, l2_mdl_error_ua
},
1814 {ST_L2_5
, EV_L2_UA
, l2_connected
},
1815 {ST_L2_6
, EV_L2_UA
, l2_released
},
1816 {ST_L2_7
, EV_L2_UA
, l2_mdl_error_ua
},
1817 {ST_L2_8
, EV_L2_UA
, l2_mdl_error_ua
},
1818 {ST_L2_4
, EV_L2_DM
, l2_reestablish
},
1819 {ST_L2_5
, EV_L2_DM
, l2_st5_dm_release
},
1820 {ST_L2_6
, EV_L2_DM
, l2_st6_dm_release
},
1821 {ST_L2_7
, EV_L2_DM
, l2_mdl_error_dm
},
1822 {ST_L2_8
, EV_L2_DM
, l2_st8_mdl_error_dm
},
1823 {ST_L2_1
, EV_L2_UI
, l2_got_ui
},
1824 {ST_L2_2
, EV_L2_UI
, l2_got_ui
},
1825 {ST_L2_3
, EV_L2_UI
, l2_got_ui
},
1826 {ST_L2_4
, EV_L2_UI
, l2_got_ui
},
1827 {ST_L2_5
, EV_L2_UI
, l2_got_ui
},
1828 {ST_L2_6
, EV_L2_UI
, l2_got_ui
},
1829 {ST_L2_7
, EV_L2_UI
, l2_got_ui
},
1830 {ST_L2_8
, EV_L2_UI
, l2_got_ui
},
1831 {ST_L2_7
, EV_L2_FRMR
, l2_got_FRMR
},
1832 {ST_L2_8
, EV_L2_FRMR
, l2_got_FRMR
},
1833 {ST_L2_7
, EV_L2_SUPER
, l2_st7_got_super
},
1834 {ST_L2_8
, EV_L2_SUPER
, l2_st8_got_super
},
1835 {ST_L2_7
, EV_L2_I
, l2_got_iframe
},
1836 {ST_L2_8
, EV_L2_I
, l2_got_iframe
},
1837 {ST_L2_5
, EV_L2_T200
, l2_timeout
},
1838 {ST_L2_6
, EV_L2_T200
, l2_timeout
},
1839 {ST_L2_7
, EV_L2_T200
, l2_timeout
},
1840 {ST_L2_8
, EV_L2_T200
, l2_timeout
},
1841 {ST_L2_7
, EV_L2_T203
, l2_timeout
},
1842 {ST_L2_5
, EV_L2_T200I
, l2_st5_tout_200
},
1843 {ST_L2_6
, EV_L2_T200I
, l2_st6_tout_200
},
1844 {ST_L2_7
, EV_L2_T200I
, l2_st7_tout_200
},
1845 {ST_L2_8
, EV_L2_T200I
, l2_st8_tout_200
},
1846 {ST_L2_7
, EV_L2_T203I
, l2_st7_tout_203
},
1847 {ST_L2_7
, EV_L2_ACK_PULL
, l2_pull_iqueue
},
1848 {ST_L2_7
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1849 {ST_L2_8
, EV_L2_SET_OWN_BUSY
, l2_set_own_busy
},
1850 {ST_L2_7
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1851 {ST_L2_8
, EV_L2_CLEAR_OWN_BUSY
, l2_clear_own_busy
},
1852 {ST_L2_4
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1853 {ST_L2_5
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1854 {ST_L2_6
, EV_L2_FRAME_ERROR
, l2_frame_error
},
1855 {ST_L2_7
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1856 {ST_L2_8
, EV_L2_FRAME_ERROR
, l2_frame_error_reest
},
1857 {ST_L2_1
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1858 {ST_L2_2
, EV_L1_DEACTIVATE
, l2_st24_tei_remove
},
1859 {ST_L2_3
, EV_L1_DEACTIVATE
, l2_st3_tei_remove
},
1860 {ST_L2_4
, EV_L1_DEACTIVATE
, l2_st14_persistent_da
},
1861 {ST_L2_5
, EV_L1_DEACTIVATE
, l2_st5_persistent_da
},
1862 {ST_L2_6
, EV_L1_DEACTIVATE
, l2_st6_persistent_da
},
1863 {ST_L2_7
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1864 {ST_L2_8
, EV_L1_DEACTIVATE
, l2_persistent_da
},
1868 ph_data_indication(struct layer2
*l2
, struct mISDNhead
*hh
, struct sk_buff
*skb
)
1870 u_char
*datap
= skb
->data
;
1877 if (skb
->len
<= l
) {
1878 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *) 'N');
1881 if (test_bit(FLG_LAPD
, &l2
->flag
)) { /* Maybe not needed */
1884 if ((psapi
& 1) || !(ptei
& 1)) {
1886 "%s l2 D-channel frame wrong EA0/EA1\n",
1887 mISDNDevName4ch(&l2
->ch
));
1892 if (psapi
!= l2
->sapi
) {
1893 /* not our business */
1894 if (*debug
& DEBUG_L2
)
1895 printk(KERN_DEBUG
"%s: sapi %d/%d mismatch\n",
1896 mISDNDevName4ch(&l2
->ch
), psapi
,
1901 if ((ptei
!= l2
->tei
) && (ptei
!= GROUP_TEI
)) {
1902 /* not our business */
1903 if (*debug
& DEBUG_L2
)
1904 printk(KERN_DEBUG
"%s: tei %d/%d mismatch\n",
1905 mISDNDevName4ch(&l2
->ch
), ptei
, l2
->tei
);
1911 if (!(*datap
& 1)) { /* I-Frame */
1912 c
= iframe_error(l2
, skb
);
1914 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_I
, skb
);
1915 } else if (IsSFrame(datap
, l2
)) { /* S-Frame */
1916 c
= super_error(l2
, skb
);
1918 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SUPER
, skb
);
1919 } else if (IsUI(datap
)) {
1920 c
= UI_error(l2
, skb
);
1922 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UI
, skb
);
1923 } else if (IsSABME(datap
, l2
)) {
1924 c
= unnum_error(l2
, skb
, CMD
);
1926 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_SABME
, skb
);
1927 } else if (IsUA(datap
)) {
1928 c
= unnum_error(l2
, skb
, RSP
);
1930 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_UA
, skb
);
1931 } else if (IsDISC(datap
)) {
1932 c
= unnum_error(l2
, skb
, CMD
);
1934 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DISC
, skb
);
1935 } else if (IsDM(datap
)) {
1936 c
= unnum_error(l2
, skb
, RSP
);
1938 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DM
, skb
);
1939 } else if (IsFRMR(datap
)) {
1940 c
= FRMR_error(l2
, skb
);
1942 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRMR
, skb
);
1946 printk(KERN_WARNING
"%s:l2 D-channel frame error %c\n",
1947 mISDNDevName4ch(&l2
->ch
), c
);
1948 mISDN_FsmEvent(&l2
->l2m
, EV_L2_FRAME_ERROR
, (void *)(long)c
);
1954 l2_send(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1956 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
1957 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1960 if (*debug
& DEBUG_L2_RECV
)
1961 printk(KERN_DEBUG
"%s: %s prim(%x) id(%x) sapi(%d) tei(%d)\n",
1962 __func__
, mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
,
1964 if (hh
->prim
== DL_INTERN_MSG
) {
1965 struct mISDNhead
*chh
= hh
+ 1; /* saved copy */
1968 if (*debug
& DEBUG_L2_RECV
)
1969 printk(KERN_DEBUG
"%s: prim(%x) id(%x) internal msg\n",
1970 mISDNDevName4ch(&l2
->ch
), hh
->prim
, hh
->id
);
1974 ret
= ph_data_indication(l2
, hh
, skb
);
1977 ret
= ph_data_confirm(l2
, hh
, skb
);
1979 case PH_ACTIVATE_IND
:
1980 test_and_set_bit(FLG_L1_ACTIV
, &l2
->flag
);
1981 l2up_create(l2
, MPH_ACTIVATE_IND
, 0, NULL
);
1982 if (test_and_clear_bit(FLG_ESTAB_PEND
, &l2
->flag
))
1983 ret
= mISDN_FsmEvent(&l2
->l2m
,
1984 EV_L2_DL_ESTABLISH_REQ
, skb
);
1986 case PH_DEACTIVATE_IND
:
1987 test_and_clear_bit(FLG_L1_ACTIV
, &l2
->flag
);
1988 l2up_create(l2
, MPH_DEACTIVATE_IND
, 0, NULL
);
1989 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L1_DEACTIVATE
, skb
);
1991 case MPH_INFORMATION_IND
:
1994 ret
= l2
->up
->send(l2
->up
, skb
);
1997 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_DATA
, skb
);
1999 case DL_UNITDATA_REQ
:
2000 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_UNITDATA
, skb
);
2002 case DL_ESTABLISH_REQ
:
2003 if (test_bit(FLG_LAPB
, &l2
->flag
))
2004 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
2005 if (test_bit(FLG_L1_ACTIV
, &l2
->flag
)) {
2006 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
2007 test_bit(FLG_ORIG
, &l2
->flag
))
2008 ret
= mISDN_FsmEvent(&l2
->l2m
,
2009 EV_L2_DL_ESTABLISH_REQ
, skb
);
2011 if (test_bit(FLG_LAPD
, &l2
->flag
) ||
2012 test_bit(FLG_ORIG
, &l2
->flag
)) {
2013 test_and_set_bit(FLG_ESTAB_PEND
,
2016 ret
= l2down(l2
, PH_ACTIVATE_REQ
, l2_newid(l2
),
2020 case DL_RELEASE_REQ
:
2021 if (test_bit(FLG_LAPB
, &l2
->flag
))
2022 l2down_create(l2
, PH_DEACTIVATE_REQ
,
2023 l2_newid(l2
), 0, NULL
);
2024 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_DL_RELEASE_REQ
,
2027 case DL_TIMER200_IND
:
2028 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T200I
, NULL
);
2030 case DL_TIMER203_IND
:
2031 mISDN_FsmEvent(&l2
->l2m
, EV_L2_T203I
, NULL
);
2034 if (*debug
& DEBUG_L2
)
2035 l2m_debug(&l2
->l2m
, "l2 unknown pr %04x",
2046 tei_l2(struct layer2
*l2
, u_int cmd
, u_long arg
)
2050 if (*debug
& DEBUG_L2_TEI
)
2051 printk(KERN_DEBUG
"%s: cmd(%x) in %s\n",
2052 mISDNDevName4ch(&l2
->ch
), cmd
, __func__
);
2054 case (MDL_ASSIGN_REQ
):
2055 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ASSIGN
, (void *)arg
);
2057 case (MDL_REMOVE_REQ
):
2058 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_REMOVE
, NULL
);
2060 case (MDL_ERROR_IND
):
2061 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2063 case (MDL_ERROR_RSP
):
2064 /* ETS 300-125 5.3.2.1 Test: TC13010 */
2065 printk(KERN_NOTICE
"%s: MDL_ERROR|REQ (tei_l2)\n",
2066 mISDNDevName4ch(&l2
->ch
));
2067 ret
= mISDN_FsmEvent(&l2
->l2m
, EV_L2_MDL_ERROR
, NULL
);
2074 release_l2(struct layer2
*l2
)
2076 mISDN_FsmDelTimer(&l2
->t200
, 21);
2077 mISDN_FsmDelTimer(&l2
->t203
, 16);
2078 skb_queue_purge(&l2
->i_queue
);
2079 skb_queue_purge(&l2
->ui_queue
);
2080 skb_queue_purge(&l2
->down_queue
);
2082 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2085 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
,
2086 CLOSE_CHANNEL
, NULL
);
2092 l2_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
2094 struct layer2
*l2
= container_of(ch
, struct layer2
, ch
);
2097 if (*debug
& DEBUG_L2_CTRL
)
2098 printk(KERN_DEBUG
"%s: %s cmd(%x)\n",
2099 mISDNDevName4ch(ch
), __func__
, cmd
);
2103 if (test_bit(FLG_LAPD
, &l2
->flag
)) {
2104 set_channel_address(&l2
->ch
, l2
->sapi
, l2
->tei
);
2105 info
= DL_INFO_L2_CONNECT
;
2106 l2up_create(l2
, DL_INFORMATION_IND
,
2107 sizeof(info
), &info
);
2112 l2
->ch
.peer
->ctrl(l2
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
2120 create_l2(struct mISDNchannel
*ch
, u_int protocol
, u_long options
, int tei
,
2124 struct channel_req rq
;
2126 l2
= kzalloc(sizeof(struct layer2
), GFP_KERNEL
);
2128 printk(KERN_ERR
"kzalloc layer2 failed\n");
2132 l2
->down_id
= MISDN_ID_NONE
;
2135 l2
->ch
.send
= l2_send
;
2136 l2
->ch
.ctrl
= l2_ctrl
;
2138 case ISDN_P_LAPD_NT
:
2139 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2140 test_and_set_bit(FLG_LAPD_NET
, &l2
->flag
);
2141 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2143 l2
->maxlen
= MAX_DFRAME_LEN
;
2144 if (test_bit(OPTION_L2_PMX
, &options
))
2148 if (test_bit(OPTION_L2_PTP
, &options
))
2149 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2150 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2151 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2156 if (test_bit(OPTION_L2_PMX
, &options
))
2157 rq
.protocol
= ISDN_P_NT_E1
;
2159 rq
.protocol
= ISDN_P_NT_S0
;
2161 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2163 case ISDN_P_LAPD_TE
:
2164 test_and_set_bit(FLG_LAPD
, &l2
->flag
);
2165 test_and_set_bit(FLG_MOD128
, &l2
->flag
);
2166 test_and_set_bit(FLG_ORIG
, &l2
->flag
);
2168 l2
->maxlen
= MAX_DFRAME_LEN
;
2169 if (test_bit(OPTION_L2_PMX
, &options
))
2173 if (test_bit(OPTION_L2_PTP
, &options
))
2174 test_and_set_bit(FLG_PTP
, &l2
->flag
);
2175 if (test_bit(OPTION_L2_FIXEDTEI
, &options
))
2176 test_and_set_bit(FLG_FIXED_TEI
, &l2
->flag
);
2181 if (test_bit(OPTION_L2_PMX
, &options
))
2182 rq
.protocol
= ISDN_P_TE_E1
;
2184 rq
.protocol
= ISDN_P_TE_S0
;
2186 l2
->ch
.st
->dev
->D
.ctrl(&l2
->ch
.st
->dev
->D
, OPEN_CHANNEL
, &rq
);
2188 case ISDN_P_B_X75SLP
:
2189 test_and_set_bit(FLG_LAPB
, &l2
->flag
);
2191 l2
->maxlen
= MAX_DATA_SIZE
;
2199 printk(KERN_ERR
"layer2 create failed prt %x\n",
2204 skb_queue_head_init(&l2
->i_queue
);
2205 skb_queue_head_init(&l2
->ui_queue
);
2206 skb_queue_head_init(&l2
->down_queue
);
2207 skb_queue_head_init(&l2
->tmp_queue
);
2209 l2
->l2m
.fsm
= &l2fsm
;
2210 if (test_bit(FLG_LAPB
, &l2
->flag
) ||
2211 test_bit(FLG_FIXED_TEI
, &l2
->flag
) ||
2212 test_bit(FLG_LAPD_NET
, &l2
->flag
))
2213 l2
->l2m
.state
= ST_L2_4
;
2215 l2
->l2m
.state
= ST_L2_1
;
2216 l2
->l2m
.debug
= *debug
;
2217 l2
->l2m
.userdata
= l2
;
2218 l2
->l2m
.userint
= 0;
2219 l2
->l2m
.printdebug
= l2m_debug
;
2221 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t200
);
2222 mISDN_FsmInitTimer(&l2
->l2m
, &l2
->t203
);
2227 x75create(struct channel_req
*crq
)
2231 if (crq
->protocol
!= ISDN_P_B_X75SLP
)
2232 return -EPROTONOSUPPORT
;
2233 l2
= create_l2(crq
->ch
, crq
->protocol
, 0, 0, 0);
2237 crq
->protocol
= ISDN_P_B_HDLC
;
2241 static struct Bprotocol X75SLP
= {
2242 .Bprotocols
= (1 << (ISDN_P_B_X75SLP
& ISDN_P_B_MASK
)),
2248 Isdnl2_Init(u_int
*deb
)
2252 mISDN_register_Bprotocol(&X75SLP
);
2253 l2fsm
.state_count
= L2_STATE_COUNT
;
2254 l2fsm
.event_count
= L2_EVENT_COUNT
;
2255 l2fsm
.strEvent
= strL2Event
;
2256 l2fsm
.strState
= strL2State
;
2257 res
= mISDN_FsmNew(&l2fsm
, L2FnList
, ARRAY_SIZE(L2FnList
));
2266 mISDN_FsmFree(&l2fsm
);
2268 mISDN_unregister_Bprotocol(&X75SLP
);
2273 Isdnl2_cleanup(void)
2275 mISDN_unregister_Bprotocol(&X75SLP
);
2277 mISDN_FsmFree(&l2fsm
);