1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux 4 * 3 * 5 * Copyright (C) 1999-2005 Krzysztof Halasa <k !! 4 * Copyright (C) 1999-2003 Krzysztof Halasa <khc@pm.waw.pl> >> 5 * >> 6 * This program is free software; you can redistribute it and/or modify it >> 7 * under the terms of version 2 of the GNU General Public License >> 8 * as published by the Free Software Foundation. 6 */ 9 */ >> 10 7 #ifndef __HDLC_H 11 #ifndef __HDLC_H 8 #define __HDLC_H 12 #define __HDLC_H 9 13 >> 14 #define GENERIC_HDLC_VERSION 4 /* For synchronization with sethdlc utility */ >> 15 >> 16 #define CLOCK_DEFAULT 0 /* Default setting */ >> 17 #define CLOCK_EXT 1 /* External TX and RX clock - DTE */ >> 18 #define CLOCK_INT 2 /* Internal TX and RX clock - DCE */ >> 19 #define CLOCK_TXINT 3 /* Internal TX and external RX clock */ >> 20 #define CLOCK_TXFROMRX 4 /* TX clock derived from external RX clock */ >> 21 >> 22 >> 23 #define ENCODING_DEFAULT 0 /* Default setting */ >> 24 #define ENCODING_NRZ 1 >> 25 #define ENCODING_NRZI 2 >> 26 #define ENCODING_FM_MARK 3 >> 27 #define ENCODING_FM_SPACE 4 >> 28 #define ENCODING_MANCHESTER 5 >> 29 >> 30 >> 31 #define PARITY_DEFAULT 0 /* Default setting */ >> 32 #define PARITY_NONE 1 /* No parity */ >> 33 #define PARITY_CRC16_PR0 2 /* CRC16, initial value 0x0000 */ >> 34 #define PARITY_CRC16_PR1 3 /* CRC16, initial value 0xFFFF */ >> 35 #define PARITY_CRC16_PR0_CCITT 4 /* CRC16, initial 0x0000, ITU-T version */ >> 36 #define PARITY_CRC16_PR1_CCITT 5 /* CRC16, initial 0xFFFF, ITU-T version */ >> 37 #define PARITY_CRC32_PR0_CCITT 6 /* CRC32, initial value 0x00000000 */ >> 38 #define PARITY_CRC32_PR1_CCITT 7 /* CRC32, initial value 0xFFFFFFFF */ >> 39 >> 40 #define LMI_DEFAULT 0 /* Default setting */ >> 41 #define LMI_NONE 1 /* No LMI, all PVCs are static */ >> 42 #define LMI_ANSI 2 /* ANSI Annex D */ >> 43 #define LMI_CCITT 3 /* ITU-T Annex A */ >> 44 >> 45 #define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */ >> 46 #define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */ >> 47 >> 48 >> 49 #ifdef __KERNEL__ 10 50 11 #include <linux/skbuff.h> 51 #include <linux/skbuff.h> 12 #include <linux/netdevice.h> 52 #include <linux/netdevice.h> >> 53 #include <net/syncppp.h> 13 #include <linux/hdlc/ioctl.h> 54 #include <linux/hdlc/ioctl.h> 14 #include <uapi/linux/hdlc.h> << 15 55 16 /* This structure is a private property of HDL << 17 Hardware drivers have no interest here */ << 18 56 19 struct hdlc_proto { !! 57 typedef struct { /* Used in Cisco and PPP mode */ 20 int (*open)(struct net_device *dev); !! 58 u8 address; 21 void (*close)(struct net_device *dev); !! 59 u8 control; 22 void (*start)(struct net_device *dev); !! 60 u16 protocol; 23 void (*stop)(struct net_device *dev); !! 61 }__attribute__ ((packed)) hdlc_header; 24 void (*detach)(struct net_device *dev) !! 62 25 int (*ioctl)(struct net_device *dev, s !! 63 26 __be16 (*type_trans)(struct sk_buff *s !! 64 27 int (*netif_rx)(struct sk_buff *skb); !! 65 typedef struct { 28 netdev_tx_t (*xmit)(struct sk_buff *sk !! 66 u32 type; /* code */ 29 struct module *module; !! 67 u32 par1; 30 struct hdlc_proto *next; /* next proto !! 68 u32 par2; 31 }; !! 69 u16 rel; /* reliability */ >> 70 u32 time; >> 71 }__attribute__ ((packed)) cisco_packet; >> 72 #define CISCO_PACKET_LEN 18 >> 73 #define CISCO_BIG_PACKET_LEN 20 >> 74 32 75 33 76 34 /* Pointed to by netdev_priv(dev) */ !! 77 typedef struct pvc_device_struct { 35 typedef struct hdlc_device { !! 78 struct hdlc_device_struct *master; >> 79 struct net_device *main; >> 80 struct net_device *ether; /* bridged Ethernet interface */ >> 81 struct pvc_device_struct *next; /* Sorted in ascending DLCI order */ >> 82 int dlci; >> 83 int open_count; >> 84 >> 85 struct { >> 86 unsigned int new: 1; >> 87 unsigned int active: 1; >> 88 unsigned int exist: 1; >> 89 unsigned int deleted: 1; >> 90 unsigned int fecn: 1; >> 91 unsigned int becn: 1; >> 92 }state; >> 93 }pvc_device; >> 94 >> 95 >> 96 >> 97 typedef struct hdlc_device_struct { >> 98 /* To be initialized by hardware driver */ >> 99 struct net_device netdev; /* master net device - must be first */ >> 100 struct net_device_stats stats; >> 101 36 /* used by HDLC layer to take control 102 /* used by HDLC layer to take control over HDLC device from hw driver*/ 37 int (*attach)(struct net_device *dev, !! 103 int (*attach)(struct hdlc_device_struct *hdlc, 38 unsigned short encoding, 104 unsigned short encoding, unsigned short parity); 39 105 40 /* hardware driver must handle this in 106 /* hardware driver must handle this instead of dev->hard_start_xmit */ 41 netdev_tx_t (*xmit)(struct sk_buff *sk !! 107 int (*xmit)(struct sk_buff *skb, struct net_device *dev); >> 108 42 109 43 /* Things below are for HDLC layer int 110 /* Things below are for HDLC layer internal use only */ 44 const struct hdlc_proto *proto; !! 111 int (*ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); 45 int carrier; !! 112 int (*open)(struct hdlc_device_struct *hdlc); 46 int open; !! 113 void (*stop)(struct hdlc_device_struct *hdlc); 47 spinlock_t state_lock; !! 114 void (*proto_detach)(struct hdlc_device_struct *hdlc); 48 void *state; !! 115 void (*netif_rx)(struct sk_buff *skb); 49 void *priv; !! 116 unsigned short (*type_trans)(struct sk_buff *skb, 50 } hdlc_device; !! 117 struct net_device *dev); >> 118 int proto; /* IF_PROTO_HDLC/CISCO/FR/etc. */ >> 119 >> 120 union { >> 121 struct { >> 122 fr_proto settings; >> 123 pvc_device *first_pvc; >> 124 int dce_pvc_count; >> 125 >> 126 struct timer_list timer; >> 127 int last_poll; >> 128 int reliable; >> 129 int dce_changed; >> 130 int request; >> 131 int fullrep_sent; >> 132 u32 last_errors; /* last errors bit list */ >> 133 u8 n391cnt; >> 134 u8 txseq; /* TX sequence number */ >> 135 u8 rxseq; /* RX sequence number */ >> 136 }fr; >> 137 >> 138 struct { >> 139 cisco_proto settings; >> 140 >> 141 struct timer_list timer; >> 142 int last_poll; >> 143 int up; >> 144 u32 txseq; /* TX sequence number */ >> 145 u32 rxseq; /* RX sequence number */ >> 146 }cisco; >> 147 >> 148 struct { >> 149 raw_hdlc_proto settings; >> 150 }raw_hdlc; >> 151 >> 152 struct { >> 153 struct ppp_device pppdev; >> 154 struct ppp_device *syncppp_ptr; >> 155 int (*old_change_mtu)(struct net_device *dev, >> 156 int new_mtu); >> 157 }ppp; >> 158 }state; >> 159 }hdlc_device; 51 160 52 161 53 162 54 /* Exported from hdlc module */ !! 163 int hdlc_raw_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 164 int hdlc_raw_eth_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 165 int hdlc_cisco_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 166 int hdlc_ppp_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 167 int hdlc_fr_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 168 int hdlc_x25_ioctl(hdlc_device *hdlc, struct ifreq *ifr); >> 169 >> 170 >> 171 /* Exported from hdlc.o */ 55 172 56 /* Called by hardware driver when a user reque 173 /* Called by hardware driver when a user requests HDLC service */ 57 int hdlc_ioctl(struct net_device *dev, struct !! 174 int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); 58 175 59 /* Must be used by hardware driver on module s 176 /* Must be used by hardware driver on module startup/exit */ 60 #define register_hdlc_device(dev) regist !! 177 int register_hdlc_device(hdlc_device *hdlc); 61 void unregister_hdlc_device(struct net_device !! 178 void unregister_hdlc_device(hdlc_device *hdlc); >> 179 >> 180 >> 181 static __inline__ struct net_device* hdlc_to_dev(hdlc_device *hdlc) >> 182 { >> 183 return &hdlc->netdev; >> 184 } >> 185 >> 186 >> 187 static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev) >> 188 { >> 189 return (hdlc_device*)dev; >> 190 } 62 191 63 192 64 void register_hdlc_protocol(struct hdlc_proto !! 193 static __inline__ pvc_device* dev_to_pvc(struct net_device *dev) 65 void unregister_hdlc_protocol(struct hdlc_prot !! 194 { >> 195 return (pvc_device*)dev->priv; >> 196 } 66 197 67 struct net_device *alloc_hdlcdev(void *priv); << 68 198 69 static inline struct hdlc_device* dev_to_hdlc( !! 199 static __inline__ const char *hdlc_to_name(hdlc_device *hdlc) 70 { 200 { 71 return netdev_priv(dev); !! 201 return hdlc_to_dev(hdlc)->name; 72 } 202 } 73 203 >> 204 74 static __inline__ void debug_frame(const struc 205 static __inline__ void debug_frame(const struct sk_buff *skb) 75 { 206 { 76 int i; 207 int i; 77 208 78 for (i=0; i < skb->len; i++) { 209 for (i=0; i < skb->len; i++) { 79 if (i == 100) { 210 if (i == 100) { 80 printk("...\n"); 211 printk("...\n"); 81 return; 212 return; 82 } 213 } 83 printk(" %02X", skb->data[i]); 214 printk(" %02X", skb->data[i]); 84 } 215 } 85 printk("\n"); 216 printk("\n"); 86 } 217 } 87 218 88 219 >> 220 89 /* Must be called by hardware driver when HDLC 221 /* Must be called by hardware driver when HDLC device is being opened */ 90 int hdlc_open(struct net_device *dev); !! 222 static __inline__ int hdlc_open(hdlc_device *hdlc) >> 223 { >> 224 if (hdlc->proto == -1) >> 225 return -ENOSYS; /* no protocol attached */ >> 226 >> 227 if (hdlc->open) >> 228 return hdlc->open(hdlc); >> 229 return 0; >> 230 } >> 231 >> 232 91 /* Must be called by hardware driver when HDLC 233 /* Must be called by hardware driver when HDLC device is being closed */ 92 void hdlc_close(struct net_device *dev); !! 234 static __inline__ void hdlc_close(hdlc_device *hdlc) 93 /* Must be pointed to by hw driver's dev->netd !! 235 { 94 netdev_tx_t hdlc_start_xmit(struct sk_buff *sk !! 236 if (hdlc->stop) >> 237 hdlc->stop(hdlc); >> 238 } 95 239 96 int attach_hdlc_protocol(struct net_device *de << 97 size_t size); << 98 /* May be used by hardware driver to gain cont << 99 int detach_hdlc_protocol(struct net_device *de << 100 240 101 static __inline__ __be16 hdlc_type_trans(struc !! 241 /* May be used by hardware driver to gain control over HDLC device */ 102 struc !! 242 static __inline__ void hdlc_proto_detach(hdlc_device *hdlc) 103 { 243 { 104 hdlc_device *hdlc = dev_to_hdlc(dev); !! 244 if (hdlc->proto_detach) >> 245 hdlc->proto_detach(hdlc); >> 246 hdlc->proto_detach = NULL; >> 247 } 105 248 106 skb->dev = dev; << 107 skb_reset_mac_header(skb); << 108 249 109 if (hdlc->proto->type_trans) !! 250 static __inline__ unsigned short hdlc_type_trans(struct sk_buff *skb, 110 return hdlc->proto->type_trans !! 251 struct net_device *dev) >> 252 { >> 253 hdlc_device *hdlc = dev_to_hdlc(skb->dev); >> 254 if (hdlc->type_trans) >> 255 return hdlc->type_trans(skb, dev); 111 else 256 else 112 return htons(ETH_P_HDLC); !! 257 return __constant_htons(ETH_P_HDLC); 113 } 258 } 114 259 >> 260 #endif /* __KERNEL */ 115 #endif /* __HDLC_H */ 261 #endif /* __HDLC_H */ 116 262
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.