Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: iwd@lists.01.org
Subject: [PATCH 04/18] p2p: Use nl80211_parse_attrs
Date: Sat, 11 Jul 2020 03:00:39 +0200	[thread overview]
Message-ID: <20200711010053.224223-4-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <20200711010053.224223-1-andrew.zaborowski@intel.com>

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

Simplify p2p_device_update_from_genl by making use of nl80211_parse_attrs.
---
 src/p2p.c | 72 +++++++++++++------------------------------------------
 1 file changed, 16 insertions(+), 56 deletions(-)

diff --git a/src/p2p.c b/src/p2p.c
index c3e4d8dd..0d580ce3 100644
--- a/src/p2p.c
+++ b/src/p2p.c
@@ -3044,74 +3044,34 @@ static void p2p_mlme_notify(struct l_genl_msg *msg, void *user_data)
 struct p2p_device *p2p_device_update_from_genl(struct l_genl_msg *msg,
 						bool create)
 {
-	struct l_genl_attr attr;
-	uint16_t type, len;
-	const void *data;
-	const uint8_t *ifaddr = NULL;
-	const uint64_t *wdev_id = NULL;
-	struct wiphy *wiphy = NULL;
+	const uint8_t *ifaddr;
+	uint32_t iftype;
+	uint64_t wdev_id;
+	uint32_t wiphy_id;
+	struct wiphy *wiphy;
 	struct p2p_device *dev;
 	char hostname[HOST_NAME_MAX + 1];
 	char *str;
 	unsigned int uint_val;
 
-	if (!l_genl_attr_init(&attr, msg))
-		return NULL;
-
-	while (l_genl_attr_next(&attr, &type, &len, &data)) {
-		switch (type) {
-		case NL80211_ATTR_WDEV:
-			if (len != sizeof(uint64_t)) {
-				l_warn("Invalid wdev index attribute");
-				return NULL;
-			}
-
-			wdev_id = data;
-			break;
-
-		case NL80211_ATTR_WIPHY:
-			if (len != sizeof(uint32_t)) {
-				l_warn("Invalid wiphy attribute");
-				return NULL;
-			}
-
-			wiphy = wiphy_find(*((uint32_t *) data));
-			break;
-
-		case NL80211_ATTR_IFTYPE:
-			if (len != sizeof(uint32_t)) {
-				l_warn("Invalid interface type attribute");
-				return NULL;
-			}
-
-			if (*((uint32_t *) data) != NL80211_IFTYPE_P2P_DEVICE)
-				return NULL;
-
-			break;
-
-		case NL80211_ATTR_MAC:
-			if (len != ETH_ALEN) {
-				l_warn("Invalid interface address attribute");
-				return NULL;
-			}
-
-			ifaddr = data;
-			break;
-		}
-	}
-
-	if (!wiphy || !wdev_id || !ifaddr) {
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_WDEV, &wdev_id,
+				NL80211_ATTR_WIPHY, &wiphy_id,
+				NL80211_ATTR_IFTYPE, &iftype,
+				NL80211_ATTR_MAC, &ifaddr,
+				NL80211_ATTR_UNSPEC) < 0 ||
+			L_WARN_ON(!(wiphy = wiphy_find(wiphy_id))) ||
+			L_WARN_ON(iftype != NL80211_IFTYPE_P2P_DEVICE)) {
 		l_warn("Unable to parse interface information");
 		return NULL;
 	}
 
 	if (create) {
-		if (p2p_device_find(*wdev_id)) {
-			l_debug("Duplicate p2p device %" PRIx64, *wdev_id);
+		if (p2p_device_find(wdev_id)) {
+			l_debug("Duplicate p2p device %" PRIx64, wdev_id);
 			return NULL;
 		}
 	} else {
-		dev = p2p_device_find(*wdev_id);
+		dev = p2p_device_find(wdev_id);
 		if (!dev)
 			return NULL;
 
@@ -3120,7 +3080,7 @@ struct p2p_device *p2p_device_update_from_genl(struct l_genl_msg *msg,
 	}
 
 	dev = l_new(struct p2p_device, 1);
-	dev->wdev_id = *wdev_id;
+	dev->wdev_id = wdev_id;
 	memcpy(dev->addr, ifaddr, ETH_ALEN);
 	dev->nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME);
 	dev->wiphy = wiphy;
-- 
2.25.1

  parent reply	other threads:[~2020-07-11  1:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-11  1:00 [PATCH 01/18] p2p: Stop discovery after GO Negotiation Req error Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 02/18] p2p: Update peer->device_addr when updating peer->bss Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 03/18] p2p: Initialize dev->discovery_users in p2p_device_request_discovery Andrew Zaborowski
2020-07-11  1:00 ` Andrew Zaborowski [this message]
2020-07-11  1:00 ` [PATCH 05/18] p2p: Implement the Peer.Device property Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 06/18] man iwd.debug: Document IWD_GENL_DEBUG Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 07/18] test: Set WSC.PushButton call timeout to 120s Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 08/18] scan: Extract WFD IE payload into struct bss Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 09/18] p2putil: Extract WFD IE payloads from P2P Action frames Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 10/18] p2putil: Add WFD IEs when building " Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 11/18] p2p: Implement the p2p.ServiceManager interface Andrew Zaborowski
2020-07-13 19:47   ` Denis Kenzior
2020-07-15 14:25     ` Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 12/18] p2p: Add the p2p.Display interface on WFD-capable peers Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 13/18] p2p: Add WFD IEs in GO Negotiation and association Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 14/18] doc: Wi-Fi Display DBus API doc Andrew Zaborowski
2020-07-13 19:51   ` Denis Kenzior
2020-07-11  1:00 ` [PATCH 15/18] netconfig: Implement netconfig_get_dhcp_server_ipv4 Andrew Zaborowski
2020-07-13 19:53   ` Denis Kenzior
2020-07-11  1:00 ` [PATCH 16/18] p2p: Add ConnectedInterface and ConnectedIP Peer properties Andrew Zaborowski
2020-07-13 19:54   ` Denis Kenzior
2020-07-11  1:00 ` [PATCH 17/18] doc: Document Peer.ConnectedInterface and ConnectedIP Andrew Zaborowski
2020-07-11  1:00 ` [PATCH 18/18] test: Add a sample Wi-Fi Display source app Andrew Zaborowski
2020-07-13 19:25 ` [PATCH 01/18] p2p: Stop discovery after GO Negotiation Req error Denis Kenzior

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=20200711010053.224223-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox