blob: e8548205a527a5ea804091c1fab1e666e7827b5c [file] [log] [blame]
developer5f18e6c2021-07-28 11:55:08 +08001/* Copyright (C) 2021 Mediatek Inc. */
2#define _GNU_SOURCE
3
4#include "mt76-vendor.h"
5
6static int mt76_ap_rfeatures_set_attr(struct nl_msg *msg, int argc, char **argv)
7{
8 char *val;
9
10 val = strchr(argv[0], '=');
11 if (val)
12 *(val++) = 0;
13
14 if (!strncmp(argv[0], "he_gi", 5)) {
15 nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_GI, strtoul(val, NULL, 0));
16 } else if (!strncmp(argv[0], "he_ltf", 6)) {
17 nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_LTF, strtoul(val, NULL, 0));
developer31b1a282021-08-04 14:13:00 +080018 } else if (!strncmp(argv[0], "trig_type", 9)) {
19 nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_TRIG_TYPE, strtoul(val, NULL, 0));
20 } else if (!strncmp(argv[0], "ack_policy", 10)) {
21 nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_ACK_PLCY, strtoul(val, NULL, 0));
developer5f18e6c2021-07-28 11:55:08 +080022 }
23
24 return 0;
25}
26
27int mt76_ap_rfeatures_set(int idx, int argc, char **argv)
28{
29 struct nl_msg *msg;
30 void *data;
31 int ret;
32
33 if (argc < 1)
34 return 1;
35
36 if (unl_genl_init(&unl, "nl80211") < 0) {
37 fprintf(stderr, "Failed to connect to nl80211\n");
38 return 2;
39 }
40
41 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
42
43 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
44 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
45 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL))
46 return false;
47
48 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
49
50 mt76_ap_rfeatures_set_attr(msg, argc, argv);
51
52 nla_nest_end(msg, data);
53
54 ret = unl_genl_request(&unl, msg, NULL, NULL);
55 if (ret)
56 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
57
58 unl_free(&unl);
59
60 return ret;
61}
62
63static int mt76_ap_wireless_set_attr(struct nl_msg *msg, int argc, char **argv)
64{
65 char *val;
66
67 val = strchr(argv[0], '=');
68 if (val)
69 *(val++) = 0;
70
71 if (!strncmp(argv[0], "fixed_mcs", 9)) {
72 nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_FIXED_MCS, strtoul(val, NULL, 0));
developer507ff0c2021-07-30 14:51:55 +080073 } else if (!strncmp(argv[0], "ofdma", 5)) {
74 nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_FIXED_OFDMA, strtoul(val, NULL, 0));
developerb72be592021-08-16 10:58:59 +080075 } else if (!strncmp(argv[0], "ppdu_type", 9)) {
76 nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_PPDU_TX_TYPE, strtoul(val, NULL, 0));
77 } else if (!strncmp(argv[0], "nusers_ofdma", 12)) {
78 nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_NUSERS_OFDMA, strtoul(val, NULL, 0));
developer5f18e6c2021-07-28 11:55:08 +080079 }
80
81 return 0;
82}
83
84int mt76_ap_wireless_set(int idx, int argc, char **argv)
85{
86 struct nl_msg *msg;
87 void *data;
88 int ret;
89
90 if (argc < 1)
91 return 1;
92
93 if (unl_genl_init(&unl, "nl80211") < 0) {
94 fprintf(stderr, "Failed to connect to nl80211\n");
95 return 2;
96 }
97
98 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
99
100 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
101 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
102 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL))
103 return false;
104
105 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
106
107 mt76_ap_wireless_set_attr(msg, argc, argv);
108
109 nla_nest_end(msg, data);
110
111 ret = unl_genl_request(&unl, msg, NULL, NULL);
112 if (ret)
113 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
114
115 unl_free(&unl);
116
117 return ret;
118}