blob: 6a6e701f1631622c950a0dc25174184036ce18b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic HDLC support routines for Linux
3 *
Krzysztof Halasab3dd65f2005-04-21 15:57:25 +02004 * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020016#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020018#else
19#define HDLC_MAX_MRU 1600 /* as required for FR network */
20#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22
23#ifdef __KERNEL__
24
25#include <linux/skbuff.h>
26#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/hdlc/ioctl.h>
28
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020029/* This structure is a private property of HDLC protocols.
30 Hardware drivers have no interest here */
31
32struct 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);
Krzysztof Halasaabf17ff2007-04-27 13:13:33 +020039 __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
Krzysztof Halasa40d25142008-02-01 22:37:12 +010040 int (*netif_rx)(struct sk_buff *skb);
Krzysztof Hałasa991990a2009-01-08 22:52:11 +010041 int (*xmit)(struct sk_buff *skb, struct net_device *dev);
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020042 struct module *module;
43 struct hdlc_proto *next; /* next protocol in the list */
44};
45
46
Wang Chenb74ca3a2008-12-08 01:14:16 -080047/* Pointed to by netdev_priv(dev) */
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020048typedef struct hdlc_device {
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 /* used by HDLC layer to take control over HDLC device from hw driver*/
50 int (*attach)(struct net_device *dev,
51 unsigned short encoding, unsigned short parity);
52
53 /* hardware driver must handle this instead of dev->hard_start_xmit */
54 int (*xmit)(struct sk_buff *skb, struct net_device *dev);
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* Things below are for HDLC layer internal use only */
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020057 const struct hdlc_proto *proto;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 int carrier;
59 int open;
60 spinlock_t state_lock;
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020061 void *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 void *priv;
63}hdlc_device;
64
65
66
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020067/* Exported from hdlc module */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* Called by hardware driver when a user requests HDLC service */
70int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
71
72/* Must be used by hardware driver on module startup/exit */
Krzysztof Halasa4a31e342006-06-22 22:20:19 +020073#define register_hdlc_device(dev) register_netdev(dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074void unregister_hdlc_device(struct net_device *dev);
75
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +020076
77void register_hdlc_protocol(struct hdlc_proto *proto);
78void unregister_hdlc_protocol(struct hdlc_proto *proto);
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080struct net_device *alloc_hdlcdev(void *priv);
81
Krzysztof Halasa40d25142008-02-01 22:37:12 +010082static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Wang Chen2baf8a22008-11-21 16:34:18 -080084 return netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static __inline__ void debug_frame(const struct sk_buff *skb)
88{
89 int i;
90
91 for (i=0; i < skb->len; i++) {
92 if (i == 100) {
93 printk("...\n");
94 return;
95 }
96 printk(" %02X", skb->data[i]);
97 }
98 printk("\n");
99}
100
101
102/* Must be called by hardware driver when HDLC device is being opened */
103int hdlc_open(struct net_device *dev);
104/* Must be called by hardware driver when HDLC device is being closed */
105void hdlc_close(struct net_device *dev);
Krzysztof Hałasa991990a2009-01-08 22:52:11 +0100106/* May be used by hardware driver */
107int hdlc_change_mtu(struct net_device *dev, int new_mtu);
108/* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
109int hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +0200111int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
Krzysztof Halasa40d25142008-02-01 22:37:12 +0100112 size_t size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* May be used by hardware driver to gain control over HDLC device */
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +0200114void detach_hdlc_protocol(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Alexey Dobriyanab611482005-07-12 12:08:43 -0700116static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
117 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 hdlc_device *hdlc = dev_to_hdlc(dev);
120
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700121 skb->dev = dev;
122 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Krzysztof Halasaeb2a2fd2006-09-26 23:23:45 +0200124 if (hdlc->proto->type_trans)
125 return hdlc->proto->type_trans(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 else
127 return htons(ETH_P_HDLC);
128}
129
130#endif /* __KERNEL */
131#endif /* __HDLC_H */