Commit | Line | Data |
---|---|---|
25763b3c | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
1da177e4 LT |
2 | /* |
3 | * Generic HDLC support routines for Linux | |
4 | * | |
b3dd65f9 | 5 | * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl> |
1da177e4 | 6 | */ |
1da177e4 LT |
7 | #ifndef __HDLC_H |
8 | #define __HDLC_H | |
9 | ||
1da177e4 | 10 | |
1da177e4 LT |
11 | #include <linux/skbuff.h> |
12 | #include <linux/netdevice.h> | |
1da177e4 | 13 | #include <linux/hdlc/ioctl.h> |
607ca46e | 14 | #include <uapi/linux/hdlc.h> |
1da177e4 | 15 | |
eb2a2fd9 KH |
16 | /* This structure is a private property of HDLC protocols. |
17 | Hardware drivers have no interest here */ | |
18 | ||
19 | struct hdlc_proto { | |
20 | int (*open)(struct net_device *dev); | |
21 | void (*close)(struct net_device *dev); | |
22 | void (*start)(struct net_device *dev); /* if open & DCD */ | |
23 | void (*stop)(struct net_device *dev); /* if open & !DCD */ | |
24 | void (*detach)(struct net_device *dev); | |
ad7eab2a | 25 | int (*ioctl)(struct net_device *dev, struct if_settings *ifs); |
abf17ffd | 26 | __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev); |
40d25142 | 27 | int (*netif_rx)(struct sk_buff *skb); |
4c5d502d | 28 | netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev); |
eb2a2fd9 KH |
29 | struct module *module; |
30 | struct hdlc_proto *next; /* next protocol in the list */ | |
31 | }; | |
32 | ||
33 | ||
b74ca3a8 | 34 | /* Pointed to by netdev_priv(dev) */ |
eb2a2fd9 | 35 | typedef struct hdlc_device { |
1da177e4 LT |
36 | /* used by HDLC layer to take control over HDLC device from hw driver*/ |
37 | int (*attach)(struct net_device *dev, | |
38 | unsigned short encoding, unsigned short parity); | |
39 | ||
40 | /* hardware driver must handle this instead of dev->hard_start_xmit */ | |
4c5d502d | 41 | netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev); |
1da177e4 | 42 | |
1da177e4 | 43 | /* Things below are for HDLC layer internal use only */ |
eb2a2fd9 | 44 | const struct hdlc_proto *proto; |
1da177e4 LT |
45 | int carrier; |
46 | int open; | |
47 | spinlock_t state_lock; | |
eb2a2fd9 | 48 | void *state; |
1da177e4 | 49 | void *priv; |
4c5d502d | 50 | } hdlc_device; |
1da177e4 LT |
51 | |
52 | ||
53 | ||
eb2a2fd9 | 54 | /* Exported from hdlc module */ |
1da177e4 LT |
55 | |
56 | /* Called by hardware driver when a user requests HDLC service */ | |
ad7eab2a | 57 | int hdlc_ioctl(struct net_device *dev, struct if_settings *ifs); |
1da177e4 LT |
58 | |
59 | /* Must be used by hardware driver on module startup/exit */ | |
4a31e348 | 60 | #define register_hdlc_device(dev) register_netdev(dev) |
1da177e4 LT |
61 | void unregister_hdlc_device(struct net_device *dev); |
62 | ||
eb2a2fd9 KH |
63 | |
64 | void register_hdlc_protocol(struct hdlc_proto *proto); | |
65 | void unregister_hdlc_protocol(struct hdlc_proto *proto); | |
66 | ||
1da177e4 LT |
67 | struct net_device *alloc_hdlcdev(void *priv); |
68 | ||
40d25142 | 69 | static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev) |
1da177e4 | 70 | { |
2baf8a2d | 71 | return netdev_priv(dev); |
1da177e4 LT |
72 | } |
73 | ||
1da177e4 LT |
74 | static __inline__ void debug_frame(const struct sk_buff *skb) |
75 | { | |
76 | int i; | |
77 | ||
78 | for (i=0; i < skb->len; i++) { | |
79 | if (i == 100) { | |
80 | printk("...\n"); | |
81 | return; | |
82 | } | |
83 | printk(" %02X", skb->data[i]); | |
84 | } | |
85 | printk("\n"); | |
86 | } | |
87 | ||
88 | ||
89 | /* Must be called by hardware driver when HDLC device is being opened */ | |
90 | int hdlc_open(struct net_device *dev); | |
91 | /* Must be called by hardware driver when HDLC device is being closed */ | |
92 | void hdlc_close(struct net_device *dev); | |
991990a1 | 93 | /* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */ |
4c5d502d | 94 | netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev); |
1da177e4 | 95 | |
eb2a2fd9 | 96 | int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, |
40d25142 | 97 | size_t size); |
1da177e4 | 98 | /* May be used by hardware driver to gain control over HDLC device */ |
2f8364a2 | 99 | int detach_hdlc_protocol(struct net_device *dev); |
1da177e4 | 100 | |
ab611487 AD |
101 | static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb, |
102 | struct net_device *dev) | |
1da177e4 LT |
103 | { |
104 | hdlc_device *hdlc = dev_to_hdlc(dev); | |
105 | ||
459a98ed ACM |
106 | skb->dev = dev; |
107 | skb_reset_mac_header(skb); | |
1da177e4 | 108 | |
eb2a2fd9 KH |
109 | if (hdlc->proto->type_trans) |
110 | return hdlc->proto->type_trans(skb, dev); | |
1da177e4 LT |
111 | else |
112 | return htons(ETH_P_HDLC); | |
113 | } | |
114 | ||
1da177e4 | 115 | #endif /* __HDLC_H */ |