Move ownership of MAC address randomization mask to scan params
This array can be freed either from the scan parameters or from clearing the MAC address randomization parameters from the wpa_supplicant struct. To make this ownership more clear, we have each struct own its own copy of the parameters. Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
This commit is contained in:
parent
6c2f70cc6a
commit
bb66d46758
2 changed files with 41 additions and 40 deletions
|
@ -517,7 +517,7 @@ struct wpa_driver_scan_params {
|
|||
* mac_addr - MAC address used with randomization. The address cannot be
|
||||
* a multicast one, i.e., bit 0 of byte 0 should not be set.
|
||||
*/
|
||||
const u8 *mac_addr;
|
||||
u8 *mac_addr;
|
||||
|
||||
/**
|
||||
* mac_addr_mask - MAC address mask used with randomization.
|
||||
|
|
|
@ -79,6 +79,33 @@ static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
|
|||
#endif /* CONFIG_WPS */
|
||||
|
||||
|
||||
static int wpa_setup_mac_addr_rand_params(struct wpa_driver_scan_params *params,
|
||||
const u8 *mac_addr)
|
||||
{
|
||||
u8 *tmp;
|
||||
|
||||
if (params->mac_addr) {
|
||||
params->mac_addr_mask = NULL;
|
||||
os_free(params->mac_addr);
|
||||
params->mac_addr = NULL;
|
||||
}
|
||||
|
||||
params->mac_addr_rand = 1;
|
||||
|
||||
if (!mac_addr)
|
||||
return 0;
|
||||
|
||||
tmp = os_malloc(2 * ETH_ALEN);
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
os_memcpy(tmp, mac_addr, 2 * ETH_ALEN);
|
||||
params->mac_addr = tmp;
|
||||
params->mac_addr_mask = tmp + ETH_ALEN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_enabled_networks - Check whether there are enabled networks
|
||||
* @wpa_s: Pointer to wpa_supplicant data
|
||||
|
@ -1211,13 +1238,8 @@ ssid_list_set:
|
|||
#endif /* CONFIG_P2P */
|
||||
|
||||
if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) &&
|
||||
wpa_s->wpa_state <= WPA_SCANNING) {
|
||||
params.mac_addr_rand = 1;
|
||||
if (wpa_s->mac_addr_scan) {
|
||||
params.mac_addr = wpa_s->mac_addr_scan;
|
||||
params.mac_addr_mask = wpa_s->mac_addr_scan + ETH_ALEN;
|
||||
}
|
||||
}
|
||||
wpa_s->wpa_state <= WPA_SCANNING)
|
||||
wpa_setup_mac_addr_rand_params(¶ms, wpa_s->mac_addr_scan);
|
||||
|
||||
if (!is_zero_ether_addr(wpa_s->next_scan_bssid)) {
|
||||
struct wpa_bss *bss;
|
||||
|
@ -1286,6 +1308,7 @@ scan:
|
|||
wpabuf_free(extra_ie);
|
||||
os_free(params.freqs);
|
||||
os_free(params.filter_ssids);
|
||||
os_free(params.mac_addr);
|
||||
|
||||
if (ret) {
|
||||
wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan");
|
||||
|
@ -1664,20 +1687,16 @@ scan:
|
|||
wpa_setband_scan_freqs(wpa_s, scan_params);
|
||||
|
||||
if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCHED_SCAN) &&
|
||||
wpa_s->wpa_state <= WPA_SCANNING) {
|
||||
params.mac_addr_rand = 1;
|
||||
if (wpa_s->mac_addr_sched_scan) {
|
||||
params.mac_addr = wpa_s->mac_addr_sched_scan;
|
||||
params.mac_addr_mask = wpa_s->mac_addr_sched_scan +
|
||||
ETH_ALEN;
|
||||
}
|
||||
}
|
||||
wpa_s->wpa_state <= WPA_SCANNING)
|
||||
wpa_setup_mac_addr_rand_params(¶ms,
|
||||
wpa_s->mac_addr_sched_scan);
|
||||
|
||||
wpa_scan_set_relative_rssi_params(wpa_s, scan_params);
|
||||
|
||||
ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params);
|
||||
wpabuf_free(extra_ie);
|
||||
os_free(params.filter_ssids);
|
||||
os_free(params.mac_addr);
|
||||
if (ret) {
|
||||
wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan");
|
||||
if (prev_state != wpa_s->wpa_state)
|
||||
|
@ -2535,24 +2554,10 @@ wpa_scan_clone_params(const struct wpa_driver_scan_params *src)
|
|||
params->sched_scan_plans_num = src->sched_scan_plans_num;
|
||||
}
|
||||
|
||||
if (src->mac_addr_rand) {
|
||||
params->mac_addr_rand = src->mac_addr_rand;
|
||||
|
||||
if (src->mac_addr && src->mac_addr_mask) {
|
||||
u8 *mac_addr;
|
||||
|
||||
mac_addr = os_malloc(2 * ETH_ALEN);
|
||||
if (!mac_addr)
|
||||
if (src->mac_addr_rand &&
|
||||
wpa_setup_mac_addr_rand_params(params, src->mac_addr))
|
||||
goto failed;
|
||||
|
||||
os_memcpy(mac_addr, src->mac_addr, ETH_ALEN);
|
||||
os_memcpy(mac_addr + ETH_ALEN, src->mac_addr_mask,
|
||||
ETH_ALEN);
|
||||
params->mac_addr = mac_addr;
|
||||
params->mac_addr_mask = mac_addr + ETH_ALEN;
|
||||
}
|
||||
}
|
||||
|
||||
if (src->bssid) {
|
||||
u8 *bssid;
|
||||
|
||||
|
@ -2738,18 +2743,14 @@ int wpas_start_pno(struct wpa_supplicant *wpa_s)
|
|||
}
|
||||
|
||||
if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_PNO) &&
|
||||
wpa_s->wpa_state <= WPA_SCANNING) {
|
||||
params.mac_addr_rand = 1;
|
||||
if (wpa_s->mac_addr_pno) {
|
||||
params.mac_addr = wpa_s->mac_addr_pno;
|
||||
params.mac_addr_mask = wpa_s->mac_addr_pno + ETH_ALEN;
|
||||
}
|
||||
}
|
||||
wpa_s->wpa_state <= WPA_SCANNING)
|
||||
wpa_setup_mac_addr_rand_params(¶ms, wpa_s->mac_addr_pno);
|
||||
|
||||
wpa_scan_set_relative_rssi_params(wpa_s, ¶ms);
|
||||
|
||||
ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms);
|
||||
os_free(params.filter_ssids);
|
||||
os_free(params.mac_addr);
|
||||
if (ret == 0)
|
||||
wpa_s->pno = 1;
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue