All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: iwd@lists.01.org
Subject: [PATCH 3/8] scan: Parse P2P IEs according to frame type
Date: Thu, 24 Oct 2019 06:29:55 +0200	[thread overview]
Message-ID: <20191024043000.13687-3-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <20191024043000.13687-1-andrew.zaborowski@intel.com>

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

Save the source frame type in struct scan_bss as it may affect how some
of the data in the struct should be parsed.  Also replace the P2P IE
payload data in that struct with a union containing pre-parsed p2p
attributes corresponding to the frame type.

This means users don't have to call the parsers in p2putil.c on that
data, which wouldn't have worked anyway because we those parsers were
assuming the raw concatenated P2P IEs as a parameter instead of the
payload extracted with ie_tlv_extract_p2p_payload.
---
 src/scan.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++-------
 src/scan.h | 17 ++++++++++--
 2 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/src/scan.c b/src/scan.c
index 2d54af12..2c676890 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -45,6 +45,7 @@
 #include "src/nl80211cmd.h"
 #include "src/nl80211util.h"
 #include "src/util.h"
+#include "src/p2putil.h"
 #include "src/scan.h"
 
 #define SCAN_MAX_INTERVAL 320
@@ -987,6 +988,38 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
 		}
 	}
 
+	bss->wsc = ie_tlv_extract_wsc_payload(data, len, &bss->wsc_size);
+
+	switch (bss->source_frame) {
+	case SCAN_BSS_PROBE_RESP:
+	{
+		struct p2p_probe_resp info;
+
+		if (p2p_parse_probe_resp(data, len, &info) == 0)
+			bss->p2p_probe_resp_info = l_memdup(&info, sizeof(info));
+
+		break;
+	}
+	case SCAN_BSS_PROBE_REQ:
+	{
+		struct p2p_probe_req info;
+
+		if (p2p_parse_probe_req(data, len, &info) == 0)
+			bss->p2p_probe_req_info = l_memdup(&info, sizeof(info));
+
+		break;
+	}
+	case SCAN_BSS_BEACON:
+	{
+		struct p2p_beacon info;
+
+		if (p2p_parse_beacon(data, len, &info) == 0)
+			bss->p2p_beacon_info = l_memdup(&info, sizeof(info));
+
+		break;
+	}
+	}
+
 	return have_ssid;
 }
 
@@ -995,9 +1028,12 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)
 	uint16_t type, len;
 	const void *data;
 	struct scan_bss *bss;
+	const uint8_t *ies = NULL;
+	size_t ies_len;
 
 	bss = l_new(struct scan_bss, 1);
 	bss->utilization = 127;
+	bss->source_frame = SCAN_BSS_BEACON;
 
 	while (l_genl_attr_next(attr, &type, &len, &data)) {
 		switch (type) {
@@ -1025,20 +1061,19 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)
 
 			bss->signal_strength = *((int32_t *) data);
 			break;
+		case NL80211_BSS_PRESP_DATA:
+			bss->source_frame = SCAN_BSS_PROBE_RESP;
+			break;
 		case NL80211_BSS_INFORMATION_ELEMENTS:
-			if (!scan_parse_bss_information_elements(bss,
-								data, len))
-				goto fail;
-
-			bss->wsc = ie_tlv_extract_wsc_payload(data, len,
-								&bss->wsc_size);
-			bss->p2p = ie_tlv_extract_p2p_payload(data, len,
-								&bss->p2p_size);
-
+			ies = data;
+			ies_len = len;
 			break;
 		}
 	}
 
+	if (ies && !scan_parse_bss_information_elements(bss, ies, ies_len))
+		goto fail;
+
 	return bss;
 
 fail:
@@ -1198,9 +1233,33 @@ void scan_bss_free(struct scan_bss *bss)
 	l_free(bss->rsne);
 	l_free(bss->wpa);
 	l_free(bss->wsc);
-	l_free(bss->p2p);
 	l_free(bss->osen);
 	l_free(bss->rc_ie);
+
+	switch (bss->source_frame) {
+	case SCAN_BSS_PROBE_RESP:
+		if (!bss->p2p_probe_resp_info)
+			break;
+
+		p2p_free_probe_resp(bss->p2p_probe_resp_info);
+		l_free(bss->p2p_probe_resp_info);
+		break;
+	case SCAN_BSS_PROBE_REQ:
+		if (!bss->p2p_probe_req_info)
+			break;
+
+		p2p_free_probe_req(bss->p2p_probe_req_info);
+		l_free(bss->p2p_probe_req_info);
+		break;
+	case SCAN_BSS_BEACON:
+		if (!bss->p2p_beacon_info)
+			break;
+
+		p2p_free_beacon(bss->p2p_beacon_info);
+		l_free(bss->p2p_beacon_info);
+		break;
+	}
+
 	l_free(bss);
 }
 
diff --git a/src/scan.h b/src/scan.h
index dabce95f..a3129dea 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -40,6 +40,15 @@ typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata);
 
 struct scan_freq_set;
 struct ie_rsn_info;
+struct p2p_probe_resp;
+struct p2p_probe_req;
+struct p2p_beacon;
+
+enum scan_bss_frame_type {
+	SCAN_BSS_PROBE_RESP,
+	SCAN_BSS_PROBE_REQ,
+	SCAN_BSS_BEACON,
+};
 
 struct scan_bss {
 	uint8_t addr[6];
@@ -51,8 +60,12 @@ struct scan_bss {
 	uint8_t *osen;
 	uint8_t *wsc;		/* Concatenated WSC IEs */
 	ssize_t wsc_size;	/* Size of Concatenated WSC IEs */
-	uint8_t *p2p;		/* Concatenated P2P IEs */
-	ssize_t p2p_size;	/* Size of Concatenated P2P IEs */
+	enum scan_bss_frame_type source_frame;
+	union {
+		struct p2p_probe_resp *p2p_probe_resp_info;
+		struct p2p_probe_req *p2p_probe_req_info;
+		struct p2p_beacon *p2p_beacon_info;
+	};
 	uint8_t mde[3];
 	uint8_t ssid[32];
 	uint8_t ssid_len;
-- 
2.20.1

  parent reply	other threads:[~2019-10-24  4:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24  4:29 [PATCH 1/8] wiphy: Add wiphy_get_supported_rates Andrew Zaborowski
2019-10-24  4:29 ` [PATCH 2/8] scan: Hide CCK rates if no_cck_rates set Andrew Zaborowski
2019-10-24  4:29 ` Andrew Zaborowski [this message]
2019-10-24  4:29 ` [PATCH 4/8] scan: Add scan_bss_new_from_probe_req Andrew Zaborowski
2019-10-24  4:29 ` [PATCH 5/8] nl80211util: Fail in nl80211_parse_attrs if attribute missing Andrew Zaborowski
2019-10-25 18:53   ` Denis Kenzior
2019-10-24  4:29 ` [PATCH 6/8] monitor: Fix the OUI check for P2P action frames Andrew Zaborowski
2019-10-24  4:29 ` [PATCH 7/8] p2putil: Replace constants with wifi_alliance_oui Andrew Zaborowski
2019-10-25 18:34   ` Denis Kenzior
2019-10-24  4:30 ` [PATCH 8/8] p2putils: Fix length in Channel List parsing Andrew Zaborowski
2019-10-25 18:34   ` Denis Kenzior
2019-10-25 19:11 ` [PATCH 1/8] wiphy: Add wiphy_get_supported_rates Denis Kenzior
2019-10-26  2:33   ` 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=20191024043000.13687-3-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.