From b4d634fbf20676b9ce4b5e43d15b15e4bb761d8a Mon Sep 17 00:00:00 2001 From: Kiran Kumar Lokere Date: Fri, 11 Jan 2019 18:32:32 -0800 Subject: [PATCH] qcacmn: Fix compilation issue with crypto set key Fix compilation issue with crypto set key feature. Change-Id: I82d8220a9fea1f9e48338baa74307c124c98e784 CRs-Fixed: 2381329 --- os_if/linux/crypto/inc/wlan_cfg80211_crypto.h | 12 +++--- os_if/linux/crypto/src/wlan_cfg80211_crypto.c | 37 +++++++++++-------- target_if/crypto/src/target_if_crypto.c | 33 ++++++++++++----- .../crypto/inc/wlan_crypto_global_api.h | 17 +++++---- .../crypto/inc/wlan_crypto_global_def.h | 1 + .../crypto/src/wlan_crypto_global_api.c | 4 +- .../crypto/src/wlan_crypto_ucfg_api.c | 5 ++- 7 files changed, 68 insertions(+), 41 deletions(-) diff --git a/os_if/linux/crypto/inc/wlan_cfg80211_crypto.h b/os_if/linux/crypto/inc/wlan_cfg80211_crypto.h index 6a70eb5c2839..1f4e8df2a253 100644 --- a/os_if/linux/crypto/inc/wlan_cfg80211_crypto.h +++ b/os_if/linux/crypto/inc/wlan_cfg80211_crypto.h @@ -23,7 +23,7 @@ #ifndef _WLAN_CFG80211_CRYPTO_H_ #define _WLAN_CFG80211_CRYPTO_H_ #include - +#include "wlan_crypto_global_def.h" #ifdef CONFIG_CRYPTO_COMPONENT /** * wlan_cfg80211_set_default_key() - to set the default key to be used @@ -49,24 +49,26 @@ static inline int wlan_cfg80211_set_default_key(struct wlan_objmgr_vdev *vdev, * wlan_cfg80211_store_key() - Store the key * @vdev: VDEV Object pointer * @key_index: Index to be set as the default - * @pairwise: denotes if the key is pairwise or group key + * @key_type: denotes if the key is pairwise or group key * @mac_addr: BSSID for which the key is to be set * @key_params: Params received from the kernel * * Return: Zero for success and negative for failure. */ int wlan_cfg80211_store_key(struct wlan_objmgr_vdev *vdev, - uint8_t key_index, bool pairwise, + uint8_t key_index, + enum wlan_crypto_key_type key_type, const u8 *mac_addr, struct key_params *params); /** * wlan_cfg80211_crypto_add_key() - Add key for the specified vdev * @vdev: vdev object - * @pairwise: denotes if the add key request is for pairwise or group key + * @key_type: denotes if the add key request is for pairwise or group key * @key_index: Index of the key that needs to be added * * Return: Zero on Success, negative value on failure */ -int wlan_cfg80211_crypto_add_key(struct wlan_objmgr_vdev *vdev, bool pairwise, +int wlan_cfg80211_crypto_add_key(struct wlan_objmgr_vdev *vdev, + enum wlan_crypto_key_type key_type, uint8_t key_index); #endif diff --git a/os_if/linux/crypto/src/wlan_cfg80211_crypto.c b/os_if/linux/crypto/src/wlan_cfg80211_crypto.c index 90694f43a235..697258c8f66d 100644 --- a/os_if/linux/crypto/src/wlan_cfg80211_crypto.c +++ b/os_if/linux/crypto/src/wlan_cfg80211_crypto.c @@ -28,13 +28,13 @@ #include "wlan_cfg80211_crypto.h" #include -static void wlan_cfg80211_translate_key(uint8_t key_index, bool pairwise, +static void wlan_cfg80211_translate_key(struct wlan_objmgr_vdev *vdev, + uint8_t key_index, + enum wlan_crypto_key_type key_type, const u8 *mac_addr, struct key_params *params, struct wlan_crypto_key *crypto_key) { - static const struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT; - qdf_mem_zero(crypto_key, sizeof(*crypto_key)); crypto_key->keylen = params->key_len; crypto_key->keyix = key_index; @@ -42,19 +42,25 @@ static void wlan_cfg80211_translate_key(uint8_t key_index, bool pairwise, qdf_mem_copy(&crypto_key->keyrsc[0], params->seq, params->seq_len); crypto_key->cipher_type = osif_nl_to_crypto_cipher_type(params->cipher); - if (pairwise) { - crypto_key->flags |= PAIRWISE_USAGE; - qdf_mem_copy(&crypto_key->macaddr, mac_addr, - QDF_MAC_ADDR_SIZE); + if (key_type == WLAN_CRYPTO_KEY_TYPE_UNICAST) { + qdf_mem_copy(&crypto_key->macaddr, mac_addr, QDF_MAC_ADDR_SIZE); } else { - crypto_key->flags |= GROUP_USAGE; - qdf_mem_copy(&crypto_key->macaddr, &bcast_mac, - QDF_MAC_ADDR_SIZE); + if ((vdev->vdev_mlme.vdev_opmode == QDF_STA_MODE) || + (vdev->vdev_mlme.vdev_opmode == QDF_P2P_CLIENT_MODE)) + qdf_mem_copy(&crypto_key->macaddr, mac_addr, + QDF_MAC_ADDR_SIZE); + else + qdf_mem_copy(&crypto_key->macaddr, + vdev->vdev_mlme.macaddr, + QDF_MAC_ADDR_SIZE); } + cfg80211_debug("key_type %d, opmode %d, mac %pM", key_type, + vdev->vdev_mlme.vdev_opmode, crypto_key->macaddr); } int wlan_cfg80211_store_key(struct wlan_objmgr_vdev *vdev, - uint8_t key_index, bool pairwise, + uint8_t key_index, + enum wlan_crypto_key_type key_type, const u8 *mac_addr, struct key_params *params) { struct wlan_crypto_key *crypto_key = NULL; @@ -70,7 +76,7 @@ int wlan_cfg80211_store_key(struct wlan_objmgr_vdev *vdev, cfg80211_err("Key params is NULL"); return -EINVAL; } - if (pairwise && !mac_addr) { + if ((key_type == WLAN_CRYPTO_KEY_TYPE_UNICAST) && !mac_addr) { cfg80211_err("mac_addr is NULL for pairwise Key"); return -EINVAL; } @@ -106,13 +112,14 @@ int wlan_cfg80211_store_key(struct wlan_objmgr_vdev *vdev, } } - wlan_cfg80211_translate_key(key_index, pairwise, mac_addr, + wlan_cfg80211_translate_key(vdev, key_index, key_type, mac_addr, params, crypto_key); return 0; } -int wlan_cfg80211_crypto_add_key(struct wlan_objmgr_vdev *vdev, bool pairwise, +int wlan_cfg80211_crypto_add_key(struct wlan_objmgr_vdev *vdev, + enum wlan_crypto_key_type key_type, uint8_t key_index) { struct wlan_crypto_key *crypto_key; @@ -123,7 +130,7 @@ int wlan_cfg80211_crypto_add_key(struct wlan_objmgr_vdev *vdev, bool pairwise, cfg80211_err("Crypto KEY is NULL"); return -EINVAL; } - status = ucfg_crypto_set_key_req(vdev, crypto_key, pairwise); + status = ucfg_crypto_set_key_req(vdev, crypto_key, key_type); return qdf_status_to_os_return(status); } diff --git a/target_if/crypto/src/target_if_crypto.c b/target_if/crypto/src/target_if_crypto.c index b80bc952e3cd..01c6951204f9 100644 --- a/target_if/crypto/src/target_if_crypto.c +++ b/target_if/crypto/src/target_if_crypto.c @@ -119,7 +119,7 @@ QDF_STATUS target_if_crypto_set_key(struct wlan_objmgr_vdev *vdev, uint8_t peer_id; uint8_t def_tx_idx; void *pdev_wmi_handle; - bool pairwise = false; + bool pairwise; QDF_STATUS status; pdev = wlan_vdev_get_pdev(vdev); @@ -146,11 +146,17 @@ QDF_STATUS target_if_crypto_set_key(struct wlan_objmgr_vdev *vdev, return QDF_STATUS_E_FAILURE; } - if (key_type != WLAN_CRYPTO_KEY_TYPE_UNICAST) + params.key_flags = req->flags; + if (key_type != WLAN_CRYPTO_KEY_TYPE_UNICAST) { pairwise = false; + params.key_flags |= GROUP_USAGE; + + } else { + pairwise = true; + params.key_flags |= PAIRWISE_USAGE; + } qdf_mem_copy(¶ms.key_rsc_ctr, &req->keyrsc[0], sizeof(uint64_t)); - params.key_flags = req->flags; txrx_vdev = (struct cdp_vdev *)cdp_get_vdev_from_vdev_id(soc, (struct cdp_pdev *)txrx_pdev, params.vdev_id); peer = cdp_peer_find_by_addr(soc, txrx_pdev, req->macaddr, &peer_id); @@ -160,7 +166,12 @@ QDF_STATUS target_if_crypto_set_key(struct wlan_objmgr_vdev *vdev, return QDF_STATUS_E_FAILURE; } - if (!peer) { + target_if_debug("key_type %d, mac: %02x:%02x:%02x:%02x:%02x:%02x", + key_type, req->macaddr[0], req->macaddr[1], + req->macaddr[2], req->macaddr[3], req->macaddr[4], + req->macaddr[5]); + + if ((key_type == WLAN_CRYPTO_KEY_TYPE_UNICAST) && !peer) { target_if_err("Invalid peer"); return QDF_STATUS_E_FAILURE; } @@ -190,12 +201,14 @@ QDF_STATUS target_if_crypto_set_key(struct wlan_objmgr_vdev *vdev, &req->keyval[0], req->keylen); params.key_len = req->keylen; - /* Set PN check & security type in data path */ - cdp_set_pn_check(soc, txrx_vdev, peer, sec_type, pn); - cdp_set_key(soc, peer, pairwise, - (uint32_t *)(req->keyval + - WLAN_CRYPTO_IV_SIZE + - WLAN_CRYPTO_MIC_LEN)); + if (peer) { + /* Set PN check & security type in data path */ + cdp_set_pn_check(soc, txrx_vdev, peer, sec_type, pn); + cdp_set_key(soc, peer, pairwise, (uint32_t *)(req->keyval + + WLAN_CRYPTO_IV_SIZE + WLAN_CRYPTO_MIC_LEN)); + } else { + target_if_info("peer not found"); + } target_if_debug("vdev_id:%d, key: idx:%d,len:%d", params.vdev_id, params.key_idx, params.key_len); diff --git a/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h b/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h index c9c560e82d12..ca2f55178558 100644 --- a/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h +++ b/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h @@ -684,12 +684,13 @@ static inline int omac1_aes_256(const uint8_t *key, const uint8_t *data, * ucfg_crypto_set_key_req() - Set key request to UCFG * @vdev: vdev object * @req: key request information - * @pairwise: indicates the type of key to be set, unicast or group key + * @key_type: indicates the type of key to be set, unicast or group key * * Return: None */ QDF_STATUS ucfg_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, - struct wlan_crypto_key *req, bool pairwise); + struct wlan_crypto_key *req, + enum wlan_crypto_key_type key_type); /** * wlan_crypto_get_default_key_idx() - Get the default key index @@ -766,12 +767,13 @@ struct wlan_crypto_key *wlan_crypto_get_key(struct wlan_objmgr_vdev *vdev, * wlan_crypto_set_key_req() - Set key request * @vdev: vdev object * @req: key request information - * @pairwise: indicates the type of key to be set, unicast or group key + * @key_type: indicates the type of key to be set, unicast or group key * * Return: QDF status */ QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, - struct wlan_crypto_key *req, bool pairwise); + struct wlan_crypto_key *req, + enum wlan_crypto_key_type key_type); #else static inline void wlan_crypto_update_set_key_peer( struct wlan_objmgr_vdev *vdev, @@ -794,9 +796,10 @@ wlan_crypto_get_key(struct wlan_objmgr_vdev *vdev, uint8_t key_index) return NULL; } -static inline QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, - struct wlan_crypto_key *req, - bool pairwise) +static inline +QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, + struct wlan_crypto_key *req, + enum wlan_crypto_key_type key_type) { return QDF_STATUS_SUCCESS; } diff --git a/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h b/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h index 17783bdba99a..99c2021e7185 100644 --- a/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h +++ b/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h @@ -28,6 +28,7 @@ #include "wlan_crypto_fils_def.h" #endif #include +#include #define WLAN_CRYPTO_TID_SIZE (17) #define WLAN_CRYPTO_RSC_SIZE (16) diff --git a/umac/cmn_services/crypto/src/wlan_crypto_global_api.c b/umac/cmn_services/crypto/src/wlan_crypto_global_api.c index d4af573ca26c..9be6f43249a7 100644 --- a/umac/cmn_services/crypto/src/wlan_crypto_global_api.c +++ b/umac/cmn_services/crypto/src/wlan_crypto_global_api.c @@ -4004,13 +4004,13 @@ struct wlan_crypto_key *wlan_crypto_get_key(struct wlan_objmgr_vdev *vdev, QDF_STATUS wlan_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, struct wlan_crypto_key *req, - bool pairwise) + enum wlan_crypto_key_type key_type) { struct wlan_objmgr_psoc *psoc; psoc = wlan_vdev_get_psoc(vdev); if (psoc && WLAN_CRYPTO_TX_OPS_SET_KEY(psoc)) - WLAN_CRYPTO_TX_OPS_SET_KEY(psoc)(vdev, req, pairwise); + WLAN_CRYPTO_TX_OPS_SET_KEY(psoc)(vdev, req, key_type); else return QDF_STATUS_E_FAILURE; diff --git a/umac/cmn_services/crypto/src/wlan_crypto_ucfg_api.c b/umac/cmn_services/crypto/src/wlan_crypto_ucfg_api.c index 211203aff4db..8e6e64a0c730 100644 --- a/umac/cmn_services/crypto/src/wlan_crypto_ucfg_api.c +++ b/umac/cmn_services/crypto/src/wlan_crypto_ucfg_api.c @@ -25,7 +25,8 @@ #include #include QDF_STATUS ucfg_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, - struct wlan_crypto_key *req, bool pairwise) + struct wlan_crypto_key *req, + enum wlan_crypto_key_type key_type) { /* * It is the job of dispatcher to decide whether the @@ -37,6 +38,6 @@ QDF_STATUS ucfg_crypto_set_key_req(struct wlan_objmgr_vdev *vdev, * Hence the request handler is directly called from * here. */ - return wlan_crypto_set_key_req(vdev, req, pairwise); + return wlan_crypto_set_key_req(vdev, req, key_type); }