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