| From a7adff7d782e329e9f8b1063f78616757f944d51 Mon Sep 17 00:00:00 2001 |
| From: MeiChia Chiu <meichia.chiu@mediatek.com> |
| Date: Wed, 22 Nov 2023 21:41:34 +0800 |
| Subject: [PATCH 073/104] mtk: hostapd: add no_beacon vendor command for cert |
| |
| Add the vendor command to disable/enable beacon |
| |
| [Usage] |
| hostapd_cli -i <interface> no_beacon <value> |
| <value> |
| 0: enable beacon |
| 1: disable beacon |
| |
| Signed-off-by: MeiChia Chiu <meichia.chiu@mediatek.com> |
| --- |
| hostapd/ctrl_iface.c | 21 +++++++++++++++++++ |
| hostapd/hostapd_cli.c | 7 +++++++ |
| src/ap/ap_drv_ops.c | 8 ++++++++ |
| src/ap/ap_drv_ops.h | 1 + |
| src/common/mtk_vendor.h | 12 +++++++++++ |
| src/drivers/driver.h | 7 +++++++ |
| src/drivers/driver_nl80211.c | 34 +++++++++++++++++++++++++++++++ |
| src/drivers/driver_nl80211.h | 1 + |
| src/drivers/driver_nl80211_capa.c | 3 +++ |
| 9 files changed, 94 insertions(+) |
| |
| diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
| index c9b53c64e..0fded7ed4 100644 |
| --- a/hostapd/ctrl_iface.c |
| +++ b/hostapd/ctrl_iface.c |
| @@ -4862,6 +4862,24 @@ hostapd_ctrl_iface_get_pp(struct hostapd_data *hapd, char *cmd, char *buf, |
| } |
| } |
| |
| +static int |
| +hostapd_ctrl_iface_disable_beacon(struct hostapd_data *hapd, char *value, |
| + char *buf, size_t buflen) |
| +{ |
| + int disable_beacon = atoi(value); |
| + |
| + if (disable_beacon < 0) { |
| + wpa_printf(MSG_ERROR, "Invalid value for beacon ctrl"); |
| + return -1; |
| + } |
| + |
| + if (hostapd_drv_beacon_ctrl(hapd, !disable_beacon) == 0) |
| + return os_snprintf(buf, buflen, "OK\n"); |
| + else |
| + return -1; |
| + |
| +} |
| + |
| static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| char *buf, char *reply, |
| int reply_size, |
| @@ -5512,6 +5530,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| } else if (os_strncmp(buf, "SET_BACKGROUND_RADAR_MODE", 25) == 0) { |
| reply_len = hostapd_ctrl_iface_set_background_radar_mode(hapd, buf + 25, |
| reply, reply_size); |
| + } else if (os_strncmp(buf, "NO_BEACON ", 10) == 0) { |
| + reply_len = hostapd_ctrl_iface_disable_beacon(hapd, buf + 10, 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 e0b175386..7e4485cb8 100644 |
| --- a/hostapd/hostapd_cli.c |
| +++ b/hostapd/hostapd_cli.c |
| @@ -1464,6 +1464,11 @@ static int hostapd_cli_cmd_get_mu(struct wpa_ctrl *ctrl, int argc, |
| return hostapd_cli_cmd(ctrl, "GET_MU", 0, NULL, NULL); |
| } |
| |
| +static int hostapd_cli_cmd_disable_beacon(struct wpa_ctrl *ctrl, int argc, |
| + char *argv[]) |
| +{ |
| + return hostapd_cli_cmd(ctrl, "NO_BEACON", 1, argc, argv); |
| +} |
| |
| #ifdef CONFIG_DPP |
| |
| @@ -1871,6 +1876,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { |
| "<value> [0-15] bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0)"}, |
| { "get_mu", hostapd_cli_cmd_get_mu, NULL, |
| " = show mu onoff value in 0-15 bitmap"}, |
| + { "no_beacon", hostapd_cli_cmd_disable_beacon, NULL, |
| + "<value> 0: Enable beacon, 1: Disable beacon"}, |
| #ifdef CONFIG_DPP |
| { "dpp_qr_code", hostapd_cli_cmd_dpp_qr_code, NULL, |
| "report a scanned DPP URI from a QR Code" }, |
| diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c |
| index c71cfe1bd..d6bd157d8 100644 |
| --- a/src/ap/ap_drv_ops.c |
| +++ b/src/ap/ap_drv_ops.c |
| @@ -1388,3 +1388,11 @@ int hostapd_drv_pp_mode_set(struct hostapd_data *hapd) |
| return hapd->driver->pp_mode_set(hapd->drv_priv, |
| hapd->iconf->pp_mode); |
| } |
| + |
| +int hostapd_drv_beacon_ctrl(struct hostapd_data *hapd, u8 beacon_mode) |
| +{ |
| + if (!hapd->driver || !hapd->driver->beacon_ctrl) |
| + return 0; |
| + return hapd->driver->beacon_ctrl(hapd->drv_priv, beacon_mode); |
| +} |
| + |
| diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h |
| index ef61001e5..78e5c8d5a 100644 |
| --- a/src/ap/ap_drv_ops.h |
| +++ b/src/ap/ap_drv_ops.h |
| @@ -170,6 +170,7 @@ int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_ma |
| int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf); |
| int hostapd_drv_background_radar_mode(struct hostapd_data *hapd); |
| int hostapd_drv_pp_mode_set(struct hostapd_data *hapd); |
| +int hostapd_drv_beacon_ctrl(struct hostapd_data *hapd, u8 beacon_mode); |
| |
| #include "drivers/driver.h" |
| |
| diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h |
| index 6275c141d..5531802b8 100644 |
| --- a/src/common/mtk_vendor.h |
| +++ b/src/common/mtk_vendor.h |
| @@ -18,6 +18,7 @@ enum mtk_nl80211_vendor_subcmds { |
| MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL = 0xca, |
| MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL = 0xcb, |
| MTK_NL80211_VENDOR_SUBCMD_PP_CTRL = 0xcc, |
| + MTK_NL80211_VENDOR_SUBCMD_BEACON_CTRL = 0xcd, |
| }; |
| |
| enum mtk_vendor_attr_edcca_ctrl { |
| @@ -268,6 +269,17 @@ enum mtk_vendor_attr_pp_ctrl { |
| NUM_MTK_VENDOR_ATTRS_PP_CTRL - 1 |
| }; |
| |
| +enum mtk_vendor_attr_beacon_ctrl { |
| + MTK_VENDOR_ATTR_BEACON_CTRL_UNSPEC, |
| + |
| + MTK_VENDOR_ATTR_BEACON_CTRL_MODE, |
| + |
| + /* keep last */ |
| + NUM_MTK_VENDOR_ATTRS_BEACON_CTRL, |
| + MTK_VENDOR_ATTR_BEACON_CTRL_MAX = |
| + NUM_MTK_VENDOR_ATTRS_BEACON_CTRL - 1 |
| +}; |
| + |
| #define CSI_MAX_COUNT 256 |
| #define ETH_ALEN 6 |
| |
| diff --git a/src/drivers/driver.h b/src/drivers/driver.h |
| index be0e89ba3..332a51c55 100644 |
| --- a/src/drivers/driver.h |
| +++ b/src/drivers/driver.h |
| @@ -5243,6 +5243,13 @@ struct wpa_driver_ops { |
| int (*mu_ctrl)(void *priv, u8 mode, void *config); |
| int (*mu_dump)(void *priv, u8 *mu_onoff); |
| |
| + /** |
| + * beacon_ctrl - ctrl on off for beacon |
| + * @priv: Private driver interface data |
| + * |
| + */ |
| + int (*beacon_ctrl)(void *priv, u8 beacon_mode); |
| + |
| /** |
| * three_wire_ctrl - set three_wire_ctrl mode |
| * @priv: Private driver interface data |
| diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
| index b47ab07ea..e588e7538 100644 |
| --- a/src/drivers/driver_nl80211.c |
| +++ b/src/drivers/driver_nl80211.c |
| @@ -14111,6 +14111,39 @@ static int nl80211_mu_dump(void *priv, u8 *mu_onoff) |
| |
| return ret; |
| } |
| +static int nl80211_beacon_ctrl(void *priv, u8 beacon_mode) |
| +{ |
| + 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_beacon_ctrl_vendor_cmd_avail) { |
| + wpa_printf(MSG_ERROR, |
| + "nl80211: Driver does not support setting beacon control"); |
| + return 0; |
| + } |
| + |
| + if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| + nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_BEACON_CTRL) || |
| + !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| + nla_put_u8(msg, MTK_VENDOR_ATTR_BEACON_CTRL_MODE, beacon_mode)) { |
| + nlmsg_free(msg); |
| + return -ENOBUFS; |
| + } |
| + |
| + nla_nest_end(msg, data); |
| + |
| + ret = send_and_recv_cmd(drv, msg); |
| + |
| + if (ret) |
| + wpa_printf(MSG_ERROR, "Failed to set beacon_ctrl. ret=%d (%s)", ret, strerror(-ret)); |
| + |
| + return ret; |
| +} |
| + |
| #endif /* CONFIG_IEEE80211AX */ |
| |
| |
| @@ -15281,6 +15314,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| .set_4addr_mode = nl80211_set_4addr_mode, |
| .mu_ctrl = nl80211_mu_ctrl, |
| .mu_dump = nl80211_mu_dump, |
| + .beacon_ctrl = nl80211_beacon_ctrl, |
| #ifdef CONFIG_DPP |
| .dpp_listen = nl80211_dpp_listen, |
| #endif /* CONFIG_DPP */ |
| diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h |
| index 707bb7fe4..9866c221c 100644 |
| --- a/src/drivers/driver_nl80211.h |
| +++ b/src/drivers/driver_nl80211.h |
| @@ -210,6 +210,7 @@ struct wpa_driver_nl80211_data { |
| unsigned int mtk_amnt_vendor_cmd_avail:1; |
| unsigned int mtk_background_radar_vendor_cmd_avail:1; |
| unsigned int mtk_pp_vendor_cmd_avail:1; |
| + unsigned int mtk_beacon_ctrl_vendor_cmd_avail:1; |
| |
| u32 ignore_next_local_disconnect; |
| u32 ignore_next_local_deauth; |
| diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c |
| index ba3c0817b..f3e3d52e2 100644 |
| --- a/src/drivers/driver_nl80211_capa.c |
| +++ b/src/drivers/driver_nl80211_capa.c |
| @@ -1170,6 +1170,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| case MTK_NL80211_VENDOR_SUBCMD_PP_CTRL: |
| drv->mtk_pp_vendor_cmd_avail = 1; |
| break; |
| + case MTK_NL80211_VENDOR_SUBCMD_BEACON_CTRL : |
| + drv->mtk_beacon_ctrl_vendor_cmd_avail = 1; |
| + break; |
| } |
| } |
| |
| -- |
| 2.39.2 |
| |