blob: 79f9364aded67f1f648b78ea57727d282fff11e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: capi.c,v 1.1.2.7 2004/04/28 09:48:59 armin Exp $
2 *
3 * CAPI 2.0 Interface for Linux
4 *
5 * Copyright 1996 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/errno.h>
14#include <linux/kernel.h>
15#include <linux/major.h>
16#include <linux/sched.h>
17#include <linux/slab.h>
18#include <linux/fcntl.h>
19#include <linux/fs.h>
20#include <linux/signal.h>
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -070021#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/mm.h>
Jonathan Corbeta237f3b2008-05-16 14:15:33 -060023#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/timer.h>
25#include <linux/wait.h>
26#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
27#include <linux/tty.h>
28#ifdef CONFIG_PPP
29#include <linux/netdevice.h>
30#include <linux/ppp_defs.h>
31#include <linux/if_ppp.h>
32#endif /* CONFIG_PPP */
33#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
34#include <linux/skbuff.h>
35#include <linux/proc_fs.h>
Alexey Dobriyan9a58a802010-01-14 03:10:54 -080036#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/poll.h>
38#include <linux/capi.h>
39#include <linux/kernelcapi.h>
40#include <linux/init.h>
41#include <linux/device.h>
42#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/isdn/capiutil.h>
44#include <linux/isdn/capicmd.h>
45#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
46#include "capifs.h"
47#endif
48
49static char *revision = "$Revision: 1.1.2.7 $";
50
51MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface");
52MODULE_AUTHOR("Carsten Paeth");
53MODULE_LICENSE("GPL");
54
55#undef _DEBUG_REFCOUNT /* alloc/free and open/close debug */
56#undef _DEBUG_TTYFUNCS /* call to tty_driver */
57#undef _DEBUG_DATAFLOW /* data flow */
58
59/* -------- driver information -------------------------------------- */
60
gregkh@suse.de56b22932005-03-23 10:01:41 -080061static struct class *capi_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Adrian Bunk408b6642005-05-01 08:59:29 -070063static int capi_major = 68; /* allocated */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
65#define CAPINC_NR_PORTS 32
66#define CAPINC_MAX_PORTS 256
Adrian Bunk408b6642005-05-01 08:59:29 -070067static int capi_ttymajor = 191;
68static int capi_ttyminors = CAPINC_NR_PORTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
70
71module_param_named(major, capi_major, uint, 0);
72#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
73module_param_named(ttymajor, capi_ttymajor, uint, 0);
74module_param_named(ttyminors, capi_ttyminors, uint, 0);
75#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
76
77/* -------- defines ------------------------------------------------- */
78
79#define CAPINC_MAX_RECVQUEUE 10
80#define CAPINC_MAX_SENDQUEUE 10
81#define CAPI_MAX_BLKSIZE 2048
82
83/* -------- data structures ----------------------------------------- */
84
85struct capidev;
86struct capincci;
87#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
88struct capiminor;
89
Michael Buesch6aa65472006-06-26 00:25:30 -070090struct datahandle_queue {
91 struct list_head list;
92 u16 datahandle;
93};
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095struct capiminor {
96 struct list_head list;
97 struct capincci *nccip;
98 unsigned int minor;
99
100 struct capi20_appl *ap;
101 u32 ncci;
102 u16 datahandle;
103 u16 msgid;
104
105 struct tty_struct *tty;
106 int ttyinstop;
107 int ttyoutstop;
108 struct sk_buff *ttyskb;
109 atomic_t ttyopencount;
110
111 struct sk_buff_head inqueue;
112 int inbytes;
113 struct sk_buff_head outqueue;
114 int outbytes;
115
116 /* transmit path */
Michael Buesch6aa65472006-06-26 00:25:30 -0700117 struct list_head ackqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 int nack;
Michael Buesch6aa65472006-06-26 00:25:30 -0700119 spinlock_t ackqlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
122
Michael Buesch053b47f2007-02-12 00:53:26 -0800123/* FIXME: The following lock is a sledgehammer-workaround to a
124 * locking issue with the capiminor (and maybe other) data structure(s).
125 * Access to this data is done in a racy way and crashes the machine with
126 * a FritzCard DSL driver; sooner or later. This is a workaround
127 * which trades scalability vs stability, so it doesn't crash the kernel anymore.
128 * The correct (and scalable) fix for the issue seems to require
129 * an API change to the drivers... . */
130static DEFINE_SPINLOCK(workaround_lock);
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132struct capincci {
133 struct capincci *next;
134 u32 ncci;
135 struct capidev *cdev;
136#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
137 struct capiminor *minorp;
138#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
139};
140
141struct capidev {
142 struct list_head list;
143 struct capi20_appl ap;
144 u16 errcode;
145 unsigned userflags;
146
147 struct sk_buff_head recvqueue;
148 wait_queue_head_t recvwait;
149
150 struct capincci *nccis;
151
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700152 struct mutex ncci_list_mtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155/* -------- global variables ---------------------------------------- */
156
157static DEFINE_RWLOCK(capidev_list_lock);
158static LIST_HEAD(capidev_list);
159
160#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
161static DEFINE_RWLOCK(capiminor_list_lock);
162static LIST_HEAD(capiminor_list);
163#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
164
165#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
166/* -------- datahandles --------------------------------------------- */
167
168static int capincci_add_ack(struct capiminor *mp, u16 datahandle)
169{
Michael Buesch6aa65472006-06-26 00:25:30 -0700170 struct datahandle_queue *n;
171 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 n = kmalloc(sizeof(*n), GFP_ATOMIC);
Michael Buesch6aa65472006-06-26 00:25:30 -0700174 if (unlikely(!n)) {
175 printk(KERN_ERR "capi: alloc datahandle failed\n");
176 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 n->datahandle = datahandle;
Michael Buesch6aa65472006-06-26 00:25:30 -0700179 INIT_LIST_HEAD(&n->list);
180 spin_lock_irqsave(&mp->ackqlock, flags);
181 list_add_tail(&n->list, &mp->ackqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 mp->nack++;
Michael Buesch6aa65472006-06-26 00:25:30 -0700183 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return 0;
185}
186
187static int capiminor_del_ack(struct capiminor *mp, u16 datahandle)
188{
Michael Buesch6aa65472006-06-26 00:25:30 -0700189 struct datahandle_queue *p, *tmp;
190 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Michael Buesch6aa65472006-06-26 00:25:30 -0700192 spin_lock_irqsave(&mp->ackqlock, flags);
193 list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
194 if (p->datahandle == datahandle) {
195 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 kfree(p);
197 mp->nack--;
Michael Buesch6aa65472006-06-26 00:25:30 -0700198 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return 0;
200 }
201 }
Michael Buesch6aa65472006-06-26 00:25:30 -0700202 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return -1;
204}
205
206static void capiminor_del_all_ack(struct capiminor *mp)
207{
Michael Buesch6aa65472006-06-26 00:25:30 -0700208 struct datahandle_queue *p, *tmp;
209 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Michael Buesch6aa65472006-06-26 00:25:30 -0700211 spin_lock_irqsave(&mp->ackqlock, flags);
212 list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
213 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 kfree(p);
215 mp->nack--;
216 }
Michael Buesch6aa65472006-06-26 00:25:30 -0700217 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
220
221/* -------- struct capiminor ---------------------------------------- */
222
223static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
224{
225 struct capiminor *mp, *p;
226 unsigned int minor = 0;
227 unsigned long flags;
228
Burman Yan41f96932006-12-08 02:39:35 -0800229 mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!mp) {
231 printk(KERN_ERR "capi: can't alloc capiminor\n");
232 return NULL;
233 }
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 mp->ap = ap;
236 mp->ncci = ncci;
237 mp->msgid = 0;
238 atomic_set(&mp->ttyopencount,0);
Michael Buesch6aa65472006-06-26 00:25:30 -0700239 INIT_LIST_HEAD(&mp->ackqueue);
240 spin_lock_init(&mp->ackqlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 skb_queue_head_init(&mp->inqueue);
243 skb_queue_head_init(&mp->outqueue);
244
245 /* Allocate the least unused minor number.
246 */
247 write_lock_irqsave(&capiminor_list_lock, flags);
248 if (list_empty(&capiminor_list))
249 list_add(&mp->list, &capiminor_list);
250 else {
251 list_for_each_entry(p, &capiminor_list, list) {
252 if (p->minor > minor)
253 break;
254 minor++;
255 }
256
257 if (minor < capi_ttyminors) {
258 mp->minor = minor;
259 list_add(&mp->list, p->list.prev);
260 }
261 }
262 write_unlock_irqrestore(&capiminor_list_lock, flags);
263
264 if (!(minor < capi_ttyminors)) {
265 printk(KERN_NOTICE "capi: out of minors\n");
266 kfree(mp);
267 return NULL;
268 }
269
270 return mp;
271}
272
273static void capiminor_free(struct capiminor *mp)
274{
275 unsigned long flags;
276
277 write_lock_irqsave(&capiminor_list_lock, flags);
278 list_del(&mp->list);
279 write_unlock_irqrestore(&capiminor_list_lock, flags);
280
Wei Yongjund46604e2009-02-25 00:12:09 +0000281 kfree_skb(mp->ttyskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 mp->ttyskb = NULL;
283 skb_queue_purge(&mp->inqueue);
284 skb_queue_purge(&mp->outqueue);
285 capiminor_del_all_ack(mp);
286 kfree(mp);
287}
288
Adrian Bunk408b6642005-05-01 08:59:29 -0700289static struct capiminor *capiminor_find(unsigned int minor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 struct list_head *l;
292 struct capiminor *p = NULL;
293
294 read_lock(&capiminor_list_lock);
295 list_for_each(l, &capiminor_list) {
296 p = list_entry(l, struct capiminor, list);
297 if (p->minor == minor)
298 break;
299 }
300 read_unlock(&capiminor_list_lock);
301 if (l == &capiminor_list)
302 return NULL;
303
304 return p;
305}
306#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
307
308/* -------- struct capincci ----------------------------------------- */
309
310static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
311{
312 struct capincci *np, **pp;
313#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
314 struct capiminor *mp = NULL;
315#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
316
Burman Yan41f96932006-12-08 02:39:35 -0800317 np = kzalloc(sizeof(*np), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (!np)
319 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 np->ncci = ncci;
321 np->cdev = cdev;
322#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
323 mp = NULL;
324 if (cdev->userflags & CAPIFLAG_HIGHJACKING)
325 mp = np->minorp = capiminor_alloc(&cdev->ap, ncci);
326 if (mp) {
327 mp->nccip = np;
328#ifdef _DEBUG_REFCOUNT
329 printk(KERN_DEBUG "set mp->nccip\n");
330#endif
331#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
332 capifs_new_ncci(mp->minor, MKDEV(capi_ttymajor, mp->minor));
333#endif
334 }
335#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
336 for (pp=&cdev->nccis; *pp; pp = &(*pp)->next)
337 ;
338 *pp = np;
339 return np;
340}
341
342static void capincci_free(struct capidev *cdev, u32 ncci)
343{
344 struct capincci *np, **pp;
345#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
346 struct capiminor *mp;
347#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
348
349 pp=&cdev->nccis;
350 while (*pp) {
351 np = *pp;
352 if (ncci == 0xffffffff || np->ncci == ncci) {
353 *pp = (*pp)->next;
354#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700355 if ((mp = np->minorp) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
357 capifs_free_ncci(mp->minor);
358#endif
359 if (mp->tty) {
360 mp->nccip = NULL;
361#ifdef _DEBUG_REFCOUNT
362 printk(KERN_DEBUG "reset mp->nccip\n");
363#endif
364 tty_hangup(mp->tty);
365 } else {
366 capiminor_free(mp);
367 }
368 }
369#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
370 kfree(np);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700371 if (*pp == NULL) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 } else {
373 pp = &(*pp)->next;
374 }
375 }
376}
377
378static struct capincci *capincci_find(struct capidev *cdev, u32 ncci)
379{
380 struct capincci *p;
381
382 for (p=cdev->nccis; p ; p = p->next) {
383 if (p->ncci == ncci)
384 break;
385 }
386 return p;
387}
388
389/* -------- struct capidev ------------------------------------------ */
390
391static struct capidev *capidev_alloc(void)
392{
393 struct capidev *cdev;
394 unsigned long flags;
395
Burman Yan41f96932006-12-08 02:39:35 -0800396 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (!cdev)
398 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700400 mutex_init(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 skb_queue_head_init(&cdev->recvqueue);
402 init_waitqueue_head(&cdev->recvwait);
403 write_lock_irqsave(&capidev_list_lock, flags);
404 list_add_tail(&cdev->list, &capidev_list);
405 write_unlock_irqrestore(&capidev_list_lock, flags);
406 return cdev;
407}
408
409static void capidev_free(struct capidev *cdev)
410{
411 unsigned long flags;
412
413 if (cdev->ap.applid) {
414 capi20_release(&cdev->ap);
415 cdev->ap.applid = 0;
416 }
417 skb_queue_purge(&cdev->recvqueue);
418
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700419 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 capincci_free(cdev, 0xffffffff);
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700421 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 write_lock_irqsave(&capidev_list_lock, flags);
424 list_del(&cdev->list);
425 write_unlock_irqrestore(&capidev_list_lock, flags);
426 kfree(cdev);
427}
428
429#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
430/* -------- handle data queue --------------------------------------- */
431
432static struct sk_buff *
433gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
434{
435 struct sk_buff *nskb;
436 nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_ATOMIC);
437 if (nskb) {
438 u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2);
439 unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN);
440 capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN);
441 capimsg_setu16(s, 2, mp->ap->applid);
442 capimsg_setu8 (s, 4, CAPI_DATA_B3);
443 capimsg_setu8 (s, 5, CAPI_RESP);
444 capimsg_setu16(s, 6, mp->msgid++);
445 capimsg_setu32(s, 8, mp->ncci);
446 capimsg_setu16(s, 12, datahandle);
447 }
448 return nskb;
449}
450
451static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)
452{
453 struct sk_buff *nskb;
454 int datalen;
455 u16 errcode, datahandle;
456 struct tty_ldisc *ld;
457
458 datalen = skb->len - CAPIMSG_LEN(skb->data);
459 if (mp->tty == NULL)
460 {
461#ifdef _DEBUG_DATAFLOW
462 printk(KERN_DEBUG "capi: currently no receiver\n");
463#endif
464 return -1;
465 }
466
467 ld = tty_ldisc_ref(mp->tty);
468 if (ld == NULL)
469 return -1;
Alan Coxa352def2008-07-16 21:53:12 +0100470 if (ld->ops->receive_buf == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
472 printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n");
473#endif
474 goto bad;
475 }
476 if (mp->ttyinstop) {
477#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
478 printk(KERN_DEBUG "capi: recv tty throttled\n");
479#endif
480 goto bad;
481 }
Alan Cox33f0f882006-01-09 20:54:13 -0800482 if (mp->tty->receive_room < datalen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
484 printk(KERN_DEBUG "capi: no room in tty\n");
485#endif
486 goto bad;
487 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700488 if ((nskb = gen_data_b3_resp_for(mp, skb)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 printk(KERN_ERR "capi: gen_data_b3_resp failed\n");
490 goto bad;
491 }
492 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4);
493 errcode = capi20_put_message(mp->ap, nskb);
494 if (errcode != CAPI_NOERROR) {
495 printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n",
496 errcode);
497 kfree_skb(nskb);
498 goto bad;
499 }
500 (void)skb_pull(skb, CAPIMSG_LEN(skb->data));
501#ifdef _DEBUG_DATAFLOW
502 printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n",
503 datahandle, skb->len);
504#endif
Alan Coxa352def2008-07-16 21:53:12 +0100505 ld->ops->receive_buf(mp->tty, skb->data, NULL, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 kfree_skb(skb);
507 tty_ldisc_deref(ld);
508 return 0;
509bad:
510 tty_ldisc_deref(ld);
511 return -1;
512}
513
514static void handle_minor_recv(struct capiminor *mp)
515{
516 struct sk_buff *skb;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700517 while ((skb = skb_dequeue(&mp->inqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 unsigned int len = skb->len;
519 mp->inbytes -= len;
520 if (handle_recv_skb(mp, skb) < 0) {
521 skb_queue_head(&mp->inqueue, skb);
522 mp->inbytes += len;
523 return;
524 }
525 }
526}
527
528static int handle_minor_send(struct capiminor *mp)
529{
530 struct sk_buff *skb;
531 u16 len;
532 int count = 0;
533 u16 errcode;
534 u16 datahandle;
535
536 if (mp->tty && mp->ttyoutstop) {
537#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
538 printk(KERN_DEBUG "capi: send: tty stopped\n");
539#endif
540 return 0;
541 }
542
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700543 while ((skb = skb_dequeue(&mp->outqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 datahandle = mp->datahandle;
545 len = (u16)skb->len;
546 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
547 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
548 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
549 capimsg_setu16(skb->data, 2, mp->ap->applid);
550 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
551 capimsg_setu8 (skb->data, 5, CAPI_REQ);
552 capimsg_setu16(skb->data, 6, mp->msgid++);
553 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
Andrew Morton5e6c20a2007-07-17 04:04:22 -0700554 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 capimsg_setu16(skb->data, 16, len); /* Data length */
556 capimsg_setu16(skb->data, 18, datahandle);
557 capimsg_setu16(skb->data, 20, 0); /* Flags */
558
559 if (capincci_add_ack(mp, datahandle) < 0) {
560 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
561 skb_queue_head(&mp->outqueue, skb);
562 return count;
563 }
564 errcode = capi20_put_message(mp->ap, skb);
565 if (errcode == CAPI_NOERROR) {
566 mp->datahandle++;
567 count++;
568 mp->outbytes -= len;
569#ifdef _DEBUG_DATAFLOW
570 printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n",
571 datahandle, len);
572#endif
573 continue;
574 }
575 capiminor_del_ack(mp, datahandle);
576
577 if (errcode == CAPI_SENDQUEUEFULL) {
578 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
579 skb_queue_head(&mp->outqueue, skb);
580 break;
581 }
582
583 /* ups, drop packet */
584 printk(KERN_ERR "capi: put_message = %x\n", errcode);
585 mp->outbytes -= len;
586 kfree_skb(skb);
587 }
588 return count;
589}
590
591#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
592/* -------- function called by lower level -------------------------- */
593
594static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
595{
596 struct capidev *cdev = ap->private;
597#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
598 struct capiminor *mp;
599 u16 datahandle;
600#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
601 struct capincci *np;
602 u32 ncci;
Michael Buesch053b47f2007-02-12 00:53:26 -0800603 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
606 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
Tilman Schmidt812d7342009-10-06 12:18:05 +0000607 if ((info & 0xff00) == 0) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700608 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700610 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612 }
613 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700614 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700616 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
Michael Buesch053b47f2007-02-12 00:53:26 -0800618 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
620 skb_queue_tail(&cdev->recvqueue, skb);
621 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800622 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return;
624 }
625 ncci = CAPIMSG_CONTROL(skb->data);
626 for (np = cdev->nccis; np && np->ncci != ncci; np = np->next)
627 ;
628 if (!np) {
629 printk(KERN_ERR "BUG: capi_signal: ncci not found\n");
630 skb_queue_tail(&cdev->recvqueue, skb);
631 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800632 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return;
634 }
635#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
636 skb_queue_tail(&cdev->recvqueue, skb);
637 wake_up_interruptible(&cdev->recvwait);
638#else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
639 mp = np->minorp;
640 if (!mp) {
641 skb_queue_tail(&cdev->recvqueue, skb);
642 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800643 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return;
645 }
646
647
648 if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) {
649
650 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2);
651#ifdef _DEBUG_DATAFLOW
652 printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n",
653 datahandle, skb->len-CAPIMSG_LEN(skb->data));
654#endif
655 skb_queue_tail(&mp->inqueue, skb);
656 mp->inbytes += skb->len;
657 handle_minor_recv(mp);
658
659 } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) {
660
661 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4);
662#ifdef _DEBUG_DATAFLOW
663 printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n",
664 datahandle,
665 CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2));
666#endif
667 kfree_skb(skb);
668 (void)capiminor_del_ack(mp, datahandle);
669 if (mp->tty)
670 tty_wakeup(mp->tty);
671 (void)handle_minor_send(mp);
672
673 } else {
674 /* ups, let capi application handle it :-) */
675 skb_queue_tail(&cdev->recvqueue, skb);
676 wake_up_interruptible(&cdev->recvwait);
677 }
678#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Michael Buesch053b47f2007-02-12 00:53:26 -0800679 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682/* -------- file_operations for capidev ----------------------------- */
683
684static ssize_t
685capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
686{
687 struct capidev *cdev = (struct capidev *)file->private_data;
688 struct sk_buff *skb;
689 size_t copied;
690
691 if (!cdev->ap.applid)
692 return -ENODEV;
693
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700694 if ((skb = skb_dequeue(&cdev->recvqueue)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 if (file->f_flags & O_NONBLOCK)
697 return -EAGAIN;
698
699 for (;;) {
700 interruptible_sleep_on(&cdev->recvwait);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700701 if ((skb = skb_dequeue(&cdev->recvqueue)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 break;
703 if (signal_pending(current))
704 break;
705 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700706 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 return -ERESTARTNOHAND;
708 }
709 if (skb->len > count) {
710 skb_queue_head(&cdev->recvqueue, skb);
711 return -EMSGSIZE;
712 }
713 if (copy_to_user(buf, skb->data, skb->len)) {
714 skb_queue_head(&cdev->recvqueue, skb);
715 return -EFAULT;
716 }
717 copied = skb->len;
718
719 kfree_skb(skb);
720
721 return copied;
722}
723
724static ssize_t
725capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
726{
727 struct capidev *cdev = (struct capidev *)file->private_data;
728 struct sk_buff *skb;
729 u16 mlen;
730
731 if (!cdev->ap.applid)
732 return -ENODEV;
733
734 skb = alloc_skb(count, GFP_USER);
735 if (!skb)
736 return -ENOMEM;
737
738 if (copy_from_user(skb_put(skb, count), buf, count)) {
739 kfree_skb(skb);
740 return -EFAULT;
741 }
742 mlen = CAPIMSG_LEN(skb->data);
743 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
744 if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) {
745 kfree_skb(skb);
746 return -EINVAL;
747 }
748 } else {
749 if (mlen != count) {
750 kfree_skb(skb);
751 return -EINVAL;
752 }
753 }
754 CAPIMSG_SETAPPID(skb->data, cdev->ap.applid);
755
756 if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700757 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 capincci_free(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700759 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761
762 cdev->errcode = capi20_put_message(&cdev->ap, skb);
763
764 if (cdev->errcode) {
765 kfree_skb(skb);
766 return -EIO;
767 }
768 return count;
769}
770
771static unsigned int
772capi_poll(struct file *file, poll_table * wait)
773{
774 struct capidev *cdev = (struct capidev *)file->private_data;
775 unsigned int mask = 0;
776
777 if (!cdev->ap.applid)
778 return POLLERR;
779
780 poll_wait(file, &(cdev->recvwait), wait);
781 mask = POLLOUT | POLLWRNORM;
782 if (!skb_queue_empty(&cdev->recvqueue))
783 mask |= POLLIN | POLLRDNORM;
784 return mask;
785}
786
787static int
788capi_ioctl(struct inode *inode, struct file *file,
789 unsigned int cmd, unsigned long arg)
790{
791 struct capidev *cdev = file->private_data;
792 struct capi20_appl *ap = &cdev->ap;
793 capi_ioctl_struct data;
794 int retval = -EINVAL;
795 void __user *argp = (void __user *)arg;
796
797 switch (cmd) {
798 case CAPI_REGISTER:
799 {
800 if (ap->applid)
801 return -EEXIST;
802
803 if (copy_from_user(&cdev->ap.rparam, argp,
804 sizeof(struct capi_register_params)))
805 return -EFAULT;
806
807 cdev->ap.private = cdev;
808 cdev->ap.recv_message = capi_recv_message;
809 cdev->errcode = capi20_register(ap);
810 if (cdev->errcode) {
811 ap->applid = 0;
812 return -EIO;
813 }
814 }
815 return (int)ap->applid;
816
817 case CAPI_GET_VERSION:
818 {
819 if (copy_from_user(&data.contr, argp,
820 sizeof(data.contr)))
821 return -EFAULT;
822 cdev->errcode = capi20_get_version(data.contr, &data.version);
823 if (cdev->errcode)
824 return -EIO;
825 if (copy_to_user(argp, &data.version,
826 sizeof(data.version)))
827 return -EFAULT;
828 }
829 return 0;
830
831 case CAPI_GET_SERIAL:
832 {
833 if (copy_from_user(&data.contr, argp,
834 sizeof(data.contr)))
835 return -EFAULT;
836 cdev->errcode = capi20_get_serial (data.contr, data.serial);
837 if (cdev->errcode)
838 return -EIO;
839 if (copy_to_user(argp, data.serial,
840 sizeof(data.serial)))
841 return -EFAULT;
842 }
843 return 0;
844 case CAPI_GET_PROFILE:
845 {
846 if (copy_from_user(&data.contr, argp,
847 sizeof(data.contr)))
848 return -EFAULT;
849
850 if (data.contr == 0) {
851 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
852 if (cdev->errcode)
853 return -EIO;
854
855 retval = copy_to_user(argp,
856 &data.profile.ncontroller,
857 sizeof(data.profile.ncontroller));
858
859 } else {
860 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
861 if (cdev->errcode)
862 return -EIO;
863
864 retval = copy_to_user(argp, &data.profile,
865 sizeof(data.profile));
866 }
867 if (retval)
868 return -EFAULT;
869 }
870 return 0;
871
872 case CAPI_GET_MANUFACTURER:
873 {
874 if (copy_from_user(&data.contr, argp,
875 sizeof(data.contr)))
876 return -EFAULT;
877 cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer);
878 if (cdev->errcode)
879 return -EIO;
880
881 if (copy_to_user(argp, data.manufacturer,
882 sizeof(data.manufacturer)))
883 return -EFAULT;
884
885 }
886 return 0;
887 case CAPI_GET_ERRCODE:
888 data.errcode = cdev->errcode;
889 cdev->errcode = CAPI_NOERROR;
890 if (arg) {
891 if (copy_to_user(argp, &data.errcode,
892 sizeof(data.errcode)))
893 return -EFAULT;
894 }
895 return data.errcode;
896
897 case CAPI_INSTALLED:
898 if (capi20_isinstalled() == CAPI_NOERROR)
899 return 0;
900 return -ENXIO;
901
902 case CAPI_MANUFACTURER_CMD:
903 {
904 struct capi_manufacturer_cmd mcmd;
905 if (!capable(CAP_SYS_ADMIN))
906 return -EPERM;
907 if (copy_from_user(&mcmd, argp, sizeof(mcmd)))
908 return -EFAULT;
909 return capi20_manufacturer(mcmd.cmd, mcmd.data);
910 }
911 return 0;
912
913 case CAPI_SET_FLAGS:
914 case CAPI_CLR_FLAGS:
915 {
916 unsigned userflags;
917 if (copy_from_user(&userflags, argp,
918 sizeof(userflags)))
919 return -EFAULT;
920 if (cmd == CAPI_SET_FLAGS)
921 cdev->userflags |= userflags;
922 else
923 cdev->userflags &= ~userflags;
924 }
925 return 0;
926
927 case CAPI_GET_FLAGS:
928 if (copy_to_user(argp, &cdev->userflags,
929 sizeof(cdev->userflags)))
930 return -EFAULT;
931 return 0;
932
933 case CAPI_NCCI_OPENCOUNT:
934 {
935 struct capincci *nccip;
936#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
937 struct capiminor *mp;
938#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
939 unsigned ncci;
940 int count = 0;
941 if (copy_from_user(&ncci, argp, sizeof(ncci)))
942 return -EFAULT;
943
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700944 mutex_lock(&cdev->ncci_list_mtx);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700945 if ((nccip = capincci_find(cdev, (u32) ncci)) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700946 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 return 0;
948 }
949#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700950 if ((mp = nccip->minorp) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 count += atomic_read(&mp->ttyopencount);
952 }
953#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700954 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 return count;
956 }
957 return 0;
958
959#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
960 case CAPI_NCCI_GETUNIT:
961 {
962 struct capincci *nccip;
963 struct capiminor *mp;
964 unsigned ncci;
965 int unit = 0;
966 if (copy_from_user(&ncci, argp,
967 sizeof(ncci)))
968 return -EFAULT;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700969 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 nccip = capincci_find(cdev, (u32) ncci);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700971 if (!nccip || (mp = nccip->minorp) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700972 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 return -ESRCH;
974 }
975 unit = mp->minor;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700976 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 return unit;
978 }
979 return 0;
980#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
981 }
982 return -EINVAL;
983}
984
985static int
986capi_open(struct inode *inode, struct file *file)
987{
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600988 int ret;
989
990 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (file->private_data)
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600992 ret = -EEXIST;
993 else if ((file->private_data = capidev_alloc()) == NULL)
994 ret = -ENOMEM;
995 else
996 ret = nonseekable_open(inode, file);
997 unlock_kernel();
998 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
1001static int
1002capi_release(struct inode *inode, struct file *file)
1003{
1004 struct capidev *cdev = (struct capidev *)file->private_data;
1005
1006 capidev_free(cdev);
1007 file->private_data = NULL;
1008
1009 return 0;
1010}
1011
Arjan van de Ven2b8693c2007-02-12 00:55:32 -08001012static const struct file_operations capi_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 .owner = THIS_MODULE,
1015 .llseek = no_llseek,
1016 .read = capi_read,
1017 .write = capi_write,
1018 .poll = capi_poll,
1019 .ioctl = capi_ioctl,
1020 .open = capi_open,
1021 .release = capi_release,
1022};
1023
1024#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1025/* -------- tty_operations for capincci ----------------------------- */
1026
1027static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1028{
1029 struct capiminor *mp;
Michael Buesch053b47f2007-02-12 00:53:26 -08001030 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001032 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 return -ENXIO;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001034 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 return -ENXIO;
1036
1037 tty->driver_data = (void *)mp;
1038
Michael Buesch053b47f2007-02-12 00:53:26 -08001039 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (atomic_read(&mp->ttyopencount) == 0)
1041 mp->tty = tty;
1042 atomic_inc(&mp->ttyopencount);
1043#ifdef _DEBUG_REFCOUNT
1044 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount));
1045#endif
1046 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001047 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return 0;
1049}
1050
1051static void capinc_tty_close(struct tty_struct * tty, struct file * file)
1052{
1053 struct capiminor *mp;
1054
1055 mp = (struct capiminor *)tty->driver_data;
1056 if (mp) {
1057 if (atomic_dec_and_test(&mp->ttyopencount)) {
1058#ifdef _DEBUG_REFCOUNT
1059 printk(KERN_DEBUG "capinc_tty_close lastclose\n");
1060#endif
1061 tty->driver_data = NULL;
1062 mp->tty = NULL;
1063 }
1064#ifdef _DEBUG_REFCOUNT
1065 printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount));
1066#endif
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001067 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 capiminor_free(mp);
1069 }
1070
1071#ifdef _DEBUG_REFCOUNT
1072 printk(KERN_DEBUG "capinc_tty_close\n");
1073#endif
1074}
1075
1076static int capinc_tty_write(struct tty_struct * tty,
1077 const unsigned char *buf, int count)
1078{
1079 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1080 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001081 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
1083#ifdef _DEBUG_TTYFUNCS
1084 printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count);
1085#endif
1086
1087 if (!mp || !mp->nccip) {
1088#ifdef _DEBUG_TTYFUNCS
1089 printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n");
1090#endif
1091 return 0;
1092 }
1093
Michael Buesch053b47f2007-02-12 00:53:26 -08001094 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 skb = mp->ttyskb;
1096 if (skb) {
1097 mp->ttyskb = NULL;
1098 skb_queue_tail(&mp->outqueue, skb);
1099 mp->outbytes += skb->len;
1100 }
1101
1102 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC);
1103 if (!skb) {
1104 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n");
Michael Buesch053b47f2007-02-12 00:53:26 -08001105 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 return -ENOMEM;
1107 }
1108
1109 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1110 memcpy(skb_put(skb, count), buf, count);
1111
1112 skb_queue_tail(&mp->outqueue, skb);
1113 mp->outbytes += skb->len;
1114 (void)handle_minor_send(mp);
1115 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001116 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 return count;
1118}
1119
Alan Coxf2545a72008-04-30 00:54:09 -07001120static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
1122 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1123 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001124 unsigned long flags;
Alan Coxf2545a72008-04-30 00:54:09 -07001125 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127#ifdef _DEBUG_TTYFUNCS
1128 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
1129#endif
1130
1131 if (!mp || !mp->nccip) {
1132#ifdef _DEBUG_TTYFUNCS
1133 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n");
1134#endif
Alan Coxf2545a72008-04-30 00:54:09 -07001135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137
Michael Buesch053b47f2007-02-12 00:53:26 -08001138 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 skb = mp->ttyskb;
1140 if (skb) {
1141 if (skb_tailroom(skb) > 0) {
1142 *(skb_put(skb, 1)) = ch;
Michael Buesch053b47f2007-02-12 00:53:26 -08001143 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001144 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 mp->ttyskb = NULL;
1147 skb_queue_tail(&mp->outqueue, skb);
1148 mp->outbytes += skb->len;
1149 (void)handle_minor_send(mp);
1150 }
1151 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC);
1152 if (skb) {
1153 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1154 *(skb_put(skb, 1)) = ch;
1155 mp->ttyskb = skb;
1156 } else {
1157 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
Alan Coxf2545a72008-04-30 00:54:09 -07001158 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 }
Michael Buesch053b47f2007-02-12 00:53:26 -08001160 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001161 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
1164static void capinc_tty_flush_chars(struct tty_struct *tty)
1165{
1166 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1167 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001168 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170#ifdef _DEBUG_TTYFUNCS
1171 printk(KERN_DEBUG "capinc_tty_flush_chars\n");
1172#endif
1173
1174 if (!mp || !mp->nccip) {
1175#ifdef _DEBUG_TTYFUNCS
1176 printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n");
1177#endif
1178 return;
1179 }
1180
Michael Buesch053b47f2007-02-12 00:53:26 -08001181 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 skb = mp->ttyskb;
1183 if (skb) {
1184 mp->ttyskb = NULL;
1185 skb_queue_tail(&mp->outqueue, skb);
1186 mp->outbytes += skb->len;
1187 (void)handle_minor_send(mp);
1188 }
1189 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001190 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
1193static int capinc_tty_write_room(struct tty_struct *tty)
1194{
1195 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1196 int room;
1197 if (!mp || !mp->nccip) {
1198#ifdef _DEBUG_TTYFUNCS
1199 printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n");
1200#endif
1201 return 0;
1202 }
1203 room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
1204 room *= CAPI_MAX_BLKSIZE;
1205#ifdef _DEBUG_TTYFUNCS
1206 printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room);
1207#endif
1208 return room;
1209}
1210
Adrian Bunk408b6642005-05-01 08:59:29 -07001211static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1214 if (!mp || !mp->nccip) {
1215#ifdef _DEBUG_TTYFUNCS
1216 printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n");
1217#endif
1218 return 0;
1219 }
1220#ifdef _DEBUG_TTYFUNCS
1221 printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n",
1222 mp->outbytes, mp->nack,
1223 skb_queue_len(&mp->outqueue),
1224 skb_queue_len(&mp->inqueue));
1225#endif
1226 return mp->outbytes;
1227}
1228
1229static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1230 unsigned int cmd, unsigned long arg)
1231{
1232 int error = 0;
1233 switch (cmd) {
1234 default:
Stephen Rothwell53e86312008-10-13 10:44:33 +01001235 error = n_tty_ioctl_helper(tty, file, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237 }
1238 return error;
1239}
1240
Alan Cox606d0992006-12-08 02:38:45 -08001241static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
1243#ifdef _DEBUG_TTYFUNCS
1244 printk(KERN_DEBUG "capinc_tty_set_termios\n");
1245#endif
1246}
1247
1248static void capinc_tty_throttle(struct tty_struct * tty)
1249{
1250 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1251#ifdef _DEBUG_TTYFUNCS
1252 printk(KERN_DEBUG "capinc_tty_throttle\n");
1253#endif
1254 if (mp)
1255 mp->ttyinstop = 1;
1256}
1257
1258static void capinc_tty_unthrottle(struct tty_struct * tty)
1259{
1260 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001261 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262#ifdef _DEBUG_TTYFUNCS
1263 printk(KERN_DEBUG "capinc_tty_unthrottle\n");
1264#endif
1265 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001266 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 mp->ttyinstop = 0;
1268 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001269 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
1271}
1272
1273static void capinc_tty_stop(struct tty_struct *tty)
1274{
1275 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1276#ifdef _DEBUG_TTYFUNCS
1277 printk(KERN_DEBUG "capinc_tty_stop\n");
1278#endif
1279 if (mp) {
1280 mp->ttyoutstop = 1;
1281 }
1282}
1283
1284static void capinc_tty_start(struct tty_struct *tty)
1285{
1286 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001287 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288#ifdef _DEBUG_TTYFUNCS
1289 printk(KERN_DEBUG "capinc_tty_start\n");
1290#endif
1291 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001292 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 mp->ttyoutstop = 0;
1294 (void)handle_minor_send(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001295 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 }
1297}
1298
1299static void capinc_tty_hangup(struct tty_struct *tty)
1300{
1301#ifdef _DEBUG_TTYFUNCS
1302 printk(KERN_DEBUG "capinc_tty_hangup\n");
1303#endif
1304}
1305
Alan Cox9e989662008-07-22 11:18:03 +01001306static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307{
1308#ifdef _DEBUG_TTYFUNCS
1309 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1310#endif
Alan Cox9e989662008-07-22 11:18:03 +01001311 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
1314static void capinc_tty_flush_buffer(struct tty_struct *tty)
1315{
1316#ifdef _DEBUG_TTYFUNCS
1317 printk(KERN_DEBUG "capinc_tty_flush_buffer\n");
1318#endif
1319}
1320
1321static void capinc_tty_set_ldisc(struct tty_struct *tty)
1322{
1323#ifdef _DEBUG_TTYFUNCS
1324 printk(KERN_DEBUG "capinc_tty_set_ldisc\n");
1325#endif
1326}
1327
1328static void capinc_tty_send_xchar(struct tty_struct *tty, char ch)
1329{
1330#ifdef _DEBUG_TTYFUNCS
1331 printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch);
1332#endif
1333}
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335static struct tty_driver *capinc_tty_driver;
1336
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001337static const struct tty_operations capinc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 .open = capinc_tty_open,
1339 .close = capinc_tty_close,
1340 .write = capinc_tty_write,
1341 .put_char = capinc_tty_put_char,
1342 .flush_chars = capinc_tty_flush_chars,
1343 .write_room = capinc_tty_write_room,
1344 .chars_in_buffer = capinc_tty_chars_in_buffer,
1345 .ioctl = capinc_tty_ioctl,
1346 .set_termios = capinc_tty_set_termios,
1347 .throttle = capinc_tty_throttle,
1348 .unthrottle = capinc_tty_unthrottle,
1349 .stop = capinc_tty_stop,
1350 .start = capinc_tty_start,
1351 .hangup = capinc_tty_hangup,
1352 .break_ctl = capinc_tty_break_ctl,
1353 .flush_buffer = capinc_tty_flush_buffer,
1354 .set_ldisc = capinc_tty_set_ldisc,
1355 .send_xchar = capinc_tty_send_xchar,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356};
1357
1358static int capinc_tty_init(void)
1359{
1360 struct tty_driver *drv;
1361
1362 if (capi_ttyminors > CAPINC_MAX_PORTS)
1363 capi_ttyminors = CAPINC_MAX_PORTS;
1364 if (capi_ttyminors <= 0)
1365 capi_ttyminors = CAPINC_NR_PORTS;
1366
1367 drv = alloc_tty_driver(capi_ttyminors);
1368 if (!drv)
1369 return -ENOMEM;
1370
1371 drv->owner = THIS_MODULE;
1372 drv->driver_name = "capi_nc";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 drv->name = "capi";
1374 drv->major = capi_ttymajor;
1375 drv->minor_start = 0;
1376 drv->type = TTY_DRIVER_TYPE_SERIAL;
1377 drv->subtype = SERIAL_TYPE_NORMAL;
1378 drv->init_termios = tty_std_termios;
1379 drv->init_termios.c_iflag = ICRNL;
1380 drv->init_termios.c_oflag = OPOST | ONLCR;
1381 drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1382 drv->init_termios.c_lflag = 0;
1383 drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS;
1384 tty_set_operations(drv, &capinc_ops);
1385 if (tty_register_driver(drv)) {
1386 put_tty_driver(drv);
1387 printk(KERN_ERR "Couldn't register capi_nc driver\n");
1388 return -1;
1389 }
1390 capinc_tty_driver = drv;
1391 return 0;
1392}
1393
1394static void capinc_tty_exit(void)
1395{
1396 struct tty_driver *drv = capinc_tty_driver;
1397 int retval;
1398 if ((retval = tty_unregister_driver(drv)))
1399 printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
1400 put_tty_driver(drv);
1401}
1402
1403#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1404
1405/* -------- /proc functions ----------------------------------------- */
1406
1407/*
1408 * /proc/capi/capi20:
1409 * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
1410 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001411static int capi20_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
1413 struct capidev *cdev;
1414 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
1416 read_lock(&capidev_list_lock);
1417 list_for_each(l, &capidev_list) {
1418 cdev = list_entry(l, struct capidev, list);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001419 seq_printf(m, "0 %d %lu %lu %lu %lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 cdev->ap.applid,
1421 cdev->ap.nrecvctlpkt,
1422 cdev->ap.nrecvdatapkt,
1423 cdev->ap.nsentctlpkt,
1424 cdev->ap.nsentdatapkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001430static int capi20_proc_open(struct inode *inode, struct file *file)
1431{
1432 return single_open(file, capi20_proc_show, NULL);
1433}
1434
1435static const struct file_operations capi20_proc_fops = {
1436 .owner = THIS_MODULE,
1437 .open = capi20_proc_open,
1438 .read = seq_read,
1439 .llseek = seq_lseek,
1440 .release = single_release,
1441};
1442
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443/*
1444 * /proc/capi/capi20ncci:
1445 * applid ncci
1446 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001447static int capi20ncci_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
1449 struct capidev *cdev;
1450 struct capincci *np;
1451 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453 read_lock(&capidev_list_lock);
1454 list_for_each(l, &capidev_list) {
1455 cdev = list_entry(l, struct capidev, list);
1456 for (np=cdev->nccis; np; np = np->next) {
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001457 seq_printf(m, "%d 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 cdev->ap.applid,
1459 np->ncci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 }
1461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001463 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001466static int capi20ncci_proc_open(struct inode *inode, struct file *file)
1467{
1468 return single_open(file, capi20ncci_proc_show, NULL);
1469}
1470
1471static const struct file_operations capi20ncci_proc_fops = {
1472 .owner = THIS_MODULE,
1473 .open = capi20ncci_proc_open,
1474 .read = seq_read,
1475 .llseek = seq_lseek,
1476 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477};
1478
1479static void __init proc_init(void)
1480{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001481 proc_create("capi/capi20", 0, NULL, &capi20_proc_fops);
1482 proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
1485static void __exit proc_exit(void)
1486{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001487 remove_proc_entry("capi/capi20", NULL);
1488 remove_proc_entry("capi/capi20ncci", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
1491/* -------- init function and module interface ---------------------- */
1492
1493
1494static char rev[32];
1495
1496static int __init capi_init(void)
1497{
1498 char *p;
1499 char *compileinfo;
Andrew Morton6d9eac32006-03-28 01:56:19 -08001500 int major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001502 if ((p = strchr(revision, ':')) != NULL && p[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 strlcpy(rev, p + 2, sizeof(rev));
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001504 if ((p = strchr(rev, '$')) != NULL && p > rev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 *(p-1) = 0;
1506 } else
1507 strcpy(rev, "1.0");
1508
Andrew Morton6d9eac32006-03-28 01:56:19 -08001509 major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
1510 if (major_ret < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
Andrew Morton6d9eac32006-03-28 01:56:19 -08001512 return major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 }
gregkh@suse.de56b22932005-03-23 10:01:41 -08001514 capi_class = class_create(THIS_MODULE, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 if (IS_ERR(capi_class)) {
1516 unregister_chrdev(capi_major, "capi20");
1517 return PTR_ERR(capi_class);
1518 }
1519
Greg Kroah-Hartmana9b12612008-07-21 20:03:34 -07001520 device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1523 if (capinc_tty_init() < 0) {
Tony Jonesd78b0362007-09-25 02:03:03 +02001524 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001525 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 unregister_chrdev(capi_major, "capi20");
1527 return -ENOMEM;
1528 }
1529#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1530
1531 proc_init();
1532
1533#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1534#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
1535 compileinfo = " (middleware+capifs)";
1536#else
1537 compileinfo = " (no capifs)";
1538#endif
1539#else
1540 compileinfo = " (no middleware)";
1541#endif
1542 printk(KERN_NOTICE "capi20: Rev %s: started up with major %d%s\n",
1543 rev, capi_major, compileinfo);
1544
1545 return 0;
1546}
1547
1548static void __exit capi_exit(void)
1549{
1550 proc_exit();
1551
Tony Jonesd78b0362007-09-25 02:03:03 +02001552 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001553 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 unregister_chrdev(capi_major, "capi20");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1557 capinc_tty_exit();
1558#endif
1559 printk(KERN_NOTICE "capi: Rev %s: unloaded\n", rev);
1560}
1561
1562module_init(capi_init);
1563module_exit(capi_exit);