0001
0002
0003
0004
0005
0006
0007 #ifndef __HDLC_H
0008 #define __HDLC_H
0009
0010
0011 #include <linux/skbuff.h>
0012 #include <linux/netdevice.h>
0013 #include <linux/hdlc/ioctl.h>
0014 #include <uapi/linux/hdlc.h>
0015
0016
0017
0018
0019 struct hdlc_proto {
0020 int (*open)(struct net_device *dev);
0021 void (*close)(struct net_device *dev);
0022 void (*start)(struct net_device *dev);
0023 void (*stop)(struct net_device *dev);
0024 void (*detach)(struct net_device *dev);
0025 int (*ioctl)(struct net_device *dev, struct if_settings *ifs);
0026 __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
0027 int (*netif_rx)(struct sk_buff *skb);
0028 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
0029 struct module *module;
0030 struct hdlc_proto *next;
0031 };
0032
0033
0034
0035 typedef struct hdlc_device {
0036
0037 int (*attach)(struct net_device *dev,
0038 unsigned short encoding, unsigned short parity);
0039
0040
0041 netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
0042
0043
0044 const struct hdlc_proto *proto;
0045 int carrier;
0046 int open;
0047 spinlock_t state_lock;
0048 void *state;
0049 void *priv;
0050 } hdlc_device;
0051
0052
0053
0054
0055
0056
0057 int hdlc_ioctl(struct net_device *dev, struct if_settings *ifs);
0058
0059
0060 #define register_hdlc_device(dev) register_netdev(dev)
0061 void unregister_hdlc_device(struct net_device *dev);
0062
0063
0064 void register_hdlc_protocol(struct hdlc_proto *proto);
0065 void unregister_hdlc_protocol(struct hdlc_proto *proto);
0066
0067 struct net_device *alloc_hdlcdev(void *priv);
0068
0069 static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
0070 {
0071 return netdev_priv(dev);
0072 }
0073
0074 static __inline__ void debug_frame(const struct sk_buff *skb)
0075 {
0076 int i;
0077
0078 for (i=0; i < skb->len; i++) {
0079 if (i == 100) {
0080 printk("...\n");
0081 return;
0082 }
0083 printk(" %02X", skb->data[i]);
0084 }
0085 printk("\n");
0086 }
0087
0088
0089
0090 int hdlc_open(struct net_device *dev);
0091
0092 void hdlc_close(struct net_device *dev);
0093
0094 netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
0095
0096 int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
0097 size_t size);
0098
0099 int detach_hdlc_protocol(struct net_device *dev);
0100
0101 static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
0102 struct net_device *dev)
0103 {
0104 hdlc_device *hdlc = dev_to_hdlc(dev);
0105
0106 skb->dev = dev;
0107 skb_reset_mac_header(skb);
0108
0109 if (hdlc->proto->type_trans)
0110 return hdlc->proto->type_trans(skb, dev);
0111 else
0112 return htons(ETH_P_HDLC);
0113 }
0114
0115 #endif