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/vmalloc.h>
18 #include <linux/isdn.h>
19 #include <linux/smp_lock.h>
20 #include "isdn_common.h"
24 #ifdef CONFIG_ISDN_AUDIO
25 #include "isdn_audio.h"
27 #ifdef CONFIG_ISDN_DIVERSION_MODULE
28 #define CONFIG_ISDN_DIVERSION
30 #ifdef CONFIG_ISDN_DIVERSION
31 #include <linux/isdn_divertif.h>
32 #endif /* CONFIG_ISDN_DIVERSION */
33 #include "isdn_v110.h"
36 #undef ISDN_DEBUG_STATCALLB
38 MODULE_DESCRIPTION("ISDN4Linux: link layer");
39 MODULE_AUTHOR("Fritz Elfert");
40 MODULE_LICENSE("GPL");
44 static char *isdn_revision
= "$Revision: 1.1.2.3 $";
46 extern char *isdn_net_revision
;
47 extern char *isdn_tty_revision
;
48 #ifdef CONFIG_ISDN_PPP
49 extern char *isdn_ppp_revision
;
51 static char *isdn_ppp_revision
= ": none $";
53 #ifdef CONFIG_ISDN_AUDIO
54 extern char *isdn_audio_revision
;
56 static char *isdn_audio_revision
= ": none $";
58 extern char *isdn_v110_revision
;
60 #ifdef CONFIG_ISDN_DIVERSION
61 static isdn_divert_if
*divert_if
; /* = NULL */
62 #endif /* CONFIG_ISDN_DIVERSION */
65 static int isdn_writebuf_stub(int, int, const u_char __user
*, int);
66 static void set_global_features(void);
67 static int isdn_wildmat(char *s
, char *p
);
68 static int isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
);
71 isdn_lock_driver(isdn_driver_t
*drv
)
73 try_module_get(drv
->interface
->owner
);
78 isdn_lock_drivers(void)
82 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
85 isdn_lock_driver(dev
->drv
[i
]);
90 isdn_unlock_driver(isdn_driver_t
*drv
)
94 module_put(drv
->interface
->owner
);
99 isdn_unlock_drivers(void)
103 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
106 isdn_unlock_driver(dev
->drv
[i
]);
110 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
112 isdn_dumppkt(char *s
, u_char
* p
, int len
, int dumplen
)
116 printk(KERN_DEBUG
"%s(%d) ", s
, len
);
117 for (dumpc
= 0; (dumpc
< dumplen
) && (len
); len
--, dumpc
++)
118 printk(" %02x", *p
++);
124 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
125 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
128 isdn_star(char *s
, char *p
)
130 while (isdn_wildmat(s
, p
)) {
138 * Shell-type Pattern-matching for incoming caller-Ids
139 * This function gets a string in s and checks, if it matches the pattern
145 * 2 = no match. Would eventually match, if s would be longer.
149 * '?' matches one character
150 * '*' matches zero or more characters
151 * [xyz] matches the set of characters in brackets.
152 * [^xyz] matches any single character not in the set of characters
156 isdn_wildmat(char *s
, char *p
)
159 register int matched
;
160 register int reverse
;
161 register int nostar
= 1;
169 * Literal match with following character,
175 return (*s
== '\0')?2:1;
178 /* Match anything. */
184 /* Trailing star matches everything. */
185 return (*++p
? isdn_star(s
, p
) : 0);
187 /* [^....] means inverse character class. */
188 if ((reverse
= (p
[1] == '^')))
190 for (last
= 0, matched
= 0; *++p
&& (*p
!= ']'); last
= *p
)
191 /* This next line requires a good C compiler. */
192 if (*p
== '-' ? *s
<= *++p
&& *s
>= last
: *s
== *p
)
194 if (matched
== reverse
)
198 return (*s
== '\0')?0:nostar
;
201 int isdn_msncmp( const char * msn1
, const char * msn2
)
203 char TmpMsn1
[ ISDN_MSNLEN
];
204 char TmpMsn2
[ ISDN_MSNLEN
];
207 for ( p
= TmpMsn1
; *msn1
&& *msn1
!= ':'; ) // Strip off a SPID
211 for ( p
= TmpMsn2
; *msn2
&& *msn2
!= ':'; ) // Strip off a SPID
215 return isdn_wildmat( TmpMsn1
, TmpMsn2
);
219 isdn_dc2minor(int di
, int ch
)
222 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
223 if (dev
->chanmap
[i
] == ch
&& dev
->drvmap
[i
] == di
)
228 static int isdn_timer_cnt1
= 0;
229 static int isdn_timer_cnt2
= 0;
230 static int isdn_timer_cnt3
= 0;
233 isdn_timer_funct(ulong dummy
)
235 int tf
= dev
->tflags
;
236 if (tf
& ISDN_TIMER_FAST
) {
237 if (tf
& ISDN_TIMER_MODEMREAD
)
238 isdn_tty_readmodem();
239 if (tf
& ISDN_TIMER_MODEMPLUS
)
240 isdn_tty_modem_escape();
241 if (tf
& ISDN_TIMER_MODEMXMIT
)
242 isdn_tty_modem_xmit();
244 if (tf
& ISDN_TIMER_SLOW
) {
245 if (++isdn_timer_cnt1
>= ISDN_TIMER_02SEC
) {
247 if (tf
& ISDN_TIMER_NETDIAL
)
250 if (++isdn_timer_cnt2
>= ISDN_TIMER_1SEC
) {
252 if (tf
& ISDN_TIMER_NETHANGUP
)
254 if (++isdn_timer_cnt3
>= ISDN_TIMER_RINGING
) {
256 if (tf
& ISDN_TIMER_MODEMRING
)
257 isdn_tty_modem_ring();
259 if (tf
& ISDN_TIMER_CARRIER
)
260 isdn_tty_carrier_timeout();
264 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
268 isdn_timer_ctrl(int tf
, int onoff
)
273 spin_lock_irqsave(&dev
->timerlock
, flags
);
274 if ((tf
& ISDN_TIMER_SLOW
) && (!(dev
->tflags
& ISDN_TIMER_SLOW
))) {
275 /* If the slow-timer wasn't activated until now */
279 old_tflags
= dev
->tflags
;
284 if (dev
->tflags
&& !old_tflags
)
285 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
286 spin_unlock_irqrestore(&dev
->timerlock
, flags
);
290 * Receive a packet from B-Channel. (Called from low-level-module)
293 isdn_receive_skb_callback(int di
, int channel
, struct sk_buff
*skb
)
297 if ((i
= isdn_dc2minor(di
, channel
)) == -1) {
301 /* Update statistics */
302 dev
->ibytes
[i
] += skb
->len
;
304 /* First, try to deliver data to network-device */
305 if (isdn_net_rcv_skb(i
, skb
))
309 * makes sense for async streams only, so it is
310 * called after possible net-device delivery.
313 atomic_inc(&dev
->v110use
[i
]);
314 skb
= isdn_v110_decode(dev
->v110
[i
], skb
);
315 atomic_dec(&dev
->v110use
[i
]);
320 /* No network-device found, deliver to tty or raw-channel */
322 if (isdn_tty_rcv_skb(i
, di
, channel
, skb
))
324 wake_up_interruptible(&dev
->drv
[di
]->rcv_waitq
[channel
]);
330 * Intercept command from Linklevel to Lowlevel.
331 * If layer 2 protocol is V.110 and this is not supported by current
332 * lowlevel-driver, use driver's transparent mode and handle V.110 in
336 isdn_command(isdn_ctrl
*cmd
)
338 if (cmd
->driver
== -1) {
339 printk(KERN_WARNING
"isdn_command command(%x) driver -1\n", cmd
->command
);
342 if (!dev
->drv
[cmd
->driver
]) {
343 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d] NULL\n",
344 cmd
->command
, cmd
->driver
);
347 if (!dev
->drv
[cmd
->driver
]->interface
) {
348 printk(KERN_WARNING
"isdn_command command(%x) dev->drv[%d]->interface NULL\n",
349 cmd
->command
, cmd
->driver
);
352 if (cmd
->command
== ISDN_CMD_SETL2
) {
353 int idx
= isdn_dc2minor(cmd
->driver
, cmd
->arg
& 255);
354 unsigned long l2prot
= (cmd
->arg
>> 8) & 255;
355 unsigned long features
= (dev
->drv
[cmd
->driver
]->interface
->features
356 >> ISDN_FEATURE_L2_SHIFT
) &
357 ISDN_FEATURE_L2_MASK
;
358 unsigned long l2_feature
= (1 << l2prot
);
361 case ISDN_PROTO_L2_V11096
:
362 case ISDN_PROTO_L2_V11019
:
363 case ISDN_PROTO_L2_V11038
:
364 /* If V.110 requested, but not supported by
365 * HL-driver, set emulator-flag and change
366 * Layer-2 to transparent
368 if (!(features
& l2_feature
)) {
369 dev
->v110emu
[idx
] = l2prot
;
370 cmd
->arg
= (cmd
->arg
& 255) |
371 (ISDN_PROTO_L2_TRANS
<< 8);
373 dev
->v110emu
[idx
] = 0;
376 return dev
->drv
[cmd
->driver
]->interface
->command(cmd
);
380 isdn_all_eaz(int di
, int ch
)
388 cmd
.command
= ISDN_CMD_SETEAZ
;
389 cmd
.parm
.num
[0] = '\0';
394 * Begin of a CAPI like LL<->HL interface, currently used only for
395 * supplementary service (CAPI 2.0 part III)
397 #include <linux/isdn/capicmd.h>
400 isdn_capi_rec_hl_msg(capi_msg
*cm
) {
405 di
= (cm
->adr
.Controller
& 0x7f) -1;
406 ch
= isdn_dc2minor(di
, (cm
->adr
.Controller
>>8)& 0x7f);
407 switch(cm
->Command
) {
409 /* in the moment only handled in tty */
410 return(isdn_tty_capi_facility(cm
));
417 isdn_status_callback(isdn_ctrl
* c
)
428 i
= isdn_dc2minor(di
, c
->arg
);
429 switch (c
->command
) {
430 case ISDN_STAT_BSENT
:
433 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
435 if (isdn_net_stat_callback(i
, c
))
437 if (isdn_v110_stat_callback(i
, c
))
439 if (isdn_tty_stat_callback(i
, c
))
441 wake_up_interruptible(&dev
->drv
[di
]->snd_waitq
[c
->arg
]);
443 case ISDN_STAT_STAVAIL
:
444 dev
->drv
[di
]->stavail
+= c
->arg
;
445 wake_up_interruptible(&dev
->drv
[di
]->st_waitq
);
448 dev
->drv
[di
]->flags
|= DRV_FLAG_RUNNING
;
449 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
450 if (dev
->drvmap
[i
] == di
)
451 isdn_all_eaz(di
, dev
->chanmap
[i
]);
452 set_global_features();
455 dev
->drv
[di
]->flags
&= ~DRV_FLAG_RUNNING
;
457 case ISDN_STAT_ICALL
:
460 #ifdef ISDN_DEBUG_STATCALLB
461 printk(KERN_DEBUG
"ICALL (net): %d %ld %s\n", di
, c
->arg
, c
->parm
.num
);
463 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) {
466 cmd
.command
= ISDN_CMD_HANGUP
;
470 /* Try to find a network-interface which will accept incoming call */
471 r
= ((c
->command
== ISDN_STAT_ICALLW
) ? 0 : isdn_net_find_icall(di
, c
->arg
, i
, &c
->parm
.setup
));
474 /* No network-device replies.
476 * These return 0 on no match, 1 on match and
477 * 3 on eventually match, if CID is longer.
479 if (c
->command
== ISDN_STAT_ICALL
)
480 if ((retval
= isdn_tty_find_icall(di
, c
->arg
, &c
->parm
.setup
))) return(retval
);
481 #ifdef CONFIG_ISDN_DIVERSION
483 if ((retval
= divert_if
->stat_callback(c
)))
484 return(retval
); /* processed */
485 #endif /* CONFIG_ISDN_DIVERSION */
486 if ((!retval
) && (dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
)) {
487 /* No tty responding */
490 cmd
.command
= ISDN_CMD_HANGUP
;
496 /* Schedule connection-setup */
500 cmd
.command
= ISDN_CMD_ACCEPTD
;
501 for ( p
= dev
->netdev
; p
; p
= p
->next
)
502 if ( p
->local
->isdn_channel
== cmd
.arg
)
504 strcpy( cmd
.parm
.setup
.eazmsn
, p
->local
->msn
);
511 case 2: /* For calling back, first reject incoming call ... */
512 case 3: /* Interface found, but down, reject call actively */
514 printk(KERN_INFO
"isdn: Rejecting Call\n");
517 cmd
.command
= ISDN_CMD_HANGUP
;
523 /* ... then start callback. */
527 /* Number would eventually match, if longer */
531 #ifdef ISDN_DEBUG_STATCALLB
532 printk(KERN_DEBUG
"ICALL: ret=%d\n", retval
);
539 #ifdef ISDN_DEBUG_STATCALLB
540 printk(KERN_DEBUG
"CINF: %ld %s\n", c
->arg
, c
->parm
.num
);
542 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
544 if (strcmp(c
->parm
.num
, "0"))
545 isdn_net_stat_callback(i
, c
);
546 isdn_tty_stat_callback(i
, c
);
548 case ISDN_STAT_CAUSE
:
549 #ifdef ISDN_DEBUG_STATCALLB
550 printk(KERN_DEBUG
"CAUSE: %ld %s\n", c
->arg
, c
->parm
.num
);
552 printk(KERN_INFO
"isdn: %s,ch%ld cause: %s\n",
553 dev
->drvid
[di
], c
->arg
, c
->parm
.num
);
554 isdn_tty_stat_callback(i
, c
);
555 #ifdef CONFIG_ISDN_DIVERSION
557 divert_if
->stat_callback(c
);
558 #endif /* CONFIG_ISDN_DIVERSION */
560 case ISDN_STAT_DISPLAY
:
561 #ifdef ISDN_DEBUG_STATCALLB
562 printk(KERN_DEBUG
"DISPLAY: %ld %s\n", c
->arg
, c
->parm
.display
);
564 isdn_tty_stat_callback(i
, c
);
565 #ifdef CONFIG_ISDN_DIVERSION
567 divert_if
->stat_callback(c
);
568 #endif /* CONFIG_ISDN_DIVERSION */
570 case ISDN_STAT_DCONN
:
573 #ifdef ISDN_DEBUG_STATCALLB
574 printk(KERN_DEBUG
"DCONN: %ld\n", c
->arg
);
576 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
578 /* Find any net-device, waiting for D-channel setup */
579 if (isdn_net_stat_callback(i
, c
))
581 isdn_v110_stat_callback(i
, c
);
582 /* Find any ttyI, waiting for D-channel setup */
583 if (isdn_tty_stat_callback(i
, c
)) {
586 cmd
.command
= ISDN_CMD_ACCEPTB
;
594 #ifdef ISDN_DEBUG_STATCALLB
595 printk(KERN_DEBUG
"DHUP: %ld\n", c
->arg
);
597 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
599 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
601 /* Signal hangup to network-devices */
602 if (isdn_net_stat_callback(i
, c
))
604 isdn_v110_stat_callback(i
, c
);
605 if (isdn_tty_stat_callback(i
, c
))
607 #ifdef CONFIG_ISDN_DIVERSION
609 divert_if
->stat_callback(c
);
610 #endif /* CONFIG_ISDN_DIVERSION */
613 case ISDN_STAT_BCONN
:
616 #ifdef ISDN_DEBUG_STATCALLB
617 printk(KERN_DEBUG
"BCONN: %ld\n", c
->arg
);
619 /* Signal B-channel-connect to network-devices */
620 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
622 dev
->drv
[di
]->online
|= (1 << (c
->arg
));
624 if (isdn_net_stat_callback(i
, c
))
626 isdn_v110_stat_callback(i
, c
);
627 if (isdn_tty_stat_callback(i
, c
))
633 #ifdef ISDN_DEBUG_STATCALLB
634 printk(KERN_DEBUG
"BHUP: %ld\n", c
->arg
);
636 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
638 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
640 #ifdef CONFIG_ISDN_X25
641 /* Signal hangup to network-devices */
642 if (isdn_net_stat_callback(i
, c
))
645 isdn_v110_stat_callback(i
, c
);
646 if (isdn_tty_stat_callback(i
, c
))
649 case ISDN_STAT_NODCH
:
652 #ifdef ISDN_DEBUG_STATCALLB
653 printk(KERN_DEBUG
"NODCH: %ld\n", c
->arg
);
655 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
657 if (isdn_net_stat_callback(i
, c
))
659 if (isdn_tty_stat_callback(i
, c
))
662 case ISDN_STAT_ADDCH
:
663 spin_lock_irqsave(&dev
->lock
, flags
);
664 if (isdn_add_channels(dev
->drv
[di
], di
, c
->arg
, 1)) {
665 spin_unlock_irqrestore(&dev
->lock
, flags
);
668 spin_unlock_irqrestore(&dev
->lock
, flags
);
671 case ISDN_STAT_DISCH
:
672 spin_lock_irqsave(&dev
->lock
, flags
);
673 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
674 if ((dev
->drvmap
[i
] == di
) &&
675 (dev
->chanmap
[i
] == c
->arg
)) {
677 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
679 if (USG_NONE(dev
->usage
[i
])) {
680 dev
->usage
[i
] |= ISDN_USAGE_DISABLED
;
686 spin_unlock_irqrestore(&dev
->lock
, flags
);
689 case ISDN_STAT_UNLOAD
:
690 while (dev
->drv
[di
]->locks
> 0) {
691 isdn_unlock_driver(dev
->drv
[di
]);
693 spin_lock_irqsave(&dev
->lock
, flags
);
694 isdn_tty_stat_callback(i
, c
);
695 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
696 if (dev
->drvmap
[i
] == di
) {
698 dev
->chanmap
[i
] = -1;
699 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
702 dev
->channels
-= dev
->drv
[di
]->channels
;
703 kfree(dev
->drv
[di
]->rcverr
);
704 kfree(dev
->drv
[di
]->rcvcount
);
705 for (i
= 0; i
< dev
->drv
[di
]->channels
; i
++)
706 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[i
]);
707 kfree(dev
->drv
[di
]->rpqueue
);
708 kfree(dev
->drv
[di
]->rcv_waitq
);
711 dev
->drvid
[di
][0] = '\0';
713 set_global_features();
714 spin_unlock_irqrestore(&dev
->lock
, flags
);
716 case ISDN_STAT_L1ERR
:
718 case CAPI_PUT_MESSAGE
:
719 return(isdn_capi_rec_hl_msg(&c
->parm
.cmsg
));
720 #ifdef CONFIG_ISDN_TTY_FAX
721 case ISDN_STAT_FAXIND
:
722 isdn_tty_stat_callback(i
, c
);
725 #ifdef CONFIG_ISDN_AUDIO
726 case ISDN_STAT_AUDIO
:
727 isdn_tty_stat_callback(i
, c
);
730 #ifdef CONFIG_ISDN_DIVERSION
732 case ISDN_STAT_REDIR
:
734 return(divert_if
->stat_callback(c
));
735 #endif /* CONFIG_ISDN_DIVERSION */
743 * Get integer from char-pointer, set pointer to end of number
746 isdn_getnum(char **p
)
750 while (*p
[0] >= '0' && *p
[0] <= '9')
751 v
= ((v
< 0) ? 0 : (v
* 10)) + (int) ((*p
[0]++) - '0');
758 * isdn_readbchan() tries to get data from the read-queue.
759 * It MUST be called with interrupts off.
761 * Be aware that this is not an atomic operation when sleep != 0, even though
762 * interrupts are turned off! Well, like that we are currently only called
763 * on behalf of a read system call on raw device files (which are documented
764 * to be dangerous and for for debugging purpose only). The inode semaphore
765 * takes care that this is not called for the same minor device number while
766 * we are sleeping, but access is not serialized against simultaneous read()
767 * from the corresponding ttyI device. Can other ugly events, like changes
768 * of the mapping (di,ch)<->minor, happen during the sleep? --he
771 isdn_readbchan(int di
, int channel
, u_char
* buf
, u_char
* fp
, int len
, wait_queue_head_t
*sleep
)
782 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
])) {
784 interruptible_sleep_on(sleep
);
788 if (len
> dev
->drv
[di
]->rcvcount
[channel
])
789 len
= dev
->drv
[di
]->rcvcount
[channel
];
793 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
795 #ifdef CONFIG_ISDN_AUDIO
796 if (ISDN_AUDIO_SKB_LOCK(skb
))
798 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
799 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
801 unsigned long DLEmask
= (1 << channel
);
804 count_pull
= count_put
= 0;
805 while ((count_pull
< skb
->len
) && (len
> 0)) {
807 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
809 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
813 dev
->drv
[di
]->DLEflag
|= DLEmask
;
814 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
821 if (count_pull
>= skb
->len
)
825 /* No DLE's in buff, so simply copy it */
827 if ((count_pull
= skb
->len
) > len
) {
831 count_put
= count_pull
;
832 skb_copy_from_linear_data(skb
, cp
, count_put
);
835 #ifdef CONFIG_ISDN_AUDIO
840 memset(fp
, 0, count_put
);
844 /* We got all the data in this buff.
845 * Now we can dequeue it.
849 #ifdef CONFIG_ISDN_AUDIO
850 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
852 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
855 /* Not yet emptied this buff, so it
856 * must stay in the queue, for further calls
857 * but we pull off the data we got until now.
859 skb_pull(skb
, count_pull
);
860 #ifdef CONFIG_ISDN_AUDIO
861 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
864 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
870 * isdn_readbchan_tty() tries to get data from the read-queue.
871 * It MUST be called with interrupts off.
873 * Be aware that this is not an atomic operation when sleep != 0, even though
874 * interrupts are turned off! Well, like that we are currently only called
875 * on behalf of a read system call on raw device files (which are documented
876 * to be dangerous and for for debugging purpose only). The inode semaphore
877 * takes care that this is not called for the same minor device number while
878 * we are sleeping, but access is not serialized against simultaneous read()
879 * from the corresponding ttyI device. Can other ugly events, like changes
880 * of the mapping (di,ch)<->minor, happen during the sleep? --he
883 isdn_readbchan_tty(int di
, int channel
, struct tty_struct
*tty
, int cisco_hack
)
895 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
898 len
= tty_buffer_request_room(tty
, dev
->drv
[di
]->rcvcount
[channel
]);
904 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
906 #ifdef CONFIG_ISDN_AUDIO
907 if (ISDN_AUDIO_SKB_LOCK(skb
))
909 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
910 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
912 unsigned long DLEmask
= (1 << channel
);
915 count_pull
= count_put
= 0;
916 while ((count_pull
< skb
->len
) && (len
> 0)) {
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
);
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
);
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
)
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
);
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
);
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
);
1271 isdn_ioctl(struct inode
*inode
, struct file
*file
, uint cmd
, ulong arg
)
1273 uint minor
= iminor(inode
);
1284 isdn_ioctl_struct iocts
;
1285 isdn_net_ioctl_phone phone
;
1286 isdn_net_ioctl_cfg cfg
;
1288 void __user
*argp
= (void __user
*)arg
;
1290 #define name iocpar.name
1291 #define bname iocpar.bname
1292 #define iocts iocpar.iocts
1293 #define phone iocpar.phone
1294 #define cfg iocpar.cfg
1296 if (minor
== ISDN_MINOR_STATUS
) {
1304 ulong __user
*p
= argp
;
1306 if (!access_ok(VERIFY_WRITE
, p
,
1307 sizeof(ulong
) * ISDN_MAX_CHANNELS
* 2))
1309 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1310 put_user(dev
->ibytes
[i
], p
++);
1311 put_user(dev
->obytes
[i
], p
++);
1317 #ifdef CONFIG_NETDEVICES
1319 /* Get peer phone number of a connected
1320 * isdn network interface */
1322 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1324 return isdn_net_getpeer(&phone
, argp
);
1334 if (minor
<= ISDN_MINOR_BMAX
) {
1335 drvidx
= isdn_minor2drv(minor
);
1338 chidx
= isdn_minor2chan(minor
);
1339 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1343 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1345 * isdn net devices manage lots of configuration variables as linked lists.
1346 * Those lists must only be manipulated from user space. Some of the ioctl's
1347 * service routines access user space and are not atomic. Therefor, ioctl's
1348 * manipulating the lists and ioctl's sleeping while accessing the lists
1349 * are serialized by means of a semaphore.
1353 printk(KERN_INFO
"INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1356 printk(KERN_INFO
"INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1358 #ifdef CONFIG_NETDEVICES
1360 /* Add a network-interface */
1362 if (copy_from_user(name
, argp
, sizeof(name
)))
1368 ret
= mutex_lock_interruptible(&dev
->mtx
);
1369 if( ret
) return ret
;
1370 if ((s
= isdn_net_new(s
, NULL
))) {
1371 if (copy_to_user(argp
, s
, strlen(s
) + 1)){
1378 mutex_unlock(&dev
->mtx
);
1381 /* Add a slave to a network-interface */
1383 if (copy_from_user(bname
, argp
, sizeof(bname
) - 1))
1387 ret
= mutex_lock_interruptible(&dev
->mtx
);
1388 if( ret
) return ret
;
1389 if ((s
= isdn_net_newslave(bname
))) {
1390 if (copy_to_user(argp
, s
, strlen(s
) + 1)){
1397 mutex_unlock(&dev
->mtx
);
1400 /* Delete a network-interface */
1402 if (copy_from_user(name
, argp
, sizeof(name
)))
1404 ret
= mutex_lock_interruptible(&dev
->mtx
);
1405 if( ret
) return ret
;
1406 ret
= isdn_net_rm(name
);
1407 mutex_unlock(&dev
->mtx
);
1412 /* Set configurable parameters of a network-interface */
1414 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1416 return isdn_net_setcfg(&cfg
);
1420 /* Get configurable parameters of a network-interface */
1422 if (copy_from_user(&cfg
, argp
, sizeof(cfg
)))
1424 if (!(ret
= isdn_net_getcfg(&cfg
))) {
1425 if (copy_to_user(argp
, &cfg
, sizeof(cfg
)))
1432 /* Add a phone-number to a network-interface */
1434 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1436 ret
= mutex_lock_interruptible(&dev
->mtx
);
1437 if( ret
) return ret
;
1438 ret
= isdn_net_addphone(&phone
);
1439 mutex_unlock(&dev
->mtx
);
1444 /* Get list of phone-numbers of a network-interface */
1446 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1448 ret
= mutex_lock_interruptible(&dev
->mtx
);
1449 if( ret
) return ret
;
1450 ret
= isdn_net_getphones(&phone
, argp
);
1451 mutex_unlock(&dev
->mtx
);
1456 /* Delete a phone-number of a network-interface */
1458 if (copy_from_user(&phone
, argp
, sizeof(phone
)))
1460 ret
= mutex_lock_interruptible(&dev
->mtx
);
1461 if( ret
) return ret
;
1462 ret
= isdn_net_delphone(&phone
);
1463 mutex_unlock(&dev
->mtx
);
1468 /* Force dialing of a network-interface */
1470 if (copy_from_user(name
, argp
, sizeof(name
)))
1472 return isdn_net_force_dial(name
);
1475 #ifdef CONFIG_ISDN_PPP
1479 if (copy_from_user(name
, argp
, sizeof(name
)))
1481 return isdn_ppp_dial_slave(name
);
1485 if (copy_from_user(name
, argp
, sizeof(name
)))
1487 return isdn_ppp_hangup_slave(name
);
1490 /* Force hangup of a network-interface */
1493 if (copy_from_user(name
, argp
, sizeof(name
)))
1495 return isdn_net_force_hangup(name
);
1497 #endif /* CONFIG_NETDEVICES */
1499 dev
->net_verbose
= arg
;
1500 printk(KERN_INFO
"isdn: Verbose-Level is %d\n", dev
->net_verbose
);
1504 dev
->global_flags
|= ISDN_GLOBAL_STOPPED
;
1506 dev
->global_flags
&= ~ISDN_GLOBAL_STOPPED
;
1507 printk(KERN_INFO
"isdn: Global Mode %s\n",
1508 (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) ? "stopped" : "running");
1515 if (copy_from_user(&iocts
, argp
,
1516 sizeof(isdn_ioctl_struct
)))
1518 if (strlen(iocts
.drvid
)) {
1519 if ((p
= strchr(iocts
.drvid
, ',')))
1522 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1523 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1532 dev
->drv
[drvidx
]->flags
|= DRV_FLAG_REJBUS
;
1534 dev
->drv
[drvidx
]->flags
&= ~DRV_FLAG_REJBUS
;
1537 dev
->profd
= current
;
1541 /* Get all Modem-Profiles */
1543 char __user
*p
= argp
;
1546 if (!access_ok(VERIFY_WRITE
, argp
,
1547 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
)
1548 * ISDN_MAX_CHANNELS
))
1551 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1552 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.profile
,
1555 p
+= ISDN_MODEM_NUMREG
;
1556 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.pmsn
, ISDN_MSNLEN
))
1559 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.plmsn
, ISDN_LMSNLEN
))
1563 return (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
) * ISDN_MAX_CHANNELS
;
1568 /* Set all Modem-Profiles */
1570 char __user
*p
= argp
;
1573 if (!access_ok(VERIFY_READ
, argp
,
1574 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
)
1575 * ISDN_MAX_CHANNELS
))
1578 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1579 if (copy_from_user(dev
->mdm
.info
[i
].emu
.profile
, p
,
1582 p
+= ISDN_MODEM_NUMREG
;
1583 if (copy_from_user(dev
->mdm
.info
[i
].emu
.plmsn
, p
, ISDN_LMSNLEN
))
1586 if (copy_from_user(dev
->mdm
.info
[i
].emu
.pmsn
, p
, ISDN_MSNLEN
))
1596 /* Set/Get MSN->EAZ-Mapping for a driver */
1599 if (copy_from_user(&iocts
, argp
,
1600 sizeof(isdn_ioctl_struct
)))
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 sprintf(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 if (strlen(iocts
.drvid
)) {
1677 if ((p
= strchr(iocts
.drvid
, ',')))
1680 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1681 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1689 if (!access_ok(VERIFY_WRITE
, argp
,
1690 sizeof(isdn_ioctl_struct
)))
1693 c
.command
= ISDN_CMD_IOCTL
;
1695 memcpy(c
.parm
.num
, &iocts
.arg
, sizeof(ulong
));
1696 ret
= isdn_command(&c
);
1697 memcpy(&iocts
.arg
, c
.parm
.num
, sizeof(ulong
));
1698 if (copy_to_user(argp
, &iocts
, sizeof(isdn_ioctl_struct
)))
1705 #ifdef CONFIG_ISDN_PPP
1706 if (minor
<= ISDN_MINOR_PPPMAX
)
1707 return (isdn_ppp_ioctl(minor
- ISDN_MINOR_PPP
, file
, cmd
, arg
));
1719 * Open the device code.
1722 isdn_open(struct inode
*ino
, struct file
*filep
)
1724 uint minor
= iminor(ino
);
1727 int retval
= -ENODEV
;
1730 if (minor
== ISDN_MINOR_STATUS
) {
1733 if ((p
= kmalloc(sizeof(infostruct
), GFP_KERNEL
))) {
1734 p
->next
= (char *) dev
->infochain
;
1735 p
->private = (char *) &(filep
->private_data
);
1737 /* At opening we allow a single update */
1738 filep
->private_data
= (char *) 1;
1748 if (minor
<= ISDN_MINOR_BMAX
) {
1749 printk(KERN_WARNING
"isdn_open minor %d obsolete!\n", minor
);
1750 drvidx
= isdn_minor2drv(minor
);
1753 chidx
= isdn_minor2chan(minor
);
1754 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1756 if (!(dev
->drv
[drvidx
]->online
& (1 << chidx
)))
1758 isdn_lock_drivers();
1762 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1763 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1766 isdn_lock_drivers();
1770 #ifdef CONFIG_ISDN_PPP
1771 if (minor
<= ISDN_MINOR_PPPMAX
) {
1772 retval
= isdn_ppp_open(minor
- ISDN_MINOR_PPP
, filep
);
1774 isdn_lock_drivers();
1779 nonseekable_open(ino
, filep
);
1784 isdn_close(struct inode
*ino
, struct file
*filep
)
1786 uint minor
= iminor(ino
);
1789 if (minor
== ISDN_MINOR_STATUS
) {
1790 infostruct
*p
= dev
->infochain
;
1791 infostruct
*q
= NULL
;
1794 if (p
->private == (char *) &(filep
->private_data
)) {
1798 dev
->infochain
= (infostruct
*) (p
->next
);
1803 p
= (infostruct
*) (p
->next
);
1805 printk(KERN_WARNING
"isdn: No private data while closing isdnctrl\n");
1808 isdn_unlock_drivers();
1809 if (minor
<= ISDN_MINOR_BMAX
)
1811 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1812 if (dev
->profd
== current
)
1816 #ifdef CONFIG_ISDN_PPP
1817 if (minor
<= ISDN_MINOR_PPPMAX
)
1818 isdn_ppp_release(minor
- ISDN_MINOR_PPP
, filep
);
1826 static const struct file_operations isdn_fops
=
1828 .owner
= THIS_MODULE
,
1829 .llseek
= no_llseek
,
1831 .write
= isdn_write
,
1833 .ioctl
= isdn_ioctl
,
1835 .release
= isdn_close
,
1839 isdn_map_eaz2msn(char *msn
, int di
)
1841 isdn_driver_t
*this = dev
->drv
[di
];
1844 if (strlen(msn
) == 1) {
1846 if ((i
>= 0) && (i
<= 9))
1847 if (strlen(this->msn2eaz
[i
]))
1848 return (this->msn2eaz
[i
]);
1854 * Find an unused ISDN-channel, whose feature-flags match the
1855 * given L2- and L3-protocols.
1857 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1860 * This function must be called with holding the dev->lock.
1863 isdn_get_free_channel(int usage
, int l2_proto
, int l3_proto
, int pre_dev
1864 ,int pre_chan
, char *msn
)
1870 features
= ((1 << l2_proto
) | (0x10000 << l3_proto
));
1871 vfeatures
= (((1 << l2_proto
) | (0x10000 << l3_proto
)) &
1872 ~(ISDN_FEATURE_L2_V11096
|ISDN_FEATURE_L2_V11019
|ISDN_FEATURE_L2_V11038
));
1873 /* If Layer-2 protocol is V.110, accept drivers with
1874 * transparent feature even if these don't support V.110
1875 * because we can emulate this in linklevel.
1877 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1878 if (USG_NONE(dev
->usage
[i
]) &&
1879 (dev
->drvmap
[i
] != -1)) {
1880 int d
= dev
->drvmap
[i
];
1881 if ((dev
->usage
[i
] & ISDN_USAGE_EXCLUSIVE
) &&
1882 ((pre_dev
!= d
) || (pre_chan
!= dev
->chanmap
[i
])))
1884 if (!strcmp(isdn_map_eaz2msn(msn
, d
), "-"))
1886 if (dev
->usage
[i
] & ISDN_USAGE_DISABLED
)
1887 continue; /* usage not allowed */
1888 if (dev
->drv
[d
]->flags
& DRV_FLAG_RUNNING
) {
1889 if (((dev
->drv
[d
]->interface
->features
& features
) == features
) ||
1890 (((dev
->drv
[d
]->interface
->features
& vfeatures
) == vfeatures
) &&
1891 (dev
->drv
[d
]->interface
->features
& ISDN_FEATURE_L2_TRANS
))) {
1892 if ((pre_dev
< 0) || (pre_chan
< 0)) {
1893 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1894 dev
->usage
[i
] |= usage
;
1898 if ((pre_dev
== d
) && (pre_chan
== dev
->chanmap
[i
])) {
1899 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1900 dev
->usage
[i
] |= usage
;
1912 * Set state of ISDN-channel to 'unused'
1915 isdn_free_channel(int di
, int ch
, int usage
)
1919 if ((di
< 0) || (ch
< 0)) {
1920 printk(KERN_WARNING
"%s: called with invalid drv(%d) or channel(%d)\n",
1921 __FUNCTION__
, di
, ch
);
1924 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1925 if (((!usage
) || ((dev
->usage
[i
] & ISDN_USAGE_MASK
) == usage
)) &&
1926 (dev
->drvmap
[i
] == di
) &&
1927 (dev
->chanmap
[i
] == ch
)) {
1928 dev
->usage
[i
] &= (ISDN_USAGE_NONE
| ISDN_USAGE_EXCLUSIVE
);
1929 strcpy(dev
->num
[i
], "???");
1932 // 20.10.99 JIM, try to reinitialize v110 !
1933 dev
->v110emu
[i
] = 0;
1934 atomic_set(&(dev
->v110use
[i
]), 0);
1935 isdn_v110_close(dev
->v110
[i
]);
1936 dev
->v110
[i
] = NULL
;
1937 // 20.10.99 JIM, try to reinitialize v110 !
1940 skb_queue_purge(&dev
->drv
[di
]->rpqueue
[ch
]);
1945 * Cancel Exclusive-Flag for ISDN-channel
1948 isdn_unexclusive_channel(int di
, int ch
)
1952 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1953 if ((dev
->drvmap
[i
] == di
) &&
1954 (dev
->chanmap
[i
] == ch
)) {
1955 dev
->usage
[i
] &= ~ISDN_USAGE_EXCLUSIVE
;
1962 * writebuf replacement for SKB_ABLE drivers
1965 isdn_writebuf_stub(int drvidx
, int chan
, const u_char __user
* buf
, int len
)
1968 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1969 struct sk_buff
*skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1973 skb_reserve(skb
, hl
);
1974 if (copy_from_user(skb_put(skb
, len
), buf
, len
))
1976 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, 1, skb
);
1980 dev
->obytes
[isdn_dc2minor(drvidx
, chan
)] += ret
;
1985 * Return: length of data on success, -ERRcode on failure.
1988 isdn_writebuf_skb_stub(int drvidx
, int chan
, int ack
, struct sk_buff
*skb
)
1991 struct sk_buff
*nskb
= NULL
;
1992 int v110_ret
= skb
->len
;
1993 int idx
= isdn_dc2minor(drvidx
, chan
);
1995 if (dev
->v110
[idx
]) {
1996 atomic_inc(&dev
->v110use
[idx
]);
1997 nskb
= isdn_v110_encode(dev
->v110
[idx
], skb
);
1998 atomic_dec(&dev
->v110use
[idx
]);
2001 v110_ret
= *((int *)nskb
->data
);
2002 skb_pull(nskb
, sizeof(int));
2004 dev_kfree_skb(nskb
);
2007 /* V.110 must always be acknowledged */
2009 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, nskb
);
2011 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2013 if( skb_headroom(skb
) < hl
){
2015 * This should only occur when new HL driver with
2016 * increased hl_hdrlen was loaded after netdevice
2017 * was created and connected to the new driver.
2019 * The V.110 branch (re-allocates on its own) does
2022 struct sk_buff
* skb_tmp
;
2024 skb_tmp
= skb_realloc_headroom(skb
, hl
);
2025 printk(KERN_DEBUG
"isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp
? "" : " failed");
2026 if (!skb_tmp
) return -ENOMEM
; /* 0 better? */
2027 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb_tmp
);
2031 dev_kfree_skb(skb_tmp
);
2034 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb
);
2038 dev
->obytes
[idx
] += ret
;
2039 if (dev
->v110
[idx
]) {
2040 atomic_inc(&dev
->v110use
[idx
]);
2041 dev
->v110
[idx
]->skbuser
++;
2042 atomic_dec(&dev
->v110use
[idx
]);
2043 /* For V.110 return unencoded data length */
2045 /* if the complete frame was send we free the skb;
2046 if not upper function will requeue the skb */
2047 if (ret
== skb
->len
)
2052 dev_kfree_skb(nskb
);
2057 isdn_add_channels(isdn_driver_t
*d
, int drvidx
, int n
, int adding
)
2061 init_waitqueue_head(&d
->st_waitq
);
2062 if (d
->flags
& DRV_FLAG_RUNNING
)
2064 if (n
< 1) return 0;
2066 m
= (adding
) ? d
->channels
+ n
: n
;
2068 if (dev
->channels
+ n
> ISDN_MAX_CHANNELS
) {
2069 printk(KERN_WARNING
"register_isdn: Max. %d channels supported\n",
2074 if ((adding
) && (d
->rcverr
))
2076 if (!(d
->rcverr
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2077 printk(KERN_WARNING
"register_isdn: Could not alloc rcverr\n");
2081 if ((adding
) && (d
->rcvcount
))
2083 if (!(d
->rcvcount
= kzalloc(sizeof(int) * m
, GFP_ATOMIC
))) {
2084 printk(KERN_WARNING
"register_isdn: Could not alloc rcvcount\n");
2090 if ((adding
) && (d
->rpqueue
)) {
2091 for (j
= 0; j
< d
->channels
; j
++)
2092 skb_queue_purge(&d
->rpqueue
[j
]);
2095 if (!(d
->rpqueue
= kmalloc(sizeof(struct sk_buff_head
) * m
, GFP_ATOMIC
))) {
2096 printk(KERN_WARNING
"register_isdn: Could not alloc rpqueue\n");
2103 for (j
= 0; j
< m
; j
++) {
2104 skb_queue_head_init(&d
->rpqueue
[j
]);
2107 if ((adding
) && (d
->rcv_waitq
))
2108 kfree(d
->rcv_waitq
);
2109 d
->rcv_waitq
= kmalloc(sizeof(wait_queue_head_t
) * 2 * m
, GFP_ATOMIC
);
2110 if (!d
->rcv_waitq
) {
2111 printk(KERN_WARNING
"register_isdn: Could not alloc rcv_waitq\n");
2119 d
->snd_waitq
= d
->rcv_waitq
+ m
;
2120 for (j
= 0; j
< m
; j
++) {
2121 init_waitqueue_head(&d
->rcv_waitq
[j
]);
2122 init_waitqueue_head(&d
->snd_waitq
[j
]);
2126 for (j
= d
->channels
; j
< m
; j
++)
2127 for (k
= 0; k
< ISDN_MAX_CHANNELS
; k
++)
2128 if (dev
->chanmap
[k
] < 0) {
2129 dev
->chanmap
[k
] = j
;
2130 dev
->drvmap
[k
] = drvidx
;
2138 * Low-level-driver registration
2142 set_global_features(void)
2146 dev
->global_features
= 0;
2147 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++) {
2148 if (!dev
->drv
[drvidx
])
2150 if (dev
->drv
[drvidx
]->interface
)
2151 dev
->global_features
|= dev
->drv
[drvidx
]->interface
->features
;
2155 #ifdef CONFIG_ISDN_DIVERSION
2157 static char *map_drvname(int di
)
2159 if ((di
< 0) || (di
>= ISDN_MAX_DRIVERS
))
2161 return(dev
->drvid
[di
]); /* driver name */
2164 static int map_namedrv(char *id
)
2167 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2168 { if (!strcmp(dev
->drvid
[i
],id
))
2174 int DIVERT_REG_NAME(isdn_divert_if
*i_div
)
2176 if (i_div
->if_magic
!= DIVERT_IF_MAGIC
)
2177 return(DIVERT_VER_ERR
);
2180 case DIVERT_CMD_REL
:
2181 if (divert_if
!= i_div
)
2182 return(DIVERT_REL_ERR
);
2183 divert_if
= NULL
; /* free interface */
2184 return(DIVERT_NO_ERR
);
2186 case DIVERT_CMD_REG
:
2188 return(DIVERT_REG_ERR
);
2189 i_div
->ll_cmd
= isdn_command
; /* set command function */
2190 i_div
->drv_to_name
= map_drvname
;
2191 i_div
->name_to_drv
= map_namedrv
;
2192 divert_if
= i_div
; /* remember interface */
2193 return(DIVERT_NO_ERR
);
2196 return(DIVERT_CMD_ERR
);
2198 } /* DIVERT_REG_NAME */
2200 EXPORT_SYMBOL(DIVERT_REG_NAME
);
2202 #endif /* CONFIG_ISDN_DIVERSION */
2205 EXPORT_SYMBOL(register_isdn
);
2206 #ifdef CONFIG_ISDN_PPP
2207 EXPORT_SYMBOL(isdn_ppp_register_compressor
);
2208 EXPORT_SYMBOL(isdn_ppp_unregister_compressor
);
2212 register_isdn(isdn_if
* i
)
2219 if (dev
->drivers
>= ISDN_MAX_DRIVERS
) {
2220 printk(KERN_WARNING
"register_isdn: Max. %d drivers supported\n",
2224 if (!i
->writebuf_skb
) {
2225 printk(KERN_WARNING
"register_isdn: No write routine given.\n");
2228 if (!(d
= kzalloc(sizeof(isdn_driver_t
), GFP_KERNEL
))) {
2229 printk(KERN_WARNING
"register_isdn: Could not alloc driver-struct\n");
2233 d
->maxbufsize
= i
->maxbufsize
;
2236 d
->flags
= DRV_FLAG_LOADED
;
2240 spin_lock_irqsave(&dev
->lock
, flags
);
2241 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2242 if (!dev
->drv
[drvidx
])
2244 if (isdn_add_channels(d
, drvidx
, i
->channels
, 0)) {
2245 spin_unlock_irqrestore(&dev
->lock
, flags
);
2249 i
->channels
= drvidx
;
2250 i
->rcvcallb_skb
= isdn_receive_skb_callback
;
2251 i
->statcallb
= isdn_status_callback
;
2253 sprintf(i
->id
, "line%d", drvidx
);
2254 for (j
= 0; j
< drvidx
; j
++)
2255 if (!strcmp(i
->id
, dev
->drvid
[j
]))
2256 sprintf(i
->id
, "line%d", drvidx
);
2257 dev
->drv
[drvidx
] = d
;
2258 strcpy(dev
->drvid
[drvidx
], i
->id
);
2261 set_global_features();
2262 spin_unlock_irqrestore(&dev
->lock
, flags
);
2267 *****************************************************************************
2268 * And now the modules code.
2269 *****************************************************************************
2273 isdn_getrev(const char *revision
)
2278 if ((p
= strchr(revision
, ':'))) {
2280 p
= strchr(rev
, '$');
2288 * Allocate and initialize all data, register modem-devices
2290 static int __init
isdn_init(void)
2295 if (!(dev
= vmalloc(sizeof(isdn_dev
)))) {
2296 printk(KERN_WARNING
"isdn: Could not allocate device-struct.\n");
2299 memset((char *) dev
, 0, sizeof(isdn_dev
));
2300 init_timer(&dev
->timer
);
2301 dev
->timer
.function
= isdn_timer_funct
;
2302 spin_lock_init(&dev
->lock
);
2303 spin_lock_init(&dev
->timerlock
);
2305 dev
->owner
= THIS_MODULE
;
2307 mutex_init(&dev
->mtx
);
2308 init_waitqueue_head(&dev
->info_waitq
);
2309 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2310 dev
->drvmap
[i
] = -1;
2311 dev
->chanmap
[i
] = -1;
2313 strcpy(dev
->num
[i
], "???");
2314 init_waitqueue_head(&dev
->mdm
.info
[i
].open_wait
);
2315 init_waitqueue_head(&dev
->mdm
.info
[i
].close_wait
);
2317 if (register_chrdev(ISDN_MAJOR
, "isdn", &isdn_fops
)) {
2318 printk(KERN_WARNING
"isdn: Could not register control devices\n");
2322 if ((isdn_tty_modem_init()) < 0) {
2323 printk(KERN_WARNING
"isdn: Could not register tty devices\n");
2325 unregister_chrdev(ISDN_MAJOR
, "isdn");
2328 #ifdef CONFIG_ISDN_PPP
2329 if (isdn_ppp_init() < 0) {
2330 printk(KERN_WARNING
"isdn: Could not create PPP-device-structs\n");
2332 unregister_chrdev(ISDN_MAJOR
, "isdn");
2336 #endif /* CONFIG_ISDN_PPP */
2338 strcpy(tmprev
, isdn_revision
);
2339 printk(KERN_NOTICE
"ISDN subsystem Rev: %s/", isdn_getrev(tmprev
));
2340 strcpy(tmprev
, isdn_tty_revision
);
2341 printk("%s/", isdn_getrev(tmprev
));
2342 strcpy(tmprev
, isdn_net_revision
);
2343 printk("%s/", isdn_getrev(tmprev
));
2344 strcpy(tmprev
, isdn_ppp_revision
);
2345 printk("%s/", isdn_getrev(tmprev
));
2346 strcpy(tmprev
, isdn_audio_revision
);
2347 printk("%s/", isdn_getrev(tmprev
));
2348 strcpy(tmprev
, isdn_v110_revision
);
2349 printk("%s", isdn_getrev(tmprev
));
2352 printk(" loaded\n");
2363 static void __exit
isdn_exit(void)
2365 #ifdef CONFIG_ISDN_PPP
2368 if (isdn_net_rmall() < 0) {
2369 printk(KERN_WARNING
"isdn: net-device busy, remove cancelled\n");
2373 unregister_chrdev(ISDN_MAJOR
, "isdn");
2374 del_timer(&dev
->timer
);
2375 /* call vfree with interrupts enabled, else it will hang */
2377 printk(KERN_NOTICE
"ISDN-subsystem unloaded\n");
2380 module_init(isdn_init
);
2381 module_exit(isdn_exit
);