1 /* $Id: isdn_net.c,v 1.89 1999/08/22 20:26:03 calle Exp $
3 * Linux ISDN subsystem, network interfaces and related functions (linklevel).
5 * Copyright 1994-1998 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * $Log: isdn_net.c,v $
24 * Revision 1.89 1999/08/22 20:26:03 calle
25 * backported changes from kernel 2.3.14:
26 * - several #include "config.h" gone, others come.
27 * - "struct device" changed to "struct net_device" in 2.3.14, added a
28 * define in isdn_compat.h for older kernel versions.
30 * Revision 1.88 1999/07/07 10:13:31 detabc
31 * remove unused messages
33 * Revision 1.87 1999/07/06 07:53:53 calle
34 * calls to dev_alloc_skb waste 16 bytes of memory, if we calculate the
35 * right header space for the lowlevel driver. using alloc_skb instead.
37 * Revision 1.86 1999/06/09 10:12:05 paul
38 * thinko in previous patch
40 * Revision 1.85 1999/06/07 19:42:39 paul
41 * isdn_net_getpeer() fixed to return correct `outgoing' flag
43 * Revision 1.84 1999/04/18 14:06:55 fritz
44 * Removed TIMRU stuff.
46 * Revision 1.83 1999/04/12 12:33:23 fritz
47 * Changes from 2.0 tree.
49 * Revision 1.82 1999/01/17 00:55:58 he
50 * added mark_bh in BCONN statcallb and cleaned up some dead code
52 * Revision 1.81 1999/01/15 16:36:52 he
53 * replaced icmp_send() by dst_link_failure()
55 * Revision 1.80 1998/12/01 13:06:22 paul
56 * Also huptimeout with dialmode == manual
58 * Revision 1.79 1998/10/30 17:55:27 he
59 * dialmode for x25iface and multulink ppp
61 * Revision 1.78 1998/10/26 18:20:46 he
62 * re-inserted p=p->next in isdn_net_find_icall() (fixes kernel lock up
63 * on incoming call not matching the first interface)
65 * Revision 1.77 1998/10/23 10:18:44 paul
66 * Implementation of "dialmode" (successor of "status")
67 * You also need current isdnctrl for this!
69 * Revision 1.76 1998/09/07 22:00:05 he
70 * flush method for 2.1.118 and above
71 * updated IIOCTLNETGPN
73 * Revision 1.75 1998/08/31 21:09:50 he
74 * new ioctl IIOCNETGPN for /dev/isdninfo (get network interface'
77 * Revision 1.74 1998/07/30 11:28:32 paul
78 * printk message only appeared when status is off and interface is rawIP,
79 * which is confusing for people who don't know about "isdnctrl status <if> on".
81 * Revision 1.73 1998/06/26 22:01:37 keil
82 * tx_queue_len = 5 was too small
84 * Revision 1.72 1998/06/26 15:12:31 fritz
85 * Added handling of STAT_ICALL with incomplete CPN.
86 * Added AT&L for ttyI emulator.
87 * Added more locking stuff in tty_write.
89 * Revision 1.71 1998/06/18 22:43:08 fritz
90 * Bugfix: Setting ndev->do_ioctl had beed accidetly removed at cleanup.
92 * Revision 1.70 1998/06/17 19:50:49 he
93 * merged with 2.1.10[34] (cosmetics and udelay() -> mdelay())
94 * brute force fix to avoid Ugh's in isdn_tty_write()
95 * cleaned up some dead code
97 * Revision 1.69 1998/06/09 12:27:37 cal
98 * Changed default of local netdev flags: ISDN_NET_STOPPED is default now,
99 * so autodial is suppressed for that device until it is switched on using
100 * 'isdnctrl status dev-name on'.
104 * Revision 1.66 1998/05/26 22:39:24 he
105 * sync'ed with 2.1.102 where appropriate (CAPABILITY changes)
107 * cleared dev.tbusy in isdn_net BCONN status callback
109 * Revision 1.61 1998/04/16 19:19:42 keil
110 * Fix from vger (tx max qlength)
112 * Revision 1.60 1998/04/14 16:28:49 he
113 * Fixed user space access with interrupts off and remaining
114 * copy_{to,from}_user() -> -EFAULT return codes
116 * Revision 1.59 1998/03/07 22:37:33 fritz
117 * Bugfix: restore_flags missing.
119 * Revision 1.58 1998/03/07 18:21:05 cal
120 * Dynamic Timeout-Rule-Handling vs. 971110 included
122 * Revision 1.57 1998/02/25 18:31:13 fritz
123 * Added debugging output in adjust_header.
125 * Revision 1.56 1998/02/25 17:49:42 he
126 * Changed return codes caused be failing copy_{to,from}_user to -EFAULT
128 * Revision 1.55 1998/02/23 19:38:22 fritz
129 * Corrected check for modified feature-flags.
131 * Revision 1.54 1998/02/20 17:15:07 fritz
132 * Changes for recent kernels.
133 * Ugly workaround for adjusting Ethernet frames with recent kernels.
134 * replaced direct calls to lowlevel-driver command by common hook.
136 * Revision 1.53 1998/01/31 22:05:54 keil
137 * Lots of changes for X.25 support:
138 * Added generic support for connection-controlling encapsulation protocols
139 * Added support of BHUP status message
140 * Added support for additional p_encap X25IFACE
141 * Added support for kernels >= 2.1.72
143 * Revision 1.52 1998/01/31 19:29:51 calle
144 * Merged changes from and for 2.1.82, not tested only compiled ...
146 * Revision 1.51 1997/10/09 21:28:50 fritz
147 * New HL<->LL interface:
148 * New BSENT callback with nr. of bytes included.
149 * Sending without ACK.
150 * New L1 error status (not yet in use).
151 * Cleaned up obsolete structures.
152 * Implemented Cisco-SLARP.
153 * Changed local net-interface data to be dynamically allocated.
154 * Removed old 2.0 compatibility stuff.
156 * Revision 1.50 1997/10/01 09:20:32 fritz
157 * Removed old compatibility stuff for 2.0.X kernels.
158 * From now on, this code is for 2.1.X ONLY!
159 * Old stuff is still in the separate branch.
161 * Revision 1.49 1997/08/21 14:38:13 fritz
162 * Bugfix: Did not compile without SyncPPP.
164 * Revision 1.48 1997/06/22 11:57:15 fritz
165 * Added ability to adjust slave triggerlevel.
167 * Revision 1.47 1997/06/21 10:52:05 fritz
168 * Removed wrong SET_SKB_FREE in isdn_net_send_skb()
170 * Revision 1.46 1997/06/17 13:05:24 hipp
171 * Applied Eric's underflow-patches (slightly modified)
173 * Revision 1.45 1997/06/10 16:24:22 hipp
174 * hard_header changes for syncPPP (now behaves like RAWIP)
176 * Revision 1.44 1997/05/27 15:17:26 fritz
177 * Added changes for recent 2.1.x kernels:
178 * changed return type of isdn_close
179 * queue_task_* -> queue_task
180 * clear/set_bit -> test_and_... where apropriate.
181 * changed type of hard_header_cache parameter.
183 * Revision 1.43 1997/03/30 16:51:13 calle
184 * changed calls to copy_from_user/copy_to_user and removed verify_area
187 * Revision 1.42 1997/03/11 08:43:51 fritz
188 * Perform a hangup if number is deleted while dialing.
190 * Revision 1.41 1997/03/08 08:16:31 fritz
191 * Bugfix: Deleting a phone number during dial gave unpredictable results.
193 * Revision 1.40 1997/03/05 21:16:08 fritz
194 * Fix: did not compile with 2.1.27
196 * Revision 1.39 1997/03/04 21:36:52 fritz
197 * Added sending ICMP messages when no connetion is possible.
199 * Revision 1.38 1997/02/23 23:41:14 fritz
200 * Bugfix: Slave interfaces have to be hung up before master.
202 * Revision 1.37 1997/02/11 18:32:51 fritz
203 * Bugfix in isdn_ppp_free_mpqueue().
205 * Revision 1.36 1997/02/10 21:31:11 fritz
206 * Changed setup-interface (incoming and outgoing).
208 * Revision 1.35 1997/02/10 20:12:45 fritz
209 * Changed interface for reporting incoming calls.
211 * Revision 1.34 1997/02/03 23:15:07 fritz
212 * Reformatted according CodingStyle.
213 * replaced arp_find prototype by proper include.
214 * made dev_purge_queues static.
215 * Bugfix in bogocps calculation.
216 * removed isdn_net_receive_callback - was never used ;-)
217 * Misc. fixes for Kernel 2.1.X comaptibility.
219 * Revision 1.33 1997/01/17 01:19:25 fritz
220 * Applied chargeint patch.
222 * Revision 1.32 1997/01/14 01:29:31 fritz
223 * Bugfix: isdn_net_hangup() did not reset ISDN_NET_CONNECTED.
225 * Revision 1.31 1997/01/11 23:30:42 fritz
226 * Speed up dial statemachine.
228 * Revision 1.30 1996/11/25 17:20:50 hipp
229 * fixed pppbind bug in isdn_net_find_icall()
231 * Revision 1.29 1996/11/13 02:31:38 fritz
234 * Revision 1.28 1996/10/27 20:49:06 keil
235 * bugfix to compile without MPP
237 * Revision 1.27 1996/10/25 18:46:01 fritz
238 * Another bugfix in isdn_net_autohup()
240 * Revision 1.26 1996/10/23 23:05:36 fritz
241 * Bugfix: Divide by zero in isdn_net_autohup()
243 * Revision 1.25 1996/10/22 23:13:58 fritz
244 * Changes for compatibility to 2.0.X and 2.1.X kernels.
246 * Revision 1.24 1996/10/11 13:57:40 fritz
247 * Bugfix: Error in BogoCPS calculation.
249 * Revision 1.23 1996/09/23 01:58:08 fritz
250 * Fix: With syncPPP encapsulation, discard LCP packets
251 * when calculating hangup timeout.
253 * Revision 1.22 1996/09/23 00:03:37 fritz
254 * Fix: did not compile without CONFIG_ISDN_PPP
256 * Revision 1.21 1996/09/07 12:44:50 hipp
257 * (hopefully) fixed callback problem with syncPPP
258 * syncPPP network devices now show PPP link encap
260 * Revision 1.20 1996/08/29 20:06:03 fritz
261 * Bugfix: Transmission timeout had been much to low.
263 * Revision 1.19 1996/08/12 16:24:32 hipp
264 * removed some (now) obsolete functions for syncPPP in rebuild_header etc.
266 * Revision 1.18 1996/07/03 13:48:51 hipp
267 * bugfix: Call dev_purge_queues() only for master device
269 * Revision 1.17 1996/06/25 18:37:37 fritz
270 * Fixed return count for empty return string in isdn_net_getphones().
272 * Revision 1.16 1996/06/24 17:48:08 fritz
274 * - Did not free channel on unbinding.
275 * - ioctl returned wrong callback settings.
277 * Revision 1.15 1996/06/16 17:42:54 tsbogend
278 * fixed problem with IP addresses on Linux/Alpha (long is 8 byte there)
280 * Revision 1.14 1996/06/11 14:54:08 hipp
281 * minor bugfix in isdn_net_send_skb
282 * changes in BSENT callback handler for syncPPP
283 * added lp->sav_skb stuff
285 * Revision 1.13 1996/06/06 14:25:44 fritz
286 * Changed loglevel of "incoming ... without OAD" message, since
287 * with audio support this is quite normal.
289 * Revision 1.12 1996/06/05 02:36:45 fritz
290 * Minor bugfixes by M. Hipp.
292 * Revision 1.11 1996/05/18 01:36:59 fritz
293 * Added spelling corrections and some minor changes
294 * to stay in sync with kernel.
296 * Revision 1.10 1996/05/17 03:49:01 fritz
299 * Revision 1.9 1996/05/06 11:34:57 hipp
302 * Revision 1.8 1996/04/30 21:04:40 fritz
305 * Revision 1.7 1996/04/30 11:10:42 fritz
306 * Added Michael's ippp-bind patch.
308 * Revision 1.6 1996/04/30 09:34:35 fritz
309 * Removed compatibility-macros.
311 * Revision 1.5 1996/04/20 16:28:38 fritz
312 * Made more parameters of the dial statemachine user-configurable and
313 * added hangup after dial for more reliability using callback.
314 * Changed all io going through generic routines in isdn_common.c
315 * Added missing call to dev_free_skb on failed dialing.
316 * Added uihdlc encapsulation.
317 * Fixed isdn_net_setcfg not to destroy interface-flags anymore.
320 * Revision 1.4 1996/02/19 15:23:38 fritz
321 * Bugfix: Sync-PPP packets got compressed twice, when resent due to
322 * send-queue-full reject.
324 * Revision 1.3 1996/02/11 02:22:28 fritz
325 * Changed status- receive-callbacks to use pointer-arrays for finding
326 * a corresponding interface instead of looping over all interfaces.
327 * Activate Auto-hangup-timer only when interface is online.
328 * Some bugfixes in the dialing-statemachine.
329 * Lot of bugfixes in sk_buff'ized encapsulation handling.
330 * For speedup connection-setup after dialing, remember sk_buf that triggered
332 * Fixed isdn_net_log_packet according to different encapsulations.
333 * Correct ARP-handling for ETHERNET-encapsulation.
335 * Revision 1.2 1996/01/22 05:05:12 fritz
336 * Changed returncode-logic for isdn_net_start_xmit() and its
338 * Changed handling of buildheader for RAWIP and ETHERNET-encapsulation.
340 * Revision 1.1 1996/01/09 04:12:34 fritz
345 #include <linux/config.h>
346 #define __NO_VERSION__
347 #include <linux/module.h>
348 #include <linux/isdn.h>
351 #include <net/pkt_sched.h>
352 #include <linux/inetdevice.h>
353 #include "isdn_common.h"
354 #include "isdn_net.h"
355 #ifdef CONFIG_ISDN_PPP
356 #include "isdn_ppp.h"
358 #ifdef CONFIG_ISDN_X25
359 #include <linux/concap.h>
360 #include "isdn_concap.h"
365 int isdn_net_force_dial_lp(isdn_net_local
*);
366 static int isdn_net_start_xmit(struct sk_buff
*, struct net_device
*);
367 static int isdn_net_xmit(struct net_device
*, isdn_net_local
*, struct sk_buff
*);
369 char *isdn_net_revision
= "$Revision: 1.89 $";
372 * Code for raw-networking over ISDN
376 isdn_net_unreachable(struct net_device
*dev
, struct sk_buff
*skb
, char *reason
)
381 u_short proto
= ntohs(skb
->protocol
);
383 printk(KERN_DEBUG
"isdn_net: %s: %s, signalling dst_link_failure %s\n",
385 (reason
!= NULL
) ? reason
: "unknown",
386 (proto
!= ETH_P_IP
) ? "Protocol != ETH_P_IP" : "");
388 dst_link_failure(skb
);
390 else { /* dial not triggered by rawIP packet */
391 printk(KERN_DEBUG
"isdn_net: %s: %s\n",
393 (reason
!= NULL
) ? reason
: "reason unknown");
398 isdn_net_reset(struct net_device
*dev
)
400 #ifdef CONFIG_ISDN_X25
401 struct concap_device_ops
* dops
=
402 ( (isdn_net_local
*) dev
->priv
) -> dops
;
403 struct concap_proto
* cprot
=
404 ( (isdn_net_local
*) dev
->priv
) -> netdev
-> cprot
;
409 cli(); /* Avoid glitch on writes to CMD regs */
412 #ifdef CONFIG_ISDN_X25
413 if( cprot
&& cprot
-> pops
&& dops
)
414 cprot
-> pops
-> restart ( cprot
, dev
, dops
);
416 restore_flags(flags
);
419 /* Open/initialize the board. */
421 isdn_net_open(struct net_device
*dev
)
424 struct net_device
*p
;
425 struct in_device
*in_dev
;
429 /* Fill in the MAC-level header (not needed, but for compatibility... */
430 for (i
= 0; i
< ETH_ALEN
- sizeof(u32
); i
++)
431 dev
->dev_addr
[i
] = 0xfc;
432 if ((in_dev
= dev
->ip_ptr
) != NULL
) {
434 * Any address will do - we take the first
436 struct in_ifaddr
*ifa
= in_dev
->ifa_list
;
438 memcpy(dev
->dev_addr
+2, &ifa
->ifa_local
, 4);
441 /* If this interface has slaves, start them also */
443 if ((p
= (((isdn_net_local
*) dev
->priv
)->slave
))) {
447 p
= (((isdn_net_local
*) p
->priv
)->slave
);
450 isdn_MOD_INC_USE_COUNT();
455 * Assign an ISDN-channel to a net-interface
458 isdn_net_bind_channel(isdn_net_local
* lp
, int idx
)
464 lp
->flags
|= ISDN_NET_CONNECTED
;
465 lp
->isdn_device
= dev
->drvmap
[idx
];
466 lp
->isdn_channel
= dev
->chanmap
[idx
];
467 dev
->rx_netdev
[idx
] = lp
->netdev
;
468 dev
->st_netdev
[idx
] = lp
->netdev
;
469 restore_flags(flags
);
473 * unbind a net-interface (resets interface after an error)
476 isdn_net_unbind_channel(isdn_net_local
* lp
)
483 dev_kfree_skb(lp
->first_skb
);
484 lp
->first_skb
= NULL
;
487 dev_kfree_skb(lp
->sav_skb
);
490 if (!lp
->master
) { /* reset only master device */
491 /* Moral equivalent of dev_purge_queues():
492 BEWARE! This chunk of code cannot be called from hardware
493 interrupt handler. I hope it is true. --ANK
495 qdisc_reset(lp
->netdev
->dev
.qdisc
);
498 dev
->rx_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
499 dev
->st_netdev
[isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
)] = NULL
;
500 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
, ISDN_USAGE_NET
);
501 lp
->flags
&= ~ISDN_NET_CONNECTED
;
502 lp
->isdn_device
= -1;
503 lp
->isdn_channel
= -1;
505 restore_flags(flags
);
509 * Perform auto-hangup and cps-calculation for net-interfaces.
512 * Increment idle-counter (this counter is reset on any incoming or
513 * outgoing packet), if counter exceeds configured limit either do a
514 * hangup immediately or - if configured - wait until just before the next
517 * cps-calculation (needed for dynamic channel-bundling):
518 * Since this function is called every second, simply reset the
519 * byte-counter of the interface after copying it to the cps-variable.
521 unsigned long last_jiffies
= -HZ
;
526 isdn_net_dev
*p
= dev
->netdev
;
531 isdn_net_local
*l
= p
->local
;
532 if ((jiffies
- last_jiffies
) == 0)
533 l
->cps
= l
->transcount
;
535 l
->cps
= (l
->transcount
* HZ
) / (jiffies
- last_jiffies
);
537 if (dev
->net_verbose
> 3)
538 printk(KERN_DEBUG
"%s: %d bogocps\n", l
->name
, l
->cps
);
539 if ((l
->flags
& ISDN_NET_CONNECTED
) && (!l
->dialstate
)) {
543 * if there is some dialmode where timeout-hangup
544 * should _not_ be done, check for that here
547 (l
->huptimer
> l
->onhtime
))
549 if (l
->hupflags
& ISDN_MANCHARGE
&&
550 l
->hupflags
& ISDN_CHARGEHUP
) {
551 while (jiffies
- l
->chargetime
> l
->chargeint
)
552 l
->chargetime
+= l
->chargeint
;
553 if (jiffies
- l
->chargetime
>= l
->chargeint
- 2 * HZ
)
554 if (l
->outgoing
|| l
->hupflags
& ISDN_INHUP
)
555 isdn_net_hangup(&p
->dev
);
556 } else if (l
->outgoing
) {
557 if (l
->hupflags
& ISDN_CHARGEHUP
) {
558 if (l
->hupflags
& ISDN_WAITCHARGE
) {
559 printk(KERN_DEBUG
"isdn_net: Hupflags of %s are %X\n",
560 l
->name
, l
->hupflags
);
561 isdn_net_hangup(&p
->dev
);
562 } else if (jiffies
- l
->chargetime
> l
->chargeint
) {
564 "isdn_net: %s: chtime = %d, chint = %d\n",
565 l
->name
, l
->chargetime
, l
->chargeint
);
566 isdn_net_hangup(&p
->dev
);
569 isdn_net_hangup(&p
->dev
);
570 } else if (l
->hupflags
& ISDN_INHUP
)
571 isdn_net_hangup(&p
->dev
);
574 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*l
) == ISDN_NET_DM_OFF
)) {
575 isdn_net_hangup(&p
->dev
);
579 p
= (isdn_net_dev
*) p
->next
;
581 last_jiffies
= jiffies
;
582 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, anymore
);
586 * Handle status-messages from ISDN-interfacecard.
587 * This function is called from within the main-status-dispatcher
588 * isdn_status_callback, which itself is called from the low-level driver.
589 * Return: 1 = Event handled, 0 = not for us or unknown Event.
592 isdn_net_stat_callback(int idx
, isdn_ctrl
*c
)
594 isdn_net_dev
*p
= dev
->st_netdev
[idx
];
595 int cmd
= c
->command
;
598 isdn_net_local
*lp
= p
->local
;
599 #ifdef CONFIG_ISDN_X25
600 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
601 struct concap_proto_ops
*pops
= cprot
? cprot
-> pops
: 0;
604 case ISDN_STAT_BSENT
:
605 /* A packet has successfully been sent out */
606 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
608 lp
->stats
.tx_packets
++;
609 lp
->stats
.tx_bytes
+= c
->parm
.length
;
610 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
&& lp
->sav_skb
) {
611 struct net_device
*mdev
;
615 mdev
= &lp
->netdev
->dev
;
616 if (!isdn_net_send_skb(mdev
, lp
, lp
->sav_skb
)) {
623 if (test_and_clear_bit(0, (void *) &(p
->dev
.tbusy
)))
627 case ISDN_STAT_DCONN
:
628 /* D-Channel is up */
629 switch (lp
->dialstate
) {
641 /* Either D-Channel-hangup or error during dialout */
642 #ifdef CONFIG_ISDN_X25
643 /* If we are not connencted then dialing had
644 failed. If there are generic encap protocol
645 receiver routines signal the closure of
648 if( !(lp
->flags
& ISDN_NET_CONNECTED
)
649 && pops
&& pops
-> disconn_ind
)
650 pops
-> disconn_ind(cprot
);
651 #endif /* CONFIG_ISDN_X25 */
652 if ((!lp
->dialstate
) && (lp
->flags
& ISDN_NET_CONNECTED
)) {
653 #ifdef CONFIG_ISDN_PPP
656 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
657 printk(KERN_INFO
"%s: remote hangup\n", lp
->name
);
658 printk(KERN_INFO
"%s: Chargesum is %d\n", lp
->name
,
660 isdn_net_unbind_channel(lp
);
664 #ifdef CONFIG_ISDN_X25
666 /* B-Channel-hangup */
667 /* try if there are generic encap protocol
668 receiver routines and signal the closure of
670 if( pops
&& pops
-> disconn_ind
){
671 pops
-> disconn_ind(cprot
);
675 #endif /* CONFIG_ISDN_X25 */
676 case ISDN_STAT_BCONN
:
677 /* B-Channel is up */
678 switch (lp
->dialstate
) {
686 if (lp
->dialstate
<= 6) {
687 dev
->usage
[idx
] |= ISDN_USAGE_OUTGOING
;
690 dev
->rx_netdev
[idx
] = p
;
692 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 1);
693 if (lp
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
)
694 isdn_timer_ctrl(ISDN_TIMER_KEEPALIVE
, 1);
695 printk(KERN_INFO
"isdn_net: %s connected\n", lp
->name
);
696 /* If first Chargeinfo comes before B-Channel connect,
697 * we correct the timestamp here.
699 lp
->chargetime
= jiffies
;
700 printk(KERN_DEBUG
"isdn_net: chargetime of %s now %d\n",
701 lp
->name
, lp
->chargetime
);
703 /* reset dial-timeout */
705 lp
->dialwait_timer
= 0;
707 /* Immediately send first skb to speed up arp */
708 #ifdef CONFIG_ISDN_PPP
709 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
710 isdn_ppp_wakeup_daemon(lp
);
712 #ifdef CONFIG_ISDN_X25
713 /* try if there are generic concap receiver routines */
715 if( pops
->connect_ind
)
716 pops
->connect_ind(cprot
);
717 #endif /* CONFIG_ISDN_X25 */
720 if (!(isdn_net_xmit(&p
->dev
, lp
, lp
->first_skb
)))
721 lp
->first_skb
= NULL
;
725 * dev.tbusy is usually cleared implicitly by isdn_net_xmit(,,lp->first_skb).
726 * With an empty lp->first_skb, we need to do this ourselves
728 lp
->netdev
->dev
.tbusy
= 0;
734 case ISDN_STAT_NODCH
:
735 /* No D-Channel avail. */
736 if (lp
->dialstate
== 4) {
742 /* Charge-info from TelCo. Calculate interval between
743 * charge-infos and set timestamp for last info for
744 * usage by isdn_net_autohup()
747 if (lp
->hupflags
& ISDN_HAVECHARGE
) {
748 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
749 lp
->chargeint
= jiffies
- lp
->chargetime
- (2 * HZ
);
751 if (lp
->hupflags
& ISDN_WAITCHARGE
)
752 lp
->hupflags
|= ISDN_HAVECHARGE
;
753 lp
->chargetime
= jiffies
;
754 printk(KERN_DEBUG
"isdn_net: Got CINF chargetime of %s now %d\n",
755 lp
->name
, lp
->chargetime
);
763 * Check, if a number contains wildcard-characters, in which case it
764 * is for incoming purposes only.
767 isdn_net_checkwild(char *num
)
769 return ((strchr(num
, '?')) ||
770 (strchr(num
, '*')) ||
771 (strchr(num
, '[')) ||
772 (strchr(num
, ']')) ||
777 * Perform dialout for net-interfaces and timeout-handling for
778 * D-Channel-up and B-Channel-up Messages.
779 * This function is initially called from within isdn_net_start_xmit() or
780 * or isdn_net_find_icall() after initializing the dialstate for an
781 * interface. If further calls are needed, the function schedules itself
782 * for a timer-callback via isdn_timer_function().
783 * The dialstate is also affected by incoming status-messages from
784 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
789 isdn_net_dev
*p
= dev
->netdev
;
796 isdn_net_local
*lp
= p
->local
;
798 #ifdef ISDN_DEBUG_NET_DIAL
800 printk(KERN_DEBUG
"%s: dialstate=%d\n", lp
->name
, lp
->dialstate
);
802 switch (lp
->dialstate
) {
804 /* Nothing to do for this interface */
807 /* Initiate dialout. Set phone-number-pointer to first number
812 lp
->dial
= lp
->phone
[1];
813 restore_flags(flags
);
815 printk(KERN_WARNING
"%s: phone number deleted?\n",
817 isdn_net_hangup(&p
->dev
);
822 if(lp
->dialtimeout
> 0)
823 if(lp
->dialstarted
== 0 || jiffies
> (lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
)) {
824 lp
->dialstarted
= jiffies
;
825 lp
->dialwait_timer
= 0;
831 /* Prepare dialing. Clear EAZ, then set EAZ. */
832 cmd
.driver
= lp
->isdn_device
;
833 cmd
.arg
= lp
->isdn_channel
;
834 cmd
.command
= ISDN_CMD_CLREAZ
;
836 sprintf(cmd
.parm
.num
, "%s", isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
837 cmd
.command
= ISDN_CMD_SETEAZ
;
844 /* Setup interface, dial current phone-number, switch to next number.
845 * If list of phone-numbers is exhausted, increment
848 if(dev
->global_flags
& ISDN_GLOBAL_STOPPED
|| (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
)) {
850 if (dev
->global_flags
& ISDN_GLOBAL_STOPPED
)
851 s
= "dial suppressed: isdn system stopped";
853 s
= "dial suppressed: dialmode `off'";
854 isdn_net_unreachable(&p
->dev
, lp
->first_skb
, s
);
855 isdn_net_hangup(&p
->dev
);
858 cmd
.driver
= lp
->isdn_device
;
859 cmd
.command
= ISDN_CMD_SETL2
;
860 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
862 cmd
.driver
= lp
->isdn_device
;
863 cmd
.command
= ISDN_CMD_SETL3
;
864 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
866 cmd
.driver
= lp
->isdn_device
;
867 cmd
.arg
= lp
->isdn_channel
;
871 restore_flags(flags
);
872 printk(KERN_WARNING
"%s: phone number deleted?\n",
874 isdn_net_hangup(&p
->dev
);
877 if (!strcmp(lp
->dial
->num
, "LEASED")) {
878 restore_flags(flags
);
880 printk(KERN_INFO
"%s: Open leased line ...\n", lp
->name
);
882 if(lp
->dialtimeout
> 0)
883 if(jiffies
> (lp
->dialstarted
+ lp
->dialtimeout
)) {
884 restore_flags(flags
);
885 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
887 isdn_net_unreachable(&p
->dev
, lp
->first_skb
, "dial: timed out");
888 isdn_net_hangup(&p
->dev
);
892 sprintf(cmd
.parm
.setup
.phone
, "%s", lp
->dial
->num
);
894 * Switch to next number or back to start if at end of list.
896 if (!(lp
->dial
= (isdn_net_phone
*) lp
->dial
->next
)) {
897 lp
->dial
= lp
->phone
[1];
900 if (lp
->dialretry
> lp
->dialmax
) {
901 restore_flags(flags
);
902 if (lp
->dialtimeout
== 0) {
903 lp
->dialwait_timer
= jiffies
+ lp
->dialwait
;
905 isdn_net_unreachable(&p
->dev
, lp
->first_skb
, "dial: tried all numbers dialmax times");
907 isdn_net_hangup(&p
->dev
);
911 restore_flags(flags
);
912 cmd
.driver
= lp
->isdn_device
;
913 cmd
.command
= ISDN_CMD_DIAL
;
914 cmd
.parm
.setup
.si1
= 7;
915 cmd
.parm
.setup
.si2
= 0;
916 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
917 isdn_map_eaz2msn(lp
->msn
, cmd
.driver
));
918 i
= isdn_dc2minor(lp
->isdn_device
, lp
->isdn_channel
);
920 strcpy(dev
->num
[i
], cmd
.parm
.setup
.phone
);
923 printk(KERN_INFO
"%s: dialing %d %s...\n", lp
->name
,
924 lp
->dialretry
, cmd
.parm
.setup
.phone
);
926 #ifdef ISDN_DEBUG_NET_DIAL
927 printk(KERN_DEBUG
"dial: d=%d c=%d\n", lp
->isdn_device
,
935 lp
->hupflags
|= ISDN_HAVECHARGE
;
936 lp
->hupflags
&= ~ISDN_WAITCHARGE
;
938 lp
->hupflags
|= ISDN_WAITCHARGE
;
939 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
944 (lp
->flags
& ISDN_NET_CBOUT
)) ? 12 : 4;
947 /* Wait for D-Channel-connect.
948 * If timeout, switch back to state 3.
949 * Dialmax-handling moved to state 3.
951 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
956 /* Got D-Channel-Connect, send B-Channel-request */
957 cmd
.driver
= lp
->isdn_device
;
958 cmd
.arg
= lp
->isdn_channel
;
959 cmd
.command
= ISDN_CMD_ACCEPTB
;
966 /* Wait for B- or D-Channel-connect. If timeout,
967 * switch back to state 3.
969 #ifdef ISDN_DEBUG_NET_DIAL
970 printk(KERN_DEBUG
"dialtimer2: %d\n", lp
->dtimer
);
972 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
977 /* Got incoming Call, setup L2 and L3 protocols,
978 * then wait for D-Channel-connect
980 #ifdef ISDN_DEBUG_NET_DIAL
981 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
983 cmd
.driver
= lp
->isdn_device
;
984 cmd
.command
= ISDN_CMD_SETL2
;
985 cmd
.arg
= lp
->isdn_channel
+ (lp
->l2_proto
<< 8);
987 cmd
.driver
= lp
->isdn_device
;
988 cmd
.command
= ISDN_CMD_SETL3
;
989 cmd
.arg
= lp
->isdn_channel
+ (lp
->l3_proto
<< 8);
991 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT15
)
992 isdn_net_hangup(&p
->dev
);
999 /* Got incoming D-Channel-Connect, send B-Channel-request */
1000 cmd
.driver
= lp
->isdn_device
;
1001 cmd
.arg
= lp
->isdn_channel
;
1002 cmd
.command
= ISDN_CMD_ACCEPTB
;
1010 /* Wait for B- or D-channel-connect */
1011 #ifdef ISDN_DEBUG_NET_DIAL
1012 printk(KERN_DEBUG
"dialtimer4: %d\n", lp
->dtimer
);
1014 if (lp
->dtimer
++ > ISDN_TIMER_DTIMEOUT10
)
1015 isdn_net_hangup(&p
->dev
);
1020 /* Callback Delay */
1021 if (lp
->dtimer
++ > lp
->cbdelay
)
1026 /* Remote does callback. Hangup after cbdelay, then wait for incoming
1027 * call (in state 4).
1029 if (lp
->dtimer
++ > lp
->cbdelay
)
1031 printk(KERN_INFO
"%s: hangup waiting for callback ...\n", lp
->name
);
1034 cmd
.driver
= lp
->isdn_device
;
1035 cmd
.command
= ISDN_CMD_HANGUP
;
1036 cmd
.arg
= lp
->isdn_channel
;
1038 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
1043 printk(KERN_WARNING
"isdn_net: Illegal dialstate %d for device %s\n",
1044 lp
->dialstate
, lp
->name
);
1046 p
= (isdn_net_dev
*) p
->next
;
1048 isdn_timer_ctrl(ISDN_TIMER_NETDIAL
, anymore
);
1052 * Perform hangup for a net-interface.
1055 isdn_net_hangup(struct net_device
*d
)
1057 isdn_net_local
*lp
= (isdn_net_local
*) d
->priv
;
1059 #ifdef CONFIG_ISDN_X25
1060 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
1061 struct concap_proto_ops
*pops
= cprot
? cprot
-> pops
: 0;
1064 if (lp
->flags
& ISDN_NET_CONNECTED
) {
1065 printk(KERN_INFO
"isdn_net: local hangup %s\n", lp
->name
);
1066 #ifdef CONFIG_ISDN_PPP
1069 #ifdef CONFIG_ISDN_X25
1070 /* try if there are generic encap protocol
1071 receiver routines and signal the closure of
1073 if( pops
&& pops
-> disconn_ind
)
1074 pops
-> disconn_ind(cprot
);
1075 #endif /* CONFIG_ISDN_X25 */
1077 cmd
.driver
= lp
->isdn_device
;
1078 cmd
.command
= ISDN_CMD_HANGUP
;
1079 cmd
.arg
= lp
->isdn_channel
;
1081 printk(KERN_INFO
"%s: Chargesum is %d\n", lp
->name
, lp
->charge
);
1082 isdn_all_eaz(lp
->isdn_device
, lp
->isdn_channel
);
1084 isdn_net_unbind_channel(lp
);
1088 unsigned short source
;
1089 unsigned short dest
;
1093 isdn_net_log_skb(struct sk_buff
* skb
, isdn_net_local
* lp
)
1095 u_char
*p
= skb
->nh
.raw
; /* hopefully, this was set correctly */
1096 unsigned short proto
= ntohs(skb
->protocol
);
1102 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
1103 if (skb
->nh
.raw
< skb
->data
|| skb
->nh
.raw
>= skb
->tail
) {
1104 /* fall back to old isdn_net_log_packet method() */
1105 char * buf
= skb
->data
;
1107 printk(KERN_DEBUG
"isdn_net: protocol %04x is buggy, dev %s\n", skb
->protocol
, lp
->name
);
1110 switch (lp
->p_encap
) {
1111 case ISDN_NET_ENCAP_IPTYP
:
1112 proto
= ntohs(*(unsigned short *) &buf
[0]);
1115 case ISDN_NET_ENCAP_ETHER
:
1116 proto
= ntohs(*(unsigned short *) &buf
[12]);
1119 case ISDN_NET_ENCAP_CISCOHDLC
:
1120 proto
= ntohs(*(unsigned short *) &buf
[2]);
1123 #ifdef CONFIG_ISDN_PPP
1124 case ISDN_NET_ENCAP_SYNCPPP
:
1125 proto
= ntohs(skb
->protocol
);
1126 p
= &buf
[IPPP_MAX_HEADER
];
1131 data_ofs
= ((p
[0] & 15) * 4);
1136 strcpy(addinfo
, " ICMP");
1139 strcpy(addinfo
, " IGMP");
1142 strcpy(addinfo
, " IPIP");
1145 ipp
= (ip_ports
*) (&p
[data_ofs
]);
1146 sprintf(addinfo
, " TCP, port: %d -> %d", ntohs(ipp
->source
),
1150 strcpy(addinfo
, " EGP");
1153 strcpy(addinfo
, " PUP");
1156 ipp
= (ip_ports
*) (&p
[data_ofs
]);
1157 sprintf(addinfo
, " UDP, port: %d -> %d", ntohs(ipp
->source
),
1161 strcpy(addinfo
, " IDP");
1164 printk(KERN_INFO
"OPEN: %d.%d.%d.%d -> %d.%d.%d.%d%s\n",
1165 p
[12], p
[13], p
[14], p
[15],
1166 p
[16], p
[17], p
[18], p
[19],
1170 printk(KERN_INFO
"OPEN: ARP %d.%d.%d.%d -> *.*.*.* ?%d.%d.%d.%d\n",
1171 p
[14], p
[15], p
[16], p
[17],
1172 p
[24], p
[25], p
[26], p
[27]);
1178 * Generic routine to send out an skbuf.
1179 * If lowlevel-device does not support support skbufs, use
1180 * standard send-routine, else send directly.
1182 * Return: 0 on success, !0 on failure.
1183 * Side-effects: ndev->tbusy is cleared on success.
1186 isdn_net_send_skb(struct net_device
*ndev
, isdn_net_local
* lp
,
1187 struct sk_buff
*skb
)
1190 int len
= skb
->len
; /* save len */
1192 ret
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
);
1194 lp
->transcount
+= len
;
1195 clear_bit(0, (void *) &(ndev
->tbusy
));
1200 lp
->stats
.tx_errors
++;
1201 clear_bit(0, (void *) &(ndev
->tbusy
));
1208 * Helper function for isdn_net_start_xmit.
1209 * When called, the connection is already established.
1210 * Based on cps-calculation, check if device is overloaded.
1211 * If so, and if a slave exists, trigger dialing for it.
1212 * If any slave is online, deliver packets using a simple round robin
1215 * Return: 0 on success, !0 on failure.
1219 isdn_net_xmit(struct net_device
*ndev
, isdn_net_local
* lp
, struct sk_buff
*skb
)
1223 /* For the other encaps the header has already been built */
1224 #ifdef CONFIG_ISDN_PPP
1225 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1226 return isdn_ppp_xmit(skb
, ndev
);
1229 /* Reset hangup-timeout */
1231 if (lp
->cps
> lp
->triggercps
) {
1232 /* Device overloaded */
1235 * Packet-delivery via round-robin over master
1236 * and all connected slaves.
1239 /* Slaves always deliver themselves */
1240 ret
= isdn_net_send_skb(ndev
, lp
, skb
);
1242 isdn_net_local
*slp
= (isdn_net_local
*) (lp
->srobin
->priv
);
1243 /* Master delivers via srobin and maintains srobin */
1244 if (lp
->srobin
== ndev
)
1245 ret
= isdn_net_send_skb(ndev
, lp
, skb
);
1247 ret
= ndev
->tbusy
= isdn_net_start_xmit(skb
, lp
->srobin
);
1248 lp
->srobin
= (slp
->slave
) ? slp
->slave
: ndev
;
1249 slp
= (isdn_net_local
*) (lp
->srobin
->priv
);
1250 if (!((slp
->flags
& ISDN_NET_CONNECTED
) && (slp
->dialstate
== 0)))
1253 /* Slave-startup using delay-variable */
1256 /* First time overload: set timestamp only */
1258 lp
->sqfull_stamp
= jiffies
;
1260 /* subsequent overload: if slavedelay exceeded, start dialing */
1261 if ((jiffies
- lp
->sqfull_stamp
) > lp
->slavedelay
)
1262 isdn_net_force_dial_lp((isdn_net_local
*) lp
->slave
->priv
);
1266 /* Not overloaded, deliver locally */
1267 ret
= isdn_net_send_skb(ndev
, lp
, skb
);
1268 if (lp
->sqfull
&& ((jiffies
- lp
->sqfull_stamp
) > (lp
->slavedelay
+ (10 * HZ
))))
1275 isdn_net_adjust_hdr(struct sk_buff
*skb
, struct net_device
*dev
)
1277 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1280 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1281 int pullsize
= (ulong
)skb
->nh
.raw
- (ulong
)skb
->data
- ETH_HLEN
;
1283 printk(KERN_DEBUG
"isdn_net: Pull junk %d\n", pullsize
);
1284 skb_pull(skb
, pullsize
);
1290 * Try sending a packet.
1291 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1292 * and start dialing.
1295 isdn_net_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1297 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1298 #ifdef CONFIG_ISDN_X25
1299 struct concap_proto
* cprot
= lp
-> netdev
-> cprot
;
1303 if (jiffies
- ndev
->trans_start
< (2 * HZ
))
1306 lp
->stats
.tx_errors
++;
1307 ndev
->trans_start
= jiffies
;
1309 ndev
->tbusy
= 1; /* left instead of obsolete test_and_set_bit() */
1310 #ifdef CONFIG_ISDN_X25
1311 /* At this point hard_start_xmit() passes control to the encapsulation
1312 protocol (if present).
1313 For X.25 auto-dialing is completly bypassed because:
1314 - It does not conform with the semantics of a reliable datalink
1315 service as needed by X.25 PLP.
1316 - I don't want that the interface starts dialing when the network layer
1317 sends a message which requests to disconnect the lapb link (or if it
1318 sends any other message not resulting in data transmission).
1319 Instead, dialing will be initiated by the encapsulation protocol entity
1320 when a dl_establish request is received from the upper layer.
1323 return cprot
-> pops
-> encap_and_xmit ( cprot
, skb
);
1326 /* auto-dialing xmit function */
1328 #ifdef ISDN_DEBUG_NET_DUMP
1331 isdn_net_adjust_hdr(skb
, ndev
);
1332 #ifdef ISDN_DEBUG_NET_DUMP
1334 isdn_dumppkt("S:", buf
, skb
->len
, 40);
1336 if (!(lp
->flags
& ISDN_NET_CONNECTED
)) {
1338 /* only do autodial if allowed by config */
1339 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) {
1340 isdn_net_unreachable(ndev
, skb
, "dial rejected: interface not in dialmode `auto'");
1350 if(lp
->dialwait_timer
<= 0)
1351 if(lp
->dialstarted
> 0 && lp
->dialtimeout
> 0 && jiffies
< lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
)
1352 lp
->dialwait_timer
= lp
->dialstarted
+ lp
->dialtimeout
+ lp
->dialwait
;
1354 if(lp
->dialwait_timer
> 0) {
1355 if(jiffies
< lp
->dialwait_timer
) {
1356 isdn_net_unreachable(ndev
, skb
, "dial rejected: retry-time not reached");
1359 restore_flags(flags
);
1362 lp
->dialwait_timer
= 0;
1365 /* Grab a free ISDN-Channel */
1367 isdn_get_free_channel(ISDN_USAGE_NET
,
1371 lp
->pre_channel
)) < 0) &&
1373 isdn_get_free_channel(ISDN_USAGE_NET
,
1377 lp
->pre_channel
^1)) < 0)) {
1378 restore_flags(flags
);
1379 isdn_net_unreachable(ndev
, skb
,
1385 /* Log packet, which triggered dialing */
1386 if (dev
->net_verbose
)
1387 isdn_net_log_skb(skb
, lp
);
1389 /* Connect interface with channel */
1390 isdn_net_bind_channel(lp
, chi
);
1391 #ifdef CONFIG_ISDN_PPP
1392 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
) {
1393 /* no 'first_skb' handling for syncPPP */
1394 if (isdn_ppp_bind(lp
) < 0) {
1396 isdn_net_unbind_channel(lp
);
1397 restore_flags(flags
);
1398 return 0; /* STN (skb to nirvana) ;) */
1400 restore_flags(flags
);
1401 isdn_net_dial(); /* Initiate dialing */
1402 return 1; /* let upper layer requeue skb packet */
1405 /* remember first skb to speed up arp
1406 * when using encap ETHER
1408 if (lp
->first_skb
) {
1409 printk(KERN_WARNING
"isdn_net_start_xmit: First skb already set!\n");
1410 dev_kfree_skb(lp
->first_skb
);
1411 lp
->first_skb
= NULL
;
1413 lp
->first_skb
= skb
;
1414 /* Initiate dialing */
1416 restore_flags(flags
);
1420 isdn_net_unreachable(ndev
, skb
,
1427 /* Connection is established, try sending */
1428 ndev
->trans_start
= jiffies
;
1429 if (!lp
->dialstate
) {
1430 if (lp
->first_skb
) {
1431 if (isdn_net_xmit(ndev
, lp
, lp
->first_skb
))
1433 lp
->first_skb
= NULL
;
1435 return (isdn_net_xmit(ndev
, lp
, skb
));
1444 * Shutdown a net-interface.
1447 isdn_net_close(struct net_device
*dev
)
1449 struct net_device
*p
;
1450 #ifdef CONFIG_ISDN_X25
1451 struct concap_proto
* cprot
=
1452 ( (isdn_net_local
*) dev
->priv
) -> netdev
-> cprot
;
1453 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1456 #ifdef CONFIG_ISDN_X25
1457 if( cprot
&& cprot
-> pops
) cprot
-> pops
-> close( cprot
);
1461 if ((p
= (((isdn_net_local
*) dev
->priv
)->slave
))) {
1462 /* If this interface has slaves, stop them also */
1464 #ifdef CONFIG_ISDN_X25
1465 cprot
= ( (isdn_net_local
*) p
->priv
)
1467 if( cprot
&& cprot
-> pops
)
1468 cprot
-> pops
-> close( cprot
);
1473 p
= (((isdn_net_local
*) p
->priv
)->slave
);
1476 isdn_net_hangup(dev
);
1477 isdn_MOD_DEC_USE_COUNT();
1484 static struct enet_statistics
*
1485 isdn_net_get_stats(struct net_device
*dev
)
1487 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1491 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1492 * instead of dev->hard_header_len off. This is done because the
1493 * lowlevel-driver has already pulled off its stuff when we get
1494 * here and this routine only gets called with p_encap == ETHER.
1495 * Determine the packet's protocol ID. The rule here is that we
1496 * assume 802.3 if the type field is short enough to be a length.
1497 * This is normal practice and works for any 'now in use' protocol.
1500 static unsigned short
1501 isdn_net_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1504 unsigned char *rawp
;
1506 skb
->mac
.raw
= skb
->data
;
1507 skb_pull(skb
, ETH_HLEN
);
1508 eth
= skb
->mac
.ethernet
;
1510 if (*eth
->h_dest
& 1) {
1511 if (memcmp(eth
->h_dest
, dev
->broadcast
, ETH_ALEN
) == 0)
1512 skb
->pkt_type
= PACKET_BROADCAST
;
1514 skb
->pkt_type
= PACKET_MULTICAST
;
1517 * This ALLMULTI check should be redundant by 1.4
1518 * so don't forget to remove it.
1521 else if (dev
->flags
& (IFF_PROMISC
/*| IFF_ALLMULTI*/)) {
1522 if (memcmp(eth
->h_dest
, dev
->dev_addr
, ETH_ALEN
))
1523 skb
->pkt_type
= PACKET_OTHERHOST
;
1525 if (ntohs(eth
->h_proto
) >= 1536)
1526 return eth
->h_proto
;
1531 * This is a magic hack to spot IPX packets. Older Novell breaks
1532 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1533 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1534 * won't work for fault tolerant netware but does for the rest.
1536 if (*(unsigned short *) rawp
== 0xFFFF)
1537 return htons(ETH_P_802_3
);
1541 return htons(ETH_P_802_2
);
1545 isdn_net_slarp_send(isdn_net_local
*lp
, int is_reply
)
1547 unsigned short hl
= dev
->drv
[lp
->isdn_device
]->interface
->hl_hdrlen
;
1548 struct sk_buff
*skb
= alloc_skb(hl
+ sizeof(cisco_hdr
) + sizeof(cisco_slarp
), GFP_ATOMIC
);
1549 unsigned long t
= (jiffies
/ HZ
* 1000000);
1556 "%s: Could not allocate SLARP reply\n", lp
->name
);
1559 skb_reserve(skb
, hl
);
1560 ch
= (cisco_hdr
*)skb_put(skb
, sizeof(cisco_hdr
));
1561 ch
->addr
= CISCO_ADDR_UNICAST
;
1563 ch
->type
= htons(CISCO_TYPE_SLARP
);
1564 s
= (cisco_slarp
*)skb_put(skb
, sizeof(cisco_slarp
));
1566 s
->code
= htonl(CISCO_SLARP_REPLY
);
1567 memset(&s
->slarp
.reply
.ifaddr
, 0, sizeof(__u32
));
1568 memset(&s
->slarp
.reply
.netmask
, 0, sizeof(__u32
));
1571 s
->code
= htonl(CISCO_SLARP_KEEPALIVE
);
1572 s
->slarp
.keepalive
.my_seq
= htonl(lp
->cisco_myseq
);
1573 s
->slarp
.keepalive
.your_seq
= htonl(lp
->cisco_yourseq
);
1579 if (isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 0, skb
) != len
)
1584 isdn_net_slarp_in(isdn_net_local
*lp
, struct sk_buff
*skb
)
1586 cisco_slarp
*s
= (cisco_slarp
*)skb
->data
;
1588 switch (ntohl(s
->code
)) {
1589 case CISCO_SLARP_REQUEST
:
1590 isdn_net_slarp_send(lp
, 1);
1592 case CISCO_SLARP_REPLY
:
1593 /* Ignore replies */
1595 case CISCO_SLARP_KEEPALIVE
:
1596 lp
->cisco_yourseq
= s
->slarp
.keepalive
.my_seq
;
1597 if (ntohl(s
->slarp
.keepalive
.my_seq
== lp
->cisco_myseq
)) {
1598 if (lp
->cisco_loop
++ == 2) {
1599 printk(KERN_WARNING
"%s: Keepalive Loop\n",
1601 lp
->cisco_myseq
^= jiffies
;
1611 * Called every 10 sec. via timer-interrupt if
1612 * any network-interface has Cisco-Keepalive-Encapsulation
1614 * Send Keepalive-Packet and re-schedule.
1617 isdn_net_slarp_out(void)
1619 isdn_net_dev
*p
= dev
->netdev
;
1623 isdn_net_local
*l
= p
->local
;
1624 if ((l
->p_encap
== ISDN_NET_ENCAP_CISCOHDLCK
) &&
1625 (l
->flags
& ISDN_NET_CONNECTED
) &&
1628 isdn_net_slarp_send(l
, 0);
1630 p
= (isdn_net_dev
*) p
->next
;
1632 isdn_timer_ctrl(ISDN_TIMER_KEEPALIVE
, anymore
);
1636 * Got a packet from ISDN-Channel.
1639 isdn_net_receive(struct net_device
*ndev
, struct sk_buff
*skb
)
1641 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1642 isdn_net_local
*olp
= lp
; /* original 'lp' */
1643 #ifdef CONFIG_ISDN_PPP
1644 int proto
= PPP_PROTOCOL(skb
->data
);
1646 #ifdef CONFIG_ISDN_X25
1647 struct concap_proto
*cprot
= lp
-> netdev
-> cprot
;
1651 lp
->transcount
+= skb
->len
;
1653 lp
->stats
.rx_packets
++;
1654 lp
->stats
.rx_bytes
+= skb
->len
;
1656 /* Bundling: If device is a slave-device, deliver to master, also
1657 * handle master's statistics and hangup-timeout
1660 lp
= (isdn_net_local
*) ndev
->priv
;
1661 lp
->stats
.rx_packets
++;
1662 lp
->stats
.rx_bytes
+= skb
->len
;
1666 skb
->pkt_type
= PACKET_HOST
;
1667 skb
->mac
.raw
= skb
->data
;
1668 #ifdef ISDN_DEBUG_NET_DUMP
1669 isdn_dumppkt("R:", skb
->data
, skb
->len
, 40);
1671 switch (lp
->p_encap
) {
1672 case ISDN_NET_ENCAP_ETHER
:
1673 /* Ethernet over ISDN */
1676 skb
->protocol
= isdn_net_type_trans(skb
, ndev
);
1678 case ISDN_NET_ENCAP_UIHDLC
:
1679 /* HDLC with UI-frame (for ispa with -h1 option) */
1684 case ISDN_NET_ENCAP_RAWIP
:
1685 /* RAW-IP without MAC-Header */
1688 skb
->protocol
= htons(ETH_P_IP
);
1690 case ISDN_NET_ENCAP_CISCOHDLCK
:
1691 ch
= (cisco_hdr
*)skb
->data
;
1692 if ((ch
->addr
!= CISCO_ADDR_UNICAST
) &&
1693 (ch
->addr
!= CISCO_ADDR_BROADCAST
) ) {
1694 printk(KERN_WARNING
"%s: Unknown Cisco addr 0x%02x\n",
1695 lp
->name
, ch
->addr
);
1699 if (ch
->ctrl
!= 0) {
1700 printk(KERN_WARNING
"%s: Unknown Cisco ctrl 0x%02x\n",
1701 lp
->name
, ch
->ctrl
);
1705 switch (ntohs(ch
->type
)) {
1706 case CISCO_TYPE_INET
:
1708 skb
->protocol
= htons(ETH_P_IP
);
1710 case CISCO_TYPE_SLARP
:
1712 isdn_net_slarp_in(olp
, skb
);
1715 printk(KERN_WARNING
"%s: Unknown Cisco type 0x%04x\n",
1716 lp
->name
, ch
->type
);
1721 case ISDN_NET_ENCAP_CISCOHDLC
:
1722 /* CISCO-HDLC IP with type field and fake I-frame-header */
1725 case ISDN_NET_ENCAP_IPTYP
:
1726 /* IP with type field */
1729 skb
->protocol
= *(unsigned short *) &(skb
->data
[0]);
1731 if (*(unsigned short *) skb
->data
== 0xFFFF)
1732 skb
->protocol
= htons(ETH_P_802_3
);
1734 #ifdef CONFIG_ISDN_PPP
1735 case ISDN_NET_ENCAP_SYNCPPP
:
1737 * If encapsulation is syncppp, don't reset
1738 * huptimer on LCP packets.
1740 if (proto
!= PPP_LCP
) {
1744 isdn_ppp_receive(lp
->netdev
, olp
, skb
);
1748 #ifdef CONFIG_ISDN_X25
1749 /* try if there are generic sync_device receiver routines */
1750 if(cprot
) if(cprot
-> pops
)
1751 if( cprot
-> pops
-> data_ind
){
1752 cprot
-> pops
-> data_ind(cprot
,skb
);
1755 #endif /* CONFIG_ISDN_X25 */
1756 printk(KERN_WARNING
"%s: unknown encapsulation, dropping\n",
1767 * A packet arrived via ISDN. Search interface-chain for a corresponding
1768 * interface. If found, deliver packet to receiver-function and return 1,
1772 isdn_net_rcv_skb(int idx
, struct sk_buff
*skb
)
1774 isdn_net_dev
*p
= dev
->rx_netdev
[idx
];
1777 isdn_net_local
*lp
= p
->local
;
1778 if ((lp
->flags
& ISDN_NET_CONNECTED
) &&
1780 isdn_net_receive(&p
->dev
, skb
);
1788 my_eth_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
1789 void *daddr
, void *saddr
, unsigned len
)
1791 struct ethhdr
*eth
= (struct ethhdr
*) skb_push(skb
, ETH_HLEN
);
1794 * Set the protocol type. For a packet of type ETH_P_802_3 we
1795 * put the length here instead. It is up to the 802.2 layer to
1796 * carry protocol information.
1799 if (type
!= ETH_P_802_3
)
1800 eth
->h_proto
= htons(type
);
1802 eth
->h_proto
= htons(len
);
1805 * Set the source hardware address.
1808 memcpy(eth
->h_source
, saddr
, dev
->addr_len
);
1810 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
1813 * Anyway, the loopback-device should never use this function...
1816 if (dev
->flags
& (IFF_LOOPBACK
| IFF_NOARP
)) {
1817 memset(eth
->h_dest
, 0, dev
->addr_len
);
1818 return ETH_HLEN
/*(dev->hard_header_len)*/;
1821 memcpy(eth
->h_dest
, daddr
, dev
->addr_len
);
1822 return ETH_HLEN
/*dev->hard_header_len*/;
1824 return -ETH_HLEN
/*dev->hard_header_len*/;
1829 * depends on encaps that is being used.
1833 isdn_net_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
1834 void *daddr
, void *saddr
, unsigned plen
)
1836 isdn_net_local
*lp
= dev
->priv
;
1839 switch (lp
->p_encap
) {
1840 case ISDN_NET_ENCAP_ETHER
:
1841 len
= my_eth_header(skb
, dev
, type
, daddr
, saddr
, plen
);
1843 #ifdef CONFIG_ISDN_PPP
1844 case ISDN_NET_ENCAP_SYNCPPP
:
1845 /* stick on a fake header to keep fragmentation code happy. */
1846 len
= IPPP_MAX_HEADER
;
1850 case ISDN_NET_ENCAP_RAWIP
:
1851 printk(KERN_WARNING
"isdn_net_header called with RAW_IP!\n");
1854 case ISDN_NET_ENCAP_IPTYP
:
1855 /* ethernet type field */
1856 *((ushort
*) skb_push(skb
, 2)) = htons(type
);
1859 case ISDN_NET_ENCAP_UIHDLC
:
1860 /* HDLC with UI-Frames (for ispa with -h1 option) */
1861 *((ushort
*) skb_push(skb
, 2)) = htons(0x0103);
1864 case ISDN_NET_ENCAP_CISCOHDLC
:
1866 skb
->data
[0] = 0x0f;
1867 skb
->data
[1] = 0x00;
1868 *((ushort
*) & skb
->data
[2]) = htons(type
);
1871 #ifdef CONFIG_ISDN_X25
1873 /* try if there are generic concap protocol routines */
1874 if( lp
-> netdev
-> cprot
){
1875 printk(KERN_WARNING
"isdn_net_header called with concap_proto!\n");
1880 #endif /* CONFIG_ISDN_X25 */
1885 /* We don't need to send arp, because we have point-to-point connections. */
1887 isdn_net_rebuild_header(struct sk_buff
*skb
)
1889 struct net_device
*dev
= skb
->dev
;
1890 isdn_net_local
*lp
= dev
->priv
;
1893 if (lp
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
1894 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
1897 * Only ARP/IP is currently supported
1900 if (eth
->h_proto
!= htons(ETH_P_IP
)) {
1902 "isdn_net: %s don't know how to resolve type %d addresses?\n",
1903 dev
->name
, (int) eth
->h_proto
);
1904 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
1908 * Try to get ARP to resolve the header.
1911 ret
= arp_find(eth
->h_dest
, skb
);
1918 * Interface-setup. (called just after registering a new interface)
1921 isdn_net_init(struct net_device
*ndev
)
1923 ushort max_hlhdr_len
= 0;
1924 isdn_net_local
*lp
= (isdn_net_local
*) ndev
->priv
;
1929 printk(KERN_WARNING
"isdn_net_init: dev = NULL!\n");
1932 if (ndev
->priv
== NULL
) {
1933 printk(KERN_WARNING
"isdn_net_init: dev->priv = NULL!\n");
1937 lp
->org_hhc
= ndev
->hard_header_cache
;
1938 lp
->org_hcu
= ndev
->header_cache_update
;
1940 /* Setup the generic properties */
1942 ndev
->hard_header
= NULL
;
1943 ndev
->hard_header_cache
= NULL
;
1944 ndev
->header_cache_update
= NULL
;
1946 ndev
->flags
= IFF_NOARP
|IFF_POINTOPOINT
;
1947 ndev
->type
= ARPHRD_ETHER
;
1948 ndev
->addr_len
= ETH_ALEN
;
1950 /* for clients with MPPP maybe higher values better */
1951 ndev
->tx_queue_len
= 30;
1953 for (i
= 0; i
< ETH_ALEN
; i
++)
1954 ndev
->broadcast
[i
] = 0xff;
1956 /* The ISDN-specific entries in the device structure. */
1957 ndev
->open
= &isdn_net_open
;
1958 ndev
->hard_start_xmit
= &isdn_net_start_xmit
;
1961 * up till binding we ask the protocol layer to reserve as much
1962 * as we might need for HL layer
1965 for (drvidx
= 0; drvidx
< ISDN_MAX_DRIVERS
; drvidx
++)
1966 if (dev
->drv
[drvidx
])
1967 if (max_hlhdr_len
< dev
->drv
[drvidx
]->interface
->hl_hdrlen
)
1968 max_hlhdr_len
= dev
->drv
[drvidx
]->interface
->hl_hdrlen
;
1970 ndev
->hard_header_len
= ETH_HLEN
+ max_hlhdr_len
;
1971 ndev
->stop
= &isdn_net_close
;
1972 ndev
->get_stats
= &isdn_net_get_stats
;
1973 ndev
->rebuild_header
= &isdn_net_rebuild_header
;
1974 #ifdef CONFIG_ISDN_PPP
1975 ndev
->do_ioctl
= isdn_ppp_dev_ioctl
;
1981 isdn_net_swapbind(int drvidx
)
1985 #ifdef ISDN_DEBUG_NET_ICALL
1986 printk(KERN_DEBUG
"n_fi: swapping ch of %d\n", drvidx
);
1990 if (p
->local
->pre_device
== drvidx
)
1991 switch (p
->local
->pre_channel
) {
1993 p
->local
->pre_channel
= 1;
1996 p
->local
->pre_channel
= 0;
1999 p
= (isdn_net_dev
*) p
->next
;
2004 isdn_net_swap_usage(int i1
, int i2
)
2006 int u1
= dev
->usage
[i1
] & ISDN_USAGE_EXCLUSIVE
;
2007 int u2
= dev
->usage
[i2
] & ISDN_USAGE_EXCLUSIVE
;
2009 #ifdef ISDN_DEBUG_NET_ICALL
2010 printk(KERN_DEBUG
"n_fi: usage of %d and %d\n", i1
, i2
);
2012 dev
->usage
[i1
] &= ~ISDN_USAGE_EXCLUSIVE
;
2013 dev
->usage
[i1
] |= u2
;
2014 dev
->usage
[i2
] &= ~ISDN_USAGE_EXCLUSIVE
;
2015 dev
->usage
[i2
] |= u1
;
2020 * An incoming call-request has arrived.
2021 * Search the interface-chain for an appropriate interface.
2022 * If found, connect the interface to the ISDN-channel and initiate
2023 * D- and B-Channel-setup. If secure-flag is set, accept only
2024 * configured phone-numbers. If callback-flag is set, initiate
2027 * Return-Value: 0 = No appropriate interface for this call.
2029 * 2 = Reject call, wait cbdelay, then call back
2031 * 4 = Wait cbdelay, then call back
2032 * 5 = No appropriate interface for this call,
2033 * would eventually match if CID was longer.
2036 isdn_net_find_icall(int di
, int ch
, int idx
, setup_parm setup
)
2050 /* Search name in netdev-chain */
2053 if (!setup
.phone
[0]) {
2056 printk(KERN_INFO
"isdn_net: Incoming call without OAD, assuming '0'\n");
2058 strcpy(nr
, setup
.phone
);
2059 si1
= (int) setup
.si1
;
2060 si2
= (int) setup
.si2
;
2061 if (!setup
.eazmsn
[0]) {
2062 printk(KERN_WARNING
"isdn_net: Incoming call without CPN, assuming '0'\n");
2066 if (dev
->net_verbose
> 1)
2067 printk(KERN_INFO
"isdn_net: call from %s,%d,%d -> %s\n", nr
, si1
, si2
, eaz
);
2068 /* Accept only calls with Si1 = 7 (Data-Transmission) */
2070 restore_flags(flags
);
2071 if (dev
->net_verbose
> 1)
2072 printk(KERN_INFO
"isdn_net: Service-Indicator not 7, ignored\n");
2075 n
= (isdn_net_phone
*) 0;
2077 ematch
= wret
= swapped
= 0;
2078 #ifdef ISDN_DEBUG_NET_ICALL
2079 printk(KERN_DEBUG
"n_fi: di=%d ch=%d idx=%d usg=%d\n", di
, ch
, idx
,
2084 isdn_net_local
*lp
= p
->local
;
2086 /* If last check has triggered as binding-swap, revert it */
2089 isdn_net_swap_usage(idx
, sidx
);
2092 isdn_net_swapbind(di
);
2096 if (!(matchret
= isdn_wildmat(eaz
, isdn_map_eaz2msn(lp
->msn
, di
))))
2098 /* Remember if more numbers eventually can match */
2099 if (matchret
> wret
)
2101 #ifdef ISDN_DEBUG_NET_ICALL
2102 printk(KERN_DEBUG
"n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2103 lp
->name
, lp
->msn
, lp
->flags
, lp
->dialstate
);
2105 if ((!matchret
) && /* EAZ is matching */
2106 (((!(lp
->flags
& ISDN_NET_CONNECTED
)) && /* but not connected */
2107 (USG_NONE(dev
->usage
[idx
]))) || /* and ch. unused or */
2108 ((((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) && /* if dialing */
2109 (!(lp
->flags
& ISDN_NET_CALLBACK
))) /* but no callback */
2112 #ifdef ISDN_DEBUG_NET_ICALL
2113 printk(KERN_DEBUG
"n_fi: match1, pdev=%d pch=%d\n",
2114 lp
->pre_device
, lp
->pre_channel
);
2116 if (dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) {
2117 if ((lp
->pre_channel
!= ch
) ||
2118 (lp
->pre_device
!= di
)) {
2119 /* Here we got a problem:
2120 * If using an ICN-Card, an incoming call is always signaled on
2121 * on the first channel of the card, if both channels are
2122 * down. However this channel may be bound exclusive. If the
2123 * second channel is free, this call should be accepted.
2124 * The solution is horribly but it runs, so what:
2125 * We exchange the exclusive bindings of the two channels, the
2126 * corresponding variables in the interface-structs.
2129 sidx
= isdn_dc2minor(di
, 1);
2130 #ifdef ISDN_DEBUG_NET_ICALL
2131 printk(KERN_DEBUG
"n_fi: ch is 0\n");
2133 if (USG_NONE(dev
->usage
[sidx
])) {
2134 /* Second Channel is free, now see if it is bound
2136 if (dev
->usage
[sidx
] & ISDN_USAGE_EXCLUSIVE
) {
2137 #ifdef ISDN_DEBUG_NET_ICALL
2138 printk(KERN_DEBUG
"n_fi: 2nd channel is down and bound\n");
2140 /* Yes, swap bindings only, if the original
2141 * binding is bound to channel 1 of this driver */
2142 if ((lp
->pre_device
== di
) &&
2143 (lp
->pre_channel
== 1)) {
2144 isdn_net_swapbind(di
);
2147 /* ... else iterate next device */
2148 p
= (isdn_net_dev
*) p
->next
;
2152 #ifdef ISDN_DEBUG_NET_ICALL
2153 printk(KERN_DEBUG
"n_fi: 2nd channel is down and unbound\n");
2155 /* No, swap always and swap excl-usage also */
2156 isdn_net_swap_usage(idx
, sidx
);
2157 isdn_net_swapbind(di
);
2160 /* Now check for exclusive binding again */
2161 #ifdef ISDN_DEBUG_NET_ICALL
2162 printk(KERN_DEBUG
"n_fi: final check\n");
2164 if ((dev
->usage
[idx
] & ISDN_USAGE_EXCLUSIVE
) &&
2165 ((lp
->pre_channel
!= ch
) ||
2166 (lp
->pre_device
!= di
))) {
2167 #ifdef ISDN_DEBUG_NET_ICALL
2168 printk(KERN_DEBUG
"n_fi: final check failed\n");
2170 p
= (isdn_net_dev
*) p
->next
;
2175 /* We are already on the second channel, so nothing to do */
2176 #ifdef ISDN_DEBUG_NET_ICALL
2177 printk(KERN_DEBUG
"n_fi: already on 2nd channel\n");
2182 #ifdef ISDN_DEBUG_NET_ICALL
2183 printk(KERN_DEBUG
"n_fi: match2\n");
2186 if (lp
->flags
& ISDN_NET_SECURE
) {
2188 if (!isdn_wildmat(nr
, n
->num
))
2190 n
= (isdn_net_phone
*) n
->next
;
2193 if (n
|| (!(lp
->flags
& ISDN_NET_SECURE
))) {
2194 #ifdef ISDN_DEBUG_NET_ICALL
2195 printk(KERN_DEBUG
"n_fi: match3\n");
2197 /* matching interface found */
2200 * Is the state STOPPED?
2201 * If so, no dialin is allowed,
2202 * so reject actively.
2204 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2205 restore_flags(flags
);
2206 printk(KERN_INFO
"incoming call, interface %s `stopped' -> rejected\n",
2211 * Is the interface up?
2212 * If not, reject the call actively.
2214 if (!p
->dev
.start
) {
2215 restore_flags(flags
);
2216 printk(KERN_INFO
"%s: incoming call, interface down -> rejected\n",
2220 /* Interface is up, now see if it's a slave. If so, see if
2221 * it's master and parent slave is online. If not, reject the call.
2224 isdn_net_local
*mlp
= (isdn_net_local
*) lp
->master
->priv
;
2225 printk(KERN_DEBUG
"ICALLslv: %s\n", lp
->name
);
2226 printk(KERN_DEBUG
"master=%s\n", mlp
->name
);
2227 if (mlp
->flags
& ISDN_NET_CONNECTED
) {
2228 printk(KERN_DEBUG
"master online\n");
2229 /* Master is online, find parent-slave (master if first slave) */
2230 while (mlp
->slave
) {
2231 if ((isdn_net_local
*) mlp
->slave
->priv
== lp
)
2233 mlp
= (isdn_net_local
*) mlp
->slave
->priv
;
2236 printk(KERN_DEBUG
"master offline\n");
2237 /* Found parent, if it's offline iterate next device */
2238 printk(KERN_DEBUG
"mlpf: %d\n", mlp
->flags
& ISDN_NET_CONNECTED
);
2239 if (!(mlp
->flags
& ISDN_NET_CONNECTED
)) {
2240 p
= (isdn_net_dev
*) p
->next
;
2244 if (lp
->flags
& ISDN_NET_CALLBACK
) {
2247 * Is the state MANUAL?
2248 * If so, no callback can be made,
2249 * so reject actively.
2251 if (ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_OFF
) {
2252 restore_flags(flags
);
2253 printk(KERN_INFO
"incoming call for callback, interface %s `off' -> rejected\n",
2257 printk(KERN_DEBUG
"%s: call from %s -> %s, start callback\n",
2260 /* Grab a free ISDN-Channel */
2261 if ((chi
= isdn_get_free_channel(ISDN_USAGE_NET
, lp
->l2_proto
,
2264 lp
->pre_channel
)) < 0) {
2265 printk(KERN_WARNING
"isdn_net_find_icall: No channel for %s\n", lp
->name
);
2266 restore_flags(flags
);
2269 /* Setup dialstate. */
2272 /* Connect interface with channel */
2273 isdn_net_bind_channel(lp
, chi
);
2274 #ifdef CONFIG_ISDN_PPP
2275 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2276 if (isdn_ppp_bind(lp
) < 0) {
2277 isdn_net_unbind_channel(lp
);
2278 restore_flags(flags
);
2282 /* Initiate dialing by returning 2 or 4 */
2283 restore_flags(flags
);
2284 return (lp
->flags
& ISDN_NET_CBHUP
) ? 2 : 4;
2286 printk(KERN_WARNING
"isdn_net: %s: No phone number\n", lp
->name
);
2287 restore_flags(flags
);
2290 printk(KERN_DEBUG
"%s: call from %s -> %s accepted\n", lp
->name
, nr
,
2292 /* if this interface is dialing, it does it probably on a different
2293 device, so free this device */
2294 if ((lp
->dialstate
== 4) || (lp
->dialstate
== 12)) {
2295 #ifdef CONFIG_ISDN_PPP
2296 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2299 isdn_free_channel(lp
->isdn_device
, lp
->isdn_channel
,
2302 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2303 dev
->usage
[idx
] |= ISDN_USAGE_NET
;
2304 strcpy(dev
->num
[idx
], nr
);
2306 dev
->st_netdev
[idx
] = lp
->netdev
;
2307 lp
->isdn_device
= di
;
2308 lp
->isdn_channel
= ch
;
2310 lp
->flags
|= ISDN_NET_CONNECTED
;
2315 lp
->hupflags
|= ISDN_WAITCHARGE
;
2316 lp
->hupflags
&= ~ISDN_HAVECHARGE
;
2317 #ifdef CONFIG_ISDN_PPP
2318 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2319 if (isdn_ppp_bind(lp
) < 0) {
2320 isdn_net_unbind_channel(lp
);
2321 restore_flags(flags
);
2325 restore_flags(flags
);
2330 p
= (isdn_net_dev
*) p
->next
;
2332 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2333 if (!ematch
|| dev
->net_verbose
)
2334 printk(KERN_INFO
"isdn_net: call from %s -> %d %s ignored\n", nr
, di
, eaz
);
2335 restore_flags(flags
);
2336 return (wret
== 2)?5:0;
2340 * Search list of net-interfaces for an interface with given name.
2343 isdn_net_findif(char *name
)
2345 isdn_net_dev
*p
= dev
->netdev
;
2348 if (!strcmp(p
->local
->name
, name
))
2350 p
= (isdn_net_dev
*) p
->next
;
2352 return (isdn_net_dev
*) NULL
;
2356 * Force a net-interface to dial out.
2357 * This is called from the userlevel-routine below or
2358 * from isdn_net_start_xmit().
2361 isdn_net_force_dial_lp(isdn_net_local
* lp
)
2363 if ((!(lp
->flags
& ISDN_NET_CONNECTED
)) && !lp
->dialstate
) {
2370 /* Grab a free ISDN-Channel */
2371 if ((chi
= isdn_get_free_channel(ISDN_USAGE_NET
, lp
->l2_proto
,
2374 lp
->pre_channel
)) < 0) {
2375 printk(KERN_WARNING
"isdn_net_force_dial: No channel for %s\n", lp
->name
);
2376 restore_flags(flags
);
2380 /* Connect interface with channel */
2381 isdn_net_bind_channel(lp
, chi
);
2382 #ifdef CONFIG_ISDN_PPP
2383 if (lp
->p_encap
== ISDN_NET_ENCAP_SYNCPPP
)
2384 if (isdn_ppp_bind(lp
) < 0) {
2385 isdn_net_unbind_channel(lp
);
2386 restore_flags(flags
);
2390 /* Initiate dialing */
2391 restore_flags(flags
);
2401 * This is called from certain upper protocol layers (multilink ppp
2402 * and x25iface encapsulation module) that want to initiate dialing
2406 isdn_net_dial_req(isdn_net_local
* lp
)
2408 /* is there a better error code? */
2409 if (!(ISDN_NET_DIALMODE(*lp
) == ISDN_NET_DM_AUTO
)) return -EBUSY
;
2411 return isdn_net_force_dial_lp(lp
);
2415 * Force a net-interface to dial out.
2416 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2419 isdn_net_force_dial(char *name
)
2421 isdn_net_dev
*p
= isdn_net_findif(name
);
2425 return (isdn_net_force_dial_lp(p
->local
));
2429 * Allocate a new network-interface and initialize its data structures.
2432 isdn_net_new(char *name
, struct net_device
*master
)
2434 isdn_net_dev
*netdev
;
2436 /* Avoid creating an existing interface */
2437 if (isdn_net_findif(name
)) {
2438 printk(KERN_WARNING
"isdn_net: interface %s already exists\n", name
);
2441 if (!(netdev
= (isdn_net_dev
*) kmalloc(sizeof(isdn_net_dev
), GFP_KERNEL
))) {
2442 printk(KERN_WARNING
"isdn_net: Could not allocate net-device\n");
2445 memset(netdev
, 0, sizeof(isdn_net_dev
));
2446 if (!(netdev
->local
= (isdn_net_local
*) kmalloc(sizeof(isdn_net_local
), GFP_KERNEL
))) {
2447 printk(KERN_WARNING
"isdn_net: Could not allocate device locals\n");
2450 memset(netdev
->local
, 0, sizeof(isdn_net_local
));
2452 strcpy(netdev
->local
->name
, " ");
2454 strcpy(netdev
->local
->name
, name
);
2455 netdev
->dev
.name
= netdev
->local
->name
;
2456 netdev
->dev
.priv
= netdev
->local
;
2457 netdev
->dev
.init
= isdn_net_init
;
2458 netdev
->local
->p_encap
= ISDN_NET_ENCAP_RAWIP
;
2460 /* Device shall be a slave */
2461 struct net_device
*p
= (((isdn_net_local
*) master
->priv
)->slave
);
2462 struct net_device
*q
= master
;
2464 netdev
->local
->master
= master
;
2465 /* Put device at end of slave-chain */
2468 p
= (((isdn_net_local
*) p
->priv
)->slave
);
2470 ((isdn_net_local
*) q
->priv
)->slave
= &(netdev
->dev
);
2473 q
->start
= master
->start
;
2475 /* Device shall be a master */
2476 if (register_netdev(&netdev
->dev
) != 0) {
2477 printk(KERN_WARNING
"isdn_net: Could not register net-device\n");
2478 kfree(netdev
->local
);
2483 netdev
->local
->magic
= ISDN_NET_MAGIC
;
2485 #ifdef CONFIG_ISDN_PPP
2486 netdev
->mp_last
= NULL
; /* mpqueue is empty */
2487 netdev
->ib
.next_num
= 0;
2488 netdev
->ib
.last
= NULL
;
2490 netdev
->queue
= netdev
->local
;
2491 netdev
->local
->last
= netdev
->local
;
2492 netdev
->local
->netdev
= netdev
;
2493 netdev
->local
->next
= netdev
->local
;
2495 netdev
->local
->isdn_device
= -1;
2496 netdev
->local
->isdn_channel
= -1;
2497 netdev
->local
->pre_device
= -1;
2498 netdev
->local
->pre_channel
= -1;
2499 netdev
->local
->exclusive
= -1;
2500 netdev
->local
->ppp_slot
= -1;
2501 netdev
->local
->pppbind
= -1;
2502 netdev
->local
->sav_skb
= NULL
;
2503 netdev
->local
->first_skb
= NULL
;
2504 netdev
->local
->l2_proto
= ISDN_PROTO_L2_X75I
;
2505 netdev
->local
->l3_proto
= ISDN_PROTO_L3_TRANS
;
2506 netdev
->local
->triggercps
= 6000;
2507 netdev
->local
->slavedelay
= 10 * HZ
;
2508 netdev
->local
->srobin
= &netdev
->dev
;
2509 netdev
->local
->hupflags
= ISDN_INHUP
; /* Do hangup even on incoming calls */
2510 netdev
->local
->onhtime
= 10; /* Default hangup-time for saving costs
2511 of those who forget configuring this */
2512 netdev
->local
->dialmax
= 1;
2513 netdev
->local
->flags
= ISDN_NET_CBHUP
| ISDN_NET_DM_MANUAL
; /* Hangup before Callback, manual dial */
2514 netdev
->local
->cbdelay
= 25; /* Wait 5 secs before Callback */
2515 netdev
->local
->dialtimeout
= -1; /* Infinite Dial-Timeout */
2516 netdev
->local
->dialwait
= 5 * HZ
; /* Wait 5 sec. after failed dial */
2517 netdev
->local
->dialstarted
= 0; /* Jiffies of last dial-start */
2518 netdev
->local
->dialwait_timer
= 0; /* Jiffies of earliest next dial-start */
2520 /* Put into to netdev-chain */
2521 netdev
->next
= (void *) dev
->netdev
;
2522 dev
->netdev
= netdev
;
2523 return netdev
->dev
.name
;
2527 isdn_net_newslave(char *parm
)
2529 char *p
= strchr(parm
, ',');
2534 /* Slave-Name MUST not be empty */
2537 strcpy(newname
, p
+ 1);
2539 /* Master must already exist */
2540 if (!(n
= isdn_net_findif(parm
)))
2542 /* Master must be a real interface, not a slave */
2543 if (n
->local
->master
)
2545 /* Master must not be started yet */
2548 return (isdn_net_new(newname
, &(n
->dev
)));
2554 * Set interface-parameters.
2555 * Always set all parameters, so the user-level application is responsible
2556 * for not overwriting existing setups. It has to get the current
2557 * setup first, if only selected parameters are to be changed.
2560 isdn_net_setcfg(isdn_net_ioctl_cfg
* cfg
)
2562 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2568 #ifdef CONFIG_ISDN_X25
2572 isdn_net_local
*lp
= p
->local
;
2574 /* See if any registered driver supports the features we want */
2575 features
= ((1 << cfg
->l2_proto
) << ISDN_FEATURE_L2_SHIFT
) |
2576 ((1 << cfg
->l3_proto
) << ISDN_FEATURE_L3_SHIFT
);
2577 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2579 if ((dev
->drv
[i
]->interface
->features
& features
) == features
)
2581 if (i
== ISDN_MAX_DRIVERS
) {
2582 printk(KERN_WARNING
"isdn_net: No driver with selected features\n");
2585 if (lp
->p_encap
!= cfg
->p_encap
){
2586 #ifdef CONFIG_ISDN_X25
2587 struct concap_proto
* cprot
= p
-> cprot
;
2591 "%s: cannot change encap when if is up\n",
2595 #ifdef CONFIG_ISDN_X25
2596 /* delete old encapsulation protocol if present ... */
2598 cli(); /* avoid races with incoming events trying to
2599 call cprot->pops methods */
2600 if( cprot
&& cprot
-> pops
)
2601 cprot
-> pops
-> proto_del ( cprot
);
2604 restore_flags(flags
);
2605 /* ... , prepare for configuration of new one ... */
2606 switch ( cfg
-> p_encap
){
2607 case ISDN_NET_ENCAP_X25IFACE
:
2608 lp
-> dops
= &isdn_concap_reliable_dl_dops
;
2610 /* ... and allocate new one ... */
2611 p
-> cprot
= isdn_concap_new( cfg
-> p_encap
);
2612 /* p -> cprot == NULL now if p_encap is not supported
2613 by means of the concap_proto mechanism */
2614 /* the protocol is not configured yet; this will
2615 happen later when isdn_net_reset() is called */
2618 switch ( cfg
->p_encap
) {
2619 case ISDN_NET_ENCAP_SYNCPPP
:
2620 #ifndef CONFIG_ISDN_PPP
2621 printk(KERN_WARNING
"%s: SyncPPP support not configured\n",
2625 p
->dev
.type
= ARPHRD_PPP
; /* change ARP type */
2626 p
->dev
.addr_len
= 0;
2629 case ISDN_NET_ENCAP_X25IFACE
:
2630 #ifndef CONFIG_ISDN_X25
2631 printk(KERN_WARNING
"%s: isdn-x25 support not configured\n",
2635 p
->dev
.type
= ARPHRD_X25
; /* change ARP type */
2636 p
->dev
.addr_len
= 0;
2640 if( cfg
->p_encap
>= 0 &&
2641 cfg
->p_encap
<= ISDN_NET_ENCAP_MAX_ENCAP
)
2644 "%s: encapsulation protocol %d not supported\n",
2645 p
->local
->name
, cfg
->p_encap
);
2648 if (strlen(cfg
->drvid
)) {
2649 /* A bind has been requested ... */
2655 strcpy(drvid
, cfg
->drvid
);
2656 if ((c
= strchr(drvid
, ','))) {
2657 /* The channel-number is appended to the driver-Id with a comma */
2658 chidx
= (int) simple_strtoul(c
+ 1, &e
, 10);
2663 for (i
= 0; i
< ISDN_MAX_DRIVERS
; i
++)
2664 /* Lookup driver-Id in array */
2665 if (!(strcmp(dev
->drvid
[i
], drvid
))) {
2669 if ((drvidx
== -1) || (chidx
== -1))
2670 /* Either driver-Id or channel-number invalid */
2673 /* Parameters are valid, so get them */
2674 drvidx
= lp
->pre_device
;
2675 chidx
= lp
->pre_channel
;
2677 if (cfg
->exclusive
> 0) {
2680 /* If binding is exclusive, try to grab the channel */
2682 if ((i
= isdn_get_free_channel(ISDN_USAGE_NET
, lp
->l2_proto
,
2686 /* Grab failed, because desired channel is in use */
2688 restore_flags(flags
);
2691 /* All went ok, so update isdninfo */
2692 dev
->usage
[i
] = ISDN_USAGE_EXCLUSIVE
;
2694 restore_flags(flags
);
2697 /* Non-exclusive binding or unbind. */
2699 if ((lp
->pre_device
!= -1) && (cfg
->exclusive
== -1)) {
2700 isdn_unexclusive_channel(lp
->pre_device
, lp
->pre_channel
);
2701 isdn_free_channel(lp
->pre_device
, lp
->pre_channel
, ISDN_USAGE_NET
);
2706 strcpy(lp
->msn
, cfg
->eaz
);
2707 lp
->pre_device
= drvidx
;
2708 lp
->pre_channel
= chidx
;
2709 lp
->onhtime
= cfg
->onhtime
;
2710 lp
->charge
= cfg
->charge
;
2711 lp
->l2_proto
= cfg
->l2_proto
;
2712 lp
->l3_proto
= cfg
->l3_proto
;
2713 lp
->cbdelay
= cfg
->cbdelay
;
2714 lp
->dialmax
= cfg
->dialmax
;
2715 lp
->triggercps
= cfg
->triggercps
;
2716 lp
->slavedelay
= cfg
->slavedelay
* HZ
;
2717 lp
->pppbind
= cfg
->pppbind
;
2718 lp
->dialtimeout
= cfg
->dialtimeout
>= 0 ? cfg
->dialtimeout
* HZ
: -1;
2719 lp
->dialwait
= cfg
->dialwait
* HZ
;
2721 lp
->flags
|= ISDN_NET_SECURE
;
2723 lp
->flags
&= ~ISDN_NET_SECURE
;
2725 lp
->flags
|= ISDN_NET_CBHUP
;
2727 lp
->flags
&= ~ISDN_NET_CBHUP
;
2728 switch (cfg
->callback
) {
2730 lp
->flags
&= ~(ISDN_NET_CALLBACK
| ISDN_NET_CBOUT
);
2733 lp
->flags
|= ISDN_NET_CALLBACK
;
2734 lp
->flags
&= ~ISDN_NET_CBOUT
;
2737 lp
->flags
|= ISDN_NET_CBOUT
;
2738 lp
->flags
&= ~ISDN_NET_CALLBACK
;
2741 lp
->flags
&= ~ISDN_NET_DIALMODE_MASK
; /* first all bits off */
2742 if (cfg
->dialmode
&& !(cfg
->dialmode
& ISDN_NET_DIALMODE_MASK
)) {
2743 /* old isdnctrl version, where only 0 or 1 is given */
2745 "Old isdnctrl version detected! Please update.\n");
2746 lp
->flags
|= ISDN_NET_DM_OFF
; /* turn on `off' bit */
2749 lp
->flags
|= cfg
->dialmode
; /* turn on selected bits */
2752 lp
->hupflags
|= ISDN_CHARGEHUP
;
2754 lp
->hupflags
&= ~ISDN_CHARGEHUP
;
2756 lp
->hupflags
|= ISDN_INHUP
;
2758 lp
->hupflags
&= ~ISDN_INHUP
;
2759 if (cfg
->chargeint
> 10) {
2760 lp
->hupflags
|= ISDN_CHARGEHUP
| ISDN_HAVECHARGE
| ISDN_MANCHARGE
;
2761 lp
->chargeint
= cfg
->chargeint
* HZ
;
2763 if (cfg
->p_encap
!= lp
->p_encap
) {
2764 if (cfg
->p_encap
== ISDN_NET_ENCAP_RAWIP
) {
2765 p
->dev
.hard_header
= NULL
;
2766 p
->dev
.hard_header_cache
= NULL
;
2767 p
->dev
.header_cache_update
= NULL
;
2768 p
->dev
.flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2770 p
->dev
.hard_header
= isdn_net_header
;
2771 if (cfg
->p_encap
== ISDN_NET_ENCAP_ETHER
) {
2772 p
->dev
.hard_header_cache
= lp
->org_hhc
;
2773 p
->dev
.header_cache_update
= lp
->org_hcu
;
2774 p
->dev
.flags
= IFF_BROADCAST
| IFF_MULTICAST
;
2776 p
->dev
.hard_header_cache
= NULL
;
2777 p
->dev
.header_cache_update
= NULL
;
2778 p
->dev
.flags
= IFF_NOARP
|IFF_POINTOPOINT
;
2782 lp
->p_encap
= cfg
->p_encap
;
2789 * Perform get-interface-parameters.ioctl
2792 isdn_net_getcfg(isdn_net_ioctl_cfg
* cfg
)
2794 isdn_net_dev
*p
= isdn_net_findif(cfg
->name
);
2797 isdn_net_local
*lp
= p
->local
;
2799 strcpy(cfg
->eaz
, lp
->msn
);
2800 cfg
->exclusive
= lp
->exclusive
;
2801 if (lp
->pre_device
>= 0) {
2802 sprintf(cfg
->drvid
, "%s,%d", dev
->drvid
[lp
->pre_device
],
2805 cfg
->drvid
[0] = '\0';
2806 cfg
->onhtime
= lp
->onhtime
;
2807 cfg
->charge
= lp
->charge
;
2808 cfg
->l2_proto
= lp
->l2_proto
;
2809 cfg
->l3_proto
= lp
->l3_proto
;
2810 cfg
->p_encap
= lp
->p_encap
;
2811 cfg
->secure
= (lp
->flags
& ISDN_NET_SECURE
) ? 1 : 0;
2813 if (lp
->flags
& ISDN_NET_CALLBACK
)
2815 if (lp
->flags
& ISDN_NET_CBOUT
)
2817 cfg
->cbhup
= (lp
->flags
& ISDN_NET_CBHUP
) ? 1 : 0;
2818 cfg
->dialmode
= lp
->flags
& ISDN_NET_DIALMODE_MASK
;
2819 cfg
->chargehup
= (lp
->hupflags
& 4) ? 1 : 0;
2820 cfg
->ihup
= (lp
->hupflags
& 8) ? 1 : 0;
2821 cfg
->cbdelay
= lp
->cbdelay
;
2822 cfg
->dialmax
= lp
->dialmax
;
2823 cfg
->triggercps
= lp
->triggercps
;
2824 cfg
->slavedelay
= lp
->slavedelay
/ HZ
;
2825 cfg
->chargeint
= (lp
->hupflags
& ISDN_CHARGEHUP
) ?
2826 (lp
->chargeint
/ HZ
) : 0;
2827 cfg
->pppbind
= lp
->pppbind
;
2828 cfg
->dialtimeout
= lp
->dialtimeout
>= 0 ? lp
->dialtimeout
/ HZ
: -1;
2829 cfg
->dialwait
= lp
->dialwait
/ HZ
;
2831 strcpy(cfg
->slave
, ((isdn_net_local
*) lp
->slave
->priv
)->name
);
2833 cfg
->slave
[0] = '\0';
2835 strcpy(cfg
->master
, ((isdn_net_local
*) lp
->master
->priv
)->name
);
2837 cfg
->master
[0] = '\0';
2844 * Add a phone-number to an interface.
2847 isdn_net_addphone(isdn_net_ioctl_phone
* phone
)
2849 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2852 if (isdn_net_checkwild(phone
->phone
) && (phone
->outgoing
& 1))
2855 if (!(n
= (isdn_net_phone
*) kmalloc(sizeof(isdn_net_phone
), GFP_KERNEL
)))
2857 strcpy(n
->num
, phone
->phone
);
2858 n
->next
= p
->local
->phone
[phone
->outgoing
& 1];
2859 p
->local
->phone
[phone
->outgoing
& 1] = n
;
2866 * Copy a string of all phone-numbers of an interface to user space.
2867 * This might sleep and must be called with the isdn semaphore down.
2870 isdn_net_getphones(isdn_net_ioctl_phone
* phone
, char *phones
)
2872 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2873 int inout
= phone
->outgoing
& 1;
2881 for (n
= p
->local
->phone
[inout
]; n
; n
= n
->next
) {
2883 put_user(' ', phones
++);
2886 if (copy_to_user(phones
, n
->num
, strlen(n
->num
) + 1)) {
2889 phones
+= strlen(n
->num
);
2890 count
+= strlen(n
->num
);
2893 put_user(0, phones
);
2899 * Copy a string containing the peer's phone number of a connected interface
2903 isdn_net_getpeer(isdn_net_ioctl_phone
*phone
, isdn_net_ioctl_phone
*peer
)
2905 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2908 if (!p
) return -ENODEV
;
2910 * Theoretical race: while this executes, the remote number might
2911 * become invalid (hang up) or change (new connection), resulting
2912 * in (partially) wrong number copied to user. This race
2913 * currently ignored.
2915 ch
= p
->local
->isdn_channel
;
2916 dv
= p
->local
->isdn_device
;
2917 if(ch
<0 && dv
<0) return -ENOTCONN
;
2918 idx
= isdn_dc2minor(dv
, ch
);
2919 if (idx
<0) return -ENODEV
;
2920 /* for pre-bound channels, we need this extra check */
2921 if ( strncmp(dev
->num
[idx
],"???",3) == 0 ) return -ENOTCONN
;
2922 strncpy(phone
->phone
,dev
->num
[idx
],ISDN_MSNLEN
);
2923 phone
->outgoing
=USG_OUTGOING(dev
->usage
[idx
]);
2924 if ( copy_to_user(peer
,phone
,sizeof(*peer
)) ) return -EFAULT
;
2928 * Delete a phone-number from an interface.
2931 isdn_net_delphone(isdn_net_ioctl_phone
* phone
)
2933 isdn_net_dev
*p
= isdn_net_findif(phone
->name
);
2934 int inout
= phone
->outgoing
& 1;
2942 n
= p
->local
->phone
[inout
];
2945 if (!strcmp(n
->num
, phone
->phone
)) {
2946 if (p
->local
->dial
== n
)
2947 p
->local
->dial
= n
->next
;
2951 p
->local
->phone
[inout
] = n
->next
;
2953 restore_flags(flags
);
2957 n
= (isdn_net_phone
*) n
->next
;
2959 restore_flags(flags
);
2966 * Delete all phone-numbers of an interface.
2969 isdn_net_rmallphone(isdn_net_dev
* p
)
2978 for (i
= 0; i
< 2; i
++) {
2979 n
= p
->local
->phone
[i
];
2985 p
->local
->phone
[i
] = NULL
;
2987 p
->local
->dial
= NULL
;
2988 restore_flags(flags
);
2993 * Force a hangup of a network-interface.
2996 isdn_net_force_hangup(char *name
)
2998 isdn_net_dev
*p
= isdn_net_findif(name
);
2999 struct net_device
*q
;
3002 if (p
->local
->isdn_device
< 0)
3004 q
= p
->local
->slave
;
3005 /* If this interface has slaves, do a hangup for them also. */
3008 q
= (((isdn_net_local
*) q
->priv
)->slave
);
3010 isdn_net_hangup(&p
->dev
);
3017 * Helper-function for isdn_net_rm: Do the real work.
3020 isdn_net_realrm(isdn_net_dev
* p
, isdn_net_dev
* q
)
3026 if (p
->local
->master
) {
3027 /* If it's a slave, it may be removed even if it is busy. However
3028 * it has to be hung up first.
3030 isdn_net_hangup(&p
->dev
);
3034 restore_flags(flags
);
3037 #ifdef CONFIG_ISDN_X25
3038 if( p
-> cprot
&& p
-> cprot
-> pops
)
3039 p
-> cprot
-> pops
-> proto_del ( p
-> cprot
);
3041 /* Free all phone-entries */
3042 isdn_net_rmallphone(p
);
3043 /* If interface is bound exclusive, free channel-usage */
3044 if (p
->local
->exclusive
!= -1)
3045 isdn_unexclusive_channel(p
->local
->pre_device
, p
->local
->pre_channel
);
3046 if (p
->local
->master
) {
3047 /* It's a slave-device, so update master's slave-pointer if necessary */
3048 if (((isdn_net_local
*) (p
->local
->master
->priv
))->slave
== &p
->dev
)
3049 ((isdn_net_local
*) (p
->local
->master
->priv
))->slave
= p
->local
->slave
;
3051 /* Unregister only if it's a master-device */
3052 p
->dev
.hard_header_cache
= p
->local
->org_hhc
;
3053 p
->dev
.header_cache_update
= p
->local
->org_hcu
;
3054 unregister_netdev(&p
->dev
);
3056 /* Unlink device from chain */
3060 dev
->netdev
= p
->next
;
3061 if (p
->local
->slave
) {
3062 /* If this interface has a slave, remove it also */
3063 char *slavename
= ((isdn_net_local
*) (p
->local
->slave
->priv
))->name
;
3064 isdn_net_dev
*n
= dev
->netdev
;
3067 if (!strcmp(n
->local
->name
, slavename
)) {
3068 isdn_net_realrm(n
, q
);
3072 n
= (isdn_net_dev
*) n
->next
;
3075 /* If no more net-devices remain, disable auto-hangup timer */
3076 if (dev
->netdev
== NULL
)
3077 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3078 restore_flags(flags
);
3087 * Remove a single network-interface.
3090 isdn_net_rm(char *name
)
3095 /* Search name in netdev-chain */
3099 if (!strcmp(p
->local
->name
, name
))
3100 return (isdn_net_realrm(p
, q
));
3102 p
= (isdn_net_dev
*) p
->next
;
3104 /* If no more net-devices remain, disable auto-hangup timer */
3105 if (dev
->netdev
== NULL
)
3106 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP
, 0);
3111 * Remove all network-interfaces
3114 isdn_net_rmall(void)
3119 /* Walk through netdev-chain */
3122 while (dev
->netdev
) {
3123 if (!dev
->netdev
->local
->master
) {
3124 /* Remove master-devices only, slaves get removed with their master */
3125 if ((ret
= isdn_net_realrm(dev
->netdev
, NULL
))) {
3126 restore_flags(flags
);
3132 restore_flags(flags
);