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 extern char *isdn_tty_revision
;
50 #ifdef CONFIG_ISDN_PPP
51 extern char *isdn_ppp_revision
;
53 static char *isdn_ppp_revision
= ": none $";
55 #ifdef CONFIG_ISDN_AUDIO
56 extern char *isdn_audio_revision
;
58 static char *isdn_audio_revision
= ": none $";
60 extern char *isdn_v110_revision
;
62 #ifdef CONFIG_ISDN_DIVERSION
63 static isdn_divert_if
*divert_if
; /* = NULL */
64 #endif /* CONFIG_ISDN_DIVERSION */
67 static int isdn_writebuf_stub(int, int, const u_char __user
*, int);
68 static void set_global_features(void);
69 static int isdn_wildmat(char *s
, char *p
);
70 static int isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
);
73 isdn_lock_driver(isdn_driver_t
*drv
)
75 try_module_get(drv
->interface
->owner
);
80 isdn_lock_drivers(void)
84 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
87 isdn_lock_driver(dev
->drv
[i
]);
92 isdn_unlock_driver(isdn_driver_t
*drv
)
96 module_put(drv
->interface
->owner
);
101 isdn_unlock_drivers(void)
105 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
108 isdn_unlock_driver(dev
->drv
[i
]);
112 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
114 isdn_dumppkt(char *s
, u_char
* p
, int len
, int dumplen
)
118 printk(KERN_DEBUG
"%s(%d) ", s
, len
);
119 for (dumpc
= 0; (dumpc
< dumplen
) && (len
); len
--, dumpc
++)
120 printk(" %02x", *p
++);
126 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
127 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
130 isdn_star(char *s
, char *p
)
132 while (isdn_wildmat(s
, p
)) {
140 * Shell-type Pattern-matching for incoming caller-Ids
141 * This function gets a string in s and checks, if it matches the pattern
147 * 2 = no match. Would eventually match, if s would be longer.
151 * '?' matches one character
152 * '*' matches zero or more characters
153 * [xyz] matches the set of characters in brackets.
154 * [^xyz] matches any single character not in the set of characters
158 isdn_wildmat(char *s
, char *p
)
161 register int matched
;
162 register int reverse
;
163 register int nostar
= 1;
171 * Literal match with following character,
177 return (*s
== '\0')?2:1;
180 /* Match anything. */
186 /* Trailing star matches everything. */
187 return (*++p
? isdn_star(s
, p
) : 0);
189 /* [^....] means inverse character class. */
190 if ((reverse
= (p
[1] == '^')))
192 for (last
= 0, matched
= 0; *++p
&& (*p
!= ']'); last
= *p
)
193 /* This next line requires a good C compiler. */
194 if (*p
== '-' ? *s
<= *++p
&& *s
>= last
: *s
== *p
)
196 if (matched
== reverse
)
200 return (*s
== '\0')?0:nostar
;
203 int isdn_msncmp( const char * msn1
, const char * msn2
)
205 char TmpMsn1
[ ISDN_MSNLEN
];
206 char TmpMsn2
[ ISDN_MSNLEN
];
209 for ( p
= TmpMsn1
; *msn1
&& *msn1
!= ':'; ) // Strip off a SPID
213 for ( p
= TmpMsn2
; *msn2
&& *msn2
!= ':'; ) // Strip off a SPID
217 return isdn_wildmat( TmpMsn1
, TmpMsn2
);
221 isdn_dc2minor(int di
, int ch
)
224 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
225 if (dev
->chanmap
[i
] == ch
&& dev
->drvmap
[i
] == di
)
230 static int isdn_timer_cnt1
= 0;
231 static int isdn_timer_cnt2
= 0;
232 static int isdn_timer_cnt3
= 0;
235 isdn_timer_funct(ulong dummy
)
237 int tf
= dev
->tflags
;
238 if (tf
& ISDN_TIMER_FAST
) {
239 if (tf
& ISDN_TIMER_MODEMREAD
)
240 isdn_tty_readmodem();
241 if (tf
& ISDN_TIMER_MODEMPLUS
)
242 isdn_tty_modem_escape();
243 if (tf
& ISDN_TIMER_MODEMXMIT
)
244 isdn_tty_modem_xmit();
246 if (tf
& ISDN_TIMER_SLOW
) {
247 if (++isdn_timer_cnt1
>= ISDN_TIMER_02SEC
) {
249 if (tf
& ISDN_TIMER_NETDIAL
)
252 if (++isdn_timer_cnt2
>= ISDN_TIMER_1SEC
) {
254 if (tf
& ISDN_TIMER_NETHANGUP
)
256 if (++isdn_timer_cnt3
>= ISDN_TIMER_RINGING
) {
258 if (tf
& ISDN_TIMER_MODEMRING
)
259 isdn_tty_modem_ring();
261 if (tf
& ISDN_TIMER_CARRIER
)
262 isdn_tty_carrier_timeout();
266 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
270 isdn_timer_ctrl(int tf
, int onoff
)
275 spin_lock_irqsave(&dev
->timerlock
, flags
);
276 if ((tf
& ISDN_TIMER_SLOW
) && (!(dev
->tflags
& ISDN_TIMER_SLOW
))) {
277 /* If the slow-timer wasn't activated until now */
281 old_tflags
= dev
->tflags
;
286 if (dev
->tflags
&& !old_tflags
)
287 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
288 spin_unlock_irqrestore(&dev
->timerlock
, flags
);
292 * Receive a packet from B-Channel. (Called from low-level-module)
295 isdn_receive_skb_callback(int di
, int channel
, struct sk_buff
*skb
)
299 if ((i
= isdn_dc2minor(di
, channel
)) == -1) {
303 /* Update statistics */
304 dev
->ibytes
[i
] += skb
->len
;
306 /* First, try to deliver data to network-device */
307 if (isdn_net_rcv_skb(i
, skb
))
311 * makes sense for async streams only, so it is
312 * called after possible net-device delivery.
315 atomic_inc(&dev
->v110use
[i
]);
316 skb
= isdn_v110_decode(dev
->v110
[i
], skb
);
317 atomic_dec(&dev
->v110use
[i
]);
322 /* No network-device found, deliver to tty or raw-channel */
324 if (isdn_tty_rcv_skb(i
, di
, channel
, skb
))
326 wake_up_interruptible(&dev
->drv
[di
]->rcv_waitq
[channel
]);
332 * Intercept command from Linklevel to Lowlevel.
333 * If layer 2 protocol is V.110 and this is not supported by current
334 * lowlevel-driver, use driver's transparent mode and handle V.110 in
338 isdn_command(isdn_ctrl
*cmd
)
340 if (cmd
->driver
== -1) {
341 printk(KERN_WARNING
"isdn_command command(%x) driver -1\n", cmd
->command
);
344 if (!dev
->drv
[cmd
->driver
]) {
345 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d] NULL\n",
346 cmd
->command
, cmd
->driver
);
349 if (!dev
->drv
[cmd
->driver
]->interface
) {
350 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d]->interface NULL\n",
351 cmd
->command
, cmd
->driver
);
354 if (cmd
->command
== ISDN_CMD_SETL2
) {
355 int idx
= isdn_dc2minor(cmd
->driver
, cmd
->arg
& 255);
356 unsigned long l2prot
= (cmd
->arg
>> 8) & 255;
357 unsigned long features
= (dev
->drv
[cmd
->driver
]->interface
->features
358 >> ISDN_FEATURE_L2_SHIFT
) &
359 ISDN_FEATURE_L2_MASK
;
360 unsigned long l2_feature
= (1 << l2prot
);
363 case ISDN_PROTO_L2_V11096
:
364 case ISDN_PROTO_L2_V11019
:
365 case ISDN_PROTO_L2_V11038
:
366 /* If V.110 requested, but not supported by
367 * HL-driver, set emulator-flag and change
368 * Layer-2 to transparent
370 if (!(features
& l2_feature
)) {
371 dev
->v110emu
[idx
] = l2prot
;
372 cmd
->arg
= (cmd
->arg
& 255) |
373 (ISDN_PROTO_L2_TRANS
<< 8);
375 dev
->v110emu
[idx
] = 0;
378 return dev
->drv
[cmd
->driver
]->interface
->command(cmd
);
382 isdn_all_eaz(int di
, int ch
)
390 cmd
.command
= ISDN_CMD_SETEAZ
;
391 cmd
.parm
.num
[0] = '\0';
396 * Begin of a CAPI like LL<->HL interface, currently used only for
397 * supplementary service (CAPI 2.0 part III)
399 #include <linux/isdn/capicmd.h>
402 isdn_capi_rec_hl_msg(capi_msg
*cm
)
404 switch(cm
->Command
) {
406 /* in the moment only handled in tty */
407 return(isdn_tty_capi_facility(cm
));
414 isdn_status_callback(isdn_ctrl
* c
)
425 i
= isdn_dc2minor(di
, c
->arg
);
426 switch (c
->command
) {
427 case ISDN_STAT_BSENT
:
430 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
432 if (isdn_net_stat_callback(i
, c
))
434 if (isdn_v110_stat_callback(i
, c
))
436 if (isdn_tty_stat_callback(i
, c
))
438 wake_up_interruptible(&dev
->drv
[di
]->snd_waitq
[c
->arg
]);
440 case ISDN_STAT_STAVAIL
:
441 dev
->drv
[di
]->stavail
+= c
->arg
;
442 wake_up_interruptible(&dev
->drv
[di
]->st_waitq
);
445 dev
->drv
[di
]->flags
|= DRV_FLAG_RUNNING
;
446 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
447 if (dev
->drvmap
[i
] == di
)
448 isdn_all_eaz(di
, dev
->chanmap
[i
]);
449 set_global_features();
452 dev
->drv
[di
]->flags
&= ~DRV_FLAG_RUNNING
;
454 case ISDN_STAT_ICALL
:
457 #ifdef ISDN_DEBUG_STATCALLB
458 printk(KERN_DEBUG
"ICALL (net): %d %ld %s\n", di
, c
->arg
, c
->parm
.num
);
460 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) {
463 cmd
.command
= ISDN_CMD_HANGUP
;
467 /* Try to find a network-interface which will accept incoming call */
468 r
= ((c
->command
== ISDN_STAT_ICALLW
) ? 0 : isdn_net_find_icall(di
, c
->arg
, i
, &c
->parm
.setup
));
471 /* No network-device replies.
473 * These return 0 on no match, 1 on match and
474 * 3 on eventually match, if CID is longer.
476 if (c
->command
== ISDN_STAT_ICALL
)
477 if ((retval
= isdn_tty_find_icall(di
, c
->arg
, &c
->parm
.setup
))) return(retval
);
478 #ifdef CONFIG_ISDN_DIVERSION
480 if ((retval
= divert_if
->stat_callback(c
)))
481 return(retval
); /* processed */
482 #endif /* CONFIG_ISDN_DIVERSION */
483 if ((!retval
) && (dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
)) {
484 /* No tty responding */
487 cmd
.command
= ISDN_CMD_HANGUP
;
493 /* Schedule connection-setup */
497 cmd
.command
= ISDN_CMD_ACCEPTD
;
498 for ( p
= dev
->netdev
; p
; p
= p
->next
)
499 if ( p
->local
->isdn_channel
== cmd
.arg
)
501 strcpy( cmd
.parm
.setup
.eazmsn
, p
->local
->msn
);
508 case 2: /* For calling back, first reject incoming call ... */
509 case 3: /* Interface found, but down, reject call actively */
511 printk(KERN_INFO
"isdn: Rejecting Call\n");
514 cmd
.command
= ISDN_CMD_HANGUP
;
520 /* ... then start callback. */
524 /* Number would eventually match, if longer */
528 #ifdef ISDN_DEBUG_STATCALLB
529 printk(KERN_DEBUG
"ICALL: ret=%d\n", retval
);
536 #ifdef ISDN_DEBUG_STATCALLB
537 printk(KERN_DEBUG
"CINF: %ld %s\n", c
->arg
, c
->parm
.num
);
539 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
541 if (strcmp(c
->parm
.num
, "0"))
542 isdn_net_stat_callback(i
, c
);
543 isdn_tty_stat_callback(i
, c
);
545 case ISDN_STAT_CAUSE
:
546 #ifdef ISDN_DEBUG_STATCALLB
547 printk(KERN_DEBUG
"CAUSE: %ld %s\n", c
->arg
, c
->parm
.num
);
549 printk(KERN_INFO
"isdn: %s,ch%ld cause: %s\n",
550 dev
->drvid
[di
], c
->arg
, c
->parm
.num
);
551 isdn_tty_stat_callback(i
, c
);
552 #ifdef CONFIG_ISDN_DIVERSION
554 divert_if
->stat_callback(c
);
555 #endif /* CONFIG_ISDN_DIVERSION */
557 case ISDN_STAT_DISPLAY
:
558 #ifdef ISDN_DEBUG_STATCALLB
559 printk(KERN_DEBUG
"DISPLAY: %ld %s\n", c
->arg
, c
->parm
.display
);
561 isdn_tty_stat_callback(i
, c
);
562 #ifdef CONFIG_ISDN_DIVERSION
564 divert_if
->stat_callback(c
);
565 #endif /* CONFIG_ISDN_DIVERSION */
567 case ISDN_STAT_DCONN
:
570 #ifdef ISDN_DEBUG_STATCALLB
571 printk(KERN_DEBUG
"DCONN: %ld\n", c
->arg
);
573 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
575 /* Find any net-device, waiting for D-channel setup */
576 if (isdn_net_stat_callback(i
, c
))
578 isdn_v110_stat_callback(i
, c
);
579 /* Find any ttyI, waiting for D-channel setup */
580 if (isdn_tty_stat_callback(i
, c
)) {
583 cmd
.command
= ISDN_CMD_ACCEPTB
;
591 #ifdef ISDN_DEBUG_STATCALLB
592 printk(KERN_DEBUG
"DHUP: %ld\n", c
->arg
);
594 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
596 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
598 /* Signal hangup to network-devices */
599 if (isdn_net_stat_callback(i
, c
))
601 isdn_v110_stat_callback(i
, c
);
602 if (isdn_tty_stat_callback(i
, c
))
604 #ifdef CONFIG_ISDN_DIVERSION
606 divert_if
->stat_callback(c
);
607 #endif /* CONFIG_ISDN_DIVERSION */
610 case ISDN_STAT_BCONN
:
613 #ifdef ISDN_DEBUG_STATCALLB
614 printk(KERN_DEBUG
"BCONN: %ld\n", c
->arg
);
616 /* Signal B-channel-connect to network-devices */
617 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
619 dev
->drv
[di
]->online
|= (1 << (c
->arg
));
621 if (isdn_net_stat_callback(i
, c
))
623 isdn_v110_stat_callback(i
, c
);
624 if (isdn_tty_stat_callback(i
, c
))
630 #ifdef ISDN_DEBUG_STATCALLB
631 printk(KERN_DEBUG
"BHUP: %ld\n", c
->arg
);
633 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
635 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
637 #ifdef CONFIG_ISDN_X25
638 /* Signal hangup to network-devices */
639 if (isdn_net_stat_callback(i
, c
))
642 isdn_v110_stat_callback(i
, c
);
643 if (isdn_tty_stat_callback(i
, c
))
646 case ISDN_STAT_NODCH
:
649 #ifdef ISDN_DEBUG_STATCALLB
650 printk(KERN_DEBUG
"NODCH: %ld\n", c
->arg
);
652 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
654 if (isdn_net_stat_callback(i
, c
))
656 if (isdn_tty_stat_callback(i
, c
))
659 case ISDN_STAT_ADDCH
:
660 spin_lock_irqsave(&dev
->lock
, flags
);
661 if (isdn_add_channels(dev
->drv
[di
], di
, c
->arg
, 1)) {
662 spin_unlock_irqrestore(&dev
->lock
, flags
);
665 spin_unlock_irqrestore(&dev
->lock
, flags
);
668 case ISDN_STAT_DISCH
:
669 spin_lock_irqsave(&dev
->lock
, flags
);
670 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
671 if ((dev
->drvmap
[i
] == di
) &&
672 (dev
->chanmap
[i
] == c
->arg
)) {
674 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
676 if (USG_NONE(dev
->usage
[i
])) {
677 dev
->usage
[i
] |= ISDN_USAGE_DISABLED
;
683 spin_unlock_irqrestore(&dev
->lock
, flags
);
686 case ISDN_STAT_UNLOAD
:
687 while (dev
->drv
[di
]->locks
> 0) {
688 isdn_unlock_driver(dev
->drv
[di
]);
690 spin_lock_irqsave(&dev
->lock
, flags
);
691 isdn_tty_stat_callback(i
, c
);
692 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
693 if (dev
->drvmap
[i
] == di
) {
695 dev
->chanmap
[i
] = -1;
696 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
699 dev
->channels
-= dev
->drv
[di
]->channels
;
700 kfree(dev
->drv
[di
]->rcverr
);
701 kfree(dev
->drv
[di
]->rcvcount
);
702 for (i
= 0; i
< dev
->drv
[di
]->channels
; i
++)
703 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[i
]);
704 kfree(dev
->drv
[di
]->rpqueue
);
705 kfree(dev
->drv
[di
]->rcv_waitq
);
708 dev
->drvid
[di
][0] = '\0';
710 set_global_features();
711 spin_unlock_irqrestore(&dev
->lock
, flags
);
713 case ISDN_STAT_L1ERR
:
715 case CAPI_PUT_MESSAGE
:
716 return(isdn_capi_rec_hl_msg(&c
->parm
.cmsg
));
717 #ifdef CONFIG_ISDN_TTY_FAX
718 case ISDN_STAT_FAXIND
:
719 isdn_tty_stat_callback(i
, c
);
722 #ifdef CONFIG_ISDN_AUDIO
723 case ISDN_STAT_AUDIO
:
724 isdn_tty_stat_callback(i
, c
);
727 #ifdef CONFIG_ISDN_DIVERSION
729 case ISDN_STAT_REDIR
:
731 return(divert_if
->stat_callback(c
));
732 #endif /* CONFIG_ISDN_DIVERSION */
740 * Get integer from char-pointer, set pointer to end of number
743 isdn_getnum(char **p
)
747 while (*p
[0] >= '0' && *p
[0] <= '9')
748 v
= ((v
< 0) ? 0 : (v
* 10)) + (int) ((*p
[0]++) - '0');
755 * isdn_readbchan() tries to get data from the read-queue.
756 * It MUST be called with interrupts off.
758 * Be aware that this is not an atomic operation when sleep != 0, even though
759 * interrupts are turned off! Well, like that we are currently only called
760 * on behalf of a read system call on raw device files (which are documented
761 * to be dangerous and for debugging purpose only). The inode semaphore
762 * takes care that this is not called for the same minor device number while
763 * we are sleeping, but access is not serialized against simultaneous read()
764 * from the corresponding ttyI device. Can other ugly events, like changes
765 * of the mapping (di,ch)<->minor, happen during the sleep? --he
768 isdn_readbchan(int di
, int channel
, u_char
* buf
, u_char
* fp
, int len
, wait_queue_head_t
*sleep
)
779 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
])) {
781 interruptible_sleep_on(sleep
);
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_struct
*tty
, int cisco_hack
)
892 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
895 len
= tty_buffer_request_room(tty
, 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(tty
, 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(tty
, 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(tty
, last
, 0xFF);
958 tty_insert_flip_char(tty
, 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(tty
, 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
->f_path
.dentry
->d_inode
);
1069 mutex_lock(&isdn_mutex
);
1070 if (minor
== ISDN_MINOR_STATUS
) {
1071 if (!file
->private_data
) {
1072 if (file
->f_flags
& O_NONBLOCK
) {
1076 interruptible_sleep_on(&(dev
->info_waitq
));
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 interruptible_sleep_on(&(dev
->drv
[drvidx
]->st_waitq
));
1134 if (dev
->drv
[drvidx
]->interface
->readstat
) {
1135 if (count
> dev
->drv
[drvidx
]->stavail
)
1136 count
= dev
->drv
[drvidx
]->stavail
;
1137 len
= dev
->drv
[drvidx
]->interface
->readstat(buf
, count
,
1138 drvidx
, isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1147 dev
->drv
[drvidx
]->stavail
-= len
;
1149 dev
->drv
[drvidx
]->stavail
= 0;
1154 #ifdef CONFIG_ISDN_PPP
1155 if (minor
<= ISDN_MINOR_PPPMAX
) {
1156 retval
= isdn_ppp_read(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1162 mutex_unlock(&isdn_mutex
);
1167 isdn_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
* off
)
1169 uint minor
= iminor(file
->f_path
.dentry
->d_inode
);
1174 if (minor
== ISDN_MINOR_STATUS
)
1179 mutex_lock(&isdn_mutex
);
1180 if (minor
<= ISDN_MINOR_BMAX
) {
1181 printk(KERN_WARNING
"isdn_write minor %d obsolete!\n", minor
);
1182 drvidx
= isdn_minor2drv(minor
);
1187 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1191 chidx
= isdn_minor2chan(minor
);
1192 while ((retval
= isdn_writebuf_stub(drvidx
, chidx
, buf
, count
)) == 0)
1193 interruptible_sleep_on(&dev
->drv
[drvidx
]->snd_waitq
[chidx
]);
1196 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1197 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1203 * We want to use the isdnctrl device to load the firmware
1205 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1208 if (dev
->drv
[drvidx
]->interface
->writecmd
)
1209 retval
= dev
->drv
[drvidx
]->interface
->
1210 writecmd(buf
, count
, drvidx
,
1211 isdn_minor2chan(minor
- ISDN_MINOR_CTRL
));
1216 #ifdef CONFIG_ISDN_PPP
1217 if (minor
<= ISDN_MINOR_PPPMAX
) {
1218 retval
= isdn_ppp_write(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1224 mutex_unlock(&isdn_mutex
);
1229 isdn_poll(struct file
*file
, poll_table
* wait
)
1231 unsigned int mask
= 0;
1232 unsigned int minor
= iminor(file
->f_path
.dentry
->d_inode
);
1233 int drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1235 mutex_lock(&isdn_mutex
);
1236 if (minor
== ISDN_MINOR_STATUS
) {
1237 poll_wait(file
, &(dev
->info_waitq
), wait
);
1238 /* mask = POLLOUT | POLLWRNORM; */
1239 if (file
->private_data
) {
1240 mask
|= POLLIN
| POLLRDNORM
;
1244 if (minor
>= ISDN_MINOR_CTRL
&& minor
<= ISDN_MINOR_CTRLMAX
) {
1246 /* driver deregistered while file open */
1250 poll_wait(file
, &(dev
->drv
[drvidx
]->st_waitq
), wait
);
1251 mask
= POLLOUT
| POLLWRNORM
;
1252 if (dev
->drv
[drvidx
]->stavail
) {
1253 mask
|= POLLIN
| POLLRDNORM
;
1257 #ifdef CONFIG_ISDN_PPP
1258 if (minor
<= ISDN_MINOR_PPPMAX
) {
1259 mask
= isdn_ppp_poll(file
, wait
);
1265 mutex_unlock(&isdn_mutex
);
1271 isdn_ioctl(struct file
*file
, uint cmd
, ulong arg
)
1273 uint minor
= iminor(file
->f_path
.dentry
->d_inode
);
1283 isdn_ioctl_struct iocts
;
1284 isdn_net_ioctl_phone phone
;
1285 isdn_net_ioctl_cfg cfg
;
1287 void __user
*argp
= (void __user
*)arg
;
1289 #define name iocpar.name
1290 #define bname iocpar.bname
1291 #define iocts iocpar.iocts
1292 #define phone iocpar.phone
1293 #define cfg iocpar.cfg
1295 if (minor
== ISDN_MINOR_STATUS
) {
1303 ulong __user
*p
= argp
;
1305 if (!access_ok(VERIFY_WRITE
, p
,
1306 sizeof(ulong
) * ISDN_MAX_CHANNELS
* 2))
1308 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1309 put_user(dev
->ibytes
[i
], p
++);
1310 put_user(dev
->obytes
[i
], p
++);
1316 #ifdef CONFIG_NETDEVICES
1318 /* Get peer phone number of a connected
1319 * isdn network interface */
1321 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1323 return isdn_net_getpeer(&phone
, argp
);
1333 if (minor
<= ISDN_MINOR_BMAX
) {
1334 drvidx
= isdn_minor2drv(minor
);
1337 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1341 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1343 * isdn net devices manage lots of configuration variables as linked lists.
1344 * Those lists must only be manipulated from user space. Some of the ioctl's
1345 * service routines access user space and are not atomic. Therefore, ioctl's
1346 * manipulating the lists and ioctl's sleeping while accessing the lists
1347 * are serialized by means of a semaphore.
1351 printk(KERN_INFO
"INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1354 printk(KERN_INFO
"INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1356 #ifdef CONFIG_NETDEVICES
1358 /* Add a network-interface */
1360 if (copy_from_user(name
, argp
, sizeof(name
)))
1366 ret
= mutex_lock_interruptible(&dev
->mtx
);
1367 if( ret
) return ret
;
1368 if ((s
= isdn_net_new(s
, NULL
))) {
1369 if (copy_to_user(argp
, s
, strlen(s
) + 1)){
1376 mutex_unlock(&dev
->mtx
);
1379 /* Add a slave to a network-interface */
1381 if (copy_from_user(bname
, argp
, sizeof(bname
) - 1))
1385 ret
= mutex_lock_interruptible(&dev
->mtx
);
1386 if( ret
) return ret
;
1387 if ((s
= isdn_net_newslave(bname
))) {
1388 if (copy_to_user(argp
, s
, strlen(s
) + 1)){
1395 mutex_unlock(&dev
->mtx
);
1398 /* Delete a network-interface */
1400 if (copy_from_user(name
, argp
, sizeof(name
)))
1402 ret
= mutex_lock_interruptible(&dev
->mtx
);
1403 if( ret
) return ret
;
1404 ret
= isdn_net_rm(name
);
1405 mutex_unlock(&dev
->mtx
);
1410 /* Set configurable parameters of a network-interface */
1412 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1414 return isdn_net_setcfg(&cfg
);
1418 /* Get configurable parameters of a network-interface */
1420 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1422 if (!(ret
= isdn_net_getcfg(&cfg
))) {
1423 if (copy_to_user(argp
, &cfg
, sizeof(cfg
)))
1430 /* Add a phone-number to a network-interface */
1432 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1434 ret
= mutex_lock_interruptible(&dev
->mtx
);
1435 if( ret
) return ret
;
1436 ret
= isdn_net_addphone(&phone
);
1437 mutex_unlock(&dev
->mtx
);
1442 /* Get list of phone-numbers of a network-interface */
1444 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1446 ret
= mutex_lock_interruptible(&dev
->mtx
);
1447 if( ret
) return ret
;
1448 ret
= isdn_net_getphones(&phone
, argp
);
1449 mutex_unlock(&dev
->mtx
);
1454 /* Delete a phone-number of a network-interface */
1456 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1458 ret
= mutex_lock_interruptible(&dev
->mtx
);
1459 if( ret
) return ret
;
1460 ret
= isdn_net_delphone(&phone
);
1461 mutex_unlock(&dev
->mtx
);
1466 /* Force dialing of a network-interface */
1468 if (copy_from_user(name
, argp
, sizeof(name
)))
1470 return isdn_net_force_dial(name
);
1473 #ifdef CONFIG_ISDN_PPP
1477 if (copy_from_user(name
, argp
, sizeof(name
)))
1479 return isdn_ppp_dial_slave(name
);
1483 if (copy_from_user(name
, argp
, sizeof(name
)))
1485 return isdn_ppp_hangup_slave(name
);
1488 /* Force hangup of a network-interface */
1491 if (copy_from_user(name
, argp
, sizeof(name
)))
1493 return isdn_net_force_hangup(name
);
1495 #endif /* CONFIG_NETDEVICES */
1497 dev
->net_verbose
= arg
;
1498 printk(KERN_INFO
"isdn: Verbose-Level is %d\n", dev
->net_verbose
);
1502 dev
->global_flags
|= ISDN_GLOBAL_STOPPED
;
1504 dev
->global_flags
&= ~ISDN_GLOBAL_STOPPED
;
1505 printk(KERN_INFO
"isdn: Global Mode %s\n",
1506 (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) ? "stopped" : "running");
1513 if (copy_from_user(&iocts
, argp
,
1514 sizeof(isdn_ioctl_struct
)))
1516 iocts
.drvid
[sizeof(iocts
.drvid
)-1] = 0;
1517 if (strlen(iocts
.drvid
)) {
1518 if ((p
= strchr(iocts
.drvid
, ',')))
1521 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1522 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1531 dev
->drv
[drvidx
]->flags
|= DRV_FLAG_REJBUS
;
1533 dev
->drv
[drvidx
]->flags
&= ~DRV_FLAG_REJBUS
;
1536 dev
->profd
= current
;
1540 /* Get all Modem-Profiles */
1542 char __user
*p
= argp
;
1545 if (!access_ok(VERIFY_WRITE
, argp
,
1546 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
)
1547 * ISDN_MAX_CHANNELS
))
1550 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1551 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.profile
,
1554 p
+= ISDN_MODEM_NUMREG
;
1555 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.pmsn
, ISDN_MSNLEN
))
1558 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.plmsn
, ISDN_LMSNLEN
))
1562 return (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
) * ISDN_MAX_CHANNELS
;
1567 /* Set all Modem-Profiles */
1569 char __user
*p
= argp
;
1572 if (!access_ok(VERIFY_READ
, argp
,
1573 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
)
1574 * ISDN_MAX_CHANNELS
))
1577 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1578 if (copy_from_user(dev
->mdm
.info
[i
].emu
.profile
, p
,
1581 p
+= ISDN_MODEM_NUMREG
;
1582 if (copy_from_user(dev
->mdm
.info
[i
].emu
.plmsn
, p
, ISDN_LMSNLEN
))
1585 if (copy_from_user(dev
->mdm
.info
[i
].emu
.pmsn
, p
, ISDN_MSNLEN
))
1595 /* Set/Get MSN->EAZ-Mapping for a driver */
1598 if (copy_from_user(&iocts
, argp
,
1599 sizeof(isdn_ioctl_struct
)))
1601 iocts
.drvid
[sizeof(iocts
.drvid
)-1] = 0;
1602 if (strlen(iocts
.drvid
)) {
1604 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1605 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1613 if (cmd
== IIOCSETMAP
) {
1616 p
= (char __user
*) iocts
.arg
;
1622 if (!access_ok(VERIFY_READ
, p
, 1))
1624 get_user(bname
[j
], p
++);
1631 strcpy(dev
->drv
[drvidx
]->msn2eaz
[i
], bname
);
1637 if (j
>= ISDN_MSNLEN
)
1644 p
= (char __user
*) iocts
.arg
;
1645 for (i
= 0; i
< 10; i
++) {
1646 snprintf(bname
, sizeof(bname
), "%s%s",
1647 strlen(dev
->drv
[drvidx
]->msn2eaz
[i
]) ?
1648 dev
->drv
[drvidx
]->msn2eaz
[i
] : "_",
1649 (i
< 9) ? "," : "\0");
1650 if (copy_to_user(p
, bname
, strlen(bname
) + 1))
1660 if (copy_to_user(argp
, &dev
, sizeof(ulong
)))
1667 if ((cmd
& IIOCDRVCTL
) == IIOCDRVCTL
)
1668 cmd
= ((cmd
>> _IOC_NRSHIFT
) & _IOC_NRMASK
) & ISDN_DRVIOCTL_MASK
;
1674 if (copy_from_user(&iocts
, argp
, sizeof(isdn_ioctl_struct
)))
1676 iocts
.drvid
[sizeof(iocts
.drvid
)-1] = 0;
1677 if (strlen(iocts
.drvid
)) {
1678 if ((p
= strchr(iocts
.drvid
, ',')))
1681 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1682 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1690 if (!access_ok(VERIFY_WRITE
, argp
,
1691 sizeof(isdn_ioctl_struct
)))
1694 c
.command
= ISDN_CMD_IOCTL
;
1696 memcpy(c
.parm
.num
, &iocts
.arg
, sizeof(ulong
));
1697 ret
= isdn_command(&c
);
1698 memcpy(&iocts
.arg
, c
.parm
.num
, sizeof(ulong
));
1699 if (copy_to_user(argp
, &iocts
, sizeof(isdn_ioctl_struct
)))
1706 #ifdef CONFIG_ISDN_PPP
1707 if (minor
<= ISDN_MINOR_PPPMAX
)
1708 return (isdn_ppp_ioctl(minor
- ISDN_MINOR_PPP
, file
, cmd
, arg
));
1720 isdn_unlocked_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1724 mutex_lock(&isdn_mutex
);
1725 ret
= isdn_ioctl(file
, cmd
, arg
);
1726 mutex_unlock(&isdn_mutex
);
1732 * Open the device code.
1735 isdn_open(struct inode
*ino
, struct file
*filep
)
1737 uint minor
= iminor(ino
);
1740 int retval
= -ENODEV
;
1742 mutex_lock(&isdn_mutex
);
1743 if (minor
== ISDN_MINOR_STATUS
) {
1746 if ((p
= kmalloc(sizeof(infostruct
), GFP_KERNEL
))) {
1747 p
->next
= (char *) dev
->infochain
;
1748 p
->private = (char *) &(filep
->private_data
);
1750 /* At opening we allow a single update */
1751 filep
->private_data
= (char *) 1;
1761 if (minor
<= ISDN_MINOR_BMAX
) {
1762 printk(KERN_WARNING
"isdn_open minor %d obsolete!\n", minor
);
1763 drvidx
= isdn_minor2drv(minor
);
1766 chidx
= isdn_minor2chan(minor
);
1767 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1769 if (!(dev
->drv
[drvidx
]->online
& (1 << chidx
)))
1771 isdn_lock_drivers();
1775 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1776 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1779 isdn_lock_drivers();
1783 #ifdef CONFIG_ISDN_PPP
1784 if (minor
<= ISDN_MINOR_PPPMAX
) {
1785 retval
= isdn_ppp_open(minor
- ISDN_MINOR_PPP
, filep
);
1787 isdn_lock_drivers();
1792 nonseekable_open(ino
, filep
);
1793 mutex_unlock(&isdn_mutex
);
1798 isdn_close(struct inode
*ino
, struct file
*filep
)
1800 uint minor
= iminor(ino
);
1802 mutex_lock(&isdn_mutex
);
1803 if (minor
== ISDN_MINOR_STATUS
) {
1804 infostruct
*p
= dev
->infochain
;
1805 infostruct
*q
= NULL
;
1808 if (p
->private == (char *) &(filep
->private_data
)) {
1812 dev
->infochain
= (infostruct
*) (p
->next
);
1817 p
= (infostruct
*) (p
->next
);
1819 printk(KERN_WARNING
"isdn: No private data while closing isdnctrl\n");
1822 isdn_unlock_drivers();
1823 if (minor
<= ISDN_MINOR_BMAX
)
1825 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1826 if (dev
->profd
== current
)
1830 #ifdef CONFIG_ISDN_PPP
1831 if (minor
<= ISDN_MINOR_PPPMAX
)
1832 isdn_ppp_release(minor
- ISDN_MINOR_PPP
, filep
);
1836 mutex_unlock(&isdn_mutex
);
1840 static const struct file_operations isdn_fops
=
1842 .owner
= THIS_MODULE
,
1843 .llseek
= no_llseek
,
1845 .write
= isdn_write
,
1847 .unlocked_ioctl
= isdn_unlocked_ioctl
,
1849 .release
= isdn_close
,
1853 isdn_map_eaz2msn(char *msn
, int di
)
1855 isdn_driver_t
*this = dev
->drv
[di
];
1858 if (strlen(msn
) == 1) {
1860 if ((i
>= 0) && (i
<= 9))
1861 if (strlen(this->msn2eaz
[i
]))
1862 return (this->msn2eaz
[i
]);
1868 * Find an unused ISDN-channel, whose feature-flags match the
1869 * given L2- and L3-protocols.
1871 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1874 * This function must be called with holding the dev->lock.
1877 isdn_get_free_channel(int usage
, int l2_proto
, int l3_proto
, int pre_dev
1878 ,int pre_chan
, char *msn
)
1884 features
= ((1 << l2_proto
) | (0x10000 << l3_proto
));
1885 vfeatures
= (((1 << l2_proto
) | (0x10000 << l3_proto
)) &
1886 ~(ISDN_FEATURE_L2_V11096
|ISDN_FEATURE_L2_V11019
|ISDN_FEATURE_L2_V11038
));
1887 /* If Layer-2 protocol is V.110, accept drivers with
1888 * transparent feature even if these don't support V.110
1889 * because we can emulate this in linklevel.
1891 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1892 if (USG_NONE(dev
->usage
[i
]) &&
1893 (dev
->drvmap
[i
] != -1)) {
1894 int d
= dev
->drvmap
[i
];
1895 if ((dev
->usage
[i
] & ISDN_USAGE_EXCLUSIVE
) &&
1896 ((pre_dev
!= d
) || (pre_chan
!= dev
->chanmap
[i
])))
1898 if (!strcmp(isdn_map_eaz2msn(msn
, d
), "-"))
1900 if (dev
->usage
[i
] & ISDN_USAGE_DISABLED
)
1901 continue; /* usage not allowed */
1902 if (dev
->drv
[d
]->flags
& DRV_FLAG_RUNNING
) {
1903 if (((dev
->drv
[d
]->interface
->features
& features
) == features
) ||
1904 (((dev
->drv
[d
]->interface
->features
& vfeatures
) == vfeatures
) &&
1905 (dev
->drv
[d
]->interface
->features
& ISDN_FEATURE_L2_TRANS
))) {
1906 if ((pre_dev
< 0) || (pre_chan
< 0)) {
1907 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1908 dev
->usage
[i
] |= usage
;
1912 if ((pre_dev
== d
) && (pre_chan
== dev
->chanmap
[i
])) {
1913 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1914 dev
->usage
[i
] |= usage
;
1926 * Set state of ISDN-channel to 'unused'
1929 isdn_free_channel(int di
, int ch
, int usage
)
1933 if ((di
< 0) || (ch
< 0)) {
1934 printk(KERN_WARNING
"%s: called with invalid drv(%d) or channel(%d)\n",
1938 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1939 if (((!usage
) || ((dev
->usage
[i
] & ISDN_USAGE_MASK
) == usage
)) &&
1940 (dev
->drvmap
[i
] == di
) &&
1941 (dev
->chanmap
[i
] == ch
)) {
1942 dev
->usage
[i
] &= (ISDN_USAGE_NONE
| ISDN_USAGE_EXCLUSIVE
);
1943 strcpy(dev
->num
[i
], "???");
1946 // 20.10.99 JIM, try to reinitialize v110 !
1947 dev
->v110emu
[i
] = 0;
1948 atomic_set(&(dev
->v110use
[i
]), 0);
1949 isdn_v110_close(dev
->v110
[i
]);
1950 dev
->v110
[i
] = NULL
;
1951 // 20.10.99 JIM, try to reinitialize v110 !
1954 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[ch
]);
1959 * Cancel Exclusive-Flag for ISDN-channel
1962 isdn_unexclusive_channel(int di
, int ch
)
1966 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1967 if ((dev
->drvmap
[i
] == di
) &&
1968 (dev
->chanmap
[i
] == ch
)) {
1969 dev
->usage
[i
] &= ~ISDN_USAGE_EXCLUSIVE
;
1976 * writebuf replacement for SKB_ABLE drivers
1979 isdn_writebuf_stub(int drvidx
, int chan
, const u_char __user
* buf
, int len
)
1982 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1983 struct sk_buff
*skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1987 skb_reserve(skb
, hl
);
1988 if (copy_from_user(skb_put(skb
, len
), buf
, len
)) {
1992 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, 1, skb
);
1996 dev
->obytes
[isdn_dc2minor(drvidx
, chan
)] += ret
;
2001 * Return: length of data on success, -ERRcode on failure.
2004 isdn_writebuf_skb_stub(int drvidx
, int chan
, int ack
, struct sk_buff
*skb
)
2007 struct sk_buff
*nskb
= NULL
;
2008 int v110_ret
= skb
->len
;
2009 int idx
= isdn_dc2minor(drvidx
, chan
);
2011 if (dev
->v110
[idx
]) {
2012 atomic_inc(&dev
->v110use
[idx
]);
2013 nskb
= isdn_v110_encode(dev
->v110
[idx
], skb
);
2014 atomic_dec(&dev
->v110use
[idx
]);
2017 v110_ret
= *((int *)nskb
->data
);
2018 skb_pull(nskb
, sizeof(int));
2020 dev_kfree_skb(nskb
);
2023 /* V.110 must always be acknowledged */
2025 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, nskb
);
2027 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2029 if( skb_headroom(skb
) < hl
){
2031 * This should only occur when new HL driver with
2032 * increased hl_hdrlen was loaded after netdevice
2033 * was created and connected to the new driver.
2035 * The V.110 branch (re-allocates on its own) does
2038 struct sk_buff
* skb_tmp
;
2040 skb_tmp
= skb_realloc_headroom(skb
, hl
);
2041 printk(KERN_DEBUG
"isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp
? "" : " failed");
2042 if (!skb_tmp
) return -ENOMEM
; /* 0 better? */
2043 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb_tmp
);
2047 dev_kfree_skb(skb_tmp
);
2050 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb
);
2054 dev
->obytes
[idx
] += ret
;
2055 if (dev
->v110
[idx
]) {
2056 atomic_inc(&dev
->v110use
[idx
]);
2057 dev
->v110
[idx
]->skbuser
++;
2058 atomic_dec(&dev
->v110use
[idx
]);
2059 /* For V.110 return unencoded data length */
2061 /* if the complete frame was send we free the skb;
2062 if not upper function will requeue the skb */
2063 if (ret
== skb
->len
)
2068 dev_kfree_skb(nskb
);
2073 isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
)
2077 init_waitqueue_head(&d
->st_waitq
);
2078 if (d
->flags
& DRV_FLAG_RUNNING
)
2080 if (n
< 1) return 0;
2082 m
= (adding
) ? d
->channels
+ n
: n
;
2084 if (dev
->channels
+ n
> ISDN_MAX_CHANNELS
) {
2085 printk(KERN_WARNING
"register_isdn: Max. %d channels supported\n",
2090 if ((adding
) && (d
->rcverr
))
2092 if (!(d
->rcverr
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2093 printk(KERN_WARNING
"register_isdn: Could not alloc rcverr\n");
2097 if ((adding
) && (d
->rcvcount
))
2099 if (!(d
->rcvcount
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2100 printk(KERN_WARNING
"register_isdn: Could not alloc rcvcount\n");
2106 if ((adding
) && (d
->rpqueue
)) {
2107 for (j
= 0; j
< d
->channels
; j
++)
2108 skb_queue_purge(&d
->rpqueue
[j
]);
2111 if (!(d
->rpqueue
= kmalloc(sizeof(struct sk_buff_head
) * m
, GFP_ATOMIC
))) {
2112 printk(KERN_WARNING
"register_isdn: Could not alloc rpqueue\n");
2119 for (j
= 0; j
< m
; j
++) {
2120 skb_queue_head_init(&d
->rpqueue
[j
]);
2123 if ((adding
) && (d
->rcv_waitq
))
2124 kfree(d
->rcv_waitq
);
2125 d
->rcv_waitq
= kmalloc(sizeof(wait_queue_head_t
) * 2 * m
, GFP_ATOMIC
);
2126 if (!d
->rcv_waitq
) {
2127 printk(KERN_WARNING
"register_isdn: Could not alloc rcv_waitq\n");
2135 d
->snd_waitq
= d
->rcv_waitq
+ m
;
2136 for (j
= 0; j
< m
; j
++) {
2137 init_waitqueue_head(&d
->rcv_waitq
[j
]);
2138 init_waitqueue_head(&d
->snd_waitq
[j
]);
2142 for (j
= d
->channels
; j
< m
; j
++)
2143 for (k
= 0; k
< ISDN_MAX_CHANNELS
; k
++)
2144 if (dev
->chanmap
[k
] < 0) {
2145 dev
->chanmap
[k
] = j
;
2146 dev
->drvmap
[k
] = drvidx
;
2154 * Low-level-driver registration
2158 set_global_features(void)
2162 dev
->global_features
= 0;
2163 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++) {
2164 if (!dev
->drv
[drvidx
])
2166 if (dev
->drv
[drvidx
]->interface
)
2167 dev
->global_features
|= dev
->drv
[drvidx
]->interface
->features
;
2171 #ifdef CONFIG_ISDN_DIVERSION
2173 static char *map_drvname(int di
)
2175 if ((di
< 0) || (di
>= ISDN_MAX_DRIVERS
))
2177 return(dev
->drvid
[di
]); /* driver name */
2180 static int map_namedrv(char *id
)
2183 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2184 { if (!strcmp(dev
->drvid
[i
],id
))
2190 int DIVERT_REG_NAME(isdn_divert_if
*i_div
)
2192 if (i_div
->if_magic
!= DIVERT_IF_MAGIC
)
2193 return(DIVERT_VER_ERR
);
2196 case DIVERT_CMD_REL
:
2197 if (divert_if
!= i_div
)
2198 return(DIVERT_REL_ERR
);
2199 divert_if
= NULL
; /* free interface */
2200 return(DIVERT_NO_ERR
);
2202 case DIVERT_CMD_REG
:
2204 return(DIVERT_REG_ERR
);
2205 i_div
->ll_cmd
= isdn_command
; /* set command function */
2206 i_div
->drv_to_name
= map_drvname
;
2207 i_div
->name_to_drv
= map_namedrv
;
2208 divert_if
= i_div
; /* remember interface */
2209 return(DIVERT_NO_ERR
);
2212 return(DIVERT_CMD_ERR
);
2214 } /* DIVERT_REG_NAME */
2216 EXPORT_SYMBOL(DIVERT_REG_NAME
);
2218 #endif /* CONFIG_ISDN_DIVERSION */
2221 EXPORT_SYMBOL(register_isdn
);
2222 #ifdef CONFIG_ISDN_PPP
2223 EXPORT_SYMBOL(isdn_ppp_register_compressor
);
2224 EXPORT_SYMBOL(isdn_ppp_unregister_compressor
);
2228 register_isdn(isdn_if
* i
)
2235 if (dev
->drivers
>= ISDN_MAX_DRIVERS
) {
2236 printk(KERN_WARNING
"register_isdn: Max. %d drivers supported\n",
2240 if (!i
->writebuf_skb
) {
2241 printk(KERN_WARNING
"register_isdn: No write routine given.\n");
2244 if (!(d
= kzalloc(sizeof(isdn_driver_t
), GFP_KERNEL
))) {
2245 printk(KERN_WARNING
"register_isdn: Could not alloc driver-struct\n");
2249 d
->maxbufsize
= i
->maxbufsize
;
2252 d
->flags
= DRV_FLAG_LOADED
;
2256 spin_lock_irqsave(&dev
->lock
, flags
);
2257 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2258 if (!dev
->drv
[drvidx
])
2260 if (isdn_add_channels(d
, drvidx
, i
->channels
, 0)) {
2261 spin_unlock_irqrestore(&dev
->lock
, flags
);
2265 i
->channels
= drvidx
;
2266 i
->rcvcallb_skb
= isdn_receive_skb_callback
;
2267 i
->statcallb
= isdn_status_callback
;
2269 sprintf(i
->id
, "line%d", drvidx
);
2270 for (j
= 0; j
< drvidx
; j
++)
2271 if (!strcmp(i
->id
, dev
->drvid
[j
]))
2272 sprintf(i
->id
, "line%d", drvidx
);
2273 dev
->drv
[drvidx
] = d
;
2274 strcpy(dev
->drvid
[drvidx
], i
->id
);
2277 set_global_features();
2278 spin_unlock_irqrestore(&dev
->lock
, flags
);
2283 *****************************************************************************
2284 * And now the modules code.
2285 *****************************************************************************
2289 isdn_getrev(const char *revision
)
2294 if ((p
= strchr(revision
, ':'))) {
2296 p
= strchr(rev
, '$');
2304 * Allocate and initialize all data, register modem-devices
2306 static int __init
isdn_init(void)
2311 if (!(dev
= vmalloc(sizeof(isdn_dev
)))) {
2312 printk(KERN_WARNING
"isdn: Could not allocate device-struct.\n");
2315 memset((char *) dev
, 0, sizeof(isdn_dev
));
2316 init_timer(&dev
->timer
);
2317 dev
->timer
.function
= isdn_timer_funct
;
2318 spin_lock_init(&dev
->lock
);
2319 spin_lock_init(&dev
->timerlock
);
2321 dev
->owner
= THIS_MODULE
;
2323 mutex_init(&dev
->mtx
);
2324 init_waitqueue_head(&dev
->info_waitq
);
2325 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2326 dev
->drvmap
[i
] = -1;
2327 dev
->chanmap
[i
] = -1;
2329 strcpy(dev
->num
[i
], "???");
2330 init_waitqueue_head(&dev
->mdm
.info
[i
].open_wait
);
2331 init_waitqueue_head(&dev
->mdm
.info
[i
].close_wait
);
2333 if (register_chrdev(ISDN_MAJOR
, "isdn", &isdn_fops
)) {
2334 printk(KERN_WARNING
"isdn: Could not register control devices\n");
2338 if ((isdn_tty_modem_init()) < 0) {
2339 printk(KERN_WARNING
"isdn: Could not register tty devices\n");
2341 unregister_chrdev(ISDN_MAJOR
, "isdn");
2344 #ifdef CONFIG_ISDN_PPP
2345 if (isdn_ppp_init() < 0) {
2346 printk(KERN_WARNING
"isdn: Could not create PPP-device-structs\n");
2348 unregister_chrdev(ISDN_MAJOR
, "isdn");
2352 #endif /* CONFIG_ISDN_PPP */
2354 strcpy(tmprev
, isdn_revision
);
2355 printk(KERN_NOTICE
"ISDN subsystem Rev: %s/", isdn_getrev(tmprev
));
2356 strcpy(tmprev
, isdn_tty_revision
);
2357 printk("%s/", isdn_getrev(tmprev
));
2358 strcpy(tmprev
, isdn_net_revision
);
2359 printk("%s/", isdn_getrev(tmprev
));
2360 strcpy(tmprev
, isdn_ppp_revision
);
2361 printk("%s/", isdn_getrev(tmprev
));
2362 strcpy(tmprev
, isdn_audio_revision
);
2363 printk("%s/", isdn_getrev(tmprev
));
2364 strcpy(tmprev
, isdn_v110_revision
);
2365 printk("%s", isdn_getrev(tmprev
));
2368 printk(" loaded\n");
2379 static void __exit
isdn_exit(void)
2381 #ifdef CONFIG_ISDN_PPP
2384 if (isdn_net_rmall() < 0) {
2385 printk(KERN_WARNING
"isdn: net-device busy, remove cancelled\n");
2389 unregister_chrdev(ISDN_MAJOR
, "isdn");
2390 del_timer(&dev
->timer
);
2391 /* call vfree with interrupts enabled, else it will hang */
2393 printk(KERN_NOTICE
"ISDN-subsystem unloaded\n");
2396 module_init(isdn_init
);
2397 module_exit(isdn_exit
);