- error = 0;
- if (data.transmit) {
- if (ppp->sc_xc_state != NULL)
- (*ppp->sc_xcomp->comp_free)(ppp->sc_xc_state);
- ppp->sc_xc_state = NULL;
-
- ppp->sc_xcomp = cp;
- ppp->sc_xc_state = cp->comp_alloc(ccp_option, nb);
- if (ppp->sc_xc_state == NULL) {
- printk(KERN_WARNING "%s: comp_alloc failed\n",
- ppp->name);
- error = -ENOBUFS;
- } else if (ppp->flags & SC_DEBUG)
- printk(KERN_DEBUG "%s: comp_alloc -> %p\n",
- ppp->name, ppp->sc_xc_state);
- } else {
- if (ppp->sc_rc_state != NULL)
- (*ppp->sc_rcomp->decomp_free)(ppp->sc_rc_state);
- ppp->sc_rc_state = NULL;
-
- ppp->sc_rcomp = cp;
- ppp->sc_rc_state = cp->decomp_alloc(ccp_option, nb);
- if (ppp->sc_rc_state == NULL) {
- printk(KERN_WARNING "%s: decomp_alloc failed\n",
- ppp->name);
- error = -ENOBUFS;
- } else if (ppp->flags & SC_DEBUG)
- printk(KERN_DEBUG "%s: decomp_alloc -> %p\n",
- ppp->name, ppp->sc_rc_state);
- }
- return error;
-
-out_no_comp:
- if (ppp->flags & SC_DEBUG)
- printk(KERN_DEBUG "%s: no compressor for [%x %x %x], %x\n",
- ppp->name, ccp_option[0], ccp_option[1],
- ccp_option[2], nb);
- return (-EINVAL); /* no handler found */
-}
-
-/*
- * Process the IOCTL event for the tty device.
- */
-
-static int
-ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
- unsigned int param2, unsigned long param3)
-{
- struct ppp *ppp = tty2ppp (tty);
- register int temp_i = 0, oldflags;
- int error = 0;
- unsigned long flags;
-/*
- * Verify the status of the PPP device.
- */
- if (!ppp)
- return -EBADF;
-
- if (ppp->magic != PPP_MAGIC)
- return -EBADF;
-
- CHECK_PPP (-ENXIO);
-/*
- * The user must have an euid of root to do these requests.
- */
- if (!suser ())
- return -EPERM;
-/*
- * Set the MRU value
- */
- switch (param2) {
- case PPPIOCSMRU:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set mru to %x\n", temp_i);
-
- if (ppp->mru != temp_i)
- ppp_changedmtu (ppp, ppp2dev (ppp)->mtu, temp_i);
- break;
-/*
- * Fetch the flags
- */
- case PPPIOCGFLAGS:
- temp_i = (ppp->flags & SC_MASK);
-#ifndef CHECK_CHARACTERS /* Don't generate errors if we don't check chars. */
- temp_i |= SC_RCV_B7_1 | SC_RCV_B7_0 |
- SC_RCV_ODDP | SC_RCV_EVNP;
-#endif
- PUT_USER (error, temp_i, (int *) param3);
- break;
-/*
- * Set the flags for the various options
- */
- case PPPIOCSFLAGS:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- temp_i &= SC_MASK;
-
- if ((ppp->flags & SC_CCP_OPEN) && (temp_i & SC_CCP_OPEN) == 0)
- ppp_ccp_closed(ppp);
-
- save_flags(flags);
- cli();
- oldflags = ppp->flags;
- ppp->flags = temp_i |= (ppp->flags & ~SC_MASK);
- restore_flags(flags);
- if ((oldflags | temp_i) & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set flags to %x\n", temp_i);
- break;
-/*
- * Set the compression mode
- */
- case PPPIOCSCOMPRESS:
- error = ppp_set_compression (ppp,
- (struct ppp_option_data *) param3);
- break;
-/*
- * Retrieve the transmit async map
- */
- case PPPIOCGASYNCMAP:
- PUT_USER (error, ppp->xmit_async_map[0], (int *) param3);
- break;
-/*
- * Set the transmit async map
- */
- case PPPIOCSASYNCMAP:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- ppp->xmit_async_map[0] = temp_i;
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set xmit asyncmap %x\n",
- ppp->xmit_async_map[0]);
- break;
-/*
- * Set the receive async map
- */
- case PPPIOCSRASYNCMAP:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- ppp->recv_async_map = temp_i;
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set rcv asyncmap %x\n",
- ppp->recv_async_map);
- break;
-/*
- * Obtain the unit number for this device.
- */
- case PPPIOCGUNIT:
- PUT_USER (error, ppp2dev (ppp)->base_addr, (int *) param3);
- if (error != 0)
- break;
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: get unit: %ld\n",
- ppp2dev (ppp)->base_addr);
- break;
-/*
- * Set the debug level
- */
- case PPPIOCSDEBUG:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- temp_i = (temp_i & 0x1F) << 16;
- temp_i |= (ppp->flags & ~0x1F0000);
-
- if ((ppp->flags | temp_i) & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set flags to %x\n", temp_i);
- ppp->flags = temp_i;
- break;
-/*
- * Get the debug level
- */
- case PPPIOCGDEBUG:
- temp_i = (ppp->flags >> 16) & 0x1F;
- PUT_USER (error, temp_i, (int *) param3);
- break;
-/*
- * Get the times since the last send/receive frame operation
- */
- case PPPIOCGIDLE:
- {
- struct ppp_idle cur_ddinfo;
-
- /* change absolute times to relative times. */
- cur_ddinfo.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
- cur_ddinfo.recv_idle = (jiffies - ppp->last_recv) / HZ;
- COPY_TO_USER (error, (void *) param3, &cur_ddinfo,
- sizeof (cur_ddinfo));
- }
- break;
-/*
- * Retrieve the extended async map
- */
- case PPPIOCGXASYNCMAP:
- COPY_TO_USER (error, (void *) param3, ppp->xmit_async_map,
- sizeof (ppp->xmit_async_map));
- break;
-/*
- * Set the async extended map
- */
- case PPPIOCSXASYNCMAP:
- {
- __u32 temp_tbl[8];
-
- COPY_FROM_USER (error, temp_tbl, (void *) param3,
- sizeof (temp_tbl));
- if (error != 0)
- break;
-
- temp_tbl[1] = 0x00000000;
- temp_tbl[2] &= ~0x40000000;
- temp_tbl[3] |= 0x60000000;
-
- if ((temp_tbl[2] & temp_tbl[3]) != 0 ||
- (temp_tbl[4] & temp_tbl[5]) != 0 ||
- (temp_tbl[6] & temp_tbl[7]) != 0)
- error = -EINVAL;
- else {
- memcpy (ppp->xmit_async_map,
- temp_tbl,
- sizeof (ppp->xmit_async_map));
-
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set xasyncmap\n");
- }
- }
- break;
-/*
- * Set the maximum VJ header compression slot number.
- */
- case PPPIOCSMAXCID:
- GET_USER (error, temp_i, (int *) param3);
- if (error != 0)
- break;
- temp_i = (temp_i & 255) + 1;
- if (ppp->flags & SC_DEBUG)
- printk (KERN_INFO
- "ppp_tty_ioctl: set maxcid to %d\n", temp_i);
- if (ppp->slcomp != NULL)
- slhc_free (ppp->slcomp);
- ppp->slcomp = NULL;
-
- ppp->slcomp = slhc_init (16, temp_i);
- if (ppp->slcomp == NULL) {
- printk (KERN_ERR "ppp_tty_ioctl: "
- "no space for compression buffers!\n");
- ppp_release (ppp);
- error = -ENOMEM;
- }
- break;
-
- case PPPIOCXFERUNIT:
- ppp->backup_tty = tty;
- ppp->sc_xfer = current->pid;
- break;
-
- case PPPIOCGNPMODE:
- case PPPIOCSNPMODE:
- {
- struct npioctl npi;
-
- COPY_FROM_USER (error, &npi, (void *) param3,
- sizeof (npi));
- if (error != 0)
- break;
-
- switch (npi.protocol) {
- case PPP_IP:
- npi.protocol = NP_IP;
- break;
- default:
- if (ppp->flags & SC_DEBUG)
- printk(KERN_DEBUG "pppioc[gs]npmode: "
- "invalid protocol %d\n",
- npi.protocol);
- error = -EINVAL;
- }
-
- if (error != 0)
- break;
-
- if (param2 == PPPIOCGNPMODE) {
- npi.mode = ppp->sc_npmode[npi.protocol];
-
- COPY_TO_USER (error, (void *) param3, &npi,
- sizeof (npi));
- break;
- }
-
- ppp->sc_npmode[npi.protocol] = npi.mode;
- if (ppp->flags & SC_DEBUG)
- printk(KERN_DEBUG "ppp: set np %d to %d\n",
- npi.protocol, npi.mode);
- ppp2dev(ppp)->tbusy = 0;
- mark_bh(NET_BH);
- }
- break;
-/*
- * Allow users to read, but not set, the serial port parameters
- */
- case TCGETS:
- case TCGETA:
- error = n_tty_ioctl (tty, file, param2, param3);
- break;
-
- case FIONREAD:
- {
- int count = ppp->ubuf->tail - ppp->ubuf->head;
- if (count < 0)
- count += (ppp->ubuf->size + 1);
- PUT_USER (error, count, (int *) param3);