xref: /freebsd/contrib/wpa/wpa_supplicant/wpas_module_tests.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
15b9c547cSRui Paulo /*
25b9c547cSRui Paulo  * wpa_supplicant module tests
35b9c547cSRui Paulo  * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
45b9c547cSRui Paulo  *
55b9c547cSRui Paulo  * This software may be distributed under the terms of the BSD license.
65b9c547cSRui Paulo  * See README for more details.
75b9c547cSRui Paulo  */
85b9c547cSRui Paulo 
95b9c547cSRui Paulo #include "utils/includes.h"
105b9c547cSRui Paulo 
115b9c547cSRui Paulo #include "utils/common.h"
12780fb4a2SCy Schubert #include "utils/module_tests.h"
135b9c547cSRui Paulo #include "wpa_supplicant_i.h"
14c1d255d3SCy Schubert #include "bssid_ignore.h"
155b9c547cSRui Paulo 
165b9c547cSRui Paulo 
wpas_bssid_ignore_module_tests(void)17c1d255d3SCy Schubert static int wpas_bssid_ignore_module_tests(void)
185b9c547cSRui Paulo {
195b9c547cSRui Paulo 	struct wpa_supplicant wpa_s;
20*a90b9d01SCy Schubert 	struct wpa_global global;
215b9c547cSRui Paulo 	int ret = -1;
225b9c547cSRui Paulo 
235b9c547cSRui Paulo 	os_memset(&wpa_s, 0, sizeof(wpa_s));
24*a90b9d01SCy Schubert 	os_memset(&global, 0, sizeof(global));
25*a90b9d01SCy Schubert 	wpa_s.global = &global;
265b9c547cSRui Paulo 
27c1d255d3SCy Schubert 	wpa_bssid_ignore_clear(&wpa_s);
285b9c547cSRui Paulo 
29c1d255d3SCy Schubert 	if (wpa_bssid_ignore_get(NULL, NULL) != NULL ||
30c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(NULL, (u8 *) "123456") != NULL ||
31c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, NULL) != NULL ||
32c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, (u8 *) "123456") != NULL)
335b9c547cSRui Paulo 		goto fail;
345b9c547cSRui Paulo 
35c1d255d3SCy Schubert 	if (wpa_bssid_ignore_add(NULL, NULL) == 0 ||
36c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(NULL, (u8 *) "123456") == 0 ||
37c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, NULL) == 0)
385b9c547cSRui Paulo 		goto fail;
395b9c547cSRui Paulo 
40c1d255d3SCy Schubert 	if (wpa_bssid_ignore_del(NULL, NULL) == 0 ||
41c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(NULL, (u8 *) "123456") == 0 ||
42c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, NULL) == 0 ||
43c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "123456") == 0)
445b9c547cSRui Paulo 		goto fail;
455b9c547cSRui Paulo 
46c1d255d3SCy Schubert 	if (wpa_bssid_ignore_add(&wpa_s, (u8 *) "111111") < 0 ||
47c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "111111") < 0 ||
48c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "222222") < 0 ||
49c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "333333") < 0 ||
50c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "444444") < 0 ||
51c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "333333") < 0 ||
52c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "xxxxxx") == 0 ||
53c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, (u8 *) "xxxxxx") != NULL ||
54c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, (u8 *) "111111") == NULL ||
55c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, (u8 *) "222222") == NULL ||
56c1d255d3SCy Schubert 	    wpa_bssid_ignore_get(&wpa_s, (u8 *) "444444") == NULL ||
57c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "111111") < 0 ||
58c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "222222") < 0 ||
59c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "444444") < 0 ||
60c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "111111") < 0 ||
61c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "222222") < 0 ||
62c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "333333") < 0)
63c1d255d3SCy Schubert 		goto fail;
64c1d255d3SCy Schubert 
65c1d255d3SCy Schubert 	wpa_bssid_ignore_clear(&wpa_s);
66c1d255d3SCy Schubert 
67c1d255d3SCy Schubert 	if (wpa_bssid_ignore_add(&wpa_s, (u8 *) "111111") < 0 ||
68c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "222222") < 0 ||
69c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "333333") < 0 ||
70c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "444444") < 0 ||
71c1d255d3SCy Schubert 	    !wpa_bssid_ignore_is_listed(&wpa_s, (u8 *) "111111") ||
72c1d255d3SCy Schubert 	    wpa_bssid_ignore_del(&wpa_s, (u8 *) "111111") < 0 ||
73c1d255d3SCy Schubert 	    wpa_bssid_ignore_is_listed(&wpa_s, (u8 *) "111111") ||
74c1d255d3SCy Schubert 	    wpa_bssid_ignore_add(&wpa_s, (u8 *) "111111") < 0)
75c1d255d3SCy Schubert 		goto fail;
76c1d255d3SCy Schubert 
77c1d255d3SCy Schubert 	wpa_bssid_ignore_update(&wpa_s);
78c1d255d3SCy Schubert 
79c1d255d3SCy Schubert 	if (!wpa_bssid_ignore_is_listed(&wpa_s, (u8 *) "111111"))
805b9c547cSRui Paulo 		goto fail;
815b9c547cSRui Paulo 
825b9c547cSRui Paulo 	ret = 0;
835b9c547cSRui Paulo fail:
84c1d255d3SCy Schubert 	wpa_bssid_ignore_clear(&wpa_s);
855b9c547cSRui Paulo 
865b9c547cSRui Paulo 	if (ret)
87c1d255d3SCy Schubert 		wpa_printf(MSG_ERROR, "bssid_ignore module test failure");
885b9c547cSRui Paulo 
895b9c547cSRui Paulo 	return ret;
905b9c547cSRui Paulo }
915b9c547cSRui Paulo 
925b9c547cSRui Paulo 
wpas_module_tests(void)935b9c547cSRui Paulo int wpas_module_tests(void)
945b9c547cSRui Paulo {
955b9c547cSRui Paulo 	int ret = 0;
965b9c547cSRui Paulo 
975b9c547cSRui Paulo 	wpa_printf(MSG_INFO, "wpa_supplicant module tests");
985b9c547cSRui Paulo 
99c1d255d3SCy Schubert 	if (wpas_bssid_ignore_module_tests() < 0)
1005b9c547cSRui Paulo 		ret = -1;
1015b9c547cSRui Paulo 
1025b9c547cSRui Paulo #ifdef CONFIG_WPS
1035b9c547cSRui Paulo 	if (wps_module_tests() < 0)
1045b9c547cSRui Paulo 		ret = -1;
1055b9c547cSRui Paulo #endif /* CONFIG_WPS */
1065b9c547cSRui Paulo 
1075b9c547cSRui Paulo 	if (utils_module_tests() < 0)
1085b9c547cSRui Paulo 		ret = -1;
1095b9c547cSRui Paulo 
1105b9c547cSRui Paulo 	if (common_module_tests() < 0)
1115b9c547cSRui Paulo 		ret = -1;
1125b9c547cSRui Paulo 
1135b9c547cSRui Paulo 	if (crypto_module_tests() < 0)
1145b9c547cSRui Paulo 		ret = -1;
1155b9c547cSRui Paulo 
1165b9c547cSRui Paulo 	return ret;
1175b9c547cSRui Paulo }
118