blob: 32c9504bbac6879a535ec93f4c41258c356e7b44 [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
7phy_capa_ctrl_policy[NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL] = {
8 [MTK_VENDOR_ATTR_PHY_CAPA_CTRL_SET] = {.type = NLA_NESTED },
9 [MTK_VENDOR_ATTR_PHY_CAPA_CTRL_DUMP] = {.type = NLA_NESTED },
10};
11
12static struct nla_policy
13phy_capa_dump_policy[NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL] = {
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 },
16};
17
18static int mt76_phy_capa_dump_cb(struct nl_msg *msg, void *arg)
19{
20 struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP];
21 struct nlattr *tb_dump[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP];
22 struct nlattr *attr;
23 int max_bss, max_sta;
24
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
37 nla_parse_nested(tb_dump, NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP,
38 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
43 printf("[vendor] Max Supported BSS=%d "
44 " Max Supported STA=%d\n", __func__, max_bss, max_sta);
45
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}