| From 1ca50d17101a4812a424ed5eb6ae10d54635b055 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 51/54] 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 64bab0228..7406aef38 100644 |
| --- a/hostapd/ctrl_iface.c |
| +++ b/hostapd/ctrl_iface.c |
| @@ -4301,6 +4301,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, |
| @@ -4904,6 +4922,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 363a6bb93..d5b6d59f3 100644 |
| --- a/hostapd/hostapd_cli.c |
| +++ b/hostapd/hostapd_cli.c |
| @@ -1422,6 +1422,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 |
| |
| @@ -1799,6 +1804,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 d0d8279e2..073c05de8 100644 |
| --- a/src/ap/ap_drv_ops.c |
| +++ b/src/ap/ap_drv_ops.c |
| @@ -1280,3 +1280,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 e4c2827bf..6b9e454de 100644 |
| --- a/src/ap/ap_drv_ops.h |
| +++ b/src/ap/ap_drv_ops.h |
| @@ -164,6 +164,7 @@ int hostapd_drv_ap_trig_type(struct hostapd_data *hapd, u8 enable, u8 type); |
| int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_mac); |
| int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf); |
| 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 fb463aaac..40f6150d7 100644 |
| --- a/src/drivers/driver.h |
| +++ b/src/drivers/driver.h |
| @@ -5128,6 +5128,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 cbe793cc6..9a10a93f0 100644 |
| --- a/src/drivers/driver_nl80211.c |
| +++ b/src/drivers/driver_nl80211.c |
| @@ -13827,6 +13827,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_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| + |
| + if (ret) |
| + wpa_printf(MSG_ERROR, "Failed to set beacon_ctrl. ret=%d (%s)", ret, strerror(-ret)); |
| + |
| + return ret; |
| +} |
| + |
| #endif /* CONFIG_IEEE80211AX */ |
| |
| |
| @@ -14972,6 +15005,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 1bba5b14e..300c0d11a 100644 |
| --- a/src/drivers/driver_nl80211.h |
| +++ b/src/drivers/driver_nl80211.h |
| @@ -212,6 +212,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; |
| |
| 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 0e044b03c..2f844053d 100644 |
| --- a/src/drivers/driver_nl80211_capa.c |
| +++ b/src/drivers/driver_nl80211_capa.c |
| @@ -1143,6 +1143,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.18.0 |
| |