Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 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 Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 28 | #if !defined(__CDS_UTILS_H) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 29 | #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 Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 45 | #include <qdf_status.h> |
| 46 | #include <qdf_event.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 47 | #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 Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 92 | QDF_STATUS cds_crypto_init(uint32_t *phCryptProv); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 93 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 94 | QDF_STATUS cds_crypto_deinit(uint32_t hCryptProv); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 95 | |
| 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 Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 107 | * @return QDF_STATUS_SUCCSS if the operation succeeds |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 108 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 109 | QDF_STATUS cds_rand_get_bytes(uint32_t handle, uint8_t *pbBuf, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 110 | 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 Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 131 | * @return QDF_STATUS_SUCCSS if the operation succeeds |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 132 | * |
| 133 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 134 | QDF_STATUS cds_sha1_hmac_str(uint32_t cryptHandle, /* Handle */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 135 | uint8_t *text, /* pointer to data stream */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 136 | uint32_t textLen, /* length of data stream */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 137 | uint8_t *key, /* pointer to authentication key */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 138 | 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 Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 160 | * @return QDF_STATUS_SUCCSS if the operation succeeds |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 161 | * |
| 162 | */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 163 | QDF_STATUS cds_md5_hmac_str(uint32_t cryptHandle, /* Handle */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 164 | uint8_t *text, /* pointer to data stream */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 165 | uint32_t textLen, /* length of data stream */ |
Anurag Chouhan | ce0dc99 | 2016-02-16 18:18:03 +0530 | [diff] [blame] | 166 | uint8_t *key, /* pointer to authentication key */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 167 | uint32_t keyLen, /* length of authentication key */ |
| 168 | uint8_t digest[CDS_DIGEST_MD5_SIZE]); /* caller digest to be filled in */ |
| 169 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 170 | QDF_STATUS cds_encrypt_aes(uint32_t cryptHandle, /* Handle */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 171 | uint8_t *pText, /* pointer to data stream */ |
| 172 | uint8_t *Encrypted, uint8_t *pKey); /* pointer to authentication key */ |
| 173 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 174 | QDF_STATUS cds_decrypt_aes(uint32_t cryptHandle, /* Handle */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 175 | uint8_t *pText, /* pointer to data stream */ |
| 176 | uint8_t *pDecrypted, uint8_t *pKey); /* pointer to authentication key */ |
| 177 | |
| 178 | uint32_t cds_chan_to_freq(uint8_t chan); |
| 179 | uint8_t cds_freq_to_chan(uint32_t freq); |
| 180 | uint8_t cds_chan_to_band(uint32_t chan); |
| 181 | #ifdef WLAN_FEATURE_11W |
| 182 | bool cds_is_mmie_valid(uint8_t *key, uint8_t *ipn, |
| 183 | uint8_t *frm, uint8_t *efrm); |
| 184 | bool cds_attach_mmie(uint8_t *igtk, uint8_t *ipn, uint16_t key_id, |
| 185 | uint8_t *frm, uint8_t *efrm, uint16_t frmLen); |
| 186 | uint8_t cds_get_mmie_size(void); |
| 187 | #endif /* WLAN_FEATURE_11W */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 188 | QDF_STATUS sme_send_flush_logs_cmd_to_fw(tpAniSirGlobal pMac); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 189 | #endif /* #if !defined __CDS_UTILS_H */ |