Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* $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 | ||
1da177e4 LT |
12 | #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> | |
9ea6e5d8 | 21 | #include <linux/mutex.h> |
1da177e4 | 22 | #include <linux/mm.h> |
a237f3bb | 23 | #include <linux/smp_lock.h> |
1da177e4 LT |
24 | #include <linux/timer.h> |
25 | #include <linux/wait.h> | |
1da177e4 | 26 | #include <linux/tty.h> |
1da177e4 LT |
27 | #include <linux/netdevice.h> |
28 | #include <linux/ppp_defs.h> | |
29 | #include <linux/if_ppp.h> | |
1da177e4 LT |
30 | #include <linux/skbuff.h> |
31 | #include <linux/proc_fs.h> | |
9a58a80a | 32 | #include <linux/seq_file.h> |
1da177e4 LT |
33 | #include <linux/poll.h> |
34 | #include <linux/capi.h> | |
35 | #include <linux/kernelcapi.h> | |
36 | #include <linux/init.h> | |
37 | #include <linux/device.h> | |
38 | #include <linux/moduleparam.h> | |
1da177e4 LT |
39 | #include <linux/isdn/capiutil.h> |
40 | #include <linux/isdn/capicmd.h> | |
90926f0e | 41 | |
1da177e4 | 42 | #include "capifs.h" |
1da177e4 | 43 | |
1da177e4 LT |
44 | MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface"); |
45 | MODULE_AUTHOR("Carsten Paeth"); | |
46 | MODULE_LICENSE("GPL"); | |
47 | ||
1da177e4 LT |
48 | #undef _DEBUG_TTYFUNCS /* call to tty_driver */ |
49 | #undef _DEBUG_DATAFLOW /* data flow */ | |
50 | ||
51 | /* -------- driver information -------------------------------------- */ | |
52 | ||
56b22935 | 53 | static struct class *capi_class; |
408b664a | 54 | static int capi_major = 68; /* allocated */ |
501c87a9 JK |
55 | |
56 | module_param_named(major, capi_major, uint, 0); | |
57 | ||
1da177e4 | 58 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
501c87a9 | 59 | #define CAPINC_NR_PORTS 32 |
1da177e4 | 60 | #define CAPINC_MAX_PORTS 256 |
501c87a9 | 61 | |
408b664a | 62 | static int capi_ttyminors = CAPINC_NR_PORTS; |
1da177e4 | 63 | |
1da177e4 LT |
64 | module_param_named(ttyminors, capi_ttyminors, uint, 0); |
65 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
66 | ||
67 | /* -------- defines ------------------------------------------------- */ | |
68 | ||
69 | #define CAPINC_MAX_RECVQUEUE 10 | |
70 | #define CAPINC_MAX_SENDQUEUE 10 | |
71 | #define CAPI_MAX_BLKSIZE 2048 | |
72 | ||
73 | /* -------- data structures ----------------------------------------- */ | |
74 | ||
75 | struct capidev; | |
76 | struct capincci; | |
1da177e4 LT |
77 | struct capiminor; |
78 | ||
42651b5c | 79 | struct ackqueue_entry { |
6aa65472 MB |
80 | struct list_head list; |
81 | u16 datahandle; | |
82 | }; | |
83 | ||
1da177e4 | 84 | struct capiminor { |
0159d549 JK |
85 | struct kref kref; |
86 | ||
1da177e4 | 87 | unsigned int minor; |
90926f0e | 88 | struct dentry *capifs_dentry; |
1da177e4 | 89 | |
42792713 JK |
90 | struct capi20_appl *ap; |
91 | u32 ncci; | |
92 | atomic_t datahandle; | |
93 | atomic_t msgid; | |
1da177e4 | 94 | |
fb4b4881 | 95 | struct tty_port port; |
1da177e4 LT |
96 | int ttyinstop; |
97 | int ttyoutstop; | |
1da177e4 | 98 | |
dfbb84ff JK |
99 | struct sk_buff_head inqueue; |
100 | ||
101 | struct sk_buff_head outqueue; | |
102 | int outbytes; | |
103 | struct sk_buff *outskb; | |
104 | spinlock_t outlock; | |
1da177e4 LT |
105 | |
106 | /* transmit path */ | |
6aa65472 | 107 | struct list_head ackqueue; |
1da177e4 | 108 | int nack; |
6aa65472 | 109 | spinlock_t ackqlock; |
1da177e4 | 110 | }; |
1da177e4 LT |
111 | |
112 | struct capincci { | |
884f5c44 | 113 | struct list_head list; |
1da177e4 LT |
114 | u32 ncci; |
115 | struct capidev *cdev; | |
116 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | |
117 | struct capiminor *minorp; | |
118 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
119 | }; | |
120 | ||
121 | struct capidev { | |
122 | struct list_head list; | |
123 | struct capi20_appl ap; | |
124 | u16 errcode; | |
125 | unsigned userflags; | |
126 | ||
127 | struct sk_buff_head recvqueue; | |
128 | wait_queue_head_t recvwait; | |
129 | ||
884f5c44 | 130 | struct list_head nccis; |
1da177e4 | 131 | |
05b41494 | 132 | struct mutex lock; |
1da177e4 LT |
133 | }; |
134 | ||
135 | /* -------- global variables ---------------------------------------- */ | |
136 | ||
b8f433dc | 137 | static DEFINE_MUTEX(capidev_list_lock); |
1da177e4 LT |
138 | static LIST_HEAD(capidev_list); |
139 | ||
140 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | |
501c87a9 | 141 | |
3d5d30fe | 142 | static DEFINE_SPINLOCK(capiminors_lock); |
81d17fe5 | 143 | static struct capiminor **capiminors; |
1da177e4 | 144 | |
40fb2d0d JK |
145 | static struct tty_driver *capinc_tty_driver; |
146 | ||
1da177e4 LT |
147 | /* -------- datahandles --------------------------------------------- */ |
148 | ||
501c87a9 | 149 | static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) |
1da177e4 | 150 | { |
42651b5c | 151 | struct ackqueue_entry *n; |
1da177e4 LT |
152 | |
153 | n = kmalloc(sizeof(*n), GFP_ATOMIC); | |
6aa65472 MB |
154 | if (unlikely(!n)) { |
155 | printk(KERN_ERR "capi: alloc datahandle failed\n"); | |
156 | return -1; | |
1da177e4 | 157 | } |
1da177e4 | 158 | n->datahandle = datahandle; |
6aa65472 | 159 | INIT_LIST_HEAD(&n->list); |
2b72b5bd | 160 | spin_lock_bh(&mp->ackqlock); |
6aa65472 | 161 | list_add_tail(&n->list, &mp->ackqueue); |
1da177e4 | 162 | mp->nack++; |
2b72b5bd | 163 | spin_unlock_bh(&mp->ackqlock); |
1da177e4 LT |
164 | return 0; |
165 | } | |
166 | ||
167 | static int capiminor_del_ack(struct capiminor *mp, u16 datahandle) | |
168 | { | |
42651b5c | 169 | struct ackqueue_entry *p, *tmp; |
1da177e4 | 170 | |
2b72b5bd | 171 | spin_lock_bh(&mp->ackqlock); |
6aa65472 MB |
172 | list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { |
173 | if (p->datahandle == datahandle) { | |
174 | list_del(&p->list); | |
1da177e4 | 175 | mp->nack--; |
2b72b5bd JK |
176 | spin_unlock_bh(&mp->ackqlock); |
177 | kfree(p); | |
1da177e4 LT |
178 | return 0; |
179 | } | |
180 | } | |
2b72b5bd | 181 | spin_unlock_bh(&mp->ackqlock); |
1da177e4 LT |
182 | return -1; |
183 | } | |
184 | ||
185 | static void capiminor_del_all_ack(struct capiminor *mp) | |
186 | { | |
42651b5c | 187 | struct ackqueue_entry *p, *tmp; |
1da177e4 | 188 | |
6aa65472 MB |
189 | list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { |
190 | list_del(&p->list); | |
1da177e4 LT |
191 | kfree(p); |
192 | mp->nack--; | |
193 | } | |
194 | } | |
195 | ||
196 | ||
197 | /* -------- struct capiminor ---------------------------------------- */ | |
198 | ||
fb4b4881 JK |
199 | static const struct tty_port_operations capiminor_port_ops; /* we have none */ |
200 | ||
1da177e4 LT |
201 | static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) |
202 | { | |
81d17fe5 | 203 | struct capiminor *mp; |
40fb2d0d | 204 | struct device *dev; |
81d17fe5 | 205 | unsigned int minor; |
1da177e4 | 206 | |
54f0fad3 | 207 | mp = kzalloc(sizeof(*mp), GFP_KERNEL); |
1da177e4 LT |
208 | if (!mp) { |
209 | printk(KERN_ERR "capi: can't alloc capiminor\n"); | |
210 | return NULL; | |
211 | } | |
212 | ||
0159d549 JK |
213 | kref_init(&mp->kref); |
214 | ||
1da177e4 LT |
215 | mp->ap = ap; |
216 | mp->ncci = ncci; | |
6aa65472 MB |
217 | INIT_LIST_HEAD(&mp->ackqueue); |
218 | spin_lock_init(&mp->ackqlock); | |
1da177e4 LT |
219 | |
220 | skb_queue_head_init(&mp->inqueue); | |
221 | skb_queue_head_init(&mp->outqueue); | |
dfbb84ff | 222 | spin_lock_init(&mp->outlock); |
1da177e4 | 223 | |
fb4b4881 JK |
224 | tty_port_init(&mp->port); |
225 | mp->port.ops = &capiminor_port_ops; | |
226 | ||
81d17fe5 | 227 | /* Allocate the least unused minor number. */ |
3d5d30fe | 228 | spin_lock(&capiminors_lock); |
81d17fe5 JK |
229 | for (minor = 0; minor < capi_ttyminors; minor++) |
230 | if (!capiminors[minor]) { | |
231 | capiminors[minor] = mp; | |
232 | break; | |
1da177e4 | 233 | } |
3d5d30fe | 234 | spin_unlock(&capiminors_lock); |
1da177e4 | 235 | |
81d17fe5 | 236 | if (minor == capi_ttyminors) { |
1da177e4 | 237 | printk(KERN_NOTICE "capi: out of minors\n"); |
40fb2d0d | 238 | goto err_out1; |
1da177e4 LT |
239 | } |
240 | ||
81d17fe5 JK |
241 | mp->minor = minor; |
242 | ||
40fb2d0d JK |
243 | dev = tty_register_device(capinc_tty_driver, minor, NULL); |
244 | if (IS_ERR(dev)) | |
245 | goto err_out2; | |
246 | ||
1da177e4 | 247 | return mp; |
40fb2d0d JK |
248 | |
249 | err_out2: | |
3d5d30fe | 250 | spin_lock(&capiminors_lock); |
40fb2d0d | 251 | capiminors[minor] = NULL; |
3d5d30fe | 252 | spin_unlock(&capiminors_lock); |
40fb2d0d JK |
253 | |
254 | err_out1: | |
255 | kfree(mp); | |
256 | return NULL; | |
1da177e4 LT |
257 | } |
258 | ||
0159d549 | 259 | static void capiminor_destroy(struct kref *kref) |
1da177e4 | 260 | { |
0159d549 | 261 | struct capiminor *mp = container_of(kref, struct capiminor, kref); |
1da177e4 | 262 | |
dfbb84ff | 263 | kfree_skb(mp->outskb); |
1da177e4 LT |
264 | skb_queue_purge(&mp->inqueue); |
265 | skb_queue_purge(&mp->outqueue); | |
266 | capiminor_del_all_ack(mp); | |
267 | kfree(mp); | |
268 | } | |
269 | ||
40fb2d0d | 270 | static struct capiminor *capiminor_get(unsigned int minor) |
1da177e4 | 271 | { |
81d17fe5 | 272 | struct capiminor *mp; |
1da177e4 | 273 | |
3d5d30fe | 274 | spin_lock(&capiminors_lock); |
81d17fe5 | 275 | mp = capiminors[minor]; |
0159d549 JK |
276 | if (mp) |
277 | kref_get(&mp->kref); | |
3d5d30fe | 278 | spin_unlock(&capiminors_lock); |
81d17fe5 JK |
279 | |
280 | return mp; | |
1da177e4 | 281 | } |
1da177e4 | 282 | |
0159d549 JK |
283 | static inline void capiminor_put(struct capiminor *mp) |
284 | { | |
285 | kref_put(&mp->kref, capiminor_destroy); | |
286 | } | |
287 | ||
288 | static void capiminor_free(struct capiminor *mp) | |
289 | { | |
0159d549 JK |
290 | tty_unregister_device(capinc_tty_driver, mp->minor); |
291 | ||
3d5d30fe | 292 | spin_lock(&capiminors_lock); |
0159d549 | 293 | capiminors[mp->minor] = NULL; |
3d5d30fe | 294 | spin_unlock(&capiminors_lock); |
0159d549 JK |
295 | |
296 | capiminor_put(mp); | |
297 | } | |
298 | ||
1da177e4 LT |
299 | /* -------- struct capincci ----------------------------------------- */ |
300 | ||
501c87a9 | 301 | static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) |
1da177e4 | 302 | { |
501c87a9 | 303 | struct capiminor *mp; |
e95ac143 | 304 | dev_t device; |
1da177e4 | 305 | |
501c87a9 JK |
306 | if (!(cdev->userflags & CAPIFLAG_HIGHJACKING)) |
307 | return; | |
308 | ||
309 | mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci); | |
1da177e4 | 310 | if (mp) { |
e95ac143 JK |
311 | device = MKDEV(capinc_tty_driver->major, mp->minor); |
312 | mp->capifs_dentry = capifs_new_ncci(mp->minor, device); | |
1da177e4 | 313 | } |
501c87a9 JK |
314 | } |
315 | ||
316 | static void capincci_free_minor(struct capincci *np) | |
317 | { | |
318 | struct capiminor *mp = np->minorp; | |
fb4b4881 | 319 | struct tty_struct *tty; |
501c87a9 JK |
320 | |
321 | if (mp) { | |
322 | capifs_free_ncci(mp->capifs_dentry); | |
fb4b4881 JK |
323 | |
324 | tty = tty_port_tty_get(&mp->port); | |
325 | if (tty) { | |
30bced91 | 326 | tty_vhangup(tty); |
fb4b4881 | 327 | tty_kref_put(tty); |
501c87a9 | 328 | } |
fb4b4881 JK |
329 | |
330 | capiminor_free(mp); | |
501c87a9 JK |
331 | } |
332 | } | |
333 | ||
334 | static inline unsigned int capincci_minor_opencount(struct capincci *np) | |
335 | { | |
336 | struct capiminor *mp = np->minorp; | |
a84fdf41 JK |
337 | unsigned int count = 0; |
338 | struct tty_struct *tty; | |
501c87a9 | 339 | |
a84fdf41 JK |
340 | if (mp) { |
341 | tty = tty_port_tty_get(&mp->port); | |
342 | if (tty) { | |
343 | count = tty->count; | |
344 | tty_kref_put(tty); | |
345 | } | |
346 | } | |
347 | return count; | |
501c87a9 JK |
348 | } |
349 | ||
350 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
351 | ||
352 | static inline void | |
353 | capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { } | |
354 | static inline void capincci_free_minor(struct capincci *np) { } | |
355 | ||
356 | static inline unsigned int capincci_minor_opencount(struct capincci *np) | |
357 | { | |
358 | return 0; | |
359 | } | |
360 | ||
361 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
362 | ||
363 | static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) | |
364 | { | |
884f5c44 | 365 | struct capincci *np; |
501c87a9 | 366 | |
54f0fad3 | 367 | np = kzalloc(sizeof(*np), GFP_KERNEL); |
501c87a9 JK |
368 | if (!np) |
369 | return NULL; | |
370 | np->ncci = ncci; | |
371 | np->cdev = cdev; | |
372 | ||
373 | capincci_alloc_minor(cdev, np); | |
374 | ||
884f5c44 JK |
375 | list_add_tail(&np->list, &cdev->nccis); |
376 | ||
377 | return np; | |
1da177e4 LT |
378 | } |
379 | ||
380 | static void capincci_free(struct capidev *cdev, u32 ncci) | |
381 | { | |
884f5c44 | 382 | struct capincci *np, *tmp; |
1da177e4 | 383 | |
884f5c44 | 384 | list_for_each_entry_safe(np, tmp, &cdev->nccis, list) |
1da177e4 | 385 | if (ncci == 0xffffffff || np->ncci == ncci) { |
501c87a9 | 386 | capincci_free_minor(np); |
884f5c44 | 387 | list_del(&np->list); |
1da177e4 | 388 | kfree(np); |
1da177e4 | 389 | } |
1da177e4 LT |
390 | } |
391 | ||
392 | static struct capincci *capincci_find(struct capidev *cdev, u32 ncci) | |
393 | { | |
884f5c44 | 394 | struct capincci *np; |
1da177e4 | 395 | |
884f5c44 JK |
396 | list_for_each_entry(np, &cdev->nccis, list) |
397 | if (np->ncci == ncci) | |
398 | return np; | |
399 | return NULL; | |
1da177e4 LT |
400 | } |
401 | ||
1da177e4 LT |
402 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
403 | /* -------- handle data queue --------------------------------------- */ | |
404 | ||
405 | static struct sk_buff * | |
406 | gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) | |
407 | { | |
408 | struct sk_buff *nskb; | |
dfbb84ff | 409 | nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_KERNEL); |
1da177e4 LT |
410 | if (nskb) { |
411 | u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2); | |
412 | unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN); | |
413 | capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN); | |
414 | capimsg_setu16(s, 2, mp->ap->applid); | |
415 | capimsg_setu8 (s, 4, CAPI_DATA_B3); | |
416 | capimsg_setu8 (s, 5, CAPI_RESP); | |
42792713 | 417 | capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid)); |
1da177e4 LT |
418 | capimsg_setu32(s, 8, mp->ncci); |
419 | capimsg_setu16(s, 12, datahandle); | |
420 | } | |
421 | return nskb; | |
422 | } | |
423 | ||
424 | static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) | |
425 | { | |
a11ef7be | 426 | unsigned int datalen = skb->len - CAPIMSG_LEN(skb->data); |
fb4b4881 | 427 | struct tty_struct *tty; |
1da177e4 | 428 | struct sk_buff *nskb; |
1da177e4 LT |
429 | u16 errcode, datahandle; |
430 | struct tty_ldisc *ld; | |
fb4b4881 JK |
431 | int ret = -1; |
432 | ||
fb4b4881 JK |
433 | tty = tty_port_tty_get(&mp->port); |
434 | if (!tty) { | |
1da177e4 LT |
435 | #ifdef _DEBUG_DATAFLOW |
436 | printk(KERN_DEBUG "capi: currently no receiver\n"); | |
437 | #endif | |
438 | return -1; | |
439 | } | |
440 | ||
fb4b4881 | 441 | ld = tty_ldisc_ref(tty); |
a11ef7be JK |
442 | if (!ld) { |
443 | /* fatal error, do not requeue */ | |
444 | ret = 0; | |
445 | kfree_skb(skb); | |
446 | goto deref_tty; | |
447 | } | |
fb4b4881 | 448 | |
a352def2 | 449 | if (ld->ops->receive_buf == NULL) { |
1da177e4 LT |
450 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
451 | printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n"); | |
452 | #endif | |
a11ef7be JK |
453 | /* fatal error, do not requeue */ |
454 | goto free_skb; | |
1da177e4 LT |
455 | } |
456 | if (mp->ttyinstop) { | |
457 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) | |
458 | printk(KERN_DEBUG "capi: recv tty throttled\n"); | |
459 | #endif | |
a11ef7be | 460 | goto deref_ldisc; |
1da177e4 | 461 | } |
a11ef7be | 462 | |
fb4b4881 | 463 | if (tty->receive_room < datalen) { |
1da177e4 LT |
464 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
465 | printk(KERN_DEBUG "capi: no room in tty\n"); | |
466 | #endif | |
a11ef7be | 467 | goto deref_ldisc; |
1da177e4 | 468 | } |
a11ef7be JK |
469 | |
470 | nskb = gen_data_b3_resp_for(mp, skb); | |
471 | if (!nskb) { | |
1da177e4 | 472 | printk(KERN_ERR "capi: gen_data_b3_resp failed\n"); |
a11ef7be | 473 | goto deref_ldisc; |
1da177e4 | 474 | } |
a11ef7be JK |
475 | |
476 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN + 4); | |
477 | ||
1da177e4 | 478 | errcode = capi20_put_message(mp->ap, nskb); |
a11ef7be JK |
479 | |
480 | if (errcode == CAPI_NOERROR) { | |
481 | skb_pull(skb, CAPIMSG_LEN(skb->data)); | |
482 | #ifdef _DEBUG_DATAFLOW | |
483 | printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n", | |
484 | datahandle, skb->len); | |
485 | #endif | |
486 | ld->ops->receive_buf(tty, skb->data, NULL, skb->len); | |
487 | } else { | |
1da177e4 LT |
488 | printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n", |
489 | errcode); | |
490 | kfree_skb(nskb); | |
a11ef7be JK |
491 | |
492 | if (errcode == CAPI_SENDQUEUEFULL) | |
493 | goto deref_ldisc; | |
1da177e4 | 494 | } |
a11ef7be JK |
495 | |
496 | free_skb: | |
fb4b4881 | 497 | ret = 0; |
a11ef7be JK |
498 | kfree_skb(skb); |
499 | ||
500 | deref_ldisc: | |
1da177e4 | 501 | tty_ldisc_deref(ld); |
a11ef7be JK |
502 | |
503 | deref_tty: | |
fb4b4881 JK |
504 | tty_kref_put(tty); |
505 | return ret; | |
1da177e4 LT |
506 | } |
507 | ||
508 | static void handle_minor_recv(struct capiminor *mp) | |
509 | { | |
510 | struct sk_buff *skb; | |
68d7347b JK |
511 | |
512 | while ((skb = skb_dequeue(&mp->inqueue)) != NULL) | |
1da177e4 LT |
513 | if (handle_recv_skb(mp, skb) < 0) { |
514 | skb_queue_head(&mp->inqueue, skb); | |
1da177e4 LT |
515 | return; |
516 | } | |
1da177e4 LT |
517 | } |
518 | ||
eef0ced0 | 519 | static void handle_minor_send(struct capiminor *mp) |
1da177e4 | 520 | { |
fb4b4881 | 521 | struct tty_struct *tty; |
1da177e4 LT |
522 | struct sk_buff *skb; |
523 | u16 len; | |
1da177e4 LT |
524 | u16 errcode; |
525 | u16 datahandle; | |
526 | ||
fb4b4881 JK |
527 | tty = tty_port_tty_get(&mp->port); |
528 | if (!tty) | |
eef0ced0 | 529 | return; |
fb4b4881 JK |
530 | |
531 | if (mp->ttyoutstop) { | |
1da177e4 LT |
532 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
533 | printk(KERN_DEBUG "capi: send: tty stopped\n"); | |
534 | #endif | |
fb4b4881 | 535 | tty_kref_put(tty); |
eef0ced0 | 536 | return; |
1da177e4 LT |
537 | } |
538 | ||
dfbb84ff JK |
539 | while (1) { |
540 | spin_lock_bh(&mp->outlock); | |
541 | skb = __skb_dequeue(&mp->outqueue); | |
542 | if (!skb) { | |
543 | spin_unlock_bh(&mp->outlock); | |
544 | break; | |
545 | } | |
1da177e4 | 546 | len = (u16)skb->len; |
dfbb84ff JK |
547 | mp->outbytes -= len; |
548 | spin_unlock_bh(&mp->outlock); | |
549 | ||
550 | datahandle = atomic_inc_return(&mp->datahandle); | |
1da177e4 LT |
551 | skb_push(skb, CAPI_DATA_B3_REQ_LEN); |
552 | memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN); | |
553 | capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN); | |
554 | capimsg_setu16(skb->data, 2, mp->ap->applid); | |
555 | capimsg_setu8 (skb->data, 4, CAPI_DATA_B3); | |
556 | capimsg_setu8 (skb->data, 5, CAPI_REQ); | |
42792713 | 557 | capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid)); |
1da177e4 | 558 | capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */ |
5e6c20a9 | 559 | capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */ |
1da177e4 LT |
560 | capimsg_setu16(skb->data, 16, len); /* Data length */ |
561 | capimsg_setu16(skb->data, 18, datahandle); | |
562 | capimsg_setu16(skb->data, 20, 0); /* Flags */ | |
563 | ||
501c87a9 | 564 | if (capiminor_add_ack(mp, datahandle) < 0) { |
1da177e4 | 565 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); |
dfbb84ff JK |
566 | |
567 | spin_lock_bh(&mp->outlock); | |
568 | __skb_queue_head(&mp->outqueue, skb); | |
569 | mp->outbytes += len; | |
570 | spin_unlock_bh(&mp->outlock); | |
571 | ||
eef0ced0 | 572 | break; |
1da177e4 LT |
573 | } |
574 | errcode = capi20_put_message(mp->ap, skb); | |
575 | if (errcode == CAPI_NOERROR) { | |
1da177e4 LT |
576 | #ifdef _DEBUG_DATAFLOW |
577 | printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n", | |
578 | datahandle, len); | |
579 | #endif | |
580 | continue; | |
581 | } | |
582 | capiminor_del_ack(mp, datahandle); | |
583 | ||
584 | if (errcode == CAPI_SENDQUEUEFULL) { | |
585 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); | |
dfbb84ff JK |
586 | |
587 | spin_lock_bh(&mp->outlock); | |
588 | __skb_queue_head(&mp->outqueue, skb); | |
589 | mp->outbytes += len; | |
590 | spin_unlock_bh(&mp->outlock); | |
591 | ||
1da177e4 LT |
592 | break; |
593 | } | |
594 | ||
595 | /* ups, drop packet */ | |
596 | printk(KERN_ERR "capi: put_message = %x\n", errcode); | |
1da177e4 LT |
597 | kfree_skb(skb); |
598 | } | |
fb4b4881 | 599 | tty_kref_put(tty); |
1da177e4 LT |
600 | } |
601 | ||
602 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
603 | /* -------- function called by lower level -------------------------- */ | |
604 | ||
605 | static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) | |
606 | { | |
607 | struct capidev *cdev = ap->private; | |
608 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | |
fb4b4881 | 609 | struct tty_struct *tty; |
1da177e4 LT |
610 | struct capiminor *mp; |
611 | u16 datahandle; | |
612 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
613 | struct capincci *np; | |
1da177e4 | 614 | |
05b41494 JK |
615 | mutex_lock(&cdev->lock); |
616 | ||
1da177e4 LT |
617 | if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { |
618 | u16 info = CAPIMSG_U16(skb->data, 12); // Info field | |
05b41494 | 619 | if ((info & 0xff00) == 0) |
1da177e4 | 620 | capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); |
1da177e4 | 621 | } |
05b41494 | 622 | if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) |
1da177e4 | 623 | capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); |
05b41494 | 624 | |
1da177e4 LT |
625 | if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { |
626 | skb_queue_tail(&cdev->recvqueue, skb); | |
627 | wake_up_interruptible(&cdev->recvwait); | |
05b41494 | 628 | goto unlock_out; |
1da177e4 | 629 | } |
05b41494 JK |
630 | |
631 | np = capincci_find(cdev, CAPIMSG_CONTROL(skb->data)); | |
1da177e4 LT |
632 | if (!np) { |
633 | printk(KERN_ERR "BUG: capi_signal: ncci not found\n"); | |
634 | skb_queue_tail(&cdev->recvqueue, skb); | |
635 | wake_up_interruptible(&cdev->recvwait); | |
05b41494 | 636 | goto unlock_out; |
1da177e4 | 637 | } |
501c87a9 | 638 | |
1da177e4 LT |
639 | #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE |
640 | skb_queue_tail(&cdev->recvqueue, skb); | |
641 | wake_up_interruptible(&cdev->recvwait); | |
501c87a9 | 642 | |
1da177e4 | 643 | #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
501c87a9 | 644 | |
1da177e4 LT |
645 | mp = np->minorp; |
646 | if (!mp) { | |
647 | skb_queue_tail(&cdev->recvqueue, skb); | |
648 | wake_up_interruptible(&cdev->recvwait); | |
05b41494 | 649 | goto unlock_out; |
1da177e4 | 650 | } |
1da177e4 | 651 | if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { |
1da177e4 LT |
652 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); |
653 | #ifdef _DEBUG_DATAFLOW | |
654 | printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", | |
655 | datahandle, skb->len-CAPIMSG_LEN(skb->data)); | |
656 | #endif | |
657 | skb_queue_tail(&mp->inqueue, skb); | |
68d7347b | 658 | |
1da177e4 LT |
659 | handle_minor_recv(mp); |
660 | ||
661 | } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) { | |
662 | ||
663 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4); | |
664 | #ifdef _DEBUG_DATAFLOW | |
665 | printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n", | |
666 | datahandle, | |
667 | CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2)); | |
668 | #endif | |
669 | kfree_skb(skb); | |
2b72b5bd | 670 | capiminor_del_ack(mp, datahandle); |
fb4b4881 JK |
671 | tty = tty_port_tty_get(&mp->port); |
672 | if (tty) { | |
673 | tty_wakeup(tty); | |
674 | tty_kref_put(tty); | |
675 | } | |
eef0ced0 | 676 | handle_minor_send(mp); |
1da177e4 LT |
677 | |
678 | } else { | |
679 | /* ups, let capi application handle it :-) */ | |
680 | skb_queue_tail(&cdev->recvqueue, skb); | |
681 | wake_up_interruptible(&cdev->recvwait); | |
682 | } | |
683 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
501c87a9 | 684 | |
05b41494 | 685 | unlock_out: |
05b41494 | 686 | mutex_unlock(&cdev->lock); |
1da177e4 LT |
687 | } |
688 | ||
689 | /* -------- file_operations for capidev ----------------------------- */ | |
690 | ||
691 | static ssize_t | |
692 | capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) | |
693 | { | |
694 | struct capidev *cdev = (struct capidev *)file->private_data; | |
695 | struct sk_buff *skb; | |
696 | size_t copied; | |
28a1dbb6 | 697 | int err; |
1da177e4 LT |
698 | |
699 | if (!cdev->ap.applid) | |
700 | return -ENODEV; | |
701 | ||
28a1dbb6 JK |
702 | skb = skb_dequeue(&cdev->recvqueue); |
703 | if (!skb) { | |
1da177e4 LT |
704 | if (file->f_flags & O_NONBLOCK) |
705 | return -EAGAIN; | |
28a1dbb6 JK |
706 | err = wait_event_interruptible(cdev->recvwait, |
707 | (skb = skb_dequeue(&cdev->recvqueue))); | |
708 | if (err) | |
709 | return err; | |
1da177e4 LT |
710 | } |
711 | if (skb->len > count) { | |
712 | skb_queue_head(&cdev->recvqueue, skb); | |
713 | return -EMSGSIZE; | |
714 | } | |
715 | if (copy_to_user(buf, skb->data, skb->len)) { | |
716 | skb_queue_head(&cdev->recvqueue, skb); | |
717 | return -EFAULT; | |
718 | } | |
719 | copied = skb->len; | |
720 | ||
721 | kfree_skb(skb); | |
722 | ||
723 | return copied; | |
724 | } | |
725 | ||
726 | static ssize_t | |
727 | capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | |
728 | { | |
729 | struct capidev *cdev = (struct capidev *)file->private_data; | |
730 | struct sk_buff *skb; | |
731 | u16 mlen; | |
732 | ||
733 | if (!cdev->ap.applid) | |
734 | return -ENODEV; | |
735 | ||
736 | skb = alloc_skb(count, GFP_USER); | |
737 | if (!skb) | |
738 | return -ENOMEM; | |
739 | ||
740 | if (copy_from_user(skb_put(skb, count), buf, count)) { | |
741 | kfree_skb(skb); | |
742 | return -EFAULT; | |
743 | } | |
744 | mlen = CAPIMSG_LEN(skb->data); | |
745 | if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) { | |
746 | if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) { | |
747 | kfree_skb(skb); | |
748 | return -EINVAL; | |
749 | } | |
750 | } else { | |
751 | if (mlen != count) { | |
752 | kfree_skb(skb); | |
753 | return -EINVAL; | |
754 | } | |
755 | } | |
756 | CAPIMSG_SETAPPID(skb->data, cdev->ap.applid); | |
757 | ||
758 | if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) { | |
05b41494 | 759 | mutex_lock(&cdev->lock); |
1da177e4 | 760 | capincci_free(cdev, CAPIMSG_NCCI(skb->data)); |
05b41494 | 761 | mutex_unlock(&cdev->lock); |
1da177e4 LT |
762 | } |
763 | ||
764 | cdev->errcode = capi20_put_message(&cdev->ap, skb); | |
765 | ||
766 | if (cdev->errcode) { | |
767 | kfree_skb(skb); | |
768 | return -EIO; | |
769 | } | |
770 | return count; | |
771 | } | |
772 | ||
773 | static unsigned int | |
774 | capi_poll(struct file *file, poll_table * wait) | |
775 | { | |
776 | struct capidev *cdev = (struct capidev *)file->private_data; | |
777 | unsigned int mask = 0; | |
778 | ||
779 | if (!cdev->ap.applid) | |
780 | return POLLERR; | |
781 | ||
782 | poll_wait(file, &(cdev->recvwait), wait); | |
783 | mask = POLLOUT | POLLWRNORM; | |
784 | if (!skb_queue_empty(&cdev->recvqueue)) | |
785 | mask |= POLLIN | POLLRDNORM; | |
786 | return mask; | |
787 | } | |
788 | ||
789 | static int | |
790 | capi_ioctl(struct inode *inode, struct file *file, | |
791 | unsigned int cmd, unsigned long arg) | |
792 | { | |
793 | struct capidev *cdev = file->private_data; | |
1da177e4 LT |
794 | capi_ioctl_struct data; |
795 | int retval = -EINVAL; | |
796 | void __user *argp = (void __user *)arg; | |
797 | ||
798 | switch (cmd) { | |
799 | case CAPI_REGISTER: | |
05b41494 | 800 | mutex_lock(&cdev->lock); |
1da177e4 | 801 | |
05b41494 JK |
802 | if (cdev->ap.applid) { |
803 | retval = -EEXIST; | |
804 | goto register_out; | |
805 | } | |
806 | if (copy_from_user(&cdev->ap.rparam, argp, | |
807 | sizeof(struct capi_register_params))) { | |
808 | retval = -EFAULT; | |
809 | goto register_out; | |
810 | } | |
811 | cdev->ap.private = cdev; | |
812 | cdev->ap.recv_message = capi_recv_message; | |
813 | cdev->errcode = capi20_register(&cdev->ap); | |
814 | retval = (int)cdev->ap.applid; | |
815 | if (cdev->errcode) { | |
816 | cdev->ap.applid = 0; | |
817 | retval = -EIO; | |
1da177e4 | 818 | } |
05b41494 JK |
819 | |
820 | register_out: | |
821 | mutex_unlock(&cdev->lock); | |
822 | return retval; | |
1da177e4 LT |
823 | |
824 | case CAPI_GET_VERSION: | |
825 | { | |
826 | if (copy_from_user(&data.contr, argp, | |
827 | sizeof(data.contr))) | |
828 | return -EFAULT; | |
829 | cdev->errcode = capi20_get_version(data.contr, &data.version); | |
830 | if (cdev->errcode) | |
831 | return -EIO; | |
832 | if (copy_to_user(argp, &data.version, | |
833 | sizeof(data.version))) | |
834 | return -EFAULT; | |
835 | } | |
836 | return 0; | |
837 | ||
838 | case CAPI_GET_SERIAL: | |
839 | { | |
840 | if (copy_from_user(&data.contr, argp, | |
841 | sizeof(data.contr))) | |
842 | return -EFAULT; | |
843 | cdev->errcode = capi20_get_serial (data.contr, data.serial); | |
844 | if (cdev->errcode) | |
845 | return -EIO; | |
846 | if (copy_to_user(argp, data.serial, | |
847 | sizeof(data.serial))) | |
848 | return -EFAULT; | |
849 | } | |
850 | return 0; | |
851 | case CAPI_GET_PROFILE: | |
852 | { | |
853 | if (copy_from_user(&data.contr, argp, | |
854 | sizeof(data.contr))) | |
855 | return -EFAULT; | |
856 | ||
857 | if (data.contr == 0) { | |
858 | cdev->errcode = capi20_get_profile(data.contr, &data.profile); | |
859 | if (cdev->errcode) | |
860 | return -EIO; | |
861 | ||
862 | retval = copy_to_user(argp, | |
863 | &data.profile.ncontroller, | |
864 | sizeof(data.profile.ncontroller)); | |
865 | ||
866 | } else { | |
867 | cdev->errcode = capi20_get_profile(data.contr, &data.profile); | |
868 | if (cdev->errcode) | |
869 | return -EIO; | |
870 | ||
871 | retval = copy_to_user(argp, &data.profile, | |
872 | sizeof(data.profile)); | |
873 | } | |
874 | if (retval) | |
875 | return -EFAULT; | |
876 | } | |
877 | return 0; | |
878 | ||
879 | case CAPI_GET_MANUFACTURER: | |
880 | { | |
881 | if (copy_from_user(&data.contr, argp, | |
882 | sizeof(data.contr))) | |
883 | return -EFAULT; | |
884 | cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer); | |
885 | if (cdev->errcode) | |
886 | return -EIO; | |
887 | ||
888 | if (copy_to_user(argp, data.manufacturer, | |
889 | sizeof(data.manufacturer))) | |
890 | return -EFAULT; | |
891 | ||
892 | } | |
893 | return 0; | |
894 | case CAPI_GET_ERRCODE: | |
895 | data.errcode = cdev->errcode; | |
896 | cdev->errcode = CAPI_NOERROR; | |
897 | if (arg) { | |
898 | if (copy_to_user(argp, &data.errcode, | |
899 | sizeof(data.errcode))) | |
900 | return -EFAULT; | |
901 | } | |
902 | return data.errcode; | |
903 | ||
904 | case CAPI_INSTALLED: | |
905 | if (capi20_isinstalled() == CAPI_NOERROR) | |
906 | return 0; | |
907 | return -ENXIO; | |
908 | ||
909 | case CAPI_MANUFACTURER_CMD: | |
910 | { | |
911 | struct capi_manufacturer_cmd mcmd; | |
912 | if (!capable(CAP_SYS_ADMIN)) | |
913 | return -EPERM; | |
914 | if (copy_from_user(&mcmd, argp, sizeof(mcmd))) | |
915 | return -EFAULT; | |
916 | return capi20_manufacturer(mcmd.cmd, mcmd.data); | |
917 | } | |
918 | return 0; | |
919 | ||
920 | case CAPI_SET_FLAGS: | |
05b41494 JK |
921 | case CAPI_CLR_FLAGS: { |
922 | unsigned userflags; | |
923 | ||
924 | if (copy_from_user(&userflags, argp, sizeof(userflags))) | |
925 | return -EFAULT; | |
1da177e4 | 926 | |
05b41494 JK |
927 | mutex_lock(&cdev->lock); |
928 | if (cmd == CAPI_SET_FLAGS) | |
929 | cdev->userflags |= userflags; | |
930 | else | |
931 | cdev->userflags &= ~userflags; | |
932 | mutex_unlock(&cdev->lock); | |
933 | return 0; | |
934 | } | |
1da177e4 LT |
935 | case CAPI_GET_FLAGS: |
936 | if (copy_to_user(argp, &cdev->userflags, | |
937 | sizeof(cdev->userflags))) | |
938 | return -EFAULT; | |
939 | return 0; | |
940 | ||
05b41494 JK |
941 | case CAPI_NCCI_OPENCOUNT: { |
942 | struct capincci *nccip; | |
943 | unsigned ncci; | |
944 | int count = 0; | |
1da177e4 | 945 | |
05b41494 JK |
946 | if (copy_from_user(&ncci, argp, sizeof(ncci))) |
947 | return -EFAULT; | |
948 | ||
949 | mutex_lock(&cdev->lock); | |
950 | nccip = capincci_find(cdev, (u32)ncci); | |
951 | if (nccip) | |
952 | count = capincci_minor_opencount(nccip); | |
953 | mutex_unlock(&cdev->lock); | |
954 | return count; | |
955 | } | |
1da177e4 LT |
956 | |
957 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | |
05b41494 JK |
958 | case CAPI_NCCI_GETUNIT: { |
959 | struct capincci *nccip; | |
960 | struct capiminor *mp; | |
961 | unsigned ncci; | |
962 | int unit = -ESRCH; | |
963 | ||
964 | if (copy_from_user(&ncci, argp, sizeof(ncci))) | |
965 | return -EFAULT; | |
966 | ||
967 | mutex_lock(&cdev->lock); | |
968 | nccip = capincci_find(cdev, (u32)ncci); | |
969 | if (nccip) { | |
970 | mp = nccip->minorp; | |
971 | if (mp) | |
972 | unit = mp->minor; | |
1da177e4 | 973 | } |
05b41494 JK |
974 | mutex_unlock(&cdev->lock); |
975 | return unit; | |
976 | } | |
1da177e4 | 977 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
05b41494 JK |
978 | |
979 | default: | |
980 | return -EINVAL; | |
1da177e4 | 981 | } |
1da177e4 LT |
982 | } |
983 | ||
eca39dd8 | 984 | static int capi_open(struct inode *inode, struct file *file) |
1da177e4 | 985 | { |
eca39dd8 JK |
986 | struct capidev *cdev; |
987 | ||
988 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); | |
989 | if (!cdev) | |
990 | return -ENOMEM; | |
991 | ||
05b41494 | 992 | mutex_init(&cdev->lock); |
eca39dd8 JK |
993 | skb_queue_head_init(&cdev->recvqueue); |
994 | init_waitqueue_head(&cdev->recvwait); | |
884f5c44 | 995 | INIT_LIST_HEAD(&cdev->nccis); |
eca39dd8 JK |
996 | file->private_data = cdev; |
997 | ||
998 | mutex_lock(&capidev_list_lock); | |
999 | list_add_tail(&cdev->list, &capidev_list); | |
1000 | mutex_unlock(&capidev_list_lock); | |
1001 | ||
1002 | return nonseekable_open(inode, file); | |
1da177e4 LT |
1003 | } |
1004 | ||
eca39dd8 | 1005 | static int capi_release(struct inode *inode, struct file *file) |
1da177e4 | 1006 | { |
eca39dd8 | 1007 | struct capidev *cdev = file->private_data; |
1da177e4 | 1008 | |
eca39dd8 JK |
1009 | mutex_lock(&capidev_list_lock); |
1010 | list_del(&cdev->list); | |
1011 | mutex_unlock(&capidev_list_lock); | |
1012 | ||
05b41494 | 1013 | if (cdev->ap.applid) |
eca39dd8 | 1014 | capi20_release(&cdev->ap); |
eca39dd8 | 1015 | skb_queue_purge(&cdev->recvqueue); |
eca39dd8 | 1016 | capincci_free(cdev, 0xffffffff); |
eca39dd8 JK |
1017 | |
1018 | kfree(cdev); | |
1da177e4 LT |
1019 | return 0; |
1020 | } | |
1021 | ||
2b8693c0 | 1022 | static const struct file_operations capi_fops = |
1da177e4 LT |
1023 | { |
1024 | .owner = THIS_MODULE, | |
1025 | .llseek = no_llseek, | |
1026 | .read = capi_read, | |
1027 | .write = capi_write, | |
1028 | .poll = capi_poll, | |
1029 | .ioctl = capi_ioctl, | |
1030 | .open = capi_open, | |
1031 | .release = capi_release, | |
1032 | }; | |
1033 | ||
1034 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE | |
1035 | /* -------- tty_operations for capincci ----------------------------- */ | |
1036 | ||
46324511 JK |
1037 | static int |
1038 | capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty) | |
1da177e4 | 1039 | { |
46324511 JK |
1040 | int idx = tty->index; |
1041 | struct capiminor *mp = capiminor_get(idx); | |
1042 | int ret = tty_init_termios(tty); | |
1043 | ||
1044 | if (ret == 0) { | |
1045 | tty_driver_kref_get(driver); | |
1046 | tty->count++; | |
1047 | tty->driver_data = mp; | |
1048 | driver->ttys[idx] = tty; | |
1049 | } else | |
1050 | capiminor_put(mp); | |
1051 | return ret; | |
1052 | } | |
1da177e4 | 1053 | |
46324511 JK |
1054 | static void capinc_tty_cleanup(struct tty_struct *tty) |
1055 | { | |
1056 | struct capiminor *mp = tty->driver_data; | |
1057 | tty->driver_data = NULL; | |
1058 | capiminor_put(mp); | |
1059 | } | |
1da177e4 | 1060 | |
fb4b4881 | 1061 | static int capinc_tty_open(struct tty_struct *tty, struct file *filp) |
46324511 JK |
1062 | { |
1063 | struct capiminor *mp = tty->driver_data; | |
fb4b4881 JK |
1064 | int err; |
1065 | ||
1066 | err = tty_port_open(&mp->port, tty, filp); | |
1067 | if (err) | |
1068 | return err; | |
1da177e4 | 1069 | |
1da177e4 LT |
1070 | handle_minor_recv(mp); |
1071 | return 0; | |
1072 | } | |
1073 | ||
fb4b4881 | 1074 | static void capinc_tty_close(struct tty_struct *tty, struct file *filp) |
1da177e4 | 1075 | { |
46324511 | 1076 | struct capiminor *mp = tty->driver_data; |
1da177e4 | 1077 | |
fb4b4881 | 1078 | tty_port_close(&mp->port, tty, filp); |
1da177e4 LT |
1079 | } |
1080 | ||
6576c289 | 1081 | static int capinc_tty_write(struct tty_struct *tty, |
1da177e4 LT |
1082 | const unsigned char *buf, int count) |
1083 | { | |
2c8df722 | 1084 | struct capiminor *mp = tty->driver_data; |
1da177e4 LT |
1085 | struct sk_buff *skb; |
1086 | ||
1087 | #ifdef _DEBUG_TTYFUNCS | |
1088 | printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); | |
1089 | #endif | |
1090 | ||
dfbb84ff JK |
1091 | spin_lock_bh(&mp->outlock); |
1092 | skb = mp->outskb; | |
1da177e4 | 1093 | if (skb) { |
dfbb84ff JK |
1094 | mp->outskb = NULL; |
1095 | __skb_queue_tail(&mp->outqueue, skb); | |
1da177e4 LT |
1096 | mp->outbytes += skb->len; |
1097 | } | |
1098 | ||
1099 | skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC); | |
1100 | if (!skb) { | |
1101 | printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n"); | |
dfbb84ff | 1102 | spin_unlock_bh(&mp->outlock); |
1da177e4 LT |
1103 | return -ENOMEM; |
1104 | } | |
1105 | ||
1106 | skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); | |
1107 | memcpy(skb_put(skb, count), buf, count); | |
1108 | ||
dfbb84ff | 1109 | __skb_queue_tail(&mp->outqueue, skb); |
1da177e4 | 1110 | mp->outbytes += skb->len; |
dfbb84ff JK |
1111 | spin_unlock_bh(&mp->outlock); |
1112 | ||
eef0ced0 | 1113 | handle_minor_send(mp); |
dfbb84ff | 1114 | |
1da177e4 LT |
1115 | return count; |
1116 | } | |
1117 | ||
f2545a75 | 1118 | static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) |
1da177e4 | 1119 | { |
2c8df722 | 1120 | struct capiminor *mp = tty->driver_data; |
dfbb84ff | 1121 | bool invoke_send = false; |
1da177e4 | 1122 | struct sk_buff *skb; |
f2545a75 | 1123 | int ret = 1; |
1da177e4 LT |
1124 | |
1125 | #ifdef _DEBUG_TTYFUNCS | |
1126 | printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); | |
1127 | #endif | |
1128 | ||
dfbb84ff JK |
1129 | spin_lock_bh(&mp->outlock); |
1130 | skb = mp->outskb; | |
1da177e4 LT |
1131 | if (skb) { |
1132 | if (skb_tailroom(skb) > 0) { | |
1133 | *(skb_put(skb, 1)) = ch; | |
dfbb84ff | 1134 | goto unlock_out; |
1da177e4 | 1135 | } |
dfbb84ff JK |
1136 | mp->outskb = NULL; |
1137 | __skb_queue_tail(&mp->outqueue, skb); | |
1da177e4 | 1138 | mp->outbytes += skb->len; |
dfbb84ff | 1139 | invoke_send = true; |
1da177e4 | 1140 | } |
dfbb84ff | 1141 | |
1da177e4 LT |
1142 | skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC); |
1143 | if (skb) { | |
1144 | skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); | |
1145 | *(skb_put(skb, 1)) = ch; | |
dfbb84ff | 1146 | mp->outskb = skb; |
1da177e4 LT |
1147 | } else { |
1148 | printk(KERN_ERR "capinc_put_char: char %u lost\n", ch); | |
f2545a75 | 1149 | ret = 0; |
1da177e4 | 1150 | } |
dfbb84ff JK |
1151 | |
1152 | unlock_out: | |
1153 | spin_unlock_bh(&mp->outlock); | |
1154 | ||
1155 | if (invoke_send) | |
eef0ced0 | 1156 | handle_minor_send(mp); |
dfbb84ff | 1157 | |
f2545a75 | 1158 | return ret; |
1da177e4 LT |
1159 | } |
1160 | ||
1161 | static void capinc_tty_flush_chars(struct tty_struct *tty) | |
1162 | { | |
2c8df722 | 1163 | struct capiminor *mp = tty->driver_data; |
1da177e4 LT |
1164 | struct sk_buff *skb; |
1165 | ||
1166 | #ifdef _DEBUG_TTYFUNCS | |
1167 | printk(KERN_DEBUG "capinc_tty_flush_chars\n"); | |
1168 | #endif | |
1169 | ||
dfbb84ff JK |
1170 | spin_lock_bh(&mp->outlock); |
1171 | skb = mp->outskb; | |
1da177e4 | 1172 | if (skb) { |
dfbb84ff JK |
1173 | mp->outskb = NULL; |
1174 | __skb_queue_tail(&mp->outqueue, skb); | |
1da177e4 | 1175 | mp->outbytes += skb->len; |
dfbb84ff JK |
1176 | spin_unlock_bh(&mp->outlock); |
1177 | ||
eef0ced0 | 1178 | handle_minor_send(mp); |
dfbb84ff JK |
1179 | } else |
1180 | spin_unlock_bh(&mp->outlock); | |
1181 | ||
1182 | handle_minor_recv(mp); | |
1da177e4 LT |
1183 | } |
1184 | ||
1185 | static int capinc_tty_write_room(struct tty_struct *tty) | |
1186 | { | |
2c8df722 | 1187 | struct capiminor *mp = tty->driver_data; |
1da177e4 | 1188 | int room; |
2c8df722 | 1189 | |
1da177e4 LT |
1190 | room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue); |
1191 | room *= CAPI_MAX_BLKSIZE; | |
1192 | #ifdef _DEBUG_TTYFUNCS | |
1193 | printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room); | |
1194 | #endif | |
1195 | return room; | |
1196 | } | |
1197 | ||
408b664a | 1198 | static int capinc_tty_chars_in_buffer(struct tty_struct *tty) |
1da177e4 | 1199 | { |
2c8df722 JK |
1200 | struct capiminor *mp = tty->driver_data; |
1201 | ||
1da177e4 LT |
1202 | #ifdef _DEBUG_TTYFUNCS |
1203 | printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n", | |
1204 | mp->outbytes, mp->nack, | |
1205 | skb_queue_len(&mp->outqueue), | |
1206 | skb_queue_len(&mp->inqueue)); | |
1207 | #endif | |
1208 | return mp->outbytes; | |
1209 | } | |
1210 | ||
1211 | static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file, | |
1212 | unsigned int cmd, unsigned long arg) | |
1213 | { | |
1214 | int error = 0; | |
1215 | switch (cmd) { | |
1216 | default: | |
53e86317 | 1217 | error = n_tty_ioctl_helper(tty, file, cmd, arg); |
1da177e4 LT |
1218 | break; |
1219 | } | |
1220 | return error; | |
1221 | } | |
1222 | ||
606d099c | 1223 | static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old) |
1da177e4 LT |
1224 | { |
1225 | #ifdef _DEBUG_TTYFUNCS | |
1226 | printk(KERN_DEBUG "capinc_tty_set_termios\n"); | |
1227 | #endif | |
1228 | } | |
1229 | ||
2c8df722 | 1230 | static void capinc_tty_throttle(struct tty_struct *tty) |
1da177e4 | 1231 | { |
2c8df722 | 1232 | struct capiminor *mp = tty->driver_data; |
1da177e4 LT |
1233 | #ifdef _DEBUG_TTYFUNCS |
1234 | printk(KERN_DEBUG "capinc_tty_throttle\n"); | |
1235 | #endif | |
2c8df722 | 1236 | mp->ttyinstop = 1; |
1da177e4 LT |
1237 | } |
1238 | ||
2c8df722 | 1239 | static void capinc_tty_unthrottle(struct tty_struct *tty) |
1da177e4 | 1240 | { |
2c8df722 | 1241 | struct capiminor *mp = tty->driver_data; |
2c8df722 | 1242 | |
1da177e4 LT |
1243 | #ifdef _DEBUG_TTYFUNCS |
1244 | printk(KERN_DEBUG "capinc_tty_unthrottle\n"); | |
1245 | #endif | |
2c8df722 JK |
1246 | mp->ttyinstop = 0; |
1247 | handle_minor_recv(mp); | |
1da177e4 LT |
1248 | } |
1249 | ||
1250 | static void capinc_tty_stop(struct tty_struct *tty) | |
1251 | { | |
2c8df722 JK |
1252 | struct capiminor *mp = tty->driver_data; |
1253 | ||
1da177e4 LT |
1254 | #ifdef _DEBUG_TTYFUNCS |
1255 | printk(KERN_DEBUG "capinc_tty_stop\n"); | |
1256 | #endif | |
2c8df722 | 1257 | mp->ttyoutstop = 1; |
1da177e4 LT |
1258 | } |
1259 | ||
1260 | static void capinc_tty_start(struct tty_struct *tty) | |
1261 | { | |
2c8df722 | 1262 | struct capiminor *mp = tty->driver_data; |
2c8df722 | 1263 | |
1da177e4 LT |
1264 | #ifdef _DEBUG_TTYFUNCS |
1265 | printk(KERN_DEBUG "capinc_tty_start\n"); | |
1266 | #endif | |
2c8df722 | 1267 | mp->ttyoutstop = 0; |
eef0ced0 | 1268 | handle_minor_send(mp); |
1da177e4 LT |
1269 | } |
1270 | ||
1271 | static void capinc_tty_hangup(struct tty_struct *tty) | |
1272 | { | |
fb4b4881 JK |
1273 | struct capiminor *mp = tty->driver_data; |
1274 | ||
1da177e4 LT |
1275 | #ifdef _DEBUG_TTYFUNCS |
1276 | printk(KERN_DEBUG "capinc_tty_hangup\n"); | |
1277 | #endif | |
fb4b4881 | 1278 | tty_port_hangup(&mp->port); |
1da177e4 LT |
1279 | } |
1280 | ||
9e98966c | 1281 | static int capinc_tty_break_ctl(struct tty_struct *tty, int state) |
1da177e4 LT |
1282 | { |
1283 | #ifdef _DEBUG_TTYFUNCS | |
1284 | printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state); | |
1285 | #endif | |
9e98966c | 1286 | return 0; |
1da177e4 LT |
1287 | } |
1288 | ||
1289 | static void capinc_tty_flush_buffer(struct tty_struct *tty) | |
1290 | { | |
1291 | #ifdef _DEBUG_TTYFUNCS | |
1292 | printk(KERN_DEBUG "capinc_tty_flush_buffer\n"); | |
1293 | #endif | |
1294 | } | |
1295 | ||
1296 | static void capinc_tty_set_ldisc(struct tty_struct *tty) | |
1297 | { | |
1298 | #ifdef _DEBUG_TTYFUNCS | |
1299 | printk(KERN_DEBUG "capinc_tty_set_ldisc\n"); | |
1300 | #endif | |
1301 | } | |
1302 | ||
1303 | static void capinc_tty_send_xchar(struct tty_struct *tty, char ch) | |
1304 | { | |
1305 | #ifdef _DEBUG_TTYFUNCS | |
1306 | printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch); | |
1307 | #endif | |
1308 | } | |
1309 | ||
b68e31d0 | 1310 | static const struct tty_operations capinc_ops = { |
1da177e4 LT |
1311 | .open = capinc_tty_open, |
1312 | .close = capinc_tty_close, | |
1313 | .write = capinc_tty_write, | |
1314 | .put_char = capinc_tty_put_char, | |
1315 | .flush_chars = capinc_tty_flush_chars, | |
1316 | .write_room = capinc_tty_write_room, | |
1317 | .chars_in_buffer = capinc_tty_chars_in_buffer, | |
1318 | .ioctl = capinc_tty_ioctl, | |
1319 | .set_termios = capinc_tty_set_termios, | |
1320 | .throttle = capinc_tty_throttle, | |
1321 | .unthrottle = capinc_tty_unthrottle, | |
1322 | .stop = capinc_tty_stop, | |
1323 | .start = capinc_tty_start, | |
1324 | .hangup = capinc_tty_hangup, | |
1325 | .break_ctl = capinc_tty_break_ctl, | |
1326 | .flush_buffer = capinc_tty_flush_buffer, | |
1327 | .set_ldisc = capinc_tty_set_ldisc, | |
1328 | .send_xchar = capinc_tty_send_xchar, | |
46324511 JK |
1329 | .install = capinc_tty_install, |
1330 | .cleanup = capinc_tty_cleanup, | |
1da177e4 LT |
1331 | }; |
1332 | ||
e76b1544 | 1333 | static int __init capinc_tty_init(void) |
1da177e4 LT |
1334 | { |
1335 | struct tty_driver *drv; | |
e76b1544 JK |
1336 | int err; |
1337 | ||
1da177e4 LT |
1338 | if (capi_ttyminors > CAPINC_MAX_PORTS) |
1339 | capi_ttyminors = CAPINC_MAX_PORTS; | |
1340 | if (capi_ttyminors <= 0) | |
1341 | capi_ttyminors = CAPINC_NR_PORTS; | |
1342 | ||
81d17fe5 JK |
1343 | capiminors = kzalloc(sizeof(struct capi_minor *) * capi_ttyminors, |
1344 | GFP_KERNEL); | |
1345 | if (!capiminors) | |
1da177e4 LT |
1346 | return -ENOMEM; |
1347 | ||
81d17fe5 JK |
1348 | drv = alloc_tty_driver(capi_ttyminors); |
1349 | if (!drv) { | |
1350 | kfree(capiminors); | |
1351 | return -ENOMEM; | |
1352 | } | |
1da177e4 LT |
1353 | drv->owner = THIS_MODULE; |
1354 | drv->driver_name = "capi_nc"; | |
1da177e4 | 1355 | drv->name = "capi"; |
e95ac143 | 1356 | drv->major = 0; |
1da177e4 LT |
1357 | drv->minor_start = 0; |
1358 | drv->type = TTY_DRIVER_TYPE_SERIAL; | |
1359 | drv->subtype = SERIAL_TYPE_NORMAL; | |
1360 | drv->init_termios = tty_std_termios; | |
1361 | drv->init_termios.c_iflag = ICRNL; | |
1362 | drv->init_termios.c_oflag = OPOST | ONLCR; | |
1363 | drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | |
1364 | drv->init_termios.c_lflag = 0; | |
40fb2d0d JK |
1365 | drv->flags = |
1366 | TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS | | |
1367 | TTY_DRIVER_DYNAMIC_DEV; | |
1da177e4 | 1368 | tty_set_operations(drv, &capinc_ops); |
e76b1544 JK |
1369 | |
1370 | err = tty_register_driver(drv); | |
1371 | if (err) { | |
1da177e4 | 1372 | put_tty_driver(drv); |
81d17fe5 | 1373 | kfree(capiminors); |
1da177e4 | 1374 | printk(KERN_ERR "Couldn't register capi_nc driver\n"); |
e76b1544 | 1375 | return err; |
1da177e4 LT |
1376 | } |
1377 | capinc_tty_driver = drv; | |
1378 | return 0; | |
1379 | } | |
1380 | ||
e76b1544 | 1381 | static void __exit capinc_tty_exit(void) |
1da177e4 | 1382 | { |
e76b1544 JK |
1383 | tty_unregister_driver(capinc_tty_driver); |
1384 | put_tty_driver(capinc_tty_driver); | |
81d17fe5 | 1385 | kfree(capiminors); |
1da177e4 LT |
1386 | } |
1387 | ||
501c87a9 JK |
1388 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
1389 | ||
1390 | static inline int capinc_tty_init(void) | |
1391 | { | |
1392 | return 0; | |
1393 | } | |
1394 | ||
1395 | static inline void capinc_tty_exit(void) { } | |
1396 | ||
1397 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ | |
1da177e4 LT |
1398 | |
1399 | /* -------- /proc functions ----------------------------------------- */ | |
1400 | ||
1401 | /* | |
1402 | * /proc/capi/capi20: | |
1403 | * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt | |
1404 | */ | |
9a58a80a | 1405 | static int capi20_proc_show(struct seq_file *m, void *v) |
1da177e4 LT |
1406 | { |
1407 | struct capidev *cdev; | |
1408 | struct list_head *l; | |
1da177e4 | 1409 | |
b8f433dc | 1410 | mutex_lock(&capidev_list_lock); |
1da177e4 LT |
1411 | list_for_each(l, &capidev_list) { |
1412 | cdev = list_entry(l, struct capidev, list); | |
9a58a80a | 1413 | seq_printf(m, "0 %d %lu %lu %lu %lu\n", |
1da177e4 LT |
1414 | cdev->ap.applid, |
1415 | cdev->ap.nrecvctlpkt, | |
1416 | cdev->ap.nrecvdatapkt, | |
1417 | cdev->ap.nsentctlpkt, | |
1418 | cdev->ap.nsentdatapkt); | |
1da177e4 | 1419 | } |
b8f433dc | 1420 | mutex_unlock(&capidev_list_lock); |
9a58a80a | 1421 | return 0; |
1da177e4 LT |
1422 | } |
1423 | ||
9a58a80a AD |
1424 | static int capi20_proc_open(struct inode *inode, struct file *file) |
1425 | { | |
1426 | return single_open(file, capi20_proc_show, NULL); | |
1427 | } | |
1428 | ||
1429 | static const struct file_operations capi20_proc_fops = { | |
1430 | .owner = THIS_MODULE, | |
1431 | .open = capi20_proc_open, | |
1432 | .read = seq_read, | |
1433 | .llseek = seq_lseek, | |
1434 | .release = single_release, | |
1435 | }; | |
1436 | ||
1da177e4 LT |
1437 | /* |
1438 | * /proc/capi/capi20ncci: | |
1439 | * applid ncci | |
1440 | */ | |
9a58a80a | 1441 | static int capi20ncci_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1442 | { |
884f5c44 JK |
1443 | struct capidev *cdev; |
1444 | struct capincci *np; | |
1da177e4 | 1445 | |
b8f433dc | 1446 | mutex_lock(&capidev_list_lock); |
884f5c44 | 1447 | list_for_each_entry(cdev, &capidev_list, list) { |
05b41494 | 1448 | mutex_lock(&cdev->lock); |
884f5c44 JK |
1449 | list_for_each_entry(np, &cdev->nccis, list) |
1450 | seq_printf(m, "%d 0x%x\n", cdev->ap.applid, np->ncci); | |
05b41494 | 1451 | mutex_unlock(&cdev->lock); |
1da177e4 | 1452 | } |
b8f433dc | 1453 | mutex_unlock(&capidev_list_lock); |
9a58a80a | 1454 | return 0; |
1da177e4 LT |
1455 | } |
1456 | ||
9a58a80a AD |
1457 | static int capi20ncci_proc_open(struct inode *inode, struct file *file) |
1458 | { | |
1459 | return single_open(file, capi20ncci_proc_show, NULL); | |
1460 | } | |
1461 | ||
1462 | static const struct file_operations capi20ncci_proc_fops = { | |
1463 | .owner = THIS_MODULE, | |
1464 | .open = capi20ncci_proc_open, | |
1465 | .read = seq_read, | |
1466 | .llseek = seq_lseek, | |
1467 | .release = single_release, | |
1da177e4 LT |
1468 | }; |
1469 | ||
1470 | static void __init proc_init(void) | |
1471 | { | |
9a58a80a AD |
1472 | proc_create("capi/capi20", 0, NULL, &capi20_proc_fops); |
1473 | proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops); | |
1da177e4 LT |
1474 | } |
1475 | ||
1476 | static void __exit proc_exit(void) | |
1477 | { | |
9a58a80a AD |
1478 | remove_proc_entry("capi/capi20", NULL); |
1479 | remove_proc_entry("capi/capi20ncci", NULL); | |
1da177e4 LT |
1480 | } |
1481 | ||
1482 | /* -------- init function and module interface ---------------------- */ | |
1483 | ||
1484 | ||
1da177e4 LT |
1485 | static int __init capi_init(void) |
1486 | { | |
88549d6b | 1487 | const char *compileinfo; |
6d9eac34 | 1488 | int major_ret; |
1da177e4 | 1489 | |
6d9eac34 AM |
1490 | major_ret = register_chrdev(capi_major, "capi20", &capi_fops); |
1491 | if (major_ret < 0) { | |
1da177e4 | 1492 | printk(KERN_ERR "capi20: unable to get major %d\n", capi_major); |
6d9eac34 | 1493 | return major_ret; |
1da177e4 | 1494 | } |
56b22935 | 1495 | capi_class = class_create(THIS_MODULE, "capi"); |
1da177e4 LT |
1496 | if (IS_ERR(capi_class)) { |
1497 | unregister_chrdev(capi_major, "capi20"); | |
1498 | return PTR_ERR(capi_class); | |
1499 | } | |
1500 | ||
a9b12619 | 1501 | device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); |
1da177e4 | 1502 | |
1da177e4 | 1503 | if (capinc_tty_init() < 0) { |
d78b0368 | 1504 | device_destroy(capi_class, MKDEV(capi_major, 0)); |
56b22935 | 1505 | class_destroy(capi_class); |
1da177e4 LT |
1506 | unregister_chrdev(capi_major, "capi20"); |
1507 | return -ENOMEM; | |
1508 | } | |
1da177e4 LT |
1509 | |
1510 | proc_init(); | |
1511 | ||
1da177e4 LT |
1512 | #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) |
1513 | compileinfo = " (middleware+capifs)"; | |
501c87a9 | 1514 | #elif defined(CONFIG_ISDN_CAPI_MIDDLEWARE) |
1da177e4 | 1515 | compileinfo = " (no capifs)"; |
1da177e4 LT |
1516 | #else |
1517 | compileinfo = " (no middleware)"; | |
1518 | #endif | |
88549d6b JK |
1519 | printk(KERN_NOTICE "CAPI 2.0 started up with major %d%s\n", |
1520 | capi_major, compileinfo); | |
1da177e4 LT |
1521 | |
1522 | return 0; | |
1523 | } | |
1524 | ||
1525 | static void __exit capi_exit(void) | |
1526 | { | |
1527 | proc_exit(); | |
1528 | ||
d78b0368 | 1529 | device_destroy(capi_class, MKDEV(capi_major, 0)); |
56b22935 | 1530 | class_destroy(capi_class); |
1da177e4 | 1531 | unregister_chrdev(capi_major, "capi20"); |
1da177e4 | 1532 | |
1da177e4 | 1533 | capinc_tty_exit(); |
1da177e4 LT |
1534 | } |
1535 | ||
1536 | module_init(capi_init); | |
1537 | module_exit(capi_exit); |