1 /* $Id: isdnl3.c,v 2.22.2.3 2004/01/13 14:31:25 keil Exp $
4 * based on the teles driver from Jan den Ouden
5 * Copyright by Karsten Keil <keil@isdn4linux.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
10 * For changes and modifications please read
11 * Documentation/isdn/HiSax.cert
13 * Thanks to Jan den Ouden
18 #include <linux/init.h>
22 const char *l3_revision
= "$Revision: 2.22.2.3 $";
24 static struct Fsm l3fsm
;
34 #define L3_STATE_COUNT (ST_L3_LC_ESTAB+1)
36 static char *strL3State
[] =
39 "ST_L3_LC_ESTAB_WAIT",
55 #define L3_EVENT_COUNT (EV_TIMEOUT+1)
57 static char *strL3Event
[] =
69 l3m_debug(struct FsmInst
*fi
, char *fmt
, ...)
72 struct PStack
*st
= fi
->userdata
;
75 VHiSax_putstatus(st
->l1
.hardware
, st
->l3
.debug_id
, fmt
, args
);
80 findie(u_char
* p
, int size
, u_char ie
, int wanted_set
)
82 int l
, codeset
, maincodeset
;
83 u_char
*pend
= p
+ size
;
85 /* skip protocol discriminator, callref and message type */
92 /* while there are bytes left... */
94 if ((*p
& 0xf0) == 0x90) {
97 maincodeset
= codeset
;
102 if (codeset
== wanted_set
) {
104 { /* improved length check (Werner Cornelius) */
107 if (*(p
+1) > (pend
- (p
+2)))
118 codeset
= maincodeset
;
125 getcallref(u_char
* p
)
129 p
++; /* prot discr */
130 if (*p
& 0xfe) /* wrong callref BRI only 1 octet*/
132 l
= 0xf & *p
++; /* callref length */
133 if (!l
) /* dummy CallRef */
139 static int OrigCallRef
= 0;
144 if (OrigCallRef
== 127)
148 return (OrigCallRef
);
152 newl3state(struct l3_process
*pc
, int state
)
154 if (pc
->debug
& L3_DEB_STATE
)
155 l3_debug(pc
->st
, "newstate cr %d %d --> %d",
162 L3ExpireTimer(struct L3Timer
*t
)
164 t
->pc
->st
->lli
.l4l3(t
->pc
->st
, t
->event
, t
->pc
);
168 L3InitTimer(struct l3_process
*pc
, struct L3Timer
*t
)
171 t
->tl
.function
= (void *) L3ExpireTimer
;
172 t
->tl
.data
= (long) t
;
177 L3DelTimer(struct L3Timer
*t
)
183 L3AddTimer(struct L3Timer
*t
,
184 int millisec
, int event
)
186 if (timer_pending(&t
->tl
)) {
187 printk(KERN_WARNING
"L3AddTimer: timer already active!\n");
192 t
->tl
.expires
= jiffies
+ (millisec
* HZ
) / 1000;
198 StopAllL3Timer(struct l3_process
*pc
)
200 L3DelTimer(&pc
->timer
);
204 l3_alloc_skb(int len
)
208 if (!(skb
= alloc_skb(len
+ MAX_HEADER_LEN
, GFP_ATOMIC
))) {
209 printk(KERN_WARNING
"HiSax: No skb for D-channel\n");
212 skb_reserve(skb
, MAX_HEADER_LEN
);
217 no_l3_proto(struct PStack
*st
, int pr
, void *arg
)
219 struct sk_buff
*skb
= arg
;
221 HiSax_putstatus(st
->l1
.hardware
, "L3", "no D protocol");
228 no_l3_proto_spec(struct PStack
*st
, isdn_ctrl
*ic
)
230 printk(KERN_WARNING
"HiSax: no specific protocol handler for proto %lu\n",ic
->arg
& 0xFF);
234 #ifdef CONFIG_HISAX_EURO
235 extern void setstack_dss1(struct PStack
*st
);
238 #ifdef CONFIG_HISAX_NI1
239 extern void setstack_ni1(struct PStack
*st
);
242 #ifdef CONFIG_HISAX_1TR6
243 extern void setstack_1tr6(struct PStack
*st
);
247 *getl3proc(struct PStack
*st
, int cr
)
249 struct l3_process
*p
= st
->l3
.proc
;
252 if (p
->callref
== cr
)
260 *new_l3_process(struct PStack
*st
, int cr
)
262 struct l3_process
*p
, *np
;
264 if (!(p
= kmalloc(sizeof(struct l3_process
), GFP_ATOMIC
))) {
265 printk(KERN_ERR
"HiSax can't get memory for cr %d\n", cr
);
277 p
->debug
= st
->l3
.debug
;
282 p
->N303
= st
->l3
.N303
;
283 L3InitTimer(p
, &p
->timer
);
288 release_l3_process(struct l3_process
*p
)
290 struct l3_process
*np
, *pp
= NULL
;
300 else if (!(p
->st
->l3
.proc
= np
->next
) &&
301 !test_bit(FLG_PTP
, &p
->st
->l2
.flag
)) {
303 l3_debug(p
->st
, "release_l3_process: last process");
304 if (skb_queue_empty(&p
->st
->l3
.squeue
)) {
306 l3_debug(p
->st
, "release_l3_process: release link");
307 if (p
->st
->protocol
!= ISDN_PTYPE_NI1
)
308 FsmEvent(&p
->st
->l3
.l3m
, EV_RELEASE_REQ
, NULL
);
310 FsmEvent(&p
->st
->l3
.l3m
, EV_RELEASE_IND
, NULL
);
313 l3_debug(p
->st
, "release_l3_process: not release link");
322 printk(KERN_ERR
"HiSax internal L3 error CR(%d) not in list\n", p
->callref
);
323 l3_debug(p
->st
, "HiSax internal L3 error CR(%d) not in list", p
->callref
);
327 l3ml3p(struct PStack
*st
, int pr
)
329 struct l3_process
*p
= st
->l3
.proc
;
330 struct l3_process
*np
;
333 /* p might be kfreed under us, so we need to save where we want to go on */
335 st
->l3
.l3ml3(st
, pr
, p
);
341 setstack_l3dc(struct PStack
*st
, struct Channel
*chanp
)
346 st
->l3
.global
= NULL
;
347 skb_queue_head_init(&st
->l3
.squeue
);
348 st
->l3
.l3m
.fsm
= &l3fsm
;
349 st
->l3
.l3m
.state
= ST_L3_LC_REL
;
350 st
->l3
.l3m
.debug
= 1;
351 st
->l3
.l3m
.userdata
= st
;
352 st
->l3
.l3m
.userint
= 0;
353 st
->l3
.l3m
.printdebug
= l3m_debug
;
354 FsmInitTimer(&st
->l3
.l3m
, &st
->l3
.l3m_timer
);
355 strcpy(st
->l3
.debug_id
, "L3DC ");
356 st
->lli
.l4l3_proto
= no_l3_proto_spec
;
358 #ifdef CONFIG_HISAX_EURO
359 if (st
->protocol
== ISDN_PTYPE_EURO
) {
363 #ifdef CONFIG_HISAX_NI1
364 if (st
->protocol
== ISDN_PTYPE_NI1
) {
368 #ifdef CONFIG_HISAX_1TR6
369 if (st
->protocol
== ISDN_PTYPE_1TR6
) {
373 if (st
->protocol
== ISDN_PTYPE_LEASED
) {
374 st
->lli
.l4l3
= no_l3_proto
;
375 st
->l2
.l2l3
= no_l3_proto
;
376 st
->l3
.l3ml3
= no_l3_proto
;
377 printk(KERN_INFO
"HiSax: Leased line mode\n");
379 st
->lli
.l4l3
= no_l3_proto
;
380 st
->l2
.l2l3
= no_l3_proto
;
381 st
->l3
.l3ml3
= no_l3_proto
;
382 sprintf(tmp
, "protocol %s not supported",
383 (st
->protocol
== ISDN_PTYPE_1TR6
) ? "1tr6" :
384 (st
->protocol
== ISDN_PTYPE_EURO
) ? "euro" :
385 (st
->protocol
== ISDN_PTYPE_NI1
) ? "ni1" :
387 printk(KERN_WARNING
"HiSax: %s\n", tmp
);
393 isdnl3_trans(struct PStack
*st
, int pr
, void *arg
) {
394 st
->l3
.l3l2(st
, pr
, arg
);
398 releasestack_isdnl3(struct PStack
*st
)
401 release_l3_process(st
->l3
.proc
);
403 StopAllL3Timer(st
->l3
.global
);
404 kfree(st
->l3
.global
);
405 st
->l3
.global
= NULL
;
407 FsmDelTimer(&st
->l3
.l3m_timer
, 54);
408 skb_queue_purge(&st
->l3
.squeue
);
412 setstack_l3bc(struct PStack
*st
, struct Channel
*chanp
)
416 st
->l3
.global
= NULL
;
417 skb_queue_head_init(&st
->l3
.squeue
);
418 st
->l3
.l3m
.fsm
= &l3fsm
;
419 st
->l3
.l3m
.state
= ST_L3_LC_REL
;
420 st
->l3
.l3m
.debug
= 1;
421 st
->l3
.l3m
.userdata
= st
;
422 st
->l3
.l3m
.userint
= 0;
423 st
->l3
.l3m
.printdebug
= l3m_debug
;
424 strcpy(st
->l3
.debug_id
, "L3BC ");
425 st
->lli
.l4l3
= isdnl3_trans
;
428 #define DREL_TIMER_VALUE 40000
431 lc_activate(struct FsmInst
*fi
, int event
, void *arg
)
433 struct PStack
*st
= fi
->userdata
;
435 FsmChangeState(fi
, ST_L3_LC_ESTAB_WAIT
);
436 st
->l3
.l3l2(st
, DL_ESTABLISH
| REQUEST
, NULL
);
440 lc_connect(struct FsmInst
*fi
, int event
, void *arg
)
442 struct PStack
*st
= fi
->userdata
;
443 struct sk_buff
*skb
= arg
;
446 FsmChangeState(fi
, ST_L3_LC_ESTAB
);
447 while ((skb
= skb_dequeue(&st
->l3
.squeue
))) {
448 st
->l3
.l3l2(st
, DL_DATA
| REQUEST
, skb
);
451 if ((!st
->l3
.proc
) && dequeued
) {
453 l3_debug(st
, "lc_connect: release link");
454 FsmEvent(&st
->l3
.l3m
, EV_RELEASE_REQ
, NULL
);
456 l3ml3p(st
, DL_ESTABLISH
| INDICATION
);
460 lc_connected(struct FsmInst
*fi
, int event
, void *arg
)
462 struct PStack
*st
= fi
->userdata
;
463 struct sk_buff
*skb
= arg
;
466 FsmDelTimer(&st
->l3
.l3m_timer
, 51);
467 FsmChangeState(fi
, ST_L3_LC_ESTAB
);
468 while ((skb
= skb_dequeue(&st
->l3
.squeue
))) {
469 st
->l3
.l3l2(st
, DL_DATA
| REQUEST
, skb
);
472 if ((!st
->l3
.proc
) && dequeued
) {
474 l3_debug(st
, "lc_connected: release link");
475 FsmEvent(&st
->l3
.l3m
, EV_RELEASE_REQ
, NULL
);
477 l3ml3p(st
, DL_ESTABLISH
| CONFIRM
);
481 lc_start_delay(struct FsmInst
*fi
, int event
, void *arg
)
483 struct PStack
*st
= fi
->userdata
;
485 FsmChangeState(fi
, ST_L3_LC_REL_DELAY
);
486 FsmAddTimer(&st
->l3
.l3m_timer
, DREL_TIMER_VALUE
, EV_TIMEOUT
, NULL
, 50);
490 lc_start_delay_check(struct FsmInst
*fi
, int event
, void *arg
)
491 /* 20/09/00 - GE timer not user for NI-1 as layer 2 should stay up */
493 struct PStack
*st
= fi
->userdata
;
495 FsmChangeState(fi
, ST_L3_LC_REL_DELAY
);
496 /* 19/09/00 - GE timer not user for NI-1 */
497 if (st
->protocol
!= ISDN_PTYPE_NI1
)
498 FsmAddTimer(&st
->l3
.l3m_timer
, DREL_TIMER_VALUE
, EV_TIMEOUT
, NULL
, 50);
502 lc_release_req(struct FsmInst
*fi
, int event
, void *arg
)
504 struct PStack
*st
= fi
->userdata
;
506 if (test_bit(FLG_L2BLOCK
, &st
->l2
.flag
)) {
508 l3_debug(st
, "lc_release_req: l2 blocked");
509 /* restart release timer */
510 FsmAddTimer(&st
->l3
.l3m_timer
, DREL_TIMER_VALUE
, EV_TIMEOUT
, NULL
, 51);
512 FsmChangeState(fi
, ST_L3_LC_REL_WAIT
);
513 st
->l3
.l3l2(st
, DL_RELEASE
| REQUEST
, NULL
);
518 lc_release_ind(struct FsmInst
*fi
, int event
, void *arg
)
520 struct PStack
*st
= fi
->userdata
;
522 FsmDelTimer(&st
->l3
.l3m_timer
, 52);
523 FsmChangeState(fi
, ST_L3_LC_REL
);
524 skb_queue_purge(&st
->l3
.squeue
);
525 l3ml3p(st
, DL_RELEASE
| INDICATION
);
529 lc_release_cnf(struct FsmInst
*fi
, int event
, void *arg
)
531 struct PStack
*st
= fi
->userdata
;
533 FsmChangeState(fi
, ST_L3_LC_REL
);
534 skb_queue_purge(&st
->l3
.squeue
);
535 l3ml3p(st
, DL_RELEASE
| CONFIRM
);
540 static struct FsmNode L3FnList
[] __initdata
=
542 {ST_L3_LC_REL
, EV_ESTABLISH_REQ
, lc_activate
},
543 {ST_L3_LC_REL
, EV_ESTABLISH_IND
, lc_connect
},
544 {ST_L3_LC_REL
, EV_ESTABLISH_CNF
, lc_connect
},
545 {ST_L3_LC_ESTAB_WAIT
, EV_ESTABLISH_CNF
, lc_connected
},
546 {ST_L3_LC_ESTAB_WAIT
, EV_RELEASE_REQ
, lc_start_delay
},
547 {ST_L3_LC_ESTAB_WAIT
, EV_RELEASE_IND
, lc_release_ind
},
548 {ST_L3_LC_ESTAB
, EV_RELEASE_IND
, lc_release_ind
},
549 {ST_L3_LC_ESTAB
, EV_RELEASE_REQ
, lc_start_delay_check
},
550 {ST_L3_LC_REL_DELAY
, EV_RELEASE_IND
, lc_release_ind
},
551 {ST_L3_LC_REL_DELAY
, EV_ESTABLISH_REQ
, lc_connected
},
552 {ST_L3_LC_REL_DELAY
, EV_TIMEOUT
, lc_release_req
},
553 {ST_L3_LC_REL_WAIT
, EV_RELEASE_CNF
, lc_release_cnf
},
554 {ST_L3_LC_REL_WAIT
, EV_ESTABLISH_REQ
, lc_activate
},
558 #define L3_FN_COUNT (sizeof(L3FnList)/sizeof(struct FsmNode))
561 l3_msg(struct PStack
*st
, int pr
, void *arg
)
564 case (DL_DATA
| REQUEST
):
565 if (st
->l3
.l3m
.state
== ST_L3_LC_ESTAB
) {
566 st
->l3
.l3l2(st
, pr
, arg
);
568 struct sk_buff
*skb
= arg
;
570 skb_queue_tail(&st
->l3
.squeue
, skb
);
571 FsmEvent(&st
->l3
.l3m
, EV_ESTABLISH_REQ
, NULL
);
574 case (DL_ESTABLISH
| REQUEST
):
575 FsmEvent(&st
->l3
.l3m
, EV_ESTABLISH_REQ
, NULL
);
577 case (DL_ESTABLISH
| CONFIRM
):
578 FsmEvent(&st
->l3
.l3m
, EV_ESTABLISH_CNF
, NULL
);
580 case (DL_ESTABLISH
| INDICATION
):
581 FsmEvent(&st
->l3
.l3m
, EV_ESTABLISH_IND
, NULL
);
583 case (DL_RELEASE
| INDICATION
):
584 FsmEvent(&st
->l3
.l3m
, EV_RELEASE_IND
, NULL
);
586 case (DL_RELEASE
| CONFIRM
):
587 FsmEvent(&st
->l3
.l3m
, EV_RELEASE_CNF
, NULL
);
589 case (DL_RELEASE
| REQUEST
):
590 FsmEvent(&st
->l3
.l3m
, EV_RELEASE_REQ
, NULL
);
598 l3fsm
.state_count
= L3_STATE_COUNT
;
599 l3fsm
.event_count
= L3_EVENT_COUNT
;
600 l3fsm
.strEvent
= strL3Event
;
601 l3fsm
.strState
= strL3State
;
602 return FsmNew(&l3fsm
, L3FnList
, L3_FN_COUNT
);