This source file includes following definitions.
- store_long
- ppp_first_time
- ppp_init_dev
- ppp_init_ctrl_blk
- ppp_init
- ppp_alloc_buf
- ppp_free_buf
- lock_buffer
- ppp_changedmtu
- ppp_ccp_closed
- ppp_release
- ppp_tty_close
- ppp_tty_open
- ppp_tty_wakeup_code
- ppp_tty_wakeup
- ppp_kick_tty
- ppp_tty_room
- ppp_tty_receive
- ppp_rcv_rx
- rcv_proto_ip
- rcv_proto_ipx
- rcv_proto_vjc_comp
- rcv_proto_vjc_uncomp
- rcv_proto_unknown
- ppp_proto_ccp
- rcv_proto_ccp
- rcv_proto_lqr
- ppp_doframe_lower
- ppp_doframe
- ppp_tty_read
- ppp_stuff_char
- ppp_dev_xmit_lower
- ppp_dev_xmit_frame
- send_revise_frame
- ppp_tty_write
- ppp_set_compression
- ppp_tty_ioctl
- ppp_tty_select
- ppp_dev_open
- ppp_dev_close
- ppp_dev_ioctl_version
- ppp_dev_ioctl_stats
- ppp_dev_ioctl_comp_stats
- ppp_dev_ioctl
- ppp_dev_xmit_ip1
- ppp_dev_xmit_ip
- ppp_dev_xmit_ipx1
- ppp_dev_xmit_ipx
- ppp_dev_xmit
- ppp_dev_stats
- ppp_dev_input
- ppp_dev_output
- ppp_dev_getkey
- ppp_dev_type
- ppp_dev_header
- ppp_dev_rebuild
- ppp_alloc
- ppp_print_hex
- ppp_print_char
- ppp_print_buffer
- find_compressor
- ppp_register_compressor
- ppp_unregister_compressor
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #define OPTIMIZE_FLAG_TIME ((HZ * 3)/2)
48
49 #define CHECK_CHARACTERS 1
50 #define PPP_COMPRESS 1
51 #define USE_SKB_PROTOCOL 1
52
53 #ifdef NEW_SKBUFF
54 #undef USE_SKB_PROTOCOL
55 #define USE_SKB_PROTOCOL 2
56 #endif
57
58 #ifndef PPP_MAX_DEV
59 #define PPP_MAX_DEV 256
60 #endif
61
62
63
64
65
66
67
68
69
70 #include <linux/module.h>
71
72 #include <endian.h>
73 #include <linux/kernel.h>
74 #include <linux/sched.h>
75 #include <linux/types.h>
76 #include <linux/fcntl.h>
77 #include <linux/interrupt.h>
78 #include <linux/ptrace.h>
79 #include <linux/ioport.h>
80 #include <linux/in.h>
81 #include <linux/malloc.h>
82 #include <linux/tty.h>
83 #include <linux/errno.h>
84 #include <linux/sched.h>
85 #include <linux/string.h>
86 #include <linux/signal.h>
87 #include <asm/system.h>
88 #include <asm/bitops.h>
89 #include <asm/segment.h>
90 #include <net/if.h>
91 #include <linux/if_ether.h>
92 #include <linux/netdevice.h>
93 #include <linux/skbuff.h>
94 #include <linux/inet.h>
95 #include <linux/ioctl.h>
96
97 #ifdef NEW_SKBUFF
98 #include <linux/netprotocol.h>
99 #else
100 typedef struct sk_buff sk_buff;
101 #define skb_data(skb) ((unsigned char *) (skb)->data)
102 #endif
103
104 #include <netinet/ip.h>
105 #include <netinet/tcp.h>
106 #include <linux/if_arp.h>
107 #include "slhc.h"
108 #include <linux/ppp_defs.h>
109 #include <linux/socket.h>
110 #include <linux/if_ppp.h>
111 #include <linux/if_pppvar.h>
112
113 #undef PACKETPTR
114 #define PACKETPTR 1
115 #include <linux/ppp-comp.h>
116 #undef PACKETPTR
117
118 #define bsd_decompress (*ppp->sc_rcomp->decompress)
119 #define bsd_compress (*ppp->sc_xcomp->compress)
120
121 #ifndef PPP_IPX
122 #define PPP_IPX 0x2b
123 #endif
124
125 #ifndef PPP_LQR
126 #define PPP_LQR 0xc025
127 #endif
128
129 int ppp_register_compressor (struct compressor *cp);
130 void ppp_unregister_compressor (struct compressor *cp);
131
132
133
134
135
136 static struct compressor *find_compressor (int type);
137 static void ppp_init_ctrl_blk (register struct ppp *);
138 static void ppp_kick_tty (struct ppp *, struct ppp_buffer *bfr);
139 static int ppp_doframe (struct ppp *);
140 static struct ppp *ppp_alloc (void);
141 static void ppp_print_buffer (const u_char *, const u_char *, int);
142 extern inline void ppp_stuff_char (struct ppp *ppp,
143 register struct ppp_buffer *buf,
144 register u_char chr);
145 extern inline int lock_buffer (register struct ppp_buffer *buf);
146
147 static int rcv_proto_ip (struct ppp *, u_short, u_char *, int);
148 static int rcv_proto_ipx (struct ppp *, u_short, u_char *, int);
149 static int rcv_proto_vjc_comp (struct ppp *, u_short, u_char *, int);
150 static int rcv_proto_vjc_uncomp (struct ppp *, u_short, u_char *, int);
151 static int rcv_proto_unknown (struct ppp *, u_short, u_char *, int);
152 static int rcv_proto_lqr (struct ppp *, u_short, u_char *, int);
153 static void ppp_doframe_lower (struct ppp *, u_char *, int);
154 static int ppp_doframe (struct ppp *);
155
156 extern int ppp_bsd_compressor_init(void);
157 static void ppp_proto_ccp (struct ppp *ppp, u_char *dp, int len, int rcvd);
158 static int rcv_proto_ccp (struct ppp *, u_short, u_char *, int);
159
160 #define ins_char(pbuf,c) (buf_base(pbuf) [(pbuf)->count++] = (u_char)(c))
161
162 #ifndef OPTIMIZE_FLAG_TIME
163 #define OPTIMIZE_FLAG_TIME 0
164 #endif
165
166 #ifndef PPP_MAX_DEV
167 #define PPP_MAX_DEV 256
168 #endif
169
170
171
172
173
174 static int flag_time = OPTIMIZE_FLAG_TIME;
175 static int max_dev = PPP_MAX_DEV;
176
177
178
179
180
181 int ppp_init (struct device *);
182
183
184
185
186
187 static int ppp_dev_open (struct device *);
188 static int ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd);
189 static int ppp_dev_close (struct device *);
190 static int ppp_dev_xmit (sk_buff *, struct device *);
191 static struct enet_statistics *ppp_dev_stats (struct device *);
192
193 #if USE_SKB_PROTOCOL == 0
194 #define dev_alloc_skb(count) alloc_skb(count, GFP_ATOMIC)
195 #define skb_put(skb,count) skb_data(skb)
196 #define get_long_user(addr) get_user_long((void *) addr)
197 #define get_int_user(addr) ((int) get_user_long((void *) addr))
198 #define put_byte_user(val,addr) put_fs_byte(val,((u_char *) (addr)))
199 #define put_long_user(val,addr) put_fs_long((val),((void *) (addr)))
200
201 static unsigned short ppp_dev_type (sk_buff *, struct device *);
202 static int ppp_dev_header (unsigned char *buff, struct device *dev,
203 unsigned short type, void *daddr, void *saddr,
204 unsigned len, struct sk_buff *skb);
205
206 #else
207 #define get_long_user(addr) get_user(((int *) addr))
208 #define get_int_user(addr) ((int) get_user(((int *) addr)))
209 #define put_byte_user(val,addr) put_user((val),((u_char *) (addr)))
210 #define put_long_user(val,addr) put_user((val),((int *) (addr)))
211
212 static int ppp_dev_header (sk_buff *, struct device *, unsigned short,
213 void *, void *, unsigned);
214 #endif
215
216 #ifdef NEW_SKBUFF
217 static int ppp_dev_input (struct protocol *self, struct protocol *lower,
218 sk_buff *skb, void *saddr, void *daddr);
219 static int ppp_dev_output (struct protocol *self, sk_buff *skb, int type,
220 int subid, void *saddr, void *daddr, void *opt);
221 static int ppp_dev_getkey(int protocol, int subid, unsigned char *key);
222 #else
223 static int ppp_dev_rebuild (void *, struct device *, unsigned long,
224 sk_buff *);
225 #endif
226
227
228
229
230
231 static int ppp_tty_read (struct tty_struct *, struct file *, u_char *,
232 unsigned int);
233 static int ppp_tty_write (struct tty_struct *, struct file *, const u_char *,
234 unsigned int);
235 static int ppp_tty_ioctl (struct tty_struct *, struct file *, unsigned int,
236 unsigned long);
237 static int ppp_tty_select (struct tty_struct *tty, struct inode *inode,
238 struct file *filp, int sel_type, select_table * wait);
239 static int ppp_tty_open (struct tty_struct *);
240 static void ppp_tty_close (struct tty_struct *);
241 static int ppp_tty_room (struct tty_struct *tty);
242 static void ppp_tty_receive (struct tty_struct *tty, const u_char * cp,
243 char *fp, int count);
244 static void ppp_tty_wakeup (struct tty_struct *tty);
245
246 #define CHECK_PPP(a) if (!ppp->inuse) { printk (ppp_warning, __LINE__); return a;}
247 #define CHECK_PPP_VOID() if (!ppp->inuse) { printk (ppp_warning, __LINE__); return;}
248
249 #define in_xmap(ppp,c) (ppp->xmit_async_map[(c) >> 5] & (1 << ((c) & 0x1f)))
250 #define in_rmap(ppp,c) ((((unsigned int) (u_char) (c)) < 0x20) && \
251 ppp->recv_async_map & (1 << (c)))
252
253 #define bset(p,b) ((p)[(b) >> 5] |= (1 << ((b) & 0x1f)))
254
255 #define tty2ppp(tty) ((struct ppp *) (tty->disc_data))
256 #define dev2ppp(dev) ((struct ppp *) (dev->priv))
257 #define ppp2tty(ppp) ((struct tty_struct *) ppp->tty)
258 #define ppp2dev(ppp) ((struct device *) ppp->dev)
259
260 struct ppp_hdr {
261 unsigned char address;
262 unsigned char control;
263 unsigned char protocol[2];
264 };
265
266 #define PPP_HARD_HDR_LEN (sizeof (struct ppp_hdr))
267
268 typedef struct ppp_ctrl {
269 struct ppp_ctrl *next;
270 char name [8];
271 struct ppp ppp;
272 struct device dev;
273 } ppp_ctrl_t;
274
275 static ppp_ctrl_t *ppp_list = NULL;
276
277 #define ctl2ppp(ctl) (struct ppp *) &ctl->ppp
278 #define ctl2dev(ctl) (struct device *) &ctl->dev
279 #undef PPP_NRUNIT
280
281
282 #define BUFFER_TYPE_DEV_RD 0
283 #define BUFFER_TYPE_TTY_WR 1
284 #define BUFFER_TYPE_DEV_WR 2
285 #define BUFFER_TYPE_TTY_RD 3
286 #define BUFFER_TYPE_VJ 4
287
288
289 static char ppp_warning[] = KERN_WARNING "PPP: ALERT! not INUSE! %d\n";
290
291 static char szVersion[] = PPP_VERSION;
292
293 #ifdef NEW_SKBUFF
294 static struct protocol proto_ppp;
295 #endif
296
297
298
299
300
301 typedef int (*pfn_proto) (struct ppp *, u_short, u_char *, int);
302
303 typedef struct ppp_proto_struct {
304 int proto;
305 pfn_proto func;
306 } ppp_proto_type;
307
308 static
309 ppp_proto_type proto_list[] = {
310 { PPP_IP, rcv_proto_ip },
311 { PPP_IPX, rcv_proto_ipx },
312 { PPP_VJC_COMP, rcv_proto_vjc_comp },
313 { PPP_VJC_UNCOMP, rcv_proto_vjc_uncomp },
314 { PPP_LQR, rcv_proto_lqr },
315 { PPP_CCP, rcv_proto_ccp },
316 { 0, rcv_proto_unknown }
317 };
318
319
320
321
322
323 #define PPP_INITFCS 0xffff
324 #define PPP_GOODFCS 0xf0b8
325 #define PPP_FCS(fcs, c) (((fcs) >> 8) ^ ppp_crc16_table[((fcs) ^ (c)) & 0xff])
326
327 unsigned short ppp_crc16_table[256] =
328 {
329 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
330 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
331 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
332 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
333 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
334 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
335 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
336 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
337 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
338 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
339 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
340 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
341 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
342 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
343 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
344 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
345 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
346 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
347 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
348 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
349 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
350 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
351 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
352 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
353 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
354 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
355 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
356 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
357 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
358 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
359 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
360 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
361 };
362
363 #ifdef CHECK_CHARACTERS
364 static unsigned paritytab[8] =
365 {
366 0x96696996, 0x69969669, 0x69969669, 0x96696996,
367 0x69969669, 0x96696996, 0x96696996, 0x69969669
368 };
369 #endif
370
371
372 extern inline u_char * store_long (register u_char *p, register int value) {
373 *p++ = (u_char) (value >> 24);
374 *p++ = (u_char) (value >> 16);
375 *p++ = (u_char) (value >> 8);
376 *p++ = (u_char) value;
377 return p;
378 }
379
380
381
382
383
384
385
386
387
388
389 static int
390 ppp_first_time (void)
391 {
392 static struct tty_ldisc ppp_ldisc;
393 int status;
394
395 printk (KERN_INFO
396 "PPP: version %s (dynamic channel allocation)"
397 #ifdef NEW_SKBUFF
398 " NEW_SKBUFF"
399 #endif
400 "\n", szVersion);
401
402 #ifndef MODULE
403 printk (KERN_INFO
404 "TCP compression code copyright 1989 Regents of the "
405 "University of California\n");
406 #endif
407
408 printk (KERN_INFO
409 "PPP Dynamic channel allocation code copyright 1995 "
410 "Caldera, Inc.\n");
411
412
413
414
415 #ifdef NEW_SKBUFF
416 memset (&proto_ppp, 0, sizeof (proto_ppp));
417
418 proto_ppp.name = "PPP";
419 proto_ppp.output = ppp_dev_output;
420 proto_ppp.input = ppp_dev_input;
421 proto_ppp.bh_input = ppp_dev_input;
422 proto_ppp.control_event = default_protocol_control;
423 proto_ppp.get_binding = ppp_dev_getkey;
424 proto_ppp.header_space = 0;
425
426 protocol_register(&proto_ppp);
427 #endif
428
429
430
431
432 (void) memset (&ppp_ldisc, 0, sizeof (ppp_ldisc));
433 ppp_ldisc.magic = TTY_LDISC_MAGIC;
434 ppp_ldisc.open = ppp_tty_open;
435 ppp_ldisc.close = ppp_tty_close;
436 ppp_ldisc.read = ppp_tty_read;
437 ppp_ldisc.write = ppp_tty_write;
438 ppp_ldisc.ioctl = ppp_tty_ioctl;
439 ppp_ldisc.select = ppp_tty_select;
440 ppp_ldisc.receive_room = ppp_tty_room;
441 ppp_ldisc.receive_buf = ppp_tty_receive;
442 ppp_ldisc.write_wakeup = ppp_tty_wakeup;
443
444 status = tty_register_ldisc (N_PPP, &ppp_ldisc);
445 if (status == 0)
446 printk (KERN_INFO "PPP line discipline registered.\n");
447 else
448 printk (KERN_ERR "error registering line discipline: %d\n",
449 status);
450 return status;
451 }
452
453
454
455
456
457
458
459 static int
460 ppp_init_dev (struct device *dev)
461 {
462 int indx;
463 #ifdef NEW_SKBUFF
464 dev->default_protocol = &proto_ppp;
465 #else
466 dev->hard_header = ppp_dev_header;
467 #if USE_SKB_PROTOCOL == 0
468 dev->type_trans = ppp_dev_type;
469 #endif
470 dev->rebuild_header = ppp_dev_rebuild;
471 dev->hard_header_len = 0;
472 #endif
473
474
475 dev->mtu = PPP_MTU;
476 dev->hard_start_xmit = ppp_dev_xmit;
477 dev->open = ppp_dev_open;
478 dev->stop = ppp_dev_close;
479 dev->get_stats = ppp_dev_stats;
480 dev->do_ioctl = ppp_dev_ioctl;
481 dev->addr_len = 0;
482 dev->type = ARPHRD_PPP;
483 dev->tx_queue_len = 10;
484
485 for (indx = 0; indx < DEV_NUMBUFFS; indx++)
486 skb_queue_head_init (&dev->buffs[indx]);
487
488
489 dev->flags = IFF_POINTOPOINT;
490 dev->family = AF_INET;
491 dev->pa_addr = 0;
492 dev->pa_brdaddr = 0;
493 dev->pa_mask = 0;
494 dev->pa_alen = 4;
495
496 return 0;
497 }
498
499
500
501
502
503 static void
504 ppp_init_ctrl_blk (register struct ppp *ppp)
505 {
506 ppp->magic = PPP_MAGIC;
507 ppp->toss = 0xE0;
508 ppp->escape = 0;
509
510 ppp->flags = 0;
511 ppp->mtu = PPP_MTU;
512 ppp->mru = PPP_MRU;
513
514 memset (ppp->xmit_async_map, 0, sizeof (ppp->xmit_async_map));
515 ppp->xmit_async_map[0] = 0xffffffff;
516 ppp->xmit_async_map[3] = 0x60000000;
517 ppp->recv_async_map = 0x00000000;
518
519 ppp->rbuf = NULL;
520 ppp->wbuf = NULL;
521 ppp->ubuf = NULL;
522 ppp->cbuf = NULL;
523 ppp->slcomp = NULL;
524 ppp->read_wait = NULL;
525 ppp->write_wait = NULL;
526 ppp->last_xmit = jiffies - flag_time;
527
528
529 memset (&ppp->stats, '\0', sizeof (struct pppstat));
530
531
532 ppp->ddinfo.xmit_idle=
533 ppp->ddinfo.recv_idle=jiffies;
534
535
536 ppp->sc_xc_state =
537 ppp->sc_rc_state = NULL;
538 }
539
540 static struct symbol_table ppp_syms = {
541 #include <linux/symtab_begin.h>
542 X(ppp_register_compressor),
543 X(ppp_unregister_compressor),
544 X(ppp_crc16_table),
545 #include <linux/symtab_end.h>
546 };
547
548
549
550 #ifndef MODULE
551 int
552 ppp_init (struct device *dev)
553 {
554 static int first_time = 1;
555 int answer = 0;
556
557 if (first_time) {
558 first_time = 0;
559 answer = ppp_first_time();
560 if (answer == 0)
561 (void) register_symtab (&ppp_syms);
562 }
563 if (answer)
564 return answer;
565
566
567
568
569 return ENODEV;
570
571 }
572 #endif
573
574
575
576
577
578 static struct ppp_buffer *
579 ppp_alloc_buf (int size, int type)
580 {
581 struct ppp_buffer *buf;
582
583 buf = (struct ppp_buffer *) kmalloc (size + sizeof (struct ppp_buffer),
584 GFP_ATOMIC);
585
586 if (buf != NULL) {
587 buf->size = size - 1;
588 buf->type = type;
589 buf->locked = 0;
590 buf->count = 0;
591 buf->head = 0;
592 buf->tail = 0;
593 buf->fcs = PPP_INITFCS;
594 }
595 return (buf);
596 }
597
598
599
600
601
602 static void
603 ppp_free_buf (struct ppp_buffer *ptr)
604 {
605 if (ptr != NULL)
606 kfree (ptr);
607 }
608
609
610
611
612
613 extern inline int
614 lock_buffer (register struct ppp_buffer *buf)
615 {
616 register int state;
617 int flags;
618
619
620
621 save_flags (flags);
622 cli ();
623 state = buf->locked;
624 if (state == 0)
625 buf->locked = 2;
626
627
628
629 restore_flags (flags);
630 return (state);
631 }
632
633
634
635
636
637
638
639 static int
640 ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
641 {
642 struct device *dev;
643
644 struct ppp_buffer *new_rbuf;
645 struct ppp_buffer *new_wbuf;
646 struct ppp_buffer *new_cbuf;
647 struct ppp_buffer *new_tbuf;
648
649 struct ppp_buffer *old_rbuf;
650 struct ppp_buffer *old_wbuf;
651 struct ppp_buffer *old_cbuf;
652 struct ppp_buffer *old_tbuf;
653
654 int mtu, mru;
655
656
657
658 dev = ppp2dev (ppp);
659 mru = new_mru;
660
661 mtu = (new_mtu * 2) + 20;
662
663
664 if (mru < PPP_MRU)
665 mru = PPP_MRU;
666
667 mru += 10;
668
669 if (ppp->flags & SC_DEBUG)
670 printk (KERN_INFO "ppp: channel %s mtu = %d, mru = %d\n",
671 dev->name, new_mtu, new_mru);
672
673 new_wbuf = ppp_alloc_buf (mtu+PPP_HARD_HDR_LEN, BUFFER_TYPE_DEV_WR);
674 new_tbuf = ppp_alloc_buf ((PPP_MTU * 2) + 24, BUFFER_TYPE_TTY_WR);
675 new_rbuf = ppp_alloc_buf (mru + 84, BUFFER_TYPE_DEV_RD);
676 new_cbuf = ppp_alloc_buf (mru+PPP_HARD_HDR_LEN, BUFFER_TYPE_VJ);
677
678
679
680
681 if (new_wbuf == NULL || new_tbuf == NULL ||
682 new_rbuf == NULL || new_cbuf == NULL) {
683 if (ppp->flags & SC_DEBUG)
684 printk (KERN_ERR
685 "ppp: failed to allocate new buffers\n");
686
687 ppp_free_buf (new_wbuf);
688 ppp_free_buf (new_tbuf);
689 ppp_free_buf (new_rbuf);
690 ppp_free_buf (new_cbuf);
691 return 0;
692 }
693
694
695
696 cli ();
697 old_wbuf = ppp->wbuf;
698 old_rbuf = ppp->rbuf;
699 old_cbuf = ppp->cbuf;
700 old_tbuf = ppp->tbuf;
701
702 ppp->wbuf = new_wbuf;
703 ppp->rbuf = new_rbuf;
704 ppp->cbuf = new_cbuf;
705 ppp->tbuf = new_tbuf;
706
707 ppp->rbuf->size -= 80;
708
709 dev->mem_start = (unsigned long) buf_base (new_wbuf);
710 dev->mem_end = (unsigned long) (dev->mem_start + mtu);
711 dev->rmem_start = (unsigned long) buf_base (new_rbuf);
712 dev->rmem_end = (unsigned long) (dev->rmem_start + mru);
713
714
715
716 ppp->toss = 0xE0;
717 ppp->escape = 0;
718
719 dev->mtu =
720 ppp->mtu = new_mtu;
721 ppp->mru = new_mru;
722
723 ppp->s1buf = NULL;
724 ppp->s2buf = NULL;
725 ppp->xbuf = NULL;
726
727 ppp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
728 ppp->flags &= ~SC_XMIT_BUSY;
729
730 sti ();
731
732
733
734 ppp_free_buf (old_rbuf);
735 ppp_free_buf (old_wbuf);
736 ppp_free_buf (old_cbuf);
737 ppp_free_buf (old_tbuf);
738 return 1;
739 }
740
741
742
743
744
745 static void
746 ppp_ccp_closed (struct ppp *ppp)
747 {
748 if (ppp->sc_xc_state) {
749 (*ppp->sc_xcomp->comp_free) (ppp->sc_xc_state);
750 ppp->sc_xc_state = NULL;
751 }
752
753 if (ppp->sc_rc_state) {
754 (*ppp->sc_rcomp->decomp_free) (ppp->sc_rc_state);
755 ppp->sc_rc_state = NULL;
756 }
757 }
758
759
760
761
762
763
764
765
766 static void
767 ppp_release (struct ppp *ppp)
768 {
769 struct tty_struct *tty;
770 struct device *dev;
771
772 tty = ppp2tty (ppp);
773 dev = ppp2dev (ppp);
774
775 ppp_ccp_closed (ppp);
776
777 if (tty != NULL && tty->disc_data == ppp)
778 tty->disc_data = NULL;
779
780 if (dev && dev->flags & IFF_UP) {
781 dev_close (dev);
782 dev->flags = 0;
783 }
784
785 ppp_free_buf (ppp->rbuf);
786 ppp_free_buf (ppp->wbuf);
787 ppp_free_buf (ppp->cbuf);
788 ppp_free_buf (ppp->ubuf);
789 ppp_free_buf (ppp->tbuf);
790
791 ppp->rbuf =
792 ppp->wbuf =
793 ppp->cbuf =
794 ppp->tbuf =
795 ppp->xbuf =
796 ppp->s1buf =
797 ppp->s2buf =
798 ppp->ubuf = NULL;
799
800 if (ppp->slcomp) {
801 slhc_free (ppp->slcomp);
802 ppp->slcomp = NULL;
803 }
804
805 ppp->inuse = 0;
806 ppp->tty = NULL;
807 }
808
809
810
811
812
813
814
815 static void
816 ppp_tty_close (struct tty_struct *tty)
817 {
818 struct ppp *ppp = tty2ppp (tty);
819
820 if (ppp != NULL) {
821 if (ppp->magic != PPP_MAGIC) {
822 if (ppp->flags & SC_DEBUG)
823 printk (KERN_WARNING
824 "ppp: trying to close unopened tty!\n");
825 } else {
826 CHECK_PPP_VOID();
827 if (ppp->flags & SC_DEBUG)
828 printk (KERN_INFO "ppp: channel %s closing.\n",
829 ppp2dev(ppp) -> name);
830 ppp_release (ppp);
831 MOD_DEC_USE_COUNT;
832 }
833 }
834 }
835
836
837
838
839
840
841
842 static int
843 ppp_tty_open (struct tty_struct *tty)
844 {
845 struct ppp *ppp = tty2ppp (tty);
846
847
848
849 if (ppp) {
850 if (ppp->flags & SC_DEBUG)
851 printk (KERN_ERR
852 "ppp_tty_open: gack! tty already associated to %s!\n",
853 ppp->magic == PPP_MAGIC ? ppp2dev(ppp)->name
854 : "unknown");
855 return -EEXIST;
856 }
857
858
859
860 ppp = ppp_alloc();
861 if (ppp == NULL) {
862 if (ppp->flags & SC_DEBUG)
863 printk (KERN_ERR
864 "ppp_tty_open: couldn't allocate ppp channel\n");
865 return -ENFILE;
866 }
867
868
869
870 ppp_init_ctrl_blk (ppp);
871 ppp->tty = tty;
872 tty->disc_data = ppp;
873
874
875
876 if (tty->ldisc.flush_buffer)
877 tty->ldisc.flush_buffer (tty);
878
879 if (tty->driver.flush_buffer)
880 tty->driver.flush_buffer (tty);
881
882
883
884 ppp->slcomp = slhc_init (16, 16);
885 if (ppp->slcomp == NULL) {
886 if (ppp->flags & SC_DEBUG)
887 printk (KERN_ERR
888 "ppp_tty_open: no space for compression buffers!\n");
889 ppp_release (ppp);
890 return -ENOMEM;
891 }
892
893
894
895 if (ppp_changedmtu (ppp, ppp2dev(ppp)->mtu, ppp->mru) == 0) {
896 ppp_release (ppp);
897 return -ENOMEM;
898 }
899
900
901
902 ppp->ubuf = ppp_alloc_buf (RBUFSIZE, BUFFER_TYPE_TTY_RD);
903 if (ppp->ubuf == NULL) {
904 if (ppp->flags & SC_DEBUG)
905 printk (KERN_ERR
906 "ppp_tty_open: no space for user receive buffer\n");
907 ppp_release (ppp);
908 return -ENOMEM;
909 }
910
911 if (ppp->flags & SC_DEBUG)
912 printk (KERN_INFO "ppp: channel %s open\n",
913 ppp2dev(ppp)->name);
914
915 MOD_INC_USE_COUNT;
916 return (ppp->line);
917 }
918
919
920
921
922
923
924
925
926
927
928
929
930 static void
931 ppp_tty_wakeup_code (struct ppp *ppp, struct tty_struct *tty,
932 struct ppp_buffer *xbuf)
933 {
934 register int count, actual;
935
936
937
938 cli ();
939 if (ppp->flags & SC_XMIT_BUSY) {
940 sti ();
941 return;
942 }
943 ppp->flags |= SC_XMIT_BUSY;
944 sti ();
945
946
947
948 count = xbuf->count - xbuf->tail;
949 actual = tty->driver.write (tty, 0,
950 buf_base (xbuf) + xbuf->tail, count);
951
952
953
954
955 if (actual < 0) {
956 ppp->stats.ppp_oerrors++;
957 actual = count;
958 } else
959 ppp->bytes_sent += actual;
960
961
962
963 xbuf->tail += actual;
964 if (actual == count) {
965 xbuf = NULL;
966 ppp->flags &= ~SC_XMIT_BUSY;
967
968
969
970 xbuf = ppp->xbuf;
971 if (xbuf != NULL) {
972 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
973 xbuf->locked = 0;
974 ppp->xbuf = NULL;
975
976
977
978
979 if (ppp2dev (ppp) -> flags & IFF_UP) {
980 if (xbuf->type == BUFFER_TYPE_DEV_WR)
981 ppp2dev (ppp)->tbusy = 0;
982 mark_bh (NET_BH);
983 }
984
985
986
987 wake_up_interruptible (&ppp->write_wait);
988
989
990
991 cli();
992 xbuf = ppp->s1buf;
993 ppp->s1buf = NULL;
994 if (xbuf == NULL) {
995 xbuf = ppp->s2buf;
996 ppp->s2buf = NULL;
997 }
998 sti();
999
1000
1001
1002 if (xbuf != NULL) {
1003 ppp->flags &= ~SC_XMIT_BUSY;
1004 ppp_kick_tty (ppp, xbuf);
1005 return;
1006 }
1007 }
1008 }
1009
1010
1011
1012 ppp->flags &= ~SC_XMIT_BUSY;
1013 }
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 static void
1025 ppp_tty_wakeup (struct tty_struct *tty)
1026 {
1027 struct ppp_buffer *xbuf;
1028 struct ppp *ppp = tty2ppp (tty);
1029
1030 if (!ppp)
1031 return;
1032
1033 if (ppp->magic != PPP_MAGIC)
1034 return;
1035
1036
1037
1038
1039 xbuf = ppp->xbuf;
1040 if (xbuf == NULL)
1041 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
1042 else
1043 ppp_tty_wakeup_code (ppp, tty, xbuf);
1044 }
1045
1046
1047
1048
1049
1050
1051
1052 static void
1053 ppp_kick_tty (struct ppp *ppp, struct ppp_buffer *xbuf)
1054 {
1055 register int flags;
1056
1057
1058
1059 save_flags (flags);
1060 cli ();
1061
1062
1063
1064 xbuf->locked = 1;
1065 xbuf->tail = 0;
1066
1067
1068
1069
1070 if (ppp->xbuf != NULL) {
1071 if (xbuf->type == BUFFER_TYPE_TTY_WR)
1072 ppp->s1buf = xbuf;
1073 else
1074 ppp->s2buf = xbuf;
1075 restore_flags (flags);
1076 return;
1077 }
1078
1079
1080
1081 ppp->flags &= ~SC_XMIT_BUSY;
1082 ppp->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
1083 ppp->xbuf = xbuf;
1084 restore_flags (flags);
1085
1086
1087
1088 ppp_tty_wakeup_code (ppp, ppp2tty (ppp), xbuf);
1089 }
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105 static int
1106 ppp_tty_room (struct tty_struct *tty)
1107 {
1108 return 65536;
1109 }
1110
1111
1112
1113
1114
1115 static void
1116 ppp_tty_receive (struct tty_struct *tty, const u_char * data,
1117 char *flags, int count)
1118 {
1119 register struct ppp *ppp = tty2ppp (tty);
1120 register struct ppp_buffer *buf = NULL;
1121 u_char chr;
1122
1123
1124
1125 if (ppp != NULL)
1126 buf = ppp->rbuf;
1127
1128 if (buf == NULL)
1129 return;
1130
1131
1132
1133
1134 if (ppp->magic != PPP_MAGIC) {
1135 if (ppp->flags & SC_DEBUG)
1136 printk (KERN_DEBUG
1137 "PPP: handler called but couldn't find "
1138 "PPP struct.\n");
1139 return;
1140 }
1141 CHECK_PPP_VOID ();
1142
1143
1144
1145 if (ppp->flags & SC_LOG_RAWIN)
1146 ppp_print_buffer ("receive buffer", data, count);
1147
1148
1149
1150
1151 while (count-- > 0) {
1152 ppp->bytes_rcvd++;
1153 chr = *data++;
1154 if (flags) {
1155 if (*flags && ppp->toss == 0)
1156 ppp->toss = *flags;
1157 ++flags;
1158 }
1159
1160
1161
1162
1163
1164
1165
1166
1167 #ifdef CHECK_CHARACTERS
1168 if (chr & 0x80)
1169 ppp->flags |= SC_RCV_B7_1;
1170 else
1171 ppp->flags |= SC_RCV_B7_0;
1172
1173 if (paritytab[chr >> 5] & (1 << (chr & 0x1F)))
1174 ppp->flags |= SC_RCV_ODDP;
1175 else
1176 ppp->flags |= SC_RCV_EVNP;
1177 #endif
1178
1179
1180
1181
1182 switch (chr) {
1183 case PPP_ESCAPE:
1184 ppp->escape = PPP_TRANS;
1185 break;
1186
1187
1188
1189
1190
1191 case PPP_FLAG:
1192 ppp->stats.ppp_ibytes += ppp->rbuf->count;
1193 if (ppp->escape)
1194 ppp->toss |= 0x80;
1195
1196
1197
1198
1199 if ((ppp->toss & 0x80) != 0 ||
1200 ppp_doframe (ppp) == 0) {
1201 slhc_toss (ppp->slcomp);
1202 }
1203
1204
1205
1206 buf->count = 0;
1207 buf->fcs = PPP_INITFCS;
1208 ppp->escape = 0;
1209 ppp->toss = 0;
1210 break;
1211
1212
1213
1214
1215 default:
1216 if (in_rmap (ppp, chr))
1217 break;
1218
1219
1220
1221
1222 chr ^= ppp->escape;
1223 ppp->escape = 0;
1224
1225 if (ppp->toss != 0)
1226 break;
1227
1228
1229
1230
1231 if (buf->count < buf->size) {
1232 buf_base (buf)[buf->count++] = chr;
1233 buf->fcs = PPP_FCS (buf->fcs, chr);
1234 break;
1235 }
1236
1237
1238
1239
1240 ppp->stats.ppp_ierrors++;
1241 ppp->toss |= 0xC0;
1242 break;
1243 }
1244 }
1245 }
1246
1247
1248
1249
1250
1251 static int
1252 ppp_rcv_rx (struct ppp *ppp, unsigned short proto, u_char * data, int count)
1253 {
1254 sk_buff *skb = dev_alloc_skb (count);
1255
1256
1257
1258 if (skb == NULL) {
1259 if (ppp->flags & SC_DEBUG)
1260 printk (KERN_ERR
1261 "ppp_do_ip: packet dropped on %s (no memory)!\n",
1262 ppp2dev (ppp)->name);
1263 return 0;
1264 }
1265
1266
1267
1268 skb->dev = ppp2dev (ppp);
1269 #if USE_SKB_PROTOCOL == 0
1270 skb->len = count;
1271 #else
1272 skb->protocol = proto;
1273 skb->mac.raw = skb_data(skb);
1274 #endif
1275 memcpy (skb_put(skb,count), data, count);
1276
1277
1278
1279 skb->free = 1;
1280 ppp->ddinfo.recv_idle = jiffies;
1281 netif_rx (skb);
1282 return 1;
1283 }
1284
1285
1286
1287
1288
1289 static int
1290 rcv_proto_ip (struct ppp *ppp, unsigned short proto, u_char * data, int count)
1291 {
1292 if (ppp2dev (ppp)->flags & IFF_UP) {
1293 if (count > 0)
1294 return ppp_rcv_rx (ppp, htons (ETH_P_IP), data, count);
1295 }
1296 return 0;
1297 }
1298
1299
1300
1301
1302
1303 static int
1304 rcv_proto_ipx (struct ppp *ppp, unsigned short proto, u_char * data, int count)
1305 {
1306 #ifdef NEW_SKBUFF
1307 if (ppp2dev (ppp)->flags & IFF_UP) {
1308 if (count > 0)
1309 return ppp_rcv_rx (ppp, htons (ETH_P_IPX), data, count);
1310 } else
1311 #endif
1312 return 0;
1313 }
1314
1315
1316
1317
1318
1319 static int
1320 rcv_proto_vjc_comp (struct ppp *ppp, unsigned short proto,
1321 u_char *data, int count)
1322 {
1323 if ((ppp->flags & SC_REJ_COMP_TCP) == 0) {
1324 int new_count = slhc_uncompress (ppp->slcomp, data, count);
1325 if (new_count >= 0) {
1326 return rcv_proto_ip (ppp, PPP_IP, data, new_count);
1327 }
1328 if (ppp->flags & SC_DEBUG)
1329 printk (KERN_NOTICE
1330 "ppp: error in VJ decompression\n");
1331 }
1332 return 0;
1333 }
1334
1335
1336
1337
1338
1339 static int
1340 rcv_proto_vjc_uncomp (struct ppp *ppp, unsigned short proto,
1341 u_char *data, int count)
1342 {
1343 if ((ppp->flags & SC_REJ_COMP_TCP) == 0) {
1344 if (slhc_remember (ppp->slcomp, data, count) > 0) {
1345 return rcv_proto_ip (ppp, PPP_IP, data, count);
1346 }
1347 if (ppp->flags & SC_DEBUG)
1348 printk (KERN_NOTICE
1349 "ppp: error in VJ memorizing\n");
1350 }
1351 return 0;
1352 }
1353
1354
1355
1356
1357
1358 static int
1359 rcv_proto_unknown (struct ppp *ppp, unsigned short proto,
1360 u_char *data, int len)
1361 {
1362 int totlen;
1363 register int current_idx;
1364
1365 #define PUTC(c) \
1366 { \
1367 buf_base (ppp->ubuf) [current_idx++] = (u_char) (c); \
1368 current_idx &= ppp->ubuf->size; \
1369 if (current_idx == ppp->ubuf->tail) \
1370 goto failure; \
1371 }
1372
1373
1374
1375
1376
1377 if (set_bit (0, &ppp->ubuf->locked)) {
1378 if (ppp->flags & SC_DEBUG)
1379 printk (KERN_DEBUG
1380 "ppp_us_queue: can't get lock\n");
1381 } else {
1382 current_idx = ppp->ubuf->head;
1383
1384
1385
1386 totlen = len + 2;
1387 PUTC (totlen >> 8);
1388 PUTC (totlen);
1389
1390 PUTC (proto >> 8);
1391 PUTC (proto);
1392
1393 totlen -= 2;
1394 while (totlen-- > 0) {
1395 PUTC (*data++);
1396 }
1397 #undef PUTC
1398
1399
1400
1401
1402 ppp->ubuf->head = current_idx;
1403
1404 clear_bit (0, &ppp->ubuf->locked);
1405 wake_up_interruptible (&ppp->read_wait);
1406 if (ppp->tty->fasync != NULL)
1407 kill_fasync (ppp->tty->fasync, SIGIO);
1408
1409 if (ppp->flags & SC_DEBUG)
1410 printk (KERN_INFO
1411 "ppp: successfully queued %d bytes, flags = %x\n",
1412 len + 2, ppp->flags);
1413
1414 return 1;
1415
1416
1417
1418 failure:
1419 clear_bit (0, &ppp->ubuf->locked);
1420 if (ppp->flags & SC_DEBUG)
1421 printk (KERN_INFO
1422 "ppp_us_queue: ran out of buffer space.\n");
1423 }
1424
1425
1426
1427 if (ppp->flags & SC_DEBUG)
1428 printk (KERN_WARNING
1429 "ppp: dropping packet on the floor.\n");
1430 slhc_toss (ppp->slcomp);
1431 return 0;
1432 }
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442 static void ppp_proto_ccp (struct ppp *ppp, u_char *dp, int len, int rcvd)
1443 {
1444 int slen = CCP_LENGTH(dp);
1445 u_char *opt = dp + CCP_HDRLEN;
1446 int opt_len = slen - CCP_HDRLEN;
1447
1448 if (slen > len)
1449 return;
1450
1451 switch (CCP_CODE(dp)) {
1452 case CCP_CONFREQ:
1453 case CCP_TERMREQ:
1454 case CCP_TERMACK:
1455
1456
1457
1458 if (ppp->flags & SC_CCP_UP) {
1459 ppp->flags &= ~(SC_CCP_UP |
1460 SC_COMP_RUN |
1461 SC_DECOMP_RUN);
1462 }
1463 break;
1464
1465 case CCP_CONFACK:
1466 if ((ppp->flags & SC_CCP_OPEN) == 0)
1467 break;
1468 if (ppp->flags & SC_CCP_UP)
1469 break;
1470 if (slen < (CCP_HDRLEN + CCP_OPT_MINLEN))
1471 break;
1472 if (slen < (CCP_OPT_LENGTH (opt) + CCP_HDRLEN))
1473 break;
1474
1475
1476
1477 if (!rcvd) {
1478 if (ppp->sc_xc_state == NULL)
1479 break;
1480
1481 if ((*ppp->sc_xcomp->comp_init)
1482 (ppp->sc_xc_state,
1483 opt,
1484 opt_len,
1485 ppp2dev (ppp)->base_addr,
1486 0,
1487 ppp->flags & SC_DEBUG))
1488 ppp->flags |= SC_COMP_RUN;
1489 break;
1490 }
1491
1492
1493
1494 if (ppp->sc_rc_state == NULL)
1495 break;
1496
1497 if ((*ppp->sc_rcomp->decomp_init)
1498 (ppp->sc_rc_state,
1499 opt,
1500 opt_len,
1501 ppp2dev (ppp)->base_addr,
1502 0,
1503 ppp->mru,
1504 ppp->flags & SC_DEBUG)) {
1505 ppp->flags |= SC_DECOMP_RUN;
1506 ppp->flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
1507 }
1508 break;
1509
1510
1511
1512 case CCP_RESETACK:
1513 if ((ppp->flags & SC_CCP_UP) == 0)
1514 break;
1515
1516 if (!rcvd) {
1517 if (ppp->sc_xc_state && (ppp->flags & SC_COMP_RUN))
1518 (*ppp->sc_xcomp->comp_reset)(ppp->sc_xc_state);
1519 } else {
1520 if (ppp->sc_rc_state && (ppp->flags & SC_DECOMP_RUN)) {
1521 (*ppp->sc_rcomp->decomp_reset)(ppp->sc_rc_state);
1522 ppp->flags &= ~SC_DC_ERROR;
1523 }
1524 }
1525 break;
1526 }
1527 }
1528
1529 static int
1530 rcv_proto_ccp (struct ppp *ppp, unsigned short proto, u_char *dp, int len)
1531 {
1532 ppp_proto_ccp (ppp, dp, len, 1);
1533 return rcv_proto_unknown (ppp, proto, dp, len);
1534 }
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 static int
1545 rcv_proto_lqr (struct ppp *ppp, unsigned short proto, u_char * data, int len)
1546 {
1547 #if 0
1548 register u_char *p;
1549 if (len > 8) {
1550 if (len < 48)
1551 memset (&data [len], '\0', 48 - len);
1552
1553
1554
1555 p = &data [48];
1556 p = store_long (p, ++ppp->stats.ppp_ilqrs);
1557 p = store_long (p, ppp->stats.ppp_ipackets);
1558 p = store_long (p, ppp->stats.ppp_discards);
1559 p = store_long (p, ppp->stats.ppp_ierrors);
1560 p = store_long (p, ppp->stats.ppp_ioctects + len);
1561
1562 len = 68;
1563 }
1564 #endif
1565
1566
1567
1568 return rcv_proto_unknown (ppp, proto, data, len);
1569 }
1570
1571
1572
1573
1574 static void ppp_doframe_lower (struct ppp *ppp, u_char *data, int count)
1575 {
1576 u_short proto = PPP_PROTOCOL (data);
1577 ppp_proto_type *proto_ptr;
1578
1579
1580
1581 if (count <= 4)
1582 return;
1583
1584
1585
1586 ++ppp->stats.ppp_ipackets;
1587 if (ppp->flags & SC_LOG_INPKT)
1588 ppp_print_buffer ("receive frame", data, count);
1589
1590
1591
1592
1593 proto_ptr = proto_list;
1594 while (proto_ptr->proto != 0 && proto_ptr->proto != proto)
1595 ++proto_ptr;
1596
1597
1598
1599 if ((*proto_ptr->func) (ppp, proto,
1600 &data[PPP_HARD_HDR_LEN],
1601 count - PPP_HARD_HDR_LEN))
1602 ppp->stats.ppp_ioctects += count;
1603 else
1604 ++ppp->stats.ppp_discards;
1605 }
1606
1607
1608
1609
1610 static int
1611 ppp_doframe (struct ppp *ppp)
1612 {
1613 u_char *data = buf_base (ppp->rbuf);
1614 int count = ppp->rbuf->count;
1615 int addr, ctrl, proto;
1616 int new_count;
1617 u_char *new_data;
1618
1619
1620
1621
1622 if (ppp->toss) {
1623 if (ppp->flags & SC_DEBUG)
1624 printk (KERN_WARNING
1625 "ppp_toss: tossing frame, reason = %d\n",
1626 ppp->toss);
1627 ppp->stats.ppp_ierrors++;
1628 return 0;
1629 }
1630
1631
1632
1633
1634 if (count == 0)
1635 return 1;
1636
1637
1638
1639 if (count < PPP_HARD_HDR_LEN) {
1640 if (ppp->flags & SC_DEBUG)
1641 printk (KERN_WARNING
1642 "ppp: got runt ppp frame, %d chars\n", count);
1643 slhc_toss (ppp->slcomp);
1644 ppp->stats.ppp_ierrors++;
1645 return 1;
1646 }
1647
1648
1649
1650
1651 if (ppp->rbuf->fcs != PPP_GOODFCS) {
1652 if (ppp->flags & SC_DEBUG)
1653 printk (KERN_WARNING
1654 "ppp: frame with bad fcs, excess = %x\n",
1655 ppp->rbuf->fcs ^ PPP_GOODFCS);
1656 ppp->stats.ppp_ierrors++;
1657 return 0;
1658 }
1659 count -= 2;
1660
1661
1662
1663 addr = PPP_ALLSTATIONS;
1664 ctrl = PPP_UI;
1665
1666 if ((data[0] == PPP_ALLSTATIONS) && (data[1] == PPP_UI)) {
1667 data += 2;
1668 count -= 2;
1669 }
1670
1671
1672
1673 proto = (u_short) *data++;
1674 if ((proto & 1) == 0) {
1675 proto = (proto << 8) | (u_short) *data++;
1676 --count;
1677 }
1678
1679
1680
1681
1682
1683 *(--data) = proto;
1684 *(--data) = proto >> 8;
1685 *(--data) = ctrl;
1686 *(--data) = addr;
1687 count += 3;
1688
1689
1690
1691 if ((ppp->sc_rc_state != (void *) 0) &&
1692 (ppp->flags & SC_DECOMP_RUN) &&
1693 ((ppp->flags & (SC_DC_FERROR | SC_DC_ERROR)) == 0)) {
1694 if (proto == PPP_COMP) {
1695
1696
1697
1698 new_data = kmalloc (ppp->mru + 4, GFP_ATOMIC);
1699 if (new_data == NULL) {
1700 if (ppp->flags & SC_DEBUG)
1701 printk (KERN_ERR
1702 "ppp_doframe: no memory\n");
1703 slhc_toss (ppp->slcomp);
1704 (*ppp->sc_rcomp->incomp) (ppp->sc_rc_state,
1705 data,
1706 count);
1707 return 1;
1708 }
1709
1710
1711
1712 new_count = bsd_decompress (ppp->sc_rc_state,
1713 data,
1714 count,
1715 new_data,
1716 ppp->mru + 4);
1717 switch (new_count) {
1718 default:
1719 ppp_doframe_lower (ppp, new_data, new_count);
1720 kfree (new_data);
1721 return 1;
1722
1723 case DECOMP_OK:
1724 break;
1725
1726 case DECOMP_ERROR:
1727 ppp->flags |= SC_DC_ERROR;
1728 break;
1729
1730 case DECOMP_FATALERROR:
1731 ppp->flags |= SC_DC_FERROR;
1732 break;
1733 }
1734
1735
1736
1737 if (ppp->flags & SC_DEBUG)
1738 printk (KERN_ERR
1739 "ppp_proto_comp: "
1740 "decompress err %d\n", new_count);
1741 kfree (new_data);
1742 slhc_toss (ppp->slcomp);
1743 return 1;
1744 }
1745
1746
1747
1748
1749 (*ppp->sc_rcomp->incomp) (ppp->sc_rc_state,
1750 data,
1751 count);
1752 }
1753
1754
1755
1756 ppp_doframe_lower (ppp, data, count);
1757 return 1;
1758 }
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772 static int
1773 ppp_tty_read (struct tty_struct *tty, struct file *file, u_char * buf,
1774 unsigned int nr)
1775 {
1776 struct ppp *ppp = tty2ppp (tty);
1777 u_char c;
1778 int len, indx;
1779
1780 #define GETC(c) \
1781 { \
1782 c = buf_base (ppp->ubuf) [ppp->ubuf->tail++]; \
1783 ppp->ubuf->tail &= ppp->ubuf->size; \
1784 }
1785
1786
1787
1788
1789 if (!ppp)
1790 return -EIO;
1791
1792 if (ppp->magic != PPP_MAGIC)
1793 return -EIO;
1794
1795 CHECK_PPP (-ENXIO);
1796
1797 if (ppp->flags & SC_DEBUG)
1798 printk (KERN_DEBUG
1799 "ppp_tty_read: called buf=%p nr=%u\n",
1800 buf, nr);
1801
1802
1803
1804 for (;;) {
1805 ppp = tty2ppp (tty);
1806 if (!ppp || ppp->magic != PPP_MAGIC || !ppp->inuse)
1807 return 0;
1808
1809 if (set_bit (0, &ppp->ubuf->locked) != 0) {
1810 if (ppp->flags & SC_DEBUG)
1811 printk (KERN_DEBUG
1812 "ppp_tty_read: sleeping(ubuf)\n");
1813
1814 current->timeout = 0;
1815 current->state = TASK_INTERRUPTIBLE;
1816 schedule ();
1817
1818 if (current->signal & ~current->blocked)
1819 return -EINTR;
1820 continue;
1821 }
1822
1823
1824
1825
1826 indx = verify_area (VERIFY_WRITE, buf, nr);
1827 if (indx != 0)
1828 return (indx);
1829
1830
1831
1832 if (ppp->ubuf->head == ppp->ubuf->tail)
1833 len = 0;
1834 else {
1835 GETC (c);
1836 len = c << 8;
1837 GETC (c);
1838 len += c;
1839 }
1840
1841
1842
1843 if (len == 0) {
1844
1845 clear_bit (0, &ppp->ubuf->locked);
1846 if (file->f_flags & O_NONBLOCK) {
1847 if (ppp->flags & SC_DEBUG)
1848 printk (KERN_DEBUG
1849 "ppp_tty_read: no data "
1850 "(EAGAIN)\n");
1851 return -EAGAIN;
1852 }
1853 current->timeout = 0;
1854
1855 if (ppp->flags & SC_DEBUG)
1856 printk (KERN_DEBUG
1857 "ppp_tty_read: sleeping(read_wait)\n");
1858
1859 interruptible_sleep_on (&ppp->read_wait);
1860 if (current->signal & ~current->blocked)
1861 return -EINTR;
1862 continue;
1863 }
1864
1865
1866
1867 if (ppp->flags & SC_DEBUG)
1868 printk (KERN_DEBUG "ppp_tty_read: len = %d\n", len);
1869
1870
1871
1872
1873 if (len + 2 > nr) {
1874
1875
1876 if (ppp->flags & SC_DEBUG)
1877 printk (KERN_DEBUG
1878 "ppp: read of %u bytes too small for %d "
1879 "frame\n", nr, len + 2);
1880 ppp->ubuf->tail += len;
1881 ppp->ubuf->tail &= ppp->ubuf->size;
1882 clear_bit (0, &ppp->ubuf->locked);
1883 ppp->stats.ppp_ierrors++;
1884 return -EOVERFLOW;
1885 }
1886
1887
1888
1889
1890 indx = verify_area (VERIFY_WRITE, buf, len + 2);
1891 if (indx != 0) {
1892 ppp->ubuf->tail += len;
1893 ppp->ubuf->tail &= ppp->ubuf->size;
1894 clear_bit (0, &ppp->ubuf->locked);
1895 return (indx);
1896 }
1897
1898
1899
1900
1901 put_byte_user (PPP_ALLSTATIONS, buf++);
1902 put_byte_user (PPP_UI, buf++);
1903
1904 indx = len;
1905
1906
1907
1908 while (indx-- > 0) {
1909 GETC (c);
1910 put_byte_user (c, buf);
1911 ++buf;
1912 }
1913
1914
1915
1916 clear_bit (0, &ppp->ubuf->locked);
1917 len += 2;
1918 if (ppp->flags & SC_DEBUG)
1919 printk (KERN_DEBUG
1920 "ppp_tty_read: passing %d bytes up\n", len);
1921 return len;
1922 }
1923 #undef GETC
1924 }
1925
1926
1927
1928
1929
1930 extern inline void
1931 ppp_stuff_char (struct ppp *ppp, register struct ppp_buffer *buf,
1932 register u_char chr)
1933 {
1934
1935
1936
1937 if (ppp->flags & SC_DEBUG) {
1938 if ((buf->count < 0) || (buf->count > 3000))
1939 printk (KERN_DEBUG "ppp_stuff_char: %x %d\n",
1940 (unsigned int) buf->count,
1941 (unsigned int) chr);
1942 }
1943
1944
1945
1946 buf->fcs = PPP_FCS (buf->fcs, chr);
1947 if (in_xmap (ppp, chr)) {
1948 chr ^= PPP_TRANS;
1949 ins_char (buf, PPP_ESCAPE);
1950 }
1951
1952
1953
1954 ins_char (buf, chr);
1955 }
1956
1957
1958
1959
1960
1961
1962 static void
1963 ppp_dev_xmit_lower (struct ppp *ppp, struct ppp_buffer *buf,
1964 u_char *data, int count, int non_ip)
1965 {
1966 unsigned short int write_fcs;
1967 int address, control;
1968 int proto;
1969
1970
1971
1972 buf->count = 0;
1973
1974 if (non_ip || flag_time == 0)
1975 ins_char (buf, PPP_FLAG);
1976 else {
1977 if (jiffies - ppp->last_xmit > flag_time)
1978 ins_char (buf, PPP_FLAG);
1979 }
1980 ppp->last_xmit = jiffies;
1981 buf->fcs = PPP_INITFCS;
1982
1983
1984
1985 address = PPP_ADDRESS (data);
1986 control = PPP_CONTROL (data);
1987 proto = PPP_PROTOCOL (data);
1988
1989 if (address != PPP_ALLSTATIONS ||
1990 control != PPP_UI ||
1991 (ppp->flags & SC_COMP_AC) == 0) {
1992 ppp_stuff_char (ppp, buf, address);
1993 ppp_stuff_char (ppp, buf, control);
1994 }
1995
1996
1997
1998 if ((ppp->flags & SC_COMP_PROT) == 0 || (proto & 0xFF00))
1999 ppp_stuff_char (ppp, buf, proto >> 8);
2000
2001 ppp_stuff_char (ppp, buf, proto);
2002
2003
2004
2005 data += 4;
2006 count -= 4;
2007
2008 while (count-- > 0)
2009 ppp_stuff_char (ppp, buf, *data++);
2010
2011
2012
2013 write_fcs = buf->fcs ^ 0xFFFF;
2014 ppp_stuff_char (ppp, buf, write_fcs);
2015 ppp_stuff_char (ppp, buf, write_fcs >> 8);
2016
2017 if (ppp->flags & SC_DEBUG)
2018 printk (KERN_DEBUG "ppp_dev_xmit_lower: fcs is %hx\n",
2019 write_fcs);
2020
2021
2022
2023 ins_char (buf, PPP_FLAG);
2024
2025
2026
2027 if (ppp->flags & SC_LOG_FLUSH)
2028 ppp_print_buffer ("ppp flush", buf_base (buf),
2029 buf->count);
2030 else {
2031 if (ppp->flags & SC_DEBUG)
2032 printk (KERN_DEBUG
2033 "ppp_dev_xmit: writing %d chars\n",
2034 buf->count);
2035 }
2036
2037
2038
2039 ppp->stats.ppp_obytes += buf->count;
2040 ppp_kick_tty (ppp, buf);
2041 }
2042
2043
2044
2045
2046
2047
2048
2049
2050 static int
2051 ppp_dev_xmit_frame (struct ppp *ppp, struct ppp_buffer *buf,
2052 u_char *data, int count)
2053 {
2054 int proto;
2055 int address, control;
2056 u_char *new_data;
2057 int new_count;
2058
2059
2060
2061 if (ppp->flags & SC_LOG_OUTPKT)
2062 ppp_print_buffer ("write frame", data, count);
2063
2064
2065
2066
2067 proto = PPP_PROTOCOL (data);
2068 address = PPP_ADDRESS (data);
2069 control = PPP_CONTROL (data);
2070
2071 if (((ppp->flags & SC_COMP_RUN) != 0) &&
2072 (ppp->sc_xc_state != (void *) 0) &&
2073 (address == PPP_ALLSTATIONS) &&
2074 (control == PPP_UI) &&
2075 (proto != PPP_LCP) &&
2076 (proto != PPP_CCP)) {
2077 new_data = kmalloc (count, GFP_ATOMIC);
2078 if (new_data == NULL) {
2079 if (ppp->flags & SC_DEBUG)
2080 printk (KERN_ERR
2081 "ppp_dev_xmit_frame: no memory\n");
2082 return 1;
2083 }
2084
2085 new_count = bsd_compress (ppp->sc_xc_state,
2086 data,
2087 new_data,
2088 count,
2089 count);
2090
2091 if (new_count > 0) {
2092 ++ppp->stats.ppp_opackets;
2093 ppp->stats.ppp_ooctects += new_count;
2094
2095 ppp_dev_xmit_lower (ppp, buf, new_data,
2096 new_count, 0);
2097 kfree (new_data);
2098 return 0;
2099 }
2100
2101
2102
2103 kfree (new_data);
2104 }
2105
2106
2107
2108
2109 ++ppp->stats.ppp_opackets;
2110 ppp->stats.ppp_ooctects += count;
2111
2112
2113
2114 ppp_dev_xmit_lower (ppp, buf, data, count, !!(proto & 0xFF00));
2115 return 0;
2116 }
2117
2118
2119
2120
2121
2122 static int
2123 send_revise_frame (register struct ppp *ppp, u_char *data, int len)
2124 {
2125 u_char *p;
2126
2127 switch (PPP_PROTOCOL (data)) {
2128
2129
2130
2131
2132 case PPP_LQR:
2133 len = 48;
2134 p = (u_char *) &data [40];
2135 p = store_long (p, ppp->stats.ppp_opackets + 1);
2136 p = store_long (p, ppp->stats.ppp_ooctects + len);
2137 break;
2138
2139
2140
2141 case PPP_CCP:
2142 ppp_proto_ccp (ppp,
2143 data + PPP_HARD_HDR_LEN,
2144 len - PPP_HARD_HDR_LEN,
2145 0);
2146 break;
2147
2148
2149
2150 default:
2151 break;
2152 }
2153
2154 return len;
2155 }
2156
2157
2158
2159
2160
2161
2162 static int
2163 ppp_tty_write (struct tty_struct *tty, struct file *file, const u_char * data,
2164 unsigned int count)
2165 {
2166 struct ppp *ppp = tty2ppp (tty);
2167 u_char *new_data;
2168 int status;
2169
2170
2171
2172 if (!ppp)
2173 return -EIO;
2174
2175 if (ppp->magic != PPP_MAGIC)
2176 return -EIO;
2177
2178 CHECK_PPP (-ENXIO);
2179
2180
2181
2182 if (count > PPP_MTU) {
2183 if (ppp->flags & SC_DEBUG)
2184 printk (KERN_WARNING
2185 "ppp_tty_write: truncating user packet "
2186 "from %u to mtu %d\n", count, PPP_MTU);
2187 count = PPP_MTU;
2188 }
2189
2190
2191
2192 new_data = kmalloc (count, GFP_KERNEL);
2193 if (new_data == NULL) {
2194 if (ppp->flags & SC_DEBUG)
2195 printk (KERN_ERR
2196 "ppp_tty_write: no memory\n");
2197 return 0;
2198 }
2199
2200
2201
2202
2203 while (lock_buffer (ppp->tbuf) != 0) {
2204 current->timeout = 0;
2205 if (ppp->flags & SC_DEBUG)
2206 printk (KERN_DEBUG "ppp_tty_write: sleeping\n");
2207 interruptible_sleep_on (&ppp->write_wait);
2208
2209 ppp = tty2ppp (tty);
2210 if (!ppp || ppp->magic != PPP_MAGIC || !ppp->inuse) {
2211 kfree (new_data);
2212 return 0;
2213 }
2214
2215 if (current->signal & ~current->blocked) {
2216 kfree (new_data);
2217 return -EINTR;
2218 }
2219 }
2220
2221
2222
2223 status = verify_area (VERIFY_READ, data, count);
2224 if (status != 0) {
2225 kfree (new_data);
2226 ppp->tbuf->locked = 0;
2227 return status;
2228 }
2229
2230 memcpy_fromfs (new_data, data, count);
2231
2232
2233
2234 count = send_revise_frame (ppp, new_data, count);
2235
2236
2237
2238 ppp_dev_xmit_frame (ppp, ppp->tbuf, new_data, count);
2239 kfree (new_data);
2240 return (int) count;
2241 }
2242
2243
2244
2245
2246
2247 static int
2248 ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp)
2249 {
2250 struct compressor *cp;
2251 struct ppp_option_data data;
2252 int error;
2253 int nb;
2254 u_char *ptr;
2255 u_char ccp_option[CCP_MAX_OPTION_LENGTH];
2256
2257
2258
2259 error = verify_area (VERIFY_READ, odp, sizeof (data));
2260 if (error == 0) {
2261 memcpy_fromfs (&data, odp, sizeof (data));
2262 nb = data.length;
2263 ptr = data.ptr;
2264 if ((unsigned long) nb >= (unsigned long)CCP_MAX_OPTION_LENGTH)
2265 nb = CCP_MAX_OPTION_LENGTH;
2266
2267 error = verify_area (VERIFY_READ, ptr, nb);
2268 }
2269
2270 if (error != 0)
2271 return error;
2272
2273 memcpy_fromfs (ccp_option, ptr, nb);
2274
2275 if (ccp_option[1] < 2)
2276 return (-EINVAL);
2277
2278 cp = find_compressor ((int) (unsigned) (unsigned char) ccp_option[0]);
2279 if (cp != (struct compressor *) 0) {
2280
2281
2282
2283
2284 error = 0;
2285 if (data.transmit) {
2286 if (ppp->sc_xc_state != NULL)
2287 (*ppp->sc_xcomp->comp_free)(ppp->sc_xc_state);
2288
2289 ppp->sc_xcomp = cp;
2290 ppp->sc_xc_state = cp->comp_alloc(ccp_option, nb);
2291
2292 if (ppp->sc_xc_state == NULL) {
2293 if (ppp->flags & SC_DEBUG)
2294 printk("ppp%ld: comp_alloc failed\n",
2295 ppp2dev (ppp)->base_addr);
2296 error = -ENOBUFS;
2297 }
2298 ppp->flags &= ~SC_COMP_RUN;
2299 } else {
2300 if (ppp->sc_rc_state != NULL)
2301 (*ppp->sc_rcomp->decomp_free)(ppp->sc_rc_state);
2302 ppp->sc_rcomp = cp;
2303 ppp->sc_rc_state = cp->decomp_alloc(ccp_option, nb);
2304 if (ppp->sc_rc_state == NULL) {
2305 if (ppp->flags & SC_DEBUG)
2306 printk("ppp%ld: decomp_alloc failed\n",
2307 ppp2dev (ppp)->base_addr);
2308 error = ENOBUFS;
2309 }
2310 ppp->flags &= ~SC_DECOMP_RUN;
2311 }
2312 return (error);
2313 }
2314
2315 if (ppp->flags & SC_DEBUG)
2316 printk(KERN_DEBUG "ppp%ld: no compressor for [%x %x %x], %x\n",
2317 ppp2dev (ppp)->base_addr, ccp_option[0], ccp_option[1],
2318 ccp_option[2], nb);
2319 return (-EINVAL);
2320 }
2321
2322
2323
2324
2325
2326 static int
2327 ppp_tty_ioctl (struct tty_struct *tty, struct file *file, unsigned int param2,
2328 unsigned long param3)
2329 {
2330 struct ppp *ppp = tty2ppp (tty);
2331 register int temp_i = 0;
2332 int error;
2333
2334
2335
2336 if (!ppp)
2337 return -EBADF;
2338
2339 if (ppp->magic != PPP_MAGIC)
2340 return -EBADF;
2341
2342 CHECK_PPP (-ENXIO);
2343
2344
2345
2346 if (!suser ())
2347 return -EPERM;
2348
2349
2350
2351 switch (param2) {
2352 case PPPIOCSMRU:
2353 error = verify_area (VERIFY_READ, (void *) param3,
2354 sizeof (temp_i));
2355 if (error == 0) {
2356 temp_i = get_int_user ((int *) param3);
2357 if (ppp->flags & SC_DEBUG)
2358 printk (KERN_INFO
2359 "ppp_tty_ioctl: set mru to %x\n", temp_i);
2360
2361 if (ppp->mru != temp_i)
2362 ppp_changedmtu (ppp, ppp2dev (ppp)->mtu, temp_i);
2363 }
2364 break;
2365
2366
2367
2368 case PPPIOCGFLAGS:
2369 error = verify_area (VERIFY_WRITE, (void *) param3,
2370 sizeof (temp_i));
2371 if (error == 0) {
2372 temp_i = (ppp->flags & SC_MASK);
2373 #ifndef CHECK_CHARACTERS
2374 temp_i |= SC_RCV_B7_1 | SC_RCV_B7_0 |
2375 SC_RCV_ODDP | SC_RCV_EVNP;
2376 #endif
2377 put_long_user ((long) temp_i, param3);
2378 if (ppp->flags & SC_DEBUG)
2379 printk (KERN_DEBUG
2380 "ppp_tty_ioctl: get flags: addr %lx flags "
2381 "%x\n", param3, temp_i);
2382 }
2383 break;
2384
2385
2386
2387 case PPPIOCSFLAGS:
2388 error = verify_area (VERIFY_READ, (void *) param3,
2389 sizeof (temp_i));
2390 if (error == 0) {
2391 temp_i = get_int_user (param3) & SC_MASK;
2392 temp_i |= (ppp->flags & ~SC_MASK);
2393
2394 if ((ppp->flags & SC_CCP_OPEN) &&
2395 (temp_i & SC_CCP_OPEN) == 0)
2396 ppp_ccp_closed (ppp);
2397
2398 if ((ppp->flags | temp_i) & SC_DEBUG)
2399 printk (KERN_INFO
2400 "ppp_tty_ioctl: set flags to %x\n", temp_i);
2401 ppp->flags = temp_i;
2402 }
2403 break;
2404
2405
2406
2407 case PPPIOCSCOMPRESS:
2408 error = ppp_set_compression (ppp,
2409 (struct ppp_option_data *) param3);
2410 break;
2411
2412
2413
2414 case PPPIOCGASYNCMAP:
2415 error = verify_area (VERIFY_WRITE, (void *) param3,
2416 sizeof (temp_i));
2417 if (error == 0) {
2418 put_long_user (ppp->xmit_async_map[0], param3);
2419 if (ppp->flags & SC_DEBUG)
2420 printk (KERN_INFO
2421 "ppp_tty_ioctl: get asyncmap: addr "
2422 "%lx asyncmap %lx\n",
2423 param3,
2424 (unsigned long) ppp->xmit_async_map[0]);
2425 }
2426 break;
2427
2428
2429
2430 case PPPIOCSASYNCMAP:
2431 error = verify_area (VERIFY_READ, (void *) param3,
2432 sizeof (temp_i));
2433 if (error == 0) {
2434 ppp->xmit_async_map[0] = get_long_user (param3);
2435 if (ppp->flags & SC_DEBUG)
2436 printk (KERN_INFO
2437 "ppp_tty_ioctl: set xmit asyncmap %lx\n",
2438 (unsigned long) ppp->xmit_async_map[0]);
2439 }
2440 break;
2441
2442
2443
2444 case PPPIOCSRASYNCMAP:
2445 error = verify_area (VERIFY_READ, (void *) param3,
2446 sizeof (temp_i));
2447 if (error == 0) {
2448 ppp->recv_async_map = get_long_user (param3);
2449 if (ppp->flags & SC_DEBUG)
2450 printk (KERN_INFO
2451 "ppp_tty_ioctl: set rcv asyncmap %lx\n",
2452 (unsigned long) ppp->recv_async_map);
2453 }
2454 break;
2455
2456
2457
2458 case PPPIOCGUNIT:
2459 error = verify_area (VERIFY_WRITE, (void *) param3,
2460 sizeof (temp_i));
2461 if (error == 0) {
2462 put_long_user (ppp2dev (ppp)->base_addr, param3);
2463 if (ppp->flags & SC_DEBUG)
2464 printk (KERN_INFO
2465 "ppp_tty_ioctl: get unit: %ld",
2466 ppp2dev (ppp)->base_addr);
2467 }
2468 break;
2469
2470
2471
2472 case PPPIOCSDEBUG:
2473 error = verify_area (VERIFY_READ, (void *) param3,
2474 sizeof (temp_i));
2475 if (error == 0) {
2476 temp_i = (get_int_user (param3) & 0x1F) << 16;
2477 temp_i |= (ppp->flags & ~0x1F0000);
2478
2479 if ((ppp->flags | temp_i) & SC_DEBUG)
2480 printk (KERN_INFO
2481 "ppp_tty_ioctl: set flags to %x\n", temp_i);
2482 ppp->flags = temp_i;
2483 }
2484 break;
2485
2486
2487
2488 case PPPIOCGDEBUG:
2489 error = verify_area (VERIFY_WRITE, (void *) param3,
2490 sizeof (temp_i));
2491 if (error == 0) {
2492 temp_i = (ppp->flags >> 16) & 0x1F;
2493 put_long_user ((long) temp_i, param3);
2494
2495 if (ppp->flags & SC_DEBUG)
2496 printk (KERN_INFO
2497 "ppp_tty_ioctl: get debug level %d\n",
2498 temp_i);
2499 }
2500 break;
2501
2502
2503
2504 case PPPIOCGIDLE:
2505 error = verify_area (VERIFY_WRITE, (void *) param3,
2506 sizeof (struct ppp_idle));
2507 if (error == 0) {
2508 struct ppp_idle cur_ddinfo;
2509 unsigned long cur_jiffies = jiffies;
2510
2511
2512 cur_ddinfo.xmit_idle = (cur_jiffies - ppp->ddinfo.xmit_idle) / HZ;
2513 cur_ddinfo.recv_idle = (cur_jiffies - ppp->ddinfo.recv_idle) / HZ;
2514 memcpy_tofs ((void *) param3, &cur_ddinfo,
2515 sizeof (cur_ddinfo));
2516 if (ppp->flags & SC_DEBUG)
2517 printk (KERN_INFO
2518 "ppp_tty_ioctl: read demand dial info\n");
2519 }
2520 break;
2521
2522
2523
2524 case PPPIOCGXASYNCMAP:
2525 error = verify_area (VERIFY_WRITE,
2526 (void *) param3,
2527 sizeof (ppp->xmit_async_map));
2528 if (error == 0) {
2529 memcpy_tofs ((void *) param3,
2530 ppp->xmit_async_map,
2531 sizeof (ppp->xmit_async_map));
2532
2533 if (ppp->flags & SC_DEBUG)
2534 printk (KERN_INFO
2535 "ppp_tty_ioctl: get xasyncmap: addr %lx\n",
2536 param3);
2537 }
2538 break;
2539
2540
2541
2542 case PPPIOCSXASYNCMAP:
2543 error = verify_area (VERIFY_READ, (void *) param3,
2544 sizeof (ppp->xmit_async_map));
2545 if (error == 0) {
2546 __u32 temp_tbl[8];
2547
2548 memcpy_fromfs (temp_tbl, (void *) param3,
2549 sizeof (ppp->xmit_async_map));
2550 temp_tbl[1] = 0x00000000;
2551 temp_tbl[2] &= ~0x40000000;
2552 temp_tbl[3] |= 0x60000000;
2553
2554 if ((temp_tbl[2] & temp_tbl[3]) != 0 ||
2555 (temp_tbl[4] & temp_tbl[5]) != 0 ||
2556 (temp_tbl[6] & temp_tbl[7]) != 0)
2557 error = -EINVAL;
2558 else {
2559 memcpy (ppp->xmit_async_map, temp_tbl,
2560 sizeof (ppp->xmit_async_map));
2561
2562 if (ppp->flags & SC_DEBUG)
2563 printk (KERN_INFO
2564 "ppp_tty_ioctl: set xasyncmap\n");
2565 }
2566 }
2567 break;
2568
2569
2570
2571 case PPPIOCSMAXCID:
2572 error = verify_area (VERIFY_READ, (void *) param3,
2573 sizeof (temp_i));
2574 if (error == 0) {
2575 temp_i = get_int_user (param3) + 1;
2576 if (ppp->flags & SC_DEBUG)
2577 printk (KERN_INFO
2578 "ppp_tty_ioctl: set maxcid to %d\n",
2579 temp_i);
2580 if (ppp->slcomp != NULL)
2581 slhc_free (ppp->slcomp);
2582 ppp->slcomp = slhc_init (16, temp_i);
2583
2584 if (ppp->slcomp == NULL) {
2585 if (ppp->flags & SC_DEBUG)
2586 printk (KERN_ERR
2587 "ppp: no space for compression buffers!\n");
2588 ppp_release (ppp);
2589 error = -ENOMEM;
2590 }
2591 }
2592 break;
2593
2594
2595
2596 case TCGETS:
2597 case TCGETA:
2598 error = n_tty_ioctl (tty, file, param2, param3);
2599 break;
2600
2601
2602
2603 default:
2604 if (ppp->flags & SC_DEBUG)
2605 printk (KERN_ERR
2606 "ppp_tty_ioctl: invalid ioctl: %x, addr %lx\n",
2607 param2,
2608 param3);
2609
2610 error = -ENOIOCTLCMD;
2611 break;
2612 }
2613 return error;
2614 }
2615
2616
2617
2618
2619
2620
2621
2622 static int
2623 ppp_tty_select (struct tty_struct *tty, struct inode *inode,
2624 struct file *filp, int sel_type, select_table * wait)
2625 {
2626 struct ppp *ppp = tty2ppp (tty);
2627 int result = 1;
2628
2629
2630
2631 if (!ppp)
2632 return -EBADF;
2633
2634 if (ppp->magic != PPP_MAGIC)
2635 return -EBADF;
2636
2637 CHECK_PPP (0);
2638
2639
2640
2641
2642 switch (sel_type) {
2643 case SEL_IN:
2644 if (set_bit (0, &ppp->ubuf->locked) == 0) {
2645
2646 if (ppp->ubuf->head != ppp->ubuf->tail) {
2647 clear_bit (0, &ppp->ubuf->locked);
2648 break;
2649 }
2650 clear_bit (0, &ppp->ubuf->locked);
2651 }
2652
2653
2654
2655 case SEL_EX:
2656
2657 if (tty->flags & (1 << TTY_SLAVE_CLOSED))
2658 break;
2659
2660
2661 if (tty_hung_up_p (filp))
2662 break;
2663
2664 select_wait (&ppp->read_wait, wait);
2665 result = 0;
2666 break;
2667
2668
2669
2670 case SEL_OUT:
2671 if (ppp->tbuf->locked != 0) {
2672 select_wait (&ppp->write_wait, wait);
2673 result = 0;
2674 }
2675 break;
2676 }
2677 return result;
2678 }
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692 static int
2693 ppp_dev_open (struct device *dev)
2694 {
2695 struct ppp *ppp = dev2ppp (dev);
2696
2697
2698 dev->flags |= IFF_POINTOPOINT;
2699
2700 if (ppp2tty (ppp) == NULL) {
2701 if (ppp->flags & SC_DEBUG)
2702 printk (KERN_ERR
2703 "ppp: %s not connected to a TTY! can't go open!\n",
2704 dev->name);
2705 return -ENXIO;
2706 }
2707
2708 if (ppp->flags & SC_DEBUG)
2709 printk (KERN_INFO
2710 "ppp: channel %s going up for IP packets!\n",
2711 dev->name);
2712
2713 CHECK_PPP (-ENXIO);
2714 return 0;
2715 }
2716
2717
2718
2719
2720
2721 static int
2722 ppp_dev_close (struct device *dev)
2723 {
2724 struct ppp *ppp = dev2ppp (dev);
2725
2726 if (ppp2tty (ppp) == NULL) {
2727 if (ppp->flags & SC_DEBUG)
2728 printk (KERN_ERR
2729 "ppp: %s not connected to a TTY! can't go down!\n",
2730 dev->name);
2731 return -ENXIO;
2732 }
2733
2734
2735
2736
2737 if (ppp->flags & SC_DEBUG)
2738 printk (KERN_INFO
2739 "ppp: channel %s going down for IP packets!\n",
2740 dev->name);
2741 CHECK_PPP (-ENXIO);
2742 return 0;
2743 }
2744
2745
2746
2747
2748
2749 static int
2750 ppp_dev_ioctl_version (struct ppp *ppp, struct ifreq *ifr)
2751 {
2752 int error;
2753 int len;
2754 char *result;
2755
2756
2757
2758 result = (char *) ifr->ifr_ifru.ifru_data;
2759 len = strlen (szVersion) + 1;
2760 error = verify_area (VERIFY_WRITE, result, len);
2761
2762
2763
2764 if (error == 0)
2765 memcpy_tofs (result, szVersion, len);
2766
2767 return error;
2768 }
2769
2770
2771
2772
2773
2774 static int
2775 ppp_dev_ioctl_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev)
2776 {
2777 struct ppp_stats *result, temp;
2778 int error;
2779
2780
2781
2782 result = (struct ppp_stats *) ifr->ifr_ifru.ifru_data;
2783 error = verify_area (VERIFY_WRITE,
2784 result,
2785 sizeof (temp));
2786
2787
2788
2789
2790 memset (&temp, 0, sizeof(temp));
2791 if (error == 0 && dev->flags & IFF_UP) {
2792 memcpy (&temp.p, &ppp->stats, sizeof (struct pppstat));
2793 if (ppp->slcomp != NULL) {
2794 temp.vj.vjs_packets = ppp->slcomp->sls_o_compressed+
2795 ppp->slcomp->sls_o_uncompressed;
2796 temp.vj.vjs_compressed = ppp->slcomp->sls_o_compressed;
2797 temp.vj.vjs_searches = ppp->slcomp->sls_o_searches;
2798 temp.vj.vjs_misses = ppp->slcomp->sls_o_misses;
2799 temp.vj.vjs_errorin = ppp->slcomp->sls_i_error;
2800 temp.vj.vjs_tossed = ppp->slcomp->sls_i_tossed;
2801 temp.vj.vjs_uncompressedin = ppp->slcomp->sls_i_uncompressed;
2802 temp.vj.vjs_compressedin = ppp->slcomp->sls_i_compressed;
2803 }
2804 }
2805
2806
2807
2808 if (error == 0)
2809 memcpy_tofs (result, &temp, sizeof (temp));
2810 return error;
2811 }
2812
2813
2814
2815
2816
2817 static int
2818 ppp_dev_ioctl_comp_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev)
2819 {
2820 struct ppp_comp_stats *result, temp;
2821 int error;
2822
2823
2824
2825 result = (struct ppp_comp_stats *) ifr->ifr_ifru.ifru_data;
2826 error = verify_area (VERIFY_WRITE,
2827 result,
2828 sizeof (temp));
2829
2830
2831
2832 memset (&temp, 0, sizeof(temp));
2833 if (error == 0 && dev->flags & IFF_UP) {
2834 if (ppp->sc_xc_state != NULL)
2835 (*ppp->sc_xcomp->comp_stat) (ppp->sc_xc_state,
2836 &temp.c);
2837
2838 if (ppp->sc_rc_state != NULL)
2839 (*ppp->sc_rcomp->decomp_stat) (ppp->sc_rc_state,
2840 &temp.d);
2841 }
2842
2843
2844
2845 if (error == 0)
2846 memcpy_tofs (result, &temp, sizeof (temp));
2847 return error;
2848 }
2849
2850
2851
2852
2853
2854 static int
2855 ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd)
2856 {
2857 struct ppp *ppp = dev2ppp (dev);
2858 int error;
2859
2860
2861
2862 switch (cmd) {
2863 case SIOCGPPPSTATS:
2864 error = ppp_dev_ioctl_stats (ppp, ifr, dev);
2865 break;
2866
2867 case SIOCGPPPCSTATS:
2868 error = ppp_dev_ioctl_comp_stats (ppp, ifr, dev);
2869 break;
2870
2871 case SIOCGPPPVER:
2872 error = ppp_dev_ioctl_version (ppp, ifr);
2873 break;
2874
2875 default:
2876 error = -EINVAL;
2877 break;
2878 }
2879 return error;
2880 }
2881
2882
2883
2884
2885
2886
2887
2888
2889 static int
2890 ppp_dev_xmit_ip1 (struct device *dev, struct ppp *ppp, u_char *data)
2891 {
2892 int proto = PPP_IP;
2893 int len;
2894 struct ppp_hdr *hdr;
2895 struct tty_struct *tty = ppp2tty (ppp);
2896
2897
2898
2899 len = ((struct iphdr *)data) -> tot_len;
2900 len = ntohs (len);
2901
2902
2903
2904 if (tty == NULL) {
2905 if (ppp->flags & SC_DEBUG)
2906 printk (KERN_ERR
2907 "ppp_dev_xmit: %s not connected to a TTY!\n",
2908 dev->name);
2909 return 0;
2910 }
2911
2912
2913
2914 if (!(dev->flags & IFF_UP)) {
2915 if (ppp->flags & SC_DEBUG)
2916 printk (KERN_WARNING
2917 "ppp_dev_xmit: packet sent on interface %s,"
2918 " which is down for IP\n",
2919 dev->name);
2920 return 0;
2921 }
2922
2923
2924
2925 if (ppp->mtu != ppp2dev (ppp)->mtu) {
2926 ppp_changedmtu (ppp,
2927 ppp2dev (ppp)->mtu,
2928 ppp->mru);
2929 }
2930
2931
2932
2933
2934 if (lock_buffer (ppp->wbuf) != 0) {
2935 dev->tbusy = 1;
2936 return 1;
2937 }
2938
2939
2940
2941 if (ppp->flags & SC_LOG_OUTPKT)
2942 ppp_print_buffer ("ppp outpkt", data, len);
2943
2944
2945
2946
2947
2948 if (ppp->flags & SC_COMP_TCP) {
2949 len = slhc_compress (ppp->slcomp, data, len,
2950 buf_base (ppp->cbuf) + PPP_HARD_HDR_LEN,
2951 &data,
2952 (ppp->flags & SC_NO_TCP_CCID) == 0);
2953
2954 if (data[0] & SL_TYPE_COMPRESSED_TCP) {
2955 proto = PPP_VJC_COMP;
2956 data[0] ^= SL_TYPE_COMPRESSED_TCP;
2957 } else {
2958 if (data[0] >= SL_TYPE_UNCOMPRESSED_TCP)
2959 proto = PPP_VJC_UNCOMP;
2960 data[0] = (data[0] & 0x0f) | 0x40;
2961 }
2962 }
2963
2964
2965
2966 len += PPP_HARD_HDR_LEN;
2967 hdr = &((struct ppp_hdr *) data)[-1];
2968
2969 hdr->address = PPP_ALLSTATIONS;
2970 hdr->control = PPP_UI;
2971 hdr->protocol[0] = 0;
2972 hdr->protocol[1] = proto;
2973
2974 return ppp_dev_xmit_frame (ppp, ppp->wbuf, (u_char *) hdr, len);
2975 }
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986 static int
2987 ppp_dev_xmit_ip (struct device *dev, struct ppp *ppp, u_char *data)
2988 {
2989 struct ppp_hdr *hdr;
2990 int len;
2991 int answer;
2992
2993 len = ((struct iphdr *)data) -> tot_len;
2994 len = ntohs (len);
2995
2996 hdr = (struct ppp_hdr *) kmalloc (len + sizeof (struct ppp_hdr),
2997 GFP_ATOMIC);
2998
2999 if (hdr == NULL)
3000 answer = 1;
3001 else {
3002 memcpy (&hdr[1], data, len);
3003 answer = ppp_dev_xmit_ip1 (dev, ppp, (u_char *) &hdr[1]);
3004 kfree (hdr);
3005 }
3006
3007 return answer;
3008 }
3009
3010
3011
3012
3013
3014
3015
3016
3017 #ifdef NEW_SKBUFF
3018 static int
3019 ppp_dev_xmit_ipx1 (struct device *dev, struct ppp *ppp,
3020 u_char *data, int len, int proto)
3021 {
3022 struct tty_struct *tty = ppp2tty (ppp);
3023 struct ppp_hdr *hdr;
3024
3025
3026
3027 if (tty == NULL) {
3028 if (ppp->flags & SC_DEBUG)
3029 printk (KERN_ERR
3030 "ppp_dev_xmit: %s not connected to a TTY!\n",
3031 dev->name);
3032 return 0;
3033 }
3034
3035
3036
3037 if (!(dev->flags & IFF_UP)) {
3038 if (ppp->flags & SC_DEBUG)
3039 printk (KERN_WARNING
3040 "ppp_dev_xmit: packet sent on interface %s,"
3041 " which is down\n",
3042 dev->name);
3043 return 0;
3044 }
3045
3046
3047
3048 if (ppp->mtu != ppp2dev (ppp)->mtu) {
3049 ppp_changedmtu (ppp,
3050 ppp2dev (ppp)->mtu,
3051 ppp->mru);
3052 }
3053
3054
3055
3056
3057 if (lock_buffer (ppp->wbuf) != 0) {
3058 dev->tbusy = 1;
3059 return 1;
3060 }
3061
3062
3063
3064 if (ppp->flags & SC_LOG_OUTPKT)
3065 ppp_print_buffer ("ppp outpkt", data, len);
3066
3067
3068
3069 len += PPP_HARD_HDR_LEN;
3070 hdr = &((struct ppp_hdr *) data)[-1];
3071
3072 hdr->address = PPP_ALLSTATIONS;
3073 hdr->control = PPP_UI;
3074 hdr->protocol[0] = proto >> 8;
3075 hdr->protocol[1] = proto;
3076
3077 return ppp_dev_xmit_frame (ppp, ppp->wbuf, (u_char *) hdr, len);
3078 }
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089 static int
3090 ppp_dev_xmit_ipx (struct device *dev, struct ppp *ppp,
3091 u_char *data, int len, int proto)
3092 {
3093 struct ppp_hdr *hdr;
3094 int answer;
3095
3096 hdr = (struct ppp_hdr *) kmalloc (len + sizeof (struct ppp_hdr),
3097 GFP_ATOMIC);
3098 if (hdr == NULL)
3099 answer = 1;
3100 else {
3101 memcpy (&hdr[1], data, len);
3102 answer = ppp_dev_xmit_ipx1 (dev, ppp, (u_char *) &hdr[1],
3103 len, proto);
3104 kfree (hdr);
3105 }
3106
3107 return answer;
3108 }
3109 #endif
3110
3111
3112
3113
3114
3115 static int
3116 ppp_dev_xmit (sk_buff *skb, struct device *dev)
3117 {
3118 int answer, len;
3119 u_char *data;
3120 struct ppp *ppp = dev2ppp (dev);
3121 struct tty_struct *tty = ppp2tty (ppp);
3122
3123
3124
3125 if (skb == NULL) {
3126 if (ppp->flags & SC_DEBUG)
3127 printk (KERN_WARNING "ppp_dev_xmit: null packet!\n");
3128 return 0;
3129 }
3130
3131
3132
3133 if (!ppp->inuse) {
3134 dev_kfree_skb (skb, FREE_WRITE);
3135 dev_close (dev);
3136 return 0;
3137 }
3138
3139
3140
3141 if (ppp->flags & SC_DEBUG)
3142 printk (KERN_DEBUG "ppp_dev_xmit [%s]: skb %p\n",
3143 dev->name, skb);
3144
3145
3146
3147 if (tty == NULL) {
3148 if (ppp->flags & SC_DEBUG)
3149 printk (KERN_ERR
3150 "ppp_dev_xmit: %s not connected to a TTY!\n",
3151 dev->name);
3152 dev_kfree_skb (skb, FREE_WRITE);
3153 return 0;
3154 }
3155
3156
3157
3158 len = skb->len;
3159 data = skb_data(skb);
3160
3161
3162
3163
3164
3165 #ifdef NEW_SKBUFF
3166 switch (skb->protocol) {
3167 case htons (ETH_P_IPX):
3168 answer = ppp_dev_xmit_ipx (dev, ppp, data, len, PPP_IPX);
3169 break;
3170
3171 case htons (ETH_P_IP):
3172 answer = ppp_dev_xmit_ip (dev, ppp, data);
3173 break;
3174
3175 default:
3176 dev_kfree_skb (skb, FREE_WRITE);
3177 return 0;
3178 }
3179 #else
3180 answer = ppp_dev_xmit_ip (dev, ppp, data);
3181 #endif
3182
3183
3184
3185
3186 if (answer == 0) {
3187 dev_kfree_skb (skb, FREE_WRITE);
3188 ppp->ddinfo.xmit_idle = jiffies;
3189 }
3190 return answer;
3191 }
3192
3193
3194
3195
3196
3197 static struct enet_statistics *
3198 ppp_dev_stats (struct device *dev)
3199 {
3200 struct ppp *ppp = dev2ppp (dev);
3201 static struct enet_statistics ppp_stats;
3202
3203 ppp_stats.rx_packets = ppp->stats.ppp_ipackets;
3204 ppp_stats.rx_errors = ppp->stats.ppp_ierrors;
3205 ppp_stats.rx_dropped = ppp->stats.ppp_ierrors;
3206 ppp_stats.rx_fifo_errors = 0;
3207 ppp_stats.rx_length_errors = 0;
3208 ppp_stats.rx_over_errors = 0;
3209 ppp_stats.rx_crc_errors = 0;
3210 ppp_stats.rx_frame_errors = 0;
3211 ppp_stats.tx_packets = ppp->stats.ppp_opackets;
3212 ppp_stats.tx_errors = ppp->stats.ppp_oerrors;
3213 ppp_stats.tx_dropped = 0;
3214 ppp_stats.tx_fifo_errors = 0;
3215 ppp_stats.collisions = 0;
3216 ppp_stats.tx_carrier_errors = 0;
3217 ppp_stats.tx_aborted_errors = 0;
3218 ppp_stats.tx_window_errors = 0;
3219 ppp_stats.tx_heartbeat_errors = 0;
3220
3221 if (ppp->flags & SC_DEBUG)
3222 printk (KERN_INFO "ppp_dev_stats called");
3223 return &ppp_stats;
3224 }
3225
3226 #ifdef NEW_SKBUFF
3227
3228
3229
3230
3231
3232
3233 static int ppp_dev_input (struct protocol *self, struct protocol *lower,
3234 sk_buff *skb, void *saddr, void *daddr)
3235 {
3236 return protocol_pass_demultiplex(self, NULL, skb, NULL, NULL);
3237 }
3238
3239 static int ppp_dev_output (struct protocol *self, sk_buff *skb, int type,
3240 int subid, void *saddr, void *daddr, void *opt)
3241 {
3242 if(skb->dev==NULL)
3243 {
3244 printk("ppp_dev_output: No device.\n");
3245 kfree_skb(skb, FREE_WRITE);
3246 return -1;
3247 }
3248 dev_queue_xmit(skb, skb->dev, skb->priority);
3249 return 0;
3250 }
3251
3252 static int ppp_dev_getkey(int protocol, int subid, unsigned char *key)
3253 {
3254 switch (protocol)
3255 {
3256 case htons (ETH_P_IP):
3257 case htons (ETH_P_IPX):
3258 return 0;
3259
3260 default:
3261 break;
3262 }
3263
3264 return -EAFNOSUPPORT;
3265 }
3266
3267 #else
3268
3269 #if USE_SKB_PROTOCOL == 0
3270
3271
3272
3273
3274
3275 static unsigned short
3276 ppp_dev_type (sk_buff *skb, struct device *dev)
3277 {
3278 return (htons (ETH_P_IP));
3279 }
3280 #endif
3281
3282 #if USE_SKB_PROTOCOL == 0
3283 static int ppp_dev_header (unsigned char *buff, struct device *dev,
3284 unsigned short type, void *daddr, void *saddr,
3285 unsigned len, struct sk_buff *skb)
3286 #else
3287 static int ppp_dev_header (sk_buff *skb, struct device *dev,
3288 unsigned short type, void *daddr,
3289 void *saddr, unsigned len)
3290 #endif
3291 {
3292 return (0);
3293 }
3294
3295 static int
3296 ppp_dev_rebuild (void *buff, struct device *dev, unsigned long raddr,
3297 sk_buff *skb)
3298 {
3299 return (0);
3300 }
3301 #endif
3302
3303
3304
3305
3306
3307
3308
3309 static struct ppp *
3310 ppp_alloc (void)
3311 {
3312 int if_num;
3313 int status;
3314 ppp_ctrl_t *ctl;
3315 struct device *dev;
3316 struct ppp *ppp;
3317
3318
3319 ctl = ppp_list;
3320 if_num = 0;
3321
3322 while (ctl) {
3323 ppp = ctl2ppp (ctl);
3324 if (!set_bit(0, &ppp->inuse))
3325 return (ppp);
3326 ctl = ctl->next;
3327 if (++if_num == max_dev)
3328 return (NULL);
3329 }
3330
3331
3332
3333 ctl = (ppp_ctrl_t *) kmalloc (sizeof(ppp_ctrl_t), GFP_KERNEL);
3334 if (ctl) {
3335 (void) memset(ctl, 0, sizeof(ppp_ctrl_t));
3336 ppp = ctl2ppp (ctl);
3337 dev = ctl2dev (ctl);
3338
3339
3340 set_bit(0, &ppp->inuse);
3341
3342 ppp->line = if_num;
3343 ppp->tty = NULL;
3344 ppp->dev = dev;
3345
3346 dev->next = NULL;
3347 dev->init = ppp_init_dev;
3348 dev->name = ctl->name;
3349 dev->base_addr = (unsigned long) if_num;
3350 dev->priv = (void *) ppp;
3351
3352 sprintf (dev->name, "ppp%d", if_num);
3353
3354
3355 ctl->next = ppp_list;
3356 ppp_list = ctl;
3357
3358
3359
3360
3361 status = register_netdev (dev);
3362 if (status == 0) {
3363 printk (KERN_INFO "registered device %s\n", dev->name);
3364 return (ppp);
3365 }
3366
3367 printk (KERN_ERR
3368 "ppp_alloc - register_netdev(%s) = %d failure.\n",
3369 dev->name, status);
3370
3371 }
3372 return (NULL);
3373 }
3374
3375
3376
3377
3378
3379 static void
3380 ppp_print_hex (register u_char * out, const u_char * in, int count)
3381 {
3382 register u_char next_ch;
3383 static char hex[] = "0123456789ABCDEF";
3384
3385 while (count-- > 0) {
3386 next_ch = *in++;
3387 *out++ = hex[(next_ch >> 4) & 0x0F];
3388 *out++ = hex[next_ch & 0x0F];
3389 ++out;
3390 }
3391 }
3392
3393 static void
3394 ppp_print_char (register u_char * out, const u_char * in, int count)
3395 {
3396 register u_char next_ch;
3397
3398 while (count-- > 0) {
3399 next_ch = *in++;
3400
3401 if (next_ch < 0x20 || next_ch > 0x7e)
3402 *out++ = '.';
3403 else {
3404 *out++ = next_ch;
3405 if (next_ch == '%')
3406 *out++ = '%';
3407 }
3408 }
3409 *out = '\0';
3410 }
3411
3412 static void
3413 ppp_print_buffer (const u_char * name, const u_char * buf, int count)
3414 {
3415 u_char line[44];
3416
3417 if (name != (u_char *) NULL)
3418 printk (KERN_DEBUG "ppp: %s, count = %d\n", name, count);
3419
3420 while (count > 8) {
3421 memset (line, 32, 44);
3422 ppp_print_hex (line, buf, 8);
3423 ppp_print_char (&line[8 * 3], buf, 8);
3424 printk (KERN_DEBUG "%s\n", line);
3425 count -= 8;
3426 buf += 8;
3427 }
3428
3429 if (count > 0) {
3430 memset (line, 32, 44);
3431 ppp_print_hex (line, buf, count);
3432 ppp_print_char (&line[8 * 3], buf, count);
3433 printk (KERN_DEBUG "%s\n", line);
3434 }
3435 }
3436
3437
3438
3439
3440
3441 struct compressor_link {
3442 struct compressor_link *next;
3443 struct compressor *comp;
3444 };
3445
3446 static struct compressor_link *ppp_compressors = (struct compressor_link *) 0;
3447
3448 static struct compressor *find_compressor (int type)
3449 {
3450 struct compressor_link *lnk;
3451 unsigned long flags;
3452
3453 save_flags(flags);
3454 cli();
3455
3456 lnk = ppp_compressors;
3457 while (lnk != (struct compressor_link *) 0) {
3458 if ((int) (unsigned char) lnk->comp->compress_proto == type) {
3459 restore_flags(flags);
3460 return lnk->comp;
3461 }
3462 lnk = lnk->next;
3463 }
3464
3465 restore_flags(flags);
3466 return (struct compressor *) 0;
3467 }
3468
3469 int ppp_register_compressor (struct compressor *cp)
3470 {
3471 struct compressor_link *new;
3472 unsigned long flags;
3473
3474 new = (struct compressor_link *) kmalloc (sizeof (struct compressor_link), GFP_KERNEL);
3475
3476 if (new == (struct compressor_link *) 0)
3477 return 1;
3478
3479 save_flags(flags);
3480 cli();
3481
3482 if (find_compressor (cp->compress_proto)) {
3483 restore_flags(flags);
3484 kfree (new);
3485 return 0;
3486 }
3487
3488 new->next = ppp_compressors;
3489 new->comp = cp;
3490 ppp_compressors = new;
3491
3492 restore_flags(flags);
3493 return 0;
3494 }
3495
3496 void ppp_unregister_compressor (struct compressor *cp)
3497 {
3498 struct compressor_link *prev = (struct compressor_link *) 0;
3499 struct compressor_link *lnk;
3500 unsigned long flags;
3501
3502 save_flags(flags);
3503 cli();
3504
3505 lnk = ppp_compressors;
3506 while (lnk != (struct compressor_link *) 0) {
3507 if (lnk->comp == cp) {
3508 if (prev)
3509 prev->next = lnk->next;
3510 else
3511 ppp_compressors = lnk->next;
3512 kfree (lnk);
3513 break;
3514 }
3515 prev = lnk;
3516 lnk = lnk->next;
3517 }
3518 restore_flags(flags);
3519 }
3520
3521
3522
3523
3524
3525 #ifdef MODULE
3526
3527 int
3528 init_module(void)
3529 {
3530 int status;
3531
3532
3533 status = ppp_first_time();
3534 if (status != 0)
3535 printk (KERN_INFO
3536 "PPP: ppp_init() failure %d\n", status);
3537 else
3538 (void) register_symtab (&ppp_syms);
3539 return (status);
3540 }
3541
3542 void
3543 cleanup_module(void)
3544 {
3545 int status;
3546 ppp_ctrl_t *ctl, *next_ctl;
3547 struct device *dev;
3548 struct ppp *ppp;
3549 int busy_flag = 0;
3550
3551
3552
3553 ctl = ppp_list;
3554 while (ctl) {
3555 ppp = ctl2ppp (ctl);
3556 if (ppp->inuse && ppp->tty != NULL) {
3557 busy_flag = 1;
3558 break;
3559 }
3560
3561 dev = ctl2dev (ctl);
3562 if (dev->start || dev->flags & IFF_UP) {
3563 busy_flag = 1;
3564 break;
3565 }
3566 ctl = ctl->next;
3567 }
3568
3569
3570
3571 if (busy_flag == 0 && ppp_compressors != NULL)
3572 busy_flag = 1;
3573
3574 if (busy_flag) {
3575 printk (KERN_INFO
3576 "PPP: device busy, remove delayed\n");
3577 return;
3578 }
3579
3580
3581
3582
3583 status = tty_register_ldisc (N_PPP, NULL);
3584 if (status != 0)
3585 printk (KERN_INFO
3586 "PPP: Unable to unregister ppp line discipline "
3587 "(err = %d)\n", status);
3588 else
3589 printk (KERN_INFO
3590 "PPP: ppp line discipline successfully unregistered\n");
3591
3592
3593
3594 next_ctl = ppp_list;
3595 while (next_ctl) {
3596 ctl = next_ctl;
3597 next_ctl = ctl->next;
3598 ppp = ctl2ppp (ctl);
3599 dev = ctl2dev (ctl);
3600
3601 ppp_release (ppp);
3602 unregister_netdev (dev);
3603 kfree (ctl);
3604 }
3605 }
3606 #endif