| From 9b82b5966b57403f389759b6dfb8318dd862b480 Mon Sep 17 00:00:00 2001 |
| From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| Date: Fri, 16 Dec 2022 03:57:11 +0800 |
| Subject: [PATCH 12/35] hostapd: mtk: Add amsdu set get ctrl |
| |
| --- |
| hostapd/config_file.c | 9 +++ |
| hostapd/ctrl_iface.c | 26 +++++++ |
| hostapd/hostapd_cli.c | 9 +++ |
| src/ap/ap_config.c | 1 + |
| src/ap/ap_config.h | 1 + |
| src/ap/ap_drv_ops.c | 14 ++++ |
| src/ap/ap_drv_ops.h | 2 + |
| src/ap/hostapd.c | 2 + |
| src/common/mtk_vendor.h | 17 ++++- |
| src/drivers/driver.h | 9 +++ |
| src/drivers/driver_nl80211.c | 114 ++++++++++++++++++++++++++++++ |
| src/drivers/driver_nl80211.h | 1 + |
| src/drivers/driver_nl80211_capa.c | 3 + |
| 13 files changed, 207 insertions(+), 1 deletion(-) |
| |
| diff --git a/hostapd/config_file.c b/hostapd/config_file.c |
| index 8a61726..017c21e 100644 |
| --- a/hostapd/config_file.c |
| +++ b/hostapd/config_file.c |
| @@ -4807,6 +4807,15 @@ static int hostapd_config_fill(struct hostapd_config *conf, |
| u8 en = strtol(pos, NULL, 10); |
| |
| conf->dfs_detect_mode = en; |
| + } else if (os_strcmp(buf, "amsdu") == 0) { |
| + int val = atoi(pos); |
| + if (val < 0 || val > 1) { |
| + wpa_printf(MSG_ERROR, |
| + "Line %d: invalid amsdu value", |
| + line); |
| + return 1; |
| + } |
| + conf->amsdu = val; |
| } else { |
| wpa_printf(MSG_ERROR, |
| "Line %d: unknown configuration item '%s'", |
| diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
| index 37a1b2a..61c9e80 100644 |
| --- a/hostapd/ctrl_iface.c |
| +++ b/hostapd/ctrl_iface.c |
| @@ -3612,6 +3612,30 @@ hostapd_ctrl_iface_set_offchan_ctrl(struct hostapd_data *hapd, char *cmd, |
| } |
| |
| |
| +static int |
| +hostapd_ctrl_iface_get_amsdu(struct hostapd_data *hapd, char *buf, |
| + size_t buflen) |
| +{ |
| + u8 amsdu; |
| + int ret; |
| + char *pos, *end; |
| + |
| + pos = buf; |
| + end = buf + buflen; |
| + |
| + if (hostapd_drv_amsdu_dump(hapd, &amsdu) == 0) { |
| + hapd->iconf->amsdu = amsdu; |
| + ret = os_snprintf(pos, end - pos, "[hostapd_cli] AMSDU: %u\n", |
| + hapd->iconf->amsdu); |
| + } |
| + |
| + if (os_snprintf_error(end - pos, ret)) |
| + return 0; |
| + |
| + return ret; |
| +} |
| + |
| + |
| static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| char *buf, char *reply, |
| int reply_size, |
| @@ -4176,6 +4200,8 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| reply, reply_size); |
| } else if (os_strncmp(buf, "SET_OFFCHAN_CTRL", 16) == 0) { |
| reply_len = hostapd_ctrl_iface_set_offchan_ctrl(hapd, buf + 16, reply, reply_size); |
| + } else if (os_strncmp(buf, "GET_AMSDU", 9) == 0) { |
| + reply_len = hostapd_ctrl_iface_get_amsdu(hapd, reply, reply_size); |
| } else { |
| os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| reply_len = 16; |
| diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c |
| index 1f7013e..0da18e2 100644 |
| --- a/hostapd/hostapd_cli.c |
| +++ b/hostapd/hostapd_cli.c |
| @@ -1593,6 +1593,13 @@ static int hostapd_cli_cmd_get_ibf(struct wpa_ctrl *ctrl, int argc, |
| } |
| |
| |
| +static int hostapd_cli_cmd_get_amsdu(struct wpa_ctrl *ctrl, int argc, |
| + char *argv[]) |
| +{ |
| + return hostapd_cli_cmd(ctrl, "GET_AMSDU", 0, NULL, NULL); |
| +} |
| + |
| + |
| struct hostapd_cli_cmd { |
| const char *cmd; |
| int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]); |
| @@ -1796,6 +1803,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { |
| "<tx type(0/1/2)> <interval> = runtime set inband discovery" }, |
| { "get_ibf", hostapd_cli_cmd_get_ibf, NULL, |
| " = show iBF state (enabled/disabled)"}, |
| + { "get_amsdu", hostapd_cli_cmd_get_amsdu, NULL, |
| + " = show AMSDU state"}, |
| { NULL, NULL, NULL, NULL } |
| }; |
| |
| diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c |
| index df90814..24fc0f5 100644 |
| --- a/src/ap/ap_config.c |
| +++ b/src/ap/ap_config.c |
| @@ -299,6 +299,7 @@ struct hostapd_config * hostapd_config_defaults(void) |
| conf->edcca_compensation = EDCCA_DEFAULT_COMPENSATION; |
| conf->three_wire_enable = THREE_WIRE_MODE_DISABLE; |
| conf->ibf_enable = IBF_DEFAULT_ENABLE; |
| + conf->amsdu = 1; |
| |
| return conf; |
| } |
| diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h |
| index d3a9fb0..ce0d84c 100644 |
| --- a/src/ap/ap_config.h |
| +++ b/src/ap/ap_config.h |
| @@ -1161,6 +1161,7 @@ struct hostapd_config { |
| u8 three_wire_enable; |
| u8 ibf_enable; |
| u8 dfs_detect_mode; |
| + u8 amsdu; |
| }; |
| |
| enum three_wire_mode { |
| diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c |
| index bec9798..342a7a8 100644 |
| --- a/src/ap/ap_drv_ops.c |
| +++ b/src/ap/ap_drv_ops.c |
| @@ -1077,4 +1077,18 @@ int hostapd_drv_ibf_dump(struct hostapd_data *hapd, u8 *ibf_enable) |
| if (!hapd->driver || !hapd->driver->ibf_dump) |
| return 0; |
| return hapd->driver->ibf_dump(hapd->drv_priv, ibf_enable); |
| +} |
| + |
| +int hostapd_drv_amsdu_ctrl(struct hostapd_data *hapd) |
| +{ |
| + if (!hapd->driver || !hapd->driver->amsdu_ctrl) |
| + return 0; |
| + return hapd->driver->amsdu_ctrl(hapd->drv_priv, hapd->iconf->amsdu); |
| +} |
| + |
| +int hostapd_drv_amsdu_dump(struct hostapd_data *hapd, u8 *amsdu) |
| +{ |
| + if (!hapd->driver || !hapd->driver->amsdu_dump) |
| + return 0; |
| + return hapd->driver->amsdu_dump(hapd->drv_priv, amsdu); |
| } |
| \ No newline at end of file |
| diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h |
| index 30b0322..79fef71 100644 |
| --- a/src/ap/ap_drv_ops.h |
| +++ b/src/ap/ap_drv_ops.h |
| @@ -147,6 +147,8 @@ int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff); |
| int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd); |
| int hostapd_drv_ibf_ctrl(struct hostapd_data *hapd); |
| int hostapd_drv_ibf_dump(struct hostapd_data *hapd, u8 *ibf_enable); |
| +int hostapd_drv_amsdu_ctrl(struct hostapd_data *hapd); |
| +int hostapd_drv_amsdu_dump(struct hostapd_data *hapd, u8 *amsdu); |
| |
| #include "drivers/driver.h" |
| |
| diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c |
| index e83298e..42e8ed7 100644 |
| --- a/src/ap/hostapd.c |
| +++ b/src/ap/hostapd.c |
| @@ -2308,6 +2308,8 @@ dfs_offload: |
| goto fail; |
| if (hostapd_drv_ibf_ctrl(hapd) < 0) |
| goto fail; |
| + if (hostapd_drv_amsdu_ctrl(hapd) < 0) |
| + goto fail; |
| |
| wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", |
| iface->bss[0]->conf->iface); |
| diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h |
| index 7b7aeaa..97c5a47 100644 |
| --- a/src/common/mtk_vendor.h |
| +++ b/src/common/mtk_vendor.h |
| @@ -167,7 +167,6 @@ enum mtk_vendor_attr_wireless_ctrl { |
| MTK_VENDOR_ATTR_WIRELESS_CTRL_NUSERS_OFDMA, |
| MTK_VENDOR_ATTR_WIRELESS_CTRL_BA_BUFFER_SIZE, |
| MTK_VENDOR_ATTR_WIRELESS_CTRL_MIMO, |
| - MTK_VENDOR_ATTR_WIRELESS_CTRL_AMPDU, |
| MTK_VENDOR_ATTR_WIRELESS_CTRL_AMSDU, |
| MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT, |
| |
| @@ -177,6 +176,22 @@ enum mtk_vendor_attr_wireless_ctrl { |
| NUM_MTK_VENDOR_ATTRS_WIRELESS_CTRL - 1 |
| }; |
| |
| +enum mtk_vendor_attr_wireless_dump { |
| + MTK_VENDOR_ATTR_WIRELESS_DUMP_UNSPEC, |
| + |
| + MTK_VENDOR_ATTR_WIRELESS_DUMP_AMSDU, |
| + |
| + /* keep last */ |
| + NUM_MTK_VENDOR_ATTRS_WIRELESS_DUMP, |
| + MTK_VENDOR_ATTR_WIRELESS_DUMP_MAX = |
| + NUM_MTK_VENDOR_ATTRS_WIRELESS_DUMP - 1 |
| +}; |
| + |
| +static const struct nla_policy |
| +wireless_dump_policy[NUM_MTK_VENDOR_ATTRS_WIRELESS_DUMP] = { |
| + [MTK_VENDOR_ATTR_WIRELESS_DUMP_AMSDU] = { .type = NLA_U8 }, |
| +}; |
| + |
| enum mtk_vendor_attr_rfeature_ctrl { |
| MTK_VENDOR_ATTR_RFEATURE_CTRL_UNSPEC, |
| |
| diff --git a/src/drivers/driver.h b/src/drivers/driver.h |
| index 913a194..3e034d7 100644 |
| --- a/src/drivers/driver.h |
| +++ b/src/drivers/driver.h |
| @@ -4720,6 +4720,15 @@ struct wpa_driver_ops { |
| * |
| */ |
| int (*ibf_dump)(void *priv, u8 *ibf_enable); |
| + |
| + /** |
| + * amsdu_ctrl - enable/disable amsdu |
| + * amsdu_dump - get current amsdu status |
| + * @priv: Private driver interface data |
| + * |
| + */ |
| + int (*amsdu_ctrl)(void *priv, u8 amsdu); |
| + int (*amsdu_dump)(void *priv, u8 *amsdu); |
| }; |
| |
| /** |
| diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
| index ff257eb..6c65901 100644 |
| --- a/src/drivers/driver_nl80211.c |
| +++ b/src/drivers/driver_nl80211.c |
| @@ -12776,6 +12776,118 @@ fail: |
| return -ENOBUFS; |
| } |
| |
| +static int nl80211_enable_amsdu(void *priv, u8 amsdu) |
| +{ |
| + struct i802_bss *bss = priv; |
| + struct wpa_driver_nl80211_data *drv = bss->drv; |
| + struct nl_msg *msg; |
| + struct nlattr *data; |
| + int ret; |
| + |
| + if (!drv->mtk_wireless_vendor_cmd_avail) { |
| + wpa_printf(MSG_INFO, |
| + "nl80211: Driver does not support setting ap wireless control"); |
| + return 0; |
| + } |
| + |
| + msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| + if (!msg) |
| + goto fail; |
| + |
| + if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL)) |
| + goto fail; |
| + |
| + data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| + if (!data) |
| + goto fail; |
| + |
| + nla_put_u8(msg, MTK_VENDOR_ATTR_WIRELESS_CTRL_AMSDU, amsdu); |
| + |
| + nla_nest_end(msg, data); |
| + ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| + if (ret) { |
| + wpa_printf(MSG_ERROR, "Failed to set amsdu. ret=%d (%s)", ret, strerror(-ret)); |
| + } |
| + |
| + return ret; |
| + |
| +fail: |
| + nlmsg_free(msg); |
| + return -ENOBUFS; |
| +} |
| + |
| +static int dump_amsdu_handler(struct nl_msg *msg, void *arg) |
| +{ |
| + u8 *amsdu = (u8 *) arg; |
| + struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| + struct nlattr *tb_vendor[MTK_VENDOR_ATTR_WIRELESS_DUMP_MAX + 1]; |
| + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| + struct nlattr *nl_vend, *attr_amsdu; |
| + |
| + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| + genlmsg_attrlen(gnlh, 0), NULL); |
| + |
| + nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| + if (!nl_vend) |
| + return NL_SKIP; |
| + |
| + nla_parse(tb_vendor, MTK_VENDOR_ATTR_WIRELESS_DUMP_MAX, |
| + nla_data(nl_vend), nla_len(nl_vend), NULL); |
| + |
| + attr_amsdu = tb_vendor[MTK_VENDOR_ATTR_WIRELESS_DUMP_AMSDU]; |
| + if (!attr_amsdu ){ |
| + wpa_printf(MSG_ERROR, "nl80211: cannot find vendor attributes"); |
| + return NL_SKIP; |
| + } |
| + |
| + *amsdu = nla_get_u8(attr_amsdu); |
| + |
| + return NL_SKIP; |
| +} |
| + |
| +static int |
| +nl80211_dump_amsdu(void *priv, u8 *amsdu) |
| +{ |
| + struct i802_bss *bss = priv; |
| + struct wpa_driver_nl80211_data *drv = bss->drv; |
| + struct nl_msg *msg; |
| + struct nlattr *data; |
| + int ret; |
| + |
| + if (!drv->mtk_wireless_vendor_cmd_avail) { |
| + wpa_printf(MSG_INFO, |
| + "nl80211: Driver does not support ap_wireless control"); |
| + return 0; |
| + } |
| + |
| + msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_VENDOR); |
| + if (!msg) |
| + goto fail; |
| + |
| + if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL)) |
| + goto fail; |
| + |
| + data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| + if (!data) |
| + goto fail; |
| + |
| + nla_nest_end(msg, data); |
| + |
| + ret = send_and_recv_msgs(drv, msg, dump_amsdu_handler, amsdu, NULL, NULL); |
| + |
| + if (ret) { |
| + wpa_printf(MSG_ERROR, "Failed to dump amsdu. ret=%d (%s)", ret, strerror(-ret)); |
| + } |
| + |
| + return ret; |
| + |
| +fail: |
| + nlmsg_free(msg); |
| + return -ENOBUFS; |
| +} |
| + |
| const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| .name = "nl80211", |
| .desc = "Linux nl80211/cfg80211", |
| @@ -12930,4 +13042,6 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| .three_wire_ctrl = nl80211_enable_three_wire, |
| .ibf_ctrl = nl80211_ibf_enable, |
| .ibf_dump = nl80211_ibf_dump, |
| + .amsdu_ctrl = nl80211_enable_amsdu, |
| + .amsdu_dump = nl80211_dump_amsdu, |
| }; |
| diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h |
| index 92e5ad6..21d48cc 100644 |
| --- a/src/drivers/driver_nl80211.h |
| +++ b/src/drivers/driver_nl80211.h |
| @@ -185,6 +185,7 @@ struct wpa_driver_nl80211_data { |
| unsigned int mtk_mu_vendor_cmd_avail:1; |
| unsigned int mtk_3wire_vendor_cmd_avail:1; |
| unsigned int mtk_ibf_vendor_cmd_avail:1; |
| + unsigned int mtk_wireless_vendor_cmd_avail:1; |
| |
| u64 vendor_scan_cookie; |
| u64 remain_on_chan_cookie; |
| diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c |
| index 83b4c5e..06a52db 100644 |
| --- a/src/drivers/driver_nl80211_capa.c |
| +++ b/src/drivers/driver_nl80211_capa.c |
| @@ -1065,6 +1065,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| case MTK_NL80211_VENDOR_SUBCMD_IBF_CTRL: |
| drv->mtk_ibf_vendor_cmd_avail = 1; |
| break; |
| + case MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL: |
| + drv->mtk_wireless_vendor_cmd_avail = 1; |
| + break; |
| } |
| } |
| |
| -- |
| 2.18.0 |
| |