1 /* $Id: isdn_common.c,v 1.114 2000/11/25 17:00:59 kai 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 program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/version.h>
28 #include <linux/poll.h>
29 #include <linux/vmalloc.h>
30 #include <linux/isdn.h>
31 #include <linux/smp_lock.h>
32 #include "isdn_common.h"
36 #ifdef CONFIG_ISDN_AUDIO
37 #include "isdn_audio.h"
39 #ifdef CONFIG_ISDN_DIVERSION_MODULE
40 #define CONFIG_ISDN_DIVERSION
42 #ifdef CONFIG_ISDN_DIVERSION
43 #include <linux/isdn_divertif.h>
44 #endif CONFIG_ISDN_DIVERSION
45 #include "isdn_v110.h"
46 #include "isdn_cards.h"
47 #include <linux/devfs_fs_kernel.h>
50 #undef ISDN_DEBUG_STATCALLB
54 static char *isdn_revision
= "$Revision: 1.114 $";
56 extern char *isdn_net_revision
;
57 extern char *isdn_tty_revision
;
58 #ifdef CONFIG_ISDN_PPP
59 extern char *isdn_ppp_revision
;
61 static char *isdn_ppp_revision
= ": none $";
63 #ifdef CONFIG_ISDN_AUDIO
64 extern char *isdn_audio_revision
;
66 static char *isdn_audio_revision
= ": none $";
68 extern char *isdn_v110_revision
;
70 #ifdef CONFIG_ISDN_DIVERSION
71 isdn_divert_if
*divert_if
; /* interface to diversion module */
72 #endif CONFIG_ISDN_DIVERSION
75 static int isdn_writebuf_stub(int, int, const u_char
*, int, int);
76 static void set_global_features(void);
77 static void isdn_register_devfs(int);
78 static void isdn_unregister_devfs(int);
79 static int isdn_wildmat(char *s
, char *p
);
82 isdn_lock_drivers(void)
86 for (i
= 0; i
< dev
->drivers
; i
++) {
91 cmd
.command
= ISDN_CMD_LOCK
;
98 isdn_MOD_INC_USE_COUNT(void)
105 isdn_unlock_drivers(void)
109 for (i
= 0; i
< dev
->drivers
; i
++)
110 if (dev
->drv
[i
]->locks
> 0) {
115 cmd
.command
= ISDN_CMD_UNLOCK
;
117 dev
->drv
[i
]->locks
--;
122 isdn_MOD_DEC_USE_COUNT(void)
125 isdn_unlock_drivers();
128 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
130 isdn_dumppkt(char *s
, u_char
* p
, int len
, int dumplen
)
134 printk(KERN_DEBUG
"%s(%d) ", s
, len
);
135 for (dumpc
= 0; (dumpc
< dumplen
) && (len
); len
--, dumpc
++)
136 printk(" %02x", *p
++);
142 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
143 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
146 isdn_star(char *s
, char *p
)
148 while (isdn_wildmat(s
, p
)) {
156 * Shell-type Pattern-matching for incoming caller-Ids
157 * This function gets a string in s and checks, if it matches the pattern
163 * 2 = no match. Would eventually match, if s would be longer.
167 * '?' matches one character
168 * '*' matches zero or more characters
169 * [xyz] matches the set of characters in brackets.
170 * [^xyz] matches any single character not in the set of characters
174 isdn_wildmat(char *s
, char *p
)
177 register int matched
;
178 register int reverse
;
179 register int nostar
= 1;
187 * Literal match with following character,
193 return (*s
== '\0')?2:1;
196 /* Match anything. */
202 /* Trailing star matches everything. */
203 return (*++p
? isdn_star(s
, p
) : 0);
205 /* [^....] means inverse character class. */
206 if ((reverse
= (p
[1] == '^')))
208 for (last
= 0, matched
= 0; *++p
&& (*p
!= ']'); last
= *p
)
209 /* This next line requires a good C compiler. */
210 if (*p
== '-' ? *s
<= *++p
&& *s
>= last
: *s
== *p
)
212 if (matched
== reverse
)
216 return (*s
== '\0')?0:nostar
;
219 int isdn_msncmp( const char * msn1
, const char * msn2
)
221 char TmpMsn1
[ ISDN_MSNLEN
];
222 char TmpMsn2
[ ISDN_MSNLEN
];
225 for ( p
= TmpMsn1
; *msn1
&& *msn1
!= ':'; ) // Strip off a SPID
229 for ( p
= TmpMsn2
; *msn2
&& *msn2
!= ':'; ) // Strip off a SPID
233 return isdn_wildmat( TmpMsn1
, TmpMsn2
);
237 isdn_free_queue(struct sk_buff_head
*queue
)
244 if (skb_queue_len(queue
))
245 while ((skb
= skb_dequeue(queue
)))
247 restore_flags(flags
);
251 isdn_dc2minor(int di
, int ch
)
254 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
255 if (dev
->chanmap
[i
] == ch
&& dev
->drvmap
[i
] == di
)
260 static int isdn_timer_cnt1
= 0;
261 static int isdn_timer_cnt2
= 0;
262 static int isdn_timer_cnt3
= 0;
263 static int isdn_timer_cnt4
= 0;
266 isdn_timer_funct(ulong dummy
)
268 int tf
= dev
->tflags
;
269 if (tf
& ISDN_TIMER_FAST
) {
270 if (tf
& ISDN_TIMER_MODEMREAD
)
271 isdn_tty_readmodem();
272 if (tf
& ISDN_TIMER_MODEMPLUS
)
273 isdn_tty_modem_escape();
274 if (tf
& ISDN_TIMER_MODEMXMIT
)
275 isdn_tty_modem_xmit();
277 if (tf
& ISDN_TIMER_SLOW
) {
278 if (++isdn_timer_cnt1
>= ISDN_TIMER_02SEC
) {
280 if (tf
& ISDN_TIMER_NETDIAL
)
283 if (++isdn_timer_cnt2
>= ISDN_TIMER_1SEC
) {
285 if (tf
& ISDN_TIMER_NETHANGUP
)
287 if (++isdn_timer_cnt3
> ISDN_TIMER_RINGING
) {
289 if (tf
& ISDN_TIMER_MODEMRING
)
290 isdn_tty_modem_ring();
292 if (++isdn_timer_cnt4
> ISDN_TIMER_KEEPINT
) {
294 if (tf
& ISDN_TIMER_KEEPALIVE
)
295 isdn_net_slarp_out();
297 if (tf
& ISDN_TIMER_CARRIER
)
298 isdn_tty_carrier_timeout();
307 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
308 restore_flags(flags
);
313 isdn_timer_ctrl(int tf
, int onoff
)
319 if ((tf
& ISDN_TIMER_SLOW
) && (!(dev
->tflags
& ISDN_TIMER_SLOW
))) {
320 /* If the slow-timer wasn't activated until now */
329 mod_timer(&dev
->timer
, jiffies
+ISDN_TIMER_RES
);
330 restore_flags(flags
);
334 * Receive a packet from B-Channel. (Called from low-level-module)
337 isdn_receive_skb_callback(int di
, int channel
, struct sk_buff
*skb
)
341 if ((i
= isdn_dc2minor(di
, channel
)) == -1) {
345 /* Update statistics */
346 dev
->ibytes
[i
] += skb
->len
;
348 /* First, try to deliver data to network-device */
349 if (isdn_net_rcv_skb(i
, skb
))
353 * makes sense for async streams only, so it is
354 * called after possible net-device delivery.
357 atomic_inc(&dev
->v110use
[i
]);
358 skb
= isdn_v110_decode(dev
->v110
[i
], skb
);
359 atomic_dec(&dev
->v110use
[i
]);
364 /* No network-device found, deliver to tty or raw-channel */
366 if (isdn_tty_rcv_skb(i
, di
, channel
, skb
))
368 wake_up_interruptible(&dev
->drv
[di
]->rcv_waitq
[channel
]);
374 * Intercept command from Linklevel to Lowlevel.
375 * If layer 2 protocol is V.110 and this is not supported by current
376 * lowlevel-driver, use driver's transparent mode and handle V.110 in
380 isdn_command(isdn_ctrl
*cmd
)
382 if (cmd
->driver
== -1) {
383 printk(KERN_WARNING
"isdn_command command(%x) driver -1\n", cmd
->command
);
386 if (cmd
->command
== ISDN_CMD_SETL2
) {
387 int idx
= isdn_dc2minor(cmd
->driver
, cmd
->arg
& 255);
388 unsigned long l2prot
= (cmd
->arg
>> 8) & 255;
389 unsigned long features
= (dev
->drv
[cmd
->driver
]->interface
->features
390 >> ISDN_FEATURE_L2_SHIFT
) &
391 ISDN_FEATURE_L2_MASK
;
392 unsigned long l2_feature
= (1 << l2prot
);
395 case ISDN_PROTO_L2_V11096
:
396 case ISDN_PROTO_L2_V11019
:
397 case ISDN_PROTO_L2_V11038
:
398 /* If V.110 requested, but not supported by
399 * HL-driver, set emulator-flag and change
400 * Layer-2 to transparent
402 if (!(features
& l2_feature
)) {
403 dev
->v110emu
[idx
] = l2prot
;
404 cmd
->arg
= (cmd
->arg
& 255) |
405 (ISDN_PROTO_L2_TRANS
<< 8);
407 dev
->v110emu
[idx
] = 0;
410 return dev
->drv
[cmd
->driver
]->interface
->command(cmd
);
414 isdn_all_eaz(int di
, int ch
)
422 cmd
.command
= ISDN_CMD_SETEAZ
;
423 cmd
.parm
.num
[0] = '\0';
428 * Begin of a CAPI like LL<->HL interface, currently used only for
429 * supplementary service (CAPI 2.0 part III)
431 #include "avmb1/capicmd.h" /* this should be moved in a common place */
434 isdn_capi_rec_hl_msg(capi_msg
*cm
) {
439 di
= (cm
->adr
.Controller
& 0x7f) -1;
440 ch
= isdn_dc2minor(di
, (cm
->adr
.Controller
>>8)& 0x7f);
441 switch(cm
->Command
) {
443 /* in the moment only handled in tty */
444 return(isdn_tty_capi_facility(cm
));
451 isdn_status_callback(isdn_ctrl
* c
)
462 i
= isdn_dc2minor(di
, c
->arg
);
463 switch (c
->command
) {
464 case ISDN_STAT_BSENT
:
467 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
469 if (isdn_net_stat_callback(i
, c
))
471 if (isdn_v110_stat_callback(i
, c
))
473 if (isdn_tty_stat_callback(i
, c
))
475 wake_up_interruptible(&dev
->drv
[di
]->snd_waitq
[c
->arg
]);
477 case ISDN_STAT_STAVAIL
:
480 dev
->drv
[di
]->stavail
+= c
->arg
;
481 restore_flags(flags
);
482 wake_up_interruptible(&dev
->drv
[di
]->st_waitq
);
485 dev
->drv
[di
]->flags
|= DRV_FLAG_RUNNING
;
486 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
487 if (dev
->drvmap
[i
] == di
)
488 isdn_all_eaz(di
, dev
->chanmap
[i
]);
489 set_global_features();
492 dev
->drv
[di
]->flags
&= ~DRV_FLAG_RUNNING
;
494 case ISDN_STAT_ICALL
:
497 #ifdef ISDN_DEBUG_STATCALLB
498 printk(KERN_DEBUG
"ICALL (net): %d %ld %s\n", di
, c
->arg
, c
->parm
.num
);
500 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) {
503 cmd
.command
= ISDN_CMD_HANGUP
;
507 /* Try to find a network-interface which will accept incoming call */
508 r
= ((c
->command
== ISDN_STAT_ICALLW
) ? 0 : isdn_net_find_icall(di
, c
->arg
, i
, &c
->parm
.setup
));
511 /* No network-device replies.
513 * These return 0 on no match, 1 on match and
514 * 3 on eventually match, if CID is longer.
516 if (c
->command
== ISDN_STAT_ICALL
)
517 if ((retval
= isdn_tty_find_icall(di
, c
->arg
, &c
->parm
.setup
))) return(retval
);
518 #ifdef CONFIG_ISDN_DIVERSION
520 if ((retval
= divert_if
->stat_callback(c
)))
521 return(retval
); /* processed */
522 #endif CONFIG_ISDN_DIVERSION
523 if ((!retval
) && (dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
)) {
524 /* No tty responding */
527 cmd
.command
= ISDN_CMD_HANGUP
;
533 /* Schedule connection-setup */
537 cmd
.command
= ISDN_CMD_ACCEPTD
;
538 for ( p
= dev
->netdev
; p
; p
= p
->next
)
539 if ( p
->local
->isdn_channel
== cmd
.arg
)
541 strcpy( cmd
.parm
.setup
.eazmsn
, p
->local
->msn
);
548 case 2: /* For calling back, first reject incoming call ... */
549 case 3: /* Interface found, but down, reject call actively */
551 printk(KERN_INFO
"isdn: Rejecting Call\n");
554 cmd
.command
= ISDN_CMD_HANGUP
;
560 /* ... then start callback. */
564 /* Number would eventually match, if longer */
568 #ifdef ISDN_DEBUG_STATCALLB
569 printk(KERN_DEBUG
"ICALL: ret=%d\n", retval
);
576 #ifdef ISDN_DEBUG_STATCALLB
577 printk(KERN_DEBUG
"CINF: %ld %s\n", c
->arg
, c
->parm
.num
);
579 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
581 if (strcmp(c
->parm
.num
, "0"))
582 isdn_net_stat_callback(i
, c
);
583 isdn_tty_stat_callback(i
, c
);
585 case ISDN_STAT_CAUSE
:
586 #ifdef ISDN_DEBUG_STATCALLB
587 printk(KERN_DEBUG
"CAUSE: %ld %s\n", c
->arg
, c
->parm
.num
);
589 printk(KERN_INFO
"isdn: %s,ch%ld cause: %s\n",
590 dev
->drvid
[di
], c
->arg
, c
->parm
.num
);
591 isdn_tty_stat_callback(i
, c
);
592 #ifdef CONFIG_ISDN_DIVERSION
594 divert_if
->stat_callback(c
);
595 #endif CONFIG_ISDN_DIVERSION
597 case ISDN_STAT_DISPLAY
:
598 #ifdef ISDN_DEBUG_STATCALLB
599 printk(KERN_DEBUG
"DISPLAY: %ld %s\n", c
->arg
, c
->parm
.display
);
601 isdn_tty_stat_callback(i
, c
);
602 #ifdef CONFIG_ISDN_DIVERSION
604 divert_if
->stat_callback(c
);
605 #endif CONFIG_ISDN_DIVERSION
607 case ISDN_STAT_DCONN
:
610 #ifdef ISDN_DEBUG_STATCALLB
611 printk(KERN_DEBUG
"DCONN: %ld\n", c
->arg
);
613 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
615 /* Find any net-device, waiting for D-channel setup */
616 if (isdn_net_stat_callback(i
, c
))
618 isdn_v110_stat_callback(i
, c
);
619 /* Find any ttyI, waiting for D-channel setup */
620 if (isdn_tty_stat_callback(i
, c
)) {
623 cmd
.command
= ISDN_CMD_ACCEPTB
;
631 #ifdef ISDN_DEBUG_STATCALLB
632 printk(KERN_DEBUG
"DHUP: %ld\n", c
->arg
);
634 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
636 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
638 /* Signal hangup to network-devices */
639 if (isdn_net_stat_callback(i
, c
))
641 isdn_v110_stat_callback(i
, c
);
642 if (isdn_tty_stat_callback(i
, c
))
644 #ifdef CONFIG_ISDN_DIVERSION
646 divert_if
->stat_callback(c
);
647 #endif CONFIG_ISDN_DIVERSION
650 case ISDN_STAT_BCONN
:
653 #ifdef ISDN_DEBUG_STATCALLB
654 printk(KERN_DEBUG
"BCONN: %ld\n", c
->arg
);
656 /* Signal B-channel-connect to network-devices */
657 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
659 dev
->drv
[di
]->online
|= (1 << (c
->arg
));
661 if (isdn_net_stat_callback(i
, c
))
663 isdn_v110_stat_callback(i
, c
);
664 if (isdn_tty_stat_callback(i
, c
))
670 #ifdef ISDN_DEBUG_STATCALLB
671 printk(KERN_DEBUG
"BHUP: %ld\n", c
->arg
);
673 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
675 dev
->drv
[di
]->online
&= ~(1 << (c
->arg
));
677 #ifdef CONFIG_ISDN_X25
678 /* Signal hangup to network-devices */
679 if (isdn_net_stat_callback(i
, c
))
682 isdn_v110_stat_callback(i
, c
);
683 if (isdn_tty_stat_callback(i
, c
))
686 case ISDN_STAT_NODCH
:
689 #ifdef ISDN_DEBUG_STATCALLB
690 printk(KERN_DEBUG
"NODCH: %ld\n", c
->arg
);
692 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
694 if (isdn_net_stat_callback(i
, c
))
696 if (isdn_tty_stat_callback(i
, c
))
699 case ISDN_STAT_ADDCH
:
700 if (isdn_add_channels(dev
->drv
[di
], di
, c
->arg
, 1))
704 case ISDN_STAT_DISCH
:
707 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
708 if ((dev
->drvmap
[i
] == di
) &&
709 (dev
->chanmap
[i
] == c
->arg
)) {
711 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
713 if (USG_NONE(dev
->usage
[i
])) {
714 dev
->usage
[i
] |= ISDN_USAGE_DISABLED
;
720 restore_flags(flags
);
723 case ISDN_STAT_UNLOAD
:
724 while (dev
->drv
[di
]->locks
> 0) {
728 cmd
.command
= ISDN_CMD_UNLOCK
;
730 dev
->drv
[di
]->locks
--;
734 isdn_tty_stat_callback(i
, c
);
735 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
736 if (dev
->drvmap
[i
] == di
) {
738 dev
->chanmap
[i
] = -1;
739 dev
->usage
[i
] &= ~ISDN_USAGE_DISABLED
;
740 isdn_unregister_devfs(i
);
743 dev
->channels
-= dev
->drv
[di
]->channels
;
744 kfree(dev
->drv
[di
]->rcverr
);
745 kfree(dev
->drv
[di
]->rcvcount
);
746 for (i
= 0; i
< dev
->drv
[di
]->channels
; i
++)
747 isdn_free_queue(&dev
->drv
[di
]->rpqueue
[i
]);
748 kfree(dev
->drv
[di
]->rpqueue
);
749 kfree(dev
->drv
[di
]->rcv_waitq
);
752 dev
->drvid
[di
][0] = '\0';
754 set_global_features();
755 restore_flags(flags
);
757 case ISDN_STAT_L1ERR
:
759 case CAPI_PUT_MESSAGE
:
760 return(isdn_capi_rec_hl_msg(&c
->parm
.cmsg
));
761 #ifdef CONFIG_ISDN_TTY_FAX
762 case ISDN_STAT_FAXIND
:
763 isdn_tty_stat_callback(i
, c
);
766 #ifdef CONFIG_ISDN_AUDIO
767 case ISDN_STAT_AUDIO
:
768 isdn_tty_stat_callback(i
, c
);
771 #ifdef CONFIG_ISDN_DIVERSION
773 case ISDN_STAT_REDIR
:
775 return(divert_if
->stat_callback(c
));
776 #endif CONFIG_ISDN_DIVERSION
784 * Get integer from char-pointer, set pointer to end of number
787 isdn_getnum(char **p
)
791 while (*p
[0] >= '0' && *p
[0] <= '9')
792 v
= ((v
< 0) ? 0 : (v
* 10)) + (int) ((*p
[0]++) - '0');
799 * isdn_readbchan() tries to get data from the read-queue.
800 * It MUST be called with interrupts off.
802 * Be aware that this is not an atomic operation when sleep != 0, even though
803 * interrupts are turned off! Well, like that we are currently only called
804 * on behalf of a read system call on raw device files (which are documented
805 * to be dangerous and for for debugging purpose only). The inode semaphore
806 * takes care that this is not called for the same minor device number while
807 * we are sleeping, but access is not serialized against simultaneous read()
808 * from the corresponding ttyI device. Can other ugly events, like changes
809 * of the mapping (di,ch)<->minor, happen during the sleep? --he
812 isdn_readbchan(int di
, int channel
, u_char
* buf
, u_char
* fp
, int len
, wait_queue_head_t
*sleep
)
824 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
])) {
826 interruptible_sleep_on(sleep
);
830 left
= MIN(len
, dev
->drv
[di
]->rcvcount
[channel
]);
834 if (!(skb
= skb_peek(&dev
->drv
[di
]->rpqueue
[channel
])))
836 #ifdef CONFIG_ISDN_AUDIO
837 if (ISDN_AUDIO_SKB_LOCK(skb
))
839 ISDN_AUDIO_SKB_LOCK(skb
) = 1;
840 if ((ISDN_AUDIO_SKB_DLECOUNT(skb
)) || (dev
->drv
[di
]->DLEflag
& (1 << channel
))) {
842 unsigned long DLEmask
= (1 << channel
);
845 count_pull
= count_put
= 0;
846 while ((count_pull
< skb
->len
) && (left
> 0)) {
848 if (dev
->drv
[di
]->DLEflag
& DLEmask
) {
850 dev
->drv
[di
]->DLEflag
&= ~DLEmask
;
854 dev
->drv
[di
]->DLEflag
|= DLEmask
;
855 (ISDN_AUDIO_SKB_DLECOUNT(skb
))--;
862 if (count_pull
>= skb
->len
)
866 /* No DLE's in buff, so simply copy it */
868 if ((count_pull
= skb
->len
) > left
) {
872 count_put
= count_pull
;
873 memcpy(cp
, skb
->data
, count_put
);
876 #ifdef CONFIG_ISDN_AUDIO
881 memset(fp
, 0, count_put
);
885 /* We got all the data in this buff.
886 * Now we can dequeue it.
890 #ifdef CONFIG_ISDN_AUDIO
891 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
893 skb
= skb_dequeue(&dev
->drv
[di
]->rpqueue
[channel
]);
896 /* Not yet emptied this buff, so it
897 * must stay in the queue, for further calls
898 * but we pull off the data we got until now.
900 skb_pull(skb
, count_pull
);
901 #ifdef CONFIG_ISDN_AUDIO
902 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
905 dev
->drv
[di
]->rcvcount
[channel
] -= count_put
;
911 isdn_minor2drv(int minor
)
913 return (dev
->drvmap
[minor
]);
917 isdn_minor2chan(int minor
)
919 return (dev
->chanmap
[minor
]);
925 static char istatbuf
[2048];
929 sprintf(istatbuf
, "idmap:\t");
930 p
= istatbuf
+ strlen(istatbuf
);
931 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
932 sprintf(p
, "%s ", (dev
->drvmap
[i
] < 0) ? "-" : dev
->drvid
[dev
->drvmap
[i
]]);
933 p
= istatbuf
+ strlen(istatbuf
);
935 sprintf(p
, "\nchmap:\t");
936 p
= istatbuf
+ strlen(istatbuf
);
937 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
938 sprintf(p
, "%d ", dev
->chanmap
[i
]);
939 p
= istatbuf
+ strlen(istatbuf
);
941 sprintf(p
, "\ndrmap:\t");
942 p
= istatbuf
+ strlen(istatbuf
);
943 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
944 sprintf(p
, "%d ", dev
->drvmap
[i
]);
945 p
= istatbuf
+ strlen(istatbuf
);
947 sprintf(p
, "\nusage:\t");
948 p
= istatbuf
+ strlen(istatbuf
);
949 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
950 sprintf(p
, "%d ", dev
->usage
[i
]);
951 p
= istatbuf
+ strlen(istatbuf
);
953 sprintf(p
, "\nflags:\t");
954 p
= istatbuf
+ strlen(istatbuf
);
955 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++) {
957 sprintf(p
, "%ld ", dev
->drv
[i
]->online
);
958 p
= istatbuf
+ strlen(istatbuf
);
961 p
= istatbuf
+ strlen(istatbuf
);
964 sprintf(p
, "\nphone:\t");
965 p
= istatbuf
+ strlen(istatbuf
);
966 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
967 sprintf(p
, "%s ", dev
->num
[i
]);
968 p
= istatbuf
+ strlen(istatbuf
);
974 /* Module interface-code */
977 isdn_info_update(void)
979 infostruct
*p
= dev
->infochain
;
983 p
= (infostruct
*) p
->next
;
985 wake_up_interruptible(&(dev
->info_waitq
));
989 isdn_read(struct file
*file
, char *buf
, size_t count
, loff_t
* off
)
991 uint minor
= MINOR(file
->f_dentry
->d_inode
->i_rdev
);
999 if (off
!= &file
->f_pos
)
1003 if (minor
== ISDN_MINOR_STATUS
) {
1004 if (!file
->private_data
) {
1005 if (file
->f_flags
& O_NONBLOCK
) {
1009 interruptible_sleep_on(&(dev
->info_waitq
));
1012 file
->private_data
= 0;
1013 if ((len
= strlen(p
)) <= count
) {
1014 if (copy_to_user(buf
, p
, len
)) {
1025 if (!dev
->drivers
) {
1029 if (minor
< ISDN_MINOR_CTRL
) {
1030 printk(KERN_WARNING
"isdn_read minor %d obsolete!\n", minor
);
1031 drvidx
= isdn_minor2drv(minor
);
1036 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1040 chidx
= isdn_minor2chan(minor
);
1041 if (!(p
= kmalloc(count
, GFP_KERNEL
))) {
1047 len
= isdn_readbchan(drvidx
, chidx
, p
, 0, count
,
1048 &dev
->drv
[drvidx
]->rcv_waitq
[chidx
]);
1050 restore_flags(flags
);
1051 if (copy_to_user(buf
,p
,len
))
1057 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1058 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1063 if (!dev
->drv
[drvidx
]->stavail
) {
1064 if (file
->f_flags
& O_NONBLOCK
) {
1068 interruptible_sleep_on(&(dev
->drv
[drvidx
]->st_waitq
));
1070 if (dev
->drv
[drvidx
]->interface
->readstat
)
1071 len
= dev
->drv
[drvidx
]->interface
->
1072 readstat(buf
, MIN(count
, dev
->drv
[drvidx
]->stavail
),
1073 1, drvidx
, isdn_minor2chan(minor
));
1079 dev
->drv
[drvidx
]->stavail
-= len
;
1081 dev
->drv
[drvidx
]->stavail
= 0;
1082 restore_flags(flags
);
1087 #ifdef CONFIG_ISDN_PPP
1088 if (minor
<= ISDN_MINOR_PPPMAX
) {
1089 retval
= isdn_ppp_read(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1100 isdn_llseek(struct file
*file
, loff_t offset
, int orig
)
1106 isdn_write(struct file
*file
, const char *buf
, size_t count
, loff_t
* off
)
1108 uint minor
= MINOR(file
->f_dentry
->d_inode
->i_rdev
);
1113 if (off
!= &file
->f_pos
)
1116 if (minor
== ISDN_MINOR_STATUS
)
1122 if (minor
< ISDN_MINOR_CTRL
) {
1123 printk(KERN_WARNING
"isdn_write minor %d obsolete!\n", minor
);
1124 drvidx
= isdn_minor2drv(minor
);
1129 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
)) {
1133 chidx
= isdn_minor2chan(minor
);
1134 while (isdn_writebuf_stub(drvidx
, chidx
, buf
, count
, 1) != count
)
1135 interruptible_sleep_on(&dev
->drv
[drvidx
]->snd_waitq
[chidx
]);
1139 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1140 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1146 * We want to use the isdnctrl device to load the firmware
1148 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1151 if (dev
->drv
[drvidx
]->interface
->writecmd
)
1152 retval
= dev
->drv
[drvidx
]->interface
->
1153 writecmd(buf
, count
, 1, drvidx
, isdn_minor2chan(minor
));
1158 #ifdef CONFIG_ISDN_PPP
1159 if (minor
<= ISDN_MINOR_PPPMAX
) {
1160 retval
= isdn_ppp_write(minor
- ISDN_MINOR_PPP
, file
, buf
, count
);
1171 isdn_poll(struct file
*file
, poll_table
* wait
)
1173 unsigned int mask
= 0;
1174 unsigned int minor
= MINOR(file
->f_dentry
->d_inode
->i_rdev
);
1175 int drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1178 if (minor
== ISDN_MINOR_STATUS
) {
1179 poll_wait(file
, &(dev
->info_waitq
), wait
);
1180 /* mask = POLLOUT | POLLWRNORM; */
1181 if (file
->private_data
) {
1182 mask
|= POLLIN
| POLLRDNORM
;
1186 if (minor
>= ISDN_MINOR_CTRL
&& minor
<= ISDN_MINOR_CTRLMAX
) {
1188 /* driver deregistered while file open */
1192 poll_wait(file
, &(dev
->drv
[drvidx
]->st_waitq
), wait
);
1193 mask
= POLLOUT
| POLLWRNORM
;
1194 if (dev
->drv
[drvidx
]->stavail
) {
1195 mask
|= POLLIN
| POLLRDNORM
;
1199 #ifdef CONFIG_ISDN_PPP
1200 if (minor
<= ISDN_MINOR_PPPMAX
) {
1201 mask
= isdn_ppp_poll(file
, wait
);
1213 isdn_ioctl(struct inode
*inode
, struct file
*file
, uint cmd
, ulong arg
)
1215 uint minor
= MINOR(inode
->i_rdev
);
1226 isdn_ioctl_struct iocts
;
1227 isdn_net_ioctl_phone phone
;
1228 isdn_net_ioctl_cfg cfg
;
1231 #define name iocpar.name
1232 #define bname iocpar.bname
1233 #define iocts iocpar.iocts
1234 #define phone iocpar.phone
1235 #define cfg iocpar.cfg
1237 if (minor
== ISDN_MINOR_STATUS
) {
1245 ulong
*p
= (ulong
*) arg
;
1247 if ((ret
= verify_area(VERIFY_WRITE
, (void *) arg
,
1248 sizeof(ulong
) * ISDN_MAX_CHANNELS
* 2)))
1250 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1251 put_user(dev
->ibytes
[i
], p
++);
1252 put_user(dev
->obytes
[i
], p
++);
1258 #ifdef CONFIG_NETDEVICES
1260 /* Get peer phone number of a connected
1261 * isdn network interface */
1263 if (copy_from_user((char *) &phone
, (char *) arg
, sizeof(phone
)))
1265 return isdn_net_getpeer(&phone
, (isdn_net_ioctl_phone
*) arg
);
1275 if (minor
< ISDN_MINOR_CTRL
) {
1276 drvidx
= isdn_minor2drv(minor
);
1279 chidx
= isdn_minor2chan(minor
);
1280 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1284 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1286 * isdn net devices manage lots of configuration variables as linked lists.
1287 * Those lists must only be manipulated from user space. Some of the ioctl's
1288 * service routines access user space and are not atomic. Therefor, ioctl's
1289 * manipulating the lists and ioctl's sleeping while accessing the lists
1290 * are serialized by means of a semaphore.
1294 printk(KERN_INFO
"INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1297 printk(KERN_INFO
"INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1299 #ifdef CONFIG_NETDEVICES
1301 /* Add a network-interface */
1303 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1309 ret
= down_interruptible(&dev
->sem
);
1310 if( ret
) return ret
;
1311 if ((s
= isdn_net_new(s
, NULL
))) {
1312 if (copy_to_user((char *) arg
, s
, strlen(s
) + 1)){
1322 /* Add a slave to a network-interface */
1324 if (copy_from_user(bname
, (char *) arg
, sizeof(bname
) - 1))
1328 ret
= down_interruptible(&dev
->sem
);
1329 if( ret
) return ret
;
1330 if ((s
= isdn_net_newslave(bname
))) {
1331 if (copy_to_user((char *) arg
, s
, strlen(s
) + 1)){
1341 /* Delete a network-interface */
1343 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1345 ret
= down_interruptible(&dev
->sem
);
1346 if( ret
) return ret
;
1347 ret
= isdn_net_rm(name
);
1353 /* Set configurable parameters of a network-interface */
1355 if (copy_from_user((char *) &cfg
, (char *) arg
, sizeof(cfg
)))
1357 return isdn_net_setcfg(&cfg
);
1361 /* Get configurable parameters of a network-interface */
1363 if (copy_from_user((char *) &cfg
, (char *) arg
, sizeof(cfg
)))
1365 if (!(ret
= isdn_net_getcfg(&cfg
))) {
1366 if (copy_to_user((char *) arg
, (char *) &cfg
, sizeof(cfg
)))
1373 /* Add a phone-number to a network-interface */
1375 if (copy_from_user((char *) &phone
, (char *) arg
, sizeof(phone
)))
1377 ret
= down_interruptible(&dev
->sem
);
1378 if( ret
) return ret
;
1379 ret
= isdn_net_addphone(&phone
);
1385 /* Get list of phone-numbers of a network-interface */
1387 if (copy_from_user((char *) &phone
, (char *) arg
, sizeof(phone
)))
1389 ret
= down_interruptible(&dev
->sem
);
1390 if( ret
) return ret
;
1391 ret
= isdn_net_getphones(&phone
, (char *) arg
);
1397 /* Delete a phone-number of a network-interface */
1399 if (copy_from_user((char *) &phone
, (char *) arg
, sizeof(phone
)))
1401 ret
= down_interruptible(&dev
->sem
);
1402 if( ret
) return ret
;
1403 ret
= isdn_net_delphone(&phone
);
1409 /* Force dialing of a network-interface */
1411 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1413 return isdn_net_force_dial(name
);
1416 #ifdef CONFIG_ISDN_PPP
1420 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1422 return isdn_ppp_dial_slave(name
);
1426 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1428 return isdn_ppp_hangup_slave(name
);
1431 /* Force hangup of a network-interface */
1434 if (copy_from_user(name
, (char *) arg
, sizeof(name
)))
1436 return isdn_net_force_hangup(name
);
1438 #endif /* CONFIG_NETDEVICES */
1440 dev
->net_verbose
= arg
;
1441 printk(KERN_INFO
"isdn: Verbose-Level is %d\n", dev
->net_verbose
);
1445 dev
->global_flags
|= ISDN_GLOBAL_STOPPED
;
1447 dev
->global_flags
&= ~ISDN_GLOBAL_STOPPED
;
1448 printk(KERN_INFO
"isdn: Global Mode %s\n",
1449 (dev
->global_flags
& ISDN_GLOBAL_STOPPED
) ? "stopped" : "running");
1456 if (copy_from_user((char *) &iocts
, (char *) arg
,
1457 sizeof(isdn_ioctl_struct
)))
1459 if (strlen(iocts
.drvid
)) {
1460 if ((p
= strchr(iocts
.drvid
, ',')))
1463 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1464 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1473 dev
->drv
[drvidx
]->flags
|= DRV_FLAG_REJBUS
;
1475 dev
->drv
[drvidx
]->flags
&= ~DRV_FLAG_REJBUS
;
1478 dev
->profd
= current
;
1482 /* Get all Modem-Profiles */
1484 char *p
= (char *) arg
;
1487 if ((ret
= verify_area(VERIFY_WRITE
, (void *) arg
,
1488 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
)
1489 * ISDN_MAX_CHANNELS
)))
1492 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1493 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.profile
,
1496 p
+= ISDN_MODEM_NUMREG
;
1497 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.pmsn
, ISDN_MSNLEN
))
1500 if (copy_to_user(p
, dev
->mdm
.info
[i
].emu
.plmsn
, ISDN_LMSNLEN
))
1504 return (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
+ ISDN_LMSNLEN
) * ISDN_MAX_CHANNELS
;
1509 /* Set all Modem-Profiles */
1511 char *p
= (char *) arg
;
1514 if ((ret
= verify_area(VERIFY_READ
, (void *) arg
,
1515 (ISDN_MODEM_NUMREG
+ ISDN_MSNLEN
)
1516 * ISDN_MAX_CHANNELS
)))
1519 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1520 if (copy_from_user(dev
->mdm
.info
[i
].emu
.profile
, p
,
1523 p
+= ISDN_MODEM_NUMREG
;
1524 if (copy_from_user(dev
->mdm
.info
[i
].emu
.pmsn
, p
, ISDN_MSNLEN
))
1534 /* Set/Get MSN->EAZ-Mapping for a driver */
1537 if (copy_from_user((char *) &iocts
,
1539 sizeof(isdn_ioctl_struct
)))
1541 if (strlen(iocts
.drvid
)) {
1543 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1544 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1552 if (cmd
== IIOCSETMAP
) {
1555 p
= (char *) iocts
.arg
;
1561 if ((ret
= verify_area(VERIFY_READ
, p
, 1)))
1563 get_user(bname
[j
], p
++);
1570 strcpy(dev
->drv
[drvidx
]->msn2eaz
[i
], bname
);
1576 if (j
>= ISDN_MSNLEN
)
1583 p
= (char *) iocts
.arg
;
1584 for (i
= 0; i
< 10; i
++) {
1585 sprintf(bname
, "%s%s",
1586 strlen(dev
->drv
[drvidx
]->msn2eaz
[i
]) ?
1587 dev
->drv
[drvidx
]->msn2eaz
[i
] : "_",
1588 (i
< 9) ? "," : "\0");
1589 if (copy_to_user(p
, bname
, strlen(bname
) + 1))
1599 if (copy_to_user((char *) arg
, (char *) &dev
, sizeof(ulong
)))
1606 if ((cmd
& IIOCDRVCTL
) == IIOCDRVCTL
)
1607 cmd
= ((cmd
>> _IOC_NRSHIFT
) & _IOC_NRMASK
) & ISDN_DRVIOCTL_MASK
;
1613 if (copy_from_user((char *) &iocts
, (char *) arg
, sizeof(isdn_ioctl_struct
)))
1615 if (strlen(iocts
.drvid
)) {
1616 if ((p
= strchr(iocts
.drvid
, ',')))
1619 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
1620 if (!(strcmp(dev
->drvid
[i
], iocts
.drvid
))) {
1628 if ((ret
= verify_area(VERIFY_WRITE
, (void *) arg
,
1629 sizeof(isdn_ioctl_struct
))))
1632 c
.command
= ISDN_CMD_IOCTL
;
1634 memcpy(c
.parm
.num
, (char *) &iocts
.arg
, sizeof(ulong
));
1635 ret
= isdn_command(&c
);
1636 memcpy((char *) &iocts
.arg
, c
.parm
.num
, sizeof(ulong
));
1637 if (copy_to_user((char *) arg
, &iocts
, sizeof(isdn_ioctl_struct
)))
1644 #ifdef CONFIG_ISDN_PPP
1645 if (minor
<= ISDN_MINOR_PPPMAX
)
1646 return (isdn_ppp_ioctl(minor
- ISDN_MINOR_PPP
, file
, cmd
, arg
));
1658 * Open the device code.
1661 isdn_open(struct inode
*ino
, struct file
*filep
)
1663 uint minor
= MINOR(ino
->i_rdev
);
1666 int retval
= -ENODEV
;
1669 if (minor
== ISDN_MINOR_STATUS
) {
1672 if ((p
= (infostruct
*) kmalloc(sizeof(infostruct
), GFP_KERNEL
))) {
1673 p
->next
= (char *) dev
->infochain
;
1674 p
->private = (char *) &(filep
->private_data
);
1676 /* At opening we allow a single update */
1677 filep
->private_data
= (char *) 1;
1687 if (minor
< ISDN_MINOR_CTRL
) {
1688 printk(KERN_WARNING
"isdn_open minor %d obsolete!\n", minor
);
1689 drvidx
= isdn_minor2drv(minor
);
1692 chidx
= isdn_minor2chan(minor
);
1693 if (!(dev
->drv
[drvidx
]->flags
& DRV_FLAG_RUNNING
))
1695 if (!(dev
->drv
[drvidx
]->online
& (1 << chidx
)))
1697 isdn_lock_drivers();
1701 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1702 drvidx
= isdn_minor2drv(minor
- ISDN_MINOR_CTRL
);
1705 isdn_lock_drivers();
1709 #ifdef CONFIG_ISDN_PPP
1710 if (minor
<= ISDN_MINOR_PPPMAX
) {
1711 retval
= isdn_ppp_open(minor
- ISDN_MINOR_PPP
, filep
);
1713 isdn_lock_drivers();
1722 isdn_close(struct inode
*ino
, struct file
*filep
)
1724 uint minor
= MINOR(ino
->i_rdev
);
1727 if (minor
== ISDN_MINOR_STATUS
) {
1728 infostruct
*p
= dev
->infochain
;
1729 infostruct
*q
= NULL
;
1732 if (p
->private == (char *) &(filep
->private_data
)) {
1736 dev
->infochain
= (infostruct
*) (p
->next
);
1741 p
= (infostruct
*) (p
->next
);
1743 printk(KERN_WARNING
"isdn: No private data while closing isdnctrl\n");
1746 isdn_unlock_drivers();
1747 if (minor
< ISDN_MINOR_CTRL
)
1749 if (minor
<= ISDN_MINOR_CTRLMAX
) {
1750 if (dev
->profd
== current
)
1754 #ifdef CONFIG_ISDN_PPP
1755 if (minor
<= ISDN_MINOR_PPPMAX
)
1756 isdn_ppp_release(minor
- ISDN_MINOR_PPP
, filep
);
1764 static struct file_operations isdn_fops
=
1767 llseek
: isdn_llseek
,
1773 release
: isdn_close
,
1777 isdn_map_eaz2msn(char *msn
, int di
)
1779 driver
*this = dev
->drv
[di
];
1782 if (strlen(msn
) == 1) {
1784 if ((i
>= 0) && (i
<= 9))
1785 if (strlen(this->msn2eaz
[i
]))
1786 return (this->msn2eaz
[i
]);
1792 * Find an unused ISDN-channel, whose feature-flags match the
1793 * given L2- and L3-protocols.
1795 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1798 isdn_get_free_channel(int usage
, int l2_proto
, int l3_proto
, int pre_dev
1799 ,int pre_chan
, char *msn
)
1808 features
= ((1 << l2_proto
) | (0x10000 << l3_proto
));
1809 vfeatures
= (((1 << l2_proto
) | (0x10000 << l3_proto
)) &
1810 ~(ISDN_FEATURE_L2_V11096
|ISDN_FEATURE_L2_V11019
|ISDN_FEATURE_L2_V11038
));
1811 /* If Layer-2 protocol is V.110, accept drivers with
1812 * transparent feature even if these don't support V.110
1813 * because we can emulate this in linklevel.
1815 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1816 if (USG_NONE(dev
->usage
[i
]) &&
1817 (dev
->drvmap
[i
] != -1)) {
1818 int d
= dev
->drvmap
[i
];
1819 if ((dev
->usage
[i
] & ISDN_USAGE_EXCLUSIVE
) &&
1820 ((pre_dev
!= d
) || (pre_chan
!= dev
->chanmap
[i
])))
1822 if (!strcmp(isdn_map_eaz2msn(msn
, d
), "-"))
1824 if (dev
->usage
[i
] & ISDN_USAGE_DISABLED
)
1825 continue; /* usage not allowed */
1826 if (dev
->drv
[d
]->flags
& DRV_FLAG_RUNNING
) {
1827 if (((dev
->drv
[d
]->interface
->features
& features
) == features
) ||
1828 (((dev
->drv
[d
]->interface
->features
& vfeatures
) == vfeatures
) &&
1829 (dev
->drv
[d
]->interface
->features
& ISDN_FEATURE_L2_TRANS
))) {
1830 if ((pre_dev
< 0) || (pre_chan
< 0)) {
1831 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1832 dev
->usage
[i
] |= usage
;
1834 restore_flags(flags
);
1837 if ((pre_dev
== d
) && (pre_chan
== dev
->chanmap
[i
])) {
1838 dev
->usage
[i
] &= ISDN_USAGE_EXCLUSIVE
;
1839 dev
->usage
[i
] |= usage
;
1841 restore_flags(flags
);
1848 restore_flags(flags
);
1853 * Set state of ISDN-channel to 'unused'
1856 isdn_free_channel(int di
, int ch
, int usage
)
1863 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1864 if (((!usage
) || ((dev
->usage
[i
] & ISDN_USAGE_MASK
) == usage
)) &&
1865 (dev
->drvmap
[i
] == di
) &&
1866 (dev
->chanmap
[i
] == ch
)) {
1867 dev
->usage
[i
] &= (ISDN_USAGE_NONE
| ISDN_USAGE_EXCLUSIVE
);
1868 strcpy(dev
->num
[i
], "???");
1871 // 20.10.99 JIM, try to reinitialize v110 !
1872 dev
->v110emu
[i
] = 0;
1873 atomic_set(&(dev
->v110use
[i
]), 0);
1874 isdn_v110_close(dev
->v110
[i
]);
1875 dev
->v110
[i
] = NULL
;
1876 // 20.10.99 JIM, try to reinitialize v110 !
1878 isdn_free_queue(&dev
->drv
[di
]->rpqueue
[ch
]);
1880 restore_flags(flags
);
1884 * Cancel Exclusive-Flag for ISDN-channel
1887 isdn_unexclusive_channel(int di
, int ch
)
1894 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1895 if ((dev
->drvmap
[i
] == di
) &&
1896 (dev
->chanmap
[i
] == ch
)) {
1897 dev
->usage
[i
] &= ~ISDN_USAGE_EXCLUSIVE
;
1899 restore_flags(flags
);
1902 restore_flags(flags
);
1906 * writebuf replacement for SKB_ABLE drivers
1909 isdn_writebuf_stub(int drvidx
, int chan
, const u_char
* buf
, int len
,
1913 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1914 struct sk_buff
*skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1918 skb_reserve(skb
, hl
);
1920 copy_from_user(skb_put(skb
, len
), buf
, len
);
1922 memcpy(skb_put(skb
, len
), buf
, len
);
1923 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, 1, skb
);
1927 dev
->obytes
[isdn_dc2minor(drvidx
, chan
)] += ret
;
1932 * Return: length of data on success, -ERRcode on failure.
1935 isdn_writebuf_skb_stub(int drvidx
, int chan
, int ack
, struct sk_buff
*skb
)
1938 struct sk_buff
*nskb
= NULL
;
1939 int v110_ret
= skb
->len
;
1940 int idx
= isdn_dc2minor(drvidx
, chan
);
1942 if (dev
->v110
[idx
]) {
1943 atomic_inc(&dev
->v110use
[idx
]);
1944 nskb
= isdn_v110_encode(dev
->v110
[idx
], skb
);
1945 atomic_dec(&dev
->v110use
[idx
]);
1948 v110_ret
= *((int *)nskb
->data
);
1949 skb_pull(nskb
, sizeof(int));
1951 dev_kfree_skb(nskb
);
1954 /* V.110 must always be acknowledged */
1956 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, nskb
);
1958 int hl
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1960 if( skb_headroom(skb
) < hl
){
1962 * This should only occur when new HL driver with
1963 * increased hl_hdrlen was loaded after netdevice
1964 * was created and connected to the new driver.
1966 * The V.110 branch (re-allocates on its own) does
1969 struct sk_buff
* skb_tmp
;
1971 skb_tmp
= skb_realloc_headroom(skb
, hl
);
1972 printk(KERN_DEBUG
"isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp
? "" : " failed");
1973 if (!skb_tmp
) return -ENOMEM
; /* 0 better? */
1974 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb_tmp
);
1978 dev_kfree_skb(skb_tmp
);
1981 ret
= dev
->drv
[drvidx
]->interface
->writebuf_skb(drvidx
, chan
, ack
, skb
);
1985 dev
->obytes
[idx
] += ret
;
1986 if (dev
->v110
[idx
]) {
1987 atomic_inc(&dev
->v110use
[idx
]);
1988 dev
->v110
[idx
]->skbuser
++;
1989 atomic_dec(&dev
->v110use
[idx
]);
1990 /* For V.110 return unencoded data length */
1992 /* if the complete frame was send we free the skb;
1993 if not upper function will requeue the skb */
1994 if (ret
== skb
->len
)
1999 dev_kfree_skb(nskb
);
2004 register_isdn_module(isdn_module
*m
) {
2009 unregister_isdn_module(isdn_module
*m
) {
2014 isdn_add_channels(driver
*d
, int drvidx
, int n
, int adding
)
2019 init_waitqueue_head(&d
->st_waitq
);
2020 if (d
->flags
& DRV_FLAG_RUNNING
)
2022 if (n
< 1) return 0;
2024 m
= (adding
) ? d
->channels
+ n
: n
;
2026 if (dev
->channels
+ n
> ISDN_MAX_CHANNELS
) {
2027 printk(KERN_WARNING
"register_isdn: Max. %d channels supported\n",
2032 if ((adding
) && (d
->rcverr
))
2034 if (!(d
->rcverr
= (int *) kmalloc(sizeof(int) * m
, GFP_KERNEL
))) {
2035 printk(KERN_WARNING
"register_isdn: Could not alloc rcverr\n");
2038 memset((char *) d
->rcverr
, 0, sizeof(int) * m
);
2040 if ((adding
) && (d
->rcvcount
))
2042 if (!(d
->rcvcount
= (int *) kmalloc(sizeof(int) * m
, GFP_KERNEL
))) {
2043 printk(KERN_WARNING
"register_isdn: Could not alloc rcvcount\n");
2044 if (!adding
) kfree(d
->rcverr
);
2047 memset((char *) d
->rcvcount
, 0, sizeof(int) * m
);
2049 if ((adding
) && (d
->rpqueue
)) {
2050 for (j
= 0; j
< d
->channels
; j
++)
2051 isdn_free_queue(&d
->rpqueue
[j
]);
2055 (struct sk_buff_head
*) kmalloc(sizeof(struct sk_buff_head
) * m
, GFP_KERNEL
))) {
2056 printk(KERN_WARNING
"register_isdn: Could not alloc rpqueue\n");
2063 for (j
= 0; j
< m
; j
++) {
2064 skb_queue_head_init(&d
->rpqueue
[j
]);
2067 if ((adding
) && (d
->rcv_waitq
))
2068 kfree(d
->rcv_waitq
);
2069 d
->rcv_waitq
= (wait_queue_head_t
*)
2070 kmalloc(sizeof(wait_queue_head_t
) * 2 * m
, GFP_KERNEL
);
2071 if (!d
->rcv_waitq
) {
2072 printk(KERN_WARNING
"register_isdn: Could not alloc rcv_waitq\n");
2080 d
->snd_waitq
= d
->rcv_waitq
+ m
;
2081 for (j
= 0; j
< m
; j
++) {
2082 init_waitqueue_head(&d
->rcv_waitq
[j
]);
2083 init_waitqueue_head(&d
->snd_waitq
[j
]);
2089 for (j
= d
->channels
; j
< m
; j
++)
2090 for (k
= 0; k
< ISDN_MAX_CHANNELS
; k
++)
2091 if (dev
->chanmap
[k
] < 0) {
2092 dev
->chanmap
[k
] = j
;
2093 dev
->drvmap
[k
] = drvidx
;
2094 isdn_register_devfs(k
);
2097 restore_flags(flags
);
2103 * Low-level-driver registration
2107 set_global_features(void)
2111 dev
->global_features
= 0;
2112 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++) {
2113 if (!dev
->drv
[drvidx
])
2115 if (dev
->drv
[drvidx
]->interface
)
2116 dev
->global_features
|= dev
->drv
[drvidx
]->interface
->features
;
2120 #ifdef CONFIG_ISDN_DIVERSION
2121 extern isdn_divert_if
*divert_if
;
2123 static char *map_drvname(int di
)
2125 if ((di
< 0) || (di
>= ISDN_MAX_DRIVERS
))
2127 return(dev
->drvid
[di
]); /* driver name */
2130 static int map_namedrv(char *id
)
2133 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2134 { if (!strcmp(dev
->drvid
[i
],id
))
2140 int DIVERT_REG_NAME(isdn_divert_if
*i_div
)
2142 if (i_div
->if_magic
!= DIVERT_IF_MAGIC
)
2143 return(DIVERT_VER_ERR
);
2146 case DIVERT_CMD_REL
:
2147 if (divert_if
!= i_div
)
2148 return(DIVERT_REL_ERR
);
2149 divert_if
= NULL
; /* free interface */
2151 return(DIVERT_NO_ERR
);
2153 case DIVERT_CMD_REG
:
2155 return(DIVERT_REG_ERR
);
2156 i_div
->ll_cmd
= isdn_command
; /* set command function */
2157 i_div
->drv_to_name
= map_drvname
;
2158 i_div
->name_to_drv
= map_namedrv
;
2160 divert_if
= i_div
; /* remember interface */
2161 return(DIVERT_NO_ERR
);
2164 return(DIVERT_CMD_ERR
);
2166 } /* DIVERT_REG_NAME */
2168 EXPORT_SYMBOL(DIVERT_REG_NAME
);
2170 #endif CONFIG_ISDN_DIVERSION
2173 EXPORT_SYMBOL(register_isdn
);
2174 EXPORT_SYMBOL(register_isdn_module
);
2175 EXPORT_SYMBOL(unregister_isdn_module
);
2176 #ifdef CONFIG_ISDN_PPP
2177 EXPORT_SYMBOL(isdn_ppp_register_compressor
);
2178 EXPORT_SYMBOL(isdn_ppp_unregister_compressor
);
2182 register_isdn(isdn_if
* i
)
2189 if (dev
->drivers
>= ISDN_MAX_DRIVERS
) {
2190 printk(KERN_WARNING
"register_isdn: Max. %d drivers supported\n",
2194 if (!i
->writebuf_skb
) {
2195 printk(KERN_WARNING
"register_isdn: No write routine given.\n");
2198 if (!(d
= (driver
*) kmalloc(sizeof(driver
), GFP_KERNEL
))) {
2199 printk(KERN_WARNING
"register_isdn: Could not alloc driver-struct\n");
2202 memset((char *) d
, 0, sizeof(driver
));
2204 d
->maxbufsize
= i
->maxbufsize
;
2207 d
->flags
= DRV_FLAG_LOADED
;
2211 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2212 if (!dev
->drv
[drvidx
])
2214 if (isdn_add_channels(d
, drvidx
, i
->channels
, 0)) {
2218 i
->channels
= drvidx
;
2219 i
->rcvcallb_skb
= isdn_receive_skb_callback
;
2220 i
->statcallb
= isdn_status_callback
;
2222 sprintf(i
->id
, "line%d", drvidx
);
2225 for (j
= 0; j
< drvidx
; j
++)
2226 if (!strcmp(i
->id
, dev
->drvid
[j
]))
2227 sprintf(i
->id
, "line%d", drvidx
);
2228 dev
->drv
[drvidx
] = d
;
2229 strcpy(dev
->drvid
[drvidx
], i
->id
);
2232 set_global_features();
2233 restore_flags(flags
);
2238 *****************************************************************************
2239 * And now the modules code.
2240 *****************************************************************************
2243 extern int printk(const char *fmt
,...);
2246 #define isdn_init init_module
2250 isdn_getrev(const char *revision
)
2255 if ((p
= strchr(revision
, ':'))) {
2257 p
= strchr(rev
, '$');
2264 #ifdef CONFIG_DEVFS_FS
2266 static devfs_handle_t devfs_handle
;
2268 static void isdn_register_devfs(int k
)
2272 sprintf (buf
, "isdn%d", k
);
2273 dev
->devfs_handle_isdnX
[k
] =
2274 devfs_register (devfs_handle
, buf
, DEVFS_FL_DEFAULT
,
2275 ISDN_MAJOR
, ISDN_MINOR_B
+ k
,0600 | S_IFCHR
,
2277 sprintf (buf
, "isdnctrl%d", k
);
2278 dev
->devfs_handle_isdnctrlX
[k
] =
2279 devfs_register (devfs_handle
, buf
, DEVFS_FL_DEFAULT
,
2280 ISDN_MAJOR
, ISDN_MINOR_CTRL
+ k
, 0600 | S_IFCHR
,
2284 static void isdn_unregister_devfs(int k
)
2286 devfs_unregister (dev
->devfs_handle_isdnX
[k
]);
2287 devfs_unregister (dev
->devfs_handle_isdnctrlX
[k
]);
2290 static void isdn_init_devfs(void)
2292 # ifdef CONFIG_ISDN_PPP
2296 devfs_handle
= devfs_mk_dir (NULL
, "isdn", NULL
);
2297 # ifdef CONFIG_ISDN_PPP
2298 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2301 sprintf (buf
, "ippp%d", i
);
2302 dev
->devfs_handle_ipppX
[i
] =
2303 devfs_register (devfs_handle
, buf
, DEVFS_FL_DEFAULT
,
2304 ISDN_MAJOR
, ISDN_MINOR_PPP
+ i
,
2305 0600 | S_IFCHR
, &isdn_fops
, NULL
);
2309 dev
->devfs_handle_isdninfo
=
2310 devfs_register (devfs_handle
, "isdninfo", DEVFS_FL_DEFAULT
,
2311 ISDN_MAJOR
, ISDN_MINOR_STATUS
, 0600 | S_IFCHR
,
2313 dev
->devfs_handle_isdnctrl
=
2314 devfs_register (devfs_handle
, "isdnctrl", DEVFS_FL_DEFAULT
,
2315 ISDN_MAJOR
, ISDN_MINOR_CTRL
, 0600 | S_IFCHR
,
2319 static void isdn_cleanup_devfs(void)
2321 # ifdef CONFIG_ISDN_PPP
2323 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
2324 devfs_unregister (dev
->devfs_handle_ipppX
[i
]);
2326 devfs_unregister (dev
->devfs_handle_isdninfo
);
2327 devfs_unregister (dev
->devfs_handle_isdnctrl
);
2328 devfs_unregister (devfs_handle
);
2331 #else /* CONFIG_DEVFS_FS */
2332 static void isdn_register_devfs(int dummy
)
2337 static void isdn_unregister_devfs(int dummy
)
2342 static void isdn_init_devfs(void)
2347 static void isdn_cleanup_devfs(void)
2352 #endif /* CONFIG_DEVFS_FS */
2355 * Allocate and initialize all data, register modem-devices
2363 if (!(dev
= (isdn_dev
*) vmalloc(sizeof(isdn_dev
)))) {
2364 printk(KERN_WARNING
"isdn: Could not allocate device-struct.\n");
2367 memset((char *) dev
, 0, sizeof(isdn_dev
));
2368 init_timer(&dev
->timer
);
2369 dev
->timer
.function
= isdn_timer_funct
;
2370 init_MUTEX(&dev
->sem
);
2371 init_waitqueue_head(&dev
->info_waitq
);
2372 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2373 dev
->drvmap
[i
] = -1;
2374 dev
->chanmap
[i
] = -1;
2376 strcpy(dev
->num
[i
], "???");
2377 init_waitqueue_head(&dev
->mdm
.info
[i
].open_wait
);
2378 init_waitqueue_head(&dev
->mdm
.info
[i
].close_wait
);
2380 if (devfs_register_chrdev(ISDN_MAJOR
, "isdn", &isdn_fops
)) {
2381 printk(KERN_WARNING
"isdn: Could not register control devices\n");
2386 if ((i
= isdn_tty_modem_init()) < 0) {
2387 printk(KERN_WARNING
"isdn: Could not register tty devices\n");
2389 tty_unregister_driver(&dev
->mdm
.cua_modem
);
2391 tty_unregister_driver(&dev
->mdm
.tty_modem
);
2393 isdn_cleanup_devfs();
2394 devfs_unregister_chrdev(ISDN_MAJOR
, "isdn");
2397 #ifdef CONFIG_ISDN_PPP
2398 if (isdn_ppp_init() < 0) {
2399 printk(KERN_WARNING
"isdn: Could not create PPP-device-structs\n");
2400 tty_unregister_driver(&dev
->mdm
.tty_modem
);
2401 tty_unregister_driver(&dev
->mdm
.cua_modem
);
2402 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
2403 kfree(dev
->mdm
.info
[i
].xmit_buf
- 4);
2404 isdn_cleanup_devfs();
2405 devfs_unregister_chrdev(ISDN_MAJOR
, "isdn");
2409 #endif /* CONFIG_ISDN_PPP */
2411 strcpy(tmprev
, isdn_revision
);
2412 printk(KERN_NOTICE
"ISDN subsystem Rev: %s/", isdn_getrev(tmprev
));
2413 strcpy(tmprev
, isdn_tty_revision
);
2414 printk("%s/", isdn_getrev(tmprev
));
2415 strcpy(tmprev
, isdn_net_revision
);
2416 printk("%s/", isdn_getrev(tmprev
));
2417 strcpy(tmprev
, isdn_ppp_revision
);
2418 printk("%s/", isdn_getrev(tmprev
));
2419 strcpy(tmprev
, isdn_audio_revision
);
2420 printk("%s/", isdn_getrev(tmprev
));
2421 strcpy(tmprev
, isdn_v110_revision
);
2422 printk("%s", isdn_getrev(tmprev
));
2425 printk(" loaded\n");
2439 cleanup_module(void)
2444 #ifdef CONFIG_ISDN_PPP
2449 if (isdn_net_rmall() < 0) {
2450 printk(KERN_WARNING
"isdn: net-device busy, remove cancelled\n");
2451 restore_flags(flags
);
2454 if (tty_unregister_driver(&dev
->mdm
.tty_modem
)) {
2455 printk(KERN_WARNING
"isdn: ttyI-device busy, remove cancelled\n");
2456 restore_flags(flags
);
2459 if (tty_unregister_driver(&dev
->mdm
.cua_modem
)) {
2460 printk(KERN_WARNING
"isdn: cui-device busy, remove cancelled\n");
2461 restore_flags(flags
);
2464 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2465 isdn_tty_cleanup_xmit(&dev
->mdm
.info
[i
]);
2466 kfree(dev
->mdm
.info
[i
].xmit_buf
- 4);
2467 #ifdef CONFIG_ISDN_TTY_FAX
2468 kfree(dev
->mdm
.info
[i
].fax
);
2471 if (devfs_unregister_chrdev(ISDN_MAJOR
, "isdn") != 0) {
2472 printk(KERN_WARNING
"isdn: controldevice busy, remove cancelled\n");
2473 restore_flags(flags
);
2475 isdn_cleanup_devfs();
2476 del_timer(&dev
->timer
);
2477 restore_flags(flags
);
2478 /* call vfree with interrupts enabled, else it will hang */
2480 printk(KERN_NOTICE
"ISDN-subsystem unloaded\n");