hippi.c 4.9 KB

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