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/module.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/poll.h>
16 #include <linux/errno.h>
17 #include <linux/if_arp.h>
18 #include <linux/init.h>
19 #include <linux/skbuff.h>
20 #include <linux/pkt_sched.h>
21 #include <linux/inetdevice.h>
22 #include <linux/lapb.h>
23 #include <linux/rtnetlink.h>
24 #include <linux/hdlc.h>
25 #include <net/syncppp.h>
28 struct ppp_device pppdev
;
29 struct ppp_device
*syncppp_ptr
;
30 int (*old_change_mtu
)(struct net_device
*dev
, int new_mtu
);
33 static int ppp_ioctl(struct net_device
*dev
, struct ifreq
*ifr
);
36 static inline struct ppp_state
* state(hdlc_device
*hdlc
)
38 return(struct ppp_state
*)(hdlc
->state
);
42 static int ppp_open(struct net_device
*dev
)
44 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
45 int (*old_ioctl
)(struct net_device
*, struct ifreq
*, int);
48 dev
->priv
= &state(hdlc
)->syncppp_ptr
;
49 state(hdlc
)->syncppp_ptr
= &state(hdlc
)->pppdev
;
50 state(hdlc
)->pppdev
.dev
= dev
;
52 old_ioctl
= dev
->do_ioctl
;
53 state(hdlc
)->old_change_mtu
= dev
->change_mtu
;
54 sppp_attach(&state(hdlc
)->pppdev
);
55 /* sppp_attach nukes them. We don't need syncppp's ioctl */
56 dev
->do_ioctl
= old_ioctl
;
57 state(hdlc
)->pppdev
.sppp
.pp_flags
&= ~PP_CISCO
;
58 dev
->type
= ARPHRD_PPP
;
59 result
= sppp_open(dev
);
70 static void ppp_close(struct net_device
*dev
)
72 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
77 dev
->change_mtu
= state(hdlc
)->old_change_mtu
;
78 dev
->mtu
= HDLC_MAX_MTU
;
79 dev
->hard_header_len
= 16;
84 static __be16
ppp_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
86 return __constant_htons(ETH_P_WAN_PPP
);
91 static struct hdlc_proto proto
= {
94 .type_trans
= ppp_type_trans
,
96 .module
= THIS_MODULE
,
100 static int ppp_ioctl(struct net_device
*dev
, struct ifreq
*ifr
)
102 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
105 switch (ifr
->ifr_settings
.type
) {
107 if (dev_to_hdlc(dev
)->proto
!= &proto
)
109 ifr
->ifr_settings
.type
= IF_PROTO_PPP
;
110 return 0; /* return protocol only, no settable parameters */
113 if(!capable(CAP_NET_ADMIN
))
116 if(dev
->flags
& IFF_UP
)
119 /* no settable parameters */
121 result
=hdlc
->attach(dev
, ENCODING_NRZ
,PARITY_CRC16_PR1_CCITT
);
125 result
= attach_hdlc_protocol(dev
, &proto
,
126 sizeof(struct ppp_state
));
129 dev
->hard_start_xmit
= hdlc
->xmit
;
130 dev
->type
= ARPHRD_PPP
;
131 netif_dormant_off(dev
);
139 static int __init
mod_init(void)
141 register_hdlc_protocol(&proto
);
147 static void __exit
mod_exit(void)
149 unregister_hdlc_protocol(&proto
);
153 module_init(mod_init
);
154 module_exit(mod_exit
);
156 MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
157 MODULE_DESCRIPTION("PPP protocol support for generic HDLC");
158 MODULE_LICENSE("GPL v2");