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