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