bcmipv6.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Fundamental constants relating to Neighbor Discovery Protocol
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: bcmipv6.h 681862 2018-01-03 12:34:14Z $
  30. */
  31. #ifndef _bcmipv6_h_
  32. #define _bcmipv6_h_
  33. #ifndef _TYPEDEFS_H_
  34. #include <typedefs.h>
  35. #endif // endif
  36. /* This marks the start of a packed structure section. */
  37. #include <packed_section_start.h>
  38. /* Extension headers */
  39. #define IPV6_EXT_HOP 0
  40. #define IPV6_EXT_ROUTE 43
  41. #define IPV6_EXT_FRAG 44
  42. #define IPV6_EXT_DEST 60
  43. #define IPV6_EXT_ESEC 50
  44. #define IPV6_EXT_AUTH 51
  45. /* Minimum size (extension header "word" length) */
  46. #define IPV6_EXT_WORD 8
  47. /* Offsets for most extension headers */
  48. #define IPV6_EXT_NEXTHDR 0
  49. #define IPV6_EXT_HDRLEN 1
  50. /* Constants specific to fragmentation header */
  51. #define IPV6_FRAG_MORE_MASK 0x0001
  52. #define IPV6_FRAG_MORE_SHIFT 0
  53. #define IPV6_FRAG_OFFS_MASK 0xfff8
  54. #define IPV6_FRAG_OFFS_SHIFT 3
  55. /* For icmpv6 */
  56. #define ICMPV6_HEADER_TYPE 0x3A
  57. #define ICMPV6_PKT_TYPE_RA 134
  58. #define ICMPV6_PKT_TYPE_NS 135
  59. #define ICMPV6_PKT_TYPE_NA 136
  60. #define ICMPV6_ND_OPT_TYPE_TARGET_MAC 2
  61. #define ICMPV6_ND_OPT_TYPE_SRC_MAC 1
  62. #define ICMPV6_ND_OPT_LEN_LINKADDR 1
  63. #define ICMPV6_ND_OPT_LEN_LINKADDR 1
  64. #define IPV6_VERSION 6
  65. #define IPV6_HOP_LIMIT 255
  66. #define IPV6_ADDR_NULL(a) ((a[0] | a[1] | a[2] | a[3] | a[4] | \
  67. a[5] | a[6] | a[7] | a[8] | a[9] | \
  68. a[10] | a[11] | a[12] | a[13] | \
  69. a[14] | a[15]) == 0)
  70. #define IPV6_ADDR_LOCAL(a) (((a[0] == 0xfe) && (a[1] & 0x80))? TRUE: FALSE)
  71. /* IPV6 address */
  72. BWL_PRE_PACKED_STRUCT struct ipv6_addr {
  73. uint8 addr[16];
  74. } BWL_POST_PACKED_STRUCT;
  75. /* ICMPV6 Header */
  76. BWL_PRE_PACKED_STRUCT struct icmp6_hdr {
  77. uint8 icmp6_type;
  78. uint8 icmp6_code;
  79. uint16 icmp6_cksum;
  80. BWL_PRE_PACKED_STRUCT union {
  81. uint32 reserved;
  82. BWL_PRE_PACKED_STRUCT struct nd_advt {
  83. uint32 reserved1:5,
  84. override:1,
  85. solicited:1,
  86. router:1,
  87. reserved2:24;
  88. } BWL_POST_PACKED_STRUCT nd_advt;
  89. } BWL_POST_PACKED_STRUCT opt;
  90. } BWL_POST_PACKED_STRUCT;
  91. /* Ipv6 Header Format */
  92. BWL_PRE_PACKED_STRUCT struct ipv6_hdr {
  93. uint8 priority:4,
  94. version:4;
  95. uint8 flow_lbl[3];
  96. uint16 payload_len;
  97. uint8 nexthdr;
  98. uint8 hop_limit;
  99. struct ipv6_addr saddr;
  100. struct ipv6_addr daddr;
  101. } BWL_POST_PACKED_STRUCT;
  102. /* Neighbor Advertisement/Solicitation Packet Structure */
  103. BWL_PRE_PACKED_STRUCT struct bcm_nd_msg {
  104. struct icmp6_hdr icmph;
  105. struct ipv6_addr target;
  106. } BWL_POST_PACKED_STRUCT;
  107. /* Neighibor Solicitation/Advertisement Optional Structure */
  108. BWL_PRE_PACKED_STRUCT struct nd_msg_opt {
  109. uint8 type;
  110. uint8 len;
  111. uint8 mac_addr[ETHER_ADDR_LEN];
  112. } BWL_POST_PACKED_STRUCT;
  113. /* Ipv6 Fragmentation Header */
  114. BWL_PRE_PACKED_STRUCT struct ipv6_frag {
  115. uint8 nexthdr;
  116. uint8 reserved;
  117. uint16 frag_offset;
  118. uint32 ident;
  119. } BWL_POST_PACKED_STRUCT;
  120. /* This marks the end of a packed structure section. */
  121. #include <packed_section_end.h>
  122. static const struct ipv6_addr all_node_ipv6_maddr = {
  123. { 0xff, 0x2, 0, 0,
  124. 0, 0, 0, 0,
  125. 0, 0, 0, 0,
  126. 0, 0, 0, 1
  127. }};
  128. #define IPV6_ISMULTI(a) (a[0] == 0xff)
  129. #define IPV6_MCAST_TO_ETHER_MCAST(ipv6, ether) \
  130. { \
  131. ether[0] = 0x33; \
  132. ether[1] = 0x33; \
  133. ether[2] = ipv6[12]; \
  134. ether[3] = ipv6[13]; \
  135. ether[4] = ipv6[14]; \
  136. ether[5] = ipv6[15]; \
  137. }
  138. #endif /* !defined(_bcmipv6_h_) */