@@ -234,7 +234,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
234234 if ((ssid == NULL ) ||
235235 (strlen (ssid) == 0 ) ||
236236 (pass == NULL && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
237- (strlen (pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
237+ (strlen (pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT && security != NSAPI_SECURITY_WEP )) ||
238238 (strlen (pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA ||
239239 security == NSAPI_SECURITY_WPA_WPA2 || security == NSAPI_SECURITY_WPA3 || security == NSAPI_SECURITY_WPA3_WPA2))
240240 ) {
@@ -245,7 +245,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
245245 strncpy (_ssid, ssid, sizeof (_ssid));
246246
247247 memset (_pass, 0 , sizeof (_pass));
248- strncpy (_pass, pass, sizeof (_pass));
248+ memcpy (_pass, pass, sizeof (_pass));
249249
250250 _security = security;
251251
@@ -324,15 +324,29 @@ nsapi_error_t WhdSTAInterface::connect()
324324#endif
325325 // join the network
326326 for (i = 0 ; i < MAX_RETRY_COUNT; i++) {
327- res = (whd_result_t )whd_wifi_join (_whd_emac.ifp ,
328- &ssid,
329- security,
330- (const uint8_t *)_pass, strlen (_pass));
331- if (res == WHD_SUCCESS) {
332- break ;
327+
328+ if (security != WHD_SECURITY_WEP_PSK)
329+ {
330+ res = (whd_result_t )whd_wifi_join (_whd_emac.ifp ,
331+ &ssid,
332+ security,
333+ (const uint8_t *)_pass, strlen (_pass));
334+ }
335+ else
336+ {
337+ uint8_t key_length = 0 ;
338+
339+ /* key_length = (index field + length field + _pass[1] ( length ) ) * 4 ( for key index 0, 1, 2, 3) */
340+ key_length = (_pass[1 ] + 2 )* 4 ;
341+ res = (whd_result_t )whd_wifi_join (_whd_emac.ifp ,
342+ &ssid,
343+ security,
344+ (const uint8_t *)_pass, key_length);
345+ }
346+ if (res == WHD_SUCCESS) {
347+ break ;
333348 }
334349 }
335-
336350 if (res != WHD_SUCCESS) {
337351 return whd_toerror (res);
338352 }
0 commit comments