From 11c7393bebe4df6e2061f69787f4a7dd5c31f077 Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 9 Jan 2022 15:20:45 +0000 Subject: test: Add beacon parser test --- test/CMakeLists.txt | 1 + test/src/beacon_tests.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- utils/src/test_generation.c | 5 ----- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 32934a5..64f8f36 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -53,6 +53,7 @@ add_test(NAME test_auth_gen_tags COMMAND auth_tests --auth-gen-tags) add_test(NAME test_beacon_gen_full COMMAND beacon_tests --beacon-gen-full) add_test(NAME test_beacon_gen_tags COMMAND beacon_tests --beacon-gen-tags) +add_test(NAME test_beacon_parse COMMAND beacon_tests --beacon-parse) add_test(NAME test_deauth_gen_full COMMAND deauth_tests --deauth-gen-full) add_test(NAME test_deauth_gen_tags COMMAND deauth_tests --deauth-gen-tags) diff --git a/test/src/beacon_tests.c b/test/src/beacon_tests.c index 1c4e17e..d152d5e 100644 --- a/test/src/beacon_tests.c +++ b/test/src/beacon_tests.c @@ -9,6 +9,18 @@ const unsigned char to[] = TO_MAC; const unsigned char bcast[] = BCAST_MAC; +const unsigned char beacon[] = "\x00\x00\x18\x00\x8e\x58\x00\x00\x10\x02\x6c\x09\xa0\x00\x54\x00" \ + "\x00\x2b\x00\x00\x9f\x61\xc9\x5c\x80\x00\x00\x00\xff\xff\xff\xff" \ + "\xff\xff\x00\x0c\x41\x82\xb2\x55\x00\x0c\x41\x82\xb2\x55\x50\xf8" \ + "\x89\xf1\xd4\x1b\x01\x00\x00\x00\x64\x00\x11\x04\x00\x07\x43\x6f" \ + "\x68\x65\x72\x65\x72\x01\x08\x82\x84\x8b\x96\x24\x30\x48\x6c\x03" \ + "\x01\x01\x05\x04\x00\x01\x00\x00\x2a\x01\x02\x2f\x01\x02\x30\x18" \ + "\x01\x00\x00\x0f\xac\x02\x02\x00\x00\x0f\xac\x04\x00\x0f\xac\x02" \ + "\x01\x00\x00\x0f\xac\x02\x00\x00\x32\x04\x0c\x12\x18\x60\xdd\x06" \ + "\x00\x10\x18\x02\x00\x04\xdd\x1c\x00\x50\xf2\x01\x01\x00\x00\x50" \ + "\xf2\x02\x02\x00\x00\x50\xf2\x04\x00\x50\xf2\x02\x01\x00\x00\x50" \ + "\xf2\x02\x00\x00\x9f\x61\xc9\x5c"; + int test_beacon_gen_full() { struct libwifi_beacon beacon = {0}; @@ -48,7 +60,10 @@ int test_beacon_add_tag() { return ret; } - ret = libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); + ret = libwifi_quick_add_tag(&beacon.tags, + TAG_VENDOR_SPECIFIC, + (const unsigned char *) "\x00\x11\x22\xAAHello World", + 15); if (ret != 0) { fprintf(stderr, "Failed to add beacon tagged parameter: %s\n", strerror(ret)); return ret; @@ -75,6 +90,38 @@ int test_beacon_add_tag() { return 0; } +int test_beacon_parse() { + struct libwifi_frame frame = {0}; + struct libwifi_bss bss = {0}; + + int ret = libwifi_get_wifi_frame(&frame, beacon, sizeof(beacon), 1); + if (ret != 0) { + return ret; + } + + if (frame.frame_control.type != TYPE_MANAGEMENT || frame.frame_control.subtype != SUBTYPE_BEACON) { + return -1; + } + + ret = libwifi_parse_beacon(&bss, &frame); + if (ret != 0) { + return ret; + } + + if (strcmp(bss.ssid, "Coherer") != 0) { + return -2; + } + + if (bss.channel != 1) { + return -3; + } + + libwifi_free_bss(&bss); + libwifi_free_wifi_frame(&frame); + + return 0; +} + int main(int argc, char **argv) { if (argc < 2) { printf("Specify test\n"); @@ -85,6 +132,8 @@ int main(int argc, char **argv) { return test_beacon_gen_full(); } else if (strcmp(argv[1], "--beacon-gen-tags") == 0) { return test_beacon_add_tag(); + } else if (strcmp(argv[1], "--beacon-parse") == 0) { + return test_beacon_parse(); } return -1; diff --git a/utils/src/test_generation.c b/utils/src/test_generation.c index 407e87f..314ce34 100644 --- a/utils/src/test_generation.c +++ b/utils/src/test_generation.c @@ -1,10 +1,5 @@ #include #include -#include -#include -#include -#include -#include #include #include #include -- cgit 1.4.1