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