xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/infineon/bcmdhd/include/bcmipv6.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Fundamental constants relating to Neighbor Discovery Protocol
3  *
4  * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, 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$
30  */
31 
32 #ifndef _bcmipv6_h_
33 #define _bcmipv6_h_
34 
35 #ifndef _TYPEDEFS_H_
36 #include <typedefs.h>
37 #endif // endif
38 
39 /* This marks the start of a packed structure section. */
40 #include <packed_section_start.h>
41 
42 /* Extension headers */
43 #define IPV6_EXT_HOP	0
44 #define IPV6_EXT_ROUTE	43
45 #define IPV6_EXT_FRAG	44
46 #define IPV6_EXT_DEST	60
47 #define IPV6_EXT_ESEC	50
48 #define IPV6_EXT_AUTH	51
49 
50 /* Minimum size (extension header "word" length) */
51 #define IPV6_EXT_WORD	8
52 
53 /* Offsets for most extension headers */
54 #define IPV6_EXT_NEXTHDR	0
55 #define IPV6_EXT_HDRLEN		1
56 
57 /* Constants specific to fragmentation header */
58 #define IPV6_FRAG_MORE_MASK	0x0001
59 #define IPV6_FRAG_MORE_SHIFT	0
60 #define IPV6_FRAG_OFFS_MASK	0xfff8
61 #define IPV6_FRAG_OFFS_SHIFT	3
62 
63 /* For icmpv6 */
64 #define ICMPV6_HEADER_TYPE	0x3A
65 #define ICMPV6_PKT_TYPE_RA	134
66 #define ICMPV6_PKT_TYPE_NS	135
67 #define ICMPV6_PKT_TYPE_NA	136
68 
69 #define ICMPV6_ND_OPT_TYPE_TARGET_MAC	2
70 #define ICMPV6_ND_OPT_TYPE_SRC_MAC		1
71 
72 #define ICMPV6_ND_OPT_LEN_LINKADDR		1
73 
74 #define ICMPV6_ND_OPT_LEN_LINKADDR		1
75 
76 #define IPV6_VERSION 	6
77 #define IPV6_HOP_LIMIT 	255
78 
79 #define IPV6_ADDR_NULL(a)	((a[0] | a[1] | a[2] | a[3] | a[4] | \
80 							 a[5] | a[6] | a[7] | a[8] | a[9] | \
81 							 a[10] | a[11] | a[12] | a[13] | \
82 							 a[14] | a[15]) == 0)
83 
84 #define IPV6_ADDR_LOCAL(a)	(((a[0] == 0xfe) && (a[1] & 0x80))? TRUE: FALSE)
85 
86 /* IPV6 address */
87 BWL_PRE_PACKED_STRUCT struct ipv6_addr {
88 		uint8		addr[16];
89 } BWL_POST_PACKED_STRUCT;
90 
91 /* ICMPV6 Header */
92 BWL_PRE_PACKED_STRUCT struct icmp6_hdr {
93 	uint8	icmp6_type;
94 	uint8	icmp6_code;
95 	uint16	icmp6_cksum;
96 	BWL_PRE_PACKED_STRUCT union {
97 		uint32 reserved;
98 		BWL_PRE_PACKED_STRUCT struct nd_advt {
99 			uint32	reserved1:5,
100 				override:1,
101 				solicited:1,
102 				router:1,
103 				reserved2:24;
104 		} BWL_POST_PACKED_STRUCT nd_advt;
105 	} BWL_POST_PACKED_STRUCT opt;
106 } BWL_POST_PACKED_STRUCT;
107 
108 /* Ipv6 Header Format */
109 BWL_PRE_PACKED_STRUCT struct ipv6_hdr {
110 	uint8	priority:4,
111 		version:4;
112 	uint8	flow_lbl[3];
113 	uint16	payload_len;
114 	uint8	nexthdr;
115 	uint8 	hop_limit;
116 	struct	ipv6_addr	saddr;
117 	struct	ipv6_addr	daddr;
118 } BWL_POST_PACKED_STRUCT;
119 
120 /* Neighbor Advertisement/Solicitation Packet Structure */
121 BWL_PRE_PACKED_STRUCT struct bcm_nd_msg {
122 	struct	icmp6_hdr	icmph;
123 	struct	ipv6_addr	target;
124 } BWL_POST_PACKED_STRUCT;
125 
126 /* Neighibor Solicitation/Advertisement Optional Structure */
127 BWL_PRE_PACKED_STRUCT struct nd_msg_opt {
128 	uint8 type;
129 	uint8 len;
130 	uint8 mac_addr[ETHER_ADDR_LEN];
131 } BWL_POST_PACKED_STRUCT;
132 
133 /* Ipv6 Fragmentation Header */
134 BWL_PRE_PACKED_STRUCT struct ipv6_frag {
135 	uint8	nexthdr;
136 	uint8	reserved;
137 	uint16	frag_offset;
138 	uint32	ident;
139 } BWL_POST_PACKED_STRUCT;
140 
141 /* This marks the end of a packed structure section. */
142 #include <packed_section_end.h>
143 
144 static const struct ipv6_addr all_node_ipv6_maddr = {
145 									{ 0xff, 0x2, 0, 0,
146 									0, 0, 0, 0,
147 									0, 0, 0, 0,
148 									0, 0, 0, 1
149 									}};
150 
151 #define IPV6_ISMULTI(a) (a[0] == 0xff)
152 
153 #define IPV6_MCAST_TO_ETHER_MCAST(ipv6, ether) \
154 { \
155 	ether[0] = 0x33; \
156 	ether[1] = 0x33; \
157 	ether[2] = ipv6[12]; \
158 	ether[3] = ipv6[13]; \
159 	ether[4] = ipv6[14]; \
160 	ether[5] = ipv6[15]; \
161 }
162 
163 #endif	/* !defined(_bcmipv6_h_) */
164