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/sched.h>
17 #include <linux/slab.h>
18 #include <linux/fcntl.h>
20 #include <linux/signal.h>
22 #include <linux/timer.h>
23 #include <linux/wait.h>
24 #include <linux/skbuff.h>
25 #include <linux/isdn.h>
26 #include <linux/isdnif.h>
27 #include <linux/proc_fs.h>
28 #include <linux/capi.h>
29 #include <linux/kernelcapi.h>
30 #include <linux/ctype.h>
31 #include <linux/init.h>
32 #include <linux/moduleparam.h>
34 #include <linux/isdn/capiutil.h>
35 #include <linux/isdn/capicmd.h>
38 static char *revision = "$Revision: 1.1.2.2 $";
39 static int debugmode = 0;
41 MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux");
42 MODULE_AUTHOR("Carsten Paeth");
43 MODULE_LICENSE("GPL");
44 module_param(debugmode, uint, 0);
46 /* -------- type definitions ----------------------------------------- */
49 struct capidrv_contr {
51 struct capidrv_contr *next;
68 struct timer_list listentimer;
71 * ID of capi message sent
79 struct capidrv_bchan {
80 struct capidrv_contr *contr;
85 u8 mynum[ISDN_MSNLEN];
91 struct capidrv_plci *next;
93 u32 ncci; /* ncci for CONNECT_ACTIVE_IND */
94 u16 msgid; /* to identfy CONNECT_CONF */
99 struct capidrv_ncci *next;
100 struct capidrv_plci *plcip;
102 u16 msgid; /* to identfy CONNECT_B3_CONF */
108 struct ncci_datahandle_queue {
109 struct ncci_datahandle_queue *next;
115 struct capidrv_ncci *nccip;
118 struct capidrv_plci *plci_list;
128 struct capidrv_data {
129 struct capi20_appl ap;
131 struct capidrv_contr *contr_list;
134 typedef struct capidrv_plci capidrv_plci;
135 typedef struct capidrv_ncci capidrv_ncci;
136 typedef struct capidrv_contr capidrv_contr;
137 typedef struct capidrv_data capidrv_data;
138 typedef struct capidrv_bchan capidrv_bchan;
140 /* -------- data definitions ----------------------------------------- */
142 static capidrv_data global;
143 static DEFINE_SPINLOCK(global_lock);
145 static void handle_dtrace_data(capidrv_contr *card,
146 int send, int level2, u8 *data, u16 len);
148 /* -------- convert functions ---------------------------------------- */
150 static inline u32 b1prot(int l2, int l3)
153 case ISDN_PROTO_L2_X75I:
154 case ISDN_PROTO_L2_X75UI:
155 case ISDN_PROTO_L2_X75BUI:
157 case ISDN_PROTO_L2_HDLC:
160 case ISDN_PROTO_L2_TRANS:
162 case ISDN_PROTO_L2_V11096:
163 case ISDN_PROTO_L2_V11019:
164 case ISDN_PROTO_L2_V11038:
166 case ISDN_PROTO_L2_FAX:
168 case ISDN_PROTO_L2_MODEM:
173 static inline u32 b2prot(int l2, int l3)
176 case ISDN_PROTO_L2_X75I:
177 case ISDN_PROTO_L2_X75UI:
178 case ISDN_PROTO_L2_X75BUI:
181 case ISDN_PROTO_L2_HDLC:
182 case ISDN_PROTO_L2_TRANS:
183 case ISDN_PROTO_L2_V11096:
184 case ISDN_PROTO_L2_V11019:
185 case ISDN_PROTO_L2_V11038:
186 case ISDN_PROTO_L2_MODEM:
188 case ISDN_PROTO_L2_FAX:
193 static inline u32 b3prot(int l2, int l3)
196 case ISDN_PROTO_L2_X75I:
197 case ISDN_PROTO_L2_X75UI:
198 case ISDN_PROTO_L2_X75BUI:
199 case ISDN_PROTO_L2_HDLC:
200 case ISDN_PROTO_L2_TRANS:
201 case ISDN_PROTO_L2_V11096:
202 case ISDN_PROTO_L2_V11019:
203 case ISDN_PROTO_L2_V11038:
204 case ISDN_PROTO_L2_MODEM:
207 case ISDN_PROTO_L2_FAX:
212 static _cstruct b1config_async_v110(u16 rate)
214 /* CAPI-Spec "B1 Configuration" */
215 static unsigned char buf[9];
216 buf[0] = 8; /* len */
217 /* maximum bitrate */
218 buf[1] = rate & 0xff; buf[2] = (rate >> 8) & 0xff;
219 buf[3] = 8; buf[4] = 0; /* 8 bits per character */
220 buf[5] = 0; buf[6] = 0; /* parity none */
221 buf[7] = 0; buf[8] = 0; /* 1 stop bit */
225 static _cstruct b1config(int l2, int l3)
228 case ISDN_PROTO_L2_X75I:
229 case ISDN_PROTO_L2_X75UI:
230 case ISDN_PROTO_L2_X75BUI:
231 case ISDN_PROTO_L2_HDLC:
232 case ISDN_PROTO_L2_TRANS:
235 case ISDN_PROTO_L2_V11096:
236 return b1config_async_v110(9600);
237 case ISDN_PROTO_L2_V11019:
238 return b1config_async_v110(19200);
239 case ISDN_PROTO_L2_V11038:
240 return b1config_async_v110(38400);
244 static inline u16 si2cip(u8 si1, u8 si2)
246 static const u8 cip[17][5] =
249 {0, 0, 0, 0, 0}, /*0 */
250 {16, 16, 4, 26, 16}, /*1 */
251 {17, 17, 17, 4, 4}, /*2 */
252 {2, 2, 2, 2, 2}, /*3 */
253 {18, 18, 18, 18, 18}, /*4 */
254 {2, 2, 2, 2, 2}, /*5 */
255 {0, 0, 0, 0, 0}, /*6 */
256 {2, 2, 2, 2, 2}, /*7 */
257 {2, 2, 2, 2, 2}, /*8 */
258 {21, 21, 21, 21, 21}, /*9 */
259 {19, 19, 19, 19, 19}, /*10 */
260 {0, 0, 0, 0, 0}, /*11 */
261 {0, 0, 0, 0, 0}, /*12 */
262 {0, 0, 0, 0, 0}, /*13 */
263 {0, 0, 0, 0, 0}, /*14 */
264 {22, 22, 22, 22, 22}, /*15 */
265 {27, 27, 27, 28, 27} /*16 */
272 return (u16) cip[si1][si2];
275 static inline u8 cip2si1(u16 cipval)
277 static const u8 si[32] =
278 {7, 1, 7, 7, 1, 1, 7, 7, /*0-7 */
279 7, 1, 0, 0, 0, 0, 0, 0, /*8-15 */
280 1, 2, 4, 10, 9, 9, 15, 7, /*16-23 */
281 7, 7, 1, 16, 16, 0, 0, 0}; /*24-31 */
284 cipval = 0; /* .... */
288 static inline u8 cip2si2(u16 cipval)
290 static const u8 si[32] =
291 {0, 0, 0, 0, 2, 3, 0, 0, /*0-7 */
292 0, 3, 0, 0, 0, 0, 0, 0, /*8-15 */
293 1, 2, 0, 0, 9, 0, 0, 0, /*16-23 */
294 0, 0, 3, 2, 3, 0, 0, 0}; /*24-31 */
297 cipval = 0; /* .... */
302 /* -------- controller management ------------------------------------- */
304 static inline capidrv_contr *findcontrbydriverid(int driverid)
309 spin_lock_irqsave(&global_lock, flags);
310 for (p = global.contr_list; p; p = p->next)
311 if (p->myid == driverid)
313 spin_unlock_irqrestore(&global_lock, flags);
317 static capidrv_contr *findcontrbynumber(u32 contr)
320 capidrv_contr *p = global.contr_list;
322 spin_lock_irqsave(&global_lock, flags);
323 for (p = global.contr_list; p; p = p->next)
324 if (p->contrnr == contr)
326 spin_unlock_irqrestore(&global_lock, flags);
331 /* -------- plci management ------------------------------------------ */
333 static capidrv_plci *new_plci(capidrv_contr * card, int chan)
337 plcip = (capidrv_plci *) kmalloc(sizeof(capidrv_plci), GFP_ATOMIC);
342 memset(plcip, 0, sizeof(capidrv_plci));
343 plcip->state = ST_PLCI_NONE;
347 plcip->next = card->plci_list;
348 card->plci_list = plcip;
349 card->bchans[chan].plcip = plcip;
354 static capidrv_plci *find_plci_by_plci(capidrv_contr * card, u32 plci)
357 for (p = card->plci_list; p; p = p->next)
363 static capidrv_plci *find_plci_by_msgid(capidrv_contr * card, u16 msgid)
366 for (p = card->plci_list; p; p = p->next)
367 if (p->msgid == msgid)
372 static capidrv_plci *find_plci_by_ncci(capidrv_contr * card, u32 ncci)
375 for (p = card->plci_list; p; p = p->next)
376 if (p->plci == (ncci & 0xffff))
381 static void free_plci(capidrv_contr * card, capidrv_plci * plcip)
385 for (pp = &card->plci_list; *pp; pp = &(*pp)->next) {
388 card->bchans[plcip->chan].plcip = NULL;
389 card->bchans[plcip->chan].disconnecting = 0;
390 card->bchans[plcip->chan].incoming = 0;
395 printk(KERN_ERR "capidrv-%d: free_plci %p (0x%x) not found, Huh?\n",
396 card->contrnr, plcip, plcip->plci);
399 /* -------- ncci management ------------------------------------------ */
401 static inline capidrv_ncci *new_ncci(capidrv_contr * card,
402 capidrv_plci * plcip,
407 nccip = (capidrv_ncci *) kmalloc(sizeof(capidrv_ncci), GFP_ATOMIC);
412 memset(nccip, 0, sizeof(capidrv_ncci));
414 nccip->state = ST_NCCI_NONE;
415 nccip->plcip = plcip;
416 nccip->chan = plcip->chan;
417 nccip->datahandle = 0;
419 nccip->next = plcip->ncci_list;
420 plcip->ncci_list = nccip;
422 card->bchans[plcip->chan].nccip = nccip;
427 static inline capidrv_ncci *find_ncci(capidrv_contr * card, u32 ncci)
432 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
435 for (p = plcip->ncci_list; p; p = p->next)
441 static inline capidrv_ncci *find_ncci_by_msgid(capidrv_contr * card,
447 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
450 for (p = plcip->ncci_list; p; p = p->next)
451 if (p->msgid == msgid)
456 static void free_ncci(capidrv_contr * card, struct capidrv_ncci *nccip)
458 struct capidrv_ncci **pp;
460 for (pp = &(nccip->plcip->ncci_list); *pp; pp = &(*pp)->next) {
466 card->bchans[nccip->chan].nccip = NULL;
470 static int capidrv_add_ack(struct capidrv_ncci *nccip,
471 u16 datahandle, int len)
473 struct ncci_datahandle_queue *n, **pp;
475 n = (struct ncci_datahandle_queue *)
476 kmalloc(sizeof(struct ncci_datahandle_queue), GFP_ATOMIC);
478 printk(KERN_ERR "capidrv: kmalloc ncci_datahandle failed\n");
482 n->datahandle = datahandle;
484 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) ;
489 static int capidrv_del_ack(struct capidrv_ncci *nccip, u16 datahandle)
491 struct ncci_datahandle_queue **pp, *p;
494 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) {
495 if ((*pp)->datahandle == datahandle) {
506 /* -------- convert and send capi message ---------------------------- */
508 static void send_message(capidrv_contr * card, _cmsg * cmsg)
512 capi_cmsg2message(cmsg, cmsg->buf);
513 len = CAPIMSG_LEN(cmsg->buf);
514 skb = alloc_skb(len, GFP_ATOMIC);
515 memcpy(skb_put(skb, len), cmsg->buf, len);
516 if (capi20_put_message(&global.ap, skb) != CAPI_NOERROR)
520 /* -------- state machine -------------------------------------------- */
522 struct listenstatechange {
528 static struct listenstatechange listentable[] =
530 {ST_LISTEN_NONE, ST_LISTEN_WAIT_CONF, EV_LISTEN_REQ},
531 {ST_LISTEN_ACTIVE, ST_LISTEN_ACTIVE_WAIT_CONF, EV_LISTEN_REQ},
532 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_ERROR},
533 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_ERROR},
534 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
535 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
536 {ST_LISTEN_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
537 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
541 static void listen_change_state(capidrv_contr * card, int event)
543 struct listenstatechange *p = listentable;
545 if (card->state == p->actstate && p->event == event) {
547 printk(KERN_DEBUG "capidrv-%d: listen_change_state %d -> %d\n",
548 card->contrnr, card->state, p->nextstate);
549 card->state = p->nextstate;
554 printk(KERN_ERR "capidrv-%d: listen_change_state state=%d event=%d ????\n",
555 card->contrnr, card->state, event);
559 /* ------------------------------------------------------------------ */
561 static void p0(capidrv_contr * card, capidrv_plci * plci)
565 card->bchans[plci->chan].contr = NULL;
566 cmd.command = ISDN_STAT_DHUP;
567 cmd.driver = card->myid;
568 cmd.arg = plci->chan;
569 card->interface.statcallb(&cmd);
570 free_plci(card, plci);
573 /* ------------------------------------------------------------------ */
575 struct plcistatechange {
579 void (*changefunc) (capidrv_contr * card, capidrv_plci * plci);
582 static struct plcistatechange plcitable[] =
585 {ST_PLCI_NONE, ST_PLCI_OUTGOING, EV_PLCI_CONNECT_REQ, NULL},
586 {ST_PLCI_NONE, ST_PLCI_ALLOCATED, EV_PLCI_FACILITY_IND_UP, NULL},
587 {ST_PLCI_NONE, ST_PLCI_INCOMING, EV_PLCI_CONNECT_IND, NULL},
588 {ST_PLCI_NONE, ST_PLCI_RESUMEING, EV_PLCI_RESUME_REQ, NULL},
590 {ST_PLCI_OUTGOING, ST_PLCI_NONE, EV_PLCI_CONNECT_CONF_ERROR, p0},
591 {ST_PLCI_OUTGOING, ST_PLCI_ALLOCATED, EV_PLCI_CONNECT_CONF_OK, NULL},
593 {ST_PLCI_ALLOCATED, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
594 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
595 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
596 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
598 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
599 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
600 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
601 {ST_PLCI_ACTIVE, ST_PLCI_HELD, EV_PLCI_HOLD_IND, NULL},
602 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_SUSPEND_IND, NULL},
604 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
605 {ST_PLCI_INCOMING, ST_PLCI_FACILITY_IND, EV_PLCI_FACILITY_IND_UP, NULL},
606 {ST_PLCI_INCOMING, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_RESP, NULL},
607 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
608 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
609 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
610 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CD_IND, NULL},
612 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
613 {ST_PLCI_FACILITY_IND, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
614 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
615 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
616 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
618 {ST_PLCI_ACCEPTING, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
619 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
620 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
621 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
623 {ST_PLCI_DISCONNECTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
625 {ST_PLCI_DISCONNECTED, ST_PLCI_NONE, EV_PLCI_DISCONNECT_RESP, p0},
627 {ST_PLCI_RESUMEING, ST_PLCI_NONE, EV_PLCI_RESUME_CONF_ERROR, p0},
628 {ST_PLCI_RESUMEING, ST_PLCI_RESUME, EV_PLCI_RESUME_CONF_OK, NULL},
630 {ST_PLCI_RESUME, ST_PLCI_ACTIVE, EV_PLCI_RESUME_IND, NULL},
632 {ST_PLCI_HELD, ST_PLCI_ACTIVE, EV_PLCI_RETRIEVE_IND, NULL},
636 static void plci_change_state(capidrv_contr * card, capidrv_plci * plci, int event)
638 struct plcistatechange *p = plcitable;
640 if (plci->state == p->actstate && p->event == event) {
642 printk(KERN_DEBUG "capidrv-%d: plci_change_state:0x%x %d -> %d\n",
643 card->contrnr, plci->plci, plci->state, p->nextstate);
644 plci->state = p->nextstate;
646 p->changefunc(card, plci);
651 printk(KERN_ERR "capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
652 card->contrnr, plci->plci, plci->state, event);
655 /* ------------------------------------------------------------------ */
659 static void n0(capidrv_contr * card, capidrv_ncci * ncci)
663 capi_fill_DISCONNECT_REQ(&cmsg,
667 NULL, /* BChannelinformation */
668 NULL, /* Keypadfacility */
669 NULL, /* Useruserdata */ /* $$$$ */
670 NULL /* Facilitydataarray */
672 send_message(card, &cmsg);
673 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ);
675 cmd.command = ISDN_STAT_BHUP;
676 cmd.driver = card->myid;
677 cmd.arg = ncci->chan;
678 card->interface.statcallb(&cmd);
679 free_ncci(card, ncci);
682 /* ------------------------------------------------------------------ */
684 struct nccistatechange {
688 void (*changefunc) (capidrv_contr * card, capidrv_ncci * ncci);
691 static struct nccistatechange nccitable[] =
694 {ST_NCCI_NONE, ST_NCCI_OUTGOING, EV_NCCI_CONNECT_B3_REQ, NULL},
695 {ST_NCCI_NONE, ST_NCCI_INCOMING, EV_NCCI_CONNECT_B3_IND, NULL},
697 {ST_NCCI_OUTGOING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_CONF_OK, NULL},
698 {ST_NCCI_OUTGOING, ST_NCCI_NONE, EV_NCCI_CONNECT_B3_CONF_ERROR, n0},
700 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_CONNECT_B3_REJECT, NULL},
701 {ST_NCCI_INCOMING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_RESP, NULL},
702 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
703 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
705 {ST_NCCI_ALLOCATED, ST_NCCI_ACTIVE, EV_NCCI_CONNECT_B3_ACTIVE_IND, NULL},
706 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
707 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
709 {ST_NCCI_ACTIVE, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
710 {ST_NCCI_ACTIVE, ST_NCCI_RESETING, EV_NCCI_RESET_B3_REQ, NULL},
711 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
712 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
714 {ST_NCCI_RESETING, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
715 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
716 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
718 {ST_NCCI_DISCONNECTING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
719 {ST_NCCI_DISCONNECTING, ST_NCCI_PREVIOUS, EV_NCCI_DISCONNECT_B3_CONF_ERROR,NULL},
721 {ST_NCCI_DISCONNECTED, ST_NCCI_NONE, EV_NCCI_DISCONNECT_B3_RESP, n0},
725 static void ncci_change_state(capidrv_contr * card, capidrv_ncci * ncci, int event)
727 struct nccistatechange *p = nccitable;
729 if (ncci->state == p->actstate && p->event == event) {
731 printk(KERN_DEBUG "capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
732 card->contrnr, ncci->ncci, ncci->state, p->nextstate);
733 if (p->nextstate == ST_NCCI_PREVIOUS) {
734 ncci->state = ncci->oldstate;
735 ncci->oldstate = p->actstate;
737 ncci->oldstate = p->actstate;
738 ncci->state = p->nextstate;
741 p->changefunc(card, ncci);
746 printk(KERN_ERR "capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
747 card->contrnr, ncci->ncci, ncci->state, event);
750 /* ------------------------------------------------------------------- */
752 static inline int new_bchan(capidrv_contr * card)
755 for (i = 0; i < card->nbchan; i++) {
756 if (card->bchans[i].plcip == 0) {
757 card->bchans[i].disconnecting = 0;
764 /* ------------------------------------------------------------------- */
766 static void handle_controller(_cmsg * cmsg)
768 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
771 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
772 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
773 cmsg->adr.adrController & 0x7f);
776 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
778 case CAPI_LISTEN_CONF: /* Controller */
780 printk(KERN_DEBUG "capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
781 card->contrnr, cmsg->Info, capi_info2str(cmsg->Info), card->cipmask);
783 listen_change_state(card, EV_LISTEN_CONF_ERROR);
784 } else if (card->cipmask == 0) {
785 listen_change_state(card, EV_LISTEN_CONF_EMPTY);
787 listen_change_state(card, EV_LISTEN_CONF_OK);
791 case CAPI_MANUFACTURER_IND: /* Controller */
792 if ( cmsg->ManuID == 0x214D5641
794 && cmsg->Function == 1) {
795 u8 *data = cmsg->ManuData+3;
796 u16 len = cmsg->ManuData[0];
800 len = (cmsg->ManuData[1] | (cmsg->ManuData[2] << 8));
804 layer = ((*(data-1)) << 8) | *(data-2);
806 direction = (layer & 0x200) ? 0 : 1;
807 else direction = (layer & 0x800) ? 0 : 1;
808 if (layer & 0x0C00) {
809 if ((layer & 0xff) == 0x80) {
810 handle_dtrace_data(card, direction, 1, data, len);
813 } else if ((layer & 0xff) < 0x80) {
814 handle_dtrace_data(card, direction, 0, data, len);
817 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
819 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
820 cmsg->adr.adrController, layer);
824 case CAPI_MANUFACTURER_CONF: /* Controller */
825 if (cmsg->ManuID == 0x214D5641) {
827 switch (cmsg->Class) {
829 case 1: s = "unknown class"; break;
830 case 2: s = "unknown function"; break;
831 default: s = "unkown error"; break;
834 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x function %d: %s\n",
836 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
837 cmsg->adr.adrController,
842 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
844 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
846 case CAPI_INFO_IND: /* Controller/plci */
848 case CAPI_INFO_CONF: /* Controller/plci */
852 printk(KERN_ERR "capidrv-%d: got %s from controller 0x%x ???",
854 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
855 cmsg->adr.adrController);
860 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x ignored\n",
862 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
863 cmsg->adr.adrController);
866 static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
869 capidrv_bchan *bchan;
873 if ((chan = new_bchan(card)) == -1) {
874 printk(KERN_ERR "capidrv-%d: incoming call on not existing bchan ?\n", card->contrnr);
877 bchan = &card->bchans[chan];
878 if ((plcip = new_plci(card, chan)) == 0) {
879 printk(KERN_ERR "capidrv-%d: incoming call: no memory, sorry.\n", card->contrnr);
883 plcip->plci = cmsg->adr.adrPLCI;
884 plci_change_state(card, plcip, EV_PLCI_CONNECT_IND);
886 cmd.command = ISDN_STAT_ICALL;
887 cmd.driver = card->myid;
889 memset(&cmd.parm.setup, 0, sizeof(cmd.parm.setup));
890 strncpy(cmd.parm.setup.phone,
891 cmsg->CallingPartyNumber + 3,
892 cmsg->CallingPartyNumber[0] - 2);
893 strncpy(cmd.parm.setup.eazmsn,
894 cmsg->CalledPartyNumber + 2,
895 cmsg->CalledPartyNumber[0] - 1);
896 cmd.parm.setup.si1 = cip2si1(cmsg->CIPValue);
897 cmd.parm.setup.si2 = cip2si2(cmsg->CIPValue);
898 cmd.parm.setup.plan = cmsg->CallingPartyNumber[1];
899 cmd.parm.setup.screen = cmsg->CallingPartyNumber[2];
901 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s\n",
903 cmd.parm.setup.phone,
906 cmd.parm.setup.eazmsn);
908 if (cmd.parm.setup.si1 == 1 && cmd.parm.setup.si2 != 0) {
909 printk(KERN_INFO "capidrv-%d: patching si2=%d to 0 for VBOX\n",
912 cmd.parm.setup.si2 = 0;
915 switch (card->interface.statcallb(&cmd)) {
918 /* No device matching this call.
919 * and isdn_common.c has send a HANGUP command
920 * which is ignored in state ST_PLCI_INCOMING,
921 * so we send RESP to ignore the call
923 capi_cmsg_answer(cmsg);
924 cmsg->Reject = 1; /* ignore */
925 send_message(card, cmsg);
926 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
927 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
929 cmd.parm.setup.phone,
932 cmd.parm.setup.eazmsn);
935 /* At least one device matching this call (RING on ttyI)
936 * HL-driver may send ALERTING on the D-channel in this
938 * really means: RING on ttyI or a net interface
939 * accepted this call already.
941 * If the call was accepted, state has already changed,
942 * and CONNECT_RESP already sent.
944 if (plcip->state == ST_PLCI_INCOMING) {
945 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
947 cmd.parm.setup.phone,
950 cmd.parm.setup.eazmsn);
951 capi_fill_ALERT_REQ(cmsg,
954 plcip->plci, /* adr */
955 NULL,/* BChannelinformation */
956 NULL,/* Keypadfacility */
957 NULL,/* Useruserdata */
958 NULL /* Facilitydataarray */
960 plcip->msgid = cmsg->Messagenumber;
961 send_message(card, cmsg);
963 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
965 cmd.parm.setup.phone,
968 cmd.parm.setup.eazmsn);
972 case 2: /* Call will be rejected. */
973 capi_cmsg_answer(cmsg);
974 cmsg->Reject = 2; /* reject call, normal call clearing */
975 send_message(card, cmsg);
976 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
980 /* An error happened. (Invalid parameters for example.) */
981 capi_cmsg_answer(cmsg);
982 cmsg->Reject = 8; /* reject call,
983 destination out of order */
984 send_message(card, cmsg);
985 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
991 static void handle_plci(_cmsg * cmsg)
993 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
998 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
999 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1000 cmsg->adr.adrController & 0x7f);
1003 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
1005 case CAPI_DISCONNECT_IND: /* plci */
1007 printk(KERN_INFO "capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1009 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1010 cmsg->Reason, capi_info2str(cmsg->Reason), cmsg->adr.adrPLCI);
1012 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) {
1013 capi_cmsg_answer(cmsg);
1014 send_message(card, cmsg);
1017 card->bchans[plcip->chan].disconnecting = 1;
1018 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_IND);
1019 capi_cmsg_answer(cmsg);
1020 send_message(card, cmsg);
1021 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_RESP);
1024 case CAPI_DISCONNECT_CONF: /* plci */
1026 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1028 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1029 cmsg->Info, capi_info2str(cmsg->Info),
1032 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1035 card->bchans[plcip->chan].disconnecting = 1;
1038 case CAPI_ALERT_CONF: /* plci */
1040 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1042 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1043 cmsg->Info, capi_info2str(cmsg->Info),
1048 case CAPI_CONNECT_IND: /* plci */
1049 handle_incoming_call(card, cmsg);
1052 case CAPI_CONNECT_CONF: /* plci */
1054 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1056 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1057 cmsg->Info, capi_info2str(cmsg->Info),
1060 if (!(plcip = find_plci_by_msgid(card, cmsg->Messagenumber)))
1063 plcip->plci = cmsg->adr.adrPLCI;
1065 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_ERROR);
1067 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_OK);
1071 case CAPI_CONNECT_ACTIVE_IND: /* plci */
1073 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1076 if (card->bchans[plcip->chan].incoming) {
1077 capi_cmsg_answer(cmsg);
1078 send_message(card, cmsg);
1079 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1081 capidrv_ncci *nccip;
1082 capi_cmsg_answer(cmsg);
1083 send_message(card, cmsg);
1085 nccip = new_ncci(card, plcip, cmsg->adr.adrPLCI);
1088 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
1091 capi_fill_CONNECT_B3_REQ(cmsg,
1094 plcip->plci, /* adr */
1097 nccip->msgid = cmsg->Messagenumber;
1098 send_message(card, cmsg);
1099 cmd.command = ISDN_STAT_DCONN;
1100 cmd.driver = card->myid;
1101 cmd.arg = plcip->chan;
1102 card->interface.statcallb(&cmd);
1103 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1104 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_REQ);
1108 case CAPI_INFO_IND: /* Controller/plci */
1110 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1113 if (cmsg->InfoNumber == 0x4000) {
1114 if (cmsg->InfoElement[0] == 4) {
1115 cmd.command = ISDN_STAT_CINF;
1116 cmd.driver = card->myid;
1117 cmd.arg = plcip->chan;
1118 sprintf(cmd.parm.num, "%lu",
1120 ((u32) cmsg->InfoElement[1]
1121 | ((u32) (cmsg->InfoElement[2]) << 8)
1122 | ((u32) (cmsg->InfoElement[3]) << 16)
1123 | ((u32) (cmsg->InfoElement[4]) << 24)));
1124 card->interface.statcallb(&cmd);
1128 printk(KERN_ERR "capidrv-%d: %s\n",
1129 card->contrnr, capi_cmsg2str(cmsg));
1132 case CAPI_CONNECT_ACTIVE_CONF: /* plci */
1134 case CAPI_SELECT_B_PROTOCOL_CONF: /* plci */
1136 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1138 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1141 case CAPI_INFO_CONF: /* Controller/plci */
1145 printk(KERN_ERR "capidrv-%d: got %s for plci 0x%x ???",
1147 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1152 printk(KERN_INFO "capidrv-%d: %s for plci 0x%x ignored\n",
1154 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1158 printk(KERN_ERR "capidrv-%d: %s: plci 0x%x not found\n",
1160 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1165 static void handle_ncci(_cmsg * cmsg)
1167 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1168 capidrv_plci *plcip;
1169 capidrv_ncci *nccip;
1174 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1175 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1176 cmsg->adr.adrController & 0x7f);
1179 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
1181 case CAPI_CONNECT_B3_ACTIVE_IND: /* ncci */
1182 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1185 capi_cmsg_answer(cmsg);
1186 send_message(card, cmsg);
1187 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND);
1189 cmd.command = ISDN_STAT_BCONN;
1190 cmd.driver = card->myid;
1191 cmd.arg = nccip->chan;
1192 card->interface.statcallb(&cmd);
1194 printk(KERN_INFO "capidrv-%d: chan %d up with ncci 0x%x\n",
1195 card->contrnr, nccip->chan, nccip->ncci);
1198 case CAPI_CONNECT_B3_ACTIVE_CONF: /* ncci */
1201 case CAPI_CONNECT_B3_IND: /* ncci */
1203 plcip = find_plci_by_ncci(card, cmsg->adr.adrNCCI);
1205 nccip = new_ncci(card, plcip, cmsg->adr.adrNCCI);
1207 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_IND);
1208 capi_fill_CONNECT_B3_RESP(cmsg,
1211 nccip->ncci, /* adr */
1215 send_message(card, cmsg);
1216 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP);
1219 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
1221 printk(KERN_ERR "capidrv-%d: %s: plci for ncci 0x%x not found\n",
1223 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1226 capi_fill_CONNECT_B3_RESP(cmsg,
1233 send_message(card, cmsg);
1236 case CAPI_CONNECT_B3_CONF: /* ncci */
1238 if (!(nccip = find_ncci_by_msgid(card,
1240 cmsg->Messagenumber)))
1243 nccip->ncci = cmsg->adr.adrNCCI;
1245 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1247 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1248 cmsg->Info, capi_info2str(cmsg->Info),
1253 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_ERROR);
1255 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_OK);
1258 case CAPI_CONNECT_B3_T90_ACTIVE_IND: /* ncci */
1259 capi_cmsg_answer(cmsg);
1260 send_message(card, cmsg);
1263 case CAPI_DATA_B3_IND: /* ncci */
1264 /* handled in handle_data() */
1267 case CAPI_DATA_B3_CONF: /* ncci */
1269 printk(KERN_WARNING "CAPI_DATA_B3_CONF: Info %x - %s\n",
1270 cmsg->Info, capi_info2str(cmsg->Info));
1272 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1275 len = capidrv_del_ack(nccip, cmsg->DataHandle);
1278 cmd.command = ISDN_STAT_BSENT;
1279 cmd.driver = card->myid;
1280 cmd.arg = nccip->chan;
1281 cmd.parm.length = len;
1282 card->interface.statcallb(&cmd);
1285 case CAPI_DISCONNECT_B3_IND: /* ncci */
1286 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1289 card->bchans[nccip->chan].disconnecting = 1;
1290 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND);
1291 capi_cmsg_answer(cmsg);
1292 send_message(card, cmsg);
1293 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP);
1296 case CAPI_DISCONNECT_B3_CONF: /* ncci */
1297 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1300 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1302 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1303 cmsg->Info, capi_info2str(cmsg->Info),
1305 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_CONF_ERROR);
1309 case CAPI_RESET_B3_IND: /* ncci */
1310 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1312 ncci_change_state(card, nccip, EV_NCCI_RESET_B3_IND);
1313 capi_cmsg_answer(cmsg);
1314 send_message(card, cmsg);
1317 case CAPI_RESET_B3_CONF: /* ncci */
1318 goto ignored; /* $$$$ */
1320 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1322 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1326 printk(KERN_ERR "capidrv-%d: got %s for ncci 0x%x ???",
1328 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1333 printk(KERN_INFO "capidrv-%d: %s for ncci 0x%x ignored\n",
1335 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1339 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1341 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1346 static void handle_data(_cmsg * cmsg, struct sk_buff *skb)
1348 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1349 capidrv_ncci *nccip;
1352 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1353 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1354 cmsg->adr.adrController & 0x7f);
1358 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) {
1359 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1361 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1366 (void) skb_pull(skb, CAPIMSG_LEN(skb->data));
1367 card->interface.rcvcallb_skb(card->myid, nccip->chan, skb);
1368 capi_cmsg_answer(cmsg);
1369 send_message(card, cmsg);
1372 static _cmsg s_cmsg;
1374 static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
1376 capi_message2cmsg(&s_cmsg, skb->data);
1378 printk(KERN_DEBUG "capidrv_signal: applid=%d %s\n",
1379 ap->applid, capi_cmsg2str(&s_cmsg));
1381 if (s_cmsg.Command == CAPI_DATA_B3
1382 && s_cmsg.Subcommand == CAPI_IND) {
1383 handle_data(&s_cmsg, skb);
1386 if ((s_cmsg.adr.adrController & 0xffffff00) == 0)
1387 handle_controller(&s_cmsg);
1388 else if ((s_cmsg.adr.adrPLCI & 0xffff0000) == 0)
1389 handle_plci(&s_cmsg);
1391 handle_ncci(&s_cmsg);
1393 * data of skb used in s_cmsg,
1394 * free data when s_cmsg is not used again
1395 * thanks to Lars Heete <hel@admin.de>
1400 /* ------------------------------------------------------------------- */
1402 #define PUTBYTE_TO_STATUS(card, byte) \
1404 *(card)->q931_write++ = (byte); \
1405 if ((card)->q931_write > (card)->q931_end) \
1406 (card)->q931_write = (card)->q931_buf; \
1409 static void handle_dtrace_data(capidrv_contr *card,
1410 int send, int level2, u8 *data, u16 len)
1416 printk(KERN_DEBUG "capidrv-%d: avmb1_q931_data: len == %d\n",
1417 card->contrnr, len);
1422 PUTBYTE_TO_STATUS(card, 'D');
1423 PUTBYTE_TO_STATUS(card, '2');
1424 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1425 PUTBYTE_TO_STATUS(card, ':');
1427 PUTBYTE_TO_STATUS(card, 'D');
1428 PUTBYTE_TO_STATUS(card, '3');
1429 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1430 PUTBYTE_TO_STATUS(card, ':');
1433 for (p = data, end = data+len; p < end; p++) {
1435 PUTBYTE_TO_STATUS(card, ' ');
1436 w = (*p >> 4) & 0xf;
1437 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1439 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1441 PUTBYTE_TO_STATUS(card, '\n');
1443 cmd.command = ISDN_STAT_STAVAIL;
1444 cmd.driver = card->myid;
1446 card->interface.statcallb(&cmd);
1449 /* ------------------------------------------------------------------- */
1451 static _cmsg cmdcmsg;
1453 static int capidrv_ioctl(isdn_ctrl * c, capidrv_contr * card)
1457 debugmode = (int)(*((unsigned int *)c->parm.num));
1458 printk(KERN_DEBUG "capidrv-%d: debugmode=%d\n",
1459 card->contrnr, debugmode);
1462 printk(KERN_DEBUG "capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1463 card->contrnr, c->arg);
1470 * Handle leased lines (CAPI-Bundling)
1473 struct internal_bchannelinfo {
1474 unsigned short channelalloc;
1475 unsigned short operation;
1476 unsigned char cmask[31];
1479 static int decodeFVteln(char *teln, unsigned long *bmaskp, int *activep)
1481 unsigned long bmask = 0;
1486 if (strncmp(teln, "FV:", 3) != 0)
1489 while (*s && *s == ' ') s++;
1491 if (*s == 'p' || *s == 'P') {
1495 if (*s == 'a' || *s == 'A') {
1502 if (!isdigit(*s)) return -3;
1503 while (isdigit(*s)) { digit1 = digit1*10 + (*s - '0'); s++; }
1504 if (digit1 <= 0 && digit1 > 30) return -4;
1505 if (*s == 0 || *s == ',' || *s == ' ') {
1506 bmask |= (1 << digit1);
1511 if (*s != '-') return -5;
1513 if (!isdigit(*s)) return -3;
1514 while (isdigit(*s)) { digit2 = digit2*10 + (*s - '0'); s++; }
1515 if (digit2 <= 0 && digit2 > 30) return -4;
1516 if (*s == 0 || *s == ',' || *s == ' ') {
1517 if (digit1 > digit2)
1518 for (i = digit2; i <= digit1 ; i++)
1521 for (i = digit1; i <= digit2 ; i++)
1523 digit1 = digit2 = 0;
1529 if (activep) *activep = active;
1530 if (bmaskp) *bmaskp = bmask;
1534 static int FVteln2capi20(char *teln, u8 AdditionalInfo[1+2+2+31])
1536 unsigned long bmask;
1540 rc = decodeFVteln(teln, &bmask, &active);
1543 AdditionalInfo[0] = 2+2+31;
1544 /* Channel: 3 => use channel allocation */
1545 AdditionalInfo[1] = 3; AdditionalInfo[2] = 0;
1546 /* Operation: 0 => DTE mode, 1 => DCE mode */
1548 AdditionalInfo[3] = 0; AdditionalInfo[4] = 0;
1550 AdditionalInfo[3] = 1; AdditionalInfo[4] = 0;
1552 /* Channel mask array */
1553 AdditionalInfo[5] = 0; /* no D-Channel */
1554 for (i=1; i <= 30; i++)
1555 AdditionalInfo[5+i] = (bmask & (1 << i)) ? 0xff : 0;
1559 static int capidrv_command(isdn_ctrl * c, capidrv_contr * card)
1562 struct capidrv_bchan *bchan;
1563 struct capidrv_plci *plcip;
1564 u8 AdditionalInfo[1+2+2+31];
1565 int rc, isleasedline = 0;
1567 if (c->command == ISDN_CMD_IOCTL)
1568 return capidrv_ioctl(c, card);
1570 switch (c->command) {
1571 case ISDN_CMD_DIAL:{
1572 u8 calling[ISDN_MSNLEN + 3];
1573 u8 called[ISDN_MSNLEN + 2];
1576 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1579 c->parm.setup.phone,
1582 c->parm.setup.eazmsn);
1584 bchan = &card->bchans[c->arg % card->nbchan];
1587 printk(KERN_ERR "capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1590 c->parm.setup.phone,
1593 c->parm.setup.eazmsn,
1594 bchan->plcip->plci);
1597 bchan->si1 = c->parm.setup.si1;
1598 bchan->si2 = c->parm.setup.si2;
1600 strncpy(bchan->num, c->parm.setup.phone, sizeof(bchan->num));
1601 strncpy(bchan->mynum, c->parm.setup.eazmsn, sizeof(bchan->mynum));
1602 rc = FVteln2capi20(bchan->num, AdditionalInfo);
1603 isleasedline = (rc == 0);
1605 printk(KERN_ERR "capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card->contrnr, bchan->num);
1611 printk(KERN_DEBUG "capidrv-%d: connecting leased line\n", card->contrnr);
1613 calling[0] = strlen(bchan->mynum) + 2;
1616 strncpy(calling + 3, bchan->mynum, ISDN_MSNLEN);
1617 called[0] = strlen(bchan->num) + 1;
1619 strncpy(called + 2, bchan->num, ISDN_MSNLEN);
1622 capi_fill_CONNECT_REQ(&cmdcmsg,
1625 card->contrnr, /* adr */
1626 si2cip(bchan->si1, bchan->si2), /* cipvalue */
1627 called, /* CalledPartyNumber */
1628 calling, /* CallingPartyNumber */
1629 NULL, /* CalledPartySubaddress */
1630 NULL, /* CallingPartySubaddress */
1631 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1632 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1633 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1634 b1config(bchan->l2, bchan->l3), /* B1configuration */
1635 NULL, /* B2configuration */
1636 NULL, /* B3configuration */
1640 /* BChannelinformation */
1641 isleasedline ? AdditionalInfo : NULL,
1642 NULL, /* Keypadfacility */
1643 NULL, /* Useruserdata */
1644 NULL /* Facilitydataarray */
1646 if ((plcip = new_plci(card, (c->arg % card->nbchan))) == 0) {
1647 cmd.command = ISDN_STAT_DHUP;
1648 cmd.driver = card->myid;
1649 cmd.arg = (c->arg % card->nbchan);
1650 card->interface.statcallb(&cmd);
1653 plcip->msgid = cmdcmsg.Messagenumber;
1654 plcip->leasedline = isleasedline;
1655 plci_change_state(card, plcip, EV_PLCI_CONNECT_REQ);
1656 send_message(card, &cmdcmsg);
1660 case ISDN_CMD_ACCEPTD:
1662 bchan = &card->bchans[c->arg % card->nbchan];
1664 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1666 c->arg, bchan->l2, bchan->l3);
1668 capi_fill_CONNECT_RESP(&cmdcmsg,
1671 bchan->plcip->plci, /* adr */
1673 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1674 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1675 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1676 b1config(bchan->l2, bchan->l3), /* B1configuration */
1677 NULL, /* B2configuration */
1678 NULL, /* B3configuration */
1679 NULL, /* ConnectedNumber */
1680 NULL, /* ConnectedSubaddress */
1682 NULL, /* BChannelinformation */
1683 NULL, /* Keypadfacility */
1684 NULL, /* Useruserdata */
1685 NULL /* Facilitydataarray */
1687 capi_cmsg2message(&cmdcmsg, cmdcmsg.buf);
1688 plci_change_state(card, bchan->plcip, EV_PLCI_CONNECT_RESP);
1689 send_message(card, &cmdcmsg);
1692 case ISDN_CMD_ACCEPTB:
1694 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1699 case ISDN_CMD_HANGUP:
1701 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1704 bchan = &card->bchans[c->arg % card->nbchan];
1706 if (bchan->disconnecting) {
1708 printk(KERN_DEBUG "capidrv-%d: chan %ld already disconnecting ...\n",
1714 bchan->disconnecting = 1;
1715 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg,
1721 ncci_change_state(card, bchan->nccip, EV_NCCI_DISCONNECT_B3_REQ);
1722 send_message(card, &cmdcmsg);
1724 } else if (bchan->plcip) {
1725 if (bchan->plcip->state == ST_PLCI_INCOMING) {
1727 * just ignore, we a called from
1728 * isdn_status_callback(),
1729 * which will return 0 or 2, this is handled
1730 * by the CONNECT_IND handler
1732 bchan->disconnecting = 1;
1734 } else if (bchan->plcip->plci) {
1735 bchan->disconnecting = 1;
1736 capi_fill_DISCONNECT_REQ(&cmdcmsg,
1740 NULL, /* BChannelinformation */
1741 NULL, /* Keypadfacility */
1742 NULL, /* Useruserdata */
1743 NULL /* Facilitydataarray */
1745 plci_change_state(card, bchan->plcip, EV_PLCI_DISCONNECT_REQ);
1746 send_message(card, &cmdcmsg);
1749 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1755 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request on free channel\n",
1761 case ISDN_CMD_SETL2:
1763 printk(KERN_DEBUG "capidrv-%d: set L2 on chan %ld to %ld\n",
1765 (c->arg & 0xff), (c->arg >> 8));
1766 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1767 bchan->l2 = (c->arg >> 8);
1770 case ISDN_CMD_SETL3:
1772 printk(KERN_DEBUG "capidrv-%d: set L3 on chan %ld to %ld\n",
1774 (c->arg & 0xff), (c->arg >> 8));
1775 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1776 bchan->l3 = (c->arg >> 8);
1779 case ISDN_CMD_SETEAZ:
1781 printk(KERN_DEBUG "capidrv-%d: set EAZ \"%s\" on chan %ld\n",
1783 c->parm.num, c->arg);
1784 bchan = &card->bchans[c->arg % card->nbchan];
1785 strncpy(bchan->msn, c->parm.num, ISDN_MSNLEN);
1788 case ISDN_CMD_CLREAZ:
1790 printk(KERN_DEBUG "capidrv-%d: clearing EAZ on chan %ld\n",
1791 card->contrnr, c->arg);
1792 bchan = &card->bchans[c->arg % card->nbchan];
1797 printk(KERN_ERR "capidrv-%d: ISDN_CMD_%d, Huh?\n",
1798 card->contrnr, c->command);
1804 static int if_command(isdn_ctrl * c)
1806 capidrv_contr *card = findcontrbydriverid(c->driver);
1809 return capidrv_command(c, card);
1812 "capidrv: if_command %d called with invalid driverId %d!\n",
1813 c->command, c->driver);
1817 static _cmsg sendcmsg;
1819 static int if_sendbuf(int id, int channel, int doack, struct sk_buff *skb)
1821 capidrv_contr *card = findcontrbydriverid(id);
1822 capidrv_bchan *bchan;
1823 capidrv_ncci *nccip;
1830 printk(KERN_ERR "capidrv: if_sendbuf called with invalid driverId %d!\n",
1835 printk(KERN_DEBUG "capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
1836 card->contrnr, len, skb, doack);
1837 bchan = &card->bchans[channel % card->nbchan];
1838 nccip = bchan->nccip;
1839 if (!nccip || nccip->state != ST_NCCI_ACTIVE) {
1840 printk(KERN_ERR "capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
1841 card->contrnr, card->name, channel);
1844 datahandle = nccip->datahandle;
1845 capi_fill_DATA_B3_REQ(&sendcmsg, global.ap.applid, card->msgid++,
1846 nccip->ncci, /* adr */
1847 (u32) skb->data, /* Data */
1848 skb->len, /* DataLength */
1849 datahandle, /* DataHandle */
1853 if (capidrv_add_ack(nccip, datahandle, doack ? (int)skb->len : -1) < 0)
1856 capi_cmsg2message(&sendcmsg, sendcmsg.buf);
1857 msglen = CAPIMSG_LEN(sendcmsg.buf);
1858 if (skb_headroom(skb) < msglen) {
1859 struct sk_buff *nskb = skb_realloc_headroom(skb, msglen);
1861 printk(KERN_ERR "capidrv-%d: if_sendbuf: no memory\n",
1863 (void)capidrv_del_ack(nccip, datahandle);
1866 printk(KERN_DEBUG "capidrv-%d: only %d bytes headroom, need %d\n",
1867 card->contrnr, skb_headroom(skb), msglen);
1868 memcpy(skb_push(nskb, msglen), sendcmsg.buf, msglen);
1869 errcode = capi20_put_message(&global.ap, nskb);
1870 if (errcode == CAPI_NOERROR) {
1872 nccip->datahandle++;
1876 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1877 card->contrnr, errcode, capi_info2str(errcode));
1878 (void)capidrv_del_ack(nccip, datahandle);
1879 dev_kfree_skb(nskb);
1880 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1882 memcpy(skb_push(skb, msglen), sendcmsg.buf, msglen);
1883 errcode = capi20_put_message(&global.ap, skb);
1884 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 skb_pull(skb, msglen);
1892 (void)capidrv_del_ack(nccip, datahandle);
1893 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1897 static int if_readstat(u8 __user *buf, int len, int id, int channel)
1899 capidrv_contr *card = findcontrbydriverid(id);
1904 printk(KERN_ERR "capidrv: if_readstat called with invalid driverId %d!\n",
1909 for (p=buf, count=0; count < len; p++, count++) {
1910 put_user(*card->q931_read++, p);
1911 if (card->q931_read > card->q931_end)
1912 card->q931_read = card->q931_buf;
1918 static void enable_dchannel_trace(capidrv_contr *card)
1920 u8 manufacturer[CAPI_MANUFACTURER_LEN];
1921 capi_version version;
1922 u16 contr = card->contrnr;
1926 errcode = capi20_get_manufacturer(contr, manufacturer);
1927 if (errcode != CAPI_NOERROR) {
1928 printk(KERN_ERR "%s: can't get manufacturer (0x%x)\n",
1929 card->name, errcode);
1932 if (strstr(manufacturer, "AVM") == 0) {
1933 printk(KERN_ERR "%s: not from AVM, no d-channel trace possible (%s)\n",
1934 card->name, manufacturer);
1937 errcode = capi20_get_version(contr, &version);
1938 if (errcode != CAPI_NOERROR) {
1939 printk(KERN_ERR "%s: can't get version (0x%x)\n",
1940 card->name, errcode);
1943 avmversion[0] = (version.majormanuversion >> 4) & 0x0f;
1944 avmversion[1] = (version.majormanuversion << 4) & 0xf0;
1945 avmversion[1] |= (version.minormanuversion >> 4) & 0x0f;
1946 avmversion[2] |= version.minormanuversion & 0x0f;
1948 if (avmversion[0] > 3 || (avmversion[0] == 3 && avmversion[1] > 5)) {
1949 printk(KERN_INFO "%s: D2 trace enabled\n", card->name);
1950 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid,
1953 0x214D5641, /* ManuID */
1956 (_cstruct)"\004\200\014\000\000");
1958 printk(KERN_INFO "%s: D3 trace enabled\n", card->name);
1959 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid,
1962 0x214D5641, /* ManuID */
1965 (_cstruct)"\004\002\003\000\000");
1967 send_message(card, &cmdcmsg);
1971 static void send_listen(capidrv_contr *card)
1973 capi_fill_LISTEN_REQ(&cmdcmsg, global.ap.applid,
1975 card->contrnr, /* controller */
1976 1 << 6, /* Infomask */
1980 send_message(card, &cmdcmsg);
1981 listen_change_state(card, EV_LISTEN_REQ);
1984 static void listentimerfunc(unsigned long x)
1986 capidrv_contr *card = (capidrv_contr *)x;
1987 if (card->state != ST_LISTEN_NONE && card->state != ST_LISTEN_ACTIVE)
1988 printk(KERN_ERR "%s: controller dead ??\n", card->name);
1990 mod_timer(&card->listentimer, jiffies + 60*HZ);
1994 static int capidrv_addcontr(u16 contr, struct capi_profile *profp)
1996 capidrv_contr *card;
1997 unsigned long flags;
2002 sprintf(id, "capidrv-%d", contr);
2003 if (!try_module_get(THIS_MODULE)) {
2004 printk(KERN_WARNING "capidrv: (%s) Could not reserve module\n", id);
2007 if (!(card = (capidrv_contr *) kmalloc(sizeof(capidrv_contr), GFP_ATOMIC))) {
2009 "capidrv: (%s) Could not allocate contr-struct.\n", id);
2012 memset(card, 0, sizeof(capidrv_contr));
2013 card->owner = THIS_MODULE;
2014 init_timer(&card->listentimer);
2015 strcpy(card->name, id);
2016 card->contrnr = contr;
2017 card->nbchan = profp->nbchannel;
2018 card->bchans = (capidrv_bchan *) kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC);
2019 if (!card->bchans) {
2021 "capidrv: (%s) Could not allocate bchan-structs.\n", id);
2022 module_put(card->owner);
2026 card->interface.channels = profp->nbchannel;
2027 card->interface.maxbufsize = 2048;
2028 card->interface.command = if_command;
2029 card->interface.writebuf_skb = if_sendbuf;
2030 card->interface.writecmd = NULL;
2031 card->interface.readstat = if_readstat;
2032 card->interface.features = ISDN_FEATURE_L2_HDLC |
2033 ISDN_FEATURE_L2_TRANS |
2034 ISDN_FEATURE_L3_TRANS |
2035 ISDN_FEATURE_P_UNKNOWN |
2036 ISDN_FEATURE_L2_X75I |
2037 ISDN_FEATURE_L2_X75UI |
2038 ISDN_FEATURE_L2_X75BUI;
2039 if (profp->support1 & (1<<2))
2040 card->interface.features |= ISDN_FEATURE_L2_V11096 |
2041 ISDN_FEATURE_L2_V11019 |
2042 ISDN_FEATURE_L2_V11038;
2043 if (profp->support1 & (1<<8))
2044 card->interface.features |= ISDN_FEATURE_L2_MODEM;
2045 card->interface.hl_hdrlen = 22; /* len of DATA_B3_REQ */
2046 strncpy(card->interface.id, id, sizeof(card->interface.id) - 1);
2049 card->q931_read = card->q931_buf;
2050 card->q931_write = card->q931_buf;
2051 card->q931_end = card->q931_buf + sizeof(card->q931_buf) - 1;
2053 if (!register_isdn(&card->interface)) {
2054 printk(KERN_ERR "capidrv: Unable to register contr %s\n", id);
2055 kfree(card->bchans);
2056 module_put(card->owner);
2060 card->myid = card->interface.channels;
2061 memset(card->bchans, 0, sizeof(capidrv_bchan) * card->nbchan);
2062 for (i = 0; i < card->nbchan; i++) {
2063 card->bchans[i].contr = card;
2066 spin_lock_irqsave(&global_lock, flags);
2067 card->next = global.contr_list;
2068 global.contr_list = card;
2070 spin_unlock_irqrestore(&global_lock, flags);
2072 cmd.command = ISDN_STAT_RUN;
2073 cmd.driver = card->myid;
2074 card->interface.statcallb(&cmd);
2076 card->cipmask = 0x1FFF03FF; /* any */
2079 card->listentimer.data = (unsigned long)card;
2080 card->listentimer.function = listentimerfunc;
2082 mod_timer(&card->listentimer, jiffies + 60*HZ);
2084 printk(KERN_INFO "%s: now up (%d B channels)\n",
2085 card->name, card->nbchan);
2087 enable_dchannel_trace(card);
2092 static int capidrv_delcontr(u16 contr)
2094 capidrv_contr **pp, *card;
2095 unsigned long flags;
2098 spin_lock_irqsave(&global_lock, flags);
2099 for (card = global.contr_list; card; card = card->next) {
2100 if (card->contrnr == contr)
2104 spin_unlock_irqrestore(&global_lock, flags);
2105 printk(KERN_ERR "capidrv: delcontr: no contr %u\n", contr);
2108 #warning FIXME: maybe a race condition the card should be removed here from global list /kkeil
2109 spin_unlock_irqrestore(&global_lock, flags);
2111 del_timer(&card->listentimer);
2114 printk(KERN_DEBUG "capidrv-%d: id=%d unloading\n",
2115 card->contrnr, card->myid);
2117 cmd.command = ISDN_STAT_STOP;
2118 cmd.driver = card->myid;
2119 card->interface.statcallb(&cmd);
2121 while (card->nbchan) {
2123 cmd.command = ISDN_STAT_DISCH;
2124 cmd.driver = card->myid;
2125 cmd.arg = card->nbchan-1;
2126 cmd.parm.num[0] = 0;
2128 printk(KERN_DEBUG "capidrv-%d: id=%d disable chan=%ld\n",
2129 card->contrnr, card->myid, cmd.arg);
2130 card->interface.statcallb(&cmd);
2132 if (card->bchans[card->nbchan-1].nccip)
2133 free_ncci(card, card->bchans[card->nbchan-1].nccip);
2134 if (card->bchans[card->nbchan-1].plcip)
2135 free_plci(card, card->bchans[card->nbchan-1].plcip);
2136 if (card->plci_list)
2137 printk(KERN_ERR "capidrv: bug in free_plci()\n");
2140 kfree(card->bchans);
2141 card->bchans = NULL;
2144 printk(KERN_DEBUG "capidrv-%d: id=%d isdn unload\n",
2145 card->contrnr, card->myid);
2147 cmd.command = ISDN_STAT_UNLOAD;
2148 cmd.driver = card->myid;
2149 card->interface.statcallb(&cmd);
2152 printk(KERN_DEBUG "capidrv-%d: id=%d remove contr from list\n",
2153 card->contrnr, card->myid);
2155 spin_lock_irqsave(&global_lock, flags);
2156 for (pp = &global.contr_list; *pp; pp = &(*pp)->next) {
2164 spin_unlock_irqrestore(&global_lock, flags);
2166 module_put(card->owner);
2167 printk(KERN_INFO "%s: now down.\n", card->name);
2173 static void lower_callback(unsigned int cmd, u32 contr, void *data)
2178 printk(KERN_INFO "capidrv: controller %hu up\n", contr);
2179 (void) capidrv_addcontr(contr, (capi_profile *) data);
2182 printk(KERN_INFO "capidrv: controller %hu down\n", contr);
2183 (void) capidrv_delcontr(contr);
2189 * /proc/capi/capidrv:
2190 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2192 static int proc_capidrv_read_proc(char *page, char **start, off_t off,
2193 int count, int *eof, void *data)
2197 len += sprintf(page+len, "%lu %lu %lu %lu\n",
2198 global.ap.nrecvctlpkt,
2199 global.ap.nrecvdatapkt,
2200 global.ap.nsentctlpkt,
2201 global.ap.nsentdatapkt);
2202 if (off+count >= len)
2206 *start = page + off;
2207 return ((count < len-off) ? count : len-off);
2210 static struct procfsentries {
2213 int (*read_proc)(char *page, char **start, off_t off,
2214 int count, int *eof, void *data);
2215 struct proc_dir_entry *procent;
2216 } procfsentries[] = {
2217 /* { "capi", S_IFDIR, 0 }, */
2218 { "capi/capidrv", 0 , proc_capidrv_read_proc },
2221 static void __init proc_init(void)
2223 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2226 for (i=0; i < nelem; i++) {
2227 struct procfsentries *p = procfsentries + i;
2228 p->procent = create_proc_entry(p->name, p->mode, NULL);
2229 if (p->procent) p->procent->read_proc = p->read_proc;
2233 static void __exit proc_exit(void)
2235 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2238 for (i=nelem-1; i >= 0; i--) {
2239 struct procfsentries *p = procfsentries + i;
2241 remove_proc_entry(p->name, NULL);
2247 static int __init capidrv_init(void)
2249 capi_profile profile;
2255 if ((p = strchr(revision, ':')) != 0 && p[1]) {
2256 strncpy(rev, p + 2, sizeof(rev));
2257 rev[sizeof(rev)-1] = 0;
2258 if ((p = strchr(rev, '$')) != 0 && p > rev)
2263 global.ap.rparam.level3cnt = -2; /* number of bchannels twice */
2264 global.ap.rparam.datablkcnt = 16;
2265 global.ap.rparam.datablklen = 2048;
2267 global.ap.recv_message = capidrv_recv_message;
2268 errcode = capi20_register(&global.ap);
2273 capi20_set_callback(&global.ap, lower_callback);
2275 errcode = capi20_get_profile(0, &profile);
2276 if (errcode != CAPI_NOERROR) {
2277 capi20_release(&global.ap);
2281 ncontr = profile.ncontroller;
2282 for (contr = 1; contr <= ncontr; contr++) {
2283 errcode = capi20_get_profile(contr, &profile);
2284 if (errcode != CAPI_NOERROR)
2286 (void) capidrv_addcontr(contr, &profile);
2290 printk(KERN_NOTICE "capidrv: Rev %s: loaded\n", rev);
2294 static void __exit capidrv_exit(void)
2299 if ((p = strchr(revision, ':')) != 0) {
2301 p = strchr(rev, '$');
2304 strcpy(rev, " ??? ");
2307 capi20_release(&global.ap);
2311 printk(KERN_NOTICE "capidrv: Rev%s: unloaded\n", rev);
2314 module_init(capidrv_init);
2315 module_exit(capidrv_exit);