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 | ||
eb2a2fd9 KH |
29 | /* This structure is a private property of HDLC protocols. |
30 | Hardware drivers have no interest here */ | |
31 | ||
32 | struct hdlc_proto { | |
33 | int (*open)(struct net_device *dev); | |
34 | void (*close)(struct net_device *dev); | |
35 | void (*start)(struct net_device *dev); /* if open & DCD */ | |
36 | void (*stop)(struct net_device *dev); /* if open & !DCD */ | |
37 | void (*detach)(struct net_device *dev); | |
38 | int (*ioctl)(struct net_device *dev, struct ifreq *ifr); | |
abf17ffd | 39 | __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev); |
40d25142 | 40 | int (*netif_rx)(struct sk_buff *skb); |
eb2a2fd9 KH |
41 | struct module *module; |
42 | struct hdlc_proto *next; /* next protocol in the list */ | |
43 | }; | |
44 | ||
45 | ||
40d25142 | 46 | /* Pointed to by dev->priv */ |
eb2a2fd9 | 47 | typedef struct hdlc_device { |
1da177e4 LT |
48 | /* used by HDLC layer to take control over HDLC device from hw driver*/ |
49 | int (*attach)(struct net_device *dev, | |
50 | unsigned short encoding, unsigned short parity); | |
51 | ||
52 | /* hardware driver must handle this instead of dev->hard_start_xmit */ | |
53 | int (*xmit)(struct sk_buff *skb, struct net_device *dev); | |
54 | ||
1da177e4 | 55 | /* Things below are for HDLC layer internal use only */ |
eb2a2fd9 | 56 | const struct hdlc_proto *proto; |
1da177e4 LT |
57 | int carrier; |
58 | int open; | |
59 | spinlock_t state_lock; | |
eb2a2fd9 | 60 | void *state; |
1da177e4 LT |
61 | void *priv; |
62 | }hdlc_device; | |
63 | ||
64 | ||
65 | ||
eb2a2fd9 | 66 | /* Exported from hdlc module */ |
1da177e4 LT |
67 | |
68 | /* Called by hardware driver when a user requests HDLC service */ | |
69 | int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); | |
70 | ||
71 | /* Must be used by hardware driver on module startup/exit */ | |
4a31e348 | 72 | #define register_hdlc_device(dev) register_netdev(dev) |
1da177e4 LT |
73 | void unregister_hdlc_device(struct net_device *dev); |
74 | ||
eb2a2fd9 KH |
75 | |
76 | void register_hdlc_protocol(struct hdlc_proto *proto); | |
77 | void unregister_hdlc_protocol(struct hdlc_proto *proto); | |
78 | ||
1da177e4 LT |
79 | struct net_device *alloc_hdlcdev(void *priv); |
80 | ||
40d25142 | 81 | static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev) |
1da177e4 | 82 | { |
40d25142 | 83 | return dev->priv; |
1da177e4 LT |
84 | } |
85 | ||
1da177e4 LT |
86 | static __inline__ void debug_frame(const struct sk_buff *skb) |
87 | { | |
88 | int i; | |
89 | ||
90 | for (i=0; i < skb->len; i++) { | |
91 | if (i == 100) { | |
92 | printk("...\n"); | |
93 | return; | |
94 | } | |
95 | printk(" %02X", skb->data[i]); | |
96 | } | |
97 | printk("\n"); | |
98 | } | |
99 | ||
100 | ||
101 | /* Must be called by hardware driver when HDLC device is being opened */ | |
102 | int hdlc_open(struct net_device *dev); | |
103 | /* Must be called by hardware driver when HDLC device is being closed */ | |
104 | void hdlc_close(struct net_device *dev); | |
1da177e4 | 105 | |
eb2a2fd9 | 106 | int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, |
40d25142 | 107 | size_t size); |
1da177e4 | 108 | /* May be used by hardware driver to gain control over HDLC device */ |
eb2a2fd9 | 109 | void detach_hdlc_protocol(struct net_device *dev); |
1da177e4 | 110 | |
ab611487 AD |
111 | static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb, |
112 | struct net_device *dev) | |
1da177e4 LT |
113 | { |
114 | hdlc_device *hdlc = dev_to_hdlc(dev); | |
115 | ||
459a98ed ACM |
116 | skb->dev = dev; |
117 | skb_reset_mac_header(skb); | |
1da177e4 | 118 | |
eb2a2fd9 KH |
119 | if (hdlc->proto->type_trans) |
120 | return hdlc->proto->type_trans(skb, dev); | |
1da177e4 LT |
121 | else |
122 | return htons(ETH_P_HDLC); | |
123 | } | |
124 | ||
125 | #endif /* __KERNEL */ | |
126 | #endif /* __HDLC_H */ |