@@ -219,7 +219,7 @@ static bool check_ap(const struct mgos_wifi_scan_result *e,
219
219
break ;
220
220
}
221
221
// If the config specifies a particular BSSID and/or channel, check them.
222
- if (!mgos_conf_str_empty (cfg -> bssid ) && cfg -> bssid [ 0 ] != '*' ) {
222
+ if (!mgos_conf_str_empty (cfg -> bssid )) {
223
223
char bssid_s [20 ];
224
224
mgos_wifi_sta_bssid_to_str (e -> bssid , bssid_s );
225
225
if (strcasecmp (cfg -> bssid , bssid_s ) != 0 ) {
@@ -492,11 +492,11 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
492
492
for (int i = s_num_cfgs - 1 ; i >= 0 ; i -- ) {
493
493
struct mgos_config_wifi_sta * cfg = s_cfgs [i ];
494
494
if (!cfg -> enable ) continue ;
495
- if (mgos_conf_str_empty (cfg -> bssid )) continue ;
495
+ if (mgos_conf_str_empty (cfg -> last_bssid ) || cfg -> last_channel == 0 ) {
496
+ continue ;
497
+ }
496
498
uint8_t bssid [6 ];
497
- const char * bssid_s = cfg -> bssid ;
498
- if (bssid_s [0 ] == '*' ) bssid_s ++ ;
499
- if (!mgos_wifi_sta_bssid_from_str (bssid_s , bssid )) {
499
+ if (!mgos_wifi_sta_bssid_from_str (cfg -> last_bssid , bssid )) {
500
500
continue ;
501
501
}
502
502
bool found = true;
@@ -509,11 +509,7 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
509
509
ape -> cfg = cfg ;
510
510
memcpy (ape -> bssid , bssid , sizeof (ape -> bssid ));
511
511
}
512
- if (cfg -> channel >= 0 ) {
513
- ape -> channel = cfg -> channel ;
514
- } else {
515
- ape -> channel = - cfg -> channel ;
516
- }
512
+ ape -> channel = cfg -> last_channel ;
517
513
if (found ) mgos_wifi_sta_remove_history_entry (ape );
518
514
SLIST_INSERT_HEAD (& s_ap_queue , ape , next );
519
515
}
@@ -644,12 +640,8 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
644
640
s_cur_entry = NULL ;
645
641
// Reset quick connect settings for this config.
646
642
{
647
- if (!mgos_conf_str_empty (cfg -> bssid ) && cfg -> bssid [0 ] == '*' ) {
648
- mgos_conf_set_str (& cfg -> bssid , NULL );
649
- }
650
- if (ape -> cfg -> channel < 0 ) {
651
- ape -> cfg -> channel = 0 ;
652
- }
643
+ mgos_conf_set_str (& cfg -> last_bssid , NULL );
644
+ ape -> cfg -> last_channel = 0 ;
653
645
// We do not save config at this point, it will be saved when we
654
646
// eventually connect.
655
647
}
@@ -681,19 +673,25 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
681
673
s_rssi_info .samples [i ] = cur_rssi ;
682
674
}
683
675
// Save the AP that we connected to, for quick reconnect.
684
- if (ape -> channel != 0 && !BSSID_EMPTY (ape -> bssid ) &&
685
- cfg -> channel <= 0 &&
686
- (mgos_conf_str_empty (cfg -> bssid ) || cfg -> bssid [0 ] == '*' )) {
687
- char bssid_s [20 ] = {'*' };
688
- mgos_wifi_sta_bssid_to_str (ape -> bssid , bssid_s + 1 );
689
- bool changed = (- ape -> channel != cfg -> channel ||
690
- mgos_conf_str_empty (cfg -> bssid ));
691
- if (!changed ) changed = strcasecmp (cfg -> bssid , bssid_s );
676
+ if (ape -> channel != 0 && !BSSID_EMPTY (ape -> bssid )) {
677
+ char bssid_s [20 ] = {0 };
678
+ mgos_wifi_sta_bssid_to_str (ape -> bssid , bssid_s );
679
+ bool changed = (ape -> channel != cfg -> last_channel ||
680
+ mgos_conf_str_empty (cfg -> last_bssid ));
681
+ if (!changed ) changed = strcasecmp (cfg -> last_bssid , bssid_s );
692
682
if (changed ) {
693
- cfg -> channel = - ape -> channel ;
694
- mgos_conf_set_str (& cfg -> bssid , bssid_s );
695
- LOG (LL_INFO , ("Saving AP %s %s ch %d" , cfg -> ssid , bssid_s + 1 ,
696
- ape -> channel ));
683
+ mgos_conf_set_str (& cfg -> last_bssid , bssid_s );
684
+ cfg -> last_channel = ape -> channel ;
685
+ LOG (LL_INFO ,
686
+ ("Saving AP %s %s ch %d" , cfg -> ssid , bssid_s , ape -> channel ));
687
+ // Early version of this code was using bssid prefixed with '*' and
688
+ // negative channel to store quick connect values.
689
+ // This was a bad idea that broke backward compatibility,
690
+ // we no longer do this and clean up such values when possible.
691
+ if (cfg -> channel < 0 ) cfg -> channel = 0 ;
692
+ if (!mgos_conf_str_empty (cfg -> bssid ) && cfg -> bssid [0 ] == '*' ) {
693
+ mgos_conf_set_str (& cfg -> bssid , NULL );
694
+ }
697
695
mgos_sys_config_save (& mgos_sys_config , false /* try_once */ ,
698
696
NULL /* msg */ );
699
697
}
0 commit comments