diff options
41 files changed, 1413 insertions, 62 deletions
diff --git a/.github/workflows/x86_64.yml b/.github/workflows/x86_64.yml index 844a109..cc90e1d 100644 --- a/.github/workflows/x86_64.yml +++ b/.github/workflows/x86_64.yml | |||
@@ -22,6 +22,43 @@ jobs: | |||
22 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | 22 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE |
23 | 23 | ||
24 | - name: Build X86_64 | 24 | - name: Build X86_64 |
25 | shell: bash | ||
26 | working-directory: ${{github.workspace}}/build | ||
27 | run: cmake --build . --config $BUILD_TYPE | ||
28 | |||
29 | test: | ||
30 | runs-on: ubuntu-latest | ||
31 | |||
32 | steps: | ||
33 | - uses: actions/checkout@v2 | ||
34 | |||
35 | - name: Create Build Environment | ||
36 | run: cmake -E make_directory ${{github.workspace}}/build | ||
37 | |||
38 | - name: Configure CMake | ||
39 | shell: bash | ||
25 | working-directory: ${{github.workspace}}/build | 40 | working-directory: ${{github.workspace}}/build |
41 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | ||
42 | |||
43 | - name: Build X86_64 | ||
26 | shell: bash | 44 | shell: bash |
45 | working-directory: ${{github.workspace}}/build | ||
27 | run: cmake --build . --config $BUILD_TYPE | 46 | run: cmake --build . --config $BUILD_TYPE |
47 | |||
48 | - name: Create Test Environment | ||
49 | run: cmake -E make_directory ${{github.workspace}}/test/build | ||
50 | |||
51 | - name: Configure CMake | ||
52 | shell: bash | ||
53 | working-directory: ${{github.workspace}}/test/build | ||
54 | run: cmake ${{github.workspace}}/test | ||
55 | |||
56 | - name: Build Tests | ||
57 | shell: bash | ||
58 | working-directory: ${{github.workspace}}/test/build | ||
59 | run: cmake --build . | ||
60 | |||
61 | - name: Test X86_64 | ||
62 | shell: bash | ||
63 | working-directory: ${{github.workspace}}/test/build | ||
64 | run: ctest --output-on-failure | ||
diff --git a/src/libwifi/gen/management/assoc_request.c b/src/libwifi/gen/management/assoc_request.c index 8ba3585..268b167 100644 --- a/src/libwifi/gen/management/assoc_request.c +++ b/src/libwifi/gen/management/assoc_request.c | |||
@@ -47,8 +47,15 @@ int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req, const unsigned | |||
47 | assoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); | 47 | assoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); |
48 | assoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); | 48 | assoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); |
49 | 49 | ||
50 | libwifi_quick_add_tag(&assoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); | 50 | int ret = libwifi_quick_add_tag(&assoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); |
51 | libwifi_quick_add_tag(&assoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | 51 | if (ret != 0) { |
52 | return ret; | ||
53 | } | ||
54 | |||
55 | ret = libwifi_quick_add_tag(&assoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | ||
56 | if (ret != 0) { | ||
57 | return ret; | ||
58 | } | ||
52 | 59 | ||
53 | return 0; | 60 | return 0; |
54 | } | 61 | } |
diff --git a/src/libwifi/gen/management/assoc_response.c b/src/libwifi/gen/management/assoc_response.c index be00511..b3077de 100644 --- a/src/libwifi/gen/management/assoc_response.c +++ b/src/libwifi/gen/management/assoc_response.c | |||
@@ -41,21 +41,28 @@ size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp) { | |||
41 | * Simple helper function to set the channel of an association response by removing and re-adding the | 41 | * Simple helper function to set the channel of an association response by removing and re-adding the |
42 | * DS tagged parameter. | 42 | * DS tagged parameter. |
43 | */ | 43 | */ |
44 | void libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel) { | 44 | int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel) { |
45 | int ret = 0; | ||
46 | |||
45 | if (assoc_resp->tags.length != 0) { | 47 | if (assoc_resp->tags.length != 0) { |
46 | libwifi_remove_tag(&assoc_resp->tags, TAG_DS_PARAMETER); | 48 | ret = libwifi_remove_tag(&assoc_resp->tags, TAG_DS_PARAMETER); |
49 | if (ret != 0) { | ||
50 | return ret; | ||
51 | } | ||
47 | } | 52 | } |
48 | 53 | ||
49 | const unsigned char *chan = (const unsigned char *) &channel; | 54 | const unsigned char *chan = (const unsigned char *) &channel; |
50 | 55 | ||
51 | libwifi_quick_add_tag(&assoc_resp->tags, TAG_DS_PARAMETER, chan, 1); | 56 | ret = libwifi_quick_add_tag(&assoc_resp->tags, TAG_DS_PARAMETER, chan, 1); |
57 | |||
58 | return ret; | ||
52 | } | 59 | } |
53 | 60 | ||
54 | /** | 61 | /** |
55 | * The generated association response frame is made with sane defaults defined in common.h and core/types.h. | 62 | * The generated association response frame is made with sane defaults defined in common.h and core/types.h. |
56 | * Two tagged parameters are also added to the association response: Channel and Supported Rates. | 63 | * Two tagged parameters are also added to the association response: Channel and Supported Rates. |
57 | */ | 64 | */ |
58 | void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], | 65 | int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], |
59 | const unsigned char transmitter[6], uint8_t channel) { | 66 | const unsigned char transmitter[6], uint8_t channel) { |
60 | memset(assoc_resp, 0, sizeof(struct libwifi_assoc_resp)); | 67 | memset(assoc_resp, 0, sizeof(struct libwifi_assoc_resp)); |
61 | 68 | ||
@@ -71,7 +78,9 @@ void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsi | |||
71 | libwifi_set_assoc_resp_channel(assoc_resp, channel); | 78 | libwifi_set_assoc_resp_channel(assoc_resp, channel); |
72 | 79 | ||
73 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; | 80 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; |
74 | libwifi_quick_add_tag(&assoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); | 81 | int ret = libwifi_quick_add_tag(&assoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); |
82 | |||
83 | return ret; | ||
75 | } | 84 | } |
76 | 85 | ||
77 | /** | 86 | /** |
diff --git a/src/libwifi/gen/management/assoc_response.h b/src/libwifi/gen/management/assoc_response.h index 9162d1c..07ad4b4 100644 --- a/src/libwifi/gen/management/assoc_response.h +++ b/src/libwifi/gen/management/assoc_response.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * @param assoc_resp A libwifi_assoc_resp | 24 | * @param assoc_resp A libwifi_assoc_resp |
25 | * @param channel The new channel | 25 | * @param channel The new channel |
26 | */ | 26 | */ |
27 | void libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); | 27 | int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Calculate the length of a given libwifi_assoc_resp | 30 | * Calculate the length of a given libwifi_assoc_resp |
@@ -46,7 +46,7 @@ size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp); | |||
46 | * @param channel The desired channel of the assoc_resp | 46 | * @param channel The desired channel of the assoc_resp |
47 | * | 47 | * |
48 | */ | 48 | */ |
49 | void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], | 49 | int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], |
50 | const unsigned char transmitter[6], uint8_t channel); | 50 | const unsigned char transmitter[6], uint8_t channel); |
51 | 51 | ||
52 | /** | 52 | /** |
diff --git a/src/libwifi/gen/management/authentication.c b/src/libwifi/gen/management/authentication.c index 7fcaa22..e8ffea2 100644 --- a/src/libwifi/gen/management/authentication.c +++ b/src/libwifi/gen/management/authentication.c | |||
@@ -32,7 +32,7 @@ size_t libwifi_get_auth_length(struct libwifi_auth *auth) { | |||
32 | /** | 32 | /** |
33 | * The generated authentication frame is made with sane defaults defined in common.h. | 33 | * The generated authentication frame is made with sane defaults defined in common.h. |
34 | */ | 34 | */ |
35 | void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], | 35 | int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], |
36 | const unsigned char transmitter[6], uint16_t algorithm_number, | 36 | const unsigned char transmitter[6], uint16_t algorithm_number, |
37 | uint16_t transaction_sequence, uint16_t status_code) { | 37 | uint16_t transaction_sequence, uint16_t status_code) { |
38 | memset(auth, 0, sizeof(struct libwifi_auth)); | 38 | memset(auth, 0, sizeof(struct libwifi_auth)); |
@@ -47,6 +47,8 @@ void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver | |||
47 | auth->fixed_parameters.algorithm_number = algorithm_number; | 47 | auth->fixed_parameters.algorithm_number = algorithm_number; |
48 | auth->fixed_parameters.transaction_sequence = transaction_sequence; | 48 | auth->fixed_parameters.transaction_sequence = transaction_sequence; |
49 | auth->fixed_parameters.status_code = status_code; | 49 | auth->fixed_parameters.status_code = status_code; |
50 | |||
51 | return 0; | ||
50 | } | 52 | } |
51 | 53 | ||
52 | /** | 54 | /** |
diff --git a/src/libwifi/gen/management/authentication.h b/src/libwifi/gen/management/authentication.h index 4328f95..75e8dcf 100644 --- a/src/libwifi/gen/management/authentication.h +++ b/src/libwifi/gen/management/authentication.h | |||
@@ -40,7 +40,7 @@ size_t libwifi_get_auth_length(struct libwifi_auth *auth); | |||
40 | * @param algorithm_number Algorithm type to use | 40 | * @param algorithm_number Algorithm type to use |
41 | * | 41 | * |
42 | */ | 42 | */ |
43 | void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], | 43 | int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], |
44 | const unsigned char transmitter[6], uint16_t algorithm_number, | 44 | const unsigned char transmitter[6], uint16_t algorithm_number, |
45 | uint16_t transaction_sequence, uint16_t status_code); | 45 | uint16_t transaction_sequence, uint16_t status_code); |
46 | 46 | ||
diff --git a/src/libwifi/gen/management/beacon.c b/src/libwifi/gen/management/beacon.c index 4eb394a..e678fd7 100644 --- a/src/libwifi/gen/management/beacon.c +++ b/src/libwifi/gen/management/beacon.c | |||
@@ -39,32 +39,46 @@ size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon) { | |||
39 | /** | 39 | /** |
40 | * Simple helper to set the beacon SSID tag by removing it and then adding it back with the new value. | 40 | * Simple helper to set the beacon SSID tag by removing it and then adding it back with the new value. |
41 | */ | 41 | */ |
42 | void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid) { | 42 | int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid) { |
43 | int ret = 0; | ||
44 | |||
43 | if (beacon->tags.length != 0) { | 45 | if (beacon->tags.length != 0) { |
44 | libwifi_remove_tag(&beacon->tags, TAG_SSID); | 46 | ret = libwifi_remove_tag(&beacon->tags, TAG_SSID); |
47 | if (ret != 0) { | ||
48 | return ret; | ||
49 | } | ||
45 | } | 50 | } |
46 | 51 | ||
47 | libwifi_quick_add_tag(&beacon->tags, TAG_SSID, (void *) ssid, strlen(ssid)); | 52 | ret = libwifi_quick_add_tag(&beacon->tags, TAG_SSID, (void *) ssid, strlen(ssid)); |
53 | |||
54 | return ret; | ||
48 | } | 55 | } |
49 | 56 | ||
50 | /** | 57 | /** |
51 | * Simple helper to set the beacon DS tag by removing it and then adding it back with the new value. | 58 | * Simple helper to set the beacon DS tag by removing it and then adding it back with the new value. |
52 | */ | 59 | */ |
53 | void libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) { | 60 | int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) { |
61 | int ret = 0; | ||
62 | |||
54 | if (beacon->tags.length != 0) { | 63 | if (beacon->tags.length != 0) { |
55 | libwifi_remove_tag(&beacon->tags, TAG_DS_PARAMETER); | 64 | ret = libwifi_remove_tag(&beacon->tags, TAG_DS_PARAMETER); |
65 | if (ret != 0) { | ||
66 | return ret; | ||
67 | } | ||
56 | } | 68 | } |
57 | 69 | ||
58 | const unsigned char *chan = (const unsigned char *) &channel; | 70 | const unsigned char *chan = (const unsigned char *) &channel; |
59 | 71 | ||
60 | libwifi_quick_add_tag(&beacon->tags, TAG_DS_PARAMETER, chan, 1); | 72 | ret = libwifi_quick_add_tag(&beacon->tags, TAG_DS_PARAMETER, chan, 1); |
73 | |||
74 | return ret; | ||
61 | } | 75 | } |
62 | 76 | ||
63 | /** | 77 | /** |
64 | * The generated beacon frame is made with sane defaults defined in common.h. | 78 | * The generated beacon frame is made with sane defaults defined in common.h. |
65 | * Three tagged parameters are also added to the beacon: SSID, Channel and Supported Rates. | 79 | * Three tagged parameters are also added to the beacon: SSID, Channel and Supported Rates. |
66 | */ | 80 | */ |
67 | void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], | 81 | int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], |
68 | const unsigned char transmitter[6], const char *ssid, uint8_t channel) { | 82 | const unsigned char transmitter[6], const char *ssid, uint8_t channel) { |
69 | memset(beacon, 0, sizeof(struct libwifi_beacon)); | 83 | memset(beacon, 0, sizeof(struct libwifi_beacon)); |
70 | 84 | ||
@@ -82,7 +96,9 @@ void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char re | |||
82 | libwifi_set_beacon_channel(beacon, channel); | 96 | libwifi_set_beacon_channel(beacon, channel); |
83 | 97 | ||
84 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; | 98 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; |
85 | libwifi_quick_add_tag(&beacon->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); | 99 | int ret = libwifi_quick_add_tag(&beacon->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); |
100 | |||
101 | return ret; | ||
86 | } | 102 | } |
87 | 103 | ||
88 | /** | 104 | /** |
diff --git a/src/libwifi/gen/management/beacon.h b/src/libwifi/gen/management/beacon.h index 3da342b..971df88 100644 --- a/src/libwifi/gen/management/beacon.h +++ b/src/libwifi/gen/management/beacon.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * @param beacon A struct libwifi_beacon | 24 | * @param beacon A struct libwifi_beacon |
25 | * @param ssid The new SSID | 25 | * @param ssid The new SSID |
26 | */ | 26 | */ |
27 | void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); | 27 | int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Set the channel of a struct libwifi_beacon. | 30 | * Set the channel of a struct libwifi_beacon. |
@@ -32,7 +32,7 @@ void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); | |||
32 | * @param beacon A struct libwifi_beacon | 32 | * @param beacon A struct libwifi_beacon |
33 | * @param channel The new channel | 33 | * @param channel The new channel |
34 | */ | 34 | */ |
35 | void libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel); | 35 | int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Calculate the length of a given struct libwifi_beacon | 38 | * Calculate the length of a given struct libwifi_beacon |
@@ -55,7 +55,7 @@ size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon); | |||
55 | * @param channel The desired channel of the beacon | 55 | * @param channel The desired channel of the beacon |
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], | 58 | int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], |
59 | const unsigned char transmitter[6], const char *ssid, uint8_t channel); | 59 | const unsigned char transmitter[6], const char *ssid, uint8_t channel); |
60 | 60 | ||
61 | /** | 61 | /** |
diff --git a/src/libwifi/gen/management/disassociation.c b/src/libwifi/gen/management/disassociation.c index a885efd..d6cf237 100644 --- a/src/libwifi/gen/management/disassociation.c +++ b/src/libwifi/gen/management/disassociation.c | |||
@@ -33,7 +33,7 @@ size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc) { | |||
33 | * The generated disassociation frame contains only the supplied receiver, transmitter and reason_code by | 33 | * The generated disassociation frame contains only the supplied receiver, transmitter and reason_code by |
34 | * default. | 34 | * default. |
35 | */ | 35 | */ |
36 | void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], | 36 | int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], |
37 | const unsigned char transmitter[6], uint16_t reason_code) { | 37 | const unsigned char transmitter[6], uint16_t reason_code) { |
38 | memset(disassoc, 0, sizeof(struct libwifi_disassoc)); | 38 | memset(disassoc, 0, sizeof(struct libwifi_disassoc)); |
39 | 39 | ||
@@ -46,6 +46,8 @@ void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned c | |||
46 | disassoc->frame_header.seq_control.sequence_number = (rand() % 4096); | 46 | disassoc->frame_header.seq_control.sequence_number = (rand() % 4096); |
47 | 47 | ||
48 | memcpy(&disassoc->fixed_parameters.reason_code, &reason_code, sizeof(reason_code)); | 48 | memcpy(&disassoc->fixed_parameters.reason_code, &reason_code, sizeof(reason_code)); |
49 | |||
50 | return 0; | ||
49 | } | 51 | } |
50 | 52 | ||
51 | /** | 53 | /** |
diff --git a/src/libwifi/gen/management/disassociation.h b/src/libwifi/gen/management/disassociation.h index fada9f0..10f1db9 100644 --- a/src/libwifi/gen/management/disassociation.h +++ b/src/libwifi/gen/management/disassociation.h | |||
@@ -40,7 +40,7 @@ size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc); | |||
40 | * @param reason_code The disassoc reason code | 40 | * @param reason_code The disassoc reason code |
41 | * | 41 | * |
42 | */ | 42 | */ |
43 | void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], | 43 | int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], |
44 | const unsigned char transmitter[6], uint16_t reason_code); | 44 | const unsigned char transmitter[6], uint16_t reason_code); |
45 | 45 | ||
46 | /** | 46 | /** |
diff --git a/src/libwifi/gen/management/probe_request.c b/src/libwifi/gen/management/probe_request.c index 7c5b99e..95cdcdb 100644 --- a/src/libwifi/gen/management/probe_request.c +++ b/src/libwifi/gen/management/probe_request.c | |||
@@ -31,7 +31,7 @@ size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req) { | |||
31 | * The generated probe request frame is made with sane defaults defined in common.h. | 31 | * The generated probe request frame is made with sane defaults defined in common.h. |
32 | * Two tagged parameters are also added to the beacon: SSID and Channel. | 32 | * Two tagged parameters are also added to the beacon: SSID and Channel. |
33 | */ | 33 | */ |
34 | void libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], | 34 | int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], |
35 | const unsigned char transmitter[6], const unsigned char bssid[6], | 35 | const unsigned char transmitter[6], const unsigned char bssid[6], |
36 | const char *ssid, uint8_t channel) { | 36 | const char *ssid, uint8_t channel) { |
37 | memset(probe_req, 0, sizeof(struct libwifi_probe_req)); | 37 | memset(probe_req, 0, sizeof(struct libwifi_probe_req)); |
@@ -43,8 +43,13 @@ void libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigne | |||
43 | memcpy(&probe_req->frame_header.addr3, bssid, 6); | 43 | memcpy(&probe_req->frame_header.addr3, bssid, 6); |
44 | probe_req->frame_header.seq_control.sequence_number = (rand() % 4096); | 44 | probe_req->frame_header.seq_control.sequence_number = (rand() % 4096); |
45 | 45 | ||
46 | libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); | 46 | int ret = libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); |
47 | libwifi_quick_add_tag(&probe_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | 47 | if (ret != 0) { |
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&probe_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | ||
52 | return ret; | ||
48 | } | 53 | } |
49 | 54 | ||
50 | /** | 55 | /** |
diff --git a/src/libwifi/gen/management/probe_request.h b/src/libwifi/gen/management/probe_request.h index f98b70a..c71897b 100644 --- a/src/libwifi/gen/management/probe_request.h +++ b/src/libwifi/gen/management/probe_request.h | |||
@@ -40,7 +40,7 @@ size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req); | |||
40 | * @param reason_code The probe_req reason code | 40 | * @param reason_code The probe_req reason code |
41 | * | 41 | * |
42 | */ | 42 | */ |
43 | void libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], | 43 | int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], |
44 | const unsigned char transmitter[6], const unsigned char bssid[6], | 44 | const unsigned char transmitter[6], const unsigned char bssid[6], |
45 | const char *ssid, uint8_t channel); | 45 | const char *ssid, uint8_t channel); |
46 | 46 | ||
diff --git a/src/libwifi/gen/management/probe_response.c b/src/libwifi/gen/management/probe_response.c index 403a8bc..1528313 100644 --- a/src/libwifi/gen/management/probe_response.c +++ b/src/libwifi/gen/management/probe_response.c | |||
@@ -39,32 +39,46 @@ size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp) { | |||
39 | /** | 39 | /** |
40 | * Simple helper to set the probe response SSID tag by removing it and then adding it back with the new value. | 40 | * Simple helper to set the probe response SSID tag by removing it and then adding it back with the new value. |
41 | */ | 41 | */ |
42 | void libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid) { | 42 | int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid) { |
43 | int ret = 0; | ||
44 | |||
43 | if (probe_resp->tags.length != 0) { | 45 | if (probe_resp->tags.length != 0) { |
44 | libwifi_remove_tag(&probe_resp->tags, TAG_SSID); | 46 | ret = libwifi_remove_tag(&probe_resp->tags, TAG_SSID); |
47 | if (ret != 0) { | ||
48 | return ret; | ||
49 | } | ||
45 | } | 50 | } |
46 | 51 | ||
47 | libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (void *) ssid, strlen(ssid)); | 52 | ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (void *) ssid, strlen(ssid)); |
53 | |||
54 | return ret; | ||
48 | } | 55 | } |
49 | 56 | ||
50 | /** | 57 | /** |
51 | * Simple helper to set the probe response DS tag by removing it and then adding it back with the new value. | 58 | * Simple helper to set the probe response DS tag by removing it and then adding it back with the new value. |
52 | */ | 59 | */ |
53 | void libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel) { | 60 | int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel) { |
61 | int ret = 0; | ||
62 | |||
54 | if (probe_resp->tags.length != 0) { | 63 | if (probe_resp->tags.length != 0) { |
55 | libwifi_remove_tag(&probe_resp->tags, TAG_DS_PARAMETER); | 64 | ret = libwifi_remove_tag(&probe_resp->tags, TAG_DS_PARAMETER); |
65 | if (ret != 0) { | ||
66 | return ret; | ||
67 | } | ||
56 | } | 68 | } |
57 | 69 | ||
58 | const unsigned char *chan = (const unsigned char *) &channel; | 70 | const unsigned char *chan = (const unsigned char *) &channel; |
59 | 71 | ||
60 | libwifi_quick_add_tag(&probe_resp->tags, TAG_DS_PARAMETER, chan, 1); | 72 | ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_DS_PARAMETER, chan, 1); |
73 | |||
74 | return ret; | ||
61 | } | 75 | } |
62 | 76 | ||
63 | /** | 77 | /** |
64 | * The generated probe response frame is made with sane defaults defined in common.h. | 78 | * The generated probe response frame is made with sane defaults defined in common.h. |
65 | * Three tagged parameters are also added to the probe response: SSID, Channel and Supported Rates. | 79 | * Three tagged parameters are also added to the probe response: SSID, Channel and Supported Rates. |
66 | */ | 80 | */ |
67 | void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], | 81 | int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], |
68 | const unsigned char transmitter[6], const char *ssid, uint8_t channel) { | 82 | const unsigned char transmitter[6], const char *ssid, uint8_t channel) { |
69 | memset(probe_resp, 0, sizeof(struct libwifi_probe_resp)); | 83 | memset(probe_resp, 0, sizeof(struct libwifi_probe_resp)); |
70 | 84 | ||
@@ -79,11 +93,20 @@ void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsi | |||
79 | probe_resp->fixed_parameters.probe_resp_interval = BYTESWAP16(probe_resp_interval); | 93 | probe_resp->fixed_parameters.probe_resp_interval = BYTESWAP16(probe_resp_interval); |
80 | probe_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); | 94 | probe_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); |
81 | 95 | ||
82 | libwifi_set_probe_resp_ssid(probe_resp, ssid); | 96 | int ret = libwifi_set_probe_resp_ssid(probe_resp, ssid); |
83 | libwifi_set_probe_resp_channel(probe_resp, channel); | 97 | if (ret != 0) { |
98 | return ret; | ||
99 | } | ||
100 | |||
101 | ret = libwifi_set_probe_resp_channel(probe_resp, channel); | ||
102 | if (ret != 0) { | ||
103 | return ret; | ||
104 | } | ||
84 | 105 | ||
85 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; | 106 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; |
86 | libwifi_quick_add_tag(&probe_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); | 107 | ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); |
108 | |||
109 | return ret; | ||
87 | } | 110 | } |
88 | 111 | ||
89 | /** | 112 | /** |
diff --git a/src/libwifi/gen/management/probe_response.h b/src/libwifi/gen/management/probe_response.h index 56243ee..80f5451 100644 --- a/src/libwifi/gen/management/probe_response.h +++ b/src/libwifi/gen/management/probe_response.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * @param probe_resp A libwifi_probe_resp | 24 | * @param probe_resp A libwifi_probe_resp |
25 | * @param ssid The new SSID | 25 | * @param ssid The new SSID |
26 | */ | 26 | */ |
27 | void libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid); | 27 | int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Set the channel of a libwifi_probe_resp. | 30 | * Set the channel of a libwifi_probe_resp. |
@@ -32,7 +32,7 @@ void libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const ch | |||
32 | * @param probe_resp A libwifi_probe_resp | 32 | * @param probe_resp A libwifi_probe_resp |
33 | * @param channel The new channel | 33 | * @param channel The new channel |
34 | */ | 34 | */ |
35 | void libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel); | 35 | int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Calculate the length of a given libwifi_probe_resp | 38 | * Calculate the length of a given libwifi_probe_resp |
@@ -55,7 +55,7 @@ size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp); | |||
55 | * @param channel The desired channel of the probe_resp | 55 | * @param channel The desired channel of the probe_resp |
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], | 58 | int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], |
59 | const unsigned char transmitter[6], const char *ssid, uint8_t channel); | 59 | const unsigned char transmitter[6], const char *ssid, uint8_t channel); |
60 | 60 | ||
61 | /** | 61 | /** |
diff --git a/src/libwifi/gen/management/reassoc_request.c b/src/libwifi/gen/management/reassoc_request.c index f678caf..9e9bcd8 100644 --- a/src/libwifi/gen/management/reassoc_request.c +++ b/src/libwifi/gen/management/reassoc_request.c | |||
@@ -49,10 +49,14 @@ int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req, const un | |||
49 | reassoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); | 49 | reassoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); |
50 | memcpy(&reassoc_req->fixed_parameters.current_ap_address, current_ap, 6); | 50 | memcpy(&reassoc_req->fixed_parameters.current_ap_address, current_ap, 6); |
51 | 51 | ||
52 | libwifi_quick_add_tag(&reassoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); | 52 | int ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); |
53 | libwifi_quick_add_tag(&reassoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | 53 | if (ret != 0) { |
54 | return ret; | ||
55 | } | ||
56 | |||
57 | ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); | ||
54 | 58 | ||
55 | return 0; | 59 | return ret; |
56 | } | 60 | } |
57 | 61 | ||
58 | /** | 62 | /** |
diff --git a/src/libwifi/gen/management/reassoc_response.c b/src/libwifi/gen/management/reassoc_response.c index b9acbb6..3279f52 100644 --- a/src/libwifi/gen/management/reassoc_response.c +++ b/src/libwifi/gen/management/reassoc_response.c | |||
@@ -41,21 +41,27 @@ size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp | |||
41 | * Simple helper to set the reassociation response DS tag by removing it and then adding it back with the new | 41 | * Simple helper to set the reassociation response DS tag by removing it and then adding it back with the new |
42 | * value. | 42 | * value. |
43 | */ | 43 | */ |
44 | void libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel) { | 44 | int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel) { |
45 | int ret = 0; | ||
46 | |||
45 | if (reassoc_resp->tags.length != 0) { | 47 | if (reassoc_resp->tags.length != 0) { |
46 | libwifi_remove_tag(&reassoc_resp->tags, TAG_DS_PARAMETER); | 48 | ret = libwifi_remove_tag(&reassoc_resp->tags, TAG_DS_PARAMETER); |
49 | if (ret != 0) { | ||
50 | return ret; | ||
51 | } | ||
47 | } | 52 | } |
48 | 53 | ||
49 | const unsigned char *chan = (const unsigned char *) &channel; | 54 | const unsigned char *chan = (const unsigned char *) &channel; |
55 | ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_DS_PARAMETER, chan, 1); | ||
50 | 56 | ||
51 | libwifi_quick_add_tag(&reassoc_resp->tags, TAG_DS_PARAMETER, chan, 1); | 57 | return ret; |
52 | } | 58 | } |
53 | 59 | ||
54 | /** | 60 | /** |
55 | * The generated reassoc_resp frame is made with sane defaults defined in common.h. | 61 | * The generated reassoc_resp frame is made with sane defaults defined in common.h. |
56 | * Three tagged parameters are also added to the reassoc_resp: SSID, Channel and Supported Rates. | 62 | * Three tagged parameters are also added to the reassoc_resp: SSID, Channel and Supported Rates. |
57 | */ | 63 | */ |
58 | void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], | 64 | int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], |
59 | const unsigned char transmitter[6], uint8_t channel) { | 65 | const unsigned char transmitter[6], uint8_t channel) { |
60 | memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp)); | 66 | memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp)); |
61 | 67 | ||
@@ -68,10 +74,15 @@ void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, cons | |||
68 | reassoc_resp->fixed_parameters.status_code = STATUS_SUCCESS; | 74 | reassoc_resp->fixed_parameters.status_code = STATUS_SUCCESS; |
69 | reassoc_resp->fixed_parameters.association_id = rand() % 4096; | 75 | reassoc_resp->fixed_parameters.association_id = rand() % 4096; |
70 | 76 | ||
71 | libwifi_set_reassoc_resp_channel(reassoc_resp, channel); | 77 | int ret = libwifi_set_reassoc_resp_channel(reassoc_resp, channel); |
78 | if (ret != 0) { | ||
79 | return ret; | ||
80 | } | ||
72 | 81 | ||
73 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; | 82 | const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; |
74 | libwifi_quick_add_tag(&reassoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); | 83 | ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); |
84 | |||
85 | return ret; | ||
75 | } | 86 | } |
76 | 87 | ||
77 | /** | 88 | /** |
diff --git a/src/libwifi/gen/management/reassoc_response.h b/src/libwifi/gen/management/reassoc_response.h index f0a2da2..420ed66 100644 --- a/src/libwifi/gen/management/reassoc_response.h +++ b/src/libwifi/gen/management/reassoc_response.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * @param reassoc_resp A libwifi_reassoc_resp | 24 | * @param reassoc_resp A libwifi_reassoc_resp |
25 | * @param channel The new channel | 25 | * @param channel The new channel |
26 | */ | 26 | */ |
27 | void libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); | 27 | int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Calculate the length of a given libwifi_reassoc_resp | 30 | * Calculate the length of a given libwifi_reassoc_resp |
@@ -46,7 +46,7 @@ size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp | |||
46 | * @param channel The desired channel of the reassoc_resp | 46 | * @param channel The desired channel of the reassoc_resp |
47 | * | 47 | * |
48 | */ | 48 | */ |
49 | void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], | 49 | int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], |
50 | const unsigned char transmitter[6], uint8_t channel); | 50 | const unsigned char transmitter[6], uint8_t channel); |
51 | 51 | ||
52 | /** | 52 | /** |
diff --git a/src/libwifi/gen/management/timing_ad.c b/src/libwifi/gen/management/timing_ad.c index 6e67a6b..61b9003 100644 --- a/src/libwifi/gen/management/timing_ad.c +++ b/src/libwifi/gen/management/timing_ad.c | |||
@@ -19,10 +19,11 @@ | |||
19 | #include "../../core/misc/epoch.h" | 19 | #include "../../core/misc/epoch.h" |
20 | #include "../../core/frame/tag.h" | 20 | #include "../../core/frame/tag.h" |
21 | 21 | ||
22 | #include <errno.h> | ||
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | #include <string.h> | 24 | #include <string.h> |
24 | 25 | ||
25 | void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], | 26 | int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], |
26 | const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, | 27 | const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, |
27 | const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, | 28 | const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, |
28 | uint8_t noise_floor) { | 29 | uint8_t noise_floor) { |
@@ -45,7 +46,7 @@ void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsig | |||
45 | adv->fixed_parameters.noise_floor = noise_floor; | 46 | adv->fixed_parameters.noise_floor = noise_floor; |
46 | 47 | ||
47 | if (adv_fields == NULL) { | 48 | if (adv_fields == NULL) { |
48 | return; | 49 | return -EINVAL; |
49 | } | 50 | } |
50 | 51 | ||
51 | // Maximum element size is 17 | 52 | // Maximum element size is 17 |
@@ -78,7 +79,9 @@ void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsig | |||
78 | 79 | ||
79 | element_data_len = offset; | 80 | element_data_len = offset; |
80 | 81 | ||
81 | libwifi_quick_add_tag(&adv->tags, TAG_TIME_ADVERTISEMENT, element_data, element_data_len); | 82 | int ret = libwifi_quick_add_tag(&adv->tags, TAG_TIME_ADVERTISEMENT, element_data, element_data_len); |
83 | |||
84 | return ret; | ||
82 | } | 85 | } |
83 | 86 | ||
84 | size_t libwifi_get_timing_advert_length(struct libwifi_timing_advert *adv) { | 87 | size_t libwifi_get_timing_advert_length(struct libwifi_timing_advert *adv) { |
diff --git a/src/libwifi/gen/management/timing_ad.h b/src/libwifi/gen/management/timing_ad.h index cdcb827..51c7729 100644 --- a/src/libwifi/gen/management/timing_ad.h +++ b/src/libwifi/gen/management/timing_ad.h | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include "../../core/frame/management/timing_ad.h" | 19 | #include "../../core/frame/management/timing_ad.h" |
20 | 20 | ||
21 | void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], | 21 | int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], |
22 | const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, | 22 | const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, |
23 | const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, | 23 | const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, |
24 | uint8_t noise_floor); | 24 | uint8_t noise_floor); |
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b418f93..32934a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt | |||
@@ -7,10 +7,69 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) | |||
7 | 7 | ||
8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") | 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") |
9 | 9 | ||
10 | add_executable(test_misc src/helpers.c src/test_misc.c) | 10 | link_directories("../build/") |
11 | add_executable(test_generation src/helpers.c src/test_generation.c) | ||
12 | add_executable(test_parsing src/helpers.c src/test_parsing.c) | ||
13 | 11 | ||
14 | target_link_libraries(test_misc wifi) | 12 | add_executable(action_tests src/action_tests.c) |
15 | target_link_libraries(test_generation wifi pcap) | 13 | target_link_libraries(action_tests wifi) |
16 | target_link_libraries(test_parsing wifi pcap) | 14 | add_executable(assoc_req_tests src/assoc_req_tests.c) |
15 | target_link_libraries(assoc_req_tests wifi) | ||
16 | add_executable(assoc_resp_tests src/assoc_resp_tests.c) | ||
17 | target_link_libraries(assoc_resp_tests wifi) | ||
18 | add_executable(atim_tests src/atim_tests.c) | ||
19 | target_link_libraries(atim_tests wifi) | ||
20 | add_executable(auth_tests src/auth_tests.c) | ||
21 | target_link_libraries(auth_tests wifi) | ||
22 | add_executable(beacon_tests src/beacon_tests.c) | ||
23 | target_link_libraries(beacon_tests wifi) | ||
24 | add_executable(deauth_tests src/deauth_tests.c) | ||
25 | target_link_libraries(deauth_tests wifi) | ||
26 | add_executable(disassoc_tests src/disassoc_tests.c) | ||
27 | target_link_libraries(disassoc_tests wifi) | ||
28 | add_executable(probe_req_tests src/probe_req_tests.c) | ||
29 | target_link_libraries(probe_req_tests wifi) | ||
30 | add_executable(probe_resp_tests src/probe_resp_tests.c) | ||
31 | target_link_libraries(probe_resp_tests wifi) | ||
32 | add_executable(reassoc_req_tests src/reassoc_req_tests.c) | ||
33 | target_link_libraries(reassoc_req_tests wifi) | ||
34 | add_executable(reassoc_resp_tests src/reassoc_resp_tests.c) | ||
35 | target_link_libraries(reassoc_resp_tests wifi) | ||
36 | add_executable(timing_ad_tests src/timing_ad_tests.c) | ||
37 | target_link_libraries(timing_ad_tests wifi) | ||
38 | |||
39 | enable_testing() | ||
40 | add_test(NAME test_action_gen_full COMMAND action_tests --action-gen-full) | ||
41 | add_test(NAME test_action_gen_details COMMAND action_tests --action-gen-details) | ||
42 | |||
43 | add_test(NAME test_assoc_req_gen_full COMMAND assoc_req_tests --assoc_req-gen-full) | ||
44 | add_test(NAME test_assoc_req_gen_tags COMMAND assoc_req_tests --assoc_req-gen-tags) | ||
45 | |||
46 | add_test(NAME test_assoc_resp_gen_full COMMAND assoc_resp_tests --assoc_resp-gen-full) | ||
47 | add_test(NAME test_assoc_resp_gen_tags COMMAND assoc_resp_tests --assoc_resp-gen-tags) | ||
48 | |||
49 | add_test(NAME test_atim_gen_full COMMAND atim_tests --atim-gen-full) | ||
50 | |||
51 | add_test(NAME test_auth_gen_full COMMAND auth_tests --auth-gen-full) | ||
52 | add_test(NAME test_auth_gen_tags COMMAND auth_tests --auth-gen-tags) | ||
53 | |||
54 | add_test(NAME test_beacon_gen_full COMMAND beacon_tests --beacon-gen-full) | ||
55 | add_test(NAME test_beacon_gen_tags COMMAND beacon_tests --beacon-gen-tags) | ||
56 | |||
57 | add_test(NAME test_deauth_gen_full COMMAND deauth_tests --deauth-gen-full) | ||
58 | add_test(NAME test_deauth_gen_tags COMMAND deauth_tests --deauth-gen-tags) | ||
59 | |||
60 | add_test(NAME test_disassoc_gen_full COMMAND disassoc_tests --disassoc-gen-full) | ||
61 | add_test(NAME test_disassoc_gen_tags COMMAND disassoc_tests --disassoc-gen-tags) | ||
62 | |||
63 | add_test(NAME test_probe_req_gen_full COMMAND probe_req_tests --probe_req-gen-full) | ||
64 | add_test(NAME test_probe_req_gen_tags COMMAND probe_req_tests --probe_req-gen-tags) | ||
65 | |||
66 | add_test(NAME test_probe_resp_gen_full COMMAND probe_resp_tests --probe_resp-gen-full) | ||
67 | add_test(NAME test_probe_resp_gen_tags COMMAND probe_resp_tests --probe_resp-gen-tags) | ||
68 | |||
69 | add_test(NAME test_reassoc_req_gen_full COMMAND reassoc_req_tests --reassoc_req-gen-full) | ||
70 | add_test(NAME test_reassoc_req_gen_tags COMMAND reassoc_req_tests --reassoc_req-gen-tags) | ||
71 | |||
72 | add_test(NAME test_reassoc_resp_gen_full COMMAND reassoc_resp_tests --reassoc_resp-gen-full) | ||
73 | add_test(NAME test_reassoc_resp_gen_tags COMMAND reassoc_resp_tests --reassoc_resp-gen-tags) | ||
74 | |||
75 | add_test(NAME test_timing_ad_gen_tags COMMAND timing_ad_tests --timing_ad-gen-full) | ||
diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..402fa87 --- /dev/null +++ b/test/README.md | |||
@@ -0,0 +1,69 @@ | |||
1 | # libwifi Tests | ||
2 | libwifi uses CMakes testing functionalities. The tests are in the `src/` directory, and can be used with `make test`. | ||
3 | |||
4 | ## Running Tests | ||
5 | ``` | ||
6 | >> mkdir build | ||
7 | >> cd build | ||
8 | >> cmake .. | ||
9 | >> make && make test | ||
10 | ``` | ||
11 | |||
12 | ## Expected Output | ||
13 | ``` | ||
14 | >> make test | ||
15 | Running tests... | ||
16 | Test project libwifi/test/build | ||
17 | Start 1: test_action_gen_full | ||
18 | 1/24 Test #1: test_action_gen_full ............. Passed 0.00 sec | ||
19 | Start 2: test_action_gen_details | ||
20 | 2/24 Test #2: test_action_gen_details .......... Passed 0.00 sec | ||
21 | Start 3: test_assoc_req_gen_full | ||
22 | 3/24 Test #3: test_assoc_req_gen_full .......... Passed 0.00 sec | ||
23 | Start 4: test_assoc_req_gen_tags | ||
24 | 4/24 Test #4: test_assoc_req_gen_tags .......... Passed 0.00 sec | ||
25 | Start 5: test_assoc_resp_gen_full | ||
26 | 5/24 Test #5: test_assoc_resp_gen_full ......... Passed 0.00 sec | ||
27 | Start 6: test_assoc_resp_gen_tags | ||
28 | 6/24 Test #6: test_assoc_resp_gen_tags ......... Passed 0.00 sec | ||
29 | Start 7: test_atim_gen_full | ||
30 | 7/24 Test #7: test_atim_gen_full ............... Passed 0.00 sec | ||
31 | Start 8: test_auth_gen_full | ||
32 | 8/24 Test #8: test_auth_gen_full ............... Passed 0.00 sec | ||
33 | Start 9: test_auth_gen_tags | ||
34 | 9/24 Test #9: test_auth_gen_tags ............... Passed 0.00 sec | ||
35 | Start 10: test_beacon_gen_full | ||
36 | 10/24 Test #10: test_beacon_gen_full ............. Passed 0.00 sec | ||
37 | Start 11: test_beacon_gen_tags | ||
38 | 11/24 Test #11: test_beacon_gen_tags ............. Passed 0.00 sec | ||
39 | Start 12: test_deauth_gen_full | ||
40 | 12/24 Test #12: test_deauth_gen_full ............. Passed 0.00 sec | ||
41 | Start 13: test_deauth_gen_tags | ||
42 | 13/24 Test #13: test_deauth_gen_tags ............. Passed 0.00 sec | ||
43 | Start 14: test_disassoc_gen_full | ||
44 | 14/24 Test #14: test_disassoc_gen_full ........... Passed 0.00 sec | ||
45 | Start 15: test_disassoc_gen_tags | ||
46 | 15/24 Test #15: test_disassoc_gen_tags ........... Passed 0.00 sec | ||
47 | Start 16: test_probe_req_gen_full | ||
48 | 16/24 Test #16: test_probe_req_gen_full .......... Passed 0.00 sec | ||
49 | Start 17: test_probe_req_gen_tags | ||
50 | 17/24 Test #17: test_probe_req_gen_tags .......... Passed 0.00 sec | ||
51 | Start 18: test_probe_resp_gen_full | ||
52 | 18/24 Test #18: test_probe_resp_gen_full ......... Passed 0.00 sec | ||
53 | Start 19: test_probe_resp_gen_tags | ||
54 | 19/24 Test #19: test_probe_resp_gen_tags ......... Passed 0.00 sec | ||
55 | Start 20: test_reassoc_req_gen_full | ||
56 | 20/24 Test #20: test_reassoc_req_gen_full ........ Passed 0.00 sec | ||
57 | Start 21: test_reassoc_req_gen_tags | ||
58 | 21/24 Test #21: test_reassoc_req_gen_tags ........ Passed 0.00 sec | ||
59 | Start 22: test_reassoc_resp_gen_full | ||
60 | 22/24 Test #22: test_reassoc_resp_gen_full ....... Passed 0.00 sec | ||
61 | Start 23: test_reassoc_resp_gen_tags | ||
62 | 23/24 Test #23: test_reassoc_resp_gen_tags ....... Passed 0.00 sec | ||
63 | Start 24: test_timing_ad_gen_tags | ||
64 | 24/24 Test #24: test_timing_ad_gen_tags .......... Passed 0.00 sec | ||
65 | |||
66 | 100% tests passed, 0 tests failed out of 24 | ||
67 | |||
68 | Total Test time (real) = 0.06 sec | ||
69 | ``` | ||
diff --git a/test/src/action_tests.c b/test/src/action_tests.c new file mode 100644 index 0000000..997095d --- /dev/null +++ b/test/src/action_tests.c | |||
@@ -0,0 +1,87 @@ | |||
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_action_gen_full() { | ||
13 | struct libwifi_action action = {0}; | ||
14 | |||
15 | int ret = libwifi_create_action(&action, bcast, to, ACTION_HT); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int action_len = libwifi_get_action_length(&action); | ||
22 | if (action_len <= 0) { | ||
23 | fprintf(stderr, "Invalid action length: %d\n", action_len); | ||
24 | return action_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(action_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_action(&action, buf, action_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump action\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_action_add_detail() { | ||
43 | struct libwifi_action action = {0}; | ||
44 | |||
45 | int ret = libwifi_create_action(&action, bcast, to, ACTION_HT); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_add_action_detail(&action.fixed_parameters.details, (const unsigned char *) "HELLO WORLD", strlen("HELLO WORLD")); | ||
52 | |||
53 | int action_len = libwifi_get_action_length(&action); | ||
54 | if (action_len <= 0) { | ||
55 | fprintf(stderr, "Invalid action length: %d\n", action_len); | ||
56 | return action_len; | ||
57 | } | ||
58 | |||
59 | unsigned char *buf = malloc(action_len); | ||
60 | if (buf == NULL) { | ||
61 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
62 | return -1; | ||
63 | } | ||
64 | |||
65 | int dump_len = libwifi_dump_action(&action, buf, action_len); | ||
66 | if (dump_len <= 0) { | ||
67 | fprintf(stderr, "Failed to dump action\n"); | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | int main(int argc, char **argv) { | ||
75 | if (argc < 2) { | ||
76 | printf("Specify test\n"); | ||
77 | return -1; | ||
78 | } | ||
79 | |||
80 | if (strcmp(argv[1], "--action-gen-full") == 0) { | ||
81 | return test_action_gen_full(); | ||
82 | } else if (strcmp(argv[1], "--action-gen-details") == 0) { | ||
83 | return test_action_add_detail(); | ||
84 | } | ||
85 | |||
86 | return -1; | ||
87 | } | ||
diff --git a/test/src/assoc_req_tests.c b/test/src/assoc_req_tests.c new file mode 100644 index 0000000..fc6379f --- /dev/null +++ b/test/src/assoc_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" | ||
9 | const unsigned char to[] = TO_MAC; | ||
10 | const unsigned char bcast[] = BCAST_MAC; | ||
11 | |||
12 | int test_assoc_req_gen_full() { | ||
13 | struct libwifi_assoc_req assoc_req = {0}; | ||
14 | |||
15 | int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, "Some SSID", 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req); | ||
22 | if (assoc_req_len <= 0) { | ||
23 | fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len); | ||
24 | return assoc_req_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(assoc_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_assoc_req(&assoc_req, buf, assoc_req_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump assoc_req\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_assoc_req_add_tag() { | ||
43 | struct libwifi_assoc_req assoc_req = {0}; | ||
44 | |||
45 | int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, "Some SSID", 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&assoc_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add assoc_req tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req); | ||
58 | if (assoc_req_len <= 0) { | ||
59 | fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len); | ||
60 | return assoc_req_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(assoc_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_assoc_req(&assoc_req, buf, assoc_req_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump assoc_req\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], "--assoc_req-gen-full") == 0) { | ||
85 | return test_assoc_req_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--assoc_req-gen-tags") == 0) { | ||
87 | return test_assoc_req_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/assoc_resp_tests.c b/test/src/assoc_resp_tests.c new file mode 100644 index 0000000..3a261ed --- /dev/null +++ b/test/src/assoc_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_assoc_resp_gen_full() { | ||
13 | struct libwifi_assoc_resp assoc_resp = {0}; | ||
14 | |||
15 | int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp); | ||
22 | if (assoc_resp_len <= 0) { | ||
23 | fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len); | ||
24 | return assoc_resp_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(assoc_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_assoc_resp(&assoc_resp, buf, assoc_resp_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump assoc_resp\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_assoc_resp_add_tag() { | ||
43 | struct libwifi_assoc_resp assoc_resp = {0}; | ||
44 | |||
45 | int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&assoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add assoc_resp tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp); | ||
58 | if (assoc_resp_len <= 0) { | ||
59 | fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len); | ||
60 | return assoc_resp_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(assoc_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_assoc_resp(&assoc_resp, buf, assoc_resp_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump assoc_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], "--assoc_resp-gen-full") == 0) { | ||
85 | return test_assoc_resp_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--assoc_resp-gen-tags") == 0) { | ||
87 | return test_assoc_resp_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/atim_tests.c b/test/src/atim_tests.c new file mode 100644 index 0000000..43f2265 --- /dev/null +++ b/test/src/atim_tests.c | |||
@@ -0,0 +1,35 @@ | |||
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_atim_gen_full() { | ||
13 | struct libwifi_atim atim = {0}; | ||
14 | |||
15 | int ret = libwifi_create_atim(&atim, bcast, to, to); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create atim: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | int main(int argc, char **argv) { | ||
25 | if (argc < 2) { | ||
26 | printf("Specify test\n"); | ||
27 | return -1; | ||
28 | } | ||
29 | |||
30 | if (strcmp(argv[1], "--atim-gen-full") == 0) { | ||
31 | return test_atim_gen_full(); | ||
32 | } | ||
33 | |||
34 | return -1; | ||
35 | } | ||
diff --git a/test/src/auth_tests.c b/test/src/auth_tests.c new file mode 100644 index 0000000..f78aeed --- /dev/null +++ b/test/src/auth_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_auth_gen_full() { | ||
13 | struct libwifi_auth auth = {0}; | ||
14 | |||
15 | int ret = libwifi_create_auth(&auth, bcast, to, 0, 100, STATUS_SUCCESS); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create auth: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int auth_len = libwifi_get_auth_length(&auth); | ||
22 | if (auth_len <= 0) { | ||
23 | fprintf(stderr, "Invalid auth length: %d\n", auth_len); | ||
24 | return auth_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(auth_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_auth(&auth, buf, auth_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump auth\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_auth_add_tag() { | ||
43 | struct libwifi_auth auth = {0}; | ||
44 | |||
45 | int ret = libwifi_create_auth(&auth, bcast, to, 0, 100, STATUS_SUCCESS); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create auth: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&auth.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add auth tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int auth_len = libwifi_get_auth_length(&auth); | ||
58 | if (auth_len <= 0) { | ||
59 | fprintf(stderr, "Invalid auth length: %d\n", auth_len); | ||
60 | return auth_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(auth_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_auth(&auth, buf, auth_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump auth\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], "--auth-gen-full") == 0) { | ||
85 | return test_auth_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--auth-gen-tags") == 0) { | ||
87 | return test_auth_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/beacon_tests.c b/test/src/beacon_tests.c new file mode 100644 index 0000000..1c4e17e --- /dev/null +++ b/test/src/beacon_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_beacon_gen_full() { | ||
13 | struct libwifi_beacon beacon = {0}; | ||
14 | |||
15 | int ret = libwifi_create_beacon(&beacon, bcast, to, "Some SSID", 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create beacon: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int beacon_len = libwifi_get_beacon_length(&beacon); | ||
22 | if (beacon_len <= 0) { | ||
23 | fprintf(stderr, "Invalid beacon length: %d\n", beacon_len); | ||
24 | return beacon_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(beacon_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_beacon(&beacon, buf, beacon_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump beacon\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_beacon_add_tag() { | ||
43 | struct libwifi_beacon beacon = {0}; | ||
44 | |||
45 | int ret = libwifi_create_beacon(&beacon, bcast, to, "Some SSID", 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create beacon: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add beacon tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int beacon_len = libwifi_get_beacon_length(&beacon); | ||
58 | if (beacon_len <= 0) { | ||
59 | fprintf(stderr, "Invalid beacon length: %d\n", beacon_len); | ||
60 | return beacon_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(beacon_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_beacon(&beacon, buf, beacon_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump beacon\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], "--beacon-gen-full") == 0) { | ||
85 | return test_beacon_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--beacon-gen-tags") == 0) { | ||
87 | return test_beacon_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/deauth_tests.c b/test/src/deauth_tests.c new file mode 100644 index 0000000..9033574 --- /dev/null +++ b/test/src/deauth_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_deauth_gen_full() { | ||
13 | struct libwifi_deauth deauth = {0}; | ||
14 | |||
15 | int ret = libwifi_create_deauth(&deauth, bcast, to, REASON_STA_LEAVING); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create deauth: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int deauth_len = libwifi_get_deauth_length(&deauth); | ||
22 | if (deauth_len <= 0) { | ||
23 | fprintf(stderr, "Invalid deauth length: %d\n", deauth_len); | ||
24 | return deauth_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(deauth_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_deauth(&deauth, buf, deauth_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump deauth\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_deauth_add_tag() { | ||
43 | struct libwifi_deauth deauth = {0}; | ||
44 | |||
45 | int ret = libwifi_create_deauth(&deauth, bcast, to, REASON_STA_LEAVING); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create deauth: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&deauth.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add deauth tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int deauth_len = libwifi_get_deauth_length(&deauth); | ||
58 | if (deauth_len <= 0) { | ||
59 | fprintf(stderr, "Invalid deauth length: %d\n", deauth_len); | ||
60 | return deauth_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(deauth_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_deauth(&deauth, buf, deauth_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump deauth\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], "--deauth-gen-full") == 0) { | ||
85 | return test_deauth_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--deauth-gen-tags") == 0) { | ||
87 | return test_deauth_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/disassoc_tests.c b/test/src/disassoc_tests.c new file mode 100644 index 0000000..c5e27de --- /dev/null +++ b/test/src/disassoc_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_disassoc_gen_full() { | ||
13 | struct libwifi_disassoc disassoc = {0}; | ||
14 | |||
15 | int ret = libwifi_create_disassoc(&disassoc, bcast, to, REASON_STA_LEAVING); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create disassoc: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int disassoc_len = libwifi_get_disassoc_length(&disassoc); | ||
22 | if (disassoc_len <= 0) { | ||
23 | fprintf(stderr, "Invalid disassoc length: %d\n", disassoc_len); | ||
24 | return disassoc_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(disassoc_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_disassoc(&disassoc, buf, disassoc_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump disassoc\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_disassoc_add_tag() { | ||
43 | struct libwifi_disassoc disassoc = {0}; | ||
44 | |||
45 | int ret = libwifi_create_disassoc(&disassoc, bcast, to, REASON_STA_LEAVING); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create disassoc: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&disassoc.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add disassoc tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int disassoc_len = libwifi_get_disassoc_length(&disassoc); | ||
58 | if (disassoc_len <= 0) { | ||
59 | fprintf(stderr, "Invalid disassoc length: %d\n", disassoc_len); | ||
60 | return disassoc_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(disassoc_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_disassoc(&disassoc, buf, disassoc_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump disassoc\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], "--disassoc-gen-full") == 0) { | ||
85 | return test_disassoc_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--disassoc-gen-tags") == 0) { | ||
87 | return test_disassoc_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
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" | ||
9 | const unsigned char to[] = TO_MAC; | ||
10 | const unsigned char bcast[] = BCAST_MAC; | ||
11 | |||
12 | int 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 | |||
42 | int 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 | |||
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_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 | } | ||
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 | } | ||
diff --git a/test/src/reassoc_req_tests.c b/test/src/reassoc_req_tests.c new file mode 100644 index 0000000..00e2b53 --- /dev/null +++ b/test/src/reassoc_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" | ||
9 | const unsigned char to[] = TO_MAC; | ||
10 | const unsigned char bcast[] = BCAST_MAC; | ||
11 | |||
12 | int test_reassoc_req_gen_full() { | ||
13 | struct libwifi_reassoc_req reassoc_req = {0}; | ||
14 | |||
15 | int ret = libwifi_create_reassoc_req(&reassoc_req, bcast, to, to, "Some SSID", 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create reassoc_req: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int reassoc_req_len = libwifi_get_reassoc_req_length(&reassoc_req); | ||
22 | if (reassoc_req_len <= 0) { | ||
23 | fprintf(stderr, "Invalid reassoc_req length: %d\n", reassoc_req_len); | ||
24 | return reassoc_req_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(reassoc_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_reassoc_req(&reassoc_req, buf, reassoc_req_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump reassoc_req\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_reassoc_req_add_tag() { | ||
43 | struct libwifi_reassoc_req reassoc_req = {0}; | ||
44 | |||
45 | int ret = libwifi_create_reassoc_req(&reassoc_req, bcast, to, to, "Some SSID", 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create reassoc_req: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&reassoc_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add reassoc_req tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int reassoc_req_len = libwifi_get_reassoc_req_length(&reassoc_req); | ||
58 | if (reassoc_req_len <= 0) { | ||
59 | fprintf(stderr, "Invalid reassoc_req length: %d\n", reassoc_req_len); | ||
60 | return reassoc_req_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(reassoc_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_reassoc_req(&reassoc_req, buf, reassoc_req_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump reassoc_req\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], "--reassoc_req-gen-full") == 0) { | ||
85 | return test_reassoc_req_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--reassoc_req-gen-tags") == 0) { | ||
87 | return test_reassoc_req_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/reassoc_resp_tests.c b/test/src/reassoc_resp_tests.c new file mode 100644 index 0000000..8167916 --- /dev/null +++ b/test/src/reassoc_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_reassoc_resp_gen_full() { | ||
13 | struct libwifi_reassoc_resp reassoc_resp = {0}; | ||
14 | |||
15 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); | ||
22 | if (reassoc_resp_len <= 0) { | ||
23 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); | ||
24 | return reassoc_resp_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(reassoc_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_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump reassoc_resp\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_reassoc_resp_add_tag() { | ||
43 | struct libwifi_reassoc_resp reassoc_resp = {0}; | ||
44 | |||
45 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&reassoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add reassoc_resp tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); | ||
58 | if (reassoc_resp_len <= 0) { | ||
59 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); | ||
60 | return reassoc_resp_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(reassoc_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_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump reassoc_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], "--reassoc_resp-gen-full") == 0) { | ||
85 | return test_reassoc_resp_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--reassoc_resp-gen-tags") == 0) { | ||
87 | return test_reassoc_resp_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||
diff --git a/test/src/timing_ad_tests.c b/test/src/timing_ad_tests.c new file mode 100644 index 0000000..59d20eb --- /dev/null +++ b/test/src/timing_ad_tests.c | |||
@@ -0,0 +1,57 @@ | |||
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_timing_ad_gen_full() { | ||
13 | struct libwifi_timing_advert time_ad = {0}; | ||
14 | struct libwifi_timing_advert_fields ad_fields = {0}; | ||
15 | |||
16 | ad_fields.timing_capabilities = 2; | ||
17 | memcpy(ad_fields.time_error, "\xCC\xCC\xCC\xCC\xCC", 5); | ||
18 | memcpy(ad_fields.time_update, "\xBB", 1); | ||
19 | memcpy(ad_fields.time_value, | ||
20 | "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA", 10); | ||
21 | |||
22 | int ret = libwifi_create_timing_advert(&time_ad, to, to, &ad_fields, "GB", -56, -56, -30, -20); | ||
23 | if (ret != 0) { | ||
24 | fprintf(stderr, "Failed to create timing advert\n"); | ||
25 | return ret; | ||
26 | } | ||
27 | |||
28 | unsigned char *buf = NULL; | ||
29 | size_t buf_len = libwifi_get_timing_advert_length(&time_ad); | ||
30 | buf = malloc(buf_len); | ||
31 | if (buf == NULL) { | ||
32 | fprintf(stderr, "Failed to create buffer\n"); | ||
33 | return -1; | ||
34 | } | ||
35 | printf("buf_len: %zu\n", buf_len); | ||
36 | |||
37 | ret = libwifi_dump_timing_advert(&time_ad, buf, buf_len); | ||
38 | if (ret < 0) { | ||
39 | fprintf(stderr, "Failed to dump advert"); | ||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | int main(int argc, char **argv) { | ||
47 | if (argc < 2) { | ||
48 | printf("Specify test\n"); | ||
49 | return -1; | ||
50 | } | ||
51 | |||
52 | if (strcmp(argv[1], "--timing_ad-gen-full") == 0) { | ||
53 | return test_timing_ad_gen_full(); | ||
54 | } | ||
55 | |||
56 | return -1; | ||
57 | } | ||
diff --git a/test/src/.clang-format b/utils/.clang-format index 111249f..111249f 100644 --- a/test/src/.clang-format +++ b/utils/.clang-format | |||
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 0000000..bdf7227 --- /dev/null +++ b/utils/CMakeLists.txt | |||
@@ -0,0 +1,15 @@ | |||
1 | cmake_minimum_required(VERSION 3.18) | ||
2 | |||
3 | project(libwifi_tests VERSION 0.1) | ||
4 | |||
5 | set(CMAKE_CXX_STANDARD 11) | ||
6 | set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
7 | |||
8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") | ||
9 | |||
10 | add_executable(test_misc src/helpers.c src/test_misc.c) | ||
11 | add_executable(test_generation src/helpers.c src/test_generation.c) | ||
12 | add_executable(test_parsing src/helpers.c src/test_parsing.c) | ||
13 | target_link_libraries(test_misc wifi) | ||
14 | target_link_libraries(test_generation wifi pcap) | ||
15 | target_link_libraries(test_parsing wifi pcap) | ||
diff --git a/test/src/helpers.c b/utils/src/helpers.c index 9fc9d0b..9fc9d0b 100644 --- a/test/src/helpers.c +++ b/utils/src/helpers.c | |||
diff --git a/test/src/helpers.h b/utils/src/helpers.h index 99a5329..99a5329 100644 --- a/test/src/helpers.h +++ b/utils/src/helpers.h | |||
diff --git a/test/src/test_generation.c b/utils/src/test_generation.c index 407e87f..407e87f 100644 --- a/test/src/test_generation.c +++ b/utils/src/test_generation.c | |||
diff --git a/test/src/test_misc.c b/utils/src/test_misc.c index f103455..f103455 100644 --- a/test/src/test_misc.c +++ b/utils/src/test_misc.c | |||
diff --git a/test/src/test_parsing.c b/utils/src/test_parsing.c index c345346..c345346 100644 --- a/test/src/test_parsing.c +++ b/utils/src/test_parsing.c | |||