1 /* $Id: capidrv.c,v 1.1.2.2 2004/01/12 23:17:24 keil Exp $
3 * ISDN4Linux Driver, using capi20 interface (kernelcapi)
5 * Copyright 1997 by Carsten Paeth <calle@calle.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <linux/kernel.h>
15 #include <linux/major.h>
16 #include <linux/slab.h>
17 #include <linux/fcntl.h>
19 #include <linux/signal.h>
21 #include <linux/timer.h>
22 #include <linux/wait.h>
23 #include <linux/skbuff.h>
24 #include <linux/isdn.h>
25 #include <linux/isdnif.h>
26 #include <linux/proc_fs.h>
27 #include <linux/seq_file.h>
28 #include <linux/capi.h>
29 #include <linux/kernelcapi.h>
30 #include <linux/ctype.h>
31 #include <linux/init.h>
32 #include <linux/moduleparam.h>
34 #include <linux/isdn/capiutil.h>
35 #include <linux/isdn/capicmd.h>
38 static int debugmode
= 0;
40 MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux");
41 MODULE_AUTHOR("Carsten Paeth");
42 MODULE_LICENSE("GPL");
43 module_param(debugmode
, uint
, S_IRUGO
| S_IWUSR
);
45 /* -------- type definitions ----------------------------------------- */
48 struct capidrv_contr
{
50 struct capidrv_contr
*next
;
67 struct timer_list listentimer
;
70 * ID of capi message sent
78 struct capidrv_bchan
{
79 struct capidrv_contr
*contr
;
84 u8 mynum
[ISDN_MSNLEN
];
90 struct capidrv_plci
*next
;
92 u32 ncci
; /* ncci for CONNECT_ACTIVE_IND */
93 u16 msgid
; /* to identfy CONNECT_CONF */
98 struct capidrv_ncci
*next
;
99 struct capidrv_plci
*plcip
;
101 u16 msgid
; /* to identfy CONNECT_B3_CONF */
107 struct ncci_datahandle_queue
{
108 struct ncci_datahandle_queue
*next
;
114 struct capidrv_ncci
*nccip
;
117 struct capidrv_plci
*plci_list
;
127 struct capidrv_data
{
128 struct capi20_appl ap
;
130 struct capidrv_contr
*contr_list
;
133 typedef struct capidrv_plci capidrv_plci
;
134 typedef struct capidrv_ncci capidrv_ncci
;
135 typedef struct capidrv_contr capidrv_contr
;
136 typedef struct capidrv_data capidrv_data
;
137 typedef struct capidrv_bchan capidrv_bchan
;
139 /* -------- data definitions ----------------------------------------- */
141 static capidrv_data global
;
142 static DEFINE_SPINLOCK(global_lock
);
144 static void handle_dtrace_data(capidrv_contr
*card
,
145 int send
, int level2
, u8
*data
, u16 len
);
147 /* -------- convert functions ---------------------------------------- */
149 static inline u32
b1prot(int l2
, int l3
)
152 case ISDN_PROTO_L2_X75I
:
153 case ISDN_PROTO_L2_X75UI
:
154 case ISDN_PROTO_L2_X75BUI
:
156 case ISDN_PROTO_L2_HDLC
:
159 case ISDN_PROTO_L2_TRANS
:
161 case ISDN_PROTO_L2_V11096
:
162 case ISDN_PROTO_L2_V11019
:
163 case ISDN_PROTO_L2_V11038
:
165 case ISDN_PROTO_L2_FAX
:
167 case ISDN_PROTO_L2_MODEM
:
172 static inline u32
b2prot(int l2
, int l3
)
175 case ISDN_PROTO_L2_X75I
:
176 case ISDN_PROTO_L2_X75UI
:
177 case ISDN_PROTO_L2_X75BUI
:
180 case ISDN_PROTO_L2_HDLC
:
181 case ISDN_PROTO_L2_TRANS
:
182 case ISDN_PROTO_L2_V11096
:
183 case ISDN_PROTO_L2_V11019
:
184 case ISDN_PROTO_L2_V11038
:
185 case ISDN_PROTO_L2_MODEM
:
187 case ISDN_PROTO_L2_FAX
:
192 static inline u32
b3prot(int l2
, int l3
)
195 case ISDN_PROTO_L2_X75I
:
196 case ISDN_PROTO_L2_X75UI
:
197 case ISDN_PROTO_L2_X75BUI
:
198 case ISDN_PROTO_L2_HDLC
:
199 case ISDN_PROTO_L2_TRANS
:
200 case ISDN_PROTO_L2_V11096
:
201 case ISDN_PROTO_L2_V11019
:
202 case ISDN_PROTO_L2_V11038
:
203 case ISDN_PROTO_L2_MODEM
:
206 case ISDN_PROTO_L2_FAX
:
211 static _cstruct
b1config_async_v110(u16 rate
)
213 /* CAPI-Spec "B1 Configuration" */
214 static unsigned char buf
[9];
215 buf
[0] = 8; /* len */
216 /* maximum bitrate */
217 buf
[1] = rate
& 0xff; buf
[2] = (rate
>> 8) & 0xff;
218 buf
[3] = 8; buf
[4] = 0; /* 8 bits per character */
219 buf
[5] = 0; buf
[6] = 0; /* parity none */
220 buf
[7] = 0; buf
[8] = 0; /* 1 stop bit */
224 static _cstruct
b1config(int l2
, int l3
)
227 case ISDN_PROTO_L2_X75I
:
228 case ISDN_PROTO_L2_X75UI
:
229 case ISDN_PROTO_L2_X75BUI
:
230 case ISDN_PROTO_L2_HDLC
:
231 case ISDN_PROTO_L2_TRANS
:
234 case ISDN_PROTO_L2_V11096
:
235 return b1config_async_v110(9600);
236 case ISDN_PROTO_L2_V11019
:
237 return b1config_async_v110(19200);
238 case ISDN_PROTO_L2_V11038
:
239 return b1config_async_v110(38400);
243 static inline u16
si2cip(u8 si1
, u8 si2
)
245 static const u8 cip
[17][5] =
248 {0, 0, 0, 0, 0}, /*0 */
249 {16, 16, 4, 26, 16}, /*1 */
250 {17, 17, 17, 4, 4}, /*2 */
251 {2, 2, 2, 2, 2}, /*3 */
252 {18, 18, 18, 18, 18}, /*4 */
253 {2, 2, 2, 2, 2}, /*5 */
254 {0, 0, 0, 0, 0}, /*6 */
255 {2, 2, 2, 2, 2}, /*7 */
256 {2, 2, 2, 2, 2}, /*8 */
257 {21, 21, 21, 21, 21}, /*9 */
258 {19, 19, 19, 19, 19}, /*10 */
259 {0, 0, 0, 0, 0}, /*11 */
260 {0, 0, 0, 0, 0}, /*12 */
261 {0, 0, 0, 0, 0}, /*13 */
262 {0, 0, 0, 0, 0}, /*14 */
263 {22, 22, 22, 22, 22}, /*15 */
264 {27, 27, 27, 28, 27} /*16 */
271 return (u16
) cip
[si1
][si2
];
274 static inline u8
cip2si1(u16 cipval
)
276 static const u8 si
[32] =
277 {7, 1, 7, 7, 1, 1, 7, 7, /*0-7 */
278 7, 1, 0, 0, 0, 0, 0, 0, /*8-15 */
279 1, 2, 4, 10, 9, 9, 15, 7, /*16-23 */
280 7, 7, 1, 16, 16, 0, 0, 0}; /*24-31 */
283 cipval
= 0; /* .... */
287 static inline u8
cip2si2(u16 cipval
)
289 static const u8 si
[32] =
290 {0, 0, 0, 0, 2, 3, 0, 0, /*0-7 */
291 0, 3, 0, 0, 0, 0, 0, 0, /*8-15 */
292 1, 2, 0, 0, 9, 0, 0, 0, /*16-23 */
293 0, 0, 3, 2, 3, 0, 0, 0}; /*24-31 */
296 cipval
= 0; /* .... */
301 /* -------- controller management ------------------------------------- */
303 static inline capidrv_contr
*findcontrbydriverid(int driverid
)
308 spin_lock_irqsave(&global_lock
, flags
);
309 for (p
= global
.contr_list
; p
; p
= p
->next
)
310 if (p
->myid
== driverid
)
312 spin_unlock_irqrestore(&global_lock
, flags
);
316 static capidrv_contr
*findcontrbynumber(u32 contr
)
319 capidrv_contr
*p
= global
.contr_list
;
321 spin_lock_irqsave(&global_lock
, flags
);
322 for (p
= global
.contr_list
; p
; p
= p
->next
)
323 if (p
->contrnr
== contr
)
325 spin_unlock_irqrestore(&global_lock
, flags
);
330 /* -------- plci management ------------------------------------------ */
332 static capidrv_plci
*new_plci(capidrv_contr
*card
, int chan
)
336 plcip
= kzalloc(sizeof(capidrv_plci
), GFP_ATOMIC
);
341 plcip
->state
= ST_PLCI_NONE
;
345 plcip
->next
= card
->plci_list
;
346 card
->plci_list
= plcip
;
347 card
->bchans
[chan
].plcip
= plcip
;
352 static capidrv_plci
*find_plci_by_plci(capidrv_contr
*card
, u32 plci
)
355 for (p
= card
->plci_list
; p
; p
= p
->next
)
361 static capidrv_plci
*find_plci_by_msgid(capidrv_contr
*card
, u16 msgid
)
364 for (p
= card
->plci_list
; p
; p
= p
->next
)
365 if (p
->msgid
== msgid
)
370 static capidrv_plci
*find_plci_by_ncci(capidrv_contr
*card
, u32 ncci
)
373 for (p
= card
->plci_list
; p
; p
= p
->next
)
374 if (p
->plci
== (ncci
& 0xffff))
379 static void free_plci(capidrv_contr
*card
, capidrv_plci
*plcip
)
383 for (pp
= &card
->plci_list
; *pp
; pp
= &(*pp
)->next
) {
386 card
->bchans
[plcip
->chan
].plcip
= NULL
;
387 card
->bchans
[plcip
->chan
].disconnecting
= 0;
388 card
->bchans
[plcip
->chan
].incoming
= 0;
393 printk(KERN_ERR
"capidrv-%d: free_plci %p (0x%x) not found, Huh?\n",
394 card
->contrnr
, plcip
, plcip
->plci
);
397 /* -------- ncci management ------------------------------------------ */
399 static inline capidrv_ncci
*new_ncci(capidrv_contr
*card
,
405 nccip
= kzalloc(sizeof(capidrv_ncci
), GFP_ATOMIC
);
411 nccip
->state
= ST_NCCI_NONE
;
412 nccip
->plcip
= plcip
;
413 nccip
->chan
= plcip
->chan
;
414 nccip
->datahandle
= 0;
416 nccip
->next
= plcip
->ncci_list
;
417 plcip
->ncci_list
= nccip
;
419 card
->bchans
[plcip
->chan
].nccip
= nccip
;
424 static inline capidrv_ncci
*find_ncci(capidrv_contr
*card
, u32 ncci
)
429 if ((plcip
= find_plci_by_ncci(card
, ncci
)) == NULL
)
432 for (p
= plcip
->ncci_list
; p
; p
= p
->next
)
438 static inline capidrv_ncci
*find_ncci_by_msgid(capidrv_contr
*card
,
444 if ((plcip
= find_plci_by_ncci(card
, ncci
)) == NULL
)
447 for (p
= plcip
->ncci_list
; p
; p
= p
->next
)
448 if (p
->msgid
== msgid
)
453 static void free_ncci(capidrv_contr
*card
, struct capidrv_ncci
*nccip
)
455 struct capidrv_ncci
**pp
;
457 for (pp
= &(nccip
->plcip
->ncci_list
); *pp
; pp
= &(*pp
)->next
) {
463 card
->bchans
[nccip
->chan
].nccip
= NULL
;
467 static int capidrv_add_ack(struct capidrv_ncci
*nccip
,
468 u16 datahandle
, int len
)
470 struct ncci_datahandle_queue
*n
, **pp
;
472 n
= kmalloc(sizeof(struct ncci_datahandle_queue
), GFP_ATOMIC
);
474 printk(KERN_ERR
"capidrv: kmalloc ncci_datahandle failed\n");
478 n
->datahandle
= datahandle
;
480 for (pp
= &nccip
->ackqueue
; *pp
; pp
= &(*pp
)->next
);
485 static int capidrv_del_ack(struct capidrv_ncci
*nccip
, u16 datahandle
)
487 struct ncci_datahandle_queue
**pp
, *p
;
490 for (pp
= &nccip
->ackqueue
; *pp
; pp
= &(*pp
)->next
) {
491 if ((*pp
)->datahandle
== datahandle
) {
502 /* -------- convert and send capi message ---------------------------- */
504 static void send_message(capidrv_contr
*card
, _cmsg
*cmsg
)
509 if (capi_cmsg2message(cmsg
, cmsg
->buf
)) {
510 printk(KERN_ERR
"capidrv::send_message: parser failure\n");
513 len
= CAPIMSG_LEN(cmsg
->buf
);
514 skb
= alloc_skb(len
, GFP_ATOMIC
);
516 printk(KERN_ERR
"capidrv::send_message: can't allocate mem\n");
519 memcpy(skb_put(skb
, len
), cmsg
->buf
, len
);
520 if (capi20_put_message(&global
.ap
, skb
) != CAPI_NOERROR
)
524 /* -------- state machine -------------------------------------------- */
526 struct listenstatechange
{
532 static struct listenstatechange listentable
[] =
534 {ST_LISTEN_NONE
, ST_LISTEN_WAIT_CONF
, EV_LISTEN_REQ
},
535 {ST_LISTEN_ACTIVE
, ST_LISTEN_ACTIVE_WAIT_CONF
, EV_LISTEN_REQ
},
536 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_ERROR
},
537 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_ERROR
},
538 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
539 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
540 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
541 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
545 static void listen_change_state(capidrv_contr
*card
, int event
)
547 struct listenstatechange
*p
= listentable
;
549 if (card
->state
== p
->actstate
&& p
->event
== event
) {
551 printk(KERN_DEBUG
"capidrv-%d: listen_change_state %d -> %d\n",
552 card
->contrnr
, card
->state
, p
->nextstate
);
553 card
->state
= p
->nextstate
;
558 printk(KERN_ERR
"capidrv-%d: listen_change_state state=%d event=%d ????\n",
559 card
->contrnr
, card
->state
, event
);
563 /* ------------------------------------------------------------------ */
565 static void p0(capidrv_contr
*card
, capidrv_plci
*plci
)
569 card
->bchans
[plci
->chan
].contr
= NULL
;
570 cmd
.command
= ISDN_STAT_DHUP
;
571 cmd
.driver
= card
->myid
;
572 cmd
.arg
= plci
->chan
;
573 card
->interface
.statcallb(&cmd
);
574 free_plci(card
, plci
);
577 /* ------------------------------------------------------------------ */
579 struct plcistatechange
{
583 void (*changefunc
)(capidrv_contr
*card
, capidrv_plci
*plci
);
586 static struct plcistatechange plcitable
[] =
589 {ST_PLCI_NONE
, ST_PLCI_OUTGOING
, EV_PLCI_CONNECT_REQ
, NULL
},
590 {ST_PLCI_NONE
, ST_PLCI_ALLOCATED
, EV_PLCI_FACILITY_IND_UP
, NULL
},
591 {ST_PLCI_NONE
, ST_PLCI_INCOMING
, EV_PLCI_CONNECT_IND
, NULL
},
592 {ST_PLCI_NONE
, ST_PLCI_RESUMEING
, EV_PLCI_RESUME_REQ
, NULL
},
594 {ST_PLCI_OUTGOING
, ST_PLCI_NONE
, EV_PLCI_CONNECT_CONF_ERROR
, p0
},
595 {ST_PLCI_OUTGOING
, ST_PLCI_ALLOCATED
, EV_PLCI_CONNECT_CONF_OK
, NULL
},
597 {ST_PLCI_ALLOCATED
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
598 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
599 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
600 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
602 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
603 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
604 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
605 {ST_PLCI_ACTIVE
, ST_PLCI_HELD
, EV_PLCI_HOLD_IND
, NULL
},
606 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_SUSPEND_IND
, NULL
},
608 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
609 {ST_PLCI_INCOMING
, ST_PLCI_FACILITY_IND
, EV_PLCI_FACILITY_IND_UP
, NULL
},
610 {ST_PLCI_INCOMING
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_RESP
, NULL
},
611 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
612 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
613 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
614 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CD_IND
, NULL
},
616 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
617 {ST_PLCI_FACILITY_IND
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
618 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
619 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
620 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
622 {ST_PLCI_ACCEPTING
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
623 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
624 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
625 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
627 {ST_PLCI_DISCONNECTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
629 {ST_PLCI_DISCONNECTED
, ST_PLCI_NONE
, EV_PLCI_DISCONNECT_RESP
, p0
},
631 {ST_PLCI_RESUMEING
, ST_PLCI_NONE
, EV_PLCI_RESUME_CONF_ERROR
, p0
},
632 {ST_PLCI_RESUMEING
, ST_PLCI_RESUME
, EV_PLCI_RESUME_CONF_OK
, NULL
},
634 {ST_PLCI_RESUME
, ST_PLCI_ACTIVE
, EV_PLCI_RESUME_IND
, NULL
},
636 {ST_PLCI_HELD
, ST_PLCI_ACTIVE
, EV_PLCI_RETRIEVE_IND
, NULL
},
640 static void plci_change_state(capidrv_contr
*card
, capidrv_plci
*plci
, int event
)
642 struct plcistatechange
*p
= plcitable
;
644 if (plci
->state
== p
->actstate
&& p
->event
== event
) {
646 printk(KERN_DEBUG
"capidrv-%d: plci_change_state:0x%x %d -> %d\n",
647 card
->contrnr
, plci
->plci
, plci
->state
, p
->nextstate
);
648 plci
->state
= p
->nextstate
;
650 p
->changefunc(card
, plci
);
655 printk(KERN_ERR
"capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
656 card
->contrnr
, plci
->plci
, plci
->state
, event
);
659 /* ------------------------------------------------------------------ */
663 static void n0(capidrv_contr
*card
, capidrv_ncci
*ncci
)
667 capi_fill_DISCONNECT_REQ(&cmsg
,
671 NULL
, /* BChannelinformation */
672 NULL
, /* Keypadfacility */
673 NULL
, /* Useruserdata */ /* $$$$ */
674 NULL
/* Facilitydataarray */
676 plci_change_state(card
, ncci
->plcip
, EV_PLCI_DISCONNECT_REQ
);
677 send_message(card
, &cmsg
);
679 cmd
.command
= ISDN_STAT_BHUP
;
680 cmd
.driver
= card
->myid
;
681 cmd
.arg
= ncci
->chan
;
682 card
->interface
.statcallb(&cmd
);
683 free_ncci(card
, ncci
);
686 /* ------------------------------------------------------------------ */
688 struct nccistatechange
{
692 void (*changefunc
)(capidrv_contr
*card
, capidrv_ncci
*ncci
);
695 static struct nccistatechange nccitable
[] =
698 {ST_NCCI_NONE
, ST_NCCI_OUTGOING
, EV_NCCI_CONNECT_B3_REQ
, NULL
},
699 {ST_NCCI_NONE
, ST_NCCI_INCOMING
, EV_NCCI_CONNECT_B3_IND
, NULL
},
701 {ST_NCCI_OUTGOING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_CONF_OK
, NULL
},
702 {ST_NCCI_OUTGOING
, ST_NCCI_NONE
, EV_NCCI_CONNECT_B3_CONF_ERROR
, n0
},
704 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_CONNECT_B3_REJECT
, NULL
},
705 {ST_NCCI_INCOMING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_RESP
, NULL
},
706 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
707 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
709 {ST_NCCI_ALLOCATED
, ST_NCCI_ACTIVE
, EV_NCCI_CONNECT_B3_ACTIVE_IND
, NULL
},
710 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
711 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
713 {ST_NCCI_ACTIVE
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
714 {ST_NCCI_ACTIVE
, ST_NCCI_RESETING
, EV_NCCI_RESET_B3_REQ
, NULL
},
715 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
716 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
718 {ST_NCCI_RESETING
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
719 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
720 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
722 {ST_NCCI_DISCONNECTING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
723 {ST_NCCI_DISCONNECTING
, ST_NCCI_PREVIOUS
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
, NULL
},
725 {ST_NCCI_DISCONNECTED
, ST_NCCI_NONE
, EV_NCCI_DISCONNECT_B3_RESP
, n0
},
729 static void ncci_change_state(capidrv_contr
*card
, capidrv_ncci
*ncci
, int event
)
731 struct nccistatechange
*p
= nccitable
;
733 if (ncci
->state
== p
->actstate
&& p
->event
== event
) {
735 printk(KERN_DEBUG
"capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
736 card
->contrnr
, ncci
->ncci
, ncci
->state
, p
->nextstate
);
737 if (p
->nextstate
== ST_NCCI_PREVIOUS
) {
738 ncci
->state
= ncci
->oldstate
;
739 ncci
->oldstate
= p
->actstate
;
741 ncci
->oldstate
= p
->actstate
;
742 ncci
->state
= p
->nextstate
;
745 p
->changefunc(card
, ncci
);
750 printk(KERN_ERR
"capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
751 card
->contrnr
, ncci
->ncci
, ncci
->state
, event
);
754 /* ------------------------------------------------------------------- */
756 static inline int new_bchan(capidrv_contr
*card
)
759 for (i
= 0; i
< card
->nbchan
; i
++) {
760 if (card
->bchans
[i
].plcip
== NULL
) {
761 card
->bchans
[i
].disconnecting
= 0;
768 /* ------------------------------------------------------------------- */
769 static char *capi_info2str(u16 reason
)
771 #ifndef CONFIG_ISDN_CAPI_CAPIDRV_VERBOSE
776 /*-- informative values (corresponding message was processed) -----*/
778 return "NCPI not supported by current protocol, NCPI ignored";
780 return "Flags not supported by current protocol, flags ignored";
782 return "Alert already sent by another application";
784 /*-- error information concerning CAPI_REGISTER -----*/
786 return "Too many applications";
788 return "Logical block size too small, must be at least 128 Bytes";
790 return "Buffer exceeds 64 kByte";
792 return "Message buffer size too small, must be at least 1024 Bytes";
794 return "Max. number of logical connections not supported";
798 return "The message could not be accepted because of an internal busy condition";
800 return "OS resource error (no memory ?)";
802 return "CAPI not installed";
804 return "Controller does not support external equipment";
806 return "Controller does only support external equipment";
808 /*-- error information concerning message exchange functions -----*/
810 return "Illegal application number";
812 return "Illegal command or subcommand or message length less than 12 bytes";
814 return "The message could not be accepted because of a queue full condition !! The error code does not imply that CAPI cannot receive messages directed to another controller, PLCI or NCCI";
816 return "Queue is empty";
818 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
820 return "Unknown notification parameter";
822 return "The Message could not be accepted because of an internal busy condition";
824 return "OS Resource error (no memory ?)";
826 return "CAPI not installed";
828 return "Controller does not support external equipment";
830 return "Controller does only support external equipment";
832 /*-- error information concerning resource / coding problems -----*/
834 return "Message not supported in current state";
836 return "Illegal Controller / PLCI / NCCI";
838 return "Out of PLCI";
840 return "Out of NCCI";
842 return "Out of LISTEN";
844 return "Out of FAX resources (protocol T.30)";
846 return "Illegal message parameter coding";
848 /*-- error information concerning requested services -----*/
850 return "B1 protocol not supported";
852 return "B2 protocol not supported";
854 return "B3 protocol not supported";
856 return "B1 protocol parameter not supported";
858 return "B2 protocol parameter not supported";
860 return "B3 protocol parameter not supported";
862 return "B protocol combination not supported";
864 return "NCPI not supported";
866 return "CIP Value unknown";
868 return "Flags not supported (reserved bits)";
870 return "Facility not supported";
872 return "Data length not supported by current protocol";
874 return "Reset procedure not supported by current protocol";
876 /*-- informations about the clearing of a physical connection -----*/
878 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
880 return "Protocol error layer 2";
882 return "Protocol error layer 3";
884 return "Another application got that call";
885 /*-- T.30 specific reasons -----*/
887 return "Connecting not successful (remote station is no FAX G3 machine)";
889 return "Connecting not successful (training error)";
891 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
893 return "Disconnected during transfer (remote abort)";
895 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
897 return "Disconnected during transfer (local tx data underrun)";
899 return "Disconnected during transfer (local rx data overflow)";
901 return "Disconnected during transfer (local abort)";
903 return "Illegal parameter coding (e.g. SFF coding error)";
905 /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
906 case 0x3481: return "Unallocated (unassigned) number";
907 case 0x3482: return "No route to specified transit network";
908 case 0x3483: return "No route to destination";
909 case 0x3486: return "Channel unacceptable";
911 return "Call awarded and being delivered in an established channel";
912 case 0x3490: return "Normal call clearing";
913 case 0x3491: return "User busy";
914 case 0x3492: return "No user responding";
915 case 0x3493: return "No answer from user (user alerted)";
916 case 0x3495: return "Call rejected";
917 case 0x3496: return "Number changed";
918 case 0x349A: return "Non-selected user clearing";
919 case 0x349B: return "Destination out of order";
920 case 0x349C: return "Invalid number format";
921 case 0x349D: return "Facility rejected";
922 case 0x349E: return "Response to STATUS ENQUIRY";
923 case 0x349F: return "Normal, unspecified";
924 case 0x34A2: return "No circuit / channel available";
925 case 0x34A6: return "Network out of order";
926 case 0x34A9: return "Temporary failure";
927 case 0x34AA: return "Switching equipment congestion";
928 case 0x34AB: return "Access information discarded";
929 case 0x34AC: return "Requested circuit / channel not available";
930 case 0x34AF: return "Resources unavailable, unspecified";
931 case 0x34B1: return "Quality of service unavailable";
932 case 0x34B2: return "Requested facility not subscribed";
933 case 0x34B9: return "Bearer capability not authorized";
934 case 0x34BA: return "Bearer capability not presently available";
935 case 0x34BF: return "Service or option not available, unspecified";
936 case 0x34C1: return "Bearer capability not implemented";
937 case 0x34C2: return "Channel type not implemented";
938 case 0x34C5: return "Requested facility not implemented";
939 case 0x34C6: return "Only restricted digital information bearer capability is available";
940 case 0x34CF: return "Service or option not implemented, unspecified";
941 case 0x34D1: return "Invalid call reference value";
942 case 0x34D2: return "Identified channel does not exist";
943 case 0x34D3: return "A suspended call exists, but this call identity does not";
944 case 0x34D4: return "Call identity in use";
945 case 0x34D5: return "No call suspended";
946 case 0x34D6: return "Call having the requested call identity has been cleared";
947 case 0x34D8: return "Incompatible destination";
948 case 0x34DB: return "Invalid transit network selection";
949 case 0x34DF: return "Invalid message, unspecified";
950 case 0x34E0: return "Mandatory information element is missing";
951 case 0x34E1: return "Message type non-existent or not implemented";
952 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
953 case 0x34E3: return "Information element non-existent or not implemented";
954 case 0x34E4: return "Invalid information element contents";
955 case 0x34E5: return "Message not compatible with call state";
956 case 0x34E6: return "Recovery on timer expiry";
957 case 0x34EF: return "Protocol error, unspecified";
958 case 0x34FF: return "Interworking, unspecified";
960 default: return "No additional information";
965 static void handle_controller(_cmsg
*cmsg
)
967 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
970 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
971 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
972 cmsg
->adr
.adrController
& 0x7f);
975 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
977 case CAPI_LISTEN_CONF
: /* Controller */
979 printk(KERN_DEBUG
"capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
980 card
->contrnr
, cmsg
->Info
, capi_info2str(cmsg
->Info
), card
->cipmask
);
982 listen_change_state(card
, EV_LISTEN_CONF_ERROR
);
983 } else if (card
->cipmask
== 0) {
984 listen_change_state(card
, EV_LISTEN_CONF_EMPTY
);
986 listen_change_state(card
, EV_LISTEN_CONF_OK
);
990 case CAPI_MANUFACTURER_IND
: /* Controller */
991 if (cmsg
->ManuID
== 0x214D5641
993 && cmsg
->Function
== 1) {
994 u8
*data
= cmsg
->ManuData
+ 3;
995 u16 len
= cmsg
->ManuData
[0];
999 len
= (cmsg
->ManuData
[1] | (cmsg
->ManuData
[2] << 8));
1003 layer
= ((*(data
- 1)) << 8) | *(data
- 2);
1005 direction
= (layer
& 0x200) ? 0 : 1;
1006 else direction
= (layer
& 0x800) ? 0 : 1;
1007 if (layer
& 0x0C00) {
1008 if ((layer
& 0xff) == 0x80) {
1009 handle_dtrace_data(card
, direction
, 1, data
, len
);
1012 } else if ((layer
& 0xff) < 0x80) {
1013 handle_dtrace_data(card
, direction
, 0, data
, len
);
1016 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
1018 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1019 cmsg
->adr
.adrController
, layer
);
1023 case CAPI_MANUFACTURER_CONF
: /* Controller */
1024 if (cmsg
->ManuID
== 0x214D5641) {
1026 switch (cmsg
->Class
) {
1028 case 1: s
= "unknown class"; break;
1029 case 2: s
= "unknown function"; break;
1030 default: s
= "unknown error"; break;
1033 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x function %d: %s\n",
1035 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1036 cmsg
->adr
.adrController
,
1041 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1043 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1045 case CAPI_INFO_IND
: /* Controller/plci */
1047 case CAPI_INFO_CONF
: /* Controller/plci */
1051 printk(KERN_ERR
"capidrv-%d: got %s from controller 0x%x ???",
1053 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1054 cmsg
->adr
.adrController
);
1059 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x ignored\n",
1061 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1062 cmsg
->adr
.adrController
);
1065 static void handle_incoming_call(capidrv_contr
*card
, _cmsg
*cmsg
)
1067 capidrv_plci
*plcip
;
1068 capidrv_bchan
*bchan
;
1072 if ((chan
= new_bchan(card
)) == -1) {
1073 printk(KERN_ERR
"capidrv-%d: incoming call on not existing bchan ?\n", card
->contrnr
);
1076 bchan
= &card
->bchans
[chan
];
1077 if ((plcip
= new_plci(card
, chan
)) == NULL
) {
1078 printk(KERN_ERR
"capidrv-%d: incoming call: no memory, sorry.\n", card
->contrnr
);
1081 bchan
->incoming
= 1;
1082 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1083 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_IND
);
1085 cmd
.command
= ISDN_STAT_ICALL
;
1086 cmd
.driver
= card
->myid
;
1088 memset(&cmd
.parm
.setup
, 0, sizeof(cmd
.parm
.setup
));
1089 strncpy(cmd
.parm
.setup
.phone
,
1090 cmsg
->CallingPartyNumber
+ 3,
1091 cmsg
->CallingPartyNumber
[0] - 2);
1092 strncpy(cmd
.parm
.setup
.eazmsn
,
1093 cmsg
->CalledPartyNumber
+ 2,
1094 cmsg
->CalledPartyNumber
[0] - 1);
1095 cmd
.parm
.setup
.si1
= cip2si1(cmsg
->CIPValue
);
1096 cmd
.parm
.setup
.si2
= cip2si2(cmsg
->CIPValue
);
1097 cmd
.parm
.setup
.plan
= cmsg
->CallingPartyNumber
[1];
1098 cmd
.parm
.setup
.screen
= cmsg
->CallingPartyNumber
[2];
1100 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s\n",
1102 cmd
.parm
.setup
.phone
,
1105 cmd
.parm
.setup
.eazmsn
);
1107 if (cmd
.parm
.setup
.si1
== 1 && cmd
.parm
.setup
.si2
!= 0) {
1108 printk(KERN_INFO
"capidrv-%d: patching si2=%d to 0 for VBOX\n",
1110 cmd
.parm
.setup
.si2
);
1111 cmd
.parm
.setup
.si2
= 0;
1114 switch (card
->interface
.statcallb(&cmd
)) {
1117 /* No device matching this call.
1118 * and isdn_common.c has send a HANGUP command
1119 * which is ignored in state ST_PLCI_INCOMING,
1120 * so we send RESP to ignore the call
1122 capi_cmsg_answer(cmsg
);
1123 cmsg
->Reject
= 1; /* ignore */
1124 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1125 send_message(card
, cmsg
);
1126 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
1128 cmd
.parm
.setup
.phone
,
1131 cmd
.parm
.setup
.eazmsn
);
1134 /* At least one device matching this call (RING on ttyI)
1135 * HL-driver may send ALERTING on the D-channel in this
1137 * really means: RING on ttyI or a net interface
1138 * accepted this call already.
1140 * If the call was accepted, state has already changed,
1141 * and CONNECT_RESP already sent.
1143 if (plcip
->state
== ST_PLCI_INCOMING
) {
1144 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
1146 cmd
.parm
.setup
.phone
,
1149 cmd
.parm
.setup
.eazmsn
);
1150 capi_fill_ALERT_REQ(cmsg
,
1153 plcip
->plci
, /* adr */
1154 NULL
,/* BChannelinformation */
1155 NULL
,/* Keypadfacility */
1156 NULL
,/* Useruserdata */
1157 NULL
/* Facilitydataarray */
1159 plcip
->msgid
= cmsg
->Messagenumber
;
1160 send_message(card
, cmsg
);
1162 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
1164 cmd
.parm
.setup
.phone
,
1167 cmd
.parm
.setup
.eazmsn
);
1171 case 2: /* Call will be rejected. */
1172 capi_cmsg_answer(cmsg
);
1173 cmsg
->Reject
= 2; /* reject call, normal call clearing */
1174 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1175 send_message(card
, cmsg
);
1179 /* An error happened. (Invalid parameters for example.) */
1180 capi_cmsg_answer(cmsg
);
1181 cmsg
->Reject
= 8; /* reject call,
1182 destination out of order */
1183 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1184 send_message(card
, cmsg
);
1190 static void handle_plci(_cmsg
*cmsg
)
1192 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1193 capidrv_plci
*plcip
;
1198 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1199 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1200 cmsg
->adr
.adrController
& 0x7f);
1203 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1205 case CAPI_DISCONNECT_IND
: /* plci */
1207 printk(KERN_INFO
"capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1209 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1210 cmsg
->Reason
, capi_info2str(cmsg
->Reason
), cmsg
->adr
.adrPLCI
);
1212 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
))) {
1213 capi_cmsg_answer(cmsg
);
1214 send_message(card
, cmsg
);
1217 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1218 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_IND
);
1219 capi_cmsg_answer(cmsg
);
1220 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_RESP
);
1221 send_message(card
, cmsg
);
1224 case CAPI_DISCONNECT_CONF
: /* plci */
1226 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1228 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1229 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1232 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1235 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1238 case CAPI_ALERT_CONF
: /* plci */
1240 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1242 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1243 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1248 case CAPI_CONNECT_IND
: /* plci */
1249 handle_incoming_call(card
, cmsg
);
1252 case CAPI_CONNECT_CONF
: /* plci */
1254 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1256 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1257 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1260 if (!(plcip
= find_plci_by_msgid(card
, cmsg
->Messagenumber
)))
1263 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1265 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_ERROR
);
1267 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_OK
);
1271 case CAPI_CONNECT_ACTIVE_IND
: /* plci */
1273 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1276 if (card
->bchans
[plcip
->chan
].incoming
) {
1277 capi_cmsg_answer(cmsg
);
1278 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_ACTIVE_IND
);
1279 send_message(card
, cmsg
);
1281 capidrv_ncci
*nccip
;
1282 capi_cmsg_answer(cmsg
);
1283 send_message(card
, cmsg
);
1285 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrPLCI
);
1288 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1291 capi_fill_CONNECT_B3_REQ(cmsg
,
1294 plcip
->plci
, /* adr */
1297 nccip
->msgid
= cmsg
->Messagenumber
;
1298 plci_change_state(card
, plcip
,
1299 EV_PLCI_CONNECT_ACTIVE_IND
);
1300 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_REQ
);
1301 send_message(card
, cmsg
);
1302 cmd
.command
= ISDN_STAT_DCONN
;
1303 cmd
.driver
= card
->myid
;
1304 cmd
.arg
= plcip
->chan
;
1305 card
->interface
.statcallb(&cmd
);
1309 case CAPI_INFO_IND
: /* Controller/plci */
1311 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1314 if (cmsg
->InfoNumber
== 0x4000) {
1315 if (cmsg
->InfoElement
[0] == 4) {
1316 cmd
.command
= ISDN_STAT_CINF
;
1317 cmd
.driver
= card
->myid
;
1318 cmd
.arg
= plcip
->chan
;
1319 sprintf(cmd
.parm
.num
, "%lu",
1321 ((u32
) cmsg
->InfoElement
[1]
1322 | ((u32
) (cmsg
->InfoElement
[2]) << 8)
1323 | ((u32
) (cmsg
->InfoElement
[3]) << 16)
1324 | ((u32
) (cmsg
->InfoElement
[4]) << 24)));
1325 card
->interface
.statcallb(&cmd
);
1329 cdb
= capi_cmsg2str(cmsg
);
1331 printk(KERN_WARNING
"capidrv-%d: %s\n",
1332 card
->contrnr
, cdb
->buf
);
1335 printk(KERN_WARNING
"capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n",
1336 card
->contrnr
, cmsg
->InfoNumber
);
1340 case CAPI_CONNECT_ACTIVE_CONF
: /* plci */
1342 case CAPI_SELECT_B_PROTOCOL_CONF
: /* plci */
1344 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1346 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1349 case CAPI_INFO_CONF
: /* Controller/plci */
1353 printk(KERN_ERR
"capidrv-%d: got %s for plci 0x%x ???",
1355 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1360 printk(KERN_INFO
"capidrv-%d: %s for plci 0x%x ignored\n",
1362 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1366 printk(KERN_ERR
"capidrv-%d: %s: plci 0x%x not found\n",
1368 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1373 static void handle_ncci(_cmsg
*cmsg
)
1375 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1376 capidrv_plci
*plcip
;
1377 capidrv_ncci
*nccip
;
1382 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1383 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1384 cmsg
->adr
.adrController
& 0x7f);
1387 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1389 case CAPI_CONNECT_B3_ACTIVE_IND
: /* ncci */
1390 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1393 capi_cmsg_answer(cmsg
);
1394 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_ACTIVE_IND
);
1395 send_message(card
, cmsg
);
1397 cmd
.command
= ISDN_STAT_BCONN
;
1398 cmd
.driver
= card
->myid
;
1399 cmd
.arg
= nccip
->chan
;
1400 card
->interface
.statcallb(&cmd
);
1402 printk(KERN_INFO
"capidrv-%d: chan %d up with ncci 0x%x\n",
1403 card
->contrnr
, nccip
->chan
, nccip
->ncci
);
1406 case CAPI_CONNECT_B3_ACTIVE_CONF
: /* ncci */
1409 case CAPI_CONNECT_B3_IND
: /* ncci */
1411 plcip
= find_plci_by_ncci(card
, cmsg
->adr
.adrNCCI
);
1413 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrNCCI
);
1415 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_IND
);
1416 capi_fill_CONNECT_B3_RESP(cmsg
,
1419 nccip
->ncci
, /* adr */
1423 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_RESP
);
1424 send_message(card
, cmsg
);
1427 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1429 printk(KERN_ERR
"capidrv-%d: %s: plci for ncci 0x%x not found\n",
1431 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1434 capi_fill_CONNECT_B3_RESP(cmsg
,
1441 send_message(card
, cmsg
);
1444 case CAPI_CONNECT_B3_CONF
: /* ncci */
1446 if (!(nccip
= find_ncci_by_msgid(card
,
1448 cmsg
->Messagenumber
)))
1451 nccip
->ncci
= cmsg
->adr
.adrNCCI
;
1453 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1455 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1456 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1461 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_ERROR
);
1463 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_OK
);
1466 case CAPI_CONNECT_B3_T90_ACTIVE_IND
: /* ncci */
1467 capi_cmsg_answer(cmsg
);
1468 send_message(card
, cmsg
);
1471 case CAPI_DATA_B3_IND
: /* ncci */
1472 /* handled in handle_data() */
1475 case CAPI_DATA_B3_CONF
: /* ncci */
1477 printk(KERN_WARNING
"CAPI_DATA_B3_CONF: Info %x - %s\n",
1478 cmsg
->Info
, capi_info2str(cmsg
->Info
));
1480 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1483 len
= capidrv_del_ack(nccip
, cmsg
->DataHandle
);
1486 cmd
.command
= ISDN_STAT_BSENT
;
1487 cmd
.driver
= card
->myid
;
1488 cmd
.arg
= nccip
->chan
;
1489 cmd
.parm
.length
= len
;
1490 card
->interface
.statcallb(&cmd
);
1493 case CAPI_DISCONNECT_B3_IND
: /* ncci */
1494 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1497 card
->bchans
[nccip
->chan
].disconnecting
= 1;
1498 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_IND
);
1499 capi_cmsg_answer(cmsg
);
1500 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_RESP
);
1501 send_message(card
, cmsg
);
1504 case CAPI_DISCONNECT_B3_CONF
: /* ncci */
1505 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1508 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1510 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1511 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1513 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
);
1517 case CAPI_RESET_B3_IND
: /* ncci */
1518 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1520 ncci_change_state(card
, nccip
, EV_NCCI_RESET_B3_IND
);
1521 capi_cmsg_answer(cmsg
);
1522 send_message(card
, cmsg
);
1525 case CAPI_RESET_B3_CONF
: /* ncci */
1526 goto ignored
; /* $$$$ */
1528 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1530 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1534 printk(KERN_ERR
"capidrv-%d: got %s for ncci 0x%x ???",
1536 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1541 printk(KERN_INFO
"capidrv-%d: %s for ncci 0x%x ignored\n",
1543 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1547 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1549 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1554 static void handle_data(_cmsg
*cmsg
, struct sk_buff
*skb
)
1556 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1557 capidrv_ncci
*nccip
;
1560 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1561 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1562 cmsg
->adr
.adrController
& 0x7f);
1566 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
))) {
1567 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1569 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1574 (void) skb_pull(skb
, CAPIMSG_LEN(skb
->data
));
1575 card
->interface
.rcvcallb_skb(card
->myid
, nccip
->chan
, skb
);
1576 capi_cmsg_answer(cmsg
);
1577 send_message(card
, cmsg
);
1580 static _cmsg s_cmsg
;
1582 static void capidrv_recv_message(struct capi20_appl
*ap
, struct sk_buff
*skb
)
1584 if (capi_message2cmsg(&s_cmsg
, skb
->data
)) {
1585 printk(KERN_ERR
"capidrv: applid=%d: received invalid message\n",
1590 if (debugmode
> 3) {
1591 _cdebbuf
*cdb
= capi_cmsg2str(&s_cmsg
);
1594 printk(KERN_DEBUG
"%s: applid=%d %s\n", __func__
,
1595 ap
->applid
, cdb
->buf
);
1598 printk(KERN_DEBUG
"%s: applid=%d %s not traced\n",
1599 __func__
, ap
->applid
,
1600 capi_cmd2str(s_cmsg
.Command
, s_cmsg
.Subcommand
));
1602 if (s_cmsg
.Command
== CAPI_DATA_B3
1603 && s_cmsg
.Subcommand
== CAPI_IND
) {
1604 handle_data(&s_cmsg
, skb
);
1607 if ((s_cmsg
.adr
.adrController
& 0xffffff00) == 0)
1608 handle_controller(&s_cmsg
);
1609 else if ((s_cmsg
.adr
.adrPLCI
& 0xffff0000) == 0)
1610 handle_plci(&s_cmsg
);
1612 handle_ncci(&s_cmsg
);
1614 * data of skb used in s_cmsg,
1615 * free data when s_cmsg is not used again
1616 * thanks to Lars Heete <hel@admin.de>
1621 /* ------------------------------------------------------------------- */
1623 #define PUTBYTE_TO_STATUS(card, byte) \
1625 *(card)->q931_write++ = (byte); \
1626 if ((card)->q931_write > (card)->q931_end) \
1627 (card)->q931_write = (card)->q931_buf; \
1630 static void handle_dtrace_data(capidrv_contr
*card
,
1631 int send
, int level2
, u8
*data
, u16 len
)
1637 printk(KERN_DEBUG
"capidrv-%d: avmb1_q931_data: len == %d\n",
1638 card
->contrnr
, len
);
1643 PUTBYTE_TO_STATUS(card
, 'D');
1644 PUTBYTE_TO_STATUS(card
, '2');
1645 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1646 PUTBYTE_TO_STATUS(card
, ':');
1648 PUTBYTE_TO_STATUS(card
, 'D');
1649 PUTBYTE_TO_STATUS(card
, '3');
1650 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1651 PUTBYTE_TO_STATUS(card
, ':');
1654 for (p
= data
, end
= data
+ len
; p
< end
; p
++) {
1655 PUTBYTE_TO_STATUS(card
, ' ');
1656 PUTBYTE_TO_STATUS(card
, hex_asc_hi(*p
));
1657 PUTBYTE_TO_STATUS(card
, hex_asc_lo(*p
));
1659 PUTBYTE_TO_STATUS(card
, '\n');
1661 cmd
.command
= ISDN_STAT_STAVAIL
;
1662 cmd
.driver
= card
->myid
;
1663 cmd
.arg
= len
* 3 + 5;
1664 card
->interface
.statcallb(&cmd
);
1667 /* ------------------------------------------------------------------- */
1669 static _cmsg cmdcmsg
;
1671 static int capidrv_ioctl(isdn_ctrl
*c
, capidrv_contr
*card
)
1675 debugmode
= (int)(*((unsigned int *)c
->parm
.num
));
1676 printk(KERN_DEBUG
"capidrv-%d: debugmode=%d\n",
1677 card
->contrnr
, debugmode
);
1680 printk(KERN_DEBUG
"capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1681 card
->contrnr
, c
->arg
);
1688 * Handle leased lines (CAPI-Bundling)
1691 struct internal_bchannelinfo
{
1692 unsigned short channelalloc
;
1693 unsigned short operation
;
1694 unsigned char cmask
[31];
1697 static int decodeFVteln(char *teln
, unsigned long *bmaskp
, int *activep
)
1699 unsigned long bmask
= 0;
1704 if (strncmp(teln
, "FV:", 3) != 0)
1707 while (*s
&& *s
== ' ') s
++;
1709 if (*s
== 'p' || *s
== 'P') {
1713 if (*s
== 'a' || *s
== 'A') {
1722 digit1
= simple_strtoul(s
, &endp
, 10);
1727 if (digit1
<= 0 || digit1
> 30) return -4;
1728 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1729 bmask
|= (1 << digit1
);
1734 if (*s
!= '-') return -5;
1737 digit2
= simple_strtoul(s
, &endp
, 10);
1742 if (digit2
<= 0 || digit2
> 30) return -4;
1743 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1744 if (digit1
> digit2
)
1745 for (i
= digit2
; i
<= digit1
; i
++)
1748 for (i
= digit1
; i
<= digit2
; i
++)
1750 digit1
= digit2
= 0;
1756 if (activep
) *activep
= active
;
1757 if (bmaskp
) *bmaskp
= bmask
;
1761 static int FVteln2capi20(char *teln
, u8 AdditionalInfo
[1 + 2 + 2 + 31])
1763 unsigned long bmask
;
1767 rc
= decodeFVteln(teln
, &bmask
, &active
);
1770 AdditionalInfo
[0] = 2 + 2 + 31;
1771 /* Channel: 3 => use channel allocation */
1772 AdditionalInfo
[1] = 3; AdditionalInfo
[2] = 0;
1773 /* Operation: 0 => DTE mode, 1 => DCE mode */
1775 AdditionalInfo
[3] = 0; AdditionalInfo
[4] = 0;
1777 AdditionalInfo
[3] = 1; AdditionalInfo
[4] = 0;
1779 /* Channel mask array */
1780 AdditionalInfo
[5] = 0; /* no D-Channel */
1781 for (i
= 1; i
<= 30; i
++)
1782 AdditionalInfo
[5 + i
] = (bmask
& (1 << i
)) ? 0xff : 0;
1786 static int capidrv_command(isdn_ctrl
*c
, capidrv_contr
*card
)
1789 struct capidrv_bchan
*bchan
;
1790 struct capidrv_plci
*plcip
;
1791 u8 AdditionalInfo
[1 + 2 + 2 + 31];
1792 int rc
, isleasedline
= 0;
1794 if (c
->command
== ISDN_CMD_IOCTL
)
1795 return capidrv_ioctl(c
, card
);
1797 switch (c
->command
) {
1798 case ISDN_CMD_DIAL
: {
1799 u8 calling
[ISDN_MSNLEN
+ 3];
1800 u8 called
[ISDN_MSNLEN
+ 2];
1803 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1806 c
->parm
.setup
.phone
,
1809 c
->parm
.setup
.eazmsn
);
1811 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1814 printk(KERN_ERR
"capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1817 c
->parm
.setup
.phone
,
1820 c
->parm
.setup
.eazmsn
,
1821 bchan
->plcip
->plci
);
1824 bchan
->si1
= c
->parm
.setup
.si1
;
1825 bchan
->si2
= c
->parm
.setup
.si2
;
1827 strncpy(bchan
->num
, c
->parm
.setup
.phone
, sizeof(bchan
->num
));
1828 strncpy(bchan
->mynum
, c
->parm
.setup
.eazmsn
, sizeof(bchan
->mynum
));
1829 rc
= FVteln2capi20(bchan
->num
, AdditionalInfo
);
1830 isleasedline
= (rc
== 0);
1832 printk(KERN_ERR
"capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card
->contrnr
, bchan
->num
);
1838 printk(KERN_DEBUG
"capidrv-%d: connecting leased line\n", card
->contrnr
);
1840 calling
[0] = strlen(bchan
->mynum
) + 2;
1843 strncpy(calling
+ 3, bchan
->mynum
, ISDN_MSNLEN
);
1844 called
[0] = strlen(bchan
->num
) + 1;
1846 strncpy(called
+ 2, bchan
->num
, ISDN_MSNLEN
);
1849 capi_fill_CONNECT_REQ(&cmdcmsg
,
1852 card
->contrnr
, /* adr */
1853 si2cip(bchan
->si1
, bchan
->si2
), /* cipvalue */
1854 called
, /* CalledPartyNumber */
1855 calling
, /* CallingPartyNumber */
1856 NULL
, /* CalledPartySubaddress */
1857 NULL
, /* CallingPartySubaddress */
1858 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1859 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1860 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1861 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1862 NULL
, /* B2configuration */
1863 NULL
, /* B3configuration */
1867 /* BChannelinformation */
1868 isleasedline
? AdditionalInfo
: NULL
,
1869 NULL
, /* Keypadfacility */
1870 NULL
, /* Useruserdata */
1871 NULL
/* Facilitydataarray */
1873 if ((plcip
= new_plci(card
, (c
->arg
% card
->nbchan
))) == NULL
) {
1874 cmd
.command
= ISDN_STAT_DHUP
;
1875 cmd
.driver
= card
->myid
;
1876 cmd
.arg
= (c
->arg
% card
->nbchan
);
1877 card
->interface
.statcallb(&cmd
);
1880 plcip
->msgid
= cmdcmsg
.Messagenumber
;
1881 plcip
->leasedline
= isleasedline
;
1882 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REQ
);
1883 send_message(card
, &cmdcmsg
);
1887 case ISDN_CMD_ACCEPTD
:
1889 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1891 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1893 c
->arg
, bchan
->l2
, bchan
->l3
);
1895 capi_fill_CONNECT_RESP(&cmdcmsg
,
1898 bchan
->plcip
->plci
, /* adr */
1900 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1901 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1902 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1903 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1904 NULL
, /* B2configuration */
1905 NULL
, /* B3configuration */
1906 NULL
, /* ConnectedNumber */
1907 NULL
, /* ConnectedSubaddress */
1909 NULL
, /* BChannelinformation */
1910 NULL
, /* Keypadfacility */
1911 NULL
, /* Useruserdata */
1912 NULL
/* Facilitydataarray */
1914 if (capi_cmsg2message(&cmdcmsg
, cmdcmsg
.buf
)) {
1915 printk(KERN_ERR
"capidrv-%d: capidrv_command: parser failure\n",
1919 plci_change_state(card
, bchan
->plcip
, EV_PLCI_CONNECT_RESP
);
1920 send_message(card
, &cmdcmsg
);
1923 case ISDN_CMD_ACCEPTB
:
1925 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1930 case ISDN_CMD_HANGUP
:
1932 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1935 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1937 if (bchan
->disconnecting
) {
1939 printk(KERN_DEBUG
"capidrv-%d: chan %ld already disconnecting ...\n",
1945 bchan
->disconnecting
= 1;
1946 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg
,
1952 ncci_change_state(card
, bchan
->nccip
, EV_NCCI_DISCONNECT_B3_REQ
);
1953 send_message(card
, &cmdcmsg
);
1955 } else if (bchan
->plcip
) {
1956 if (bchan
->plcip
->state
== ST_PLCI_INCOMING
) {
1958 * just ignore, we a called from
1959 * isdn_status_callback(),
1960 * which will return 0 or 2, this is handled
1961 * by the CONNECT_IND handler
1963 bchan
->disconnecting
= 1;
1965 } else if (bchan
->plcip
->plci
) {
1966 bchan
->disconnecting
= 1;
1967 capi_fill_DISCONNECT_REQ(&cmdcmsg
,
1971 NULL
, /* BChannelinformation */
1972 NULL
, /* Keypadfacility */
1973 NULL
, /* Useruserdata */
1974 NULL
/* Facilitydataarray */
1976 plci_change_state(card
, bchan
->plcip
, EV_PLCI_DISCONNECT_REQ
);
1977 send_message(card
, &cmdcmsg
);
1980 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1986 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request on free channel\n",
1992 case ISDN_CMD_SETL2
:
1994 printk(KERN_DEBUG
"capidrv-%d: set L2 on chan %ld to %ld\n",
1996 (c
->arg
& 0xff), (c
->arg
>> 8));
1997 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1998 bchan
->l2
= (c
->arg
>> 8);
2001 case ISDN_CMD_SETL3
:
2003 printk(KERN_DEBUG
"capidrv-%d: set L3 on chan %ld to %ld\n",
2005 (c
->arg
& 0xff), (c
->arg
>> 8));
2006 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
2007 bchan
->l3
= (c
->arg
>> 8);
2010 case ISDN_CMD_SETEAZ
:
2012 printk(KERN_DEBUG
"capidrv-%d: set EAZ \"%s\" on chan %ld\n",
2014 c
->parm
.num
, c
->arg
);
2015 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
2016 strncpy(bchan
->msn
, c
->parm
.num
, ISDN_MSNLEN
);
2019 case ISDN_CMD_CLREAZ
:
2021 printk(KERN_DEBUG
"capidrv-%d: clearing EAZ on chan %ld\n",
2022 card
->contrnr
, c
->arg
);
2023 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
2028 printk(KERN_ERR
"capidrv-%d: ISDN_CMD_%d, Huh?\n",
2029 card
->contrnr
, c
->command
);
2035 static int if_command(isdn_ctrl
*c
)
2037 capidrv_contr
*card
= findcontrbydriverid(c
->driver
);
2040 return capidrv_command(c
, card
);
2043 "capidrv: if_command %d called with invalid driverId %d!\n",
2044 c
->command
, c
->driver
);
2048 static _cmsg sendcmsg
;
2050 static int if_sendbuf(int id
, int channel
, int doack
, struct sk_buff
*skb
)
2052 capidrv_contr
*card
= findcontrbydriverid(id
);
2053 capidrv_bchan
*bchan
;
2054 capidrv_ncci
*nccip
;
2062 printk(KERN_ERR
"capidrv: if_sendbuf called with invalid driverId %d!\n",
2067 printk(KERN_DEBUG
"capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
2068 card
->contrnr
, len
, skb
, doack
);
2069 bchan
= &card
->bchans
[channel
% card
->nbchan
];
2070 nccip
= bchan
->nccip
;
2071 if (!nccip
|| nccip
->state
!= ST_NCCI_ACTIVE
) {
2072 printk(KERN_ERR
"capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
2073 card
->contrnr
, card
->name
, channel
);
2076 datahandle
= nccip
->datahandle
;
2079 * Here we copy pointer skb->data into the 32-bit 'Data' field.
2080 * The 'Data' field is not used in practice in linux kernel
2081 * (neither in 32 or 64 bit), but should have some value,
2082 * since a CAPI message trace will display it.
2084 * The correct value in the 32 bit case is the address of the
2085 * data, in 64 bit it makes no sense, we use 0 there.
2091 data
= (unsigned long) skb
->data
;
2094 capi_fill_DATA_B3_REQ(&sendcmsg
, global
.ap
.applid
, card
->msgid
++,
2095 nccip
->ncci
, /* adr */
2097 skb
->len
, /* DataLength */
2098 datahandle
, /* DataHandle */
2102 if (capidrv_add_ack(nccip
, datahandle
, doack
? (int)skb
->len
: -1) < 0)
2105 if (capi_cmsg2message(&sendcmsg
, sendcmsg
.buf
)) {
2106 printk(KERN_ERR
"capidrv-%d: if_sendbuf: parser failure\n",
2110 msglen
= CAPIMSG_LEN(sendcmsg
.buf
);
2111 if (skb_headroom(skb
) < msglen
) {
2112 struct sk_buff
*nskb
= skb_realloc_headroom(skb
, msglen
);
2114 printk(KERN_ERR
"capidrv-%d: if_sendbuf: no memory\n",
2116 (void)capidrv_del_ack(nccip
, datahandle
);
2119 printk(KERN_DEBUG
"capidrv-%d: only %d bytes headroom, need %d\n",
2120 card
->contrnr
, skb_headroom(skb
), msglen
);
2121 memcpy(skb_push(nskb
, msglen
), sendcmsg
.buf
, msglen
);
2122 errcode
= capi20_put_message(&global
.ap
, nskb
);
2123 if (errcode
== CAPI_NOERROR
) {
2125 nccip
->datahandle
++;
2129 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
2130 card
->contrnr
, errcode
, capi_info2str(errcode
));
2131 (void)capidrv_del_ack(nccip
, datahandle
);
2132 dev_kfree_skb(nskb
);
2133 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
2135 memcpy(skb_push(skb
, msglen
), sendcmsg
.buf
, msglen
);
2136 errcode
= capi20_put_message(&global
.ap
, skb
);
2137 if (errcode
== CAPI_NOERROR
) {
2138 nccip
->datahandle
++;
2142 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
2143 card
->contrnr
, errcode
, capi_info2str(errcode
));
2144 skb_pull(skb
, msglen
);
2145 (void)capidrv_del_ack(nccip
, datahandle
);
2146 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
2150 static int if_readstat(u8 __user
*buf
, int len
, int id
, int channel
)
2152 capidrv_contr
*card
= findcontrbydriverid(id
);
2157 printk(KERN_ERR
"capidrv: if_readstat called with invalid driverId %d!\n",
2162 for (p
= buf
, count
= 0; count
< len
; p
++, count
++) {
2163 if (put_user(*card
->q931_read
++, p
))
2165 if (card
->q931_read
> card
->q931_end
)
2166 card
->q931_read
= card
->q931_buf
;
2172 static void enable_dchannel_trace(capidrv_contr
*card
)
2174 u8 manufacturer
[CAPI_MANUFACTURER_LEN
];
2175 capi_version version
;
2176 u16 contr
= card
->contrnr
;
2180 errcode
= capi20_get_manufacturer(contr
, manufacturer
);
2181 if (errcode
!= CAPI_NOERROR
) {
2182 printk(KERN_ERR
"%s: can't get manufacturer (0x%x)\n",
2183 card
->name
, errcode
);
2186 if (strstr(manufacturer
, "AVM") == NULL
) {
2187 printk(KERN_ERR
"%s: not from AVM, no d-channel trace possible (%s)\n",
2188 card
->name
, manufacturer
);
2191 errcode
= capi20_get_version(contr
, &version
);
2192 if (errcode
!= CAPI_NOERROR
) {
2193 printk(KERN_ERR
"%s: can't get version (0x%x)\n",
2194 card
->name
, errcode
);
2197 avmversion
[0] = (version
.majormanuversion
>> 4) & 0x0f;
2198 avmversion
[1] = (version
.majormanuversion
<< 4) & 0xf0;
2199 avmversion
[1] |= (version
.minormanuversion
>> 4) & 0x0f;
2200 avmversion
[2] |= version
.minormanuversion
& 0x0f;
2202 if (avmversion
[0] > 3 || (avmversion
[0] == 3 && avmversion
[1] > 5)) {
2203 printk(KERN_INFO
"%s: D2 trace enabled\n", card
->name
);
2204 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
2207 0x214D5641, /* ManuID */
2210 (_cstruct
)"\004\200\014\000\000");
2212 printk(KERN_INFO
"%s: D3 trace enabled\n", card
->name
);
2213 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
2216 0x214D5641, /* ManuID */
2219 (_cstruct
)"\004\002\003\000\000");
2221 send_message(card
, &cmdcmsg
);
2225 static void send_listen(capidrv_contr
*card
)
2227 capi_fill_LISTEN_REQ(&cmdcmsg
, global
.ap
.applid
,
2229 card
->contrnr
, /* controller */
2230 1 << 6, /* Infomask */
2234 listen_change_state(card
, EV_LISTEN_REQ
);
2235 send_message(card
, &cmdcmsg
);
2238 static void listentimerfunc(unsigned long x
)
2240 capidrv_contr
*card
= (capidrv_contr
*)x
;
2241 if (card
->state
!= ST_LISTEN_NONE
&& card
->state
!= ST_LISTEN_ACTIVE
)
2242 printk(KERN_ERR
"%s: controller dead ??\n", card
->name
);
2244 mod_timer(&card
->listentimer
, jiffies
+ 60 * HZ
);
2248 static int capidrv_addcontr(u16 contr
, struct capi_profile
*profp
)
2250 capidrv_contr
*card
;
2251 unsigned long flags
;
2256 sprintf(id
, "capidrv-%d", contr
);
2257 if (!try_module_get(THIS_MODULE
)) {
2258 printk(KERN_WARNING
"capidrv: (%s) Could not reserve module\n", id
);
2261 if (!(card
= kzalloc(sizeof(capidrv_contr
), GFP_ATOMIC
))) {
2263 "capidrv: (%s) Could not allocate contr-struct.\n", id
);
2266 card
->owner
= THIS_MODULE
;
2267 setup_timer(&card
->listentimer
, listentimerfunc
, (unsigned long)card
);
2268 strcpy(card
->name
, id
);
2269 card
->contrnr
= contr
;
2270 card
->nbchan
= profp
->nbchannel
;
2271 card
->bchans
= kmalloc(sizeof(capidrv_bchan
) * card
->nbchan
, GFP_ATOMIC
);
2272 if (!card
->bchans
) {
2274 "capidrv: (%s) Could not allocate bchan-structs.\n", id
);
2275 module_put(card
->owner
);
2279 card
->interface
.channels
= profp
->nbchannel
;
2280 card
->interface
.maxbufsize
= 2048;
2281 card
->interface
.command
= if_command
;
2282 card
->interface
.writebuf_skb
= if_sendbuf
;
2283 card
->interface
.writecmd
= NULL
;
2284 card
->interface
.readstat
= if_readstat
;
2285 card
->interface
.features
=
2286 ISDN_FEATURE_L2_HDLC
|
2287 ISDN_FEATURE_L2_TRANS
|
2288 ISDN_FEATURE_L3_TRANS
|
2289 ISDN_FEATURE_P_UNKNOWN
|
2290 ISDN_FEATURE_L2_X75I
|
2291 ISDN_FEATURE_L2_X75UI
|
2292 ISDN_FEATURE_L2_X75BUI
;
2293 if (profp
->support1
& (1 << 2))
2294 card
->interface
.features
|=
2295 ISDN_FEATURE_L2_V11096
|
2296 ISDN_FEATURE_L2_V11019
|
2297 ISDN_FEATURE_L2_V11038
;
2298 if (profp
->support1
& (1 << 8))
2299 card
->interface
.features
|= ISDN_FEATURE_L2_MODEM
;
2300 card
->interface
.hl_hdrlen
= 22; /* len of DATA_B3_REQ */
2301 strncpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
) - 1);
2304 card
->q931_read
= card
->q931_buf
;
2305 card
->q931_write
= card
->q931_buf
;
2306 card
->q931_end
= card
->q931_buf
+ sizeof(card
->q931_buf
) - 1;
2308 if (!register_isdn(&card
->interface
)) {
2309 printk(KERN_ERR
"capidrv: Unable to register contr %s\n", id
);
2310 kfree(card
->bchans
);
2311 module_put(card
->owner
);
2315 card
->myid
= card
->interface
.channels
;
2316 memset(card
->bchans
, 0, sizeof(capidrv_bchan
) * card
->nbchan
);
2317 for (i
= 0; i
< card
->nbchan
; i
++) {
2318 card
->bchans
[i
].contr
= card
;
2321 spin_lock_irqsave(&global_lock
, flags
);
2322 card
->next
= global
.contr_list
;
2323 global
.contr_list
= card
;
2325 spin_unlock_irqrestore(&global_lock
, flags
);
2327 cmd
.command
= ISDN_STAT_RUN
;
2328 cmd
.driver
= card
->myid
;
2329 card
->interface
.statcallb(&cmd
);
2331 card
->cipmask
= 0x1FFF03FF; /* any */
2335 mod_timer(&card
->listentimer
, jiffies
+ 60 * HZ
);
2337 printk(KERN_INFO
"%s: now up (%d B channels)\n",
2338 card
->name
, card
->nbchan
);
2340 enable_dchannel_trace(card
);
2345 static int capidrv_delcontr(u16 contr
)
2347 capidrv_contr
**pp
, *card
;
2348 unsigned long flags
;
2351 spin_lock_irqsave(&global_lock
, flags
);
2352 for (card
= global
.contr_list
; card
; card
= card
->next
) {
2353 if (card
->contrnr
== contr
)
2357 spin_unlock_irqrestore(&global_lock
, flags
);
2358 printk(KERN_ERR
"capidrv: delcontr: no contr %u\n", contr
);
2362 /* FIXME: maybe a race condition the card should be removed
2363 * here from global list /kkeil
2365 spin_unlock_irqrestore(&global_lock
, flags
);
2367 del_timer(&card
->listentimer
);
2370 printk(KERN_DEBUG
"capidrv-%d: id=%d unloading\n",
2371 card
->contrnr
, card
->myid
);
2373 cmd
.command
= ISDN_STAT_STOP
;
2374 cmd
.driver
= card
->myid
;
2375 card
->interface
.statcallb(&cmd
);
2377 while (card
->nbchan
) {
2379 cmd
.command
= ISDN_STAT_DISCH
;
2380 cmd
.driver
= card
->myid
;
2381 cmd
.arg
= card
->nbchan
- 1;
2382 cmd
.parm
.num
[0] = 0;
2384 printk(KERN_DEBUG
"capidrv-%d: id=%d disable chan=%ld\n",
2385 card
->contrnr
, card
->myid
, cmd
.arg
);
2386 card
->interface
.statcallb(&cmd
);
2388 if (card
->bchans
[card
->nbchan
- 1].nccip
)
2389 free_ncci(card
, card
->bchans
[card
->nbchan
- 1].nccip
);
2390 if (card
->bchans
[card
->nbchan
- 1].plcip
)
2391 free_plci(card
, card
->bchans
[card
->nbchan
- 1].plcip
);
2392 if (card
->plci_list
)
2393 printk(KERN_ERR
"capidrv: bug in free_plci()\n");
2396 kfree(card
->bchans
);
2397 card
->bchans
= NULL
;
2400 printk(KERN_DEBUG
"capidrv-%d: id=%d isdn unload\n",
2401 card
->contrnr
, card
->myid
);
2403 cmd
.command
= ISDN_STAT_UNLOAD
;
2404 cmd
.driver
= card
->myid
;
2405 card
->interface
.statcallb(&cmd
);
2408 printk(KERN_DEBUG
"capidrv-%d: id=%d remove contr from list\n",
2409 card
->contrnr
, card
->myid
);
2411 spin_lock_irqsave(&global_lock
, flags
);
2412 for (pp
= &global
.contr_list
; *pp
; pp
= &(*pp
)->next
) {
2420 spin_unlock_irqrestore(&global_lock
, flags
);
2422 module_put(card
->owner
);
2423 printk(KERN_INFO
"%s: now down.\n", card
->name
);
2430 lower_callback(struct notifier_block
*nb
, unsigned long val
, void *v
)
2432 capi_profile profile
;
2433 u32 contr
= (long)v
;
2437 printk(KERN_INFO
"capidrv: controller %hu up\n", contr
);
2438 if (capi20_get_profile(contr
, &profile
) == CAPI_NOERROR
)
2439 (void) capidrv_addcontr(contr
, &profile
);
2442 printk(KERN_INFO
"capidrv: controller %hu down\n", contr
);
2443 (void) capidrv_delcontr(contr
);
2450 * /proc/capi/capidrv:
2451 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2453 static int capidrv_proc_show(struct seq_file
*m
, void *v
)
2455 seq_printf(m
, "%lu %lu %lu %lu\n",
2456 global
.ap
.nrecvctlpkt
,
2457 global
.ap
.nrecvdatapkt
,
2458 global
.ap
.nsentctlpkt
,
2459 global
.ap
.nsentdatapkt
);
2463 static int capidrv_proc_open(struct inode
*inode
, struct file
*file
)
2465 return single_open(file
, capidrv_proc_show
, NULL
);
2468 static const struct file_operations capidrv_proc_fops
= {
2469 .owner
= THIS_MODULE
,
2470 .open
= capidrv_proc_open
,
2472 .llseek
= seq_lseek
,
2473 .release
= single_release
,
2476 static void __init
proc_init(void)
2478 proc_create("capi/capidrv", 0, NULL
, &capidrv_proc_fops
);
2481 static void __exit
proc_exit(void)
2483 remove_proc_entry("capi/capidrv", NULL
);
2486 static struct notifier_block capictr_nb
= {
2487 .notifier_call
= lower_callback
,
2490 static int __init
capidrv_init(void)
2492 capi_profile profile
;
2496 global
.ap
.rparam
.level3cnt
= -2; /* number of bchannels twice */
2497 global
.ap
.rparam
.datablkcnt
= 16;
2498 global
.ap
.rparam
.datablklen
= 2048;
2500 global
.ap
.recv_message
= capidrv_recv_message
;
2501 errcode
= capi20_register(&global
.ap
);
2506 register_capictr_notifier(&capictr_nb
);
2508 errcode
= capi20_get_profile(0, &profile
);
2509 if (errcode
!= CAPI_NOERROR
) {
2510 unregister_capictr_notifier(&capictr_nb
);
2511 capi20_release(&global
.ap
);
2515 ncontr
= profile
.ncontroller
;
2516 for (contr
= 1; contr
<= ncontr
; contr
++) {
2517 errcode
= capi20_get_profile(contr
, &profile
);
2518 if (errcode
!= CAPI_NOERROR
)
2520 (void) capidrv_addcontr(contr
, &profile
);
2527 static void __exit
capidrv_exit(void)
2529 unregister_capictr_notifier(&capictr_nb
);
2530 capi20_release(&global
.ap
);
2535 module_init(capidrv_init
);
2536 module_exit(capidrv_exit
);