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