1 /* $Id: isdn_common.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, common used functions (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/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"
38 #undef ISDN_DEBUG_STATCALLB
40 MODULE_DESCRIPTION("ISDN4Linux: link layer");
41 MODULE_AUTHOR("Fritz Elfert");
42 MODULE_LICENSE("GPL");
46 static char *isdn_revision = "$Revision: 1.1.2.3 $";
48 extern char *isdn_net_revision;
49 extern char *isdn_tty_revision;
50 #ifdef CONFIG_ISDN_PPP
51 extern char *isdn_ppp_revision;
53 static char *isdn_ppp_revision = ": none $";
55 #ifdef CONFIG_ISDN_AUDIO
56 extern char *isdn_audio_revision;
58 static char *isdn_audio_revision = ": none $";
60 extern char *isdn_v110_revision;
62 #ifdef CONFIG_ISDN_DIVERSION
63 static isdn_divert_if *divert_if; /* = NULL */
64 #endif /* CONFIG_ISDN_DIVERSION */
67 static int isdn_writebuf_stub(int, int, const u_char __user *, int);
68 static void set_global_features(void);
69 static int isdn_wildmat(char *s, char *p);
73 isdn_lock_driver(isdn_driver_t *drv)
75 try_module_get(drv->interface->owner);
80 isdn_lock_drivers(void)
84 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
87 isdn_lock_driver(dev->drv[i]);
92 isdn_unlock_driver(isdn_driver_t *drv)
96 module_put(drv->interface->owner);
101 isdn_unlock_drivers(void)
105 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
108 isdn_unlock_driver(dev->drv[i]);
112 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
114 isdn_dumppkt(char *s, u_char * p, int len, int dumplen)
118 printk(KERN_DEBUG "%s(%d) ", s, len);
119 for (dumpc = 0; (dumpc < dumplen) && (len); len--, dumpc++)
120 printk(" %02x", *p++);
126 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
127 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
130 isdn_star(char *s, char *p)
132 while (isdn_wildmat(s, p)) {
140 * Shell-type Pattern-matching for incoming caller-Ids
141 * This function gets a string in s and checks, if it matches the pattern
147 * 2 = no match. Would eventually match, if s would be longer.
151 * '?' matches one character
152 * '*' matches zero or more characters
153 * [xyz] matches the set of characters in brackets.
154 * [^xyz] matches any single character not in the set of characters
158 isdn_wildmat(char *s, char *p)
161 register int matched;
162 register int reverse;
163 register int nostar = 1;
171 * Literal match with following character,
177 return (*s == '\0')?2:1;
180 /* Match anything. */
186 /* Trailing star matches everything. */
187 return (*++p ? isdn_star(s, p) : 0);
189 /* [^....] means inverse character class. */
190 if ((reverse = (p[1] == '^')))
192 for (last = 0, matched = 0; *++p && (*p != ']'); last = *p)
193 /* This next line requires a good C compiler. */
194 if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
196 if (matched == reverse)
200 return (*s == '\0')?0:nostar;
203 int isdn_msncmp( const char * msn1, const char * msn2 )
205 char TmpMsn1[ ISDN_MSNLEN ];
206 char TmpMsn2[ ISDN_MSNLEN ];
209 for ( p = TmpMsn1; *msn1 && *msn1 != ':'; ) // Strip off a SPID
213 for ( p = TmpMsn2; *msn2 && *msn2 != ':'; ) // Strip off a SPID
217 return isdn_wildmat( TmpMsn1, TmpMsn2 );
221 isdn_dc2minor(int di, int ch)
224 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
225 if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
230 static int isdn_timer_cnt1 = 0;
231 static int isdn_timer_cnt2 = 0;
232 static int isdn_timer_cnt3 = 0;
235 isdn_timer_funct(ulong dummy)
237 int tf = dev->tflags;
238 if (tf & ISDN_TIMER_FAST) {
239 if (tf & ISDN_TIMER_MODEMREAD)
240 isdn_tty_readmodem();
241 if (tf & ISDN_TIMER_MODEMPLUS)
242 isdn_tty_modem_escape();
243 if (tf & ISDN_TIMER_MODEMXMIT)
244 isdn_tty_modem_xmit();
246 if (tf & ISDN_TIMER_SLOW) {
247 if (++isdn_timer_cnt1 >= ISDN_TIMER_02SEC) {
249 if (tf & ISDN_TIMER_NETDIAL)
252 if (++isdn_timer_cnt2 >= ISDN_TIMER_1SEC) {
254 if (tf & ISDN_TIMER_NETHANGUP)
256 if (++isdn_timer_cnt3 >= ISDN_TIMER_RINGING) {
258 if (tf & ISDN_TIMER_MODEMRING)
259 isdn_tty_modem_ring();
261 if (tf & ISDN_TIMER_CARRIER)
262 isdn_tty_carrier_timeout();
266 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
270 isdn_timer_ctrl(int tf, int onoff)
275 spin_lock_irqsave(&dev->timerlock, flags);
276 if ((tf & ISDN_TIMER_SLOW) && (!(dev->tflags & ISDN_TIMER_SLOW))) {
277 /* If the slow-timer wasn't activated until now */
281 old_tflags = dev->tflags;
286 if (dev->tflags && !old_tflags)
287 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
288 spin_unlock_irqrestore(&dev->timerlock, flags);
292 * Receive a packet from B-Channel. (Called from low-level-module)
295 isdn_receive_skb_callback(int di, int channel, struct sk_buff *skb)
299 if ((i = isdn_dc2minor(di, channel)) == -1) {
303 /* Update statistics */
304 dev->ibytes[i] += skb->len;
306 /* First, try to deliver data to network-device */
307 if (isdn_net_rcv_skb(i, skb))
311 * makes sense for async streams only, so it is
312 * called after possible net-device delivery.
315 atomic_inc(&dev->v110use[i]);
316 skb = isdn_v110_decode(dev->v110[i], skb);
317 atomic_dec(&dev->v110use[i]);
322 /* No network-device found, deliver to tty or raw-channel */
324 if (isdn_tty_rcv_skb(i, di, channel, skb))
326 wake_up_interruptible(&dev->drv[di]->rcv_waitq[channel]);
332 * Intercept command from Linklevel to Lowlevel.
333 * If layer 2 protocol is V.110 and this is not supported by current
334 * lowlevel-driver, use driver's transparent mode and handle V.110 in
338 isdn_command(isdn_ctrl *cmd)
340 if (cmd->driver == -1) {
341 printk(KERN_WARNING "isdn_command command(%x) driver -1\n", cmd->command);
344 if (cmd->command == ISDN_CMD_SETL2) {
345 int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
346 unsigned long l2prot = (cmd->arg >> 8) & 255;
347 unsigned long features = (dev->drv[cmd->driver]->interface->features
348 >> ISDN_FEATURE_L2_SHIFT) &
349 ISDN_FEATURE_L2_MASK;
350 unsigned long l2_feature = (1 << l2prot);
353 case ISDN_PROTO_L2_V11096:
354 case ISDN_PROTO_L2_V11019:
355 case ISDN_PROTO_L2_V11038:
356 /* If V.110 requested, but not supported by
357 * HL-driver, set emulator-flag and change
358 * Layer-2 to transparent
360 if (!(features & l2_feature)) {
361 dev->v110emu[idx] = l2prot;
362 cmd->arg = (cmd->arg & 255) |
363 (ISDN_PROTO_L2_TRANS << 8);
365 dev->v110emu[idx] = 0;
368 return dev->drv[cmd->driver]->interface->command(cmd);
372 isdn_all_eaz(int di, int ch)
380 cmd.command = ISDN_CMD_SETEAZ;
381 cmd.parm.num[0] = '\0';
386 * Begin of a CAPI like LL<->HL interface, currently used only for
387 * supplementary service (CAPI 2.0 part III)
389 #include <linux/isdn/capicmd.h>
392 isdn_capi_rec_hl_msg(capi_msg *cm) {
397 di = (cm->adr.Controller & 0x7f) -1;
398 ch = isdn_dc2minor(di, (cm->adr.Controller>>8)& 0x7f);
399 switch(cm->Command) {
401 /* in the moment only handled in tty */
402 return(isdn_tty_capi_facility(cm));
409 isdn_status_callback(isdn_ctrl * c)
420 i = isdn_dc2minor(di, c->arg);
421 switch (c->command) {
422 case ISDN_STAT_BSENT:
425 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
427 if (isdn_net_stat_callback(i, c))
429 if (isdn_v110_stat_callback(i, c))
431 if (isdn_tty_stat_callback(i, c))
433 wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
435 case ISDN_STAT_STAVAIL:
436 dev->drv[di]->stavail += c->arg;
437 wake_up_interruptible(&dev->drv[di]->st_waitq);
440 dev->drv[di]->flags |= DRV_FLAG_RUNNING;
441 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
442 if (dev->drvmap[i] == di)
443 isdn_all_eaz(di, dev->chanmap[i]);
444 set_global_features();
447 dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
449 case ISDN_STAT_ICALL:
452 #ifdef ISDN_DEBUG_STATCALLB
453 printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
455 if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
458 cmd.command = ISDN_CMD_HANGUP;
462 /* Try to find a network-interface which will accept incoming call */
463 r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
466 /* No network-device replies.
468 * These return 0 on no match, 1 on match and
469 * 3 on eventually match, if CID is longer.
471 if (c->command == ISDN_STAT_ICALL)
472 if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return(retval);
473 #ifdef CONFIG_ISDN_DIVERSION
475 if ((retval = divert_if->stat_callback(c)))
476 return(retval); /* processed */
477 #endif /* CONFIG_ISDN_DIVERSION */
478 if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
479 /* No tty responding */
482 cmd.command = ISDN_CMD_HANGUP;
488 /* Schedule connection-setup */
492 cmd.command = ISDN_CMD_ACCEPTD;
493 for ( p = dev->netdev; p; p = p->next )
494 if ( p->local->isdn_channel == cmd.arg )
496 strcpy( cmd.parm.setup.eazmsn, p->local->msn );
503 case 2: /* For calling back, first reject incoming call ... */
504 case 3: /* Interface found, but down, reject call actively */
506 printk(KERN_INFO "isdn: Rejecting Call\n");
509 cmd.command = ISDN_CMD_HANGUP;
515 /* ... then start callback. */
519 /* Number would eventually match, if longer */
523 #ifdef ISDN_DEBUG_STATCALLB
524 printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
531 #ifdef ISDN_DEBUG_STATCALLB
532 printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
534 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
536 if (strcmp(c->parm.num, "0"))
537 isdn_net_stat_callback(i, c);
538 isdn_tty_stat_callback(i, c);
540 case ISDN_STAT_CAUSE:
541 #ifdef ISDN_DEBUG_STATCALLB
542 printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
544 printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
545 dev->drvid[di], c->arg, c->parm.num);
546 isdn_tty_stat_callback(i, c);
547 #ifdef CONFIG_ISDN_DIVERSION
549 divert_if->stat_callback(c);
550 #endif /* CONFIG_ISDN_DIVERSION */
552 case ISDN_STAT_DISPLAY:
553 #ifdef ISDN_DEBUG_STATCALLB
554 printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
556 isdn_tty_stat_callback(i, c);
557 #ifdef CONFIG_ISDN_DIVERSION
559 divert_if->stat_callback(c);
560 #endif /* CONFIG_ISDN_DIVERSION */
562 case ISDN_STAT_DCONN:
565 #ifdef ISDN_DEBUG_STATCALLB
566 printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
568 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
570 /* Find any net-device, waiting for D-channel setup */
571 if (isdn_net_stat_callback(i, c))
573 isdn_v110_stat_callback(i, c);
574 /* Find any ttyI, waiting for D-channel setup */
575 if (isdn_tty_stat_callback(i, c)) {
578 cmd.command = ISDN_CMD_ACCEPTB;
586 #ifdef ISDN_DEBUG_STATCALLB
587 printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
589 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
591 dev->drv[di]->online &= ~(1 << (c->arg));
593 /* Signal hangup to network-devices */
594 if (isdn_net_stat_callback(i, c))
596 isdn_v110_stat_callback(i, c);
597 if (isdn_tty_stat_callback(i, c))
599 #ifdef CONFIG_ISDN_DIVERSION
601 divert_if->stat_callback(c);
602 #endif /* CONFIG_ISDN_DIVERSION */
605 case ISDN_STAT_BCONN:
608 #ifdef ISDN_DEBUG_STATCALLB
609 printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
611 /* Signal B-channel-connect to network-devices */
612 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
614 dev->drv[di]->online |= (1 << (c->arg));
616 if (isdn_net_stat_callback(i, c))
618 isdn_v110_stat_callback(i, c);
619 if (isdn_tty_stat_callback(i, c))
625 #ifdef ISDN_DEBUG_STATCALLB
626 printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
628 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
630 dev->drv[di]->online &= ~(1 << (c->arg));
632 #ifdef CONFIG_ISDN_X25
633 /* Signal hangup to network-devices */
634 if (isdn_net_stat_callback(i, c))
637 isdn_v110_stat_callback(i, c);
638 if (isdn_tty_stat_callback(i, c))
641 case ISDN_STAT_NODCH:
644 #ifdef ISDN_DEBUG_STATCALLB
645 printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
647 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
649 if (isdn_net_stat_callback(i, c))
651 if (isdn_tty_stat_callback(i, c))
654 case ISDN_STAT_ADDCH:
655 spin_lock_irqsave(&dev->lock, flags);
656 if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
657 spin_unlock_irqrestore(&dev->lock, flags);
660 spin_unlock_irqrestore(&dev->lock, flags);
663 case ISDN_STAT_DISCH:
664 spin_lock_irqsave(&dev->lock, flags);
665 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
666 if ((dev->drvmap[i] == di) &&
667 (dev->chanmap[i] == c->arg)) {
669 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
671 if (USG_NONE(dev->usage[i])) {
672 dev->usage[i] |= ISDN_USAGE_DISABLED;
678 spin_unlock_irqrestore(&dev->lock, flags);
681 case ISDN_STAT_UNLOAD:
682 while (dev->drv[di]->locks > 0) {
683 isdn_unlock_driver(dev->drv[di]);
685 spin_lock_irqsave(&dev->lock, flags);
686 isdn_tty_stat_callback(i, c);
687 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
688 if (dev->drvmap[i] == di) {
690 dev->chanmap[i] = -1;
691 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
694 dev->channels -= dev->drv[di]->channels;
695 kfree(dev->drv[di]->rcverr);
696 kfree(dev->drv[di]->rcvcount);
697 for (i = 0; i < dev->drv[di]->channels; i++)
698 skb_queue_purge(&dev->drv[di]->rpqueue[i]);
699 kfree(dev->drv[di]->rpqueue);
700 kfree(dev->drv[di]->rcv_waitq);
703 dev->drvid[di][0] = '\0';
705 set_global_features();
706 spin_unlock_irqrestore(&dev->lock, flags);
708 case ISDN_STAT_L1ERR:
710 case CAPI_PUT_MESSAGE:
711 return(isdn_capi_rec_hl_msg(&c->parm.cmsg));
712 #ifdef CONFIG_ISDN_TTY_FAX
713 case ISDN_STAT_FAXIND:
714 isdn_tty_stat_callback(i, c);
717 #ifdef CONFIG_ISDN_AUDIO
718 case ISDN_STAT_AUDIO:
719 isdn_tty_stat_callback(i, c);
722 #ifdef CONFIG_ISDN_DIVERSION
724 case ISDN_STAT_REDIR:
726 return(divert_if->stat_callback(c));
727 #endif /* CONFIG_ISDN_DIVERSION */
735 * Get integer from char-pointer, set pointer to end of number
738 isdn_getnum(char **p)
742 while (*p[0] >= '0' && *p[0] <= '9')
743 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
750 * isdn_readbchan() tries to get data from the read-queue.
751 * It MUST be called with interrupts off.
753 * Be aware that this is not an atomic operation when sleep != 0, even though
754 * interrupts are turned off! Well, like that we are currently only called
755 * on behalf of a read system call on raw device files (which are documented
756 * to be dangerous and for for debugging purpose only). The inode semaphore
757 * takes care that this is not called for the same minor device number while
758 * we are sleeping, but access is not serialized against simultaneous read()
759 * from the corresponding ttyI device. Can other ugly events, like changes
760 * of the mapping (di,ch)<->minor, happen during the sleep? --he
763 isdn_readbchan(int di, int channel, u_char * buf, u_char * fp, int len, wait_queue_head_t *sleep)
774 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
776 interruptible_sleep_on(sleep);
780 if (len > dev->drv[di]->rcvcount[channel])
781 len = dev->drv[di]->rcvcount[channel];
785 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
787 #ifdef CONFIG_ISDN_AUDIO
788 if (ISDN_AUDIO_SKB_LOCK(skb))
790 ISDN_AUDIO_SKB_LOCK(skb) = 1;
791 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
793 unsigned long DLEmask = (1 << channel);
796 count_pull = count_put = 0;
797 while ((count_pull < skb->len) && (len > 0)) {
799 if (dev->drv[di]->DLEflag & DLEmask) {
801 dev->drv[di]->DLEflag &= ~DLEmask;
805 dev->drv[di]->DLEflag |= DLEmask;
806 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
813 if (count_pull >= skb->len)
817 /* No DLE's in buff, so simply copy it */
819 if ((count_pull = skb->len) > len) {
823 count_put = count_pull;
824 memcpy(cp, skb->data, count_put);
827 #ifdef CONFIG_ISDN_AUDIO
832 memset(fp, 0, count_put);
836 /* We got all the data in this buff.
837 * Now we can dequeue it.
841 #ifdef CONFIG_ISDN_AUDIO
842 ISDN_AUDIO_SKB_LOCK(skb) = 0;
844 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
847 /* Not yet emptied this buff, so it
848 * must stay in the queue, for further calls
849 * but we pull off the data we got until now.
851 skb_pull(skb, count_pull);
852 #ifdef CONFIG_ISDN_AUDIO
853 ISDN_AUDIO_SKB_LOCK(skb) = 0;
856 dev->drv[di]->rcvcount[channel] -= count_put;
862 isdn_minor2drv(int minor)
864 return (dev->drvmap[minor]);
868 isdn_minor2chan(int minor)
870 return (dev->chanmap[minor]);
876 static char istatbuf[2048];
880 sprintf(istatbuf, "idmap:\t");
881 p = istatbuf + strlen(istatbuf);
882 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
883 sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
884 p = istatbuf + strlen(istatbuf);
886 sprintf(p, "\nchmap:\t");
887 p = istatbuf + strlen(istatbuf);
888 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
889 sprintf(p, "%d ", dev->chanmap[i]);
890 p = istatbuf + strlen(istatbuf);
892 sprintf(p, "\ndrmap:\t");
893 p = istatbuf + strlen(istatbuf);
894 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
895 sprintf(p, "%d ", dev->drvmap[i]);
896 p = istatbuf + strlen(istatbuf);
898 sprintf(p, "\nusage:\t");
899 p = istatbuf + strlen(istatbuf);
900 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
901 sprintf(p, "%d ", dev->usage[i]);
902 p = istatbuf + strlen(istatbuf);
904 sprintf(p, "\nflags:\t");
905 p = istatbuf + strlen(istatbuf);
906 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
908 sprintf(p, "%ld ", dev->drv[i]->online);
909 p = istatbuf + strlen(istatbuf);
912 p = istatbuf + strlen(istatbuf);
915 sprintf(p, "\nphone:\t");
916 p = istatbuf + strlen(istatbuf);
917 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
918 sprintf(p, "%s ", dev->num[i]);
919 p = istatbuf + strlen(istatbuf);
925 /* Module interface-code */
928 isdn_info_update(void)
930 infostruct *p = dev->infochain;
934 p = (infostruct *) p->next;
936 wake_up_interruptible(&(dev->info_waitq));
940 isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
942 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
949 if (off != &file->f_pos)
953 if (minor == ISDN_MINOR_STATUS) {
954 if (!file->private_data) {
955 if (file->f_flags & O_NONBLOCK) {
959 interruptible_sleep_on(&(dev->info_waitq));
962 file->private_data = NULL;
963 if ((len = strlen(p)) <= count) {
964 if (copy_to_user(buf, p, len)) {
979 if (minor <= ISDN_MINOR_BMAX) {
980 printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
981 drvidx = isdn_minor2drv(minor);
986 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
990 chidx = isdn_minor2chan(minor);
991 if (!(p = kmalloc(count, GFP_KERNEL))) {
995 len = isdn_readbchan(drvidx, chidx, p, NULL, count,
996 &dev->drv[drvidx]->rcv_waitq[chidx]);
998 if (copy_to_user(buf,p,len))
1004 if (minor <= ISDN_MINOR_CTRLMAX) {
1005 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1010 if (!dev->drv[drvidx]->stavail) {
1011 if (file->f_flags & O_NONBLOCK) {
1015 interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
1017 if (dev->drv[drvidx]->interface->readstat) {
1018 if (count > dev->drv[drvidx]->stavail)
1019 count = dev->drv[drvidx]->stavail;
1020 len = dev->drv[drvidx]->interface->
1021 readstat(buf, count, drvidx,
1022 isdn_minor2chan(minor));
1027 dev->drv[drvidx]->stavail -= len;
1029 dev->drv[drvidx]->stavail = 0;
1034 #ifdef CONFIG_ISDN_PPP
1035 if (minor <= ISDN_MINOR_PPPMAX) {
1036 retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
1047 isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
1049 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
1054 if (off != &file->f_pos)
1057 if (minor == ISDN_MINOR_STATUS)
1063 if (minor <= ISDN_MINOR_BMAX) {
1064 printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
1065 drvidx = isdn_minor2drv(minor);
1070 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1074 chidx = isdn_minor2chan(minor);
1075 while (isdn_writebuf_stub(drvidx, chidx, buf, count) != count)
1076 interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
1080 if (minor <= ISDN_MINOR_CTRLMAX) {
1081 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1087 * We want to use the isdnctrl device to load the firmware
1089 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1092 if (dev->drv[drvidx]->interface->writecmd)
1093 retval = dev->drv[drvidx]->interface->
1094 writecmd(buf, count, drvidx, isdn_minor2chan(minor));
1099 #ifdef CONFIG_ISDN_PPP
1100 if (minor <= ISDN_MINOR_PPPMAX) {
1101 retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
1112 isdn_poll(struct file *file, poll_table * wait)
1114 unsigned int mask = 0;
1115 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1116 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1119 if (minor == ISDN_MINOR_STATUS) {
1120 poll_wait(file, &(dev->info_waitq), wait);
1121 /* mask = POLLOUT | POLLWRNORM; */
1122 if (file->private_data) {
1123 mask |= POLLIN | POLLRDNORM;
1127 if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
1129 /* driver deregistered while file open */
1133 poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
1134 mask = POLLOUT | POLLWRNORM;
1135 if (dev->drv[drvidx]->stavail) {
1136 mask |= POLLIN | POLLRDNORM;
1140 #ifdef CONFIG_ISDN_PPP
1141 if (minor <= ISDN_MINOR_PPPMAX) {
1142 mask = isdn_ppp_poll(file, wait);
1154 isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1156 uint minor = MINOR(inode->i_rdev);
1167 isdn_ioctl_struct iocts;
1168 isdn_net_ioctl_phone phone;
1169 isdn_net_ioctl_cfg cfg;
1171 void __user *argp = (void __user *)arg;
1173 #define name iocpar.name
1174 #define bname iocpar.bname
1175 #define iocts iocpar.iocts
1176 #define phone iocpar.phone
1177 #define cfg iocpar.cfg
1179 if (minor == ISDN_MINOR_STATUS) {
1187 ulong __user *p = argp;
1189 if ((ret = verify_area(VERIFY_WRITE, p,
1190 sizeof(ulong) * ISDN_MAX_CHANNELS * 2)))
1192 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1193 put_user(dev->ibytes[i], p++);
1194 put_user(dev->obytes[i], p++);
1200 #ifdef CONFIG_NETDEVICES
1202 /* Get peer phone number of a connected
1203 * isdn network interface */
1205 if (copy_from_user(&phone, argp, sizeof(phone)))
1207 return isdn_net_getpeer(&phone, argp);
1217 if (minor <= ISDN_MINOR_BMAX) {
1218 drvidx = isdn_minor2drv(minor);
1221 chidx = isdn_minor2chan(minor);
1222 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1226 if (minor <= ISDN_MINOR_CTRLMAX) {
1228 * isdn net devices manage lots of configuration variables as linked lists.
1229 * Those lists must only be manipulated from user space. Some of the ioctl's
1230 * service routines access user space and are not atomic. Therefor, ioctl's
1231 * manipulating the lists and ioctl's sleeping while accessing the lists
1232 * are serialized by means of a semaphore.
1236 printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1239 printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1241 #ifdef CONFIG_NETDEVICES
1243 /* Add a network-interface */
1245 if (copy_from_user(name, argp, sizeof(name)))
1251 ret = down_interruptible(&dev->sem);
1252 if( ret ) return ret;
1253 if ((s = isdn_net_new(s, NULL))) {
1254 if (copy_to_user(argp, s, strlen(s) + 1)){
1264 /* Add a slave to a network-interface */
1266 if (copy_from_user(bname, argp, sizeof(bname) - 1))
1270 ret = down_interruptible(&dev->sem);
1271 if( ret ) return ret;
1272 if ((s = isdn_net_newslave(bname))) {
1273 if (copy_to_user(argp, s, strlen(s) + 1)){
1283 /* Delete a network-interface */
1285 if (copy_from_user(name, argp, sizeof(name)))
1287 ret = down_interruptible(&dev->sem);
1288 if( ret ) return ret;
1289 ret = isdn_net_rm(name);
1295 /* Set configurable parameters of a network-interface */
1297 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1299 return isdn_net_setcfg(&cfg);
1303 /* Get configurable parameters of a network-interface */
1305 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1307 if (!(ret = isdn_net_getcfg(&cfg))) {
1308 if (copy_to_user(argp, &cfg, sizeof(cfg)))
1315 /* Add a phone-number to a network-interface */
1317 if (copy_from_user(&phone, argp, sizeof(phone)))
1319 ret = down_interruptible(&dev->sem);
1320 if( ret ) return ret;
1321 ret = isdn_net_addphone(&phone);
1327 /* Get list of phone-numbers of a network-interface */
1329 if (copy_from_user(&phone, argp, sizeof(phone)))
1331 ret = down_interruptible(&dev->sem);
1332 if( ret ) return ret;
1333 ret = isdn_net_getphones(&phone, argp);
1339 /* Delete a phone-number of a network-interface */
1341 if (copy_from_user(&phone, argp, sizeof(phone)))
1343 ret = down_interruptible(&dev->sem);
1344 if( ret ) return ret;
1345 ret = isdn_net_delphone(&phone);
1351 /* Force dialing of a network-interface */
1353 if (copy_from_user(name, argp, sizeof(name)))
1355 return isdn_net_force_dial(name);
1358 #ifdef CONFIG_ISDN_PPP
1362 if (copy_from_user(name, argp, sizeof(name)))
1364 return isdn_ppp_dial_slave(name);
1368 if (copy_from_user(name, argp, sizeof(name)))
1370 return isdn_ppp_hangup_slave(name);
1373 /* Force hangup of a network-interface */
1376 if (copy_from_user(name, argp, sizeof(name)))
1378 return isdn_net_force_hangup(name);
1380 #endif /* CONFIG_NETDEVICES */
1382 dev->net_verbose = arg;
1383 printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
1387 dev->global_flags |= ISDN_GLOBAL_STOPPED;
1389 dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
1390 printk(KERN_INFO "isdn: Global Mode %s\n",
1391 (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
1398 if (copy_from_user(&iocts, argp,
1399 sizeof(isdn_ioctl_struct)))
1401 if (strlen(iocts.drvid)) {
1402 if ((p = strchr(iocts.drvid, ',')))
1405 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1406 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1415 dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
1417 dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
1420 dev->profd = current;
1424 /* Get all Modem-Profiles */
1426 char __user *p = argp;
1429 if ((ret = verify_area(VERIFY_WRITE, argp,
1430 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1431 * ISDN_MAX_CHANNELS)))
1434 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1435 if (copy_to_user(p, dev->mdm.info[i].emu.profile,
1438 p += ISDN_MODEM_NUMREG;
1439 if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
1442 if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
1446 return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
1451 /* Set all Modem-Profiles */
1453 char __user *p = argp;
1456 if ((ret = verify_area(VERIFY_READ, argp,
1457 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1458 * ISDN_MAX_CHANNELS)))
1461 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1462 if (copy_from_user(dev->mdm.info[i].emu.profile, p,
1465 p += ISDN_MODEM_NUMREG;
1466 if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
1469 if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
1479 /* Set/Get MSN->EAZ-Mapping for a driver */
1482 if (copy_from_user(&iocts, argp,
1483 sizeof(isdn_ioctl_struct)))
1485 if (strlen(iocts.drvid)) {
1487 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1488 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1496 if (cmd == IIOCSETMAP) {
1499 p = (char __user *) iocts.arg;
1505 if ((ret = verify_area(VERIFY_READ, p, 1)))
1507 get_user(bname[j], p++);
1514 strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
1520 if (j >= ISDN_MSNLEN)
1527 p = (char __user *) iocts.arg;
1528 for (i = 0; i < 10; i++) {
1529 sprintf(bname, "%s%s",
1530 strlen(dev->drv[drvidx]->msn2eaz[i]) ?
1531 dev->drv[drvidx]->msn2eaz[i] : "_",
1532 (i < 9) ? "," : "\0");
1533 if (copy_to_user(p, bname, strlen(bname) + 1))
1543 if (copy_to_user(argp, &dev, sizeof(ulong)))
1550 if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
1551 cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
1557 if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
1559 if (strlen(iocts.drvid)) {
1560 if ((p = strchr(iocts.drvid, ',')))
1563 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1564 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1572 if ((ret = verify_area(VERIFY_WRITE, argp,
1573 sizeof(isdn_ioctl_struct))))
1576 c.command = ISDN_CMD_IOCTL;
1578 memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
1579 ret = isdn_command(&c);
1580 memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
1581 if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
1588 #ifdef CONFIG_ISDN_PPP
1589 if (minor <= ISDN_MINOR_PPPMAX)
1590 return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
1602 * Open the device code.
1605 isdn_open(struct inode *ino, struct file *filep)
1607 uint minor = MINOR(ino->i_rdev);
1610 int retval = -ENODEV;
1613 if (minor == ISDN_MINOR_STATUS) {
1616 if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
1617 p->next = (char *) dev->infochain;
1618 p->private = (char *) &(filep->private_data);
1620 /* At opening we allow a single update */
1621 filep->private_data = (char *) 1;
1631 if (minor <= ISDN_MINOR_BMAX) {
1632 printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
1633 drvidx = isdn_minor2drv(minor);
1636 chidx = isdn_minor2chan(minor);
1637 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1639 if (!(dev->drv[drvidx]->online & (1 << chidx)))
1641 isdn_lock_drivers();
1645 if (minor <= ISDN_MINOR_CTRLMAX) {
1646 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1649 isdn_lock_drivers();
1653 #ifdef CONFIG_ISDN_PPP
1654 if (minor <= ISDN_MINOR_PPPMAX) {
1655 retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
1657 isdn_lock_drivers();
1666 isdn_close(struct inode *ino, struct file *filep)
1668 uint minor = MINOR(ino->i_rdev);
1671 if (minor == ISDN_MINOR_STATUS) {
1672 infostruct *p = dev->infochain;
1673 infostruct *q = NULL;
1676 if (p->private == (char *) &(filep->private_data)) {
1680 dev->infochain = (infostruct *) (p->next);
1685 p = (infostruct *) (p->next);
1687 printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
1690 isdn_unlock_drivers();
1691 if (minor <= ISDN_MINOR_BMAX)
1693 if (minor <= ISDN_MINOR_CTRLMAX) {
1694 if (dev->profd == current)
1698 #ifdef CONFIG_ISDN_PPP
1699 if (minor <= ISDN_MINOR_PPPMAX)
1700 isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
1708 static struct file_operations isdn_fops =
1710 .owner = THIS_MODULE,
1711 .llseek = no_llseek,
1713 .write = isdn_write,
1715 .ioctl = isdn_ioctl,
1717 .release = isdn_close,
1721 isdn_map_eaz2msn(char *msn, int di)
1723 isdn_driver_t *this = dev->drv[di];
1726 if (strlen(msn) == 1) {
1728 if ((i >= 0) && (i <= 9))
1729 if (strlen(this->msn2eaz[i]))
1730 return (this->msn2eaz[i]);
1736 * Find an unused ISDN-channel, whose feature-flags match the
1737 * given L2- and L3-protocols.
1739 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1742 * This function must be called with holding the dev->lock.
1745 isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
1746 ,int pre_chan, char *msn)
1752 features = ((1 << l2_proto) | (0x10000 << l3_proto));
1753 vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
1754 ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
1755 /* If Layer-2 protocol is V.110, accept drivers with
1756 * transparent feature even if these don't support V.110
1757 * because we can emulate this in linklevel.
1759 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1760 if (USG_NONE(dev->usage[i]) &&
1761 (dev->drvmap[i] != -1)) {
1762 int d = dev->drvmap[i];
1763 if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
1764 ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
1766 if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
1768 if (dev->usage[i] & ISDN_USAGE_DISABLED)
1769 continue; /* usage not allowed */
1770 if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
1771 if (((dev->drv[d]->interface->features & features) == features) ||
1772 (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
1773 (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
1774 if ((pre_dev < 0) || (pre_chan < 0)) {
1775 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1776 dev->usage[i] |= usage;
1780 if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
1781 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1782 dev->usage[i] |= usage;
1794 * Set state of ISDN-channel to 'unused'
1797 isdn_free_channel(int di, int ch, int usage)
1801 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1802 if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
1803 (dev->drvmap[i] == di) &&
1804 (dev->chanmap[i] == ch)) {
1805 dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
1806 strcpy(dev->num[i], "???");
1809 // 20.10.99 JIM, try to reinitialize v110 !
1810 dev->v110emu[i] = 0;
1811 atomic_set(&(dev->v110use[i]), 0);
1812 isdn_v110_close(dev->v110[i]);
1813 dev->v110[i] = NULL;
1814 // 20.10.99 JIM, try to reinitialize v110 !
1816 skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
1821 * Cancel Exclusive-Flag for ISDN-channel
1824 isdn_unexclusive_channel(int di, int ch)
1828 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1829 if ((dev->drvmap[i] == di) &&
1830 (dev->chanmap[i] == ch)) {
1831 dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
1838 * writebuf replacement for SKB_ABLE drivers
1841 isdn_writebuf_stub(int drvidx, int chan, const u_char __user * buf, int len)
1844 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1845 struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
1849 skb_reserve(skb, hl);
1850 copy_from_user(skb_put(skb, len), buf, len);
1851 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
1855 dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
1860 * Return: length of data on success, -ERRcode on failure.
1863 isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
1866 struct sk_buff *nskb = NULL;
1867 int v110_ret = skb->len;
1868 int idx = isdn_dc2minor(drvidx, chan);
1870 if (dev->v110[idx]) {
1871 atomic_inc(&dev->v110use[idx]);
1872 nskb = isdn_v110_encode(dev->v110[idx], skb);
1873 atomic_dec(&dev->v110use[idx]);
1876 v110_ret = *((int *)nskb->data);
1877 skb_pull(nskb, sizeof(int));
1879 dev_kfree_skb(nskb);
1882 /* V.110 must always be acknowledged */
1884 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
1886 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1888 if( skb_headroom(skb) < hl ){
1890 * This should only occur when new HL driver with
1891 * increased hl_hdrlen was loaded after netdevice
1892 * was created and connected to the new driver.
1894 * The V.110 branch (re-allocates on its own) does
1897 struct sk_buff * skb_tmp;
1899 skb_tmp = skb_realloc_headroom(skb, hl);
1900 printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
1901 if (!skb_tmp) return -ENOMEM; /* 0 better? */
1902 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
1906 dev_kfree_skb(skb_tmp);
1909 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
1913 dev->obytes[idx] += ret;
1914 if (dev->v110[idx]) {
1915 atomic_inc(&dev->v110use[idx]);
1916 dev->v110[idx]->skbuser++;
1917 atomic_dec(&dev->v110use[idx]);
1918 /* For V.110 return unencoded data length */
1920 /* if the complete frame was send we free the skb;
1921 if not upper function will requeue the skb */
1922 if (ret == skb->len)
1927 dev_kfree_skb(nskb);
1932 isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
1936 init_waitqueue_head(&d->st_waitq);
1937 if (d->flags & DRV_FLAG_RUNNING)
1939 if (n < 1) return 0;
1941 m = (adding) ? d->channels + n : n;
1943 if (dev->channels + n > ISDN_MAX_CHANNELS) {
1944 printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
1949 if ((adding) && (d->rcverr))
1951 if (!(d->rcverr = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
1952 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
1955 memset((char *) d->rcverr, 0, sizeof(int) * m);
1957 if ((adding) && (d->rcvcount))
1959 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
1960 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
1961 if (!adding) kfree(d->rcverr);
1964 memset((char *) d->rcvcount, 0, sizeof(int) * m);
1966 if ((adding) && (d->rpqueue)) {
1967 for (j = 0; j < d->channels; j++)
1968 skb_queue_purge(&d->rpqueue[j]);
1971 if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
1972 printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
1979 for (j = 0; j < m; j++) {
1980 skb_queue_head_init(&d->rpqueue[j]);
1983 if ((adding) && (d->rcv_waitq))
1984 kfree(d->rcv_waitq);
1985 d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
1986 if (!d->rcv_waitq) {
1987 printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
1995 d->snd_waitq = d->rcv_waitq + m;
1996 for (j = 0; j < m; j++) {
1997 init_waitqueue_head(&d->rcv_waitq[j]);
1998 init_waitqueue_head(&d->snd_waitq[j]);
2002 for (j = d->channels; j < m; j++)
2003 for (k = 0; k < ISDN_MAX_CHANNELS; k++)
2004 if (dev->chanmap[k] < 0) {
2005 dev->chanmap[k] = j;
2006 dev->drvmap[k] = drvidx;
2014 * Low-level-driver registration
2018 set_global_features(void)
2022 dev->global_features = 0;
2023 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
2024 if (!dev->drv[drvidx])
2026 if (dev->drv[drvidx]->interface)
2027 dev->global_features |= dev->drv[drvidx]->interface->features;
2031 #ifdef CONFIG_ISDN_DIVERSION
2033 static char *map_drvname(int di)
2035 if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
2037 return(dev->drvid[di]); /* driver name */
2040 static int map_namedrv(char *id)
2043 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2044 { if (!strcmp(dev->drvid[i],id))
2050 int DIVERT_REG_NAME(isdn_divert_if *i_div)
2052 if (i_div->if_magic != DIVERT_IF_MAGIC)
2053 return(DIVERT_VER_ERR);
2056 case DIVERT_CMD_REL:
2057 if (divert_if != i_div)
2058 return(DIVERT_REL_ERR);
2059 divert_if = NULL; /* free interface */
2060 return(DIVERT_NO_ERR);
2062 case DIVERT_CMD_REG:
2064 return(DIVERT_REG_ERR);
2065 i_div->ll_cmd = isdn_command; /* set command function */
2066 i_div->drv_to_name = map_drvname;
2067 i_div->name_to_drv = map_namedrv;
2068 divert_if = i_div; /* remember interface */
2069 return(DIVERT_NO_ERR);
2072 return(DIVERT_CMD_ERR);
2074 } /* DIVERT_REG_NAME */
2076 EXPORT_SYMBOL(DIVERT_REG_NAME);
2078 #endif /* CONFIG_ISDN_DIVERSION */
2081 EXPORT_SYMBOL(register_isdn);
2082 #ifdef CONFIG_ISDN_PPP
2083 EXPORT_SYMBOL(isdn_ppp_register_compressor);
2084 EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
2088 register_isdn(isdn_if * i)
2095 if (dev->drivers >= ISDN_MAX_DRIVERS) {
2096 printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
2100 if (!i->writebuf_skb) {
2101 printk(KERN_WARNING "register_isdn: No write routine given.\n");
2104 if (!(d = kmalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
2105 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
2108 memset((char *) d, 0, sizeof(isdn_driver_t));
2110 d->maxbufsize = i->maxbufsize;
2113 d->flags = DRV_FLAG_LOADED;
2117 spin_lock_irqsave(&dev->lock, flags);
2118 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2119 if (!dev->drv[drvidx])
2121 if (isdn_add_channels(d, drvidx, i->channels, 0)) {
2122 spin_unlock_irqrestore(&dev->lock, flags);
2126 i->channels = drvidx;
2127 i->rcvcallb_skb = isdn_receive_skb_callback;
2128 i->statcallb = isdn_status_callback;
2130 sprintf(i->id, "line%d", drvidx);
2131 for (j = 0; j < drvidx; j++)
2132 if (!strcmp(i->id, dev->drvid[j]))
2133 sprintf(i->id, "line%d", drvidx);
2134 dev->drv[drvidx] = d;
2135 strcpy(dev->drvid[drvidx], i->id);
2138 set_global_features();
2139 spin_unlock_irqrestore(&dev->lock, flags);
2144 *****************************************************************************
2145 * And now the modules code.
2146 *****************************************************************************
2150 isdn_getrev(const char *revision)
2155 if ((p = strchr(revision, ':'))) {
2157 p = strchr(rev, '$');
2165 * Allocate and initialize all data, register modem-devices
2167 static int __init isdn_init(void)
2172 if (!(dev = (isdn_dev *) vmalloc(sizeof(isdn_dev)))) {
2173 printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
2176 memset((char *) dev, 0, sizeof(isdn_dev));
2177 init_timer(&dev->timer);
2178 dev->timer.function = isdn_timer_funct;
2179 spin_lock_init(&dev->lock);
2180 spin_lock_init(&dev->timerlock);
2182 dev->owner = THIS_MODULE;
2184 init_MUTEX(&dev->sem);
2185 init_waitqueue_head(&dev->info_waitq);
2186 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2187 dev->drvmap[i] = -1;
2188 dev->chanmap[i] = -1;
2190 strcpy(dev->num[i], "???");
2191 init_waitqueue_head(&dev->mdm.info[i].open_wait);
2192 init_waitqueue_head(&dev->mdm.info[i].close_wait);
2194 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
2195 printk(KERN_WARNING "isdn: Could not register control devices\n");
2199 if ((isdn_tty_modem_init()) < 0) {
2200 printk(KERN_WARNING "isdn: Could not register tty devices\n");
2202 unregister_chrdev(ISDN_MAJOR, "isdn");
2205 #ifdef CONFIG_ISDN_PPP
2206 if (isdn_ppp_init() < 0) {
2207 printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
2209 unregister_chrdev(ISDN_MAJOR, "isdn");
2213 #endif /* CONFIG_ISDN_PPP */
2215 strcpy(tmprev, isdn_revision);
2216 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
2217 strcpy(tmprev, isdn_tty_revision);
2218 printk("%s/", isdn_getrev(tmprev));
2219 strcpy(tmprev, isdn_net_revision);
2220 printk("%s/", isdn_getrev(tmprev));
2221 strcpy(tmprev, isdn_ppp_revision);
2222 printk("%s/", isdn_getrev(tmprev));
2223 strcpy(tmprev, isdn_audio_revision);
2224 printk("%s/", isdn_getrev(tmprev));
2225 strcpy(tmprev, isdn_v110_revision);
2226 printk("%s", isdn_getrev(tmprev));
2229 printk(" loaded\n");
2240 static void __exit isdn_exit(void)
2242 #ifdef CONFIG_ISDN_PPP
2245 if (isdn_net_rmall() < 0) {
2246 printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
2250 unregister_chrdev(ISDN_MAJOR, "isdn");
2251 del_timer(&dev->timer);
2252 /* call vfree with interrupts enabled, else it will hang */
2254 printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
2257 module_init(isdn_init);
2258 module_exit(isdn_exit);