@@ -234,7 +234,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
234
234
if ((ssid == NULL ) ||
235
235
(strlen (ssid) == 0 ) ||
236
236
(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 )) ||
238
238
(strlen (pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA ||
239
239
security == NSAPI_SECURITY_WPA_WPA2 || security == NSAPI_SECURITY_WPA3 || security == NSAPI_SECURITY_WPA3_WPA2))
240
240
) {
@@ -245,7 +245,7 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
245
245
strncpy (_ssid, ssid, sizeof (_ssid));
246
246
247
247
memset (_pass, 0 , sizeof (_pass));
248
- strncpy (_pass, pass, sizeof (_pass));
248
+ memcpy (_pass, pass, sizeof (_pass));
249
249
250
250
_security = security;
251
251
@@ -324,15 +324,29 @@ nsapi_error_t WhdSTAInterface::connect()
324
324
#endif
325
325
// join the network
326
326
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 ;
333
348
}
334
349
}
335
-
336
350
if (res != WHD_SUCCESS) {
337
351
return whd_toerror (res);
338
352
}
0 commit comments