2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Generic HDLC support routines for Linux
|
|
|
|
*
|
2005-04-21 17:57:25 +04:00
|
|
|
* Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/hdlc/ioctl.h>
|
2012-10-13 13:46:48 +04:00
|
|
|
#include <uapi/linux/hdlc.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 01:23:45 +04:00
|
|
|
/* 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);
|
2007-04-27 15:13:33 +04:00
|
|
|
__be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
|
2008-02-02 00:37:12 +03:00
|
|
|
int (*netif_rx)(struct sk_buff *skb);
|
2009-08-31 23:50:48 +04:00
|
|
|
netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
|
2006-09-27 01:23:45 +04:00
|
|
|
struct module *module;
|
|
|
|
struct hdlc_proto *next; /* next protocol in the list */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-12-08 12:14:16 +03:00
|
|
|
/* Pointed to by netdev_priv(dev) */
|
2006-09-27 01:23:45 +04:00
|
|
|
typedef struct hdlc_device {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* 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 */
|
2009-08-31 23:50:48 +04:00
|
|
|
netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Things below are for HDLC layer internal use only */
|
2006-09-27 01:23:45 +04:00
|
|
|
const struct hdlc_proto *proto;
|
2005-04-17 02:20:36 +04:00
|
|
|
int carrier;
|
|
|
|
int open;
|
|
|
|
spinlock_t state_lock;
|
2006-09-27 01:23:45 +04:00
|
|
|
void *state;
|
2005-04-17 02:20:36 +04:00
|
|
|
void *priv;
|
2009-08-31 23:50:48 +04:00
|
|
|
} hdlc_device;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-27 01:23:45 +04:00
|
|
|
/* Exported from hdlc module */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* 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 */
|
2006-06-23 00:20:19 +04:00
|
|
|
#define register_hdlc_device(dev) register_netdev(dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
void unregister_hdlc_device(struct net_device *dev);
|
|
|
|
|
2006-09-27 01:23:45 +04:00
|
|
|
|
|
|
|
void register_hdlc_protocol(struct hdlc_proto *proto);
|
|
|
|
void unregister_hdlc_protocol(struct hdlc_proto *proto);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
struct net_device *alloc_hdlcdev(void *priv);
|
|
|
|
|
2008-02-02 00:37:12 +03:00
|
|
|
static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-11-22 03:34:18 +03:00
|
|
|
return netdev_priv(dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-01-09 00:52:11 +03:00
|
|
|
/* May be used by hardware driver */
|
|
|
|
int hdlc_change_mtu(struct net_device *dev, int new_mtu);
|
|
|
|
/* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
|
2009-08-31 23:50:48 +04:00
|
|
|
netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 01:23:45 +04:00
|
|
|
int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
|
2008-02-02 00:37:12 +03:00
|
|
|
size_t size);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* May be used by hardware driver to gain control over HDLC device */
|
2015-12-03 23:12:31 +03:00
|
|
|
int detach_hdlc_protocol(struct net_device *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-12 23:08:43 +04:00
|
|
|
static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
hdlc_device *hdlc = dev_to_hdlc(dev);
|
|
|
|
|
2007-03-20 01:30:44 +03:00
|
|
|
skb->dev = dev;
|
|
|
|
skb_reset_mac_header(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 01:23:45 +04:00
|
|
|
if (hdlc->proto->type_trans)
|
|
|
|
return hdlc->proto->type_trans(skb, dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
|
|
|
return htons(ETH_P_HDLC);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __HDLC_H */
|