/*1* INET An implementation of the TCP/IP protocol suite for the LINUX2* operating system. INET is implemented using the BSD Socket3* interface as the means of communication with the user level.4*5* HIPPI-type device handling.6*7* Version: @(#)hippi.c 1.0.0 05/29/978*9* Authors: Ross Biro10* Fred N. van Kempen, <[email protected]>11* Mark Evans, <[email protected]>12* Florian La Roche, <[email protected]>13* Alan Cox, <[email protected]>14* Jes Sorensen, <[email protected]>15*16* This program is free software; you can redistribute it and/or17* modify it under the terms of the GNU General Public License18* as published by the Free Software Foundation; either version19* 2 of the License, or (at your option) any later version.20*/2122#include <linux/module.h>23#include <linux/types.h>24#include <linux/kernel.h>25#include <linux/string.h>26#include <linux/mm.h>27#include <linux/socket.h>28#include <linux/in.h>29#include <linux/inet.h>30#include <linux/netdevice.h>31#include <linux/hippidevice.h>32#include <linux/skbuff.h>33#include <linux/errno.h>34#include <net/arp.h>35#include <net/sock.h>36#include <asm/uaccess.h>37#include <asm/system.h>3839/*40* Create the HIPPI MAC header for an arbitrary protocol layer41*42* saddr=NULL means use device source address43* daddr=NULL means leave destination address (eg unresolved arp)44*/4546static int hippi_header(struct sk_buff *skb, struct net_device *dev,47unsigned short type,48const void *daddr, const void *saddr, unsigned len)49{50struct hippi_hdr *hip = (struct hippi_hdr *)skb_push(skb, HIPPI_HLEN);51struct hippi_cb *hcb = (struct hippi_cb *) skb->cb;5253if (!len){54len = skb->len - HIPPI_HLEN;55printk("hippi_header(): length not supplied\n");56}5758/*59* Due to the stupidity of the little endian byte-order we60* have to set the fp field this way.61*/62hip->fp.fixed = htonl(0x04800018);63hip->fp.d2_size = htonl(len + 8);64hip->le.fc = 0;65hip->le.double_wide = 0; /* only HIPPI 800 for the time being */66hip->le.message_type = 0; /* Data PDU */6768hip->le.dest_addr_type = 2; /* 12 bit SC address */69hip->le.src_addr_type = 2; /* 12 bit SC address */7071memcpy(hip->le.src_switch_addr, dev->dev_addr + 3, 3);72memset(&hip->le.reserved, 0, 16);7374hip->snap.dsap = HIPPI_EXTENDED_SAP;75hip->snap.ssap = HIPPI_EXTENDED_SAP;76hip->snap.ctrl = HIPPI_UI_CMD;77hip->snap.oui[0] = 0x00;78hip->snap.oui[1] = 0x00;79hip->snap.oui[2] = 0x00;80hip->snap.ethertype = htons(type);8182if (daddr)83{84memcpy(hip->le.dest_switch_addr, daddr + 3, 3);85memcpy(&hcb->ifield, daddr + 2, 4);86return HIPPI_HLEN;87}88hcb->ifield = 0;89return -((int)HIPPI_HLEN);90}919293/*94* Rebuild the HIPPI MAC header. This is called after an ARP has95* completed on this sk_buff. We now let ARP fill in the other fields.96*/9798static int hippi_rebuild_header(struct sk_buff *skb)99{100struct hippi_hdr *hip = (struct hippi_hdr *)skb->data;101102/*103* Only IP is currently supported104*/105106if(hip->snap.ethertype != htons(ETH_P_IP))107{108printk(KERN_DEBUG "%s: unable to resolve type %X addresses.\n",skb->dev->name,ntohs(hip->snap.ethertype));109return 0;110}111112/*113* We don't support dynamic ARP on HIPPI, but we use the ARP114* static ARP tables to hold the I-FIELDs.115*/116return arp_find(hip->le.daddr, skb);117}118119120/*121* Determine the packet's protocol ID.122*/123124__be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)125{126struct hippi_hdr *hip;127128/*129* This is actually wrong ... question is if we really should130* set the raw address here.131*/132skb->dev = dev;133skb_reset_mac_header(skb);134hip = (struct hippi_hdr *)skb_mac_header(skb);135skb_pull(skb, HIPPI_HLEN);136137/*138* No fancy promisc stuff here now.139*/140141return hip->snap.ethertype;142}143144EXPORT_SYMBOL(hippi_type_trans);145146int hippi_change_mtu(struct net_device *dev, int new_mtu)147{148/*149* HIPPI's got these nice large MTUs.150*/151if ((new_mtu < 68) || (new_mtu > 65280))152return -EINVAL;153dev->mtu = new_mtu;154return 0;155}156EXPORT_SYMBOL(hippi_change_mtu);157158/*159* For HIPPI we will actually use the lower 4 bytes of the hardware160* address as the I-FIELD rather than the actual hardware address.161*/162int hippi_mac_addr(struct net_device *dev, void *p)163{164struct sockaddr *addr = p;165if (netif_running(dev))166return -EBUSY;167memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);168return 0;169}170EXPORT_SYMBOL(hippi_mac_addr);171172int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)173{174/* Never send broadcast/multicast ARP messages */175p->mcast_probes = 0;176177/* In IPv6 unicast probes are valid even on NBMA,178* because they are encapsulated in normal IPv6 protocol.179* Should be a generic flag.180*/181if (p->tbl->family != AF_INET6)182p->ucast_probes = 0;183return 0;184}185EXPORT_SYMBOL(hippi_neigh_setup_dev);186187static const struct header_ops hippi_header_ops = {188.create = hippi_header,189.rebuild = hippi_rebuild_header,190};191192193static void hippi_setup(struct net_device *dev)194{195dev->header_ops = &hippi_header_ops;196197/*198* We don't support HIPPI `ARP' for the time being, and probably199* never will unless someone else implements it. However we200* still need a fake ARPHRD to make ifconfig and friends play ball.201*/202dev->type = ARPHRD_HIPPI;203dev->hard_header_len = HIPPI_HLEN;204dev->mtu = 65280;205dev->addr_len = HIPPI_ALEN;206dev->tx_queue_len = 25 /* 5 */;207memset(dev->broadcast, 0xFF, HIPPI_ALEN);208209210/*211* HIPPI doesn't support broadcast+multicast and we only use212* static ARP tables. ARP is disabled by hippi_neigh_setup_dev.213*/214dev->flags = 0;215}216217/**218* alloc_hippi_dev - Register HIPPI device219* @sizeof_priv: Size of additional driver-private structure to be allocated220* for this HIPPI device221*222* Fill in the fields of the device structure with HIPPI-generic values.223*224* Constructs a new net device, complete with a private data area of225* size @sizeof_priv. A 32-byte (not bit) alignment is enforced for226* this private data area.227*/228229struct net_device *alloc_hippi_dev(int sizeof_priv)230{231return alloc_netdev(sizeof_priv, "hip%d", hippi_setup);232}233234EXPORT_SYMBOL(alloc_hippi_dev);235236237