1 /* $Id: isdn_net.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
3 * Linux ISDN subsystem, network interfaces and related functions (linklevel).
5 * Copyright 1994-1998 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
12 * Data Over Voice (DOV) support added - Guy Ellis 23-Mar-02
14 * Outgoing calls - looks for a 'V' in first char of dialed number
15 * Incoming calls - checks first character of eaz as follows:
16 * Numeric - accept DATA only - original functionality
17 * 'V' - accept VOICE (DOV) only
18 * 'B' - accept BOTH DATA and DOV types
20 * Jan 2001: fix CISCO HDLC Bjoern A. Zeeb <i4l@zabbadoz.net>
21 * for info on the protocol, see
22 * http://i4l.zabbadoz.net/i4l/cisco-hdlc.txt
25 #include <linux/isdn.h>
28 #include <net/pkt_sched.h>
29 #include <linux/inetdevice.h>
30 #include "isdn_common.h"
32 #ifdef CONFIG_ISDN_PPP
35 #ifdef CONFIG_ISDN_X25
36 #include <linux/concap.h>
37 #include "isdn_concap.h"
42 * Outline of new tbusy handling:
44 * Old method, roughly spoken, consisted of setting tbusy when entering
45 * isdn_net_start_xmit() and at several other locations and clearing
46 * it from isdn_net_start_xmit() thread when sending was successful.
48 * With 2.3.x multithreaded network core, to prevent problems, tbusy should
49 * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
50 * condition is detected. Other threads (in particular isdn_net_stat_callb())
51 * are only allowed to clear tbusy.
58 * Most of the changes were pretty obvious and basically done by HE already.
60 * One problem of the isdn net device code is that is uses struct net_device
61 * for masters and slaves. However, only master interface are registered to
62 * the network layer, and therefore, it only makes sense to call netif_*
69 * Find out if the netdevice has been ifup-ed yet.
70 * For slaves, look at the corresponding master.
72 static __inline__
int isdn_net_device_started(isdn_net_dev
*n
)
74 isdn_net_local
*lp
= n
->local
;
75 struct net_device
*dev
;
81 return netif_running(dev
);
85 * wake up the network -> net_device queue.
86 * For slaves, wake the corresponding master interface.
88 static __inline__
void isdn_net_device_wake_queue(isdn_net_local
*lp
)
91 netif_wake_queue(lp
->master
);
93 netif_wake_queue(lp
->netdev
->dev
);
97 * stop the network -> net_device queue.
98 * For slaves, stop the corresponding master interface.
100 static __inline__
void isdn_net_device_stop_queue(isdn_net_local
*lp
)
103 netif_stop_queue(lp
->master
);
105 netif_stop_queue(lp
->netdev
->dev
);
109 * find out if the net_device which this lp belongs to (lp can be
110 * master or slave) is busy. It's busy iff all (master and slave)
113 static __inline__
int isdn_net_device_busy(isdn_net_local
*lp
)
119 if (!isdn_net_lp_busy(lp
))
123 nd
= ISDN_MASTER_PRIV(lp
)->netdev
;
127 spin_lock_irqsave(&nd
->queue_lock
, flags
);
130 if (!isdn_net_lp_busy(nlp
)) {
131 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
136 spin_unlock_irqrestore(&nd
->queue_lock
, flags
);
140 static __inline__
void isdn_net_inc_frame_cnt(isdn_net_local
*lp
)
142 atomic_inc(&lp
->frame_cnt
);
143 if (isdn_net_device_busy(lp
))
144 isdn_net_device_stop_queue(lp
);
147 static __inline__
void isdn_net_dec_frame_cnt(isdn_net_local
*lp
)
149 atomic_dec(&lp
->frame_cnt
);
151 if (!(isdn_net_device_busy(lp
))) {
152 if (!skb_queue_empty(&lp
->super_tx_queue
)) {
153 schedule_work(&lp
->tqueue
);
155 isdn_net_device_wake_queue(lp
);
160 static __inline__
void isdn_net_zero_frame_cnt(isdn_net_local
*lp
)
162 atomic_set(&lp
->frame_cnt
, 0);
165 /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
167 * For 2.3.x we push it up to 20 secs, because call establishment
168 * (in particular callback) may take such a long time, and we
169 * don't want confusing messages in the log. However, there is a slight
170 * possibility that this large timeout will break other things like MPPP,
171 * which might rely on the tx timeout. If so, we'll find out this way...
174 #define ISDN_NET_TX_TIMEOUT (20*HZ)
178 static int isdn_net_force_dial_lp(isdn_net_local
*);
179 static netdev_tx_t
isdn_net_start_xmit(struct sk_buff
*,
180 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
*) netdev_priv(dev
))->dops
;
218 struct concap_proto
* cprot
=
219 ((isdn_net_local
*) netdev_priv(dev
))->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 */
254 p
= MASTER_TO_SLAVE(dev
);
258 p
= MASTER_TO_SLAVE(p
);
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_all_tx(lp
->netdev
->dev
);
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 if (lp
->isdn_device
!= -1 && lp
->isdn_channel
!= -1)
297 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
299 lp
->flags
&= ~ISDN_NET_CONNECTED
;
300 lp
->isdn_device
= -1;
301 lp
->isdn_channel
= -1;
305 * Perform auto-hangup and cps-calculation for net-interfaces.
308 * Increment idle-counter (this counter is reset on any incoming or
309 * outgoing packet), if counter exceeds configured limit either do a
310 * hangup immediately or - if configured - wait until just before the next
313 * cps-calculation (needed for dynamic channel-bundling):
314 * Since this function is called every second, simply reset the
315 * byte-counter of the interface after copying it to the cps-variable.
317 static unsigned long last_jiffies
= -HZ
;
320 isdn_net_autohup(void)
322 isdn_net_dev
*p
= dev
->netdev
;
327 isdn_net_local
*l
= p
->local
;
328 if (jiffies
== last_jiffies
)
329 l
->cps
= l
->transcount
;
331 l
->cps
= (l
->transcount
* HZ
) / (jiffies
- last_jiffies
);
333 if (dev
->net_verbose
> 3)
334 printk(KERN_DEBUG
"%s: %d bogocps\n", p
->dev
->name
, l
->cps
);
335 if ((l
->flags
& ISDN_NET_CONNECTED
) && (!l
->dialstate
)) {
339 * if there is some dialmode where timeout-hangup
340 * should _not_ be done, check for that here
343 (l
->huptimer
> l
->onhtime
))
345 if (l
->hupflags
& ISDN_MANCHARGE
&&
346 l
->hupflags
& ISDN_CHARGEHUP
) {
347 while (time_after(jiffies
, l
->chargetime
+ l
->chargeint
))
348 l
->chargetime
+= l
->chargeint
;
349 if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
- 2 * HZ
))
350 if (l
->outgoing
|| l
->hupflags
& ISDN_INHUP
)
351 isdn_net_hangup(p
->dev
);
352 } else if (l
->outgoing
) {
353 if (l
->hupflags
& ISDN_CHARGEHUP
) {
354 if (l
->hupflags
& ISDN_WAITCHARGE
) {
355 printk(KERN_DEBUG
"isdn_net: Hupflags of %s are %X\n",
356 p
->dev
->name
, l
->hupflags
);
357 isdn_net_hangup(p
->dev
);
358 } else if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
)) {
360 "isdn_net: %s: chtime = %lu, chint = %d\n",
361 p
->dev
->name
, l
->chargetime
, l
->chargeint
);
362 isdn_net_hangup(p
->dev
);
365 isdn_net_hangup(p
->dev
);
366 } else if (l
->hupflags
& ISDN_INHUP
)
367 isdn_net_hangup(p
->dev
);
370 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*l
) == ISDN_NET_DM_OFF
)) {
371 isdn_net_hangup(p
->dev
);
375 p
= (isdn_net_dev
*) p
->next
;
377 last_jiffies
= jiffies
;
378 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, anymore
);
381 static void isdn_net_lp_disconnected(isdn_net_local
*lp
)
383 isdn_net_rm_from_bundle(lp
);
387 * Handle status-messages from ISDN-interfacecard.
388 * This function is called from within the main-status-dispatcher
389 * isdn_status_callback, which itself is called from the low-level driver.
390 * Return: 1 = Event handled, 0 = not for us or unknown Event.
393 isdn_net_stat_callback(int idx
, isdn_ctrl
*c
)
395 isdn_net_dev
*p
= dev
->st_netdev
[idx
];
396 int cmd
= c
->command
;
399 isdn_net_local
*lp
= p
->local
;
400 #ifdef CONFIG_ISDN_X25
401 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
402 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
405 case ISDN_STAT_BSENT
:
406 /* A packet has successfully been sent out */
407 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
409 isdn_net_dec_frame_cnt(lp
);
410 lp
->stats
.tx_packets
++;
411 lp
->stats
.tx_bytes
+= c
->parm
.length
;
414 case ISDN_STAT_DCONN
:
415 /* D-Channel is up */
416 switch (lp
->dialstate
) {
428 /* Either D-Channel-hangup or error during dialout */
429 #ifdef CONFIG_ISDN_X25
430 /* If we are not connencted then dialing had
431 failed. If there are generic encap protocol
432 receiver routines signal the closure of
435 if( !(lp
->flags
& ISDN_NET_CONNECTED
)
436 && pops
&& pops
-> disconn_ind
)
437 pops
-> disconn_ind(cprot
);
438 #endif /* CONFIG_ISDN_X25 */
439 if ((!lp
->dialstate
) && (lp
->flags
& ISDN_NET_CONNECTED
)) {
440 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
441 isdn_net_ciscohdlck_disconnected(lp
);
442 #ifdef CONFIG_ISDN_PPP
443 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
446 isdn_net_lp_disconnected(lp
);
447 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
448 printk(KERN_INFO
"%s: remote hangup\n", p
->dev
->name
);
449 printk(KERN_INFO
"%s: Chargesum is %d\n", p
->dev
->name
,
451 isdn_net_unbind_channel(lp
);
455 #ifdef CONFIG_ISDN_X25
457 /* B-Channel-hangup */
458 /* try if there are generic encap protocol
459 receiver routines and signal the closure of
461 if( pops
&& pops
-> disconn_ind
){
462 pops
-> disconn_ind(cprot
);
466 #endif /* CONFIG_ISDN_X25 */
467 case ISDN_STAT_BCONN
:
468 /* B-Channel is up */
469 isdn_net_zero_frame_cnt(lp
);
470 switch (lp
->dialstate
) {
478 if (lp
->dialstate
<= 6) {
479 dev
->usage
[idx
] |= ISDN_USAGE_OUTGOING
;
482 dev
->rx_netdev
[idx
] = p
;
484 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 1);
485 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
486 isdn_net_ciscohdlck_connected(lp
);
487 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
) {
488 if (lp
->master
) { /* is lp a slave? */
489 isdn_net_dev
*nd
= ISDN_MASTER_PRIV(lp
)->netdev
;
490 isdn_net_add_to_bundle(nd
, lp
);
493 printk(KERN_INFO
"isdn_net: %s connected\n", p
->dev
->name
);
494 /* If first Chargeinfo comes before B-Channel connect,
495 * we correct the timestamp here.
497 lp
->chargetime
= jiffies
;
499 /* reset dial-timeout */
501 lp
->dialwait_timer
= 0;
503 #ifdef CONFIG_ISDN_PPP
504 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
505 isdn_ppp_wakeup_daemon(lp
);
507 #ifdef CONFIG_ISDN_X25
508 /* try if there are generic concap receiver routines */
510 if( pops
->connect_ind
)
511 pops
->connect_ind(cprot
);
512 #endif /* CONFIG_ISDN_X25 */
513 /* ppp needs to do negotiations first */
514 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
)
515 isdn_net_device_wake_queue(lp
);
519 case ISDN_STAT_NODCH
:
520 /* No D-Channel avail. */
521 if (lp
->dialstate
== 4) {
527 /* Charge-info from TelCo. Calculate interval between
528 * charge-infos and set timestamp for last info for
529 * usage by isdn_net_autohup()
532 if (lp
->hupflags
& ISDN_HAVECHARGE
) {
533 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
534 lp
->chargeint
= jiffies
- lp
->chargetime
- (2 * HZ
);
536 if (lp
->hupflags
& ISDN_WAITCHARGE
)
537 lp
->hupflags
|= ISDN_HAVECHARGE
;
538 lp
->chargetime
= jiffies
;
539 printk(KERN_DEBUG
"isdn_net: Got CINF chargetime of %s now %lu\n",
540 p
->dev
->name
, lp
->chargetime
);
548 * Perform dialout for net-interfaces and timeout-handling for
549 * D-Channel-up and B-Channel-up Messages.
550 * This function is initially called from within isdn_net_start_xmit() or
551 * or isdn_net_find_icall() after initializing the dialstate for an
552 * interface. If further calls are needed, the function schedules itself
553 * for a timer-callback via isdn_timer_function().
554 * The dialstate is also affected by incoming status-messages from
555 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
560 isdn_net_dev
*p
= dev
->netdev
;
564 u_char
*phone_number
;
567 isdn_net_local
*lp
= p
->local
;
569 #ifdef ISDN_DEBUG_NET_DIAL
571 printk(KERN_DEBUG
"%s: dialstate=%d\n", p
->dev
->name
, lp
->dialstate
);
573 switch (lp
->dialstate
) {
575 /* Nothing to do for this interface */
578 /* Initiate dialout. Set phone-number-pointer to first number
581 lp
->dial
= lp
->phone
[1];
583 printk(KERN_WARNING
"%s: phone number deleted?\n",
585 isdn_net_hangup(p
->dev
);
590 if(lp
->dialtimeout
> 0)
591 if(lp
->dialstarted
== 0 || time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
)) {
592 lp
->dialstarted
= jiffies
;
593 lp
->dialwait_timer
= 0;
599 /* Prepare dialing. Clear EAZ, then set EAZ. */
600 cmd
.driver
= lp
->isdn_device
;
601 cmd
.arg
= lp
->isdn_channel
;
602 cmd
.command
= ISDN_CMD_CLREAZ
;
604 sprintf(cmd
.parm
.num
, "%s", isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
605 cmd
.command
= ISDN_CMD_SETEAZ
;
612 /* Setup interface, dial current phone-number, switch to next number.
613 * If list of phone-numbers is exhausted, increment
616 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
)) {
618 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
619 s
= "dial suppressed: isdn system stopped";
621 s
= "dial suppressed: dialmode `off'";
622 isdn_net_unreachable(p
->dev
, NULL
, s
);
623 isdn_net_hangup(p
->dev
);
626 cmd
.driver
= lp
->isdn_device
;
627 cmd
.command
= ISDN_CMD_SETL2
;
628 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
630 cmd
.driver
= lp
->isdn_device
;
631 cmd
.command
= ISDN_CMD_SETL3
;
632 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
634 cmd
.driver
= lp
->isdn_device
;
635 cmd
.arg
= lp
->isdn_channel
;
637 printk(KERN_WARNING
"%s: phone number deleted?\n",
639 isdn_net_hangup(p
->dev
);
642 if (!strncmp(lp
->dial
->num
, "LEASED", strlen("LEASED"))) {
644 printk(KERN_INFO
"%s: Open leased line ...\n", p
->dev
->name
);
646 if(lp
->dialtimeout
> 0)
647 if (time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
)) {
648 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
650 isdn_net_unreachable(p
->dev
, NULL
, "dial: timed out");
651 isdn_net_hangup(p
->dev
);
655 cmd
.driver
= lp
->isdn_device
;
656 cmd
.command
= ISDN_CMD_DIAL
;
657 cmd
.parm
.setup
.si2
= 0;
660 phone_number
= lp
->dial
->num
;
661 if ((*phone_number
== 'v') ||
662 (*phone_number
== 'V')) { /* DOV call */
663 cmd
.parm
.setup
.si1
= 1;
664 } else { /* DATA call */
665 cmd
.parm
.setup
.si1
= 7;
668 strcpy(cmd
.parm
.setup
.phone
, phone_number
);
670 * Switch to next number or back to start if at end of list.
672 if (!(lp
->dial
= (isdn_net_phone
*) lp
->dial
->next
)) {
673 lp
->dial
= lp
->phone
[1];
676 if (lp
->dialretry
> lp
->dialmax
) {
677 if (lp
->dialtimeout
== 0) {
678 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
680 isdn_net_unreachable(p
->dev
, NULL
, "dial: tried all numbers dialmax times");
682 isdn_net_hangup(p
->dev
);
686 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
687 isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
688 i
= isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
);
690 strcpy(dev
->num
[i
], cmd
.parm
.setup
.phone
);
691 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
694 printk(KERN_INFO
"%s: dialing %d %s... %s\n", p
->dev
->name
,
695 lp
->dialretry
, cmd
.parm
.setup
.phone
,
696 (cmd
.parm
.setup
.si1
== 1) ? "DOV" : "");
698 #ifdef ISDN_DEBUG_NET_DIAL
699 printk(KERN_DEBUG
"dial: d=%d c=%d\n", lp
->isdn_device
,
707 lp
->hupflags
|= ISDN_HAVECHARGE
;
708 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
710 lp
->hupflags
|= ISDN_WAITCHARGE
;
711 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
716 (lp
->flags
& ISDN_NET_CBOUT
)) ? 12 : 4;
719 /* Wait for D-Channel-connect.
720 * If timeout, switch back to state 3.
721 * Dialmax-handling moved to state 3.
723 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
728 /* Got D-Channel-Connect, send B-Channel-request */
729 cmd
.driver
= lp
->isdn_device
;
730 cmd
.arg
= lp
->isdn_channel
;
731 cmd
.command
= ISDN_CMD_ACCEPTB
;
738 /* Wait for B- or D-Channel-connect. If timeout,
739 * switch back to state 3.
741 #ifdef ISDN_DEBUG_NET_DIAL
742 printk(KERN_DEBUG
"dialtimer2: %d\n", lp
->dtimer
);
744 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
749 /* Got incoming Call, setup L2 and L3 protocols,
750 * then wait for D-Channel-connect
752 #ifdef ISDN_DEBUG_NET_DIAL
753 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
755 cmd
.driver
= lp
->isdn_device
;
756 cmd
.command
= ISDN_CMD_SETL2
;
757 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
759 cmd
.driver
= lp
->isdn_device
;
760 cmd
.command
= ISDN_CMD_SETL3
;
761 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
763 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT15
)
764 isdn_net_hangup(p
->dev
);
771 /* Got incoming D-Channel-Connect, send B-Channel-request */
772 cmd
.driver
= lp
->isdn_device
;
773 cmd
.arg
= lp
->isdn_channel
;
774 cmd
.command
= ISDN_CMD_ACCEPTB
;
782 /* Wait for B- or D-channel-connect */
783 #ifdef ISDN_DEBUG_NET_DIAL
784 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
786 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
787 isdn_net_hangup(p
->dev
);
793 if (lp
->dtimer
++ > lp
->cbdelay
)
798 /* Remote does callback. Hangup after cbdelay, then wait for incoming
801 if (lp
->dtimer
++ > lp
->cbdelay
)
803 printk(KERN_INFO
"%s: hangup waiting for callback ...\n", p
->dev
->name
);
806 cmd
.driver
= lp
->isdn_device
;
807 cmd
.command
= ISDN_CMD_HANGUP
;
808 cmd
.arg
= lp
->isdn_channel
;
810 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
815 printk(KERN_WARNING
"isdn_net: Illegal dialstate %d for device %s\n",
816 lp
->dialstate
, p
->dev
->name
);
818 p
= (isdn_net_dev
*) p
->next
;
820 isdn_timer_ctrl(ISDN_TIMER_NETDIAL
, anymore
);
824 * Perform hangup for a net-interface.
827 isdn_net_hangup(struct net_device
*d
)
829 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(d
);
831 #ifdef CONFIG_ISDN_X25
832 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
833 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
836 if (lp
->flags
& ISDN_NET_CONNECTED
) {
837 if (lp
->slave
!= NULL
) {
838 isdn_net_local
*slp
= ISDN_SLAVE_PRIV(lp
);
839 if (slp
->flags
& ISDN_NET_CONNECTED
) {
841 "isdn_net: hang up slave %s before %s\n",
842 lp
->slave
->name
, d
->name
);
843 isdn_net_hangup(lp
->slave
);
846 printk(KERN_INFO
"isdn_net: local hangup %s\n", d
->name
);
847 #ifdef CONFIG_ISDN_PPP
848 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
851 isdn_net_lp_disconnected(lp
);
852 #ifdef CONFIG_ISDN_X25
853 /* try if there are generic encap protocol
854 receiver routines and signal the closure of
856 if( pops
&& pops
-> disconn_ind
)
857 pops
-> disconn_ind(cprot
);
858 #endif /* CONFIG_ISDN_X25 */
860 cmd
.driver
= lp
->isdn_device
;
861 cmd
.command
= ISDN_CMD_HANGUP
;
862 cmd
.arg
= lp
->isdn_channel
;
864 printk(KERN_INFO
"%s: Chargesum is %d\n", d
->name
, lp
->charge
);
865 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
867 isdn_net_unbind_channel(lp
);
876 isdn_net_log_skb(struct sk_buff
* skb
, isdn_net_local
* lp
)
878 /* hopefully, this was set correctly */
879 const u_char
*p
= skb_network_header(skb
);
880 unsigned short proto
= ntohs(skb
->protocol
);
886 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
887 if (p
< skb
->data
|| skb
->network_header
>= skb
->tail
) {
888 /* fall back to old isdn_net_log_packet method() */
889 char * buf
= skb
->data
;
891 printk(KERN_DEBUG
"isdn_net: protocol %04x is buggy, dev %s\n", skb
->protocol
, lp
->netdev
->dev
->name
);
894 switch (lp
->p_encap
) {
895 case ISDN_NET_ENCAP_IPTYP
:
896 proto
= ntohs(*(__be16
*)&buf
[0]);
899 case ISDN_NET_ENCAP_ETHER
:
900 proto
= ntohs(*(__be16
*)&buf
[12]);
903 case ISDN_NET_ENCAP_CISCOHDLC
:
904 proto
= ntohs(*(__be16
*)&buf
[2]);
907 #ifdef CONFIG_ISDN_PPP
908 case ISDN_NET_ENCAP_SYNCPPP
:
909 proto
= ntohs(skb
->protocol
);
910 p
= &buf
[IPPP_MAX_HEADER
];
915 data_ofs
= ((p
[0] & 15) * 4);
920 strcpy(addinfo
, " ICMP");
923 strcpy(addinfo
, " IGMP");
926 strcpy(addinfo
, " IPIP");
929 ipp
= (ip_ports
*) (&p
[data_ofs
]);
930 sprintf(addinfo
, " TCP, port: %d -> %d", ntohs(ipp
->source
),
934 strcpy(addinfo
, " EGP");
937 strcpy(addinfo
, " PUP");
940 ipp
= (ip_ports
*) (&p
[data_ofs
]);
941 sprintf(addinfo
, " UDP, port: %d -> %d", ntohs(ipp
->source
),
945 strcpy(addinfo
, " IDP");
948 printk(KERN_INFO
"OPEN: %pI4 -> %pI4%s\n",
949 p
+ 12, p
+ 16, addinfo
);
952 printk(KERN_INFO
"OPEN: ARP %pI4 -> *.*.*.* ?%pI4\n",
959 * this function is used to send supervisory data, i.e. data which was
960 * not received from the network layer, but e.g. frames from ipppd, CCP
963 void isdn_net_write_super(isdn_net_local
*lp
, struct sk_buff
*skb
)
966 // we can't grab the lock from irq context,
967 // so we just queue the packet
968 skb_queue_tail(&lp
->super_tx_queue
, skb
);
969 schedule_work(&lp
->tqueue
);
973 spin_lock_bh(&lp
->xmit_lock
);
974 if (!isdn_net_lp_busy(lp
)) {
975 isdn_net_writebuf_skb(lp
, skb
);
977 skb_queue_tail(&lp
->super_tx_queue
, skb
);
979 spin_unlock_bh(&lp
->xmit_lock
);
983 * called from tq_immediate
985 static void isdn_net_softint(struct work_struct
*work
)
987 isdn_net_local
*lp
= container_of(work
, isdn_net_local
, tqueue
);
990 spin_lock_bh(&lp
->xmit_lock
);
991 while (!isdn_net_lp_busy(lp
)) {
992 skb
= skb_dequeue(&lp
->super_tx_queue
);
995 isdn_net_writebuf_skb(lp
, skb
);
997 spin_unlock_bh(&lp
->xmit_lock
);
1001 * all frames sent from the (net) LL to a HL driver should go via this function
1002 * it's serialized by the caller holding the lp->xmit_lock spinlock
1004 void isdn_net_writebuf_skb(isdn_net_local
*lp
, struct sk_buff
*skb
)
1007 int len
= skb
->len
; /* save len */
1009 /* before obtaining the lock the caller should have checked that
1010 the lp isn't busy */
1011 if (isdn_net_lp_busy(lp
)) {
1012 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1016 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1017 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1020 ret
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
);
1022 /* we should never get here */
1023 printk(KERN_WARNING
"%s: HL driver queue full\n", lp
->netdev
->dev
->name
);
1027 lp
->transcount
+= len
;
1028 isdn_net_inc_frame_cnt(lp
);
1033 lp
->stats
.tx_errors
++;
1039 * Helper function for isdn_net_start_xmit.
1040 * When called, the connection is already established.
1041 * Based on cps-calculation, check if device is overloaded.
1042 * If so, and if a slave exists, trigger dialing for it.
1043 * If any slave is online, deliver packets using a simple round robin
1046 * Return: 0 on success, !0 on failure.
1050 isdn_net_xmit(struct net_device
*ndev
, struct sk_buff
*skb
)
1053 isdn_net_local
*slp
;
1054 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(ndev
);
1055 int retv
= NETDEV_TX_OK
;
1057 if (((isdn_net_local
*) netdev_priv(ndev
))->master
) {
1058 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1060 return NETDEV_TX_OK
;
1063 /* For the other encaps the header has already been built */
1064 #ifdef CONFIG_ISDN_PPP
1065 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1066 return isdn_ppp_xmit(skb
, ndev
);
1069 nd
= ((isdn_net_local
*) netdev_priv(ndev
))->netdev
;
1070 lp
= isdn_net_get_locked_lp(nd
);
1072 printk(KERN_WARNING
"%s: all channels busy - requeuing!\n", ndev
->name
);
1073 return NETDEV_TX_BUSY
;
1075 /* we have our lp locked from now on */
1077 /* Reset hangup-timeout */
1078 lp
->huptimer
= 0; // FIXME?
1079 isdn_net_writebuf_skb(lp
, skb
);
1080 spin_unlock_bh(&lp
->xmit_lock
);
1082 /* the following stuff is here for backwards compatibility.
1083 * in future, start-up and hangup of slaves (based on current load)
1084 * should move to userspace and get based on an overall cps
1087 if (lp
->cps
> lp
->triggercps
) {
1090 /* First time overload: set timestamp only */
1092 lp
->sqfull_stamp
= jiffies
;
1094 /* subsequent overload: if slavedelay exceeded, start dialing */
1095 if (time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
)) {
1096 slp
= ISDN_SLAVE_PRIV(lp
);
1097 if (!(slp
->flags
& ISDN_NET_CONNECTED
)) {
1098 isdn_net_force_dial_lp(ISDN_SLAVE_PRIV(lp
));
1104 if (lp
->sqfull
&& time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
+ (10 * HZ
))) {
1107 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1108 nd
->queue
= nd
->local
;
1116 isdn_net_adjust_hdr(struct sk_buff
*skb
, struct net_device
*dev
)
1118 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(dev
);
1121 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1122 const int pullsize
= skb_network_offset(skb
) - ETH_HLEN
;
1124 printk(KERN_DEBUG
"isdn_net: Pull junk %d\n", pullsize
);
1125 skb_pull(skb
, pullsize
);
1131 static void isdn_net_tx_timeout(struct net_device
* ndev
)
1133 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(ndev
);
1135 printk(KERN_WARNING
"isdn_tx_timeout dev %s dialstate %d\n", ndev
->name
, lp
->dialstate
);
1136 if (!lp
->dialstate
){
1137 lp
->stats
.tx_errors
++;
1139 * There is a certain probability that this currently
1140 * works at all because if we always wake up the interface,
1141 * then upper layer will try to send the next packet
1142 * immediately. And then, the old clean_up logic in the
1143 * driver will hopefully continue to work as it used to do.
1145 * This is rather primitive right know, we better should
1146 * clean internal queues here, in particular for multilink and
1147 * ppp, and reset HL driver's channel, too. --HE
1149 * actually, this may not matter at all, because ISDN hardware
1150 * should not see transmitter hangs at all IMO
1151 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1155 ndev
->trans_start
= jiffies
;
1156 netif_wake_queue(ndev
);
1160 * Try sending a packet.
1161 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1162 * and start dialing.
1165 isdn_net_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1167 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(ndev
);
1168 #ifdef CONFIG_ISDN_X25
1169 struct concap_proto
* cprot
= lp
-> netdev
-> cprot
;
1170 /* At this point hard_start_xmit() passes control to the encapsulation
1171 protocol (if present).
1172 For X.25 auto-dialing is completly bypassed because:
1173 - It does not conform with the semantics of a reliable datalink
1174 service as needed by X.25 PLP.
1175 - I don't want that the interface starts dialing when the network layer
1176 sends a message which requests to disconnect the lapb link (or if it
1177 sends any other message not resulting in data transmission).
1178 Instead, dialing will be initiated by the encapsulation protocol entity
1179 when a dl_establish request is received from the upper layer.
1181 if (cprot
&& cprot
-> pops
) {
1182 int ret
= cprot
-> pops
-> encap_and_xmit ( cprot
, skb
);
1185 netif_stop_queue(ndev
);
1189 /* auto-dialing xmit function */
1191 #ifdef ISDN_DEBUG_NET_DUMP
1194 isdn_net_adjust_hdr(skb
, ndev
);
1195 #ifdef ISDN_DEBUG_NET_DUMP
1197 isdn_dumppkt("S:", buf
, skb
->len
, 40);
1200 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1202 /* only do autodial if allowed by config */
1203 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) {
1204 isdn_net_unreachable(ndev
, skb
, "dial rejected: interface not in dialmode `auto'");
1206 return NETDEV_TX_OK
;
1211 if(lp
->dialwait_timer
<= 0)
1212 if(lp
->dialstarted
> 0 && lp
->dialtimeout
> 0 && time_before(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
))
1213 lp
->dialwait_timer
= lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
;
1215 if(lp
->dialwait_timer
> 0) {
1216 if(time_before(jiffies
, lp
->dialwait_timer
)) {
1217 isdn_net_unreachable(ndev
, skb
, "dial rejected: retry-time not reached");
1219 return NETDEV_TX_OK
;
1221 lp
->dialwait_timer
= 0;
1223 /* Grab a free ISDN-Channel */
1224 spin_lock_irqsave(&dev
->lock
, flags
);
1226 isdn_get_free_channel(
1235 isdn_get_free_channel(
1243 spin_unlock_irqrestore(&dev
->lock
, flags
);
1244 isdn_net_unreachable(ndev
, skb
,
1247 return NETDEV_TX_OK
;
1249 /* Log packet, which triggered dialing */
1250 if (dev
->net_verbose
)
1251 isdn_net_log_skb(skb
, lp
);
1253 /* Connect interface with channel */
1254 isdn_net_bind_channel(lp
, chi
);
1255 #ifdef CONFIG_ISDN_PPP
1256 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1257 /* no 'first_skb' handling for syncPPP */
1258 if (isdn_ppp_bind(lp
) < 0) {
1260 isdn_net_unbind_channel(lp
);
1261 spin_unlock_irqrestore(&dev
->lock
, flags
);
1262 return NETDEV_TX_OK
; /* STN (skb to nirvana) ;) */
1264 #ifdef CONFIG_IPPP_FILTER
1265 if (isdn_ppp_autodial_filter(skb
, lp
)) {
1267 isdn_net_unbind_channel(lp
);
1268 spin_unlock_irqrestore(&dev
->lock
, flags
);
1269 isdn_net_unreachable(ndev
, skb
, "dial rejected: packet filtered");
1271 return NETDEV_TX_OK
;
1274 spin_unlock_irqrestore(&dev
->lock
, flags
);
1275 isdn_net_dial(); /* Initiate dialing */
1276 netif_stop_queue(ndev
);
1277 return NETDEV_TX_BUSY
; /* let upper layer requeue skb packet */
1280 /* Initiate dialing */
1281 spin_unlock_irqrestore(&dev
->lock
, flags
);
1283 isdn_net_device_stop_queue(lp
);
1284 return NETDEV_TX_BUSY
;
1286 isdn_net_unreachable(ndev
, skb
,
1289 return NETDEV_TX_OK
;
1292 /* Device is connected to an ISDN channel */
1293 ndev
->trans_start
= jiffies
;
1294 if (!lp
->dialstate
) {
1295 /* ISDN connection is established, try sending */
1297 ret
= (isdn_net_xmit(ndev
, skb
));
1298 if(ret
) netif_stop_queue(ndev
);
1301 netif_stop_queue(ndev
);
1304 return NETDEV_TX_BUSY
;
1308 * Shutdown a net-interface.
1311 isdn_net_close(struct net_device
*dev
)
1313 struct net_device
*p
;
1314 #ifdef CONFIG_ISDN_X25
1315 struct concap_proto
* cprot
=
1316 ((isdn_net_local
*) netdev_priv(dev
))->netdev
->cprot
;
1317 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1320 #ifdef CONFIG_ISDN_X25
1321 if( cprot
&& cprot
-> pops
) cprot
-> pops
-> close( cprot
);
1323 netif_stop_queue(dev
);
1324 p
= MASTER_TO_SLAVE(dev
);
1326 /* If this interface has slaves, stop them also */
1328 #ifdef CONFIG_ISDN_X25
1329 cprot
= ((isdn_net_local
*) netdev_priv(p
))
1331 if( cprot
&& cprot
-> pops
)
1332 cprot
-> pops
-> close( cprot
);
1335 p
= MASTER_TO_SLAVE(p
);
1338 isdn_net_hangup(dev
);
1339 isdn_unlock_drivers();
1346 static struct net_device_stats
*
1347 isdn_net_get_stats(struct net_device
*dev
)
1349 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(dev
);
1353 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1354 * instead of dev->hard_header_len off. This is done because the
1355 * lowlevel-driver has already pulled off its stuff when we get
1356 * here and this routine only gets called with p_encap == ETHER.
1357 * Determine the packet's protocol ID. The rule here is that we
1358 * assume 802.3 if the type field is short enough to be a length.
1359 * This is normal practice and works for any 'now in use' protocol.
1363 isdn_net_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1366 unsigned char *rawp
;
1368 skb_reset_mac_header(skb
);
1369 skb_pull(skb
, ETH_HLEN
);
1372 if (*eth
->h_dest
& 1) {
1373 if (memcmp(eth
->h_dest
, dev
->broadcast
, ETH_ALEN
) == 0)
1374 skb
->pkt_type
= PACKET_BROADCAST
;
1376 skb
->pkt_type
= PACKET_MULTICAST
;
1379 * This ALLMULTI check should be redundant by 1.4
1380 * so don't forget to remove it.
1383 else if (dev
->flags
& (IFF_PROMISC
/*| IFF_ALLMULTI*/)) {
1384 if (memcmp(eth
->h_dest
, dev
->dev_addr
, ETH_ALEN
))
1385 skb
->pkt_type
= PACKET_OTHERHOST
;
1387 if (ntohs(eth
->h_proto
) >= 1536)
1388 return eth
->h_proto
;
1393 * This is a magic hack to spot IPX packets. Older Novell breaks
1394 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1395 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1396 * won't work for fault tolerant netware but does for the rest.
1398 if (*(unsigned short *) rawp
== 0xFFFF)
1399 return htons(ETH_P_802_3
);
1403 return htons(ETH_P_802_2
);
1408 * CISCO HDLC keepalive specific stuff
1410 static struct sk_buff
*
1411 isdn_net_ciscohdlck_alloc_skb(isdn_net_local
*lp
, int len
)
1413 unsigned short hl
= dev
->drv
[lp
->isdn_device
]->interface
->hl_hdrlen
;
1414 struct sk_buff
*skb
;
1416 skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1418 skb_reserve(skb
, hl
);
1420 printk("isdn out of mem at %s:%d!\n", __FILE__
, __LINE__
);
1424 /* cisco hdlck device private ioctls */
1426 isdn_ciscohdlck_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1428 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(dev
);
1429 unsigned long len
= 0;
1430 unsigned long expires
= 0;
1432 int period
= lp
->cisco_keepalive_period
;
1433 s8 debserint
= lp
->cisco_debserint
;
1436 if (lp
->p_encap
!= ISDN_NET_ENCAP_CISCOHDLCK
)
1440 /* get/set keepalive period */
1441 case SIOCGKEEPPERIOD
:
1442 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1443 if (copy_to_user(ifr
->ifr_data
,
1444 &lp
->cisco_keepalive_period
, len
))
1447 case SIOCSKEEPPERIOD
:
1448 tmp
= lp
->cisco_keepalive_period
;
1449 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1450 if (copy_from_user(&period
, ifr
->ifr_data
, len
))
1452 if ((period
> 0) && (period
<= 32767))
1453 lp
->cisco_keepalive_period
= period
;
1456 if (!rc
&& (tmp
!= lp
->cisco_keepalive_period
)) {
1457 expires
= (unsigned long)(jiffies
+
1458 lp
->cisco_keepalive_period
* HZ
);
1459 mod_timer(&lp
->cisco_timer
, expires
);
1460 printk(KERN_INFO
"%s: Keepalive period set "
1462 dev
->name
, lp
->cisco_keepalive_period
);
1466 /* get/set debugging */
1467 case SIOCGDEBSERINT
:
1468 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1469 if (copy_to_user(ifr
->ifr_data
,
1470 &lp
->cisco_debserint
, len
))
1473 case SIOCSDEBSERINT
:
1474 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1475 if (copy_from_user(&debserint
,
1476 ifr
->ifr_data
, len
))
1478 if ((debserint
>= 0) && (debserint
<= 64))
1479 lp
->cisco_debserint
= debserint
;
1492 static int isdn_net_ioctl(struct net_device
*dev
,
1493 struct ifreq
*ifr
, int cmd
)
1495 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(dev
);
1497 switch (lp
->p_encap
) {
1498 #ifdef CONFIG_ISDN_PPP
1499 case ISDN_NET_ENCAP_SYNCPPP
:
1500 return isdn_ppp_dev_ioctl(dev
, ifr
, cmd
);
1502 case ISDN_NET_ENCAP_CISCOHDLCK
:
1503 return isdn_ciscohdlck_dev_ioctl(dev
, ifr
, cmd
);
1509 /* called via cisco_timer.function */
1511 isdn_net_ciscohdlck_slarp_send_keepalive(unsigned long data
)
1513 isdn_net_local
*lp
= (isdn_net_local
*) data
;
1514 struct sk_buff
*skb
;
1516 unsigned long last_cisco_myseq
= lp
->cisco_myseq
;
1519 if (!(lp
->flags
& ISDN_NET_CONNECTED
) || lp
->dialstate
) {
1520 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1525 myseq_diff
= (lp
->cisco_myseq
- lp
->cisco_mineseen
);
1526 if ((lp
->cisco_line_state
) && ((myseq_diff
>= 3)||(myseq_diff
<= -3))) {
1527 /* line up -> down */
1528 lp
->cisco_line_state
= 0;
1529 printk (KERN_WARNING
1530 "UPDOWN: Line protocol on Interface %s,"
1531 " changed state to down\n", lp
->netdev
->dev
->name
);
1532 /* should stop routing higher-level data accross */
1533 } else if ((!lp
->cisco_line_state
) &&
1534 (myseq_diff
>= 0) && (myseq_diff
<= 2)) {
1535 /* line down -> up */
1536 lp
->cisco_line_state
= 1;
1537 printk (KERN_WARNING
1538 "UPDOWN: Line protocol on Interface %s,"
1539 " changed state to up\n", lp
->netdev
->dev
->name
);
1540 /* restart routing higher-level data accross */
1543 if (lp
->cisco_debserint
)
1544 printk (KERN_DEBUG
"%s: HDLC "
1545 "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
1546 lp
->netdev
->dev
->name
, last_cisco_myseq
, lp
->cisco_mineseen
,
1547 ((last_cisco_myseq
== lp
->cisco_mineseen
) ? '*' : 040),
1549 ((lp
->cisco_line_state
) ? "line up" : "line down"));
1551 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1555 p
= skb_put(skb
, 4 + 14);
1558 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1559 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1560 *(__be16
*)(p
+ 2) = cpu_to_be16(CISCO_TYPE_SLARP
);
1562 /* slarp keepalive */
1563 *(__be32
*)(p
+ 4) = cpu_to_be32(CISCO_SLARP_KEEPALIVE
);
1564 *(__be32
*)(p
+ 8) = cpu_to_be32(lp
->cisco_myseq
);
1565 *(__be32
*)(p
+ 12) = cpu_to_be32(lp
->cisco_yourseq
);
1566 *(__be16
*)(p
+ 16) = cpu_to_be16(0xffff); // reliablity, always 0xffff
1569 isdn_net_write_super(lp
, skb
);
1571 lp
->cisco_timer
.expires
= jiffies
+ lp
->cisco_keepalive_period
* HZ
;
1573 add_timer(&lp
->cisco_timer
);
1577 isdn_net_ciscohdlck_slarp_send_request(isdn_net_local
*lp
)
1579 struct sk_buff
*skb
;
1582 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1586 p
= skb_put(skb
, 4 + 14);
1589 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1590 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1591 *(__be16
*)(p
+ 2) = cpu_to_be16(CISCO_TYPE_SLARP
);
1594 *(__be32
*)(p
+ 4) = cpu_to_be32(CISCO_SLARP_REQUEST
);
1595 *(__be32
*)(p
+ 8) = cpu_to_be32(0); // address
1596 *(__be32
*)(p
+ 12) = cpu_to_be32(0); // netmask
1597 *(__be16
*)(p
+ 16) = cpu_to_be16(0); // unused
1600 isdn_net_write_super(lp
, skb
);
1604 isdn_net_ciscohdlck_connected(isdn_net_local
*lp
)
1606 lp
->cisco_myseq
= 0;
1607 lp
->cisco_mineseen
= 0;
1608 lp
->cisco_yourseq
= 0;
1609 lp
->cisco_keepalive_period
= ISDN_TIMER_KEEPINT
;
1610 lp
->cisco_last_slarp_in
= 0;
1611 lp
->cisco_line_state
= 0;
1612 lp
->cisco_debserint
= 0;
1614 /* send slarp request because interface/seq.no.s reset */
1615 isdn_net_ciscohdlck_slarp_send_request(lp
);
1617 init_timer(&lp
->cisco_timer
);
1618 lp
->cisco_timer
.data
= (unsigned long) lp
;
1619 lp
->cisco_timer
.function
= isdn_net_ciscohdlck_slarp_send_keepalive
;
1620 lp
->cisco_timer
.expires
= jiffies
+ lp
->cisco_keepalive_period
* HZ
;
1621 add_timer(&lp
->cisco_timer
);
1625 isdn_net_ciscohdlck_disconnected(isdn_net_local
*lp
)
1627 del_timer(&lp
->cisco_timer
);
1631 isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local
*lp
)
1633 struct sk_buff
*skb
;
1635 struct in_device
*in_dev
= NULL
;
1636 __be32 addr
= 0; /* local ipv4 address */
1637 __be32 mask
= 0; /* local netmask */
1639 if ((in_dev
= lp
->netdev
->dev
->ip_ptr
) != NULL
) {
1640 /* take primary(first) address of interface */
1641 struct in_ifaddr
*ifa
= in_dev
->ifa_list
;
1643 addr
= ifa
->ifa_local
;
1644 mask
= ifa
->ifa_mask
;
1648 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1652 p
= skb_put(skb
, 4 + 14);
1655 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1656 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1657 *(__be16
*)(p
+ 2) = cpu_to_be16(CISCO_TYPE_SLARP
);
1659 /* slarp reply, send own ip/netmask; if values are nonsense remote
1660 * should think we are unable to provide it with an address via SLARP */
1661 *(__be32
*)(p
+ 4) = cpu_to_be32(CISCO_SLARP_REPLY
);
1662 *(__be32
*)(p
+ 8) = addr
; // address
1663 *(__be32
*)(p
+ 12) = mask
; // netmask
1664 *(__be16
*)(p
+ 16) = cpu_to_be16(0); // unused
1667 isdn_net_write_super(lp
, skb
);
1671 isdn_net_ciscohdlck_slarp_in(isdn_net_local
*lp
, struct sk_buff
*skb
)
1679 __be32
*addr
, *mask
;
1686 code
= be32_to_cpup((__be32
*)p
);
1690 case CISCO_SLARP_REQUEST
:
1691 lp
->cisco_yourseq
= 0;
1692 isdn_net_ciscohdlck_slarp_send_reply(lp
);
1694 case CISCO_SLARP_REPLY
:
1696 mask
= (__be32
*)(p
+ 4);
1697 if (*mask
!= cpu_to_be32(0xfffffffc))
1698 goto slarp_reply_out
;
1699 if ((*addr
& cpu_to_be32(3)) == cpu_to_be32(0) ||
1700 (*addr
& cpu_to_be32(3)) == cpu_to_be32(3))
1701 goto slarp_reply_out
;
1702 local
= *addr
^ cpu_to_be32(3);
1703 printk(KERN_INFO
"%s: got slarp reply: remote ip: %pI4, local ip: %pI4 mask: %pI4\n",
1704 lp
->netdev
->dev
->name
, addr
, &local
, mask
);
1707 printk(KERN_INFO
"%s: got invalid slarp reply (%pI4/%pI4) - ignored\n",
1708 lp
->netdev
->dev
->name
, addr
, mask
);
1710 case CISCO_SLARP_KEEPALIVE
:
1711 period
= (int)((jiffies
- lp
->cisco_last_slarp_in
1713 if (lp
->cisco_debserint
&&
1714 (period
!= lp
->cisco_keepalive_period
) &&
1715 lp
->cisco_last_slarp_in
) {
1716 printk(KERN_DEBUG
"%s: Keepalive period mismatch - "
1717 "is %d but should be %d.\n",
1718 lp
->netdev
->dev
->name
, period
,
1719 lp
->cisco_keepalive_period
);
1721 lp
->cisco_last_slarp_in
= jiffies
;
1722 my_seq
= be32_to_cpup((__be32
*)(p
+ 0));
1723 your_seq
= be32_to_cpup((__be32
*)(p
+ 4));
1724 unused
= be16_to_cpup((__be16
*)(p
+ 8));
1726 lp
->cisco_yourseq
= my_seq
;
1727 lp
->cisco_mineseen
= your_seq
;
1733 isdn_net_ciscohdlck_receive(isdn_net_local
*lp
, struct sk_buff
*skb
)
1744 addr
= *(u8
*)(p
+ 0);
1745 ctrl
= *(u8
*)(p
+ 1);
1746 type
= be16_to_cpup((__be16
*)(p
+ 2));
1750 if (addr
!= CISCO_ADDR_UNICAST
&& addr
!= CISCO_ADDR_BROADCAST
) {
1751 printk(KERN_WARNING
"%s: Unknown Cisco addr 0x%02x\n",
1752 lp
->netdev
->dev
->name
, addr
);
1755 if (ctrl
!= CISCO_CTRL
) {
1756 printk(KERN_WARNING
"%s: Unknown Cisco ctrl 0x%02x\n",
1757 lp
->netdev
->dev
->name
, ctrl
);
1762 case CISCO_TYPE_SLARP
:
1763 isdn_net_ciscohdlck_slarp_in(lp
, skb
);
1765 case CISCO_TYPE_CDP
:
1766 if (lp
->cisco_debserint
)
1767 printk(KERN_DEBUG
"%s: Received CDP packet. use "
1768 "\"no cdp enable\" on cisco.\n",
1769 lp
->netdev
->dev
->name
);
1772 /* no special cisco protocol */
1773 skb
->protocol
= htons(type
);
1783 * Got a packet from ISDN-Channel.
1786 isdn_net_receive(struct net_device
*ndev
, struct sk_buff
*skb
)
1788 isdn_net_local
*lp
= (isdn_net_local
*) netdev_priv(ndev
);
1789 isdn_net_local
*olp
= lp
; /* original 'lp' */
1790 #ifdef CONFIG_ISDN_X25
1791 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
1793 lp
->transcount
+= skb
->len
;
1795 lp
->stats
.rx_packets
++;
1796 lp
->stats
.rx_bytes
+= skb
->len
;
1798 /* Bundling: If device is a slave-device, deliver to master, also
1799 * handle master's statistics and hangup-timeout
1802 lp
= (isdn_net_local
*) netdev_priv(ndev
);
1803 lp
->stats
.rx_packets
++;
1804 lp
->stats
.rx_bytes
+= skb
->len
;
1807 skb
->pkt_type
= PACKET_HOST
;
1808 skb_reset_mac_header(skb
);
1809 #ifdef ISDN_DEBUG_NET_DUMP
1810 isdn_dumppkt("R:", skb
->data
, skb
->len
, 40);
1812 switch (lp
->p_encap
) {
1813 case ISDN_NET_ENCAP_ETHER
:
1814 /* Ethernet over ISDN */
1817 skb
->protocol
= isdn_net_type_trans(skb
, ndev
);
1819 case ISDN_NET_ENCAP_UIHDLC
:
1820 /* HDLC with UI-frame (for ispa with -h1 option) */
1825 case ISDN_NET_ENCAP_RAWIP
:
1826 /* RAW-IP without MAC-Header */
1829 skb
->protocol
= htons(ETH_P_IP
);
1831 case ISDN_NET_ENCAP_CISCOHDLCK
:
1832 isdn_net_ciscohdlck_receive(lp
, skb
);
1834 case ISDN_NET_ENCAP_CISCOHDLC
:
1835 /* CISCO-HDLC IP with type field and fake I-frame-header */
1838 case ISDN_NET_ENCAP_IPTYP
:
1839 /* IP with type field */
1842 skb
->protocol
= *(__be16
*)&(skb
->data
[0]);
1844 if (*(unsigned short *) skb
->data
== 0xFFFF)
1845 skb
->protocol
= htons(ETH_P_802_3
);
1847 #ifdef CONFIG_ISDN_PPP
1848 case ISDN_NET_ENCAP_SYNCPPP
:
1849 /* huptimer is done in isdn_ppp_push_higher */
1850 isdn_ppp_receive(lp
->netdev
, olp
, skb
);
1855 #ifdef CONFIG_ISDN_X25
1856 /* try if there are generic sync_device receiver routines */
1857 if(cprot
) if(cprot
-> pops
)
1858 if( cprot
-> pops
-> data_ind
){
1859 cprot
-> pops
-> data_ind(cprot
,skb
);
1862 #endif /* CONFIG_ISDN_X25 */
1863 printk(KERN_WARNING
"%s: unknown encapsulation, dropping\n",
1864 lp
->netdev
->dev
->name
);
1874 * A packet arrived via ISDN. Search interface-chain for a corresponding
1875 * interface. If found, deliver packet to receiver-function and return 1,
1879 isdn_net_rcv_skb(int idx
, struct sk_buff
*skb
)
1881 isdn_net_dev
*p
= dev
->rx_netdev
[idx
];
1884 isdn_net_local
*lp
= p
->local
;
1885 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
1887 isdn_net_receive(p
->dev
, skb
);
1896 * depends on encaps that is being used.
1899 static int isdn_net_header(struct sk_buff
*skb
, struct net_device
*dev
,
1900 unsigned short type
,
1901 const void *daddr
, const void *saddr
, unsigned plen
)
1903 isdn_net_local
*lp
= netdev_priv(dev
);
1907 switch (lp
->p_encap
) {
1908 case ISDN_NET_ENCAP_ETHER
:
1909 len
= eth_header(skb
, dev
, type
, daddr
, saddr
, plen
);
1911 #ifdef CONFIG_ISDN_PPP
1912 case ISDN_NET_ENCAP_SYNCPPP
:
1913 /* stick on a fake header to keep fragmentation code happy. */
1914 len
= IPPP_MAX_HEADER
;
1918 case ISDN_NET_ENCAP_RAWIP
:
1919 printk(KERN_WARNING
"isdn_net_header called with RAW_IP!\n");
1922 case ISDN_NET_ENCAP_IPTYP
:
1923 /* ethernet type field */
1924 *((__be16
*)skb_push(skb
, 2)) = htons(type
);
1927 case ISDN_NET_ENCAP_UIHDLC
:
1928 /* HDLC with UI-Frames (for ispa with -h1 option) */
1929 *((__be16
*)skb_push(skb
, 2)) = htons(0x0103);
1932 case ISDN_NET_ENCAP_CISCOHDLC
:
1933 case ISDN_NET_ENCAP_CISCOHDLCK
:
1934 p
= skb_push(skb
, 4);
1935 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1936 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1937 *(__be16
*)(p
+ 2) = cpu_to_be16(type
);
1941 #ifdef CONFIG_ISDN_X25
1943 /* try if there are generic concap protocol routines */
1944 if( lp
-> netdev
-> cprot
){
1945 printk(KERN_WARNING
"isdn_net_header called with concap_proto!\n");
1950 #endif /* CONFIG_ISDN_X25 */
1955 /* We don't need to send arp, because we have point-to-point connections. */
1957 isdn_net_rebuild_header(struct sk_buff
*skb
)
1959 struct net_device
*dev
= skb
->dev
;
1960 isdn_net_local
*lp
= netdev_priv(dev
);
1963 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1964 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
1967 * Only ARP/IP is currently supported
1970 if (eth
->h_proto
!= htons(ETH_P_IP
)) {
1972 "isdn_net: %s don't know how to resolve type %d addresses?\n",
1973 dev
->name
, (int) eth
->h_proto
);
1974 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
1978 * Try to get ARP to resolve the header.
1981 ret
= arp_find(eth
->h_dest
, skb
);
1987 static int isdn_header_cache(const struct neighbour
*neigh
, struct hh_cache
*hh
)
1989 const struct net_device
*dev
= neigh
->dev
;
1990 isdn_net_local
*lp
= netdev_priv(dev
);
1992 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
)
1993 return eth_header_cache(neigh
, hh
);
1997 static void isdn_header_cache_update(struct hh_cache
*hh
,
1998 const struct net_device
*dev
,
1999 const unsigned char *haddr
)
2001 isdn_net_local
*lp
= netdev_priv(dev
);
2002 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
)
2003 eth_header_cache_update(hh
, dev
, haddr
);
2006 static const struct header_ops isdn_header_ops
= {
2007 .create
= isdn_net_header
,
2008 .rebuild
= isdn_net_rebuild_header
,
2009 .cache
= isdn_header_cache
,
2010 .cache_update
= isdn_header_cache_update
,
2014 * Interface-setup. (just after registering a new interface)
2017 isdn_net_init(struct net_device
*ndev
)
2019 ushort max_hlhdr_len
= 0;
2023 * up till binding we ask the protocol layer to reserve as much
2024 * as we might need for HL layer
2027 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
2028 if (dev
->drv
[drvidx
])
2029 if (max_hlhdr_len
< dev
->drv
[drvidx
]->interface
->hl_hdrlen
)
2030 max_hlhdr_len
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
2032 ndev
->hard_header_len
= ETH_HLEN
+ max_hlhdr_len
;
2037 isdn_net_swapbind(int drvidx
)
2041 #ifdef ISDN_DEBUG_NET_ICALL
2042 printk(KERN_DEBUG
"n_fi: swapping ch of %d\n", drvidx
);
2046 if (p
->local
->pre_device
== drvidx
)
2047 switch (p
->local
->pre_channel
) {
2049 p
->local
->pre_channel
= 1;
2052 p
->local
->pre_channel
= 0;
2055 p
= (isdn_net_dev
*) p
->next
;
2060 isdn_net_swap_usage(int i1
, int i2
)
2062 int u1
= dev
->usage
[i1
] & ISDN_USAGE_EXCLUSIVE
;
2063 int u2
= dev
->usage
[i2
] & ISDN_USAGE_EXCLUSIVE
;
2065 #ifdef ISDN_DEBUG_NET_ICALL
2066 printk(KERN_DEBUG
"n_fi: usage of %d and %d\n", i1
, i2
);
2068 dev
->usage
[i1
] &= ~ISDN_USAGE_EXCLUSIVE
;
2069 dev
->usage
[i1
] |= u2
;
2070 dev
->usage
[i2
] &= ~ISDN_USAGE_EXCLUSIVE
;
2071 dev
->usage
[i2
] |= u1
;
2076 * An incoming call-request has arrived.
2077 * Search the interface-chain for an appropriate interface.
2078 * If found, connect the interface to the ISDN-channel and initiate
2079 * D- and B-Channel-setup. If secure-flag is set, accept only
2080 * configured phone-numbers. If callback-flag is set, initiate
2083 * Return-Value: 0 = No appropriate interface for this call.
2085 * 2 = Reject call, wait cbdelay, then call back
2087 * 4 = Wait cbdelay, then call back
2088 * 5 = No appropriate interface for this call,
2089 * would eventually match if CID was longer.
2093 isdn_net_find_icall(int di
, int ch
, int idx
, setup_parm
*setup
)
2105 char nr
[ISDN_MSNLEN
];
2108 /* Search name in netdev-chain */
2109 if (!setup
->phone
[0]) {
2112 printk(KERN_INFO
"isdn_net: Incoming call without OAD, assuming '0'\n");
2114 strlcpy(nr
, setup
->phone
, ISDN_MSNLEN
);
2115 si1
= (int) setup
->si1
;
2116 si2
= (int) setup
->si2
;
2117 if (!setup
->eazmsn
[0]) {
2118 printk(KERN_WARNING
"isdn_net: Incoming call without CPN, assuming '0'\n");
2121 eaz
= setup
->eazmsn
;
2122 if (dev
->net_verbose
> 1)
2123 printk(KERN_INFO
"isdn_net: call from %s,%d,%d -> %s\n", nr
, si1
, si2
, eaz
);
2124 /* Accept DATA and VOICE calls at this stage
2125 * local eaz is checked later for allowed call types
2127 if ((si1
!= 7) && (si1
!= 1)) {
2128 if (dev
->net_verbose
> 1)
2129 printk(KERN_INFO
"isdn_net: Service-Indicator not 1 or 7, ignored\n");
2132 n
= (isdn_net_phone
*) 0;
2134 ematch
= wret
= swapped
= 0;
2135 #ifdef ISDN_DEBUG_NET_ICALL
2136 printk(KERN_DEBUG
"n_fi: di=%d ch=%d idx=%d usg=%d\n", di
, ch
, idx
,
2141 isdn_net_local
*lp
= p
->local
;
2143 /* If last check has triggered as binding-swap, revert it */
2146 isdn_net_swap_usage(idx
, sidx
);
2149 isdn_net_swapbind(di
);
2153 /* check acceptable call types for DOV */
2154 my_eaz
= isdn_map_eaz2msn(lp
->msn
, di
);
2155 if (si1
== 1) { /* it's a DOV call, check if we allow it */
2156 if (*my_eaz
== 'v' || *my_eaz
== 'V' ||
2157 *my_eaz
== 'b' || *my_eaz
== 'B')
2158 my_eaz
++; /* skip to allow a match */
2160 my_eaz
= NULL
; /* force non match */
2161 } else { /* it's a DATA call, check if we allow it */
2162 if (*my_eaz
== 'b' || *my_eaz
== 'B')
2163 my_eaz
++; /* skip to allow a match */
2166 matchret
= isdn_msncmp(eaz
, my_eaz
);
2172 /* Remember if more numbers eventually can match */
2173 if (matchret
> wret
)
2175 #ifdef ISDN_DEBUG_NET_ICALL
2176 printk(KERN_DEBUG
"n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2177 p
->dev
->name
, lp
->msn
, lp
->flags
, lp
->dialstate
);
2179 if ((!matchret
) && /* EAZ is matching */
2180 (((!(lp
->flags
& ISDN_NET_CONNECTED
)) && /* but not connected */
2181 (USG_NONE(dev
->usage
[idx
]))) || /* and ch. unused or */
2182 ((((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) && /* if dialing */
2183 (!(lp
->flags
& ISDN_NET_CALLBACK
))) /* but no callback */
2186 #ifdef ISDN_DEBUG_NET_ICALL
2187 printk(KERN_DEBUG
"n_fi: match1, pdev=%d pch=%d\n",
2188 lp
->pre_device
, lp
->pre_channel
);
2190 if (dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) {
2191 if ((lp
->pre_channel
!= ch
) ||
2192 (lp
->pre_device
!= di
)) {
2193 /* Here we got a problem:
2194 * If using an ICN-Card, an incoming call is always signaled on
2195 * on the first channel of the card, if both channels are
2196 * down. However this channel may be bound exclusive. If the
2197 * second channel is free, this call should be accepted.
2198 * The solution is horribly but it runs, so what:
2199 * We exchange the exclusive bindings of the two channels, the
2200 * corresponding variables in the interface-structs.
2203 sidx
= isdn_dc2minor(di
, 1);
2204 #ifdef ISDN_DEBUG_NET_ICALL
2205 printk(KERN_DEBUG
"n_fi: ch is 0\n");
2207 if (USG_NONE(dev
->usage
[sidx
])) {
2208 /* Second Channel is free, now see if it is bound
2210 if (dev
->usage
[sidx
] & ISDN_USAGE_EXCLUSIVE
) {
2211 #ifdef ISDN_DEBUG_NET_ICALL
2212 printk(KERN_DEBUG
"n_fi: 2nd channel is down and bound\n");
2214 /* Yes, swap bindings only, if the original
2215 * binding is bound to channel 1 of this driver */
2216 if ((lp
->pre_device
== di
) &&
2217 (lp
->pre_channel
== 1)) {
2218 isdn_net_swapbind(di
);
2221 /* ... else iterate next device */
2222 p
= (isdn_net_dev
*) p
->next
;
2226 #ifdef ISDN_DEBUG_NET_ICALL
2227 printk(KERN_DEBUG
"n_fi: 2nd channel is down and unbound\n");
2229 /* No, swap always and swap excl-usage also */
2230 isdn_net_swap_usage(idx
, sidx
);
2231 isdn_net_swapbind(di
);
2234 /* Now check for exclusive binding again */
2235 #ifdef ISDN_DEBUG_NET_ICALL
2236 printk(KERN_DEBUG
"n_fi: final check\n");
2238 if ((dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) &&
2239 ((lp
->pre_channel
!= ch
) ||
2240 (lp
->pre_device
!= di
))) {
2241 #ifdef ISDN_DEBUG_NET_ICALL
2242 printk(KERN_DEBUG
"n_fi: final check failed\n");
2244 p
= (isdn_net_dev
*) p
->next
;
2249 /* We are already on the second channel, so nothing to do */
2250 #ifdef ISDN_DEBUG_NET_ICALL
2251 printk(KERN_DEBUG
"n_fi: already on 2nd channel\n");
2256 #ifdef ISDN_DEBUG_NET_ICALL
2257 printk(KERN_DEBUG
"n_fi: match2\n");
2260 if (lp
->flags
& ISDN_NET_SECURE
) {
2262 if (!isdn_msncmp(nr
, n
->num
))
2264 n
= (isdn_net_phone
*) n
->next
;
2267 if (n
|| (!(lp
->flags
& ISDN_NET_SECURE
))) {
2268 #ifdef ISDN_DEBUG_NET_ICALL
2269 printk(KERN_DEBUG
"n_fi: match3\n");
2271 /* matching interface found */
2274 * Is the state STOPPED?
2275 * If so, no dialin is allowed,
2276 * so reject actively.
2278 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2279 printk(KERN_INFO
"incoming call, interface %s `stopped' -> rejected\n",
2284 * Is the interface up?
2285 * If not, reject the call actively.
2287 if (!isdn_net_device_started(p
)) {
2288 printk(KERN_INFO
"%s: incoming call, interface down -> rejected\n",
2292 /* Interface is up, now see if it's a slave. If so, see if
2293 * it's master and parent slave is online. If not, reject the call.
2296 isdn_net_local
*mlp
= ISDN_MASTER_PRIV(lp
);
2297 printk(KERN_DEBUG
"ICALLslv: %s\n", p
->dev
->name
);
2298 printk(KERN_DEBUG
"master=%s\n", lp
->master
->name
);
2299 if (mlp
->flags
& ISDN_NET_CONNECTED
) {
2300 printk(KERN_DEBUG
"master online\n");
2301 /* Master is online, find parent-slave (master if first slave) */
2302 while (mlp
->slave
) {
2303 if (ISDN_SLAVE_PRIV(mlp
) == lp
)
2305 mlp
= ISDN_SLAVE_PRIV(mlp
);
2308 printk(KERN_DEBUG
"master offline\n");
2309 /* Found parent, if it's offline iterate next device */
2310 printk(KERN_DEBUG
"mlpf: %d\n", mlp
->flags
& ISDN_NET_CONNECTED
);
2311 if (!(mlp
->flags
& ISDN_NET_CONNECTED
)) {
2312 p
= (isdn_net_dev
*) p
->next
;
2316 if (lp
->flags
& ISDN_NET_CALLBACK
) {
2319 * Is the state MANUAL?
2320 * If so, no callback can be made,
2321 * so reject actively.
2323 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2324 printk(KERN_INFO
"incoming call for callback, interface %s `off' -> rejected\n",
2328 printk(KERN_DEBUG
"%s: call from %s -> %s, start callback\n",
2329 p
->dev
->name
, nr
, eaz
);
2331 /* Grab a free ISDN-Channel */
2332 spin_lock_irqsave(&dev
->lock
, flags
);
2334 isdn_get_free_channel(
2343 printk(KERN_WARNING
"isdn_net_find_icall: No channel for %s\n",
2345 spin_unlock_irqrestore(&dev
->lock
, flags
);
2348 /* Setup dialstate. */
2351 /* Connect interface with channel */
2352 isdn_net_bind_channel(lp
, chi
);
2353 #ifdef CONFIG_ISDN_PPP
2354 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2355 if (isdn_ppp_bind(lp
) < 0) {
2356 spin_unlock_irqrestore(&dev
->lock
, flags
);
2357 isdn_net_unbind_channel(lp
);
2361 spin_unlock_irqrestore(&dev
->lock
, flags
);
2362 /* Initiate dialing by returning 2 or 4 */
2363 return (lp
->flags
& ISDN_NET_CBHUP
) ? 2 : 4;
2365 printk(KERN_WARNING
"isdn_net: %s: No phone number\n",
2369 printk(KERN_DEBUG
"%s: call from %s -> %s accepted\n",
2370 p
->dev
->name
, nr
, eaz
);
2371 /* if this interface is dialing, it does it probably on a different
2372 device, so free this device */
2373 if ((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) {
2374 #ifdef CONFIG_ISDN_PPP
2375 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2378 isdn_net_lp_disconnected(lp
);
2379 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
2382 spin_lock_irqsave(&dev
->lock
, flags
);
2383 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2384 dev
->usage
[idx
] |= ISDN_USAGE_NET
;
2385 strcpy(dev
->num
[idx
], nr
);
2387 dev
->st_netdev
[idx
] = lp
->netdev
;
2388 lp
->isdn_device
= di
;
2389 lp
->isdn_channel
= ch
;
2391 lp
->flags
|= ISDN_NET_CONNECTED
;
2396 lp
->hupflags
|= ISDN_WAITCHARGE
;
2397 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
2398 #ifdef CONFIG_ISDN_PPP
2399 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
2400 if (isdn_ppp_bind(lp
) < 0) {
2401 isdn_net_unbind_channel(lp
);
2402 spin_unlock_irqrestore(&dev
->lock
, flags
);
2407 spin_unlock_irqrestore(&dev
->lock
, flags
);
2412 p
= (isdn_net_dev
*) p
->next
;
2414 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2415 if (!ematch
|| dev
->net_verbose
)
2416 printk(KERN_INFO
"isdn_net: call from %s -> %d %s ignored\n", nr
, di
, eaz
);
2417 return (wret
== 2)?5:0;
2421 * Search list of net-interfaces for an interface with given name.
2424 isdn_net_findif(char *name
)
2426 isdn_net_dev
*p
= dev
->netdev
;
2429 if (!strcmp(p
->dev
->name
, name
))
2431 p
= (isdn_net_dev
*) p
->next
;
2433 return (isdn_net_dev
*) NULL
;
2437 * Force a net-interface to dial out.
2438 * This is called from the userlevel-routine below or
2439 * from isdn_net_start_xmit().
2442 isdn_net_force_dial_lp(isdn_net_local
* lp
)
2444 if ((!(lp
->flags
& ISDN_NET_CONNECTED
)) && !lp
->dialstate
) {
2449 /* Grab a free ISDN-Channel */
2450 spin_lock_irqsave(&dev
->lock
, flags
);
2451 if ((chi
= isdn_get_free_channel(
2458 printk(KERN_WARNING
"isdn_net_force_dial: No channel for %s\n",
2459 lp
->netdev
->dev
->name
);
2460 spin_unlock_irqrestore(&dev
->lock
, flags
);
2464 /* Connect interface with channel */
2465 isdn_net_bind_channel(lp
, chi
);
2466 #ifdef CONFIG_ISDN_PPP
2467 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2468 if (isdn_ppp_bind(lp
) < 0) {
2469 isdn_net_unbind_channel(lp
);
2470 spin_unlock_irqrestore(&dev
->lock
, flags
);
2474 /* Initiate dialing */
2475 spin_unlock_irqrestore(&dev
->lock
, flags
);
2485 * This is called from certain upper protocol layers (multilink ppp
2486 * and x25iface encapsulation module) that want to initiate dialing
2490 isdn_net_dial_req(isdn_net_local
* lp
)
2492 /* is there a better error code? */
2493 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) return -EBUSY
;
2495 return isdn_net_force_dial_lp(lp
);
2499 * Force a net-interface to dial out.
2500 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2503 isdn_net_force_dial(char *name
)
2505 isdn_net_dev
*p
= isdn_net_findif(name
);
2509 return (isdn_net_force_dial_lp(p
->local
));
2512 /* The ISDN-specific entries in the device structure. */
2513 static const struct net_device_ops isdn_netdev_ops
= {
2514 .ndo_init
= isdn_net_init
,
2515 .ndo_open
= isdn_net_open
,
2516 .ndo_stop
= isdn_net_close
,
2517 .ndo_do_ioctl
= isdn_net_ioctl
,
2519 .ndo_start_xmit
= isdn_net_start_xmit
,
2520 .ndo_get_stats
= isdn_net_get_stats
,
2521 .ndo_tx_timeout
= isdn_net_tx_timeout
,
2525 * Helper for alloc_netdev()
2527 static void _isdn_setup(struct net_device
*dev
)
2529 isdn_net_local
*lp
= netdev_priv(dev
);
2533 /* Setup the generic properties */
2534 dev
->flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2535 dev
->header_ops
= NULL
;
2536 dev
->netdev_ops
= &isdn_netdev_ops
;
2538 /* for clients with MPPP maybe higher values better */
2539 dev
->tx_queue_len
= 30;
2541 lp
->p_encap
= ISDN_NET_ENCAP_RAWIP
;
2542 lp
->magic
= ISDN_NET_MAGIC
;
2545 lp
->isdn_device
= -1;
2546 lp
->isdn_channel
= -1;
2547 lp
->pre_device
= -1;
2548 lp
->pre_channel
= -1;
2552 skb_queue_head_init(&lp
->super_tx_queue
);
2553 lp
->l2_proto
= ISDN_PROTO_L2_X75I
;
2554 lp
->l3_proto
= ISDN_PROTO_L3_TRANS
;
2555 lp
->triggercps
= 6000;
2556 lp
->slavedelay
= 10 * HZ
;
2557 lp
->hupflags
= ISDN_INHUP
; /* Do hangup even on incoming calls */
2558 lp
->onhtime
= 10; /* Default hangup-time for saving costs */
2560 /* Hangup before Callback, manual dial */
2561 lp
->flags
= ISDN_NET_CBHUP
| ISDN_NET_DM_MANUAL
;
2562 lp
->cbdelay
= 25; /* Wait 5 secs before Callback */
2563 lp
->dialtimeout
= -1; /* Infinite Dial-Timeout */
2564 lp
->dialwait
= 5 * HZ
; /* Wait 5 sec. after failed dial */
2565 lp
->dialstarted
= 0; /* Jiffies of last dial-start */
2566 lp
->dialwait_timer
= 0; /* Jiffies of earliest next dial-start */
2570 * Allocate a new network-interface and initialize its data structures.
2573 isdn_net_new(char *name
, struct net_device
*master
)
2575 isdn_net_dev
*netdev
;
2577 /* Avoid creating an existing interface */
2578 if (isdn_net_findif(name
)) {
2579 printk(KERN_WARNING
"isdn_net: interface %s already exists\n", name
);
2584 if (!(netdev
= kzalloc(sizeof(isdn_net_dev
), GFP_KERNEL
))) {
2585 printk(KERN_WARNING
"isdn_net: Could not allocate net-device\n");
2588 netdev
->dev
= alloc_netdev(sizeof(isdn_net_local
), name
, _isdn_setup
);
2590 printk(KERN_WARNING
"isdn_net: Could not allocate network device\n");
2594 netdev
->local
= netdev_priv(netdev
->dev
);
2597 /* Device shall be a slave */
2598 struct net_device
*p
= MASTER_TO_SLAVE(master
);
2599 struct net_device
*q
= master
;
2601 netdev
->local
->master
= master
;
2602 /* Put device at end of slave-chain */
2605 p
= MASTER_TO_SLAVE(p
);
2607 MASTER_TO_SLAVE(q
) = netdev
->dev
;
2609 /* Device shall be a master */
2611 * Watchdog timer (currently) for master only.
2613 netdev
->dev
->watchdog_timeo
= ISDN_NET_TX_TIMEOUT
;
2614 if (register_netdev(netdev
->dev
) != 0) {
2615 printk(KERN_WARNING
"isdn_net: Could not register net-device\n");
2616 free_netdev(netdev
->dev
);
2621 netdev
->queue
= netdev
->local
;
2622 spin_lock_init(&netdev
->queue_lock
);
2624 netdev
->local
->netdev
= netdev
;
2626 INIT_WORK(&netdev
->local
->tqueue
, isdn_net_softint
);
2627 spin_lock_init(&netdev
->local
->xmit_lock
);
2629 /* Put into to netdev-chain */
2630 netdev
->next
= (void *) dev
->netdev
;
2631 dev
->netdev
= netdev
;
2632 return netdev
->dev
->name
;
2636 isdn_net_newslave(char *parm
)
2638 char *p
= strchr(parm
, ',');
2643 /* Slave-Name MUST not be empty */
2646 strcpy(newname
, p
+ 1);
2648 /* Master must already exist */
2649 if (!(n
= isdn_net_findif(parm
)))
2651 /* Master must be a real interface, not a slave */
2652 if (n
->local
->master
)
2654 /* Master must not be started yet */
2655 if (isdn_net_device_started(n
))
2657 return (isdn_net_new(newname
, n
->dev
));
2663 * Set interface-parameters.
2664 * Always set all parameters, so the user-level application is responsible
2665 * for not overwriting existing setups. It has to get the current
2666 * setup first, if only selected parameters are to be changed.
2669 isdn_net_setcfg(isdn_net_ioctl_cfg
* cfg
)
2671 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2679 isdn_net_local
*lp
= p
->local
;
2681 /* See if any registered driver supports the features we want */
2682 features
= ((1 << cfg
->l2_proto
) << ISDN_FEATURE_L2_SHIFT
) |
2683 ((1 << cfg
->l3_proto
) << ISDN_FEATURE_L3_SHIFT
);
2684 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2686 if ((dev
->drv
[i
]->interface
->features
& features
) == features
)
2688 if (i
== ISDN_MAX_DRIVERS
) {
2689 printk(KERN_WARNING
"isdn_net: No driver with selected features\n");
2692 if (lp
->p_encap
!= cfg
->p_encap
){
2693 #ifdef CONFIG_ISDN_X25
2694 struct concap_proto
* cprot
= p
-> cprot
;
2696 if (isdn_net_device_started(p
)) {
2697 printk(KERN_WARNING
"%s: cannot change encap when if is up\n",
2701 #ifdef CONFIG_ISDN_X25
2702 if( cprot
&& cprot
-> pops
)
2703 cprot
-> pops
-> proto_del ( cprot
);
2706 /* ... , prepare for configuration of new one ... */
2707 switch ( cfg
-> p_encap
){
2708 case ISDN_NET_ENCAP_X25IFACE
:
2709 lp
-> dops
= &isdn_concap_reliable_dl_dops
;
2711 /* ... and allocate new one ... */
2712 p
-> cprot
= isdn_concap_new( cfg
-> p_encap
);
2713 /* p -> cprot == NULL now if p_encap is not supported
2714 by means of the concap_proto mechanism */
2715 /* the protocol is not configured yet; this will
2716 happen later when isdn_net_reset() is called */
2719 switch ( cfg
->p_encap
) {
2720 case ISDN_NET_ENCAP_SYNCPPP
:
2721 #ifndef CONFIG_ISDN_PPP
2722 printk(KERN_WARNING
"%s: SyncPPP support not configured\n",
2726 p
->dev
->type
= ARPHRD_PPP
; /* change ARP type */
2727 p
->dev
->addr_len
= 0;
2730 case ISDN_NET_ENCAP_X25IFACE
:
2731 #ifndef CONFIG_ISDN_X25
2732 printk(KERN_WARNING
"%s: isdn-x25 support not configured\n",
2736 p
->dev
->type
= ARPHRD_X25
; /* change ARP type */
2737 p
->dev
->addr_len
= 0;
2740 case ISDN_NET_ENCAP_CISCOHDLCK
:
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
->dev
->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 strlcpy(lp
->msn
, cfg
->eaz
, sizeof(lp
->msn
));
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
->header_ops
= NULL
;
2868 p
->dev
->flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2870 p
->dev
->header_ops
= &isdn_header_ops
;
2871 if (cfg
->p_encap
== ISDN_NET_ENCAP_ETHER
)
2872 p
->dev
->flags
= IFF_BROADCAST
| IFF_MULTICAST
;
2874 p
->dev
->flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2877 lp
->p_encap
= cfg
->p_encap
;
2884 * Perform get-interface-parameters.ioctl
2887 isdn_net_getcfg(isdn_net_ioctl_cfg
* cfg
)
2889 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2892 isdn_net_local
*lp
= p
->local
;
2894 strcpy(cfg
->eaz
, lp
->msn
);
2895 cfg
->exclusive
= lp
->exclusive
;
2896 if (lp
->pre_device
>= 0) {
2897 sprintf(cfg
->drvid
, "%s,%d", dev
->drvid
[lp
->pre_device
],
2900 cfg
->drvid
[0] = '\0';
2901 cfg
->onhtime
= lp
->onhtime
;
2902 cfg
->charge
= lp
->charge
;
2903 cfg
->l2_proto
= lp
->l2_proto
;
2904 cfg
->l3_proto
= lp
->l3_proto
;
2905 cfg
->p_encap
= lp
->p_encap
;
2906 cfg
->secure
= (lp
->flags
& ISDN_NET_SECURE
) ? 1 : 0;
2908 if (lp
->flags
& ISDN_NET_CALLBACK
)
2910 if (lp
->flags
& ISDN_NET_CBOUT
)
2912 cfg
->cbhup
= (lp
->flags
& ISDN_NET_CBHUP
) ? 1 : 0;
2913 cfg
->dialmode
= lp
->flags
& ISDN_NET_DIALMODE_MASK
;
2914 cfg
->chargehup
= (lp
->hupflags
& 4) ? 1 : 0;
2915 cfg
->ihup
= (lp
->hupflags
& 8) ? 1 : 0;
2916 cfg
->cbdelay
= lp
->cbdelay
;
2917 cfg
->dialmax
= lp
->dialmax
;
2918 cfg
->triggercps
= lp
->triggercps
;
2919 cfg
->slavedelay
= lp
->slavedelay
/ HZ
;
2920 cfg
->chargeint
= (lp
->hupflags
& ISDN_CHARGEHUP
) ?
2921 (lp
->chargeint
/ HZ
) : 0;
2922 cfg
->pppbind
= lp
->pppbind
;
2923 cfg
->dialtimeout
= lp
->dialtimeout
>= 0 ? lp
->dialtimeout
/ HZ
: -1;
2924 cfg
->dialwait
= lp
->dialwait
/ HZ
;
2926 if (strlen(lp
->slave
->name
) > 8)
2927 strcpy(cfg
->slave
, "too-long");
2929 strcpy(cfg
->slave
, lp
->slave
->name
);
2931 cfg
->slave
[0] = '\0';
2933 if (strlen(lp
->master
->name
) > 8)
2934 strcpy(cfg
->master
, "too-long");
2935 strcpy(cfg
->master
, lp
->master
->name
);
2937 cfg
->master
[0] = '\0';
2944 * Add a phone-number to an interface.
2947 isdn_net_addphone(isdn_net_ioctl_phone
* phone
)
2949 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2953 if (!(n
= kmalloc(sizeof(isdn_net_phone
), GFP_KERNEL
)))
2955 strlcpy(n
->num
, phone
->phone
, sizeof(n
->num
));
2956 n
->next
= p
->local
->phone
[phone
->outgoing
& 1];
2957 p
->local
->phone
[phone
->outgoing
& 1] = n
;
2964 * Copy a string of all phone-numbers of an interface to user space.
2965 * This might sleep and must be called with the isdn semaphore down.
2968 isdn_net_getphones(isdn_net_ioctl_phone
* phone
, char __user
*phones
)
2970 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2971 int inout
= phone
->outgoing
& 1;
2979 for (n
= p
->local
->phone
[inout
]; n
; n
= n
->next
) {
2981 put_user(' ', phones
++);
2984 if (copy_to_user(phones
, n
->num
, strlen(n
->num
) + 1)) {
2987 phones
+= strlen(n
->num
);
2988 count
+= strlen(n
->num
);
2991 put_user(0, phones
);
2997 * Copy a string containing the peer's phone number of a connected interface
3001 isdn_net_getpeer(isdn_net_ioctl_phone
*phone
, isdn_net_ioctl_phone __user
*peer
)
3003 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
3009 * Theoretical race: while this executes, the remote number might
3010 * become invalid (hang up) or change (new connection), resulting
3011 * in (partially) wrong number copied to user. This race
3012 * currently ignored.
3014 ch
= p
->local
->isdn_channel
;
3015 dv
= p
->local
->isdn_device
;
3016 if(ch
< 0 && dv
< 0)
3018 idx
= isdn_dc2minor(dv
, ch
);
3021 /* for pre-bound channels, we need this extra check */
3022 if (strncmp(dev
->num
[idx
], "???", 3) == 0)
3024 strncpy(phone
->phone
, dev
->num
[idx
], ISDN_MSNLEN
);
3025 phone
->outgoing
= USG_OUTGOING(dev
->usage
[idx
]);
3026 if (copy_to_user(peer
, phone
, sizeof(*peer
)))
3031 * Delete a phone-number from an interface.
3034 isdn_net_delphone(isdn_net_ioctl_phone
* phone
)
3036 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
3037 int inout
= phone
->outgoing
& 1;
3042 n
= p
->local
->phone
[inout
];
3045 if (!strcmp(n
->num
, phone
->phone
)) {
3046 if (p
->local
->dial
== n
)
3047 p
->local
->dial
= n
->next
;
3051 p
->local
->phone
[inout
] = n
->next
;
3056 n
= (isdn_net_phone
*) n
->next
;
3064 * Delete all phone-numbers of an interface.
3067 isdn_net_rmallphone(isdn_net_dev
* p
)
3073 for (i
= 0; i
< 2; i
++) {
3074 n
= p
->local
->phone
[i
];
3080 p
->local
->phone
[i
] = NULL
;
3082 p
->local
->dial
= NULL
;
3087 * Force a hangup of a network-interface.
3090 isdn_net_force_hangup(char *name
)
3092 isdn_net_dev
*p
= isdn_net_findif(name
);
3093 struct net_device
*q
;
3096 if (p
->local
->isdn_device
< 0)
3098 q
= p
->local
->slave
;
3099 /* If this interface has slaves, do a hangup for them also. */
3102 q
= MASTER_TO_SLAVE(q
);
3104 isdn_net_hangup(p
->dev
);
3111 * Helper-function for isdn_net_rm: Do the real work.
3114 isdn_net_realrm(isdn_net_dev
* p
, isdn_net_dev
* q
)
3118 if (isdn_net_device_started(p
)) {
3121 #ifdef CONFIG_ISDN_X25
3122 if( p
-> cprot
&& p
-> cprot
-> pops
)
3123 p
-> cprot
-> pops
-> proto_del ( p
-> cprot
);
3125 /* Free all phone-entries */
3126 isdn_net_rmallphone(p
);
3127 /* If interface is bound exclusive, free channel-usage */
3128 if (p
->local
->exclusive
!= -1)
3129 isdn_unexclusive_channel(p
->local
->pre_device
, p
->local
->pre_channel
);
3130 if (p
->local
->master
) {
3131 /* It's a slave-device, so update master's slave-pointer if necessary */
3132 if (((isdn_net_local
*) ISDN_MASTER_PRIV(p
->local
))->slave
==
3134 ((isdn_net_local
*)ISDN_MASTER_PRIV(p
->local
))->slave
=
3137 /* Unregister only if it's a master-device */
3138 unregister_netdev(p
->dev
);
3140 /* Unlink device from chain */
3141 spin_lock_irqsave(&dev
->lock
, flags
);
3145 dev
->netdev
= p
->next
;
3146 if (p
->local
->slave
) {
3147 /* If this interface has a slave, remove it also */
3148 char *slavename
= p
->local
->slave
->name
;
3149 isdn_net_dev
*n
= dev
->netdev
;
3152 if (!strcmp(n
->dev
->name
, slavename
)) {
3153 spin_unlock_irqrestore(&dev
->lock
, flags
);
3154 isdn_net_realrm(n
, q
);
3155 spin_lock_irqsave(&dev
->lock
, flags
);
3159 n
= (isdn_net_dev
*)n
->next
;
3162 spin_unlock_irqrestore(&dev
->lock
, flags
);
3163 /* If no more net-devices remain, disable auto-hangup timer */
3164 if (dev
->netdev
== NULL
)
3165 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3166 free_netdev(p
->dev
);
3173 * Remove a single network-interface.
3176 isdn_net_rm(char *name
)
3182 /* Search name in netdev-chain */
3183 spin_lock_irqsave(&dev
->lock
, flags
);
3187 if (!strcmp(p
->dev
->name
, name
)) {
3188 spin_unlock_irqrestore(&dev
->lock
, flags
);
3189 return (isdn_net_realrm(p
, q
));
3192 p
= (isdn_net_dev
*) p
->next
;
3194 spin_unlock_irqrestore(&dev
->lock
, flags
);
3195 /* If no more net-devices remain, disable auto-hangup timer */
3196 if (dev
->netdev
== NULL
)
3197 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3202 * Remove all network-interfaces
3205 isdn_net_rmall(void)
3210 /* Walk through netdev-chain */
3211 spin_lock_irqsave(&dev
->lock
, flags
);
3212 while (dev
->netdev
) {
3213 if (!dev
->netdev
->local
->master
) {
3214 /* Remove master-devices only, slaves get removed with their master */
3215 spin_unlock_irqrestore(&dev
->lock
, flags
);
3216 if ((ret
= isdn_net_realrm(dev
->netdev
, NULL
))) {
3219 spin_lock_irqsave(&dev
->lock
, flags
);
3223 spin_unlock_irqrestore(&dev
->lock
, flags
);