1 /* 2 * P2P - Internal definitions for P2P module 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 9 #ifndef P2P_I_H 10 #define P2P_I_H 11 12 #include "utils/list.h" 13 #include "drivers/driver.h" 14 #include "p2p.h" 15 16 #define P2P_GO_NEG_CNF_MAX_RETRY_COUNT 1 17 18 /* 19 * A threshold (in seconds) to prefer a direct Probe Response frame from a P2P 20 * Device over the P2P Client Info received from a GO. 21 */ 22 #define P2P_DEV_GROUP_CLIENT_RESP_THRESHOLD 1 23 24 enum p2p_role_indication; 25 26 /* 27 * To force Service Instances to fit within a single P2P Tag, MAX_SVC_ADV_LEN 28 * must equal 248 or less. Must have a minimum size of 19. 29 */ 30 #define MAX_SVC_ADV_LEN 600 31 #define MAX_SVC_ADV_IE_LEN (9 + MAX_SVC_ADV_LEN + (5 * (MAX_SVC_ADV_LEN / 240))) 32 33 enum p2p_go_state { 34 UNKNOWN_GO, 35 LOCAL_GO, 36 REMOTE_GO 37 }; 38 39 /* Enumeration for P2P device current role */ 40 enum p2p_role { 41 P2P_ROLE_IDLE = 0, 42 P2P_ROLE_PAIRING_INITIATOR, 43 P2P_ROLE_PAIRING_RESPONDER, 44 }; 45 46 /** 47 * struct bootstrap_params - P2P Device bootstrap request parameters 48 */ 49 struct p2p_bootstrap_params { 50 /* Bootstrap method */ 51 u16 bootstrap_method; 52 53 /* Status code */ 54 enum p2p_status_code status; 55 56 /* Cookie for comeback */ 57 u8 cookie[50]; 58 59 /* Cookie length */ 60 size_t cookie_len; 61 62 /* Comeback time in TUs after which receiver is requested to retry */ 63 int comeback_after; 64 }; 65 66 /** 67 * struct p2p_device - P2P Device data (internal to P2P module) 68 */ 69 struct p2p_device { 70 struct dl_list list; 71 struct os_reltime last_seen; 72 int listen_freq; 73 int oob_go_neg_freq; 74 enum p2p_wps_method wps_method; 75 u16 oob_pw_id; 76 77 struct p2p_peer_info info; 78 79 /* 80 * If the peer was discovered based on an interface address (e.g., GO 81 * from Beacon/Probe Response), the interface address is stored here. 82 * p2p_device_addr must still be set in such a case to the unique 83 * identifier for the P2P Device. 84 * 85 * This field is also used during P2PS PD to store the intended GO 86 * address of the peer. 87 */ 88 u8 interface_addr[ETH_ALEN]; 89 90 /* 91 * P2P Device Address of the GO in whose group this P2P Device is a 92 * client. 93 */ 94 u8 member_in_go_dev[ETH_ALEN]; 95 96 /* 97 * P2P Interface Address of the GO in whose group this P2P Device is a 98 * client. 99 */ 100 u8 member_in_go_iface[ETH_ALEN]; 101 102 int go_neg_req_sent; 103 enum p2p_go_state go_state; 104 u8 dialog_token; 105 u8 tie_breaker; 106 u8 intended_addr[ETH_ALEN]; 107 108 char country[3]; 109 struct p2p_channels channels; 110 int oper_freq; 111 u8 oper_ssid[SSID_MAX_LEN]; 112 size_t oper_ssid_len; 113 114 /** 115 * req_config_methods - Pending provision discovery methods 116 */ 117 u16 req_config_methods; 118 119 /** 120 * wps_prov_info - Stored provisioning WPS config method 121 * 122 * This is used to store pending WPS config method between Provisioning 123 * Discovery and connection to a running group. 124 */ 125 u16 wps_prov_info; 126 127 #define P2P_DEV_PROBE_REQ_ONLY BIT(0) 128 #define P2P_DEV_REPORTED BIT(1) 129 #define P2P_DEV_NOT_YET_READY BIT(2) 130 #define P2P_DEV_PD_PEER_DISPLAY BIT(5) 131 #define P2P_DEV_PD_PEER_KEYPAD BIT(6) 132 #define P2P_DEV_USER_REJECTED BIT(7) 133 #define P2P_DEV_PEER_WAITING_RESPONSE BIT(8) 134 #define P2P_DEV_PREFER_PERSISTENT_GROUP BIT(9) 135 #define P2P_DEV_WAIT_GO_NEG_RESPONSE BIT(10) 136 #define P2P_DEV_WAIT_GO_NEG_CONFIRM BIT(11) 137 #define P2P_DEV_GROUP_CLIENT_ONLY BIT(12) 138 #define P2P_DEV_FORCE_FREQ BIT(13) 139 #define P2P_DEV_PD_FOR_JOIN BIT(14) 140 #define P2P_DEV_REPORTED_ONCE BIT(15) 141 #define P2P_DEV_PREFER_PERSISTENT_RECONN BIT(16) 142 #define P2P_DEV_PD_BEFORE_GO_NEG BIT(17) 143 #define P2P_DEV_NO_PREF_CHAN BIT(18) 144 #define P2P_DEV_WAIT_INV_REQ_ACK BIT(19) 145 #define P2P_DEV_P2PS_REPORTED BIT(20) 146 #define P2P_DEV_PD_PEER_P2PS BIT(21) 147 #define P2P_DEV_LAST_SEEN_AS_GROUP_CLIENT BIT(22) 148 149 unsigned int flags; 150 151 int status; /* enum p2p_status_code */ 152 unsigned int wait_count; 153 unsigned int connect_reqs; 154 unsigned int invitation_reqs; 155 unsigned int sd_reqs; 156 157 u16 ext_listen_period; 158 u16 ext_listen_interval; 159 160 u8 go_timeout; 161 u8 client_timeout; 162 163 /** 164 * go_neg_conf_sent - Number of GO Negotiation Confirmation retries 165 */ 166 u8 go_neg_conf_sent; 167 168 /** 169 * freq - Frquency on which the GO Negotiation Confirmation is sent 170 */ 171 int go_neg_conf_freq; 172 173 /** 174 * go_neg_conf - GO Negotiation Confirmation frame 175 */ 176 struct wpabuf *go_neg_conf; 177 178 int sd_pending_bcast_queries; 179 bool support_6ghz; 180 181 /* Supports P2P2 */ 182 bool p2p2; 183 184 /* Requested bootstrap method */ 185 u16 req_bootstrap_method; 186 187 /* Bootstrap parameters received from peer */ 188 struct p2p_bootstrap_params *bootstrap_params; 189 190 /* Password for P2P2 GO negotiation */ 191 char password[100]; 192 193 /* PASN data structure */ 194 struct pasn_data *pasn; 195 struct wpabuf *action_frame_wrapper; 196 197 /* Device role */ 198 enum p2p_role role; 199 200 /* Invitation parameters for P2P2 */ 201 bool inv_reject; 202 u8 inv_status; 203 int inv_freq; 204 int inv_peer_oper_freq; 205 u8 inv_bssid[ETH_ALEN]; 206 u8 inv_ssid[SSID_MAX_LEN]; 207 size_t inv_ssid_len; 208 bool inv_all_channels; 209 }; 210 211 struct p2p_sd_query { 212 struct p2p_sd_query *next; 213 u8 peer[ETH_ALEN]; 214 int for_all_peers; 215 int wsd; /* Wi-Fi Display Service Discovery Request */ 216 struct wpabuf *tlvs; 217 }; 218 219 /* P2P Device Identity Key parameters */ 220 struct p2p_id_key { 221 /* AKMP used for DevIK derviation */ 222 int akmp; 223 /* Cipher version type */ 224 int cipher_version; 225 /* DevIK expiration time in hours */ 226 u32 expiration; 227 /* Buffer to hold the DevIK */ 228 u8 dik_data[DEVICE_IDENTITY_KEY_MAX_LEN]; 229 /* Length of DevIK */ 230 size_t dik_len; 231 /* Nonce used in DIRA attribute */ 232 u8 dira_nonce[DEVICE_IDENTITY_NONCE_LEN]; 233 /* Length of nonce */ 234 size_t dira_nonce_len; 235 /* Tag computed for nonce using NIK */ 236 u8 dira_tag[DEVICE_IDENTITY_TAG_LEN]; 237 /* Length of tag in octets */ 238 size_t dira_tag_len; 239 }; 240 241 struct p2p_pairing_info { 242 /* P2P device own address */ 243 u8 own_addr[ETH_ALEN]; 244 /* device capability to enable pairing setup */ 245 bool enable_pairing_setup; 246 /* device capability to enable pairing cache */ 247 bool enable_pairing_cache; 248 /* device supported bootstrapping */ 249 u16 supported_bootstrap; 250 /* P2P Device Identity Key info */ 251 struct p2p_id_key dev_ik; 252 }; 253 254 /** 255 * struct p2p_data - P2P module data (internal to P2P module) 256 */ 257 struct p2p_data { 258 /** 259 * cfg - P2P module configuration 260 * 261 * This is included in the same memory allocation with the 262 * struct p2p_data and as such, must not be freed separately. 263 */ 264 struct p2p_config *cfg; 265 266 /** 267 * state - The current P2P state 268 */ 269 enum p2p_state { 270 /** 271 * P2P_IDLE - Idle 272 */ 273 P2P_IDLE, 274 275 /** 276 * P2P_SEARCH - Search (Device Discovery) 277 */ 278 P2P_SEARCH, 279 280 /** 281 * P2P_CONNECT - Trying to start GO Negotiation 282 */ 283 P2P_CONNECT, 284 285 /** 286 * P2P_CONNECT_LISTEN - Listen during GO Negotiation start 287 */ 288 P2P_CONNECT_LISTEN, 289 290 /** 291 * P2P_GO_NEG - In GO Negotiation 292 */ 293 P2P_GO_NEG, 294 295 /** 296 * P2P_LISTEN_ONLY - Listen only 297 */ 298 P2P_LISTEN_ONLY, 299 300 /** 301 * P2P_WAIT_PEER_CONNECT - Waiting peer in List for GO Neg 302 */ 303 P2P_WAIT_PEER_CONNECT, 304 305 /** 306 * P2P_WAIT_PEER_IDLE - Waiting peer idle for GO Neg 307 */ 308 P2P_WAIT_PEER_IDLE, 309 310 /** 311 * P2P_SD_DURING_FIND - Service Discovery during find 312 */ 313 P2P_SD_DURING_FIND, 314 315 /** 316 * P2P_PROVISIONING - Provisioning (during group formation) 317 */ 318 P2P_PROVISIONING, 319 320 /** 321 * P2P_PD_DURING_FIND - Provision Discovery during find 322 */ 323 P2P_PD_DURING_FIND, 324 325 /** 326 * P2P_INVITE - Trying to start Invite 327 */ 328 P2P_INVITE, 329 330 /** 331 * P2P_INVITE_LISTEN - Listen during Invite 332 */ 333 P2P_INVITE_LISTEN, 334 } state; 335 336 /** 337 * min_disc_int - minDiscoverableInterval 338 */ 339 int min_disc_int; 340 341 /** 342 * max_disc_int - maxDiscoverableInterval 343 */ 344 int max_disc_int; 345 346 /** 347 * max_disc_tu - Maximum number of TUs for discoverable interval 348 */ 349 int max_disc_tu; 350 351 /** 352 * devices - List of known P2P Device peers 353 */ 354 struct dl_list devices; 355 356 /** 357 * go_neg_peer - Pointer to GO Negotiation peer 358 */ 359 struct p2p_device *go_neg_peer; 360 361 /** 362 * invite_peer - Pointer to Invite peer 363 */ 364 struct p2p_device *invite_peer; 365 366 /** 367 * last_p2p_find_oper - Pointer to last pre-find operation peer 368 */ 369 struct p2p_device *last_p2p_find_oper; 370 371 const u8 *invite_go_dev_addr; 372 u8 invite_go_dev_addr_buf[ETH_ALEN]; 373 int invite_dev_pw_id; 374 375 unsigned int retry_invite_req:1; 376 unsigned int retry_invite_req_sent:1; 377 378 /** 379 * sd_peer - Pointer to Service Discovery peer 380 */ 381 struct p2p_device *sd_peer; 382 383 /** 384 * sd_query - Pointer to Service Discovery query 385 */ 386 struct p2p_sd_query *sd_query; 387 388 /** 389 * num_p2p_sd_queries - Total number of broadcast SD queries present in 390 * the list 391 */ 392 int num_p2p_sd_queries; 393 394 /** 395 * sd_query_no_ack - The first peer (Dev Addr) that did not ACK SD Query 396 * 397 * This is used to track the first peer that did not ACK an SD Query 398 * within a single P2P Search iteration. All zeros address means no such 399 * peer was yet seen. This information is used to allow a new Listen and 400 * Search phases to be once every pending SD Query has been sent once to 401 * each peer instead of looping all pending attempts continuously until 402 * running out of retry maximums. 403 */ 404 u8 sd_query_no_ack[ETH_ALEN]; 405 406 /* GO Negotiation data */ 407 408 /** 409 * intended_addr - Local Intended P2P Interface Address 410 * 411 * This address is used during group owner negotiation as the Intended 412 * P2P Interface Address and the group interface will be created with 413 * address as the local address in case of successfully completed 414 * negotiation. 415 */ 416 u8 intended_addr[ETH_ALEN]; 417 418 /** 419 * go_intent - Local GO Intent to be used during GO Negotiation 420 */ 421 u8 go_intent; 422 423 /** 424 * next_tie_breaker - Next tie-breaker value to use in GO Negotiation 425 */ 426 u8 next_tie_breaker; 427 428 /** 429 * ssid - Selected SSID for GO Negotiation (if local end will be GO) 430 */ 431 u8 ssid[SSID_MAX_LEN]; 432 433 /** 434 * ssid_len - ssid length in octets 435 */ 436 size_t ssid_len; 437 438 /** 439 * ssid_set - Whether SSID is already set for GO Negotiation 440 */ 441 int ssid_set; 442 443 /** 444 * Regulatory class for own operational channel 445 */ 446 u8 op_reg_class; 447 448 /** 449 * op_channel - Own operational channel 450 */ 451 u8 op_channel; 452 453 /** 454 * channels - Own supported regulatory classes and channels 455 * 456 * List of supposerted channels per regulatory class. The regulatory 457 * classes are defined in IEEE Std 802.11-2007 Annex J and the 458 * numbering of the clases depends on the configured country code. 459 */ 460 struct p2p_channels channels; 461 462 struct wpa_freq_range_list no_go_freq; 463 464 enum p2p_pending_action_state { 465 P2P_NO_PENDING_ACTION, 466 P2P_PENDING_GO_NEG_REQUEST, 467 P2P_PENDING_GO_NEG_RESPONSE, 468 P2P_PENDING_GO_NEG_RESPONSE_FAILURE, 469 P2P_PENDING_GO_NEG_CONFIRM, 470 P2P_PENDING_SD, 471 P2P_PENDING_PD, 472 P2P_PENDING_PD_RESPONSE, 473 P2P_PENDING_INVITATION_REQUEST, 474 P2P_PENDING_INVITATION_RESPONSE, 475 P2P_PENDING_DEV_DISC_REQUEST, 476 P2P_PENDING_DEV_DISC_RESPONSE, 477 P2P_PENDING_GO_DISC_REQ 478 } pending_action_state; 479 480 unsigned int pending_listen_freq; 481 unsigned int pending_listen_sec; 482 unsigned int pending_listen_usec; 483 bool pending_listen_wait_drv; 484 485 u8 dev_capab; 486 487 int in_listen; 488 int drv_in_listen; 489 490 /** 491 * sd_queries - Pending service discovery queries 492 */ 493 struct p2p_sd_query *sd_queries; 494 495 /** 496 * srv_update_indic - Service Update Indicator for local services 497 */ 498 u16 srv_update_indic; 499 500 struct wpabuf *sd_resp; /* Fragmented SD response */ 501 u8 sd_resp_addr[ETH_ALEN]; 502 u8 sd_resp_dialog_token; 503 size_t sd_resp_pos; /* Offset in sd_resp */ 504 u8 sd_frag_id; 505 506 struct wpabuf *sd_rx_resp; /* Reassembled SD response */ 507 u16 sd_rx_update_indic; 508 509 /* P2P Invitation data */ 510 enum p2p_invite_role inv_role; 511 u8 inv_bssid[ETH_ALEN]; 512 int inv_bssid_set; 513 u8 inv_ssid[SSID_MAX_LEN]; 514 size_t inv_ssid_len; 515 u8 inv_sa[ETH_ALEN]; 516 u8 inv_group_bssid[ETH_ALEN]; 517 u8 *inv_group_bssid_ptr; 518 u8 inv_go_dev_addr[ETH_ALEN]; 519 u8 inv_status; 520 int inv_op_freq; 521 int inv_persistent; 522 523 enum p2p_discovery_type find_type; 524 int find_specified_freq; 525 unsigned int last_p2p_find_timeout; 526 u8 last_prog_scan_class; 527 u8 last_prog_scan_chan; 528 unsigned int find_pending_full:1; 529 int p2p_scan_running; 530 enum p2p_after_scan { 531 P2P_AFTER_SCAN_NOTHING, 532 P2P_AFTER_SCAN_LISTEN, 533 P2P_AFTER_SCAN_CONNECT 534 } start_after_scan; 535 u8 after_scan_peer[ETH_ALEN]; 536 unsigned int send_action_in_progress:1; 537 538 /* Requested device types for find/search */ 539 unsigned int num_req_dev_types; 540 u8 *req_dev_types; 541 u8 *find_dev_id; 542 u8 find_dev_id_buf[ETH_ALEN]; 543 544 struct os_reltime find_start; /* time of last p2p_find start */ 545 546 struct p2p_group **groups; 547 size_t num_groups; 548 549 struct p2p_device *pending_client_disc_go; 550 u8 pending_client_disc_addr[ETH_ALEN]; 551 u8 pending_dev_disc_dialog_token; 552 u8 pending_dev_disc_addr[ETH_ALEN]; 553 int pending_dev_disc_freq; 554 unsigned int pending_client_disc_freq; 555 556 int ext_listen_only; 557 unsigned int ext_listen_period; 558 unsigned int ext_listen_interval; 559 unsigned int ext_listen_interval_sec; 560 unsigned int ext_listen_interval_usec; 561 562 u8 peer_filter[ETH_ALEN]; 563 564 int cross_connect; 565 566 int best_freq_24; 567 int best_freq_5; 568 int best_freq_overall; 569 int own_freq_preference; 570 571 /** 572 * wps_vendor_ext - WPS Vendor Extensions to add 573 */ 574 struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT]; 575 576 /* 577 * user_initiated_pd - Whether a PD request is user initiated or not. 578 */ 579 u8 user_initiated_pd; 580 581 /* 582 * Keep track of which peer a given PD request was sent to. 583 * Used to raise a timeout alert in case there is no response. 584 */ 585 u8 pending_pd_devaddr[ETH_ALEN]; 586 587 /* 588 * Retry counter for provision discovery requests when issued 589 * in IDLE state. 590 */ 591 int pd_retries; 592 593 /** 594 * pd_force_freq - Forced frequency for PD retries or 0 to auto-select 595 * 596 * This is is used during PD retries for join-a-group case to use the 597 * correct operating frequency determined from a BSS entry for the GO. 598 */ 599 int pd_force_freq; 600 601 u8 go_timeout; 602 u8 client_timeout; 603 604 /* Extra delay in milliseconds between search iterations */ 605 unsigned int search_delay; 606 int in_search_delay; 607 608 u8 pending_reg_class; 609 u8 pending_channel; 610 u8 pending_channel_forced; 611 612 /* ASP Support */ 613 struct p2ps_advertisement *p2ps_adv_list; 614 struct p2ps_provision *p2ps_prov; 615 u8 wild_card_hash[P2PS_HASH_LEN]; 616 u8 p2ps_seek; 617 u8 p2ps_seek_hash[P2P_MAX_QUERY_HASH * P2PS_HASH_LEN]; 618 u8 p2ps_seek_count; 619 620 #ifdef CONFIG_WIFI_DISPLAY 621 struct wpabuf *wfd_ie_beacon; 622 struct wpabuf *wfd_ie_probe_req; 623 struct wpabuf *wfd_ie_probe_resp; 624 struct wpabuf *wfd_ie_assoc_req; 625 struct wpabuf *wfd_ie_invitation; 626 struct wpabuf *wfd_ie_prov_disc_req; 627 struct wpabuf *wfd_ie_prov_disc_resp; 628 struct wpabuf *wfd_ie_go_neg; 629 struct wpabuf *wfd_dev_info; 630 struct wpabuf *wfd_assoc_bssid; 631 struct wpabuf *wfd_coupled_sink_info; 632 struct wpabuf *wfd_r2_dev_info; 633 #endif /* CONFIG_WIFI_DISPLAY */ 634 635 u16 authorized_oob_dev_pw_id; 636 637 struct wpabuf **vendor_elem; 638 639 struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; 640 unsigned int num_pref_freq; 641 642 /* Override option for preferred operating channel in GO Negotiation */ 643 u8 override_pref_op_class; 644 u8 override_pref_channel; 645 bool p2p_6ghz_capable; 646 bool include_6ghz; 647 bool allow_6ghz; 648 649 struct p2p_pairing_info *pairing_info; 650 651 /* Pairing initiator PMKSA cache */ 652 struct rsn_pmksa_cache *initiator_pmksa; 653 /* Pairing responder PMKSA cache */ 654 struct rsn_pmksa_cache *responder_pmksa; 655 656 /* DevIK variables: Cipher version, DevIK, and its lifetime 657 * These are fetched from the P2P2 included in the PASN Encrypted Data 658 * element during P2P2 group negotiation with PASN Authentication 659 * frames. These values are stored in struct p2p_data for an ongoing GO 660 * negotiation or join-a-group operation with the assumption that these 661 * operations cannot happen in parallel with multiple peers. After 662 * successful group formation and connection, these are moved to 663 * wpa_supplicant configuration if the connection is persistent. */ 664 u8 dik_cipher_version; 665 u8 peer_dik_data[DEVICE_IDENTITY_KEY_MAX_LEN]; 666 size_t peer_dik_len; 667 unsigned int peer_dik_lifetime; 668 669 /* Password used during an ongoing group formation after opportunistic 670 * PASN authentication or while joining an existing group. This will be 671 * moved to a more permanent location from struct p2p_data at the 672 * conclusion of a successful pairing. */ 673 char dev_sae_password[100]; 674 char peer_sae_password[100]; 675 676 /* Variable used to know the role of the device in a given instance. 677 * go_role variable is set while authorizing a P2P Client for PASN 678 * authentication with predefined GO intent value for GO (15 for 679 * P2P-GO). Once the authentication is completed and security 680 * configuration is done, this variable is reset to false. 681 */ 682 bool go_role; 683 684 #ifdef CONFIG_TESTING_OPTIONS 685 /** 686 * PASN PTK of recent auth 687 */ 688 u8 pasn_ptk[128]; 689 690 /** 691 * PASN PTK length 692 */ 693 size_t pasn_ptk_len; 694 #endif /* CONFIG_TESTING_OPTIONS */ 695 696 bool usd_service; 697 u8 p2p_service_hash[P2PS_HASH_LEN]; 698 699 /** 700 * dfs_ap_connected - Whether STA is connected to a DFS AP 701 */ 702 bool dfs_ap_connected; 703 704 /** 705 * sta_connected_freq - STA connection frequency 706 * 707 * Valid only when dfs_ap_connected is true. 708 */ 709 int sta_connected_freq; 710 711 /** 712 * sta_connected_chan_width - STA connection channel width 713 * 714 * Valid only when dfs_ap_connected is true. 715 */ 716 enum chan_width sta_connected_chan_width; 717 }; 718 719 /** 720 * struct p2p_message - Parsed P2P message (or P2P IE) 721 */ 722 struct p2p_message { 723 struct wpabuf *p2p_attributes; 724 struct wpabuf *p2p2_attributes; 725 struct wpabuf *wps_attributes; 726 struct wpabuf *wfd_subelems; 727 728 u8 dialog_token; 729 730 const u8 *capability; 731 const u8 *go_intent; 732 const u8 *status; 733 const u8 *listen_channel; 734 const u8 *operating_channel; 735 const u8 *channel_list; 736 u8 channel_list_len; 737 const u8 *config_timeout; 738 const u8 *intended_addr; 739 const u8 *group_bssid; 740 const u8 *invitation_flags; 741 742 const u8 *group_info; 743 size_t group_info_len; 744 745 const u8 *group_id; 746 size_t group_id_len; 747 748 const u8 *device_id; 749 750 const u8 *manageability; 751 752 const u8 *noa; 753 size_t noa_len; 754 755 const u8 *ext_listen_timing; 756 757 const u8 *minor_reason_code; 758 759 const u8 *oob_go_neg_channel; 760 761 /* P2P Device Info */ 762 const u8 *p2p_device_info; 763 size_t p2p_device_info_len; 764 const u8 *p2p_device_addr; 765 const u8 *pri_dev_type; 766 u8 num_sec_dev_types; 767 char device_name[WPS_DEV_NAME_MAX_LEN + 1]; 768 u16 config_methods; 769 770 /* WPS IE */ 771 u16 dev_password_id; 772 int dev_password_id_present; 773 u16 wps_config_methods; 774 const u8 *wps_pri_dev_type; 775 const u8 *wps_sec_dev_type_list; 776 size_t wps_sec_dev_type_list_len; 777 const u8 *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT]; 778 size_t wps_vendor_ext_len[P2P_MAX_WPS_VENDOR_EXT]; 779 const u8 *manufacturer; 780 size_t manufacturer_len; 781 const u8 *model_name; 782 size_t model_name_len; 783 const u8 *model_number; 784 size_t model_number_len; 785 const u8 *serial_number; 786 size_t serial_number_len; 787 const u8 *oob_dev_password; 788 size_t oob_dev_password_len; 789 790 /* DS Parameter Set IE */ 791 const u8 *ds_params; 792 793 /* SSID IE */ 794 const u8 *ssid; 795 796 /* P2PS */ 797 u8 service_hash_count; 798 const u8 *service_hash; 799 800 const u8 *session_info; 801 size_t session_info_len; 802 803 const u8 *conn_cap; 804 805 const u8 *adv_id; 806 const u8 *adv_mac; 807 808 const u8 *adv_service_instance; 809 size_t adv_service_instance_len; 810 811 const u8 *session_id; 812 const u8 *session_mac; 813 814 const u8 *feature_cap; 815 size_t feature_cap_len; 816 817 const u8 *persistent_dev; 818 const u8 *persistent_ssid; 819 size_t persistent_ssid_len; 820 821 const u8 *pref_freq_list; 822 size_t pref_freq_list_len; 823 824 const u8 *pcea_info; 825 size_t pcea_info_len; 826 827 const u8 *pbma_info; 828 size_t pbma_info_len; 829 830 const u8 *action_frame_wrapper; 831 size_t action_frame_wrapper_len; 832 833 const u8 *dira; 834 size_t dira_len; 835 836 const u8 *wlan_ap_info; 837 size_t wlan_ap_info_len; 838 }; 839 840 841 #define P2P_MAX_GROUP_ENTRIES 50 842 843 struct p2p_group_info { 844 unsigned int num_clients; 845 struct p2p_client_info { 846 const u8 *p2p_device_addr; 847 const u8 *p2p_interface_addr; 848 u8 dev_capab; 849 u16 config_methods; 850 const u8 *pri_dev_type; 851 u8 num_sec_dev_types; 852 const u8 *sec_dev_types; 853 const char *dev_name; 854 size_t dev_name_len; 855 } client[P2P_MAX_GROUP_ENTRIES]; 856 }; 857 858 859 /* p2p_utils.c */ 860 int p2p_random(char *buf, size_t len); 861 int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel); 862 void p2p_channels_intersect(const struct p2p_channels *a, 863 const struct p2p_channels *b, 864 struct p2p_channels *res); 865 void p2p_channels_union_inplace(struct p2p_channels *res, 866 const struct p2p_channels *b); 867 void p2p_channels_union(const struct p2p_channels *a, 868 const struct p2p_channels *b, 869 struct p2p_channels *res); 870 void p2p_channels_remove_freqs(struct p2p_channels *chan, 871 const struct wpa_freq_range_list *list); 872 int p2p_channels_includes(const struct p2p_channels *channels, u8 reg_class, 873 u8 channel); 874 void p2p_channels_dump(struct p2p_data *p2p, const char *title, 875 const struct p2p_channels *chan); 876 int p2p_channel_select(struct p2p_channels *chans, const int *classes, 877 u8 *op_class, u8 *op_channel); 878 int p2p_channel_random_social(struct p2p_channels *chans, u8 *op_class, 879 u8 *op_channel, 880 struct wpa_freq_range_list *avoid_list, 881 struct wpa_freq_range_list *disallow_list); 882 void p2p_copy_channels(struct p2p_channels *dst, const struct p2p_channels *src, 883 bool allow_6ghz); 884 885 /* p2p_parse.c */ 886 void p2p_copy_filter_devname(char *dst, size_t dst_len, 887 const void *src, size_t src_len); 888 int p2p_parse_p2p_ie(const struct wpabuf *buf, struct p2p_message *msg); 889 int p2p_parse_ies(const u8 *data, size_t len, struct p2p_message *msg); 890 int p2p_parse(const u8 *data, size_t len, struct p2p_message *msg); 891 int p2p_parse_ies_separate(const u8 *wsc, size_t wsc_len, const u8 *p2p, 892 size_t p2p_len, struct p2p_message *msg); 893 void p2p_parse_free(struct p2p_message *msg); 894 int p2p_attr_text(struct wpabuf *data, char *buf, char *end); 895 int p2p_group_info_parse(const u8 *gi, size_t gi_len, 896 struct p2p_group_info *info); 897 898 /* p2p_build.c */ 899 900 struct p2p_noa_desc { 901 u8 count_type; 902 u32 duration; 903 u32 interval; 904 u32 start_time; 905 }; 906 907 /* p2p_group.c */ 908 const u8 * p2p_group_get_interface_addr(struct p2p_group *group); 909 u8 p2p_group_presence_req(struct p2p_group *group, 910 const u8 *client_interface_addr, 911 const u8 *noa, size_t noa_len); 912 int p2p_group_is_group_id_match(struct p2p_group *group, const u8 *group_id, 913 size_t group_id_len); 914 void p2p_group_update_ies(struct p2p_group *group); 915 void p2p_group_force_beacon_update_ies(struct p2p_group *group); 916 struct wpabuf * p2p_group_get_wfd_ie(struct p2p_group *g); 917 void p2p_buf_add_group_info(struct p2p_group *group, struct wpabuf *buf, 918 int max_clients); 919 void p2p_group_buf_add_id(struct p2p_group *group, struct wpabuf *buf); 920 int p2p_group_get_freq(struct p2p_group *group); 921 922 923 void p2p_buf_add_action_hdr(struct wpabuf *buf, u8 subtype, u8 dialog_token); 924 void p2p_buf_add_public_action_hdr(struct wpabuf *buf, u8 subtype, 925 u8 dialog_token); 926 u8 * p2p_buf_add_ie_hdr(struct wpabuf *buf); 927 u8 * p2p_buf_add_p2p2_ie_hdr(struct wpabuf *buf); 928 void p2p_buf_add_status(struct wpabuf *buf, u8 status); 929 void p2p_buf_add_device_info(struct wpabuf *buf, struct p2p_data *p2p, 930 struct p2p_device *peer); 931 void p2p_buf_add_device_id(struct wpabuf *buf, const u8 *dev_addr); 932 void p2p_buf_update_ie_hdr(struct wpabuf *buf, u8 *len); 933 void p2p_buf_add_capability(struct wpabuf *buf, u8 dev_capab, u8 group_capab); 934 void p2p_buf_add_go_intent(struct wpabuf *buf, u8 go_intent); 935 void p2p_buf_add_listen_channel(struct wpabuf *buf, const char *country, 936 u8 reg_class, u8 channel); 937 void p2p_buf_add_operating_channel(struct wpabuf *buf, const char *country, 938 u8 reg_class, u8 channel); 939 void p2p_buf_add_channel_list(struct wpabuf *buf, const char *country, 940 struct p2p_channels *chan, bool is_6ghz_capab); 941 void p2p_buf_add_config_timeout(struct wpabuf *buf, u8 go_timeout, 942 u8 client_timeout); 943 void p2p_buf_add_intended_addr(struct wpabuf *buf, const u8 *interface_addr); 944 void p2p_buf_add_group_bssid(struct wpabuf *buf, const u8 *bssid); 945 void p2p_buf_add_group_id(struct wpabuf *buf, const u8 *dev_addr, 946 const u8 *ssid, size_t ssid_len); 947 void p2p_buf_add_invitation_flags(struct wpabuf *buf, u8 flags); 948 void p2p_buf_add_noa(struct wpabuf *buf, u8 noa_index, u8 opp_ps, u8 ctwindow, 949 struct p2p_noa_desc *desc1, struct p2p_noa_desc *desc2); 950 void p2p_buf_add_ext_listen_timing(struct wpabuf *buf, u16 period, 951 u16 interval); 952 void p2p_buf_add_p2p_interface(struct wpabuf *buf, struct p2p_data *p2p); 953 void p2p_buf_add_oob_go_neg_channel(struct wpabuf *buf, const char *country, 954 u8 oper_class, u8 channel, 955 enum p2p_role_indication role); 956 void p2p_buf_add_service_hash(struct wpabuf *buf, struct p2p_data *p2p); 957 void p2p_buf_add_session_info(struct wpabuf *buf, const char *info); 958 void p2p_buf_add_connection_capability(struct wpabuf *buf, u8 connection_cap); 959 void p2p_buf_add_advertisement_id(struct wpabuf *buf, u32 id, const u8 *mac); 960 void p2p_buf_add_service_instance(struct wpabuf *buf, struct p2p_data *p2p, 961 u8 count, const u8 *hash, 962 struct p2ps_advertisement *adv_list); 963 void p2p_buf_add_session_id(struct wpabuf *buf, u32 id, const u8 *mac); 964 void p2p_buf_add_feature_capability(struct wpabuf *buf, u16 len, 965 const u8 *mask); 966 void p2p_buf_add_persistent_group_info(struct wpabuf *buf, const u8 *dev_addr, 967 const u8 *ssid, size_t ssid_len); 968 void p2p_buf_add_pcea(struct wpabuf *buf, struct p2p_data *p2p); 969 void p2p_buf_add_pbma(struct wpabuf *buf, u16 bootstrap, const u8 *cookie, 970 size_t cookie_len, int comeback_after); 971 void p2p_buf_add_dira(struct wpabuf *buf, struct p2p_data *p2p); 972 int p2p_build_wps_ie(struct p2p_data *p2p, struct wpabuf *buf, int pw_id, 973 int all_attr); 974 void p2p_buf_add_pref_channel_list(struct wpabuf *buf, 975 const struct weighted_pcl *pref_freq_list, 976 unsigned int size); 977 struct wpabuf * p2p_encaps_ie(const struct wpabuf *subelems, u32 ie_type); 978 struct wpabuf * p2p_group_build_p2p2_ie(struct p2p_data *p2p, 979 struct wpabuf *p2p2_ie, int freq); 980 981 /* p2p_sd.c */ 982 struct p2p_sd_query * p2p_pending_sd_req(struct p2p_data *p2p, 983 struct p2p_device *dev); 984 void p2p_free_sd_queries(struct p2p_data *p2p); 985 void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa, 986 const u8 *data, size_t len, int rx_freq); 987 void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa, 988 const u8 *data, size_t len, int rx_freq); 989 void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa, 990 const u8 *data, size_t len, int rx_freq); 991 void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa, 992 const u8 *data, size_t len, int rx_freq); 993 int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev); 994 995 /* p2p_go_neg.c */ 996 struct wpabuf * p2p_build_go_neg_req(struct p2p_data *p2p, 997 struct p2p_device *peer); 998 int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own, 999 struct p2p_device *dev, 1000 const u8 *channel_list, size_t channel_list_len); 1001 void p2p_handle_go_neg_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, 1002 size_t len, int rx_freq); 1003 void p2p_handle_go_neg_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, 1004 size_t len, int rx_freq); 1005 void p2p_handle_go_neg_conf(struct p2p_data *p2p, const u8 *sa, const u8 *data, 1006 size_t len, bool p2p2); 1007 struct wpabuf * p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa, 1008 const u8 *data, size_t len, int rx_freq, 1009 bool p2p2); 1010 struct wpabuf * p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa, 1011 const u8 *data, size_t len, 1012 int rx_freq, bool p2p2); 1013 int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev); 1014 u16 p2p_wps_method_pw_id(enum p2p_wps_method wps_method); 1015 void p2p_reselect_channel(struct p2p_data *p2p, 1016 struct p2p_channels *intersection); 1017 void p2p_check_pref_chan(struct p2p_data *p2p, int go, 1018 struct p2p_device *dev, struct p2p_message *msg); 1019 1020 /* p2p_pd.c */ 1021 void p2p_handle_prov_disc_req(struct p2p_data *p2p, const u8 *sa, 1022 const u8 *data, size_t len, int rx_freq); 1023 void p2p_handle_prov_disc_resp(struct p2p_data *p2p, const u8 *sa, 1024 const u8 *data, size_t len, int rx_freq); 1025 int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev, 1026 int join, int force_freq); 1027 void p2p_reset_pending_pd(struct p2p_data *p2p); 1028 void p2ps_prov_free(struct p2p_data *p2p); 1029 void p2p_process_pcea(struct p2p_data *p2p, struct p2p_message *msg, 1030 struct p2p_device *dev); 1031 1032 /* p2p_invitation.c */ 1033 struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p, 1034 struct p2p_device *peer, 1035 const u8 *go_dev_addr, int dev_pw_id); 1036 void p2p_handle_invitation_req(struct p2p_data *p2p, const u8 *sa, 1037 const u8 *data, size_t len, int rx_freq); 1038 void p2p_handle_invitation_resp(struct p2p_data *p2p, const u8 *sa, 1039 const u8 *data, size_t len); 1040 struct wpabuf * p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa, 1041 const u8 *data, size_t len, 1042 int rx_freq, bool p2p2); 1043 void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, 1044 const u8 *data, size_t len); 1045 int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev, 1046 const u8 *go_dev_addr, int dev_pw_id); 1047 void p2p_invitation_req_cb(struct p2p_data *p2p, int success); 1048 void p2p_invitation_resp_cb(struct p2p_data *p2p, const u8 *dst, int success); 1049 void p2p_start_invitation_connect(struct p2p_data *p2p, struct p2p_device *dev); 1050 1051 /* p2p_dev_disc.c */ 1052 void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa, 1053 const u8 *data, size_t len, int rx_freq); 1054 void p2p_dev_disc_req_cb(struct p2p_data *p2p, int success); 1055 int p2p_send_dev_disc_req(struct p2p_data *p2p, struct p2p_device *dev); 1056 void p2p_dev_disc_resp_cb(struct p2p_data *p2p, int success); 1057 void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa, 1058 const u8 *data, size_t len); 1059 void p2p_go_disc_req_cb(struct p2p_data *p2p, int success); 1060 void p2p_process_go_disc_req(struct p2p_data *p2p, const u8 *da, const u8 *sa, 1061 const u8 *data, size_t len, int rx_freq); 1062 1063 /* p2p.c */ 1064 void p2p_set_state(struct p2p_data *p2p, int new_state); 1065 void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec, 1066 unsigned int usec); 1067 void p2p_clear_timeout(struct p2p_data *p2p); 1068 void p2p_continue_find(struct p2p_data *p2p); 1069 struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, 1070 const u8 *addr, 1071 struct p2p_message *msg); 1072 void p2p_update_peer_6ghz_capab(struct p2p_device *dev, 1073 const struct p2p_message *msg); 1074 void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, 1075 struct p2p_device *dev, struct p2p_message *msg); 1076 int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, 1077 struct os_reltime *rx_time, int level, const u8 *ies, 1078 size_t ies_len, int scan_res); 1079 struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr); 1080 struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p, 1081 const u8 *addr); 1082 void p2p_go_neg_failed(struct p2p_data *p2p, int status); 1083 void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer); 1084 int p2p_match_dev_type(struct p2p_data *p2p, struct wpabuf *wps); 1085 int dev_type_list_match(const u8 *dev_type, const u8 *req_dev_type[], 1086 size_t num_req_dev_type); 1087 struct wpabuf * p2p_build_probe_resp_ies(struct p2p_data *p2p, 1088 const u8 *query_hash, 1089 u8 query_count); 1090 int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst, 1091 const u8 *src, const u8 *bssid, const u8 *buf, 1092 size_t len, unsigned int wait_time); 1093 void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq); 1094 int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev, 1095 unsigned int force_freq, unsigned int pref_freq, 1096 int go); 1097 void p2p_go_neg_wait_timeout(void *eloop_ctx, void *timeout_ctx); 1098 int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev, 1099 u8 *status); 1100 void p2p_pref_channel_filter(const struct p2p_channels *a, 1101 const struct weighted_pcl *freq_list, 1102 unsigned int num_channels, 1103 struct p2p_channels *res, bool go); 1104 1105 void p2p_sd_query_cb(struct p2p_data *p2p, int success); 1106 void p2p_pasn_initialize(struct p2p_data *p2p, struct p2p_device *dev, 1107 const u8 *addr, int freq, bool verify, 1108 bool derive_kek); 1109 void p2p_buf_add_usd_service_hash(struct wpabuf *buf, struct p2p_data *p2p); 1110 void p2p_dfs_channel_filter(struct p2p_data *p2p, 1111 const struct p2p_channels *p2p_chan, 1112 struct p2p_channels *res, bool go); 1113 bool is_dfs_freq_allowed(struct p2p_data *p2p, bool go, int freq); 1114 1115 void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...) 1116 PRINTF_FORMAT(2, 3); 1117 void p2p_info(struct p2p_data *p2p, const char *fmt, ...) 1118 PRINTF_FORMAT(2, 3); 1119 void p2p_err(struct p2p_data *p2p, const char *fmt, ...) 1120 PRINTF_FORMAT(2, 3); 1121 1122 #endif /* P2P_I_H */ 1123