p2p_parse.c (252726) | p2p_parse.c (281806) |
---|---|
1/* 2 * P2P - IE parser 3 * Copyright (c) 2009-2010, Atheros Communications 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 --- 254 unchanged lines hidden (view full) --- 263 wpa_printf(MSG_DEBUG, "P2P: Too short Minor Reason " 264 "Code attribute (length %d)", len); 265 return -1; 266 } 267 msg->minor_reason_code = data; 268 wpa_printf(MSG_DEBUG, "P2P: * Minor Reason Code: %u", 269 *msg->minor_reason_code); 270 break; | 1/* 2 * P2P - IE parser 3 * Copyright (c) 2009-2010, Atheros Communications 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 --- 254 unchanged lines hidden (view full) --- 263 wpa_printf(MSG_DEBUG, "P2P: Too short Minor Reason " 264 "Code attribute (length %d)", len); 265 return -1; 266 } 267 msg->minor_reason_code = data; 268 wpa_printf(MSG_DEBUG, "P2P: * Minor Reason Code: %u", 269 *msg->minor_reason_code); 270 break; |
271 case P2P_ATTR_OOB_GO_NEG_CHANNEL: 272 if (len < 6) { 273 wpa_printf(MSG_DEBUG, "P2P: Too short OOB GO Neg " 274 "Channel attribute (length %d)", len); 275 return -1; 276 } 277 msg->oob_go_neg_channel = data; 278 wpa_printf(MSG_DEBUG, "P2P: * OOB GO Neg Channel: " 279 "Country %c%c(0x%02x) Operating Class %d " 280 "Channel Number %d Role %d", 281 data[0], data[1], data[2], data[3], data[4], 282 data[5]); 283 break; 284 case P2P_ATTR_SERVICE_HASH: 285 if (len < P2PS_HASH_LEN) { 286 wpa_printf(MSG_DEBUG, 287 "P2P: Too short Service Hash (length %u)", 288 len); 289 return -1; 290 } 291 msg->service_hash_count = len / P2PS_HASH_LEN; 292 msg->service_hash = data; 293 wpa_hexdump(MSG_DEBUG, "P2P: * Service Hash(s)", data, len); 294 break; 295 case P2P_ATTR_SESSION_INFORMATION_DATA: 296 msg->session_info = data; 297 msg->session_info_len = len; 298 wpa_printf(MSG_DEBUG, "P2P: * Service Instance: %u bytes - %p", 299 len, data); 300 break; 301 case P2P_ATTR_CONNECTION_CAPABILITY: 302 if (len < 1) { 303 wpa_printf(MSG_DEBUG, 304 "P2P: Too short Connection Capability (length %u)", 305 len); 306 return -1; 307 } 308 msg->conn_cap = data; 309 wpa_printf(MSG_DEBUG, "P2P: * Connection Capability: 0x%x", 310 *msg->conn_cap); 311 break; 312 case P2P_ATTR_ADVERTISEMENT_ID: 313 if (len < 10) { 314 wpa_printf(MSG_DEBUG, 315 "P2P: Too short Advertisement ID (length %u)", 316 len); 317 return -1; 318 } 319 msg->adv_id = data; 320 msg->adv_mac = &data[sizeof(u32)]; 321 wpa_printf(MSG_DEBUG, "P2P: * Advertisement ID %x", 322 WPA_GET_LE32(data)); 323 break; 324 case P2P_ATTR_ADVERTISED_SERVICE: 325 if (len < 8) { 326 wpa_printf(MSG_DEBUG, 327 "P2P: Too short Service Instance (length %u)", 328 len); 329 return -1; 330 } 331 msg->adv_service_instance = data; 332 msg->adv_service_instance_len = len; 333 if (len <= 255 + 8) { 334 char str[256]; 335 u8 namelen; 336 337 namelen = data[6]; 338 if (namelen > len - 7) 339 break; 340 os_memcpy(str, &data[7], namelen); 341 str[namelen] = '\0'; 342 wpa_printf(MSG_DEBUG, "P2P: * Service Instance: %x-%s", 343 WPA_GET_LE32(data), str); 344 } else { 345 wpa_printf(MSG_DEBUG, "P2P: * Service Instance: %p", 346 data); 347 } 348 break; 349 case P2P_ATTR_SESSION_ID: 350 if (len < sizeof(u32) + ETH_ALEN) { 351 wpa_printf(MSG_DEBUG, 352 "P2P: Too short Session ID Info (length %u)", 353 len); 354 return -1; 355 } 356 msg->session_id = data; 357 msg->session_mac = &data[sizeof(u32)]; 358 wpa_printf(MSG_DEBUG, "P2P: * Session ID: %x " MACSTR, 359 WPA_GET_LE32(data), MAC2STR(msg->session_mac)); 360 break; 361 case P2P_ATTR_FEATURE_CAPABILITY: 362 if (!len) { 363 wpa_printf(MSG_DEBUG, 364 "P2P: Too short Feature Capability (length %u)", 365 len); 366 return -1; 367 } 368 msg->feature_cap = data; 369 msg->feature_cap_len = len; 370 wpa_printf(MSG_DEBUG, "P2P: * Feature Cap (length=%u)", len); 371 break; 372 case P2P_ATTR_PERSISTENT_GROUP: 373 { 374 if (len < ETH_ALEN) { 375 wpa_printf(MSG_DEBUG, 376 "P2P: Too short Persistent Group Info (length %u)", 377 len); 378 return -1; 379 } 380 381 msg->persistent_dev = data; 382 msg->persistent_ssid_len = len - ETH_ALEN; 383 msg->persistent_ssid = &data[ETH_ALEN]; 384 wpa_printf(MSG_DEBUG, "P2P: * Persistent Group: " MACSTR " %s", 385 MAC2STR(msg->persistent_dev), 386 wpa_ssid_txt(msg->persistent_ssid, 387 msg->persistent_ssid_len)); 388 break; 389 } |
|
271 default: 272 wpa_printf(MSG_DEBUG, "P2P: Skipped unknown attribute %d " 273 "(length %d)", id, len); 274 break; 275 } 276 277 return 0; 278} --- 12 unchanged lines hidden (view full) --- 291{ 292 const u8 *pos = wpabuf_head_u8(buf); 293 const u8 *end = pos + wpabuf_len(buf); 294 295 wpa_printf(MSG_DEBUG, "P2P: Parsing P2P IE"); 296 297 while (pos < end) { 298 u16 attr_len; | 390 default: 391 wpa_printf(MSG_DEBUG, "P2P: Skipped unknown attribute %d " 392 "(length %d)", id, len); 393 break; 394 } 395 396 return 0; 397} --- 12 unchanged lines hidden (view full) --- 410{ 411 const u8 *pos = wpabuf_head_u8(buf); 412 const u8 *end = pos + wpabuf_len(buf); 413 414 wpa_printf(MSG_DEBUG, "P2P: Parsing P2P IE"); 415 416 while (pos < end) { 417 u16 attr_len; |
299 if (pos + 2 >= end) { | 418 u8 id; 419 420 if (end - pos < 3) { |
300 wpa_printf(MSG_DEBUG, "P2P: Invalid P2P attribute"); 301 return -1; 302 } | 421 wpa_printf(MSG_DEBUG, "P2P: Invalid P2P attribute"); 422 return -1; 423 } |
303 attr_len = WPA_GET_LE16(pos + 1); | 424 id = *pos++; 425 attr_len = WPA_GET_LE16(pos); 426 pos += 2; |
304 wpa_printf(MSG_DEBUG, "P2P: Attribute %d length %u", | 427 wpa_printf(MSG_DEBUG, "P2P: Attribute %d length %u", |
305 pos[0], attr_len); 306 if (pos + 3 + attr_len > end) { | 428 id, attr_len); 429 if (attr_len > end - pos) { |
307 wpa_printf(MSG_DEBUG, "P2P: Attribute underflow " 308 "(len=%u left=%d)", | 430 wpa_printf(MSG_DEBUG, "P2P: Attribute underflow " 431 "(len=%u left=%d)", |
309 attr_len, (int) (end - pos - 3)); | 432 attr_len, (int) (end - pos)); |
310 wpa_hexdump(MSG_MSGDUMP, "P2P: Data", pos, end - pos); 311 return -1; 312 } | 433 wpa_hexdump(MSG_MSGDUMP, "P2P: Data", pos, end - pos); 434 return -1; 435 } |
313 if (p2p_parse_attribute(pos[0], pos + 3, attr_len, msg)) | 436 if (p2p_parse_attribute(id, pos, attr_len, msg)) |
314 return -1; | 437 return -1; |
315 pos += 3 + attr_len; | 438 pos += attr_len; |
316 } 317 318 return 0; 319} 320 321 322static int p2p_parse_wps_ie(const struct wpabuf *buf, struct p2p_message *msg) 323{ --- 11 unchanged lines hidden (view full) --- 335 WPA_GET_BE16(attr.config_methods); 336 wpa_printf(MSG_DEBUG, "P2P: Config Methods (WPS): 0x%x", 337 msg->wps_config_methods); 338 } 339 if (attr.dev_password_id) { 340 msg->dev_password_id = WPA_GET_BE16(attr.dev_password_id); 341 wpa_printf(MSG_DEBUG, "P2P: Device Password ID: %d", 342 msg->dev_password_id); | 439 } 440 441 return 0; 442} 443 444 445static int p2p_parse_wps_ie(const struct wpabuf *buf, struct p2p_message *msg) 446{ --- 11 unchanged lines hidden (view full) --- 458 WPA_GET_BE16(attr.config_methods); 459 wpa_printf(MSG_DEBUG, "P2P: Config Methods (WPS): 0x%x", 460 msg->wps_config_methods); 461 } 462 if (attr.dev_password_id) { 463 msg->dev_password_id = WPA_GET_BE16(attr.dev_password_id); 464 wpa_printf(MSG_DEBUG, "P2P: Device Password ID: %d", 465 msg->dev_password_id); |
466 msg->dev_password_id_present = 1; |
|
343 } 344 if (attr.primary_dev_type) { 345 char devtype[WPS_DEV_TYPE_BUFSIZE]; 346 msg->wps_pri_dev_type = attr.primary_dev_type; 347 wpa_printf(MSG_DEBUG, "P2P: Primary Device Type (WPS): %s", 348 wps_dev_type_bin2str(msg->wps_pri_dev_type, devtype, 349 sizeof(devtype))); 350 } --- 11 unchanged lines hidden (view full) --- 362 msg->manufacturer_len = attr.manufacturer_len; 363 msg->model_name = attr.model_name; 364 msg->model_name_len = attr.model_name_len; 365 msg->model_number = attr.model_number; 366 msg->model_number_len = attr.model_number_len; 367 msg->serial_number = attr.serial_number; 368 msg->serial_number_len = attr.serial_number_len; 369 | 467 } 468 if (attr.primary_dev_type) { 469 char devtype[WPS_DEV_TYPE_BUFSIZE]; 470 msg->wps_pri_dev_type = attr.primary_dev_type; 471 wpa_printf(MSG_DEBUG, "P2P: Primary Device Type (WPS): %s", 472 wps_dev_type_bin2str(msg->wps_pri_dev_type, devtype, 473 sizeof(devtype))); 474 } --- 11 unchanged lines hidden (view full) --- 486 msg->manufacturer_len = attr.manufacturer_len; 487 msg->model_name = attr.model_name; 488 msg->model_name_len = attr.model_name_len; 489 msg->model_number = attr.model_number; 490 msg->model_number_len = attr.model_number_len; 491 msg->serial_number = attr.serial_number; 492 msg->serial_number_len = attr.serial_number_len; 493 |
494 msg->oob_dev_password = attr.oob_dev_password; 495 msg->oob_dev_password_len = attr.oob_dev_password_len; 496 |
|
370 return 0; 371} 372 373 374/** 375 * p2p_parse_ies - Parse P2P message IEs (both WPS and P2P IE) 376 * @data: IEs from the message 377 * @len: Length of data buffer in octets --- 67 unchanged lines hidden (view full) --- 445 } 446 msg->dialog_token = data[0]; 447 wpa_printf(MSG_DEBUG, "P2P: * Dialog Token: %d", msg->dialog_token); 448 449 return p2p_parse_ies(data + 1, len - 1, msg); 450} 451 452 | 497 return 0; 498} 499 500 501/** 502 * p2p_parse_ies - Parse P2P message IEs (both WPS and P2P IE) 503 * @data: IEs from the message 504 * @len: Length of data buffer in octets --- 67 unchanged lines hidden (view full) --- 572 } 573 msg->dialog_token = data[0]; 574 wpa_printf(MSG_DEBUG, "P2P: * Dialog Token: %d", msg->dialog_token); 575 576 return p2p_parse_ies(data + 1, len - 1, msg); 577} 578 579 |
580int p2p_parse_ies_separate(const u8 *wsc, size_t wsc_len, const u8 *p2p, 581 size_t p2p_len, struct p2p_message *msg) 582{ 583 os_memset(msg, 0, sizeof(*msg)); 584 585 msg->wps_attributes = wpabuf_alloc_copy(wsc, wsc_len); 586 if (msg->wps_attributes && 587 p2p_parse_wps_ie(msg->wps_attributes, msg)) { 588 p2p_parse_free(msg); 589 return -1; 590 } 591 592 msg->p2p_attributes = wpabuf_alloc_copy(p2p, p2p_len); 593 if (msg->p2p_attributes && 594 p2p_parse_p2p_ie(msg->p2p_attributes, msg)) { 595 wpa_printf(MSG_DEBUG, "P2P: Failed to parse P2P IE data"); 596 if (msg->p2p_attributes) 597 wpa_hexdump_buf(MSG_MSGDUMP, "P2P: P2P IE data", 598 msg->p2p_attributes); 599 p2p_parse_free(msg); 600 return -1; 601 } 602 603 return 0; 604} 605 606 |
|
453/** 454 * p2p_parse_free - Free temporary data from P2P parsing 455 * @msg: Parsed attributes 456 */ 457void p2p_parse_free(struct p2p_message *msg) 458{ 459 wpabuf_free(msg->p2p_attributes); 460 msg->p2p_attributes = NULL; --- 93 unchanged lines hidden (view full) --- 554 u8 s; 555 int count; 556 557 cli = &info.client[i]; 558 ret = os_snprintf(pos, end - pos, "p2p_group_client: " 559 "dev=" MACSTR " iface=" MACSTR, 560 MAC2STR(cli->p2p_device_addr), 561 MAC2STR(cli->p2p_interface_addr)); | 607/** 608 * p2p_parse_free - Free temporary data from P2P parsing 609 * @msg: Parsed attributes 610 */ 611void p2p_parse_free(struct p2p_message *msg) 612{ 613 wpabuf_free(msg->p2p_attributes); 614 msg->p2p_attributes = NULL; --- 93 unchanged lines hidden (view full) --- 708 u8 s; 709 int count; 710 711 cli = &info.client[i]; 712 ret = os_snprintf(pos, end - pos, "p2p_group_client: " 713 "dev=" MACSTR " iface=" MACSTR, 714 MAC2STR(cli->p2p_device_addr), 715 MAC2STR(cli->p2p_interface_addr)); |
562 if (ret < 0 || ret >= end - pos) | 716 if (os_snprintf_error(end - pos, ret)) |
563 return pos - buf; 564 pos += ret; 565 566 ret = os_snprintf(pos, end - pos, 567 " dev_capab=0x%x config_methods=0x%x " 568 "dev_type=%s", 569 cli->dev_capab, cli->config_methods, 570 wps_dev_type_bin2str(cli->pri_dev_type, 571 devtype, 572 sizeof(devtype))); | 717 return pos - buf; 718 pos += ret; 719 720 ret = os_snprintf(pos, end - pos, 721 " dev_capab=0x%x config_methods=0x%x " 722 "dev_type=%s", 723 cli->dev_capab, cli->config_methods, 724 wps_dev_type_bin2str(cli->pri_dev_type, 725 devtype, 726 sizeof(devtype))); |
573 if (ret < 0 || ret >= end - pos) | 727 if (os_snprintf_error(end - pos, ret)) |
574 return pos - buf; 575 pos += ret; 576 577 for (s = 0; s < cli->num_sec_dev_types; s++) { 578 ret = os_snprintf(pos, end - pos, " dev_type=%s", 579 wps_dev_type_bin2str( 580 &cli->sec_dev_types[s * 8], 581 devtype, sizeof(devtype))); | 728 return pos - buf; 729 pos += ret; 730 731 for (s = 0; s < cli->num_sec_dev_types; s++) { 732 ret = os_snprintf(pos, end - pos, " dev_type=%s", 733 wps_dev_type_bin2str( 734 &cli->sec_dev_types[s * 8], 735 devtype, sizeof(devtype))); |
582 if (ret < 0 || ret >= end - pos) | 736 if (os_snprintf_error(end - pos, ret)) |
583 return pos - buf; 584 pos += ret; 585 } 586 587 os_memcpy(name, cli->dev_name, cli->dev_name_len); 588 name[cli->dev_name_len] = '\0'; 589 count = (int) cli->dev_name_len - 1; 590 while (count >= 0) { 591 if (name[count] > 0 && name[count] < 32) 592 name[count] = '_'; 593 count--; 594 } 595 596 ret = os_snprintf(pos, end - pos, " dev_name='%s'\n", name); | 737 return pos - buf; 738 pos += ret; 739 } 740 741 os_memcpy(name, cli->dev_name, cli->dev_name_len); 742 name[cli->dev_name_len] = '\0'; 743 count = (int) cli->dev_name_len - 1; 744 while (count >= 0) { 745 if (name[count] > 0 && name[count] < 32) 746 name[count] = '_'; 747 count--; 748 } 749 750 ret = os_snprintf(pos, end - pos, " dev_name='%s'\n", name); |
597 if (ret < 0 || ret >= end - pos) | 751 if (os_snprintf_error(end - pos, ret)) |
598 return pos - buf; 599 pos += ret; 600 } 601 602 return pos - buf; 603} 604 605 --- 17 unchanged lines hidden (view full) --- 623 if (p2p_parse_p2p_ie(data, &msg)) 624 return -1; 625 626 if (msg.capability) { 627 ret = os_snprintf(pos, end - pos, 628 "p2p_dev_capab=0x%x\n" 629 "p2p_group_capab=0x%x\n", 630 msg.capability[0], msg.capability[1]); | 752 return pos - buf; 753 pos += ret; 754 } 755 756 return pos - buf; 757} 758 759 --- 17 unchanged lines hidden (view full) --- 777 if (p2p_parse_p2p_ie(data, &msg)) 778 return -1; 779 780 if (msg.capability) { 781 ret = os_snprintf(pos, end - pos, 782 "p2p_dev_capab=0x%x\n" 783 "p2p_group_capab=0x%x\n", 784 msg.capability[0], msg.capability[1]); |
631 if (ret < 0 || ret >= end - pos) | 785 if (os_snprintf_error(end - pos, ret)) |
632 return pos - buf; 633 pos += ret; 634 } 635 636 if (msg.pri_dev_type) { 637 char devtype[WPS_DEV_TYPE_BUFSIZE]; 638 ret = os_snprintf(pos, end - pos, 639 "p2p_primary_device_type=%s\n", 640 wps_dev_type_bin2str(msg.pri_dev_type, 641 devtype, 642 sizeof(devtype))); | 786 return pos - buf; 787 pos += ret; 788 } 789 790 if (msg.pri_dev_type) { 791 char devtype[WPS_DEV_TYPE_BUFSIZE]; 792 ret = os_snprintf(pos, end - pos, 793 "p2p_primary_device_type=%s\n", 794 wps_dev_type_bin2str(msg.pri_dev_type, 795 devtype, 796 sizeof(devtype))); |
643 if (ret < 0 || ret >= end - pos) | 797 if (os_snprintf_error(end - pos, ret)) |
644 return pos - buf; 645 pos += ret; 646 } 647 648 ret = os_snprintf(pos, end - pos, "p2p_device_name=%s\n", 649 msg.device_name); | 798 return pos - buf; 799 pos += ret; 800 } 801 802 ret = os_snprintf(pos, end - pos, "p2p_device_name=%s\n", 803 msg.device_name); |
650 if (ret < 0 || ret >= end - pos) | 804 if (os_snprintf_error(end - pos, ret)) |
651 return pos - buf; 652 pos += ret; 653 654 if (msg.p2p_device_addr) { 655 ret = os_snprintf(pos, end - pos, "p2p_device_addr=" MACSTR 656 "\n", 657 MAC2STR(msg.p2p_device_addr)); | 805 return pos - buf; 806 pos += ret; 807 808 if (msg.p2p_device_addr) { 809 ret = os_snprintf(pos, end - pos, "p2p_device_addr=" MACSTR 810 "\n", 811 MAC2STR(msg.p2p_device_addr)); |
658 if (ret < 0 || ret >= end - pos) | 812 if (os_snprintf_error(end - pos, ret)) |
659 return pos - buf; 660 pos += ret; 661 } 662 663 ret = os_snprintf(pos, end - pos, "p2p_config_methods=0x%x\n", 664 msg.config_methods); | 813 return pos - buf; 814 pos += ret; 815 } 816 817 ret = os_snprintf(pos, end - pos, "p2p_config_methods=0x%x\n", 818 msg.config_methods); |
665 if (ret < 0 || ret >= end - pos) | 819 if (os_snprintf_error(end - pos, ret)) |
666 return pos - buf; 667 pos += ret; 668 669 ret = p2p_group_info_text(msg.group_info, msg.group_info_len, 670 pos, end); 671 if (ret < 0) 672 return pos - buf; 673 pos += ret; --- 50 unchanged lines hidden --- | 820 return pos - buf; 821 pos += ret; 822 823 ret = p2p_group_info_text(msg.group_info, msg.group_info_len, 824 pos, end); 825 if (ret < 0) 826 return pos - buf; 827 pos += ret; --- 50 unchanged lines hidden --- |