blob: 24d8b5af4eb547f5c6a8caeefe8bb1044027dbbb [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Anurag Chouhance0dc992016-02-16 18:18:03 +05302 * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Anurag Chouhance0dc992016-02-16 18:18:03 +053028#if !defined(__CDS_UTILS_H)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029#define __CDS_UTILS_H
30
31/**=========================================================================
32
33 \file cds_utils.h
34
35 \brief Connectivity driver services (CDS) utility APIs
36
37 Various utility functions
38
39 ========================================================================*/
40
41/*--------------------------------------------------------------------------
42 Include Files
43 ------------------------------------------------------------------------*/
44#include <cdf_types.h>
Anurag Chouhance0dc992016-02-16 18:18:03 +053045#include <qdf_status.h>
46#include <qdf_event.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080047#include "ani_global.h"
48
49/*--------------------------------------------------------------------------
50 Preprocessor definitions and constants
51 ------------------------------------------------------------------------*/
52#define CDS_DIGEST_SHA1_SIZE (20)
53#define CDS_DIGEST_MD5_SIZE (16)
54#define CDS_BAND_2GHZ (1)
55#define CDS_BAND_5GHZ (2)
56
57#define CDS_24_GHZ_BASE_FREQ (2407)
58#define CDS_5_GHZ_BASE_FREQ (5000)
59#define CDS_24_GHZ_CHANNEL_14 (14)
60#define CDS_24_GHZ_CHANNEL_15 (15)
61#define CDS_24_GHZ_CHANNEL_27 (27)
62#define CDS_5_GHZ_CHANNEL_170 (170)
63#define CDS_CHAN_SPACING_5MHZ (5)
64#define CDS_CHAN_SPACING_20MHZ (20)
65#define CDS_CHAN_14_FREQ (2484)
66#define CDS_CHAN_15_FREQ (2512)
67#define CDS_CHAN_170_FREQ (5852)
68
69#define cds_log(level, args...) CDF_TRACE(CDF_MODULE_ID_CDF, level, ## args)
70#define cds_logfl(level, format, args...) cds_log(level, FL(format), ## args)
71
72#define cds_alert(format, args...) \
73 cds_logfl(CDF_TRACE_LEVEL_FATAL, format, ## args)
74#define cds_err(format, args...) \
75 cds_logfl(CDF_TRACE_LEVEL_ERROR, format, ## args)
76#define cds_warn(format, args...) \
77 cds_logfl(CDF_TRACE_LEVEL_WARN, format, ## args)
78#define cds_notice(format, args...) \
79 cds_logfl(CDF_TRACE_LEVEL_INFO, format, ## args)
80#define cds_info(format, args...) \
81 cds_logfl(CDF_TRACE_LEVEL_INFO_HIGH, format, ## args)
82#define cds_debug(format, args...) \
83 cds_logfl(CDF_TRACE_LEVEL_DEBUG, format, ## args)
84/*--------------------------------------------------------------------------
85 Type declarations
86 ------------------------------------------------------------------------*/
87
88/*-------------------------------------------------------------------------
89 Function declarations and documenation
90 ------------------------------------------------------------------------*/
91
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053092QDF_STATUS cds_crypto_init(uint32_t *phCryptProv);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053094QDF_STATUS cds_crypto_deinit(uint32_t hCryptProv);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095
96/**
97 * cds_rand_get_bytes
98
99 * FUNCTION:
100 * Returns cryptographically secure pseudo-random bytes.
101 *
102 *
103 * @param pbBuf - the caller allocated location where the bytes should be copied
104 * @param numBytes the number of bytes that should be generated and
105 * copied
106 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530107 * @return QDF_STATUS_SUCCSS if the operation succeeds
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800108 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530109QDF_STATUS cds_rand_get_bytes(uint32_t handle, uint8_t *pbBuf,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800110 uint32_t numBytes);
111
112/**
113 * cds_sha1_hmac_str
114 *
115 * FUNCTION:
116 * Generate the HMAC-SHA1 of a string given a key.
117 *
118 * LOGIC:
119 * Standard HMAC processing from RFC 2104. The code is provided in the
120 * appendix of the RFC.
121 *
122 * ASSUMPTIONS:
123 * The RFC is correct.
124 *
125 * @param text text to be hashed
126 * @param textLen length of text
127 * @param key key to use for HMAC
128 * @param keyLen length of key
129 * @param digest holds resultant SHA1 HMAC (20B)
130 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530131 * @return QDF_STATUS_SUCCSS if the operation succeeds
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132 *
133 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530134QDF_STATUS cds_sha1_hmac_str(uint32_t cryptHandle, /* Handle */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530135 uint8_t *text, /* pointer to data stream */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136 uint32_t textLen, /* length of data stream */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530137 uint8_t *key, /* pointer to authentication key */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138 uint32_t keyLen, /* length of authentication key */
139 uint8_t digest[CDS_DIGEST_SHA1_SIZE]); /* caller digest to be filled in */
140
141/**
142 * cds_md5_hmac_str
143 *
144 * FUNCTION:
145 * Generate the HMAC-MD5 of a string given a key.
146 *
147 * LOGIC:
148 * Standard HMAC processing from RFC 2104. The code is provided in the
149 * appendix of the RFC.
150 *
151 * ASSUMPTIONS:
152 * The RFC is correct.
153 *
154 * @param text text to be hashed
155 * @param textLen length of text
156 * @param key key to use for HMAC
157 * @param keyLen length of key
158 * @param digest holds resultant MD5 HMAC (16B)
159 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530160 * @return QDF_STATUS_SUCCSS if the operation succeeds
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800161 *
162 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530163QDF_STATUS cds_md5_hmac_str(uint32_t cryptHandle, /* Handle */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530164 uint8_t *text, /* pointer to data stream */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800165 uint32_t textLen, /* length of data stream */
Anurag Chouhance0dc992016-02-16 18:18:03 +0530166 uint8_t *key, /* pointer to authentication key */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800167 uint32_t keyLen, /* length of authentication key */
168 uint8_t digest[CDS_DIGEST_MD5_SIZE]); /* caller digest to be filled in */
169
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530170QDF_STATUS cds_encrypt_aes(uint32_t cryptHandle, /* Handle */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800171 uint8_t *pText, /* pointer to data stream */
172 uint8_t *Encrypted, uint8_t *pKey); /* pointer to authentication key */
173
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530174QDF_STATUS cds_decrypt_aes(uint32_t cryptHandle, /* Handle */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800175 uint8_t *pText, /* pointer to data stream */
176 uint8_t *pDecrypted, uint8_t *pKey); /* pointer to authentication key */
177
178uint32_t cds_chan_to_freq(uint8_t chan);
179uint8_t cds_freq_to_chan(uint32_t freq);
180uint8_t cds_chan_to_band(uint32_t chan);
181#ifdef WLAN_FEATURE_11W
182bool cds_is_mmie_valid(uint8_t *key, uint8_t *ipn,
183 uint8_t *frm, uint8_t *efrm);
184bool cds_attach_mmie(uint8_t *igtk, uint8_t *ipn, uint16_t key_id,
185 uint8_t *frm, uint8_t *efrm, uint16_t frmLen);
186uint8_t cds_get_mmie_size(void);
187#endif /* WLAN_FEATURE_11W */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530188QDF_STATUS sme_send_flush_logs_cmd_to_fw(tpAniSirGlobal pMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189#endif /* #if !defined __CDS_UTILS_H */