1 /*
2 * Copyright (c) 2011-2019 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /*
20 *
21 * This file lim_ser_des_utils.h contains the utility definitions
22 * LIM uses while processing messages from upper layer software
23 * modules
24 * Author: Chandra Modumudi
25 * Date: 10/20/02
26 * History:-
27 * Date Modified by Modification Information
28 * --------------------------------------------------------------------
29 */
30 #ifndef __LIM_SERDES_UTILS_H
31 #define __LIM_SERDES_UTILS_H
32
33 #include "sir_api.h"
34 #include "ani_system_defs.h"
35 #include "sir_mac_prot_def.h"
36 #include "utils_api.h"
37 #include "lim_types.h"
38 #include "lim_prop_exts_utils.h"
39
40 /* Byte String <--> uint16_t/uint32_t copy functions */
lim_copy_u16(uint8_t * ptr,uint16_t u16Val)41 static inline void lim_copy_u16(uint8_t *ptr, uint16_t u16Val)
42 {
43 #if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
44 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
45 *ptr++ = (uint8_t) (u16Val & 0xff);
46 *ptr = (uint8_t) ((u16Val >> 8) & 0xff);
47 #else
48 #error "Unknown combination of OS Type and endianness"
49 #endif
50 }
51
lim_get_u16(uint8_t * ptr)52 static inline uint16_t lim_get_u16(uint8_t *ptr)
53 {
54 #if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
55 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
56 return ((uint16_t) (*(ptr + 1) << 8)) | ((uint16_t) (*ptr));
57 #else
58 #error "Unknown combination of OS Type and endianness"
59 #endif
60 }
61
lim_copy_u32(uint8_t * ptr,uint32_t u32Val)62 static inline void lim_copy_u32(uint8_t *ptr, uint32_t u32Val)
63 {
64 #if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
65 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
66 *ptr++ = (uint8_t) (u32Val & 0xff);
67 *ptr++ = (uint8_t) ((u32Val >> 8) & 0xff);
68 *ptr++ = (uint8_t) ((u32Val >> 16) & 0xff);
69 *ptr = (uint8_t) ((u32Val >> 24) & 0xff);
70 #else
71 #error "Unknown combination of OS Type and endianness"
72 #endif
73 }
74
lim_get_u32(uint8_t * ptr)75 static inline uint32_t lim_get_u32(uint8_t *ptr)
76 {
77 #if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
78 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
79 return ((*(ptr + 3) << 24) |
80 (*(ptr + 2) << 16) | (*(ptr + 1) << 8) | (*(ptr)));
81 #else
82 #error "Unknown combination of OS Type and endianness"
83 #endif
84 }
85
86 /**
87 * lim_copy_u16_be()- This API copies a u16 value in buffer
88 * to network byte order
89 * @ptr: pointer to buffer
90 * @u16_val: value needs to be copied
91 *
92 * Return: None
93 */
lim_copy_u16_be(uint8_t * ptr,uint16_t u16_val)94 static inline void lim_copy_u16_be(uint8_t *ptr, uint16_t u16_val)
95 {
96 ptr[0] = u16_val >> 8;
97 ptr[1] = u16_val & 0xff;
98 }
99
100 /**
101 * lim_copy_u16_be()- This API reads u16 value from network byte order buffer
102 * @ptr: pointer to buffer
103 *
104 * Return: 16bit value
105 */
lim_get_u16_be(uint8_t * buf)106 static inline uint16_t lim_get_u16_be(uint8_t *buf)
107 {
108 return (buf[0] << 8) | buf[1];
109 }
110 #endif /* __LIM_SERDES_UTILS_H */
111