From patchwork Fri Mar 15 22:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 1057266 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=candelatech.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GAAz2I4x"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=candelatech.com header.i=@candelatech.com header.b="hjvaveU1"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Lfqy6xw4z9s4V for ; Sat, 16 Mar 2019 09:09:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=RDc9DAkbfCXGh5kz83A+RO33tJcR5pI2s0uriHM+r5Y=; b=GAA z2I4xR++t8+wilo52CoRfGiKNB8a+tOsbeEkFE5GG9OpOI5urezqXvRwNJgivS8mGPuQVL6F5wezf T7zLO3eZmscjGchosPprExg5FECH0ghqR+K9EVluNFrA+hJfvHRGvvZW4w1hzeiD3kV7p0SQ3g/uU iHQFK/o2FbAQGid4Vekk0K1Cjf9JRxCiLS8DwfYer/lFsjppGOc8BEfnClSPYsl45dwFteOw54gLI 1oaqHdCW+dzmk8umqx8/KoacI0xopsGnVuj1j0u85JiuPMsR+dKyKGEAa96ugsl6ILDDWI/qABmgT 5O7AM7bELYHJ8e+q/nko8gtxUk50qxA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4v0k-0001KZ-6M; Fri, 15 Mar 2019 22:09:06 +0000 Received: from [208.74.158.174] (helo=mail3.candelatech.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4v0h-0001K9-8p for hostap@lists.infradead.org; Fri, 15 Mar 2019 22:09:04 +0000 Received: from v-f24-64.candelatech.com (50-251-239-81-static.hfc.comcastbusiness.net [50.251.239.81]) by mail3.candelatech.com (Postfix) with ESMTP id 49F97114B48; Fri, 15 Mar 2019 15:09:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 mail3.candelatech.com 49F97114B48 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=candelatech.com; s=default; t=1552687740; bh=61Pjm1ZMuyBkM9uOmfsiVu+6rqGqJKwPRA5Yko1PAk8=; h=From:To:Cc:Subject:Date:From; b=hjvaveU1308DyJgQfPKtH1YXirXaTKMjRxNA4zH0b6ALpLEfi8/0zeiMNqAV163h/ TIIf9yptuyqYciMyo9i6P8DqXW3sO3sza0CtPgRbi+B/yxlHHKFPvJnBoLxmLqXvPt R7IKN5CF3FKUcYX8/ryeAH9BiWNy9Sp+JAO5mOY4= From: greearb@candelatech.com To: hostap@lists.infradead.org Subject: [PATCH v2] hostapd: Support showing neighbor list through hostapd_cli Date: Fri, 15 Mar 2019 15:08:54 -0700 Message-Id: <1552687734-25399-1-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 2.7.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_150903_360493_05862CFE X-CRM114-Status: GOOD ( 11.38 ) X-Spam-Score: 1.1 (+) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Greear MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Ben Greear This lets one know the current neighbor list, and could be used to populate the neighbor list of other hostapd processes. For instance: # hostapd_cli -i vap0001 show_neighbor 04:f0:21:1e:ae:b0 ssid=04f0211eaeb0af190000802809 nr=04f0211eaeb0af1900008028090603022a00 lci=[BLANK] civic=[BLANK] stationary=0 # hostapd_cli -i vap0000 set_neighbor 04:f0:21:1e:ae:b0 ssid=04f0211eaeb0af190000802809 nr=04f0211eaeb0af1900008028090603022a00 OK # hostapd_cli -i vap0000 show_neighbor 04:f0:21:1e:ae:b0 ssid=04f0211eaeb0af190000802809 nr=04f0211eaeb0af1900008028090603022a00 lci=[BLANK] civic=[BLANK] stationary=0 04:f0:21:c3:b2:b0 ssid=04f021c3b2b0af190000802809 nr=04f021c3b2b0af1900008028090603022a00 lci=[BLANK] civic=[BLANK] stationary=0 # Signed-off-by: Ben Greear --- v2: Add ssid to dump, use [blank] for empty things instead of printing 00 hex as previous version. hostapd/ctrl_iface.c | 19 +++++++++++++++ hostapd/hostapd_cli.c | 8 ++++++ src/ap/neighbor_db.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/ap/neighbor_db.h | 1 + 4 files changed, 95 insertions(+) diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index df2524a..f47d21e 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -2655,6 +2655,23 @@ static int hostapd_ctrl_iface_req_beacon(struct hostapd_data *hapd, return ret; } +static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data *hapd, + char *buf, size_t buflen) +{ + struct hostapd_iface *iface = hapd->iface; + struct hostapd_sta_info *info; + struct os_reltime now; + + if (!(hapd->conf->radio_measurements[0] & + WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { + wpa_printf(MSG_ERROR, + "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled"); + return -1; + } + + return hostapd_neighbor_show(hapd, buf, buflen); +} + static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data *hapd, char *buf) { @@ -3174,6 +3191,8 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, } else if (os_strncmp(buf, "SET_NEIGHBOR ", 13) == 0) { if (hostapd_ctrl_iface_set_neighbor(hapd, buf + 13)) reply_len = -1; + } else if (os_strcmp(buf, "SHOW_NEIGHBOR") == 0) { + reply_len = hostapd_ctrl_iface_show_neighbor(hapd, reply, reply_size); } else if (os_strncmp(buf, "REMOVE_NEIGHBOR ", 16) == 0) { if (hostapd_ctrl_iface_remove_neighbor(hapd, buf + 16)) reply_len = -1; diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 23c592a..4b1c877 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -1303,6 +1303,12 @@ static int hostapd_cli_cmd_set_neighbor(struct wpa_ctrl *ctrl, int argc, return wpa_ctrl_command(ctrl, cmd); } +static int hostapd_cli_cmd_show_neighbor(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + return wpa_ctrl_command(ctrl, "SHOW_NEIGHBOR"); +} + static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc, char *argv[]) @@ -1628,6 +1634,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { { "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL, " [lci=] [civic=] [stat]\n" " = add AP to neighbor database" }, + { "show_neighbor", hostapd_cli_cmd_show_neighbor, NULL, + " = show neighbor database entries" }, { "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL, " = remove AP from neighbor database" }, { "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations, diff --git a/src/ap/neighbor_db.c b/src/ap/neighbor_db.c index 2b6f727..f54b065 100644 --- a/src/ap/neighbor_db.c +++ b/src/ap/neighbor_db.c @@ -33,6 +33,73 @@ hostapd_neighbor_get(struct hostapd_data *hapd, const u8 *bssid, return NULL; } +int +hostapd_neighbor_show(struct hostapd_data *hapd, char* buf, size_t buflen) +{ + struct hostapd_neighbor_entry *nr; + char *pos, *end; + + pos = buf; + end = buf + buflen; + + dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, + list) { + int ret; + char nrie[120]; + char lci[120]; + char civic[120]; + char ssid[SSID_MAX_LEN * 2 + 1]; + int i = 0; + static const char* blank = "[BLANK]"; + + for (i = 0; issid.ssid_len; i++) { + os_snprintf(ssid + i * 2, 3, "%02hx", nr->nr->buf[i]); + } + if (i == 0) + os_snprintf(ssid, sizeof(ssid), "%s", blank); + + i = 0; + if (nr->nr) { + for (i = 0; inr->used; i++) { + if (i * 2 + 2 >= sizeof(nrie)) + break; + os_snprintf(nrie + i * 2, 3, "%02hx", nr->nr->buf[i]); + } + } + if (i == 0) + os_snprintf(nrie, sizeof(nrie), "%s", blank); + + i = 0; + if (nr->lci) { + for (i = 0; ilci->used; i++) { + if (i * 2 + 2 >= sizeof(lci)) + break; + os_snprintf(lci + i * 2, 3, "%02hx", nr->lci->buf[i]); + } + } + if (i == 0) + os_snprintf(lci, sizeof(lci), "%s", blank); + + i = 0; + if (nr->civic) { + for (i = 0; icivic->used; i++) { + if (i * 2 + 2 >= sizeof(civic)) + break; + os_snprintf(civic + i * 2, 3, "%02hx", nr->civic->buf[i]); + } + } + if (i == 0) + os_snprintf(civic, sizeof(civic), "%s", blank); + + ret = os_snprintf(pos, end - pos, MACSTR " ssid=%s nr=%s lci=%s civic=%s stationary=%i\n", + MAC2STR(nr->bssid), ssid, nrie, lci, civic, nr->stationary); + if (os_snprintf_error(end - pos, ret)) + break; + pos += ret; + } + return pos - buf; +} + static void hostapd_neighbor_clear_entry(struct hostapd_neighbor_entry *nr) { diff --git a/src/ap/neighbor_db.h b/src/ap/neighbor_db.h index 9c8f4f2..e269310 100644 --- a/src/ap/neighbor_db.h +++ b/src/ap/neighbor_db.h @@ -13,6 +13,7 @@ struct hostapd_neighbor_entry * hostapd_neighbor_get(struct hostapd_data *hapd, const u8 *bssid, const struct wpa_ssid_value *ssid); +int hostapd_neighbor_show(struct hostapd_data *hapd, char* buf, size_t buflen); int hostapd_neighbor_set(struct hostapd_data *hapd, const u8 *bssid, const struct wpa_ssid_value *ssid, const struct wpabuf *nr, const struct wpabuf *lci,