difos/package/network/utils/iw/patches/310-vif_radio_mask.patch
Felix Fietkau 5c1ee08e2d iw: add multi-radio support
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-22 14:40:43 +02:00

99 lines
2.4 KiB
Diff

--- a/interface.c
+++ b/interface.c
@@ -226,6 +226,43 @@ nla_put_failure:
return 1;
}
+static int parse_radio_list(char *str, struct nl_msg *msg)
+{
+ unsigned int mask = 0;
+ unsigned long id;
+ char *end;
+
+ if (!str)
+ return 1;
+
+ if (!strcmp(str, "all"))
+ goto out;
+
+ while (1) {
+ if (!*str)
+ return 1;
+
+ id = strtoul(str, &end, 0);
+ if (id > 31)
+ return 1;
+
+ mask |= 1 << id;
+ if (!*end)
+ break;
+
+ if (end == str || *end != ',')
+ return 1;
+
+ str = end + 1;
+ }
+
+out:
+ NLA_PUT_U32(msg, NL80211_ATTR_VIF_RADIO_MASK, mask);
+ return 0;
+nla_put_failure:
+ return 1;
+}
+
static int handle_interface_add(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
@@ -287,6 +324,15 @@ try_another:
fprintf(stderr, "flags error\n");
return 2;
}
+ } else if (strcmp(argv[0], "radios") == 0) {
+ argc--;
+ argv++;
+ if (parse_radio_list(argv[0], msg)) {
+ fprintf(stderr, "Invalid radio list\n");
+ return 2;
+ }
+ argc--;
+ argv++;
} else {
return 1;
}
@@ -306,14 +352,14 @@ try_another:
nla_put_failure:
return -ENOBUFS;
}
-COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]",
+COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>] [radios all|<id>[,<id>...]]",
NL80211_CMD_NEW_INTERFACE, 0, CIB_PHY, handle_interface_add,
"Add a new virtual interface with the given configuration.\n"
IFACE_TYPES "\n\n"
"The flags are only used for monitor interfaces, valid flags are:\n"
VALID_FLAGS "\n\n"
"The mesh_id is used only for mesh mode.");
-COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]",
+COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>] [radios all|<id>[,<id>...]]",
NL80211_CMD_NEW_INTERFACE, 0, CIB_NETDEV, handle_interface_add, NULL);
static int handle_interface_del(struct nl80211_state *state,
@@ -493,6 +539,19 @@ static int print_iface_handler(struct nl
printf("\n");
}
}
+
+ if (tb_msg[NL80211_ATTR_VIF_RADIO_MASK]) {
+ uint32_t mask = nla_get_u32(tb_msg[NL80211_ATTR_VIF_RADIO_MASK]);
+ int i;
+
+ if (mask) {
+ printf("%s\tRadios:", indent);
+ for (i = 0; mask; i++, mask >>= 1)
+ if (mask & 1)
+ printf(" %d", i);
+ printf("\n");
+ }
+ }
return NL_SKIP;
}