Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Generic HDLC support routines for Linux | |
3 | * | |
b3dd65f9 | 4 | * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl> |
1da177e4 LT |
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 | ||
1da177e4 LT |
14 | |
15 | #define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */ | |
eb2a2fd9 | 16 | #if 0 |
1da177e4 | 17 | #define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */ |
eb2a2fd9 KH |
18 | #else |
19 | #define HDLC_MAX_MRU 1600 /* as required for FR network */ | |
20 | #endif | |
1da177e4 LT |
21 | |
22 | ||
23 | #ifdef __KERNEL__ | |
24 | ||
25 | #include <linux/skbuff.h> | |
26 | #include <linux/netdevice.h> | |
1da177e4 LT |
27 | #include <linux/hdlc/ioctl.h> |
28 | ||
29 | ||
eb2a2fd9 KH |
30 | /* Used by all network devices here, pointed to by netdev_priv(dev) */ |
31 | struct hdlc_device_desc { | |
32 | int (*netif_rx)(struct sk_buff *skb); | |
1da177e4 | 33 | struct net_device_stats stats; |
eb2a2fd9 KH |
34 | }; |
35 | ||
36 | /* This structure is a private property of HDLC protocols. | |
37 | Hardware drivers have no interest here */ | |
38 | ||
39 | struct hdlc_proto { | |
40 | int (*open)(struct net_device *dev); | |
41 | void (*close)(struct net_device *dev); | |
42 | void (*start)(struct net_device *dev); /* if open & DCD */ | |
43 | void (*stop)(struct net_device *dev); /* if open & !DCD */ | |
44 | void (*detach)(struct net_device *dev); | |
45 | int (*ioctl)(struct net_device *dev, struct ifreq *ifr); | |
46 | unsigned short (*type_trans)(struct sk_buff *skb, | |
47 | struct net_device *dev); | |
48 | struct module *module; | |
49 | struct hdlc_proto *next; /* next protocol in the list */ | |
50 | }; | |
51 | ||
52 | ||
53 | typedef struct hdlc_device { | |
1da177e4 LT |
54 | /* used by HDLC layer to take control over HDLC device from hw driver*/ |
55 | int (*attach)(struct net_device *dev, | |
56 | unsigned short encoding, unsigned short parity); | |
57 | ||
58 | /* hardware driver must handle this instead of dev->hard_start_xmit */ | |
59 | int (*xmit)(struct sk_buff *skb, struct net_device *dev); | |
60 | ||
1da177e4 | 61 | /* Things below are for HDLC layer internal use only */ |
eb2a2fd9 | 62 | const struct hdlc_proto *proto; |
1da177e4 LT |
63 | int carrier; |
64 | int open; | |
65 | spinlock_t state_lock; | |
eb2a2fd9 | 66 | void *state; |
1da177e4 LT |
67 | void *priv; |
68 | }hdlc_device; | |
69 | ||
70 | ||
71 | ||
eb2a2fd9 | 72 | /* Exported from hdlc module */ |
1da177e4 LT |
73 | |
74 | /* Called by hardware driver when a user requests HDLC service */ | |
75 | int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); | |
76 | ||
77 | /* Must be used by hardware driver on module startup/exit */ | |
4a31e348 | 78 | #define register_hdlc_device(dev) register_netdev(dev) |
1da177e4 LT |
79 | void unregister_hdlc_device(struct net_device *dev); |
80 | ||
eb2a2fd9 KH |
81 | |
82 | void register_hdlc_protocol(struct hdlc_proto *proto); | |
83 | void unregister_hdlc_protocol(struct hdlc_proto *proto); | |
84 | ||
1da177e4 LT |
85 | struct net_device *alloc_hdlcdev(void *priv); |
86 | ||
eb2a2fd9 KH |
87 | |
88 | static __inline__ struct hdlc_device_desc* dev_to_desc(struct net_device *dev) | |
1da177e4 LT |
89 | { |
90 | return netdev_priv(dev); | |
91 | } | |
92 | ||
eb2a2fd9 | 93 | static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev) |
1da177e4 | 94 | { |
eb2a2fd9 | 95 | return netdev_priv(dev) + sizeof(struct hdlc_device_desc); |
1da177e4 LT |
96 | } |
97 | ||
98 | ||
99 | static __inline__ void debug_frame(const struct sk_buff *skb) | |
100 | { | |
101 | int i; | |
102 | ||
103 | for (i=0; i < skb->len; i++) { | |
104 | if (i == 100) { | |
105 | printk("...\n"); | |
106 | return; | |
107 | } | |
108 | printk(" %02X", skb->data[i]); | |
109 | } | |
110 | printk("\n"); | |
111 | } | |
112 | ||
113 | ||
114 | /* Must be called by hardware driver when HDLC device is being opened */ | |
115 | int hdlc_open(struct net_device *dev); | |
116 | /* Must be called by hardware driver when HDLC device is being closed */ | |
117 | void hdlc_close(struct net_device *dev); | |
1da177e4 | 118 | |
eb2a2fd9 KH |
119 | int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, |
120 | int (*rx)(struct sk_buff *skb), size_t size); | |
1da177e4 | 121 | /* May be used by hardware driver to gain control over HDLC device */ |
eb2a2fd9 | 122 | void detach_hdlc_protocol(struct net_device *dev); |
1da177e4 LT |
123 | |
124 | static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev) | |
125 | { | |
eb2a2fd9 | 126 | return &dev_to_desc(dev)->stats; |
1da177e4 LT |
127 | } |
128 | ||
129 | ||
ab611487 AD |
130 | static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb, |
131 | struct net_device *dev) | |
1da177e4 LT |
132 | { |
133 | hdlc_device *hdlc = dev_to_hdlc(dev); | |
134 | ||
135 | skb->mac.raw = skb->data; | |
136 | skb->dev = dev; | |
137 | ||
eb2a2fd9 KH |
138 | if (hdlc->proto->type_trans) |
139 | return hdlc->proto->type_trans(skb, dev); | |
1da177e4 LT |
140 | else |
141 | return htons(ETH_P_HDLC); | |
142 | } | |
143 | ||
144 | #endif /* __KERNEL */ | |
145 | #endif /* __HDLC_H */ |