blob: 5f4837cecf632c90e8fc6f2650d8c676d207b6c5 [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));
18 }
19
20 return 0;
21}
22
23int mt76_ap_rfeatures_set(int idx, int argc, char **argv)
24{
25 struct nl_msg *msg;
26 void *data;
27 int ret;
28
29 if (argc < 1)
30 return 1;
31
32 if (unl_genl_init(&unl, "nl80211") < 0) {
33 fprintf(stderr, "Failed to connect to nl80211\n");
34 return 2;
35 }
36
37 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
38
39 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
40 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
41 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL))
42 return false;
43
44 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
45
46 mt76_ap_rfeatures_set_attr(msg, argc, argv);
47
48 nla_nest_end(msg, data);
49
50 ret = unl_genl_request(&unl, msg, NULL, NULL);
51 if (ret)
52 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
53
54 unl_free(&unl);
55
56 return ret;
57}
58
59static int mt76_ap_wireless_set_attr(struct nl_msg *msg, int argc, char **argv)
60{
61 char *val;
62
63 val = strchr(argv[0], '=');
64 if (val)
65 *(val++) = 0;
66
67 if (!strncmp(argv[0], "fixed_mcs", 9)) {
68 nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_FIXED_MCS, strtoul(val, NULL, 0));
69 }
70
71 return 0;
72}
73
74int mt76_ap_wireless_set(int idx, int argc, char **argv)
75{
76 struct nl_msg *msg;
77 void *data;
78 int ret;
79
80 if (argc < 1)
81 return 1;
82
83 if (unl_genl_init(&unl, "nl80211") < 0) {
84 fprintf(stderr, "Failed to connect to nl80211\n");
85 return 2;
86 }
87
88 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
89
90 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
91 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
92 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL))
93 return false;
94
95 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
96
97 mt76_ap_wireless_set_attr(msg, argc, argv);
98
99 nla_nest_end(msg, data);
100
101 ret = unl_genl_request(&unl, msg, NULL, NULL);
102 if (ret)
103 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
104
105 unl_free(&unl);
106
107 return ret;
108}