ethernet.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
  3. *
  4. * Copyright 2006, Broadcom Corporation
  5. * All Rights Reserved.
  6. *
  7. * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
  8. * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
  9. * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
  10. * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
  11. *
  12. */
  13. #ifndef __NET_ETHERNET_H
  14. #define __NET_ETHERNET_H
  15. #ifndef _TYPEDEFS_H_
  16. #include "typedefs.h"
  17. #endif
  18. /* enable structure packing */
  19. #if defined(__GNUC__)
  20. #define PACKED __attribute__((packed))
  21. #else
  22. #pragma pack(1)
  23. #define PACKED
  24. #endif
  25. /*
  26. * The number of bytes in an ethernet (MAC) address.
  27. */
  28. #define ETHER_ADDR_LEN 6
  29. /*
  30. * The number of bytes in the type field.
  31. */
  32. #define ETHER_TYPE_LEN 2
  33. /*
  34. * The number of bytes in the trailing CRC field.
  35. */
  36. #define ETHER_CRC_LEN 4
  37. /*
  38. * The length of the combined header.
  39. */
  40. #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
  41. /*
  42. * The minimum packet length.
  43. */
  44. #define ETHER_MIN_LEN 64
  45. /*
  46. * The minimum packet user data length.
  47. */
  48. #define ETHER_MIN_DATA 46
  49. /*
  50. * The maximum packet length.
  51. */
  52. #define ETHER_MAX_LEN 1518
  53. /*
  54. * The maximum packet user data length.
  55. */
  56. #define ETHER_MAX_DATA 1500
  57. /* ether types */
  58. #define ETHER_TYPE_IP 0x0800 /* IP */
  59. #define ETHER_TYPE_ARP 0x0806 /* ARP */
  60. #define ETHER_TYPE_8021Q 0x8100 /* 802.1Q */
  61. #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */
  62. #define ETHER_TYPE_802_1X 0x888e /* 802.1x */
  63. #ifdef BCMWPA2
  64. #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 /* 802.1x preauthentication */
  65. #endif
  66. /* Broadcom subtype follows ethertype; First 2 bytes are reserved; Next 2 are subtype; */
  67. #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4 byte subtype */
  68. #define ETHER_BRCM_CRAM 0x1 /* Broadcom subtype cram protocol */
  69. /* ether header */
  70. #define ETHER_DEST_OFFSET 0 /* dest address offset */
  71. #define ETHER_SRC_OFFSET 6 /* src address offset */
  72. #define ETHER_TYPE_OFFSET 12 /* ether type offset */
  73. /*
  74. * A macro to validate a length with
  75. */
  76. #define ETHER_IS_VALID_LEN(foo) \
  77. ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
  78. #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
  79. /*
  80. * Structure of a 10Mb/s Ethernet header.
  81. */
  82. struct ether_header {
  83. uint8 ether_dhost[ETHER_ADDR_LEN];
  84. uint8 ether_shost[ETHER_ADDR_LEN];
  85. uint16 ether_type;
  86. } PACKED;
  87. /*
  88. * Structure of a 48-bit Ethernet address.
  89. */
  90. struct ether_addr {
  91. uint8 octet[ETHER_ADDR_LEN];
  92. } PACKED;
  93. #endif /* !__INCif_etherh Quick and ugly hack for VxWorks */
  94. /*
  95. * Takes a pointer, sets locally admininistered
  96. * address bit in the 48-bit Ethernet address.
  97. */
  98. #define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
  99. /*
  100. * Takes a pointer, returns true if a 48-bit multicast address
  101. * (including broadcast, since it is all ones)
  102. */
  103. #define ETHER_ISMULTI(ea) (((uint8 *)(ea))[0] & 1)
  104. /* compare two ethernet addresses - assumes the pointers can be referenced as shorts */
  105. #define ether_cmp(a, b) (!(((short*)a)[0] == ((short*)b)[0]) | \
  106. !(((short*)a)[1] == ((short*)b)[1]) | \
  107. !(((short*)a)[2] == ((short*)b)[2]))
  108. /* copy an ethernet address - assumes the pointers can be referenced as shorts */
  109. #define ether_copy(s, d) { \
  110. ((short*)d)[0] = ((short*)s)[0]; \
  111. ((short*)d)[1] = ((short*)s)[1]; \
  112. ((short*)d)[2] = ((short*)s)[2]; }
  113. /*
  114. * Takes a pointer, returns true if a 48-bit broadcast (all ones)
  115. */
  116. #define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \
  117. ((uint8 *)(ea))[1] & \
  118. ((uint8 *)(ea))[2] & \
  119. ((uint8 *)(ea))[3] & \
  120. ((uint8 *)(ea))[4] & \
  121. ((uint8 *)(ea))[5]) == 0xff)
  122. static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
  123. /*
  124. * Takes a pointer, returns true if a 48-bit null address (all zeros)
  125. */
  126. #define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \
  127. ((uint8 *)(ea))[1] | \
  128. ((uint8 *)(ea))[2] | \
  129. ((uint8 *)(ea))[3] | \
  130. ((uint8 *)(ea))[4] | \
  131. ((uint8 *)(ea))[5]) == 0)
  132. #undef PACKED
  133. #if !defined(__GNUC__)
  134. #pragma pack()
  135. #endif
  136. #endif /* __NET_ETHERNET_H */