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/poll.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 (cmd->command == ISDN_CMD_SETL2) {
344 int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
345 unsigned long l2prot = (cmd->arg >> 8) & 255;
346 unsigned long features = (dev->drv[cmd->driver]->interface->features
347 >> ISDN_FEATURE_L2_SHIFT) &
348 ISDN_FEATURE_L2_MASK;
349 unsigned long l2_feature = (1 << l2prot);
352 case ISDN_PROTO_L2_V11096:
353 case ISDN_PROTO_L2_V11019:
354 case ISDN_PROTO_L2_V11038:
355 /* If V.110 requested, but not supported by
356 * HL-driver, set emulator-flag and change
357 * Layer-2 to transparent
359 if (!(features & l2_feature)) {
360 dev->v110emu[idx] = l2prot;
361 cmd->arg = (cmd->arg & 255) |
362 (ISDN_PROTO_L2_TRANS << 8);
364 dev->v110emu[idx] = 0;
367 return dev->drv[cmd->driver]->interface->command(cmd);
371 isdn_all_eaz(int di, int ch)
379 cmd.command = ISDN_CMD_SETEAZ;
380 cmd.parm.num[0] = '\0';
385 * Begin of a CAPI like LL<->HL interface, currently used only for
386 * supplementary service (CAPI 2.0 part III)
388 #include <linux/isdn/capicmd.h>
391 isdn_capi_rec_hl_msg(capi_msg *cm) {
396 di = (cm->adr.Controller & 0x7f) -1;
397 ch = isdn_dc2minor(di, (cm->adr.Controller>>8)& 0x7f);
398 switch(cm->Command) {
400 /* in the moment only handled in tty */
401 return(isdn_tty_capi_facility(cm));
408 isdn_status_callback(isdn_ctrl * c)
419 i = isdn_dc2minor(di, c->arg);
420 switch (c->command) {
421 case ISDN_STAT_BSENT:
424 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
426 if (isdn_net_stat_callback(i, c))
428 if (isdn_v110_stat_callback(i, c))
430 if (isdn_tty_stat_callback(i, c))
432 wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
434 case ISDN_STAT_STAVAIL:
435 dev->drv[di]->stavail += c->arg;
436 wake_up_interruptible(&dev->drv[di]->st_waitq);
439 dev->drv[di]->flags |= DRV_FLAG_RUNNING;
440 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
441 if (dev->drvmap[i] == di)
442 isdn_all_eaz(di, dev->chanmap[i]);
443 set_global_features();
446 dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
448 case ISDN_STAT_ICALL:
451 #ifdef ISDN_DEBUG_STATCALLB
452 printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
454 if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
457 cmd.command = ISDN_CMD_HANGUP;
461 /* Try to find a network-interface which will accept incoming call */
462 r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
465 /* No network-device replies.
467 * These return 0 on no match, 1 on match and
468 * 3 on eventually match, if CID is longer.
470 if (c->command == ISDN_STAT_ICALL)
471 if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return(retval);
472 #ifdef CONFIG_ISDN_DIVERSION
474 if ((retval = divert_if->stat_callback(c)))
475 return(retval); /* processed */
476 #endif /* CONFIG_ISDN_DIVERSION */
477 if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
478 /* No tty responding */
481 cmd.command = ISDN_CMD_HANGUP;
487 /* Schedule connection-setup */
491 cmd.command = ISDN_CMD_ACCEPTD;
492 for ( p = dev->netdev; p; p = p->next )
493 if ( p->local->isdn_channel == cmd.arg )
495 strcpy( cmd.parm.setup.eazmsn, p->local->msn );
502 case 2: /* For calling back, first reject incoming call ... */
503 case 3: /* Interface found, but down, reject call actively */
505 printk(KERN_INFO "isdn: Rejecting Call\n");
508 cmd.command = ISDN_CMD_HANGUP;
514 /* ... then start callback. */
518 /* Number would eventually match, if longer */
522 #ifdef ISDN_DEBUG_STATCALLB
523 printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
530 #ifdef ISDN_DEBUG_STATCALLB
531 printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
533 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
535 if (strcmp(c->parm.num, "0"))
536 isdn_net_stat_callback(i, c);
537 isdn_tty_stat_callback(i, c);
539 case ISDN_STAT_CAUSE:
540 #ifdef ISDN_DEBUG_STATCALLB
541 printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
543 printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
544 dev->drvid[di], c->arg, c->parm.num);
545 isdn_tty_stat_callback(i, c);
546 #ifdef CONFIG_ISDN_DIVERSION
548 divert_if->stat_callback(c);
549 #endif /* CONFIG_ISDN_DIVERSION */
551 case ISDN_STAT_DISPLAY:
552 #ifdef ISDN_DEBUG_STATCALLB
553 printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
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_DCONN:
564 #ifdef ISDN_DEBUG_STATCALLB
565 printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
567 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
569 /* Find any net-device, waiting for D-channel setup */
570 if (isdn_net_stat_callback(i, c))
572 isdn_v110_stat_callback(i, c);
573 /* Find any ttyI, waiting for D-channel setup */
574 if (isdn_tty_stat_callback(i, c)) {
577 cmd.command = ISDN_CMD_ACCEPTB;
585 #ifdef ISDN_DEBUG_STATCALLB
586 printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
588 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
590 dev->drv[di]->online &= ~(1 << (c->arg));
592 /* Signal hangup to network-devices */
593 if (isdn_net_stat_callback(i, c))
595 isdn_v110_stat_callback(i, c);
596 if (isdn_tty_stat_callback(i, c))
598 #ifdef CONFIG_ISDN_DIVERSION
600 divert_if->stat_callback(c);
601 #endif /* CONFIG_ISDN_DIVERSION */
604 case ISDN_STAT_BCONN:
607 #ifdef ISDN_DEBUG_STATCALLB
608 printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
610 /* Signal B-channel-connect to network-devices */
611 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
613 dev->drv[di]->online |= (1 << (c->arg));
615 if (isdn_net_stat_callback(i, c))
617 isdn_v110_stat_callback(i, c);
618 if (isdn_tty_stat_callback(i, c))
624 #ifdef ISDN_DEBUG_STATCALLB
625 printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
627 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
629 dev->drv[di]->online &= ~(1 << (c->arg));
631 #ifdef CONFIG_ISDN_X25
632 /* Signal hangup to network-devices */
633 if (isdn_net_stat_callback(i, c))
636 isdn_v110_stat_callback(i, c);
637 if (isdn_tty_stat_callback(i, c))
640 case ISDN_STAT_NODCH:
643 #ifdef ISDN_DEBUG_STATCALLB
644 printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
646 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
648 if (isdn_net_stat_callback(i, c))
650 if (isdn_tty_stat_callback(i, c))
653 case ISDN_STAT_ADDCH:
654 spin_lock_irqsave(&dev->lock, flags);
655 if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
656 spin_unlock_irqrestore(&dev->lock, flags);
659 spin_unlock_irqrestore(&dev->lock, flags);
662 case ISDN_STAT_DISCH:
663 spin_lock_irqsave(&dev->lock, flags);
664 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
665 if ((dev->drvmap[i] == di) &&
666 (dev->chanmap[i] == c->arg)) {
668 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
670 if (USG_NONE(dev->usage[i])) {
671 dev->usage[i] |= ISDN_USAGE_DISABLED;
677 spin_unlock_irqrestore(&dev->lock, flags);
680 case ISDN_STAT_UNLOAD:
681 while (dev->drv[di]->locks > 0) {
682 isdn_unlock_driver(dev->drv[di]);
684 spin_lock_irqsave(&dev->lock, flags);
685 isdn_tty_stat_callback(i, c);
686 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
687 if (dev->drvmap[i] == di) {
689 dev->chanmap[i] = -1;
690 dev->usage[i] &= ~ISDN_USAGE_DISABLED;
693 dev->channels -= dev->drv[di]->channels;
694 kfree(dev->drv[di]->rcverr);
695 kfree(dev->drv[di]->rcvcount);
696 for (i = 0; i < dev->drv[di]->channels; i++)
697 skb_queue_purge(&dev->drv[di]->rpqueue[i]);
698 kfree(dev->drv[di]->rpqueue);
699 kfree(dev->drv[di]->rcv_waitq);
702 dev->drvid[di][0] = '\0';
704 set_global_features();
705 spin_unlock_irqrestore(&dev->lock, flags);
707 case ISDN_STAT_L1ERR:
709 case CAPI_PUT_MESSAGE:
710 return(isdn_capi_rec_hl_msg(&c->parm.cmsg));
711 #ifdef CONFIG_ISDN_TTY_FAX
712 case ISDN_STAT_FAXIND:
713 isdn_tty_stat_callback(i, c);
716 #ifdef CONFIG_ISDN_AUDIO
717 case ISDN_STAT_AUDIO:
718 isdn_tty_stat_callback(i, c);
721 #ifdef CONFIG_ISDN_DIVERSION
723 case ISDN_STAT_REDIR:
725 return(divert_if->stat_callback(c));
726 #endif /* CONFIG_ISDN_DIVERSION */
734 * Get integer from char-pointer, set pointer to end of number
737 isdn_getnum(char **p)
741 while (*p[0] >= '0' && *p[0] <= '9')
742 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
749 * isdn_readbchan() tries to get data from the read-queue.
750 * It MUST be called with interrupts off.
752 * Be aware that this is not an atomic operation when sleep != 0, even though
753 * interrupts are turned off! Well, like that we are currently only called
754 * on behalf of a read system call on raw device files (which are documented
755 * to be dangerous and for for debugging purpose only). The inode semaphore
756 * takes care that this is not called for the same minor device number while
757 * we are sleeping, but access is not serialized against simultaneous read()
758 * from the corresponding ttyI device. Can other ugly events, like changes
759 * of the mapping (di,ch)<->minor, happen during the sleep? --he
762 isdn_readbchan(int di, int channel, u_char * buf, u_char * fp, int len, wait_queue_head_t *sleep)
773 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
775 interruptible_sleep_on(sleep);
779 if (len > dev->drv[di]->rcvcount[channel])
780 len = dev->drv[di]->rcvcount[channel];
784 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
786 #ifdef CONFIG_ISDN_AUDIO
787 if (ISDN_AUDIO_SKB_LOCK(skb))
789 ISDN_AUDIO_SKB_LOCK(skb) = 1;
790 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
792 unsigned long DLEmask = (1 << channel);
795 count_pull = count_put = 0;
796 while ((count_pull < skb->len) && (len > 0)) {
798 if (dev->drv[di]->DLEflag & DLEmask) {
800 dev->drv[di]->DLEflag &= ~DLEmask;
804 dev->drv[di]->DLEflag |= DLEmask;
805 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
812 if (count_pull >= skb->len)
816 /* No DLE's in buff, so simply copy it */
818 if ((count_pull = skb->len) > len) {
822 count_put = count_pull;
823 memcpy(cp, skb->data, count_put);
826 #ifdef CONFIG_ISDN_AUDIO
831 memset(fp, 0, count_put);
835 /* We got all the data in this buff.
836 * Now we can dequeue it.
840 #ifdef CONFIG_ISDN_AUDIO
841 ISDN_AUDIO_SKB_LOCK(skb) = 0;
843 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
846 /* Not yet emptied this buff, so it
847 * must stay in the queue, for further calls
848 * but we pull off the data we got until now.
850 skb_pull(skb, count_pull);
851 #ifdef CONFIG_ISDN_AUDIO
852 ISDN_AUDIO_SKB_LOCK(skb) = 0;
855 dev->drv[di]->rcvcount[channel] -= count_put;
861 * isdn_readbchan_tty() tries to get data from the read-queue.
862 * It MUST be called with interrupts off.
864 * Be aware that this is not an atomic operation when sleep != 0, even though
865 * interrupts are turned off! Well, like that we are currently only called
866 * on behalf of a read system call on raw device files (which are documented
867 * to be dangerous and for for debugging purpose only). The inode semaphore
868 * takes care that this is not called for the same minor device number while
869 * we are sleeping, but access is not serialized against simultaneous read()
870 * from the corresponding ttyI device. Can other ugly events, like changes
871 * of the mapping (di,ch)<->minor, happen during the sleep? --he
874 isdn_readbchan_tty(int di, int channel, struct tty_struct *tty, int cisco_hack)
886 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
889 len = tty_buffer_request_room(tty, dev->drv[di]->rcvcount[channel]);
895 if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
897 #ifdef CONFIG_ISDN_AUDIO
898 if (ISDN_AUDIO_SKB_LOCK(skb))
900 ISDN_AUDIO_SKB_LOCK(skb) = 1;
901 if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
903 unsigned long DLEmask = (1 << channel);
906 count_pull = count_put = 0;
907 while ((count_pull < skb->len) && (len > 0)) {
909 if (dev->drv[di]->DLEflag & DLEmask) {
911 dev->drv[di]->DLEflag &= ~DLEmask;
915 dev->drv[di]->DLEflag |= DLEmask;
916 (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
923 if (count_pull >= skb->len)
927 /* No DLE's in buff, so simply copy it */
929 if ((count_pull = skb->len) > len) {
933 count_put = count_pull;
935 tty_insert_flip_string(tty, skb->data, count_put - 1);
936 last = skb->data[count_put] - 1;
938 #ifdef CONFIG_ISDN_AUDIO
943 /* We got all the data in this buff.
944 * Now we can dequeue it.
947 tty_insert_flip_char(tty, last, 0xFF);
949 tty_insert_flip_char(tty, last, TTY_NORMAL);
950 #ifdef CONFIG_ISDN_AUDIO
951 ISDN_AUDIO_SKB_LOCK(skb) = 0;
953 skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
956 tty_insert_flip_char(tty, last, TTY_NORMAL);
957 /* Not yet emptied this buff, so it
958 * must stay in the queue, for further calls
959 * but we pull off the data we got until now.
961 skb_pull(skb, count_pull);
962 #ifdef CONFIG_ISDN_AUDIO
963 ISDN_AUDIO_SKB_LOCK(skb) = 0;
966 dev->drv[di]->rcvcount[channel] -= count_put;
973 isdn_minor2drv(int minor)
975 return (dev->drvmap[minor]);
979 isdn_minor2chan(int minor)
981 return (dev->chanmap[minor]);
987 static char istatbuf[2048];
991 sprintf(istatbuf, "idmap:\t");
992 p = istatbuf + strlen(istatbuf);
993 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
994 sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
995 p = istatbuf + strlen(istatbuf);
997 sprintf(p, "\nchmap:\t");
998 p = istatbuf + strlen(istatbuf);
999 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1000 sprintf(p, "%d ", dev->chanmap[i]);
1001 p = istatbuf + strlen(istatbuf);
1003 sprintf(p, "\ndrmap:\t");
1004 p = istatbuf + strlen(istatbuf);
1005 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1006 sprintf(p, "%d ", dev->drvmap[i]);
1007 p = istatbuf + strlen(istatbuf);
1009 sprintf(p, "\nusage:\t");
1010 p = istatbuf + strlen(istatbuf);
1011 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1012 sprintf(p, "%d ", dev->usage[i]);
1013 p = istatbuf + strlen(istatbuf);
1015 sprintf(p, "\nflags:\t");
1016 p = istatbuf + strlen(istatbuf);
1017 for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
1019 sprintf(p, "%ld ", dev->drv[i]->online);
1020 p = istatbuf + strlen(istatbuf);
1023 p = istatbuf + strlen(istatbuf);
1026 sprintf(p, "\nphone:\t");
1027 p = istatbuf + strlen(istatbuf);
1028 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1029 sprintf(p, "%s ", dev->num[i]);
1030 p = istatbuf + strlen(istatbuf);
1036 /* Module interface-code */
1039 isdn_info_update(void)
1041 infostruct *p = dev->infochain;
1045 p = (infostruct *) p->next;
1047 wake_up_interruptible(&(dev->info_waitq));
1051 isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1053 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
1061 if (minor == ISDN_MINOR_STATUS) {
1062 if (!file->private_data) {
1063 if (file->f_flags & O_NONBLOCK) {
1067 interruptible_sleep_on(&(dev->info_waitq));
1070 file->private_data = NULL;
1071 if ((len = strlen(p)) <= count) {
1072 if (copy_to_user(buf, p, len)) {
1083 if (!dev->drivers) {
1087 if (minor <= ISDN_MINOR_BMAX) {
1088 printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
1089 drvidx = isdn_minor2drv(minor);
1094 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1098 chidx = isdn_minor2chan(minor);
1099 if (!(p = kmalloc(count, GFP_KERNEL))) {
1103 len = isdn_readbchan(drvidx, chidx, p, NULL, count,
1104 &dev->drv[drvidx]->rcv_waitq[chidx]);
1106 if (copy_to_user(buf,p,len))
1112 if (minor <= ISDN_MINOR_CTRLMAX) {
1113 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1118 if (!dev->drv[drvidx]->stavail) {
1119 if (file->f_flags & O_NONBLOCK) {
1123 interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
1125 if (dev->drv[drvidx]->interface->readstat) {
1126 if (count > dev->drv[drvidx]->stavail)
1127 count = dev->drv[drvidx]->stavail;
1128 len = dev->drv[drvidx]->interface->
1129 readstat(buf, count, drvidx,
1130 isdn_minor2chan(minor));
1135 dev->drv[drvidx]->stavail -= len;
1137 dev->drv[drvidx]->stavail = 0;
1142 #ifdef CONFIG_ISDN_PPP
1143 if (minor <= ISDN_MINOR_PPPMAX) {
1144 retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
1155 isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
1157 uint minor = MINOR(file->f_dentry->d_inode->i_rdev);
1162 if (minor == ISDN_MINOR_STATUS)
1168 if (minor <= ISDN_MINOR_BMAX) {
1169 printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
1170 drvidx = isdn_minor2drv(minor);
1175 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
1179 chidx = isdn_minor2chan(minor);
1180 while (isdn_writebuf_stub(drvidx, chidx, buf, count) != count)
1181 interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
1185 if (minor <= ISDN_MINOR_CTRLMAX) {
1186 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1192 * We want to use the isdnctrl device to load the firmware
1194 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1197 if (dev->drv[drvidx]->interface->writecmd)
1198 retval = dev->drv[drvidx]->interface->
1199 writecmd(buf, count, drvidx, isdn_minor2chan(minor));
1204 #ifdef CONFIG_ISDN_PPP
1205 if (minor <= ISDN_MINOR_PPPMAX) {
1206 retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
1217 isdn_poll(struct file *file, poll_table * wait)
1219 unsigned int mask = 0;
1220 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1221 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1224 if (minor == ISDN_MINOR_STATUS) {
1225 poll_wait(file, &(dev->info_waitq), wait);
1226 /* mask = POLLOUT | POLLWRNORM; */
1227 if (file->private_data) {
1228 mask |= POLLIN | POLLRDNORM;
1232 if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
1234 /* driver deregistered while file open */
1238 poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
1239 mask = POLLOUT | POLLWRNORM;
1240 if (dev->drv[drvidx]->stavail) {
1241 mask |= POLLIN | POLLRDNORM;
1245 #ifdef CONFIG_ISDN_PPP
1246 if (minor <= ISDN_MINOR_PPPMAX) {
1247 mask = isdn_ppp_poll(file, wait);
1259 isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1261 uint minor = MINOR(inode->i_rdev);
1272 isdn_ioctl_struct iocts;
1273 isdn_net_ioctl_phone phone;
1274 isdn_net_ioctl_cfg cfg;
1276 void __user *argp = (void __user *)arg;
1278 #define name iocpar.name
1279 #define bname iocpar.bname
1280 #define iocts iocpar.iocts
1281 #define phone iocpar.phone
1282 #define cfg iocpar.cfg
1284 if (minor == ISDN_MINOR_STATUS) {
1292 ulong __user *p = argp;
1294 if (!access_ok(VERIFY_WRITE, p,
1295 sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
1297 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1298 put_user(dev->ibytes[i], p++);
1299 put_user(dev->obytes[i], p++);
1305 #ifdef CONFIG_NETDEVICES
1307 /* Get peer phone number of a connected
1308 * isdn network interface */
1310 if (copy_from_user(&phone, argp, sizeof(phone)))
1312 return isdn_net_getpeer(&phone, argp);
1322 if (minor <= ISDN_MINOR_BMAX) {
1323 drvidx = isdn_minor2drv(minor);
1326 chidx = isdn_minor2chan(minor);
1327 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1331 if (minor <= ISDN_MINOR_CTRLMAX) {
1333 * isdn net devices manage lots of configuration variables as linked lists.
1334 * Those lists must only be manipulated from user space. Some of the ioctl's
1335 * service routines access user space and are not atomic. Therefor, ioctl's
1336 * manipulating the lists and ioctl's sleeping while accessing the lists
1337 * are serialized by means of a semaphore.
1341 printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
1344 printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
1346 #ifdef CONFIG_NETDEVICES
1348 /* Add a network-interface */
1350 if (copy_from_user(name, argp, sizeof(name)))
1356 ret = down_interruptible(&dev->sem);
1357 if( ret ) return ret;
1358 if ((s = isdn_net_new(s, NULL))) {
1359 if (copy_to_user(argp, s, strlen(s) + 1)){
1369 /* Add a slave to a network-interface */
1371 if (copy_from_user(bname, argp, sizeof(bname) - 1))
1375 ret = down_interruptible(&dev->sem);
1376 if( ret ) return ret;
1377 if ((s = isdn_net_newslave(bname))) {
1378 if (copy_to_user(argp, s, strlen(s) + 1)){
1388 /* Delete a network-interface */
1390 if (copy_from_user(name, argp, sizeof(name)))
1392 ret = down_interruptible(&dev->sem);
1393 if( ret ) return ret;
1394 ret = isdn_net_rm(name);
1400 /* Set configurable parameters of a network-interface */
1402 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1404 return isdn_net_setcfg(&cfg);
1408 /* Get configurable parameters of a network-interface */
1410 if (copy_from_user(&cfg, argp, sizeof(cfg)))
1412 if (!(ret = isdn_net_getcfg(&cfg))) {
1413 if (copy_to_user(argp, &cfg, sizeof(cfg)))
1420 /* Add a phone-number to a network-interface */
1422 if (copy_from_user(&phone, argp, sizeof(phone)))
1424 ret = down_interruptible(&dev->sem);
1425 if( ret ) return ret;
1426 ret = isdn_net_addphone(&phone);
1432 /* Get list of phone-numbers of a network-interface */
1434 if (copy_from_user(&phone, argp, sizeof(phone)))
1436 ret = down_interruptible(&dev->sem);
1437 if( ret ) return ret;
1438 ret = isdn_net_getphones(&phone, argp);
1444 /* Delete a phone-number of a network-interface */
1446 if (copy_from_user(&phone, argp, sizeof(phone)))
1448 ret = down_interruptible(&dev->sem);
1449 if( ret ) return ret;
1450 ret = isdn_net_delphone(&phone);
1456 /* Force dialing of a network-interface */
1458 if (copy_from_user(name, argp, sizeof(name)))
1460 return isdn_net_force_dial(name);
1463 #ifdef CONFIG_ISDN_PPP
1467 if (copy_from_user(name, argp, sizeof(name)))
1469 return isdn_ppp_dial_slave(name);
1473 if (copy_from_user(name, argp, sizeof(name)))
1475 return isdn_ppp_hangup_slave(name);
1478 /* Force hangup of a network-interface */
1481 if (copy_from_user(name, argp, sizeof(name)))
1483 return isdn_net_force_hangup(name);
1485 #endif /* CONFIG_NETDEVICES */
1487 dev->net_verbose = arg;
1488 printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
1492 dev->global_flags |= ISDN_GLOBAL_STOPPED;
1494 dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
1495 printk(KERN_INFO "isdn: Global Mode %s\n",
1496 (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
1503 if (copy_from_user(&iocts, argp,
1504 sizeof(isdn_ioctl_struct)))
1506 if (strlen(iocts.drvid)) {
1507 if ((p = strchr(iocts.drvid, ',')))
1510 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1511 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1520 dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
1522 dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
1525 dev->profd = current;
1529 /* Get all Modem-Profiles */
1531 char __user *p = argp;
1534 if (!access_ok(VERIFY_WRITE, argp,
1535 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1536 * ISDN_MAX_CHANNELS))
1539 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1540 if (copy_to_user(p, dev->mdm.info[i].emu.profile,
1543 p += ISDN_MODEM_NUMREG;
1544 if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
1547 if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
1551 return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
1556 /* Set all Modem-Profiles */
1558 char __user *p = argp;
1561 if (!access_ok(VERIFY_READ, argp,
1562 (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
1563 * ISDN_MAX_CHANNELS))
1566 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1567 if (copy_from_user(dev->mdm.info[i].emu.profile, p,
1570 p += ISDN_MODEM_NUMREG;
1571 if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
1574 if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
1584 /* Set/Get MSN->EAZ-Mapping for a driver */
1587 if (copy_from_user(&iocts, argp,
1588 sizeof(isdn_ioctl_struct)))
1590 if (strlen(iocts.drvid)) {
1592 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1593 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1601 if (cmd == IIOCSETMAP) {
1604 p = (char __user *) iocts.arg;
1610 if (!access_ok(VERIFY_READ, p, 1))
1612 get_user(bname[j], p++);
1619 strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
1625 if (j >= ISDN_MSNLEN)
1632 p = (char __user *) iocts.arg;
1633 for (i = 0; i < 10; i++) {
1634 sprintf(bname, "%s%s",
1635 strlen(dev->drv[drvidx]->msn2eaz[i]) ?
1636 dev->drv[drvidx]->msn2eaz[i] : "_",
1637 (i < 9) ? "," : "\0");
1638 if (copy_to_user(p, bname, strlen(bname) + 1))
1648 if (copy_to_user(argp, &dev, sizeof(ulong)))
1655 if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
1656 cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
1662 if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
1664 if (strlen(iocts.drvid)) {
1665 if ((p = strchr(iocts.drvid, ',')))
1668 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
1669 if (!(strcmp(dev->drvid[i], iocts.drvid))) {
1677 if (!access_ok(VERIFY_WRITE, argp,
1678 sizeof(isdn_ioctl_struct)))
1681 c.command = ISDN_CMD_IOCTL;
1683 memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
1684 ret = isdn_command(&c);
1685 memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
1686 if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
1693 #ifdef CONFIG_ISDN_PPP
1694 if (minor <= ISDN_MINOR_PPPMAX)
1695 return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
1707 * Open the device code.
1710 isdn_open(struct inode *ino, struct file *filep)
1712 uint minor = MINOR(ino->i_rdev);
1715 int retval = -ENODEV;
1718 if (minor == ISDN_MINOR_STATUS) {
1721 if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
1722 p->next = (char *) dev->infochain;
1723 p->private = (char *) &(filep->private_data);
1725 /* At opening we allow a single update */
1726 filep->private_data = (char *) 1;
1736 if (minor <= ISDN_MINOR_BMAX) {
1737 printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
1738 drvidx = isdn_minor2drv(minor);
1741 chidx = isdn_minor2chan(minor);
1742 if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
1744 if (!(dev->drv[drvidx]->online & (1 << chidx)))
1746 isdn_lock_drivers();
1750 if (minor <= ISDN_MINOR_CTRLMAX) {
1751 drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1754 isdn_lock_drivers();
1758 #ifdef CONFIG_ISDN_PPP
1759 if (minor <= ISDN_MINOR_PPPMAX) {
1760 retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
1762 isdn_lock_drivers();
1767 nonseekable_open(ino, filep);
1772 isdn_close(struct inode *ino, struct file *filep)
1774 uint minor = MINOR(ino->i_rdev);
1777 if (minor == ISDN_MINOR_STATUS) {
1778 infostruct *p = dev->infochain;
1779 infostruct *q = NULL;
1782 if (p->private == (char *) &(filep->private_data)) {
1786 dev->infochain = (infostruct *) (p->next);
1791 p = (infostruct *) (p->next);
1793 printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
1796 isdn_unlock_drivers();
1797 if (minor <= ISDN_MINOR_BMAX)
1799 if (minor <= ISDN_MINOR_CTRLMAX) {
1800 if (dev->profd == current)
1804 #ifdef CONFIG_ISDN_PPP
1805 if (minor <= ISDN_MINOR_PPPMAX)
1806 isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
1814 static struct file_operations isdn_fops =
1816 .owner = THIS_MODULE,
1817 .llseek = no_llseek,
1819 .write = isdn_write,
1821 .ioctl = isdn_ioctl,
1823 .release = isdn_close,
1827 isdn_map_eaz2msn(char *msn, int di)
1829 isdn_driver_t *this = dev->drv[di];
1832 if (strlen(msn) == 1) {
1834 if ((i >= 0) && (i <= 9))
1835 if (strlen(this->msn2eaz[i]))
1836 return (this->msn2eaz[i]);
1842 * Find an unused ISDN-channel, whose feature-flags match the
1843 * given L2- and L3-protocols.
1845 #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
1848 * This function must be called with holding the dev->lock.
1851 isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
1852 ,int pre_chan, char *msn)
1858 features = ((1 << l2_proto) | (0x10000 << l3_proto));
1859 vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
1860 ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
1861 /* If Layer-2 protocol is V.110, accept drivers with
1862 * transparent feature even if these don't support V.110
1863 * because we can emulate this in linklevel.
1865 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1866 if (USG_NONE(dev->usage[i]) &&
1867 (dev->drvmap[i] != -1)) {
1868 int d = dev->drvmap[i];
1869 if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
1870 ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
1872 if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
1874 if (dev->usage[i] & ISDN_USAGE_DISABLED)
1875 continue; /* usage not allowed */
1876 if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
1877 if (((dev->drv[d]->interface->features & features) == features) ||
1878 (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
1879 (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
1880 if ((pre_dev < 0) || (pre_chan < 0)) {
1881 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1882 dev->usage[i] |= usage;
1886 if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
1887 dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
1888 dev->usage[i] |= usage;
1900 * Set state of ISDN-channel to 'unused'
1903 isdn_free_channel(int di, int ch, int usage)
1907 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1908 if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
1909 (dev->drvmap[i] == di) &&
1910 (dev->chanmap[i] == ch)) {
1911 dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
1912 strcpy(dev->num[i], "???");
1915 // 20.10.99 JIM, try to reinitialize v110 !
1916 dev->v110emu[i] = 0;
1917 atomic_set(&(dev->v110use[i]), 0);
1918 isdn_v110_close(dev->v110[i]);
1919 dev->v110[i] = NULL;
1920 // 20.10.99 JIM, try to reinitialize v110 !
1922 skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
1927 * Cancel Exclusive-Flag for ISDN-channel
1930 isdn_unexclusive_channel(int di, int ch)
1934 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
1935 if ((dev->drvmap[i] == di) &&
1936 (dev->chanmap[i] == ch)) {
1937 dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
1944 * writebuf replacement for SKB_ABLE drivers
1947 isdn_writebuf_stub(int drvidx, int chan, const u_char __user * buf, int len)
1950 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1951 struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
1955 skb_reserve(skb, hl);
1956 copy_from_user(skb_put(skb, len), buf, len);
1957 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
1961 dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
1966 * Return: length of data on success, -ERRcode on failure.
1969 isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
1972 struct sk_buff *nskb = NULL;
1973 int v110_ret = skb->len;
1974 int idx = isdn_dc2minor(drvidx, chan);
1976 if (dev->v110[idx]) {
1977 atomic_inc(&dev->v110use[idx]);
1978 nskb = isdn_v110_encode(dev->v110[idx], skb);
1979 atomic_dec(&dev->v110use[idx]);
1982 v110_ret = *((int *)nskb->data);
1983 skb_pull(nskb, sizeof(int));
1985 dev_kfree_skb(nskb);
1988 /* V.110 must always be acknowledged */
1990 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
1992 int hl = dev->drv[drvidx]->interface->hl_hdrlen;
1994 if( skb_headroom(skb) < hl ){
1996 * This should only occur when new HL driver with
1997 * increased hl_hdrlen was loaded after netdevice
1998 * was created and connected to the new driver.
2000 * The V.110 branch (re-allocates on its own) does
2003 struct sk_buff * skb_tmp;
2005 skb_tmp = skb_realloc_headroom(skb, hl);
2006 printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
2007 if (!skb_tmp) return -ENOMEM; /* 0 better? */
2008 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
2012 dev_kfree_skb(skb_tmp);
2015 ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
2019 dev->obytes[idx] += ret;
2020 if (dev->v110[idx]) {
2021 atomic_inc(&dev->v110use[idx]);
2022 dev->v110[idx]->skbuser++;
2023 atomic_dec(&dev->v110use[idx]);
2024 /* For V.110 return unencoded data length */
2026 /* if the complete frame was send we free the skb;
2027 if not upper function will requeue the skb */
2028 if (ret == skb->len)
2033 dev_kfree_skb(nskb);
2038 isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
2042 init_waitqueue_head(&d->st_waitq);
2043 if (d->flags & DRV_FLAG_RUNNING)
2045 if (n < 1) return 0;
2047 m = (adding) ? d->channels + n : n;
2049 if (dev->channels + n > ISDN_MAX_CHANNELS) {
2050 printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
2055 if ((adding) && (d->rcverr))
2057 if (!(d->rcverr = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
2058 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
2061 memset((char *) d->rcverr, 0, sizeof(int) * m);
2063 if ((adding) && (d->rcvcount))
2065 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) {
2066 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
2071 memset((char *) d->rcvcount, 0, sizeof(int) * m);
2073 if ((adding) && (d->rpqueue)) {
2074 for (j = 0; j < d->channels; j++)
2075 skb_queue_purge(&d->rpqueue[j]);
2078 if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
2079 printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
2086 for (j = 0; j < m; j++) {
2087 skb_queue_head_init(&d->rpqueue[j]);
2090 if ((adding) && (d->rcv_waitq))
2091 kfree(d->rcv_waitq);
2092 d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
2093 if (!d->rcv_waitq) {
2094 printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
2102 d->snd_waitq = d->rcv_waitq + m;
2103 for (j = 0; j < m; j++) {
2104 init_waitqueue_head(&d->rcv_waitq[j]);
2105 init_waitqueue_head(&d->snd_waitq[j]);
2109 for (j = d->channels; j < m; j++)
2110 for (k = 0; k < ISDN_MAX_CHANNELS; k++)
2111 if (dev->chanmap[k] < 0) {
2112 dev->chanmap[k] = j;
2113 dev->drvmap[k] = drvidx;
2121 * Low-level-driver registration
2125 set_global_features(void)
2129 dev->global_features = 0;
2130 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
2131 if (!dev->drv[drvidx])
2133 if (dev->drv[drvidx]->interface)
2134 dev->global_features |= dev->drv[drvidx]->interface->features;
2138 #ifdef CONFIG_ISDN_DIVERSION
2140 static char *map_drvname(int di)
2142 if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
2144 return(dev->drvid[di]); /* driver name */
2147 static int map_namedrv(char *id)
2150 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2151 { if (!strcmp(dev->drvid[i],id))
2157 int DIVERT_REG_NAME(isdn_divert_if *i_div)
2159 if (i_div->if_magic != DIVERT_IF_MAGIC)
2160 return(DIVERT_VER_ERR);
2163 case DIVERT_CMD_REL:
2164 if (divert_if != i_div)
2165 return(DIVERT_REL_ERR);
2166 divert_if = NULL; /* free interface */
2167 return(DIVERT_NO_ERR);
2169 case DIVERT_CMD_REG:
2171 return(DIVERT_REG_ERR);
2172 i_div->ll_cmd = isdn_command; /* set command function */
2173 i_div->drv_to_name = map_drvname;
2174 i_div->name_to_drv = map_namedrv;
2175 divert_if = i_div; /* remember interface */
2176 return(DIVERT_NO_ERR);
2179 return(DIVERT_CMD_ERR);
2181 } /* DIVERT_REG_NAME */
2183 EXPORT_SYMBOL(DIVERT_REG_NAME);
2185 #endif /* CONFIG_ISDN_DIVERSION */
2188 EXPORT_SYMBOL(register_isdn);
2189 #ifdef CONFIG_ISDN_PPP
2190 EXPORT_SYMBOL(isdn_ppp_register_compressor);
2191 EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
2195 register_isdn(isdn_if * i)
2202 if (dev->drivers >= ISDN_MAX_DRIVERS) {
2203 printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
2207 if (!i->writebuf_skb) {
2208 printk(KERN_WARNING "register_isdn: No write routine given.\n");
2211 if (!(d = kmalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
2212 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
2215 memset((char *) d, 0, sizeof(isdn_driver_t));
2217 d->maxbufsize = i->maxbufsize;
2220 d->flags = DRV_FLAG_LOADED;
2224 spin_lock_irqsave(&dev->lock, flags);
2225 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2226 if (!dev->drv[drvidx])
2228 if (isdn_add_channels(d, drvidx, i->channels, 0)) {
2229 spin_unlock_irqrestore(&dev->lock, flags);
2233 i->channels = drvidx;
2234 i->rcvcallb_skb = isdn_receive_skb_callback;
2235 i->statcallb = isdn_status_callback;
2237 sprintf(i->id, "line%d", drvidx);
2238 for (j = 0; j < drvidx; j++)
2239 if (!strcmp(i->id, dev->drvid[j]))
2240 sprintf(i->id, "line%d", drvidx);
2241 dev->drv[drvidx] = d;
2242 strcpy(dev->drvid[drvidx], i->id);
2245 set_global_features();
2246 spin_unlock_irqrestore(&dev->lock, flags);
2251 *****************************************************************************
2252 * And now the modules code.
2253 *****************************************************************************
2257 isdn_getrev(const char *revision)
2262 if ((p = strchr(revision, ':'))) {
2264 p = strchr(rev, '$');
2272 * Allocate and initialize all data, register modem-devices
2274 static int __init isdn_init(void)
2279 if (!(dev = (isdn_dev *) vmalloc(sizeof(isdn_dev)))) {
2280 printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
2283 memset((char *) dev, 0, sizeof(isdn_dev));
2284 init_timer(&dev->timer);
2285 dev->timer.function = isdn_timer_funct;
2286 spin_lock_init(&dev->lock);
2287 spin_lock_init(&dev->timerlock);
2289 dev->owner = THIS_MODULE;
2291 init_MUTEX(&dev->sem);
2292 init_waitqueue_head(&dev->info_waitq);
2293 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2294 dev->drvmap[i] = -1;
2295 dev->chanmap[i] = -1;
2297 strcpy(dev->num[i], "???");
2298 init_waitqueue_head(&dev->mdm.info[i].open_wait);
2299 init_waitqueue_head(&dev->mdm.info[i].close_wait);
2301 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
2302 printk(KERN_WARNING "isdn: Could not register control devices\n");
2306 if ((isdn_tty_modem_init()) < 0) {
2307 printk(KERN_WARNING "isdn: Could not register tty devices\n");
2309 unregister_chrdev(ISDN_MAJOR, "isdn");
2312 #ifdef CONFIG_ISDN_PPP
2313 if (isdn_ppp_init() < 0) {
2314 printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
2316 unregister_chrdev(ISDN_MAJOR, "isdn");
2320 #endif /* CONFIG_ISDN_PPP */
2322 strcpy(tmprev, isdn_revision);
2323 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
2324 strcpy(tmprev, isdn_tty_revision);
2325 printk("%s/", isdn_getrev(tmprev));
2326 strcpy(tmprev, isdn_net_revision);
2327 printk("%s/", isdn_getrev(tmprev));
2328 strcpy(tmprev, isdn_ppp_revision);
2329 printk("%s/", isdn_getrev(tmprev));
2330 strcpy(tmprev, isdn_audio_revision);
2331 printk("%s/", isdn_getrev(tmprev));
2332 strcpy(tmprev, isdn_v110_revision);
2333 printk("%s", isdn_getrev(tmprev));
2336 printk(" loaded\n");
2347 static void __exit isdn_exit(void)
2349 #ifdef CONFIG_ISDN_PPP
2352 if (isdn_net_rmall() < 0) {
2353 printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
2357 unregister_chrdev(ISDN_MAJOR, "isdn");
2358 del_timer(&dev->timer);
2359 /* call vfree with interrupts enabled, else it will hang */
2361 printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
2364 module_init(isdn_init);
2365 module_exit(isdn_exit);