3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-30 06:39:46 +01:00
iwd/unit/test-ssid-security.c

128 lines
3.4 KiB
C
Raw Normal View History

/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2015 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <ell/ell.h>
2016-05-11 22:53:35 +02:00
#include "src/iwd.h"
#include "src/common.h"
#include "src/ie.h"
struct test_data {
2015-01-28 21:25:39 +01:00
unsigned char *rsne;
unsigned int rsne_len;
enum ie_bss_capability capability;
2016-05-11 22:53:35 +02:00
enum security expected;
};
static unsigned char ssid_security_wpa_data_1[] = {
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
0x00, 0x0f, 0xac, 0x02, 0x0c, 0x00,
};
static struct test_data ssid_security_wpa_test_1 = {
2015-01-28 21:25:39 +01:00
.rsne = ssid_security_wpa_data_1,
.rsne_len = sizeof(ssid_security_wpa_data_1),
.capability = IE_BSS_CAP_ESS,
2016-05-11 22:53:35 +02:00
.expected = SECURITY_PSK,
};
static unsigned char ssid_security_wpa2_data_1[] = {
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
0x00, 0x0f, 0xac, 0x02, 0x00, 0x00,
};
static struct test_data ssid_security_wpa_test_2 = {
2015-01-28 21:25:39 +01:00
.rsne = ssid_security_wpa2_data_1,
.rsne_len = sizeof(ssid_security_wpa2_data_1),
.capability = IE_BSS_CAP_ESS,
2016-05-11 22:53:35 +02:00
.expected = SECURITY_PSK,
};
static unsigned char ssid_security_8021x_data_1[] = {
0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
0x00, 0x0f, 0xac, 0x01, 0x28, 0x00,
};
static struct test_data ssid_security_8021x_test_1 = {
2015-01-28 21:25:39 +01:00
.rsne = ssid_security_8021x_data_1,
.rsne_len = sizeof(ssid_security_8021x_data_1),
.capability = IE_BSS_CAP_ESS,
2016-05-11 22:53:35 +02:00
.expected = SECURITY_8021X,
};
static struct test_data ssid_security_wep_test_1 = {
.capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY,
2016-05-11 22:53:35 +02:00
.expected = SECURITY_WEP,
};
static struct test_data ssid_security_open_test_1 = {
.capability = IE_BSS_CAP_ESS,
2016-05-11 22:53:35 +02:00
.expected = SECURITY_NONE,
};
2015-01-28 21:25:39 +01:00
static void ssid_security_test(const void *data)
{
2015-01-28 21:25:39 +01:00
const struct test_data *test = data;
struct ie_rsn_info info;
2015-01-28 21:25:39 +01:00
const struct ie_rsn_info *infop;
int ret;
2015-01-28 21:25:39 +01:00
if (test->rsne) {
ret = ie_parse_rsne_from_data(test->rsne,
test->rsne_len, &info);
assert(ret == 0);
2015-01-28 21:25:39 +01:00
infop = &info;
} else
infop = NULL;
assert(security_determine(test->capability, infop) == test->expected);
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
l_test_add("/SSID Security/Open",
2015-01-28 21:25:39 +01:00
ssid_security_test, &ssid_security_open_test_1);
l_test_add("/SSID Security/WPA",
2015-01-28 21:25:39 +01:00
ssid_security_test, &ssid_security_wpa_test_1);
l_test_add("/SSID Security/WPA2",
2015-01-28 21:25:39 +01:00
ssid_security_test, &ssid_security_wpa_test_2);
l_test_add("/SSID Security/8021x",
2015-01-28 21:25:39 +01:00
ssid_security_test, &ssid_security_8021x_test_1);
l_test_add("/SSID Security/WEP",
2015-01-28 21:25:39 +01:00
ssid_security_test, &ssid_security_wep_test_1);
return l_test_run();
}