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>
26 #include <linux/slab.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 it 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_MASTER_PRIV(lp
)->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 netdev_tx_t
isdn_net_start_xmit(struct sk_buff
*,
181 struct net_device
*);
183 static void isdn_net_ciscohdlck_connected(isdn_net_local
*lp
);
184 static void isdn_net_ciscohdlck_disconnected(isdn_net_local
*lp
);
186 char *isdn_net_revision
= "$Revision: 1.1.2.2 $";
189 * Code for raw-networking over ISDN
193 isdn_net_unreachable(struct net_device
*dev
, struct sk_buff
*skb
, char *reason
)
197 u_short proto
= ntohs(skb
->protocol
);
199 printk(KERN_DEBUG
"isdn_net: %s: %s, signalling dst_link_failure %s\n",
201 (reason
!= NULL
) ? reason
: "unknown",
202 (proto
!= ETH_P_IP
) ? "Protocol != ETH_P_IP" : "");
204 dst_link_failure(skb
);
206 else { /* dial not triggered by rawIP packet */
207 printk(KERN_DEBUG
"isdn_net: %s: %s\n",
209 (reason
!= NULL
) ? reason
: "reason unknown");
214 isdn_net_reset(struct net_device
*dev
)
216 #ifdef CONFIG_ISDN_X25
217 struct concap_device_ops
*dops
=
218 ((isdn_net_local
*)netdev_priv(dev
))->dops
;
219 struct concap_proto
*cprot
=
220 ((isdn_net_local
*)netdev_priv(dev
))->netdev
->cprot
;
222 #ifdef CONFIG_ISDN_X25
223 if (cprot
&& cprot
->pops
&& dops
)
224 cprot
->pops
->restart(cprot
, dev
, dops
);
228 /* Open/initialize the board. */
230 isdn_net_open(struct net_device
*dev
)
233 struct net_device
*p
;
234 struct in_device
*in_dev
;
236 /* moved here from isdn_net_reset, because only the master has an
237 interface associated which is supposed to be started. BTW:
238 we need to call netif_start_queue, not netif_wake_queue here */
239 netif_start_queue(dev
);
242 /* Fill in the MAC-level header (not needed, but for compatibility... */
243 for (i
= 0; i
< ETH_ALEN
- sizeof(u32
); i
++)
244 dev
->dev_addr
[i
] = 0xfc;
245 if ((in_dev
= dev
->ip_ptr
) != NULL
) {
247 * Any address will do - we take the first
249 struct in_ifaddr
*ifa
= in_dev
->ifa_list
;
251 memcpy(dev
->dev_addr
+ 2, &ifa
->ifa_local
, 4);
254 /* If this interface has slaves, start them also */
255 p
= MASTER_TO_SLAVE(dev
);
259 p
= MASTER_TO_SLAVE(p
);
267 * Assign an ISDN-channel to a net-interface
270 isdn_net_bind_channel(isdn_net_local
*lp
, int idx
)
272 lp
->flags
|= ISDN_NET_CONNECTED
;
273 lp
->isdn_device
= dev
->drvmap
[idx
];
274 lp
->isdn_channel
= dev
->chanmap
[idx
];
275 dev
->rx_netdev
[idx
] = lp
->netdev
;
276 dev
->st_netdev
[idx
] = lp
->netdev
;
280 * unbind a net-interface (resets interface after an error)
283 isdn_net_unbind_channel(isdn_net_local
*lp
)
285 skb_queue_purge(&lp
->super_tx_queue
);
287 if (!lp
->master
) { /* reset only master device */
288 /* Moral equivalent of dev_purge_queues():
289 BEWARE! This chunk of code cannot be called from hardware
290 interrupt handler. I hope it is true. --ANK
292 qdisc_reset_all_tx(lp
->netdev
->dev
);
295 dev
->rx_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
296 dev
->st_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
297 if (lp
->isdn_device
!= -1 && lp
->isdn_channel
!= -1)
298 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
300 lp
->flags
&= ~ISDN_NET_CONNECTED
;
301 lp
->isdn_device
= -1;
302 lp
->isdn_channel
= -1;
306 * Perform auto-hangup and cps-calculation for net-interfaces.
309 * Increment idle-counter (this counter is reset on any incoming or
310 * outgoing packet), if counter exceeds configured limit either do a
311 * hangup immediately or - if configured - wait until just before the next
314 * cps-calculation (needed for dynamic channel-bundling):
315 * Since this function is called every second, simply reset the
316 * byte-counter of the interface after copying it to the cps-variable.
318 static unsigned long last_jiffies
= -HZ
;
321 isdn_net_autohup(void)
323 isdn_net_dev
*p
= dev
->netdev
;
328 isdn_net_local
*l
= p
->local
;
329 if (jiffies
== last_jiffies
)
330 l
->cps
= l
->transcount
;
332 l
->cps
= (l
->transcount
* HZ
) / (jiffies
- last_jiffies
);
334 if (dev
->net_verbose
> 3)
335 printk(KERN_DEBUG
"%s: %d bogocps\n", p
->dev
->name
, l
->cps
);
336 if ((l
->flags
& ISDN_NET_CONNECTED
) && (!l
->dialstate
)) {
340 * if there is some dialmode where timeout-hangup
341 * should _not_ be done, check for that here
344 (l
->huptimer
> l
->onhtime
))
346 if (l
->hupflags
& ISDN_MANCHARGE
&&
347 l
->hupflags
& ISDN_CHARGEHUP
) {
348 while (time_after(jiffies
, l
->chargetime
+ l
->chargeint
))
349 l
->chargetime
+= l
->chargeint
;
350 if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
- 2 * HZ
))
351 if (l
->outgoing
|| l
->hupflags
& ISDN_INHUP
)
352 isdn_net_hangup(p
->dev
);
353 } else if (l
->outgoing
) {
354 if (l
->hupflags
& ISDN_CHARGEHUP
) {
355 if (l
->hupflags
& ISDN_WAITCHARGE
) {
356 printk(KERN_DEBUG
"isdn_net: Hupflags of %s are %X\n",
357 p
->dev
->name
, l
->hupflags
);
358 isdn_net_hangup(p
->dev
);
359 } else if (time_after(jiffies
, l
->chargetime
+ l
->chargeint
)) {
361 "isdn_net: %s: chtime = %lu, chint = %d\n",
362 p
->dev
->name
, l
->chargetime
, l
->chargeint
);
363 isdn_net_hangup(p
->dev
);
366 isdn_net_hangup(p
->dev
);
367 } else if (l
->hupflags
& ISDN_INHUP
)
368 isdn_net_hangup(p
->dev
);
371 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*l
) == ISDN_NET_DM_OFF
)) {
372 isdn_net_hangup(p
->dev
);
376 p
= (isdn_net_dev
*) p
->next
;
378 last_jiffies
= jiffies
;
379 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, anymore
);
382 static void isdn_net_lp_disconnected(isdn_net_local
*lp
)
384 isdn_net_rm_from_bundle(lp
);
388 * Handle status-messages from ISDN-interfacecard.
389 * This function is called from within the main-status-dispatcher
390 * isdn_status_callback, which itself is called from the low-level driver.
391 * Return: 1 = Event handled, 0 = not for us or unknown Event.
394 isdn_net_stat_callback(int idx
, isdn_ctrl
*c
)
396 isdn_net_dev
*p
= dev
->st_netdev
[idx
];
397 int cmd
= c
->command
;
400 isdn_net_local
*lp
= p
->local
;
401 #ifdef CONFIG_ISDN_X25
402 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
403 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
406 case ISDN_STAT_BSENT
:
407 /* A packet has successfully been sent out */
408 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
410 isdn_net_dec_frame_cnt(lp
);
411 lp
->stats
.tx_packets
++;
412 lp
->stats
.tx_bytes
+= c
->parm
.length
;
415 case ISDN_STAT_DCONN
:
416 /* D-Channel is up */
417 switch (lp
->dialstate
) {
429 /* Either D-Channel-hangup or error during dialout */
430 #ifdef CONFIG_ISDN_X25
431 /* If we are not connencted then dialing had
432 failed. If there are generic encap protocol
433 receiver routines signal the closure of
436 if (!(lp
->flags
& ISDN_NET_CONNECTED
)
437 && pops
&& pops
->disconn_ind
)
438 pops
->disconn_ind(cprot
);
439 #endif /* CONFIG_ISDN_X25 */
440 if ((!lp
->dialstate
) && (lp
->flags
& ISDN_NET_CONNECTED
)) {
441 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
442 isdn_net_ciscohdlck_disconnected(lp
);
443 #ifdef CONFIG_ISDN_PPP
444 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
447 isdn_net_lp_disconnected(lp
);
448 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
449 printk(KERN_INFO
"%s: remote hangup\n", p
->dev
->name
);
450 printk(KERN_INFO
"%s: Chargesum is %d\n", p
->dev
->name
,
452 isdn_net_unbind_channel(lp
);
456 #ifdef CONFIG_ISDN_X25
458 /* B-Channel-hangup */
459 /* try if there are generic encap protocol
460 receiver routines and signal the closure of
462 if (pops
&& pops
->disconn_ind
) {
463 pops
->disconn_ind(cprot
);
467 #endif /* CONFIG_ISDN_X25 */
468 case ISDN_STAT_BCONN
:
469 /* B-Channel is up */
470 isdn_net_zero_frame_cnt(lp
);
471 switch (lp
->dialstate
) {
479 if (lp
->dialstate
<= 6) {
480 dev
->usage
[idx
] |= ISDN_USAGE_OUTGOING
;
483 dev
->rx_netdev
[idx
] = p
;
485 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 1);
486 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
487 isdn_net_ciscohdlck_connected(lp
);
488 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
) {
489 if (lp
->master
) { /* is lp a slave? */
490 isdn_net_dev
*nd
= ISDN_MASTER_PRIV(lp
)->netdev
;
491 isdn_net_add_to_bundle(nd
, lp
);
494 printk(KERN_INFO
"isdn_net: %s connected\n", p
->dev
->name
);
495 /* If first Chargeinfo comes before B-Channel connect,
496 * we correct the timestamp here.
498 lp
->chargetime
= jiffies
;
500 /* reset dial-timeout */
502 lp
->dialwait_timer
= 0;
504 #ifdef CONFIG_ISDN_PPP
505 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
506 isdn_ppp_wakeup_daemon(lp
);
508 #ifdef CONFIG_ISDN_X25
509 /* try if there are generic concap receiver routines */
511 if (pops
->connect_ind
)
512 pops
->connect_ind(cprot
);
513 #endif /* CONFIG_ISDN_X25 */
514 /* ppp needs to do negotiations first */
515 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
)
516 isdn_net_device_wake_queue(lp
);
520 case ISDN_STAT_NODCH
:
521 /* No D-Channel avail. */
522 if (lp
->dialstate
== 4) {
528 /* Charge-info from TelCo. Calculate interval between
529 * charge-infos and set timestamp for last info for
530 * usage by isdn_net_autohup()
533 if (lp
->hupflags
& ISDN_HAVECHARGE
) {
534 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
535 lp
->chargeint
= jiffies
- lp
->chargetime
- (2 * HZ
);
537 if (lp
->hupflags
& ISDN_WAITCHARGE
)
538 lp
->hupflags
|= ISDN_HAVECHARGE
;
539 lp
->chargetime
= jiffies
;
540 printk(KERN_DEBUG
"isdn_net: Got CINF chargetime of %s now %lu\n",
541 p
->dev
->name
, lp
->chargetime
);
549 * Perform dialout for net-interfaces and timeout-handling for
550 * D-Channel-up and B-Channel-up Messages.
551 * This function is initially called from within isdn_net_start_xmit() or
552 * or isdn_net_find_icall() after initializing the dialstate for an
553 * interface. If further calls are needed, the function schedules itself
554 * for a timer-callback via isdn_timer_function().
555 * The dialstate is also affected by incoming status-messages from
556 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
561 isdn_net_dev
*p
= dev
->netdev
;
565 u_char
*phone_number
;
568 isdn_net_local
*lp
= p
->local
;
570 #ifdef ISDN_DEBUG_NET_DIAL
572 printk(KERN_DEBUG
"%s: dialstate=%d\n", p
->dev
->name
, lp
->dialstate
);
574 switch (lp
->dialstate
) {
576 /* Nothing to do for this interface */
579 /* Initiate dialout. Set phone-number-pointer to first number
582 lp
->dial
= lp
->phone
[1];
584 printk(KERN_WARNING
"%s: phone number deleted?\n",
586 isdn_net_hangup(p
->dev
);
591 if (lp
->dialtimeout
> 0)
592 if (lp
->dialstarted
== 0 || time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
)) {
593 lp
->dialstarted
= jiffies
;
594 lp
->dialwait_timer
= 0;
600 /* Prepare dialing. Clear EAZ, then set EAZ. */
601 cmd
.driver
= lp
->isdn_device
;
602 cmd
.arg
= lp
->isdn_channel
;
603 cmd
.command
= ISDN_CMD_CLREAZ
;
605 sprintf(cmd
.parm
.num
, "%s", isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
606 cmd
.command
= ISDN_CMD_SETEAZ
;
613 /* Setup interface, dial current phone-number, switch to next number.
614 * If list of phone-numbers is exhausted, increment
617 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
)) {
619 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
620 s
= "dial suppressed: isdn system stopped";
622 s
= "dial suppressed: dialmode `off'";
623 isdn_net_unreachable(p
->dev
, NULL
, s
);
624 isdn_net_hangup(p
->dev
);
627 cmd
.driver
= lp
->isdn_device
;
628 cmd
.command
= ISDN_CMD_SETL2
;
629 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
631 cmd
.driver
= lp
->isdn_device
;
632 cmd
.command
= ISDN_CMD_SETL3
;
633 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
635 cmd
.driver
= lp
->isdn_device
;
636 cmd
.arg
= lp
->isdn_channel
;
638 printk(KERN_WARNING
"%s: phone number deleted?\n",
640 isdn_net_hangup(p
->dev
);
643 if (!strncmp(lp
->dial
->num
, "LEASED", strlen("LEASED"))) {
645 printk(KERN_INFO
"%s: Open leased line ...\n", p
->dev
->name
);
647 if (lp
->dialtimeout
> 0)
648 if (time_after(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
)) {
649 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
651 isdn_net_unreachable(p
->dev
, NULL
, "dial: timed out");
652 isdn_net_hangup(p
->dev
);
656 cmd
.driver
= lp
->isdn_device
;
657 cmd
.command
= ISDN_CMD_DIAL
;
658 cmd
.parm
.setup
.si2
= 0;
661 phone_number
= lp
->dial
->num
;
662 if ((*phone_number
== 'v') ||
663 (*phone_number
== 'V')) { /* DOV call */
664 cmd
.parm
.setup
.si1
= 1;
665 } else { /* DATA call */
666 cmd
.parm
.setup
.si1
= 7;
669 strcpy(cmd
.parm
.setup
.phone
, phone_number
);
671 * Switch to next number or back to start if at end of list.
673 if (!(lp
->dial
= (isdn_net_phone
*) lp
->dial
->next
)) {
674 lp
->dial
= lp
->phone
[1];
677 if (lp
->dialretry
> lp
->dialmax
) {
678 if (lp
->dialtimeout
== 0) {
679 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
681 isdn_net_unreachable(p
->dev
, NULL
, "dial: tried all numbers dialmax times");
683 isdn_net_hangup(p
->dev
);
687 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
688 isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
689 i
= isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
);
691 strcpy(dev
->num
[i
], cmd
.parm
.setup
.phone
);
692 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
695 printk(KERN_INFO
"%s: dialing %d %s... %s\n", p
->dev
->name
,
696 lp
->dialretry
, cmd
.parm
.setup
.phone
,
697 (cmd
.parm
.setup
.si1
== 1) ? "DOV" : "");
699 #ifdef ISDN_DEBUG_NET_DIAL
700 printk(KERN_DEBUG
"dial: d=%d c=%d\n", lp
->isdn_device
,
708 lp
->hupflags
|= ISDN_HAVECHARGE
;
709 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
711 lp
->hupflags
|= ISDN_WAITCHARGE
;
712 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
717 (lp
->flags
& ISDN_NET_CBOUT
)) ? 12 : 4;
720 /* Wait for D-Channel-connect.
721 * If timeout, switch back to state 3.
722 * Dialmax-handling moved to state 3.
724 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
729 /* Got D-Channel-Connect, send B-Channel-request */
730 cmd
.driver
= lp
->isdn_device
;
731 cmd
.arg
= lp
->isdn_channel
;
732 cmd
.command
= ISDN_CMD_ACCEPTB
;
739 /* Wait for B- or D-Channel-connect. If timeout,
740 * switch back to state 3.
742 #ifdef ISDN_DEBUG_NET_DIAL
743 printk(KERN_DEBUG
"dialtimer2: %d\n", lp
->dtimer
);
745 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
750 /* Got incoming Call, setup L2 and L3 protocols,
751 * then wait for D-Channel-connect
753 #ifdef ISDN_DEBUG_NET_DIAL
754 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
756 cmd
.driver
= lp
->isdn_device
;
757 cmd
.command
= ISDN_CMD_SETL2
;
758 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
760 cmd
.driver
= lp
->isdn_device
;
761 cmd
.command
= ISDN_CMD_SETL3
;
762 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
764 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT15
)
765 isdn_net_hangup(p
->dev
);
772 /* Got incoming D-Channel-Connect, send B-Channel-request */
773 cmd
.driver
= lp
->isdn_device
;
774 cmd
.arg
= lp
->isdn_channel
;
775 cmd
.command
= ISDN_CMD_ACCEPTB
;
783 /* Wait for B- or D-channel-connect */
784 #ifdef ISDN_DEBUG_NET_DIAL
785 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
787 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
788 isdn_net_hangup(p
->dev
);
794 if (lp
->dtimer
++ > lp
->cbdelay
)
799 /* Remote does callback. Hangup after cbdelay, then wait for incoming
802 if (lp
->dtimer
++ > lp
->cbdelay
)
804 printk(KERN_INFO
"%s: hangup waiting for callback ...\n", p
->dev
->name
);
807 cmd
.driver
= lp
->isdn_device
;
808 cmd
.command
= ISDN_CMD_HANGUP
;
809 cmd
.arg
= lp
->isdn_channel
;
811 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
816 printk(KERN_WARNING
"isdn_net: Illegal dialstate %d for device %s\n",
817 lp
->dialstate
, p
->dev
->name
);
819 p
= (isdn_net_dev
*) p
->next
;
821 isdn_timer_ctrl(ISDN_TIMER_NETDIAL
, anymore
);
825 * Perform hangup for a net-interface.
828 isdn_net_hangup(struct net_device
*d
)
830 isdn_net_local
*lp
= netdev_priv(d
);
832 #ifdef CONFIG_ISDN_X25
833 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
834 struct concap_proto_ops
*pops
= cprot
? cprot
->pops
: NULL
;
837 if (lp
->flags
& ISDN_NET_CONNECTED
) {
838 if (lp
->slave
!= NULL
) {
839 isdn_net_local
*slp
= ISDN_SLAVE_PRIV(lp
);
840 if (slp
->flags
& ISDN_NET_CONNECTED
) {
842 "isdn_net: hang up slave %s before %s\n",
843 lp
->slave
->name
, d
->name
);
844 isdn_net_hangup(lp
->slave
);
847 printk(KERN_INFO
"isdn_net: local hangup %s\n", d
->name
);
848 #ifdef CONFIG_ISDN_PPP
849 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
852 isdn_net_lp_disconnected(lp
);
853 #ifdef CONFIG_ISDN_X25
854 /* try if there are generic encap protocol
855 receiver routines and signal the closure of
857 if (pops
&& pops
->disconn_ind
)
858 pops
->disconn_ind(cprot
);
859 #endif /* CONFIG_ISDN_X25 */
861 cmd
.driver
= lp
->isdn_device
;
862 cmd
.command
= ISDN_CMD_HANGUP
;
863 cmd
.arg
= lp
->isdn_channel
;
865 printk(KERN_INFO
"%s: Chargesum is %d\n", d
->name
, lp
->charge
);
866 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
868 isdn_net_unbind_channel(lp
);
877 isdn_net_log_skb(struct sk_buff
*skb
, isdn_net_local
*lp
)
879 /* hopefully, this was set correctly */
880 const u_char
*p
= skb_network_header(skb
);
881 unsigned short proto
= ntohs(skb
->protocol
);
887 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
888 if (p
< skb
->data
|| skb_network_header(skb
) >= skb_tail_pointer(skb
)) {
889 /* fall back to old isdn_net_log_packet method() */
890 char *buf
= skb
->data
;
892 printk(KERN_DEBUG
"isdn_net: protocol %04x is buggy, dev %s\n", skb
->protocol
, lp
->netdev
->dev
->name
);
895 switch (lp
->p_encap
) {
896 case ISDN_NET_ENCAP_IPTYP
:
897 proto
= ntohs(*(__be16
*)&buf
[0]);
900 case ISDN_NET_ENCAP_ETHER
:
901 proto
= ntohs(*(__be16
*)&buf
[12]);
904 case ISDN_NET_ENCAP_CISCOHDLC
:
905 proto
= ntohs(*(__be16
*)&buf
[2]);
908 #ifdef CONFIG_ISDN_PPP
909 case ISDN_NET_ENCAP_SYNCPPP
:
910 proto
= ntohs(skb
->protocol
);
911 p
= &buf
[IPPP_MAX_HEADER
];
916 data_ofs
= ((p
[0] & 15) * 4);
921 strcpy(addinfo
, " ICMP");
924 strcpy(addinfo
, " IGMP");
927 strcpy(addinfo
, " IPIP");
930 ipp
= (ip_ports
*) (&p
[data_ofs
]);
931 sprintf(addinfo
, " TCP, port: %d -> %d", ntohs(ipp
->source
),
935 strcpy(addinfo
, " EGP");
938 strcpy(addinfo
, " PUP");
941 ipp
= (ip_ports
*) (&p
[data_ofs
]);
942 sprintf(addinfo
, " UDP, port: %d -> %d", ntohs(ipp
->source
),
946 strcpy(addinfo
, " IDP");
949 printk(KERN_INFO
"OPEN: %pI4 -> %pI4%s\n",
950 p
+ 12, p
+ 16, addinfo
);
953 printk(KERN_INFO
"OPEN: ARP %pI4 -> *.*.*.* ?%pI4\n",
960 * this function is used to send supervisory data, i.e. data which was
961 * not received from the network layer, but e.g. frames from ipppd, CCP
964 void isdn_net_write_super(isdn_net_local
*lp
, struct sk_buff
*skb
)
967 // we can't grab the lock from irq context,
968 // so we just queue the packet
969 skb_queue_tail(&lp
->super_tx_queue
, skb
);
970 schedule_work(&lp
->tqueue
);
974 spin_lock_bh(&lp
->xmit_lock
);
975 if (!isdn_net_lp_busy(lp
)) {
976 isdn_net_writebuf_skb(lp
, skb
);
978 skb_queue_tail(&lp
->super_tx_queue
, skb
);
980 spin_unlock_bh(&lp
->xmit_lock
);
984 * called from tq_immediate
986 static void isdn_net_softint(struct work_struct
*work
)
988 isdn_net_local
*lp
= container_of(work
, isdn_net_local
, tqueue
);
991 spin_lock_bh(&lp
->xmit_lock
);
992 while (!isdn_net_lp_busy(lp
)) {
993 skb
= skb_dequeue(&lp
->super_tx_queue
);
996 isdn_net_writebuf_skb(lp
, skb
);
998 spin_unlock_bh(&lp
->xmit_lock
);
1002 * all frames sent from the (net) LL to a HL driver should go via this function
1003 * it's serialized by the caller holding the lp->xmit_lock spinlock
1005 void isdn_net_writebuf_skb(isdn_net_local
*lp
, struct sk_buff
*skb
)
1008 int len
= skb
->len
; /* save len */
1010 /* before obtaining the lock the caller should have checked that
1011 the lp isn't busy */
1012 if (isdn_net_lp_busy(lp
)) {
1013 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1017 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1018 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1021 ret
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
);
1023 /* we should never get here */
1024 printk(KERN_WARNING
"%s: HL driver queue full\n", lp
->netdev
->dev
->name
);
1028 lp
->transcount
+= len
;
1029 isdn_net_inc_frame_cnt(lp
);
1034 lp
->stats
.tx_errors
++;
1040 * Helper function for isdn_net_start_xmit.
1041 * When called, the connection is already established.
1042 * Based on cps-calculation, check if device is overloaded.
1043 * If so, and if a slave exists, trigger dialing for it.
1044 * If any slave is online, deliver packets using a simple round robin
1047 * Return: 0 on success, !0 on failure.
1051 isdn_net_xmit(struct net_device
*ndev
, struct sk_buff
*skb
)
1054 isdn_net_local
*slp
;
1055 isdn_net_local
*lp
= netdev_priv(ndev
);
1056 int retv
= NETDEV_TX_OK
;
1058 if (((isdn_net_local
*) netdev_priv(ndev
))->master
) {
1059 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1061 return NETDEV_TX_OK
;
1064 /* For the other encaps the header has already been built */
1065 #ifdef CONFIG_ISDN_PPP
1066 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1067 return isdn_ppp_xmit(skb
, ndev
);
1070 nd
= ((isdn_net_local
*) netdev_priv(ndev
))->netdev
;
1071 lp
= isdn_net_get_locked_lp(nd
);
1073 printk(KERN_WARNING
"%s: all channels busy - requeuing!\n", ndev
->name
);
1074 return NETDEV_TX_BUSY
;
1076 /* we have our lp locked from now on */
1078 /* Reset hangup-timeout */
1079 lp
->huptimer
= 0; // FIXME?
1080 isdn_net_writebuf_skb(lp
, skb
);
1081 spin_unlock_bh(&lp
->xmit_lock
);
1083 /* the following stuff is here for backwards compatibility.
1084 * in future, start-up and hangup of slaves (based on current load)
1085 * should move to userspace and get based on an overall cps
1088 if (lp
->cps
> lp
->triggercps
) {
1091 /* First time overload: set timestamp only */
1093 lp
->sqfull_stamp
= jiffies
;
1095 /* subsequent overload: if slavedelay exceeded, start dialing */
1096 if (time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
)) {
1097 slp
= ISDN_SLAVE_PRIV(lp
);
1098 if (!(slp
->flags
& ISDN_NET_CONNECTED
)) {
1099 isdn_net_force_dial_lp(ISDN_SLAVE_PRIV(lp
));
1105 if (lp
->sqfull
&& time_after(jiffies
, lp
->sqfull_stamp
+ lp
->slavedelay
+ (10 * HZ
))) {
1108 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1109 nd
->queue
= nd
->local
;
1117 isdn_net_adjust_hdr(struct sk_buff
*skb
, struct net_device
*dev
)
1119 isdn_net_local
*lp
= netdev_priv(dev
);
1122 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1123 const int pullsize
= skb_network_offset(skb
) - ETH_HLEN
;
1125 printk(KERN_DEBUG
"isdn_net: Pull junk %d\n", pullsize
);
1126 skb_pull(skb
, pullsize
);
1132 static void isdn_net_tx_timeout(struct net_device
*ndev
)
1134 isdn_net_local
*lp
= netdev_priv(ndev
);
1136 printk(KERN_WARNING
"isdn_tx_timeout dev %s dialstate %d\n", ndev
->name
, lp
->dialstate
);
1137 if (!lp
->dialstate
) {
1138 lp
->stats
.tx_errors
++;
1140 * There is a certain probability that this currently
1141 * works at all because if we always wake up the interface,
1142 * then upper layer will try to send the next packet
1143 * immediately. And then, the old clean_up logic in the
1144 * driver will hopefully continue to work as it used to do.
1146 * This is rather primitive right know, we better should
1147 * clean internal queues here, in particular for multilink and
1148 * ppp, and reset HL driver's channel, too. --HE
1150 * actually, this may not matter at all, because ISDN hardware
1151 * should not see transmitter hangs at all IMO
1152 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1156 netif_trans_update(ndev
);
1157 netif_wake_queue(ndev
);
1161 * Try sending a packet.
1162 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1163 * and start dialing.
1166 isdn_net_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1168 isdn_net_local
*lp
= netdev_priv(ndev
);
1169 #ifdef CONFIG_ISDN_X25
1170 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
1171 /* At this point hard_start_xmit() passes control to the encapsulation
1172 protocol (if present).
1173 For X.25 auto-dialing is completly bypassed because:
1174 - It does not conform with the semantics of a reliable datalink
1175 service as needed by X.25 PLP.
1176 - I don't want that the interface starts dialing when the network layer
1177 sends a message which requests to disconnect the lapb link (or if it
1178 sends any other message not resulting in data transmission).
1179 Instead, dialing will be initiated by the encapsulation protocol entity
1180 when a dl_establish request is received from the upper layer.
1182 if (cprot
&& cprot
->pops
) {
1183 int ret
= cprot
->pops
->encap_and_xmit(cprot
, skb
);
1186 netif_stop_queue(ndev
);
1190 /* auto-dialing xmit function */
1192 #ifdef ISDN_DEBUG_NET_DUMP
1195 isdn_net_adjust_hdr(skb
, ndev
);
1196 #ifdef ISDN_DEBUG_NET_DUMP
1198 isdn_dumppkt("S:", buf
, skb
->len
, 40);
1201 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1203 /* only do autodial if allowed by config */
1204 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) {
1205 isdn_net_unreachable(ndev
, skb
, "dial rejected: interface not in dialmode `auto'");
1207 return NETDEV_TX_OK
;
1212 if (lp
->dialwait_timer
<= 0)
1213 if (lp
->dialstarted
> 0 && lp
->dialtimeout
> 0 && time_before(jiffies
, lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
))
1214 lp
->dialwait_timer
= lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
;
1216 if (lp
->dialwait_timer
> 0) {
1217 if (time_before(jiffies
, lp
->dialwait_timer
)) {
1218 isdn_net_unreachable(ndev
, skb
, "dial rejected: retry-time not reached");
1220 return NETDEV_TX_OK
;
1222 lp
->dialwait_timer
= 0;
1224 /* Grab a free ISDN-Channel */
1225 spin_lock_irqsave(&dev
->lock
, flags
);
1227 isdn_get_free_channel(
1236 isdn_get_free_channel(
1244 spin_unlock_irqrestore(&dev
->lock
, flags
);
1245 isdn_net_unreachable(ndev
, skb
,
1248 return NETDEV_TX_OK
;
1250 /* Log packet, which triggered dialing */
1251 if (dev
->net_verbose
)
1252 isdn_net_log_skb(skb
, lp
);
1254 /* Connect interface with channel */
1255 isdn_net_bind_channel(lp
, chi
);
1256 #ifdef CONFIG_ISDN_PPP
1257 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1258 /* no 'first_skb' handling for syncPPP */
1259 if (isdn_ppp_bind(lp
) < 0) {
1261 isdn_net_unbind_channel(lp
);
1262 spin_unlock_irqrestore(&dev
->lock
, flags
);
1263 return NETDEV_TX_OK
; /* STN (skb to nirvana) ;) */
1265 #ifdef CONFIG_IPPP_FILTER
1266 if (isdn_ppp_autodial_filter(skb
, lp
)) {
1268 isdn_net_unbind_channel(lp
);
1269 spin_unlock_irqrestore(&dev
->lock
, flags
);
1270 isdn_net_unreachable(ndev
, skb
, "dial rejected: packet filtered");
1272 return NETDEV_TX_OK
;
1275 spin_unlock_irqrestore(&dev
->lock
, flags
);
1276 isdn_net_dial(); /* Initiate dialing */
1277 netif_stop_queue(ndev
);
1278 return NETDEV_TX_BUSY
; /* let upper layer requeue skb packet */
1281 /* Initiate dialing */
1282 spin_unlock_irqrestore(&dev
->lock
, flags
);
1284 isdn_net_device_stop_queue(lp
);
1285 return NETDEV_TX_BUSY
;
1287 isdn_net_unreachable(ndev
, skb
,
1290 return NETDEV_TX_OK
;
1293 /* Device is connected to an ISDN channel */
1294 netif_trans_update(ndev
);
1295 if (!lp
->dialstate
) {
1296 /* ISDN connection is established, try sending */
1298 ret
= (isdn_net_xmit(ndev
, skb
));
1299 if (ret
) netif_stop_queue(ndev
);
1302 netif_stop_queue(ndev
);
1305 return NETDEV_TX_BUSY
;
1309 * Shutdown a net-interface.
1312 isdn_net_close(struct net_device
*dev
)
1314 struct net_device
*p
;
1315 #ifdef CONFIG_ISDN_X25
1316 struct concap_proto
*cprot
=
1317 ((isdn_net_local
*)netdev_priv(dev
))->netdev
->cprot
;
1318 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name); */
1321 #ifdef CONFIG_ISDN_X25
1322 if (cprot
&& cprot
->pops
) cprot
->pops
->close(cprot
);
1324 netif_stop_queue(dev
);
1325 p
= MASTER_TO_SLAVE(dev
);
1327 /* If this interface has slaves, stop them also */
1329 #ifdef CONFIG_ISDN_X25
1330 cprot
= ((isdn_net_local
*)netdev_priv(p
))
1332 if (cprot
&& cprot
->pops
)
1333 cprot
->pops
->close(cprot
);
1336 p
= MASTER_TO_SLAVE(p
);
1339 isdn_net_hangup(dev
);
1340 isdn_unlock_drivers();
1347 static struct net_device_stats
*
1348 isdn_net_get_stats(struct net_device
*dev
)
1350 isdn_net_local
*lp
= netdev_priv(dev
);
1354 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1355 * instead of dev->hard_header_len off. This is done because the
1356 * lowlevel-driver has already pulled off its stuff when we get
1357 * here and this routine only gets called with p_encap == ETHER.
1358 * Determine the packet's protocol ID. The rule here is that we
1359 * assume 802.3 if the type field is short enough to be a length.
1360 * This is normal practice and works for any 'now in use' protocol.
1364 isdn_net_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1367 unsigned char *rawp
;
1369 skb_reset_mac_header(skb
);
1370 skb_pull(skb
, ETH_HLEN
);
1373 if (*eth
->h_dest
& 1) {
1374 if (ether_addr_equal(eth
->h_dest
, dev
->broadcast
))
1375 skb
->pkt_type
= PACKET_BROADCAST
;
1377 skb
->pkt_type
= PACKET_MULTICAST
;
1380 * This ALLMULTI check should be redundant by 1.4
1381 * so don't forget to remove it.
1384 else if (dev
->flags
& (IFF_PROMISC
/*| IFF_ALLMULTI*/)) {
1385 if (!ether_addr_equal(eth
->h_dest
, dev
->dev_addr
))
1386 skb
->pkt_type
= PACKET_OTHERHOST
;
1388 if (ntohs(eth
->h_proto
) >= ETH_P_802_3_MIN
)
1389 return eth
->h_proto
;
1394 * This is a magic hack to spot IPX packets. Older Novell breaks
1395 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1396 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1397 * won't work for fault tolerant netware but does for the rest.
1399 if (*(unsigned short *) rawp
== 0xFFFF)
1400 return htons(ETH_P_802_3
);
1404 return htons(ETH_P_802_2
);
1409 * CISCO HDLC keepalive specific stuff
1411 static struct sk_buff
*
1412 isdn_net_ciscohdlck_alloc_skb(isdn_net_local
*lp
, int len
)
1414 unsigned short hl
= dev
->drv
[lp
->isdn_device
]->interface
->hl_hdrlen
;
1415 struct sk_buff
*skb
;
1417 skb
= alloc_skb(hl
+ len
, GFP_ATOMIC
);
1419 skb_reserve(skb
, hl
);
1421 printk("isdn out of mem at %s:%d!\n", __FILE__
, __LINE__
);
1425 /* cisco hdlck device private ioctls */
1427 isdn_ciscohdlck_dev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1429 isdn_net_local
*lp
= netdev_priv(dev
);
1430 unsigned long len
= 0;
1431 unsigned long expires
= 0;
1433 int period
= lp
->cisco_keepalive_period
;
1434 s8 debserint
= lp
->cisco_debserint
;
1437 if (lp
->p_encap
!= ISDN_NET_ENCAP_CISCOHDLCK
)
1441 /* get/set keepalive period */
1442 case SIOCGKEEPPERIOD
:
1443 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1444 if (copy_to_user(ifr
->ifr_data
,
1445 &lp
->cisco_keepalive_period
, len
))
1448 case SIOCSKEEPPERIOD
:
1449 tmp
= lp
->cisco_keepalive_period
;
1450 len
= (unsigned long)sizeof(lp
->cisco_keepalive_period
);
1451 if (copy_from_user(&period
, ifr
->ifr_data
, len
))
1453 if ((period
> 0) && (period
<= 32767))
1454 lp
->cisco_keepalive_period
= period
;
1457 if (!rc
&& (tmp
!= lp
->cisco_keepalive_period
)) {
1458 expires
= (unsigned long)(jiffies
+
1459 lp
->cisco_keepalive_period
* HZ
);
1460 mod_timer(&lp
->cisco_timer
, expires
);
1461 printk(KERN_INFO
"%s: Keepalive period set "
1463 dev
->name
, lp
->cisco_keepalive_period
);
1467 /* get/set debugging */
1468 case SIOCGDEBSERINT
:
1469 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1470 if (copy_to_user(ifr
->ifr_data
,
1471 &lp
->cisco_debserint
, len
))
1474 case SIOCSDEBSERINT
:
1475 len
= (unsigned long)sizeof(lp
->cisco_debserint
);
1476 if (copy_from_user(&debserint
,
1477 ifr
->ifr_data
, len
))
1479 if ((debserint
>= 0) && (debserint
<= 64))
1480 lp
->cisco_debserint
= debserint
;
1493 static int isdn_net_ioctl(struct net_device
*dev
,
1494 struct ifreq
*ifr
, int cmd
)
1496 isdn_net_local
*lp
= netdev_priv(dev
);
1498 switch (lp
->p_encap
) {
1499 #ifdef CONFIG_ISDN_PPP
1500 case ISDN_NET_ENCAP_SYNCPPP
:
1501 return isdn_ppp_dev_ioctl(dev
, ifr
, cmd
);
1503 case ISDN_NET_ENCAP_CISCOHDLCK
:
1504 return isdn_ciscohdlck_dev_ioctl(dev
, ifr
, cmd
);
1510 /* called via cisco_timer.function */
1512 isdn_net_ciscohdlck_slarp_send_keepalive(struct timer_list
*t
)
1514 isdn_net_local
*lp
= from_timer(lp
, t
, cisco_timer
);
1515 struct sk_buff
*skb
;
1517 unsigned long last_cisco_myseq
= lp
->cisco_myseq
;
1520 if (!(lp
->flags
& ISDN_NET_CONNECTED
) || lp
->dialstate
) {
1521 printk("isdn BUG at %s:%d!\n", __FILE__
, __LINE__
);
1526 myseq_diff
= (lp
->cisco_myseq
- lp
->cisco_mineseen
);
1527 if ((lp
->cisco_line_state
) && ((myseq_diff
>= 3) || (myseq_diff
<= -3))) {
1528 /* line up -> down */
1529 lp
->cisco_line_state
= 0;
1531 "UPDOWN: Line protocol on Interface %s,"
1532 " changed state to down\n", lp
->netdev
->dev
->name
);
1533 /* should stop routing higher-level data across */
1534 } else if ((!lp
->cisco_line_state
) &&
1535 (myseq_diff
>= 0) && (myseq_diff
<= 2)) {
1536 /* line down -> up */
1537 lp
->cisco_line_state
= 1;
1539 "UPDOWN: Line protocol on Interface %s,"
1540 " changed state to up\n", lp
->netdev
->dev
->name
);
1541 /* restart routing higher-level data across */
1544 if (lp
->cisco_debserint
)
1545 printk(KERN_DEBUG
"%s: HDLC "
1546 "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
1547 lp
->netdev
->dev
->name
, last_cisco_myseq
, lp
->cisco_mineseen
,
1548 ((last_cisco_myseq
== lp
->cisco_mineseen
) ? '*' : 040),
1550 ((lp
->cisco_line_state
) ? "line up" : "line down"));
1552 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1556 p
= skb_put(skb
, 4 + 14);
1559 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1560 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1561 *(__be16
*)(p
+ 2) = cpu_to_be16(CISCO_TYPE_SLARP
);
1563 /* slarp keepalive */
1564 *(__be32
*)(p
+ 4) = cpu_to_be32(CISCO_SLARP_KEEPALIVE
);
1565 *(__be32
*)(p
+ 8) = cpu_to_be32(lp
->cisco_myseq
);
1566 *(__be32
*)(p
+ 12) = cpu_to_be32(lp
->cisco_yourseq
);
1567 *(__be16
*)(p
+ 16) = cpu_to_be16(0xffff); // reliability, always 0xffff
1570 isdn_net_write_super(lp
, skb
);
1572 lp
->cisco_timer
.expires
= jiffies
+ lp
->cisco_keepalive_period
* HZ
;
1574 add_timer(&lp
->cisco_timer
);
1578 isdn_net_ciscohdlck_slarp_send_request(isdn_net_local
*lp
)
1580 struct sk_buff
*skb
;
1583 skb
= isdn_net_ciscohdlck_alloc_skb(lp
, 4 + 14);
1587 p
= skb_put(skb
, 4 + 14);
1590 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1591 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1592 *(__be16
*)(p
+ 2) = cpu_to_be16(CISCO_TYPE_SLARP
);
1595 *(__be32
*)(p
+ 4) = cpu_to_be32(CISCO_SLARP_REQUEST
);
1596 *(__be32
*)(p
+ 8) = cpu_to_be32(0); // address
1597 *(__be32
*)(p
+ 12) = cpu_to_be32(0); // netmask
1598 *(__be16
*)(p
+ 16) = cpu_to_be16(0); // unused
1601 isdn_net_write_super(lp
, skb
);
1605 isdn_net_ciscohdlck_connected(isdn_net_local
*lp
)
1607 lp
->cisco_myseq
= 0;
1608 lp
->cisco_mineseen
= 0;
1609 lp
->cisco_yourseq
= 0;
1610 lp
->cisco_keepalive_period
= ISDN_TIMER_KEEPINT
;
1611 lp
->cisco_last_slarp_in
= 0;
1612 lp
->cisco_line_state
= 0;
1613 lp
->cisco_debserint
= 0;
1615 /* send slarp request because interface/seq.no.s reset */
1616 isdn_net_ciscohdlck_slarp_send_request(lp
);
1618 timer_setup(&lp
->cisco_timer
,
1619 isdn_net_ciscohdlck_slarp_send_keepalive
, 0);
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
;
1685 code
= be32_to_cpup((__be32
*)p
);
1689 case CISCO_SLARP_REQUEST
:
1690 lp
->cisco_yourseq
= 0;
1691 isdn_net_ciscohdlck_slarp_send_reply(lp
);
1693 case CISCO_SLARP_REPLY
:
1695 mask
= (__be32
*)(p
+ 4);
1696 if (*mask
!= cpu_to_be32(0xfffffffc))
1697 goto slarp_reply_out
;
1698 if ((*addr
& cpu_to_be32(3)) == cpu_to_be32(0) ||
1699 (*addr
& cpu_to_be32(3)) == cpu_to_be32(3))
1700 goto slarp_reply_out
;
1701 local
= *addr
^ cpu_to_be32(3);
1702 printk(KERN_INFO
"%s: got slarp reply: remote ip: %pI4, local ip: %pI4 mask: %pI4\n",
1703 lp
->netdev
->dev
->name
, addr
, &local
, mask
);
1706 printk(KERN_INFO
"%s: got invalid slarp reply (%pI4/%pI4) - ignored\n",
1707 lp
->netdev
->dev
->name
, addr
, mask
);
1709 case CISCO_SLARP_KEEPALIVE
:
1710 period
= (int)((jiffies
- lp
->cisco_last_slarp_in
1711 + HZ
/ 2 - 1) / HZ
);
1712 if (lp
->cisco_debserint
&&
1713 (period
!= lp
->cisco_keepalive_period
) &&
1714 lp
->cisco_last_slarp_in
) {
1715 printk(KERN_DEBUG
"%s: Keepalive period mismatch - "
1716 "is %d but should be %d.\n",
1717 lp
->netdev
->dev
->name
, period
,
1718 lp
->cisco_keepalive_period
);
1720 lp
->cisco_last_slarp_in
= jiffies
;
1721 my_seq
= be32_to_cpup((__be32
*)(p
+ 0));
1722 your_seq
= be32_to_cpup((__be32
*)(p
+ 4));
1724 lp
->cisco_yourseq
= my_seq
;
1725 lp
->cisco_mineseen
= your_seq
;
1731 isdn_net_ciscohdlck_receive(isdn_net_local
*lp
, struct sk_buff
*skb
)
1742 addr
= *(u8
*)(p
+ 0);
1743 ctrl
= *(u8
*)(p
+ 1);
1744 type
= be16_to_cpup((__be16
*)(p
+ 2));
1748 if (addr
!= CISCO_ADDR_UNICAST
&& addr
!= CISCO_ADDR_BROADCAST
) {
1749 printk(KERN_WARNING
"%s: Unknown Cisco addr 0x%02x\n",
1750 lp
->netdev
->dev
->name
, addr
);
1753 if (ctrl
!= CISCO_CTRL
) {
1754 printk(KERN_WARNING
"%s: Unknown Cisco ctrl 0x%02x\n",
1755 lp
->netdev
->dev
->name
, ctrl
);
1760 case CISCO_TYPE_SLARP
:
1761 isdn_net_ciscohdlck_slarp_in(lp
, skb
);
1763 case CISCO_TYPE_CDP
:
1764 if (lp
->cisco_debserint
)
1765 printk(KERN_DEBUG
"%s: Received CDP packet. use "
1766 "\"no cdp enable\" on cisco.\n",
1767 lp
->netdev
->dev
->name
);
1770 /* no special cisco protocol */
1771 skb
->protocol
= htons(type
);
1781 * Got a packet from ISDN-Channel.
1784 isdn_net_receive(struct net_device
*ndev
, struct sk_buff
*skb
)
1786 isdn_net_local
*lp
= netdev_priv(ndev
);
1787 isdn_net_local
*olp
= lp
; /* original 'lp' */
1788 #ifdef CONFIG_ISDN_X25
1789 struct concap_proto
*cprot
= lp
->netdev
->cprot
;
1791 lp
->transcount
+= skb
->len
;
1793 lp
->stats
.rx_packets
++;
1794 lp
->stats
.rx_bytes
+= skb
->len
;
1796 /* Bundling: If device is a slave-device, deliver to master, also
1797 * handle master's statistics and hangup-timeout
1800 lp
= netdev_priv(ndev
);
1801 lp
->stats
.rx_packets
++;
1802 lp
->stats
.rx_bytes
+= skb
->len
;
1805 skb
->pkt_type
= PACKET_HOST
;
1806 skb_reset_mac_header(skb
);
1807 #ifdef ISDN_DEBUG_NET_DUMP
1808 isdn_dumppkt("R:", skb
->data
, skb
->len
, 40);
1810 switch (lp
->p_encap
) {
1811 case ISDN_NET_ENCAP_ETHER
:
1812 /* Ethernet over ISDN */
1815 skb
->protocol
= isdn_net_type_trans(skb
, ndev
);
1817 case ISDN_NET_ENCAP_UIHDLC
:
1818 /* HDLC with UI-frame (for ispa with -h1 option) */
1823 case ISDN_NET_ENCAP_RAWIP
:
1824 /* RAW-IP without MAC-Header */
1827 skb
->protocol
= htons(ETH_P_IP
);
1829 case ISDN_NET_ENCAP_CISCOHDLCK
:
1830 isdn_net_ciscohdlck_receive(lp
, skb
);
1832 case ISDN_NET_ENCAP_CISCOHDLC
:
1833 /* CISCO-HDLC IP with type field and fake I-frame-header */
1836 case ISDN_NET_ENCAP_IPTYP
:
1837 /* IP with type field */
1840 skb
->protocol
= *(__be16
*)&(skb
->data
[0]);
1842 if (*(unsigned short *) skb
->data
== 0xFFFF)
1843 skb
->protocol
= htons(ETH_P_802_3
);
1845 #ifdef CONFIG_ISDN_PPP
1846 case ISDN_NET_ENCAP_SYNCPPP
:
1847 /* huptimer is done in isdn_ppp_push_higher */
1848 isdn_ppp_receive(lp
->netdev
, olp
, skb
);
1853 #ifdef CONFIG_ISDN_X25
1854 /* try if there are generic sync_device receiver routines */
1855 if (cprot
) if (cprot
->pops
)
1856 if (cprot
->pops
->data_ind
) {
1857 cprot
->pops
->data_ind(cprot
, skb
);
1860 #endif /* CONFIG_ISDN_X25 */
1861 printk(KERN_WARNING
"%s: unknown encapsulation, dropping\n",
1862 lp
->netdev
->dev
->name
);
1872 * A packet arrived via ISDN. Search interface-chain for a corresponding
1873 * interface. If found, deliver packet to receiver-function and return 1,
1877 isdn_net_rcv_skb(int idx
, struct sk_buff
*skb
)
1879 isdn_net_dev
*p
= dev
->rx_netdev
[idx
];
1882 isdn_net_local
*lp
= p
->local
;
1883 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
1885 isdn_net_receive(p
->dev
, skb
);
1894 * depends on encaps that is being used.
1897 static int isdn_net_header(struct sk_buff
*skb
, struct net_device
*dev
,
1898 unsigned short type
,
1899 const void *daddr
, const void *saddr
, unsigned plen
)
1901 isdn_net_local
*lp
= netdev_priv(dev
);
1905 switch (lp
->p_encap
) {
1906 case ISDN_NET_ENCAP_ETHER
:
1907 len
= eth_header(skb
, dev
, type
, daddr
, saddr
, plen
);
1909 #ifdef CONFIG_ISDN_PPP
1910 case ISDN_NET_ENCAP_SYNCPPP
:
1911 /* stick on a fake header to keep fragmentation code happy. */
1912 len
= IPPP_MAX_HEADER
;
1916 case ISDN_NET_ENCAP_RAWIP
:
1917 printk(KERN_WARNING
"isdn_net_header called with RAW_IP!\n");
1920 case ISDN_NET_ENCAP_IPTYP
:
1921 /* ethernet type field */
1922 *((__be16
*)skb_push(skb
, 2)) = htons(type
);
1925 case ISDN_NET_ENCAP_UIHDLC
:
1926 /* HDLC with UI-Frames (for ispa with -h1 option) */
1927 *((__be16
*)skb_push(skb
, 2)) = htons(0x0103);
1930 case ISDN_NET_ENCAP_CISCOHDLC
:
1931 case ISDN_NET_ENCAP_CISCOHDLCK
:
1932 p
= skb_push(skb
, 4);
1933 *(u8
*)(p
+ 0) = CISCO_ADDR_UNICAST
;
1934 *(u8
*)(p
+ 1) = CISCO_CTRL
;
1935 *(__be16
*)(p
+ 2) = cpu_to_be16(type
);
1939 #ifdef CONFIG_ISDN_X25
1941 /* try if there are generic concap protocol routines */
1942 if (lp
->netdev
->cprot
) {
1943 printk(KERN_WARNING
"isdn_net_header called with concap_proto!\n");
1948 #endif /* CONFIG_ISDN_X25 */
1953 static int isdn_header_cache(const struct neighbour
*neigh
, struct hh_cache
*hh
,
1956 const struct net_device
*dev
= neigh
->dev
;
1957 isdn_net_local
*lp
= netdev_priv(dev
);
1959 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
)
1960 return eth_header_cache(neigh
, hh
, type
);
1964 static void isdn_header_cache_update(struct hh_cache
*hh
,
1965 const struct net_device
*dev
,
1966 const unsigned char *haddr
)
1968 isdn_net_local
*lp
= netdev_priv(dev
);
1969 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
)
1970 eth_header_cache_update(hh
, dev
, haddr
);
1973 static const struct header_ops isdn_header_ops
= {
1974 .create
= isdn_net_header
,
1975 .cache
= isdn_header_cache
,
1976 .cache_update
= isdn_header_cache_update
,
1980 * Interface-setup. (just after registering a new interface)
1983 isdn_net_init(struct net_device
*ndev
)
1985 ushort max_hlhdr_len
= 0;
1989 * up till binding we ask the protocol layer to reserve as much
1990 * as we might need for HL layer
1993 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
1994 if (dev
->drv
[drvidx
])
1995 if (max_hlhdr_len
< dev
->drv
[drvidx
]->interface
->hl_hdrlen
)
1996 max_hlhdr_len
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1998 ndev
->hard_header_len
= ETH_HLEN
+ max_hlhdr_len
;
2003 isdn_net_swapbind(int drvidx
)
2007 #ifdef ISDN_DEBUG_NET_ICALL
2008 printk(KERN_DEBUG
"n_fi: swapping ch of %d\n", drvidx
);
2012 if (p
->local
->pre_device
== drvidx
)
2013 switch (p
->local
->pre_channel
) {
2015 p
->local
->pre_channel
= 1;
2018 p
->local
->pre_channel
= 0;
2021 p
= (isdn_net_dev
*) p
->next
;
2026 isdn_net_swap_usage(int i1
, int i2
)
2028 int u1
= dev
->usage
[i1
] & ISDN_USAGE_EXCLUSIVE
;
2029 int u2
= dev
->usage
[i2
] & ISDN_USAGE_EXCLUSIVE
;
2031 #ifdef ISDN_DEBUG_NET_ICALL
2032 printk(KERN_DEBUG
"n_fi: usage of %d and %d\n", i1
, i2
);
2034 dev
->usage
[i1
] &= ~ISDN_USAGE_EXCLUSIVE
;
2035 dev
->usage
[i1
] |= u2
;
2036 dev
->usage
[i2
] &= ~ISDN_USAGE_EXCLUSIVE
;
2037 dev
->usage
[i2
] |= u1
;
2042 * An incoming call-request has arrived.
2043 * Search the interface-chain for an appropriate interface.
2044 * If found, connect the interface to the ISDN-channel and initiate
2045 * D- and B-Channel-setup. If secure-flag is set, accept only
2046 * configured phone-numbers. If callback-flag is set, initiate
2049 * Return-Value: 0 = No appropriate interface for this call.
2051 * 2 = Reject call, wait cbdelay, then call back
2053 * 4 = Wait cbdelay, then call back
2054 * 5 = No appropriate interface for this call,
2055 * would eventually match if CID was longer.
2059 isdn_net_find_icall(int di
, int ch
, int idx
, setup_parm
*setup
)
2071 char nr
[ISDN_MSNLEN
];
2074 /* Search name in netdev-chain */
2075 if (!setup
->phone
[0]) {
2078 printk(KERN_INFO
"isdn_net: Incoming call without OAD, assuming '0'\n");
2080 strlcpy(nr
, setup
->phone
, ISDN_MSNLEN
);
2081 si1
= (int) setup
->si1
;
2082 si2
= (int) setup
->si2
;
2083 if (!setup
->eazmsn
[0]) {
2084 printk(KERN_WARNING
"isdn_net: Incoming call without CPN, assuming '0'\n");
2087 eaz
= setup
->eazmsn
;
2088 if (dev
->net_verbose
> 1)
2089 printk(KERN_INFO
"isdn_net: call from %s,%d,%d -> %s\n", nr
, si1
, si2
, eaz
);
2090 /* Accept DATA and VOICE calls at this stage
2091 * local eaz is checked later for allowed call types
2093 if ((si1
!= 7) && (si1
!= 1)) {
2094 if (dev
->net_verbose
> 1)
2095 printk(KERN_INFO
"isdn_net: Service-Indicator not 1 or 7, ignored\n");
2098 n
= (isdn_net_phone
*) 0;
2100 ematch
= wret
= swapped
= 0;
2101 #ifdef ISDN_DEBUG_NET_ICALL
2102 printk(KERN_DEBUG
"n_fi: di=%d ch=%d idx=%d usg=%d\n", di
, ch
, idx
,
2107 isdn_net_local
*lp
= p
->local
;
2109 /* If last check has triggered as binding-swap, revert it */
2112 isdn_net_swap_usage(idx
, sidx
);
2115 isdn_net_swapbind(di
);
2119 /* check acceptable call types for DOV */
2120 my_eaz
= isdn_map_eaz2msn(lp
->msn
, di
);
2121 if (si1
== 1) { /* it's a DOV call, check if we allow it */
2122 if (*my_eaz
== 'v' || *my_eaz
== 'V' ||
2123 *my_eaz
== 'b' || *my_eaz
== 'B')
2124 my_eaz
++; /* skip to allow a match */
2126 my_eaz
= NULL
; /* force non match */
2127 } else { /* it's a DATA call, check if we allow it */
2128 if (*my_eaz
== 'b' || *my_eaz
== 'B')
2129 my_eaz
++; /* skip to allow a match */
2132 matchret
= isdn_msncmp(eaz
, my_eaz
);
2138 /* Remember if more numbers eventually can match */
2139 if (matchret
> wret
)
2141 #ifdef ISDN_DEBUG_NET_ICALL
2142 printk(KERN_DEBUG
"n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2143 p
->dev
->name
, lp
->msn
, lp
->flags
, lp
->dialstate
);
2145 if ((!matchret
) && /* EAZ is matching */
2146 (((!(lp
->flags
& ISDN_NET_CONNECTED
)) && /* but not connected */
2147 (USG_NONE(dev
->usage
[idx
]))) || /* and ch. unused or */
2148 ((((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) && /* if dialing */
2149 (!(lp
->flags
& ISDN_NET_CALLBACK
))) /* but no callback */
2152 #ifdef ISDN_DEBUG_NET_ICALL
2153 printk(KERN_DEBUG
"n_fi: match1, pdev=%d pch=%d\n",
2154 lp
->pre_device
, lp
->pre_channel
);
2156 if (dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) {
2157 if ((lp
->pre_channel
!= ch
) ||
2158 (lp
->pre_device
!= di
)) {
2159 /* Here we got a problem:
2160 * If using an ICN-Card, an incoming call is always signaled on
2161 * on the first channel of the card, if both channels are
2162 * down. However this channel may be bound exclusive. If the
2163 * second channel is free, this call should be accepted.
2164 * The solution is horribly but it runs, so what:
2165 * We exchange the exclusive bindings of the two channels, the
2166 * corresponding variables in the interface-structs.
2169 sidx
= isdn_dc2minor(di
, 1);
2170 #ifdef ISDN_DEBUG_NET_ICALL
2171 printk(KERN_DEBUG
"n_fi: ch is 0\n");
2173 if (USG_NONE(dev
->usage
[sidx
])) {
2174 /* Second Channel is free, now see if it is bound
2176 if (dev
->usage
[sidx
] & ISDN_USAGE_EXCLUSIVE
) {
2177 #ifdef ISDN_DEBUG_NET_ICALL
2178 printk(KERN_DEBUG
"n_fi: 2nd channel is down and bound\n");
2180 /* Yes, swap bindings only, if the original
2181 * binding is bound to channel 1 of this driver */
2182 if ((lp
->pre_device
== di
) &&
2183 (lp
->pre_channel
== 1)) {
2184 isdn_net_swapbind(di
);
2187 /* ... else iterate next device */
2188 p
= (isdn_net_dev
*) p
->next
;
2192 #ifdef ISDN_DEBUG_NET_ICALL
2193 printk(KERN_DEBUG
"n_fi: 2nd channel is down and unbound\n");
2195 /* No, swap always and swap excl-usage also */
2196 isdn_net_swap_usage(idx
, sidx
);
2197 isdn_net_swapbind(di
);
2200 /* Now check for exclusive binding again */
2201 #ifdef ISDN_DEBUG_NET_ICALL
2202 printk(KERN_DEBUG
"n_fi: final check\n");
2204 if ((dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) &&
2205 ((lp
->pre_channel
!= ch
) ||
2206 (lp
->pre_device
!= di
))) {
2207 #ifdef ISDN_DEBUG_NET_ICALL
2208 printk(KERN_DEBUG
"n_fi: final check failed\n");
2210 p
= (isdn_net_dev
*) p
->next
;
2215 /* We are already on the second channel, so nothing to do */
2216 #ifdef ISDN_DEBUG_NET_ICALL
2217 printk(KERN_DEBUG
"n_fi: already on 2nd channel\n");
2222 #ifdef ISDN_DEBUG_NET_ICALL
2223 printk(KERN_DEBUG
"n_fi: match2\n");
2226 if (lp
->flags
& ISDN_NET_SECURE
) {
2228 if (!isdn_msncmp(nr
, n
->num
))
2230 n
= (isdn_net_phone
*) n
->next
;
2233 if (n
|| (!(lp
->flags
& ISDN_NET_SECURE
))) {
2234 #ifdef ISDN_DEBUG_NET_ICALL
2235 printk(KERN_DEBUG
"n_fi: match3\n");
2237 /* matching interface found */
2240 * Is the state STOPPED?
2241 * If so, no dialin is allowed,
2242 * so reject actively.
2244 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2245 printk(KERN_INFO
"incoming call, interface %s `stopped' -> rejected\n",
2250 * Is the interface up?
2251 * If not, reject the call actively.
2253 if (!isdn_net_device_started(p
)) {
2254 printk(KERN_INFO
"%s: incoming call, interface down -> rejected\n",
2258 /* Interface is up, now see if it's a slave. If so, see if
2259 * it's master and parent slave is online. If not, reject the call.
2262 isdn_net_local
*mlp
= ISDN_MASTER_PRIV(lp
);
2263 printk(KERN_DEBUG
"ICALLslv: %s\n", p
->dev
->name
);
2264 printk(KERN_DEBUG
"master=%s\n", lp
->master
->name
);
2265 if (mlp
->flags
& ISDN_NET_CONNECTED
) {
2266 printk(KERN_DEBUG
"master online\n");
2267 /* Master is online, find parent-slave (master if first slave) */
2268 while (mlp
->slave
) {
2269 if (ISDN_SLAVE_PRIV(mlp
) == lp
)
2271 mlp
= ISDN_SLAVE_PRIV(mlp
);
2274 printk(KERN_DEBUG
"master offline\n");
2275 /* Found parent, if it's offline iterate next device */
2276 printk(KERN_DEBUG
"mlpf: %d\n", mlp
->flags
& ISDN_NET_CONNECTED
);
2277 if (!(mlp
->flags
& ISDN_NET_CONNECTED
)) {
2278 p
= (isdn_net_dev
*) p
->next
;
2282 if (lp
->flags
& ISDN_NET_CALLBACK
) {
2285 * Is the state MANUAL?
2286 * If so, no callback can be made,
2287 * so reject actively.
2289 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2290 printk(KERN_INFO
"incoming call for callback, interface %s `off' -> rejected\n",
2294 printk(KERN_DEBUG
"%s: call from %s -> %s, start callback\n",
2295 p
->dev
->name
, nr
, eaz
);
2297 /* Grab a free ISDN-Channel */
2298 spin_lock_irqsave(&dev
->lock
, flags
);
2300 isdn_get_free_channel(
2309 printk(KERN_WARNING
"isdn_net_find_icall: No channel for %s\n",
2311 spin_unlock_irqrestore(&dev
->lock
, flags
);
2314 /* Setup dialstate. */
2317 /* Connect interface with channel */
2318 isdn_net_bind_channel(lp
, chi
);
2319 #ifdef CONFIG_ISDN_PPP
2320 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2321 if (isdn_ppp_bind(lp
) < 0) {
2322 spin_unlock_irqrestore(&dev
->lock
, flags
);
2323 isdn_net_unbind_channel(lp
);
2327 spin_unlock_irqrestore(&dev
->lock
, flags
);
2328 /* Initiate dialing by returning 2 or 4 */
2329 return (lp
->flags
& ISDN_NET_CBHUP
) ? 2 : 4;
2331 printk(KERN_WARNING
"isdn_net: %s: No phone number\n",
2335 printk(KERN_DEBUG
"%s: call from %s -> %s accepted\n",
2336 p
->dev
->name
, nr
, eaz
);
2337 /* if this interface is dialing, it does it probably on a different
2338 device, so free this device */
2339 if ((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) {
2340 #ifdef CONFIG_ISDN_PPP
2341 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2344 isdn_net_lp_disconnected(lp
);
2345 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
2348 spin_lock_irqsave(&dev
->lock
, flags
);
2349 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2350 dev
->usage
[idx
] |= ISDN_USAGE_NET
;
2351 strcpy(dev
->num
[idx
], nr
);
2353 dev
->st_netdev
[idx
] = lp
->netdev
;
2354 lp
->isdn_device
= di
;
2355 lp
->isdn_channel
= ch
;
2357 lp
->flags
|= ISDN_NET_CONNECTED
;
2362 lp
->hupflags
|= ISDN_WAITCHARGE
;
2363 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
2364 #ifdef CONFIG_ISDN_PPP
2365 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
2366 if (isdn_ppp_bind(lp
) < 0) {
2367 isdn_net_unbind_channel(lp
);
2368 spin_unlock_irqrestore(&dev
->lock
, flags
);
2373 spin_unlock_irqrestore(&dev
->lock
, flags
);
2378 p
= (isdn_net_dev
*) p
->next
;
2380 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2381 if (!ematch
|| dev
->net_verbose
)
2382 printk(KERN_INFO
"isdn_net: call from %s -> %d %s ignored\n", nr
, di
, eaz
);
2383 return (wret
== 2) ? 5 : 0;
2387 * Search list of net-interfaces for an interface with given name.
2390 isdn_net_findif(char *name
)
2392 isdn_net_dev
*p
= dev
->netdev
;
2395 if (!strcmp(p
->dev
->name
, name
))
2397 p
= (isdn_net_dev
*) p
->next
;
2399 return (isdn_net_dev
*) NULL
;
2403 * Force a net-interface to dial out.
2404 * This is called from the userlevel-routine below or
2405 * from isdn_net_start_xmit().
2408 isdn_net_force_dial_lp(isdn_net_local
*lp
)
2410 if ((!(lp
->flags
& ISDN_NET_CONNECTED
)) && !lp
->dialstate
) {
2415 /* Grab a free ISDN-Channel */
2416 spin_lock_irqsave(&dev
->lock
, flags
);
2417 if ((chi
= isdn_get_free_channel(
2424 printk(KERN_WARNING
"isdn_net_force_dial: No channel for %s\n",
2425 lp
->netdev
->dev
->name
);
2426 spin_unlock_irqrestore(&dev
->lock
, flags
);
2430 /* Connect interface with channel */
2431 isdn_net_bind_channel(lp
, chi
);
2432 #ifdef CONFIG_ISDN_PPP
2433 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2434 if (isdn_ppp_bind(lp
) < 0) {
2435 isdn_net_unbind_channel(lp
);
2436 spin_unlock_irqrestore(&dev
->lock
, flags
);
2440 /* Initiate dialing */
2441 spin_unlock_irqrestore(&dev
->lock
, flags
);
2451 * This is called from certain upper protocol layers (multilink ppp
2452 * and x25iface encapsulation module) that want to initiate dialing
2456 isdn_net_dial_req(isdn_net_local
*lp
)
2458 /* is there a better error code? */
2459 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) return -EBUSY
;
2461 return isdn_net_force_dial_lp(lp
);
2465 * Force a net-interface to dial out.
2466 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2469 isdn_net_force_dial(char *name
)
2471 isdn_net_dev
*p
= isdn_net_findif(name
);
2475 return (isdn_net_force_dial_lp(p
->local
));
2478 /* The ISDN-specific entries in the device structure. */
2479 static const struct net_device_ops isdn_netdev_ops
= {
2480 .ndo_init
= isdn_net_init
,
2481 .ndo_open
= isdn_net_open
,
2482 .ndo_stop
= isdn_net_close
,
2483 .ndo_do_ioctl
= isdn_net_ioctl
,
2485 .ndo_start_xmit
= isdn_net_start_xmit
,
2486 .ndo_get_stats
= isdn_net_get_stats
,
2487 .ndo_tx_timeout
= isdn_net_tx_timeout
,
2491 * Helper for alloc_netdev()
2493 static void _isdn_setup(struct net_device
*dev
)
2495 isdn_net_local
*lp
= netdev_priv(dev
);
2499 /* Setup the generic properties */
2500 dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
2502 /* isdn prepends a header in the tx path, can't share skbs */
2503 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
2504 dev
->header_ops
= NULL
;
2505 dev
->netdev_ops
= &isdn_netdev_ops
;
2507 /* for clients with MPPP maybe higher values better */
2508 dev
->tx_queue_len
= 30;
2510 lp
->p_encap
= ISDN_NET_ENCAP_RAWIP
;
2511 lp
->magic
= ISDN_NET_MAGIC
;
2514 lp
->isdn_device
= -1;
2515 lp
->isdn_channel
= -1;
2516 lp
->pre_device
= -1;
2517 lp
->pre_channel
= -1;
2521 skb_queue_head_init(&lp
->super_tx_queue
);
2522 lp
->l2_proto
= ISDN_PROTO_L2_X75I
;
2523 lp
->l3_proto
= ISDN_PROTO_L3_TRANS
;
2524 lp
->triggercps
= 6000;
2525 lp
->slavedelay
= 10 * HZ
;
2526 lp
->hupflags
= ISDN_INHUP
; /* Do hangup even on incoming calls */
2527 lp
->onhtime
= 10; /* Default hangup-time for saving costs */
2529 /* Hangup before Callback, manual dial */
2530 lp
->flags
= ISDN_NET_CBHUP
| ISDN_NET_DM_MANUAL
;
2531 lp
->cbdelay
= 25; /* Wait 5 secs before Callback */
2532 lp
->dialtimeout
= -1; /* Infinite Dial-Timeout */
2533 lp
->dialwait
= 5 * HZ
; /* Wait 5 sec. after failed dial */
2534 lp
->dialstarted
= 0; /* Jiffies of last dial-start */
2535 lp
->dialwait_timer
= 0; /* Jiffies of earliest next dial-start */
2539 * Allocate a new network-interface and initialize its data structures.
2542 isdn_net_new(char *name
, struct net_device
*master
)
2544 isdn_net_dev
*netdev
;
2546 /* Avoid creating an existing interface */
2547 if (isdn_net_findif(name
)) {
2548 printk(KERN_WARNING
"isdn_net: interface %s already exists\n", name
);
2553 if (!(netdev
= kzalloc(sizeof(isdn_net_dev
), GFP_KERNEL
))) {
2554 printk(KERN_WARNING
"isdn_net: Could not allocate net-device\n");
2557 netdev
->dev
= alloc_netdev(sizeof(isdn_net_local
), name
,
2558 NET_NAME_UNKNOWN
, _isdn_setup
);
2560 printk(KERN_WARNING
"isdn_net: Could not allocate network device\n");
2564 netdev
->local
= netdev_priv(netdev
->dev
);
2567 /* Device shall be a slave */
2568 struct net_device
*p
= MASTER_TO_SLAVE(master
);
2569 struct net_device
*q
= master
;
2571 netdev
->local
->master
= master
;
2572 /* Put device at end of slave-chain */
2575 p
= MASTER_TO_SLAVE(p
);
2577 MASTER_TO_SLAVE(q
) = netdev
->dev
;
2579 /* Device shall be a master */
2581 * Watchdog timer (currently) for master only.
2583 netdev
->dev
->watchdog_timeo
= ISDN_NET_TX_TIMEOUT
;
2584 if (register_netdev(netdev
->dev
) != 0) {
2585 printk(KERN_WARNING
"isdn_net: Could not register net-device\n");
2586 free_netdev(netdev
->dev
);
2591 netdev
->queue
= netdev
->local
;
2592 spin_lock_init(&netdev
->queue_lock
);
2594 netdev
->local
->netdev
= netdev
;
2596 INIT_WORK(&netdev
->local
->tqueue
, isdn_net_softint
);
2597 spin_lock_init(&netdev
->local
->xmit_lock
);
2599 /* Put into to netdev-chain */
2600 netdev
->next
= (void *) dev
->netdev
;
2601 dev
->netdev
= netdev
;
2602 return netdev
->dev
->name
;
2606 isdn_net_newslave(char *parm
)
2608 char *p
= strchr(parm
, ',');
2613 /* Slave-Name MUST not be empty or overflow 'newname' */
2614 if (strscpy(newname
, p
+ 1, sizeof(newname
)) <= 0)
2617 /* Master must already exist */
2618 if (!(n
= isdn_net_findif(parm
)))
2620 /* Master must be a real interface, not a slave */
2621 if (n
->local
->master
)
2623 /* Master must not be started yet */
2624 if (isdn_net_device_started(n
))
2626 return (isdn_net_new(newname
, n
->dev
));
2632 * Set interface-parameters.
2633 * Always set all parameters, so the user-level application is responsible
2634 * for not overwriting existing setups. It has to get the current
2635 * setup first, if only selected parameters are to be changed.
2638 isdn_net_setcfg(isdn_net_ioctl_cfg
*cfg
)
2640 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2648 isdn_net_local
*lp
= p
->local
;
2650 /* See if any registered driver supports the features we want */
2651 features
= ((1 << cfg
->l2_proto
) << ISDN_FEATURE_L2_SHIFT
) |
2652 ((1 << cfg
->l3_proto
) << ISDN_FEATURE_L3_SHIFT
);
2653 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2655 if ((dev
->drv
[i
]->interface
->features
& features
) == features
)
2657 if (i
== ISDN_MAX_DRIVERS
) {
2658 printk(KERN_WARNING
"isdn_net: No driver with selected features\n");
2661 if (lp
->p_encap
!= cfg
->p_encap
) {
2662 #ifdef CONFIG_ISDN_X25
2663 struct concap_proto
*cprot
= p
->cprot
;
2665 if (isdn_net_device_started(p
)) {
2666 printk(KERN_WARNING
"%s: cannot change encap when if is up\n",
2670 #ifdef CONFIG_ISDN_X25
2671 if (cprot
&& cprot
->pops
)
2672 cprot
->pops
->proto_del(cprot
);
2675 /* ... , prepare for configuration of new one ... */
2676 switch (cfg
->p_encap
) {
2677 case ISDN_NET_ENCAP_X25IFACE
:
2678 lp
->dops
= &isdn_concap_reliable_dl_dops
;
2680 /* ... and allocate new one ... */
2681 p
->cprot
= isdn_concap_new(cfg
->p_encap
);
2682 /* p -> cprot == NULL now if p_encap is not supported
2683 by means of the concap_proto mechanism */
2684 /* the protocol is not configured yet; this will
2685 happen later when isdn_net_reset() is called */
2688 switch (cfg
->p_encap
) {
2689 case ISDN_NET_ENCAP_SYNCPPP
:
2690 #ifndef CONFIG_ISDN_PPP
2691 printk(KERN_WARNING
"%s: SyncPPP support not configured\n",
2695 p
->dev
->type
= ARPHRD_PPP
; /* change ARP type */
2696 p
->dev
->addr_len
= 0;
2699 case ISDN_NET_ENCAP_X25IFACE
:
2700 #ifndef CONFIG_ISDN_X25
2701 printk(KERN_WARNING
"%s: isdn-x25 support not configured\n",
2705 p
->dev
->type
= ARPHRD_X25
; /* change ARP type */
2706 p
->dev
->addr_len
= 0;
2709 case ISDN_NET_ENCAP_CISCOHDLCK
:
2712 if (cfg
->p_encap
>= 0 &&
2713 cfg
->p_encap
<= ISDN_NET_ENCAP_MAX_ENCAP
)
2716 "%s: encapsulation protocol %d not supported\n",
2717 p
->dev
->name
, cfg
->p_encap
);
2720 if (strlen(cfg
->drvid
)) {
2721 /* A bind has been requested ... */
2725 if (strnlen(cfg
->drvid
, sizeof(cfg
->drvid
)) ==
2730 strcpy(drvid
, cfg
->drvid
);
2731 if ((c
= strchr(drvid
, ','))) {
2732 /* The channel-number is appended to the driver-Id with a comma */
2733 chidx
= (int) simple_strtoul(c
+ 1, &e
, 10);
2738 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2739 /* Lookup driver-Id in array */
2740 if (!(strcmp(dev
->drvid
[i
], drvid
))) {
2744 if ((drvidx
== -1) || (chidx
== -1))
2745 /* Either driver-Id or channel-number invalid */
2748 /* Parameters are valid, so get them */
2749 drvidx
= lp
->pre_device
;
2750 chidx
= lp
->pre_channel
;
2752 if (cfg
->exclusive
> 0) {
2753 unsigned long flags
;
2755 /* If binding is exclusive, try to grab the channel */
2756 spin_lock_irqsave(&dev
->lock
, flags
);
2757 if ((i
= isdn_get_free_channel(ISDN_USAGE_NET
,
2758 lp
->l2_proto
, lp
->l3_proto
, drvidx
,
2759 chidx
, lp
->msn
)) < 0) {
2760 /* Grab failed, because desired channel is in use */
2762 spin_unlock_irqrestore(&dev
->lock
, flags
);
2765 /* All went ok, so update isdninfo */
2766 dev
->usage
[i
] = ISDN_USAGE_EXCLUSIVE
;
2768 spin_unlock_irqrestore(&dev
->lock
, flags
);
2771 /* Non-exclusive binding or unbind. */
2773 if ((lp
->pre_device
!= -1) && (cfg
->exclusive
== -1)) {
2774 isdn_unexclusive_channel(lp
->pre_device
, lp
->pre_channel
);
2775 isdn_free_channel(lp
->pre_device
, lp
->pre_channel
, ISDN_USAGE_NET
);
2780 strlcpy(lp
->msn
, cfg
->eaz
, sizeof(lp
->msn
));
2781 lp
->pre_device
= drvidx
;
2782 lp
->pre_channel
= chidx
;
2783 lp
->onhtime
= cfg
->onhtime
;
2784 lp
->charge
= cfg
->charge
;
2785 lp
->l2_proto
= cfg
->l2_proto
;
2786 lp
->l3_proto
= cfg
->l3_proto
;
2787 lp
->cbdelay
= cfg
->cbdelay
;
2788 lp
->dialmax
= cfg
->dialmax
;
2789 lp
->triggercps
= cfg
->triggercps
;
2790 lp
->slavedelay
= cfg
->slavedelay
* HZ
;
2791 lp
->pppbind
= cfg
->pppbind
;
2792 lp
->dialtimeout
= cfg
->dialtimeout
>= 0 ? cfg
->dialtimeout
* HZ
: -1;
2793 lp
->dialwait
= cfg
->dialwait
* HZ
;
2795 lp
->flags
|= ISDN_NET_SECURE
;
2797 lp
->flags
&= ~ISDN_NET_SECURE
;
2799 lp
->flags
|= ISDN_NET_CBHUP
;
2801 lp
->flags
&= ~ISDN_NET_CBHUP
;
2802 switch (cfg
->callback
) {
2804 lp
->flags
&= ~(ISDN_NET_CALLBACK
| ISDN_NET_CBOUT
);
2807 lp
->flags
|= ISDN_NET_CALLBACK
;
2808 lp
->flags
&= ~ISDN_NET_CBOUT
;
2811 lp
->flags
|= ISDN_NET_CBOUT
;
2812 lp
->flags
&= ~ISDN_NET_CALLBACK
;
2815 lp
->flags
&= ~ISDN_NET_DIALMODE_MASK
; /* first all bits off */
2816 if (cfg
->dialmode
&& !(cfg
->dialmode
& ISDN_NET_DIALMODE_MASK
)) {
2817 /* old isdnctrl version, where only 0 or 1 is given */
2819 "Old isdnctrl version detected! Please update.\n");
2820 lp
->flags
|= ISDN_NET_DM_OFF
; /* turn on `off' bit */
2823 lp
->flags
|= cfg
->dialmode
; /* turn on selected bits */
2826 lp
->hupflags
|= ISDN_CHARGEHUP
;
2828 lp
->hupflags
&= ~ISDN_CHARGEHUP
;
2830 lp
->hupflags
|= ISDN_INHUP
;
2832 lp
->hupflags
&= ~ISDN_INHUP
;
2833 if (cfg
->chargeint
> 10) {
2834 lp
->hupflags
|= ISDN_CHARGEHUP
| ISDN_HAVECHARGE
| ISDN_MANCHARGE
;
2835 lp
->chargeint
= cfg
->chargeint
* HZ
;
2837 if (cfg
->p_encap
!= lp
->p_encap
) {
2838 if (cfg
->p_encap
== ISDN_NET_ENCAP_RAWIP
) {
2839 p
->dev
->header_ops
= NULL
;
2840 p
->dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
2842 p
->dev
->header_ops
= &isdn_header_ops
;
2843 if (cfg
->p_encap
== ISDN_NET_ENCAP_ETHER
)
2844 p
->dev
->flags
= IFF_BROADCAST
| IFF_MULTICAST
;
2846 p
->dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
2849 lp
->p_encap
= cfg
->p_encap
;
2856 * Perform get-interface-parameters.ioctl
2859 isdn_net_getcfg(isdn_net_ioctl_cfg
*cfg
)
2861 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2864 isdn_net_local
*lp
= p
->local
;
2866 strcpy(cfg
->eaz
, lp
->msn
);
2867 cfg
->exclusive
= lp
->exclusive
;
2868 if (lp
->pre_device
>= 0) {
2869 sprintf(cfg
->drvid
, "%s,%d", dev
->drvid
[lp
->pre_device
],
2872 cfg
->drvid
[0] = '\0';
2873 cfg
->onhtime
= lp
->onhtime
;
2874 cfg
->charge
= lp
->charge
;
2875 cfg
->l2_proto
= lp
->l2_proto
;
2876 cfg
->l3_proto
= lp
->l3_proto
;
2877 cfg
->p_encap
= lp
->p_encap
;
2878 cfg
->secure
= (lp
->flags
& ISDN_NET_SECURE
) ? 1 : 0;
2880 if (lp
->flags
& ISDN_NET_CALLBACK
)
2882 if (lp
->flags
& ISDN_NET_CBOUT
)
2884 cfg
->cbhup
= (lp
->flags
& ISDN_NET_CBHUP
) ? 1 : 0;
2885 cfg
->dialmode
= lp
->flags
& ISDN_NET_DIALMODE_MASK
;
2886 cfg
->chargehup
= (lp
->hupflags
& ISDN_CHARGEHUP
) ? 1 : 0;
2887 cfg
->ihup
= (lp
->hupflags
& ISDN_INHUP
) ? 1 : 0;
2888 cfg
->cbdelay
= lp
->cbdelay
;
2889 cfg
->dialmax
= lp
->dialmax
;
2890 cfg
->triggercps
= lp
->triggercps
;
2891 cfg
->slavedelay
= lp
->slavedelay
/ HZ
;
2892 cfg
->chargeint
= (lp
->hupflags
& ISDN_CHARGEHUP
) ?
2893 (lp
->chargeint
/ HZ
) : 0;
2894 cfg
->pppbind
= lp
->pppbind
;
2895 cfg
->dialtimeout
= lp
->dialtimeout
>= 0 ? lp
->dialtimeout
/ HZ
: -1;
2896 cfg
->dialwait
= lp
->dialwait
/ HZ
;
2898 if (strlen(lp
->slave
->name
) >= 10)
2899 strcpy(cfg
->slave
, "too-long");
2901 strcpy(cfg
->slave
, lp
->slave
->name
);
2903 cfg
->slave
[0] = '\0';
2905 if (strlen(lp
->master
->name
) >= 10)
2906 strcpy(cfg
->master
, "too-long");
2908 strcpy(cfg
->master
, lp
->master
->name
);
2910 cfg
->master
[0] = '\0';
2917 * Add a phone-number to an interface.
2920 isdn_net_addphone(isdn_net_ioctl_phone
*phone
)
2922 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2926 if (!(n
= kmalloc(sizeof(isdn_net_phone
), GFP_KERNEL
)))
2928 strlcpy(n
->num
, phone
->phone
, sizeof(n
->num
));
2929 n
->next
= p
->local
->phone
[phone
->outgoing
& 1];
2930 p
->local
->phone
[phone
->outgoing
& 1] = n
;
2937 * Copy a string of all phone-numbers of an interface to user space.
2938 * This might sleep and must be called with the isdn semaphore down.
2941 isdn_net_getphones(isdn_net_ioctl_phone
*phone
, char __user
*phones
)
2943 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2944 int inout
= phone
->outgoing
& 1;
2952 for (n
= p
->local
->phone
[inout
]; n
; n
= n
->next
) {
2954 put_user(' ', phones
++);
2957 if (copy_to_user(phones
, n
->num
, strlen(n
->num
) + 1)) {
2960 phones
+= strlen(n
->num
);
2961 count
+= strlen(n
->num
);
2964 put_user(0, phones
);
2970 * Copy a string containing the peer's phone number of a connected interface
2974 isdn_net_getpeer(isdn_net_ioctl_phone
*phone
, isdn_net_ioctl_phone __user
*peer
)
2976 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2982 * Theoretical race: while this executes, the remote number might
2983 * become invalid (hang up) or change (new connection), resulting
2984 * in (partially) wrong number copied to user. This race
2985 * currently ignored.
2987 ch
= p
->local
->isdn_channel
;
2988 dv
= p
->local
->isdn_device
;
2989 if (ch
< 0 && dv
< 0)
2991 idx
= isdn_dc2minor(dv
, ch
);
2994 /* for pre-bound channels, we need this extra check */
2995 if (strncmp(dev
->num
[idx
], "???", 3) == 0)
2997 strncpy(phone
->phone
, dev
->num
[idx
], ISDN_MSNLEN
);
2998 phone
->outgoing
= USG_OUTGOING(dev
->usage
[idx
]);
2999 if (copy_to_user(peer
, phone
, sizeof(*peer
)))
3004 * Delete a phone-number from an interface.
3007 isdn_net_delphone(isdn_net_ioctl_phone
*phone
)
3009 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
3010 int inout
= phone
->outgoing
& 1;
3015 n
= p
->local
->phone
[inout
];
3018 if (!strcmp(n
->num
, phone
->phone
)) {
3019 if (p
->local
->dial
== n
)
3020 p
->local
->dial
= n
->next
;
3024 p
->local
->phone
[inout
] = n
->next
;
3029 n
= (isdn_net_phone
*) n
->next
;
3037 * Delete all phone-numbers of an interface.
3040 isdn_net_rmallphone(isdn_net_dev
*p
)
3046 for (i
= 0; i
< 2; i
++) {
3047 n
= p
->local
->phone
[i
];
3053 p
->local
->phone
[i
] = NULL
;
3055 p
->local
->dial
= NULL
;
3060 * Force a hangup of a network-interface.
3063 isdn_net_force_hangup(char *name
)
3065 isdn_net_dev
*p
= isdn_net_findif(name
);
3066 struct net_device
*q
;
3069 if (p
->local
->isdn_device
< 0)
3071 q
= p
->local
->slave
;
3072 /* If this interface has slaves, do a hangup for them also. */
3075 q
= MASTER_TO_SLAVE(q
);
3077 isdn_net_hangup(p
->dev
);
3084 * Helper-function for isdn_net_rm: Do the real work.
3087 isdn_net_realrm(isdn_net_dev
*p
, isdn_net_dev
*q
)
3091 if (isdn_net_device_started(p
)) {
3094 #ifdef CONFIG_ISDN_X25
3095 if (p
->cprot
&& p
->cprot
->pops
)
3096 p
->cprot
->pops
->proto_del(p
->cprot
);
3098 /* Free all phone-entries */
3099 isdn_net_rmallphone(p
);
3100 /* If interface is bound exclusive, free channel-usage */
3101 if (p
->local
->exclusive
!= -1)
3102 isdn_unexclusive_channel(p
->local
->pre_device
, p
->local
->pre_channel
);
3103 if (p
->local
->master
) {
3104 /* It's a slave-device, so update master's slave-pointer if necessary */
3105 if (((isdn_net_local
*) ISDN_MASTER_PRIV(p
->local
))->slave
==
3107 ((isdn_net_local
*)ISDN_MASTER_PRIV(p
->local
))->slave
=
3110 /* Unregister only if it's a master-device */
3111 unregister_netdev(p
->dev
);
3113 /* Unlink device from chain */
3114 spin_lock_irqsave(&dev
->lock
, flags
);
3118 dev
->netdev
= p
->next
;
3119 if (p
->local
->slave
) {
3120 /* If this interface has a slave, remove it also */
3121 char *slavename
= p
->local
->slave
->name
;
3122 isdn_net_dev
*n
= dev
->netdev
;
3125 if (!strcmp(n
->dev
->name
, slavename
)) {
3126 spin_unlock_irqrestore(&dev
->lock
, flags
);
3127 isdn_net_realrm(n
, q
);
3128 spin_lock_irqsave(&dev
->lock
, flags
);
3132 n
= (isdn_net_dev
*)n
->next
;
3135 spin_unlock_irqrestore(&dev
->lock
, flags
);
3136 /* If no more net-devices remain, disable auto-hangup timer */
3137 if (dev
->netdev
== NULL
)
3138 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3139 free_netdev(p
->dev
);
3146 * Remove a single network-interface.
3149 isdn_net_rm(char *name
)
3155 /* Search name in netdev-chain */
3156 spin_lock_irqsave(&dev
->lock
, flags
);
3160 if (!strcmp(p
->dev
->name
, name
)) {
3161 spin_unlock_irqrestore(&dev
->lock
, flags
);
3162 return (isdn_net_realrm(p
, q
));
3165 p
= (isdn_net_dev
*) p
->next
;
3167 spin_unlock_irqrestore(&dev
->lock
, flags
);
3168 /* If no more net-devices remain, disable auto-hangup timer */
3169 if (dev
->netdev
== NULL
)
3170 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3175 * Remove all network-interfaces
3178 isdn_net_rmall(void)
3183 /* Walk through netdev-chain */
3184 spin_lock_irqsave(&dev
->lock
, flags
);
3185 while (dev
->netdev
) {
3186 if (!dev
->netdev
->local
->master
) {
3187 /* Remove master-devices only, slaves get removed with their master */
3188 spin_unlock_irqrestore(&dev
->lock
, flags
);
3189 if ((ret
= isdn_net_realrm(dev
->netdev
, NULL
))) {
3192 spin_lock_irqsave(&dev
->lock
, flags
);
3196 spin_unlock_irqrestore(&dev
->lock
, flags
);