diff mbox series

[04/10] nl80211util: add nl80211_parse_nested

Message ID 20240618165854.113598-4-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [01/10] netdev: downgrade L_WARN_ON for ensure_eapol_registered | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood June 18, 2024, 4:58 p.m. UTC
Add a nested attribute parser. For the first supported attribute
add NL80211_ATTR_SURVEY_INFO.

This allows parsing of nested attributes in the same convenient
way as nl80211_parse_attrs but allows for support of any level of
nested attributes provided that a handler is added for each.
---
 src/nl80211util.c | 37 +++++++++++++++++++++++++++++++++++++
 src/nl80211util.h |  1 +
 2 files changed, 38 insertions(+)
diff mbox series

Patch

diff --git a/src/nl80211util.c b/src/nl80211util.c
index 4a402e2f..0076aa51 100644
--- a/src/nl80211util.c
+++ b/src/nl80211util.c
@@ -193,6 +193,20 @@  static attr_handler handler_for_nl80211(int type)
 	return NULL;
 }
 
+static attr_handler handler_for_survey_info(int type)
+{
+	switch (type) {
+	case NL80211_SURVEY_INFO_NOISE:
+		return extract_u8;
+	case NL80211_SURVEY_INFO_FREQUENCY:
+		return extract_uint32;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
 struct attr_entry {
 	uint16_t type;
 	void *data;
@@ -297,6 +311,29 @@  int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...)
 	return ret;
 }
 
+int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...)
+{
+	handler_for_type handler;
+	va_list args;
+	int ret;
+
+	switch (type) {
+	case NL80211_ATTR_SURVEY_INFO:
+		handler = handler_for_survey_info;
+		break;
+	default:
+		return -ENOTSUP;
+	}
+
+	va_start(args, tag);
+
+	ret = parse_attrs(attr, handler, tag, args);
+
+	va_end(args);
+
+	return ret;
+}
+
 struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
 						const uint8_t addr[static 6],
 						uint16_t reason_code)
diff --git a/src/nl80211util.h b/src/nl80211util.h
index 6f7b9eab..d966e049 100644
--- a/src/nl80211util.h
+++ b/src/nl80211util.h
@@ -28,6 +28,7 @@  struct band_freq_attrs;
 struct handshake_state;
 
 int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...);
+int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...);
 
 struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
 						const uint8_t addr[static 6],