| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * INET		An implementation of the TCP/IP protocol suite for the LINUX | 
|  | 3 | *		operating system.  INET is implemented using the  BSD Socket | 
|  | 4 | *		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/97 | 
|  | 9 | * | 
|  | 10 | * Authors:	Ross Biro | 
|  | 11 | *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 
|  | 12 | *		Mark Evans, <evansmp@uhura.aston.ac.uk> | 
|  | 13 | *		Florian  La Roche, <rzsfl@rz.uni-sb.de> | 
|  | 14 | *		Alan Cox, <gw4pts@gw4pts.ampr.org> | 
|  | 15 | *		Jes Sorensen, <Jes.Sorensen@cern.ch> | 
|  | 16 | * | 
|  | 17 | *		This program is free software; you can redistribute it and/or | 
|  | 18 | *		modify it under the terms of the GNU General Public License | 
|  | 19 | *		as published by the Free Software Foundation; either version | 
|  | 20 | *		2 of the License, or (at your option) any later version. | 
|  | 21 | */ | 
|  | 22 |  | 
|  | 23 | #include <linux/module.h> | 
|  | 24 | #include <linux/types.h> | 
|  | 25 | #include <linux/kernel.h> | 
|  | 26 | #include <linux/string.h> | 
|  | 27 | #include <linux/mm.h> | 
|  | 28 | #include <linux/socket.h> | 
|  | 29 | #include <linux/in.h> | 
|  | 30 | #include <linux/inet.h> | 
|  | 31 | #include <linux/netdevice.h> | 
|  | 32 | #include <linux/hippidevice.h> | 
|  | 33 | #include <linux/skbuff.h> | 
|  | 34 | #include <linux/errno.h> | 
|  | 35 | #include <net/arp.h> | 
|  | 36 | #include <net/sock.h> | 
|  | 37 | #include <linux/uaccess.h> | 
|  | 38 |  | 
|  | 39 | /* | 
|  | 40 | * Create the HIPPI MAC header for an arbitrary protocol layer | 
|  | 41 | * | 
|  | 42 | * saddr=NULL	means use device source address | 
|  | 43 | * daddr=NULL	means leave destination address (eg unresolved arp) | 
|  | 44 | */ | 
|  | 45 |  | 
|  | 46 | static int hippi_header(struct sk_buff *skb, struct net_device *dev, | 
|  | 47 | unsigned short type, | 
|  | 48 | const void *daddr, const void *saddr, unsigned int len) | 
|  | 49 | { | 
|  | 50 | struct hippi_hdr *hip = skb_push(skb, HIPPI_HLEN); | 
|  | 51 | struct hippi_cb *hcb = (struct hippi_cb *) skb->cb; | 
|  | 52 |  | 
|  | 53 | if (!len){ | 
|  | 54 | len = skb->len - HIPPI_HLEN; | 
|  | 55 | printk("hippi_header(): length not supplied\n"); | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | /* | 
|  | 59 | * Due to the stupidity of the little endian byte-order we | 
|  | 60 | * have to set the fp field this way. | 
|  | 61 | */ | 
|  | 62 | hip->fp.fixed		= htonl(0x04800018); | 
|  | 63 | hip->fp.d2_size		= htonl(len + 8); | 
|  | 64 | hip->le.fc		= 0; | 
|  | 65 | hip->le.double_wide	= 0;	/* only HIPPI 800 for the time being */ | 
|  | 66 | hip->le.message_type	= 0;	/* Data PDU */ | 
|  | 67 |  | 
|  | 68 | hip->le.dest_addr_type	= 2;	/* 12 bit SC address */ | 
|  | 69 | hip->le.src_addr_type	= 2;	/* 12 bit SC address */ | 
|  | 70 |  | 
|  | 71 | memcpy(hip->le.src_switch_addr, dev->dev_addr + 3, 3); | 
|  | 72 | memset(&hip->le.reserved, 0, 16); | 
|  | 73 |  | 
|  | 74 | hip->snap.dsap		= HIPPI_EXTENDED_SAP; | 
|  | 75 | hip->snap.ssap		= HIPPI_EXTENDED_SAP; | 
|  | 76 | hip->snap.ctrl		= HIPPI_UI_CMD; | 
|  | 77 | hip->snap.oui[0]	= 0x00; | 
|  | 78 | hip->snap.oui[1]	= 0x00; | 
|  | 79 | hip->snap.oui[2]	= 0x00; | 
|  | 80 | hip->snap.ethertype	= htons(type); | 
|  | 81 |  | 
|  | 82 | if (daddr) | 
|  | 83 | { | 
|  | 84 | memcpy(hip->le.dest_switch_addr, daddr + 3, 3); | 
|  | 85 | memcpy(&hcb->ifield, daddr + 2, 4); | 
|  | 86 | return HIPPI_HLEN; | 
|  | 87 | } | 
|  | 88 | hcb->ifield = 0; | 
|  | 89 | return -((int)HIPPI_HLEN); | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 |  | 
|  | 93 | /* | 
|  | 94 | *	Determine the packet's protocol ID. | 
|  | 95 | */ | 
|  | 96 |  | 
|  | 97 | __be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev) | 
|  | 98 | { | 
|  | 99 | struct hippi_hdr *hip; | 
|  | 100 |  | 
|  | 101 | /* | 
|  | 102 | * This is actually wrong ... question is if we really should | 
|  | 103 | * set the raw address here. | 
|  | 104 | */ | 
|  | 105 | skb->dev = dev; | 
|  | 106 | skb_reset_mac_header(skb); | 
|  | 107 | hip = (struct hippi_hdr *)skb_mac_header(skb); | 
|  | 108 | skb_pull(skb, HIPPI_HLEN); | 
|  | 109 |  | 
|  | 110 | /* | 
|  | 111 | * No fancy promisc stuff here now. | 
|  | 112 | */ | 
|  | 113 |  | 
|  | 114 | return hip->snap.ethertype; | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | EXPORT_SYMBOL(hippi_type_trans); | 
|  | 118 |  | 
|  | 119 | /* | 
|  | 120 | * For HIPPI we will actually use the lower 4 bytes of the hardware | 
|  | 121 | * address as the I-FIELD rather than the actual hardware address. | 
|  | 122 | */ | 
|  | 123 | int hippi_mac_addr(struct net_device *dev, void *p) | 
|  | 124 | { | 
|  | 125 | struct sockaddr *addr = p; | 
|  | 126 | if (netif_running(dev)) | 
|  | 127 | return -EBUSY; | 
|  | 128 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); | 
|  | 129 | return 0; | 
|  | 130 | } | 
|  | 131 | EXPORT_SYMBOL(hippi_mac_addr); | 
|  | 132 |  | 
|  | 133 | int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p) | 
|  | 134 | { | 
|  | 135 | /* Never send broadcast/multicast ARP messages */ | 
|  | 136 | NEIGH_VAR_INIT(p, MCAST_PROBES, 0); | 
|  | 137 |  | 
|  | 138 | /* In IPv6 unicast probes are valid even on NBMA, | 
|  | 139 | * because they are encapsulated in normal IPv6 protocol. | 
|  | 140 | * Should be a generic flag. | 
|  | 141 | */ | 
|  | 142 | if (p->tbl->family != AF_INET6) | 
|  | 143 | NEIGH_VAR_INIT(p, UCAST_PROBES, 0); | 
|  | 144 | return 0; | 
|  | 145 | } | 
|  | 146 | EXPORT_SYMBOL(hippi_neigh_setup_dev); | 
|  | 147 |  | 
|  | 148 | static const struct header_ops hippi_header_ops = { | 
|  | 149 | .create		= hippi_header, | 
|  | 150 | }; | 
|  | 151 |  | 
|  | 152 |  | 
|  | 153 | static void hippi_setup(struct net_device *dev) | 
|  | 154 | { | 
|  | 155 | dev->header_ops			= &hippi_header_ops; | 
|  | 156 |  | 
|  | 157 | /* | 
|  | 158 | * We don't support HIPPI `ARP' for the time being, and probably | 
|  | 159 | * never will unless someone else implements it. However we | 
|  | 160 | * still need a fake ARPHRD to make ifconfig and friends play ball. | 
|  | 161 | */ | 
|  | 162 | dev->type		= ARPHRD_HIPPI; | 
|  | 163 | dev->hard_header_len 	= HIPPI_HLEN; | 
|  | 164 | dev->mtu		= 65280; | 
|  | 165 | dev->min_mtu		= 68; | 
|  | 166 | dev->max_mtu		= 65280; | 
|  | 167 | dev->addr_len		= HIPPI_ALEN; | 
|  | 168 | dev->tx_queue_len	= 25 /* 5 */; | 
|  | 169 | memset(dev->broadcast, 0xFF, HIPPI_ALEN); | 
|  | 170 |  | 
|  | 171 |  | 
|  | 172 | /* | 
|  | 173 | * HIPPI doesn't support broadcast+multicast and we only use | 
|  | 174 | * static ARP tables. ARP is disabled by hippi_neigh_setup_dev. | 
|  | 175 | */ | 
|  | 176 | dev->flags = 0; | 
|  | 177 | } | 
|  | 178 |  | 
|  | 179 | /** | 
|  | 180 | * alloc_hippi_dev - Register HIPPI device | 
|  | 181 | * @sizeof_priv: Size of additional driver-private structure to be allocated | 
|  | 182 | *	for this HIPPI device | 
|  | 183 | * | 
|  | 184 | * Fill in the fields of the device structure with HIPPI-generic values. | 
|  | 185 | * | 
|  | 186 | * Constructs a new net device, complete with a private data area of | 
|  | 187 | * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for | 
|  | 188 | * this private data area. | 
|  | 189 | */ | 
|  | 190 |  | 
|  | 191 | struct net_device *alloc_hippi_dev(int sizeof_priv) | 
|  | 192 | { | 
|  | 193 | return alloc_netdev(sizeof_priv, "hip%d", NET_NAME_UNKNOWN, | 
|  | 194 | hippi_setup); | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | EXPORT_SYMBOL(alloc_hippi_dev); |