2 * Generic HDLC support routines for Linux
3 * HDLC Ethernet emulation support
5 * Copyright (C) 2002-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/etherdevice.h>
14 #include <linux/gfp.h>
15 #include <linux/hdlc.h>
16 #include <linux/if_arp.h>
17 #include <linux/inetdevice.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/pkt_sched.h>
22 #include <linux/poll.h>
23 #include <linux/rtnetlink.h>
24 #include <linux/skbuff.h>
26 static int raw_eth_ioctl(struct net_device
*dev
, struct ifreq
*ifr
);
28 static netdev_tx_t
eth_tx(struct sk_buff
*skb
, struct net_device
*dev
)
30 int pad
= ETH_ZLEN
- skb
->len
;
31 if (pad
> 0) { /* Pad the frame with zeros */
33 if (skb_tailroom(skb
) < pad
)
34 if (pskb_expand_head(skb
, 0, pad
, GFP_ATOMIC
)) {
35 dev
->stats
.tx_dropped
++;
40 memset(skb
->data
+ len
, 0, pad
);
42 return dev_to_hdlc(dev
)->xmit(skb
, dev
);
46 static struct hdlc_proto proto
= {
47 .type_trans
= eth_type_trans
,
49 .ioctl
= raw_eth_ioctl
,
50 .module
= THIS_MODULE
,
54 static int raw_eth_ioctl(struct net_device
*dev
, struct ifreq
*ifr
)
56 raw_hdlc_proto __user
*raw_s
= ifr
->ifr_settings
.ifs_ifsu
.raw_hdlc
;
57 const size_t size
= sizeof(raw_hdlc_proto
);
58 raw_hdlc_proto new_settings
;
59 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
60 unsigned int old_qlen
;
63 switch (ifr
->ifr_settings
.type
) {
65 if (dev_to_hdlc(dev
)->proto
!= &proto
)
67 ifr
->ifr_settings
.type
= IF_PROTO_HDLC_ETH
;
68 if (ifr
->ifr_settings
.size
< size
) {
69 ifr
->ifr_settings
.size
= size
; /* data size wanted */
72 if (copy_to_user(raw_s
, hdlc
->state
, size
))
76 case IF_PROTO_HDLC_ETH
:
77 if (!capable(CAP_NET_ADMIN
))
80 if (dev
->flags
& IFF_UP
)
83 if (copy_from_user(&new_settings
, raw_s
, size
))
86 if (new_settings
.encoding
== ENCODING_DEFAULT
)
87 new_settings
.encoding
= ENCODING_NRZ
;
89 if (new_settings
.parity
== PARITY_DEFAULT
)
90 new_settings
.parity
= PARITY_CRC16_PR1_CCITT
;
92 result
= hdlc
->attach(dev
, new_settings
.encoding
,
97 result
= attach_hdlc_protocol(dev
, &proto
,
98 sizeof(raw_hdlc_proto
));
101 memcpy(hdlc
->state
, &new_settings
, size
);
102 old_qlen
= dev
->tx_queue_len
;
104 dev
->tx_queue_len
= old_qlen
;
105 eth_hw_addr_random(dev
);
106 call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE
, dev
);
107 netif_dormant_off(dev
);
115 static int __init
mod_init(void)
117 register_hdlc_protocol(&proto
);
123 static void __exit
mod_exit(void)
125 unregister_hdlc_protocol(&proto
);
129 module_init(mod_init
);
130 module_exit(mod_exit
);
132 MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
133 MODULE_DESCRIPTION("Ethernet encapsulation support for generic HDLC");
134 MODULE_LICENSE("GPL v2");