2 * Generic HDLC support routines for Linux
3 * Point-to-point protocol support
5 * Copyright (C) 1999 - 2003 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>
27 static int ppp_open(struct net_device
*dev
)
29 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
33 dev
->priv
= &hdlc
->state
.ppp
.syncppp_ptr
;
34 hdlc
->state
.ppp
.syncppp_ptr
= &hdlc
->state
.ppp
.pppdev
;
35 hdlc
->state
.ppp
.pppdev
.dev
= dev
;
37 old_ioctl
= dev
->do_ioctl
;
38 hdlc
->state
.ppp
.old_change_mtu
= dev
->change_mtu
;
39 sppp_attach(&hdlc
->state
.ppp
.pppdev
);
40 /* sppp_attach nukes them. We don't need syncppp's ioctl */
41 dev
->do_ioctl
= old_ioctl
;
42 hdlc
->state
.ppp
.pppdev
.sppp
.pp_flags
&= ~PP_CISCO
;
43 dev
->type
= ARPHRD_PPP
;
44 result
= sppp_open(dev
);
55 static void ppp_close(struct net_device
*dev
)
57 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
61 dev
->rebuild_header
= NULL
;
62 dev
->change_mtu
= hdlc
->state
.ppp
.old_change_mtu
;
63 dev
->mtu
= HDLC_MAX_MTU
;
64 dev
->hard_header_len
= 16;
69 static __be16
ppp_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
71 return __constant_htons(ETH_P_WAN_PPP
);
76 int hdlc_ppp_ioctl(struct net_device
*dev
, struct ifreq
*ifr
)
78 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
81 switch (ifr
->ifr_settings
.type
) {
83 ifr
->ifr_settings
.type
= IF_PROTO_PPP
;
84 return 0; /* return protocol only, no settable parameters */
87 if(!capable(CAP_NET_ADMIN
))
90 if(dev
->flags
& IFF_UP
)
93 /* no settable parameters */
95 result
=hdlc
->attach(dev
, ENCODING_NRZ
,PARITY_CRC16_PR1_CCITT
);
99 hdlc_proto_detach(hdlc
);
100 memset(&hdlc
->proto
, 0, sizeof(hdlc
->proto
));
102 hdlc
->proto
.open
= ppp_open
;
103 hdlc
->proto
.close
= ppp_close
;
104 hdlc
->proto
.type_trans
= ppp_type_trans
;
105 hdlc
->proto
.id
= IF_PROTO_PPP
;
106 dev
->hard_start_xmit
= hdlc
->xmit
;
107 dev
->hard_header
= NULL
;
108 dev
->type
= ARPHRD_PPP
;
110 netif_dormant_off(dev
);