blob: dd1a9fe7e36fcad25347dbb789a246c85f3e47f7 [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));
developer5f18e6c2021-07-28 11:55:08 +080075 }
76
77 return 0;
78}
79
80int mt76_ap_wireless_set(int idx, int argc, char **argv)
81{
82 struct nl_msg *msg;
83 void *data;
84 int ret;
85
86 if (argc < 1)
87 return 1;
88
89 if (unl_genl_init(&unl, "nl80211") < 0) {
90 fprintf(stderr, "Failed to connect to nl80211\n");
91 return 2;
92 }
93
94 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
95
96 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
97 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
98 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL))
99 return false;
100
101 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
102
103 mt76_ap_wireless_set_attr(msg, argc, argv);
104
105 nla_nest_end(msg, data);
106
107 ret = unl_genl_request(&unl, msg, NULL, NULL);
108 if (ret)
109 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
110
111 unl_free(&unl);
112
113 return ret;
114}