wsc: Refactor store_credentials / try_credentials

Instead of taking the credentials from wsc object directly, have the
caller pass these in.  This makes it more consistent with how the
done_cb was done.
This commit is contained in:
Andrew Zaborowski 2019-12-19 04:50:58 +01:00 committed by Denis Kenzior
parent 25708fbb5c
commit 0f8a49501e
1 changed files with 20 additions and 19 deletions

View File

@ -113,20 +113,21 @@ static struct l_dbus_message *wsc_error_time_expired(struct l_dbus_message *msg)
"No APs in PIN mode found in " "No APs in PIN mode found in "
"the alloted time"); "the alloted time");
} }
static void wsc_try_credentials(struct wsc *wsc) static void wsc_try_credentials(struct wsc *wsc,
struct wsc_credentials_info *creds,
unsigned int n_creds)
{ {
unsigned int i; unsigned int i;
struct network *network; struct network *network;
struct scan_bss *bss; struct scan_bss *bss;
for (i = 0; i < wsc->n_creds; i++) { for (i = 0; i < n_creds; i++) {
network = station_network_find(wsc->station, network = station_network_find(wsc->station, creds[i].ssid,
wsc->creds[i].ssid, creds[i].security);
wsc->creds[i].security);
if (!network) if (!network)
continue; continue;
bss = network_bss_find_by_addr(network, wsc->creds[i].addr); bss = network_bss_find_by_addr(network, creds[i].addr);
if (!bss) if (!bss)
bss = network_bss_select(network, true); bss = network_bss_select(network, true);
@ -134,7 +135,7 @@ static void wsc_try_credentials(struct wsc *wsc)
if (!bss) if (!bss)
continue; continue;
if (wsc->creds[i].security == SECURITY_PSK) { if (creds[i].security == SECURITY_PSK) {
bool ret; bool ret;
/* /*
@ -142,12 +143,11 @@ static void wsc_try_credentials(struct wsc *wsc)
* WPA2 and WPA3 since the PSK can always be generated * WPA2 and WPA3 since the PSK can always be generated
* if needed * if needed
*/ */
if (wsc->creds[i].has_passphrase) if (creds[i].has_passphrase)
ret = network_set_passphrase(network, ret = network_set_passphrase(network,
wsc->creds[i].passphrase); creds[i].passphrase);
else else
ret = network_set_psk(network, ret = network_set_psk(network, creds[i].psk);
wsc->creds[i].psk);
if (!ret) if (!ret)
continue; continue;
@ -166,21 +166,22 @@ static void wsc_try_credentials(struct wsc *wsc)
station_set_autoconnect(wsc->station, true); station_set_autoconnect(wsc->station, true);
} }
static void wsc_store_credentials(struct wsc *wsc) static void wsc_store_credentials(struct wsc_credentials_info *creds,
unsigned int n_creds)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < wsc->n_creds; i++) { for (i = 0; i < n_creds; i++) {
enum security security = wsc->creds[i].security; enum security security = creds[i].security;
const char *ssid = wsc->creds[i].ssid; const char *ssid = creds[i].ssid;
struct l_settings *settings = l_settings_new(); struct l_settings *settings = l_settings_new();
l_debug("Storing credential for '%s(%s)'", ssid, l_debug("Storing credential for '%s(%s)'", ssid,
security_to_str(security)); security_to_str(security));
if (security == SECURITY_PSK) { if (security == SECURITY_PSK) {
char *hex = l_util_hexstring(wsc->creds[i].psk, char *hex = l_util_hexstring(creds[i].psk,
sizeof(wsc->creds[i].psk)); sizeof(creds[i].psk));
l_settings_set_value(settings, "Security", l_settings_set_value(settings, "Security",
"PreSharedKey", hex); "PreSharedKey", hex);
@ -563,8 +564,8 @@ static void wsc_dbus_done_cb(int err, struct wsc_credentials_info *creds,
return; return;
} }
wsc_store_credentials(wsc); wsc_store_credentials(creds, n_creds);
wsc_try_credentials(wsc); wsc_try_credentials(wsc, creds, n_creds);
} }
static void station_state_watch(enum station_state state, void *userdata) static void station_state_watch(enum station_state state, void *userdata)