From patchwork Tue Nov 15 16:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Heider X-Patchwork-Id: 1704199 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4zXZNrhW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=STgFdHsW; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBXRR4j5hz23mh for ; Wed, 16 Nov 2022 03:57:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=WKHbjvTsc+Z7j1VRaU3DFaAPDTweBnp7NuaPMk+J43c=; b=4zXZNrhWVhy1md 5oKgzgsgWA7vT73U4YkUR9n46R3Bik3+SZE1kNaPIHlN45wsDyXwSBq2C5jFDk3x1Dkh9Yt4duCGQ 6hcH8mHZZbT3x1/WqFLB/XY3ssYHAlRr5oG28bLaBF918Pcn9kWsVzEl//0ceTKokJJgN4ZupL7/U weuLF/aXfw2LkGBV9cQnYJoVfctiyd94iqNPC5JApR1w32Q43TCZiH7ss9US2Uo4y8zm5O5UQlvXH eR5juWX6rED88kH8Rd8mLRj58D9StgIWI3HOjY2OIuykRIv6C8eviBbXxUxUxOq33BZ1LePvTqZe+ IvIbscvsdu2nvuAwv4lQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDc-00DHCi-OQ; Tue, 15 Nov 2022 16:55:29 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDX-00DH9p-U3 for openwrt-devel@lists.openwrt.org; Tue, 15 Nov 2022 16:55:25 +0000 Received: by mail-ej1-x62d.google.com with SMTP id bj12so37486441ejb.13 for ; Tue, 15 Nov 2022 08:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=anm8yNseiH5g7cY0NpLCNlw0aXODK8OaE4HEL7x5Myc=; b=STgFdHsWjvZEXd2c0n8GXUiATwVgfwhHF4f6U1ejAQEfUjYLkB4BRhkZJap4NJ6ZfJ mFatsJFHq6yEnX2vipPF2FAMITpTdZw0NjLdnpTh8hFz2Nn0kgl3yG3NRCwJR+x58I1b MXqtJuQVIoRn5SB1Yh8Rbgmnc4+dbNwm8Tpet+eFJZ4ebJOJQajdzG9YAo3UJj3MDNt2 ySR6QCCYiiATKFzOjiUxhm599e8+WtiQYnN9s3tP+++USiDo0BvbYYh4MEt8KDCNEW0b vJD0GM2JUCBAcXEQ1OWQzbhs6n7bqWjWE56OXrceEJBguXXGDFZSJHhCiNOKBc+FviYY SH0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=anm8yNseiH5g7cY0NpLCNlw0aXODK8OaE4HEL7x5Myc=; b=EbryMng/dn17eUL2f2lVaG6qglxkZtRqbg4MhnTwX82A9sj+SKv2+ySgPULzgOEL09 RzbT0LmhgBcUlVySXuxPydevOtoIXkVsgIoMg6GA6f2d6jiYHAdGFPH8RBvJpue9mEbC a3azbv9MU3NIOt44UUA/8kdmwE08mLTqYlEOEFOPGYLYjQ/KZ3oI/k+1XaoXdwiw3lTN BZ0D/iOHYTS6rOr1Jclsj3UGjvG5tWOqnYNiV4OO/amhNaHEUW6qoZO2AXGTIkA+4uPX 1lY8jVFaKgbxQV1ZmnWih7I7MKXn1K516IL/uc9HvKtjcMpQjXbkShv6ozijCxyOc5qp 3+xg== X-Gm-Message-State: ANoB5pmfrnEV4qjVeWpphDPXJ548Zaz+uGWhUN2MiT5RjGFwQ3+OEKo9 E/y9pcpmxrU4iIC+QwNkhgLMZcM7U9Y= X-Google-Smtp-Source: AA0mqf6b/GmX+3AR1XLnpuMJIqn8xhnamrvdfrK8bvGcB6eyK4VoRP4WPFI/3IgbIkBFX89yVUo9xA== X-Received: by 2002:a17:906:ae47:b0:78d:a871:737c with SMTP id lf7-20020a170906ae4700b0078da871737cmr14465268ejb.597.1668531320283; Tue, 15 Nov 2022 08:55:20 -0800 (PST) Received: from mamamia.internal (a89-182-186-105.net-htp.de. [89.182.186.105]) by smtp.gmail.com with ESMTPSA id q17-20020a170906a09100b0077909095acasm5791615ejy.143.2022.11.15.08.55.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 08:55:19 -0800 (PST) From: Andre Heider To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] iwinfo: nl80211: don't guess if a name is an ifname Date: Tue, 15 Nov 2022 17:55:17 +0100 Message-Id: <20221115165518.1667524-1-a.heider@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221115_085523_999287_C7E33AF1 X-CRM114-Status: GOOD ( 12.45 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: It's too slow to do it all over again and again, especially with e.g. luci constantly polling. Before: $ time iwinfo phy0 info real 0m 0.54s $ time iwinfo radio0 info real 0m 0.70s $ time ubus call luci-rpc getWirelessDevices real 0m 0.67s Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:62d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [a.heider[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org It's too slow to do it all over again and again, especially with e.g. luci constantly polling. Before: $ time iwinfo phy0 info real 0m 0.54s $ time iwinfo radio0 info real 0m 0.70s $ time ubus call luci-rpc getWirelessDevices real 0m 0.67s After: $ time iwinfo phy0 info real 0m 0.04s $ time iwinfo radio0 info real 0m 0.09s $ time ubus call luci-rpc getWirelessDevices real 0m 0.17s Signed-off-by: Andre Heider --- iwinfo_nl80211.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 77fddee..77a65ed 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -22,6 +22,7 @@ * Parts of this code are derived from the Linux iw utility. */ +#include #include #include #include @@ -411,6 +412,15 @@ out: return idx; } +static bool nl80211_is_ifname(const char *name) +{ + struct stat st; + char buffer[PATH_MAX]; + + snprintf(buffer, sizeof(buffer), "/sys/class/net/%s", name); + return !lstat(buffer, &st); +} + static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, int cmd, int flags) { @@ -426,10 +436,9 @@ static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, if (!strncmp(ifname, "mon.", 4)) ifidx = if_nametoindex(&ifname[4]); - else + else if (nl80211_is_ifname(ifname)) ifidx = if_nametoindex(ifname); - - if (!ifidx) { + else { phyidx = nl80211_phy_idx_from_phy(ifname); if (phyidx < 0) phyidx = nl80211_phy_idx_from_uci(ifname); From patchwork Tue Nov 15 16:55:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Heider X-Patchwork-Id: 1704200 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PpCN1jrp; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DST4xl0r; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBXRd4xgJz23lt for ; Wed, 16 Nov 2022 03:57:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jh9Hrt2s0fcVp5jLseWinIP40POQzURLCjRk5Gu1THo=; b=PpCN1jrpGCxo3O OYZR7B5/UsX1ai4N8ahh3xlOFrQi+Ta3OcjLeJ4XgLgjghdgOfNVCzTNyMis3Qn+8V51NGQS9MF9z KW0sO8sQKyKavhZUpkY5Mted7rzDk6qs8oifawf40qFbvwbh4S/YWKNDUC5XtrzJUimHK+p2BpJ3C EnD1Mekbxw5SesywgkVwvJ/UmE6EY6VBcxcEODh+gRvBcekivHbiAfeP5aAjblw6vNVh1712rSlw/ G8P6JZqt2bAOzncKMmq5WLsm0ca/NABjLL3GkeR7viUkcH7SNc8GweeTL6AUOXXsbQ5CllVOjacz2 rGxPKAh0xqozBgjhPiGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDy-00DHUB-At; Tue, 15 Nov 2022 16:55:50 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDY-00DHA8-VL for openwrt-devel@lists.openwrt.org; Tue, 15 Nov 2022 16:55:26 +0000 Received: by mail-ed1-x52d.google.com with SMTP id s5so6538650edc.12 for ; Tue, 15 Nov 2022 08:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=plOkiqMC+gb0GfHqJ/KE07IPNxZFqdlg9eW2PJCYTPI=; b=DST4xl0rfcM5wNntQf0f70NNNHh9PrQbd+xGfAFhsxGJcC6bJ/nd6KQAVuSHhctJBl 2TsYCXXFfn9CeS0nyeZBFO1qr2cag1NaX+uPCCKE1pb6F1Lru4bqxois588+DGKKfep8 USxa+6vyWAxYniKbBHT17DyMatiTfpy/ajdEowPvMpyudpYmchZi0ARBF7W/u7bcSM3B +sxIeHrCgdv6Q0mecwO98CNcSfTj+dapvuuA/Jn1x0Ud85C/hdutyJJTHl/P2sVXQGo1 WXYXpcdcNs6omsIDHh9Zy3hMwiZvHGq0gYXB04EUmWkyWhiofmubzbHFMOiycqU6Ahqb jhqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=plOkiqMC+gb0GfHqJ/KE07IPNxZFqdlg9eW2PJCYTPI=; b=JL0ALvmymTK+63Mt/tUAzuqxsfHFg8Xgef0IRxtArFtCq3XxLjdKV3bTcWWdam+Eaj Z270pVhFkZ5hNVV9abUKlIy09aU7v0ZZdbh7QPMG8zytTuJlojtl4VhPmSiCz1koQm8X DuTZp1acBUiheJWB9Rp/cUQW6n0YuRnE7j9b7k/ms+kofIehRtpwxaRLDFP3D1PsXGSs LoVPPxyhRPEsFs//tqM/3KYT7o5/JF9JhBv4DPRAURUm/HxQ4xHfz6cqcReq0PnyDwGS dTXJUqmVDxbdBVaEotM0KsHU5ceiseWDI+egqCWP8NY7G2BGcYUkYIBBeKz4cE5RNRoL H2GQ== X-Gm-Message-State: ANoB5pkOjVktx+7Ivnzkv2Eu2/hK/Y2eUekRPRZrD5MIpPI3L8+2Ow4i pBejS/enzqFXuT5DMSn633IdiCV+ccw= X-Google-Smtp-Source: AA0mqf7DOuRApFCarD2fhR62lSyP1upT1WwN9B3ECU4bqTVsqog2sPiVnVLezDgqkADTXk1pn32fcA== X-Received: by 2002:a05:6402:d51:b0:462:3340:758f with SMTP id ec17-20020a0564020d5100b004623340758fmr16321338edb.37.1668531321307; Tue, 15 Nov 2022 08:55:21 -0800 (PST) Received: from mamamia.internal (a89-182-186-105.net-htp.de. [89.182.186.105]) by smtp.gmail.com with ESMTPSA id q17-20020a170906a09100b0077909095acasm5791615ejy.143.2022.11.15.08.55.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 08:55:20 -0800 (PST) From: Andre Heider To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/2] iwinfo: nl80211: don't use a random iface when getting phy infos Date: Tue, 15 Nov 2022 17:55:18 +0100 Message-Id: <20221115165518.1667524-2-a.heider@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221115165518.1667524-1-a.heider@gmail.com> References: <20221115165518.1667524-1-a.heider@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221115_085525_031505_3894EC40 X-CRM114-Status: GOOD ( 13.57 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: One phy can have more than one wifi-iface. When getting just the phy infos, don't get iface specific values of some random iface from that phy, that's just not right and confusing. Note: This removes ssid, bssid, mode, quality_max and encryption from the phy result table of e.g: $ ubus call iwinfo info '{"device":"phy0"}' Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:52d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [a.heider[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org One phy can have more than one wifi-iface. When getting just the phy infos, don't get iface specific values of some random iface from that phy, that's just not right and confusing. Note: This removes ssid, bssid, mode, quality_max and encryption from the phy result table of e.g: $ ubus call iwinfo info '{"device":"phy0"}' But there're of course still present of for ifaces, e.g.: $ ubus call iwinfo info '{"device":"wlan0"}'` And more importantly this is unchanged: $ ubus call luci-rpc getWirelessDevices (Which has iface _and_ phy iwinfo tables, where the latter already doesn't include the values removed here). Signed-off-by: Andre Heider --- iwinfo_nl80211.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 77a65ed..1d59676 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -819,13 +819,12 @@ static int nl80211_get_mode_cb(struct nl_msg *msg, void *arg) static int nl80211_get_mode(const char *ifname, int *buf) { - char *res; - *buf = IWINFO_OPMODE_UNKNOWN; - res = nl80211_phy2ifname(ifname); + if (!nl80211_is_ifname(ifname)) + return -1; - nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_request(ifname, NL80211_CMD_GET_INTERFACE, 0, nl80211_get_mode_cb, buf); return (*buf == IWINFO_OPMODE_UNKNOWN) ? -1 : 0; @@ -1242,14 +1241,15 @@ static int nl80211_get_ssid_bssid_cb(struct nl_msg *msg, void *arg) static int nl80211_get_ssid(const char *ifname, char *buf) { - char *res; struct nl80211_ssid_bssid sb = { .ssid = (unsigned char *)buf }; + if (!nl80211_is_ifname(ifname)) + return -1; + /* try to find ssid from scan dump results */ - res = nl80211_phy2ifname(ifname); sb.ssid[0] = 0; - nl80211_request(res ? res : ifname, NL80211_CMD_GET_SCAN, NLM_F_DUMP, + nl80211_request(ifname, NL80211_CMD_GET_SCAN, NLM_F_DUMP, nl80211_get_ssid_bssid_cb, &sb); /* failed, try to find from hostapd info */ @@ -1259,7 +1259,7 @@ static int nl80211_get_ssid(const char *ifname, char *buf) /* failed, try to obtain Mesh ID */ if (sb.ssid[0] == 0) - iwinfo_ubus_query(res ? res : ifname, "mesh_id", + iwinfo_ubus_query(ifname, "mesh_id", sb.ssid, IWINFO_ESSID_MAX_SIZE + 1); return (sb.ssid[0] == 0) ? -1 : 0; @@ -1267,18 +1267,19 @@ static int nl80211_get_ssid(const char *ifname, char *buf) static int nl80211_get_bssid(const char *ifname, char *buf) { - char *res, bssid[sizeof("FF:FF:FF:FF:FF:FF\0")]; + char bssid[sizeof("FF:FF:FF:FF:FF:FF\0")]; struct nl80211_ssid_bssid sb = { }; - res = nl80211_phy2ifname(ifname); + if (!nl80211_is_ifname(ifname)) + return -1; /* try to obtain mac address via NL80211_CMD_GET_INTERFACE */ - nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_request(ifname, NL80211_CMD_GET_INTERFACE, 0, nl80211_get_macaddr_cb, &sb); /* failed, try to find bssid from scan dump results */ if (sb.bssid[0] == 0) - nl80211_request(res ? res : ifname, + nl80211_request(ifname, NL80211_CMD_GET_SCAN, NLM_F_DUMP, nl80211_get_ssid_bssid_cb, &sb); @@ -1570,6 +1571,9 @@ static int nl80211_get_bitrate(const char *ifname, int *buf) { struct nl80211_rssi_rate rr; + if (!nl80211_is_ifname(ifname)) + return -1; + nl80211_fill_signal(ifname, &rr); if (rr.rate_samples) @@ -1585,6 +1589,9 @@ static int nl80211_get_signal(const char *ifname, int *buf) { struct nl80211_rssi_rate rr; + if (!nl80211_is_ifname(ifname)) + return -1; + nl80211_fill_signal(ifname, &rr); if (rr.rssi_samples) @@ -1674,6 +1681,9 @@ static int nl80211_get_quality(const char *ifname, int *buf) static int nl80211_get_quality_max(const char *ifname, int *buf) { + if (!nl80211_is_ifname(ifname)) + return -1; + /* The cfg80211 wext compat layer assumes a maximum * quality of 70 */ *buf = 70; @@ -1813,6 +1823,9 @@ static int nl80211_get_encryption(const char *ifname, char *buf) struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf; + if (!nl80211_is_ifname(ifname)) + return -1; + /* WPA supplicant */ if (nl80211_wpactl_query(ifname, "pairwise_cipher", wpa_pairwise, sizeof(wpa_pairwise),