35 #include <linux/module.h>
36 #include <linux/kernel.h>
38 #include <linux/tty.h>
39 #include <linux/netdevice.h>
40 #include <linux/poll.h>
41 #include <linux/ppp_defs.h>
48 #include <linux/slab.h>
49 #include <asm/unaligned.h>
50 #include <asm/uaccess.h>
52 #define PPP_VERSION "2.4.2"
85 #define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
87 #define PPPSYNC_MAX_RQLEN 32
96 static void ppp_sync_process(
unsigned long arg);
97 static int ppp_sync_push(
struct syncppp *ap);
98 static void ppp_sync_flush_output(
struct syncppp *ap);
99 static void ppp_sync_input(
struct syncppp *ap,
const unsigned char *
buf,
103 .start_xmit = ppp_sync_send,
104 .ioctl = ppp_sync_ioctl,
113 register __u8 next_ch;
114 static const char hex[] =
"0123456789ABCDEF";
116 while (count-- > 0) {
118 *out++ = hex[(next_ch >> 4) & 0x0F];
119 *out++ = hex[next_ch & 0x0F];
125 ppp_print_char (
register __u8 * out,
const __u8 * in,
int count)
127 register __u8 next_ch;
129 while (count-- > 0) {
132 if (next_ch < 0x20 || next_ch > 0x7e)
144 ppp_print_buffer (
const char *
name,
const __u8 *
buf,
int count)
153 ppp_print_hex (line, buf, 8);
154 ppp_print_char (&line[8 * 3], buf, 8);
162 ppp_print_hex (line, buf, count);
163 ppp_print_char (&line[8 * 3], buf, count);
198 static void sp_put(
struct syncppp *ap)
228 ap->
xaccm[3] = 0x60000000
U;
231 skb_queue_head_init(&ap->
rqueue);
237 ap->
chan.private = ap;
238 ap->
chan.ops = &sync_ops;
242 ap->
chan.speed = speed;
300 static int ppp_sync_hangup(
struct tty_struct *tty)
312 unsigned char __user *buf,
size_t count)
323 const unsigned char *buf,
size_t count)
330 unsigned int cmd,
unsigned long arg)
332 struct syncppp *ap = sp_get(tty);
357 ppp_sync_flush_output(ap);
386 ppp_sync_receive(
struct tty_struct *tty,
const unsigned char *buf,
389 struct syncppp *ap = sp_get(tty);
395 ppp_sync_input(ap, buf, cflags, count);
396 spin_unlock_irqrestore(&ap->
recv_lock, flags);
397 if (!skb_queue_empty(&ap->
rqueue))
398 tasklet_schedule(&ap->
tsk);
406 struct syncppp *ap = sp_get(tty);
412 tasklet_schedule(&ap->
tsk);
421 .open = ppp_sync_open,
422 .close = ppp_sync_close,
423 .hangup = ppp_sync_hangup,
424 .read = ppp_sync_read,
425 .write = ppp_sync_write,
426 .ioctl = ppp_synctty_ioctl,
427 .poll = ppp_sync_poll,
428 .receive_buf = ppp_sync_receive,
429 .write_wakeup = ppp_sync_wakeup,
448 ppp_sync_ioctl(
struct ppp_channel *
chan,
unsigned int cmd,
unsigned long arg)
460 if (
put_user(val, (
int __user *) argp))
465 if (
get_user(val, (
int __user *) argp))
504 accm[2] &= ~0x40000000
U;
505 accm[3] |= 0x60000000
U;
516 if (
get_user(val, (
int __user *) argp))
535 static void ppp_sync_process(
unsigned long arg)
568 proto = get_unaligned_be16(data);
574 islcp = proto ==
PPP_LCP && 1 <= data[2] && data[2] <= 7;
582 if (skb_headroom(skb) < 2) {
583 struct sk_buff *npkt = dev_alloc_skb(skb->
len + 2);
589 skb_copy_from_linear_data(skb,
602 ppp_print_buffer (
"send buffer", skb->
data, skb->
len);
626 skb = ppp_sync_txmunge(ap, skb);
640 ppp_sync_push(
struct syncppp *ap)
651 if (!tty_stuffed && ap->
tpkt) {
653 sent = tty->
ops->write(tty, ap->
tpkt->data, ap->
tpkt->len);
656 if (sent < ap->tpkt->len) {
669 (!tty_stuffed && ap->
tpkt)))
692 ppp_sync_flush_output(
struct syncppp *ap)
719 ppp_sync_input(
struct syncppp *ap,
const unsigned char *buf,
720 char *flags,
int count)
729 ppp_print_buffer (
"receive buffer", buf, count);
739 skb_reserve(skb, 2 + (buf[0] & 1));
741 if (flags && *flags) {
744 }
else if (count > skb_tailroom(skb)) {
765 }
else if (skb->
len < 2)
774 if (skb || (skb = dev_alloc_skb(0))) {
781 ppp_sync_cleanup(
void)
784 printk(
KERN_ERR "failed to unregister Sync PPP line discipline\n");