blob: 488529a81bbc69897a42d67fa539920df5a63bfb [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson0e1e7682019-02-20 13:36:04 -08002 * Copyright (c) 2011-2019 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * 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/*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080020 *
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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040/* Byte String <--> uint16_t/uint32_t copy functions */
41static 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
Jeff Johnson47d75242018-05-12 15:58:53 -070048#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080049#endif
50}
51
52static 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
Jeff Johnson47d75242018-05-12 15:58:53 -070058#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059#endif
60}
61
62static 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
Jeff Johnson47d75242018-05-12 15:58:53 -070071#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080072#endif
73}
74
75static 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
Jeff Johnson47d75242018-05-12 15:58:53 -070082#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#endif
84}
85
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +053086/**
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 */
94static 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 */
106static inline uint16_t lim_get_u16_be(uint8_t *buf)
107{
108 return (buf[0] << 8) | buf[1];
109}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800110#endif /* __LIM_SERDES_UTILS_H */