blob: ec1cea030128bb20bac2cc1ed731ff145c1c4af3 [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
6static int mt76_hemu_onoff_set_attr(struct nl_msg *msg, int argc, char **argv)
7{
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))
17 nla_put_u8(msg, MTK_VENDOR_ATTR_HEMU_CTRL_ONOFF, strtoul(val, NULL, 0));
18
19 return 0;
20}
21
22int mt76_hemu_onoff_set(int idx, int argc, char **argv)
23{
24 struct nl_msg *msg;
25 void *data;
26 int ret;
27
28 if (argc < 1)
29 return 1;
30
31 if (unl_genl_init(&unl, "nl80211") < 0) {
32 fprintf(stderr, "Failed to connect to nl80211\n");
33 return 2;
34 }
35
36 msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false);
37
38 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) ||
39 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) ||
40 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL))
41 return false;
42
43 data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED);
44 if (!data)
45 return -ENOMEM;
46
47 mt76_hemu_onoff_set_attr(msg, argc, argv);
48
49 nla_nest_end(msg, data);
50
51 ret = unl_genl_request(&unl, msg, NULL, NULL);
52 if (ret)
53 fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret));
54
55 unl_free(&unl);
56
57 return ret;
58}