1 /* $Id: isdn_common.c,v 1.1.4.1 2001/11/20 14:19:34 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 software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/version.h>
18 #include <linux/poll.h>
19 #include <linux/vmalloc.h>
20 #include <linux/isdn.h>
21 #include <linux/smp_lock.h>
22 #include "isdn_common.h"
26 #ifdef CONFIG_ISDN_AUDIO
27 #include "isdn_audio.h"
29 #ifdef CONFIG_ISDN_DIVERSION_MODULE
30 #define CONFIG_ISDN_DIVERSION
32 #ifdef CONFIG_ISDN_DIVERSION
33 #include <linux/isdn_divertif.h>
34 #endif /* CONFIG_ISDN_DIVERSION */
35 #include "isdn_v110.h"
36 #include <linux/devfs_fs_kernel.h>
39 #undef ISDN_DEBUG_STATCALLB
41 MODULE_DESCRIPTION("ISDN4Linux: link layer");
42 MODULE_AUTHOR("Fritz Elfert");
43 MODULE_LICENSE("GPL");
47 static char *isdn_revision = "$Revision: 1.1.4.1 $";
49 extern char *isdn_net_revision;
50 extern char *isdn_tty_revision;
51 #ifdef CONFIG_ISDN_PPP
52 extern char *isdn_ppp_revision;
54 static char *isdn_ppp_revision = ": none $";
56 #ifdef CONFIG_ISDN_AUDIO
57 extern char *isdn_audio_revision;
59 static char *isdn_audio_revision = ": none $";
61 extern char *isdn_v110_revision;
63 #ifdef CONFIG_ISDN_DIVERSION
64 static isdn_divert_if *divert_if; /* = NULL */
65 #endif /* CONFIG_ISDN_DIVERSION */
68 static int isdn_writebuf_stub(int, int, const u_char *, int, int);
69 static void set_global_features(void);
70 static void isdn_register_devfs(int);
71 static void isdn_unregister_devfs(int);
72 static int isdn_wildmat(char *s, char *p);
75 isdn_lock_drivers(void)
80 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
86 cmd.command = ISDN_CMD_LOCK;
93 isdn_MOD_INC_USE_COUNT(void)
100 isdn_unlock_drivers(void)
104 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
108 if (dev->drv[i]->locks > 0) {
113 cmd.command = ISDN_CMD_UNLOCK;
115 dev->drv[i]->locks--;
121 isdn_MOD_DEC_USE_COUNT(void)
124 isdn_unlock_drivers();
127 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
129 isdn_dumppkt(char *s, u_char * p, int len, int dumplen)
133 printk(KERN_DEBUG "%s(%d) ", s, len);
134 for (dumpc = 0; (dumpc < dumplen) && (len); len--, dumpc++)
135 printk(" %02x", *p++);
141 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
142 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
145 isdn_star(char *s, char *p)
147 while (isdn_wildmat(s, p)) {
155 * Shell-type Pattern-matching for incoming caller-Ids
156 * This function gets a string in s and checks, if it matches the pattern
162 * 2 = no match. Would eventually match, if s would be longer.
166 * '?' matches one character
167 * '*' matches zero or more characters
168 * [xyz] matches the set of characters in brackets.
169 * [^xyz] matches any single character not in the set of characters
173 isdn_wildmat(char *s, char *p)
176 register int matched;
177 register int reverse;
178 register int nostar = 1;
186 * Literal match with following character,
192 return (*s == '\0')?2:1;
195 /* Match anything. */
201 /* Trailing star matches everything. */
202 return (*++p ? isdn_star(s, p) : 0);
204 /* [^....] means inverse character class. */
205 if ((reverse = (p[1] == '^')))
207 for (last = 0, matched = 0; *++p && (*p != ']'); last = *p)
208 /* This next line requires a good C compiler. */
209 if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
211 if (matched == reverse)
215 return (*s == '\0')?0:nostar;
218 int isdn_msncmp( const char * msn1, const char * msn2 )
220 char TmpMsn1[ ISDN_MSNLEN ];
221 char TmpMsn2[ ISDN_MSNLEN ];
224 for ( p = TmpMsn1; *msn1 && *msn1 != ':'; ) // Strip off a SPID
228 for ( p = TmpMsn2; *msn2 && *msn2 != ':'; ) // Strip off a SPID
232 return isdn_wildmat( TmpMsn1, TmpMsn2 );
236 isdn_dc2minor(int di, int ch)
239 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
240 if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
245 static int isdn_timer_cnt1 = 0;
246 static int isdn_timer_cnt2 = 0;
247 static int isdn_timer_cnt3 = 0;
250 isdn_timer_funct(ulong dummy)
252 int tf = dev->tflags;
253 if (tf & ISDN_TIMER_FAST) {
254 if (tf & ISDN_TIMER_MODEMREAD)
255 isdn_tty_readmodem();
256 if (tf & ISDN_TIMER_MODEMPLUS)
257 isdn_tty_modem_escape();
258 if (tf & ISDN_TIMER_MODEMXMIT)
259 isdn_tty_modem_xmit();
261 if (tf & ISDN_TIMER_SLOW) {
262 if (++isdn_timer_cnt1 >= ISDN_TIMER_02SEC) {
264 if (tf & ISDN_TIMER_NETDIAL)
267 if (++isdn_timer_cnt2 >= ISDN_TIMER_1SEC) {
269 if (tf & ISDN_TIMER_NETHANGUP)
271 if (++isdn_timer_cnt3 >= ISDN_TIMER_RINGING) {
273 if (tf & ISDN_TIMER_MODEMRING)
274 isdn_tty_modem_ring();
276 if (tf & ISDN_TIMER_CARRIER)
277 isdn_tty_carrier_timeout();
286 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
287 restore_flags(flags);
292 isdn_timer_ctrl(int tf, int onoff)
299 if ((tf & ISDN_TIMER_SLOW) && (!(dev->tflags & ISDN_TIMER_SLOW))) {
300 /* If the slow-timer wasn't activated until now */
304 old_tflags = dev->tflags;
309 if (dev->tflags && !old_tflags)
310 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
311 restore_flags(flags);
315 * Receive a packet from B-Channel. (Called from low-level-module)
318 isdn_receive_skb_callback(int di, int channel, struct sk_buff *skb)
322 if ((i = isdn_dc2minor(di, channel)) == -1) {
326 /* Update statistics */
327 dev->ibytes[i] += skb->len;
329 /* First, try to deliver data to network-device */
330 if (isdn_net_rcv_skb(i, skb))
334 * makes sense for async streams only, so it is
335 * called after possible net-device delivery.
338 atomic_inc(&dev->v110use[i]);
339 skb = isdn_v110_decode(dev->v110[i], skb);
340 atomic_dec(&dev->v110use[i]);
345 /* No network-device found, deliver to tty or raw-channel */
347 if (isdn_tty_rcv_skb(i, di, channel, skb))
349 wake_up_interruptible(&dev->drv[di]->rcv_waitq[channel]);
355 * Intercept command from Linklevel to Lowlevel.
356 * If layer 2 protocol is V.110 and this is not supported by current
357 * lowlevel-driver, use driver's transparent mode and handle V.110 in
361 isdn_command(isdn_ctrl *cmd)
363 if (cmd->driver == -1) {
364 printk(KERN_WARNING "isdn_command command(%x) driver -1\n", cmd->command);
367 if (cmd->command == ISDN_CMD_SETL2) {
368 int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
369 unsigned long l2prot = (cmd->arg >> 8) & 255;
370 unsigned long features = (dev->drv[cmd->driver]->interface->features
371 >> ISDN_FEATURE_L2_SHIFT) &
372 ISDN_FEATURE_L2_MASK;
373 unsigned long l2_feature = (1 << l2prot);
376 case ISDN_PROTO_L2_V11096:
377 case ISDN_PROTO_L2_V11019:
378 case ISDN_PROTO_L2_V11038:
379 /* If V.110 requested, but not supported by
380 * HL-driver, set emulator-flag and change
381 * Layer-2 to transparent
383 if (!(features & l2_feature)) {
384 dev->v110emu[idx] = l2prot;
385 cmd->arg = (cmd->arg & 255) |
386 (ISDN_PROTO_L2_TRANS << 8);
388 dev->v110emu[idx] = 0;
391 return dev->drv[cmd->driver]->interface->command(cmd);
395 isdn_all_eaz(int di, int ch)
403 cmd.command = ISDN_CMD_SETEAZ;
404 cmd.parm.num[0] = '\0';
409 * Begin of a CAPI like LL<->HL interface, currently used only for
410 * supplementary service (CAPI 2.0 part III)
412 #include "avmb1/capicmd.h" /* this should be moved in a common place */
415 isdn_capi_rec_hl_msg(capi_msg *cm) {
420 di = (cm->adr.Controller & 0x7f) -1;
421 ch = isdn_dc2minor(di, (cm->adr.Controller>>8)& 0x7f);
422 switch(cm->Command) {
424 /* in the moment only handled in tty */
425 return(isdn_tty_capi_facility(cm));
432 isdn_status_callback(isdn_ctrl * c)
443 i = isdn_dc2minor(di, c->arg);
444 switch (c->command) {
445 case ISDN_STAT_BSENT:
448 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
450 if (isdn_net_stat_callback(i, c))
452 if (isdn_v110_stat_callback(i, c))
454 if (isdn_tty_stat_callback(i, c))
456 wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
458 case ISDN_STAT_STAVAIL:
461 dev->drv[di]->stavail += c->arg;
462 restore_flags(flags);
463 wake_up_interruptible(&dev->drv[di]->st_waitq);
466 dev->drv[di]->flags |= DRV_FLAG_RUNNING;
467 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
468 if (dev->drvmap[i] == di)
469 isdn_all_eaz(di, dev->chanmap[i]);
470 set_global_features();
473 dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
475 case ISDN_STAT_ICALL:
478 #ifdef ISDN_DEBUG_STATCALLB
479 printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
481 if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
484 cmd.command = ISDN_CMD_HANGUP;
488 /* Try to find a network-interface which will accept incoming call */
489 r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
492 /* No network-device replies.
494 * These return 0 on no match, 1 on match and
495 * 3 on eventually match, if CID is longer.
497 if (c->command == ISDN_STAT_ICALL)
498 if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return(retval);
499 #ifdef CONFIG_ISDN_DIVERSION
501 if ((retval = divert_if->stat_callback(c)))
502 return(retval); /* processed */
503 #endif /* CONFIG_ISDN_DIVERSION */
504 if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
505 /* No tty responding */
508 cmd.command = ISDN_CMD_HANGUP;
514 /* Schedule connection-setup */
518 cmd.command = ISDN_CMD_ACCEPTD;
519 for ( p = dev->netdev; p; p = p->next )
520 if ( p->local->isdn_channel == cmd.arg )
522 strcpy( cmd.parm.setup.eazmsn, p->local->msn );
529 case 2: /* For calling back, first reject incoming call ... */
530 case 3: /* Interface found, but down, reject call actively */
532 printk(KERN_INFO "isdn: Rejecting Call\n");
535 cmd.command = ISDN_CMD_HANGUP;
541 /* ... then start callback. */
545 /* Number would eventually match, if longer */
549 #ifdef ISDN_DEBUG_STATCALLB
550 printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
557 #ifdef ISDN_DEBUG_STATCALLB
558 printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
560 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
562 if (strcmp(c->parm.num, "0"))
563 isdn_net_stat_callback(i, c);
564 isdn_tty_stat_callback(i, c);
566 case ISDN_STAT_CAUSE:
567 #ifdef ISDN_DEBUG_STATCALLB
568 printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
570 printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
571 dev->drvid[di], c->arg, c->parm.num);
572 isdn_tty_stat_callback(i, c);
573 #ifdef CONFIG_ISDN_DIVERSION
575 divert_if->stat_callback(c);
576 #endif /* CONFIG_ISDN_DIVERSION */
578 case ISDN_STAT_DISPLAY:
579 #ifdef ISDN_DEBUG_STATCALLB
580 printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
582 isdn_tty_stat_callback(i, c);
583 #ifdef CONFIG_ISDN_DIVERSION
585 divert_if->stat_callback(c);
586 #endif /* CONFIG_ISDN_DIVERSION */
588 case ISDN_STAT_DCONN:
591 #ifdef ISDN_DEBUG_STATCALLB
592 printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
594 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
596 /* Find any net-device, waiting for D-channel setup */
597 if (isdn_net_stat_callback(i, c))
599 isdn_v110_stat_callback(i, c);
600 /* Find any ttyI, waiting for D-channel setup */
601 if (isdn_tty_stat_callback(i, c)) {
604 cmd.command = ISDN_CMD_ACCEPTB;
612 #ifdef ISDN_DEBUG_STATCALLB
613 printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
615 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
617 dev->drv[di]->online &= ~(1 << (c->arg));
619 /* Signal hangup to network-devices */
620 if (isdn_net_stat_callback(i, c))
622 isdn_v110_stat_callback(i, c);
623 if (isdn_tty_stat_callback(i, c))
625 #ifdef CONFIG_ISDN_DIVERSION
627 divert_if->stat_callback(c);
628 #endif /* CONFIG_ISDN_DIVERSION */
631 case ISDN_STAT_BCONN:
634 #ifdef ISDN_DEBUG_STATCALLB
635 printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
637 /* Signal B-channel-connect to network-devices */
638 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
640 dev->drv[di]->online |= (1 << (c->arg));
642 if (isdn_net_stat_callback(i, c))
644 isdn_v110_stat_callback(i, c);
645 if (isdn_tty_stat_callback(i, c))
651 #ifdef ISDN_DEBUG_STATCALLB
652 printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
654 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
656 dev->drv[di]->online &= ~(1 << (c->arg));
658 #ifdef CONFIG_ISDN_X25
659 /* Signal hangup to network-devices */
660 if (isdn_net_stat_callback(i, c))
663 isdn_v110_stat_callback(i, c);
664 if (isdn_tty_stat_callback(i, c))
667 case ISDN_STAT_NODCH:
670 #ifdef ISDN_DEBUG_STATCALLB
671 printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
673 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
675 if (isdn_net_stat_callback(i, c))
677 if (isdn_tty_stat_callback(i, c))
680 case ISDN_STAT_ADDCH:
681 if (isdn_add_channels(dev->drv[di], di, c->arg, 1))
685 case ISDN_STAT_DISCH:
688 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
689 if ((dev->drvmap[i] == di) &&
690 (dev->chanmap[i] == c->arg)) {
692 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
694 if (USG_NONE(dev->usage[i])) {
695 dev->usage[i] |= ISDN_USAGE_DISABLED;
701 restore_flags(flags);
704 case ISDN_STAT_UNLOAD:
705 while (dev->drv[di]->locks > 0) {
709 cmd.command = ISDN_CMD_UNLOCK;
711 dev->drv[di]->locks--;
715 isdn_tty_stat_callback(i, c);
716 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
717 if (dev->drvmap[i] == di) {
719 dev->chanmap[i] = -1;
720 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
721 isdn_unregister_devfs(i);
724 dev->channels -= dev->drv[di]->channels;
725 kfree(dev->drv[di]->rcverr);
726 kfree(dev->drv[di]->rcvcount);
727 for (i = 0; i < dev->drv[di]->channels; i++)
728 skb_queue_purge(&dev->drv[di]->rpqueue[i]);
729 kfree(dev->drv[di]->rpqueue);
730 kfree(dev->drv[di]->rcv_waitq);
733 dev->drvid[di][0] = '\0';
735 set_global_features();
736 restore_flags(flags);
738 case ISDN_STAT_L1ERR:
740 case CAPI_PUT_MESSAGE:
741 return(isdn_capi_rec_hl_msg(&c->parm.cmsg));
742 #ifdef CONFIG_ISDN_TTY_FAX
743 case ISDN_STAT_FAXIND:
744 isdn_tty_stat_callback(i, c);
747 #ifdef CONFIG_ISDN_AUDIO
748 case ISDN_STAT_AUDIO:
749 isdn_tty_stat_callback(i, c);
752 #ifdef CONFIG_ISDN_DIVERSION
754 case ISDN_STAT_REDIR:
756 return(divert_if->stat_callback(c));
757 #endif /* CONFIG_ISDN_DIVERSION */
765 * Get integer from char-pointer, set pointer to end of number
768 isdn_getnum(char **p)
772 while (*p[0] >= '0' && *p[0] <= '9')
773 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
780 * isdn_readbchan() tries to get data from the read-queue.
781 * It MUST be called with interrupts off.
783 * Be aware that this is not an atomic operation when sleep != 0, even though
784 * interrupts are turned off! Well, like that we are currently only called
785 * on behalf of a read system call on raw device files (which are documented
786 * to be dangerous and for for debugging purpose only). The inode semaphore
787 * takes care that this is not called for the same minor device number while
788 * we are sleeping, but access is not serialized against simultaneous read()
789 * from the corresponding ttyI device. Can other ugly events, like changes
790 * of the mapping (di,ch)<->minor, happen during the sleep? --he
793 isdn_readbchan(int di, int channel, u_char * buf, u_char * fp, int len, wait_queue_head_t *sleep)
804 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
806 interruptible_sleep_on(sleep);
810 if (len > dev->drv[di]->rcvcount[channel])
811 len = dev->drv[di]->rcvcount[channel];
815 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
817 #ifdef CONFIG_ISDN_AUDIO
818 if (ISDN_AUDIO_SKB_LOCK(skb))
820 ISDN_AUDIO_SKB_LOCK(skb) = 1;
821 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
823 unsigned long DLEmask = (1 << channel);
826 count_pull = count_put = 0;
827 while ((count_pull < skb->len) && (len > 0)) {
829 if (dev->drv[di]->DLEflag & DLEmask) {
831 dev->drv[di]->DLEflag &= ~DLEmask;
835 dev->drv[di]->DLEflag |= DLEmask;
836 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
843 if (count_pull >= skb->len)
847 /* No DLE's in buff, so simply copy it */
849 if ((count_pull = skb->len) > len) {
853 count_put = count_pull;
854 memcpy(cp, skb->data, count_put);
857 #ifdef CONFIG_ISDN_AUDIO
862 memset(fp, 0, count_put);
866 /* We got all the data in this buff.
867 * Now we can dequeue it.
871 #ifdef CONFIG_ISDN_AUDIO
872 ISDN_AUDIO_SKB_LOCK(skb) = 0;
874 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
877 /* Not yet emptied this buff, so it
878 * must stay in the queue, for further calls
879 * but we pull off the data we got until now.
881 skb_pull(skb, count_pull);
882 #ifdef CONFIG_ISDN_AUDIO
883 ISDN_AUDIO_SKB_LOCK(skb) = 0;
886 dev->drv[di]->rcvcount[channel] -= count_put;
892 isdn_minor2drv(int minor)
894 return (dev->drvmap[minor]);
898 isdn_minor2chan(int minor)
900 return (dev->chanmap[minor]);
906 static char istatbuf[2048];
910 sprintf(istatbuf, "idmap:\t");
911 p = istatbuf + strlen(istatbuf);
912 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
913 sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
914 p = istatbuf + strlen(istatbuf);
916 sprintf(p, "\nchmap:\t");
917 p = istatbuf + strlen(istatbuf);
918 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
919 sprintf(p, "%d ", dev->chanmap[i]);
920 p = istatbuf + strlen(istatbuf);
922 sprintf(p, "\ndrmap:\t");
923 p = istatbuf + strlen(istatbuf);
924 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
925 sprintf(p, "%d ", dev->drvmap[i]);
926 p = istatbuf + strlen(istatbuf);
928 sprintf(p, "\nusage:\t");
929 p = istatbuf + strlen(istatbuf);
930 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
931 sprintf(p, "%d ", dev->usage[i]);
932 p = istatbuf + strlen(istatbuf);
934 sprintf(p, "\nflags:\t");
935 p = istatbuf + strlen(istatbuf);
936 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
938 sprintf(p, "%ld ", dev->drv[i]->online);
939 p = istatbuf + strlen(istatbuf);
942 p = istatbuf + strlen(istatbuf);
945 sprintf(p, "\nphone:\t");
946 p = istatbuf + strlen(istatbuf);
947 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
948 sprintf(p, "%s ", dev->num[i]);
949 p = istatbuf + strlen(istatbuf);
955 /* Module interface-code */
958 isdn_info_update(void)
960 infostruct *p = dev->infochain;
964 p = (infostruct *) p->next;
966 wake_up_interruptible(&(dev->info_waitq));
970 isdn_read(struct file *file, char *buf, size_t count, loff_t * off)
972 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
981 if (off != &file->f_pos)
984 if (pos != (unsigned) pos)
988 if (minor == ISDN_MINOR_STATUS) {
989 if (!file->private_data) {
990 if (file->f_flags & O_NONBLOCK) {
994 interruptible_sleep_on(&(dev->info_waitq));
997 file->private_data = 0;
998 if ((len = strlen(p)) <= count) {
999 if (copy_to_user(buf, p, len)) {
1010 if (!dev->drivers) {
1014 if (minor <= ISDN_MINOR_BMAX) {
1015 printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
1016 drvidx = isdn_minor2drv(minor);
1021 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1025 chidx = isdn_minor2chan(minor);
1026 if (!(p = kmalloc(count, GFP_KERNEL))) {
1032 len = isdn_readbchan(drvidx, chidx, p, 0, count,
1033 &dev->drv[drvidx]->rcv_waitq[chidx]);
1035 restore_flags(flags);
1036 if (copy_to_user(buf,p,len))
1042 if (minor <= ISDN_MINOR_CTRLMAX) {
1043 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1048 if (!dev->drv[drvidx]->stavail) {
1049 if (file->f_flags & O_NONBLOCK) {
1053 interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
1055 if (dev->drv[drvidx]->interface->readstat) {
1056 if (count > dev->drv[drvidx]->stavail)
1057 count = dev->drv[drvidx]->stavail;
1058 len = dev->drv[drvidx]->interface->
1059 readstat(buf, count, 1, drvidx,
1060 isdn_minor2chan(minor));
1071 dev->drv[drvidx]->stavail -= len;
1073 dev->drv[drvidx]->stavail = 0;
1074 restore_flags(flags);
1079 #ifdef CONFIG_ISDN_PPP
1080 if (minor <= ISDN_MINOR_PPPMAX) {
1081 retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
1092 isdn_write(struct file *file, const char *buf, size_t count, loff_t * off)
1094 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
1099 if (off != &file->f_pos)
1102 if (minor == ISDN_MINOR_STATUS)
1108 if (minor <= ISDN_MINOR_BMAX) {
1109 printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
1110 drvidx = isdn_minor2drv(minor);
1115 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1119 chidx = isdn_minor2chan(minor);
1120 while (isdn_writebuf_stub(drvidx, chidx, buf, count, 1) != count)
1121 interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
1125 if (minor <= ISDN_MINOR_CTRLMAX) {
1126 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1132 * We want to use the isdnctrl device to load the firmware
1134 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1137 if (dev->drv[drvidx]->interface->writecmd)
1138 retval = dev->drv[drvidx]->interface->
1139 writecmd(buf, count, 1, drvidx, isdn_minor2chan(minor));
1144 #ifdef CONFIG_ISDN_PPP
1145 if (minor <= ISDN_MINOR_PPPMAX) {
1146 retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
1157 isdn_poll(struct file *file, poll_table * wait)
1159 unsigned int mask = 0;
1160 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1161 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1164 if (minor == ISDN_MINOR_STATUS) {
1165 poll_wait(file, &(dev->info_waitq), wait);
1166 /* mask = POLLOUT | POLLWRNORM; */
1167 if (file->private_data) {
1168 mask |= POLLIN | POLLRDNORM;
1172 if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
1174 /* driver deregistered while file open */
1178 poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
1179 mask = POLLOUT | POLLWRNORM;
1180 if (dev->drv[drvidx]->stavail) {
1181 mask |= POLLIN | POLLRDNORM;
1185 #ifdef CONFIG_ISDN_PPP
1186 if (minor <= ISDN_MINOR_PPPMAX) {
1187 mask = isdn_ppp_poll(file, wait);
1199 isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1201 uint minor = MINOR(inode->i_rdev);
1212 isdn_ioctl_struct iocts;
1213 isdn_net_ioctl_phone phone;
1214 isdn_net_ioctl_cfg cfg;
1217 #define name iocpar.name
1218 #define bname iocpar.bname
1219 #define iocts iocpar.iocts
1220 #define phone iocpar.phone
1221 #define cfg iocpar.cfg
1223 if (minor == ISDN_MINOR_STATUS) {
1231 ulong *p = (ulong *) arg;
1233 if ((ret = verify_area(VERIFY_WRITE, (void *) arg,
1234 sizeof(ulong) * ISDN_MAX_CHANNELS * 2)))
1236 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1237 put_user(dev->ibytes[i], p++);
1238 put_user(dev->obytes[i], p++);
1244 #ifdef CONFIG_NETDEVICES
1246 /* Get peer phone number of a connected
1247 * isdn network interface */
1249 if (copy_from_user((char *) &phone, (char *) arg, sizeof(phone)))
1251 return isdn_net_getpeer(&phone, (isdn_net_ioctl_phone *) arg);
1261 if (minor <= ISDN_MINOR_BMAX) {
1262 drvidx = isdn_minor2drv(minor);
1265 chidx = isdn_minor2chan(minor);
1266 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1270 if (minor <= ISDN_MINOR_CTRLMAX) {
1272 * isdn net devices manage lots of configuration variables as linked lists.
1273 * Those lists must only be manipulated from user space. Some of the ioctl's
1274 * service routines access user space and are not atomic. Therefor, ioctl's
1275 * manipulating the lists and ioctl's sleeping while accessing the lists
1276 * are serialized by means of a semaphore.
1280 printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1283 printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1285 #ifdef CONFIG_NETDEVICES
1287 /* Add a network-interface */
1289 if (copy_from_user(name, (char *) arg, sizeof(name)))
1295 ret = down_interruptible(&dev->sem);
1296 if( ret ) return ret;
1297 if ((s = isdn_net_new(s, NULL))) {
1298 if (copy_to_user((char *) arg, s, strlen(s) + 1)){
1308 /* Add a slave to a network-interface */
1310 if (copy_from_user(bname, (char *) arg, sizeof(bname) - 1))
1314 ret = down_interruptible(&dev->sem);
1315 if( ret ) return ret;
1316 if ((s = isdn_net_newslave(bname))) {
1317 if (copy_to_user((char *) arg, s, strlen(s) + 1)){
1327 /* Delete a network-interface */
1329 if (copy_from_user(name, (char *) arg, sizeof(name)))
1331 ret = down_interruptible(&dev->sem);
1332 if( ret ) return ret;
1333 ret = isdn_net_rm(name);
1339 /* Set configurable parameters of a network-interface */
1341 if (copy_from_user((char *) &cfg, (char *) arg, sizeof(cfg)))
1343 return isdn_net_setcfg(&cfg);
1347 /* Get configurable parameters of a network-interface */
1349 if (copy_from_user((char *) &cfg, (char *) arg, sizeof(cfg)))
1351 if (!(ret = isdn_net_getcfg(&cfg))) {
1352 if (copy_to_user((char *) arg, (char *) &cfg, sizeof(cfg)))
1359 /* Add a phone-number to a network-interface */
1361 if (copy_from_user((char *) &phone, (char *) arg, sizeof(phone)))
1363 ret = down_interruptible(&dev->sem);
1364 if( ret ) return ret;
1365 ret = isdn_net_addphone(&phone);
1371 /* Get list of phone-numbers of a network-interface */
1373 if (copy_from_user((char *) &phone, (char *) arg, sizeof(phone)))
1375 ret = down_interruptible(&dev->sem);
1376 if( ret ) return ret;
1377 ret = isdn_net_getphones(&phone, (char *) arg);
1383 /* Delete a phone-number of a network-interface */
1385 if (copy_from_user((char *) &phone, (char *) arg, sizeof(phone)))
1387 ret = down_interruptible(&dev->sem);
1388 if( ret ) return ret;
1389 ret = isdn_net_delphone(&phone);
1395 /* Force dialing of a network-interface */
1397 if (copy_from_user(name, (char *) arg, sizeof(name)))
1399 return isdn_net_force_dial(name);
1402 #ifdef CONFIG_ISDN_PPP
1406 if (copy_from_user(name, (char *) arg, sizeof(name)))
1408 return isdn_ppp_dial_slave(name);
1412 if (copy_from_user(name, (char *) arg, sizeof(name)))
1414 return isdn_ppp_hangup_slave(name);
1417 /* Force hangup of a network-interface */
1420 if (copy_from_user(name, (char *) arg, sizeof(name)))
1422 return isdn_net_force_hangup(name);
1424 #endif /* CONFIG_NETDEVICES */
1426 dev->net_verbose = arg;
1427 printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
1431 dev->global_flags |= ISDN_GLOBAL_STOPPED;
1433 dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
1434 printk(KERN_INFO "isdn: Global Mode %s\n",
1435 (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
1442 if (copy_from_user((char *) &iocts, (char *) arg,
1443 sizeof(isdn_ioctl_struct)))
1445 if (strlen(iocts.drvid)) {
1446 if ((p = strchr(iocts.drvid, ',')))
1449 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1450 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1459 dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
1461 dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
1464 dev->profd = current;
1468 /* Get all Modem-Profiles */
1470 char *p = (char *) arg;
1473 if ((ret = verify_area(VERIFY_WRITE, (void *) arg,
1474 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1475 * ISDN_MAX_CHANNELS)))
1478 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1479 if (copy_to_user(p, dev->mdm.info[i].emu.profile,
1482 p += ISDN_MODEM_NUMREG;
1483 if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
1486 if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
1490 return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
1495 /* Set all Modem-Profiles */
1497 char *p = (char *) arg;
1500 if ((ret = verify_area(VERIFY_READ, (void *) arg,
1501 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1502 * ISDN_MAX_CHANNELS)))
1505 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1506 if (copy_from_user(dev->mdm.info[i].emu.profile, p,
1509 p += ISDN_MODEM_NUMREG;
1510 if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
1513 if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
1523 /* Set/Get MSN->EAZ-Mapping for a driver */
1526 if (copy_from_user((char *) &iocts,
1528 sizeof(isdn_ioctl_struct)))
1530 if (strlen(iocts.drvid)) {
1532 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1533 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1541 if (cmd == IIOCSETMAP) {
1544 p = (char *) iocts.arg;
1550 if ((ret = verify_area(VERIFY_READ, p, 1)))
1552 get_user(bname[j], p++);
1559 strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
1565 if (j >= ISDN_MSNLEN)
1572 p = (char *) iocts.arg;
1573 for (i = 0; i < 10; i++) {
1574 sprintf(bname, "%s%s",
1575 strlen(dev->drv[drvidx]->msn2eaz[i]) ?
1576 dev->drv[drvidx]->msn2eaz[i] : "_",
1577 (i < 9) ? "," : "\0");
1578 if (copy_to_user(p, bname, strlen(bname) + 1))
1588 if (copy_to_user((char *) arg, (char *) &dev, sizeof(ulong)))
1595 if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
1596 cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
1602 if (copy_from_user((char *) &iocts, (char *) arg, sizeof(isdn_ioctl_struct)))
1604 if (strlen(iocts.drvid)) {
1605 if ((p = strchr(iocts.drvid, ',')))
1608 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1609 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1617 if ((ret = verify_area(VERIFY_WRITE, (void *) arg,
1618 sizeof(isdn_ioctl_struct))))
1621 c.command = ISDN_CMD_IOCTL;
1623 memcpy(c.parm.num, (char *) &iocts.arg, sizeof(ulong));
1624 ret = isdn_command(&c);
1625 memcpy((char *) &iocts.arg, c.parm.num, sizeof(ulong));
1626 if (copy_to_user((char *) arg, &iocts, sizeof(isdn_ioctl_struct)))
1633 #ifdef CONFIG_ISDN_PPP
1634 if (minor <= ISDN_MINOR_PPPMAX)
1635 return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
1647 * Open the device code.
1650 isdn_open(struct inode *ino, struct file *filep)
1652 uint minor = MINOR(ino->i_rdev);
1655 int retval = -ENODEV;
1658 if (minor == ISDN_MINOR_STATUS) {
1661 if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
1662 p->next = (char *) dev->infochain;
1663 p->private = (char *) &(filep->private_data);
1665 /* At opening we allow a single update */
1666 filep->private_data = (char *) 1;
1676 if (minor <= ISDN_MINOR_BMAX) {
1677 printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
1678 drvidx = isdn_minor2drv(minor);
1681 chidx = isdn_minor2chan(minor);
1682 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1684 if (!(dev->drv[drvidx]->online & (1 << chidx)))
1686 isdn_lock_drivers();
1690 if (minor <= ISDN_MINOR_CTRLMAX) {
1691 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1694 isdn_lock_drivers();
1698 #ifdef CONFIG_ISDN_PPP
1699 if (minor <= ISDN_MINOR_PPPMAX) {
1700 retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
1702 isdn_lock_drivers();
1711 isdn_close(struct inode *ino, struct file *filep)
1713 uint minor = MINOR(ino->i_rdev);
1716 if (minor == ISDN_MINOR_STATUS) {
1717 infostruct *p = dev->infochain;
1718 infostruct *q = NULL;
1721 if (p->private == (char *) &(filep->private_data)) {
1725 dev->infochain = (infostruct *) (p->next);
1730 p = (infostruct *) (p->next);
1732 printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
1735 isdn_unlock_drivers();
1736 if (minor <= ISDN_MINOR_BMAX)
1738 if (minor <= ISDN_MINOR_CTRLMAX) {
1739 if (dev->profd == current)
1743 #ifdef CONFIG_ISDN_PPP
1744 if (minor <= ISDN_MINOR_PPPMAX)
1745 isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
1753 static struct file_operations isdn_fops =
1762 release: isdn_close,
1766 isdn_map_eaz2msn(char *msn, int di)
1768 driver *this = dev->drv[di];
1771 if (strlen(msn) == 1) {
1773 if ((i >= 0) && (i <= 9))
1774 if (strlen(this->msn2eaz[i]))
1775 return (this->msn2eaz[i]);
1781 * Find an unused ISDN-channel, whose feature-flags match the
1782 * given L2- and L3-protocols.
1784 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1787 isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
1788 ,int pre_chan, char *msn)
1797 features = ((1 << l2_proto) | (0x10000 << l3_proto));
1798 vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
1799 ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
1800 /* If Layer-2 protocol is V.110, accept drivers with
1801 * transparent feature even if these don't support V.110
1802 * because we can emulate this in linklevel.
1804 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1805 if (USG_NONE(dev->usage[i]) &&
1806 (dev->drvmap[i] != -1)) {
1807 int d = dev->drvmap[i];
1808 if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
1809 ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
1811 if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
1813 if (dev->usage[i] & ISDN_USAGE_DISABLED)
1814 continue; /* usage not allowed */
1815 if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
1816 if (((dev->drv[d]->interface->features & features) == features) ||
1817 (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
1818 (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
1819 if ((pre_dev < 0) || (pre_chan < 0)) {
1820 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1821 dev->usage[i] |= usage;
1823 restore_flags(flags);
1826 if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
1827 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1828 dev->usage[i] |= usage;
1830 restore_flags(flags);
1837 restore_flags(flags);
1842 * Set state of ISDN-channel to 'unused'
1845 isdn_free_channel(int di, int ch, int usage)
1852 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1853 if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
1854 (dev->drvmap[i] == di) &&
1855 (dev->chanmap[i] == ch)) {
1856 dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
1857 strcpy(dev->num[i], "???");
1860 // 20.10.99 JIM, try to reinitialize v110 !
1861 dev->v110emu[i] = 0;
1862 atomic_set(&(dev->v110use[i]), 0);
1863 isdn_v110_close(dev->v110[i]);
1864 dev->v110[i] = NULL;
1865 // 20.10.99 JIM, try to reinitialize v110 !
1867 skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
1869 restore_flags(flags);
1873 * Cancel Exclusive-Flag for ISDN-channel
1876 isdn_unexclusive_channel(int di, int ch)
1883 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1884 if ((dev->drvmap[i] == di) &&
1885 (dev->chanmap[i] == ch)) {
1886 dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
1888 restore_flags(flags);
1891 restore_flags(flags);
1895 * writebuf replacement for SKB_ABLE drivers
1898 isdn_writebuf_stub(int drvidx, int chan, const u_char * buf, int len,
1902 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1903 struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
1907 skb_reserve(skb, hl);
1909 copy_from_user(skb_put(skb, len), buf, len);
1911 memcpy(skb_put(skb, len), buf, len);
1912 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
1916 dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
1921 * Return: length of data on success, -ERRcode on failure.
1924 isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
1927 struct sk_buff *nskb = NULL;
1928 int v110_ret = skb->len;
1929 int idx = isdn_dc2minor(drvidx, chan);
1931 if (dev->v110[idx]) {
1932 atomic_inc(&dev->v110use[idx]);
1933 nskb = isdn_v110_encode(dev->v110[idx], skb);
1934 atomic_dec(&dev->v110use[idx]);
1937 v110_ret = *((int *)nskb->data);
1938 skb_pull(nskb, sizeof(int));
1940 dev_kfree_skb(nskb);
1943 /* V.110 must always be acknowledged */
1945 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
1947 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1949 if( skb_headroom(skb) < hl ){
1951 * This should only occur when new HL driver with
1952 * increased hl_hdrlen was loaded after netdevice
1953 * was created and connected to the new driver.
1955 * The V.110 branch (re-allocates on its own) does
1958 struct sk_buff * skb_tmp;
1960 skb_tmp = skb_realloc_headroom(skb, hl);
1961 printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
1962 if (!skb_tmp) return -ENOMEM; /* 0 better? */
1963 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
1967 dev_kfree_skb(skb_tmp);
1970 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
1974 dev->obytes[idx] += ret;
1975 if (dev->v110[idx]) {
1976 atomic_inc(&dev->v110use[idx]);
1977 dev->v110[idx]->skbuser++;
1978 atomic_dec(&dev->v110use[idx]);
1979 /* For V.110 return unencoded data length */
1981 /* if the complete frame was send we free the skb;
1982 if not upper function will requeue the skb */
1983 if (ret == skb->len)
1988 dev_kfree_skb(nskb);
1993 isdn_add_channels(driver *d, int drvidx, int n, int adding)
1998 init_waitqueue_head(&d->st_waitq);
1999 if (d->flags & DRV_FLAG_RUNNING)
2001 if (n < 1) return 0;
2003 m = (adding) ? d->channels + n : n;
2005 if (dev->channels + n > ISDN_MAX_CHANNELS) {
2006 printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
2011 if ((adding) && (d->rcverr))
2013 if (!(d->rcverr = kmalloc(sizeof(int) * m, GFP_KERNEL))) {
2014 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
2017 memset((char *) d->rcverr, 0, sizeof(int) * m);
2019 if ((adding) && (d->rcvcount))
2021 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_KERNEL))) {
2022 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
2023 if (!adding) kfree(d->rcverr);
2026 memset((char *) d->rcvcount, 0, sizeof(int) * m);
2028 if ((adding) && (d->rpqueue)) {
2029 for (j = 0; j < d->channels; j++)
2030 skb_queue_purge(&d->rpqueue[j]);
2033 if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_KERNEL))) {
2034 printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
2041 for (j = 0; j < m; j++) {
2042 skb_queue_head_init(&d->rpqueue[j]);
2045 if ((adding) && (d->rcv_waitq))
2046 kfree(d->rcv_waitq);
2047 d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_KERNEL);
2048 if (!d->rcv_waitq) {
2049 printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
2057 d->snd_waitq = d->rcv_waitq + m;
2058 for (j = 0; j < m; j++) {
2059 init_waitqueue_head(&d->rcv_waitq[j]);
2060 init_waitqueue_head(&d->snd_waitq[j]);
2066 for (j = d->channels; j < m; j++)
2067 for (k = 0; k < ISDN_MAX_CHANNELS; k++)
2068 if (dev->chanmap[k] < 0) {
2069 dev->chanmap[k] = j;
2070 dev->drvmap[k] = drvidx;
2071 isdn_register_devfs(k);
2074 restore_flags(flags);
2080 * Low-level-driver registration
2084 set_global_features(void)
2088 dev->global_features = 0;
2089 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
2090 if (!dev->drv[drvidx])
2092 if (dev->drv[drvidx]->interface)
2093 dev->global_features |= dev->drv[drvidx]->interface->features;
2097 #ifdef CONFIG_ISDN_DIVERSION
2099 static char *map_drvname(int di)
2101 if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
2103 return(dev->drvid[di]); /* driver name */
2106 static int map_namedrv(char *id)
2109 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2110 { if (!strcmp(dev->drvid[i],id))
2116 int DIVERT_REG_NAME(isdn_divert_if *i_div)
2118 if (i_div->if_magic != DIVERT_IF_MAGIC)
2119 return(DIVERT_VER_ERR);
2122 case DIVERT_CMD_REL:
2123 if (divert_if != i_div)
2124 return(DIVERT_REL_ERR);
2125 divert_if = NULL; /* free interface */
2127 return(DIVERT_NO_ERR);
2129 case DIVERT_CMD_REG:
2131 return(DIVERT_REG_ERR);
2132 i_div->ll_cmd = isdn_command; /* set command function */
2133 i_div->drv_to_name = map_drvname;
2134 i_div->name_to_drv = map_namedrv;
2136 divert_if = i_div; /* remember interface */
2137 return(DIVERT_NO_ERR);
2140 return(DIVERT_CMD_ERR);
2142 } /* DIVERT_REG_NAME */
2144 EXPORT_SYMBOL(DIVERT_REG_NAME);
2146 #endif /* CONFIG_ISDN_DIVERSION */
2149 EXPORT_SYMBOL(register_isdn);
2150 #ifdef CONFIG_ISDN_PPP
2151 EXPORT_SYMBOL(isdn_ppp_register_compressor);
2152 EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
2156 register_isdn(isdn_if * i)
2163 if (dev->drivers >= ISDN_MAX_DRIVERS) {
2164 printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
2168 if (!i->writebuf_skb) {
2169 printk(KERN_WARNING "register_isdn: No write routine given.\n");
2172 if (!(d = kmalloc(sizeof(driver), GFP_KERNEL))) {
2173 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
2176 memset((char *) d, 0, sizeof(driver));
2178 d->maxbufsize = i->maxbufsize;
2181 d->flags = DRV_FLAG_LOADED;
2185 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2186 if (!dev->drv[drvidx])
2188 if (isdn_add_channels(d, drvidx, i->channels, 0)) {
2192 i->channels = drvidx;
2193 i->rcvcallb_skb = isdn_receive_skb_callback;
2194 i->statcallb = isdn_status_callback;
2196 sprintf(i->id, "line%d", drvidx);
2199 for (j = 0; j < drvidx; j++)
2200 if (!strcmp(i->id, dev->drvid[j]))
2201 sprintf(i->id, "line%d", drvidx);
2202 dev->drv[drvidx] = d;
2203 strcpy(dev->drvid[drvidx], i->id);
2206 set_global_features();
2207 restore_flags(flags);
2212 *****************************************************************************
2213 * And now the modules code.
2214 *****************************************************************************
2218 isdn_getrev(const char *revision)
2223 if ((p = strchr(revision, ':'))) {
2225 p = strchr(rev, '$');
2232 #ifdef CONFIG_DEVFS_FS
2234 static devfs_handle_t devfs_handle;
2236 static void isdn_register_devfs(int k)
2240 sprintf (buf, "isdn%d", k);
2241 dev->devfs_handle_isdnX[k] =
2242 devfs_register (devfs_handle, buf, DEVFS_FL_DEFAULT,
2243 ISDN_MAJOR, ISDN_MINOR_B + k,0600 | S_IFCHR,
2245 sprintf (buf, "isdnctrl%d", k);
2246 dev->devfs_handle_isdnctrlX[k] =
2247 devfs_register (devfs_handle, buf, DEVFS_FL_DEFAULT,
2248 ISDN_MAJOR, ISDN_MINOR_CTRL + k, 0600 | S_IFCHR,
2252 static void isdn_unregister_devfs(int k)
2254 devfs_unregister (dev->devfs_handle_isdnX[k]);
2255 devfs_unregister (dev->devfs_handle_isdnctrlX[k]);
2258 static void isdn_init_devfs(void)
2260 # ifdef CONFIG_ISDN_PPP
2264 devfs_handle = devfs_mk_dir (NULL, "isdn", NULL);
2265 # ifdef CONFIG_ISDN_PPP
2266 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2269 sprintf (buf, "ippp%d", i);
2270 dev->devfs_handle_ipppX[i] =
2271 devfs_register (devfs_handle, buf, DEVFS_FL_DEFAULT,
2272 ISDN_MAJOR, ISDN_MINOR_PPP + i,
2273 0600 | S_IFCHR, &isdn_fops, NULL);
2277 dev->devfs_handle_isdninfo =
2278 devfs_register (devfs_handle, "isdninfo", DEVFS_FL_DEFAULT,
2279 ISDN_MAJOR, ISDN_MINOR_STATUS, 0600 | S_IFCHR,
2281 dev->devfs_handle_isdnctrl =
2282 devfs_register (devfs_handle, "isdnctrl", DEVFS_FL_DEFAULT,
2283 ISDN_MAJOR, ISDN_MINOR_CTRL, 0600 | S_IFCHR,
2287 static void isdn_cleanup_devfs(void)
2289 # ifdef CONFIG_ISDN_PPP
2291 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
2292 devfs_unregister (dev->devfs_handle_ipppX[i]);
2294 devfs_unregister (dev->devfs_handle_isdninfo);
2295 devfs_unregister (dev->devfs_handle_isdnctrl);
2296 devfs_unregister (devfs_handle);
2299 #else /* CONFIG_DEVFS_FS */
2300 static void isdn_register_devfs(int dummy)
2305 static void isdn_unregister_devfs(int dummy)
2310 static void isdn_init_devfs(void)
2315 static void isdn_cleanup_devfs(void)
2320 #endif /* CONFIG_DEVFS_FS */
2323 * Allocate and initialize all data, register modem-devices
2325 static int __init isdn_init(void)
2330 if (!(dev = (isdn_dev *) vmalloc(sizeof(isdn_dev)))) {
2331 printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
2334 memset((char *) dev, 0, sizeof(isdn_dev));
2335 init_timer(&dev->timer);
2336 dev->timer.function = isdn_timer_funct;
2337 init_MUTEX(&dev->sem);
2338 init_waitqueue_head(&dev->info_waitq);
2339 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2340 dev->drvmap[i] = -1;
2341 dev->chanmap[i] = -1;
2343 strcpy(dev->num[i], "???");
2344 init_waitqueue_head(&dev->mdm.info[i].open_wait);
2345 init_waitqueue_head(&dev->mdm.info[i].close_wait);
2347 if (devfs_register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
2348 printk(KERN_WARNING "isdn: Could not register control devices\n");
2353 if ((i = isdn_tty_modem_init()) < 0) {
2354 printk(KERN_WARNING "isdn: Could not register tty devices\n");
2356 tty_unregister_driver(&dev->mdm.cua_modem);
2358 tty_unregister_driver(&dev->mdm.tty_modem);
2360 isdn_cleanup_devfs();
2361 devfs_unregister_chrdev(ISDN_MAJOR, "isdn");
2364 #ifdef CONFIG_ISDN_PPP
2365 if (isdn_ppp_init() < 0) {
2366 printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
2367 tty_unregister_driver(&dev->mdm.tty_modem);
2368 tty_unregister_driver(&dev->mdm.cua_modem);
2369 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
2370 kfree(dev->mdm.info[i].xmit_buf - 4);
2371 isdn_cleanup_devfs();
2372 devfs_unregister_chrdev(ISDN_MAJOR, "isdn");
2376 #endif /* CONFIG_ISDN_PPP */
2378 strcpy(tmprev, isdn_revision);
2379 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
2380 strcpy(tmprev, isdn_tty_revision);
2381 printk("%s/", isdn_getrev(tmprev));
2382 strcpy(tmprev, isdn_net_revision);
2383 printk("%s/", isdn_getrev(tmprev));
2384 strcpy(tmprev, isdn_ppp_revision);
2385 printk("%s/", isdn_getrev(tmprev));
2386 strcpy(tmprev, isdn_audio_revision);
2387 printk("%s/", isdn_getrev(tmprev));
2388 strcpy(tmprev, isdn_v110_revision);
2389 printk("%s", isdn_getrev(tmprev));
2392 printk(" loaded\n");
2403 static void __exit isdn_exit(void)
2405 unsigned long flags;
2408 #ifdef CONFIG_ISDN_PPP
2413 if (isdn_net_rmall() < 0) {
2414 printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
2415 restore_flags(flags);
2418 if (tty_unregister_driver(&dev->mdm.tty_modem)) {
2419 printk(KERN_WARNING "isdn: ttyI-device busy, remove cancelled\n");
2420 restore_flags(flags);
2423 if (tty_unregister_driver(&dev->mdm.cua_modem)) {
2424 printk(KERN_WARNING "isdn: cui-device busy, remove cancelled\n");
2425 restore_flags(flags);
2428 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2429 isdn_tty_cleanup_xmit(&dev->mdm.info[i]);
2430 kfree(dev->mdm.info[i].xmit_buf - 4);
2431 #ifdef CONFIG_ISDN_TTY_FAX
2432 kfree(dev->mdm.info[i].fax);
2435 if (devfs_unregister_chrdev(ISDN_MAJOR, "isdn") != 0) {
2436 printk(KERN_WARNING "isdn: controldevice busy, remove cancelled\n");
2437 restore_flags(flags);
2439 isdn_cleanup_devfs();
2440 del_timer(&dev->timer);
2441 restore_flags(flags);
2442 /* call vfree with interrupts enabled, else it will hang */
2444 printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
2448 module_init(isdn_init);
2449 module_exit(isdn_exit);