From 7d0e1806d4119e2db7320a166d6dc3467b318ed0 Mon Sep 17 00:00:00 2001 From: Balaji Subramanyam Date: Fri, 11 Sep 2020 11:20:42 -0700 Subject: [PATCH] WEP Security fix for Cypress Target Kits --- .../interface/WhdSTAInterface.cpp | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/connectivity/drivers/emac/TARGET_Cypress/COMPONENT_WHD/interface/WhdSTAInterface.cpp b/connectivity/drivers/emac/TARGET_Cypress/COMPONENT_WHD/interface/WhdSTAInterface.cpp index b939b340f6..af14a7e2c4 100644 --- a/connectivity/drivers/emac/TARGET_Cypress/COMPONENT_WHD/interface/WhdSTAInterface.cpp +++ b/connectivity/drivers/emac/TARGET_Cypress/COMPONENT_WHD/interface/WhdSTAInterface.cpp @@ -234,7 +234,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas if ((ssid == NULL) || (strlen(ssid) == 0) || (pass == NULL && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) || - (strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) || + (strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT && security != NSAPI_SECURITY_WEP)) || (strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2 || security == NSAPI_SECURITY_WPA3 || security == NSAPI_SECURITY_WPA3_WPA2)) ) { @@ -245,7 +245,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas strncpy(_ssid, ssid, sizeof(_ssid)); memset(_pass, 0, sizeof(_pass)); - strncpy(_pass, pass, sizeof(_pass)); + memcpy(_pass, pass, sizeof(_pass)); _security = security; @@ -324,15 +324,29 @@ nsapi_error_t WhdSTAInterface::connect() #endif // join the network for (i = 0; i < MAX_RETRY_COUNT; i++) { - res = (whd_result_t)whd_wifi_join(_whd_emac.ifp, - &ssid, - security, - (const uint8_t *)_pass, strlen(_pass)); - if (res == WHD_SUCCESS) { - break; + + if (security != WHD_SECURITY_WEP_PSK) + { + res = (whd_result_t)whd_wifi_join(_whd_emac.ifp, + &ssid, + security, + (const uint8_t *)_pass, strlen(_pass)); + } + else + { + uint8_t key_length = 0; + + /* key_length = (index field + length field + _pass[1] ( length ) ) * 4 ( for key index 0, 1, 2, 3) */ + key_length = (_pass[1] + 2 )* 4; + res = (whd_result_t)whd_wifi_join(_whd_emac.ifp, + &ssid, + security, + (const uint8_t *)_pass, key_length); + } + if (res == WHD_SUCCESS) { + break; } } - if (res != WHD_SUCCESS) { return whd_toerror(res); }