2 * Generic HDLC support routines for Linux
4 * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
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.
15 #define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */
16 #define HDLC_MAX_MRU 1600 /* as required for FR network */
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/hdlc/ioctl.h>
25 /* This structure is a private property of HDLC protocols.
26 Hardware drivers have no interest here */
29 int (*open
)(struct net_device
*dev
);
30 void (*close
)(struct net_device
*dev
);
31 void (*start
)(struct net_device
*dev
); /* if open & DCD */
32 void (*stop
)(struct net_device
*dev
); /* if open & !DCD */
33 void (*detach
)(struct net_device
*dev
);
34 int (*ioctl
)(struct net_device
*dev
, struct ifreq
*ifr
);
35 __be16 (*type_trans
)(struct sk_buff
*skb
, struct net_device
*dev
);
36 int (*netif_rx
)(struct sk_buff
*skb
);
37 netdev_tx_t (*xmit
)(struct sk_buff
*skb
, struct net_device
*dev
);
38 struct module
*module
;
39 struct hdlc_proto
*next
; /* next protocol in the list */
43 /* Pointed to by netdev_priv(dev) */
44 typedef struct hdlc_device
{
45 /* used by HDLC layer to take control over HDLC device from hw driver*/
46 int (*attach
)(struct net_device
*dev
,
47 unsigned short encoding
, unsigned short parity
);
49 /* hardware driver must handle this instead of dev->hard_start_xmit */
50 netdev_tx_t (*xmit
)(struct sk_buff
*skb
, struct net_device
*dev
);
52 /* Things below are for HDLC layer internal use only */
53 const struct hdlc_proto
*proto
;
56 spinlock_t state_lock
;
63 /* Exported from hdlc module */
65 /* Called by hardware driver when a user requests HDLC service */
66 int hdlc_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
68 /* Must be used by hardware driver on module startup/exit */
69 #define register_hdlc_device(dev) register_netdev(dev)
70 void unregister_hdlc_device(struct net_device
*dev
);
73 void register_hdlc_protocol(struct hdlc_proto
*proto
);
74 void unregister_hdlc_protocol(struct hdlc_proto
*proto
);
76 struct net_device
*alloc_hdlcdev(void *priv
);
78 static inline struct hdlc_device
* dev_to_hdlc(struct net_device
*dev
)
80 return netdev_priv(dev
);
83 static __inline__
void debug_frame(const struct sk_buff
*skb
)
87 for (i
=0; i
< skb
->len
; i
++) {
92 printk(" %02X", skb
->data
[i
]);
98 /* Must be called by hardware driver when HDLC device is being opened */
99 int hdlc_open(struct net_device
*dev
);
100 /* Must be called by hardware driver when HDLC device is being closed */
101 void hdlc_close(struct net_device
*dev
);
102 /* May be used by hardware driver */
103 int hdlc_change_mtu(struct net_device
*dev
, int new_mtu
);
104 /* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
105 netdev_tx_t
hdlc_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
107 int attach_hdlc_protocol(struct net_device
*dev
, struct hdlc_proto
*proto
,
109 /* May be used by hardware driver to gain control over HDLC device */
110 void detach_hdlc_protocol(struct net_device
*dev
);
112 static __inline__ __be16
hdlc_type_trans(struct sk_buff
*skb
,
113 struct net_device
*dev
)
115 hdlc_device
*hdlc
= dev_to_hdlc(dev
);
118 skb_reset_mac_header(skb
);
120 if (hdlc
->proto
->type_trans
)
121 return hdlc
->proto
->type_trans(skb
, dev
);
123 return htons(ETH_P_HDLC
);
126 #endif /* __KERNEL */
127 #endif /* __HDLC_H */