1 /* $Id: isdn_common.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, common used functions (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/poll.h>
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/isdn.h>
20 #include <linux/mutex.h>
21 #include "isdn_common.h"
25 #ifdef CONFIG_ISDN_AUDIO
26 #include "isdn_audio.h"
28 #ifdef CONFIG_ISDN_DIVERSION_MODULE
29 #define CONFIG_ISDN_DIVERSION
31 #ifdef CONFIG_ISDN_DIVERSION
32 #include <linux/isdn_divertif.h>
33 #endif /* CONFIG_ISDN_DIVERSION */
34 #include "isdn_v110.h"
37 #undef ISDN_DEBUG_STATCALLB
39 MODULE_DESCRIPTION("ISDN4Linux: link layer");
40 MODULE_AUTHOR("Fritz Elfert");
41 MODULE_LICENSE("GPL");
45 static DEFINE_MUTEX(isdn_mutex
);
46 static char *isdn_revision
= "$Revision: 1.1.2.3 $";
48 extern char *isdn_net_revision
;
49 #ifdef CONFIG_ISDN_PPP
50 extern char *isdn_ppp_revision
;
52 static char *isdn_ppp_revision
= ": none $";
54 #ifdef CONFIG_ISDN_AUDIO
55 extern char *isdn_audio_revision
;
57 static char *isdn_audio_revision
= ": none $";
59 extern char *isdn_v110_revision
;
61 #ifdef CONFIG_ISDN_DIVERSION
62 static isdn_divert_if
*divert_if
; /* = NULL */
63 #endif /* CONFIG_ISDN_DIVERSION */
66 static int isdn_writebuf_stub(int, int, const u_char __user
*, int);
67 static void set_global_features(void);
68 static int isdn_wildmat(char *s
, char *p
);
69 static int isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
);
72 isdn_lock_driver(isdn_driver_t
*drv
)
74 try_module_get(drv
->interface
->owner
);
79 isdn_lock_drivers(void)
83 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
86 isdn_lock_driver(dev
->drv
[i
]);
91 isdn_unlock_driver(isdn_driver_t
*drv
)
95 module_put(drv
->interface
->owner
);
100 isdn_unlock_drivers(void)
104 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
107 isdn_unlock_driver(dev
->drv
[i
]);
111 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
113 isdn_dumppkt(char *s
, u_char
*p
, int len
, int dumplen
)
117 printk(KERN_DEBUG
"%s(%d) ", s
, len
);
118 for (dumpc
= 0; (dumpc
< dumplen
) && (len
); len
--, dumpc
++)
119 printk(" %02x", *p
++);
125 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
126 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
129 isdn_star(char *s
, char *p
)
131 while (isdn_wildmat(s
, p
)) {
139 * Shell-type Pattern-matching for incoming caller-Ids
140 * This function gets a string in s and checks, if it matches the pattern
146 * 2 = no match. Would eventually match, if s would be longer.
150 * '?' matches one character
151 * '*' matches zero or more characters
152 * [xyz] matches the set of characters in brackets.
153 * [^xyz] matches any single character not in the set of characters
157 isdn_wildmat(char *s
, char *p
)
160 register int matched
;
161 register int reverse
;
162 register int nostar
= 1;
169 /* Literal match with following character. */
174 return (*s
== '\0') ? 2 : 1;
177 /* Match anything. */
183 /* Trailing star matches everything. */
184 return (*++p
? isdn_star(s
, p
) : 0);
186 /* [^....] means inverse character class. */
187 if ((reverse
= (p
[1] == '^')))
189 for (last
= 0, matched
= 0; *++p
&& (*p
!= ']'); last
= *p
)
190 /* This next line requires a good C compiler. */
191 if (*p
== '-' ? *s
<= *++p
&& *s
>= last
: *s
== *p
)
193 if (matched
== reverse
)
197 return (*s
== '\0') ? 0 : nostar
;
200 int isdn_msncmp(const char *msn1
, const char *msn2
)
202 char TmpMsn1
[ISDN_MSNLEN
];
203 char TmpMsn2
[ISDN_MSNLEN
];
206 for (p
= TmpMsn1
; *msn1
&& *msn1
!= ':';) // Strip off a SPID
210 for (p
= TmpMsn2
; *msn2
&& *msn2
!= ':';) // Strip off a SPID
214 return isdn_wildmat(TmpMsn1
, TmpMsn2
);
218 isdn_dc2minor(int di
, int ch
)
221 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
222 if (dev
->chanmap
[i
] == ch
&& dev
->drvmap
[i
] == di
)
227 static int isdn_timer_cnt1
= 0;
228 static int isdn_timer_cnt2
= 0;
229 static int isdn_timer_cnt3
= 0;
232 isdn_timer_funct(struct timer_list
*unused
)
234 int tf
= dev
->tflags
;
235 if (tf
& ISDN_TIMER_FAST
) {
236 if (tf
& ISDN_TIMER_MODEMREAD
)
237 isdn_tty_readmodem();
238 if (tf
& ISDN_TIMER_MODEMPLUS
)
239 isdn_tty_modem_escape();
240 if (tf
& ISDN_TIMER_MODEMXMIT
)
241 isdn_tty_modem_xmit();
243 if (tf
& ISDN_TIMER_SLOW
) {
244 if (++isdn_timer_cnt1
>= ISDN_TIMER_02SEC
) {
246 if (tf
& ISDN_TIMER_NETDIAL
)
249 if (++isdn_timer_cnt2
>= ISDN_TIMER_1SEC
) {
251 if (tf
& ISDN_TIMER_NETHANGUP
)
253 if (++isdn_timer_cnt3
>= ISDN_TIMER_RINGING
) {
255 if (tf
& ISDN_TIMER_MODEMRING
)
256 isdn_tty_modem_ring();
258 if (tf
& ISDN_TIMER_CARRIER
)
259 isdn_tty_carrier_timeout();
263 mod_timer(&dev
->timer
, jiffies
+ ISDN_TIMER_RES
);
267 isdn_timer_ctrl(int tf
, int onoff
)
272 spin_lock_irqsave(&dev
->timerlock
, flags
);
273 if ((tf
& ISDN_TIMER_SLOW
) && (!(dev
->tflags
& ISDN_TIMER_SLOW
))) {
274 /* If the slow-timer wasn't activated until now */
278 old_tflags
= dev
->tflags
;
283 if (dev
->tflags
&& !old_tflags
)
284 mod_timer(&dev
->timer
, jiffies
+ ISDN_TIMER_RES
);
285 spin_unlock_irqrestore(&dev
->timerlock
, flags
);
289 * Receive a packet from B-Channel. (Called from low-level-module)
292 isdn_receive_skb_callback(int di
, int channel
, struct sk_buff
*skb
)
296 if ((i
= isdn_dc2minor(di
, channel
)) == -1) {
300 /* Update statistics */
301 dev
->ibytes
[i
] += skb
->len
;
303 /* First, try to deliver data to network-device */
304 if (isdn_net_rcv_skb(i
, skb
))
308 * makes sense for async streams only, so it is
309 * called after possible net-device delivery.
312 atomic_inc(&dev
->v110use
[i
]);
313 skb
= isdn_v110_decode(dev
->v110
[i
], skb
);
314 atomic_dec(&dev
->v110use
[i
]);
319 /* No network-device found, deliver to tty or raw-channel */
321 if (isdn_tty_rcv_skb(i
, di
, channel
, skb
))
323 wake_up_interruptible(&dev
->drv
[di
]->rcv_waitq
[channel
]);
329 * Intercept command from Linklevel to Lowlevel.
330 * If layer 2 protocol is V.110 and this is not supported by current
331 * lowlevel-driver, use driver's transparent mode and handle V.110 in
335 isdn_command(isdn_ctrl
*cmd
)
337 if (cmd
->driver
== -1) {
338 printk(KERN_WARNING
"isdn_command command(%x) driver -1\n", cmd
->command
);
341 if (!dev
->drv
[cmd
->driver
]) {
342 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d] NULL\n",
343 cmd
->command
, cmd
->driver
);
346 if (!dev
->drv
[cmd
->driver
]->interface
) {
347 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d]->interface NULL\n",
348 cmd
->command
, cmd
->driver
);
351 if (cmd
->command
== ISDN_CMD_SETL2
) {
352 int idx
= isdn_dc2minor(cmd
->driver
, cmd
->arg
& 255);
353 unsigned long l2prot
= (cmd
->arg
>> 8) & 255;
354 unsigned long features
= (dev
->drv
[cmd
->driver
]->interface
->features
355 >> ISDN_FEATURE_L2_SHIFT
) &
356 ISDN_FEATURE_L2_MASK
;
357 unsigned long l2_feature
= (1 << l2prot
);
360 case ISDN_PROTO_L2_V11096
:
361 case ISDN_PROTO_L2_V11019
:
362 case ISDN_PROTO_L2_V11038
:
363 /* If V.110 requested, but not supported by
364 * HL-driver, set emulator-flag and change
365 * Layer-2 to transparent
367 if (!(features
& l2_feature
)) {
368 dev
->v110emu
[idx
] = l2prot
;
369 cmd
->arg
= (cmd
->arg
& 255) |
370 (ISDN_PROTO_L2_TRANS
<< 8);
372 dev
->v110emu
[idx
] = 0;
375 return dev
->drv
[cmd
->driver
]->interface
->command(cmd
);
379 isdn_all_eaz(int di
, int ch
)
387 cmd
.command
= ISDN_CMD_SETEAZ
;
388 cmd
.parm
.num
[0] = '\0';
393 * Begin of a CAPI like LL<->HL interface, currently used only for
394 * supplementary service (CAPI 2.0 part III)
396 #include <linux/isdn/capicmd.h>
399 isdn_capi_rec_hl_msg(capi_msg
*cm
)
401 switch (cm
->Command
) {
403 /* in the moment only handled in tty */
404 return (isdn_tty_capi_facility(cm
));
411 isdn_status_callback(isdn_ctrl
*c
)
422 i
= isdn_dc2minor(di
, c
->arg
);
423 switch (c
->command
) {
424 case ISDN_STAT_BSENT
:
427 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
429 if (isdn_net_stat_callback(i
, c
))
431 if (isdn_v110_stat_callback(i
, c
))
433 if (isdn_tty_stat_callback(i
, c
))
435 wake_up_interruptible(&dev
->drv
[di
]->snd_waitq
[c
->arg
]);
437 case ISDN_STAT_STAVAIL
:
438 dev
->drv
[di
]->stavail
+= c
->arg
;
439 wake_up_interruptible(&dev
->drv
[di
]->st_waitq
);
442 dev
->drv
[di
]->flags
|= DRV_FLAG_RUNNING
;
443 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
444 if (dev
->drvmap
[i
] == di
)
445 isdn_all_eaz(di
, dev
->chanmap
[i
]);
446 set_global_features();
449 dev
->drv
[di
]->flags
&= ~DRV_FLAG_RUNNING
;
451 case ISDN_STAT_ICALL
:
454 #ifdef ISDN_DEBUG_STATCALLB
455 printk(KERN_DEBUG
"ICALL (net): %d %ld %s\n", di
, c
->arg
, c
->parm
.num
);
457 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) {
460 cmd
.command
= ISDN_CMD_HANGUP
;
464 /* Try to find a network-interface which will accept incoming call */
465 r
= ((c
->command
== ISDN_STAT_ICALLW
) ? 0 : isdn_net_find_icall(di
, c
->arg
, i
, &c
->parm
.setup
));
468 /* No network-device replies.
470 * These return 0 on no match, 1 on match and
471 * 3 on eventually match, if CID is longer.
473 if (c
->command
== ISDN_STAT_ICALL
)
474 if ((retval
= isdn_tty_find_icall(di
, c
->arg
, &c
->parm
.setup
))) return (retval
);
475 #ifdef CONFIG_ISDN_DIVERSION
477 if ((retval
= divert_if
->stat_callback(c
)))
478 return (retval
); /* processed */
479 #endif /* CONFIG_ISDN_DIVERSION */
480 if ((!retval
) && (dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
)) {
481 /* No tty responding */
484 cmd
.command
= ISDN_CMD_HANGUP
;
490 /* Schedule connection-setup */
494 cmd
.command
= ISDN_CMD_ACCEPTD
;
495 for (p
= dev
->netdev
; p
; p
= p
->next
)
496 if (p
->local
->isdn_channel
== cmd
.arg
)
498 strcpy(cmd
.parm
.setup
.eazmsn
, p
->local
->msn
);
505 case 2: /* For calling back, first reject incoming call ... */
506 case 3: /* Interface found, but down, reject call actively */
508 printk(KERN_INFO
"isdn: Rejecting Call\n");
511 cmd
.command
= ISDN_CMD_HANGUP
;
517 /* ... then start callback. */
521 /* Number would eventually match, if longer */
525 #ifdef ISDN_DEBUG_STATCALLB
526 printk(KERN_DEBUG
"ICALL: ret=%d\n", retval
);
533 #ifdef ISDN_DEBUG_STATCALLB
534 printk(KERN_DEBUG
"CINF: %ld %s\n", c
->arg
, c
->parm
.num
);
536 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
538 if (strcmp(c
->parm
.num
, "0"))
539 isdn_net_stat_callback(i
, c
);
540 isdn_tty_stat_callback(i
, c
);
542 case ISDN_STAT_CAUSE
:
543 #ifdef ISDN_DEBUG_STATCALLB
544 printk(KERN_DEBUG
"CAUSE: %ld %s\n", c
->arg
, c
->parm
.num
);
546 printk(KERN_INFO
"isdn: %s,ch%ld cause: %s\n",
547 dev
->drvid
[di
], c
->arg
, c
->parm
.num
);
548 isdn_tty_stat_callback(i
, c
);
549 #ifdef CONFIG_ISDN_DIVERSION
551 divert_if
->stat_callback(c
);
552 #endif /* CONFIG_ISDN_DIVERSION */
554 case ISDN_STAT_DISPLAY
:
555 #ifdef ISDN_DEBUG_STATCALLB
556 printk(KERN_DEBUG
"DISPLAY: %ld %s\n", c
->arg
, c
->parm
.display
);
558 isdn_tty_stat_callback(i
, c
);
559 #ifdef CONFIG_ISDN_DIVERSION
561 divert_if
->stat_callback(c
);
562 #endif /* CONFIG_ISDN_DIVERSION */
564 case ISDN_STAT_DCONN
:
567 #ifdef ISDN_DEBUG_STATCALLB
568 printk(KERN_DEBUG
"DCONN: %ld\n", c
->arg
);
570 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
572 /* Find any net-device, waiting for D-channel setup */
573 if (isdn_net_stat_callback(i
, c
))
575 isdn_v110_stat_callback(i
, c
);
576 /* Find any ttyI, waiting for D-channel setup */
577 if (isdn_tty_stat_callback(i
, c
)) {
580 cmd
.command
= ISDN_CMD_ACCEPTB
;
588 #ifdef ISDN_DEBUG_STATCALLB
589 printk(KERN_DEBUG
"DHUP: %ld\n", c
->arg
);
591 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
593 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
595 /* Signal hangup to network-devices */
596 if (isdn_net_stat_callback(i
, c
))
598 isdn_v110_stat_callback(i
, c
);
599 if (isdn_tty_stat_callback(i
, c
))
601 #ifdef CONFIG_ISDN_DIVERSION
603 divert_if
->stat_callback(c
);
604 #endif /* CONFIG_ISDN_DIVERSION */
607 case ISDN_STAT_BCONN
:
610 #ifdef ISDN_DEBUG_STATCALLB
611 printk(KERN_DEBUG
"BCONN: %ld\n", c
->arg
);
613 /* Signal B-channel-connect to network-devices */
614 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
616 dev
->drv
[di
]->online
|= (1 << (c
->arg
));
618 if (isdn_net_stat_callback(i
, c
))
620 isdn_v110_stat_callback(i
, c
);
621 if (isdn_tty_stat_callback(i
, c
))
627 #ifdef ISDN_DEBUG_STATCALLB
628 printk(KERN_DEBUG
"BHUP: %ld\n", c
->arg
);
630 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
632 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
634 #ifdef CONFIG_ISDN_X25
635 /* Signal hangup to network-devices */
636 if (isdn_net_stat_callback(i
, c
))
639 isdn_v110_stat_callback(i
, c
);
640 if (isdn_tty_stat_callback(i
, c
))
643 case ISDN_STAT_NODCH
:
646 #ifdef ISDN_DEBUG_STATCALLB
647 printk(KERN_DEBUG
"NODCH: %ld\n", c
->arg
);
649 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
651 if (isdn_net_stat_callback(i
, c
))
653 if (isdn_tty_stat_callback(i
, c
))
656 case ISDN_STAT_ADDCH
:
657 spin_lock_irqsave(&dev
->lock
, flags
);
658 if (isdn_add_channels(dev
->drv
[di
], di
, c
->arg
, 1)) {
659 spin_unlock_irqrestore(&dev
->lock
, flags
);
662 spin_unlock_irqrestore(&dev
->lock
, flags
);
665 case ISDN_STAT_DISCH
:
666 spin_lock_irqsave(&dev
->lock
, flags
);
667 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
668 if ((dev
->drvmap
[i
] == di
) &&
669 (dev
->chanmap
[i
] == c
->arg
)) {
671 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
673 if (USG_NONE(dev
->usage
[i
])) {
674 dev
->usage
[i
] |= ISDN_USAGE_DISABLED
;
680 spin_unlock_irqrestore(&dev
->lock
, flags
);
683 case ISDN_STAT_UNLOAD
:
684 while (dev
->drv
[di
]->locks
> 0) {
685 isdn_unlock_driver(dev
->drv
[di
]);
687 spin_lock_irqsave(&dev
->lock
, flags
);
688 isdn_tty_stat_callback(i
, c
);
689 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
690 if (dev
->drvmap
[i
] == di
) {
692 dev
->chanmap
[i
] = -1;
693 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
696 dev
->channels
-= dev
->drv
[di
]->channels
;
697 kfree(dev
->drv
[di
]->rcverr
);
698 kfree(dev
->drv
[di
]->rcvcount
);
699 for (i
= 0; i
< dev
->drv
[di
]->channels
; i
++)
700 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[i
]);
701 kfree(dev
->drv
[di
]->rpqueue
);
702 kfree(dev
->drv
[di
]->rcv_waitq
);
705 dev
->drvid
[di
][0] = '\0';
707 set_global_features();
708 spin_unlock_irqrestore(&dev
->lock
, flags
);
710 case ISDN_STAT_L1ERR
:
712 case CAPI_PUT_MESSAGE
:
713 return (isdn_capi_rec_hl_msg(&c
->parm
.cmsg
));
714 #ifdef CONFIG_ISDN_TTY_FAX
715 case ISDN_STAT_FAXIND
:
716 isdn_tty_stat_callback(i
, c
);
719 #ifdef CONFIG_ISDN_AUDIO
720 case ISDN_STAT_AUDIO
:
721 isdn_tty_stat_callback(i
, c
);
724 #ifdef CONFIG_ISDN_DIVERSION
726 case ISDN_STAT_REDIR
:
728 return (divert_if
->stat_callback(c
));
729 #endif /* CONFIG_ISDN_DIVERSION */
738 * Get integer from char-pointer, set pointer to end of number
741 isdn_getnum(char **p
)
745 while (*p
[0] >= '0' && *p
[0] <= '9')
746 v
= ((v
< 0) ? 0 : (v
* 10)) + (int) ((*p
[0]++) - '0');
753 * isdn_readbchan() tries to get data from the read-queue.
754 * It MUST be called with interrupts off.
756 * Be aware that this is not an atomic operation when sleep != 0, even though
757 * interrupts are turned off! Well, like that we are currently only called
758 * on behalf of a read system call on raw device files (which are documented
759 * to be dangerous and for debugging purpose only). The inode semaphore
760 * takes care that this is not called for the same minor device number while
761 * we are sleeping, but access is not serialized against simultaneous read()
762 * from the corresponding ttyI device. Can other ugly events, like changes
763 * of the mapping (di,ch)<->minor, happen during the sleep? --he
766 isdn_readbchan(int di
, int channel
, u_char
*buf
, u_char
*fp
, int len
, wait_queue_head_t
*sleep
)
777 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
])) {
779 wait_event_interruptible(*sleep
,
780 !skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]));
784 if (len
> dev
->drv
[di
]->rcvcount
[channel
])
785 len
= dev
->drv
[di
]->rcvcount
[channel
];
789 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
791 #ifdef CONFIG_ISDN_AUDIO
792 if (ISDN_AUDIO_SKB_LOCK(skb
))
794 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
795 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
797 unsigned long DLEmask
= (1 << channel
);
800 count_pull
= count_put
= 0;
801 while ((count_pull
< skb
->len
) && (len
> 0)) {
803 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
805 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
809 dev
->drv
[di
]->DLEflag
|= DLEmask
;
810 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
817 if (count_pull
>= skb
->len
)
821 /* No DLE's in buff, so simply copy it */
823 if ((count_pull
= skb
->len
) > len
) {
827 count_put
= count_pull
;
828 skb_copy_from_linear_data(skb
, cp
, count_put
);
831 #ifdef CONFIG_ISDN_AUDIO
836 memset(fp
, 0, count_put
);
840 /* We got all the data in this buff.
841 * Now we can dequeue it.
845 #ifdef CONFIG_ISDN_AUDIO
846 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
848 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
851 /* Not yet emptied this buff, so it
852 * must stay in the queue, for further calls
853 * but we pull off the data we got until now.
855 skb_pull(skb
, count_pull
);
856 #ifdef CONFIG_ISDN_AUDIO
857 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
860 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
866 * isdn_readbchan_tty() tries to get data from the read-queue.
867 * It MUST be called with interrupts off.
869 * Be aware that this is not an atomic operation when sleep != 0, even though
870 * interrupts are turned off! Well, like that we are currently only called
871 * on behalf of a read system call on raw device files (which are documented
872 * to be dangerous and for debugging purpose only). The inode semaphore
873 * takes care that this is not called for the same minor device number while
874 * we are sleeping, but access is not serialized against simultaneous read()
875 * from the corresponding ttyI device. Can other ugly events, like changes
876 * of the mapping (di,ch)<->minor, happen during the sleep? --he
879 isdn_readbchan_tty(int di
, int channel
, struct tty_port
*port
, int cisco_hack
)
891 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
894 len
= tty_buffer_request_room(port
, dev
->drv
[di
]->rcvcount
[channel
]);
900 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
902 #ifdef CONFIG_ISDN_AUDIO
903 if (ISDN_AUDIO_SKB_LOCK(skb
))
905 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
906 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
908 unsigned long DLEmask
= (1 << channel
);
911 count_pull
= count_put
= 0;
912 while ((count_pull
< skb
->len
) && (len
> 0)) {
913 /* push every character but the last to the tty buffer directly */
915 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
917 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
919 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
923 dev
->drv
[di
]->DLEflag
|= DLEmask
;
924 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
931 if (count_pull
>= skb
->len
)
935 /* No DLE's in buff, so simply copy it */
937 if ((count_pull
= skb
->len
) > len
) {
941 count_put
= count_pull
;
943 tty_insert_flip_string(port
, skb
->data
, count_put
- 1);
944 last
= skb
->data
[count_put
- 1];
946 #ifdef CONFIG_ISDN_AUDIO
951 /* We got all the data in this buff.
952 * Now we can dequeue it.
955 tty_insert_flip_char(port
, last
, 0xFF);
957 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
958 #ifdef CONFIG_ISDN_AUDIO
959 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
961 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
964 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
965 /* Not yet emptied this buff, so it
966 * must stay in the queue, for further calls
967 * but we pull off the data we got until now.
969 skb_pull(skb
, count_pull
);
970 #ifdef CONFIG_ISDN_AUDIO
971 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
974 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
981 isdn_minor2drv(int minor
)
983 return (dev
->drvmap
[minor
]);
987 isdn_minor2chan(int minor
)
989 return (dev
->chanmap
[minor
]);
995 static char istatbuf
[2048];
999 sprintf(istatbuf
, "idmap:\t");
1000 p
= istatbuf
+ strlen(istatbuf
);
1001 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1002 sprintf(p
, "%s ", (dev
->drvmap
[i
] < 0) ? "-" : dev
->drvid
[dev
->drvmap
[i
]]);
1003 p
= istatbuf
+ strlen(istatbuf
);
1005 sprintf(p
, "\nchmap:\t");
1006 p
= istatbuf
+ strlen(istatbuf
);
1007 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1008 sprintf(p
, "%d ", dev
->chanmap
[i
]);
1009 p
= istatbuf
+ strlen(istatbuf
);
1011 sprintf(p
, "\ndrmap:\t");
1012 p
= istatbuf
+ strlen(istatbuf
);
1013 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1014 sprintf(p
, "%d ", dev
->drvmap
[i
]);
1015 p
= istatbuf
+ strlen(istatbuf
);
1017 sprintf(p
, "\nusage:\t");
1018 p
= istatbuf
+ strlen(istatbuf
);
1019 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1020 sprintf(p
, "%d ", dev
->usage
[i
]);
1021 p
= istatbuf
+ strlen(istatbuf
);
1023 sprintf(p
, "\nflags:\t");
1024 p
= istatbuf
+ strlen(istatbuf
);
1025 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
1027 sprintf(p
, "%ld ", dev
->drv
[i
]->online
);
1028 p
= istatbuf
+ strlen(istatbuf
);
1031 p
= istatbuf
+ strlen(istatbuf
);
1034 sprintf(p
, "\nphone:\t");
1035 p
= istatbuf
+ strlen(istatbuf
);
1036 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1037 sprintf(p
, "%s ", dev
->num
[i
]);
1038 p
= istatbuf
+ strlen(istatbuf
);
1044 /* Module interface-code */
1047 isdn_info_update(void)
1049 infostruct
*p
= dev
->infochain
;
1053 p
= (infostruct
*) p
->next
;
1055 wake_up_interruptible(&(dev
->info_waitq
));
1059 isdn_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*off
)
1061 uint minor
= iminor(file_inode(file
));
1068 mutex_lock(&isdn_mutex
);
1069 if (minor
== ISDN_MINOR_STATUS
) {
1070 if (!file
->private_data
) {
1071 if (file
->f_flags
& O_NONBLOCK
) {
1075 wait_event_interruptible(dev
->info_waitq
,
1076 file
->private_data
);
1079 file
->private_data
= NULL
;
1080 if ((len
= strlen(p
)) <= count
) {
1081 if (copy_to_user(buf
, p
, len
)) {
1092 if (!dev
->drivers
) {
1096 if (minor
<= ISDN_MINOR_BMAX
) {
1097 printk(KERN_WARNING
"isdn_read minor %d obsolete!\n", minor
);
1098 drvidx
= isdn_minor2drv(minor
);
1103 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1107 chidx
= isdn_minor2chan(minor
);
1108 if (!(p
= kmalloc(count
, GFP_KERNEL
))) {
1112 len
= isdn_readbchan(drvidx
, chidx
, p
, NULL
, count
,
1113 &dev
->drv
[drvidx
]->rcv_waitq
[chidx
]);
1115 if (copy_to_user(buf
, p
, len
))
1121 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1122 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1127 if (!dev
->drv
[drvidx
]->stavail
) {
1128 if (file
->f_flags
& O_NONBLOCK
) {
1132 wait_event_interruptible(dev
->drv
[drvidx
]->st_waitq
,
1133 dev
->drv
[drvidx
]->stavail
);
1135 if (dev
->drv
[drvidx
]->interface
->readstat
) {
1136 if (count
> dev
->drv
[drvidx
]->stavail
)
1137 count
= dev
->drv
[drvidx
]->stavail
;
1138 len
= dev
->drv
[drvidx
]->interface
->readstat(buf
, count
,
1139 drvidx
, isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1148 dev
->drv
[drvidx
]->stavail
-= len
;
1150 dev
->drv
[drvidx
]->stavail
= 0;
1155 #ifdef CONFIG_ISDN_PPP
1156 if (minor
<= ISDN_MINOR_PPPMAX
) {
1157 retval
= isdn_ppp_read(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1163 mutex_unlock(&isdn_mutex
);
1168 isdn_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*off
)
1170 uint minor
= iminor(file_inode(file
));
1175 if (minor
== ISDN_MINOR_STATUS
)
1180 mutex_lock(&isdn_mutex
);
1181 if (minor
<= ISDN_MINOR_BMAX
) {
1182 printk(KERN_WARNING
"isdn_write minor %d obsolete!\n", minor
);
1183 drvidx
= isdn_minor2drv(minor
);
1188 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1192 chidx
= isdn_minor2chan(minor
);
1193 wait_event_interruptible(dev
->drv
[drvidx
]->snd_waitq
[chidx
],
1194 (retval
= isdn_writebuf_stub(drvidx
, chidx
, buf
, count
)));
1197 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1198 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1204 * We want to use the isdnctrl device to load the firmware
1206 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1209 if (dev
->drv
[drvidx
]->interface
->writecmd
)
1210 retval
= dev
->drv
[drvidx
]->interface
->
1211 writecmd(buf
, count
, drvidx
,
1212 isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1217 #ifdef CONFIG_ISDN_PPP
1218 if (minor
<= ISDN_MINOR_PPPMAX
) {
1219 retval
= isdn_ppp_write(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1225 mutex_unlock(&isdn_mutex
);
1230 isdn_poll(struct file
*file
, poll_table
*wait
)
1233 unsigned int minor
= iminor(file_inode(file
));
1234 int drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1236 mutex_lock(&isdn_mutex
);
1237 if (minor
== ISDN_MINOR_STATUS
) {
1238 poll_wait(file
, &(dev
->info_waitq
), wait
);
1239 /* mask = EPOLLOUT | EPOLLWRNORM; */
1240 if (file
->private_data
) {
1241 mask
|= EPOLLIN
| EPOLLRDNORM
;
1245 if (minor
>= ISDN_MINOR_CTRL
&& minor
<= ISDN_MINOR_CTRLMAX
) {
1247 /* driver deregistered while file open */
1251 poll_wait(file
, &(dev
->drv
[drvidx
]->st_waitq
), wait
);
1252 mask
= EPOLLOUT
| EPOLLWRNORM
;
1253 if (dev
->drv
[drvidx
]->stavail
) {
1254 mask
|= EPOLLIN
| EPOLLRDNORM
;
1258 #ifdef CONFIG_ISDN_PPP
1259 if (minor
<= ISDN_MINOR_PPPMAX
) {
1260 mask
= isdn_ppp_poll(file
, wait
);
1266 mutex_unlock(&isdn_mutex
);
1272 isdn_ioctl(struct file
*file
, uint cmd
, ulong arg
)
1274 uint minor
= iminor(file_inode(file
));
1284 isdn_ioctl_struct iocts
;
1285 isdn_net_ioctl_phone phone
;
1286 isdn_net_ioctl_cfg cfg
;
1288 void __user
*argp
= (void __user
*)arg
;
1290 #define name iocpar.name
1291 #define bname iocpar.bname
1292 #define iocts iocpar.iocts
1293 #define phone iocpar.phone
1294 #define cfg iocpar.cfg
1296 if (minor
== ISDN_MINOR_STATUS
) {
1304 ulong __user
*p
= argp
;
1306 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1307 put_user(dev
->ibytes
[i
], p
++);
1308 put_user(dev
->obytes
[i
], p
++);
1315 /* Get peer phone number of a connected
1316 * isdn network interface */
1318 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1320 return isdn_net_getpeer(&phone
, argp
);
1329 if (minor
<= ISDN_MINOR_BMAX
) {
1330 drvidx
= isdn_minor2drv(minor
);
1333 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1337 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1339 * isdn net devices manage lots of configuration variables as linked lists.
1340 * Those lists must only be manipulated from user space. Some of the ioctl's
1341 * service routines access user space and are not atomic. Therefore, ioctl's
1342 * manipulating the lists and ioctl's sleeping while accessing the lists
1343 * are serialized by means of a semaphore.
1347 printk(KERN_INFO
"INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1350 printk(KERN_INFO
"INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1353 /* Add a network-interface */
1355 if (copy_from_user(name
, argp
, sizeof(name
)))
1361 ret
= mutex_lock_interruptible(&dev
->mtx
);
1362 if (ret
) return ret
;
1363 if ((s
= isdn_net_new(s
, NULL
))) {
1364 if (copy_to_user(argp
, s
, strlen(s
) + 1)) {
1371 mutex_unlock(&dev
->mtx
);
1374 /* Add a slave to a network-interface */
1376 if (copy_from_user(bname
, argp
, sizeof(bname
) - 1))
1378 bname
[sizeof(bname
)-1] = 0;
1381 ret
= mutex_lock_interruptible(&dev
->mtx
);
1382 if (ret
) return ret
;
1383 if ((s
= isdn_net_newslave(bname
))) {
1384 if (copy_to_user(argp
, s
, strlen(s
) + 1)) {
1391 mutex_unlock(&dev
->mtx
);
1394 /* Delete a network-interface */
1396 if (copy_from_user(name
, argp
, sizeof(name
)))
1398 ret
= mutex_lock_interruptible(&dev
->mtx
);
1399 if (ret
) return ret
;
1400 ret
= isdn_net_rm(name
);
1401 mutex_unlock(&dev
->mtx
);
1406 /* Set configurable parameters of a network-interface */
1408 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1410 return isdn_net_setcfg(&cfg
);
1414 /* Get configurable parameters of a network-interface */
1416 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1418 if (!(ret
= isdn_net_getcfg(&cfg
))) {
1419 if (copy_to_user(argp
, &cfg
, sizeof(cfg
)))
1426 /* Add a phone-number to a network-interface */
1428 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1430 ret
= mutex_lock_interruptible(&dev
->mtx
);
1431 if (ret
) return ret
;
1432 ret
= isdn_net_addphone(&phone
);
1433 mutex_unlock(&dev
->mtx
);
1438 /* Get list of phone-numbers of a network-interface */
1440 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1442 ret
= mutex_lock_interruptible(&dev
->mtx
);
1443 if (ret
) return ret
;
1444 ret
= isdn_net_getphones(&phone
, argp
);
1445 mutex_unlock(&dev
->mtx
);
1450 /* Delete a phone-number of a network-interface */
1452 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1454 ret
= mutex_lock_interruptible(&dev
->mtx
);
1455 if (ret
) return ret
;
1456 ret
= isdn_net_delphone(&phone
);
1457 mutex_unlock(&dev
->mtx
);
1462 /* Force dialing of a network-interface */
1464 if (copy_from_user(name
, argp
, sizeof(name
)))
1466 return isdn_net_force_dial(name
);
1469 #ifdef CONFIG_ISDN_PPP
1473 if (copy_from_user(name
, argp
, sizeof(name
)))
1475 return isdn_ppp_dial_slave(name
);
1479 if (copy_from_user(name
, argp
, sizeof(name
)))
1481 return isdn_ppp_hangup_slave(name
);
1484 /* Force hangup of a network-interface */
1487 if (copy_from_user(name
, argp
, sizeof(name
)))
1489 return isdn_net_force_hangup(name
);
1492 dev
->net_verbose
= arg
;
1493 printk(KERN_INFO
"isdn: Verbose-Level is %d\n", dev
->net_verbose
);
1497 dev
->global_flags
|= ISDN_GLOBAL_STOPPED
;
1499 dev
->global_flags
&= ~ISDN_GLOBAL_STOPPED
;
1500 printk(KERN_INFO
"isdn: Global Mode %s\n",
1501 (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) ? "stopped" : "running");
1508 if (copy_from_user(&iocts
, argp
,
1509 sizeof(isdn_ioctl_struct
)))
1511 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1512 if (strlen(iocts
.drvid
)) {
1513 if ((p
= strchr(iocts
.drvid
, ',')))
1516 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1517 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1526 dev
->drv
[drvidx
]->flags
|= DRV_FLAG_REJBUS
;
1528 dev
->drv
[drvidx
]->flags
&= ~DRV_FLAG_REJBUS
;
1531 dev
->profd
= current
;
1535 /* Get all Modem-Profiles */
1537 char __user
*p
= argp
;
1540 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1541 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.profile
,
1544 p
+= ISDN_MODEM_NUMREG
;
1545 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.pmsn
, ISDN_MSNLEN
))
1548 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.plmsn
, ISDN_LMSNLEN
))
1552 return (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
) * ISDN_MAX_CHANNELS
;
1557 /* Set all Modem-Profiles */
1559 char __user
*p
= argp
;
1562 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1563 if (copy_from_user(dev
->mdm
.info
[i
].emu
.profile
, p
,
1566 p
+= ISDN_MODEM_NUMREG
;
1567 if (copy_from_user(dev
->mdm
.info
[i
].emu
.plmsn
, p
, ISDN_LMSNLEN
))
1570 if (copy_from_user(dev
->mdm
.info
[i
].emu
.pmsn
, p
, ISDN_MSNLEN
))
1580 /* Set/Get MSN->EAZ-Mapping for a driver */
1583 if (copy_from_user(&iocts
, argp
,
1584 sizeof(isdn_ioctl_struct
)))
1586 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1587 if (strlen(iocts
.drvid
)) {
1589 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1590 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1598 if (cmd
== IIOCSETMAP
) {
1601 p
= (char __user
*) iocts
.arg
;
1607 get_user(bname
[j
], p
++);
1614 strcpy(dev
->drv
[drvidx
]->msn2eaz
[i
], bname
);
1620 if (j
>= ISDN_MSNLEN
)
1627 p
= (char __user
*) iocts
.arg
;
1628 for (i
= 0; i
< 10; i
++) {
1629 snprintf(bname
, sizeof(bname
), "%s%s",
1630 strlen(dev
->drv
[drvidx
]->msn2eaz
[i
]) ?
1631 dev
->drv
[drvidx
]->msn2eaz
[i
] : "_",
1632 (i
< 9) ? "," : "\0");
1633 if (copy_to_user(p
, bname
, strlen(bname
) + 1))
1644 if ((cmd
& IIOCDRVCTL
) == IIOCDRVCTL
)
1645 cmd
= ((cmd
>> _IOC_NRSHIFT
) & _IOC_NRMASK
) & ISDN_DRVIOCTL_MASK
;
1651 if (copy_from_user(&iocts
, argp
, sizeof(isdn_ioctl_struct
)))
1653 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1654 if (strlen(iocts
.drvid
)) {
1655 if ((p
= strchr(iocts
.drvid
, ',')))
1658 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1659 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1668 c
.command
= ISDN_CMD_IOCTL
;
1670 memcpy(c
.parm
.num
, &iocts
.arg
, sizeof(ulong
));
1671 ret
= isdn_command(&c
);
1672 memcpy(&iocts
.arg
, c
.parm
.num
, sizeof(ulong
));
1673 if (copy_to_user(argp
, &iocts
, sizeof(isdn_ioctl_struct
)))
1680 #ifdef CONFIG_ISDN_PPP
1681 if (minor
<= ISDN_MINOR_PPPMAX
)
1682 return (isdn_ppp_ioctl(minor
- ISDN_MINOR_PPP
, file
, cmd
, arg
));
1694 isdn_unlocked_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1698 mutex_lock(&isdn_mutex
);
1699 ret
= isdn_ioctl(file
, cmd
, arg
);
1700 mutex_unlock(&isdn_mutex
);
1706 * Open the device code.
1709 isdn_open(struct inode
*ino
, struct file
*filep
)
1711 uint minor
= iminor(ino
);
1714 int retval
= -ENODEV
;
1716 mutex_lock(&isdn_mutex
);
1717 if (minor
== ISDN_MINOR_STATUS
) {
1720 if ((p
= kmalloc(sizeof(infostruct
), GFP_KERNEL
))) {
1721 p
->next
= (char *) dev
->infochain
;
1722 p
->private = (char *) &(filep
->private_data
);
1724 /* At opening we allow a single update */
1725 filep
->private_data
= (char *) 1;
1735 if (minor
<= ISDN_MINOR_BMAX
) {
1736 printk(KERN_WARNING
"isdn_open minor %d obsolete!\n", minor
);
1737 drvidx
= isdn_minor2drv(minor
);
1740 chidx
= isdn_minor2chan(minor
);
1741 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1743 if (!(dev
->drv
[drvidx
]->online
& (1 << chidx
)))
1745 isdn_lock_drivers();
1749 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1750 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1753 isdn_lock_drivers();
1757 #ifdef CONFIG_ISDN_PPP
1758 if (minor
<= ISDN_MINOR_PPPMAX
) {
1759 retval
= isdn_ppp_open(minor
- ISDN_MINOR_PPP
, filep
);
1761 isdn_lock_drivers();
1766 nonseekable_open(ino
, filep
);
1767 mutex_unlock(&isdn_mutex
);
1772 isdn_close(struct inode
*ino
, struct file
*filep
)
1774 uint minor
= iminor(ino
);
1776 mutex_lock(&isdn_mutex
);
1777 if (minor
== ISDN_MINOR_STATUS
) {
1778 infostruct
*p
= dev
->infochain
;
1779 infostruct
*q
= NULL
;
1782 if (p
->private == (char *) &(filep
->private_data
)) {
1786 dev
->infochain
= (infostruct
*) (p
->next
);
1791 p
= (infostruct
*) (p
->next
);
1793 printk(KERN_WARNING
"isdn: No private data while closing isdnctrl\n");
1796 isdn_unlock_drivers();
1797 if (minor
<= ISDN_MINOR_BMAX
)
1799 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1800 if (dev
->profd
== current
)
1804 #ifdef CONFIG_ISDN_PPP
1805 if (minor
<= ISDN_MINOR_PPPMAX
)
1806 isdn_ppp_release(minor
- ISDN_MINOR_PPP
, filep
);
1810 mutex_unlock(&isdn_mutex
);
1814 static const struct file_operations isdn_fops
=
1816 .owner
= THIS_MODULE
,
1817 .llseek
= no_llseek
,
1819 .write
= isdn_write
,
1821 .unlocked_ioctl
= isdn_unlocked_ioctl
,
1823 .release
= isdn_close
,
1827 isdn_map_eaz2msn(char *msn
, int di
)
1829 isdn_driver_t
*this = dev
->drv
[di
];
1832 if (strlen(msn
) == 1) {
1834 if ((i
>= 0) && (i
<= 9))
1835 if (strlen(this->msn2eaz
[i
]))
1836 return (this->msn2eaz
[i
]);
1842 * Find an unused ISDN-channel, whose feature-flags match the
1843 * given L2- and L3-protocols.
1845 #define L2V (~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038))
1848 * This function must be called with holding the dev->lock.
1851 isdn_get_free_channel(int usage
, int l2_proto
, int l3_proto
, int pre_dev
1852 , int pre_chan
, char *msn
)
1858 features
= ((1 << l2_proto
) | (0x10000 << l3_proto
));
1859 vfeatures
= (((1 << l2_proto
) | (0x10000 << l3_proto
)) &
1860 ~(ISDN_FEATURE_L2_V11096
| ISDN_FEATURE_L2_V11019
| ISDN_FEATURE_L2_V11038
));
1861 /* If Layer-2 protocol is V.110, accept drivers with
1862 * transparent feature even if these don't support V.110
1863 * because we can emulate this in linklevel.
1865 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1866 if (USG_NONE(dev
->usage
[i
]) &&
1867 (dev
->drvmap
[i
] != -1)) {
1868 int d
= dev
->drvmap
[i
];
1869 if ((dev
->usage
[i
] & ISDN_USAGE_EXCLUSIVE
) &&
1870 ((pre_dev
!= d
) || (pre_chan
!= dev
->chanmap
[i
])))
1872 if (!strcmp(isdn_map_eaz2msn(msn
, d
), "-"))
1874 if (dev
->usage
[i
] & ISDN_USAGE_DISABLED
)
1875 continue; /* usage not allowed */
1876 if (dev
->drv
[d
]->flags
& DRV_FLAG_RUNNING
) {
1877 if (((dev
->drv
[d
]->interface
->features
& features
) == features
) ||
1878 (((dev
->drv
[d
]->interface
->features
& vfeatures
) == vfeatures
) &&
1879 (dev
->drv
[d
]->interface
->features
& ISDN_FEATURE_L2_TRANS
))) {
1880 if ((pre_dev
< 0) || (pre_chan
< 0)) {
1881 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1882 dev
->usage
[i
] |= usage
;
1886 if ((pre_dev
== d
) && (pre_chan
== dev
->chanmap
[i
])) {
1887 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1888 dev
->usage
[i
] |= usage
;
1900 * Set state of ISDN-channel to 'unused'
1903 isdn_free_channel(int di
, int ch
, int usage
)
1907 if ((di
< 0) || (ch
< 0)) {
1908 printk(KERN_WARNING
"%s: called with invalid drv(%d) or channel(%d)\n",
1912 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1913 if (((!usage
) || ((dev
->usage
[i
] & ISDN_USAGE_MASK
) == usage
)) &&
1914 (dev
->drvmap
[i
] == di
) &&
1915 (dev
->chanmap
[i
] == ch
)) {
1916 dev
->usage
[i
] &= (ISDN_USAGE_NONE
| ISDN_USAGE_EXCLUSIVE
);
1917 strcpy(dev
->num
[i
], "???");
1920 // 20.10.99 JIM, try to reinitialize v110 !
1921 dev
->v110emu
[i
] = 0;
1922 atomic_set(&(dev
->v110use
[i
]), 0);
1923 isdn_v110_close(dev
->v110
[i
]);
1924 dev
->v110
[i
] = NULL
;
1925 // 20.10.99 JIM, try to reinitialize v110 !
1928 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[ch
]);
1933 * Cancel Exclusive-Flag for ISDN-channel
1936 isdn_unexclusive_channel(int di
, int ch
)
1940 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1941 if ((dev
->drvmap
[i
] == di
) &&
1942 (dev
->chanmap
[i
] == ch
)) {
1943 dev
->usage
[i
] &= ~ISDN_USAGE_EXCLUSIVE
;
1950 * writebuf replacement for SKB_ABLE drivers
1953 isdn_writebuf_stub(int drvidx
, int chan
, const u_char __user
*buf
, int len
)
1956 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1957 struct sk_buff
*skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1961 skb_reserve(skb
, hl
);
1962 if (copy_from_user(skb_put(skb
, len
), buf
, len
)) {
1966 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, 1, skb
);
1970 dev
->obytes
[isdn_dc2minor(drvidx
, chan
)] += ret
;
1975 * Return: length of data on success, -ERRcode on failure.
1978 isdn_writebuf_skb_stub(int drvidx
, int chan
, int ack
, struct sk_buff
*skb
)
1981 struct sk_buff
*nskb
= NULL
;
1982 int v110_ret
= skb
->len
;
1983 int idx
= isdn_dc2minor(drvidx
, chan
);
1985 if (dev
->v110
[idx
]) {
1986 atomic_inc(&dev
->v110use
[idx
]);
1987 nskb
= isdn_v110_encode(dev
->v110
[idx
], skb
);
1988 atomic_dec(&dev
->v110use
[idx
]);
1991 v110_ret
= *((int *)nskb
->data
);
1992 skb_pull(nskb
, sizeof(int));
1994 dev_kfree_skb(nskb
);
1997 /* V.110 must always be acknowledged */
1999 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, nskb
);
2001 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2003 if (skb_headroom(skb
) < hl
) {
2005 * This should only occur when new HL driver with
2006 * increased hl_hdrlen was loaded after netdevice
2007 * was created and connected to the new driver.
2009 * The V.110 branch (re-allocates on its own) does
2012 struct sk_buff
*skb_tmp
;
2014 skb_tmp
= skb_realloc_headroom(skb
, hl
);
2015 printk(KERN_DEBUG
"isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp
? "" : " failed");
2016 if (!skb_tmp
) return -ENOMEM
; /* 0 better? */
2017 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb_tmp
);
2021 dev_kfree_skb(skb_tmp
);
2024 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb
);
2028 dev
->obytes
[idx
] += ret
;
2029 if (dev
->v110
[idx
]) {
2030 atomic_inc(&dev
->v110use
[idx
]);
2031 dev
->v110
[idx
]->skbuser
++;
2032 atomic_dec(&dev
->v110use
[idx
]);
2033 /* For V.110 return unencoded data length */
2035 /* if the complete frame was send we free the skb;
2036 if not upper function will requeue the skb */
2037 if (ret
== skb
->len
)
2042 dev_kfree_skb(nskb
);
2047 isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
)
2051 init_waitqueue_head(&d
->st_waitq
);
2052 if (d
->flags
& DRV_FLAG_RUNNING
)
2054 if (n
< 1) return 0;
2056 m
= (adding
) ? d
->channels
+ n
: n
;
2058 if (dev
->channels
+ n
> ISDN_MAX_CHANNELS
) {
2059 printk(KERN_WARNING
"register_isdn: Max. %d channels supported\n",
2064 if ((adding
) && (d
->rcverr
))
2066 if (!(d
->rcverr
= kcalloc(m
, sizeof(int), GFP_ATOMIC
))) {
2067 printk(KERN_WARNING
"register_isdn: Could not alloc rcverr\n");
2071 if ((adding
) && (d
->rcvcount
))
2073 if (!(d
->rcvcount
= kcalloc(m
, sizeof(int), GFP_ATOMIC
))) {
2074 printk(KERN_WARNING
"register_isdn: Could not alloc rcvcount\n");
2080 if ((adding
) && (d
->rpqueue
)) {
2081 for (j
= 0; j
< d
->channels
; j
++)
2082 skb_queue_purge(&d
->rpqueue
[j
]);
2085 d
->rpqueue
= kmalloc_array(m
, sizeof(struct sk_buff_head
), GFP_ATOMIC
);
2087 printk(KERN_WARNING
"register_isdn: Could not alloc rpqueue\n");
2094 for (j
= 0; j
< m
; j
++) {
2095 skb_queue_head_init(&d
->rpqueue
[j
]);
2098 if ((adding
) && (d
->rcv_waitq
))
2099 kfree(d
->rcv_waitq
);
2100 d
->rcv_waitq
= kmalloc(array3_size(sizeof(wait_queue_head_t
), 2, m
),
2102 if (!d
->rcv_waitq
) {
2103 printk(KERN_WARNING
"register_isdn: Could not alloc rcv_waitq\n");
2111 d
->snd_waitq
= d
->rcv_waitq
+ m
;
2112 for (j
= 0; j
< m
; j
++) {
2113 init_waitqueue_head(&d
->rcv_waitq
[j
]);
2114 init_waitqueue_head(&d
->snd_waitq
[j
]);
2118 for (j
= d
->channels
; j
< m
; j
++)
2119 for (k
= 0; k
< ISDN_MAX_CHANNELS
; k
++)
2120 if (dev
->chanmap
[k
] < 0) {
2121 dev
->chanmap
[k
] = j
;
2122 dev
->drvmap
[k
] = drvidx
;
2130 * Low-level-driver registration
2134 set_global_features(void)
2138 dev
->global_features
= 0;
2139 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++) {
2140 if (!dev
->drv
[drvidx
])
2142 if (dev
->drv
[drvidx
]->interface
)
2143 dev
->global_features
|= dev
->drv
[drvidx
]->interface
->features
;
2147 #ifdef CONFIG_ISDN_DIVERSION
2149 static char *map_drvname(int di
)
2151 if ((di
< 0) || (di
>= ISDN_MAX_DRIVERS
))
2153 return (dev
->drvid
[di
]); /* driver name */
2156 static int map_namedrv(char *id
)
2159 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2160 { if (!strcmp(dev
->drvid
[i
], id
))
2166 int DIVERT_REG_NAME(isdn_divert_if
*i_div
)
2168 if (i_div
->if_magic
!= DIVERT_IF_MAGIC
)
2169 return (DIVERT_VER_ERR
);
2172 case DIVERT_CMD_REL
:
2173 if (divert_if
!= i_div
)
2174 return (DIVERT_REL_ERR
);
2175 divert_if
= NULL
; /* free interface */
2176 return (DIVERT_NO_ERR
);
2178 case DIVERT_CMD_REG
:
2180 return (DIVERT_REG_ERR
);
2181 i_div
->ll_cmd
= isdn_command
; /* set command function */
2182 i_div
->drv_to_name
= map_drvname
;
2183 i_div
->name_to_drv
= map_namedrv
;
2184 divert_if
= i_div
; /* remember interface */
2185 return (DIVERT_NO_ERR
);
2188 return (DIVERT_CMD_ERR
);
2190 } /* DIVERT_REG_NAME */
2192 EXPORT_SYMBOL(DIVERT_REG_NAME
);
2194 #endif /* CONFIG_ISDN_DIVERSION */
2197 EXPORT_SYMBOL(register_isdn
);
2198 #ifdef CONFIG_ISDN_PPP
2199 EXPORT_SYMBOL(isdn_ppp_register_compressor
);
2200 EXPORT_SYMBOL(isdn_ppp_unregister_compressor
);
2204 register_isdn(isdn_if
*i
)
2211 if (dev
->drivers
>= ISDN_MAX_DRIVERS
) {
2212 printk(KERN_WARNING
"register_isdn: Max. %d drivers supported\n",
2216 if (!i
->writebuf_skb
) {
2217 printk(KERN_WARNING
"register_isdn: No write routine given.\n");
2220 if (!(d
= kzalloc(sizeof(isdn_driver_t
), GFP_KERNEL
))) {
2221 printk(KERN_WARNING
"register_isdn: Could not alloc driver-struct\n");
2225 d
->maxbufsize
= i
->maxbufsize
;
2228 d
->flags
= DRV_FLAG_LOADED
;
2232 spin_lock_irqsave(&dev
->lock
, flags
);
2233 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2234 if (!dev
->drv
[drvidx
])
2236 if (isdn_add_channels(d
, drvidx
, i
->channels
, 0)) {
2237 spin_unlock_irqrestore(&dev
->lock
, flags
);
2241 i
->channels
= drvidx
;
2242 i
->rcvcallb_skb
= isdn_receive_skb_callback
;
2243 i
->statcallb
= isdn_status_callback
;
2245 sprintf(i
->id
, "line%d", drvidx
);
2246 for (j
= 0; j
< drvidx
; j
++)
2247 if (!strcmp(i
->id
, dev
->drvid
[j
]))
2248 sprintf(i
->id
, "line%d", drvidx
);
2249 dev
->drv
[drvidx
] = d
;
2250 strcpy(dev
->drvid
[drvidx
], i
->id
);
2253 set_global_features();
2254 spin_unlock_irqrestore(&dev
->lock
, flags
);
2259 *****************************************************************************
2260 * And now the modules code.
2261 *****************************************************************************
2265 isdn_getrev(const char *revision
)
2270 if ((p
= strchr(revision
, ':'))) {
2272 p
= strchr(rev
, '$');
2280 * Allocate and initialize all data, register modem-devices
2282 static int __init
isdn_init(void)
2287 dev
= vzalloc(sizeof(isdn_dev
));
2289 printk(KERN_WARNING
"isdn: Could not allocate device-struct.\n");
2292 timer_setup(&dev
->timer
, isdn_timer_funct
, 0);
2293 spin_lock_init(&dev
->lock
);
2294 spin_lock_init(&dev
->timerlock
);
2296 dev
->owner
= THIS_MODULE
;
2298 mutex_init(&dev
->mtx
);
2299 init_waitqueue_head(&dev
->info_waitq
);
2300 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2301 dev
->drvmap
[i
] = -1;
2302 dev
->chanmap
[i
] = -1;
2304 strcpy(dev
->num
[i
], "???");
2306 if (register_chrdev(ISDN_MAJOR
, "isdn", &isdn_fops
)) {
2307 printk(KERN_WARNING
"isdn: Could not register control devices\n");
2311 if ((isdn_tty_modem_init()) < 0) {
2312 printk(KERN_WARNING
"isdn: Could not register tty devices\n");
2314 unregister_chrdev(ISDN_MAJOR
, "isdn");
2317 #ifdef CONFIG_ISDN_PPP
2318 if (isdn_ppp_init() < 0) {
2319 printk(KERN_WARNING
"isdn: Could not create PPP-device-structs\n");
2321 unregister_chrdev(ISDN_MAJOR
, "isdn");
2325 #endif /* CONFIG_ISDN_PPP */
2327 strcpy(tmprev
, isdn_revision
);
2328 printk(KERN_NOTICE
"ISDN subsystem Rev: %s/", isdn_getrev(tmprev
));
2329 strcpy(tmprev
, isdn_net_revision
);
2330 printk("%s/", isdn_getrev(tmprev
));
2331 strcpy(tmprev
, isdn_ppp_revision
);
2332 printk("%s/", isdn_getrev(tmprev
));
2333 strcpy(tmprev
, isdn_audio_revision
);
2334 printk("%s/", isdn_getrev(tmprev
));
2335 strcpy(tmprev
, isdn_v110_revision
);
2336 printk("%s", isdn_getrev(tmprev
));
2339 printk(" loaded\n");
2350 static void __exit
isdn_exit(void)
2352 #ifdef CONFIG_ISDN_PPP
2355 if (isdn_net_rmall() < 0) {
2356 printk(KERN_WARNING
"isdn: net-device busy, remove cancelled\n");
2360 unregister_chrdev(ISDN_MAJOR
, "isdn");
2361 del_timer_sync(&dev
->timer
);
2362 /* call vfree with interrupts enabled, else it will hang */
2364 printk(KERN_NOTICE
"ISDN-subsystem unloaded\n");
2367 module_init(isdn_init
);
2368 module_exit(isdn_exit
);