125763b3cSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Generic HDLC support routines for Linux
41da177e4SLinus Torvalds * Cisco HDLC support
51da177e4SLinus Torvalds *
6eb2a2fd9SKrzysztof Halasa * Copyright (C) 2000 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds
91da177e4SLinus Torvalds #include <linux/errno.h>
101da177e4SLinus Torvalds #include <linux/hdlc.h>
114dfce407SKrzysztof Hałasa #include <linux/if_arp.h>
124dfce407SKrzysztof Hałasa #include <linux/inetdevice.h>
134dfce407SKrzysztof Hałasa #include <linux/init.h>
144dfce407SKrzysztof Hałasa #include <linux/kernel.h>
154dfce407SKrzysztof Hałasa #include <linux/module.h>
164dfce407SKrzysztof Hałasa #include <linux/pkt_sched.h>
174dfce407SKrzysztof Hałasa #include <linux/poll.h>
184dfce407SKrzysztof Hałasa #include <linux/rtnetlink.h>
194dfce407SKrzysztof Hałasa #include <linux/skbuff.h>
201da177e4SLinus Torvalds
211da177e4SLinus Torvalds #undef DEBUG_HARD_HEADER
221da177e4SLinus Torvalds
231da177e4SLinus Torvalds #define CISCO_MULTICAST 0x8F /* Cisco multicast address */
241da177e4SLinus Torvalds #define CISCO_UNICAST 0x0F /* Cisco unicast address */
251da177e4SLinus Torvalds #define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
261da177e4SLinus Torvalds #define CISCO_SYS_INFO 0x2000 /* Cisco interface/system info */
271da177e4SLinus Torvalds #define CISCO_ADDR_REQ 0 /* Cisco address request */
281da177e4SLinus Torvalds #define CISCO_ADDR_REPLY 1 /* Cisco address reply */
291da177e4SLinus Torvalds #define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */
301da177e4SLinus Torvalds
31eb2a2fd9SKrzysztof Halasa struct hdlc_header {
32eb2a2fd9SKrzysztof Halasa u8 address;
33eb2a2fd9SKrzysztof Halasa u8 control;
34abf17ffdSKrzysztof Halasa __be16 protocol;
35ba2d3587SEric Dumazet } __packed;
36eb2a2fd9SKrzysztof Halasa
37eb2a2fd9SKrzysztof Halasa struct cisco_packet {
38abf17ffdSKrzysztof Halasa __be32 type; /* code */
39abf17ffdSKrzysztof Halasa __be32 par1;
40abf17ffdSKrzysztof Halasa __be32 par2;
41abf17ffdSKrzysztof Halasa __be16 rel; /* reliability */
42abf17ffdSKrzysztof Halasa __be32 time;
43ba2d3587SEric Dumazet } __packed;
44eb2a2fd9SKrzysztof Halasa #define CISCO_PACKET_LEN 18
45eb2a2fd9SKrzysztof Halasa #define CISCO_BIG_PACKET_LEN 20
46eb2a2fd9SKrzysztof Halasa
47eb2a2fd9SKrzysztof Halasa struct cisco_state {
48eb2a2fd9SKrzysztof Halasa cisco_proto settings;
49eb2a2fd9SKrzysztof Halasa
50eb2a2fd9SKrzysztof Halasa struct timer_list timer;
51d26c089eSKees Cook struct net_device *dev;
52aff26e2fSKrzysztof Halasa spinlock_t lock;
53eb2a2fd9SKrzysztof Halasa unsigned long last_poll;
54eb2a2fd9SKrzysztof Halasa int up;
559652041dSKrzysztof Halasa u32 txseq; /* TX sequence number, 0 = none */
56eb2a2fd9SKrzysztof Halasa u32 rxseq; /* RX sequence number */
57eb2a2fd9SKrzysztof Halasa };
58eb2a2fd9SKrzysztof Halasa
59*ad7eab2aSArnd Bergmann static int cisco_ioctl(struct net_device *dev, struct if_settings *ifs);
60eb2a2fd9SKrzysztof Halasa
state(hdlc_device * hdlc)61eb2a2fd9SKrzysztof Halasa static inline struct cisco_state *state(hdlc_device *hdlc)
62eb2a2fd9SKrzysztof Halasa {
634dfce407SKrzysztof Hałasa return (struct cisco_state *)hdlc->state;
64eb2a2fd9SKrzysztof Halasa }
65eb2a2fd9SKrzysztof Halasa
cisco_hard_header(struct sk_buff * skb,struct net_device * dev,u16 type,const void * daddr,const void * saddr,unsigned int len)661da177e4SLinus Torvalds static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev,
673b04dddeSStephen Hemminger u16 type, const void *daddr, const void *saddr,
681da177e4SLinus Torvalds unsigned int len)
691da177e4SLinus Torvalds {
70eb2a2fd9SKrzysztof Halasa struct hdlc_header *data;
711da177e4SLinus Torvalds #ifdef DEBUG_HARD_HEADER
72c68d7248SChen Zhou netdev_dbg(dev, "%s called\n", __func__);
731da177e4SLinus Torvalds #endif
741da177e4SLinus Torvalds
75eb2a2fd9SKrzysztof Halasa skb_push(skb, sizeof(struct hdlc_header));
76eb2a2fd9SKrzysztof Halasa data = (struct hdlc_header *)skb->data;
771da177e4SLinus Torvalds if (type == CISCO_KEEPALIVE)
781da177e4SLinus Torvalds data->address = CISCO_MULTICAST;
791da177e4SLinus Torvalds else
801da177e4SLinus Torvalds data->address = CISCO_UNICAST;
811da177e4SLinus Torvalds data->control = 0;
821da177e4SLinus Torvalds data->protocol = htons(type);
831da177e4SLinus Torvalds
84eb2a2fd9SKrzysztof Halasa return sizeof(struct hdlc_header);
851da177e4SLinus Torvalds }
861da177e4SLinus Torvalds
cisco_keepalive_send(struct net_device * dev,u32 type,__be32 par1,__be32 par2)871da177e4SLinus Torvalds static void cisco_keepalive_send(struct net_device *dev, u32 type,
88abf17ffdSKrzysztof Halasa __be32 par1, __be32 par2)
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds struct sk_buff *skb;
91eb2a2fd9SKrzysztof Halasa struct cisco_packet *data;
921da177e4SLinus Torvalds
93eb2a2fd9SKrzysztof Halasa skb = dev_alloc_skb(sizeof(struct hdlc_header) +
94eb2a2fd9SKrzysztof Halasa sizeof(struct cisco_packet));
9505ff5525SPeng Li if (!skb)
961da177e4SLinus Torvalds return;
9705ff5525SPeng Li
981da177e4SLinus Torvalds skb_reserve(skb, 4);
991da177e4SLinus Torvalds cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0);
100eb2a2fd9SKrzysztof Halasa data = (struct cisco_packet *)(skb->data + 4);
1011da177e4SLinus Torvalds
1021da177e4SLinus Torvalds data->type = htonl(type);
103abf17ffdSKrzysztof Halasa data->par1 = par1;
104abf17ffdSKrzysztof Halasa data->par2 = par2;
10509640e63SHarvey Harrison data->rel = cpu_to_be16(0xFFFF);
1061da177e4SLinus Torvalds /* we will need do_div here if 1000 % HZ != 0 */
1071da177e4SLinus Torvalds data->time = htonl((jiffies - INITIAL_JIFFIES) * (1000 / HZ));
1081da177e4SLinus Torvalds
109eb2a2fd9SKrzysztof Halasa skb_put(skb, sizeof(struct cisco_packet));
1101da177e4SLinus Torvalds skb->priority = TC_PRIO_CONTROL;
1111da177e4SLinus Torvalds skb->dev = dev;
1129fb030a7SXie He skb->protocol = htons(ETH_P_HDLC);
113c1d2bbe1SArnaldo Carvalho de Melo skb_reset_network_header(skb);
1141da177e4SLinus Torvalds
1151da177e4SLinus Torvalds dev_queue_xmit(skb);
1161da177e4SLinus Torvalds }
1171da177e4SLinus Torvalds
cisco_type_trans(struct sk_buff * skb,struct net_device * dev)118ab611487SAlexey Dobriyan static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev)
1191da177e4SLinus Torvalds {
120eb2a2fd9SKrzysztof Halasa struct hdlc_header *data = (struct hdlc_header *)skb->data;
1211da177e4SLinus Torvalds
122eb2a2fd9SKrzysztof Halasa if (skb->len < sizeof(struct hdlc_header))
12309640e63SHarvey Harrison return cpu_to_be16(ETH_P_HDLC);
1241da177e4SLinus Torvalds
1251da177e4SLinus Torvalds if (data->address != CISCO_MULTICAST &&
1261da177e4SLinus Torvalds data->address != CISCO_UNICAST)
12709640e63SHarvey Harrison return cpu_to_be16(ETH_P_HDLC);
1281da177e4SLinus Torvalds
1291da177e4SLinus Torvalds switch (data->protocol) {
13009640e63SHarvey Harrison case cpu_to_be16(ETH_P_IP):
13109640e63SHarvey Harrison case cpu_to_be16(ETH_P_IPX):
13209640e63SHarvey Harrison case cpu_to_be16(ETH_P_IPV6):
133eb2a2fd9SKrzysztof Halasa skb_pull(skb, sizeof(struct hdlc_header));
1341da177e4SLinus Torvalds return data->protocol;
1351da177e4SLinus Torvalds default:
13609640e63SHarvey Harrison return cpu_to_be16(ETH_P_HDLC);
1371da177e4SLinus Torvalds }
1381da177e4SLinus Torvalds }
1391da177e4SLinus Torvalds
cisco_rx(struct sk_buff * skb)1401da177e4SLinus Torvalds static int cisco_rx(struct sk_buff *skb)
1411da177e4SLinus Torvalds {
1421da177e4SLinus Torvalds struct net_device *dev = skb->dev;
1431da177e4SLinus Torvalds hdlc_device *hdlc = dev_to_hdlc(dev);
144aff26e2fSKrzysztof Halasa struct cisco_state *st = state(hdlc);
145eb2a2fd9SKrzysztof Halasa struct hdlc_header *data = (struct hdlc_header *)skb->data;
146eb2a2fd9SKrzysztof Halasa struct cisco_packet *cisco_data;
1471da177e4SLinus Torvalds struct in_device *in_dev;
148a144ea4bSAl Viro __be32 addr, mask;
1499652041dSKrzysztof Halasa u32 ack;
1501da177e4SLinus Torvalds
151eb2a2fd9SKrzysztof Halasa if (skb->len < sizeof(struct hdlc_header))
1521da177e4SLinus Torvalds goto rx_error;
1531da177e4SLinus Torvalds
1541da177e4SLinus Torvalds if (data->address != CISCO_MULTICAST &&
1551da177e4SLinus Torvalds data->address != CISCO_UNICAST)
1561da177e4SLinus Torvalds goto rx_error;
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds switch (ntohs(data->protocol)) {
1591da177e4SLinus Torvalds case CISCO_SYS_INFO:
1601da177e4SLinus Torvalds /* Packet is not needed, drop it. */
1611da177e4SLinus Torvalds dev_kfree_skb_any(skb);
1621da177e4SLinus Torvalds return NET_RX_SUCCESS;
1631da177e4SLinus Torvalds
1641da177e4SLinus Torvalds case CISCO_KEEPALIVE:
165eb2a2fd9SKrzysztof Halasa if ((skb->len != sizeof(struct hdlc_header) +
166eb2a2fd9SKrzysztof Halasa CISCO_PACKET_LEN) &&
167eb2a2fd9SKrzysztof Halasa (skb->len != sizeof(struct hdlc_header) +
168eb2a2fd9SKrzysztof Halasa CISCO_BIG_PACKET_LEN)) {
16912a3bfefSJoe Perches netdev_info(dev, "Invalid length of Cisco control packet (%d bytes)\n",
17012a3bfefSJoe Perches skb->len);
1711da177e4SLinus Torvalds goto rx_error;
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds
174eb2a2fd9SKrzysztof Halasa cisco_data = (struct cisco_packet *)(skb->data + sizeof
175eb2a2fd9SKrzysztof Halasa (struct hdlc_header));
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds switch (ntohl(cisco_data->type)) {
1781da177e4SLinus Torvalds case CISCO_ADDR_REQ: /* Stolen from syncppp.c :-) */
17995ae6b22SEric Dumazet rcu_read_lock();
18095ae6b22SEric Dumazet in_dev = __in_dev_get_rcu(dev);
1811da177e4SLinus Torvalds addr = 0;
18209640e63SHarvey Harrison mask = ~cpu_to_be32(0); /* is the mask correct? */
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds if (in_dev != NULL) {
185cb8f1478SFlorian Westphal const struct in_ifaddr *ifa;
1861da177e4SLinus Torvalds
187cb8f1478SFlorian Westphal in_dev_for_each_ifa_rcu(ifa, in_dev) {
1881da177e4SLinus Torvalds if (strcmp(dev->name,
189cb8f1478SFlorian Westphal ifa->ifa_label) == 0) {
190cb8f1478SFlorian Westphal addr = ifa->ifa_local;
191cb8f1478SFlorian Westphal mask = ifa->ifa_mask;
1921da177e4SLinus Torvalds break;
1931da177e4SLinus Torvalds }
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds cisco_keepalive_send(dev, CISCO_ADDR_REPLY,
1971da177e4SLinus Torvalds addr, mask);
1981da177e4SLinus Torvalds }
19995ae6b22SEric Dumazet rcu_read_unlock();
2001da177e4SLinus Torvalds dev_kfree_skb_any(skb);
2011da177e4SLinus Torvalds return NET_RX_SUCCESS;
2021da177e4SLinus Torvalds
2031da177e4SLinus Torvalds case CISCO_ADDR_REPLY:
20412a3bfefSJoe Perches netdev_info(dev, "Unexpected Cisco IP address reply\n");
2051da177e4SLinus Torvalds goto rx_error;
2061da177e4SLinus Torvalds
2071da177e4SLinus Torvalds case CISCO_KEEPALIVE_REQ:
208aff26e2fSKrzysztof Halasa spin_lock(&st->lock);
209aff26e2fSKrzysztof Halasa st->rxseq = ntohl(cisco_data->par1);
2109652041dSKrzysztof Halasa ack = ntohl(cisco_data->par2);
2119652041dSKrzysztof Halasa if (ack && (ack == st->txseq ||
2129652041dSKrzysztof Halasa /* our current REQ may be in transit */
2139652041dSKrzysztof Halasa ack == st->txseq - 1)) {
214aff26e2fSKrzysztof Halasa st->last_poll = jiffies;
215aff26e2fSKrzysztof Halasa if (!st->up) {
2161da177e4SLinus Torvalds u32 sec, min, hrs, days;
2174e38d514SPeng Li
2181da177e4SLinus Torvalds sec = ntohl(cisco_data->time) / 1000;
2191da177e4SLinus Torvalds min = sec / 60; sec -= min * 60;
2201da177e4SLinus Torvalds hrs = min / 60; min -= hrs * 60;
2211da177e4SLinus Torvalds days = hrs / 24; hrs -= days * 24;
22212a3bfefSJoe Perches netdev_info(dev, "Link up (peer uptime %ud%uh%um%us)\n",
22312a3bfefSJoe Perches days, hrs, min, sec);
224c2ce9204SKrzysztof Halasa netif_dormant_off(dev);
225aff26e2fSKrzysztof Halasa st->up = 1;
2261da177e4SLinus Torvalds }
2271da177e4SLinus Torvalds }
228aff26e2fSKrzysztof Halasa spin_unlock(&st->lock);
2291da177e4SLinus Torvalds
2301da177e4SLinus Torvalds dev_kfree_skb_any(skb);
2311da177e4SLinus Torvalds return NET_RX_SUCCESS;
2321da177e4SLinus Torvalds } /* switch (keepalive type) */
2331da177e4SLinus Torvalds } /* switch (protocol) */
2341da177e4SLinus Torvalds
23512a3bfefSJoe Perches netdev_info(dev, "Unsupported protocol %x\n", ntohs(data->protocol));
2361da177e4SLinus Torvalds dev_kfree_skb_any(skb);
2371da177e4SLinus Torvalds return NET_RX_DROP;
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds rx_error:
240198191c4SKrzysztof Halasa dev->stats.rx_errors++; /* Mark error */
2411da177e4SLinus Torvalds dev_kfree_skb_any(skb);
2421da177e4SLinus Torvalds return NET_RX_DROP;
2431da177e4SLinus Torvalds }
2441da177e4SLinus Torvalds
cisco_timer(struct timer_list * t)245d26c089eSKees Cook static void cisco_timer(struct timer_list *t)
2461da177e4SLinus Torvalds {
247d26c089eSKees Cook struct cisco_state *st = from_timer(st, t, timer);
248d26c089eSKees Cook struct net_device *dev = st->dev;
2491da177e4SLinus Torvalds
250aff26e2fSKrzysztof Halasa spin_lock(&st->lock);
251aff26e2fSKrzysztof Halasa if (st->up &&
252aff26e2fSKrzysztof Halasa time_after(jiffies, st->last_poll + st->settings.timeout * HZ)) {
253aff26e2fSKrzysztof Halasa st->up = 0;
25412a3bfefSJoe Perches netdev_info(dev, "Link down\n");
255c2ce9204SKrzysztof Halasa netif_dormant_on(dev);
2561da177e4SLinus Torvalds }
2571da177e4SLinus Torvalds
258aff26e2fSKrzysztof Halasa cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, htonl(++st->txseq),
259aff26e2fSKrzysztof Halasa htonl(st->rxseq));
260aff26e2fSKrzysztof Halasa spin_unlock(&st->lock);
261aff26e2fSKrzysztof Halasa
262aff26e2fSKrzysztof Halasa st->timer.expires = jiffies + st->settings.interval * HZ;
263aff26e2fSKrzysztof Halasa add_timer(&st->timer);
2641da177e4SLinus Torvalds }
2651da177e4SLinus Torvalds
cisco_start(struct net_device * dev)2661da177e4SLinus Torvalds static void cisco_start(struct net_device *dev)
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds hdlc_device *hdlc = dev_to_hdlc(dev);
269aff26e2fSKrzysztof Halasa struct cisco_state *st = state(hdlc);
270aff26e2fSKrzysztof Halasa unsigned long flags;
2711da177e4SLinus Torvalds
272aff26e2fSKrzysztof Halasa spin_lock_irqsave(&st->lock, flags);
2739652041dSKrzysztof Halasa st->up = st->txseq = st->rxseq = 0;
274aff26e2fSKrzysztof Halasa spin_unlock_irqrestore(&st->lock, flags);
275aff26e2fSKrzysztof Halasa
276d26c089eSKees Cook st->dev = dev;
277d26c089eSKees Cook timer_setup(&st->timer, cisco_timer, 0);
278aff26e2fSKrzysztof Halasa st->timer.expires = jiffies + HZ; /* First poll after 1 s */
279aff26e2fSKrzysztof Halasa add_timer(&st->timer);
2801da177e4SLinus Torvalds }
2811da177e4SLinus Torvalds
cisco_stop(struct net_device * dev)2821da177e4SLinus Torvalds static void cisco_stop(struct net_device *dev)
2831da177e4SLinus Torvalds {
2841da177e4SLinus Torvalds hdlc_device *hdlc = dev_to_hdlc(dev);
285aff26e2fSKrzysztof Halasa struct cisco_state *st = state(hdlc);
286aff26e2fSKrzysztof Halasa unsigned long flags;
287aff26e2fSKrzysztof Halasa
288aff26e2fSKrzysztof Halasa del_timer_sync(&st->timer);
289aff26e2fSKrzysztof Halasa
290aff26e2fSKrzysztof Halasa spin_lock_irqsave(&st->lock, flags);
291c2ce9204SKrzysztof Halasa netif_dormant_on(dev);
2929652041dSKrzysztof Halasa st->up = st->txseq = 0;
293aff26e2fSKrzysztof Halasa spin_unlock_irqrestore(&st->lock, flags);
2941da177e4SLinus Torvalds }
2951da177e4SLinus Torvalds
296eb2a2fd9SKrzysztof Halasa static struct hdlc_proto proto = {
297eb2a2fd9SKrzysztof Halasa .start = cisco_start,
298eb2a2fd9SKrzysztof Halasa .stop = cisco_stop,
299eb2a2fd9SKrzysztof Halasa .type_trans = cisco_type_trans,
300eb2a2fd9SKrzysztof Halasa .ioctl = cisco_ioctl,
30140d25142SKrzysztof Halasa .netif_rx = cisco_rx,
302eb2a2fd9SKrzysztof Halasa .module = THIS_MODULE,
303eb2a2fd9SKrzysztof Halasa };
304eb2a2fd9SKrzysztof Halasa
3053b04dddeSStephen Hemminger static const struct header_ops cisco_header_ops = {
3063b04dddeSStephen Hemminger .create = cisco_hard_header,
3073b04dddeSStephen Hemminger };
308eb2a2fd9SKrzysztof Halasa
cisco_ioctl(struct net_device * dev,struct if_settings * ifs)309*ad7eab2aSArnd Bergmann static int cisco_ioctl(struct net_device *dev, struct if_settings *ifs)
3101da177e4SLinus Torvalds {
311*ad7eab2aSArnd Bergmann cisco_proto __user *cisco_s = ifs->ifs_ifsu.cisco;
3121da177e4SLinus Torvalds const size_t size = sizeof(cisco_proto);
3131da177e4SLinus Torvalds cisco_proto new_settings;
3141da177e4SLinus Torvalds hdlc_device *hdlc = dev_to_hdlc(dev);
3151da177e4SLinus Torvalds int result;
3161da177e4SLinus Torvalds
317*ad7eab2aSArnd Bergmann switch (ifs->type) {
3181da177e4SLinus Torvalds case IF_GET_PROTO:
319eb2a2fd9SKrzysztof Halasa if (dev_to_hdlc(dev)->proto != &proto)
320eb2a2fd9SKrzysztof Halasa return -EINVAL;
321*ad7eab2aSArnd Bergmann ifs->type = IF_PROTO_CISCO;
322*ad7eab2aSArnd Bergmann if (ifs->size < size) {
323*ad7eab2aSArnd Bergmann ifs->size = size; /* data size wanted */
3241da177e4SLinus Torvalds return -ENOBUFS;
3251da177e4SLinus Torvalds }
326eb2a2fd9SKrzysztof Halasa if (copy_to_user(cisco_s, &state(hdlc)->settings, size))
3271da177e4SLinus Torvalds return -EFAULT;
3281da177e4SLinus Torvalds return 0;
3291da177e4SLinus Torvalds
3301da177e4SLinus Torvalds case IF_PROTO_CISCO:
3311da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN))
3321da177e4SLinus Torvalds return -EPERM;
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds if (dev->flags & IFF_UP)
3351da177e4SLinus Torvalds return -EBUSY;
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvalds if (copy_from_user(&new_settings, cisco_s, size))
3381da177e4SLinus Torvalds return -EFAULT;
3391da177e4SLinus Torvalds
3401da177e4SLinus Torvalds if (new_settings.interval < 1 ||
3411da177e4SLinus Torvalds new_settings.timeout < 2)
3421da177e4SLinus Torvalds return -EINVAL;
3431da177e4SLinus Torvalds
344c1300f37SPeng Li result = hdlc->attach(dev, ENCODING_NRZ,
345c1300f37SPeng Li PARITY_CRC16_PR1_CCITT);
3461da177e4SLinus Torvalds if (result)
3471da177e4SLinus Torvalds return result;
3481da177e4SLinus Torvalds
34940d25142SKrzysztof Halasa result = attach_hdlc_protocol(dev, &proto,
350eb2a2fd9SKrzysztof Halasa sizeof(struct cisco_state));
351eb2a2fd9SKrzysztof Halasa if (result)
352eb2a2fd9SKrzysztof Halasa return result;
3531da177e4SLinus Torvalds
354eb2a2fd9SKrzysztof Halasa memcpy(&state(hdlc)->settings, &new_settings, size);
355aff26e2fSKrzysztof Halasa spin_lock_init(&state(hdlc)->lock);
3563b04dddeSStephen Hemminger dev->header_ops = &cisco_header_ops;
3571a545ebeSXie He dev->hard_header_len = sizeof(struct hdlc_header);
3581da177e4SLinus Torvalds dev->type = ARPHRD_CISCO;
3592f8364a2SAndrew Lunn call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
360c2ce9204SKrzysztof Halasa netif_dormant_on(dev);
3611da177e4SLinus Torvalds return 0;
3621da177e4SLinus Torvalds }
3631da177e4SLinus Torvalds
3641da177e4SLinus Torvalds return -EINVAL;
3651da177e4SLinus Torvalds }
366eb2a2fd9SKrzysztof Halasa
hdlc_cisco_init(void)367a1739c30SRandy Dunlap static int __init hdlc_cisco_init(void)
368eb2a2fd9SKrzysztof Halasa {
369eb2a2fd9SKrzysztof Halasa register_hdlc_protocol(&proto);
370eb2a2fd9SKrzysztof Halasa return 0;
371eb2a2fd9SKrzysztof Halasa }
372eb2a2fd9SKrzysztof Halasa
hdlc_cisco_exit(void)373a1739c30SRandy Dunlap static void __exit hdlc_cisco_exit(void)
374eb2a2fd9SKrzysztof Halasa {
375eb2a2fd9SKrzysztof Halasa unregister_hdlc_protocol(&proto);
376eb2a2fd9SKrzysztof Halasa }
377eb2a2fd9SKrzysztof Halasa
378a1739c30SRandy Dunlap module_init(hdlc_cisco_init);
379a1739c30SRandy Dunlap module_exit(hdlc_cisco_exit);
380eb2a2fd9SKrzysztof Halasa
381eb2a2fd9SKrzysztof Halasa MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
382eb2a2fd9SKrzysztof Halasa MODULE_DESCRIPTION("Cisco HDLC protocol support for generic HDLC");
383eb2a2fd9SKrzysztof Halasa MODULE_LICENSE("GPL v2");
384