diff --git a/unit/test-ie.c b/unit/test-ie.c index 020db2fb..0ef45765 100644 --- a/unit/test-ie.c +++ b/unit/test-ie.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "src/ie.h" @@ -535,6 +536,94 @@ static void ie_test_wpa_build_compact_info(const void *data) assert(!memcmp(test->data, buf, test->data_len)); } +struct ie_tlv_concat_test { + const unsigned char *ies; + unsigned int len; + const unsigned char *expected_data; + ssize_t expected_len; +}; + +static unsigned char wsc_ie_single[] = { + 0xdd, 0xc7, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, + 0x44, 0x00, 0x01, 0x02, 0x10, 0x41, 0x00, 0x01, 0x01, 0x10, 0x12, 0x00, + 0x02, 0x00, 0x04, 0x10, 0x53, 0x00, 0x02, 0x26, 0x88, 0x10, 0x3b, 0x00, + 0x01, 0x03, 0x10, 0x47, 0x00, 0x10, 0xc4, 0x4a, 0xad, 0x8d, 0x25, 0x2f, + 0x52, 0xc6, 0xf9, 0x6b, 0x38, 0x5d, 0xcb, 0x23, 0x31, 0xae, 0x10, 0x21, + 0x00, 0x15, 0x41, 0x53, 0x55, 0x53, 0x54, 0x65, 0x4b, 0x20, 0x43, 0x6f, + 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x10, + 0x23, 0x00, 0x1c, 0x57, 0x69, 0x2d, 0x46, 0x69, 0x20, 0x50, 0x72, 0x6f, + 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, + 0x20, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x10, 0x24, 0x00, 0x08, 0x52, + 0x54, 0x2d, 0x41, 0x43, 0x36, 0x38, 0x55, 0x10, 0x42, 0x00, 0x11, 0x31, + 0x30, 0x3a, 0x63, 0x33, 0x3a, 0x37, 0x62, 0x3a, 0x35, 0x34, 0x3a, 0x37, + 0x34, 0x3a, 0x64, 0x30, 0x10, 0x54, 0x00, 0x08, 0x00, 0x06, 0x00, 0x50, + 0xf2, 0x04, 0x00, 0x01, 0x10, 0x11, 0x00, 0x08, 0x52, 0x54, 0x2d, 0x41, + 0x43, 0x36, 0x38, 0x55, 0x10, 0x08, 0x00, 0x02, 0x20, 0x08, 0x10, 0x3c, + 0x00, 0x01, 0x03, 0x10, 0x49, 0x00, 0x0e, 0x00, 0x37, 0x2a, 0x00, 0x01, + 0x20, 0x01, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +}; + +static unsigned char wsc_ie_split[] = { + 0xdd, 0x3A, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, + 0x44, 0x00, 0x01, 0x02, 0x10, 0x41, 0x00, 0x01, 0x01, 0x10, 0x12, 0x00, + 0x02, 0x00, 0x04, 0x10, 0x53, 0x00, 0x02, 0x26, 0x88, 0x10, 0x3b, 0x00, + 0x01, 0x03, 0x10, 0x47, 0x00, 0x10, 0xc4, 0x4a, 0xad, 0x8d, 0x25, 0x2f, + 0x52, 0xc6, 0xf9, 0x6b, 0x38, 0x5d, 0xcb, 0x23, 0x31, 0xae, 0x10, 0x21, + 0xdd, 0x3A, 0x00, 0x50, 0xf2, 0x04, 0x00, 0x15, 0x41, 0x53, 0x55, 0x53, + 0x54, 0x65, 0x4b, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, + 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x10, 0x23, 0x00, 0x1c, 0x57, 0x69, 0x2d, + 0x46, 0x69, 0x20, 0x50, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, + 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, 0x20, 0x52, 0x6f, 0x75, 0x74, 0x65, + 0xdd, 0x3A, 0x00, 0x50, 0xf2, 0x04, 0x72, 0x10, 0x24, 0x00, 0x08, 0x52, + 0x54, 0x2d, 0x41, 0x43, 0x36, 0x38, 0x55, 0x10, 0x42, 0x00, 0x11, 0x31, + 0x30, 0x3a, 0x63, 0x33, 0x3a, 0x37, 0x62, 0x3a, 0x35, 0x34, 0x3a, 0x37, + 0x34, 0x3a, 0x64, 0x30, 0x10, 0x54, 0x00, 0x08, 0x00, 0x06, 0x00, 0x50, + 0xf2, 0x04, 0x00, 0x01, 0x10, 0x11, 0x00, 0x08, 0x52, 0x54, 0x2d, 0x41, + 0xdd, 0x25, 0x00, 0x50, 0xf2, 0x04, 0x43, 0x36, 0x38, 0x55, 0x10, 0x08, + 0x00, 0x02, 0x20, 0x08, 0x10, 0x3c, 0x00, 0x01, 0x03, 0x10, 0x49, 0x00, + 0x0e, 0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 0x01, 0x06, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, +}; + +struct ie_tlv_concat_test ie_tlv_concat_test_data_1 = { + .ies = wsc_ie_single, + .len = sizeof(wsc_ie_single), + .expected_data = wsc_ie_single + 6, + .expected_len = sizeof(wsc_ie_single) - 6, +}; + +struct ie_tlv_concat_test ie_tlv_concat_test_data_2 = { + .ies = beacon_frame + 36, + .len = 252, + .expected_data = beacon_frame + 206, + .expected_len = 45, +}; + +struct ie_tlv_concat_test ie_tlv_concat_test_data_3 = { + .ies = wsc_ie_split, + .len = sizeof(wsc_ie_split), + .expected_data = wsc_ie_single + 6, + .expected_len = sizeof(wsc_ie_single) - 6, +}; + +static void ie_test_concat_wsc(const void *data) +{ + const struct ie_tlv_concat_test *test = data; + void *res; + ssize_t len; + + res = ie_tlv_extract_wsc_payload(test->ies, test->len, &len); + + assert(len == test->expected_len); + + if (len > 0) + assert(!memcmp(res, test->expected_data, len)); + else + assert(res == NULL); + + l_free(res); +} + int main(int argc, char *argv[]) { l_test_init(&argc, &argv); @@ -582,5 +671,12 @@ int main(int argc, char *argv[]) ie_test_wpa_build_compact_info, &ie_wpa_info_test_5); + l_test_add("/ie/Concatentation/WSC/Test Case 1", + ie_test_concat_wsc, &ie_tlv_concat_test_data_1); + l_test_add("/ie/Concatentation/WSC/Test Case 2", + ie_test_concat_wsc, &ie_tlv_concat_test_data_2); + l_test_add("/ie/Concatentation/WSC/Test Case 3", + ie_test_concat_wsc, &ie_tlv_concat_test_data_3); + return l_test_run(); }