1 /* $Id: capi.c,v 1.1.1.1 2005/04/11 02:50:22 jack Exp $
3 * CAPI 2.0 Interface for Linux
5 * Copyright 1996 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/config.h>
13 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/major.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
19 #include <linux/fcntl.h>
21 #include <linux/signal.h>
23 #include <linux/smp_lock.h>
24 #include <linux/timer.h>
25 #include <linux/wait.h>
26 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
27 #include <linux/tty.h>
29 #include <linux/netdevice.h>
30 #include <linux/ppp_defs.h>
31 #include <linux/if_ppp.h>
32 #undef CAPI_PPP_ON_RAW_DEVICE
33 #endif /* CONFIG_PPP */
34 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
35 #include <linux/skbuff.h>
36 #include <linux/proc_fs.h>
37 #include <linux/poll.h>
38 #include <linux/capi.h>
39 #include <linux/kernelcapi.h>
40 #include <linux/init.h>
41 #include <linux/devfs_fs_kernel.h>
44 #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
48 static char *revision = "$Revision: 1.1.1.1 $";
50 MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface");
51 MODULE_AUTHOR("Carsten Paeth");
52 MODULE_LICENSE("GPL");
54 #undef _DEBUG_REFCOUNT /* alloc/free and open/close debug */
55 #undef _DEBUG_TTYFUNCS /* call to tty_driver */
56 #undef _DEBUG_DATAFLOW /* data flow */
58 /* -------- driver information -------------------------------------- */
60 int capi_major = 68; /* allocated */
61 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
62 int capi_rawmajor = 190;
63 int capi_ttymajor = 191;
64 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
66 MODULE_PARM(capi_major, "i");
67 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
68 MODULE_PARM(capi_rawmajor, "i");
69 MODULE_PARM(capi_ttymajor, "i");
70 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
72 /* -------- defines ------------------------------------------------- */
74 #define CAPINC_MAX_RECVQUEUE 10
75 #define CAPINC_MAX_SENDQUEUE 10
76 #define CAPI_MAX_BLKSIZE 2048
78 /* -------- data structures ----------------------------------------- */
82 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
86 struct capiminor *next;
87 struct capincci *nccip;
96 struct tty_struct *tty;
99 struct sk_buff *ttyskb;
100 atomic_t ttyopencount;
102 struct sk_buff_head inqueue;
104 struct sk_buff_head outqueue;
108 struct sk_buff_head recvqueue;
109 wait_queue_head_t recvwait;
110 wait_queue_head_t sendwait;
113 struct datahandle_queue {
114 struct datahandle_queue *next;
120 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
123 struct capincci *next;
125 struct capidev *cdev;
126 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
127 struct capiminor *minorp;
128 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
132 struct capidev *next;
139 struct sk_buff_head recvqueue;
140 wait_queue_head_t recvwait;
143 unsigned long nrecvctlpkt;
144 unsigned long nrecvdatapkt;
145 unsigned long nsentctlpkt;
146 unsigned long nsentdatapkt;
148 struct capincci *nccis;
151 /* -------- global variables ---------------------------------------- */
153 static struct capi_interface *capifuncs = 0;
154 static struct capidev *capidev_openlist = 0;
155 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
156 static struct capiminor *minors = 0;
157 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
159 static kmem_cache_t *capidev_cachep = 0;
160 static kmem_cache_t *capincci_cachep = 0;
161 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
162 static kmem_cache_t *capiminor_cachep = 0;
163 static kmem_cache_t *capidh_cachep = 0;
164 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
166 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
167 /* -------- datahandles --------------------------------------------- */
169 static int capincci_add_ack(struct capiminor *mp, u16 datahandle)
171 struct datahandle_queue *n, **pp;
173 n = (struct datahandle_queue *)
174 kmem_cache_alloc(capidh_cachep, GFP_ATOMIC);
176 printk(KERN_ERR "capi: alloc datahandle failed\n");
180 n->datahandle = datahandle;
181 for (pp = &mp->ackqueue; *pp; pp = &(*pp)->next) ;
187 static int capiminor_del_ack(struct capiminor *mp, u16 datahandle)
189 struct datahandle_queue **pp, *p;
191 for (pp = &mp->ackqueue; *pp; pp = &(*pp)->next) {
192 if ((*pp)->datahandle == datahandle) {
195 kmem_cache_free(capidh_cachep, p);
203 static void capiminor_del_all_ack(struct capiminor *mp)
205 struct datahandle_queue **pp, *p;
211 kmem_cache_free(capidh_cachep, p);
217 /* -------- struct capiminor ---------------------------------------- */
219 static struct capiminor *capiminor_alloc(u16 applid, u32 ncci)
221 struct capiminor *mp, **pp;
222 unsigned int minor = 0;
225 mp = (struct capiminor *)kmem_cache_alloc(capiminor_cachep, GFP_ATOMIC);
228 printk(KERN_ERR "capi: can't alloc capiminor\n");
231 #ifdef _DEBUG_REFCOUNT
232 printk(KERN_DEBUG "capiminor_alloc %d\n", GET_USE_COUNT(THIS_MODULE));
234 memset(mp, 0, sizeof(struct capiminor));
238 atomic_set(&mp->ttyopencount,0);
240 skb_queue_head_init(&mp->inqueue);
241 skb_queue_head_init(&mp->outqueue);
243 skb_queue_head_init(&mp->recvqueue);
244 init_waitqueue_head(&mp->recvwait);
245 init_waitqueue_head(&mp->sendwait);
247 for (pp = &minors; *pp; pp = &(*pp)->next) {
248 if ((*pp)->minor < minor)
250 if ((*pp)->minor > minor)
260 static void capiminor_free(struct capiminor *mp)
262 struct capiminor **pp;
268 if (mp->ttyskb) kfree_skb(mp->ttyskb);
270 skb_queue_purge(&mp->recvqueue);
271 skb_queue_purge(&mp->inqueue);
272 skb_queue_purge(&mp->outqueue);
273 capiminor_del_all_ack(mp);
274 kmem_cache_free(capiminor_cachep, mp);
276 #ifdef _DEBUG_REFCOUNT
277 printk(KERN_DEBUG "capiminor_free %d\n", GET_USE_COUNT(THIS_MODULE));
286 static struct capiminor *capiminor_find(unsigned int minor)
289 for (p = minors; p && p->minor != minor; p = p->next)
293 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
295 /* -------- struct capincci ----------------------------------------- */
297 static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
299 struct capincci *np, **pp;
300 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
301 struct capiminor *mp = 0;
303 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
305 np = (struct capincci *)kmem_cache_alloc(capincci_cachep, GFP_ATOMIC);
308 memset(np, 0, sizeof(struct capincci));
311 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
313 if (cdev->userflags & CAPIFLAG_HIGHJACKING)
314 mp = np->minorp = capiminor_alloc(cdev->applid, ncci);
317 #ifdef _DEBUG_REFCOUNT
318 printk(KERN_DEBUG "set mp->nccip\n");
320 #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
321 kdev = MKDEV(capi_rawmajor, mp->minor);
322 capifs_new_ncci('r', mp->minor, kdev);
323 kdev = MKDEV(capi_ttymajor, mp->minor);
324 capifs_new_ncci(0, mp->minor, kdev);
327 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
328 for (pp=&cdev->nccis; *pp; pp = &(*pp)->next)
334 static void capincci_free(struct capidev *cdev, u32 ncci)
336 struct capincci *np, **pp;
337 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
338 struct capiminor *mp;
339 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
344 if (ncci == 0xffffffff || np->ncci == ncci) {
346 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
347 if ((mp = np->minorp) != 0) {
348 #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
349 capifs_free_ncci('r', mp->minor);
350 capifs_free_ncci(0, mp->minor);
354 #ifdef _DEBUG_REFCOUNT
355 printk(KERN_DEBUG "reset mp->nccip\n");
358 } else if (mp->file) {
360 #ifdef _DEBUG_REFCOUNT
361 printk(KERN_DEBUG "reset mp->nccip\n");
363 wake_up_interruptible(&mp->recvwait);
364 wake_up_interruptible(&mp->sendwait);
369 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
370 kmem_cache_free(capincci_cachep, np);
371 if (*pp == 0) return;
378 static struct capincci *capincci_find(struct capidev *cdev, u32 ncci)
382 for (p=cdev->nccis; p ; p = p->next) {
389 /* -------- struct capidev ------------------------------------------ */
391 static struct capidev *capidev_alloc(struct file *file)
393 struct capidev *cdev;
396 cdev = (struct capidev *)kmem_cache_alloc(capidev_cachep, GFP_KERNEL);
399 memset(cdev, 0, sizeof(struct capidev));
401 cdev->minor = MINOR(file->f_dentry->d_inode->i_rdev);
403 skb_queue_head_init(&cdev->recvqueue);
404 init_waitqueue_head(&cdev->recvwait);
405 pp=&capidev_openlist;
406 while (*pp) pp = &(*pp)->next;
411 static void capidev_free(struct capidev *cdev)
416 (*capifuncs->capi_release) (cdev->applid);
419 skb_queue_purge(&cdev->recvqueue);
421 pp=&capidev_openlist;
422 while (*pp && *pp != cdev) pp = &(*pp)->next;
426 kmem_cache_free(capidev_cachep, cdev);
429 static struct capidev *capidev_find(u16 applid)
432 for (p=capidev_openlist; p; p = p->next) {
433 if (p->applid == applid)
439 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
440 /* -------- handle data queue --------------------------------------- */
442 static struct sk_buff *
443 gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
445 struct sk_buff *nskb;
446 nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_ATOMIC);
448 u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2);
449 unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN);
450 capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN);
451 capimsg_setu16(s, 2, mp->applid);
452 capimsg_setu8 (s, 4, CAPI_DATA_B3);
453 capimsg_setu8 (s, 5, CAPI_RESP);
454 capimsg_setu16(s, 6, mp->msgid++);
455 capimsg_setu32(s, 8, mp->ncci);
456 capimsg_setu16(s, 12, datahandle);
461 static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)
463 struct sk_buff *nskb;
464 unsigned int datalen;
465 u16 errcode, datahandle;
467 datalen = skb->len - CAPIMSG_LEN(skb->data);
469 if (mp->tty->ldisc.receive_buf == 0) {
470 printk(KERN_ERR "capi: ldisc has no receive_buf function\n");
474 #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
475 printk(KERN_DEBUG "capi: recv tty throttled\n");
479 if (mp->tty->ldisc.receive_room &&
480 mp->tty->ldisc.receive_room(mp->tty) < datalen) {
481 #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
482 printk(KERN_DEBUG "capi: no room in tty\n");
486 if ((nskb = gen_data_b3_resp_for(mp, skb)) == 0) {
487 printk(KERN_ERR "capi: gen_data_b3_resp failed\n");
490 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4);
491 errcode = (*capifuncs->capi_put_message)(mp->applid, nskb);
492 if (errcode != CAPI_NOERROR) {
493 printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n",
498 (void)skb_pull(skb, CAPIMSG_LEN(skb->data));
499 #ifdef _DEBUG_DATAFLOW
500 printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n",
501 datahandle, skb->len);
503 mp->tty->ldisc.receive_buf(mp->tty, skb->data, 0, skb->len);
507 } else if (mp->file) {
508 if (skb_queue_len(&mp->recvqueue) > CAPINC_MAX_RECVQUEUE) {
509 #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
510 printk(KERN_DEBUG "capi: no room in raw queue\n");
514 if ((nskb = gen_data_b3_resp_for(mp, skb)) == 0) {
515 printk(KERN_ERR "capi: gen_data_b3_resp failed\n");
518 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4);
519 errcode = (*capifuncs->capi_put_message)(mp->applid, nskb);
520 if (errcode != CAPI_NOERROR) {
521 printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n",
526 (void)skb_pull(skb, CAPIMSG_LEN(skb->data));
527 #ifdef _DEBUG_DATAFLOW
528 printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => raw\n",
529 datahandle, skb->len);
531 skb_queue_tail(&mp->recvqueue, skb);
532 wake_up_interruptible(&mp->recvwait);
535 #ifdef _DEBUG_DATAFLOW
536 printk(KERN_DEBUG "capi: currently no receiver\n");
541 static void handle_minor_recv(struct capiminor *mp)
544 while ((skb = skb_dequeue(&mp->inqueue)) != 0) {
545 unsigned int len = skb->len;
547 if (handle_recv_skb(mp, skb) < 0) {
548 skb_queue_head(&mp->inqueue, skb);
555 static int handle_minor_send(struct capiminor *mp)
563 if (mp->tty && mp->ttyoutstop) {
564 #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
565 printk(KERN_DEBUG "capi: send: tty stopped\n");
570 while ((skb = skb_dequeue(&mp->outqueue)) != 0) {
571 datahandle = mp->datahandle;
573 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
574 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
575 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
576 capimsg_setu16(skb->data, 2, mp->applid);
577 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
578 capimsg_setu8 (skb->data, 5, CAPI_REQ);
579 capimsg_setu16(skb->data, 6, mp->msgid++);
580 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
581 capimsg_setu32(skb->data, 12, (u32) skb->data); /* Data32 */
582 capimsg_setu16(skb->data, 16, len); /* Data length */
583 capimsg_setu16(skb->data, 18, datahandle);
584 capimsg_setu16(skb->data, 20, 0); /* Flags */
586 if (capincci_add_ack(mp, datahandle) < 0) {
587 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
588 skb_queue_head(&mp->outqueue, skb);
591 errcode = (*capifuncs->capi_put_message) (mp->applid, skb);
592 if (errcode == CAPI_NOERROR) {
596 #ifdef _DEBUG_DATAFLOW
597 printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n",
602 capiminor_del_ack(mp, datahandle);
604 if (errcode == CAPI_SENDQUEUEFULL) {
605 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
606 skb_queue_head(&mp->outqueue, skb);
610 /* ups, drop packet */
611 printk(KERN_ERR "capi: put_message = %x\n", errcode);
616 wake_up_interruptible(&mp->sendwait);
620 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
621 /* -------- function called by lower level -------------------------- */
623 static void capi_signal(u16 applid, void *param)
625 struct capidev *cdev = (struct capidev *)param;
626 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
627 struct capiminor *mp;
629 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
631 struct sk_buff *skb = 0;
634 (void) (*capifuncs->capi_get_message) (applid, &skb);
636 printk(KERN_ERR "BUG: capi_signal: no skb\n");
640 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
641 skb_queue_tail(&cdev->recvqueue, skb);
642 wake_up_interruptible(&cdev->recvwait);
645 ncci = CAPIMSG_CONTROL(skb->data);
646 for (np = cdev->nccis; np && np->ncci != ncci; np = np->next)
649 printk(KERN_ERR "BUG: capi_signal: ncci not found\n");
650 skb_queue_tail(&cdev->recvqueue, skb);
651 wake_up_interruptible(&cdev->recvwait);
654 #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
655 skb_queue_tail(&cdev->recvqueue, skb);
656 wake_up_interruptible(&cdev->recvwait);
657 #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
660 skb_queue_tail(&cdev->recvqueue, skb);
661 wake_up_interruptible(&cdev->recvwait);
666 if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) {
667 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2);
668 #ifdef _DEBUG_DATAFLOW
669 printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n",
670 datahandle, skb->len-CAPIMSG_LEN(skb->data));
672 skb_queue_tail(&mp->inqueue, skb);
673 mp->inbytes += skb->len;
674 handle_minor_recv(mp);
676 } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) {
678 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4);
679 #ifdef _DEBUG_DATAFLOW
680 printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n",
682 CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2));
685 (void)capiminor_del_ack(mp, datahandle);
687 if (mp->tty->ldisc.write_wakeup)
688 mp->tty->ldisc.write_wakeup(mp->tty);
690 wake_up_interruptible(&mp->sendwait);
692 (void)handle_minor_send(mp);
695 /* ups, let capi application handle it :-) */
696 skb_queue_tail(&cdev->recvqueue, skb);
697 wake_up_interruptible(&cdev->recvwait);
699 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
702 /* -------- file_operations for capidev ----------------------------- */
705 capi_read(struct file *file, char *buf, size_t count, loff_t *ppos)
707 struct capidev *cdev = (struct capidev *)file->private_data;
712 if (ppos != &file->f_pos)
718 if ((skb = skb_dequeue(&cdev->recvqueue)) == 0) {
720 if (file->f_flags & O_NONBLOCK)
724 interruptible_sleep_on(&cdev->recvwait);
725 if ((skb = skb_dequeue(&cdev->recvqueue)) != 0)
727 if (signal_pending(current))
731 return -ERESTARTNOHAND;
733 if (skb->len > count) {
734 skb_queue_head(&cdev->recvqueue, skb);
737 retval = copy_to_user(buf, skb->data, skb->len);
739 skb_queue_head(&cdev->recvqueue, skb);
744 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_IND) {
745 cdev->nrecvdatapkt++;
756 capi_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
758 struct capidev *cdev = (struct capidev *)file->private_data;
763 if (ppos != &file->f_pos)
769 skb = alloc_skb(count, GFP_USER);
773 if ((retval = copy_from_user(skb_put(skb, count), buf, count))) {
777 mlen = CAPIMSG_LEN(skb->data);
778 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
779 if (mlen + CAPIMSG_DATALEN(skb->data) != count) {
789 CAPIMSG_SETAPPID(skb->data, cdev->applid);
791 cdev->errcode = (*capifuncs->capi_put_message) (cdev->applid, skb);
797 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
798 cdev->nsentdatapkt++;
806 capi_poll(struct file *file, poll_table * wait)
808 struct capidev *cdev = (struct capidev *)file->private_data;
809 unsigned int mask = 0;
814 poll_wait(file, &(cdev->recvwait), wait);
815 mask = POLLOUT | POLLWRNORM;
816 if (!skb_queue_empty(&cdev->recvqueue))
817 mask |= POLLIN | POLLRDNORM;
822 capi_ioctl(struct inode *inode, struct file *file,
823 unsigned int cmd, unsigned long arg)
825 struct capidev *cdev = (struct capidev *)file->private_data;
826 capi_ioctl_struct data;
827 int retval = -EINVAL;
832 retval = copy_from_user((void *) &data.rparams,
833 (void *) arg, sizeof(struct capi_register_params));
838 cdev->errcode = (*capifuncs->capi_register) (&data.rparams,
844 (void) (*capifuncs->capi_set_signal) (cdev->applid, capi_signal, cdev);
846 return (int)cdev->applid;
848 case CAPI_GET_VERSION:
850 retval = copy_from_user((void *) &data.contr,
855 cdev->errcode = (*capifuncs->capi_get_version) (data.contr, &data.version);
858 retval = copy_to_user((void *) arg,
859 (void *) &data.version,
860 sizeof(data.version));
866 case CAPI_GET_SERIAL:
868 retval = copy_from_user((void *) &data.contr,
873 cdev->errcode = (*capifuncs->capi_get_serial) (data.contr, data.serial);
876 retval = copy_to_user((void *) arg,
877 (void *) data.serial,
878 sizeof(data.serial));
883 case CAPI_GET_PROFILE:
885 retval = copy_from_user((void *) &data.contr,
891 if (data.contr == 0) {
892 cdev->errcode = (*capifuncs->capi_get_profile) (data.contr, &data.profile);
896 retval = copy_to_user((void *) arg,
897 (void *) &data.profile.ncontroller,
898 sizeof(data.profile.ncontroller));
901 cdev->errcode = (*capifuncs->capi_get_profile) (data.contr, &data.profile);
905 retval = copy_to_user((void *) arg,
906 (void *) &data.profile,
907 sizeof(data.profile));
914 case CAPI_GET_MANUFACTURER:
916 retval = copy_from_user((void *) &data.contr,
921 cdev->errcode = (*capifuncs->capi_get_manufacturer) (data.contr, data.manufacturer);
925 retval = copy_to_user((void *) arg, (void *) data.manufacturer,
926 sizeof(data.manufacturer));
932 case CAPI_GET_ERRCODE:
933 data.errcode = cdev->errcode;
934 cdev->errcode = CAPI_NOERROR;
936 retval = copy_to_user((void *) arg,
937 (void *) &data.errcode,
938 sizeof(data.errcode));
945 if ((*capifuncs->capi_isinstalled)() == CAPI_NOERROR)
949 case CAPI_MANUFACTURER_CMD:
951 struct capi_manufacturer_cmd mcmd;
952 if (!capable(CAP_SYS_ADMIN))
954 retval = copy_from_user((void *) &mcmd, (void *) arg,
958 return (*capifuncs->capi_manufacturer) (mcmd.cmd, mcmd.data);
966 retval = copy_from_user((void *) &userflags,
971 if (cmd == CAPI_SET_FLAGS)
972 cdev->userflags |= userflags;
974 cdev->userflags &= ~userflags;
980 retval = copy_to_user((void *) arg,
981 (void *) &cdev->userflags,
982 sizeof(cdev->userflags));
988 case CAPI_NCCI_OPENCOUNT:
990 struct capincci *nccip;
991 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
992 struct capiminor *mp;
993 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
996 retval = copy_from_user((void *) &ncci,
1001 nccip = capincci_find(cdev, (u32) ncci);
1004 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1005 if ((mp = nccip->minorp) != 0) {
1006 count += atomic_read(&mp->ttyopencount);
1010 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1015 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1016 case CAPI_NCCI_GETUNIT:
1018 struct capincci *nccip;
1019 struct capiminor *mp;
1021 retval = copy_from_user((void *) &ncci,
1026 nccip = capincci_find(cdev, (u32) ncci);
1027 if (!nccip || (mp = nccip->minorp) == 0)
1032 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1038 capi_open(struct inode *inode, struct file *file)
1040 if (file->private_data)
1043 if ((file->private_data = capidev_alloc(file)) == 0)
1047 #ifdef _DEBUG_REFCOUNT
1048 printk(KERN_DEBUG "capi_open %d\n", GET_USE_COUNT(THIS_MODULE));
1054 capi_release(struct inode *inode, struct file *file)
1056 struct capidev *cdev = (struct capidev *)file->private_data;
1059 capincci_free(cdev, 0xffffffff);
1061 file->private_data = NULL;
1064 #ifdef _DEBUG_REFCOUNT
1065 printk(KERN_DEBUG "capi_release %d\n", GET_USE_COUNT(THIS_MODULE));
1071 static struct file_operations capi_fops =
1080 release: capi_release,
1083 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1084 /* -------- file_operations for capincci ---------------------------- */
1087 capinc_raw_open(struct inode *inode, struct file *file)
1089 struct capiminor *mp;
1091 if (file->private_data)
1093 if ((mp = capiminor_find(MINOR(file->f_dentry->d_inode->i_rdev))) == 0)
1100 #ifdef _DEBUG_REFCOUNT
1101 printk(KERN_DEBUG "capi_raw_open %d\n", GET_USE_COUNT(THIS_MODULE));
1106 file->private_data = (void *)mp;
1107 handle_minor_recv(mp);
1112 capinc_raw_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1114 struct capiminor *mp = (struct capiminor *)file->private_data;
1115 struct sk_buff *skb;
1119 if (ppos != &file->f_pos)
1122 if (!mp || !mp->nccip)
1125 if ((skb = skb_dequeue(&mp->recvqueue)) == 0) {
1127 if (file->f_flags & O_NONBLOCK)
1131 interruptible_sleep_on(&mp->recvwait);
1134 if ((skb = skb_dequeue(&mp->recvqueue)) != 0)
1136 if (signal_pending(current))
1140 return -ERESTARTNOHAND;
1143 if (count < skb->len) {
1144 retval = copy_to_user(buf, skb->data, count);
1146 skb_queue_head(&mp->recvqueue, skb);
1149 skb_pull(skb, count);
1150 skb_queue_head(&mp->recvqueue, skb);
1154 retval = copy_to_user(buf, skb->data, skb->len);
1156 skb_queue_head(&mp->recvqueue, skb);
1164 } while ((skb = skb_dequeue(&mp->recvqueue)) != 0);
1170 capinc_raw_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1172 struct capiminor *mp = (struct capiminor *)file->private_data;
1173 struct sk_buff *skb;
1176 if (ppos != &file->f_pos)
1179 if (!mp || !mp->nccip)
1182 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_USER);
1186 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1187 if ((retval = copy_from_user(skb_put(skb, count), buf, count))) {
1192 while (skb_queue_len(&mp->outqueue) > CAPINC_MAX_SENDQUEUE) {
1193 if (file->f_flags & O_NONBLOCK)
1195 interruptible_sleep_on(&mp->sendwait);
1196 if (mp->nccip == 0) {
1200 if (signal_pending(current))
1201 return -ERESTARTNOHAND;
1203 skb_queue_tail(&mp->outqueue, skb);
1204 mp->outbytes += skb->len;
1205 (void)handle_minor_send(mp);
1210 capinc_raw_poll(struct file *file, poll_table * wait)
1212 struct capiminor *mp = (struct capiminor *)file->private_data;
1213 unsigned int mask = 0;
1215 if (!mp || !mp->nccip)
1216 return POLLERR|POLLHUP;
1218 poll_wait(file, &(mp->recvwait), wait);
1219 if (!skb_queue_empty(&mp->recvqueue))
1220 mask |= POLLIN | POLLRDNORM;
1221 poll_wait(file, &(mp->sendwait), wait);
1222 if (skb_queue_len(&mp->outqueue) > CAPINC_MAX_SENDQUEUE)
1223 mask = POLLOUT | POLLWRNORM;
1228 capinc_raw_ioctl(struct inode *inode, struct file *file,
1229 unsigned int cmd, unsigned long arg)
1231 struct capiminor *mp = (struct capiminor *)file->private_data;
1232 if (!mp || !mp->nccip)
1241 capinc_raw_release(struct inode *inode, struct file *file)
1243 struct capiminor *mp = (struct capiminor *)file->private_data;
1248 if (mp->nccip == 0) {
1250 file->private_data = NULL;
1255 #ifdef _DEBUG_REFCOUNT
1256 printk(KERN_DEBUG "capinc_raw_release %d\n", GET_USE_COUNT(THIS_MODULE));
1261 static struct file_operations capinc_raw_fops =
1265 read: capinc_raw_read,
1266 write: capinc_raw_write,
1267 poll: capinc_raw_poll,
1268 ioctl: capinc_raw_ioctl,
1269 open: capinc_raw_open,
1270 release: capinc_raw_release,
1273 /* -------- tty_operations for capincci ----------------------------- */
1275 static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1277 struct capiminor *mp;
1279 if ((mp = capiminor_find(MINOR(file->f_dentry->d_inode->i_rdev))) == 0)
1286 skb_queue_head_init(&mp->recvqueue);
1287 init_waitqueue_head(&mp->recvwait);
1288 init_waitqueue_head(&mp->sendwait);
1289 tty->driver_data = (void *)mp;
1290 #ifdef _DEBUG_REFCOUNT
1291 printk(KERN_DEBUG "capi_tty_open %d\n", GET_USE_COUNT(THIS_MODULE));
1293 if (atomic_read(&mp->ttyopencount) == 0)
1295 atomic_inc(&mp->ttyopencount);
1296 #ifdef _DEBUG_REFCOUNT
1297 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount));
1299 handle_minor_recv(mp);
1303 static void capinc_tty_close(struct tty_struct * tty, struct file * file)
1305 struct capiminor *mp;
1307 mp = (struct capiminor *)tty->driver_data;
1309 if (atomic_dec_and_test(&mp->ttyopencount)) {
1310 #ifdef _DEBUG_REFCOUNT
1311 printk(KERN_DEBUG "capinc_tty_close lastclose\n");
1313 tty->driver_data = (void *)0;
1316 #ifdef _DEBUG_REFCOUNT
1317 printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount));
1323 #ifdef _DEBUG_REFCOUNT
1324 printk(KERN_DEBUG "capinc_tty_close\n");
1328 static int capinc_tty_write(struct tty_struct * tty, int from_user,
1329 const unsigned char *buf, int count)
1331 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1332 struct sk_buff *skb;
1335 #ifdef _DEBUG_TTYFUNCS
1336 printk(KERN_DEBUG "capinc_tty_write(from_user=%d,count=%d)\n",
1340 if (!mp || !mp->nccip) {
1341 #ifdef _DEBUG_TTYFUNCS
1342 printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n");
1350 skb_queue_tail(&mp->outqueue, skb);
1351 mp->outbytes += skb->len;
1354 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC);
1356 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n");
1360 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1362 if ((retval = copy_from_user(skb_put(skb, count), buf, count))) {
1364 #ifdef _DEBUG_TTYFUNCS
1365 printk(KERN_DEBUG "capinc_tty_write: copy_from_user=%d\n", retval);
1370 memcpy(skb_put(skb, count), buf, count);
1373 skb_queue_tail(&mp->outqueue, skb);
1374 mp->outbytes += skb->len;
1375 (void)handle_minor_send(mp);
1376 (void)handle_minor_recv(mp);
1380 static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1382 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1383 struct sk_buff *skb;
1385 #ifdef _DEBUG_TTYFUNCS
1386 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
1389 if (!mp || !mp->nccip) {
1390 #ifdef _DEBUG_TTYFUNCS
1391 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n");
1398 if (skb_tailroom(skb) > 0) {
1399 *(skb_put(skb, 1)) = ch;
1403 skb_queue_tail(&mp->outqueue, skb);
1404 mp->outbytes += skb->len;
1405 (void)handle_minor_send(mp);
1407 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC);
1409 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1410 *(skb_put(skb, 1)) = ch;
1413 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
1417 static void capinc_tty_flush_chars(struct tty_struct *tty)
1419 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1420 struct sk_buff *skb;
1422 #ifdef _DEBUG_TTYFUNCS
1423 printk(KERN_DEBUG "capinc_tty_flush_chars\n");
1426 if (!mp || !mp->nccip) {
1427 #ifdef _DEBUG_TTYFUNCS
1428 printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n");
1436 skb_queue_tail(&mp->outqueue, skb);
1437 mp->outbytes += skb->len;
1438 (void)handle_minor_send(mp);
1440 (void)handle_minor_recv(mp);
1443 static int capinc_tty_write_room(struct tty_struct *tty)
1445 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1447 if (!mp || !mp->nccip) {
1448 #ifdef _DEBUG_TTYFUNCS
1449 printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n");
1453 room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
1454 room *= CAPI_MAX_BLKSIZE;
1455 #ifdef _DEBUG_TTYFUNCS
1456 printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room);
1461 static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
1463 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1464 if (!mp || !mp->nccip) {
1465 #ifdef _DEBUG_TTYFUNCS
1466 printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n");
1470 #ifdef _DEBUG_TTYFUNCS
1471 printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n",
1472 mp->outbytes, mp->nack,
1473 skb_queue_len(&mp->outqueue),
1474 skb_queue_len(&mp->inqueue));
1476 return mp->outbytes;
1479 static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1480 unsigned int cmd, unsigned long arg)
1485 error = n_tty_ioctl (tty, file, cmd, arg);
1491 static void capinc_tty_set_termios(struct tty_struct *tty, struct termios * old)
1493 #ifdef _DEBUG_TTYFUNCS
1494 printk(KERN_DEBUG "capinc_tty_set_termios\n");
1498 static void capinc_tty_throttle(struct tty_struct * tty)
1500 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1501 #ifdef _DEBUG_TTYFUNCS
1502 printk(KERN_DEBUG "capinc_tty_throttle\n");
1508 static void capinc_tty_unthrottle(struct tty_struct * tty)
1510 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1511 #ifdef _DEBUG_TTYFUNCS
1512 printk(KERN_DEBUG "capinc_tty_unthrottle\n");
1516 handle_minor_recv(mp);
1520 static void capinc_tty_stop(struct tty_struct *tty)
1522 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1523 #ifdef _DEBUG_TTYFUNCS
1524 printk(KERN_DEBUG "capinc_tty_stop\n");
1531 static void capinc_tty_start(struct tty_struct *tty)
1533 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1534 #ifdef _DEBUG_TTYFUNCS
1535 printk(KERN_DEBUG "capinc_tty_start\n");
1539 (void)handle_minor_send(mp);
1543 static void capinc_tty_hangup(struct tty_struct *tty)
1545 #ifdef _DEBUG_TTYFUNCS
1546 printk(KERN_DEBUG "capinc_tty_hangup\n");
1550 static void capinc_tty_break_ctl(struct tty_struct *tty, int state)
1552 #ifdef _DEBUG_TTYFUNCS
1553 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1557 static void capinc_tty_flush_buffer(struct tty_struct *tty)
1559 #ifdef _DEBUG_TTYFUNCS
1560 printk(KERN_DEBUG "capinc_tty_flush_buffer\n");
1564 static void capinc_tty_set_ldisc(struct tty_struct *tty)
1566 #ifdef _DEBUG_TTYFUNCS
1567 printk(KERN_DEBUG "capinc_tty_set_ldisc\n");
1571 static void capinc_tty_send_xchar(struct tty_struct *tty, char ch)
1573 #ifdef _DEBUG_TTYFUNCS
1574 printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch);
1578 static int capinc_tty_read_proc(char *page, char **start, off_t off,
1579 int count, int *eof, void *data)
1584 #define CAPINC_NR_PORTS 256
1585 static struct tty_driver capinc_tty_driver;
1586 static int capinc_tty_refcount;
1587 static struct tty_struct *capinc_tty_table[CAPINC_NR_PORTS];
1588 static struct termios *capinc_tty_termios[CAPINC_NR_PORTS];
1589 static struct termios *capinc_tty_termios_locked[CAPINC_NR_PORTS];
1591 static int capinc_tty_init(void)
1593 struct tty_driver *drv = &capinc_tty_driver;
1595 /* Initialize the tty_driver structure */
1597 memset(drv, 0, sizeof(struct tty_driver));
1598 drv->magic = TTY_DRIVER_MAGIC;
1599 #if (LINUX_VERSION_CODE > 0x20100)
1600 drv->driver_name = "capi_nc";
1602 drv->name = "capi/%d";
1603 drv->major = capi_ttymajor;
1604 drv->minor_start = 0;
1605 drv->num = CAPINC_NR_PORTS;
1606 drv->type = TTY_DRIVER_TYPE_SERIAL;
1607 drv->subtype = SERIAL_TYPE_NORMAL;
1608 drv->init_termios = tty_std_termios;
1609 drv->init_termios.c_iflag = ICRNL;
1610 drv->init_termios.c_oflag = OPOST | ONLCR;
1611 drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1612 drv->init_termios.c_lflag = 0;
1613 drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS;
1614 drv->refcount = &capinc_tty_refcount;
1615 drv->table = capinc_tty_table;
1616 drv->termios = capinc_tty_termios;
1617 drv->termios_locked = capinc_tty_termios_locked;
1619 drv->open = capinc_tty_open;
1620 drv->close = capinc_tty_close;
1621 drv->write = capinc_tty_write;
1622 drv->put_char = capinc_tty_put_char;
1623 drv->flush_chars = capinc_tty_flush_chars;
1624 drv->write_room = capinc_tty_write_room;
1625 drv->chars_in_buffer = capinc_tty_chars_in_buffer;
1626 drv->ioctl = capinc_tty_ioctl;
1627 drv->set_termios = capinc_tty_set_termios;
1628 drv->throttle = capinc_tty_throttle;
1629 drv->unthrottle = capinc_tty_unthrottle;
1630 drv->stop = capinc_tty_stop;
1631 drv->start = capinc_tty_start;
1632 drv->hangup = capinc_tty_hangup;
1633 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
1634 drv->break_ctl = capinc_tty_break_ctl;
1636 drv->flush_buffer = capinc_tty_flush_buffer;
1637 drv->set_ldisc = capinc_tty_set_ldisc;
1638 #if (LINUX_VERSION_CODE >= 131343)
1639 drv->send_xchar = capinc_tty_send_xchar;
1640 drv->read_proc = capinc_tty_read_proc;
1642 if (tty_register_driver(drv)) {
1643 printk(KERN_ERR "Couldn't register capi_nc driver\n");
1649 static void capinc_tty_exit(void)
1651 struct tty_driver *drv = &capinc_tty_driver;
1653 if ((retval = tty_unregister_driver(drv)))
1654 printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
1657 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1659 /* -------- /proc functions ----------------------------------------- */
1662 * /proc/capi/capi20:
1663 * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
1665 static int proc_capidev_read_proc(char *page, char **start, off_t off,
1666 int count, int *eof, void *data)
1668 struct capidev *cdev;
1671 for (cdev=capidev_openlist; cdev; cdev = cdev->next) {
1672 len += sprintf(page+len, "%d %d %lu %lu %lu %lu\n",
1678 cdev->nsentdatapkt);
1683 if (len-off > count)
1690 if (len>count) len = count;
1696 * /proc/capi/capi20ncci:
1699 static int proc_capincci_read_proc(char *page, char **start, off_t off,
1700 int count, int *eof, void *data)
1702 struct capidev *cdev;
1703 struct capincci *np;
1706 for (cdev=capidev_openlist; cdev; cdev = cdev->next) {
1707 for (np=cdev->nccis; np; np = np->next) {
1708 len += sprintf(page+len, "%d 0x%x%s\n",
1711 #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
1713 #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1714 np->minorp && np->minorp->file ? " open" : "");
1715 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1720 if (len-off > count)
1729 if (len>count) len = count;
1734 static struct procfsentries {
1737 int (*read_proc)(char *page, char **start, off_t off,
1738 int count, int *eof, void *data);
1739 struct proc_dir_entry *procent;
1740 } procfsentries[] = {
1741 /* { "capi", S_IFDIR, 0 }, */
1742 { "capi/capi20", 0 , proc_capidev_read_proc },
1743 { "capi/capi20ncci", 0 , proc_capincci_read_proc },
1746 static void __init proc_init(void)
1748 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
1751 for (i=0; i < nelem; i++) {
1752 struct procfsentries *p = procfsentries + i;
1753 p->procent = create_proc_entry(p->name, p->mode, 0);
1754 if (p->procent) p->procent->read_proc = p->read_proc;
1758 static void __exit proc_exit(void)
1760 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
1763 for (i=nelem-1; i >= 0; i--) {
1764 struct procfsentries *p = procfsentries + i;
1766 remove_proc_entry(p->name, 0);
1772 /* -------- init function and module interface ---------------------- */
1775 static void alloc_exit(void)
1777 if (capidev_cachep) {
1778 (void)kmem_cache_destroy(capidev_cachep);
1781 if (capincci_cachep) {
1782 (void)kmem_cache_destroy(capincci_cachep);
1783 capincci_cachep = 0;
1785 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1786 if (capidh_cachep) {
1787 (void)kmem_cache_destroy(capidh_cachep);
1790 if (capiminor_cachep) {
1791 (void)kmem_cache_destroy(capiminor_cachep);
1792 capiminor_cachep = 0;
1794 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1797 static int __init alloc_init(void)
1799 capidev_cachep = kmem_cache_create("capi20_dev",
1800 sizeof(struct capidev),
1804 if (!capidev_cachep) {
1809 capincci_cachep = kmem_cache_create("capi20_ncci",
1810 sizeof(struct capincci),
1814 if (!capincci_cachep) {
1818 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1819 capidh_cachep = kmem_cache_create("capi20_dh",
1820 sizeof(struct datahandle_queue),
1824 if (!capidh_cachep) {
1828 capiminor_cachep = kmem_cache_create("capi20_minor",
1829 sizeof(struct capiminor),
1833 if (!capiminor_cachep) {
1837 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1841 static void lower_callback(unsigned int cmd, u32 contr, void *data)
1843 struct capi_ncciinfo *np;
1844 struct capidev *cdev;
1848 printk(KERN_INFO "capi: controller %hu up\n", contr);
1851 printk(KERN_INFO "capi: controller %hu down\n", contr);
1854 np = (struct capi_ncciinfo *)data;
1855 if ((cdev = capidev_find(np->applid)) == 0)
1857 (void)capincci_alloc(cdev, np->ncci);
1860 np = (struct capi_ncciinfo *)data;
1861 if ((cdev = capidev_find(np->applid)) == 0)
1863 (void)capincci_free(cdev, np->ncci);
1868 static struct capi_interface_user cuser = {
1870 callback: lower_callback,
1873 static char rev[32];
1875 static int __init capi_init(void)
1882 if ((p = strchr(revision, ':')) != 0 && p[1]) {
1883 strncpy(rev, p + 2, sizeof(rev));
1884 rev[sizeof(rev)-1] = 0;
1885 if ((p = strchr(rev, '$')) != 0 && p > rev)
1890 if (devfs_register_chrdev(capi_major, "capi20", &capi_fops)) {
1891 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
1896 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1897 if (devfs_register_chrdev(capi_rawmajor, "capi/r%d", &capinc_raw_fops)) {
1898 devfs_unregister_chrdev(capi_major, "capi20");
1899 printk(KERN_ERR "capi20: unable to get major %d\n", capi_rawmajor);
1903 devfs_register_series (NULL, "capi/r%u", CAPINC_NR_PORTS,
1906 S_IFCHR | S_IRUSR | S_IWUSR,
1907 &capinc_raw_fops, NULL);
1908 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1909 devfs_register (NULL, "isdn/capi20", DEVFS_FL_DEFAULT,
1910 capi_major, 0, S_IFCHR | S_IRUSR | S_IWUSR,
1912 printk(KERN_NOTICE "capi20: started up with major %d\n", capi_major);
1914 if ((capifuncs = attach_capi_interface(&cuser)) == 0) {
1917 devfs_unregister_chrdev(capi_major, "capi20");
1918 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1919 devfs_unregister_chrdev(capi_rawmajor, "capi/r%d");
1920 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1921 devfs_unregister(devfs_find_handle(NULL, "capi20",
1923 DEVFS_SPECIAL_CHR, 0));
1927 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1928 if (capinc_tty_init() < 0) {
1929 (void) detach_capi_interface(&cuser);
1930 devfs_unregister_chrdev(capi_major, "capi20");
1931 devfs_unregister_chrdev(capi_rawmajor, "capi/r%d");
1935 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1937 if (alloc_init() < 0) {
1938 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1940 devfs_unregister_chrdev(capi_rawmajor, "capi/r%d");
1941 for (j = 0; j < CAPINC_NR_PORTS; j++) {
1943 sprintf(devname, "capi/r%u", j);
1944 devfs_unregister(devfs_find_handle(NULL, devname, capi_rawmajor, j, DEVFS_SPECIAL_CHR, 0));
1947 #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1948 (void) detach_capi_interface(&cuser);
1949 devfs_unregister_chrdev(capi_major, "capi20");
1950 devfs_unregister(devfs_find_handle(NULL, "capi20",
1952 DEVFS_SPECIAL_CHR, 0));
1959 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1960 #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
1961 compileinfo = " (middleware+capifs)";
1963 compileinfo = " (no capifs)";
1966 compileinfo = " (no middleware)";
1968 printk(KERN_NOTICE "capi20: Rev %s: started up with major %d%s\n",
1969 rev, capi_major, compileinfo);
1975 static void __exit capi_exit(void)
1977 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1983 devfs_unregister_chrdev(capi_major, "capi20");
1984 devfs_unregister(devfs_find_handle(NULL, "isdn/capi20", capi_major, 0, DEVFS_SPECIAL_CHR, 0));
1986 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1988 devfs_unregister_chrdev(capi_rawmajor, "capi/r%d");
1989 for (j = 0; j < CAPINC_NR_PORTS; j++) {
1991 sprintf(devname, "capi/r%u", j);
1992 devfs_unregister(devfs_find_handle(NULL, devname, capi_rawmajor, j, DEVFS_SPECIAL_CHR, 0));
1995 (void) detach_capi_interface(&cuser);
1996 printk(KERN_NOTICE "capi: Rev %s: unloaded\n", rev);
1999 module_init(capi_init);
2000 module_exit(capi_exit);