blob: 6bb1e185f9e5bd84f5dadcce7c11cc071ddd643a [file] [log] [blame]
developer29b831d2022-06-21 10:01:42 -07001/* Copyright (C) 2021 Mediatek Inc. */
2#define _GNU_SOURCE
3
4#include "mt76-vendor.h"
5
6static struct nla_policy
developer52068512022-06-21 18:01:19 -07007phy_capa_ctrl_policy[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_CTRL] = {
8 [MTK_VENDOR_ATTR_PHY_CAPA_CTRL_SET] = { .type = NLA_NESTED },
9 [MTK_VENDOR_ATTR_PHY_CAPA_CTRL_DUMP] = { .type = NLA_NESTED },
developer29b831d2022-06-21 10:01:42 -070010};
11
12static struct nla_policy
developer52068512022-06-21 18:01:19 -070013phy_capa_dump_policy[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP] = {
14 [MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_BSS] = { .type = NLA_U16 },
15 [MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_STA] = { .type = NLA_U16 },
developer29b831d2022-06-21 10:01:42 -070016};
17
18static int mt76_phy_capa_dump_cb(struct nl_msg *msg, void *arg)
19{
developer52068512022-06-21 18:01:19 -070020 struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_CTRL];
developer29b831d2022-06-21 10:01:42 -070021 struct nlattr *tb_dump[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP];
22 struct nlattr *attr;
developer52068512022-06-21 18:01:19 -070023 u16 max_bss, max_sta;
developer29b831d2022-06-21 10:01:42 -070024
25 attr = unl_find_attr(&unl, msg, NL80211_ATTR_VENDOR_DATA);
26 if (!attr) {
27 fprintf(stderr, "Testdata attribute not found\n");
28 return NL_SKIP;
29 }
30
31 nla_parse_nested(tb, MTK_VENDOR_ATTR_PHY_CAPA_CTRL_MAX,
32 attr, phy_capa_ctrl_policy);
33
34 if (!tb[MTK_VENDOR_ATTR_PHY_CAPA_CTRL_DUMP])
35 return NL_SKIP;
36
developer52068512022-06-21 18:01:19 -070037 nla_parse_nested(tb_dump, MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX,
developer29b831d2022-06-21 10:01:42 -070038 tb[MTK_VENDOR_ATTR_PHY_CAPA_CTRL_DUMP], phy_capa_dump_policy);
39
40 max_bss = nla_get_u16(tb_dump[MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_BSS]);
41 max_sta = nla_get_u16(tb_dump[MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX_SUPPORTED_STA]);
42
developer52068512022-06-21 18:01:19 -070043 printf("[vendor] Max Supported BSS=%u "
44 " Max Supported STA=%u\n", max_bss, max_sta);
developer29b831d2022-06-21 10:01:42 -070045
46 return 0;
47}
48
49int mt76_phy_capa_dump(int idx, int argc, char **argv)
50{
51 struct nl_msg *msg;
52 void *data;
53 int ret = -EINVAL;
54
55 if (unl_genl_init(&unl, "nl80211") < 0) {
56 fprintf(stderr, "Failed to connect to nl80211\n");
57 return 2;
58 }
59
60 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, true);
61
62 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
63 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
64 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL))
65 return false;
66
67 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
68 if (!data)
69 goto out;
70
71 nla_nest_end(msg, data);
72
73 ret = unl_genl_request(&unl, msg, mt76_phy_capa_dump_cb, NULL);
74 if (ret)
75 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
76
77out:
78 unl_free(&unl);
79
80 return ret;
81}