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