All of lore.kernel.org
 help / color / mirror / Atom feed
From: "VAUTRIN Emmanuel (Canal Plus Prestataire)" <Emmanuel.VAUTRIN@cpexterne.org>
To: "connman@lists.linux.dev" <connman@lists.linux.dev>
Subject: [PATCH 1/3] iwd: Scan hidden networks
Date: Fri, 1 Oct 2021 15:26:03 +0000	[thread overview]
Message-ID: <MRZP264MB154441C6059B4972B76730FF93AB9@MRZP264MB1544.FRAP264.PROD.OUTLOOK.COM> (raw)

Only visible networks were retrieved by a scan, via GetOrderedNetworks()
iwd function. A call to GetHiddenAccessPoints() is necessary to
retrieve the hidden ones.
---
 plugins/iwd.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 140 insertions(+), 1 deletion(-)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index ec9a4574cf2d..00578f4d4ab3 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -113,12 +113,22 @@ struct iwd_known_network {
 	bool autoconnect;
 };
 
+struct iwd_hidden_ap {
+	char *path;
+	char *device;
+	char *address;
+	char *type;
+	int16_t signal_strength;
+};
+
 struct iwd_station {
 	GDBusProxy *proxy;
 	char *path;
 	char *state;
 	char *connected_network;
 	bool scanning;
+
+	GHashTable *hidden_aps;
 };
 
 struct iwd_ap {
@@ -926,7 +936,8 @@ static void add_network(const char *path, struct iwd_network *iwdn)
 	connman_network_set_data(iwdn->network, iwdn);
 
 	connman_network_set_name(iwdn->network, iwdn->name);
-	connman_network_set_blob(iwdn->network, "WiFi.SSID", iwdn->name,
+	if (iwdn->name)
+		connman_network_set_blob(iwdn->network, "WiFi.SSID", iwdn->name,
 					strlen(iwdn->name));
 	connman_network_set_string(iwdn->network, "WiFi.Security",
 					security_remap(iwdn->type));
@@ -1189,6 +1200,113 @@ static void update_signal_strength(struct iwd_station *iwds)
 		DBG("GetOrderedNetworks() failed");
 }
 
+static void create_hidden_network(struct iwd_hidden_ap *iwdh)
+{
+	struct iwd_network *iwdn;
+
+	iwdn = g_try_new0(struct iwd_network, 1);
+	if (!iwdn) {
+		connman_error("Out of memory creating IWD network");
+		return;
+	}
+
+	iwdn->proxy = NULL;
+	iwdn->path = g_strdup(iwdh->path);
+	iwdn->device = g_strdup(iwdh->device);
+	iwdn->name = NULL;
+	iwdn->type = g_strdup(iwdh->type);
+	iwdn->connected = false;
+	iwdn->known_network = NULL;
+
+	DBG("device %s type %s",
+		iwdn->device, iwdn->type);
+
+	g_hash_table_replace(networks, iwdn->path, iwdn);
+
+	add_network(iwdn->path, iwdn);
+
+	_update_signal_strength(iwdn->path, iwdh->signal_strength);
+}
+
+static void create_hidden_ap(char *path, DBusMessageIter *array)
+{
+	struct iwd_hidden_ap *iwdh;
+	const char *address, *type;
+	struct iwd_station *iwds;
+	int16_t signal_strength;
+	DBusMessageIter value;
+
+	dbus_message_iter_recurse(array, &value);
+
+	dbus_message_iter_get_basic(&value, &address);
+
+	dbus_message_iter_next(&value);
+	dbus_message_iter_get_basic(&value, &signal_strength);
+
+	dbus_message_iter_next(&value);
+	dbus_message_iter_get_basic(&value, &type);
+
+	dbus_message_iter_next(array);
+
+	DBG("device '%s' address '%s' type %s signal_strength %d",
+		path, address, type, signal_strength);
+
+	iwds = g_hash_table_lookup(stations, path);
+	if (!iwds) {
+		connman_error("Related IWD station not found %s", path);
+		return;
+	}
+
+	iwdh = g_try_new0(struct iwd_hidden_ap, 1);
+	if (!iwdh) {
+		connman_error("Out of memory creating IWD hidden ap");
+		return;
+	}
+
+	iwdh->device = g_strdup(path);
+	iwdh->type = g_strdup(type);
+	iwdh->path = g_strdup_printf("%s/hidden_%s", iwdh->device, iwdh->type);
+	iwdh->address = g_strdup(address);
+	iwdh->signal_strength = signal_strength;
+
+	g_hash_table_replace(iwds->hidden_aps, iwdh->path, iwdh);
+
+	create_hidden_network(iwdh);
+}
+
+static void hidden_access_points_cb(DBusMessage *message, void *user_data)
+{
+	DBusMessageIter array, entry;
+	struct iwd_station *iwds;
+	char *path = user_data;
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &array))
+		return;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		return;
+
+	iwds = g_hash_table_lookup(stations, path);
+	if (iwds)
+		g_hash_table_remove_all(iwds->hidden_aps);
+
+	dbus_message_iter_recurse(&array, &entry);
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRUCT) {
+		create_hidden_ap(path, &entry);
+	}
+}
+
+static void update_hidden_networks(struct iwd_station *iwds)
+{
+	if (!g_dbus_proxy_method_call(iwds->proxy,
+					"GetHiddenAccessPoints",
+					NULL, hidden_access_points_cb,
+					g_strdup(iwds->path), g_free))
+		DBG("GetHiddenAccessPoints() failed");
+}
+
 static void station_property_change(GDBusProxy *proxy, const char *name,
 		DBusMessageIter *iter, void *user_data)
 {
@@ -1234,6 +1352,7 @@ static void station_property_change(GDBusProxy *proxy, const char *name,
 					CONNMAN_SERVICE_TYPE_WIFI, true);
 		} else {
 			update_signal_strength(iwds);
+			update_hidden_networks(iwds);
 		}
 
 
@@ -1354,9 +1473,26 @@ static void station_free(gpointer data)
 	}
 	g_free(iwds->path);
 	g_free(iwds->connected_network);
+	g_hash_table_destroy(iwds->hidden_aps);
 	g_free(iwds);
 }
 
+static void hidden_ap_free(gpointer data)
+{
+	struct iwd_hidden_ap *iwdh = data;
+	struct iwd_network *iwdn;
+
+	iwdn = g_hash_table_lookup(networks, iwdh->path);
+	if (iwdn)
+		remove_network(iwdn);
+
+	g_free(iwdh->path);
+	g_free(iwdh->device);
+	g_free(iwdh->address);
+	g_free(iwdh->type);
+	g_free(iwdh);
+}
+
 static void ap_free(gpointer data)
 {
 	struct iwd_ap *iwdap = data;
@@ -1717,6 +1853,9 @@ static void create_station(GDBusProxy *proxy)
 	iwds->connected_network = g_strdup(proxy_get_string(proxy, "ConnectedNetwork"));
 	iwds->scanning = proxy_get_bool(proxy, "Scanning");
 
+	iwds->hidden_aps = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+			hidden_ap_free);
+
 	DBG("state '%s' connected_network %s scanning %d",
 		iwds->state, iwds->connected_network, iwds->scanning);
 
-- 
2.25.1


             reply	other threads:[~2021-10-01 15:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 15:26 VAUTRIN Emmanuel (Canal Plus Prestataire) [this message]
2021-10-04  6:43 ` [PATCH 1/3] iwd: Scan hidden networks Daniel Wagner
2021-10-04  8:18   ` VAUTRIN Emmanuel (Canal Plus Prestataire)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MRZP264MB154441C6059B4972B76730FF93AB9@MRZP264MB1544.FRAP264.PROD.OUTLOOK.COM \
    --to=emmanuel.vautrin@cpexterne.org \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.