developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 1 | From 76d110deecc1705295b3154ce91d046fb6115c66 Mon Sep 17 00:00:00 2001 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 2 | From: MeiChia Chiu <meichia.chiu@mediatek.com> |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 3 | Date: Tue, 31 May 2022 21:15:54 +0800 |
| 4 | Subject: [PATCH] hostapd: add support for runtime set in-band discovery |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 5 | |
| 6 | Usage: |
| 7 | hostapd_cli unsolic_probe_resp [tx_type] [interval] |
| 8 | |
| 9 | 0: disable all in-band discovery |
| 10 | 1: enable unsolicited probe response |
| 11 | 2: enable FILS discovery |
| 12 | |
| 13 | Signed-off-by: MeiChia Chiu <MeiChia.Chiu@mediatek.com> |
| 14 | --- |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 15 | hostapd/ctrl_iface.c | 66 ++++++++++++++++++++++++++++++++++++ |
| 16 | hostapd/hostapd_cli.c | 20 +++++++++++ |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 17 | src/ap/beacon.c | 5 ++- |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 18 | src/drivers/driver_nl80211.c | 10 ++++-- |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 19 | src/drivers/nl80211_copy.h | 1 + |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 20 | 5 files changed, 98 insertions(+), 4 deletions(-) |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 21 | |
| 22 | diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 23 | index 664c59df7..e6a2d4203 100644 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 24 | --- a/hostapd/ctrl_iface.c |
| 25 | +++ b/hostapd/ctrl_iface.c |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 26 | @@ -769,6 +769,69 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 27 | |
| 28 | #endif /* CONFIG_INTERWORKING */ |
| 29 | |
| 30 | +static int hostapd_ctrl_iface_inband_discovery(struct hostapd_data *hapd, |
| 31 | + const char *cmd) |
| 32 | +{ |
| 33 | + struct hostapd_bss_config *conf = hapd->conf; |
| 34 | + const char *pos = cmd; |
| 35 | + int tx_type, interval, ret; |
| 36 | + |
| 37 | + tx_type = atoi(pos); |
| 38 | + if (tx_type < 0 || tx_type > 2) { |
| 39 | + wpa_printf(MSG_ERROR, "Invalid tx type\n"); |
| 40 | + return -1; |
| 41 | + } |
| 42 | + |
| 43 | + pos = os_strchr(pos, ' '); |
| 44 | + if(!pos) |
| 45 | + return -1; |
| 46 | + pos++; |
| 47 | + interval = atoi(pos); |
| 48 | + if (interval < 0 || interval > 20) { |
| 49 | + wpa_printf(MSG_ERROR, "Invalid interval value\n"); |
| 50 | + return -1; |
| 51 | + } |
| 52 | + |
| 53 | + wpa_printf(MSG_ERROR, "Set inband discovery type:%d, interval:%d\n", |
| 54 | + tx_type, interval); |
| 55 | + |
| 56 | +#define DISABLE_INBAND_DISC 0 |
| 57 | +#define UNSOL_PROBE_RESP 1 |
| 58 | +#define FILS_DISCOVERY 2 |
| 59 | + |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 60 | +#ifdef CONFIG_FILS |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 61 | + conf->fils_discovery_max_int = 0; |
| 62 | + conf->fils_discovery_min_int = 0; |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 63 | +#endif /* CONFIG_FILS */ |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 64 | + conf->unsol_bcast_probe_resp_interval = 0; |
| 65 | + |
| 66 | + switch (tx_type) { |
| 67 | + case DISABLE_INBAND_DISC: |
| 68 | + default: |
| 69 | + /* Disable both Unsolicited probe response and FILS discovery*/ |
| 70 | + break; |
| 71 | + case UNSOL_PROBE_RESP: |
| 72 | + /* Enable Unsolicited probe response */ |
| 73 | + conf->unsol_bcast_probe_resp_interval = interval; |
| 74 | + break; |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 75 | +#ifdef CONFIG_FILS |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 76 | + case FILS_DISCOVERY: |
| 77 | + /* Enable FILS discovery */ |
| 78 | + conf->fils_discovery_min_int = interval; |
| 79 | + conf->fils_discovery_max_int = interval; |
| 80 | + break; |
developer | 9fe3113 | 2022-05-31 21:21:20 +0800 | [diff] [blame] | 81 | +#endif /* CONFIG_FILS */ |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 82 | + } |
| 83 | + |
| 84 | + ret = ieee802_11_update_beacons(hapd->iface); |
| 85 | + if(ret) { |
| 86 | + wpa_printf(MSG_DEBUG, |
| 87 | + "Failed to update with inband discovery parameters\n"); |
| 88 | + return -1; |
| 89 | + } |
| 90 | + |
| 91 | + return 0; |
| 92 | +} |
| 93 | |
| 94 | #ifdef CONFIG_WNM_AP |
| 95 | |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 96 | @@ -3336,6 +3399,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 97 | if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15)) |
| 98 | reply_len = -1; |
| 99 | #endif /* CONFIG_WNM_AP */ |
| 100 | + } else if (os_strncmp(buf, "INBAND_DISCOVERY ", 17) == 0) { |
| 101 | + if (hostapd_ctrl_iface_inband_discovery(hapd, buf + 17)) |
| 102 | + reply_len = -1; |
| 103 | } else if (os_strcmp(buf, "GET_CONFIG") == 0) { |
| 104 | reply_len = hostapd_ctrl_iface_get_config(hapd, reply, |
| 105 | reply_size); |
| 106 | diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 107 | index 60396f3da..4c4c82c9a 100644 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 108 | --- a/hostapd/hostapd_cli.c |
| 109 | +++ b/hostapd/hostapd_cli.c |
| 110 | @@ -646,6 +646,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc, |
| 111 | } |
| 112 | #endif /* CONFIG_WPS */ |
| 113 | |
| 114 | +static int hostapd_cli_cmd_inband_discovery(struct wpa_ctrl *ctrl, int argc, |
| 115 | + char *argv[]) |
| 116 | +{ |
| 117 | + char buf[300]; |
| 118 | + int res; |
| 119 | + |
| 120 | + if (argc < 2) { |
| 121 | + printf("Invalid 'inband_discovery' command - two arguments" |
| 122 | + "tx_type interval\n"); |
| 123 | + return -1; |
| 124 | + } |
| 125 | + |
| 126 | + res = os_snprintf(buf, sizeof(buf), "INBAND_DISCOVERY %s %s", |
| 127 | + argv[0], argv[1]); |
| 128 | + if (os_snprintf_error(sizeof(buf), res)) |
| 129 | + return -1; |
| 130 | + return wpa_ctrl_command(ctrl, buf); |
| 131 | +} |
| 132 | |
| 133 | static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc, |
| 134 | char *argv[]) |
| 135 | @@ -1744,6 +1762,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { |
| 136 | { "driver", hostapd_cli_cmd_driver, NULL, |
| 137 | "<driver sub command> [<hex formatted data>] = send driver command data" }, |
| 138 | #endif /* ANDROID */ |
| 139 | + { "inband_discovery", hostapd_cli_cmd_inband_discovery, NULL, |
| 140 | + "<tx type(0/1/2)> <interval> = runtime set inband discovery" }, |
| 141 | { NULL, NULL, NULL, NULL } |
| 142 | }; |
| 143 | |
| 144 | diff --git a/src/ap/beacon.c b/src/ap/beacon.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 145 | index 58872bfda..c8db86c6e 100644 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 146 | --- a/src/ap/beacon.c |
| 147 | +++ b/src/ap/beacon.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 148 | @@ -1483,6 +1483,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 149 | struct wpa_driver_ap_params *params) |
| 150 | { |
| 151 | params->fd_max_int = hapd->conf->fils_discovery_max_int; |
| 152 | + params->unsol_bcast_probe_resp_interval = |
| 153 | + hapd->conf->unsol_bcast_probe_resp_interval; |
| 154 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
| 155 | params->fd_max_int > FD_MAX_INTERVAL_6GHZ) |
| 156 | params->fd_max_int = FD_MAX_INTERVAL_6GHZ; |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 157 | @@ -1491,7 +1493,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 158 | if (params->fd_min_int > params->fd_max_int) |
| 159 | params->fd_min_int = params->fd_max_int; |
| 160 | |
| 161 | - if (params->fd_max_int) |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 162 | + if (params->fd_max_int || (is_6ghz_op_class(hapd->iconf->op_class) && |
| 163 | + !params->unsol_bcast_probe_resp_interval)) |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 164 | return hostapd_gen_fils_discovery(hapd, |
| 165 | ¶ms->fd_frame_tmpl_len); |
| 166 | |
| 167 | diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 168 | index 0127a6be2..ee763990f 100644 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 169 | --- a/src/drivers/driver_nl80211.c |
| 170 | +++ b/src/drivers/driver_nl80211.c |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 171 | @@ -4493,9 +4493,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 172 | params->fd_max_int) || |
| 173 | (params->fd_frame_tmpl && |
| 174 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 175 | - params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 176 | + params->fd_frame_tmpl_len, params->fd_frame_tmpl)) || |
| 177 | + nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE, |
| 178 | + params->unsol_bcast_probe_resp_interval)) |
| 179 | return -1; |
| 180 | - |
| 181 | nla_nest_end(msg, attr); |
| 182 | return 0; |
| 183 | } |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 184 | @@ -4839,7 +4840,10 @@ static int wpa_driver_nl80211_set_ap(void *priv, |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 185 | #endif /* CONFIG_SAE */ |
| 186 | |
| 187 | #ifdef CONFIG_FILS |
| 188 | - if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 189 | + if ((params->fd_max_int || |
| 190 | + ((params->freq->freq > 5950 && params->freq->freq <= 7115) && |
| 191 | + !(params->unsol_bcast_probe_resp_interval))) && |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 192 | + nl80211_fils_discovery(bss, msg, params) < 0) |
| 193 | goto fail; |
| 194 | #endif /* CONFIG_FILS */ |
| 195 | |
| 196 | diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 197 | index 0568a7909..c4bf3ad35 100644 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 198 | --- a/src/drivers/nl80211_copy.h |
| 199 | +++ b/src/drivers/nl80211_copy.h |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 200 | @@ -7379,6 +7379,7 @@ enum nl80211_fils_discovery_attributes { |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 201 | NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 202 | NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 203 | NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 204 | + NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE, |
| 205 | |
| 206 | /* keep last */ |
| 207 | __NL80211_FILS_DISCOVERY_ATTR_LAST, |
| 208 | -- |
developer | 34178a8 | 2022-06-23 17:44:15 +0800 | [diff] [blame] | 209 | 2.36.1 |
developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 210 | |