hippi.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #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>
  38. /*
  39. * Create the HIPPI MAC header for an arbitrary protocol layer
  40. *
  41. * saddr=NULL means use device source address
  42. * daddr=NULL means leave destination address (eg unresolved arp)
  43. */
  44. static int hippi_header(struct sk_buff *skb, struct net_device *dev,
  45. unsigned short type, void *daddr, void *saddr,
  46. unsigned len)
  47. {
  48. struct hippi_hdr *hip = (struct hippi_hdr *)skb_push(skb, HIPPI_HLEN);
  49. struct hippi_cb *hcb = (struct hippi_cb *) skb->cb;
  50. if (!len){
  51. len = skb->len - HIPPI_HLEN;
  52. printk("hippi_header(): length not supplied\n");
  53. }
  54. /*
  55. * Due to the stupidity of the little endian byte-order we
  56. * have to set the fp field this way.
  57. */
  58. hip->fp.fixed = __constant_htonl(0x04800018);
  59. hip->fp.d2_size = htonl(len + 8);
  60. hip->le.fc = 0;
  61. hip->le.double_wide = 0; /* only HIPPI 800 for the time being */
  62. hip->le.message_type = 0; /* Data PDU */
  63. hip->le.dest_addr_type = 2; /* 12 bit SC address */
  64. hip->le.src_addr_type = 2; /* 12 bit SC address */
  65. memcpy(hip->le.src_switch_addr, dev->dev_addr + 3, 3);
  66. memset(&hip->le.reserved, 0, 16);
  67. hip->snap.dsap = HIPPI_EXTENDED_SAP;
  68. hip->snap.ssap = HIPPI_EXTENDED_SAP;
  69. hip->snap.ctrl = HIPPI_UI_CMD;
  70. hip->snap.oui[0] = 0x00;
  71. hip->snap.oui[1] = 0x00;
  72. hip->snap.oui[2] = 0x00;
  73. hip->snap.ethertype = htons(type);
  74. if (daddr)
  75. {
  76. memcpy(hip->le.dest_switch_addr, daddr + 3, 3);
  77. memcpy(&hcb->ifield, daddr + 2, 4);
  78. return HIPPI_HLEN;
  79. }
  80. hcb->ifield = 0;
  81. return -((int)HIPPI_HLEN);
  82. }
  83. /*
  84. * Rebuild the HIPPI MAC header. This is called after an ARP has
  85. * completed on this sk_buff. We now let ARP fill in the other fields.
  86. */
  87. static int hippi_rebuild_header(struct sk_buff *skb)
  88. {
  89. struct hippi_hdr *hip = (struct hippi_hdr *)skb->data;
  90. /*
  91. * Only IP is currently supported
  92. */
  93. if(hip->snap.ethertype != __constant_htons(ETH_P_IP))
  94. {
  95. printk(KERN_DEBUG "%s: unable to resolve type %X addresses.\n",skb->dev->name,ntohs(hip->snap.ethertype));
  96. return 0;
  97. }
  98. /*
  99. * We don't support dynamic ARP on HIPPI, but we use the ARP
  100. * static ARP tables to hold the I-FIELDs.
  101. */
  102. return arp_find(hip->le.daddr, skb);
  103. }
  104. /*
  105. * Determine the packet's protocol ID.
  106. */
  107. __be16 hippi_type_trans(struct sk_buff *skb, struct net_device *dev)
  108. {
  109. struct hippi_hdr *hip;
  110. hip = (struct hippi_hdr *) skb->data;
  111. /*
  112. * This is actually wrong ... question is if we really should
  113. * set the raw address here.
  114. */
  115. skb->mac.raw = skb->data;
  116. skb_pull(skb, HIPPI_HLEN);
  117. /*
  118. * No fancy promisc stuff here now.
  119. */
  120. return hip->snap.ethertype;
  121. }
  122. EXPORT_SYMBOL(hippi_type_trans);
  123. static int hippi_change_mtu(struct net_device *dev, int new_mtu)
  124. {
  125. /*
  126. * HIPPI's got these nice large MTUs.
  127. */
  128. if ((new_mtu < 68) || (new_mtu > 65280))
  129. return -EINVAL;
  130. dev->mtu = new_mtu;
  131. return(0);
  132. }
  133. /*
  134. * For HIPPI we will actually use the lower 4 bytes of the hardware
  135. * address as the I-FIELD rather than the actual hardware address.
  136. */
  137. static int hippi_mac_addr(struct net_device *dev, void *p)
  138. {
  139. struct sockaddr *addr = p;
  140. if (netif_running(dev))
  141. return -EBUSY;
  142. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  143. return 0;
  144. }
  145. static int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
  146. {
  147. /* Never send broadcast/multicast ARP messages */
  148. p->mcast_probes = 0;
  149. /* In IPv6 unicast probes are valid even on NBMA,
  150. * because they are encapsulated in normal IPv6 protocol.
  151. * Should be a generic flag.
  152. */
  153. if (p->tbl->family != AF_INET6)
  154. p->ucast_probes = 0;
  155. return 0;
  156. }
  157. static void hippi_setup(struct net_device *dev)
  158. {
  159. dev->set_multicast_list = NULL;
  160. dev->change_mtu = hippi_change_mtu;
  161. dev->hard_header = hippi_header;
  162. dev->rebuild_header = hippi_rebuild_header;
  163. dev->set_mac_address = hippi_mac_addr;
  164. dev->hard_header_parse = NULL;
  165. dev->hard_header_cache = NULL;
  166. dev->header_cache_update = NULL;
  167. dev->neigh_setup = hippi_neigh_setup_dev;
  168. /*
  169. * We don't support HIPPI `ARP' for the time being, and probably
  170. * never will unless someone else implements it. However we
  171. * still need a fake ARPHRD to make ifconfig and friends play ball.
  172. */
  173. dev->type = ARPHRD_HIPPI;
  174. dev->hard_header_len = HIPPI_HLEN;
  175. dev->mtu = 65280;
  176. dev->addr_len = HIPPI_ALEN;
  177. dev->tx_queue_len = 25 /* 5 */;
  178. memset(dev->broadcast, 0xFF, HIPPI_ALEN);
  179. /*
  180. * HIPPI doesn't support broadcast+multicast and we only use
  181. * static ARP tables. ARP is disabled by hippi_neigh_setup_dev.
  182. */
  183. dev->flags = 0;
  184. }
  185. /**
  186. * alloc_hippi_dev - Register HIPPI device
  187. * @sizeof_priv: Size of additional driver-private structure to be allocated
  188. * for this HIPPI device
  189. *
  190. * Fill in the fields of the device structure with HIPPI-generic values.
  191. *
  192. * Constructs a new net device, complete with a private data area of
  193. * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
  194. * this private data area.
  195. */
  196. struct net_device *alloc_hippi_dev(int sizeof_priv)
  197. {
  198. return alloc_netdev(sizeof_priv, "hip%d", hippi_setup);
  199. }
  200. EXPORT_SYMBOL(alloc_hippi_dev);