From 23668cdf4e3b898d2d10ce2872b881909dfede1a Mon Sep 17 00:00:00 2001 From: Ashok Ponnaiah Date: Mon, 23 Apr 2018 14:22:27 +0530 Subject: [PATCH] qcacmn: Check key valid for get key api Check key valid for get key api. return key only if it is valid and return NULL is key not valid. Added new api to get key type Change-Id: Iae29366ff7d8f60e26a5a87c79119d9649c7a255 Crs-Fixed: 2204858 --- .../crypto/inc/wlan_crypto_global_api.h | 11 ++++++ .../crypto/src/wlan_crypto_global_api.c | 39 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) 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 99b151e65a62..11032982a1c3 100644 --- a/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h +++ b/umac/cmn_services/crypto/inc/wlan_crypto_global_api.h @@ -481,6 +481,17 @@ bool wlan_crypto_vdev_has_mcastcipher(struct wlan_objmgr_vdev *vdev, bool wlan_crypto_peer_has_mcastcipher(struct wlan_objmgr_peer *peer, wlan_crypto_cipher_type mcastcipher); +/** + * wlan_crypto_get_keytype - get keytype + * @key: key + * + * This function gets keytype from key + * + * Return: keytype + */ +wlan_crypto_cipher_type wlan_crypto_get_key_type( + struct wlan_crypto_key *key); + /** * wlan_crypto_vdev_getkey - get key from vdev * @vdev: vdev 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 6e32e298e080..368f60accac6 100644 --- a/umac/cmn_services/crypto/src/wlan_crypto_global_api.c +++ b/umac/cmn_services/crypto/src/wlan_crypto_global_api.c @@ -646,6 +646,23 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev, return status; } +/** + * wlan_crypto_get_keytype - get keytype + * @key: key + * + * This function gets keytype from key + * + * Return: keytype + */ +wlan_crypto_cipher_type wlan_crypto_get_key_type( + struct wlan_crypto_key *key){ + if (key && key->cipher_table) { + return ((struct wlan_crypto_cipher *) + (key->cipher_table))->cipher; + } + return WLAN_CRYPTO_CIPHER_NONE; +} +qdf_export_symbol(wlan_crypto_get_key_type); /** * wlan_crypto_vdev_getkey - get key from vdev * @vdev: vdev @@ -659,6 +676,7 @@ struct wlan_crypto_key *wlan_crypto_vdev_getkey(struct wlan_objmgr_vdev *vdev, uint16_t keyix){ struct wlan_crypto_comp_priv *crypto_priv; struct wlan_crypto_params *crypto_params; + struct wlan_crypto_key *key = NULL; crypto_params = wlan_crypto_vdev_get_comp_params(vdev, &crypto_priv); @@ -668,10 +686,16 @@ struct wlan_crypto_key *wlan_crypto_vdev_getkey(struct wlan_objmgr_vdev *vdev, } if (keyix == WLAN_CRYPTO_KEYIX_NONE || keyix >= WLAN_CRYPTO_MAXKEYIDX) - return crypto_priv->key[crypto_priv->def_tx_keyid]; + key = crypto_priv->key[crypto_priv->def_tx_keyid]; else - return crypto_priv->key[keyix]; + key = crypto_priv->key[keyix]; + + if (key && key->valid) + return key; + + return NULL; } +qdf_export_symbol(wlan_crypto_vdev_getkey); /** * wlan_crypto_peer_getkey - get key from peer @@ -686,6 +710,7 @@ struct wlan_crypto_key *wlan_crypto_peer_getkey(struct wlan_objmgr_peer *peer, uint16_t keyix){ struct wlan_crypto_comp_priv *crypto_priv; struct wlan_crypto_params *crypto_params; + struct wlan_crypto_key *key = NULL; crypto_params = wlan_crypto_peer_get_comp_params(peer, &crypto_priv); @@ -695,10 +720,16 @@ struct wlan_crypto_key *wlan_crypto_peer_getkey(struct wlan_objmgr_peer *peer, } if (keyix == WLAN_CRYPTO_KEYIX_NONE || keyix >= WLAN_CRYPTO_MAXKEYIDX) - return crypto_priv->key[crypto_priv->def_tx_keyid]; + key = crypto_priv->key[crypto_priv->def_tx_keyid]; else - return crypto_priv->key[keyix]; + key = crypto_priv->key[keyix]; + + if (key && key->valid) + return key; + + return NULL; } +qdf_export_symbol(wlan_crypto_peer_getkey); /** * wlan_crypto_getkey - called by ucfg to get key