From cd1df65dc36ac35d526de195284d5ebf18e1f92b Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 17 Dec 2021 18:52:36 +0000 Subject: test: Add ctests for generation functions. This commit also enforces error code checking on functions inside of the generation functions, such as for `libwifi_quick_add_tag`. --- src/libwifi/gen/management/assoc_request.c | 11 +++++-- src/libwifi/gen/management/assoc_response.c | 19 ++++++++---- src/libwifi/gen/management/assoc_response.h | 4 +-- src/libwifi/gen/management/authentication.c | 4 ++- src/libwifi/gen/management/authentication.h | 2 +- src/libwifi/gen/management/beacon.c | 32 +++++++++++++++----- src/libwifi/gen/management/beacon.h | 6 ++-- src/libwifi/gen/management/disassociation.c | 4 ++- src/libwifi/gen/management/disassociation.h | 2 +- src/libwifi/gen/management/probe_request.c | 11 +++++-- src/libwifi/gen/management/probe_request.h | 2 +- src/libwifi/gen/management/probe_response.c | 43 ++++++++++++++++++++------- src/libwifi/gen/management/probe_response.h | 6 ++-- src/libwifi/gen/management/reassoc_request.c | 10 +++++-- src/libwifi/gen/management/reassoc_response.c | 23 ++++++++++---- src/libwifi/gen/management/reassoc_response.h | 4 +-- src/libwifi/gen/management/timing_ad.c | 9 ++++-- src/libwifi/gen/management/timing_ad.h | 2 +- 18 files changed, 138 insertions(+), 56 deletions(-) (limited to 'src') 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 assoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); assoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); - libwifi_quick_add_tag(&assoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); - libwifi_quick_add_tag(&assoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); + int ret = libwifi_quick_add_tag(&assoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); + if (ret != 0) { + return ret; + } + + ret = libwifi_quick_add_tag(&assoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); + if (ret != 0) { + return ret; + } return 0; } 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) { * Simple helper function to set the channel of an association response by removing and re-adding the * DS tagged parameter. */ -void libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel) { +int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel) { + int ret = 0; + if (assoc_resp->tags.length != 0) { - libwifi_remove_tag(&assoc_resp->tags, TAG_DS_PARAMETER); + ret = libwifi_remove_tag(&assoc_resp->tags, TAG_DS_PARAMETER); + if (ret != 0) { + return ret; + } } const unsigned char *chan = (const unsigned char *) &channel; - libwifi_quick_add_tag(&assoc_resp->tags, TAG_DS_PARAMETER, chan, 1); + ret = libwifi_quick_add_tag(&assoc_resp->tags, TAG_DS_PARAMETER, chan, 1); + + return ret; } /** * The generated association response frame is made with sane defaults defined in common.h and core/types.h. * Two tagged parameters are also added to the association response: Channel and Supported Rates. */ -void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], +int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], const unsigned char transmitter[6], uint8_t channel) { memset(assoc_resp, 0, sizeof(struct libwifi_assoc_resp)); @@ -71,7 +78,9 @@ void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsi libwifi_set_assoc_resp_channel(assoc_resp, channel); const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; - libwifi_quick_add_tag(&assoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + int ret = libwifi_quick_add_tag(&assoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + + return ret; } /** 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 @@ * @param assoc_resp A libwifi_assoc_resp * @param channel The new channel */ -void libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); +int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); /** * 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); * @param channel The desired channel of the assoc_resp * */ -void libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], +int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], const unsigned char transmitter[6], uint8_t channel); /** 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) { /** * The generated authentication frame is made with sane defaults defined in common.h. */ -void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], +int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], const unsigned char transmitter[6], uint16_t algorithm_number, uint16_t transaction_sequence, uint16_t status_code) { memset(auth, 0, sizeof(struct libwifi_auth)); @@ -47,6 +47,8 @@ void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver auth->fixed_parameters.algorithm_number = algorithm_number; auth->fixed_parameters.transaction_sequence = transaction_sequence; auth->fixed_parameters.status_code = status_code; + + return 0; } /** 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); * @param algorithm_number Algorithm type to use * */ -void libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], +int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], const unsigned char transmitter[6], uint16_t algorithm_number, uint16_t transaction_sequence, uint16_t status_code); 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) { /** * Simple helper to set the beacon SSID tag by removing it and then adding it back with the new value. */ -void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid) { +int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid) { + int ret = 0; + if (beacon->tags.length != 0) { - libwifi_remove_tag(&beacon->tags, TAG_SSID); + ret = libwifi_remove_tag(&beacon->tags, TAG_SSID); + if (ret != 0) { + return ret; + } } - libwifi_quick_add_tag(&beacon->tags, TAG_SSID, (void *) ssid, strlen(ssid)); + ret = libwifi_quick_add_tag(&beacon->tags, TAG_SSID, (void *) ssid, strlen(ssid)); + + return ret; } /** * Simple helper to set the beacon DS tag by removing it and then adding it back with the new value. */ -void libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) { +int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) { + int ret = 0; + if (beacon->tags.length != 0) { - libwifi_remove_tag(&beacon->tags, TAG_DS_PARAMETER); + ret = libwifi_remove_tag(&beacon->tags, TAG_DS_PARAMETER); + if (ret != 0) { + return ret; + } } const unsigned char *chan = (const unsigned char *) &channel; - libwifi_quick_add_tag(&beacon->tags, TAG_DS_PARAMETER, chan, 1); + ret = libwifi_quick_add_tag(&beacon->tags, TAG_DS_PARAMETER, chan, 1); + + return ret; } /** * The generated beacon frame is made with sane defaults defined in common.h. * Three tagged parameters are also added to the beacon: SSID, Channel and Supported Rates. */ -void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], +int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], const unsigned char transmitter[6], const char *ssid, uint8_t channel) { memset(beacon, 0, sizeof(struct libwifi_beacon)); @@ -82,7 +96,9 @@ void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char re libwifi_set_beacon_channel(beacon, channel); const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; - libwifi_quick_add_tag(&beacon->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + int ret = libwifi_quick_add_tag(&beacon->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + + return ret; } /** 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 @@ * @param beacon A struct libwifi_beacon * @param ssid The new SSID */ -void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); +int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); /** * Set the channel of a struct libwifi_beacon. @@ -32,7 +32,7 @@ void libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); * @param beacon A struct libwifi_beacon * @param channel The new channel */ -void libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel); +int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel); /** * Calculate the length of a given struct libwifi_beacon @@ -55,7 +55,7 @@ size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon); * @param channel The desired channel of the beacon * */ -void libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], +int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], const unsigned char transmitter[6], const char *ssid, uint8_t channel); /** 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) { * The generated disassociation frame contains only the supplied receiver, transmitter and reason_code by * default. */ -void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], +int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], const unsigned char transmitter[6], uint16_t reason_code) { memset(disassoc, 0, sizeof(struct libwifi_disassoc)); @@ -46,6 +46,8 @@ void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned c disassoc->frame_header.seq_control.sequence_number = (rand() % 4096); memcpy(&disassoc->fixed_parameters.reason_code, &reason_code, sizeof(reason_code)); + + return 0; } /** 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); * @param reason_code The disassoc reason code * */ -void libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], +int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], const unsigned char transmitter[6], uint16_t reason_code); /** 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) { * The generated probe request frame is made with sane defaults defined in common.h. * Two tagged parameters are also added to the beacon: SSID and Channel. */ -void libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], +int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], const unsigned char transmitter[6], const unsigned char bssid[6], const char *ssid, uint8_t channel) { 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 memcpy(&probe_req->frame_header.addr3, bssid, 6); probe_req->frame_header.seq_control.sequence_number = (rand() % 4096); - libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); - libwifi_quick_add_tag(&probe_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); + int ret = libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); + if (ret != 0) { + return ret; + } + + ret = libwifi_quick_add_tag(&probe_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); + return ret; } /** 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); * @param reason_code The probe_req reason code * */ -void libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], +int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], const unsigned char transmitter[6], const unsigned char bssid[6], const char *ssid, uint8_t channel); 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) { /** * Simple helper to set the probe response SSID tag by removing it and then adding it back with the new value. */ -void libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid) { +int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid) { + int ret = 0; + if (probe_resp->tags.length != 0) { - libwifi_remove_tag(&probe_resp->tags, TAG_SSID); + ret = libwifi_remove_tag(&probe_resp->tags, TAG_SSID); + if (ret != 0) { + return ret; + } } - libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (void *) ssid, strlen(ssid)); + ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (void *) ssid, strlen(ssid)); + + return ret; } /** * Simple helper to set the probe response DS tag by removing it and then adding it back with the new value. */ -void libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel) { +int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel) { + int ret = 0; + if (probe_resp->tags.length != 0) { - libwifi_remove_tag(&probe_resp->tags, TAG_DS_PARAMETER); + ret = libwifi_remove_tag(&probe_resp->tags, TAG_DS_PARAMETER); + if (ret != 0) { + return ret; + } } const unsigned char *chan = (const unsigned char *) &channel; - libwifi_quick_add_tag(&probe_resp->tags, TAG_DS_PARAMETER, chan, 1); + ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_DS_PARAMETER, chan, 1); + + return ret; } /** * The generated probe response frame is made with sane defaults defined in common.h. * Three tagged parameters are also added to the probe response: SSID, Channel and Supported Rates. */ -void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], +int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], const unsigned char transmitter[6], const char *ssid, uint8_t channel) { memset(probe_resp, 0, sizeof(struct libwifi_probe_resp)); @@ -79,11 +93,20 @@ void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsi probe_resp->fixed_parameters.probe_resp_interval = BYTESWAP16(probe_resp_interval); probe_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); - libwifi_set_probe_resp_ssid(probe_resp, ssid); - libwifi_set_probe_resp_channel(probe_resp, channel); + int ret = libwifi_set_probe_resp_ssid(probe_resp, ssid); + if (ret != 0) { + return ret; + } + + ret = libwifi_set_probe_resp_channel(probe_resp, channel); + if (ret != 0) { + return ret; + } const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; - libwifi_quick_add_tag(&probe_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + + return ret; } /** 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 @@ * @param probe_resp A libwifi_probe_resp * @param ssid The new SSID */ -void libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid); +int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid); /** * 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 * @param probe_resp A libwifi_probe_resp * @param channel The new channel */ -void libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel); +int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel); /** * 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); * @param channel The desired channel of the probe_resp * */ -void libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], +int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], const unsigned char transmitter[6], const char *ssid, uint8_t channel); /** 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 reassoc_req->fixed_parameters.listen_interval = BYTESWAP16(LIBWIFI_DEFAULT_LISTEN_INTERVAL); memcpy(&reassoc_req->fixed_parameters.current_ap_address, current_ap, 6); - libwifi_quick_add_tag(&reassoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); - libwifi_quick_add_tag(&reassoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); + int ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); + if (ret != 0) { + return ret; + } + + ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1); - return 0; + return ret; } /** 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 * Simple helper to set the reassociation response DS tag by removing it and then adding it back with the new * value. */ -void libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel) { +int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel) { + int ret = 0; + if (reassoc_resp->tags.length != 0) { - libwifi_remove_tag(&reassoc_resp->tags, TAG_DS_PARAMETER); + ret = libwifi_remove_tag(&reassoc_resp->tags, TAG_DS_PARAMETER); + if (ret != 0) { + return ret; + } } const unsigned char *chan = (const unsigned char *) &channel; + ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_DS_PARAMETER, chan, 1); - libwifi_quick_add_tag(&reassoc_resp->tags, TAG_DS_PARAMETER, chan, 1); + return ret; } /** * The generated reassoc_resp frame is made with sane defaults defined in common.h. * Three tagged parameters are also added to the reassoc_resp: SSID, Channel and Supported Rates. */ -void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], +int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], const unsigned char transmitter[6], uint8_t channel) { memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp)); @@ -68,10 +74,15 @@ void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, cons reassoc_resp->fixed_parameters.status_code = STATUS_SUCCESS; reassoc_resp->fixed_parameters.association_id = rand() % 4096; - libwifi_set_reassoc_resp_channel(reassoc_resp, channel); + int ret = libwifi_set_reassoc_resp_channel(reassoc_resp, channel); + if (ret != 0) { + return ret; + } const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; - libwifi_quick_add_tag(&reassoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1); + + return ret; } /** 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 @@ * @param reassoc_resp A libwifi_reassoc_resp * @param channel The new channel */ -void libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); +int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); /** * 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 * @param channel The desired channel of the reassoc_resp * */ -void libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], +int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], const unsigned char transmitter[6], uint8_t channel); /** 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 @@ #include "../../core/misc/epoch.h" #include "../../core/frame/tag.h" +#include #include #include -void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], +int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, uint8_t noise_floor) { @@ -45,7 +46,7 @@ void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsig adv->fixed_parameters.noise_floor = noise_floor; if (adv_fields == NULL) { - return; + return -EINVAL; } // Maximum element size is 17 @@ -78,7 +79,9 @@ void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsig element_data_len = offset; - libwifi_quick_add_tag(&adv->tags, TAG_TIME_ADVERTISEMENT, element_data, element_data_len); + int ret = libwifi_quick_add_tag(&adv->tags, TAG_TIME_ADVERTISEMENT, element_data, element_data_len); + + return ret; } 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 @@ #include "../../core/frame/management/timing_ad.h" -void libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], +int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, uint8_t noise_floor); -- cgit 1.4.1