3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

knownnetworks: refactor to expose known_network_update

known_network_update was being used to both update and create known
networks as they appeared on the file system. Hotspot needs updating
capabilities so known_network_update was exposed and updated with
one major difference; it no longer can be used to create new known
networks. For creation, a new API was added (known_network_new)
which will create and add to the queue.
This commit is contained in:
James Prestwood 2019-08-28 09:34:10 -07:00 committed by Denis Kenzior
parent a0a81c72e1
commit ab5e83014c
2 changed files with 51 additions and 32 deletions

View File

@ -240,27 +240,14 @@ bool network_info_match_nai_realm(const struct network_info *info,
return info->ops->match_nai_realms(info, nai_realms); return info->ops->match_nai_realms(info, nai_realms);
} }
static void known_network_update(struct network_info *orig_network, void known_network_update(struct network_info *network,
const char *ssid,
enum security security,
struct l_settings *settings, struct l_settings *settings,
uint64_t connected_time) uint64_t connected_time)
{ {
struct network_info *network;
bool is_hidden = false; bool is_hidden = false;
bool is_autoconnectable; bool is_autoconnectable;
if (orig_network) if (network->connected_time != connected_time) {
network = orig_network;
else {
network = l_new(struct network_info, 1);
strcpy(network->ssid, ssid);
network->type = security;
network->ops = &known_network_ops;
}
if (l_time_before(network->connected_time, connected_time) &&
orig_network) {
l_dbus_property_changed(dbus_get_bus(), l_dbus_property_changed(dbus_get_bus(),
known_network_get_path(network), known_network_get_path(network),
IWD_KNOWN_NETWORK_INTERFACE, IWD_KNOWN_NETWORK_INTERFACE,
@ -275,31 +262,26 @@ static void known_network_update(struct network_info *orig_network,
l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden); l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden);
if (network->is_hidden && orig_network) if (network->is_hidden != is_hidden) {
num_known_hidden_networks--; if (network->is_hidden && !is_hidden)
num_known_hidden_networks--;
else if (!network->is_hidden && is_hidden)
num_known_hidden_networks++;
if (network->is_hidden != is_hidden && orig_network)
l_dbus_property_changed(dbus_get_bus(), l_dbus_property_changed(dbus_get_bus(),
known_network_get_path(network), known_network_get_path(network),
IWD_KNOWN_NETWORK_INTERFACE, IWD_KNOWN_NETWORK_INTERFACE,
"Hidden"); "Hidden");
}
network->is_hidden = is_hidden; network->is_hidden = is_hidden;
if (network->is_hidden)
num_known_hidden_networks++;
if (!l_settings_get_bool(settings, "Settings", "Autoconnect", if (!l_settings_get_bool(settings, "Settings", "Autoconnect",
&is_autoconnectable)) &is_autoconnectable))
/* If no entry, default to Autoconnectable=True */ /* If no entry, default to Autoconnectable=True */
is_autoconnectable = true; is_autoconnectable = true;
known_network_set_autoconnect(network, is_autoconnectable); known_network_set_autoconnect(network, is_autoconnectable);
if (orig_network)
return;
known_networks_add(network);
} }
bool known_networks_foreach(known_networks_foreach_func_t function, bool known_networks_foreach(known_networks_foreach_func_t function,
@ -579,6 +561,37 @@ void known_networks_add(struct network_info *network)
KNOWN_NETWORKS_EVENT_ADDED, network); KNOWN_NETWORKS_EVENT_ADDED, network);
} }
static void known_network_new(const char *ssid, enum security security,
struct l_settings *settings,
uint64_t connected_time)
{
bool is_hidden;
bool is_autoconnectable;
struct network_info *network;
network = l_new(struct network_info, 1);
strcpy(network->ssid, ssid);
network->type = security;
network->connected_time = connected_time;
network->ops = &known_network_ops;
if (!l_settings_get_bool(settings, "Settings", "Hidden",
&is_hidden))
is_hidden = false;
if (!l_settings_get_bool(settings, "Settings", "Autoconnect",
&is_autoconnectable))
is_autoconnectable = true;
if (is_hidden)
num_known_hidden_networks++;
network->is_hidden = is_hidden;
network->is_autoconnectable = is_autoconnectable;
known_networks_add(network);
}
static void known_networks_watch_cb(const char *filename, static void known_networks_watch_cb(const char *filename,
enum l_dir_watch_event event, enum l_dir_watch_event event,
void *user_data) void *user_data)
@ -622,14 +635,17 @@ static void known_networks_watch_cb(const char *filename,
if (settings) { if (settings) {
connected_time = l_path_get_mtime(full_path); connected_time = l_path_get_mtime(full_path);
known_network_update(network_before, ssid, security,
settings, connected_time);
} else {
if (network_before) if (network_before)
known_networks_remove(network_before); known_network_update(network_before, settings,
} connected_time);
else
known_network_new(ssid, security, settings,
connected_time);
} else if (network_before)
known_networks_remove(network_before);
l_settings_free(settings); l_settings_free(settings);
break; break;
case L_DIR_WATCH_EVENT_ACCESSED: case L_DIR_WATCH_EVENT_ACCESSED:
break; break;
@ -846,7 +862,7 @@ static int known_networks_init(void)
if (settings) { if (settings) {
connected_time = l_path_get_mtime(full_path); connected_time = l_path_get_mtime(full_path);
known_network_update(NULL, ssid, security, settings, known_network_new(ssid, security, settings,
connected_time); connected_time);
} }

View File

@ -103,4 +103,7 @@ bool network_info_match_nai_realm(const struct network_info *info,
const char **nai_realms); const char **nai_realms);
void known_networks_add(struct network_info *info); void known_networks_add(struct network_info *info);
void known_network_update(struct network_info *info,
struct l_settings *settings,
uint64_t connected_time);
void known_networks_remove(struct network_info *info); void known_networks_remove(struct network_info *info);