blob: b05f5ef45d1a4f62388cba7f42351df59d45de5c [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
Jeff Johnson9320c1e2018-12-02 13:09:20 -080040void lim_get_session_info(struct mac_context *mac, uint8_t *,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080041 uint8_t *, uint16_t *);
42
43/* Byte String <--> uint16_t/uint32_t copy functions */
44static inline void lim_copy_u16(uint8_t *ptr, uint16_t u16Val)
45{
46#if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
47 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
48 *ptr++ = (uint8_t) (u16Val & 0xff);
49 *ptr = (uint8_t) ((u16Val >> 8) & 0xff);
50#else
Jeff Johnson47d75242018-05-12 15:58:53 -070051#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052#endif
53}
54
55static inline uint16_t lim_get_u16(uint8_t *ptr)
56{
57#if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
58 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
59 return ((uint16_t) (*(ptr + 1) << 8)) | ((uint16_t) (*ptr));
60#else
Jeff Johnson47d75242018-05-12 15:58:53 -070061#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062#endif
63}
64
65static inline void lim_copy_u32(uint8_t *ptr, uint32_t u32Val)
66{
67#if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
68 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
69 *ptr++ = (uint8_t) (u32Val & 0xff);
70 *ptr++ = (uint8_t) ((u32Val >> 8) & 0xff);
71 *ptr++ = (uint8_t) ((u32Val >> 16) & 0xff);
72 *ptr = (uint8_t) ((u32Val >> 24) & 0xff);
73#else
Jeff Johnson47d75242018-05-12 15:58:53 -070074#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075#endif
76}
77
78static inline uint32_t lim_get_u32(uint8_t *ptr)
79{
80#if ((defined(ANI_OS_TYPE_QNX) && defined(ANI_LITTLE_BYTE_ENDIAN)) || \
81 (defined(ANI_OS_TYPE_ANDROID) && defined(ANI_LITTLE_BYTE_ENDIAN)))
82 return ((*(ptr + 3) << 24) |
83 (*(ptr + 2) << 16) | (*(ptr + 1) << 8) | (*(ptr)));
84#else
Jeff Johnson47d75242018-05-12 15:58:53 -070085#error "Unknown combination of OS Type and endianness"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086#endif
87}
88
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +053089/**
90 * lim_copy_u16_be()- This API copies a u16 value in buffer
91 * to network byte order
92 * @ptr: pointer to buffer
93 * @u16_val: value needs to be copied
94 *
95 * Return: None
96 */
97static inline void lim_copy_u16_be(uint8_t *ptr, uint16_t u16_val)
98{
99 ptr[0] = u16_val >> 8;
100 ptr[1] = u16_val & 0xff;
101}
102
103/**
104 * lim_copy_u16_be()- This API reads u16 value from network byte order buffer
105 * @ptr: pointer to buffer
106 *
107 * Return: 16bit value
108 */
109static inline uint16_t lim_get_u16_be(uint8_t *buf)
110{
111 return (buf[0] << 8) | buf[1];
112}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800113#endif /* __LIM_SERDES_UTILS_H */