Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Generic HDLC support routines for Linux
0004  *
0005  * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
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 /* This structure is a private property of HDLC protocols.
0017    Hardware drivers have no interest here */
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); /* if open & DCD */
0023     void (*stop)(struct net_device *dev); /* if open & !DCD */
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; /* next protocol in the list */
0031 };
0032 
0033 
0034 /* Pointed to by netdev_priv(dev) */
0035 typedef struct hdlc_device {
0036     /* used by HDLC layer to take control over HDLC device from hw driver*/
0037     int (*attach)(struct net_device *dev,
0038               unsigned short encoding, unsigned short parity);
0039 
0040     /* hardware driver must handle this instead of dev->hard_start_xmit */
0041     netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
0042 
0043     /* Things below are for HDLC layer internal use only */
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 /* Exported from hdlc module */
0055 
0056 /* Called by hardware driver when a user requests HDLC service */
0057 int hdlc_ioctl(struct net_device *dev, struct if_settings *ifs);
0058 
0059 /* Must be used by hardware driver on module startup/exit */
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 /* Must be called by hardware driver when HDLC device is being opened */
0090 int hdlc_open(struct net_device *dev);
0091 /* Must be called by hardware driver when HDLC device is being closed */
0092 void hdlc_close(struct net_device *dev);
0093 /* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
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 /* May be used by hardware driver to gain control over HDLC device */
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 /* __HDLC_H */