Skip to contentSkip to conversation

ap: return error from GetDiagnostics if not started

PATCH In review James Prestwood 2 participants 7 messages Feb 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 ap: return error from GetDiagnostics if not started

---
 src/ap.c | 3 +++
 1 file changed, 3 insertions(+)
src/ap.c +3 -0
index 37dd05b9..fddf0255 100644
@@ -3200,6 +3200,9 @@ static struct l_dbus_message *ap_dbus_get_diagnostics(struct l_dbus *dbus,
 	struct diagnostic_data *data;
 	int ret;
 
+	if (!ap_if->ap)
+		return dbus_error_not_found(message);
+
 	data = l_new(struct diagnostic_data, 1);
 	data->pending = l_dbus_message_ref(message);
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/5 client: ap: handle NotFound on diagnostic interface

This can happen when 'ap <wlan> show' is used on an AP interface which has not been started. This isn't an error per-se so it should be handled and print nothing rather than print an error.

---
 client/ap.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
client/ap.c +10 -1
index 7130bb9a..9a7f8642 100644
@@ -201,9 +201,18 @@ static void ap_get_diagnostics_callback(struct l_dbus_message *message,
 	struct l_dbus_message_iter iter;
 	uint16_t idx = 0;
 	char client_num[15];
+	const char *name;
+	const char *text;
 
-	if (dbus_message_has_error(message))
+	if (l_dbus_message_get_error(message, &name, &text)) {
+		if (!strcmp(name, "net.connman.iwd.NotFound")) {
+			display_table_footer();
+			return;
+		}
+
+		display_error(text);
 		return;
+	}
 
 	if (!l_dbus_message_get_arguments(message, "aa{sv}", &array)) {
 		display("Failed to parse GetDiagnostics message");
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/5 ap: add SSID property

In reply to James Prestwood

Its useful being able to refer to the SSID once an AP is started. For example opening an iwctl session with an already started AP provides no way of obtaining the SSID.

---
 src/ap.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
src/ap.c +26 -0
index fddf0255..d58932dd 100644
@@ -2971,12 +2971,18 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 		l_dbus_property_changed(dbus_get_bus(),
 					netdev_get_path(ap_if->netdev),
 					IWD_AP_INTERFACE, "Started");
+		l_dbus_property_changed(dbus_get_bus(),
+					netdev_get_path(ap_if->netdev),
+					IWD_AP_INTERFACE, "SSID");
 		break;
 
 	case AP_EVENT_STOPPING:
 		l_dbus_property_changed(dbus_get_bus(),
 					netdev_get_path(ap_if->netdev),
 					IWD_AP_INTERFACE, "Started");
+		l_dbus_property_changed(dbus_get_bus(),
+					netdev_get_path(ap_if->netdev),
+					IWD_AP_INTERFACE, "SSID");
 
 		if (!ap_if->pending)
 			ap_if->ap = NULL;
@@ -3112,6 +3118,24 @@ static bool ap_dbus_property_get_started(struct l_dbus *dbus,
 	return true;
 }
 
+static bool ap_dbus_property_get_ssid(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct ap_if_data *ap_if = user_data;
+	const char *ssid;
+
+	if (!ap_if->ap || !ap_if->ap->config || !ap_if->ap->started)
+		ssid = "";
+	else
+		ssid = ap_if->ap->config->ssid;
+
+	l_dbus_message_builder_append_basic(builder, 's', ssid);
+
+	return true;
+}
+
 static void ap_setup_interface(struct l_dbus_interface *interface)
 {
 	l_dbus_interface_method(interface, "Start", 0, ap_dbus_start, "",
@@ -3123,6 +3147,8 @@ static void ap_setup_interface(struct l_dbus_interface *interface)
 
 	l_dbus_interface_property(interface, "Started", 0, "b",
 					ap_dbus_property_get_started, NULL);
+	l_dbus_interface_property(interface, "SSID", 0, "s",
+					ap_dbus_property_get_ssid, NULL);
 }
 
 static void ap_destroy_interface(void *user_data)
Signature · 1 line
2.26.2
#3 lore raw

PATCH 4/5 doc: document SSID property on AP interface

In reply to James Prestwood
---
 doc/access-point-api.txt | 5 +++++
 1 file changed, 5 insertions(+)
doc/access-point-api.txt +5 -0
index 9682b3c7..27f4e244 100644
@@ -40,3 +40,8 @@ Methods		void Start(string ssid, string psk)
 Properties	boolean Started [readonly]
 
 			Reflects whether an access point has been started.
+
+		string SSID [readonly]
+
+			The SSID being broadcast for a started AP. This will be
+			an empty string prior to the AP being started.
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 4/5] doc: document SSID property on AP interface

Hi James,

Quoted 9 lines · James Prestwood
---
  doc/access-point-api.txt | 5 +++++
  1 file changed, 5 insertions(+)
doc/access-point-api.txt +0 -0
index 9682b3c7..27f4e244 100644

doc/access-point-api.txt Methods void Start(string ssid, string psk) · line 44

Quoted 5 lines
doc/access-point-api.txt +2 -0
@@ -40,3 +40,8 @@ Methods		void Start(string ssid, string psk)
  Properties	boolean Started [readonly]
 
  			Reflects whether an access point has been started.
+
+		string SSID [readonly]

Do we want to call it 'Name' to be symmetrical with Network? also, [readonly, optional]

doc/access-point-api.txt Methods void Start(string ssid, string psk) · line 47

Quoted 3 lines
doc/access-point-api.txt +3 -0
+
+			The SSID being broadcast for a started AP. This will be
+			an empty string prior to the AP being started.

Ah I think we should rather omit it if the AP isn't started

Quoted 1 line

Regards,
-Denis

#5 lore raw

PATCH 5/5 client: ap: show SSID in 'ap <wlan> show'

In reply to James Prestwood

This will show some basic AP information like Started and SSID. Some cleanup was done to make the AP interface and client table columns line up.

---
 client/ap.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)
client/ap.c +36 -3
index 9a7f8642..783f1e19 100644
@@ -34,6 +34,7 @@
 
 struct ap {
 	bool started;
+	char *ssid;
 };
 
 static void *ap_create(void)
@@ -74,8 +75,35 @@ static void update_started(void *data, struct l_dbus_message_iter *variant)
 	ap->started = value;
 }
 
+static const char *get_ssid_tostr(const void *data)
+{
+	const struct ap *ap = data;
+
+	if (!ap->ssid)
+		return "";
+
+	return ap->ssid;
+}
+
+static void update_ssid(void *data, struct l_dbus_message_iter *variant)
+{
+	struct ap *ap = data;
+	const char *ssid;
+
+	if (ap->ssid)
+		l_free(ap->ssid);
+
+	if (!l_dbus_message_iter_get_variant(variant, "s", &ssid)) {
+		ap->ssid = NULL;
+		return;
+	}
+
+	ap->ssid = l_strdup(ssid);
+}
+
 static const struct proxy_interface_property ap_properties[] = {
 	{ "Started",  "b", update_started,  get_started_tostr },
+	{ "SSID",     "s", update_ssid, get_ssid_tostr },
 	{ }
 };
 
@@ -221,9 +249,9 @@ static void ap_get_diagnostics_callback(struct l_dbus_message *message,
 
 	while (l_dbus_message_iter_next_entry(&array, &iter)) {
 		sprintf(client_num, "Client %u", idx++);
-		display_table_header(client_num, "%-*s%-*s",
+		display_table_header(client_num, "            %-*s%-*s",
 					20, "Property", 20, "Value");
-		diagnostic_display(&iter, "", 20, 20);
+		diagnostic_display(&iter, "            ", 20, 20);
 		display_table_footer();
 	}
 }
@@ -232,12 +260,17 @@ static enum cmd_status cmd_show(const char *device_name, char **argv, int argc)
 {
 	const struct proxy_interface *ap_diagnostic =
 		device_proxy_find(device_name, IWD_AP_DIAGNOSTIC_INTERFACE);
+	const struct proxy_interface *ap_i =
+		device_proxy_find(device_name, IWD_ACCESS_POINT_INTERFACE);
 
-	if (!ap_diagnostic) {
+	if (!ap_diagnostic || !ap_i) {
 		display("No ap on device: '%s'\n", device_name);
 		return CMD_STATUS_INVALID_VALUE;
 	}
 
+	proxy_properties_display(ap_i, "Access Point Interface", MARGIN, 20, 20);
+	display_table_footer();
+
 	proxy_interface_method_call(ap_diagnostic, "GetDiagnostics", "",
 					ap_get_diagnostics_callback);
 
Signature · 1 line
2.26.2
#6 lore raw

Re: [PATCH 5/5] client: ap: show SSID in 'ap <wlan> show'

Quoted 12 lines · James Prestwood

This will show some basic AP information like Started and SSID. Some cleanup was done to make the AP interface and client table columns line up.

---
 client/ap.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)
client/ap.c +0 -0
index 9a7f8642..783f1e19 100644

client/ap.c line 37

Quoted 4 lines
client/ap.c +1 -0
@@ -34,6 +34,7 @@
 
 struct ap {
 	bool started;
+	char *ssid;

Looks like I forgot to free this in destroy. Will send v2 after any comments.

Thanks,
James