hdlc.h 3.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 * Generic HDLC support routines for Linux
 *
K
Krzysztof Halasa 已提交
4
 * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
L
Linus Torvalds 已提交
5 6 7 8 9 10 11 12 13 14 15
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 */

#ifndef __HDLC_H
#define __HDLC_H


#define HDLC_MAX_MTU 1500	/* Ethernet 1500 bytes */
16
#if 0
L
Linus Torvalds 已提交
17
#define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */
18 19 20
#else
#define HDLC_MAX_MRU 1600 /* as required for FR network */
#endif
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28


#ifdef __KERNEL__

#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/hdlc/ioctl.h>

29 30 31 32 33 34 35 36 37 38
/* This structure is a private property of HDLC protocols.
   Hardware drivers have no interest here */

struct hdlc_proto {
	int (*open)(struct net_device *dev);
	void (*close)(struct net_device *dev);
	void (*start)(struct net_device *dev); /* if open & DCD */
	void (*stop)(struct net_device *dev); /* if open & !DCD */
	void (*detach)(struct net_device *dev);
	int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
39
	__be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
40
	int (*netif_rx)(struct sk_buff *skb);
41 42 43 44 45
	struct module *module;
	struct hdlc_proto *next; /* next protocol in the list */
};


46
/* Pointed to by dev->priv */
47
typedef struct hdlc_device {
48
	struct net_device_stats stats;
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56
	/* used by HDLC layer to take control over HDLC device from hw driver*/
	int (*attach)(struct net_device *dev,
		      unsigned short encoding, unsigned short parity);

	/* hardware driver must handle this instead of dev->hard_start_xmit */
	int (*xmit)(struct sk_buff *skb, struct net_device *dev);

	/* Things below are for HDLC layer internal use only */
57
	const struct hdlc_proto *proto;
L
Linus Torvalds 已提交
58 59 60
	int carrier;
	int open;
	spinlock_t state_lock;
61
	void *state;
L
Linus Torvalds 已提交
62 63 64 65 66
	void *priv;
}hdlc_device;



67
/* Exported from hdlc module */
L
Linus Torvalds 已提交
68 69 70 71 72

/* Called by hardware driver when a user requests HDLC service */
int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);

/* Must be used by hardware driver on module startup/exit */
73
#define register_hdlc_device(dev)	register_netdev(dev)
L
Linus Torvalds 已提交
74 75
void unregister_hdlc_device(struct net_device *dev);

76 77 78 79

void register_hdlc_protocol(struct hdlc_proto *proto);
void unregister_hdlc_protocol(struct hdlc_proto *proto);

L
Linus Torvalds 已提交
80 81
struct net_device *alloc_hdlcdev(void *priv);

82
static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
L
Linus Torvalds 已提交
83
{
84
	return dev->priv;
L
Linus Torvalds 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
}

static __inline__ void debug_frame(const struct sk_buff *skb)
{
	int i;

	for (i=0; i < skb->len; i++) {
		if (i == 100) {
			printk("...\n");
			return;
		}
		printk(" %02X", skb->data[i]);
	}
	printk("\n");
}


/* Must be called by hardware driver when HDLC device is being opened */
int hdlc_open(struct net_device *dev);
/* Must be called by hardware driver when HDLC device is being closed */
void hdlc_close(struct net_device *dev);

107
int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
108
			 size_t size);
L
Linus Torvalds 已提交
109
/* May be used by hardware driver to gain control over HDLC device */
110
void detach_hdlc_protocol(struct net_device *dev);
L
Linus Torvalds 已提交
111 112 113

static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev)
{
114
	return &dev_to_hdlc(dev)->stats;
L
Linus Torvalds 已提交
115 116 117
}


A
Alexey Dobriyan 已提交
118 119
static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
					 struct net_device *dev)
L
Linus Torvalds 已提交
120 121 122
{
	hdlc_device *hdlc = dev_to_hdlc(dev);

123 124
	skb->dev = dev;
	skb_reset_mac_header(skb);
L
Linus Torvalds 已提交
125

126 127
	if (hdlc->proto->type_trans)
		return hdlc->proto->type_trans(skb, dev);
L
Linus Torvalds 已提交
128 129 130 131 132 133
	else
		return htons(ETH_P_HDLC);
}

#endif /* __KERNEL */
#endif /* __HDLC_H */