1 /* $Id: isdn_common.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, common used functions (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/poll.h>
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/isdn.h>
20 #include <linux/smp_lock.h>
21 #include "isdn_common.h"
25 #ifdef CONFIG_ISDN_AUDIO
26 #include "isdn_audio.h"
28 #ifdef CONFIG_ISDN_DIVERSION_MODULE
29 #define CONFIG_ISDN_DIVERSION
31 #ifdef CONFIG_ISDN_DIVERSION
32 #include <linux/isdn_divertif.h>
33 #endif /* CONFIG_ISDN_DIVERSION */
34 #include "isdn_v110.h"
37 #undef ISDN_DEBUG_STATCALLB
39 MODULE_DESCRIPTION("ISDN4Linux: link layer");
40 MODULE_AUTHOR("Fritz Elfert");
41 MODULE_LICENSE("GPL");
45 static char *isdn_revision = "$Revision: 1.1.2.3 $";
47 extern char *isdn_net_revision;
48 extern char *isdn_tty_revision;
49 #ifdef CONFIG_ISDN_PPP
50 extern char *isdn_ppp_revision;
52 static char *isdn_ppp_revision = ": none $";
54 #ifdef CONFIG_ISDN_AUDIO
55 extern char *isdn_audio_revision;
57 static char *isdn_audio_revision = ": none $";
59 extern char *isdn_v110_revision;
61 #ifdef CONFIG_ISDN_DIVERSION
62 static isdn_divert_if *divert_if; /* = NULL */
63 #endif /* CONFIG_ISDN_DIVERSION */
66 static int isdn_writebuf_stub(int, int, const u_char __user *, int);
67 static void set_global_features(void);
68 static int isdn_wildmat(char *s, char *p);
69 static int isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding);
72 isdn_lock_driver(isdn_driver_t *drv)
74 try_module_get(drv->interface->owner);
79 isdn_lock_drivers(void)
83 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
86 isdn_lock_driver(dev->drv[i]);
91 isdn_unlock_driver(isdn_driver_t *drv)
95 module_put(drv->interface->owner);
100 isdn_unlock_drivers(void)
104 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
107 isdn_unlock_driver(dev->drv[i]);
111 #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
113 isdn_dumppkt(char *s, u_char * p, int len, int dumplen)
117 printk(KERN_DEBUG "%s(%d) ", s, len);
118 for (dumpc = 0; (dumpc < dumplen) && (len); len--, dumpc++)
119 printk(" %02x", *p++);
125 * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
126 * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
129 isdn_star(char *s, char *p)
131 while (isdn_wildmat(s, p)) {
139 * Shell-type Pattern-matching for incoming caller-Ids
140 * This function gets a string in s and checks, if it matches the pattern
146 * 2 = no match. Would eventually match, if s would be longer.
150 * '?' matches one character
151 * '*' matches zero or more characters
152 * [xyz] matches the set of characters in brackets.
153 * [^xyz] matches any single character not in the set of characters
157 isdn_wildmat(char *s, char *p)
160 register int matched;
161 register int reverse;
162 register int nostar = 1;
170 * Literal match with following character,
176 return (*s == '\0')?2:1;
179 /* Match anything. */
185 /* Trailing star matches everything. */
186 return (*++p ? isdn_star(s, p) : 0);
188 /* [^....] means inverse character class. */
189 if ((reverse = (p[1] == '^')))
191 for (last = 0, matched = 0; *++p && (*p != ']'); last = *p)
192 /* This next line requires a good C compiler. */
193 if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
195 if (matched == reverse)
199 return (*s == '\0')?0:nostar;
202 int isdn_msncmp( const char * msn1, const char * msn2 )
204 char TmpMsn1[ ISDN_MSNLEN ];
205 char TmpMsn2[ ISDN_MSNLEN ];
208 for ( p = TmpMsn1; *msn1 && *msn1 != ':'; ) // Strip off a SPID
212 for ( p = TmpMsn2; *msn2 && *msn2 != ':'; ) // Strip off a SPID
216 return isdn_wildmat( TmpMsn1, TmpMsn2 );
220 isdn_dc2minor(int di, int ch)
223 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
224 if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
229 static int isdn_timer_cnt1 = 0;
230 static int isdn_timer_cnt2 = 0;
231 static int isdn_timer_cnt3 = 0;
234 isdn_timer_funct(ulong dummy)
236 int tf = dev->tflags;
237 if (tf & ISDN_TIMER_FAST) {
238 if (tf & ISDN_TIMER_MODEMREAD)
239 isdn_tty_readmodem();
240 if (tf & ISDN_TIMER_MODEMPLUS)
241 isdn_tty_modem_escape();
242 if (tf & ISDN_TIMER_MODEMXMIT)
243 isdn_tty_modem_xmit();
245 if (tf & ISDN_TIMER_SLOW) {
246 if (++isdn_timer_cnt1 >= ISDN_TIMER_02SEC) {
248 if (tf & ISDN_TIMER_NETDIAL)
251 if (++isdn_timer_cnt2 >= ISDN_TIMER_1SEC) {
253 if (tf & ISDN_TIMER_NETHANGUP)
255 if (++isdn_timer_cnt3 >= ISDN_TIMER_RINGING) {
257 if (tf & ISDN_TIMER_MODEMRING)
258 isdn_tty_modem_ring();
260 if (tf & ISDN_TIMER_CARRIER)
261 isdn_tty_carrier_timeout();
265 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
269 isdn_timer_ctrl(int tf, int onoff)
274 spin_lock_irqsave(&dev->timerlock, flags);
275 if ((tf & ISDN_TIMER_SLOW) && (!(dev->tflags & ISDN_TIMER_SLOW))) {
276 /* If the slow-timer wasn't activated until now */
280 old_tflags = dev->tflags;
285 if (dev->tflags && !old_tflags)
286 mod_timer(&dev->timer, jiffies+ISDN_TIMER_RES);
287 spin_unlock_irqrestore(&dev->timerlock, flags);
291 * Receive a packet from B-Channel. (Called from low-level-module)
294 isdn_receive_skb_callback(int di, int channel, struct sk_buff *skb)
298 if ((i = isdn_dc2minor(di, channel)) == -1) {
302 /* Update statistics */
303 dev->ibytes[i] += skb->len;
305 /* First, try to deliver data to network-device */
306 if (isdn_net_rcv_skb(i, skb))
310 * makes sense for async streams only, so it is
311 * called after possible net-device delivery.
314 atomic_inc(&dev->v110use[i]);
315 skb = isdn_v110_decode(dev->v110[i], skb);
316 atomic_dec(&dev->v110use[i]);
321 /* No network-device found, deliver to tty or raw-channel */
323 if (isdn_tty_rcv_skb(i, di, channel, skb))
325 wake_up_interruptible(&dev->drv[di]->rcv_waitq[channel]);
331 * Intercept command from Linklevel to Lowlevel.
332 * If layer 2 protocol is V.110 and this is not supported by current
333 * lowlevel-driver, use driver's transparent mode and handle V.110 in
337 isdn_command(isdn_ctrl *cmd)
339 if (cmd->driver == -1) {
340 printk(KERN_WARNING "isdn_command command(%x) driver -1\n", cmd->command);
343 if (!dev->drv[cmd->driver]) {
344 printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d] NULL\n",
345 cmd->command, cmd->driver);
348 if (!dev->drv[cmd->driver]->interface) {
349 printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d]->interface NULL\n",
350 cmd->command, cmd->driver);
353 if (cmd->command == ISDN_CMD_SETL2) {
354 int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
355 unsigned long l2prot = (cmd->arg >> 8) & 255;
356 unsigned long features = (dev->drv[cmd->driver]->interface->features
357 >> ISDN_FEATURE_L2_SHIFT) &
358 ISDN_FEATURE_L2_MASK;
359 unsigned long l2_feature = (1 << l2prot);
362 case ISDN_PROTO_L2_V11096:
363 case ISDN_PROTO_L2_V11019:
364 case ISDN_PROTO_L2_V11038:
365 /* If V.110 requested, but not supported by
366 * HL-driver, set emulator-flag and change
367 * Layer-2 to transparent
369 if (!(features & l2_feature)) {
370 dev->v110emu[idx] = l2prot;
371 cmd->arg = (cmd->arg & 255) |
372 (ISDN_PROTO_L2_TRANS << 8);
374 dev->v110emu[idx] = 0;
377 return dev->drv[cmd->driver]->interface->command(cmd);
381 isdn_all_eaz(int di, int ch)
389 cmd.command = ISDN_CMD_SETEAZ;
390 cmd.parm.num[0] = '\0';
395 * Begin of a CAPI like LL<->HL interface, currently used only for
396 * supplementary service (CAPI 2.0 part III)
398 #include <linux/isdn/capicmd.h>
401 isdn_capi_rec_hl_msg(capi_msg *cm) {
406 di = (cm->adr.Controller & 0x7f) -1;
407 ch = isdn_dc2minor(di, (cm->adr.Controller>>8)& 0x7f);
408 switch(cm->Command) {
410 /* in the moment only handled in tty */
411 return(isdn_tty_capi_facility(cm));
418 isdn_status_callback(isdn_ctrl * c)
429 i = isdn_dc2minor(di, c->arg);
430 switch (c->command) {
431 case ISDN_STAT_BSENT:
434 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
436 if (isdn_net_stat_callback(i, c))
438 if (isdn_v110_stat_callback(i, c))
440 if (isdn_tty_stat_callback(i, c))
442 wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
444 case ISDN_STAT_STAVAIL:
445 dev->drv[di]->stavail += c->arg;
446 wake_up_interruptible(&dev->drv[di]->st_waitq);
449 dev->drv[di]->flags |= DRV_FLAG_RUNNING;
450 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
451 if (dev->drvmap[i] == di)
452 isdn_all_eaz(di, dev->chanmap[i]);
453 set_global_features();
456 dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
458 case ISDN_STAT_ICALL:
461 #ifdef ISDN_DEBUG_STATCALLB
462 printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
464 if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
467 cmd.command = ISDN_CMD_HANGUP;
471 /* Try to find a network-interface which will accept incoming call */
472 r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
475 /* No network-device replies.
477 * These return 0 on no match, 1 on match and
478 * 3 on eventually match, if CID is longer.
480 if (c->command == ISDN_STAT_ICALL)
481 if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return(retval);
482 #ifdef CONFIG_ISDN_DIVERSION
484 if ((retval = divert_if->stat_callback(c)))
485 return(retval); /* processed */
486 #endif /* CONFIG_ISDN_DIVERSION */
487 if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
488 /* No tty responding */
491 cmd.command = ISDN_CMD_HANGUP;
497 /* Schedule connection-setup */
501 cmd.command = ISDN_CMD_ACCEPTD;
502 for ( p = dev->netdev; p; p = p->next )
503 if ( p->local->isdn_channel == cmd.arg )
505 strcpy( cmd.parm.setup.eazmsn, p->local->msn );
512 case 2: /* For calling back, first reject incoming call ... */
513 case 3: /* Interface found, but down, reject call actively */
515 printk(KERN_INFO "isdn: Rejecting Call\n");
518 cmd.command = ISDN_CMD_HANGUP;
524 /* ... then start callback. */
528 /* Number would eventually match, if longer */
532 #ifdef ISDN_DEBUG_STATCALLB
533 printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
540 #ifdef ISDN_DEBUG_STATCALLB
541 printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
543 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
545 if (strcmp(c->parm.num, "0"))
546 isdn_net_stat_callback(i, c);
547 isdn_tty_stat_callback(i, c);
549 case ISDN_STAT_CAUSE:
550 #ifdef ISDN_DEBUG_STATCALLB
551 printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
553 printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
554 dev->drvid[di], c->arg, c->parm.num);
555 isdn_tty_stat_callback(i, c);
556 #ifdef CONFIG_ISDN_DIVERSION
558 divert_if->stat_callback(c);
559 #endif /* CONFIG_ISDN_DIVERSION */
561 case ISDN_STAT_DISPLAY:
562 #ifdef ISDN_DEBUG_STATCALLB
563 printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
565 isdn_tty_stat_callback(i, c);
566 #ifdef CONFIG_ISDN_DIVERSION
568 divert_if->stat_callback(c);
569 #endif /* CONFIG_ISDN_DIVERSION */
571 case ISDN_STAT_DCONN:
574 #ifdef ISDN_DEBUG_STATCALLB
575 printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
577 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
579 /* Find any net-device, waiting for D-channel setup */
580 if (isdn_net_stat_callback(i, c))
582 isdn_v110_stat_callback(i, c);
583 /* Find any ttyI, waiting for D-channel setup */
584 if (isdn_tty_stat_callback(i, c)) {
587 cmd.command = ISDN_CMD_ACCEPTB;
595 #ifdef ISDN_DEBUG_STATCALLB
596 printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
598 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
600 dev->drv[di]->online &= ~(1 << (c->arg));
602 /* Signal hangup to network-devices */
603 if (isdn_net_stat_callback(i, c))
605 isdn_v110_stat_callback(i, c);
606 if (isdn_tty_stat_callback(i, c))
608 #ifdef CONFIG_ISDN_DIVERSION
610 divert_if->stat_callback(c);
611 #endif /* CONFIG_ISDN_DIVERSION */
614 case ISDN_STAT_BCONN:
617 #ifdef ISDN_DEBUG_STATCALLB
618 printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
620 /* Signal B-channel-connect to network-devices */
621 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
623 dev->drv[di]->online |= (1 << (c->arg));
625 if (isdn_net_stat_callback(i, c))
627 isdn_v110_stat_callback(i, c);
628 if (isdn_tty_stat_callback(i, c))
634 #ifdef ISDN_DEBUG_STATCALLB
635 printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
637 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
639 dev->drv[di]->online &= ~(1 << (c->arg));
641 #ifdef CONFIG_ISDN_X25
642 /* Signal hangup to network-devices */
643 if (isdn_net_stat_callback(i, c))
646 isdn_v110_stat_callback(i, c);
647 if (isdn_tty_stat_callback(i, c))
650 case ISDN_STAT_NODCH:
653 #ifdef ISDN_DEBUG_STATCALLB
654 printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
656 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
658 if (isdn_net_stat_callback(i, c))
660 if (isdn_tty_stat_callback(i, c))
663 case ISDN_STAT_ADDCH:
664 spin_lock_irqsave(&dev->lock, flags);
665 if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
666 spin_unlock_irqrestore(&dev->lock, flags);
669 spin_unlock_irqrestore(&dev->lock, flags);
672 case ISDN_STAT_DISCH:
673 spin_lock_irqsave(&dev->lock, flags);
674 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
675 if ((dev->drvmap[i] == di) &&
676 (dev->chanmap[i] == c->arg)) {
678 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
680 if (USG_NONE(dev->usage[i])) {
681 dev->usage[i] |= ISDN_USAGE_DISABLED;
687 spin_unlock_irqrestore(&dev->lock, flags);
690 case ISDN_STAT_UNLOAD:
691 while (dev->drv[di]->locks > 0) {
692 isdn_unlock_driver(dev->drv[di]);
694 spin_lock_irqsave(&dev->lock, flags);
695 isdn_tty_stat_callback(i, c);
696 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
697 if (dev->drvmap[i] == di) {
699 dev->chanmap[i] = -1;
700 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
703 dev->channels -= dev->drv[di]->channels;
704 kfree(dev->drv[di]->rcverr);
705 kfree(dev->drv[di]->rcvcount);
706 for (i = 0; i < dev->drv[di]->channels; i++)
707 skb_queue_purge(&dev->drv[di]->rpqueue[i]);
708 kfree(dev->drv[di]->rpqueue);
709 kfree(dev->drv[di]->rcv_waitq);
712 dev->drvid[di][0] = '\0';
714 set_global_features();
715 spin_unlock_irqrestore(&dev->lock, flags);
717 case ISDN_STAT_L1ERR:
719 case CAPI_PUT_MESSAGE:
720 return(isdn_capi_rec_hl_msg(&c->parm.cmsg));
721 #ifdef CONFIG_ISDN_TTY_FAX
722 case ISDN_STAT_FAXIND:
723 isdn_tty_stat_callback(i, c);
726 #ifdef CONFIG_ISDN_AUDIO
727 case ISDN_STAT_AUDIO:
728 isdn_tty_stat_callback(i, c);
731 #ifdef CONFIG_ISDN_DIVERSION
733 case ISDN_STAT_REDIR:
735 return(divert_if->stat_callback(c));
736 #endif /* CONFIG_ISDN_DIVERSION */
744 * Get integer from char-pointer, set pointer to end of number
747 isdn_getnum(char **p)
751 while (*p[0] >= '0' && *p[0] <= '9')
752 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
759 * isdn_readbchan() tries to get data from the read-queue.
760 * It MUST be called with interrupts off.
762 * Be aware that this is not an atomic operation when sleep != 0, even though
763 * interrupts are turned off! Well, like that we are currently only called
764 * on behalf of a read system call on raw device files (which are documented
765 * to be dangerous and for debugging purpose only). The inode semaphore
766 * takes care that this is not called for the same minor device number while
767 * we are sleeping, but access is not serialized against simultaneous read()
768 * from the corresponding ttyI device. Can other ugly events, like changes
769 * of the mapping (di,ch)<->minor, happen during the sleep? --he
772 isdn_readbchan(int di, int channel, u_char * buf, u_char * fp, int len, wait_queue_head_t *sleep)
783 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
785 interruptible_sleep_on(sleep);
789 if (len > dev->drv[di]->rcvcount[channel])
790 len = dev->drv[di]->rcvcount[channel];
794 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
796 #ifdef CONFIG_ISDN_AUDIO
797 if (ISDN_AUDIO_SKB_LOCK(skb))
799 ISDN_AUDIO_SKB_LOCK(skb) = 1;
800 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
802 unsigned long DLEmask = (1 << channel);
805 count_pull = count_put = 0;
806 while ((count_pull < skb->len) && (len > 0)) {
808 if (dev->drv[di]->DLEflag & DLEmask) {
810 dev->drv[di]->DLEflag &= ~DLEmask;
814 dev->drv[di]->DLEflag |= DLEmask;
815 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
822 if (count_pull >= skb->len)
826 /* No DLE's in buff, so simply copy it */
828 if ((count_pull = skb->len) > len) {
832 count_put = count_pull;
833 skb_copy_from_linear_data(skb, cp, count_put);
836 #ifdef CONFIG_ISDN_AUDIO
841 memset(fp, 0, count_put);
845 /* We got all the data in this buff.
846 * Now we can dequeue it.
850 #ifdef CONFIG_ISDN_AUDIO
851 ISDN_AUDIO_SKB_LOCK(skb) = 0;
853 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
856 /* Not yet emptied this buff, so it
857 * must stay in the queue, for further calls
858 * but we pull off the data we got until now.
860 skb_pull(skb, count_pull);
861 #ifdef CONFIG_ISDN_AUDIO
862 ISDN_AUDIO_SKB_LOCK(skb) = 0;
865 dev->drv[di]->rcvcount[channel] -= count_put;
871 * isdn_readbchan_tty() tries to get data from the read-queue.
872 * It MUST be called with interrupts off.
874 * Be aware that this is not an atomic operation when sleep != 0, even though
875 * interrupts are turned off! Well, like that we are currently only called
876 * on behalf of a read system call on raw device files (which are documented
877 * to be dangerous and for debugging purpose only). The inode semaphore
878 * takes care that this is not called for the same minor device number while
879 * we are sleeping, but access is not serialized against simultaneous read()
880 * from the corresponding ttyI device. Can other ugly events, like changes
881 * of the mapping (di,ch)<->minor, happen during the sleep? --he
884 isdn_readbchan_tty(int di, int channel, struct tty_struct *tty, int cisco_hack)
896 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
899 len = tty_buffer_request_room(tty, dev->drv[di]->rcvcount[channel]);
905 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
907 #ifdef CONFIG_ISDN_AUDIO
908 if (ISDN_AUDIO_SKB_LOCK(skb))
910 ISDN_AUDIO_SKB_LOCK(skb) = 1;
911 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
913 unsigned long DLEmask = (1 << channel);
916 count_pull = count_put = 0;
917 while ((count_pull < skb->len) && (len > 0)) {
918 /* push every character but the last to the tty buffer directly */
920 tty_insert_flip_char(tty, last, TTY_NORMAL);
922 if (dev->drv[di]->DLEflag & DLEmask) {
924 dev->drv[di]->DLEflag &= ~DLEmask;
928 dev->drv[di]->DLEflag |= DLEmask;
929 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
936 if (count_pull >= skb->len)
940 /* No DLE's in buff, so simply copy it */
942 if ((count_pull = skb->len) > len) {
946 count_put = count_pull;
948 tty_insert_flip_string(tty, skb->data, count_put - 1);
949 last = skb->data[count_put - 1];
951 #ifdef CONFIG_ISDN_AUDIO
956 /* We got all the data in this buff.
957 * Now we can dequeue it.
960 tty_insert_flip_char(tty, last, 0xFF);
962 tty_insert_flip_char(tty, last, TTY_NORMAL);
963 #ifdef CONFIG_ISDN_AUDIO
964 ISDN_AUDIO_SKB_LOCK(skb) = 0;
966 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
969 tty_insert_flip_char(tty, last, TTY_NORMAL);
970 /* Not yet emptied this buff, so it
971 * must stay in the queue, for further calls
972 * but we pull off the data we got until now.
974 skb_pull(skb, count_pull);
975 #ifdef CONFIG_ISDN_AUDIO
976 ISDN_AUDIO_SKB_LOCK(skb) = 0;
979 dev->drv[di]->rcvcount[channel] -= count_put;
986 isdn_minor2drv(int minor)
988 return (dev->drvmap[minor]);
992 isdn_minor2chan(int minor)
994 return (dev->chanmap[minor]);
1000 static char istatbuf[2048];
1004 sprintf(istatbuf, "idmap:\t");
1005 p = istatbuf + strlen(istatbuf);
1006 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1007 sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
1008 p = istatbuf + strlen(istatbuf);
1010 sprintf(p, "\nchmap:\t");
1011 p = istatbuf + strlen(istatbuf);
1012 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1013 sprintf(p, "%d ", dev->chanmap[i]);
1014 p = istatbuf + strlen(istatbuf);
1016 sprintf(p, "\ndrmap:\t");
1017 p = istatbuf + strlen(istatbuf);
1018 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1019 sprintf(p, "%d ", dev->drvmap[i]);
1020 p = istatbuf + strlen(istatbuf);
1022 sprintf(p, "\nusage:\t");
1023 p = istatbuf + strlen(istatbuf);
1024 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1025 sprintf(p, "%d ", dev->usage[i]);
1026 p = istatbuf + strlen(istatbuf);
1028 sprintf(p, "\nflags:\t");
1029 p = istatbuf + strlen(istatbuf);
1030 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
1032 sprintf(p, "%ld ", dev->drv[i]->online);
1033 p = istatbuf + strlen(istatbuf);
1036 p = istatbuf + strlen(istatbuf);
1039 sprintf(p, "\nphone:\t");
1040 p = istatbuf + strlen(istatbuf);
1041 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1042 sprintf(p, "%s ", dev->num[i]);
1043 p = istatbuf + strlen(istatbuf);
1049 /* Module interface-code */
1052 isdn_info_update(void)
1054 infostruct *p = dev->infochain;
1058 p = (infostruct *) p->next;
1060 wake_up_interruptible(&(dev->info_waitq));
1064 isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1066 uint minor = iminor(file->f_path.dentry->d_inode);
1074 if (minor == ISDN_MINOR_STATUS) {
1075 if (!file->private_data) {
1076 if (file->f_flags & O_NONBLOCK) {
1080 interruptible_sleep_on(&(dev->info_waitq));
1083 file->private_data = NULL;
1084 if ((len = strlen(p)) <= count) {
1085 if (copy_to_user(buf, p, len)) {
1096 if (!dev->drivers) {
1100 if (minor <= ISDN_MINOR_BMAX) {
1101 printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
1102 drvidx = isdn_minor2drv(minor);
1107 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1111 chidx = isdn_minor2chan(minor);
1112 if (!(p = kmalloc(count, GFP_KERNEL))) {
1116 len = isdn_readbchan(drvidx, chidx, p, NULL, count,
1117 &dev->drv[drvidx]->rcv_waitq[chidx]);
1119 if (copy_to_user(buf,p,len))
1125 if (minor <= ISDN_MINOR_CTRLMAX) {
1126 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1131 if (!dev->drv[drvidx]->stavail) {
1132 if (file->f_flags & O_NONBLOCK) {
1136 interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
1138 if (dev->drv[drvidx]->interface->readstat) {
1139 if (count > dev->drv[drvidx]->stavail)
1140 count = dev->drv[drvidx]->stavail;
1141 len = dev->drv[drvidx]->interface->readstat(buf, count,
1142 drvidx, isdn_minor2chan(minor - ISDN_MINOR_CTRL));
1151 dev->drv[drvidx]->stavail -= len;
1153 dev->drv[drvidx]->stavail = 0;
1158 #ifdef CONFIG_ISDN_PPP
1159 if (minor <= ISDN_MINOR_PPPMAX) {
1160 retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
1171 isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
1173 uint minor = iminor(file->f_path.dentry->d_inode);
1178 if (minor == ISDN_MINOR_STATUS)
1184 if (minor <= ISDN_MINOR_BMAX) {
1185 printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
1186 drvidx = isdn_minor2drv(minor);
1191 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1195 chidx = isdn_minor2chan(minor);
1196 while ((retval = isdn_writebuf_stub(drvidx, chidx, buf, count)) == 0)
1197 interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
1200 if (minor <= ISDN_MINOR_CTRLMAX) {
1201 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1207 * We want to use the isdnctrl device to load the firmware
1209 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1212 if (dev->drv[drvidx]->interface->writecmd)
1213 retval = dev->drv[drvidx]->interface->
1214 writecmd(buf, count, drvidx,
1215 isdn_minor2chan(minor - ISDN_MINOR_CTRL));
1220 #ifdef CONFIG_ISDN_PPP
1221 if (minor <= ISDN_MINOR_PPPMAX) {
1222 retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
1233 isdn_poll(struct file *file, poll_table * wait)
1235 unsigned int mask = 0;
1236 unsigned int minor = iminor(file->f_path.dentry->d_inode);
1237 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1240 if (minor == ISDN_MINOR_STATUS) {
1241 poll_wait(file, &(dev->info_waitq), wait);
1242 /* mask = POLLOUT | POLLWRNORM; */
1243 if (file->private_data) {
1244 mask |= POLLIN | POLLRDNORM;
1248 if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
1250 /* driver deregistered while file open */
1254 poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
1255 mask = POLLOUT | POLLWRNORM;
1256 if (dev->drv[drvidx]->stavail) {
1257 mask |= POLLIN | POLLRDNORM;
1261 #ifdef CONFIG_ISDN_PPP
1262 if (minor <= ISDN_MINOR_PPPMAX) {
1263 mask = isdn_ppp_poll(file, wait);
1275 isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1277 uint minor = iminor(inode);
1288 isdn_ioctl_struct iocts;
1289 isdn_net_ioctl_phone phone;
1290 isdn_net_ioctl_cfg cfg;
1292 void __user *argp = (void __user *)arg;
1294 #define name iocpar.name
1295 #define bname iocpar.bname
1296 #define iocts iocpar.iocts
1297 #define phone iocpar.phone
1298 #define cfg iocpar.cfg
1300 if (minor == ISDN_MINOR_STATUS) {
1308 ulong __user *p = argp;
1310 if (!access_ok(VERIFY_WRITE, p,
1311 sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
1313 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1314 put_user(dev->ibytes[i], p++);
1315 put_user(dev->obytes[i], p++);
1321 #ifdef CONFIG_NETDEVICES
1323 /* Get peer phone number of a connected
1324 * isdn network interface */
1326 if (copy_from_user(&phone, argp, sizeof(phone)))
1328 return isdn_net_getpeer(&phone, argp);
1338 if (minor <= ISDN_MINOR_BMAX) {
1339 drvidx = isdn_minor2drv(minor);
1342 chidx = isdn_minor2chan(minor);
1343 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1347 if (minor <= ISDN_MINOR_CTRLMAX) {
1349 * isdn net devices manage lots of configuration variables as linked lists.
1350 * Those lists must only be manipulated from user space. Some of the ioctl's
1351 * service routines access user space and are not atomic. Therefore, ioctl's
1352 * manipulating the lists and ioctl's sleeping while accessing the lists
1353 * are serialized by means of a semaphore.
1357 printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1360 printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1362 #ifdef CONFIG_NETDEVICES
1364 /* Add a network-interface */
1366 if (copy_from_user(name, argp, sizeof(name)))
1372 ret = mutex_lock_interruptible(&dev->mtx);
1373 if( ret ) return ret;
1374 if ((s = isdn_net_new(s, NULL))) {
1375 if (copy_to_user(argp, s, strlen(s) + 1)){
1382 mutex_unlock(&dev->mtx);
1385 /* Add a slave to a network-interface */
1387 if (copy_from_user(bname, argp, sizeof(bname) - 1))
1391 ret = mutex_lock_interruptible(&dev->mtx);
1392 if( ret ) return ret;
1393 if ((s = isdn_net_newslave(bname))) {
1394 if (copy_to_user(argp, s, strlen(s) + 1)){
1401 mutex_unlock(&dev->mtx);
1404 /* Delete a network-interface */
1406 if (copy_from_user(name, argp, sizeof(name)))
1408 ret = mutex_lock_interruptible(&dev->mtx);
1409 if( ret ) return ret;
1410 ret = isdn_net_rm(name);
1411 mutex_unlock(&dev->mtx);
1416 /* Set configurable parameters of a network-interface */
1418 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1420 return isdn_net_setcfg(&cfg);
1424 /* Get configurable parameters of a network-interface */
1426 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1428 if (!(ret = isdn_net_getcfg(&cfg))) {
1429 if (copy_to_user(argp, &cfg, sizeof(cfg)))
1436 /* Add a phone-number to a network-interface */
1438 if (copy_from_user(&phone, argp, sizeof(phone)))
1440 ret = mutex_lock_interruptible(&dev->mtx);
1441 if( ret ) return ret;
1442 ret = isdn_net_addphone(&phone);
1443 mutex_unlock(&dev->mtx);
1448 /* Get list of phone-numbers of a network-interface */
1450 if (copy_from_user(&phone, argp, sizeof(phone)))
1452 ret = mutex_lock_interruptible(&dev->mtx);
1453 if( ret ) return ret;
1454 ret = isdn_net_getphones(&phone, argp);
1455 mutex_unlock(&dev->mtx);
1460 /* Delete a phone-number of a network-interface */
1462 if (copy_from_user(&phone, argp, sizeof(phone)))
1464 ret = mutex_lock_interruptible(&dev->mtx);
1465 if( ret ) return ret;
1466 ret = isdn_net_delphone(&phone);
1467 mutex_unlock(&dev->mtx);
1472 /* Force dialing of a network-interface */
1474 if (copy_from_user(name, argp, sizeof(name)))
1476 return isdn_net_force_dial(name);
1479 #ifdef CONFIG_ISDN_PPP
1483 if (copy_from_user(name, argp, sizeof(name)))
1485 return isdn_ppp_dial_slave(name);
1489 if (copy_from_user(name, argp, sizeof(name)))
1491 return isdn_ppp_hangup_slave(name);
1494 /* Force hangup of a network-interface */
1497 if (copy_from_user(name, argp, sizeof(name)))
1499 return isdn_net_force_hangup(name);
1501 #endif /* CONFIG_NETDEVICES */
1503 dev->net_verbose = arg;
1504 printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
1508 dev->global_flags |= ISDN_GLOBAL_STOPPED;
1510 dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
1511 printk(KERN_INFO "isdn: Global Mode %s\n",
1512 (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
1519 if (copy_from_user(&iocts, argp,
1520 sizeof(isdn_ioctl_struct)))
1522 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1523 if (strlen(iocts.drvid)) {
1524 if ((p = strchr(iocts.drvid, ',')))
1527 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1528 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1537 dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
1539 dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
1542 dev->profd = current;
1546 /* Get all Modem-Profiles */
1548 char __user *p = argp;
1551 if (!access_ok(VERIFY_WRITE, argp,
1552 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1553 * ISDN_MAX_CHANNELS))
1556 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1557 if (copy_to_user(p, dev->mdm.info[i].emu.profile,
1560 p += ISDN_MODEM_NUMREG;
1561 if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
1564 if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
1568 return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
1573 /* Set all Modem-Profiles */
1575 char __user *p = argp;
1578 if (!access_ok(VERIFY_READ, argp,
1579 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1580 * ISDN_MAX_CHANNELS))
1583 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1584 if (copy_from_user(dev->mdm.info[i].emu.profile, p,
1587 p += ISDN_MODEM_NUMREG;
1588 if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
1591 if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
1601 /* Set/Get MSN->EAZ-Mapping for a driver */
1604 if (copy_from_user(&iocts, argp,
1605 sizeof(isdn_ioctl_struct)))
1607 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1608 if (strlen(iocts.drvid)) {
1610 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1611 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1619 if (cmd == IIOCSETMAP) {
1622 p = (char __user *) iocts.arg;
1628 if (!access_ok(VERIFY_READ, p, 1))
1630 get_user(bname[j], p++);
1637 strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
1643 if (j >= ISDN_MSNLEN)
1650 p = (char __user *) iocts.arg;
1651 for (i = 0; i < 10; i++) {
1652 snprintf(bname, sizeof(bname), "%s%s",
1653 strlen(dev->drv[drvidx]->msn2eaz[i]) ?
1654 dev->drv[drvidx]->msn2eaz[i] : "_",
1655 (i < 9) ? "," : "\0");
1656 if (copy_to_user(p, bname, strlen(bname) + 1))
1666 if (copy_to_user(argp, &dev, sizeof(ulong)))
1673 if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
1674 cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
1680 if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
1682 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1683 if (strlen(iocts.drvid)) {
1684 if ((p = strchr(iocts.drvid, ',')))
1687 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1688 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1696 if (!access_ok(VERIFY_WRITE, argp,
1697 sizeof(isdn_ioctl_struct)))
1700 c.command = ISDN_CMD_IOCTL;
1702 memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
1703 ret = isdn_command(&c);
1704 memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
1705 if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
1712 #ifdef CONFIG_ISDN_PPP
1713 if (minor <= ISDN_MINOR_PPPMAX)
1714 return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
1726 * Open the device code.
1729 isdn_open(struct inode *ino, struct file *filep)
1731 uint minor = iminor(ino);
1734 int retval = -ENODEV;
1737 if (minor == ISDN_MINOR_STATUS) {
1740 if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
1741 p->next = (char *) dev->infochain;
1742 p->private = (char *) &(filep->private_data);
1744 /* At opening we allow a single update */
1745 filep->private_data = (char *) 1;
1755 if (minor <= ISDN_MINOR_BMAX) {
1756 printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
1757 drvidx = isdn_minor2drv(minor);
1760 chidx = isdn_minor2chan(minor);
1761 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1763 if (!(dev->drv[drvidx]->online & (1 << chidx)))
1765 isdn_lock_drivers();
1769 if (minor <= ISDN_MINOR_CTRLMAX) {
1770 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1773 isdn_lock_drivers();
1777 #ifdef CONFIG_ISDN_PPP
1778 if (minor <= ISDN_MINOR_PPPMAX) {
1779 retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
1781 isdn_lock_drivers();
1786 nonseekable_open(ino, filep);
1792 isdn_close(struct inode *ino, struct file *filep)
1794 uint minor = iminor(ino);
1797 if (minor == ISDN_MINOR_STATUS) {
1798 infostruct *p = dev->infochain;
1799 infostruct *q = NULL;
1802 if (p->private == (char *) &(filep->private_data)) {
1806 dev->infochain = (infostruct *) (p->next);
1811 p = (infostruct *) (p->next);
1813 printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
1816 isdn_unlock_drivers();
1817 if (minor <= ISDN_MINOR_BMAX)
1819 if (minor <= ISDN_MINOR_CTRLMAX) {
1820 if (dev->profd == current)
1824 #ifdef CONFIG_ISDN_PPP
1825 if (minor <= ISDN_MINOR_PPPMAX)
1826 isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
1834 static const struct file_operations isdn_fops =
1836 .owner = THIS_MODULE,
1837 .llseek = no_llseek,
1839 .write = isdn_write,
1841 .ioctl = isdn_ioctl,
1843 .release = isdn_close,
1847 isdn_map_eaz2msn(char *msn, int di)
1849 isdn_driver_t *this = dev->drv[di];
1852 if (strlen(msn) == 1) {
1854 if ((i >= 0) && (i <= 9))
1855 if (strlen(this->msn2eaz[i]))
1856 return (this->msn2eaz[i]);
1862 * Find an unused ISDN-channel, whose feature-flags match the
1863 * given L2- and L3-protocols.
1865 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1868 * This function must be called with holding the dev->lock.
1871 isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
1872 ,int pre_chan, char *msn)
1878 features = ((1 << l2_proto) | (0x10000 << l3_proto));
1879 vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
1880 ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
1881 /* If Layer-2 protocol is V.110, accept drivers with
1882 * transparent feature even if these don't support V.110
1883 * because we can emulate this in linklevel.
1885 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1886 if (USG_NONE(dev->usage[i]) &&
1887 (dev->drvmap[i] != -1)) {
1888 int d = dev->drvmap[i];
1889 if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
1890 ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
1892 if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
1894 if (dev->usage[i] & ISDN_USAGE_DISABLED)
1895 continue; /* usage not allowed */
1896 if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
1897 if (((dev->drv[d]->interface->features & features) == features) ||
1898 (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
1899 (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
1900 if ((pre_dev < 0) || (pre_chan < 0)) {
1901 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1902 dev->usage[i] |= usage;
1906 if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
1907 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1908 dev->usage[i] |= usage;
1920 * Set state of ISDN-channel to 'unused'
1923 isdn_free_channel(int di, int ch, int usage)
1927 if ((di < 0) || (ch < 0)) {
1928 printk(KERN_WARNING "%s: called with invalid drv(%d) or channel(%d)\n",
1932 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1933 if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
1934 (dev->drvmap[i] == di) &&
1935 (dev->chanmap[i] == ch)) {
1936 dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
1937 strcpy(dev->num[i], "???");
1940 // 20.10.99 JIM, try to reinitialize v110 !
1941 dev->v110emu[i] = 0;
1942 atomic_set(&(dev->v110use[i]), 0);
1943 isdn_v110_close(dev->v110[i]);
1944 dev->v110[i] = NULL;
1945 // 20.10.99 JIM, try to reinitialize v110 !
1948 skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
1953 * Cancel Exclusive-Flag for ISDN-channel
1956 isdn_unexclusive_channel(int di, int ch)
1960 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1961 if ((dev->drvmap[i] == di) &&
1962 (dev->chanmap[i] == ch)) {
1963 dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
1970 * writebuf replacement for SKB_ABLE drivers
1973 isdn_writebuf_stub(int drvidx, int chan, const u_char __user * buf, int len)
1976 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1977 struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
1981 skb_reserve(skb, hl);
1982 if (copy_from_user(skb_put(skb, len), buf, len)) {
1986 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
1990 dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
1995 * Return: length of data on success, -ERRcode on failure.
1998 isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
2001 struct sk_buff *nskb = NULL;
2002 int v110_ret = skb->len;
2003 int idx = isdn_dc2minor(drvidx, chan);
2005 if (dev->v110[idx]) {
2006 atomic_inc(&dev->v110use[idx]);
2007 nskb = isdn_v110_encode(dev->v110[idx], skb);
2008 atomic_dec(&dev->v110use[idx]);
2011 v110_ret = *((int *)nskb->data);
2012 skb_pull(nskb, sizeof(int));
2014 dev_kfree_skb(nskb);
2017 /* V.110 must always be acknowledged */
2019 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
2021 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
2023 if( skb_headroom(skb) < hl ){
2025 * This should only occur when new HL driver with
2026 * increased hl_hdrlen was loaded after netdevice
2027 * was created and connected to the new driver.
2029 * The V.110 branch (re-allocates on its own) does
2032 struct sk_buff * skb_tmp;
2034 skb_tmp = skb_realloc_headroom(skb, hl);
2035 printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
2036 if (!skb_tmp) return -ENOMEM; /* 0 better? */
2037 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
2041 dev_kfree_skb(skb_tmp);
2044 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
2048 dev->obytes[idx] += ret;
2049 if (dev->v110[idx]) {
2050 atomic_inc(&dev->v110use[idx]);
2051 dev->v110[idx]->skbuser++;
2052 atomic_dec(&dev->v110use[idx]);
2053 /* For V.110 return unencoded data length */
2055 /* if the complete frame was send we free the skb;
2056 if not upper function will requeue the skb */
2057 if (ret == skb->len)
2062 dev_kfree_skb(nskb);
2067 isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
2071 init_waitqueue_head(&d->st_waitq);
2072 if (d->flags & DRV_FLAG_RUNNING)
2074 if (n < 1) return 0;
2076 m = (adding) ? d->channels + n : n;
2078 if (dev->channels + n > ISDN_MAX_CHANNELS) {
2079 printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
2084 if ((adding) && (d->rcverr))
2086 if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
2087 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
2091 if ((adding) && (d->rcvcount))
2093 if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
2094 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
2100 if ((adding) && (d->rpqueue)) {
2101 for (j = 0; j < d->channels; j++)
2102 skb_queue_purge(&d->rpqueue[j]);
2105 if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
2106 printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
2113 for (j = 0; j < m; j++) {
2114 skb_queue_head_init(&d->rpqueue[j]);
2117 if ((adding) && (d->rcv_waitq))
2118 kfree(d->rcv_waitq);
2119 d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
2120 if (!d->rcv_waitq) {
2121 printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
2129 d->snd_waitq = d->rcv_waitq + m;
2130 for (j = 0; j < m; j++) {
2131 init_waitqueue_head(&d->rcv_waitq[j]);
2132 init_waitqueue_head(&d->snd_waitq[j]);
2136 for (j = d->channels; j < m; j++)
2137 for (k = 0; k < ISDN_MAX_CHANNELS; k++)
2138 if (dev->chanmap[k] < 0) {
2139 dev->chanmap[k] = j;
2140 dev->drvmap[k] = drvidx;
2148 * Low-level-driver registration
2152 set_global_features(void)
2156 dev->global_features = 0;
2157 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
2158 if (!dev->drv[drvidx])
2160 if (dev->drv[drvidx]->interface)
2161 dev->global_features |= dev->drv[drvidx]->interface->features;
2165 #ifdef CONFIG_ISDN_DIVERSION
2167 static char *map_drvname(int di)
2169 if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
2171 return(dev->drvid[di]); /* driver name */
2174 static int map_namedrv(char *id)
2177 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2178 { if (!strcmp(dev->drvid[i],id))
2184 int DIVERT_REG_NAME(isdn_divert_if *i_div)
2186 if (i_div->if_magic != DIVERT_IF_MAGIC)
2187 return(DIVERT_VER_ERR);
2190 case DIVERT_CMD_REL:
2191 if (divert_if != i_div)
2192 return(DIVERT_REL_ERR);
2193 divert_if = NULL; /* free interface */
2194 return(DIVERT_NO_ERR);
2196 case DIVERT_CMD_REG:
2198 return(DIVERT_REG_ERR);
2199 i_div->ll_cmd = isdn_command; /* set command function */
2200 i_div->drv_to_name = map_drvname;
2201 i_div->name_to_drv = map_namedrv;
2202 divert_if = i_div; /* remember interface */
2203 return(DIVERT_NO_ERR);
2206 return(DIVERT_CMD_ERR);
2208 } /* DIVERT_REG_NAME */
2210 EXPORT_SYMBOL(DIVERT_REG_NAME);
2212 #endif /* CONFIG_ISDN_DIVERSION */
2215 EXPORT_SYMBOL(register_isdn);
2216 #ifdef CONFIG_ISDN_PPP
2217 EXPORT_SYMBOL(isdn_ppp_register_compressor);
2218 EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
2222 register_isdn(isdn_if * i)
2229 if (dev->drivers >= ISDN_MAX_DRIVERS) {
2230 printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
2234 if (!i->writebuf_skb) {
2235 printk(KERN_WARNING "register_isdn: No write routine given.\n");
2238 if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
2239 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
2243 d->maxbufsize = i->maxbufsize;
2246 d->flags = DRV_FLAG_LOADED;
2250 spin_lock_irqsave(&dev->lock, flags);
2251 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2252 if (!dev->drv[drvidx])
2254 if (isdn_add_channels(d, drvidx, i->channels, 0)) {
2255 spin_unlock_irqrestore(&dev->lock, flags);
2259 i->channels = drvidx;
2260 i->rcvcallb_skb = isdn_receive_skb_callback;
2261 i->statcallb = isdn_status_callback;
2263 sprintf(i->id, "line%d", drvidx);
2264 for (j = 0; j < drvidx; j++)
2265 if (!strcmp(i->id, dev->drvid[j]))
2266 sprintf(i->id, "line%d", drvidx);
2267 dev->drv[drvidx] = d;
2268 strcpy(dev->drvid[drvidx], i->id);
2271 set_global_features();
2272 spin_unlock_irqrestore(&dev->lock, flags);
2277 *****************************************************************************
2278 * And now the modules code.
2279 *****************************************************************************
2283 isdn_getrev(const char *revision)
2288 if ((p = strchr(revision, ':'))) {
2290 p = strchr(rev, '$');
2298 * Allocate and initialize all data, register modem-devices
2300 static int __init isdn_init(void)
2305 if (!(dev = vmalloc(sizeof(isdn_dev)))) {
2306 printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
2309 memset((char *) dev, 0, sizeof(isdn_dev));
2310 init_timer(&dev->timer);
2311 dev->timer.function = isdn_timer_funct;
2312 spin_lock_init(&dev->lock);
2313 spin_lock_init(&dev->timerlock);
2315 dev->owner = THIS_MODULE;
2317 mutex_init(&dev->mtx);
2318 init_waitqueue_head(&dev->info_waitq);
2319 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2320 dev->drvmap[i] = -1;
2321 dev->chanmap[i] = -1;
2323 strcpy(dev->num[i], "???");
2324 init_waitqueue_head(&dev->mdm.info[i].open_wait);
2325 init_waitqueue_head(&dev->mdm.info[i].close_wait);
2327 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
2328 printk(KERN_WARNING "isdn: Could not register control devices\n");
2332 if ((isdn_tty_modem_init()) < 0) {
2333 printk(KERN_WARNING "isdn: Could not register tty devices\n");
2335 unregister_chrdev(ISDN_MAJOR, "isdn");
2338 #ifdef CONFIG_ISDN_PPP
2339 if (isdn_ppp_init() < 0) {
2340 printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
2342 unregister_chrdev(ISDN_MAJOR, "isdn");
2346 #endif /* CONFIG_ISDN_PPP */
2348 strcpy(tmprev, isdn_revision);
2349 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
2350 strcpy(tmprev, isdn_tty_revision);
2351 printk("%s/", isdn_getrev(tmprev));
2352 strcpy(tmprev, isdn_net_revision);
2353 printk("%s/", isdn_getrev(tmprev));
2354 strcpy(tmprev, isdn_ppp_revision);
2355 printk("%s/", isdn_getrev(tmprev));
2356 strcpy(tmprev, isdn_audio_revision);
2357 printk("%s/", isdn_getrev(tmprev));
2358 strcpy(tmprev, isdn_v110_revision);
2359 printk("%s", isdn_getrev(tmprev));
2362 printk(" loaded\n");
2373 static void __exit isdn_exit(void)
2375 #ifdef CONFIG_ISDN_PPP
2378 if (isdn_net_rmall() < 0) {
2379 printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
2383 unregister_chrdev(ISDN_MAJOR, "isdn");
2384 del_timer(&dev->timer);
2385 /* call vfree with interrupts enabled, else it will hang */
2387 printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
2390 module_init(isdn_init);
2391 module_exit(isdn_exit);