Cumulative patch from commit aef5047acc971c97622c85236f0cd84d169221e6
aef5047 P2P: Fix missing eloop_cancel_timeout in invitation trigger
3cdcb34 tests: Add module tests for WPS attribute parsing
da179bd WPS: Fix parsing of 0-length WFA vendor extension subelement
211d7ab P2P: Add even more debug prints for Probe Request in non-Listen state
Change-Id: Ifbdb1c8aa74906aaf60cb5be025dd7f02bb07c6e
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/hostapd/Makefile b/hostapd/Makefile
index 111e8c3..25c560f 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -70,6 +70,11 @@
OBJS += ../src/drivers/drivers.o
CFLAGS += -DHOSTAPD
+ifdef CONFIG_MODULE_TESTS
+CFLAGS += -DCONFIG_MODULE_TESTS
+OBJS += hapd_module_tests.o
+endif
+
ifdef CONFIG_WPA_TRACE
CFLAGS += -DWPA_TRACE
OBJS += ../src/utils/trace.o
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 4a9da5f..7f5de62 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -1650,6 +1650,12 @@
} else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
reply_len = -1;
+#ifdef CONFIG_MODULE_TESTS
+ } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
+ int hapd_module_tests(void);
+ if (hapd_module_tests() < 0)
+ reply_len = -1;
+#endif /* CONFIG_MODULE_TESTS */
} else {
wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
"ignored");
diff --git a/hostapd/hapd_module_tests.c b/hostapd/hapd_module_tests.c
new file mode 100644
index 0000000..f7887eb
--- /dev/null
+++ b/hostapd/hapd_module_tests.c
@@ -0,0 +1,17 @@
+/*
+ * hostapd module tests
+ * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+
+int hapd_module_tests(void)
+{
+ wpa_printf(MSG_INFO, "hostapd module tests");
+ return 0;
+}
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 7170e47..6f3cd68 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -1971,7 +1971,8 @@
if (!p2p->in_listen || !p2p->drv_in_listen) {
/* not in Listen state - ignore Probe Request */
- p2p_dbg(p2p, "Not in Listen state - ignore Probe Request");
+ p2p_dbg(p2p, "Not in Listen state (in_listen=%d drv_in_listen=%d) - ignore Probe Request",
+ p2p->in_listen, p2p->drv_in_listen);
return P2P_PREQ_NOT_LISTEN;
}
@@ -2142,6 +2143,7 @@
== 0) {
/* Received a Probe Request from Invite peer */
p2p_dbg(p2p, "Found Invite peer - try to start Invite from timeout");
+ eloop_cancel_timeout(p2p_invite_start, p2p, NULL);
eloop_register_timeout(0, 0, p2p_invite_start, p2p, NULL);
return P2P_PREQ_PROCESSED;
}
diff --git a/src/wps/wps_attr_parse.c b/src/wps/wps_attr_parse.c
index b04c222..1ebcfe9 100644
--- a/src/wps/wps_attr_parse.c
+++ b/src/wps/wps_attr_parse.c
@@ -75,7 +75,7 @@
const u8 *end = pos + len;
u8 id, elen;
- while (pos + 2 < end) {
+ while (pos + 2 <= end) {
id = *pos++;
elen = *pos++;
if (pos + elen > end)
diff --git a/src/wps/wps_module_tests.c b/src/wps/wps_module_tests.c
new file mode 100644
index 0000000..6800e86
--- /dev/null
+++ b/src/wps/wps_module_tests.c
@@ -0,0 +1,337 @@
+/*
+ * WPS module tests
+ * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "wps_attr_parse.h"
+
+struct wps_attr_parse_test {
+ const char *data;
+ int result;
+ int extra;
+};
+
+struct wps_attr_parse_test wps_attr_parse_test_cases[] = {
+ /* Empty message */
+ { "", 0, 0 },
+ /* Truncated attribute header */
+ { "10", -1, 0 },
+ { "1010", -1, 0 },
+ { "101000", -1, 0 },
+ /* Attribute overflow */
+ { "10100001", -1, 0 },
+#ifdef CONFIG_WPS_STRICT
+ { "10270000001057000101", -1, 0 },
+ { "1027000010570001010000000000", -1, 0 },
+#else /* CONFIG_WPS_STRICT */
+ /* Network Key workaround */
+ { "10270000001057000101", 0, 1 },
+ { "10230000001057000101", -1, 0 },
+ { "10270000101057000101", -1, 0 },
+ /* Mac OS X 10.6 padding workaround */
+ { "1027000010570001010000000000", 0, 1 },
+ { "1027000010570001010000000000000001000000", -1, 0 },
+#endif /* CONFIG_WPS_STRICT */
+ /* Version */
+ { "104a000110", 0, 0 },
+ { "104a0000", -1, 0 },
+ /* Message Type */
+ { "1022000101", 0, 0 },
+ { "10220000", -1, 0 },
+ /* Enrollee Nonce */
+ { "101a001000112233445566778899aabbccddeeff", 0, 0 },
+ { "101a00111122334455667788990011223344556677", -1, 0 },
+ /* Registrar Nonce */
+ { "1039001000112233445566778899aabbccddeeff", 0, 0 },
+ { "103900111122334455667788990011223344556677", -1, 0 },
+ /* UUID-E */
+ { "1047001000112233445566778899aabbccddeeff", 0, 0 },
+ { "10470000", -1, 0 },
+ { "104700111122334455667788990011223344556677", -1, 0 },
+ /* UUID-R */
+ { "1048001000112233445566778899aabbccddeeff", 0, 0 },
+ { "10480000", -1, 0 },
+ { "104800111122334455667788990011223344556677", -1, 0 },
+ /* Auth Type Flags */
+ { "100400021122", 0, 0 },
+ { "10040001ff", -1, 0 },
+ /* Encr Type Flags */
+ { "101000021122", 0, 0 },
+ { "10100001ff", -1, 0 },
+ /* Connection Type Flags */
+ { "100d0001ff", 0, 0 },
+ { "100d0002ffff", -1, 0 },
+ /* Config Methods */
+ { "10080002ffff", 0, 0 },
+ { "10080001ff", -1, 0 },
+ /* Selected Registrar Config Methods */
+ { "10530002ffff", 0, 0 },
+ { "10530001ff", -1, 0 },
+ /* Primary Device Type */
+ { "105400081122334455667788", 0, 0 },
+ { "105400111122334455667788990011223344556677", -1, 0 },
+ /* RF Bands */
+ { "103c0001ff", 0, 0 },
+ { "103c0002ffff", -1, 0 },
+ /* Association State */
+ { "10020002ffff", 0, 0 },
+ { "10020001ff", -1, 0 },
+ /* Config Error */
+ { "100900020001", 0, 0 },
+ { "10090001ff", -1, 0 },
+ /* Device Password ID */
+ { "101200020004", 0, 0 },
+ { "10120001ff", -1, 0 },
+ /* OOB Device Password */
+ { "102c001611223344556677889900112233445566778899000007", 0, 0 },
+ { "102c0036112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344", 0, 0 },
+ { "102c0001ff", -1, 0 },
+ { "102c003711223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455", -1, 0 },
+ { "102c002511223344556677889900112233445566778899001122334455667788990011223344556677", -1, 0 },
+ /* OS Version */
+ { "102d000411223344", 0, 0 },
+ { "102d00111122334455667788990011223344556677", -1, 0 },
+ /* WPS State */
+ { "1044000101", 0, 0 },
+ { "10440002ffff", -1, 0 },
+ /* Authenticator */
+ { "100500081122334455667788", 0, 0 },
+ { "10050000", -1, 0 },
+ { "100500111122334455667788990011223344556677", -1, 0 },
+ /* R-Hash1 */
+ { "103d00201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
+ { "103d0000", -1, 0 },
+ { "103d0021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
+ /* R-Hash2 */
+ { "103e00201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
+ { "103e0000", -1, 0 },
+ { "103e0021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
+ /* E-Hash1 */
+ { "101400201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
+ { "10140000", -1, 0 },
+ { "10140021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
+ /* E-Hash2 */
+ { "101500201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
+ { "10150000", -1, 0 },
+ { "10150021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
+ /* R-SNonce1 */
+ { "103f001011223344556677889900112233445566", 0, 0 },
+ { "103f0000", -1, 0 },
+ { "103f00111122334455667788990011223344556677", -1, 0 },
+ /* R-SNonce2 */
+ { "1040001011223344556677889900112233445566", 0, 0 },
+ { "10400000", -1, 0 },
+ { "104000111122334455667788990011223344556677", -1, 0 },
+ /* E-SNonce1 */
+ { "1016001011223344556677889900112233445566", 0, 0 },
+ { "10160000", -1, 0 },
+ { "101600111122334455667788990011223344556677", -1, 0 },
+ /* E-SNonce2 */
+ { "1017001011223344556677889900112233445566", 0, 0 },
+ { "10170000", -1, 0 },
+ { "101700111122334455667788990011223344556677", -1, 0 },
+ /* Key Wrap Authenticator */
+ { "101e00081122334455667788", 0, 0 },
+ { "101e0000", -1, 0 },
+ { "101e0009112233445566778899", -1, 0 },
+ /* Authentication Type */
+ { "100300020001", 0, 0 },
+ { "10030001ff", -1, 0 },
+ /* Encryption Type */
+ { "100f00020001", 0, 0 },
+ { "100f0001ff", -1, 0 },
+ /* Network Index */
+ { "1026000101", 0, 0 },
+ { "10260002ffff", -1, 0 },
+ /* Network Key Index */
+ { "1028000101", 0, 3 },
+ { "10280002ffff", -1, 0 },
+ /* MAC Address */
+ { "10200006112233445566", 0, 0 },
+ { "10200000", -1, 0 },
+ { "1020000711223344556677", -1, 0 },
+ /* Selected Registrar */
+ { "1041000101", 0, 0 },
+ { "10410002ffff", -1, 0 },
+ /* Request Type */
+ { "103a000101", 0, 0 },
+ { "103a0002ffff", -1, 0 },
+ /* Response Type */
+ { "103b000101", 0, 0 },
+ { "103b0002ffff", -1, 0 },
+ /* Manufacturer */
+ { "10210000", 0, 0 },
+ /* Model Name */
+ { "10230000", 0, 0 },
+ /* Model Number */
+ { "10240000", 0, 0 },
+ /* Serial Number */
+ { "10420000", 0, 0 },
+ /* Device Name */
+ { "10110000", 0, 0 },
+ /* Public Key */
+ { "10320000", 0, 0 },
+ /* Enc Settings */
+ { "10180000", 0, 0 },
+ /* SSID */
+ { "10450000", 0, 0 },
+ /* AP Setup Locked */
+ { "1057000101", 0, 0 },
+ { "10570002ffff", -1, 0 },
+ /* Requested Device Type */
+ { "106a00081122334455667788", 0, 0 },
+ { "106a0000", -1, 0 },
+ { "106a0009112233445566778899", -1, 0 },
+ /* More than maximum Requested Device Type attributes */
+ { "106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788", 0, 4 },
+ /* Secondary Device Type List */
+ { "105500081122334455667788", 0, 0 },
+ { "1055000711223344556677", -1, 0 },
+ { "1055008811223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566", -1, 0 },
+ /* AP Channel */
+ { "100100020001", 0, 0 },
+ { "1001000101", -1, 0 },
+ /* Skip invalid Vendor Extension */
+ { "10490000", 0, 0 },
+ { "1049000100", 0, 0 },
+ { "104900020000", 0, 0 },
+ /* Too long unknown vendor extension */
+ { "10490401"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "112233445566778899001122334455667788990011223344556677889900"
+ "1122334455", -1, 0 },
+ /* Maximum unknown vendor extensions */
+ { "10490003111111104900032222221049000333333310490003444444104900035555551049000366666610490003777777104900038888881049000399999910490003AAAAAA", 0, 5 },
+ /* More than maximum unknown vendor extensions */
+ { "10490003111111104900032222221049000333333310490003444444104900035555551049000366666610490003777777104900038888881049000399999910490003AAAAAA10490003BBBBBB", -1, 0 },
+ /* WFA vendor extensions */
+ { "1049000300372a", 0, 0 },
+ { "1049000400372a00", 0, 0 },
+ { "1049000500372a0001", 0, 0 },
+ { "1049001600372a0001ff0100020101030101040101ff00fe0101", 0, 6 },
+ /* Invalid Version2 length */
+ { "1049000500372a0000", -1, 0 },
+ /* Invalid Network Key Shareable length */
+ { "1049000500372a0200", -1, 0 },
+ /* Invalid Requedt To Enroll length */
+ { "1049000500372a0300", -1, 0 },
+ /* Invalid Settings Delay Time length */
+ { "1049000500372a0400", -1, 0 },
+ /* More than maximum Credential attributes */
+ { "100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000", 0, 2 },
+};
+
+
+static int wps_attr_parse_tests(void)
+{
+ struct wps_parse_attr attr;
+ unsigned int i;
+ int ret = 0;
+
+ wpa_printf(MSG_INFO, "WPS attribute parsing tests");
+
+ for (i = 0; i < ARRAY_SIZE(wps_attr_parse_test_cases); i++) {
+ struct wpabuf *buf;
+ size_t len;
+ struct wps_attr_parse_test *test =
+ &wps_attr_parse_test_cases[i];
+
+ len = os_strlen(test->data) / 2;
+ buf = wpabuf_alloc(len);
+ if (buf == NULL)
+ return -1;
+ if (hexstr2bin(test->data, wpabuf_put(buf, len), len) < 0) {
+ wpabuf_free(buf);
+ return -1;
+ }
+ if (wps_parse_msg(buf, &attr) != test->result) {
+ wpa_printf(MSG_ERROR, "WPS attribute parsing test %u failed: %s",
+ i, test->data);
+ ret = -1;
+ }
+ switch (test->extra) {
+ case 1:
+ if (!attr.network_key || !attr.ap_setup_locked)
+ ret = -1;
+ break;
+ case 2:
+ if (attr.num_cred != MAX_CRED_COUNT)
+ ret = -1;
+ break;
+ case 3:
+ if (!attr.network_key_idx)
+ ret = -1;
+ break;
+ case 4:
+ if (attr.num_req_dev_type != MAX_REQ_DEV_TYPE_COUNT)
+ ret = -1;
+ break;
+ case 5:
+ if (attr.num_vendor_ext != MAX_WPS_PARSE_VENDOR_EXT)
+ ret = -1;
+ break;
+ case 6:
+ if (!attr.version2 ||
+ !attr.authorized_macs ||
+ !attr.network_key_shareable ||
+ !attr.request_to_enroll ||
+ !attr.settings_delay_time)
+ ret = -1;
+ break;
+ }
+ wpabuf_free(buf);
+ }
+
+ return ret;
+}
+
+
+int wps_module_tests(void)
+{
+ int ret = 0;
+
+ wpa_printf(MSG_INFO, "WPS module tests");
+
+ if (wps_attr_parse_tests() < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index d01b18f..7b556e8 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -97,6 +97,14 @@
OBJS_p += ../src/utils/os_$(CONFIG_OS).o
OBJS_c += ../src/utils/os_$(CONFIG_OS).o
+ifdef CONFIG_MODULE_TESTS
+CFLAGS += -DCONFIG_MODULE_TESTS
+OBJS += wpas_module_tests.o
+ifdef CONFIG_WPS
+OBJS += ../src/wps/wps_module_tests.o
+endif
+endif
+
ifdef CONFIG_WPA_TRACE
CFLAGS += -DWPA_TRACE
OBJS += ../src/utils/trace.o
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 0d88133..e95b55b 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -6761,6 +6761,12 @@
} else if (os_strcmp(buf, "STATUS") == 0) {
reply_len = wpas_global_ctrl_iface_status(global, reply,
reply_size);
+#ifdef CONFIG_MODULE_TESTS
+ } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
+ int wpas_module_tests(void);
+ if (wpas_module_tests() < 0)
+ reply_len = -1;
+#endif /* CONFIG_MODULE_TESTS */
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index fa82491..fa75fa5 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -4771,6 +4771,10 @@
p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
wpa_s->pending_listen_duration);
wpa_s->pending_listen_freq = 0;
+ } else {
+ wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)",
+ wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
+ freq, duration);
}
}
diff --git a/wpa_supplicant/wpas_module_tests.c b/wpa_supplicant/wpas_module_tests.c
new file mode 100644
index 0000000..4e39024
--- /dev/null
+++ b/wpa_supplicant/wpas_module_tests.c
@@ -0,0 +1,28 @@
+/*
+ * wpa_supplicant module tests
+ * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+
+int wpas_module_tests(void)
+{
+ int ret = 0;
+
+ wpa_printf(MSG_INFO, "wpa_supplicant module tests");
+
+#ifdef CONFIG_WPS
+ {
+ int wps_module_tests(void);
+ if (wps_module_tests() < 0)
+ ret = -1;
+ }
+#endif /* CONFIG_WPS */
+
+ return ret;
+}