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;
170 * Literal match with following character,
176 return (*s
== '\0') ? 2 : 1;
179 /* Match anything. */
185 /* Trailing star matches everything. */
186 return (*++p
? isdn_star(s
, p
) : 0);
188 /* [^....] means inverse character class. */
189 if ((reverse
= (p
[1] == '^')))
191 for (last
= 0, matched
= 0; *++p
&& (*p
!= ']'); last
= *p
)
192 /* This next line requires a good C compiler. */
193 if (*p
== '-' ? *s
<= *++p
&& *s
>= last
: *s
== *p
)
195 if (matched
== reverse
)
199 return (*s
== '\0') ? 0 : nostar
;
202 int isdn_msncmp(const char *msn1
, const char *msn2
)
204 char TmpMsn1
[ISDN_MSNLEN
];
205 char TmpMsn2
[ISDN_MSNLEN
];
208 for (p
= TmpMsn1
; *msn1
&& *msn1
!= ':';) // Strip off a SPID
212 for (p
= TmpMsn2
; *msn2
&& *msn2
!= ':';) // Strip off a SPID
216 return isdn_wildmat(TmpMsn1
, TmpMsn2
);
220 isdn_dc2minor(int di
, int ch
)
223 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
224 if (dev
->chanmap
[i
] == ch
&& dev
->drvmap
[i
] == di
)
229 static int isdn_timer_cnt1
= 0;
230 static int isdn_timer_cnt2
= 0;
231 static int isdn_timer_cnt3
= 0;
234 isdn_timer_funct(struct timer_list
*unused
)
236 int tf
= dev
->tflags
;
237 if (tf
& ISDN_TIMER_FAST
) {
238 if (tf
& ISDN_TIMER_MODEMREAD
)
239 isdn_tty_readmodem();
240 if (tf
& ISDN_TIMER_MODEMPLUS
)
241 isdn_tty_modem_escape();
242 if (tf
& ISDN_TIMER_MODEMXMIT
)
243 isdn_tty_modem_xmit();
245 if (tf
& ISDN_TIMER_SLOW
) {
246 if (++isdn_timer_cnt1
>= ISDN_TIMER_02SEC
) {
248 if (tf
& ISDN_TIMER_NETDIAL
)
251 if (++isdn_timer_cnt2
>= ISDN_TIMER_1SEC
) {
253 if (tf
& ISDN_TIMER_NETHANGUP
)
255 if (++isdn_timer_cnt3
>= ISDN_TIMER_RINGING
) {
257 if (tf
& ISDN_TIMER_MODEMRING
)
258 isdn_tty_modem_ring();
260 if (tf
& ISDN_TIMER_CARRIER
)
261 isdn_tty_carrier_timeout();
265 mod_timer(&dev
->timer
, jiffies
+ ISDN_TIMER_RES
);
269 isdn_timer_ctrl(int tf
, int onoff
)
274 spin_lock_irqsave(&dev
->timerlock
, flags
);
275 if ((tf
& ISDN_TIMER_SLOW
) && (!(dev
->tflags
& ISDN_TIMER_SLOW
))) {
276 /* If the slow-timer wasn't activated until now */
280 old_tflags
= dev
->tflags
;
285 if (dev
->tflags
&& !old_tflags
)
286 mod_timer(&dev
->timer
, jiffies
+ ISDN_TIMER_RES
);
287 spin_unlock_irqrestore(&dev
->timerlock
, flags
);
291 * Receive a packet from B-Channel. (Called from low-level-module)
294 isdn_receive_skb_callback(int di
, int channel
, struct sk_buff
*skb
)
298 if ((i
= isdn_dc2minor(di
, channel
)) == -1) {
302 /* Update statistics */
303 dev
->ibytes
[i
] += skb
->len
;
305 /* First, try to deliver data to network-device */
306 if (isdn_net_rcv_skb(i
, skb
))
310 * makes sense for async streams only, so it is
311 * called after possible net-device delivery.
314 atomic_inc(&dev
->v110use
[i
]);
315 skb
= isdn_v110_decode(dev
->v110
[i
], skb
);
316 atomic_dec(&dev
->v110use
[i
]);
321 /* No network-device found, deliver to tty or raw-channel */
323 if (isdn_tty_rcv_skb(i
, di
, channel
, skb
))
325 wake_up_interruptible(&dev
->drv
[di
]->rcv_waitq
[channel
]);
331 * Intercept command from Linklevel to Lowlevel.
332 * If layer 2 protocol is V.110 and this is not supported by current
333 * lowlevel-driver, use driver's transparent mode and handle V.110 in
337 isdn_command(isdn_ctrl
*cmd
)
339 if (cmd
->driver
== -1) {
340 printk(KERN_WARNING
"isdn_command command(%x) driver -1\n", cmd
->command
);
343 if (!dev
->drv
[cmd
->driver
]) {
344 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d] NULL\n",
345 cmd
->command
, cmd
->driver
);
348 if (!dev
->drv
[cmd
->driver
]->interface
) {
349 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d]->interface NULL\n",
350 cmd
->command
, cmd
->driver
);
353 if (cmd
->command
== ISDN_CMD_SETL2
) {
354 int idx
= isdn_dc2minor(cmd
->driver
, cmd
->arg
& 255);
355 unsigned long l2prot
= (cmd
->arg
>> 8) & 255;
356 unsigned long features
= (dev
->drv
[cmd
->driver
]->interface
->features
357 >> ISDN_FEATURE_L2_SHIFT
) &
358 ISDN_FEATURE_L2_MASK
;
359 unsigned long l2_feature
= (1 << l2prot
);
362 case ISDN_PROTO_L2_V11096
:
363 case ISDN_PROTO_L2_V11019
:
364 case ISDN_PROTO_L2_V11038
:
365 /* If V.110 requested, but not supported by
366 * HL-driver, set emulator-flag and change
367 * Layer-2 to transparent
369 if (!(features
& l2_feature
)) {
370 dev
->v110emu
[idx
] = l2prot
;
371 cmd
->arg
= (cmd
->arg
& 255) |
372 (ISDN_PROTO_L2_TRANS
<< 8);
374 dev
->v110emu
[idx
] = 0;
377 return dev
->drv
[cmd
->driver
]->interface
->command(cmd
);
381 isdn_all_eaz(int di
, int ch
)
389 cmd
.command
= ISDN_CMD_SETEAZ
;
390 cmd
.parm
.num
[0] = '\0';
395 * Begin of a CAPI like LL<->HL interface, currently used only for
396 * supplementary service (CAPI 2.0 part III)
398 #include <linux/isdn/capicmd.h>
401 isdn_capi_rec_hl_msg(capi_msg
*cm
)
403 switch (cm
->Command
) {
405 /* in the moment only handled in tty */
406 return (isdn_tty_capi_facility(cm
));
413 isdn_status_callback(isdn_ctrl
*c
)
424 i
= isdn_dc2minor(di
, c
->arg
);
425 switch (c
->command
) {
426 case ISDN_STAT_BSENT
:
429 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
431 if (isdn_net_stat_callback(i
, c
))
433 if (isdn_v110_stat_callback(i
, c
))
435 if (isdn_tty_stat_callback(i
, c
))
437 wake_up_interruptible(&dev
->drv
[di
]->snd_waitq
[c
->arg
]);
439 case ISDN_STAT_STAVAIL
:
440 dev
->drv
[di
]->stavail
+= c
->arg
;
441 wake_up_interruptible(&dev
->drv
[di
]->st_waitq
);
444 dev
->drv
[di
]->flags
|= DRV_FLAG_RUNNING
;
445 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
446 if (dev
->drvmap
[i
] == di
)
447 isdn_all_eaz(di
, dev
->chanmap
[i
]);
448 set_global_features();
451 dev
->drv
[di
]->flags
&= ~DRV_FLAG_RUNNING
;
453 case ISDN_STAT_ICALL
:
456 #ifdef ISDN_DEBUG_STATCALLB
457 printk(KERN_DEBUG
"ICALL (net): %d %ld %s\n", di
, c
->arg
, c
->parm
.num
);
459 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) {
462 cmd
.command
= ISDN_CMD_HANGUP
;
466 /* Try to find a network-interface which will accept incoming call */
467 r
= ((c
->command
== ISDN_STAT_ICALLW
) ? 0 : isdn_net_find_icall(di
, c
->arg
, i
, &c
->parm
.setup
));
470 /* No network-device replies.
472 * These return 0 on no match, 1 on match and
473 * 3 on eventually match, if CID is longer.
475 if (c
->command
== ISDN_STAT_ICALL
)
476 if ((retval
= isdn_tty_find_icall(di
, c
->arg
, &c
->parm
.setup
))) return (retval
);
477 #ifdef CONFIG_ISDN_DIVERSION
479 if ((retval
= divert_if
->stat_callback(c
)))
480 return (retval
); /* processed */
481 #endif /* CONFIG_ISDN_DIVERSION */
482 if ((!retval
) && (dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
)) {
483 /* No tty responding */
486 cmd
.command
= ISDN_CMD_HANGUP
;
492 /* Schedule connection-setup */
496 cmd
.command
= ISDN_CMD_ACCEPTD
;
497 for (p
= dev
->netdev
; p
; p
= p
->next
)
498 if (p
->local
->isdn_channel
== cmd
.arg
)
500 strcpy(cmd
.parm
.setup
.eazmsn
, p
->local
->msn
);
507 case 2: /* For calling back, first reject incoming call ... */
508 case 3: /* Interface found, but down, reject call actively */
510 printk(KERN_INFO
"isdn: Rejecting Call\n");
513 cmd
.command
= ISDN_CMD_HANGUP
;
519 /* ... then start callback. */
523 /* Number would eventually match, if longer */
527 #ifdef ISDN_DEBUG_STATCALLB
528 printk(KERN_DEBUG
"ICALL: ret=%d\n", retval
);
535 #ifdef ISDN_DEBUG_STATCALLB
536 printk(KERN_DEBUG
"CINF: %ld %s\n", c
->arg
, c
->parm
.num
);
538 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
540 if (strcmp(c
->parm
.num
, "0"))
541 isdn_net_stat_callback(i
, c
);
542 isdn_tty_stat_callback(i
, c
);
544 case ISDN_STAT_CAUSE
:
545 #ifdef ISDN_DEBUG_STATCALLB
546 printk(KERN_DEBUG
"CAUSE: %ld %s\n", c
->arg
, c
->parm
.num
);
548 printk(KERN_INFO
"isdn: %s,ch%ld cause: %s\n",
549 dev
->drvid
[di
], c
->arg
, c
->parm
.num
);
550 isdn_tty_stat_callback(i
, c
);
551 #ifdef CONFIG_ISDN_DIVERSION
553 divert_if
->stat_callback(c
);
554 #endif /* CONFIG_ISDN_DIVERSION */
556 case ISDN_STAT_DISPLAY
:
557 #ifdef ISDN_DEBUG_STATCALLB
558 printk(KERN_DEBUG
"DISPLAY: %ld %s\n", c
->arg
, c
->parm
.display
);
560 isdn_tty_stat_callback(i
, c
);
561 #ifdef CONFIG_ISDN_DIVERSION
563 divert_if
->stat_callback(c
);
564 #endif /* CONFIG_ISDN_DIVERSION */
566 case ISDN_STAT_DCONN
:
569 #ifdef ISDN_DEBUG_STATCALLB
570 printk(KERN_DEBUG
"DCONN: %ld\n", c
->arg
);
572 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
574 /* Find any net-device, waiting for D-channel setup */
575 if (isdn_net_stat_callback(i
, c
))
577 isdn_v110_stat_callback(i
, c
);
578 /* Find any ttyI, waiting for D-channel setup */
579 if (isdn_tty_stat_callback(i
, c
)) {
582 cmd
.command
= ISDN_CMD_ACCEPTB
;
590 #ifdef ISDN_DEBUG_STATCALLB
591 printk(KERN_DEBUG
"DHUP: %ld\n", c
->arg
);
593 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
595 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
597 /* Signal hangup to network-devices */
598 if (isdn_net_stat_callback(i
, c
))
600 isdn_v110_stat_callback(i
, c
);
601 if (isdn_tty_stat_callback(i
, c
))
603 #ifdef CONFIG_ISDN_DIVERSION
605 divert_if
->stat_callback(c
);
606 #endif /* CONFIG_ISDN_DIVERSION */
609 case ISDN_STAT_BCONN
:
612 #ifdef ISDN_DEBUG_STATCALLB
613 printk(KERN_DEBUG
"BCONN: %ld\n", c
->arg
);
615 /* Signal B-channel-connect to network-devices */
616 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
618 dev
->drv
[di
]->online
|= (1 << (c
->arg
));
620 if (isdn_net_stat_callback(i
, c
))
622 isdn_v110_stat_callback(i
, c
);
623 if (isdn_tty_stat_callback(i
, c
))
629 #ifdef ISDN_DEBUG_STATCALLB
630 printk(KERN_DEBUG
"BHUP: %ld\n", c
->arg
);
632 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
634 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
636 #ifdef CONFIG_ISDN_X25
637 /* Signal hangup to network-devices */
638 if (isdn_net_stat_callback(i
, c
))
641 isdn_v110_stat_callback(i
, c
);
642 if (isdn_tty_stat_callback(i
, c
))
645 case ISDN_STAT_NODCH
:
648 #ifdef ISDN_DEBUG_STATCALLB
649 printk(KERN_DEBUG
"NODCH: %ld\n", c
->arg
);
651 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
653 if (isdn_net_stat_callback(i
, c
))
655 if (isdn_tty_stat_callback(i
, c
))
658 case ISDN_STAT_ADDCH
:
659 spin_lock_irqsave(&dev
->lock
, flags
);
660 if (isdn_add_channels(dev
->drv
[di
], di
, c
->arg
, 1)) {
661 spin_unlock_irqrestore(&dev
->lock
, flags
);
664 spin_unlock_irqrestore(&dev
->lock
, flags
);
667 case ISDN_STAT_DISCH
:
668 spin_lock_irqsave(&dev
->lock
, flags
);
669 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
670 if ((dev
->drvmap
[i
] == di
) &&
671 (dev
->chanmap
[i
] == c
->arg
)) {
673 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
675 if (USG_NONE(dev
->usage
[i
])) {
676 dev
->usage
[i
] |= ISDN_USAGE_DISABLED
;
682 spin_unlock_irqrestore(&dev
->lock
, flags
);
685 case ISDN_STAT_UNLOAD
:
686 while (dev
->drv
[di
]->locks
> 0) {
687 isdn_unlock_driver(dev
->drv
[di
]);
689 spin_lock_irqsave(&dev
->lock
, flags
);
690 isdn_tty_stat_callback(i
, c
);
691 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
692 if (dev
->drvmap
[i
] == di
) {
694 dev
->chanmap
[i
] = -1;
695 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
698 dev
->channels
-= dev
->drv
[di
]->channels
;
699 kfree(dev
->drv
[di
]->rcverr
);
700 kfree(dev
->drv
[di
]->rcvcount
);
701 for (i
= 0; i
< dev
->drv
[di
]->channels
; i
++)
702 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[i
]);
703 kfree(dev
->drv
[di
]->rpqueue
);
704 kfree(dev
->drv
[di
]->rcv_waitq
);
707 dev
->drvid
[di
][0] = '\0';
709 set_global_features();
710 spin_unlock_irqrestore(&dev
->lock
, flags
);
712 case ISDN_STAT_L1ERR
:
714 case CAPI_PUT_MESSAGE
:
715 return (isdn_capi_rec_hl_msg(&c
->parm
.cmsg
));
716 #ifdef CONFIG_ISDN_TTY_FAX
717 case ISDN_STAT_FAXIND
:
718 isdn_tty_stat_callback(i
, c
);
721 #ifdef CONFIG_ISDN_AUDIO
722 case ISDN_STAT_AUDIO
:
723 isdn_tty_stat_callback(i
, c
);
726 #ifdef CONFIG_ISDN_DIVERSION
728 case ISDN_STAT_REDIR
:
730 return (divert_if
->stat_callback(c
));
731 #endif /* CONFIG_ISDN_DIVERSION */
739 * Get integer from char-pointer, set pointer to end of number
742 isdn_getnum(char **p
)
746 while (*p
[0] >= '0' && *p
[0] <= '9')
747 v
= ((v
< 0) ? 0 : (v
* 10)) + (int) ((*p
[0]++) - '0');
754 * isdn_readbchan() tries to get data from the read-queue.
755 * It MUST be called with interrupts off.
757 * Be aware that this is not an atomic operation when sleep != 0, even though
758 * interrupts are turned off! Well, like that we are currently only called
759 * on behalf of a read system call on raw device files (which are documented
760 * to be dangerous and for debugging purpose only). The inode semaphore
761 * takes care that this is not called for the same minor device number while
762 * we are sleeping, but access is not serialized against simultaneous read()
763 * from the corresponding ttyI device. Can other ugly events, like changes
764 * of the mapping (di,ch)<->minor, happen during the sleep? --he
767 isdn_readbchan(int di
, int channel
, u_char
*buf
, u_char
*fp
, int len
, wait_queue_head_t
*sleep
)
778 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
])) {
780 wait_event_interruptible(*sleep
,
781 !skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]));
785 if (len
> dev
->drv
[di
]->rcvcount
[channel
])
786 len
= dev
->drv
[di
]->rcvcount
[channel
];
790 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
792 #ifdef CONFIG_ISDN_AUDIO
793 if (ISDN_AUDIO_SKB_LOCK(skb
))
795 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
796 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
798 unsigned long DLEmask
= (1 << channel
);
801 count_pull
= count_put
= 0;
802 while ((count_pull
< skb
->len
) && (len
> 0)) {
804 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
806 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
810 dev
->drv
[di
]->DLEflag
|= DLEmask
;
811 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
818 if (count_pull
>= skb
->len
)
822 /* No DLE's in buff, so simply copy it */
824 if ((count_pull
= skb
->len
) > len
) {
828 count_put
= count_pull
;
829 skb_copy_from_linear_data(skb
, cp
, count_put
);
832 #ifdef CONFIG_ISDN_AUDIO
837 memset(fp
, 0, count_put
);
841 /* We got all the data in this buff.
842 * Now we can dequeue it.
846 #ifdef CONFIG_ISDN_AUDIO
847 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
849 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
852 /* Not yet emptied this buff, so it
853 * must stay in the queue, for further calls
854 * but we pull off the data we got until now.
856 skb_pull(skb
, count_pull
);
857 #ifdef CONFIG_ISDN_AUDIO
858 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
861 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
867 * isdn_readbchan_tty() tries to get data from the read-queue.
868 * It MUST be called with interrupts off.
870 * Be aware that this is not an atomic operation when sleep != 0, even though
871 * interrupts are turned off! Well, like that we are currently only called
872 * on behalf of a read system call on raw device files (which are documented
873 * to be dangerous and for debugging purpose only). The inode semaphore
874 * takes care that this is not called for the same minor device number while
875 * we are sleeping, but access is not serialized against simultaneous read()
876 * from the corresponding ttyI device. Can other ugly events, like changes
877 * of the mapping (di,ch)<->minor, happen during the sleep? --he
880 isdn_readbchan_tty(int di
, int channel
, struct tty_port
*port
, int cisco_hack
)
892 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
895 len
= tty_buffer_request_room(port
, dev
->drv
[di
]->rcvcount
[channel
]);
901 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
903 #ifdef CONFIG_ISDN_AUDIO
904 if (ISDN_AUDIO_SKB_LOCK(skb
))
906 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
907 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
909 unsigned long DLEmask
= (1 << channel
);
912 count_pull
= count_put
= 0;
913 while ((count_pull
< skb
->len
) && (len
> 0)) {
914 /* push every character but the last to the tty buffer directly */
916 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
918 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
920 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
924 dev
->drv
[di
]->DLEflag
|= DLEmask
;
925 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
932 if (count_pull
>= skb
->len
)
936 /* No DLE's in buff, so simply copy it */
938 if ((count_pull
= skb
->len
) > len
) {
942 count_put
= count_pull
;
944 tty_insert_flip_string(port
, skb
->data
, count_put
- 1);
945 last
= skb
->data
[count_put
- 1];
947 #ifdef CONFIG_ISDN_AUDIO
952 /* We got all the data in this buff.
953 * Now we can dequeue it.
956 tty_insert_flip_char(port
, last
, 0xFF);
958 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
959 #ifdef CONFIG_ISDN_AUDIO
960 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
962 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
965 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
966 /* Not yet emptied this buff, so it
967 * must stay in the queue, for further calls
968 * but we pull off the data we got until now.
970 skb_pull(skb
, count_pull
);
971 #ifdef CONFIG_ISDN_AUDIO
972 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
975 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
982 isdn_minor2drv(int minor
)
984 return (dev
->drvmap
[minor
]);
988 isdn_minor2chan(int minor
)
990 return (dev
->chanmap
[minor
]);
996 static char istatbuf
[2048];
1000 sprintf(istatbuf
, "idmap:\t");
1001 p
= istatbuf
+ strlen(istatbuf
);
1002 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1003 sprintf(p
, "%s ", (dev
->drvmap
[i
] < 0) ? "-" : dev
->drvid
[dev
->drvmap
[i
]]);
1004 p
= istatbuf
+ strlen(istatbuf
);
1006 sprintf(p
, "\nchmap:\t");
1007 p
= istatbuf
+ strlen(istatbuf
);
1008 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1009 sprintf(p
, "%d ", dev
->chanmap
[i
]);
1010 p
= istatbuf
+ strlen(istatbuf
);
1012 sprintf(p
, "\ndrmap:\t");
1013 p
= istatbuf
+ strlen(istatbuf
);
1014 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1015 sprintf(p
, "%d ", dev
->drvmap
[i
]);
1016 p
= istatbuf
+ strlen(istatbuf
);
1018 sprintf(p
, "\nusage:\t");
1019 p
= istatbuf
+ strlen(istatbuf
);
1020 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1021 sprintf(p
, "%d ", dev
->usage
[i
]);
1022 p
= istatbuf
+ strlen(istatbuf
);
1024 sprintf(p
, "\nflags:\t");
1025 p
= istatbuf
+ strlen(istatbuf
);
1026 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
1028 sprintf(p
, "%ld ", dev
->drv
[i
]->online
);
1029 p
= istatbuf
+ strlen(istatbuf
);
1032 p
= istatbuf
+ strlen(istatbuf
);
1035 sprintf(p
, "\nphone:\t");
1036 p
= istatbuf
+ strlen(istatbuf
);
1037 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1038 sprintf(p
, "%s ", dev
->num
[i
]);
1039 p
= istatbuf
+ strlen(istatbuf
);
1045 /* Module interface-code */
1048 isdn_info_update(void)
1050 infostruct
*p
= dev
->infochain
;
1054 p
= (infostruct
*) p
->next
;
1056 wake_up_interruptible(&(dev
->info_waitq
));
1060 isdn_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*off
)
1062 uint minor
= iminor(file_inode(file
));
1069 mutex_lock(&isdn_mutex
);
1070 if (minor
== ISDN_MINOR_STATUS
) {
1071 if (!file
->private_data
) {
1072 if (file
->f_flags
& O_NONBLOCK
) {
1076 wait_event_interruptible(dev
->info_waitq
,
1077 file
->private_data
);
1080 file
->private_data
= NULL
;
1081 if ((len
= strlen(p
)) <= count
) {
1082 if (copy_to_user(buf
, p
, len
)) {
1093 if (!dev
->drivers
) {
1097 if (minor
<= ISDN_MINOR_BMAX
) {
1098 printk(KERN_WARNING
"isdn_read minor %d obsolete!\n", minor
);
1099 drvidx
= isdn_minor2drv(minor
);
1104 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1108 chidx
= isdn_minor2chan(minor
);
1109 if (!(p
= kmalloc(count
, GFP_KERNEL
))) {
1113 len
= isdn_readbchan(drvidx
, chidx
, p
, NULL
, count
,
1114 &dev
->drv
[drvidx
]->rcv_waitq
[chidx
]);
1116 if (copy_to_user(buf
, p
, len
))
1122 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1123 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1128 if (!dev
->drv
[drvidx
]->stavail
) {
1129 if (file
->f_flags
& O_NONBLOCK
) {
1133 wait_event_interruptible(dev
->drv
[drvidx
]->st_waitq
,
1134 dev
->drv
[drvidx
]->stavail
);
1136 if (dev
->drv
[drvidx
]->interface
->readstat
) {
1137 if (count
> dev
->drv
[drvidx
]->stavail
)
1138 count
= dev
->drv
[drvidx
]->stavail
;
1139 len
= dev
->drv
[drvidx
]->interface
->readstat(buf
, count
,
1140 drvidx
, isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1149 dev
->drv
[drvidx
]->stavail
-= len
;
1151 dev
->drv
[drvidx
]->stavail
= 0;
1156 #ifdef CONFIG_ISDN_PPP
1157 if (minor
<= ISDN_MINOR_PPPMAX
) {
1158 retval
= isdn_ppp_read(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1164 mutex_unlock(&isdn_mutex
);
1169 isdn_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*off
)
1171 uint minor
= iminor(file_inode(file
));
1176 if (minor
== ISDN_MINOR_STATUS
)
1181 mutex_lock(&isdn_mutex
);
1182 if (minor
<= ISDN_MINOR_BMAX
) {
1183 printk(KERN_WARNING
"isdn_write minor %d obsolete!\n", minor
);
1184 drvidx
= isdn_minor2drv(minor
);
1189 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1193 chidx
= isdn_minor2chan(minor
);
1194 wait_event_interruptible(dev
->drv
[drvidx
]->snd_waitq
[chidx
],
1195 (retval
= isdn_writebuf_stub(drvidx
, chidx
, buf
, count
)));
1198 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1199 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1205 * We want to use the isdnctrl device to load the firmware
1207 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1210 if (dev
->drv
[drvidx
]->interface
->writecmd
)
1211 retval
= dev
->drv
[drvidx
]->interface
->
1212 writecmd(buf
, count
, drvidx
,
1213 isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1218 #ifdef CONFIG_ISDN_PPP
1219 if (minor
<= ISDN_MINOR_PPPMAX
) {
1220 retval
= isdn_ppp_write(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1226 mutex_unlock(&isdn_mutex
);
1231 isdn_poll(struct file
*file
, poll_table
*wait
)
1233 unsigned int mask
= 0;
1234 unsigned int minor
= iminor(file_inode(file
));
1235 int drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1237 mutex_lock(&isdn_mutex
);
1238 if (minor
== ISDN_MINOR_STATUS
) {
1239 poll_wait(file
, &(dev
->info_waitq
), wait
);
1240 /* mask = POLLOUT | POLLWRNORM; */
1241 if (file
->private_data
) {
1242 mask
|= POLLIN
| POLLRDNORM
;
1246 if (minor
>= ISDN_MINOR_CTRL
&& minor
<= ISDN_MINOR_CTRLMAX
) {
1248 /* driver deregistered while file open */
1252 poll_wait(file
, &(dev
->drv
[drvidx
]->st_waitq
), wait
);
1253 mask
= POLLOUT
| POLLWRNORM
;
1254 if (dev
->drv
[drvidx
]->stavail
) {
1255 mask
|= POLLIN
| POLLRDNORM
;
1259 #ifdef CONFIG_ISDN_PPP
1260 if (minor
<= ISDN_MINOR_PPPMAX
) {
1261 mask
= isdn_ppp_poll(file
, wait
);
1267 mutex_unlock(&isdn_mutex
);
1273 isdn_ioctl(struct file
*file
, uint cmd
, ulong arg
)
1275 uint minor
= iminor(file_inode(file
));
1285 isdn_ioctl_struct iocts
;
1286 isdn_net_ioctl_phone phone
;
1287 isdn_net_ioctl_cfg cfg
;
1289 void __user
*argp
= (void __user
*)arg
;
1291 #define name iocpar.name
1292 #define bname iocpar.bname
1293 #define iocts iocpar.iocts
1294 #define phone iocpar.phone
1295 #define cfg iocpar.cfg
1297 if (minor
== ISDN_MINOR_STATUS
) {
1305 ulong __user
*p
= argp
;
1307 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1308 put_user(dev
->ibytes
[i
], p
++);
1309 put_user(dev
->obytes
[i
], p
++);
1316 /* Get peer phone number of a connected
1317 * isdn network interface */
1319 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1321 return isdn_net_getpeer(&phone
, argp
);
1330 if (minor
<= ISDN_MINOR_BMAX
) {
1331 drvidx
= isdn_minor2drv(minor
);
1334 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1338 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1340 * isdn net devices manage lots of configuration variables as linked lists.
1341 * Those lists must only be manipulated from user space. Some of the ioctl's
1342 * service routines access user space and are not atomic. Therefore, ioctl's
1343 * manipulating the lists and ioctl's sleeping while accessing the lists
1344 * are serialized by means of a semaphore.
1348 printk(KERN_INFO
"INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1351 printk(KERN_INFO
"INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1354 /* Add a network-interface */
1356 if (copy_from_user(name
, argp
, sizeof(name
)))
1362 ret
= mutex_lock_interruptible(&dev
->mtx
);
1363 if (ret
) return ret
;
1364 if ((s
= isdn_net_new(s
, NULL
))) {
1365 if (copy_to_user(argp
, s
, strlen(s
) + 1)) {
1372 mutex_unlock(&dev
->mtx
);
1375 /* Add a slave to a network-interface */
1377 if (copy_from_user(bname
, argp
, sizeof(bname
) - 1))
1379 bname
[sizeof(bname
)-1] = 0;
1382 ret
= mutex_lock_interruptible(&dev
->mtx
);
1383 if (ret
) return ret
;
1384 if ((s
= isdn_net_newslave(bname
))) {
1385 if (copy_to_user(argp
, s
, strlen(s
) + 1)) {
1392 mutex_unlock(&dev
->mtx
);
1395 /* Delete a network-interface */
1397 if (copy_from_user(name
, argp
, sizeof(name
)))
1399 ret
= mutex_lock_interruptible(&dev
->mtx
);
1400 if (ret
) return ret
;
1401 ret
= isdn_net_rm(name
);
1402 mutex_unlock(&dev
->mtx
);
1407 /* Set configurable parameters of a network-interface */
1409 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1411 return isdn_net_setcfg(&cfg
);
1415 /* Get configurable parameters of a network-interface */
1417 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1419 if (!(ret
= isdn_net_getcfg(&cfg
))) {
1420 if (copy_to_user(argp
, &cfg
, sizeof(cfg
)))
1427 /* Add a phone-number to a network-interface */
1429 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1431 ret
= mutex_lock_interruptible(&dev
->mtx
);
1432 if (ret
) return ret
;
1433 ret
= isdn_net_addphone(&phone
);
1434 mutex_unlock(&dev
->mtx
);
1439 /* Get list of phone-numbers of a network-interface */
1441 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1443 ret
= mutex_lock_interruptible(&dev
->mtx
);
1444 if (ret
) return ret
;
1445 ret
= isdn_net_getphones(&phone
, argp
);
1446 mutex_unlock(&dev
->mtx
);
1451 /* Delete a phone-number of a network-interface */
1453 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1455 ret
= mutex_lock_interruptible(&dev
->mtx
);
1456 if (ret
) return ret
;
1457 ret
= isdn_net_delphone(&phone
);
1458 mutex_unlock(&dev
->mtx
);
1463 /* Force dialing of a network-interface */
1465 if (copy_from_user(name
, argp
, sizeof(name
)))
1467 return isdn_net_force_dial(name
);
1470 #ifdef CONFIG_ISDN_PPP
1474 if (copy_from_user(name
, argp
, sizeof(name
)))
1476 return isdn_ppp_dial_slave(name
);
1480 if (copy_from_user(name
, argp
, sizeof(name
)))
1482 return isdn_ppp_hangup_slave(name
);
1485 /* Force hangup of a network-interface */
1488 if (copy_from_user(name
, argp
, sizeof(name
)))
1490 return isdn_net_force_hangup(name
);
1493 dev
->net_verbose
= arg
;
1494 printk(KERN_INFO
"isdn: Verbose-Level is %d\n", dev
->net_verbose
);
1498 dev
->global_flags
|= ISDN_GLOBAL_STOPPED
;
1500 dev
->global_flags
&= ~ISDN_GLOBAL_STOPPED
;
1501 printk(KERN_INFO
"isdn: Global Mode %s\n",
1502 (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) ? "stopped" : "running");
1509 if (copy_from_user(&iocts
, argp
,
1510 sizeof(isdn_ioctl_struct
)))
1512 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1513 if (strlen(iocts
.drvid
)) {
1514 if ((p
= strchr(iocts
.drvid
, ',')))
1517 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1518 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1527 dev
->drv
[drvidx
]->flags
|= DRV_FLAG_REJBUS
;
1529 dev
->drv
[drvidx
]->flags
&= ~DRV_FLAG_REJBUS
;
1532 dev
->profd
= current
;
1536 /* Get all Modem-Profiles */
1538 char __user
*p
= argp
;
1541 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1542 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.profile
,
1545 p
+= ISDN_MODEM_NUMREG
;
1546 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.pmsn
, ISDN_MSNLEN
))
1549 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.plmsn
, ISDN_LMSNLEN
))
1553 return (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
) * ISDN_MAX_CHANNELS
;
1558 /* Set all Modem-Profiles */
1560 char __user
*p
= argp
;
1563 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1564 if (copy_from_user(dev
->mdm
.info
[i
].emu
.profile
, p
,
1567 p
+= ISDN_MODEM_NUMREG
;
1568 if (copy_from_user(dev
->mdm
.info
[i
].emu
.plmsn
, p
, ISDN_LMSNLEN
))
1571 if (copy_from_user(dev
->mdm
.info
[i
].emu
.pmsn
, p
, ISDN_MSNLEN
))
1581 /* Set/Get MSN->EAZ-Mapping for a driver */
1584 if (copy_from_user(&iocts
, argp
,
1585 sizeof(isdn_ioctl_struct
)))
1587 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1588 if (strlen(iocts
.drvid
)) {
1590 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1591 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1599 if (cmd
== IIOCSETMAP
) {
1602 p
= (char __user
*) iocts
.arg
;
1608 get_user(bname
[j
], p
++);
1615 strcpy(dev
->drv
[drvidx
]->msn2eaz
[i
], bname
);
1621 if (j
>= ISDN_MSNLEN
)
1628 p
= (char __user
*) iocts
.arg
;
1629 for (i
= 0; i
< 10; i
++) {
1630 snprintf(bname
, sizeof(bname
), "%s%s",
1631 strlen(dev
->drv
[drvidx
]->msn2eaz
[i
]) ?
1632 dev
->drv
[drvidx
]->msn2eaz
[i
] : "_",
1633 (i
< 9) ? "," : "\0");
1634 if (copy_to_user(p
, bname
, strlen(bname
) + 1))
1644 if (copy_to_user(argp
, &dev
, sizeof(ulong
)))
1651 if ((cmd
& IIOCDRVCTL
) == IIOCDRVCTL
)
1652 cmd
= ((cmd
>> _IOC_NRSHIFT
) & _IOC_NRMASK
) & ISDN_DRVIOCTL_MASK
;
1658 if (copy_from_user(&iocts
, argp
, sizeof(isdn_ioctl_struct
)))
1660 iocts
.drvid
[sizeof(iocts
.drvid
) - 1] = 0;
1661 if (strlen(iocts
.drvid
)) {
1662 if ((p
= strchr(iocts
.drvid
, ',')))
1665 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1666 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1675 c
.command
= ISDN_CMD_IOCTL
;
1677 memcpy(c
.parm
.num
, &iocts
.arg
, sizeof(ulong
));
1678 ret
= isdn_command(&c
);
1679 memcpy(&iocts
.arg
, c
.parm
.num
, sizeof(ulong
));
1680 if (copy_to_user(argp
, &iocts
, sizeof(isdn_ioctl_struct
)))
1687 #ifdef CONFIG_ISDN_PPP
1688 if (minor
<= ISDN_MINOR_PPPMAX
)
1689 return (isdn_ppp_ioctl(minor
- ISDN_MINOR_PPP
, file
, cmd
, arg
));
1701 isdn_unlocked_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1705 mutex_lock(&isdn_mutex
);
1706 ret
= isdn_ioctl(file
, cmd
, arg
);
1707 mutex_unlock(&isdn_mutex
);
1713 * Open the device code.
1716 isdn_open(struct inode
*ino
, struct file
*filep
)
1718 uint minor
= iminor(ino
);
1721 int retval
= -ENODEV
;
1723 mutex_lock(&isdn_mutex
);
1724 if (minor
== ISDN_MINOR_STATUS
) {
1727 if ((p
= kmalloc(sizeof(infostruct
), GFP_KERNEL
))) {
1728 p
->next
= (char *) dev
->infochain
;
1729 p
->private = (char *) &(filep
->private_data
);
1731 /* At opening we allow a single update */
1732 filep
->private_data
= (char *) 1;
1742 if (minor
<= ISDN_MINOR_BMAX
) {
1743 printk(KERN_WARNING
"isdn_open minor %d obsolete!\n", minor
);
1744 drvidx
= isdn_minor2drv(minor
);
1747 chidx
= isdn_minor2chan(minor
);
1748 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1750 if (!(dev
->drv
[drvidx
]->online
& (1 << chidx
)))
1752 isdn_lock_drivers();
1756 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1757 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1760 isdn_lock_drivers();
1764 #ifdef CONFIG_ISDN_PPP
1765 if (minor
<= ISDN_MINOR_PPPMAX
) {
1766 retval
= isdn_ppp_open(minor
- ISDN_MINOR_PPP
, filep
);
1768 isdn_lock_drivers();
1773 nonseekable_open(ino
, filep
);
1774 mutex_unlock(&isdn_mutex
);
1779 isdn_close(struct inode
*ino
, struct file
*filep
)
1781 uint minor
= iminor(ino
);
1783 mutex_lock(&isdn_mutex
);
1784 if (minor
== ISDN_MINOR_STATUS
) {
1785 infostruct
*p
= dev
->infochain
;
1786 infostruct
*q
= NULL
;
1789 if (p
->private == (char *) &(filep
->private_data
)) {
1793 dev
->infochain
= (infostruct
*) (p
->next
);
1798 p
= (infostruct
*) (p
->next
);
1800 printk(KERN_WARNING
"isdn: No private data while closing isdnctrl\n");
1803 isdn_unlock_drivers();
1804 if (minor
<= ISDN_MINOR_BMAX
)
1806 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1807 if (dev
->profd
== current
)
1811 #ifdef CONFIG_ISDN_PPP
1812 if (minor
<= ISDN_MINOR_PPPMAX
)
1813 isdn_ppp_release(minor
- ISDN_MINOR_PPP
, filep
);
1817 mutex_unlock(&isdn_mutex
);
1821 static const struct file_operations isdn_fops
=
1823 .owner
= THIS_MODULE
,
1824 .llseek
= no_llseek
,
1826 .write
= isdn_write
,
1828 .unlocked_ioctl
= isdn_unlocked_ioctl
,
1830 .release
= isdn_close
,
1834 isdn_map_eaz2msn(char *msn
, int di
)
1836 isdn_driver_t
*this = dev
->drv
[di
];
1839 if (strlen(msn
) == 1) {
1841 if ((i
>= 0) && (i
<= 9))
1842 if (strlen(this->msn2eaz
[i
]))
1843 return (this->msn2eaz
[i
]);
1849 * Find an unused ISDN-channel, whose feature-flags match the
1850 * given L2- and L3-protocols.
1852 #define L2V (~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038))
1855 * This function must be called with holding the dev->lock.
1858 isdn_get_free_channel(int usage
, int l2_proto
, int l3_proto
, int pre_dev
1859 , int pre_chan
, char *msn
)
1865 features
= ((1 << l2_proto
) | (0x10000 << l3_proto
));
1866 vfeatures
= (((1 << l2_proto
) | (0x10000 << l3_proto
)) &
1867 ~(ISDN_FEATURE_L2_V11096
| ISDN_FEATURE_L2_V11019
| ISDN_FEATURE_L2_V11038
));
1868 /* If Layer-2 protocol is V.110, accept drivers with
1869 * transparent feature even if these don't support V.110
1870 * because we can emulate this in linklevel.
1872 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1873 if (USG_NONE(dev
->usage
[i
]) &&
1874 (dev
->drvmap
[i
] != -1)) {
1875 int d
= dev
->drvmap
[i
];
1876 if ((dev
->usage
[i
] & ISDN_USAGE_EXCLUSIVE
) &&
1877 ((pre_dev
!= d
) || (pre_chan
!= dev
->chanmap
[i
])))
1879 if (!strcmp(isdn_map_eaz2msn(msn
, d
), "-"))
1881 if (dev
->usage
[i
] & ISDN_USAGE_DISABLED
)
1882 continue; /* usage not allowed */
1883 if (dev
->drv
[d
]->flags
& DRV_FLAG_RUNNING
) {
1884 if (((dev
->drv
[d
]->interface
->features
& features
) == features
) ||
1885 (((dev
->drv
[d
]->interface
->features
& vfeatures
) == vfeatures
) &&
1886 (dev
->drv
[d
]->interface
->features
& ISDN_FEATURE_L2_TRANS
))) {
1887 if ((pre_dev
< 0) || (pre_chan
< 0)) {
1888 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1889 dev
->usage
[i
] |= usage
;
1893 if ((pre_dev
== d
) && (pre_chan
== dev
->chanmap
[i
])) {
1894 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1895 dev
->usage
[i
] |= usage
;
1907 * Set state of ISDN-channel to 'unused'
1910 isdn_free_channel(int di
, int ch
, int usage
)
1914 if ((di
< 0) || (ch
< 0)) {
1915 printk(KERN_WARNING
"%s: called with invalid drv(%d) or channel(%d)\n",
1919 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1920 if (((!usage
) || ((dev
->usage
[i
] & ISDN_USAGE_MASK
) == usage
)) &&
1921 (dev
->drvmap
[i
] == di
) &&
1922 (dev
->chanmap
[i
] == ch
)) {
1923 dev
->usage
[i
] &= (ISDN_USAGE_NONE
| ISDN_USAGE_EXCLUSIVE
);
1924 strcpy(dev
->num
[i
], "???");
1927 // 20.10.99 JIM, try to reinitialize v110 !
1928 dev
->v110emu
[i
] = 0;
1929 atomic_set(&(dev
->v110use
[i
]), 0);
1930 isdn_v110_close(dev
->v110
[i
]);
1931 dev
->v110
[i
] = NULL
;
1932 // 20.10.99 JIM, try to reinitialize v110 !
1935 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[ch
]);
1940 * Cancel Exclusive-Flag for ISDN-channel
1943 isdn_unexclusive_channel(int di
, int ch
)
1947 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1948 if ((dev
->drvmap
[i
] == di
) &&
1949 (dev
->chanmap
[i
] == ch
)) {
1950 dev
->usage
[i
] &= ~ISDN_USAGE_EXCLUSIVE
;
1957 * writebuf replacement for SKB_ABLE drivers
1960 isdn_writebuf_stub(int drvidx
, int chan
, const u_char __user
*buf
, int len
)
1963 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1964 struct sk_buff
*skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1968 skb_reserve(skb
, hl
);
1969 if (copy_from_user(skb_put(skb
, len
), buf
, len
)) {
1973 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, 1, skb
);
1977 dev
->obytes
[isdn_dc2minor(drvidx
, chan
)] += ret
;
1982 * Return: length of data on success, -ERRcode on failure.
1985 isdn_writebuf_skb_stub(int drvidx
, int chan
, int ack
, struct sk_buff
*skb
)
1988 struct sk_buff
*nskb
= NULL
;
1989 int v110_ret
= skb
->len
;
1990 int idx
= isdn_dc2minor(drvidx
, chan
);
1992 if (dev
->v110
[idx
]) {
1993 atomic_inc(&dev
->v110use
[idx
]);
1994 nskb
= isdn_v110_encode(dev
->v110
[idx
], skb
);
1995 atomic_dec(&dev
->v110use
[idx
]);
1998 v110_ret
= *((int *)nskb
->data
);
1999 skb_pull(nskb
, sizeof(int));
2001 dev_kfree_skb(nskb
);
2004 /* V.110 must always be acknowledged */
2006 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, nskb
);
2008 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2010 if (skb_headroom(skb
) < hl
) {
2012 * This should only occur when new HL driver with
2013 * increased hl_hdrlen was loaded after netdevice
2014 * was created and connected to the new driver.
2016 * The V.110 branch (re-allocates on its own) does
2019 struct sk_buff
*skb_tmp
;
2021 skb_tmp
= skb_realloc_headroom(skb
, hl
);
2022 printk(KERN_DEBUG
"isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp
? "" : " failed");
2023 if (!skb_tmp
) return -ENOMEM
; /* 0 better? */
2024 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb_tmp
);
2028 dev_kfree_skb(skb_tmp
);
2031 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb
);
2035 dev
->obytes
[idx
] += ret
;
2036 if (dev
->v110
[idx
]) {
2037 atomic_inc(&dev
->v110use
[idx
]);
2038 dev
->v110
[idx
]->skbuser
++;
2039 atomic_dec(&dev
->v110use
[idx
]);
2040 /* For V.110 return unencoded data length */
2042 /* if the complete frame was send we free the skb;
2043 if not upper function will requeue the skb */
2044 if (ret
== skb
->len
)
2049 dev_kfree_skb(nskb
);
2054 isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
)
2058 init_waitqueue_head(&d
->st_waitq
);
2059 if (d
->flags
& DRV_FLAG_RUNNING
)
2061 if (n
< 1) return 0;
2063 m
= (adding
) ? d
->channels
+ n
: n
;
2065 if (dev
->channels
+ n
> ISDN_MAX_CHANNELS
) {
2066 printk(KERN_WARNING
"register_isdn: Max. %d channels supported\n",
2071 if ((adding
) && (d
->rcverr
))
2073 if (!(d
->rcverr
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2074 printk(KERN_WARNING
"register_isdn: Could not alloc rcverr\n");
2078 if ((adding
) && (d
->rcvcount
))
2080 if (!(d
->rcvcount
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2081 printk(KERN_WARNING
"register_isdn: Could not alloc rcvcount\n");
2087 if ((adding
) && (d
->rpqueue
)) {
2088 for (j
= 0; j
< d
->channels
; j
++)
2089 skb_queue_purge(&d
->rpqueue
[j
]);
2092 if (!(d
->rpqueue
= kmalloc(sizeof(struct sk_buff_head
) * m
, GFP_ATOMIC
))) {
2093 printk(KERN_WARNING
"register_isdn: Could not alloc rpqueue\n");
2100 for (j
= 0; j
< m
; j
++) {
2101 skb_queue_head_init(&d
->rpqueue
[j
]);
2104 if ((adding
) && (d
->rcv_waitq
))
2105 kfree(d
->rcv_waitq
);
2106 d
->rcv_waitq
= kmalloc(sizeof(wait_queue_head_t
) * 2 * m
, GFP_ATOMIC
);
2107 if (!d
->rcv_waitq
) {
2108 printk(KERN_WARNING
"register_isdn: Could not alloc rcv_waitq\n");
2116 d
->snd_waitq
= d
->rcv_waitq
+ m
;
2117 for (j
= 0; j
< m
; j
++) {
2118 init_waitqueue_head(&d
->rcv_waitq
[j
]);
2119 init_waitqueue_head(&d
->snd_waitq
[j
]);
2123 for (j
= d
->channels
; j
< m
; j
++)
2124 for (k
= 0; k
< ISDN_MAX_CHANNELS
; k
++)
2125 if (dev
->chanmap
[k
] < 0) {
2126 dev
->chanmap
[k
] = j
;
2127 dev
->drvmap
[k
] = drvidx
;
2135 * Low-level-driver registration
2139 set_global_features(void)
2143 dev
->global_features
= 0;
2144 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++) {
2145 if (!dev
->drv
[drvidx
])
2147 if (dev
->drv
[drvidx
]->interface
)
2148 dev
->global_features
|= dev
->drv
[drvidx
]->interface
->features
;
2152 #ifdef CONFIG_ISDN_DIVERSION
2154 static char *map_drvname(int di
)
2156 if ((di
< 0) || (di
>= ISDN_MAX_DRIVERS
))
2158 return (dev
->drvid
[di
]); /* driver name */
2161 static int map_namedrv(char *id
)
2164 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2165 { if (!strcmp(dev
->drvid
[i
], id
))
2171 int DIVERT_REG_NAME(isdn_divert_if
*i_div
)
2173 if (i_div
->if_magic
!= DIVERT_IF_MAGIC
)
2174 return (DIVERT_VER_ERR
);
2177 case DIVERT_CMD_REL
:
2178 if (divert_if
!= i_div
)
2179 return (DIVERT_REL_ERR
);
2180 divert_if
= NULL
; /* free interface */
2181 return (DIVERT_NO_ERR
);
2183 case DIVERT_CMD_REG
:
2185 return (DIVERT_REG_ERR
);
2186 i_div
->ll_cmd
= isdn_command
; /* set command function */
2187 i_div
->drv_to_name
= map_drvname
;
2188 i_div
->name_to_drv
= map_namedrv
;
2189 divert_if
= i_div
; /* remember interface */
2190 return (DIVERT_NO_ERR
);
2193 return (DIVERT_CMD_ERR
);
2195 } /* DIVERT_REG_NAME */
2197 EXPORT_SYMBOL(DIVERT_REG_NAME
);
2199 #endif /* CONFIG_ISDN_DIVERSION */
2202 EXPORT_SYMBOL(register_isdn
);
2203 #ifdef CONFIG_ISDN_PPP
2204 EXPORT_SYMBOL(isdn_ppp_register_compressor
);
2205 EXPORT_SYMBOL(isdn_ppp_unregister_compressor
);
2209 register_isdn(isdn_if
*i
)
2216 if (dev
->drivers
>= ISDN_MAX_DRIVERS
) {
2217 printk(KERN_WARNING
"register_isdn: Max. %d drivers supported\n",
2221 if (!i
->writebuf_skb
) {
2222 printk(KERN_WARNING
"register_isdn: No write routine given.\n");
2225 if (!(d
= kzalloc(sizeof(isdn_driver_t
), GFP_KERNEL
))) {
2226 printk(KERN_WARNING
"register_isdn: Could not alloc driver-struct\n");
2230 d
->maxbufsize
= i
->maxbufsize
;
2233 d
->flags
= DRV_FLAG_LOADED
;
2237 spin_lock_irqsave(&dev
->lock
, flags
);
2238 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2239 if (!dev
->drv
[drvidx
])
2241 if (isdn_add_channels(d
, drvidx
, i
->channels
, 0)) {
2242 spin_unlock_irqrestore(&dev
->lock
, flags
);
2246 i
->channels
= drvidx
;
2247 i
->rcvcallb_skb
= isdn_receive_skb_callback
;
2248 i
->statcallb
= isdn_status_callback
;
2250 sprintf(i
->id
, "line%d", drvidx
);
2251 for (j
= 0; j
< drvidx
; j
++)
2252 if (!strcmp(i
->id
, dev
->drvid
[j
]))
2253 sprintf(i
->id
, "line%d", drvidx
);
2254 dev
->drv
[drvidx
] = d
;
2255 strcpy(dev
->drvid
[drvidx
], i
->id
);
2258 set_global_features();
2259 spin_unlock_irqrestore(&dev
->lock
, flags
);
2264 *****************************************************************************
2265 * And now the modules code.
2266 *****************************************************************************
2270 isdn_getrev(const char *revision
)
2275 if ((p
= strchr(revision
, ':'))) {
2277 p
= strchr(rev
, '$');
2285 * Allocate and initialize all data, register modem-devices
2287 static int __init
isdn_init(void)
2292 dev
= vzalloc(sizeof(isdn_dev
));
2294 printk(KERN_WARNING
"isdn: Could not allocate device-struct.\n");
2297 timer_setup(&dev
->timer
, isdn_timer_funct
, 0);
2298 spin_lock_init(&dev
->lock
);
2299 spin_lock_init(&dev
->timerlock
);
2301 dev
->owner
= THIS_MODULE
;
2303 mutex_init(&dev
->mtx
);
2304 init_waitqueue_head(&dev
->info_waitq
);
2305 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2306 dev
->drvmap
[i
] = -1;
2307 dev
->chanmap
[i
] = -1;
2309 strcpy(dev
->num
[i
], "???");
2311 if (register_chrdev(ISDN_MAJOR
, "isdn", &isdn_fops
)) {
2312 printk(KERN_WARNING
"isdn: Could not register control devices\n");
2316 if ((isdn_tty_modem_init()) < 0) {
2317 printk(KERN_WARNING
"isdn: Could not register tty devices\n");
2319 unregister_chrdev(ISDN_MAJOR
, "isdn");
2322 #ifdef CONFIG_ISDN_PPP
2323 if (isdn_ppp_init() < 0) {
2324 printk(KERN_WARNING
"isdn: Could not create PPP-device-structs\n");
2326 unregister_chrdev(ISDN_MAJOR
, "isdn");
2330 #endif /* CONFIG_ISDN_PPP */
2332 strcpy(tmprev
, isdn_revision
);
2333 printk(KERN_NOTICE
"ISDN subsystem Rev: %s/", isdn_getrev(tmprev
));
2334 strcpy(tmprev
, isdn_net_revision
);
2335 printk("%s/", isdn_getrev(tmprev
));
2336 strcpy(tmprev
, isdn_ppp_revision
);
2337 printk("%s/", isdn_getrev(tmprev
));
2338 strcpy(tmprev
, isdn_audio_revision
);
2339 printk("%s/", isdn_getrev(tmprev
));
2340 strcpy(tmprev
, isdn_v110_revision
);
2341 printk("%s", isdn_getrev(tmprev
));
2344 printk(" loaded\n");
2355 static void __exit
isdn_exit(void)
2357 #ifdef CONFIG_ISDN_PPP
2360 if (isdn_net_rmall() < 0) {
2361 printk(KERN_WARNING
"isdn: net-device busy, remove cancelled\n");
2365 unregister_chrdev(ISDN_MAJOR
, "isdn");
2366 del_timer_sync(&dev
->timer
);
2367 /* call vfree with interrupts enabled, else it will hang */
2369 printk(KERN_NOTICE
"ISDN-subsystem unloaded\n");
2372 module_init(isdn_init
);
2373 module_exit(isdn_exit
);