From a41da1d50f509bdee762096f3bd0c334de27f7cf Mon Sep 17 00:00:00 2001 From: Himanshu Agarwal Date: Wed, 9 Mar 2016 18:49:18 +0530 Subject: [PATCH] qcacmn: Add tlv formation of key installation commands in common wmi layer Move tlv formation of wmi setup key installation commands from umac to common wmi layer. Change-Id: I51250a9b1b6bb5aed06657b9f88f4659430f4c74 CRs-Fixed: 987362 --- wmi/inc/wmi_unified_api.h | 3 ++ wmi/inc/wmi_unified_param.h | 31 +++++++++++ wmi/inc/wmi_unified_priv.h | 3 ++ wmi/inc/wmi_unified_tlv.h | 3 ++ wmi/src/wmi_unified_api.c | 19 +++++++ wmi/src/wmi_unified_tlv.c | 104 ++++++++++++++++++++++++++++++++++++ 6 files changed, 163 insertions(+) diff --git a/wmi/inc/wmi_unified_api.h b/wmi/inc/wmi_unified_api.h index 58fd3e51d0..c703be5040 100644 --- a/wmi/inc/wmi_unified_api.h +++ b/wmi/inc/wmi_unified_api.h @@ -429,6 +429,9 @@ QDF_STATUS wmi_unified_probe_rsp_tmpl_send_cmd(void *wmi_hdl, struct wmi_probe_resp_params *probe_rsp_info, uint8_t *frm); +QDF_STATUS wmi_unified_setup_install_key_cmd(void *wmi_hdl, + struct set_key_params *key_params); + QDF_STATUS wmi_unified_p2p_go_set_beacon_ie_cmd(void *wmi_hdl, A_UINT32 vdev_id, uint8_t *p2p_ie); diff --git a/wmi/inc/wmi_unified_param.h b/wmi/inc/wmi_unified_param.h index 1644fe8213..3bc4e84540 100644 --- a/wmi/inc/wmi_unified_param.h +++ b/wmi/inc/wmi_unified_param.h @@ -61,6 +61,7 @@ #define WMI_IPV4_ADDR_LEN 4 #define WMI_KEEP_ALIVE_NULL_PKT 1 #define WMI_KEEP_ALIVE_UNSOLICIT_ARP_RSP 2 +#define WMI_MAC_MAX_KEY_LENGTH 32 #define WMI_KRK_KEY_LEN 16 #ifdef WLAN_FEATURE_ROAM_OFFLOAD #define WMI_BTK_KEY_LEN 32 @@ -856,6 +857,36 @@ struct wmi_probe_resp_params { uint32_t ucProxyProbeReqValidIEBmap[8]; }; +/* struct set_key_params: structure containing + * installation key parameters + * @vdev_id: vdev id + * @key_len: key length + * @key_idx: key index + * @peer_mac: peer mac address + * @key_flags: key flags, 0:pairwise key, 1:group key, 2:static key + * @key_cipher: key cipher based on security mode + * @key_txmic_len: tx mic length + * @key_rxmic_len: rx mic length + * @rx_iv: receive IV, applicable only in case of WAPI + * @tx_iv: transmit IV, applicable only in case of WAPI + * @key_data: key data + */ +struct set_key_params { + uint8_t vdev_id; + uint16_t key_len; + uint32_t key_idx; + uint8_t peer_mac[IEEE80211_ADDR_LEN]; + uint32_t key_flags; + uint32_t key_cipher; + uint32_t key_txmic_len; + uint32_t key_rxmic_len; +#ifdef FEATURE_WLAN_WAPI + uint8_t rx_iv[16]; + uint8_t tx_iv[16]; +#endif + uint8_t key_data[WMI_MAC_MAX_KEY_LENGTH]; +}; + /** * struct sta_params - sta keep alive parameters * @vdev_id: vdev id diff --git a/wmi/inc/wmi_unified_priv.h b/wmi/inc/wmi_unified_priv.h index 55fd7bee86..2a25b63c20 100644 --- a/wmi/inc/wmi_unified_priv.h +++ b/wmi/inc/wmi_unified_priv.h @@ -248,6 +248,9 @@ QDF_STATUS (*send_probe_rsp_tmpl_send_cmd)(wmi_unified_t wmi_handle, struct wmi_probe_resp_params *probe_rsp_info, uint8_t *frm); +QDF_STATUS (*send_setup_install_key_cmd)(wmi_unified_t wmi_handle, + struct set_key_params *key_params); + QDF_STATUS (*send_process_update_edca_param_cmd)(wmi_unified_t wmi_handle, uint8_t vdev_id, wmi_wmm_vparams gwmm_param[WMI_MAX_NUM_AC]); diff --git a/wmi/inc/wmi_unified_tlv.h b/wmi/inc/wmi_unified_tlv.h index 43acf781df..f9dbed0460 100644 --- a/wmi/inc/wmi_unified_tlv.h +++ b/wmi/inc/wmi_unified_tlv.h @@ -210,6 +210,9 @@ QDF_STATUS send_probe_rsp_tmpl_send_cmd_tlv(wmi_unified_t wmi_handle, struct wmi_probe_resp_params *probe_rsp_info, uint8_t *frm); +QDF_STATUS send_setup_install_key_cmd_tlv(wmi_unified_t wmi_handle, + struct set_key_params *key_params); + QDF_STATUS send_process_update_edca_param_cmd_tlv(wmi_unified_t wmi_handle, uint8_t vdev_id, wmi_wmm_vparams gwmm_param[WMI_MAX_NUM_AC]); diff --git a/wmi/src/wmi_unified_api.c b/wmi/src/wmi_unified_api.c index f775128601..78c01876b1 100644 --- a/wmi/src/wmi_unified_api.c +++ b/wmi/src/wmi_unified_api.c @@ -1209,6 +1209,25 @@ QDF_STATUS wmi_unified_probe_rsp_tmpl_send_cmd(void *wmi_hdl, return QDF_STATUS_E_FAILURE; } +/** + * wmi_unified_setup_install_key_cmd - send key to install to fw + * @wmi_hdl: wmi handle + * @key_params: key parameters + * + * Return: 0 for success or error code + */ +QDF_STATUS wmi_unified_setup_install_key_cmd(void *wmi_hdl, + struct set_key_params *key_params) +{ + wmi_unified_t wmi_handle = (wmi_unified_t) wmi_hdl; + + if (wmi_handle->ops->send_setup_install_key_cmd) + return wmi_handle->ops->send_setup_install_key_cmd(wmi_handle, + key_params); + + return QDF_STATUS_E_FAILURE; +} + /** * wmi_unified_p2p_go_set_beacon_ie_cmd() - set beacon IE for p2p go * @wma_handle: wma handle diff --git a/wmi/src/wmi_unified_tlv.c b/wmi/src/wmi_unified_tlv.c index 1527310eb1..4e2d6997a6 100644 --- a/wmi/src/wmi_unified_tlv.c +++ b/wmi/src/wmi_unified_tlv.c @@ -3377,6 +3377,108 @@ QDF_STATUS send_probe_rsp_tmpl_send_cmd_tlv(wmi_unified_t wmi_handle, return ret; } +#ifdef FEATURE_WLAN_WAPI +#define WPI_IV_LEN 16 + +/** + * wmi_update_wpi_key_counter() - update WAPI tsc and rsc key counters + * + * @dest_tx: destination address of tsc key counter + * @src_tx: source address of tsc key counter + * @dest_rx: destination address of rsc key counter + * @src_rx: source address of rsc key counter + * + * This function copies WAPI tsc and rsc key counters in the wmi buffer. + * + * Return: None + * + */ +static void wmi_update_wpi_key_counter(uint8_t *dest_tx, uint8_t *src_tx, + uint8_t *dest_rx, uint8_t *src_rx) +{ + qdf_mem_copy(dest_tx, src_tx, WPI_IV_LEN); + qdf_mem_copy(dest_rx, src_rx, WPI_IV_LEN); +} +#else +static void wmi_update_wpi_key_counter(uint8_t *dest_tx, uint8_t *src_tx, + uint8_t *dest_rx, uint8_t *src_rx) +{ + return; +} +#endif + +/** + * send_setup_install_key_cmd_tlv() - set key parameters + * @wmi_handle: wmi handle + * @key_params: key parameters + * + * This function fills structure from information + * passed in key_params. + * + * Return: QDF_STATUS_SUCCESS - success + * QDF_STATUS_E_FAILURE - failure + * QDF_STATUS_E_NOMEM - not able to allocate buffer + */ +QDF_STATUS send_setup_install_key_cmd_tlv(wmi_unified_t wmi_handle, + struct set_key_params *key_params) +{ + wmi_vdev_install_key_cmd_fixed_param *cmd; + wmi_buf_t buf; + uint8_t *buf_ptr; + uint32_t len; + uint8_t *key_data; + uint8_t status; + + len = sizeof(*cmd) + roundup(key_params->key_len, sizeof(uint32_t)) + + WMI_TLV_HDR_SIZE; + + buf = wmi_buf_alloc(wmi_handle, len); + if (!buf) { + WMA_LOGE("Failed to allocate buffer to send set key cmd"); + return QDF_STATUS_E_NOMEM; + } + + buf_ptr = (uint8_t *) wmi_buf_data(buf); + cmd = (wmi_vdev_install_key_cmd_fixed_param *) buf_ptr; + WMITLV_SET_HDR(&cmd->tlv_header, + WMITLV_TAG_STRUC_wmi_vdev_install_key_cmd_fixed_param, + WMITLV_GET_STRUCT_TLVLEN + (wmi_vdev_install_key_cmd_fixed_param)); + cmd->vdev_id = key_params->vdev_id; + cmd->key_ix = key_params->key_idx; + WMI_CHAR_ARRAY_TO_MAC_ADDR(key_params->peer_mac, &cmd->peer_macaddr); + cmd->key_flags |= key_params->key_flags; + cmd->key_cipher = key_params->key_cipher; + if ((key_params->key_txmic_len) && + (key_params->key_rxmic_len)) { + cmd->key_txmic_len = key_params->key_txmic_len; + cmd->key_rxmic_len = key_params->key_rxmic_len; + } + + wmi_update_wpi_key_counter(cmd->wpi_key_tsc_counter, + key_params->tx_iv, + cmd->wpi_key_rsc_counter, + key_params->rx_iv); + + buf_ptr += sizeof(wmi_vdev_install_key_cmd_fixed_param); + WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, + roundup(key_params->key_len, sizeof(uint32_t))); + key_data = (A_UINT8 *) (buf_ptr + WMI_TLV_HDR_SIZE); + qdf_mem_copy((void *)key_data, + (const void *)key_params->key_data, key_params->key_len); + cmd->key_len = key_params->key_len; + + status = wmi_unified_cmd_send(wmi_handle, buf, len, + WMI_VDEV_INSTALL_KEY_CMDID); + if (status) { + qdf_nbuf_free(buf); + return QDF_STATUS_E_FAILURE; + } + + return QDF_STATUS_SUCCESS; +} + + /** * send_p2p_go_set_beacon_ie_cmd_tlv() - set beacon IE for p2p go * @wmi_handle: wmi handle @@ -10258,6 +10360,8 @@ struct wmi_ops tlv_ops = { send_probe_rsp_tmpl_send_cmd_tlv, .send_p2p_go_set_beacon_ie_cmd = send_p2p_go_set_beacon_ie_cmd_tlv, + .send_setup_install_key_cmd = + send_setup_install_key_cmd_tlv, .send_set_gateway_params_cmd = send_set_gateway_params_cmd_tlv, .send_set_rssi_monitoring_cmd =