developer | 2c9b8e9 | 2022-05-13 17:50:31 +0800 | [diff] [blame] | 1 | From 8c9d9f2b8da1b0e3e0832e7d7b02d75c4c0a4f3e Mon Sep 17 00:00:00 2001 |
| 2 | From: MeiChia Chiu <meichia.chiu@mediatek.com> |
| 3 | Date: Thu, 24 May 2022 21:48:21 +0800 |
| 4 | Subject: [PATCH] hostapd:v2 add support for runtime set in-band discovery-v2 |
| 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 | --- |
| 15 | hostapd/ctrl_iface.c | 62 ++++++++++++++++++++++++++++++++++++ |
| 16 | hostapd/hostapd_cli.c | 20 ++++++++++++ |
| 17 | src/ap/beacon.c | 5 ++- |
| 18 | src/drivers/driver_nl80211.c | 8 +++-- |
| 19 | src/drivers/nl80211_copy.h | 1 + |
| 20 | 5 files changed, 92 insertions(+), 4 deletions(-) |
| 21 | |
| 22 | diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
| 23 | index 86adf18e5..41740cfd5 100644 |
| 24 | --- a/hostapd/ctrl_iface.c |
| 25 | +++ b/hostapd/ctrl_iface.c |
| 26 | @@ -769,6 +769,65 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd, |
| 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 | + |
| 60 | + conf->fils_discovery_max_int = 0; |
| 61 | + conf->fils_discovery_min_int = 0; |
| 62 | + conf->unsol_bcast_probe_resp_interval = 0; |
| 63 | + |
| 64 | + switch (tx_type) { |
| 65 | + case DISABLE_INBAND_DISC: |
| 66 | + default: |
| 67 | + /* Disable both Unsolicited probe response and FILS discovery*/ |
| 68 | + break; |
| 69 | + case UNSOL_PROBE_RESP: |
| 70 | + /* Enable Unsolicited probe response */ |
| 71 | + conf->unsol_bcast_probe_resp_interval = interval; |
| 72 | + break; |
| 73 | + case FILS_DISCOVERY: |
| 74 | + /* Enable FILS discovery */ |
| 75 | + conf->fils_discovery_min_int = interval; |
| 76 | + conf->fils_discovery_max_int = interval; |
| 77 | + break; |
| 78 | + } |
| 79 | + |
| 80 | + ret = ieee802_11_update_beacons(hapd->iface); |
| 81 | + if(ret) { |
| 82 | + wpa_printf(MSG_DEBUG, |
| 83 | + "Failed to update with inband discovery parameters\n"); |
| 84 | + return -1; |
| 85 | + } |
| 86 | + |
| 87 | + return 0; |
| 88 | +} |
| 89 | |
| 90 | #ifdef CONFIG_WNM_AP |
| 91 | |
| 92 | @@ -3673,6 +3732,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| 93 | if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15)) |
| 94 | reply_len = -1; |
| 95 | #endif /* CONFIG_WNM_AP */ |
| 96 | + } else if (os_strncmp(buf, "INBAND_DISCOVERY ", 17) == 0) { |
| 97 | + if (hostapd_ctrl_iface_inband_discovery(hapd, buf + 17)) |
| 98 | + reply_len = -1; |
| 99 | } else if (os_strcmp(buf, "GET_CONFIG") == 0) { |
| 100 | reply_len = hostapd_ctrl_iface_get_config(hapd, reply, |
| 101 | reply_size); |
| 102 | diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c |
| 103 | index 260912111..e30c4e7c1 100644 |
| 104 | --- a/hostapd/hostapd_cli.c |
| 105 | +++ b/hostapd/hostapd_cli.c |
| 106 | @@ -646,6 +646,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc, |
| 107 | } |
| 108 | #endif /* CONFIG_WPS */ |
| 109 | |
| 110 | +static int hostapd_cli_cmd_inband_discovery(struct wpa_ctrl *ctrl, int argc, |
| 111 | + char *argv[]) |
| 112 | +{ |
| 113 | + char buf[300]; |
| 114 | + int res; |
| 115 | + |
| 116 | + if (argc < 2) { |
| 117 | + printf("Invalid 'inband_discovery' command - two arguments" |
| 118 | + "tx_type interval\n"); |
| 119 | + return -1; |
| 120 | + } |
| 121 | + |
| 122 | + res = os_snprintf(buf, sizeof(buf), "INBAND_DISCOVERY %s %s", |
| 123 | + argv[0], argv[1]); |
| 124 | + if (os_snprintf_error(sizeof(buf), res)) |
| 125 | + return -1; |
| 126 | + return wpa_ctrl_command(ctrl, buf); |
| 127 | +} |
| 128 | |
| 129 | static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc, |
| 130 | char *argv[]) |
| 131 | @@ -1744,6 +1762,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { |
| 132 | { "driver", hostapd_cli_cmd_driver, NULL, |
| 133 | "<driver sub command> [<hex formatted data>] = send driver command data" }, |
| 134 | #endif /* ANDROID */ |
| 135 | + { "inband_discovery", hostapd_cli_cmd_inband_discovery, NULL, |
| 136 | + "<tx type(0/1/2)> <interval> = runtime set inband discovery" }, |
| 137 | { NULL, NULL, NULL, NULL } |
| 138 | }; |
| 139 | |
| 140 | diff --git a/src/ap/beacon.c b/src/ap/beacon.c |
| 141 | index 3c49653cc..367e32611 100644 |
| 142 | --- a/src/ap/beacon.c |
| 143 | +++ b/src/ap/beacon.c |
| 144 | @@ -1406,6 +1406,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
| 145 | struct wpa_driver_ap_params *params) |
| 146 | { |
| 147 | params->fd_max_int = hapd->conf->fils_discovery_max_int; |
| 148 | + params->unsol_bcast_probe_resp_interval = |
| 149 | + hapd->conf->unsol_bcast_probe_resp_interval; |
| 150 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
| 151 | params->fd_max_int > FD_MAX_INTERVAL_6GHZ) |
| 152 | params->fd_max_int = FD_MAX_INTERVAL_6GHZ; |
| 153 | @@ -1414,7 +1416,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
| 154 | if (params->fd_min_int > params->fd_max_int) |
| 155 | params->fd_min_int = params->fd_max_int; |
| 156 | |
| 157 | - if (params->fd_max_int) |
| 158 | + if (params->fd_max_int || |
| 159 | + !params->unsol_bcast_probe_resp_interval) |
| 160 | return hostapd_gen_fils_discovery(hapd, |
| 161 | ¶ms->fd_frame_tmpl_len); |
| 162 | |
| 163 | diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
| 164 | index aec179ac3..6113aff0b 100644 |
| 165 | --- a/src/drivers/driver_nl80211.c |
| 166 | +++ b/src/drivers/driver_nl80211.c |
| 167 | @@ -4491,9 +4491,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
| 168 | params->fd_max_int) || |
| 169 | (params->fd_frame_tmpl && |
| 170 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 171 | - params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 172 | + params->fd_frame_tmpl_len, params->fd_frame_tmpl)) || |
| 173 | + nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE, |
| 174 | + params->unsol_bcast_probe_resp_interval)) |
| 175 | return -1; |
| 176 | - |
| 177 | nla_nest_end(msg, attr); |
| 178 | return 0; |
| 179 | } |
| 180 | @@ -4823,7 +4824,8 @@ static int wpa_driver_nl80211_set_ap(void *priv, |
| 181 | #endif /* CONFIG_SAE */ |
| 182 | |
| 183 | #ifdef CONFIG_FILS |
| 184 | - if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
| 185 | + if ((params->fd_max_int || !(params->unsol_bcast_probe_resp_interval)) && |
| 186 | + nl80211_fils_discovery(bss, msg, params) < 0) |
| 187 | goto fail; |
| 188 | #endif /* CONFIG_FILS */ |
| 189 | |
| 190 | diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h |
| 191 | index f962c06e9..6fb7b7fcf 100644 |
| 192 | --- a/src/drivers/nl80211_copy.h |
| 193 | +++ b/src/drivers/nl80211_copy.h |
| 194 | @@ -7150,6 +7150,7 @@ enum nl80211_fils_discovery_attributes { |
| 195 | NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 196 | NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 197 | NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 198 | + NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE, |
| 199 | |
| 200 | /* keep last */ |
| 201 | __NL80211_FILS_DISCOVERY_ATTR_LAST, |
| 202 | -- |
| 203 | 2.29.2 |
| 204 | |