// SPDX-License-Identifier: GPL-2.0-or-later1/*2* INET An implementation of the TCP/IP protocol suite for the LINUX3* operating system. INET is implemented using the BSD Socket4* interface as the means of communication with the user level.5*6* HIPPI-type device handling.7*8* Version: @(#)hippi.c 1.0.0 05/29/979*10* Authors: Ross Biro11* Fred N. van Kempen, <[email protected]>12* Mark Evans, <[email protected]>13* Florian La Roche, <[email protected]>14* Alan Cox, <[email protected]>15* Jes Sorensen, <[email protected]>16*/1718#include <linux/module.h>19#include <linux/types.h>20#include <linux/kernel.h>21#include <linux/string.h>22#include <linux/mm.h>23#include <linux/socket.h>24#include <linux/in.h>25#include <linux/inet.h>26#include <linux/netdevice.h>27#include <linux/hippidevice.h>28#include <linux/skbuff.h>29#include <linux/errno.h>30#include <net/arp.h>31#include <net/sock.h>32#include <linux/uaccess.h>3334/*35* Create the HIPPI MAC header for an arbitrary protocol layer36*37* saddr=NULL means use device source address38* daddr=NULL means leave destination address (eg unresolved arp)39*/4041static int hippi_header(struct sk_buff *skb, struct net_device *dev,42unsigned short type,43const void *daddr, const void *saddr, unsigned int len)44{45struct hippi_hdr *hip = skb_push(skb, HIPPI_HLEN);46struct hippi_cb *hcb = (struct hippi_cb *) skb->cb;4748if (!len){49len = skb->len - HIPPI_HLEN;50printk("hippi_header(): length not supplied\n");51}5253/*54* Due to the stupidity of the little endian byte-order we55* have to set the fp field this way.56*/57hip->fp.fixed = htonl(0x04800018);58hip->fp.d2_size = htonl(len + 8);59hip->le.fc = 0;60hip->le.double_wide = 0; /* only HIPPI 800 for the time being */61hip->le.message_type = 0; /* Data PDU */6263hip->le.dest_addr_type = 2; /* 12 bit SC address */64hip->le.src_addr_type = 2; /* 12 bit SC address */6566memcpy(hip->le.src_switch_addr, dev->dev_addr + 3, 3);67memset_startat(&hip->le, 0, reserved);6869hip->snap.dsap = HIPPI_EXTENDED_SAP;70hip->snap.ssap = HIPPI_EXTENDED_SAP;71hip->snap.ctrl = HIPPI_UI_CMD;72hip->snap.oui[0] = 0x00;73hip->snap.oui[1] = 0x00;74hip->snap.oui[2] = 0x00;75hip->snap.ethertype = htons(type);7677if (daddr)78{79memcpy(hip->le.dest_switch_addr, daddr + 3, 3);80memcpy(&hcb->ifield, daddr + 2, 4);81return HIPPI_HLEN;82}83hcb->ifield = 0;84return -((int)HIPPI_HLEN);85}868788/*89* Determine the packet's protocol ID.90*/9192__be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)93{94struct hippi_hdr *hip;9596/*97* This is actually wrong ... question is if we really should98* set the raw address here.99*/100skb->dev = dev;101skb_reset_mac_header(skb);102hip = (struct hippi_hdr *)skb_mac_header(skb);103skb_pull(skb, HIPPI_HLEN);104105/*106* No fancy promisc stuff here now.107*/108109return hip->snap.ethertype;110}111112EXPORT_SYMBOL(hippi_type_trans);113114/*115* For HIPPI we will actually use the lower 4 bytes of the hardware116* address as the I-FIELD rather than the actual hardware address.117*/118int hippi_mac_addr(struct net_device *dev, void *p)119{120struct sockaddr *addr = p;121if (netif_running(dev))122return -EBUSY;123dev_addr_set(dev, addr->sa_data);124return 0;125}126EXPORT_SYMBOL(hippi_mac_addr);127128int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)129{130/* Never send broadcast/multicast ARP messages */131NEIGH_VAR_INIT(p, MCAST_PROBES, 0);132133/* In IPv6 unicast probes are valid even on NBMA,134* because they are encapsulated in normal IPv6 protocol.135* Should be a generic flag.136*/137if (p->tbl->family != AF_INET6)138NEIGH_VAR_INIT(p, UCAST_PROBES, 0);139return 0;140}141EXPORT_SYMBOL(hippi_neigh_setup_dev);142143static const struct header_ops hippi_header_ops = {144.create = hippi_header,145};146147148static void hippi_setup(struct net_device *dev)149{150dev->header_ops = &hippi_header_ops;151152/*153* We don't support HIPPI `ARP' for the time being, and probably154* never will unless someone else implements it. However we155* still need a fake ARPHRD to make ifconfig and friends play ball.156*/157dev->type = ARPHRD_HIPPI;158dev->hard_header_len = HIPPI_HLEN;159dev->mtu = 65280;160dev->min_mtu = 68;161dev->max_mtu = 65280;162dev->addr_len = HIPPI_ALEN;163dev->tx_queue_len = 25 /* 5 */;164memset(dev->broadcast, 0xFF, HIPPI_ALEN);165166167/*168* HIPPI doesn't support broadcast+multicast and we only use169* static ARP tables. ARP is disabled by hippi_neigh_setup_dev.170*/171dev->flags = 0;172}173174/**175* alloc_hippi_dev - Register HIPPI device176* @sizeof_priv: Size of additional driver-private structure to be allocated177* for this HIPPI device178*179* Fill in the fields of the device structure with HIPPI-generic values.180*181* Constructs a new net device, complete with a private data area of182* size @sizeof_priv. A 32-byte (not bit) alignment is enforced for183* this private data area.184*/185186struct net_device *alloc_hippi_dev(int sizeof_priv)187{188return alloc_netdev(sizeof_priv, "hip%d", NET_NAME_UNKNOWN,189hippi_setup);190}191192EXPORT_SYMBOL(alloc_hippi_dev);193194195