xref: /wlan-driver/qcacld-3.0/core/dp/txrx/ipv6_defs.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2012-2014, 2017 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name  * above copyright notice and this permission notice appear in all
7*5113495bSYour Name  * copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name  */
18*5113495bSYour Name 
19*5113495bSYour Name #ifndef _IPV6__H_
20*5113495bSYour Name #define _IPV6__H_
21*5113495bSYour Name 
22*5113495bSYour Name #if defined(ATH_TARGET)
23*5113495bSYour Name #include <osapi.h>              /* A_UINT8 */
24*5113495bSYour Name #else
25*5113495bSYour Name #include <a_types.h>            /* A_UINT8 */
26*5113495bSYour Name #endif
27*5113495bSYour Name 
28*5113495bSYour Name /* utilities for converting between network byte order and native endianness */
29*5113495bSYour Name #ifndef BYTESWAP32
30*5113495bSYour Name #define BYTESWAP32(x) \
31*5113495bSYour Name 	((((x) & 0x000000ff) << 24) /* byte 0 -> byte 3 */ | \
32*5113495bSYour Name 	 (((x) & 0x0000ff00) <<  8) /* byte 1 -> byte 2 */ | \
33*5113495bSYour Name 	 (((x) & 0x00ff0000) >>  8) /* byte 2 -> byte 1 */ | \
34*5113495bSYour Name 	 (((x) & 0xff000000) >> 24) /* byte 3 -> byte 0 */)
35*5113495bSYour Name #endif /* BYTESWAP32 */
36*5113495bSYour Name 
37*5113495bSYour Name #ifndef BE_TO_CPU32
38*5113495bSYour Name #if defined(ATH_TARGET)
39*5113495bSYour Name /* assume target is little-endian */
40*5113495bSYour Name #define BE_TO_CPU32(x) BYTESWAP32(x)
41*5113495bSYour Name #else
42*5113495bSYour Name #ifdef BIG_ENDIAN_HOST
43*5113495bSYour Name #define BE_TO_CPU32(x) (x)
44*5113495bSYour Name #else
45*5113495bSYour Name #define BE_TO_CPU32(x) BYTESWAP32(x)
46*5113495bSYour Name #endif
47*5113495bSYour Name #endif
48*5113495bSYour Name #endif /* BE_TO_CPU32 */
49*5113495bSYour Name 
50*5113495bSYour Name /* IPv6 header definition */
51*5113495bSYour Name 
52*5113495bSYour Name #define IPV6_ADDR_LEN 4         /* bytes */
53*5113495bSYour Name struct ipv6_hdr_t {
54*5113495bSYour Name 	/* version, traffic class, and flow label */
55*5113495bSYour Name 	A_UINT32 ver_tclass_flowlabel;
56*5113495bSYour Name 	A_UINT8 pyld_len[2];    /* payload length */
57*5113495bSYour Name 	A_UINT8 next_hdr;
58*5113495bSYour Name 	A_UINT8 hop_limit;
59*5113495bSYour Name 	A_UINT8 src_addr[IPV6_ADDR_LEN];
60*5113495bSYour Name 	A_UINT8 dst_addr[IPV6_ADDR_LEN];
61*5113495bSYour Name };
62*5113495bSYour Name 
63*5113495bSYour Name #define IPV6_HDR_LEN (sizeof(struct ipv6_hdr_t))
64*5113495bSYour Name #define IPV6_HDR_OFFSET_NEXT_HDR (offsetof(struct ipv6_hdr_t, next_hdr))
65*5113495bSYour Name #define IPV6_HDR_OFFSET_DST_ADDR (offsetof(struct ipv6_hdr_t, dst_addr[0]))
66*5113495bSYour Name 
67*5113495bSYour Name /* IPv6 header field access macros */
68*5113495bSYour Name 
69*5113495bSYour Name #define IPV6_HDR_VERSION_M       0xF0000000
70*5113495bSYour Name #define IPV6_HDR_VERSION_S       28
71*5113495bSYour Name 
72*5113495bSYour Name #define IPV6_HDR_TRAFFIC_CLASS_M 0x0FF00000
73*5113495bSYour Name #define IPV6_HDR_TRAFFIC_CLASS_S 20
74*5113495bSYour Name 
75*5113495bSYour Name #define IPV6_HDR_FLOW_LABEL_M    0x000FFFFF
76*5113495bSYour Name #define IPV6_HDR_FLOW_LABEL_S    0
77*5113495bSYour Name 
ipv6_version(struct ipv6_hdr_t * ipv6_hdr)78*5113495bSYour Name static inline A_UINT8 ipv6_version(struct ipv6_hdr_t *ipv6_hdr)
79*5113495bSYour Name {
80*5113495bSYour Name 	return (BE_TO_CPU32(ipv6_hdr->ver_tclass_flowlabel) &
81*5113495bSYour Name 	       IPV6_HDR_VERSION_M) >> IPV6_HDR_VERSION_S;
82*5113495bSYour Name }
83*5113495bSYour Name 
ipv6_traffic_class(struct ipv6_hdr_t * ipv6_hdr)84*5113495bSYour Name static inline A_UINT8 ipv6_traffic_class(struct ipv6_hdr_t *ipv6_hdr)
85*5113495bSYour Name {
86*5113495bSYour Name 	return (A_UINT8)((BE_TO_CPU32(ipv6_hdr->ver_tclass_flowlabel) &
87*5113495bSYour Name 	       IPV6_HDR_TRAFFIC_CLASS_M) >> IPV6_HDR_TRAFFIC_CLASS_S);
88*5113495bSYour Name }
89*5113495bSYour Name 
ipv6_flow_label(struct ipv6_hdr_t * ipv6_hdr)90*5113495bSYour Name static inline A_UINT32 ipv6_flow_label(struct ipv6_hdr_t *ipv6_hdr)
91*5113495bSYour Name {
92*5113495bSYour Name 	return (BE_TO_CPU32(ipv6_hdr->ver_tclass_flowlabel) &
93*5113495bSYour Name 	       IPV6_HDR_FLOW_LABEL_M) >> IPV6_HDR_FLOW_LABEL_S;
94*5113495bSYour Name }
95*5113495bSYour Name 
96*5113495bSYour Name #endif /* _IPV6__H_ */
97