1
2
3
4
5
6
7
8
9
10#ifndef __HDLC_H
11#define __HDLC_H
12
13
14#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/hdlc/ioctl.h>
17#include <uapi/linux/hdlc.h>
18
19
20
21
22struct hdlc_proto {
23 int (*open)(struct net_device *dev);
24 void (*close)(struct net_device *dev);
25 void (*start)(struct net_device *dev);
26 void (*stop)(struct net_device *dev);
27 void (*detach)(struct net_device *dev);
28 int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
29 __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
30 int (*netif_rx)(struct sk_buff *skb);
31 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
32 struct module *module;
33 struct hdlc_proto *next;
34};
35
36
37
38typedef struct hdlc_device {
39
40 int (*attach)(struct net_device *dev,
41 unsigned short encoding, unsigned short parity);
42
43
44 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
45
46
47 const struct hdlc_proto *proto;
48 int carrier;
49 int open;
50 spinlock_t state_lock;
51 void *state;
52 void *priv;
53} hdlc_device;
54
55
56
57
58
59
60int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
61
62
63#define register_hdlc_device(dev) register_netdev(dev)
64void unregister_hdlc_device(struct net_device *dev);
65
66
67void register_hdlc_protocol(struct hdlc_proto *proto);
68void unregister_hdlc_protocol(struct hdlc_proto *proto);
69
70struct net_device *alloc_hdlcdev(void *priv);
71
72static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
73{
74 return netdev_priv(dev);
75}
76
77static __inline__ void debug_frame(const struct sk_buff *skb)
78{
79 int i;
80
81 for (i=0; i < skb->len; i++) {
82 if (i == 100) {
83 printk("...\n");
84 return;
85 }
86 printk(" %02X", skb->data[i]);
87 }
88 printk("\n");
89}
90
91
92
93int hdlc_open(struct net_device *dev);
94
95void hdlc_close(struct net_device *dev);
96
97netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
98
99int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
100 size_t size);
101
102int detach_hdlc_protocol(struct net_device *dev);
103
104static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
105 struct net_device *dev)
106{
107 hdlc_device *hdlc = dev_to_hdlc(dev);
108
109 skb->dev = dev;
110 skb_reset_mac_header(skb);
111
112 if (hdlc->proto->type_trans)
113 return hdlc->proto->type_trans(skb, dev);
114 else
115 return htons(ETH_P_HDLC);
116}
117
118#endif
119