blob: 3b077978c496971f39cbdec83b8e54ef14d70632 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070048MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface");
49MODULE_AUTHOR("Carsten Paeth");
50MODULE_LICENSE("GPL");
51
52#undef _DEBUG_REFCOUNT /* alloc/free and open/close debug */
53#undef _DEBUG_TTYFUNCS /* call to tty_driver */
54#undef _DEBUG_DATAFLOW /* data flow */
55
56/* -------- driver information -------------------------------------- */
57
gregkh@suse.de56b22932005-03-23 10:01:41 -080058static struct class *capi_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Adrian Bunk408b6642005-05-01 08:59:29 -070060static int capi_major = 68; /* allocated */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
62#define CAPINC_NR_PORTS 32
63#define CAPINC_MAX_PORTS 256
Adrian Bunk408b6642005-05-01 08:59:29 -070064static int capi_ttymajor = 191;
65static int capi_ttyminors = CAPINC_NR_PORTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
67
68module_param_named(major, capi_major, uint, 0);
69#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
70module_param_named(ttymajor, capi_ttymajor, uint, 0);
71module_param_named(ttyminors, capi_ttyminors, uint, 0);
72#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
73
74/* -------- defines ------------------------------------------------- */
75
76#define CAPINC_MAX_RECVQUEUE 10
77#define CAPINC_MAX_SENDQUEUE 10
78#define CAPI_MAX_BLKSIZE 2048
79
80/* -------- data structures ----------------------------------------- */
81
82struct capidev;
83struct capincci;
84#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
85struct capiminor;
86
Michael Buesch6aa65472006-06-26 00:25:30 -070087struct datahandle_queue {
88 struct list_head list;
89 u16 datahandle;
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092struct capiminor {
93 struct list_head list;
94 struct capincci *nccip;
95 unsigned int minor;
Jan Kiszka90926f02010-02-08 10:12:06 +000096 struct dentry *capifs_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 struct capi20_appl *ap;
99 u32 ncci;
100 u16 datahandle;
101 u16 msgid;
102
103 struct tty_struct *tty;
104 int ttyinstop;
105 int ttyoutstop;
106 struct sk_buff *ttyskb;
107 atomic_t ttyopencount;
108
109 struct sk_buff_head inqueue;
110 int inbytes;
111 struct sk_buff_head outqueue;
112 int outbytes;
113
114 /* transmit path */
Michael Buesch6aa65472006-06-26 00:25:30 -0700115 struct list_head ackqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 int nack;
Michael Buesch6aa65472006-06-26 00:25:30 -0700117 spinlock_t ackqlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
120
Michael Buesch053b47f2007-02-12 00:53:26 -0800121/* FIXME: The following lock is a sledgehammer-workaround to a
122 * locking issue with the capiminor (and maybe other) data structure(s).
123 * Access to this data is done in a racy way and crashes the machine with
124 * a FritzCard DSL driver; sooner or later. This is a workaround
125 * which trades scalability vs stability, so it doesn't crash the kernel anymore.
126 * The correct (and scalable) fix for the issue seems to require
127 * an API change to the drivers... . */
128static DEFINE_SPINLOCK(workaround_lock);
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130struct capincci {
131 struct capincci *next;
132 u32 ncci;
133 struct capidev *cdev;
134#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
135 struct capiminor *minorp;
136#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
137};
138
139struct capidev {
140 struct list_head list;
141 struct capi20_appl ap;
142 u16 errcode;
143 unsigned userflags;
144
145 struct sk_buff_head recvqueue;
146 wait_queue_head_t recvwait;
147
148 struct capincci *nccis;
149
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700150 struct mutex ncci_list_mtx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153/* -------- global variables ---------------------------------------- */
154
155static DEFINE_RWLOCK(capidev_list_lock);
156static LIST_HEAD(capidev_list);
157
158#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
159static DEFINE_RWLOCK(capiminor_list_lock);
160static LIST_HEAD(capiminor_list);
161#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
162
163#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
164/* -------- datahandles --------------------------------------------- */
165
166static int capincci_add_ack(struct capiminor *mp, u16 datahandle)
167{
Michael Buesch6aa65472006-06-26 00:25:30 -0700168 struct datahandle_queue *n;
169 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 n = kmalloc(sizeof(*n), GFP_ATOMIC);
Michael Buesch6aa65472006-06-26 00:25:30 -0700172 if (unlikely(!n)) {
173 printk(KERN_ERR "capi: alloc datahandle failed\n");
174 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 n->datahandle = datahandle;
Michael Buesch6aa65472006-06-26 00:25:30 -0700177 INIT_LIST_HEAD(&n->list);
178 spin_lock_irqsave(&mp->ackqlock, flags);
179 list_add_tail(&n->list, &mp->ackqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 mp->nack++;
Michael Buesch6aa65472006-06-26 00:25:30 -0700181 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return 0;
183}
184
185static int capiminor_del_ack(struct capiminor *mp, u16 datahandle)
186{
Michael Buesch6aa65472006-06-26 00:25:30 -0700187 struct datahandle_queue *p, *tmp;
188 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Michael Buesch6aa65472006-06-26 00:25:30 -0700190 spin_lock_irqsave(&mp->ackqlock, flags);
191 list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
192 if (p->datahandle == datahandle) {
193 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 kfree(p);
195 mp->nack--;
Michael Buesch6aa65472006-06-26 00:25:30 -0700196 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return 0;
198 }
199 }
Michael Buesch6aa65472006-06-26 00:25:30 -0700200 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return -1;
202}
203
204static void capiminor_del_all_ack(struct capiminor *mp)
205{
Michael Buesch6aa65472006-06-26 00:25:30 -0700206 struct datahandle_queue *p, *tmp;
207 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Michael Buesch6aa65472006-06-26 00:25:30 -0700209 spin_lock_irqsave(&mp->ackqlock, flags);
210 list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) {
211 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 kfree(p);
213 mp->nack--;
214 }
Michael Buesch6aa65472006-06-26 00:25:30 -0700215 spin_unlock_irqrestore(&mp->ackqlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218
219/* -------- struct capiminor ---------------------------------------- */
220
221static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
222{
223 struct capiminor *mp, *p;
224 unsigned int minor = 0;
225 unsigned long flags;
226
Burman Yan41f96932006-12-08 02:39:35 -0800227 mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (!mp) {
229 printk(KERN_ERR "capi: can't alloc capiminor\n");
230 return NULL;
231 }
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 mp->ap = ap;
234 mp->ncci = ncci;
235 mp->msgid = 0;
236 atomic_set(&mp->ttyopencount,0);
Michael Buesch6aa65472006-06-26 00:25:30 -0700237 INIT_LIST_HEAD(&mp->ackqueue);
238 spin_lock_init(&mp->ackqlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 skb_queue_head_init(&mp->inqueue);
241 skb_queue_head_init(&mp->outqueue);
242
243 /* Allocate the least unused minor number.
244 */
245 write_lock_irqsave(&capiminor_list_lock, flags);
246 if (list_empty(&capiminor_list))
247 list_add(&mp->list, &capiminor_list);
248 else {
249 list_for_each_entry(p, &capiminor_list, list) {
250 if (p->minor > minor)
251 break;
252 minor++;
253 }
254
255 if (minor < capi_ttyminors) {
256 mp->minor = minor;
257 list_add(&mp->list, p->list.prev);
258 }
259 }
260 write_unlock_irqrestore(&capiminor_list_lock, flags);
261
262 if (!(minor < capi_ttyminors)) {
263 printk(KERN_NOTICE "capi: out of minors\n");
264 kfree(mp);
265 return NULL;
266 }
267
268 return mp;
269}
270
271static void capiminor_free(struct capiminor *mp)
272{
273 unsigned long flags;
274
275 write_lock_irqsave(&capiminor_list_lock, flags);
276 list_del(&mp->list);
277 write_unlock_irqrestore(&capiminor_list_lock, flags);
278
Wei Yongjund46604e2009-02-25 00:12:09 +0000279 kfree_skb(mp->ttyskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 mp->ttyskb = NULL;
281 skb_queue_purge(&mp->inqueue);
282 skb_queue_purge(&mp->outqueue);
283 capiminor_del_all_ack(mp);
284 kfree(mp);
285}
286
Adrian Bunk408b6642005-05-01 08:59:29 -0700287static struct capiminor *capiminor_find(unsigned int minor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 struct list_head *l;
290 struct capiminor *p = NULL;
291
292 read_lock(&capiminor_list_lock);
293 list_for_each(l, &capiminor_list) {
294 p = list_entry(l, struct capiminor, list);
295 if (p->minor == minor)
296 break;
297 }
298 read_unlock(&capiminor_list_lock);
299 if (l == &capiminor_list)
300 return NULL;
301
302 return p;
303}
304#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
305
306/* -------- struct capincci ----------------------------------------- */
307
308static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
309{
310 struct capincci *np, **pp;
311#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
312 struct capiminor *mp = NULL;
313#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
314
Burman Yan41f96932006-12-08 02:39:35 -0800315 np = kzalloc(sizeof(*np), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!np)
317 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 np->ncci = ncci;
319 np->cdev = cdev;
320#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
321 mp = NULL;
322 if (cdev->userflags & CAPIFLAG_HIGHJACKING)
323 mp = np->minorp = capiminor_alloc(&cdev->ap, ncci);
324 if (mp) {
325 mp->nccip = np;
326#ifdef _DEBUG_REFCOUNT
327 printk(KERN_DEBUG "set mp->nccip\n");
328#endif
Jan Kiszka90926f02010-02-08 10:12:06 +0000329 mp->capifs_dentry =
330 capifs_new_ncci(mp->minor,
331 MKDEV(capi_ttymajor, mp->minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
334 for (pp=&cdev->nccis; *pp; pp = &(*pp)->next)
335 ;
336 *pp = np;
337 return np;
338}
339
340static void capincci_free(struct capidev *cdev, u32 ncci)
341{
342 struct capincci *np, **pp;
343#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
344 struct capiminor *mp;
345#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
346
347 pp=&cdev->nccis;
348 while (*pp) {
349 np = *pp;
350 if (ncci == 0xffffffff || np->ncci == ncci) {
351 *pp = (*pp)->next;
352#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700353 if ((mp = np->minorp) != NULL) {
Jan Kiszka90926f02010-02-08 10:12:06 +0000354 capifs_free_ncci(mp->capifs_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (mp->tty) {
356 mp->nccip = NULL;
357#ifdef _DEBUG_REFCOUNT
358 printk(KERN_DEBUG "reset mp->nccip\n");
359#endif
360 tty_hangup(mp->tty);
361 } else {
362 capiminor_free(mp);
363 }
364 }
365#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
366 kfree(np);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700367 if (*pp == NULL) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 } else {
369 pp = &(*pp)->next;
370 }
371 }
372}
373
374static struct capincci *capincci_find(struct capidev *cdev, u32 ncci)
375{
376 struct capincci *p;
377
378 for (p=cdev->nccis; p ; p = p->next) {
379 if (p->ncci == ncci)
380 break;
381 }
382 return p;
383}
384
385/* -------- struct capidev ------------------------------------------ */
386
387static struct capidev *capidev_alloc(void)
388{
389 struct capidev *cdev;
390 unsigned long flags;
391
Burman Yan41f96932006-12-08 02:39:35 -0800392 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (!cdev)
394 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700396 mutex_init(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 skb_queue_head_init(&cdev->recvqueue);
398 init_waitqueue_head(&cdev->recvwait);
399 write_lock_irqsave(&capidev_list_lock, flags);
400 list_add_tail(&cdev->list, &capidev_list);
401 write_unlock_irqrestore(&capidev_list_lock, flags);
402 return cdev;
403}
404
405static void capidev_free(struct capidev *cdev)
406{
407 unsigned long flags;
408
409 if (cdev->ap.applid) {
410 capi20_release(&cdev->ap);
411 cdev->ap.applid = 0;
412 }
413 skb_queue_purge(&cdev->recvqueue);
414
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700415 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 capincci_free(cdev, 0xffffffff);
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700417 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 write_lock_irqsave(&capidev_list_lock, flags);
420 list_del(&cdev->list);
421 write_unlock_irqrestore(&capidev_list_lock, flags);
422 kfree(cdev);
423}
424
425#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
426/* -------- handle data queue --------------------------------------- */
427
428static struct sk_buff *
429gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
430{
431 struct sk_buff *nskb;
432 nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_ATOMIC);
433 if (nskb) {
434 u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2);
435 unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN);
436 capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN);
437 capimsg_setu16(s, 2, mp->ap->applid);
438 capimsg_setu8 (s, 4, CAPI_DATA_B3);
439 capimsg_setu8 (s, 5, CAPI_RESP);
440 capimsg_setu16(s, 6, mp->msgid++);
441 capimsg_setu32(s, 8, mp->ncci);
442 capimsg_setu16(s, 12, datahandle);
443 }
444 return nskb;
445}
446
447static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)
448{
449 struct sk_buff *nskb;
450 int datalen;
451 u16 errcode, datahandle;
452 struct tty_ldisc *ld;
453
454 datalen = skb->len - CAPIMSG_LEN(skb->data);
455 if (mp->tty == NULL)
456 {
457#ifdef _DEBUG_DATAFLOW
458 printk(KERN_DEBUG "capi: currently no receiver\n");
459#endif
460 return -1;
461 }
462
463 ld = tty_ldisc_ref(mp->tty);
464 if (ld == NULL)
465 return -1;
Alan Coxa352def2008-07-16 21:53:12 +0100466 if (ld->ops->receive_buf == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
468 printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n");
469#endif
470 goto bad;
471 }
472 if (mp->ttyinstop) {
473#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
474 printk(KERN_DEBUG "capi: recv tty throttled\n");
475#endif
476 goto bad;
477 }
Alan Cox33f0f882006-01-09 20:54:13 -0800478 if (mp->tty->receive_room < datalen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
480 printk(KERN_DEBUG "capi: no room in tty\n");
481#endif
482 goto bad;
483 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700484 if ((nskb = gen_data_b3_resp_for(mp, skb)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 printk(KERN_ERR "capi: gen_data_b3_resp failed\n");
486 goto bad;
487 }
488 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4);
489 errcode = capi20_put_message(mp->ap, nskb);
490 if (errcode != CAPI_NOERROR) {
491 printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n",
492 errcode);
493 kfree_skb(nskb);
494 goto bad;
495 }
496 (void)skb_pull(skb, CAPIMSG_LEN(skb->data));
497#ifdef _DEBUG_DATAFLOW
498 printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n",
499 datahandle, skb->len);
500#endif
Alan Coxa352def2008-07-16 21:53:12 +0100501 ld->ops->receive_buf(mp->tty, skb->data, NULL, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 kfree_skb(skb);
503 tty_ldisc_deref(ld);
504 return 0;
505bad:
506 tty_ldisc_deref(ld);
507 return -1;
508}
509
510static void handle_minor_recv(struct capiminor *mp)
511{
512 struct sk_buff *skb;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700513 while ((skb = skb_dequeue(&mp->inqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 unsigned int len = skb->len;
515 mp->inbytes -= len;
516 if (handle_recv_skb(mp, skb) < 0) {
517 skb_queue_head(&mp->inqueue, skb);
518 mp->inbytes += len;
519 return;
520 }
521 }
522}
523
524static int handle_minor_send(struct capiminor *mp)
525{
526 struct sk_buff *skb;
527 u16 len;
528 int count = 0;
529 u16 errcode;
530 u16 datahandle;
531
532 if (mp->tty && mp->ttyoutstop) {
533#if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
534 printk(KERN_DEBUG "capi: send: tty stopped\n");
535#endif
536 return 0;
537 }
538
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700539 while ((skb = skb_dequeue(&mp->outqueue)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 datahandle = mp->datahandle;
541 len = (u16)skb->len;
542 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
543 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
544 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
545 capimsg_setu16(skb->data, 2, mp->ap->applid);
546 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
547 capimsg_setu8 (skb->data, 5, CAPI_REQ);
548 capimsg_setu16(skb->data, 6, mp->msgid++);
549 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
Andrew Morton5e6c20a2007-07-17 04:04:22 -0700550 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 capimsg_setu16(skb->data, 16, len); /* Data length */
552 capimsg_setu16(skb->data, 18, datahandle);
553 capimsg_setu16(skb->data, 20, 0); /* Flags */
554
555 if (capincci_add_ack(mp, datahandle) < 0) {
556 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
557 skb_queue_head(&mp->outqueue, skb);
558 return count;
559 }
560 errcode = capi20_put_message(mp->ap, skb);
561 if (errcode == CAPI_NOERROR) {
562 mp->datahandle++;
563 count++;
564 mp->outbytes -= len;
565#ifdef _DEBUG_DATAFLOW
566 printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n",
567 datahandle, len);
568#endif
569 continue;
570 }
571 capiminor_del_ack(mp, datahandle);
572
573 if (errcode == CAPI_SENDQUEUEFULL) {
574 skb_pull(skb, CAPI_DATA_B3_REQ_LEN);
575 skb_queue_head(&mp->outqueue, skb);
576 break;
577 }
578
579 /* ups, drop packet */
580 printk(KERN_ERR "capi: put_message = %x\n", errcode);
581 mp->outbytes -= len;
582 kfree_skb(skb);
583 }
584 return count;
585}
586
587#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
588/* -------- function called by lower level -------------------------- */
589
590static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
591{
592 struct capidev *cdev = ap->private;
593#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
594 struct capiminor *mp;
595 u16 datahandle;
596#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
597 struct capincci *np;
598 u32 ncci;
Michael Buesch053b47f2007-02-12 00:53:26 -0800599 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
602 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
Tilman Schmidt812d7342009-10-06 12:18:05 +0000603 if ((info & 0xff00) == 0) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700604 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700606 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608 }
609 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700610 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700612 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
Michael Buesch053b47f2007-02-12 00:53:26 -0800614 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
616 skb_queue_tail(&cdev->recvqueue, skb);
617 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800618 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 return;
620 }
621 ncci = CAPIMSG_CONTROL(skb->data);
622 for (np = cdev->nccis; np && np->ncci != ncci; np = np->next)
623 ;
624 if (!np) {
625 printk(KERN_ERR "BUG: capi_signal: ncci not found\n");
626 skb_queue_tail(&cdev->recvqueue, skb);
627 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800628 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return;
630 }
631#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
632 skb_queue_tail(&cdev->recvqueue, skb);
633 wake_up_interruptible(&cdev->recvwait);
634#else /* CONFIG_ISDN_CAPI_MIDDLEWARE */
635 mp = np->minorp;
636 if (!mp) {
637 skb_queue_tail(&cdev->recvqueue, skb);
638 wake_up_interruptible(&cdev->recvwait);
Michael Buesch053b47f2007-02-12 00:53:26 -0800639 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return;
641 }
642
643
644 if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) {
645
646 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2);
647#ifdef _DEBUG_DATAFLOW
648 printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n",
649 datahandle, skb->len-CAPIMSG_LEN(skb->data));
650#endif
651 skb_queue_tail(&mp->inqueue, skb);
652 mp->inbytes += skb->len;
653 handle_minor_recv(mp);
654
655 } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) {
656
657 datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4);
658#ifdef _DEBUG_DATAFLOW
659 printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n",
660 datahandle,
661 CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2));
662#endif
663 kfree_skb(skb);
664 (void)capiminor_del_ack(mp, datahandle);
665 if (mp->tty)
666 tty_wakeup(mp->tty);
667 (void)handle_minor_send(mp);
668
669 } else {
670 /* ups, let capi application handle it :-) */
671 skb_queue_tail(&cdev->recvqueue, skb);
672 wake_up_interruptible(&cdev->recvwait);
673 }
674#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Michael Buesch053b47f2007-02-12 00:53:26 -0800675 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678/* -------- file_operations for capidev ----------------------------- */
679
680static ssize_t
681capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
682{
683 struct capidev *cdev = (struct capidev *)file->private_data;
684 struct sk_buff *skb;
685 size_t copied;
686
687 if (!cdev->ap.applid)
688 return -ENODEV;
689
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700690 if ((skb = skb_dequeue(&cdev->recvqueue)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 if (file->f_flags & O_NONBLOCK)
693 return -EAGAIN;
694
695 for (;;) {
696 interruptible_sleep_on(&cdev->recvwait);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700697 if ((skb = skb_dequeue(&cdev->recvqueue)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 break;
699 if (signal_pending(current))
700 break;
701 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700702 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return -ERESTARTNOHAND;
704 }
705 if (skb->len > count) {
706 skb_queue_head(&cdev->recvqueue, skb);
707 return -EMSGSIZE;
708 }
709 if (copy_to_user(buf, skb->data, skb->len)) {
710 skb_queue_head(&cdev->recvqueue, skb);
711 return -EFAULT;
712 }
713 copied = skb->len;
714
715 kfree_skb(skb);
716
717 return copied;
718}
719
720static ssize_t
721capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
722{
723 struct capidev *cdev = (struct capidev *)file->private_data;
724 struct sk_buff *skb;
725 u16 mlen;
726
727 if (!cdev->ap.applid)
728 return -ENODEV;
729
730 skb = alloc_skb(count, GFP_USER);
731 if (!skb)
732 return -ENOMEM;
733
734 if (copy_from_user(skb_put(skb, count), buf, count)) {
735 kfree_skb(skb);
736 return -EFAULT;
737 }
738 mlen = CAPIMSG_LEN(skb->data);
739 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
740 if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) {
741 kfree_skb(skb);
742 return -EINVAL;
743 }
744 } else {
745 if (mlen != count) {
746 kfree_skb(skb);
747 return -EINVAL;
748 }
749 }
750 CAPIMSG_SETAPPID(skb->data, cdev->ap.applid);
751
752 if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700753 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 capincci_free(cdev, CAPIMSG_NCCI(skb->data));
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700755 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
758 cdev->errcode = capi20_put_message(&cdev->ap, skb);
759
760 if (cdev->errcode) {
761 kfree_skb(skb);
762 return -EIO;
763 }
764 return count;
765}
766
767static unsigned int
768capi_poll(struct file *file, poll_table * wait)
769{
770 struct capidev *cdev = (struct capidev *)file->private_data;
771 unsigned int mask = 0;
772
773 if (!cdev->ap.applid)
774 return POLLERR;
775
776 poll_wait(file, &(cdev->recvwait), wait);
777 mask = POLLOUT | POLLWRNORM;
778 if (!skb_queue_empty(&cdev->recvqueue))
779 mask |= POLLIN | POLLRDNORM;
780 return mask;
781}
782
783static int
784capi_ioctl(struct inode *inode, struct file *file,
785 unsigned int cmd, unsigned long arg)
786{
787 struct capidev *cdev = file->private_data;
788 struct capi20_appl *ap = &cdev->ap;
789 capi_ioctl_struct data;
790 int retval = -EINVAL;
791 void __user *argp = (void __user *)arg;
792
793 switch (cmd) {
794 case CAPI_REGISTER:
795 {
796 if (ap->applid)
797 return -EEXIST;
798
799 if (copy_from_user(&cdev->ap.rparam, argp,
800 sizeof(struct capi_register_params)))
801 return -EFAULT;
802
803 cdev->ap.private = cdev;
804 cdev->ap.recv_message = capi_recv_message;
805 cdev->errcode = capi20_register(ap);
806 if (cdev->errcode) {
807 ap->applid = 0;
808 return -EIO;
809 }
810 }
811 return (int)ap->applid;
812
813 case CAPI_GET_VERSION:
814 {
815 if (copy_from_user(&data.contr, argp,
816 sizeof(data.contr)))
817 return -EFAULT;
818 cdev->errcode = capi20_get_version(data.contr, &data.version);
819 if (cdev->errcode)
820 return -EIO;
821 if (copy_to_user(argp, &data.version,
822 sizeof(data.version)))
823 return -EFAULT;
824 }
825 return 0;
826
827 case CAPI_GET_SERIAL:
828 {
829 if (copy_from_user(&data.contr, argp,
830 sizeof(data.contr)))
831 return -EFAULT;
832 cdev->errcode = capi20_get_serial (data.contr, data.serial);
833 if (cdev->errcode)
834 return -EIO;
835 if (copy_to_user(argp, data.serial,
836 sizeof(data.serial)))
837 return -EFAULT;
838 }
839 return 0;
840 case CAPI_GET_PROFILE:
841 {
842 if (copy_from_user(&data.contr, argp,
843 sizeof(data.contr)))
844 return -EFAULT;
845
846 if (data.contr == 0) {
847 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
848 if (cdev->errcode)
849 return -EIO;
850
851 retval = copy_to_user(argp,
852 &data.profile.ncontroller,
853 sizeof(data.profile.ncontroller));
854
855 } else {
856 cdev->errcode = capi20_get_profile(data.contr, &data.profile);
857 if (cdev->errcode)
858 return -EIO;
859
860 retval = copy_to_user(argp, &data.profile,
861 sizeof(data.profile));
862 }
863 if (retval)
864 return -EFAULT;
865 }
866 return 0;
867
868 case CAPI_GET_MANUFACTURER:
869 {
870 if (copy_from_user(&data.contr, argp,
871 sizeof(data.contr)))
872 return -EFAULT;
873 cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer);
874 if (cdev->errcode)
875 return -EIO;
876
877 if (copy_to_user(argp, data.manufacturer,
878 sizeof(data.manufacturer)))
879 return -EFAULT;
880
881 }
882 return 0;
883 case CAPI_GET_ERRCODE:
884 data.errcode = cdev->errcode;
885 cdev->errcode = CAPI_NOERROR;
886 if (arg) {
887 if (copy_to_user(argp, &data.errcode,
888 sizeof(data.errcode)))
889 return -EFAULT;
890 }
891 return data.errcode;
892
893 case CAPI_INSTALLED:
894 if (capi20_isinstalled() == CAPI_NOERROR)
895 return 0;
896 return -ENXIO;
897
898 case CAPI_MANUFACTURER_CMD:
899 {
900 struct capi_manufacturer_cmd mcmd;
901 if (!capable(CAP_SYS_ADMIN))
902 return -EPERM;
903 if (copy_from_user(&mcmd, argp, sizeof(mcmd)))
904 return -EFAULT;
905 return capi20_manufacturer(mcmd.cmd, mcmd.data);
906 }
907 return 0;
908
909 case CAPI_SET_FLAGS:
910 case CAPI_CLR_FLAGS:
911 {
912 unsigned userflags;
913 if (copy_from_user(&userflags, argp,
914 sizeof(userflags)))
915 return -EFAULT;
916 if (cmd == CAPI_SET_FLAGS)
917 cdev->userflags |= userflags;
918 else
919 cdev->userflags &= ~userflags;
920 }
921 return 0;
922
923 case CAPI_GET_FLAGS:
924 if (copy_to_user(argp, &cdev->userflags,
925 sizeof(cdev->userflags)))
926 return -EFAULT;
927 return 0;
928
929 case CAPI_NCCI_OPENCOUNT:
930 {
931 struct capincci *nccip;
932#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
933 struct capiminor *mp;
934#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
935 unsigned ncci;
936 int count = 0;
937 if (copy_from_user(&ncci, argp, sizeof(ncci)))
938 return -EFAULT;
939
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700940 mutex_lock(&cdev->ncci_list_mtx);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700941 if ((nccip = capincci_find(cdev, (u32) ncci)) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700942 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return 0;
944 }
945#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700946 if ((mp = nccip->minorp) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 count += atomic_read(&mp->ttyopencount);
948 }
949#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700950 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return count;
952 }
953 return 0;
954
955#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
956 case CAPI_NCCI_GETUNIT:
957 {
958 struct capincci *nccip;
959 struct capiminor *mp;
960 unsigned ncci;
961 int unit = 0;
962 if (copy_from_user(&ncci, argp,
963 sizeof(ncci)))
964 return -EFAULT;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700965 mutex_lock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 nccip = capincci_find(cdev, (u32) ncci);
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700967 if (!nccip || (mp = nccip->minorp) == NULL) {
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700968 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return -ESRCH;
970 }
971 unit = mp->minor;
Matthias Kaehlcke9ea6e5d2007-05-08 00:32:43 -0700972 mutex_unlock(&cdev->ncci_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 return unit;
974 }
975 return 0;
976#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
977 }
978 return -EINVAL;
979}
980
981static int
982capi_open(struct inode *inode, struct file *file)
983{
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600984 int ret;
985
986 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (file->private_data)
Jonathan Corbeta237f3b2008-05-16 14:15:33 -0600988 ret = -EEXIST;
989 else if ((file->private_data = capidev_alloc()) == NULL)
990 ret = -ENOMEM;
991 else
992 ret = nonseekable_open(inode, file);
993 unlock_kernel();
994 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
997static int
998capi_release(struct inode *inode, struct file *file)
999{
1000 struct capidev *cdev = (struct capidev *)file->private_data;
1001
1002 capidev_free(cdev);
1003 file->private_data = NULL;
1004
1005 return 0;
1006}
1007
Arjan van de Ven2b8693c2007-02-12 00:55:32 -08001008static const struct file_operations capi_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 .owner = THIS_MODULE,
1011 .llseek = no_llseek,
1012 .read = capi_read,
1013 .write = capi_write,
1014 .poll = capi_poll,
1015 .ioctl = capi_ioctl,
1016 .open = capi_open,
1017 .release = capi_release,
1018};
1019
1020#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1021/* -------- tty_operations for capincci ----------------------------- */
1022
1023static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1024{
1025 struct capiminor *mp;
Michael Buesch053b47f2007-02-12 00:53:26 -08001026 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001028 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 return -ENXIO;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001030 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return -ENXIO;
1032
1033 tty->driver_data = (void *)mp;
1034
Michael Buesch053b47f2007-02-12 00:53:26 -08001035 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (atomic_read(&mp->ttyopencount) == 0)
1037 mp->tty = tty;
1038 atomic_inc(&mp->ttyopencount);
1039#ifdef _DEBUG_REFCOUNT
1040 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount));
1041#endif
1042 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001043 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return 0;
1045}
1046
1047static void capinc_tty_close(struct tty_struct * tty, struct file * file)
1048{
1049 struct capiminor *mp;
1050
1051 mp = (struct capiminor *)tty->driver_data;
1052 if (mp) {
1053 if (atomic_dec_and_test(&mp->ttyopencount)) {
1054#ifdef _DEBUG_REFCOUNT
1055 printk(KERN_DEBUG "capinc_tty_close lastclose\n");
1056#endif
1057 tty->driver_data = NULL;
1058 mp->tty = NULL;
1059 }
1060#ifdef _DEBUG_REFCOUNT
1061 printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount));
1062#endif
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001063 if (mp->nccip == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 capiminor_free(mp);
1065 }
1066
1067#ifdef _DEBUG_REFCOUNT
1068 printk(KERN_DEBUG "capinc_tty_close\n");
1069#endif
1070}
1071
1072static int capinc_tty_write(struct tty_struct * tty,
1073 const unsigned char *buf, int count)
1074{
1075 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1076 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001077 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079#ifdef _DEBUG_TTYFUNCS
1080 printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count);
1081#endif
1082
1083 if (!mp || !mp->nccip) {
1084#ifdef _DEBUG_TTYFUNCS
1085 printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n");
1086#endif
1087 return 0;
1088 }
1089
Michael Buesch053b47f2007-02-12 00:53:26 -08001090 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 skb = mp->ttyskb;
1092 if (skb) {
1093 mp->ttyskb = NULL;
1094 skb_queue_tail(&mp->outqueue, skb);
1095 mp->outbytes += skb->len;
1096 }
1097
1098 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC);
1099 if (!skb) {
1100 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n");
Michael Buesch053b47f2007-02-12 00:53:26 -08001101 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return -ENOMEM;
1103 }
1104
1105 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1106 memcpy(skb_put(skb, count), buf, count);
1107
1108 skb_queue_tail(&mp->outqueue, skb);
1109 mp->outbytes += skb->len;
1110 (void)handle_minor_send(mp);
1111 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001112 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 return count;
1114}
1115
Alan Coxf2545a72008-04-30 00:54:09 -07001116static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
1118 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1119 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001120 unsigned long flags;
Alan Coxf2545a72008-04-30 00:54:09 -07001121 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123#ifdef _DEBUG_TTYFUNCS
1124 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
1125#endif
1126
1127 if (!mp || !mp->nccip) {
1128#ifdef _DEBUG_TTYFUNCS
1129 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n");
1130#endif
Alan Coxf2545a72008-04-30 00:54:09 -07001131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
1133
Michael Buesch053b47f2007-02-12 00:53:26 -08001134 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 skb = mp->ttyskb;
1136 if (skb) {
1137 if (skb_tailroom(skb) > 0) {
1138 *(skb_put(skb, 1)) = ch;
Michael Buesch053b47f2007-02-12 00:53:26 -08001139 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001140 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
1142 mp->ttyskb = NULL;
1143 skb_queue_tail(&mp->outqueue, skb);
1144 mp->outbytes += skb->len;
1145 (void)handle_minor_send(mp);
1146 }
1147 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC);
1148 if (skb) {
1149 skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
1150 *(skb_put(skb, 1)) = ch;
1151 mp->ttyskb = skb;
1152 } else {
1153 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
Alan Coxf2545a72008-04-30 00:54:09 -07001154 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
Michael Buesch053b47f2007-02-12 00:53:26 -08001156 spin_unlock_irqrestore(&workaround_lock, flags);
Alan Coxf2545a72008-04-30 00:54:09 -07001157 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
1160static void capinc_tty_flush_chars(struct tty_struct *tty)
1161{
1162 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1163 struct sk_buff *skb;
Michael Buesch053b47f2007-02-12 00:53:26 -08001164 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166#ifdef _DEBUG_TTYFUNCS
1167 printk(KERN_DEBUG "capinc_tty_flush_chars\n");
1168#endif
1169
1170 if (!mp || !mp->nccip) {
1171#ifdef _DEBUG_TTYFUNCS
1172 printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n");
1173#endif
1174 return;
1175 }
1176
Michael Buesch053b47f2007-02-12 00:53:26 -08001177 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 skb = mp->ttyskb;
1179 if (skb) {
1180 mp->ttyskb = NULL;
1181 skb_queue_tail(&mp->outqueue, skb);
1182 mp->outbytes += skb->len;
1183 (void)handle_minor_send(mp);
1184 }
1185 (void)handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001186 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
1189static int capinc_tty_write_room(struct tty_struct *tty)
1190{
1191 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1192 int room;
1193 if (!mp || !mp->nccip) {
1194#ifdef _DEBUG_TTYFUNCS
1195 printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n");
1196#endif
1197 return 0;
1198 }
1199 room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
1200 room *= CAPI_MAX_BLKSIZE;
1201#ifdef _DEBUG_TTYFUNCS
1202 printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room);
1203#endif
1204 return room;
1205}
1206
Adrian Bunk408b6642005-05-01 08:59:29 -07001207static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
1209 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1210 if (!mp || !mp->nccip) {
1211#ifdef _DEBUG_TTYFUNCS
1212 printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n");
1213#endif
1214 return 0;
1215 }
1216#ifdef _DEBUG_TTYFUNCS
1217 printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n",
1218 mp->outbytes, mp->nack,
1219 skb_queue_len(&mp->outqueue),
1220 skb_queue_len(&mp->inqueue));
1221#endif
1222 return mp->outbytes;
1223}
1224
1225static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1226 unsigned int cmd, unsigned long arg)
1227{
1228 int error = 0;
1229 switch (cmd) {
1230 default:
Stephen Rothwell53e86312008-10-13 10:44:33 +01001231 error = n_tty_ioctl_helper(tty, file, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 break;
1233 }
1234 return error;
1235}
1236
Alan Cox606d0992006-12-08 02:38:45 -08001237static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239#ifdef _DEBUG_TTYFUNCS
1240 printk(KERN_DEBUG "capinc_tty_set_termios\n");
1241#endif
1242}
1243
1244static void capinc_tty_throttle(struct tty_struct * tty)
1245{
1246 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1247#ifdef _DEBUG_TTYFUNCS
1248 printk(KERN_DEBUG "capinc_tty_throttle\n");
1249#endif
1250 if (mp)
1251 mp->ttyinstop = 1;
1252}
1253
1254static void capinc_tty_unthrottle(struct tty_struct * tty)
1255{
1256 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001257 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258#ifdef _DEBUG_TTYFUNCS
1259 printk(KERN_DEBUG "capinc_tty_unthrottle\n");
1260#endif
1261 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001262 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 mp->ttyinstop = 0;
1264 handle_minor_recv(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001265 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
1267}
1268
1269static void capinc_tty_stop(struct tty_struct *tty)
1270{
1271 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1272#ifdef _DEBUG_TTYFUNCS
1273 printk(KERN_DEBUG "capinc_tty_stop\n");
1274#endif
1275 if (mp) {
1276 mp->ttyoutstop = 1;
1277 }
1278}
1279
1280static void capinc_tty_start(struct tty_struct *tty)
1281{
1282 struct capiminor *mp = (struct capiminor *)tty->driver_data;
Michael Buesch053b47f2007-02-12 00:53:26 -08001283 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284#ifdef _DEBUG_TTYFUNCS
1285 printk(KERN_DEBUG "capinc_tty_start\n");
1286#endif
1287 if (mp) {
Michael Buesch053b47f2007-02-12 00:53:26 -08001288 spin_lock_irqsave(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 mp->ttyoutstop = 0;
1290 (void)handle_minor_send(mp);
Michael Buesch053b47f2007-02-12 00:53:26 -08001291 spin_unlock_irqrestore(&workaround_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 }
1293}
1294
1295static void capinc_tty_hangup(struct tty_struct *tty)
1296{
1297#ifdef _DEBUG_TTYFUNCS
1298 printk(KERN_DEBUG "capinc_tty_hangup\n");
1299#endif
1300}
1301
Alan Cox9e989662008-07-22 11:18:03 +01001302static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
1304#ifdef _DEBUG_TTYFUNCS
1305 printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state);
1306#endif
Alan Cox9e989662008-07-22 11:18:03 +01001307 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
1310static void capinc_tty_flush_buffer(struct tty_struct *tty)
1311{
1312#ifdef _DEBUG_TTYFUNCS
1313 printk(KERN_DEBUG "capinc_tty_flush_buffer\n");
1314#endif
1315}
1316
1317static void capinc_tty_set_ldisc(struct tty_struct *tty)
1318{
1319#ifdef _DEBUG_TTYFUNCS
1320 printk(KERN_DEBUG "capinc_tty_set_ldisc\n");
1321#endif
1322}
1323
1324static void capinc_tty_send_xchar(struct tty_struct *tty, char ch)
1325{
1326#ifdef _DEBUG_TTYFUNCS
1327 printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch);
1328#endif
1329}
1330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331static struct tty_driver *capinc_tty_driver;
1332
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001333static const struct tty_operations capinc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .open = capinc_tty_open,
1335 .close = capinc_tty_close,
1336 .write = capinc_tty_write,
1337 .put_char = capinc_tty_put_char,
1338 .flush_chars = capinc_tty_flush_chars,
1339 .write_room = capinc_tty_write_room,
1340 .chars_in_buffer = capinc_tty_chars_in_buffer,
1341 .ioctl = capinc_tty_ioctl,
1342 .set_termios = capinc_tty_set_termios,
1343 .throttle = capinc_tty_throttle,
1344 .unthrottle = capinc_tty_unthrottle,
1345 .stop = capinc_tty_stop,
1346 .start = capinc_tty_start,
1347 .hangup = capinc_tty_hangup,
1348 .break_ctl = capinc_tty_break_ctl,
1349 .flush_buffer = capinc_tty_flush_buffer,
1350 .set_ldisc = capinc_tty_set_ldisc,
1351 .send_xchar = capinc_tty_send_xchar,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352};
1353
1354static int capinc_tty_init(void)
1355{
1356 struct tty_driver *drv;
1357
1358 if (capi_ttyminors > CAPINC_MAX_PORTS)
1359 capi_ttyminors = CAPINC_MAX_PORTS;
1360 if (capi_ttyminors <= 0)
1361 capi_ttyminors = CAPINC_NR_PORTS;
1362
1363 drv = alloc_tty_driver(capi_ttyminors);
1364 if (!drv)
1365 return -ENOMEM;
1366
1367 drv->owner = THIS_MODULE;
1368 drv->driver_name = "capi_nc";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 drv->name = "capi";
1370 drv->major = capi_ttymajor;
1371 drv->minor_start = 0;
1372 drv->type = TTY_DRIVER_TYPE_SERIAL;
1373 drv->subtype = SERIAL_TYPE_NORMAL;
1374 drv->init_termios = tty_std_termios;
1375 drv->init_termios.c_iflag = ICRNL;
1376 drv->init_termios.c_oflag = OPOST | ONLCR;
1377 drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1378 drv->init_termios.c_lflag = 0;
1379 drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS;
1380 tty_set_operations(drv, &capinc_ops);
1381 if (tty_register_driver(drv)) {
1382 put_tty_driver(drv);
1383 printk(KERN_ERR "Couldn't register capi_nc driver\n");
1384 return -1;
1385 }
1386 capinc_tty_driver = drv;
1387 return 0;
1388}
1389
1390static void capinc_tty_exit(void)
1391{
1392 struct tty_driver *drv = capinc_tty_driver;
1393 int retval;
1394 if ((retval = tty_unregister_driver(drv)))
1395 printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval);
1396 put_tty_driver(drv);
1397}
1398
1399#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1400
1401/* -------- /proc functions ----------------------------------------- */
1402
1403/*
1404 * /proc/capi/capi20:
1405 * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt
1406 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001407static int capi20_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
1409 struct capidev *cdev;
1410 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 read_lock(&capidev_list_lock);
1413 list_for_each(l, &capidev_list) {
1414 cdev = list_entry(l, struct capidev, list);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001415 seq_printf(m, "0 %d %lu %lu %lu %lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 cdev->ap.applid,
1417 cdev->ap.nrecvctlpkt,
1418 cdev->ap.nrecvdatapkt,
1419 cdev->ap.nsentctlpkt,
1420 cdev->ap.nsentdatapkt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001423 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424}
1425
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001426static int capi20_proc_open(struct inode *inode, struct file *file)
1427{
1428 return single_open(file, capi20_proc_show, NULL);
1429}
1430
1431static const struct file_operations capi20_proc_fops = {
1432 .owner = THIS_MODULE,
1433 .open = capi20_proc_open,
1434 .read = seq_read,
1435 .llseek = seq_lseek,
1436 .release = single_release,
1437};
1438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439/*
1440 * /proc/capi/capi20ncci:
1441 * applid ncci
1442 */
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001443static int capi20ncci_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 struct capidev *cdev;
1446 struct capincci *np;
1447 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 read_lock(&capidev_list_lock);
1450 list_for_each(l, &capidev_list) {
1451 cdev = list_entry(l, struct capidev, list);
1452 for (np=cdev->nccis; np; np = np->next) {
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001453 seq_printf(m, "%d 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 cdev->ap.applid,
1455 np->ncci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
1457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 read_unlock(&capidev_list_lock);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001459 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460}
1461
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001462static int capi20ncci_proc_open(struct inode *inode, struct file *file)
1463{
1464 return single_open(file, capi20ncci_proc_show, NULL);
1465}
1466
1467static const struct file_operations capi20ncci_proc_fops = {
1468 .owner = THIS_MODULE,
1469 .open = capi20ncci_proc_open,
1470 .read = seq_read,
1471 .llseek = seq_lseek,
1472 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473};
1474
1475static void __init proc_init(void)
1476{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001477 proc_create("capi/capi20", 0, NULL, &capi20_proc_fops);
1478 proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481static void __exit proc_exit(void)
1482{
Alexey Dobriyan9a58a802010-01-14 03:10:54 -08001483 remove_proc_entry("capi/capi20", NULL);
1484 remove_proc_entry("capi/capi20ncci", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485}
1486
1487/* -------- init function and module interface ---------------------- */
1488
1489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490static int __init capi_init(void)
1491{
Jan Kiszka88549d62010-02-08 10:12:09 +00001492 const char *compileinfo;
Andrew Morton6d9eac32006-03-28 01:56:19 -08001493 int major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Andrew Morton6d9eac32006-03-28 01:56:19 -08001495 major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
1496 if (major_ret < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
Andrew Morton6d9eac32006-03-28 01:56:19 -08001498 return major_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 }
gregkh@suse.de56b22932005-03-23 10:01:41 -08001500 capi_class = class_create(THIS_MODULE, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (IS_ERR(capi_class)) {
1502 unregister_chrdev(capi_major, "capi20");
1503 return PTR_ERR(capi_class);
1504 }
1505
Greg Kroah-Hartmana9b12612008-07-21 20:03:34 -07001506 device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1509 if (capinc_tty_init() < 0) {
Tony Jonesd78b0362007-09-25 02:03:03 +02001510 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001511 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 unregister_chrdev(capi_major, "capi20");
1513 return -ENOMEM;
1514 }
1515#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
1516
1517 proc_init();
1518
1519#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1520#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE)
1521 compileinfo = " (middleware+capifs)";
1522#else
1523 compileinfo = " (no capifs)";
1524#endif
1525#else
1526 compileinfo = " (no middleware)";
1527#endif
Jan Kiszka88549d62010-02-08 10:12:09 +00001528 printk(KERN_NOTICE "CAPI 2.0 started up with major %d%s\n",
1529 capi_major, compileinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 return 0;
1532}
1533
1534static void __exit capi_exit(void)
1535{
1536 proc_exit();
1537
Tony Jonesd78b0362007-09-25 02:03:03 +02001538 device_destroy(capi_class, MKDEV(capi_major, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08001539 class_destroy(capi_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 unregister_chrdev(capi_major, "capi20");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1543 capinc_tty_exit();
1544#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
1547module_init(capi_init);
1548module_exit(capi_exit);