From 7a7ce957460ac5cc598068a9a26e45cbac90b1d3 Mon Sep 17 00:00:00 2001 From: David Ruth Date: Wed, 30 Nov 2022 23:33:10 +0000 Subject: [PATCH] dbus: Emit more information over D-Bus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows informing the connection manager of additional information on CQM events. Allows the connection manager to request the same information on demand by using the existing "SignalPoll" method. * Add new property "SignalChange"         * Add storage for wpa_signal_info into wpa_supplicant context           object         * Copy memory from event to context object on CQM Event * Write a common conversion method to be used by both "SignalPoll" and   this property Signed-off-by: David Ruth --- doc/dbus.doxygen | 29 +++++- wpa_supplicant/dbus/dbus_dict_helpers.c | 19 ++++ wpa_supplicant/dbus/dbus_dict_helpers.h | 4 + wpa_supplicant/dbus/dbus_new.c | 8 ++ wpa_supplicant/dbus/dbus_new.h | 1 + wpa_supplicant/dbus/dbus_new_handlers.c | 53 +++++----- wpa_supplicant/dbus/dbus_new_handlers.h | 2 + wpa_supplicant/dbus/dbus_new_helpers.c | 129 ++++++++++++++++++++++++ wpa_supplicant/dbus/dbus_new_helpers.h | 5 + wpa_supplicant/events.c | 3 + wpa_supplicant/notify.c | 6 ++ wpa_supplicant/notify.h | 1 + wpa_supplicant/wpa_supplicant_i.h | 2 + 13 files changed, 235 insertions(+), 27 deletions(-) diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen index e4819d134..3fc3146a7 100644 --- a/doc/dbus.doxygen +++ b/doc/dbus.doxygen @@ -647,6 +647,33 @@ fi.w1.wpa_supplicant1.CreateInterface. avg-rssiiAverage RSSI (dBm)No center-frq1iVHT segment 1 frequency (MHz)No center-frq2iVHT segment 2 frequency (MHz)No + rx-bytesiBytes recievedNo + tx-bytesiBytes sentNo + rx-packetsiPackets recievedNo + tx-packetsiPackets sentNo + beaconsiBeacons receivedNo + linkrxspeediLink Speed (RX, kbps)No + linktxspeediLink Speed (TX, kbps)No + retries-failediRetries (failed)No + retriesiRetriesNo + last-ack-rssiiRSSI of last ACK frame (dBm)No + fcs-errorsiFCS errorsNo + beacon-lossesiBeacons lostNo + expected-throughputiExpected Throughput (kbps)No + rx-drop-misciRX packets dropped for unspecified reasonsNo + rx-mpdusiRecieved packetsNo + rx-he-mcsiMCS index (rx, he)No + tx-he-mcsiMCS index (tx, he)No + rx-vht-mcsiMCS index (rx, vht)No + tx-vht-mcsiMCS index (tx, vht)No + rx-mcsiMCS index (rx)No + tx-mcsiMCS index (tx)No + rx-he-nssiNumber of streams (rx, he)No + tx-he-nssiNumber of streams (tx, he)No + rx-vht-nssiNumber of streams (rx, vht)No + tx-vht-nssiNumber of streams (tx, vht)No + avg-beacon-rssiiAverage Beacon RSSI (dBm)No + avg-ack-rssiiAverage ACK frame RSSI (dBm)No @@ -1244,7 +1271,7 @@ fi.w1.wpa_supplicant1.CreateInterface.

Arguments

a{sv} : properties
-
A dictionary with pairs of properties names which have changed and theirs new values. Possible dictionary keys are: "ApScan", "Scanning", "State", "CurrentBSS", "CurrentNetwork"
+
A dictionary with pairs of properties names which have changed and their new values. Possible dictionary keys are: "ApScan", "Scanning", "State", "CurrentBSS", "CurrentNetwork", "SignalChange"
diff --git a/wpa_supplicant/dbus/dbus_dict_helpers.c b/wpa_supplicant/dbus/dbus_dict_helpers.c index e4e9b8da9..0e4753450 100644 --- a/wpa_supplicant/dbus/dbus_dict_helpers.c +++ b/wpa_supplicant/dbus/dbus_dict_helpers.c @@ -298,6 +298,25 @@ dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict, } +/** + * Add a 64-bit unsigned integer entry to the dict. + * + * @param iter_dict A valid DBusMessageIter returned from + * wpa_dbus_dict_open_write() + * @param key The key of the dict item + * @param value The 64-bit unsigned integer value + * @return TRUE on success, FALSE on failure + * + */ +dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict, + const char *key, + const dbus_uint64_t value) +{ + return _wpa_dbus_add_dict_entry_basic(iter_dict, key, DBUS_TYPE_UINT64, + &value); +} + + /** * Add a DBus object path entry to the dict. * diff --git a/wpa_supplicant/dbus/dbus_dict_helpers.h b/wpa_supplicant/dbus/dbus_dict_helpers.h index 94a0efdbe..44685ea4a 100644 --- a/wpa_supplicant/dbus/dbus_dict_helpers.h +++ b/wpa_supplicant/dbus/dbus_dict_helpers.h @@ -46,6 +46,10 @@ dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict, const char *key, const dbus_uint32_t value); +dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict, + const char *key, + const dbus_uint64_t value); + dbus_bool_t wpa_dbus_dict_append_object_path(DBusMessageIter *iter_dict, const char *key, const char *value); diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index 12a2d42e5..9c23588c8 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -2347,6 +2347,9 @@ void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s, case WPAS_DBUS_PROP_MAC_ADDRESS: prop = "MACAddress"; break; + case WPAS_DBUS_PROP_SIGNAL_CHANGE: + prop = "SignalChange"; + break; default: wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d", __func__, property); @@ -4529,6 +4532,11 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = { NULL, NULL }, + { "SignalChange", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}", + wpas_dbus_getter_signal_change, + NULL, + NULL + }, { NULL, NULL, NULL, NULL, NULL, NULL } }; diff --git a/wpa_supplicant/dbus/dbus_new.h b/wpa_supplicant/dbus/dbus_new.h index 40ff9bb7d..ca8506f87 100644 --- a/wpa_supplicant/dbus/dbus_new.h +++ b/wpa_supplicant/dbus/dbus_new.h @@ -39,6 +39,7 @@ enum wpas_dbus_prop { WPAS_DBUS_PROP_SESSION_LENGTH, WPAS_DBUS_PROP_BSS_TM_STATUS, WPAS_DBUS_PROP_MAC_ADDRESS, + WPAS_DBUS_PROP_SIGNAL_CHANGE, }; enum wpas_dbus_bss_prop { diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index c2bdc513c..9a0f8c157 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1950,7 +1950,7 @@ DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message, { struct wpa_signal_info si; DBusMessage *reply = NULL; - DBusMessageIter iter, iter_dict, variant_iter; + DBusMessageIter iter; int ret; ret = wpa_drv_signal_poll(wpa_s, &si); @@ -1965,31 +1965,7 @@ DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message, dbus_message_iter_init_append(reply, &iter); - if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, - "a{sv}", &variant_iter) || - !wpa_dbus_dict_open_write(&variant_iter, &iter_dict) || - !wpa_dbus_dict_append_int32(&iter_dict, "rssi", - si.data.signal) || - !wpa_dbus_dict_append_int32(&iter_dict, "linkspeed", - si.data.current_tx_rate / 1000) || - !wpa_dbus_dict_append_int32(&iter_dict, "noise", - si.current_noise) || - !wpa_dbus_dict_append_uint32(&iter_dict, "frequency", - si.frequency) || - (si.chanwidth != CHAN_WIDTH_UNKNOWN && - !wpa_dbus_dict_append_string( - &iter_dict, "width", - channel_width_to_string(si.chanwidth))) || - (si.center_frq1 > 0 && si.center_frq2 > 0 && - (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1", - si.center_frq1) || - !wpa_dbus_dict_append_int32(&iter_dict, "center-frq2", - si.center_frq2))) || - (si.data.avg_signal && - !wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi", - si.data.avg_signal)) || - !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || - !dbus_message_iter_close_container(&iter, &variant_iter)) + if (wpas_dbus_new_from_signal_information(&iter, &si) != 0) goto nomem; return reply; @@ -6120,3 +6096,28 @@ dbus_bool_t wpas_dbus_getter_mesh_group( } #endif /* CONFIG_MESH */ + + +/** + * wpas_dbus_getter_signal_change - Get signal change + * @iter: Pointer to incoming dbus message iter + * @error: Location to store error on failure + * @user_data: Function specific data + * Returns: TRUE on success, FALSE on failure + * + * Getter for "SignalChange" property. + */ +dbus_bool_t wpas_dbus_getter_signal_change( + const struct wpa_dbus_property_desc *property_desc, + DBusMessageIter *iter, DBusError *error, void *user_data) +{ + struct wpa_supplicant *wpa_s = user_data; + struct wpa_signal_info si = wpa_s->last_signal_info; + + if (wpas_dbus_new_from_signal_information(iter, &si) != 0) { + dbus_set_error(error, DBUS_ERROR_FAILED, + "%s: error constructing reply", __func__); + return FALSE; + } + return TRUE; +} diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h index 72c36cdc6..97fa337bd 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.h +++ b/wpa_supplicant/dbus/dbus_new_handlers.h @@ -247,6 +247,8 @@ DECLARE_ACCESSOR(wpas_dbus_setter_wps_device_device_type); DECLARE_ACCESSOR(wpas_dbus_getter_mesh_peers); DECLARE_ACCESSOR(wpas_dbus_getter_mesh_group); +DECLARE_ACCESSOR(wpas_dbus_getter_signal_change); + DBusMessage * wpas_dbus_handler_tdls_discover(DBusMessage *message, struct wpa_supplicant *wpa_s); DBusMessage * wpas_dbus_handler_tdls_setup(DBusMessage *message, diff --git a/wpa_supplicant/dbus/dbus_new_helpers.c b/wpa_supplicant/dbus/dbus_new_helpers.c index d9009ba85..e21f9129f 100644 --- a/wpa_supplicant/dbus/dbus_new_helpers.c +++ b/wpa_supplicant/dbus/dbus_new_helpers.c @@ -11,6 +11,7 @@ #include "utils/common.h" #include "utils/eloop.h" +#include "drivers/driver.h" #include "dbus_common.h" #include "dbus_common_i.h" #include "dbus_new.h" @@ -1023,3 +1024,131 @@ DBusMessage * wpas_dbus_reply_new_from_error(DBusMessage *message, } return NULL; } + + +/** + * wpas_dbus_new_from_signal_information - Adds a wpa_signal_info + * to a DBusMessage. + * @msg: Pointer to message to append fields to + * @si: Pointer to wpa_signal_info to add to the message + * Returns: 0 on success, otherwise, an errorcode + * + * Adds all the pertinent fields from a wpa_signal_info to a DBusMessage. + * The same logic is useful in both responding to signal_poll calls, and + * sending signal_change signals. + */ +int wpas_dbus_new_from_signal_information(DBusMessageIter *iter, + struct wpa_signal_info *si) +{ + DBusMessageIter iter_dict, variant_iter; + + if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + "a{sv}", &variant_iter) || + !wpa_dbus_dict_open_write(&variant_iter, &iter_dict) || + !wpa_dbus_dict_append_int32(&iter_dict, "rssi", + si->data.signal) || + !wpa_dbus_dict_append_uint32(&iter_dict, "linkspeed", + si->data.current_tx_rate / 1000) || + !wpa_dbus_dict_append_int32(&iter_dict, "noise", + si->current_noise) || + !wpa_dbus_dict_append_uint32(&iter_dict, "frequency", + si->frequency) || + (si->chanwidth != CHAN_WIDTH_UNKNOWN && + !wpa_dbus_dict_append_string( + &iter_dict, "width", + channel_width_to_string(si->chanwidth))) || + (si->center_frq1 > 0 && si->center_frq2 > 0 && + (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1", + si->center_frq1) || + !wpa_dbus_dict_append_int32(&iter_dict, "center-frq2", + si->center_frq2))) || + (si->data.avg_signal && + !wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi", + si->data.avg_signal)) || + (si->data.rx_bytes && + !wpa_dbus_dict_append_uint64(&iter_dict, "rx-bytes", + si->data.rx_bytes)) || + (si->data.tx_bytes && + !wpa_dbus_dict_append_uint64(&iter_dict, "tx-bytes", + si->data.tx_bytes)) || + (si->data.rx_packets && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-packets", + si->data.rx_packets)) || + (si->data.tx_packets && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-packets", + si->data.tx_packets)) || + (si->data.beacons_count && + !wpa_dbus_dict_append_uint64(&iter_dict, "beacons", + si->data.beacons_count)) || + (si->data.current_rx_rate && + !wpa_dbus_dict_append_uint32(&iter_dict, "linkrxspeed", + si->data.current_rx_rate)) || + (si->data.current_rx_rate && + !wpa_dbus_dict_append_uint32(&iter_dict, "linktxspeed", + si->data.current_tx_rate)) || + (si->data.tx_retry_failed && + !wpa_dbus_dict_append_uint32(&iter_dict, "retries-failed", + si->data.tx_retry_failed)) || + (si->data.tx_retry_count && + !wpa_dbus_dict_append_uint32(&iter_dict, "retries", + si->data.tx_retry_count)) || + (si->data.last_ack_rssi && + !wpa_dbus_dict_append_int32(&iter_dict, "last-ack-rssi", + si->data.last_ack_rssi)) || + (si->data.fcs_error_count && + !wpa_dbus_dict_append_uint32(&iter_dict, "fcs-errors", + si->data.fcs_error_count)) || + (si->data.beacon_loss_count && + !wpa_dbus_dict_append_uint32(&iter_dict, "beacon-losses", + si->data.beacon_loss_count)) || + (si->data.expected_throughput && + !wpa_dbus_dict_append_uint32(&iter_dict, "expected-throughput", + si->data.expected_throughput)) || + (si->data.rx_drop_misc && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-drop-misc", + si->data.rx_drop_misc)) || + (si->data.rx_mpdus && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-mpdus", + si->data.rx_mpdus)) || + (si->data.rx_hemcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-he-mcs", + si->data.rx_hemcs)) || + (si->data.tx_hemcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-he-mcs", + si->data.tx_hemcs)) || + (si->data.rx_vhtmcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-vht-mcs", + si->data.rx_vhtmcs)) || + (si->data.tx_vhtmcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-vht-mcs", + si->data.tx_vhtmcs)) || + (si->data.rx_mcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-mcs", + si->data.rx_mcs)) || + (si->data.tx_mcs && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-mcs", + si->data.tx_mcs)) || + (si->data.rx_he_nss && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-he-nss", + si->data.rx_he_nss)) || + (si->data.tx_he_nss && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-he-nss", + si->data.tx_he_nss)) || + (si->data.rx_vht_nss && + !wpa_dbus_dict_append_uint32(&iter_dict, "rx-vht-nss", + si->data.rx_vht_nss)) || + (si->data.tx_vht_nss && + !wpa_dbus_dict_append_uint32(&iter_dict, "tx-vht-nss", + si->data.tx_vht_nss)) || + (si->data.avg_beacon_signal && + !wpa_dbus_dict_append_int32(&iter_dict, "avg-beacon-rssi", + si->data.avg_beacon_signal)) || + (si->data.avg_ack_signal && + !wpa_dbus_dict_append_int32(&iter_dict, "avg-ack-rssi", + si->data.avg_ack_signal)) || + !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || + !dbus_message_iter_close_container(iter, &variant_iter)) + return -ENOMEM; + + return 0; +} diff --git a/wpa_supplicant/dbus/dbus_new_helpers.h b/wpa_supplicant/dbus/dbus_new_helpers.h index 7b63b28d7..c8d44a00b 100644 --- a/wpa_supplicant/dbus/dbus_new_helpers.h +++ b/wpa_supplicant/dbus/dbus_new_helpers.h @@ -12,6 +12,8 @@ #include +struct wpa_signal_info; + typedef DBusMessage * (*WPADBusMethodHandler)(DBusMessage *message, void *user_data); typedef void (*WPADBusArgumentFreeFunction)(void *handler_arg); @@ -151,4 +153,7 @@ DBusMessage *wpas_dbus_reply_new_from_error(DBusMessage *message, const char *fallback_name, const char *fallback_string); +int wpas_dbus_new_from_signal_information(DBusMessageIter *iter, + struct wpa_signal_info *si); + #endif /* WPA_DBUS_CTRL_H */ diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 1f2006188..769663c5d 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -5781,6 +5781,9 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, data->signal_change.data.signal, data->signal_change.current_noise, data->signal_change.data.current_tx_rate); + os_memcpy(&wpa_s->last_signal_info, data, + sizeof(struct wpa_signal_info)); + wpas_notify_signal_change(wpa_s); break; case EVENT_INTERFACE_MAC_CHANGED: wpa_supplicant_update_mac_addr(wpa_s); diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c index a0f70d640..d8a64327c 100644 --- a/wpa_supplicant/notify.c +++ b/wpa_supplicant/notify.c @@ -993,3 +993,9 @@ void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s, { /* TODO: Notify external entities of the added PMKSA cache entry */ } + + +void wpas_notify_signal_change(struct wpa_supplicant *wpa_s) +{ + wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SIGNAL_CHANGE); +} diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h index a3349a061..78ae4bcb1 100644 --- a/wpa_supplicant/notify.h +++ b/wpa_supplicant/notify.h @@ -167,5 +167,6 @@ void wpas_notify_interworking_ap_added(struct wpa_supplicant *wpa_s, void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s); void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s, struct rsn_pmksa_cache_entry *entry); +void wpas_notify_signal_change(struct wpa_supplicant *wpa_s); #endif /* NOTIFY_H */ diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 0cc8633ee..f5c44115c 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -1523,6 +1523,8 @@ struct wpa_supplicant { unsigned int enable_dscp_policy_capa:1; unsigned int connection_dscp:1; unsigned int wait_for_dscp_req:1; + + struct wpa_signal_info last_signal_info; };