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