1 /* $Id: isdn_ppp.c,v 1.47 1999/04/18 14:06:59 fritz Exp $
3 * Linux ISDN subsystem, functions for synchronous PPP (linklevel).
5 * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * $Log: isdn_ppp.c,v $
22 * Revision 1.47 1999/04/18 14:06:59 fritz
23 * Removed TIMRU stuff.
25 * Revision 1.46 1999/04/12 12:33:35 fritz
26 * Changes from 2.0 tree.
28 * Revision 1.45 1998/12/30 17:48:24 paul
29 * fixed syncPPP callback out
31 * Revision 1.44 1998/10/30 17:55:34 he
32 * dialmode for x25iface and multulink ppp
34 * Revision 1.43 1998/10/29 17:23:54 hipp
35 * Minor MPPP fixes, verboser logging.
37 * Revision 1.42 1998/07/20 11:30:07 hipp
38 * Readded compression check
40 * Revision 1.41 1998/07/08 16:50:57 hipp
43 * Revision 1.40 1998/04/06 19:07:27 hipp
44 * added check, whether compression is enabled.
46 * Revision 1.39 1998/03/25 22:46:53 hipp
47 * Some additional CCP changes.
49 * Revision 1.38 1998/03/24 16:33:06 hipp
50 * More CCP changes. BSD compression now "works" on a local loopback link.
51 * Moved some isdn_ppp stuff from isdn.h to isdn_ppp.h
53 * Revision 1.37 1998/03/22 18:50:49 hipp
54 * Added BSD Compression for syncPPP .. UNTESTED at the moment
56 * Revision 1.36 1998/03/09 17:46:30 he
57 * merged in 2.1.89 changes
59 * Revision 1.35 1998/03/07 18:21:11 cal
60 * Dynamic Timeout-Rule-Handling vs. 971110 included
62 * Revision 1.34 1998/02/25 17:49:48 he
63 * Changed return codes caused be failing copy_{to,from}_user to -EFAULT
65 * Revision 1.33 1998/02/20 17:11:54 fritz
66 * Changes for recent kernels.
68 * Revision 1.32 1998/01/31 19:29:55 calle
69 * Merged changes from and for 2.1.82, not tested only compiled ...
71 * Revision 1.31 1997/10/09 21:29:01 fritz
72 * New HL<->LL interface:
73 * New BSENT callback with nr. of bytes included.
74 * Sending without ACK.
75 * New L1 error status (not yet in use).
76 * Cleaned up obsolete structures.
77 * Implemented Cisco-SLARP.
78 * Changed local net-interface data to be dynamically allocated.
79 * Removed old 2.0 compatibility stuff.
81 * Revision 1.30 1997/10/01 09:20:38 fritz
82 * Removed old compatibility stuff for 2.0.X kernels.
83 * From now on, this code is for 2.1.X ONLY!
84 * Old stuff is still in the separate branch.
86 * Revision 1.29 1997/08/21 23:11:44 fritz
87 * Added changes for kernels >= 2.1.45
89 * Revision 1.28 1997/06/17 13:05:57 hipp
90 * Applied Eric's underflow-patches (slightly modified)
91 * more compression changes (but disabled at the moment)
92 * changed one copy_to_user() to run with enabled IRQs
94 * changed 'proto' handling in the isdn_ppp receive code
96 * Revision 1.27 1997/03/30 16:51:17 calle
97 * changed calls to copy_from_user/copy_to_user and removed verify_area
100 * Revision 1.26 1997/02/23 16:53:44 hipp
102 * some initial changes for future PPP compresion
103 * added AC,PC compression for outgoing frames
105 * Revision 1.25 1997/02/12 20:37:35 hipp
106 * New ioctl() PPPIOCGCALLINFO, minor cleanup
108 * Revision 1.24 1997/02/11 18:32:56 fritz
109 * Bugfix in isdn_ppp_free_mpqueue().
111 * Revision 1.23 1997/02/10 11:12:19 fritz
112 * More changes for Kernel 2.1.X compatibility.
114 * Revision 1.22 1997/02/06 15:03:51 hipp
115 * changed GFP_KERNEL kmalloc to GFP_ATOMIC in isdn_ppp_fill_mpqueue()
117 * Revision 1.21 1997/02/03 23:29:38 fritz
118 * Reformatted according CodingStyle
119 * Bugfix: removed isdn_ppp_skb_destructor, used by upper layers.
120 * Misc changes for Kernel 2.1.X compatibility.
122 * Revision 1.20 1996/10/30 12:21:58 fritz
123 * Cosmetic fix: Compiler warning when compiling without MPP.
125 * Revision 1.19 1996/10/25 19:03:21 hipp
126 * changed/added some defines to (re)allow compilation without MP/VJ
128 * Revision 1.18 1996/10/22 23:14:00 fritz
129 * Changes for compatibility to 2.0.X and 2.1.X kernels.
131 * Revision 1.17 1996/10/22 09:39:49 hipp
132 * a few MP changes and bugfixes
134 * Revision 1.16 1996/09/23 01:58:10 fritz
135 * Fix: With syncPPP encapsulation, discard LCP packets
136 * when calculating hangup timeout.
138 * Revision 1.15 1996/09/07 12:50:12 hipp
139 * bugfixes (unknown device after failed dial attempt, minor bugs)
141 * Revision 1.14 1996/08/12 16:26:47 hipp
143 * changed connection management from minors to slots
145 * Revision 1.13 1996/07/01 19:47:24 hipp
146 * Fixed memory leak in VJ handling and more VJ changes
148 * Revision 1.12 1996/06/24 17:42:03 fritz
151 * Revision 1.11 1996/06/16 17:46:05 tsbogend
152 * changed unsigned long to u32 to make Alpha people happy
154 * Revision 1.10 1996/06/11 14:50:29 hipp
155 * Lot of changes and bugfixes.
156 * New scheme to resend packets to busy LL devices.
158 * Revision 1.9 1996/05/18 01:37:01 fritz
159 * Added spelling corrections and some minor changes
160 * to stay in sync with kernel.
162 * Revision 1.8 1996/05/06 11:34:55 hipp
165 * Revision 1.7 1996/04/30 11:07:42 fritz
166 * Added Michael's ippp-bind patch.
168 * Revision 1.6 1996/04/30 09:33:09 fritz
169 * Removed compatibility-macros.
171 * Revision 1.5 1996/04/20 16:32:32 fritz
172 * Changed ippp_table to an array of pointers, allocating each part
175 * Revision 1.4 1996/02/19 15:25:50 fritz
176 * Bugfix: Sync-PPP packets got compressed twice, when resent due to
177 * send-queue-full reject.
179 * Revision 1.3 1996/02/11 02:27:12 fritz
180 * Lot of Bugfixes my Michael.
181 * Moved calls to skb_push() into isdn_net_header()
182 * Fixed a possible race-condition in isdn_ppp_timer_timeout().
184 * Revision 1.2 1996/01/22 05:08:06 fritz
185 * Merged in Michael's patches for MP.
186 * Minor changes in isdn_ppp_xmit.
188 * Revision 1.1 1996/01/09 04:11:29 fritz
193 /* TODO: right tbusy handling when using MP */
196 * experimental for dynamic addressing: readdress IP frames
198 #undef ISDN_SYNCPPP_READDRESS
199 #define CONFIG_ISDN_CCP 1
201 #include <linux/config.h>
202 #define __NO_VERSION__
203 #include <linux/module.h>
204 #include <linux/version.h>
205 #include <linux/poll.h>
206 #include <linux/isdn.h>
207 #include <linux/ppp-comp.h>
209 #include "isdn_common.h"
210 #include "isdn_ppp.h"
211 #include "isdn_net.h"
214 #define PPP_IPX 0x002b
217 /* set this if you use dynamic addressing */
220 static int isdn_ppp_fill_rq(unsigned char *buf
, int len
, int proto
, int slot
);
221 static int isdn_ppp_closewait(int slot
);
222 static void isdn_ppp_push_higher(isdn_net_dev
* net_dev
, isdn_net_local
* lp
,
223 struct sk_buff
*skb
, int proto
);
224 static int isdn_ppp_if_get_unit(char *namebuf
);
225 static int isdn_ppp_set_compressor(struct ippp_struct
*is
,struct isdn_ppp_comp_data
*);
226 static struct sk_buff
*isdn_ppp_decompress(struct sk_buff
*,
227 struct ippp_struct
*,struct ippp_struct
*,int proto
);
228 static void isdn_ppp_receive_ccp(isdn_net_dev
* net_dev
, isdn_net_local
* lp
,
229 struct sk_buff
*skb
,int proto
);
230 static struct sk_buff
*isdn_ppp_compress(struct sk_buff
*skb_in
,int *proto
,
231 struct ippp_struct
*is
,struct ippp_struct
*master
,int type
);
232 static void isdn_ppp_send_ccp(isdn_net_dev
*net_dev
, isdn_net_local
*lp
,
233 struct sk_buff
*skb
);
236 static void isdn_ppp_ccp_kickup(struct ippp_struct
*is
);
237 static void isdn_ppp_ccp_xmit_reset(struct ippp_struct
*is
, int proto
,
238 unsigned char code
, unsigned char id
,
239 unsigned char *data
, int len
);
240 static struct ippp_ccp_reset
*isdn_ppp_ccp_reset_alloc(struct ippp_struct
*is
);
241 static void isdn_ppp_ccp_reset_free_state(struct ippp_struct
*is
,
243 static void isdn_ppp_ccp_timer_callback(unsigned long closure
);
244 static struct ippp_ccp_reset_state
*isdn_ppp_ccp_reset_alloc_state(struct ippp_struct
*is
,
246 static void isdn_ppp_ccp_reset_trans(struct ippp_struct
*is
,
247 struct isdn_ppp_resetparams
*rp
);
248 static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct
*is
,
253 #ifdef CONFIG_ISDN_MPP
254 static int isdn_ppp_bundle(struct ippp_struct
*, int unit
);
255 static void isdn_ppp_mask_queue(isdn_net_dev
* dev
, long mask
);
256 static void isdn_ppp_cleanup_mpqueue(isdn_net_dev
* dev
, long min
);
257 static void isdn_ppp_cleanup_sqqueue(isdn_net_dev
* dev
, isdn_net_local
*, long min
);
258 static void isdn_ppp_free_sqqueue(isdn_net_dev
*);
259 static int isdn_ppp_fill_mpqueue(isdn_net_dev
*, struct sk_buff
**skb
,
260 int BEbyte
, long *sqno
, int min_sqno
);
261 static void isdn_ppp_free_mpqueue(isdn_net_dev
*);
264 char *isdn_ppp_revision
= "$Revision: 1.47 $";
266 static struct ippp_struct
*ippp_table
[ISDN_MAX_CHANNELS
];
267 static struct isdn_ppp_compressor
*ipc_head
= NULL
;
273 isdn_ppp_frame_log(char *info
, char *data
, int len
, int maxlen
,int unit
,int slot
)
283 for (i
= 0, cnt
= 0; cnt
< maxlen
; i
++) {
284 for (j
= 0; j
< 16 && cnt
< maxlen
; j
++, cnt
++)
285 sprintf(buf
+ j
* 3, "%02x ", (unsigned char) data
[cnt
]);
286 printk(KERN_DEBUG
"[%d/%d].%s[%d]: %s\n",unit
,slot
, info
, i
, buf
);
291 * unbind isdn_net_local <=> ippp-device
292 * note: it can happen, that we hangup/free the master before the slaves
293 * in this case we bind another lp to the master device
296 isdn_ppp_free(isdn_net_local
* lp
)
298 #ifdef CONFIG_ISDN_MPP
299 isdn_net_local
*master_lp
= lp
;
302 struct ippp_struct
*is
;
304 if (lp
->ppp_slot
< 0 || lp
->ppp_slot
> ISDN_MAX_CHANNELS
)
307 is
= ippp_table
[lp
->ppp_slot
];
311 #ifdef CONFIG_ISDN_MPP
313 master_lp
= (isdn_net_local
*) lp
->master
->priv
;
315 lp
->last
->next
= lp
->next
;
316 lp
->next
->last
= lp
->last
;
317 if (master_lp
->netdev
->queue
== lp
) {
318 master_lp
->netdev
->queue
= lp
->next
;
319 if (lp
->next
== lp
) { /* last link in queue? */
320 master_lp
->netdev
->ib
.bundled
= 0;
321 isdn_ppp_free_mpqueue(master_lp
->netdev
);
322 isdn_ppp_free_sqqueue(master_lp
->netdev
);
325 lp
->next
= lp
->last
= lp
; /* (re)set own pointers */
328 if ((is
->state
& IPPP_CONNECT
))
329 isdn_ppp_closewait(lp
->ppp_slot
); /* force wakeup on ippp device */
330 else if (is
->state
& IPPP_ASSIGNED
)
331 is
->state
= IPPP_OPEN
; /* fallback to 'OPEN but not ASSIGNED' state */
334 printk(KERN_DEBUG
"isdn_ppp_free %d %lx %lx\n", lp
->ppp_slot
, (long) lp
, (long) is
->lp
);
336 is
->lp
= NULL
; /* link is down .. set lp to NULL */
337 #ifdef ISDN_SYNCPPP_READDRESS
338 is
->old_pa_addr
= 0x0;
339 is
->old_pa_dstaddr
= 0x0;
341 lp
->ppp_slot
= -1; /* is this OK ?? */
342 restore_flags(flags
);
348 * bind isdn_net_local <=> ippp-device
351 isdn_ppp_bind(isdn_net_local
* lp
)
356 struct ippp_struct
*is
;
358 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
)
364 if (lp
->pppbind
< 0) { /* device bounded to ippp device ? */
365 isdn_net_dev
*net_dev
= dev
->netdev
;
366 char exclusive
[ISDN_MAX_CHANNELS
]; /* exclusive flags */
367 memset(exclusive
, 0, ISDN_MAX_CHANNELS
);
368 while (net_dev
) { /* step through net devices to find exclusive minors */
369 isdn_net_local
*lp
= net_dev
->local
;
370 if (lp
->pppbind
>= 0)
371 exclusive
[lp
->pppbind
] = 1;
372 net_dev
= net_dev
->next
;
375 * search a free device / slot
377 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
378 if (ippp_table
[i
]->state
== IPPP_OPEN
&& !exclusive
[ippp_table
[i
]->minor
]) { /* OPEN, but not connected! */
383 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
384 if (ippp_table
[i
]->minor
== lp
->pppbind
&&
385 (ippp_table
[i
]->state
& IPPP_OPEN
) == IPPP_OPEN
)
390 if (i
>= ISDN_MAX_CHANNELS
) {
391 restore_flags(flags
);
392 printk(KERN_WARNING
"isdn_ppp_bind: Can't find a (free) connection to the ipppd daemon.\n");
395 unit
= isdn_ppp_if_get_unit(lp
->name
); /* get unit number from interface name .. ugly! */
397 printk(KERN_ERR
"isdn_ppp_bind: illegal interface name %s.\n", lp
->name
);
402 /* reset some values */
403 lp
->netdev
->ib
.bundled
= 0;
404 lp
->netdev
->ib
.next_num
= 0;
405 lp
->netdev
->ib
.modify
= 0;
406 lp
->netdev
->ib
.last
= NULL
;
407 lp
->netdev
->ib
.min
= 0;
408 lp
->netdev
->ib
.sq
= NULL
;
413 is
->state
= IPPP_OPEN
| IPPP_ASSIGNED
; /* assigned to a netdevice but not connected */
415 restore_flags(flags
);
421 * kick the ipppd on the device
422 * (wakes up daemon after B-channel connect)
426 isdn_ppp_wakeup_daemon(isdn_net_local
* lp
)
428 if (lp
->ppp_slot
< 0 || lp
->ppp_slot
>= ISDN_MAX_CHANNELS
)
431 ippp_table
[lp
->ppp_slot
]->state
= IPPP_OPEN
| IPPP_CONNECT
| IPPP_NOBLOCK
;
433 #if LINUX_VERSION_CODE < 131841
434 if (ippp_table
[lp
->ppp_slot
]->wq
)
436 wake_up_interruptible(&ippp_table
[lp
->ppp_slot
]->wq
);
440 * there was a hangup on the netdevice
441 * force wakeup of the ippp device
442 * go into 'device waits for release' state
445 isdn_ppp_closewait(int slot
)
447 struct ippp_struct
*is
;
449 if (slot
< 0 || slot
>= ISDN_MAX_CHANNELS
)
451 is
= ippp_table
[slot
];
453 #if LINUX_VERSION_CODE < 131841
454 if (is
->state
&& is
->wq
)
458 wake_up_interruptible(&is
->wq
);
460 is
->state
= IPPP_CLOSEWAIT
;
465 * isdn_ppp_find_slot / isdn_ppp_free_slot
469 isdn_ppp_get_slot(void)
472 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
473 if (!ippp_table
[i
]->state
)
484 isdn_ppp_open(int min
, struct file
*file
)
487 struct ippp_struct
*is
;
489 if (min
< 0 || min
> ISDN_MAX_CHANNELS
)
492 slot
= isdn_ppp_get_slot();
496 is
= file
->private_data
= ippp_table
[slot
];
501 printk(KERN_DEBUG
"ippp, open, slot: %d, minor: %d, state: %04x\n", slot
, min
, is
->state
);
503 /* compression stuff */
504 is
->link_compressor
= is
->compressor
= NULL
;
505 is
->link_decompressor
= is
->decompressor
= NULL
;
506 is
->link_comp_stat
= is
->comp_stat
= NULL
;
507 is
->link_decomp_stat
= is
->decomp_stat
= NULL
;
510 is
->reset
= isdn_ppp_ccp_reset_alloc(is
);
513 is
->mp_seqno
= 0; /* MP sequence number */
514 is
->pppcfg
= 0; /* ppp configuration */
515 is
->mpppcfg
= 0; /* mppp configuration */
516 is
->range
= 0x1000000; /* MP: 24 bit range */
517 is
->last_link_seqno
= -1; /* MP: maybe set to Bundle-MIN, when joining a bundle ?? */
518 is
->unit
= -1; /* set, when we have our interface */
519 is
->mru
= 1524; /* MRU, default 1524 */
520 is
->maxcid
= 16; /* VJ: maxcid */
522 #if LINUX_VERSION_CODE < 131841
523 is
->wq
= NULL
; /* read() wait queue */
525 init_waitqueue_head(&is
->wq
);
527 is
->first
= is
->rq
+ NUM_RCV_BUFFS
- 1; /* receive queue */
530 #ifdef CONFIG_ISDN_PPP_VJ
532 * VJ header compression init
534 is
->slcomp
= slhc_init(16, 16); /* not necessary for 2. link in bundle */
537 is
->state
= IPPP_OPEN
;
543 * release ippp device
546 isdn_ppp_release(int min
, struct file
*file
)
549 struct ippp_struct
*is
;
551 if (min
< 0 || min
>= ISDN_MAX_CHANNELS
)
553 is
= file
->private_data
;
556 printk(KERN_DEBUG
"ippp: release, minor: %d %lx\n", min
, (long) is
->lp
);
558 if (is
->lp
) { /* a lp address says: this link is still up */
559 isdn_net_dev
*p
= is
->lp
->netdev
;
561 is
->state
&= ~IPPP_CONNECT
; /* -> effect: no call of wakeup */
563 * isdn_net_hangup() calls isdn_ppp_free()
564 * isdn_ppp_free() sets is->lp to NULL and lp->ppp_slot to -1
565 * removing the IPPP_CONNECT flag omits calling of isdn_ppp_wakeup_daemon()
567 isdn_net_hangup(&p
->dev
);
569 for (i
= 0; i
< NUM_RCV_BUFFS
; i
++) {
571 kfree(is
->rq
[i
].buf
);
572 is
->rq
[i
].buf
= NULL
;
575 is
->first
= is
->rq
+ NUM_RCV_BUFFS
- 1; /* receive queue */
578 #ifdef CONFIG_ISDN_PPP_VJ
579 /* TODO: if this was the previous master: link the slcomp to the new master */
580 slhc_free(is
->slcomp
);
584 /* TODO: if this was the previous master: link the the stuff to the new master */
586 is
->compressor
->free(is
->comp_stat
);
587 if(is
->link_comp_stat
)
588 is
->link_compressor
->free(is
->link_comp_stat
);
589 if(is
->link_decomp_stat
)
590 is
->link_decompressor
->free(is
->link_decomp_stat
);
592 is
->decompressor
->free(is
->decomp_stat
);
593 is
->compressor
= is
->link_compressor
= NULL
;
594 is
->decompressor
= is
->link_decompressor
= NULL
;
595 is
->comp_stat
= is
->link_comp_stat
= NULL
;
596 is
->decomp_stat
= is
->link_decomp_stat
= NULL
;
602 /* this slot is ready for new connections */
607 * get_arg .. ioctl helper
610 get_arg(void *b
, void *val
, int len
)
613 len
= sizeof(void *);
614 if (copy_from_user((void *) val
, b
, len
))
620 * set arg .. ioctl helper
623 set_arg(void *b
, void *val
,int len
)
626 len
= sizeof(void *);
627 if (copy_to_user(b
, (void *) val
, len
))
636 isdn_ppp_ioctl(int min
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
640 struct ippp_struct
*is
;
642 struct isdn_ppp_comp_data data
;
644 is
= (struct ippp_struct
*) file
->private_data
;
648 printk(KERN_DEBUG
"isdn_ppp_ioctl: minor: %d cmd: %x state: %x\n", min
, cmd
, is
->state
);
650 if (!(is
->state
& IPPP_OPEN
))
655 #ifdef CONFIG_ISDN_MPP
656 if (!(is
->state
& IPPP_CONNECT
))
658 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) )))
660 printk(KERN_DEBUG
"iPPP-bundle: minor: %d, slave unit: %d, master unit: %d\n",
661 (int) min
, (int) is
->unit
, (int) val
);
662 return isdn_ppp_bundle(is
, val
);
667 case PPPIOCGUNIT
: /* get ppp/isdn unit number */
668 if ((r
= set_arg((void *) arg
, &is
->unit
, sizeof(is
->unit
) )))
674 if ((r
= set_arg((void *) arg
, lp
->name
,strlen(lp
->name
))))
677 case PPPIOCGMPFLAGS
: /* get configuration flags */
678 if ((r
= set_arg((void *) arg
, &is
->mpppcfg
, sizeof(is
->mpppcfg
) )))
681 case PPPIOCSMPFLAGS
: /* set configuration flags */
682 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) )))
686 case PPPIOCGFLAGS
: /* get configuration flags */
687 if ((r
= set_arg((void *) arg
, &is
->pppcfg
,sizeof(is
->pppcfg
) )))
690 case PPPIOCSFLAGS
: /* set configuration flags */
691 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) ))) {
694 if (val
& SC_ENABLE_IP
&& !(is
->pppcfg
& SC_ENABLE_IP
) && (is
->state
& IPPP_CONNECT
)) {
696 lp
->netdev
->dev
.tbusy
= 0;
697 mark_bh(NET_BH
); /* OK .. we are ready to send buffers */
703 case PPPIOCGSTAT
: /* read PPP statistic information */
706 case PPPIOCGIDLE
: /* get idle time information */
708 struct ppp_idle pidle
;
709 pidle
.xmit_idle
= pidle
.recv_idle
= lp
->huptimer
;
710 if ((r
= set_arg((void *) arg
, &pidle
,sizeof(struct ppp_idle
))))
714 case PPPIOCSMRU
: /* set receive unit size for PPP */
715 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) )))
723 case PPPIOCSMAXCID
: /* set the maximum compression slot id */
724 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) )))
727 if (is
->maxcid
!= val
) {
728 #ifdef CONFIG_ISDN_PPP_VJ
729 struct slcompress
*sltmp
;
732 printk(KERN_DEBUG
"ippp, ioctl: changed MAXCID to %ld\n", val
);
734 #ifdef CONFIG_ISDN_PPP_VJ
735 sltmp
= slhc_init(16, val
);
737 printk(KERN_ERR
"ippp, can't realloc slhc struct\n");
741 slhc_free(is
->slcomp
);
747 if ((r
= set_arg((void *) arg
, &is
->debug
, sizeof(is
->debug
) )))
751 if ((r
= get_arg((void *) arg
, &val
, sizeof(val
) )))
755 case PPPIOCGCOMPRESSORS
:
757 unsigned long protos
[8] = {0,};
758 struct isdn_ppp_compressor
*ipc
= ipc_head
;
760 j
= ipc
->num
/ (sizeof(long)*8);
761 i
= ipc
->num
% (sizeof(long)*8);
763 protos
[j
] |= (0x1<<i
);
766 if ((r
= set_arg((void *) arg
,protos
,8*sizeof(long) )))
770 case PPPIOCSCOMPRESSOR
:
771 if ((r
= get_arg((void *) arg
, &data
, sizeof(struct isdn_ppp_comp_data
))))
773 return isdn_ppp_set_compressor(is
, &data
);
774 case PPPIOCGCALLINFO
:
776 struct pppcallinfo pci
;
777 memset((char *) &pci
,0,sizeof(struct pppcallinfo
));
780 strncpy(pci
.local_num
,lp
->msn
,63);
782 strncpy(pci
.remote_num
,lp
->dial
->num
,63);
784 pci
.charge_units
= lp
->charge
;
786 pci
.calltype
= CALLTYPE_OUTGOING
;
788 pci
.calltype
= CALLTYPE_INCOMING
;
789 if(lp
->flags
& ISDN_NET_CALLBACK
)
790 pci
.calltype
|= CALLTYPE_CALLBACK
;
792 return set_arg((void *)arg
,&pci
,sizeof(struct pppcallinfo
));
801 isdn_ppp_poll(struct file
*file
, poll_table
* wait
)
804 struct ippp_buf_queue
*bf
;
805 struct ippp_buf_queue
*bl
;
807 struct ippp_struct
*is
;
809 is
= file
->private_data
;
812 printk(KERN_DEBUG
"isdn_ppp_poll: minor: %d\n",
813 MINOR(file
->f_dentry
->d_inode
->i_rdev
));
815 /* just registers wait_queue hook. This doesn't really wait. */
816 poll_wait(file
, &is
->wq
, wait
);
818 if (!(is
->state
& IPPP_OPEN
)) {
819 if(is
->state
== IPPP_CLOSEWAIT
)
821 printk(KERN_DEBUG
"isdn_ppp: device not open\n");
824 /* we're always ready to send .. */
825 mask
= POLLOUT
| POLLWRNORM
;
832 * if IPPP_NOBLOCK is set we return even if we have nothing to read
834 if (bf
->next
!= bl
|| (is
->state
& IPPP_NOBLOCK
)) {
835 is
->state
&= ~IPPP_NOBLOCK
;
836 mask
|= POLLIN
| POLLRDNORM
;
838 restore_flags(flags
);
843 * fill up isdn_ppp_read() queue ..
847 isdn_ppp_fill_rq(unsigned char *buf
, int len
, int proto
, int slot
)
849 struct ippp_buf_queue
*bf
,
853 struct ippp_struct
*is
;
855 if (slot
< 0 || slot
>= ISDN_MAX_CHANNELS
) {
856 printk(KERN_WARNING
"ippp: illegal slot.\n");
859 is
= ippp_table
[slot
];
861 if (!(is
->state
& IPPP_CONNECT
)) {
862 printk(KERN_DEBUG
"ippp: device not activated.\n");
865 nbuf
= (unsigned char *) kmalloc(len
+ 4, GFP_ATOMIC
);
867 printk(KERN_WARNING
"ippp: Can't alloc buf\n");
870 nbuf
[0] = PPP_ALLSTATIONS
;
872 nbuf
[2] = proto
>> 8;
873 nbuf
[3] = proto
& 0xff;
874 memcpy(nbuf
+ 4, buf
, len
);
883 printk(KERN_WARNING
"ippp: Queue is full; discarding first buffer\n");
888 bl
->buf
= (char *) nbuf
;
892 restore_flags(flags
);
894 #if LINUX_VERSION_CODE < 131841
897 wake_up_interruptible(&is
->wq
);
903 * read() .. non-blocking: ipppd calls it only after select()
904 * reports, that there is data
908 isdn_ppp_read(int min
, struct file
*file
, char *buf
, int count
)
910 struct ippp_struct
*is
;
911 struct ippp_buf_queue
*b
;
914 unsigned char *save_buf
;
916 is
= file
->private_data
;
918 if (!(is
->state
& IPPP_OPEN
))
921 if ((r
= verify_area(VERIFY_WRITE
, (void *) buf
, count
)))
930 restore_flags(flags
);
938 restore_flags(flags
);
940 copy_to_user(buf
, save_buf
, count
);
947 * ipppd wanna write a packet to the card .. non-blocking
951 isdn_ppp_write(int min
, struct file
*file
, const char *buf
, int count
)
954 struct ippp_struct
*is
;
956 unsigned char protobuf
[4];
958 is
= file
->private_data
;
960 if (!(is
->state
& IPPP_CONNECT
))
965 /* -> push it directly to the lowlevel interface */
968 printk(KERN_DEBUG
"isdn_ppp_write: lp == NULL\n");
971 * Don't reset huptimer for
972 * LCP packets. (Echo requests).
974 if (copy_from_user(protobuf
, buf
, 4))
976 proto
= PPP_PROTOCOL(protobuf
);
977 if (proto
!= PPP_LCP
)
980 if (lp
->isdn_device
< 0 || lp
->isdn_channel
< 0)
983 if ((dev
->drv
[lp
->isdn_device
]->flags
& DRV_FLAG_RUNNING
) &&
984 lp
->dialstate
== 0 &&
985 (lp
->flags
& ISDN_NET_CONNECTED
)) {
988 skb
= dev_alloc_skb(count
);
990 printk(KERN_WARNING
"isdn_ppp_write: out of memory!\n");
993 if (copy_from_user(skb_put(skb
, count
), buf
, count
))
995 if (is
->debug
& 0x40) {
996 printk(KERN_DEBUG
"ppp xmit: len %d\n", (int) skb
->len
);
997 isdn_ppp_frame_log("xmit", skb
->data
, skb
->len
, 32,is
->unit
,lp
->ppp_slot
);
1000 isdn_ppp_send_ccp(lp
->netdev
,lp
,skb
); /* keeps CCP/compression states in sync */
1002 if ((cnt
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
, 1, skb
)) != count
) {
1004 dev_kfree_skb(lp
->sav_skb
);
1005 printk(KERN_INFO
"isdn_ppp_write: freeing sav_skb (%d,%d)!\n", cnt
, count
);
1007 printk(KERN_INFO
"isdn_ppp_write: Can't write PPP frame to LL (%d,%d)!\n", cnt
, count
);
1016 * init memory, structures etc.
1025 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1026 if (!(ippp_table
[i
] = (struct ippp_struct
*)
1027 kmalloc(sizeof(struct ippp_struct
), GFP_KERNEL
))) {
1028 printk(KERN_WARNING
"isdn_ppp_init: Could not alloc ippp_table\n");
1029 for (j
= 0; j
< i
; j
++)
1030 kfree(ippp_table
[i
]);
1033 memset((char *) ippp_table
[i
], 0, sizeof(struct ippp_struct
));
1034 ippp_table
[i
]->state
= 0;
1035 ippp_table
[i
]->first
= ippp_table
[i
]->rq
+ NUM_RCV_BUFFS
- 1;
1036 ippp_table
[i
]->last
= ippp_table
[i
]->rq
;
1038 for (j
= 0; j
< NUM_RCV_BUFFS
; j
++) {
1039 ippp_table
[i
]->rq
[j
].buf
= NULL
;
1040 ippp_table
[i
]->rq
[j
].last
= ippp_table
[i
]->rq
+
1041 (NUM_RCV_BUFFS
+ j
- 1) % NUM_RCV_BUFFS
;
1042 ippp_table
[i
]->rq
[j
].next
= ippp_table
[i
]->rq
+ (j
+ 1) % NUM_RCV_BUFFS
;
1049 isdn_ppp_cleanup(void)
1053 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
1054 kfree(ippp_table
[i
]);
1058 * get the PPP protocol header and pull skb
1060 static int isdn_ppp_strip_proto(struct sk_buff
*skb
)
1063 if (skb
->data
[0] & 0x1) {
1064 proto
= skb
->data
[0];
1065 skb_pull(skb
, 1); /* protocol ID is only 8 bit */
1067 proto
= ((int) skb
->data
[0] << 8) + skb
->data
[1];
1075 * handler for incoming packets on a syncPPP interface
1077 void isdn_ppp_receive(isdn_net_dev
* net_dev
, isdn_net_local
* lp
, struct sk_buff
*skb
)
1079 struct ippp_struct
*is
;
1082 is
= ippp_table
[lp
->ppp_slot
];
1084 if (is
->debug
& 0x4) {
1085 printk(KERN_DEBUG
"ippp_receive: is:%08lx lp:%08lx slot:%d unit:%d len:%d\n",
1086 (long)is
,(long)lp
,lp
->ppp_slot
,is
->unit
,(int) skb
->len
);
1087 isdn_ppp_frame_log("receive", skb
->data
, skb
->len
, 32,is
->unit
,lp
->ppp_slot
);
1089 if (net_dev
->local
->master
) {
1090 printk(KERN_WARNING
"isdn_ppp_receice: net_dev != master\n");
1091 net_dev
= ((isdn_net_local
*) net_dev
->local
->master
->priv
)->netdev
;
1093 if (skb
->data
[0] == 0xff && skb
->data
[1] == 0x03)
1095 else if (is
->pppcfg
& SC_REJ_COMP_AC
) {
1097 return; /* discard it silently */
1100 proto
= isdn_ppp_strip_proto(skb
);
1102 #ifdef CONFIG_ISDN_MPP
1103 if (!(is
->mpppcfg
& SC_REJ_MP_PROT
)) {
1106 if(is
->compflags
& SC_LINK_DECOMP_ON
) {
1107 if(proto
== PPP_LINK_COMP
) {
1108 if(is
->debug
& 0x10)
1109 printk(KERN_DEBUG
"received single link compressed frame\n");
1110 skb
= isdn_ppp_decompress(skb
,is
,NULL
,proto
);
1113 proto
= isdn_ppp_strip_proto(skb
);
1116 isdn_ppp_decompress(skb
,is
,NULL
,proto
);
1119 if (proto
== PPP_MP
) {
1120 isdn_net_local
*lpq
;
1121 long sqno
, min_sqno
, tseq
;
1123 u_char BEbyte
= skb
->data
[0];
1124 if (is
->debug
& 0x8)
1125 printk(KERN_DEBUG
"recv: %d/%04x/%d -> %02x %02x %02x %02x %02x %02x\n", lp
->ppp_slot
, proto
,
1126 (int) skb
->len
, (int) skb
->data
[0], (int) skb
->data
[1], (int) skb
->data
[2],
1127 (int) skb
->data
[3], (int) skb
->data
[4], (int) skb
->data
[5]);
1128 if (!(is
->mpppcfg
& SC_IN_SHORT_SEQ
)) {
1129 sqno
= ((int) skb
->data
[1] << 16) + ((int) skb
->data
[2] << 8) + (int) skb
->data
[3];
1132 sqno
= (((int) skb
->data
[0] & 0xf) << 8) + (int) skb
->data
[1];
1137 * new sequence number lower than last number? (this is only allowed
1138 * for overflow case)
1140 if ((tseq
= is
->last_link_seqno
) >= sqno
) {
1141 int range
= is
->range
;
1142 if (tseq
+ 1024 < range
+ sqno
) /* redundancy check .. not MP conform */
1143 printk(KERN_WARNING
"isdn_ppp_receive, MP, detected overflow with sqno: %ld, last: %ld !!!\n", sqno
, tseq
);
1146 is
->last_link_seqno
= sqno
;
1149 /* here, we should also add an redundancy check */
1150 is
->last_link_seqno
= sqno
;
1154 * step over all links to find lowest link number
1156 for (min_sqno
= LONG_MAX
, lpq
= net_dev
->queue
;;) {
1157 long lls
= ippp_table
[lpq
->ppp_slot
]->last_link_seqno
;
1158 if (lls
>= 0 && lls
< min_sqno
)
1161 if (lpq
== net_dev
->queue
)
1166 * for the case, that the last frame numbers of all
1167 * links are overflowed: mask/reduce the sequenece number to
1168 * 'normal' numbering.
1170 if (min_sqno
>= ippp_table
[lpq
->ppp_slot
]->range
) {
1171 int mask
= ippp_table
[lpq
->ppp_slot
]->range
-1; /* range is power of two, so a mask will do the job */
1172 isdn_ppp_mask_queue(net_dev
, mask
);
1173 net_dev
->ib
.next_num
&= mask
;
1175 struct sqqueue
*q
= net_dev
->ib
.sq
;
1177 q
->sqno_start
&= mask
;
1178 q
->sqno_end
&= mask
;
1182 for (lpq
= net_dev
->queue
;;) {
1183 if(ippp_table
[lpq
->ppp_slot
]->last_link_seqno
>= 0)
1184 ippp_table
[lpq
->ppp_slot
]->last_link_seqno
&= mask
;
1186 if (lpq
== net_dev
->queue
)
1190 if ((BEbyte
& (MP_BEGIN_FRAG
| MP_END_FRAG
)) != (MP_BEGIN_FRAG
| MP_END_FRAG
)) {
1191 static int dmes
= 0;
1193 printk(KERN_DEBUG
"ippp: trying ;) to fill mp_queue %d .. UNTESTED!!\n", lp
->ppp_slot
);
1196 if ((sqno_end
= isdn_ppp_fill_mpqueue(net_dev
, &skb
, BEbyte
, &sqno
, min_sqno
)) < 0) {
1197 net_dev
->ib
.modify
= 1; /* block timeout-timer */
1198 isdn_ppp_cleanup_sqqueue(net_dev
, lp
, min_sqno
);
1199 net_dev
->ib
.modify
= 0;
1200 return; /* no packet complete */
1205 if (is
->debug
& 0x40)
1206 printk(KERN_DEBUG
"min_sqno: %ld sqno_end %d next: %ld\n", min_sqno
, sqno_end
, net_dev
->ib
.next_num
);
1209 * MP buffer management .. reorders incoming packets ..
1210 * lotsa mem-copies and not heavily tested.
1212 * first check whether there is more than one link in the bundle
1213 * then check whether the number is in order
1215 net_dev
->ib
.modify
= 1; /* block timeout-timer */
1216 if (net_dev
->ib
.bundled
&& net_dev
->ib
.next_num
!= sqno
) {
1218 * packet is not 'in order'
1222 q
= (struct sqqueue
*) kmalloc(sizeof(struct sqqueue
), GFP_ATOMIC
);
1224 net_dev
->ib
.modify
= 0;
1225 printk(KERN_WARNING
"ippp/MPPP: Bad! Can't alloc sq node!\n");
1227 return; /* discard */
1230 q
->sqno_end
= sqno_end
;
1231 q
->sqno_start
= sqno
;
1232 q
->timer
= jiffies
+ (ISDN_TIMER_1SEC
) * 5; /* timeout after 5 seconds */
1234 if (!net_dev
->ib
.sq
) {
1238 struct sqqueue
*ql
= net_dev
->ib
.sq
;
1239 if (ql
->sqno_start
> q
->sqno_start
) {
1243 while (ql
->next
&& ql
->next
->sqno_start
< q
->sqno_start
)
1251 * packet was 'in order' .. push it higher
1253 net_dev
->ib
.next_num
= sqno_end
+ 1;
1254 proto
= isdn_ppp_strip_proto(skb
);
1255 isdn_ppp_push_higher(net_dev
, lp
, skb
, proto
);
1257 isdn_ppp_cleanup_sqqueue(net_dev
, lp
, min_sqno
);
1258 net_dev
->ib
.modify
= 0;
1261 isdn_ppp_push_higher(net_dev
, lp
, skb
, proto
);
1264 isdn_ppp_push_higher(net_dev
, lp
, skb
, proto
);
1268 * push frame to higher layers
1269 * note: net_dev has to be master net_dev
1272 isdn_ppp_push_higher(isdn_net_dev
* net_dev
, isdn_net_local
* lp
, struct sk_buff
*skb
, int proto
)
1274 struct device
*dev
= &net_dev
->dev
;
1275 struct ippp_struct
*is
= ippp_table
[lp
->ppp_slot
];
1277 if (is
->debug
& 0x10) {
1278 printk(KERN_DEBUG
"push, skb %d %04x\n", (int) skb
->len
, proto
);
1279 isdn_ppp_frame_log("rpush", skb
->data
, skb
->len
, 32,is
->unit
,lp
->ppp_slot
);
1282 if(proto
== PPP_COMP
) {
1284 skb
= isdn_ppp_decompress(skb
,is
,is
,proto
);
1286 skb
= isdn_ppp_decompress(skb
,is
,ippp_table
[((isdn_net_local
*) (lp
->master
->priv
))->ppp_slot
],proto
);
1289 printk(KERN_DEBUG
"ippp: compressed frame discarded!\n");
1293 proto
= isdn_ppp_strip_proto(skb
);
1294 if (is
->debug
& 0x10) {
1295 printk(KERN_DEBUG
"RPostDecomp, skb %d %04x\n", (int) skb
->len
, proto
);
1296 isdn_ppp_frame_log("R-Decomp", skb
->data
, skb
->len
, 32,is
->unit
,lp
->ppp_slot
);
1299 else if(is
->compflags
& SC_DECOMP_ON
) { /* If decomp is ON */
1301 isdn_ppp_decompress(skb
,is
,is
,proto
);
1303 isdn_ppp_decompress(skb
,is
,ippp_table
[((isdn_net_local
*) (lp
->master
->priv
))->ppp_slot
],proto
);
1307 case PPP_IPX
: /* untested */
1308 if (is
->debug
& 0x20)
1309 printk(KERN_DEBUG
"isdn_ppp: IPX\n");
1311 skb
->mac
.raw
= skb
->data
;
1312 skb
->protocol
= htons(ETH_P_IPX
);
1314 #ifdef CONFIG_ISDN_PPP_VJ
1315 case PPP_VJC_UNCOMP
:
1316 if (is
->debug
& 0x20)
1317 printk(KERN_DEBUG
"isdn_ppp: VJC_UNCOMP\n");
1318 if (slhc_remember(ippp_table
[net_dev
->local
->ppp_slot
]->slcomp
, skb
->data
, skb
->len
) <= 0) {
1319 printk(KERN_WARNING
"isdn_ppp: received illegal VJC_UNCOMP frame!\n");
1320 net_dev
->local
->stats
.rx_dropped
++;
1326 if (is
->debug
& 0x20)
1327 printk(KERN_DEBUG
"isdn_ppp: IP\n");
1329 skb
->mac
.raw
= skb
->data
;
1330 skb
->protocol
= htons(ETH_P_IP
);
1333 if (is
->debug
& 0x20)
1334 printk(KERN_DEBUG
"isdn_ppp: VJC_COMP\n");
1335 #ifdef CONFIG_ISDN_PPP_VJ
1337 struct sk_buff
*skb_old
= skb
;
1339 skb
= dev_alloc_skb(skb_old
->len
+ 40);
1342 printk(KERN_WARNING
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1343 net_dev
->local
->stats
.rx_dropped
++;
1344 dev_kfree_skb(skb_old
);
1348 skb_put(skb
, skb_old
->len
+ 40);
1349 memcpy(skb
->data
, skb_old
->data
, skb_old
->len
);
1350 skb
->mac
.raw
= skb
->data
;
1351 pkt_len
= slhc_uncompress(ippp_table
[net_dev
->local
->ppp_slot
]->slcomp
,
1352 skb
->data
, skb_old
->len
);
1353 dev_kfree_skb(skb_old
);
1356 lp
->stats
.rx_dropped
++;
1359 skb_trim(skb
, pkt_len
);
1360 skb
->protocol
= htons(ETH_P_IP
);
1363 printk(KERN_INFO
"isdn: Ooopsa .. VJ-Compression support not compiled into isdn driver.\n");
1364 lp
->stats
.rx_dropped
++;
1371 isdn_ppp_receive_ccp(net_dev
,lp
,skb
,proto
);
1372 /* Dont pop up ResetReq/Ack stuff to the daemon any
1373 longer - the job is done already */
1374 if(skb
->data
[0] == CCP_RESETREQ
||
1375 skb
->data
[0] == CCP_RESETACK
)
1379 isdn_ppp_fill_rq(skb
->data
, skb
->len
, proto
, lp
->ppp_slot
); /* push data to pppd device */
1384 /* Reset hangup-timer */
1387 /* net_dev->local->stats.rx_packets++; *//* done in isdn_net.c */
1393 * isdn_ppp_skb_push ..
1394 * checks whether we have enough space at the beginning of the SKB
1395 * and allocs a new SKB if necessary
1397 static unsigned char *isdn_ppp_skb_push(struct sk_buff
**skb_p
,int len
)
1399 struct sk_buff
*skb
= *skb_p
;
1401 if(skb_headroom(skb
) < len
) {
1402 printk(KERN_ERR
"isdn_ppp_skb_push:under %d %d\n",skb_headroom(skb
),len
);
1406 return skb_push(skb
,len
);
1411 * send ppp frame .. we expect a PIDCOMPressable proto --
1412 * (here: currently always PPP_IP,PPP_VJC_COMP,PPP_VJC_UNCOMP)
1414 * VJ compression may change skb pointer!!! .. requeue with old
1415 * skb isn't allowed!!
1419 isdn_ppp_xmit(struct sk_buff
*skb
, struct device
*dev
)
1421 struct device
*mdev
= ((isdn_net_local
*) (dev
->priv
))->master
; /* get master (for redundancy) */
1422 isdn_net_local
*lp
,*mlp
;
1424 unsigned int proto
= PPP_IP
; /* 0x21 */
1425 struct ippp_struct
*ipt
,*ipts
;
1428 mlp
= (isdn_net_local
*) (mdev
->priv
);
1431 mlp
= (isdn_net_local
*) (dev
->priv
);
1433 nd
= mlp
->netdev
; /* get master lp */
1434 ipts
= ippp_table
[mlp
->ppp_slot
];
1436 if (!(ipts
->pppcfg
& SC_ENABLE_IP
)) { /* PPP connected ? */
1437 #ifdef ISDN_SYNCPPP_READDRESS
1438 if (!ipts
->old_pa_addr
)
1439 ipts
->old_pa_addr
= mdev
->pa_addr
;
1440 if (!ipts
->old_pa_dstaddr
)
1441 ipts
->old_pa_dstaddr
= mdev
->pa_dstaddr
;
1443 if (ipts
->debug
& 0x1)
1444 printk(KERN_INFO
"%s: IP frame delayed.\n", dev
->name
);
1448 switch (ntohs(skb
->protocol
)) {
1451 #ifdef ISDN_SYNCPPP_READDRESS
1452 if (ipts
->old_pa_addr
!= mdev
->pa_addr
) {
1454 ipfr
= (struct iphdr
*) skb
->data
;
1455 if(ipts
->debug
& 0x4)
1456 printk(KERN_DEBUG
"IF-address changed from %lx to %lx\n", ipts
->old_pa_addr
, mdev
->pa_addr
);
1457 if (ipfr
->version
== 4) {
1458 if (ipfr
->saddr
== ipts
->old_pa_addr
) {
1459 printk(KERN_DEBUG
"readdressing %lx to %lx\n", ipfr
->saddr
, mdev
->pa_addr
);
1460 ipfr
->saddr
= mdev
->pa_addr
;
1464 /* dstaddr change not so important */
1468 proto
= PPP_IPX
; /* untested */
1472 printk(KERN_ERR
"isdn_ppp: skipped frame with unsupported protocoll: %#x.\n", skb
->protocol
);
1476 lp
= nd
->queue
; /* get lp on top of queue */
1478 if (lp
->sav_skb
) { /* find a non-busy device */
1479 isdn_net_local
*nlp
= lp
->next
;
1480 while (lp
->sav_skb
) {
1483 nlp
= nd
->queue
= nd
->queue
->next
;
1487 ipt
= ippp_table
[lp
->ppp_slot
];
1491 * after this line .. requeueing in the device queue is no longer allowed!!!
1494 /* Pull off the fake header we stuck on earlier to keep
1495 * the fragemntation code happy.
1496 * this will break the ISDN_SYNCPPP_READDRESS hack a few lines
1497 * above. So, enabling this is no longer allowed
1499 skb_pull(skb
,IPPP_MAX_HEADER
);
1501 if (ipt
->debug
& 0x4)
1502 printk(KERN_DEBUG
"xmit skb, len %d\n", (int) skb
->len
);
1503 if (ipts
->debug
& 0x40)
1504 isdn_ppp_frame_log("xmit0", skb
->data
, skb
->len
, 32,ipts
->unit
,lp
->ppp_slot
);
1506 #ifdef CONFIG_ISDN_PPP_VJ
1507 if (proto
== PPP_IP
&& ipts
->pppcfg
& SC_COMP_TCP
) { /* ipts here? probably yes, but check this again */
1508 struct sk_buff
*new_skb
;
1510 new_skb
= dev_alloc_skb(skb
->len
);
1515 new_skb
->dev
= skb
->dev
;
1516 skb_put(new_skb
, skb
->len
);
1519 pktlen
= slhc_compress(ipts
->slcomp
, skb
->data
, skb
->len
, new_skb
->data
,
1520 &buf
, !(ipts
->pppcfg
& SC_NO_TCP_CCID
));
1522 if (buf
!= skb
->data
) {
1523 if (new_skb
->data
!= buf
)
1524 printk(KERN_ERR
"isdn_ppp: FATAL error after slhc_compress!!\n");
1528 dev_kfree_skb(new_skb
);
1531 skb_trim(skb
, pktlen
);
1532 if (skb
->data
[0] & SL_TYPE_COMPRESSED_TCP
) { /* cslip? style -> PPP */
1533 proto
= PPP_VJC_COMP
;
1534 skb
->data
[0] ^= SL_TYPE_COMPRESSED_TCP
;
1536 if (skb
->data
[0] >= SL_TYPE_UNCOMPRESSED_TCP
)
1537 proto
= PPP_VJC_UNCOMP
;
1538 skb
->data
[0] = (skb
->data
[0] & 0x0f) | 0x40;
1545 * normal (single link) or bundle compression
1547 if(ipts
->compflags
& SC_COMP_ON
)
1548 skb
= isdn_ppp_compress(skb
,&proto
,ipt
,ipts
,0);
1550 if (ipt
->debug
& 0x24)
1551 printk(KERN_DEBUG
"xmit2 skb, len %d, proto %04x\n", (int) skb
->len
, proto
);
1553 #ifdef CONFIG_ISDN_MPP
1554 if (ipt
->mpppcfg
& SC_MP_PROT
) {
1555 /* we get mp_seqno from static isdn_net_local */
1556 long mp_seqno
= ipts
->mp_seqno
;
1558 nd
->queue
= nd
->queue
->next
;
1559 if (ipt
->mpppcfg
& SC_OUT_SHORT_SEQ
) {
1560 unsigned char *data
= isdn_ppp_skb_push(&skb
, 3);
1564 data
[0] = MP_BEGIN_FRAG
| MP_END_FRAG
| ((mp_seqno
>> 8) & 0xf); /* (B)egin & (E)ndbit .. */
1565 data
[1] = mp_seqno
& 0xff;
1566 data
[2] = proto
; /* PID compression */
1568 unsigned char *data
= isdn_ppp_skb_push(&skb
, 5);
1571 data
[0] = MP_BEGIN_FRAG
| MP_END_FRAG
; /* (B)egin & (E)ndbit .. */
1572 data
[1] = (mp_seqno
>> 16) & 0xff; /* sequence number: 24bit */
1573 data
[2] = (mp_seqno
>> 8) & 0xff;
1574 data
[3] = (mp_seqno
>> 0) & 0xff;
1575 data
[4] = proto
; /* PID compression */
1577 proto
= PPP_MP
; /* MP Protocol, 0x003d */
1582 * 'link in bundle' compression ...
1584 if(ipt
->compflags
& SC_LINK_COMP_ON
)
1585 skb
= isdn_ppp_compress(skb
,&proto
,ipt
,ipts
,1);
1587 if( (ipt
->pppcfg
& SC_COMP_PROT
) && (proto
<= 0xff) ) {
1588 unsigned char *data
= isdn_ppp_skb_push(&skb
,1);
1591 data
[0] = proto
& 0xff;
1594 unsigned char *data
= isdn_ppp_skb_push(&skb
,2);
1597 data
[0] = (proto
>> 8) & 0xff;
1598 data
[1] = proto
& 0xff;
1600 if(!(ipt
->pppcfg
& SC_COMP_AC
)) {
1601 unsigned char *data
= isdn_ppp_skb_push(&skb
,2);
1604 data
[0] = 0xff; /* All Stations */
1605 data
[1] = 0x03; /* Unnumbered information */
1608 /* tx-stats are now updated via BSENT-callback */
1610 if (ipts
->debug
& 0x40) {
1611 printk(KERN_DEBUG
"skb xmit: len: %d\n", (int) skb
->len
);
1612 isdn_ppp_frame_log("xmit", skb
->data
, skb
->len
, 32,ipt
->unit
,lp
->ppp_slot
);
1614 if (isdn_net_send_skb(dev
, lp
, skb
)) {
1615 if (lp
->sav_skb
) { /* whole sav_skb processing with disabled IRQs ?? */
1616 printk(KERN_ERR
"%s: whoops .. there is another stored skb!\n", dev
->name
);
1624 #ifdef CONFIG_ISDN_MPP
1629 * Note: We need two queues for MPPP. The SQ queue holds fully (re)assembled frames,
1630 * that can't be delivered, because there is an outstanding earlier frame
1633 isdn_ppp_free_sqqueue(isdn_net_dev
* p
)
1635 struct sqqueue
*q
= p
->ib
.sq
;
1639 struct sqqueue
*qn
= q
->next
;
1641 dev_kfree_skb(q
->skb
);
1651 * Note: The MP queue holds all frame fragments of frames, that can't be
1652 * reassembled, because there is at least one missing fragment.
1655 isdn_ppp_free_mpqueue(isdn_net_dev
* p
)
1657 struct mpqueue
*q
= p
->mp_last
;
1661 struct mpqueue
*ql
= q
->next
;
1662 dev_kfree_skb(q
->skb
);
1669 isdn_ppp_bundle(struct ippp_struct
*is
, int unit
)
1671 char ifn
[IFNAMSIZ
+ 1];
1677 sprintf(ifn
, "ippp%d", unit
);
1678 p
= isdn_net_findif(ifn
);
1682 isdn_timer_ctrl(ISDN_TIMER_IPPP
, 1); /* enable timer for ippp/MP */
1691 nlp
->last
= lp
->last
;
1692 lp
->last
->next
= nlp
;
1697 ippp_table
[nlp
->ppp_slot
]->unit
= ippp_table
[lp
->ppp_slot
]->unit
;
1698 /* maybe also SC_CCP stuff */
1699 ippp_table
[nlp
->ppp_slot
]->pppcfg
|= ippp_table
[lp
->ppp_slot
]->pppcfg
&
1700 (SC_ENABLE_IP
| SC_NO_TCP_CCID
| SC_REJ_COMP_TCP
);
1702 ippp_table
[nlp
->ppp_slot
]->mpppcfg
|= ippp_table
[lp
->ppp_slot
]->mpppcfg
&
1703 (SC_MP_PROT
| SC_REJ_MP_PROT
| SC_OUT_SHORT_SEQ
| SC_IN_SHORT_SEQ
);
1705 if (ippp_table
[nlp
->ppp_slot
]->mpppcfg
!= ippp_table
[lp
->ppp_slot
]->mpppcfg
) {
1706 printk(KERN_WARNING
"isdn_ppp_bundle: different MP options %04x and %04x\n",
1707 ippp_table
[nlp
->ppp_slot
]->mpppcfg
, ippp_table
[lp
->ppp_slot
]->mpppcfg
);
1711 restore_flags(flags
);
1716 * Mask sequence numbers in MP queue
1719 isdn_ppp_mask_queue(isdn_net_dev
* dev
, long mask
)
1721 struct mpqueue
*q
= dev
->mp_last
;
1729 * put a fragment at the right place into the MP queue
1730 * Also checks, whether this fragment completes a frame. In this case
1731 * the fragments are copied together into one SKB
1734 isdn_ppp_fill_mpqueue(isdn_net_dev
* dev
, struct sk_buff
**skb
, int BEbyte
, long *sqnop
, int min_sqno
)
1745 q1
= (struct mpqueue
*) kmalloc(sizeof(struct mpqueue
), GFP_ATOMIC
);
1747 printk(KERN_WARNING
"isdn_ppp_fill_mpqueue: Can't alloc struct memory.\n");
1750 isdn_ppp_cleanup_mpqueue(dev
, min_sqno
);
1751 restore_flags(flags
);
1756 q1
->BEbyte
= BEbyte
;
1762 if (!(q
= dev
->mp_last
)) {
1766 isdn_ppp_cleanup_mpqueue(dev
, min_sqno
); /* not necessary */
1767 restore_flags(flags
);
1768 return -1; /* -1 is not an error. Just says, that this fragment hasn't complete a full frame */
1770 for (;;) { /* the faster way would be to step from the queue-end to the start */
1771 if (sqno
> q
->sqno
) {
1781 if (sqno
== q
->sqno
)
1782 printk(KERN_WARNING
"isdn_fill_mpqueue: illegal sqno received!!\n");
1793 /* now we check whether we completed a packet with this fragment */
1794 pktlen
= -q1
->skb
->len
;
1797 while (!(q
->BEbyte
& MP_END_FRAG
)) {
1799 if (!(q
->next
) || q
->next
->sqno
!= cnt
) {
1800 isdn_ppp_cleanup_mpqueue(dev
, min_sqno
);
1801 restore_flags(flags
);
1804 pktlen
+= q
->skb
->len
;
1807 pktlen
+= q
->skb
->len
;
1812 while (!(q
->BEbyte
& MP_BEGIN_FRAG
)) {
1814 if (!(q
->last
) || q
->last
->sqno
!= cnt
) {
1815 isdn_ppp_cleanup_mpqueue(dev
, min_sqno
);
1816 restore_flags(flags
);
1819 pktlen
+= q
->skb
->len
;
1822 pktlen
+= q
->skb
->len
;
1825 q
->last
->next
= qe
->next
;
1827 dev
->mp_last
= qe
->next
;
1830 qe
->next
->last
= q
->last
;
1832 sqno_end
= qe
->sqno
;
1835 isdn_ppp_cleanup_mpqueue(dev
, min_sqno
);
1836 restore_flags(flags
);
1838 *skb
= dev_alloc_skb(pktlen
+ 40); /* not needed: +40 for VJ compression .. */
1842 struct mpqueue
*ql
= q
->next
;
1843 dev_kfree_skb(q
->skb
);
1850 skb_put(*skb
, pktlen
);
1852 struct mpqueue
*ql
= q
->next
;
1853 memcpy((*skb
)->data
+ cnt
, q
->skb
->data
, q
->skb
->len
);
1855 dev_kfree_skb(q
->skb
);
1864 * check sq-queue, whether we have still buffered the next packet(s)
1865 * or packets with a sqno less or equal to min_sqno
1866 * net_dev: master netdevice , lp: 'real' local connection
1869 isdn_ppp_cleanup_sqqueue(isdn_net_dev
* net_dev
, isdn_net_local
* lp
, long min_sqno
)
1873 while ((q
= net_dev
->ib
.sq
) && (q
->sqno_start
== net_dev
->ib
.next_num
|| q
->sqno_end
<= min_sqno
)) {
1875 if (q
->sqno_start
!= net_dev
->ib
.next_num
) {
1876 printk(KERN_DEBUG
"ippp: MP, stepping over missing frame: %ld\n", net_dev
->ib
.next_num
);
1877 #ifdef CONFIG_ISDN_PPP_VJ
1878 slhc_toss(ippp_table
[net_dev
->local
->ppp_slot
]->slcomp
);
1881 proto
= isdn_ppp_strip_proto(q
->skb
);
1882 isdn_ppp_push_higher(net_dev
, lp
, q
->skb
, proto
);
1883 net_dev
->ib
.sq
= q
->next
;
1884 net_dev
->ib
.next_num
= q
->sqno_end
+ 1;
1890 * remove stale packets from list
1893 isdn_ppp_cleanup_mpqueue(isdn_net_dev
* dev
, long min_sqno
)
1895 #ifdef CONFIG_ISDN_PPP_VJ
1898 /* z.z einfaches aussortieren gammeliger pakete. Fuer die Zukunft:
1899 eventuell, solange vorne kein B-paket ist und sqno<=min_sqno: auch rauswerfen
1900 wenn sqno<min_sqno und Luecken vorhanden sind: auch weg (die koennen nicht mehr gefuellt werden)
1901 bei paketen groesser min_sqno: ueber mp_mrru: wenn summe ueber pktlen der rumhaengenden Pakete
1902 groesser als mrru ist: raus damit , Pakete muessen allerdings zusammenhaengen sonst koennte
1903 ja ein Paket mit B und eins mit E dazwischenpassen */
1907 while(q
&& (q
->sqno
< min_sqno
) ) {
1908 if ( (q
->BEbyte
& MP_END_FRAG
) ||
1909 (q
->next
&& (q
->next
->sqno
<= min_sqno
) && (q
->next
->BEbyte
& MP_BEGIN_FRAG
)) ) {
1910 printk(KERN_DEBUG
"ippp: freeing stale packet(s), min_sq: %ld!\n",min_sqno
);
1911 if ((dev
->mp_last
= q
->next
))
1912 q
->next
->last
= NULL
;
1915 printk(KERN_DEBUG
"ippp, freeing packet with sqno: %ld\n",q
->sqno
);
1916 dev_kfree_skb(q
->skb
);
1918 #ifdef CONFIG_ISDN_PPP_VJ
1927 #ifdef CONFIG_ISDN_PPP_VJ
1928 /* did we free a stale frame ? */
1930 slhc_toss(ippp_table
[dev
->local
->ppp_slot
]->slcomp
);
1936 * a buffered packet timed-out?
1939 isdn_ppp_timer_timeout(void)
1941 #ifdef CONFIG_ISDN_MPP
1942 isdn_net_dev
*net_dev
= dev
->netdev
;
1948 isdn_net_local
*lp
= net_dev
->local
;
1949 if (net_dev
->ib
.modify
|| lp
->master
) { /* interface locked or slave? */
1950 net_dev
= net_dev
->next
;
1955 if (q
->sqno_start
== net_dev
->ib
.next_num
|| q
->timer
< jiffies
) {
1957 #ifdef CONFIG_ISDN_PPP_VJ
1958 /* did we step over a missing frame ? */
1959 if (q
->sqno_start
!= net_dev
->ib
.next_num
)
1960 slhc_toss(ippp_table
[lp
->ppp_slot
]->slcomp
);
1963 ql
= net_dev
->ib
.sq
;
1964 net_dev
->ib
.sq
= q
->next
;
1965 net_dev
->ib
.next_num
= q
->sqno_end
+ 1;
1968 int proto
= isdn_ppp_strip_proto(ql
->skb
);
1969 isdn_ppp_push_higher(net_dev
, lp
, ql
->skb
, proto
);
1978 net_dev
= net_dev
->next
;
1984 * network device ioctl handlers
1988 isdn_ppp_dev_ioctl_stats(int slot
, struct ifreq
*ifr
, struct device
*dev
)
1990 struct ppp_stats
*res
,
1992 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
1995 res
= (struct ppp_stats
*) ifr
->ifr_ifru
.ifru_data
;
1996 err
= verify_area(VERIFY_WRITE
, res
, sizeof(struct ppp_stats
));
2001 /* build a temporary stat struct and copy it to user space */
2003 memset(&t
, 0, sizeof(struct ppp_stats
));
2004 if (dev
->flags
& IFF_UP
) {
2005 t
.p
.ppp_ipackets
= lp
->stats
.rx_packets
;
2006 t
.p
.ppp_ierrors
= lp
->stats
.rx_errors
;
2007 t
.p
.ppp_opackets
= lp
->stats
.tx_packets
;
2008 t
.p
.ppp_oerrors
= lp
->stats
.tx_errors
;
2009 #ifdef CONFIG_ISDN_PPP_VJ
2010 if (slot
>= 0 && ippp_table
[slot
]->slcomp
) {
2011 struct slcompress
*slcomp
= ippp_table
[slot
]->slcomp
;
2012 t
.vj
.vjs_packets
= slcomp
->sls_o_compressed
+ slcomp
->sls_o_uncompressed
;
2013 t
.vj
.vjs_compressed
= slcomp
->sls_o_compressed
;
2014 t
.vj
.vjs_searches
= slcomp
->sls_o_searches
;
2015 t
.vj
.vjs_misses
= slcomp
->sls_o_misses
;
2016 t
.vj
.vjs_errorin
= slcomp
->sls_i_error
;
2017 t
.vj
.vjs_tossed
= slcomp
->sls_i_tossed
;
2018 t
.vj
.vjs_uncompressedin
= slcomp
->sls_i_uncompressed
;
2019 t
.vj
.vjs_compressedin
= slcomp
->sls_i_compressed
;
2023 if( copy_to_user(res
, &t
, sizeof(struct ppp_stats
))) return -EFAULT
;
2028 isdn_ppp_dev_ioctl(struct device
*dev
, struct ifreq
*ifr
, int cmd
)
2033 isdn_net_local
*lp
= (isdn_net_local
*) dev
->priv
;
2036 printk(KERN_DEBUG
"ippp, dev_ioctl: cmd %#08x , %d \n", cmd
, lp
->ppp_slot
);
2039 if (lp
->p_encap
!= ISDN_NET_ENCAP_SYNCPPP
)
2044 r
= (char *) ifr
->ifr_ifru
.ifru_data
;
2045 len
= strlen(PPP_VERSION
) + 1;
2046 if(copy_to_user(r
, PPP_VERSION
, len
)) error
= -EFAULT
;
2049 error
= isdn_ppp_dev_ioctl_stats(lp
->ppp_slot
, ifr
, dev
);
2059 isdn_ppp_if_get_unit(char *name
)
2068 if (strncmp("ippp", name
, 4) || len
> 8)
2071 for (i
= 0, deci
= 1; i
< len
; i
++, deci
*= 10) {
2072 char a
= name
[len
- i
- 1];
2073 if (a
>= '0' && a
<= '9')
2074 unit
+= (a
- '0') * deci
;
2078 if (!i
|| len
- i
!= 4)
2086 isdn_ppp_dial_slave(char *name
)
2088 #ifdef CONFIG_ISDN_MPP
2091 struct device
*sdev
;
2093 if (!(ndev
= isdn_net_findif(name
)))
2096 if (!(lp
->flags
& ISDN_NET_CONNECTED
))
2101 isdn_net_local
*mlp
= (isdn_net_local
*) sdev
->priv
;
2102 if (!(mlp
->flags
& ISDN_NET_CONNECTED
))
2109 isdn_net_dial_req((isdn_net_local
*) sdev
->priv
);
2117 isdn_ppp_hangup_slave(char *name
)
2119 #ifdef CONFIG_ISDN_MPP
2122 struct device
*sdev
;
2124 if (!(ndev
= isdn_net_findif(name
)))
2127 if (!(lp
->flags
& ISDN_NET_CONNECTED
))
2132 isdn_net_local
*mlp
= (isdn_net_local
*) sdev
->priv
;
2133 if ((mlp
->flags
& ISDN_NET_CONNECTED
))
2140 isdn_net_hangup(sdev
);
2148 * PPP compression stuff
2152 /* Push an empty CCP Data Frame up to the daemon to wake it up and let it
2153 generate a CCP Reset-Request or tear down CCP altogether */
2155 static void isdn_ppp_ccp_kickup(struct ippp_struct
*is
)
2157 isdn_ppp_fill_rq(NULL
, 0, PPP_COMP
, is
->lp
->ppp_slot
);
2160 /* In-kernel handling of CCP Reset-Request and Reset-Ack is necessary,
2161 but absolutely nontrivial. The most abstruse problem we are facing is
2162 that the generation, reception and all the handling of timeouts and
2163 resends including proper request id management should be entirely left
2164 to the (de)compressor, but indeed is not covered by the current API to
2165 the (de)compressor. The API is a prototype version from PPP where only
2166 some (de)compressors have yet been implemented and all of them are
2167 rather simple in their reset handling. Especially, their is only one
2168 outstanding ResetAck at a time with all of them and ResetReq/-Acks do
2169 not have parameters. For this very special case it was sufficient to
2170 just return an error code from the decompressor and have a single
2171 reset() entry to communicate all the necessary information between
2172 the framework and the (de)compressor. Bad enough, LZS is different
2173 (and any other compressor may be different, too). It has multiple
2174 histories (eventually) and needs to Reset each of them independently
2175 and thus uses multiple outstanding Acks and history numbers as an
2176 additional parameter to Reqs/Acks.
2177 All that makes it harder to port the reset state engine into the
2178 kernel because it is not just the same simple one as in (i)pppd but
2179 it must be able to pass additional parameters and have multiple out-
2180 standing Acks. We are trying to achieve the impossible by handling
2181 reset transactions independent by their id. The id MUST change when
2182 the data portion changes, thus any (de)compressor who uses more than
2183 one resettable state must provide and recognize individual ids for
2184 each individual reset transaction. The framework itself does _only_
2185 differentiate them by id, because it has no other semantics like the
2186 (de)compressor might.
2187 This looks like a major redesign of the interface would be nice,
2188 but I don't have an idea how to do it better. */
2190 /* Send a CCP Reset-Request or Reset-Ack directly from the kernel. This is
2191 getting that lengthy because there is no simple "send-this-frame-out"
2192 function above but every wrapper does a bit different. Hope I guess
2193 correct in this hack... */
2195 static void isdn_ppp_ccp_xmit_reset(struct ippp_struct
*is
, int proto
,
2196 unsigned char code
, unsigned char id
,
2197 unsigned char *data
, int len
)
2199 struct sk_buff
*skb
;
2203 isdn_net_local
*lp
= is
->lp
;
2205 /* Alloc large enough skb */
2206 skb
= dev_alloc_skb(len
+ 16);
2209 "ippp: CCP cannot send reset - out of memory\n");
2213 /* We may need to stuff an address and control field first */
2214 if(!(is
->pppcfg
& SC_COMP_AC
)) {
2215 p
= skb_put(skb
, 2);
2220 /* Stuff proto, code, id and length */
2221 p
= skb_put(skb
, 6);
2222 *p
++ = (proto
>> 8);
2223 *p
++ = (proto
& 0xff);
2228 *p
++ = (cnt
& 0xff);
2230 /* Now stuff remaining bytes */
2232 p
= skb_put(skb
, len
);
2233 memcpy(p
, data
, len
);
2236 /* skb is now ready for xmit */
2237 printk(KERN_DEBUG
"Sending CCP Frame:\n");
2238 isdn_ppp_frame_log("ccp-xmit", skb
->data
, skb
->len
, 32, is
->unit
,lp
->ppp_slot
);
2240 /* Just ripped from isdn_ppp_write. Dunno whether it makes sense,
2241 especially dunno what the sav_skb stuff is good for. */
2244 if ((cnt
= isdn_writebuf_skb_stub(lp
->isdn_device
, lp
->isdn_channel
,
2245 1, skb
)) != count
) {
2247 dev_kfree_skb(lp
->sav_skb
);
2249 "isdn_ppp_write: freeing sav_skb (%d,%d)!\n",
2253 "isdn_ppp_write: Can't write PPP frame to LL (%d,%d)!\n",
2259 /* Allocate the reset state vector */
2260 static struct ippp_ccp_reset
*isdn_ppp_ccp_reset_alloc(struct ippp_struct
*is
)
2262 struct ippp_ccp_reset
*r
;
2263 printk(KERN_DEBUG
"ippp_ccp: allocating reset data structure\n");
2264 r
= kmalloc(sizeof(struct ippp_ccp_reset
), GFP_KERNEL
);
2267 memset(r
, 0, sizeof(struct ippp_ccp_reset
));
2272 /* Free a given state and clear everything up for later reallocation */
2273 static void isdn_ppp_ccp_reset_free_state(struct ippp_struct
*is
,
2276 struct ippp_ccp_reset_state
*rs
;
2278 if(is
->reset
->rs
[id
]) {
2279 printk(KERN_DEBUG
"ippp_ccp: freeing state for id %d\n", id
);
2280 rs
= is
->reset
->rs
[id
];
2281 /* Make sure the kernel will not call back later */
2283 del_timer(&rs
->timer
);
2284 is
->reset
->rs
[id
] = NULL
;
2287 printk(KERN_WARNING
"ippp_ccp: id %d is not allocated\n", id
);
2291 /* The timer callback function which is called when a ResetReq has timed out,
2292 aka has never been answered by a ResetAck */
2293 static void isdn_ppp_ccp_timer_callback(unsigned long closure
)
2295 struct ippp_ccp_reset_state
*rs
=
2296 (struct ippp_ccp_reset_state
*)closure
;
2299 printk(KERN_ERR
"ippp_ccp: timer cb with zero closure.\n");
2302 if(rs
->ta
&& rs
->state
== CCPResetSentReq
) {
2303 /* We are correct here */
2304 printk(KERN_DEBUG
"ippp_ccp: CCP Reset timed out for id %d\n",
2307 /* Hmm, there is no Ack really expected. We can clean
2308 up the state now, it will be reallocated if the
2309 decompressor insists on another reset */
2311 isdn_ppp_ccp_reset_free_state(rs
->is
, rs
->id
);
2315 isdn_ppp_ccp_xmit_reset(rs
->is
, PPP_CCP
, CCP_RESETREQ
, rs
->id
,
2316 rs
->data
, rs
->dlen
);
2318 rs
->timer
.expires
= jiffies
+ HZ
*5;
2319 add_timer(&rs
->timer
);
2321 printk(KERN_WARNING
"ippp_ccp: timer cb in wrong state %d\n",
2326 /* Allocate a new reset transaction state */
2327 static struct ippp_ccp_reset_state
*isdn_ppp_ccp_reset_alloc_state(struct ippp_struct
*is
,
2330 struct ippp_ccp_reset_state
*rs
;
2331 if(is
->reset
->rs
[id
]) {
2332 printk(KERN_WARNING
"ippp_ccp: old state exists for id %d\n",
2336 rs
= kmalloc(sizeof(struct ippp_ccp_reset_state
), GFP_KERNEL
);
2339 memset(rs
, 0, sizeof(struct ippp_ccp_reset_state
));
2340 rs
->state
= CCPResetIdle
;
2343 rs
->timer
.data
= (unsigned long)rs
;
2344 rs
->timer
.function
= isdn_ppp_ccp_timer_callback
;
2345 is
->reset
->rs
[id
] = rs
;
2351 /* A decompressor wants a reset with a set of parameters - do what is
2352 necessary to fulfill it */
2353 static void isdn_ppp_ccp_reset_trans(struct ippp_struct
*is
,
2354 struct isdn_ppp_resetparams
*rp
)
2356 struct ippp_ccp_reset_state
*rs
;
2359 /* The decompressor defines parameters by itself */
2361 /* And he wants us to send a request */
2363 printk(KERN_ERR
"ippp_ccp: decompressor must"
2364 " specify reset id\n");
2367 if(is
->reset
->rs
[rp
->id
]) {
2368 /* There is already a transaction in existence
2369 for this id. May be still waiting for a
2370 Ack or may be wrong. */
2371 rs
= is
->reset
->rs
[rp
->id
];
2372 if(rs
->state
== CCPResetSentReq
&& rs
->ta
) {
2373 printk(KERN_DEBUG
"ippp_ccp: reset"
2374 " trans still in progress"
2375 " for id %d\n", rp
->id
);
2377 printk(KERN_WARNING
"ippp_ccp: reset"
2378 " trans in wrong state %d for"
2379 " id %d\n", rs
->state
, rp
->id
);
2382 /* Ok, this is a new transaction */
2383 printk(KERN_DEBUG
"ippp_ccp: new trans for id"
2384 " %d to be started\n", rp
->id
);
2385 rs
= isdn_ppp_ccp_reset_alloc_state(is
, rp
->id
);
2387 printk(KERN_ERR
"ippp_ccp: out of mem"
2388 " allocing ccp trans\n");
2391 rs
->state
= CCPResetSentReq
;
2392 rs
->expra
= rp
->expra
;
2394 rs
->dlen
= rp
->dlen
;
2395 memcpy(rs
->data
, rp
->data
, rp
->dlen
);
2397 /* HACK TODO - add link comp here */
2398 isdn_ppp_ccp_xmit_reset(is
, PPP_CCP
,
2399 CCP_RESETREQ
, rs
->id
,
2400 rs
->data
, rs
->dlen
);
2401 /* Start the timer */
2402 rs
->timer
.expires
= jiffies
+ 5*HZ
;
2403 add_timer(&rs
->timer
);
2407 printk(KERN_DEBUG
"ippp_ccp: no reset sent\n");
2410 /* The reset params are invalid. The decompressor does not
2411 care about them, so we just send the minimal requests
2412 and increase ids only when an Ack is received for a
2414 if(is
->reset
->rs
[is
->reset
->lastid
]) {
2415 /* There is already a transaction in existence
2416 for this id. May be still waiting for a
2417 Ack or may be wrong. */
2418 rs
= is
->reset
->rs
[is
->reset
->lastid
];
2419 if(rs
->state
== CCPResetSentReq
&& rs
->ta
) {
2420 printk(KERN_DEBUG
"ippp_ccp: reset"
2421 " trans still in progress"
2422 " for id %d\n", rp
->id
);
2424 printk(KERN_WARNING
"ippp_ccp: reset"
2425 " trans in wrong state %d for"
2426 " id %d\n", rs
->state
, rp
->id
);
2429 printk(KERN_DEBUG
"ippp_ccp: new trans for id"
2430 " %d to be started\n", is
->reset
->lastid
);
2431 rs
= isdn_ppp_ccp_reset_alloc_state(is
,
2434 printk(KERN_ERR
"ippp_ccp: out of mem"
2435 " allocing ccp trans\n");
2438 rs
->state
= CCPResetSentReq
;
2439 /* We always expect an Ack if the decompressor doesnt
2443 /* HACK TODO - add link comp here */
2444 isdn_ppp_ccp_xmit_reset(is
, PPP_CCP
, CCP_RESETREQ
,
2446 /* Start the timer */
2447 rs
->timer
.expires
= jiffies
+ 5*HZ
;
2448 add_timer(&rs
->timer
);
2454 /* An Ack was received for this id. This means we stop the timer and clean
2455 up the state prior to calling the decompressors reset routine. */
2456 static void isdn_ppp_ccp_reset_ack_rcvd(struct ippp_struct
*is
,
2459 struct ippp_ccp_reset_state
*rs
= is
->reset
->rs
[id
];
2462 if(rs
->ta
&& rs
->state
== CCPResetSentReq
) {
2463 /* Great, we are correct */
2465 printk(KERN_DEBUG
"ippp_ccp: ResetAck received"
2466 " for id %d but not expected\n", id
);
2468 printk(KERN_INFO
"ippp_ccp: ResetAck received out of"
2469 "sync for id %d\n", id
);
2473 del_timer(&rs
->timer
);
2475 isdn_ppp_ccp_reset_free_state(is
, id
);
2477 printk(KERN_INFO
"ippp_ccp: ResetAck received for unknown id"
2480 /* Make sure the simple reset stuff uses a new id next time */
2481 is
->reset
->lastid
++;
2484 static struct sk_buff
*isdn_ppp_decompress(struct sk_buff
*skb
,struct ippp_struct
*is
,struct ippp_struct
*master
,
2487 #ifndef CONFIG_ISDN_CCP
2488 if(proto
== PPP_COMP
|| proto
== PPP_LINK_COMP
) {
2489 printk(KERN_ERR
"isdn_ppp: Ouch! Compression not included!\n");
2496 struct isdn_ppp_compressor
*ipc
= NULL
;
2497 struct sk_buff
*skb_out
;
2499 struct ippp_struct
*ri
;
2500 struct isdn_ppp_resetparams rsparm
;
2501 unsigned char rsdata
[IPPP_RESET_MAXDATABYTES
];
2505 * single link decompression
2507 if(!is
->link_decompressor
) {
2508 printk(KERN_ERR
"ippp: no link decompressor defined!\n");
2512 if(!is
->link_decomp_stat
) {
2513 printk(KERN_DEBUG
"ippp: no link decompressor data allocated\n");
2517 stat
= is
->link_decomp_stat
;
2518 ipc
= is
->link_decompressor
;
2523 * 'normal' or bundle-compression
2525 if(!master
->decompressor
) {
2526 printk(KERN_ERR
"ippp: no decompressor defined!\n");
2530 if(!master
->decomp_stat
) {
2531 printk(KERN_DEBUG
"ippp: no decompressor data allocated\n");
2535 stat
= master
->decomp_stat
;
2536 ipc
= master
->decompressor
;
2541 printk(KERN_DEBUG "ippp: Decompress valid!\n");
2544 if((master
&& proto
== PPP_COMP
) || (!master
&& proto
== PPP_LINK_COMP
) ) {
2545 /* Set up reset params for the decompressor */
2546 memset(&rsparm
, 0, sizeof(rsparm
));
2547 rsparm
.data
= rsdata
;
2548 rsparm
.maxdlen
= IPPP_RESET_MAXDATABYTES
;
2550 /* !!!HACK,HACK,HACK!!! 2048 is only assumed */
2551 skb_out
= dev_alloc_skb(2048);
2552 len
= ipc
->decompress(stat
,skb
,skb_out
, &rsparm
);
2555 /* Ok, some error */
2558 ri
->pppcfg
|= SC_DC_ERROR
;
2559 printk(KERN_INFO
"ippp: decomp wants reset %s params\n",
2560 rsparm
.valid
? "with" : "without");
2562 isdn_ppp_ccp_reset_trans(ri
, &rsparm
);
2565 case DECOMP_FATALERROR
:
2566 ri
->pppcfg
|= SC_DC_FERROR
;
2567 /* Kick ipppd to recognize the error */
2568 isdn_ppp_ccp_kickup(ri
);
2571 /* Did I see a leak here ? */
2572 dev_kfree_skb(skb_out
);
2579 printk(KERN_DEBUG "isdn_ppp: [%d] Calling incomp with this frame!\n",is->unit);
2581 ipc
->incomp(stat
,skb
,proto
);
2589 * type=0: normal/bundle compression
2590 * =1: link compression
2591 * returns original skb if we haven't compressed the frame
2592 * and a new skb pointer if we've done it
2594 static struct sk_buff
*isdn_ppp_compress(struct sk_buff
*skb_in
,int *proto
,
2595 struct ippp_struct
*is
,struct ippp_struct
*master
,int type
)
2599 struct isdn_ppp_compressor
*compressor
;
2601 struct sk_buff
*skb_out
;
2603 #ifdef CONFIG_ISDN_CCP
2604 /* we do not compress control protocols */
2605 if(*proto
< 0 || *proto
> 0x3fff) {
2612 if(type
) { /* type=1 => Link compression */
2614 compressor
= is
->link_compressor
;
2615 stat
= is
->link_comp_stat
;
2616 new_proto
= PPP_LINK_COMP
;
2623 compressor
= is
->compressor
;
2624 stat
= is
->comp_stat
;
2627 compressor
= master
->compressor
;
2628 stat
= master
->comp_stat
;
2630 new_proto
= PPP_COMP
;
2634 printk(KERN_ERR
"isdn_ppp: No compressor set!\n");
2638 printk(KERN_ERR
"isdn_ppp: Compressor not initialized?\n");
2642 /* Allow for at least 150 % expansion (for now) */
2643 skb_out
= dev_alloc_skb(skb_in
->len
+ skb_in
->len
/2 + 32);
2647 ret
= (compressor
->compress
)(stat
,skb_in
,skb_out
,*proto
);
2649 dev_kfree_skb(skb_out
);
2653 dev_kfree_skb(skb_in
);
2659 * we received a CCP frame ..
2660 * not a clean solution, but we MUST handle a few cases in the kernel
2662 static void isdn_ppp_receive_ccp(isdn_net_dev
*net_dev
, isdn_net_local
*lp
,
2663 struct sk_buff
*skb
,int proto
)
2665 struct ippp_struct
*is
= ippp_table
[lp
->ppp_slot
];
2666 struct ippp_struct
*mis
;
2668 struct isdn_ppp_resetparams rsparm
;
2669 unsigned char rsdata
[IPPP_RESET_MAXDATABYTES
];
2671 printk(KERN_DEBUG
"Received CCP frame from peer\n");
2672 isdn_ppp_frame_log("ccp-rcv", skb
->data
, skb
->len
, 32, is
->unit
,lp
->ppp_slot
);
2675 mis
= ippp_table
[((isdn_net_local
*) (lp
->master
->priv
))->ppp_slot
];
2679 switch(skb
->data
[0]) {
2683 if(is
->debug
& 0x10)
2684 printk(KERN_DEBUG
"Disable (de)compression here!\n");
2685 if(proto
== PPP_CCP
)
2686 mis
->compflags
&= ~(SC_DECOMP_ON
|SC_COMP_ON
);
2688 is
->compflags
&= ~(SC_LINK_DECOMP_ON
|SC_LINK_COMP_ON
);
2691 /* if we RECEIVE an ackowledge we enable the decompressor */
2692 if(is
->debug
& 0x10)
2693 printk(KERN_DEBUG
"Enable decompression here!\n");
2694 if(proto
== PPP_CCP
)
2695 mis
->compflags
|= SC_DECOMP_ON
;
2697 is
->compflags
|= SC_LINK_DECOMP_ON
;
2701 printk(KERN_DEBUG
"Received ResetAck from peer\n");
2702 len
= (skb
->data
[2] << 8) | skb
->data
[3];
2705 if(proto
== PPP_CCP
) {
2706 /* If a reset Ack was outstanding for this id, then
2707 clean up the state engine */
2708 isdn_ppp_ccp_reset_ack_rcvd(mis
, skb
->data
[1]);
2709 if(mis
->decompressor
&& mis
->decomp_stat
)
2711 reset(mis
->decomp_stat
,
2714 len
? &skb
->data
[4] : NULL
,
2716 /* TODO: This is not easy to decide here */
2717 mis
->compflags
&= ~SC_DECOMP_DISCARD
;
2718 mis
->pppcfg
&= ~SC_DC_ERROR
;
2721 isdn_ppp_ccp_reset_ack_rcvd(is
, skb
->data
[1]);
2722 if(is
->link_decompressor
&& is
->link_decomp_stat
)
2723 is
->link_decompressor
->
2724 reset(is
->link_decomp_stat
,
2727 len
? &skb
->data
[4] : NULL
,
2729 /* TODO: neither here */
2730 is
->compflags
&= ~SC_LINK_DECOMP_DISCARD
;
2731 is
->pppcfg
&= ~SC_DC_ERROR
;
2736 printk(KERN_DEBUG
"Received ResetReq from peer\n");
2737 /* Receiving a ResetReq means we must reset our compressor */
2738 /* Set up reset params for the reset entry */
2739 memset(&rsparm
, 0, sizeof(rsparm
));
2740 rsparm
.data
= rsdata
;
2741 rsparm
.maxdlen
= IPPP_RESET_MAXDATABYTES
;
2742 /* Isolate data length */
2743 len
= (skb
->data
[2] << 8) | skb
->data
[3];
2745 if(proto
== PPP_CCP
) {
2746 if(mis
->compressor
&& mis
->comp_stat
)
2748 reset(mis
->comp_stat
,
2751 len
? &skb
->data
[4] : NULL
,
2755 if(is
->link_compressor
&& is
->link_comp_stat
)
2756 is
->link_compressor
->
2757 reset(is
->link_comp_stat
,
2760 len
? &skb
->data
[4] : NULL
,
2763 /* Ack the Req as specified by rsparm */
2765 /* Compressor reset handler decided how to answer */
2767 /* We should send a Frame */
2768 isdn_ppp_ccp_xmit_reset(is
, proto
, CCP_RESETACK
,
2769 rsparm
.idval
? rsparm
.id
2776 printk(KERN_DEBUG
"ResetAck suppressed\n");
2779 /* We answer with a straight reflected Ack */
2780 isdn_ppp_ccp_xmit_reset(is
, proto
, CCP_RESETACK
,
2782 len
? &skb
->data
[4] : NULL
,
2791 * Daemon sends a CCP frame ...
2794 /* TODO: Clean this up with new Reset semantics */
2796 static void isdn_ppp_send_ccp(isdn_net_dev
*net_dev
, isdn_net_local
*lp
, struct sk_buff
*skb
)
2798 struct ippp_struct
*mis
,*is
= ippp_table
[lp
->ppp_slot
];
2800 unsigned char *data
;
2802 if(!skb
|| skb
->len
< 3)
2805 /* Daemon may send with or without address and control field comp */
2807 if(!(is
->pppcfg
& SC_COMP_AC
) && data
[0] == 0xff && data
[1] == 0x03) {
2813 proto
= ((int)data
[0]<<8)+data
[1];
2814 if(proto
!= PPP_CCP
&& proto
!= PPP_LINK_CCP
)
2817 printk(KERN_DEBUG
"Received CCP frame from daemon:\n");
2818 isdn_ppp_frame_log("ccp-xmit", skb
->data
, skb
->len
, 32, is
->unit
,lp
->ppp_slot
);
2821 mis
= ippp_table
[((isdn_net_local
*) (lp
->master
->priv
))->ppp_slot
];
2826 printk(KERN_DEBUG
"isdn_ppp: Ouch! Master CCP sends on slave slot!\n");
2832 if(is
->debug
& 0x10)
2833 printk(KERN_DEBUG
"Disable (de)compression here!\n");
2834 if(proto
== PPP_CCP
)
2835 is
->compflags
&= ~(SC_DECOMP_ON
|SC_COMP_ON
);
2837 is
->compflags
&= ~(SC_LINK_DECOMP_ON
|SC_LINK_COMP_ON
);
2840 /* if we SEND an ackowledge we can/must enable the compressor */
2841 if(is
->debug
& 0x10)
2842 printk(KERN_DEBUG
"Enable compression here!\n");
2843 if(proto
== PPP_CCP
)
2844 is
->compflags
|= SC_COMP_ON
;
2846 is
->compflags
|= SC_LINK_COMP_ON
;
2849 /* If we send a ACK we should reset our compressor */
2850 if(is
->debug
& 0x10)
2851 printk(KERN_DEBUG
"Reset decompression state here!\n");
2852 printk(KERN_DEBUG
"ResetAck from daemon passed by\n");
2853 if(proto
== PPP_CCP
) {
2854 /* link to master? */
2855 if(is
->compressor
&& is
->comp_stat
)
2856 is
->compressor
->reset(is
->comp_stat
, 0, 0,
2858 is
->compflags
&= ~SC_COMP_DISCARD
;
2861 if(is
->link_compressor
&& is
->link_comp_stat
)
2862 is
->link_compressor
->reset(is
->link_comp_stat
,
2863 0, 0, NULL
, 0, NULL
);
2864 is
->compflags
&= ~SC_LINK_COMP_DISCARD
;
2868 /* Just let it pass by */
2869 printk(KERN_DEBUG
"ResetReq from daemon passed by\n");
2875 int isdn_ppp_register_compressor(struct isdn_ppp_compressor
*ipc
)
2877 ipc
->next
= ipc_head
;
2880 ipc_head
->prev
= ipc
;
2886 int isdn_ppp_unregister_compressor(struct isdn_ppp_compressor
*ipc
)
2889 ipc
->prev
->next
= ipc
->next
;
2891 ipc_head
= ipc
->next
;
2893 ipc
->next
->prev
= ipc
->prev
;
2894 ipc
->prev
= ipc
->next
= NULL
;
2898 static int isdn_ppp_set_compressor(struct ippp_struct
*is
, struct isdn_ppp_comp_data
*data
)
2900 struct isdn_ppp_compressor
*ipc
= ipc_head
;
2903 int num
= data
->num
;
2905 if(is
->debug
& 0x10)
2906 printk(KERN_DEBUG
"[%d] Set %s type %d\n",is
->unit
,
2907 (data
->flags
&IPPP_COMP_FLAG_XMIT
)?"compressor":"decompressor",num
);
2910 if(ipc
->num
== num
) {
2911 stat
= ipc
->alloc(data
);
2913 ret
= ipc
->init(stat
,data
,is
->unit
,0);
2915 printk(KERN_ERR
"Can't init (de)compression!\n");
2922 printk(KERN_ERR
"Can't alloc (de)compression!\n");
2926 if(data
->flags
& IPPP_COMP_FLAG_XMIT
) {
2927 if(data
->flags
& IPPP_COMP_FLAG_LINK
) {
2928 if(is
->link_comp_stat
)
2929 is
->link_compressor
->free(is
->link_comp_stat
);
2930 is
->link_comp_stat
= stat
;
2931 is
->link_compressor
= ipc
;
2935 is
->compressor
->free(is
->comp_stat
);
2936 is
->comp_stat
= stat
;
2937 is
->compressor
= ipc
;
2941 if(data
->flags
& IPPP_COMP_FLAG_LINK
) {
2942 if(is
->link_decomp_stat
)
2943 is
->link_decompressor
->free(is
->link_decomp_stat
);
2944 is
->link_decomp_stat
= stat
;
2945 is
->link_decompressor
= ipc
;
2949 is
->decompressor
->free(is
->decomp_stat
);
2950 is
->decomp_stat
= stat
;
2951 is
->decompressor
= ipc
;