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