From patchwork Tue Nov 4 08:51:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinash Patil X-Patchwork-Id: 406476 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 EC074140079 for ; Tue, 4 Nov 2014 19:51:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id ABA349D29D; Tue, 4 Nov 2014 03:51:42 -0500 (EST) 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 yBq9Sf2BV-Sm; Tue, 4 Nov 2014 03:51:42 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 25FB19D29E; Tue, 4 Nov 2014 03:51:36 -0500 (EST) 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 508599D29E for ; Tue, 4 Nov 2014 03:51:35 -0500 (EST) 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 MsJue-aR1dBp for ; Tue, 4 Nov 2014 03:51:28 -0500 (EST) Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 41A9B9D29D for ; Tue, 4 Nov 2014 03:51:28 -0500 (EST) Received: by mail-pa0-f41.google.com with SMTP id rd3so14109701pab.0 for ; Tue, 04 Nov 2014 00:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=sKC/8MJZvm9vw4uJFnT82MPcHR2amIqh8fDo3foeDe4=; b=ivFQ4pHrzA/m8dAvFtGNY69Y0CuCU7sKBdoZ3hSHq8e9NvLdyJ97c7n47u0DEj2gGS zV3rJTh+jvHrdEXfyyjn1HWGV/jDWU7Y/HrwSj0gN7au95ppvcK2fXCzOdiI8I/OAiNl 13A7qGVTEk4eIrPKij9ZIV2qkYhe6UaaKN2oJzJI2rnDChYzb/Idj48CpoqzmWDcNe2G eW03DF0f1epbTeveLx2aneOnMdmDMmV7tRzWwBfL7U9o+j9C1m4Yqp0gGIFq4xNvH5cb 7wq5QuIiJwDp2L8OdbjMDCWDAWCT7GXjkz/rKvTKdYjd5D6QsJ5wx5uvosfXolKZOq2b /qyA== MIME-Version: 1.0 X-Received: by 10.70.109.169 with SMTP id ht9mr6426375pdb.152.1415091087066; Tue, 04 Nov 2014 00:51:27 -0800 (PST) Received: by 10.70.69.5 with HTTP; Tue, 4 Nov 2014 00:51:27 -0800 (PST) Date: Tue, 4 Nov 2014 14:21:27 +0530 Message-ID: Subject: [PATCH] supplicant: add dbus getter method for nl80211 iftype From: Avinash Patil To: hostap@lists.shmoo.com Cc: Avinash Patil 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 This patch adds dbus getter method for nl80211 iftype. This is required by certain applications which intend to start AP operations only if current interface type is AP. Getter method for capabilities cannot be used for this purpose as this enumerates all the supported interface types. Signed-off-by: Avinash Patil --- src/common/defs.h | 18 ++++++++++++++++ src/drivers/driver.h | 12 +++++++++++ src/drivers/driver_nl80211.c | 11 ++++++++++ wpa_supplicant/dbus/dbus_new.c | 4 ++++ wpa_supplicant/dbus/dbus_new_handlers.c | 38 +++++++++++++++++++++++++++++++++ wpa_supplicant/dbus/dbus_new_handlers.h | 4 ++++ wpa_supplicant/driver_i.h | 8 +++++++ wpa_supplicant/wpa_supplicant.c | 33 ++++++++++++++++++++++++++++ wpa_supplicant/wpa_supplicant_i.h | 1 + 9 files changed, 129 insertions(+) int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, -- 1.8.1.4 diff --git a/src/common/defs.h b/src/common/defs.h index d4091e3..b5e5a77 100644 --- a/src/common/defs.h +++ b/src/common/defs.h @@ -297,6 +297,24 @@ enum wpa_ctrl_req_type { NUM_WPA_CTRL_REQS }; +enum wpa_nl80211_iftype { + WPA_IFTYPE_UNSPECIFIED, + WPA_IFTYPE_ADHOC, + WPA_IFTYPE_STATION, + WPA_IFTYPE_AP, + WPA_IFTYPE_AP_VLAN, + WPA_IFTYPE_WDS, + WPA_IFTYPE_MONITOR, + WPA_IFTYPE_MESH_POINT, + WPA_IFTYPE_P2P_CLIENT, + WPA_IFTYPE_P2P_GO, + WPA_IFTYPE_P2P_DEVICE, + + /* keep last */ + WPA_NL80211_IFTYPES, + WPA_IFTYPE_MAX = WPA_NL80211_IFTYPES - 1 +}; + /* Maximum number of EAP methods to store for EAP server user information */ #define EAP_MAX_METHODS 8 diff --git a/src/drivers/driver.h b/src/drivers/driver.h index 6e47b86..6833d32 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -1358,6 +1358,18 @@ struct wpa_driver_ops { int (*get_ssid)(void *priv, u8 *ssid); /** + * get_iftype - Get the current NL80211 iftype + * @priv: private driver interface data + * @iftype: buffer for storing iftype + * + * Returns: 0 on success, -1 on failure + * + * Query kernel driver for the current NL80211 mode and copy it to + * iftype. + */ + int (*get_iftype)(void *priv, u8 *iftype); + + /** * set_key - Configure encryption key * @ifname: Interface name (for multi-SSID/VLAN support) * @priv: private driver interface data diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 5d31018..15fa461 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -1063,6 +1063,16 @@ static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) return 0; } +static int wpa_driver_nl80211_get_nl80211_iftype(void *priv, u8 *iftype) +{ + struct i802_bss *bss = priv; + if (!bss) + return -1; + + *iftype = (u8)nl80211_get_ifmode(bss); + + return 0; +} static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) { @@ -12293,6 +12303,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { .desc = "Linux nl80211/cfg80211", .get_bssid = wpa_driver_nl80211_get_bssid, .get_ssid = wpa_driver_nl80211_get_ssid, + .get_iftype = wpa_driver_nl80211_get_nl80211_iftype, .set_key = driver_nl80211_set_key, .scan2 = driver_nl80211_scan2, .sched_scan = wpa_driver_nl80211_sched_scan, diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index 6bd2a40..67238e7 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -2809,6 +2809,10 @@ static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = { wpas_dbus_getter_driver, NULL }, + { "CurrentIfType", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", + wpas_dbus_getter_current_iftype, + NULL + }, { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", wpas_dbus_getter_bridge_ifname, NULL diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index f5efd8b..755f902 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -3083,6 +3083,44 @@ dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error, &driver, error); } +/** + * wpas_dbus_getter_current_mode - + * Get current NL mode + * @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 "Current IF type" property. + */ +dbus_bool_t wpas_dbus_getter_current_iftype(DBusMessageIter *iter, + DBusError *error, void *user_data) +{ + struct wpa_supplicant *wpa_s = user_data; + u8 iftype; + const char *char_iftype; + + if (wpa_s->driver == NULL) { + wpa_printf(MSG_DEBUG, "wpas_dbus_getter_current_iftype[dbus]: " + "wpa_s has no driver set"); + dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set", + __func__); + return FALSE; + } + + if(wpa_drv_get_iftype(wpa_s, &iftype)) { + wpa_printf(MSG_DEBUG, "wpas_dbus_getter_current_iftype[dbus]: " + "failed"); + dbus_set_error(error, DBUS_ERROR_FAILED, "%s: failed", + __func__); + return FALSE; + } + char_iftype = wpa_supplicant_iftype_txt(iftype); + + wpa_printf(MSG_DEBUG, "dbus: Get interface type: %s", char_iftype); + return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, + &char_iftype, error); +} /** * wpas_dbus_getter_current_bss - Get current bss object path diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h index 461970d..51f0332 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.h +++ b/wpa_supplicant/dbus/dbus_new_handlers.h @@ -202,6 +202,10 @@ dbus_bool_t wpas_dbus_getter_ifname(DBusMessageIter *iter, DBusError *error, dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error, void *user_data); +dbus_bool_t wpas_dbus_getter_current_iftype(DBusMessageIter *iter, + DBusError *error, + void *user_data); + dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter, DBusError *error, void *user_data); diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h index 00703d9..c10ae25 100644 --- a/wpa_supplicant/driver_i.h +++ b/wpa_supplicant/driver_i.h @@ -114,6 +114,14 @@ static inline int wpa_drv_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid) return -1; } +static inline int wpa_drv_get_iftype(struct wpa_supplicant *wpa_s, u8 *iftype) +{ + if (wpa_s->driver->get_iftype) { + return wpa_s->driver->get_iftype(wpa_s->drv_priv, iftype); + } + return -1; +} + static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, enum wpa_alg alg, const u8 *addr, int key_idx, int set_tx, diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 28d763c..16519d9 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -573,6 +573,39 @@ const char * wpa_supplicant_state_txt(enum wpa_states state) } } +/** + * wpa_supplicant_iftype_txt - Get the NL80211 iftype as a text string + * Returns: The iftype name as a printable text string + */ +const char * wpa_supplicant_iftype_txt(u8 iftype) +{ + switch (iftype) { + case WPA_IFTYPE_UNSPECIFIED: + return "UNSPECIFIED"; + case WPA_IFTYPE_ADHOC: + return "ADHOC"; + case WPA_IFTYPE_STATION: + return "STATION"; + case WPA_IFTYPE_AP: + return "AP"; + case WPA_IFTYPE_AP_VLAN: + return "AP_VLAN"; + case WPA_IFTYPE_WDS: + return "WDS"; + case WPA_IFTYPE_MONITOR: + return "MONITOR"; + case WPA_IFTYPE_MESH_POINT: + return "MESH_POINT"; + case WPA_IFTYPE_P2P_CLIENT: + return "P2P_CLIENT"; + case WPA_IFTYPE_P2P_GO: + return "P2P_GO"; + case WPA_IFTYPE_P2P_DEVICE: + return "P2P_DEVICE"; + default: + return "UNKNOWN"; + } +} #ifdef CONFIG_BGSCAN diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index c51a703..9138630 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -874,6 +874,7 @@ int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s, int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s); const char * wpa_supplicant_state_txt(enum wpa_states state); +const char * wpa_supplicant_iftype_txt(u8 iftype); int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s); int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);