enet.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2012-2014, 2017, 2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef _ENET__H_
  27. #define _ENET__H_
  28. #if defined(ATH_TARGET)
  29. #include <osapi.h> /* A_UINT8 */
  30. #else
  31. #include <a_types.h> /* A_UINT8 */
  32. #endif
  33. #define ETHERNET_ADDR_LEN 6 /* bytes */
  34. #define ETHERNET_TYPE_LEN 2 /* bytes - length of the Ethernet type field */
  35. struct ethernet_hdr_t {
  36. A_UINT8 dest_addr[ETHERNET_ADDR_LEN];
  37. A_UINT8 src_addr[ETHERNET_ADDR_LEN];
  38. A_UINT8 ethertype[ETHERNET_TYPE_LEN];
  39. };
  40. #define ETHERNET_HDR_LEN (sizeof(struct ethernet_hdr_t))
  41. #define ETHERNET_CRC_LEN 4 /* bytes - length of the Ethernet CRC */
  42. #define ETHERNET_MAX_LEN 1518 /* bytes */
  43. #define ETHERNET_MTU (ETHERNET_MAX_LEN - (ETHERNET_HDR_LEN + ETHERNET_CRC_LEN))
  44. typedef struct llc_snap_hdr_t {
  45. A_UINT8 dsap;
  46. A_UINT8 ssap;
  47. A_UINT8 cntl;
  48. A_UINT8 org_code[3];
  49. A_UINT8 ethertype[2];
  50. } LLC_SNAP_HDR;
  51. #define LLC_SNAP_HDR_LEN (sizeof(struct llc_snap_hdr_t))
  52. #define LLC_SNAP_HDR_OFFSET_ETHERTYPE \
  53. (offsetof(struct llc_snap_hdr_t, ethertype[0]))
  54. #define ETHERTYPE_VLAN_LEN 4
  55. struct ethernet_vlan_hdr_t {
  56. A_UINT8 dest_addr[ETHERNET_ADDR_LEN];
  57. A_UINT8 src_addr[ETHERNET_ADDR_LEN];
  58. A_UINT8 vlan_tpid[2];
  59. A_UINT8 vlan_tci[2];
  60. A_UINT8 ethertype[2];
  61. };
  62. typedef PREPACK struct _wai_hdr {
  63. A_UINT8 version[2];
  64. A_UINT8 type;
  65. A_UINT8 stype;
  66. A_UINT8 reserve[2];
  67. A_UINT8 length[2];
  68. A_UINT8 rxseq[2];
  69. A_UINT8 frag_sc;
  70. A_UINT8 more_frag;
  71. /* followed octets of data */
  72. } POSTPACK wai_hdr;
  73. typedef PREPACK struct {
  74. A_UINT16 vlan_tci;
  75. A_UINT16 vlan_encap_p;
  76. } POSTPACK vlan_hdr_t;
  77. #define ETHERTYPE_IS_EAPOL_WAPI(typeorlen) \
  78. ((typeorlen) == ETHERTYPE_PAE || \
  79. (typeorlen) == ETHERTYPE_WAI)
  80. #define IS_ETHERTYPE(_typeOrLen) ((_typeOrLen) >= 0x0600)
  81. #ifndef ETHERTYPE_IPV4
  82. #define ETHERTYPE_IPV4 0x0800 /* Internet Protocol, Version 4 (IPv4) */
  83. #endif
  84. #ifndef ETHERTYPE_AARP
  85. #define ETHERTYPE_AARP 0x80f3 /* Internal QCA AARP protocol */
  86. #endif
  87. #ifndef ETHERTYPE_IPX
  88. #define ETHERTYPE_IPX 0x8137 /* IPX over DIX protocol */
  89. #endif
  90. #ifndef ETHERTYPE_ARP
  91. #define ETHERTYPE_ARP 0x0806 /* Address Resolution Protocol (ARP) */
  92. #endif
  93. #ifndef ETHERTYPE_RARP
  94. #define ETHERTYPE_RARP 0x8035 /* Reverse Address Resolution Protocol (RARP) */
  95. #endif
  96. #ifndef ETHERTYPE_VLAN
  97. #define ETHERTYPE_VLAN 0x8100 /* VLAN TAG protocol */
  98. #endif
  99. #ifndef ETHERTYPE_SNMP
  100. #define ETHERTYPE_SNMP 0x814C /* Simple Network Management Protocol (SNMP) */
  101. #endif
  102. #ifndef ETHERTYPE_IPV6
  103. #define ETHERTYPE_IPV6 0x86DD /* Internet Protocol, Version 6 (IPv6) */
  104. #endif
  105. #ifndef ETHERTYPE_PAE
  106. #define ETHERTYPE_PAE 0x888E /* EAP over LAN (EAPOL) */
  107. #endif
  108. #ifndef ETHERTYPE_WAI
  109. #define ETHERTYPE_WAI 0x88B4 /* WAPI */
  110. #endif
  111. #ifndef ETHERTYPE_TDLS
  112. #define ETHERTYPE_TDLS 0x890D /* TDLS */
  113. #endif
  114. #define LLC_SNAP_LSAP 0xaa
  115. #define LLC_UI 0x3
  116. #define RFC1042_SNAP_ORGCODE_0 0x00
  117. #define RFC1042_SNAP_ORGCODE_1 0x00
  118. #define RFC1042_SNAP_ORGCODE_2 0x00
  119. #define BTEP_SNAP_ORGCODE_0 0x00
  120. #define BTEP_SNAP_ORGCODE_1 0x00
  121. #define BTEP_SNAP_ORGCODE_2 0xf8
  122. #define WAI_FRAME_TYPE 0X01
  123. #define WAPI_M4_TYPE 0x0c
  124. #define WAPI_M2_TYPE 0x09
  125. #define ICMP_PROTOCOL 1
  126. #define TCP_PROTOCOL 6
  127. #define UDP_PROTOCOL 17
  128. #define IGMP_PROTOCOL 2
  129. #define ICMPV6_PROTOCOL 58
  130. #define BOOTP_SERVER_PORT 67
  131. #define BOOTP_CLIENT_PORT 68
  132. #define MLD_QUERY 130
  133. #define MLD_DONE 132
  134. #define IS_EAPOL(typeorlen) \
  135. ((typeorlen) == ETHERTYPE_PAE || \
  136. (typeorlen) == ETHERTYPE_WAI)
  137. #define IS_SNAP(_llc) \
  138. ((_llc)->dsap == LLC_SNAP_LSAP && \
  139. (_llc)->ssap == LLC_SNAP_LSAP && \
  140. (_llc)->cntl == LLC_UI)
  141. #define IS_RFC1042(_llc) \
  142. ((_llc)->org_code[0] == RFC1042_SNAP_ORGCODE_0 && \
  143. (_llc)->org_code[1] == RFC1042_SNAP_ORGCODE_1 && \
  144. (_llc)->org_code[2] == RFC1042_SNAP_ORGCODE_2)
  145. #define IS_BTEP(_llc) \
  146. ((_llc)->org_code[0] == BTEP_SNAP_ORGCODE_0 && \
  147. (_llc)->org_code[1] == BTEP_SNAP_ORGCODE_1 && \
  148. (_llc)->org_code[2] == BTEP_SNAP_ORGCODE_2)
  149. #define IS_MULTICAST(_hdr) (*(A_UINT8 *)(_hdr) & 0x1)
  150. #define IS_BROADCAST(_hdr) \
  151. ((*((A_UINT8 *)(_hdr) + 0) == 0xff) && \
  152. (*((A_UINT8 *)(_hdr) + 1) == 0xff) && \
  153. (*((A_UINT8 *)(_hdr) + 2) == 0xff) && \
  154. (*((A_UINT8 *)(_hdr) + 3) == 0xff) && \
  155. (*((A_UINT8 *)(_hdr) + 4) == 0xff) && \
  156. (*((A_UINT8 *)(_hdr) + 5) == 0xff))
  157. #endif /* _ENET__H_ */