developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 1 | /* Copyright (C) 2021 Mediatek Inc. */ |
| 2 | #define _GNU_SOURCE |
| 3 | |
| 4 | #include "mt76-vendor.h" |
| 5 | |
| 6 | static int mt76_ap_rfeatures_set_attr(struct nl_msg *msg, int argc, char **argv) |
| 7 | { |
developer | 951bbeb | 2021-11-15 16:48:31 +0800 | [diff] [blame] | 8 | char *val, *s1, *s2, *cur; |
developer | 13aaa77 | 2021-09-27 18:09:26 +0800 | [diff] [blame] | 9 | void *data; |
| 10 | int idx = MTK_VENDOR_ATTR_RFEATURE_CTRL_TRIG_TYPE_EN; |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 11 | |
| 12 | val = strchr(argv[0], '='); |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 13 | if (!val) |
| 14 | return -EINVAL; |
| 15 | |
| 16 | *(val++) = 0; |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 17 | |
| 18 | if (!strncmp(argv[0], "he_gi", 5)) { |
| 19 | nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_GI, strtoul(val, NULL, 0)); |
| 20 | } else if (!strncmp(argv[0], "he_ltf", 6)) { |
| 21 | nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_HE_LTF, strtoul(val, NULL, 0)); |
developer | 31b1a28 | 2021-08-04 14:13:00 +0800 | [diff] [blame] | 22 | } else if (!strncmp(argv[0], "trig_type", 9)) { |
developer | 13aaa77 | 2021-09-27 18:09:26 +0800 | [diff] [blame] | 23 | data = nla_nest_start(msg, |
| 24 | MTK_VENDOR_ATTR_RFEATURE_CTRL_TRIG_TYPE_CFG | NLA_F_NESTED); |
developer | 951bbeb | 2021-11-15 16:48:31 +0800 | [diff] [blame] | 25 | if (!data) |
| 26 | return -ENOMEM; |
developer | 13aaa77 | 2021-09-27 18:09:26 +0800 | [diff] [blame] | 27 | |
developer | 951bbeb | 2021-11-15 16:48:31 +0800 | [diff] [blame] | 28 | s1 = s2 = strdup(val); |
developer | 13aaa77 | 2021-09-27 18:09:26 +0800 | [diff] [blame] | 29 | while ((cur = strsep(&s1, ",")) != NULL) |
| 30 | nla_put_u8(msg, idx++, strtoul(cur, NULL, 0)); |
| 31 | |
| 32 | nla_nest_end(msg, data); |
developer | 951bbeb | 2021-11-15 16:48:31 +0800 | [diff] [blame] | 33 | |
| 34 | free(s2); |
developer | 31b1a28 | 2021-08-04 14:13:00 +0800 | [diff] [blame] | 35 | } else if (!strncmp(argv[0], "ack_policy", 10)) { |
| 36 | nla_put_u8(msg, MTK_VENDOR_ATTR_RFEATURE_CTRL_ACK_PLCY, strtoul(val, NULL, 0)); |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | int mt76_ap_rfeatures_set(int idx, int argc, char **argv) |
| 43 | { |
| 44 | struct nl_msg *msg; |
| 45 | void *data; |
| 46 | int ret; |
| 47 | |
| 48 | if (argc < 1) |
| 49 | return 1; |
| 50 | |
| 51 | if (unl_genl_init(&unl, "nl80211") < 0) { |
| 52 | fprintf(stderr, "Failed to connect to nl80211\n"); |
| 53 | return 2; |
| 54 | } |
| 55 | |
| 56 | msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false); |
| 57 | |
| 58 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) || |
| 59 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) || |
| 60 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL)) |
| 61 | return false; |
| 62 | |
| 63 | data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 64 | if (!data) |
| 65 | return -ENOMEM; |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 66 | |
| 67 | mt76_ap_rfeatures_set_attr(msg, argc, argv); |
| 68 | |
| 69 | nla_nest_end(msg, data); |
| 70 | |
| 71 | ret = unl_genl_request(&unl, msg, NULL, NULL); |
| 72 | if (ret) |
| 73 | fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret)); |
| 74 | |
| 75 | unl_free(&unl); |
| 76 | |
| 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | static int mt76_ap_wireless_set_attr(struct nl_msg *msg, int argc, char **argv) |
| 81 | { |
| 82 | char *val; |
| 83 | |
| 84 | val = strchr(argv[0], '='); |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 85 | if (!val) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | *(val++) = 0; |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 89 | |
| 90 | if (!strncmp(argv[0], "fixed_mcs", 9)) { |
| 91 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_FIXED_MCS, strtoul(val, NULL, 0)); |
developer | 507ff0c | 2021-07-30 14:51:55 +0800 | [diff] [blame] | 92 | } else if (!strncmp(argv[0], "ofdma", 5)) { |
| 93 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_FIXED_OFDMA, strtoul(val, NULL, 0)); |
developer | b72be59 | 2021-08-16 10:58:59 +0800 | [diff] [blame] | 94 | } else if (!strncmp(argv[0], "ppdu_type", 9)) { |
| 95 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_PPDU_TX_TYPE, strtoul(val, NULL, 0)); |
| 96 | } else if (!strncmp(argv[0], "nusers_ofdma", 12)) { |
| 97 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_NUSERS_OFDMA, strtoul(val, NULL, 0)); |
developer | 786d929 | 2021-09-22 11:03:21 +0800 | [diff] [blame] | 98 | } else if (!strncmp(argv[0], "add_ba_req_bufsize", 18)) { |
| 99 | nla_put_u16(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_BA_BUFFER_SIZE, |
| 100 | strtoul(val, NULL, 0)); |
| 101 | } else if (!strncmp(argv[0], "mimo", 4)) { |
| 102 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_MIMO, strtoul(val, NULL, 0)); |
developer | 3a5765c | 2021-09-23 16:19:12 +0800 | [diff] [blame] | 103 | } else if (!strncmp(argv[0], "ampdu", 5)) { |
| 104 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_AMPDU, strtoul(val, NULL, 0)); |
| 105 | } else if (!strncmp(argv[0], "amsdu", 5)) { |
| 106 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_AMSDU, strtoul(val, NULL, 0)); |
developer | 07ede8d | 2021-11-16 18:31:21 +0800 | [diff] [blame] | 107 | } else if (!strncmp(argv[0], "cert", 4)) { |
| 108 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT, strtoul(val, NULL, 0)); |
developer | a98a5ea | 2023-01-24 14:23:34 +0800 | [diff] [blame] | 109 | } else if (!strncmp(argv[0], "rts_sigta", 9)) { |
| 110 | nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_RTS_SIGTA, |
| 111 | strtoul(val, NULL, 0)); |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int mt76_ap_wireless_set(int idx, int argc, char **argv) |
| 118 | { |
| 119 | struct nl_msg *msg; |
| 120 | void *data; |
| 121 | int ret; |
| 122 | |
| 123 | if (argc < 1) |
| 124 | return 1; |
| 125 | |
| 126 | if (unl_genl_init(&unl, "nl80211") < 0) { |
| 127 | fprintf(stderr, "Failed to connect to nl80211\n"); |
| 128 | return 2; |
| 129 | } |
| 130 | |
| 131 | msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false); |
| 132 | |
| 133 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) || |
| 134 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) || |
| 135 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL)) |
| 136 | return false; |
| 137 | |
| 138 | data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 139 | if (!data) |
| 140 | return -ENOMEM; |
developer | 5f18e6c | 2021-07-28 11:55:08 +0800 | [diff] [blame] | 141 | |
| 142 | mt76_ap_wireless_set_attr(msg, argc, argv); |
| 143 | |
| 144 | nla_nest_end(msg, data); |
| 145 | |
| 146 | ret = unl_genl_request(&unl, msg, NULL, NULL); |
| 147 | if (ret) |
| 148 | fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret)); |
| 149 | |
| 150 | unl_free(&unl); |
| 151 | |
| 152 | return ret; |
| 153 | } |