1 /* $Id: isdn_net.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
3 * Linux ISDN subsystem, network interfaces and related functions (linklevel).
5 * Copyright 1994-1998 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by 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.
12 * Data Over Voice (DOV) support added - Guy Ellis 23-Mar-02
14 * Outgoing calls - looks for a 'V' in first char of dialed number
15 * Incoming calls - checks first character of eaz as follows:
16 * Numeric - accept DATA only - original functionality
17 * 'V' - accept VOICE (DOV) only
18 * 'B' - accept BOTH DATA and DOV types
20 * Jan 2001: fix CISCO HDLC Bjoern A. Zeeb <i4l@zabbadoz.net>
21 * for info on the protocol, see
22 * http://i4l.zabbadoz.net/i4l/cisco-hdlc.txt
25 #include <linux/isdn.h>
28 #include <net/pkt_sched.h>
29 #include <linux/inetdevice.h>
30 #include "isdn_common.h"
32 #ifdef CONFIG_ISDN_PPP
35 #ifdef CONFIG_ISDN_X25
36 #include <linux/concap.h>
37 #include "isdn_concap.h"
42 * Outline of new tbusy handling:
44 * Old method, roughly spoken, consisted of setting tbusy when entering
45 * isdn_net_start_xmit() and at several other locations and clearing
46 * it from isdn_net_start_xmit() thread when sending was successful.
48 * With 2.3.x multithreaded network core, to prevent problems, tbusy should
49 * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
50 * condition is detected. Other threads (in particular isdn_net_stat_callb())
51 * are only allowed to clear tbusy.
58 * Most of the changes were pretty obvious and basically done by HE already.
60 * One problem of the isdn net device code is that is uses struct net_device
61 * for masters and slaves. However, only master interface are registered to
62 * the network layer, and therefore, it only makes sense to call netif_*
69 * Find out if the netdevice has been ifup-ed yet.
70 * For slaves, look at the corresponding master.
72 static __inline__ int isdn_net_device_started(isdn_net_dev *n)
74 isdn_net_local *lp = n->local;
75 struct net_device *dev;
81 return netif_running(dev);
85 * wake up the network -> net_device queue.
86 * For slaves, wake the corresponding master interface.
88 static __inline__ void isdn_net_device_wake_queue(isdn_net_local *lp)
91 netif_wake_queue(lp->master);
93 netif_wake_queue(lp->netdev->dev);
97 * stop the network -> net_device queue.
98 * For slaves, stop the corresponding master interface.
100 static __inline__ void isdn_net_device_stop_queue(isdn_net_local *lp)
103 netif_stop_queue(lp->master);
105 netif_stop_queue(lp->netdev->dev);
109 * find out if the net_device which this lp belongs to (lp can be
110 * master or slave) is busy. It's busy iff all (master and slave)
113 static __inline__ int isdn_net_device_busy(isdn_net_local *lp)
119 if (!isdn_net_lp_busy(lp))
123 nd = ISDN_MASTER_PRIV(lp)->netdev;
127 spin_lock_irqsave(&nd->queue_lock, flags);
130 if (!isdn_net_lp_busy(nlp)) {
131 spin_unlock_irqrestore(&nd->queue_lock, flags);
136 spin_unlock_irqrestore(&nd->queue_lock, flags);
140 static __inline__ void isdn_net_inc_frame_cnt(isdn_net_local *lp)
142 atomic_inc(&lp->frame_cnt);
143 if (isdn_net_device_busy(lp))
144 isdn_net_device_stop_queue(lp);
147 static __inline__ void isdn_net_dec_frame_cnt(isdn_net_local *lp)
149 atomic_dec(&lp->frame_cnt);
151 if (!(isdn_net_device_busy(lp))) {
152 if (!skb_queue_empty(&lp->super_tx_queue)) {
153 schedule_work(&lp->tqueue);
155 isdn_net_device_wake_queue(lp);
160 static __inline__ void isdn_net_zero_frame_cnt(isdn_net_local *lp)
162 atomic_set(&lp->frame_cnt, 0);
165 /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
167 * For 2.3.x we push it up to 20 secs, because call establishment
168 * (in particular callback) may take such a long time, and we
169 * don't want confusing messages in the log. However, there is a slight
170 * possibility that this large timeout will break other things like MPPP,
171 * which might rely on the tx timeout. If so, we'll find out this way...
174 #define ISDN_NET_TX_TIMEOUT (20*HZ)
178 static int isdn_net_force_dial_lp(isdn_net_local *);
179 static int isdn_net_start_xmit(struct sk_buff *, struct net_device *);
181 static void isdn_net_ciscohdlck_connected(isdn_net_local *lp);
182 static void isdn_net_ciscohdlck_disconnected(isdn_net_local *lp);
184 char *isdn_net_revision = "$Revision: 1.1.2.2 $";
187 * Code for raw-networking over ISDN
191 isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason)
195 u_short proto = ntohs(skb->protocol);
197 printk(KERN_DEBUG "isdn_net: %s: %s, signalling dst_link_failure %s\n",
199 (reason != NULL) ? reason : "unknown",
200 (proto != ETH_P_IP) ? "Protocol != ETH_P_IP" : "");
202 dst_link_failure(skb);
204 else { /* dial not triggered by rawIP packet */
205 printk(KERN_DEBUG "isdn_net: %s: %s\n",
207 (reason != NULL) ? reason : "reason unknown");
212 isdn_net_reset(struct net_device *dev)
214 #ifdef CONFIG_ISDN_X25
215 struct concap_device_ops * dops =
216 ((isdn_net_local *) netdev_priv(dev))->dops;
217 struct concap_proto * cprot =
218 ((isdn_net_local *) netdev_priv(dev))->netdev->cprot;
220 #ifdef CONFIG_ISDN_X25
221 if( cprot && cprot -> pops && dops )
222 cprot -> pops -> restart ( cprot, dev, dops );
226 /* Open/initialize the board. */
228 isdn_net_open(struct net_device *dev)
231 struct net_device *p;
232 struct in_device *in_dev;
234 /* moved here from isdn_net_reset, because only the master has an
235 interface associated which is supposed to be started. BTW:
236 we need to call netif_start_queue, not netif_wake_queue here */
237 netif_start_queue(dev);
240 /* Fill in the MAC-level header (not needed, but for compatibility... */
241 for (i = 0; i < ETH_ALEN - sizeof(u32); i++)
242 dev->dev_addr[i] = 0xfc;
243 if ((in_dev = dev->ip_ptr) != NULL) {
245 * Any address will do - we take the first
247 struct in_ifaddr *ifa = in_dev->ifa_list;
249 memcpy(dev->dev_addr+2, &ifa->ifa_local, 4);
252 /* If this interface has slaves, start them also */
253 p = MASTER_TO_SLAVE(dev);
257 p = MASTER_TO_SLAVE(p);
265 * Assign an ISDN-channel to a net-interface
268 isdn_net_bind_channel(isdn_net_local * lp, int idx)
270 lp->flags |= ISDN_NET_CONNECTED;
271 lp->isdn_device = dev->drvmap[idx];
272 lp->isdn_channel = dev->chanmap[idx];
273 dev->rx_netdev[idx] = lp->netdev;
274 dev->st_netdev[idx] = lp->netdev;
278 * unbind a net-interface (resets interface after an error)
281 isdn_net_unbind_channel(isdn_net_local * lp)
283 skb_queue_purge(&lp->super_tx_queue);
285 if (!lp->master) { /* reset only master device */
286 /* Moral equivalent of dev_purge_queues():
287 BEWARE! This chunk of code cannot be called from hardware
288 interrupt handler. I hope it is true. --ANK
290 qdisc_reset_all_tx(lp->netdev->dev);
293 dev->rx_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
294 dev->st_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
295 isdn_free_channel(lp->isdn_device, lp->isdn_channel, ISDN_USAGE_NET);
296 lp->flags &= ~ISDN_NET_CONNECTED;
297 lp->isdn_device = -1;
298 lp->isdn_channel = -1;
302 * Perform auto-hangup and cps-calculation for net-interfaces.
305 * Increment idle-counter (this counter is reset on any incoming or
306 * outgoing packet), if counter exceeds configured limit either do a
307 * hangup immediately or - if configured - wait until just before the next
310 * cps-calculation (needed for dynamic channel-bundling):
311 * Since this function is called every second, simply reset the
312 * byte-counter of the interface after copying it to the cps-variable.
314 static unsigned long last_jiffies = -HZ;
317 isdn_net_autohup(void)
319 isdn_net_dev *p = dev->netdev;
324 isdn_net_local *l = p->local;
325 if (jiffies == last_jiffies)
326 l->cps = l->transcount;
328 l->cps = (l->transcount * HZ) / (jiffies - last_jiffies);
330 if (dev->net_verbose > 3)
331 printk(KERN_DEBUG "%s: %d bogocps\n", p->dev->name, l->cps);
332 if ((l->flags & ISDN_NET_CONNECTED) && (!l->dialstate)) {
336 * if there is some dialmode where timeout-hangup
337 * should _not_ be done, check for that here
340 (l->huptimer > l->onhtime))
342 if (l->hupflags & ISDN_MANCHARGE &&
343 l->hupflags & ISDN_CHARGEHUP) {
344 while (time_after(jiffies, l->chargetime + l->chargeint))
345 l->chargetime += l->chargeint;
346 if (time_after(jiffies, l->chargetime + l->chargeint - 2 * HZ))
347 if (l->outgoing || l->hupflags & ISDN_INHUP)
348 isdn_net_hangup(p->dev);
349 } else if (l->outgoing) {
350 if (l->hupflags & ISDN_CHARGEHUP) {
351 if (l->hupflags & ISDN_WAITCHARGE) {
352 printk(KERN_DEBUG "isdn_net: Hupflags of %s are %X\n",
353 p->dev->name, l->hupflags);
354 isdn_net_hangup(p->dev);
355 } else if (time_after(jiffies, l->chargetime + l->chargeint)) {
357 "isdn_net: %s: chtime = %lu, chint = %d\n",
358 p->dev->name, l->chargetime, l->chargeint);
359 isdn_net_hangup(p->dev);
362 isdn_net_hangup(p->dev);
363 } else if (l->hupflags & ISDN_INHUP)
364 isdn_net_hangup(p->dev);
367 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*l) == ISDN_NET_DM_OFF)) {
368 isdn_net_hangup(p->dev);
372 p = (isdn_net_dev *) p->next;
374 last_jiffies = jiffies;
375 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, anymore);
378 static void isdn_net_lp_disconnected(isdn_net_local *lp)
380 isdn_net_rm_from_bundle(lp);
384 * Handle status-messages from ISDN-interfacecard.
385 * This function is called from within the main-status-dispatcher
386 * isdn_status_callback, which itself is called from the low-level driver.
387 * Return: 1 = Event handled, 0 = not for us or unknown Event.
390 isdn_net_stat_callback(int idx, isdn_ctrl *c)
392 isdn_net_dev *p = dev->st_netdev[idx];
393 int cmd = c->command;
396 isdn_net_local *lp = p->local;
397 #ifdef CONFIG_ISDN_X25
398 struct concap_proto *cprot = lp->netdev->cprot;
399 struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
402 case ISDN_STAT_BSENT:
403 /* A packet has successfully been sent out */
404 if ((lp->flags & ISDN_NET_CONNECTED) &&
406 isdn_net_dec_frame_cnt(lp);
407 lp->stats.tx_packets++;
408 lp->stats.tx_bytes += c->parm.length;
411 case ISDN_STAT_DCONN:
412 /* D-Channel is up */
413 switch (lp->dialstate) {
425 /* Either D-Channel-hangup or error during dialout */
426 #ifdef CONFIG_ISDN_X25
427 /* If we are not connencted then dialing had
428 failed. If there are generic encap protocol
429 receiver routines signal the closure of
432 if( !(lp->flags & ISDN_NET_CONNECTED)
433 && pops && pops -> disconn_ind )
434 pops -> disconn_ind(cprot);
435 #endif /* CONFIG_ISDN_X25 */
436 if ((!lp->dialstate) && (lp->flags & ISDN_NET_CONNECTED)) {
437 if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
438 isdn_net_ciscohdlck_disconnected(lp);
439 #ifdef CONFIG_ISDN_PPP
440 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
443 isdn_net_lp_disconnected(lp);
444 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
445 printk(KERN_INFO "%s: remote hangup\n", p->dev->name);
446 printk(KERN_INFO "%s: Chargesum is %d\n", p->dev->name,
448 isdn_net_unbind_channel(lp);
452 #ifdef CONFIG_ISDN_X25
454 /* B-Channel-hangup */
455 /* try if there are generic encap protocol
456 receiver routines and signal the closure of
458 if( pops && pops -> disconn_ind ){
459 pops -> disconn_ind(cprot);
463 #endif /* CONFIG_ISDN_X25 */
464 case ISDN_STAT_BCONN:
465 /* B-Channel is up */
466 isdn_net_zero_frame_cnt(lp);
467 switch (lp->dialstate) {
475 if (lp->dialstate <= 6) {
476 dev->usage[idx] |= ISDN_USAGE_OUTGOING;
479 dev->rx_netdev[idx] = p;
481 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 1);
482 if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
483 isdn_net_ciscohdlck_connected(lp);
484 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP) {
485 if (lp->master) { /* is lp a slave? */
486 isdn_net_dev *nd = ISDN_MASTER_PRIV(lp)->netdev;
487 isdn_net_add_to_bundle(nd, lp);
490 printk(KERN_INFO "isdn_net: %s connected\n", p->dev->name);
491 /* If first Chargeinfo comes before B-Channel connect,
492 * we correct the timestamp here.
494 lp->chargetime = jiffies;
496 /* reset dial-timeout */
498 lp->dialwait_timer = 0;
500 #ifdef CONFIG_ISDN_PPP
501 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
502 isdn_ppp_wakeup_daemon(lp);
504 #ifdef CONFIG_ISDN_X25
505 /* try if there are generic concap receiver routines */
507 if( pops->connect_ind)
508 pops->connect_ind(cprot);
509 #endif /* CONFIG_ISDN_X25 */
510 /* ppp needs to do negotiations first */
511 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
512 isdn_net_device_wake_queue(lp);
516 case ISDN_STAT_NODCH:
517 /* No D-Channel avail. */
518 if (lp->dialstate == 4) {
524 /* Charge-info from TelCo. Calculate interval between
525 * charge-infos and set timestamp for last info for
526 * usage by isdn_net_autohup()
529 if (lp->hupflags & ISDN_HAVECHARGE) {
530 lp->hupflags &= ~ISDN_WAITCHARGE;
531 lp->chargeint = jiffies - lp->chargetime - (2 * HZ);
533 if (lp->hupflags & ISDN_WAITCHARGE)
534 lp->hupflags |= ISDN_HAVECHARGE;
535 lp->chargetime = jiffies;
536 printk(KERN_DEBUG "isdn_net: Got CINF chargetime of %s now %lu\n",
537 p->dev->name, lp->chargetime);
545 * Perform dialout for net-interfaces and timeout-handling for
546 * D-Channel-up and B-Channel-up Messages.
547 * This function is initially called from within isdn_net_start_xmit() or
548 * or isdn_net_find_icall() after initializing the dialstate for an
549 * interface. If further calls are needed, the function schedules itself
550 * for a timer-callback via isdn_timer_function().
551 * The dialstate is also affected by incoming status-messages from
552 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
557 isdn_net_dev *p = dev->netdev;
561 u_char *phone_number;
564 isdn_net_local *lp = p->local;
566 #ifdef ISDN_DEBUG_NET_DIAL
568 printk(KERN_DEBUG "%s: dialstate=%d\n", p->dev->name, lp->dialstate);
570 switch (lp->dialstate) {
572 /* Nothing to do for this interface */
575 /* Initiate dialout. Set phone-number-pointer to first number
578 lp->dial = lp->phone[1];
580 printk(KERN_WARNING "%s: phone number deleted?\n",
582 isdn_net_hangup(p->dev);
587 if(lp->dialtimeout > 0)
588 if(lp->dialstarted == 0 || time_after(jiffies, lp->dialstarted + lp->dialtimeout + lp->dialwait)) {
589 lp->dialstarted = jiffies;
590 lp->dialwait_timer = 0;
596 /* Prepare dialing. Clear EAZ, then set EAZ. */
597 cmd.driver = lp->isdn_device;
598 cmd.arg = lp->isdn_channel;
599 cmd.command = ISDN_CMD_CLREAZ;
601 sprintf(cmd.parm.num, "%s", isdn_map_eaz2msn(lp->msn, cmd.driver));
602 cmd.command = ISDN_CMD_SETEAZ;
609 /* Setup interface, dial current phone-number, switch to next number.
610 * If list of phone-numbers is exhausted, increment
613 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF)) {
615 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
616 s = "dial suppressed: isdn system stopped";
618 s = "dial suppressed: dialmode `off'";
619 isdn_net_unreachable(p->dev, NULL, s);
620 isdn_net_hangup(p->dev);
623 cmd.driver = lp->isdn_device;
624 cmd.command = ISDN_CMD_SETL2;
625 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
627 cmd.driver = lp->isdn_device;
628 cmd.command = ISDN_CMD_SETL3;
629 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
631 cmd.driver = lp->isdn_device;
632 cmd.arg = lp->isdn_channel;
634 printk(KERN_WARNING "%s: phone number deleted?\n",
636 isdn_net_hangup(p->dev);
639 if (!strncmp(lp->dial->num, "LEASED", strlen("LEASED"))) {
641 printk(KERN_INFO "%s: Open leased line ...\n", p->dev->name);
643 if(lp->dialtimeout > 0)
644 if (time_after(jiffies, lp->dialstarted + lp->dialtimeout)) {
645 lp->dialwait_timer = jiffies + lp->dialwait;
647 isdn_net_unreachable(p->dev, NULL, "dial: timed out");
648 isdn_net_hangup(p->dev);
652 cmd.driver = lp->isdn_device;
653 cmd.command = ISDN_CMD_DIAL;
654 cmd.parm.setup.si2 = 0;
657 phone_number = lp->dial->num;
658 if ((*phone_number == 'v') ||
659 (*phone_number == 'V')) { /* DOV call */
660 cmd.parm.setup.si1 = 1;
661 } else { /* DATA call */
662 cmd.parm.setup.si1 = 7;
665 strcpy(cmd.parm.setup.phone, phone_number);
667 * Switch to next number or back to start if at end of list.
669 if (!(lp->dial = (isdn_net_phone *) lp->dial->next)) {
670 lp->dial = lp->phone[1];
673 if (lp->dialretry > lp->dialmax) {
674 if (lp->dialtimeout == 0) {
675 lp->dialwait_timer = jiffies + lp->dialwait;
677 isdn_net_unreachable(p->dev, NULL, "dial: tried all numbers dialmax times");
679 isdn_net_hangup(p->dev);
683 sprintf(cmd.parm.setup.eazmsn, "%s",
684 isdn_map_eaz2msn(lp->msn, cmd.driver));
685 i = isdn_dc2minor(lp->isdn_device, lp->isdn_channel);
687 strcpy(dev->num[i], cmd.parm.setup.phone);
688 dev->usage[i] |= ISDN_USAGE_OUTGOING;
691 printk(KERN_INFO "%s: dialing %d %s... %s\n", p->dev->name,
692 lp->dialretry, cmd.parm.setup.phone,
693 (cmd.parm.setup.si1 == 1) ? "DOV" : "");
695 #ifdef ISDN_DEBUG_NET_DIAL
696 printk(KERN_DEBUG "dial: d=%d c=%d\n", lp->isdn_device,
704 lp->hupflags |= ISDN_HAVECHARGE;
705 lp->hupflags &= ~ISDN_WAITCHARGE;
707 lp->hupflags |= ISDN_WAITCHARGE;
708 lp->hupflags &= ~ISDN_HAVECHARGE;
713 (lp->flags & ISDN_NET_CBOUT)) ? 12 : 4;
716 /* Wait for D-Channel-connect.
717 * If timeout, switch back to state 3.
718 * Dialmax-handling moved to state 3.
720 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
725 /* Got D-Channel-Connect, send B-Channel-request */
726 cmd.driver = lp->isdn_device;
727 cmd.arg = lp->isdn_channel;
728 cmd.command = ISDN_CMD_ACCEPTB;
735 /* Wait for B- or D-Channel-connect. If timeout,
736 * switch back to state 3.
738 #ifdef ISDN_DEBUG_NET_DIAL
739 printk(KERN_DEBUG "dialtimer2: %d\n", lp->dtimer);
741 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
746 /* Got incoming Call, setup L2 and L3 protocols,
747 * then wait for D-Channel-connect
749 #ifdef ISDN_DEBUG_NET_DIAL
750 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
752 cmd.driver = lp->isdn_device;
753 cmd.command = ISDN_CMD_SETL2;
754 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
756 cmd.driver = lp->isdn_device;
757 cmd.command = ISDN_CMD_SETL3;
758 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
760 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT15)
761 isdn_net_hangup(p->dev);
768 /* Got incoming D-Channel-Connect, send B-Channel-request */
769 cmd.driver = lp->isdn_device;
770 cmd.arg = lp->isdn_channel;
771 cmd.command = ISDN_CMD_ACCEPTB;
779 /* Wait for B- or D-channel-connect */
780 #ifdef ISDN_DEBUG_NET_DIAL
781 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
783 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
784 isdn_net_hangup(p->dev);
790 if (lp->dtimer++ > lp->cbdelay)
795 /* Remote does callback. Hangup after cbdelay, then wait for incoming
798 if (lp->dtimer++ > lp->cbdelay)
800 printk(KERN_INFO "%s: hangup waiting for callback ...\n", p->dev->name);
803 cmd.driver = lp->isdn_device;
804 cmd.command = ISDN_CMD_HANGUP;
805 cmd.arg = lp->isdn_channel;
807 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
812 printk(KERN_WARNING "isdn_net: Illegal dialstate %d for device %s\n",
813 lp->dialstate, p->dev->name);
815 p = (isdn_net_dev *) p->next;
817 isdn_timer_ctrl(ISDN_TIMER_NETDIAL, anymore);
821 * Perform hangup for a net-interface.
824 isdn_net_hangup(struct net_device *d)
826 isdn_net_local *lp = (isdn_net_local *) netdev_priv(d);
828 #ifdef CONFIG_ISDN_X25
829 struct concap_proto *cprot = lp->netdev->cprot;
830 struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
833 if (lp->flags & ISDN_NET_CONNECTED) {
834 if (lp->slave != NULL) {
835 isdn_net_local *slp = ISDN_SLAVE_PRIV(lp);
836 if (slp->flags & ISDN_NET_CONNECTED) {
838 "isdn_net: hang up slave %s before %s\n",
839 lp->slave->name, d->name);
840 isdn_net_hangup(lp->slave);
843 printk(KERN_INFO "isdn_net: local hangup %s\n", d->name);
844 #ifdef CONFIG_ISDN_PPP
845 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
848 isdn_net_lp_disconnected(lp);
849 #ifdef CONFIG_ISDN_X25
850 /* try if there are generic encap protocol
851 receiver routines and signal the closure of
853 if( pops && pops -> disconn_ind )
854 pops -> disconn_ind(cprot);
855 #endif /* CONFIG_ISDN_X25 */
857 cmd.driver = lp->isdn_device;
858 cmd.command = ISDN_CMD_HANGUP;
859 cmd.arg = lp->isdn_channel;
861 printk(KERN_INFO "%s: Chargesum is %d\n", d->name, lp->charge);
862 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
864 isdn_net_unbind_channel(lp);
873 isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
875 /* hopefully, this was set correctly */
876 const u_char *p = skb_network_header(skb);
877 unsigned short proto = ntohs(skb->protocol);
883 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
884 if (p < skb->data || skb->network_header >= skb->tail) {
885 /* fall back to old isdn_net_log_packet method() */
886 char * buf = skb->data;
888 printk(KERN_DEBUG "isdn_net: protocol %04x is buggy, dev %s\n", skb->protocol, lp->netdev->dev->name);
891 switch (lp->p_encap) {
892 case ISDN_NET_ENCAP_IPTYP:
893 proto = ntohs(*(__be16 *)&buf[0]);
896 case ISDN_NET_ENCAP_ETHER:
897 proto = ntohs(*(__be16 *)&buf[12]);
900 case ISDN_NET_ENCAP_CISCOHDLC:
901 proto = ntohs(*(__be16 *)&buf[2]);
904 #ifdef CONFIG_ISDN_PPP
905 case ISDN_NET_ENCAP_SYNCPPP:
906 proto = ntohs(skb->protocol);
907 p = &buf[IPPP_MAX_HEADER];
912 data_ofs = ((p[0] & 15) * 4);
917 strcpy(addinfo, " ICMP");
920 strcpy(addinfo, " IGMP");
923 strcpy(addinfo, " IPIP");
926 ipp = (ip_ports *) (&p[data_ofs]);
927 sprintf(addinfo, " TCP, port: %d -> %d", ntohs(ipp->source),
931 strcpy(addinfo, " EGP");
934 strcpy(addinfo, " PUP");
937 ipp = (ip_ports *) (&p[data_ofs]);
938 sprintf(addinfo, " UDP, port: %d -> %d", ntohs(ipp->source),
942 strcpy(addinfo, " IDP");
945 printk(KERN_INFO "OPEN: %pI4 -> %pI4%s\n",
946 p + 12, p + 16, addinfo);
949 printk(KERN_INFO "OPEN: ARP %pI4 -> *.*.*.* ?%pI4\n",
956 * this function is used to send supervisory data, i.e. data which was
957 * not received from the network layer, but e.g. frames from ipppd, CCP
960 void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb)
963 // we can't grab the lock from irq context,
964 // so we just queue the packet
965 skb_queue_tail(&lp->super_tx_queue, skb);
966 schedule_work(&lp->tqueue);
970 spin_lock_bh(&lp->xmit_lock);
971 if (!isdn_net_lp_busy(lp)) {
972 isdn_net_writebuf_skb(lp, skb);
974 skb_queue_tail(&lp->super_tx_queue, skb);
976 spin_unlock_bh(&lp->xmit_lock);
980 * called from tq_immediate
982 static void isdn_net_softint(struct work_struct *work)
984 isdn_net_local *lp = container_of(work, isdn_net_local, tqueue);
987 spin_lock_bh(&lp->xmit_lock);
988 while (!isdn_net_lp_busy(lp)) {
989 skb = skb_dequeue(&lp->super_tx_queue);
992 isdn_net_writebuf_skb(lp, skb);
994 spin_unlock_bh(&lp->xmit_lock);
998 * all frames sent from the (net) LL to a HL driver should go via this function
999 * it's serialized by the caller holding the lp->xmit_lock spinlock
1001 void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb)
1004 int len = skb->len; /* save len */
1006 /* before obtaining the lock the caller should have checked that
1007 the lp isn't busy */
1008 if (isdn_net_lp_busy(lp)) {
1009 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1013 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1014 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1017 ret = isdn_writebuf_skb_stub(lp->isdn_device, lp->isdn_channel, 1, skb);
1019 /* we should never get here */
1020 printk(KERN_WARNING "%s: HL driver queue full\n", lp->netdev->dev->name);
1024 lp->transcount += len;
1025 isdn_net_inc_frame_cnt(lp);
1030 lp->stats.tx_errors++;
1036 * Helper function for isdn_net_start_xmit.
1037 * When called, the connection is already established.
1038 * Based on cps-calculation, check if device is overloaded.
1039 * If so, and if a slave exists, trigger dialing for it.
1040 * If any slave is online, deliver packets using a simple round robin
1043 * Return: 0 on success, !0 on failure.
1047 isdn_net_xmit(struct net_device *ndev, struct sk_buff *skb)
1050 isdn_net_local *slp;
1051 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
1054 if (((isdn_net_local *) netdev_priv(ndev))->master) {
1055 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1060 /* For the other encaps the header has already been built */
1061 #ifdef CONFIG_ISDN_PPP
1062 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1063 return isdn_ppp_xmit(skb, ndev);
1066 nd = ((isdn_net_local *) netdev_priv(ndev))->netdev;
1067 lp = isdn_net_get_locked_lp(nd);
1069 printk(KERN_WARNING "%s: all channels busy - requeuing!\n", ndev->name);
1072 /* we have our lp locked from now on */
1074 /* Reset hangup-timeout */
1075 lp->huptimer = 0; // FIXME?
1076 isdn_net_writebuf_skb(lp, skb);
1077 spin_unlock_bh(&lp->xmit_lock);
1079 /* the following stuff is here for backwards compatibility.
1080 * in future, start-up and hangup of slaves (based on current load)
1081 * should move to userspace and get based on an overall cps
1084 if (lp->cps > lp->triggercps) {
1087 /* First time overload: set timestamp only */
1089 lp->sqfull_stamp = jiffies;
1091 /* subsequent overload: if slavedelay exceeded, start dialing */
1092 if (time_after(jiffies, lp->sqfull_stamp + lp->slavedelay)) {
1093 slp = ISDN_SLAVE_PRIV(lp);
1094 if (!(slp->flags & ISDN_NET_CONNECTED)) {
1095 isdn_net_force_dial_lp(ISDN_SLAVE_PRIV(lp));
1101 if (lp->sqfull && time_after(jiffies, lp->sqfull_stamp + lp->slavedelay + (10 * HZ))) {
1104 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1105 nd->queue = nd->local;
1113 isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
1115 isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
1118 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
1119 const int pullsize = skb_network_offset(skb) - ETH_HLEN;
1121 printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
1122 skb_pull(skb, pullsize);
1128 static void isdn_net_tx_timeout(struct net_device * ndev)
1130 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
1132 printk(KERN_WARNING "isdn_tx_timeout dev %s dialstate %d\n", ndev->name, lp->dialstate);
1133 if (!lp->dialstate){
1134 lp->stats.tx_errors++;
1136 * There is a certain probability that this currently
1137 * works at all because if we always wake up the interface,
1138 * then upper layer will try to send the next packet
1139 * immediately. And then, the old clean_up logic in the
1140 * driver will hopefully continue to work as it used to do.
1142 * This is rather primitive right know, we better should
1143 * clean internal queues here, in particular for multilink and
1144 * ppp, and reset HL driver's channel, too. --HE
1146 * actually, this may not matter at all, because ISDN hardware
1147 * should not see transmitter hangs at all IMO
1148 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1152 ndev->trans_start = jiffies;
1153 netif_wake_queue(ndev);
1157 * Try sending a packet.
1158 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1159 * and start dialing.
1162 isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1164 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
1165 #ifdef CONFIG_ISDN_X25
1166 struct concap_proto * cprot = lp -> netdev -> cprot;
1167 /* At this point hard_start_xmit() passes control to the encapsulation
1168 protocol (if present).
1169 For X.25 auto-dialing is completly bypassed because:
1170 - It does not conform with the semantics of a reliable datalink
1171 service as needed by X.25 PLP.
1172 - I don't want that the interface starts dialing when the network layer
1173 sends a message which requests to disconnect the lapb link (or if it
1174 sends any other message not resulting in data transmission).
1175 Instead, dialing will be initiated by the encapsulation protocol entity
1176 when a dl_establish request is received from the upper layer.
1178 if (cprot && cprot -> pops) {
1179 int ret = cprot -> pops -> encap_and_xmit ( cprot , skb);
1182 netif_stop_queue(ndev);
1186 /* auto-dialing xmit function */
1188 #ifdef ISDN_DEBUG_NET_DUMP
1191 isdn_net_adjust_hdr(skb, ndev);
1192 #ifdef ISDN_DEBUG_NET_DUMP
1194 isdn_dumppkt("S:", buf, skb->len, 40);
1197 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1199 /* only do autodial if allowed by config */
1200 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) {
1201 isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'");
1208 if(lp->dialwait_timer <= 0)
1209 if(lp->dialstarted > 0 && lp->dialtimeout > 0 && time_before(jiffies, lp->dialstarted + lp->dialtimeout + lp->dialwait))
1210 lp->dialwait_timer = lp->dialstarted + lp->dialtimeout + lp->dialwait;
1212 if(lp->dialwait_timer > 0) {
1213 if(time_before(jiffies, lp->dialwait_timer)) {
1214 isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached");
1218 lp->dialwait_timer = 0;
1220 /* Grab a free ISDN-Channel */
1221 spin_lock_irqsave(&dev->lock, flags);
1223 isdn_get_free_channel(
1232 isdn_get_free_channel(
1240 spin_unlock_irqrestore(&dev->lock, flags);
1241 isdn_net_unreachable(ndev, skb,
1246 /* Log packet, which triggered dialing */
1247 if (dev->net_verbose)
1248 isdn_net_log_skb(skb, lp);
1250 /* Connect interface with channel */
1251 isdn_net_bind_channel(lp, chi);
1252 #ifdef CONFIG_ISDN_PPP
1253 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1254 /* no 'first_skb' handling for syncPPP */
1255 if (isdn_ppp_bind(lp) < 0) {
1257 isdn_net_unbind_channel(lp);
1258 spin_unlock_irqrestore(&dev->lock, flags);
1259 return 0; /* STN (skb to nirvana) ;) */
1261 #ifdef CONFIG_IPPP_FILTER
1262 if (isdn_ppp_autodial_filter(skb, lp)) {
1264 isdn_net_unbind_channel(lp);
1265 spin_unlock_irqrestore(&dev->lock, flags);
1266 isdn_net_unreachable(ndev, skb, "dial rejected: packet filtered");
1271 spin_unlock_irqrestore(&dev->lock, flags);
1272 isdn_net_dial(); /* Initiate dialing */
1273 netif_stop_queue(ndev);
1274 return 1; /* let upper layer requeue skb packet */
1277 /* Initiate dialing */
1278 spin_unlock_irqrestore(&dev->lock, flags);
1280 isdn_net_device_stop_queue(lp);
1283 isdn_net_unreachable(ndev, skb,
1289 /* Device is connected to an ISDN channel */
1290 ndev->trans_start = jiffies;
1291 if (!lp->dialstate) {
1292 /* ISDN connection is established, try sending */
1294 ret = (isdn_net_xmit(ndev, skb));
1295 if(ret) netif_stop_queue(ndev);
1298 netif_stop_queue(ndev);
1305 * Shutdown a net-interface.
1308 isdn_net_close(struct net_device *dev)
1310 struct net_device *p;
1311 #ifdef CONFIG_ISDN_X25
1312 struct concap_proto * cprot =
1313 ((isdn_net_local *) netdev_priv(dev))->netdev->cprot;
1314 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1317 #ifdef CONFIG_ISDN_X25
1318 if( cprot && cprot -> pops ) cprot -> pops -> close( cprot );
1320 netif_stop_queue(dev);
1321 p = MASTER_TO_SLAVE(dev);
1323 /* If this interface has slaves, stop them also */
1325 #ifdef CONFIG_ISDN_X25
1326 cprot = ((isdn_net_local *) netdev_priv(p))
1328 if( cprot && cprot -> pops )
1329 cprot -> pops -> close( cprot );
1332 p = MASTER_TO_SLAVE(p);
1335 isdn_net_hangup(dev);
1336 isdn_unlock_drivers();
1343 static struct net_device_stats *
1344 isdn_net_get_stats(struct net_device *dev)
1346 isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
1350 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1351 * instead of dev->hard_header_len off. This is done because the
1352 * lowlevel-driver has already pulled off its stuff when we get
1353 * here and this routine only gets called with p_encap == ETHER.
1354 * Determine the packet's protocol ID. The rule here is that we
1355 * assume 802.3 if the type field is short enough to be a length.
1356 * This is normal practice and works for any 'now in use' protocol.
1360 isdn_net_type_trans(struct sk_buff *skb, struct net_device *dev)
1363 unsigned char *rawp;
1365 skb_reset_mac_header(skb);
1366 skb_pull(skb, ETH_HLEN);
1369 if (*eth->h_dest & 1) {
1370 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
1371 skb->pkt_type = PACKET_BROADCAST;
1373 skb->pkt_type = PACKET_MULTICAST;
1376 * This ALLMULTI check should be redundant by 1.4
1377 * so don't forget to remove it.
1380 else if (dev->flags & (IFF_PROMISC /*| IFF_ALLMULTI*/)) {
1381 if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
1382 skb->pkt_type = PACKET_OTHERHOST;
1384 if (ntohs(eth->h_proto) >= 1536)
1385 return eth->h_proto;
1390 * This is a magic hack to spot IPX packets. Older Novell breaks
1391 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1392 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1393 * won't work for fault tolerant netware but does for the rest.
1395 if (*(unsigned short *) rawp == 0xFFFF)
1396 return htons(ETH_P_802_3);
1400 return htons(ETH_P_802_2);
1405 * CISCO HDLC keepalive specific stuff
1407 static struct sk_buff*
1408 isdn_net_ciscohdlck_alloc_skb(isdn_net_local *lp, int len)
1410 unsigned short hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
1411 struct sk_buff *skb;
1413 skb = alloc_skb(hl + len, GFP_ATOMIC);
1415 skb_reserve(skb, hl);
1417 printk("isdn out of mem at %s:%d!\n", __FILE__, __LINE__);
1421 /* cisco hdlck device private ioctls */
1423 isdn_ciscohdlck_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1425 isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
1426 unsigned long len = 0;
1427 unsigned long expires = 0;
1429 int period = lp->cisco_keepalive_period;
1430 s8 debserint = lp->cisco_debserint;
1433 if (lp->p_encap != ISDN_NET_ENCAP_CISCOHDLCK)
1437 /* get/set keepalive period */
1438 case SIOCGKEEPPERIOD:
1439 len = (unsigned long)sizeof(lp->cisco_keepalive_period);
1440 if (copy_to_user(ifr->ifr_data,
1441 &lp->cisco_keepalive_period, len))
1444 case SIOCSKEEPPERIOD:
1445 tmp = lp->cisco_keepalive_period;
1446 len = (unsigned long)sizeof(lp->cisco_keepalive_period);
1447 if (copy_from_user(&period, ifr->ifr_data, len))
1449 if ((period > 0) && (period <= 32767))
1450 lp->cisco_keepalive_period = period;
1453 if (!rc && (tmp != lp->cisco_keepalive_period)) {
1454 expires = (unsigned long)(jiffies +
1455 lp->cisco_keepalive_period * HZ);
1456 mod_timer(&lp->cisco_timer, expires);
1457 printk(KERN_INFO "%s: Keepalive period set "
1459 dev->name, lp->cisco_keepalive_period);
1463 /* get/set debugging */
1464 case SIOCGDEBSERINT:
1465 len = (unsigned long)sizeof(lp->cisco_debserint);
1466 if (copy_to_user(ifr->ifr_data,
1467 &lp->cisco_debserint, len))
1470 case SIOCSDEBSERINT:
1471 len = (unsigned long)sizeof(lp->cisco_debserint);
1472 if (copy_from_user(&debserint,
1473 ifr->ifr_data, len))
1475 if ((debserint >= 0) && (debserint <= 64))
1476 lp->cisco_debserint = debserint;
1488 /* called via cisco_timer.function */
1490 isdn_net_ciscohdlck_slarp_send_keepalive(unsigned long data)
1492 isdn_net_local *lp = (isdn_net_local *) data;
1493 struct sk_buff *skb;
1495 unsigned long last_cisco_myseq = lp->cisco_myseq;
1498 if (!(lp->flags & ISDN_NET_CONNECTED) || lp->dialstate) {
1499 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1504 myseq_diff = (lp->cisco_myseq - lp->cisco_mineseen);
1505 if ((lp->cisco_line_state) && ((myseq_diff >= 3)||(myseq_diff <= -3))) {
1506 /* line up -> down */
1507 lp->cisco_line_state = 0;
1508 printk (KERN_WARNING
1509 "UPDOWN: Line protocol on Interface %s,"
1510 " changed state to down\n", lp->netdev->dev->name);
1511 /* should stop routing higher-level data accross */
1512 } else if ((!lp->cisco_line_state) &&
1513 (myseq_diff >= 0) && (myseq_diff <= 2)) {
1514 /* line down -> up */
1515 lp->cisco_line_state = 1;
1516 printk (KERN_WARNING
1517 "UPDOWN: Line protocol on Interface %s,"
1518 " changed state to up\n", lp->netdev->dev->name);
1519 /* restart routing higher-level data accross */
1522 if (lp->cisco_debserint)
1523 printk (KERN_DEBUG "%s: HDLC "
1524 "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
1525 lp->netdev->dev->name, last_cisco_myseq, lp->cisco_mineseen,
1526 ((last_cisco_myseq == lp->cisco_mineseen) ? '*' : 040),
1528 ((lp->cisco_line_state) ? "line up" : "line down"));
1530 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1534 p = skb_put(skb, 4 + 14);
1537 *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
1538 *(u8 *)(p + 1) = CISCO_CTRL;
1539 *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
1541 /* slarp keepalive */
1542 *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_KEEPALIVE);
1543 *(__be32 *)(p + 8) = cpu_to_be32(lp->cisco_myseq);
1544 *(__be32 *)(p + 12) = cpu_to_be32(lp->cisco_yourseq);
1545 *(__be16 *)(p + 16) = cpu_to_be16(0xffff); // reliablity, always 0xffff
1548 isdn_net_write_super(lp, skb);
1550 lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
1552 add_timer(&lp->cisco_timer);
1556 isdn_net_ciscohdlck_slarp_send_request(isdn_net_local *lp)
1558 struct sk_buff *skb;
1561 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1565 p = skb_put(skb, 4 + 14);
1568 *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
1569 *(u8 *)(p + 1) = CISCO_CTRL;
1570 *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
1573 *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_REQUEST);
1574 *(__be32 *)(p + 8) = cpu_to_be32(0); // address
1575 *(__be32 *)(p + 12) = cpu_to_be32(0); // netmask
1576 *(__be16 *)(p + 16) = cpu_to_be16(0); // unused
1579 isdn_net_write_super(lp, skb);
1583 isdn_net_ciscohdlck_connected(isdn_net_local *lp)
1585 lp->cisco_myseq = 0;
1586 lp->cisco_mineseen = 0;
1587 lp->cisco_yourseq = 0;
1588 lp->cisco_keepalive_period = ISDN_TIMER_KEEPINT;
1589 lp->cisco_last_slarp_in = 0;
1590 lp->cisco_line_state = 0;
1591 lp->cisco_debserint = 0;
1593 /* send slarp request because interface/seq.no.s reset */
1594 isdn_net_ciscohdlck_slarp_send_request(lp);
1596 init_timer(&lp->cisco_timer);
1597 lp->cisco_timer.data = (unsigned long) lp;
1598 lp->cisco_timer.function = isdn_net_ciscohdlck_slarp_send_keepalive;
1599 lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
1600 add_timer(&lp->cisco_timer);
1604 isdn_net_ciscohdlck_disconnected(isdn_net_local *lp)
1606 del_timer(&lp->cisco_timer);
1610 isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local *lp)
1612 struct sk_buff *skb;
1614 struct in_device *in_dev = NULL;
1615 __be32 addr = 0; /* local ipv4 address */
1616 __be32 mask = 0; /* local netmask */
1618 if ((in_dev = lp->netdev->dev->ip_ptr) != NULL) {
1619 /* take primary(first) address of interface */
1620 struct in_ifaddr *ifa = in_dev->ifa_list;
1622 addr = ifa->ifa_local;
1623 mask = ifa->ifa_mask;
1627 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1631 p = skb_put(skb, 4 + 14);
1634 *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
1635 *(u8 *)(p + 1) = CISCO_CTRL;
1636 *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
1638 /* slarp reply, send own ip/netmask; if values are nonsense remote
1639 * should think we are unable to provide it with an address via SLARP */
1640 *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_REPLY);
1641 *(__be32 *)(p + 8) = addr; // address
1642 *(__be32 *)(p + 12) = mask; // netmask
1643 *(__be16 *)(p + 16) = cpu_to_be16(0); // unused
1646 isdn_net_write_super(lp, skb);
1650 isdn_net_ciscohdlck_slarp_in(isdn_net_local *lp, struct sk_buff *skb)
1658 __be32 *addr, *mask;
1665 code = be32_to_cpup((__be32 *)p);
1669 case CISCO_SLARP_REQUEST:
1670 lp->cisco_yourseq = 0;
1671 isdn_net_ciscohdlck_slarp_send_reply(lp);
1673 case CISCO_SLARP_REPLY:
1675 mask = (__be32 *)(p + 4);
1676 if (*mask != cpu_to_be32(0xfffffffc))
1677 goto slarp_reply_out;
1678 if ((*addr & cpu_to_be32(3)) == cpu_to_be32(0) ||
1679 (*addr & cpu_to_be32(3)) == cpu_to_be32(3))
1680 goto slarp_reply_out;
1681 local = *addr ^ cpu_to_be32(3);
1682 printk(KERN_INFO "%s: got slarp reply: remote ip: %pI4, local ip: %pI4 mask: %pI4\n",
1683 lp->netdev->dev->name, addr, &local, mask);
1686 printk(KERN_INFO "%s: got invalid slarp reply (%pI4/%pI4) - ignored\n",
1687 lp->netdev->dev->name, addr, mask);
1689 case CISCO_SLARP_KEEPALIVE:
1690 period = (int)((jiffies - lp->cisco_last_slarp_in
1692 if (lp->cisco_debserint &&
1693 (period != lp->cisco_keepalive_period) &&
1694 lp->cisco_last_slarp_in) {
1695 printk(KERN_DEBUG "%s: Keepalive period mismatch - "
1696 "is %d but should be %d.\n",
1697 lp->netdev->dev->name, period,
1698 lp->cisco_keepalive_period);
1700 lp->cisco_last_slarp_in = jiffies;
1701 my_seq = be32_to_cpup((__be32 *)(p + 0));
1702 your_seq = be32_to_cpup((__be32 *)(p + 4));
1703 unused = be16_to_cpup((__be16 *)(p + 8));
1705 lp->cisco_yourseq = my_seq;
1706 lp->cisco_mineseen = your_seq;
1712 isdn_net_ciscohdlck_receive(isdn_net_local *lp, struct sk_buff *skb)
1723 addr = *(u8 *)(p + 0);
1724 ctrl = *(u8 *)(p + 1);
1725 type = be16_to_cpup((__be16 *)(p + 2));
1729 if (addr != CISCO_ADDR_UNICAST && addr != CISCO_ADDR_BROADCAST) {
1730 printk(KERN_WARNING "%s: Unknown Cisco addr 0x%02x\n",
1731 lp->netdev->dev->name, addr);
1734 if (ctrl != CISCO_CTRL) {
1735 printk(KERN_WARNING "%s: Unknown Cisco ctrl 0x%02x\n",
1736 lp->netdev->dev->name, ctrl);
1741 case CISCO_TYPE_SLARP:
1742 isdn_net_ciscohdlck_slarp_in(lp, skb);
1744 case CISCO_TYPE_CDP:
1745 if (lp->cisco_debserint)
1746 printk(KERN_DEBUG "%s: Received CDP packet. use "
1747 "\"no cdp enable\" on cisco.\n",
1748 lp->netdev->dev->name);
1751 /* no special cisco protocol */
1752 skb->protocol = htons(type);
1762 * Got a packet from ISDN-Channel.
1765 isdn_net_receive(struct net_device *ndev, struct sk_buff *skb)
1767 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
1768 isdn_net_local *olp = lp; /* original 'lp' */
1769 #ifdef CONFIG_ISDN_X25
1770 struct concap_proto *cprot = lp -> netdev -> cprot;
1772 lp->transcount += skb->len;
1774 lp->stats.rx_packets++;
1775 lp->stats.rx_bytes += skb->len;
1777 /* Bundling: If device is a slave-device, deliver to master, also
1778 * handle master's statistics and hangup-timeout
1781 lp = (isdn_net_local *) netdev_priv(ndev);
1782 lp->stats.rx_packets++;
1783 lp->stats.rx_bytes += skb->len;
1786 skb->pkt_type = PACKET_HOST;
1787 skb_reset_mac_header(skb);
1788 #ifdef ISDN_DEBUG_NET_DUMP
1789 isdn_dumppkt("R:", skb->data, skb->len, 40);
1791 switch (lp->p_encap) {
1792 case ISDN_NET_ENCAP_ETHER:
1793 /* Ethernet over ISDN */
1796 skb->protocol = isdn_net_type_trans(skb, ndev);
1798 case ISDN_NET_ENCAP_UIHDLC:
1799 /* HDLC with UI-frame (for ispa with -h1 option) */
1804 case ISDN_NET_ENCAP_RAWIP:
1805 /* RAW-IP without MAC-Header */
1808 skb->protocol = htons(ETH_P_IP);
1810 case ISDN_NET_ENCAP_CISCOHDLCK:
1811 isdn_net_ciscohdlck_receive(lp, skb);
1813 case ISDN_NET_ENCAP_CISCOHDLC:
1814 /* CISCO-HDLC IP with type field and fake I-frame-header */
1817 case ISDN_NET_ENCAP_IPTYP:
1818 /* IP with type field */
1821 skb->protocol = *(__be16 *)&(skb->data[0]);
1823 if (*(unsigned short *) skb->data == 0xFFFF)
1824 skb->protocol = htons(ETH_P_802_3);
1826 #ifdef CONFIG_ISDN_PPP
1827 case ISDN_NET_ENCAP_SYNCPPP:
1828 /* huptimer is done in isdn_ppp_push_higher */
1829 isdn_ppp_receive(lp->netdev, olp, skb);
1834 #ifdef CONFIG_ISDN_X25
1835 /* try if there are generic sync_device receiver routines */
1836 if(cprot) if(cprot -> pops)
1837 if( cprot -> pops -> data_ind){
1838 cprot -> pops -> data_ind(cprot,skb);
1841 #endif /* CONFIG_ISDN_X25 */
1842 printk(KERN_WARNING "%s: unknown encapsulation, dropping\n",
1843 lp->netdev->dev->name);
1853 * A packet arrived via ISDN. Search interface-chain for a corresponding
1854 * interface. If found, deliver packet to receiver-function and return 1,
1858 isdn_net_rcv_skb(int idx, struct sk_buff *skb)
1860 isdn_net_dev *p = dev->rx_netdev[idx];
1863 isdn_net_local *lp = p->local;
1864 if ((lp->flags & ISDN_NET_CONNECTED) &&
1866 isdn_net_receive(p->dev, skb);
1875 * depends on encaps that is being used.
1878 static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
1879 unsigned short type,
1880 const void *daddr, const void *saddr, unsigned plen)
1882 isdn_net_local *lp = netdev_priv(dev);
1886 switch (lp->p_encap) {
1887 case ISDN_NET_ENCAP_ETHER:
1888 len = eth_header(skb, dev, type, daddr, saddr, plen);
1890 #ifdef CONFIG_ISDN_PPP
1891 case ISDN_NET_ENCAP_SYNCPPP:
1892 /* stick on a fake header to keep fragmentation code happy. */
1893 len = IPPP_MAX_HEADER;
1897 case ISDN_NET_ENCAP_RAWIP:
1898 printk(KERN_WARNING "isdn_net_header called with RAW_IP!\n");
1901 case ISDN_NET_ENCAP_IPTYP:
1902 /* ethernet type field */
1903 *((__be16 *)skb_push(skb, 2)) = htons(type);
1906 case ISDN_NET_ENCAP_UIHDLC:
1907 /* HDLC with UI-Frames (for ispa with -h1 option) */
1908 *((__be16 *)skb_push(skb, 2)) = htons(0x0103);
1911 case ISDN_NET_ENCAP_CISCOHDLC:
1912 case ISDN_NET_ENCAP_CISCOHDLCK:
1913 p = skb_push(skb, 4);
1914 *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
1915 *(u8 *)(p + 1) = CISCO_CTRL;
1916 *(__be16 *)(p + 2) = cpu_to_be16(type);
1920 #ifdef CONFIG_ISDN_X25
1922 /* try if there are generic concap protocol routines */
1923 if( lp-> netdev -> cprot ){
1924 printk(KERN_WARNING "isdn_net_header called with concap_proto!\n");
1929 #endif /* CONFIG_ISDN_X25 */
1934 /* We don't need to send arp, because we have point-to-point connections. */
1936 isdn_net_rebuild_header(struct sk_buff *skb)
1938 struct net_device *dev = skb->dev;
1939 isdn_net_local *lp = netdev_priv(dev);
1942 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
1943 struct ethhdr *eth = (struct ethhdr *) skb->data;
1946 * Only ARP/IP is currently supported
1949 if (eth->h_proto != htons(ETH_P_IP)) {
1951 "isdn_net: %s don't know how to resolve type %d addresses?\n",
1952 dev->name, (int) eth->h_proto);
1953 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
1957 * Try to get ARP to resolve the header.
1960 ret = arp_find(eth->h_dest, skb);
1966 static int isdn_header_cache(const struct neighbour *neigh, struct hh_cache *hh)
1968 const struct net_device *dev = neigh->dev;
1969 isdn_net_local *lp = netdev_priv(dev);
1971 if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
1972 return eth_header_cache(neigh, hh);
1976 static void isdn_header_cache_update(struct hh_cache *hh,
1977 const struct net_device *dev,
1978 const unsigned char *haddr)
1980 isdn_net_local *lp = netdev_priv(dev);
1981 if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
1982 eth_header_cache_update(hh, dev, haddr);
1985 static const struct header_ops isdn_header_ops = {
1986 .create = isdn_net_header,
1987 .rebuild = isdn_net_rebuild_header,
1988 .cache = isdn_header_cache,
1989 .cache_update = isdn_header_cache_update,
1993 * Interface-setup. (just after registering a new interface)
1996 isdn_net_init(struct net_device *ndev)
1998 ushort max_hlhdr_len = 0;
2002 ndev->header_ops = NULL;
2004 /* Setup the generic properties */
2006 ndev->flags = IFF_NOARP|IFF_POINTOPOINT;
2007 ndev->type = ARPHRD_ETHER;
2008 ndev->addr_len = ETH_ALEN;
2009 ndev->validate_addr = NULL;
2011 /* for clients with MPPP maybe higher values better */
2012 ndev->tx_queue_len = 30;
2014 /* The ISDN-specific entries in the device structure. */
2015 ndev->open = &isdn_net_open;
2016 ndev->hard_start_xmit = &isdn_net_start_xmit;
2019 * up till binding we ask the protocol layer to reserve as much
2020 * as we might need for HL layer
2023 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2024 if (dev->drv[drvidx])
2025 if (max_hlhdr_len < dev->drv[drvidx]->interface->hl_hdrlen)
2026 max_hlhdr_len = dev->drv[drvidx]->interface->hl_hdrlen;
2028 ndev->hard_header_len = ETH_HLEN + max_hlhdr_len;
2029 ndev->stop = &isdn_net_close;
2030 ndev->get_stats = &isdn_net_get_stats;
2031 ndev->do_ioctl = NULL;
2036 isdn_net_swapbind(int drvidx)
2040 #ifdef ISDN_DEBUG_NET_ICALL
2041 printk(KERN_DEBUG "n_fi: swapping ch of %d\n", drvidx);
2045 if (p->local->pre_device == drvidx)
2046 switch (p->local->pre_channel) {
2048 p->local->pre_channel = 1;
2051 p->local->pre_channel = 0;
2054 p = (isdn_net_dev *) p->next;
2059 isdn_net_swap_usage(int i1, int i2)
2061 int u1 = dev->usage[i1] & ISDN_USAGE_EXCLUSIVE;
2062 int u2 = dev->usage[i2] & ISDN_USAGE_EXCLUSIVE;
2064 #ifdef ISDN_DEBUG_NET_ICALL
2065 printk(KERN_DEBUG "n_fi: usage of %d and %d\n", i1, i2);
2067 dev->usage[i1] &= ~ISDN_USAGE_EXCLUSIVE;
2068 dev->usage[i1] |= u2;
2069 dev->usage[i2] &= ~ISDN_USAGE_EXCLUSIVE;
2070 dev->usage[i2] |= u1;
2075 * An incoming call-request has arrived.
2076 * Search the interface-chain for an appropriate interface.
2077 * If found, connect the interface to the ISDN-channel and initiate
2078 * D- and B-Channel-setup. If secure-flag is set, accept only
2079 * configured phone-numbers. If callback-flag is set, initiate
2082 * Return-Value: 0 = No appropriate interface for this call.
2084 * 2 = Reject call, wait cbdelay, then call back
2086 * 4 = Wait cbdelay, then call back
2087 * 5 = No appropriate interface for this call,
2088 * would eventually match if CID was longer.
2092 isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
2104 char nr[ISDN_MSNLEN];
2107 /* Search name in netdev-chain */
2108 if (!setup->phone[0]) {
2111 printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
2113 strlcpy(nr, setup->phone, ISDN_MSNLEN);
2114 si1 = (int) setup->si1;
2115 si2 = (int) setup->si2;
2116 if (!setup->eazmsn[0]) {
2117 printk(KERN_WARNING "isdn_net: Incoming call without CPN, assuming '0'\n");
2120 eaz = setup->eazmsn;
2121 if (dev->net_verbose > 1)
2122 printk(KERN_INFO "isdn_net: call from %s,%d,%d -> %s\n", nr, si1, si2, eaz);
2123 /* Accept DATA and VOICE calls at this stage
2124 * local eaz is checked later for allowed call types
2126 if ((si1 != 7) && (si1 != 1)) {
2127 if (dev->net_verbose > 1)
2128 printk(KERN_INFO "isdn_net: Service-Indicator not 1 or 7, ignored\n");
2131 n = (isdn_net_phone *) 0;
2133 ematch = wret = swapped = 0;
2134 #ifdef ISDN_DEBUG_NET_ICALL
2135 printk(KERN_DEBUG "n_fi: di=%d ch=%d idx=%d usg=%d\n", di, ch, idx,
2140 isdn_net_local *lp = p->local;
2142 /* If last check has triggered as binding-swap, revert it */
2145 isdn_net_swap_usage(idx, sidx);
2148 isdn_net_swapbind(di);
2152 /* check acceptable call types for DOV */
2153 my_eaz = isdn_map_eaz2msn(lp->msn, di);
2154 if (si1 == 1) { /* it's a DOV call, check if we allow it */
2155 if (*my_eaz == 'v' || *my_eaz == 'V' ||
2156 *my_eaz == 'b' || *my_eaz == 'B')
2157 my_eaz++; /* skip to allow a match */
2159 my_eaz = NULL; /* force non match */
2160 } else { /* it's a DATA call, check if we allow it */
2161 if (*my_eaz == 'b' || *my_eaz == 'B')
2162 my_eaz++; /* skip to allow a match */
2165 matchret = isdn_msncmp(eaz, my_eaz);
2171 /* Remember if more numbers eventually can match */
2172 if (matchret > wret)
2174 #ifdef ISDN_DEBUG_NET_ICALL
2175 printk(KERN_DEBUG "n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2176 p->dev->name, lp->msn, lp->flags, lp->dialstate);
2178 if ((!matchret) && /* EAZ is matching */
2179 (((!(lp->flags & ISDN_NET_CONNECTED)) && /* but not connected */
2180 (USG_NONE(dev->usage[idx]))) || /* and ch. unused or */
2181 ((((lp->dialstate == 4) || (lp->dialstate == 12)) && /* if dialing */
2182 (!(lp->flags & ISDN_NET_CALLBACK))) /* but no callback */
2185 #ifdef ISDN_DEBUG_NET_ICALL
2186 printk(KERN_DEBUG "n_fi: match1, pdev=%d pch=%d\n",
2187 lp->pre_device, lp->pre_channel);
2189 if (dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) {
2190 if ((lp->pre_channel != ch) ||
2191 (lp->pre_device != di)) {
2192 /* Here we got a problem:
2193 * If using an ICN-Card, an incoming call is always signaled on
2194 * on the first channel of the card, if both channels are
2195 * down. However this channel may be bound exclusive. If the
2196 * second channel is free, this call should be accepted.
2197 * The solution is horribly but it runs, so what:
2198 * We exchange the exclusive bindings of the two channels, the
2199 * corresponding variables in the interface-structs.
2202 sidx = isdn_dc2minor(di, 1);
2203 #ifdef ISDN_DEBUG_NET_ICALL
2204 printk(KERN_DEBUG "n_fi: ch is 0\n");
2206 if (USG_NONE(dev->usage[sidx])) {
2207 /* Second Channel is free, now see if it is bound
2209 if (dev->usage[sidx] & ISDN_USAGE_EXCLUSIVE) {
2210 #ifdef ISDN_DEBUG_NET_ICALL
2211 printk(KERN_DEBUG "n_fi: 2nd channel is down and bound\n");
2213 /* Yes, swap bindings only, if the original
2214 * binding is bound to channel 1 of this driver */
2215 if ((lp->pre_device == di) &&
2216 (lp->pre_channel == 1)) {
2217 isdn_net_swapbind(di);
2220 /* ... else iterate next device */
2221 p = (isdn_net_dev *) p->next;
2225 #ifdef ISDN_DEBUG_NET_ICALL
2226 printk(KERN_DEBUG "n_fi: 2nd channel is down and unbound\n");
2228 /* No, swap always and swap excl-usage also */
2229 isdn_net_swap_usage(idx, sidx);
2230 isdn_net_swapbind(di);
2233 /* Now check for exclusive binding again */
2234 #ifdef ISDN_DEBUG_NET_ICALL
2235 printk(KERN_DEBUG "n_fi: final check\n");
2237 if ((dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) &&
2238 ((lp->pre_channel != ch) ||
2239 (lp->pre_device != di))) {
2240 #ifdef ISDN_DEBUG_NET_ICALL
2241 printk(KERN_DEBUG "n_fi: final check failed\n");
2243 p = (isdn_net_dev *) p->next;
2248 /* We are already on the second channel, so nothing to do */
2249 #ifdef ISDN_DEBUG_NET_ICALL
2250 printk(KERN_DEBUG "n_fi: already on 2nd channel\n");
2255 #ifdef ISDN_DEBUG_NET_ICALL
2256 printk(KERN_DEBUG "n_fi: match2\n");
2259 if (lp->flags & ISDN_NET_SECURE) {
2261 if (!isdn_msncmp(nr, n->num))
2263 n = (isdn_net_phone *) n->next;
2266 if (n || (!(lp->flags & ISDN_NET_SECURE))) {
2267 #ifdef ISDN_DEBUG_NET_ICALL
2268 printk(KERN_DEBUG "n_fi: match3\n");
2270 /* matching interface found */
2273 * Is the state STOPPED?
2274 * If so, no dialin is allowed,
2275 * so reject actively.
2277 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2278 printk(KERN_INFO "incoming call, interface %s `stopped' -> rejected\n",
2283 * Is the interface up?
2284 * If not, reject the call actively.
2286 if (!isdn_net_device_started(p)) {
2287 printk(KERN_INFO "%s: incoming call, interface down -> rejected\n",
2291 /* Interface is up, now see if it's a slave. If so, see if
2292 * it's master and parent slave is online. If not, reject the call.
2295 isdn_net_local *mlp = ISDN_MASTER_PRIV(lp);
2296 printk(KERN_DEBUG "ICALLslv: %s\n", p->dev->name);
2297 printk(KERN_DEBUG "master=%s\n", lp->master->name);
2298 if (mlp->flags & ISDN_NET_CONNECTED) {
2299 printk(KERN_DEBUG "master online\n");
2300 /* Master is online, find parent-slave (master if first slave) */
2301 while (mlp->slave) {
2302 if (ISDN_SLAVE_PRIV(mlp) == lp)
2304 mlp = ISDN_SLAVE_PRIV(mlp);
2307 printk(KERN_DEBUG "master offline\n");
2308 /* Found parent, if it's offline iterate next device */
2309 printk(KERN_DEBUG "mlpf: %d\n", mlp->flags & ISDN_NET_CONNECTED);
2310 if (!(mlp->flags & ISDN_NET_CONNECTED)) {
2311 p = (isdn_net_dev *) p->next;
2315 if (lp->flags & ISDN_NET_CALLBACK) {
2318 * Is the state MANUAL?
2319 * If so, no callback can be made,
2320 * so reject actively.
2322 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2323 printk(KERN_INFO "incoming call for callback, interface %s `off' -> rejected\n",
2327 printk(KERN_DEBUG "%s: call from %s -> %s, start callback\n",
2328 p->dev->name, nr, eaz);
2330 /* Grab a free ISDN-Channel */
2331 spin_lock_irqsave(&dev->lock, flags);
2333 isdn_get_free_channel(
2342 printk(KERN_WARNING "isdn_net_find_icall: No channel for %s\n",
2344 spin_unlock_irqrestore(&dev->lock, flags);
2347 /* Setup dialstate. */
2350 /* Connect interface with channel */
2351 isdn_net_bind_channel(lp, chi);
2352 #ifdef CONFIG_ISDN_PPP
2353 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2354 if (isdn_ppp_bind(lp) < 0) {
2355 spin_unlock_irqrestore(&dev->lock, flags);
2356 isdn_net_unbind_channel(lp);
2360 spin_unlock_irqrestore(&dev->lock, flags);
2361 /* Initiate dialing by returning 2 or 4 */
2362 return (lp->flags & ISDN_NET_CBHUP) ? 2 : 4;
2364 printk(KERN_WARNING "isdn_net: %s: No phone number\n",
2368 printk(KERN_DEBUG "%s: call from %s -> %s accepted\n",
2369 p->dev->name, nr, eaz);
2370 /* if this interface is dialing, it does it probably on a different
2371 device, so free this device */
2372 if ((lp->dialstate == 4) || (lp->dialstate == 12)) {
2373 #ifdef CONFIG_ISDN_PPP
2374 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2377 isdn_net_lp_disconnected(lp);
2378 isdn_free_channel(lp->isdn_device, lp->isdn_channel,
2381 spin_lock_irqsave(&dev->lock, flags);
2382 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2383 dev->usage[idx] |= ISDN_USAGE_NET;
2384 strcpy(dev->num[idx], nr);
2386 dev->st_netdev[idx] = lp->netdev;
2387 lp->isdn_device = di;
2388 lp->isdn_channel = ch;
2390 lp->flags |= ISDN_NET_CONNECTED;
2395 lp->hupflags |= ISDN_WAITCHARGE;
2396 lp->hupflags &= ~ISDN_HAVECHARGE;
2397 #ifdef CONFIG_ISDN_PPP
2398 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
2399 if (isdn_ppp_bind(lp) < 0) {
2400 isdn_net_unbind_channel(lp);
2401 spin_unlock_irqrestore(&dev->lock, flags);
2406 spin_unlock_irqrestore(&dev->lock, flags);
2411 p = (isdn_net_dev *) p->next;
2413 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2414 if (!ematch || dev->net_verbose)
2415 printk(KERN_INFO "isdn_net: call from %s -> %d %s ignored\n", nr, di, eaz);
2416 return (wret == 2)?5:0;
2420 * Search list of net-interfaces for an interface with given name.
2423 isdn_net_findif(char *name)
2425 isdn_net_dev *p = dev->netdev;
2428 if (!strcmp(p->dev->name, name))
2430 p = (isdn_net_dev *) p->next;
2432 return (isdn_net_dev *) NULL;
2436 * Force a net-interface to dial out.
2437 * This is called from the userlevel-routine below or
2438 * from isdn_net_start_xmit().
2441 isdn_net_force_dial_lp(isdn_net_local * lp)
2443 if ((!(lp->flags & ISDN_NET_CONNECTED)) && !lp->dialstate) {
2448 /* Grab a free ISDN-Channel */
2449 spin_lock_irqsave(&dev->lock, flags);
2450 if ((chi = isdn_get_free_channel(
2457 printk(KERN_WARNING "isdn_net_force_dial: No channel for %s\n",
2458 lp->netdev->dev->name);
2459 spin_unlock_irqrestore(&dev->lock, flags);
2463 /* Connect interface with channel */
2464 isdn_net_bind_channel(lp, chi);
2465 #ifdef CONFIG_ISDN_PPP
2466 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2467 if (isdn_ppp_bind(lp) < 0) {
2468 isdn_net_unbind_channel(lp);
2469 spin_unlock_irqrestore(&dev->lock, flags);
2473 /* Initiate dialing */
2474 spin_unlock_irqrestore(&dev->lock, flags);
2484 * This is called from certain upper protocol layers (multilink ppp
2485 * and x25iface encapsulation module) that want to initiate dialing
2489 isdn_net_dial_req(isdn_net_local * lp)
2491 /* is there a better error code? */
2492 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) return -EBUSY;
2494 return isdn_net_force_dial_lp(lp);
2498 * Force a net-interface to dial out.
2499 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2502 isdn_net_force_dial(char *name)
2504 isdn_net_dev *p = isdn_net_findif(name);
2508 return (isdn_net_force_dial_lp(p->local));
2512 * Helper for alloc_netdev()
2514 static void _isdn_setup(struct net_device *dev)
2516 isdn_net_local *lp = netdev_priv(dev);
2518 dev->flags = IFF_NOARP | IFF_POINTOPOINT;
2519 lp->p_encap = ISDN_NET_ENCAP_RAWIP;
2520 lp->magic = ISDN_NET_MAGIC;
2523 lp->isdn_device = -1;
2524 lp->isdn_channel = -1;
2525 lp->pre_device = -1;
2526 lp->pre_channel = -1;
2530 skb_queue_head_init(&lp->super_tx_queue);
2531 lp->l2_proto = ISDN_PROTO_L2_X75I;
2532 lp->l3_proto = ISDN_PROTO_L3_TRANS;
2533 lp->triggercps = 6000;
2534 lp->slavedelay = 10 * HZ;
2535 lp->hupflags = ISDN_INHUP; /* Do hangup even on incoming calls */
2536 lp->onhtime = 10; /* Default hangup-time for saving costs */
2538 /* Hangup before Callback, manual dial */
2539 lp->flags = ISDN_NET_CBHUP | ISDN_NET_DM_MANUAL;
2540 lp->cbdelay = 25; /* Wait 5 secs before Callback */
2541 lp->dialtimeout = -1; /* Infinite Dial-Timeout */
2542 lp->dialwait = 5 * HZ; /* Wait 5 sec. after failed dial */
2543 lp->dialstarted = 0; /* Jiffies of last dial-start */
2544 lp->dialwait_timer = 0; /* Jiffies of earliest next dial-start */
2548 * Allocate a new network-interface and initialize its data structures.
2551 isdn_net_new(char *name, struct net_device *master)
2553 isdn_net_dev *netdev;
2555 /* Avoid creating an existing interface */
2556 if (isdn_net_findif(name)) {
2557 printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
2562 if (!(netdev = kzalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
2563 printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
2566 netdev->dev = alloc_netdev(sizeof(isdn_net_local), name, _isdn_setup);
2568 printk(KERN_WARNING "isdn_net: Could not allocate network device\n");
2572 netdev->local = netdev_priv(netdev->dev);
2573 netdev->dev->init = isdn_net_init;
2575 /* Device shall be a slave */
2576 struct net_device *p = MASTER_TO_SLAVE(master);
2577 struct net_device *q = master;
2579 netdev->local->master = master;
2580 /* Put device at end of slave-chain */
2583 p = MASTER_TO_SLAVE(p);
2585 MASTER_TO_SLAVE(q) = netdev->dev;
2587 /* Device shall be a master */
2589 * Watchdog timer (currently) for master only.
2591 netdev->dev->tx_timeout = isdn_net_tx_timeout;
2592 netdev->dev->watchdog_timeo = ISDN_NET_TX_TIMEOUT;
2593 if (register_netdev(netdev->dev) != 0) {
2594 printk(KERN_WARNING "isdn_net: Could not register net-device\n");
2595 free_netdev(netdev->dev);
2600 netdev->queue = netdev->local;
2601 spin_lock_init(&netdev->queue_lock);
2603 netdev->local->netdev = netdev;
2605 INIT_WORK(&netdev->local->tqueue, isdn_net_softint);
2606 spin_lock_init(&netdev->local->xmit_lock);
2608 /* Put into to netdev-chain */
2609 netdev->next = (void *) dev->netdev;
2610 dev->netdev = netdev;
2611 return netdev->dev->name;
2615 isdn_net_newslave(char *parm)
2617 char *p = strchr(parm, ',');
2622 /* Slave-Name MUST not be empty */
2625 strcpy(newname, p + 1);
2627 /* Master must already exist */
2628 if (!(n = isdn_net_findif(parm)))
2630 /* Master must be a real interface, not a slave */
2631 if (n->local->master)
2633 /* Master must not be started yet */
2634 if (isdn_net_device_started(n))
2636 return (isdn_net_new(newname, n->dev));
2642 * Set interface-parameters.
2643 * Always set all parameters, so the user-level application is responsible
2644 * for not overwriting existing setups. It has to get the current
2645 * setup first, if only selected parameters are to be changed.
2648 isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
2650 isdn_net_dev *p = isdn_net_findif(cfg->name);
2658 isdn_net_local *lp = p->local;
2660 /* See if any registered driver supports the features we want */
2661 features = ((1 << cfg->l2_proto) << ISDN_FEATURE_L2_SHIFT) |
2662 ((1 << cfg->l3_proto) << ISDN_FEATURE_L3_SHIFT);
2663 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2665 if ((dev->drv[i]->interface->features & features) == features)
2667 if (i == ISDN_MAX_DRIVERS) {
2668 printk(KERN_WARNING "isdn_net: No driver with selected features\n");
2671 if (lp->p_encap != cfg->p_encap){
2672 #ifdef CONFIG_ISDN_X25
2673 struct concap_proto * cprot = p -> cprot;
2675 if (isdn_net_device_started(p)) {
2676 printk(KERN_WARNING "%s: cannot change encap when if is up\n",
2680 #ifdef CONFIG_ISDN_X25
2681 if( cprot && cprot -> pops )
2682 cprot -> pops -> proto_del ( cprot );
2685 /* ... , prepare for configuration of new one ... */
2686 switch ( cfg -> p_encap ){
2687 case ISDN_NET_ENCAP_X25IFACE:
2688 lp -> dops = &isdn_concap_reliable_dl_dops;
2690 /* ... and allocate new one ... */
2691 p -> cprot = isdn_concap_new( cfg -> p_encap );
2692 /* p -> cprot == NULL now if p_encap is not supported
2693 by means of the concap_proto mechanism */
2694 /* the protocol is not configured yet; this will
2695 happen later when isdn_net_reset() is called */
2698 switch ( cfg->p_encap ) {
2699 case ISDN_NET_ENCAP_SYNCPPP:
2700 #ifndef CONFIG_ISDN_PPP
2701 printk(KERN_WARNING "%s: SyncPPP support not configured\n",
2705 p->dev->type = ARPHRD_PPP; /* change ARP type */
2706 p->dev->addr_len = 0;
2707 p->dev->do_ioctl = isdn_ppp_dev_ioctl;
2710 case ISDN_NET_ENCAP_X25IFACE:
2711 #ifndef CONFIG_ISDN_X25
2712 printk(KERN_WARNING "%s: isdn-x25 support not configured\n",
2716 p->dev->type = ARPHRD_X25; /* change ARP type */
2717 p->dev->addr_len = 0;
2720 case ISDN_NET_ENCAP_CISCOHDLCK:
2721 p->dev->do_ioctl = isdn_ciscohdlck_dev_ioctl;
2724 if( cfg->p_encap >= 0 &&
2725 cfg->p_encap <= ISDN_NET_ENCAP_MAX_ENCAP )
2728 "%s: encapsulation protocol %d not supported\n",
2729 p->dev->name, cfg->p_encap);
2732 if (strlen(cfg->drvid)) {
2733 /* A bind has been requested ... */
2739 strcpy(drvid, cfg->drvid);
2740 if ((c = strchr(drvid, ','))) {
2741 /* The channel-number is appended to the driver-Id with a comma */
2742 chidx = (int) simple_strtoul(c + 1, &e, 10);
2747 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2748 /* Lookup driver-Id in array */
2749 if (!(strcmp(dev->drvid[i], drvid))) {
2753 if ((drvidx == -1) || (chidx == -1))
2754 /* Either driver-Id or channel-number invalid */
2757 /* Parameters are valid, so get them */
2758 drvidx = lp->pre_device;
2759 chidx = lp->pre_channel;
2761 if (cfg->exclusive > 0) {
2762 unsigned long flags;
2764 /* If binding is exclusive, try to grab the channel */
2765 spin_lock_irqsave(&dev->lock, flags);
2766 if ((i = isdn_get_free_channel(ISDN_USAGE_NET,
2767 lp->l2_proto, lp->l3_proto, drvidx,
2768 chidx, lp->msn)) < 0) {
2769 /* Grab failed, because desired channel is in use */
2771 spin_unlock_irqrestore(&dev->lock, flags);
2774 /* All went ok, so update isdninfo */
2775 dev->usage[i] = ISDN_USAGE_EXCLUSIVE;
2777 spin_unlock_irqrestore(&dev->lock, flags);
2780 /* Non-exclusive binding or unbind. */
2782 if ((lp->pre_device != -1) && (cfg->exclusive == -1)) {
2783 isdn_unexclusive_channel(lp->pre_device, lp->pre_channel);
2784 isdn_free_channel(lp->pre_device, lp->pre_channel, ISDN_USAGE_NET);
2789 strlcpy(lp->msn, cfg->eaz, sizeof(lp->msn));
2790 lp->pre_device = drvidx;
2791 lp->pre_channel = chidx;
2792 lp->onhtime = cfg->onhtime;
2793 lp->charge = cfg->charge;
2794 lp->l2_proto = cfg->l2_proto;
2795 lp->l3_proto = cfg->l3_proto;
2796 lp->cbdelay = cfg->cbdelay;
2797 lp->dialmax = cfg->dialmax;
2798 lp->triggercps = cfg->triggercps;
2799 lp->slavedelay = cfg->slavedelay * HZ;
2800 lp->pppbind = cfg->pppbind;
2801 lp->dialtimeout = cfg->dialtimeout >= 0 ? cfg->dialtimeout * HZ : -1;
2802 lp->dialwait = cfg->dialwait * HZ;
2804 lp->flags |= ISDN_NET_SECURE;
2806 lp->flags &= ~ISDN_NET_SECURE;
2808 lp->flags |= ISDN_NET_CBHUP;
2810 lp->flags &= ~ISDN_NET_CBHUP;
2811 switch (cfg->callback) {
2813 lp->flags &= ~(ISDN_NET_CALLBACK | ISDN_NET_CBOUT);
2816 lp->flags |= ISDN_NET_CALLBACK;
2817 lp->flags &= ~ISDN_NET_CBOUT;
2820 lp->flags |= ISDN_NET_CBOUT;
2821 lp->flags &= ~ISDN_NET_CALLBACK;
2824 lp->flags &= ~ISDN_NET_DIALMODE_MASK; /* first all bits off */
2825 if (cfg->dialmode && !(cfg->dialmode & ISDN_NET_DIALMODE_MASK)) {
2826 /* old isdnctrl version, where only 0 or 1 is given */
2828 "Old isdnctrl version detected! Please update.\n");
2829 lp->flags |= ISDN_NET_DM_OFF; /* turn on `off' bit */
2832 lp->flags |= cfg->dialmode; /* turn on selected bits */
2835 lp->hupflags |= ISDN_CHARGEHUP;
2837 lp->hupflags &= ~ISDN_CHARGEHUP;
2839 lp->hupflags |= ISDN_INHUP;
2841 lp->hupflags &= ~ISDN_INHUP;
2842 if (cfg->chargeint > 10) {
2843 lp->hupflags |= ISDN_CHARGEHUP | ISDN_HAVECHARGE | ISDN_MANCHARGE;
2844 lp->chargeint = cfg->chargeint * HZ;
2846 if (cfg->p_encap != lp->p_encap) {
2847 if (cfg->p_encap == ISDN_NET_ENCAP_RAWIP) {
2848 p->dev->header_ops = NULL;
2849 p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
2851 p->dev->header_ops = &isdn_header_ops;
2852 if (cfg->p_encap == ISDN_NET_ENCAP_ETHER)
2853 p->dev->flags = IFF_BROADCAST | IFF_MULTICAST;
2855 p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
2858 lp->p_encap = cfg->p_encap;
2865 * Perform get-interface-parameters.ioctl
2868 isdn_net_getcfg(isdn_net_ioctl_cfg * cfg)
2870 isdn_net_dev *p = isdn_net_findif(cfg->name);
2873 isdn_net_local *lp = p->local;
2875 strcpy(cfg->eaz, lp->msn);
2876 cfg->exclusive = lp->exclusive;
2877 if (lp->pre_device >= 0) {
2878 sprintf(cfg->drvid, "%s,%d", dev->drvid[lp->pre_device],
2881 cfg->drvid[0] = '\0';
2882 cfg->onhtime = lp->onhtime;
2883 cfg->charge = lp->charge;
2884 cfg->l2_proto = lp->l2_proto;
2885 cfg->l3_proto = lp->l3_proto;
2886 cfg->p_encap = lp->p_encap;
2887 cfg->secure = (lp->flags & ISDN_NET_SECURE) ? 1 : 0;
2889 if (lp->flags & ISDN_NET_CALLBACK)
2891 if (lp->flags & ISDN_NET_CBOUT)
2893 cfg->cbhup = (lp->flags & ISDN_NET_CBHUP) ? 1 : 0;
2894 cfg->dialmode = lp->flags & ISDN_NET_DIALMODE_MASK;
2895 cfg->chargehup = (lp->hupflags & 4) ? 1 : 0;
2896 cfg->ihup = (lp->hupflags & 8) ? 1 : 0;
2897 cfg->cbdelay = lp->cbdelay;
2898 cfg->dialmax = lp->dialmax;
2899 cfg->triggercps = lp->triggercps;
2900 cfg->slavedelay = lp->slavedelay / HZ;
2901 cfg->chargeint = (lp->hupflags & ISDN_CHARGEHUP) ?
2902 (lp->chargeint / HZ) : 0;
2903 cfg->pppbind = lp->pppbind;
2904 cfg->dialtimeout = lp->dialtimeout >= 0 ? lp->dialtimeout / HZ : -1;
2905 cfg->dialwait = lp->dialwait / HZ;
2907 if (strlen(lp->slave->name) > 8)
2908 strcpy(cfg->slave, "too-long");
2910 strcpy(cfg->slave, lp->slave->name);
2912 cfg->slave[0] = '\0';
2914 if (strlen(lp->master->name) > 8)
2915 strcpy(cfg->master, "too-long");
2916 strcpy(cfg->master, lp->master->name);
2918 cfg->master[0] = '\0';
2925 * Add a phone-number to an interface.
2928 isdn_net_addphone(isdn_net_ioctl_phone * phone)
2930 isdn_net_dev *p = isdn_net_findif(phone->name);
2934 if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
2936 strlcpy(n->num, phone->phone, sizeof(n->num));
2937 n->next = p->local->phone[phone->outgoing & 1];
2938 p->local->phone[phone->outgoing & 1] = n;
2945 * Copy a string of all phone-numbers of an interface to user space.
2946 * This might sleep and must be called with the isdn semaphore down.
2949 isdn_net_getphones(isdn_net_ioctl_phone * phone, char __user *phones)
2951 isdn_net_dev *p = isdn_net_findif(phone->name);
2952 int inout = phone->outgoing & 1;
2960 for (n = p->local->phone[inout]; n; n = n->next) {
2962 put_user(' ', phones++);
2965 if (copy_to_user(phones, n->num, strlen(n->num) + 1)) {
2968 phones += strlen(n->num);
2969 count += strlen(n->num);
2972 put_user(0, phones);
2978 * Copy a string containing the peer's phone number of a connected interface
2982 isdn_net_getpeer(isdn_net_ioctl_phone *phone, isdn_net_ioctl_phone __user *peer)
2984 isdn_net_dev *p = isdn_net_findif(phone->name);
2990 * Theoretical race: while this executes, the remote number might
2991 * become invalid (hang up) or change (new connection), resulting
2992 * in (partially) wrong number copied to user. This race
2993 * currently ignored.
2995 ch = p->local->isdn_channel;
2996 dv = p->local->isdn_device;
2997 if(ch < 0 && dv < 0)
2999 idx = isdn_dc2minor(dv, ch);
3002 /* for pre-bound channels, we need this extra check */
3003 if (strncmp(dev->num[idx], "???", 3) == 0)
3005 strncpy(phone->phone, dev->num[idx], ISDN_MSNLEN);
3006 phone->outgoing = USG_OUTGOING(dev->usage[idx]);
3007 if (copy_to_user(peer, phone, sizeof(*peer)))
3012 * Delete a phone-number from an interface.
3015 isdn_net_delphone(isdn_net_ioctl_phone * phone)
3017 isdn_net_dev *p = isdn_net_findif(phone->name);
3018 int inout = phone->outgoing & 1;
3023 n = p->local->phone[inout];
3026 if (!strcmp(n->num, phone->phone)) {
3027 if (p->local->dial == n)
3028 p->local->dial = n->next;
3032 p->local->phone[inout] = n->next;
3037 n = (isdn_net_phone *) n->next;
3045 * Delete all phone-numbers of an interface.
3048 isdn_net_rmallphone(isdn_net_dev * p)
3054 for (i = 0; i < 2; i++) {
3055 n = p->local->phone[i];
3061 p->local->phone[i] = NULL;
3063 p->local->dial = NULL;
3068 * Force a hangup of a network-interface.
3071 isdn_net_force_hangup(char *name)
3073 isdn_net_dev *p = isdn_net_findif(name);
3074 struct net_device *q;
3077 if (p->local->isdn_device < 0)
3079 q = p->local->slave;
3080 /* If this interface has slaves, do a hangup for them also. */
3083 q = MASTER_TO_SLAVE(q);
3085 isdn_net_hangup(p->dev);
3092 * Helper-function for isdn_net_rm: Do the real work.
3095 isdn_net_realrm(isdn_net_dev * p, isdn_net_dev * q)
3099 if (isdn_net_device_started(p)) {
3102 #ifdef CONFIG_ISDN_X25
3103 if( p -> cprot && p -> cprot -> pops )
3104 p -> cprot -> pops -> proto_del ( p -> cprot );
3106 /* Free all phone-entries */
3107 isdn_net_rmallphone(p);
3108 /* If interface is bound exclusive, free channel-usage */
3109 if (p->local->exclusive != -1)
3110 isdn_unexclusive_channel(p->local->pre_device, p->local->pre_channel);
3111 if (p->local->master) {
3112 /* It's a slave-device, so update master's slave-pointer if necessary */
3113 if (((isdn_net_local *) ISDN_MASTER_PRIV(p->local))->slave ==
3115 ((isdn_net_local *)ISDN_MASTER_PRIV(p->local))->slave =
3118 /* Unregister only if it's a master-device */
3119 unregister_netdev(p->dev);
3121 /* Unlink device from chain */
3122 spin_lock_irqsave(&dev->lock, flags);
3126 dev->netdev = p->next;
3127 if (p->local->slave) {
3128 /* If this interface has a slave, remove it also */
3129 char *slavename = p->local->slave->name;
3130 isdn_net_dev *n = dev->netdev;
3133 if (!strcmp(n->dev->name, slavename)) {
3134 spin_unlock_irqrestore(&dev->lock, flags);
3135 isdn_net_realrm(n, q);
3136 spin_lock_irqsave(&dev->lock, flags);
3140 n = (isdn_net_dev *)n->next;
3143 spin_unlock_irqrestore(&dev->lock, flags);
3144 /* If no more net-devices remain, disable auto-hangup timer */
3145 if (dev->netdev == NULL)
3146 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
3147 free_netdev(p->dev);
3154 * Remove a single network-interface.
3157 isdn_net_rm(char *name)
3163 /* Search name in netdev-chain */
3164 spin_lock_irqsave(&dev->lock, flags);
3168 if (!strcmp(p->dev->name, name)) {
3169 spin_unlock_irqrestore(&dev->lock, flags);
3170 return (isdn_net_realrm(p, q));
3173 p = (isdn_net_dev *) p->next;
3175 spin_unlock_irqrestore(&dev->lock, flags);
3176 /* If no more net-devices remain, disable auto-hangup timer */
3177 if (dev->netdev == NULL)
3178 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
3183 * Remove all network-interfaces
3186 isdn_net_rmall(void)
3191 /* Walk through netdev-chain */
3192 spin_lock_irqsave(&dev->lock, flags);
3193 while (dev->netdev) {
3194 if (!dev->netdev->local->master) {
3195 /* Remove master-devices only, slaves get removed with their master */
3196 spin_unlock_irqrestore(&dev->lock, flags);
3197 if ((ret = isdn_net_realrm(dev->netdev, NULL))) {
3200 spin_lock_irqsave(&dev->lock, flags);
3204 spin_unlock_irqrestore(&dev->lock, flags);