diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/wan/hdlc_raw_eth.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/net/wan/hdlc_raw_eth.c')
-rw-r--r-- | drivers/net/wan/hdlc_raw_eth.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/net/wan/hdlc_raw_eth.c b/drivers/net/wan/hdlc_raw_eth.c new file mode 100644 index 000000000000..b1285cc8fee6 --- /dev/null +++ b/drivers/net/wan/hdlc_raw_eth.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Generic HDLC support routines for Linux | ||
3 | * HDLC Ethernet emulation support | ||
4 | * | ||
5 | * Copyright (C) 2002-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/random.h> | ||
22 | #include <linux/inetdevice.h> | ||
23 | #include <linux/lapb.h> | ||
24 | #include <linux/rtnetlink.h> | ||
25 | #include <linux/etherdevice.h> | ||
26 | #include <linux/hdlc.h> | ||
27 | |||
28 | |||
29 | static int eth_tx(struct sk_buff *skb, struct net_device *dev) | ||
30 | { | ||
31 | int pad = ETH_ZLEN - skb->len; | ||
32 | if (pad > 0) { /* Pad the frame with zeros */ | ||
33 | int len = skb->len; | ||
34 | if (skb_tailroom(skb) < pad) | ||
35 | if (pskb_expand_head(skb, 0, pad, GFP_ATOMIC)) { | ||
36 | hdlc_stats(dev)->tx_dropped++; | ||
37 | dev_kfree_skb(skb); | ||
38 | return 0; | ||
39 | } | ||
40 | skb_put(skb, pad); | ||
41 | memset(skb->data + len, 0, pad); | ||
42 | } | ||
43 | return dev_to_hdlc(dev)->xmit(skb, dev); | ||
44 | } | ||
45 | |||
46 | |||
47 | int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr) | ||
48 | { | ||
49 | raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc; | ||
50 | const size_t size = sizeof(raw_hdlc_proto); | ||
51 | raw_hdlc_proto new_settings; | ||
52 | hdlc_device *hdlc = dev_to_hdlc(dev); | ||
53 | int result; | ||
54 | void *old_ch_mtu; | ||
55 | int old_qlen; | ||
56 | |||
57 | switch (ifr->ifr_settings.type) { | ||
58 | case IF_GET_PROTO: | ||
59 | ifr->ifr_settings.type = IF_PROTO_HDLC_ETH; | ||
60 | if (ifr->ifr_settings.size < size) { | ||
61 | ifr->ifr_settings.size = size; /* data size wanted */ | ||
62 | return -ENOBUFS; | ||
63 | } | ||
64 | if (copy_to_user(raw_s, &hdlc->state.raw_hdlc.settings, size)) | ||
65 | return -EFAULT; | ||
66 | return 0; | ||
67 | |||
68 | case IF_PROTO_HDLC_ETH: | ||
69 | if (!capable(CAP_NET_ADMIN)) | ||
70 | return -EPERM; | ||
71 | |||
72 | if (dev->flags & IFF_UP) | ||
73 | return -EBUSY; | ||
74 | |||
75 | if (copy_from_user(&new_settings, raw_s, size)) | ||
76 | return -EFAULT; | ||
77 | |||
78 | if (new_settings.encoding == ENCODING_DEFAULT) | ||
79 | new_settings.encoding = ENCODING_NRZ; | ||
80 | |||
81 | if (new_settings.parity == PARITY_DEFAULT) | ||
82 | new_settings.parity = PARITY_CRC16_PR1_CCITT; | ||
83 | |||
84 | result = hdlc->attach(dev, new_settings.encoding, | ||
85 | new_settings.parity); | ||
86 | if (result) | ||
87 | return result; | ||
88 | |||
89 | hdlc_proto_detach(hdlc); | ||
90 | memcpy(&hdlc->state.raw_hdlc.settings, &new_settings, size); | ||
91 | memset(&hdlc->proto, 0, sizeof(hdlc->proto)); | ||
92 | |||
93 | hdlc->proto.type_trans = eth_type_trans; | ||
94 | hdlc->proto.id = IF_PROTO_HDLC_ETH; | ||
95 | dev->hard_start_xmit = eth_tx; | ||
96 | old_ch_mtu = dev->change_mtu; | ||
97 | old_qlen = dev->tx_queue_len; | ||
98 | ether_setup(dev); | ||
99 | dev->change_mtu = old_ch_mtu; | ||
100 | dev->tx_queue_len = old_qlen; | ||
101 | memcpy(dev->dev_addr, "\x00\x01", 2); | ||
102 | get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2); | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | return -EINVAL; | ||
107 | } | ||