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 = kzalloc(sizeof(capidrv_plci), GFP_ATOMIC);
342 plcip->state = ST_PLCI_NONE;
346 plcip->next = card->plci_list;
347 card->plci_list = plcip;
348 card->bchans[chan].plcip = plcip;
353 static capidrv_plci *find_plci_by_plci(capidrv_contr * card, u32 plci)
356 for (p = card->plci_list; p; p = p->next)
362 static capidrv_plci *find_plci_by_msgid(capidrv_contr * card, u16 msgid)
365 for (p = card->plci_list; p; p = p->next)
366 if (p->msgid == msgid)
371 static capidrv_plci *find_plci_by_ncci(capidrv_contr * card, u32 ncci)
374 for (p = card->plci_list; p; p = p->next)
375 if (p->plci == (ncci & 0xffff))
380 static void free_plci(capidrv_contr * card, capidrv_plci * plcip)
384 for (pp = &card->plci_list; *pp; pp = &(*pp)->next) {
387 card->bchans[plcip->chan].plcip = NULL;
388 card->bchans[plcip->chan].disconnecting = 0;
389 card->bchans[plcip->chan].incoming = 0;
394 printk(KERN_ERR "capidrv-%d: free_plci %p (0x%x) not found, Huh?\n",
395 card->contrnr, plcip, plcip->plci);
398 /* -------- ncci management ------------------------------------------ */
400 static inline capidrv_ncci *new_ncci(capidrv_contr * card,
401 capidrv_plci * plcip,
406 nccip = kzalloc(sizeof(capidrv_ncci), GFP_ATOMIC);
412 nccip->state = ST_NCCI_NONE;
413 nccip->plcip = plcip;
414 nccip->chan = plcip->chan;
415 nccip->datahandle = 0;
417 nccip->next = plcip->ncci_list;
418 plcip->ncci_list = nccip;
420 card->bchans[plcip->chan].nccip = nccip;
425 static inline capidrv_ncci *find_ncci(capidrv_contr * card, u32 ncci)
430 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
433 for (p = plcip->ncci_list; p; p = p->next)
439 static inline capidrv_ncci *find_ncci_by_msgid(capidrv_contr * card,
445 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
448 for (p = plcip->ncci_list; p; p = p->next)
449 if (p->msgid == msgid)
454 static void free_ncci(capidrv_contr * card, struct capidrv_ncci *nccip)
456 struct capidrv_ncci **pp;
458 for (pp = &(nccip->plcip->ncci_list); *pp; pp = &(*pp)->next) {
464 card->bchans[nccip->chan].nccip = NULL;
468 static int capidrv_add_ack(struct capidrv_ncci *nccip,
469 u16 datahandle, int len)
471 struct ncci_datahandle_queue *n, **pp;
473 n = (struct ncci_datahandle_queue *)
474 kmalloc(sizeof(struct ncci_datahandle_queue), GFP_ATOMIC);
476 printk(KERN_ERR "capidrv: kmalloc ncci_datahandle failed\n");
480 n->datahandle = datahandle;
482 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) ;
487 static int capidrv_del_ack(struct capidrv_ncci *nccip, u16 datahandle)
489 struct ncci_datahandle_queue **pp, *p;
492 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) {
493 if ((*pp)->datahandle == datahandle) {
504 /* -------- convert and send capi message ---------------------------- */
506 static void send_message(capidrv_contr * card, _cmsg * cmsg)
510 capi_cmsg2message(cmsg, cmsg->buf);
511 len = CAPIMSG_LEN(cmsg->buf);
512 skb = alloc_skb(len, GFP_ATOMIC);
513 memcpy(skb_put(skb, len), cmsg->buf, len);
514 if (capi20_put_message(&global.ap, skb) != CAPI_NOERROR)
518 /* -------- state machine -------------------------------------------- */
520 struct listenstatechange {
526 static struct listenstatechange listentable[] =
528 {ST_LISTEN_NONE, ST_LISTEN_WAIT_CONF, EV_LISTEN_REQ},
529 {ST_LISTEN_ACTIVE, ST_LISTEN_ACTIVE_WAIT_CONF, EV_LISTEN_REQ},
530 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_ERROR},
531 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_ERROR},
532 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
533 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
534 {ST_LISTEN_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
535 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
539 static void listen_change_state(capidrv_contr * card, int event)
541 struct listenstatechange *p = listentable;
543 if (card->state == p->actstate && p->event == event) {
545 printk(KERN_DEBUG "capidrv-%d: listen_change_state %d -> %d\n",
546 card->contrnr, card->state, p->nextstate);
547 card->state = p->nextstate;
552 printk(KERN_ERR "capidrv-%d: listen_change_state state=%d event=%d ????\n",
553 card->contrnr, card->state, event);
557 /* ------------------------------------------------------------------ */
559 static void p0(capidrv_contr * card, capidrv_plci * plci)
563 card->bchans[plci->chan].contr = NULL;
564 cmd.command = ISDN_STAT_DHUP;
565 cmd.driver = card->myid;
566 cmd.arg = plci->chan;
567 card->interface.statcallb(&cmd);
568 free_plci(card, plci);
571 /* ------------------------------------------------------------------ */
573 struct plcistatechange {
577 void (*changefunc) (capidrv_contr * card, capidrv_plci * plci);
580 static struct plcistatechange plcitable[] =
583 {ST_PLCI_NONE, ST_PLCI_OUTGOING, EV_PLCI_CONNECT_REQ, NULL},
584 {ST_PLCI_NONE, ST_PLCI_ALLOCATED, EV_PLCI_FACILITY_IND_UP, NULL},
585 {ST_PLCI_NONE, ST_PLCI_INCOMING, EV_PLCI_CONNECT_IND, NULL},
586 {ST_PLCI_NONE, ST_PLCI_RESUMEING, EV_PLCI_RESUME_REQ, NULL},
588 {ST_PLCI_OUTGOING, ST_PLCI_NONE, EV_PLCI_CONNECT_CONF_ERROR, p0},
589 {ST_PLCI_OUTGOING, ST_PLCI_ALLOCATED, EV_PLCI_CONNECT_CONF_OK, NULL},
591 {ST_PLCI_ALLOCATED, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
592 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
593 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
594 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
596 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
597 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
598 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
599 {ST_PLCI_ACTIVE, ST_PLCI_HELD, EV_PLCI_HOLD_IND, NULL},
600 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_SUSPEND_IND, NULL},
602 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
603 {ST_PLCI_INCOMING, ST_PLCI_FACILITY_IND, EV_PLCI_FACILITY_IND_UP, NULL},
604 {ST_PLCI_INCOMING, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_RESP, NULL},
605 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
606 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
607 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
608 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CD_IND, NULL},
610 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
611 {ST_PLCI_FACILITY_IND, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
612 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
613 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
614 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
616 {ST_PLCI_ACCEPTING, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
617 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
618 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
619 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
621 {ST_PLCI_DISCONNECTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
623 {ST_PLCI_DISCONNECTED, ST_PLCI_NONE, EV_PLCI_DISCONNECT_RESP, p0},
625 {ST_PLCI_RESUMEING, ST_PLCI_NONE, EV_PLCI_RESUME_CONF_ERROR, p0},
626 {ST_PLCI_RESUMEING, ST_PLCI_RESUME, EV_PLCI_RESUME_CONF_OK, NULL},
628 {ST_PLCI_RESUME, ST_PLCI_ACTIVE, EV_PLCI_RESUME_IND, NULL},
630 {ST_PLCI_HELD, ST_PLCI_ACTIVE, EV_PLCI_RETRIEVE_IND, NULL},
634 static void plci_change_state(capidrv_contr * card, capidrv_plci * plci, int event)
636 struct plcistatechange *p = plcitable;
638 if (plci->state == p->actstate && p->event == event) {
640 printk(KERN_DEBUG "capidrv-%d: plci_change_state:0x%x %d -> %d\n",
641 card->contrnr, plci->plci, plci->state, p->nextstate);
642 plci->state = p->nextstate;
644 p->changefunc(card, plci);
649 printk(KERN_ERR "capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
650 card->contrnr, plci->plci, plci->state, event);
653 /* ------------------------------------------------------------------ */
657 static void n0(capidrv_contr * card, capidrv_ncci * ncci)
661 capi_fill_DISCONNECT_REQ(&cmsg,
665 NULL, /* BChannelinformation */
666 NULL, /* Keypadfacility */
667 NULL, /* Useruserdata */ /* $$$$ */
668 NULL /* Facilitydataarray */
670 send_message(card, &cmsg);
671 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ);
673 cmd.command = ISDN_STAT_BHUP;
674 cmd.driver = card->myid;
675 cmd.arg = ncci->chan;
676 card->interface.statcallb(&cmd);
677 free_ncci(card, ncci);
680 /* ------------------------------------------------------------------ */
682 struct nccistatechange {
686 void (*changefunc) (capidrv_contr * card, capidrv_ncci * ncci);
689 static struct nccistatechange nccitable[] =
692 {ST_NCCI_NONE, ST_NCCI_OUTGOING, EV_NCCI_CONNECT_B3_REQ, NULL},
693 {ST_NCCI_NONE, ST_NCCI_INCOMING, EV_NCCI_CONNECT_B3_IND, NULL},
695 {ST_NCCI_OUTGOING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_CONF_OK, NULL},
696 {ST_NCCI_OUTGOING, ST_NCCI_NONE, EV_NCCI_CONNECT_B3_CONF_ERROR, n0},
698 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_CONNECT_B3_REJECT, NULL},
699 {ST_NCCI_INCOMING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_RESP, NULL},
700 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
701 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
703 {ST_NCCI_ALLOCATED, ST_NCCI_ACTIVE, EV_NCCI_CONNECT_B3_ACTIVE_IND, NULL},
704 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
705 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
707 {ST_NCCI_ACTIVE, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
708 {ST_NCCI_ACTIVE, ST_NCCI_RESETING, EV_NCCI_RESET_B3_REQ, NULL},
709 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
710 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
712 {ST_NCCI_RESETING, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
713 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
714 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
716 {ST_NCCI_DISCONNECTING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
717 {ST_NCCI_DISCONNECTING, ST_NCCI_PREVIOUS, EV_NCCI_DISCONNECT_B3_CONF_ERROR,NULL},
719 {ST_NCCI_DISCONNECTED, ST_NCCI_NONE, EV_NCCI_DISCONNECT_B3_RESP, n0},
723 static void ncci_change_state(capidrv_contr * card, capidrv_ncci * ncci, int event)
725 struct nccistatechange *p = nccitable;
727 if (ncci->state == p->actstate && p->event == event) {
729 printk(KERN_DEBUG "capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
730 card->contrnr, ncci->ncci, ncci->state, p->nextstate);
731 if (p->nextstate == ST_NCCI_PREVIOUS) {
732 ncci->state = ncci->oldstate;
733 ncci->oldstate = p->actstate;
735 ncci->oldstate = p->actstate;
736 ncci->state = p->nextstate;
739 p->changefunc(card, ncci);
744 printk(KERN_ERR "capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
745 card->contrnr, ncci->ncci, ncci->state, event);
748 /* ------------------------------------------------------------------- */
750 static inline int new_bchan(capidrv_contr * card)
753 for (i = 0; i < card->nbchan; i++) {
754 if (card->bchans[i].plcip == 0) {
755 card->bchans[i].disconnecting = 0;
762 /* ------------------------------------------------------------------- */
764 static void handle_controller(_cmsg * cmsg)
766 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
769 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
770 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
771 cmsg->adr.adrController & 0x7f);
774 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
776 case CAPI_LISTEN_CONF: /* Controller */
778 printk(KERN_DEBUG "capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
779 card->contrnr, cmsg->Info, capi_info2str(cmsg->Info), card->cipmask);
781 listen_change_state(card, EV_LISTEN_CONF_ERROR);
782 } else if (card->cipmask == 0) {
783 listen_change_state(card, EV_LISTEN_CONF_EMPTY);
785 listen_change_state(card, EV_LISTEN_CONF_OK);
789 case CAPI_MANUFACTURER_IND: /* Controller */
790 if ( cmsg->ManuID == 0x214D5641
792 && cmsg->Function == 1) {
793 u8 *data = cmsg->ManuData+3;
794 u16 len = cmsg->ManuData[0];
798 len = (cmsg->ManuData[1] | (cmsg->ManuData[2] << 8));
802 layer = ((*(data-1)) << 8) | *(data-2);
804 direction = (layer & 0x200) ? 0 : 1;
805 else direction = (layer & 0x800) ? 0 : 1;
806 if (layer & 0x0C00) {
807 if ((layer & 0xff) == 0x80) {
808 handle_dtrace_data(card, direction, 1, data, len);
811 } else if ((layer & 0xff) < 0x80) {
812 handle_dtrace_data(card, direction, 0, data, len);
815 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
817 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
818 cmsg->adr.adrController, layer);
822 case CAPI_MANUFACTURER_CONF: /* Controller */
823 if (cmsg->ManuID == 0x214D5641) {
825 switch (cmsg->Class) {
827 case 1: s = "unknown class"; break;
828 case 2: s = "unknown function"; break;
829 default: s = "unkown error"; break;
832 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x function %d: %s\n",
834 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
835 cmsg->adr.adrController,
840 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
842 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
844 case CAPI_INFO_IND: /* Controller/plci */
846 case CAPI_INFO_CONF: /* Controller/plci */
850 printk(KERN_ERR "capidrv-%d: got %s from controller 0x%x ???",
852 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
853 cmsg->adr.adrController);
858 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x ignored\n",
860 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
861 cmsg->adr.adrController);
864 static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
867 capidrv_bchan *bchan;
871 if ((chan = new_bchan(card)) == -1) {
872 printk(KERN_ERR "capidrv-%d: incoming call on not existing bchan ?\n", card->contrnr);
875 bchan = &card->bchans[chan];
876 if ((plcip = new_plci(card, chan)) == 0) {
877 printk(KERN_ERR "capidrv-%d: incoming call: no memory, sorry.\n", card->contrnr);
881 plcip->plci = cmsg->adr.adrPLCI;
882 plci_change_state(card, plcip, EV_PLCI_CONNECT_IND);
884 cmd.command = ISDN_STAT_ICALL;
885 cmd.driver = card->myid;
887 memset(&cmd.parm.setup, 0, sizeof(cmd.parm.setup));
888 strncpy(cmd.parm.setup.phone,
889 cmsg->CallingPartyNumber + 3,
890 cmsg->CallingPartyNumber[0] - 2);
891 strncpy(cmd.parm.setup.eazmsn,
892 cmsg->CalledPartyNumber + 2,
893 cmsg->CalledPartyNumber[0] - 1);
894 cmd.parm.setup.si1 = cip2si1(cmsg->CIPValue);
895 cmd.parm.setup.si2 = cip2si2(cmsg->CIPValue);
896 cmd.parm.setup.plan = cmsg->CallingPartyNumber[1];
897 cmd.parm.setup.screen = cmsg->CallingPartyNumber[2];
899 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s\n",
901 cmd.parm.setup.phone,
904 cmd.parm.setup.eazmsn);
906 if (cmd.parm.setup.si1 == 1 && cmd.parm.setup.si2 != 0) {
907 printk(KERN_INFO "capidrv-%d: patching si2=%d to 0 for VBOX\n",
910 cmd.parm.setup.si2 = 0;
913 switch (card->interface.statcallb(&cmd)) {
916 /* No device matching this call.
917 * and isdn_common.c has send a HANGUP command
918 * which is ignored in state ST_PLCI_INCOMING,
919 * so we send RESP to ignore the call
921 capi_cmsg_answer(cmsg);
922 cmsg->Reject = 1; /* ignore */
923 send_message(card, cmsg);
924 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
925 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
927 cmd.parm.setup.phone,
930 cmd.parm.setup.eazmsn);
933 /* At least one device matching this call (RING on ttyI)
934 * HL-driver may send ALERTING on the D-channel in this
936 * really means: RING on ttyI or a net interface
937 * accepted this call already.
939 * If the call was accepted, state has already changed,
940 * and CONNECT_RESP already sent.
942 if (plcip->state == ST_PLCI_INCOMING) {
943 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
945 cmd.parm.setup.phone,
948 cmd.parm.setup.eazmsn);
949 capi_fill_ALERT_REQ(cmsg,
952 plcip->plci, /* adr */
953 NULL,/* BChannelinformation */
954 NULL,/* Keypadfacility */
955 NULL,/* Useruserdata */
956 NULL /* Facilitydataarray */
958 plcip->msgid = cmsg->Messagenumber;
959 send_message(card, cmsg);
961 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
963 cmd.parm.setup.phone,
966 cmd.parm.setup.eazmsn);
970 case 2: /* Call will be rejected. */
971 capi_cmsg_answer(cmsg);
972 cmsg->Reject = 2; /* reject call, normal call clearing */
973 send_message(card, cmsg);
974 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
978 /* An error happened. (Invalid parameters for example.) */
979 capi_cmsg_answer(cmsg);
980 cmsg->Reject = 8; /* reject call,
981 destination out of order */
982 send_message(card, cmsg);
983 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
989 static void handle_plci(_cmsg * cmsg)
991 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 printk(KERN_ERR "capidrv-%d: %s\n",
1127 card->contrnr, capi_cmsg2str(cmsg));
1130 case CAPI_CONNECT_ACTIVE_CONF: /* plci */
1132 case CAPI_SELECT_B_PROTOCOL_CONF: /* plci */
1134 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1136 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1139 case CAPI_INFO_CONF: /* Controller/plci */
1143 printk(KERN_ERR "capidrv-%d: got %s for plci 0x%x ???",
1145 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1150 printk(KERN_INFO "capidrv-%d: %s for plci 0x%x ignored\n",
1152 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1156 printk(KERN_ERR "capidrv-%d: %s: plci 0x%x not found\n",
1158 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1163 static void handle_ncci(_cmsg * cmsg)
1165 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1166 capidrv_plci *plcip;
1167 capidrv_ncci *nccip;
1172 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1173 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1174 cmsg->adr.adrController & 0x7f);
1177 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
1179 case CAPI_CONNECT_B3_ACTIVE_IND: /* ncci */
1180 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1183 capi_cmsg_answer(cmsg);
1184 send_message(card, cmsg);
1185 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND);
1187 cmd.command = ISDN_STAT_BCONN;
1188 cmd.driver = card->myid;
1189 cmd.arg = nccip->chan;
1190 card->interface.statcallb(&cmd);
1192 printk(KERN_INFO "capidrv-%d: chan %d up with ncci 0x%x\n",
1193 card->contrnr, nccip->chan, nccip->ncci);
1196 case CAPI_CONNECT_B3_ACTIVE_CONF: /* ncci */
1199 case CAPI_CONNECT_B3_IND: /* ncci */
1201 plcip = find_plci_by_ncci(card, cmsg->adr.adrNCCI);
1203 nccip = new_ncci(card, plcip, cmsg->adr.adrNCCI);
1205 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_IND);
1206 capi_fill_CONNECT_B3_RESP(cmsg,
1209 nccip->ncci, /* adr */
1213 send_message(card, cmsg);
1214 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP);
1217 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
1219 printk(KERN_ERR "capidrv-%d: %s: plci for ncci 0x%x not found\n",
1221 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1224 capi_fill_CONNECT_B3_RESP(cmsg,
1231 send_message(card, cmsg);
1234 case CAPI_CONNECT_B3_CONF: /* ncci */
1236 if (!(nccip = find_ncci_by_msgid(card,
1238 cmsg->Messagenumber)))
1241 nccip->ncci = cmsg->adr.adrNCCI;
1243 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1245 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1246 cmsg->Info, capi_info2str(cmsg->Info),
1251 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_ERROR);
1253 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_OK);
1256 case CAPI_CONNECT_B3_T90_ACTIVE_IND: /* ncci */
1257 capi_cmsg_answer(cmsg);
1258 send_message(card, cmsg);
1261 case CAPI_DATA_B3_IND: /* ncci */
1262 /* handled in handle_data() */
1265 case CAPI_DATA_B3_CONF: /* ncci */
1267 printk(KERN_WARNING "CAPI_DATA_B3_CONF: Info %x - %s\n",
1268 cmsg->Info, capi_info2str(cmsg->Info));
1270 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1273 len = capidrv_del_ack(nccip, cmsg->DataHandle);
1276 cmd.command = ISDN_STAT_BSENT;
1277 cmd.driver = card->myid;
1278 cmd.arg = nccip->chan;
1279 cmd.parm.length = len;
1280 card->interface.statcallb(&cmd);
1283 case CAPI_DISCONNECT_B3_IND: /* ncci */
1284 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1287 card->bchans[nccip->chan].disconnecting = 1;
1288 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND);
1289 capi_cmsg_answer(cmsg);
1290 send_message(card, cmsg);
1291 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP);
1294 case CAPI_DISCONNECT_B3_CONF: /* ncci */
1295 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1298 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1300 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1301 cmsg->Info, capi_info2str(cmsg->Info),
1303 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_CONF_ERROR);
1307 case CAPI_RESET_B3_IND: /* ncci */
1308 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1310 ncci_change_state(card, nccip, EV_NCCI_RESET_B3_IND);
1311 capi_cmsg_answer(cmsg);
1312 send_message(card, cmsg);
1315 case CAPI_RESET_B3_CONF: /* ncci */
1316 goto ignored; /* $$$$ */
1318 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1320 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1324 printk(KERN_ERR "capidrv-%d: got %s for ncci 0x%x ???",
1326 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1331 printk(KERN_INFO "capidrv-%d: %s for ncci 0x%x ignored\n",
1333 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1337 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1339 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1344 static void handle_data(_cmsg * cmsg, struct sk_buff *skb)
1346 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1347 capidrv_ncci *nccip;
1350 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1351 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1352 cmsg->adr.adrController & 0x7f);
1356 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) {
1357 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1359 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1364 (void) skb_pull(skb, CAPIMSG_LEN(skb->data));
1365 card->interface.rcvcallb_skb(card->myid, nccip->chan, skb);
1366 capi_cmsg_answer(cmsg);
1367 send_message(card, cmsg);
1370 static _cmsg s_cmsg;
1372 static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
1374 capi_message2cmsg(&s_cmsg, skb->data);
1376 printk(KERN_DEBUG "capidrv_signal: applid=%d %s\n",
1377 ap->applid, capi_cmsg2str(&s_cmsg));
1379 if (s_cmsg.Command == CAPI_DATA_B3
1380 && s_cmsg.Subcommand == CAPI_IND) {
1381 handle_data(&s_cmsg, skb);
1384 if ((s_cmsg.adr.adrController & 0xffffff00) == 0)
1385 handle_controller(&s_cmsg);
1386 else if ((s_cmsg.adr.adrPLCI & 0xffff0000) == 0)
1387 handle_plci(&s_cmsg);
1389 handle_ncci(&s_cmsg);
1391 * data of skb used in s_cmsg,
1392 * free data when s_cmsg is not used again
1393 * thanks to Lars Heete <hel@admin.de>
1398 /* ------------------------------------------------------------------- */
1400 #define PUTBYTE_TO_STATUS(card, byte) \
1402 *(card)->q931_write++ = (byte); \
1403 if ((card)->q931_write > (card)->q931_end) \
1404 (card)->q931_write = (card)->q931_buf; \
1407 static void handle_dtrace_data(capidrv_contr *card,
1408 int send, int level2, u8 *data, u16 len)
1414 printk(KERN_DEBUG "capidrv-%d: avmb1_q931_data: len == %d\n",
1415 card->contrnr, len);
1420 PUTBYTE_TO_STATUS(card, 'D');
1421 PUTBYTE_TO_STATUS(card, '2');
1422 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1423 PUTBYTE_TO_STATUS(card, ':');
1425 PUTBYTE_TO_STATUS(card, 'D');
1426 PUTBYTE_TO_STATUS(card, '3');
1427 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1428 PUTBYTE_TO_STATUS(card, ':');
1431 for (p = data, end = data+len; p < end; p++) {
1433 PUTBYTE_TO_STATUS(card, ' ');
1434 w = (*p >> 4) & 0xf;
1435 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1437 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1439 PUTBYTE_TO_STATUS(card, '\n');
1441 cmd.command = ISDN_STAT_STAVAIL;
1442 cmd.driver = card->myid;
1444 card->interface.statcallb(&cmd);
1447 /* ------------------------------------------------------------------- */
1449 static _cmsg cmdcmsg;
1451 static int capidrv_ioctl(isdn_ctrl * c, capidrv_contr * card)
1455 debugmode = (int)(*((unsigned int *)c->parm.num));
1456 printk(KERN_DEBUG "capidrv-%d: debugmode=%d\n",
1457 card->contrnr, debugmode);
1460 printk(KERN_DEBUG "capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1461 card->contrnr, c->arg);
1468 * Handle leased lines (CAPI-Bundling)
1471 struct internal_bchannelinfo {
1472 unsigned short channelalloc;
1473 unsigned short operation;
1474 unsigned char cmask[31];
1477 static int decodeFVteln(char *teln, unsigned long *bmaskp, int *activep)
1479 unsigned long bmask = 0;
1484 if (strncmp(teln, "FV:", 3) != 0)
1487 while (*s && *s == ' ') s++;
1489 if (*s == 'p' || *s == 'P') {
1493 if (*s == 'a' || *s == 'A') {
1500 if (!isdigit(*s)) return -3;
1501 while (isdigit(*s)) { digit1 = digit1*10 + (*s - '0'); s++; }
1502 if (digit1 <= 0 && digit1 > 30) return -4;
1503 if (*s == 0 || *s == ',' || *s == ' ') {
1504 bmask |= (1 << digit1);
1509 if (*s != '-') return -5;
1511 if (!isdigit(*s)) return -3;
1512 while (isdigit(*s)) { digit2 = digit2*10 + (*s - '0'); s++; }
1513 if (digit2 <= 0 && digit2 > 30) return -4;
1514 if (*s == 0 || *s == ',' || *s == ' ') {
1515 if (digit1 > digit2)
1516 for (i = digit2; i <= digit1 ; i++)
1519 for (i = digit1; i <= digit2 ; i++)
1521 digit1 = digit2 = 0;
1527 if (activep) *activep = active;
1528 if (bmaskp) *bmaskp = bmask;
1532 static int FVteln2capi20(char *teln, u8 AdditionalInfo[1+2+2+31])
1534 unsigned long bmask;
1538 rc = decodeFVteln(teln, &bmask, &active);
1541 AdditionalInfo[0] = 2+2+31;
1542 /* Channel: 3 => use channel allocation */
1543 AdditionalInfo[1] = 3; AdditionalInfo[2] = 0;
1544 /* Operation: 0 => DTE mode, 1 => DCE mode */
1546 AdditionalInfo[3] = 0; AdditionalInfo[4] = 0;
1548 AdditionalInfo[3] = 1; AdditionalInfo[4] = 0;
1550 /* Channel mask array */
1551 AdditionalInfo[5] = 0; /* no D-Channel */
1552 for (i=1; i <= 30; i++)
1553 AdditionalInfo[5+i] = (bmask & (1 << i)) ? 0xff : 0;
1557 static int capidrv_command(isdn_ctrl * c, capidrv_contr * card)
1560 struct capidrv_bchan *bchan;
1561 struct capidrv_plci *plcip;
1562 u8 AdditionalInfo[1+2+2+31];
1563 int rc, isleasedline = 0;
1565 if (c->command == ISDN_CMD_IOCTL)
1566 return capidrv_ioctl(c, card);
1568 switch (c->command) {
1569 case ISDN_CMD_DIAL:{
1570 u8 calling[ISDN_MSNLEN + 3];
1571 u8 called[ISDN_MSNLEN + 2];
1574 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1577 c->parm.setup.phone,
1580 c->parm.setup.eazmsn);
1582 bchan = &card->bchans[c->arg % card->nbchan];
1585 printk(KERN_ERR "capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1588 c->parm.setup.phone,
1591 c->parm.setup.eazmsn,
1592 bchan->plcip->plci);
1595 bchan->si1 = c->parm.setup.si1;
1596 bchan->si2 = c->parm.setup.si2;
1598 strncpy(bchan->num, c->parm.setup.phone, sizeof(bchan->num));
1599 strncpy(bchan->mynum, c->parm.setup.eazmsn, sizeof(bchan->mynum));
1600 rc = FVteln2capi20(bchan->num, AdditionalInfo);
1601 isleasedline = (rc == 0);
1603 printk(KERN_ERR "capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card->contrnr, bchan->num);
1609 printk(KERN_DEBUG "capidrv-%d: connecting leased line\n", card->contrnr);
1611 calling[0] = strlen(bchan->mynum) + 2;
1614 strncpy(calling + 3, bchan->mynum, ISDN_MSNLEN);
1615 called[0] = strlen(bchan->num) + 1;
1617 strncpy(called + 2, bchan->num, ISDN_MSNLEN);
1620 capi_fill_CONNECT_REQ(&cmdcmsg,
1623 card->contrnr, /* adr */
1624 si2cip(bchan->si1, bchan->si2), /* cipvalue */
1625 called, /* CalledPartyNumber */
1626 calling, /* CallingPartyNumber */
1627 NULL, /* CalledPartySubaddress */
1628 NULL, /* CallingPartySubaddress */
1629 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1630 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1631 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1632 b1config(bchan->l2, bchan->l3), /* B1configuration */
1633 NULL, /* B2configuration */
1634 NULL, /* B3configuration */
1638 /* BChannelinformation */
1639 isleasedline ? AdditionalInfo : NULL,
1640 NULL, /* Keypadfacility */
1641 NULL, /* Useruserdata */
1642 NULL /* Facilitydataarray */
1644 if ((plcip = new_plci(card, (c->arg % card->nbchan))) == 0) {
1645 cmd.command = ISDN_STAT_DHUP;
1646 cmd.driver = card->myid;
1647 cmd.arg = (c->arg % card->nbchan);
1648 card->interface.statcallb(&cmd);
1651 plcip->msgid = cmdcmsg.Messagenumber;
1652 plcip->leasedline = isleasedline;
1653 plci_change_state(card, plcip, EV_PLCI_CONNECT_REQ);
1654 send_message(card, &cmdcmsg);
1658 case ISDN_CMD_ACCEPTD:
1660 bchan = &card->bchans[c->arg % card->nbchan];
1662 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1664 c->arg, bchan->l2, bchan->l3);
1666 capi_fill_CONNECT_RESP(&cmdcmsg,
1669 bchan->plcip->plci, /* adr */
1671 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1672 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1673 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1674 b1config(bchan->l2, bchan->l3), /* B1configuration */
1675 NULL, /* B2configuration */
1676 NULL, /* B3configuration */
1677 NULL, /* ConnectedNumber */
1678 NULL, /* ConnectedSubaddress */
1680 NULL, /* BChannelinformation */
1681 NULL, /* Keypadfacility */
1682 NULL, /* Useruserdata */
1683 NULL /* Facilitydataarray */
1685 capi_cmsg2message(&cmdcmsg, cmdcmsg.buf);
1686 plci_change_state(card, bchan->plcip, EV_PLCI_CONNECT_RESP);
1687 send_message(card, &cmdcmsg);
1690 case ISDN_CMD_ACCEPTB:
1692 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1697 case ISDN_CMD_HANGUP:
1699 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1702 bchan = &card->bchans[c->arg % card->nbchan];
1704 if (bchan->disconnecting) {
1706 printk(KERN_DEBUG "capidrv-%d: chan %ld already disconnecting ...\n",
1712 bchan->disconnecting = 1;
1713 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg,
1719 ncci_change_state(card, bchan->nccip, EV_NCCI_DISCONNECT_B3_REQ);
1720 send_message(card, &cmdcmsg);
1722 } else if (bchan->plcip) {
1723 if (bchan->plcip->state == ST_PLCI_INCOMING) {
1725 * just ignore, we a called from
1726 * isdn_status_callback(),
1727 * which will return 0 or 2, this is handled
1728 * by the CONNECT_IND handler
1730 bchan->disconnecting = 1;
1732 } else if (bchan->plcip->plci) {
1733 bchan->disconnecting = 1;
1734 capi_fill_DISCONNECT_REQ(&cmdcmsg,
1738 NULL, /* BChannelinformation */
1739 NULL, /* Keypadfacility */
1740 NULL, /* Useruserdata */
1741 NULL /* Facilitydataarray */
1743 plci_change_state(card, bchan->plcip, EV_PLCI_DISCONNECT_REQ);
1744 send_message(card, &cmdcmsg);
1747 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1753 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request on free channel\n",
1759 case ISDN_CMD_SETL2:
1761 printk(KERN_DEBUG "capidrv-%d: set L2 on chan %ld to %ld\n",
1763 (c->arg & 0xff), (c->arg >> 8));
1764 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1765 bchan->l2 = (c->arg >> 8);
1768 case ISDN_CMD_SETL3:
1770 printk(KERN_DEBUG "capidrv-%d: set L3 on chan %ld to %ld\n",
1772 (c->arg & 0xff), (c->arg >> 8));
1773 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1774 bchan->l3 = (c->arg >> 8);
1777 case ISDN_CMD_SETEAZ:
1779 printk(KERN_DEBUG "capidrv-%d: set EAZ \"%s\" on chan %ld\n",
1781 c->parm.num, c->arg);
1782 bchan = &card->bchans[c->arg % card->nbchan];
1783 strncpy(bchan->msn, c->parm.num, ISDN_MSNLEN);
1786 case ISDN_CMD_CLREAZ:
1788 printk(KERN_DEBUG "capidrv-%d: clearing EAZ on chan %ld\n",
1789 card->contrnr, c->arg);
1790 bchan = &card->bchans[c->arg % card->nbchan];
1795 printk(KERN_ERR "capidrv-%d: ISDN_CMD_%d, Huh?\n",
1796 card->contrnr, c->command);
1802 static int if_command(isdn_ctrl * c)
1804 capidrv_contr *card = findcontrbydriverid(c->driver);
1807 return capidrv_command(c, card);
1810 "capidrv: if_command %d called with invalid driverId %d!\n",
1811 c->command, c->driver);
1815 static _cmsg sendcmsg;
1817 static int if_sendbuf(int id, int channel, int doack, struct sk_buff *skb)
1819 capidrv_contr *card = findcontrbydriverid(id);
1820 capidrv_bchan *bchan;
1821 capidrv_ncci *nccip;
1828 printk(KERN_ERR "capidrv: if_sendbuf called with invalid driverId %d!\n",
1833 printk(KERN_DEBUG "capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
1834 card->contrnr, len, skb, doack);
1835 bchan = &card->bchans[channel % card->nbchan];
1836 nccip = bchan->nccip;
1837 if (!nccip || nccip->state != ST_NCCI_ACTIVE) {
1838 printk(KERN_ERR "capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
1839 card->contrnr, card->name, channel);
1842 datahandle = nccip->datahandle;
1843 capi_fill_DATA_B3_REQ(&sendcmsg, global.ap.applid, card->msgid++,
1844 nccip->ncci, /* adr */
1845 (u32) skb->data, /* Data */
1846 skb->len, /* DataLength */
1847 datahandle, /* DataHandle */
1851 if (capidrv_add_ack(nccip, datahandle, doack ? (int)skb->len : -1) < 0)
1854 capi_cmsg2message(&sendcmsg, sendcmsg.buf);
1855 msglen = CAPIMSG_LEN(sendcmsg.buf);
1856 if (skb_headroom(skb) < msglen) {
1857 struct sk_buff *nskb = skb_realloc_headroom(skb, msglen);
1859 printk(KERN_ERR "capidrv-%d: if_sendbuf: no memory\n",
1861 (void)capidrv_del_ack(nccip, datahandle);
1864 printk(KERN_DEBUG "capidrv-%d: only %d bytes headroom, need %d\n",
1865 card->contrnr, skb_headroom(skb), msglen);
1866 memcpy(skb_push(nskb, msglen), sendcmsg.buf, msglen);
1867 errcode = capi20_put_message(&global.ap, nskb);
1868 if (errcode == CAPI_NOERROR) {
1870 nccip->datahandle++;
1874 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1875 card->contrnr, errcode, capi_info2str(errcode));
1876 (void)capidrv_del_ack(nccip, datahandle);
1877 dev_kfree_skb(nskb);
1878 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1880 memcpy(skb_push(skb, msglen), sendcmsg.buf, msglen);
1881 errcode = capi20_put_message(&global.ap, skb);
1882 if (errcode == CAPI_NOERROR) {
1883 nccip->datahandle++;
1887 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1888 card->contrnr, errcode, capi_info2str(errcode));
1889 skb_pull(skb, msglen);
1890 (void)capidrv_del_ack(nccip, datahandle);
1891 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1895 static int if_readstat(u8 __user *buf, int len, int id, int channel)
1897 capidrv_contr *card = findcontrbydriverid(id);
1902 printk(KERN_ERR "capidrv: if_readstat called with invalid driverId %d!\n",
1907 for (p=buf, count=0; count < len; p++, count++) {
1908 if (put_user(*card->q931_read++, p))
1910 if (card->q931_read > card->q931_end)
1911 card->q931_read = card->q931_buf;
1917 static void enable_dchannel_trace(capidrv_contr *card)
1919 u8 manufacturer[CAPI_MANUFACTURER_LEN];
1920 capi_version version;
1921 u16 contr = card->contrnr;
1925 errcode = capi20_get_manufacturer(contr, manufacturer);
1926 if (errcode != CAPI_NOERROR) {
1927 printk(KERN_ERR "%s: can't get manufacturer (0x%x)\n",
1928 card->name, errcode);
1931 if (strstr(manufacturer, "AVM") == 0) {
1932 printk(KERN_ERR "%s: not from AVM, no d-channel trace possible (%s)\n",
1933 card->name, manufacturer);
1936 errcode = capi20_get_version(contr, &version);
1937 if (errcode != CAPI_NOERROR) {
1938 printk(KERN_ERR "%s: can't get version (0x%x)\n",
1939 card->name, errcode);
1942 avmversion[0] = (version.majormanuversion >> 4) & 0x0f;
1943 avmversion[1] = (version.majormanuversion << 4) & 0xf0;
1944 avmversion[1] |= (version.minormanuversion >> 4) & 0x0f;
1945 avmversion[2] |= version.minormanuversion & 0x0f;
1947 if (avmversion[0] > 3 || (avmversion[0] == 3 && avmversion[1] > 5)) {
1948 printk(KERN_INFO "%s: D2 trace enabled\n", card->name);
1949 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid,
1952 0x214D5641, /* ManuID */
1955 (_cstruct)"\004\200\014\000\000");
1957 printk(KERN_INFO "%s: D3 trace enabled\n", card->name);
1958 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid,
1961 0x214D5641, /* ManuID */
1964 (_cstruct)"\004\002\003\000\000");
1966 send_message(card, &cmdcmsg);
1970 static void send_listen(capidrv_contr *card)
1972 capi_fill_LISTEN_REQ(&cmdcmsg, global.ap.applid,
1974 card->contrnr, /* controller */
1975 1 << 6, /* Infomask */
1979 send_message(card, &cmdcmsg);
1980 listen_change_state(card, EV_LISTEN_REQ);
1983 static void listentimerfunc(unsigned long x)
1985 capidrv_contr *card = (capidrv_contr *)x;
1986 if (card->state != ST_LISTEN_NONE && card->state != ST_LISTEN_ACTIVE)
1987 printk(KERN_ERR "%s: controller dead ??\n", card->name);
1989 mod_timer(&card->listentimer, jiffies + 60*HZ);
1993 static int capidrv_addcontr(u16 contr, struct capi_profile *profp)
1995 capidrv_contr *card;
1996 unsigned long flags;
2001 sprintf(id, "capidrv-%d", contr);
2002 if (!try_module_get(THIS_MODULE)) {
2003 printk(KERN_WARNING "capidrv: (%s) Could not reserve module\n", id);
2006 if (!(card = kzalloc(sizeof(capidrv_contr), GFP_ATOMIC))) {
2008 "capidrv: (%s) Could not allocate contr-struct.\n", id);
2011 card->owner = THIS_MODULE;
2012 init_timer(&card->listentimer);
2013 strcpy(card->name, id);
2014 card->contrnr = contr;
2015 card->nbchan = profp->nbchannel;
2016 card->bchans = (capidrv_bchan *) kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC);
2017 if (!card->bchans) {
2019 "capidrv: (%s) Could not allocate bchan-structs.\n", id);
2020 module_put(card->owner);
2024 card->interface.channels = profp->nbchannel;
2025 card->interface.maxbufsize = 2048;
2026 card->interface.command = if_command;
2027 card->interface.writebuf_skb = if_sendbuf;
2028 card->interface.writecmd = NULL;
2029 card->interface.readstat = if_readstat;
2030 card->interface.features = ISDN_FEATURE_L2_HDLC |
2031 ISDN_FEATURE_L2_TRANS |
2032 ISDN_FEATURE_L3_TRANS |
2033 ISDN_FEATURE_P_UNKNOWN |
2034 ISDN_FEATURE_L2_X75I |
2035 ISDN_FEATURE_L2_X75UI |
2036 ISDN_FEATURE_L2_X75BUI;
2037 if (profp->support1 & (1<<2))
2038 card->interface.features |= ISDN_FEATURE_L2_V11096 |
2039 ISDN_FEATURE_L2_V11019 |
2040 ISDN_FEATURE_L2_V11038;
2041 if (profp->support1 & (1<<8))
2042 card->interface.features |= ISDN_FEATURE_L2_MODEM;
2043 card->interface.hl_hdrlen = 22; /* len of DATA_B3_REQ */
2044 strncpy(card->interface.id, id, sizeof(card->interface.id) - 1);
2047 card->q931_read = card->q931_buf;
2048 card->q931_write = card->q931_buf;
2049 card->q931_end = card->q931_buf + sizeof(card->q931_buf) - 1;
2051 if (!register_isdn(&card->interface)) {
2052 printk(KERN_ERR "capidrv: Unable to register contr %s\n", id);
2053 kfree(card->bchans);
2054 module_put(card->owner);
2058 card->myid = card->interface.channels;
2059 memset(card->bchans, 0, sizeof(capidrv_bchan) * card->nbchan);
2060 for (i = 0; i < card->nbchan; i++) {
2061 card->bchans[i].contr = card;
2064 spin_lock_irqsave(&global_lock, flags);
2065 card->next = global.contr_list;
2066 global.contr_list = card;
2068 spin_unlock_irqrestore(&global_lock, flags);
2070 cmd.command = ISDN_STAT_RUN;
2071 cmd.driver = card->myid;
2072 card->interface.statcallb(&cmd);
2074 card->cipmask = 0x1FFF03FF; /* any */
2077 card->listentimer.data = (unsigned long)card;
2078 card->listentimer.function = listentimerfunc;
2080 mod_timer(&card->listentimer, jiffies + 60*HZ);
2082 printk(KERN_INFO "%s: now up (%d B channels)\n",
2083 card->name, card->nbchan);
2085 enable_dchannel_trace(card);
2090 static int capidrv_delcontr(u16 contr)
2092 capidrv_contr **pp, *card;
2093 unsigned long flags;
2096 spin_lock_irqsave(&global_lock, flags);
2097 for (card = global.contr_list; card; card = card->next) {
2098 if (card->contrnr == contr)
2102 spin_unlock_irqrestore(&global_lock, flags);
2103 printk(KERN_ERR "capidrv: delcontr: no contr %u\n", contr);
2106 #warning FIXME: maybe a race condition the card should be removed here from global list /kkeil
2107 spin_unlock_irqrestore(&global_lock, flags);
2109 del_timer(&card->listentimer);
2112 printk(KERN_DEBUG "capidrv-%d: id=%d unloading\n",
2113 card->contrnr, card->myid);
2115 cmd.command = ISDN_STAT_STOP;
2116 cmd.driver = card->myid;
2117 card->interface.statcallb(&cmd);
2119 while (card->nbchan) {
2121 cmd.command = ISDN_STAT_DISCH;
2122 cmd.driver = card->myid;
2123 cmd.arg = card->nbchan-1;
2124 cmd.parm.num[0] = 0;
2126 printk(KERN_DEBUG "capidrv-%d: id=%d disable chan=%ld\n",
2127 card->contrnr, card->myid, cmd.arg);
2128 card->interface.statcallb(&cmd);
2130 if (card->bchans[card->nbchan-1].nccip)
2131 free_ncci(card, card->bchans[card->nbchan-1].nccip);
2132 if (card->bchans[card->nbchan-1].plcip)
2133 free_plci(card, card->bchans[card->nbchan-1].plcip);
2134 if (card->plci_list)
2135 printk(KERN_ERR "capidrv: bug in free_plci()\n");
2138 kfree(card->bchans);
2139 card->bchans = NULL;
2142 printk(KERN_DEBUG "capidrv-%d: id=%d isdn unload\n",
2143 card->contrnr, card->myid);
2145 cmd.command = ISDN_STAT_UNLOAD;
2146 cmd.driver = card->myid;
2147 card->interface.statcallb(&cmd);
2150 printk(KERN_DEBUG "capidrv-%d: id=%d remove contr from list\n",
2151 card->contrnr, card->myid);
2153 spin_lock_irqsave(&global_lock, flags);
2154 for (pp = &global.contr_list; *pp; pp = &(*pp)->next) {
2162 spin_unlock_irqrestore(&global_lock, flags);
2164 module_put(card->owner);
2165 printk(KERN_INFO "%s: now down.\n", card->name);
2171 static void lower_callback(unsigned int cmd, u32 contr, void *data)
2176 printk(KERN_INFO "capidrv: controller %hu up\n", contr);
2177 (void) capidrv_addcontr(contr, (capi_profile *) data);
2180 printk(KERN_INFO "capidrv: controller %hu down\n", contr);
2181 (void) capidrv_delcontr(contr);
2187 * /proc/capi/capidrv:
2188 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2190 static int proc_capidrv_read_proc(char *page, char **start, off_t off,
2191 int count, int *eof, void *data)
2195 len += sprintf(page+len, "%lu %lu %lu %lu\n",
2196 global.ap.nrecvctlpkt,
2197 global.ap.nrecvdatapkt,
2198 global.ap.nsentctlpkt,
2199 global.ap.nsentdatapkt);
2200 if (off+count >= len)
2204 *start = page + off;
2205 return ((count < len-off) ? count : len-off);
2208 static struct procfsentries {
2211 int (*read_proc)(char *page, char **start, off_t off,
2212 int count, int *eof, void *data);
2213 struct proc_dir_entry *procent;
2214 } procfsentries[] = {
2215 /* { "capi", S_IFDIR, 0 }, */
2216 { "capi/capidrv", 0 , proc_capidrv_read_proc },
2219 static void __init proc_init(void)
2221 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2224 for (i=0; i < nelem; i++) {
2225 struct procfsentries *p = procfsentries + i;
2226 p->procent = create_proc_entry(p->name, p->mode, NULL);
2227 if (p->procent) p->procent->read_proc = p->read_proc;
2231 static void __exit proc_exit(void)
2233 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2236 for (i=nelem-1; i >= 0; i--) {
2237 struct procfsentries *p = procfsentries + i;
2239 remove_proc_entry(p->name, NULL);
2245 static int __init capidrv_init(void)
2247 capi_profile profile;
2253 if ((p = strchr(revision, ':')) != 0 && p[1]) {
2254 strncpy(rev, p + 2, sizeof(rev));
2255 rev[sizeof(rev)-1] = 0;
2256 if ((p = strchr(rev, '$')) != 0 && p > rev)
2261 global.ap.rparam.level3cnt = -2; /* number of bchannels twice */
2262 global.ap.rparam.datablkcnt = 16;
2263 global.ap.rparam.datablklen = 2048;
2265 global.ap.recv_message = capidrv_recv_message;
2266 errcode = capi20_register(&global.ap);
2271 capi20_set_callback(&global.ap, lower_callback);
2273 errcode = capi20_get_profile(0, &profile);
2274 if (errcode != CAPI_NOERROR) {
2275 capi20_release(&global.ap);
2279 ncontr = profile.ncontroller;
2280 for (contr = 1; contr <= ncontr; contr++) {
2281 errcode = capi20_get_profile(contr, &profile);
2282 if (errcode != CAPI_NOERROR)
2284 (void) capidrv_addcontr(contr, &profile);
2288 printk(KERN_NOTICE "capidrv: Rev %s: loaded\n", rev);
2292 static void __exit capidrv_exit(void)
2297 if ((p = strchr(revision, ':')) != 0) {
2299 p = strchr(rev, '$');
2302 strcpy(rev, " ??? ");
2305 capi20_release(&global.ap);
2309 printk(KERN_NOTICE "capidrv: Rev%s: unloaded\n", rev);
2312 module_init(capidrv_init);
2313 module_exit(capidrv_exit);