about summary refs log tree commit diff stats
path: root/test/src/probe_req_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/probe_req_tests.c')
-rw-r--r--test/src/probe_req_tests.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/probe_req_tests.c b/test/src/probe_req_tests.c new file mode 100644 index 0000000..553c9d9 --- /dev/null +++ b/test/src/probe_req_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"
9const unsigned char to[] = TO_MAC;
10const unsigned char bcast[] = BCAST_MAC;
11
12int test_probe_req_gen_full() {
13 struct libwifi_probe_req probe_req = {0};
14
15 int ret = libwifi_create_probe_req(&probe_req, bcast, to, to, "Some SSID", 11);
16 if (ret != 0) {
17 fprintf(stderr, "Failed to create probe_req: %s\n", strerror(ret));
18 return ret;
19 }
20
21 int probe_req_len = libwifi_get_probe_req_length(&probe_req);
22 if (probe_req_len <= 0) {
23 fprintf(stderr, "Invalid probe_req length: %d\n", probe_req_len);
24 return probe_req_len;
25 }
26
27 unsigned char *buf = malloc(probe_req_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_req(&probe_req, buf, probe_req_len);
34 if (dump_len <= 0) {
35 fprintf(stderr, "Failed to dump probe_req\n");
36 return ret;
37 }
38
39 return 0;
40}
41
42int test_probe_req_add_tag() {
43 struct libwifi_probe_req probe_req = {0};
44
45 int ret = libwifi_create_probe_req(&probe_req, bcast, to, to, "Some SSID", 11);
46 if (ret != 0) {
47 fprintf(stderr, "Failed to create probe_req: %s\n", strerror(ret));
48 return ret;
49 }
50
51 ret = libwifi_quick_add_tag(&probe_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15);
52 if (ret != 0) {
53 fprintf(stderr, "Failed to add probe_req tagged parameter: %s\n", strerror(ret));
54 return ret;
55 }
56
57 int probe_req_len = libwifi_get_probe_req_length(&probe_req);
58 if (probe_req_len <= 0) {
59 fprintf(stderr, "Invalid probe_req length: %d\n", probe_req_len);
60 return probe_req_len;
61 }
62
63 unsigned char *buf = malloc(probe_req_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_req(&probe_req, buf, probe_req_len);
70 if (dump_len <= 0) {
71 fprintf(stderr, "Failed to dump probe_req\n");
72 return ret;
73 }
74
75 return 0;
76}
77
78int 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_req-gen-full") == 0) {
85 return test_probe_req_gen_full();
86 } else if (strcmp(argv[1], "--probe_req-gen-tags") == 0) {
87 return test_probe_req_add_tag();
88 }
89
90 return -1;
91}