File: /usr/src/linux/drivers/isdn/isdn_net.c
1 /* $Id: isdn_net.c,v 1.140.6.8 2001/08/14 14:04:21 kai Exp $
2
3 * Linux ISDN subsystem, network interfaces and related functions (linklevel).
4 *
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)
8 *
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)
12 * any later version.
13 *
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.
18 *
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.
22 *
23 */
24
25 /* Jan 2001: fix CISCO HDLC Bjoern A. Zeeb <i4l@zabbadoz.net>
26 * for info on the protocol, see
27 * http://i4l.zabbadoz.net/i4l/cisco-hdlc.txt
28 */
29
30 #include <linux/config.h>
31 #define __NO_VERSION__
32 #include <linux/module.h>
33 #include <linux/isdn.h>
34 #include <net/arp.h>
35 #include <net/dst.h>
36 #include <net/pkt_sched.h>
37 #include <linux/inetdevice.h>
38 #include "isdn_common.h"
39 #include "isdn_net.h"
40 #ifdef CONFIG_ISDN_PPP
41 #include "isdn_ppp.h"
42 #endif
43 #ifdef CONFIG_ISDN_X25
44 #include <linux/concap.h>
45 #include "isdn_concap.h"
46 #endif
47
48
49 /*
50 * Outline of new tbusy handling:
51 *
52 * Old method, roughly spoken, consisted of setting tbusy when entering
53 * isdn_net_start_xmit() and at several other locations and clearing
54 * it from isdn_net_start_xmit() thread when sending was successful.
55 *
56 * With 2.3.x multithreaded network core, to prevent problems, tbusy should
57 * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
58 * condition is detected. Other threads (in particular isdn_net_stat_callb())
59 * are only allowed to clear tbusy.
60 *
61 * -HE
62 */
63
64 /*
65 * About SOFTNET:
66 * Most of the changes were pretty obvious and basically done by HE already.
67 *
68 * One problem of the isdn net device code is that is uses struct net_device
69 * for masters and slaves. However, only master interface are registered to
70 * the network layer, and therefore, it only makes sense to call netif_*
71 * functions on them.
72 *
73 * --KG
74 */
75
76 /*
77 * Find out if the netdevice has been ifup-ed yet.
78 * For slaves, look at the corresponding master.
79 */
80 static __inline__ int isdn_net_device_started(isdn_net_dev *n)
81 {
82 isdn_net_local *lp = n->local;
83 struct net_device *dev;
84
85 if (lp->master)
86 dev = lp->master;
87 else
88 dev = &n->dev;
89 return netif_running(dev);
90 }
91
92 /*
93 * wake up the network -> net_device queue.
94 * For slaves, wake the corresponding master interface.
95 */
96 static __inline__ void isdn_net_device_wake_queue(isdn_net_local *lp)
97 {
98 if (lp->master)
99 netif_wake_queue(lp->master);
100 else
101 netif_wake_queue(&lp->netdev->dev);
102 }
103
104 /*
105 * stop the network -> net_device queue.
106 * For slaves, stop the corresponding master interface.
107 */
108 static __inline__ void isdn_net_device_stop_queue(isdn_net_local *lp)
109 {
110 if (lp->master)
111 netif_stop_queue(lp->master);
112 else
113 netif_stop_queue(&lp->netdev->dev);
114 }
115
116 /*
117 * find out if the net_device which this lp belongs to (lp can be
118 * master or slave) is busy. It's busy iff all (master and slave)
119 * queues are busy
120 */
121 static __inline__ int isdn_net_device_busy(isdn_net_local *lp)
122 {
123 isdn_net_local *nlp;
124 isdn_net_dev *nd;
125 unsigned long flags;
126
127 if (!isdn_net_lp_busy(lp))
128 return 0;
129
130 if (lp->master)
131 nd = ((isdn_net_local *) lp->master->priv)->netdev;
132 else
133 nd = lp->netdev;
134
135 spin_lock_irqsave(&nd->queue_lock, flags);
136 nlp = lp->next;
137 while (nlp != lp) {
138 if (!isdn_net_lp_busy(nlp)) {
139 spin_unlock_irqrestore(&nd->queue_lock, flags);
140 return 0;
141 }
142 nlp = nlp->next;
143 }
144 spin_unlock_irqrestore(&nd->queue_lock, flags);
145 return 1;
146 }
147
148 static __inline__ void isdn_net_inc_frame_cnt(isdn_net_local *lp)
149 {
150 atomic_inc(&lp->frame_cnt);
151 if (isdn_net_device_busy(lp))
152 isdn_net_device_stop_queue(lp);
153 }
154
155 static __inline__ void isdn_net_dec_frame_cnt(isdn_net_local *lp)
156 {
157 atomic_dec(&lp->frame_cnt);
158
159 if (!(isdn_net_device_busy(lp))) {
160 if (!skb_queue_empty(&lp->super_tx_queue)) {
161 queue_task(&lp->tqueue, &tq_immediate);
162 mark_bh(IMMEDIATE_BH);
163 } else {
164 isdn_net_device_wake_queue(lp);
165 }
166 }
167 }
168
169 static __inline__ void isdn_net_zero_frame_cnt(isdn_net_local *lp)
170 {
171 atomic_set(&lp->frame_cnt, 0);
172 }
173
174 /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
175 * to be safe.
176 * For 2.3.x we push it up to 20 secs, because call establishment
177 * (in particular callback) may take such a long time, and we
178 * don't want confusing messages in the log. However, there is a slight
179 * possibility that this large timeout will break other things like MPPP,
180 * which might rely on the tx timeout. If so, we'll find out this way...
181 */
182
183 #define ISDN_NET_TX_TIMEOUT (20*HZ)
184
185 /* Prototypes */
186
187 int isdn_net_force_dial_lp(isdn_net_local *);
188 static int isdn_net_start_xmit(struct sk_buff *, struct net_device *);
189
190 static void isdn_net_ciscohdlck_connected(isdn_net_local *lp);
191 static void isdn_net_ciscohdlck_disconnected(isdn_net_local *lp);
192
193 char *isdn_net_revision = "$Revision: 1.140.6.8 $";
194
195 /*
196 * Code for raw-networking over ISDN
197 */
198
199 static void
200 isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason)
201 {
202 if(skb) {
203
204 u_short proto = ntohs(skb->protocol);
205
206 printk(KERN_DEBUG "isdn_net: %s: %s, signalling dst_link_failure %s\n",
207 dev->name,
208 (reason != NULL) ? reason : "unknown",
209 (proto != ETH_P_IP) ? "Protocol != ETH_P_IP" : "");
210
211 dst_link_failure(skb);
212 }
213 else { /* dial not triggered by rawIP packet */
214 printk(KERN_DEBUG "isdn_net: %s: %s\n",
215 dev->name,
216 (reason != NULL) ? reason : "reason unknown");
217 }
218 }
219
220 static void
221 isdn_net_reset(struct net_device *dev)
222 {
223 #ifdef CONFIG_ISDN_X25
224 struct concap_device_ops * dops =
225 ( (isdn_net_local *) dev->priv ) -> dops;
226 struct concap_proto * cprot =
227 ( (isdn_net_local *) dev->priv ) -> netdev -> cprot;
228 #endif
229 ulong flags;
230
231 /* not sure if the cli() is needed at all --KG */
232 save_flags(flags);
233 cli(); /* Avoid glitch on writes to CMD regs */
234 #ifdef CONFIG_ISDN_X25
235 if( cprot && cprot -> pops && dops )
236 cprot -> pops -> restart ( cprot, dev, dops );
237 #endif
238 restore_flags(flags);
239 }
240
241 /* Open/initialize the board. */
242 static int
243 isdn_net_open(struct net_device *dev)
244 {
245 int i;
246 struct net_device *p;
247 struct in_device *in_dev;
248
249 /* moved here from isdn_net_reset, because only the master has an
250 interface associated which is supposed to be started. BTW:
251 we need to call netif_start_queue, not netif_wake_queue here */
252 netif_start_queue(dev);
253
254 isdn_net_reset(dev);
255 /* Fill in the MAC-level header (not needed, but for compatibility... */
256 for (i = 0; i < ETH_ALEN - sizeof(u32); i++)
257 dev->dev_addr[i] = 0xfc;
258 if ((in_dev = dev->ip_ptr) != NULL) {
259 /*
260 * Any address will do - we take the first
261 */
262 struct in_ifaddr *ifa = in_dev->ifa_list;
263 if (ifa != NULL)
264 memcpy(dev->dev_addr+2, &ifa->ifa_local, 4);
265 }
266
267 /* If this interface has slaves, start them also */
268
269 if ((p = (((isdn_net_local *) dev->priv)->slave))) {
270 while (p) {
271 isdn_net_reset(p);
272 p = (((isdn_net_local *) p->priv)->slave);
273 }
274 }
275 isdn_MOD_INC_USE_COUNT();
276 return 0;
277 }
278
279 /*
280 * Assign an ISDN-channel to a net-interface
281 */
282 static void
283 isdn_net_bind_channel(isdn_net_local * lp, int idx)
284 {
285 ulong flags;
286
287 save_flags(flags);
288 cli();
289 lp->flags |= ISDN_NET_CONNECTED;
290 lp->isdn_device = dev->drvmap[idx];
291 lp->isdn_channel = dev->chanmap[idx];
292 dev->rx_netdev[idx] = lp->netdev;
293 dev->st_netdev[idx] = lp->netdev;
294 restore_flags(flags);
295 }
296
297 /*
298 * unbind a net-interface (resets interface after an error)
299 */
300 static void
301 isdn_net_unbind_channel(isdn_net_local * lp)
302 {
303 ulong flags;
304
305 save_flags(flags);
306 cli();
307 skb_queue_purge(&lp->super_tx_queue);
308
309 if (!lp->master) { /* reset only master device */
310 /* Moral equivalent of dev_purge_queues():
311 BEWARE! This chunk of code cannot be called from hardware
312 interrupt handler. I hope it is true. --ANK
313 */
314 qdisc_reset(lp->netdev->dev.qdisc);
315 }
316 lp->dialstate = 0;
317 dev->rx_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
318 dev->st_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
319 isdn_free_channel(lp->isdn_device, lp->isdn_channel, ISDN_USAGE_NET);
320 lp->flags &= ~ISDN_NET_CONNECTED;
321 lp->isdn_device = -1;
322 lp->isdn_channel = -1;
323
324 restore_flags(flags);
325 }
326
327 /*
328 * Perform auto-hangup and cps-calculation for net-interfaces.
329 *
330 * auto-hangup:
331 * Increment idle-counter (this counter is reset on any incoming or
332 * outgoing packet), if counter exceeds configured limit either do a
333 * hangup immediately or - if configured - wait until just before the next
334 * charge-info.
335 *
336 * cps-calculation (needed for dynamic channel-bundling):
337 * Since this function is called every second, simply reset the
338 * byte-counter of the interface after copying it to the cps-variable.
339 */
340 unsigned long last_jiffies = -HZ;
341
342 void
343 isdn_net_autohup()
344 {
345 isdn_net_dev *p = dev->netdev;
346 int anymore;
347
348 anymore = 0;
349 while (p) {
350 isdn_net_local *l = p->local;
351 if ((jiffies - last_jiffies) == 0)
352 l->cps = l->transcount;
353 else
354 l->cps = (l->transcount * HZ) / (jiffies - last_jiffies);
355 l->transcount = 0;
356 if (dev->net_verbose > 3)
357 printk(KERN_DEBUG "%s: %d bogocps\n", l->name, l->cps);
358 if ((l->flags & ISDN_NET_CONNECTED) && (!l->dialstate)) {
359 anymore = 1;
360 l->huptimer++;
361 /*
362 * if there is some dialmode where timeout-hangup
363 * should _not_ be done, check for that here
364 */
365 if ((l->onhtime) &&
366 (l->huptimer > l->onhtime))
367 {
368 if (l->hupflags & ISDN_MANCHARGE &&
369 l->hupflags & ISDN_CHARGEHUP) {
370 while (jiffies - l->chargetime > l->chargeint)
371 l->chargetime += l->chargeint;
372 if (jiffies - l->chargetime >= l->chargeint - 2 * HZ)
373 if (l->outgoing || l->hupflags & ISDN_INHUP)
374 isdn_net_hangup(&p->dev);
375 } else if (l->outgoing) {
376 if (l->hupflags & ISDN_CHARGEHUP) {
377 if (l->hupflags & ISDN_WAITCHARGE) {
378 printk(KERN_DEBUG "isdn_net: Hupflags of %s are %X\n",
379 l->name, l->hupflags);
380 isdn_net_hangup(&p->dev);
381 } else if (jiffies - l->chargetime > l->chargeint) {
382 printk(KERN_DEBUG
383 "isdn_net: %s: chtime = %lu, chint = %d\n",
384 l->name, l->chargetime, l->chargeint);
385 isdn_net_hangup(&p->dev);
386 }
387 } else
388 isdn_net_hangup(&p->dev);
389 } else if (l->hupflags & ISDN_INHUP)
390 isdn_net_hangup(&p->dev);
391 }
392
393 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*l) == ISDN_NET_DM_OFF)) {
394 isdn_net_hangup(&p->dev);
395 break;
396 }
397 }
398 p = (isdn_net_dev *) p->next;
399 }
400 last_jiffies = jiffies;
401 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, anymore);
402 }
403
404 static void isdn_net_lp_disconnected(isdn_net_local *lp)
405 {
406 isdn_net_rm_from_bundle(lp);
407 }
408
409 /*
410 * Handle status-messages from ISDN-interfacecard.
411 * This function is called from within the main-status-dispatcher
412 * isdn_status_callback, which itself is called from the low-level driver.
413 * Return: 1 = Event handled, 0 = not for us or unknown Event.
414 */
415 int
416 isdn_net_stat_callback(int idx, isdn_ctrl *c)
417 {
418 isdn_net_dev *p = dev->st_netdev[idx];
419 int cmd = c->command;
420
421 if (p) {
422 isdn_net_local *lp = p->local;
423 #ifdef CONFIG_ISDN_X25
424 struct concap_proto *cprot = lp -> netdev -> cprot;
425 struct concap_proto_ops *pops = cprot ? cprot -> pops : 0;
426 #endif
427 switch (cmd) {
428 case ISDN_STAT_BSENT:
429 /* A packet has successfully been sent out */
430 if ((lp->flags & ISDN_NET_CONNECTED) &&
431 (!lp->dialstate)) {
432 isdn_net_dec_frame_cnt(lp);
433 lp->stats.tx_packets++;
434 lp->stats.tx_bytes += c->parm.length;
435 }
436 return 1;
437 case ISDN_STAT_DCONN:
438 /* D-Channel is up */
439 switch (lp->dialstate) {
440 case 4:
441 case 7:
442 case 8:
443 lp->dialstate++;
444 return 1;
445 case 12:
446 lp->dialstate = 5;
447 return 1;
448 }
449 break;
450 case ISDN_STAT_DHUP:
451 /* Either D-Channel-hangup or error during dialout */
452 #ifdef CONFIG_ISDN_X25
453 /* If we are not connencted then dialing had
454 failed. If there are generic encap protocol
455 receiver routines signal the closure of
456 the link*/
457
458 if( !(lp->flags & ISDN_NET_CONNECTED)
459 && pops && pops -> disconn_ind )
460 pops -> disconn_ind(cprot);
461 #endif /* CONFIG_ISDN_X25 */
462 if ((!lp->dialstate) && (lp->flags & ISDN_NET_CONNECTED)) {
463 if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
464 isdn_net_ciscohdlck_disconnected(lp);
465 #ifdef CONFIG_ISDN_PPP
466 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
467 isdn_ppp_free(lp);
468 #endif
469 isdn_net_lp_disconnected(lp);
470 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
471 printk(KERN_INFO "%s: remote hangup\n", lp->name);
472 printk(KERN_INFO "%s: Chargesum is %d\n", lp->name,
473 lp->charge);
474 isdn_net_unbind_channel(lp);
475 return 1;
476 }
477 break;
478 #ifdef CONFIG_ISDN_X25
479 case ISDN_STAT_BHUP:
480 /* B-Channel-hangup */
481 /* try if there are generic encap protocol
482 receiver routines and signal the closure of
483 the link */
484 if( pops && pops -> disconn_ind ){
485 pops -> disconn_ind(cprot);
486 return 1;
487 }
488 break;
489 #endif /* CONFIG_ISDN_X25 */
490 case ISDN_STAT_BCONN:
491 /* B-Channel is up */
492 isdn_net_zero_frame_cnt(lp);
493 switch (lp->dialstate) {
494 case 5:
495 case 6:
496 case 7:
497 case 8:
498 case 9:
499 case 10:
500 case 12:
501 if (lp->dialstate <= 6) {
502 dev->usage[idx] |= ISDN_USAGE_OUTGOING;
503 isdn_info_update();
504 } else
505 dev->rx_netdev[idx] = p;
506 lp->dialstate = 0;
507 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 1);
508 if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
509 isdn_net_ciscohdlck_connected(lp);
510 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP) {
511 if (lp->master) { /* is lp a slave? */
512 isdn_net_dev *nd = ((isdn_net_local *)lp->master->priv)->netdev;
513 isdn_net_add_to_bundle(nd, lp);
514 }
515 }
516 printk(KERN_INFO "isdn_net: %s connected\n", lp->name);
517 /* If first Chargeinfo comes before B-Channel connect,
518 * we correct the timestamp here.
519 */
520 lp->chargetime = jiffies;
521
522 /* reset dial-timeout */
523 lp->dialstarted = 0;
524 lp->dialwait_timer = 0;
525
526 #ifdef CONFIG_ISDN_PPP
527 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
528 isdn_ppp_wakeup_daemon(lp);
529 #endif
530 #ifdef CONFIG_ISDN_X25
531 /* try if there are generic concap receiver routines */
532 if( pops )
533 if( pops->connect_ind)
534 pops->connect_ind(cprot);
535 #endif /* CONFIG_ISDN_X25 */
536 /* ppp needs to do negotiations first */
537 if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
538 isdn_net_device_wake_queue(lp);
539 return 1;
540 }
541 break;
542 case ISDN_STAT_NODCH:
543 /* No D-Channel avail. */
544 if (lp->dialstate == 4) {
545 lp->dialstate--;
546 return 1;
547 }
548 break;
549 case ISDN_STAT_CINF:
550 /* Charge-info from TelCo. Calculate interval between
551 * charge-infos and set timestamp for last info for
552 * usage by isdn_net_autohup()
553 */
554 lp->charge++;
555 if (lp->hupflags & ISDN_HAVECHARGE) {
556 lp->hupflags &= ~ISDN_WAITCHARGE;
557 lp->chargeint = jiffies - lp->chargetime - (2 * HZ);
558 }
559 if (lp->hupflags & ISDN_WAITCHARGE)
560 lp->hupflags |= ISDN_HAVECHARGE;
561 lp->chargetime = jiffies;
562 printk(KERN_DEBUG "isdn_net: Got CINF chargetime of %s now %lu\n",
563 lp->name, lp->chargetime);
564 return 1;
565 }
566 }
567 return 0;
568 }
569
570 /*
571 * Perform dialout for net-interfaces and timeout-handling for
572 * D-Channel-up and B-Channel-up Messages.
573 * This function is initially called from within isdn_net_start_xmit() or
574 * or isdn_net_find_icall() after initializing the dialstate for an
575 * interface. If further calls are needed, the function schedules itself
576 * for a timer-callback via isdn_timer_function().
577 * The dialstate is also affected by incoming status-messages from
578 * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
579 */
580 void
581 isdn_net_dial(void)
582 {
583 isdn_net_dev *p = dev->netdev;
584 int anymore = 0;
585 int i;
586 ulong flags;
587 isdn_ctrl cmd;
588
589 while (p) {
590 isdn_net_local *lp = p->local;
591
592 #ifdef ISDN_DEBUG_NET_DIAL
593 if (lp->dialstate)
594 printk(KERN_DEBUG "%s: dialstate=%d\n", lp->name, lp->dialstate);
595 #endif
596 switch (lp->dialstate) {
597 case 0:
598 /* Nothing to do for this interface */
599 break;
600 case 1:
601 /* Initiate dialout. Set phone-number-pointer to first number
602 * of interface.
603 */
604 save_flags(flags);
605 cli();
606 lp->dial = lp->phone[1];
607 restore_flags(flags);
608 if (!lp->dial) {
609 printk(KERN_WARNING "%s: phone number deleted?\n",
610 lp->name);
611 isdn_net_hangup(&p->dev);
612 break;
613 }
614 anymore = 1;
615
616 if(lp->dialtimeout > 0)
617 if(lp->dialstarted == 0 || jiffies > (lp->dialstarted + lp->dialtimeout + lp->dialwait)) {
618 lp->dialstarted = jiffies;
619 lp->dialwait_timer = 0;
620 }
621
622 lp->dialstate++;
623 /* Fall through */
624 case 2:
625 /* Prepare dialing. Clear EAZ, then set EAZ. */
626 cmd.driver = lp->isdn_device;
627 cmd.arg = lp->isdn_channel;
628 cmd.command = ISDN_CMD_CLREAZ;
629 isdn_command(&cmd);
630 sprintf(cmd.parm.num, "%s", isdn_map_eaz2msn(lp->msn, cmd.driver));
631 cmd.command = ISDN_CMD_SETEAZ;
632 isdn_command(&cmd);
633 lp->dialretry = 0;
634 anymore = 1;
635 lp->dialstate++;
636 /* Fall through */
637 case 3:
638 /* Setup interface, dial current phone-number, switch to next number.
639 * If list of phone-numbers is exhausted, increment
640 * retry-counter.
641 */
642 if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF)) {
643 char *s;
644 if (dev->global_flags & ISDN_GLOBAL_STOPPED)
645 s = "dial suppressed: isdn system stopped";
646 else
647 s = "dial suppressed: dialmode `off'";
648 isdn_net_unreachable(&p->dev, 0, s);
649 isdn_net_hangup(&p->dev);
650 break;
651 }
652 cmd.driver = lp->isdn_device;
653 cmd.command = ISDN_CMD_SETL2;
654 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
655 isdn_command(&cmd);
656 cmd.driver = lp->isdn_device;
657 cmd.command = ISDN_CMD_SETL3;
658 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
659 isdn_command(&cmd);
660 cmd.driver = lp->isdn_device;
661 cmd.arg = lp->isdn_channel;
662 save_flags(flags);
663 cli();
664 if (!lp->dial) {
665 restore_flags(flags);
666 printk(KERN_WARNING "%s: phone number deleted?\n",
667 lp->name);
668 isdn_net_hangup(&p->dev);
669 break;
670 }
671 if (!strncmp(lp->dial->num, "LEASED", strlen("LEASED"))) {
672 restore_flags(flags);
673 lp->dialstate = 4;
674 printk(KERN_INFO "%s: Open leased line ...\n", lp->name);
675 } else {
676 if(lp->dialtimeout > 0)
677 if(jiffies > (lp->dialstarted + lp->dialtimeout)) {
678 restore_flags(flags);
679 lp->dialwait_timer = jiffies + lp->dialwait;
680 lp->dialstarted = 0;
681 isdn_net_unreachable(&p->dev, 0, "dial: timed out");
682 isdn_net_hangup(&p->dev);
683 break;
684 }
685
686 sprintf(cmd.parm.setup.phone, "%s", lp->dial->num);
687 /*
688 * Switch to next number or back to start if at end of list.
689 */
690 if (!(lp->dial = (isdn_net_phone *) lp->dial->next)) {
691 lp->dial = lp->phone[1];
692 lp->dialretry++;
693
694 if (lp->dialretry > lp->dialmax) {
695 restore_flags(flags);
696 if (lp->dialtimeout == 0) {
697 lp->dialwait_timer = jiffies + lp->dialwait;
698 lp->dialstarted = 0;
699 isdn_net_unreachable(&p->dev, 0, "dial: tried all numbers dialmax times");
700 }
701 isdn_net_hangup(&p->dev);
702 break;
703 }
704 }
705 restore_flags(flags);
706 cmd.driver = lp->isdn_device;
707 cmd.command = ISDN_CMD_DIAL;
708 cmd.parm.setup.si1 = 7;
709 cmd.parm.setup.si2 = 0;
710 sprintf(cmd.parm.setup.eazmsn, "%s",
711 isdn_map_eaz2msn(lp->msn, cmd.driver));
712 i = isdn_dc2minor(lp->isdn_device, lp->isdn_channel);
713 if (i >= 0) {
714 strcpy(dev->num[i], cmd.parm.setup.phone);
715 dev->usage[i] |= ISDN_USAGE_OUTGOING;
716 isdn_info_update();
717 }
718 printk(KERN_INFO "%s: dialing %d %s...\n", lp->name,
719 lp->dialretry, cmd.parm.setup.phone);
720 lp->dtimer = 0;
721 #ifdef ISDN_DEBUG_NET_DIAL
722 printk(KERN_DEBUG "dial: d=%d c=%d\n", lp->isdn_device,
723 lp->isdn_channel);
724 #endif
725 isdn_command(&cmd);
726 }
727 lp->huptimer = 0;
728 lp->outgoing = 1;
729 if (lp->chargeint) {
730 lp->hupflags |= ISDN_HAVECHARGE;
731 lp->hupflags &= ~ISDN_WAITCHARGE;
732 } else {
733 lp->hupflags |= ISDN_WAITCHARGE;
734 lp->hupflags &= ~ISDN_HAVECHARGE;
735 }
736 anymore = 1;
737 lp->dialstate =
738 (lp->cbdelay &&
739 (lp->flags & ISDN_NET_CBOUT)) ? 12 : 4;
740 break;
741 case 4:
742 /* Wait for D-Channel-connect.
743 * If timeout, switch back to state 3.
744 * Dialmax-handling moved to state 3.
745 */
746 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
747 lp->dialstate = 3;
748 anymore = 1;
749 break;
750 case 5:
751 /* Got D-Channel-Connect, send B-Channel-request */
752 cmd.driver = lp->isdn_device;
753 cmd.arg = lp->isdn_channel;
754 cmd.command = ISDN_CMD_ACCEPTB;
755 anymore = 1;
756 lp->dtimer = 0;
757 lp->dialstate++;
758 isdn_command(&cmd);
759 break;
760 case 6:
761 /* Wait for B- or D-Channel-connect. If timeout,
762 * switch back to state 3.
763 */
764 #ifdef ISDN_DEBUG_NET_DIAL
765 printk(KERN_DEBUG "dialtimer2: %d\n", lp->dtimer);
766 #endif
767 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
768 lp->dialstate = 3;
769 anymore = 1;
770 break;
771 case 7:
772 /* Got incoming Call, setup L2 and L3 protocols,
773 * then wait for D-Channel-connect
774 */
775 #ifdef ISDN_DEBUG_NET_DIAL
776 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
777 #endif
778 cmd.driver = lp->isdn_device;
779 cmd.command = ISDN_CMD_SETL2;
780 cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
781 isdn_command(&cmd);
782 cmd.driver = lp->isdn_device;
783 cmd.command = ISDN_CMD_SETL3;
784 cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
785 isdn_command(&cmd);
786 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT15)
787 isdn_net_hangup(&p->dev);
788 else {
789 anymore = 1;
790 lp->dialstate++;
791 }
792 break;
793 case 9:
794 /* Got incoming D-Channel-Connect, send B-Channel-request */
795 cmd.driver = lp->isdn_device;
796 cmd.arg = lp->isdn_channel;
797 cmd.command = ISDN_CMD_ACCEPTB;
798 isdn_command(&cmd);
799 anymore = 1;
800 lp->dtimer = 0;
801 lp->dialstate++;
802 break;
803 case 8:
804 case 10:
805 /* Wait for B- or D-channel-connect */
806 #ifdef ISDN_DEBUG_NET_DIAL
807 printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
808 #endif
809 if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
810 isdn_net_hangup(&p->dev);
811 else
812 anymore = 1;
813 break;
814 case 11:
815 /* Callback Delay */
816 if (lp->dtimer++ > lp->cbdelay)
817 lp->dialstate = 1;
818 anymore = 1;
819 break;
820 case 12:
821 /* Remote does callback. Hangup after cbdelay, then wait for incoming
822 * call (in state 4).
823 */
824 if (lp->dtimer++ > lp->cbdelay)
825 {
826 printk(KERN_INFO "%s: hangup waiting for callback ...\n", lp->name);
827 lp->dtimer = 0;
828 lp->dialstate = 4;
829 cmd.driver = lp->isdn_device;
830 cmd.command = ISDN_CMD_HANGUP;
831 cmd.arg = lp->isdn_channel;
832 isdn_command(&cmd);
833 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
834 }
835 anymore = 1;
836 break;
837 default:
838 printk(KERN_WARNING "isdn_net: Illegal dialstate %d for device %s\n",
839 lp->dialstate, lp->name);
840 }
841 p = (isdn_net_dev *) p->next;
842 }
843 isdn_timer_ctrl(ISDN_TIMER_NETDIAL, anymore);
844 }
845
846 /*
847 * Perform hangup for a net-interface.
848 */
849 void
850 isdn_net_hangup(struct net_device *d)
851 {
852 isdn_net_local *lp = (isdn_net_local *) d->priv;
853 isdn_ctrl cmd;
854 #ifdef CONFIG_ISDN_X25
855 struct concap_proto *cprot = lp -> netdev -> cprot;
856 struct concap_proto_ops *pops = cprot ? cprot -> pops : 0;
857 #endif
858
859 if (lp->flags & ISDN_NET_CONNECTED) {
860 if (lp->slave != NULL) {
861 isdn_net_local *slp = (isdn_net_local *)lp->slave->priv;
862 if (slp->flags & ISDN_NET_CONNECTED) {
863 printk(KERN_INFO
864 "isdn_net: hang up slave %s before %s\n",
865 slp->name, lp->name);
866 isdn_net_hangup(lp->slave);
867 }
868 }
869 printk(KERN_INFO "isdn_net: local hangup %s\n", lp->name);
870 #ifdef CONFIG_ISDN_PPP
871 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
872 isdn_ppp_free(lp);
873 #endif
874 isdn_net_lp_disconnected(lp);
875 #ifdef CONFIG_ISDN_X25
876 /* try if there are generic encap protocol
877 receiver routines and signal the closure of
878 the link */
879 if( pops && pops -> disconn_ind )
880 pops -> disconn_ind(cprot);
881 #endif /* CONFIG_ISDN_X25 */
882
883 cmd.driver = lp->isdn_device;
884 cmd.command = ISDN_CMD_HANGUP;
885 cmd.arg = lp->isdn_channel;
886 isdn_command(&cmd);
887 printk(KERN_INFO "%s: Chargesum is %d\n", lp->name, lp->charge);
888 isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
889 }
890 isdn_net_unbind_channel(lp);
891 }
892
893 typedef struct {
894 unsigned short source;
895 unsigned short dest;
896 } ip_ports;
897
898 static void
899 isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
900 {
901 u_char *p = skb->nh.raw; /* hopefully, this was set correctly */
902 unsigned short proto = ntohs(skb->protocol);
903 int data_ofs;
904 ip_ports *ipp;
905 char addinfo[100];
906
907 addinfo[0] = '\0';
908 /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
909 if (skb->nh.raw < skb->data || skb->nh.raw >= skb->tail) {
910 /* fall back to old isdn_net_log_packet method() */
911 char * buf = skb->data;
912
913 printk(KERN_DEBUG "isdn_net: protocol %04x is buggy, dev %s\n", skb->protocol, lp->name);
914 p = buf;
915 proto = ETH_P_IP;
916 switch (lp->p_encap) {
917 case ISDN_NET_ENCAP_IPTYP:
918 proto = ntohs(*(unsigned short *) &buf[0]);
919 p = &buf[2];
920 break;
921 case ISDN_NET_ENCAP_ETHER:
922 proto = ntohs(*(unsigned short *) &buf[12]);
923 p = &buf[14];
924 break;
925 case ISDN_NET_ENCAP_CISCOHDLC:
926 proto = ntohs(*(unsigned short *) &buf[2]);
927 p = &buf[4];
928 break;
929 #ifdef CONFIG_ISDN_PPP
930 case ISDN_NET_ENCAP_SYNCPPP:
931 proto = ntohs(skb->protocol);
932 p = &buf[IPPP_MAX_HEADER];
933 break;
934 #endif
935 }
936 }
937 data_ofs = ((p[0] & 15) * 4);
938 switch (proto) {
939 case ETH_P_IP:
940 switch (p[9]) {
941 case 1:
942 strcpy(addinfo, " ICMP");
943 break;
944 case 2:
945 strcpy(addinfo, " IGMP");
946 break;
947 case 4:
948 strcpy(addinfo, " IPIP");
949 break;
950 case 6:
951 ipp = (ip_ports *) (&p[data_ofs]);
952 sprintf(addinfo, " TCP, port: %d -> %d", ntohs(ipp->source),
953 ntohs(ipp->dest));
954 break;
955 case 8:
956 strcpy(addinfo, " EGP");
957 break;
958 case 12:
959 strcpy(addinfo, " PUP");
960 break;
961 case 17:
962 ipp = (ip_ports *) (&p[data_ofs]);
963 sprintf(addinfo, " UDP, port: %d -> %d", ntohs(ipp->source),
964 ntohs(ipp->dest));
965 break;
966 case 22:
967 strcpy(addinfo, " IDP");
968 break;
969 }
970 printk(KERN_INFO
971 "OPEN: %d.%d.%d.%d -> %d.%d.%d.%d%s\n",
972
973 p[12], p[13], p[14], p[15],
974 p[16], p[17], p[18], p[19],
975 addinfo);
976 break;
977 case ETH_P_ARP:
978 printk(KERN_INFO
979 "OPEN: ARP %d.%d.%d.%d -> *.*.*.* ?%d.%d.%d.%d\n",
980 p[14], p[15], p[16], p[17],
981 p[24], p[25], p[26], p[27]);
982 break;
983 }
984 }
985
986 /*
987 * this function is used to send supervisory data, i.e. data which was
988 * not received from the network layer, but e.g. frames from ipppd, CCP
989 * reset frames etc.
990 */
991 void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb)
992 {
993 if (in_irq()) {
994 // we can't grab the lock from irq context,
995 // so we just queue the packet
996 skb_queue_tail(&lp->super_tx_queue, skb);
997 queue_task(&lp->tqueue, &tq_immediate);
998 mark_bh(IMMEDIATE_BH);
999 return;
1000 }
1001
1002 spin_lock_bh(&lp->xmit_lock);
1003 if (!isdn_net_lp_busy(lp)) {
1004 isdn_net_writebuf_skb(lp, skb);
1005 } else {
1006 skb_queue_tail(&lp->super_tx_queue, skb);
1007 }
1008 spin_unlock_bh(&lp->xmit_lock);
1009 }
1010
1011 /*
1012 * called from tq_immediate
1013 */
1014 static void isdn_net_softint(void *private)
1015 {
1016 isdn_net_local *lp = private;
1017 struct sk_buff *skb;
1018
1019 spin_lock_bh(&lp->xmit_lock);
1020 while (!isdn_net_lp_busy(lp)) {
1021 skb = skb_dequeue(&lp->super_tx_queue);
1022 if (!skb)
1023 break;
1024 isdn_net_writebuf_skb(lp, skb);
1025 }
1026 spin_unlock_bh(&lp->xmit_lock);
1027 }
1028
1029 /*
1030 * all frames sent from the (net) LL to a HL driver should go via this function
1031 * it's serialized by the caller holding the lp->xmit_lock spinlock
1032 */
1033 void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb)
1034 {
1035 int ret;
1036 int len = skb->len; /* save len */
1037
1038 /* before obtaining the lock the caller should have checked that
1039 the lp isn't busy */
1040 if (isdn_net_lp_busy(lp)) {
1041 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1042 goto error;
1043 }
1044
1045 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1046 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1047 goto error;
1048 }
1049 ret = isdn_writebuf_skb_stub(lp->isdn_device, lp->isdn_channel, 1, skb);
1050 if (ret != len) {
1051 /* we should never get here */
1052 printk(KERN_WARNING "%s: HL driver queue full\n", lp->name);
1053 goto error;
1054 }
1055
1056 lp->transcount += len;
1057 isdn_net_inc_frame_cnt(lp);
1058 return;
1059
1060 error:
1061 dev_kfree_skb(skb);
1062 lp->stats.tx_errors++;
1063
1064 }
1065
1066
1067 /*
1068 * Helper function for isdn_net_start_xmit.
1069 * When called, the connection is already established.
1070 * Based on cps-calculation, check if device is overloaded.
1071 * If so, and if a slave exists, trigger dialing for it.
1072 * If any slave is online, deliver packets using a simple round robin
1073 * scheme.
1074 *
1075 * Return: 0 on success, !0 on failure.
1076 */
1077
1078 static int
1079 isdn_net_xmit(struct net_device *ndev, struct sk_buff *skb)
1080 {
1081 isdn_net_dev *nd;
1082 isdn_net_local *slp;
1083 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1084 int retv = 0;
1085
1086 if (((isdn_net_local *) (ndev->priv))->master) {
1087 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1088 dev_kfree_skb(skb);
1089 return 0;
1090 }
1091
1092 /* For the other encaps the header has already been built */
1093 #ifdef CONFIG_ISDN_PPP
1094 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1095 return isdn_ppp_xmit(skb, ndev);
1096 }
1097 #endif
1098 nd = ((isdn_net_local *) ndev->priv)->netdev;
1099 lp = isdn_net_get_locked_lp(nd);
1100 if (!lp) {
1101 printk(KERN_WARNING "%s: all channels busy - requeuing!\n", ndev->name);
1102 return 1;
1103 }
1104 /* we have our lp locked from now on */
1105
1106 /* Reset hangup-timeout */
1107 lp->huptimer = 0; // FIXME?
1108 isdn_net_writebuf_skb(lp, skb);
1109 spin_unlock_bh(&lp->xmit_lock);
1110
1111 /* the following stuff is here for backwards compatibility.
1112 * in future, start-up and hangup of slaves (based on current load)
1113 * should move to userspace and get based on an overall cps
1114 * calculation
1115 */
1116 if (lp->cps > lp->triggercps) {
1117 if (lp->slave) {
1118 if (!lp->sqfull) {
1119 /* First time overload: set timestamp only */
1120 lp->sqfull = 1;
1121 lp->sqfull_stamp = jiffies;
1122 } else {
1123 /* subsequent overload: if slavedelay exceeded, start dialing */
1124 if ((jiffies - lp->sqfull_stamp) > lp->slavedelay) {
1125 slp = lp->slave->priv;
1126 if (!(slp->flags & ISDN_NET_CONNECTED)) {
1127 isdn_net_force_dial_lp((isdn_net_local *) lp->slave->priv);
1128 }
1129 }
1130 }
1131 }
1132 } else {
1133 if (lp->sqfull && ((jiffies - lp->sqfull_stamp) > (lp->slavedelay + (10 * HZ)))) {
1134 lp->sqfull = 0;
1135 }
1136 /* this is a hack to allow auto-hangup for slaves on moderate loads */
1137 nd->queue = nd->local;
1138 }
1139
1140 return retv;
1141
1142 }
1143
1144 static void
1145 isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
1146 {
1147 isdn_net_local *lp = (isdn_net_local *) dev->priv;
1148 if (!skb)
1149 return;
1150 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
1151 int pullsize = (ulong)skb->nh.raw - (ulong)skb->data - ETH_HLEN;
1152 if (pullsize > 0) {
1153 printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
1154 skb_pull(skb, pullsize);
1155 }
1156 }
1157 }
1158
1159
1160 void isdn_net_tx_timeout(struct net_device * ndev)
1161 {
1162 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1163
1164 printk(KERN_WARNING "isdn_tx_timeout dev %s dialstate %d\n", ndev->name, lp->dialstate);
1165 if (!lp->dialstate){
1166 lp->stats.tx_errors++;
1167 /*
1168 * There is a certain probability that this currently
1169 * works at all because if we always wake up the interface,
1170 * then upper layer will try to send the next packet
1171 * immediately. And then, the old clean_up logic in the
1172 * driver will hopefully continue to work as it used to do.
1173 *
1174 * This is rather primitive right know, we better should
1175 * clean internal queues here, in particular for multilink and
1176 * ppp, and reset HL driver's channel, too. --HE
1177 *
1178 * actually, this may not matter at all, because ISDN hardware
1179 * should not see transmitter hangs at all IMO
1180 * changed KERN_DEBUG to KERN_WARNING to find out if this is
1181 * ever called --KG
1182 */
1183 }
1184 ndev->trans_start = jiffies;
1185 netif_wake_queue(ndev);
1186 }
1187
1188 /*
1189 * Try sending a packet.
1190 * If this interface isn't connected to a ISDN-Channel, find a free channel,
1191 * and start dialing.
1192 */
1193 static int
1194 isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1195 {
1196 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1197 #ifdef CONFIG_ISDN_X25
1198 struct concap_proto * cprot = lp -> netdev -> cprot;
1199 #endif
1200 #ifdef CONFIG_ISDN_X25
1201 /* At this point hard_start_xmit() passes control to the encapsulation
1202 protocol (if present).
1203 For X.25 auto-dialing is completly bypassed because:
1204 - It does not conform with the semantics of a reliable datalink
1205 service as needed by X.25 PLP.
1206 - I don't want that the interface starts dialing when the network layer
1207 sends a message which requests to disconnect the lapb link (or if it
1208 sends any other message not resulting in data transmission).
1209 Instead, dialing will be initiated by the encapsulation protocol entity
1210 when a dl_establish request is received from the upper layer.
1211 */
1212 if( cprot ) {
1213 int ret = cprot -> pops -> encap_and_xmit ( cprot , skb);
1214 if(ret) netif_stop_queue(ndev);
1215 return ret;
1216 } else
1217 #endif
1218 /* auto-dialing xmit function */
1219 {
1220 #ifdef ISDN_DEBUG_NET_DUMP
1221 u_char *buf;
1222 #endif
1223 isdn_net_adjust_hdr(skb, ndev);
1224 #ifdef ISDN_DEBUG_NET_DUMP
1225 buf = skb->data;
1226 isdn_dumppkt("S:", buf, skb->len, 40);
1227 #endif
1228
1229 if (!(lp->flags & ISDN_NET_CONNECTED)) {
1230 int chi;
1231 /* only do autodial if allowed by config */
1232 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) {
1233 isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'");
1234 dev_kfree_skb(skb);
1235 return 0;
1236 }
1237 if (lp->phone[1]) {
1238 ulong flags;
1239 save_flags(flags);
1240 cli();
1241
1242 if(lp->dialwait_timer <= 0)
1243 if(lp->dialstarted > 0 && lp->dialtimeout > 0 && jiffies < lp->dialstarted + lp->dialtimeout + lp->dialwait)
1244 lp->dialwait_timer = lp->dialstarted + lp->dialtimeout + lp->dialwait;
1245
1246 if(lp->dialwait_timer > 0) {
1247 if(jiffies < lp->dialwait_timer) {
1248 isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached");
1249 dev_kfree_skb(skb);
1250 restore_flags(flags);
1251 return 0;
1252 } else
1253 lp->dialwait_timer = 0;
1254 }
1255 /* Grab a free ISDN-Channel */
1256 if (((chi =
1257 isdn_get_free_channel(
1258 ISDN_USAGE_NET,
1259 lp->l2_proto,
1260 lp->l3_proto,
1261 lp->pre_device,
1262 lp->pre_channel,
1263 lp->msn)
1264 ) < 0) &&
1265 ((chi =
1266 isdn_get_free_channel(
1267 ISDN_USAGE_NET,
1268 lp->l2_proto,
1269 lp->l3_proto,
1270 lp->pre_device,
1271 lp->pre_channel^1,
1272 lp->msn)
1273 ) < 0)) {
1274 restore_flags(flags);
1275 isdn_net_unreachable(ndev, skb,
1276 "No channel");
1277 dev_kfree_skb(skb);
1278 return 0;
1279 }
1280 /* Log packet, which triggered dialing */
1281 if (dev->net_verbose)
1282 isdn_net_log_skb(skb, lp);
1283 lp->dialstate = 1;
1284 /* Connect interface with channel */
1285 isdn_net_bind_channel(lp, chi);
1286 #ifdef CONFIG_ISDN_PPP
1287 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
1288 /* no 'first_skb' handling for syncPPP */
1289 if (isdn_ppp_bind(lp) < 0) {
1290 dev_kfree_skb(skb);
1291 isdn_net_unbind_channel(lp);
1292 restore_flags(flags);
1293 return 0; /* STN (skb to nirvana) ;) */
1294 }
1295 restore_flags(flags);
1296 isdn_net_dial(); /* Initiate dialing */
1297 netif_stop_queue(ndev);
1298 return 1; /* let upper layer requeue skb packet */
1299 }
1300 #endif
1301 /* Initiate dialing */
1302 restore_flags(flags);
1303 isdn_net_dial();
1304 isdn_net_device_stop_queue(lp);
1305 return 1;
1306 } else {
1307 isdn_net_unreachable(ndev, skb,
1308 "No phone number");
1309 dev_kfree_skb(skb);
1310 return 0;
1311 }
1312 } else {
1313 /* Device is connected to an ISDN channel */
1314 ndev->trans_start = jiffies;
1315 if (!lp->dialstate) {
1316 /* ISDN connection is established, try sending */
1317 int ret;
1318 ret = (isdn_net_xmit(ndev, skb));
1319 if(ret) netif_stop_queue(ndev);
1320 return ret;
1321 } else
1322 netif_stop_queue(ndev);
1323 }
1324 }
1325 return 1;
1326 }
1327
1328 /*
1329 * Shutdown a net-interface.
1330 */
1331 static int
1332 isdn_net_close(struct net_device *dev)
1333 {
1334 struct net_device *p;
1335 #ifdef CONFIG_ISDN_X25
1336 struct concap_proto * cprot =
1337 ( (isdn_net_local *) dev->priv ) -> netdev -> cprot;
1338 /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
1339 #endif
1340
1341 #ifdef CONFIG_ISDN_X25
1342 if( cprot && cprot -> pops ) cprot -> pops -> close( cprot );
1343 #endif
1344 netif_stop_queue(dev);
1345 if ((p = (((isdn_net_local *) dev->priv)->slave))) {
1346 /* If this interface has slaves, stop them also */
1347 while (p) {
1348 #ifdef CONFIG_ISDN_X25
1349 cprot = ( (isdn_net_local *) p->priv )
1350 -> netdev -> cprot;
1351 if( cprot && cprot -> pops )
1352 cprot -> pops -> close( cprot );
1353 #endif
1354 isdn_net_hangup(p);
1355 p = (((isdn_net_local *) p->priv)->slave);
1356 }
1357 }
1358 isdn_net_hangup(dev);
1359 isdn_MOD_DEC_USE_COUNT();
1360 return 0;
1361 }
1362
1363 /*
1364 * Get statistics
1365 */
1366 static struct net_device_stats *
1367 isdn_net_get_stats(struct net_device *dev)
1368 {
1369 isdn_net_local *lp = (isdn_net_local *) dev->priv;
1370 return &lp->stats;
1371 }
1372
1373 /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
1374 * instead of dev->hard_header_len off. This is done because the
1375 * lowlevel-driver has already pulled off its stuff when we get
1376 * here and this routine only gets called with p_encap == ETHER.
1377 * Determine the packet's protocol ID. The rule here is that we
1378 * assume 802.3 if the type field is short enough to be a length.
1379 * This is normal practice and works for any 'now in use' protocol.
1380 */
1381
1382 static unsigned short
1383 isdn_net_type_trans(struct sk_buff *skb, struct net_device *dev)
1384 {
1385 struct ethhdr *eth;
1386 unsigned char *rawp;
1387
1388 skb->mac.raw = skb->data;
1389 skb_pull(skb, ETH_HLEN);
1390 eth = skb->mac.ethernet;
1391
1392 if (*eth->h_dest & 1) {
1393 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
1394 skb->pkt_type = PACKET_BROADCAST;
1395 else
1396 skb->pkt_type = PACKET_MULTICAST;
1397 }
1398 /*
1399 * This ALLMULTI check should be redundant by 1.4
1400 * so don't forget to remove it.
1401 */
1402
1403 else if (dev->flags & (IFF_PROMISC /*| IFF_ALLMULTI*/)) {
1404 if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
1405 skb->pkt_type = PACKET_OTHERHOST;
1406 }
1407 if (ntohs(eth->h_proto) >= 1536)
1408 return eth->h_proto;
1409
1410 rawp = skb->data;
1411
1412 /*
1413 * This is a magic hack to spot IPX packets. Older Novell breaks
1414 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
1415 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
1416 * won't work for fault tolerant netware but does for the rest.
1417 */
1418 if (*(unsigned short *) rawp == 0xFFFF)
1419 return htons(ETH_P_802_3);
1420 /*
1421 * Real 802.2 LLC
1422 */
1423 return htons(ETH_P_802_2);
1424 }
1425
1426
1427 /*
1428 * CISCO HDLC keepalive specific stuff
1429 */
1430 static struct sk_buff*
1431 isdn_net_ciscohdlck_alloc_skb(isdn_net_local *lp, int len)
1432 {
1433 unsigned short hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
1434 struct sk_buff *skb;
1435
1436 skb = alloc_skb(hl + len, GFP_ATOMIC);
1437 if (!skb) {
1438 printk("isdn out of mem at %s:%d!\n", __FILE__, __LINE__);
1439 return 0;
1440 }
1441 skb_reserve(skb, hl);
1442 return skb;
1443 }
1444
1445 /* cisco hdlck device private ioctls */
1446 int
1447 isdn_ciscohdlck_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1448 {
1449 isdn_net_local *lp = (isdn_net_local *) dev->priv;
1450 unsigned long len = 0;
1451 unsigned long expires = 0;
1452 int tmp = 0;
1453 int period = lp->cisco_keepalive_period;
1454 char debserint = lp->cisco_debserint;
1455 int rc = 0;
1456
1457 if (lp->p_encap != ISDN_NET_ENCAP_CISCOHDLCK)
1458 return -EINVAL;
1459
1460 switch (cmd) {
1461 /* get/set keepalive period */
1462 case SIOCGKEEPPERIOD:
1463 len = (unsigned long)sizeof(lp->cisco_keepalive_period);
1464 if (copy_to_user((char *)ifr->ifr_ifru.ifru_data,
1465 (int *)&lp->cisco_keepalive_period, len))
1466 rc = -EFAULT;
1467 break;
1468 case SIOCSKEEPPERIOD:
1469 tmp = lp->cisco_keepalive_period;
1470 len = (unsigned long)sizeof(lp->cisco_keepalive_period);
1471 if (copy_from_user((int *)&period,
1472 (char *)ifr->ifr_ifru.ifru_data, len))
1473 rc = -EFAULT;
1474 if ((period > 0) && (period <= 32767))
1475 lp->cisco_keepalive_period = period;
1476 else
1477 rc = -EINVAL;
1478 if (!rc && (tmp != lp->cisco_keepalive_period)) {
1479 expires = (unsigned long)(jiffies +
1480 lp->cisco_keepalive_period * HZ);
1481 mod_timer(&lp->cisco_timer, expires);
1482 printk(KERN_INFO "%s: Keepalive period set "
1483 "to %d seconds.\n",
1484 lp->name, lp->cisco_keepalive_period);
1485 }
1486 break;
1487
1488 /* get/set debugging */
1489 case SIOCGDEBSERINT:
1490 len = (unsigned long)sizeof(lp->cisco_debserint);
1491 if (copy_to_user((char *)ifr->ifr_ifru.ifru_data,
1492 (char *)&lp->cisco_debserint, len))
1493 rc = -EFAULT;
1494 break;
1495 case SIOCSDEBSERINT:
1496 len = (unsigned long)sizeof(lp->cisco_debserint);
1497 if (copy_from_user((char *)&debserint,
1498 (char *)ifr->ifr_ifru.ifru_data, len))
1499 rc = -EFAULT;
1500 if ((debserint >= 0) && (debserint <= 64))
1501 lp->cisco_debserint = debserint;
1502 else
1503 rc = -EINVAL;
1504 break;
1505
1506 default:
1507 rc = -EINVAL;
1508 break;
1509 }
1510 return (rc);
1511 }
1512
1513 /* called via cisco_timer.function */
1514 static void
1515 isdn_net_ciscohdlck_slarp_send_keepalive(unsigned long data)
1516 {
1517 isdn_net_local *lp = (isdn_net_local *) data;
1518 struct sk_buff *skb;
1519 unsigned char *p;
1520 unsigned long last_cisco_myseq = lp->cisco_myseq;
1521 int myseq_diff = 0;
1522
1523 if (!(lp->flags & ISDN_NET_CONNECTED) || lp->dialstate) {
1524 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1525 return;
1526 }
1527 lp->cisco_myseq++;
1528
1529 myseq_diff = (lp->cisco_myseq - lp->cisco_mineseen);
1530 if ((lp->cisco_line_state) && ((myseq_diff >= 3)||(myseq_diff <= -3))) {
1531 /* line up -> down */
1532 lp->cisco_line_state = 0;
1533 printk (KERN_WARNING
1534 "UPDOWN: Line protocol on Interface %s,"
1535 " changed state to down\n", lp->name);
1536 /* should stop routing higher-level data accross */
1537 } else if ((!lp->cisco_line_state) &&
1538 (myseq_diff >= 0) && (myseq_diff <= 2)) {
1539 /* line down -> up */
1540 lp->cisco_line_state = 1;
1541 printk (KERN_WARNING
1542 "UPDOWN: Line protocol on Interface %s,"
1543 " changed state to up\n", lp->name);
1544 /* restart routing higher-level data accross */
1545 }
1546
1547 if (lp->cisco_debserint)
1548 printk (KERN_DEBUG "%s: HDLC "
1549 "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
1550 lp->name, last_cisco_myseq, lp->cisco_mineseen,
1551 ((last_cisco_myseq == lp->cisco_mineseen) ? '*' : 040),
1552 lp->cisco_yourseq,
1553 ((lp->cisco_line_state) ? "line up" : "line down"));
1554
1555 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1556 if (!skb)
1557 return;
1558
1559 p = skb_put(skb, 4 + 14);
1560
1561 /* cisco header */
1562 p += put_u8 (p, CISCO_ADDR_UNICAST);
1563 p += put_u8 (p, CISCO_CTRL);
1564 p += put_u16(p, CISCO_TYPE_SLARP);
1565
1566 /* slarp keepalive */
1567 p += put_u32(p, CISCO_SLARP_KEEPALIVE);
1568 p += put_u32(p, lp->cisco_myseq);
1569 p += put_u32(p, lp->cisco_yourseq);
1570 p += put_u16(p, 0xffff); // reliablity, always 0xffff
1571
1572 isdn_net_write_super(lp, skb);
1573
1574 lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
1575
1576 add_timer(&lp->cisco_timer);
1577 }
1578
1579 static void
1580 isdn_net_ciscohdlck_slarp_send_request(isdn_net_local *lp)
1581 {
1582 struct sk_buff *skb;
1583 unsigned char *p;
1584
1585 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1586 if (!skb)
1587 return;
1588
1589 p = skb_put(skb, 4 + 14);
1590
1591 /* cisco header */
1592 p += put_u8 (p, CISCO_ADDR_UNICAST);
1593 p += put_u8 (p, CISCO_CTRL);
1594 p += put_u16(p, CISCO_TYPE_SLARP);
1595
1596 /* slarp request */
1597 p += put_u32(p, CISCO_SLARP_REQUEST);
1598 p += put_u32(p, 0); // address
1599 p += put_u32(p, 0); // netmask
1600 p += put_u16(p, 0); // unused
1601
1602 isdn_net_write_super(lp, skb);
1603 }
1604
1605 static void
1606 isdn_net_ciscohdlck_connected(isdn_net_local *lp)
1607 {
1608 lp->cisco_myseq = 0;
1609 lp->cisco_mineseen = 0;
1610 lp->cisco_yourseq = 0;
1611 lp->cisco_keepalive_period = ISDN_TIMER_KEEPINT;
1612 lp->cisco_last_slarp_in = 0;
1613 lp->cisco_line_state = 0;
1614 lp->cisco_debserint = 0;
1615
1616 /* send slarp request because interface/seq.no.s reset */
1617 isdn_net_ciscohdlck_slarp_send_request(lp);
1618
1619 init_timer(&lp->cisco_timer);
1620 lp->cisco_timer.data = (unsigned long) lp;
1621 lp->cisco_timer.function = isdn_net_ciscohdlck_slarp_send_keepalive;
1622 lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
1623 add_timer(&lp->cisco_timer);
1624 }
1625
1626 static void
1627 isdn_net_ciscohdlck_disconnected(isdn_net_local *lp)
1628 {
1629 del_timer(&lp->cisco_timer);
1630 }
1631
1632 static void
1633 isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local *lp)
1634 {
1635 struct sk_buff *skb;
1636 unsigned char *p;
1637 struct in_device *in_dev = NULL;
1638 u32 addr = 0; /* local ipv4 address */
1639 u32 mask = 0; /* local netmask */
1640
1641 if ((in_dev = lp->netdev->dev.ip_ptr) != NULL) {
1642 /* take primary(first) address of interface */
1643 struct in_ifaddr *ifa = in_dev->ifa_list;
1644 if (ifa != NULL) {
1645 addr = ifa->ifa_local;
1646 mask = ifa->ifa_mask;
1647 }
1648 }
1649
1650 skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
1651 if (!skb)
1652 return;
1653
1654 p = skb_put(skb, 4 + 14);
1655
1656 /* cisco header */
1657 p += put_u8 (p, CISCO_ADDR_UNICAST);
1658 p += put_u8 (p, CISCO_CTRL);
1659 p += put_u16(p, CISCO_TYPE_SLARP);
1660
1661 /* slarp reply, send own ip/netmask; if values are nonsense remote
1662 * should think we are unable to provide it with an address via SLARP */
1663 p += put_u32(p, CISCO_SLARP_REPLY);
1664 p += put_u32(p, addr); // address
1665 p += put_u32(p, mask); // netmask
1666 p += put_u16(p, 0); // unused
1667
1668 isdn_net_write_super(lp, skb);
1669 }
1670
1671 static void
1672 isdn_net_ciscohdlck_slarp_in(isdn_net_local *lp, struct sk_buff *skb)
1673 {
1674 unsigned char *p;
1675 int period;
1676 __u32 code;
1677 __u32 my_seq, addr;
1678 __u32 your_seq, mask;
1679 __u16 unused;
1680
1681 if (skb->len < 14)
1682 return;
1683
1684 p = skb->data;
1685 p += get_u32(p, &code);
1686
1687 switch (code) {
1688 case CISCO_SLARP_REQUEST:
1689 lp->cisco_yourseq = 0;
1690 isdn_net_ciscohdlck_slarp_send_reply(lp);
1691 break;
1692 case CISCO_SLARP_REPLY:
1693 /* Ignore replies - at least for now */
1694 if (lp->cisco_debserint) {
1695 p += get_u32(p, &addr);
1696 p += get_u32(p, &mask);
1697 p += get_u16(p, &unused);
1698 printk(KERN_DEBUG "%s: got slarp reply (%ul/%ul) - "
1699 "ignored\n", lp->name, addr, mask);
1700 }
1701 break;
1702 case CISCO_SLARP_KEEPALIVE:
1703 period = (int)((jiffies - lp->cisco_last_slarp_in
1704 + HZ/2 - 1) / HZ);
1705 if (lp->cisco_debserint &&
1706 (period != lp->cisco_keepalive_period) &&
1707 lp->cisco_last_slarp_in) {
1708 printk(KERN_DEBUG "%s: Keepalive period mismatch - "
1709 "is %d but should be %d.\n",
1710 lp->name, period, lp->cisco_keepalive_period);
1711 }
1712 lp->cisco_last_slarp_in = jiffies;
1713 p += get_u32(p, &my_seq);
1714 p += get_u32(p, &your_seq);
1715 p += get_u16(p, &unused);
1716 lp->cisco_yourseq = my_seq;
1717 lp->cisco_mineseen = your_seq;
1718 break;
1719 }
1720 }
1721
1722 static void
1723 isdn_net_ciscohdlck_receive(isdn_net_local *lp, struct sk_buff *skb)
1724 {
1725 unsigned char *p;
1726 __u8 addr;
1727 __u8 ctrl;
1728 __u16 type;
1729
1730 if (skb->len < 4)
1731 goto out_free;
1732
1733 p = skb->data;
1734 p += get_u8 (p, &addr);
1735 p += get_u8 (p, &ctrl);
1736 p += get_u16(p, &type);
1737 skb_pull(skb, 4);
1738
1739 if (addr != CISCO_ADDR_UNICAST && addr != CISCO_ADDR_BROADCAST) {
1740 printk(KERN_WARNING "%s: Unknown Cisco addr 0x%02x\n",
1741 lp->name, addr);
1742 goto out_free;
1743 }
1744 if (ctrl != CISCO_CTRL) {
1745 printk(KERN_WARNING "%s: Unknown Cisco ctrl 0x%02x\n",
1746 lp->name, ctrl);
1747 goto out_free;
1748 }
1749
1750 switch (type) {
1751 case CISCO_TYPE_INET:
1752 skb->protocol = htons(ETH_P_IP);
1753 netif_rx(skb);
1754 break;
1755 case CISCO_TYPE_SLARP:
1756 isdn_net_ciscohdlck_slarp_in(lp, skb);
1757 goto out_free;
1758 case CISCO_TYPE_CDP:
1759 if (lp->cisco_debserint)
1760 printk(KERN_DEBUG "%s: Received CDP packet. use "
1761 "\"no cdp enable\" on cisco.\n", lp->name);
1762 goto out_free;
1763 default:
1764 printk(KERN_WARNING "%s: Unknown Cisco type 0x%04x\n",
1765 lp->name, type);
1766 goto out_free;
1767 }
1768 return;
1769
1770 out_free:
1771 kfree_skb(skb);
1772 }
1773
1774 /*
1775 * Got a packet from ISDN-Channel.
1776 */
1777 static void
1778 isdn_net_receive(struct net_device *ndev, struct sk_buff *skb)
1779 {
1780 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
1781 isdn_net_local *olp = lp; /* original 'lp' */
1782 #ifdef CONFIG_ISDN_PPP
1783 int proto = PPP_PROTOCOL(skb->data);
1784 #endif
1785 #ifdef CONFIG_ISDN_X25
1786 struct concap_proto *cprot = lp -> netdev -> cprot;
1787 #endif
1788 lp->transcount += skb->len;
1789
1790 lp->stats.rx_packets++;
1791 lp->stats.rx_bytes += skb->len;
1792 if (lp->master) {
1793 /* Bundling: If device is a slave-device, deliver to master, also
1794 * handle master's statistics and hangup-timeout
1795 */
1796 ndev = lp->master;
1797 lp = (isdn_net_local *) ndev->priv;
1798 lp->stats.rx_packets++;
1799 lp->stats.rx_bytes += skb->len;
1800 }
1801 skb->dev = ndev;
1802 skb->pkt_type = PACKET_HOST;
1803 skb->mac.raw = skb->data;
1804 #ifdef ISDN_DEBUG_NET_DUMP
1805 isdn_dumppkt("R:", skb->data, skb->len, 40);
1806 #endif
1807 switch (lp->p_encap) {
1808 case ISDN_NET_ENCAP_ETHER:
1809 /* Ethernet over ISDN */
1810 olp->huptimer = 0;
1811 lp->huptimer = 0;
1812 skb->protocol = isdn_net_type_trans(skb, ndev);
1813 break;
1814 case ISDN_NET_ENCAP_UIHDLC:
1815 /* HDLC with UI-frame (for ispa with -h1 option) */
1816 olp->huptimer = 0;
1817 lp->huptimer = 0;
1818 skb_pull(skb, 2);
1819 /* Fall through */
1820 case ISDN_NET_ENCAP_RAWIP:
1821 /* RAW-IP without MAC-Header */
1822 olp->huptimer = 0;
1823 lp->huptimer = 0;
1824 skb->protocol = htons(ETH_P_IP);
1825 break;
1826 case ISDN_NET_ENCAP_CISCOHDLCK:
1827 isdn_net_ciscohdlck_receive(lp, skb);
1828 return;
1829 case ISDN_NET_ENCAP_CISCOHDLC:
1830 /* CISCO-HDLC IP with type field and fake I-frame-header */
1831 skb_pull(skb, 2);
1832 /* Fall through */
1833 case ISDN_NET_ENCAP_IPTYP:
1834 /* IP with type field */
1835 olp->huptimer = 0;
1836 lp->huptimer = 0;
1837 skb->protocol = *(unsigned short *) &(skb->data[0]);
1838 skb_pull(skb, 2);
1839 if (*(unsigned short *) skb->data == 0xFFFF)
1840 skb->protocol = htons(ETH_P_802_3);
1841 break;
1842 #ifdef CONFIG_ISDN_PPP
1843 case ISDN_NET_ENCAP_SYNCPPP:
1844 /*
1845 * If encapsulation is syncppp, don't reset
1846 * huptimer on LCP packets.
1847 */
1848 if (proto != PPP_LCP) {
1849 olp->huptimer = 0;
1850 lp->huptimer = 0;
1851 }
1852 isdn_ppp_receive(lp->netdev, olp, skb);
1853 return;
1854 #endif
1855
1856 default:
1857 #ifdef CONFIG_ISDN_X25
1858 /* try if there are generic sync_device receiver routines */
1859 if(cprot) if(cprot -> pops)
1860 if( cprot -> pops -> data_ind){
1861 cprot -> pops -> data_ind(cprot,skb);
1862 return;
1863 };
1864 #endif /* CONFIG_ISDN_X25 */
1865 printk(KERN_WARNING "%s: unknown encapsulation, dropping\n",
1866 lp->name);
1867 kfree_skb(skb);
1868 return;
1869 }
1870
1871 netif_rx(skb);
1872 return;
1873 }
1874
1875 /*
1876 * A packet arrived via ISDN. Search interface-chain for a corresponding
1877 * interface. If found, deliver packet to receiver-function and return 1,
1878 * else return 0.
1879 */
1880 int
1881 isdn_net_rcv_skb(int idx, struct sk_buff *skb)
1882 {
1883 isdn_net_dev *p = dev->rx_netdev[idx];
1884
1885 if (p) {
1886 isdn_net_local *lp = p->local;
1887 if ((lp->flags & ISDN_NET_CONNECTED) &&
1888 (!lp->dialstate)) {
1889 isdn_net_receive(&p->dev, skb);
1890 return 1;
1891 }
1892 }
1893 return 0;
1894 }
1895
1896 static int
1897 my_eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1898 void *daddr, void *saddr, unsigned len)
1899 {
1900 struct ethhdr *eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
1901
1902 /*
1903 * Set the protocol type. For a packet of type ETH_P_802_3 we
1904 * put the length here instead. It is up to the 802.2 layer to
1905 * carry protocol information.
1906 */
1907
1908 if (type != ETH_P_802_3)
1909 eth->h_proto = htons(type);
1910 else
1911 eth->h_proto = htons(len);
1912
1913 /*
1914 * Set the source hardware address.
1915 */
1916 if (saddr)
1917 memcpy(eth->h_source, saddr, dev->addr_len);
1918 else
1919 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
1920
1921 /*
1922 * Anyway, the loopback-device should never use this function...
1923 */
1924
1925 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
1926 memset(eth->h_dest, 0, dev->addr_len);
1927 return ETH_HLEN /*(dev->hard_header_len)*/;
1928 }
1929 if (daddr) {
1930 memcpy(eth->h_dest, daddr, dev->addr_len);
1931 return ETH_HLEN /*dev->hard_header_len*/;
1932 }
1933 return -ETH_HLEN /*dev->hard_header_len*/;
1934 }
1935
1936 /*
1937 * build an header
1938 * depends on encaps that is being used.
1939 */
1940
1941 static int
1942 isdn_net_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
1943 void *daddr, void *saddr, unsigned plen)
1944 {
1945 isdn_net_local *lp = dev->priv;
1946 unsigned char *p;
1947 ushort len = 0;
1948
1949 switch (lp->p_encap) {
1950 case ISDN_NET_ENCAP_ETHER:
1951 len = my_eth_header(skb, dev, type, daddr, saddr, plen);
1952 break;
1953 #ifdef CONFIG_ISDN_PPP
1954 case ISDN_NET_ENCAP_SYNCPPP:
1955 /* stick on a fake header to keep fragmentation code happy. */
1956 len = IPPP_MAX_HEADER;
1957 skb_push(skb,len);
1958 break;
1959 #endif
1960 case ISDN_NET_ENCAP_RAWIP:
1961 printk(KERN_WARNING "isdn_net_header called with RAW_IP!\n");
1962 len = 0;
1963 break;
1964 case ISDN_NET_ENCAP_IPTYP:
1965 /* ethernet type field */
1966 *((ushort *) skb_push(skb, 2)) = htons(type);
1967 len = 2;
1968 break;
1969 case ISDN_NET_ENCAP_UIHDLC:
1970 /* HDLC with UI-Frames (for ispa with -h1 option) */
1971 *((ushort *) skb_push(skb, 2)) = htons(0x0103);
1972 len = 2;
1973 break;
1974 case ISDN_NET_ENCAP_CISCOHDLC:
1975 case ISDN_NET_ENCAP_CISCOHDLCK:
1976 p = skb_push(skb, 4);
1977 p += put_u8 (p, CISCO_ADDR_UNICAST);
1978 p += put_u8 (p, CISCO_CTRL);
1979 p += put_u16(p, type);
1980 len = 4;
1981 break;
1982 #ifdef CONFIG_ISDN_X25
1983 default:
1984 /* try if there are generic concap protocol routines */
1985 if( lp-> netdev -> cprot ){
1986 printk(KERN_WARNING "isdn_net_header called with concap_proto!\n");
1987 len = 0;
1988 break;
1989 }
1990 break;
1991 #endif /* CONFIG_ISDN_X25 */
1992 }
1993 return len;
1994 }
1995
1996 /* We don't need to send arp, because we have point-to-point connections. */
1997 static int
1998 isdn_net_rebuild_header(struct sk_buff *skb)
1999 {
2000 struct net_device *dev = skb->dev;
2001 isdn_net_local *lp = dev->priv;
2002 int ret = 0;
2003
2004 if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
2005 struct ethhdr *eth = (struct ethhdr *) skb->data;
2006
2007 /*
2008 * Only ARP/IP is currently supported
2009 */
2010
2011 if (eth->h_proto != htons(ETH_P_IP)) {
2012 printk(KERN_WARNING
2013 "isdn_net: %s don't know how to resolve type %d addresses?\n",
2014 dev->name, (int) eth->h_proto);
2015 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
2016 return 0;
2017 }
2018 /*
2019 * Try to get ARP to resolve the header.
2020 */
2021 #ifdef CONFIG_INET
2022 ret = arp_find(eth->h_dest, skb);
2023 #endif
2024 }
2025 return ret;
2026 }
2027
2028 /*
2029 * Interface-setup. (just after registering a new interface)
2030 */
2031 static int
2032 isdn_net_init(struct net_device *ndev)
2033 {
2034 ushort max_hlhdr_len = 0;
2035 isdn_net_local *lp = (isdn_net_local *) ndev->priv;
2036 int drvidx, i;
2037
2038 ether_setup(ndev);
2039 lp->org_hhc = ndev->hard_header_cache;
2040 lp->org_hcu = ndev->header_cache_update;
2041
2042 /* Setup the generic properties */
2043
2044 ndev->hard_header = NULL;
2045 ndev->hard_header_cache = NULL;
2046 ndev->header_cache_update = NULL;
2047 ndev->mtu = 1500;
2048 ndev->flags = IFF_NOARP|IFF_POINTOPOINT;
2049 ndev->type = ARPHRD_ETHER;
2050 ndev->addr_len = ETH_ALEN;
2051
2052 /* for clients with MPPP maybe higher values better */
2053 ndev->tx_queue_len = 30;
2054
2055 for (i = 0; i < ETH_ALEN; i++)
2056 ndev->broadcast[i] = 0xff;
2057
2058 /* The ISDN-specific entries in the device structure. */
2059 ndev->open = &isdn_net_open;
2060 ndev->hard_start_xmit = &isdn_net_start_xmit;
2061
2062 /*
2063 * up till binding we ask the protocol layer to reserve as much
2064 * as we might need for HL layer
2065 */
2066
2067 for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
2068 if (dev->drv[drvidx])
2069 if (max_hlhdr_len < dev->drv[drvidx]->interface->hl_hdrlen)
2070 max_hlhdr_len = dev->drv[drvidx]->interface->hl_hdrlen;
2071
2072 ndev->hard_header_len = ETH_HLEN + max_hlhdr_len;
2073 ndev->stop = &isdn_net_close;
2074 ndev->get_stats = &isdn_net_get_stats;
2075 ndev->rebuild_header = &isdn_net_rebuild_header;
2076 ndev->do_ioctl = NULL;
2077 return 0;
2078 }
2079
2080 static void
2081 isdn_net_swapbind(int drvidx)
2082 {
2083 isdn_net_dev *p;
2084
2085 #ifdef ISDN_DEBUG_NET_ICALL
2086 printk(KERN_DEBUG "n_fi: swapping ch of %d\n", drvidx);
2087 #endif
2088 p = dev->netdev;
2089 while (p) {
2090 if (p->local->pre_device == drvidx)
2091 switch (p->local->pre_channel) {
2092 case 0:
2093 p->local->pre_channel = 1;
2094 break;
2095 case 1:
2096 p->local->pre_channel = 0;
2097 break;
2098 }
2099 p = (isdn_net_dev *) p->next;
2100 }
2101 }
2102
2103 static void
2104 isdn_net_swap_usage(int i1, int i2)
2105 {
2106 int u1 = dev->usage[i1] & ISDN_USAGE_EXCLUSIVE;
2107 int u2 = dev->usage[i2] & ISDN_USAGE_EXCLUSIVE;
2108
2109 #ifdef ISDN_DEBUG_NET_ICALL
2110 printk(KERN_DEBUG "n_fi: usage of %d and %d\n", i1, i2);
2111 #endif
2112 dev->usage[i1] &= ~ISDN_USAGE_EXCLUSIVE;
2113 dev->usage[i1] |= u2;
2114 dev->usage[i2] &= ~ISDN_USAGE_EXCLUSIVE;
2115 dev->usage[i2] |= u1;
2116 isdn_info_update();
2117 }
2118
2119 /*
2120 * An incoming call-request has arrived.
2121 * Search the interface-chain for an appropriate interface.
2122 * If found, connect the interface to the ISDN-channel and initiate
2123 * D- and B-Channel-setup. If secure-flag is set, accept only
2124 * configured phone-numbers. If callback-flag is set, initiate
2125 * callback-dialing.
2126 *
2127 * Return-Value: 0 = No appropriate interface for this call.
2128 * 1 = Call accepted
2129 * 2 = Reject call, wait cbdelay, then call back
2130 * 3 = Reject call
2131 * 4 = Wait cbdelay, then call back
2132 * 5 = No appropriate interface for this call,
2133 * would eventually match if CID was longer.
2134 */
2135 int
2136 isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
2137 {
2138 char *eaz;
2139 int si1;
2140 int si2;
2141 int ematch;
2142 int wret;
2143 int swapped;
2144 int sidx = 0;
2145 isdn_net_dev *p;
2146 isdn_net_phone *n;
2147 ulong flags;
2148 char nr[32];
2149 /* Search name in netdev-chain */
2150 save_flags(flags);
2151 cli();
2152 if (!setup->phone[0]) {
2153 nr[0] = '0';
2154 nr[1] = '\0';
2155 printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
2156 } else
2157 strcpy(nr, setup->phone);
2158 si1 = (int) setup->si1;
2159 si2 = (int) setup->si2;
2160 if (!setup->eazmsn[0]) {
2161 printk(KERN_WARNING "isdn_net: Incoming call without CPN, assuming '0'\n");
2162 eaz = "0";
2163 } else
2164 eaz = setup->eazmsn;
2165 if (dev->net_verbose > 1)
2166 printk(KERN_INFO "isdn_net: call from %s,%d,%d -> %s\n", nr, si1, si2, eaz);
2167 /* Accept only calls with Si1 = 7 (Data-Transmission) */
2168 if (si1 != 7) {
2169 restore_flags(flags);
2170 if (dev->net_verbose > 1)
2171 printk(KERN_INFO "isdn_net: Service-Indicator not 7, ignored\n");
2172 return 0;
2173 }
2174 n = (isdn_net_phone *) 0;
2175 p = dev->netdev;
2176 ematch = wret = swapped = 0;
2177 #ifdef ISDN_DEBUG_NET_ICALL
2178 printk(KERN_DEBUG "n_fi: di=%d ch=%d idx=%d usg=%d\n", di, ch, idx,
2179 dev->usage[idx]);
2180 #endif
2181 while (p) {
2182 int matchret;
2183 isdn_net_local *lp = p->local;
2184
2185 /* If last check has triggered as binding-swap, revert it */
2186 switch (swapped) {
2187 case 2:
2188 isdn_net_swap_usage(idx, sidx);
2189 /* fall through */
2190 case 1:
2191 isdn_net_swapbind(di);
2192 break;
2193 }
2194 swapped = 0;
2195 if (!(matchret = isdn_msncmp(eaz, isdn_map_eaz2msn(lp->msn, di))))
2196 ematch = 1;
2197 /* Remember if more numbers eventually can match */
2198 if (matchret > wret)
2199 wret = matchret;
2200 #ifdef ISDN_DEBUG_NET_ICALL
2201 printk(KERN_DEBUG "n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
2202 lp->name, lp->msn, lp->flags, lp->dialstate);
2203 #endif
2204 if ((!matchret) && /* EAZ is matching */
2205 (((!(lp->flags & ISDN_NET_CONNECTED)) && /* but not connected */
2206 (USG_NONE(dev->usage[idx]))) || /* and ch. unused or */
2207 ((((lp->dialstate == 4) || (lp->dialstate == 12)) && /* if dialing */
2208 (!(lp->flags & ISDN_NET_CALLBACK))) /* but no callback */
2209 )))
2210 {
2211 #ifdef ISDN_DEBUG_NET_ICALL
2212 printk(KERN_DEBUG "n_fi: match1, pdev=%d pch=%d\n",
2213 lp->pre_device, lp->pre_channel);
2214 #endif
2215 if (dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) {
2216 if ((lp->pre_channel != ch) ||
2217 (lp->pre_device != di)) {
2218 /* Here we got a problem:
2219 * If using an ICN-Card, an incoming call is always signaled on
2220 * on the first channel of the card, if both channels are
2221 * down. However this channel may be bound exclusive. If the
2222 * second channel is free, this call should be accepted.
2223 * The solution is horribly but it runs, so what:
2224 * We exchange the exclusive bindings of the two channels, the
2225 * corresponding variables in the interface-structs.
2226 */
2227 if (ch == 0) {
2228 sidx = isdn_dc2minor(di, 1);
2229 #ifdef ISDN_DEBUG_NET_ICALL
2230 printk(KERN_DEBUG "n_fi: ch is 0\n");
2231 #endif
2232 if (USG_NONE(dev->usage[sidx])) {
2233 /* Second Channel is free, now see if it is bound
2234 * exclusive too. */
2235 if (dev->usage[sidx] & ISDN_USAGE_EXCLUSIVE) {
2236 #ifdef ISDN_DEBUG_NET_ICALL
2237 printk(KERN_DEBUG "n_fi: 2nd channel is down and bound\n");
2238 #endif
2239 /* Yes, swap bindings only, if the original
2240 * binding is bound to channel 1 of this driver */
2241 if ((lp->pre_device == di) &&
2242 (lp->pre_channel == 1)) {
2243 isdn_net_swapbind(di);
2244 swapped = 1;
2245 } else {
2246 /* ... else iterate next device */
2247 p = (isdn_net_dev *) p->next;
2248 continue;
2249 }
2250 } else {
2251 #ifdef ISDN_DEBUG_NET_ICALL
2252 printk(KERN_DEBUG "n_fi: 2nd channel is down and unbound\n");
2253 #endif
2254 /* No, swap always and swap excl-usage also */
2255 isdn_net_swap_usage(idx, sidx);
2256 isdn_net_swapbind(di);
2257 swapped = 2;
2258 }
2259 /* Now check for exclusive binding again */
2260 #ifdef ISDN_DEBUG_NET_ICALL
2261 printk(KERN_DEBUG "n_fi: final check\n");
2262 #endif
2263 if ((dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) &&
2264 ((lp->pre_channel != ch) ||
2265 (lp->pre_device != di))) {
2266 #ifdef ISDN_DEBUG_NET_ICALL
2267 printk(KERN_DEBUG "n_fi: final check failed\n");
2268 #endif
2269 p = (isdn_net_dev *) p->next;
2270 continue;
2271 }
2272 }
2273 } else {
2274 /* We are already on the second channel, so nothing to do */
2275 #ifdef ISDN_DEBUG_NET_ICALL
2276 printk(KERN_DEBUG "n_fi: already on 2nd channel\n");
2277 #endif
2278 }
2279 }
2280 }
2281 #ifdef ISDN_DEBUG_NET_ICALL
2282 printk(KERN_DEBUG "n_fi: match2\n");
2283 #endif
2284 n = lp->phone[0];
2285 if (lp->flags & ISDN_NET_SECURE) {
2286 while (n) {
2287 if (!isdn_msncmp(nr, n->num))
2288 break;
2289 n = (isdn_net_phone *) n->next;
2290 }
2291 }
2292 if (n || (!(lp->flags & ISDN_NET_SECURE))) {
2293 #ifdef ISDN_DEBUG_NET_ICALL
2294 printk(KERN_DEBUG "n_fi: match3\n");
2295 #endif
2296 /* matching interface found */
2297
2298 /*
2299 * Is the state STOPPED?
2300 * If so, no dialin is allowed,
2301 * so reject actively.
2302 * */
2303 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2304 restore_flags(flags);
2305 printk(KERN_INFO "incoming call, interface %s `stopped' -> rejected\n",
2306 lp->name);
2307 return 3;
2308 }
2309 /*
2310 * Is the interface up?
2311 * If not, reject the call actively.
2312 */
2313 if (!isdn_net_device_started(p)) {
2314 restore_flags(flags);
2315 printk(KERN_INFO "%s: incoming call, interface down -> rejected\n",
2316 lp->name);
2317 return 3;
2318 }
2319 /* Interface is up, now see if it's a slave. If so, see if
2320 * it's master and parent slave is online. If not, reject the call.
2321 */
2322 if (lp->master) {
2323 isdn_net_local *mlp = (isdn_net_local *) lp->master->priv;
2324 printk(KERN_DEBUG "ICALLslv: %s\n", lp->name);
2325 printk(KERN_DEBUG "master=%s\n", mlp->name);
2326 if (mlp->flags & ISDN_NET_CONNECTED) {
2327 printk(KERN_DEBUG "master online\n");
2328 /* Master is online, find parent-slave (master if first slave) */
2329 while (mlp->slave) {
2330 if ((isdn_net_local *) mlp->slave->priv == lp)
2331 break;
2332 mlp = (isdn_net_local *) mlp->slave->priv;
2333 }
2334 } else
2335 printk(KERN_DEBUG "master offline\n");
2336 /* Found parent, if it's offline iterate next device */
2337 printk(KERN_DEBUG "mlpf: %d\n", mlp->flags & ISDN_NET_CONNECTED);
2338 if (!(mlp->flags & ISDN_NET_CONNECTED)) {
2339 p = (isdn_net_dev *) p->next;
2340 continue;
2341 }
2342 }
2343 if (lp->flags & ISDN_NET_CALLBACK) {
2344 int chi;
2345 /*
2346 * Is the state MANUAL?
2347 * If so, no callback can be made,
2348 * so reject actively.
2349 * */
2350 if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
2351 restore_flags(flags);
2352 printk(KERN_INFO "incoming call for callback, interface %s `off' -> rejected\n",
2353 lp->name);
2354 return 3;
2355 }
2356 printk(KERN_DEBUG "%s: call from %s -> %s, start callback\n",
2357 lp->name, nr, eaz);
2358 if (lp->phone[1]) {
2359 /* Grab a free ISDN-Channel */
2360 if ((chi =
2361 isdn_get_free_channel(
2362 ISDN_USAGE_NET,
2363 lp->l2_proto,
2364 lp->l3_proto,
2365 lp->pre_device,
2366 lp->pre_channel,
2367 lp->msn)
2368 ) < 0) {
2369
2370 printk(KERN_WARNING "isdn_net_find_icall: No channel for %s\n", lp->name);
2371 restore_flags(flags);
2372 return 0;
2373 }
2374 /* Setup dialstate. */
2375 lp->dtimer = 0;
2376 lp->dialstate = 11;
2377 /* Connect interface with channel */
2378 isdn_net_bind_channel(lp, chi);
2379 #ifdef CONFIG_ISDN_PPP
2380 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2381 if (isdn_ppp_bind(lp) < 0) {
2382 isdn_net_unbind_channel(lp);
2383 restore_flags(flags);
2384 return 0;
2385 }
2386 #endif
2387 /* Initiate dialing by returning 2 or 4 */
2388 restore_flags(flags);
2389 return (lp->flags & ISDN_NET_CBHUP) ? 2 : 4;
2390 } else
2391 printk(KERN_WARNING "isdn_net: %s: No phone number\n", lp->name);
2392 restore_flags(flags);
2393 return 0;
2394 } else {
2395 printk(KERN_DEBUG "%s: call from %s -> %s accepted\n", lp->name, nr,
2396 eaz);
2397 /* if this interface is dialing, it does it probably on a different
2398 device, so free this device */
2399 if ((lp->dialstate == 4) || (lp->dialstate == 12)) {
2400 #ifdef CONFIG_ISDN_PPP
2401 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2402 isdn_ppp_free(lp);
2403 #endif
2404 isdn_net_lp_disconnected(lp);
2405 isdn_free_channel(lp->isdn_device, lp->isdn_channel,
2406 ISDN_USAGE_NET);
2407 }
2408 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2409 dev->usage[idx] |= ISDN_USAGE_NET;
2410 strcpy(dev->num[idx], nr);
2411 isdn_info_update();
2412 dev->st_netdev[idx] = lp->netdev;
2413 lp->isdn_device = di;
2414 lp->isdn_channel = ch;
2415 lp->ppp_slot = -1;
2416 lp->flags |= ISDN_NET_CONNECTED;
2417 lp->dialstate = 7;
2418 lp->dtimer = 0;
2419 lp->outgoing = 0;
2420 lp->huptimer = 0;
2421 lp->hupflags |= ISDN_WAITCHARGE;
2422 lp->hupflags &= ~ISDN_HAVECHARGE;
2423 #ifdef CONFIG_ISDN_PPP
2424 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2425 if (isdn_ppp_bind(lp) < 0) {
2426 isdn_net_unbind_channel(lp);
2427 restore_flags(flags);
2428 return 0;
2429 }
2430 #endif
2431 restore_flags(flags);
2432 return 1;
2433 }
2434 }
2435 }
2436 p = (isdn_net_dev *) p->next;
2437 }
2438 /* If none of configured EAZ/MSN matched and not verbose, be silent */
2439 if (!ematch || dev->net_verbose)
2440 printk(KERN_INFO "isdn_net: call from %s -> %d %s ignored\n", nr, di, eaz);
2441 restore_flags(flags);
2442 return (wret == 2)?5:0;
2443 }
2444
2445 /*
2446 * Search list of net-interfaces for an interface with given name.
2447 */
2448 isdn_net_dev *
2449 isdn_net_findif(char *name)
2450 {
2451 isdn_net_dev *p = dev->netdev;
2452
2453 while (p) {
2454 if (!strcmp(p->local->name, name))
2455 return p;
2456 p = (isdn_net_dev *) p->next;
2457 }
2458 return (isdn_net_dev *) NULL;
2459 }
2460
2461 /*
2462 * Force a net-interface to dial out.
2463 * This is called from the userlevel-routine below or
2464 * from isdn_net_start_xmit().
2465 */
2466 int
2467 isdn_net_force_dial_lp(isdn_net_local * lp)
2468 {
2469 if ((!(lp->flags & ISDN_NET_CONNECTED)) && !lp->dialstate) {
2470 int chi;
2471 if (lp->phone[1]) {
2472 ulong flags;
2473 save_flags(flags);
2474 cli();
2475
2476 /* Grab a free ISDN-Channel */
2477 if ((chi =
2478 isdn_get_free_channel(
2479 ISDN_USAGE_NET,
2480 lp->l2_proto,
2481 lp->l3_proto,
2482 lp->pre_device,
2483 lp->pre_channel,
2484 lp->msn)
2485 ) < 0) {
2486 printk(KERN_WARNING "isdn_net_force_dial: No channel for %s\n", lp->name);
2487 restore_flags(flags);
2488 return -EAGAIN;
2489 }
2490 lp->dialstate = 1;
2491 /* Connect interface with channel */
2492 isdn_net_bind_channel(lp, chi);
2493 #ifdef CONFIG_ISDN_PPP
2494 if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
2495 if (isdn_ppp_bind(lp) < 0) {
2496 isdn_net_unbind_channel(lp);
2497 restore_flags(flags);
2498 return -EAGAIN;
2499 }
2500 #endif
2501 /* Initiate dialing */
2502 restore_flags(flags);
2503 isdn_net_dial();
2504 return 0;
2505 } else
2506 return -EINVAL;
2507 } else
2508 return -EBUSY;
2509 }
2510
2511 /*
2512 * This is called from certain upper protocol layers (multilink ppp
2513 * and x25iface encapsulation module) that want to initiate dialing
2514 * themselves.
2515 */
2516 int
2517 isdn_net_dial_req(isdn_net_local * lp)
2518 {
2519 /* is there a better error code? */
2520 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) return -EBUSY;
2521
2522 return isdn_net_force_dial_lp(lp);
2523 }
2524
2525 /*
2526 * Force a net-interface to dial out.
2527 * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
2528 */
2529 int
2530 isdn_net_force_dial(char *name)
2531 {
2532 isdn_net_dev *p = isdn_net_findif(name);
2533
2534 if (!p)
2535 return -ENODEV;
2536 return (isdn_net_force_dial_lp(p->local));
2537 }
2538
2539 /*
2540 * Allocate a new network-interface and initialize its data structures.
2541 */
2542 char *
2543 isdn_net_new(char *name, struct net_device *master)
2544 {
2545 isdn_net_dev *netdev;
2546
2547 /* Avoid creating an existing interface */
2548 if (isdn_net_findif(name)) {
2549 printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
2550 return NULL;
2551 }
2552 if (!(netdev = (isdn_net_dev *) kmalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
2553 printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
2554 return NULL;
2555 }
2556 memset(netdev, 0, sizeof(isdn_net_dev));
2557 if (!(netdev->local = (isdn_net_local *) kmalloc(sizeof(isdn_net_local), GFP_KERNEL))) {
2558 printk(KERN_WARNING "isdn_net: Could not allocate device locals\n");
2559 kfree(netdev);
2560 return NULL;
2561 }
2562 memset(netdev->local, 0, sizeof(isdn_net_local));
2563 if (name == NULL)
2564 strcpy(netdev->local->name, " ");
2565 else
2566 strcpy(netdev->local->name, name);
2567 strcpy(netdev->dev.name, netdev->local->name);
2568 netdev->dev.priv = netdev->local;
2569 netdev->dev.init = isdn_net_init;
2570 netdev->local->p_encap = ISDN_NET_ENCAP_RAWIP;
2571 if (master) {
2572 /* Device shall be a slave */
2573 struct net_device *p = (((isdn_net_local *) master->priv)->slave);
2574 struct net_device *q = master;
2575
2576 netdev->local->master = master;
2577 /* Put device at end of slave-chain */
2578 while (p) {
2579 q = p;
2580 p = (((isdn_net_local *) p->priv)->slave);
2581 }
2582 ((isdn_net_local *) q->priv)->slave = &(netdev->dev);
2583 } else {
2584 /* Device shall be a master */
2585 /*
2586 * Watchdog timer (currently) for master only.
2587 */
2588 netdev->dev.tx_timeout = isdn_net_tx_timeout;
2589 netdev->dev.watchdog_timeo = ISDN_NET_TX_TIMEOUT;
2590 if (register_netdev(&netdev->dev) != 0) {
2591 printk(KERN_WARNING "isdn_net: Could not register net-device\n");
2592 kfree(netdev->local);
2593 kfree(netdev);
2594 return NULL;
2595 }
2596 }
2597 netdev->local->magic = ISDN_NET_MAGIC;
2598
2599 netdev->queue = netdev->local;
2600 spin_lock_init(&netdev->queue_lock);
2601
2602 netdev->local->last = netdev->local;
2603 netdev->local->netdev = netdev;
2604 netdev->local->next = netdev->local;
2605
2606 netdev->local->tqueue.sync = 0;
2607 netdev->local->tqueue.routine = isdn_net_softint;
2608 netdev->local->tqueue.data = netdev->local;
2609 spin_lock_init(&netdev->local->xmit_lock);
2610
2611 netdev->local->isdn_device = -1;
2612 netdev->local->isdn_channel = -1;
2613 netdev->local->pre_device = -1;
2614 netdev->local->pre_channel = -1;
2615 netdev->local->exclusive = -1;
2616 netdev->local->ppp_slot = -1;
2617 netdev->local->pppbind = -1;
2618 skb_queue_head_init(&netdev->local->super_tx_queue);
2619 netdev->local->l2_proto = ISDN_PROTO_L2_X75I;
2620 netdev->local->l3_proto = ISDN_PROTO_L3_TRANS;
2621 netdev->local->triggercps = 6000;
2622 netdev->local->slavedelay = 10 * HZ;
2623 netdev->local->hupflags = ISDN_INHUP; /* Do hangup even on incoming calls */
2624 netdev->local->onhtime = 10; /* Default hangup-time for saving costs
2625 of those who forget configuring this */
2626 netdev->local->dialmax = 1;
2627 netdev->local->flags = ISDN_NET_CBHUP | ISDN_NET_DM_MANUAL; /* Hangup before Callback, manual dial */
2628 netdev->local->cbdelay = 25; /* Wait 5 secs before Callback */
2629 netdev->local->dialtimeout = -1; /* Infinite Dial-Timeout */
2630 netdev->local->dialwait = 5 * HZ; /* Wait 5 sec. after failed dial */
2631 netdev->local->dialstarted = 0; /* Jiffies of last dial-start */
2632 netdev->local->dialwait_timer = 0; /* Jiffies of earliest next dial-start */
2633
2634 /* Put into to netdev-chain */
2635 netdev->next = (void *) dev->netdev;
2636 dev->netdev = netdev;
2637 return netdev->dev.name;
2638 }
2639
2640 char *
2641 isdn_net_newslave(char *parm)
2642 {
2643 char *p = strchr(parm, ',');
2644 isdn_net_dev *n;
2645 char newname[10];
2646
2647 if (p) {
2648 /* Slave-Name MUST not be empty */
2649 if (!strlen(p + 1))
2650 return NULL;
2651 strcpy(newname, p + 1);
2652 *p = 0;
2653 /* Master must already exist */
2654 if (!(n = isdn_net_findif(parm)))
2655 return NULL;
2656 /* Master must be a real interface, not a slave */
2657 if (n->local->master)
2658 return NULL;
2659 /* Master must not be started yet */
2660 if (isdn_net_device_started(n))
2661 return NULL;
2662 return (isdn_net_new(newname, &(n->dev)));
2663 }
2664 return NULL;
2665 }
2666
2667 /*
2668 * Set interface-parameters.
2669 * Always set all parameters, so the user-level application is responsible
2670 * for not overwriting existing setups. It has to get the current
2671 * setup first, if only selected parameters are to be changed.
2672 */
2673 int
2674 isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
2675 {
2676 isdn_net_dev *p = isdn_net_findif(cfg->name);
2677 ulong features;
2678 int i;
2679 int drvidx;
2680 int chidx;
2681 char drvid[25];
2682 #ifdef CONFIG_ISDN_X25
2683 ulong flags;
2684 #endif
2685 if (p) {
2686 isdn_net_local *lp = p->local;
2687
2688 /* See if any registered driver supports the features we want */
2689 features = ((1 << cfg->l2_proto) << ISDN_FEATURE_L2_SHIFT) |
2690 ((1 << cfg->l3_proto) << ISDN_FEATURE_L3_SHIFT);
2691 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2692 if (dev->drv[i])
2693 if ((dev->drv[i]->interface->features & features) == features)
2694 break;
2695 if (i == ISDN_MAX_DRIVERS) {
2696 printk(KERN_WARNING "isdn_net: No driver with selected features\n");
2697 return -ENODEV;
2698 }
2699 if (lp->p_encap != cfg->p_encap){
2700 #ifdef CONFIG_ISDN_X25
2701 struct concap_proto * cprot = p -> cprot;
2702 #endif
2703 if (isdn_net_device_started(p)) {
2704 printk(KERN_WARNING "%s: cannot change encap when if is up\n",
2705 lp->name);
2706 return -EBUSY;
2707 }
2708 #ifdef CONFIG_ISDN_X25
2709 /* delete old encapsulation protocol if present ... */
2710 save_flags(flags);
2711 cli(); /* avoid races with incoming events trying to
2712 call cprot->pops methods */
2713 if( cprot && cprot -> pops )
2714 cprot -> pops -> proto_del ( cprot );
2715 p -> cprot = NULL;
2716 lp -> dops = NULL;
2717 restore_flags(flags);
2718 /* ... , prepare for configuration of new one ... */
2719 switch ( cfg -> p_encap ){
2720 case ISDN_NET_ENCAP_X25IFACE:
2721 lp -> dops = &isdn_concap_reliable_dl_dops;
2722 }
2723 /* ... and allocate new one ... */
2724 p -> cprot = isdn_concap_new( cfg -> p_encap );
2725 /* p -> cprot == NULL now if p_encap is not supported
2726 by means of the concap_proto mechanism */
2727 /* the protocol is not configured yet; this will
2728 happen later when isdn_net_reset() is called */
2729 #endif
2730 }
2731 switch ( cfg->p_encap ) {
2732 case ISDN_NET_ENCAP_SYNCPPP:
2733 #ifndef CONFIG_ISDN_PPP
2734 printk(KERN_WARNING "%s: SyncPPP support not configured\n",
2735 lp->name);
2736 return -EINVAL;
2737 #else
2738 p->dev.type = ARPHRD_PPP; /* change ARP type */
2739 p->dev.addr_len = 0;
2740 p->dev.do_ioctl = isdn_ppp_dev_ioctl;
2741 #endif
2742 break;
2743 case ISDN_NET_ENCAP_X25IFACE:
2744 #ifndef CONFIG_ISDN_X25
2745 printk(KERN_WARNING "%s: isdn-x25 support not configured\n",
2746 p->local->name);
2747 return -EINVAL;
2748 #else
2749 p->dev.type = ARPHRD_X25; /* change ARP type */
2750 p->dev.addr_len = 0;
2751 #endif
2752 break;
2753 case ISDN_NET_ENCAP_CISCOHDLCK:
2754 p->dev.do_ioctl = isdn_ciscohdlck_dev_ioctl;
2755 break;
2756 default:
2757 if( cfg->p_encap >= 0 &&
2758 cfg->p_encap <= ISDN_NET_ENCAP_MAX_ENCAP )
2759 break;
2760 printk(KERN_WARNING
2761 "%s: encapsulation protocol %d not supported\n",
2762 p->local->name, cfg->p_encap);
2763 return -EINVAL;
2764 }
2765 if (strlen(cfg->drvid)) {
2766 /* A bind has been requested ... */
2767 char *c,
2768 *e;
2769
2770 drvidx = -1;
2771 chidx = -1;
2772 strcpy(drvid, cfg->drvid);
2773 if ((c = strchr(drvid, ','))) {
2774 /* The channel-number is appended to the driver-Id with a comma */
2775 chidx = (int) simple_strtoul(c + 1, &e, 10);
2776 if (e == c)
2777 chidx = -1;
2778 *c = '\0';
2779 }
2780 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
2781 /* Lookup driver-Id in array */
2782 if (!(strcmp(dev->drvid[i], drvid))) {
2783 drvidx = i;
2784 break;
2785 }
2786 if ((drvidx == -1) || (chidx == -1))
2787 /* Either driver-Id or channel-number invalid */
2788 return -ENODEV;
2789 } else {
2790 /* Parameters are valid, so get them */
2791 drvidx = lp->pre_device;
2792 chidx = lp->pre_channel;
2793 }
2794 if (cfg->exclusive > 0) {
2795 ulong flags;
2796
2797 /* If binding is exclusive, try to grab the channel */
2798 save_flags(flags);
2799 if ((i = isdn_get_free_channel(ISDN_USAGE_NET,
2800 lp->l2_proto, lp->l3_proto, drvidx,
2801 chidx, lp->msn)) < 0) {
2802 /* Grab failed, because desired channel is in use */
2803 lp->exclusive = -1;
2804 restore_flags(flags);
2805 return -EBUSY;
2806 }
2807 /* All went ok, so update isdninfo */
2808 dev->usage[i] = ISDN_USAGE_EXCLUSIVE;
2809 isdn_info_update();
2810 restore_flags(flags);
2811 lp->exclusive = i;
2812 } else {
2813 /* Non-exclusive binding or unbind. */
2814 lp->exclusive = -1;
2815 if ((lp->pre_device != -1) && (cfg->exclusive == -1)) {
2816 isdn_unexclusive_channel(lp->pre_device, lp->pre_channel);
2817 isdn_free_channel(lp->pre_device, lp->pre_channel, ISDN_USAGE_NET);
2818 drvidx = -1;
2819 chidx = -1;
2820 }
2821 }
2822 strcpy(lp->msn, cfg->eaz);
2823 lp->pre_device = drvidx;
2824 lp->pre_channel = chidx;
2825 lp->onhtime = cfg->onhtime;
2826 lp->charge = cfg->charge;
2827 lp->l2_proto = cfg->l2_proto;
2828 lp->l3_proto = cfg->l3_proto;
2829 lp->cbdelay = cfg->cbdelay;
2830 lp->dialmax = cfg->dialmax;
2831 lp->triggercps = cfg->triggercps;
2832 lp->slavedelay = cfg->slavedelay * HZ;
2833 lp->pppbind = cfg->pppbind;
2834 lp->dialtimeout = cfg->dialtimeout >= 0 ? cfg->dialtimeout * HZ : -1;
2835 lp->dialwait = cfg->dialwait * HZ;
2836 if (cfg->secure)
2837 lp->flags |= ISDN_NET_SECURE;
2838 else
2839 lp->flags &= ~ISDN_NET_SECURE;
2840 if (cfg->cbhup)
2841 lp->flags |= ISDN_NET_CBHUP;
2842 else
2843 lp->flags &= ~ISDN_NET_CBHUP;
2844 switch (cfg->callback) {
2845 case 0:
2846 lp->flags &= ~(ISDN_NET_CALLBACK | ISDN_NET_CBOUT);
2847 break;
2848 case 1:
2849 lp->flags |= ISDN_NET_CALLBACK;
2850 lp->flags &= ~ISDN_NET_CBOUT;
2851 break;
2852 case 2:
2853 lp->flags |= ISDN_NET_CBOUT;
2854 lp->flags &= ~ISDN_NET_CALLBACK;
2855 break;
2856 }
2857 lp->flags &= ~ISDN_NET_DIALMODE_MASK; /* first all bits off */
2858 if (cfg->dialmode && !(cfg->dialmode & ISDN_NET_DIALMODE_MASK)) {
2859 /* old isdnctrl version, where only 0 or 1 is given */
2860 printk(KERN_WARNING
2861 "Old isdnctrl version detected! Please update.\n");
2862 lp->flags |= ISDN_NET_DM_OFF; /* turn on `off' bit */
2863 }
2864 else {
2865 lp->flags |= cfg->dialmode; /* turn on selected bits */
2866 }
2867 if (cfg->chargehup)
2868 lp->hupflags |= ISDN_CHARGEHUP;
2869 else
2870 lp->hupflags &= ~ISDN_CHARGEHUP;
2871 if (cfg->ihup)
2872 lp->hupflags |= ISDN_INHUP;
2873 else
2874 lp->hupflags &= ~ISDN_INHUP;
2875 if (cfg->chargeint > 10) {
2876 lp->hupflags |= ISDN_CHARGEHUP | ISDN_HAVECHARGE | ISDN_MANCHARGE;
2877 lp->chargeint = cfg->chargeint * HZ;
2878 }
2879 if (cfg->p_encap != lp->p_encap) {
2880 if (cfg->p_encap == ISDN_NET_ENCAP_RAWIP) {
2881 p->dev.hard_header = NULL;
2882 p->dev.hard_header_cache = NULL;
2883 p->dev.header_cache_update = NULL;
2884 p->dev.flags = IFF_NOARP|IFF_POINTOPOINT;
2885 } else {
2886 p->dev.hard_header = isdn_net_header;
2887 if (cfg->p_encap == ISDN_NET_ENCAP_ETHER) {
2888 p->dev.hard_header_cache = lp->org_hhc;
2889 p->dev.header_cache_update = lp->org_hcu;
2890 p->dev.flags = IFF_BROADCAST | IFF_MULTICAST;
2891 } else {
2892 p->dev.hard_header_cache = NULL;
2893 p->dev.header_cache_update = NULL;
2894 p->dev.flags = IFF_NOARP|IFF_POINTOPOINT;
2895 }
2896 }
2897 }
2898 lp->p_encap = cfg->p_encap;
2899 return 0;
2900 }
2901 return -ENODEV;
2902 }
2903
2904 /*
2905 * Perform get-interface-parameters.ioctl
2906 */
2907 int
2908 isdn_net_getcfg(isdn_net_ioctl_cfg * cfg)
2909 {
2910 isdn_net_dev *p = isdn_net_findif(cfg->name);
2911
2912 if (p) {
2913 isdn_net_local *lp = p->local;
2914
2915 strcpy(cfg->eaz, lp->msn);
2916 cfg->exclusive = lp->exclusive;
2917 if (lp->pre_device >= 0) {
2918 sprintf(cfg->drvid, "%s,%d", dev->drvid[lp->pre_device],
2919 lp->pre_channel);
2920 } else
2921 cfg->drvid[0] = '\0';
2922 cfg->onhtime = lp->onhtime;
2923 cfg->charge = lp->charge;
2924 cfg->l2_proto = lp->l2_proto;
2925 cfg->l3_proto = lp->l3_proto;
2926 cfg->p_encap = lp->p_encap;
2927 cfg->secure = (lp->flags & ISDN_NET_SECURE) ? 1 : 0;
2928 cfg->callback = 0;
2929 if (lp->flags & ISDN_NET_CALLBACK)
2930 cfg->callback = 1;
2931 if (lp->flags & ISDN_NET_CBOUT)
2932 cfg->callback = 2;
2933 cfg->cbhup = (lp->flags & ISDN_NET_CBHUP) ? 1 : 0;
2934 cfg->dialmode = lp->flags & ISDN_NET_DIALMODE_MASK;
2935 cfg->chargehup = (lp->hupflags & 4) ? 1 : 0;
2936 cfg->ihup = (lp->hupflags & 8) ? 1 : 0;
2937 cfg->cbdelay = lp->cbdelay;
2938 cfg->dialmax = lp->dialmax;
2939 cfg->triggercps = lp->triggercps;
2940 cfg->slavedelay = lp->slavedelay / HZ;
2941 cfg->chargeint = (lp->hupflags & ISDN_CHARGEHUP) ?
2942 (lp->chargeint / HZ) : 0;
2943 cfg->pppbind = lp->pppbind;
2944 cfg->dialtimeout = lp->dialtimeout >= 0 ? lp->dialtimeout / HZ : -1;
2945 cfg->dialwait = lp->dialwait / HZ;
2946 if (lp->slave)
2947 strcpy(cfg->slave, ((isdn_net_local *) lp->slave->priv)->name);
2948 else
2949 cfg->slave[0] = '\0';
2950 if (lp->master)
2951 strcpy(cfg->master, ((isdn_net_local *) lp->master->priv)->name);
2952 else
2953 cfg->master[0] = '\0';
2954 return 0;
2955 }
2956 return -ENODEV;
2957 }
2958
2959 /*
2960 * Add a phone-number to an interface.
2961 */
2962 int
2963 isdn_net_addphone(isdn_net_ioctl_phone * phone)
2964 {
2965 isdn_net_dev *p = isdn_net_findif(phone->name);
2966 isdn_net_phone *n;
2967
2968 if (p) {
2969 if (!(n = (isdn_net_phone *) kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
2970 return -ENOMEM;
2971 strcpy(n->num, phone->phone);
2972 n->next = p->local->phone[phone->outgoing & 1];
2973 p->local->phone[phone->outgoing & 1] = n;
2974 return 0;
2975 }
2976 return -ENODEV;
2977 }
2978
2979 /*
2980 * Copy a string of all phone-numbers of an interface to user space.
2981 * This might sleep and must be called with the isdn semaphore down.
2982 */
2983 int
2984 isdn_net_getphones(isdn_net_ioctl_phone * phone, char *phones)
2985 {
2986 isdn_net_dev *p = isdn_net_findif(phone->name);
2987 int inout = phone->outgoing & 1;
2988 int more = 0;
2989 int count = 0;
2990 isdn_net_phone *n;
2991
2992 if (!p)
2993 return -ENODEV;
2994 inout &= 1;
2995 for (n = p->local->phone[inout]; n; n = n->next) {
2996 if (more) {
2997 put_user(' ', phones++);
2998 count++;
2999 }
3000 if (copy_to_user(phones, n->num, strlen(n->num) + 1)) {
3001 return -EFAULT;
3002 }
3003 phones += strlen(n->num);
3004 count += strlen(n->num);
3005 more = 1;
3006 }
3007 put_user(0, phones);
3008 count++;
3009 return count;
3010 }
3011
3012 /*
3013 * Copy a string containing the peer's phone number of a connected interface
3014 * to user space.
3015 */
3016 int
3017 isdn_net_getpeer(isdn_net_ioctl_phone *phone, isdn_net_ioctl_phone *peer)
3018 {
3019 isdn_net_dev *p = isdn_net_findif(phone->name);
3020 int ch, dv, idx;
3021
3022 if (!p) return -ENODEV;
3023 /*
3024 * Theoretical race: while this executes, the remote number might
3025 * become invalid (hang up) or change (new connection), resulting
3026 * in (partially) wrong number copied to user. This race
3027 * currently ignored.
3028 */
3029 ch = p->local->isdn_channel;
3030 dv = p->local->isdn_device;
3031 if(ch<0 && dv<0) return -ENOTCONN;
3032 idx = isdn_dc2minor(dv, ch);
3033 if (idx<0) return -ENODEV;
3034 /* for pre-bound channels, we need this extra check */
3035 if ( strncmp(dev->num[idx],"???",3) == 0 ) return -ENOTCONN;
3036 strncpy(phone->phone,dev->num[idx],ISDN_MSNLEN);
3037 phone->outgoing=USG_OUTGOING(dev->usage[idx]);
3038 if ( copy_to_user(peer,phone,sizeof(*peer)) ) return -EFAULT;
3039 return 0;
3040 }
3041 /*
3042 * Delete a phone-number from an interface.
3043 */
3044 int
3045 isdn_net_delphone(isdn_net_ioctl_phone * phone)
3046 {
3047 isdn_net_dev *p = isdn_net_findif(phone->name);
3048 int inout = phone->outgoing & 1;
3049 isdn_net_phone *n;
3050 isdn_net_phone *m;
3051 ulong flags;
3052
3053 if (p) {
3054 save_flags(flags);
3055 cli();
3056 n = p->local->phone[inout];
3057 m = NULL;
3058 while (n) {
3059 if (!strcmp(n->num, phone->phone)) {
3060 if (p->local->dial == n)
3061 p->local->dial = n->next;
3062 if (m)
3063 m->next = n->next;
3064 else
3065 p->local->phone[inout] = n->next;
3066 kfree(n);
3067 restore_flags(flags);
3068 return 0;
3069 }
3070 m = n;
3071 n = (isdn_net_phone *) n->next;
3072 }
3073 restore_flags(flags);
3074 return -EINVAL;
3075 }
3076 return -ENODEV;
3077 }
3078
3079 /*
3080 * Delete all phone-numbers of an interface.
3081 */
3082 static int
3083 isdn_net_rmallphone(isdn_net_dev * p)
3084 {
3085 isdn_net_phone *n;
3086 isdn_net_phone *m;
3087 ulong flags;
3088 int i;
3089
3090 save_flags(flags);
3091 cli();
3092 for (i = 0; i < 2; i++) {
3093 n = p->local->phone[i];
3094 while (n) {
3095 m = n->next;
3096 kfree(n);
3097 n = m;
3098 }
3099 p->local->phone[i] = NULL;
3100 }
3101 p->local->dial = NULL;
3102 restore_flags(flags);
3103 return 0;
3104 }
3105
3106 /*
3107 * Force a hangup of a network-interface.
3108 */
3109 int
3110 isdn_net_force_hangup(char *name)
3111 {
3112 isdn_net_dev *p = isdn_net_findif(name);
3113 struct net_device *q;
3114
3115 if (p) {
3116 if (p->local->isdn_device < 0)
3117 return 1;
3118 q = p->local->slave;
3119 /* If this interface has slaves, do a hangup for them also. */
3120 while (q) {
3121 isdn_net_hangup(q);
3122 q = (((isdn_net_local *) q->priv)->slave);
3123 }
3124 isdn_net_hangup(&p->dev);
3125 return 0;
3126 }
3127 return -ENODEV;
3128 }
3129
3130 /*
3131 * Helper-function for isdn_net_rm: Do the real work.
3132 */
3133 static int
3134 isdn_net_realrm(isdn_net_dev * p, isdn_net_dev * q)
3135 {
3136 ulong flags;
3137
3138 save_flags(flags);
3139 cli();
3140 if (isdn_net_device_started(p)) {
3141 restore_flags(flags);
3142 return -EBUSY;
3143 }
3144 #ifdef CONFIG_ISDN_X25
3145 if( p -> cprot && p -> cprot -> pops )
3146 p -> cprot -> pops -> proto_del ( p -> cprot );
3147 #endif
3148 /* Free all phone-entries */
3149 isdn_net_rmallphone(p);
3150 /* If interface is bound exclusive, free channel-usage */
3151 if (p->local->exclusive != -1)
3152 isdn_unexclusive_channel(p->local->pre_device, p->local->pre_channel);
3153 if (p->local->master) {
3154 /* It's a slave-device, so update master's slave-pointer if necessary */
3155 if (((isdn_net_local *) (p->local->master->priv))->slave == &p->dev)
3156 ((isdn_net_local *) (p->local->master->priv))->slave = p->local->slave;
3157 } else {
3158 /* Unregister only if it's a master-device */
3159 p->dev.hard_header_cache = p->local->org_hhc;
3160 p->dev.header_cache_update = p->local->org_hcu;
3161 unregister_netdev(&p->dev);
3162 }
3163 /* Unlink device from chain */
3164 if (q)
3165 q->next = p->next;
3166 else
3167 dev->netdev = p->next;
3168 if (p->local->slave) {
3169 /* If this interface has a slave, remove it also */
3170 char *slavename = ((isdn_net_local *) (p->local->slave->priv))->name;
3171 isdn_net_dev *n = dev->netdev;
3172 q = NULL;
3173 while (n) {
3174 if (!strcmp(n->local->name, slavename)) {
3175 isdn_net_realrm(n, q);
3176 break;
3177 }
3178 q = n;
3179 n = (isdn_net_dev *) n->next;
3180 }
3181 }
3182 /* If no more net-devices remain, disable auto-hangup timer */
3183 if (dev->netdev == NULL)
3184 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
3185 restore_flags(flags);
3186 kfree(p->local);
3187 kfree(p);
3188
3189 return 0;
3190 }
3191
3192 /*
3193 * Remove a single network-interface.
3194 */
3195 int
3196 isdn_net_rm(char *name)
3197 {
3198 isdn_net_dev *p;
3199 isdn_net_dev *q;
3200
3201 /* Search name in netdev-chain */
3202 p = dev->netdev;
3203 q = NULL;
3204 while (p) {
3205 if (!strcmp(p->local->name, name))
3206 return (isdn_net_realrm(p, q));
3207 q = p;
3208 p = (isdn_net_dev *) p->next;
3209 }
3210 /* If no more net-devices remain, disable auto-hangup timer */
3211 if (dev->netdev == NULL)
3212 isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
3213 return -ENODEV;
3214 }
3215
3216 /*
3217 * Remove all network-interfaces
3218 */
3219 int
3220 isdn_net_rmall(void)
3221 {
3222 ulong flags;
3223 int ret;
3224
3225 /* Walk through netdev-chain */
3226 save_flags(flags);
3227 cli();
3228 while (dev->netdev) {
3229 if (!dev->netdev->local->master) {
3230 /* Remove master-devices only, slaves get removed with their master */
3231 if ((ret = isdn_net_realrm(dev->netdev, NULL))) {
3232 restore_flags(flags);
3233 return ret;
3234 }
3235 }
3236 }
3237 dev->netdev = NULL;
3238 restore_flags(flags);
3239 return 0;
3240 }
3241