| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Generic HDLC support routines for Linux | 
 | 3 |  * Point-to-point protocol support | 
 | 4 |  * | 
 | 5 |  * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl> | 
 | 6 |  * | 
 | 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. | 
 | 10 |  */ | 
 | 11 |  | 
 | 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 |  | 
 | 26 |  | 
 | 27 | static int ppp_open(struct net_device *dev) | 
 | 28 | { | 
 | 29 | 	hdlc_device *hdlc = dev_to_hdlc(dev); | 
 | 30 | 	void *old_ioctl; | 
 | 31 | 	int result; | 
 | 32 |  | 
 | 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; | 
 | 36 |  | 
 | 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); | 
 | 45 | 	if (result) { | 
 | 46 | 		sppp_detach(dev); | 
 | 47 | 		return result; | 
 | 48 | 	} | 
 | 49 |  | 
 | 50 | 	return 0; | 
 | 51 | } | 
 | 52 |  | 
 | 53 |  | 
 | 54 |  | 
 | 55 | static void ppp_close(struct net_device *dev) | 
 | 56 | { | 
 | 57 | 	hdlc_device *hdlc = dev_to_hdlc(dev); | 
 | 58 |  | 
 | 59 | 	sppp_close(dev); | 
 | 60 | 	sppp_detach(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; | 
 | 65 | } | 
 | 66 |  | 
 | 67 |  | 
 | 68 |  | 
| Alexey Dobriyan | ab61148 | 2005-07-12 12:08:43 -0700 | [diff] [blame] | 69 | static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { | 
 | 71 | 	return __constant_htons(ETH_P_WAN_PPP); | 
 | 72 | } | 
 | 73 |  | 
 | 74 |  | 
 | 75 |  | 
 | 76 | int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr) | 
 | 77 | { | 
 | 78 | 	hdlc_device *hdlc = dev_to_hdlc(dev); | 
 | 79 | 	int result; | 
 | 80 |  | 
 | 81 | 	switch (ifr->ifr_settings.type) { | 
 | 82 | 	case IF_GET_PROTO: | 
 | 83 | 		ifr->ifr_settings.type = IF_PROTO_PPP; | 
 | 84 | 		return 0; /* return protocol only, no settable parameters */ | 
 | 85 |  | 
 | 86 | 	case IF_PROTO_PPP: | 
 | 87 | 		if(!capable(CAP_NET_ADMIN)) | 
 | 88 | 			return -EPERM; | 
 | 89 |  | 
 | 90 | 		if(dev->flags & IFF_UP) | 
 | 91 | 			return -EBUSY; | 
 | 92 |  | 
 | 93 | 		/* no settable parameters */ | 
 | 94 |  | 
 | 95 | 		result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); | 
 | 96 | 		if (result) | 
 | 97 | 			return result; | 
 | 98 |  | 
 | 99 | 		hdlc_proto_detach(hdlc); | 
 | 100 | 		memset(&hdlc->proto, 0, sizeof(hdlc->proto)); | 
 | 101 |  | 
 | 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; | 
 | 109 | 		dev->addr_len = 0; | 
| Krzysztof Halasa | 4bc83b4 | 2006-07-21 14:41:01 -0700 | [diff] [blame] | 110 | 		netif_dormant_off(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 		return 0; | 
 | 112 | 	} | 
 | 113 |  | 
 | 114 | 	return -EINVAL; | 
 | 115 | } |