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 capi_cmsg2message(cmsg
, cmsg
->buf
);
510 len
= CAPIMSG_LEN(cmsg
->buf
);
511 skb
= alloc_skb(len
, GFP_ATOMIC
);
513 printk(KERN_ERR
"capidrv::send_message: can't allocate mem\n");
516 memcpy(skb_put(skb
, len
), cmsg
->buf
, len
);
517 if (capi20_put_message(&global
.ap
, skb
) != CAPI_NOERROR
)
521 /* -------- state machine -------------------------------------------- */
523 struct listenstatechange
{
529 static struct listenstatechange listentable
[] =
531 {ST_LISTEN_NONE
, ST_LISTEN_WAIT_CONF
, EV_LISTEN_REQ
},
532 {ST_LISTEN_ACTIVE
, ST_LISTEN_ACTIVE_WAIT_CONF
, EV_LISTEN_REQ
},
533 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_ERROR
},
534 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_ERROR
},
535 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
536 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
537 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
538 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
542 static void listen_change_state(capidrv_contr
*card
, int event
)
544 struct listenstatechange
*p
= listentable
;
546 if (card
->state
== p
->actstate
&& p
->event
== event
) {
548 printk(KERN_DEBUG
"capidrv-%d: listen_change_state %d -> %d\n",
549 card
->contrnr
, card
->state
, p
->nextstate
);
550 card
->state
= p
->nextstate
;
555 printk(KERN_ERR
"capidrv-%d: listen_change_state state=%d event=%d ????\n",
556 card
->contrnr
, card
->state
, event
);
560 /* ------------------------------------------------------------------ */
562 static void p0(capidrv_contr
*card
, capidrv_plci
*plci
)
566 card
->bchans
[plci
->chan
].contr
= NULL
;
567 cmd
.command
= ISDN_STAT_DHUP
;
568 cmd
.driver
= card
->myid
;
569 cmd
.arg
= plci
->chan
;
570 card
->interface
.statcallb(&cmd
);
571 free_plci(card
, plci
);
574 /* ------------------------------------------------------------------ */
576 struct plcistatechange
{
580 void (*changefunc
)(capidrv_contr
*card
, capidrv_plci
*plci
);
583 static struct plcistatechange plcitable
[] =
586 {ST_PLCI_NONE
, ST_PLCI_OUTGOING
, EV_PLCI_CONNECT_REQ
, NULL
},
587 {ST_PLCI_NONE
, ST_PLCI_ALLOCATED
, EV_PLCI_FACILITY_IND_UP
, NULL
},
588 {ST_PLCI_NONE
, ST_PLCI_INCOMING
, EV_PLCI_CONNECT_IND
, NULL
},
589 {ST_PLCI_NONE
, ST_PLCI_RESUMEING
, EV_PLCI_RESUME_REQ
, NULL
},
591 {ST_PLCI_OUTGOING
, ST_PLCI_NONE
, EV_PLCI_CONNECT_CONF_ERROR
, p0
},
592 {ST_PLCI_OUTGOING
, ST_PLCI_ALLOCATED
, EV_PLCI_CONNECT_CONF_OK
, NULL
},
594 {ST_PLCI_ALLOCATED
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
595 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
596 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
597 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
599 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
600 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
601 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
602 {ST_PLCI_ACTIVE
, ST_PLCI_HELD
, EV_PLCI_HOLD_IND
, NULL
},
603 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_SUSPEND_IND
, NULL
},
605 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
606 {ST_PLCI_INCOMING
, ST_PLCI_FACILITY_IND
, EV_PLCI_FACILITY_IND_UP
, NULL
},
607 {ST_PLCI_INCOMING
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_RESP
, NULL
},
608 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
609 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
610 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
611 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CD_IND
, NULL
},
613 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
614 {ST_PLCI_FACILITY_IND
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
615 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
616 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
617 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
619 {ST_PLCI_ACCEPTING
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
620 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
621 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
622 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
624 {ST_PLCI_DISCONNECTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
626 {ST_PLCI_DISCONNECTED
, ST_PLCI_NONE
, EV_PLCI_DISCONNECT_RESP
, p0
},
628 {ST_PLCI_RESUMEING
, ST_PLCI_NONE
, EV_PLCI_RESUME_CONF_ERROR
, p0
},
629 {ST_PLCI_RESUMEING
, ST_PLCI_RESUME
, EV_PLCI_RESUME_CONF_OK
, NULL
},
631 {ST_PLCI_RESUME
, ST_PLCI_ACTIVE
, EV_PLCI_RESUME_IND
, NULL
},
633 {ST_PLCI_HELD
, ST_PLCI_ACTIVE
, EV_PLCI_RETRIEVE_IND
, NULL
},
637 static void plci_change_state(capidrv_contr
*card
, capidrv_plci
*plci
, int event
)
639 struct plcistatechange
*p
= plcitable
;
641 if (plci
->state
== p
->actstate
&& p
->event
== event
) {
643 printk(KERN_DEBUG
"capidrv-%d: plci_change_state:0x%x %d -> %d\n",
644 card
->contrnr
, plci
->plci
, plci
->state
, p
->nextstate
);
645 plci
->state
= p
->nextstate
;
647 p
->changefunc(card
, plci
);
652 printk(KERN_ERR
"capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
653 card
->contrnr
, plci
->plci
, plci
->state
, event
);
656 /* ------------------------------------------------------------------ */
660 static void n0(capidrv_contr
*card
, capidrv_ncci
*ncci
)
664 capi_fill_DISCONNECT_REQ(&cmsg
,
668 NULL
, /* BChannelinformation */
669 NULL
, /* Keypadfacility */
670 NULL
, /* Useruserdata */ /* $$$$ */
671 NULL
/* Facilitydataarray */
673 plci_change_state(card
, ncci
->plcip
, EV_PLCI_DISCONNECT_REQ
);
674 send_message(card
, &cmsg
);
676 cmd
.command
= ISDN_STAT_BHUP
;
677 cmd
.driver
= card
->myid
;
678 cmd
.arg
= ncci
->chan
;
679 card
->interface
.statcallb(&cmd
);
680 free_ncci(card
, ncci
);
683 /* ------------------------------------------------------------------ */
685 struct nccistatechange
{
689 void (*changefunc
)(capidrv_contr
*card
, capidrv_ncci
*ncci
);
692 static struct nccistatechange nccitable
[] =
695 {ST_NCCI_NONE
, ST_NCCI_OUTGOING
, EV_NCCI_CONNECT_B3_REQ
, NULL
},
696 {ST_NCCI_NONE
, ST_NCCI_INCOMING
, EV_NCCI_CONNECT_B3_IND
, NULL
},
698 {ST_NCCI_OUTGOING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_CONF_OK
, NULL
},
699 {ST_NCCI_OUTGOING
, ST_NCCI_NONE
, EV_NCCI_CONNECT_B3_CONF_ERROR
, n0
},
701 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_CONNECT_B3_REJECT
, NULL
},
702 {ST_NCCI_INCOMING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_RESP
, NULL
},
703 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
704 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
706 {ST_NCCI_ALLOCATED
, ST_NCCI_ACTIVE
, EV_NCCI_CONNECT_B3_ACTIVE_IND
, NULL
},
707 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
708 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
710 {ST_NCCI_ACTIVE
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
711 {ST_NCCI_ACTIVE
, ST_NCCI_RESETING
, EV_NCCI_RESET_B3_REQ
, NULL
},
712 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
713 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
715 {ST_NCCI_RESETING
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
716 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
717 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
719 {ST_NCCI_DISCONNECTING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
720 {ST_NCCI_DISCONNECTING
, ST_NCCI_PREVIOUS
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
, NULL
},
722 {ST_NCCI_DISCONNECTED
, ST_NCCI_NONE
, EV_NCCI_DISCONNECT_B3_RESP
, n0
},
726 static void ncci_change_state(capidrv_contr
*card
, capidrv_ncci
*ncci
, int event
)
728 struct nccistatechange
*p
= nccitable
;
730 if (ncci
->state
== p
->actstate
&& p
->event
== event
) {
732 printk(KERN_DEBUG
"capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
733 card
->contrnr
, ncci
->ncci
, ncci
->state
, p
->nextstate
);
734 if (p
->nextstate
== ST_NCCI_PREVIOUS
) {
735 ncci
->state
= ncci
->oldstate
;
736 ncci
->oldstate
= p
->actstate
;
738 ncci
->oldstate
= p
->actstate
;
739 ncci
->state
= p
->nextstate
;
742 p
->changefunc(card
, ncci
);
747 printk(KERN_ERR
"capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
748 card
->contrnr
, ncci
->ncci
, ncci
->state
, event
);
751 /* ------------------------------------------------------------------- */
753 static inline int new_bchan(capidrv_contr
*card
)
756 for (i
= 0; i
< card
->nbchan
; i
++) {
757 if (card
->bchans
[i
].plcip
== NULL
) {
758 card
->bchans
[i
].disconnecting
= 0;
765 /* ------------------------------------------------------------------- */
766 static char *capi_info2str(u16 reason
)
768 #ifndef CONFIG_ISDN_CAPI_CAPIDRV_VERBOSE
773 /*-- informative values (corresponding message was processed) -----*/
775 return "NCPI not supported by current protocol, NCPI ignored";
777 return "Flags not supported by current protocol, flags ignored";
779 return "Alert already sent by another application";
781 /*-- error information concerning CAPI_REGISTER -----*/
783 return "Too many applications";
785 return "Logical block size too small, must be at least 128 Bytes";
787 return "Buffer exceeds 64 kByte";
789 return "Message buffer size too small, must be at least 1024 Bytes";
791 return "Max. number of logical connections not supported";
795 return "The message could not be accepted because of an internal busy condition";
797 return "OS resource error (no memory ?)";
799 return "CAPI not installed";
801 return "Controller does not support external equipment";
803 return "Controller does only support external equipment";
805 /*-- error information concerning message exchange functions -----*/
807 return "Illegal application number";
809 return "Illegal command or subcommand or message length less than 12 bytes";
811 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";
813 return "Queue is empty";
815 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
817 return "Unknown notification parameter";
819 return "The Message could not be accepted because of an internal busy condition";
821 return "OS Resource error (no memory ?)";
823 return "CAPI not installed";
825 return "Controller does not support external equipment";
827 return "Controller does only support external equipment";
829 /*-- error information concerning resource / coding problems -----*/
831 return "Message not supported in current state";
833 return "Illegal Controller / PLCI / NCCI";
835 return "Out of PLCI";
837 return "Out of NCCI";
839 return "Out of LISTEN";
841 return "Out of FAX resources (protocol T.30)";
843 return "Illegal message parameter coding";
845 /*-- error information concerning requested services -----*/
847 return "B1 protocol not supported";
849 return "B2 protocol not supported";
851 return "B3 protocol not supported";
853 return "B1 protocol parameter not supported";
855 return "B2 protocol parameter not supported";
857 return "B3 protocol parameter not supported";
859 return "B protocol combination not supported";
861 return "NCPI not supported";
863 return "CIP Value unknown";
865 return "Flags not supported (reserved bits)";
867 return "Facility not supported";
869 return "Data length not supported by current protocol";
871 return "Reset procedure not supported by current protocol";
873 /*-- informations about the clearing of a physical connection -----*/
875 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
877 return "Protocol error layer 2";
879 return "Protocol error layer 3";
881 return "Another application got that call";
882 /*-- T.30 specific reasons -----*/
884 return "Connecting not successful (remote station is no FAX G3 machine)";
886 return "Connecting not successful (training error)";
888 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
890 return "Disconnected during transfer (remote abort)";
892 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
894 return "Disconnected during transfer (local tx data underrun)";
896 return "Disconnected during transfer (local rx data overflow)";
898 return "Disconnected during transfer (local abort)";
900 return "Illegal parameter coding (e.g. SFF coding error)";
902 /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
903 case 0x3481: return "Unallocated (unassigned) number";
904 case 0x3482: return "No route to specified transit network";
905 case 0x3483: return "No route to destination";
906 case 0x3486: return "Channel unacceptable";
908 return "Call awarded and being delivered in an established channel";
909 case 0x3490: return "Normal call clearing";
910 case 0x3491: return "User busy";
911 case 0x3492: return "No user responding";
912 case 0x3493: return "No answer from user (user alerted)";
913 case 0x3495: return "Call rejected";
914 case 0x3496: return "Number changed";
915 case 0x349A: return "Non-selected user clearing";
916 case 0x349B: return "Destination out of order";
917 case 0x349C: return "Invalid number format";
918 case 0x349D: return "Facility rejected";
919 case 0x349E: return "Response to STATUS ENQUIRY";
920 case 0x349F: return "Normal, unspecified";
921 case 0x34A2: return "No circuit / channel available";
922 case 0x34A6: return "Network out of order";
923 case 0x34A9: return "Temporary failure";
924 case 0x34AA: return "Switching equipment congestion";
925 case 0x34AB: return "Access information discarded";
926 case 0x34AC: return "Requested circuit / channel not available";
927 case 0x34AF: return "Resources unavailable, unspecified";
928 case 0x34B1: return "Quality of service unavailable";
929 case 0x34B2: return "Requested facility not subscribed";
930 case 0x34B9: return "Bearer capability not authorized";
931 case 0x34BA: return "Bearer capability not presently available";
932 case 0x34BF: return "Service or option not available, unspecified";
933 case 0x34C1: return "Bearer capability not implemented";
934 case 0x34C2: return "Channel type not implemented";
935 case 0x34C5: return "Requested facility not implemented";
936 case 0x34C6: return "Only restricted digital information bearer capability is available";
937 case 0x34CF: return "Service or option not implemented, unspecified";
938 case 0x34D1: return "Invalid call reference value";
939 case 0x34D2: return "Identified channel does not exist";
940 case 0x34D3: return "A suspended call exists, but this call identity does not";
941 case 0x34D4: return "Call identity in use";
942 case 0x34D5: return "No call suspended";
943 case 0x34D6: return "Call having the requested call identity has been cleared";
944 case 0x34D8: return "Incompatible destination";
945 case 0x34DB: return "Invalid transit network selection";
946 case 0x34DF: return "Invalid message, unspecified";
947 case 0x34E0: return "Mandatory information element is missing";
948 case 0x34E1: return "Message type non-existent or not implemented";
949 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
950 case 0x34E3: return "Information element non-existent or not implemented";
951 case 0x34E4: return "Invalid information element contents";
952 case 0x34E5: return "Message not compatible with call state";
953 case 0x34E6: return "Recovery on timer expiry";
954 case 0x34EF: return "Protocol error, unspecified";
955 case 0x34FF: return "Interworking, unspecified";
957 default: return "No additional information";
962 static void handle_controller(_cmsg
*cmsg
)
964 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
967 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
968 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
969 cmsg
->adr
.adrController
& 0x7f);
972 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
974 case CAPI_LISTEN_CONF
: /* Controller */
976 printk(KERN_DEBUG
"capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
977 card
->contrnr
, cmsg
->Info
, capi_info2str(cmsg
->Info
), card
->cipmask
);
979 listen_change_state(card
, EV_LISTEN_CONF_ERROR
);
980 } else if (card
->cipmask
== 0) {
981 listen_change_state(card
, EV_LISTEN_CONF_EMPTY
);
983 listen_change_state(card
, EV_LISTEN_CONF_OK
);
987 case CAPI_MANUFACTURER_IND
: /* Controller */
988 if (cmsg
->ManuID
== 0x214D5641
990 && cmsg
->Function
== 1) {
991 u8
*data
= cmsg
->ManuData
+ 3;
992 u16 len
= cmsg
->ManuData
[0];
996 len
= (cmsg
->ManuData
[1] | (cmsg
->ManuData
[2] << 8));
1000 layer
= ((*(data
- 1)) << 8) | *(data
- 2);
1002 direction
= (layer
& 0x200) ? 0 : 1;
1003 else direction
= (layer
& 0x800) ? 0 : 1;
1004 if (layer
& 0x0C00) {
1005 if ((layer
& 0xff) == 0x80) {
1006 handle_dtrace_data(card
, direction
, 1, data
, len
);
1009 } else if ((layer
& 0xff) < 0x80) {
1010 handle_dtrace_data(card
, direction
, 0, data
, len
);
1013 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
1015 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1016 cmsg
->adr
.adrController
, layer
);
1020 case CAPI_MANUFACTURER_CONF
: /* Controller */
1021 if (cmsg
->ManuID
== 0x214D5641) {
1023 switch (cmsg
->Class
) {
1025 case 1: s
= "unknown class"; break;
1026 case 2: s
= "unknown function"; break;
1027 default: s
= "unknown error"; break;
1030 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x function %d: %s\n",
1032 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1033 cmsg
->adr
.adrController
,
1038 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1040 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1042 case CAPI_INFO_IND
: /* Controller/plci */
1044 case CAPI_INFO_CONF
: /* Controller/plci */
1048 printk(KERN_ERR
"capidrv-%d: got %s from controller 0x%x ???",
1050 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1051 cmsg
->adr
.adrController
);
1056 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x ignored\n",
1058 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1059 cmsg
->adr
.adrController
);
1062 static void handle_incoming_call(capidrv_contr
*card
, _cmsg
*cmsg
)
1064 capidrv_plci
*plcip
;
1065 capidrv_bchan
*bchan
;
1069 if ((chan
= new_bchan(card
)) == -1) {
1070 printk(KERN_ERR
"capidrv-%d: incoming call on not existing bchan ?\n", card
->contrnr
);
1073 bchan
= &card
->bchans
[chan
];
1074 if ((plcip
= new_plci(card
, chan
)) == NULL
) {
1075 printk(KERN_ERR
"capidrv-%d: incoming call: no memory, sorry.\n", card
->contrnr
);
1078 bchan
->incoming
= 1;
1079 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1080 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_IND
);
1082 cmd
.command
= ISDN_STAT_ICALL
;
1083 cmd
.driver
= card
->myid
;
1085 memset(&cmd
.parm
.setup
, 0, sizeof(cmd
.parm
.setup
));
1086 strncpy(cmd
.parm
.setup
.phone
,
1087 cmsg
->CallingPartyNumber
+ 3,
1088 cmsg
->CallingPartyNumber
[0] - 2);
1089 strncpy(cmd
.parm
.setup
.eazmsn
,
1090 cmsg
->CalledPartyNumber
+ 2,
1091 cmsg
->CalledPartyNumber
[0] - 1);
1092 cmd
.parm
.setup
.si1
= cip2si1(cmsg
->CIPValue
);
1093 cmd
.parm
.setup
.si2
= cip2si2(cmsg
->CIPValue
);
1094 cmd
.parm
.setup
.plan
= cmsg
->CallingPartyNumber
[1];
1095 cmd
.parm
.setup
.screen
= cmsg
->CallingPartyNumber
[2];
1097 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s\n",
1099 cmd
.parm
.setup
.phone
,
1102 cmd
.parm
.setup
.eazmsn
);
1104 if (cmd
.parm
.setup
.si1
== 1 && cmd
.parm
.setup
.si2
!= 0) {
1105 printk(KERN_INFO
"capidrv-%d: patching si2=%d to 0 for VBOX\n",
1107 cmd
.parm
.setup
.si2
);
1108 cmd
.parm
.setup
.si2
= 0;
1111 switch (card
->interface
.statcallb(&cmd
)) {
1114 /* No device matching this call.
1115 * and isdn_common.c has send a HANGUP command
1116 * which is ignored in state ST_PLCI_INCOMING,
1117 * so we send RESP to ignore the call
1119 capi_cmsg_answer(cmsg
);
1120 cmsg
->Reject
= 1; /* ignore */
1121 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1122 send_message(card
, cmsg
);
1123 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
1125 cmd
.parm
.setup
.phone
,
1128 cmd
.parm
.setup
.eazmsn
);
1131 /* At least one device matching this call (RING on ttyI)
1132 * HL-driver may send ALERTING on the D-channel in this
1134 * really means: RING on ttyI or a net interface
1135 * accepted this call already.
1137 * If the call was accepted, state has already changed,
1138 * and CONNECT_RESP already sent.
1140 if (plcip
->state
== ST_PLCI_INCOMING
) {
1141 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
1143 cmd
.parm
.setup
.phone
,
1146 cmd
.parm
.setup
.eazmsn
);
1147 capi_fill_ALERT_REQ(cmsg
,
1150 plcip
->plci
, /* adr */
1151 NULL
,/* BChannelinformation */
1152 NULL
,/* Keypadfacility */
1153 NULL
,/* Useruserdata */
1154 NULL
/* Facilitydataarray */
1156 plcip
->msgid
= cmsg
->Messagenumber
;
1157 send_message(card
, cmsg
);
1159 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
1161 cmd
.parm
.setup
.phone
,
1164 cmd
.parm
.setup
.eazmsn
);
1168 case 2: /* Call will be rejected. */
1169 capi_cmsg_answer(cmsg
);
1170 cmsg
->Reject
= 2; /* reject call, normal call clearing */
1171 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1172 send_message(card
, cmsg
);
1176 /* An error happened. (Invalid parameters for example.) */
1177 capi_cmsg_answer(cmsg
);
1178 cmsg
->Reject
= 8; /* reject call,
1179 destination out of order */
1180 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
1181 send_message(card
, cmsg
);
1187 static void handle_plci(_cmsg
*cmsg
)
1189 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1190 capidrv_plci
*plcip
;
1195 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1196 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1197 cmsg
->adr
.adrController
& 0x7f);
1200 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1202 case CAPI_DISCONNECT_IND
: /* plci */
1204 printk(KERN_INFO
"capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1206 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1207 cmsg
->Reason
, capi_info2str(cmsg
->Reason
), cmsg
->adr
.adrPLCI
);
1209 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
))) {
1210 capi_cmsg_answer(cmsg
);
1211 send_message(card
, cmsg
);
1214 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1215 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_IND
);
1216 capi_cmsg_answer(cmsg
);
1217 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_RESP
);
1218 send_message(card
, cmsg
);
1221 case CAPI_DISCONNECT_CONF
: /* plci */
1223 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1225 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1226 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1229 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1232 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1235 case CAPI_ALERT_CONF
: /* plci */
1237 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1239 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1240 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1245 case CAPI_CONNECT_IND
: /* plci */
1246 handle_incoming_call(card
, cmsg
);
1249 case CAPI_CONNECT_CONF
: /* plci */
1251 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1253 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1254 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1257 if (!(plcip
= find_plci_by_msgid(card
, cmsg
->Messagenumber
)))
1260 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1262 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_ERROR
);
1264 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_OK
);
1268 case CAPI_CONNECT_ACTIVE_IND
: /* plci */
1270 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1273 if (card
->bchans
[plcip
->chan
].incoming
) {
1274 capi_cmsg_answer(cmsg
);
1275 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_ACTIVE_IND
);
1276 send_message(card
, cmsg
);
1278 capidrv_ncci
*nccip
;
1279 capi_cmsg_answer(cmsg
);
1280 send_message(card
, cmsg
);
1282 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrPLCI
);
1285 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1288 capi_fill_CONNECT_B3_REQ(cmsg
,
1291 plcip
->plci
, /* adr */
1294 nccip
->msgid
= cmsg
->Messagenumber
;
1295 plci_change_state(card
, plcip
,
1296 EV_PLCI_CONNECT_ACTIVE_IND
);
1297 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_REQ
);
1298 send_message(card
, cmsg
);
1299 cmd
.command
= ISDN_STAT_DCONN
;
1300 cmd
.driver
= card
->myid
;
1301 cmd
.arg
= plcip
->chan
;
1302 card
->interface
.statcallb(&cmd
);
1306 case CAPI_INFO_IND
: /* Controller/plci */
1308 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1311 if (cmsg
->InfoNumber
== 0x4000) {
1312 if (cmsg
->InfoElement
[0] == 4) {
1313 cmd
.command
= ISDN_STAT_CINF
;
1314 cmd
.driver
= card
->myid
;
1315 cmd
.arg
= plcip
->chan
;
1316 sprintf(cmd
.parm
.num
, "%lu",
1318 ((u32
) cmsg
->InfoElement
[1]
1319 | ((u32
) (cmsg
->InfoElement
[2]) << 8)
1320 | ((u32
) (cmsg
->InfoElement
[3]) << 16)
1321 | ((u32
) (cmsg
->InfoElement
[4]) << 24)));
1322 card
->interface
.statcallb(&cmd
);
1326 cdb
= capi_cmsg2str(cmsg
);
1328 printk(KERN_WARNING
"capidrv-%d: %s\n",
1329 card
->contrnr
, cdb
->buf
);
1332 printk(KERN_WARNING
"capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n",
1333 card
->contrnr
, cmsg
->InfoNumber
);
1337 case CAPI_CONNECT_ACTIVE_CONF
: /* plci */
1339 case CAPI_SELECT_B_PROTOCOL_CONF
: /* plci */
1341 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1343 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1346 case CAPI_INFO_CONF
: /* Controller/plci */
1350 printk(KERN_ERR
"capidrv-%d: got %s for plci 0x%x ???",
1352 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1357 printk(KERN_INFO
"capidrv-%d: %s for plci 0x%x ignored\n",
1359 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1363 printk(KERN_ERR
"capidrv-%d: %s: plci 0x%x not found\n",
1365 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1370 static void handle_ncci(_cmsg
*cmsg
)
1372 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1373 capidrv_plci
*plcip
;
1374 capidrv_ncci
*nccip
;
1379 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1380 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1381 cmsg
->adr
.adrController
& 0x7f);
1384 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1386 case CAPI_CONNECT_B3_ACTIVE_IND
: /* ncci */
1387 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1390 capi_cmsg_answer(cmsg
);
1391 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_ACTIVE_IND
);
1392 send_message(card
, cmsg
);
1394 cmd
.command
= ISDN_STAT_BCONN
;
1395 cmd
.driver
= card
->myid
;
1396 cmd
.arg
= nccip
->chan
;
1397 card
->interface
.statcallb(&cmd
);
1399 printk(KERN_INFO
"capidrv-%d: chan %d up with ncci 0x%x\n",
1400 card
->contrnr
, nccip
->chan
, nccip
->ncci
);
1403 case CAPI_CONNECT_B3_ACTIVE_CONF
: /* ncci */
1406 case CAPI_CONNECT_B3_IND
: /* ncci */
1408 plcip
= find_plci_by_ncci(card
, cmsg
->adr
.adrNCCI
);
1410 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrNCCI
);
1412 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_IND
);
1413 capi_fill_CONNECT_B3_RESP(cmsg
,
1416 nccip
->ncci
, /* adr */
1420 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_RESP
);
1421 send_message(card
, cmsg
);
1424 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1426 printk(KERN_ERR
"capidrv-%d: %s: plci for ncci 0x%x not found\n",
1428 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1431 capi_fill_CONNECT_B3_RESP(cmsg
,
1438 send_message(card
, cmsg
);
1441 case CAPI_CONNECT_B3_CONF
: /* ncci */
1443 if (!(nccip
= find_ncci_by_msgid(card
,
1445 cmsg
->Messagenumber
)))
1448 nccip
->ncci
= cmsg
->adr
.adrNCCI
;
1450 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1452 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1453 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1458 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_ERROR
);
1460 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_OK
);
1463 case CAPI_CONNECT_B3_T90_ACTIVE_IND
: /* ncci */
1464 capi_cmsg_answer(cmsg
);
1465 send_message(card
, cmsg
);
1468 case CAPI_DATA_B3_IND
: /* ncci */
1469 /* handled in handle_data() */
1472 case CAPI_DATA_B3_CONF
: /* ncci */
1474 printk(KERN_WARNING
"CAPI_DATA_B3_CONF: Info %x - %s\n",
1475 cmsg
->Info
, capi_info2str(cmsg
->Info
));
1477 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1480 len
= capidrv_del_ack(nccip
, cmsg
->DataHandle
);
1483 cmd
.command
= ISDN_STAT_BSENT
;
1484 cmd
.driver
= card
->myid
;
1485 cmd
.arg
= nccip
->chan
;
1486 cmd
.parm
.length
= len
;
1487 card
->interface
.statcallb(&cmd
);
1490 case CAPI_DISCONNECT_B3_IND
: /* ncci */
1491 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1494 card
->bchans
[nccip
->chan
].disconnecting
= 1;
1495 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_IND
);
1496 capi_cmsg_answer(cmsg
);
1497 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_RESP
);
1498 send_message(card
, cmsg
);
1501 case CAPI_DISCONNECT_B3_CONF
: /* ncci */
1502 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1505 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1507 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1508 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1510 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
);
1514 case CAPI_RESET_B3_IND
: /* ncci */
1515 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1517 ncci_change_state(card
, nccip
, EV_NCCI_RESET_B3_IND
);
1518 capi_cmsg_answer(cmsg
);
1519 send_message(card
, cmsg
);
1522 case CAPI_RESET_B3_CONF
: /* ncci */
1523 goto ignored
; /* $$$$ */
1525 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1527 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1531 printk(KERN_ERR
"capidrv-%d: got %s for ncci 0x%x ???",
1533 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1538 printk(KERN_INFO
"capidrv-%d: %s for ncci 0x%x ignored\n",
1540 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1544 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1546 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1551 static void handle_data(_cmsg
*cmsg
, struct sk_buff
*skb
)
1553 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1554 capidrv_ncci
*nccip
;
1557 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1558 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1559 cmsg
->adr
.adrController
& 0x7f);
1563 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
))) {
1564 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1566 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1571 (void) skb_pull(skb
, CAPIMSG_LEN(skb
->data
));
1572 card
->interface
.rcvcallb_skb(card
->myid
, nccip
->chan
, skb
);
1573 capi_cmsg_answer(cmsg
);
1574 send_message(card
, cmsg
);
1577 static _cmsg s_cmsg
;
1579 static void capidrv_recv_message(struct capi20_appl
*ap
, struct sk_buff
*skb
)
1581 capi_message2cmsg(&s_cmsg
, skb
->data
);
1582 if (debugmode
> 3) {
1583 _cdebbuf
*cdb
= capi_cmsg2str(&s_cmsg
);
1586 printk(KERN_DEBUG
"%s: applid=%d %s\n", __func__
,
1587 ap
->applid
, cdb
->buf
);
1590 printk(KERN_DEBUG
"%s: applid=%d %s not traced\n",
1591 __func__
, ap
->applid
,
1592 capi_cmd2str(s_cmsg
.Command
, s_cmsg
.Subcommand
));
1594 if (s_cmsg
.Command
== CAPI_DATA_B3
1595 && s_cmsg
.Subcommand
== CAPI_IND
) {
1596 handle_data(&s_cmsg
, skb
);
1599 if ((s_cmsg
.adr
.adrController
& 0xffffff00) == 0)
1600 handle_controller(&s_cmsg
);
1601 else if ((s_cmsg
.adr
.adrPLCI
& 0xffff0000) == 0)
1602 handle_plci(&s_cmsg
);
1604 handle_ncci(&s_cmsg
);
1606 * data of skb used in s_cmsg,
1607 * free data when s_cmsg is not used again
1608 * thanks to Lars Heete <hel@admin.de>
1613 /* ------------------------------------------------------------------- */
1615 #define PUTBYTE_TO_STATUS(card, byte) \
1617 *(card)->q931_write++ = (byte); \
1618 if ((card)->q931_write > (card)->q931_end) \
1619 (card)->q931_write = (card)->q931_buf; \
1622 static void handle_dtrace_data(capidrv_contr
*card
,
1623 int send
, int level2
, u8
*data
, u16 len
)
1629 printk(KERN_DEBUG
"capidrv-%d: avmb1_q931_data: len == %d\n",
1630 card
->contrnr
, len
);
1635 PUTBYTE_TO_STATUS(card
, 'D');
1636 PUTBYTE_TO_STATUS(card
, '2');
1637 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1638 PUTBYTE_TO_STATUS(card
, ':');
1640 PUTBYTE_TO_STATUS(card
, 'D');
1641 PUTBYTE_TO_STATUS(card
, '3');
1642 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1643 PUTBYTE_TO_STATUS(card
, ':');
1646 for (p
= data
, end
= data
+ len
; p
< end
; p
++) {
1647 PUTBYTE_TO_STATUS(card
, ' ');
1648 PUTBYTE_TO_STATUS(card
, hex_asc_hi(*p
));
1649 PUTBYTE_TO_STATUS(card
, hex_asc_lo(*p
));
1651 PUTBYTE_TO_STATUS(card
, '\n');
1653 cmd
.command
= ISDN_STAT_STAVAIL
;
1654 cmd
.driver
= card
->myid
;
1655 cmd
.arg
= len
* 3 + 5;
1656 card
->interface
.statcallb(&cmd
);
1659 /* ------------------------------------------------------------------- */
1661 static _cmsg cmdcmsg
;
1663 static int capidrv_ioctl(isdn_ctrl
*c
, capidrv_contr
*card
)
1667 debugmode
= (int)(*((unsigned int *)c
->parm
.num
));
1668 printk(KERN_DEBUG
"capidrv-%d: debugmode=%d\n",
1669 card
->contrnr
, debugmode
);
1672 printk(KERN_DEBUG
"capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1673 card
->contrnr
, c
->arg
);
1680 * Handle leased lines (CAPI-Bundling)
1683 struct internal_bchannelinfo
{
1684 unsigned short channelalloc
;
1685 unsigned short operation
;
1686 unsigned char cmask
[31];
1689 static int decodeFVteln(char *teln
, unsigned long *bmaskp
, int *activep
)
1691 unsigned long bmask
= 0;
1696 if (strncmp(teln
, "FV:", 3) != 0)
1699 while (*s
&& *s
== ' ') s
++;
1701 if (*s
== 'p' || *s
== 'P') {
1705 if (*s
== 'a' || *s
== 'A') {
1714 digit1
= simple_strtoul(s
, &endp
, 10);
1719 if (digit1
<= 0 || digit1
> 30) return -4;
1720 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1721 bmask
|= (1 << digit1
);
1726 if (*s
!= '-') return -5;
1729 digit2
= simple_strtoul(s
, &endp
, 10);
1734 if (digit2
<= 0 || digit2
> 30) return -4;
1735 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1736 if (digit1
> digit2
)
1737 for (i
= digit2
; i
<= digit1
; i
++)
1740 for (i
= digit1
; i
<= digit2
; i
++)
1742 digit1
= digit2
= 0;
1748 if (activep
) *activep
= active
;
1749 if (bmaskp
) *bmaskp
= bmask
;
1753 static int FVteln2capi20(char *teln
, u8 AdditionalInfo
[1 + 2 + 2 + 31])
1755 unsigned long bmask
;
1759 rc
= decodeFVteln(teln
, &bmask
, &active
);
1762 AdditionalInfo
[0] = 2 + 2 + 31;
1763 /* Channel: 3 => use channel allocation */
1764 AdditionalInfo
[1] = 3; AdditionalInfo
[2] = 0;
1765 /* Operation: 0 => DTE mode, 1 => DCE mode */
1767 AdditionalInfo
[3] = 0; AdditionalInfo
[4] = 0;
1769 AdditionalInfo
[3] = 1; AdditionalInfo
[4] = 0;
1771 /* Channel mask array */
1772 AdditionalInfo
[5] = 0; /* no D-Channel */
1773 for (i
= 1; i
<= 30; i
++)
1774 AdditionalInfo
[5 + i
] = (bmask
& (1 << i
)) ? 0xff : 0;
1778 static int capidrv_command(isdn_ctrl
*c
, capidrv_contr
*card
)
1781 struct capidrv_bchan
*bchan
;
1782 struct capidrv_plci
*plcip
;
1783 u8 AdditionalInfo
[1 + 2 + 2 + 31];
1784 int rc
, isleasedline
= 0;
1786 if (c
->command
== ISDN_CMD_IOCTL
)
1787 return capidrv_ioctl(c
, card
);
1789 switch (c
->command
) {
1790 case ISDN_CMD_DIAL
: {
1791 u8 calling
[ISDN_MSNLEN
+ 3];
1792 u8 called
[ISDN_MSNLEN
+ 2];
1795 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1798 c
->parm
.setup
.phone
,
1801 c
->parm
.setup
.eazmsn
);
1803 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1806 printk(KERN_ERR
"capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1809 c
->parm
.setup
.phone
,
1812 c
->parm
.setup
.eazmsn
,
1813 bchan
->plcip
->plci
);
1816 bchan
->si1
= c
->parm
.setup
.si1
;
1817 bchan
->si2
= c
->parm
.setup
.si2
;
1819 strncpy(bchan
->num
, c
->parm
.setup
.phone
, sizeof(bchan
->num
));
1820 strncpy(bchan
->mynum
, c
->parm
.setup
.eazmsn
, sizeof(bchan
->mynum
));
1821 rc
= FVteln2capi20(bchan
->num
, AdditionalInfo
);
1822 isleasedline
= (rc
== 0);
1824 printk(KERN_ERR
"capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card
->contrnr
, bchan
->num
);
1830 printk(KERN_DEBUG
"capidrv-%d: connecting leased line\n", card
->contrnr
);
1832 calling
[0] = strlen(bchan
->mynum
) + 2;
1835 strncpy(calling
+ 3, bchan
->mynum
, ISDN_MSNLEN
);
1836 called
[0] = strlen(bchan
->num
) + 1;
1838 strncpy(called
+ 2, bchan
->num
, ISDN_MSNLEN
);
1841 capi_fill_CONNECT_REQ(&cmdcmsg
,
1844 card
->contrnr
, /* adr */
1845 si2cip(bchan
->si1
, bchan
->si2
), /* cipvalue */
1846 called
, /* CalledPartyNumber */
1847 calling
, /* CallingPartyNumber */
1848 NULL
, /* CalledPartySubaddress */
1849 NULL
, /* CallingPartySubaddress */
1850 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1851 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1852 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1853 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1854 NULL
, /* B2configuration */
1855 NULL
, /* B3configuration */
1859 /* BChannelinformation */
1860 isleasedline
? AdditionalInfo
: NULL
,
1861 NULL
, /* Keypadfacility */
1862 NULL
, /* Useruserdata */
1863 NULL
/* Facilitydataarray */
1865 if ((plcip
= new_plci(card
, (c
->arg
% card
->nbchan
))) == NULL
) {
1866 cmd
.command
= ISDN_STAT_DHUP
;
1867 cmd
.driver
= card
->myid
;
1868 cmd
.arg
= (c
->arg
% card
->nbchan
);
1869 card
->interface
.statcallb(&cmd
);
1872 plcip
->msgid
= cmdcmsg
.Messagenumber
;
1873 plcip
->leasedline
= isleasedline
;
1874 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REQ
);
1875 send_message(card
, &cmdcmsg
);
1879 case ISDN_CMD_ACCEPTD
:
1881 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1883 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1885 c
->arg
, bchan
->l2
, bchan
->l3
);
1887 capi_fill_CONNECT_RESP(&cmdcmsg
,
1890 bchan
->plcip
->plci
, /* adr */
1892 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1893 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1894 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1895 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1896 NULL
, /* B2configuration */
1897 NULL
, /* B3configuration */
1898 NULL
, /* ConnectedNumber */
1899 NULL
, /* ConnectedSubaddress */
1901 NULL
, /* BChannelinformation */
1902 NULL
, /* Keypadfacility */
1903 NULL
, /* Useruserdata */
1904 NULL
/* Facilitydataarray */
1906 capi_cmsg2message(&cmdcmsg
, cmdcmsg
.buf
);
1907 plci_change_state(card
, bchan
->plcip
, EV_PLCI_CONNECT_RESP
);
1908 send_message(card
, &cmdcmsg
);
1911 case ISDN_CMD_ACCEPTB
:
1913 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1918 case ISDN_CMD_HANGUP
:
1920 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1923 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1925 if (bchan
->disconnecting
) {
1927 printk(KERN_DEBUG
"capidrv-%d: chan %ld already disconnecting ...\n",
1933 bchan
->disconnecting
= 1;
1934 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg
,
1940 ncci_change_state(card
, bchan
->nccip
, EV_NCCI_DISCONNECT_B3_REQ
);
1941 send_message(card
, &cmdcmsg
);
1943 } else if (bchan
->plcip
) {
1944 if (bchan
->plcip
->state
== ST_PLCI_INCOMING
) {
1946 * just ignore, we a called from
1947 * isdn_status_callback(),
1948 * which will return 0 or 2, this is handled
1949 * by the CONNECT_IND handler
1951 bchan
->disconnecting
= 1;
1953 } else if (bchan
->plcip
->plci
) {
1954 bchan
->disconnecting
= 1;
1955 capi_fill_DISCONNECT_REQ(&cmdcmsg
,
1959 NULL
, /* BChannelinformation */
1960 NULL
, /* Keypadfacility */
1961 NULL
, /* Useruserdata */
1962 NULL
/* Facilitydataarray */
1964 plci_change_state(card
, bchan
->plcip
, EV_PLCI_DISCONNECT_REQ
);
1965 send_message(card
, &cmdcmsg
);
1968 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1974 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request on free channel\n",
1980 case ISDN_CMD_SETL2
:
1982 printk(KERN_DEBUG
"capidrv-%d: set L2 on chan %ld to %ld\n",
1984 (c
->arg
& 0xff), (c
->arg
>> 8));
1985 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1986 bchan
->l2
= (c
->arg
>> 8);
1989 case ISDN_CMD_SETL3
:
1991 printk(KERN_DEBUG
"capidrv-%d: set L3 on chan %ld to %ld\n",
1993 (c
->arg
& 0xff), (c
->arg
>> 8));
1994 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1995 bchan
->l3
= (c
->arg
>> 8);
1998 case ISDN_CMD_SETEAZ
:
2000 printk(KERN_DEBUG
"capidrv-%d: set EAZ \"%s\" on chan %ld\n",
2002 c
->parm
.num
, c
->arg
);
2003 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
2004 strncpy(bchan
->msn
, c
->parm
.num
, ISDN_MSNLEN
);
2007 case ISDN_CMD_CLREAZ
:
2009 printk(KERN_DEBUG
"capidrv-%d: clearing EAZ on chan %ld\n",
2010 card
->contrnr
, c
->arg
);
2011 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
2016 printk(KERN_ERR
"capidrv-%d: ISDN_CMD_%d, Huh?\n",
2017 card
->contrnr
, c
->command
);
2023 static int if_command(isdn_ctrl
*c
)
2025 capidrv_contr
*card
= findcontrbydriverid(c
->driver
);
2028 return capidrv_command(c
, card
);
2031 "capidrv: if_command %d called with invalid driverId %d!\n",
2032 c
->command
, c
->driver
);
2036 static _cmsg sendcmsg
;
2038 static int if_sendbuf(int id
, int channel
, int doack
, struct sk_buff
*skb
)
2040 capidrv_contr
*card
= findcontrbydriverid(id
);
2041 capidrv_bchan
*bchan
;
2042 capidrv_ncci
*nccip
;
2050 printk(KERN_ERR
"capidrv: if_sendbuf called with invalid driverId %d!\n",
2055 printk(KERN_DEBUG
"capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
2056 card
->contrnr
, len
, skb
, doack
);
2057 bchan
= &card
->bchans
[channel
% card
->nbchan
];
2058 nccip
= bchan
->nccip
;
2059 if (!nccip
|| nccip
->state
!= ST_NCCI_ACTIVE
) {
2060 printk(KERN_ERR
"capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
2061 card
->contrnr
, card
->name
, channel
);
2064 datahandle
= nccip
->datahandle
;
2067 * Here we copy pointer skb->data into the 32-bit 'Data' field.
2068 * The 'Data' field is not used in practice in linux kernel
2069 * (neither in 32 or 64 bit), but should have some value,
2070 * since a CAPI message trace will display it.
2072 * The correct value in the 32 bit case is the address of the
2073 * data, in 64 bit it makes no sense, we use 0 there.
2079 data
= (unsigned long) skb
->data
;
2082 capi_fill_DATA_B3_REQ(&sendcmsg
, global
.ap
.applid
, card
->msgid
++,
2083 nccip
->ncci
, /* adr */
2085 skb
->len
, /* DataLength */
2086 datahandle
, /* DataHandle */
2090 if (capidrv_add_ack(nccip
, datahandle
, doack
? (int)skb
->len
: -1) < 0)
2093 capi_cmsg2message(&sendcmsg
, sendcmsg
.buf
);
2094 msglen
= CAPIMSG_LEN(sendcmsg
.buf
);
2095 if (skb_headroom(skb
) < msglen
) {
2096 struct sk_buff
*nskb
= skb_realloc_headroom(skb
, msglen
);
2098 printk(KERN_ERR
"capidrv-%d: if_sendbuf: no memory\n",
2100 (void)capidrv_del_ack(nccip
, datahandle
);
2103 printk(KERN_DEBUG
"capidrv-%d: only %d bytes headroom, need %d\n",
2104 card
->contrnr
, skb_headroom(skb
), msglen
);
2105 memcpy(skb_push(nskb
, msglen
), sendcmsg
.buf
, msglen
);
2106 errcode
= capi20_put_message(&global
.ap
, nskb
);
2107 if (errcode
== CAPI_NOERROR
) {
2109 nccip
->datahandle
++;
2113 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
2114 card
->contrnr
, errcode
, capi_info2str(errcode
));
2115 (void)capidrv_del_ack(nccip
, datahandle
);
2116 dev_kfree_skb(nskb
);
2117 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
2119 memcpy(skb_push(skb
, msglen
), sendcmsg
.buf
, msglen
);
2120 errcode
= capi20_put_message(&global
.ap
, skb
);
2121 if (errcode
== CAPI_NOERROR
) {
2122 nccip
->datahandle
++;
2126 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
2127 card
->contrnr
, errcode
, capi_info2str(errcode
));
2128 skb_pull(skb
, msglen
);
2129 (void)capidrv_del_ack(nccip
, datahandle
);
2130 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
2134 static int if_readstat(u8 __user
*buf
, int len
, int id
, int channel
)
2136 capidrv_contr
*card
= findcontrbydriverid(id
);
2141 printk(KERN_ERR
"capidrv: if_readstat called with invalid driverId %d!\n",
2146 for (p
= buf
, count
= 0; count
< len
; p
++, count
++) {
2147 if (put_user(*card
->q931_read
++, p
))
2149 if (card
->q931_read
> card
->q931_end
)
2150 card
->q931_read
= card
->q931_buf
;
2156 static void enable_dchannel_trace(capidrv_contr
*card
)
2158 u8 manufacturer
[CAPI_MANUFACTURER_LEN
];
2159 capi_version version
;
2160 u16 contr
= card
->contrnr
;
2164 errcode
= capi20_get_manufacturer(contr
, manufacturer
);
2165 if (errcode
!= CAPI_NOERROR
) {
2166 printk(KERN_ERR
"%s: can't get manufacturer (0x%x)\n",
2167 card
->name
, errcode
);
2170 if (strstr(manufacturer
, "AVM") == NULL
) {
2171 printk(KERN_ERR
"%s: not from AVM, no d-channel trace possible (%s)\n",
2172 card
->name
, manufacturer
);
2175 errcode
= capi20_get_version(contr
, &version
);
2176 if (errcode
!= CAPI_NOERROR
) {
2177 printk(KERN_ERR
"%s: can't get version (0x%x)\n",
2178 card
->name
, errcode
);
2181 avmversion
[0] = (version
.majormanuversion
>> 4) & 0x0f;
2182 avmversion
[1] = (version
.majormanuversion
<< 4) & 0xf0;
2183 avmversion
[1] |= (version
.minormanuversion
>> 4) & 0x0f;
2184 avmversion
[2] |= version
.minormanuversion
& 0x0f;
2186 if (avmversion
[0] > 3 || (avmversion
[0] == 3 && avmversion
[1] > 5)) {
2187 printk(KERN_INFO
"%s: D2 trace enabled\n", card
->name
);
2188 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
2191 0x214D5641, /* ManuID */
2194 (_cstruct
)"\004\200\014\000\000");
2196 printk(KERN_INFO
"%s: D3 trace enabled\n", card
->name
);
2197 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
2200 0x214D5641, /* ManuID */
2203 (_cstruct
)"\004\002\003\000\000");
2205 send_message(card
, &cmdcmsg
);
2209 static void send_listen(capidrv_contr
*card
)
2211 capi_fill_LISTEN_REQ(&cmdcmsg
, global
.ap
.applid
,
2213 card
->contrnr
, /* controller */
2214 1 << 6, /* Infomask */
2218 listen_change_state(card
, EV_LISTEN_REQ
);
2219 send_message(card
, &cmdcmsg
);
2222 static void listentimerfunc(unsigned long x
)
2224 capidrv_contr
*card
= (capidrv_contr
*)x
;
2225 if (card
->state
!= ST_LISTEN_NONE
&& card
->state
!= ST_LISTEN_ACTIVE
)
2226 printk(KERN_ERR
"%s: controller dead ??\n", card
->name
);
2228 mod_timer(&card
->listentimer
, jiffies
+ 60 * HZ
);
2232 static int capidrv_addcontr(u16 contr
, struct capi_profile
*profp
)
2234 capidrv_contr
*card
;
2235 unsigned long flags
;
2240 sprintf(id
, "capidrv-%d", contr
);
2241 if (!try_module_get(THIS_MODULE
)) {
2242 printk(KERN_WARNING
"capidrv: (%s) Could not reserve module\n", id
);
2245 if (!(card
= kzalloc(sizeof(capidrv_contr
), GFP_ATOMIC
))) {
2247 "capidrv: (%s) Could not allocate contr-struct.\n", id
);
2250 card
->owner
= THIS_MODULE
;
2251 init_timer(&card
->listentimer
);
2252 strcpy(card
->name
, id
);
2253 card
->contrnr
= contr
;
2254 card
->nbchan
= profp
->nbchannel
;
2255 card
->bchans
= kmalloc(sizeof(capidrv_bchan
) * card
->nbchan
, GFP_ATOMIC
);
2256 if (!card
->bchans
) {
2258 "capidrv: (%s) Could not allocate bchan-structs.\n", id
);
2259 module_put(card
->owner
);
2263 card
->interface
.channels
= profp
->nbchannel
;
2264 card
->interface
.maxbufsize
= 2048;
2265 card
->interface
.command
= if_command
;
2266 card
->interface
.writebuf_skb
= if_sendbuf
;
2267 card
->interface
.writecmd
= NULL
;
2268 card
->interface
.readstat
= if_readstat
;
2269 card
->interface
.features
=
2270 ISDN_FEATURE_L2_HDLC
|
2271 ISDN_FEATURE_L2_TRANS
|
2272 ISDN_FEATURE_L3_TRANS
|
2273 ISDN_FEATURE_P_UNKNOWN
|
2274 ISDN_FEATURE_L2_X75I
|
2275 ISDN_FEATURE_L2_X75UI
|
2276 ISDN_FEATURE_L2_X75BUI
;
2277 if (profp
->support1
& (1 << 2))
2278 card
->interface
.features
|=
2279 ISDN_FEATURE_L2_V11096
|
2280 ISDN_FEATURE_L2_V11019
|
2281 ISDN_FEATURE_L2_V11038
;
2282 if (profp
->support1
& (1 << 8))
2283 card
->interface
.features
|= ISDN_FEATURE_L2_MODEM
;
2284 card
->interface
.hl_hdrlen
= 22; /* len of DATA_B3_REQ */
2285 strncpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
) - 1);
2288 card
->q931_read
= card
->q931_buf
;
2289 card
->q931_write
= card
->q931_buf
;
2290 card
->q931_end
= card
->q931_buf
+ sizeof(card
->q931_buf
) - 1;
2292 if (!register_isdn(&card
->interface
)) {
2293 printk(KERN_ERR
"capidrv: Unable to register contr %s\n", id
);
2294 kfree(card
->bchans
);
2295 module_put(card
->owner
);
2299 card
->myid
= card
->interface
.channels
;
2300 memset(card
->bchans
, 0, sizeof(capidrv_bchan
) * card
->nbchan
);
2301 for (i
= 0; i
< card
->nbchan
; i
++) {
2302 card
->bchans
[i
].contr
= card
;
2305 spin_lock_irqsave(&global_lock
, flags
);
2306 card
->next
= global
.contr_list
;
2307 global
.contr_list
= card
;
2309 spin_unlock_irqrestore(&global_lock
, flags
);
2311 cmd
.command
= ISDN_STAT_RUN
;
2312 cmd
.driver
= card
->myid
;
2313 card
->interface
.statcallb(&cmd
);
2315 card
->cipmask
= 0x1FFF03FF; /* any */
2318 card
->listentimer
.data
= (unsigned long)card
;
2319 card
->listentimer
.function
= listentimerfunc
;
2321 mod_timer(&card
->listentimer
, jiffies
+ 60 * HZ
);
2323 printk(KERN_INFO
"%s: now up (%d B channels)\n",
2324 card
->name
, card
->nbchan
);
2326 enable_dchannel_trace(card
);
2331 static int capidrv_delcontr(u16 contr
)
2333 capidrv_contr
**pp
, *card
;
2334 unsigned long flags
;
2337 spin_lock_irqsave(&global_lock
, flags
);
2338 for (card
= global
.contr_list
; card
; card
= card
->next
) {
2339 if (card
->contrnr
== contr
)
2343 spin_unlock_irqrestore(&global_lock
, flags
);
2344 printk(KERN_ERR
"capidrv: delcontr: no contr %u\n", contr
);
2348 /* FIXME: maybe a race condition the card should be removed
2349 * here from global list /kkeil
2351 spin_unlock_irqrestore(&global_lock
, flags
);
2353 del_timer(&card
->listentimer
);
2356 printk(KERN_DEBUG
"capidrv-%d: id=%d unloading\n",
2357 card
->contrnr
, card
->myid
);
2359 cmd
.command
= ISDN_STAT_STOP
;
2360 cmd
.driver
= card
->myid
;
2361 card
->interface
.statcallb(&cmd
);
2363 while (card
->nbchan
) {
2365 cmd
.command
= ISDN_STAT_DISCH
;
2366 cmd
.driver
= card
->myid
;
2367 cmd
.arg
= card
->nbchan
- 1;
2368 cmd
.parm
.num
[0] = 0;
2370 printk(KERN_DEBUG
"capidrv-%d: id=%d disable chan=%ld\n",
2371 card
->contrnr
, card
->myid
, cmd
.arg
);
2372 card
->interface
.statcallb(&cmd
);
2374 if (card
->bchans
[card
->nbchan
- 1].nccip
)
2375 free_ncci(card
, card
->bchans
[card
->nbchan
- 1].nccip
);
2376 if (card
->bchans
[card
->nbchan
- 1].plcip
)
2377 free_plci(card
, card
->bchans
[card
->nbchan
- 1].plcip
);
2378 if (card
->plci_list
)
2379 printk(KERN_ERR
"capidrv: bug in free_plci()\n");
2382 kfree(card
->bchans
);
2383 card
->bchans
= NULL
;
2386 printk(KERN_DEBUG
"capidrv-%d: id=%d isdn unload\n",
2387 card
->contrnr
, card
->myid
);
2389 cmd
.command
= ISDN_STAT_UNLOAD
;
2390 cmd
.driver
= card
->myid
;
2391 card
->interface
.statcallb(&cmd
);
2394 printk(KERN_DEBUG
"capidrv-%d: id=%d remove contr from list\n",
2395 card
->contrnr
, card
->myid
);
2397 spin_lock_irqsave(&global_lock
, flags
);
2398 for (pp
= &global
.contr_list
; *pp
; pp
= &(*pp
)->next
) {
2406 spin_unlock_irqrestore(&global_lock
, flags
);
2408 module_put(card
->owner
);
2409 printk(KERN_INFO
"%s: now down.\n", card
->name
);
2416 lower_callback(struct notifier_block
*nb
, unsigned long val
, void *v
)
2418 capi_profile profile
;
2419 u32 contr
= (long)v
;
2423 printk(KERN_INFO
"capidrv: controller %hu up\n", contr
);
2424 if (capi20_get_profile(contr
, &profile
) == CAPI_NOERROR
)
2425 (void) capidrv_addcontr(contr
, &profile
);
2428 printk(KERN_INFO
"capidrv: controller %hu down\n", contr
);
2429 (void) capidrv_delcontr(contr
);
2436 * /proc/capi/capidrv:
2437 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2439 static int capidrv_proc_show(struct seq_file
*m
, void *v
)
2441 seq_printf(m
, "%lu %lu %lu %lu\n",
2442 global
.ap
.nrecvctlpkt
,
2443 global
.ap
.nrecvdatapkt
,
2444 global
.ap
.nsentctlpkt
,
2445 global
.ap
.nsentdatapkt
);
2449 static int capidrv_proc_open(struct inode
*inode
, struct file
*file
)
2451 return single_open(file
, capidrv_proc_show
, NULL
);
2454 static const struct file_operations capidrv_proc_fops
= {
2455 .owner
= THIS_MODULE
,
2456 .open
= capidrv_proc_open
,
2458 .llseek
= seq_lseek
,
2459 .release
= single_release
,
2462 static void __init
proc_init(void)
2464 proc_create("capi/capidrv", 0, NULL
, &capidrv_proc_fops
);
2467 static void __exit
proc_exit(void)
2469 remove_proc_entry("capi/capidrv", NULL
);
2472 static struct notifier_block capictr_nb
= {
2473 .notifier_call
= lower_callback
,
2476 static int __init
capidrv_init(void)
2478 capi_profile profile
;
2482 global
.ap
.rparam
.level3cnt
= -2; /* number of bchannels twice */
2483 global
.ap
.rparam
.datablkcnt
= 16;
2484 global
.ap
.rparam
.datablklen
= 2048;
2486 global
.ap
.recv_message
= capidrv_recv_message
;
2487 errcode
= capi20_register(&global
.ap
);
2492 register_capictr_notifier(&capictr_nb
);
2494 errcode
= capi20_get_profile(0, &profile
);
2495 if (errcode
!= CAPI_NOERROR
) {
2496 unregister_capictr_notifier(&capictr_nb
);
2497 capi20_release(&global
.ap
);
2501 ncontr
= profile
.ncontroller
;
2502 for (contr
= 1; contr
<= ncontr
; contr
++) {
2503 errcode
= capi20_get_profile(contr
, &profile
);
2504 if (errcode
!= CAPI_NOERROR
)
2506 (void) capidrv_addcontr(contr
, &profile
);
2513 static void __exit
capidrv_exit(void)
2515 unregister_capictr_notifier(&capictr_nb
);
2516 capi20_release(&global
.ap
);
2521 module_init(capidrv_init
);
2522 module_exit(capidrv_exit
);