1/*
2 * Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 * Fundamental constants relating to Neighbor Discovery Protocol
17 *
18 * $Id: bcmipv6.h 399481 2013-04-30 09:24:20Z $
19 */
20
21#ifndef _bcmipv6_h_
22#define _bcmipv6_h_
23
24#ifndef _TYPEDEFS_H_
25#include <typedefs.h>
26#endif
27
28/* This marks the start of a packed structure section. */
29#include <packed_section_start.h>
30
31/* Extension headers */
32#define IPV6_EXT_HOP	0
33#define IPV6_EXT_ROUTE	43
34#define IPV6_EXT_FRAG	44
35#define IPV6_EXT_DEST	60
36#define IPV6_EXT_ESEC	50
37#define IPV6_EXT_AUTH	51
38
39/* Minimum size (extension header "word" length) */
40#define IPV6_EXT_WORD	8
41
42/* Offsets for most extension headers */
43#define IPV6_EXT_NEXTHDR	0
44#define IPV6_EXT_HDRLEN		1
45
46/* Constants specific to fragmentation header */
47#define IPV6_FRAG_MORE_MASK	0x0001
48#define IPV6_FRAG_MORE_SHIFT	0
49#define IPV6_FRAG_OFFS_MASK	0xfff8
50#define IPV6_FRAG_OFFS_SHIFT	3
51
52/* For icmpv6 */
53#define ICMPV6_HEADER_TYPE 	0x3A
54#define ICMPV6_PKT_TYPE_NS	135
55#define ICMPV6_PKT_TYPE_NA	136
56
57#define ICMPV6_ND_OPT_TYPE_TARGET_MAC	2
58#define ICMPV6_ND_OPT_TYPE_SRC_MAC		1
59
60#define ICMPV6_ND_OPT_LEN_LINKADDR		1
61
62#define ICMPV6_ND_OPT_LEN_LINKADDR		1
63
64#define IPV6_VERSION 	6
65#define IPV6_HOP_LIMIT 	255
66
67#define IPV6_ADDR_NULL(a)	((a[0] | a[1] | a[2] | a[3] | a[4] | \
68							 a[5] | a[6] | a[7] | a[8] | a[9] | \
69							 a[10] | a[11] | a[12] | a[13] | \
70							 a[14] | a[15]) == 0)
71
72#define IPV6_ADDR_LOCAL(a)	(((a[0] == 0xfe) && (a[1] & 0x80))? TRUE: FALSE)
73
74/* IPV6 address */
75BWL_PRE_PACKED_STRUCT struct ipv6_addr {
76		uint8		addr[16];
77} BWL_POST_PACKED_STRUCT;
78
79#ifndef IL_BIGENDIAN
80
81/* ICMPV6 Header */
82BWL_PRE_PACKED_STRUCT struct icmp6_hdr {
83	uint8	icmp6_type;
84	uint8	icmp6_code;
85	uint16	icmp6_cksum;
86	BWL_PRE_PACKED_STRUCT union {
87		uint32 reserved;
88		BWL_PRE_PACKED_STRUCT struct nd_advt {
89			uint32	reserved1:5,
90				override:1,
91				solicited:1,
92				router:1,
93				reserved2:24;
94		} BWL_POST_PACKED_STRUCT nd_advt;
95	} BWL_POST_PACKED_STRUCT opt;
96} BWL_POST_PACKED_STRUCT;
97
98/* Ipv6 Header Format */
99BWL_PRE_PACKED_STRUCT struct ipv6_hdr {
100	uint8	priority:4,
101		version:4;
102	uint8	flow_lbl[3];
103	uint16	payload_len;
104	uint8	nexthdr;
105	uint8 	hop_limit;
106	struct	ipv6_addr	saddr;
107	struct	ipv6_addr	daddr;
108} BWL_POST_PACKED_STRUCT;
109
110/* Neighbor Advertisement/Solicitation Packet Structure */
111BWL_PRE_PACKED_STRUCT struct nd_msg {
112	struct icmp6_hdr	icmph;
113	struct ipv6_addr target;
114} BWL_POST_PACKED_STRUCT;
115
116
117/* Neighibor Solicitation/Advertisement Optional Structure */
118BWL_PRE_PACKED_STRUCT struct nd_msg_opt {
119	uint8 type;
120	uint8 len;
121	uint8 mac_addr[ETHER_ADDR_LEN];
122} BWL_POST_PACKED_STRUCT;
123
124/* Ipv6 Fragmentation Header */
125BWL_PRE_PACKED_STRUCT struct ipv6_frag {
126	uint8	nexthdr;
127	uint8	reserved;
128	uint16	frag_offset;
129	uint32	ident;
130} BWL_POST_PACKED_STRUCT;
131
132#endif /* IL_BIGENDIAN */
133
134/* This marks the end of a packed structure section. */
135#include <packed_section_end.h>
136
137static const struct ipv6_addr all_node_ipv6_maddr = {
138									{ 0xff, 0x2, 0, 0,
139									0, 0, 0, 0,
140									0, 0, 0, 0,
141									0, 0, 0, 1
142									}};
143
144#define IPV6_ISMULTI(a) (a[0] == 0xff)
145
146#define IPV6_MCAST_TO_ETHER_MCAST(ipv6, ether) \
147{ \
148	ether[0] = 0x33; \
149	ether[1] = 0x33; \
150	ether[2] = ipv6[12]; \
151	ether[3] = ipv6[13]; \
152	ether[4] = ipv6[14]; \
153	ether[5] = ipv6[15]; \
154}
155
156#endif	/* !defined(_bcmipv6_h_) */
157