OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [isdn/] [isdn_net.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.