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. [link-id ] If found, put NL80211_ATTR_MLO_LINK_ID and remove the assignment from the argv range. Signed-off-by: Zong-Zhe Yang --- v2: newly added --- iw.h | 1 + util.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/iw.h b/iw.h index 145b058d86ba..1d87f011e7be 100644 --- 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 36c118513e3f..ad265c1dc007 100644 --- a/util.c +++ b/util.c @@ -2378,3 +2378,43 @@ 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; + int pos = -1; + int i; + + for (i = 0; i < *argc; i++) { + if (strcmp(argv[i], "link-id") == 0) { + if (pos >= 0) + goto usage; + + if (i + 1 >= *argc) + goto usage; + + link_id = strtol(argv[i + 1], &endptr, 0); + if (*endptr != '\0') + goto usage; + + pos = i; + } + } + + if (pos == -1) + return 0; + + memmove(argv + pos, argv + pos + 2, + sizeof(*argv) * (*argc - pos - 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; +} -- 2.39.0