1 /* 2 * Wi-Fi Direct - 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_H 10 #define P2P_H 11 12 #include "common/ieee802_11_defs.h" 13 #include "wps/wps.h" 14 #include "common/wpa_common.h" 15 16 #define DEVICE_IDENTITY_KEY_MAX_LEN 64 17 #define DEVICE_IDENTITY_KEY_LEN 16 18 #define DEVICE_IDENTITY_TAG_LEN 8 19 #define DEVICE_IDENTITY_NONCE_LEN 8 20 #define DEVICE_MAX_HASH_LEN 32 21 #define DIR_STR_LEN 3 22 23 /* DIRA Cipher versions */ 24 #define DIRA_CIPHER_VERSION_128 0 25 26 struct weighted_pcl; 27 28 /* P2P ASP Setup Capability */ 29 #define P2PS_SETUP_NONE 0 30 #define P2PS_SETUP_NEW BIT(0) 31 #define P2PS_SETUP_CLIENT BIT(1) 32 #define P2PS_SETUP_GROUP_OWNER BIT(2) 33 34 #define P2PS_WILD_HASH_STR "org.wi-fi.wfds" 35 #define P2PS_HASH_LEN 6 36 #define P2P_MAX_QUERY_HASH 6 37 #define P2PS_FEATURE_CAPAB_CPT_MAX 2 38 39 /** 40 * P2P_MAX_PREF_CHANNELS - Maximum number of preferred channels 41 */ 42 #define P2P_MAX_PREF_CHANNELS 100 43 44 /** 45 * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes 46 */ 47 #define P2P_MAX_REG_CLASSES 15 48 49 /** 50 * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class 51 */ 52 #define P2P_MAX_REG_CLASS_CHANNELS 60 53 54 /** 55 * struct p2p_channels - List of supported channels 56 */ 57 struct p2p_channels { 58 /** 59 * struct p2p_reg_class - Supported regulatory class 60 */ 61 struct p2p_reg_class { 62 /** 63 * reg_class - Regulatory class (IEEE 802.11-2007, Annex J) 64 */ 65 u8 reg_class; 66 67 /** 68 * channel - Supported channels 69 */ 70 u8 channel[P2P_MAX_REG_CLASS_CHANNELS]; 71 72 /** 73 * channels - Number of channel entries in use 74 */ 75 size_t channels; 76 } reg_class[P2P_MAX_REG_CLASSES]; 77 78 /** 79 * reg_classes - Number of reg_class entries in use 80 */ 81 size_t reg_classes; 82 }; 83 84 enum p2p_wps_method { 85 WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC, WPS_NFC, 86 WPS_P2PS 87 }; 88 89 /** 90 * struct p2p_go_neg_results - P2P Group Owner Negotiation results 91 */ 92 struct p2p_go_neg_results { 93 /** 94 * status - Negotiation result (Status Code) 95 * 96 * 0 (P2P_SC_SUCCESS) indicates success. Non-zero values indicate 97 * failed negotiation. 98 */ 99 int status; 100 101 /** 102 * role_go - Whether local end is Group Owner 103 */ 104 int role_go; 105 106 /** 107 * freq - Frequency of the group operational channel in MHz 108 */ 109 int freq; 110 111 int ht40; 112 113 int vht; 114 115 int edmg; 116 117 u8 max_oper_chwidth; 118 119 unsigned int vht_center_freq2; 120 121 /** 122 * he - Indicates if IEEE 802.11ax HE is enabled 123 */ 124 int he; 125 126 /** 127 * ssid - SSID of the group 128 */ 129 u8 ssid[SSID_MAX_LEN]; 130 131 /** 132 * ssid_len - Length of SSID in octets 133 */ 134 size_t ssid_len; 135 136 /** 137 * psk - WPA pre-shared key (256 bits) (GO only) 138 */ 139 u8 psk[32]; 140 141 /** 142 * psk_set - Whether PSK field is configured (GO only) 143 */ 144 int psk_set; 145 146 /** 147 * passphrase - WPA2-Personal passphrase for the group (GO only) 148 */ 149 char passphrase[64]; 150 151 /** 152 * peer_device_addr - P2P Device Address of the peer 153 */ 154 u8 peer_device_addr[ETH_ALEN]; 155 156 /** 157 * peer_interface_addr - P2P Interface Address of the peer 158 */ 159 u8 peer_interface_addr[ETH_ALEN]; 160 161 /** 162 * wps_method - WPS method to be used during provisioning 163 */ 164 enum p2p_wps_method wps_method; 165 166 #define P2P_MAX_CHANNELS 50 167 168 /** 169 * freq_list - Zero-terminated list of possible operational channels 170 */ 171 int freq_list[P2P_MAX_CHANNELS]; 172 173 /** 174 * persistent_group - Whether the group should be made persistent 175 * 0 = not persistent 176 * 1 = persistent group without persistent reconnect 177 * 2 = persistent group with persistent reconnect 178 */ 179 int persistent_group; 180 181 /** 182 * peer_config_timeout - Peer configuration timeout (in 10 msec units) 183 */ 184 unsigned int peer_config_timeout; 185 186 /** 187 * p2p2 - Whether this group uses P2P2 188 */ 189 bool p2p2; 190 191 /** 192 * akmp - The negotiated PASN AKMP for P2P2 193 */ 194 int akmp; 195 196 /** 197 * cipher - Pairwise cipher(s) for the group for P2P2 198 */ 199 int cipher; 200 201 /** 202 * pmkid - PMKID for P2P2 when PMK is derived as part of pairing 203 */ 204 u8 pmkid[PMKID_LEN]; 205 206 /** 207 * pmk - PMK for P2P2 when PMK is derived as part of pairing 208 */ 209 u8 pmk[PMK_LEN_MAX]; 210 211 /** 212 * pmk_len - Length of @pmk in octets 213 */ 214 size_t pmk_len; 215 216 /** 217 * sae_password - SAE password for the group (P2P2) 218 */ 219 char sae_password[100]; 220 }; 221 222 struct p2ps_provision { 223 /** 224 * pd_seeker - P2PS provision discovery seeker role 225 */ 226 unsigned int pd_seeker:1; 227 228 /** 229 * status - Remote returned provisioning status code 230 */ 231 int status; 232 233 /** 234 * adv_id - P2PS Advertisement ID 235 */ 236 u32 adv_id; 237 238 /** 239 * session_id - P2PS Session ID 240 */ 241 u32 session_id; 242 243 /** 244 * method - WPS Method (to be) used to establish session 245 */ 246 u16 method; 247 248 /** 249 * conncap - Connection Capabilities negotiated between P2P peers 250 */ 251 u8 conncap; 252 253 /** 254 * role - Info about the roles to be used for this connection 255 */ 256 u8 role; 257 258 /** 259 * session_mac - MAC address of the peer that started the session 260 */ 261 u8 session_mac[ETH_ALEN]; 262 263 /** 264 * adv_mac - MAC address of the peer advertised the service 265 */ 266 u8 adv_mac[ETH_ALEN]; 267 268 /** 269 * cpt_mask - Supported Coordination Protocol Transport mask 270 * 271 * A bitwise mask of supported ASP Coordination Protocol Transports. 272 * This property is set together and corresponds with cpt_priority. 273 */ 274 u8 cpt_mask; 275 276 /** 277 * cpt_priority - Coordination Protocol Transport priority list 278 * 279 * Priorities of supported ASP Coordination Protocol Transports. 280 * This property is set together and corresponds with cpt_mask. 281 * The CPT priority list is 0 terminated. 282 */ 283 u8 cpt_priority[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; 284 285 /** 286 * force_freq - The only allowed channel frequency in MHz or 0. 287 */ 288 unsigned int force_freq; 289 290 /** 291 * pref_freq - Preferred operating frequency in MHz or 0. 292 */ 293 unsigned int pref_freq; 294 295 /** 296 * info - Vendor defined extra Provisioning information 297 */ 298 char info[0]; 299 }; 300 301 struct p2ps_advertisement { 302 struct p2ps_advertisement *next; 303 304 /** 305 * svc_info - Pointer to (internal) Service defined information 306 */ 307 char *svc_info; 308 309 /** 310 * id - P2PS Advertisement ID 311 */ 312 u32 id; 313 314 /** 315 * config_methods - WPS Methods which are allowed for this service 316 */ 317 u16 config_methods; 318 319 /** 320 * state - Current state of the service: 0 - Out Of Service, 1-255 Vendor defined 321 */ 322 u8 state; 323 324 /** 325 * auto_accept - Automatically Accept provisioning request if possible. 326 */ 327 u8 auto_accept; 328 329 /** 330 * hash - 6 octet Service Name has to match against incoming Probe Requests 331 */ 332 u8 hash[P2PS_HASH_LEN]; 333 334 /** 335 * cpt_mask - supported Coordination Protocol Transport mask 336 * 337 * A bitwise mask of supported ASP Coordination Protocol Transports. 338 * This property is set together and corresponds with cpt_priority. 339 */ 340 u8 cpt_mask; 341 342 /** 343 * cpt_priority - Coordination Protocol Transport priority list 344 * 345 * Priorities of supported ASP Coordinatin Protocol Transports. 346 * This property is set together and corresponds with cpt_mask. 347 * The CPT priority list is 0 terminated. 348 */ 349 u8 cpt_priority[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; 350 351 /** 352 * svc_name - NULL Terminated UTF-8 Service Name, and svc_info storage 353 */ 354 char svc_name[0]; 355 }; 356 357 358 struct p2p_data; 359 360 enum p2p_scan_type { 361 P2P_SCAN_SOCIAL, 362 P2P_SCAN_FULL, 363 P2P_SCAN_SPECIFIC, 364 P2P_SCAN_SOCIAL_PLUS_ONE 365 }; 366 367 #define P2P_MAX_WPS_VENDOR_EXT 10 368 369 /** 370 * struct p2p_pairing_config - P2P pairing configuration 371 */ 372 struct p2p_pairing_config { 373 /** 374 * Pairing capable 375 */ 376 bool pairing_capable; 377 378 /** 379 * Enable P2P pairing setup 380 */ 381 bool enable_pairing_setup; 382 383 /** 384 * Enable pairing cache to allow verification 385 */ 386 bool enable_pairing_cache; 387 388 /** 389 * P2P bootstrapping methods supported 390 */ 391 u16 bootstrap_methods; 392 393 /** 394 * Bitmap of supported PASN types 395 */ 396 u8 pasn_type; 397 398 /* Cipher version type */ 399 int dik_cipher; 400 401 /* Buffer to hold the DevIK */ 402 u8 dik_data[DEVICE_IDENTITY_KEY_MAX_LEN]; 403 404 /* Length of DevIK in octets */ 405 size_t dik_len; 406 }; 407 408 /** 409 * struct p2p_peer_info - P2P peer information 410 */ 411 struct p2p_peer_info { 412 /** 413 * p2p_device_addr - P2P Device Address of the peer 414 */ 415 u8 p2p_device_addr[ETH_ALEN]; 416 417 /** 418 * pri_dev_type - Primary Device Type 419 */ 420 u8 pri_dev_type[8]; 421 422 /** 423 * device_name - Device Name (0..32 octets encoded in UTF-8) 424 */ 425 char device_name[WPS_DEV_NAME_MAX_LEN + 1]; 426 427 /** 428 * manufacturer - Manufacturer (0..64 octets encoded in UTF-8) 429 */ 430 char manufacturer[WPS_MANUFACTURER_MAX_LEN + 1]; 431 432 /** 433 * model_name - Model Name (0..32 octets encoded in UTF-8) 434 */ 435 char model_name[WPS_MODEL_NAME_MAX_LEN + 1]; 436 437 /** 438 * model_number - Model Number (0..32 octets encoded in UTF-8) 439 */ 440 char model_number[WPS_MODEL_NUMBER_MAX_LEN + 1]; 441 442 /** 443 * serial_number - Serial Number (0..32 octets encoded in UTF-8) 444 */ 445 char serial_number[WPS_SERIAL_NUMBER_MAX_LEN + 1]; 446 447 /** 448 * level - Signal level 449 */ 450 int level; 451 452 /** 453 * config_methods - WPS Configuration Methods 454 */ 455 u16 config_methods; 456 457 /** 458 * dev_capab - Device Capabilities 459 */ 460 u8 dev_capab; 461 462 /** 463 * group_capab - Group Capabilities 464 */ 465 u8 group_capab; 466 467 /** 468 * wps_sec_dev_type_list - WPS secondary device type list 469 * 470 * This list includes from 0 to 16 Secondary Device Types as indicated 471 * by wps_sec_dev_type_list_len (8 * number of types). 472 */ 473 u8 wps_sec_dev_type_list[WPS_SEC_DEV_TYPE_MAX_LEN]; 474 475 /** 476 * wps_sec_dev_type_list_len - Length of secondary device type list 477 */ 478 size_t wps_sec_dev_type_list_len; 479 480 struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT]; 481 482 /** 483 * wfd_subelems - Wi-Fi Display subelements from WFD IE(s) 484 */ 485 struct wpabuf *wfd_subelems; 486 487 /** 488 * vendor_elems - Unrecognized vendor elements 489 * 490 * This buffer includes any other vendor element than P2P, WPS, and WFD 491 * IE(s) from the frame that was used to discover the peer. 492 */ 493 struct wpabuf *vendor_elems; 494 495 /** 496 * p2ps_instance - P2PS Application Service Info 497 */ 498 struct wpabuf *p2ps_instance; 499 500 /** 501 * pcea_cap_info - Capability info in PCEA 502 */ 503 u16 pcea_cap_info; 504 505 /** 506 * The regulatory info encoding for operation in 6 GHz band 507 */ 508 u8 reg_info; 509 510 /** 511 * p2p_pairing_config - P2P pairing configuration 512 */ 513 struct p2p_pairing_config pairing_config; 514 515 /** 516 * dik_id - For paired peers Identity block ID with PMK 517 */ 518 int dik_id; 519 520 /** 521 * nonce_tag_valid - Whether nonce and tag are valid 522 */ 523 bool nonce_tag_valid; 524 525 /** 526 * nonce - Valid nonce received in a recent discovery frame 527 */ 528 u8 nonce[DEVICE_IDENTITY_NONCE_LEN]; 529 530 /** 531 * tag - Valid tag received in a recent discovery frame 532 */ 533 u8 tag[DEVICE_IDENTITY_TAG_LEN]; 534 }; 535 536 enum p2p_prov_disc_status { 537 P2P_PROV_DISC_SUCCESS, 538 P2P_PROV_DISC_TIMEOUT, 539 P2P_PROV_DISC_REJECTED, 540 P2P_PROV_DISC_TIMEOUT_JOIN, 541 P2P_PROV_DISC_INFO_UNAVAILABLE, 542 }; 543 544 struct p2p_channel { 545 u8 op_class; 546 u8 chan; 547 }; 548 549 /** 550 * struct p2p_config - P2P configuration 551 * 552 * This configuration is provided to the P2P module during initialization with 553 * p2p_init(). 554 */ 555 struct p2p_config { 556 /** 557 * country - Country code to use in P2P operations 558 */ 559 char country[3]; 560 561 /** 562 * reg_class - Regulatory class for own listen channel 563 */ 564 u8 reg_class; 565 566 /** 567 * channel - Own listen channel 568 */ 569 u8 channel; 570 571 /** 572 * channel_forced - the listen channel was forced by configuration 573 * or by control interface and cannot be overridden 574 */ 575 u8 channel_forced; 576 577 /** 578 * Regulatory class for own operational channel 579 */ 580 u8 op_reg_class; 581 582 /** 583 * op_channel - Own operational channel 584 */ 585 u8 op_channel; 586 587 /** 588 * cfg_op_channel - Whether op_channel is hardcoded in configuration 589 */ 590 u8 cfg_op_channel; 591 592 /** 593 * channels - Own supported regulatory classes and channels 594 * 595 * List of supposerted channels per regulatory class. The regulatory 596 * classes are defined in IEEE Std 802.11-2007 Annex J and the 597 * numbering of the clases depends on the configured country code. 598 */ 599 struct p2p_channels channels; 600 601 /** 602 * cli_channels - Additional client channels 603 * 604 * This list of channels (if any) will be used when advertising local 605 * channels during GO Negotiation or Invitation for the cases where the 606 * local end may become the client. This may allow the peer to become a 607 * GO on additional channels if it supports these options. The main use 608 * case for this is to include passive-scan channels on devices that may 609 * not know their current location and have configured most channels to 610 * not allow initiation of radition (i.e., another device needs to take 611 * master responsibilities). 612 */ 613 struct p2p_channels cli_channels; 614 615 /** 616 * num_pref_chan - Number of pref_chan entries 617 */ 618 unsigned int num_pref_chan; 619 620 /** 621 * pref_chan - Preferred channels for GO Negotiation 622 */ 623 struct p2p_channel *pref_chan; 624 625 /** 626 * p2p_6ghz_disable - Disable 6GHz for P2P operations 627 */ 628 bool p2p_6ghz_disable; 629 630 /** 631 * p2p_dfs_chan_enable - Enable p2p Go to operate on dfs channel 632 */ 633 bool p2p_dfs_chan_enable; 634 635 /** 636 * pri_dev_type - Primary Device Type (see WPS) 637 */ 638 u8 pri_dev_type[8]; 639 640 /** 641 * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types 642 */ 643 #define P2P_SEC_DEVICE_TYPES 5 644 645 /** 646 * sec_dev_type - Optional secondary device types 647 */ 648 u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8]; 649 650 /** 651 * num_sec_dev_types - Number of sec_dev_type entries 652 */ 653 size_t num_sec_dev_types; 654 655 /** 656 * dev_addr - P2P Device Address 657 */ 658 u8 dev_addr[ETH_ALEN]; 659 660 /** 661 * dev_name - Device Name 662 */ 663 char *dev_name; 664 665 char *manufacturer; 666 char *model_name; 667 char *model_number; 668 char *serial_number; 669 670 u8 uuid[16]; 671 u16 config_methods; 672 673 /** 674 * concurrent_operations - Whether concurrent operations are supported 675 */ 676 int concurrent_operations; 677 678 /** 679 * max_peers - Maximum number of discovered peers to remember 680 * 681 * If more peers are discovered, older entries will be removed to make 682 * room for the new ones. 683 */ 684 size_t max_peers; 685 686 /** 687 * p2p_intra_bss - Intra BSS communication is supported 688 */ 689 int p2p_intra_bss; 690 691 /** 692 * ssid_postfix - Postfix data to add to the SSID 693 * 694 * This data will be added to the end of the SSID after the 695 * DIRECT-<random two octets> prefix. 696 */ 697 u8 ssid_postfix[SSID_MAX_LEN - 9]; 698 699 /** 700 * ssid_postfix_len - Length of the ssid_postfix data 701 */ 702 size_t ssid_postfix_len; 703 704 /** 705 * max_listen - Maximum listen duration in ms 706 */ 707 unsigned int max_listen; 708 709 /** 710 * passphrase_len - Passphrase length (8..63) 711 * 712 * This parameter controls the length of the random passphrase that is 713 * generated at the GO. 714 */ 715 unsigned int passphrase_len; 716 717 /** 718 * p2p_pairing_config - P2P pairing configuration 719 */ 720 struct p2p_pairing_config pairing_config; 721 722 /** 723 * reg_info - Regulatory info encoding for operation in 6 GHz band 724 */ 725 u8 reg_info; 726 727 /** 728 * dfs_owner - Enable P2P GO to act as DFS Owner 729 */ 730 bool dfs_owner; 731 732 /** 733 * twt_power_mgmt - Enable TWT based power management for P2P 734 */ 735 bool twt_power_mgmt; 736 737 /** 738 * comeback_after - Bootstrap request unauthorized for peer 739 * 740 * Ask to come back after this many TUs. 741 */ 742 u16 comeback_after; 743 744 /** 745 * chan_switch_req_enable - Enable P2P client channel switch request 746 */ 747 bool chan_switch_req_enable; 748 749 #ifdef CONFIG_TESTING_OPTIONS 750 /** 751 * Operating class for own operational channel in Invitation Response 752 */ 753 u8 inv_op_class; 754 755 /** 756 * inv_op_channel - Own operational channel in Invitation Response 757 */ 758 u8 inv_op_channel; 759 #endif /* CONFIG_TESTING_OPTIONS */ 760 761 /** 762 * cb_ctx - Context to use with callback functions 763 */ 764 void *cb_ctx; 765 766 /** 767 * debug_print - Debug print 768 * @ctx: Callback context from cb_ctx 769 * @level: Debug verbosity level (MSG_*) 770 * @msg: Debug message 771 */ 772 void (*debug_print)(void *ctx, int level, const char *msg); 773 774 775 /* Callbacks to request lower layer driver operations */ 776 777 /** 778 * p2p_scan - Request a P2P scan/search 779 * @ctx: Callback context from cb_ctx 780 * @type: Scan type 781 * @freq: Specific frequency (MHz) to scan or 0 for no restriction 782 * @num_req_dev_types: Number of requested device types 783 * @req_dev_types: Array containing requested device types 784 * @dev_id: Device ID to search for or %NULL to find all devices 785 * @pw_id: Device Password ID 786 * @include_6ghz: Include 6 GHz channels in P2P scan 787 * Returns: 0 on success, -1 on failure 788 * 789 * This callback function is used to request a P2P scan or search 790 * operation to be completed. Type type argument specifies which type 791 * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the 792 * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL 793 * indicates that all channels are to be scanned. @P2P_SCAN_SPECIFIC 794 * request a scan of a single channel specified by freq. 795 * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels 796 * plus one extra channel specified by freq. 797 * 798 * The full scan is used for the initial scan to find group owners from 799 * all. The other types are used during search phase scan of the social 800 * channels (with potential variation if the Listen channel of the 801 * target peer is known or if other channels are scanned in steps). 802 * 803 * The scan results are returned after this call by calling 804 * p2p_scan_res_handler() for each scan result that has a P2P IE and 805 * then calling p2p_scan_res_handled() to indicate that all scan 806 * results have been indicated. 807 */ 808 int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq, 809 unsigned int num_req_dev_types, 810 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id, 811 bool include_6ghz); 812 813 /** 814 * send_probe_resp - Transmit a Probe Response frame 815 * @ctx: Callback context from cb_ctx 816 * @buf: Probe Response frame (including the header and body) 817 * @freq: Forced frequency (in MHz) to use or 0. 818 * Returns: 0 on success, -1 on failure 819 * 820 * This function is used to reply to Probe Request frames that were 821 * indicated with a call to p2p_probe_req_rx(). The response is to be 822 * sent on the same channel, unless otherwise specified, or to be 823 * dropped if the driver is not listening to Probe Request frames 824 * anymore. 825 * 826 * Alternatively, the responsibility for building the Probe Response 827 * frames in Listen state may be in another system component in which 828 * case this function need to be implemented (i.e., the function 829 * pointer can be %NULL). The WPS and P2P IEs to be added for Probe 830 * Response frames in such a case are available from the 831 * start_listen() callback. It should be noted that the received Probe 832 * Request frames must be indicated by calling p2p_probe_req_rx() even 833 * if this send_probe_resp() is not used. 834 */ 835 int (*send_probe_resp)(void *ctx, const struct wpabuf *buf, 836 unsigned int freq); 837 838 /** 839 * send_action - Transmit an Action frame 840 * @ctx: Callback context from cb_ctx 841 * @freq: Frequency in MHz for the channel on which to transmit 842 * @dst: Destination MAC address (Address 1) 843 * @src: Source MAC address (Address 2) 844 * @bssid: BSSID (Address 3) 845 * @buf: Frame body (starting from Category field) 846 * @len: Length of buf in octets 847 * @wait_time: How many msec to wait for a response frame 848 * @scheduled: Return value indicating whether the transmissions was 849 * scheduled to happen once the radio is available 850 * Returns: 0 on success, -1 on failure 851 * 852 * The Action frame may not be transmitted immediately and the status 853 * of the transmission must be reported by calling 854 * p2p_send_action_cb() once the frame has either been transmitted or 855 * it has been dropped due to excessive retries or other failure to 856 * transmit. 857 */ 858 int (*send_action)(void *ctx, unsigned int freq, const u8 *dst, 859 const u8 *src, const u8 *bssid, const u8 *buf, 860 size_t len, unsigned int wait_time, int *scheduled); 861 862 /** 863 * send_action_done - Notify that Action frame sequence was completed 864 * @ctx: Callback context from cb_ctx 865 * 866 * This function is called when the Action frame sequence that was 867 * started with send_action() has been completed, i.e., when there is 868 * no need to wait for a response from the destination peer anymore. 869 */ 870 void (*send_action_done)(void *ctx); 871 872 /** 873 * start_listen - Start Listen state 874 * @ctx: Callback context from cb_ctx 875 * @freq: Frequency of the listen channel in MHz 876 * @duration: Duration for the Listen state in milliseconds 877 * @probe_resp_ie: IE(s) to be added to Probe Response frames 878 * Returns: 0 on success, -1 on failure 879 * 880 * This Listen state may not start immediately since the driver may 881 * have other pending operations to complete first. Once the Listen 882 * state has started, p2p_listen_cb() must be called to notify the P2P 883 * module. Once the Listen state is stopped, p2p_listen_end() must be 884 * called to notify the P2P module that the driver is not in the Listen 885 * state anymore. 886 * 887 * If the send_probe_resp() is not used for generating the response, 888 * the IEs from probe_resp_ie need to be added to the end of the Probe 889 * Response frame body. If send_probe_resp() is used, the probe_resp_ie 890 * information can be ignored. 891 */ 892 int (*start_listen)(void *ctx, unsigned int freq, 893 unsigned int duration, 894 const struct wpabuf *probe_resp_ie); 895 /** 896 * stop_listen - Stop Listen state 897 * @ctx: Callback context from cb_ctx 898 * 899 * This callback can be used to stop a Listen state operation that was 900 * previously requested with start_listen(). 901 */ 902 void (*stop_listen)(void *ctx); 903 904 /** 905 * get_noa - Get current Notice of Absence attribute payload 906 * @ctx: Callback context from cb_ctx 907 * @interface_addr: P2P Interface Address of the GO 908 * @buf: Buffer for returning NoA 909 * @buf_len: Buffer length in octets 910 * Returns: Number of octets used in buf, 0 to indicate no NoA is being 911 * advertized, or -1 on failure 912 * 913 * This function is used to fetch the current Notice of Absence 914 * attribute value from GO. 915 */ 916 int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf, 917 size_t buf_len); 918 919 /* Callbacks to notify events to upper layer management entity */ 920 921 /** 922 * dev_found - Notification of a found P2P Device 923 * @ctx: Callback context from cb_ctx 924 * @addr: Source address of the message triggering this notification 925 * @info: P2P peer information 926 * @new_device: Inform if the peer is newly found 927 * 928 * This callback is used to notify that a new P2P Device has been 929 * found. This may happen, e.g., during Search state based on scan 930 * results or during Listen state based on receive Probe Request and 931 * Group Owner Negotiation Request. 932 */ 933 void (*dev_found)(void *ctx, const u8 *addr, 934 const struct p2p_peer_info *info, 935 int new_device); 936 937 /** 938 * dev_lost - Notification of a lost P2P Device 939 * @ctx: Callback context from cb_ctx 940 * @dev_addr: P2P Device Address of the lost P2P Device 941 * 942 * This callback is used to notify that a P2P Device has been deleted. 943 */ 944 void (*dev_lost)(void *ctx, const u8 *dev_addr); 945 946 /** 947 * find_stopped - Notification of a p2p_find operation stopping 948 * @ctx: Callback context from cb_ctx 949 */ 950 void (*find_stopped)(void *ctx); 951 952 /** 953 * go_neg_req_rx - Notification of a receive GO Negotiation Request 954 * @ctx: Callback context from cb_ctx 955 * @src: Source address of the message triggering this notification 956 * @dev_passwd_id: WPS Device Password ID 957 * @go_intent: Peer's GO Intent 958 * 959 * This callback is used to notify that a P2P Device is requesting 960 * group owner negotiation with us, but we do not have all the 961 * necessary information to start GO Negotiation. This indicates that 962 * the local user has not authorized the connection yet by providing a 963 * PIN or PBC button press. This information can be provided with a 964 * call to p2p_connect(). 965 */ 966 void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id, 967 u8 go_intent); 968 969 /** 970 * go_neg_completed - Notification of GO Negotiation results 971 * @ctx: Callback context from cb_ctx 972 * @res: GO Negotiation results 973 * 974 * This callback is used to notify that Group Owner Negotiation has 975 * been completed. Non-zero struct p2p_go_neg_results::status indicates 976 * failed negotiation. In case of success, this function is responsible 977 * for creating a new group interface (or using the existing interface 978 * depending on driver features), setting up the group interface in 979 * proper mode based on struct p2p_go_neg_results::role_go and 980 * initializing WPS provisioning either as a Registrar (if GO) or as an 981 * Enrollee. Successful WPS provisioning must be indicated by calling 982 * p2p_wps_success_cb(). The callee is responsible for timing out group 983 * formation if WPS provisioning cannot be completed successfully 984 * within 15 seconds. 985 */ 986 void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res); 987 988 /** 989 * set_go_security_config - Set security configuration for P2P GO 990 * @ctx: Callback context from cb_ctx 991 * @res: GO Negotiation results 992 * 993 * This callback is used to set PMK/passphrase derived during PASN 994 * authentication with a P2P client. This will fetch an active P2P group 995 * owner instance and configure PMKSA in case of password based PASN, or 996 * configures the passphrase and derive PT in case of unauthenticated 997 * PASN. 998 */ 999 void (*set_go_security_config)(void *ctx, 1000 struct p2p_go_neg_results *res); 1001 1002 /** 1003 * sd_request - Callback on Service Discovery Request 1004 * @ctx: Callback context from cb_ctx 1005 * @freq: Frequency (in MHz) of the channel 1006 * @sa: Source address of the request 1007 * @dialog_token: Dialog token 1008 * @update_indic: Service Update Indicator from the source of request 1009 * @tlvs: P2P Service Request TLV(s) 1010 * @tlvs_len: Length of tlvs buffer in octets 1011 * 1012 * This callback is used to indicate reception of a service discovery 1013 * request. Response to the query must be indicated by calling 1014 * p2p_sd_response() with the context information from the arguments to 1015 * this callback function. 1016 * 1017 * This callback handler can be set to %NULL to indicate that service 1018 * discovery is not supported. 1019 */ 1020 void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token, 1021 u16 update_indic, const u8 *tlvs, size_t tlvs_len); 1022 1023 /** 1024 * sd_response - Callback on Service Discovery Response 1025 * @ctx: Callback context from cb_ctx 1026 * @sa: Source address of the request 1027 * @update_indic: Service Update Indicator from the source of response 1028 * @tlvs: P2P Service Response TLV(s) 1029 * @tlvs_len: Length of tlvs buffer in octets 1030 * 1031 * This callback is used to indicate reception of a service discovery 1032 * response. This callback handler can be set to %NULL if no service 1033 * discovery requests are used. The information provided with this call 1034 * is replies to the queries scheduled with p2p_sd_request(). 1035 */ 1036 void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic, 1037 const u8 *tlvs, size_t tlvs_len); 1038 1039 /** 1040 * prov_disc_req - Callback on Provisiong Discovery Request 1041 * @ctx: Callback context from cb_ctx 1042 * @peer: Source address of the request 1043 * @config_methods: Requested WPS Config Method 1044 * @dev_addr: P2P Device Address of the found P2P Device 1045 * @pri_dev_type: Primary Device Type 1046 * @dev_name: Device Name 1047 * @supp_config_methods: Supported configuration Methods 1048 * @dev_capab: Device Capabilities 1049 * @group_capab: Group Capabilities 1050 * @group_id: P2P Group ID (or %NULL if not included) 1051 * @group_id_len: Length of P2P Group ID 1052 * 1053 * This callback is used to indicate reception of a Provision Discovery 1054 * Request frame that the P2P module accepted. 1055 */ 1056 void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods, 1057 const u8 *dev_addr, const u8 *pri_dev_type, 1058 const char *dev_name, u16 supp_config_methods, 1059 u8 dev_capab, u8 group_capab, 1060 const u8 *group_id, size_t group_id_len); 1061 1062 /** 1063 * prov_disc_resp - Callback on Provisiong Discovery Response 1064 * @ctx: Callback context from cb_ctx 1065 * @peer: Source address of the response 1066 * @config_methods: Value from p2p_prov_disc_req() or 0 on failure 1067 * 1068 * This callback is used to indicate reception of a Provision Discovery 1069 * Response frame for a pending request scheduled with 1070 * p2p_prov_disc_req(). This callback handler can be set to %NULL if 1071 * provision discovery is not used. 1072 */ 1073 void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods); 1074 1075 /** 1076 * prov_disc_fail - Callback on Provision Discovery failure 1077 * @ctx: Callback context from cb_ctx 1078 * @peer: Source address of the response 1079 * @status: Cause of failure, will not be %P2P_PROV_DISC_SUCCESS 1080 * @adv_id: If non-zero, then the adv_id of the PD Request 1081 * @adv_mac: P2P Device Address of the advertizer 1082 * @deferred_session_resp: Deferred session response sent by advertizer 1083 * 1084 * This callback is used to indicate either a failure or no response 1085 * to an earlier provision discovery request. 1086 * 1087 * This callback handler can be set to %NULL if provision discovery 1088 * is not used or failures do not need to be indicated. 1089 */ 1090 void (*prov_disc_fail)(void *ctx, const u8 *peer, 1091 enum p2p_prov_disc_status status, 1092 u32 adv_id, const u8 *adv_mac, 1093 const char *deferred_session_resp); 1094 1095 /** 1096 * invitation_process - Optional callback for processing Invitations 1097 * @ctx: Callback context from cb_ctx 1098 * @sa: Source address of the Invitation Request 1099 * @bssid: P2P Group BSSID from the request or %NULL if not included 1100 * @go_dev_addr: GO Device Address from P2P Group ID 1101 * @ssid: SSID from P2P Group ID 1102 * @ssid_len: Length of ssid buffer in octets 1103 * @go: Variable for returning whether the local end is GO in the group 1104 * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO) 1105 * @force_freq: Variable for returning forced frequency for the group 1106 * @persistent_group: Whether this is an invitation to reinvoke a 1107 * persistent group (instead of invitation to join an active 1108 * group) 1109 * @channels: Available operating channels for the group 1110 * @dev_pw_id: Device Password ID for NFC static handover or -1 if not 1111 * used 1112 * @p2p2: Whether invitation request was wrapped in PASN authentication 1113 * received from a P2P2 device 1114 * @new_ssid: Pointer to hold new SSID 1115 * @new_ssid_len: Length of new SSID buffer in octets 1116 * Returns: Status code (P2P_SC_*) 1117 * 1118 * This optional callback can be used to implement persistent reconnect 1119 * by allowing automatic restarting of persistent groups without user 1120 * interaction. If this callback is not implemented (i.e., is %NULL), 1121 * the received Invitation Request frames are replied with 1122 * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the 1123 * invitation_result() callback. 1124 * 1125 * If the requested parameters are acceptable and the group is known, 1126 * %P2P_SC_SUCCESS may be returned. If the requested group is unknown, 1127 * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED 1128 * can be returned if there is not enough data to provide immediate 1129 * response, i.e., if some sort of user interaction is needed. The 1130 * invitation_received() callback will be called in that case 1131 * immediately after this call. 1132 */ 1133 u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid, 1134 const u8 *go_dev_addr, const u8 *ssid, 1135 size_t ssid_len, int *go, u8 *group_bssid, 1136 int *force_freq, int persistent_group, 1137 const struct p2p_channels *channels, 1138 int dev_pw_id, bool p2p2, const u8 **new_ssid, 1139 size_t *new_ssid_len); 1140 1141 /** 1142 * invitation_received - Callback on Invitation Request RX 1143 * @ctx: Callback context from cb_ctx 1144 * @sa: Source address of the Invitation Request 1145 * @bssid: P2P Group BSSID or %NULL if not received 1146 * @ssid: SSID of the group 1147 * @ssid_len: Length of ssid in octets 1148 * @go_dev_addr: GO Device Address 1149 * @status: Response Status 1150 * @op_freq: Operational frequency for the group 1151 * 1152 * This callback is used to indicate sending of an Invitation Response 1153 * for a received Invitation Request. If status == 0 (success), the 1154 * upper layer code is responsible for starting the group. status == 1 1155 * indicates need to get user authorization for the group. Other status 1156 * values indicate that the invitation request was rejected. 1157 */ 1158 void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid, 1159 const u8 *ssid, size_t ssid_len, 1160 const u8 *go_dev_addr, u8 status, 1161 int op_freq, const u8 *pmkid, const u8 *pmk, 1162 size_t pmk_len); 1163 1164 /** 1165 * invitation_result - Callback on Invitation result 1166 * @ctx: Callback context from cb_ctx 1167 * @status: Negotiation result (Status Code) 1168 * @new_ssid: New SSID received in invitation response 1169 * @new_ssid_len: Length of new SSID received 1170 * @bssid: P2P Group BSSID or %NULL if not received 1171 * @channels: Available operating channels for the group 1172 * @addr: Peer address 1173 * @freq: Frequency (in MHz) indicated during invitation or 0 1174 * @peer_oper_freq: Operating frequency (in MHz) advertized by the peer 1175 * during invitation or 0 1176 * @pmkid: PMKID used during invitation handshake 1177 * @pmk: The derived PMK 1178 * @pmk_len: PMK length in octets 1179 * @go_dev_addr: The P2P Device Address of the GO 1180 * 1181 * This callback is used to indicate result of an Invitation procedure 1182 * started with a call to p2p_invite(). The indicated status code is 1183 * the value received from the peer in Invitation Response with 0 1184 * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a 1185 * local failure in transmitting the Invitation Request. 1186 */ 1187 void (*invitation_result)(void *ctx, int status, const u8 *new_ssid, 1188 size_t new_ssid_len, const u8 *bssid, 1189 const struct p2p_channels *channels, 1190 const u8 *addr, int freq, int peer_oper_freq, 1191 const u8 *pmkid, const u8 *pmk, 1192 size_t pmk_len, const u8 *go_dev_addr); 1193 1194 /** 1195 * go_connected - Check whether we are connected to a GO 1196 * @ctx: Callback context from cb_ctx 1197 * @dev_addr: P2P Device Address of a GO 1198 * Returns: 1 if we are connected as a P2P client to the specified GO 1199 * or 0 if not. 1200 */ 1201 int (*go_connected)(void *ctx, const u8 *dev_addr); 1202 1203 /** 1204 * presence_resp - Callback on Presence Response 1205 * @ctx: Callback context from cb_ctx 1206 * @src: Source address (GO's P2P Interface Address) 1207 * @status: Result of the request (P2P_SC_*) 1208 * @noa: Returned NoA value 1209 * @noa_len: Length of the NoA buffer in octets 1210 */ 1211 void (*presence_resp)(void *ctx, const u8 *src, u8 status, 1212 const u8 *noa, size_t noa_len); 1213 1214 /** 1215 * is_concurrent_session_active - Check whether concurrent session is 1216 * active on other virtual interfaces 1217 * @ctx: Callback context from cb_ctx 1218 * Returns: 1 if concurrent session is active on other virtual interface 1219 * or 0 if not. 1220 */ 1221 int (*is_concurrent_session_active)(void *ctx); 1222 1223 /** 1224 * is_p2p_in_progress - Check whether P2P operation is in progress 1225 * @ctx: Callback context from cb_ctx 1226 * Returns: 1 if P2P operation (e.g., group formation) is in progress 1227 * or 0 if not. 1228 */ 1229 int (*is_p2p_in_progress)(void *ctx); 1230 1231 /** 1232 * Determine if we have a persistent group we share with remote peer 1233 * and allocate interface for this group if needed 1234 * @ctx: Callback context from cb_ctx 1235 * @addr: Peer device address to search for 1236 * @ssid: Persistent group SSID or %NULL if any 1237 * @ssid_len: Length of @ssid 1238 * @go_dev_addr: Buffer for returning GO P2P Device Address 1239 * @ret_ssid: Buffer for returning group SSID 1240 * @ret_ssid_len: Buffer for returning length of @ssid 1241 * @intended_iface_addr: Buffer for returning intended iface address 1242 * Returns: 1 if a matching persistent group was found, 0 otherwise 1243 */ 1244 int (*get_persistent_group)(void *ctx, const u8 *addr, const u8 *ssid, 1245 size_t ssid_len, u8 *go_dev_addr, 1246 u8 *ret_ssid, size_t *ret_ssid_len, 1247 u8 *intended_iface_addr); 1248 1249 /** 1250 * Get information about a possible local GO role 1251 * @ctx: Callback context from cb_ctx 1252 * @intended_addr: Buffer for returning intended GO interface address 1253 * @ssid: Buffer for returning group SSID 1254 * @ssid_len: Buffer for returning length of @ssid 1255 * @group_iface: Buffer for returning whether a separate group interface 1256 * would be used 1257 * @freq: Variable for returning the current operating frequency of a 1258 * currently running P2P GO. 1259 * Returns: 1 if GO info found, 0 otherwise 1260 * 1261 * This is used to compose New Group settings (SSID, and intended 1262 * address) during P2PS provisioning if results of provisioning *might* 1263 * result in our being an autonomous GO. 1264 */ 1265 int (*get_go_info)(void *ctx, u8 *intended_addr, 1266 u8 *ssid, size_t *ssid_len, int *group_iface, 1267 unsigned int *freq); 1268 1269 /** 1270 * remove_stale_groups - Remove stale P2PS groups 1271 * 1272 * Because P2PS stages *potential* GOs, and remote devices can remove 1273 * credentials unilaterally, we need to make sure we don't let stale 1274 * unusable groups build up. 1275 */ 1276 int (*remove_stale_groups)(void *ctx, const u8 *peer, const u8 *go, 1277 const u8 *ssid, size_t ssid_len); 1278 1279 /** 1280 * p2ps_prov_complete - P2PS provisioning complete 1281 * 1282 * When P2PS provisioning completes (successfully or not) we must 1283 * transmit all of the results to the upper layers. 1284 */ 1285 void (*p2ps_prov_complete)(void *ctx, enum p2p_status_code status, 1286 const u8 *dev, 1287 const u8 *adv_mac, const u8 *ses_mac, 1288 const u8 *grp_mac, u32 adv_id, u32 ses_id, 1289 u8 conncap, int passwd_id, 1290 const u8 *persist_ssid, 1291 size_t persist_ssid_size, int response_done, 1292 int prov_start, const char *session_info, 1293 const u8 *feat_cap, size_t feat_cap_len, 1294 unsigned int freq, const u8 *group_ssid, 1295 size_t group_ssid_len); 1296 1297 /** 1298 * prov_disc_resp_cb - Callback for indicating completion of PD Response 1299 * @ctx: Callback context from cb_ctx 1300 * Returns: 1 if operation was started, 0 otherwise 1301 * 1302 * This callback can be used to perform any pending actions after 1303 * provisioning. It is mainly used for P2PS pending group creation. 1304 */ 1305 int (*prov_disc_resp_cb)(void *ctx); 1306 1307 /** 1308 * p2ps_group_capability - Determine group capability 1309 * @ctx: Callback context from cb_ctx 1310 * @incoming: Peer requested roles, expressed with P2PS_SETUP_* bitmap. 1311 * @role: Local roles, expressed with P2PS_SETUP_* bitmap. 1312 * @force_freq: Variable for returning forced frequency for the group. 1313 * @pref_freq: Variable for returning preferred frequency for the group. 1314 * Returns: P2PS_SETUP_* bitmap of group capability result. 1315 * 1316 * This function can be used to determine group capability and 1317 * frequencies based on information from P2PS PD exchange and the 1318 * current state of ongoing groups and driver capabilities. 1319 */ 1320 u8 (*p2ps_group_capability)(void *ctx, u8 incoming, u8 role, 1321 unsigned int *force_freq, 1322 unsigned int *pref_freq); 1323 1324 /** 1325 * get_pref_freq_list - Get preferred frequency list for an interface 1326 * @ctx: Callback context from cb_ctx 1327 * @go: Whether the use if for GO role 1328 * @len: Length of freq_list in entries (both IN and OUT) 1329 * @freq_list: Buffer for returning the preferred frequencies (MHz) 1330 * Returns: 0 on success, -1 on failure 1331 * 1332 * This function can be used to query the preferred frequency list from 1333 * the driver specific to a particular interface type. 1334 */ 1335 int (*get_pref_freq_list)(void *ctx, int go, 1336 unsigned int *len, 1337 struct weighted_pcl *freq_list); 1338 1339 /** 1340 * register_bootstrap_comeback - Register timeout to initiate bootstrap 1341 * comeback request 1342 * @ctx: Callback context from cb_ctx 1343 * @addr: P2P Device Address to which comeback request is to be sent 1344 * @comeback_after: Time in TUs after which comeback request is sent 1345 * 1346 * This function can be used to send comeback request after given 1347 * timeout. 1348 */ 1349 void (*register_bootstrap_comeback)(void *ctx, const u8 *addr, 1350 u16 comeback_after); 1351 1352 /** 1353 * bootstrap_req_rx - Indicate bootstrap request from a P2P peer 1354 * @ctx: Callback context from cb_ctx 1355 * @addr: P2P device address from which bootstrap request was received 1356 * @bootstrap_method: Bootstrapping method request by the peer device 1357 * 1358 * This function can be used to notify that bootstrap request is 1359 * received from a P2P peer. 1360 */ 1361 void (*bootstrap_req_rx)(void *ctx, const u8 *addr, 1362 u16 bootstrap_method); 1363 1364 /** 1365 * bootstrap_rsp_rx - Indicate bootstrapping response from a P2P peer 1366 * @ctx: Callback context from cb_ctx 1367 * @addr: P2P device address with which bootstrapping is completed 1368 * @status: P2P Status Code of bootstrapping handshake 1369 * @freq: Frequency in which bootstrapping is done 1370 * @bootstrap_method: Bootstrapping method by the peer device 1371 * 1372 * This function can be used to notify the status of bootstrapping 1373 * handshake. 1374 */ 1375 void (*bootstrap_rsp_rx)(void *ctx, const u8 *addr, 1376 enum p2p_status_code status, int freq, 1377 u16 bootstrap_method); 1378 1379 /** 1380 * validate_dira - Indicate reception of DIRA to be validated against a 1381 * list of available device identity keys 1382 * @ctx: Callback context from cb_ctx 1383 * @peer_addr: P2P Device address of the peer 1384 * @dira_nonce: DIRA Nonce 1385 * @dira_tag: DIRA Tag 1386 * Returns: Identity block ID on success, 0 on failure 1387 * 1388 * This function can be used to validate DIRA and configure PMK of a 1389 * paired/persistent peer from configuration. The handler function is 1390 * expected to call p2p_pasn_pmksa_set_pmk() to set the PMK/PMKID in 1391 * case a matching entry is found. 1392 */ 1393 int (*validate_dira)(void *ctx, const u8 *peer_addr, 1394 const u8 *dira_nonce, const u8 *dira_tag); 1395 1396 /** 1397 * pasn_send_mgmt - Function handler to transmit a Management frame 1398 * @ctx: Callback context from cb_ctx 1399 * @data: Frame to transmit 1400 * @data_len: Length of frame to transmit 1401 * @noack: No ack flag 1402 * @freq: Frequency in MHz for the channel on which to transmit 1403 * @wait: How many milliseconds to wait for a response frame 1404 * Returns: 0 on success, -1 on failure 1405 */ 1406 int (*pasn_send_mgmt)(void *ctx, const u8 *data, size_t data_len, 1407 int noack, unsigned int freq, unsigned int wait); 1408 1409 /** 1410 * prepare_data_element - Function handler to update protocol specific 1411 * elements in PASN authentication frames 1412 * @ctx: Callback context from cb_ctx 1413 * @peer_addr: Peer MAC address 1414 * Returns: 0 on success, -1 on failure 1415 */ 1416 int (*prepare_data_element)(void *ctx, const u8 *peer_addr); 1417 1418 /** 1419 * parse_data_element - Function handler to parse P2P data element 1420 * @ctx: Callback context from cb_ctx 1421 * @data: Data to be parsed 1422 * @len: Length of data 1423 * Returns: 0 on success, -1 on failure 1424 */ 1425 int (*parse_data_element)(void *ctx, const u8 *data, size_t len); 1426 1427 /** 1428 * pasn_validate_pmkid - Function handler to validate RSN PMKID 1429 * @ctx: Callback context from cb_ctx 1430 * @addr: Peer MAC address 1431 * @pmkid: PMKID in the PASN frame 1432 * Returns: 0 on success, -1 on failure 1433 */ 1434 int (*pasn_validate_pmkid)(void *ctx, const u8 *addr, const u8 *pmkid); 1435 }; 1436 1437 1438 /* P2P module initialization/deinitialization */ 1439 1440 /** 1441 * p2p_init - Initialize P2P module 1442 * @cfg: P2P module configuration 1443 * Returns: Pointer to private data or %NULL on failure 1444 * 1445 * This function is used to initialize global P2P module context (one per 1446 * device). The P2P module will keep a copy of the configuration data, so the 1447 * caller does not need to maintain this structure. However, the callback 1448 * functions and the context parameters to them must be kept available until 1449 * the P2P module is deinitialized with p2p_deinit(). 1450 */ 1451 struct p2p_data * p2p_init(const struct p2p_config *cfg); 1452 1453 /** 1454 * p2p_deinit - Deinitialize P2P module 1455 * @p2p: P2P module context from p2p_init() 1456 */ 1457 void p2p_deinit(struct p2p_data *p2p); 1458 1459 /** 1460 * p2p_flush - Flush P2P module state 1461 * @p2p: P2P module context from p2p_init() 1462 * 1463 * This command removes the P2P module state like peer device entries. 1464 */ 1465 void p2p_flush(struct p2p_data *p2p); 1466 1467 /** 1468 * p2p_unauthorize - Unauthorize the specified peer device 1469 * @p2p: P2P module context from p2p_init() 1470 * @addr: P2P peer entry to be unauthorized 1471 * Returns: 0 on success, -1 on failure 1472 * 1473 * This command removes any connection authorization from the specified P2P 1474 * peer device address. This can be used, e.g., to cancel effect of a previous 1475 * p2p_authorize() or p2p_connect() call that has not yet resulted in completed 1476 * GO Negotiation. 1477 */ 1478 int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr); 1479 1480 /** 1481 * p2p_set_dev_name - Set device name 1482 * @p2p: P2P module context from p2p_init() 1483 * Returns: 0 on success, -1 on failure 1484 * 1485 * This function can be used to update the P2P module configuration with 1486 * information that was not available at the time of the p2p_init() call. 1487 */ 1488 int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name); 1489 1490 int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer); 1491 int p2p_set_model_name(struct p2p_data *p2p, const char *model_name); 1492 int p2p_set_model_number(struct p2p_data *p2p, const char *model_number); 1493 int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number); 1494 1495 void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods); 1496 void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid); 1497 1498 /** 1499 * p2p_set_pri_dev_type - Set primary device type 1500 * @p2p: P2P module context from p2p_init() 1501 * Returns: 0 on success, -1 on failure 1502 * 1503 * This function can be used to update the P2P module configuration with 1504 * information that was not available at the time of the p2p_init() call. 1505 */ 1506 int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type); 1507 1508 /** 1509 * p2p_set_sec_dev_types - Set secondary device types 1510 * @p2p: P2P module context from p2p_init() 1511 * Returns: 0 on success, -1 on failure 1512 * 1513 * This function can be used to update the P2P module configuration with 1514 * information that was not available at the time of the p2p_init() call. 1515 */ 1516 int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8], 1517 size_t num_dev_types); 1518 1519 int p2p_set_country(struct p2p_data *p2p, const char *country); 1520 1521 1522 /* Commands from upper layer management entity */ 1523 1524 enum p2p_discovery_type { 1525 P2P_FIND_START_WITH_FULL, 1526 P2P_FIND_ONLY_SOCIAL, 1527 P2P_FIND_PROGRESSIVE 1528 }; 1529 1530 /** 1531 * p2p_find - Start P2P Find (Device Discovery) 1532 * @p2p: P2P module context from p2p_init() 1533 * @timeout: Timeout for find operation in seconds or 0 for no timeout 1534 * @type: Device Discovery type 1535 * @num_req_dev_types: Number of requested device types 1536 * @req_dev_types: Requested device types array, must be an array 1537 * containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no 1538 * requested device types. 1539 * @dev_id: Device ID to search for or %NULL to find all devices 1540 * @search_delay: Extra delay in milliseconds between search iterations 1541 * @seek_count: Number of ASP Service Strings in the seek_string array 1542 * @seek_string: ASP Service Strings to query for in Probe Requests 1543 * @freq: Requested first scan frequency (in MHz) to modify type == 1544 * P2P_FIND_START_WITH_FULL behavior. 0 = Use normal full scan. 1545 * If p2p_find is already in progress, this parameter is ignored and full 1546 * scan will be executed. 1547 * @include_6ghz: Include 6 GHz channels in P2P find 1548 * Returns: 0 on success, -1 on failure 1549 */ 1550 int p2p_find(struct p2p_data *p2p, unsigned int timeout, 1551 enum p2p_discovery_type type, 1552 unsigned int num_req_dev_types, const u8 *req_dev_types, 1553 const u8 *dev_id, unsigned int search_delay, 1554 u8 seek_count, const char **seek_string, int freq, 1555 bool include_6ghz); 1556 1557 /** 1558 * p2p_notify_scan_trigger_status - Indicate scan trigger status 1559 * @p2p: P2P module context from p2p_init() 1560 * @status: 0 on success, -1 on failure 1561 */ 1562 void p2p_notify_scan_trigger_status(struct p2p_data *p2p, int status); 1563 1564 /** 1565 * p2p_stop_find - Stop P2P Find (Device Discovery) 1566 * @p2p: P2P module context from p2p_init() 1567 */ 1568 void p2p_stop_find(struct p2p_data *p2p); 1569 1570 /** 1571 * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq 1572 * @p2p: P2P module context from p2p_init() 1573 * @freq: Frequency in MHz for next operation 1574 * 1575 * This is like p2p_stop_find(), but Listen state is not stopped if we are 1576 * already on the same frequency. 1577 */ 1578 void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq); 1579 1580 /** 1581 * p2p_listen - Start P2P Listen state for specified duration 1582 * @p2p: P2P module context from p2p_init() 1583 * @timeout: Listen state duration in milliseconds 1584 * Returns: 0 on success, -1 on failure 1585 * 1586 * This function can be used to request the P2P module to keep the device 1587 * discoverable on the listen channel for an extended set of time. At least in 1588 * its current form, this is mainly used for testing purposes and may not be of 1589 * much use for normal P2P operations. 1590 */ 1591 int p2p_listen(struct p2p_data *p2p, unsigned int timeout); 1592 1593 /** 1594 * p2p_stop_listen - Stop P2P Listen 1595 * @p2p: P2P module context from p2p_init() 1596 */ 1597 void p2p_stop_listen(struct p2p_data *p2p); 1598 1599 /** 1600 * p2p_connect - Start P2P group formation (GO negotiation) 1601 * @p2p: P2P module context from p2p_init() 1602 * @peer_addr: MAC address of the peer P2P client 1603 * @wps_method: WPS method to be used in provisioning 1604 * @go_intent: Local GO intent value (1..15) 1605 * @own_interface_addr: Intended interface address to use with the group 1606 * @force_freq: The only allowed channel frequency in MHz or 0 1607 * @persistent_group: Whether to create a persistent group (0 = no, 1 = 1608 * persistent group without persistent reconnect, 2 = persistent group with 1609 * persistent reconnect) 1610 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate 1611 * a new SSID 1612 * @force_ssid_len: Length of $force_ssid buffer 1613 * @pd_before_go_neg: Whether to send Provision Discovery prior to GO 1614 * Negotiation as an interoperability workaround when initiating group 1615 * formation 1616 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if 1617 * force_freq == 0) 1618 * @oob_pw_id: OOB password identifier 1619 * @p2p2: Device supports P2P2 features 1620 * @bootstrap: Bootstrapping method requested for P2P2 provision discovery 1621 * @password: P2P2 pairing password or %NULL for opportunistic method 1622 * Returns: 0 on success, -1 on failure 1623 */ 1624 int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr, 1625 enum p2p_wps_method wps_method, 1626 int go_intent, const u8 *own_interface_addr, 1627 unsigned int force_freq, int persistent_group, 1628 const u8 *force_ssid, size_t force_ssid_len, 1629 int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id, 1630 bool p2p2, u16 bootstrap, const char *password); 1631 1632 /** 1633 * p2p_authorize - Authorize P2P group formation (GO negotiation) 1634 * @p2p: P2P module context from p2p_init() 1635 * @peer_addr: MAC address of the peer P2P client 1636 * @wps_method: WPS method to be used in provisioning 1637 * @go_intent: Local GO intent value (1..15) 1638 * @own_interface_addr: Intended interface address to use with the group 1639 * @force_freq: The only allowed channel frequency in MHz or 0 1640 * @persistent_group: Whether to create a persistent group (0 = no, 1 = 1641 * persistent group without persistent reconnect, 2 = persistent group with 1642 * persistent reconnect) 1643 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate 1644 * a new SSID 1645 * @force_ssid_len: Length of $force_ssid buffer 1646 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if 1647 * force_freq == 0) 1648 * @oob_pw_id: OOB password identifier 1649 * @bootstrap: Bootstrapping method requested for P2P2 provision discovery 1650 * @password: P2P2 pairing password or %NULL for opportunistic method 1651 * Returns: 0 on success, -1 on failure 1652 * 1653 * This is like p2p_connect(), but the actual group negotiation is not 1654 * initiated automatically, i.e., the other end is expected to do that. 1655 */ 1656 int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, 1657 enum p2p_wps_method wps_method, 1658 int go_intent, const u8 *own_interface_addr, 1659 unsigned int force_freq, int persistent_group, 1660 const u8 *force_ssid, size_t force_ssid_len, 1661 unsigned int pref_freq, u16 oob_pw_id, u16 bootstrap, 1662 const char *password); 1663 1664 /** 1665 * p2p_reject - Reject peer device (explicitly block connection attempts) 1666 * @p2p: P2P module context from p2p_init() 1667 * @peer_addr: MAC address of the peer P2P client 1668 * Returns: 0 on success, -1 on failure 1669 */ 1670 int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr); 1671 1672 /** 1673 * p2p_set_req_bootstrap_method - Send Provision Discovery Request to initiate 1674 * bootstrapping 1675 * @p2p: P2P module context from p2p_init() 1676 * @peer_addr: MAC address of the peer P2P client 1677 * @boostrap: Bootstrapping method 1678 * Returns: 0 on success, -1 on failure 1679 */ 1680 int p2p_set_req_bootstrap_method(struct p2p_data *p2p, const u8 *peer_addr, 1681 u16 bootstrap); 1682 1683 /** 1684 * p2p_prov_disc_req - Send Provision Discovery Request 1685 * @p2p: P2P module context from p2p_init() 1686 * @peer_addr: MAC address of the peer P2P client 1687 * @p2ps_prov: Provisioning info for P2PS 1688 * @config_methods: WPS Config Methods value (only one bit set) 1689 * @join: Whether this is used by a client joining an active group 1690 * @force_freq: Forced TX frequency for the frame (mainly for the join case) 1691 * @user_initiated_pd: Flag to indicate if initiated by user or not 1692 * Returns: 0 on success, -1 on failure 1693 * 1694 * This function can be used to request a discovered P2P peer to display a PIN 1695 * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us 1696 * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame 1697 * is transmitted once immediately and if no response is received, the frame 1698 * will be sent again whenever the target device is discovered during device 1699 * dsicovery (start with a p2p_find() call). Response from the peer is 1700 * indicated with the p2p_config::prov_disc_resp() callback. 1701 */ 1702 int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr, 1703 struct p2ps_provision *p2ps_prov, u16 config_methods, 1704 int join, int force_freq, 1705 int user_initiated_pd); 1706 1707 /** 1708 * p2p_sd_request - Schedule a service discovery query 1709 * @p2p: P2P module context from p2p_init() 1710 * @dst: Destination peer or %NULL to apply for all peers 1711 * @tlvs: P2P Service Query TLV(s) 1712 * Returns: Reference to the query or %NULL on failure 1713 * 1714 * Response to the query is indicated with the p2p_config::sd_response() 1715 * callback. 1716 */ 1717 void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst, 1718 const struct wpabuf *tlvs); 1719 1720 #ifdef CONFIG_WIFI_DISPLAY 1721 void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst, 1722 const struct wpabuf *tlvs); 1723 #endif /* CONFIG_WIFI_DISPLAY */ 1724 1725 /** 1726 * p2p_sd_cancel_request - Cancel a pending service discovery query 1727 * @p2p: P2P module context from p2p_init() 1728 * @req: Query reference from p2p_sd_request() 1729 * Returns: 0 if request for cancelled; -1 if not found 1730 */ 1731 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req); 1732 1733 /** 1734 * p2p_sd_response - Send response to a service discovery query 1735 * @p2p: P2P module context from p2p_init() 1736 * @freq: Frequency from p2p_config::sd_request() callback 1737 * @dst: Destination address from p2p_config::sd_request() callback 1738 * @dialog_token: Dialog token from p2p_config::sd_request() callback 1739 * @resp_tlvs: P2P Service Response TLV(s) 1740 * 1741 * This function is called as a response to the request indicated with 1742 * p2p_config::sd_request() callback. 1743 */ 1744 void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst, 1745 u8 dialog_token, const struct wpabuf *resp_tlvs); 1746 1747 /** 1748 * p2p_sd_service_update - Indicate a change in local services 1749 * @p2p: P2P module context from p2p_init() 1750 * 1751 * This function needs to be called whenever there is a change in availability 1752 * of the local services. This will increment the Service Update Indicator 1753 * value which will be used in SD Request and Response frames. 1754 */ 1755 void p2p_sd_service_update(struct p2p_data *p2p); 1756 1757 1758 enum p2p_invite_role { 1759 P2P_INVITE_ROLE_GO, 1760 P2P_INVITE_ROLE_ACTIVE_GO, 1761 P2P_INVITE_ROLE_CLIENT 1762 }; 1763 1764 /** 1765 * p2p_invite - Invite a P2P Device into a group 1766 * @p2p: P2P module context from p2p_init() 1767 * @peer: Device Address of the peer P2P Device 1768 * @role: Local role in the group 1769 * @bssid: Group BSSID or %NULL if not known 1770 * @ssid: Group SSID 1771 * @ssid_len: Length of ssid in octets 1772 * @force_freq: The only allowed channel frequency in MHz or 0 1773 * @go_dev_addr: Forced GO Device Address or %NULL if none 1774 * @persistent_group: Whether this is to reinvoke a persistent group 1775 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if 1776 * force_freq == 0) 1777 * @dev_pw_id: Device Password ID from OOB Device Password (NFC) static handover 1778 * case or -1 if not used 1779 * @p2p2: Operating in P2P2 mode 1780 * Returns: 0 on success, -1 on failure 1781 */ 1782 int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role, 1783 const u8 *bssid, const u8 *ssid, size_t ssid_len, 1784 unsigned int force_freq, const u8 *go_dev_addr, 1785 int persistent_group, unsigned int pref_freq, int dev_pw_id, 1786 bool p2p2); 1787 1788 /** 1789 * p2p_presence_req - Request GO presence 1790 * @p2p: P2P module context from p2p_init() 1791 * @go_interface_addr: GO P2P Interface Address 1792 * @own_interface_addr: Own P2P Interface Address for this group 1793 * @freq: Group operating frequence (in MHz) 1794 * @duration1: Preferred presence duration in microseconds 1795 * @interval1: Preferred presence interval in microseconds 1796 * @duration2: Acceptable presence duration in microseconds 1797 * @interval2: Acceptable presence interval in microseconds 1798 * Returns: 0 on success, -1 on failure 1799 * 1800 * If both duration and interval values are zero, the parameter pair is not 1801 * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0). 1802 */ 1803 int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr, 1804 const u8 *own_interface_addr, unsigned int freq, 1805 u32 duration1, u32 interval1, u32 duration2, 1806 u32 interval2); 1807 1808 /** 1809 * p2p_ext_listen - Set Extended Listen Timing 1810 * @p2p: P2P module context from p2p_init() 1811 * @freq: Group operating frequence (in MHz) 1812 * @period: Availability period in milliseconds (1-65535; 0 to disable) 1813 * @interval: Availability interval in milliseconds (1-65535; 0 to disable) 1814 * Returns: 0 on success, -1 on failure 1815 * 1816 * This function can be used to enable or disable (period = interval = 0) 1817 * Extended Listen Timing. When enabled, the P2P Device will become 1818 * discoverable (go into Listen State) every @interval milliseconds for at 1819 * least @period milliseconds. 1820 */ 1821 int p2p_ext_listen(struct p2p_data *p2p, unsigned int period, 1822 unsigned int interval); 1823 1824 /* Event notifications from upper layer management operations */ 1825 1826 /** 1827 * p2p_wps_success_cb - Report successfully completed WPS provisioning 1828 * @p2p: P2P module context from p2p_init() 1829 * @mac_addr: Peer address 1830 * 1831 * This function is used to report successfully completed WPS provisioning 1832 * during group formation in both GO/Registrar and client/Enrollee roles. 1833 */ 1834 void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr); 1835 1836 /** 1837 * p2p_group_formation_failed - Report failed WPS provisioning 1838 * @p2p: P2P module context from p2p_init() 1839 * 1840 * This function is used to report failed group formation. This can happen 1841 * either due to failed WPS provisioning or due to 15 second timeout during 1842 * the provisioning phase. 1843 */ 1844 void p2p_group_formation_failed(struct p2p_data *p2p); 1845 1846 /** 1847 * p2p_get_provisioning_info - Get any stored provisioning info 1848 * @p2p: P2P module context from p2p_init() 1849 * @addr: Peer P2P Device Address 1850 * Returns: WPS provisioning information (WPS config method) or 0 if no 1851 * information is available 1852 * 1853 * This function is used to retrieve stored WPS provisioning info for the given 1854 * peer. 1855 */ 1856 u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr); 1857 1858 /** 1859 * p2p_clear_provisioning_info - Clear any stored provisioning info 1860 * @p2p: P2P module context from p2p_init() 1861 * @iface_addr: Peer P2P Device Address 1862 * 1863 * This function is used to clear stored WPS provisioning info for the given 1864 * peer. 1865 */ 1866 void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr); 1867 1868 1869 /* Event notifications from lower layer driver operations */ 1870 1871 /** 1872 * enum p2p_probe_req_status 1873 * 1874 * @P2P_PREQ_MALFORMED: frame was not well-formed 1875 * @P2P_PREQ_NOT_LISTEN: device isn't in listen state, frame ignored 1876 * @P2P_PREQ_NOT_P2P: frame was not a P2P probe request 1877 * @P2P_PREQ_P2P_NOT_PROCESSED: frame was P2P but wasn't processed 1878 * @P2P_PREQ_P2P_PROCESSED: frame has been processed by P2P 1879 */ 1880 enum p2p_probe_req_status { 1881 P2P_PREQ_MALFORMED, 1882 P2P_PREQ_NOT_LISTEN, 1883 P2P_PREQ_NOT_P2P, 1884 P2P_PREQ_NOT_PROCESSED, 1885 P2P_PREQ_PROCESSED 1886 }; 1887 1888 /** 1889 * p2p_probe_req_rx - Report reception of a Probe Request frame 1890 * @p2p: P2P module context from p2p_init() 1891 * @addr: Source MAC address 1892 * @dst: Destination MAC address if available or %NULL 1893 * @bssid: BSSID if available or %NULL 1894 * @ie: Information elements from the Probe Request frame body 1895 * @ie_len: Length of ie buffer in octets 1896 * @rx_freq: Probe Request frame RX frequency 1897 * @p2p_lo_started: Whether P2P Listen Offload is started 1898 * Returns: value indicating the type and status of the probe request 1899 */ 1900 enum p2p_probe_req_status 1901 p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst, 1902 const u8 *bssid, const u8 *ie, size_t ie_len, 1903 unsigned int rx_freq, int p2p_lo_started); 1904 1905 /** 1906 * p2p_rx_action - Report received Action frame 1907 * @p2p: P2P module context from p2p_init() 1908 * @da: Destination address of the received Action frame 1909 * @sa: Source address of the received Action frame 1910 * @bssid: Address 3 of the received Action frame 1911 * @category: Category of the received Action frame 1912 * @data: Action frame body after the Category field 1913 * @len: Length of the data buffer in octets 1914 * @freq: Frequency (in MHz) on which the frame was received 1915 */ 1916 void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, 1917 const u8 *bssid, u8 category, 1918 const u8 *data, size_t len, int freq); 1919 1920 /** 1921 * p2p_scan_res_handler - Indicate a P2P scan results 1922 * @p2p: P2P module context from p2p_init() 1923 * @bssid: BSSID of the scan result 1924 * @freq: Frequency of the channel on which the device was found in MHz 1925 * @rx_time: Time when the result was received 1926 * @level: Signal level (signal strength of the received Beacon/Probe Response 1927 * frame) 1928 * @ies: Pointer to IEs from the scan result 1929 * @ies_len: Length of the ies buffer 1930 * Returns: 0 to continue or 1 to stop scan result indication 1931 * 1932 * This function is called to indicate a scan result entry with P2P IE from a 1933 * scan requested with struct p2p_config::p2p_scan(). This can be called during 1934 * the actual scan process (i.e., whenever a new device is found) or as a 1935 * sequence of calls after the full scan has been completed. The former option 1936 * can result in optimized operations, but may not be supported by all 1937 * driver/firmware designs. The ies buffer need to include at least the P2P IE, 1938 * but it is recommended to include all IEs received from the device. The 1939 * caller does not need to check that the IEs contain a P2P IE before calling 1940 * this function since frames will be filtered internally if needed. 1941 * 1942 * This function will return 1 if it wants to stop scan result iteration (and 1943 * scan in general if it is still in progress). This is used to allow faster 1944 * start of a pending operation, e.g., to start a pending GO negotiation. 1945 */ 1946 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, 1947 struct os_reltime *rx_time, int level, const u8 *ies, 1948 size_t ies_len); 1949 1950 /** 1951 * p2p_scan_res_handled - Indicate end of scan results 1952 * @p2p: P2P module context from p2p_init() 1953 * @delay: Search delay for next scan in ms 1954 * 1955 * This function is called to indicate that all P2P scan results from a scan 1956 * have been reported with zero or more calls to p2p_scan_res_handler(). This 1957 * function must be called as a response to successful 1958 * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler() 1959 * calls stopped iteration. 1960 */ 1961 void p2p_scan_res_handled(struct p2p_data *p2p, unsigned int delay); 1962 1963 enum p2p_send_action_result { 1964 P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */, 1965 P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */, 1966 P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */ 1967 }; 1968 1969 /** 1970 * p2p_send_action_cb - Notify TX status of an Action frame 1971 * @p2p: P2P module context from p2p_init() 1972 * @freq: Channel frequency in MHz 1973 * @dst: Destination MAC address (Address 1) 1974 * @src: Source MAC address (Address 2) 1975 * @bssid: BSSID (Address 3) 1976 * @result: Result of the transmission attempt 1977 * 1978 * This function is used to indicate the result of an Action frame transmission 1979 * that was requested with struct p2p_config::send_action() callback. 1980 */ 1981 void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst, 1982 const u8 *src, const u8 *bssid, 1983 enum p2p_send_action_result result); 1984 1985 /** 1986 * p2p_listen_cb - Indicate the start of a requested Listen state 1987 * @p2p: P2P module context from p2p_init() 1988 * @freq: Listen channel frequency in MHz 1989 * @duration: Duration for the Listen state in milliseconds 1990 * 1991 * This function is used to indicate that a Listen state requested with 1992 * struct p2p_config::start_listen() callback has started. 1993 */ 1994 void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq, 1995 unsigned int duration); 1996 1997 /** 1998 * p2p_listen_end - Indicate the end of a requested Listen state 1999 * @p2p: P2P module context from p2p_init() 2000 * @freq: Listen channel frequency in MHz 2001 * Returns: 0 if no operations were started, 1 if an operation was started 2002 * 2003 * This function is used to indicate that a Listen state requested with 2004 * struct p2p_config::start_listen() callback has ended. 2005 */ 2006 int p2p_listen_end(struct p2p_data *p2p, unsigned int freq); 2007 2008 void p2p_listen_failed(struct p2p_data *p2p, unsigned int freq); 2009 2010 void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, 2011 const u8 *ie, size_t ie_len); 2012 2013 void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, 2014 const u8 *ie, size_t ie_len); 2015 2016 2017 /* Per-group P2P state for GO */ 2018 2019 struct p2p_group; 2020 2021 /** 2022 * struct p2p_group_config - P2P group configuration 2023 * 2024 * This configuration is provided to the P2P module during initialization of 2025 * the per-group information with p2p_group_init(). 2026 */ 2027 struct p2p_group_config { 2028 /** 2029 * p2p2 - Whether the group was formed using P2P2 2030 */ 2031 bool p2p2; 2032 2033 /** 2034 * persistent_group - Whether the group is persistent 2035 * 0 = not a persistent group 2036 * 1 = persistent group without persistent reconnect 2037 * 2 = persistent group with persistent reconnect 2038 */ 2039 int persistent_group; 2040 2041 /** 2042 * interface_addr - P2P Interface Address of the group 2043 */ 2044 u8 interface_addr[ETH_ALEN]; 2045 2046 /** 2047 * max_clients - Maximum number of clients in the group 2048 */ 2049 unsigned int max_clients; 2050 2051 /** 2052 * ssid - Group SSID 2053 */ 2054 u8 ssid[SSID_MAX_LEN]; 2055 2056 /** 2057 * ssid_len - Length of SSID 2058 */ 2059 size_t ssid_len; 2060 2061 /** 2062 * freq - Operating channel of the group 2063 */ 2064 int freq; 2065 2066 /** 2067 * ip_addr_alloc - Whether IP address allocation within 4-way handshake 2068 * is supported 2069 */ 2070 int ip_addr_alloc; 2071 2072 /** 2073 * cb_ctx - Context to use with callback functions 2074 */ 2075 void *cb_ctx; 2076 2077 /** 2078 * ie_update - Notification of IE update 2079 * @ctx: Callback context from cb_ctx 2080 * @beacon_ies: P2P IE for Beacon frames or %NULL if no change 2081 * @proberesp_ies: P2P Ie for Probe Response frames 2082 * 2083 * P2P module uses this callback function to notify whenever the P2P IE 2084 * in Beacon or Probe Response frames should be updated based on group 2085 * events. 2086 * 2087 * The callee is responsible for freeing the returned buffer(s) with 2088 * wpabuf_free(). 2089 */ 2090 void (*ie_update)(void *ctx, struct wpabuf *beacon_ies, 2091 struct wpabuf *proberesp_ies); 2092 2093 /** 2094 * idle_update - Notification of changes in group idle state 2095 * @ctx: Callback context from cb_ctx 2096 * @idle: Whether the group is idle (no associated stations) 2097 */ 2098 void (*idle_update)(void *ctx, int idle); 2099 }; 2100 2101 /** 2102 * p2p_group_init - Initialize P2P group 2103 * @p2p: P2P module context from p2p_init() 2104 * @config: P2P group configuration (will be freed by p2p_group_deinit()) 2105 * Returns: Pointer to private data or %NULL on failure 2106 * 2107 * This function is used to initialize per-group P2P module context. Currently, 2108 * this is only used to manage GO functionality and P2P clients do not need to 2109 * create an instance of this per-group information. 2110 */ 2111 struct p2p_group * p2p_group_init(struct p2p_data *p2p, 2112 struct p2p_group_config *config); 2113 2114 /** 2115 * p2p_group_deinit - Deinitialize P2P group 2116 * @group: P2P group context from p2p_group_init() 2117 */ 2118 void p2p_group_deinit(struct p2p_group *group); 2119 2120 /** 2121 * p2p_group_notif_assoc - Notification of P2P client association with GO 2122 * @group: P2P group context from p2p_group_init() 2123 * @addr: Interface address of the P2P client 2124 * @ie: IEs from the (Re)association Request frame 2125 * @len: Length of the ie buffer in octets 2126 * Returns: 0 on success, -1 on failure 2127 */ 2128 int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr, 2129 const u8 *ie, size_t len); 2130 2131 /** 2132 * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response 2133 * @group: P2P group context from p2p_group_init() 2134 * @status: Status value (P2P_SC_SUCCESS if association succeeded) 2135 * Returns: P2P IE for (Re)association Response or %NULL on failure 2136 * 2137 * The caller is responsible for freeing the returned buffer with 2138 * wpabuf_free(). 2139 */ 2140 struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status); 2141 2142 /** 2143 * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO 2144 * @group: P2P group context from p2p_group_init() 2145 * @addr: Interface address of the P2P client 2146 */ 2147 void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr); 2148 2149 /** 2150 * p2p_group_notif_formation_done - Notification of completed group formation 2151 * @group: P2P group context from p2p_group_init() 2152 */ 2153 void p2p_group_notif_formation_done(struct p2p_group *group); 2154 2155 /** 2156 * p2p_group_notif_noa - Notification of NoA change 2157 * @group: P2P group context from p2p_group_init() 2158 * @noa: Notice of Absence attribute payload, %NULL if none 2159 * @noa_len: Length of noa buffer in octets 2160 * Returns: 0 on success, -1 on failure 2161 * 2162 * Notify the P2P group management about a new NoA contents. This will be 2163 * inserted into the P2P IEs in Beacon and Probe Response frames with rest of 2164 * the group information. 2165 */ 2166 int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa, 2167 size_t noa_len); 2168 2169 /** 2170 * p2p_group_match_dev_type - Match device types in group with requested type 2171 * @group: P2P group context from p2p_group_init() 2172 * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs) 2173 * Returns: 1 on match, 0 on mismatch 2174 * 2175 * This function can be used to match the Requested Device Type attribute in 2176 * WPS IE with the device types of a group member for deciding whether a GO 2177 * should reply to a Probe Request frame. Match will be reported if the WPS IE 2178 * is not requested any specific device type. 2179 */ 2180 int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps); 2181 2182 /** 2183 * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id 2184 */ 2185 int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p); 2186 2187 /** 2188 * p2p_group_go_discover - Send GO Discoverability Request to a group client 2189 * @group: P2P group context from p2p_group_init() 2190 * Returns: 0 on success (frame scheduled); -1 if client was not found 2191 */ 2192 int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id, 2193 const u8 *searching_dev, int rx_freq); 2194 2195 2196 /* Generic helper functions */ 2197 2198 /** 2199 * p2p_ie_text - Build text format description of P2P IE 2200 * @p2p_ie: P2P IE 2201 * @buf: Buffer for returning text 2202 * @end: Pointer to the end of the buf area 2203 * Returns: Number of octets written to the buffer or -1 on failure 2204 * 2205 * This function can be used to parse P2P IE contents into text format 2206 * field=value lines. 2207 */ 2208 int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end); 2209 2210 /** 2211 * p2p_scan_result_text - Build text format description of P2P IE 2212 * @ies: Information elements from scan results 2213 * @ies_len: ies buffer length in octets 2214 * @buf: Buffer for returning text 2215 * @end: Pointer to the end of the buf area 2216 * Returns: Number of octets written to the buffer or -1 on failure 2217 * 2218 * This function can be used to parse P2P IE contents into text format 2219 * field=value lines. 2220 */ 2221 int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end); 2222 2223 /** 2224 * p2p_parse_dev_addr_in_p2p_ie - Parse P2P Device Address from a concatenated 2225 * P2P IE 2226 * @p2p_ie: P2P IE 2227 * @dev_addr: Buffer for returning P2P Device Address 2228 * Returns: 0 on success or -1 if P2P Device Address could not be parsed 2229 */ 2230 int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr); 2231 2232 /** 2233 * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s) 2234 * @ies: Information elements from scan results 2235 * @ies_len: ies buffer length in octets 2236 * @dev_addr: Buffer for returning P2P Device Address 2237 * Returns: 0 on success or -1 if P2P Device Address could not be parsed 2238 */ 2239 int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr); 2240 2241 /** 2242 * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame 2243 * @p2p: P2P module context from p2p_init() 2244 * @bssid: BSSID 2245 * @buf: Buffer for writing the P2P IE 2246 * @len: Maximum buf length in octets 2247 * @p2p_group: Whether this is for association with a P2P GO 2248 * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none 2249 * Returns: Number of octets written into buf or -1 on failure 2250 */ 2251 int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, 2252 size_t len, int p2p_group, struct wpabuf *p2p_ie); 2253 2254 /** 2255 * p2p_scan_ie - Build P2P IE for Probe Request 2256 * @p2p: P2P module context from p2p_init() 2257 * @ies: Buffer for writing P2P IE 2258 * @dev_id: Device ID to search for or %NULL for any 2259 * @bands: Frequency bands used in the scan (enum wpa_radio_work_band bitmap) 2260 */ 2261 void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id, 2262 unsigned int bands); 2263 2264 /** 2265 * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie 2266 * @p2p: P2P module context from p2p_init() 2267 * Returns: Number of octets that p2p_scan_ie() may add to the buffer 2268 */ 2269 size_t p2p_scan_ie_buf_len(struct p2p_data *p2p); 2270 2271 /** 2272 * p2p_build_ssid - Generate a random P2P SSID 2273 * @p2p: P2P module context from p2p_init() 2274 * @ssid: Buffer for SSID 2275 * @ssid_len: Pointer to hold SSID length 2276 */ 2277 void p2p_build_ssid(struct p2p_data *p2p, u8 *ssid, size_t *ssid_len); 2278 2279 /** 2280 * p2p_go_params - Generate random P2P group parameters 2281 * @p2p: P2P module context from p2p_init() 2282 * @params: Buffer for parameters 2283 * Returns: 0 on success, -1 on failure 2284 */ 2285 int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params); 2286 2287 /** 2288 * p2p_set_go_role - Set the current role of P2P device 2289 * @p2p: P2P module context from p2p_init() 2290 * @val: 1 if P2P GO, 0 to reset the role variable 2291 * 2292 * This role is configured as P2P GO when authorizing a P2P Client to join the 2293 * group. Once PASN authentication with GO negotiation with predefined GO intent 2294 * values (15 for P2P GO) is completed, the role helps to configure PMK derived 2295 * during the PASN authentication. 2296 */ 2297 void p2p_set_go_role(struct p2p_data *p2p, bool val); 2298 2299 /** 2300 * p2p_get_group_capab - Get Group Capability from P2P IE data 2301 * @p2p_ie: P2P IE(s) contents 2302 * Returns: Group Capability 2303 */ 2304 u8 p2p_get_group_capab(const struct wpabuf *p2p_ie); 2305 2306 /** 2307 * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection 2308 * @p2p_ie: P2P IE(s) contents 2309 * Returns: 0 if cross connection is allow, 1 if not 2310 */ 2311 int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie); 2312 2313 /** 2314 * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data 2315 * @p2p_ie: P2P IE(s) contents 2316 * Returns: Pointer to P2P Device Address or %NULL if not included 2317 */ 2318 const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie); 2319 2320 /** 2321 * p2p_get_peer_info - Get P2P peer information 2322 * @p2p: P2P module context from p2p_init() 2323 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer 2324 * @next: Whether to select the peer entry following the one indicated by addr 2325 * Returns: Pointer to peer info or %NULL if not found 2326 */ 2327 const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p, 2328 const u8 *addr, int next); 2329 2330 /** 2331 * p2p_get_peer_info_txt - Get internal P2P peer information in text format 2332 * @info: Pointer to P2P peer info from p2p_get_peer_info() 2333 * @buf: Buffer for returning text 2334 * @buflen: Maximum buffer length 2335 * Returns: Number of octets written to the buffer or -1 on failure 2336 * 2337 * Note: This information is internal to the P2P module and subject to change. 2338 * As such, this should not really be used by external programs for purposes 2339 * other than debugging. 2340 */ 2341 int p2p_get_peer_info_txt(const struct p2p_peer_info *info, 2342 char *buf, size_t buflen); 2343 2344 /** 2345 * p2p_peer_known - Check whether P2P peer is known 2346 * @p2p: P2P module context from p2p_init() 2347 * @addr: P2P Device Address of the peer 2348 * Returns: 1 if the specified device is in the P2P peer table or 0 if not 2349 */ 2350 int p2p_peer_known(struct p2p_data *p2p, const u8 *addr); 2351 2352 /** 2353 * p2p_set_client_discoverability - Set client discoverability capability 2354 * @p2p: P2P module context from p2p_init() 2355 * @enabled: Whether client discoverability will be enabled 2356 * 2357 * This function can be used to disable (and re-enable) client discoverability. 2358 * This capability is enabled by default and should not be disabled in normal 2359 * use cases, i.e., this is mainly for testing purposes. 2360 */ 2361 void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled); 2362 2363 /** 2364 * p2p_set_managed_oper - Set managed P2P Device operations capability 2365 * @p2p: P2P module context from p2p_init() 2366 * @enabled: Whether managed P2P Device operations will be enabled 2367 */ 2368 void p2p_set_managed_oper(struct p2p_data *p2p, int enabled); 2369 2370 /** 2371 * p2p_config_get_random_social - Return a random social channel 2372 * @p2p: P2P config 2373 * @op_class: Selected operating class 2374 * @op_channel: Selected social channel 2375 * @avoid_list: Channel ranges to try to avoid or %NULL 2376 * @disallow_list: Channel ranges to discard or %NULL 2377 * Returns: 0 on success, -1 on failure 2378 * 2379 * This function is used before p2p_init is called. A random social channel 2380 * from supports bands 2.4 GHz (channels 1,6,11) and 60 GHz (channel 2) is 2381 * returned on success. 2382 */ 2383 int p2p_config_get_random_social(struct p2p_config *p2p, u8 *op_class, 2384 u8 *op_channel, 2385 struct wpa_freq_range_list *avoid_list, 2386 struct wpa_freq_range_list *disallow_list); 2387 2388 int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel, 2389 u8 forced); 2390 2391 u8 p2p_get_listen_channel(struct p2p_data *p2p); 2392 2393 int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len); 2394 2395 int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, 2396 u8 *iface_addr); 2397 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr, 2398 u8 *dev_addr); 2399 int p2p_get_dev_identity_key(struct p2p_data *p2p, const u8 *dev_addr, 2400 const u8 **dik_data, size_t *dik_len, u8 *cipher); 2401 2402 void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr); 2403 2404 /** 2405 * p2p_set_cross_connect - Set cross connection capability 2406 * @p2p: P2P module context from p2p_init() 2407 * @enabled: Whether cross connection will be enabled 2408 */ 2409 void p2p_set_cross_connect(struct p2p_data *p2p, int enabled); 2410 2411 int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr); 2412 2413 /** 2414 * p2p_set_intra_bss_dist - Set intra BSS distribution 2415 * @p2p: P2P module context from p2p_init() 2416 * @enabled: Whether intra BSS distribution will be enabled 2417 */ 2418 void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled); 2419 2420 int p2p_channels_includes_freq(const struct p2p_channels *channels, 2421 unsigned int freq); 2422 2423 int p2p_channels_to_freqs(const struct p2p_channels *channels, 2424 int *freq_list, unsigned int max_len); 2425 2426 /** 2427 * p2p_supported_freq - Check whether channel is supported for P2P 2428 * @p2p: P2P module context from p2p_init() 2429 * @freq: Channel frequency in MHz 2430 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P 2431 */ 2432 int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq); 2433 2434 /** 2435 * p2p_supported_freq_go - Check whether channel is supported for P2P GO operation 2436 * @p2p: P2P module context from p2p_init() 2437 * @freq: Channel frequency in MHz 2438 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P 2439 */ 2440 int p2p_supported_freq_go(struct p2p_data *p2p, unsigned int freq); 2441 2442 /** 2443 * p2p_supported_freq_cli - Check whether channel is supported for P2P client operation 2444 * @p2p: P2P module context from p2p_init() 2445 * @freq: Channel frequency in MHz 2446 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P 2447 */ 2448 int p2p_supported_freq_cli(struct p2p_data *p2p, unsigned int freq); 2449 2450 /** 2451 * p2p_get_pref_freq - Get channel from preferred channel list 2452 * @p2p: P2P module context from p2p_init() 2453 * @channels: List of channels 2454 * Returns: Preferred channel 2455 */ 2456 unsigned int p2p_get_pref_freq(struct p2p_data *p2p, 2457 const struct p2p_channels *channels); 2458 2459 void p2p_update_channel_list(struct p2p_data *p2p, 2460 const struct p2p_channels *chan, 2461 const struct p2p_channels *cli_chan); 2462 2463 bool is_p2p_6ghz_disabled(struct p2p_data *p2p); 2464 bool is_p2p_dfs_chan_enabled(struct p2p_data *p2p); 2465 2466 /** 2467 * p2p_set_best_channels - Update best channel information 2468 * @p2p: P2P module context from p2p_init() 2469 * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band 2470 * @freq_5: Frequency (MHz) of best channel in 5 GHz band 2471 * @freq_overall: Frequency (MHz) of best channel overall 2472 */ 2473 void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5, 2474 int freq_overall); 2475 2476 /** 2477 * p2p_set_own_freq_preference - Set own preference for channel 2478 * @p2p: P2P module context from p2p_init() 2479 * @freq: Frequency (MHz) of the preferred channel or 0 if no preference 2480 * 2481 * This function can be used to set a preference on the operating channel based 2482 * on frequencies used on the other virtual interfaces that share the same 2483 * radio. If non-zero, this is used to try to avoid multi-channel concurrency. 2484 */ 2485 void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq); 2486 2487 const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p); 2488 2489 /** 2490 * p2p_get_group_num_members - Get number of members in group 2491 * @group: P2P group context from p2p_group_init() 2492 * Returns: Number of members in the group 2493 */ 2494 unsigned int p2p_get_group_num_members(struct p2p_group *group); 2495 2496 /** 2497 * p2p_client_limit_reached - Check if client limit is reached 2498 * @group: P2P group context from p2p_group_init() 2499 * Returns: 1 if no of clients limit reached 2500 */ 2501 int p2p_client_limit_reached(struct p2p_group *group); 2502 2503 /** 2504 * p2p_iterate_group_members - Iterate group members 2505 * @group: P2P group context from p2p_group_init() 2506 * @next: iteration pointer, must be a pointer to a void * that is set to %NULL 2507 * on the first call and not modified later 2508 * Returns: A P2P Device Address for each call and %NULL for no more members 2509 */ 2510 const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next); 2511 2512 /** 2513 * p2p_group_get_client_interface_addr - Get P2P Interface Address of a client in a group 2514 * @group: P2P group context from p2p_group_init() 2515 * @dev_addr: P2P Device Address of the client 2516 * Returns: P2P Interface Address of the client if found or %NULL if no match 2517 * found 2518 */ 2519 const u8 * p2p_group_get_client_interface_addr(struct p2p_group *group, 2520 const u8 *dev_addr); 2521 2522 /** 2523 * p2p_group_get_dev_addr - Get a P2P Device Address of a client in a group 2524 * @group: P2P group context from p2p_group_init() 2525 * @addr: P2P Interface Address of the client 2526 * Returns: P2P Device Address of the client if found or %NULL if no match 2527 * found 2528 */ 2529 const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr); 2530 2531 /** 2532 * p2p_group_is_client_connected - Check whether a specific client is connected 2533 * @group: P2P group context from p2p_group_init() 2534 * @addr: P2P Device Address of the client 2535 * Returns: 1 if client is connected or 0 if not 2536 */ 2537 int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr); 2538 2539 /** 2540 * p2p_group_get_config - Get the group configuration 2541 * @group: P2P group context from p2p_group_init() 2542 * Returns: The group configuration pointer 2543 */ 2544 const struct p2p_group_config * p2p_group_get_config(struct p2p_group *group); 2545 2546 /** 2547 * p2p_loop_on_all_groups - Run the given callback on all groups 2548 * @p2p: P2P module context from p2p_init() 2549 * @group_callback: The callback function pointer 2550 * @user_data: Some user data pointer which can be %NULL 2551 * 2552 * The group_callback function can stop the iteration by returning 0. 2553 */ 2554 void p2p_loop_on_all_groups(struct p2p_data *p2p, 2555 int (*group_callback)(struct p2p_group *group, 2556 void *user_data), 2557 void *user_data); 2558 2559 /** 2560 * p2p_get_peer_found - Get P2P peer info structure of a found peer 2561 * @p2p: P2P module context from p2p_init() 2562 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer 2563 * @next: Whether to select the peer entry following the one indicated by addr 2564 * Returns: The first P2P peer info available or %NULL if no such peer exists 2565 */ 2566 const struct p2p_peer_info * 2567 p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next); 2568 2569 /** 2570 * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions 2571 * @p2p: P2P module context from p2p_init() 2572 */ 2573 void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p); 2574 2575 /** 2576 * p2p_add_wps_vendor_extension - Add a WPS vendor extension 2577 * @p2p: P2P module context from p2p_init() 2578 * @vendor_ext: The vendor extensions to add 2579 * Returns: 0 on success, -1 on failure 2580 * 2581 * The wpabuf structures in the array are owned by the P2P 2582 * module after this call. 2583 */ 2584 int p2p_add_wps_vendor_extension(struct p2p_data *p2p, 2585 const struct wpabuf *vendor_ext); 2586 2587 /** 2588 * p2p_set_oper_channel - Set the P2P operating channel 2589 * @p2p: P2P module context from p2p_init() 2590 * @op_reg_class: Operating regulatory class to set 2591 * @op_channel: operating channel to set 2592 * @cfg_op_channel : Whether op_channel is hardcoded in configuration 2593 * Returns: 0 on success, -1 on failure 2594 */ 2595 int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, 2596 int cfg_op_channel); 2597 2598 /** 2599 * p2p_set_pref_chan - Set P2P preferred channel list 2600 * @p2p: P2P module context from p2p_init() 2601 * @num_pref_chan: Number of entries in pref_chan list 2602 * @pref_chan: Preferred channels or %NULL to remove preferences 2603 * Returns: 0 on success, -1 on failure 2604 */ 2605 int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan, 2606 const struct p2p_channel *pref_chan); 2607 2608 /** 2609 * p2p_set_no_go_freq - Set no GO channel ranges 2610 * @p2p: P2P module context from p2p_init() 2611 * @list: Channel ranges or %NULL to remove restriction 2612 * Returns: 0 on success, -1 on failure 2613 */ 2614 int p2p_set_no_go_freq(struct p2p_data *p2p, 2615 const struct wpa_freq_range_list *list); 2616 2617 /** 2618 * p2p_in_progress - Check whether a P2P operation is progress 2619 * @p2p: P2P module context from p2p_init() 2620 * Returns: 0 if P2P module is idle, 1 if an operation is in progress but not 2621 * in search state, or 2 if search state operation is in progress 2622 */ 2623 int p2p_in_progress(struct p2p_data *p2p); 2624 2625 const char * p2p_wps_method_text(enum p2p_wps_method method); 2626 2627 /** 2628 * p2p_set_config_timeout - Set local config timeouts 2629 * @p2p: P2P module context from p2p_init() 2630 * @go_timeout: Time in 10 ms units it takes to start the GO mode 2631 * @client_timeout: Time in 10 ms units it takes to start the client mode 2632 */ 2633 void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout, 2634 u8 client_timeout); 2635 2636 int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie); 2637 int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie); 2638 int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie); 2639 int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie); 2640 int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie); 2641 int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie); 2642 int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie); 2643 int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie); 2644 int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem); 2645 int p2p_set_wfd_r2_dev_info(struct p2p_data *p2p, const struct wpabuf *elem); 2646 int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem); 2647 int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p, 2648 const struct wpabuf *elem); 2649 struct wpabuf * wifi_display_encaps(struct wpabuf *subelems); 2650 2651 /** 2652 * p2p_set_disc_int - Set min/max discoverable interval for p2p_find 2653 * @p2p: P2P module context from p2p_init() 2654 * @min_disc_int: minDiscoverableInterval (in units of 100 TU); default 1 2655 * @max_disc_int: maxDiscoverableInterval (in units of 100 TU); default 3 2656 * @max_disc_tu: Maximum number of TUs (1.024 ms) for discoverable interval; or 2657 * -1 not to limit 2658 * Returns: 0 on success, or -1 on failure 2659 * 2660 * This function can be used to configure minDiscoverableInterval and 2661 * maxDiscoverableInterval parameters for the Listen state during device 2662 * discovery (p2p_find). A random number of 100 TU units is picked for each 2663 * Listen state iteration from [min_disc_int,max_disc_int] range. 2664 * 2665 * max_disc_tu can be used to further limit the discoverable duration. However, 2666 * it should be noted that use of this parameter is not recommended since it 2667 * would not be compliant with the P2P specification. 2668 */ 2669 int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int, 2670 int max_disc_tu); 2671 2672 /** 2673 * p2p_get_state_txt - Get current P2P state for debug purposes 2674 * @p2p: P2P module context from p2p_init() 2675 * Returns: Name of the current P2P module state 2676 * 2677 * It should be noted that the P2P module state names are internal information 2678 * and subject to change at any point, i.e., this information should be used 2679 * mainly for debugging purposes. 2680 */ 2681 const char * p2p_get_state_txt(struct p2p_data *p2p); 2682 2683 struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p, 2684 int client_freq, 2685 const u8 *go_dev_addr, 2686 const u8 *ssid, size_t ssid_len); 2687 struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p, 2688 int client_freq, 2689 const u8 *go_dev_addr, 2690 const u8 *ssid, size_t ssid_len); 2691 2692 bool p2p_pref_freq_allowed(const struct weighted_pcl *freq_list, bool go); 2693 2694 struct p2p_nfc_params { 2695 int sel; 2696 const u8 *wsc_attr; 2697 size_t wsc_len; 2698 const u8 *p2p_attr; 2699 size_t p2p_len; 2700 2701 enum { 2702 NO_ACTION, JOIN_GROUP, AUTH_JOIN, INIT_GO_NEG, RESP_GO_NEG, 2703 BOTH_GO, PEER_CLIENT 2704 } next_step; 2705 struct p2p_peer_info *peer; 2706 u8 oob_dev_pw[WPS_OOB_PUBKEY_HASH_LEN + 2 + 2707 WPS_OOB_DEVICE_PASSWORD_LEN]; 2708 size_t oob_dev_pw_len; 2709 int go_freq; 2710 u8 go_dev_addr[ETH_ALEN]; 2711 u8 go_ssid[SSID_MAX_LEN]; 2712 size_t go_ssid_len; 2713 }; 2714 2715 int p2p_process_nfc_connection_handover(struct p2p_data *p2p, 2716 struct p2p_nfc_params *params); 2717 2718 void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id, 2719 int go_intent, 2720 const u8 *own_interface_addr); 2721 2722 int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len); 2723 2724 void p2p_loop_on_known_peers(struct p2p_data *p2p, 2725 void (*peer_callback)(struct p2p_peer_info *peer, 2726 void *user_data), 2727 void *user_data); 2728 2729 void p2p_set_vendor_elems(struct p2p_data *p2p, struct wpabuf **vendor_elem); 2730 2731 void p2p_set_intended_addr(struct p2p_data *p2p, const u8 *intended_addr); 2732 2733 struct p2ps_advertisement * 2734 p2p_service_p2ps_id(struct p2p_data *p2p, u32 adv_id); 2735 int p2p_service_add_asp(struct p2p_data *p2p, int auto_accept, u32 adv_id, 2736 const char *adv_str, u8 svc_state, 2737 u16 config_methods, const char *svc_info, 2738 const u8 *cpt_priority); 2739 int p2p_service_del_asp(struct p2p_data *p2p, u32 adv_id); 2740 void p2p_service_flush_asp(struct p2p_data *p2p); 2741 struct p2ps_advertisement * p2p_get_p2ps_adv_list(struct p2p_data *p2p); 2742 2743 /** 2744 * p2p_expire_peers - Periodic cleanup function to expire peers 2745 * @p2p: P2P module context from p2p_init() 2746 * 2747 * This is a cleanup function that the entity calling p2p_init() is 2748 * expected to call periodically to clean up expired peer entries. 2749 */ 2750 void p2p_expire_peers(struct p2p_data *p2p); 2751 2752 void p2p_set_own_pref_freq_list(struct p2p_data *p2p, 2753 const struct weighted_pcl *pref_freq_list, 2754 unsigned int size); 2755 void p2p_set_override_pref_op_chan(struct p2p_data *p2p, u8 op_class, 2756 u8 chan); 2757 2758 /** 2759 * p2p_group_get_common_freqs - Get the group common frequencies 2760 * @group: P2P group context from p2p_group_init() 2761 * @common_freqs: On return will hold the group common frequencies 2762 * @num: On return will hold the number of group common frequencies 2763 * Returns: 0 on success, -1 otherwise 2764 */ 2765 int p2p_group_get_common_freqs(struct p2p_group *group, int *common_freqs, 2766 unsigned int *num); 2767 2768 struct wpabuf * p2p_build_probe_resp_template(struct p2p_data *p2p, 2769 unsigned int freq); 2770 2771 void p2p_set_6ghz_dev_capab(struct p2p_data *p2p, bool allow_6ghz); 2772 bool is_p2p_6ghz_capable(struct p2p_data *p2p); 2773 bool p2p_is_peer_6ghz_capab(struct p2p_data *p2p, const u8 *addr); 2774 bool p2p_peer_wfd_enabled(struct p2p_data *p2p, const u8 *peer_addr); 2775 bool p2p_wfd_enabled(struct p2p_data *p2p); 2776 bool is_p2p_allow_6ghz(struct p2p_data *p2p); 2777 void set_p2p_allow_6ghz(struct p2p_data *p2p, bool value); 2778 int p2p_remove_6ghz_channels(struct weighted_pcl *pref_freq_list, int size); 2779 int p2p_channel_to_freq(int op_class, int channel); 2780 struct wpabuf * p2p_usd_elems(struct p2p_data *p2p); 2781 void p2p_process_usd_elems(struct p2p_data *p2p, const u8 *ies, u16 ies_len, 2782 const u8 *peer_addr, unsigned int freq); 2783 int p2p_get_dik_id(struct p2p_data *p2p, const u8 *peer); 2784 2785 void p2p_set_pairing_setup(struct p2p_data *p2p, int pairing_setup); 2786 void p2p_set_pairing_cache(struct p2p_data *p2p, int pairing_cache); 2787 void p2p_set_bootstrapmethods(struct p2p_data *p2p, int bootstrap_methods); 2788 void p2p_set_pasn_type(struct p2p_data *p2p, u8 pasn_type); 2789 void p2p_set_comeback_after(struct p2p_data *p2p, int comeback_after); 2790 void p2p_set_reg_info(struct p2p_data *p2p, u8 val); 2791 void p2p_set_twt_power_mgmt(struct p2p_data *p2p, int val); 2792 void p2p_set_dev_addr(struct p2p_data *p2p, const u8 *addr); 2793 void p2p_set_chan_switch_req_enable(struct p2p_data *p2p, bool val); 2794 void p2p_set_invitation_op_freq(struct p2p_data *p2p, int freq); 2795 2796 int p2p_get_listen_freq(struct p2p_data *p2p, const u8 *peer_addr); 2797 int p2p_initiate_pasn_auth(struct p2p_data *p2p, const u8 *addr, int freq); 2798 int p2p_initiate_pasn_verify(struct p2p_data *p2p, const u8 *peer_addr, 2799 int freq, enum p2p_invite_role role, 2800 const u8 *bssid, const u8 *ssid, size_t ssid_len, 2801 unsigned int force_freq, const u8 *go_dev_addr, 2802 unsigned int pref_freq); 2803 int p2p_pasn_auth_rx(struct p2p_data *p2p, const struct ieee80211_mgmt *mgmt, 2804 size_t len, int freq); 2805 int p2p_prepare_data_element(struct p2p_data *p2p, const u8 *peer_addr); 2806 int p2p_parse_data_element(struct p2p_data *p2p, const u8 *data, size_t len); 2807 int p2p_pasn_validate_and_update_pmkid(struct p2p_data *p2p, const u8 *addr, 2808 const u8 *pmkid); 2809 int p2p_pasn_auth_tx_status(struct p2p_data *p2p, const u8 *data, 2810 size_t data_len, bool acked, bool verify); 2811 int p2p_config_sae_password(struct p2p_data *p2p, const char *pw); 2812 void p2p_pasn_pmksa_set_pmk(struct p2p_data *p2p, const u8 *src, const u8 *dst, 2813 const u8 *pmk, size_t pmk_len, const u8 *pmkid); 2814 void p2p_set_store_pasn_ptk(struct p2p_data *p2p, u8 val); 2815 void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk); 2816 int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len); 2817 void p2p_usd_service_hash(struct p2p_data *p2p, const char *service_name); 2818 int p2p_get_dira_info(struct p2p_data *p2p, char *buf, size_t buflen); 2819 2820 #endif /* P2P_H */ 2821