Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Andrew Zaborowski <balrogg@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 02/11] netdev: Report RSSI to frame watch callbacks
Date: Mon, 21 Oct 2019 15:55:01 +0200	[thread overview]
Message-ID: <20191021135510.12657-2-balrogg@gmail.com> (raw)
In-Reply-To: <20191021135510.12657-1-balrogg@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6523 bytes --]

From: Andrew Zaborowski <andrew.zaborowski@intel.com>

The main use case is for user-space implemented scanning / device
discovery logic, like in P2P, to be able to report device rssi like
the kernel- or driver-side scanning does, based on the received beacons,
probe requests, probe responses, GO negotiation requests, PD requests
etc.
---
 src/ap.c     | 13 +++++++------
 src/device.c |  2 +-
 src/netdev.c | 20 ++++++++++++++------
 src/netdev.h |  2 +-
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/ap.c b/src/ap.c
index cb7288db..db231167 100644
--- a/src/ap.c
+++ b/src/ap.c
@@ -966,7 +966,7 @@ bad_frame:
 static void ap_assoc_req_cb(struct netdev *netdev,
 				const struct mmpdu_header *hdr,
 				const void *body, size_t body_len,
-				void *user_data)
+				int rssi, void *user_data)
 {
 	struct ap_state *ap = user_data;
 	struct sta_state *sta;
@@ -1000,7 +1000,7 @@ static void ap_assoc_req_cb(struct netdev *netdev,
 static void ap_reassoc_req_cb(struct netdev *netdev,
 				const struct mmpdu_header *hdr,
 				const void *body, size_t body_len,
-				void *user_data)
+				int rssi, void *user_data)
 {
 	struct ap_state *ap = user_data;
 	struct sta_state *sta;
@@ -1054,7 +1054,7 @@ static void ap_probe_resp_cb(struct l_genl_msg *msg, void *user_data)
 static void ap_probe_req_cb(struct netdev *netdev,
 				const struct mmpdu_header *hdr,
 				const void *body, size_t body_len,
-				void *user_data)
+				int rssi, void *user_data)
 {
 	struct ap_state *ap = user_data;
 	const struct mmpdu_probe_request *req = body;
@@ -1147,7 +1147,7 @@ static void ap_probe_req_cb(struct netdev *netdev,
 static void ap_disassoc_cb(struct netdev *netdev,
 				const struct mmpdu_header *hdr,
 				const void *body, size_t body_len,
-				void *user_data)
+				int rssi, void *user_data)
 {
 	struct ap_state *ap = user_data;
 	struct sta_state *sta;
@@ -1217,7 +1217,8 @@ static void ap_auth_reply(struct ap_state *ap, const uint8_t *dest,
  * 802.11-2016 12.3.3.2 (MLME/SME)
  */
 static void ap_auth_cb(struct netdev *netdev, const struct mmpdu_header *hdr,
-			const void *body, size_t body_len, void *user_data)
+			const void *body, size_t body_len, int rssi,
+			void *user_data)
 {
 	struct ap_state *ap = user_data;
 	const struct mmpdu_authentication *auth = body;
@@ -1285,7 +1286,7 @@ done:
 
 /* 802.11-2016 9.3.3.13 (frame format), 802.11-2016 11.3.4.5 (MLME/SME) */
 static void ap_deauth_cb(struct netdev *netdev, const struct mmpdu_header *hdr,
-				const void *body, size_t body_len,
+				const void *body, size_t body_len, int rssi,
 				void *user_data)
 {
 	struct ap_state *ap = user_data;
diff --git a/src/device.c b/src/device.c
index 4f9d3933..4fd4edbe 100644
--- a/src/device.c
+++ b/src/device.c
@@ -57,7 +57,7 @@ static uint32_t netdev_watch;
 static void device_ap_roam_frame_event(struct netdev *netdev,
 		const struct mmpdu_header *hdr,
 		const void *body, size_t body_len,
-		void *user_data)
+		int rssi, void *user_data)
 {
 	struct device *device = user_data;
 	struct station *station = station_find(device->index);
diff --git a/src/netdev.c b/src/netdev.c
index 526480dd..23fd980d 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -36,6 +36,7 @@
 #include <linux/filter.h>
 #include <sys/socket.h>
 #include <errno.h>
+#include <limits.h>
 
 #include <ell/ell.h>
 
@@ -2895,7 +2896,7 @@ static void netdev_ft_request_cb(struct l_genl_msg *msg, void *user_data)
 static void netdev_ft_response_frame_event(struct netdev *netdev,
 					const struct mmpdu_header *hdr,
 					const void *body, size_t body_len,
-					void *user_data)
+					int rssi, void *user_data)
 {
 	int ret;
 	uint16_t status_code = MMPDU_STATUS_CODE_UNSPECIFIED;
@@ -3171,7 +3172,7 @@ int netdev_neighbor_report_req(struct netdev *netdev,
 static void netdev_neighbor_report_frame_event(struct netdev *netdev,
 					const struct mmpdu_header *hdr,
 					const void *body, size_t body_len,
-					void *user_data)
+					int rssi, void *user_data)
 {
 	if (body_len < 3) {
 		l_debug("Neighbor Report frame too short");
@@ -3206,7 +3207,7 @@ static void netdev_sa_query_resp_cb(struct l_genl_msg *msg,
 static void netdev_sa_query_req_frame_event(struct netdev *netdev,
 		const struct mmpdu_header *hdr,
 		const void *body, size_t body_len,
-		void *user_data)
+		int rssi, void *user_data)
 {
 	uint8_t sa_resp[4];
 	uint16_t transaction;
@@ -3244,7 +3245,7 @@ static void netdev_sa_query_req_frame_event(struct netdev *netdev,
 static void netdev_sa_query_resp_frame_event(struct netdev *netdev,
 		const struct mmpdu_header *hdr,
 		const void *body, size_t body_len,
-		void *user_data)
+		int rssi, void *user_data)
 {
 	if (body_len < 4) {
 		l_debug("SA Query frame too short");
@@ -3511,6 +3512,7 @@ static void netdev_mgmt_frame_event(struct l_genl_msg *msg,
 	const struct mmpdu_header *mpdu = NULL;
 	const uint8_t *body;
 	struct frame_prefix_info info;
+	int rssi = INT_MIN;
 
 	if (!l_genl_attr_init(&attr, msg))
 		return;
@@ -3527,6 +3529,11 @@ static void netdev_mgmt_frame_event(struct l_genl_msg *msg,
 
 			frame_len = len;
 			break;
+		case NL80211_ATTR_RX_SIGNAL_DBM:
+			if (len != 4)
+				break;
+
+			rssi = *(const int32_t *) data;
 		}
 	}
 
@@ -3550,12 +3557,13 @@ static void netdev_mgmt_frame_event(struct l_genl_msg *msg,
 		WATCHLIST_NOTIFY_MATCHES(&netdev->frame_watches,
 					netdev_frame_watch_match_prefix, &info,
 					netdev_frame_watch_func_t,
-					netdev, mpdu, body, info.body_len);
+					netdev, mpdu, body, info.body_len,
+					rssi);
 	else
 		WATCHLIST_NOTIFY_MATCHES(&wdev_frame_watches,
 					netdev_frame_watch_match_prefix, &info,
 					netdev_frame_watch_func_t,
-					NULL, mpdu, body, info.body_len);
+					NULL, mpdu, body, info.body_len, rssi);
 }
 
 static void netdev_pae_destroy(void *user_data)
diff --git a/src/netdev.h b/src/netdev.h
index 624811b2..77da52de 100644
--- a/src/netdev.h
+++ b/src/netdev.h
@@ -119,7 +119,7 @@ typedef void (*netdev_preauthenticate_cb_t)(struct netdev *netdev,
 typedef void (*netdev_frame_watch_func_t)(struct netdev *netdev,
 					const struct mmpdu_header *frame,
 					const void *body, size_t body_len,
-					void *user_data);
+					int rssi, void *user_data);
 typedef void (*netdev_station_watch_func_t)(struct netdev *netdev,
 					const uint8_t *mac, bool added,
 					void *user_data);
-- 
2.20.1

  reply	other threads:[~2019-10-21 13:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 13:55 [PATCH 01/11] netdev: Add a wdev_id based frame watch API Andrew Zaborowski
2019-10-21 13:55 ` Andrew Zaborowski [this message]
2019-10-22  3:34   ` [PATCH 02/11] netdev: Report RSSI to frame watch callbacks Denis Kenzior
2019-10-22 13:46     ` Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 03/11] netdev: Extend checks for P2P scenarios Andrew Zaborowski
2019-10-22  3:36   ` Denis Kenzior
2019-10-21 13:55 ` [PATCH 04/11] eapol: Move the EAP event handler to handshake state Andrew Zaborowski
2019-10-22  4:11   ` Denis Kenzior
2019-10-22 14:00     ` Andrew Zaborowski
2019-10-22 14:34       ` Denis Kenzior
2019-10-21 13:55 ` [PATCH 05/11] unit: Update test-wsc to use handshake_state_set_eap_event_func Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 06/11] wsc: Replace netdev_connect_wsc with netdev_connect usage Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 07/11] netdev: Drop unused netdev_connect_wsc Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 08/11] wsc: Add wsc_new_p2p_enrollee, refactor Andrew Zaborowski
2019-10-22 14:47   ` Denis Kenzior
2019-10-22 23:46     ` Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 09/11] wsc: Accept extra IEs in wsc_new_p2p_enrollee Andrew Zaborowski
2019-10-21 13:55 ` [PATCH 10/11] wiphy: Add wiphy_get_max_roc_duration Andrew Zaborowski
2019-10-22  3:26   ` Denis Kenzior
2019-10-21 13:55 ` [PATCH 11/11] wiphy: Add wiphy_get_supported_rates Andrew Zaborowski
2019-10-22 14:53 ` [PATCH 01/11] netdev: Add a wdev_id based frame watch API Denis Kenzior
2019-10-22 23:56   ` Andrew Zaborowski
2019-10-23  0:23     ` Denis Kenzior
2019-10-23  1:04       ` Andrew Zaborowski
2019-10-23  1:32         ` Denis Kenzior
2019-10-24  0:59           ` Andrew Zaborowski
2019-10-24  2:53             ` Denis Kenzior
2019-10-24  3:22               ` Andrew Zaborowski
2019-10-24 15:29                 ` Denis Kenzior
2019-10-24 21:47                   ` Andrew Zaborowski
2019-10-24 22:16                     ` Denis Kenzior
2019-10-24 22:45                       ` Andrew Zaborowski
2019-10-25  1:27                         ` Denis Kenzior
2019-10-25  2:59                           ` Andrew Zaborowski
2019-10-25  3:56                             ` Denis Kenzior
2019-10-25  4:42                               ` Andrew Zaborowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191021135510.12657-2-balrogg@gmail.com \
    --to=balrogg@gmail.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox