Linux 2.4.0-test7-pre6
[davej-history.git] / drivers / isdn / isdn_net.c
blobd33fb513558c3d97098f1f4cfce749d2de5e68ef
1 /* $Id: isdn_net.c,v 1.135 2000/08/10 22:52:46 kai 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 program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/config.h>
26 #define __NO_VERSION__
27 #include <linux/module.h>
28 #include <linux/isdn.h>
29 #include <net/arp.h>
30 #include <net/dst.h>
31 #include <net/pkt_sched.h>
32 #include <linux/inetdevice.h>
33 #include "isdn_common.h"
34 #include "isdn_net.h"
35 #ifdef CONFIG_ISDN_PPP
36 #include "isdn_ppp.h"
37 #endif
38 #ifdef CONFIG_ISDN_X25
39 #include <linux/concap.h>
40 #include "isdn_concap.h"
41 #endif
45 * Outline of new tbusy handling:
47 * Old method, roughly spoken, consisted of setting tbusy when entering
48 * isdn_net_start_xmit() and at several other locations and clearing
49 * it from isdn_net_start_xmit() thread when sending was successful.
51 * With 2.3.x multithreaded network core, to prevent problems, tbusy should
52 * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
53 * condition is detected. Other threads (in particular isdn_net_stat_callb())
54 * are only allowed to clear tbusy.
56 * -HE
60 * About SOFTNET:
61 * Most of the changes were pretty obvious and basically done by HE already.
63 * One problem of the isdn net device code is that is uses struct net_device
64 * for masters and slaves. However, only master interface are registered to
65 * the network layer, and therefore, it only makes sense to call netif_*
66 * functions on them.
68 * --KG
71 /*
72 * Find out if the netdevice has been ifup-ed yet.
73 * For slaves, look at the corresponding master.
75 static __inline__ int isdn_net_device_started(isdn_net_dev *n)
77 isdn_net_local *lp = n->local;
78 struct net_device *dev;
80 if (lp->master)
81 dev = lp->master;
82 else
83 dev = &n->dev;
84 return netif_running(dev);
88 * wake up the network -> net_device queue.
89 * For slaves, wake the corresponding master interface.
91 static __inline__ void isdn_net_device_wake_queue(isdn_net_local *lp)
93 if (lp->master)
94 netif_wake_queue(lp->master);
95 else
96 netif_wake_queue(&lp->netdev->dev);
100 * stop the network -> net_device queue.
101 * For slaves, stop the corresponding master interface.
103 static __inline__ void isdn_net_device_stop_queue(isdn_net_local *lp)
105 if (lp->master)
106 netif_stop_queue(lp->master);
107 else
108 netif_stop_queue(&lp->netdev->dev);
112 * find out if the net_device which this lp belongs to (lp can be
113 * master or slave) is busy. It's busy iff all (master and slave)
114 * queues are busy
116 static __inline__ int isdn_net_device_busy(isdn_net_local *lp)
118 isdn_net_local *nlp;
119 isdn_net_dev *nd;
120 unsigned long flags;
122 if (!isdn_net_lp_busy(lp))
123 return 0;
125 if (lp->master)
126 nd = ((isdn_net_local *) lp->master->priv)->netdev;
127 else
128 nd = lp->netdev;
130 spin_lock_irqsave(&nd->queue_lock, flags);
131 nlp = lp->next;
132 while (nlp != lp) {
133 if (!isdn_net_lp_busy(nlp)) {
134 spin_unlock_irqrestore(&nd->queue_lock, flags);
135 return 0;
137 nlp = nlp->next;
139 spin_unlock_irqrestore(&nd->queue_lock, flags);
140 return 1;
143 static __inline__ void isdn_net_inc_frame_cnt(isdn_net_local *lp)
145 atomic_inc(&lp->frame_cnt);
146 if (isdn_net_device_busy(lp))
147 isdn_net_device_stop_queue(lp);
150 static __inline__ void isdn_net_dec_frame_cnt(isdn_net_local *lp)
152 atomic_dec(&lp->frame_cnt);
154 if (!(isdn_net_device_busy(lp))) {
155 if (!skb_queue_empty(&lp->super_tx_queue)) {
156 queue_task(&lp->tqueue, &tq_immediate);
157 } else {
158 isdn_net_device_wake_queue(lp);
163 static __inline__ void isdn_net_zero_frame_cnt(isdn_net_local *lp)
165 atomic_set(&lp->frame_cnt, 0);
168 /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
169 * to be safe.
170 * For 2.3.x we push it up to 20 secs, because call establishment
171 * (in particular callback) may take such a long time, and we
172 * don't want confusing messages in the log. However, there is a slight
173 * possibility that this large timeout will break other things like MPPP,
174 * which might rely on the tx timeout. If so, we'll find out this way...
177 #define ISDN_NET_TX_TIMEOUT (20*HZ)
179 /* Prototypes */
181 int isdn_net_force_dial_lp(isdn_net_local *);
182 static int isdn_net_start_xmit(struct sk_buff *, struct net_device *);
184 char *isdn_net_revision = "$Revision: 1.135 $";
187 * Code for raw-networking over ISDN
190 static void
191 isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason)
194 if(skb) {
196 u_short proto = ntohs(skb->protocol);
198 printk(KERN_DEBUG "isdn_net: %s: %s, signalling dst_link_failure %s\n",
199 dev->name,
200 (reason != NULL) ? reason : "unknown",
201 (proto != ETH_P_IP) ? "Protocol != ETH_P_IP" : "");
203 dst_link_failure(skb);
205 else { /* dial not triggered by rawIP packet */
206 printk(KERN_DEBUG "isdn_net: %s: %s\n",
207 dev->name,
208 (reason != NULL) ? reason : "reason unknown");
212 static void
213 isdn_net_reset(struct net_device *dev)
215 #ifdef CONFIG_ISDN_X25
216 struct concap_device_ops * dops =
217 ( (isdn_net_local *) dev->priv ) -> dops;
218 struct concap_proto * cprot =
219 ( (isdn_net_local *) dev->priv ) -> netdev -> cprot;
220 #endif
221 ulong flags;
223 /* not sure if the cli() is needed at all --KG */
224 save_flags(flags);
225 cli(); /* Avoid glitch on writes to CMD regs */
226 #ifdef CONFIG_ISDN_X25
227 if( cprot && cprot -> pops && dops )
228 cprot -> pops -> restart ( cprot, dev, dops );
229 #endif
230 restore_flags(flags);
233 /* Open/initialize the board. */
234 static int
235 isdn_net_open(struct net_device *dev)
237 int i;
238 struct net_device *p;
239 struct in_device *in_dev;
241 /* moved here from isdn_net_reset, because only the master has an
242 interface associated which is supposed to be started. BTW:
243 we need to call netif_start_queue, not netif_wake_queue here */
244 netif_start_queue(dev);
246 isdn_net_reset(dev);
247 /* Fill in the MAC-level header (not needed, but for compatibility... */
248 for (i = 0; i < ETH_ALEN - sizeof(u32); i++)
249 dev->dev_addr[i] = 0xfc;
250 if ((in_dev = dev->ip_ptr) != NULL) {
252 * Any address will do - we take the first
254 struct in_ifaddr *ifa = in_dev->ifa_list;
255 if (ifa != NULL)
256 memcpy(dev->dev_addr+2, &ifa->ifa_local, 4);
259 /* If this interface has slaves, start them also */
261 if ((p = (((isdn_net_local *) dev->priv)->slave))) {
262 while (p) {
263 isdn_net_reset(p);
264 p = (((isdn_net_local *) p->priv)->slave);
267 isdn_MOD_INC_USE_COUNT();
268 return 0;
272 * Assign an ISDN-channel to a net-interface
274 static void
275 isdn_net_bind_channel(isdn_net_local * lp, int idx)
277 ulong flags;
279 save_flags(flags);
280 cli();
281 lp->flags |= ISDN_NET_CONNECTED;
282 lp->isdn_device = dev->drvmap[idx];
283 lp->isdn_channel = dev->chanmap[idx];
284 dev->rx_netdev[idx] = lp->netdev;
285 dev->st_netdev[idx] = lp->netdev;
286 restore_flags(flags);
290 * unbind a net-interface (resets interface after an error)
292 static void
293 isdn_net_unbind_channel(isdn_net_local * lp)
295 ulong flags;
296 struct sk_buff *skb;
298 save_flags(flags);
299 cli();
300 while ((skb = skb_dequeue(&lp->super_tx_queue))) {
301 kfree_skb(skb);
303 if (!lp->master) { /* reset only master device */
304 /* Moral equivalent of dev_purge_queues():
305 BEWARE! This chunk of code cannot be called from hardware
306 interrupt handler. I hope it is true. --ANK
308 qdisc_reset(lp->netdev->dev.qdisc);
310 lp->dialstate = 0;
311 dev->rx_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
312 dev->st_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
313 isdn_free_channel(lp->isdn_device, lp->isdn_channel, ISDN_USAGE_NET);
314 lp->flags &= ~ISDN_NET_CONNECTED;
315 lp->isdn_device = -1;
316 lp->isdn_channel = -1;
318 restore_flags(flags);
322 * Perform auto-hangup and cps-calculation for net-interfaces.
324 * auto-hangup:
325 * Increment idle-counter (this counter is reset on any incoming or
326 * outgoing packet), if counter exceeds configured limit either do a
327 * hangup immediately or - if configured - wait until just before the next
328 * charge-info.
330 * cps-calculation (needed for dynamic channel-bundling):
331 * Since this function is called every second, simply reset the
332 * byte-counter of the interface after copying it to the cps-variable.
334 unsigned long last_jiffies = -HZ;
336 void
337 isdn_net_autohup()
339 isdn_net_dev *p = dev->netdev;
340 int anymore;
342 anymore = 0;
343 while (p) {
344 isdn_net_local *l = p->local;
345 if ((jiffies - last_jiffies) == 0)
346 l->cps = l->transcount;
347 else
348 l->cps = (l->transcount * HZ) / (jiffies - last_jiffies);
349 l->transcount = 0;
350 if (dev->net_verbose > 3)
351 printk(KERN_DEBUG "%s: %d bogocps\n", l->name, l->cps);
352 if ((l->flags & ISDN_NET_CONNECTED) && (!l->dialstate)) {
353 anymore = 1;
354 l->huptimer++;
356 * if there is some dialmode where timeout-hangup
357 * should _not_ be done, check for that here
359 if ((l->onhtime) &&
360 (l->huptimer > l->onhtime))
362 if (l->hupflags & ISDN_MANCHARGE &&
363 l->hupflags & ISDN_CHARGEHUP) {
364 while (jiffies - l->chargetime > l->chargeint)
365 l->chargetime += l->chargeint;
366 if (jiffies - l->chargetime >= l->chargeint - 2 * HZ)
367 if (l->outgoing || l->hupflags & ISDN_INHUP)
368 isdn_net_hangup(&p->dev);
369 } else if (l->outgoing) {
370 if (l->hupflags & ISDN_CHARGEHUP) {
371 if (l->hupflags & ISDN_WAITCHARGE) {
372 printk(KERN_DEBUG "isdn_net: Hupflags of %s are %X\n",
373 l->name, l->hupflags);
374 isdn_net_hangup(&p->dev);
375 } else if (jiffies - l->chargetime > l->chargeint) {
376 printk(KERN_DEBUG
377 "isdn_net: %s: chtime = %lu, chint = %d\n",
378 l->name, l->chargetime, l->chargeint);
379 isdn_net_hangup(&p->dev);
381 } else
382 isdn_net_hangup(&p->dev);
383 } else if (l->hupflags & ISDN_INHUP)
384 isdn_net_hangup(&p->dev);
387 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*l) == ISDN_NET_DM_OFF)) {
388 isdn_net_hangup(&p->dev);
389 break;
392 p = (isdn_net_dev *) p->next;
394 last_jiffies = jiffies;
395 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, anymore);
398 static void isdn_net_lp_disconnected(isdn_net_local *lp)
400 isdn_net_rm_from_bundle(lp);
404 * Handle status-messages from ISDN-interfacecard.
405 * This function is called from within the main-status-dispatcher
406 * isdn_status_callback, which itself is called from the low-level driver.
407 * Return: 1 = Event handled, 0 = not for us or unknown Event.
410 isdn_net_stat_callback(int idx, isdn_ctrl *c)
412 isdn_net_dev *p = dev->st_netdev[idx];
413 int cmd = c->command;
415 if (p) {
416 isdn_net_local *lp = p->local;
417 #ifdef CONFIG_ISDN_X25
418 struct concap_proto *cprot = lp -> netdev -> cprot;
419 struct concap_proto_ops *pops = cprot ? cprot -> pops : 0;
420 #endif
421 switch (cmd) {
422 case ISDN_STAT_BSENT:
423 /* A packet has successfully been sent out */
424 if ((lp->flags & ISDN_NET_CONNECTED) &&
425 (!lp->dialstate)) {
426 isdn_net_dec_frame_cnt(lp);
427 lp->stats.tx_packets++;
428 lp->stats.tx_bytes += c->parm.length;
430 return 1;
431 case ISDN_STAT_DCONN:
432 /* D-Channel is up */
433 switch (lp->dialstate) {
434 case 4:
435 case 7:
436 case 8:
437 lp->dialstate++;
438 return 1;
439 case 12:
440 lp->dialstate = 5;
441 return 1;
443 break;
444 case ISDN_STAT_DHUP:
445 /* Either D-Channel-hangup or error during dialout */
446 #ifdef CONFIG_ISDN_X25
447 /* If we are not connencted then dialing had
448 failed. If there are generic encap protocol
449 receiver routines signal the closure of
450 the link*/
452 if( !(lp->flags & ISDN_NET_CONNECTED)
453 && pops && pops -> disconn_ind )
454 pops -> disconn_ind(cprot);
455 #endif /* CONFIG_ISDN_X25 */
456 if ((!lp->dialstate) && (lp->flags & ISDN_NET_CONNECTED)) {
457 #ifdef CONFIG_ISDN_PPP
458 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
459 isdn_ppp_free(lp);
460 #endif
461 isdn_net_lp_disconnected(lp);
462 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
463 printk(KERN_INFO "%s: remote hangup\n", lp->name);
464 printk(KERN_INFO "%s: Chargesum is %d\n", lp->name,
465 lp->charge);
466 isdn_net_unbind_channel(lp);
467 return 1;
469 break;
470 #ifdef CONFIG_ISDN_X25
471 case ISDN_STAT_BHUP:
472 /* B-Channel-hangup */
473 /* try if there are generic encap protocol
474 receiver routines and signal the closure of
475 the link */
476 if( pops && pops -> disconn_ind ){
477 pops -> disconn_ind(cprot);
478 return 1;
480 break;
481 #endif /* CONFIG_ISDN_X25 */
482 case ISDN_STAT_BCONN:
483 /* B-Channel is up */
484 isdn_net_zero_frame_cnt(lp);
485 switch (lp->dialstate) {
486 case 5:
487 case 6:
488 case 7:
489 case 8:
490 case 9:
491 case 10:
492 case 12:
493 if (lp->dialstate <= 6) {
494 dev->usage[idx] |= ISDN_USAGE_OUTGOING;
495 isdn_info_update();
496 } else
497 dev->rx_netdev[idx] = p;
498 lp->dialstate = 0;
499 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 1);
500 if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
501 isdn_timer_ctrl(ISDN_TIMER_KEEPALIVE, 1);
502 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP) {
503 if (lp->master) { /* is lp a slave? */
504 isdn_net_dev *nd = ((isdn_net_local *)lp->master->priv)->netdev;
505 isdn_net_add_to_bundle(nd, lp);
508 printk(KERN_INFO "isdn_net: %s connected\n", lp->name);
509 /* If first Chargeinfo comes before B-Channel connect,
510 * we correct the timestamp here.
512 lp->chargetime = jiffies;
514 /* reset dial-timeout */
515 lp->dialstarted = 0;
516 lp->dialwait_timer = 0;
518 #ifdef CONFIG_ISDN_PPP
519 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
520 isdn_ppp_wakeup_daemon(lp);
521 #endif
522 #ifdef CONFIG_ISDN_X25
523 /* try if there are generic concap receiver routines */
524 if( pops )
525 if( pops->connect_ind)
526 pops->connect_ind(cprot);
527 #endif /* CONFIG_ISDN_X25 */
528 /* ppp needs to do negotiations first */
529 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
530 isdn_net_device_wake_queue(lp);
531 return 1;
533 break;
534 case ISDN_STAT_NODCH:
535 /* No D-Channel avail. */
536 if (lp->dialstate == 4) {
537 lp->dialstate--;
538 return 1;
540 break;
541 case ISDN_STAT_CINF:
542 /* Charge-info from TelCo. Calculate interval between
543 * charge-infos and set timestamp for last info for
544 * usage by isdn_net_autohup()
546 lp->charge++;
547 if (lp->hupflags & ISDN_HAVECHARGE) {
548 lp->hupflags &= ~ISDN_WAITCHARGE;
549 lp->chargeint = jiffies - lp->chargetime - (2 * HZ);
551 if (lp->hupflags & ISDN_WAITCHARGE)
552 lp->hupflags |= ISDN_HAVECHARGE;
553 lp->chargetime = jiffies;
554 printk(KERN_DEBUG "isdn_net: Got CINF chargetime of %s now %lu\n",
555 lp->name, lp->chargetime);
556 return 1;
559 return 0;
563 * Perform dialout for net-interfaces and timeout-handling for
564 * D-Channel-up and B-Channel-up Messages.
565 * This function is initially called from within isdn_net_start_xmit() or
566 * or isdn_net_find_icall() after initializing the dialstate for an
567 * interface. If further calls are needed, the function schedules itself
568 * for a timer-callback via isdn_timer_function().
569 * The dialstate is also affected by incoming status-messages from
570 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
572 void
573 isdn_net_dial(void)
575 isdn_net_dev *p = dev->netdev;
576 int anymore = 0;
577 int i;
578 int flags;
579 isdn_ctrl cmd;
581 while (p) {
582 isdn_net_local *lp = p->local;
584 #ifdef ISDN_DEBUG_NET_DIAL
585 if (lp->dialstate)
586 printk(KERN_DEBUG "%s: dialstate=%d\n", lp->name, lp->dialstate);
587 #endif
588 switch (lp->dialstate) {
589 case 0:
590 /* Nothing to do for this interface */
591 break;
592 case 1:
593 /* Initiate dialout. Set phone-number-pointer to first number
594 * of interface.
596 save_flags(flags);
597 cli();
598 lp->dial = lp->phone[1];
599 restore_flags(flags);
600 if (!lp->dial) {
601 printk(KERN_WARNING "%s: phone number deleted?\n",
602 lp->name);
603 isdn_net_hangup(&p->dev);
604 break;
606 anymore = 1;
608 if(lp->dialtimeout > 0)
609 if(lp->dialstarted == 0 || jiffies > (lp->dialstarted + lp->dialtimeout + lp->dialwait)) {
610 lp->dialstarted = jiffies;
611 lp->dialwait_timer = 0;
614 lp->dialstate++;
615 /* Fall through */
616 case 2:
617 /* Prepare dialing. Clear EAZ, then set EAZ. */
618 cmd.driver = lp->isdn_device;
619 cmd.arg = lp->isdn_channel;
620 cmd.command = ISDN_CMD_CLREAZ;
621 isdn_command(&cmd);
622 sprintf(cmd.parm.num, "%s", isdn_map_eaz2msn(lp->msn, cmd.driver));
623 cmd.command = ISDN_CMD_SETEAZ;
624 isdn_command(&cmd);
625 lp->dialretry = 0;
626 anymore = 1;
627 lp->dialstate++;
628 /* Fall through */
629 case 3:
630 /* Setup interface, dial current phone-number, switch to next number.
631 * If list of phone-numbers is exhausted, increment
632 * retry-counter.
634 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF)) {
635 char *s;
636 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
637 s = "dial suppressed: isdn system stopped";
638 else
639 s = "dial suppressed: dialmode `off'";
640 isdn_net_unreachable(&p->dev, 0, s);
641 isdn_net_hangup(&p->dev);
642 break;
644 cmd.driver = lp->isdn_device;
645 cmd.command = ISDN_CMD_SETL2;
646 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
647 isdn_command(&cmd);
648 cmd.driver = lp->isdn_device;
649 cmd.command = ISDN_CMD_SETL3;
650 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
651 isdn_command(&cmd);
652 cmd.driver = lp->isdn_device;
653 cmd.arg = lp->isdn_channel;
654 save_flags(flags);
655 cli();
656 if (!lp->dial) {
657 restore_flags(flags);
658 printk(KERN_WARNING "%s: phone number deleted?\n",
659 lp->name);
660 isdn_net_hangup(&p->dev);
661 break;
663 if (!strcmp(lp->dial->num, "LEASED")) {
664 restore_flags(flags);
665 lp->dialstate = 4;
666 printk(KERN_INFO "%s: Open leased line ...\n", lp->name);
667 } else {
668 if(lp->dialtimeout > 0)
669 if(jiffies > (lp->dialstarted + lp->dialtimeout)) {
670 restore_flags(flags);
671 lp->dialwait_timer = jiffies + lp->dialwait;
672 lp->dialstarted = 0;
673 isdn_net_unreachable(&p->dev, 0, "dial: timed out");
674 isdn_net_hangup(&p->dev);
675 break;
678 sprintf(cmd.parm.setup.phone, "%s", lp->dial->num);
680 * Switch to next number or back to start if at end of list.
682 if (!(lp->dial = (isdn_net_phone *) lp->dial->next)) {
683 lp->dial = lp->phone[1];
684 lp->dialretry++;
686 if (lp->dialretry > lp->dialmax) {
687 restore_flags(flags);
688 if (lp->dialtimeout == 0) {
689 lp->dialwait_timer = jiffies + lp->dialwait;
690 lp->dialstarted = 0;
691 isdn_net_unreachable(&p->dev, 0, "dial: tried all numbers dialmax times");
693 isdn_net_hangup(&p->dev);
694 break;
697 restore_flags(flags);
698 cmd.driver = lp->isdn_device;
699 cmd.command = ISDN_CMD_DIAL;
700 cmd.parm.setup.si1 = 7;
701 cmd.parm.setup.si2 = 0;
702 sprintf(cmd.parm.setup.eazmsn, "%s",
703 isdn_map_eaz2msn(lp->msn, cmd.driver));
704 i = isdn_dc2minor(lp->isdn_device, lp->isdn_channel);
705 if (i >= 0) {
706 strcpy(dev->num[i], cmd.parm.setup.phone);
707 isdn_info_update();
709 printk(KERN_INFO "%s: dialing %d %s...\n", lp->name,
710 lp->dialretry, cmd.parm.setup.phone);
711 lp->dtimer = 0;
712 #ifdef ISDN_DEBUG_NET_DIAL
713 printk(KERN_DEBUG "dial: d=%d c=%d\n", lp->isdn_device,
714 lp->isdn_channel);
715 #endif
716 isdn_command(&cmd);
718 lp->huptimer = 0;
719 lp->outgoing = 1;
720 if (lp->chargeint) {
721 lp->hupflags |= ISDN_HAVECHARGE;
722 lp->hupflags &= ~ISDN_WAITCHARGE;
723 } else {
724 lp->hupflags |= ISDN_WAITCHARGE;
725 lp->hupflags &= ~ISDN_HAVECHARGE;
727 anymore = 1;
728 lp->dialstate =
729 (lp->cbdelay &&
730 (lp->flags & ISDN_NET_CBOUT)) ? 12 : 4;
731 break;
732 case 4:
733 /* Wait for D-Channel-connect.
734 * If timeout, switch back to state 3.
735 * Dialmax-handling moved to state 3.
737 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
738 lp->dialstate = 3;
739 anymore = 1;
740 break;
741 case 5:
742 /* Got D-Channel-Connect, send B-Channel-request */
743 cmd.driver = lp->isdn_device;
744 cmd.arg = lp->isdn_channel;
745 cmd.command = ISDN_CMD_ACCEPTB;
746 anymore = 1;
747 lp->dtimer = 0;
748 lp->dialstate++;
749 isdn_command(&cmd);
750 break;
751 case 6:
752 /* Wait for B- or D-Channel-connect. If timeout,
753 * switch back to state 3.
755 #ifdef ISDN_DEBUG_NET_DIAL
756 printk(KERN_DEBUG "dialtimer2: %d\n", lp->dtimer);
757 #endif
758 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
759 lp->dialstate = 3;
760 anymore = 1;
761 break;
762 case 7:
763 /* Got incoming Call, setup L2 and L3 protocols,
764 * then wait for D-Channel-connect
766 #ifdef ISDN_DEBUG_NET_DIAL
767 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
768 #endif
769 cmd.driver = lp->isdn_device;
770 cmd.command = ISDN_CMD_SETL2;
771 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
772 isdn_command(&cmd);
773 cmd.driver = lp->isdn_device;
774 cmd.command = ISDN_CMD_SETL3;
775 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
776 isdn_command(&cmd);
777 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT15)
778 isdn_net_hangup(&p->dev);
779 else {
780 anymore = 1;
781 lp->dialstate++;
783 break;
784 case 9:
785 /* Got incoming D-Channel-Connect, send B-Channel-request */
786 cmd.driver = lp->isdn_device;
787 cmd.arg = lp->isdn_channel;
788 cmd.command = ISDN_CMD_ACCEPTB;
789 isdn_command(&cmd);
790 anymore = 1;
791 lp->dtimer = 0;
792 lp->dialstate++;
793 break;
794 case 8:
795 case 10:
796 /* Wait for B- or D-channel-connect */
797 #ifdef ISDN_DEBUG_NET_DIAL
798 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
799 #endif
800 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
801 isdn_net_hangup(&p->dev);
802 else
803 anymore = 1;
804 break;
805 case 11:
806 /* Callback Delay */
807 if (lp->dtimer++ > lp->cbdelay)
808 lp->dialstate = 1;
809 anymore = 1;
810 break;
811 case 12:
812 /* Remote does callback. Hangup after cbdelay, then wait for incoming
813 * call (in state 4).
815 if (lp->dtimer++ > lp->cbdelay)
817 printk(KERN_INFO "%s: hangup waiting for callback ...\n", lp->name);
818 lp->dtimer = 0;
819 lp->dialstate = 4;
820 cmd.driver = lp->isdn_device;
821 cmd.command = ISDN_CMD_HANGUP;
822 cmd.arg = lp->isdn_channel;
823 isdn_command(&cmd);
824 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
826 anymore = 1;
827 break;
828 default:
829 printk(KERN_WARNING "isdn_net: Illegal dialstate %d for device %s\n",
830 lp->dialstate, lp->name);
832 p = (isdn_net_dev *) p->next;
834 isdn_timer_ctrl(ISDN_TIMER_NETDIAL, anymore);
838 * Perform hangup for a net-interface.
840 void
841 isdn_net_hangup(struct net_device *d)
843 isdn_net_local *lp = (isdn_net_local *) d->priv;
844 isdn_ctrl cmd;
845 #ifdef CONFIG_ISDN_X25
846 struct concap_proto *cprot = lp -> netdev -> cprot;
847 struct concap_proto_ops *pops = cprot ? cprot -> pops : 0;
848 #endif
850 if (lp->flags & ISDN_NET_CONNECTED) {
851 if (lp->slave != NULL) {
852 isdn_net_local *slp = (isdn_net_local *)lp->slave->priv;
853 if (slp->flags & ISDN_NET_CONNECTED) {
854 printk(KERN_INFO
855 "isdn_net: hang up slave %s before %s\n",
856 slp->name, lp->name);
857 isdn_net_hangup(lp->slave);
860 printk(KERN_INFO "isdn_net: local hangup %s\n", lp->name);
861 #ifdef CONFIG_ISDN_PPP
862 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
863 isdn_ppp_free(lp);
864 #endif
865 isdn_net_lp_disconnected(lp);
866 #ifdef CONFIG_ISDN_X25
867 /* try if there are generic encap protocol
868 receiver routines and signal the closure of
869 the link */
870 if( pops && pops -> disconn_ind )
871 pops -> disconn_ind(cprot);
872 #endif /* CONFIG_ISDN_X25 */
874 cmd.driver = lp->isdn_device;
875 cmd.command = ISDN_CMD_HANGUP;
876 cmd.arg = lp->isdn_channel;
877 isdn_command(&cmd);
878 printk(KERN_INFO "%s: Chargesum is %d\n", lp->name, lp->charge);
879 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
881 isdn_net_unbind_channel(lp);
884 typedef struct {
885 unsigned short source;
886 unsigned short dest;
887 } ip_ports;
889 static void
890 isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
892 u_char *p = skb->nh.raw; /* hopefully, this was set correctly */
893 unsigned short proto = ntohs(skb->protocol);
894 int data_ofs;
895 ip_ports *ipp;
896 char addinfo[100];
898 addinfo[0] = '\0';
899 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
900 if (skb->nh.raw < skb->data || skb->nh.raw >= skb->tail) {
901 /* fall back to old isdn_net_log_packet method() */
902 char * buf = skb->data;
904 printk(KERN_DEBUG "isdn_net: protocol %04x is buggy, dev %s\n", skb->protocol, lp->name);
905 p = buf;
906 proto = ETH_P_IP;
907 switch (lp->p_encap) {
908 case ISDN_NET_ENCAP_IPTYP:
909 proto = ntohs(*(unsigned short *) &buf[0]);
910 p = &buf[2];
911 break;
912 case ISDN_NET_ENCAP_ETHER:
913 proto = ntohs(*(unsigned short *) &buf[12]);
914 p = &buf[14];
915 break;
916 case ISDN_NET_ENCAP_CISCOHDLC:
917 proto = ntohs(*(unsigned short *) &buf[2]);
918 p = &buf[4];
919 break;
920 #ifdef CONFIG_ISDN_PPP
921 case ISDN_NET_ENCAP_SYNCPPP:
922 proto = ntohs(skb->protocol);
923 p = &buf[IPPP_MAX_HEADER];
924 break;
925 #endif
928 data_ofs = ((p[0] & 15) * 4);
929 switch (proto) {
930 case ETH_P_IP:
931 switch (p[9]) {
932 case 1:
933 strcpy(addinfo, " ICMP");
934 break;
935 case 2:
936 strcpy(addinfo, " IGMP");
937 break;
938 case 4:
939 strcpy(addinfo, " IPIP");
940 break;
941 case 6:
942 ipp = (ip_ports *) (&p[data_ofs]);
943 sprintf(addinfo, " TCP, port: %d -> %d", ntohs(ipp->source),
944 ntohs(ipp->dest));
945 break;
946 case 8:
947 strcpy(addinfo, " EGP");
948 break;
949 case 12:
950 strcpy(addinfo, " PUP");
951 break;
952 case 17:
953 ipp = (ip_ports *) (&p[data_ofs]);
954 sprintf(addinfo, " UDP, port: %d -> %d", ntohs(ipp->source),
955 ntohs(ipp->dest));
956 break;
957 case 22:
958 strcpy(addinfo, " IDP");
959 break;
961 printk(KERN_INFO
962 "OPEN: %d.%d.%d.%d -> %d.%d.%d.%d%s\n",
964 p[12], p[13], p[14], p[15],
965 p[16], p[17], p[18], p[19],
966 addinfo);
967 break;
968 case ETH_P_ARP:
969 printk(KERN_INFO
970 "OPEN: ARP %d.%d.%d.%d -> *.*.*.* ?%d.%d.%d.%d\n",
971 p[14], p[15], p[16], p[17],
972 p[24], p[25], p[26], p[27]);
973 break;
978 * this function is used to send supervisory data, i.e. data which was
979 * not received from the network layer, but e.g. frames from ipppd, CCP
980 * reset frames etc.
982 void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb)
984 if (in_interrupt()) {
985 // we can't grab the lock from irq context,
986 // so we just queue the packet
987 skb_queue_tail(&lp->super_tx_queue, skb);
988 queue_task(&lp->tqueue, &tq_immediate);
989 return;
992 spin_lock_bh(&lp->xmit_lock);
993 if (!isdn_net_lp_busy(lp)) {
994 isdn_net_writebuf_skb(lp, skb);
995 } else {
996 skb_queue_tail(&lp->super_tx_queue, skb);
998 spin_unlock_bh(&lp->xmit_lock);
1002 * called from tq_immediate
1004 static void
1005 isdn_net_softint(void *private)
1007 isdn_net_local *lp = private;
1008 struct sk_buff *skb;
1010 spin_lock_bh(&lp->xmit_lock);
1011 while (!isdn_net_lp_busy(lp)) {
1012 skb = skb_dequeue(&lp->super_tx_queue);
1013 if (!skb)
1014 break;
1015 isdn_net_writebuf_skb(lp, skb);
1017 spin_unlock_bh(&lp->xmit_lock);
1021 * all frames sent from the (net) LL to a HL driver should go via this function
1022 * it's serialized by the caller holding the lp->xmit_lock spinlock
1024 void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb)
1026 int ret;
1027 int len = skb->len; /* save len */
1029 /* before obtaining the lock the caller should have checked that
1030 the lp isn't busy */
1031 if (isdn_net_lp_busy(lp)) {
1032 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1033 goto error;
1036 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1037 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1038 goto error;
1040 ret = isdn_writebuf_skb_stub(lp->isdn_device, lp->isdn_channel, 1, skb);
1041 if (ret != len) {
1042 /* we should never get here */
1043 printk(KERN_WARNING "%s: HL driver queue full\n", lp->name);
1044 goto error;
1047 lp->transcount += len;
1048 isdn_net_inc_frame_cnt(lp);
1049 return;
1051 error:
1052 dev_kfree_skb(skb);
1053 lp->stats.tx_errors++;
1059 * Helper function for isdn_net_start_xmit.
1060 * When called, the connection is already established.
1061 * Based on cps-calculation, check if device is overloaded.
1062 * If so, and if a slave exists, trigger dialing for it.
1063 * If any slave is online, deliver packets using a simple round robin
1064 * scheme.
1066 * Return: 0 on success, !0 on failure.
1069 static int
1070 isdn_net_xmit(struct net_device *ndev, struct sk_buff *skb)
1072 isdn_net_dev *nd;
1073 isdn_net_local *slp;
1074 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1075 int retv = 0;
1077 if (((isdn_net_local *) (ndev->priv))->master) {
1078 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1079 dev_kfree_skb(skb);
1080 return 0;
1083 /* For the other encaps the header has already been built */
1084 #ifdef CONFIG_ISDN_PPP
1085 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1086 return isdn_ppp_xmit(skb, ndev);
1088 #endif
1090 nd = ((isdn_net_local *) ndev->priv)->netdev;
1092 lp = isdn_net_get_locked_lp(nd);
1093 if (!lp) {
1094 printk(KERN_WARNING "%s: all channels busy - requeuing!\n", ndev->name);
1095 return 1;
1097 /* we have our lp locked from now on */
1099 /* Reset hangup-timeout */
1100 lp->huptimer = 0; // FIXME?
1101 isdn_net_writebuf_skb(lp, skb);
1102 spin_unlock_bh(&lp->xmit_lock);
1104 /* the following stuff is here for backwards compatibility.
1105 * in future, start-up and hangup of slaves (based on current load)
1106 * should move to userspace and get based on an overall cps
1107 * calculation
1109 if (lp->cps > lp->triggercps) {
1110 if (lp->slave) {
1111 if (!lp->sqfull) {
1112 /* First time overload: set timestamp only */
1113 lp->sqfull = 1;
1114 lp->sqfull_stamp = jiffies;
1115 } else {
1116 /* subsequent overload: if slavedelay exceeded, start dialing */
1117 if ((jiffies - lp->sqfull_stamp) > lp->slavedelay) {
1118 slp = lp->slave->priv;
1119 if (!(slp->flags & ISDN_NET_CONNECTED)) {
1120 isdn_net_force_dial_lp((isdn_net_local *) lp->slave->priv);
1125 } else {
1126 if (lp->sqfull && ((jiffies - lp->sqfull_stamp) > (lp->slavedelay + (10 * HZ)))) {
1127 lp->sqfull = 0;
1129 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1130 nd->queue = nd->local;
1133 return retv;
1137 static void
1138 isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
1140 isdn_net_local *lp = (isdn_net_local *) dev->priv;
1141 if (!skb)
1142 return;
1143 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
1144 int pullsize = (ulong)skb->nh.raw - (ulong)skb->data - ETH_HLEN;
1145 if (pullsize > 0) {
1146 printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
1147 skb_pull(skb, pullsize);
1153 void isdn_net_tx_timeout(struct net_device * ndev)
1155 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1157 printk(KERN_WARNING "isdn_tx_timeout dev %s dialstate %d\n", ndev->name, lp->dialstate);
1158 if (!lp->dialstate){
1159 lp->stats.tx_errors++;
1161 * There is a certain probability that this currently
1162 * works at all because if we always wake up the interface,
1163 * then upper layer will try to send the next packet
1164 * immediately. And then, the old clean_up logic in the
1165 * driver will hopefully continue to work as it used to do.
1167 * This is rather primitive right know, we better should
1168 * clean internal queues here, in particular for multilink and
1169 * ppp, and reset HL driver's channel, too. --HE
1171 * actually, this may not matter at all, because ISDN hardware
1172 * should not see transmitter hangs at all IMO
1173 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1174 * ever called --KG
1177 ndev->trans_start = jiffies;
1178 netif_wake_queue(ndev);
1182 * Try sending a packet.
1183 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1184 * and start dialing.
1186 static int
1187 isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1189 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1190 #ifdef CONFIG_ISDN_X25
1191 struct concap_proto * cprot = lp -> netdev -> cprot;
1192 #endif
1193 #ifdef CONFIG_ISDN_X25
1194 /* At this point hard_start_xmit() passes control to the encapsulation
1195 protocol (if present).
1196 For X.25 auto-dialing is completly bypassed because:
1197 - It does not conform with the semantics of a reliable datalink
1198 service as needed by X.25 PLP.
1199 - I don't want that the interface starts dialing when the network layer
1200 sends a message which requests to disconnect the lapb link (or if it
1201 sends any other message not resulting in data transmission).
1202 Instead, dialing will be initiated by the encapsulation protocol entity
1203 when a dl_establish request is received from the upper layer.
1205 if( cprot ) {
1206 int ret = cprot -> pops -> encap_and_xmit ( cprot , skb);
1207 if(ret) netif_stop_queue(ndev);
1208 return ret;
1209 } else
1210 #endif
1211 /* auto-dialing xmit function */
1213 #ifdef ISDN_DEBUG_NET_DUMP
1214 u_char *buf;
1215 #endif
1216 isdn_net_adjust_hdr(skb, ndev);
1217 #ifdef ISDN_DEBUG_NET_DUMP
1218 buf = skb->data;
1219 isdn_dumppkt("S:", buf, skb->len, 40);
1220 #endif
1221 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1222 int chi;
1223 /* only do autodial if allowed by config */
1224 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) {
1225 isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'");
1226 dev_kfree_skb(skb);
1227 return 0;
1229 if (lp->phone[1]) {
1230 ulong flags;
1231 save_flags(flags);
1232 cli();
1234 if(lp->dialwait_timer <= 0)
1235 if(lp->dialstarted > 0 && lp->dialtimeout > 0 && jiffies < lp->dialstarted + lp->dialtimeout + lp->dialwait)
1236 lp->dialwait_timer = lp->dialstarted + lp->dialtimeout + lp->dialwait;
1238 if(lp->dialwait_timer > 0) {
1239 if(jiffies < lp->dialwait_timer) {
1240 isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached");
1241 dev_kfree_skb(skb);
1242 restore_flags(flags);
1243 return 0;
1244 } else
1245 lp->dialwait_timer = 0;
1247 /* Grab a free ISDN-Channel */
1248 if (((chi =
1249 isdn_get_free_channel(
1250 ISDN_USAGE_NET,
1251 lp->l2_proto,
1252 lp->l3_proto,
1253 lp->pre_device,
1254 lp->pre_channel,
1255 lp->msn)
1256 ) < 0) &&
1257 ((chi =
1258 isdn_get_free_channel(
1259 ISDN_USAGE_NET,
1260 lp->l2_proto,
1261 lp->l3_proto,
1262 lp->pre_device,
1263 lp->pre_channel^1,
1264 lp->msn)
1265 ) < 0)) {
1266 restore_flags(flags);
1267 isdn_net_unreachable(ndev, skb,
1268 "No channel");
1269 dev_kfree_skb(skb);
1270 return 0;
1272 /* Log packet, which triggered dialing */
1273 if (dev->net_verbose)
1274 isdn_net_log_skb(skb, lp);
1275 lp->dialstate = 1;
1276 /* Connect interface with channel */
1277 isdn_net_bind_channel(lp, chi);
1278 #ifdef CONFIG_ISDN_PPP
1279 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1280 /* no 'first_skb' handling for syncPPP */
1281 if (isdn_ppp_bind(lp) < 0) {
1282 dev_kfree_skb(skb);
1283 isdn_net_unbind_channel(lp);
1284 restore_flags(flags);
1285 return 0; /* STN (skb to nirvana) ;) */
1287 restore_flags(flags);
1288 isdn_net_dial(); /* Initiate dialing */
1289 netif_stop_queue(ndev);
1290 return 1; /* let upper layer requeue skb packet */
1292 #endif
1293 /* Initiate dialing */
1294 restore_flags(flags);
1295 isdn_net_dial();
1296 isdn_net_device_stop_queue(lp);
1297 return 1;
1298 } else {
1299 isdn_net_unreachable(ndev, skb,
1300 "No phone number");
1301 dev_kfree_skb(skb);
1302 return 0;
1304 } else {
1305 /* Device is connected to an ISDN channel */
1306 ndev->trans_start = jiffies;
1307 if (!lp->dialstate) {
1308 /* ISDN connection is established, try sending */
1309 int ret;
1310 ret = (isdn_net_xmit(ndev, skb));
1311 if(ret) netif_stop_queue(ndev);
1312 return ret;
1313 } else
1314 netif_stop_queue(ndev);
1317 return 1;
1321 * Shutdown a net-interface.
1323 static int
1324 isdn_net_close(struct net_device *dev)
1326 struct net_device *p;
1327 #ifdef CONFIG_ISDN_X25
1328 struct concap_proto * cprot =
1329 ( (isdn_net_local *) dev->priv ) -> netdev -> cprot;
1330 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1331 #endif
1333 #ifdef CONFIG_ISDN_X25
1334 if( cprot && cprot -> pops ) cprot -> pops -> close( cprot );
1335 #endif
1336 netif_stop_queue(dev);
1337 if ((p = (((isdn_net_local *) dev->priv)->slave))) {
1338 /* If this interface has slaves, stop them also */
1339 while (p) {
1340 #ifdef CONFIG_ISDN_X25
1341 cprot = ( (isdn_net_local *) p->priv )
1342 -> netdev -> cprot;
1343 if( cprot && cprot -> pops )
1344 cprot -> pops -> close( cprot );
1345 #endif
1346 isdn_net_hangup(p);
1347 p = (((isdn_net_local *) p->priv)->slave);
1350 isdn_net_hangup(dev);
1351 isdn_MOD_DEC_USE_COUNT();
1352 return 0;
1356 * Get statistics
1358 static struct net_device_stats *
1359 isdn_net_get_stats(struct net_device *dev)
1361 isdn_net_local *lp = (isdn_net_local *) dev->priv;
1362 return &lp->stats;
1365 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1366 * instead of dev->hard_header_len off. This is done because the
1367 * lowlevel-driver has already pulled off its stuff when we get
1368 * here and this routine only gets called with p_encap == ETHER.
1369 * Determine the packet's protocol ID. The rule here is that we
1370 * assume 802.3 if the type field is short enough to be a length.
1371 * This is normal practice and works for any 'now in use' protocol.
1374 static unsigned short
1375 isdn_net_type_trans(struct sk_buff *skb, struct net_device *dev)
1377 struct ethhdr *eth;
1378 unsigned char *rawp;
1380 skb->mac.raw = skb->data;
1381 skb_pull(skb, ETH_HLEN);
1382 eth = skb->mac.ethernet;
1384 if (*eth->h_dest & 1) {
1385 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
1386 skb->pkt_type = PACKET_BROADCAST;
1387 else
1388 skb->pkt_type = PACKET_MULTICAST;
1391 * This ALLMULTI check should be redundant by 1.4
1392 * so don't forget to remove it.
1395 else if (dev->flags & (IFF_PROMISC /*| IFF_ALLMULTI*/)) {
1396 if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
1397 skb->pkt_type = PACKET_OTHERHOST;
1399 if (ntohs(eth->h_proto) >= 1536)
1400 return eth->h_proto;
1402 rawp = skb->data;
1405 * This is a magic hack to spot IPX packets. Older Novell breaks
1406 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1407 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1408 * won't work for fault tolerant netware but does for the rest.
1410 if (*(unsigned short *) rawp == 0xFFFF)
1411 return htons(ETH_P_802_3);
1413 * Real 802.2 LLC
1415 return htons(ETH_P_802_2);
1418 static void
1419 isdn_net_slarp_send(isdn_net_local *lp, int is_reply)
1421 unsigned short hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
1422 struct sk_buff *skb = alloc_skb(hl + sizeof(cisco_hdr) + sizeof(cisco_slarp), GFP_ATOMIC);
1423 unsigned long t = (jiffies / HZ * 1000000);
1424 cisco_hdr *ch;
1425 cisco_slarp *s;
1427 if (!skb) {
1428 printk(KERN_WARNING
1429 "%s: Could not allocate SLARP reply\n", lp->name);
1430 return;
1432 skb_reserve(skb, hl);
1433 ch = (cisco_hdr *)skb_put(skb, sizeof(cisco_hdr));
1434 ch->addr = CISCO_ADDR_UNICAST;
1435 ch->ctrl = 0;
1436 ch->type = htons(CISCO_TYPE_SLARP);
1437 s = (cisco_slarp *)skb_put(skb, sizeof(cisco_slarp));
1438 if (is_reply) {
1439 s->code = htonl(CISCO_SLARP_REPLY);
1440 memset(&s->slarp.reply.ifaddr, 0, sizeof(__u32));
1441 memset(&s->slarp.reply.netmask, 0, sizeof(__u32));
1442 } else {
1443 lp->cisco_myseq++;
1444 s->code = htonl(CISCO_SLARP_KEEPALIVE);
1445 s->slarp.keepalive.my_seq = htonl(lp->cisco_myseq);
1446 s->slarp.keepalive.your_seq = htonl(lp->cisco_yourseq);
1448 s->rel = 0xffff;
1449 s->t1 = t >> 16;
1450 s->t0 = t & 0xffff;
1451 isdn_net_write_super(lp, skb);
1454 static void
1455 isdn_net_slarp_in(isdn_net_local *lp, struct sk_buff *skb)
1457 cisco_slarp *s = (cisco_slarp *)skb->data;
1459 switch (ntohl(s->code)) {
1460 case CISCO_SLARP_REQUEST:
1461 isdn_net_slarp_send(lp, 1);
1462 break;
1463 case CISCO_SLARP_REPLY:
1464 /* Ignore replies */
1465 break;
1466 case CISCO_SLARP_KEEPALIVE:
1467 lp->cisco_yourseq = s->slarp.keepalive.my_seq;
1468 if (ntohl(s->slarp.keepalive.my_seq == lp->cisco_myseq)) {
1469 if (lp->cisco_loop++ == 2) {
1470 printk(KERN_WARNING "%s: Keepalive Loop\n",
1471 lp->name);
1472 lp->cisco_myseq ^= jiffies;
1474 } else
1475 lp->cisco_loop = 0;
1476 break;
1478 kfree_skb(skb);
1482 * Called every 10 sec. via timer-interrupt if
1483 * any network-interface has Cisco-Keepalive-Encapsulation
1484 * and is online.
1485 * Send Keepalive-Packet and re-schedule.
1487 void
1488 isdn_net_slarp_out(void)
1490 isdn_net_dev *p = dev->netdev;
1491 int anymore = 0;
1493 while (p) {
1494 isdn_net_local *l = p->local;
1495 if ((l->p_encap == ISDN_NET_ENCAP_CISCOHDLCK) &&
1496 (l->flags & ISDN_NET_CONNECTED) &&
1497 (!l->dialstate) ) {
1498 anymore = 1;
1499 isdn_net_slarp_send(l, 0);
1501 p = (isdn_net_dev *) p->next;
1503 isdn_timer_ctrl(ISDN_TIMER_KEEPALIVE, anymore);
1507 * Got a packet from ISDN-Channel.
1509 static void
1510 isdn_net_receive(struct net_device *ndev, struct sk_buff *skb)
1512 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1513 isdn_net_local *olp = lp; /* original 'lp' */
1514 #ifdef CONFIG_ISDN_PPP
1515 int proto = PPP_PROTOCOL(skb->data);
1516 #endif
1517 #ifdef CONFIG_ISDN_X25
1518 struct concap_proto *cprot = lp -> netdev -> cprot;
1519 #endif
1520 cisco_hdr *ch;
1522 lp->transcount += skb->len;
1524 lp->stats.rx_packets++;
1525 lp->stats.rx_bytes += skb->len;
1526 if (lp->master) {
1527 /* Bundling: If device is a slave-device, deliver to master, also
1528 * handle master's statistics and hangup-timeout
1530 ndev = lp->master;
1531 lp = (isdn_net_local *) ndev->priv;
1532 lp->stats.rx_packets++;
1533 lp->stats.rx_bytes += skb->len;
1536 skb->dev = ndev;
1537 skb->pkt_type = PACKET_HOST;
1538 skb->mac.raw = skb->data;
1539 #ifdef ISDN_DEBUG_NET_DUMP
1540 isdn_dumppkt("R:", skb->data, skb->len, 40);
1541 #endif
1542 switch (lp->p_encap) {
1543 case ISDN_NET_ENCAP_ETHER:
1544 /* Ethernet over ISDN */
1545 olp->huptimer = 0;
1546 lp->huptimer = 0;
1547 skb->protocol = isdn_net_type_trans(skb, ndev);
1548 break;
1549 case ISDN_NET_ENCAP_UIHDLC:
1550 /* HDLC with UI-frame (for ispa with -h1 option) */
1551 olp->huptimer = 0;
1552 lp->huptimer = 0;
1553 skb_pull(skb, 2);
1554 /* Fall through */
1555 case ISDN_NET_ENCAP_RAWIP:
1556 /* RAW-IP without MAC-Header */
1557 olp->huptimer = 0;
1558 lp->huptimer = 0;
1559 skb->protocol = htons(ETH_P_IP);
1560 break;
1561 case ISDN_NET_ENCAP_CISCOHDLCK:
1562 ch = (cisco_hdr *)skb->data;
1563 if ((ch->addr != CISCO_ADDR_UNICAST) &&
1564 (ch->addr != CISCO_ADDR_BROADCAST) ) {
1565 printk(KERN_WARNING "%s: Unknown Cisco addr 0x%02x\n",
1566 lp->name, ch->addr);
1567 kfree_skb(skb);
1568 return;
1570 if (ch->ctrl != 0) {
1571 printk(KERN_WARNING "%s: Unknown Cisco ctrl 0x%02x\n",
1572 lp->name, ch->ctrl);
1573 kfree_skb(skb);
1574 return;
1576 switch (ntohs(ch->type)) {
1577 case CISCO_TYPE_INET:
1578 skb_pull(skb, 4);
1579 skb->protocol = htons(ETH_P_IP);
1580 break;
1581 case CISCO_TYPE_SLARP:
1582 skb_pull(skb, 4);
1583 isdn_net_slarp_in(olp, skb);
1584 return;
1585 default:
1586 printk(KERN_WARNING "%s: Unknown Cisco type 0x%04x\n",
1587 lp->name, ch->type);
1588 kfree_skb(skb);
1589 return;
1591 break;
1592 case ISDN_NET_ENCAP_CISCOHDLC:
1593 /* CISCO-HDLC IP with type field and fake I-frame-header */
1594 skb_pull(skb, 2);
1595 /* Fall through */
1596 case ISDN_NET_ENCAP_IPTYP:
1597 /* IP with type field */
1598 olp->huptimer = 0;
1599 lp->huptimer = 0;
1600 skb->protocol = *(unsigned short *) &(skb->data[0]);
1601 skb_pull(skb, 2);
1602 if (*(unsigned short *) skb->data == 0xFFFF)
1603 skb->protocol = htons(ETH_P_802_3);
1604 break;
1605 #ifdef CONFIG_ISDN_PPP
1606 case ISDN_NET_ENCAP_SYNCPPP:
1608 * If encapsulation is syncppp, don't reset
1609 * huptimer on LCP packets.
1611 if (proto != PPP_LCP) {
1612 olp->huptimer = 0;
1613 lp->huptimer = 0;
1615 isdn_ppp_receive(lp->netdev, olp, skb);
1616 return;
1617 #endif
1618 default:
1619 #ifdef CONFIG_ISDN_X25
1620 /* try if there are generic sync_device receiver routines */
1621 if(cprot) if(cprot -> pops)
1622 if( cprot -> pops -> data_ind){
1623 cprot -> pops -> data_ind(cprot,skb);
1624 return;
1626 #endif /* CONFIG_ISDN_X25 */
1627 printk(KERN_WARNING "%s: unknown encapsulation, dropping\n",
1628 lp->name);
1629 kfree_skb(skb);
1630 return;
1633 netif_rx(skb);
1634 return;
1638 * A packet arrived via ISDN. Search interface-chain for a corresponding
1639 * interface. If found, deliver packet to receiver-function and return 1,
1640 * else return 0.
1643 isdn_net_rcv_skb(int idx, struct sk_buff *skb)
1645 isdn_net_dev *p = dev->rx_netdev[idx];
1647 if (p) {
1648 isdn_net_local *lp = p->local;
1649 if ((lp->flags & ISDN_NET_CONNECTED) &&
1650 (!lp->dialstate)) {
1651 isdn_net_receive(&p->dev, skb);
1652 return 1;
1655 return 0;
1658 static int
1659 my_eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1660 void *daddr, void *saddr, unsigned len)
1662 struct ethhdr *eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
1665 * Set the protocol type. For a packet of type ETH_P_802_3 we
1666 * put the length here instead. It is up to the 802.2 layer to
1667 * carry protocol information.
1670 if (type != ETH_P_802_3)
1671 eth->h_proto = htons(type);
1672 else
1673 eth->h_proto = htons(len);
1676 * Set the source hardware address.
1678 if (saddr)
1679 memcpy(eth->h_source, saddr, dev->addr_len);
1680 else
1681 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
1684 * Anyway, the loopback-device should never use this function...
1687 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
1688 memset(eth->h_dest, 0, dev->addr_len);
1689 return ETH_HLEN /*(dev->hard_header_len)*/;
1691 if (daddr) {
1692 memcpy(eth->h_dest, daddr, dev->addr_len);
1693 return ETH_HLEN /*dev->hard_header_len*/;
1695 return -ETH_HLEN /*dev->hard_header_len*/;
1699 * build an header
1700 * depends on encaps that is being used.
1703 static int
1704 isdn_net_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1705 void *daddr, void *saddr, unsigned plen)
1707 isdn_net_local *lp = dev->priv;
1708 ushort len = 0;
1710 switch (lp->p_encap) {
1711 case ISDN_NET_ENCAP_ETHER:
1712 len = my_eth_header(skb, dev, type, daddr, saddr, plen);
1713 break;
1714 #ifdef CONFIG_ISDN_PPP
1715 case ISDN_NET_ENCAP_SYNCPPP:
1716 /* stick on a fake header to keep fragmentation code happy. */
1717 len = IPPP_MAX_HEADER;
1718 skb_push(skb,len);
1719 break;
1720 #endif
1721 case ISDN_NET_ENCAP_RAWIP:
1722 printk(KERN_WARNING "isdn_net_header called with RAW_IP!\n");
1723 len = 0;
1724 break;
1725 case ISDN_NET_ENCAP_IPTYP:
1726 /* ethernet type field */
1727 *((ushort *) skb_push(skb, 2)) = htons(type);
1728 len = 2;
1729 break;
1730 case ISDN_NET_ENCAP_UIHDLC:
1731 /* HDLC with UI-Frames (for ispa with -h1 option) */
1732 *((ushort *) skb_push(skb, 2)) = htons(0x0103);
1733 len = 2;
1734 break;
1735 case ISDN_NET_ENCAP_CISCOHDLC:
1736 skb_push(skb, 4);
1737 skb->data[0] = 0x0f;
1738 skb->data[1] = 0x00;
1739 *((ushort *) & skb->data[2]) = htons(type);
1740 len = 4;
1741 break;
1742 #ifdef CONFIG_ISDN_X25
1743 default:
1744 /* try if there are generic concap protocol routines */
1745 if( lp-> netdev -> cprot ){
1746 printk(KERN_WARNING "isdn_net_header called with concap_proto!\n");
1747 len = 0;
1748 break;
1750 break;
1751 #endif /* CONFIG_ISDN_X25 */
1753 return len;
1756 /* We don't need to send arp, because we have point-to-point connections. */
1757 static int
1758 isdn_net_rebuild_header(struct sk_buff *skb)
1760 struct net_device *dev = skb->dev;
1761 isdn_net_local *lp = dev->priv;
1762 int ret = 0;
1764 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
1765 struct ethhdr *eth = (struct ethhdr *) skb->data;
1768 * Only ARP/IP is currently supported
1771 if (eth->h_proto != htons(ETH_P_IP)) {
1772 printk(KERN_WARNING
1773 "isdn_net: %s don't know how to resolve type %d addresses?\n",
1774 dev->name, (int) eth->h_proto);
1775 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
1776 return 0;
1779 * Try to get ARP to resolve the header.
1781 #ifdef CONFIG_INET
1782 ret = arp_find(eth->h_dest, skb);
1783 #endif
1785 return ret;
1789 * Interface-setup. (just after registering a new interface)
1791 static int
1792 isdn_net_init(struct net_device *ndev)
1794 ushort max_hlhdr_len = 0;
1795 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1796 int drvidx,
1799 if (ndev == NULL) {
1800 printk(KERN_WARNING "isdn_net_init: dev = NULL!\n");
1801 return -ENODEV;
1803 if (ndev->priv == NULL) {
1804 printk(KERN_WARNING "isdn_net_init: dev->priv = NULL!\n");
1805 return -ENODEV;
1807 ether_setup(ndev);
1808 lp->org_hhc = ndev->hard_header_cache;
1809 lp->org_hcu = ndev->header_cache_update;
1811 /* Setup the generic properties */
1813 ndev->hard_header = NULL;
1814 ndev->hard_header_cache = NULL;
1815 ndev->header_cache_update = NULL;
1816 ndev->mtu = 1500;
1817 ndev->flags = IFF_NOARP|IFF_POINTOPOINT;
1818 ndev->type = ARPHRD_ETHER;
1819 ndev->addr_len = ETH_ALEN;
1821 /* for clients with MPPP maybe higher values better */
1822 ndev->tx_queue_len = 30;
1824 for (i = 0; i < ETH_ALEN; i++)
1825 ndev->broadcast[i] = 0xff;
1827 /* The ISDN-specific entries in the device structure. */
1828 ndev->open = &isdn_net_open;
1829 ndev->hard_start_xmit = &isdn_net_start_xmit;
1832 * up till binding we ask the protocol layer to reserve as much
1833 * as we might need for HL layer
1836 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
1837 if (dev->drv[drvidx])
1838 if (max_hlhdr_len < dev->drv[drvidx]->interface->hl_hdrlen)
1839 max_hlhdr_len = dev->drv[drvidx]->interface->hl_hdrlen;
1841 ndev->hard_header_len = ETH_HLEN + max_hlhdr_len;
1842 ndev->stop = &isdn_net_close;
1843 ndev->get_stats = &isdn_net_get_stats;
1844 ndev->rebuild_header = &isdn_net_rebuild_header;
1845 #ifdef CONFIG_ISDN_PPP
1846 ndev->do_ioctl = isdn_ppp_dev_ioctl;
1847 #endif
1848 return 0;
1851 static void
1852 isdn_net_swapbind(int drvidx)
1854 isdn_net_dev *p;
1856 #ifdef ISDN_DEBUG_NET_ICALL
1857 printk(KERN_DEBUG "n_fi: swapping ch of %d\n", drvidx);
1858 #endif
1859 p = dev->netdev;
1860 while (p) {
1861 if (p->local->pre_device == drvidx)
1862 switch (p->local->pre_channel) {
1863 case 0:
1864 p->local->pre_channel = 1;
1865 break;
1866 case 1:
1867 p->local->pre_channel = 0;
1868 break;
1870 p = (isdn_net_dev *) p->next;
1874 static void
1875 isdn_net_swap_usage(int i1, int i2)
1877 int u1 = dev->usage[i1] & ISDN_USAGE_EXCLUSIVE;
1878 int u2 = dev->usage[i2] & ISDN_USAGE_EXCLUSIVE;
1880 #ifdef ISDN_DEBUG_NET_ICALL
1881 printk(KERN_DEBUG "n_fi: usage of %d and %d\n", i1, i2);
1882 #endif
1883 dev->usage[i1] &= ~ISDN_USAGE_EXCLUSIVE;
1884 dev->usage[i1] |= u2;
1885 dev->usage[i2] &= ~ISDN_USAGE_EXCLUSIVE;
1886 dev->usage[i2] |= u1;
1887 isdn_info_update();
1891 * An incoming call-request has arrived.
1892 * Search the interface-chain for an appropriate interface.
1893 * If found, connect the interface to the ISDN-channel and initiate
1894 * D- and B-Channel-setup. If secure-flag is set, accept only
1895 * configured phone-numbers. If callback-flag is set, initiate
1896 * callback-dialing.
1898 * Return-Value: 0 = No appropriate interface for this call.
1899 * 1 = Call accepted
1900 * 2 = Reject call, wait cbdelay, then call back
1901 * 3 = Reject call
1902 * 4 = Wait cbdelay, then call back
1903 * 5 = No appropriate interface for this call,
1904 * would eventually match if CID was longer.
1907 isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
1909 char *eaz;
1910 int si1;
1911 int si2;
1912 int ematch;
1913 int wret;
1914 int swapped;
1915 int sidx = 0;
1916 isdn_net_dev *p;
1917 isdn_net_phone *n;
1918 ulong flags;
1919 char nr[32];
1920 /* Search name in netdev-chain */
1921 save_flags(flags);
1922 cli();
1923 if (!setup->phone[0]) {
1924 nr[0] = '0';
1925 nr[1] = '\0';
1926 printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
1927 } else
1928 strcpy(nr, setup->phone);
1929 si1 = (int) setup->si1;
1930 si2 = (int) setup->si2;
1931 if (!setup->eazmsn[0]) {
1932 printk(KERN_WARNING "isdn_net: Incoming call without CPN, assuming '0'\n");
1933 eaz = "0";
1934 } else
1935 eaz = setup->eazmsn;
1936 if (dev->net_verbose > 1)
1937 printk(KERN_INFO "isdn_net: call from %s,%d,%d -> %s\n", nr, si1, si2, eaz);
1938 /* Accept only calls with Si1 = 7 (Data-Transmission) */
1939 if (si1 != 7) {
1940 restore_flags(flags);
1941 if (dev->net_verbose > 1)
1942 printk(KERN_INFO "isdn_net: Service-Indicator not 7, ignored\n");
1943 return 0;
1945 n = (isdn_net_phone *) 0;
1946 p = dev->netdev;
1947 ematch = wret = swapped = 0;
1948 #ifdef ISDN_DEBUG_NET_ICALL
1949 printk(KERN_DEBUG "n_fi: di=%d ch=%d idx=%d usg=%d\n", di, ch, idx,
1950 dev->usage[idx]);
1951 #endif
1952 while (p) {
1953 int matchret;
1954 isdn_net_local *lp = p->local;
1956 /* If last check has triggered as binding-swap, revert it */
1957 switch (swapped) {
1958 case 2:
1959 isdn_net_swap_usage(idx, sidx);
1960 /* fall through */
1961 case 1:
1962 isdn_net_swapbind(di);
1963 break;
1965 swapped = 0;
1966 if (!(matchret = isdn_msncmp(eaz, isdn_map_eaz2msn(lp->msn, di))))
1967 ematch = 1;
1968 /* Remember if more numbers eventually can match */
1969 if (matchret > wret)
1970 wret = matchret;
1971 #ifdef ISDN_DEBUG_NET_ICALL
1972 printk(KERN_DEBUG "n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
1973 lp->name, lp->msn, lp->flags, lp->dialstate);
1974 #endif
1975 if ((!matchret) && /* EAZ is matching */
1976 (((!(lp->flags & ISDN_NET_CONNECTED)) && /* but not connected */
1977 (USG_NONE(dev->usage[idx]))) || /* and ch. unused or */
1978 ((((lp->dialstate == 4) || (lp->dialstate == 12)) && /* if dialing */
1979 (!(lp->flags & ISDN_NET_CALLBACK))) /* but no callback */
1982 #ifdef ISDN_DEBUG_NET_ICALL
1983 printk(KERN_DEBUG "n_fi: match1, pdev=%d pch=%d\n",
1984 lp->pre_device, lp->pre_channel);
1985 #endif
1986 if (dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) {
1987 if ((lp->pre_channel != ch) ||
1988 (lp->pre_device != di)) {
1989 /* Here we got a problem:
1990 * If using an ICN-Card, an incoming call is always signaled on
1991 * on the first channel of the card, if both channels are
1992 * down. However this channel may be bound exclusive. If the
1993 * second channel is free, this call should be accepted.
1994 * The solution is horribly but it runs, so what:
1995 * We exchange the exclusive bindings of the two channels, the
1996 * corresponding variables in the interface-structs.
1998 if (ch == 0) {
1999 sidx = isdn_dc2minor(di, 1);
2000 #ifdef ISDN_DEBUG_NET_ICALL
2001 printk(KERN_DEBUG "n_fi: ch is 0\n");
2002 #endif
2003 if (USG_NONE(dev->usage[sidx])) {
2004 /* Second Channel is free, now see if it is bound
2005 * exclusive too. */
2006 if (dev->usage[sidx] & ISDN_USAGE_EXCLUSIVE) {
2007 #ifdef ISDN_DEBUG_NET_ICALL
2008 printk(KERN_DEBUG "n_fi: 2nd channel is down and bound\n");
2009 #endif
2010 /* Yes, swap bindings only, if the original
2011 * binding is bound to channel 1 of this driver */
2012 if ((lp->pre_device == di) &&
2013 (lp->pre_channel == 1)) {
2014 isdn_net_swapbind(di);
2015 swapped = 1;
2016 } else {
2017 /* ... else iterate next device */
2018 p = (isdn_net_dev *) p->next;
2019 continue;
2021 } else {
2022 #ifdef ISDN_DEBUG_NET_ICALL
2023 printk(KERN_DEBUG "n_fi: 2nd channel is down and unbound\n");
2024 #endif
2025 /* No, swap always and swap excl-usage also */
2026 isdn_net_swap_usage(idx, sidx);
2027 isdn_net_swapbind(di);
2028 swapped = 2;
2030 /* Now check for exclusive binding again */
2031 #ifdef ISDN_DEBUG_NET_ICALL
2032 printk(KERN_DEBUG "n_fi: final check\n");
2033 #endif
2034 if ((dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) &&
2035 ((lp->pre_channel != ch) ||
2036 (lp->pre_device != di))) {
2037 #ifdef ISDN_DEBUG_NET_ICALL
2038 printk(KERN_DEBUG "n_fi: final check failed\n");
2039 #endif
2040 p = (isdn_net_dev *) p->next;
2041 continue;
2044 } else {
2045 /* We are already on the second channel, so nothing to do */
2046 #ifdef ISDN_DEBUG_NET_ICALL
2047 printk(KERN_DEBUG "n_fi: already on 2nd channel\n");
2048 #endif
2052 #ifdef ISDN_DEBUG_NET_ICALL
2053 printk(KERN_DEBUG "n_fi: match2\n");
2054 #endif
2055 n = lp->phone[0];
2056 if (lp->flags & ISDN_NET_SECURE) {
2057 while (n) {
2058 if (!isdn_msncmp(nr, n->num))
2059 break;
2060 n = (isdn_net_phone *) n->next;
2063 if (n || (!(lp->flags & ISDN_NET_SECURE))) {
2064 #ifdef ISDN_DEBUG_NET_ICALL
2065 printk(KERN_DEBUG "n_fi: match3\n");
2066 #endif
2067 /* matching interface found */
2070 * Is the state STOPPED?
2071 * If so, no dialin is allowed,
2072 * so reject actively.
2073 * */
2074 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2075 restore_flags(flags);
2076 printk(KERN_INFO "incoming call, interface %s `stopped' -> rejected\n",
2077 lp->name);
2078 return 3;
2081 * Is the interface up?
2082 * If not, reject the call actively.
2084 if (!isdn_net_device_started(p)) {
2085 restore_flags(flags);
2086 printk(KERN_INFO "%s: incoming call, interface down -> rejected\n",
2087 lp->name);
2088 return 3;
2090 /* Interface is up, now see if it's a slave. If so, see if
2091 * it's master and parent slave is online. If not, reject the call.
2093 if (lp->master) {
2094 isdn_net_local *mlp = (isdn_net_local *) lp->master->priv;
2095 printk(KERN_DEBUG "ICALLslv: %s\n", lp->name);
2096 printk(KERN_DEBUG "master=%s\n", mlp->name);
2097 if (mlp->flags & ISDN_NET_CONNECTED) {
2098 printk(KERN_DEBUG "master online\n");
2099 /* Master is online, find parent-slave (master if first slave) */
2100 while (mlp->slave) {
2101 if ((isdn_net_local *) mlp->slave->priv == lp)
2102 break;
2103 mlp = (isdn_net_local *) mlp->slave->priv;
2105 } else
2106 printk(KERN_DEBUG "master offline\n");
2107 /* Found parent, if it's offline iterate next device */
2108 printk(KERN_DEBUG "mlpf: %d\n", mlp->flags & ISDN_NET_CONNECTED);
2109 if (!(mlp->flags & ISDN_NET_CONNECTED)) {
2110 p = (isdn_net_dev *) p->next;
2111 continue;
2114 if (lp->flags & ISDN_NET_CALLBACK) {
2115 int chi;
2117 * Is the state MANUAL?
2118 * If so, no callback can be made,
2119 * so reject actively.
2120 * */
2121 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2122 restore_flags(flags);
2123 printk(KERN_INFO "incoming call for callback, interface %s `off' -> rejected\n",
2124 lp->name);
2125 return 3;
2127 printk(KERN_DEBUG "%s: call from %s -> %s, start callback\n",
2128 lp->name, nr, eaz);
2129 if (lp->phone[1]) {
2130 /* Grab a free ISDN-Channel */
2131 if ((chi =
2132 isdn_get_free_channel(
2133 ISDN_USAGE_NET,
2134 lp->l2_proto,
2135 lp->l3_proto,
2136 lp->pre_device,
2137 lp->pre_channel,
2138 lp->msn)
2139 ) < 0) {
2141 printk(KERN_WARNING "isdn_net_find_icall: No channel for %s\n", lp->name);
2142 restore_flags(flags);
2143 return 0;
2145 /* Setup dialstate. */
2146 lp->dtimer = 0;
2147 lp->dialstate = 11;
2148 /* Connect interface with channel */
2149 isdn_net_bind_channel(lp, chi);
2150 #ifdef CONFIG_ISDN_PPP
2151 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2152 if (isdn_ppp_bind(lp) < 0) {
2153 isdn_net_unbind_channel(lp);
2154 restore_flags(flags);
2155 return 0;
2157 #endif
2158 /* Initiate dialing by returning 2 or 4 */
2159 restore_flags(flags);
2160 return (lp->flags & ISDN_NET_CBHUP) ? 2 : 4;
2161 } else
2162 printk(KERN_WARNING "isdn_net: %s: No phone number\n", lp->name);
2163 restore_flags(flags);
2164 return 0;
2165 } else {
2166 printk(KERN_DEBUG "%s: call from %s -> %s accepted\n", lp->name, nr,
2167 eaz);
2168 /* if this interface is dialing, it does it probably on a different
2169 device, so free this device */
2170 if ((lp->dialstate == 4) || (lp->dialstate == 12)) {
2171 #ifdef CONFIG_ISDN_PPP
2172 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2173 isdn_ppp_free(lp);
2174 #endif
2175 isdn_net_lp_disconnected(lp);
2176 isdn_free_channel(lp->isdn_device, lp->isdn_channel,
2177 ISDN_USAGE_NET);
2179 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2180 dev->usage[idx] |= ISDN_USAGE_NET;
2181 strcpy(dev->num[idx], nr);
2182 isdn_info_update();
2183 dev->st_netdev[idx] = lp->netdev;
2184 lp->isdn_device = di;
2185 lp->isdn_channel = ch;
2186 lp->ppp_slot = -1;
2187 lp->flags |= ISDN_NET_CONNECTED;
2188 lp->dialstate = 7;
2189 lp->dtimer = 0;
2190 lp->outgoing = 0;
2191 lp->huptimer = 0;
2192 lp->hupflags |= ISDN_WAITCHARGE;
2193 lp->hupflags &= ~ISDN_HAVECHARGE;
2194 #ifdef CONFIG_ISDN_PPP
2195 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2196 if (isdn_ppp_bind(lp) < 0) {
2197 isdn_net_unbind_channel(lp);
2198 restore_flags(flags);
2199 return 0;
2201 #endif
2202 restore_flags(flags);
2203 return 1;
2207 p = (isdn_net_dev *) p->next;
2209 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2210 if (!ematch || dev->net_verbose)
2211 printk(KERN_INFO "isdn_net: call from %s -> %d %s ignored\n", nr, di, eaz);
2212 restore_flags(flags);
2213 return (wret == 2)?5:0;
2217 * Search list of net-interfaces for an interface with given name.
2219 isdn_net_dev *
2220 isdn_net_findif(char *name)
2222 isdn_net_dev *p = dev->netdev;
2224 while (p) {
2225 if (!strcmp(p->local->name, name))
2226 return p;
2227 p = (isdn_net_dev *) p->next;
2229 return (isdn_net_dev *) NULL;
2233 * Force a net-interface to dial out.
2234 * This is called from the userlevel-routine below or
2235 * from isdn_net_start_xmit().
2238 isdn_net_force_dial_lp(isdn_net_local * lp)
2240 if ((!(lp->flags & ISDN_NET_CONNECTED)) && !lp->dialstate) {
2241 int chi;
2242 if (lp->phone[1]) {
2243 ulong flags;
2244 save_flags(flags);
2245 cli();
2247 /* Grab a free ISDN-Channel */
2248 if ((chi =
2249 isdn_get_free_channel(
2250 ISDN_USAGE_NET,
2251 lp->l2_proto,
2252 lp->l3_proto,
2253 lp->pre_device,
2254 lp->pre_channel,
2255 lp->msn)
2256 ) < 0) {
2257 printk(KERN_WARNING "isdn_net_force_dial: No channel for %s\n", lp->name);
2258 restore_flags(flags);
2259 return -EAGAIN;
2261 lp->dialstate = 1;
2262 /* Connect interface with channel */
2263 isdn_net_bind_channel(lp, chi);
2264 #ifdef CONFIG_ISDN_PPP
2265 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2266 if (isdn_ppp_bind(lp) < 0) {
2267 isdn_net_unbind_channel(lp);
2268 restore_flags(flags);
2269 return -EAGAIN;
2271 #endif
2272 /* Initiate dialing */
2273 restore_flags(flags);
2274 isdn_net_dial();
2275 return 0;
2276 } else
2277 return -EINVAL;
2278 } else
2279 return -EBUSY;
2283 * This is called from certain upper protocol layers (multilink ppp
2284 * and x25iface encapsulation module) that want to initiate dialing
2285 * themselves.
2288 isdn_net_dial_req(isdn_net_local * lp)
2290 /* is there a better error code? */
2291 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) return -EBUSY;
2293 return isdn_net_force_dial_lp(lp);
2297 * Force a net-interface to dial out.
2298 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2301 isdn_net_force_dial(char *name)
2303 isdn_net_dev *p = isdn_net_findif(name);
2305 if (!p)
2306 return -ENODEV;
2307 return (isdn_net_force_dial_lp(p->local));
2311 * Allocate a new network-interface and initialize its data structures.
2313 char *
2314 isdn_net_new(char *name, struct net_device *master)
2316 isdn_net_dev *netdev;
2318 /* Avoid creating an existing interface */
2319 if (isdn_net_findif(name)) {
2320 printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
2321 return NULL;
2323 if (!(netdev = (isdn_net_dev *) kmalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
2324 printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
2325 return NULL;
2327 memset(netdev, 0, sizeof(isdn_net_dev));
2328 if (!(netdev->local = (isdn_net_local *) kmalloc(sizeof(isdn_net_local), GFP_KERNEL))) {
2329 printk(KERN_WARNING "isdn_net: Could not allocate device locals\n");
2330 return NULL;
2332 memset(netdev->local, 0, sizeof(isdn_net_local));
2333 if (name == NULL)
2334 strcpy(netdev->local->name, " ");
2335 else
2336 strcpy(netdev->local->name, name);
2337 strcpy(netdev->dev.name, netdev->local->name);
2338 netdev->dev.priv = netdev->local;
2339 netdev->dev.init = isdn_net_init;
2340 netdev->local->p_encap = ISDN_NET_ENCAP_RAWIP;
2341 if (master) {
2342 /* Device shall be a slave */
2343 struct net_device *p = (((isdn_net_local *) master->priv)->slave);
2344 struct net_device *q = master;
2346 netdev->local->master = master;
2347 /* Put device at end of slave-chain */
2348 while (p) {
2349 q = p;
2350 p = (((isdn_net_local *) p->priv)->slave);
2352 ((isdn_net_local *) q->priv)->slave = &(netdev->dev);
2353 } else {
2354 /* Device shall be a master */
2356 * Watchdog timer (currently) for master only.
2358 netdev->dev.tx_timeout = isdn_net_tx_timeout;
2359 netdev->dev.watchdog_timeo = ISDN_NET_TX_TIMEOUT;
2360 if (register_netdev(&netdev->dev) != 0) {
2361 printk(KERN_WARNING "isdn_net: Could not register net-device\n");
2362 kfree(netdev->local);
2363 kfree(netdev);
2364 return NULL;
2367 netdev->local->magic = ISDN_NET_MAGIC;
2369 netdev->queue = netdev->local;
2370 spin_lock_init(&netdev->queue_lock);
2372 netdev->local->last = netdev->local;
2373 netdev->local->netdev = netdev;
2374 netdev->local->next = netdev->local;
2376 memset(&netdev->local->tqueue, 0, sizeof(struct tq_struct));
2377 netdev->local->tqueue.routine = isdn_net_softint;
2378 netdev->local->tqueue.data = netdev->local;
2379 spin_lock_init(&netdev->local->xmit_lock);
2381 netdev->local->isdn_device = -1;
2382 netdev->local->isdn_channel = -1;
2383 netdev->local->pre_device = -1;
2384 netdev->local->pre_channel = -1;
2385 netdev->local->exclusive = -1;
2386 netdev->local->ppp_slot = -1;
2387 netdev->local->pppbind = -1;
2388 skb_queue_head_init(&netdev->local->super_tx_queue);
2389 netdev->local->l2_proto = ISDN_PROTO_L2_X75I;
2390 netdev->local->l3_proto = ISDN_PROTO_L3_TRANS;
2391 netdev->local->triggercps = 6000;
2392 netdev->local->slavedelay = 10 * HZ;
2393 netdev->local->hupflags = ISDN_INHUP; /* Do hangup even on incoming calls */
2394 netdev->local->onhtime = 10; /* Default hangup-time for saving costs
2395 of those who forget configuring this */
2396 netdev->local->dialmax = 1;
2397 netdev->local->flags = ISDN_NET_CBHUP | ISDN_NET_DM_MANUAL; /* Hangup before Callback, manual dial */
2398 netdev->local->cbdelay = 25; /* Wait 5 secs before Callback */
2399 netdev->local->dialtimeout = -1; /* Infinite Dial-Timeout */
2400 netdev->local->dialwait = 5 * HZ; /* Wait 5 sec. after failed dial */
2401 netdev->local->dialstarted = 0; /* Jiffies of last dial-start */
2402 netdev->local->dialwait_timer = 0; /* Jiffies of earliest next dial-start */
2404 /* Put into to netdev-chain */
2405 netdev->next = (void *) dev->netdev;
2406 dev->netdev = netdev;
2407 return netdev->dev.name;
2410 char *
2411 isdn_net_newslave(char *parm)
2413 char *p = strchr(parm, ',');
2414 isdn_net_dev *n;
2415 char newname[10];
2417 if (p) {
2418 /* Slave-Name MUST not be empty */
2419 if (!strlen(p + 1))
2420 return NULL;
2421 strcpy(newname, p + 1);
2422 *p = 0;
2423 /* Master must already exist */
2424 if (!(n = isdn_net_findif(parm)))
2425 return NULL;
2426 /* Master must be a real interface, not a slave */
2427 if (n->local->master)
2428 return NULL;
2429 /* Master must not be started yet */
2430 if (isdn_net_device_started(n))
2431 return NULL;
2432 return (isdn_net_new(newname, &(n->dev)));
2434 return NULL;
2438 * Set interface-parameters.
2439 * Always set all parameters, so the user-level application is responsible
2440 * for not overwriting existing setups. It has to get the current
2441 * setup first, if only selected parameters are to be changed.
2444 isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
2446 isdn_net_dev *p = isdn_net_findif(cfg->name);
2447 ulong features;
2448 int i;
2449 int drvidx;
2450 int chidx;
2451 char drvid[25];
2452 #ifdef CONFIG_ISDN_X25
2453 ulong flags;
2454 #endif
2455 if (p) {
2456 isdn_net_local *lp = p->local;
2458 /* See if any registered driver supports the features we want */
2459 features = ((1 << cfg->l2_proto) << ISDN_FEATURE_L2_SHIFT) |
2460 ((1 << cfg->l3_proto) << ISDN_FEATURE_L3_SHIFT);
2461 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2462 if (dev->drv[i])
2463 if ((dev->drv[i]->interface->features & features) == features)
2464 break;
2465 if (i == ISDN_MAX_DRIVERS) {
2466 printk(KERN_WARNING "isdn_net: No driver with selected features\n");
2467 return -ENODEV;
2469 if (lp->p_encap != cfg->p_encap){
2470 #ifdef CONFIG_ISDN_X25
2471 struct concap_proto * cprot = p -> cprot;
2472 #endif
2473 if (isdn_net_device_started(p)) {
2474 printk(KERN_WARNING "%s: cannot change encap when if is up\n",
2475 lp->name);
2476 return -EBUSY;
2478 #ifdef CONFIG_ISDN_X25
2479 /* delete old encapsulation protocol if present ... */
2480 save_flags(flags);
2481 cli(); /* avoid races with incoming events trying to
2482 call cprot->pops methods */
2483 if( cprot && cprot -> pops )
2484 cprot -> pops -> proto_del ( cprot );
2485 p -> cprot = NULL;
2486 lp -> dops = NULL;
2487 restore_flags(flags);
2488 /* ... , prepare for configuration of new one ... */
2489 switch ( cfg -> p_encap ){
2490 case ISDN_NET_ENCAP_X25IFACE:
2491 lp -> dops = &isdn_concap_reliable_dl_dops;
2493 /* ... and allocate new one ... */
2494 p -> cprot = isdn_concap_new( cfg -> p_encap );
2495 /* p -> cprot == NULL now if p_encap is not supported
2496 by means of the concap_proto mechanism */
2497 /* the protocol is not configured yet; this will
2498 happen later when isdn_net_reset() is called */
2499 #endif
2501 switch ( cfg->p_encap ) {
2502 case ISDN_NET_ENCAP_SYNCPPP:
2503 #ifndef CONFIG_ISDN_PPP
2504 printk(KERN_WARNING "%s: SyncPPP support not configured\n",
2505 lp->name);
2506 return -EINVAL;
2507 #else
2508 p->dev.type = ARPHRD_PPP; /* change ARP type */
2509 p->dev.addr_len = 0;
2510 #endif
2511 break;
2512 case ISDN_NET_ENCAP_X25IFACE:
2513 #ifndef CONFIG_ISDN_X25
2514 printk(KERN_WARNING "%s: isdn-x25 support not configured\n",
2515 p->local->name);
2516 return -EINVAL;
2517 #else
2518 p->dev.type = ARPHRD_X25; /* change ARP type */
2519 p->dev.addr_len = 0;
2520 #endif
2521 break;
2522 default:
2523 if( cfg->p_encap >= 0 &&
2524 cfg->p_encap <= ISDN_NET_ENCAP_MAX_ENCAP )
2525 break;
2526 printk(KERN_WARNING
2527 "%s: encapsulation protocol %d not supported\n",
2528 p->local->name, cfg->p_encap);
2529 return -EINVAL;
2531 if (strlen(cfg->drvid)) {
2532 /* A bind has been requested ... */
2533 char *c,
2536 drvidx = -1;
2537 chidx = -1;
2538 strcpy(drvid, cfg->drvid);
2539 if ((c = strchr(drvid, ','))) {
2540 /* The channel-number is appended to the driver-Id with a comma */
2541 chidx = (int) simple_strtoul(c + 1, &e, 10);
2542 if (e == c)
2543 chidx = -1;
2544 *c = '\0';
2546 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2547 /* Lookup driver-Id in array */
2548 if (!(strcmp(dev->drvid[i], drvid))) {
2549 drvidx = i;
2550 break;
2552 if ((drvidx == -1) || (chidx == -1))
2553 /* Either driver-Id or channel-number invalid */
2554 return -ENODEV;
2555 } else {
2556 /* Parameters are valid, so get them */
2557 drvidx = lp->pre_device;
2558 chidx = lp->pre_channel;
2560 if (cfg->exclusive > 0) {
2561 int flags;
2563 /* If binding is exclusive, try to grab the channel */
2564 save_flags(flags);
2565 if ((i = isdn_get_free_channel(ISDN_USAGE_NET,
2566 lp->l2_proto, lp->l3_proto, drvidx,
2567 chidx, lp->msn)) < 0) {
2568 /* Grab failed, because desired channel is in use */
2569 lp->exclusive = -1;
2570 restore_flags(flags);
2571 return -EBUSY;
2573 /* All went ok, so update isdninfo */
2574 dev->usage[i] = ISDN_USAGE_EXCLUSIVE;
2575 isdn_info_update();
2576 restore_flags(flags);
2577 lp->exclusive = i;
2578 } else {
2579 /* Non-exclusive binding or unbind. */
2580 lp->exclusive = -1;
2581 if ((lp->pre_device != -1) && (cfg->exclusive == -1)) {
2582 isdn_unexclusive_channel(lp->pre_device, lp->pre_channel);
2583 isdn_free_channel(lp->pre_device, lp->pre_channel, ISDN_USAGE_NET);
2584 drvidx = -1;
2585 chidx = -1;
2588 strcpy(lp->msn, cfg->eaz);
2589 lp->pre_device = drvidx;
2590 lp->pre_channel = chidx;
2591 lp->onhtime = cfg->onhtime;
2592 lp->charge = cfg->charge;
2593 lp->l2_proto = cfg->l2_proto;
2594 lp->l3_proto = cfg->l3_proto;
2595 lp->cbdelay = cfg->cbdelay;
2596 lp->dialmax = cfg->dialmax;
2597 lp->triggercps = cfg->triggercps;
2598 lp->slavedelay = cfg->slavedelay * HZ;
2599 lp->pppbind = cfg->pppbind;
2600 lp->dialtimeout = cfg->dialtimeout >= 0 ? cfg->dialtimeout * HZ : -1;
2601 lp->dialwait = cfg->dialwait * HZ;
2602 if (cfg->secure)
2603 lp->flags |= ISDN_NET_SECURE;
2604 else
2605 lp->flags &= ~ISDN_NET_SECURE;
2606 if (cfg->cbhup)
2607 lp->flags |= ISDN_NET_CBHUP;
2608 else
2609 lp->flags &= ~ISDN_NET_CBHUP;
2610 switch (cfg->callback) {
2611 case 0:
2612 lp->flags &= ~(ISDN_NET_CALLBACK | ISDN_NET_CBOUT);
2613 break;
2614 case 1:
2615 lp->flags |= ISDN_NET_CALLBACK;
2616 lp->flags &= ~ISDN_NET_CBOUT;
2617 break;
2618 case 2:
2619 lp->flags |= ISDN_NET_CBOUT;
2620 lp->flags &= ~ISDN_NET_CALLBACK;
2621 break;
2623 lp->flags &= ~ISDN_NET_DIALMODE_MASK; /* first all bits off */
2624 if (cfg->dialmode && !(cfg->dialmode & ISDN_NET_DIALMODE_MASK)) {
2625 /* old isdnctrl version, where only 0 or 1 is given */
2626 printk(KERN_WARNING
2627 "Old isdnctrl version detected! Please update.\n");
2628 lp->flags |= ISDN_NET_DM_OFF; /* turn on `off' bit */
2630 else {
2631 lp->flags |= cfg->dialmode; /* turn on selected bits */
2633 if (cfg->chargehup)
2634 lp->hupflags |= ISDN_CHARGEHUP;
2635 else
2636 lp->hupflags &= ~ISDN_CHARGEHUP;
2637 if (cfg->ihup)
2638 lp->hupflags |= ISDN_INHUP;
2639 else
2640 lp->hupflags &= ~ISDN_INHUP;
2641 if (cfg->chargeint > 10) {
2642 lp->hupflags |= ISDN_CHARGEHUP | ISDN_HAVECHARGE | ISDN_MANCHARGE;
2643 lp->chargeint = cfg->chargeint * HZ;
2645 if (cfg->p_encap != lp->p_encap) {
2646 if (cfg->p_encap == ISDN_NET_ENCAP_RAWIP) {
2647 p->dev.hard_header = NULL;
2648 p->dev.hard_header_cache = NULL;
2649 p->dev.header_cache_update = NULL;
2650 p->dev.flags = IFF_NOARP|IFF_POINTOPOINT;
2651 } else {
2652 p->dev.hard_header = isdn_net_header;
2653 if (cfg->p_encap == ISDN_NET_ENCAP_ETHER) {
2654 p->dev.hard_header_cache = lp->org_hhc;
2655 p->dev.header_cache_update = lp->org_hcu;
2656 p->dev.flags = IFF_BROADCAST | IFF_MULTICAST;
2657 } else {
2658 p->dev.hard_header_cache = NULL;
2659 p->dev.header_cache_update = NULL;
2660 p->dev.flags = IFF_NOARP|IFF_POINTOPOINT;
2664 lp->p_encap = cfg->p_encap;
2665 return 0;
2667 return -ENODEV;
2671 * Perform get-interface-parameters.ioctl
2674 isdn_net_getcfg(isdn_net_ioctl_cfg * cfg)
2676 isdn_net_dev *p = isdn_net_findif(cfg->name);
2678 if (p) {
2679 isdn_net_local *lp = p->local;
2681 strcpy(cfg->eaz, lp->msn);
2682 cfg->exclusive = lp->exclusive;
2683 if (lp->pre_device >= 0) {
2684 sprintf(cfg->drvid, "%s,%d", dev->drvid[lp->pre_device],
2685 lp->pre_channel);
2686 } else
2687 cfg->drvid[0] = '\0';
2688 cfg->onhtime = lp->onhtime;
2689 cfg->charge = lp->charge;
2690 cfg->l2_proto = lp->l2_proto;
2691 cfg->l3_proto = lp->l3_proto;
2692 cfg->p_encap = lp->p_encap;
2693 cfg->secure = (lp->flags & ISDN_NET_SECURE) ? 1 : 0;
2694 cfg->callback = 0;
2695 if (lp->flags & ISDN_NET_CALLBACK)
2696 cfg->callback = 1;
2697 if (lp->flags & ISDN_NET_CBOUT)
2698 cfg->callback = 2;
2699 cfg->cbhup = (lp->flags & ISDN_NET_CBHUP) ? 1 : 0;
2700 cfg->dialmode = lp->flags & ISDN_NET_DIALMODE_MASK;
2701 cfg->chargehup = (lp->hupflags & 4) ? 1 : 0;
2702 cfg->ihup = (lp->hupflags & 8) ? 1 : 0;
2703 cfg->cbdelay = lp->cbdelay;
2704 cfg->dialmax = lp->dialmax;
2705 cfg->triggercps = lp->triggercps;
2706 cfg->slavedelay = lp->slavedelay / HZ;
2707 cfg->chargeint = (lp->hupflags & ISDN_CHARGEHUP) ?
2708 (lp->chargeint / HZ) : 0;
2709 cfg->pppbind = lp->pppbind;
2710 cfg->dialtimeout = lp->dialtimeout >= 0 ? lp->dialtimeout / HZ : -1;
2711 cfg->dialwait = lp->dialwait / HZ;
2712 if (lp->slave)
2713 strcpy(cfg->slave, ((isdn_net_local *) lp->slave->priv)->name);
2714 else
2715 cfg->slave[0] = '\0';
2716 if (lp->master)
2717 strcpy(cfg->master, ((isdn_net_local *) lp->master->priv)->name);
2718 else
2719 cfg->master[0] = '\0';
2720 return 0;
2722 return -ENODEV;
2726 * Add a phone-number to an interface.
2729 isdn_net_addphone(isdn_net_ioctl_phone * phone)
2731 isdn_net_dev *p = isdn_net_findif(phone->name);
2732 isdn_net_phone *n;
2734 if (p) {
2735 if (!(n = (isdn_net_phone *) kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
2736 return -ENOMEM;
2737 strcpy(n->num, phone->phone);
2738 n->next = p->local->phone[phone->outgoing & 1];
2739 p->local->phone[phone->outgoing & 1] = n;
2740 return 0;
2742 return -ENODEV;
2746 * Copy a string of all phone-numbers of an interface to user space.
2747 * This might sleep and must be called with the isdn semaphore down.
2750 isdn_net_getphones(isdn_net_ioctl_phone * phone, char *phones)
2752 isdn_net_dev *p = isdn_net_findif(phone->name);
2753 int inout = phone->outgoing & 1;
2754 int more = 0;
2755 int count = 0;
2756 isdn_net_phone *n;
2758 if (!p)
2759 return -ENODEV;
2760 inout &= 1;
2761 for (n = p->local->phone[inout]; n; n = n->next) {
2762 if (more) {
2763 put_user(' ', phones++);
2764 count++;
2766 if (copy_to_user(phones, n->num, strlen(n->num) + 1)) {
2767 return -EFAULT;
2769 phones += strlen(n->num);
2770 count += strlen(n->num);
2771 more = 1;
2773 put_user(0, phones);
2774 count++;
2775 return count;
2779 * Copy a string containing the peer's phone number of a connected interface
2780 * to user space.
2783 isdn_net_getpeer(isdn_net_ioctl_phone *phone, isdn_net_ioctl_phone *peer)
2785 isdn_net_dev *p = isdn_net_findif(phone->name);
2786 int ch, dv, idx;
2788 if (!p) return -ENODEV;
2790 * Theoretical race: while this executes, the remote number might
2791 * become invalid (hang up) or change (new connection), resulting
2792 * in (partially) wrong number copied to user. This race
2793 * currently ignored.
2795 ch = p->local->isdn_channel;
2796 dv = p->local->isdn_device;
2797 if(ch<0 && dv<0) return -ENOTCONN;
2798 idx = isdn_dc2minor(dv, ch);
2799 if (idx<0) return -ENODEV;
2800 /* for pre-bound channels, we need this extra check */
2801 if ( strncmp(dev->num[idx],"???",3) == 0 ) return -ENOTCONN;
2802 strncpy(phone->phone,dev->num[idx],ISDN_MSNLEN);
2803 phone->outgoing=USG_OUTGOING(dev->usage[idx]);
2804 if ( copy_to_user(peer,phone,sizeof(*peer)) ) return -EFAULT;
2805 return 0;
2808 * Delete a phone-number from an interface.
2811 isdn_net_delphone(isdn_net_ioctl_phone * phone)
2813 isdn_net_dev *p = isdn_net_findif(phone->name);
2814 int inout = phone->outgoing & 1;
2815 isdn_net_phone *n;
2816 isdn_net_phone *m;
2817 int flags;
2819 if (p) {
2820 save_flags(flags);
2821 cli();
2822 n = p->local->phone[inout];
2823 m = NULL;
2824 while (n) {
2825 if (!strcmp(n->num, phone->phone)) {
2826 if (p->local->dial == n)
2827 p->local->dial = n->next;
2828 if (m)
2829 m->next = n->next;
2830 else
2831 p->local->phone[inout] = n->next;
2832 kfree(n);
2833 restore_flags(flags);
2834 return 0;
2836 m = n;
2837 n = (isdn_net_phone *) n->next;
2839 restore_flags(flags);
2840 return -EINVAL;
2842 return -ENODEV;
2846 * Delete all phone-numbers of an interface.
2848 static int
2849 isdn_net_rmallphone(isdn_net_dev * p)
2851 isdn_net_phone *n;
2852 isdn_net_phone *m;
2853 int flags;
2854 int i;
2856 save_flags(flags);
2857 cli();
2858 for (i = 0; i < 2; i++) {
2859 n = p->local->phone[i];
2860 while (n) {
2861 m = n->next;
2862 kfree(n);
2863 n = m;
2865 p->local->phone[i] = NULL;
2867 p->local->dial = NULL;
2868 restore_flags(flags);
2869 return 0;
2873 * Force a hangup of a network-interface.
2876 isdn_net_force_hangup(char *name)
2878 isdn_net_dev *p = isdn_net_findif(name);
2879 struct net_device *q;
2881 if (p) {
2882 if (p->local->isdn_device < 0)
2883 return 1;
2884 q = p->local->slave;
2885 /* If this interface has slaves, do a hangup for them also. */
2886 while (q) {
2887 isdn_net_hangup(q);
2888 q = (((isdn_net_local *) q->priv)->slave);
2890 isdn_net_hangup(&p->dev);
2891 return 0;
2893 return -ENODEV;
2897 * Helper-function for isdn_net_rm: Do the real work.
2899 static int
2900 isdn_net_realrm(isdn_net_dev * p, isdn_net_dev * q)
2902 int flags;
2904 save_flags(flags);
2905 cli();
2906 if (isdn_net_device_started(p)) {
2907 restore_flags(flags);
2908 return -EBUSY;
2910 #ifdef CONFIG_ISDN_X25
2911 if( p -> cprot && p -> cprot -> pops )
2912 p -> cprot -> pops -> proto_del ( p -> cprot );
2913 #endif
2914 /* Free all phone-entries */
2915 isdn_net_rmallphone(p);
2916 /* If interface is bound exclusive, free channel-usage */
2917 if (p->local->exclusive != -1)
2918 isdn_unexclusive_channel(p->local->pre_device, p->local->pre_channel);
2919 if (p->local->master) {
2920 /* It's a slave-device, so update master's slave-pointer if necessary */
2921 if (((isdn_net_local *) (p->local->master->priv))->slave == &p->dev)
2922 ((isdn_net_local *) (p->local->master->priv))->slave = p->local->slave;
2923 } else {
2924 /* Unregister only if it's a master-device */
2925 p->dev.hard_header_cache = p->local->org_hhc;
2926 p->dev.header_cache_update = p->local->org_hcu;
2927 unregister_netdev(&p->dev);
2929 /* Unlink device from chain */
2930 if (q)
2931 q->next = p->next;
2932 else
2933 dev->netdev = p->next;
2934 if (p->local->slave) {
2935 /* If this interface has a slave, remove it also */
2936 char *slavename = ((isdn_net_local *) (p->local->slave->priv))->name;
2937 isdn_net_dev *n = dev->netdev;
2938 q = NULL;
2939 while (n) {
2940 if (!strcmp(n->local->name, slavename)) {
2941 isdn_net_realrm(n, q);
2942 break;
2944 q = n;
2945 n = (isdn_net_dev *) n->next;
2948 /* If no more net-devices remain, disable auto-hangup timer */
2949 if (dev->netdev == NULL)
2950 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
2951 restore_flags(flags);
2952 kfree(p->local);
2953 kfree(p);
2955 return 0;
2959 * Remove a single network-interface.
2962 isdn_net_rm(char *name)
2964 isdn_net_dev *p;
2965 isdn_net_dev *q;
2967 /* Search name in netdev-chain */
2968 p = dev->netdev;
2969 q = NULL;
2970 while (p) {
2971 if (!strcmp(p->local->name, name))
2972 return (isdn_net_realrm(p, q));
2973 q = p;
2974 p = (isdn_net_dev *) p->next;
2976 /* If no more net-devices remain, disable auto-hangup timer */
2977 if (dev->netdev == NULL)
2978 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
2979 return -ENODEV;
2983 * Remove all network-interfaces
2986 isdn_net_rmall(void)
2988 int flags;
2989 int ret;
2991 /* Walk through netdev-chain */
2992 save_flags(flags);
2993 cli();
2994 while (dev->netdev) {
2995 if (!dev->netdev->local->master) {
2996 /* Remove master-devices only, slaves get removed with their master */
2997 if ((ret = isdn_net_realrm(dev->netdev, NULL))) {
2998 restore_flags(flags);
2999 return ret;
3003 dev->netdev = NULL;
3004 restore_flags(flags);
3005 return 0;