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
, 0);
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
)) == 0)
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
)) == 0)
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
)
509 capi_cmsg2message(cmsg
, cmsg
->buf
);
510 len
= CAPIMSG_LEN(cmsg
->buf
);
511 skb
= alloc_skb(len
, GFP_ATOMIC
);
512 memcpy(skb_put(skb
, len
), cmsg
->buf
, len
);
513 if (capi20_put_message(&global
.ap
, skb
) != CAPI_NOERROR
)
517 /* -------- state machine -------------------------------------------- */
519 struct listenstatechange
{
525 static struct listenstatechange listentable
[] =
527 {ST_LISTEN_NONE
, ST_LISTEN_WAIT_CONF
, EV_LISTEN_REQ
},
528 {ST_LISTEN_ACTIVE
, ST_LISTEN_ACTIVE_WAIT_CONF
, EV_LISTEN_REQ
},
529 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_ERROR
},
530 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_ERROR
},
531 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
532 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_NONE
, EV_LISTEN_CONF_EMPTY
},
533 {ST_LISTEN_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
534 {ST_LISTEN_ACTIVE_WAIT_CONF
, ST_LISTEN_ACTIVE
, EV_LISTEN_CONF_OK
},
538 static void listen_change_state(capidrv_contr
* card
, int event
)
540 struct listenstatechange
*p
= listentable
;
542 if (card
->state
== p
->actstate
&& p
->event
== event
) {
544 printk(KERN_DEBUG
"capidrv-%d: listen_change_state %d -> %d\n",
545 card
->contrnr
, card
->state
, p
->nextstate
);
546 card
->state
= p
->nextstate
;
551 printk(KERN_ERR
"capidrv-%d: listen_change_state state=%d event=%d ????\n",
552 card
->contrnr
, card
->state
, event
);
556 /* ------------------------------------------------------------------ */
558 static void p0(capidrv_contr
* card
, capidrv_plci
* plci
)
562 card
->bchans
[plci
->chan
].contr
= NULL
;
563 cmd
.command
= ISDN_STAT_DHUP
;
564 cmd
.driver
= card
->myid
;
565 cmd
.arg
= plci
->chan
;
566 card
->interface
.statcallb(&cmd
);
567 free_plci(card
, plci
);
570 /* ------------------------------------------------------------------ */
572 struct plcistatechange
{
576 void (*changefunc
) (capidrv_contr
* card
, capidrv_plci
* plci
);
579 static struct plcistatechange plcitable
[] =
582 {ST_PLCI_NONE
, ST_PLCI_OUTGOING
, EV_PLCI_CONNECT_REQ
, NULL
},
583 {ST_PLCI_NONE
, ST_PLCI_ALLOCATED
, EV_PLCI_FACILITY_IND_UP
, NULL
},
584 {ST_PLCI_NONE
, ST_PLCI_INCOMING
, EV_PLCI_CONNECT_IND
, NULL
},
585 {ST_PLCI_NONE
, ST_PLCI_RESUMEING
, EV_PLCI_RESUME_REQ
, NULL
},
587 {ST_PLCI_OUTGOING
, ST_PLCI_NONE
, EV_PLCI_CONNECT_CONF_ERROR
, p0
},
588 {ST_PLCI_OUTGOING
, ST_PLCI_ALLOCATED
, EV_PLCI_CONNECT_CONF_OK
, NULL
},
590 {ST_PLCI_ALLOCATED
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
591 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
592 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
593 {ST_PLCI_ALLOCATED
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
595 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
596 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
597 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
598 {ST_PLCI_ACTIVE
, ST_PLCI_HELD
, EV_PLCI_HOLD_IND
, NULL
},
599 {ST_PLCI_ACTIVE
, ST_PLCI_DISCONNECTING
, EV_PLCI_SUSPEND_IND
, NULL
},
601 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
602 {ST_PLCI_INCOMING
, ST_PLCI_FACILITY_IND
, EV_PLCI_FACILITY_IND_UP
, NULL
},
603 {ST_PLCI_INCOMING
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_RESP
, NULL
},
604 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
605 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
606 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
607 {ST_PLCI_INCOMING
, ST_PLCI_DISCONNECTING
, EV_PLCI_CD_IND
, NULL
},
609 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_CONNECT_REJECT
, NULL
},
610 {ST_PLCI_FACILITY_IND
, ST_PLCI_ACCEPTING
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
611 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
612 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
613 {ST_PLCI_FACILITY_IND
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
615 {ST_PLCI_ACCEPTING
, ST_PLCI_ACTIVE
, EV_PLCI_CONNECT_ACTIVE_IND
, NULL
},
616 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_DISCONNECT_REQ
, NULL
},
617 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTING
, EV_PLCI_FACILITY_IND_DOWN
, NULL
},
618 {ST_PLCI_ACCEPTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
620 {ST_PLCI_DISCONNECTING
, ST_PLCI_DISCONNECTED
, EV_PLCI_DISCONNECT_IND
, NULL
},
622 {ST_PLCI_DISCONNECTED
, ST_PLCI_NONE
, EV_PLCI_DISCONNECT_RESP
, p0
},
624 {ST_PLCI_RESUMEING
, ST_PLCI_NONE
, EV_PLCI_RESUME_CONF_ERROR
, p0
},
625 {ST_PLCI_RESUMEING
, ST_PLCI_RESUME
, EV_PLCI_RESUME_CONF_OK
, NULL
},
627 {ST_PLCI_RESUME
, ST_PLCI_ACTIVE
, EV_PLCI_RESUME_IND
, NULL
},
629 {ST_PLCI_HELD
, ST_PLCI_ACTIVE
, EV_PLCI_RETRIEVE_IND
, NULL
},
633 static void plci_change_state(capidrv_contr
* card
, capidrv_plci
* plci
, int event
)
635 struct plcistatechange
*p
= plcitable
;
637 if (plci
->state
== p
->actstate
&& p
->event
== event
) {
639 printk(KERN_DEBUG
"capidrv-%d: plci_change_state:0x%x %d -> %d\n",
640 card
->contrnr
, plci
->plci
, plci
->state
, p
->nextstate
);
641 plci
->state
= p
->nextstate
;
643 p
->changefunc(card
, plci
);
648 printk(KERN_ERR
"capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
649 card
->contrnr
, plci
->plci
, plci
->state
, event
);
652 /* ------------------------------------------------------------------ */
656 static void n0(capidrv_contr
* card
, capidrv_ncci
* ncci
)
660 capi_fill_DISCONNECT_REQ(&cmsg
,
664 NULL
, /* BChannelinformation */
665 NULL
, /* Keypadfacility */
666 NULL
, /* Useruserdata */ /* $$$$ */
667 NULL
/* Facilitydataarray */
669 send_message(card
, &cmsg
);
670 plci_change_state(card
, ncci
->plcip
, EV_PLCI_DISCONNECT_REQ
);
672 cmd
.command
= ISDN_STAT_BHUP
;
673 cmd
.driver
= card
->myid
;
674 cmd
.arg
= ncci
->chan
;
675 card
->interface
.statcallb(&cmd
);
676 free_ncci(card
, ncci
);
679 /* ------------------------------------------------------------------ */
681 struct nccistatechange
{
685 void (*changefunc
) (capidrv_contr
* card
, capidrv_ncci
* ncci
);
688 static struct nccistatechange nccitable
[] =
691 {ST_NCCI_NONE
, ST_NCCI_OUTGOING
, EV_NCCI_CONNECT_B3_REQ
, NULL
},
692 {ST_NCCI_NONE
, ST_NCCI_INCOMING
, EV_NCCI_CONNECT_B3_IND
, NULL
},
694 {ST_NCCI_OUTGOING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_CONF_OK
, NULL
},
695 {ST_NCCI_OUTGOING
, ST_NCCI_NONE
, EV_NCCI_CONNECT_B3_CONF_ERROR
, n0
},
697 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_CONNECT_B3_REJECT
, NULL
},
698 {ST_NCCI_INCOMING
, ST_NCCI_ALLOCATED
, EV_NCCI_CONNECT_B3_RESP
, NULL
},
699 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
700 {ST_NCCI_INCOMING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
702 {ST_NCCI_ALLOCATED
, ST_NCCI_ACTIVE
, EV_NCCI_CONNECT_B3_ACTIVE_IND
, NULL
},
703 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
704 {ST_NCCI_ALLOCATED
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
706 {ST_NCCI_ACTIVE
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
707 {ST_NCCI_ACTIVE
, ST_NCCI_RESETING
, EV_NCCI_RESET_B3_REQ
, NULL
},
708 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
709 {ST_NCCI_ACTIVE
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
711 {ST_NCCI_RESETING
, ST_NCCI_ACTIVE
, EV_NCCI_RESET_B3_IND
, NULL
},
712 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
713 {ST_NCCI_RESETING
, ST_NCCI_DISCONNECTING
, EV_NCCI_DISCONNECT_B3_REQ
, NULL
},
715 {ST_NCCI_DISCONNECTING
, ST_NCCI_DISCONNECTED
, EV_NCCI_DISCONNECT_B3_IND
, NULL
},
716 {ST_NCCI_DISCONNECTING
, ST_NCCI_PREVIOUS
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
,NULL
},
718 {ST_NCCI_DISCONNECTED
, ST_NCCI_NONE
, EV_NCCI_DISCONNECT_B3_RESP
, n0
},
722 static void ncci_change_state(capidrv_contr
* card
, capidrv_ncci
* ncci
, int event
)
724 struct nccistatechange
*p
= nccitable
;
726 if (ncci
->state
== p
->actstate
&& p
->event
== event
) {
728 printk(KERN_DEBUG
"capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
729 card
->contrnr
, ncci
->ncci
, ncci
->state
, p
->nextstate
);
730 if (p
->nextstate
== ST_NCCI_PREVIOUS
) {
731 ncci
->state
= ncci
->oldstate
;
732 ncci
->oldstate
= p
->actstate
;
734 ncci
->oldstate
= p
->actstate
;
735 ncci
->state
= p
->nextstate
;
738 p
->changefunc(card
, ncci
);
743 printk(KERN_ERR
"capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
744 card
->contrnr
, ncci
->ncci
, ncci
->state
, event
);
747 /* ------------------------------------------------------------------- */
749 static inline int new_bchan(capidrv_contr
* card
)
752 for (i
= 0; i
< card
->nbchan
; i
++) {
753 if (card
->bchans
[i
].plcip
== 0) {
754 card
->bchans
[i
].disconnecting
= 0;
761 /* ------------------------------------------------------------------- */
763 static void handle_controller(_cmsg
* cmsg
)
765 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
768 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
769 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
770 cmsg
->adr
.adrController
& 0x7f);
773 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
775 case CAPI_LISTEN_CONF
: /* Controller */
777 printk(KERN_DEBUG
"capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
778 card
->contrnr
, cmsg
->Info
, capi_info2str(cmsg
->Info
), card
->cipmask
);
780 listen_change_state(card
, EV_LISTEN_CONF_ERROR
);
781 } else if (card
->cipmask
== 0) {
782 listen_change_state(card
, EV_LISTEN_CONF_EMPTY
);
784 listen_change_state(card
, EV_LISTEN_CONF_OK
);
788 case CAPI_MANUFACTURER_IND
: /* Controller */
789 if ( cmsg
->ManuID
== 0x214D5641
791 && cmsg
->Function
== 1) {
792 u8
*data
= cmsg
->ManuData
+3;
793 u16 len
= cmsg
->ManuData
[0];
797 len
= (cmsg
->ManuData
[1] | (cmsg
->ManuData
[2] << 8));
801 layer
= ((*(data
-1)) << 8) | *(data
-2);
803 direction
= (layer
& 0x200) ? 0 : 1;
804 else direction
= (layer
& 0x800) ? 0 : 1;
805 if (layer
& 0x0C00) {
806 if ((layer
& 0xff) == 0x80) {
807 handle_dtrace_data(card
, direction
, 1, data
, len
);
810 } else if ((layer
& 0xff) < 0x80) {
811 handle_dtrace_data(card
, direction
, 0, data
, len
);
814 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
816 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
817 cmsg
->adr
.adrController
, layer
);
821 case CAPI_MANUFACTURER_CONF
: /* Controller */
822 if (cmsg
->ManuID
== 0x214D5641) {
824 switch (cmsg
->Class
) {
826 case 1: s
= "unknown class"; break;
827 case 2: s
= "unknown function"; break;
828 default: s
= "unkown error"; break;
831 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x function %d: %s\n",
833 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
834 cmsg
->adr
.adrController
,
839 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
841 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
843 case CAPI_INFO_IND
: /* Controller/plci */
845 case CAPI_INFO_CONF
: /* Controller/plci */
849 printk(KERN_ERR
"capidrv-%d: got %s from controller 0x%x ???",
851 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
852 cmsg
->adr
.adrController
);
857 printk(KERN_INFO
"capidrv-%d: %s from controller 0x%x ignored\n",
859 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
860 cmsg
->adr
.adrController
);
863 static void handle_incoming_call(capidrv_contr
* card
, _cmsg
* cmsg
)
866 capidrv_bchan
*bchan
;
870 if ((chan
= new_bchan(card
)) == -1) {
871 printk(KERN_ERR
"capidrv-%d: incoming call on not existing bchan ?\n", card
->contrnr
);
874 bchan
= &card
->bchans
[chan
];
875 if ((plcip
= new_plci(card
, chan
)) == 0) {
876 printk(KERN_ERR
"capidrv-%d: incoming call: no memory, sorry.\n", card
->contrnr
);
880 plcip
->plci
= cmsg
->adr
.adrPLCI
;
881 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_IND
);
883 cmd
.command
= ISDN_STAT_ICALL
;
884 cmd
.driver
= card
->myid
;
886 memset(&cmd
.parm
.setup
, 0, sizeof(cmd
.parm
.setup
));
887 strncpy(cmd
.parm
.setup
.phone
,
888 cmsg
->CallingPartyNumber
+ 3,
889 cmsg
->CallingPartyNumber
[0] - 2);
890 strncpy(cmd
.parm
.setup
.eazmsn
,
891 cmsg
->CalledPartyNumber
+ 2,
892 cmsg
->CalledPartyNumber
[0] - 1);
893 cmd
.parm
.setup
.si1
= cip2si1(cmsg
->CIPValue
);
894 cmd
.parm
.setup
.si2
= cip2si2(cmsg
->CIPValue
);
895 cmd
.parm
.setup
.plan
= cmsg
->CallingPartyNumber
[1];
896 cmd
.parm
.setup
.screen
= cmsg
->CallingPartyNumber
[2];
898 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s\n",
900 cmd
.parm
.setup
.phone
,
903 cmd
.parm
.setup
.eazmsn
);
905 if (cmd
.parm
.setup
.si1
== 1 && cmd
.parm
.setup
.si2
!= 0) {
906 printk(KERN_INFO
"capidrv-%d: patching si2=%d to 0 for VBOX\n",
909 cmd
.parm
.setup
.si2
= 0;
912 switch (card
->interface
.statcallb(&cmd
)) {
915 /* No device matching this call.
916 * and isdn_common.c has send a HANGUP command
917 * which is ignored in state ST_PLCI_INCOMING,
918 * so we send RESP to ignore the call
920 capi_cmsg_answer(cmsg
);
921 cmsg
->Reject
= 1; /* ignore */
922 send_message(card
, cmsg
);
923 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
924 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
926 cmd
.parm
.setup
.phone
,
929 cmd
.parm
.setup
.eazmsn
);
932 /* At least one device matching this call (RING on ttyI)
933 * HL-driver may send ALERTING on the D-channel in this
935 * really means: RING on ttyI or a net interface
936 * accepted this call already.
938 * If the call was accepted, state has already changed,
939 * and CONNECT_RESP already sent.
941 if (plcip
->state
== ST_PLCI_INCOMING
) {
942 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
944 cmd
.parm
.setup
.phone
,
947 cmd
.parm
.setup
.eazmsn
);
948 capi_fill_ALERT_REQ(cmsg
,
951 plcip
->plci
, /* adr */
952 NULL
,/* BChannelinformation */
953 NULL
,/* Keypadfacility */
954 NULL
,/* Useruserdata */
955 NULL
/* Facilitydataarray */
957 plcip
->msgid
= cmsg
->Messagenumber
;
958 send_message(card
, cmsg
);
960 printk(KERN_INFO
"capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
962 cmd
.parm
.setup
.phone
,
965 cmd
.parm
.setup
.eazmsn
);
969 case 2: /* Call will be rejected. */
970 capi_cmsg_answer(cmsg
);
971 cmsg
->Reject
= 2; /* reject call, normal call clearing */
972 send_message(card
, cmsg
);
973 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
977 /* An error happened. (Invalid parameters for example.) */
978 capi_cmsg_answer(cmsg
);
979 cmsg
->Reject
= 8; /* reject call,
980 destination out of order */
981 send_message(card
, cmsg
);
982 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REJECT
);
988 static void handle_plci(_cmsg
* cmsg
)
990 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
996 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
997 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
998 cmsg
->adr
.adrController
& 0x7f);
1001 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1003 case CAPI_DISCONNECT_IND
: /* plci */
1005 printk(KERN_INFO
"capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1007 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1008 cmsg
->Reason
, capi_info2str(cmsg
->Reason
), cmsg
->adr
.adrPLCI
);
1010 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
))) {
1011 capi_cmsg_answer(cmsg
);
1012 send_message(card
, cmsg
);
1015 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1016 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_IND
);
1017 capi_cmsg_answer(cmsg
);
1018 send_message(card
, cmsg
);
1019 plci_change_state(card
, plcip
, EV_PLCI_DISCONNECT_RESP
);
1022 case CAPI_DISCONNECT_CONF
: /* plci */
1024 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1026 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1027 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1030 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1033 card
->bchans
[plcip
->chan
].disconnecting
= 1;
1036 case CAPI_ALERT_CONF
: /* plci */
1038 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1040 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1041 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1046 case CAPI_CONNECT_IND
: /* plci */
1047 handle_incoming_call(card
, cmsg
);
1050 case CAPI_CONNECT_CONF
: /* plci */
1052 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1054 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1055 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1058 if (!(plcip
= find_plci_by_msgid(card
, cmsg
->Messagenumber
)))
1061 plcip
->plci
= cmsg
->adr
.adrPLCI
;
1063 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_ERROR
);
1065 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_CONF_OK
);
1069 case CAPI_CONNECT_ACTIVE_IND
: /* plci */
1071 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1074 if (card
->bchans
[plcip
->chan
].incoming
) {
1075 capi_cmsg_answer(cmsg
);
1076 send_message(card
, cmsg
);
1077 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_ACTIVE_IND
);
1079 capidrv_ncci
*nccip
;
1080 capi_cmsg_answer(cmsg
);
1081 send_message(card
, cmsg
);
1083 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrPLCI
);
1086 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1089 capi_fill_CONNECT_B3_REQ(cmsg
,
1092 plcip
->plci
, /* adr */
1095 nccip
->msgid
= cmsg
->Messagenumber
;
1096 send_message(card
, cmsg
);
1097 cmd
.command
= ISDN_STAT_DCONN
;
1098 cmd
.driver
= card
->myid
;
1099 cmd
.arg
= plcip
->chan
;
1100 card
->interface
.statcallb(&cmd
);
1101 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_ACTIVE_IND
);
1102 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_REQ
);
1106 case CAPI_INFO_IND
: /* Controller/plci */
1108 if (!(plcip
= find_plci_by_plci(card
, cmsg
->adr
.adrPLCI
)))
1111 if (cmsg
->InfoNumber
== 0x4000) {
1112 if (cmsg
->InfoElement
[0] == 4) {
1113 cmd
.command
= ISDN_STAT_CINF
;
1114 cmd
.driver
= card
->myid
;
1115 cmd
.arg
= plcip
->chan
;
1116 sprintf(cmd
.parm
.num
, "%lu",
1118 ((u32
) cmsg
->InfoElement
[1]
1119 | ((u32
) (cmsg
->InfoElement
[2]) << 8)
1120 | ((u32
) (cmsg
->InfoElement
[3]) << 16)
1121 | ((u32
) (cmsg
->InfoElement
[4]) << 24)));
1122 card
->interface
.statcallb(&cmd
);
1126 cdb
= capi_cmsg2str(cmsg
);
1128 printk(KERN_WARNING
"capidrv-%d: %s\n",
1129 card
->contrnr
, cdb
->buf
);
1132 printk(KERN_WARNING
"capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n",
1133 card
->contrnr
, cmsg
->InfoNumber
);
1137 case CAPI_CONNECT_ACTIVE_CONF
: /* plci */
1139 case CAPI_SELECT_B_PROTOCOL_CONF
: /* plci */
1141 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1143 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1146 case CAPI_INFO_CONF
: /* Controller/plci */
1150 printk(KERN_ERR
"capidrv-%d: got %s for plci 0x%x ???",
1152 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1157 printk(KERN_INFO
"capidrv-%d: %s for plci 0x%x ignored\n",
1159 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1163 printk(KERN_ERR
"capidrv-%d: %s: plci 0x%x not found\n",
1165 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1170 static void handle_ncci(_cmsg
* cmsg
)
1172 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1173 capidrv_plci
*plcip
;
1174 capidrv_ncci
*nccip
;
1179 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1180 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1181 cmsg
->adr
.adrController
& 0x7f);
1184 switch (CAPICMD(cmsg
->Command
, cmsg
->Subcommand
)) {
1186 case CAPI_CONNECT_B3_ACTIVE_IND
: /* ncci */
1187 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1190 capi_cmsg_answer(cmsg
);
1191 send_message(card
, cmsg
);
1192 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_ACTIVE_IND
);
1194 cmd
.command
= ISDN_STAT_BCONN
;
1195 cmd
.driver
= card
->myid
;
1196 cmd
.arg
= nccip
->chan
;
1197 card
->interface
.statcallb(&cmd
);
1199 printk(KERN_INFO
"capidrv-%d: chan %d up with ncci 0x%x\n",
1200 card
->contrnr
, nccip
->chan
, nccip
->ncci
);
1203 case CAPI_CONNECT_B3_ACTIVE_CONF
: /* ncci */
1206 case CAPI_CONNECT_B3_IND
: /* ncci */
1208 plcip
= find_plci_by_ncci(card
, cmsg
->adr
.adrNCCI
);
1210 nccip
= new_ncci(card
, plcip
, cmsg
->adr
.adrNCCI
);
1212 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_IND
);
1213 capi_fill_CONNECT_B3_RESP(cmsg
,
1216 nccip
->ncci
, /* adr */
1220 send_message(card
, cmsg
);
1221 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_RESP
);
1224 printk(KERN_ERR
"capidrv-%d: no mem for ncci, sorry\n", card
->contrnr
);
1226 printk(KERN_ERR
"capidrv-%d: %s: plci for ncci 0x%x not found\n",
1228 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1231 capi_fill_CONNECT_B3_RESP(cmsg
,
1238 send_message(card
, cmsg
);
1241 case CAPI_CONNECT_B3_CONF
: /* ncci */
1243 if (!(nccip
= find_ncci_by_msgid(card
,
1245 cmsg
->Messagenumber
)))
1248 nccip
->ncci
= cmsg
->adr
.adrNCCI
;
1250 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1252 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1253 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1258 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_ERROR
);
1260 ncci_change_state(card
, nccip
, EV_NCCI_CONNECT_B3_CONF_OK
);
1263 case CAPI_CONNECT_B3_T90_ACTIVE_IND
: /* ncci */
1264 capi_cmsg_answer(cmsg
);
1265 send_message(card
, cmsg
);
1268 case CAPI_DATA_B3_IND
: /* ncci */
1269 /* handled in handle_data() */
1272 case CAPI_DATA_B3_CONF
: /* ncci */
1274 printk(KERN_WARNING
"CAPI_DATA_B3_CONF: Info %x - %s\n",
1275 cmsg
->Info
, capi_info2str(cmsg
->Info
));
1277 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1280 len
= capidrv_del_ack(nccip
, cmsg
->DataHandle
);
1283 cmd
.command
= ISDN_STAT_BSENT
;
1284 cmd
.driver
= card
->myid
;
1285 cmd
.arg
= nccip
->chan
;
1286 cmd
.parm
.length
= len
;
1287 card
->interface
.statcallb(&cmd
);
1290 case CAPI_DISCONNECT_B3_IND
: /* ncci */
1291 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1294 card
->bchans
[nccip
->chan
].disconnecting
= 1;
1295 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_IND
);
1296 capi_cmsg_answer(cmsg
);
1297 send_message(card
, cmsg
);
1298 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_RESP
);
1301 case CAPI_DISCONNECT_B3_CONF
: /* ncci */
1302 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1305 printk(KERN_INFO
"capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1307 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1308 cmsg
->Info
, capi_info2str(cmsg
->Info
),
1310 ncci_change_state(card
, nccip
, EV_NCCI_DISCONNECT_B3_CONF_ERROR
);
1314 case CAPI_RESET_B3_IND
: /* ncci */
1315 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
)))
1317 ncci_change_state(card
, nccip
, EV_NCCI_RESET_B3_IND
);
1318 capi_cmsg_answer(cmsg
);
1319 send_message(card
, cmsg
);
1322 case CAPI_RESET_B3_CONF
: /* ncci */
1323 goto ignored
; /* $$$$ */
1325 case CAPI_FACILITY_IND
: /* Controller/plci/ncci */
1327 case CAPI_FACILITY_CONF
: /* Controller/plci/ncci */
1331 printk(KERN_ERR
"capidrv-%d: got %s for ncci 0x%x ???",
1333 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1338 printk(KERN_INFO
"capidrv-%d: %s for ncci 0x%x ignored\n",
1340 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1344 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1346 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1351 static void handle_data(_cmsg
* cmsg
, struct sk_buff
*skb
)
1353 capidrv_contr
*card
= findcontrbynumber(cmsg
->adr
.adrController
& 0x7f);
1354 capidrv_ncci
*nccip
;
1357 printk(KERN_ERR
"capidrv: %s from unknown controller 0x%x\n",
1358 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1359 cmsg
->adr
.adrController
& 0x7f);
1363 if (!(nccip
= find_ncci(card
, cmsg
->adr
.adrNCCI
))) {
1364 printk(KERN_ERR
"capidrv-%d: %s: ncci 0x%x not found\n",
1366 capi_cmd2str(cmsg
->Command
, cmsg
->Subcommand
),
1371 (void) skb_pull(skb
, CAPIMSG_LEN(skb
->data
));
1372 card
->interface
.rcvcallb_skb(card
->myid
, nccip
->chan
, skb
);
1373 capi_cmsg_answer(cmsg
);
1374 send_message(card
, cmsg
);
1377 static _cmsg s_cmsg
;
1379 static void capidrv_recv_message(struct capi20_appl
*ap
, struct sk_buff
*skb
)
1381 capi_message2cmsg(&s_cmsg
, skb
->data
);
1382 if (debugmode
> 3) {
1383 _cdebbuf
*cdb
= capi_cmsg2str(&s_cmsg
);
1386 printk(KERN_DEBUG
"%s: applid=%d %s\n", __FUNCTION__
,
1387 ap
->applid
, cdb
->buf
);
1390 printk(KERN_DEBUG
"%s: applid=%d %s not traced\n",
1391 __FUNCTION__
, ap
->applid
,
1392 capi_cmd2str(s_cmsg
.Command
, s_cmsg
.Subcommand
));
1394 if (s_cmsg
.Command
== CAPI_DATA_B3
1395 && s_cmsg
.Subcommand
== CAPI_IND
) {
1396 handle_data(&s_cmsg
, skb
);
1399 if ((s_cmsg
.adr
.adrController
& 0xffffff00) == 0)
1400 handle_controller(&s_cmsg
);
1401 else if ((s_cmsg
.adr
.adrPLCI
& 0xffff0000) == 0)
1402 handle_plci(&s_cmsg
);
1404 handle_ncci(&s_cmsg
);
1406 * data of skb used in s_cmsg,
1407 * free data when s_cmsg is not used again
1408 * thanks to Lars Heete <hel@admin.de>
1413 /* ------------------------------------------------------------------- */
1415 #define PUTBYTE_TO_STATUS(card, byte) \
1417 *(card)->q931_write++ = (byte); \
1418 if ((card)->q931_write > (card)->q931_end) \
1419 (card)->q931_write = (card)->q931_buf; \
1422 static void handle_dtrace_data(capidrv_contr
*card
,
1423 int send
, int level2
, u8
*data
, u16 len
)
1429 printk(KERN_DEBUG
"capidrv-%d: avmb1_q931_data: len == %d\n",
1430 card
->contrnr
, len
);
1435 PUTBYTE_TO_STATUS(card
, 'D');
1436 PUTBYTE_TO_STATUS(card
, '2');
1437 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1438 PUTBYTE_TO_STATUS(card
, ':');
1440 PUTBYTE_TO_STATUS(card
, 'D');
1441 PUTBYTE_TO_STATUS(card
, '3');
1442 PUTBYTE_TO_STATUS(card
, send
? '>' : '<');
1443 PUTBYTE_TO_STATUS(card
, ':');
1446 for (p
= data
, end
= data
+len
; p
< end
; p
++) {
1448 PUTBYTE_TO_STATUS(card
, ' ');
1449 w
= (*p
>> 4) & 0xf;
1450 PUTBYTE_TO_STATUS(card
, (w
< 10) ? '0'+w
: 'A'-10+w
);
1452 PUTBYTE_TO_STATUS(card
, (w
< 10) ? '0'+w
: 'A'-10+w
);
1454 PUTBYTE_TO_STATUS(card
, '\n');
1456 cmd
.command
= ISDN_STAT_STAVAIL
;
1457 cmd
.driver
= card
->myid
;
1459 card
->interface
.statcallb(&cmd
);
1462 /* ------------------------------------------------------------------- */
1464 static _cmsg cmdcmsg
;
1466 static int capidrv_ioctl(isdn_ctrl
* c
, capidrv_contr
* card
)
1470 debugmode
= (int)(*((unsigned int *)c
->parm
.num
));
1471 printk(KERN_DEBUG
"capidrv-%d: debugmode=%d\n",
1472 card
->contrnr
, debugmode
);
1475 printk(KERN_DEBUG
"capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1476 card
->contrnr
, c
->arg
);
1483 * Handle leased lines (CAPI-Bundling)
1486 struct internal_bchannelinfo
{
1487 unsigned short channelalloc
;
1488 unsigned short operation
;
1489 unsigned char cmask
[31];
1492 static int decodeFVteln(char *teln
, unsigned long *bmaskp
, int *activep
)
1494 unsigned long bmask
= 0;
1499 if (strncmp(teln
, "FV:", 3) != 0)
1502 while (*s
&& *s
== ' ') s
++;
1504 if (*s
== 'p' || *s
== 'P') {
1508 if (*s
== 'a' || *s
== 'A') {
1515 if (!isdigit(*s
)) return -3;
1516 while (isdigit(*s
)) { digit1
= digit1
*10 + (*s
- '0'); s
++; }
1517 if (digit1
<= 0 && digit1
> 30) return -4;
1518 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1519 bmask
|= (1 << digit1
);
1524 if (*s
!= '-') return -5;
1526 if (!isdigit(*s
)) return -3;
1527 while (isdigit(*s
)) { digit2
= digit2
*10 + (*s
- '0'); s
++; }
1528 if (digit2
<= 0 && digit2
> 30) return -4;
1529 if (*s
== 0 || *s
== ',' || *s
== ' ') {
1530 if (digit1
> digit2
)
1531 for (i
= digit2
; i
<= digit1
; i
++)
1534 for (i
= digit1
; i
<= digit2
; i
++)
1536 digit1
= digit2
= 0;
1542 if (activep
) *activep
= active
;
1543 if (bmaskp
) *bmaskp
= bmask
;
1547 static int FVteln2capi20(char *teln
, u8 AdditionalInfo
[1+2+2+31])
1549 unsigned long bmask
;
1553 rc
= decodeFVteln(teln
, &bmask
, &active
);
1556 AdditionalInfo
[0] = 2+2+31;
1557 /* Channel: 3 => use channel allocation */
1558 AdditionalInfo
[1] = 3; AdditionalInfo
[2] = 0;
1559 /* Operation: 0 => DTE mode, 1 => DCE mode */
1561 AdditionalInfo
[3] = 0; AdditionalInfo
[4] = 0;
1563 AdditionalInfo
[3] = 1; AdditionalInfo
[4] = 0;
1565 /* Channel mask array */
1566 AdditionalInfo
[5] = 0; /* no D-Channel */
1567 for (i
=1; i
<= 30; i
++)
1568 AdditionalInfo
[5+i
] = (bmask
& (1 << i
)) ? 0xff : 0;
1572 static int capidrv_command(isdn_ctrl
* c
, capidrv_contr
* card
)
1575 struct capidrv_bchan
*bchan
;
1576 struct capidrv_plci
*plcip
;
1577 u8 AdditionalInfo
[1+2+2+31];
1578 int rc
, isleasedline
= 0;
1580 if (c
->command
== ISDN_CMD_IOCTL
)
1581 return capidrv_ioctl(c
, card
);
1583 switch (c
->command
) {
1584 case ISDN_CMD_DIAL
:{
1585 u8 calling
[ISDN_MSNLEN
+ 3];
1586 u8 called
[ISDN_MSNLEN
+ 2];
1589 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1592 c
->parm
.setup
.phone
,
1595 c
->parm
.setup
.eazmsn
);
1597 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1600 printk(KERN_ERR
"capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1603 c
->parm
.setup
.phone
,
1606 c
->parm
.setup
.eazmsn
,
1607 bchan
->plcip
->plci
);
1610 bchan
->si1
= c
->parm
.setup
.si1
;
1611 bchan
->si2
= c
->parm
.setup
.si2
;
1613 strncpy(bchan
->num
, c
->parm
.setup
.phone
, sizeof(bchan
->num
));
1614 strncpy(bchan
->mynum
, c
->parm
.setup
.eazmsn
, sizeof(bchan
->mynum
));
1615 rc
= FVteln2capi20(bchan
->num
, AdditionalInfo
);
1616 isleasedline
= (rc
== 0);
1618 printk(KERN_ERR
"capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card
->contrnr
, bchan
->num
);
1624 printk(KERN_DEBUG
"capidrv-%d: connecting leased line\n", card
->contrnr
);
1626 calling
[0] = strlen(bchan
->mynum
) + 2;
1629 strncpy(calling
+ 3, bchan
->mynum
, ISDN_MSNLEN
);
1630 called
[0] = strlen(bchan
->num
) + 1;
1632 strncpy(called
+ 2, bchan
->num
, ISDN_MSNLEN
);
1635 capi_fill_CONNECT_REQ(&cmdcmsg
,
1638 card
->contrnr
, /* adr */
1639 si2cip(bchan
->si1
, bchan
->si2
), /* cipvalue */
1640 called
, /* CalledPartyNumber */
1641 calling
, /* CallingPartyNumber */
1642 NULL
, /* CalledPartySubaddress */
1643 NULL
, /* CallingPartySubaddress */
1644 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1645 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1646 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1647 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1648 NULL
, /* B2configuration */
1649 NULL
, /* B3configuration */
1653 /* BChannelinformation */
1654 isleasedline
? AdditionalInfo
: NULL
,
1655 NULL
, /* Keypadfacility */
1656 NULL
, /* Useruserdata */
1657 NULL
/* Facilitydataarray */
1659 if ((plcip
= new_plci(card
, (c
->arg
% card
->nbchan
))) == 0) {
1660 cmd
.command
= ISDN_STAT_DHUP
;
1661 cmd
.driver
= card
->myid
;
1662 cmd
.arg
= (c
->arg
% card
->nbchan
);
1663 card
->interface
.statcallb(&cmd
);
1666 plcip
->msgid
= cmdcmsg
.Messagenumber
;
1667 plcip
->leasedline
= isleasedline
;
1668 plci_change_state(card
, plcip
, EV_PLCI_CONNECT_REQ
);
1669 send_message(card
, &cmdcmsg
);
1673 case ISDN_CMD_ACCEPTD
:
1675 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1677 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1679 c
->arg
, bchan
->l2
, bchan
->l3
);
1681 capi_fill_CONNECT_RESP(&cmdcmsg
,
1684 bchan
->plcip
->plci
, /* adr */
1686 b1prot(bchan
->l2
, bchan
->l3
), /* B1protocol */
1687 b2prot(bchan
->l2
, bchan
->l3
), /* B2protocol */
1688 b3prot(bchan
->l2
, bchan
->l3
), /* B3protocol */
1689 b1config(bchan
->l2
, bchan
->l3
), /* B1configuration */
1690 NULL
, /* B2configuration */
1691 NULL
, /* B3configuration */
1692 NULL
, /* ConnectedNumber */
1693 NULL
, /* ConnectedSubaddress */
1695 NULL
, /* BChannelinformation */
1696 NULL
, /* Keypadfacility */
1697 NULL
, /* Useruserdata */
1698 NULL
/* Facilitydataarray */
1700 capi_cmsg2message(&cmdcmsg
, cmdcmsg
.buf
);
1701 plci_change_state(card
, bchan
->plcip
, EV_PLCI_CONNECT_RESP
);
1702 send_message(card
, &cmdcmsg
);
1705 case ISDN_CMD_ACCEPTB
:
1707 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1712 case ISDN_CMD_HANGUP
:
1714 printk(KERN_DEBUG
"capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1717 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1719 if (bchan
->disconnecting
) {
1721 printk(KERN_DEBUG
"capidrv-%d: chan %ld already disconnecting ...\n",
1727 bchan
->disconnecting
= 1;
1728 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg
,
1734 ncci_change_state(card
, bchan
->nccip
, EV_NCCI_DISCONNECT_B3_REQ
);
1735 send_message(card
, &cmdcmsg
);
1737 } else if (bchan
->plcip
) {
1738 if (bchan
->plcip
->state
== ST_PLCI_INCOMING
) {
1740 * just ignore, we a called from
1741 * isdn_status_callback(),
1742 * which will return 0 or 2, this is handled
1743 * by the CONNECT_IND handler
1745 bchan
->disconnecting
= 1;
1747 } else if (bchan
->plcip
->plci
) {
1748 bchan
->disconnecting
= 1;
1749 capi_fill_DISCONNECT_REQ(&cmdcmsg
,
1753 NULL
, /* BChannelinformation */
1754 NULL
, /* Keypadfacility */
1755 NULL
, /* Useruserdata */
1756 NULL
/* Facilitydataarray */
1758 plci_change_state(card
, bchan
->plcip
, EV_PLCI_DISCONNECT_REQ
);
1759 send_message(card
, &cmdcmsg
);
1762 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1768 printk(KERN_ERR
"capidrv-%d: chan %ld disconnect request on free channel\n",
1774 case ISDN_CMD_SETL2
:
1776 printk(KERN_DEBUG
"capidrv-%d: set L2 on chan %ld to %ld\n",
1778 (c
->arg
& 0xff), (c
->arg
>> 8));
1779 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1780 bchan
->l2
= (c
->arg
>> 8);
1783 case ISDN_CMD_SETL3
:
1785 printk(KERN_DEBUG
"capidrv-%d: set L3 on chan %ld to %ld\n",
1787 (c
->arg
& 0xff), (c
->arg
>> 8));
1788 bchan
= &card
->bchans
[(c
->arg
& 0xff) % card
->nbchan
];
1789 bchan
->l3
= (c
->arg
>> 8);
1792 case ISDN_CMD_SETEAZ
:
1794 printk(KERN_DEBUG
"capidrv-%d: set EAZ \"%s\" on chan %ld\n",
1796 c
->parm
.num
, c
->arg
);
1797 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1798 strncpy(bchan
->msn
, c
->parm
.num
, ISDN_MSNLEN
);
1801 case ISDN_CMD_CLREAZ
:
1803 printk(KERN_DEBUG
"capidrv-%d: clearing EAZ on chan %ld\n",
1804 card
->contrnr
, c
->arg
);
1805 bchan
= &card
->bchans
[c
->arg
% card
->nbchan
];
1810 printk(KERN_ERR
"capidrv-%d: ISDN_CMD_%d, Huh?\n",
1811 card
->contrnr
, c
->command
);
1817 static int if_command(isdn_ctrl
* c
)
1819 capidrv_contr
*card
= findcontrbydriverid(c
->driver
);
1822 return capidrv_command(c
, card
);
1825 "capidrv: if_command %d called with invalid driverId %d!\n",
1826 c
->command
, c
->driver
);
1830 static _cmsg sendcmsg
;
1832 static int if_sendbuf(int id
, int channel
, int doack
, struct sk_buff
*skb
)
1834 capidrv_contr
*card
= findcontrbydriverid(id
);
1835 capidrv_bchan
*bchan
;
1836 capidrv_ncci
*nccip
;
1843 printk(KERN_ERR
"capidrv: if_sendbuf called with invalid driverId %d!\n",
1848 printk(KERN_DEBUG
"capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
1849 card
->contrnr
, len
, skb
, doack
);
1850 bchan
= &card
->bchans
[channel
% card
->nbchan
];
1851 nccip
= bchan
->nccip
;
1852 if (!nccip
|| nccip
->state
!= ST_NCCI_ACTIVE
) {
1853 printk(KERN_ERR
"capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
1854 card
->contrnr
, card
->name
, channel
);
1857 datahandle
= nccip
->datahandle
;
1858 capi_fill_DATA_B3_REQ(&sendcmsg
, global
.ap
.applid
, card
->msgid
++,
1859 nccip
->ncci
, /* adr */
1860 (u32
) skb
->data
, /* Data */
1861 skb
->len
, /* DataLength */
1862 datahandle
, /* DataHandle */
1866 if (capidrv_add_ack(nccip
, datahandle
, doack
? (int)skb
->len
: -1) < 0)
1869 capi_cmsg2message(&sendcmsg
, sendcmsg
.buf
);
1870 msglen
= CAPIMSG_LEN(sendcmsg
.buf
);
1871 if (skb_headroom(skb
) < msglen
) {
1872 struct sk_buff
*nskb
= skb_realloc_headroom(skb
, msglen
);
1874 printk(KERN_ERR
"capidrv-%d: if_sendbuf: no memory\n",
1876 (void)capidrv_del_ack(nccip
, datahandle
);
1879 printk(KERN_DEBUG
"capidrv-%d: only %d bytes headroom, need %d\n",
1880 card
->contrnr
, skb_headroom(skb
), msglen
);
1881 memcpy(skb_push(nskb
, msglen
), sendcmsg
.buf
, msglen
);
1882 errcode
= capi20_put_message(&global
.ap
, nskb
);
1883 if (errcode
== CAPI_NOERROR
) {
1885 nccip
->datahandle
++;
1889 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1890 card
->contrnr
, errcode
, capi_info2str(errcode
));
1891 (void)capidrv_del_ack(nccip
, datahandle
);
1892 dev_kfree_skb(nskb
);
1893 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
1895 memcpy(skb_push(skb
, msglen
), sendcmsg
.buf
, msglen
);
1896 errcode
= capi20_put_message(&global
.ap
, skb
);
1897 if (errcode
== CAPI_NOERROR
) {
1898 nccip
->datahandle
++;
1902 printk(KERN_DEBUG
"capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1903 card
->contrnr
, errcode
, capi_info2str(errcode
));
1904 skb_pull(skb
, msglen
);
1905 (void)capidrv_del_ack(nccip
, datahandle
);
1906 return errcode
== CAPI_SENDQUEUEFULL
? 0 : -1;
1910 static int if_readstat(u8 __user
*buf
, int len
, int id
, int channel
)
1912 capidrv_contr
*card
= findcontrbydriverid(id
);
1917 printk(KERN_ERR
"capidrv: if_readstat called with invalid driverId %d!\n",
1922 for (p
=buf
, count
=0; count
< len
; p
++, count
++) {
1923 if (put_user(*card
->q931_read
++, p
))
1925 if (card
->q931_read
> card
->q931_end
)
1926 card
->q931_read
= card
->q931_buf
;
1932 static void enable_dchannel_trace(capidrv_contr
*card
)
1934 u8 manufacturer
[CAPI_MANUFACTURER_LEN
];
1935 capi_version version
;
1936 u16 contr
= card
->contrnr
;
1940 errcode
= capi20_get_manufacturer(contr
, manufacturer
);
1941 if (errcode
!= CAPI_NOERROR
) {
1942 printk(KERN_ERR
"%s: can't get manufacturer (0x%x)\n",
1943 card
->name
, errcode
);
1946 if (strstr(manufacturer
, "AVM") == 0) {
1947 printk(KERN_ERR
"%s: not from AVM, no d-channel trace possible (%s)\n",
1948 card
->name
, manufacturer
);
1951 errcode
= capi20_get_version(contr
, &version
);
1952 if (errcode
!= CAPI_NOERROR
) {
1953 printk(KERN_ERR
"%s: can't get version (0x%x)\n",
1954 card
->name
, errcode
);
1957 avmversion
[0] = (version
.majormanuversion
>> 4) & 0x0f;
1958 avmversion
[1] = (version
.majormanuversion
<< 4) & 0xf0;
1959 avmversion
[1] |= (version
.minormanuversion
>> 4) & 0x0f;
1960 avmversion
[2] |= version
.minormanuversion
& 0x0f;
1962 if (avmversion
[0] > 3 || (avmversion
[0] == 3 && avmversion
[1] > 5)) {
1963 printk(KERN_INFO
"%s: D2 trace enabled\n", card
->name
);
1964 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
1967 0x214D5641, /* ManuID */
1970 (_cstruct
)"\004\200\014\000\000");
1972 printk(KERN_INFO
"%s: D3 trace enabled\n", card
->name
);
1973 capi_fill_MANUFACTURER_REQ(&cmdcmsg
, global
.ap
.applid
,
1976 0x214D5641, /* ManuID */
1979 (_cstruct
)"\004\002\003\000\000");
1981 send_message(card
, &cmdcmsg
);
1985 static void send_listen(capidrv_contr
*card
)
1987 capi_fill_LISTEN_REQ(&cmdcmsg
, global
.ap
.applid
,
1989 card
->contrnr
, /* controller */
1990 1 << 6, /* Infomask */
1994 send_message(card
, &cmdcmsg
);
1995 listen_change_state(card
, EV_LISTEN_REQ
);
1998 static void listentimerfunc(unsigned long x
)
2000 capidrv_contr
*card
= (capidrv_contr
*)x
;
2001 if (card
->state
!= ST_LISTEN_NONE
&& card
->state
!= ST_LISTEN_ACTIVE
)
2002 printk(KERN_ERR
"%s: controller dead ??\n", card
->name
);
2004 mod_timer(&card
->listentimer
, jiffies
+ 60*HZ
);
2008 static int capidrv_addcontr(u16 contr
, struct capi_profile
*profp
)
2010 capidrv_contr
*card
;
2011 unsigned long flags
;
2016 sprintf(id
, "capidrv-%d", contr
);
2017 if (!try_module_get(THIS_MODULE
)) {
2018 printk(KERN_WARNING
"capidrv: (%s) Could not reserve module\n", id
);
2021 if (!(card
= kzalloc(sizeof(capidrv_contr
), GFP_ATOMIC
))) {
2023 "capidrv: (%s) Could not allocate contr-struct.\n", id
);
2026 card
->owner
= THIS_MODULE
;
2027 init_timer(&card
->listentimer
);
2028 strcpy(card
->name
, id
);
2029 card
->contrnr
= contr
;
2030 card
->nbchan
= profp
->nbchannel
;
2031 card
->bchans
= kmalloc(sizeof(capidrv_bchan
) * card
->nbchan
, GFP_ATOMIC
);
2032 if (!card
->bchans
) {
2034 "capidrv: (%s) Could not allocate bchan-structs.\n", id
);
2035 module_put(card
->owner
);
2039 card
->interface
.channels
= profp
->nbchannel
;
2040 card
->interface
.maxbufsize
= 2048;
2041 card
->interface
.command
= if_command
;
2042 card
->interface
.writebuf_skb
= if_sendbuf
;
2043 card
->interface
.writecmd
= NULL
;
2044 card
->interface
.readstat
= if_readstat
;
2045 card
->interface
.features
= ISDN_FEATURE_L2_HDLC
|
2046 ISDN_FEATURE_L2_TRANS
|
2047 ISDN_FEATURE_L3_TRANS
|
2048 ISDN_FEATURE_P_UNKNOWN
|
2049 ISDN_FEATURE_L2_X75I
|
2050 ISDN_FEATURE_L2_X75UI
|
2051 ISDN_FEATURE_L2_X75BUI
;
2052 if (profp
->support1
& (1<<2))
2053 card
->interface
.features
|= ISDN_FEATURE_L2_V11096
|
2054 ISDN_FEATURE_L2_V11019
|
2055 ISDN_FEATURE_L2_V11038
;
2056 if (profp
->support1
& (1<<8))
2057 card
->interface
.features
|= ISDN_FEATURE_L2_MODEM
;
2058 card
->interface
.hl_hdrlen
= 22; /* len of DATA_B3_REQ */
2059 strncpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
) - 1);
2062 card
->q931_read
= card
->q931_buf
;
2063 card
->q931_write
= card
->q931_buf
;
2064 card
->q931_end
= card
->q931_buf
+ sizeof(card
->q931_buf
) - 1;
2066 if (!register_isdn(&card
->interface
)) {
2067 printk(KERN_ERR
"capidrv: Unable to register contr %s\n", id
);
2068 kfree(card
->bchans
);
2069 module_put(card
->owner
);
2073 card
->myid
= card
->interface
.channels
;
2074 memset(card
->bchans
, 0, sizeof(capidrv_bchan
) * card
->nbchan
);
2075 for (i
= 0; i
< card
->nbchan
; i
++) {
2076 card
->bchans
[i
].contr
= card
;
2079 spin_lock_irqsave(&global_lock
, flags
);
2080 card
->next
= global
.contr_list
;
2081 global
.contr_list
= card
;
2083 spin_unlock_irqrestore(&global_lock
, flags
);
2085 cmd
.command
= ISDN_STAT_RUN
;
2086 cmd
.driver
= card
->myid
;
2087 card
->interface
.statcallb(&cmd
);
2089 card
->cipmask
= 0x1FFF03FF; /* any */
2092 card
->listentimer
.data
= (unsigned long)card
;
2093 card
->listentimer
.function
= listentimerfunc
;
2095 mod_timer(&card
->listentimer
, jiffies
+ 60*HZ
);
2097 printk(KERN_INFO
"%s: now up (%d B channels)\n",
2098 card
->name
, card
->nbchan
);
2100 enable_dchannel_trace(card
);
2105 static int capidrv_delcontr(u16 contr
)
2107 capidrv_contr
**pp
, *card
;
2108 unsigned long flags
;
2111 spin_lock_irqsave(&global_lock
, flags
);
2112 for (card
= global
.contr_list
; card
; card
= card
->next
) {
2113 if (card
->contrnr
== contr
)
2117 spin_unlock_irqrestore(&global_lock
, flags
);
2118 printk(KERN_ERR
"capidrv: delcontr: no contr %u\n", contr
);
2121 #warning FIXME: maybe a race condition the card should be removed here from global list /kkeil
2122 spin_unlock_irqrestore(&global_lock
, flags
);
2124 del_timer(&card
->listentimer
);
2127 printk(KERN_DEBUG
"capidrv-%d: id=%d unloading\n",
2128 card
->contrnr
, card
->myid
);
2130 cmd
.command
= ISDN_STAT_STOP
;
2131 cmd
.driver
= card
->myid
;
2132 card
->interface
.statcallb(&cmd
);
2134 while (card
->nbchan
) {
2136 cmd
.command
= ISDN_STAT_DISCH
;
2137 cmd
.driver
= card
->myid
;
2138 cmd
.arg
= card
->nbchan
-1;
2139 cmd
.parm
.num
[0] = 0;
2141 printk(KERN_DEBUG
"capidrv-%d: id=%d disable chan=%ld\n",
2142 card
->contrnr
, card
->myid
, cmd
.arg
);
2143 card
->interface
.statcallb(&cmd
);
2145 if (card
->bchans
[card
->nbchan
-1].nccip
)
2146 free_ncci(card
, card
->bchans
[card
->nbchan
-1].nccip
);
2147 if (card
->bchans
[card
->nbchan
-1].plcip
)
2148 free_plci(card
, card
->bchans
[card
->nbchan
-1].plcip
);
2149 if (card
->plci_list
)
2150 printk(KERN_ERR
"capidrv: bug in free_plci()\n");
2153 kfree(card
->bchans
);
2154 card
->bchans
= NULL
;
2157 printk(KERN_DEBUG
"capidrv-%d: id=%d isdn unload\n",
2158 card
->contrnr
, card
->myid
);
2160 cmd
.command
= ISDN_STAT_UNLOAD
;
2161 cmd
.driver
= card
->myid
;
2162 card
->interface
.statcallb(&cmd
);
2165 printk(KERN_DEBUG
"capidrv-%d: id=%d remove contr from list\n",
2166 card
->contrnr
, card
->myid
);
2168 spin_lock_irqsave(&global_lock
, flags
);
2169 for (pp
= &global
.contr_list
; *pp
; pp
= &(*pp
)->next
) {
2177 spin_unlock_irqrestore(&global_lock
, flags
);
2179 module_put(card
->owner
);
2180 printk(KERN_INFO
"%s: now down.\n", card
->name
);
2186 static void lower_callback(unsigned int cmd
, u32 contr
, void *data
)
2191 printk(KERN_INFO
"capidrv: controller %hu up\n", contr
);
2192 (void) capidrv_addcontr(contr
, (capi_profile
*) data
);
2195 printk(KERN_INFO
"capidrv: controller %hu down\n", contr
);
2196 (void) capidrv_delcontr(contr
);
2202 * /proc/capi/capidrv:
2203 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2205 static int proc_capidrv_read_proc(char *page
, char **start
, off_t off
,
2206 int count
, int *eof
, void *data
)
2210 len
+= sprintf(page
+len
, "%lu %lu %lu %lu\n",
2211 global
.ap
.nrecvctlpkt
,
2212 global
.ap
.nrecvdatapkt
,
2213 global
.ap
.nsentctlpkt
,
2214 global
.ap
.nsentdatapkt
);
2215 if (off
+count
>= len
)
2219 *start
= page
+ off
;
2220 return ((count
< len
-off
) ? count
: len
-off
);
2223 static struct procfsentries
{
2226 int (*read_proc
)(char *page
, char **start
, off_t off
,
2227 int count
, int *eof
, void *data
);
2228 struct proc_dir_entry
*procent
;
2229 } procfsentries
[] = {
2230 /* { "capi", S_IFDIR, 0 }, */
2231 { "capi/capidrv", 0 , proc_capidrv_read_proc
},
2234 static void __init
proc_init(void)
2236 int nelem
= ARRAY_SIZE(procfsentries
);
2239 for (i
=0; i
< nelem
; i
++) {
2240 struct procfsentries
*p
= procfsentries
+ i
;
2241 p
->procent
= create_proc_entry(p
->name
, p
->mode
, NULL
);
2242 if (p
->procent
) p
->procent
->read_proc
= p
->read_proc
;
2246 static void __exit
proc_exit(void)
2248 int nelem
= ARRAY_SIZE(procfsentries
);
2251 for (i
=nelem
-1; i
>= 0; i
--) {
2252 struct procfsentries
*p
= procfsentries
+ i
;
2254 remove_proc_entry(p
->name
, NULL
);
2260 static int __init
capidrv_init(void)
2262 capi_profile profile
;
2268 if ((p
= strchr(revision
, ':')) != 0 && p
[1]) {
2269 strncpy(rev
, p
+ 2, sizeof(rev
));
2270 rev
[sizeof(rev
)-1] = 0;
2271 if ((p
= strchr(rev
, '$')) != 0 && p
> rev
)
2276 global
.ap
.rparam
.level3cnt
= -2; /* number of bchannels twice */
2277 global
.ap
.rparam
.datablkcnt
= 16;
2278 global
.ap
.rparam
.datablklen
= 2048;
2280 global
.ap
.recv_message
= capidrv_recv_message
;
2281 errcode
= capi20_register(&global
.ap
);
2286 capi20_set_callback(&global
.ap
, lower_callback
);
2288 errcode
= capi20_get_profile(0, &profile
);
2289 if (errcode
!= CAPI_NOERROR
) {
2290 capi20_release(&global
.ap
);
2294 ncontr
= profile
.ncontroller
;
2295 for (contr
= 1; contr
<= ncontr
; contr
++) {
2296 errcode
= capi20_get_profile(contr
, &profile
);
2297 if (errcode
!= CAPI_NOERROR
)
2299 (void) capidrv_addcontr(contr
, &profile
);
2303 printk(KERN_NOTICE
"capidrv: Rev %s: loaded\n", rev
);
2307 static void __exit
capidrv_exit(void)
2312 if ((p
= strchr(revision
, ':')) != 0) {
2314 p
= strchr(rev
, '$');
2317 strcpy(rev
, " ??? ");
2320 capi20_release(&global
.ap
);
2324 printk(KERN_NOTICE
"capidrv: Rev%s: unloaded\n", rev
);
2327 module_init(capidrv_init
);
2328 module_exit(capidrv_exit
);