From patchwork Wed Sep 10 17:34:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 387910 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E94751400D5 for ; Thu, 11 Sep 2014 03:35:17 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 90D1C17C0F2; Wed, 10 Sep 2014 13:35:14 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uHEkQBgDqsvW; Wed, 10 Sep 2014 13:35:14 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 9C98F17C0F7; Wed, 10 Sep 2014 13:35:08 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 91F519D2A3 for ; Wed, 10 Sep 2014 13:35:06 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vYuSCK9YIw33 for ; Wed, 10 Sep 2014 13:34:59 -0400 (EDT) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx1.redhat.com", Issuer "DigiCert SHA2 Extended Validation Server CA" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 9E22517C0F2 for ; Wed, 10 Sep 2014 13:34:59 -0400 (EDT) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8AHYvqn019998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Sep 2014 13:34:57 -0400 Received: from [10.3.227.200] (vpn-227-200.phx2.redhat.com [10.3.227.200]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8AHYuGT021487; Wed, 10 Sep 2014 13:34:57 -0400 Message-ID: <1410370496.3399.1.camel@dcbw.local> Subject: [PATCH v2] dbus: add SignalPoll() method to report current signal properties From: Dan Williams To: hostap@lists.shmoo.com Date: Wed, 10 Sep 2014 12:34:56 -0500 In-Reply-To: <1408392036.25041.3.camel@dcbw.local> References: <1408392036.25041.3.camel@dcbw.local> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Cc: Jouni Malinen X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com Analogous to the control interface's SIGNAL_POLL request. Signed-hostap: Dan Williams --- src/drivers/driver.h | 3 ++ src/drivers/driver_common.c | 20 ++++++++ wpa_supplicant/ctrl_iface.c | 26 +---------- wpa_supplicant/dbus/dbus_new.c | 7 +++ wpa_supplicant/dbus/dbus_new_handlers.c | 81 +++++++++++++++++++++++++++++++++ wpa_supplicant/dbus/dbus_new_handlers.h | 3 ++ 6 files changed, 116 insertions(+), 24 deletions(-) diff --git a/src/drivers/driver.h b/src/drivers/driver.h index 352c163..f24660e 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -4168,11 +4168,14 @@ static inline void drv_event_eapol_rx(void *ctx, const u8 *src, const u8 *data, /* driver_common.c */ void wpa_scan_results_free(struct wpa_scan_results *res); /* Convert wpa_event_type to a string for logging */ const char * event_to_string(enum wpa_event_type event); +/* Convert chan_width to a string for logging and control interfaces */ +const char * channel_width_to_string(enum chan_width width); + /* NULL terminated array of linked in driver wrappers */ extern struct wpa_driver_ops *wpa_drivers[]; #endif /* DRIVER_H */ diff --git a/src/drivers/driver_common.c b/src/drivers/driver_common.c index 3058cd5..4b580cc 100644 --- a/src/drivers/driver_common.c +++ b/src/drivers/driver_common.c @@ -80,7 +80,27 @@ const char * event_to_string(enum wpa_event_type event) E2S(SCAN_STARTED); E2S(AVOID_FREQUENCIES); } return "UNKNOWN"; #undef E2S } + +const char * channel_width_to_string(enum chan_width width) +{ + switch (width) { + case CHAN_WIDTH_20_NOHT: + return "20 MHz (no HT)"; + case CHAN_WIDTH_20: + return "20 MHz"; + case CHAN_WIDTH_40: + return "40 MHz"; + case CHAN_WIDTH_80: + return "80 MHz"; + case CHAN_WIDTH_80P80: + return "80+80 MHz"; + case CHAN_WIDTH_160: + return "160 MHz"; + default: + return "unknown"; + } +} diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index f612b49..dd77ba9 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -37,14 +37,15 @@ #include "scan.h" #include "ctrl_iface.h" #include "interworking.h" #include "blacklist.h" #include "autoscan.h" #include "wnm_sta.h" #include "offchannel.h" +#include "drivers/driver.h" static int wpa_supplicant_global_iface_list(struct wpa_global *global, char *buf, int len); static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, char *buf, int len); static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val); @@ -5533,37 +5534,14 @@ static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd query_reason); return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason); } #endif /* CONFIG_WNM */ - -/* Get string representation of channel width */ -static const char * channel_width_name(enum chan_width width) -{ - switch (width) { - case CHAN_WIDTH_20_NOHT: - return "20 MHz (no HT)"; - case CHAN_WIDTH_20: - return "20 MHz"; - case CHAN_WIDTH_40: - return "40 MHz"; - case CHAN_WIDTH_80: - return "80 MHz"; - case CHAN_WIDTH_80P80: - return "80+80 MHz"; - case CHAN_WIDTH_160: - return "160 MHz"; - default: - return "unknown"; - } -} - - static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, size_t buflen) { struct wpa_signal_info si; int ret; char *pos, *end; @@ -5580,15 +5558,15 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, si.current_noise, si.frequency); if (ret < 0 || ret > end - pos) return -1; pos += ret; if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", - channel_width_name(si.chanwidth)); + channel_width_to_string(si.chanwidth)); if (ret < 0 || ret > end - pos) return -1; pos += ret; } if (si.center_frq1 > 0 && si.center_frq2 > 0) { ret = os_snprintf(pos, end - pos, diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index ab20961..73b1aea 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -2521,14 +2521,21 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = { { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE, (WPADBusMethodHandler) &wpas_dbus_handler_scan, { { "args", "a{sv}", ARG_IN }, END_ARGS } }, + { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE, + (WPADBusMethodHandler) &wpas_dbus_handler_signal_poll, + { + { "args", "a{sv}", ARG_OUT }, + END_ARGS + } + }, { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE, (WPADBusMethodHandler) &wpas_dbus_handler_disconnect, { END_ARGS } }, { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index b7d88b4..db5bba8 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -23,14 +23,15 @@ #include "../scan.h" #include "../autoscan.h" #include "dbus_new_helpers.h" #include "dbus_new.h" #include "dbus_new_handlers.h" #include "dbus_dict_helpers.h" #include "dbus_common_i.h" +#include "drivers/driver.h" static const char *debug_strings[] = { "excessive", "msgdump", "debug", "info", "warning", "error", NULL }; /** @@ -1396,14 +1397,94 @@ out: for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++) os_free((u8 *) params.ssids[i].ssid); os_free((u8 *) params.extra_ies); os_free(params.freqs); return reply; } +/** + * wpas_dbus_handler_signal_poll - Request immediate signal properties + * @message: Pointer to incoming dbus message + * @wpa_s: wpa_supplicant structure for a network interface + * Returns: NULL indicating success or DBus error message on failure + * + * Handler function for "SignalPoll" method call of a network device. Requests + * that wpa_supplicant read signal properties like RSSI, noise, and link + * speed and return them. + */ +DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message, + struct wpa_supplicant *wpa_s) +{ + struct wpa_signal_info si; + DBusMessage *reply = NULL; + DBusMessageIter iter, iter_dict, variant_iter; + int ret; + + ret = wpa_drv_signal_poll(wpa_s, &si); + if (ret) { + return dbus_message_new_error(message, DBUS_ERROR_FAILED, + "Failed to read signal"); + } + + reply = dbus_message_new_method_return(message); + if (reply == NULL) + goto nomem; + + dbus_message_iter_init_append(reply, &iter); + + if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, + "a{sv}", &variant_iter)) + goto nomem; + if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict)) + goto nomem; + + if (!wpa_dbus_dict_append_int32(&iter_dict, "rssi", si.current_signal)) + goto nomem; + if (!wpa_dbus_dict_append_int32(&iter_dict, "linkspeed", + si.current_txrate / 1000)) + goto nomem; + if (!wpa_dbus_dict_append_int32(&iter_dict, "noise", si.current_noise)) + goto nomem; + if (!wpa_dbus_dict_append_uint32(&iter_dict, "frequency", si.frequency)) + goto nomem; + + if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { + if (!wpa_dbus_dict_append_string(&iter_dict, "width", + channel_width_to_string(si.chanwidth))) + goto nomem; + } + + if (si.center_frq1 > 0 && si.center_frq2 > 0) { + if (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1", + si.center_frq1)) + goto nomem; + if (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq2", + si.center_frq2)) + goto nomem; + } + + if (si.avg_signal) { + if (!wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi", + si.avg_signal)) + goto nomem; + } + + if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict)) + goto nomem; + if (!dbus_message_iter_close_container(&iter, &variant_iter)) + goto nomem; + + return reply; + +nomem: + if (reply) + dbus_message_unref(reply); + reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL); + return reply; +} /* * wpas_dbus_handler_disconnect - Terminate the current connection * @message: Pointer to incoming dbus message * @wpa_s: wpa_supplicant structure for a network interface * Returns: NotConnected DBus error message if already not connected * or NULL otherwise. diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h index 8d157ed..51cf5f3 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.h +++ b/wpa_supplicant/dbus/dbus_new_handlers.h @@ -83,14 +83,17 @@ dbus_bool_t wpas_dbus_getter_eap_methods(DBusMessageIter *iter, dbus_bool_t wpas_dbus_getter_global_capabilities(DBusMessageIter *iter, DBusError *error, void *user_data); DBusMessage * wpas_dbus_handler_scan(DBusMessage *message, struct wpa_supplicant *wpa_s); +DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message, + struct wpa_supplicant *wpa_s); + DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message, struct wpa_supplicant *wpa_s); dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, DBusMessageIter *iter, DBusError *error);