developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2021 Mediatek Inc. */ |
| 2 | #define _GNU_SOURCE |
| 3 | |
| 4 | #include "mt76-vendor.h" |
| 5 | |
| 6 | static struct nla_policy |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 7 | phy_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 }, |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | static struct nla_policy |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 13 | phy_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 }, |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | static int mt76_phy_capa_dump_cb(struct nl_msg *msg, void *arg) |
| 19 | { |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 20 | struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_CTRL]; |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 21 | struct nlattr *tb_dump[NUM_MTK_VENDOR_ATTRS_PHY_CAPA_DUMP]; |
| 22 | struct nlattr *attr; |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 23 | u16 max_bss, max_sta; |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 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 | |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 37 | nla_parse_nested(tb_dump, MTK_VENDOR_ATTR_PHY_CAPA_DUMP_MAX, |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 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 | |
developer | 5206851 | 2022-06-21 18:01:19 -0700 | [diff] [blame] | 43 | printf("[vendor] Max Supported BSS=%u " |
| 44 | " Max Supported STA=%u\n", max_bss, max_sta); |
developer | 29b831d | 2022-06-21 10:01:42 -0700 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | int 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 | |
| 77 | out: |
| 78 | unl_free(&unl); |
| 79 | |
| 80 | return ret; |
| 81 | } |