From 1ba2630216a2045cd203396ebb44f416d83e168f Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 28 May 2016 05:27:13 +0200 Subject: [PATCH] networks: Simplify parameters for network_seen and network_connected Only accept a struct network pointer instead of separately the ssid and security type. This is needed so we can do some more simplification in the next patch by having access to the network struct. --- src/network.c | 27 ++++++++++++++------------- src/network.h | 5 +++-- src/wiphy.c | 5 ++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/network.c b/src/network.c index 7b250316..a352111a 100644 --- a/src/network.c +++ b/src/network.c @@ -99,24 +99,24 @@ static bool network_info_match(const void *a, const void *b) return true; } -bool network_seen(uint32_t type, const char *ssid) +bool network_seen(struct network *network) { struct timespec mtim; int err; struct network_info *info; struct network_info search; - search.type = type; - strncpy(search.ssid, ssid, 32); + search.type = network->security; + strncpy(search.ssid, network->ssid, 32); search.ssid[32] = 0; info = l_queue_find(networks, network_info_match, &search); if (info) return true; - switch(type) { + switch (network->security) { case SECURITY_PSK: - err = storage_network_get_mtime("psk", ssid, &mtim); + err = storage_network_get_mtime("psk", network->ssid, &mtim); break; default: return false; @@ -126,8 +126,8 @@ bool network_seen(uint32_t type, const char *ssid) return false; info = l_new(struct network_info, 1); - info->type = type; - strncpy(info->ssid, ssid, 32); + info->type = network->security; + strncpy(info->ssid, network->ssid, 32); info->ssid[32] = 0; memcpy(&info->connected_time, &mtim, sizeof(struct timespec)); @@ -136,30 +136,31 @@ bool network_seen(uint32_t type, const char *ssid) return true; } -bool network_connected(uint32_t type, const char *ssid) +bool network_connected(struct network *network) { int err; struct network_info *info; struct network_info search; const char *strtype; - search.type = type; - strncpy(search.ssid, ssid, 32); + search.type = network->security; + strncpy(search.ssid, network->ssid, 32); search.ssid[32] = 0; info = l_queue_remove_if(networks, network_info_match, &search); if (!info) return false; - strtype = security_to_str(type); + strtype = security_to_str(network->security); if (!strtype) goto fail; - err = storage_network_touch(strtype, ssid); + err = storage_network_touch(strtype, network->ssid); if (err < 0) goto fail; - err = storage_network_get_mtime(strtype, ssid, &info->connected_time); + err = storage_network_get_mtime(strtype, network->ssid, + &info->connected_time); if (err < 0) goto fail; diff --git a/src/network.h b/src/network.h index 06fb9f1b..b6ea5677 100644 --- a/src/network.h +++ b/src/network.h @@ -23,9 +23,10 @@ #include struct netdev; +struct network; -bool network_seen(uint32_t type, const char *ssid); -bool network_connected(uint32_t type, const char *ssid); +bool network_seen(struct network *network); +bool network_connected(struct network *network); double network_rankmod(uint32_t type, const char *ssid); struct network *network_create(struct netdev *device, diff --git a/src/wiphy.c b/src/wiphy.c index da58854f..61777135 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -810,8 +810,7 @@ static void operstate_cb(bool result, void *user_data) dbus_pending_reply(&netdev->connect_pending, reply); } - network_connected(network_get_security(netdev->connected_network), - network_get_ssid(netdev->connected_network)); + network_connected(netdev->connected_network); netdev_enter_state(netdev, DEVICE_STATE_CONNECTED); } @@ -1299,7 +1298,7 @@ static void process_bss(struct netdev *netdev, struct scan_bss *bss) l_debug("Added new Network \"%s\" security %s", network_get_ssid(network), security_to_str(security)); - network_seen(security, network_get_ssid(network)); + network_seen(network); } network_bss_add(network, bss);