Skip to content

Commit

Permalink
rg_network ssid and ssid0 are now the same thing
Browse files Browse the repository at this point in the history
It was confusing so now if no slot number is used in the config file, 0 is assumed.
  • Loading branch information
ducalex committed Aug 29, 2024
1 parent 99f8caf commit a6406d5
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions components/retro-go/rg_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,13 @@ bool rg_network_wifi_load_config(int slot)
#ifdef RG_ENABLE_NETWORKING
char key_ssid[16], key_password[16], key_channel[16], key_mode[16];

if (slot < -1 || slot > 999)
if (slot < 0 || slot > 9)
return false;

if (slot == -1)
{
snprintf(key_ssid, 16, "%s", SETTING_WIFI_SSID);
snprintf(key_password, 16, "%s", SETTING_WIFI_PASSWORD);
snprintf(key_channel, 16, "%s", SETTING_WIFI_CHANNEL);
snprintf(key_mode, 16, "%s", SETTING_WIFI_MODE);
}
else
{
snprintf(key_ssid, 16, "%s%d", SETTING_WIFI_SSID, slot);
snprintf(key_password, 16, "%s%d", SETTING_WIFI_PASSWORD, slot);
snprintf(key_channel, 16, "%s%d", SETTING_WIFI_CHANNEL, slot);
snprintf(key_mode, 16, "%s%d", SETTING_WIFI_MODE, slot);
}
snprintf(key_ssid, 16, "%s%d", SETTING_WIFI_SSID, slot);
snprintf(key_password, 16, "%s%d", SETTING_WIFI_PASSWORD, slot);
snprintf(key_channel, 16, "%s%d", SETTING_WIFI_CHANNEL, slot);
snprintf(key_mode, 16, "%s%d", SETTING_WIFI_MODE, slot);

RG_LOGI("Looking for '%s' (slot %d)\n", key_ssid, slot);
rg_wifi_config_t config = {0};
Expand All @@ -139,6 +129,16 @@ bool rg_network_wifi_load_config(int slot)
config.channel = rg_settings_get_number(NS_WIFI, key_channel, 0);
config.ap_mode = rg_settings_get_number(NS_WIFI, key_mode, 0);

if (!config.ssid[0] && slot == 0)
{
if ((ptr = rg_settings_get_string(NS_WIFI, SETTING_WIFI_SSID, NULL)))
memccpy(config.ssid, ptr, 0, 32), free(ptr);
if ((ptr = rg_settings_get_string(NS_WIFI, SETTING_WIFI_PASSWORD, NULL)))
memccpy(config.password, ptr, 0, 64), free(ptr);
config.channel = rg_settings_get_number(NS_WIFI, SETTING_WIFI_CHANNEL, 0);
config.ap_mode = rg_settings_get_number(NS_WIFI, SETTING_WIFI_MODE, 0);
}

if (!config.ssid[0])
return false;

Expand Down Expand Up @@ -262,10 +262,9 @@ bool rg_network_init(void)
// Tell rg_network_get_info() that we're enabled but not yet connected
network.state = RG_NETWORK_DISCONNECTED;

// We try loading the specified slot (if any), and fallback to no slot
// We try loading the specified slot (if any)
int slot = rg_settings_get_number(NS_WIFI, SETTING_WIFI_SLOT, 0);
if (!rg_network_wifi_load_config(slot) && slot != -1)
rg_network_wifi_load_config(-1);
rg_network_wifi_load_config(slot);

initialized = true;
return true;
Expand Down

0 comments on commit a6406d5

Please sign in to comment.