developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2021 Mediatek Inc. */ |
| 2 | #define _GNU_SOURCE |
| 3 | |
| 4 | #include "mt76-vendor.h" |
| 5 | |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 6 | static int mt76_mu_onoff_set_attr(struct nl_msg *msg, int argc, char **argv) |
developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 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)) |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 17 | nla_put_u8(msg, MTK_VENDOR_ATTR_MU_CTRL_ONOFF, |
| 18 | strtoul(val, NULL, 0)); |
developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 23 | int mt76_mu_onoff_set(int idx, int argc, char **argv) |
developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 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) || |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 41 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 42 | MTK_NL80211_VENDOR_SUBCMD_MU_CTRL)) |
developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 43 | return false; |
| 44 | |
| 45 | data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
| 46 | if (!data) |
| 47 | return -ENOMEM; |
| 48 | |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 49 | mt76_mu_onoff_set_attr(msg, argc, argv); |
developer | 7f1a58f | 2022-05-26 16:00:32 -0700 | [diff] [blame] | 50 | |
| 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; |
developer | 57de9b7 | 2023-02-20 11:15:54 +0800 | [diff] [blame] | 60 | } |