@@ -82,14 +82,10 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
8282 wifi_config->sta .ssid [0 ] = 0 ;
8383 wifi_config->sta .password [0 ] = 0 ;
8484 if (ssid != NULL && ssid[0 ] != 0 ){
85- snprintf ((char *)wifi_config->sta .ssid , 32 , ssid );
85+ strncpy ((char *)wifi_config->sta .ssid , ssid, 32 );
8686 if (password != NULL && password[0 ] != 0 ){
8787 wifi_config->sta .threshold .authmode = WIFI_AUTH_WEP;
88- if (strlen (password) == 64 ){
89- memcpy ((char *)wifi_config->sta .password , password, 64 );
90- } else {
91- snprintf ((char *)wifi_config->sta .password , 64 , password);
92- }
88+ strncpy ((char *)wifi_config->sta .password , password, 64 );
9389 }
9490 if (bssid != NULL ){
9591 wifi_config->sta .bssid_set = 1 ;
@@ -165,15 +161,11 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
165161
166162 wifi_config_t conf;
167163 memset (&conf, 0 , sizeof (wifi_config_t ));
168- strcpy (reinterpret_cast <char *>(conf.sta .ssid ), ssid);
164+ strncpy (reinterpret_cast <char *>(conf.sta .ssid ), ssid, 32 );
169165 conf.sta .scan_method = WIFI_ALL_CHANNEL_SCAN; // force full scan to be able to choose the nearest / strongest AP
170166
171167 if (passphrase) {
172- if (strlen (passphrase) == 64 ){ // it's not a passphrase, is the PSK
173- memcpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
174- } else {
175- strcpy (reinterpret_cast <char *>(conf.sta .password ), passphrase);
176- }
168+ strncpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
177169 }
178170
179171 wifi_config_t current_conf;
@@ -370,14 +362,14 @@ bool WiFiSTAClass::getAutoReconnect()
370362 * returns the status reached or disconnect if STA is off
371363 * @return wl_status_t
372364 */
373- uint8_t WiFiSTAClass::waitForConnectResult ()
365+ uint8_t WiFiSTAClass::waitForConnectResult (unsigned long timeoutLength )
374366{
375367 // 1 and 3 have STA enabled
376368 if ((WiFiGenericClass::getMode () & WIFI_MODE_STA) == 0 ) {
377369 return WL_DISCONNECTED;
378370 }
379- int i = 0 ;
380- while ((!status () || status () >= WL_DISCONNECTED) && i++ < 100 ) {
371+ unsigned long start = millis () ;
372+ while ((!status () || status () >= WL_DISCONNECTED) && ( millis () - start) < timeoutLength ) {
381373 delay (100 );
382374 }
383375 return status ();
0 commit comments