test-p2p.c (39820B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <stdio.h> 28 #include <string.h> 29 #include <assert.h> 30 #include <stdlib.h> 31 #include <errno.h> 32 #include <ell/ell.h> 33 34 #include "src/p2putil.h" 35 #include "src/ie.h" 36 37 static const uint8_t p2p_attrs1[] = { 38 0x02, 0x02, 0x00, 0x25, 0x00, 0x0d, 0x1d, 0x00, 0x00, 0x28, 0xf8, 0xed, 39 0x26, 0x57, 0x11, 0x08, 0x00, 0x01, 0x00, 0x50, 0xf2, 0x04, 0x00, 0x01, 40 0x00, 0x10, 0x11, 0x00, 0x08, 0x74, 0x65, 0x73, 0x74, 0x64, 0x65, 0x76, 41 0x31, 0x0f, 0x15, 0x00, 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0, 0x44, 0x49, 42 0x52, 0x45, 0x43, 0x54, 0x2d, 0x5a, 0x75, 0x2d, 0x41, 0x6e, 0x64, 0x72, 43 0x65, 44 }; 45 46 static void p2p_test_iter_sanity_check(const void *data) 47 { 48 struct p2p_attr_iter iter; 49 50 p2p_attr_iter_init(&iter, p2p_attrs1, sizeof(p2p_attrs1)); 51 52 assert(p2p_attr_iter_next(&iter)); 53 assert(p2p_attr_iter_get_type(&iter) == P2P_ATTR_P2P_CAPABILITY); 54 assert(p2p_attr_iter_get_length(&iter) == 2); 55 56 assert(p2p_attr_iter_next(&iter)); 57 assert(p2p_attr_iter_get_type(&iter) == P2P_ATTR_P2P_DEVICE_INFO); 58 assert(p2p_attr_iter_get_length(&iter) == 29); 59 60 assert(p2p_attr_iter_next(&iter)); 61 assert(p2p_attr_iter_get_type(&iter) == P2P_ATTR_P2P_GROUP_ID); 62 assert(p2p_attr_iter_get_length(&iter) == 21); 63 64 assert(!p2p_attr_iter_next(&iter)); 65 } 66 67 typedef bool (*test_queue_cmp_func)(const void *data1, const void *data2); 68 69 static bool test_queue_cmp(struct l_queue *q1, struct l_queue *q2, 70 test_queue_cmp_func func) 71 { 72 const struct l_queue_entry *entry1 = l_queue_get_entries(q1); 73 const struct l_queue_entry *entry2 = l_queue_get_entries(q2); 74 75 while (entry1 && entry2) { 76 if (!func(entry1->data, entry2->data)) 77 return false; 78 79 entry1 = entry1->next; 80 entry2 = entry2->next; 81 } 82 83 return !entry1 && !entry2; 84 } 85 86 static bool p2p_noa_desc_cmp(const void *data1, const void *data2) 87 { 88 const struct p2p_notice_of_absence_desc *desc1 = data1; 89 const struct p2p_notice_of_absence_desc *desc2 = data2; 90 91 if (desc1->count_type != desc2->count_type) 92 return false; 93 if (desc1->duration != desc2->duration) 94 return false; 95 if (desc1->interval != desc2->interval) 96 return false; 97 if (desc1->start_time != desc2->start_time) 98 return false; 99 100 return true; 101 } 102 103 /* 104 * The attributes in a P2P IE are not explicitly required to be ordered 105 * in the same way they're listed in each frame's format specification in 106 * Wi-Fi P2P Technical Specification v1.7 and in fact some consumer devices 107 * switch some attributes' order in their probe responses. This compares 108 * the contents of two sets of P2P IEs ignoring attribute order and payload 109 * segmentation into individual P2P IEs. 110 * TODO: Might also want to validate the WSC IEs written by the p2putil.c 111 * builder functions. 112 */ 113 static bool p2p_payload_cmd(const uint8_t *ies1, size_t ies1_len, 114 const uint8_t *ies2, size_t ies2_len) 115 { 116 uint8_t *payload1, *payload2; 117 ssize_t payload1_len, payload2_len; 118 struct p2p_attr_iter iter1, iter2; 119 const uint8_t *attr1_start[P2P_ATTR_PERSISTENT_GROUP_INFO + 1]; 120 int i; 121 bool r = false; 122 123 if (!ies1 || !ies2) 124 return false; 125 126 payload1 = ie_tlv_extract_p2p_payload(ies1, ies1_len, &payload1_len); 127 payload2 = ie_tlv_extract_p2p_payload(ies2, ies2_len, &payload2_len); 128 129 if (payload1_len < 0 || payload2_len < 0) 130 return false; 131 132 p2p_attr_iter_init(&iter1, payload1, payload1_len); 133 p2p_attr_iter_init(&iter2, payload2, payload2_len); 134 135 memset(attr1_start, 0, sizeof(attr1_start)); 136 137 while (p2p_attr_iter_next(&iter1)) { 138 enum p2p_attr type = p2p_attr_iter_get_type(&iter1); 139 const uint8_t *start = p2p_attr_iter_get_data(&iter1) - 3; 140 141 if (type >= L_ARRAY_SIZE(attr1_start)) 142 goto done; /* Unknown attribute */ 143 144 if (attr1_start[type]) 145 goto done; /* Duplicate attribute type in @ies1 */ 146 147 attr1_start[type] = start; 148 } 149 150 while (p2p_attr_iter_next(&iter2)) { 151 enum p2p_attr type = p2p_attr_iter_get_type(&iter2); 152 const uint8_t *start = p2p_attr_iter_get_data(&iter2) - 3; 153 size_t len; 154 155 if ((int) type >= (int) L_ARRAY_SIZE(attr1_start)) 156 goto done; /* Unknown attribute */ 157 158 if (!attr1_start[type]) 159 goto done; /* Not in @ies1 or dupe in @ies2 */ 160 161 len = p2p_attr_iter_get_length(&iter2) + 3; 162 163 /* 164 * It's safe to memcmp len bytes because the length is also 165 * encoded in the first 3 bytes of both buffers. 166 */ 167 if (memcmp(start, attr1_start[type], len)) 168 goto done; /* Contents or lengths differ */ 169 170 attr1_start[type] = NULL; 171 } 172 173 for (i = 0; i < (int) L_ARRAY_SIZE(attr1_start); i++) 174 if (attr1_start[i]) 175 goto done; /* @ies1 attribute was not in @ies2 */ 176 177 r = true; 178 179 done: 180 l_free(payload1); 181 l_free(payload2); 182 return r; 183 } 184 185 static const uint8_t p2p_beacon_ies_1[] = { 186 0xdd, 0x12, 0x50, 0x6f, 0x9a, 0x09, 0x02, 0x02, 0x00, 0x05, 0xab, 0x03, 187 0x06, 0x00, 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0, 0xdd, 0x4e, 0x00, 0x50, 188 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 0x44, 0x00, 0x01, 0x02, 189 0x10, 0x41, 0x00, 0x01, 0x01, 0x10, 0x12, 0x00, 0x02, 0x00, 0x04, 0x10, 190 0x53, 0x00, 0x02, 0x43, 0x88, 0x10, 0x49, 0x00, 0x0e, 0x00, 0x37, 0x2a, 191 0x00, 0x01, 0x20, 0x01, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 192 0x11, 0x00, 0x0d, 0x4c, 0x45, 0x58, 0x36, 0x32, 0x36, 0x2d, 0x50, 0x64, 193 0x61, 0x4e, 0x65, 0x74, 0x10, 0x54, 0x00, 0x08, 0x00, 0x08, 0x00, 0x50, 194 0xf2, 0x04, 0x00, 0x02, 0xdd, 0x16, 0x50, 0x6f, 0x9a, 0x09, 0x0c, 0x0f, 195 0x00, 0xe1, 0x00, 0x01, 0xb0, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 196 0x7c, 0x45, 0x8f, 0x0c, 197 }; 198 199 struct p2p_beacon_data { 200 const uint8_t *ies; 201 size_t ies_len; 202 ssize_t payload_len; 203 struct p2p_beacon data; 204 const struct p2p_notice_of_absence_desc *noa_descs; 205 }; 206 207 static const struct p2p_beacon_data p2p_beacon_data_1 = { 208 .ies = p2p_beacon_ies_1, 209 .ies_len = L_ARRAY_SIZE(p2p_beacon_ies_1), 210 .payload_len = 32, 211 .data = { 212 .capability = { 213 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 214 P2P_DEVICE_CAP_CONCURRENT_OP, 215 .group_caps = P2P_GROUP_CAP_GO | 216 P2P_GROUP_CAP_PERSISTENT_GROUP | 217 P2P_GROUP_CAP_INTRA_BSS_DISTRIBUTION | 218 P2P_GROUP_CAP_PERSISTENT_RECONNECT | 219 P2P_GROUP_CAP_IP_ALLOCATION, 220 }, 221 .device_addr = { 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0 }, 222 .notice_of_absence = { 223 .index = 225, 224 .opp_ps = false, 225 .ct_window = 0, 226 }, 227 }, 228 .noa_descs = (const struct p2p_notice_of_absence_desc []) { 229 [0] = { 230 .count_type = 1, 231 .duration = 46000, 232 .interval = 0, 233 .start_time = 210716028, 234 }, 235 [1] = {} 236 }, 237 }; 238 239 static void p2p_test_parse_beacon(const void *data) 240 { 241 const struct p2p_beacon_data *test = data; 242 struct p2p_beacon attrs1, attrs2; 243 const struct p2p_notice_of_absence_desc *desc = test->noa_descs; 244 uint8_t *payload; 245 ssize_t payload_len; 246 247 payload = ie_tlv_extract_p2p_payload(test->ies, test->ies_len, 248 &payload_len); 249 l_free(payload); 250 assert(payload_len == test->payload_len); 251 252 memcpy(&attrs2, &test->data, sizeof(attrs2)); 253 254 if (desc) 255 attrs2.notice_of_absence.descriptors = l_queue_new(); 256 257 while (desc && desc->start_time) { 258 l_queue_push_tail(attrs2.notice_of_absence.descriptors, 259 l_memdup(desc, sizeof(*desc))); 260 desc++; 261 } 262 263 assert(p2p_parse_beacon(test->ies, test->ies_len, &attrs1) == 0); 264 265 assert(attrs1.capability.device_caps == attrs2.capability.device_caps); 266 assert(attrs1.capability.group_caps == attrs2.capability.group_caps); 267 268 assert(!memcmp(attrs1.device_addr, attrs2.device_addr, 6)); 269 270 assert(attrs1.notice_of_absence.index == 271 attrs2.notice_of_absence.index); 272 assert(attrs1.notice_of_absence.opp_ps == 273 attrs2.notice_of_absence.opp_ps); 274 assert(attrs1.notice_of_absence.ct_window == 275 attrs2.notice_of_absence.ct_window); 276 assert(test_queue_cmp(attrs1.notice_of_absence.descriptors, 277 attrs2.notice_of_absence.descriptors, 278 p2p_noa_desc_cmp)); 279 280 p2p_clear_beacon(&attrs1); 281 p2p_clear_beacon(&attrs2); 282 } 283 284 static void p2p_test_build_beacon(const void *data) 285 { 286 const struct p2p_beacon_data *test = data; 287 struct p2p_beacon attrs2; 288 const struct p2p_notice_of_absence_desc *desc = test->noa_descs; 289 uint8_t *ies; 290 size_t ies_len; 291 292 memcpy(&attrs2, &test->data, sizeof(attrs2)); 293 294 if (desc) 295 attrs2.notice_of_absence.descriptors = l_queue_new(); 296 297 while (desc && desc->start_time) { 298 l_queue_push_tail(attrs2.notice_of_absence.descriptors, 299 l_memdup(desc, sizeof(*desc))); 300 desc++; 301 } 302 303 ies = p2p_build_beacon(&attrs2, &ies_len); 304 p2p_clear_beacon(&attrs2); 305 306 assert(p2p_payload_cmd(ies, ies_len, test->ies, test->ies_len)); 307 l_free(ies); 308 } 309 310 static const uint8_t p2p_probe_req_ies_1[] = { 311 0xdd, 0x73, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 312 0x3a, 0x00, 0x01, 0x01, 0x10, 0x08, 0x00, 0x02, 0x31, 0x48, 0x10, 0x47, 313 0x00, 0x10, 0x9a, 0xdd, 0x77, 0x82, 0xcb, 0xa6, 0x5e, 0x2d, 0xac, 0xd9, 314 0xc0, 0x54, 0x34, 0xd0, 0xd7, 0x29, 0x10, 0x54, 0x00, 0x08, 0x00, 0x01, 315 0x00, 0x50, 0xf2, 0x04, 0x00, 0x01, 0x10, 0x3c, 0x00, 0x01, 0x03, 0x10, 316 0x02, 0x00, 0x02, 0x00, 0x00, 0x10, 0x09, 0x00, 0x02, 0x00, 0x00, 0x10, 317 0x12, 0x00, 0x02, 0x00, 0x00, 0x10, 0x21, 0x00, 0x01, 0x20, 0x10, 0x23, 318 0x00, 0x01, 0x20, 0x10, 0x24, 0x00, 0x01, 0x20, 0x10, 0x11, 0x00, 0x08, 319 0x74, 0x65, 0x73, 0x74, 0x64, 0x65, 0x76, 0x31, 0x10, 0x49, 0x00, 0x09, 320 0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 0x03, 0x01, 0x01, 0xdd, 0x11, 0x50, 321 0x6f, 0x9a, 0x09, 0x02, 0x02, 0x00, 0x25, 0x00, 0x06, 0x05, 0x00, 0x58, 322 0x58, 0x04, 0x51, 0x01, 323 }; 324 325 struct p2p_probe_req_data { 326 const uint8_t *ies; 327 size_t ies_len; 328 ssize_t payload_len; 329 struct p2p_probe_req data; 330 }; 331 332 static const struct p2p_probe_req_data p2p_probe_req_data_1 = { 333 .ies = p2p_probe_req_ies_1, 334 .ies_len = L_ARRAY_SIZE(p2p_probe_req_ies_1), 335 .payload_len = 13, 336 .data = { 337 .capability = { 338 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 339 P2P_DEVICE_CAP_CONCURRENT_OP | 340 P2P_DEVICE_CAP_INVITATION_PROCEDURE, 341 .group_caps = 0, 342 }, 343 .listen_channel = { 344 .country = { 'X', 'X', '\x04' }, 345 .oper_class = 81, 346 .channel_num = 1, 347 }, 348 }, 349 }; 350 351 static void p2p_test_parse_probe_req(const void *data) 352 { 353 const struct p2p_probe_req_data *test = data; 354 uint8_t *payload; 355 ssize_t payload_len; 356 struct p2p_probe_req attrs; 357 358 payload = ie_tlv_extract_p2p_payload(test->ies, test->ies_len, 359 &payload_len); 360 l_free(payload); 361 assert(payload_len == test->payload_len); 362 363 assert(p2p_parse_probe_req(test->ies, test->ies_len, &attrs) == 0); 364 365 assert(attrs.capability.device_caps == 366 test->data.capability.device_caps); 367 assert(attrs.capability.group_caps == test->data.capability.group_caps); 368 369 assert(!memcmp(attrs.device_addr, test->data.device_addr, 6)); 370 371 assert(!memcmp(attrs.listen_channel.country, 372 test->data.listen_channel.country, 3)); 373 assert(attrs.listen_channel.oper_class == 374 test->data.listen_channel.oper_class); 375 assert(attrs.listen_channel.channel_num == 376 test->data.listen_channel.channel_num); 377 378 assert(attrs.listen_availability.avail_period_ms == 379 test->data.listen_availability.avail_period_ms); 380 assert(attrs.listen_availability.avail_interval_ms == 381 test->data.listen_availability.avail_interval_ms); 382 383 assert(!memcmp(attrs.device_info.device_addr, 384 test->data.device_info.device_addr, 6)); 385 assert(attrs.device_info.wsc_config_methods == 386 test->data.device_info.wsc_config_methods); 387 assert(attrs.device_info.primary_device_type.category == 388 test->data.device_info.primary_device_type.category); 389 assert(!memcmp(attrs.device_info.primary_device_type.oui, 390 test->data.device_info.primary_device_type.oui, 3)); 391 assert(attrs.device_info.primary_device_type.oui_type == 392 test->data.device_info.primary_device_type.oui_type); 393 assert(attrs.device_info.primary_device_type.subcategory == 394 test->data.device_info.primary_device_type.subcategory); 395 assert(l_queue_length(attrs.device_info.secondary_device_types) == 396 l_queue_length(test->data.device_info.secondary_device_types)); 397 assert(!strcmp(attrs.device_info.device_name, 398 test->data.device_info.device_name)); 399 400 assert(!memcmp(attrs.operating_channel.country, 401 test->data.operating_channel.country, 3)); 402 assert(attrs.operating_channel.oper_class == 403 test->data.operating_channel.oper_class); 404 assert(attrs.operating_channel.channel_num == 405 test->data.operating_channel.channel_num); 406 407 assert(l_queue_length(attrs.service_hashes) == 408 l_queue_length(test->data.service_hashes)); 409 410 p2p_clear_probe_req(&attrs); 411 } 412 413 static void p2p_test_build_probe_req(const void *data) 414 { 415 const struct p2p_probe_req_data *test = data; 416 uint8_t *ies; 417 size_t ies_len; 418 419 ies = p2p_build_probe_req(&test->data, &ies_len); 420 421 assert(p2p_payload_cmd(ies, ies_len, test->ies, test->ies_len)); 422 l_free(ies); 423 } 424 425 /* Notice of Absence and Device Info in the wrong order */ 426 static const uint8_t p2p_probe_resp_ies_1[] = { 427 0xdd, 0xa2, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 428 0x44, 0x00, 0x01, 0x02, 0x10, 0x41, 0x00, 0x01, 0x01, 0x10, 0x12, 0x00, 429 0x02, 0x00, 0x04, 0x10, 0x53, 0x00, 0x02, 0x43, 0x88, 0x10, 0x3b, 0x00, 430 0x01, 0x03, 0x10, 0x47, 0x00, 0x10, 0xb1, 0x7d, 0x6f, 0xc9, 0x4f, 0xd1, 431 0x5a, 0x6f, 0xb6, 0x50, 0x53, 0x11, 0x0b, 0x2a, 0xb5, 0x25, 0x10, 0x21, 432 0x00, 0x0d, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x65, 0x6b, 0x20, 0x49, 433 0x6e, 0x63, 0x2e, 0x10, 0x23, 0x00, 0x12, 0x4d, 0x54, 0x4b, 0x20, 0x57, 434 0x69, 0x72, 0x65, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x4d, 0x6f, 0x64, 0x65, 435 0x6c, 0x10, 0x24, 0x00, 0x03, 0x31, 0x2e, 0x30, 0x10, 0x42, 0x00, 0x03, 436 0x32, 0x2e, 0x30, 0x10, 0x54, 0x00, 0x08, 0x00, 0x08, 0x00, 0x50, 0xf2, 437 0x04, 0x00, 0x02, 0x10, 0x11, 0x00, 0x0d, 0x4c, 0x45, 0x58, 0x36, 0x32, 438 0x36, 0x2d, 0x50, 0x64, 0x61, 0x4e, 0x65, 0x74, 0x10, 0x08, 0x00, 0x02, 439 0x41, 0x08, 0x10, 0x49, 0x00, 0x0e, 0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 440 0x01, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdd, 0x27, 0x50, 0x6f, 441 0x9a, 0x09, 0x02, 0x02, 0x00, 0x05, 0xab, 0x0d, 0x1b, 0x00, 0x2a, 0xfe, 442 0xcd, 0x01, 0xbe, 0xa0, 0x01, 0x88, 0x00, 0x08, 0x00, 0x50, 0xf2, 0x04, 443 0x00, 0x02, 0x00, 0x10, 0x11, 0x00, 0x06, 0x4d, 0x6f, 0x62, 0x69, 0x6c, 444 0x65, 0xdd, 0x16, 0x50, 0x6f, 0x9a, 0x09, 0x0c, 0x0f, 0x00, 0xe1, 0x00, 445 0x01, 0xb0, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x45, 0x8f, 446 0x0c, 447 }; 448 449 struct p2p_probe_resp_data { 450 const uint8_t *ies; 451 size_t ies_len; 452 ssize_t payload_len; 453 struct p2p_probe_resp data; 454 const struct p2p_notice_of_absence_desc *noa_descs; 455 }; 456 457 static const struct p2p_probe_resp_data p2p_probe_resp_data_1 = { 458 .ies = p2p_probe_resp_ies_1, 459 .ies_len = L_ARRAY_SIZE(p2p_probe_resp_ies_1), 460 .payload_len = 53, 461 .data = { 462 .capability = { 463 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 464 P2P_DEVICE_CAP_CONCURRENT_OP, 465 .group_caps = P2P_GROUP_CAP_GO | 466 P2P_GROUP_CAP_PERSISTENT_GROUP | 467 P2P_GROUP_CAP_INTRA_BSS_DISTRIBUTION | 468 P2P_GROUP_CAP_PERSISTENT_RECONNECT | 469 P2P_GROUP_CAP_IP_ALLOCATION, 470 }, 471 .notice_of_absence = { 472 .index = 225, 473 .opp_ps = false, 474 .ct_window = 0, 475 }, 476 .device_info = { 477 .device_addr = { 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0 }, 478 .wsc_config_methods = WSC_CONFIGURATION_METHOD_DISPLAY | 479 WSC_CONFIGURATION_METHOD_PUSH_BUTTON | 480 WSC_CONFIGURATION_METHOD_KEYPAD, 481 .primary_device_type = { 482 .category = 8, 483 .oui = { 0x00, 0x50, 0xf2 }, 484 .oui_type = 0x04, 485 .subcategory = 2, 486 }, 487 .device_name = "Mobile", 488 }, 489 }, 490 .noa_descs = (const struct p2p_notice_of_absence_desc []) { 491 [0] = { 492 .count_type = 1, 493 .duration = 46000, 494 .interval = 0, 495 .start_time = 210716028, 496 }, 497 [1] = {} 498 }, 499 }; 500 501 static const uint8_t p2p_probe_resp_ies_2[] = { 502 0xdd, 0x3e, 0x50, 0x6f, 0x9a, 0x09, 0x02, 0x02, 0x00, 0x05, 0x01, 0x0d, 503 0x32, 0x00, 0xa2, 0x8c, 0xfd, 0xb9, 0x05, 0xef, 0x5a, 0x88, 0x00, 0x03, 504 0x00, 0x50, 0xf2, 0x04, 0x00, 0x01, 0x00, 0x10, 0x11, 0x00, 0x1d, 0x44, 505 0x49, 0x52, 0x45, 0x43, 0x54, 0x2d, 0x45, 0x46, 0x2d, 0x48, 0x50, 0x20, 506 0x45, 0x4e, 0x56, 0x59, 0x20, 0x34, 0x35, 0x32, 0x30, 0x20, 0x73, 0x65, 507 0x72, 0x69, 0x65, 0x73, 0xdd, 0xc1, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 508 0x00, 0x01, 0x10, 0x10, 0x44, 0x00, 0x01, 0x02, 0x10, 0x57, 0x00, 0x01, 509 0x01, 0x10, 0x41, 0x00, 0x01, 0x00, 0x10, 0x3b, 0x00, 0x01, 0x03, 0x10, 510 0x47, 0x00, 0x10, 0x1c, 0x85, 0x2a, 0x4d, 0xb8, 0x00, 0x1f, 0x08, 0xab, 511 0xcd, 0xa0, 0x8c, 0xfd, 0xb9, 0x05, 0xef, 0x10, 0x21, 0x00, 0x02, 0x48, 512 0x50, 0x10, 0x23, 0x00, 0x11, 0x45, 0x4e, 0x56, 0x59, 0x20, 0x34, 0x35, 513 0x32, 0x30, 0x20, 0x73, 0x65, 0x72, 0x69, 0x65, 0x73, 0x00, 0x10, 0x24, 514 0x00, 0x05, 0x34, 0x35, 0x32, 0x37, 0x00, 0x10, 0x42, 0x00, 0x10, 0x54, 515 0x48, 0x36, 0x35, 0x4f, 0x33, 0x48, 0x31, 0x58, 0x59, 0x30, 0x36, 0x36, 516 0x30, 0x00, 0x00, 0x10, 0x54, 0x00, 0x08, 0x00, 0x03, 0x00, 0x50, 0xf2, 517 0x04, 0x00, 0x05, 0x10, 0x11, 0x00, 0x1d, 0x44, 0x49, 0x52, 0x45, 0x43, 518 0x54, 0x2d, 0x45, 0x46, 0x2d, 0x48, 0x50, 0x20, 0x45, 0x4e, 0x56, 0x59, 519 0x20, 0x34, 0x35, 0x32, 0x30, 0x20, 0x73, 0x65, 0x72, 0x69, 0x65, 0x73, 520 0x10, 0x08, 0x00, 0x02, 0x00, 0x00, 0x10, 0x49, 0x00, 0x06, 0x00, 0x37, 521 0x2a, 0x00, 0x01, 0x20, 0x10, 0x49, 0x00, 0x17, 0x00, 0x01, 0x37, 0x10, 522 0x06, 0x00, 0x10, 0x1c, 0x85, 0x2a, 0x4d, 0xb8, 0x00, 0x1f, 0x08, 0xab, 523 0xcd, 0xa0, 0x8c, 0xfd, 0xb9, 0x05, 0xef, 524 }; 525 526 static const struct p2p_probe_resp_data p2p_probe_resp_data_2 = { 527 .ies = p2p_probe_resp_ies_2, 528 .ies_len = L_ARRAY_SIZE(p2p_probe_resp_ies_2), 529 .payload_len = 58, 530 .data = { 531 .capability = { 532 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 533 P2P_DEVICE_CAP_CONCURRENT_OP, 534 .group_caps = P2P_GROUP_CAP_GO, 535 }, 536 .device_info = { 537 .device_addr = { 0xa2, 0x8c, 0xfd, 0xb9, 0x05, 0xef }, 538 .wsc_config_methods = 539 WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | 540 0x0800 | WSC_CONFIGURATION_METHOD_P2P | 541 WSC_CONFIGURATION_METHOD_PHYSICAL_DISPLAY_PIN, 542 .primary_device_type = { 543 .category = 3, 544 .oui = { 0x00, 0x50, 0xf2 }, 545 .oui_type = 0x04, 546 .subcategory = 1, 547 }, 548 .device_name = "DIRECT-EF-HP ENVY 4520 series", 549 }, 550 }, 551 }; 552 553 static void p2p_test_parse_probe_resp(const void *data) 554 { 555 const struct p2p_probe_resp_data *test = data; 556 struct p2p_probe_resp attrs1, attrs2; 557 const struct p2p_notice_of_absence_desc *desc = test->noa_descs; 558 uint8_t *payload; 559 ssize_t payload_len; 560 561 payload = ie_tlv_extract_p2p_payload(test->ies, test->ies_len, 562 &payload_len); 563 l_free(payload); 564 assert(payload_len == test->payload_len); 565 566 assert(p2p_parse_probe_resp(test->ies, test->ies_len, &attrs1) == 0); 567 568 memcpy(&attrs2, &test->data, sizeof(attrs2)); 569 570 if (desc) 571 attrs2.notice_of_absence.descriptors = l_queue_new(); 572 573 while (desc && desc->start_time) { 574 l_queue_push_tail(attrs2.notice_of_absence.descriptors, 575 l_memdup(desc, sizeof(*desc))); 576 desc++; 577 } 578 579 assert(attrs1.capability.device_caps == attrs2.capability.device_caps); 580 assert(attrs1.capability.group_caps == attrs2.capability.group_caps); 581 582 assert(attrs1.listen_availability.avail_period_ms == 583 attrs2.listen_availability.avail_period_ms); 584 assert(attrs1.listen_availability.avail_interval_ms == 585 attrs2.listen_availability.avail_interval_ms); 586 587 assert(attrs1.notice_of_absence.index == 588 attrs2.notice_of_absence.index); 589 assert(attrs1.notice_of_absence.opp_ps == 590 attrs2.notice_of_absence.opp_ps); 591 assert(attrs1.notice_of_absence.ct_window == 592 attrs2.notice_of_absence.ct_window); 593 assert(test_queue_cmp(attrs1.notice_of_absence.descriptors, 594 attrs2.notice_of_absence.descriptors, 595 p2p_noa_desc_cmp)); 596 597 assert(!memcmp(attrs1.device_info.device_addr, 598 attrs2.device_info.device_addr, 6)); 599 assert(attrs1.device_info.wsc_config_methods == 600 attrs2.device_info.wsc_config_methods); 601 assert(attrs1.device_info.primary_device_type.category == 602 attrs2.device_info.primary_device_type.category); 603 assert(!memcmp(attrs1.device_info.primary_device_type.oui, 604 attrs2.device_info.primary_device_type.oui, 3)); 605 assert(attrs1.device_info.primary_device_type.oui_type == 606 attrs2.device_info.primary_device_type.oui_type); 607 assert(attrs1.device_info.primary_device_type.subcategory == 608 attrs2.device_info.primary_device_type.subcategory); 609 assert(l_queue_length(attrs1.device_info.secondary_device_types) == 610 l_queue_length(attrs2.device_info.secondary_device_types)); 611 assert(!strcmp(attrs1.device_info.device_name, 612 attrs2.device_info.device_name)); 613 614 assert(l_queue_length(attrs1.group_clients) == 615 l_queue_length(attrs2.group_clients)); 616 617 assert(l_queue_length(attrs1.advertised_svcs) == 618 l_queue_length(attrs2.advertised_svcs)); 619 620 p2p_clear_probe_resp(&attrs1); 621 p2p_clear_probe_resp(&attrs2); 622 } 623 624 static void p2p_test_build_probe_resp(const void *data) 625 { 626 const struct p2p_probe_resp_data *test = data; 627 struct p2p_probe_resp attrs2; 628 const struct p2p_notice_of_absence_desc *desc = test->noa_descs; 629 uint8_t *ies; 630 size_t ies_len; 631 632 memcpy(&attrs2, &test->data, sizeof(attrs2)); 633 634 if (desc) 635 attrs2.notice_of_absence.descriptors = l_queue_new(); 636 637 while (desc && desc->start_time) { 638 l_queue_push_tail(attrs2.notice_of_absence.descriptors, 639 l_memdup(desc, sizeof(*desc))); 640 desc++; 641 } 642 643 ies = p2p_build_probe_resp(&attrs2, &ies_len); 644 p2p_clear_probe_resp(&attrs2); 645 646 assert(p2p_payload_cmd(ies, ies_len, test->ies, test->ies_len)); 647 l_free(ies); 648 } 649 650 static const uint8_t p2p_association_req_ies_1[] = { 651 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 652 0x3a, 0x00, 0x01, 0x01, 0x10, 0x49, 0x00, 0x06, 0x00, 0x37, 0x2a, 0x00, 653 0x01, 0x20, 0xdd, 0x29, 0x50, 0x6f, 0x9a, 0x09, 0x02, 0x02, 0x00, 0x27, 654 0x00, 0x0d, 0x1d, 0x00, 0x00, 0x28, 0xf8, 0xed, 0x26, 0x57, 0x11, 0x08, 655 0x00, 0x01, 0x00, 0x50, 0xf2, 0x04, 0x00, 0x01, 0x00, 0x10, 0x11, 0x00, 656 0x08, 0x74, 0x65, 0x73, 0x74, 0x64, 0x65, 0x76, 0x31, 657 }; 658 659 struct p2p_association_req_data { 660 const uint8_t *ies; 661 size_t ies_len; 662 ssize_t payload_len; 663 struct p2p_association_req data; 664 }; 665 666 static const struct p2p_association_req_data p2p_association_req_data_1 = { 667 .ies = p2p_association_req_ies_1, 668 .ies_len = L_ARRAY_SIZE(p2p_association_req_ies_1), 669 .payload_len = 37, 670 .data = { 671 .capability = { 672 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 673 P2P_DEVICE_CAP_CLIENT_DISCOVERABILITY | 674 P2P_DEVICE_CAP_CONCURRENT_OP | 675 P2P_DEVICE_CAP_INVITATION_PROCEDURE, 676 .group_caps = 0, 677 }, 678 .device_info = { 679 .device_addr = { 0x00, 0x28, 0xf8, 0xed, 0x26, 0x57 }, 680 .wsc_config_methods = WSC_CONFIGURATION_METHOD_DISPLAY | 681 WSC_CONFIGURATION_METHOD_KEYPAD | 682 WSC_CONFIGURATION_METHOD_P2P, 683 .primary_device_type = { 684 .category = 1, 685 .oui = { 0x00, 0x50, 0xf2 }, 686 .oui_type = 0x04, 687 .subcategory = 1, 688 }, 689 .device_name = "testdev1", 690 }, 691 }, 692 }; 693 694 static void p2p_test_parse_association_req(const void *data) 695 { 696 const struct p2p_association_req_data *test = data; 697 struct p2p_association_req attrs1, attrs2; 698 uint8_t *payload; 699 ssize_t payload_len; 700 701 payload = ie_tlv_extract_p2p_payload(test->ies, test->ies_len, 702 &payload_len); 703 l_free(payload); 704 assert(payload_len == test->payload_len); 705 706 assert(p2p_parse_association_req(test->ies, test->ies_len, &attrs1) == 707 0); 708 709 memcpy(&attrs2, &test->data, sizeof(attrs2)); 710 711 assert(attrs1.capability.device_caps == attrs2.capability.device_caps); 712 assert(attrs1.capability.group_caps == attrs2.capability.group_caps); 713 714 assert(attrs1.listen_availability.avail_period_ms == 715 attrs2.listen_availability.avail_period_ms); 716 assert(attrs1.listen_availability.avail_interval_ms == 717 attrs2.listen_availability.avail_interval_ms); 718 719 assert(!memcmp(attrs1.device_info.device_addr, 720 attrs2.device_info.device_addr, 6)); 721 assert(attrs1.device_info.wsc_config_methods == 722 attrs2.device_info.wsc_config_methods); 723 assert(attrs1.device_info.primary_device_type.category == 724 attrs2.device_info.primary_device_type.category); 725 assert(!memcmp(attrs1.device_info.primary_device_type.oui, 726 attrs2.device_info.primary_device_type.oui, 3)); 727 assert(attrs1.device_info.primary_device_type.oui_type == 728 attrs2.device_info.primary_device_type.oui_type); 729 assert(attrs1.device_info.primary_device_type.subcategory == 730 attrs2.device_info.primary_device_type.subcategory); 731 assert(l_queue_length(attrs1.device_info.secondary_device_types) == 732 l_queue_length(attrs2.device_info.secondary_device_types)); 733 assert(!strcmp(attrs1.device_info.device_name, 734 attrs2.device_info.device_name)); 735 736 assert(!memcmp(attrs1.interface.device_addr, 737 attrs2.interface.device_addr, 6)); 738 assert(l_queue_length(attrs1.interface.interface_addrs) == 739 l_queue_length(attrs2.interface.interface_addrs)); 740 741 p2p_clear_association_req(&attrs1); 742 p2p_clear_association_req(&attrs2); 743 } 744 745 static void p2p_test_build_association_req(const void *data) 746 { 747 const struct p2p_association_req_data *test = data; 748 uint8_t *ies; 749 size_t ies_len; 750 751 ies = p2p_build_association_req(&test->data, &ies_len); 752 753 assert(p2p_payload_cmd(ies, ies_len, test->ies, test->ies_len)); 754 l_free(ies); 755 } 756 757 /* Obligatory P2P IE empty here */ 758 static const uint8_t p2p_association_resp_ies_1[] = { 759 0x01, 0x08, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, 0x2d, 0x1a, 760 0x73, 0x11, 0x03, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 761 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 762 0x00, 0x00, 0x3d, 0x16, 0x64, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 763 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 764 0x00, 0x00, 0xdd, 0x04, 0x50, 0x6f, 0x9a, 0x09, 0x7f, 0x08, 0x01, 0x00, 765 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbf, 0x0c, 0x30, 0x71, 0x90, 0x03, 766 0xfe, 0xff, 0x00, 0x00, 0xfe, 0xff, 0x00, 0x00, 0xc0, 0x05, 0x00, 0x00, 767 0x00, 0xfe, 0xff, 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x80, 768 0x01, 0x03, 0xa4, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 769 0x00, 0x62, 0x32, 0x2f, 0x00, 0xdd, 0x07, 0x00, 0x0c, 0xe7, 0x08, 0x00, 770 0x00, 0x00, 771 }; 772 773 struct p2p_association_resp_data { 774 const uint8_t *ies; 775 size_t ies_len; 776 ssize_t payload_len; 777 struct p2p_association_resp data; 778 }; 779 780 static const struct p2p_association_resp_data p2p_association_resp_data_1 = { 781 .ies = p2p_association_resp_ies_1, 782 .ies_len = L_ARRAY_SIZE(p2p_association_resp_ies_1), 783 .payload_len = 0, 784 .data = {}, 785 }; 786 787 static void p2p_test_parse_association_resp(const void *data) 788 { 789 const struct p2p_association_resp_data *test = data; 790 struct p2p_association_resp attrs1, attrs2; 791 uint8_t *payload; 792 ssize_t payload_len; 793 794 payload = ie_tlv_extract_p2p_payload(test->ies, test->ies_len, 795 &payload_len); 796 l_free(payload); 797 assert(payload_len == test->payload_len); 798 799 assert(p2p_parse_association_resp(test->ies, test->ies_len, &attrs1) == 800 0); 801 802 memcpy(&attrs2, &test->data, sizeof(attrs2)); 803 804 assert(attrs1.status == attrs2.status); 805 806 assert(attrs1.listen_availability.avail_period_ms == 807 attrs2.listen_availability.avail_period_ms); 808 assert(attrs1.listen_availability.avail_interval_ms == 809 attrs2.listen_availability.avail_interval_ms); 810 811 p2p_clear_association_resp(&attrs1); 812 p2p_clear_association_resp(&attrs2); 813 } 814 815 static void p2p_test_build_association_resp(const void *data) 816 { 817 const struct p2p_association_resp_data *test = data; 818 uint8_t *ies; 819 size_t ies_len; 820 821 ies = p2p_build_association_resp(&test->data, &ies_len); 822 823 assert(p2p_payload_cmd(ies, ies_len, test->ies, test->ies_len)); 824 l_free(ies); 825 } 826 827 static const uint8_t p2p_provision_disc_req_1[] = { 828 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, 0x07, 0x01, 0xdd, 0x41, 0x50, 0x6f, 829 0x9a, 0x09, 0x02, 0x02, 0x00, 0x25, 0x00, 0x0d, 0x1d, 0x00, 0x00, 0x28, 830 0xf8, 0xed, 0x26, 0x57, 0x11, 0x08, 0x00, 0x01, 0x00, 0x50, 0xf2, 0x04, 831 0x00, 0x01, 0x00, 0x10, 0x11, 0x00, 0x08, 0x74, 0x65, 0x73, 0x74, 0x64, 832 0x65, 0x76, 0x31, 0x0f, 0x15, 0x00, 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0, 833 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x2d, 0x5a, 0x75, 0x2d, 0x54, 0x65, 834 0x73, 0x74, 0x31, 0xdd, 0x0a, 0x00, 0x50, 0xf2, 0x04, 0x10, 0x08, 0x00, 835 0x02, 0x00, 0x80, 836 }; 837 838 struct p2p_provision_disc_req_data { 839 const uint8_t *frame; 840 size_t frame_len; 841 ssize_t payload_len; 842 struct p2p_provision_discovery_req data; 843 }; 844 845 static const struct p2p_provision_disc_req_data p2p_provision_disc_req_data_1 = 846 { 847 .frame = p2p_provision_disc_req_1, 848 .frame_len = L_ARRAY_SIZE(p2p_provision_disc_req_1), 849 .payload_len = 61, 850 .data = { 851 .dialog_token = 1, 852 .capability = { 853 .device_caps = P2P_DEVICE_CAP_SVC_DISCOVERY | 854 P2P_DEVICE_CAP_CONCURRENT_OP | 855 P2P_DEVICE_CAP_INVITATION_PROCEDURE, 856 .group_caps = 0, 857 }, 858 .device_info = { 859 .device_addr = { 0x00, 0x28, 0xf8, 0xed, 0x26, 0x57 }, 860 .wsc_config_methods = WSC_CONFIGURATION_METHOD_DISPLAY | 861 WSC_CONFIGURATION_METHOD_KEYPAD | 862 WSC_CONFIGURATION_METHOD_P2P, 863 .primary_device_type = { 864 .category = 1, 865 .oui = { 0x00, 0x50, 0xf2 }, 866 .oui_type = 0x04, 867 .subcategory = 1, 868 }, 869 .device_name = "testdev1", 870 }, 871 .group_id = { 872 .device_addr = { 0x2a, 0xfe, 0xcd, 0x01, 0xbe, 0xa0 }, 873 .ssid = "DIRECT-Zu-Test1", 874 }, 875 .status = -1, 876 .wsc_config_method = WSC_CONFIGURATION_METHOD_PUSH_BUTTON, 877 }, 878 }; 879 880 static void p2p_test_parse_provision_disc_req(const void *data) 881 { 882 const struct p2p_provision_disc_req_data *test = data; 883 struct p2p_provision_discovery_req attrs1, attrs2; 884 uint8_t *payload; 885 ssize_t payload_len; 886 887 payload = ie_tlv_extract_p2p_payload(test->frame + 8, 888 test->frame_len - 8, 889 &payload_len); 890 l_free(payload); 891 assert(payload_len == test->payload_len); 892 893 assert(p2p_parse_provision_disc_req(test->frame + 7, 894 test->frame_len - 7, 895 &attrs1) == 0); 896 897 memcpy(&attrs2, &test->data, sizeof(attrs2)); 898 899 assert(attrs1.dialog_token == attrs2.dialog_token); 900 901 assert(attrs1.capability.device_caps == attrs2.capability.device_caps); 902 assert(attrs1.capability.group_caps == attrs2.capability.group_caps); 903 904 assert(!memcmp(attrs1.device_info.device_addr, 905 attrs2.device_info.device_addr, 6)); 906 assert(attrs1.device_info.wsc_config_methods == 907 attrs2.device_info.wsc_config_methods); 908 assert(attrs1.device_info.primary_device_type.category == 909 attrs2.device_info.primary_device_type.category); 910 assert(!memcmp(attrs1.device_info.primary_device_type.oui, 911 attrs2.device_info.primary_device_type.oui, 3)); 912 assert(attrs1.device_info.primary_device_type.oui_type == 913 attrs2.device_info.primary_device_type.oui_type); 914 assert(attrs1.device_info.primary_device_type.subcategory == 915 attrs2.device_info.primary_device_type.subcategory); 916 assert(l_queue_length(attrs1.device_info.secondary_device_types) == 917 l_queue_length(attrs2.device_info.secondary_device_types)); 918 assert(!strcmp(attrs1.device_info.device_name, 919 attrs2.device_info.device_name)); 920 921 assert(!memcmp(attrs1.group_id.device_addr, 922 attrs2.group_id.device_addr, 6)); 923 assert(!strcmp(attrs1.group_id.ssid, attrs2.group_id.ssid)); 924 925 assert(!memcmp(attrs1.intended_interface_addr, 926 attrs2.intended_interface_addr, 6)); 927 928 assert(attrs1.status == attrs2.status); 929 930 assert(!memcmp(attrs1.operating_channel.country, 931 attrs2.operating_channel.country, 3)); 932 assert(attrs1.operating_channel.oper_class == 933 attrs2.operating_channel.oper_class); 934 assert(attrs1.operating_channel.channel_num == 935 attrs2.operating_channel.channel_num); 936 937 assert(!memcmp(attrs1.channel_list.country, 938 attrs2.channel_list.country, 3)); 939 assert(l_queue_length(attrs1.channel_list.channel_entries) == 940 l_queue_length(attrs2.channel_list.channel_entries)); 941 942 assert(attrs1.session_info.data_len == attrs2.session_info.data_len); 943 assert(!attrs1.session_info.data_len || 944 !memcmp(attrs1.session_info.data, attrs2.session_info.data, 945 attrs1.session_info.data_len)); 946 947 assert(attrs1.connection_capability == attrs2.connection_capability); 948 949 assert(attrs1.advertisement_id.advertisement_id == 950 attrs2.advertisement_id.advertisement_id); 951 assert(!memcmp(attrs1.advertisement_id.service_mac_addr, 952 attrs2.advertisement_id.service_mac_addr, 6)); 953 954 assert(attrs1.config_timeout.go_config_timeout == 955 attrs2.config_timeout.go_config_timeout); 956 assert(attrs1.config_timeout.client_config_timeout == 957 attrs2.config_timeout.client_config_timeout); 958 959 assert(!memcmp(attrs1.listen_channel.country, 960 attrs2.listen_channel.country, 3)); 961 assert(attrs1.listen_channel.oper_class == 962 attrs2.listen_channel.oper_class); 963 assert(attrs1.listen_channel.channel_num == 964 attrs2.listen_channel.channel_num); 965 966 assert(attrs1.session_id.session_id == attrs2.session_id.session_id); 967 assert(!memcmp(attrs1.session_id.session_mac_addr, 968 attrs2.session_id.session_mac_addr, 6)); 969 970 assert(attrs1.transport_protocol == attrs2.transport_protocol); 971 972 assert(!memcmp(attrs1.persistent_group_info.device_addr, 973 attrs2.persistent_group_info.device_addr, 6)); 974 assert(!strcmp(attrs1.persistent_group_info.ssid, 975 attrs2.persistent_group_info.ssid)); 976 977 assert(attrs1.wsc_config_method == attrs2.wsc_config_method); 978 979 p2p_clear_provision_disc_req(&attrs1); 980 p2p_clear_provision_disc_req(&attrs2); 981 } 982 983 static void p2p_test_build_provision_disc_req(const void *data) 984 { 985 const struct p2p_provision_disc_req_data *test = data; 986 uint8_t *frame; 987 size_t frame_len; 988 989 frame = p2p_build_provision_disc_req(&test->data, &frame_len); 990 991 assert(!memcmp(frame, test->frame, 8)); 992 assert(p2p_payload_cmd(frame + 8, frame_len - 8, 993 test->frame + 8, test->frame_len - 8)); 994 l_free(frame); 995 } 996 997 /* The optional P2P IE not present here */ 998 static const uint8_t p2p_provision_disc_resp_1[] = { 999 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x09, 0x08, 0x01, 0xdd, 0x0a, 0x00, 0x50, 1000 0xf2, 0x04, 0x10, 0x08, 0x00, 0x02, 0x00, 0x80, 0xdd, 0x0d, 0x50, 0x6f, 1001 0x9a, 0x0a, 0x00, 0x00, 0x06, 0x00, 0x11, 0x00, 0x00, 0x00, 0x32, 1002 }; 1003 1004 struct p2p_provision_disc_resp_data { 1005 const uint8_t *frame; 1006 size_t frame_len; 1007 ssize_t payload_len; 1008 struct p2p_provision_discovery_resp data; 1009 }; 1010 1011 static const struct p2p_provision_disc_resp_data 1012 p2p_provision_disc_resp_data_1 = { 1013 .frame = p2p_provision_disc_resp_1, 1014 .frame_len = L_ARRAY_SIZE(p2p_provision_disc_resp_1), 1015 .payload_len = -ENOENT, 1016 .data = { 1017 .dialog_token = 1, 1018 .status = -1, 1019 .wsc_config_method = WSC_CONFIGURATION_METHOD_PUSH_BUTTON, 1020 }, 1021 }; 1022 1023 static void p2p_test_parse_provision_disc_resp(const void *data) 1024 { 1025 const struct p2p_provision_disc_resp_data *test = data; 1026 struct p2p_provision_discovery_resp attrs1, attrs2; 1027 uint8_t *payload; 1028 ssize_t payload_len; 1029 1030 payload = ie_tlv_extract_p2p_payload(test->frame + 8, 1031 test->frame_len - 8, 1032 &payload_len); 1033 if (payload_len >= 0) 1034 l_free(payload); 1035 1036 assert(payload_len == test->payload_len); 1037 1038 assert(p2p_parse_provision_disc_resp(test->frame + 7, 1039 test->frame_len - 7, 1040 &attrs1) == 0); 1041 1042 memcpy(&attrs2, &test->data, sizeof(attrs2)); 1043 1044 assert(attrs1.dialog_token == attrs2.dialog_token); 1045 1046 assert(attrs1.status == attrs2.status); 1047 1048 assert(attrs1.capability.device_caps == attrs2.capability.device_caps); 1049 assert(attrs1.capability.group_caps == attrs2.capability.group_caps); 1050 1051 assert(!memcmp(attrs1.device_info.device_addr, 1052 attrs2.device_info.device_addr, 6)); 1053 assert(attrs1.device_info.wsc_config_methods == 1054 attrs2.device_info.wsc_config_methods); 1055 assert(attrs1.device_info.primary_device_type.category == 1056 attrs2.device_info.primary_device_type.category); 1057 assert(!memcmp(attrs1.device_info.primary_device_type.oui, 1058 attrs2.device_info.primary_device_type.oui, 3)); 1059 assert(attrs1.device_info.primary_device_type.oui_type == 1060 attrs2.device_info.primary_device_type.oui_type); 1061 assert(attrs1.device_info.primary_device_type.subcategory == 1062 attrs2.device_info.primary_device_type.subcategory); 1063 assert(l_queue_length(attrs1.device_info.secondary_device_types) == 1064 l_queue_length(attrs2.device_info.secondary_device_types)); 1065 assert(!strcmp(attrs1.device_info.device_name, 1066 attrs2.device_info.device_name)); 1067 1068 assert(!memcmp(attrs1.group_id.device_addr, 1069 attrs2.group_id.device_addr, 6)); 1070 assert(!strcmp(attrs1.group_id.ssid, attrs2.group_id.ssid)); 1071 1072 assert(!memcmp(attrs1.intended_interface_addr, 1073 attrs2.intended_interface_addr, 6)); 1074 1075 assert(!memcmp(attrs1.operating_channel.country, 1076 attrs2.operating_channel.country, 3)); 1077 assert(attrs1.operating_channel.oper_class == 1078 attrs2.operating_channel.oper_class); 1079 assert(attrs1.operating_channel.channel_num == 1080 attrs2.operating_channel.channel_num); 1081 1082 assert(!memcmp(attrs1.channel_list.country, 1083 attrs2.channel_list.country, 3)); 1084 assert(l_queue_length(attrs1.channel_list.channel_entries) == 1085 l_queue_length(attrs2.channel_list.channel_entries)); 1086 1087 assert(attrs1.connection_capability == attrs2.connection_capability); 1088 1089 assert(attrs1.advertisement_id.advertisement_id == 1090 attrs2.advertisement_id.advertisement_id); 1091 assert(!memcmp(attrs1.advertisement_id.service_mac_addr, 1092 attrs2.advertisement_id.service_mac_addr, 6)); 1093 1094 assert(attrs1.config_timeout.go_config_timeout == 1095 attrs2.config_timeout.go_config_timeout); 1096 assert(attrs1.config_timeout.client_config_timeout == 1097 attrs2.config_timeout.client_config_timeout); 1098 1099 assert(attrs1.session_id.session_id == attrs2.session_id.session_id); 1100 assert(!memcmp(attrs1.session_id.session_mac_addr, 1101 attrs2.session_id.session_mac_addr, 6)); 1102 1103 assert(attrs1.transport_protocol == attrs2.transport_protocol); 1104 1105 assert(!memcmp(attrs1.persistent_group_info.device_addr, 1106 attrs2.persistent_group_info.device_addr, 6)); 1107 assert(!strcmp(attrs1.persistent_group_info.ssid, 1108 attrs2.persistent_group_info.ssid)); 1109 1110 assert(attrs1.session_info.data_len == attrs2.session_info.data_len); 1111 assert(!attrs1.session_info.data_len || 1112 !memcmp(attrs1.session_info.data, attrs2.session_info.data, 1113 attrs1.session_info.data_len)); 1114 1115 assert(attrs1.wsc_config_method == attrs2.wsc_config_method); 1116 1117 p2p_clear_provision_disc_resp(&attrs1); 1118 p2p_clear_provision_disc_resp(&attrs2); 1119 } 1120 1121 int main(int argc, char *argv[]) 1122 { 1123 l_test_init(&argc, &argv); 1124 1125 l_test_add("/p2p/iter/sanity-check", p2p_test_iter_sanity_check, NULL); 1126 1127 l_test_add("/p2p/parse/Beacon IEs 1", p2p_test_parse_beacon, 1128 &p2p_beacon_data_1); 1129 1130 l_test_add("/p2p/build/Beacon IEs 1", p2p_test_build_beacon, 1131 &p2p_beacon_data_1); 1132 1133 l_test_add("/p2p/parse/Probe Request IEs 1", p2p_test_parse_probe_req, 1134 &p2p_probe_req_data_1); 1135 1136 l_test_add("/p2p/build/Probe Request IEs 1", p2p_test_build_probe_req, 1137 &p2p_probe_req_data_1); 1138 1139 l_test_add("/p2p/parse/Probe Response IEs 1", p2p_test_parse_probe_resp, 1140 &p2p_probe_resp_data_1); 1141 l_test_add("/p2p/parse/Probe Response IEs 2", p2p_test_parse_probe_resp, 1142 &p2p_probe_resp_data_2); 1143 1144 l_test_add("/p2p/build/Probe Response IEs 1", p2p_test_build_probe_resp, 1145 &p2p_probe_resp_data_1); 1146 l_test_add("/p2p/build/Probe Response IEs 2", p2p_test_build_probe_resp, 1147 &p2p_probe_resp_data_2); 1148 1149 l_test_add("/p2p/parse/Association Request IEs 1", 1150 p2p_test_parse_association_req, 1151 &p2p_association_req_data_1); 1152 1153 l_test_add("/p2p/build/Association Request IEs 1", 1154 p2p_test_build_association_req, 1155 &p2p_association_req_data_1); 1156 1157 l_test_add("/p2p/parse/Association Response IEs 1", 1158 p2p_test_parse_association_resp, 1159 &p2p_association_resp_data_1); 1160 1161 l_test_add("/p2p/build/Association Response IEs 1", 1162 p2p_test_build_association_resp, 1163 &p2p_association_resp_data_1); 1164 1165 l_test_add("/p2p/parse/Provision Discovery Request 1", 1166 p2p_test_parse_provision_disc_req, 1167 &p2p_provision_disc_req_data_1); 1168 1169 l_test_add("/p2p/build/Provision Discovery Request 1", 1170 p2p_test_build_provision_disc_req, 1171 &p2p_provision_disc_req_data_1); 1172 1173 l_test_add("/p2p/parse/Provision Discovery Response 1", 1174 p2p_test_parse_provision_disc_resp, 1175 &p2p_provision_disc_resp_data_1); 1176 1177 return l_test_run(); 1178 }