1 /* $Id: callc.c,v 2.59.2.4 2004/02/11 13:21:32 keil Exp $
4 * Copyright by Karsten Keil <keil@isdn4linux.de>
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
9 * For changes and modifications please read
10 * Documentation/isdn/HiSax.cert
12 * based on the teles driver from Jan den Ouden
14 * Thanks to Jan den Ouden
19 #include <linux/module.h>
20 #include <linux/init.h>
22 #include <linux/isdn/capicmd.h>
24 const char *lli_revision
= "$Revision: 2.59.2.4 $";
26 extern struct IsdnCard cards
[];
28 static int init_b_st(struct Channel
*chanp
, int incoming
);
29 static void release_b_st(struct Channel
*chanp
);
31 static struct Fsm callcfsm
;
34 /* experimental REJECT after ALERTING for CALLBACK to beat the 4s delay */
35 #define ALERT_REJECT 0
37 /* Value to delay the sending of the first B-channel paket after CONNECT
38 * here is no value given by ITU, but experience shows that 300 ms will
39 * work on many networks, if you or your other side is behind local exchanges
40 * a greater value may be recommented. If the delay is to short the first paket
41 * will be lost and autodetect on many comercial routers goes wrong !
42 * You can adjust this value on runtime with
43 * hisaxctrl <id> 2 <value>
44 * value is in milliseconds
46 #define DEFAULT_B_DELAY 300
48 /* Flags for remembering action done in lli */
53 * Find card with given driverId
55 static inline struct IsdnCardState
*
56 hisax_findcard(int driverid
)
60 for (i
= 0; i
< nrcards
; i
++)
62 if (cards
[i
].cs
->myid
== driverid
)
64 return (struct IsdnCardState
*) 0;
68 link_debug(struct Channel
*chanp
, int direction
, char *fmt
, ...)
74 sprintf(tmp
, "Ch%d %s ", chanp
->chan
,
75 direction
? "LL->HL" : "HL->LL");
76 VHiSax_putstatus(chanp
->cs
, tmp
, fmt
, args
);
81 ST_NULL
, /* 0 inactive */
82 ST_OUT_DIAL
, /* 1 outgoing, SETUP send; awaiting confirm */
83 ST_IN_WAIT_LL
, /* 2 incoming call received; wait for LL confirm */
84 ST_IN_ALERT_SENT
, /* 3 incoming call received; ALERT send */
85 ST_IN_WAIT_CONN_ACK
, /* 4 incoming CONNECT send; awaiting CONN_ACK */
86 ST_WAIT_BCONN
, /* 5 CONNECT/CONN_ACK received, awaiting b-channel prot. estbl. */
87 ST_ACTIVE
, /* 6 active, b channel prot. established */
88 ST_WAIT_BRELEASE
, /* 7 call clear. (initiator), awaiting b channel prot. rel. */
89 ST_WAIT_BREL_DISC
, /* 8 call clear. (receiver), DISCONNECT req. received */
90 ST_WAIT_DCOMMAND
, /* 9 call clear. (receiver), awaiting DCHANNEL message */
91 ST_WAIT_DRELEASE
, /* 10 DISCONNECT sent, awaiting RELEASE */
92 ST_WAIT_D_REL_CNF
, /* 11 RELEASE sent, awaiting RELEASE confirm */
93 ST_IN_PROCEED_SEND
, /* 12 incoming call, proceeding send */
97 #define STATE_COUNT (ST_IN_PROCEED_SEND + 1)
99 static char *strState
[] =
105 "ST_IN_WAIT_CONN_ACK",
113 "ST_IN_PROCEED_SEND",
118 EV_SETUP_CNF
, /* 1 */
120 EV_DISCONNECT_IND
, /* 3 */
123 EV_LEASED_REL
, /* 6 */
124 EV_SETUP_IND
, /* 7 */
126 EV_SETUP_CMPL_IND
, /* 9 */
128 EV_WRITEBUF
, /* 11 */
134 EV_NOSETUP_RSP
, /* 17 */
135 EV_SETUP_ERR
, /* 18 */
136 EV_CONNECT_ERR
, /* 19 */
142 #define EVENT_COUNT (EV_REDIR + 1)
144 static char *strEvent
[] =
173 HL_LL(struct Channel
*chanp
, int command
)
177 ic
.driver
= chanp
->cs
->myid
;
178 ic
.command
= command
;
179 ic
.arg
= chanp
->chan
;
180 chanp
->cs
->iif
.statcallb(&ic
);
184 lli_deliver_cause(struct Channel
*chanp
)
190 if (chanp
->proc
->para
.cause
== NO_CAUSE
)
192 ic
.driver
= chanp
->cs
->myid
;
193 ic
.command
= ISDN_STAT_CAUSE
;
194 ic
.arg
= chanp
->chan
;
195 if (chanp
->cs
->protocol
== ISDN_PTYPE_EURO
)
196 sprintf(ic
.parm
.num
, "E%02X%02X", chanp
->proc
->para
.loc
& 0x7f,
197 chanp
->proc
->para
.cause
& 0x7f);
199 sprintf(ic
.parm
.num
, "%02X%02X", chanp
->proc
->para
.loc
& 0x7f,
200 chanp
->proc
->para
.cause
& 0x7f);
201 chanp
->cs
->iif
.statcallb(&ic
);
205 lli_close(struct FsmInst
*fi
)
207 struct Channel
*chanp
= fi
->userdata
;
209 FsmChangeState(fi
, ST_NULL
);
211 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_REL
, (void *) (long)chanp
->chan
);
215 lli_leased_in(struct FsmInst
*fi
, int event
, void *arg
)
217 struct Channel
*chanp
= fi
->userdata
;
223 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_SETUP
, (void *) (long)chanp
->chan
);
224 FsmChangeState(fi
, ST_IN_WAIT_LL
);
225 if (chanp
->debug
& 1)
226 link_debug(chanp
, 0, "STAT_ICALL_LEASED");
227 ic
.driver
= chanp
->cs
->myid
;
228 ic
.command
= ((chanp
->chan
< 2) ? ISDN_STAT_ICALL
: ISDN_STAT_ICALLW
);
229 ic
.arg
= chanp
->chan
;
230 ic
.parm
.setup
.si1
= 7;
231 ic
.parm
.setup
.si2
= 0;
232 ic
.parm
.setup
.plan
= 0;
233 ic
.parm
.setup
.screen
= 0;
234 sprintf(ic
.parm
.setup
.eazmsn
,"%d", chanp
->chan
+ 1);
235 sprintf(ic
.parm
.setup
.phone
,"LEASED%d", chanp
->cs
->myid
);
236 ret
= chanp
->cs
->iif
.statcallb(&ic
);
237 if (chanp
->debug
& 1)
238 link_debug(chanp
, 1, "statcallb ret=%d", ret
);
240 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_REL
, (void *) (long)chanp
->chan
);
241 FsmChangeState(fi
, ST_NULL
);
250 lli_init_bchan_out(struct FsmInst
*fi
, int event
, void *arg
)
252 struct Channel
*chanp
= fi
->userdata
;
254 FsmChangeState(fi
, ST_WAIT_BCONN
);
255 if (chanp
->debug
& 1)
256 link_debug(chanp
, 0, "STAT_DCONN");
257 HL_LL(chanp
, ISDN_STAT_DCONN
);
259 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_ESTABLISH
| REQUEST
, NULL
);
263 lli_prep_dialout(struct FsmInst
*fi
, int event
, void *arg
)
265 struct Channel
*chanp
= fi
->userdata
;
267 FsmDelTimer(&chanp
->drel_timer
, 60);
268 FsmDelTimer(&chanp
->dial_timer
, 73);
269 chanp
->l2_active_protocol
= chanp
->l2_protocol
;
271 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_SETUP
, (void *) (long)chanp
->chan
);
273 lli_init_bchan_out(fi
, event
, arg
);
275 FsmChangeState(fi
, ST_OUT_DIAL
);
276 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_SETUP
| REQUEST
, chanp
);
281 lli_resume(struct FsmInst
*fi
, int event
, void *arg
)
283 struct Channel
*chanp
= fi
->userdata
;
285 FsmDelTimer(&chanp
->drel_timer
, 60);
286 FsmDelTimer(&chanp
->dial_timer
, 73);
287 chanp
->l2_active_protocol
= chanp
->l2_protocol
;
289 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_SETUP
, (void *) (long)chanp
->chan
);
291 lli_init_bchan_out(fi
, event
, arg
);
293 FsmChangeState(fi
, ST_OUT_DIAL
);
294 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_RESUME
| REQUEST
, chanp
);
299 lli_go_active(struct FsmInst
*fi
, int event
, void *arg
)
301 struct Channel
*chanp
= fi
->userdata
;
305 FsmChangeState(fi
, ST_ACTIVE
);
306 chanp
->data_open
= !0;
307 if (chanp
->bcs
->conmsg
)
308 strcpy(ic
.parm
.num
, chanp
->bcs
->conmsg
);
311 if (chanp
->debug
& 1)
312 link_debug(chanp
, 0, "STAT_BCONN %s", ic
.parm
.num
);
313 ic
.driver
= chanp
->cs
->myid
;
314 ic
.command
= ISDN_STAT_BCONN
;
315 ic
.arg
= chanp
->chan
;
316 chanp
->cs
->iif
.statcallb(&ic
);
317 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_CONN
, (void *) (long)chanp
->chan
);
328 lli_deliver_call(struct FsmInst
*fi
, int event
, void *arg
)
330 struct Channel
*chanp
= fi
->userdata
;
334 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_SETUP
, (void *) (long)chanp
->chan
);
336 * Report incoming calls only once to linklevel, use CallFlags
337 * which is set to 3 with each broadcast message in isdnl1.c
338 * and resetted if a interface answered the STAT_ICALL.
340 if (1) { /* for only one TEI */
341 FsmChangeState(fi
, ST_IN_WAIT_LL
);
342 if (chanp
->debug
& 1)
343 link_debug(chanp
, 0, (chanp
->chan
< 2) ? "STAT_ICALL" : "STAT_ICALLW");
344 ic
.driver
= chanp
->cs
->myid
;
345 ic
.command
= ((chanp
->chan
< 2) ? ISDN_STAT_ICALL
: ISDN_STAT_ICALLW
);
347 ic
.arg
= chanp
->chan
;
349 * No need to return "unknown" for calls without OAD,
350 * cause that's handled in linklevel now (replaced by '0')
352 memcpy(&ic
.parm
.setup
, &chanp
->proc
->para
.setup
, sizeof(setup_parm
));
353 ret
= chanp
->cs
->iif
.statcallb(&ic
);
354 if (chanp
->debug
& 1)
355 link_debug(chanp
, 1, "statcallb ret=%d", ret
);
358 case 1: /* OK, someone likes this call */
359 FsmDelTimer(&chanp
->drel_timer
, 61);
360 FsmChangeState(fi
, ST_IN_ALERT_SENT
);
361 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_ALERTING
| REQUEST
, chanp
->proc
);
363 case 5: /* direct redirect */
364 case 4: /* Proceeding desired */
365 FsmDelTimer(&chanp
->drel_timer
, 61);
366 FsmChangeState(fi
, ST_IN_PROCEED_SEND
);
367 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_PROCEED_SEND
| REQUEST
, chanp
->proc
);
369 memcpy(&chanp
->setup
, &ic
.parm
.setup
, sizeof(setup_parm
));
370 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_REDIR
| REQUEST
, chanp
->proc
);
373 case 2: /* Rejecting Call */
375 case 3: /* incomplete number */
376 FsmDelTimer(&chanp
->drel_timer
, 61);
377 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_MORE_INFO
| REQUEST
, chanp
->proc
);
379 case 0: /* OK, nobody likes this call */
380 default: /* statcallb problems */
381 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_IGNORE
| REQUEST
, chanp
->proc
);
382 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_REL
, (void *) (long)chanp
->chan
);
383 FsmChangeState(fi
, ST_NULL
);
387 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_IGNORE
| REQUEST
, chanp
->proc
);
388 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_REL
, (void *) (long)chanp
->chan
);
393 lli_send_dconnect(struct FsmInst
*fi
, int event
, void *arg
)
395 struct Channel
*chanp
= fi
->userdata
;
397 FsmChangeState(fi
, ST_IN_WAIT_CONN_ACK
);
398 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_SETUP
| RESPONSE
, chanp
->proc
);
402 lli_send_alert(struct FsmInst
*fi
, int event
, void *arg
)
404 struct Channel
*chanp
= fi
->userdata
;
406 FsmChangeState(fi
, ST_IN_ALERT_SENT
);
407 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_ALERTING
| REQUEST
, chanp
->proc
);
411 lli_send_redir(struct FsmInst
*fi
, int event
, void *arg
)
413 struct Channel
*chanp
= fi
->userdata
;
415 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_REDIR
| REQUEST
, chanp
->proc
);
419 lli_init_bchan_in(struct FsmInst
*fi
, int event
, void *arg
)
421 struct Channel
*chanp
= fi
->userdata
;
423 FsmChangeState(fi
, ST_WAIT_BCONN
);
424 if (chanp
->debug
& 1)
425 link_debug(chanp
, 0, "STAT_DCONN");
426 HL_LL(chanp
, ISDN_STAT_DCONN
);
427 chanp
->l2_active_protocol
= chanp
->l2_protocol
;
428 chanp
->incoming
= !0;
429 init_b_st(chanp
, !0);
430 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_ESTABLISH
| REQUEST
, NULL
);
434 lli_setup_rsp(struct FsmInst
*fi
, int event
, void *arg
)
436 struct Channel
*chanp
= fi
->userdata
;
439 lli_init_bchan_in(fi
, event
, arg
);
441 FsmChangeState(fi
, ST_IN_WAIT_CONN_ACK
);
443 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_ALERTING
| REQUEST
, chanp
->proc
);
445 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_SETUP
| RESPONSE
, chanp
->proc
);
452 lli_suspend(struct FsmInst
*fi
, int event
, void *arg
)
454 struct Channel
*chanp
= fi
->userdata
;
456 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_SUSPEND
| REQUEST
, chanp
->proc
);
462 lli_leased_hup(struct FsmInst
*fi
, struct Channel
*chanp
)
466 ic
.driver
= chanp
->cs
->myid
;
467 ic
.command
= ISDN_STAT_CAUSE
;
468 ic
.arg
= chanp
->chan
;
469 sprintf(ic
.parm
.num
, "L0010");
470 chanp
->cs
->iif
.statcallb(&ic
);
471 if (chanp
->debug
& 1)
472 link_debug(chanp
, 0, "STAT_DHUP");
473 HL_LL(chanp
, ISDN_STAT_DHUP
);
478 lli_disconnect_req(struct FsmInst
*fi
, int event
, void *arg
)
480 struct Channel
*chanp
= fi
->userdata
;
483 lli_leased_hup(fi
, chanp
);
485 FsmChangeState(fi
, ST_WAIT_DRELEASE
);
487 chanp
->proc
->para
.cause
= 0x10; /* Normal Call Clearing */
488 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_DISCONNECT
| REQUEST
,
494 lli_disconnect_reject(struct FsmInst
*fi
, int event
, void *arg
)
496 struct Channel
*chanp
= fi
->userdata
;
499 lli_leased_hup(fi
, chanp
);
501 FsmChangeState(fi
, ST_WAIT_DRELEASE
);
503 chanp
->proc
->para
.cause
= 0x15; /* Call Rejected */
504 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_DISCONNECT
| REQUEST
,
510 lli_dhup_close(struct FsmInst
*fi
, int event
, void *arg
)
512 struct Channel
*chanp
= fi
->userdata
;
515 lli_leased_hup(fi
, chanp
);
517 if (chanp
->debug
& 1)
518 link_debug(chanp
, 0, "STAT_DHUP");
519 lli_deliver_cause(chanp
);
520 HL_LL(chanp
, ISDN_STAT_DHUP
);
526 lli_reject_req(struct FsmInst
*fi
, int event
, void *arg
)
528 struct Channel
*chanp
= fi
->userdata
;
531 lli_leased_hup(fi
, chanp
);
536 chanp
->proc
->para
.cause
= 0x15; /* Call Rejected */
537 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_REJECT
| REQUEST
, chanp
->proc
);
538 lli_dhup_close(fi
, event
, arg
);
540 FsmRestartTimer(&chanp
->drel_timer
, 40, EV_HANGUP
, NULL
, 63);
541 FsmChangeState(fi
, ST_IN_ALERT_SENT
);
542 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_ALERTING
| REQUEST
, chanp
->proc
);
547 lli_disconn_bchan(struct FsmInst
*fi
, int event
, void *arg
)
549 struct Channel
*chanp
= fi
->userdata
;
551 chanp
->data_open
= 0;
552 FsmChangeState(fi
, ST_WAIT_BRELEASE
);
553 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_RELEASE
| REQUEST
, NULL
);
557 lli_start_disc(struct FsmInst
*fi
, int event
, void *arg
)
559 struct Channel
*chanp
= fi
->userdata
;
562 lli_leased_hup(fi
, chanp
);
564 lli_disconnect_req(fi
, event
, arg
);
569 lli_rel_b_disc(struct FsmInst
*fi
, int event
, void *arg
)
571 struct Channel
*chanp
= fi
->userdata
;
574 lli_start_disc(fi
, event
, arg
);
578 lli_bhup_disc(struct FsmInst
*fi
, int event
, void *arg
)
580 struct Channel
*chanp
= fi
->userdata
;
582 if (chanp
->debug
& 1)
583 link_debug(chanp
, 0, "STAT_BHUP");
584 HL_LL(chanp
, ISDN_STAT_BHUP
);
585 lli_rel_b_disc(fi
, event
, arg
);
589 lli_bhup_rel_b(struct FsmInst
*fi
, int event
, void *arg
)
591 struct Channel
*chanp
= fi
->userdata
;
593 FsmChangeState(fi
, ST_WAIT_DCOMMAND
);
594 chanp
->data_open
= 0;
595 if (chanp
->debug
& 1)
596 link_debug(chanp
, 0, "STAT_BHUP");
597 HL_LL(chanp
, ISDN_STAT_BHUP
);
602 lli_release_bchan(struct FsmInst
*fi
, int event
, void *arg
)
604 struct Channel
*chanp
= fi
->userdata
;
606 chanp
->data_open
= 0;
607 FsmChangeState(fi
, ST_WAIT_BREL_DISC
);
608 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_RELEASE
| REQUEST
, NULL
);
613 lli_rel_b_dhup(struct FsmInst
*fi
, int event
, void *arg
)
615 struct Channel
*chanp
= fi
->userdata
;
618 lli_dhup_close(fi
, event
, arg
);
622 lli_bhup_dhup(struct FsmInst
*fi
, int event
, void *arg
)
624 struct Channel
*chanp
= fi
->userdata
;
626 if (chanp
->debug
& 1)
627 link_debug(chanp
, 0, "STAT_BHUP");
628 HL_LL(chanp
, ISDN_STAT_BHUP
);
629 lli_rel_b_dhup(fi
, event
, arg
);
633 lli_abort(struct FsmInst
*fi
, int event
, void *arg
)
635 struct Channel
*chanp
= fi
->userdata
;
637 chanp
->data_open
= 0;
638 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_RELEASE
| REQUEST
, NULL
);
639 lli_bhup_dhup(fi
, event
, arg
);
643 lli_release_req(struct FsmInst
*fi
, int event
, void *arg
)
645 struct Channel
*chanp
= fi
->userdata
;
648 lli_leased_hup(fi
, chanp
);
650 FsmChangeState(fi
, ST_WAIT_D_REL_CNF
);
651 chanp
->d_st
->lli
.l4l3(chanp
->d_st
, CC_RELEASE
| REQUEST
,
657 lli_rel_b_release_req(struct FsmInst
*fi
, int event
, void *arg
)
659 struct Channel
*chanp
= fi
->userdata
;
662 lli_release_req(fi
, event
, arg
);
666 lli_bhup_release_req(struct FsmInst
*fi
, int event
, void *arg
)
668 struct Channel
*chanp
= fi
->userdata
;
670 if (chanp
->debug
& 1)
671 link_debug(chanp
, 0, "STAT_BHUP");
672 HL_LL(chanp
, ISDN_STAT_BHUP
);
673 lli_rel_b_release_req(fi
, event
, arg
);
677 /* processing charge info */
679 lli_charge_info(struct FsmInst
*fi
, int event
, void *arg
)
681 struct Channel
*chanp
= fi
->userdata
;
684 ic
.driver
= chanp
->cs
->myid
;
685 ic
.command
= ISDN_STAT_CINF
;
686 ic
.arg
= chanp
->chan
;
687 sprintf(ic
.parm
.num
, "%d", chanp
->proc
->para
.chargeinfo
);
688 chanp
->cs
->iif
.statcallb(&ic
);
691 /* error procedures */
694 lli_dchan_not_ready(struct FsmInst
*fi
, int event
, void *arg
)
696 struct Channel
*chanp
= fi
->userdata
;
698 if (chanp
->debug
& 1)
699 link_debug(chanp
, 0, "STAT_DHUP");
700 HL_LL(chanp
, ISDN_STAT_DHUP
);
704 lli_no_setup_rsp(struct FsmInst
*fi
, int event
, void *arg
)
706 struct Channel
*chanp
= fi
->userdata
;
708 if (chanp
->debug
& 1)
709 link_debug(chanp
, 0, "STAT_DHUP");
710 HL_LL(chanp
, ISDN_STAT_DHUP
);
715 lli_error(struct FsmInst
*fi
, int event
, void *arg
)
717 FsmChangeState(fi
, ST_WAIT_DRELEASE
);
721 lli_failure_l(struct FsmInst
*fi
, int event
, void *arg
)
723 struct Channel
*chanp
= fi
->userdata
;
726 FsmChangeState(fi
, ST_NULL
);
727 ic
.driver
= chanp
->cs
->myid
;
728 ic
.command
= ISDN_STAT_CAUSE
;
729 ic
.arg
= chanp
->chan
;
730 sprintf(ic
.parm
.num
, "L%02X%02X", 0, 0x2f);
731 chanp
->cs
->iif
.statcallb(&ic
);
732 HL_LL(chanp
, ISDN_STAT_DHUP
);
734 chanp
->cs
->cardmsg(chanp
->cs
, MDL_INFO_REL
, (void *) (long)chanp
->chan
);
738 lli_rel_b_fail(struct FsmInst
*fi
, int event
, void *arg
)
740 struct Channel
*chanp
= fi
->userdata
;
743 lli_failure_l(fi
, event
, arg
);
747 lli_bhup_fail(struct FsmInst
*fi
, int event
, void *arg
)
749 struct Channel
*chanp
= fi
->userdata
;
751 if (chanp
->debug
& 1)
752 link_debug(chanp
, 0, "STAT_BHUP");
753 HL_LL(chanp
, ISDN_STAT_BHUP
);
754 lli_rel_b_fail(fi
, event
, arg
);
758 lli_failure_a(struct FsmInst
*fi
, int event
, void *arg
)
760 struct Channel
*chanp
= fi
->userdata
;
762 chanp
->data_open
= 0;
763 chanp
->b_st
->lli
.l4l3(chanp
->b_st
, DL_RELEASE
| REQUEST
, NULL
);
764 lli_bhup_fail(fi
, event
, arg
);
768 static struct FsmNode fnlist
[] __initdata
=
770 {ST_NULL
, EV_DIAL
, lli_prep_dialout
},
771 {ST_NULL
, EV_RESUME
, lli_resume
},
772 {ST_NULL
, EV_SETUP_IND
, lli_deliver_call
},
773 {ST_NULL
, EV_LEASED
, lli_leased_in
},
774 {ST_OUT_DIAL
, EV_SETUP_CNF
, lli_init_bchan_out
},
775 {ST_OUT_DIAL
, EV_HANGUP
, lli_disconnect_req
},
776 {ST_OUT_DIAL
, EV_DISCONNECT_IND
, lli_release_req
},
777 {ST_OUT_DIAL
, EV_RELEASE
, lli_dhup_close
},
778 {ST_OUT_DIAL
, EV_NOSETUP_RSP
, lli_no_setup_rsp
},
779 {ST_OUT_DIAL
, EV_SETUP_ERR
, lli_error
},
780 {ST_IN_WAIT_LL
, EV_LEASED_REL
, lli_failure_l
},
781 {ST_IN_WAIT_LL
, EV_ACCEPTD
, lli_setup_rsp
},
782 {ST_IN_WAIT_LL
, EV_HANGUP
, lli_reject_req
},
783 {ST_IN_WAIT_LL
, EV_DISCONNECT_IND
, lli_release_req
},
784 {ST_IN_WAIT_LL
, EV_RELEASE
, lli_dhup_close
},
785 {ST_IN_WAIT_LL
, EV_SETUP_IND
, lli_deliver_call
},
786 {ST_IN_WAIT_LL
, EV_SETUP_ERR
, lli_error
},
787 {ST_IN_ALERT_SENT
, EV_SETUP_CMPL_IND
, lli_init_bchan_in
},
788 {ST_IN_ALERT_SENT
, EV_ACCEPTD
, lli_send_dconnect
},
789 {ST_IN_ALERT_SENT
, EV_HANGUP
, lli_disconnect_reject
},
790 {ST_IN_ALERT_SENT
, EV_DISCONNECT_IND
, lli_release_req
},
791 {ST_IN_ALERT_SENT
, EV_RELEASE
, lli_dhup_close
},
792 {ST_IN_ALERT_SENT
, EV_REDIR
, lli_send_redir
},
793 {ST_IN_PROCEED_SEND
, EV_REDIR
, lli_send_redir
},
794 {ST_IN_PROCEED_SEND
, EV_ALERT
, lli_send_alert
},
795 {ST_IN_PROCEED_SEND
, EV_ACCEPTD
, lli_send_dconnect
},
796 {ST_IN_PROCEED_SEND
, EV_HANGUP
, lli_disconnect_reject
},
797 {ST_IN_PROCEED_SEND
, EV_DISCONNECT_IND
, lli_dhup_close
},
798 {ST_IN_ALERT_SENT
, EV_RELEASE
, lli_dhup_close
},
799 {ST_IN_WAIT_CONN_ACK
, EV_SETUP_CMPL_IND
, lli_init_bchan_in
},
800 {ST_IN_WAIT_CONN_ACK
, EV_HANGUP
, lli_disconnect_req
},
801 {ST_IN_WAIT_CONN_ACK
, EV_DISCONNECT_IND
, lli_release_req
},
802 {ST_IN_WAIT_CONN_ACK
, EV_RELEASE
, lli_dhup_close
},
803 {ST_IN_WAIT_CONN_ACK
, EV_CONNECT_ERR
, lli_error
},
804 {ST_WAIT_BCONN
, EV_BC_EST
, lli_go_active
},
805 {ST_WAIT_BCONN
, EV_BC_REL
, lli_rel_b_disc
},
806 {ST_WAIT_BCONN
, EV_HANGUP
, lli_rel_b_disc
},
807 {ST_WAIT_BCONN
, EV_DISCONNECT_IND
, lli_rel_b_release_req
},
808 {ST_WAIT_BCONN
, EV_RELEASE
, lli_rel_b_dhup
},
809 {ST_WAIT_BCONN
, EV_LEASED_REL
, lli_rel_b_fail
},
810 {ST_WAIT_BCONN
, EV_CINF
, lli_charge_info
},
811 {ST_ACTIVE
, EV_CINF
, lli_charge_info
},
812 {ST_ACTIVE
, EV_BC_REL
, lli_bhup_rel_b
},
813 {ST_ACTIVE
, EV_SUSPEND
, lli_suspend
},
814 {ST_ACTIVE
, EV_HANGUP
, lli_disconn_bchan
},
815 {ST_ACTIVE
, EV_DISCONNECT_IND
, lli_release_bchan
},
816 {ST_ACTIVE
, EV_RELEASE
, lli_abort
},
817 {ST_ACTIVE
, EV_LEASED_REL
, lli_failure_a
},
818 {ST_WAIT_BRELEASE
, EV_BC_REL
, lli_bhup_disc
},
819 {ST_WAIT_BRELEASE
, EV_DISCONNECT_IND
, lli_bhup_release_req
},
820 {ST_WAIT_BRELEASE
, EV_RELEASE
, lli_bhup_dhup
},
821 {ST_WAIT_BRELEASE
, EV_LEASED_REL
, lli_bhup_fail
},
822 {ST_WAIT_BREL_DISC
, EV_BC_REL
, lli_bhup_release_req
},
823 {ST_WAIT_BREL_DISC
, EV_RELEASE
, lli_bhup_dhup
},
824 {ST_WAIT_DCOMMAND
, EV_HANGUP
, lli_start_disc
},
825 {ST_WAIT_DCOMMAND
, EV_DISCONNECT_IND
, lli_release_req
},
826 {ST_WAIT_DCOMMAND
, EV_RELEASE
, lli_dhup_close
},
827 {ST_WAIT_DCOMMAND
, EV_LEASED_REL
, lli_failure_l
},
828 {ST_WAIT_DRELEASE
, EV_RELEASE
, lli_dhup_close
},
829 {ST_WAIT_DRELEASE
, EV_DIAL
, lli_dchan_not_ready
},
830 /* ETS 300-104 16.1 */
831 {ST_WAIT_D_REL_CNF
, EV_RELEASE
, lli_dhup_close
},
832 {ST_WAIT_D_REL_CNF
, EV_DIAL
, lli_dchan_not_ready
},
836 #define FNCOUNT (sizeof(fnlist)/sizeof(struct FsmNode))
841 callcfsm
.state_count
= STATE_COUNT
;
842 callcfsm
.event_count
= EVENT_COUNT
;
843 callcfsm
.strEvent
= strEvent
;
844 callcfsm
.strState
= strState
;
845 return FsmNew(&callcfsm
, fnlist
, FNCOUNT
);
855 release_b_st(struct Channel
*chanp
)
857 struct PStack
*st
= chanp
->b_st
;
859 if(test_and_clear_bit(FLG_START_B
, &chanp
->Flags
)) {
860 chanp
->bcs
->BC_Close(chanp
->bcs
);
861 switch (chanp
->l2_active_protocol
) {
862 case (ISDN_PROTO_L2_X75I
):
863 releasestack_isdnl2(st
);
865 case (ISDN_PROTO_L2_HDLC
):
866 case (ISDN_PROTO_L2_HDLC_56K
):
867 case (ISDN_PROTO_L2_TRANS
):
868 case (ISDN_PROTO_L2_MODEM
):
869 case (ISDN_PROTO_L2_FAX
):
870 releasestack_transl2(st
);
876 static struct Channel
877 *selectfreechannel(struct PStack
*st
, int bch
)
879 struct IsdnCardState
*cs
= st
->l1
.hardware
;
880 struct Channel
*chanp
= st
->lli
.userdata
;
883 if (test_bit(FLG_TWO_DCHAN
, &cs
->HW_Flags
))
889 i
= 2; /* virtual channel */
893 while (i
< ((bch
) ? cs
->chanlimit
: (2 + MAX_WAITING_CALLS
))) {
894 if (chanp
->fi
.state
== ST_NULL
)
900 if (bch
) /* number of channels is limited */ {
901 i
= 2; /* virtual channel */
902 chanp
= st
->lli
.userdata
;
904 while (i
< (2 + MAX_WAITING_CALLS
)) {
905 if (chanp
->fi
.state
== ST_NULL
)
914 static void stat_redir_result(struct IsdnCardState
*cs
, int chan
, ulong result
)
917 ic
.driver
= cs
->myid
;
918 ic
.command
= ISDN_STAT_REDIR
;
920 ic
.parm
.num
[0] = result
;
921 cs
->iif
.statcallb(&ic
);
922 } /* stat_redir_result */
925 dchan_l3l4(struct PStack
*st
, int pr
, void *arg
)
927 struct l3_process
*pc
= arg
;
928 struct IsdnCardState
*cs
= st
->l1
.hardware
;
929 struct Channel
*chanp
;
934 if (pr
== (CC_SETUP
| INDICATION
)) {
935 if (!(chanp
= selectfreechannel(pc
->st
, pc
->para
.bchannel
))) {
936 pc
->para
.cause
= 0x11; /* User busy */
937 pc
->st
->lli
.l4l3(pc
->st
, CC_REJECT
| REQUEST
, pc
);
941 FsmEvent(&chanp
->fi
, EV_SETUP_IND
, NULL
);
945 if (!(chanp
= pc
->chan
))
949 case (CC_MORE_INFO
| INDICATION
):
950 FsmEvent(&chanp
->fi
, EV_SETUP_IND
, NULL
);
952 case (CC_DISCONNECT
| INDICATION
):
953 FsmEvent(&chanp
->fi
, EV_DISCONNECT_IND
, NULL
);
955 case (CC_RELEASE
| CONFIRM
):
956 FsmEvent(&chanp
->fi
, EV_RELEASE
, NULL
);
958 case (CC_SUSPEND
| CONFIRM
):
959 FsmEvent(&chanp
->fi
, EV_RELEASE
, NULL
);
961 case (CC_RESUME
| CONFIRM
):
962 FsmEvent(&chanp
->fi
, EV_SETUP_CNF
, NULL
);
964 case (CC_RESUME_ERR
):
965 FsmEvent(&chanp
->fi
, EV_RELEASE
, NULL
);
967 case (CC_RELEASE
| INDICATION
):
968 FsmEvent(&chanp
->fi
, EV_RELEASE
, NULL
);
970 case (CC_SETUP_COMPL
| INDICATION
):
971 FsmEvent(&chanp
->fi
, EV_SETUP_CMPL_IND
, NULL
);
973 case (CC_SETUP
| CONFIRM
):
974 FsmEvent(&chanp
->fi
, EV_SETUP_CNF
, NULL
);
976 case (CC_CHARGE
| INDICATION
):
977 FsmEvent(&chanp
->fi
, EV_CINF
, NULL
);
979 case (CC_NOSETUP_RSP
):
980 FsmEvent(&chanp
->fi
, EV_NOSETUP_RSP
, NULL
);
983 FsmEvent(&chanp
->fi
, EV_SETUP_ERR
, NULL
);
985 case (CC_CONNECT_ERR
):
986 FsmEvent(&chanp
->fi
, EV_CONNECT_ERR
, NULL
);
988 case (CC_RELEASE_ERR
):
989 FsmEvent(&chanp
->fi
, EV_RELEASE
, NULL
);
991 case (CC_PROCEED_SEND
| INDICATION
):
992 case (CC_PROCEEDING
| INDICATION
):
993 case (CC_ALERTING
| INDICATION
):
994 case (CC_PROGRESS
| INDICATION
):
995 case (CC_NOTIFY
| INDICATION
):
997 case (CC_REDIR
| INDICATION
):
998 stat_redir_result(cs
, chanp
->chan
, pc
->redir_result
);
1001 if (chanp
->debug
& 0x800) {
1002 HiSax_putstatus(chanp
->cs
, "Ch",
1003 "%d L3->L4 unknown primitiv %#x",
1010 dummy_pstack(struct PStack
*st
, int pr
, void *arg
) {
1011 printk(KERN_WARNING
"call to dummy_pstack pr=%04x arg %lx\n", pr
, (long)arg
);
1015 init_PStack(struct PStack
**stp
) {
1016 *stp
= kmalloc(sizeof(struct PStack
), GFP_ATOMIC
);
1019 (*stp
)->next
= NULL
;
1020 (*stp
)->l1
.l1l2
= dummy_pstack
;
1021 (*stp
)->l1
.l1hw
= dummy_pstack
;
1022 (*stp
)->l1
.l1tei
= dummy_pstack
;
1023 (*stp
)->l2
.l2tei
= dummy_pstack
;
1024 (*stp
)->l2
.l2l1
= dummy_pstack
;
1025 (*stp
)->l2
.l2l3
= dummy_pstack
;
1026 (*stp
)->l3
.l3l2
= dummy_pstack
;
1027 (*stp
)->l3
.l3ml3
= dummy_pstack
;
1028 (*stp
)->l3
.l3l4
= dummy_pstack
;
1029 (*stp
)->lli
.l4l3
= dummy_pstack
;
1030 (*stp
)->ma
.layer
= dummy_pstack
;
1035 init_d_st(struct Channel
*chanp
)
1038 struct IsdnCardState
*cs
= chanp
->cs
;
1042 err
= init_PStack(&chanp
->d_st
);
1047 HiSax_addlist(cs
, st
);
1048 setstack_HiSax(st
, cs
);
1052 test_and_set_bit(FLG_MOD128
, &st
->l2
.flag
);
1053 test_and_set_bit(FLG_LAPD
, &st
->l2
.flag
);
1054 test_and_set_bit(FLG_ORIG
, &st
->l2
.flag
);
1055 st
->l2
.maxlen
= MAX_DFRAME_LEN
;
1057 st
->l2
.T200
= 1000; /* 1000 milliseconds */
1058 st
->l2
.N200
= 3; /* try 3 times */
1059 st
->l2
.T203
= 10000; /* 10000 milliseconds */
1060 if (test_bit(FLG_TWO_DCHAN
, &cs
->HW_Flags
))
1061 sprintf(tmp
, "DCh%d Q.921 ", chanp
->chan
);
1063 sprintf(tmp
, "DCh Q.921 ");
1064 setstack_isdnl2(st
, tmp
);
1065 setstack_l3dc(st
, chanp
);
1066 st
->lli
.userdata
= chanp
;
1067 st
->l3
.l3l4
= dchan_l3l4
;
1073 callc_debug(struct FsmInst
*fi
, char *fmt
, ...)
1076 struct Channel
*chanp
= fi
->userdata
;
1079 va_start(args
, fmt
);
1080 sprintf(tmp
, "Ch%d callc ", chanp
->chan
);
1081 VHiSax_putstatus(chanp
->cs
, tmp
, fmt
, args
);
1086 init_chan(int chan
, struct IsdnCardState
*csta
)
1088 struct Channel
*chanp
= csta
->channel
+ chan
;
1092 chanp
->bcs
= csta
->bcs
+ chan
;
1094 chanp
->incoming
= 0;
1098 err
= init_PStack(&chanp
->b_st
);
1101 chanp
->b_st
->l1
.delay
= DEFAULT_B_DELAY
;
1102 chanp
->fi
.fsm
= &callcfsm
;
1103 chanp
->fi
.state
= ST_NULL
;
1104 chanp
->fi
.debug
= 0;
1105 chanp
->fi
.userdata
= chanp
;
1106 chanp
->fi
.printdebug
= callc_debug
;
1107 FsmInitTimer(&chanp
->fi
, &chanp
->dial_timer
);
1108 FsmInitTimer(&chanp
->fi
, &chanp
->drel_timer
);
1109 if (!chan
|| (test_bit(FLG_TWO_DCHAN
, &csta
->HW_Flags
) && chan
< 2)) {
1110 err
= init_d_st(chanp
);
1114 chanp
->d_st
= csta
->channel
->d_st
;
1116 chanp
->data_open
= 0;
1121 CallcNewChan(struct IsdnCardState
*csta
) {
1125 err
= init_chan(0, csta
);
1128 err
= init_chan(1, csta
);
1131 printk(KERN_INFO
"HiSax: 2 channels added\n");
1133 for (i
= 0; i
< MAX_WAITING_CALLS
; i
++) {
1134 err
= init_chan(i
+2,csta
);
1138 printk(KERN_INFO
"HiSax: MAX_WAITING_CALLS added\n");
1139 if (test_bit(FLG_PTP
, &csta
->channel
->d_st
->l2
.flag
)) {
1140 printk(KERN_INFO
"LAYER2 WATCHING ESTABLISH\n");
1141 csta
->channel
->d_st
->lli
.l4l3(csta
->channel
->d_st
,
1142 DL_ESTABLISH
| REQUEST
, NULL
);
1148 release_d_st(struct Channel
*chanp
)
1150 struct PStack
*st
= chanp
->d_st
;
1154 releasestack_isdnl2(st
);
1155 releasestack_isdnl3(st
);
1156 HiSax_rmlist(st
->l1
.hardware
, st
);
1162 CallcFreeChan(struct IsdnCardState
*csta
)
1166 for (i
= 0; i
< 2; i
++) {
1167 FsmDelTimer(&csta
->channel
[i
].drel_timer
, 74);
1168 FsmDelTimer(&csta
->channel
[i
].dial_timer
, 75);
1169 if (i
|| test_bit(FLG_TWO_DCHAN
, &csta
->HW_Flags
))
1170 release_d_st(csta
->channel
+ i
);
1171 if (csta
->channel
[i
].b_st
) {
1172 release_b_st(csta
->channel
+ i
);
1173 kfree(csta
->channel
[i
].b_st
);
1174 csta
->channel
[i
].b_st
= NULL
;
1176 printk(KERN_WARNING
"CallcFreeChan b_st ch%d allready freed\n", i
);
1177 if (i
|| test_bit(FLG_TWO_DCHAN
, &csta
->HW_Flags
)) {
1178 release_d_st(csta
->channel
+ i
);
1180 csta
->channel
[i
].d_st
= NULL
;
1185 lldata_handler(struct PStack
*st
, int pr
, void *arg
)
1187 struct Channel
*chanp
= (struct Channel
*) st
->lli
.userdata
;
1188 struct sk_buff
*skb
= arg
;
1191 case (DL_DATA
| INDICATION
):
1192 if (chanp
->data_open
) {
1193 if (chanp
->debug
& 0x800)
1194 link_debug(chanp
, 0, "lldata: %d", skb
->len
);
1195 chanp
->cs
->iif
.rcvcallb_skb(chanp
->cs
->myid
, chanp
->chan
, skb
);
1197 link_debug(chanp
, 0, "lldata: channel not open");
1201 case (DL_ESTABLISH
| INDICATION
):
1202 case (DL_ESTABLISH
| CONFIRM
):
1203 FsmEvent(&chanp
->fi
, EV_BC_EST
, NULL
);
1205 case (DL_RELEASE
| INDICATION
):
1206 case (DL_RELEASE
| CONFIRM
):
1207 FsmEvent(&chanp
->fi
, EV_BC_REL
, NULL
);
1210 printk(KERN_WARNING
"lldata_handler unknown primitive %#x\n",
1217 lltrans_handler(struct PStack
*st
, int pr
, void *arg
)
1219 struct Channel
*chanp
= (struct Channel
*) st
->lli
.userdata
;
1220 struct sk_buff
*skb
= arg
;
1223 case (PH_DATA
| INDICATION
):
1224 if (chanp
->data_open
) {
1225 if (chanp
->debug
& 0x800)
1226 link_debug(chanp
, 0, "lltrans: %d", skb
->len
);
1227 chanp
->cs
->iif
.rcvcallb_skb(chanp
->cs
->myid
, chanp
->chan
, skb
);
1229 link_debug(chanp
, 0, "lltrans: channel not open");
1233 case (PH_ACTIVATE
| INDICATION
):
1234 case (PH_ACTIVATE
| CONFIRM
):
1235 FsmEvent(&chanp
->fi
, EV_BC_EST
, NULL
);
1237 case (PH_DEACTIVATE
| INDICATION
):
1238 case (PH_DEACTIVATE
| CONFIRM
):
1239 FsmEvent(&chanp
->fi
, EV_BC_REL
, NULL
);
1242 printk(KERN_WARNING
"lltrans_handler unknown primitive %#x\n",
1249 lli_writewakeup(struct PStack
*st
, int len
)
1251 struct Channel
*chanp
= st
->lli
.userdata
;
1254 if (chanp
->debug
& 0x800)
1255 link_debug(chanp
, 0, "llwakeup: %d", len
);
1256 ic
.driver
= chanp
->cs
->myid
;
1257 ic
.command
= ISDN_STAT_BSENT
;
1258 ic
.arg
= chanp
->chan
;
1259 ic
.parm
.length
= len
;
1260 chanp
->cs
->iif
.statcallb(&ic
);
1264 init_b_st(struct Channel
*chanp
, int incoming
)
1266 struct PStack
*st
= chanp
->b_st
;
1267 struct IsdnCardState
*cs
= chanp
->cs
;
1270 st
->l1
.hardware
= cs
;
1272 st
->l1
.bc
= chanp
->chan
& 1;
1274 st
->l1
.bc
= chanp
->proc
->para
.bchannel
- 1;
1275 switch (chanp
->l2_active_protocol
) {
1276 case (ISDN_PROTO_L2_X75I
):
1277 case (ISDN_PROTO_L2_HDLC
):
1278 st
->l1
.mode
= L1_MODE_HDLC
;
1280 case (ISDN_PROTO_L2_HDLC_56K
):
1281 st
->l1
.mode
= L1_MODE_HDLC_56K
;
1283 case (ISDN_PROTO_L2_TRANS
):
1284 st
->l1
.mode
= L1_MODE_TRANS
;
1286 case (ISDN_PROTO_L2_MODEM
):
1287 st
->l1
.mode
= L1_MODE_V32
;
1289 case (ISDN_PROTO_L2_FAX
):
1290 st
->l1
.mode
= L1_MODE_FAX
;
1293 chanp
->bcs
->conmsg
= NULL
;
1294 if (chanp
->bcs
->BC_SetStack(st
, chanp
->bcs
))
1297 test_and_set_bit(FLG_LAPB
, &st
->l2
.flag
);
1298 st
->l2
.maxlen
= MAX_DATA_SIZE
;
1300 test_and_set_bit(FLG_ORIG
, &st
->l2
.flag
);
1301 st
->l2
.T200
= 1000; /* 1000 milliseconds */
1303 st
->l2
.N200
= 4; /* try 4 times */
1304 st
->l2
.T203
= 5000; /* 5000 milliseconds */
1306 switch (chanp
->l2_active_protocol
) {
1307 case (ISDN_PROTO_L2_X75I
):
1308 sprintf(tmp
, "Ch%d X.75", chanp
->chan
);
1309 setstack_isdnl2(st
, tmp
);
1310 setstack_l3bc(st
, chanp
);
1311 st
->l2
.l2l3
= lldata_handler
;
1312 st
->lli
.userdata
= chanp
;
1313 test_and_clear_bit(FLG_LLI_L1WAKEUP
, &st
->lli
.flag
);
1314 test_and_set_bit(FLG_LLI_L2WAKEUP
, &st
->lli
.flag
);
1315 st
->l2
.l2m
.debug
= chanp
->debug
& 16;
1316 st
->l2
.debug
= chanp
->debug
& 64;
1318 case (ISDN_PROTO_L2_HDLC
):
1319 case (ISDN_PROTO_L2_HDLC_56K
):
1320 case (ISDN_PROTO_L2_TRANS
):
1321 case (ISDN_PROTO_L2_MODEM
):
1322 case (ISDN_PROTO_L2_FAX
):
1323 st
->l1
.l1l2
= lltrans_handler
;
1324 st
->lli
.userdata
= chanp
;
1325 test_and_set_bit(FLG_LLI_L1WAKEUP
, &st
->lli
.flag
);
1326 test_and_clear_bit(FLG_LLI_L2WAKEUP
, &st
->lli
.flag
);
1327 setstack_transl2(st
);
1328 setstack_l3bc(st
, chanp
);
1331 test_and_set_bit(FLG_START_B
, &chanp
->Flags
);
1336 leased_l4l3(struct PStack
*st
, int pr
, void *arg
)
1338 struct Channel
*chanp
= (struct Channel
*) st
->lli
.userdata
;
1339 struct sk_buff
*skb
= arg
;
1342 case (DL_DATA
| REQUEST
):
1343 link_debug(chanp
, 0, "leased line d-channel DATA");
1346 case (DL_ESTABLISH
| REQUEST
):
1347 st
->l2
.l2l1(st
, PH_ACTIVATE
| REQUEST
, NULL
);
1349 case (DL_RELEASE
| REQUEST
):
1352 printk(KERN_WARNING
"transd_l4l3 unknown primitive %#x\n",
1359 leased_l1l2(struct PStack
*st
, int pr
, void *arg
)
1361 struct Channel
*chanp
= (struct Channel
*) st
->lli
.userdata
;
1362 struct sk_buff
*skb
= arg
;
1363 int i
,event
= EV_LEASED_REL
;
1366 case (PH_DATA
| INDICATION
):
1367 link_debug(chanp
, 0, "leased line d-channel DATA");
1370 case (PH_ACTIVATE
| INDICATION
):
1371 case (PH_ACTIVATE
| CONFIRM
):
1373 case (PH_DEACTIVATE
| INDICATION
):
1374 case (PH_DEACTIVATE
| CONFIRM
):
1375 if (test_bit(FLG_TWO_DCHAN
, &chanp
->cs
->HW_Flags
))
1380 FsmEvent(&chanp
->fi
, event
, NULL
);
1387 "transd_l1l2 unknown primitive %#x\n", pr
);
1393 distr_debug(struct IsdnCardState
*csta
, int debugflags
)
1396 struct Channel
*chanp
= csta
->channel
;
1398 for (i
= 0; i
< (2 + MAX_WAITING_CALLS
) ; i
++) {
1399 chanp
[i
].debug
= debugflags
;
1400 chanp
[i
].fi
.debug
= debugflags
& 2;
1401 chanp
[i
].d_st
->l2
.l2m
.debug
= debugflags
& 8;
1402 chanp
[i
].b_st
->l2
.l2m
.debug
= debugflags
& 0x10;
1403 chanp
[i
].d_st
->l2
.debug
= debugflags
& 0x20;
1404 chanp
[i
].b_st
->l2
.debug
= debugflags
& 0x40;
1405 chanp
[i
].d_st
->l3
.l3m
.debug
= debugflags
& 0x80;
1406 chanp
[i
].b_st
->l3
.l3m
.debug
= debugflags
& 0x100;
1407 chanp
[i
].b_st
->ma
.tei_m
.debug
= debugflags
& 0x200;
1408 chanp
[i
].b_st
->ma
.debug
= debugflags
& 0x200;
1409 chanp
[i
].d_st
->l1
.l1m
.debug
= debugflags
& 0x1000;
1410 chanp
[i
].b_st
->l1
.l1m
.debug
= debugflags
& 0x2000;
1413 csta
->debug
|= DEB_DLOG_HEX
;
1415 csta
->debug
&= ~DEB_DLOG_HEX
;
1418 static char tmpbuf
[256];
1421 capi_debug(struct Channel
*chanp
, capi_msg
*cm
)
1425 t
+= QuickHex(t
, (u_char
*)cm
, (cm
->Length
>50)? 50: cm
->Length
);
1428 HiSax_putstatus(chanp
->cs
, "Ch", "%d CAPIMSG %s", chanp
->chan
, tmpbuf
);
1432 lli_got_fac_req(struct Channel
*chanp
, capi_msg
*cm
) {
1433 if ((cm
->para
[0] != 3) || (cm
->para
[1] != 0))
1437 if (cm
->para
[4] != 0)
1439 switch(cm
->para
[3]) {
1440 case 4: /* Suspend */
1441 strncpy(chanp
->setup
.phone
, &cm
->para
[5], cm
->para
[5] +1);
1442 FsmEvent(&chanp
->fi
, EV_SUSPEND
, cm
);
1444 case 5: /* Resume */
1445 strncpy(chanp
->setup
.phone
, &cm
->para
[5], cm
->para
[5] +1);
1446 if (chanp
->fi
.state
== ST_NULL
) {
1447 FsmEvent(&chanp
->fi
, EV_RESUME
, cm
);
1449 FsmDelTimer(&chanp
->dial_timer
, 72);
1450 FsmAddTimer(&chanp
->dial_timer
, 80, EV_RESUME
, cm
, 73);
1457 lli_got_manufacturer(struct Channel
*chanp
, struct IsdnCardState
*cs
, capi_msg
*cm
) {
1458 if ((cs
->typ
== ISDN_CTYPE_ELSA
) || (cs
->typ
== ISDN_CTYPE_ELSA_PNP
) ||
1459 (cs
->typ
== ISDN_CTYPE_ELSA_PCI
)) {
1460 if (cs
->hw
.elsa
.MFlag
) {
1461 cs
->cardmsg(cs
, CARD_AUX_IND
, cm
->para
);
1467 /***************************************************************/
1468 /* Limit the available number of channels for the current card */
1469 /***************************************************************/
1471 set_channel_limit(struct IsdnCardState
*cs
, int chanmax
)
1476 if ((chanmax
< 0) || (chanmax
> 2))
1479 for (ii
= 0; ii
< 2; ii
++) {
1480 ic
.driver
= cs
->myid
;
1481 ic
.command
= ISDN_STAT_DISCH
;
1484 ic
.parm
.num
[0] = 0; /* disabled */
1486 ic
.parm
.num
[0] = 1; /* enabled */
1487 i
= cs
->iif
.statcallb(&ic
);
1488 if (i
) return(-EINVAL
);
1493 } /* set_channel_limit */
1496 HiSax_command(isdn_ctrl
* ic
)
1498 struct IsdnCardState
*csta
= hisax_findcard(ic
->driver
);
1500 struct Channel
*chanp
;
1506 "HiSax: if_command %d called with invalid driverId %d!\n",
1507 ic
->command
, ic
->driver
);
1510 switch (ic
->command
) {
1511 case (ISDN_CMD_SETEAZ
):
1512 chanp
= csta
->channel
+ ic
->arg
;
1514 case (ISDN_CMD_SETL2
):
1515 chanp
= csta
->channel
+ (ic
->arg
& 0xff);
1516 if (chanp
->debug
& 1)
1517 link_debug(chanp
, 1, "SETL2 card %d %ld",
1518 csta
->cardnr
+ 1, ic
->arg
>> 8);
1519 chanp
->l2_protocol
= ic
->arg
>> 8;
1521 case (ISDN_CMD_SETL3
):
1522 chanp
= csta
->channel
+ (ic
->arg
& 0xff);
1523 if (chanp
->debug
& 1)
1524 link_debug(chanp
, 1, "SETL3 card %d %ld",
1525 csta
->cardnr
+ 1, ic
->arg
>> 8);
1526 chanp
->l3_protocol
= ic
->arg
>> 8;
1528 case (ISDN_CMD_DIAL
):
1529 chanp
= csta
->channel
+ (ic
->arg
& 0xff);
1530 if (chanp
->debug
& 1)
1531 link_debug(chanp
, 1, "DIAL %s -> %s (%d,%d)",
1532 ic
->parm
.setup
.eazmsn
, ic
->parm
.setup
.phone
,
1533 ic
->parm
.setup
.si1
, ic
->parm
.setup
.si2
);
1534 memcpy(&chanp
->setup
, &ic
->parm
.setup
, sizeof(setup_parm
));
1535 if (!strcmp(chanp
->setup
.eazmsn
, "0"))
1536 chanp
->setup
.eazmsn
[0] = '\0';
1537 /* this solution is dirty and may be change, if
1538 * we make a callreference based callmanager */
1539 if (chanp
->fi
.state
== ST_NULL
) {
1540 FsmEvent(&chanp
->fi
, EV_DIAL
, NULL
);
1542 FsmDelTimer(&chanp
->dial_timer
, 70);
1543 FsmAddTimer(&chanp
->dial_timer
, 50, EV_DIAL
, NULL
, 71);
1546 case (ISDN_CMD_ACCEPTB
):
1547 chanp
= csta
->channel
+ ic
->arg
;
1548 if (chanp
->debug
& 1)
1549 link_debug(chanp
, 1, "ACCEPTB");
1550 FsmEvent(&chanp
->fi
, EV_ACCEPTB
, NULL
);
1552 case (ISDN_CMD_ACCEPTD
):
1553 chanp
= csta
->channel
+ ic
->arg
;
1554 memcpy(&chanp
->setup
, &ic
->parm
.setup
, sizeof(setup_parm
));
1555 if (chanp
->debug
& 1)
1556 link_debug(chanp
, 1, "ACCEPTD");
1557 FsmEvent(&chanp
->fi
, EV_ACCEPTD
, NULL
);
1559 case (ISDN_CMD_HANGUP
):
1560 chanp
= csta
->channel
+ ic
->arg
;
1561 if (chanp
->debug
& 1)
1562 link_debug(chanp
, 1, "HANGUP");
1563 FsmEvent(&chanp
->fi
, EV_HANGUP
, NULL
);
1565 case (CAPI_PUT_MESSAGE
):
1566 chanp
= csta
->channel
+ ic
->arg
;
1567 if (chanp
->debug
& 1)
1568 capi_debug(chanp
, &ic
->parm
.cmsg
);
1569 if (ic
->parm
.cmsg
.Length
< 8)
1571 switch(ic
->parm
.cmsg
.Command
) {
1573 if (ic
->parm
.cmsg
.Subcommand
== CAPI_REQ
)
1574 lli_got_fac_req(chanp
, &ic
->parm
.cmsg
);
1576 case CAPI_MANUFACTURER
:
1577 if (ic
->parm
.cmsg
.Subcommand
== CAPI_REQ
)
1578 lli_got_manufacturer(chanp
, csta
, &ic
->parm
.cmsg
);
1584 case (ISDN_CMD_IOCTL
):
1587 num
= *(unsigned int *) ic
->parm
.num
;
1588 HiSax_reportcard(csta
->cardnr
, num
);
1591 num
= *(unsigned int *) ic
->parm
.num
;
1592 distr_debug(csta
, num
);
1593 printk(KERN_DEBUG
"HiSax: debugging flags card %d set to %x\n",
1594 csta
->cardnr
+ 1, num
);
1595 HiSax_putstatus(csta
, "debugging flags ",
1596 "card %d set to %x", csta
->cardnr
+ 1, num
);
1599 num
= *(unsigned int *) ic
->parm
.num
;
1600 csta
->channel
[0].b_st
->l1
.delay
= num
;
1601 csta
->channel
[1].b_st
->l1
.delay
= num
;
1602 HiSax_putstatus(csta
, "delay ", "card %d set to %d ms",
1603 csta
->cardnr
+ 1, num
);
1604 printk(KERN_DEBUG
"HiSax: delay card %d set to %d ms\n",
1605 csta
->cardnr
+ 1, num
);
1607 case (5): /* set card in leased mode */
1608 num
= *(unsigned int *) ic
->parm
.num
;
1609 if ((num
<1) || (num
> 2)) {
1610 HiSax_putstatus(csta
, "Set LEASED ",
1611 "wrong channel %d", num
);
1612 printk(KERN_WARNING
"HiSax: Set LEASED wrong channel %d\n",
1616 chanp
= csta
->channel
+num
;
1618 HiSax_putstatus(csta
, "Card",
1619 "%d channel %d set leased mode\n",
1620 csta
->cardnr
+ 1, num
+ 1);
1621 chanp
->d_st
->l1
.l1l2
= leased_l1l2
;
1622 chanp
->d_st
->lli
.l4l3
= leased_l4l3
;
1623 chanp
->d_st
->lli
.l4l3(chanp
->d_st
,
1624 DL_ESTABLISH
| REQUEST
, NULL
);
1627 case (6): /* set B-channel test loop */
1628 num
= *(unsigned int *) ic
->parm
.num
;
1630 csta
->stlist
->l2
.l2l1(csta
->stlist
,
1631 PH_TESTLOOP
| REQUEST
, (void *) (long)num
);
1633 case (7): /* set card in PTP mode */
1634 num
= *(unsigned int *) ic
->parm
.num
;
1635 if (test_bit(FLG_TWO_DCHAN
, &csta
->HW_Flags
)) {
1636 printk(KERN_ERR
"HiSax PTP mode only with one TEI possible\n");
1638 test_and_set_bit(FLG_PTP
, &csta
->channel
[0].d_st
->l2
.flag
);
1639 test_and_set_bit(FLG_FIXED_TEI
, &csta
->channel
[0].d_st
->l2
.flag
);
1640 csta
->channel
[0].d_st
->l2
.tei
= 0;
1641 HiSax_putstatus(csta
, "set card ", "in PTP mode");
1642 printk(KERN_DEBUG
"HiSax: set card in PTP mode\n");
1643 printk(KERN_INFO
"LAYER2 WATCHING ESTABLISH\n");
1644 csta
->channel
[0].d_st
->lli
.l4l3(csta
->channel
[0].d_st
,
1645 DL_ESTABLISH
| REQUEST
, NULL
);
1647 test_and_clear_bit(FLG_PTP
, &csta
->channel
[0].d_st
->l2
.flag
);
1648 test_and_clear_bit(FLG_FIXED_TEI
, &csta
->channel
[0].d_st
->l2
.flag
);
1649 HiSax_putstatus(csta
, "set card ", "in PTMP mode");
1650 printk(KERN_DEBUG
"HiSax: set card in PTMP mode\n");
1653 case (8): /* set card in FIXED TEI mode */
1654 num
= *(unsigned int *) ic
->parm
.num
;
1655 chanp
= csta
->channel
+ (num
& 1);
1658 test_and_clear_bit(FLG_FIXED_TEI
, &chanp
->d_st
->l2
.flag
);
1659 chanp
->d_st
->l2
.tei
= -1;
1660 HiSax_putstatus(csta
, "set card ", "in VAR TEI mode");
1661 printk(KERN_DEBUG
"HiSax: set card in VAR TEI mode\n");
1663 test_and_set_bit(FLG_FIXED_TEI
, &chanp
->d_st
->l2
.flag
);
1664 chanp
->d_st
->l2
.tei
= num
;
1665 HiSax_putstatus(csta
, "set card ", "in FIXED TEI (%d) mode", num
);
1666 printk(KERN_DEBUG
"HiSax: set card in FIXED TEI (%d) mode\n",
1669 chanp
->d_st
->lli
.l4l3(chanp
->d_st
,
1670 DL_ESTABLISH
| REQUEST
, NULL
);
1673 num
= csta
->debug
& DEB_DLOG_HEX
;
1674 csta
->debug
= *(unsigned int *) ic
->parm
.num
;
1676 HiSax_putstatus(cards
[0].cs
, "l1 debugging ",
1677 "flags card %d set to %x",
1678 csta
->cardnr
+ 1, csta
->debug
);
1679 printk(KERN_DEBUG
"HiSax: l1 debugging flags card %d set to %x\n",
1680 csta
->cardnr
+ 1, csta
->debug
);
1683 csta
->channel
[0].d_st
->l3
.debug
= *(unsigned int *) ic
->parm
.num
;
1684 csta
->channel
[1].d_st
->l3
.debug
= *(unsigned int *) ic
->parm
.num
;
1685 HiSax_putstatus(cards
[0].cs
, "l3 debugging ",
1686 "flags card %d set to %x\n", csta
->cardnr
+ 1,
1687 *(unsigned int *) ic
->parm
.num
);
1688 printk(KERN_DEBUG
"HiSax: l3 debugging flags card %d set to %x\n",
1689 csta
->cardnr
+ 1, *(unsigned int *) ic
->parm
.num
);
1692 i
= *(unsigned int *) ic
->parm
.num
;
1693 return(set_channel_limit(csta
, i
));
1696 return(csta
->auxcmd(csta
, ic
));
1697 printk(KERN_DEBUG
"HiSax: invalid ioclt %d\n",
1703 case (ISDN_CMD_PROCEED
):
1704 chanp
= csta
->channel
+ ic
->arg
;
1705 if (chanp
->debug
& 1)
1706 link_debug(chanp
, 1, "PROCEED");
1707 FsmEvent(&chanp
->fi
, EV_PROCEED
, NULL
);
1710 case (ISDN_CMD_ALERT
):
1711 chanp
= csta
->channel
+ ic
->arg
;
1712 if (chanp
->debug
& 1)
1713 link_debug(chanp
, 1, "ALERT");
1714 FsmEvent(&chanp
->fi
, EV_ALERT
, NULL
);
1717 case (ISDN_CMD_REDIR
):
1718 chanp
= csta
->channel
+ ic
->arg
;
1719 if (chanp
->debug
& 1)
1720 link_debug(chanp
, 1, "REDIR");
1721 memcpy(&chanp
->setup
, &ic
->parm
.setup
, sizeof(setup_parm
));
1722 FsmEvent(&chanp
->fi
, EV_REDIR
, NULL
);
1725 /* protocol specific io commands */
1726 case (ISDN_CMD_PROT_IO
):
1727 for (st
= csta
->stlist
; st
; st
= st
->next
)
1728 if (st
->protocol
== (ic
->arg
& 0xFF))
1729 return(st
->lli
.l4l3_proto(st
, ic
));
1734 return(csta
->auxcmd(csta
, ic
));
1741 HiSax_writebuf_skb(int id
, int chan
, int ack
, struct sk_buff
*skb
)
1743 struct IsdnCardState
*csta
= hisax_findcard(id
);
1744 struct Channel
*chanp
;
1747 struct sk_buff
*nskb
;
1751 "HiSax: if_sendbuf called with invalid driverId!\n");
1754 chanp
= csta
->channel
+ chan
;
1756 if (!chanp
->data_open
) {
1757 link_debug(chanp
, 1, "writebuf: channel not open");
1760 if (len
> MAX_DATA_SIZE
) {
1761 link_debug(chanp
, 1, "writebuf: packet too large (%d bytes)", len
);
1762 printk(KERN_WARNING
"HiSax_writebuf: packet too large (%d bytes) !\n",
1767 if ((len
+ chanp
->bcs
->tx_cnt
) > MAX_DATA_MEM
) {
1768 /* Must return 0 here, since this is not an error
1769 * but a temporary lack of resources.
1771 if (chanp
->debug
& 0x800)
1772 link_debug(chanp
, 1, "writebuf: no buffers for %d bytes", len
);
1774 } else if (chanp
->debug
& 0x800)
1775 link_debug(chanp
, 1, "writebuf %d/%d/%d", len
, chanp
->bcs
->tx_cnt
,MAX_DATA_MEM
);
1776 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1778 nskb
->truesize
= nskb
->len
;
1780 nskb
->pkt_type
= PACKET_NOACK
;
1781 if (chanp
->l2_active_protocol
== ISDN_PROTO_L2_X75I
)
1782 st
->l3
.l3l2(st
, DL_DATA
| REQUEST
, nskb
);
1784 chanp
->bcs
->tx_cnt
+= len
;
1785 st
->l2
.l2l1(st
, PH_DATA
| REQUEST
, nskb
);