blob: df695e9ae32761a2bef2611c0c06b03e94fb5429 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic HDLC support routines for Linux
3 *
Krzysztof Halasab3dd65f2005-04-21 15:57:25 +02004 * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 */
Krzysztof Halasab3dd65f2005-04-21 15:57:25 +020044#define LMI_CISCO 4 /* The "original" LMI, aka Gang of Four */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */
47#define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */
48
49
50#ifdef __KERNEL__
51
52#include <linux/skbuff.h>
53#include <linux/netdevice.h>
54#include <net/syncppp.h>
55#include <linux/hdlc/ioctl.h>
56
57
58typedef struct { /* Used in Cisco and PPP mode */
59 u8 address;
60 u8 control;
61 u16 protocol;
62}__attribute__ ((packed)) hdlc_header;
63
64
65
66typedef struct {
67 u32 type; /* code */
68 u32 par1;
69 u32 par2;
70 u16 rel; /* reliability */
71 u32 time;
72}__attribute__ ((packed)) cisco_packet;
73#define CISCO_PACKET_LEN 18
74#define CISCO_BIG_PACKET_LEN 20
75
76
77
78typedef struct pvc_device_struct {
79 struct net_device *master;
80 struct net_device *main;
81 struct net_device *ether; /* bridged Ethernet interface */
82 struct pvc_device_struct *next; /* Sorted in ascending DLCI order */
83 int dlci;
84 int open_count;
85
86 struct {
87 unsigned int new: 1;
88 unsigned int active: 1;
89 unsigned int exist: 1;
90 unsigned int deleted: 1;
91 unsigned int fecn: 1;
92 unsigned int becn: 1;
Krzysztof Halasab3dd65f2005-04-21 15:57:25 +020093 unsigned int bandwidth; /* Cisco LMI reporting only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }state;
95}pvc_device;
96
97
98
99typedef struct hdlc_device_struct {
100 /* To be initialized by hardware driver */
101 struct net_device_stats stats;
102
103 /* used by HDLC layer to take control over HDLC device from hw driver*/
104 int (*attach)(struct net_device *dev,
105 unsigned short encoding, unsigned short parity);
106
107 /* hardware driver must handle this instead of dev->hard_start_xmit */
108 int (*xmit)(struct sk_buff *skb, struct net_device *dev);
109
110
111 /* Things below are for HDLC layer internal use only */
112 struct {
113 int (*open)(struct net_device *dev);
114 void (*close)(struct net_device *dev);
115
116 /* if open & DCD */
117 void (*start)(struct net_device *dev);
118 /* if open & !DCD */
119 void (*stop)(struct net_device *dev);
120
121 void (*detach)(struct hdlc_device_struct *hdlc);
122 int (*netif_rx)(struct sk_buff *skb);
123 unsigned short (*type_trans)(struct sk_buff *skb,
124 struct net_device *dev);
125 int id; /* IF_PROTO_HDLC/CISCO/FR/etc. */
126 }proto;
127
128 int carrier;
129 int open;
130 spinlock_t state_lock;
131
132 union {
133 struct {
134 fr_proto settings;
135 pvc_device *first_pvc;
136 int dce_pvc_count;
137
138 struct timer_list timer;
139 unsigned long last_poll;
140 int reliable;
141 int dce_changed;
142 int request;
143 int fullrep_sent;
144 u32 last_errors; /* last errors bit list */
145 u8 n391cnt;
146 u8 txseq; /* TX sequence number */
147 u8 rxseq; /* RX sequence number */
148 }fr;
149
150 struct {
151 cisco_proto settings;
152
153 struct timer_list timer;
154 unsigned long last_poll;
155 int up;
156 int request_sent;
157 u32 txseq; /* TX sequence number */
158 u32 rxseq; /* RX sequence number */
159 }cisco;
160
161 struct {
162 raw_hdlc_proto settings;
163 }raw_hdlc;
164
165 struct {
166 struct ppp_device pppdev;
167 struct ppp_device *syncppp_ptr;
168 int (*old_change_mtu)(struct net_device *dev,
169 int new_mtu);
170 }ppp;
171 }state;
172 void *priv;
173}hdlc_device;
174
175
176
177int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr);
178int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr);
179int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr);
180int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr);
181int hdlc_fr_ioctl(struct net_device *dev, struct ifreq *ifr);
182int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr);
183
184
185/* Exported from hdlc.o */
186
187/* Called by hardware driver when a user requests HDLC service */
188int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
189
190/* Must be used by hardware driver on module startup/exit */
191int register_hdlc_device(struct net_device *dev);
192void unregister_hdlc_device(struct net_device *dev);
193
194struct net_device *alloc_hdlcdev(void *priv);
195
196static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev)
197{
198 return netdev_priv(dev);
199}
200
201
202static __inline__ pvc_device* dev_to_pvc(struct net_device *dev)
203{
204 return (pvc_device*)dev->priv;
205}
206
207
208static __inline__ void debug_frame(const struct sk_buff *skb)
209{
210 int i;
211
212 for (i=0; i < skb->len; i++) {
213 if (i == 100) {
214 printk("...\n");
215 return;
216 }
217 printk(" %02X", skb->data[i]);
218 }
219 printk("\n");
220}
221
222
223/* Must be called by hardware driver when HDLC device is being opened */
224int hdlc_open(struct net_device *dev);
225/* Must be called by hardware driver when HDLC device is being closed */
226void hdlc_close(struct net_device *dev);
227/* Called by hardware driver when DCD line level changes */
228void hdlc_set_carrier(int on, struct net_device *dev);
229
230/* May be used by hardware driver to gain control over HDLC device */
231static __inline__ void hdlc_proto_detach(hdlc_device *hdlc)
232{
233 if (hdlc->proto.detach)
234 hdlc->proto.detach(hdlc);
235 hdlc->proto.detach = NULL;
236}
237
238
239static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev)
240{
241 return &dev_to_hdlc(dev)->stats;
242}
243
244
Alexey Dobriyanab611482005-07-12 12:08:43 -0700245static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
246 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 hdlc_device *hdlc = dev_to_hdlc(dev);
249
250 skb->mac.raw = skb->data;
251 skb->dev = dev;
252
253 if (hdlc->proto.type_trans)
254 return hdlc->proto.type_trans(skb, dev);
255 else
256 return htons(ETH_P_HDLC);
257}
258
259#endif /* __KERNEL */
260#endif /* __HDLC_H */