Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.16 2522 lines 71 kB view raw
1/* $Id: capidrv.c,v 1.1.2.2 2004/01/12 23:17:24 keil Exp $ 2 * 3 * ISDN4Linux Driver, using capi20 interface (kernelcapi) 4 * 5 * Copyright 1997 by Carsten Paeth <calle@calle.de> 6 * 7 * This software may be used and distributed according to the terms 8 * of the GNU General Public License, incorporated herein by reference. 9 * 10 */ 11 12#include <linux/module.h> 13#include <linux/errno.h> 14#include <linux/kernel.h> 15#include <linux/major.h> 16#include <linux/slab.h> 17#include <linux/fcntl.h> 18#include <linux/fs.h> 19#include <linux/signal.h> 20#include <linux/mm.h> 21#include <linux/timer.h> 22#include <linux/wait.h> 23#include <linux/skbuff.h> 24#include <linux/isdn.h> 25#include <linux/isdnif.h> 26#include <linux/proc_fs.h> 27#include <linux/seq_file.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> 33 34#include <linux/isdn/capiutil.h> 35#include <linux/isdn/capicmd.h> 36#include "capidrv.h" 37 38static int debugmode = 0; 39 40MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux"); 41MODULE_AUTHOR("Carsten Paeth"); 42MODULE_LICENSE("GPL"); 43module_param(debugmode, uint, S_IRUGO | S_IWUSR); 44 45/* -------- type definitions ----------------------------------------- */ 46 47 48struct capidrv_contr { 49 50 struct capidrv_contr *next; 51 struct module *owner; 52 u32 contrnr; 53 char name[20]; 54 55 /* 56 * for isdn4linux 57 */ 58 isdn_if interface; 59 int myid; 60 61 /* 62 * LISTEN state 63 */ 64 int state; 65 u32 cipmask; 66 u32 cipmask2; 67 struct timer_list listentimer; 68 69 /* 70 * ID of capi message sent 71 */ 72 u16 msgid; 73 74 /* 75 * B-Channels 76 */ 77 int nbchan; 78 struct capidrv_bchan { 79 struct capidrv_contr *contr; 80 u8 msn[ISDN_MSNLEN]; 81 int l2; 82 int l3; 83 u8 num[ISDN_MSNLEN]; 84 u8 mynum[ISDN_MSNLEN]; 85 int si1; 86 int si2; 87 int incoming; 88 int disconnecting; 89 struct capidrv_plci { 90 struct capidrv_plci *next; 91 u32 plci; 92 u32 ncci; /* ncci for CONNECT_ACTIVE_IND */ 93 u16 msgid; /* to identfy CONNECT_CONF */ 94 int chan; 95 int state; 96 int leasedline; 97 struct capidrv_ncci { 98 struct capidrv_ncci *next; 99 struct capidrv_plci *plcip; 100 u32 ncci; 101 u16 msgid; /* to identfy CONNECT_B3_CONF */ 102 int chan; 103 int state; 104 int oldstate; 105 /* */ 106 u16 datahandle; 107 struct ncci_datahandle_queue { 108 struct ncci_datahandle_queue *next; 109 u16 datahandle; 110 int len; 111 } *ackqueue; 112 } *ncci_list; 113 } *plcip; 114 struct capidrv_ncci *nccip; 115 } *bchans; 116 117 struct capidrv_plci *plci_list; 118 119 /* for q931 data */ 120 u8 q931_buf[4096]; 121 u8 *q931_read; 122 u8 *q931_write; 123 u8 *q931_end; 124}; 125 126 127struct capidrv_data { 128 struct capi20_appl ap; 129 int ncontr; 130 struct capidrv_contr *contr_list; 131}; 132 133typedef struct capidrv_plci capidrv_plci; 134typedef struct capidrv_ncci capidrv_ncci; 135typedef struct capidrv_contr capidrv_contr; 136typedef struct capidrv_data capidrv_data; 137typedef struct capidrv_bchan capidrv_bchan; 138 139/* -------- data definitions ----------------------------------------- */ 140 141static capidrv_data global; 142static DEFINE_SPINLOCK(global_lock); 143 144static void handle_dtrace_data(capidrv_contr *card, 145 int send, int level2, u8 *data, u16 len); 146 147/* -------- convert functions ---------------------------------------- */ 148 149static inline u32 b1prot(int l2, int l3) 150{ 151 switch (l2) { 152 case ISDN_PROTO_L2_X75I: 153 case ISDN_PROTO_L2_X75UI: 154 case ISDN_PROTO_L2_X75BUI: 155 return 0; 156 case ISDN_PROTO_L2_HDLC: 157 default: 158 return 0; 159 case ISDN_PROTO_L2_TRANS: 160 return 1; 161 case ISDN_PROTO_L2_V11096: 162 case ISDN_PROTO_L2_V11019: 163 case ISDN_PROTO_L2_V11038: 164 return 2; 165 case ISDN_PROTO_L2_FAX: 166 return 4; 167 case ISDN_PROTO_L2_MODEM: 168 return 8; 169 } 170} 171 172static inline u32 b2prot(int l2, int l3) 173{ 174 switch (l2) { 175 case ISDN_PROTO_L2_X75I: 176 case ISDN_PROTO_L2_X75UI: 177 case ISDN_PROTO_L2_X75BUI: 178 default: 179 return 0; 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: 186 return 1; 187 case ISDN_PROTO_L2_FAX: 188 return 4; 189 } 190} 191 192static inline u32 b3prot(int l2, int l3) 193{ 194 switch (l2) { 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: 204 default: 205 return 0; 206 case ISDN_PROTO_L2_FAX: 207 return 4; 208 } 209} 210 211static _cstruct b1config_async_v110(u16 rate) 212{ 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 */ 221 return buf; 222} 223 224static _cstruct b1config(int l2, int l3) 225{ 226 switch (l2) { 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: 232 default: 233 return NULL; 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); 240 } 241} 242 243static inline u16 si2cip(u8 si1, u8 si2) 244{ 245 static const u8 cip[17][5] = 246 { 247 /* 0 1 2 3 4 */ 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 */ 265 }; 266 if (si1 > 16) 267 si1 = 0; 268 if (si2 > 4) 269 si2 = 0; 270 271 return (u16) cip[si1][si2]; 272} 273 274static inline u8 cip2si1(u16 cipval) 275{ 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 */ 281 282 if (cipval > 31) 283 cipval = 0; /* .... */ 284 return si[cipval]; 285} 286 287static inline u8 cip2si2(u16 cipval) 288{ 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 */ 294 295 if (cipval > 31) 296 cipval = 0; /* .... */ 297 return si[cipval]; 298} 299 300 301/* -------- controller management ------------------------------------- */ 302 303static inline capidrv_contr *findcontrbydriverid(int driverid) 304{ 305 unsigned long flags; 306 capidrv_contr *p; 307 308 spin_lock_irqsave(&global_lock, flags); 309 for (p = global.contr_list; p; p = p->next) 310 if (p->myid == driverid) 311 break; 312 spin_unlock_irqrestore(&global_lock, flags); 313 return p; 314} 315 316static capidrv_contr *findcontrbynumber(u32 contr) 317{ 318 unsigned long flags; 319 capidrv_contr *p = global.contr_list; 320 321 spin_lock_irqsave(&global_lock, flags); 322 for (p = global.contr_list; p; p = p->next) 323 if (p->contrnr == contr) 324 break; 325 spin_unlock_irqrestore(&global_lock, flags); 326 return p; 327} 328 329 330/* -------- plci management ------------------------------------------ */ 331 332static capidrv_plci *new_plci(capidrv_contr *card, int chan) 333{ 334 capidrv_plci *plcip; 335 336 plcip = kzalloc(sizeof(capidrv_plci), GFP_ATOMIC); 337 338 if (plcip == NULL) 339 return NULL; 340 341 plcip->state = ST_PLCI_NONE; 342 plcip->plci = 0; 343 plcip->msgid = 0; 344 plcip->chan = chan; 345 plcip->next = card->plci_list; 346 card->plci_list = plcip; 347 card->bchans[chan].plcip = plcip; 348 349 return plcip; 350} 351 352static capidrv_plci *find_plci_by_plci(capidrv_contr *card, u32 plci) 353{ 354 capidrv_plci *p; 355 for (p = card->plci_list; p; p = p->next) 356 if (p->plci == plci) 357 return p; 358 return NULL; 359} 360 361static capidrv_plci *find_plci_by_msgid(capidrv_contr *card, u16 msgid) 362{ 363 capidrv_plci *p; 364 for (p = card->plci_list; p; p = p->next) 365 if (p->msgid == msgid) 366 return p; 367 return NULL; 368} 369 370static capidrv_plci *find_plci_by_ncci(capidrv_contr *card, u32 ncci) 371{ 372 capidrv_plci *p; 373 for (p = card->plci_list; p; p = p->next) 374 if (p->plci == (ncci & 0xffff)) 375 return p; 376 return NULL; 377} 378 379static void free_plci(capidrv_contr *card, capidrv_plci *plcip) 380{ 381 capidrv_plci **pp; 382 383 for (pp = &card->plci_list; *pp; pp = &(*pp)->next) { 384 if (*pp == plcip) { 385 *pp = (*pp)->next; 386 card->bchans[plcip->chan].plcip = NULL; 387 card->bchans[plcip->chan].disconnecting = 0; 388 card->bchans[plcip->chan].incoming = 0; 389 kfree(plcip); 390 return; 391 } 392 } 393 printk(KERN_ERR "capidrv-%d: free_plci %p (0x%x) not found, Huh?\n", 394 card->contrnr, plcip, plcip->plci); 395} 396 397/* -------- ncci management ------------------------------------------ */ 398 399static inline capidrv_ncci *new_ncci(capidrv_contr *card, 400 capidrv_plci *plcip, 401 u32 ncci) 402{ 403 capidrv_ncci *nccip; 404 405 nccip = kzalloc(sizeof(capidrv_ncci), GFP_ATOMIC); 406 407 if (nccip == NULL) 408 return NULL; 409 410 nccip->ncci = ncci; 411 nccip->state = ST_NCCI_NONE; 412 nccip->plcip = plcip; 413 nccip->chan = plcip->chan; 414 nccip->datahandle = 0; 415 416 nccip->next = plcip->ncci_list; 417 plcip->ncci_list = nccip; 418 419 card->bchans[plcip->chan].nccip = nccip; 420 421 return nccip; 422} 423 424static inline capidrv_ncci *find_ncci(capidrv_contr *card, u32 ncci) 425{ 426 capidrv_plci *plcip; 427 capidrv_ncci *p; 428 429 if ((plcip = find_plci_by_ncci(card, ncci)) == NULL) 430 return NULL; 431 432 for (p = plcip->ncci_list; p; p = p->next) 433 if (p->ncci == ncci) 434 return p; 435 return NULL; 436} 437 438static inline capidrv_ncci *find_ncci_by_msgid(capidrv_contr *card, 439 u32 ncci, u16 msgid) 440{ 441 capidrv_plci *plcip; 442 capidrv_ncci *p; 443 444 if ((plcip = find_plci_by_ncci(card, ncci)) == NULL) 445 return NULL; 446 447 for (p = plcip->ncci_list; p; p = p->next) 448 if (p->msgid == msgid) 449 return p; 450 return NULL; 451} 452 453static void free_ncci(capidrv_contr *card, struct capidrv_ncci *nccip) 454{ 455 struct capidrv_ncci **pp; 456 457 for (pp = &(nccip->plcip->ncci_list); *pp; pp = &(*pp)->next) { 458 if (*pp == nccip) { 459 *pp = (*pp)->next; 460 break; 461 } 462 } 463 card->bchans[nccip->chan].nccip = NULL; 464 kfree(nccip); 465} 466 467static int capidrv_add_ack(struct capidrv_ncci *nccip, 468 u16 datahandle, int len) 469{ 470 struct ncci_datahandle_queue *n, **pp; 471 472 n = kmalloc(sizeof(struct ncci_datahandle_queue), GFP_ATOMIC); 473 if (!n) { 474 printk(KERN_ERR "capidrv: kmalloc ncci_datahandle failed\n"); 475 return -1; 476 } 477 n->next = NULL; 478 n->datahandle = datahandle; 479 n->len = len; 480 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next); 481 *pp = n; 482 return 0; 483} 484 485static int capidrv_del_ack(struct capidrv_ncci *nccip, u16 datahandle) 486{ 487 struct ncci_datahandle_queue **pp, *p; 488 int len; 489 490 for (pp = &nccip->ackqueue; *pp; pp = &(*pp)->next) { 491 if ((*pp)->datahandle == datahandle) { 492 p = *pp; 493 len = p->len; 494 *pp = (*pp)->next; 495 kfree(p); 496 return len; 497 } 498 } 499 return -1; 500} 501 502/* -------- convert and send capi message ---------------------------- */ 503 504static void send_message(capidrv_contr *card, _cmsg *cmsg) 505{ 506 struct sk_buff *skb; 507 size_t len; 508 509 capi_cmsg2message(cmsg, cmsg->buf); 510 len = CAPIMSG_LEN(cmsg->buf); 511 skb = alloc_skb(len, GFP_ATOMIC); 512 if (!skb) { 513 printk(KERN_ERR "capidrv::send_message: can't allocate mem\n"); 514 return; 515 } 516 memcpy(skb_put(skb, len), cmsg->buf, len); 517 if (capi20_put_message(&global.ap, skb) != CAPI_NOERROR) 518 kfree_skb(skb); 519} 520 521/* -------- state machine -------------------------------------------- */ 522 523struct listenstatechange { 524 int actstate; 525 int nextstate; 526 int event; 527}; 528 529static struct listenstatechange listentable[] = 530{ 531 {ST_LISTEN_NONE, ST_LISTEN_WAIT_CONF, EV_LISTEN_REQ}, 532 {ST_LISTEN_ACTIVE, ST_LISTEN_ACTIVE_WAIT_CONF, EV_LISTEN_REQ}, 533 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_ERROR}, 534 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_ERROR}, 535 {ST_LISTEN_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY}, 536 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_NONE, EV_LISTEN_CONF_EMPTY}, 537 {ST_LISTEN_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK}, 538 {ST_LISTEN_ACTIVE_WAIT_CONF, ST_LISTEN_ACTIVE, EV_LISTEN_CONF_OK}, 539 {}, 540}; 541 542static void listen_change_state(capidrv_contr *card, int event) 543{ 544 struct listenstatechange *p = listentable; 545 while (p->event) { 546 if (card->state == p->actstate && p->event == event) { 547 if (debugmode) 548 printk(KERN_DEBUG "capidrv-%d: listen_change_state %d -> %d\n", 549 card->contrnr, card->state, p->nextstate); 550 card->state = p->nextstate; 551 return; 552 } 553 p++; 554 } 555 printk(KERN_ERR "capidrv-%d: listen_change_state state=%d event=%d ????\n", 556 card->contrnr, card->state, event); 557 558} 559 560/* ------------------------------------------------------------------ */ 561 562static void p0(capidrv_contr *card, capidrv_plci *plci) 563{ 564 isdn_ctrl cmd; 565 566 card->bchans[plci->chan].contr = NULL; 567 cmd.command = ISDN_STAT_DHUP; 568 cmd.driver = card->myid; 569 cmd.arg = plci->chan; 570 card->interface.statcallb(&cmd); 571 free_plci(card, plci); 572} 573 574/* ------------------------------------------------------------------ */ 575 576struct plcistatechange { 577 int actstate; 578 int nextstate; 579 int event; 580 void (*changefunc)(capidrv_contr *card, capidrv_plci *plci); 581}; 582 583static struct plcistatechange plcitable[] = 584{ 585 /* P-0 */ 586 {ST_PLCI_NONE, ST_PLCI_OUTGOING, EV_PLCI_CONNECT_REQ, NULL}, 587 {ST_PLCI_NONE, ST_PLCI_ALLOCATED, EV_PLCI_FACILITY_IND_UP, NULL}, 588 {ST_PLCI_NONE, ST_PLCI_INCOMING, EV_PLCI_CONNECT_IND, NULL}, 589 {ST_PLCI_NONE, ST_PLCI_RESUMEING, EV_PLCI_RESUME_REQ, NULL}, 590 /* P-0.1 */ 591 {ST_PLCI_OUTGOING, ST_PLCI_NONE, EV_PLCI_CONNECT_CONF_ERROR, p0}, 592 {ST_PLCI_OUTGOING, ST_PLCI_ALLOCATED, EV_PLCI_CONNECT_CONF_OK, NULL}, 593 /* P-1 */ 594 {ST_PLCI_ALLOCATED, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL}, 595 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL}, 596 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL}, 597 {ST_PLCI_ALLOCATED, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 598 /* P-ACT */ 599 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL}, 600 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL}, 601 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 602 {ST_PLCI_ACTIVE, ST_PLCI_HELD, EV_PLCI_HOLD_IND, NULL}, 603 {ST_PLCI_ACTIVE, ST_PLCI_DISCONNECTING, EV_PLCI_SUSPEND_IND, NULL}, 604 /* P-2 */ 605 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL}, 606 {ST_PLCI_INCOMING, ST_PLCI_FACILITY_IND, EV_PLCI_FACILITY_IND_UP, NULL}, 607 {ST_PLCI_INCOMING, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_RESP, NULL}, 608 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL}, 609 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL}, 610 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 611 {ST_PLCI_INCOMING, ST_PLCI_DISCONNECTING, EV_PLCI_CD_IND, NULL}, 612 /* P-3 */ 613 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_CONNECT_REJECT, NULL}, 614 {ST_PLCI_FACILITY_IND, ST_PLCI_ACCEPTING, EV_PLCI_CONNECT_ACTIVE_IND, NULL}, 615 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL}, 616 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL}, 617 {ST_PLCI_FACILITY_IND, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 618 /* P-4 */ 619 {ST_PLCI_ACCEPTING, ST_PLCI_ACTIVE, EV_PLCI_CONNECT_ACTIVE_IND, NULL}, 620 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_DISCONNECT_REQ, NULL}, 621 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTING, EV_PLCI_FACILITY_IND_DOWN, NULL}, 622 {ST_PLCI_ACCEPTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 623 /* P-5 */ 624 {ST_PLCI_DISCONNECTING, ST_PLCI_DISCONNECTED, EV_PLCI_DISCONNECT_IND, NULL}, 625 /* P-6 */ 626 {ST_PLCI_DISCONNECTED, ST_PLCI_NONE, EV_PLCI_DISCONNECT_RESP, p0}, 627 /* P-0.Res */ 628 {ST_PLCI_RESUMEING, ST_PLCI_NONE, EV_PLCI_RESUME_CONF_ERROR, p0}, 629 {ST_PLCI_RESUMEING, ST_PLCI_RESUME, EV_PLCI_RESUME_CONF_OK, NULL}, 630 /* P-RES */ 631 {ST_PLCI_RESUME, ST_PLCI_ACTIVE, EV_PLCI_RESUME_IND, NULL}, 632 /* P-HELD */ 633 {ST_PLCI_HELD, ST_PLCI_ACTIVE, EV_PLCI_RETRIEVE_IND, NULL}, 634 {}, 635}; 636 637static void plci_change_state(capidrv_contr *card, capidrv_plci *plci, int event) 638{ 639 struct plcistatechange *p = plcitable; 640 while (p->event) { 641 if (plci->state == p->actstate && p->event == event) { 642 if (debugmode) 643 printk(KERN_DEBUG "capidrv-%d: plci_change_state:0x%x %d -> %d\n", 644 card->contrnr, plci->plci, plci->state, p->nextstate); 645 plci->state = p->nextstate; 646 if (p->changefunc) 647 p->changefunc(card, plci); 648 return; 649 } 650 p++; 651 } 652 printk(KERN_ERR "capidrv-%d: plci_change_state:0x%x state=%d event=%d ????\n", 653 card->contrnr, plci->plci, plci->state, event); 654} 655 656/* ------------------------------------------------------------------ */ 657 658static _cmsg cmsg; 659 660static void n0(capidrv_contr *card, capidrv_ncci *ncci) 661{ 662 isdn_ctrl cmd; 663 664 capi_fill_DISCONNECT_REQ(&cmsg, 665 global.ap.applid, 666 card->msgid++, 667 ncci->plcip->plci, 668 NULL, /* BChannelinformation */ 669 NULL, /* Keypadfacility */ 670 NULL, /* Useruserdata */ /* $$$$ */ 671 NULL /* Facilitydataarray */ 672 ); 673 plci_change_state(card, ncci->plcip, EV_PLCI_DISCONNECT_REQ); 674 send_message(card, &cmsg); 675 676 cmd.command = ISDN_STAT_BHUP; 677 cmd.driver = card->myid; 678 cmd.arg = ncci->chan; 679 card->interface.statcallb(&cmd); 680 free_ncci(card, ncci); 681} 682 683/* ------------------------------------------------------------------ */ 684 685struct nccistatechange { 686 int actstate; 687 int nextstate; 688 int event; 689 void (*changefunc)(capidrv_contr *card, capidrv_ncci *ncci); 690}; 691 692static struct nccistatechange nccitable[] = 693{ 694 /* N-0 */ 695 {ST_NCCI_NONE, ST_NCCI_OUTGOING, EV_NCCI_CONNECT_B3_REQ, NULL}, 696 {ST_NCCI_NONE, ST_NCCI_INCOMING, EV_NCCI_CONNECT_B3_IND, NULL}, 697 /* N-0.1 */ 698 {ST_NCCI_OUTGOING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_CONF_OK, NULL}, 699 {ST_NCCI_OUTGOING, ST_NCCI_NONE, EV_NCCI_CONNECT_B3_CONF_ERROR, n0}, 700 /* N-1 */ 701 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_CONNECT_B3_REJECT, NULL}, 702 {ST_NCCI_INCOMING, ST_NCCI_ALLOCATED, EV_NCCI_CONNECT_B3_RESP, NULL}, 703 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL}, 704 {ST_NCCI_INCOMING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL}, 705 /* N-2 */ 706 {ST_NCCI_ALLOCATED, ST_NCCI_ACTIVE, EV_NCCI_CONNECT_B3_ACTIVE_IND, NULL}, 707 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL}, 708 {ST_NCCI_ALLOCATED, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL}, 709 /* N-ACT */ 710 {ST_NCCI_ACTIVE, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL}, 711 {ST_NCCI_ACTIVE, ST_NCCI_RESETING, EV_NCCI_RESET_B3_REQ, NULL}, 712 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL}, 713 {ST_NCCI_ACTIVE, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL}, 714 /* N-3 */ 715 {ST_NCCI_RESETING, ST_NCCI_ACTIVE, EV_NCCI_RESET_B3_IND, NULL}, 716 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL}, 717 {ST_NCCI_RESETING, ST_NCCI_DISCONNECTING, EV_NCCI_DISCONNECT_B3_REQ, NULL}, 718 /* N-4 */ 719 {ST_NCCI_DISCONNECTING, ST_NCCI_DISCONNECTED, EV_NCCI_DISCONNECT_B3_IND, NULL}, 720 {ST_NCCI_DISCONNECTING, ST_NCCI_PREVIOUS, EV_NCCI_DISCONNECT_B3_CONF_ERROR, NULL}, 721 /* N-5 */ 722 {ST_NCCI_DISCONNECTED, ST_NCCI_NONE, EV_NCCI_DISCONNECT_B3_RESP, n0}, 723 {}, 724}; 725 726static void ncci_change_state(capidrv_contr *card, capidrv_ncci *ncci, int event) 727{ 728 struct nccistatechange *p = nccitable; 729 while (p->event) { 730 if (ncci->state == p->actstate && p->event == event) { 731 if (debugmode) 732 printk(KERN_DEBUG "capidrv-%d: ncci_change_state:0x%x %d -> %d\n", 733 card->contrnr, ncci->ncci, ncci->state, p->nextstate); 734 if (p->nextstate == ST_NCCI_PREVIOUS) { 735 ncci->state = ncci->oldstate; 736 ncci->oldstate = p->actstate; 737 } else { 738 ncci->oldstate = p->actstate; 739 ncci->state = p->nextstate; 740 } 741 if (p->changefunc) 742 p->changefunc(card, ncci); 743 return; 744 } 745 p++; 746 } 747 printk(KERN_ERR "capidrv-%d: ncci_change_state:0x%x state=%d event=%d ????\n", 748 card->contrnr, ncci->ncci, ncci->state, event); 749} 750 751/* ------------------------------------------------------------------- */ 752 753static inline int new_bchan(capidrv_contr *card) 754{ 755 int i; 756 for (i = 0; i < card->nbchan; i++) { 757 if (card->bchans[i].plcip == NULL) { 758 card->bchans[i].disconnecting = 0; 759 return i; 760 } 761 } 762 return -1; 763} 764 765/* ------------------------------------------------------------------- */ 766static char *capi_info2str(u16 reason) 767{ 768#ifndef CONFIG_ISDN_CAPI_CAPIDRV_VERBOSE 769 return ".."; 770#else 771 switch (reason) { 772 773/*-- informative values (corresponding message was processed) -----*/ 774 case 0x0001: 775 return "NCPI not supported by current protocol, NCPI ignored"; 776 case 0x0002: 777 return "Flags not supported by current protocol, flags ignored"; 778 case 0x0003: 779 return "Alert already sent by another application"; 780 781/*-- error information concerning CAPI_REGISTER -----*/ 782 case 0x1001: 783 return "Too many applications"; 784 case 0x1002: 785 return "Logical block size too small, must be at least 128 Bytes"; 786 case 0x1003: 787 return "Buffer exceeds 64 kByte"; 788 case 0x1004: 789 return "Message buffer size too small, must be at least 1024 Bytes"; 790 case 0x1005: 791 return "Max. number of logical connections not supported"; 792 case 0x1006: 793 return "Reserved"; 794 case 0x1007: 795 return "The message could not be accepted because of an internal busy condition"; 796 case 0x1008: 797 return "OS resource error (no memory ?)"; 798 case 0x1009: 799 return "CAPI not installed"; 800 case 0x100A: 801 return "Controller does not support external equipment"; 802 case 0x100B: 803 return "Controller does only support external equipment"; 804 805/*-- error information concerning message exchange functions -----*/ 806 case 0x1101: 807 return "Illegal application number"; 808 case 0x1102: 809 return "Illegal command or subcommand or message length less than 12 bytes"; 810 case 0x1103: 811 return "The message could not be accepted because of a queue full condition !! The error code does not imply that CAPI cannot receive messages directed to another controller, PLCI or NCCI"; 812 case 0x1104: 813 return "Queue is empty"; 814 case 0x1105: 815 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE"; 816 case 0x1106: 817 return "Unknown notification parameter"; 818 case 0x1107: 819 return "The Message could not be accepted because of an internal busy condition"; 820 case 0x1108: 821 return "OS Resource error (no memory ?)"; 822 case 0x1109: 823 return "CAPI not installed"; 824 case 0x110A: 825 return "Controller does not support external equipment"; 826 case 0x110B: 827 return "Controller does only support external equipment"; 828 829/*-- error information concerning resource / coding problems -----*/ 830 case 0x2001: 831 return "Message not supported in current state"; 832 case 0x2002: 833 return "Illegal Controller / PLCI / NCCI"; 834 case 0x2003: 835 return "Out of PLCI"; 836 case 0x2004: 837 return "Out of NCCI"; 838 case 0x2005: 839 return "Out of LISTEN"; 840 case 0x2006: 841 return "Out of FAX resources (protocol T.30)"; 842 case 0x2007: 843 return "Illegal message parameter coding"; 844 845/*-- error information concerning requested services -----*/ 846 case 0x3001: 847 return "B1 protocol not supported"; 848 case 0x3002: 849 return "B2 protocol not supported"; 850 case 0x3003: 851 return "B3 protocol not supported"; 852 case 0x3004: 853 return "B1 protocol parameter not supported"; 854 case 0x3005: 855 return "B2 protocol parameter not supported"; 856 case 0x3006: 857 return "B3 protocol parameter not supported"; 858 case 0x3007: 859 return "B protocol combination not supported"; 860 case 0x3008: 861 return "NCPI not supported"; 862 case 0x3009: 863 return "CIP Value unknown"; 864 case 0x300A: 865 return "Flags not supported (reserved bits)"; 866 case 0x300B: 867 return "Facility not supported"; 868 case 0x300C: 869 return "Data length not supported by current protocol"; 870 case 0x300D: 871 return "Reset procedure not supported by current protocol"; 872 873/*-- informations about the clearing of a physical connection -----*/ 874 case 0x3301: 875 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)"; 876 case 0x3302: 877 return "Protocol error layer 2"; 878 case 0x3303: 879 return "Protocol error layer 3"; 880 case 0x3304: 881 return "Another application got that call"; 882/*-- T.30 specific reasons -----*/ 883 case 0x3311: 884 return "Connecting not successful (remote station is no FAX G3 machine)"; 885 case 0x3312: 886 return "Connecting not successful (training error)"; 887 case 0x3313: 888 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)"; 889 case 0x3314: 890 return "Disconnected during transfer (remote abort)"; 891 case 0x3315: 892 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)"; 893 case 0x3316: 894 return "Disconnected during transfer (local tx data underrun)"; 895 case 0x3317: 896 return "Disconnected during transfer (local rx data overflow)"; 897 case 0x3318: 898 return "Disconnected during transfer (local abort)"; 899 case 0x3319: 900 return "Illegal parameter coding (e.g. SFF coding error)"; 901 902/*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/ 903 case 0x3481: return "Unallocated (unassigned) number"; 904 case 0x3482: return "No route to specified transit network"; 905 case 0x3483: return "No route to destination"; 906 case 0x3486: return "Channel unacceptable"; 907 case 0x3487: 908 return "Call awarded and being delivered in an established channel"; 909 case 0x3490: return "Normal call clearing"; 910 case 0x3491: return "User busy"; 911 case 0x3492: return "No user responding"; 912 case 0x3493: return "No answer from user (user alerted)"; 913 case 0x3495: return "Call rejected"; 914 case 0x3496: return "Number changed"; 915 case 0x349A: return "Non-selected user clearing"; 916 case 0x349B: return "Destination out of order"; 917 case 0x349C: return "Invalid number format"; 918 case 0x349D: return "Facility rejected"; 919 case 0x349E: return "Response to STATUS ENQUIRY"; 920 case 0x349F: return "Normal, unspecified"; 921 case 0x34A2: return "No circuit / channel available"; 922 case 0x34A6: return "Network out of order"; 923 case 0x34A9: return "Temporary failure"; 924 case 0x34AA: return "Switching equipment congestion"; 925 case 0x34AB: return "Access information discarded"; 926 case 0x34AC: return "Requested circuit / channel not available"; 927 case 0x34AF: return "Resources unavailable, unspecified"; 928 case 0x34B1: return "Quality of service unavailable"; 929 case 0x34B2: return "Requested facility not subscribed"; 930 case 0x34B9: return "Bearer capability not authorized"; 931 case 0x34BA: return "Bearer capability not presently available"; 932 case 0x34BF: return "Service or option not available, unspecified"; 933 case 0x34C1: return "Bearer capability not implemented"; 934 case 0x34C2: return "Channel type not implemented"; 935 case 0x34C5: return "Requested facility not implemented"; 936 case 0x34C6: return "Only restricted digital information bearer capability is available"; 937 case 0x34CF: return "Service or option not implemented, unspecified"; 938 case 0x34D1: return "Invalid call reference value"; 939 case 0x34D2: return "Identified channel does not exist"; 940 case 0x34D3: return "A suspended call exists, but this call identity does not"; 941 case 0x34D4: return "Call identity in use"; 942 case 0x34D5: return "No call suspended"; 943 case 0x34D6: return "Call having the requested call identity has been cleared"; 944 case 0x34D8: return "Incompatible destination"; 945 case 0x34DB: return "Invalid transit network selection"; 946 case 0x34DF: return "Invalid message, unspecified"; 947 case 0x34E0: return "Mandatory information element is missing"; 948 case 0x34E1: return "Message type non-existent or not implemented"; 949 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented"; 950 case 0x34E3: return "Information element non-existent or not implemented"; 951 case 0x34E4: return "Invalid information element contents"; 952 case 0x34E5: return "Message not compatible with call state"; 953 case 0x34E6: return "Recovery on timer expiry"; 954 case 0x34EF: return "Protocol error, unspecified"; 955 case 0x34FF: return "Interworking, unspecified"; 956 957 default: return "No additional information"; 958 } 959#endif 960} 961 962static void handle_controller(_cmsg *cmsg) 963{ 964 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f); 965 966 if (!card) { 967 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n", 968 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 969 cmsg->adr.adrController & 0x7f); 970 return; 971 } 972 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) { 973 974 case CAPI_LISTEN_CONF: /* Controller */ 975 if (debugmode) 976 printk(KERN_DEBUG "capidrv-%d: listenconf Info=0x%4x (%s) cipmask=0x%x\n", 977 card->contrnr, cmsg->Info, capi_info2str(cmsg->Info), card->cipmask); 978 if (cmsg->Info) { 979 listen_change_state(card, EV_LISTEN_CONF_ERROR); 980 } else if (card->cipmask == 0) { 981 listen_change_state(card, EV_LISTEN_CONF_EMPTY); 982 } else { 983 listen_change_state(card, EV_LISTEN_CONF_OK); 984 } 985 break; 986 987 case CAPI_MANUFACTURER_IND: /* Controller */ 988 if (cmsg->ManuID == 0x214D5641 989 && cmsg->Class == 0 990 && cmsg->Function == 1) { 991 u8 *data = cmsg->ManuData + 3; 992 u16 len = cmsg->ManuData[0]; 993 u16 layer; 994 int direction; 995 if (len == 255) { 996 len = (cmsg->ManuData[1] | (cmsg->ManuData[2] << 8)); 997 data += 2; 998 } 999 len -= 2; 1000 layer = ((*(data - 1)) << 8) | *(data - 2); 1001 if (layer & 0x300) 1002 direction = (layer & 0x200) ? 0 : 1; 1003 else direction = (layer & 0x800) ? 0 : 1; 1004 if (layer & 0x0C00) { 1005 if ((layer & 0xff) == 0x80) { 1006 handle_dtrace_data(card, direction, 1, data, len); 1007 break; 1008 } 1009 } else if ((layer & 0xff) < 0x80) { 1010 handle_dtrace_data(card, direction, 0, data, len); 1011 break; 1012 } 1013 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x layer 0x%x, ignored\n", 1014 card->contrnr, 1015 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1016 cmsg->adr.adrController, layer); 1017 break; 1018 } 1019 goto ignored; 1020 case CAPI_MANUFACTURER_CONF: /* Controller */ 1021 if (cmsg->ManuID == 0x214D5641) { 1022 char *s = NULL; 1023 switch (cmsg->Class) { 1024 case 0: break; 1025 case 1: s = "unknown class"; break; 1026 case 2: s = "unknown function"; break; 1027 default: s = "unknown error"; break; 1028 } 1029 if (s) 1030 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x function %d: %s\n", 1031 card->contrnr, 1032 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1033 cmsg->adr.adrController, 1034 cmsg->Function, s); 1035 break; 1036 } 1037 goto ignored; 1038 case CAPI_FACILITY_IND: /* Controller/plci/ncci */ 1039 goto ignored; 1040 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */ 1041 goto ignored; 1042 case CAPI_INFO_IND: /* Controller/plci */ 1043 goto ignored; 1044 case CAPI_INFO_CONF: /* Controller/plci */ 1045 goto ignored; 1046 1047 default: 1048 printk(KERN_ERR "capidrv-%d: got %s from controller 0x%x ???", 1049 card->contrnr, 1050 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1051 cmsg->adr.adrController); 1052 } 1053 return; 1054 1055ignored: 1056 printk(KERN_INFO "capidrv-%d: %s from controller 0x%x ignored\n", 1057 card->contrnr, 1058 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1059 cmsg->adr.adrController); 1060} 1061 1062static void handle_incoming_call(capidrv_contr *card, _cmsg *cmsg) 1063{ 1064 capidrv_plci *plcip; 1065 capidrv_bchan *bchan; 1066 isdn_ctrl cmd; 1067 int chan; 1068 1069 if ((chan = new_bchan(card)) == -1) { 1070 printk(KERN_ERR "capidrv-%d: incoming call on not existing bchan ?\n", card->contrnr); 1071 return; 1072 } 1073 bchan = &card->bchans[chan]; 1074 if ((plcip = new_plci(card, chan)) == NULL) { 1075 printk(KERN_ERR "capidrv-%d: incoming call: no memory, sorry.\n", card->contrnr); 1076 return; 1077 } 1078 bchan->incoming = 1; 1079 plcip->plci = cmsg->adr.adrPLCI; 1080 plci_change_state(card, plcip, EV_PLCI_CONNECT_IND); 1081 1082 cmd.command = ISDN_STAT_ICALL; 1083 cmd.driver = card->myid; 1084 cmd.arg = chan; 1085 memset(&cmd.parm.setup, 0, sizeof(cmd.parm.setup)); 1086 strncpy(cmd.parm.setup.phone, 1087 cmsg->CallingPartyNumber + 3, 1088 cmsg->CallingPartyNumber[0] - 2); 1089 strncpy(cmd.parm.setup.eazmsn, 1090 cmsg->CalledPartyNumber + 2, 1091 cmsg->CalledPartyNumber[0] - 1); 1092 cmd.parm.setup.si1 = cip2si1(cmsg->CIPValue); 1093 cmd.parm.setup.si2 = cip2si2(cmsg->CIPValue); 1094 cmd.parm.setup.plan = cmsg->CallingPartyNumber[1]; 1095 cmd.parm.setup.screen = cmsg->CallingPartyNumber[2]; 1096 1097 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s\n", 1098 card->contrnr, 1099 cmd.parm.setup.phone, 1100 cmd.parm.setup.si1, 1101 cmd.parm.setup.si2, 1102 cmd.parm.setup.eazmsn); 1103 1104 if (cmd.parm.setup.si1 == 1 && cmd.parm.setup.si2 != 0) { 1105 printk(KERN_INFO "capidrv-%d: patching si2=%d to 0 for VBOX\n", 1106 card->contrnr, 1107 cmd.parm.setup.si2); 1108 cmd.parm.setup.si2 = 0; 1109 } 1110 1111 switch (card->interface.statcallb(&cmd)) { 1112 case 0: 1113 case 3: 1114 /* No device matching this call. 1115 * and isdn_common.c has send a HANGUP command 1116 * which is ignored in state ST_PLCI_INCOMING, 1117 * so we send RESP to ignore the call 1118 */ 1119 capi_cmsg_answer(cmsg); 1120 cmsg->Reject = 1; /* ignore */ 1121 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 1122 send_message(card, cmsg); 1123 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s ignored\n", 1124 card->contrnr, 1125 cmd.parm.setup.phone, 1126 cmd.parm.setup.si1, 1127 cmd.parm.setup.si2, 1128 cmd.parm.setup.eazmsn); 1129 break; 1130 case 1: 1131 /* At least one device matching this call (RING on ttyI) 1132 * HL-driver may send ALERTING on the D-channel in this 1133 * case. 1134 * really means: RING on ttyI or a net interface 1135 * accepted this call already. 1136 * 1137 * If the call was accepted, state has already changed, 1138 * and CONNECT_RESP already sent. 1139 */ 1140 if (plcip->state == ST_PLCI_INCOMING) { 1141 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s tty alerting\n", 1142 card->contrnr, 1143 cmd.parm.setup.phone, 1144 cmd.parm.setup.si1, 1145 cmd.parm.setup.si2, 1146 cmd.parm.setup.eazmsn); 1147 capi_fill_ALERT_REQ(cmsg, 1148 global.ap.applid, 1149 card->msgid++, 1150 plcip->plci, /* adr */ 1151 NULL,/* BChannelinformation */ 1152 NULL,/* Keypadfacility */ 1153 NULL,/* Useruserdata */ 1154 NULL /* Facilitydataarray */ 1155 ); 1156 plcip->msgid = cmsg->Messagenumber; 1157 send_message(card, cmsg); 1158 } else { 1159 printk(KERN_INFO "capidrv-%d: incoming call %s,%d,%d,%s on netdev\n", 1160 card->contrnr, 1161 cmd.parm.setup.phone, 1162 cmd.parm.setup.si1, 1163 cmd.parm.setup.si2, 1164 cmd.parm.setup.eazmsn); 1165 } 1166 break; 1167 1168 case 2: /* Call will be rejected. */ 1169 capi_cmsg_answer(cmsg); 1170 cmsg->Reject = 2; /* reject call, normal call clearing */ 1171 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 1172 send_message(card, cmsg); 1173 break; 1174 1175 default: 1176 /* An error happened. (Invalid parameters for example.) */ 1177 capi_cmsg_answer(cmsg); 1178 cmsg->Reject = 8; /* reject call, 1179 destination out of order */ 1180 plci_change_state(card, plcip, EV_PLCI_CONNECT_REJECT); 1181 send_message(card, cmsg); 1182 break; 1183 } 1184 return; 1185} 1186 1187static void handle_plci(_cmsg *cmsg) 1188{ 1189 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f); 1190 capidrv_plci *plcip; 1191 isdn_ctrl cmd; 1192 _cdebbuf *cdb; 1193 1194 if (!card) { 1195 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n", 1196 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1197 cmsg->adr.adrController & 0x7f); 1198 return; 1199 } 1200 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) { 1201 1202 case CAPI_DISCONNECT_IND: /* plci */ 1203 if (cmsg->Reason) { 1204 printk(KERN_INFO "capidrv-%d: %s reason 0x%x (%s) for plci 0x%x\n", 1205 card->contrnr, 1206 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1207 cmsg->Reason, capi_info2str(cmsg->Reason), cmsg->adr.adrPLCI); 1208 } 1209 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) { 1210 capi_cmsg_answer(cmsg); 1211 send_message(card, cmsg); 1212 goto notfound; 1213 } 1214 card->bchans[plcip->chan].disconnecting = 1; 1215 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_IND); 1216 capi_cmsg_answer(cmsg); 1217 plci_change_state(card, plcip, EV_PLCI_DISCONNECT_RESP); 1218 send_message(card, cmsg); 1219 break; 1220 1221 case CAPI_DISCONNECT_CONF: /* plci */ 1222 if (cmsg->Info) { 1223 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n", 1224 card->contrnr, 1225 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1226 cmsg->Info, capi_info2str(cmsg->Info), 1227 cmsg->adr.adrPLCI); 1228 } 1229 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) 1230 goto notfound; 1231 1232 card->bchans[plcip->chan].disconnecting = 1; 1233 break; 1234 1235 case CAPI_ALERT_CONF: /* plci */ 1236 if (cmsg->Info) { 1237 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n", 1238 card->contrnr, 1239 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1240 cmsg->Info, capi_info2str(cmsg->Info), 1241 cmsg->adr.adrPLCI); 1242 } 1243 break; 1244 1245 case CAPI_CONNECT_IND: /* plci */ 1246 handle_incoming_call(card, cmsg); 1247 break; 1248 1249 case CAPI_CONNECT_CONF: /* plci */ 1250 if (cmsg->Info) { 1251 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for plci 0x%x\n", 1252 card->contrnr, 1253 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1254 cmsg->Info, capi_info2str(cmsg->Info), 1255 cmsg->adr.adrPLCI); 1256 } 1257 if (!(plcip = find_plci_by_msgid(card, cmsg->Messagenumber))) 1258 goto notfound; 1259 1260 plcip->plci = cmsg->adr.adrPLCI; 1261 if (cmsg->Info) { 1262 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_ERROR); 1263 } else { 1264 plci_change_state(card, plcip, EV_PLCI_CONNECT_CONF_OK); 1265 } 1266 break; 1267 1268 case CAPI_CONNECT_ACTIVE_IND: /* plci */ 1269 1270 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) 1271 goto notfound; 1272 1273 if (card->bchans[plcip->chan].incoming) { 1274 capi_cmsg_answer(cmsg); 1275 plci_change_state(card, plcip, EV_PLCI_CONNECT_ACTIVE_IND); 1276 send_message(card, cmsg); 1277 } else { 1278 capidrv_ncci *nccip; 1279 capi_cmsg_answer(cmsg); 1280 send_message(card, cmsg); 1281 1282 nccip = new_ncci(card, plcip, cmsg->adr.adrPLCI); 1283 1284 if (!nccip) { 1285 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr); 1286 break; /* $$$$ */ 1287 } 1288 capi_fill_CONNECT_B3_REQ(cmsg, 1289 global.ap.applid, 1290 card->msgid++, 1291 plcip->plci, /* adr */ 1292 NULL /* NCPI */ 1293 ); 1294 nccip->msgid = cmsg->Messagenumber; 1295 plci_change_state(card, plcip, 1296 EV_PLCI_CONNECT_ACTIVE_IND); 1297 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_REQ); 1298 send_message(card, cmsg); 1299 cmd.command = ISDN_STAT_DCONN; 1300 cmd.driver = card->myid; 1301 cmd.arg = plcip->chan; 1302 card->interface.statcallb(&cmd); 1303 } 1304 break; 1305 1306 case CAPI_INFO_IND: /* Controller/plci */ 1307 1308 if (!(plcip = find_plci_by_plci(card, cmsg->adr.adrPLCI))) 1309 goto notfound; 1310 1311 if (cmsg->InfoNumber == 0x4000) { 1312 if (cmsg->InfoElement[0] == 4) { 1313 cmd.command = ISDN_STAT_CINF; 1314 cmd.driver = card->myid; 1315 cmd.arg = plcip->chan; 1316 sprintf(cmd.parm.num, "%lu", 1317 (unsigned long) 1318 ((u32) cmsg->InfoElement[1] 1319 | ((u32) (cmsg->InfoElement[2]) << 8) 1320 | ((u32) (cmsg->InfoElement[3]) << 16) 1321 | ((u32) (cmsg->InfoElement[4]) << 24))); 1322 card->interface.statcallb(&cmd); 1323 break; 1324 } 1325 } 1326 cdb = capi_cmsg2str(cmsg); 1327 if (cdb) { 1328 printk(KERN_WARNING "capidrv-%d: %s\n", 1329 card->contrnr, cdb->buf); 1330 cdebbuf_free(cdb); 1331 } else 1332 printk(KERN_WARNING "capidrv-%d: CAPI_INFO_IND InfoNumber %x not handled\n", 1333 card->contrnr, cmsg->InfoNumber); 1334 1335 break; 1336 1337 case CAPI_CONNECT_ACTIVE_CONF: /* plci */ 1338 goto ignored; 1339 case CAPI_SELECT_B_PROTOCOL_CONF: /* plci */ 1340 goto ignored; 1341 case CAPI_FACILITY_IND: /* Controller/plci/ncci */ 1342 goto ignored; 1343 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */ 1344 goto ignored; 1345 1346 case CAPI_INFO_CONF: /* Controller/plci */ 1347 goto ignored; 1348 1349 default: 1350 printk(KERN_ERR "capidrv-%d: got %s for plci 0x%x ???", 1351 card->contrnr, 1352 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1353 cmsg->adr.adrPLCI); 1354 } 1355 return; 1356ignored: 1357 printk(KERN_INFO "capidrv-%d: %s for plci 0x%x ignored\n", 1358 card->contrnr, 1359 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1360 cmsg->adr.adrPLCI); 1361 return; 1362notfound: 1363 printk(KERN_ERR "capidrv-%d: %s: plci 0x%x not found\n", 1364 card->contrnr, 1365 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1366 cmsg->adr.adrPLCI); 1367 return; 1368} 1369 1370static void handle_ncci(_cmsg *cmsg) 1371{ 1372 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f); 1373 capidrv_plci *plcip; 1374 capidrv_ncci *nccip; 1375 isdn_ctrl cmd; 1376 int len; 1377 1378 if (!card) { 1379 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n", 1380 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1381 cmsg->adr.adrController & 0x7f); 1382 return; 1383 } 1384 switch (CAPICMD(cmsg->Command, cmsg->Subcommand)) { 1385 1386 case CAPI_CONNECT_B3_ACTIVE_IND: /* ncci */ 1387 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) 1388 goto notfound; 1389 1390 capi_cmsg_answer(cmsg); 1391 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_ACTIVE_IND); 1392 send_message(card, cmsg); 1393 1394 cmd.command = ISDN_STAT_BCONN; 1395 cmd.driver = card->myid; 1396 cmd.arg = nccip->chan; 1397 card->interface.statcallb(&cmd); 1398 1399 printk(KERN_INFO "capidrv-%d: chan %d up with ncci 0x%x\n", 1400 card->contrnr, nccip->chan, nccip->ncci); 1401 break; 1402 1403 case CAPI_CONNECT_B3_ACTIVE_CONF: /* ncci */ 1404 goto ignored; 1405 1406 case CAPI_CONNECT_B3_IND: /* ncci */ 1407 1408 plcip = find_plci_by_ncci(card, cmsg->adr.adrNCCI); 1409 if (plcip) { 1410 nccip = new_ncci(card, plcip, cmsg->adr.adrNCCI); 1411 if (nccip) { 1412 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_IND); 1413 capi_fill_CONNECT_B3_RESP(cmsg, 1414 global.ap.applid, 1415 card->msgid++, 1416 nccip->ncci, /* adr */ 1417 0, /* Reject */ 1418 NULL /* NCPI */ 1419 ); 1420 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_RESP); 1421 send_message(card, cmsg); 1422 break; 1423 } 1424 printk(KERN_ERR "capidrv-%d: no mem for ncci, sorry\n", card->contrnr); 1425 } else { 1426 printk(KERN_ERR "capidrv-%d: %s: plci for ncci 0x%x not found\n", 1427 card->contrnr, 1428 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1429 cmsg->adr.adrNCCI); 1430 } 1431 capi_fill_CONNECT_B3_RESP(cmsg, 1432 global.ap.applid, 1433 card->msgid++, 1434 cmsg->adr.adrNCCI, 1435 2, /* Reject */ 1436 NULL /* NCPI */ 1437 ); 1438 send_message(card, cmsg); 1439 break; 1440 1441 case CAPI_CONNECT_B3_CONF: /* ncci */ 1442 1443 if (!(nccip = find_ncci_by_msgid(card, 1444 cmsg->adr.adrNCCI, 1445 cmsg->Messagenumber))) 1446 goto notfound; 1447 1448 nccip->ncci = cmsg->adr.adrNCCI; 1449 if (cmsg->Info) { 1450 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n", 1451 card->contrnr, 1452 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1453 cmsg->Info, capi_info2str(cmsg->Info), 1454 cmsg->adr.adrNCCI); 1455 } 1456 1457 if (cmsg->Info) 1458 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_ERROR); 1459 else 1460 ncci_change_state(card, nccip, EV_NCCI_CONNECT_B3_CONF_OK); 1461 break; 1462 1463 case CAPI_CONNECT_B3_T90_ACTIVE_IND: /* ncci */ 1464 capi_cmsg_answer(cmsg); 1465 send_message(card, cmsg); 1466 break; 1467 1468 case CAPI_DATA_B3_IND: /* ncci */ 1469 /* handled in handle_data() */ 1470 goto ignored; 1471 1472 case CAPI_DATA_B3_CONF: /* ncci */ 1473 if (cmsg->Info) { 1474 printk(KERN_WARNING "CAPI_DATA_B3_CONF: Info %x - %s\n", 1475 cmsg->Info, capi_info2str(cmsg->Info)); 1476 } 1477 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) 1478 goto notfound; 1479 1480 len = capidrv_del_ack(nccip, cmsg->DataHandle); 1481 if (len < 0) 1482 break; 1483 cmd.command = ISDN_STAT_BSENT; 1484 cmd.driver = card->myid; 1485 cmd.arg = nccip->chan; 1486 cmd.parm.length = len; 1487 card->interface.statcallb(&cmd); 1488 break; 1489 1490 case CAPI_DISCONNECT_B3_IND: /* ncci */ 1491 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) 1492 goto notfound; 1493 1494 card->bchans[nccip->chan].disconnecting = 1; 1495 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_IND); 1496 capi_cmsg_answer(cmsg); 1497 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_RESP); 1498 send_message(card, cmsg); 1499 break; 1500 1501 case CAPI_DISCONNECT_B3_CONF: /* ncci */ 1502 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) 1503 goto notfound; 1504 if (cmsg->Info) { 1505 printk(KERN_INFO "capidrv-%d: %s info 0x%x (%s) for ncci 0x%x\n", 1506 card->contrnr, 1507 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1508 cmsg->Info, capi_info2str(cmsg->Info), 1509 cmsg->adr.adrNCCI); 1510 ncci_change_state(card, nccip, EV_NCCI_DISCONNECT_B3_CONF_ERROR); 1511 } 1512 break; 1513 1514 case CAPI_RESET_B3_IND: /* ncci */ 1515 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) 1516 goto notfound; 1517 ncci_change_state(card, nccip, EV_NCCI_RESET_B3_IND); 1518 capi_cmsg_answer(cmsg); 1519 send_message(card, cmsg); 1520 break; 1521 1522 case CAPI_RESET_B3_CONF: /* ncci */ 1523 goto ignored; /* $$$$ */ 1524 1525 case CAPI_FACILITY_IND: /* Controller/plci/ncci */ 1526 goto ignored; 1527 case CAPI_FACILITY_CONF: /* Controller/plci/ncci */ 1528 goto ignored; 1529 1530 default: 1531 printk(KERN_ERR "capidrv-%d: got %s for ncci 0x%x ???", 1532 card->contrnr, 1533 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1534 cmsg->adr.adrNCCI); 1535 } 1536 return; 1537ignored: 1538 printk(KERN_INFO "capidrv-%d: %s for ncci 0x%x ignored\n", 1539 card->contrnr, 1540 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1541 cmsg->adr.adrNCCI); 1542 return; 1543notfound: 1544 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n", 1545 card->contrnr, 1546 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1547 cmsg->adr.adrNCCI); 1548} 1549 1550 1551static void handle_data(_cmsg *cmsg, struct sk_buff *skb) 1552{ 1553 capidrv_contr *card = findcontrbynumber(cmsg->adr.adrController & 0x7f); 1554 capidrv_ncci *nccip; 1555 1556 if (!card) { 1557 printk(KERN_ERR "capidrv: %s from unknown controller 0x%x\n", 1558 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1559 cmsg->adr.adrController & 0x7f); 1560 kfree_skb(skb); 1561 return; 1562 } 1563 if (!(nccip = find_ncci(card, cmsg->adr.adrNCCI))) { 1564 printk(KERN_ERR "capidrv-%d: %s: ncci 0x%x not found\n", 1565 card->contrnr, 1566 capi_cmd2str(cmsg->Command, cmsg->Subcommand), 1567 cmsg->adr.adrNCCI); 1568 kfree_skb(skb); 1569 return; 1570 } 1571 (void) skb_pull(skb, CAPIMSG_LEN(skb->data)); 1572 card->interface.rcvcallb_skb(card->myid, nccip->chan, skb); 1573 capi_cmsg_answer(cmsg); 1574 send_message(card, cmsg); 1575} 1576 1577static _cmsg s_cmsg; 1578 1579static void capidrv_recv_message(struct capi20_appl *ap, struct sk_buff *skb) 1580{ 1581 capi_message2cmsg(&s_cmsg, skb->data); 1582 if (debugmode > 3) { 1583 _cdebbuf *cdb = capi_cmsg2str(&s_cmsg); 1584 1585 if (cdb) { 1586 printk(KERN_DEBUG "%s: applid=%d %s\n", __func__, 1587 ap->applid, cdb->buf); 1588 cdebbuf_free(cdb); 1589 } else 1590 printk(KERN_DEBUG "%s: applid=%d %s not traced\n", 1591 __func__, ap->applid, 1592 capi_cmd2str(s_cmsg.Command, s_cmsg.Subcommand)); 1593 } 1594 if (s_cmsg.Command == CAPI_DATA_B3 1595 && s_cmsg.Subcommand == CAPI_IND) { 1596 handle_data(&s_cmsg, skb); 1597 return; 1598 } 1599 if ((s_cmsg.adr.adrController & 0xffffff00) == 0) 1600 handle_controller(&s_cmsg); 1601 else if ((s_cmsg.adr.adrPLCI & 0xffff0000) == 0) 1602 handle_plci(&s_cmsg); 1603 else 1604 handle_ncci(&s_cmsg); 1605 /* 1606 * data of skb used in s_cmsg, 1607 * free data when s_cmsg is not used again 1608 * thanks to Lars Heete <hel@admin.de> 1609 */ 1610 kfree_skb(skb); 1611} 1612 1613/* ------------------------------------------------------------------- */ 1614 1615#define PUTBYTE_TO_STATUS(card, byte) \ 1616 do { \ 1617 *(card)->q931_write++ = (byte); \ 1618 if ((card)->q931_write > (card)->q931_end) \ 1619 (card)->q931_write = (card)->q931_buf; \ 1620 } while (0) 1621 1622static void handle_dtrace_data(capidrv_contr *card, 1623 int send, int level2, u8 *data, u16 len) 1624{ 1625 u8 *p, *end; 1626 isdn_ctrl cmd; 1627 1628 if (!len) { 1629 printk(KERN_DEBUG "capidrv-%d: avmb1_q931_data: len == %d\n", 1630 card->contrnr, len); 1631 return; 1632 } 1633 1634 if (level2) { 1635 PUTBYTE_TO_STATUS(card, 'D'); 1636 PUTBYTE_TO_STATUS(card, '2'); 1637 PUTBYTE_TO_STATUS(card, send ? '>' : '<'); 1638 PUTBYTE_TO_STATUS(card, ':'); 1639 } else { 1640 PUTBYTE_TO_STATUS(card, 'D'); 1641 PUTBYTE_TO_STATUS(card, '3'); 1642 PUTBYTE_TO_STATUS(card, send ? '>' : '<'); 1643 PUTBYTE_TO_STATUS(card, ':'); 1644 } 1645 1646 for (p = data, end = data + len; p < end; p++) { 1647 PUTBYTE_TO_STATUS(card, ' '); 1648 PUTBYTE_TO_STATUS(card, hex_asc_hi(*p)); 1649 PUTBYTE_TO_STATUS(card, hex_asc_lo(*p)); 1650 } 1651 PUTBYTE_TO_STATUS(card, '\n'); 1652 1653 cmd.command = ISDN_STAT_STAVAIL; 1654 cmd.driver = card->myid; 1655 cmd.arg = len * 3 + 5; 1656 card->interface.statcallb(&cmd); 1657} 1658 1659/* ------------------------------------------------------------------- */ 1660 1661static _cmsg cmdcmsg; 1662 1663static int capidrv_ioctl(isdn_ctrl *c, capidrv_contr *card) 1664{ 1665 switch (c->arg) { 1666 case 1: 1667 debugmode = (int)(*((unsigned int *)c->parm.num)); 1668 printk(KERN_DEBUG "capidrv-%d: debugmode=%d\n", 1669 card->contrnr, debugmode); 1670 return 0; 1671 default: 1672 printk(KERN_DEBUG "capidrv-%d: capidrv_ioctl(%ld) called ??\n", 1673 card->contrnr, c->arg); 1674 return -EINVAL; 1675 } 1676 return -EINVAL; 1677} 1678 1679/* 1680 * Handle leased lines (CAPI-Bundling) 1681 */ 1682 1683struct internal_bchannelinfo { 1684 unsigned short channelalloc; 1685 unsigned short operation; 1686 unsigned char cmask[31]; 1687}; 1688 1689static int decodeFVteln(char *teln, unsigned long *bmaskp, int *activep) 1690{ 1691 unsigned long bmask = 0; 1692 int active = !0; 1693 char *s; 1694 int i; 1695 1696 if (strncmp(teln, "FV:", 3) != 0) 1697 return 1; 1698 s = teln + 3; 1699 while (*s && *s == ' ') s++; 1700 if (!*s) return -2; 1701 if (*s == 'p' || *s == 'P') { 1702 active = 0; 1703 s++; 1704 } 1705 if (*s == 'a' || *s == 'A') { 1706 active = !0; 1707 s++; 1708 } 1709 while (*s) { 1710 int digit1 = 0; 1711 int digit2 = 0; 1712 char *endp; 1713 1714 digit1 = simple_strtoul(s, &endp, 10); 1715 if (s == endp) 1716 return -3; 1717 s = endp; 1718 1719 if (digit1 <= 0 || digit1 > 30) return -4; 1720 if (*s == 0 || *s == ',' || *s == ' ') { 1721 bmask |= (1 << digit1); 1722 digit1 = 0; 1723 if (*s) s++; 1724 continue; 1725 } 1726 if (*s != '-') return -5; 1727 s++; 1728 1729 digit2 = simple_strtoul(s, &endp, 10); 1730 if (s == endp) 1731 return -3; 1732 s = endp; 1733 1734 if (digit2 <= 0 || digit2 > 30) return -4; 1735 if (*s == 0 || *s == ',' || *s == ' ') { 1736 if (digit1 > digit2) 1737 for (i = digit2; i <= digit1; i++) 1738 bmask |= (1 << i); 1739 else 1740 for (i = digit1; i <= digit2; i++) 1741 bmask |= (1 << i); 1742 digit1 = digit2 = 0; 1743 if (*s) s++; 1744 continue; 1745 } 1746 return -6; 1747 } 1748 if (activep) *activep = active; 1749 if (bmaskp) *bmaskp = bmask; 1750 return 0; 1751} 1752 1753static int FVteln2capi20(char *teln, u8 AdditionalInfo[1 + 2 + 2 + 31]) 1754{ 1755 unsigned long bmask; 1756 int active; 1757 int rc, i; 1758 1759 rc = decodeFVteln(teln, &bmask, &active); 1760 if (rc) return rc; 1761 /* Length */ 1762 AdditionalInfo[0] = 2 + 2 + 31; 1763 /* Channel: 3 => use channel allocation */ 1764 AdditionalInfo[1] = 3; AdditionalInfo[2] = 0; 1765 /* Operation: 0 => DTE mode, 1 => DCE mode */ 1766 if (active) { 1767 AdditionalInfo[3] = 0; AdditionalInfo[4] = 0; 1768 } else { 1769 AdditionalInfo[3] = 1; AdditionalInfo[4] = 0; 1770 } 1771 /* Channel mask array */ 1772 AdditionalInfo[5] = 0; /* no D-Channel */ 1773 for (i = 1; i <= 30; i++) 1774 AdditionalInfo[5 + i] = (bmask & (1 << i)) ? 0xff : 0; 1775 return 0; 1776} 1777 1778static int capidrv_command(isdn_ctrl *c, capidrv_contr *card) 1779{ 1780 isdn_ctrl cmd; 1781 struct capidrv_bchan *bchan; 1782 struct capidrv_plci *plcip; 1783 u8 AdditionalInfo[1 + 2 + 2 + 31]; 1784 int rc, isleasedline = 0; 1785 1786 if (c->command == ISDN_CMD_IOCTL) 1787 return capidrv_ioctl(c, card); 1788 1789 switch (c->command) { 1790 case ISDN_CMD_DIAL: { 1791 u8 calling[ISDN_MSNLEN + 3]; 1792 u8 called[ISDN_MSNLEN + 2]; 1793 1794 if (debugmode) 1795 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_DIAL(ch=%ld,\"%s,%d,%d,%s\")\n", 1796 card->contrnr, 1797 c->arg, 1798 c->parm.setup.phone, 1799 c->parm.setup.si1, 1800 c->parm.setup.si2, 1801 c->parm.setup.eazmsn); 1802 1803 bchan = &card->bchans[c->arg % card->nbchan]; 1804 1805 if (bchan->plcip) { 1806 printk(KERN_ERR "capidrv-%d: dail ch=%ld,\"%s,%d,%d,%s\" in use (plci=0x%x)\n", 1807 card->contrnr, 1808 c->arg, 1809 c->parm.setup.phone, 1810 c->parm.setup.si1, 1811 c->parm.setup.si2, 1812 c->parm.setup.eazmsn, 1813 bchan->plcip->plci); 1814 return 0; 1815 } 1816 bchan->si1 = c->parm.setup.si1; 1817 bchan->si2 = c->parm.setup.si2; 1818 1819 strncpy(bchan->num, c->parm.setup.phone, sizeof(bchan->num)); 1820 strncpy(bchan->mynum, c->parm.setup.eazmsn, sizeof(bchan->mynum)); 1821 rc = FVteln2capi20(bchan->num, AdditionalInfo); 1822 isleasedline = (rc == 0); 1823 if (rc < 0) 1824 printk(KERN_ERR "capidrv-%d: WARNING: invalid leased linedefinition \"%s\"\n", card->contrnr, bchan->num); 1825 1826 if (isleasedline) { 1827 calling[0] = 0; 1828 called[0] = 0; 1829 if (debugmode) 1830 printk(KERN_DEBUG "capidrv-%d: connecting leased line\n", card->contrnr); 1831 } else { 1832 calling[0] = strlen(bchan->mynum) + 2; 1833 calling[1] = 0; 1834 calling[2] = 0x80; 1835 strncpy(calling + 3, bchan->mynum, ISDN_MSNLEN); 1836 called[0] = strlen(bchan->num) + 1; 1837 called[1] = 0x80; 1838 strncpy(called + 2, bchan->num, ISDN_MSNLEN); 1839 } 1840 1841 capi_fill_CONNECT_REQ(&cmdcmsg, 1842 global.ap.applid, 1843 card->msgid++, 1844 card->contrnr, /* adr */ 1845 si2cip(bchan->si1, bchan->si2), /* cipvalue */ 1846 called, /* CalledPartyNumber */ 1847 calling, /* CallingPartyNumber */ 1848 NULL, /* CalledPartySubaddress */ 1849 NULL, /* CallingPartySubaddress */ 1850 b1prot(bchan->l2, bchan->l3), /* B1protocol */ 1851 b2prot(bchan->l2, bchan->l3), /* B2protocol */ 1852 b3prot(bchan->l2, bchan->l3), /* B3protocol */ 1853 b1config(bchan->l2, bchan->l3), /* B1configuration */ 1854 NULL, /* B2configuration */ 1855 NULL, /* B3configuration */ 1856 NULL, /* BC */ 1857 NULL, /* LLC */ 1858 NULL, /* HLC */ 1859 /* BChannelinformation */ 1860 isleasedline ? AdditionalInfo : NULL, 1861 NULL, /* Keypadfacility */ 1862 NULL, /* Useruserdata */ 1863 NULL /* Facilitydataarray */ 1864 ); 1865 if ((plcip = new_plci(card, (c->arg % card->nbchan))) == NULL) { 1866 cmd.command = ISDN_STAT_DHUP; 1867 cmd.driver = card->myid; 1868 cmd.arg = (c->arg % card->nbchan); 1869 card->interface.statcallb(&cmd); 1870 return -1; 1871 } 1872 plcip->msgid = cmdcmsg.Messagenumber; 1873 plcip->leasedline = isleasedline; 1874 plci_change_state(card, plcip, EV_PLCI_CONNECT_REQ); 1875 send_message(card, &cmdcmsg); 1876 return 0; 1877 } 1878 1879 case ISDN_CMD_ACCEPTD: 1880 1881 bchan = &card->bchans[c->arg % card->nbchan]; 1882 if (debugmode) 1883 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTD(ch=%ld) l2=%d l3=%d\n", 1884 card->contrnr, 1885 c->arg, bchan->l2, bchan->l3); 1886 1887 capi_fill_CONNECT_RESP(&cmdcmsg, 1888 global.ap.applid, 1889 card->msgid++, 1890 bchan->plcip->plci, /* adr */ 1891 0, /* Reject */ 1892 b1prot(bchan->l2, bchan->l3), /* B1protocol */ 1893 b2prot(bchan->l2, bchan->l3), /* B2protocol */ 1894 b3prot(bchan->l2, bchan->l3), /* B3protocol */ 1895 b1config(bchan->l2, bchan->l3), /* B1configuration */ 1896 NULL, /* B2configuration */ 1897 NULL, /* B3configuration */ 1898 NULL, /* ConnectedNumber */ 1899 NULL, /* ConnectedSubaddress */ 1900 NULL, /* LLC */ 1901 NULL, /* BChannelinformation */ 1902 NULL, /* Keypadfacility */ 1903 NULL, /* Useruserdata */ 1904 NULL /* Facilitydataarray */ 1905 ); 1906 capi_cmsg2message(&cmdcmsg, cmdcmsg.buf); 1907 plci_change_state(card, bchan->plcip, EV_PLCI_CONNECT_RESP); 1908 send_message(card, &cmdcmsg); 1909 return 0; 1910 1911 case ISDN_CMD_ACCEPTB: 1912 if (debugmode) 1913 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_ACCEPTB(ch=%ld)\n", 1914 card->contrnr, 1915 c->arg); 1916 return -ENOSYS; 1917 1918 case ISDN_CMD_HANGUP: 1919 if (debugmode) 1920 printk(KERN_DEBUG "capidrv-%d: ISDN_CMD_HANGUP(ch=%ld)\n", 1921 card->contrnr, 1922 c->arg); 1923 bchan = &card->bchans[c->arg % card->nbchan]; 1924 1925 if (bchan->disconnecting) { 1926 if (debugmode) 1927 printk(KERN_DEBUG "capidrv-%d: chan %ld already disconnecting ...\n", 1928 card->contrnr, 1929 c->arg); 1930 return 0; 1931 } 1932 if (bchan->nccip) { 1933 bchan->disconnecting = 1; 1934 capi_fill_DISCONNECT_B3_REQ(&cmdcmsg, 1935 global.ap.applid, 1936 card->msgid++, 1937 bchan->nccip->ncci, 1938 NULL /* NCPI */ 1939 ); 1940 ncci_change_state(card, bchan->nccip, EV_NCCI_DISCONNECT_B3_REQ); 1941 send_message(card, &cmdcmsg); 1942 return 0; 1943 } else if (bchan->plcip) { 1944 if (bchan->plcip->state == ST_PLCI_INCOMING) { 1945 /* 1946 * just ignore, we a called from 1947 * isdn_status_callback(), 1948 * which will return 0 or 2, this is handled 1949 * by the CONNECT_IND handler 1950 */ 1951 bchan->disconnecting = 1; 1952 return 0; 1953 } else if (bchan->plcip->plci) { 1954 bchan->disconnecting = 1; 1955 capi_fill_DISCONNECT_REQ(&cmdcmsg, 1956 global.ap.applid, 1957 card->msgid++, 1958 bchan->plcip->plci, 1959 NULL, /* BChannelinformation */ 1960 NULL, /* Keypadfacility */ 1961 NULL, /* Useruserdata */ 1962 NULL /* Facilitydataarray */ 1963 ); 1964 plci_change_state(card, bchan->plcip, EV_PLCI_DISCONNECT_REQ); 1965 send_message(card, &cmdcmsg); 1966 return 0; 1967 } else { 1968 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request while waiting for CONNECT_CONF\n", 1969 card->contrnr, 1970 c->arg); 1971 return -EINVAL; 1972 } 1973 } 1974 printk(KERN_ERR "capidrv-%d: chan %ld disconnect request on free channel\n", 1975 card->contrnr, 1976 c->arg); 1977 return -EINVAL; 1978/* ready */ 1979 1980 case ISDN_CMD_SETL2: 1981 if (debugmode) 1982 printk(KERN_DEBUG "capidrv-%d: set L2 on chan %ld to %ld\n", 1983 card->contrnr, 1984 (c->arg & 0xff), (c->arg >> 8)); 1985 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan]; 1986 bchan->l2 = (c->arg >> 8); 1987 return 0; 1988 1989 case ISDN_CMD_SETL3: 1990 if (debugmode) 1991 printk(KERN_DEBUG "capidrv-%d: set L3 on chan %ld to %ld\n", 1992 card->contrnr, 1993 (c->arg & 0xff), (c->arg >> 8)); 1994 bchan = &card->bchans[(c->arg & 0xff) % card->nbchan]; 1995 bchan->l3 = (c->arg >> 8); 1996 return 0; 1997 1998 case ISDN_CMD_SETEAZ: 1999 if (debugmode) 2000 printk(KERN_DEBUG "capidrv-%d: set EAZ \"%s\" on chan %ld\n", 2001 card->contrnr, 2002 c->parm.num, c->arg); 2003 bchan = &card->bchans[c->arg % card->nbchan]; 2004 strncpy(bchan->msn, c->parm.num, ISDN_MSNLEN); 2005 return 0; 2006 2007 case ISDN_CMD_CLREAZ: 2008 if (debugmode) 2009 printk(KERN_DEBUG "capidrv-%d: clearing EAZ on chan %ld\n", 2010 card->contrnr, c->arg); 2011 bchan = &card->bchans[c->arg % card->nbchan]; 2012 bchan->msn[0] = 0; 2013 return 0; 2014 2015 default: 2016 printk(KERN_ERR "capidrv-%d: ISDN_CMD_%d, Huh?\n", 2017 card->contrnr, c->command); 2018 return -EINVAL; 2019 } 2020 return 0; 2021} 2022 2023static int if_command(isdn_ctrl *c) 2024{ 2025 capidrv_contr *card = findcontrbydriverid(c->driver); 2026 2027 if (card) 2028 return capidrv_command(c, card); 2029 2030 printk(KERN_ERR 2031 "capidrv: if_command %d called with invalid driverId %d!\n", 2032 c->command, c->driver); 2033 return -ENODEV; 2034} 2035 2036static _cmsg sendcmsg; 2037 2038static int if_sendbuf(int id, int channel, int doack, struct sk_buff *skb) 2039{ 2040 capidrv_contr *card = findcontrbydriverid(id); 2041 capidrv_bchan *bchan; 2042 capidrv_ncci *nccip; 2043 int len = skb->len; 2044 int msglen; 2045 u16 errcode; 2046 u16 datahandle; 2047 u32 data; 2048 2049 if (!card) { 2050 printk(KERN_ERR "capidrv: if_sendbuf called with invalid driverId %d!\n", 2051 id); 2052 return 0; 2053 } 2054 if (debugmode > 4) 2055 printk(KERN_DEBUG "capidrv-%d: sendbuf len=%d skb=%p doack=%d\n", 2056 card->contrnr, len, skb, doack); 2057 bchan = &card->bchans[channel % card->nbchan]; 2058 nccip = bchan->nccip; 2059 if (!nccip || nccip->state != ST_NCCI_ACTIVE) { 2060 printk(KERN_ERR "capidrv-%d: if_sendbuf: %s:%d: chan not up!\n", 2061 card->contrnr, card->name, channel); 2062 return 0; 2063 } 2064 datahandle = nccip->datahandle; 2065 2066 /* 2067 * Here we copy pointer skb->data into the 32-bit 'Data' field. 2068 * The 'Data' field is not used in practice in linux kernel 2069 * (neither in 32 or 64 bit), but should have some value, 2070 * since a CAPI message trace will display it. 2071 * 2072 * The correct value in the 32 bit case is the address of the 2073 * data, in 64 bit it makes no sense, we use 0 there. 2074 */ 2075 2076#ifdef CONFIG_64BIT 2077 data = 0; 2078#else 2079 data = (unsigned long) skb->data; 2080#endif 2081 2082 capi_fill_DATA_B3_REQ(&sendcmsg, global.ap.applid, card->msgid++, 2083 nccip->ncci, /* adr */ 2084 data, /* Data */ 2085 skb->len, /* DataLength */ 2086 datahandle, /* DataHandle */ 2087 0 /* Flags */ 2088 ); 2089 2090 if (capidrv_add_ack(nccip, datahandle, doack ? (int)skb->len : -1) < 0) 2091 return 0; 2092 2093 capi_cmsg2message(&sendcmsg, sendcmsg.buf); 2094 msglen = CAPIMSG_LEN(sendcmsg.buf); 2095 if (skb_headroom(skb) < msglen) { 2096 struct sk_buff *nskb = skb_realloc_headroom(skb, msglen); 2097 if (!nskb) { 2098 printk(KERN_ERR "capidrv-%d: if_sendbuf: no memory\n", 2099 card->contrnr); 2100 (void)capidrv_del_ack(nccip, datahandle); 2101 return 0; 2102 } 2103 printk(KERN_DEBUG "capidrv-%d: only %d bytes headroom, need %d\n", 2104 card->contrnr, skb_headroom(skb), msglen); 2105 memcpy(skb_push(nskb, msglen), sendcmsg.buf, msglen); 2106 errcode = capi20_put_message(&global.ap, nskb); 2107 if (errcode == CAPI_NOERROR) { 2108 dev_kfree_skb(skb); 2109 nccip->datahandle++; 2110 return len; 2111 } 2112 if (debugmode > 3) 2113 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n", 2114 card->contrnr, errcode, capi_info2str(errcode)); 2115 (void)capidrv_del_ack(nccip, datahandle); 2116 dev_kfree_skb(nskb); 2117 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1; 2118 } else { 2119 memcpy(skb_push(skb, msglen), sendcmsg.buf, msglen); 2120 errcode = capi20_put_message(&global.ap, skb); 2121 if (errcode == CAPI_NOERROR) { 2122 nccip->datahandle++; 2123 return len; 2124 } 2125 if (debugmode > 3) 2126 printk(KERN_DEBUG "capidrv-%d: sendbuf putmsg ret(%x) - %s\n", 2127 card->contrnr, errcode, capi_info2str(errcode)); 2128 skb_pull(skb, msglen); 2129 (void)capidrv_del_ack(nccip, datahandle); 2130 return errcode == CAPI_SENDQUEUEFULL ? 0 : -1; 2131 } 2132} 2133 2134static int if_readstat(u8 __user *buf, int len, int id, int channel) 2135{ 2136 capidrv_contr *card = findcontrbydriverid(id); 2137 int count; 2138 u8 __user *p; 2139 2140 if (!card) { 2141 printk(KERN_ERR "capidrv: if_readstat called with invalid driverId %d!\n", 2142 id); 2143 return -ENODEV; 2144 } 2145 2146 for (p = buf, count = 0; count < len; p++, count++) { 2147 if (put_user(*card->q931_read++, p)) 2148 return -EFAULT; 2149 if (card->q931_read > card->q931_end) 2150 card->q931_read = card->q931_buf; 2151 } 2152 return count; 2153 2154} 2155 2156static void enable_dchannel_trace(capidrv_contr *card) 2157{ 2158 u8 manufacturer[CAPI_MANUFACTURER_LEN]; 2159 capi_version version; 2160 u16 contr = card->contrnr; 2161 u16 errcode; 2162 u16 avmversion[3]; 2163 2164 errcode = capi20_get_manufacturer(contr, manufacturer); 2165 if (errcode != CAPI_NOERROR) { 2166 printk(KERN_ERR "%s: can't get manufacturer (0x%x)\n", 2167 card->name, errcode); 2168 return; 2169 } 2170 if (strstr(manufacturer, "AVM") == NULL) { 2171 printk(KERN_ERR "%s: not from AVM, no d-channel trace possible (%s)\n", 2172 card->name, manufacturer); 2173 return; 2174 } 2175 errcode = capi20_get_version(contr, &version); 2176 if (errcode != CAPI_NOERROR) { 2177 printk(KERN_ERR "%s: can't get version (0x%x)\n", 2178 card->name, errcode); 2179 return; 2180 } 2181 avmversion[0] = (version.majormanuversion >> 4) & 0x0f; 2182 avmversion[1] = (version.majormanuversion << 4) & 0xf0; 2183 avmversion[1] |= (version.minormanuversion >> 4) & 0x0f; 2184 avmversion[2] |= version.minormanuversion & 0x0f; 2185 2186 if (avmversion[0] > 3 || (avmversion[0] == 3 && avmversion[1] > 5)) { 2187 printk(KERN_INFO "%s: D2 trace enabled\n", card->name); 2188 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid, 2189 card->msgid++, 2190 contr, 2191 0x214D5641, /* ManuID */ 2192 0, /* Class */ 2193 1, /* Function */ 2194 (_cstruct)"\004\200\014\000\000"); 2195 } else { 2196 printk(KERN_INFO "%s: D3 trace enabled\n", card->name); 2197 capi_fill_MANUFACTURER_REQ(&cmdcmsg, global.ap.applid, 2198 card->msgid++, 2199 contr, 2200 0x214D5641, /* ManuID */ 2201 0, /* Class */ 2202 1, /* Function */ 2203 (_cstruct)"\004\002\003\000\000"); 2204 } 2205 send_message(card, &cmdcmsg); 2206} 2207 2208 2209static void send_listen(capidrv_contr *card) 2210{ 2211 capi_fill_LISTEN_REQ(&cmdcmsg, global.ap.applid, 2212 card->msgid++, 2213 card->contrnr, /* controller */ 2214 1 << 6, /* Infomask */ 2215 card->cipmask, 2216 card->cipmask2, 2217 NULL, NULL); 2218 listen_change_state(card, EV_LISTEN_REQ); 2219 send_message(card, &cmdcmsg); 2220} 2221 2222static void listentimerfunc(unsigned long x) 2223{ 2224 capidrv_contr *card = (capidrv_contr *)x; 2225 if (card->state != ST_LISTEN_NONE && card->state != ST_LISTEN_ACTIVE) 2226 printk(KERN_ERR "%s: controller dead ??\n", card->name); 2227 send_listen(card); 2228 mod_timer(&card->listentimer, jiffies + 60 * HZ); 2229} 2230 2231 2232static int capidrv_addcontr(u16 contr, struct capi_profile *profp) 2233{ 2234 capidrv_contr *card; 2235 unsigned long flags; 2236 isdn_ctrl cmd; 2237 char id[20]; 2238 int i; 2239 2240 sprintf(id, "capidrv-%d", contr); 2241 if (!try_module_get(THIS_MODULE)) { 2242 printk(KERN_WARNING "capidrv: (%s) Could not reserve module\n", id); 2243 return -1; 2244 } 2245 if (!(card = kzalloc(sizeof(capidrv_contr), GFP_ATOMIC))) { 2246 printk(KERN_WARNING 2247 "capidrv: (%s) Could not allocate contr-struct.\n", id); 2248 return -1; 2249 } 2250 card->owner = THIS_MODULE; 2251 init_timer(&card->listentimer); 2252 strcpy(card->name, id); 2253 card->contrnr = contr; 2254 card->nbchan = profp->nbchannel; 2255 card->bchans = kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC); 2256 if (!card->bchans) { 2257 printk(KERN_WARNING 2258 "capidrv: (%s) Could not allocate bchan-structs.\n", id); 2259 module_put(card->owner); 2260 kfree(card); 2261 return -1; 2262 } 2263 card->interface.channels = profp->nbchannel; 2264 card->interface.maxbufsize = 2048; 2265 card->interface.command = if_command; 2266 card->interface.writebuf_skb = if_sendbuf; 2267 card->interface.writecmd = NULL; 2268 card->interface.readstat = if_readstat; 2269 card->interface.features = 2270 ISDN_FEATURE_L2_HDLC | 2271 ISDN_FEATURE_L2_TRANS | 2272 ISDN_FEATURE_L3_TRANS | 2273 ISDN_FEATURE_P_UNKNOWN | 2274 ISDN_FEATURE_L2_X75I | 2275 ISDN_FEATURE_L2_X75UI | 2276 ISDN_FEATURE_L2_X75BUI; 2277 if (profp->support1 & (1 << 2)) 2278 card->interface.features |= 2279 ISDN_FEATURE_L2_V11096 | 2280 ISDN_FEATURE_L2_V11019 | 2281 ISDN_FEATURE_L2_V11038; 2282 if (profp->support1 & (1 << 8)) 2283 card->interface.features |= ISDN_FEATURE_L2_MODEM; 2284 card->interface.hl_hdrlen = 22; /* len of DATA_B3_REQ */ 2285 strncpy(card->interface.id, id, sizeof(card->interface.id) - 1); 2286 2287 2288 card->q931_read = card->q931_buf; 2289 card->q931_write = card->q931_buf; 2290 card->q931_end = card->q931_buf + sizeof(card->q931_buf) - 1; 2291 2292 if (!register_isdn(&card->interface)) { 2293 printk(KERN_ERR "capidrv: Unable to register contr %s\n", id); 2294 kfree(card->bchans); 2295 module_put(card->owner); 2296 kfree(card); 2297 return -1; 2298 } 2299 card->myid = card->interface.channels; 2300 memset(card->bchans, 0, sizeof(capidrv_bchan) * card->nbchan); 2301 for (i = 0; i < card->nbchan; i++) { 2302 card->bchans[i].contr = card; 2303 } 2304 2305 spin_lock_irqsave(&global_lock, flags); 2306 card->next = global.contr_list; 2307 global.contr_list = card; 2308 global.ncontr++; 2309 spin_unlock_irqrestore(&global_lock, flags); 2310 2311 cmd.command = ISDN_STAT_RUN; 2312 cmd.driver = card->myid; 2313 card->interface.statcallb(&cmd); 2314 2315 card->cipmask = 0x1FFF03FF; /* any */ 2316 card->cipmask2 = 0; 2317 2318 card->listentimer.data = (unsigned long)card; 2319 card->listentimer.function = listentimerfunc; 2320 send_listen(card); 2321 mod_timer(&card->listentimer, jiffies + 60 * HZ); 2322 2323 printk(KERN_INFO "%s: now up (%d B channels)\n", 2324 card->name, card->nbchan); 2325 2326 enable_dchannel_trace(card); 2327 2328 return 0; 2329} 2330 2331static int capidrv_delcontr(u16 contr) 2332{ 2333 capidrv_contr **pp, *card; 2334 unsigned long flags; 2335 isdn_ctrl cmd; 2336 2337 spin_lock_irqsave(&global_lock, flags); 2338 for (card = global.contr_list; card; card = card->next) { 2339 if (card->contrnr == contr) 2340 break; 2341 } 2342 if (!card) { 2343 spin_unlock_irqrestore(&global_lock, flags); 2344 printk(KERN_ERR "capidrv: delcontr: no contr %u\n", contr); 2345 return -1; 2346 } 2347 2348 /* FIXME: maybe a race condition the card should be removed 2349 * here from global list /kkeil 2350 */ 2351 spin_unlock_irqrestore(&global_lock, flags); 2352 2353 del_timer(&card->listentimer); 2354 2355 if (debugmode) 2356 printk(KERN_DEBUG "capidrv-%d: id=%d unloading\n", 2357 card->contrnr, card->myid); 2358 2359 cmd.command = ISDN_STAT_STOP; 2360 cmd.driver = card->myid; 2361 card->interface.statcallb(&cmd); 2362 2363 while (card->nbchan) { 2364 2365 cmd.command = ISDN_STAT_DISCH; 2366 cmd.driver = card->myid; 2367 cmd.arg = card->nbchan - 1; 2368 cmd.parm.num[0] = 0; 2369 if (debugmode) 2370 printk(KERN_DEBUG "capidrv-%d: id=%d disable chan=%ld\n", 2371 card->contrnr, card->myid, cmd.arg); 2372 card->interface.statcallb(&cmd); 2373 2374 if (card->bchans[card->nbchan - 1].nccip) 2375 free_ncci(card, card->bchans[card->nbchan - 1].nccip); 2376 if (card->bchans[card->nbchan - 1].plcip) 2377 free_plci(card, card->bchans[card->nbchan - 1].plcip); 2378 if (card->plci_list) 2379 printk(KERN_ERR "capidrv: bug in free_plci()\n"); 2380 card->nbchan--; 2381 } 2382 kfree(card->bchans); 2383 card->bchans = NULL; 2384 2385 if (debugmode) 2386 printk(KERN_DEBUG "capidrv-%d: id=%d isdn unload\n", 2387 card->contrnr, card->myid); 2388 2389 cmd.command = ISDN_STAT_UNLOAD; 2390 cmd.driver = card->myid; 2391 card->interface.statcallb(&cmd); 2392 2393 if (debugmode) 2394 printk(KERN_DEBUG "capidrv-%d: id=%d remove contr from list\n", 2395 card->contrnr, card->myid); 2396 2397 spin_lock_irqsave(&global_lock, flags); 2398 for (pp = &global.contr_list; *pp; pp = &(*pp)->next) { 2399 if (*pp == card) { 2400 *pp = (*pp)->next; 2401 card->next = NULL; 2402 global.ncontr--; 2403 break; 2404 } 2405 } 2406 spin_unlock_irqrestore(&global_lock, flags); 2407 2408 module_put(card->owner); 2409 printk(KERN_INFO "%s: now down.\n", card->name); 2410 kfree(card); 2411 return 0; 2412} 2413 2414 2415static int 2416lower_callback(struct notifier_block *nb, unsigned long val, void *v) 2417{ 2418 capi_profile profile; 2419 u32 contr = (long)v; 2420 2421 switch (val) { 2422 case CAPICTR_UP: 2423 printk(KERN_INFO "capidrv: controller %hu up\n", contr); 2424 if (capi20_get_profile(contr, &profile) == CAPI_NOERROR) 2425 (void) capidrv_addcontr(contr, &profile); 2426 break; 2427 case CAPICTR_DOWN: 2428 printk(KERN_INFO "capidrv: controller %hu down\n", contr); 2429 (void) capidrv_delcontr(contr); 2430 break; 2431 } 2432 return NOTIFY_OK; 2433} 2434 2435/* 2436 * /proc/capi/capidrv: 2437 * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt 2438 */ 2439static int capidrv_proc_show(struct seq_file *m, void *v) 2440{ 2441 seq_printf(m, "%lu %lu %lu %lu\n", 2442 global.ap.nrecvctlpkt, 2443 global.ap.nrecvdatapkt, 2444 global.ap.nsentctlpkt, 2445 global.ap.nsentdatapkt); 2446 return 0; 2447} 2448 2449static int capidrv_proc_open(struct inode *inode, struct file *file) 2450{ 2451 return single_open(file, capidrv_proc_show, NULL); 2452} 2453 2454static const struct file_operations capidrv_proc_fops = { 2455 .owner = THIS_MODULE, 2456 .open = capidrv_proc_open, 2457 .read = seq_read, 2458 .llseek = seq_lseek, 2459 .release = single_release, 2460}; 2461 2462static void __init proc_init(void) 2463{ 2464 proc_create("capi/capidrv", 0, NULL, &capidrv_proc_fops); 2465} 2466 2467static void __exit proc_exit(void) 2468{ 2469 remove_proc_entry("capi/capidrv", NULL); 2470} 2471 2472static struct notifier_block capictr_nb = { 2473 .notifier_call = lower_callback, 2474}; 2475 2476static int __init capidrv_init(void) 2477{ 2478 capi_profile profile; 2479 u32 ncontr, contr; 2480 u16 errcode; 2481 2482 global.ap.rparam.level3cnt = -2; /* number of bchannels twice */ 2483 global.ap.rparam.datablkcnt = 16; 2484 global.ap.rparam.datablklen = 2048; 2485 2486 global.ap.recv_message = capidrv_recv_message; 2487 errcode = capi20_register(&global.ap); 2488 if (errcode) { 2489 return -EIO; 2490 } 2491 2492 register_capictr_notifier(&capictr_nb); 2493 2494 errcode = capi20_get_profile(0, &profile); 2495 if (errcode != CAPI_NOERROR) { 2496 unregister_capictr_notifier(&capictr_nb); 2497 capi20_release(&global.ap); 2498 return -EIO; 2499 } 2500 2501 ncontr = profile.ncontroller; 2502 for (contr = 1; contr <= ncontr; contr++) { 2503 errcode = capi20_get_profile(contr, &profile); 2504 if (errcode != CAPI_NOERROR) 2505 continue; 2506 (void) capidrv_addcontr(contr, &profile); 2507 } 2508 proc_init(); 2509 2510 return 0; 2511} 2512 2513static void __exit capidrv_exit(void) 2514{ 2515 unregister_capictr_notifier(&capictr_nb); 2516 capi20_release(&global.ap); 2517 2518 proc_exit(); 2519} 2520 2521module_init(capidrv_init); 2522module_exit(capidrv_exit);