2 * Generic HDLC support routines for Linux
3 * Point-to-point protocol support
5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License
9 * as published by the Free Software Foundation.
12 #include <linux/errno.h>
13 #include <linux/hdlc.h>
14 #include <linux/if_arp.h>
15 #include <linux/inetdevice.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/pkt_sched.h>
20 #include <linux/poll.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/skbuff.h>
23 #include <linux/slab.h>
24 #include <net/syncppp.h>
27 struct ppp_device pppdev;
28 struct ppp_device *syncppp_ptr;
29 int (*old_change_mtu)(struct net_device *dev, int new_mtu);
32 static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr);
35 static inline struct ppp_state* state(hdlc_device *hdlc)
37 return(struct ppp_state *)(hdlc->state);
41 static int ppp_open(struct net_device *dev)
43 hdlc_device *hdlc = dev_to_hdlc(dev);
44 int (*old_ioctl)(struct net_device *, struct ifreq *, int);
47 dev->ml_priv = &state(hdlc)->syncppp_ptr;
48 state(hdlc)->syncppp_ptr = &state(hdlc)->pppdev;
49 state(hdlc)->pppdev.dev = dev;
51 old_ioctl = dev->do_ioctl;
52 state(hdlc)->old_change_mtu = dev->change_mtu;
53 sppp_attach(&state(hdlc)->pppdev);
54 /* sppp_attach nukes them. We don't need syncppp's ioctl */
55 dev->do_ioctl = old_ioctl;
56 state(hdlc)->pppdev.sppp.pp_flags &= ~PP_CISCO;
57 dev->type = ARPHRD_PPP;
58 result = sppp_open(dev);
69 static void ppp_close(struct net_device *dev)
71 hdlc_device *hdlc = dev_to_hdlc(dev);
76 dev->change_mtu = state(hdlc)->old_change_mtu;
77 dev->mtu = HDLC_MAX_MTU;
78 dev->hard_header_len = 16;
83 static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev)
85 return __constant_htons(ETH_P_WAN_PPP);
90 static struct hdlc_proto proto = {
93 .type_trans = ppp_type_trans,
95 .module = THIS_MODULE,
99 static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
101 hdlc_device *hdlc = dev_to_hdlc(dev);
104 switch (ifr->ifr_settings.type) {
106 if (dev_to_hdlc(dev)->proto != &proto)
108 ifr->ifr_settings.type = IF_PROTO_PPP;
109 return 0; /* return protocol only, no settable parameters */
112 if(!capable(CAP_NET_ADMIN))
115 if(dev->flags & IFF_UP)
118 /* no settable parameters */
120 result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
124 result = attach_hdlc_protocol(dev, &proto,
125 sizeof(struct ppp_state));
128 dev->hard_start_xmit = hdlc->xmit;
129 dev->type = ARPHRD_PPP;
130 netif_dormant_off(dev);
138 static int __init mod_init(void)
140 register_hdlc_protocol(&proto);
146 static void __exit mod_exit(void)
148 unregister_hdlc_protocol(&proto);
152 module_init(mod_init);
153 module_exit(mod_exit);
155 MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
156 MODULE_DESCRIPTION("PPP protocol support for generic HDLC");
157 MODULE_LICENSE("GPL v2");