diff options
Diffstat (limited to 'include/linux/hdlc.h')
-rw-r--r-- | include/linux/hdlc.h | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/include/linux/hdlc.h b/include/linux/hdlc.h new file mode 100644 index 000000000000..503194e62fe1 --- /dev/null +++ b/include/linux/hdlc.h | |||
@@ -0,0 +1,258 @@ | |||
1 | /* | ||
2 | * Generic HDLC support routines for Linux | ||
3 | * | ||
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. | ||
9 | */ | ||
10 | |||
11 | #ifndef __HDLC_H | ||
12 | #define __HDLC_H | ||
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__ | ||
50 | |||
51 | #include <linux/skbuff.h> | ||
52 | #include <linux/netdevice.h> | ||
53 | #include <net/syncppp.h> | ||
54 | #include <linux/hdlc/ioctl.h> | ||
55 | |||
56 | |||
57 | typedef struct { /* Used in Cisco and PPP mode */ | ||
58 | u8 address; | ||
59 | u8 control; | ||
60 | u16 protocol; | ||
61 | }__attribute__ ((packed)) hdlc_header; | ||
62 | |||
63 | |||
64 | |||
65 | typedef struct { | ||
66 | u32 type; /* code */ | ||
67 | u32 par1; | ||
68 | u32 par2; | ||
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 | |||
75 | |||
76 | |||
77 | typedef struct pvc_device_struct { | ||
78 | struct net_device *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_stats stats; | ||
100 | |||
101 | /* used by HDLC layer to take control over HDLC device from hw driver*/ | ||
102 | int (*attach)(struct net_device *dev, | ||
103 | unsigned short encoding, unsigned short parity); | ||
104 | |||
105 | /* hardware driver must handle this instead of dev->hard_start_xmit */ | ||
106 | int (*xmit)(struct sk_buff *skb, struct net_device *dev); | ||
107 | |||
108 | |||
109 | /* Things below are for HDLC layer internal use only */ | ||
110 | struct { | ||
111 | int (*open)(struct net_device *dev); | ||
112 | void (*close)(struct net_device *dev); | ||
113 | |||
114 | /* if open & DCD */ | ||
115 | void (*start)(struct net_device *dev); | ||
116 | /* if open & !DCD */ | ||
117 | void (*stop)(struct net_device *dev); | ||
118 | |||
119 | void (*detach)(struct hdlc_device_struct *hdlc); | ||
120 | int (*netif_rx)(struct sk_buff *skb); | ||
121 | unsigned short (*type_trans)(struct sk_buff *skb, | ||
122 | struct net_device *dev); | ||
123 | int id; /* IF_PROTO_HDLC/CISCO/FR/etc. */ | ||
124 | }proto; | ||
125 | |||
126 | int carrier; | ||
127 | int open; | ||
128 | spinlock_t state_lock; | ||
129 | |||
130 | union { | ||
131 | struct { | ||
132 | fr_proto settings; | ||
133 | pvc_device *first_pvc; | ||
134 | int dce_pvc_count; | ||
135 | |||
136 | struct timer_list timer; | ||
137 | unsigned long last_poll; | ||
138 | int reliable; | ||
139 | int dce_changed; | ||
140 | int request; | ||
141 | int fullrep_sent; | ||
142 | u32 last_errors; /* last errors bit list */ | ||
143 | u8 n391cnt; | ||
144 | u8 txseq; /* TX sequence number */ | ||
145 | u8 rxseq; /* RX sequence number */ | ||
146 | }fr; | ||
147 | |||
148 | struct { | ||
149 | cisco_proto settings; | ||
150 | |||
151 | struct timer_list timer; | ||
152 | unsigned long last_poll; | ||
153 | int up; | ||
154 | int request_sent; | ||
155 | u32 txseq; /* TX sequence number */ | ||
156 | u32 rxseq; /* RX sequence number */ | ||
157 | }cisco; | ||
158 | |||
159 | struct { | ||
160 | raw_hdlc_proto settings; | ||
161 | }raw_hdlc; | ||
162 | |||
163 | struct { | ||
164 | struct ppp_device pppdev; | ||
165 | struct ppp_device *syncppp_ptr; | ||
166 | int (*old_change_mtu)(struct net_device *dev, | ||
167 | int new_mtu); | ||
168 | }ppp; | ||
169 | }state; | ||
170 | void *priv; | ||
171 | }hdlc_device; | ||
172 | |||
173 | |||
174 | |||
175 | int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
176 | int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
177 | int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
178 | int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
179 | int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
180 | int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr); | ||
181 | |||
182 | |||
183 | /* Exported from hdlc.o */ | ||
184 | |||
185 | /* Called by hardware driver when a user requests HDLC service */ | ||
186 | int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); | ||
187 | |||
188 | /* Must be used by hardware driver on module startup/exit */ | ||
189 | int register_hdlc_device(struct net_device *dev); | ||
190 | void unregister_hdlc_device(struct net_device *dev); | ||
191 | |||
192 | struct net_device *alloc_hdlcdev(void *priv); | ||
193 | |||
194 | static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev) | ||
195 | { | ||
196 | return netdev_priv(dev); | ||
197 | } | ||
198 | |||
199 | |||
200 | static __inline__ pvc_device* dev_to_pvc(struct net_device *dev) | ||
201 | { | ||
202 | return (pvc_device*)dev->priv; | ||
203 | } | ||
204 | |||
205 | |||
206 | static __inline__ void debug_frame(const struct sk_buff *skb) | ||
207 | { | ||
208 | int i; | ||
209 | |||
210 | for (i=0; i < skb->len; i++) { | ||
211 | if (i == 100) { | ||
212 | printk("...\n"); | ||
213 | return; | ||
214 | } | ||
215 | printk(" %02X", skb->data[i]); | ||
216 | } | ||
217 | printk("\n"); | ||
218 | } | ||
219 | |||
220 | |||
221 | /* Must be called by hardware driver when HDLC device is being opened */ | ||
222 | int hdlc_open(struct net_device *dev); | ||
223 | /* Must be called by hardware driver when HDLC device is being closed */ | ||
224 | void hdlc_close(struct net_device *dev); | ||
225 | /* Called by hardware driver when DCD line level changes */ | ||
226 | void hdlc_set_carrier(int on, struct net_device *dev); | ||
227 | |||
228 | /* May be used by hardware driver to gain control over HDLC device */ | ||
229 | static __inline__ void hdlc_proto_detach(hdlc_device *hdlc) | ||
230 | { | ||
231 | if (hdlc->proto.detach) | ||
232 | hdlc->proto.detach(hdlc); | ||
233 | hdlc->proto.detach = NULL; | ||
234 | } | ||
235 | |||
236 | |||
237 | static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev) | ||
238 | { | ||
239 | return &dev_to_hdlc(dev)->stats; | ||
240 | } | ||
241 | |||
242 | |||
243 | static __inline__ unsigned short hdlc_type_trans(struct sk_buff *skb, | ||
244 | struct net_device *dev) | ||
245 | { | ||
246 | hdlc_device *hdlc = dev_to_hdlc(dev); | ||
247 | |||
248 | skb->mac.raw = skb->data; | ||
249 | skb->dev = dev; | ||
250 | |||
251 | if (hdlc->proto.type_trans) | ||
252 | return hdlc->proto.type_trans(skb, dev); | ||
253 | else | ||
254 | return htons(ETH_P_HDLC); | ||
255 | } | ||
256 | |||
257 | #endif /* __KERNEL */ | ||
258 | #endif /* __HDLC_H */ | ||