diff options
Diffstat (limited to 'test/src/probe_resp_tests.c')
-rw-r--r-- | test/src/probe_resp_tests.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/probe_resp_tests.c b/test/src/probe_resp_tests.c new file mode 100644 index 0000000..463a90a --- /dev/null +++ b/test/src/probe_resp_tests.c | |||
@@ -0,0 +1,91 @@ | |||
1 | #include "../../src/libwifi.h" | ||
2 | |||
3 | #include <errno.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" | ||
8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" | ||
9 | const unsigned char to[] = TO_MAC; | ||
10 | const unsigned char bcast[] = BCAST_MAC; | ||
11 | |||
12 | int test_probe_resp_gen_full() { | ||
13 | struct libwifi_probe_resp probe_resp = {0}; | ||
14 | |||
15 | int ret = libwifi_create_probe_resp(&probe_resp, bcast, to, "Some SSID", 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create probe_resp: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int probe_resp_len = libwifi_get_probe_resp_length(&probe_resp); | ||
22 | if (probe_resp_len <= 0) { | ||
23 | fprintf(stderr, "Invalid probe_resp length: %d\n", probe_resp_len); | ||
24 | return probe_resp_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(probe_resp_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_probe_resp(&probe_resp, buf, probe_resp_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump probe_resp\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_probe_resp_add_tag() { | ||
43 | struct libwifi_probe_resp probe_resp = {0}; | ||
44 | |||
45 | int ret = libwifi_create_probe_resp(&probe_resp, bcast, to, "Some SSID", 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create probe_resp: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&probe_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add probe_resp tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int probe_resp_len = libwifi_get_probe_resp_length(&probe_resp); | ||
58 | if (probe_resp_len <= 0) { | ||
59 | fprintf(stderr, "Invalid probe_resp length: %d\n", probe_resp_len); | ||
60 | return probe_resp_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(probe_resp_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_probe_resp(&probe_resp, buf, probe_resp_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump probe_resp\n"); | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | int main(int argc, char **argv) { | ||
79 | if (argc < 2) { | ||
80 | printf("Specify test\n"); | ||
81 | return -1; | ||
82 | } | ||
83 | |||
84 | if (strcmp(argv[1], "--probe_resp-gen-full") == 0) { | ||
85 | return test_probe_resp_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--probe_resp-gen-tags") == 0) { | ||
87 | return test_probe_resp_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||