]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: util: support parsing link id
authorZong-Zhe Yang <kevin_yang@realtek.com>
Mon, 22 Sep 2025 07:10:14 +0000 (15:10 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 27 Oct 2025 10:36:51 +0000 (11:36 +0100)
For NL80211_FLAG_MLO_VALID_LINK_ID cases, MLD needs to assign link id,
but non-MLD doesn't. Add support of parsing link id where the pattern
is as below. To avoid mess where some fields could have "link-id" as a
value, this pattern is only parsed at the beginning of argv.

[link-id <LINK ID>]

If found, put NL80211_ATTR_MLO_LINK_ID and remove the assignment from
the argv range.

Signed-off-by: Zong-Zhe Yang <kevin_yang@realtek.com>
Link: https://patch.msgid.link/20250922071017.11954-2-kevin_yang@realtek.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
iw.h
util.c

diff --git a/iw.h b/iw.h
index 145b058d86ba3c7ae16ffcfd5fdb5e92f7966955..df9ea1375dae256d0ec17d8e66dde3f5935da1a3 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -305,6 +305,7 @@ int set_bitrates(struct nl_msg *msg, int argc, char **argv,
                 enum nl80211_attrs attr);
 
 int calc_s1g_ch_center_freq(__u8 ch_index, __u8 s1g_oper_class);
+int parse_link_id(struct nl_msg *msg, int *argc, char ***argv);
 
 /* sections */
 DECLARE_SECTION(ap);
diff --git a/util.c b/util.c
index 36c118513e3ffa78398011ee803b90faff440760..a96fbf968244970685b75044b112bef5d7471bba 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2378,3 +2378,34 @@ void print_s1g_capability(const uint8_t *caps)
        /* Last 2 bits are reserved */
 #undef PRINT_S1G_CAP
 }
+
+int parse_link_id(struct nl_msg *msg, int *argc, char ***argv)
+{
+       unsigned int link_id;
+       char *endptr;
+
+       if (*argc < 1)
+               return 0;
+
+       if (strcmp((*argv)[0], "link-id") != 0)
+               return 0;
+
+       if (*argc == 1)
+               goto usage;
+
+       link_id = strtol((*argv)[1], &endptr, 0);
+       if (*endptr != '\0')
+               goto usage;
+
+       *argv += 2;
+       *argc -= 2;
+
+       NLA_PUT_U8(msg, NL80211_ATTR_MLO_LINK_ID, link_id);
+       return 0;
+
+usage:
+       return HANDLER_RET_USAGE;
+
+nla_put_failure:
+       return -ENOBUFS;
+}