blob: dc5ac52986ee0968bc75d125043db4f3b314da18 [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>
Jan Kiszka90926f02010-02-08 10:12:06 +000045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "capifs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48static char *revision = "$Revision: 1.1.2.7 $";
49
50MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface");
51MODULE_AUTHOR("Carsten Paeth");
52MODULE_LICENSE("GPL");
53
54#undef _DEBUG_REFCOUNT /* alloc/free and open/close debug */
55#undef _DEBUG_TTYFUNCS /* call to tty_driver */
56#undef _DEBUG_DATAFLOW /* data flow */
57
58/* -------- driver information -------------------------------------- */
59
gregkh@suse.de56b22932005-03-23 10:01:41 -080060static struct class *capi_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Adrian Bunk408b6642005-05-01 08:59:29 -070062static int capi_major = 68; /* allocated */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
64#define CAPINC_NR_PORTS 32
65#define CAPINC_MAX_PORTS 256
Adrian Bunk408b6642005-05-01 08:59:29 -070066static int capi_ttymajor = 191;
67static int capi_ttyminors = CAPINC_NR_PORTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
69
70module_param_named(major, capi_major, uint, 0);
71#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
72module_param_named(ttymajor, capi_ttymajor, uint, 0);
73module_param_named(ttyminors, capi_ttyminors, uint, 0);
74#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
75
76/* -------- defines ------------------------------------------------- */
77
78#define CAPINC_MAX_RECVQUEUE 10
79#define CAPINC_MAX_SENDQUEUE 10
80#define CAPI_MAX_BLKSIZE 2048
81
82/* -------- data structures ----------------------------------------- */
83
84struct capidev;
85struct capincci;
86#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
87struct capiminor;
88
Michael Buesch6aa65472006-06-26 00:25:30 -070089struct datahandle_queue {
90 struct list_head list;
91 u16 datahandle;
92};
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094struct capiminor {
95 struct list_head list;
96 struct capincci *nccip;
97 unsigned int minor;
Jan Kiszka90926f02010-02-08 10:12:06 +000098 struct dentry *capifs_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
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
Jan Kiszka90926f02010-02-08 10:12:06 +0000331 mp->capifs_dentry =
332 capifs_new_ncci(mp->minor,
333 MKDEV(capi_ttymajor, mp->minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
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) {
Jan Kiszka90926f02010-02-08 10:12:06 +0000356 capifs_free_ncci(mp->capifs_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (mp->tty) {
358 mp->nccip = NULL;
359#ifdef _DEBUG_REFCOUNT
360 printk(KERN_DEBUG "reset mp->nccip\n");
361#endif
362 tty_hangup(mp->tty);
363 } else {
364 capiminor_free(mp);
365 }
366 }
367#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
368 kfree(np);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700369 if (*pp == NULL) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 } else {
371 pp = &(*pp)->next;
372 }
373 }
374}
375
376static struct capincci *capincci_find(struct capidev *cdev, u32 ncci)
377{
378 struct capincci *p;
379
380 for (p=cdev->nccis; p ; p = p->next) {
381 if (p->ncci == ncci)
382 break;
383 }
384 return p;
385}
386
387/* -------- struct capidev ------------------------------------------ */
388
389static struct capidev *capidev_alloc(void)
390{
391 struct capidev *cdev;
392 unsigned long flags;
393
Burman Yan41f96932006-12-08 02:39:35 -0800394 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!cdev)
396 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700398 mutex_init(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 skb_queue_head_init(&cdev->recvqueue);
400 init_waitqueue_head(&cdev->recvwait);
401 write_lock_irqsave(&capidev_list_lock, flags);
402 list_add_tail(&cdev->list, &capidev_list);
403 write_unlock_irqrestore(&capidev_list_lock, flags);
404 return cdev;
405}
406
407static void capidev_free(struct capidev *cdev)
408{
409 unsigned long flags;
410
411 if (cdev->ap.applid) {
412 capi20_release(&cdev->ap);
413 cdev->ap.applid = 0;
414 }
415 skb_queue_purge(&cdev->recvqueue);
416
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700417 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 capincci_free(cdev, 0xffffffff);
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700419 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 write_lock_irqsave(&capidev_list_lock, flags);
422 list_del(&cdev->list);
423 write_unlock_irqrestore(&capidev_list_lock, flags);
424 kfree(cdev);
425}
426
427#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
428/* -------- handle data queue --------------------------------------- */
429
430static struct sk_buff *
431gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
432{
433 struct sk_buff *nskb;
434 nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_ATOMIC);
435 if (nskb) {
436 u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2);
437 unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN);
438 capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN);
439 capimsg_setu16(s, 2, mp->ap->applid);
440 capimsg_setu8 (s, 4, CAPI_DATA_B3);
441 capimsg_setu8 (s, 5, CAPI_RESP);
442 capimsg_setu16(s, 6, mp->msgid++);
443 capimsg_setu32(s, 8, mp->ncci);
444 capimsg_setu16(s, 12, datahandle);
445 }
446 return nskb;
447}
448
449static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)
450{
451 struct sk_buff *nskb;
452 int datalen;
453 u16 errcode, datahandle;
454 struct tty_ldisc *ld;
455
456 datalen = skb->len - CAPIMSG_LEN(skb->data);
457 if (mp->tty == NULL)
458 {
459#ifdef _DEBUG_DATAFLOW
460 printk(KERN_DEBUG "capi: currently no receiver\n");
461#endif
462 return -1;
463 }
464
465 ld = tty_ldisc_ref(mp->tty);
466 if (ld == NULL)
467 return -1;
Alan Coxa352def2008-07-16 21:53:12 +0100468 if (ld->ops->receive_buf == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
470 printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n");
471#endif
472 goto bad;
473 }
474 if (mp->ttyinstop) {
475#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
476 printk(KERN_DEBUG "capi: recv tty throttled\n");
477#endif
478 goto bad;
479 }
Alan Cox33f0f882006-01-09 20:54:13 -0800480 if (mp->tty->receive_room < datalen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
482 printk(KERN_DEBUG "capi: no room in tty\n");
483#endif
484 goto bad;
485 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700486 if ((nskb = gen_data_b3_resp_for(mp, skb)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 printk(KERN_ERR "capi: gen_data_b3_resp failed\n");
488 goto bad;
489 }
490 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4);
491 errcode = capi20_put_message(mp->ap, nskb);
492 if (errcode != CAPI_NOERROR) {
493 printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n",
494 errcode);
495 kfree_skb(nskb);
496 goto bad;
497 }
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);
502#endif
Alan Coxa352def2008-07-16 21:53:12 +0100503 ld->ops->receive_buf(mp->tty, skb->data, NULL, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 kfree_skb(skb);
505 tty_ldisc_deref(ld);
506 return 0;
507bad:
508 tty_ldisc_deref(ld);
509 return -1;
510}
511
512static void handle_minor_recv(struct capiminor *mp)
513{
514 struct sk_buff *skb;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700515 while ((skb = skb_dequeue(&mp->inqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 unsigned int len = skb->len;
517 mp->inbytes -= len;
518 if (handle_recv_skb(mp, skb) < 0) {
519 skb_queue_head(&mp->inqueue, skb);
520 mp->inbytes += len;
521 return;
522 }
523 }
524}
525
526static int handle_minor_send(struct capiminor *mp)
527{
528 struct sk_buff *skb;
529 u16 len;
530 int count = 0;
531 u16 errcode;
532 u16 datahandle;
533
534 if (mp->tty && mp->ttyoutstop) {
535#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
536 printk(KERN_DEBUG "capi: send: tty stopped\n");
537#endif
538 return 0;
539 }
540
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700541 while ((skb = skb_dequeue(&mp->outqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 datahandle = mp->datahandle;
543 len = (u16)skb->len;
544 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
545 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
546 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
547 capimsg_setu16(skb->data, 2, mp->ap->applid);
548 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
549 capimsg_setu8 (skb->data, 5, CAPI_REQ);
550 capimsg_setu16(skb->data, 6, mp->msgid++);
551 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
Andrew Morton5e6c20a2007-07-17 04:04:22 -0700552 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 capimsg_setu16(skb->data, 16, len); /* Data length */
554 capimsg_setu16(skb->data, 18, datahandle);
555 capimsg_setu16(skb->data, 20, 0); /* Flags */
556
557 if (capincci_add_ack(mp, datahandle) < 0) {
558 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
559 skb_queue_head(&mp->outqueue, skb);
560 return count;
561 }
562 errcode = capi20_put_message(mp->ap, skb);
563 if (errcode == CAPI_NOERROR) {
564 mp->datahandle++;
565 count++;
566 mp->outbytes -= len;
567#ifdef _DEBUG_DATAFLOW
568 printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n",
569 datahandle, len);
570#endif
571 continue;
572 }
573 capiminor_del_ack(mp, datahandle);
574
575 if (errcode == CAPI_SENDQUEUEFULL) {
576 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
577 skb_queue_head(&mp->outqueue, skb);
578 break;
579 }
580
581 /* ups, drop packet */
582 printk(KERN_ERR "capi: put_message = %x\n", errcode);
583 mp->outbytes -= len;
584 kfree_skb(skb);
585 }
586 return count;
587}
588
589#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
590/* -------- function called by lower level -------------------------- */
591
592static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
593{
594 struct capidev *cdev = ap->private;
595#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
596 struct capiminor *mp;
597 u16 datahandle;
598#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
599 struct capincci *np;
600 u32 ncci;
Michael Buesch053b47f2007-02-12 00:53:26 -0800601 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
604 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
Tilman Schmidt812d7342009-10-06 12:18:05 +0000605 if ((info & 0xff00) == 0) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700606 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700608 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610 }
611 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700612 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700614 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
Michael Buesch053b47f2007-02-12 00:53:26 -0800616 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
618 skb_queue_tail(&cdev->recvqueue, skb);
619 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800620 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return;
622 }
623 ncci = CAPIMSG_CONTROL(skb->data);
624 for (np = cdev->nccis; np && np->ncci != ncci; np = np->next)
625 ;
626 if (!np) {
627 printk(KERN_ERR "BUG: capi_signal: ncci not found\n");
628 skb_queue_tail(&cdev->recvqueue, skb);
629 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800630 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return;
632 }
633#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
634 skb_queue_tail(&cdev->recvqueue, skb);
635 wake_up_interruptible(&cdev->recvwait);
636#else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
637 mp = np->minorp;
638 if (!mp) {
639 skb_queue_tail(&cdev->recvqueue, skb);
640 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800641 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 return;
643 }
644
645
646 if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) {
647
648 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2);
649#ifdef _DEBUG_DATAFLOW
650 printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n",
651 datahandle, skb->len-CAPIMSG_LEN(skb->data));
652#endif
653 skb_queue_tail(&mp->inqueue, skb);
654 mp->inbytes += skb->len;
655 handle_minor_recv(mp);
656
657 } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) {
658
659 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4);
660#ifdef _DEBUG_DATAFLOW
661 printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n",
662 datahandle,
663 CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2));
664#endif
665 kfree_skb(skb);
666 (void)capiminor_del_ack(mp, datahandle);
667 if (mp->tty)
668 tty_wakeup(mp->tty);
669 (void)handle_minor_send(mp);
670
671 } else {
672 /* ups, let capi application handle it :-) */
673 skb_queue_tail(&cdev->recvqueue, skb);
674 wake_up_interruptible(&cdev->recvwait);
675 }
676#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Michael Buesch053b47f2007-02-12 00:53:26 -0800677 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
680/* -------- file_operations for capidev ----------------------------- */
681
682static ssize_t
683capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
684{
685 struct capidev *cdev = (struct capidev *)file->private_data;
686 struct sk_buff *skb;
687 size_t copied;
688
689 if (!cdev->ap.applid)
690 return -ENODEV;
691
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700692 if ((skb = skb_dequeue(&cdev->recvqueue)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 if (file->f_flags & O_NONBLOCK)
695 return -EAGAIN;
696
697 for (;;) {
698 interruptible_sleep_on(&cdev->recvwait);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700699 if ((skb = skb_dequeue(&cdev->recvqueue)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 break;
701 if (signal_pending(current))
702 break;
703 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700704 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 return -ERESTARTNOHAND;
706 }
707 if (skb->len > count) {
708 skb_queue_head(&cdev->recvqueue, skb);
709 return -EMSGSIZE;
710 }
711 if (copy_to_user(buf, skb->data, skb->len)) {
712 skb_queue_head(&cdev->recvqueue, skb);
713 return -EFAULT;
714 }
715 copied = skb->len;
716
717 kfree_skb(skb);
718
719 return copied;
720}
721
722static ssize_t
723capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
724{
725 struct capidev *cdev = (struct capidev *)file->private_data;
726 struct sk_buff *skb;
727 u16 mlen;
728
729 if (!cdev->ap.applid)
730 return -ENODEV;
731
732 skb = alloc_skb(count, GFP_USER);
733 if (!skb)
734 return -ENOMEM;
735
736 if (copy_from_user(skb_put(skb, count), buf, count)) {
737 kfree_skb(skb);
738 return -EFAULT;
739 }
740 mlen = CAPIMSG_LEN(skb->data);
741 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
742 if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) {
743 kfree_skb(skb);
744 return -EINVAL;
745 }
746 } else {
747 if (mlen != count) {
748 kfree_skb(skb);
749 return -EINVAL;
750 }
751 }
752 CAPIMSG_SETAPPID(skb->data, cdev->ap.applid);
753
754 if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700755 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 capincci_free(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700757 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759
760 cdev->errcode = capi20_put_message(&cdev->ap, skb);
761
762 if (cdev->errcode) {
763 kfree_skb(skb);
764 return -EIO;
765 }
766 return count;
767}
768
769static unsigned int
770capi_poll(struct file *file, poll_table * wait)
771{
772 struct capidev *cdev = (struct capidev *)file->private_data;
773 unsigned int mask = 0;
774
775 if (!cdev->ap.applid)
776 return POLLERR;
777
778 poll_wait(file, &(cdev->recvwait), wait);
779 mask = POLLOUT | POLLWRNORM;
780 if (!skb_queue_empty(&cdev->recvqueue))
781 mask |= POLLIN | POLLRDNORM;
782 return mask;
783}
784
785static int
786capi_ioctl(struct inode *inode, struct file *file,
787 unsigned int cmd, unsigned long arg)
788{
789 struct capidev *cdev = file->private_data;
790 struct capi20_appl *ap = &cdev->ap;
791 capi_ioctl_struct data;
792 int retval = -EINVAL;
793 void __user *argp = (void __user *)arg;
794
795 switch (cmd) {
796 case CAPI_REGISTER:
797 {
798 if (ap->applid)
799 return -EEXIST;
800
801 if (copy_from_user(&cdev->ap.rparam, argp,
802 sizeof(struct capi_register_params)))
803 return -EFAULT;
804
805 cdev->ap.private = cdev;
806 cdev->ap.recv_message = capi_recv_message;
807 cdev->errcode = capi20_register(ap);
808 if (cdev->errcode) {
809 ap->applid = 0;
810 return -EIO;
811 }
812 }
813 return (int)ap->applid;
814
815 case CAPI_GET_VERSION:
816 {
817 if (copy_from_user(&data.contr, argp,
818 sizeof(data.contr)))
819 return -EFAULT;
820 cdev->errcode = capi20_get_version(data.contr, &data.version);
821 if (cdev->errcode)
822 return -EIO;
823 if (copy_to_user(argp, &data.version,
824 sizeof(data.version)))
825 return -EFAULT;
826 }
827 return 0;
828
829 case CAPI_GET_SERIAL:
830 {
831 if (copy_from_user(&data.contr, argp,
832 sizeof(data.contr)))
833 return -EFAULT;
834 cdev->errcode = capi20_get_serial (data.contr, data.serial);
835 if (cdev->errcode)
836 return -EIO;
837 if (copy_to_user(argp, data.serial,
838 sizeof(data.serial)))
839 return -EFAULT;
840 }
841 return 0;
842 case CAPI_GET_PROFILE:
843 {
844 if (copy_from_user(&data.contr, argp,
845 sizeof(data.contr)))
846 return -EFAULT;
847
848 if (data.contr == 0) {
849 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
850 if (cdev->errcode)
851 return -EIO;
852
853 retval = copy_to_user(argp,
854 &data.profile.ncontroller,
855 sizeof(data.profile.ncontroller));
856
857 } else {
858 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
859 if (cdev->errcode)
860 return -EIO;
861
862 retval = copy_to_user(argp, &data.profile,
863 sizeof(data.profile));
864 }
865 if (retval)
866 return -EFAULT;
867 }
868 return 0;
869
870 case CAPI_GET_MANUFACTURER:
871 {
872 if (copy_from_user(&data.contr, argp,
873 sizeof(data.contr)))
874 return -EFAULT;
875 cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer);
876 if (cdev->errcode)
877 return -EIO;
878
879 if (copy_to_user(argp, data.manufacturer,
880 sizeof(data.manufacturer)))
881 return -EFAULT;
882
883 }
884 return 0;
885 case CAPI_GET_ERRCODE:
886 data.errcode = cdev->errcode;
887 cdev->errcode = CAPI_NOERROR;
888 if (arg) {
889 if (copy_to_user(argp, &data.errcode,
890 sizeof(data.errcode)))
891 return -EFAULT;
892 }
893 return data.errcode;
894
895 case CAPI_INSTALLED:
896 if (capi20_isinstalled() == CAPI_NOERROR)
897 return 0;
898 return -ENXIO;
899
900 case CAPI_MANUFACTURER_CMD:
901 {
902 struct capi_manufacturer_cmd mcmd;
903 if (!capable(CAP_SYS_ADMIN))
904 return -EPERM;
905 if (copy_from_user(&mcmd, argp, sizeof(mcmd)))
906 return -EFAULT;
907 return capi20_manufacturer(mcmd.cmd, mcmd.data);
908 }
909 return 0;
910
911 case CAPI_SET_FLAGS:
912 case CAPI_CLR_FLAGS:
913 {
914 unsigned userflags;
915 if (copy_from_user(&userflags, argp,
916 sizeof(userflags)))
917 return -EFAULT;
918 if (cmd == CAPI_SET_FLAGS)
919 cdev->userflags |= userflags;
920 else
921 cdev->userflags &= ~userflags;
922 }
923 return 0;
924
925 case CAPI_GET_FLAGS:
926 if (copy_to_user(argp, &cdev->userflags,
927 sizeof(cdev->userflags)))
928 return -EFAULT;
929 return 0;
930
931 case CAPI_NCCI_OPENCOUNT:
932 {
933 struct capincci *nccip;
934#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
935 struct capiminor *mp;
936#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
937 unsigned ncci;
938 int count = 0;
939 if (copy_from_user(&ncci, argp, sizeof(ncci)))
940 return -EFAULT;
941
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700942 mutex_lock(&cdev->ncci_list_mtx);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700943 if ((nccip = capincci_find(cdev, (u32) ncci)) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700944 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return 0;
946 }
947#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700948 if ((mp = nccip->minorp) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 count += atomic_read(&mp->ttyopencount);
950 }
951#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700952 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return count;
954 }
955 return 0;
956
957#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
958 case CAPI_NCCI_GETUNIT:
959 {
960 struct capincci *nccip;
961 struct capiminor *mp;
962 unsigned ncci;
963 int unit = 0;
964 if (copy_from_user(&ncci, argp,
965 sizeof(ncci)))
966 return -EFAULT;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700967 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 nccip = capincci_find(cdev, (u32) ncci);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700969 if (!nccip || (mp = nccip->minorp) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700970 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 return -ESRCH;
972 }
973 unit = mp->minor;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700974 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 return unit;
976 }
977 return 0;
978#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
979 }
980 return -EINVAL;
981}
982
983static int
984capi_open(struct inode *inode, struct file *file)
985{
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600986 int ret;
987
988 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (file->private_data)
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600990 ret = -EEXIST;
991 else if ((file->private_data = capidev_alloc()) == NULL)
992 ret = -ENOMEM;
993 else
994 ret = nonseekable_open(inode, file);
995 unlock_kernel();
996 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
999static int
1000capi_release(struct inode *inode, struct file *file)
1001{
1002 struct capidev *cdev = (struct capidev *)file->private_data;
1003
1004 capidev_free(cdev);
1005 file->private_data = NULL;
1006
1007 return 0;
1008}
1009
Arjan van de Ven2b8693c2007-02-12 00:55:32 -08001010static const struct file_operations capi_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
1012 .owner = THIS_MODULE,
1013 .llseek = no_llseek,
1014 .read = capi_read,
1015 .write = capi_write,
1016 .poll = capi_poll,
1017 .ioctl = capi_ioctl,
1018 .open = capi_open,
1019 .release = capi_release,
1020};
1021
1022#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1023/* -------- tty_operations for capincci ----------------------------- */
1024
1025static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1026{
1027 struct capiminor *mp;
Michael Buesch053b47f2007-02-12 00:53:26 -08001028 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001030 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return -ENXIO;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001032 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 return -ENXIO;
1034
1035 tty->driver_data = (void *)mp;
1036
Michael Buesch053b47f2007-02-12 00:53:26 -08001037 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (atomic_read(&mp->ttyopencount) == 0)
1039 mp->tty = tty;
1040 atomic_inc(&mp->ttyopencount);
1041#ifdef _DEBUG_REFCOUNT
1042 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount));
1043#endif
1044 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001045 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return 0;
1047}
1048
1049static void capinc_tty_close(struct tty_struct * tty, struct file * file)
1050{
1051 struct capiminor *mp;
1052
1053 mp = (struct capiminor *)tty->driver_data;
1054 if (mp) {
1055 if (atomic_dec_and_test(&mp->ttyopencount)) {
1056#ifdef _DEBUG_REFCOUNT
1057 printk(KERN_DEBUG "capinc_tty_close lastclose\n");
1058#endif
1059 tty->driver_data = NULL;
1060 mp->tty = NULL;
1061 }
1062#ifdef _DEBUG_REFCOUNT
1063 printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount));
1064#endif
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001065 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 capiminor_free(mp);
1067 }
1068
1069#ifdef _DEBUG_REFCOUNT
1070 printk(KERN_DEBUG "capinc_tty_close\n");
1071#endif
1072}
1073
1074static int capinc_tty_write(struct tty_struct * tty,
1075 const unsigned char *buf, int count)
1076{
1077 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1078 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001079 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081#ifdef _DEBUG_TTYFUNCS
1082 printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count);
1083#endif
1084
1085 if (!mp || !mp->nccip) {
1086#ifdef _DEBUG_TTYFUNCS
1087 printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n");
1088#endif
1089 return 0;
1090 }
1091
Michael Buesch053b47f2007-02-12 00:53:26 -08001092 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 skb = mp->ttyskb;
1094 if (skb) {
1095 mp->ttyskb = NULL;
1096 skb_queue_tail(&mp->outqueue, skb);
1097 mp->outbytes += skb->len;
1098 }
1099
1100 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC);
1101 if (!skb) {
1102 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n");
Michael Buesch053b47f2007-02-12 00:53:26 -08001103 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 return -ENOMEM;
1105 }
1106
1107 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1108 memcpy(skb_put(skb, count), buf, count);
1109
1110 skb_queue_tail(&mp->outqueue, skb);
1111 mp->outbytes += skb->len;
1112 (void)handle_minor_send(mp);
1113 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001114 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 return count;
1116}
1117
Alan Coxf2545a72008-04-30 00:54:09 -07001118static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
1120 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1121 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001122 unsigned long flags;
Alan Coxf2545a72008-04-30 00:54:09 -07001123 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125#ifdef _DEBUG_TTYFUNCS
1126 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
1127#endif
1128
1129 if (!mp || !mp->nccip) {
1130#ifdef _DEBUG_TTYFUNCS
1131 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n");
1132#endif
Alan Coxf2545a72008-04-30 00:54:09 -07001133 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
1135
Michael Buesch053b47f2007-02-12 00:53:26 -08001136 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 skb = mp->ttyskb;
1138 if (skb) {
1139 if (skb_tailroom(skb) > 0) {
1140 *(skb_put(skb, 1)) = ch;
Michael Buesch053b47f2007-02-12 00:53:26 -08001141 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001142 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144 mp->ttyskb = NULL;
1145 skb_queue_tail(&mp->outqueue, skb);
1146 mp->outbytes += skb->len;
1147 (void)handle_minor_send(mp);
1148 }
1149 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC);
1150 if (skb) {
1151 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1152 *(skb_put(skb, 1)) = ch;
1153 mp->ttyskb = skb;
1154 } else {
1155 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
Alan Coxf2545a72008-04-30 00:54:09 -07001156 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
Michael Buesch053b47f2007-02-12 00:53:26 -08001158 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001159 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
1162static void capinc_tty_flush_chars(struct tty_struct *tty)
1163{
1164 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1165 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001166 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168#ifdef _DEBUG_TTYFUNCS
1169 printk(KERN_DEBUG "capinc_tty_flush_chars\n");
1170#endif
1171
1172 if (!mp || !mp->nccip) {
1173#ifdef _DEBUG_TTYFUNCS
1174 printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n");
1175#endif
1176 return;
1177 }
1178
Michael Buesch053b47f2007-02-12 00:53:26 -08001179 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 skb = mp->ttyskb;
1181 if (skb) {
1182 mp->ttyskb = NULL;
1183 skb_queue_tail(&mp->outqueue, skb);
1184 mp->outbytes += skb->len;
1185 (void)handle_minor_send(mp);
1186 }
1187 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001188 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
1191static int capinc_tty_write_room(struct tty_struct *tty)
1192{
1193 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1194 int room;
1195 if (!mp || !mp->nccip) {
1196#ifdef _DEBUG_TTYFUNCS
1197 printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n");
1198#endif
1199 return 0;
1200 }
1201 room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
1202 room *= CAPI_MAX_BLKSIZE;
1203#ifdef _DEBUG_TTYFUNCS
1204 printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room);
1205#endif
1206 return room;
1207}
1208
Adrian Bunk408b6642005-05-01 08:59:29 -07001209static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210{
1211 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1212 if (!mp || !mp->nccip) {
1213#ifdef _DEBUG_TTYFUNCS
1214 printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n");
1215#endif
1216 return 0;
1217 }
1218#ifdef _DEBUG_TTYFUNCS
1219 printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n",
1220 mp->outbytes, mp->nack,
1221 skb_queue_len(&mp->outqueue),
1222 skb_queue_len(&mp->inqueue));
1223#endif
1224 return mp->outbytes;
1225}
1226
1227static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1228 unsigned int cmd, unsigned long arg)
1229{
1230 int error = 0;
1231 switch (cmd) {
1232 default:
Stephen Rothwell53e86312008-10-13 10:44:33 +01001233 error = n_tty_ioctl_helper(tty, file, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 break;
1235 }
1236 return error;
1237}
1238
Alan Cox606d0992006-12-08 02:38:45 -08001239static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
1241#ifdef _DEBUG_TTYFUNCS
1242 printk(KERN_DEBUG "capinc_tty_set_termios\n");
1243#endif
1244}
1245
1246static void capinc_tty_throttle(struct tty_struct * tty)
1247{
1248 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1249#ifdef _DEBUG_TTYFUNCS
1250 printk(KERN_DEBUG "capinc_tty_throttle\n");
1251#endif
1252 if (mp)
1253 mp->ttyinstop = 1;
1254}
1255
1256static void capinc_tty_unthrottle(struct tty_struct * tty)
1257{
1258 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001259 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260#ifdef _DEBUG_TTYFUNCS
1261 printk(KERN_DEBUG "capinc_tty_unthrottle\n");
1262#endif
1263 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001264 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 mp->ttyinstop = 0;
1266 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001267 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 }
1269}
1270
1271static void capinc_tty_stop(struct tty_struct *tty)
1272{
1273 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1274#ifdef _DEBUG_TTYFUNCS
1275 printk(KERN_DEBUG "capinc_tty_stop\n");
1276#endif
1277 if (mp) {
1278 mp->ttyoutstop = 1;
1279 }
1280}
1281
1282static void capinc_tty_start(struct tty_struct *tty)
1283{
1284 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001285 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286#ifdef _DEBUG_TTYFUNCS
1287 printk(KERN_DEBUG "capinc_tty_start\n");
1288#endif
1289 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001290 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 mp->ttyoutstop = 0;
1292 (void)handle_minor_send(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001293 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 }
1295}
1296
1297static void capinc_tty_hangup(struct tty_struct *tty)
1298{
1299#ifdef _DEBUG_TTYFUNCS
1300 printk(KERN_DEBUG "capinc_tty_hangup\n");
1301#endif
1302}
1303
Alan Cox9e98966c2008-07-22 11:18:03 +01001304static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
1306#ifdef _DEBUG_TTYFUNCS
1307 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1308#endif
Alan Cox9e98966c2008-07-22 11:18:03 +01001309 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
1312static void capinc_tty_flush_buffer(struct tty_struct *tty)
1313{
1314#ifdef _DEBUG_TTYFUNCS
1315 printk(KERN_DEBUG "capinc_tty_flush_buffer\n");
1316#endif
1317}
1318
1319static void capinc_tty_set_ldisc(struct tty_struct *tty)
1320{
1321#ifdef _DEBUG_TTYFUNCS
1322 printk(KERN_DEBUG "capinc_tty_set_ldisc\n");
1323#endif
1324}
1325
1326static void capinc_tty_send_xchar(struct tty_struct *tty, char ch)
1327{
1328#ifdef _DEBUG_TTYFUNCS
1329 printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch);
1330#endif
1331}
1332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333static struct tty_driver *capinc_tty_driver;
1334
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001335static const struct tty_operations capinc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .open = capinc_tty_open,
1337 .close = capinc_tty_close,
1338 .write = capinc_tty_write,
1339 .put_char = capinc_tty_put_char,
1340 .flush_chars = capinc_tty_flush_chars,
1341 .write_room = capinc_tty_write_room,
1342 .chars_in_buffer = capinc_tty_chars_in_buffer,
1343 .ioctl = capinc_tty_ioctl,
1344 .set_termios = capinc_tty_set_termios,
1345 .throttle = capinc_tty_throttle,
1346 .unthrottle = capinc_tty_unthrottle,
1347 .stop = capinc_tty_stop,
1348 .start = capinc_tty_start,
1349 .hangup = capinc_tty_hangup,
1350 .break_ctl = capinc_tty_break_ctl,
1351 .flush_buffer = capinc_tty_flush_buffer,
1352 .set_ldisc = capinc_tty_set_ldisc,
1353 .send_xchar = capinc_tty_send_xchar,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354};
1355
1356static int capinc_tty_init(void)
1357{
1358 struct tty_driver *drv;
1359
1360 if (capi_ttyminors > CAPINC_MAX_PORTS)
1361 capi_ttyminors = CAPINC_MAX_PORTS;
1362 if (capi_ttyminors <= 0)
1363 capi_ttyminors = CAPINC_NR_PORTS;
1364
1365 drv = alloc_tty_driver(capi_ttyminors);
1366 if (!drv)
1367 return -ENOMEM;
1368
1369 drv->owner = THIS_MODULE;
1370 drv->driver_name = "capi_nc";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 drv->name = "capi";
1372 drv->major = capi_ttymajor;
1373 drv->minor_start = 0;
1374 drv->type = TTY_DRIVER_TYPE_SERIAL;
1375 drv->subtype = SERIAL_TYPE_NORMAL;
1376 drv->init_termios = tty_std_termios;
1377 drv->init_termios.c_iflag = ICRNL;
1378 drv->init_termios.c_oflag = OPOST | ONLCR;
1379 drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1380 drv->init_termios.c_lflag = 0;
1381 drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS;
1382 tty_set_operations(drv, &capinc_ops);
1383 if (tty_register_driver(drv)) {
1384 put_tty_driver(drv);
1385 printk(KERN_ERR "Couldn't register capi_nc driver\n");
1386 return -1;
1387 }
1388 capinc_tty_driver = drv;
1389 return 0;
1390}
1391
1392static void capinc_tty_exit(void)
1393{
1394 struct tty_driver *drv = capinc_tty_driver;
1395 int retval;
1396 if ((retval = tty_unregister_driver(drv)))
1397 printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
1398 put_tty_driver(drv);
1399}
1400
1401#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1402
1403/* -------- /proc functions ----------------------------------------- */
1404
1405/*
1406 * /proc/capi/capi20:
1407 * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
1408 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001409static int capi20_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
1411 struct capidev *cdev;
1412 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
1414 read_lock(&capidev_list_lock);
1415 list_for_each(l, &capidev_list) {
1416 cdev = list_entry(l, struct capidev, list);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001417 seq_printf(m, "0 %d %lu %lu %lu %lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 cdev->ap.applid,
1419 cdev->ap.nrecvctlpkt,
1420 cdev->ap.nrecvdatapkt,
1421 cdev->ap.nsentctlpkt,
1422 cdev->ap.nsentdatapkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001428static int capi20_proc_open(struct inode *inode, struct file *file)
1429{
1430 return single_open(file, capi20_proc_show, NULL);
1431}
1432
1433static const struct file_operations capi20_proc_fops = {
1434 .owner = THIS_MODULE,
1435 .open = capi20_proc_open,
1436 .read = seq_read,
1437 .llseek = seq_lseek,
1438 .release = single_release,
1439};
1440
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441/*
1442 * /proc/capi/capi20ncci:
1443 * applid ncci
1444 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001445static int capi20ncci_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 struct capidev *cdev;
1448 struct capincci *np;
1449 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 read_lock(&capidev_list_lock);
1452 list_for_each(l, &capidev_list) {
1453 cdev = list_entry(l, struct capidev, list);
1454 for (np=cdev->nccis; np; np = np->next) {
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001455 seq_printf(m, "%d 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 cdev->ap.applid,
1457 np->ncci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001461 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001464static int capi20ncci_proc_open(struct inode *inode, struct file *file)
1465{
1466 return single_open(file, capi20ncci_proc_show, NULL);
1467}
1468
1469static const struct file_operations capi20ncci_proc_fops = {
1470 .owner = THIS_MODULE,
1471 .open = capi20ncci_proc_open,
1472 .read = seq_read,
1473 .llseek = seq_lseek,
1474 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475};
1476
1477static void __init proc_init(void)
1478{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001479 proc_create("capi/capi20", 0, NULL, &capi20_proc_fops);
1480 proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
1483static void __exit proc_exit(void)
1484{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001485 remove_proc_entry("capi/capi20", NULL);
1486 remove_proc_entry("capi/capi20ncci", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
1489/* -------- init function and module interface ---------------------- */
1490
1491
1492static char rev[32];
1493
1494static int __init capi_init(void)
1495{
1496 char *p;
1497 char *compileinfo;
Andrew Morton6d9eac32006-03-28 01:56:19 -08001498 int major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001500 if ((p = strchr(revision, ':')) != NULL && p[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 strlcpy(rev, p + 2, sizeof(rev));
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001502 if ((p = strchr(rev, '$')) != NULL && p > rev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 *(p-1) = 0;
1504 } else
1505 strcpy(rev, "1.0");
1506
Andrew Morton6d9eac32006-03-28 01:56:19 -08001507 major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
1508 if (major_ret < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
Andrew Morton6d9eac32006-03-28 01:56:19 -08001510 return major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 }
gregkh@suse.de56b22932005-03-23 10:01:41 -08001512 capi_class = class_create(THIS_MODULE, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (IS_ERR(capi_class)) {
1514 unregister_chrdev(capi_major, "capi20");
1515 return PTR_ERR(capi_class);
1516 }
1517
Greg Kroah-Hartmana9b12612008-07-21 20:03:34 -07001518 device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1521 if (capinc_tty_init() < 0) {
Tony Jonesd78b0362007-09-25 02:03:03 +02001522 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001523 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 unregister_chrdev(capi_major, "capi20");
1525 return -ENOMEM;
1526 }
1527#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1528
1529 proc_init();
1530
1531#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1532#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
1533 compileinfo = " (middleware+capifs)";
1534#else
1535 compileinfo = " (no capifs)";
1536#endif
1537#else
1538 compileinfo = " (no middleware)";
1539#endif
1540 printk(KERN_NOTICE "capi20: Rev %s: started up with major %d%s\n",
1541 rev, capi_major, compileinfo);
1542
1543 return 0;
1544}
1545
1546static void __exit capi_exit(void)
1547{
1548 proc_exit();
1549
Tony Jonesd78b0362007-09-25 02:03:03 +02001550 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001551 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 unregister_chrdev(capi_major, "capi20");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1555 capinc_tty_exit();
1556#endif
1557 printk(KERN_NOTICE "capi: Rev %s: unloaded\n", rev);
1558}
1559
1560module_init(capi_init);
1561module_exit(capi_exit);