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)
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>
31 #include <net/pkt_sched.h>
32 #include <linux/inetdevice.h>
33 #include "isdn_common.h"
35 #ifdef CONFIG_ISDN_PPP
38 #ifdef CONFIG_ISDN_X25
39 #include <linux/concap.h>
40 #include "isdn_concap.h"
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.
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_*
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
;
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
)
94 netif_wake_queue(lp
->master
);
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
)
106 netif_stop_queue(lp
->master
);
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)
116 static __inline__
int isdn_net_device_busy(isdn_net_local
*lp
)
122 if (!isdn_net_lp_busy(lp
))
126 nd
= ((isdn_net_local
*) lp
->master
->priv
)->netdev
;
130 spin_lock_irqsave(&nd
->queue_lock
, flags
);
133 if (!isdn_net_lp_busy(nlp
)) {
134 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
139 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
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
);
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
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)
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
191 isdn_net_unreachable(struct net_device
*dev
, struct sk_buff
*skb
, char *reason
)
196 u_short proto
= ntohs(skb
->protocol
);
198 printk(KERN_DEBUG
"isdn_net: %s: %s, signalling dst_link_failure %s\n",
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",
208 (reason
!= NULL
) ? reason
: "reason unknown");
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
;
223 /* not sure if the cli() is needed at all --KG */
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
);
230 restore_flags(flags
);
233 /* Open/initialize the board. */
235 isdn_net_open(struct net_device
*dev
)
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
);
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
;
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
))) {
264 p
= (((isdn_net_local
*) p
->priv
)->slave
);
267 isdn_MOD_INC_USE_COUNT();
272 * Assign an ISDN-channel to a net-interface
275 isdn_net_bind_channel(isdn_net_local
* lp
, int idx
)
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)
293 isdn_net_unbind_channel(isdn_net_local
* lp
)
300 while ((skb
= skb_dequeue(&lp
->super_tx_queue
))) {
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
);
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.
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
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
;
339 isdn_net_dev
*p
= dev
->netdev
;
344 isdn_net_local
*l
= p
->local
;
345 if ((jiffies
- last_jiffies
) == 0)
346 l
->cps
= l
->transcount
;
348 l
->cps
= (l
->transcount
* HZ
) / (jiffies
- last_jiffies
);
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
)) {
356 * if there is some dialmode where timeout-hangup
357 * should _not_ be done, check for that here
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
) {
377 "isdn_net: %s: chtime = %lu, chint = %d\n",
378 l
->name
, l
->chargetime
, l
->chargeint
);
379 isdn_net_hangup(&p
->dev
);
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
);
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
;
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;
422 case ISDN_STAT_BSENT
:
423 /* A packet has successfully been sent out */
424 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
426 isdn_net_dec_frame_cnt(lp
);
427 lp
->stats
.tx_packets
++;
428 lp
->stats
.tx_bytes
+= c
->parm
.length
;
431 case ISDN_STAT_DCONN
:
432 /* D-Channel is up */
433 switch (lp
->dialstate
) {
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
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
)
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
,
466 isdn_net_unbind_channel(lp
);
470 #ifdef CONFIG_ISDN_X25
472 /* B-Channel-hangup */
473 /* try if there are generic encap protocol
474 receiver routines and signal the closure of
476 if( pops
&& pops
-> disconn_ind
){
477 pops
-> disconn_ind(cprot
);
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
) {
493 if (lp
->dialstate
<= 6) {
494 dev
->usage
[idx
] |= ISDN_USAGE_OUTGOING
;
497 dev
->rx_netdev
[idx
] = p
;
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 */
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
);
522 #ifdef CONFIG_ISDN_X25
523 /* try if there are generic concap receiver routines */
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
);
534 case ISDN_STAT_NODCH
:
535 /* No D-Channel avail. */
536 if (lp
->dialstate
== 4) {
542 /* Charge-info from TelCo. Calculate interval between
543 * charge-infos and set timestamp for last info for
544 * usage by isdn_net_autohup()
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
);
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.
575 isdn_net_dev
*p
= dev
->netdev
;
582 isdn_net_local
*lp
= p
->local
;
584 #ifdef ISDN_DEBUG_NET_DIAL
586 printk(KERN_DEBUG
"%s: dialstate=%d\n", lp
->name
, lp
->dialstate
);
588 switch (lp
->dialstate
) {
590 /* Nothing to do for this interface */
593 /* Initiate dialout. Set phone-number-pointer to first number
598 lp
->dial
= lp
->phone
[1];
599 restore_flags(flags
);
601 printk(KERN_WARNING
"%s: phone number deleted?\n",
603 isdn_net_hangup(&p
->dev
);
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;
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
;
622 sprintf(cmd
.parm
.num
, "%s", isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
623 cmd
.command
= ISDN_CMD_SETEAZ
;
630 /* Setup interface, dial current phone-number, switch to next number.
631 * If list of phone-numbers is exhausted, increment
634 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
)) {
636 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
637 s
= "dial suppressed: isdn system stopped";
639 s
= "dial suppressed: dialmode `off'";
640 isdn_net_unreachable(&p
->dev
, 0, s
);
641 isdn_net_hangup(&p
->dev
);
644 cmd
.driver
= lp
->isdn_device
;
645 cmd
.command
= ISDN_CMD_SETL2
;
646 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
648 cmd
.driver
= lp
->isdn_device
;
649 cmd
.command
= ISDN_CMD_SETL3
;
650 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
652 cmd
.driver
= lp
->isdn_device
;
653 cmd
.arg
= lp
->isdn_channel
;
657 restore_flags(flags
);
658 printk(KERN_WARNING
"%s: phone number deleted?\n",
660 isdn_net_hangup(&p
->dev
);
663 if (!strcmp(lp
->dial
->num
, "LEASED")) {
664 restore_flags(flags
);
666 printk(KERN_INFO
"%s: Open leased line ...\n", lp
->name
);
668 if(lp
->dialtimeout
> 0)
669 if(jiffies
> (lp
->dialstarted
+ lp
->dialtimeout
)) {
670 restore_flags(flags
);
671 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
673 isdn_net_unreachable(&p
->dev
, 0, "dial: timed out");
674 isdn_net_hangup(&p
->dev
);
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];
686 if (lp
->dialretry
> lp
->dialmax
) {
687 restore_flags(flags
);
688 if (lp
->dialtimeout
== 0) {
689 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
691 isdn_net_unreachable(&p
->dev
, 0, "dial: tried all numbers dialmax times");
693 isdn_net_hangup(&p
->dev
);
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
);
706 strcpy(dev
->num
[i
], cmd
.parm
.setup
.phone
);
709 printk(KERN_INFO
"%s: dialing %d %s...\n", lp
->name
,
710 lp
->dialretry
, cmd
.parm
.setup
.phone
);
712 #ifdef ISDN_DEBUG_NET_DIAL
713 printk(KERN_DEBUG
"dial: d=%d c=%d\n", lp
->isdn_device
,
721 lp
->hupflags
|= ISDN_HAVECHARGE
;
722 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
724 lp
->hupflags
|= ISDN_WAITCHARGE
;
725 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
730 (lp
->flags
& ISDN_NET_CBOUT
)) ? 12 : 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
)
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
;
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
);
758 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
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
);
769 cmd
.driver
= lp
->isdn_device
;
770 cmd
.command
= ISDN_CMD_SETL2
;
771 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
773 cmd
.driver
= lp
->isdn_device
;
774 cmd
.command
= ISDN_CMD_SETL3
;
775 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
777 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT15
)
778 isdn_net_hangup(&p
->dev
);
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
;
796 /* Wait for B- or D-channel-connect */
797 #ifdef ISDN_DEBUG_NET_DIAL
798 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
800 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
801 isdn_net_hangup(&p
->dev
);
807 if (lp
->dtimer
++ > lp
->cbdelay
)
812 /* Remote does callback. Hangup after cbdelay, then wait for incoming
815 if (lp
->dtimer
++ > lp
->cbdelay
)
817 printk(KERN_INFO
"%s: hangup waiting for callback ...\n", lp
->name
);
820 cmd
.driver
= lp
->isdn_device
;
821 cmd
.command
= ISDN_CMD_HANGUP
;
822 cmd
.arg
= lp
->isdn_channel
;
824 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
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.
841 isdn_net_hangup(struct net_device
*d
)
843 isdn_net_local
*lp
= (isdn_net_local
*) d
->priv
;
845 #ifdef CONFIG_ISDN_X25
846 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
847 struct concap_proto_ops
*pops
= cprot
? cprot
-> pops
: 0;
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
) {
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
)
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
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
;
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
);
885 unsigned short source
;
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
);
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
);
907 switch (lp
->p_encap
) {
908 case ISDN_NET_ENCAP_IPTYP
:
909 proto
= ntohs(*(unsigned short *) &buf
[0]);
912 case ISDN_NET_ENCAP_ETHER
:
913 proto
= ntohs(*(unsigned short *) &buf
[12]);
916 case ISDN_NET_ENCAP_CISCOHDLC
:
917 proto
= ntohs(*(unsigned short *) &buf
[2]);
920 #ifdef CONFIG_ISDN_PPP
921 case ISDN_NET_ENCAP_SYNCPPP
:
922 proto
= ntohs(skb
->protocol
);
923 p
= &buf
[IPPP_MAX_HEADER
];
928 data_ofs
= ((p
[0] & 15) * 4);
933 strcpy(addinfo
, " ICMP");
936 strcpy(addinfo
, " IGMP");
939 strcpy(addinfo
, " IPIP");
942 ipp
= (ip_ports
*) (&p
[data_ofs
]);
943 sprintf(addinfo
, " TCP, port: %d -> %d", ntohs(ipp
->source
),
947 strcpy(addinfo
, " EGP");
950 strcpy(addinfo
, " PUP");
953 ipp
= (ip_ports
*) (&p
[data_ofs
]);
954 sprintf(addinfo
, " UDP, port: %d -> %d", ntohs(ipp
->source
),
958 strcpy(addinfo
, " IDP");
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],
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]);
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
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
);
992 spin_lock_bh(&lp
->xmit_lock
);
993 if (!isdn_net_lp_busy(lp
)) {
994 isdn_net_writebuf_skb(lp
, skb
);
996 skb_queue_tail(&lp
->super_tx_queue
, skb
);
998 spin_unlock_bh(&lp
->xmit_lock
);
1002 * called from tq_immediate
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
);
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
)
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__
);
1036 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1037 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1040 ret
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
);
1042 /* we should never get here */
1043 printk(KERN_WARNING
"%s: HL driver queue full\n", lp
->name
);
1047 lp
->transcount
+= len
;
1048 isdn_net_inc_frame_cnt(lp
);
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
1066 * Return: 0 on success, !0 on failure.
1070 isdn_net_xmit(struct net_device
*ndev
, struct sk_buff
*skb
)
1073 isdn_net_local
*slp
;
1074 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1077 if (((isdn_net_local
*) (ndev
->priv
))->master
) {
1078 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
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
);
1090 nd
= ((isdn_net_local
*) ndev
->priv
)->netdev
;
1092 lp
= isdn_net_get_locked_lp(nd
);
1094 printk(KERN_WARNING
"%s: all channels busy - requeuing!\n", ndev
->name
);
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
1109 if (lp
->cps
> lp
->triggercps
) {
1112 /* First time overload: set timestamp only */
1114 lp
->sqfull_stamp
= jiffies
;
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
);
1126 if (lp
->sqfull
&& ((jiffies
- lp
->sqfull_stamp
) > (lp
->slavedelay
+ (10 * HZ
)))) {
1129 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1130 nd
->queue
= nd
->local
;
1138 isdn_net_adjust_hdr(struct sk_buff
*skb
, struct net_device
*dev
)
1140 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1143 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1144 int pullsize
= (ulong
)skb
->nh
.raw
- (ulong
)skb
->data
- ETH_HLEN
;
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
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.
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
;
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.
1206 int ret
= cprot
-> pops
-> encap_and_xmit ( cprot
, skb
);
1207 if(ret
) netif_stop_queue(ndev
);
1211 /* auto-dialing xmit function */
1213 #ifdef ISDN_DEBUG_NET_DUMP
1216 isdn_net_adjust_hdr(skb
, ndev
);
1217 #ifdef ISDN_DEBUG_NET_DUMP
1219 isdn_dumppkt("S:", buf
, skb
->len
, 40);
1221 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
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'");
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");
1242 restore_flags(flags
);
1245 lp
->dialwait_timer
= 0;
1247 /* Grab a free ISDN-Channel */
1249 isdn_get_free_channel(
1258 isdn_get_free_channel(
1266 restore_flags(flags
);
1267 isdn_net_unreachable(ndev
, skb
,
1272 /* Log packet, which triggered dialing */
1273 if (dev
->net_verbose
)
1274 isdn_net_log_skb(skb
, lp
);
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) {
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 */
1293 /* Initiate dialing */
1294 restore_flags(flags
);
1296 isdn_net_device_stop_queue(lp
);
1299 isdn_net_unreachable(ndev
, skb
,
1305 /* Device is connected to an ISDN channel */
1306 ndev
->trans_start
= jiffies
;
1307 if (!lp
->dialstate
) {
1308 /* ISDN connection is established, try sending */
1310 ret
= (isdn_net_xmit(ndev
, skb
));
1311 if(ret
) netif_stop_queue(ndev
);
1314 netif_stop_queue(ndev
);
1321 * Shutdown a net-interface.
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 ); */
1333 #ifdef CONFIG_ISDN_X25
1334 if( cprot
&& cprot
-> pops
) cprot
-> pops
-> close( cprot
);
1336 netif_stop_queue(dev
);
1337 if ((p
= (((isdn_net_local
*) dev
->priv
)->slave
))) {
1338 /* If this interface has slaves, stop them also */
1340 #ifdef CONFIG_ISDN_X25
1341 cprot
= ( (isdn_net_local
*) p
->priv
)
1343 if( cprot
&& cprot
-> pops
)
1344 cprot
-> pops
-> close( cprot
);
1347 p
= (((isdn_net_local
*) p
->priv
)->slave
);
1350 isdn_net_hangup(dev
);
1351 isdn_MOD_DEC_USE_COUNT();
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
;
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
)
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
;
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
;
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
);
1415 return htons(ETH_P_802_2
);
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);
1429 "%s: Could not allocate SLARP reply\n", lp
->name
);
1432 skb_reserve(skb
, hl
);
1433 ch
= (cisco_hdr
*)skb_put(skb
, sizeof(cisco_hdr
));
1434 ch
->addr
= CISCO_ADDR_UNICAST
;
1436 ch
->type
= htons(CISCO_TYPE_SLARP
);
1437 s
= (cisco_slarp
*)skb_put(skb
, sizeof(cisco_slarp
));
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
));
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
);
1451 isdn_net_write_super(lp
, skb
);
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);
1463 case CISCO_SLARP_REPLY
:
1464 /* Ignore replies */
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",
1472 lp
->cisco_myseq
^= jiffies
;
1482 * Called every 10 sec. via timer-interrupt if
1483 * any network-interface has Cisco-Keepalive-Encapsulation
1485 * Send Keepalive-Packet and re-schedule.
1488 isdn_net_slarp_out(void)
1490 isdn_net_dev
*p
= dev
->netdev
;
1494 isdn_net_local
*l
= p
->local
;
1495 if ((l
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
) &&
1496 (l
->flags
& ISDN_NET_CONNECTED
) &&
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.
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
);
1517 #ifdef CONFIG_ISDN_X25
1518 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
1522 lp
->transcount
+= skb
->len
;
1524 lp
->stats
.rx_packets
++;
1525 lp
->stats
.rx_bytes
+= skb
->len
;
1527 /* Bundling: If device is a slave-device, deliver to master, also
1528 * handle master's statistics and hangup-timeout
1531 lp
= (isdn_net_local
*) ndev
->priv
;
1532 lp
->stats
.rx_packets
++;
1533 lp
->stats
.rx_bytes
+= skb
->len
;
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);
1542 switch (lp
->p_encap
) {
1543 case ISDN_NET_ENCAP_ETHER
:
1544 /* Ethernet over ISDN */
1547 skb
->protocol
= isdn_net_type_trans(skb
, ndev
);
1549 case ISDN_NET_ENCAP_UIHDLC
:
1550 /* HDLC with UI-frame (for ispa with -h1 option) */
1555 case ISDN_NET_ENCAP_RAWIP
:
1556 /* RAW-IP without MAC-Header */
1559 skb
->protocol
= htons(ETH_P_IP
);
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
);
1570 if (ch
->ctrl
!= 0) {
1571 printk(KERN_WARNING
"%s: Unknown Cisco ctrl 0x%02x\n",
1572 lp
->name
, ch
->ctrl
);
1576 switch (ntohs(ch
->type
)) {
1577 case CISCO_TYPE_INET
:
1579 skb
->protocol
= htons(ETH_P_IP
);
1581 case CISCO_TYPE_SLARP
:
1583 isdn_net_slarp_in(olp
, skb
);
1586 printk(KERN_WARNING
"%s: Unknown Cisco type 0x%04x\n",
1587 lp
->name
, ch
->type
);
1592 case ISDN_NET_ENCAP_CISCOHDLC
:
1593 /* CISCO-HDLC IP with type field and fake I-frame-header */
1596 case ISDN_NET_ENCAP_IPTYP
:
1597 /* IP with type field */
1600 skb
->protocol
= *(unsigned short *) &(skb
->data
[0]);
1602 if (*(unsigned short *) skb
->data
== 0xFFFF)
1603 skb
->protocol
= htons(ETH_P_802_3
);
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
) {
1615 isdn_ppp_receive(lp
->netdev
, olp
, skb
);
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
);
1626 #endif /* CONFIG_ISDN_X25 */
1627 printk(KERN_WARNING
"%s: unknown encapsulation, dropping\n",
1638 * A packet arrived via ISDN. Search interface-chain for a corresponding
1639 * interface. If found, deliver packet to receiver-function and return 1,
1643 isdn_net_rcv_skb(int idx
, struct sk_buff
*skb
)
1645 isdn_net_dev
*p
= dev
->rx_netdev
[idx
];
1648 isdn_net_local
*lp
= p
->local
;
1649 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
1651 isdn_net_receive(&p
->dev
, skb
);
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
);
1673 eth
->h_proto
= htons(len
);
1676 * Set the source hardware address.
1679 memcpy(eth
->h_source
, saddr
, dev
->addr_len
);
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)*/;
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*/;
1700 * depends on encaps that is being used.
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
;
1710 switch (lp
->p_encap
) {
1711 case ISDN_NET_ENCAP_ETHER
:
1712 len
= my_eth_header(skb
, dev
, type
, daddr
, saddr
, plen
);
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
;
1721 case ISDN_NET_ENCAP_RAWIP
:
1722 printk(KERN_WARNING
"isdn_net_header called with RAW_IP!\n");
1725 case ISDN_NET_ENCAP_IPTYP
:
1726 /* ethernet type field */
1727 *((ushort
*) skb_push(skb
, 2)) = htons(type
);
1730 case ISDN_NET_ENCAP_UIHDLC
:
1731 /* HDLC with UI-Frames (for ispa with -h1 option) */
1732 *((ushort
*) skb_push(skb
, 2)) = htons(0x0103);
1735 case ISDN_NET_ENCAP_CISCOHDLC
:
1737 skb
->data
[0] = 0x0f;
1738 skb
->data
[1] = 0x00;
1739 *((ushort
*) & skb
->data
[2]) = htons(type
);
1742 #ifdef CONFIG_ISDN_X25
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");
1751 #endif /* CONFIG_ISDN_X25 */
1756 /* We don't need to send arp, because we have point-to-point connections. */
1758 isdn_net_rebuild_header(struct sk_buff
*skb
)
1760 struct net_device
*dev
= skb
->dev
;
1761 isdn_net_local
*lp
= dev
->priv
;
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
)) {
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
);
1779 * Try to get ARP to resolve the header.
1782 ret
= arp_find(eth
->h_dest
, skb
);
1789 * Interface-setup. (just after registering a new interface)
1792 isdn_net_init(struct net_device
*ndev
)
1794 ushort max_hlhdr_len
= 0;
1795 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1800 printk(KERN_WARNING
"isdn_net_init: dev = NULL!\n");
1803 if (ndev
->priv
== NULL
) {
1804 printk(KERN_WARNING
"isdn_net_init: dev->priv = NULL!\n");
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
;
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
;
1852 isdn_net_swapbind(int drvidx
)
1856 #ifdef ISDN_DEBUG_NET_ICALL
1857 printk(KERN_DEBUG
"n_fi: swapping ch of %d\n", drvidx
);
1861 if (p
->local
->pre_device
== drvidx
)
1862 switch (p
->local
->pre_channel
) {
1864 p
->local
->pre_channel
= 1;
1867 p
->local
->pre_channel
= 0;
1870 p
= (isdn_net_dev
*) p
->next
;
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
);
1883 dev
->usage
[i1
] &= ~ISDN_USAGE_EXCLUSIVE
;
1884 dev
->usage
[i1
] |= u2
;
1885 dev
->usage
[i2
] &= ~ISDN_USAGE_EXCLUSIVE
;
1886 dev
->usage
[i2
] |= u1
;
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
1898 * Return-Value: 0 = No appropriate interface for this call.
1900 * 2 = Reject call, wait cbdelay, then call back
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
)
1920 /* Search name in netdev-chain */
1923 if (!setup
->phone
[0]) {
1926 printk(KERN_INFO
"isdn_net: Incoming call without OAD, assuming '0'\n");
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");
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) */
1940 restore_flags(flags
);
1941 if (dev
->net_verbose
> 1)
1942 printk(KERN_INFO
"isdn_net: Service-Indicator not 7, ignored\n");
1945 n
= (isdn_net_phone
*) 0;
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
,
1954 isdn_net_local
*lp
= p
->local
;
1956 /* If last check has triggered as binding-swap, revert it */
1959 isdn_net_swap_usage(idx
, sidx
);
1962 isdn_net_swapbind(di
);
1966 if (!(matchret
= isdn_msncmp(eaz
, isdn_map_eaz2msn(lp
->msn
, di
))))
1968 /* Remember if more numbers eventually can match */
1969 if (matchret
> wret
)
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
);
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
);
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.
1999 sidx
= isdn_dc2minor(di
, 1);
2000 #ifdef ISDN_DEBUG_NET_ICALL
2001 printk(KERN_DEBUG
"n_fi: ch is 0\n");
2003 if (USG_NONE(dev
->usage
[sidx
])) {
2004 /* Second Channel is free, now see if it is bound
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");
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
);
2017 /* ... else iterate next device */
2018 p
= (isdn_net_dev
*) p
->next
;
2022 #ifdef ISDN_DEBUG_NET_ICALL
2023 printk(KERN_DEBUG
"n_fi: 2nd channel is down and unbound\n");
2025 /* No, swap always and swap excl-usage also */
2026 isdn_net_swap_usage(idx
, sidx
);
2027 isdn_net_swapbind(di
);
2030 /* Now check for exclusive binding again */
2031 #ifdef ISDN_DEBUG_NET_ICALL
2032 printk(KERN_DEBUG
"n_fi: final check\n");
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");
2040 p
= (isdn_net_dev
*) p
->next
;
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");
2052 #ifdef ISDN_DEBUG_NET_ICALL
2053 printk(KERN_DEBUG
"n_fi: match2\n");
2056 if (lp
->flags
& ISDN_NET_SECURE
) {
2058 if (!isdn_msncmp(nr
, n
->num
))
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");
2067 /* matching interface found */
2070 * Is the state STOPPED?
2071 * If so, no dialin is allowed,
2072 * so reject actively.
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",
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",
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.
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
)
2103 mlp
= (isdn_net_local
*) mlp
->slave
->priv
;
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
;
2114 if (lp
->flags
& ISDN_NET_CALLBACK
) {
2117 * Is the state MANUAL?
2118 * If so, no callback can be made,
2119 * so reject actively.
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",
2127 printk(KERN_DEBUG
"%s: call from %s -> %s, start callback\n",
2130 /* Grab a free ISDN-Channel */
2132 isdn_get_free_channel(
2141 printk(KERN_WARNING
"isdn_net_find_icall: No channel for %s\n", lp
->name
);
2142 restore_flags(flags
);
2145 /* Setup dialstate. */
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
);
2158 /* Initiate dialing by returning 2 or 4 */
2159 restore_flags(flags
);
2160 return (lp
->flags
& ISDN_NET_CBHUP
) ? 2 : 4;
2162 printk(KERN_WARNING
"isdn_net: %s: No phone number\n", lp
->name
);
2163 restore_flags(flags
);
2166 printk(KERN_DEBUG
"%s: call from %s -> %s accepted\n", lp
->name
, nr
,
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
)
2175 isdn_net_lp_disconnected(lp
);
2176 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
2179 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2180 dev
->usage
[idx
] |= ISDN_USAGE_NET
;
2181 strcpy(dev
->num
[idx
], nr
);
2183 dev
->st_netdev
[idx
] = lp
->netdev
;
2184 lp
->isdn_device
= di
;
2185 lp
->isdn_channel
= ch
;
2187 lp
->flags
|= ISDN_NET_CONNECTED
;
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
);
2202 restore_flags(flags
);
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.
2220 isdn_net_findif(char *name
)
2222 isdn_net_dev
*p
= dev
->netdev
;
2225 if (!strcmp(p
->local
->name
, name
))
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
) {
2247 /* Grab a free ISDN-Channel */
2249 isdn_get_free_channel(
2257 printk(KERN_WARNING
"isdn_net_force_dial: No channel for %s\n", lp
->name
);
2258 restore_flags(flags
);
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
);
2272 /* Initiate dialing */
2273 restore_flags(flags
);
2283 * This is called from certain upper protocol layers (multilink ppp
2284 * and x25iface encapsulation module) that want to initiate dialing
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
);
2307 return (isdn_net_force_dial_lp(p
->local
));
2311 * Allocate a new network-interface and initialize its data structures.
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
);
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");
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");
2332 memset(netdev
->local
, 0, sizeof(isdn_net_local
));
2334 strcpy(netdev
->local
->name
, " ");
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
;
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 */
2350 p
= (((isdn_net_local
*) p
->priv
)->slave
);
2352 ((isdn_net_local
*) q
->priv
)->slave
= &(netdev
->dev
);
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
);
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
;
2411 isdn_net_newslave(char *parm
)
2413 char *p
= strchr(parm
, ',');
2418 /* Slave-Name MUST not be empty */
2421 strcpy(newname
, p
+ 1);
2423 /* Master must already exist */
2424 if (!(n
= isdn_net_findif(parm
)))
2426 /* Master must be a real interface, not a slave */
2427 if (n
->local
->master
)
2429 /* Master must not be started yet */
2430 if (isdn_net_device_started(n
))
2432 return (isdn_net_new(newname
, &(n
->dev
)));
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
);
2452 #ifdef CONFIG_ISDN_X25
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
++)
2463 if ((dev
->drv
[i
]->interface
->features
& features
) == features
)
2465 if (i
== ISDN_MAX_DRIVERS
) {
2466 printk(KERN_WARNING
"isdn_net: No driver with selected features\n");
2469 if (lp
->p_encap
!= cfg
->p_encap
){
2470 #ifdef CONFIG_ISDN_X25
2471 struct concap_proto
* cprot
= p
-> cprot
;
2473 if (isdn_net_device_started(p
)) {
2474 printk(KERN_WARNING
"%s: cannot change encap when if is up\n",
2478 #ifdef CONFIG_ISDN_X25
2479 /* delete old encapsulation protocol if present ... */
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
);
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 */
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",
2508 p
->dev
.type
= ARPHRD_PPP
; /* change ARP type */
2509 p
->dev
.addr_len
= 0;
2512 case ISDN_NET_ENCAP_X25IFACE
:
2513 #ifndef CONFIG_ISDN_X25
2514 printk(KERN_WARNING
"%s: isdn-x25 support not configured\n",
2518 p
->dev
.type
= ARPHRD_X25
; /* change ARP type */
2519 p
->dev
.addr_len
= 0;
2523 if( cfg
->p_encap
>= 0 &&
2524 cfg
->p_encap
<= ISDN_NET_ENCAP_MAX_ENCAP
)
2527 "%s: encapsulation protocol %d not supported\n",
2528 p
->local
->name
, cfg
->p_encap
);
2531 if (strlen(cfg
->drvid
)) {
2532 /* A bind has been requested ... */
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);
2546 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2547 /* Lookup driver-Id in array */
2548 if (!(strcmp(dev
->drvid
[i
], drvid
))) {
2552 if ((drvidx
== -1) || (chidx
== -1))
2553 /* Either driver-Id or channel-number invalid */
2556 /* Parameters are valid, so get them */
2557 drvidx
= lp
->pre_device
;
2558 chidx
= lp
->pre_channel
;
2560 if (cfg
->exclusive
> 0) {
2563 /* If binding is exclusive, try to grab the channel */
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 */
2570 restore_flags(flags
);
2573 /* All went ok, so update isdninfo */
2574 dev
->usage
[i
] = ISDN_USAGE_EXCLUSIVE
;
2576 restore_flags(flags
);
2579 /* Non-exclusive binding or unbind. */
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
);
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
;
2603 lp
->flags
|= ISDN_NET_SECURE
;
2605 lp
->flags
&= ~ISDN_NET_SECURE
;
2607 lp
->flags
|= ISDN_NET_CBHUP
;
2609 lp
->flags
&= ~ISDN_NET_CBHUP
;
2610 switch (cfg
->callback
) {
2612 lp
->flags
&= ~(ISDN_NET_CALLBACK
| ISDN_NET_CBOUT
);
2615 lp
->flags
|= ISDN_NET_CALLBACK
;
2616 lp
->flags
&= ~ISDN_NET_CBOUT
;
2619 lp
->flags
|= ISDN_NET_CBOUT
;
2620 lp
->flags
&= ~ISDN_NET_CALLBACK
;
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 */
2627 "Old isdnctrl version detected! Please update.\n");
2628 lp
->flags
|= ISDN_NET_DM_OFF
; /* turn on `off' bit */
2631 lp
->flags
|= cfg
->dialmode
; /* turn on selected bits */
2634 lp
->hupflags
|= ISDN_CHARGEHUP
;
2636 lp
->hupflags
&= ~ISDN_CHARGEHUP
;
2638 lp
->hupflags
|= ISDN_INHUP
;
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
;
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
;
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
;
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
);
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
],
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;
2695 if (lp
->flags
& ISDN_NET_CALLBACK
)
2697 if (lp
->flags
& ISDN_NET_CBOUT
)
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
;
2713 strcpy(cfg
->slave
, ((isdn_net_local
*) lp
->slave
->priv
)->name
);
2715 cfg
->slave
[0] = '\0';
2717 strcpy(cfg
->master
, ((isdn_net_local
*) lp
->master
->priv
)->name
);
2719 cfg
->master
[0] = '\0';
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
);
2735 if (!(n
= (isdn_net_phone
*) kmalloc(sizeof(isdn_net_phone
), GFP_KERNEL
)))
2737 strcpy(n
->num
, phone
->phone
);
2738 n
->next
= p
->local
->phone
[phone
->outgoing
& 1];
2739 p
->local
->phone
[phone
->outgoing
& 1] = n
;
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;
2761 for (n
= p
->local
->phone
[inout
]; n
; n
= n
->next
) {
2763 put_user(' ', phones
++);
2766 if (copy_to_user(phones
, n
->num
, strlen(n
->num
) + 1)) {
2769 phones
+= strlen(n
->num
);
2770 count
+= strlen(n
->num
);
2773 put_user(0, phones
);
2779 * Copy a string containing the peer's phone number of a connected interface
2783 isdn_net_getpeer(isdn_net_ioctl_phone
*phone
, isdn_net_ioctl_phone
*peer
)
2785 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
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
;
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;
2822 n
= p
->local
->phone
[inout
];
2825 if (!strcmp(n
->num
, phone
->phone
)) {
2826 if (p
->local
->dial
== n
)
2827 p
->local
->dial
= n
->next
;
2831 p
->local
->phone
[inout
] = n
->next
;
2833 restore_flags(flags
);
2837 n
= (isdn_net_phone
*) n
->next
;
2839 restore_flags(flags
);
2846 * Delete all phone-numbers of an interface.
2849 isdn_net_rmallphone(isdn_net_dev
* p
)
2858 for (i
= 0; i
< 2; i
++) {
2859 n
= p
->local
->phone
[i
];
2865 p
->local
->phone
[i
] = NULL
;
2867 p
->local
->dial
= NULL
;
2868 restore_flags(flags
);
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
;
2882 if (p
->local
->isdn_device
< 0)
2884 q
= p
->local
->slave
;
2885 /* If this interface has slaves, do a hangup for them also. */
2888 q
= (((isdn_net_local
*) q
->priv
)->slave
);
2890 isdn_net_hangup(&p
->dev
);
2897 * Helper-function for isdn_net_rm: Do the real work.
2900 isdn_net_realrm(isdn_net_dev
* p
, isdn_net_dev
* q
)
2906 if (isdn_net_device_started(p
)) {
2907 restore_flags(flags
);
2910 #ifdef CONFIG_ISDN_X25
2911 if( p
-> cprot
&& p
-> cprot
-> pops
)
2912 p
-> cprot
-> pops
-> proto_del ( p
-> cprot
);
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
;
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 */
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
;
2940 if (!strcmp(n
->local
->name
, slavename
)) {
2941 isdn_net_realrm(n
, q
);
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
);
2959 * Remove a single network-interface.
2962 isdn_net_rm(char *name
)
2967 /* Search name in netdev-chain */
2971 if (!strcmp(p
->local
->name
, name
))
2972 return (isdn_net_realrm(p
, q
));
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);
2983 * Remove all network-interfaces
2986 isdn_net_rmall(void)
2991 /* Walk through netdev-chain */
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
);
3004 restore_flags(flags
);