Move MAC address randomization enable/disable to helper functions

This makes it easier to share this for D-Bus implementation.

Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
This commit is contained in:
Eric Caruso 2019-05-30 11:10:46 -07:00 committed by Jouni Malinen
parent 9a1046a7a1
commit 91b6eba773
3 changed files with 72 additions and 52 deletions

View file

@ -9626,59 +9626,10 @@ static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
return -1;
}
if (!enable) {
wpas_mac_addr_rand_scan_clear(wpa_s, type);
if (wpa_s->pno) {
if (type & MAC_ADDR_RAND_PNO) {
wpas_stop_pno(wpa_s);
wpas_start_pno(wpa_s);
}
} else if (wpa_s->sched_scanning &&
(type & MAC_ADDR_RAND_SCHED_SCAN)) {
wpas_scan_restart_sched_scan(wpa_s);
}
return 0;
}
if (!enable)
return wpas_disable_mac_addr_randomization(wpa_s, type);
if ((addr && !mask) || (!addr && mask)) {
wpa_printf(MSG_INFO,
"CTRL: MAC_RAND_SCAN invalid addr/mask combination");
return -1;
}
if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
wpa_printf(MSG_INFO,
"CTRL: MAC_RAND_SCAN cannot allow multicast address");
return -1;
}
if (type & MAC_ADDR_RAND_SCAN) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
addr, mask))
return -1;
}
if (type & MAC_ADDR_RAND_SCHED_SCAN) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
addr, mask))
return -1;
if (wpa_s->sched_scanning && !wpa_s->pno)
wpas_scan_restart_sched_scan(wpa_s);
}
if (type & MAC_ADDR_RAND_PNO) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
addr, mask))
return -1;
if (wpa_s->pno) {
wpas_stop_pno(wpa_s);
wpas_start_pno(wpa_s);
}
}
return 0;
return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
}

View file

@ -7486,3 +7486,66 @@ int wpa_is_bss_tmp_disallowed(struct wpa_supplicant *wpa_s,
return 1;
}
int wpas_enable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
unsigned int type, const u8 *addr,
const u8 *mask)
{
if ((addr && !mask) || (!addr && mask)) {
wpa_printf(MSG_INFO,
"MAC_ADDR_RAND_SCAN invalid addr/mask combination");
return -1;
}
if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
wpa_printf(MSG_INFO,
"MAC_ADDR_RAND_SCAN cannot allow multicast address");
return -1;
}
if (type & MAC_ADDR_RAND_SCAN) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
addr, mask))
return -1;
}
if (type & MAC_ADDR_RAND_SCHED_SCAN) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
addr, mask))
return -1;
if (wpa_s->sched_scanning && !wpa_s->pno)
wpas_scan_restart_sched_scan(wpa_s);
}
if (type & MAC_ADDR_RAND_PNO) {
if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
addr, mask))
return -1;
if (wpa_s->pno) {
wpas_stop_pno(wpa_s);
wpas_start_pno(wpa_s);
}
}
return 0;
}
int wpas_disable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
unsigned int type)
{
wpas_mac_addr_rand_scan_clear(wpa_s, type);
if (wpa_s->pno) {
if (type & MAC_ADDR_RAND_PNO) {
wpas_stop_pno(wpa_s);
wpas_start_pno(wpa_s);
}
} else if (wpa_s->sched_scanning && (type & MAC_ADDR_RAND_SCHED_SCAN)) {
wpas_scan_restart_sched_scan(wpa_s);
}
return 0;
}

View file

@ -1418,6 +1418,12 @@ size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid,
int freq, u8 *pos, size_t len);
int wpas_enable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
unsigned int type, const u8 *addr,
const u8 *mask);
int wpas_disable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
unsigned int type);
/**
* wpa_supplicant_ctrl_iface_ctrl_rsp_handle - Handle a control response
* @wpa_s: Pointer to wpa_supplicant data