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