1 /* $Id: isdn_net.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
3 * Linux ISDN subsystem, network interfaces and related functions (linklevel).
5 * Copyright 1994-1998 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
12 * Data Over Voice (DOV) support added - Guy Ellis 23-Mar-02
14 * Outgoing calls - looks for a 'V' in first char of dialed number
15 * Incoming calls - checks first character of eaz as follows:
16 * Numeric - accept DATA only - original functionality
17 * 'V' - accept VOICE (DOV) only
18 * 'B' - accept BOTH DATA and DOV types
20 * Jan 2001: fix CISCO HDLC Bjoern A. Zeeb <i4l@zabbadoz.net>
21 * for info on the protocol, see
22 * http://i4l.zabbadoz.net/i4l/cisco-hdlc.txt
25 #include <linux/config.h>
26 #include <linux/isdn.h>
29 #include <net/pkt_sched.h>
30 #include <linux/inetdevice.h>
31 #include "isdn_common.h"
33 #ifdef CONFIG_ISDN_PPP
36 #ifdef CONFIG_ISDN_X25
37 #include <linux/concap.h>
38 #include "isdn_concap.h"
43 * Outline of new tbusy handling:
45 * Old method, roughly spoken, consisted of setting tbusy when entering
46 * isdn_net_start_xmit() and at several other locations and clearing
47 * it from isdn_net_start_xmit() thread when sending was successful.
49 * With 2.3.x multithreaded network core, to prevent problems, tbusy should
50 * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
51 * condition is detected. Other threads (in particular isdn_net_stat_callb())
52 * are only allowed to clear tbusy.
59 * Most of the changes were pretty obvious and basically done by HE already.
61 * One problem of the isdn net device code is that is uses struct net_device
62 * for masters and slaves. However, only master interface are registered to
63 * the network layer, and therefore, it only makes sense to call netif_*
70 * Find out if the netdevice has been ifup-ed yet.
71 * For slaves, look at the corresponding master.
73 static __inline__
int isdn_net_device_started(isdn_net_dev
*n
)
75 isdn_net_local
*lp
= n
->local
;
76 struct net_device
*dev
;
82 return netif_running(dev
);
86 * wake up the network -> net_device queue.
87 * For slaves, wake the corresponding master interface.
89 static __inline__
void isdn_net_device_wake_queue(isdn_net_local
*lp
)
92 netif_wake_queue(lp
->master
);
94 netif_wake_queue(&lp
->netdev
->dev
);
98 * stop the network -> net_device queue.
99 * For slaves, stop the corresponding master interface.
101 static __inline__
void isdn_net_device_stop_queue(isdn_net_local
*lp
)
104 netif_stop_queue(lp
->master
);
106 netif_stop_queue(&lp
->netdev
->dev
);
110 * find out if the net_device which this lp belongs to (lp can be
111 * master or slave) is busy. It's busy iff all (master and slave)
114 static __inline__
int isdn_net_device_busy(isdn_net_local
*lp
)
120 if (!isdn_net_lp_busy(lp
))
124 nd
= ((isdn_net_local
*) lp
->master
->priv
)->netdev
;
128 spin_lock_irqsave(&nd
->queue_lock
, flags
);
131 if (!isdn_net_lp_busy(nlp
)) {
132 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
137 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
141 static __inline__
void isdn_net_inc_frame_cnt(isdn_net_local
*lp
)
143 atomic_inc(&lp
->frame_cnt
);
144 if (isdn_net_device_busy(lp
))
145 isdn_net_device_stop_queue(lp
);
148 static __inline__
void isdn_net_dec_frame_cnt(isdn_net_local
*lp
)
150 atomic_dec(&lp
->frame_cnt
);
152 if (!(isdn_net_device_busy(lp
))) {
153 if (!skb_queue_empty(&lp
->super_tx_queue
)) {
154 schedule_work(&lp
->tqueue
);
156 isdn_net_device_wake_queue(lp
);
161 static __inline__
void isdn_net_zero_frame_cnt(isdn_net_local
*lp
)
163 atomic_set(&lp
->frame_cnt
, 0);
166 /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
168 * For 2.3.x we push it up to 20 secs, because call establishment
169 * (in particular callback) may take such a long time, and we
170 * don't want confusing messages in the log. However, there is a slight
171 * possibility that this large timeout will break other things like MPPP,
172 * which might rely on the tx timeout. If so, we'll find out this way...
175 #define ISDN_NET_TX_TIMEOUT (20*HZ)
179 static int isdn_net_force_dial_lp(isdn_net_local
*);
180 static int isdn_net_start_xmit(struct sk_buff
*, struct net_device
*);
182 static void isdn_net_ciscohdlck_connected(isdn_net_local
*lp
);
183 static void isdn_net_ciscohdlck_disconnected(isdn_net_local
*lp
);
185 char *isdn_net_revision
= "$Revision: 1.1.2.2 $";
188 * Code for raw-networking over ISDN
192 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
;
221 #ifdef CONFIG_ISDN_X25
222 if( cprot
&& cprot
-> pops
&& dops
)
223 cprot
-> pops
-> restart ( cprot
, dev
, dops
);
227 /* Open/initialize the board. */
229 isdn_net_open(struct net_device
*dev
)
232 struct net_device
*p
;
233 struct in_device
*in_dev
;
235 /* moved here from isdn_net_reset, because only the master has an
236 interface associated which is supposed to be started. BTW:
237 we need to call netif_start_queue, not netif_wake_queue here */
238 netif_start_queue(dev
);
241 /* Fill in the MAC-level header (not needed, but for compatibility... */
242 for (i
= 0; i
< ETH_ALEN
- sizeof(u32
); i
++)
243 dev
->dev_addr
[i
] = 0xfc;
244 if ((in_dev
= dev
->ip_ptr
) != NULL
) {
246 * Any address will do - we take the first
248 struct in_ifaddr
*ifa
= in_dev
->ifa_list
;
250 memcpy(dev
->dev_addr
+2, &ifa
->ifa_local
, 4);
253 /* If this interface has slaves, start them also */
255 if ((p
= (((isdn_net_local
*) dev
->priv
)->slave
))) {
258 p
= (((isdn_net_local
*) p
->priv
)->slave
);
266 * Assign an ISDN-channel to a net-interface
269 isdn_net_bind_channel(isdn_net_local
* lp
, int idx
)
271 lp
->flags
|= ISDN_NET_CONNECTED
;
272 lp
->isdn_device
= dev
->drvmap
[idx
];
273 lp
->isdn_channel
= dev
->chanmap
[idx
];
274 dev
->rx_netdev
[idx
] = lp
->netdev
;
275 dev
->st_netdev
[idx
] = lp
->netdev
;
279 * unbind a net-interface (resets interface after an error)
282 isdn_net_unbind_channel(isdn_net_local
* lp
)
284 skb_queue_purge(&lp
->super_tx_queue
);
286 if (!lp
->master
) { /* reset only master device */
287 /* Moral equivalent of dev_purge_queues():
288 BEWARE! This chunk of code cannot be called from hardware
289 interrupt handler. I hope it is true. --ANK
291 qdisc_reset(lp
->netdev
->dev
.qdisc
);
294 dev
->rx_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
295 dev
->st_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
296 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
, ISDN_USAGE_NET
);
297 lp
->flags
&= ~ISDN_NET_CONNECTED
;
298 lp
->isdn_device
= -1;
299 lp
->isdn_channel
= -1;
303 * Perform auto-hangup and cps-calculation for net-interfaces.
306 * Increment idle-counter (this counter is reset on any incoming or
307 * outgoing packet), if counter exceeds configured limit either do a
308 * hangup immediately or - if configured - wait until just before the next
311 * cps-calculation (needed for dynamic channel-bundling):
312 * Since this function is called every second, simply reset the
313 * byte-counter of the interface after copying it to the cps-variable.
315 static unsigned long last_jiffies
= -HZ
;
318 isdn_net_autohup(void)
320 isdn_net_dev
*p
= dev
->netdev
;
325 isdn_net_local
*l
= p
->local
;
326 if (jiffies
== last_jiffies
)
327 l
->cps
= l
->transcount
;
329 l
->cps
= (l
->transcount
* HZ
) / (jiffies
- last_jiffies
);
331 if (dev
->net_verbose
> 3)
332 printk(KERN_DEBUG
"%s: %d bogocps\n", l
->name
, l
->cps
);
333 if ((l
->flags
& ISDN_NET_CONNECTED
) && (!l
->dialstate
)) {
337 * if there is some dialmode where timeout-hangup
338 * should _not_ be done, check for that here
341 (l
->huptimer
> l
->onhtime
))
343 if (l
->hupflags
& ISDN_MANCHARGE
&&
344 l
->hupflags
& ISDN_CHARGEHUP
) {
345 while (time_after(jiffies
, l
->chargetime
+ l
->chargeint
))
346 l
->chargetime
+= l
->chargeint
;
347 if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
- 2 * HZ
))
348 if (l
->outgoing
|| l
->hupflags
& ISDN_INHUP
)
349 isdn_net_hangup(&p
->dev
);
350 } else if (l
->outgoing
) {
351 if (l
->hupflags
& ISDN_CHARGEHUP
) {
352 if (l
->hupflags
& ISDN_WAITCHARGE
) {
353 printk(KERN_DEBUG
"isdn_net: Hupflags of %s are %X\n",
354 l
->name
, l
->hupflags
);
355 isdn_net_hangup(&p
->dev
);
356 } else if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
)) {
358 "isdn_net: %s: chtime = %lu, chint = %d\n",
359 l
->name
, l
->chargetime
, l
->chargeint
);
360 isdn_net_hangup(&p
->dev
);
363 isdn_net_hangup(&p
->dev
);
364 } else if (l
->hupflags
& ISDN_INHUP
)
365 isdn_net_hangup(&p
->dev
);
368 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*l
) == ISDN_NET_DM_OFF
)) {
369 isdn_net_hangup(&p
->dev
);
373 p
= (isdn_net_dev
*) p
->next
;
375 last_jiffies
= jiffies
;
376 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, anymore
);
379 static void isdn_net_lp_disconnected(isdn_net_local
*lp
)
381 isdn_net_rm_from_bundle(lp
);
385 * Handle status-messages from ISDN-interfacecard.
386 * This function is called from within the main-status-dispatcher
387 * isdn_status_callback, which itself is called from the low-level driver.
388 * Return: 1 = Event handled, 0 = not for us or unknown Event.
391 isdn_net_stat_callback(int idx
, isdn_ctrl
*c
)
393 isdn_net_dev
*p
= dev
->st_netdev
[idx
];
394 int cmd
= c
->command
;
397 isdn_net_local
*lp
= p
->local
;
398 #ifdef CONFIG_ISDN_X25
399 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
400 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
403 case ISDN_STAT_BSENT
:
404 /* A packet has successfully been sent out */
405 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
407 isdn_net_dec_frame_cnt(lp
);
408 lp
->stats
.tx_packets
++;
409 lp
->stats
.tx_bytes
+= c
->parm
.length
;
412 case ISDN_STAT_DCONN
:
413 /* D-Channel is up */
414 switch (lp
->dialstate
) {
426 /* Either D-Channel-hangup or error during dialout */
427 #ifdef CONFIG_ISDN_X25
428 /* If we are not connencted then dialing had
429 failed. If there are generic encap protocol
430 receiver routines signal the closure of
433 if( !(lp
->flags
& ISDN_NET_CONNECTED
)
434 && pops
&& pops
-> disconn_ind
)
435 pops
-> disconn_ind(cprot
);
436 #endif /* CONFIG_ISDN_X25 */
437 if ((!lp
->dialstate
) && (lp
->flags
& ISDN_NET_CONNECTED
)) {
438 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
439 isdn_net_ciscohdlck_disconnected(lp
);
440 #ifdef CONFIG_ISDN_PPP
441 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
444 isdn_net_lp_disconnected(lp
);
445 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
446 printk(KERN_INFO
"%s: remote hangup\n", lp
->name
);
447 printk(KERN_INFO
"%s: Chargesum is %d\n", lp
->name
,
449 isdn_net_unbind_channel(lp
);
453 #ifdef CONFIG_ISDN_X25
455 /* B-Channel-hangup */
456 /* try if there are generic encap protocol
457 receiver routines and signal the closure of
459 if( pops
&& pops
-> disconn_ind
){
460 pops
-> disconn_ind(cprot
);
464 #endif /* CONFIG_ISDN_X25 */
465 case ISDN_STAT_BCONN
:
466 /* B-Channel is up */
467 isdn_net_zero_frame_cnt(lp
);
468 switch (lp
->dialstate
) {
476 if (lp
->dialstate
<= 6) {
477 dev
->usage
[idx
] |= ISDN_USAGE_OUTGOING
;
480 dev
->rx_netdev
[idx
] = p
;
482 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 1);
483 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
484 isdn_net_ciscohdlck_connected(lp
);
485 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
) {
486 if (lp
->master
) { /* is lp a slave? */
487 isdn_net_dev
*nd
= ((isdn_net_local
*)lp
->master
->priv
)->netdev
;
488 isdn_net_add_to_bundle(nd
, lp
);
491 printk(KERN_INFO
"isdn_net: %s connected\n", lp
->name
);
492 /* If first Chargeinfo comes before B-Channel connect,
493 * we correct the timestamp here.
495 lp
->chargetime
= jiffies
;
497 /* reset dial-timeout */
499 lp
->dialwait_timer
= 0;
501 #ifdef CONFIG_ISDN_PPP
502 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
503 isdn_ppp_wakeup_daemon(lp
);
505 #ifdef CONFIG_ISDN_X25
506 /* try if there are generic concap receiver routines */
508 if( pops
->connect_ind
)
509 pops
->connect_ind(cprot
);
510 #endif /* CONFIG_ISDN_X25 */
511 /* ppp needs to do negotiations first */
512 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
)
513 isdn_net_device_wake_queue(lp
);
517 case ISDN_STAT_NODCH
:
518 /* No D-Channel avail. */
519 if (lp
->dialstate
== 4) {
525 /* Charge-info from TelCo. Calculate interval between
526 * charge-infos and set timestamp for last info for
527 * usage by isdn_net_autohup()
530 if (lp
->hupflags
& ISDN_HAVECHARGE
) {
531 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
532 lp
->chargeint
= jiffies
- lp
->chargetime
- (2 * HZ
);
534 if (lp
->hupflags
& ISDN_WAITCHARGE
)
535 lp
->hupflags
|= ISDN_HAVECHARGE
;
536 lp
->chargetime
= jiffies
;
537 printk(KERN_DEBUG
"isdn_net: Got CINF chargetime of %s now %lu\n",
538 lp
->name
, lp
->chargetime
);
546 * Perform dialout for net-interfaces and timeout-handling for
547 * D-Channel-up and B-Channel-up Messages.
548 * This function is initially called from within isdn_net_start_xmit() or
549 * or isdn_net_find_icall() after initializing the dialstate for an
550 * interface. If further calls are needed, the function schedules itself
551 * for a timer-callback via isdn_timer_function().
552 * The dialstate is also affected by incoming status-messages from
553 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
558 isdn_net_dev
*p
= dev
->netdev
;
562 u_char
*phone_number
;
565 isdn_net_local
*lp
= p
->local
;
567 #ifdef ISDN_DEBUG_NET_DIAL
569 printk(KERN_DEBUG
"%s: dialstate=%d\n", lp
->name
, lp
->dialstate
);
571 switch (lp
->dialstate
) {
573 /* Nothing to do for this interface */
576 /* Initiate dialout. Set phone-number-pointer to first number
579 lp
->dial
= lp
->phone
[1];
581 printk(KERN_WARNING
"%s: phone number deleted?\n",
583 isdn_net_hangup(&p
->dev
);
588 if(lp
->dialtimeout
> 0)
589 if(lp
->dialstarted
== 0 || time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
)) {
590 lp
->dialstarted
= jiffies
;
591 lp
->dialwait_timer
= 0;
597 /* Prepare dialing. Clear EAZ, then set EAZ. */
598 cmd
.driver
= lp
->isdn_device
;
599 cmd
.arg
= lp
->isdn_channel
;
600 cmd
.command
= ISDN_CMD_CLREAZ
;
602 sprintf(cmd
.parm
.num
, "%s", isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
603 cmd
.command
= ISDN_CMD_SETEAZ
;
610 /* Setup interface, dial current phone-number, switch to next number.
611 * If list of phone-numbers is exhausted, increment
614 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
)) {
616 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
617 s
= "dial suppressed: isdn system stopped";
619 s
= "dial suppressed: dialmode `off'";
620 isdn_net_unreachable(&p
->dev
, NULL
, s
);
621 isdn_net_hangup(&p
->dev
);
624 cmd
.driver
= lp
->isdn_device
;
625 cmd
.command
= ISDN_CMD_SETL2
;
626 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
628 cmd
.driver
= lp
->isdn_device
;
629 cmd
.command
= ISDN_CMD_SETL3
;
630 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
632 cmd
.driver
= lp
->isdn_device
;
633 cmd
.arg
= lp
->isdn_channel
;
635 printk(KERN_WARNING
"%s: phone number deleted?\n",
637 isdn_net_hangup(&p
->dev
);
640 if (!strncmp(lp
->dial
->num
, "LEASED", strlen("LEASED"))) {
642 printk(KERN_INFO
"%s: Open leased line ...\n", lp
->name
);
644 if(lp
->dialtimeout
> 0)
645 if (time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
)) {
646 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
648 isdn_net_unreachable(&p
->dev
, NULL
, "dial: timed out");
649 isdn_net_hangup(&p
->dev
);
653 cmd
.driver
= lp
->isdn_device
;
654 cmd
.command
= ISDN_CMD_DIAL
;
655 cmd
.parm
.setup
.si2
= 0;
658 phone_number
= lp
->dial
->num
;
659 if ((*phone_number
== 'v') ||
660 (*phone_number
== 'V')) { /* DOV call */
661 cmd
.parm
.setup
.si1
= 1;
662 } else { /* DATA call */
663 cmd
.parm
.setup
.si1
= 7;
666 strcpy(cmd
.parm
.setup
.phone
, phone_number
);
668 * Switch to next number or back to start if at end of list.
670 if (!(lp
->dial
= (isdn_net_phone
*) lp
->dial
->next
)) {
671 lp
->dial
= lp
->phone
[1];
674 if (lp
->dialretry
> lp
->dialmax
) {
675 if (lp
->dialtimeout
== 0) {
676 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
678 isdn_net_unreachable(&p
->dev
, NULL
, "dial: tried all numbers dialmax times");
680 isdn_net_hangup(&p
->dev
);
684 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
685 isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
686 i
= isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
);
688 strcpy(dev
->num
[i
], cmd
.parm
.setup
.phone
);
689 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
692 printk(KERN_INFO
"%s: dialing %d %s... %s\n", lp
->name
,
693 lp
->dialretry
, cmd
.parm
.setup
.phone
,
694 (cmd
.parm
.setup
.si1
== 1) ? "DOV" : "");
696 #ifdef ISDN_DEBUG_NET_DIAL
697 printk(KERN_DEBUG
"dial: d=%d c=%d\n", lp
->isdn_device
,
705 lp
->hupflags
|= ISDN_HAVECHARGE
;
706 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
708 lp
->hupflags
|= ISDN_WAITCHARGE
;
709 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
714 (lp
->flags
& ISDN_NET_CBOUT
)) ? 12 : 4;
717 /* Wait for D-Channel-connect.
718 * If timeout, switch back to state 3.
719 * Dialmax-handling moved to state 3.
721 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
726 /* Got D-Channel-Connect, send B-Channel-request */
727 cmd
.driver
= lp
->isdn_device
;
728 cmd
.arg
= lp
->isdn_channel
;
729 cmd
.command
= ISDN_CMD_ACCEPTB
;
736 /* Wait for B- or D-Channel-connect. If timeout,
737 * switch back to state 3.
739 #ifdef ISDN_DEBUG_NET_DIAL
740 printk(KERN_DEBUG
"dialtimer2: %d\n", lp
->dtimer
);
742 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
747 /* Got incoming Call, setup L2 and L3 protocols,
748 * then wait for D-Channel-connect
750 #ifdef ISDN_DEBUG_NET_DIAL
751 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
753 cmd
.driver
= lp
->isdn_device
;
754 cmd
.command
= ISDN_CMD_SETL2
;
755 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
757 cmd
.driver
= lp
->isdn_device
;
758 cmd
.command
= ISDN_CMD_SETL3
;
759 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
761 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT15
)
762 isdn_net_hangup(&p
->dev
);
769 /* Got incoming D-Channel-Connect, send B-Channel-request */
770 cmd
.driver
= lp
->isdn_device
;
771 cmd
.arg
= lp
->isdn_channel
;
772 cmd
.command
= ISDN_CMD_ACCEPTB
;
780 /* Wait for B- or D-channel-connect */
781 #ifdef ISDN_DEBUG_NET_DIAL
782 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
784 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
785 isdn_net_hangup(&p
->dev
);
791 if (lp
->dtimer
++ > lp
->cbdelay
)
796 /* Remote does callback. Hangup after cbdelay, then wait for incoming
799 if (lp
->dtimer
++ > lp
->cbdelay
)
801 printk(KERN_INFO
"%s: hangup waiting for callback ...\n", lp
->name
);
804 cmd
.driver
= lp
->isdn_device
;
805 cmd
.command
= ISDN_CMD_HANGUP
;
806 cmd
.arg
= lp
->isdn_channel
;
808 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
813 printk(KERN_WARNING
"isdn_net: Illegal dialstate %d for device %s\n",
814 lp
->dialstate
, lp
->name
);
816 p
= (isdn_net_dev
*) p
->next
;
818 isdn_timer_ctrl(ISDN_TIMER_NETDIAL
, anymore
);
822 * Perform hangup for a net-interface.
825 isdn_net_hangup(struct net_device
*d
)
827 isdn_net_local
*lp
= (isdn_net_local
*) d
->priv
;
829 #ifdef CONFIG_ISDN_X25
830 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
831 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
834 if (lp
->flags
& ISDN_NET_CONNECTED
) {
835 if (lp
->slave
!= NULL
) {
836 isdn_net_local
*slp
= (isdn_net_local
*)lp
->slave
->priv
;
837 if (slp
->flags
& ISDN_NET_CONNECTED
) {
839 "isdn_net: hang up slave %s before %s\n",
840 slp
->name
, lp
->name
);
841 isdn_net_hangup(lp
->slave
);
844 printk(KERN_INFO
"isdn_net: local hangup %s\n", lp
->name
);
845 #ifdef CONFIG_ISDN_PPP
846 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
849 isdn_net_lp_disconnected(lp
);
850 #ifdef CONFIG_ISDN_X25
851 /* try if there are generic encap protocol
852 receiver routines and signal the closure of
854 if( pops
&& pops
-> disconn_ind
)
855 pops
-> disconn_ind(cprot
);
856 #endif /* CONFIG_ISDN_X25 */
858 cmd
.driver
= lp
->isdn_device
;
859 cmd
.command
= ISDN_CMD_HANGUP
;
860 cmd
.arg
= lp
->isdn_channel
;
862 printk(KERN_INFO
"%s: Chargesum is %d\n", lp
->name
, lp
->charge
);
863 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
865 isdn_net_unbind_channel(lp
);
869 unsigned short source
;
874 isdn_net_log_skb(struct sk_buff
* skb
, isdn_net_local
* lp
)
876 u_char
*p
= skb
->nh
.raw
; /* hopefully, this was set correctly */
877 unsigned short proto
= ntohs(skb
->protocol
);
883 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
884 if (skb
->nh
.raw
< skb
->data
|| skb
->nh
.raw
>= skb
->tail
) {
885 /* fall back to old isdn_net_log_packet method() */
886 char * buf
= skb
->data
;
888 printk(KERN_DEBUG
"isdn_net: protocol %04x is buggy, dev %s\n", skb
->protocol
, lp
->name
);
891 switch (lp
->p_encap
) {
892 case ISDN_NET_ENCAP_IPTYP
:
893 proto
= ntohs(*(unsigned short *) &buf
[0]);
896 case ISDN_NET_ENCAP_ETHER
:
897 proto
= ntohs(*(unsigned short *) &buf
[12]);
900 case ISDN_NET_ENCAP_CISCOHDLC
:
901 proto
= ntohs(*(unsigned short *) &buf
[2]);
904 #ifdef CONFIG_ISDN_PPP
905 case ISDN_NET_ENCAP_SYNCPPP
:
906 proto
= ntohs(skb
->protocol
);
907 p
= &buf
[IPPP_MAX_HEADER
];
912 data_ofs
= ((p
[0] & 15) * 4);
917 strcpy(addinfo
, " ICMP");
920 strcpy(addinfo
, " IGMP");
923 strcpy(addinfo
, " IPIP");
926 ipp
= (ip_ports
*) (&p
[data_ofs
]);
927 sprintf(addinfo
, " TCP, port: %d -> %d", ntohs(ipp
->source
),
931 strcpy(addinfo
, " EGP");
934 strcpy(addinfo
, " PUP");
937 ipp
= (ip_ports
*) (&p
[data_ofs
]);
938 sprintf(addinfo
, " UDP, port: %d -> %d", ntohs(ipp
->source
),
942 strcpy(addinfo
, " IDP");
946 "OPEN: %d.%d.%d.%d -> %d.%d.%d.%d%s\n",
948 p
[12], p
[13], p
[14], p
[15],
949 p
[16], p
[17], p
[18], p
[19],
954 "OPEN: ARP %d.%d.%d.%d -> *.*.*.* ?%d.%d.%d.%d\n",
955 p
[14], p
[15], p
[16], p
[17],
956 p
[24], p
[25], p
[26], p
[27]);
962 * this function is used to send supervisory data, i.e. data which was
963 * not received from the network layer, but e.g. frames from ipppd, CCP
966 void isdn_net_write_super(isdn_net_local
*lp
, struct sk_buff
*skb
)
969 // we can't grab the lock from irq context,
970 // so we just queue the packet
971 skb_queue_tail(&lp
->super_tx_queue
, skb
);
972 schedule_work(&lp
->tqueue
);
976 spin_lock_bh(&lp
->xmit_lock
);
977 if (!isdn_net_lp_busy(lp
)) {
978 isdn_net_writebuf_skb(lp
, skb
);
980 skb_queue_tail(&lp
->super_tx_queue
, skb
);
982 spin_unlock_bh(&lp
->xmit_lock
);
986 * called from tq_immediate
988 static void isdn_net_softint(void *private)
990 isdn_net_local
*lp
= private;
993 spin_lock_bh(&lp
->xmit_lock
);
994 while (!isdn_net_lp_busy(lp
)) {
995 skb
= skb_dequeue(&lp
->super_tx_queue
);
998 isdn_net_writebuf_skb(lp
, skb
);
1000 spin_unlock_bh(&lp
->xmit_lock
);
1004 * all frames sent from the (net) LL to a HL driver should go via this function
1005 * it's serialized by the caller holding the lp->xmit_lock spinlock
1007 void isdn_net_writebuf_skb(isdn_net_local
*lp
, struct sk_buff
*skb
)
1010 int len
= skb
->len
; /* save len */
1012 /* before obtaining the lock the caller should have checked that
1013 the lp isn't busy */
1014 if (isdn_net_lp_busy(lp
)) {
1015 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1019 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1020 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1023 ret
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
);
1025 /* we should never get here */
1026 printk(KERN_WARNING
"%s: HL driver queue full\n", lp
->name
);
1030 lp
->transcount
+= len
;
1031 isdn_net_inc_frame_cnt(lp
);
1036 lp
->stats
.tx_errors
++;
1042 * Helper function for isdn_net_start_xmit.
1043 * When called, the connection is already established.
1044 * Based on cps-calculation, check if device is overloaded.
1045 * If so, and if a slave exists, trigger dialing for it.
1046 * If any slave is online, deliver packets using a simple round robin
1049 * Return: 0 on success, !0 on failure.
1053 isdn_net_xmit(struct net_device
*ndev
, struct sk_buff
*skb
)
1056 isdn_net_local
*slp
;
1057 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1060 if (((isdn_net_local
*) (ndev
->priv
))->master
) {
1061 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1066 /* For the other encaps the header has already been built */
1067 #ifdef CONFIG_ISDN_PPP
1068 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1069 return isdn_ppp_xmit(skb
, ndev
);
1072 nd
= ((isdn_net_local
*) ndev
->priv
)->netdev
;
1073 lp
= isdn_net_get_locked_lp(nd
);
1075 printk(KERN_WARNING
"%s: all channels busy - requeuing!\n", ndev
->name
);
1078 /* we have our lp locked from now on */
1080 /* Reset hangup-timeout */
1081 lp
->huptimer
= 0; // FIXME?
1082 isdn_net_writebuf_skb(lp
, skb
);
1083 spin_unlock_bh(&lp
->xmit_lock
);
1085 /* the following stuff is here for backwards compatibility.
1086 * in future, start-up and hangup of slaves (based on current load)
1087 * should move to userspace and get based on an overall cps
1090 if (lp
->cps
> lp
->triggercps
) {
1093 /* First time overload: set timestamp only */
1095 lp
->sqfull_stamp
= jiffies
;
1097 /* subsequent overload: if slavedelay exceeded, start dialing */
1098 if (time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
)) {
1099 slp
= lp
->slave
->priv
;
1100 if (!(slp
->flags
& ISDN_NET_CONNECTED
)) {
1101 isdn_net_force_dial_lp((isdn_net_local
*) lp
->slave
->priv
);
1107 if (lp
->sqfull
&& time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
+ (10 * HZ
))) {
1110 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1111 nd
->queue
= nd
->local
;
1119 isdn_net_adjust_hdr(struct sk_buff
*skb
, struct net_device
*dev
)
1121 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1124 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1125 int pullsize
= (ulong
)skb
->nh
.raw
- (ulong
)skb
->data
- ETH_HLEN
;
1127 printk(KERN_DEBUG
"isdn_net: Pull junk %d\n", pullsize
);
1128 skb_pull(skb
, pullsize
);
1134 static void isdn_net_tx_timeout(struct net_device
* ndev
)
1136 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1138 printk(KERN_WARNING
"isdn_tx_timeout dev %s dialstate %d\n", ndev
->name
, lp
->dialstate
);
1139 if (!lp
->dialstate
){
1140 lp
->stats
.tx_errors
++;
1142 * There is a certain probability that this currently
1143 * works at all because if we always wake up the interface,
1144 * then upper layer will try to send the next packet
1145 * immediately. And then, the old clean_up logic in the
1146 * driver will hopefully continue to work as it used to do.
1148 * This is rather primitive right know, we better should
1149 * clean internal queues here, in particular for multilink and
1150 * ppp, and reset HL driver's channel, too. --HE
1152 * actually, this may not matter at all, because ISDN hardware
1153 * should not see transmitter hangs at all IMO
1154 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1158 ndev
->trans_start
= jiffies
;
1159 netif_wake_queue(ndev
);
1163 * Try sending a packet.
1164 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1165 * and start dialing.
1168 isdn_net_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1170 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1171 #ifdef CONFIG_ISDN_X25
1172 struct concap_proto
* cprot
= lp
-> netdev
-> cprot
;
1173 /* At this point hard_start_xmit() passes control to the encapsulation
1174 protocol (if present).
1175 For X.25 auto-dialing is completly bypassed because:
1176 - It does not conform with the semantics of a reliable datalink
1177 service as needed by X.25 PLP.
1178 - I don't want that the interface starts dialing when the network layer
1179 sends a message which requests to disconnect the lapb link (or if it
1180 sends any other message not resulting in data transmission).
1181 Instead, dialing will be initiated by the encapsulation protocol entity
1182 when a dl_establish request is received from the upper layer.
1184 if (cprot
&& cprot
-> pops
) {
1185 int ret
= cprot
-> pops
-> encap_and_xmit ( cprot
, skb
);
1188 netif_stop_queue(ndev
);
1192 /* auto-dialing xmit function */
1194 #ifdef ISDN_DEBUG_NET_DUMP
1197 isdn_net_adjust_hdr(skb
, ndev
);
1198 #ifdef ISDN_DEBUG_NET_DUMP
1200 isdn_dumppkt("S:", buf
, skb
->len
, 40);
1203 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1205 /* only do autodial if allowed by config */
1206 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) {
1207 isdn_net_unreachable(ndev
, skb
, "dial rejected: interface not in dialmode `auto'");
1214 if(lp
->dialwait_timer
<= 0)
1215 if(lp
->dialstarted
> 0 && lp
->dialtimeout
> 0 && time_before(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
))
1216 lp
->dialwait_timer
= lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
;
1218 if(lp
->dialwait_timer
> 0) {
1219 if(time_before(jiffies
, lp
->dialwait_timer
)) {
1220 isdn_net_unreachable(ndev
, skb
, "dial rejected: retry-time not reached");
1224 lp
->dialwait_timer
= 0;
1226 /* Grab a free ISDN-Channel */
1227 spin_lock_irqsave(&dev
->lock
, flags
);
1229 isdn_get_free_channel(
1238 isdn_get_free_channel(
1246 spin_unlock_irqrestore(&dev
->lock
, flags
);
1247 isdn_net_unreachable(ndev
, skb
,
1252 /* Log packet, which triggered dialing */
1253 if (dev
->net_verbose
)
1254 isdn_net_log_skb(skb
, lp
);
1256 /* Connect interface with channel */
1257 isdn_net_bind_channel(lp
, chi
);
1258 #ifdef CONFIG_ISDN_PPP
1259 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1260 /* no 'first_skb' handling for syncPPP */
1261 if (isdn_ppp_bind(lp
) < 0) {
1263 isdn_net_unbind_channel(lp
);
1264 spin_unlock_irqrestore(&dev
->lock
, flags
);
1265 return 0; /* STN (skb to nirvana) ;) */
1267 #ifdef CONFIG_IPPP_FILTER
1268 if (isdn_ppp_autodial_filter(skb
, lp
)) {
1270 isdn_net_unbind_channel(lp
);
1271 spin_unlock_irqrestore(&dev
->lock
, flags
);
1272 isdn_net_unreachable(ndev
, skb
, "dial rejected: packet filtered");
1277 spin_unlock_irqrestore(&dev
->lock
, flags
);
1278 isdn_net_dial(); /* Initiate dialing */
1279 netif_stop_queue(ndev
);
1280 return 1; /* let upper layer requeue skb packet */
1283 /* Initiate dialing */
1284 spin_unlock_irqrestore(&dev
->lock
, flags
);
1286 isdn_net_device_stop_queue(lp
);
1289 isdn_net_unreachable(ndev
, skb
,
1295 /* Device is connected to an ISDN channel */
1296 ndev
->trans_start
= jiffies
;
1297 if (!lp
->dialstate
) {
1298 /* ISDN connection is established, try sending */
1300 ret
= (isdn_net_xmit(ndev
, skb
));
1301 if(ret
) netif_stop_queue(ndev
);
1304 netif_stop_queue(ndev
);
1311 * Shutdown a net-interface.
1314 isdn_net_close(struct net_device
*dev
)
1316 struct net_device
*p
;
1317 #ifdef CONFIG_ISDN_X25
1318 struct concap_proto
* cprot
=
1319 ( (isdn_net_local
*) dev
->priv
) -> netdev
-> cprot
;
1320 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1323 #ifdef CONFIG_ISDN_X25
1324 if( cprot
&& cprot
-> pops
) cprot
-> pops
-> close( cprot
);
1326 netif_stop_queue(dev
);
1327 if ((p
= (((isdn_net_local
*) dev
->priv
)->slave
))) {
1328 /* If this interface has slaves, stop them also */
1330 #ifdef CONFIG_ISDN_X25
1331 cprot
= ( (isdn_net_local
*) p
->priv
)
1333 if( cprot
&& cprot
-> pops
)
1334 cprot
-> pops
-> close( cprot
);
1337 p
= (((isdn_net_local
*) p
->priv
)->slave
);
1340 isdn_net_hangup(dev
);
1341 isdn_unlock_drivers();
1348 static struct net_device_stats
*
1349 isdn_net_get_stats(struct net_device
*dev
)
1351 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1355 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1356 * instead of dev->hard_header_len off. This is done because the
1357 * lowlevel-driver has already pulled off its stuff when we get
1358 * here and this routine only gets called with p_encap == ETHER.
1359 * Determine the packet's protocol ID. The rule here is that we
1360 * assume 802.3 if the type field is short enough to be a length.
1361 * This is normal practice and works for any 'now in use' protocol.
1364 static unsigned short
1365 isdn_net_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1368 unsigned char *rawp
;
1370 skb
->mac
.raw
= skb
->data
;
1371 skb_pull(skb
, ETH_HLEN
);
1374 if (*eth
->h_dest
& 1) {
1375 if (memcmp(eth
->h_dest
, dev
->broadcast
, ETH_ALEN
) == 0)
1376 skb
->pkt_type
= PACKET_BROADCAST
;
1378 skb
->pkt_type
= PACKET_MULTICAST
;
1381 * This ALLMULTI check should be redundant by 1.4
1382 * so don't forget to remove it.
1385 else if (dev
->flags
& (IFF_PROMISC
/*| IFF_ALLMULTI*/)) {
1386 if (memcmp(eth
->h_dest
, dev
->dev_addr
, ETH_ALEN
))
1387 skb
->pkt_type
= PACKET_OTHERHOST
;
1389 if (ntohs(eth
->h_proto
) >= 1536)
1390 return eth
->h_proto
;
1395 * This is a magic hack to spot IPX packets. Older Novell breaks
1396 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1397 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1398 * won't work for fault tolerant netware but does for the rest.
1400 if (*(unsigned short *) rawp
== 0xFFFF)
1401 return htons(ETH_P_802_3
);
1405 return htons(ETH_P_802_2
);
1410 * CISCO HDLC keepalive specific stuff
1412 static struct sk_buff
*
1413 isdn_net_ciscohdlck_alloc_skb(isdn_net_local
*lp
, int len
)
1415 unsigned short hl
= dev
->drv
[lp
->isdn_device
]->interface
->hl_hdrlen
;
1416 struct sk_buff
*skb
;
1418 skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1420 skb_reserve(skb
, hl
);
1422 printk("isdn out of mem at %s:%d!\n", __FILE__
, __LINE__
);
1426 /* cisco hdlck device private ioctls */
1428 isdn_ciscohdlck_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1430 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1431 unsigned long len
= 0;
1432 unsigned long expires
= 0;
1434 int period
= lp
->cisco_keepalive_period
;
1435 s8 debserint
= lp
->cisco_debserint
;
1438 if (lp
->p_encap
!= ISDN_NET_ENCAP_CISCOHDLCK
)
1442 /* get/set keepalive period */
1443 case SIOCGKEEPPERIOD
:
1444 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1445 if (copy_to_user(ifr
->ifr_data
,
1446 &lp
->cisco_keepalive_period
, len
))
1449 case SIOCSKEEPPERIOD
:
1450 tmp
= lp
->cisco_keepalive_period
;
1451 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1452 if (copy_from_user(&period
, ifr
->ifr_data
, len
))
1454 if ((period
> 0) && (period
<= 32767))
1455 lp
->cisco_keepalive_period
= period
;
1458 if (!rc
&& (tmp
!= lp
->cisco_keepalive_period
)) {
1459 expires
= (unsigned long)(jiffies
+
1460 lp
->cisco_keepalive_period
* HZ
);
1461 mod_timer(&lp
->cisco_timer
, expires
);
1462 printk(KERN_INFO
"%s: Keepalive period set "
1464 lp
->name
, lp
->cisco_keepalive_period
);
1468 /* get/set debugging */
1469 case SIOCGDEBSERINT
:
1470 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1471 if (copy_to_user(ifr
->ifr_data
,
1472 &lp
->cisco_debserint
, len
))
1475 case SIOCSDEBSERINT
:
1476 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1477 if (copy_from_user(&debserint
,
1478 ifr
->ifr_data
, len
))
1480 if ((debserint
>= 0) && (debserint
<= 64))
1481 lp
->cisco_debserint
= debserint
;
1493 /* called via cisco_timer.function */
1495 isdn_net_ciscohdlck_slarp_send_keepalive(unsigned long data
)
1497 isdn_net_local
*lp
= (isdn_net_local
*) data
;
1498 struct sk_buff
*skb
;
1500 unsigned long last_cisco_myseq
= lp
->cisco_myseq
;
1503 if (!(lp
->flags
& ISDN_NET_CONNECTED
) || lp
->dialstate
) {
1504 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1509 myseq_diff
= (lp
->cisco_myseq
- lp
->cisco_mineseen
);
1510 if ((lp
->cisco_line_state
) && ((myseq_diff
>= 3)||(myseq_diff
<= -3))) {
1511 /* line up -> down */
1512 lp
->cisco_line_state
= 0;
1513 printk (KERN_WARNING
1514 "UPDOWN: Line protocol on Interface %s,"
1515 " changed state to down\n", lp
->name
);
1516 /* should stop routing higher-level data accross */
1517 } else if ((!lp
->cisco_line_state
) &&
1518 (myseq_diff
>= 0) && (myseq_diff
<= 2)) {
1519 /* line down -> up */
1520 lp
->cisco_line_state
= 1;
1521 printk (KERN_WARNING
1522 "UPDOWN: Line protocol on Interface %s,"
1523 " changed state to up\n", lp
->name
);
1524 /* restart routing higher-level data accross */
1527 if (lp
->cisco_debserint
)
1528 printk (KERN_DEBUG
"%s: HDLC "
1529 "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
1530 lp
->name
, last_cisco_myseq
, lp
->cisco_mineseen
,
1531 ((last_cisco_myseq
== lp
->cisco_mineseen
) ? '*' : 040),
1533 ((lp
->cisco_line_state
) ? "line up" : "line down"));
1535 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1539 p
= skb_put(skb
, 4 + 14);
1542 p
+= put_u8 (p
, CISCO_ADDR_UNICAST
);
1543 p
+= put_u8 (p
, CISCO_CTRL
);
1544 p
+= put_u16(p
, CISCO_TYPE_SLARP
);
1546 /* slarp keepalive */
1547 p
+= put_u32(p
, CISCO_SLARP_KEEPALIVE
);
1548 p
+= put_u32(p
, lp
->cisco_myseq
);
1549 p
+= put_u32(p
, lp
->cisco_yourseq
);
1550 p
+= put_u16(p
, 0xffff); // reliablity, always 0xffff
1552 isdn_net_write_super(lp
, skb
);
1554 lp
->cisco_timer
.expires
= jiffies
+ lp
->cisco_keepalive_period
* HZ
;
1556 add_timer(&lp
->cisco_timer
);
1560 isdn_net_ciscohdlck_slarp_send_request(isdn_net_local
*lp
)
1562 struct sk_buff
*skb
;
1565 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1569 p
= skb_put(skb
, 4 + 14);
1572 p
+= put_u8 (p
, CISCO_ADDR_UNICAST
);
1573 p
+= put_u8 (p
, CISCO_CTRL
);
1574 p
+= put_u16(p
, CISCO_TYPE_SLARP
);
1577 p
+= put_u32(p
, CISCO_SLARP_REQUEST
);
1578 p
+= put_u32(p
, 0); // address
1579 p
+= put_u32(p
, 0); // netmask
1580 p
+= put_u16(p
, 0); // unused
1582 isdn_net_write_super(lp
, skb
);
1586 isdn_net_ciscohdlck_connected(isdn_net_local
*lp
)
1588 lp
->cisco_myseq
= 0;
1589 lp
->cisco_mineseen
= 0;
1590 lp
->cisco_yourseq
= 0;
1591 lp
->cisco_keepalive_period
= ISDN_TIMER_KEEPINT
;
1592 lp
->cisco_last_slarp_in
= 0;
1593 lp
->cisco_line_state
= 0;
1594 lp
->cisco_debserint
= 0;
1596 /* send slarp request because interface/seq.no.s reset */
1597 isdn_net_ciscohdlck_slarp_send_request(lp
);
1599 init_timer(&lp
->cisco_timer
);
1600 lp
->cisco_timer
.data
= (unsigned long) lp
;
1601 lp
->cisco_timer
.function
= isdn_net_ciscohdlck_slarp_send_keepalive
;
1602 lp
->cisco_timer
.expires
= jiffies
+ lp
->cisco_keepalive_period
* HZ
;
1603 add_timer(&lp
->cisco_timer
);
1607 isdn_net_ciscohdlck_disconnected(isdn_net_local
*lp
)
1609 del_timer(&lp
->cisco_timer
);
1613 isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local
*lp
)
1615 struct sk_buff
*skb
;
1617 struct in_device
*in_dev
= NULL
;
1618 u32 addr
= 0; /* local ipv4 address */
1619 u32 mask
= 0; /* local netmask */
1621 if ((in_dev
= lp
->netdev
->dev
.ip_ptr
) != NULL
) {
1622 /* take primary(first) address of interface */
1623 struct in_ifaddr
*ifa
= in_dev
->ifa_list
;
1625 addr
= ifa
->ifa_local
;
1626 mask
= ifa
->ifa_mask
;
1630 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1634 p
= skb_put(skb
, 4 + 14);
1637 p
+= put_u8 (p
, CISCO_ADDR_UNICAST
);
1638 p
+= put_u8 (p
, CISCO_CTRL
);
1639 p
+= put_u16(p
, CISCO_TYPE_SLARP
);
1641 /* slarp reply, send own ip/netmask; if values are nonsense remote
1642 * should think we are unable to provide it with an address via SLARP */
1643 p
+= put_u32(p
, CISCO_SLARP_REPLY
);
1644 p
+= put_u32(p
, addr
); // address
1645 p
+= put_u32(p
, mask
); // netmask
1646 p
+= put_u16(p
, 0); // unused
1648 isdn_net_write_super(lp
, skb
);
1652 isdn_net_ciscohdlck_slarp_in(isdn_net_local
*lp
, struct sk_buff
*skb
)
1666 p
+= get_u32(p
, &code
);
1669 case CISCO_SLARP_REQUEST
:
1670 lp
->cisco_yourseq
= 0;
1671 isdn_net_ciscohdlck_slarp_send_reply(lp
);
1673 case CISCO_SLARP_REPLY
:
1674 addr
= ntohl(*(u32
*)p
);
1675 mask
= ntohl(*(u32
*)(p
+4));
1676 if (mask
!= 0xfffffffc)
1677 goto slarp_reply_out
;
1678 if ((addr
& 3) == 0 || (addr
& 3) == 3)
1679 goto slarp_reply_out
;
1681 printk(KERN_INFO
"%s: got slarp reply: "
1682 "remote ip: %d.%d.%d.%d, "
1683 "local ip: %d.%d.%d.%d "
1684 "mask: %d.%d.%d.%d\n",
1691 printk(KERN_INFO
"%s: got invalid slarp "
1692 "reply (%d.%d.%d.%d/%d.%d.%d.%d) "
1693 "- ignored\n", lp
->name
,
1694 HIPQUAD(addr
), HIPQUAD(mask
));
1696 case CISCO_SLARP_KEEPALIVE
:
1697 period
= (int)((jiffies
- lp
->cisco_last_slarp_in
1699 if (lp
->cisco_debserint
&&
1700 (period
!= lp
->cisco_keepalive_period
) &&
1701 lp
->cisco_last_slarp_in
) {
1702 printk(KERN_DEBUG
"%s: Keepalive period mismatch - "
1703 "is %d but should be %d.\n",
1704 lp
->name
, period
, lp
->cisco_keepalive_period
);
1706 lp
->cisco_last_slarp_in
= jiffies
;
1707 p
+= get_u32(p
, &my_seq
);
1708 p
+= get_u32(p
, &your_seq
);
1709 p
+= get_u16(p
, &unused
);
1710 lp
->cisco_yourseq
= my_seq
;
1711 lp
->cisco_mineseen
= your_seq
;
1717 isdn_net_ciscohdlck_receive(isdn_net_local
*lp
, struct sk_buff
*skb
)
1728 p
+= get_u8 (p
, &addr
);
1729 p
+= get_u8 (p
, &ctrl
);
1730 p
+= get_u16(p
, &type
);
1733 if (addr
!= CISCO_ADDR_UNICAST
&& addr
!= CISCO_ADDR_BROADCAST
) {
1734 printk(KERN_WARNING
"%s: Unknown Cisco addr 0x%02x\n",
1738 if (ctrl
!= CISCO_CTRL
) {
1739 printk(KERN_WARNING
"%s: Unknown Cisco ctrl 0x%02x\n",
1745 case CISCO_TYPE_SLARP
:
1746 isdn_net_ciscohdlck_slarp_in(lp
, skb
);
1748 case CISCO_TYPE_CDP
:
1749 if (lp
->cisco_debserint
)
1750 printk(KERN_DEBUG
"%s: Received CDP packet. use "
1751 "\"no cdp enable\" on cisco.\n", lp
->name
);
1754 /* no special cisco protocol */
1755 skb
->protocol
= htons(type
);
1765 * Got a packet from ISDN-Channel.
1768 isdn_net_receive(struct net_device
*ndev
, struct sk_buff
*skb
)
1770 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1771 isdn_net_local
*olp
= lp
; /* original 'lp' */
1772 #ifdef CONFIG_ISDN_X25
1773 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
1775 lp
->transcount
+= skb
->len
;
1777 lp
->stats
.rx_packets
++;
1778 lp
->stats
.rx_bytes
+= skb
->len
;
1780 /* Bundling: If device is a slave-device, deliver to master, also
1781 * handle master's statistics and hangup-timeout
1784 lp
= (isdn_net_local
*) ndev
->priv
;
1785 lp
->stats
.rx_packets
++;
1786 lp
->stats
.rx_bytes
+= skb
->len
;
1789 skb
->input_dev
= ndev
;
1790 skb
->pkt_type
= PACKET_HOST
;
1791 skb
->mac
.raw
= skb
->data
;
1792 #ifdef ISDN_DEBUG_NET_DUMP
1793 isdn_dumppkt("R:", skb
->data
, skb
->len
, 40);
1795 switch (lp
->p_encap
) {
1796 case ISDN_NET_ENCAP_ETHER
:
1797 /* Ethernet over ISDN */
1800 skb
->protocol
= isdn_net_type_trans(skb
, ndev
);
1802 case ISDN_NET_ENCAP_UIHDLC
:
1803 /* HDLC with UI-frame (for ispa with -h1 option) */
1808 case ISDN_NET_ENCAP_RAWIP
:
1809 /* RAW-IP without MAC-Header */
1812 skb
->protocol
= htons(ETH_P_IP
);
1814 case ISDN_NET_ENCAP_CISCOHDLCK
:
1815 isdn_net_ciscohdlck_receive(lp
, skb
);
1817 case ISDN_NET_ENCAP_CISCOHDLC
:
1818 /* CISCO-HDLC IP with type field and fake I-frame-header */
1821 case ISDN_NET_ENCAP_IPTYP
:
1822 /* IP with type field */
1825 skb
->protocol
= *(unsigned short *) &(skb
->data
[0]);
1827 if (*(unsigned short *) skb
->data
== 0xFFFF)
1828 skb
->protocol
= htons(ETH_P_802_3
);
1830 #ifdef CONFIG_ISDN_PPP
1831 case ISDN_NET_ENCAP_SYNCPPP
:
1832 /* huptimer is done in isdn_ppp_push_higher */
1833 isdn_ppp_receive(lp
->netdev
, olp
, skb
);
1838 #ifdef CONFIG_ISDN_X25
1839 /* try if there are generic sync_device receiver routines */
1840 if(cprot
) if(cprot
-> pops
)
1841 if( cprot
-> pops
-> data_ind
){
1842 cprot
-> pops
-> data_ind(cprot
,skb
);
1845 #endif /* CONFIG_ISDN_X25 */
1846 printk(KERN_WARNING
"%s: unknown encapsulation, dropping\n",
1857 * A packet arrived via ISDN. Search interface-chain for a corresponding
1858 * interface. If found, deliver packet to receiver-function and return 1,
1862 isdn_net_rcv_skb(int idx
, struct sk_buff
*skb
)
1864 isdn_net_dev
*p
= dev
->rx_netdev
[idx
];
1867 isdn_net_local
*lp
= p
->local
;
1868 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
1870 isdn_net_receive(&p
->dev
, skb
);
1878 my_eth_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
1879 void *daddr
, void *saddr
, unsigned len
)
1881 struct ethhdr
*eth
= (struct ethhdr
*) skb_push(skb
, ETH_HLEN
);
1884 * Set the protocol type. For a packet of type ETH_P_802_3 we
1885 * put the length here instead. It is up to the 802.2 layer to
1886 * carry protocol information.
1889 if (type
!= ETH_P_802_3
)
1890 eth
->h_proto
= htons(type
);
1892 eth
->h_proto
= htons(len
);
1895 * Set the source hardware address.
1898 memcpy(eth
->h_source
, saddr
, dev
->addr_len
);
1900 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
1903 * Anyway, the loopback-device should never use this function...
1906 if (dev
->flags
& (IFF_LOOPBACK
| IFF_NOARP
)) {
1907 memset(eth
->h_dest
, 0, dev
->addr_len
);
1908 return ETH_HLEN
/*(dev->hard_header_len)*/;
1911 memcpy(eth
->h_dest
, daddr
, dev
->addr_len
);
1912 return ETH_HLEN
/*dev->hard_header_len*/;
1914 return -ETH_HLEN
/*dev->hard_header_len*/;
1919 * depends on encaps that is being used.
1923 isdn_net_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
1924 void *daddr
, void *saddr
, unsigned plen
)
1926 isdn_net_local
*lp
= dev
->priv
;
1930 switch (lp
->p_encap
) {
1931 case ISDN_NET_ENCAP_ETHER
:
1932 len
= my_eth_header(skb
, dev
, type
, daddr
, saddr
, plen
);
1934 #ifdef CONFIG_ISDN_PPP
1935 case ISDN_NET_ENCAP_SYNCPPP
:
1936 /* stick on a fake header to keep fragmentation code happy. */
1937 len
= IPPP_MAX_HEADER
;
1941 case ISDN_NET_ENCAP_RAWIP
:
1942 printk(KERN_WARNING
"isdn_net_header called with RAW_IP!\n");
1945 case ISDN_NET_ENCAP_IPTYP
:
1946 /* ethernet type field */
1947 *((ushort
*) skb_push(skb
, 2)) = htons(type
);
1950 case ISDN_NET_ENCAP_UIHDLC
:
1951 /* HDLC with UI-Frames (for ispa with -h1 option) */
1952 *((ushort
*) skb_push(skb
, 2)) = htons(0x0103);
1955 case ISDN_NET_ENCAP_CISCOHDLC
:
1956 case ISDN_NET_ENCAP_CISCOHDLCK
:
1957 p
= skb_push(skb
, 4);
1958 p
+= put_u8 (p
, CISCO_ADDR_UNICAST
);
1959 p
+= put_u8 (p
, CISCO_CTRL
);
1960 p
+= put_u16(p
, type
);
1963 #ifdef CONFIG_ISDN_X25
1965 /* try if there are generic concap protocol routines */
1966 if( lp
-> netdev
-> cprot
){
1967 printk(KERN_WARNING
"isdn_net_header called with concap_proto!\n");
1972 #endif /* CONFIG_ISDN_X25 */
1977 /* We don't need to send arp, because we have point-to-point connections. */
1979 isdn_net_rebuild_header(struct sk_buff
*skb
)
1981 struct net_device
*dev
= skb
->dev
;
1982 isdn_net_local
*lp
= dev
->priv
;
1985 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1986 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
1989 * Only ARP/IP is currently supported
1992 if (eth
->h_proto
!= htons(ETH_P_IP
)) {
1994 "isdn_net: %s don't know how to resolve type %d addresses?\n",
1995 dev
->name
, (int) eth
->h_proto
);
1996 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
2000 * Try to get ARP to resolve the header.
2003 ret
= arp_find(eth
->h_dest
, skb
);
2010 * Interface-setup. (just after registering a new interface)
2013 isdn_net_init(struct net_device
*ndev
)
2015 ushort max_hlhdr_len
= 0;
2016 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
2020 lp
->org_hhc
= ndev
->hard_header_cache
;
2021 lp
->org_hcu
= ndev
->header_cache_update
;
2023 /* Setup the generic properties */
2025 ndev
->hard_header
= NULL
;
2026 ndev
->hard_header_cache
= NULL
;
2027 ndev
->header_cache_update
= NULL
;
2029 ndev
->flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2030 ndev
->type
= ARPHRD_ETHER
;
2031 ndev
->addr_len
= ETH_ALEN
;
2033 /* for clients with MPPP maybe higher values better */
2034 ndev
->tx_queue_len
= 30;
2036 for (i
= 0; i
< ETH_ALEN
; i
++)
2037 ndev
->broadcast
[i
] = 0xff;
2039 /* The ISDN-specific entries in the device structure. */
2040 ndev
->open
= &isdn_net_open
;
2041 ndev
->hard_start_xmit
= &isdn_net_start_xmit
;
2044 * up till binding we ask the protocol layer to reserve as much
2045 * as we might need for HL layer
2048 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2049 if (dev
->drv
[drvidx
])
2050 if (max_hlhdr_len
< dev
->drv
[drvidx
]->interface
->hl_hdrlen
)
2051 max_hlhdr_len
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2053 ndev
->hard_header_len
= ETH_HLEN
+ max_hlhdr_len
;
2054 ndev
->stop
= &isdn_net_close
;
2055 ndev
->get_stats
= &isdn_net_get_stats
;
2056 ndev
->rebuild_header
= &isdn_net_rebuild_header
;
2057 ndev
->do_ioctl
= NULL
;
2062 isdn_net_swapbind(int drvidx
)
2066 #ifdef ISDN_DEBUG_NET_ICALL
2067 printk(KERN_DEBUG
"n_fi: swapping ch of %d\n", drvidx
);
2071 if (p
->local
->pre_device
== drvidx
)
2072 switch (p
->local
->pre_channel
) {
2074 p
->local
->pre_channel
= 1;
2077 p
->local
->pre_channel
= 0;
2080 p
= (isdn_net_dev
*) p
->next
;
2085 isdn_net_swap_usage(int i1
, int i2
)
2087 int u1
= dev
->usage
[i1
] & ISDN_USAGE_EXCLUSIVE
;
2088 int u2
= dev
->usage
[i2
] & ISDN_USAGE_EXCLUSIVE
;
2090 #ifdef ISDN_DEBUG_NET_ICALL
2091 printk(KERN_DEBUG
"n_fi: usage of %d and %d\n", i1
, i2
);
2093 dev
->usage
[i1
] &= ~ISDN_USAGE_EXCLUSIVE
;
2094 dev
->usage
[i1
] |= u2
;
2095 dev
->usage
[i2
] &= ~ISDN_USAGE_EXCLUSIVE
;
2096 dev
->usage
[i2
] |= u1
;
2101 * An incoming call-request has arrived.
2102 * Search the interface-chain for an appropriate interface.
2103 * If found, connect the interface to the ISDN-channel and initiate
2104 * D- and B-Channel-setup. If secure-flag is set, accept only
2105 * configured phone-numbers. If callback-flag is set, initiate
2108 * Return-Value: 0 = No appropriate interface for this call.
2110 * 2 = Reject call, wait cbdelay, then call back
2112 * 4 = Wait cbdelay, then call back
2113 * 5 = No appropriate interface for this call,
2114 * would eventually match if CID was longer.
2118 isdn_net_find_icall(int di
, int ch
, int idx
, setup_parm
*setup
)
2133 /* Search name in netdev-chain */
2134 if (!setup
->phone
[0]) {
2137 printk(KERN_INFO
"isdn_net: Incoming call without OAD, assuming '0'\n");
2139 strcpy(nr
, setup
->phone
);
2140 si1
= (int) setup
->si1
;
2141 si2
= (int) setup
->si2
;
2142 if (!setup
->eazmsn
[0]) {
2143 printk(KERN_WARNING
"isdn_net: Incoming call without CPN, assuming '0'\n");
2146 eaz
= setup
->eazmsn
;
2147 if (dev
->net_verbose
> 1)
2148 printk(KERN_INFO
"isdn_net: call from %s,%d,%d -> %s\n", nr
, si1
, si2
, eaz
);
2149 /* Accept DATA and VOICE calls at this stage
2150 * local eaz is checked later for allowed call types
2152 if ((si1
!= 7) && (si1
!= 1)) {
2153 if (dev
->net_verbose
> 1)
2154 printk(KERN_INFO
"isdn_net: Service-Indicator not 1 or 7, ignored\n");
2157 n
= (isdn_net_phone
*) 0;
2159 ematch
= wret
= swapped
= 0;
2160 #ifdef ISDN_DEBUG_NET_ICALL
2161 printk(KERN_DEBUG
"n_fi: di=%d ch=%d idx=%d usg=%d\n", di
, ch
, idx
,
2166 isdn_net_local
*lp
= p
->local
;
2168 /* If last check has triggered as binding-swap, revert it */
2171 isdn_net_swap_usage(idx
, sidx
);
2174 isdn_net_swapbind(di
);
2178 /* check acceptable call types for DOV */
2179 my_eaz
= isdn_map_eaz2msn(lp
->msn
, di
);
2180 if (si1
== 1) { /* it's a DOV call, check if we allow it */
2181 if (*my_eaz
== 'v' || *my_eaz
== 'V' ||
2182 *my_eaz
== 'b' || *my_eaz
== 'B')
2183 my_eaz
++; /* skip to allow a match */
2185 my_eaz
= NULL
; /* force non match */
2186 } else { /* it's a DATA call, check if we allow it */
2187 if (*my_eaz
== 'b' || *my_eaz
== 'B')
2188 my_eaz
++; /* skip to allow a match */
2191 matchret
= isdn_msncmp(eaz
, my_eaz
);
2197 /* Remember if more numbers eventually can match */
2198 if (matchret
> wret
)
2200 #ifdef ISDN_DEBUG_NET_ICALL
2201 printk(KERN_DEBUG
"n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2202 lp
->name
, lp
->msn
, lp
->flags
, lp
->dialstate
);
2204 if ((!matchret
) && /* EAZ is matching */
2205 (((!(lp
->flags
& ISDN_NET_CONNECTED
)) && /* but not connected */
2206 (USG_NONE(dev
->usage
[idx
]))) || /* and ch. unused or */
2207 ((((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) && /* if dialing */
2208 (!(lp
->flags
& ISDN_NET_CALLBACK
))) /* but no callback */
2211 #ifdef ISDN_DEBUG_NET_ICALL
2212 printk(KERN_DEBUG
"n_fi: match1, pdev=%d pch=%d\n",
2213 lp
->pre_device
, lp
->pre_channel
);
2215 if (dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) {
2216 if ((lp
->pre_channel
!= ch
) ||
2217 (lp
->pre_device
!= di
)) {
2218 /* Here we got a problem:
2219 * If using an ICN-Card, an incoming call is always signaled on
2220 * on the first channel of the card, if both channels are
2221 * down. However this channel may be bound exclusive. If the
2222 * second channel is free, this call should be accepted.
2223 * The solution is horribly but it runs, so what:
2224 * We exchange the exclusive bindings of the two channels, the
2225 * corresponding variables in the interface-structs.
2228 sidx
= isdn_dc2minor(di
, 1);
2229 #ifdef ISDN_DEBUG_NET_ICALL
2230 printk(KERN_DEBUG
"n_fi: ch is 0\n");
2232 if (USG_NONE(dev
->usage
[sidx
])) {
2233 /* Second Channel is free, now see if it is bound
2235 if (dev
->usage
[sidx
] & ISDN_USAGE_EXCLUSIVE
) {
2236 #ifdef ISDN_DEBUG_NET_ICALL
2237 printk(KERN_DEBUG
"n_fi: 2nd channel is down and bound\n");
2239 /* Yes, swap bindings only, if the original
2240 * binding is bound to channel 1 of this driver */
2241 if ((lp
->pre_device
== di
) &&
2242 (lp
->pre_channel
== 1)) {
2243 isdn_net_swapbind(di
);
2246 /* ... else iterate next device */
2247 p
= (isdn_net_dev
*) p
->next
;
2251 #ifdef ISDN_DEBUG_NET_ICALL
2252 printk(KERN_DEBUG
"n_fi: 2nd channel is down and unbound\n");
2254 /* No, swap always and swap excl-usage also */
2255 isdn_net_swap_usage(idx
, sidx
);
2256 isdn_net_swapbind(di
);
2259 /* Now check for exclusive binding again */
2260 #ifdef ISDN_DEBUG_NET_ICALL
2261 printk(KERN_DEBUG
"n_fi: final check\n");
2263 if ((dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) &&
2264 ((lp
->pre_channel
!= ch
) ||
2265 (lp
->pre_device
!= di
))) {
2266 #ifdef ISDN_DEBUG_NET_ICALL
2267 printk(KERN_DEBUG
"n_fi: final check failed\n");
2269 p
= (isdn_net_dev
*) p
->next
;
2274 /* We are already on the second channel, so nothing to do */
2275 #ifdef ISDN_DEBUG_NET_ICALL
2276 printk(KERN_DEBUG
"n_fi: already on 2nd channel\n");
2281 #ifdef ISDN_DEBUG_NET_ICALL
2282 printk(KERN_DEBUG
"n_fi: match2\n");
2285 if (lp
->flags
& ISDN_NET_SECURE
) {
2287 if (!isdn_msncmp(nr
, n
->num
))
2289 n
= (isdn_net_phone
*) n
->next
;
2292 if (n
|| (!(lp
->flags
& ISDN_NET_SECURE
))) {
2293 #ifdef ISDN_DEBUG_NET_ICALL
2294 printk(KERN_DEBUG
"n_fi: match3\n");
2296 /* matching interface found */
2299 * Is the state STOPPED?
2300 * If so, no dialin is allowed,
2301 * so reject actively.
2303 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2304 printk(KERN_INFO
"incoming call, interface %s `stopped' -> rejected\n",
2309 * Is the interface up?
2310 * If not, reject the call actively.
2312 if (!isdn_net_device_started(p
)) {
2313 printk(KERN_INFO
"%s: incoming call, interface down -> rejected\n",
2317 /* Interface is up, now see if it's a slave. If so, see if
2318 * it's master and parent slave is online. If not, reject the call.
2321 isdn_net_local
*mlp
= (isdn_net_local
*) lp
->master
->priv
;
2322 printk(KERN_DEBUG
"ICALLslv: %s\n", lp
->name
);
2323 printk(KERN_DEBUG
"master=%s\n", mlp
->name
);
2324 if (mlp
->flags
& ISDN_NET_CONNECTED
) {
2325 printk(KERN_DEBUG
"master online\n");
2326 /* Master is online, find parent-slave (master if first slave) */
2327 while (mlp
->slave
) {
2328 if ((isdn_net_local
*) mlp
->slave
->priv
== lp
)
2330 mlp
= (isdn_net_local
*) mlp
->slave
->priv
;
2333 printk(KERN_DEBUG
"master offline\n");
2334 /* Found parent, if it's offline iterate next device */
2335 printk(KERN_DEBUG
"mlpf: %d\n", mlp
->flags
& ISDN_NET_CONNECTED
);
2336 if (!(mlp
->flags
& ISDN_NET_CONNECTED
)) {
2337 p
= (isdn_net_dev
*) p
->next
;
2341 if (lp
->flags
& ISDN_NET_CALLBACK
) {
2344 * Is the state MANUAL?
2345 * If so, no callback can be made,
2346 * so reject actively.
2348 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2349 printk(KERN_INFO
"incoming call for callback, interface %s `off' -> rejected\n",
2353 printk(KERN_DEBUG
"%s: call from %s -> %s, start callback\n",
2356 /* Grab a free ISDN-Channel */
2357 spin_lock_irqsave(&dev
->lock
, flags
);
2359 isdn_get_free_channel(
2368 printk(KERN_WARNING
"isdn_net_find_icall: No channel for %s\n", lp
->name
);
2369 spin_unlock_irqrestore(&dev
->lock
, flags
);
2372 /* Setup dialstate. */
2375 /* Connect interface with channel */
2376 isdn_net_bind_channel(lp
, chi
);
2377 #ifdef CONFIG_ISDN_PPP
2378 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2379 if (isdn_ppp_bind(lp
) < 0) {
2380 spin_unlock_irqrestore(&dev
->lock
, flags
);
2381 isdn_net_unbind_channel(lp
);
2385 spin_unlock_irqrestore(&dev
->lock
, flags
);
2386 /* Initiate dialing by returning 2 or 4 */
2387 return (lp
->flags
& ISDN_NET_CBHUP
) ? 2 : 4;
2389 printk(KERN_WARNING
"isdn_net: %s: No phone number\n", lp
->name
);
2392 printk(KERN_DEBUG
"%s: call from %s -> %s accepted\n", lp
->name
, nr
,
2394 /* if this interface is dialing, it does it probably on a different
2395 device, so free this device */
2396 if ((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) {
2397 #ifdef CONFIG_ISDN_PPP
2398 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2401 isdn_net_lp_disconnected(lp
);
2402 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
2405 spin_lock_irqsave(&dev
->lock
, flags
);
2406 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2407 dev
->usage
[idx
] |= ISDN_USAGE_NET
;
2408 strcpy(dev
->num
[idx
], nr
);
2410 dev
->st_netdev
[idx
] = lp
->netdev
;
2411 lp
->isdn_device
= di
;
2412 lp
->isdn_channel
= ch
;
2414 lp
->flags
|= ISDN_NET_CONNECTED
;
2419 lp
->hupflags
|= ISDN_WAITCHARGE
;
2420 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
2421 #ifdef CONFIG_ISDN_PPP
2422 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
2423 if (isdn_ppp_bind(lp
) < 0) {
2424 isdn_net_unbind_channel(lp
);
2425 spin_unlock_irqrestore(&dev
->lock
, flags
);
2430 spin_unlock_irqrestore(&dev
->lock
, flags
);
2435 p
= (isdn_net_dev
*) p
->next
;
2437 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2438 if (!ematch
|| dev
->net_verbose
)
2439 printk(KERN_INFO
"isdn_net: call from %s -> %d %s ignored\n", nr
, di
, eaz
);
2440 return (wret
== 2)?5:0;
2444 * Search list of net-interfaces for an interface with given name.
2447 isdn_net_findif(char *name
)
2449 isdn_net_dev
*p
= dev
->netdev
;
2452 if (!strcmp(p
->local
->name
, name
))
2454 p
= (isdn_net_dev
*) p
->next
;
2456 return (isdn_net_dev
*) NULL
;
2460 * Force a net-interface to dial out.
2461 * This is called from the userlevel-routine below or
2462 * from isdn_net_start_xmit().
2465 isdn_net_force_dial_lp(isdn_net_local
* lp
)
2467 if ((!(lp
->flags
& ISDN_NET_CONNECTED
)) && !lp
->dialstate
) {
2472 /* Grab a free ISDN-Channel */
2473 spin_lock_irqsave(&dev
->lock
, flags
);
2474 if ((chi
= isdn_get_free_channel(
2481 printk(KERN_WARNING
"isdn_net_force_dial: No channel for %s\n", lp
->name
);
2482 spin_unlock_irqrestore(&dev
->lock
, flags
);
2486 /* Connect interface with channel */
2487 isdn_net_bind_channel(lp
, chi
);
2488 #ifdef CONFIG_ISDN_PPP
2489 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2490 if (isdn_ppp_bind(lp
) < 0) {
2491 isdn_net_unbind_channel(lp
);
2492 spin_unlock_irqrestore(&dev
->lock
, flags
);
2496 /* Initiate dialing */
2497 spin_unlock_irqrestore(&dev
->lock
, flags
);
2507 * This is called from certain upper protocol layers (multilink ppp
2508 * and x25iface encapsulation module) that want to initiate dialing
2512 isdn_net_dial_req(isdn_net_local
* lp
)
2514 /* is there a better error code? */
2515 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) return -EBUSY
;
2517 return isdn_net_force_dial_lp(lp
);
2521 * Force a net-interface to dial out.
2522 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2525 isdn_net_force_dial(char *name
)
2527 isdn_net_dev
*p
= isdn_net_findif(name
);
2531 return (isdn_net_force_dial_lp(p
->local
));
2535 * Allocate a new network-interface and initialize its data structures.
2538 isdn_net_new(char *name
, struct net_device
*master
)
2540 isdn_net_dev
*netdev
;
2542 /* Avoid creating an existing interface */
2543 if (isdn_net_findif(name
)) {
2544 printk(KERN_WARNING
"isdn_net: interface %s already exists\n", name
);
2547 if (!(netdev
= (isdn_net_dev
*) kmalloc(sizeof(isdn_net_dev
), GFP_KERNEL
))) {
2548 printk(KERN_WARNING
"isdn_net: Could not allocate net-device\n");
2551 memset(netdev
, 0, sizeof(isdn_net_dev
));
2552 if (!(netdev
->local
= (isdn_net_local
*) kmalloc(sizeof(isdn_net_local
), GFP_KERNEL
))) {
2553 printk(KERN_WARNING
"isdn_net: Could not allocate device locals\n");
2557 memset(netdev
->local
, 0, sizeof(isdn_net_local
));
2559 strcpy(netdev
->local
->name
, " ");
2561 strcpy(netdev
->local
->name
, name
);
2562 strcpy(netdev
->dev
.name
, netdev
->local
->name
);
2563 netdev
->dev
.priv
= netdev
->local
;
2564 netdev
->dev
.init
= isdn_net_init
;
2565 netdev
->local
->p_encap
= ISDN_NET_ENCAP_RAWIP
;
2567 /* Device shall be a slave */
2568 struct net_device
*p
= (((isdn_net_local
*) master
->priv
)->slave
);
2569 struct net_device
*q
= master
;
2571 netdev
->local
->master
= master
;
2572 /* Put device at end of slave-chain */
2575 p
= (((isdn_net_local
*) p
->priv
)->slave
);
2577 ((isdn_net_local
*) q
->priv
)->slave
= &(netdev
->dev
);
2579 /* Device shall be a master */
2581 * Watchdog timer (currently) for master only.
2583 netdev
->dev
.tx_timeout
= isdn_net_tx_timeout
;
2584 netdev
->dev
.watchdog_timeo
= ISDN_NET_TX_TIMEOUT
;
2585 if (register_netdev(&netdev
->dev
) != 0) {
2586 printk(KERN_WARNING
"isdn_net: Could not register net-device\n");
2587 kfree(netdev
->local
);
2592 netdev
->local
->magic
= ISDN_NET_MAGIC
;
2594 netdev
->queue
= netdev
->local
;
2595 spin_lock_init(&netdev
->queue_lock
);
2597 netdev
->local
->last
= netdev
->local
;
2598 netdev
->local
->netdev
= netdev
;
2599 netdev
->local
->next
= netdev
->local
;
2601 INIT_WORK(&netdev
->local
->tqueue
, (void *)(void *) isdn_net_softint
, netdev
->local
);
2602 spin_lock_init(&netdev
->local
->xmit_lock
);
2604 netdev
->local
->isdn_device
= -1;
2605 netdev
->local
->isdn_channel
= -1;
2606 netdev
->local
->pre_device
= -1;
2607 netdev
->local
->pre_channel
= -1;
2608 netdev
->local
->exclusive
= -1;
2609 netdev
->local
->ppp_slot
= -1;
2610 netdev
->local
->pppbind
= -1;
2611 skb_queue_head_init(&netdev
->local
->super_tx_queue
);
2612 netdev
->local
->l2_proto
= ISDN_PROTO_L2_X75I
;
2613 netdev
->local
->l3_proto
= ISDN_PROTO_L3_TRANS
;
2614 netdev
->local
->triggercps
= 6000;
2615 netdev
->local
->slavedelay
= 10 * HZ
;
2616 netdev
->local
->hupflags
= ISDN_INHUP
; /* Do hangup even on incoming calls */
2617 netdev
->local
->onhtime
= 10; /* Default hangup-time for saving costs
2618 of those who forget configuring this */
2619 netdev
->local
->dialmax
= 1;
2620 netdev
->local
->flags
= ISDN_NET_CBHUP
| ISDN_NET_DM_MANUAL
; /* Hangup before Callback, manual dial */
2621 netdev
->local
->cbdelay
= 25; /* Wait 5 secs before Callback */
2622 netdev
->local
->dialtimeout
= -1; /* Infinite Dial-Timeout */
2623 netdev
->local
->dialwait
= 5 * HZ
; /* Wait 5 sec. after failed dial */
2624 netdev
->local
->dialstarted
= 0; /* Jiffies of last dial-start */
2625 netdev
->local
->dialwait_timer
= 0; /* Jiffies of earliest next dial-start */
2627 /* Put into to netdev-chain */
2628 netdev
->next
= (void *) dev
->netdev
;
2629 dev
->netdev
= netdev
;
2630 return netdev
->dev
.name
;
2634 isdn_net_newslave(char *parm
)
2636 char *p
= strchr(parm
, ',');
2641 /* Slave-Name MUST not be empty */
2644 strcpy(newname
, p
+ 1);
2646 /* Master must already exist */
2647 if (!(n
= isdn_net_findif(parm
)))
2649 /* Master must be a real interface, not a slave */
2650 if (n
->local
->master
)
2652 /* Master must not be started yet */
2653 if (isdn_net_device_started(n
))
2655 return (isdn_net_new(newname
, &(n
->dev
)));
2661 * Set interface-parameters.
2662 * Always set all parameters, so the user-level application is responsible
2663 * for not overwriting existing setups. It has to get the current
2664 * setup first, if only selected parameters are to be changed.
2667 isdn_net_setcfg(isdn_net_ioctl_cfg
* cfg
)
2669 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2677 isdn_net_local
*lp
= p
->local
;
2679 /* See if any registered driver supports the features we want */
2680 features
= ((1 << cfg
->l2_proto
) << ISDN_FEATURE_L2_SHIFT
) |
2681 ((1 << cfg
->l3_proto
) << ISDN_FEATURE_L3_SHIFT
);
2682 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2684 if ((dev
->drv
[i
]->interface
->features
& features
) == features
)
2686 if (i
== ISDN_MAX_DRIVERS
) {
2687 printk(KERN_WARNING
"isdn_net: No driver with selected features\n");
2690 if (lp
->p_encap
!= cfg
->p_encap
){
2691 #ifdef CONFIG_ISDN_X25
2692 struct concap_proto
* cprot
= p
-> cprot
;
2694 if (isdn_net_device_started(p
)) {
2695 printk(KERN_WARNING
"%s: cannot change encap when if is up\n",
2699 #ifdef CONFIG_ISDN_X25
2700 if( cprot
&& cprot
-> pops
)
2701 cprot
-> pops
-> proto_del ( cprot
);
2704 /* ... , prepare for configuration of new one ... */
2705 switch ( cfg
-> p_encap
){
2706 case ISDN_NET_ENCAP_X25IFACE
:
2707 lp
-> dops
= &isdn_concap_reliable_dl_dops
;
2709 /* ... and allocate new one ... */
2710 p
-> cprot
= isdn_concap_new( cfg
-> p_encap
);
2711 /* p -> cprot == NULL now if p_encap is not supported
2712 by means of the concap_proto mechanism */
2713 /* the protocol is not configured yet; this will
2714 happen later when isdn_net_reset() is called */
2717 switch ( cfg
->p_encap
) {
2718 case ISDN_NET_ENCAP_SYNCPPP
:
2719 #ifndef CONFIG_ISDN_PPP
2720 printk(KERN_WARNING
"%s: SyncPPP support not configured\n",
2724 p
->dev
.type
= ARPHRD_PPP
; /* change ARP type */
2725 p
->dev
.addr_len
= 0;
2726 p
->dev
.do_ioctl
= isdn_ppp_dev_ioctl
;
2729 case ISDN_NET_ENCAP_X25IFACE
:
2730 #ifndef CONFIG_ISDN_X25
2731 printk(KERN_WARNING
"%s: isdn-x25 support not configured\n",
2735 p
->dev
.type
= ARPHRD_X25
; /* change ARP type */
2736 p
->dev
.addr_len
= 0;
2739 case ISDN_NET_ENCAP_CISCOHDLCK
:
2740 p
->dev
.do_ioctl
= isdn_ciscohdlck_dev_ioctl
;
2743 if( cfg
->p_encap
>= 0 &&
2744 cfg
->p_encap
<= ISDN_NET_ENCAP_MAX_ENCAP
)
2747 "%s: encapsulation protocol %d not supported\n",
2748 p
->local
->name
, cfg
->p_encap
);
2751 if (strlen(cfg
->drvid
)) {
2752 /* A bind has been requested ... */
2758 strcpy(drvid
, cfg
->drvid
);
2759 if ((c
= strchr(drvid
, ','))) {
2760 /* The channel-number is appended to the driver-Id with a comma */
2761 chidx
= (int) simple_strtoul(c
+ 1, &e
, 10);
2766 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2767 /* Lookup driver-Id in array */
2768 if (!(strcmp(dev
->drvid
[i
], drvid
))) {
2772 if ((drvidx
== -1) || (chidx
== -1))
2773 /* Either driver-Id or channel-number invalid */
2776 /* Parameters are valid, so get them */
2777 drvidx
= lp
->pre_device
;
2778 chidx
= lp
->pre_channel
;
2780 if (cfg
->exclusive
> 0) {
2781 unsigned long flags
;
2783 /* If binding is exclusive, try to grab the channel */
2784 spin_lock_irqsave(&dev
->lock
, flags
);
2785 if ((i
= isdn_get_free_channel(ISDN_USAGE_NET
,
2786 lp
->l2_proto
, lp
->l3_proto
, drvidx
,
2787 chidx
, lp
->msn
)) < 0) {
2788 /* Grab failed, because desired channel is in use */
2790 spin_unlock_irqrestore(&dev
->lock
, flags
);
2793 /* All went ok, so update isdninfo */
2794 dev
->usage
[i
] = ISDN_USAGE_EXCLUSIVE
;
2796 spin_unlock_irqrestore(&dev
->lock
, flags
);
2799 /* Non-exclusive binding or unbind. */
2801 if ((lp
->pre_device
!= -1) && (cfg
->exclusive
== -1)) {
2802 isdn_unexclusive_channel(lp
->pre_device
, lp
->pre_channel
);
2803 isdn_free_channel(lp
->pre_device
, lp
->pre_channel
, ISDN_USAGE_NET
);
2808 strcpy(lp
->msn
, cfg
->eaz
);
2809 lp
->pre_device
= drvidx
;
2810 lp
->pre_channel
= chidx
;
2811 lp
->onhtime
= cfg
->onhtime
;
2812 lp
->charge
= cfg
->charge
;
2813 lp
->l2_proto
= cfg
->l2_proto
;
2814 lp
->l3_proto
= cfg
->l3_proto
;
2815 lp
->cbdelay
= cfg
->cbdelay
;
2816 lp
->dialmax
= cfg
->dialmax
;
2817 lp
->triggercps
= cfg
->triggercps
;
2818 lp
->slavedelay
= cfg
->slavedelay
* HZ
;
2819 lp
->pppbind
= cfg
->pppbind
;
2820 lp
->dialtimeout
= cfg
->dialtimeout
>= 0 ? cfg
->dialtimeout
* HZ
: -1;
2821 lp
->dialwait
= cfg
->dialwait
* HZ
;
2823 lp
->flags
|= ISDN_NET_SECURE
;
2825 lp
->flags
&= ~ISDN_NET_SECURE
;
2827 lp
->flags
|= ISDN_NET_CBHUP
;
2829 lp
->flags
&= ~ISDN_NET_CBHUP
;
2830 switch (cfg
->callback
) {
2832 lp
->flags
&= ~(ISDN_NET_CALLBACK
| ISDN_NET_CBOUT
);
2835 lp
->flags
|= ISDN_NET_CALLBACK
;
2836 lp
->flags
&= ~ISDN_NET_CBOUT
;
2839 lp
->flags
|= ISDN_NET_CBOUT
;
2840 lp
->flags
&= ~ISDN_NET_CALLBACK
;
2843 lp
->flags
&= ~ISDN_NET_DIALMODE_MASK
; /* first all bits off */
2844 if (cfg
->dialmode
&& !(cfg
->dialmode
& ISDN_NET_DIALMODE_MASK
)) {
2845 /* old isdnctrl version, where only 0 or 1 is given */
2847 "Old isdnctrl version detected! Please update.\n");
2848 lp
->flags
|= ISDN_NET_DM_OFF
; /* turn on `off' bit */
2851 lp
->flags
|= cfg
->dialmode
; /* turn on selected bits */
2854 lp
->hupflags
|= ISDN_CHARGEHUP
;
2856 lp
->hupflags
&= ~ISDN_CHARGEHUP
;
2858 lp
->hupflags
|= ISDN_INHUP
;
2860 lp
->hupflags
&= ~ISDN_INHUP
;
2861 if (cfg
->chargeint
> 10) {
2862 lp
->hupflags
|= ISDN_CHARGEHUP
| ISDN_HAVECHARGE
| ISDN_MANCHARGE
;
2863 lp
->chargeint
= cfg
->chargeint
* HZ
;
2865 if (cfg
->p_encap
!= lp
->p_encap
) {
2866 if (cfg
->p_encap
== ISDN_NET_ENCAP_RAWIP
) {
2867 p
->dev
.hard_header
= NULL
;
2868 p
->dev
.hard_header_cache
= NULL
;
2869 p
->dev
.header_cache_update
= NULL
;
2870 p
->dev
.flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2872 p
->dev
.hard_header
= isdn_net_header
;
2873 if (cfg
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
2874 p
->dev
.hard_header_cache
= lp
->org_hhc
;
2875 p
->dev
.header_cache_update
= lp
->org_hcu
;
2876 p
->dev
.flags
= IFF_BROADCAST
| IFF_MULTICAST
;
2878 p
->dev
.hard_header_cache
= NULL
;
2879 p
->dev
.header_cache_update
= NULL
;
2880 p
->dev
.flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2884 lp
->p_encap
= cfg
->p_encap
;
2891 * Perform get-interface-parameters.ioctl
2894 isdn_net_getcfg(isdn_net_ioctl_cfg
* cfg
)
2896 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2899 isdn_net_local
*lp
= p
->local
;
2901 strcpy(cfg
->eaz
, lp
->msn
);
2902 cfg
->exclusive
= lp
->exclusive
;
2903 if (lp
->pre_device
>= 0) {
2904 sprintf(cfg
->drvid
, "%s,%d", dev
->drvid
[lp
->pre_device
],
2907 cfg
->drvid
[0] = '\0';
2908 cfg
->onhtime
= lp
->onhtime
;
2909 cfg
->charge
= lp
->charge
;
2910 cfg
->l2_proto
= lp
->l2_proto
;
2911 cfg
->l3_proto
= lp
->l3_proto
;
2912 cfg
->p_encap
= lp
->p_encap
;
2913 cfg
->secure
= (lp
->flags
& ISDN_NET_SECURE
) ? 1 : 0;
2915 if (lp
->flags
& ISDN_NET_CALLBACK
)
2917 if (lp
->flags
& ISDN_NET_CBOUT
)
2919 cfg
->cbhup
= (lp
->flags
& ISDN_NET_CBHUP
) ? 1 : 0;
2920 cfg
->dialmode
= lp
->flags
& ISDN_NET_DIALMODE_MASK
;
2921 cfg
->chargehup
= (lp
->hupflags
& 4) ? 1 : 0;
2922 cfg
->ihup
= (lp
->hupflags
& 8) ? 1 : 0;
2923 cfg
->cbdelay
= lp
->cbdelay
;
2924 cfg
->dialmax
= lp
->dialmax
;
2925 cfg
->triggercps
= lp
->triggercps
;
2926 cfg
->slavedelay
= lp
->slavedelay
/ HZ
;
2927 cfg
->chargeint
= (lp
->hupflags
& ISDN_CHARGEHUP
) ?
2928 (lp
->chargeint
/ HZ
) : 0;
2929 cfg
->pppbind
= lp
->pppbind
;
2930 cfg
->dialtimeout
= lp
->dialtimeout
>= 0 ? lp
->dialtimeout
/ HZ
: -1;
2931 cfg
->dialwait
= lp
->dialwait
/ HZ
;
2933 strcpy(cfg
->slave
, ((isdn_net_local
*) lp
->slave
->priv
)->name
);
2935 cfg
->slave
[0] = '\0';
2937 strcpy(cfg
->master
, ((isdn_net_local
*) lp
->master
->priv
)->name
);
2939 cfg
->master
[0] = '\0';
2946 * Add a phone-number to an interface.
2949 isdn_net_addphone(isdn_net_ioctl_phone
* phone
)
2951 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2955 if (!(n
= (isdn_net_phone
*) kmalloc(sizeof(isdn_net_phone
), GFP_KERNEL
)))
2957 strcpy(n
->num
, phone
->phone
);
2958 n
->next
= p
->local
->phone
[phone
->outgoing
& 1];
2959 p
->local
->phone
[phone
->outgoing
& 1] = n
;
2966 * Copy a string of all phone-numbers of an interface to user space.
2967 * This might sleep and must be called with the isdn semaphore down.
2970 isdn_net_getphones(isdn_net_ioctl_phone
* phone
, char __user
*phones
)
2972 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2973 int inout
= phone
->outgoing
& 1;
2981 for (n
= p
->local
->phone
[inout
]; n
; n
= n
->next
) {
2983 put_user(' ', phones
++);
2986 if (copy_to_user(phones
, n
->num
, strlen(n
->num
) + 1)) {
2989 phones
+= strlen(n
->num
);
2990 count
+= strlen(n
->num
);
2993 put_user(0, phones
);
2999 * Copy a string containing the peer's phone number of a connected interface
3003 isdn_net_getpeer(isdn_net_ioctl_phone
*phone
, isdn_net_ioctl_phone __user
*peer
)
3005 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
3008 if (!p
) return -ENODEV
;
3010 * Theoretical race: while this executes, the remote number might
3011 * become invalid (hang up) or change (new connection), resulting
3012 * in (partially) wrong number copied to user. This race
3013 * currently ignored.
3015 ch
= p
->local
->isdn_channel
;
3016 dv
= p
->local
->isdn_device
;
3017 if(ch
<0 && dv
<0) return -ENOTCONN
;
3018 idx
= isdn_dc2minor(dv
, ch
);
3019 if (idx
<0) return -ENODEV
;
3020 /* for pre-bound channels, we need this extra check */
3021 if ( strncmp(dev
->num
[idx
],"???",3) == 0 ) return -ENOTCONN
;
3022 strncpy(phone
->phone
,dev
->num
[idx
],ISDN_MSNLEN
);
3023 phone
->outgoing
=USG_OUTGOING(dev
->usage
[idx
]);
3024 if ( copy_to_user(peer
,phone
,sizeof(*peer
)) ) return -EFAULT
;
3028 * Delete a phone-number from an interface.
3031 isdn_net_delphone(isdn_net_ioctl_phone
* phone
)
3033 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
3034 int inout
= phone
->outgoing
& 1;
3039 n
= p
->local
->phone
[inout
];
3042 if (!strcmp(n
->num
, phone
->phone
)) {
3043 if (p
->local
->dial
== n
)
3044 p
->local
->dial
= n
->next
;
3048 p
->local
->phone
[inout
] = n
->next
;
3053 n
= (isdn_net_phone
*) n
->next
;
3061 * Delete all phone-numbers of an interface.
3064 isdn_net_rmallphone(isdn_net_dev
* p
)
3070 for (i
= 0; i
< 2; i
++) {
3071 n
= p
->local
->phone
[i
];
3077 p
->local
->phone
[i
] = NULL
;
3079 p
->local
->dial
= NULL
;
3084 * Force a hangup of a network-interface.
3087 isdn_net_force_hangup(char *name
)
3089 isdn_net_dev
*p
= isdn_net_findif(name
);
3090 struct net_device
*q
;
3093 if (p
->local
->isdn_device
< 0)
3095 q
= p
->local
->slave
;
3096 /* If this interface has slaves, do a hangup for them also. */
3099 q
= (((isdn_net_local
*) q
->priv
)->slave
);
3101 isdn_net_hangup(&p
->dev
);
3108 * Helper-function for isdn_net_rm: Do the real work.
3111 isdn_net_realrm(isdn_net_dev
* p
, isdn_net_dev
* q
)
3115 if (isdn_net_device_started(p
)) {
3118 #ifdef CONFIG_ISDN_X25
3119 if( p
-> cprot
&& p
-> cprot
-> pops
)
3120 p
-> cprot
-> pops
-> proto_del ( p
-> cprot
);
3122 /* Free all phone-entries */
3123 isdn_net_rmallphone(p
);
3124 /* If interface is bound exclusive, free channel-usage */
3125 if (p
->local
->exclusive
!= -1)
3126 isdn_unexclusive_channel(p
->local
->pre_device
, p
->local
->pre_channel
);
3127 if (p
->local
->master
) {
3128 /* It's a slave-device, so update master's slave-pointer if necessary */
3129 if (((isdn_net_local
*) (p
->local
->master
->priv
))->slave
== &p
->dev
)
3130 ((isdn_net_local
*) (p
->local
->master
->priv
))->slave
= p
->local
->slave
;
3132 /* Unregister only if it's a master-device */
3133 p
->dev
.hard_header_cache
= p
->local
->org_hhc
;
3134 p
->dev
.header_cache_update
= p
->local
->org_hcu
;
3135 unregister_netdev(&p
->dev
);
3137 /* Unlink device from chain */
3138 spin_lock_irqsave(&dev
->lock
, flags
);
3142 dev
->netdev
= p
->next
;
3143 if (p
->local
->slave
) {
3144 /* If this interface has a slave, remove it also */
3145 char *slavename
= ((isdn_net_local
*) (p
->local
->slave
->priv
))->name
;
3146 isdn_net_dev
*n
= dev
->netdev
;
3149 if (!strcmp(n
->local
->name
, slavename
)) {
3150 spin_unlock_irqrestore(&dev
->lock
, flags
);
3151 isdn_net_realrm(n
, q
);
3152 spin_lock_irqsave(&dev
->lock
, flags
);
3156 n
= (isdn_net_dev
*) n
->next
;
3159 spin_unlock_irqrestore(&dev
->lock
, flags
);
3160 /* If no more net-devices remain, disable auto-hangup timer */
3161 if (dev
->netdev
== NULL
)
3162 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3170 * Remove a single network-interface.
3173 isdn_net_rm(char *name
)
3179 /* Search name in netdev-chain */
3180 spin_lock_irqsave(&dev
->lock
, flags
);
3184 if (!strcmp(p
->local
->name
, name
)) {
3185 spin_unlock_irqrestore(&dev
->lock
, flags
);
3186 return (isdn_net_realrm(p
, q
));
3189 p
= (isdn_net_dev
*) p
->next
;
3191 spin_unlock_irqrestore(&dev
->lock
, flags
);
3192 /* If no more net-devices remain, disable auto-hangup timer */
3193 if (dev
->netdev
== NULL
)
3194 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3199 * Remove all network-interfaces
3202 isdn_net_rmall(void)
3207 /* Walk through netdev-chain */
3208 spin_lock_irqsave(&dev
->lock
, flags
);
3209 while (dev
->netdev
) {
3210 if (!dev
->netdev
->local
->master
) {
3211 /* Remove master-devices only, slaves get removed with their master */
3212 spin_unlock_irqrestore(&dev
->lock
, flags
);
3213 if ((ret
= isdn_net_realrm(dev
->netdev
, NULL
))) {
3216 spin_lock_irqsave(&dev
->lock
, flags
);
3220 spin_unlock_irqrestore(&dev
->lock
, flags
);