blob: fb4157ea9c5d0e173dca64f12cadf448e102f40f [file] [log] [blame]
developer7f1a58f2022-05-26 16:00:32 -07001/* Copyright (C) 2021 Mediatek Inc. */
2#define _GNU_SOURCE
3
4#include "mt76-vendor.h"
5
developer57de9b72023-02-20 11:15:54 +08006static int mt76_mu_onoff_set_attr(struct nl_msg *msg, int argc, char **argv)
developer7f1a58f2022-05-26 16:00:32 -07007{
8 char *val;
9
10 val = strchr(argv[0], '=');
11 if (!val)
12 return -EINVAL;
13
14 *(val++) = 0;
15
16 if (!strncmp(argv[0], "onoff", 5))
developer57de9b72023-02-20 11:15:54 +080017 nla_put_u8(msg, MTK_VENDOR_ATTR_MU_CTRL_ONOFF,
18 strtoul(val, NULL, 0));
developer7f1a58f2022-05-26 16:00:32 -070019
20 return 0;
21}
22
developer57de9b72023-02-20 11:15:54 +080023int mt76_mu_onoff_set(int idx, int argc, char **argv)
developer7f1a58f2022-05-26 16:00:32 -070024{
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) ||
developer57de9b72023-02-20 11:15:54 +080041 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
42 MTK_NL80211_VENDOR_SUBCMD_MU_CTRL))
developer7f1a58f2022-05-26 16:00:32 -070043 return false;
44
45 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
46 if (!data)
47 return -ENOMEM;
48
developer57de9b72023-02-20 11:15:54 +080049 mt76_mu_onoff_set_attr(msg, argc, argv);
developer7f1a58f2022-05-26 16:00:32 -070050
51 nla_nest_end(msg, data);
52
53 ret = unl_genl_request(&unl, msg, NULL, NULL);
54 if (ret)
55 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
56
57 unl_free(&unl);
58
59 return ret;
developer57de9b72023-02-20 11:15:54 +080060}