hdlc_raw.c (0612ec48762bf8712db1925b2e67246d2237ebab) hdlc_raw.c (eb2a2fd91f7c8a53b15063d6f08cf22b9a56cbfb)
1/*
2 * Generic HDLC support routines for Linux
3 * HDLC support
4 *
1/*
2 * Generic HDLC support routines for Linux
3 * HDLC support
4 *
5 * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl>
5 * Copyright (C) 1999 - 2006 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>

--- 5 unchanged lines hidden (view full) ---

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
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>

--- 5 unchanged lines hidden (view full) ---

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
27static int raw_ioctl(struct net_device *dev, struct ifreq *ifr);
28
27static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
28{
29 return __constant_htons(ETH_P_IP);
30}
31
32
33
29static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
30{
31 return __constant_htons(ETH_P_IP);
32}
33
34
35
34int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr)
36static struct hdlc_proto proto = {
37 .type_trans = raw_type_trans,
38 .ioctl = raw_ioctl,
39 .module = THIS_MODULE,
40};
41
42
43static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
35{
36 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc;
37 const size_t size = sizeof(raw_hdlc_proto);
38 raw_hdlc_proto new_settings;
39 hdlc_device *hdlc = dev_to_hdlc(dev);
40 int result;
41
42 switch (ifr->ifr_settings.type) {
43 case IF_GET_PROTO:
44{
45 raw_hdlc_proto __user *raw_s = ifr->ifr_settings.ifs_ifsu.raw_hdlc;
46 const size_t size = sizeof(raw_hdlc_proto);
47 raw_hdlc_proto new_settings;
48 hdlc_device *hdlc = dev_to_hdlc(dev);
49 int result;
50
51 switch (ifr->ifr_settings.type) {
52 case IF_GET_PROTO:
53 if (dev_to_hdlc(dev)->proto != &proto)
54 return -EINVAL;
44 ifr->ifr_settings.type = IF_PROTO_HDLC;
45 if (ifr->ifr_settings.size < size) {
46 ifr->ifr_settings.size = size; /* data size wanted */
47 return -ENOBUFS;
48 }
55 ifr->ifr_settings.type = IF_PROTO_HDLC;
56 if (ifr->ifr_settings.size < size) {
57 ifr->ifr_settings.size = size; /* data size wanted */
58 return -ENOBUFS;
59 }
49 if (copy_to_user(raw_s, &hdlc->state.raw_hdlc.settings, size))
60 if (copy_to_user(raw_s, hdlc->state, size))
50 return -EFAULT;
51 return 0;
52
53 case IF_PROTO_HDLC:
54 if (!capable(CAP_NET_ADMIN))
55 return -EPERM;
56
57 if (dev->flags & IFF_UP)

--- 8 unchanged lines hidden (view full) ---

66 if (new_settings.parity == PARITY_DEFAULT)
67 new_settings.parity = PARITY_CRC16_PR1_CCITT;
68
69 result = hdlc->attach(dev, new_settings.encoding,
70 new_settings.parity);
71 if (result)
72 return result;
73
61 return -EFAULT;
62 return 0;
63
64 case IF_PROTO_HDLC:
65 if (!capable(CAP_NET_ADMIN))
66 return -EPERM;
67
68 if (dev->flags & IFF_UP)

--- 8 unchanged lines hidden (view full) ---

77 if (new_settings.parity == PARITY_DEFAULT)
78 new_settings.parity = PARITY_CRC16_PR1_CCITT;
79
80 result = hdlc->attach(dev, new_settings.encoding,
81 new_settings.parity);
82 if (result)
83 return result;
84
74 hdlc_proto_detach(hdlc);
75 memcpy(&hdlc->state.raw_hdlc.settings, &new_settings, size);
76 memset(&hdlc->proto, 0, sizeof(hdlc->proto));
77
78 hdlc->proto.type_trans = raw_type_trans;
79 hdlc->proto.id = IF_PROTO_HDLC;
85 result = attach_hdlc_protocol(dev, &proto, NULL,
86 sizeof(raw_hdlc_proto));
87 if (result)
88 return result;
89 memcpy(hdlc->state, &new_settings, size);
80 dev->hard_start_xmit = hdlc->xmit;
81 dev->hard_header = NULL;
82 dev->type = ARPHRD_RAWHDLC;
83 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
84 dev->addr_len = 0;
85 netif_dormant_off(dev);
86 return 0;
87 }
88
89 return -EINVAL;
90}
90 dev->hard_start_xmit = hdlc->xmit;
91 dev->hard_header = NULL;
92 dev->type = ARPHRD_RAWHDLC;
93 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
94 dev->addr_len = 0;
95 netif_dormant_off(dev);
96 return 0;
97 }
98
99 return -EINVAL;
100}
101
102
103static int __init mod_init(void)
104{
105 register_hdlc_protocol(&proto);
106 return 0;
107}
108
109
110
111static void __exit mod_exit(void)
112{
113 unregister_hdlc_protocol(&proto);
114}
115
116
117module_init(mod_init);
118module_exit(mod_exit);
119
120MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
121MODULE_DESCRIPTION("Raw HDLC protocol support for generic HDLC");
122MODULE_LICENSE("GPL v2");