[PATCH 4/5] ctrl_iface: Add MAC address randomization in scan processing
Ilan Peer
ilan.peer
Sun Dec 28 22:41:07 PST 2014
Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
wpa_supplicant/ctrl_iface.c | 136 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 136 insertions(+)
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index e47a82c..a3c283c 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -7016,6 +7016,139 @@ static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
}
+static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
+ char *cmd)
+{
+ char *token, *context = NULL;
+ unsigned int enable = ~0, type = 0;
+ u8 *addr = NULL, *mask = NULL;
+ int res = -1;
+
+ while ((token = str_token(cmd, " ", &context))) {
+ if (sscanf(token, "enable=%i", &enable) == 1)
+ continue;
+
+ if (os_strcasecmp(token, "scan") == 0) {
+ type |= MAC_ADDR_RAND_SCAN;
+ } else if (os_strcasecmp(token, "sched") == 0) {
+ type |= MAC_ADDR_RAND_SCHED_SCAN;
+ } else if (os_strcasecmp(token, "pno") == 0) {
+ type |= MAC_ADDR_RAND_PNO;
+ } else if (os_strcasecmp(token, "all") == 0) {
+ type = wpa_s->mac_addr_rand_supported;
+ } else if (!addr && os_strncasecmp(token, "addr=", 5) == 0) {
+ addr = os_malloc(ETH_ALEN);
+ if (!addr)
+ goto fail;
+
+ if (hwaddr_aton(token + 5, addr)) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: Invalid mac address: '%s'",
+ token);
+ goto fail;
+ }
+ } else if (!mask && os_strncasecmp(token, "mask=", 5) == 0) {
+ mask = os_malloc(ETH_ALEN);
+ if (!mask)
+ goto fail;
+
+ if (hwaddr_aton(token + 5, mask)) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: Invalid mac address mask: '%s'",
+ token);
+ goto fail;
+ }
+ } else {
+ wpa_printf(MSG_ERROR,
+ "CTRL: Invalid MAC_RAND_SCAN parameter: '%s'",
+ token);
+ goto fail;
+ }
+ }
+
+ if (!type) {
+ wpa_printf(MSG_ERROR, "CTRL: MAC_RAND_SCAN no type specified");
+ goto fail;
+ }
+
+ if ((wpa_s->mac_addr_rand_supported & type) != type) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
+ type, wpa_s->mac_addr_rand_supported);
+ goto fail;
+ }
+
+ if (enable > 1) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
+ goto fail;
+ }
+
+ 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)) {
+ /* simulate timeout to restart the sched scan */
+ wpa_s->sched_scan_timed_out = 1;
+ wpa_s->prev_sched_ssid = NULL;
+ wpa_supplicant_cancel_sched_scan(wpa_s);
+ }
+ goto out;
+ }
+
+ if ((addr && !mask) || (!addr && mask)) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
+ goto fail;
+ }
+
+ if (addr && mask && (!(mask[0] & 0x1) || (addr[0] & 0x1))) {
+ wpa_printf(MSG_ERROR,
+ "CTRL: MAC_RAND_SCAN cannot allow multicast address");
+ goto fail;
+ }
+
+
+ if (type & MAC_ADDR_RAND_SCAN) {
+ wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
+ addr, mask);
+ }
+
+ if (type & MAC_ADDR_RAND_SCHED_SCAN) {
+ wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
+ addr, mask);
+
+ if (wpa_s->sched_scanning && !wpa_s->pno) {
+ /* simulate timeout to restart the sched scan */
+ wpa_s->sched_scan_timed_out = 1;
+ wpa_s->prev_sched_ssid = NULL;
+ wpa_supplicant_cancel_sched_scan(wpa_s);
+ }
+ }
+
+ if (type & MAC_ADDR_RAND_PNO) {
+ wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
+ addr, mask);
+ if (wpa_s->pno) {
+ wpas_stop_pno(wpa_s);
+ wpas_start_pno(wpa_s);
+ }
+ }
+
+out:
+ res = 0;
+fail:
+ os_free(addr);
+ os_free(mask);
+ return res;
+}
+
+
char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
char *buf, size_t *resp_len)
{
@@ -7628,6 +7761,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
reply_len = -1;
} else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
wpas_ctrl_iface_erp_flush(wpa_s);
+ } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
+ if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
+ reply_len = -1;
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
--
1.8.3.2
More information about the Hostap
mailing list