diff options
| author | Dundi Raviteja <dundi@codeaurora.org> | 2018-05-16 17:41:51 +0530 |
|---|---|---|
| committer | nshrivas <nshrivas@codeaurora.org> | 2018-07-18 23:13:22 -0700 |
| commit | bcdc4e4d22fa8a56cd1cfa184df70a4187437edb (patch) | |
| tree | c5ec913e5dbedfccae54d2bd6b564b4e1a55fbf8 | |
| parent | 5cc4e1f9fe1257dd6a7ecb98b005050dc87be1e5 (diff) | |
qcacld-3.0: Use request manager for DISA encrypt/decrypt
We are transitioning to the new request manager framework. Change
hdd_encrypt_decrypt_msg() and hdd_encrypt_decrypt_msg_cb() to this
framework.
Note that this framework provides the infrastructure to pass data from
the response thread to the request thread and hence eliminates the
need to maintain a separate encrypt_decrypt_msg_context.
Change-Id: Ic0a0357566a2a8b39d73cb82371219315034019e
CRs-Fixed: 2005316
| -rw-r--r-- | core/hdd/src/wlan_hdd_disa.c | 235 | ||||
| -rw-r--r-- | core/hdd/src/wlan_hdd_disa.h | 30 | ||||
| -rw-r--r-- | core/hdd/src/wlan_hdd_main.c | 3 | ||||
| -rw-r--r-- | core/sme/inc/sme_api.h | 10 | ||||
| -rw-r--r-- | core/sme/inc/sme_internal.h | 5 | ||||
| -rw-r--r-- | core/sme/src/common/sme_api.c | 14 | ||||
| -rw-r--r-- | core/wma/inc/wma.h | 3 | ||||
| -rw-r--r-- | core/wma/src/wma_features.c | 3 |
8 files changed, 138 insertions, 165 deletions
diff --git a/core/hdd/src/wlan_hdd_disa.c b/core/hdd/src/wlan_hdd_disa.c index 064f5526b718..721b52f4ef1d 100644 --- a/core/hdd/src/wlan_hdd_disa.c +++ b/core/hdd/src/wlan_hdd_disa.c @@ -25,49 +25,50 @@ #include "wlan_hdd_disa.h" #include "sme_api.h" +#include "wlan_hdd_request_manager.h" -#define ENCRYPT_DECRYPT_CONTEXT_MAGIC 0x4475354 #define WLAN_WAIT_TIME_ENCRYPT_DECRYPT 1000 - /** * hdd_encrypt_decrypt_msg_context - hdd encrypt/decrypt message context - * - * @magic: magic number - * @completion: Completion variable for encrypt/decrypt message - * @response_event: encrypt/decrypt message request wait event + * @status: status of response. 0: no error, -ENOMEM: unable to allocate + * memory for the response payload + * @request: encrypt/decrypt request + * @response: encrypt/decrypt response */ struct hdd_encrypt_decrypt_msg_context { - unsigned int magic; - struct completion completion; + int status; + struct encrypt_decrypt_req_params request; struct sir_encrypt_decrypt_rsp_params response; }; -static struct hdd_encrypt_decrypt_msg_context encrypt_decrypt_msg_context; /** - * hdd_encrypt_decrypt_msg_cb () - sends encrypt/decrypt data to user space + * hdd_encrypt_decrypt_msg_cb () - encrypt/decrypt response message handler + * @cookie: hdd request cookie * @encrypt_decrypt_rsp_params: encrypt/decrypt response parameters * * Return: none */ -static void hdd_encrypt_decrypt_msg_cb(void *hdd_context, - struct sir_encrypt_decrypt_rsp_params *encrypt_decrypt_rsp_params) +static void hdd_encrypt_decrypt_msg_cb(void *cookie, + struct sir_encrypt_decrypt_rsp_params + *encrypt_decrypt_rsp_params) { - hdd_context_t *hdd_ctx = hdd_context; - int ret; + struct hdd_request *request; struct hdd_encrypt_decrypt_msg_context *context; ENTER(); - ret = wlan_hdd_validate_context(hdd_ctx); - if (ret) - return; - if (!encrypt_decrypt_rsp_params) { hdd_err("rsp params is NULL"); return; } + request = hdd_request_get(cookie); + if (!request) { + hdd_err("obsolete request"); + return; + } + print_hex_dump(KERN_INFO, "Data in hdd_encrypt_decrypt_msg_cb: ", DUMP_PREFIX_NONE, 16, 1, encrypt_decrypt_rsp_params->data, @@ -78,52 +79,42 @@ static void hdd_encrypt_decrypt_msg_cb(void *hdd_context, encrypt_decrypt_rsp_params->status, encrypt_decrypt_rsp_params->data_length); - spin_lock(&hdd_context_lock); + context = hdd_request_priv(request); - context = &encrypt_decrypt_msg_context; - /* The caller presumably timed out so there is nothing we can do */ - if (context->magic != ENCRYPT_DECRYPT_CONTEXT_MAGIC) { - spin_unlock(&hdd_context_lock); - return; - } - - /* context is valid so caller is still waiting */ context->response = *encrypt_decrypt_rsp_params; if (encrypt_decrypt_rsp_params->data_length) { context->response.data = qdf_mem_malloc(sizeof(uint8_t) * encrypt_decrypt_rsp_params->data_length); - if (context->response.data == NULL) { - hdd_err("cdf_mem_alloc failed for data"); - spin_unlock(&hdd_context_lock); + if (!context->response.data) { + hdd_err("memory allocation failed"); + context->status = -ENOMEM; + hdd_request_complete(request); + hdd_request_put(request); return; + } else { + qdf_mem_copy(context->response.data, + encrypt_decrypt_rsp_params->data, + encrypt_decrypt_rsp_params->data_length); } - qdf_mem_copy(context->response.data, - encrypt_decrypt_rsp_params->data, - encrypt_decrypt_rsp_params->data_length); + } else { + /* make sure we don't have a rogue pointer */ + context->response.data = NULL; } - /* - * Indicate to calling thread that - * response data is available - */ - context->magic = 0; - - complete(&context->completion); - - spin_unlock(&hdd_context_lock); - + hdd_request_complete(request); + hdd_request_put(request); EXIT(); } - /** - * hdd_encrypt_decrypt_msg_cb () - sends encrypt/decrypt data to user space + * hdd_post_encrypt_decrypt_msg_rsp () - sends encrypt/decrypt msg to user space + * @hdd_ctx: pointer to hdd context * @encrypt_decrypt_rsp_params: encrypt/decrypt response parameters * - * Return: none + * Return: 0 on success, negative errno on failure */ static int hdd_post_encrypt_decrypt_msg_rsp(hdd_context_t *hdd_ctx, struct sir_encrypt_decrypt_rsp_params *encrypt_decrypt_rsp_params) @@ -331,7 +322,7 @@ static int hdd_fill_encrypt_decrypt_params(struct encrypt_decrypt_req_params encrypt_decrypt_params->data_len); if (encrypt_decrypt_params->data == NULL) { - hdd_err("cdf_mem_alloc failed for data"); + hdd_err("memory allocation failed"); return -ENOMEM; } @@ -349,111 +340,119 @@ static int hdd_fill_encrypt_decrypt_params(struct encrypt_decrypt_req_params } /** + * hdd_encrypt_decrypt_context_dealloc() - deallocate memory allocated for data + * @priv: Pointer to private data + * + * Return: None + */ +static void hdd_encrypt_decrypt_context_dealloc(void *priv) +{ + struct hdd_encrypt_decrypt_msg_context *context = priv; + + if (context->request.data) { + qdf_mem_free(context->request.data); + context->request.data = NULL; + } + + if (context->response.data) { + qdf_mem_free(context->response.data); + context->response.data = NULL; + } +} + +/** * hdd_encrypt_decrypt_msg () - process encrypt/decrypt message * @adapter : adapter context * @hdd_ctx: hdd context * @data: Pointer to data * @data_len: Data length * - Return: 0 on success, negative errno on failure + * Return: 0 on success, negative errno on failure */ static int hdd_encrypt_decrypt_msg(hdd_adapter_t *adapter, - hdd_context_t *hdd_ctx, - const void *data, - int data_len) + hdd_context_t *hdd_ctx, + const void *data, + int data_len) { - struct encrypt_decrypt_req_params encrypt_decrypt_params = {0}; QDF_STATUS qdf_status; int ret; + void *cookie; + struct hdd_request *request; struct hdd_encrypt_decrypt_msg_context *context; - unsigned long rc; + static const struct hdd_request_params params = { + .priv_size = sizeof(*context), + .timeout_ms = WLAN_WAIT_TIME_ENCRYPT_DECRYPT, + .dealloc = hdd_encrypt_decrypt_context_dealloc, + }; + + request = hdd_request_alloc(¶ms); + if (!request) { + hdd_err("Request Allocation Failure"); + return -ENOMEM; + } + context = hdd_request_priv(request); - ret = hdd_fill_encrypt_decrypt_params(&encrypt_decrypt_params, - adapter, data, data_len); + ret = hdd_fill_encrypt_decrypt_params(&context->request, + adapter, data, data_len); if (ret) - return ret; + goto clean_up; - spin_lock(&hdd_context_lock); - context = &encrypt_decrypt_msg_context; - context->magic = ENCRYPT_DECRYPT_CONTEXT_MAGIC; - INIT_COMPLETION(context->completion); - spin_unlock(&hdd_context_lock); + cookie = hdd_request_cookie(request); - qdf_status = sme_encrypt_decrypt_msg(hdd_ctx->hHal, - &encrypt_decrypt_params); + qdf_status = sme_encrypt_decrypt_msg_register_callback(hdd_ctx->hHal, + hdd_encrypt_decrypt_msg_cb); + if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { + hdd_err("Encrypt/Decrypt callback failed %d", qdf_status); + ret = -EINVAL; + goto clean_up; + } - qdf_mem_free(encrypt_decrypt_params.data); + qdf_status = sme_encrypt_decrypt_msg(hdd_ctx->hHal, + &context->request, + cookie); if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { hdd_err("Unable to post encrypt/decrypt message"); - return -EINVAL; + ret = -EINVAL; + goto deregister_cb; } - rc = wait_for_completion_timeout(&context->completion, - msecs_to_jiffies(WLAN_WAIT_TIME_ENCRYPT_DECRYPT)); - - spin_lock(&hdd_context_lock); - if (!rc && (context->magic == - ENCRYPT_DECRYPT_CONTEXT_MAGIC)) { + ret = hdd_request_wait_for_response(request); + if (ret) { hdd_err("Target response timed out"); - context->magic = 0; - spin_unlock(&hdd_context_lock); - return -ETIMEDOUT; + goto deregister_cb; } - spin_unlock(&hdd_context_lock); - ret = hdd_post_encrypt_decrypt_msg_rsp(hdd_ctx, - &encrypt_decrypt_msg_context.response); + ret = context->status; + if (ret) { + hdd_err("Target response processing failed"); + goto deregister_cb; + } + + ret = hdd_post_encrypt_decrypt_msg_rsp(hdd_ctx, &context->response); if (ret) hdd_err("Failed to post encrypt/decrypt message response"); - qdf_mem_free(encrypt_decrypt_msg_context.response.data); +deregister_cb: + qdf_status = sme_encrypt_decrypt_msg_deregister_callback(hdd_ctx->hHal); + if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { + hdd_err("De-register encrypt/decrypt callback failed: %d", + qdf_status); + ret = -EINVAL; + } +clean_up: + /* + * either we never sent a request, we sent a request and + * received a response or we sent a request and timed out. + * regardless we are done with the request. + */ + hdd_request_put(request); EXIT(); return ret; } /** - * hdd_encrypt_decrypt_init () - exposes encrypt/decrypt initialization - * functionality - * @hdd_ctx: hdd context - * - Return: 0 on success, negative errno on failure - */ -int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx) -{ - QDF_STATUS status; - - init_completion(&encrypt_decrypt_msg_context.completion); - - status = sme_encrypt_decrypt_msg_register_callback(hdd_ctx->hHal, - hdd_encrypt_decrypt_msg_cb); - if (!QDF_IS_STATUS_SUCCESS(status)) { - hdd_err("encrypt/decrypt callback failed %d", status); - return -EINVAL; - } - return 0; -} - -/** - * hdd_encrypt_decrypt_deinit () - exposes encrypt/decrypt deinitialization - * functionality - * @hdd_ctx: hdd context - * - Return: 0 on success, negative errno on failure - */ -int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx) -{ - QDF_STATUS status; - - status = sme_encrypt_decrypt_msg_deregister_callback(hdd_ctx->hHal); - if (!QDF_IS_STATUS_SUCCESS(status)) - hdd_err("De-register encrypt/decrypt callback failed: %d", - status); - return 0; -} - -/** * __wlan_hdd_cfg80211_encrypt_decrypt_msg () - Encrypt/Decrypt msg * @wiphy: Pointer to wireless phy * @wdev: Pointer to wireless device diff --git a/core/hdd/src/wlan_hdd_disa.h b/core/hdd/src/wlan_hdd_disa.h index b35c02c5dbbe..c9b6eed8f19d 100644 --- a/core/hdd/src/wlan_hdd_disa.h +++ b/core/hdd/src/wlan_hdd_disa.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -22,34 +22,6 @@ #include "wlan_hdd_main.h" #include "sir_api.h" -#ifdef WLAN_FEATURE_DISA -/** - * hdd_encrypt_decrypt_init () - exposes encrypt/decrypt initialization - * functionality - * @hdd_ctx: hdd context - * - Return: 0 on success, negative errno on failure - */ -int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx); - -/** - * hdd_encrypt_decrypt_deinit () - exposes encrypt/decrypt deinitialization - * functionality - * @hdd_ctx: hdd context - * - Return: 0 on success, negative errno on failure - */ -int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx); -#else -static inline int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx) -{ - return -ENOTSUPP; -} -static inline int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx) -{ - return -ENOTSUPP; -} -#endif #ifdef WLAN_FEATURE_DISA /** diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index a85fc3f3ced1..38a03d742c7c 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -10444,7 +10444,6 @@ static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter) hdd_err("Error setting txlimit in sme: %d", status); wlan_hdd_tsf_init(hdd_ctx); - hdd_encrypt_decrypt_init(hdd_ctx); if (hdd_ctx->config->goptimize_chan_avoid_event) { status = sme_enable_disable_chanavoidind_event( @@ -10662,8 +10661,6 @@ static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx) /* De-init features */ hdd_features_deinit(hdd_ctx); - hdd_encrypt_decrypt_deinit(hdd_ctx); - sme_destroy_config(hdd_ctx->hHal); /* De-init Policy Manager */ diff --git a/core/sme/inc/sme_api.h b/core/sme/inc/sme_api.h index e2961352ab7a..3a71ec424921 100644 --- a/core/sme/inc/sme_api.h +++ b/core/sme/inc/sme_api.h @@ -1596,15 +1596,16 @@ QDF_STATUS sme_update_fils_setting(tHalHandle hal, uint8_t session_id, * * @hal - MAC global handle * @callback_routine - callback routine from HDD + * @context - callback context * * This API is invoked by HDD to register its callback in SME * * Return: QDF_STATUS */ QDF_STATUS sme_encrypt_decrypt_msg_register_callback(tHalHandle hal, - void (*encrypt_decrypt_cb)(void *hdd_context, - struct sir_encrypt_decrypt_rsp_params - *encrypt_decrypt_rsp_params)); + void (*encrypt_decrypt_cb)(void *cookie, + struct sir_encrypt_decrypt_rsp_params + *encrypt_decrypt_rsp_params)); /** * sme_encrypt_decrypt_msg_deregister_callback() - Registers @@ -1627,7 +1628,8 @@ QDF_STATUS sme_encrypt_decrypt_msg_deregister_callback(tHalHandle h_hal); * Return: QDF_STATUS enumeration. */ QDF_STATUS sme_encrypt_decrypt_msg(tHalHandle hal, - struct encrypt_decrypt_req_params *encrypt_decrypt_params); + struct encrypt_decrypt_req_params *encrypt_decrypt_params, + void *context); #endif /** diff --git a/core/sme/inc/sme_internal.h b/core/sme/inc/sme_internal.h index 325c3c2d95b9..6bc5a58b6252 100644 --- a/core/sme/inc/sme_internal.h +++ b/core/sme/inc/sme_internal.h @@ -260,8 +260,9 @@ typedef struct tagSmeStruct { p2p_lo_callback p2p_lo_event_callback; void *p2p_lo_event_context; sme_send_oem_data_rsp_msg oem_data_rsp_callback; - void (*encrypt_decrypt_cb)(void *, - struct sir_encrypt_decrypt_rsp_params *); + void *encrypt_decrypt_context; + void (*encrypt_decrypt_cb)(void *cookie, + struct sir_encrypt_decrypt_rsp_params *rsp); void (*lost_link_info_cb)(void *context, struct sir_lost_link_info *lost_link_info); void (*rso_cmd_status_cb)(void *hdd_context, diff --git a/core/sme/src/common/sme_api.c b/core/sme/src/common/sme_api.c index 1fc15fedb585..d3c16621870c 100644 --- a/core/sme/src/common/sme_api.c +++ b/core/sme/src/common/sme_api.c @@ -17646,11 +17646,13 @@ QDF_STATUS sme_set_sar_power_limits(tHalHandle hal, * sme_encrypt_decrypt_msg() - handles encrypt/decrypt mesaage * @hal: HAL handle * @encrypt_decrypt_params: struct to set encryption/decryption params. + * @context: callback context * * Return: QDF_STATUS enumeration. */ QDF_STATUS sme_encrypt_decrypt_msg(tHalHandle hal, - struct encrypt_decrypt_req_params *encrypt_decrypt_params) + struct encrypt_decrypt_req_params *encrypt_decrypt_params, + void *context) { QDF_STATUS status = QDF_STATUS_SUCCESS; tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal); @@ -17677,6 +17679,7 @@ QDF_STATUS sme_encrypt_decrypt_msg(tHalHandle hal, params->data_len); } + mac_ctx->sme.encrypt_decrypt_context = context; status = sme_acquire_global_lock(&mac_ctx->sme); if (status == QDF_STATUS_SUCCESS) { /* Serialize the req through MC thread */ @@ -17705,16 +17708,17 @@ QDF_STATUS sme_encrypt_decrypt_msg(tHalHandle hal, * encrypt/decrypt message callback * * @hal - MAC global handle - * @callback_routine - callback routine from HDD + * @encrypt_decrypt_cb - callback routine from HDD + * @context - callback context * * This API is invoked by HDD to register its callback in SME * * Return: QDF_STATUS */ QDF_STATUS sme_encrypt_decrypt_msg_register_callback(tHalHandle hal, - void (*encrypt_decrypt_cb)(void *hdd_context, - struct sir_encrypt_decrypt_rsp_params - *encrypt_decrypt_rsp_params)) + void (*encrypt_decrypt_cb)(void *cookie, + struct sir_encrypt_decrypt_rsp_params + *encrypt_decrypt_rsp_params)) { QDF_STATUS status = QDF_STATUS_SUCCESS; tpAniSirGlobal mac; diff --git a/core/wma/inc/wma.h b/core/wma/inc/wma.h index 0b69941a8455..196768f433cb 100644 --- a/core/wma/inc/wma.h +++ b/core/wma/inc/wma.h @@ -565,9 +565,6 @@ static const t_probeTime_dwellTime }; typedef void (*txFailIndCallback)(uint8_t *peer_mac, uint8_t seqNo); -typedef void (*encrypt_decrypt_cb)(struct sir_encrypt_decrypt_rsp_params - *encrypt_decrypt_rsp_params); - typedef void (*tp_wma_packetdump_cb)(qdf_nbuf_t netbuf, uint8_t status, uint8_t vdev_id, uint8_t type); diff --git a/core/wma/src/wma_features.c b/core/wma/src/wma_features.c index dddedba129f7..31550a4fa467 100644 --- a/core/wma/src/wma_features.c +++ b/core/wma/src/wma_features.c @@ -10953,7 +10953,8 @@ int wma_encrypt_decrypt_msg_handler(void *handle, uint8_t *data, encrypt_decrypt_rsp_params.data = buf_ptr; } - pmac->sme.encrypt_decrypt_cb(pmac->hHdd, &encrypt_decrypt_rsp_params); + pmac->sme.encrypt_decrypt_cb(pmac->sme.encrypt_decrypt_context, + &encrypt_decrypt_rsp_params); return 0; } |
