3 * Michael Callahan <callahan@maths.ox.ac.uk> 4 * Al Longyear <longyear@netcom.com> 5 * Paul Mackerras <Paul.Mackerras@cs.anu.edu.au> 6 * Cyrus Durgin <cider@speakeasy.org> (changes for kmod) 8 * Dynamic PPP devices by Jim Freeman <jfree@caldera.com>. 9 * ppp_tty_receive ``noisy-raise-bug'' fixed by Ove Ewerlid <ewerlid@syscon.uu.se> 11 * ==FILEVERSION 980123== 13 * NOTE TO MAINTAINERS: 14 * If you modify this file at all, please set the number above to the 15 * date of the modification as YYMMDD (year month day). 16 * ppp.c is shipped with a PPP distribution as well as with the kernel; 17 * if everyone increases the FILEVERSION number above, then scripts 18 * can do the right thing when deciding whether to install a new ppp.c 19 * file. Don't change the format of that line otherwise, so the 20 * installation script can recognize it. 28 RFC1331: The Point-to-Point Protocol (PPP) for the Transmission of 29 Multi-protocol Datagrams over Point-to-Point Links 35 Flags for this module (any combination is acceptable for testing.): 37 OPTIMIZE_FLAG_TIME - Number of jiffies to force sending of leading flag 38 character. This is normally set to ((HZ * 3) / 2). 39 This is 1.5 seconds. If zero then the leading 42 CHECK_CHARACTERS - Enable the checking on all received characters for 43 8 data bits, no parity. This adds a small amount of 44 processing for each received character. 47 #define OPTIMIZE_FLAG_TIME ((HZ * 3)/2) 49 #define CHECK_CHARACTERS 1 50 #define PPP_COMPRESS 1 52 /* $Id: ppp.c,v 1.14 1997/11/27 06:04:45 paulus Exp $ */ 54 #include <linux/config.h>/* for CONFIG_KMOD */ 55 #include <linux/module.h> 56 #include <linux/kernel.h> 57 #include <linux/sched.h> 58 #include <linux/types.h> 59 #include <linux/fcntl.h> 60 #include <linux/poll.h> 61 #include <linux/interrupt.h> 62 #include <linux/ptrace.h> 64 #include <linux/malloc.h> 65 #include <linux/tty.h> 66 #include <linux/errno.h> 67 #include <linux/sched.h>/* to get the struct task_struct */ 68 #include <linux/string.h>/* used in new tty drivers */ 69 #include <linux/signal.h>/* used in new tty drivers */ 70 #include <asm/system.h> 71 #include <asm/bitops.h> 72 #include <asm/uaccess.h> 74 #include <linux/if_ether.h> 75 #include <linux/netdevice.h> 76 #include <linux/skbuff.h> 77 #include <linux/rtnetlink.h> 78 #include <linux/inet.h> 79 #include <linux/ioctl.h> 80 #include <linux/init.h> 82 typedefstruct sk_buff sk_buff
; 83 #define skb_data(skb) ((__u8 *) (skb)->data) 86 #include <linux/tcp.h> 87 #include <linux/if_arp.h> 88 #include <net/slhc_vj.h> 90 #define fcstab ppp_crc16_table/* Name of the table in the kernel */ 91 #include <linux/ppp_defs.h> 93 #include <linux/socket.h> 94 #include <linux/if_ppp.h> 95 #include <linux/if_pppvar.h> 96 #include <linux/ppp-comp.h> 99 #include <linux/kmod.h> 103 #define PPP_IPX 0x2b/* IPX protocol over PPP */ 107 #define PPP_LQR 0xc025/* Link Quality Reporting Protocol */ 110 static intppp_register_compressor(struct compressor
*cp
); 111 static voidppp_unregister_compressor(struct compressor
*cp
); 117 static struct compressor
*find_compressor(int type
); 118 static voidppp_init_ctrl_blk(registerstruct ppp
*); 119 static voidppp_kick_tty(struct ppp
*,struct ppp_buffer
*bfr
); 120 static struct ppp
*ppp_alloc(void); 121 static struct ppp
*ppp_find(int pid_value
); 122 static voidppp_print_buffer(const __u8
*,const __u8
*,int); 123 extern inlinevoidppp_stuff_char(struct ppp
*ppp
, 124 registerstruct ppp_buffer
*buf
, 126 extern inlineintlock_buffer(registerstruct ppp_buffer
*buf
); 127 static intppp_dev_xmit_ip(struct ppp
*ppp
,struct ppp_buffer
*buf
, 128 __u8
*data
,int len
,enum NPmode npmode
); 130 static intrcv_proto_ip(struct ppp
*, __u16
, __u8
*,int); 131 static intrcv_proto_ipx(struct ppp
*, __u16
, __u8
*,int); 132 static intrcv_proto_vjc_comp(struct ppp
*, __u16
, __u8
*,int); 133 static intrcv_proto_vjc_uncomp(struct ppp
*, __u16
, __u8
*,int); 134 static intrcv_proto_unknown(struct ppp
*, __u16
, __u8
*,int); 135 static intrcv_proto_lqr(struct ppp
*, __u16
, __u8
*,int); 136 static voidppp_doframe_lower(struct ppp
*, __u8
*,int); 137 static intppp_doframe(struct ppp
*); 139 static voidppp_proto_ccp(struct ppp
*ppp
, __u8
*dp
,int len
,int rcvd
); 140 static intrcv_proto_ccp(struct ppp
*, __u16
, __u8
*,int); 142 #define ins_char(pbuf,c) (buf_base(pbuf) [(pbuf)->count++] = (__u8)(c)) 144 #ifndef OPTIMIZE_FLAG_TIME 145 #define OPTIMIZE_FLAG_TIME 0 149 * Parameters which may be changed via insmod. 152 static int flag_time
= OPTIMIZE_FLAG_TIME
; 153 MODULE_PARM(flag_time
,"i"); 156 * The "main" procedure to the ppp device 159 intppp_init(struct device
*); 162 * Network device driver callback routines 165 static intppp_dev_open(struct device
*); 166 static intppp_dev_ioctl(struct device
*dev
,struct ifreq
*ifr
,int cmd
); 167 static intppp_dev_close(struct device
*); 168 static intppp_dev_xmit(sk_buff
*,struct device
*); 169 static struct net_device_stats
*ppp_dev_stats(struct device
*); 175 static ssize_t
ppp_tty_read(struct tty_struct
*,struct file
*, __u8
*, 177 static ssize_t
ppp_tty_write(struct tty_struct
*,struct file
*, 178 const __u8
*,size_t); 179 static intppp_tty_ioctl(struct tty_struct
*,struct file
*,unsigned int, 181 static unsigned intppp_tty_poll(struct tty_struct
*tty
,struct file
*filp
, 183 static intppp_tty_open(struct tty_struct
*); 184 static voidppp_tty_close(struct tty_struct
*); 185 static intppp_tty_room(struct tty_struct
*tty
); 186 static voidppp_tty_receive(struct tty_struct
*tty
,const __u8
* cp
, 188 static voidppp_tty_wakeup(struct tty_struct
*tty
); 190 #define CHECK_PPP_MAGIC(ppp) do { \ 191 if (ppp->magic != PPP_MAGIC) { \ 192 printk(KERN_WARNING"bad magic for ppp %p at %s:%d\n", \ 193 ppp, __FILE__, __LINE__); \ 196 #define CHECK_PPP(a) do { \ 197 CHECK_PPP_MAGIC(ppp); \ 199 printk (ppp_warning, __LINE__); \ 203 #define CHECK_PPP_VOID() do { \ 204 CHECK_PPP_MAGIC(ppp); \ 206 printk (ppp_warning, __LINE__); \ 210 #define in_xmap(ppp,c) (ppp->xmit_async_map[(c) >> 5] & (1 << ((c) & 0x1f))) 211 #define in_rmap(ppp,c) ((((unsigned int) (__u8) (c)) < 0x20) && \ 212 ppp->recv_async_map & (1 << (c))) 214 #define bset(p,b) ((p)[(b) >> 5] |= (1 << ((b) & 0x1f))) 216 #define tty2ppp(tty) ((struct ppp *) ((tty)->disc_data)) 217 #define dev2ppp(dev) ((struct ppp *) ((dev)->priv)) 218 #define ppp2tty(ppp) ((ppp)->tty) 219 #define ppp2dev(ppp) (&(ppp)->dev) 221 static struct ppp
*ppp_list
= NULL
; 222 static struct ppp
*ppp_last
= NULL
; 225 #define BUFFER_TYPE_DEV_RD 0/* ppp read buffer */ 226 #define BUFFER_TYPE_TTY_WR 1/* tty write buffer */ 227 #define BUFFER_TYPE_DEV_WR 2/* ppp write buffer */ 228 #define BUFFER_TYPE_TTY_RD 3/* tty read buffer */ 229 #define BUFFER_TYPE_VJ 4/* vj compression buffer */ 231 /* Define this string only once for all macro invocations */ 232 static char ppp_warning
[] = KERN_WARNING
"PPP: ALERT! not INUSE! %d\n"; 234 static char szVersion
[] = PPP_VERSION
; 237 * Information for the protocol decoder 240 typedefint(*pfn_proto
) (struct ppp
*, __u16
, __u8
*,int); 242 typedefstruct ppp_proto_struct
{ 248 ppp_proto_type proto_list
[] = { 249 { PPP_IP
, rcv_proto_ip
}, 250 { PPP_IPX
, rcv_proto_ipx
}, 251 { PPP_VJC_COMP
, rcv_proto_vjc_comp
}, 252 { PPP_VJC_UNCOMP
, rcv_proto_vjc_uncomp
}, 253 { PPP_LQR
, rcv_proto_lqr
}, 254 { PPP_CCP
, rcv_proto_ccp
}, 255 {0, rcv_proto_unknown
}/* !!! MUST BE LAST !!! */ 258 __u16 ppp_crc16_table
[256] = 260 0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf, 261 0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7, 262 0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e, 263 0x9cc9,0x8d40,0xbfdb,0xae52,0xdaed,0xcb64,0xf9ff,0xe876, 264 0x2102,0x308b,0x0210,0x1399,0x6726,0x76af,0x4434,0x55bd, 265 0xad4a,0xbcc3,0x8e58,0x9fd1,0xeb6e,0xfae7,0xc87c,0xd9f5, 266 0x3183,0x200a,0x1291,0x0318,0x77a7,0x662e,0x54b5,0x453c, 267 0xbdcb,0xac42,0x9ed9,0x8f50,0xfbef,0xea66,0xd8fd,0xc974, 268 0x4204,0x538d,0x6116,0x709f,0x0420,0x15a9,0x2732,0x36bb, 269 0xce4c,0xdfc5,0xed5e,0xfcd7,0x8868,0x99e1,0xab7a,0xbaf3, 270 0x5285,0x430c,0x7197,0x601e,0x14a1,0x0528,0x37b3,0x263a, 271 0xdecd,0xcf44,0xfddf,0xec56,0x98e9,0x8960,0xbbfb,0xaa72, 272 0x6306,0x728f,0x4014,0x519d,0x2522,0x34ab,0x0630,0x17b9, 273 0xef4e,0xfec7,0xcc5c,0xddd5,0xa96a,0xb8e3,0x8a78,0x9bf1, 274 0x7387,0x620e,0x5095,0x411c,0x35a3,0x242a,0x16b1,0x0738, 275 0xffcf,0xee46,0xdcdd,0xcd54,0xb9eb,0xa862,0x9af9,0x8b70, 276 0x8408,0x9581,0xa71a,0xb693,0xc22c,0xd3a5,0xe13e,0xf0b7, 277 0x0840,0x19c9,0x2b52,0x3adb,0x4e64,0x5fed,0x6d76,0x7cff, 278 0x9489,0x8500,0xb79b,0xa612,0xd2ad,0xc324,0xf1bf,0xe036, 279 0x18c1,0x0948,0x3bd3,0x2a5a,0x5ee5,0x4f6c,0x7df7,0x6c7e, 280 0xa50a,0xb483,0x8618,0x9791,0xe32e,0xf2a7,0xc03c,0xd1b5, 281 0x2942,0x38cb,0x0a50,0x1bd9,0x6f66,0x7eef,0x4c74,0x5dfd, 282 0xb58b,0xa402,0x9699,0x8710,0xf3af,0xe226,0xd0bd,0xc134, 283 0x39c3,0x284a,0x1ad1,0x0b58,0x7fe7,0x6e6e,0x5cf5,0x4d7c, 284 0xc60c,0xd785,0xe51e,0xf497,0x8028,0x91a1,0xa33a,0xb2b3, 285 0x4a44,0x5bcd,0x6956,0x78df,0x0c60,0x1de9,0x2f72,0x3efb, 286 0xd68d,0xc704,0xf59f,0xe416,0x90a9,0x8120,0xb3bb,0xa232, 287 0x5ac5,0x4b4c,0x79d7,0x685e,0x1ce1,0x0d68,0x3ff3,0x2e7a, 288 0xe70e,0xf687,0xc41c,0xd595,0xa12a,0xb0a3,0x8238,0x93b1, 289 0x6b46,0x7acf,0x4854,0x59dd,0x2d62,0x3ceb,0x0e70,0x1ff9, 290 0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330, 291 0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78 294 #ifdef CHECK_CHARACTERS 295 static __u32 paritytab
[8] = 297 0x96696996,0x69969669,0x69969669,0x96696996, 298 0x69969669,0x96696996,0x96696996,0x69969669 302 /* local function to store a value into the LQR frame */ 303 extern inline __u8
*store_long(register __u8
*p
,registerint value
) { 304 *p
++ = (__u8
) (value
>>24); 305 *p
++ = (__u8
) (value
>>16); 306 *p
++ = (__u8
) (value
>>8); 311 /************************************************************* 313 *************************************************************/ 315 /* This procedure is called once and once only to define who we are to 316 * the operating system and the various procedures that it may use in 317 * accessing the ppp protocol. 320 __initfunc(static int 321 ppp_first_time(void)) 323 static struct tty_ldisc ppp_ldisc
; 327 "PPP: version %s (demand dialling)" 330 #ifndef MODULE/* slhc module logic has its own copyright announcement */ 332 "TCP compression code copyright 1989 Regents of the " 333 "University of California\n"); 337 * Register the tty discipline 339 (void)memset(&ppp_ldisc
,0,sizeof(ppp_ldisc
)); 340 ppp_ldisc
.magic
= TTY_LDISC_MAGIC
; 341 ppp_ldisc
.name
="ppp"; 342 ppp_ldisc
.open
= ppp_tty_open
; 343 ppp_ldisc
.close
= ppp_tty_close
; 344 ppp_ldisc
.read
= ppp_tty_read
; 345 ppp_ldisc
.write
= ppp_tty_write
; 346 ppp_ldisc
.ioctl
= ppp_tty_ioctl
; 347 ppp_ldisc
.poll
= ppp_tty_poll
; 348 ppp_ldisc
.receive_room
= ppp_tty_room
; 349 ppp_ldisc
.receive_buf
= ppp_tty_receive
; 350 ppp_ldisc
.write_wakeup
= ppp_tty_wakeup
; 352 status
=tty_register_ldisc(N_PPP
, &ppp_ldisc
); 354 printk(KERN_INFO
"PPP line discipline registered.\n"); 356 printk(KERN_ERR
"error registering line discipline: %d\n", 361 /************************************************************* 363 *************************************************************/ 365 /* called when the device is actually created */ 368 ppp_init_dev(struct device
*dev
) 370 dev
->hard_header_len
= PPP_HDRLEN
; 374 dev
->hard_start_xmit
= ppp_dev_xmit
; 375 dev
->open
= ppp_dev_open
; 376 dev
->stop
= ppp_dev_close
; 377 dev
->get_stats
= ppp_dev_stats
; 378 dev
->do_ioctl
= ppp_dev_ioctl
; 380 dev
->tx_queue_len
=10; 381 dev
->type
= ARPHRD_PPP
; 383 dev_init_buffers(dev
); 385 /* New-style flags */ 386 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
| IFF_MULTICAST
; 392 * Local procedure to initialize the ppp structure 396 ppp_init_ctrl_blk(registerstruct ppp
*ppp
) 398 ppp
->magic
= PPP_MAGIC
; 406 memset(ppp
->xmit_async_map
,0,sizeof(ppp
->xmit_async_map
)); 407 ppp
->xmit_async_map
[0] =0xffffffff; 408 ppp
->xmit_async_map
[3] =0x60000000; 409 ppp
->recv_async_map
=0x00000000; 416 ppp
->read_wait
= NULL
; 417 ppp
->write_wait
= NULL
; 418 ppp
->last_xmit
= jiffies
- flag_time
; 419 ppp
->last_recv
= jiffies
; 421 /* clear statistics */ 422 memset(&ppp
->stats
,0,sizeof(struct pppstat
)); 423 memset(&ppp
->estats
,0,sizeof(ppp
->estats
)); 425 /* PPP compression data */ 427 ppp
->sc_rc_state
= NULL
; 430 EXPORT_SYMBOL(ppp_register_compressor
); 431 EXPORT_SYMBOL(ppp_unregister_compressor
); 432 EXPORT_SYMBOL(ppp_crc16_table
); 434 /* called at boot/load time for each ppp device defined in the kernel */ 438 ppp_init(struct device
*dev
) 440 static int first_time
=1; 445 answer
=ppp_first_time(); 453 #define BUFFER_MAGIC 0x1d10 454 #define CHECK_BUF_MAGIC(buf) do { \ 455 if (buf->magic != BUFFER_MAGIC) { \ 456 printk(KERN_WARNING"bad magic for ppp buffer %p at %s:%d\n", \ 457 buf, __FILE__, __LINE__); \ 462 * Routine to allocate a buffer for later use by the driver. 465 static struct ppp_buffer
* 466 ppp_alloc_buf(int size
,int type
) 468 struct ppp_buffer
*buf
; 470 buf
= (struct ppp_buffer
*)kmalloc(size
+sizeof(struct ppp_buffer
), 474 buf
->size
= size
-1;/* Mask for the buffer size */ 480 buf
->fcs
= PPP_INITFCS
; 481 buf
->magic
= BUFFER_MAGIC
; 487 * Routine to release the allocated buffer. 491 ppp_free_buf(struct ppp_buffer
*ptr
) 494 CHECK_BUF_MAGIC(ptr
); 500 * Lock the indicated transmit buffer 504 lock_buffer(registerstruct ppp_buffer
*buf
) 509 * Save the current state and if free then set it to the "busy" state 511 CHECK_BUF_MAGIC(buf
); 518 restore_flags(flags
); 523 * MTU has been changed by the IP layer. Unfortunately we are not told 524 * about this, but we spot it ourselves and fix things up. We could be 525 * in an upcall from the tty driver, or in an ip packet queue. 529 ppp_changedmtu(struct ppp
*ppp
,int new_mtu
,int new_mru
) 534 struct ppp_buffer
*new_rbuf
; 535 struct ppp_buffer
*new_wbuf
; 536 struct ppp_buffer
*new_cbuf
; 537 struct ppp_buffer
*new_tbuf
; 539 struct ppp_buffer
*old_rbuf
; 540 struct ppp_buffer
*old_wbuf
; 541 struct ppp_buffer
*old_cbuf
; 542 struct ppp_buffer
*old_tbuf
; 546 * Allocate the buffer from the kernel for the data 550 if(ppp
->flags
& SC_DEBUG
) 551 printk(KERN_DEBUG
"%s: changedmtu %d %d\n", ppp
->name
, 554 /* allow for possible escaping of every character */ 555 mtu
= (new_mtu
*2) +20; 557 /* RFC 1331, section 7.2 says the minimum value is 1500 bytes */ 563 new_wbuf
=ppp_alloc_buf(mtu
+PPP_HDRLEN
, BUFFER_TYPE_DEV_WR
); 564 new_tbuf
=ppp_alloc_buf((PPP_MTU
*2) +24, BUFFER_TYPE_TTY_WR
); 565 new_rbuf
=ppp_alloc_buf(mru
+84, BUFFER_TYPE_DEV_RD
); 566 new_cbuf
=ppp_alloc_buf(mru
+PPP_HDRLEN
, BUFFER_TYPE_VJ
); 568 * If the buffers failed to allocate then complain and release the partial 571 if(new_wbuf
== NULL
|| new_tbuf
== NULL
|| 572 new_rbuf
== NULL
|| new_cbuf
== NULL
) { 573 printk(KERN_ERR
"ppp: failed to allocate new buffers\n"); 575 ppp_free_buf(new_wbuf
); 576 ppp_free_buf(new_tbuf
); 577 ppp_free_buf(new_rbuf
); 578 ppp_free_buf(new_cbuf
); 582 * Update the pointers to the new buffer structures. 586 old_wbuf
= ppp
->wbuf
; 587 old_rbuf
= ppp
->rbuf
; 588 old_cbuf
= ppp
->cbuf
; 589 old_tbuf
= ppp
->tbuf
; 591 ppp
->wbuf
= new_wbuf
; 592 ppp
->rbuf
= new_rbuf
; 593 ppp
->cbuf
= new_cbuf
; 594 ppp
->tbuf
= new_tbuf
; 597 new_wbuf
->locked
= old_wbuf
->locked
; 599 ppp
->rbuf
->size
-=80;/* reserve space for vj header expansion */ 601 dev
->mem_start
= (unsigned long)buf_base(new_wbuf
); 602 dev
->mem_end
= (unsigned long) (dev
->mem_start
+ mtu
); 603 dev
->rmem_start
= (unsigned long)buf_base(new_rbuf
); 604 dev
->rmem_end
= (unsigned long) (dev
->rmem_start
+ mru
); 606 * Update the parameters for the new buffer sizes 608 ppp
->toss
=0xE0;/* To ignore characters until new FLAG */ 609 ppp
->escape
=0;/* No pending escape character */ 619 ppp
->tty
->flags
&= ~(1<< TTY_DO_WRITE_WAKEUP
); 620 ppp
->flags
&= ~SC_XMIT_BUSY
; 622 restore_flags(flags
); 624 * Release old buffer pointers 626 ppp_free_buf(old_rbuf
); 627 ppp_free_buf(old_wbuf
); 628 ppp_free_buf(old_cbuf
); 629 ppp_free_buf(old_tbuf
); 634 * CCP is down; free (de)compressor state if necessary. 638 ppp_ccp_closed(struct ppp
*ppp
) 644 ppp
->flags
&= ~(SC_CCP_OPEN
| SC_CCP_UP
| SC_COMP_RUN
| SC_DECOMP_RUN
); 645 restore_flags(flags
); 646 if(ppp
->flags
& SC_DEBUG
) 647 printk(KERN_DEBUG
"%s: ccp closed\n", ppp
->name
); 648 if(ppp
->sc_xc_state
) { 649 (*ppp
->sc_xcomp
->comp_free
) (ppp
->sc_xc_state
); 650 ppp
->sc_xc_state
= NULL
; 653 if(ppp
->sc_rc_state
) { 654 (*ppp
->sc_rcomp
->decomp_free
) (ppp
->sc_rc_state
); 655 ppp
->sc_rc_state
= NULL
; 660 * Called to release all of the information in the current PPP structure. 662 * It is called when the ppp device goes down or if it is unable to go 667 ppp_release(struct ppp
*ppp
) 669 struct tty_struct
*tty
; 672 CHECK_PPP_MAGIC(ppp
); 676 if(ppp
->flags
& SC_DEBUG
) 677 printk(KERN_DEBUG
"%s released\n", ppp
->name
); 681 /* Ensure that the pppd process is not hanging on poll() */ 682 wake_up_interruptible(&ppp
->read_wait
); 683 wake_up_interruptible(&ppp
->write_wait
); 685 if(tty
!= NULL
&& tty
->disc_data
== ppp
) 686 tty
->disc_data
= NULL
;/* Break the tty->ppp link */ 688 ppp_free_buf(ppp
->rbuf
); 689 ppp_free_buf(ppp
->wbuf
); 690 ppp_free_buf(ppp
->cbuf
); 691 ppp_free_buf(ppp
->ubuf
); 692 ppp_free_buf(ppp
->tbuf
); 704 slhc_free(ppp
->slcomp
); 710 ppp
->backup_tty
= NULL
; 716 * Called when the line discipline is changed to something 717 * else, the tty is closed, or the tty detects a hangup. 721 ppp_tty_close(struct tty_struct
*tty
) 723 struct ppp
*ppp
=tty2ppp(tty
); 726 if(ppp
->magic
!= PPP_MAGIC
) { 727 if(ppp
->flags
& SC_DEBUG
) 729 "ppp: trying to close unopened tty!\n"); 733 tty
->disc_data
= NULL
; 734 if(tty
== ppp
->backup_tty
) 738 if(ppp
->backup_tty
) { 739 ppp
->tty
= ppp
->backup_tty
; 742 if(ppp
->flags
& SC_DEBUG
) 743 printk(KERN_INFO
"ppp: channel %s closing.\n", 754 * Called when the tty discipline is switched to PPP. 758 ppp_tty_open(struct tty_struct
*tty
) 760 struct ppp
*ppp
=tty2ppp(tty
); 763 * There should not be an existing table for this slot. 767 "ppp_tty_open: gack! tty already associated to %s!\n", 768 ppp
->magic
== PPP_MAGIC
?ppp2dev(ppp
)->name
773 * Allocate the structure from the system 775 ppp
=ppp_find(current
->pid
); 778 * If we are taking over a ppp unit which is currently 779 * connected to a loopback pty, there's not much to do. 782 tty
->disc_data
= ppp
; 788 printk(KERN_ERR
"ppp_alloc failed\n"); 792 * Initialize the control block 794 ppp_init_ctrl_blk(ppp
); 795 tty
->disc_data
= ppp
; 798 * Allocate space for the default VJ header compression slots 800 ppp
->slcomp
=slhc_init(16,16); 801 if(ppp
->slcomp
== NULL
) { 802 printk(KERN_ERR
"ppp_tty_open: " 803 "no space for compression buffers!\n"); 808 * Allocate space for the MTU and MRU buffers 810 if(ppp_changedmtu(ppp
,ppp2dev(ppp
)->mtu
, ppp
->mru
) ==0) { 815 * Allocate space for a user level buffer 817 ppp
->ubuf
=ppp_alloc_buf(RBUFSIZE
, BUFFER_TYPE_TTY_RD
); 818 if(ppp
->ubuf
== NULL
) { 819 printk(KERN_ERR
"ppp_tty_open: " 820 "no space for user receive buffer\n"); 825 if(ppp
->flags
& SC_DEBUG
) 826 printk(KERN_INFO
"ppp: channel %s open\n", 829 for(indx
=0; indx
< NUM_NP
; ++indx
) 830 ppp
->sc_npmode
[indx
] = NPMODE_PASS
; 835 * Flush any pending characters in the driver and discipline. 837 if(tty
->ldisc
.flush_buffer
) 838 tty
->ldisc
.flush_buffer(tty
); 840 if(tty
->driver
.flush_buffer
) 841 tty
->driver
.flush_buffer(tty
); 846 * Local function to send the next portion of the buffer. 848 * Called by the tty driver's tty_wakeup function should it be entered 849 * because the partial buffer was transmitted. 851 * Called by kick_tty to send the initial portion of the buffer. 853 * Completion processing of the buffer transmission is handled here. 857 ppp_tty_wakeup_code(struct ppp
*ppp
,struct tty_struct
*tty
, 858 struct ppp_buffer
*xbuf
) 860 registerint count
, actual
; 864 CHECK_BUF_MAGIC(xbuf
); 866 * Prevent re-entrancy by ensuring that this routine is called only once. 870 if(ppp
->flags
& SC_XMIT_BUSY
) { 871 restore_flags(flags
); 874 ppp
->flags
|= SC_XMIT_BUSY
; 875 restore_flags(flags
); 877 * Send the next block of data to the modem 879 count
= xbuf
->count
- xbuf
->tail
; 880 actual
= tty
->driver
.write(tty
,0, 881 buf_base(xbuf
) + xbuf
->tail
, count
); 883 * Terminate transmission of any block which may have an error. 884 * This could occur should the carrier drop. 887 ppp
->stats
.ppp_oerrors
++; 890 ppp
->bytes_sent
+= actual
; 892 * If the buffer has been transmitted then clear the indicators. 894 xbuf
->tail
+= actual
; 895 if(actual
== count
) { 897 ppp
->flags
&= ~SC_XMIT_BUSY
; 899 * Complete the transmission on the current buffer. 903 tty
->flags
&= ~(1<< TTY_DO_WRITE_WAKEUP
); 907 * If the completed buffer came from the device write, then complete the 908 * transmission block. 910 ppp2dev(ppp
)->tbusy
=0; 913 * Wake up the transmission queue for all completion events. 915 wake_up_interruptible(&ppp
->write_wait
); 917 * Look at the priorities. Choose a daemon write over the device driver. 928 * If there is a pending buffer then transmit it now. 931 ppp
->flags
&= ~SC_XMIT_BUSY
; 932 ppp_kick_tty(ppp
, xbuf
); 933 restore_flags(flags
); 936 restore_flags(flags
); 940 * Clear the re-entry flag 942 save_flags(flags
);/* &=~ may not be atomic */ 944 ppp
->flags
&= ~SC_XMIT_BUSY
; 945 restore_flags(flags
); 949 * This function is called by the tty driver when the transmit buffer has 950 * additional space. It is used by the ppp code to continue to transmit 951 * the current buffer should the buffer have been partially sent. 953 * In addition, it is used to send the first part of the buffer since the 954 * logic and the inter-locking would be identical. 958 ppp_tty_wakeup(struct tty_struct
*tty
) 960 struct ppp_buffer
*xbuf
; 961 struct ppp
*ppp
=tty2ppp(tty
); 967 if(tty
!= ppp
->tty
) { 968 tty
->flags
&= ~(1<< TTY_DO_WRITE_WAKEUP
); 972 * Ensure that there is a transmission pending. Clear the re-entry flag if 973 * there is no pending buffer. Otherwise, send the buffer. 977 tty
->flags
&= ~(1<< TTY_DO_WRITE_WAKEUP
); 979 ppp_tty_wakeup_code(ppp
, tty
, xbuf
); 983 * This function is called to transmit a buffer to the remote. The buffer 984 * is placed on the pending queue if there is presently a buffer being 985 * sent or it is transmitted with the aid of ppp_tty_wakeup. 989 ppp_kick_tty(struct ppp
*ppp
,struct ppp_buffer
*xbuf
) 994 CHECK_BUF_MAGIC(xbuf
); 1001 * Control the flags which are best performed with the interrupts masked. 1006 * If the transmitter is busy then place the buffer on the appropriate 1009 if(ppp
->xbuf
!= NULL
) { 1010 if(xbuf
->type
== BUFFER_TYPE_TTY_WR
) 1014 restore_flags(flags
); 1018 * If the transmitter is not busy then this is the highest priority frame 1020 ppp
->flags
&= ~SC_XMIT_BUSY
; 1021 ppp
->tty
->flags
|= (1<< TTY_DO_WRITE_WAKEUP
); 1023 restore_flags(flags
); 1025 * Do the "tty wakeup_code" to actually send this buffer. 1027 ppp_tty_wakeup_code(ppp
,ppp2tty(ppp
), xbuf
); 1030 /************************************************************* 1032 * The following functions handle input that arrives from 1033 * the TTY. It recognizes PPP frames and either hands them 1034 * to the network layer or queues them for delivery to a 1035 * user process reading this TTY. 1036 *************************************************************/ 1039 * Callback function from tty driver. Return the amount of space left 1040 * in the receiver's buffer to decide if remote transmitter is to be 1045 ppp_tty_room(struct tty_struct
*tty
) 1047 return65536;/* We can handle an infinite amount of data. :-) */ 1051 * Callback function when data is available at the tty driver. 1054 ppp_tty_receive(struct tty_struct
*tty
,const __u8
* data
, 1055 char*flags
,int count
) 1057 registerstruct ppp
*ppp
=tty2ppp(tty
); 1058 registerstruct ppp_buffer
*buf
= NULL
; 1064 * This can happen if stuff comes in on the backup tty. 1066 if(ppp
==0|| tty
!= ppp
->tty
) 1069 * Fetch the pointer to the buffer. Be careful about race conditions. 1075 * Verify the table pointer and ensure that the line is 1076 * still in PPP discipline. 1078 if(ppp
->magic
!= PPP_MAGIC
) { 1079 if(ppp
->flags
& SC_DEBUG
) 1081 "PPP: tty_receive called but couldn't find " 1087 * Print the buffer if desired 1089 if(ppp
->flags
& SC_LOG_RAWIN
) 1090 ppp_print_buffer("receive buffer", data
, count
); 1093 * Collect the character and error condition for the character. Set the toss 1094 * flag for the first character error. 1100 if(*flags
&& ppp
->toss
==0) { 1104 ++ppp
->estats
.rx_fifo_errors
; 1108 ++ppp
->estats
.rx_frame_errors
; 1116 * Set the flags for d7 being 0/1 and parity being even/odd so that 1117 * the normal processing would have all flags set at the end of the 1118 * session. A missing flag bit indicates an error condition. 1121 #ifdef CHECK_CHARACTERS 1123 ppp
->flags
|= SC_RCV_B7_1
; 1125 ppp
->flags
|= SC_RCV_B7_0
; 1127 if(paritytab
[chr
>>5] & (1<< (chr
&0x1F))) 1128 ppp
->flags
|= SC_RCV_ODDP
; 1130 ppp
->flags
|= SC_RCV_EVNP
; 1133 * Branch on the character. 1137 * FLAG. This is the end of the block. If the block terminated by ESC FLAG, 1138 * then the block is to be ignored. In addition, characters before the very 1139 * first FLAG are also tossed by this procedure. 1141 case PPP_FLAG
:/* PPP_FLAG: end of frame */ 1142 ppp
->stats
.ppp_ibytes
+= ppp
->rbuf
->count
; 1146 * Process frames which are not to be ignored. If the processing failed, 1147 * then clean up the VJ tables. 1149 if(ppp_doframe(ppp
) ==0) { 1150 ++ppp
->stats
.ppp_ierrors
; 1151 slhc_toss(ppp
->slcomp
); 1154 * Reset all indicators for the new frame to follow. 1157 buf
->fcs
= PPP_INITFCS
; 1162 * All other characters in the data come here. If the character is in the 1163 * receive mask then ignore the character. 1166 /* If we're tossing, look no further. */ 1170 /* If this is a control char to be ignored, do so */ 1171 if(in_rmap(ppp
, chr
)) 1175 * Modify the next character if preceded by escape. 1176 * The escape character (0x7d) could be an escaped 1177 * 0x5d, if it follows an escape :-) 1182 }else if(chr
== PPP_ESCAPE
) { 1183 ppp
->escape
= PPP_TRANS
; 1188 * Decompress A/C and protocol compression here. 1190 if(buf
->count
==0&& chr
!= PPP_ALLSTATIONS
) { 1191 buf_base(buf
)[0] = PPP_ALLSTATIONS
; 1192 buf_base(buf
)[1] = PPP_UI
; 1195 if(buf
->count
==2&& (chr
&1) !=0) { 1196 buf_base(buf
)[2] =0; 1200 * If the count sent is within reason then store the character, bump the 1201 * count, and update the FCS for the character. 1203 if(buf
->count
< buf
->size
) { 1204 buf_base(buf
)[buf
->count
++] = chr
; 1205 buf
->fcs
=PPP_FCS(buf
->fcs
, chr
); 1209 * The peer sent too much data. Set the flags to discard the current frame 1210 * and wait for the re-synchronization FLAG to be sent. 1212 ++ppp
->estats
.rx_length_errors
; 1219 /* on entry, a received frame is in ppp->rbuf.bufr 1220 check it and dispose as appropriate */ 1223 ppp_doframe(struct ppp
*ppp
) 1225 __u8
*data
=buf_base(ppp
->rbuf
); 1226 int count
= ppp
->rbuf
->count
; 1232 CHECK_BUF_MAGIC(ppp
->rbuf
); 1235 * If there is a pending error from the receiver then log it and discard 1236 * the damaged frame. 1239 if((ppp
->flags
& SC_DEBUG
) && count
>0) 1241 "ppp_toss: tossing frame, reason = %x\n", 1246 * An empty frame is ignored. This occurs if the FLAG sequence precedes and 1247 * follows each frame. 1252 * Generate an error if the frame is too small. 1254 if(count
< PPP_HDRLEN
+2) { 1255 if(ppp
->flags
& SC_DEBUG
) 1257 "ppp: got runt ppp frame, %d chars\n", count
); 1258 ++ppp
->estats
.rx_length_errors
; 1262 * Verify the CRC of the frame and discard the CRC characters from the 1263 * end of the buffer. 1265 if(ppp
->rbuf
->fcs
!= PPP_GOODFCS
) { 1266 if(ppp
->flags
& SC_DEBUG
) { 1268 "ppp: frame with bad fcs, length = %d\n", 1270 ppp_print_buffer("bad frame", data
, count
); 1272 ++ppp
->estats
.rx_crc_errors
; 1275 count
-=2;/* ignore the fcs characters */ 1277 * Obtain the protocol from the frame 1279 proto
=PPP_PROTOCOL(data
); 1281 * Process the active decompressor. 1283 if((ppp
->sc_rc_state
!= (void*)0) && 1284 (ppp
->flags
& SC_DECOMP_RUN
) && 1285 ((ppp
->flags
& (SC_DC_FERROR
| SC_DC_ERROR
)) ==0)) { 1286 if(proto
== PPP_COMP
) { 1288 * If the frame is compressed then decompress it. 1290 new_data
=kmalloc(ppp
->mru
+ PPP_HDRLEN
, GFP_ATOMIC
); 1291 if(new_data
== NULL
) { 1292 printk(KERN_ERR
"ppp_doframe: no memory\n"); 1293 new_count
= DECOMP_ERROR
; 1295 new_count
= (*ppp
->sc_rcomp
->decompress
) 1296 (ppp
->sc_rc_state
, data
, count
, 1297 new_data
, ppp
->mru
+ PPP_HDRLEN
); 1301 ppp_doframe_lower(ppp
, new_data
, new_count
); 1306 ppp
->flags
|= SC_DC_ERROR
; 1309 case DECOMP_FATALERROR
: 1310 ppp
->flags
|= SC_DC_FERROR
; 1311 printk(KERN_ERR
"ppp: fatal decomp error\n"); 1315 * Log the error condition and discard the frame. 1319 slhc_toss(ppp
->slcomp
); 1320 ++ppp
->stats
.ppp_ierrors
; 1323 * The frame is not special. Pass it through the compressor without 1324 * actually compressing the data 1326 (*ppp
->sc_rcomp
->incomp
) (ppp
->sc_rc_state
, 1331 * Process the uncompressed frame. 1333 ppp_doframe_lower(ppp
, data
, count
); 1337 static voidppp_doframe_lower(struct ppp
*ppp
, __u8
*data
,int count
) 1339 __u16 proto
=PPP_PROTOCOL(data
); 1340 ppp_proto_type
*proto_ptr
; 1344 * Ignore empty frames 1346 if(count
<= PPP_HDRLEN
) 1349 * Count the frame and print it 1351 ++ppp
->stats
.ppp_ipackets
; 1352 if(ppp
->flags
& SC_LOG_INPKT
) 1353 ppp_print_buffer("receive frame", data
, count
); 1355 * Find the procedure to handle this protocol. The last one is marked 1356 * as a protocol 0 which is the 'catch-all' to feed it to the pppd daemon. 1358 proto_ptr
= proto_list
; 1359 while(proto_ptr
->proto
!=0&& proto_ptr
->proto
!= proto
) 1362 * Update the appropriate statistic counter. 1364 if((*proto_ptr
->func
) (ppp
, proto
, 1366 count
- PPP_HDRLEN
)) 1367 ppp
->stats
.ppp_ioctects
+= count
; 1369 ++ppp
->stats
.ppp_discards
; 1373 * Put the input frame into the networking system for the indicated protocol 1377 ppp_rcv_rx(struct ppp
*ppp
, __u16 proto
, __u8
* data
,int count
) 1379 sk_buff
*skb
=dev_alloc_skb(count
); 1381 * Generate a skb buffer for the new frame. 1384 if(ppp
->flags
& SC_DEBUG
) 1386 "ppp_do_ip: packet dropped on %s (no memory)!\n", 1387 ppp2dev(ppp
)->name
); 1391 * Move the received data from the input buffer to the skb buffer. 1393 skb
->dev
=ppp2dev(ppp
);/* We are the device */ 1394 skb
->protocol
= proto
; 1395 skb
->mac
.raw
=skb_data(skb
); 1396 memcpy(skb_put(skb
,count
), data
, count
);/* move data */ 1398 * Tag the frame and kick it to the proper receive routine 1400 ppp
->last_recv
= jiffies
; 1406 * Process the receipt of an IP frame 1410 rcv_proto_ip(struct ppp
*ppp
, __u16 proto
, __u8
* data
,int count
) 1413 if((ppp2dev(ppp
)->flags
& IFF_UP
) && (count
>0)) 1414 if(ppp
->sc_npmode
[NP_IP
] == NPMODE_PASS
) 1415 returnppp_rcv_rx(ppp
,htons(ETH_P_IP
), data
, count
); 1420 * Process the receipt of an IPX frame 1424 rcv_proto_ipx(struct ppp
*ppp
, __u16 proto
, __u8
* data
,int count
) 1427 if(((ppp2dev(ppp
)->flags
& IFF_UP
) !=0) && (count
>0)) 1428 returnppp_rcv_rx(ppp
,htons(ETH_P_IPX
), data
, count
); 1433 * Process the receipt of an VJ Compressed frame 1437 rcv_proto_vjc_comp(struct ppp
*ppp
, __u16 proto
, 1438 __u8
*data
,int count
) 1441 if((ppp
->flags
& SC_REJ_COMP_TCP
) ==0) { 1442 int new_count
=slhc_uncompress(ppp
->slcomp
, data
, count
); 1444 returnrcv_proto_ip(ppp
, PPP_IP
, data
, new_count
); 1446 if(ppp
->flags
& SC_DEBUG
) 1448 "ppp: error in VJ decompression\n"); 1454 * Process the receipt of an VJ Un-compressed frame 1458 rcv_proto_vjc_uncomp(struct ppp
*ppp
, __u16 proto
, 1459 __u8
*data
,int count
) 1462 if((ppp
->flags
& SC_REJ_COMP_TCP
) ==0) { 1463 if(slhc_remember(ppp
->slcomp
, data
, count
) >0) { 1464 returnrcv_proto_ip(ppp
, PPP_IP
, data
, count
); 1466 if(ppp
->flags
& SC_DEBUG
) 1468 "ppp: error in VJ memorizing\n"); 1474 * Receive all unclassified protocols. 1478 rcv_proto_unknown(struct ppp
*ppp
, __u16 proto
, 1482 registerint current_idx
; 1486 buf_base (ppp->ubuf) [current_idx++] = (__u8) (c); \ 1487 current_idx &= ppp->ubuf->size; \ 1488 if (current_idx == ppp->ubuf->tail) \ 1494 * The total length includes the protocol data. 1495 * Lock the user information buffer. 1497 if(test_and_set_bit(0, &ppp
->ubuf
->locked
)) { 1498 if(ppp
->flags
& SC_DEBUG
) 1500 "ppp: rcv_proto_unknown: can't get lock\n"); 1502 CHECK_BUF_MAGIC(ppp
->ubuf
); 1503 current_idx
= ppp
->ubuf
->head
; 1505 * Insert the buffer length (not counted), the protocol, and the data 1515 while(totlen
-- >0) { 1520 * The frame is complete. Update the head pointer and wakeup the pppd 1523 ppp
->ubuf
->head
= current_idx
; 1525 clear_bit(0, &ppp
->ubuf
->locked
); 1526 wake_up_interruptible(&ppp
->read_wait
); 1527 if(ppp
->tty
->fasync
!= NULL
) 1528 kill_fasync(ppp
->tty
->fasync
, SIGIO
); 1532 * The buffer is full. Unlock the header 1535 clear_bit(0, &ppp
->ubuf
->locked
); 1536 if(ppp
->flags
& SC_DEBUG
) 1538 "ppp: rcv_proto_unknown: buffer overflow\n"); 1541 * Discard the frame. There are no takers for this protocol. 1543 if(ppp
->flags
& SC_DEBUG
) 1545 "ppp: rcv_proto_unknown: dropping packet\n"); 1550 * Handle a CCP packet. 1552 * The CCP packet is passed along to the pppd process just like any 1553 * other PPP frame. The difference is that some processing needs to be 1554 * immediate or the compressors will become confused on the peer. 1557 static voidppp_proto_ccp(struct ppp
*ppp
, __u8
*dp
,int len
,int rcvd
) 1559 int slen
=CCP_LENGTH(dp
); 1560 __u8
*opt
= dp
+ CCP_HDRLEN
; 1561 int opt_len
= slen
- CCP_HDRLEN
; 1562 unsigned long flags
; 1568 switch(CCP_CODE(dp
)) { 1573 * CCP must be going down - disable compression 1575 if(ppp
->flags
& SC_CCP_UP
) { 1577 ppp
->flags
&= ~(SC_CCP_UP
| 1584 if((ppp
->flags
& SC_CCP_OPEN
) ==0) 1586 if(ppp
->flags
& SC_CCP_UP
) 1588 if(slen
< (CCP_HDRLEN
+ CCP_OPT_MINLEN
)) 1590 if(slen
< (CCP_OPT_LENGTH(opt
) + CCP_HDRLEN
)) 1593 * we're agreeing to send compressed packets. 1596 if(ppp
->sc_xc_state
== NULL
) 1599 if((*ppp
->sc_xcomp
->comp_init
) 1603 ppp2dev(ppp
)->base_addr
, 1605 ppp
->flags
& SC_DEBUG
)) { 1606 if(ppp
->flags
& SC_DEBUG
) 1607 printk(KERN_DEBUG
"%s: comp running\n", 1610 ppp
->flags
|= SC_COMP_RUN
; 1615 * peer is agreeing to send compressed packets. 1617 if(ppp
->sc_rc_state
== NULL
) 1620 if((*ppp
->sc_rcomp
->decomp_init
) 1624 ppp2dev(ppp
)->base_addr
, 1627 ppp
->flags
& SC_DEBUG
)) { 1628 if(ppp
->flags
& SC_DEBUG
) 1629 printk(KERN_DEBUG
"%s: decomp running\n", 1632 ppp
->flags
|= SC_DECOMP_RUN
; 1633 ppp
->flags
&= ~(SC_DC_ERROR
| SC_DC_FERROR
); 1637 * CCP Reset-ack resets compressors and decompressors as it passes through. 1640 if((ppp
->flags
& SC_CCP_UP
) ==0) 1644 if(ppp
->sc_xc_state
&& (ppp
->flags
& SC_COMP_RUN
)) { 1645 (*ppp
->sc_xcomp
->comp_reset
)(ppp
->sc_xc_state
); 1646 if(ppp
->flags
& SC_DEBUG
) 1647 printk(KERN_DEBUG
"%s: comp reset\n", 1651 if(ppp
->sc_rc_state
&& (ppp
->flags
& SC_DECOMP_RUN
)) { 1652 (*ppp
->sc_rcomp
->decomp_reset
)(ppp
->sc_rc_state
); 1653 if(ppp
->flags
& SC_DEBUG
) 1654 printk(KERN_DEBUG
"%s: decomp reset\n", 1657 ppp
->flags
&= ~SC_DC_ERROR
; 1662 restore_flags(flags
); 1666 rcv_proto_ccp(struct ppp
*ppp
, __u16 proto
, __u8
*dp
,int len
) 1669 ppp_proto_ccp(ppp
, dp
, len
,1); 1670 returnrcv_proto_unknown(ppp
, proto
, dp
, len
); 1674 * Handle a LQR packet. 1678 rcv_proto_lqr(struct ppp
*ppp
, __u16 proto
, __u8
* data
,int len
) 1680 returnrcv_proto_unknown(ppp
, proto
, data
, len
); 1683 /************************************************************* 1684 * LINE DISCIPLINE SUPPORT 1685 * The following functions form support user programs 1686 * which read and write data on a TTY with the PPP line 1687 * discipline. Reading is done from a circular queue, 1688 * filled by the lower TTY levels. 1689 *************************************************************/ 1691 /* read a PPP frame from the us_rbuff circular buffer, 1692 waiting if necessary 1696 ppp_tty_read(struct tty_struct
*tty
,struct file
*file
, __u8
* buf
,size_t nr
) 1698 struct ppp
*ppp
=tty2ppp(tty
); 1705 c = buf_base (ppp->ubuf) [ppp->ubuf->tail++]; \ 1706 ppp->ubuf->tail &= ppp->ubuf->size; \ 1710 * Validate the pointers 1715 /* if (ppp->magic != PPP_MAGIC) 1721 * Before we attempt to write the frame to the user, ensure that the 1722 * user has access to the pages for the total buffer length. 1724 error
=verify_area(VERIFY_WRITE
, buf
, nr
); 1729 * Acquire the read lock. 1733 if(!ppp
|| ppp
->magic
!= PPP_MAGIC
|| !ppp
->inuse
1737 if(test_and_set_bit(0, &ppp
->ubuf
->locked
) !=0) { 1739 if(ppp
->flags
& SC_DEBUG
) 1741 "ppp_tty_read: sleeping(ubuf)\n"); 1743 current
->timeout
=0; 1744 current
->state
= TASK_INTERRUPTIBLE
; 1747 if(signal_pending(current
)) 1753 * Fetch the length of the buffer from the first two bytes. 1755 if(ppp
->ubuf
->head
== ppp
->ubuf
->tail
) 1767 * If there is no length then wait for the data to arrive. 1770 clear_bit(0, &ppp
->ubuf
->locked
); 1771 if(file
->f_flags
& O_NONBLOCK
) 1773 current
->timeout
=0; 1775 if(ppp
->flags
& SC_DEBUG
) 1777 "ppp_tty_read: sleeping(read_wait)\n"); 1779 interruptible_sleep_on(&ppp
->read_wait
); 1780 if(signal_pending(current
)) 1785 * Ensure that the frame will fit within the caller's buffer. If not, then 1786 * discard the frame from the input buffer. 1789 /* Can't copy it, update us_rbuff_head */ 1791 if(ppp
->flags
& SC_DEBUG
) 1793 "ppp: read of %lu bytes too small for %ld " 1794 "frame\n", (unsigned long) nr
, (long) len
+2); 1795 ppp
->stats
.ppp_ierrors
++; 1801 * Fake the insertion of the ADDRESS and CONTROL information because these 1802 * were not saved in the buffer. 1804 error
=put_user((u_char
) PPP_ALLSTATIONS
, buf
); 1808 error
=put_user((u_char
) PPP_UI
, buf
); 1814 * Copy the received data from the buffer to the caller's area. 1816 ret
= len
+2;/* Account for ADDRESS and CONTROL bytes */ 1819 error
=put_user(c
, buf
); 1825 clear_bit(0, &ppp
->ubuf
->locked
); 1829 ppp
->ubuf
->tail
+= len
; 1830 ppp
->ubuf
->tail
&= ppp
->ubuf
->size
; 1831 clear_bit(0, &ppp
->ubuf
->locked
); 1836 /* stuff a character into the transmit buffer, using PPP's way of escaping 1838 also, update fcs to take account of new character */ 1841 ppp_stuff_char(struct ppp
*ppp
,registerstruct ppp_buffer
*buf
, 1845 * The buffer should not be full. 1847 if(ppp
->flags
& SC_DEBUG
) { 1848 if((buf
->count
<0) || (buf
->count
>3000)) 1849 printk(KERN_DEBUG
"ppp_stuff_char: %d %x\n", 1850 (unsigned int) buf
->count
, 1851 (unsigned int) chr
); 1854 * Update the FCS and if the character needs to be escaped, do it. 1856 buf
->fcs
=PPP_FCS(buf
->fcs
, chr
); 1857 if(in_xmap(ppp
, chr
)) { 1859 ins_char(buf
, PPP_ESCAPE
); 1862 * Add the character to the buffer. 1868 * Procedure to encode the data with the proper escaping and send the 1869 * data to the remote system. 1873 ppp_dev_xmit_lower(struct ppp
*ppp
,struct ppp_buffer
*buf
, 1874 __u8
*data
,int count
,int non_ip
) 1877 int address
, control
; 1881 CHECK_BUF_MAGIC(buf
); 1882 ++ppp
->stats
.ppp_opackets
; 1883 ppp
->stats
.ppp_ooctects
+= count
; 1886 * Insert the leading FLAG character 1890 if(non_ip
|| flag_time
==0) 1891 ins_char(buf
, PPP_FLAG
); 1893 if(jiffies
- ppp
->last_xmit
>= flag_time
) 1894 ins_char(buf
, PPP_FLAG
); 1896 ppp
->last_xmit
= jiffies
; 1897 buf
->fcs
= PPP_INITFCS
; 1899 * Emit the address/control information if needed 1901 address
=PPP_ADDRESS(data
); 1902 control
=PPP_CONTROL(data
); 1903 proto
=PPP_PROTOCOL(data
); 1905 if(address
!= PPP_ALLSTATIONS
|| 1906 control
!= PPP_UI
|| 1907 (ppp
->flags
& SC_COMP_AC
) ==0) { 1908 ppp_stuff_char(ppp
, buf
, address
); 1909 ppp_stuff_char(ppp
, buf
, control
); 1912 * Emit the protocol (compressed if possible) 1914 if((ppp
->flags
& SC_COMP_PROT
) ==0|| (proto
&0xFF00)) 1915 ppp_stuff_char(ppp
, buf
, proto
>>8); 1917 ppp_stuff_char(ppp
, buf
, proto
); 1925 ppp_stuff_char(ppp
, buf
, *data
++); 1927 * Add the trailing CRC and the final flag character 1929 write_fcs
= buf
->fcs
^0xFFFF; 1930 ppp_stuff_char(ppp
, buf
, write_fcs
); 1931 ppp_stuff_char(ppp
, buf
, write_fcs
>>8); 1933 * Add the trailing flag character 1935 ins_char(buf
, PPP_FLAG
); 1937 * Send the block to the tty driver. 1939 ppp
->stats
.ppp_obytes
+= buf
->count
; 1940 ppp_kick_tty(ppp
, buf
); 1944 * Compress and send an frame to the peer. 1946 * Return 0 if frame was queued for transmission. 1947 * 1 if frame must be re-queued for later driver support. 1951 ppp_dev_xmit_frame(struct ppp
*ppp
,struct ppp_buffer
*buf
, 1952 __u8
*data
,int count
) 1955 int address
, control
; 1960 CHECK_BUF_MAGIC(buf
); 1964 if(ppp
->flags
& SC_LOG_OUTPKT
) 1965 ppp_print_buffer("write frame", data
, count
); 1967 * Determine if the frame may be compressed. Attempt to compress the 1968 * frame if possible. 1970 proto
=PPP_PROTOCOL(data
); 1971 address
=PPP_ADDRESS(data
); 1972 control
=PPP_CONTROL(data
); 1974 if(((ppp
->flags
& SC_COMP_RUN
) !=0) && 1975 (ppp
->sc_xc_state
!= (void*)0) && 1976 (address
== PPP_ALLSTATIONS
) && 1977 (control
== PPP_UI
) && 1978 (proto
!= PPP_LCP
) && 1979 (proto
!= PPP_CCP
)) { 1980 new_data
=kmalloc(ppp
->mtu
, GFP_ATOMIC
); 1981 if(new_data
== NULL
) { 1982 if(ppp
->flags
& SC_DEBUG
) 1984 "ppp_dev_xmit_frame: no memory\n"); 1988 new_count
= (*ppp
->sc_xcomp
->compress
) 1989 (ppp
->sc_xc_state
, data
, new_data
, count
, ppp
->mtu
); 1991 if(new_count
>0&& (ppp
->flags
& SC_CCP_UP
)) { 1992 ppp_dev_xmit_lower(ppp
, buf
, new_data
, new_count
,0); 1997 * The frame could not be compressed, or it could not be sent in 1998 * compressed form because CCP is not yet up. 2003 * Go to the escape encoding 2005 ppp_dev_xmit_lower(ppp
, buf
, data
, count
, !!(proto
&0xFF00)); 2010 * Revise the tty frame for specific protocols. 2014 send_revise_frame(registerstruct ppp
*ppp
, __u8
*data
,int len
) 2018 switch(PPP_PROTOCOL(data
)) { 2020 * Update the LQR frame with the current MIB information. This saves having 2021 * the daemon read old MIB data from the driver. 2024 len
=48;/* total size of this frame */ 2025 p
= (__u8
*) &data
[40];/* Point to last two items. */ 2026 p
=store_long(p
, ppp
->stats
.ppp_opackets
+1); 2027 p
=store_long(p
, ppp
->stats
.ppp_ooctects
+ len
); 2030 * Outbound compression frames 2047 * write a frame with NR chars from BUF to TTY 2048 * we have to put the FCS field on ourselves 2052 ppp_tty_write(struct tty_struct
*tty
,struct file
*file
,const __u8
* data
, 2055 struct ppp
*ppp
=tty2ppp(tty
); 2058 struct wait_queue wait
= {current
, NULL
}; 2061 * Verify the pointers. 2066 if(ppp
->magic
!= PPP_MAGIC
) 2071 * Ensure that the caller does not wish to send too much. 2073 if(count
> PPP_MTU
+ PPP_HDRLEN
) { 2074 if(ppp
->flags
& SC_DEBUG
) 2076 "ppp_tty_write: truncating user packet " 2077 "from %lu to mtu %d\n", (unsigned long) count
, 2078 PPP_MTU
+ PPP_HDRLEN
); 2079 count
= PPP_MTU
+ PPP_HDRLEN
; 2082 * Allocate a buffer for the data and fetch it from the user space. 2084 new_data
=kmalloc(count
, GFP_KERNEL
); 2085 if(new_data
== NULL
) { 2086 printk(KERN_ERR
"ppp_tty_write: no memory\n"); 2090 * Retrieve the user's buffer 2093 if(copy_from_user(new_data
, data
, count
)) 2096 * Lock this PPP unit so we will be the only writer, 2097 * sleeping if necessary. 2099 * Note that we add our task to the wait queue before 2100 * attempting to lock, as the lock flag may be cleared 2101 * from an interrupt. 2103 add_wait_queue(&ppp
->write_wait
, &wait
); 2106 current
->timeout
=0; 2107 current
->state
= TASK_INTERRUPTIBLE
; 2108 if(lock_buffer(ppp
->tbuf
) ==0) 2114 if(!ppp
|| ppp
->magic
!= PPP_MAGIC
|| 2115 !ppp
->inuse
|| tty
!= ppp
->tty
) { 2116 printk("ppp_tty_write: %p invalid after wait!\n", ppp
); 2120 if(signal_pending(current
)) 2123 current
->state
= TASK_RUNNING
; 2124 remove_wait_queue(&ppp
->write_wait
, &wait
); 2129 * Change the LQR frame 2131 count
=send_revise_frame(ppp
, new_data
, count
); 2135 if(PPP_PROTOCOL(new_data
) == PPP_IP
) { 2137 * IP frames can be sent by pppd when we're doing 2138 * demand-dialling. We send them via ppp_dev_xmit_ip 2139 * to make sure that VJ compression happens properly. 2141 ppp_dev_xmit_ip(ppp
, ppp
->tbuf
, new_data
+ PPP_HDRLEN
, 2142 count
- PPP_HDRLEN
, NPMODE_PASS
); 2145 ppp_dev_xmit_frame(ppp
, ppp
->tbuf
, new_data
, count
); 2156 * Process the BSD compression IOCTL event for the tty device. 2160 ppp_set_compression(struct ppp
*ppp
,struct ppp_option_data
*odp
) 2162 struct compressor
*cp
; 2164 unsigned long flags
; 2166 __u8 ccp_option
[CCP_MAX_OPTION_LENGTH
]; 2167 struct ppp_option_data data
; 2170 * Fetch the compression parameters 2173 if(copy_from_user(&data
, odp
,sizeof(data
))) 2178 if((__u32
) nb
>= (__u32
)CCP_MAX_OPTION_LENGTH
) 2179 nb
= CCP_MAX_OPTION_LENGTH
; 2181 if(copy_from_user(ccp_option
, ptr
, nb
)) 2185 if(ccp_option
[1] <2)/* preliminary check on the length byte */ 2190 ppp
->flags
&= ~(SC_COMP_RUN
| SC_DECOMP_RUN
); 2191 restore_flags(flags
); 2193 cp
=find_compressor(ccp_option
[0]); 2197 sprintf(modname
,"ppp-compress-%d", ccp_option
[0]); 2198 request_module(modname
); 2199 cp
=find_compressor(ccp_option
[0]); 2201 #endif/* CONFIG_KMOD */ 2206 * Found a handler for the protocol - try to allocate 2207 * a compressor or decompressor. 2211 if(ppp
->sc_xc_state
!= NULL
) 2212 (*ppp
->sc_xcomp
->comp_free
)(ppp
->sc_xc_state
); 2213 ppp
->sc_xc_state
= NULL
; 2216 ppp
->sc_xc_state
= cp
->comp_alloc(ccp_option
, nb
); 2217 if(ppp
->sc_xc_state
== NULL
) { 2218 printk(KERN_WARNING
"%s: comp_alloc failed\n", 2221 }else if(ppp
->flags
& SC_DEBUG
) 2222 printk(KERN_DEBUG
"%s: comp_alloc -> %p\n", 2223 ppp
->name
, ppp
->sc_xc_state
); 2225 if(ppp
->sc_rc_state
!= NULL
) 2226 (*ppp
->sc_rcomp
->decomp_free
)(ppp
->sc_rc_state
); 2227 ppp
->sc_rc_state
= NULL
; 2230 ppp
->sc_rc_state
= cp
->decomp_alloc(ccp_option
, nb
); 2231 if(ppp
->sc_rc_state
== NULL
) { 2232 printk(KERN_WARNING
"%s: decomp_alloc failed\n", 2235 }else if(ppp
->flags
& SC_DEBUG
) 2236 printk(KERN_DEBUG
"%s: decomp_alloc -> %p\n", 2237 ppp
->name
, ppp
->sc_rc_state
); 2243 error
= -EINVAL
;/* no handler found */ 2244 if(ppp
->flags
& SC_DEBUG
) 2245 printk(KERN_DEBUG
"%s: no compressor for [%x %x %x], %x\n", 2246 ppp
->name
, ccp_option
[0], ccp_option
[1], 2252 * Process the IOCTL event for the tty device. 2256 ppp_tty_ioctl(struct tty_struct
*tty
,struct file
* file
, 2257 unsigned int param2
,unsigned long param3
) 2259 struct ppp
*ppp
=tty2ppp(tty
); 2260 registerint temp_i
=0; 2263 * Verify the status of the PPP device. 2268 if(ppp
->magic
!= PPP_MAGIC
) 2273 * The user must have an euid of root to do these requests. 2282 error
=get_user(temp_i
, (int*) param3
); 2285 if(ppp
->flags
& SC_DEBUG
) 2287 "ppp_tty_ioctl: set mru to %x\n", temp_i
); 2289 if(ppp
->mru
!= temp_i
) 2290 ppp_changedmtu(ppp
,ppp2dev(ppp
)->mtu
, temp_i
); 2296 temp_i
= (ppp
->flags
& SC_MASK
); 2297 #ifndef CHECK_CHARACTERS/* Don't generate errors if we don't check chars. */ 2298 temp_i
|= SC_RCV_B7_1
| SC_RCV_B7_0
| 2299 SC_RCV_ODDP
| SC_RCV_EVNP
; 2301 error
=put_user(temp_i
, (int*) param3
); 2304 * Set the flags for the various options 2307 error
=get_user(temp_i
, (int*) param3
); 2311 temp_i
|= (ppp
->flags
& ~SC_MASK
); 2313 if((ppp
->flags
& SC_CCP_OPEN
) && 2314 (temp_i
& SC_CCP_OPEN
) ==0) 2315 ppp_ccp_closed(ppp
); 2317 if((ppp
->flags
| temp_i
) & SC_DEBUG
) 2319 "ppp_tty_ioctl: set flags to %x\n", temp_i
); 2320 ppp
->flags
= temp_i
; 2323 * Set the compression mode 2325 case PPPIOCSCOMPRESS
: 2326 error
=ppp_set_compression(ppp
, 2327 (struct ppp_option_data
*) param3
); 2330 * Retrieve the transmit async map 2332 case PPPIOCGASYNCMAP
: 2333 error
=put_user(ppp
->xmit_async_map
[0], (int*) param3
); 2336 * Set the transmit async map 2338 case PPPIOCSASYNCMAP
: 2339 error
=get_user(temp_i
, (int*) param3
); 2342 ppp
->xmit_async_map
[0] = temp_i
; 2343 if(ppp
->flags
& SC_DEBUG
) 2345 "ppp_tty_ioctl: set xmit asyncmap %x\n", 2346 ppp
->xmit_async_map
[0]); 2349 * Set the receive async map 2351 case PPPIOCSRASYNCMAP
: 2352 error
=get_user(temp_i
, (int*) param3
); 2355 ppp
->recv_async_map
= temp_i
; 2356 if(ppp
->flags
& SC_DEBUG
) 2358 "ppp_tty_ioctl: set rcv asyncmap %x\n", 2359 ppp
->recv_async_map
); 2362 * Obtain the unit number for this device. 2365 error
=put_user(ppp2dev(ppp
)->base_addr
, (int*) param3
); 2368 if(ppp
->flags
& SC_DEBUG
) 2370 "ppp_tty_ioctl: get unit: %ld\n", 2371 ppp2dev(ppp
)->base_addr
); 2374 * Set the debug level 2377 error
=get_user(temp_i
, (int*) param3
); 2380 temp_i
= (temp_i
&0x1F) <<16; 2381 temp_i
|= (ppp
->flags
& ~0x1F0000); 2383 if((ppp
->flags
| temp_i
) & SC_DEBUG
) 2385 "ppp_tty_ioctl: set flags to %x\n", temp_i
); 2386 ppp
->flags
= temp_i
; 2389 * Get the debug level 2392 temp_i
= (ppp
->flags
>>16) &0x1F; 2393 error
=put_user(temp_i
, (int*) param3
); 2396 * Get the times since the last send/receive frame operation 2400 struct ppp_idle cur_ddinfo
; 2402 /* change absolute times to relative times. */ 2403 cur_ddinfo
.xmit_idle
= (jiffies
- ppp
->last_xmit
) / HZ
; 2404 cur_ddinfo
.recv_idle
= (jiffies
- ppp
->last_recv
) / HZ
; 2406 if(!copy_to_user((void*) param3
, &cur_ddinfo
, 2407 sizeof(cur_ddinfo
))) 2412 * Retrieve the extended async map 2414 case PPPIOCGXASYNCMAP
: 2416 if(!copy_to_user((void*) param3
, ppp
->xmit_async_map
, 2417 sizeof(ppp
->xmit_async_map
))) 2421 * Set the async extended map 2423 case PPPIOCSXASYNCMAP
: 2428 if(copy_from_user(temp_tbl
, (void*) param3
, 2432 temp_tbl
[1] =0x00000000; 2433 temp_tbl
[2] &= ~0x40000000; 2434 temp_tbl
[3] |=0x60000000; 2437 if((temp_tbl
[2] & temp_tbl
[3]) !=0|| 2438 (temp_tbl
[4] & temp_tbl
[5]) !=0|| 2439 (temp_tbl
[6] & temp_tbl
[7]) !=0) 2442 memcpy(ppp
->xmit_async_map
, 2444 sizeof(ppp
->xmit_async_map
)); 2446 if(ppp
->flags
& SC_DEBUG
) 2448 "ppp_tty_ioctl: set xasyncmap\n"); 2453 * Set the maximum VJ header compression slot number. 2456 error
=get_user(temp_i
, (int*) param3
); 2459 temp_i
= (temp_i
&255) +1; 2460 if(ppp
->flags
& SC_DEBUG
) 2462 "ppp_tty_ioctl: set maxcid to %d\n", temp_i
); 2463 if(ppp
->slcomp
!= NULL
) 2464 slhc_free(ppp
->slcomp
); 2467 ppp
->slcomp
=slhc_init(16, temp_i
); 2468 if(ppp
->slcomp
== NULL
) { 2469 printk(KERN_ERR
"ppp_tty_ioctl: " 2470 "no space for compression buffers!\n"); 2476 case PPPIOCXFERUNIT
: 2477 ppp
->backup_tty
= tty
; 2478 ppp
->sc_xfer
= current
->pid
; 2487 if(copy_from_user(&npi
, (void*) param3
,sizeof(npi
))) 2490 if(npi
.protocol
!= PPP_IP
) { 2491 if(ppp
->flags
& SC_DEBUG
) 2492 printk(KERN_DEBUG
"pppioc[gs]npmode: " 2493 "invalid protocol %d\n", 2498 npi
.protocol
= NP_IP
; 2500 if(param2
== PPPIOCGNPMODE
) { 2501 npi
.mode
= ppp
->sc_npmode
[npi
.protocol
]; 2502 if(copy_to_user((void*) param3
, &npi
, 2507 ppp
->sc_npmode
[npi
.protocol
] = npi
.mode
; 2508 if(ppp
->flags
& SC_DEBUG
) 2509 printk(KERN_DEBUG
"ppp: set np %d to %d\n", 2510 npi
.protocol
, npi
.mode
); 2511 /* N.B. Why is the busy flag cleared here? */ 2512 ppp2dev(ppp
)->tbusy
=0; 2518 * Allow users to read, but not set, the serial port parameters 2522 error
=n_tty_ioctl(tty
, file
, param2
, param3
); 2527 int count
= ppp
->ubuf
->tail
- ppp
->ubuf
->head
; 2529 count
+= (ppp
->ubuf
->size
+1); 2530 error
=put_user(count
, (int*) param3
); 2534 * All other ioctl() events will come here. 2537 if(ppp
->flags
& SC_DEBUG
) 2538 printk(KERN_WARNING
"ppp_tty_ioctl: " 2539 "invalid ioctl=%x, addr=%lx\n", param2
, param3
); 2540 error
= -ENOIOCTLCMD
; 2549 * Process the poll() statement for the PPP device. 2553 ppp_tty_poll(struct tty_struct
*tty
,struct file
*filp
, poll_table
* wait
) 2555 struct ppp
*ppp
=tty2ppp(tty
); 2556 unsigned int mask
=0; 2558 if(ppp
&& ppp
->magic
== PPP_MAGIC
&& tty
== ppp
->tty
) { 2561 poll_wait(filp
, &ppp
->read_wait
, wait
); 2562 poll_wait(filp
, &ppp
->write_wait
, wait
); 2564 /* Must lock the user buffer area while checking. */ 2565 CHECK_BUF_MAGIC(ppp
->ubuf
); 2566 if(test_and_set_bit(0, &ppp
->ubuf
->locked
) ==0) { 2567 if(ppp
->ubuf
->head
!= ppp
->ubuf
->tail
) 2568 mask
|= POLLIN
| POLLRDNORM
; 2569 clear_bit(0, &ppp
->ubuf
->locked
); 2571 if(tty
->flags
& (1<< TTY_OTHER_CLOSED
)) 2573 if(tty_hung_up_p(filp
)) 2575 if(ppp
->tbuf
->locked
==0) 2576 mask
|= POLLOUT
| POLLWRNORM
; 2581 /************************************************************* 2583 * This routine accepts requests from the network layer 2584 * and attempts to deliver the packets. 2585 * It also includes various routines we are compelled to 2586 * have to make the network layer work (arp, etc...). 2587 *************************************************************/ 2590 * Callback from the network layer when the device goes up. 2594 ppp_dev_open(struct device
*dev
) 2596 struct ppp
*ppp
=dev2ppp(dev
); 2598 if(ppp2tty(ppp
) == NULL
) { 2600 "ppp: %s not connected to a TTY! can't go open!\n", 2605 if(ppp
->flags
& SC_DEBUG
) 2607 "ppp: channel %s going up for IP packets!\n", 2615 * Callback from the network layer when the ppp device goes down. 2619 ppp_dev_close(struct device
*dev
) 2621 struct ppp
*ppp
=dev2ppp(dev
); 2623 if(ppp2tty(ppp
) == NULL
) { 2627 * We don't do anything about the device going down. It is not important 2630 if(ppp
->flags
& SC_DEBUG
) 2632 "ppp: channel %s going down for IP packets!\n", 2639 * IOCTL operation to read the version of the driver. 2643 ppp_dev_ioctl_version(struct ppp
*ppp
,struct ifreq
*ifr
) 2646 char*result
= (char*) ifr
->ifr_ifru
.ifru_data
; 2647 int len
=strlen(szVersion
) +1; 2649 * Move the version data 2652 if(!copy_to_user(result
, szVersion
, len
)) 2658 * IOCTL to read the statistics for the pppstats program. 2662 ppp_dev_ioctl_stats(struct ppp
*ppp
,struct ifreq
*ifr
,struct device
*dev
) 2664 struct ppp_stats
*result
, temp
; 2667 * Supply the information for the caller. First move the version data 2668 * then move the ppp stats; and finally the vj stats. 2670 memset(&temp
,0,sizeof(temp
)); 2671 if(dev
->flags
& IFF_UP
) { 2672 memcpy(&temp
.p
, &ppp
->stats
,sizeof(struct pppstat
)); 2673 if(ppp
->slcomp
!= NULL
) { 2674 temp
.vj
.vjs_packets
= ppp
->slcomp
->sls_o_compressed
+ 2675 ppp
->slcomp
->sls_o_uncompressed
; 2676 temp
.vj
.vjs_compressed
= ppp
->slcomp
->sls_o_compressed
; 2677 temp
.vj
.vjs_searches
= ppp
->slcomp
->sls_o_searches
; 2678 temp
.vj
.vjs_misses
= ppp
->slcomp
->sls_o_misses
; 2679 temp
.vj
.vjs_errorin
= ppp
->slcomp
->sls_i_error
; 2680 temp
.vj
.vjs_tossed
= ppp
->slcomp
->sls_i_tossed
; 2681 temp
.vj
.vjs_uncompressedin
= ppp
->slcomp
->sls_i_uncompressed
; 2682 temp
.vj
.vjs_compressedin
= ppp
->slcomp
->sls_i_compressed
; 2686 result
= (struct ppp_stats
*) ifr
->ifr_ifru
.ifru_data
; 2689 if(!copy_to_user(result
, &temp
,sizeof(temp
))) 2695 * IOCTL to read the compression statistics for the pppstats program. 2699 ppp_dev_ioctl_comp_stats(struct ppp
*ppp
,struct ifreq
*ifr
,struct device
*dev
) 2701 struct ppp_comp_stats
*result
, temp
; 2704 * Supply the information for the caller. 2706 memset(&temp
,0,sizeof(temp
)); 2707 if(dev
->flags
& IFF_UP
) { 2708 if(ppp
->sc_xc_state
!= NULL
) 2709 (*ppp
->sc_xcomp
->comp_stat
) (ppp
->sc_xc_state
, 2712 if(ppp
->sc_rc_state
!= NULL
) 2713 (*ppp
->sc_rcomp
->decomp_stat
) (ppp
->sc_rc_state
, 2717 * Move the data to the caller's buffer 2719 result
= (struct ppp_comp_stats
*) ifr
->ifr_ifru
.ifru_data
; 2722 if(!copy_to_user(result
, &temp
,sizeof(temp
))) 2728 * Callback from the network layer to process the sockioctl functions. 2732 ppp_dev_ioctl(struct device
*dev
,struct ifreq
*ifr
,int cmd
) 2734 struct ppp
*ppp
=dev2ppp(dev
); 2737 CHECK_PPP_MAGIC(ppp
); 2739 * Process the requests 2743 error
=ppp_dev_ioctl_stats(ppp
, ifr
, dev
); 2746 case SIOCGPPPCSTATS
: 2747 error
=ppp_dev_ioctl_comp_stats(ppp
, ifr
, dev
); 2751 error
=ppp_dev_ioctl_version(ppp
, ifr
); 2762 * Send an IP frame to the remote with vj header compression. 2764 * Return 0 if frame was queued for transmission. 2765 * 1 if frame must be re-queued for later driver support. 2766 * -1 if frame should be dropped. 2770 ppp_dev_xmit_ip(struct ppp
*ppp
,struct ppp_buffer
*buf
, 2771 __u8
*data
,int len
,enum NPmode npmode
) 2776 * Branch on the type of processing for the IP frame. 2784 * We may not send the packet now, so drop it. 2785 * XXX It would be nice to be able to return it to the 2786 * network system to be queued and retransmitted later. 2788 if(ppp
->flags
& SC_DEBUG
) 2789 printk(KERN_DEBUG
"%s: returning frame\n", 2795 if(ppp
->flags
& SC_DEBUG
) 2797 "ppp_dev_xmit: npmode = %d on %s\n", 2798 ppp
->sc_npmode
[NP_IP
], ppp
->name
); 2802 if(ppp
->flags
& SC_DEBUG
) 2804 "ppp_dev_xmit: unknown npmode %d on %s\n", 2805 ppp
->sc_npmode
[NP_IP
], ppp
->name
); 2809 * At this point, the buffer will be transmitted. There is no other exit. 2811 * Try to compress the header. 2813 if(ppp
->flags
& SC_COMP_TCP
) { 2814 len
=slhc_compress(ppp
->slcomp
, data
, len
, 2815 buf_base(ppp
->cbuf
) + PPP_HDRLEN
, 2817 (ppp
->flags
& SC_NO_TCP_CCID
) ==0); 2819 if(data
[0] & SL_TYPE_COMPRESSED_TCP
) { 2820 proto
= PPP_VJC_COMP
; 2821 data
[0] ^= SL_TYPE_COMPRESSED_TCP
; 2823 if(data
[0] >= SL_TYPE_UNCOMPRESSED_TCP
) 2824 proto
= PPP_VJC_UNCOMP
; 2825 data
[0] = (data
[0] &0x0f) |0x40; 2832 hdr
= data
- PPP_HDRLEN
; 2834 hdr
[0] = PPP_ALLSTATIONS
; 2839 returnppp_dev_xmit_frame(ppp
, buf
, hdr
, len
); 2843 * Send a non-IP data frame (such as an IPX frame) to the remote. 2845 * Return 0 if frame was queued for transmission. 2846 * 1 if frame must be re-queued for later driver support. 2849 ppp_dev_xmit_other(struct device
*dev
,struct ppp
*ppp
, 2850 __u8
*data
,int len
,int proto
) 2857 hdr
= data
- PPP_HDRLEN
; 2859 hdr
[0] = PPP_ALLSTATIONS
; 2864 returnppp_dev_xmit_frame(ppp
, ppp
->wbuf
, hdr
, len
); 2868 * Send a frame to the remote. 2872 ppp_dev_xmit(sk_buff
*skb
,struct device
*dev
) 2876 struct ppp
*ppp
=dev2ppp(dev
); 2877 struct tty_struct
*tty
=ppp2tty(ppp
); 2879 * just a little sanity check. 2882 if(ppp
->flags
& SC_DEBUG
) 2883 printk(KERN_WARNING
"ppp_dev_xmit: null packet!\n"); 2887 * Avoid timing problem should tty hangup while data is queued to be sent 2894 * Validate the tty interface 2897 if(ppp
->flags
& SC_DEBUG
) 2899 "ppp_dev_xmit: %s not connected to a TTY!\n", 2905 * Fetch the pointer to the data 2908 data
=skb_data(skb
); 2910 if(data
== (__u8
*)0) { 2911 if(ppp
->flags
& SC_DEBUG
) 2912 printk(KERN_CRIT
"ppp_dev_xmit: %s Null skb data\n", 2918 * Detect a change in the transfer size 2920 if(ppp
->mtu
!=ppp2dev(ppp
)->mtu
) { 2926 * Acquire the lock on the transmission buffer. If the buffer was busy then 2927 * mark the device as busy. 2928 * We also require that ppp->tbuf be unlocked, in order to serialize 2929 * calls to ppp_dev_xmit_frame (which does compression) and the output 2930 * of frames w.r.t. tty writes from pppd. 2932 CHECK_BUF_MAGIC(ppp
->wbuf
); 2933 if(ppp
->tbuf
->locked
||lock_buffer(ppp
->wbuf
) !=0) { 2935 if(ppp
->flags
& SC_DEBUG
) 2936 printk(KERN_DEBUG
"dev_xmit blocked, t=%lu w=%lu\n", 2937 ppp
->tbuf
->locked
, ppp
->wbuf
->locked
); 2941 * Look at the protocol in the skb to determine the difference between 2942 * an IP frame and an IPX frame. 2944 switch(ntohs(skb
->protocol
)) { 2946 answer
=ppp_dev_xmit_other(dev
, ppp
, data
, len
, PPP_IPX
); 2950 answer
=ppp_dev_xmit_ip(ppp
, ppp
->wbuf
, data
, len
, 2951 ppp
->sc_npmode
[NP_IP
]); 2954 default:/* All others have no support at this time. */ 2959 * This is the end of the transmission. Release the buffer if it was sent. 2962 /* packet queued OK */ 2965 ppp
->wbuf
->locked
=0; 2967 /* packet should be dropped */ 2971 /* packet should be queued for later */ 2979 * Generate the statistic information for the /proc/net/dev listing. 2982 static struct net_device_stats
* 2983 ppp_dev_stats(struct device
*dev
) 2985 struct ppp
*ppp
=dev2ppp(dev
); 2987 ppp
->estats
.rx_packets
= ppp
->stats
.ppp_ipackets
; 2988 ppp
->estats
.rx_errors
= ppp
->stats
.ppp_ierrors
; 2989 ppp
->estats
.tx_packets
= ppp
->stats
.ppp_opackets
; 2990 ppp
->estats
.tx_errors
= ppp
->stats
.ppp_oerrors
; 2991 ppp
->estats
.rx_bytes
= ppp
->stats
.ppp_ibytes
; 2992 ppp
->estats
.tx_bytes
= ppp
->stats
.ppp_obytes
; 2997 /************************************************************* 2999 * Miscellany called by various functions above. 3000 *************************************************************/ 3002 /* Locate the previous instance of the PPP channel */ 3004 ppp_find(int pid_value
) 3008 /* try to find the device which this pid is already using */ 3009 for(ppp
= ppp_list
; ppp
!=0; ppp
= ppp
->next
) { 3010 if(ppp
->inuse
&& ppp
->sc_xfer
== pid_value
) { 3018 /* Collect hanged up channels */ 3020 static voidppp_sync(void) 3026 for(ppp
= ppp_list
; ppp
!=0; ppp
= ppp
->next
) { 3029 if(dev
->flags
&IFF_UP
) 3037 /* allocate or create a PPP channel */ 3048 /* try to find an free device */ 3050 for(ppp
= ppp_list
; ppp
!=0; ppp
= ppp
->next
) { 3051 if(!test_and_set_bit(0, &ppp
->inuse
)) { 3053 /* Reregister device */ 3056 unregister_netdev(dev
); 3058 if(register_netdev(dev
)) { 3059 printk(KERN_DEBUG
"cannot reregister ppp device\n"); 3067 * There are no available units, so make a new one. 3069 ppp
= (struct ppp
*)kmalloc(sizeof(struct ppp
), GFP_KERNEL
); 3072 memset(ppp
,0,sizeof(*ppp
)); 3074 /* initialize channel control data */ 3075 set_bit(0, &ppp
->inuse
); 3079 ppp
->backup_tty
= NULL
; 3083 ppp_last
->next
= ppp
; 3089 dev
->init
= ppp_init_dev
; 3090 dev
->name
= ppp
->name
; 3091 sprintf(dev
->name
,"ppp%d", if_num
); 3092 dev
->base_addr
= (__u32
) if_num
; 3093 dev
->priv
= (void*) ppp
; 3095 /* register device so that we can be ifconfig'd */ 3096 /* ppp_init_dev() will be called as a side-effect */ 3097 status
=register_netdev(dev
); 3099 printk(KERN_INFO
"registered device %s\n", dev
->name
); 3102 "ppp_alloc - register_netdev(%s) = %d failure.\n", 3105 /* This one will forever be busy as it is not initialized */ 3111 * Utility procedures to print a buffer in hex/ascii 3115 ppp_print_hex(register __u8
* out
,const __u8
* in
,int count
) 3117 register __u8 next_ch
; 3118 static char hex
[] ="0123456789ABCDEF"; 3122 *out
++ = hex
[(next_ch
>>4) &0x0F]; 3123 *out
++ = hex
[next_ch
&0x0F]; 3129 ppp_print_char(register __u8
* out
,const __u8
* in
,int count
) 3131 register __u8 next_ch
; 3136 if(next_ch
<0x20|| next_ch
>0x7e) 3140 if(next_ch
=='%')/* printk/syslogd has a bug !! */ 3148 ppp_print_buffer(const __u8
* name
,const __u8
* buf
,int count
) 3152 if(name
!= (__u8
*) NULL
) 3153 printk(KERN_DEBUG
"ppp: %s, count = %d\n", name
, count
); 3157 ppp_print_hex(line
, buf
,8); 3158 ppp_print_char(&line
[8*3], buf
,8); 3159 printk(KERN_DEBUG
"%s\n", line
); 3166 ppp_print_hex(line
, buf
, count
); 3167 ppp_print_char(&line
[8*3], buf
, count
); 3168 printk(KERN_DEBUG
"%s\n", line
); 3172 /************************************************************* 3173 * Compressor module interface 3174 *************************************************************/ 3176 struct compressor_link
{ 3177 struct compressor_link
*next
; 3178 struct compressor
*comp
; 3181 static struct compressor_link
*ppp_compressors
= (struct compressor_link
*)0; 3183 static struct compressor
*find_compressor(int type
) 3185 struct compressor_link
*lnk
; 3186 unsigned long flags
; 3191 lnk
= ppp_compressors
; 3192 while(lnk
!= (struct compressor_link
*)0) { 3193 if((int) (__u8
) lnk
->comp
->compress_proto
== type
) { 3194 restore_flags(flags
); 3200 restore_flags(flags
); 3201 return(struct compressor
*)0; 3204 static intppp_register_compressor(struct compressor
*cp
) 3206 struct compressor_link
*new; 3207 unsigned long flags
; 3209 new= (struct compressor_link
*)kmalloc(sizeof(struct compressor_link
), GFP_KERNEL
); 3211 if(new== (struct compressor_link
*)0) 3217 if(find_compressor(cp
->compress_proto
)) { 3218 restore_flags(flags
); 3223 new->next
= ppp_compressors
; 3225 ppp_compressors
=new; 3227 restore_flags(flags
); 3231 static voidppp_unregister_compressor(struct compressor
*cp
) 3233 struct compressor_link
*prev
= (struct compressor_link
*)0; 3234 struct compressor_link
*lnk
; 3235 unsigned long flags
; 3240 lnk
= ppp_compressors
; 3241 while(lnk
!= (struct compressor_link
*)0) { 3242 if(lnk
->comp
== cp
) { 3244 prev
->next
= lnk
->next
; 3246 ppp_compressors
= lnk
->next
; 3253 restore_flags(flags
); 3256 /************************************************************* 3257 * Module support routines 3258 *************************************************************/ 3266 /* register our line disciplines */ 3267 status
=ppp_first_time(); 3270 "PPP: ppp_init() failure %d\n", status
); 3275 cleanup_module(void) 3279 struct ppp
*ppp
, *next_ppp
; 3282 * Ensure that the devices are not in operation. 3284 for(ppp
= ppp_list
; ppp
!=0; ppp
= ppp
->next
) { 3285 if(ppp
->inuse
&& ppp
->tty
!= NULL
) { 3291 if(dev
->start
|| dev
->flags
& IFF_UP
) { 3297 * Ensure that there are no compressor modules registered 3299 if(ppp_compressors
!= NULL
) 3304 "PPP: device busy, remove delayed\n"); 3308 * Release the tty registration of the line discipline so that no new entries 3311 status
=tty_register_ldisc(N_PPP
, NULL
); 3314 "PPP: Unable to unregister ppp line discipline " 3315 "(err = %d)\n", status
); 3318 "PPP: ppp line discipline successfully unregistered\n"); 3320 * De-register the devices so that there is no problem with them 3322 for(ppp
= ppp_list
; ppp
!=0; ppp
= next_ppp
) { 3323 next_ppp
= ppp
->next
; 3325 unregister_netdev(&ppp
->dev
);