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
31
32struct hdlc_proto {
33 int (*open)(struct net_device *dev);
34 void (*close)(struct net_device *dev);
35 void (*start)(struct net_device *dev);
36 void (*stop)(struct net_device *dev);
37 void (*detach)(struct net_device *dev);
38 int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
39 __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
40 int (*netif_rx)(struct sk_buff *skb);
41 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
42 struct module *module;
43 struct hdlc_proto *next;
44};
45
46
47
48typedef struct hdlc_device {
49
50 int (*attach)(struct net_device *dev,
51 unsigned short encoding, unsigned short parity);
52
53
54 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
55
56
57 const struct hdlc_proto *proto;
58 int carrier;
59 int open;
60 spinlock_t state_lock;
61 void *state;
62 void *priv;
63} hdlc_device;
64
65
66
67
68
69
70int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
71
72
73#define register_hdlc_device(dev) register_netdev(dev)
74void unregister_hdlc_device(struct net_device *dev);
75
76
77void register_hdlc_protocol(struct hdlc_proto *proto);
78void unregister_hdlc_protocol(struct hdlc_proto *proto);
79
80struct net_device *alloc_hdlcdev(void *priv);
81
82static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
83{
84 return netdev_priv(dev);
85}
86
87static __inline__ void debug_frame(const struct sk_buff *skb)
88{
89 int i;
90
91 for (i=0; i < skb->len; i++) {
92 if (i == 100) {
93 printk("...\n");
94 return;
95 }
96 printk(" %02X", skb->data[i]);
97 }
98 printk("\n");
99}
100
101
102
103int hdlc_open(struct net_device *dev);
104
105void hdlc_close(struct net_device *dev);
106
107int hdlc_change_mtu(struct net_device *dev, int new_mtu);
108
109netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
110
111int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
112 size_t size);
113
114void detach_hdlc_protocol(struct net_device *dev);
115
116static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
117 struct net_device *dev)
118{
119 hdlc_device *hdlc = dev_to_hdlc(dev);
120
121 skb->dev = dev;
122 skb_reset_mac_header(skb);
123
124 if (hdlc->proto->type_trans)
125 return hdlc->proto->type_trans(skb, dev);
126 else
127 return htons(ETH_P_HDLC);
128}
129
130#endif
131#endif
132