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>
33 #include <linux/isdn/capiutil.h>
34 #include <linux/isdn/capicmd.h>
37 static char *revision = "$Revision: 1.1.2.2 $";
38 static int debugmode = 0;
40 MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux");
41 MODULE_AUTHOR("Carsten Paeth");
42 MODULE_LICENSE("GPL");
43 MODULE_PARM(debugmode, "i");
45 /* -------- type definitions ----------------------------------------- */
48 struct capidrv_contr {
50 struct capidrv_contr *next;
67 struct timer_list listentimer;
70 * ID of capi message sent
78 struct capidrv_bchan {
79 struct capidrv_contr *contr;
84 u8 mynum[ISDN_MSNLEN];
90 struct capidrv_plci *next;
92 u32 ncci; /* ncci for CONNECT_ACTIVE_IND */
93 u16 msgid; /* to identfy CONNECT_CONF */
98 struct capidrv_ncci *next;
99 struct capidrv_plci *plcip;
101 u16 msgid; /* to identfy CONNECT_B3_CONF */
107 struct ncci_datahandle_queue {
108 struct ncci_datahandle_queue *next;
114 struct capidrv_ncci *nccip;
117 struct capidrv_plci *plci_list;
127 struct capidrv_data {
128 struct capi20_appl ap;
130 struct capidrv_contr *contr_list;
133 typedef struct capidrv_plci capidrv_plci;
134 typedef struct capidrv_ncci capidrv_ncci;
135 typedef struct capidrv_contr capidrv_contr;
136 typedef struct capidrv_data capidrv_data;
137 typedef struct capidrv_bchan capidrv_bchan;
139 /* -------- data definitions ----------------------------------------- */
141 static capidrv_data global;
142 static spinlock_t global_lock = SPIN_LOCK_UNLOCKED;
144 static void handle_dtrace_data(capidrv_contr *card,
145 int send, int level2, u8 *data, u16 len);
147 /* -------- convert functions ---------------------------------------- */
149 static inline u32 b1prot(int l2, int l3)
152 case ISDN_PROTO_L2_X75I:
153 case ISDN_PROTO_L2_X75UI:
154 case ISDN_PROTO_L2_X75BUI:
156 case ISDN_PROTO_L2_HDLC:
159 case ISDN_PROTO_L2_TRANS:
161 case ISDN_PROTO_L2_V11096:
162 case ISDN_PROTO_L2_V11019:
163 case ISDN_PROTO_L2_V11038:
165 case ISDN_PROTO_L2_FAX:
167 case ISDN_PROTO_L2_MODEM:
172 static inline u32 b2prot(int l2, int l3)
175 case ISDN_PROTO_L2_X75I:
176 case ISDN_PROTO_L2_X75UI:
177 case ISDN_PROTO_L2_X75BUI:
180 case ISDN_PROTO_L2_HDLC:
181 case ISDN_PROTO_L2_TRANS:
182 case ISDN_PROTO_L2_V11096:
183 case ISDN_PROTO_L2_V11019:
184 case ISDN_PROTO_L2_V11038:
185 case ISDN_PROTO_L2_MODEM:
187 case ISDN_PROTO_L2_FAX:
192 static inline u32 b3prot(int l2, int l3)
195 case ISDN_PROTO_L2_X75I:
196 case ISDN_PROTO_L2_X75UI:
197 case ISDN_PROTO_L2_X75BUI:
198 case ISDN_PROTO_L2_HDLC:
199 case ISDN_PROTO_L2_TRANS:
200 case ISDN_PROTO_L2_V11096:
201 case ISDN_PROTO_L2_V11019:
202 case ISDN_PROTO_L2_V11038:
203 case ISDN_PROTO_L2_MODEM:
206 case ISDN_PROTO_L2_FAX:
211 static _cstruct b1config_async_v110(u16 rate)
213 /* CAPI-Spec "B1 Configuration" */
214 static unsigned char buf[9];
215 buf[0] = 8; /* len */
216 /* maximum bitrate */
217 buf[1] = rate & 0xff; buf[2] = (rate >> 8) & 0xff;
218 buf[3] = 8; buf[4] = 0; /* 8 bits per character */
219 buf[5] = 0; buf[6] = 0; /* parity none */
220 buf[7] = 0; buf[8] = 0; /* 1 stop bit */
224 static _cstruct b1config(int l2, int l3)
227 case ISDN_PROTO_L2_X75I:
228 case ISDN_PROTO_L2_X75UI:
229 case ISDN_PROTO_L2_X75BUI:
230 case ISDN_PROTO_L2_HDLC:
231 case ISDN_PROTO_L2_TRANS:
234 case ISDN_PROTO_L2_V11096:
235 return b1config_async_v110(9600);
236 case ISDN_PROTO_L2_V11019:
237 return b1config_async_v110(19200);
238 case ISDN_PROTO_L2_V11038:
239 return b1config_async_v110(38400);
243 static inline u16 si2cip(u8 si1, u8 si2)
245 static const u8 cip[17][5] =
248 {0, 0, 0, 0, 0}, /*0 */
249 {16, 16, 4, 26, 16}, /*1 */
250 {17, 17, 17, 4, 4}, /*2 */
251 {2, 2, 2, 2, 2}, /*3 */
252 {18, 18, 18, 18, 18}, /*4 */
253 {2, 2, 2, 2, 2}, /*5 */
254 {0, 0, 0, 0, 0}, /*6 */
255 {2, 2, 2, 2, 2}, /*7 */
256 {2, 2, 2, 2, 2}, /*8 */
257 {21, 21, 21, 21, 21}, /*9 */
258 {19, 19, 19, 19, 19}, /*10 */
259 {0, 0, 0, 0, 0}, /*11 */
260 {0, 0, 0, 0, 0}, /*12 */
261 {0, 0, 0, 0, 0}, /*13 */
262 {0, 0, 0, 0, 0}, /*14 */
263 {22, 22, 22, 22, 22}, /*15 */
264 {27, 27, 27, 28, 27} /*16 */
271 return (u16) cip[si1][si2];
274 static inline u8 cip2si1(u16 cipval)
276 static const u8 si[32] =
277 {7, 1, 7, 7, 1, 1, 7, 7, /*0-7 */
278 7, 1, 0, 0, 0, 0, 0, 0, /*8-15 */
279 1, 2, 4, 10, 9, 9, 15, 7, /*16-23 */
280 7, 7, 1, 16, 16, 0, 0, 0}; /*24-31 */
283 cipval = 0; /* .... */
287 static inline u8 cip2si2(u16 cipval)
289 static const u8 si[32] =
290 {0, 0, 0, 0, 2, 3, 0, 0, /*0-7 */
291 0, 3, 0, 0, 0, 0, 0, 0, /*8-15 */
292 1, 2, 0, 0, 9, 0, 0, 0, /*16-23 */
293 0, 0, 3, 2, 3, 0, 0, 0}; /*24-31 */
296 cipval = 0; /* .... */
301 /* -------- controller management ------------------------------------- */
303 static inline capidrv_contr *findcontrbydriverid(int driverid)
308 spin_lock_irqsave(&global_lock, flags);
309 for (p = global.contr_list; p; p = p->next)
310 if (p->myid == driverid)
312 spin_unlock_irqrestore(&global_lock, flags);
316 static capidrv_contr *findcontrbynumber(u32 contr)
319 capidrv_contr *p = global.contr_list;
321 spin_lock_irqsave(&global_lock, flags);
322 for (p = global.contr_list; p; p = p->next)
323 if (p->contrnr == contr)
325 spin_unlock_irqrestore(&global_lock, flags);
330 /* -------- plci management ------------------------------------------ */
332 static capidrv_plci *new_plci(capidrv_contr * card, int chan)
336 plcip = (capidrv_plci *) kmalloc(sizeof(capidrv_plci), GFP_ATOMIC);
341 memset(plcip, 0, sizeof(capidrv_plci));
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 = (capidrv_ncci *) kmalloc(sizeof(capidrv_ncci), GFP_ATOMIC);
411 memset(nccip, 0, sizeof(capidrv_ncci));
413 nccip->state = ST_NCCI_NONE;
414 nccip->plcip = plcip;
415 nccip->chan = plcip->chan;
416 nccip->datahandle = 0;
418 nccip->next = plcip->ncci_list;
419 plcip->ncci_list = nccip;
421 card->bchans[plcip->chan].nccip = nccip;
426 static inline capidrv_ncci *find_ncci(capidrv_contr * card, u32 ncci)
431 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
434 for (p = plcip->ncci_list; p; p = p->next)
440 static inline capidrv_ncci *find_ncci_by_msgid(capidrv_contr * card,
446 if ((plcip = find_plci_by_ncci(card, ncci)) == 0)
449 for (p = plcip->ncci_list; p; p = p->next)
450 if (p->msgid == msgid)
455 static void free_ncci(capidrv_contr * card, struct capidrv_ncci *nccip)
457 struct capidrv_ncci **pp;
459 for (pp = &(nccip->plcip->ncci_list); *pp; pp = &(*pp)->next) {
465 card->bchans[nccip->chan].nccip = NULL;
469 static int capidrv_add_ack(struct capidrv_ncci *nccip,
470 u16 datahandle, int len)
472 struct ncci_datahandle_queue *n, **pp;
474 n = (struct ncci_datahandle_queue *)
475 kmalloc(sizeof(struct ncci_datahandle_queue), GFP_ATOMIC);
477 printk(KERN_ERR "capidrv: kmalloc ncci_datahandle failed\n");
481 n->datahandle = datahandle;
483 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) ;
488 static int capidrv_del_ack(struct capidrv_ncci *nccip, u16 datahandle)
490 struct ncci_datahandle_queue **pp, *p;
493 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) {
494 if ((*pp)->datahandle == datahandle) {
505 /* -------- convert and send capi message ---------------------------- */
507 static void send_message(capidrv_contr * card, _cmsg * cmsg)
511 capi_cmsg2message(cmsg, cmsg->buf);
512 len = CAPIMSG_LEN(cmsg->buf);
513 skb = alloc_skb(len, GFP_ATOMIC);
514 memcpy(skb_put(skb, len), cmsg->buf, len);
515 if (capi20_put_message(&global.ap, skb) != CAPI_NOERROR)
519 /* -------- state machine -------------------------------------------- */
521 struct listenstatechange {
527 static struct listenstatechange listentable[] =
529 {ST_LISTEN_NONE, ST_LISTEN_WAIT_CONF, EV_LISTEN_REQ},
530 {ST_LISTEN_ACTIVE, ST_LISTEN_ACTIVE_WAIT_CONF, EV_LISTEN_REQ},
531 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_ERROR},
532 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_ERROR},
533 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
534 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY},
535 {ST_LISTEN_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
536 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK},
540 static void listen_change_state(capidrv_contr * card, int event)
542 struct listenstatechange *p = listentable;
544 if (card->state == p->actstate && p->event == event) {
546 printk(KERN_DEBUG "capidrv-%d: listen_change_state %d -> %d\n",
547 card->contrnr, card->state, p->nextstate);
548 card->state = p->nextstate;
553 printk(KERN_ERR "capidrv-%d: listen_change_state state=%d event=%d ????\n",
554 card->contrnr, card->state, event);
558 /* ------------------------------------------------------------------ */
560 static void p0(capidrv_contr * card, capidrv_plci * plci)
564 card->bchans[plci->chan].contr = NULL;
565 cmd.command = ISDN_STAT_DHUP;
566 cmd.driver = card->myid;
567 cmd.arg = plci->chan;
568 card->interface.statcallb(&cmd);
569 free_plci(card, plci);
572 /* ------------------------------------------------------------------ */
574 struct plcistatechange {
578 void (*changefunc) (capidrv_contr * card, capidrv_plci * plci);
581 static struct plcistatechange plcitable[] =
584 {ST_PLCI_NONE, ST_PLCI_OUTGOING, EV_PLCI_CONNECT_REQ, NULL},
585 {ST_PLCI_NONE, ST_PLCI_ALLOCATED, EV_PLCI_FACILITY_IND_UP, NULL},
586 {ST_PLCI_NONE, ST_PLCI_INCOMING, EV_PLCI_CONNECT_IND, NULL},
587 {ST_PLCI_NONE, ST_PLCI_RESUMEING, EV_PLCI_RESUME_REQ, NULL},
589 {ST_PLCI_OUTGOING, ST_PLCI_NONE, EV_PLCI_CONNECT_CONF_ERROR, p0},
590 {ST_PLCI_OUTGOING, ST_PLCI_ALLOCATED, EV_PLCI_CONNECT_CONF_OK, NULL},
592 {ST_PLCI_ALLOCATED, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
593 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
594 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
595 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
597 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
598 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
599 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
600 {ST_PLCI_ACTIVE, ST_PLCI_HELD, EV_PLCI_HOLD_IND, NULL},
601 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_SUSPEND_IND, NULL},
603 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
604 {ST_PLCI_INCOMING, ST_PLCI_FACILITY_IND, EV_PLCI_FACILITY_IND_UP, NULL},
605 {ST_PLCI_INCOMING, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_RESP, NULL},
606 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
607 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
608 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
609 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CD_IND, NULL},
611 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL},
612 {ST_PLCI_FACILITY_IND, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
613 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
614 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
615 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
617 {ST_PLCI_ACCEPTING, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL},
618 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL},
619 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL},
620 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
622 {ST_PLCI_DISCONNECTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL},
624 {ST_PLCI_DISCONNECTED, ST_PLCI_NONE, EV_PLCI_DISCONNECT_RESP, p0},
626 {ST_PLCI_RESUMEING, ST_PLCI_NONE, EV_PLCI_RESUME_CONF_ERROR, p0},
627 {ST_PLCI_RESUMEING, ST_PLCI_RESUME, EV_PLCI_RESUME_CONF_OK, NULL},
629 {ST_PLCI_RESUME, ST_PLCI_ACTIVE, EV_PLCI_RESUME_IND, NULL},
631 {ST_PLCI_HELD, ST_PLCI_ACTIVE, EV_PLCI_RETRIEVE_IND, NULL},
635 static void plci_change_state(capidrv_contr * card, capidrv_plci * plci, int event)
637 struct plcistatechange *p = plcitable;
639 if (plci->state == p->actstate && p->event == event) {
641 printk(KERN_DEBUG "capidrv-%d: plci_change_state:0x%x %d -> %d\n",
642 card->contrnr, plci->plci, plci->state, p->nextstate);
643 plci->state = p->nextstate;
645 p->changefunc(card, plci);
650 printk(KERN_ERR "capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n",
651 card->contrnr, plci->plci, plci->state, event);
654 /* ------------------------------------------------------------------ */
658 static void n0(capidrv_contr * card, capidrv_ncci * ncci)
662 capi_fill_DISCONNECT_REQ(&cmsg,
666 NULL, /* BChannelinformation */
667 NULL, /* Keypadfacility */
668 NULL, /* Useruserdata */ /* $$$$ */
669 NULL /* Facilitydataarray */
671 send_message(card, &cmsg);
672 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ);
674 cmd.command = ISDN_STAT_BHUP;
675 cmd.driver = card->myid;
676 cmd.arg = ncci->chan;
677 card->interface.statcallb(&cmd);
678 free_ncci(card, ncci);
681 /* ------------------------------------------------------------------ */
683 struct nccistatechange {
687 void (*changefunc) (capidrv_contr * card, capidrv_ncci * ncci);
690 static struct nccistatechange nccitable[] =
693 {ST_NCCI_NONE, ST_NCCI_OUTGOING, EV_NCCI_CONNECT_B3_REQ, NULL},
694 {ST_NCCI_NONE, ST_NCCI_INCOMING, EV_NCCI_CONNECT_B3_IND, NULL},
696 {ST_NCCI_OUTGOING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_CONF_OK, NULL},
697 {ST_NCCI_OUTGOING, ST_NCCI_NONE, EV_NCCI_CONNECT_B3_CONF_ERROR, n0},
699 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_CONNECT_B3_REJECT, NULL},
700 {ST_NCCI_INCOMING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_RESP, NULL},
701 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
702 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
704 {ST_NCCI_ALLOCATED, ST_NCCI_ACTIVE, EV_NCCI_CONNECT_B3_ACTIVE_IND, NULL},
705 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
706 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
708 {ST_NCCI_ACTIVE, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
709 {ST_NCCI_ACTIVE, ST_NCCI_RESETING, EV_NCCI_RESET_B3_REQ, NULL},
710 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
711 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
713 {ST_NCCI_RESETING, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL},
714 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
715 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL},
717 {ST_NCCI_DISCONNECTING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL},
718 {ST_NCCI_DISCONNECTING, ST_NCCI_PREVIOUS, EV_NCCI_DISCONNECT_B3_CONF_ERROR,NULL},
720 {ST_NCCI_DISCONNECTED, ST_NCCI_NONE, EV_NCCI_DISCONNECT_B3_RESP, n0},
724 static void ncci_change_state(capidrv_contr * card, capidrv_ncci * ncci, int event)
726 struct nccistatechange *p = nccitable;
728 if (ncci->state == p->actstate && p->event == event) {
730 printk(KERN_DEBUG "capidrv-%d: ncci_change_state:0x%x %d -> %d\n",
731 card->contrnr, ncci->ncci, ncci->state, p->nextstate);
732 if (p->nextstate == ST_NCCI_PREVIOUS) {
733 ncci->state = ncci->oldstate;
734 ncci->oldstate = p->actstate;
736 ncci->oldstate = p->actstate;
737 ncci->state = p->nextstate;
740 p->changefunc(card, ncci);
745 printk(KERN_ERR "capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n",
746 card->contrnr, ncci->ncci, ncci->state, event);
749 /* ------------------------------------------------------------------- */
751 static inline int new_bchan(capidrv_contr * card)
754 for (i = 0; i < card->nbchan; i++) {
755 if (card->bchans[i].plcip == 0) {
756 card->bchans[i].disconnecting = 0;
763 /* ------------------------------------------------------------------- */
765 static void handle_controller(_cmsg * cmsg)
767 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
770 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
771 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
772 cmsg->adr.adrController & 0x7f);
775 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
777 case CAPI_LISTEN_CONF: /* Controller */
779 printk(KERN_DEBUG "capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n",
780 card->contrnr, cmsg->Info, capi_info2str(cmsg->Info), card->cipmask);
782 listen_change_state(card, EV_LISTEN_CONF_ERROR);
783 } else if (card->cipmask == 0) {
784 listen_change_state(card, EV_LISTEN_CONF_EMPTY);
786 listen_change_state(card, EV_LISTEN_CONF_OK);
790 case CAPI_MANUFACTURER_IND: /* Controller */
791 if ( cmsg->ManuID == 0x214D5641
793 && cmsg->Function == 1) {
794 u8 *data = cmsg->ManuData+3;
795 u16 len = cmsg->ManuData[0];
799 len = (cmsg->ManuData[1] | (cmsg->ManuData[2] << 8));
803 layer = ((*(data-1)) << 8) | *(data-2);
805 direction = (layer & 0x200) ? 0 : 1;
806 else direction = (layer & 0x800) ? 0 : 1;
807 if (layer & 0x0C00) {
808 if ((layer & 0xff) == 0x80) {
809 handle_dtrace_data(card, direction, 1, data, len);
812 } else if ((layer & 0xff) < 0x80) {
813 handle_dtrace_data(card, direction, 0, data, len);
816 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n",
818 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
819 cmsg->adr.adrController, layer);
823 case CAPI_MANUFACTURER_CONF: /* Controller */
824 if (cmsg->ManuID == 0x214D5641) {
826 switch (cmsg->Class) {
828 case 1: s = "unknown class"; break;
829 case 2: s = "unknown function"; break;
830 default: s = "unkown error"; break;
833 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x function %d: %s\n",
835 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
836 cmsg->adr.adrController,
841 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
843 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
845 case CAPI_INFO_IND: /* Controller/plci */
847 case CAPI_INFO_CONF: /* Controller/plci */
851 printk(KERN_ERR "capidrv-%d: got %s from controller 0x%x ???",
853 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
854 cmsg->adr.adrController);
859 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x ignored\n",
861 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
862 cmsg->adr.adrController);
865 static void handle_incoming_call(capidrv_contr * card, _cmsg * cmsg)
868 capidrv_bchan *bchan;
872 if ((chan = new_bchan(card)) == -1) {
873 printk(KERN_ERR "capidrv-%d: incoming call on not existing bchan ?\n", card->contrnr);
876 bchan = &card->bchans[chan];
877 if ((plcip = new_plci(card, chan)) == 0) {
878 printk(KERN_ERR "capidrv-%d: incoming call: no memory, sorry.\n", card->contrnr);
882 plcip->plci = cmsg->adr.adrPLCI;
883 plci_change_state(card, plcip, EV_PLCI_CONNECT_IND);
885 cmd.command = ISDN_STAT_ICALL;
886 cmd.driver = card->myid;
888 memset(&cmd.parm.setup, 0, sizeof(cmd.parm.setup));
889 strncpy(cmd.parm.setup.phone,
890 cmsg->CallingPartyNumber + 3,
891 cmsg->CallingPartyNumber[0] - 2);
892 strncpy(cmd.parm.setup.eazmsn,
893 cmsg->CalledPartyNumber + 2,
894 cmsg->CalledPartyNumber[0] - 1);
895 cmd.parm.setup.si1 = cip2si1(cmsg->CIPValue);
896 cmd.parm.setup.si2 = cip2si2(cmsg->CIPValue);
897 cmd.parm.setup.plan = cmsg->CallingPartyNumber[1];
898 cmd.parm.setup.screen = cmsg->CallingPartyNumber[2];
900 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s\n",
902 cmd.parm.setup.phone,
905 cmd.parm.setup.eazmsn);
907 if (cmd.parm.setup.si1 == 1 && cmd.parm.setup.si2 != 0) {
908 printk(KERN_INFO "capidrv-%d: patching si2=%d to 0 for VBOX\n",
911 cmd.parm.setup.si2 = 0;
914 switch (card->interface.statcallb(&cmd)) {
917 /* No device matching this call.
918 * and isdn_common.c has send a HANGUP command
919 * which is ignored in state ST_PLCI_INCOMING,
920 * so we send RESP to ignore the call
922 capi_cmsg_answer(cmsg);
923 cmsg->Reject = 1; /* ignore */
924 send_message(card, cmsg);
925 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
926 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n",
928 cmd.parm.setup.phone,
931 cmd.parm.setup.eazmsn);
934 /* At least one device matching this call (RING on ttyI)
935 * HL-driver may send ALERTING on the D-channel in this
937 * really means: RING on ttyI or a net interface
938 * accepted this call already.
940 * If the call was accepted, state has already changed,
941 * and CONNECT_RESP already sent.
943 if (plcip->state == ST_PLCI_INCOMING) {
944 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n",
946 cmd.parm.setup.phone,
949 cmd.parm.setup.eazmsn);
950 capi_fill_ALERT_REQ(cmsg,
953 plcip->plci, /* adr */
954 NULL,/* BChannelinformation */
955 NULL,/* Keypadfacility */
956 NULL,/* Useruserdata */
957 NULL /* Facilitydataarray */
959 plcip->msgid = cmsg->Messagenumber;
960 send_message(card, cmsg);
962 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s on netdev\n",
964 cmd.parm.setup.phone,
967 cmd.parm.setup.eazmsn);
971 case 2: /* Call will be rejected. */
972 capi_cmsg_answer(cmsg);
973 cmsg->Reject = 2; /* reject call, normal call clearing */
974 send_message(card, cmsg);
975 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
979 /* An error happened. (Invalid parameters for example.) */
980 capi_cmsg_answer(cmsg);
981 cmsg->Reject = 8; /* reject call,
982 destination out of order */
983 send_message(card, cmsg);
984 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT);
990 static void handle_plci(_cmsg * cmsg)
992 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
997 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
998 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
999 cmsg->adr.adrController & 0x7f);
1002 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
1004 case CAPI_DISCONNECT_IND: /* plci */
1006 printk(KERN_INFO "capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n",
1008 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1009 cmsg->Reason, capi_info2str(cmsg->Reason), cmsg->adr.adrPLCI);
1011 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) {
1012 capi_cmsg_answer(cmsg);
1013 send_message(card, cmsg);
1016 card->bchans[plcip->chan].disconnecting = 1;
1017 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_IND);
1018 capi_cmsg_answer(cmsg);
1019 send_message(card, cmsg);
1020 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_RESP);
1023 case CAPI_DISCONNECT_CONF: /* plci */
1025 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1027 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1028 cmsg->Info, capi_info2str(cmsg->Info),
1031 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1034 card->bchans[plcip->chan].disconnecting = 1;
1037 case CAPI_ALERT_CONF: /* plci */
1039 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1041 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1042 cmsg->Info, capi_info2str(cmsg->Info),
1047 case CAPI_CONNECT_IND: /* plci */
1048 handle_incoming_call(card, cmsg);
1051 case CAPI_CONNECT_CONF: /* plci */
1053 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n",
1055 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1056 cmsg->Info, capi_info2str(cmsg->Info),
1059 if (!(plcip = find_plci_by_msgid(card, cmsg->Messagenumber)))
1062 plcip->plci = cmsg->adr.adrPLCI;
1064 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_ERROR);
1066 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_OK);
1070 case CAPI_CONNECT_ACTIVE_IND: /* plci */
1072 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1075 if (card->bchans[plcip->chan].incoming) {
1076 capi_cmsg_answer(cmsg);
1077 send_message(card, cmsg);
1078 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1080 capidrv_ncci *nccip;
1081 capi_cmsg_answer(cmsg);
1082 send_message(card, cmsg);
1084 nccip = new_ncci(card, plcip, cmsg->adr.adrPLCI);
1087 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
1090 capi_fill_CONNECT_B3_REQ(cmsg,
1093 plcip->plci, /* adr */
1096 nccip->msgid = cmsg->Messagenumber;
1097 send_message(card, cmsg);
1098 cmd.command = ISDN_STAT_DCONN;
1099 cmd.driver = card->myid;
1100 cmd.arg = plcip->chan;
1101 card->interface.statcallb(&cmd);
1102 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND);
1103 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_REQ);
1107 case CAPI_INFO_IND: /* Controller/plci */
1109 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI)))
1112 if (cmsg->InfoNumber == 0x4000) {
1113 if (cmsg->InfoElement[0] == 4) {
1114 cmd.command = ISDN_STAT_CINF;
1115 cmd.driver = card->myid;
1116 cmd.arg = plcip->chan;
1117 sprintf(cmd.parm.num, "%lu",
1119 ((u32) cmsg->InfoElement[1]
1120 | ((u32) (cmsg->InfoElement[2]) << 8)
1121 | ((u32) (cmsg->InfoElement[3]) << 16)
1122 | ((u32) (cmsg->InfoElement[4]) << 24)));
1123 card->interface.statcallb(&cmd);
1127 printk(KERN_ERR "capidrv-%d: %s\n",
1128 card->contrnr, capi_cmsg2str(cmsg));
1131 case CAPI_CONNECT_ACTIVE_CONF: /* plci */
1133 case CAPI_SELECT_B_PROTOCOL_CONF: /* plci */
1135 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1137 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1140 case CAPI_INFO_CONF: /* Controller/plci */
1144 printk(KERN_ERR "capidrv-%d: got %s for plci 0x%x ???",
1146 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1151 printk(KERN_INFO "capidrv-%d: %s for plci 0x%x ignored\n",
1153 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1157 printk(KERN_ERR "capidrv-%d: %s: plci 0x%x not found\n",
1159 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1164 static void handle_ncci(_cmsg * cmsg)
1166 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1167 capidrv_plci *plcip;
1168 capidrv_ncci *nccip;
1173 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1174 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1175 cmsg->adr.adrController & 0x7f);
1178 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) {
1180 case CAPI_CONNECT_B3_ACTIVE_IND: /* ncci */
1181 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1184 capi_cmsg_answer(cmsg);
1185 send_message(card, cmsg);
1186 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND);
1188 cmd.command = ISDN_STAT_BCONN;
1189 cmd.driver = card->myid;
1190 cmd.arg = nccip->chan;
1191 card->interface.statcallb(&cmd);
1193 printk(KERN_INFO "capidrv-%d: chan %d up with ncci 0x%x\n",
1194 card->contrnr, nccip->chan, nccip->ncci);
1197 case CAPI_CONNECT_B3_ACTIVE_CONF: /* ncci */
1200 case CAPI_CONNECT_B3_IND: /* ncci */
1202 plcip = find_plci_by_ncci(card, cmsg->adr.adrNCCI);
1204 nccip = new_ncci(card, plcip, cmsg->adr.adrNCCI);
1206 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_IND);
1207 capi_fill_CONNECT_B3_RESP(cmsg,
1210 nccip->ncci, /* adr */
1214 send_message(card, cmsg);
1215 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP);
1218 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr);
1220 printk(KERN_ERR "capidrv-%d: %s: plci for ncci 0x%x not found\n",
1222 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1225 capi_fill_CONNECT_B3_RESP(cmsg,
1232 send_message(card, cmsg);
1235 case CAPI_CONNECT_B3_CONF: /* ncci */
1237 if (!(nccip = find_ncci_by_msgid(card,
1239 cmsg->Messagenumber)))
1242 nccip->ncci = cmsg->adr.adrNCCI;
1244 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1246 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1247 cmsg->Info, capi_info2str(cmsg->Info),
1252 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_ERROR);
1254 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_OK);
1257 case CAPI_CONNECT_B3_T90_ACTIVE_IND: /* ncci */
1258 capi_cmsg_answer(cmsg);
1259 send_message(card, cmsg);
1262 case CAPI_DATA_B3_IND: /* ncci */
1263 /* handled in handle_data() */
1266 case CAPI_DATA_B3_CONF: /* ncci */
1268 printk(KERN_WARNING "CAPI_DATA_B3_CONF: Info %x - %s\n",
1269 cmsg->Info, capi_info2str(cmsg->Info));
1271 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1274 len = capidrv_del_ack(nccip, cmsg->DataHandle);
1277 cmd.command = ISDN_STAT_BSENT;
1278 cmd.driver = card->myid;
1279 cmd.arg = nccip->chan;
1280 cmd.parm.length = len;
1281 card->interface.statcallb(&cmd);
1284 case CAPI_DISCONNECT_B3_IND: /* ncci */
1285 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1288 card->bchans[nccip->chan].disconnecting = 1;
1289 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND);
1290 capi_cmsg_answer(cmsg);
1291 send_message(card, cmsg);
1292 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP);
1295 case CAPI_DISCONNECT_B3_CONF: /* ncci */
1296 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1299 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n",
1301 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1302 cmsg->Info, capi_info2str(cmsg->Info),
1304 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_CONF_ERROR);
1308 case CAPI_RESET_B3_IND: /* ncci */
1309 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI)))
1311 ncci_change_state(card, nccip, EV_NCCI_RESET_B3_IND);
1312 capi_cmsg_answer(cmsg);
1313 send_message(card, cmsg);
1316 case CAPI_RESET_B3_CONF: /* ncci */
1317 goto ignored; /* $$$$ */
1319 case CAPI_FACILITY_IND: /* Controller/plci/ncci */
1321 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */
1325 printk(KERN_ERR "capidrv-%d: got %s for ncci 0x%x ???",
1327 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1332 printk(KERN_INFO "capidrv-%d: %s for ncci 0x%x ignored\n",
1334 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1338 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1340 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1345 static void handle_data(_cmsg * cmsg, struct sk_buff *skb)
1347 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f);
1348 capidrv_ncci *nccip;
1351 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n",
1352 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1353 cmsg->adr.adrController & 0x7f);
1357 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) {
1358 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n",
1360 capi_cmd2str(cmsg->Command, cmsg->Subcommand),
1365 (void) skb_pull(skb, CAPIMSG_LEN(skb->data));
1366 card->interface.rcvcallb_skb(card->myid, nccip->chan, skb);
1367 capi_cmsg_answer(cmsg);
1368 send_message(card, cmsg);
1371 static _cmsg s_cmsg;
1373 static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
1375 capi_message2cmsg(&s_cmsg, skb->data);
1377 printk(KERN_DEBUG "capidrv_signal: applid=%d %s\n",
1378 ap->applid, capi_cmsg2str(&s_cmsg));
1380 if (s_cmsg.Command == CAPI_DATA_B3
1381 && s_cmsg.Subcommand == CAPI_IND) {
1382 handle_data(&s_cmsg, skb);
1385 if ((s_cmsg.adr.adrController & 0xffffff00) == 0)
1386 handle_controller(&s_cmsg);
1387 else if ((s_cmsg.adr.adrPLCI & 0xffff0000) == 0)
1388 handle_plci(&s_cmsg);
1390 handle_ncci(&s_cmsg);
1392 * data of skb used in s_cmsg,
1393 * free data when s_cmsg is not used again
1394 * thanks to Lars Heete <hel@admin.de>
1399 /* ------------------------------------------------------------------- */
1401 #define PUTBYTE_TO_STATUS(card, byte) \
1403 *(card)->q931_write++ = (byte); \
1404 if ((card)->q931_write > (card)->q931_end) \
1405 (card)->q931_write = (card)->q931_buf; \
1408 static void handle_dtrace_data(capidrv_contr *card,
1409 int send, int level2, u8 *data, u16 len)
1415 printk(KERN_DEBUG "capidrv-%d: avmb1_q931_data: len == %d\n",
1416 card->contrnr, len);
1421 PUTBYTE_TO_STATUS(card, 'D');
1422 PUTBYTE_TO_STATUS(card, '2');
1423 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1424 PUTBYTE_TO_STATUS(card, ':');
1426 PUTBYTE_TO_STATUS(card, 'D');
1427 PUTBYTE_TO_STATUS(card, '3');
1428 PUTBYTE_TO_STATUS(card, send ? '>' : '<');
1429 PUTBYTE_TO_STATUS(card, ':');
1432 for (p = data, end = data+len; p < end; p++) {
1434 PUTBYTE_TO_STATUS(card, ' ');
1435 w = (*p >> 4) & 0xf;
1436 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1438 PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
1440 PUTBYTE_TO_STATUS(card, '\n');
1442 cmd.command = ISDN_STAT_STAVAIL;
1443 cmd.driver = card->myid;
1445 card->interface.statcallb(&cmd);
1448 /* ------------------------------------------------------------------- */
1450 static _cmsg cmdcmsg;
1452 static int capidrv_ioctl(isdn_ctrl * c, capidrv_contr * card)
1456 debugmode = (int)(*((unsigned int *)c->parm.num));
1457 printk(KERN_DEBUG "capidrv-%d: debugmode=%d\n",
1458 card->contrnr, debugmode);
1461 printk(KERN_DEBUG "capidrv-%d: capidrv_ioctl(%ld) called ??\n",
1462 card->contrnr, c->arg);
1469 * Handle leased lines (CAPI-Bundling)
1472 struct internal_bchannelinfo {
1473 unsigned short channelalloc;
1474 unsigned short operation;
1475 unsigned char cmask[31];
1478 static int decodeFVteln(char *teln, unsigned long *bmaskp, int *activep)
1480 unsigned long bmask = 0;
1485 if (strncmp(teln, "FV:", 3) != 0)
1488 while (*s && *s == ' ') s++;
1490 if (*s == 'p' || *s == 'P') {
1494 if (*s == 'a' || *s == 'A') {
1501 if (!isdigit(*s)) return -3;
1502 while (isdigit(*s)) { digit1 = digit1*10 + (*s - '0'); s++; }
1503 if (digit1 <= 0 && digit1 > 30) return -4;
1504 if (*s == 0 || *s == ',' || *s == ' ') {
1505 bmask |= (1 << digit1);
1510 if (*s != '-') return -5;
1512 if (!isdigit(*s)) return -3;
1513 while (isdigit(*s)) { digit2 = digit2*10 + (*s - '0'); s++; }
1514 if (digit2 <= 0 && digit2 > 30) return -4;
1515 if (*s == 0 || *s == ',' || *s == ' ') {
1516 if (digit1 > digit2)
1517 for (i = digit2; i <= digit1 ; i++)
1520 for (i = digit1; i <= digit2 ; i++)
1522 digit1 = digit2 = 0;
1528 if (activep) *activep = active;
1529 if (bmaskp) *bmaskp = bmask;
1533 static int FVteln2capi20(char *teln, u8 AdditionalInfo[1+2+2+31])
1535 unsigned long bmask;
1539 rc = decodeFVteln(teln, &bmask, &active);
1542 AdditionalInfo[0] = 2+2+31;
1543 /* Channel: 3 => use channel allocation */
1544 AdditionalInfo[1] = 3; AdditionalInfo[2] = 0;
1545 /* Operation: 0 => DTE mode, 1 => DCE mode */
1547 AdditionalInfo[3] = 0; AdditionalInfo[4] = 0;
1549 AdditionalInfo[3] = 1; AdditionalInfo[4] = 0;
1551 /* Channel mask array */
1552 AdditionalInfo[5] = 0; /* no D-Channel */
1553 for (i=1; i <= 30; i++)
1554 AdditionalInfo[5+i] = (bmask & (1 << i)) ? 0xff : 0;
1558 static int capidrv_command(isdn_ctrl * c, capidrv_contr * card)
1561 struct capidrv_bchan *bchan;
1562 struct capidrv_plci *plcip;
1563 u8 AdditionalInfo[1+2+2+31];
1564 int rc, isleasedline = 0;
1566 if (c->command == ISDN_CMD_IOCTL)
1567 return capidrv_ioctl(c, card);
1569 switch (c->command) {
1570 case ISDN_CMD_DIAL:{
1571 u8 calling[ISDN_MSNLEN + 3];
1572 u8 called[ISDN_MSNLEN + 2];
1575 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n",
1578 c->parm.setup.phone,
1581 c->parm.setup.eazmsn);
1583 bchan = &card->bchans[c->arg % card->nbchan];
1586 printk(KERN_ERR "capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n",
1589 c->parm.setup.phone,
1592 c->parm.setup.eazmsn,
1593 bchan->plcip->plci);
1596 bchan->si1 = c->parm.setup.si1;
1597 bchan->si2 = c->parm.setup.si2;
1599 strncpy(bchan->num, c->parm.setup.phone, sizeof(bchan->num));
1600 strncpy(bchan->mynum, c->parm.setup.eazmsn, sizeof(bchan->mynum));
1601 rc = FVteln2capi20(bchan->num, AdditionalInfo);
1602 isleasedline = (rc == 0);
1604 printk(KERN_ERR "capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card->contrnr, bchan->num);
1610 printk(KERN_DEBUG "capidrv-%d: connecting leased line\n", card->contrnr);
1612 calling[0] = strlen(bchan->mynum) + 2;
1615 strncpy(calling + 3, bchan->mynum, ISDN_MSNLEN);
1616 called[0] = strlen(bchan->num) + 1;
1618 strncpy(called + 2, bchan->num, ISDN_MSNLEN);
1621 capi_fill_CONNECT_REQ(&cmdcmsg,
1624 card->contrnr, /* adr */
1625 si2cip(bchan->si1, bchan->si2), /* cipvalue */
1626 called, /* CalledPartyNumber */
1627 calling, /* CallingPartyNumber */
1628 NULL, /* CalledPartySubaddress */
1629 NULL, /* CallingPartySubaddress */
1630 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1631 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1632 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1633 b1config(bchan->l2, bchan->l3), /* B1configuration */
1634 NULL, /* B2configuration */
1635 NULL, /* B3configuration */
1639 /* BChannelinformation */
1640 isleasedline ? AdditionalInfo : NULL,
1641 NULL, /* Keypadfacility */
1642 NULL, /* Useruserdata */
1643 NULL /* Facilitydataarray */
1645 if ((plcip = new_plci(card, (c->arg % card->nbchan))) == 0) {
1646 cmd.command = ISDN_STAT_DHUP;
1647 cmd.driver = card->myid;
1648 cmd.arg = (c->arg % card->nbchan);
1649 card->interface.statcallb(&cmd);
1652 plcip->msgid = cmdcmsg.Messagenumber;
1653 plcip->leasedline = isleasedline;
1654 plci_change_state(card, plcip, EV_PLCI_CONNECT_REQ);
1655 send_message(card, &cmdcmsg);
1659 case ISDN_CMD_ACCEPTD:
1661 bchan = &card->bchans[c->arg % card->nbchan];
1663 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n",
1665 c->arg, bchan->l2, bchan->l3);
1667 capi_fill_CONNECT_RESP(&cmdcmsg,
1670 bchan->plcip->plci, /* adr */
1672 b1prot(bchan->l2, bchan->l3), /* B1protocol */
1673 b2prot(bchan->l2, bchan->l3), /* B2protocol */
1674 b3prot(bchan->l2, bchan->l3), /* B3protocol */
1675 b1config(bchan->l2, bchan->l3), /* B1configuration */
1676 NULL, /* B2configuration */
1677 NULL, /* B3configuration */
1678 NULL, /* ConnectedNumber */
1679 NULL, /* ConnectedSubaddress */
1681 NULL, /* BChannelinformation */
1682 NULL, /* Keypadfacility */
1683 NULL, /* Useruserdata */
1684 NULL /* Facilitydataarray */
1686 capi_cmsg2message(&cmdcmsg, cmdcmsg.buf);
1687 plci_change_state(card, bchan->plcip, EV_PLCI_CONNECT_RESP);
1688 send_message(card, &cmdcmsg);
1691 case ISDN_CMD_ACCEPTB:
1693 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n",
1698 case ISDN_CMD_HANGUP:
1700 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n",
1703 bchan = &card->bchans[c->arg % card->nbchan];
1705 if (bchan->disconnecting) {
1707 printk(KERN_DEBUG "capidrv-%d: chan %ld already disconnecting ...\n",
1713 bchan->disconnecting = 1;
1714 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg,
1720 ncci_change_state(card, bchan->nccip, EV_NCCI_DISCONNECT_B3_REQ);
1721 send_message(card, &cmdcmsg);
1723 } else if (bchan->plcip) {
1724 if (bchan->plcip->state == ST_PLCI_INCOMING) {
1726 * just ignore, we a called from
1727 * isdn_status_callback(),
1728 * which will return 0 or 2, this is handled
1729 * by the CONNECT_IND handler
1731 bchan->disconnecting = 1;
1733 } else if (bchan->plcip->plci) {
1734 bchan->disconnecting = 1;
1735 capi_fill_DISCONNECT_REQ(&cmdcmsg,
1739 NULL, /* BChannelinformation */
1740 NULL, /* Keypadfacility */
1741 NULL, /* Useruserdata */
1742 NULL /* Facilitydataarray */
1744 plci_change_state(card, bchan->plcip, EV_PLCI_DISCONNECT_REQ);
1745 send_message(card, &cmdcmsg);
1748 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n",
1754 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request on free channel\n",
1760 case ISDN_CMD_SETL2:
1762 printk(KERN_DEBUG "capidrv-%d: set L2 on chan %ld to %ld\n",
1764 (c->arg & 0xff), (c->arg >> 8));
1765 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1766 bchan->l2 = (c->arg >> 8);
1769 case ISDN_CMD_SETL3:
1771 printk(KERN_DEBUG "capidrv-%d: set L3 on chan %ld to %ld\n",
1773 (c->arg & 0xff), (c->arg >> 8));
1774 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan];
1775 bchan->l3 = (c->arg >> 8);
1778 case ISDN_CMD_SETEAZ:
1780 printk(KERN_DEBUG "capidrv-%d: set EAZ \"%s\" on chan %ld\n",
1782 c->parm.num, c->arg);
1783 bchan = &card->bchans[c->arg % card->nbchan];
1784 strncpy(bchan->msn, c->parm.num, ISDN_MSNLEN);
1787 case ISDN_CMD_CLREAZ:
1789 printk(KERN_DEBUG "capidrv-%d: clearing EAZ on chan %ld\n",
1790 card->contrnr, c->arg);
1791 bchan = &card->bchans[c->arg % card->nbchan];
1796 printk(KERN_ERR "capidrv-%d: ISDN_CMD_%d, Huh?\n",
1797 card->contrnr, c->command);
1803 static int if_command(isdn_ctrl * c)
1805 capidrv_contr *card = findcontrbydriverid(c->driver);
1808 return capidrv_command(c, card);
1811 "capidrv: if_command %d called with invalid driverId %d!\n",
1812 c->command, c->driver);
1816 static _cmsg sendcmsg;
1818 static int if_sendbuf(int id, int channel, int doack, struct sk_buff *skb)
1820 capidrv_contr *card = findcontrbydriverid(id);
1821 capidrv_bchan *bchan;
1822 capidrv_ncci *nccip;
1829 printk(KERN_ERR "capidrv: if_sendbuf called with invalid driverId %d!\n",
1834 printk(KERN_DEBUG "capidrv-%d: sendbuf len=%d skb=%p doack=%d\n",
1835 card->contrnr, len, skb, doack);
1836 bchan = &card->bchans[channel % card->nbchan];
1837 nccip = bchan->nccip;
1838 if (!nccip || nccip->state != ST_NCCI_ACTIVE) {
1839 printk(KERN_ERR "capidrv-%d: if_sendbuf: %s:%d: chan not up!\n",
1840 card->contrnr, card->name, channel);
1843 datahandle = nccip->datahandle;
1844 capi_fill_DATA_B3_REQ(&sendcmsg, global.ap.applid, card->msgid++,
1845 nccip->ncci, /* adr */
1846 (u32) skb->data, /* Data */
1847 skb->len, /* DataLength */
1848 datahandle, /* DataHandle */
1852 if (capidrv_add_ack(nccip, datahandle, doack ? (int)skb->len : -1) < 0)
1855 capi_cmsg2message(&sendcmsg, sendcmsg.buf);
1856 msglen = CAPIMSG_LEN(sendcmsg.buf);
1857 if (skb_headroom(skb) < msglen) {
1858 struct sk_buff *nskb = skb_realloc_headroom(skb, msglen);
1860 printk(KERN_ERR "capidrv-%d: if_sendbuf: no memory\n",
1862 (void)capidrv_del_ack(nccip, datahandle);
1865 printk(KERN_DEBUG "capidrv-%d: only %d bytes headroom, need %d\n",
1866 card->contrnr, skb_headroom(skb), msglen);
1867 memcpy(skb_push(nskb, msglen), sendcmsg.buf, msglen);
1868 errcode = capi20_put_message(&global.ap, nskb);
1869 if (errcode == CAPI_NOERROR) {
1871 nccip->datahandle++;
1875 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1876 card->contrnr, errcode, capi_info2str(errcode));
1877 (void)capidrv_del_ack(nccip, datahandle);
1878 dev_kfree_skb(nskb);
1879 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1881 memcpy(skb_push(skb, msglen), sendcmsg.buf, msglen);
1882 errcode = capi20_put_message(&global.ap, skb);
1883 if (errcode == CAPI_NOERROR) {
1884 nccip->datahandle++;
1888 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n",
1889 card->contrnr, errcode, capi_info2str(errcode));
1890 skb_pull(skb, msglen);
1891 (void)capidrv_del_ack(nccip, datahandle);
1892 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1;
1896 static int if_readstat(u8 __user *buf, int len, int id, int channel)
1898 capidrv_contr *card = findcontrbydriverid(id);
1903 printk(KERN_ERR "capidrv: if_readstat called with invalid driverId %d!\n",
1908 for (p=buf, count=0; count < len; p++, count++) {
1909 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 = (capidrv_contr *) kmalloc(sizeof(capidrv_contr), GFP_ATOMIC))) {
2008 "capidrv: (%s) Could not allocate contr-struct.\n", id);
2011 memset(card, 0, sizeof(capidrv_contr));
2012 card->owner = THIS_MODULE;
2013 init_timer(&card->listentimer);
2014 strcpy(card->name, id);
2015 card->contrnr = contr;
2016 card->nbchan = profp->nbchannel;
2017 card->bchans = (capidrv_bchan *) kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC);
2018 if (!card->bchans) {
2020 "capidrv: (%s) Could not allocate bchan-structs.\n", id);
2021 module_put(card->owner);
2025 card->interface.channels = profp->nbchannel;
2026 card->interface.maxbufsize = 2048;
2027 card->interface.command = if_command;
2028 card->interface.writebuf_skb = if_sendbuf;
2029 card->interface.writecmd = NULL;
2030 card->interface.readstat = if_readstat;
2031 card->interface.features = ISDN_FEATURE_L2_HDLC |
2032 ISDN_FEATURE_L2_TRANS |
2033 ISDN_FEATURE_L3_TRANS |
2034 ISDN_FEATURE_P_UNKNOWN |
2035 ISDN_FEATURE_L2_X75I |
2036 ISDN_FEATURE_L2_X75UI |
2037 ISDN_FEATURE_L2_X75BUI;
2038 if (profp->support1 & (1<<2))
2039 card->interface.features |= ISDN_FEATURE_L2_V11096 |
2040 ISDN_FEATURE_L2_V11019 |
2041 ISDN_FEATURE_L2_V11038;
2042 if (profp->support1 & (1<<8))
2043 card->interface.features |= ISDN_FEATURE_L2_MODEM;
2044 card->interface.hl_hdrlen = 22; /* len of DATA_B3_REQ */
2045 strncpy(card->interface.id, id, sizeof(card->interface.id) - 1);
2048 card->q931_read = card->q931_buf;
2049 card->q931_write = card->q931_buf;
2050 card->q931_end = card->q931_buf + sizeof(card->q931_buf) - 1;
2052 if (!register_isdn(&card->interface)) {
2053 printk(KERN_ERR "capidrv: Unable to register contr %s\n", id);
2054 kfree(card->bchans);
2055 module_put(card->owner);
2059 card->myid = card->interface.channels;
2061 spin_lock_irqsave(&global_lock, flags);
2062 card->next = global.contr_list;
2063 global.contr_list = card;
2065 spin_unlock_irqrestore(&global_lock, flags);
2067 memset(card->bchans, 0, sizeof(capidrv_bchan) * card->nbchan);
2068 for (i = 0; i < card->nbchan; i++) {
2069 card->bchans[i].contr = card;
2072 cmd.command = ISDN_STAT_RUN;
2073 cmd.driver = card->myid;
2074 card->interface.statcallb(&cmd);
2076 card->cipmask = 0x1FFF03FF; /* any */
2081 card->listentimer.data = (unsigned long)card;
2082 card->listentimer.function = listentimerfunc;
2083 mod_timer(&card->listentimer, jiffies + 60*HZ);
2085 printk(KERN_INFO "%s: now up (%d B channels)\n",
2086 card->name, card->nbchan);
2088 enable_dchannel_trace(card);
2093 static int capidrv_delcontr(u16 contr)
2095 capidrv_contr **pp, *card;
2096 unsigned long flags;
2099 spin_lock_irqsave(&global_lock, flags);
2100 for (card = global.contr_list; card; card = card->next) {
2101 if (card->contrnr == contr)
2105 spin_unlock_irqrestore(&global_lock, flags);
2106 printk(KERN_ERR "capidrv: delcontr: no contr %u\n", contr);
2109 #warning FIXME: maybe a race condition the card should be removed here from global list /kkeil
2110 spin_unlock_irqrestore(&global_lock, flags);
2112 del_timer(&card->listentimer);
2115 printk(KERN_DEBUG "capidrv-%d: id=%d unloading\n",
2116 card->contrnr, card->myid);
2118 cmd.command = ISDN_STAT_STOP;
2119 cmd.driver = card->myid;
2120 card->interface.statcallb(&cmd);
2122 while (card->nbchan) {
2124 cmd.command = ISDN_STAT_DISCH;
2125 cmd.driver = card->myid;
2126 cmd.arg = card->nbchan-1;
2127 cmd.parm.num[0] = 0;
2129 printk(KERN_DEBUG "capidrv-%d: id=%d disable chan=%ld\n",
2130 card->contrnr, card->myid, cmd.arg);
2131 card->interface.statcallb(&cmd);
2133 if (card->bchans[card->nbchan-1].nccip)
2134 free_ncci(card, card->bchans[card->nbchan-1].nccip);
2135 if (card->bchans[card->nbchan-1].plcip)
2136 free_plci(card, card->bchans[card->nbchan-1].plcip);
2137 if (card->plci_list)
2138 printk(KERN_ERR "capidrv: bug in free_plci()\n");
2141 kfree(card->bchans);
2142 card->bchans = NULL;
2145 printk(KERN_DEBUG "capidrv-%d: id=%d isdn unload\n",
2146 card->contrnr, card->myid);
2148 cmd.command = ISDN_STAT_UNLOAD;
2149 cmd.driver = card->myid;
2150 card->interface.statcallb(&cmd);
2153 printk(KERN_DEBUG "capidrv-%d: id=%d remove contr from list\n",
2154 card->contrnr, card->myid);
2156 spin_lock_irqsave(&global_lock, flags);
2157 for (pp = &global.contr_list; *pp; pp = &(*pp)->next) {
2165 spin_unlock_irqrestore(&global_lock, flags);
2167 module_put(card->owner);
2168 printk(KERN_INFO "%s: now down.\n", card->name);
2174 static void lower_callback(unsigned int cmd, u32 contr, void *data)
2179 printk(KERN_INFO "capidrv: controller %hu up\n", contr);
2180 (void) capidrv_addcontr(contr, (capi_profile *) data);
2183 printk(KERN_INFO "capidrv: controller %hu down\n", contr);
2184 (void) capidrv_delcontr(contr);
2190 * /proc/capi/capidrv:
2191 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
2193 static int proc_capidrv_read_proc(char *page, char **start, off_t off,
2194 int count, int *eof, void *data)
2198 len += sprintf(page+len, "%lu %lu %lu %lu\n",
2199 global.ap.nrecvctlpkt,
2200 global.ap.nrecvdatapkt,
2201 global.ap.nsentctlpkt,
2202 global.ap.nsentdatapkt);
2203 if (off+count >= len)
2207 *start = page + off;
2208 return ((count < len-off) ? count : len-off);
2211 static struct procfsentries {
2214 int (*read_proc)(char *page, char **start, off_t off,
2215 int count, int *eof, void *data);
2216 struct proc_dir_entry *procent;
2217 } procfsentries[] = {
2218 /* { "capi", S_IFDIR, 0 }, */
2219 { "capi/capidrv", 0 , proc_capidrv_read_proc },
2222 static void __init proc_init(void)
2224 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2227 for (i=0; i < nelem; i++) {
2228 struct procfsentries *p = procfsentries + i;
2229 p->procent = create_proc_entry(p->name, p->mode, NULL);
2230 if (p->procent) p->procent->read_proc = p->read_proc;
2234 static void __exit proc_exit(void)
2236 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
2239 for (i=nelem-1; i >= 0; i--) {
2240 struct procfsentries *p = procfsentries + i;
2242 remove_proc_entry(p->name, NULL);
2248 static int __init capidrv_init(void)
2250 capi_profile profile;
2256 if ((p = strchr(revision, ':')) != 0 && p[1]) {
2257 strncpy(rev, p + 2, sizeof(rev));
2258 rev[sizeof(rev)-1] = 0;
2259 if ((p = strchr(rev, '$')) != 0 && p > rev)
2264 global.ap.rparam.level3cnt = -2; /* number of bchannels twice */
2265 global.ap.rparam.datablkcnt = 16;
2266 global.ap.rparam.datablklen = 2048;
2268 global.ap.recv_message = capidrv_recv_message;
2269 errcode = capi20_register(&global.ap);
2274 capi20_set_callback(&global.ap, lower_callback);
2276 errcode = capi20_get_profile(0, &profile);
2277 if (errcode != CAPI_NOERROR) {
2278 capi20_release(&global.ap);
2282 ncontr = profile.ncontroller;
2283 for (contr = 1; contr <= ncontr; contr++) {
2284 errcode = capi20_get_profile(contr, &profile);
2285 if (errcode != CAPI_NOERROR)
2287 (void) capidrv_addcontr(contr, &profile);
2291 printk(KERN_NOTICE "capidrv: Rev %s: loaded\n", rev);
2295 static void __exit capidrv_exit(void)
2300 if ((p = strchr(revision, ':')) != 0) {
2302 p = strchr(rev, '$');
2305 strcpy(rev, " ??? ");
2308 capi20_release(&global.ap);
2312 printk(KERN_NOTICE "capidrv: Rev%s: unloaded\n", rev);
2315 module_init(capidrv_init);
2316 module_exit(capidrv_exit);