Release 4.11 drivers/net/wan/hdlc.c
/*
* Generic HDLC support routines for Linux
*
* Copyright (C) 1999 - 2008 Krzysztof Halasa <khc@pm.waw.pl>
*
* 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.
*
* Currently supported:
* * raw IP-in-HDLC
* * Cisco HDLC
* * Frame Relay with ANSI or CCITT LMI (both user and network side)
* * PPP
* * X.25
*
* Use sethdlc utility to set line parameters, protocol and PVCs
*
* How does it work:
* - proto->open(), close(), start(), stop() calls are serialized.
* The order is: open, [ start, stop ... ] close ...
* - proto->start() and stop() are called with spin_lock_irq held.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/errno.h>
#include <linux/hdlc.h>
#include <linux/if_arp.h>
#include <linux/inetdevice.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/pkt_sched.h>
#include <linux/poll.h>
#include <linux/rtnetlink.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <net/net_namespace.h>
static const char* version = "HDLC support module revision 1.22";
#undef DEBUG_LINK
static struct hdlc_proto *first_proto;
static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *p, struct net_device *orig_dev)
{
struct hdlc_device *hdlc = dev_to_hdlc(dev);
if (!net_eq(dev_net(dev), &init_net)) {
kfree_skb(skb);
return 0;
}
BUG_ON(!hdlc->proto->netif_rx);
return hdlc->proto->netif_rx(skb);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
François Romieu | 28 | 35.00% | 1 | 12.50% |
Krzysztof Hałasa | 25 | 31.25% | 3 | 37.50% |
Eric W. Biedermann | 14 | 17.50% | 1 | 12.50% |
David S. Miller | 5 | 6.25% | 1 | 12.50% |
Octavian Purdila | 5 | 6.25% | 1 | 12.50% |
Hideaki Yoshifuji / 吉藤英明 | 3 | 3.75% | 1 | 12.50% |
Total | 80 | 100.00% | 8 | 100.00% |
netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
if (hdlc->proto->xmit)
return hdlc->proto->xmit(skb, dev);
return hdlc->xmit(skb, dev); /* call hardware driver directly */
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 54 | 98.18% | 1 | 50.00% |
Stephen Hemminger | 1 | 1.82% | 1 | 50.00% |
Total | 55 | 100.00% | 2 | 100.00% |
static inline void hdlc_proto_start(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
if (hdlc->proto->start)
hdlc->proto->start(dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 38 | 100.00% | 4 | 100.00% |
Total | 38 | 100.00% | 4 | 100.00% |
static inline void hdlc_proto_stop(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
if (hdlc->proto->stop)
hdlc->proto->stop(dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 38 | 100.00% | 4 | 100.00% |
Total | 38 | 100.00% | 4 | 100.00% |
static int hdlc_device_event(struct notifier_block *this, unsigned long event,
void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
hdlc_device *hdlc;
unsigned long flags;
int on;
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;
if (!(dev->priv_flags & IFF_WAN_HDLC))
return NOTIFY_DONE; /* not an HDLC device */
if (event != NETDEV_CHANGE)
return NOTIFY_DONE; /* Only interested in carrier changes */
on = netif_carrier_ok(dev);
#ifdef DEBUG_LINK
printk(KERN_DEBUG "%s: hdlc_device_event NETDEV_CHANGE, carrier %i\n",
dev->name, on);
#endif
hdlc = dev_to_hdlc(dev);
spin_lock_irqsave(&hdlc->state_lock, flags);
if (hdlc->carrier == on)
goto carrier_exit; /* no change in DCD line level */
hdlc->carrier = on;
if (!hdlc->open)
goto carrier_exit;
if (hdlc->carrier) {
netdev_info(dev, "Carrier detected\n");
hdlc_proto_start(dev);
} else {
netdev_info(dev, "Carrier lost\n");
hdlc_proto_stop(dev);
}
carrier_exit:
spin_unlock_irqrestore(&hdlc->state_lock, flags);
return NOTIFY_DONE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 164 | 81.59% | 5 | 41.67% |
Eric W. Biedermann | 10 | 4.98% | 1 | 8.33% |
Al Viro | 9 | 4.48% | 1 | 8.33% |
Joe Perches | 6 | 2.99% | 1 | 8.33% |
Octavian Purdila | 5 | 2.49% | 1 | 8.33% |
Jiri Pirko | 3 | 1.49% | 1 | 8.33% |
Hideaki Yoshifuji / 吉藤英明 | 3 | 1.49% | 1 | 8.33% |
Thomas Weber | 1 | 0.50% | 1 | 8.33% |
Total | 201 | 100.00% | 12 | 100.00% |
/* Must be called by hardware driver when HDLC device is being opened */
int hdlc_open(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
#ifdef DEBUG_LINK
printk(KERN_DEBUG "%s: hdlc_open() carrier %i open %i\n", dev->name,
hdlc->carrier, hdlc->open);
#endif
if (hdlc->proto == NULL)
return -ENOSYS; /* no protocol attached */
if (hdlc->proto->open) {
int result = hdlc->proto->open(dev);
if (result)
return result;
}
spin_lock_irq(&hdlc->state_lock);
if (hdlc->carrier) {
netdev_info(dev, "Carrier detected\n");
hdlc_proto_start(dev);
} else
netdev_info(dev, "No carrier\n");
hdlc->open = 1;
spin_unlock_irq(&hdlc->state_lock);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 117 | 85.40% | 4 | 57.14% |
Al Viro | 14 | 10.22% | 2 | 28.57% |
Joe Perches | 6 | 4.38% | 1 | 14.29% |
Total | 137 | 100.00% | 7 | 100.00% |
/* Must be called by hardware driver when HDLC device is being closed */
void hdlc_close(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
#ifdef DEBUG_LINK
printk(KERN_DEBUG "%s: hdlc_close() carrier %i open %i\n", dev->name,
hdlc->carrier, hdlc->open);
#endif
spin_lock_irq(&hdlc->state_lock);
hdlc->open = 0;
if (hdlc->carrier)
hdlc_proto_stop(dev);
spin_unlock_irq(&hdlc->state_lock);
if (hdlc->proto->close)
hdlc->proto->close(dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 78 | 84.78% | 3 | 60.00% |
Al Viro | 14 | 15.22% | 2 | 40.00% |
Total | 92 | 100.00% | 5 | 100.00% |
int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct hdlc_proto *proto = first_proto;
int result;
if (cmd != SIOCWANDEV)
return -EINVAL;
if (dev_to_hdlc(dev)->proto) {
result = dev_to_hdlc(dev)->proto->ioctl(dev, ifr);
if (result != -EINVAL)
return result;
}
/* Not handled by currently attached protocol (if any) */
while (proto) {
if ((result = proto->ioctl(dev, ifr)) != -EINVAL)
return result;
proto = proto->next;
}
return -EINVAL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 57 | 50.44% | 3 | 42.86% |
François Romieu | 53 | 46.90% | 2 | 28.57% |
Al Viro | 3 | 2.65% | 2 | 28.57% |
Total | 113 | 100.00% | 7 | 100.00% |
static const struct header_ops hdlc_null_ops;
static void hdlc_setup_dev(struct net_device *dev)
{
/* Re-init all variables changed by HDLC protocol drivers,
* including ether_setup() called from hdlc_raw_eth.c.
*/
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
dev->priv_flags = IFF_WAN_HDLC;
dev->mtu = HDLC_MAX_MTU;
dev->min_mtu = 68;
dev->max_mtu = HDLC_MAX_MTU;
dev->type = ARPHRD_RAWHDLC;
dev->hard_header_len = 16;
dev->addr_len = 0;
dev->header_ops = &hdlc_null_ops;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Al Viro | 33 | 47.83% | 1 | 16.67% |
Krzysztof Hałasa | 20 | 28.99% | 2 | 33.33% |
Jarod Wilson | 12 | 17.39% | 1 | 16.67% |
Stephen Hemminger | 3 | 4.35% | 1 | 16.67% |
Adrian Bunk | 1 | 1.45% | 1 | 16.67% |
Total | 69 | 100.00% | 6 | 100.00% |
static void hdlc_setup(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
hdlc_setup_dev(dev);
hdlc->carrier = 1;
hdlc->open = 0;
spin_lock_init(&hdlc->state_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 23 | 51.11% | 1 | 50.00% |
Al Viro | 22 | 48.89% | 1 | 50.00% |
Total | 45 | 100.00% | 2 | 100.00% |
struct net_device *alloc_hdlcdev(void *priv)
{
struct net_device *dev;
dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d",
NET_NAME_UNKNOWN, hdlc_setup);
if (dev)
dev_to_hdlc(dev)->priv = priv;
return dev;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Al Viro | 46 | 93.88% | 2 | 50.00% |
Tom Gundersen | 2 | 4.08% | 1 | 25.00% |
Krzysztof Hałasa | 1 | 2.04% | 1 | 25.00% |
Total | 49 | 100.00% | 4 | 100.00% |
void unregister_hdlc_device(struct net_device *dev)
{
rtnl_lock();
detach_hdlc_protocol(dev);
unregister_netdevice(dev);
rtnl_unlock();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 14 | 53.85% | 2 | 33.33% |
François Romieu | 6 | 23.08% | 1 | 16.67% |
Al Viro | 3 | 11.54% | 1 | 16.67% |
Andrew Lunn | 2 | 7.69% | 1 | 16.67% |
David S. Miller | 1 | 3.85% | 1 | 16.67% |
Total | 26 | 100.00% | 6 | 100.00% |
int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
size_t size)
{
int err;
err = detach_hdlc_protocol(dev);
if (err)
return err;
if (!try_module_get(proto->module))
return -ENOSYS;
if (size) {
dev_to_hdlc(dev)->state = kmalloc(size, GFP_KERNEL);
if (dev_to_hdlc(dev)->state == NULL) {
module_put(proto->module);
return -ENOBUFS;
}
}
dev_to_hdlc(dev)->proto = proto;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 73 | 69.52% | 1 | 20.00% |
Andrew Lunn | 12 | 11.43% | 1 | 20.00% |
Joe Perches | 11 | 10.48% | 1 | 20.00% |
Al Viro | 5 | 4.76% | 1 | 20.00% |
François Romieu | 4 | 3.81% | 1 | 20.00% |
Total | 105 | 100.00% | 5 | 100.00% |
int detach_hdlc_protocol(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
int err;
if (hdlc->proto) {
err = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev);
err = notifier_to_errno(err);
if (err) {
netdev_err(dev, "Refused to change device type\n");
return err;
}
if (hdlc->proto->detach)
hdlc->proto->detach(dev);
module_put(hdlc->proto->module);
hdlc->proto = NULL;
}
kfree(hdlc->state);
hdlc->state = NULL;
hdlc_setup_dev(dev);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 74 | 64.35% | 2 | 50.00% |
Andrew Lunn | 39 | 33.91% | 1 | 25.00% |
François Romieu | 2 | 1.74% | 1 | 25.00% |
Total | 115 | 100.00% | 4 | 100.00% |
void register_hdlc_protocol(struct hdlc_proto *proto)
{
rtnl_lock();
proto->next = first_proto;
first_proto = proto;
rtnl_unlock();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 26 | 100.00% | 2 | 100.00% |
Total | 26 | 100.00% | 2 | 100.00% |
void unregister_hdlc_protocol(struct hdlc_proto *proto)
{
struct hdlc_proto **p;
rtnl_lock();
p = &first_proto;
while (*p != proto) {
BUG_ON(!*p);
p = &((*p)->next);
}
*p = proto->next;
rtnl_unlock();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 62 | 100.00% | 2 | 100.00% |
Total | 62 | 100.00% | 2 | 100.00% |
MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
MODULE_DESCRIPTION("HDLC support module");
MODULE_LICENSE("GPL v2");
EXPORT_SYMBOL(hdlc_start_xmit);
EXPORT_SYMBOL(hdlc_open);
EXPORT_SYMBOL(hdlc_close);
EXPORT_SYMBOL(hdlc_ioctl);
EXPORT_SYMBOL(alloc_hdlcdev);
EXPORT_SYMBOL(unregister_hdlc_device);
EXPORT_SYMBOL(register_hdlc_protocol);
EXPORT_SYMBOL(unregister_hdlc_protocol);
EXPORT_SYMBOL(attach_hdlc_protocol);
EXPORT_SYMBOL(detach_hdlc_protocol);
static struct packet_type hdlc_packet_type __read_mostly = {
.type = cpu_to_be16(ETH_P_HDLC),
.func = hdlc_rcv,
};
static struct notifier_block hdlc_notifier = {
.notifier_call = hdlc_device_event,
};
static int __init hdlc_module_init(void)
{
int result;
pr_info("%s\n", version);
if ((result = register_netdevice_notifier(&hdlc_notifier)) != 0)
return result;
dev_add_pack(&hdlc_packet_type);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
François Romieu | 24 | 53.33% | 1 | 33.33% |
Krzysztof Hałasa | 20 | 44.44% | 1 | 33.33% |
Joe Perches | 1 | 2.22% | 1 | 33.33% |
Total | 45 | 100.00% | 3 | 100.00% |
static void __exit hdlc_module_exit(void)
{
dev_remove_pack(&hdlc_packet_type);
unregister_netdevice_notifier(&hdlc_notifier);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
François Romieu | 15 | 71.43% | 1 | 50.00% |
Krzysztof Hałasa | 6 | 28.57% | 1 | 50.00% |
Total | 21 | 100.00% | 2 | 100.00% |
module_init(hdlc_module_init);
module_exit(hdlc_module_exit);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Krzysztof Hałasa | 972 | 64.80% | 15 | 32.61% |
François Romieu | 214 | 14.27% | 2 | 4.35% |
Al Viro | 149 | 9.93% | 9 | 19.57% |
Andrew Lunn | 53 | 3.53% | 2 | 4.35% |
Joe Perches | 31 | 2.07% | 2 | 4.35% |
Eric W. Biedermann | 27 | 1.80% | 2 | 4.35% |
Jarod Wilson | 12 | 0.80% | 1 | 2.17% |
Stephen Hemminger | 11 | 0.73% | 3 | 6.52% |
Octavian Purdila | 10 | 0.67% | 1 | 2.17% |
David S. Miller | 6 | 0.40% | 2 | 4.35% |
Hideaki Yoshifuji / 吉藤英明 | 6 | 0.40% | 1 | 2.17% |
Jiri Pirko | 3 | 0.20% | 1 | 2.17% |
Tom Gundersen | 2 | 0.13% | 1 | 2.17% |
Adrian Bunk | 1 | 0.07% | 1 | 2.17% |
Harvey Harrison | 1 | 0.07% | 1 | 2.17% |
Andrew Morton | 1 | 0.07% | 1 | 2.17% |
Thomas Weber | 1 | 0.07% | 1 | 2.17% |
Total | 1500 | 100.00% | 46 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.