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/capi.h>
28 #include <linux/kernelcapi.h>
29 #include <linux/ctype.h>
30 #include <linux/init.h>
31 #include <linux/moduleparam.h>
33 #include <linux/isdn/capiutil.h>
34 #include <linux/isdn/capicmd.h>
37 static char *revision
= "$Revision: 1.1.2.2 $";
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
,
400 capidrv_plci
* plcip
,
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
= (struct ncci_datahandle_queue
*)
473 kmalloc(sizeof(struct ncci_datahandle_queue
), GFP_ATOMIC
);
475 printk(KERN_ERR
"capidrv: kmalloc ncci_datahandle failed\n");
479 n
->datahandle
= datahandle
;
481 for (pp
= &nccip
->ackqueue
; *pp
; pp
= &(*pp
)->next
) ;
486 static int capidrv_del_ack(struct capidrv_ncci
*nccip
, u16 datahandle
)
488 struct ncci_datahandle_queue
**pp
, *p
;
491 for (pp
= &nccip
->ackqueue
; *pp
; pp
= &(*pp
)->next
) {
492 if ((*pp
)->datahandle
== datahandle
) {
503 /* -------- convert and send capi message ---------------------------- */
505 static void send_message(capidrv_contr
* card
, _cmsg
* cmsg
)
510 capi_cmsg2message(cmsg
, cmsg
->buf
);
511 len
= CAPIMSG_LEN(cmsg
->buf
);
512 skb
= alloc_skb(len
, GFP_ATOMIC
);
514 printk(KERN_ERR
"capidrv::send_message: can't allocate mem\n");
517 memcpy(skb_put(skb
, len
), cmsg
->buf
, len
);
518 if (capi20_put_message(&global
.ap
, skb
) != CAPI_NOERROR
)
522 /* -------- state machine -------------------------------------------- */
524 struct listenstatechange
{
530 static struct listenstatechange listentable
[] =
532 {ST_LISTEN_NONE
, ST_LISTEN_WAIT_CONF
, EV_LISTEN_REQ
},
533 {ST_LISTEN_ACTIVE
, ST_LISTEN_ACTIVE_WAIT_CONF
, EV_LISTEN_REQ
},
534 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_ERROR
},
535 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_ERROR
},
536 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
537 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
538 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
539 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
543 static void listen_change_state(capidrv_contr
* card
, int event
)
545 struct listenstatechange
*p
= listentable
;
547 if (card
->state
== p
->actstate
&& p
->event
== event
) {
549 printk(KERN_DEBUG
"capidrv-%d: listen_change_state %d -> %d\n",
550 card
->contrnr
, card
->state
, p
->nextstate
);
551 card
->state
= p
->nextstate
;
556 printk(KERN_ERR
"capidrv-%d: listen_change_state state=%d event=%d ????\n",
557 card
->contrnr
, card
->state
, event
);
561 /* ------------------------------------------------------------------ */
563 static void p0(capidrv_contr
* card
, capidrv_plci
* plci
)
567 card
->bchans
[plci
->chan
].contr
= NULL
;
568 cmd
.command
= ISDN_STAT_DHUP
;
569 cmd
.driver
= card
->myid
;
570 cmd
.arg
= plci
->chan
;
571 card
->interface
.statcallb(&cmd
);
572 free_plci(card
, plci
);
575 /* ------------------------------------------------------------------ */
577 struct plcistatechange
{
581 void (*changefunc
) (capidrv_contr
* card
, capidrv_plci
* plci
);
584 static struct plcistatechange plcitable
[] =
587 {ST_PLCI_NONE
, ST_PLCI_OUTGOING
, EV_PLCI_CONNECT_REQ
, NULL
},
588 {ST_PLCI_NONE
, ST_PLCI_ALLOCATED
, EV_PLCI_FACILITY_IND_UP
, NULL
},
589 {ST_PLCI_NONE
, ST_PLCI_INCOMING
, EV_PLCI_CONNECT_IND
, NULL
},
590 {ST_PLCI_NONE
, ST_PLCI_RESUMEING
, EV_PLCI_RESUME_REQ
, NULL
},
592 {ST_PLCI_OUTGOING
, ST_PLCI_NONE
, EV_PLCI_CONNECT_CONF_ERROR
, p0
},
593 {ST_PLCI_OUTGOING
, ST_PLCI_ALLOCATED
, EV_PLCI_CONNECT_CONF_OK
, NULL
},
595 {ST_PLCI_ALLOCATED
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
596 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
597 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
598 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
600 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
601 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
602 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
603 {ST_PLCI_ACTIVE
, ST_PLCI_HELD
, EV_PLCI_HOLD_IND
, NULL
},
604 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_SUSPEND_IND
, NULL
},
606 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
607 {ST_PLCI_INCOMING
, ST_PLCI_FACILITY_IND
, EV_PLCI_FACILITY_IND_UP
, NULL
},
608 {ST_PLCI_INCOMING
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_RESP
, NULL
},
609 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
610 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
611 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
612 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CD_IND
, NULL
},
614 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
615 {ST_PLCI_FACILITY_IND
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
616 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
617 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
618 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
620 {ST_PLCI_ACCEPTING
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
621 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
622 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
623 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
625 {ST_PLCI_DISCONNECTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
627 {ST_PLCI_DISCONNECTED
, ST_PLCI_NONE
, EV_PLCI_DISCONNECT_RESP
, p0
},
629 {ST_PLCI_RESUMEING
, ST_PLCI_NONE
, EV_PLCI_RESUME_CONF_ERROR
, p0
},
630 {ST_PLCI_RESUMEING
, ST_PLCI_RESUME
, EV_PLCI_RESUME_CONF_OK
, NULL
},
632 {ST_PLCI_RESUME
, ST_PLCI_ACTIVE
, EV_PLCI_RESUME_IND
, NULL
},
634 {ST_PLCI_HELD
, ST_PLCI_ACTIVE
, EV_PLCI_RETRIEVE_IND
, NULL
},
638 static void plci_change_state(capidrv_contr
* card
, capidrv_plci
* plci
, int event
)
640 struct plcistatechange
*p
= plcitable
;
642 if (plci
->state
== p
->actstate
&& p
->event
== event
) {
644 printk(KERN_DEBUG
"capidrv-%d: plci_change_state:0x%x %d -> %d\n",
645 card
->contrnr
, plci
->plci
, plci
->state
, p
->nextstate
);
646 plci
->state
= p
->nextstate
;
648 p
->changefunc(card
, plci
);
653 printk(KERN_ERR
"capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
654 card
->contrnr
, plci
->plci
, plci
->state
, event
);
657 /* ------------------------------------------------------------------ */
661 static void n0(capidrv_contr
* card
, capidrv_ncci
* ncci
)
665 capi_fill_DISCONNECT_REQ(&cmsg
,
669 NULL
, /* BChannelinformation */
670 NULL
, /* Keypadfacility */
671 NULL
, /* Useruserdata */ /* $$$$ */
672 NULL
/* Facilitydataarray */
674 plci_change_state(card
, ncci
->plcip
, EV_PLCI_DISCONNECT_REQ
);
675 send_message(card
, &cmsg
);
677 cmd
.command
= ISDN_STAT_BHUP
;
678 cmd
.driver
= card
->myid
;
679 cmd
.arg
= ncci
->chan
;
680 card
->interface
.statcallb(&cmd
);
681 free_ncci(card
, ncci
);
684 /* ------------------------------------------------------------------ */
686 struct nccistatechange
{
690 void (*changefunc
) (capidrv_contr
* card
, capidrv_ncci
* ncci
);
693 static struct nccistatechange nccitable
[] =
696 {ST_NCCI_NONE
, ST_NCCI_OUTGOING
, EV_NCCI_CONNECT_B3_REQ
, NULL
},
697 {ST_NCCI_NONE
, ST_NCCI_INCOMING
, EV_NCCI_CONNECT_B3_IND
, NULL
},
699 {ST_NCCI_OUTGOING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_CONF_OK
, NULL
},
700 {ST_NCCI_OUTGOING
, ST_NCCI_NONE
, EV_NCCI_CONNECT_B3_CONF_ERROR
, n0
},
702 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_CONNECT_B3_REJECT
, NULL
},
703 {ST_NCCI_INCOMING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_RESP
, NULL
},
704 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
705 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
707 {ST_NCCI_ALLOCATED
, ST_NCCI_ACTIVE
, EV_NCCI_CONNECT_B3_ACTIVE_IND
, NULL
},
708 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
709 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
711 {ST_NCCI_ACTIVE
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
712 {ST_NCCI_ACTIVE
, ST_NCCI_RESETING
, EV_NCCI_RESET_B3_REQ
, NULL
},
713 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
714 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
716 {ST_NCCI_RESETING
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
717 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
718 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
720 {ST_NCCI_DISCONNECTING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
721 {ST_NCCI_DISCONNECTING
, ST_NCCI_PREVIOUS
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
,NULL
},
723 {ST_NCCI_DISCONNECTED
, ST_NCCI_NONE
, EV_NCCI_DISCONNECT_B3_RESP
, n0
},
727 static void ncci_change_state(capidrv_contr
* card
, capidrv_ncci
* ncci
, int event
)
729 struct nccistatechange
*p
= nccitable
;
731 if (ncci
->state
== p
->actstate
&& p
->event
== event
) {
733 printk(KERN_DEBUG
"capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
734 card
->contrnr
, ncci
->ncci
, ncci
->state
, p
->nextstate
);
735 if (p
->nextstate
== ST_NCCI_PREVIOUS
) {
736 ncci
->state
= ncci
->oldstate
;
737 ncci
->oldstate
= p
->actstate
;
739 ncci
->oldstate
= p
->actstate
;
740 ncci
->state
= p
->nextstate
;
743 p
->changefunc(card
, ncci
);
748 printk(KERN_ERR
"capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
749 card
->contrnr
, ncci
->ncci
, ncci
->state
, event
);
752 /* ------------------------------------------------------------------- */
754 static inline int new_bchan(capidrv_contr
* card
)
757 for (i
= 0; i
< card
->nbchan
; i
++) {
758 if (card
->bchans
[i
].plcip
== NULL
) {
759 card
->bchans
[i
].disconnecting
= 0;
766 /* ------------------------------------------------------------------- */
768 static void handle_controller(_cmsg
* cmsg
)
770 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
773 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
774 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
775 cmsg
->adr
.adrController
& 0x7f);
778 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
780 case CAPI_LISTEN_CONF
: /* Controller */
782 printk(KERN_DEBUG
"capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
783 card
->contrnr
, cmsg
->Info
, capi_info2str(cmsg
->Info
), card
->cipmask
);
785 listen_change_state(card
, EV_LISTEN_CONF_ERROR
);
786 } else if (card
->cipmask
== 0) {
787 listen_change_state(card
, EV_LISTEN_CONF_EMPTY
);
789 listen_change_state(card
, EV_LISTEN_CONF_OK
);
793 case CAPI_MANUFACTURER_IND
: /* Controller */
794 if ( cmsg
->ManuID
== 0x214D5641
796 && cmsg
->Function
== 1) {
797 u8
*data
= cmsg
->ManuData
+3;
798 u16 len
= cmsg
->ManuData
[0];
802 len
= (cmsg
->ManuData
[1] | (cmsg
->ManuData
[2] << 8));
806 layer
= ((*(data
-1)) << 8) | *(data
-2);
808 direction
= (layer
& 0x200) ? 0 : 1;
809 else direction
= (layer
& 0x800) ? 0 : 1;
810 if (layer
& 0x0C00) {
811 if ((layer
& 0xff) == 0x80) {
812 handle_dtrace_data(card
, direction
, 1, data
, len
);
815 } else if ((layer
& 0xff) < 0x80) {
816 handle_dtrace_data(card
, direction
, 0, data
, len
);
819 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
821 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
822 cmsg
->adr
.adrController
, layer
);
826 case CAPI_MANUFACTURER_CONF
: /* Controller */
827 if (cmsg
->ManuID
== 0x214D5641) {
829 switch (cmsg
->Class
) {
831 case 1: s
= "unknown class"; break;
832 case 2: s
= "unknown function"; break;
833 default: s
= "unknown error"; break;
836 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x function %d: %s\n",
838 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
839 cmsg
->adr
.adrController
,
844 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
846 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
848 case CAPI_INFO_IND
: /* Controller/plci */
850 case CAPI_INFO_CONF
: /* Controller/plci */
854 printk(KERN_ERR
"capidrv-%d: got %s from controller 0x%x ???",
856 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
857 cmsg
->adr
.adrController
);
862 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x ignored\n",
864 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
865 cmsg
->adr
.adrController
);
868 static void handle_incoming_call(capidrv_contr
* card
, _cmsg
* cmsg
)
871 capidrv_bchan
*bchan
;
875 if ((chan
= new_bchan(card
)) == -1) {
876 printk(KERN_ERR
"capidrv-%d: incoming call on not existing bchan ?\n", card
->contrnr
);
879 bchan
= &card
->bchans
[chan
];
880 if ((plcip
= new_plci(card
, chan
)) == NULL
) {
881 printk(KERN_ERR
"capidrv-%d: incoming call: no memory, sorry.\n", card
->contrnr
);
885 plcip
->plci
= cmsg
->adr
.adrPLCI
;
886 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_IND
);
888 cmd
.command
= ISDN_STAT_ICALL
;
889 cmd
.driver
= card
->myid
;
891 memset(&cmd
.parm
.setup
, 0, sizeof(cmd
.parm
.setup
));
892 strncpy(cmd
.parm
.setup
.phone
,
893 cmsg
->CallingPartyNumber
+ 3,
894 cmsg
->CallingPartyNumber
[0] - 2);
895 strncpy(cmd
.parm
.setup
.eazmsn
,
896 cmsg
->CalledPartyNumber
+ 2,
897 cmsg
->CalledPartyNumber
[0] - 1);
898 cmd
.parm
.setup
.si1
= cip2si1(cmsg
->CIPValue
);
899 cmd
.parm
.setup
.si2
= cip2si2(cmsg
->CIPValue
);
900 cmd
.parm
.setup
.plan
= cmsg
->CallingPartyNumber
[1];
901 cmd
.parm
.setup
.screen
= cmsg
->CallingPartyNumber
[2];
903 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s\n",
905 cmd
.parm
.setup
.phone
,
908 cmd
.parm
.setup
.eazmsn
);
910 if (cmd
.parm
.setup
.si1
== 1 && cmd
.parm
.setup
.si2
!= 0) {
911 printk(KERN_INFO
"capidrv-%d: patching si2=%d to 0 for VBOX\n",
914 cmd
.parm
.setup
.si2
= 0;
917 switch (card
->interface
.statcallb(&cmd
)) {
920 /* No device matching this call.
921 * and isdn_common.c has send a HANGUP command
922 * which is ignored in state ST_PLCI_INCOMING,
923 * so we send RESP to ignore the call
925 capi_cmsg_answer(cmsg
);
926 cmsg
->Reject
= 1; /* ignore */
927 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
928 send_message(card
, cmsg
);
929 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
931 cmd
.parm
.setup
.phone
,
934 cmd
.parm
.setup
.eazmsn
);
937 /* At least one device matching this call (RING on ttyI)
938 * HL-driver may send ALERTING on the D-channel in this
940 * really means: RING on ttyI or a net interface
941 * accepted this call already.
943 * If the call was accepted, state has already changed,
944 * and CONNECT_RESP already sent.
946 if (plcip
->state
== ST_PLCI_INCOMING
) {
947 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
949 cmd
.parm
.setup
.phone
,
952 cmd
.parm
.setup
.eazmsn
);
953 capi_fill_ALERT_REQ(cmsg
,
956 plcip
->plci
, /* adr */
957 NULL
,/* BChannelinformation */
958 NULL
,/* Keypadfacility */
959 NULL
,/* Useruserdata */
960 NULL
/* Facilitydataarray */
962 plcip
->msgid
= cmsg
->Messagenumber
;
963 send_message(card
, cmsg
);
965 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
967 cmd
.parm
.setup
.phone
,
970 cmd
.parm
.setup
.eazmsn
);
974 case 2: /* Call will be rejected. */
975 capi_cmsg_answer(cmsg
);
976 cmsg
->Reject
= 2; /* reject call, normal call clearing */
977 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
978 send_message(card
, cmsg
);
982 /* An error happened. (Invalid parameters for example.) */
983 capi_cmsg_answer(cmsg
);
984 cmsg
->Reject
= 8; /* reject call,
985 destination out of order */
986 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
987 send_message(card
, cmsg
);
993 static void handle_plci(_cmsg
* cmsg
)
995 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1001 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1002 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1003 cmsg
->adr
.adrController
& 0x7f);
1006 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1008 case CAPI_DISCONNECT_IND
: /* plci */
1010 printk(KERN_INFO
"capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1012 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1013 cmsg
->Reason
, capi_info2str(cmsg
->Reason
), cmsg
->adr
.adrPLCI
);
1015 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
))) {
1016 capi_cmsg_answer(cmsg
);
1017 send_message(card
, cmsg
);
1020 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1021 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_IND
);
1022 capi_cmsg_answer(cmsg
);
1023 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_RESP
);
1024 send_message(card
, cmsg
);
1027 case CAPI_DISCONNECT_CONF
: /* plci */
1029 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1031 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1032 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1035 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1038 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1041 case CAPI_ALERT_CONF
: /* plci */
1043 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1045 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1046 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1051 case CAPI_CONNECT_IND
: /* plci */
1052 handle_incoming_call(card
, cmsg
);
1055 case CAPI_CONNECT_CONF
: /* plci */
1057 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1059 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1060 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1063 if (!(plcip
= find_plci_by_msgid(card
, cmsg
->Messagenumber
)))
1066 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1068 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_ERROR
);
1070 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_OK
);
1074 case CAPI_CONNECT_ACTIVE_IND
: /* plci */
1076 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1079 if (card
->bchans
[plcip
->chan
].incoming
) {
1080 capi_cmsg_answer(cmsg
);
1081 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_ACTIVE_IND
);
1082 send_message(card
, cmsg
);
1084 capidrv_ncci
*nccip
;
1085 capi_cmsg_answer(cmsg
);
1086 send_message(card
, cmsg
);
1088 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrPLCI
);
1091 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1094 capi_fill_CONNECT_B3_REQ(cmsg
,
1097 plcip
->plci
, /* adr */
1100 nccip
->msgid
= cmsg
->Messagenumber
;
1101 plci_change_state(card
, plcip
,
1102 EV_PLCI_CONNECT_ACTIVE_IND
);
1103 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_REQ
);
1104 send_message(card
, cmsg
);
1105 cmd
.command
= ISDN_STAT_DCONN
;
1106 cmd
.driver
= card
->myid
;
1107 cmd
.arg
= plcip
->chan
;
1108 card
->interface
.statcallb(&cmd
);
1112 case CAPI_INFO_IND
: /* Controller/plci */
1114 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1117 if (cmsg
->InfoNumber
== 0x4000) {
1118 if (cmsg
->InfoElement
[0] == 4) {
1119 cmd
.command
= ISDN_STAT_CINF
;
1120 cmd
.driver
= card
->myid
;
1121 cmd
.arg
= plcip
->chan
;
1122 sprintf(cmd
.parm
.num
, "%lu",
1124 ((u32
) cmsg
->InfoElement
[1]
1125 | ((u32
) (cmsg
->InfoElement
[2]) << 8)
1126 | ((u32
) (cmsg
->InfoElement
[3]) << 16)
1127 | ((u32
) (cmsg
->InfoElement
[4]) << 24)));
1128 card
->interface
.statcallb(&cmd
);
1132 cdb
= capi_cmsg2str(cmsg
);
1134 printk(KERN_WARNING
"capidrv-%d: %s\n",
1135 card
->contrnr
, cdb
->buf
);
1138 printk(KERN_WARNING
"capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n",
1139 card
->contrnr
, cmsg
->InfoNumber
);
1143 case CAPI_CONNECT_ACTIVE_CONF
: /* plci */
1145 case CAPI_SELECT_B_PROTOCOL_CONF
: /* plci */
1147 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1149 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1152 case CAPI_INFO_CONF
: /* Controller/plci */
1156 printk(KERN_ERR
"capidrv-%d: got %s for plci 0x%x ???",
1158 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1163 printk(KERN_INFO
"capidrv-%d: %s for plci 0x%x ignored\n",
1165 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1169 printk(KERN_ERR
"capidrv-%d: %s: plci 0x%x not found\n",
1171 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1176 static void handle_ncci(_cmsg
* cmsg
)
1178 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1179 capidrv_plci
*plcip
;
1180 capidrv_ncci
*nccip
;
1185 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1186 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1187 cmsg
->adr
.adrController
& 0x7f);
1190 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1192 case CAPI_CONNECT_B3_ACTIVE_IND
: /* ncci */
1193 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1196 capi_cmsg_answer(cmsg
);
1197 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_ACTIVE_IND
);
1198 send_message(card
, cmsg
);
1200 cmd
.command
= ISDN_STAT_BCONN
;
1201 cmd
.driver
= card
->myid
;
1202 cmd
.arg
= nccip
->chan
;
1203 card
->interface
.statcallb(&cmd
);
1205 printk(KERN_INFO
"capidrv-%d: chan %d up with ncci 0x%x\n",
1206 card
->contrnr
, nccip
->chan
, nccip
->ncci
);
1209 case CAPI_CONNECT_B3_ACTIVE_CONF
: /* ncci */
1212 case CAPI_CONNECT_B3_IND
: /* ncci */
1214 plcip
= find_plci_by_ncci(card
, cmsg
->adr
.adrNCCI
);
1216 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrNCCI
);
1218 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_IND
);
1219 capi_fill_CONNECT_B3_RESP(cmsg
,
1222 nccip
->ncci
, /* adr */
1226 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_RESP
);
1227 send_message(card
, cmsg
);
1230 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1232 printk(KERN_ERR
"capidrv-%d: %s: plci for ncci 0x%x not found\n",
1234 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1237 capi_fill_CONNECT_B3_RESP(cmsg
,
1244 send_message(card
, cmsg
);
1247 case CAPI_CONNECT_B3_CONF
: /* ncci */
1249 if (!(nccip
= find_ncci_by_msgid(card
,
1251 cmsg
->Messagenumber
)))
1254 nccip
->ncci
= cmsg
->adr
.adrNCCI
;
1256 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1258 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1259 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1264 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_ERROR
);
1266 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_OK
);
1269 case CAPI_CONNECT_B3_T90_ACTIVE_IND
: /* ncci */
1270 capi_cmsg_answer(cmsg
);
1271 send_message(card
, cmsg
);
1274 case CAPI_DATA_B3_IND
: /* ncci */
1275 /* handled in handle_data() */
1278 case CAPI_DATA_B3_CONF
: /* ncci */
1280 printk(KERN_WARNING
"CAPI_DATA_B3_CONF: Info %x - %s\n",
1281 cmsg
->Info
, capi_info2str(cmsg
->Info
));
1283 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1286 len
= capidrv_del_ack(nccip
, cmsg
->DataHandle
);
1289 cmd
.command
= ISDN_STAT_BSENT
;
1290 cmd
.driver
= card
->myid
;
1291 cmd
.arg
= nccip
->chan
;
1292 cmd
.parm
.length
= len
;
1293 card
->interface
.statcallb(&cmd
);
1296 case CAPI_DISCONNECT_B3_IND
: /* ncci */
1297 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1300 card
->bchans
[nccip
->chan
].disconnecting
= 1;
1301 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_IND
);
1302 capi_cmsg_answer(cmsg
);
1303 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_RESP
);
1304 send_message(card
, cmsg
);
1307 case CAPI_DISCONNECT_B3_CONF
: /* ncci */
1308 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1311 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1313 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1314 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1316 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
);
1320 case CAPI_RESET_B3_IND
: /* ncci */
1321 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1323 ncci_change_state(card
, nccip
, EV_NCCI_RESET_B3_IND
);
1324 capi_cmsg_answer(cmsg
);
1325 send_message(card
, cmsg
);
1328 case CAPI_RESET_B3_CONF
: /* ncci */
1329 goto ignored
; /* $$$$ */
1331 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1333 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1337 printk(KERN_ERR
"capidrv-%d: got %s for ncci 0x%x ???",
1339 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1344 printk(KERN_INFO
"capidrv-%d: %s for ncci 0x%x ignored\n",
1346 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1350 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1352 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1357 static void handle_data(_cmsg
* cmsg
, struct sk_buff
*skb
)
1359 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1360 capidrv_ncci
*nccip
;
1363 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1364 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1365 cmsg
->adr
.adrController
& 0x7f);
1369 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
))) {
1370 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1372 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1377 (void) skb_pull(skb
, CAPIMSG_LEN(skb
->data
));
1378 card
->interface
.rcvcallb_skb(card
->myid
, nccip
->chan
, skb
);
1379 capi_cmsg_answer(cmsg
);
1380 send_message(card
, cmsg
);
1383 static _cmsg s_cmsg
;
1385 static void capidrv_recv_message(struct capi20_appl
*ap
, struct sk_buff
*skb
)
1387 capi_message2cmsg(&s_cmsg
, skb
->data
);
1388 if (debugmode
> 3) {
1389 _cdebbuf
*cdb
= capi_cmsg2str(&s_cmsg
);
1392 printk(KERN_DEBUG
"%s: applid=%d %s\n", __func__
,
1393 ap
->applid
, cdb
->buf
);
1396 printk(KERN_DEBUG
"%s: applid=%d %s not traced\n",
1397 __func__
, ap
->applid
,
1398 capi_cmd2str(s_cmsg
.Command
, s_cmsg
.Subcommand
));
1400 if (s_cmsg
.Command
== CAPI_DATA_B3
1401 && s_cmsg
.Subcommand
== CAPI_IND
) {
1402 handle_data(&s_cmsg
, skb
);
1405 if ((s_cmsg
.adr
.adrController
& 0xffffff00) == 0)
1406 handle_controller(&s_cmsg
);
1407 else if ((s_cmsg
.adr
.adrPLCI
& 0xffff0000) == 0)
1408 handle_plci(&s_cmsg
);
1410 handle_ncci(&s_cmsg
);
1412 * data of skb used in s_cmsg,
1413 * free data when s_cmsg is not used again
1414 * thanks to Lars Heete <hel@admin.de>
1419 /* ------------------------------------------------------------------- */
1421 #define PUTBYTE_TO_STATUS(card, byte) \
1423 *(card)->q931_write++ = (byte); \
1424 if ((card)->q931_write > (card)->q931_end) \
1425 (card)->q931_write = (card)->q931_buf; \
1428 static void handle_dtrace_data(capidrv_contr
*card
,
1429 int send
, int level2
, u8
*data
, u16 len
)
1435 printk(KERN_DEBUG
"capidrv-%d: avmb1_q931_data: len == %d\n",
1436 card
->contrnr
, len
);
1441 PUTBYTE_TO_STATUS(card
, 'D');
1442 PUTBYTE_TO_STATUS(card
, '2');
1443 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1444 PUTBYTE_TO_STATUS(card
, ':');
1446 PUTBYTE_TO_STATUS(card
, 'D');
1447 PUTBYTE_TO_STATUS(card
, '3');
1448 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1449 PUTBYTE_TO_STATUS(card
, ':');
1452 for (p
= data
, end
= data
+len
; p
< end
; p
++) {
1454 PUTBYTE_TO_STATUS(card
, ' ');
1455 w
= (*p
>> 4) & 0xf;
1456 PUTBYTE_TO_STATUS(card
, (w
< 10) ? '0'+w
: 'A'-10+w
);
1458 PUTBYTE_TO_STATUS(card
, (w
< 10) ? '0'+w
: 'A'-10+w
);
1460 PUTBYTE_TO_STATUS(card
, '\n');
1462 cmd
.command
= ISDN_STAT_STAVAIL
;
1463 cmd
.driver
= card
->myid
;
1465 card
->interface
.statcallb(&cmd
);
1468 /* ------------------------------------------------------------------- */
1470 static _cmsg cmdcmsg
;
1472 static int capidrv_ioctl(isdn_ctrl
* c
, capidrv_contr
* card
)
1476 debugmode
= (int)(*((unsigned int *)c
->parm
.num
));
1477 printk(KERN_DEBUG
"capidrv-%d: debugmode=%d\n",
1478 card
->contrnr
, debugmode
);
1481 printk(KERN_DEBUG
"capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1482 card
->contrnr
, c
->arg
);
1489 * Handle leased lines (CAPI-Bundling)
1492 struct internal_bchannelinfo
{
1493 unsigned short channelalloc
;
1494 unsigned short operation
;
1495 unsigned char cmask
[31];
1498 static int decodeFVteln(char *teln
, unsigned long *bmaskp
, int *activep
)
1500 unsigned long bmask
= 0;
1505 if (strncmp(teln
, "FV:", 3) != 0)
1508 while (*s
&& *s
== ' ') s
++;
1510 if (*s
== 'p' || *s
== 'P') {
1514 if (*s
== 'a' || *s
== 'A') {
1521 if (!isdigit(*s
)) return -3;
1522 while (isdigit(*s
)) { digit1
= digit1
*10 + (*s
- '0'); s
++; }
1523 if (digit1
<= 0 || digit1
> 30) return -4;
1524 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1525 bmask
|= (1 << digit1
);
1530 if (*s
!= '-') return -5;
1532 if (!isdigit(*s
)) return -3;
1533 while (isdigit(*s
)) { digit2
= digit2
*10 + (*s
- '0'); s
++; }
1534 if (digit2
<= 0 || digit2
> 30) return -4;
1535 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1536 if (digit1
> digit2
)
1537 for (i
= digit2
; i
<= digit1
; i
++)
1540 for (i
= digit1
; i
<= digit2
; i
++)
1542 digit1
= digit2
= 0;
1548 if (activep
) *activep
= active
;
1549 if (bmaskp
) *bmaskp
= bmask
;
1553 static int FVteln2capi20(char *teln
, u8 AdditionalInfo
[1+2+2+31])
1555 unsigned long bmask
;
1559 rc
= decodeFVteln(teln
, &bmask
, &active
);
1562 AdditionalInfo
[0] = 2+2+31;
1563 /* Channel: 3 => use channel allocation */
1564 AdditionalInfo
[1] = 3; AdditionalInfo
[2] = 0;
1565 /* Operation: 0 => DTE mode, 1 => DCE mode */
1567 AdditionalInfo
[3] = 0; AdditionalInfo
[4] = 0;
1569 AdditionalInfo
[3] = 1; AdditionalInfo
[4] = 0;
1571 /* Channel mask array */
1572 AdditionalInfo
[5] = 0; /* no D-Channel */
1573 for (i
=1; i
<= 30; i
++)
1574 AdditionalInfo
[5+i
] = (bmask
& (1 << i
)) ? 0xff : 0;
1578 static int capidrv_command(isdn_ctrl
* c
, capidrv_contr
* card
)
1581 struct capidrv_bchan
*bchan
;
1582 struct capidrv_plci
*plcip
;
1583 u8 AdditionalInfo
[1+2+2+31];
1584 int rc
, isleasedline
= 0;
1586 if (c
->command
== ISDN_CMD_IOCTL
)
1587 return capidrv_ioctl(c
, card
);
1589 switch (c
->command
) {
1590 case ISDN_CMD_DIAL
:{
1591 u8 calling
[ISDN_MSNLEN
+ 3];
1592 u8 called
[ISDN_MSNLEN
+ 2];
1595 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1598 c
->parm
.setup
.phone
,
1601 c
->parm
.setup
.eazmsn
);
1603 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1606 printk(KERN_ERR
"capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1609 c
->parm
.setup
.phone
,
1612 c
->parm
.setup
.eazmsn
,
1613 bchan
->plcip
->plci
);
1616 bchan
->si1
= c
->parm
.setup
.si1
;
1617 bchan
->si2
= c
->parm
.setup
.si2
;
1619 strncpy(bchan
->num
, c
->parm
.setup
.phone
, sizeof(bchan
->num
));
1620 strncpy(bchan
->mynum
, c
->parm
.setup
.eazmsn
, sizeof(bchan
->mynum
));
1621 rc
= FVteln2capi20(bchan
->num
, AdditionalInfo
);
1622 isleasedline
= (rc
== 0);
1624 printk(KERN_ERR
"capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card
->contrnr
, bchan
->num
);
1630 printk(KERN_DEBUG
"capidrv-%d: connecting leased line\n", card
->contrnr
);
1632 calling
[0] = strlen(bchan
->mynum
) + 2;
1635 strncpy(calling
+ 3, bchan
->mynum
, ISDN_MSNLEN
);
1636 called
[0] = strlen(bchan
->num
) + 1;
1638 strncpy(called
+ 2, bchan
->num
, ISDN_MSNLEN
);
1641 capi_fill_CONNECT_REQ(&cmdcmsg
,
1644 card
->contrnr
, /* adr */
1645 si2cip(bchan
->si1
, bchan
->si2
), /* cipvalue */
1646 called
, /* CalledPartyNumber */
1647 calling
, /* CallingPartyNumber */
1648 NULL
, /* CalledPartySubaddress */
1649 NULL
, /* CallingPartySubaddress */
1650 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1651 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1652 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1653 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1654 NULL
, /* B2configuration */
1655 NULL
, /* B3configuration */
1659 /* BChannelinformation */
1660 isleasedline
? AdditionalInfo
: NULL
,
1661 NULL
, /* Keypadfacility */
1662 NULL
, /* Useruserdata */
1663 NULL
/* Facilitydataarray */
1665 if ((plcip
= new_plci(card
, (c
->arg
% card
->nbchan
))) == NULL
) {
1666 cmd
.command
= ISDN_STAT_DHUP
;
1667 cmd
.driver
= card
->myid
;
1668 cmd
.arg
= (c
->arg
% card
->nbchan
);
1669 card
->interface
.statcallb(&cmd
);
1672 plcip
->msgid
= cmdcmsg
.Messagenumber
;
1673 plcip
->leasedline
= isleasedline
;
1674 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REQ
);
1675 send_message(card
, &cmdcmsg
);
1679 case ISDN_CMD_ACCEPTD
:
1681 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1683 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1685 c
->arg
, bchan
->l2
, bchan
->l3
);
1687 capi_fill_CONNECT_RESP(&cmdcmsg
,
1690 bchan
->plcip
->plci
, /* adr */
1692 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1693 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1694 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1695 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1696 NULL
, /* B2configuration */
1697 NULL
, /* B3configuration */
1698 NULL
, /* ConnectedNumber */
1699 NULL
, /* ConnectedSubaddress */
1701 NULL
, /* BChannelinformation */
1702 NULL
, /* Keypadfacility */
1703 NULL
, /* Useruserdata */
1704 NULL
/* Facilitydataarray */
1706 capi_cmsg2message(&cmdcmsg
, cmdcmsg
.buf
);
1707 plci_change_state(card
, bchan
->plcip
, EV_PLCI_CONNECT_RESP
);
1708 send_message(card
, &cmdcmsg
);
1711 case ISDN_CMD_ACCEPTB
:
1713 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1718 case ISDN_CMD_HANGUP
:
1720 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1723 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1725 if (bchan
->disconnecting
) {
1727 printk(KERN_DEBUG
"capidrv-%d: chan %ld already disconnecting ...\n",
1733 bchan
->disconnecting
= 1;
1734 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg
,
1740 ncci_change_state(card
, bchan
->nccip
, EV_NCCI_DISCONNECT_B3_REQ
);
1741 send_message(card
, &cmdcmsg
);
1743 } else if (bchan
->plcip
) {
1744 if (bchan
->plcip
->state
== ST_PLCI_INCOMING
) {
1746 * just ignore, we a called from
1747 * isdn_status_callback(),
1748 * which will return 0 or 2, this is handled
1749 * by the CONNECT_IND handler
1751 bchan
->disconnecting
= 1;
1753 } else if (bchan
->plcip
->plci
) {
1754 bchan
->disconnecting
= 1;
1755 capi_fill_DISCONNECT_REQ(&cmdcmsg
,
1759 NULL
, /* BChannelinformation */
1760 NULL
, /* Keypadfacility */
1761 NULL
, /* Useruserdata */
1762 NULL
/* Facilitydataarray */
1764 plci_change_state(card
, bchan
->plcip
, EV_PLCI_DISCONNECT_REQ
);
1765 send_message(card
, &cmdcmsg
);
1768 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1774 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request on free channel\n",
1780 case ISDN_CMD_SETL2
:
1782 printk(KERN_DEBUG
"capidrv-%d: set L2 on chan %ld to %ld\n",
1784 (c
->arg
& 0xff), (c
->arg
>> 8));
1785 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1786 bchan
->l2
= (c
->arg
>> 8);
1789 case ISDN_CMD_SETL3
:
1791 printk(KERN_DEBUG
"capidrv-%d: set L3 on chan %ld to %ld\n",
1793 (c
->arg
& 0xff), (c
->arg
>> 8));
1794 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1795 bchan
->l3
= (c
->arg
>> 8);
1798 case ISDN_CMD_SETEAZ
:
1800 printk(KERN_DEBUG
"capidrv-%d: set EAZ \"%s\" on chan %ld\n",
1802 c
->parm
.num
, c
->arg
);
1803 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1804 strncpy(bchan
->msn
, c
->parm
.num
, ISDN_MSNLEN
);
1807 case ISDN_CMD_CLREAZ
:
1809 printk(KERN_DEBUG
"capidrv-%d: clearing EAZ on chan %ld\n",
1810 card
->contrnr
, c
->arg
);
1811 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1816 printk(KERN_ERR
"capidrv-%d: ISDN_CMD_%d, Huh?\n",
1817 card
->contrnr
, c
->command
);
1823 static int if_command(isdn_ctrl
* c
)
1825 capidrv_contr
*card
= findcontrbydriverid(c
->driver
);
1828 return capidrv_command(c
, card
);
1831 "capidrv: if_command %d called with invalid driverId %d!\n",
1832 c
->command
, c
->driver
);
1836 static _cmsg sendcmsg
;
1838 static int if_sendbuf(int id
, int channel
, int doack
, struct sk_buff
*skb
)
1840 capidrv_contr
*card
= findcontrbydriverid(id
);
1841 capidrv_bchan
*bchan
;
1842 capidrv_ncci
*nccip
;
1850 printk(KERN_ERR
"capidrv: if_sendbuf called with invalid driverId %d!\n",
1855 printk(KERN_DEBUG
"capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
1856 card
->contrnr
, len
, skb
, doack
);
1857 bchan
= &card
->bchans
[channel
% card
->nbchan
];
1858 nccip
= bchan
->nccip
;
1859 if (!nccip
|| nccip
->state
!= ST_NCCI_ACTIVE
) {
1860 printk(KERN_ERR
"capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
1861 card
->contrnr
, card
->name
, channel
);
1864 datahandle
= nccip
->datahandle
;
1867 * Here we copy pointer skb->data into the 32-bit 'Data' field.
1868 * The 'Data' field is not used in practice in linux kernel
1869 * (neither in 32 or 64 bit), but should have some value,
1870 * since a CAPI message trace will display it.
1872 * The correct value in the 32 bit case is the address of the
1873 * data, in 64 bit it makes no sense, we use 0 there.
1879 data
= (unsigned long) skb
->data
;
1882 capi_fill_DATA_B3_REQ(&sendcmsg
, global
.ap
.applid
, card
->msgid
++,
1883 nccip
->ncci
, /* adr */
1885 skb
->len
, /* DataLength */
1886 datahandle
, /* DataHandle */
1890 if (capidrv_add_ack(nccip
, datahandle
, doack
? (int)skb
->len
: -1) < 0)
1893 capi_cmsg2message(&sendcmsg
, sendcmsg
.buf
);
1894 msglen
= CAPIMSG_LEN(sendcmsg
.buf
);
1895 if (skb_headroom(skb
) < msglen
) {
1896 struct sk_buff
*nskb
= skb_realloc_headroom(skb
, msglen
);
1898 printk(KERN_ERR
"capidrv-%d: if_sendbuf: no memory\n",
1900 (void)capidrv_del_ack(nccip
, datahandle
);
1903 printk(KERN_DEBUG
"capidrv-%d: only %d bytes headroom, need %d\n",
1904 card
->contrnr
, skb_headroom(skb
), msglen
);
1905 memcpy(skb_push(nskb
, msglen
), sendcmsg
.buf
, msglen
);
1906 errcode
= capi20_put_message(&global
.ap
, nskb
);
1907 if (errcode
== CAPI_NOERROR
) {
1909 nccip
->datahandle
++;
1913 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1914 card
->contrnr
, errcode
, capi_info2str(errcode
));
1915 (void)capidrv_del_ack(nccip
, datahandle
);
1916 dev_kfree_skb(nskb
);
1917 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
1919 memcpy(skb_push(skb
, msglen
), sendcmsg
.buf
, msglen
);
1920 errcode
= capi20_put_message(&global
.ap
, skb
);
1921 if (errcode
== CAPI_NOERROR
) {
1922 nccip
->datahandle
++;
1926 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1927 card
->contrnr
, errcode
, capi_info2str(errcode
));
1928 skb_pull(skb
, msglen
);
1929 (void)capidrv_del_ack(nccip
, datahandle
);
1930 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
1934 static int if_readstat(u8 __user
*buf
, int len
, int id
, int channel
)
1936 capidrv_contr
*card
= findcontrbydriverid(id
);
1941 printk(KERN_ERR
"capidrv: if_readstat called with invalid driverId %d!\n",
1946 for (p
=buf
, count
=0; count
< len
; p
++, count
++) {
1947 if (put_user(*card
->q931_read
++, p
))
1949 if (card
->q931_read
> card
->q931_end
)
1950 card
->q931_read
= card
->q931_buf
;
1956 static void enable_dchannel_trace(capidrv_contr
*card
)
1958 u8 manufacturer
[CAPI_MANUFACTURER_LEN
];
1959 capi_version version
;
1960 u16 contr
= card
->contrnr
;
1964 errcode
= capi20_get_manufacturer(contr
, manufacturer
);
1965 if (errcode
!= CAPI_NOERROR
) {
1966 printk(KERN_ERR
"%s: can't get manufacturer (0x%x)\n",
1967 card
->name
, errcode
);
1970 if (strstr(manufacturer
, "AVM") == NULL
) {
1971 printk(KERN_ERR
"%s: not from AVM, no d-channel trace possible (%s)\n",
1972 card
->name
, manufacturer
);
1975 errcode
= capi20_get_version(contr
, &version
);
1976 if (errcode
!= CAPI_NOERROR
) {
1977 printk(KERN_ERR
"%s: can't get version (0x%x)\n",
1978 card
->name
, errcode
);
1981 avmversion
[0] = (version
.majormanuversion
>> 4) & 0x0f;
1982 avmversion
[1] = (version
.majormanuversion
<< 4) & 0xf0;
1983 avmversion
[1] |= (version
.minormanuversion
>> 4) & 0x0f;
1984 avmversion
[2] |= version
.minormanuversion
& 0x0f;
1986 if (avmversion
[0] > 3 || (avmversion
[0] == 3 && avmversion
[1] > 5)) {
1987 printk(KERN_INFO
"%s: D2 trace enabled\n", card
->name
);
1988 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
1991 0x214D5641, /* ManuID */
1994 (_cstruct
)"\004\200\014\000\000");
1996 printk(KERN_INFO
"%s: D3 trace enabled\n", card
->name
);
1997 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
2000 0x214D5641, /* ManuID */
2003 (_cstruct
)"\004\002\003\000\000");
2005 send_message(card
, &cmdcmsg
);
2009 static void send_listen(capidrv_contr
*card
)
2011 capi_fill_LISTEN_REQ(&cmdcmsg
, global
.ap
.applid
,
2013 card
->contrnr
, /* controller */
2014 1 << 6, /* Infomask */
2018 listen_change_state(card
, EV_LISTEN_REQ
);
2019 send_message(card
, &cmdcmsg
);
2022 static void listentimerfunc(unsigned long x
)
2024 capidrv_contr
*card
= (capidrv_contr
*)x
;
2025 if (card
->state
!= ST_LISTEN_NONE
&& card
->state
!= ST_LISTEN_ACTIVE
)
2026 printk(KERN_ERR
"%s: controller dead ??\n", card
->name
);
2028 mod_timer(&card
->listentimer
, jiffies
+ 60*HZ
);
2032 static int capidrv_addcontr(u16 contr
, struct capi_profile
*profp
)
2034 capidrv_contr
*card
;
2035 unsigned long flags
;
2040 sprintf(id
, "capidrv-%d", contr
);
2041 if (!try_module_get(THIS_MODULE
)) {
2042 printk(KERN_WARNING
"capidrv: (%s) Could not reserve module\n", id
);
2045 if (!(card
= kzalloc(sizeof(capidrv_contr
), GFP_ATOMIC
))) {
2047 "capidrv: (%s) Could not allocate contr-struct.\n", id
);
2050 card
->owner
= THIS_MODULE
;
2051 init_timer(&card
->listentimer
);
2052 strcpy(card
->name
, id
);
2053 card
->contrnr
= contr
;
2054 card
->nbchan
= profp
->nbchannel
;
2055 card
->bchans
= kmalloc(sizeof(capidrv_bchan
) * card
->nbchan
, GFP_ATOMIC
);
2056 if (!card
->bchans
) {
2058 "capidrv: (%s) Could not allocate bchan-structs.\n", id
);
2059 module_put(card
->owner
);
2063 card
->interface
.channels
= profp
->nbchannel
;
2064 card
->interface
.maxbufsize
= 2048;
2065 card
->interface
.command
= if_command
;
2066 card
->interface
.writebuf_skb
= if_sendbuf
;
2067 card
->interface
.writecmd
= NULL
;
2068 card
->interface
.readstat
= if_readstat
;
2069 card
->interface
.features
= ISDN_FEATURE_L2_HDLC
|
2070 ISDN_FEATURE_L2_TRANS
|
2071 ISDN_FEATURE_L3_TRANS
|
2072 ISDN_FEATURE_P_UNKNOWN
|
2073 ISDN_FEATURE_L2_X75I
|
2074 ISDN_FEATURE_L2_X75UI
|
2075 ISDN_FEATURE_L2_X75BUI
;
2076 if (profp
->support1
& (1<<2))
2077 card
->interface
.features
|= ISDN_FEATURE_L2_V11096
|
2078 ISDN_FEATURE_L2_V11019
|
2079 ISDN_FEATURE_L2_V11038
;
2080 if (profp
->support1
& (1<<8))
2081 card
->interface
.features
|= ISDN_FEATURE_L2_MODEM
;
2082 card
->interface
.hl_hdrlen
= 22; /* len of DATA_B3_REQ */
2083 strncpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
) - 1);
2086 card
->q931_read
= card
->q931_buf
;
2087 card
->q931_write
= card
->q931_buf
;
2088 card
->q931_end
= card
->q931_buf
+ sizeof(card
->q931_buf
) - 1;
2090 if (!register_isdn(&card
->interface
)) {
2091 printk(KERN_ERR
"capidrv: Unable to register contr %s\n", id
);
2092 kfree(card
->bchans
);
2093 module_put(card
->owner
);
2097 card
->myid
= card
->interface
.channels
;
2098 memset(card
->bchans
, 0, sizeof(capidrv_bchan
) * card
->nbchan
);
2099 for (i
= 0; i
< card
->nbchan
; i
++) {
2100 card
->bchans
[i
].contr
= card
;
2103 spin_lock_irqsave(&global_lock
, flags
);
2104 card
->next
= global
.contr_list
;
2105 global
.contr_list
= card
;
2107 spin_unlock_irqrestore(&global_lock
, flags
);
2109 cmd
.command
= ISDN_STAT_RUN
;
2110 cmd
.driver
= card
->myid
;
2111 card
->interface
.statcallb(&cmd
);
2113 card
->cipmask
= 0x1FFF03FF; /* any */
2116 card
->listentimer
.data
= (unsigned long)card
;
2117 card
->listentimer
.function
= listentimerfunc
;
2119 mod_timer(&card
->listentimer
, jiffies
+ 60*HZ
);
2121 printk(KERN_INFO
"%s: now up (%d B channels)\n",
2122 card
->name
, card
->nbchan
);
2124 enable_dchannel_trace(card
);
2129 static int capidrv_delcontr(u16 contr
)
2131 capidrv_contr
**pp
, *card
;
2132 unsigned long flags
;
2135 spin_lock_irqsave(&global_lock
, flags
);
2136 for (card
= global
.contr_list
; card
; card
= card
->next
) {
2137 if (card
->contrnr
== contr
)
2141 spin_unlock_irqrestore(&global_lock
, flags
);
2142 printk(KERN_ERR
"capidrv: delcontr: no contr %u\n", contr
);
2146 /* FIXME: maybe a race condition the card should be removed
2147 * here from global list /kkeil
2149 spin_unlock_irqrestore(&global_lock
, flags
);
2151 del_timer(&card
->listentimer
);
2154 printk(KERN_DEBUG
"capidrv-%d: id=%d unloading\n",
2155 card
->contrnr
, card
->myid
);
2157 cmd
.command
= ISDN_STAT_STOP
;
2158 cmd
.driver
= card
->myid
;
2159 card
->interface
.statcallb(&cmd
);
2161 while (card
->nbchan
) {
2163 cmd
.command
= ISDN_STAT_DISCH
;
2164 cmd
.driver
= card
->myid
;
2165 cmd
.arg
= card
->nbchan
-1;
2166 cmd
.parm
.num
[0] = 0;
2168 printk(KERN_DEBUG
"capidrv-%d: id=%d disable chan=%ld\n",
2169 card
->contrnr
, card
->myid
, cmd
.arg
);
2170 card
->interface
.statcallb(&cmd
);
2172 if (card
->bchans
[card
->nbchan
-1].nccip
)
2173 free_ncci(card
, card
->bchans
[card
->nbchan
-1].nccip
);
2174 if (card
->bchans
[card
->nbchan
-1].plcip
)
2175 free_plci(card
, card
->bchans
[card
->nbchan
-1].plcip
);
2176 if (card
->plci_list
)
2177 printk(KERN_ERR
"capidrv: bug in free_plci()\n");
2180 kfree(card
->bchans
);
2181 card
->bchans
= NULL
;
2184 printk(KERN_DEBUG
"capidrv-%d: id=%d isdn unload\n",
2185 card
->contrnr
, card
->myid
);
2187 cmd
.command
= ISDN_STAT_UNLOAD
;
2188 cmd
.driver
= card
->myid
;
2189 card
->interface
.statcallb(&cmd
);
2192 printk(KERN_DEBUG
"capidrv-%d: id=%d remove contr from list\n",
2193 card
->contrnr
, card
->myid
);
2195 spin_lock_irqsave(&global_lock
, flags
);
2196 for (pp
= &global
.contr_list
; *pp
; pp
= &(*pp
)->next
) {
2204 spin_unlock_irqrestore(&global_lock
, flags
);
2206 module_put(card
->owner
);
2207 printk(KERN_INFO
"%s: now down.\n", card
->name
);
2213 static void lower_callback(unsigned int cmd
, u32 contr
, void *data
)
2218 printk(KERN_INFO
"capidrv: controller %hu up\n", contr
);
2219 (void) capidrv_addcontr(contr
, (capi_profile
*) data
);
2222 printk(KERN_INFO
"capidrv: controller %hu down\n", contr
);
2223 (void) capidrv_delcontr(contr
);
2229 * /proc/capi/capidrv:
2230 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2232 static int proc_capidrv_read_proc(char *page
, char **start
, off_t off
,
2233 int count
, int *eof
, void *data
)
2237 len
+= sprintf(page
+len
, "%lu %lu %lu %lu\n",
2238 global
.ap
.nrecvctlpkt
,
2239 global
.ap
.nrecvdatapkt
,
2240 global
.ap
.nsentctlpkt
,
2241 global
.ap
.nsentdatapkt
);
2242 if (off
+count
>= len
)
2246 *start
= page
+ off
;
2247 return ((count
< len
-off
) ? count
: len
-off
);
2250 static struct procfsentries
{
2253 int (*read_proc
)(char *page
, char **start
, off_t off
,
2254 int count
, int *eof
, void *data
);
2255 struct proc_dir_entry
*procent
;
2256 } procfsentries
[] = {
2257 /* { "capi", S_IFDIR, 0 }, */
2258 { "capi/capidrv", 0 , proc_capidrv_read_proc
},
2261 static void __init
proc_init(void)
2263 int nelem
= ARRAY_SIZE(procfsentries
);
2266 for (i
=0; i
< nelem
; i
++) {
2267 struct procfsentries
*p
= procfsentries
+ i
;
2268 p
->procent
= create_proc_entry(p
->name
, p
->mode
, NULL
);
2269 if (p
->procent
) p
->procent
->read_proc
= p
->read_proc
;
2273 static void __exit
proc_exit(void)
2275 int nelem
= ARRAY_SIZE(procfsentries
);
2278 for (i
=nelem
-1; i
>= 0; i
--) {
2279 struct procfsentries
*p
= procfsentries
+ i
;
2281 remove_proc_entry(p
->name
, NULL
);
2287 static int __init
capidrv_init(void)
2289 capi_profile profile
;
2295 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
2296 strncpy(rev
, p
+ 2, sizeof(rev
));
2297 rev
[sizeof(rev
)-1] = 0;
2298 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
2303 global
.ap
.rparam
.level3cnt
= -2; /* number of bchannels twice */
2304 global
.ap
.rparam
.datablkcnt
= 16;
2305 global
.ap
.rparam
.datablklen
= 2048;
2307 global
.ap
.recv_message
= capidrv_recv_message
;
2308 errcode
= capi20_register(&global
.ap
);
2313 capi20_set_callback(&global
.ap
, lower_callback
);
2315 errcode
= capi20_get_profile(0, &profile
);
2316 if (errcode
!= CAPI_NOERROR
) {
2317 capi20_release(&global
.ap
);
2321 ncontr
= profile
.ncontroller
;
2322 for (contr
= 1; contr
<= ncontr
; contr
++) {
2323 errcode
= capi20_get_profile(contr
, &profile
);
2324 if (errcode
!= CAPI_NOERROR
)
2326 (void) capidrv_addcontr(contr
, &profile
);
2330 printk(KERN_NOTICE
"capidrv: Rev %s: loaded\n", rev
);
2334 static void __exit
capidrv_exit(void)
2339 if ((p
= strchr(revision
, ':')) != NULL
) {
2340 strncpy(rev
, p
+ 1, sizeof(rev
));
2341 rev
[sizeof(rev
)-1] = 0;
2342 if ((p
= strchr(rev
, '$')) != NULL
)
2345 strcpy(rev
, " ??? ");
2348 capi20_release(&global
.ap
);
2352 printk(KERN_NOTICE
"capidrv: Rev%s: unloaded\n", rev
);
2355 module_init(capidrv_init
);
2356 module_exit(capidrv_exit
);