All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH v2 1/5] station: commonize the building of diagnostic dict
Date: Thu, 21 Jan 2021 10:11:09 -0800	[thread overview]
Message-ID: <20210121181113.572092-1-prestwoj@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3872 bytes --]

AP mode will use the same structure for its diagnostic interface
and mostly the same dictionary keys. Apart from ConnectedBss and
Address being different, the remainder are the same so the
netdev_station_info to DBus dictionary conversion has been made
common so both station and AP can use it to build its diagnostic
dictionaries.
---
 src/station.c | 71 ++++++++++++++++++++++++++++++---------------------
 src/station.h |  3 +++
 2 files changed, 45 insertions(+), 29 deletions(-)

v2:
 * Generalized the dictionary building so both station and AP could
   use it.

diff --git a/src/station.c b/src/station.c
index c65fc0cc..3582ea24 100644
--- a/src/station.c
+++ b/src/station.c
@@ -3448,36 +3448,16 @@ static void station_setup_interface(struct l_dbus_interface *interface)
 					station_property_get_state, NULL);
 }
 
-static void station_destroy_interface(void *user_data)
-{
-	struct station *station = user_data;
-
-	station_free(station);
-}
-
-static void station_get_diagnostic_cb(const struct netdev_station_info *info,
-					void *user_data)
+/*
+ * Appends values from netdev_station_info into a DBus dictionary. This assumes
+ * the DBus dictionary array has already been 'entered', and expects the
+ * caller to 'leave' once called. This does not append the station address
+ * since the dictionary key name may be different depending on the caller.
+ */
+bool station_info_to_dict(const struct netdev_station_info *info,
+				struct l_dbus_message_builder *builder)
 {
-	struct station *station = user_data;
-	struct l_dbus_message *reply;
-	struct l_dbus_message_builder *builder;
-	int16_t rssi;
-
-	if (!info) {
-		reply = dbus_error_aborted(station->get_station_pending);
-		goto done;
-	}
-
-	reply = l_dbus_message_new_method_return(station->get_station_pending);
-
-	rssi = (int16_t)info->cur_rssi;
-
-	builder = l_dbus_message_builder_new(reply);
-
-	l_dbus_message_builder_enter_array(builder, "{sv}");
-
-	dbus_append_dict_basic(builder, "ConnectedBss", 's',
-					util_address_to_string(info->addr));
+	int16_t rssi = (int16_t)info->cur_rssi;
 
 	if (info->have_cur_rssi)
 		dbus_append_dict_basic(builder, "RSSI", 'n', &rssi);
@@ -3544,6 +3524,39 @@ static void station_get_diagnostic_cb(const struct netdev_station_info *info,
 		dbus_append_dict_basic(builder, "ExpectedThroughput", 'u',
 					&info->expected_throughput);
 
+	return true;
+}
+
+static void station_destroy_interface(void *user_data)
+{
+	struct station *station = user_data;
+
+	station_free(station);
+}
+
+static void station_get_diagnostic_cb(const struct netdev_station_info *info,
+					void *user_data)
+{
+	struct station *station = user_data;
+	struct l_dbus_message *reply;
+	struct l_dbus_message_builder *builder;
+
+	if (!info) {
+		reply = dbus_error_aborted(station->get_station_pending);
+		goto done;
+	}
+
+	reply = l_dbus_message_new_method_return(station->get_station_pending);
+
+	builder = l_dbus_message_builder_new(reply);
+
+	l_dbus_message_builder_enter_array(builder, "{sv}");
+
+	dbus_append_dict_basic(builder, "ConnectedBss", 's',
+					util_address_to_string(info->addr));
+
+	station_info_to_dict(info, builder);
+
 	l_dbus_message_builder_leave_array(builder);
 	l_dbus_message_builder_finalize(builder);
 	l_dbus_message_builder_destroy(builder);
diff --git a/src/station.h b/src/station.h
index c4fd505b..f6b46bd1 100644
--- a/src/station.h
+++ b/src/station.h
@@ -100,3 +100,6 @@ void station_network_foreach(struct station *station,
 				void *user_data);
 struct l_queue *station_get_bss_list(struct station *station);
 struct scan_bss *station_get_connected_bss(struct station *station);
+
+bool station_info_to_dict(const struct netdev_station_info *info,
+				struct l_dbus_message_builder *builder);
-- 
2.26.2

             reply	other threads:[~2021-01-21 18:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 18:11 James Prestwood [this message]
2021-01-21 18:11 ` [PATCH v2 2/5] ap: add AP diagnostic interface James Prestwood
2021-01-21 18:11 ` [PATCH v2 3/5] client: implement display_dictionary James Prestwood
2021-01-21 19:55   ` Denis Kenzior
2021-01-21 19:58     ` James Prestwood
2021-01-21 18:11 ` [PATCH v2 4/5] client: implement "ap <wlan> show" James Prestwood
2021-01-21 19:59   ` Denis Kenzior
2021-01-21 20:05     ` James Prestwood
2021-01-21 20:12       ` Denis Kenzior
2021-01-21 20:16         ` James Prestwood
2021-01-21 18:11 ` [PATCH v2 5/5] client: update station to use display_dictionary James Prestwood
2021-01-21 20:08 ` [PATCH v2 1/5] station: commonize the building of diagnostic dict Denis Kenzior
2021-01-21 20:10   ` James Prestwood

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=20210121181113.572092-1-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.01.org \
    /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.