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