p2p.h revision b5e8f06e18446918f6d801566e5709a8c87f1780
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/** 13 * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes 14 */ 15#define P2P_MAX_REG_CLASSES 10 16 17/** 18 * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class 19 */ 20#define P2P_MAX_REG_CLASS_CHANNELS 20 21 22/** 23 * struct p2p_channels - List of supported channels 24 */ 25struct p2p_channels { 26 /** 27 * struct p2p_reg_class - Supported regulatory class 28 */ 29 struct p2p_reg_class { 30 /** 31 * reg_class - Regulatory class (IEEE 802.11-2007, Annex J) 32 */ 33 u8 reg_class; 34 35 /** 36 * channel - Supported channels 37 */ 38 u8 channel[P2P_MAX_REG_CLASS_CHANNELS]; 39 40 /** 41 * channels - Number of channel entries in use 42 */ 43 size_t channels; 44 } reg_class[P2P_MAX_REG_CLASSES]; 45 46 /** 47 * reg_classes - Number of reg_class entries in use 48 */ 49 size_t reg_classes; 50}; 51 52enum p2p_wps_method { 53 WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC 54}; 55 56enum p2p_sd_action { 57 SRV_UPDATE, SRV_ADD, SRV_DEL, SRV_FLUSH 58}; 59 60/** 61 * struct p2p_go_neg_results - P2P Group Owner Negotiation results 62 */ 63struct p2p_go_neg_results { 64 /** 65 * status - Negotiation result (Status Code) 66 * 67 * 0 (P2P_SC_SUCCESS) indicates success. Non-zero values indicate 68 * failed negotiation. 69 */ 70 int status; 71 72 /** 73 * role_go - Whether local end is Group Owner 74 */ 75 int role_go; 76 77 /** 78 * freq - Frequency of the group operational channel in MHz 79 */ 80 int freq; 81 82 /** 83 * ssid - SSID of the group 84 */ 85 u8 ssid[32]; 86 87 /** 88 * ssid_len - Length of SSID in octets 89 */ 90 size_t ssid_len; 91 92 /** 93 * passphrase - WPA2-Personal passphrase for the group (GO only) 94 */ 95 char passphrase[64]; 96 97 /** 98 * peer_device_addr - P2P Device Address of the peer 99 */ 100 u8 peer_device_addr[ETH_ALEN]; 101 102 /** 103 * peer_interface_addr - P2P Interface Address of the peer 104 */ 105 u8 peer_interface_addr[ETH_ALEN]; 106 107 /** 108 * wps_method - WPS method to be used during provisioning 109 */ 110 enum p2p_wps_method wps_method; 111 112#define P2P_MAX_CHANNELS 50 113 114 /** 115 * freq_list - Zero-terminated list of possible operational channels 116 */ 117 int freq_list[P2P_MAX_CHANNELS]; 118 119 /** 120 * persistent_group - Whether the group should be made persistent 121 * 0 = not persistent 122 * 1 = persistent group without persistent reconnect 123 * 2 = persistent group with persistent reconnect 124 */ 125 int persistent_group; 126 127 /** 128 * peer_config_timeout - Peer configuration timeout (in 10 msec units) 129 */ 130 unsigned int peer_config_timeout; 131}; 132 133struct p2p_data; 134 135enum p2p_scan_type { 136 P2P_SCAN_SOCIAL, 137 P2P_SCAN_FULL, 138 P2P_SCAN_SPECIFIC, 139 P2P_SCAN_SOCIAL_PLUS_ONE 140}; 141 142#define P2P_MAX_WPS_VENDOR_EXT 10 143 144/** 145 * struct p2p_peer_info - P2P peer information 146 */ 147struct p2p_peer_info { 148 /** 149 * p2p_device_addr - P2P Device Address of the peer 150 */ 151 u8 p2p_device_addr[ETH_ALEN]; 152 153 /** 154 * pri_dev_type - Primary Device Type 155 */ 156 u8 pri_dev_type[8]; 157 158 /** 159 * device_name - Device Name (0..32 octets encoded in UTF-8) 160 */ 161 char device_name[33]; 162 163 /** 164 * manufacturer - Manufacturer (0..64 octets encoded in UTF-8) 165 */ 166 char manufacturer[65]; 167 168 /** 169 * model_name - Model Name (0..32 octets encoded in UTF-8) 170 */ 171 char model_name[33]; 172 173 /** 174 * model_number - Model Number (0..32 octets encoded in UTF-8) 175 */ 176 char model_number[33]; 177 178 /** 179 * serial_number - Serial Number (0..32 octets encoded in UTF-8) 180 */ 181 char serial_number[33]; 182 183 /** 184 * level - Signal level 185 */ 186 int level; 187 188 /** 189 * config_methods - WPS Configuration Methods 190 */ 191 u16 config_methods; 192 193 /** 194 * dev_capab - Device Capabilities 195 */ 196 u8 dev_capab; 197 198 /** 199 * group_capab - Group Capabilities 200 */ 201 u8 group_capab; 202 203 /** 204 * wps_sec_dev_type_list - WPS secondary device type list 205 * 206 * This list includes from 0 to 16 Secondary Device Types as indicated 207 * by wps_sec_dev_type_list_len (8 * number of types). 208 */ 209 u8 wps_sec_dev_type_list[128]; 210 211 /** 212 * wps_sec_dev_type_list_len - Length of secondary device type list 213 */ 214 size_t wps_sec_dev_type_list_len; 215 216 struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT]; 217}; 218 219enum p2p_prov_disc_status { 220 P2P_PROV_DISC_SUCCESS, 221 P2P_PROV_DISC_TIMEOUT, 222 P2P_PROV_DISC_REJECTED, 223}; 224 225struct p2p_channel { 226 u8 op_class; 227 u8 chan; 228}; 229 230/** 231 * struct p2p_config - P2P configuration 232 * 233 * This configuration is provided to the P2P module during initialization with 234 * p2p_init(). 235 */ 236struct p2p_config { 237 /** 238 * country - Country code to use in P2P operations 239 */ 240 char country[3]; 241 242 /** 243 * reg_class - Regulatory class for own listen channel 244 */ 245 u8 reg_class; 246 247 /** 248 * channel - Own listen channel 249 */ 250 u8 channel; 251 252 /** 253 * Regulatory class for own operational channel 254 */ 255 u8 op_reg_class; 256 257 /** 258 * op_channel - Own operational channel 259 */ 260 u8 op_channel; 261 262 /** 263 * cfg_op_channel - Whether op_channel is hardcoded in configuration 264 */ 265 u8 cfg_op_channel; 266 267 /** 268 * channels - Own supported regulatory classes and channels 269 * 270 * List of supposerted channels per regulatory class. The regulatory 271 * classes are defined in IEEE Std 802.11-2007 Annex J and the 272 * numbering of the clases depends on the configured country code. 273 */ 274 struct p2p_channels channels; 275 276 /** 277 * num_pref_chan - Number of pref_chan entries 278 */ 279 unsigned int num_pref_chan; 280 281 /** 282 * pref_chan - Preferred channels for GO Negotiation 283 */ 284 struct p2p_channel *pref_chan; 285 286 /** 287 * pri_dev_type - Primary Device Type (see WPS) 288 */ 289 u8 pri_dev_type[8]; 290 291 /** 292 * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types 293 */ 294#define P2P_SEC_DEVICE_TYPES 5 295 296 /** 297 * sec_dev_type - Optional secondary device types 298 */ 299 u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8]; 300 301 /** 302 * num_sec_dev_types - Number of sec_dev_type entries 303 */ 304 size_t num_sec_dev_types; 305 306 /** 307 * dev_addr - P2P Device Address 308 */ 309 u8 dev_addr[ETH_ALEN]; 310 311 /** 312 * dev_name - Device Name 313 */ 314 char *dev_name; 315 316 char *manufacturer; 317 char *model_name; 318 char *model_number; 319 char *serial_number; 320 321 u8 uuid[16]; 322 u16 config_methods; 323 324 /** 325 * concurrent_operations - Whether concurrent operations are supported 326 */ 327 int concurrent_operations; 328 329 /** 330 * max_peers - Maximum number of discovered peers to remember 331 * 332 * If more peers are discovered, older entries will be removed to make 333 * room for the new ones. 334 */ 335 size_t max_peers; 336 337 /** 338 * p2p_intra_bss - Intra BSS communication is supported 339 */ 340 int p2p_intra_bss; 341 342 /** 343 * ssid_postfix - Postfix data to add to the SSID 344 * 345 * This data will be added to the end of the SSID after the 346 * DIRECT-<random two octets> prefix. 347 */ 348 u8 ssid_postfix[32 - 9]; 349 350 /** 351 * ssid_postfix_len - Length of the ssid_postfix data 352 */ 353 size_t ssid_postfix_len; 354 355 /** 356 * msg_ctx - Context to use with wpa_msg() calls 357 */ 358 void *msg_ctx; 359 360 /** 361 * cb_ctx - Context to use with callback functions 362 */ 363 void *cb_ctx; 364 365 366 /* Callbacks to request lower layer driver operations */ 367 368 /** 369 * p2p_scan - Request a P2P scan/search 370 * @ctx: Callback context from cb_ctx 371 * @type: Scan type 372 * @freq: Specific frequency (MHz) to scan or 0 for no restriction 373 * @num_req_dev_types: Number of requested device types 374 * @req_dev_types: Array containing requested device types 375 * @dev_id: Device ID to search for or %NULL to find all devices 376 * @pw_id: Device Password ID 377 * Returns: 0 on success, -1 on failure 378 * 379 * This callback function is used to request a P2P scan or search 380 * operation to be completed. Type type argument specifies which type 381 * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the 382 * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL 383 * indicates that all channels are to be scanned. 384 * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels 385 * plus one extra channel specified by freq. 386 * 387 * The full scan is used for the initial scan to find group owners from 388 * all. The other types are used during search phase scan of the social 389 * channels (with potential variation if the Listen channel of the 390 * target peer is known or if other channels are scanned in steps). 391 * 392 * The scan results are returned after this call by calling 393 * p2p_scan_res_handler() for each scan result that has a P2P IE and 394 * then calling p2p_scan_res_handled() to indicate that all scan 395 * results have been indicated. 396 */ 397 int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq, 398 unsigned int num_req_dev_types, 399 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id); 400 401 /** 402 * send_probe_resp - Transmit a Probe Response frame 403 * @ctx: Callback context from cb_ctx 404 * @buf: Probe Response frame (including the header and body) 405 * Returns: 0 on success, -1 on failure 406 * 407 * This function is used to reply to Probe Request frames that were 408 * indicated with a call to p2p_probe_req_rx(). The response is to be 409 * sent on the same channel or to be dropped if the driver is not 410 * anymore listening to Probe Request frames. 411 * 412 * Alternatively, the responsibility for building the Probe Response 413 * frames in Listen state may be in another system component in which 414 * case this function need to be implemented (i.e., the function 415 * pointer can be %NULL). The WPS and P2P IEs to be added for Probe 416 * Response frames in such a case are available from the 417 * start_listen() callback. It should be noted that the received Probe 418 * Request frames must be indicated by calling p2p_probe_req_rx() even 419 * if this send_probe_resp() is not used. 420 */ 421 int (*send_probe_resp)(void *ctx, const struct wpabuf *buf); 422 423 /** 424 * send_action - Transmit an Action frame 425 * @ctx: Callback context from cb_ctx 426 * @freq: Frequency in MHz for the channel on which to transmit 427 * @dst: Destination MAC address (Address 1) 428 * @src: Source MAC address (Address 2) 429 * @bssid: BSSID (Address 3) 430 * @buf: Frame body (starting from Category field) 431 * @len: Length of buf in octets 432 * @wait_time: How many msec to wait for a response frame 433 * Returns: 0 on success, -1 on failure 434 * 435 * The Action frame may not be transmitted immediately and the status 436 * of the transmission must be reported by calling 437 * p2p_send_action_cb() once the frame has either been transmitted or 438 * it has been dropped due to excessive retries or other failure to 439 * transmit. 440 */ 441 int (*send_action)(void *ctx, unsigned int freq, const u8 *dst, 442 const u8 *src, const u8 *bssid, const u8 *buf, 443 size_t len, unsigned int wait_time); 444 445 /** 446 * send_action_done - Notify that Action frame sequence was completed 447 * @ctx: Callback context from cb_ctx 448 * 449 * This function is called when the Action frame sequence that was 450 * started with send_action() has been completed, i.e., when there is 451 * no need to wait for a response from the destination peer anymore. 452 */ 453 void (*send_action_done)(void *ctx); 454 455 /** 456 * start_listen - Start Listen state 457 * @ctx: Callback context from cb_ctx 458 * @freq: Frequency of the listen channel in MHz 459 * @duration: Duration for the Listen state in milliseconds 460 * @probe_resp_ie: IE(s) to be added to Probe Response frames 461 * Returns: 0 on success, -1 on failure 462 * 463 * This Listen state may not start immediately since the driver may 464 * have other pending operations to complete first. Once the Listen 465 * state has started, p2p_listen_cb() must be called to notify the P2P 466 * module. Once the Listen state is stopped, p2p_listen_end() must be 467 * called to notify the P2P module that the driver is not in the Listen 468 * state anymore. 469 * 470 * If the send_probe_resp() is not used for generating the response, 471 * the IEs from probe_resp_ie need to be added to the end of the Probe 472 * Response frame body. If send_probe_resp() is used, the probe_resp_ie 473 * information can be ignored. 474 */ 475 int (*start_listen)(void *ctx, unsigned int freq, 476 unsigned int duration, 477 const struct wpabuf *probe_resp_ie); 478 /** 479 * stop_listen - Stop Listen state 480 * @ctx: Callback context from cb_ctx 481 * 482 * This callback can be used to stop a Listen state operation that was 483 * previously requested with start_listen(). 484 */ 485 void (*stop_listen)(void *ctx); 486 487 /** 488 * get_noa - Get current Notice of Absence attribute payload 489 * @ctx: Callback context from cb_ctx 490 * @interface_addr: P2P Interface Address of the GO 491 * @buf: Buffer for returning NoA 492 * @buf_len: Buffer length in octets 493 * Returns: Number of octets used in buf, 0 to indicate no NoA is being 494 * advertized, or -1 on failure 495 * 496 * This function is used to fetch the current Notice of Absence 497 * attribute value from GO. 498 */ 499 int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf, 500 size_t buf_len); 501 502 /* Callbacks to notify events to upper layer management entity */ 503 504 /** 505 * dev_found - Notification of a found P2P Device 506 * @ctx: Callback context from cb_ctx 507 * @addr: Source address of the message triggering this notification 508 * @info: P2P peer information 509 * @new_device: Inform if the peer is newly found 510 * 511 * This callback is used to notify that a new P2P Device has been 512 * found. This may happen, e.g., during Search state based on scan 513 * results or during Listen state based on receive Probe Request and 514 * Group Owner Negotiation Request. 515 */ 516 void (*dev_found)(void *ctx, const u8 *addr, 517 const struct p2p_peer_info *info, 518 int new_device); 519 520 /** 521 * dev_lost - Notification of a lost P2P Device 522 * @ctx: Callback context from cb_ctx 523 * @dev_addr: P2P Device Address of the lost P2P Device 524 * 525 * This callback is used to notify that a P2P Device has been deleted. 526 */ 527 void (*dev_lost)(void *ctx, const u8 *dev_addr); 528 529 /** 530 * go_neg_req_rx - Notification of a receive GO Negotiation Request 531 * @ctx: Callback context from cb_ctx 532 * @src: Source address of the message triggering this notification 533 * @dev_passwd_id: WPS Device Password ID 534 * 535 * This callback is used to notify that a P2P Device is requesting 536 * group owner negotiation with us, but we do not have all the 537 * necessary information to start GO Negotiation. This indicates that 538 * the local user has not authorized the connection yet by providing a 539 * PIN or PBC button press. This information can be provided with a 540 * call to p2p_connect(). 541 */ 542 void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id); 543 544 /** 545 * go_neg_completed - Notification of GO Negotiation results 546 * @ctx: Callback context from cb_ctx 547 * @res: GO Negotiation results 548 * 549 * This callback is used to notify that Group Owner Negotiation has 550 * been completed. Non-zero struct p2p_go_neg_results::status indicates 551 * failed negotiation. In case of success, this function is responsible 552 * for creating a new group interface (or using the existing interface 553 * depending on driver features), setting up the group interface in 554 * proper mode based on struct p2p_go_neg_results::role_go and 555 * initializing WPS provisioning either as a Registrar (if GO) or as an 556 * Enrollee. Successful WPS provisioning must be indicated by calling 557 * p2p_wps_success_cb(). The callee is responsible for timing out group 558 * formation if WPS provisioning cannot be completed successfully 559 * within 15 seconds. 560 */ 561 void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res); 562 563 /** 564 * sd_request - Callback on Service Discovery Request 565 * @ctx: Callback context from cb_ctx 566 * @freq: Frequency (in MHz) of the channel 567 * @sa: Source address of the request 568 * @dialog_token: Dialog token 569 * @update_indic: Service Update Indicator from the source of request 570 * @tlvs: P2P Service Request TLV(s) 571 * @tlvs_len: Length of tlvs buffer in octets 572 * 573 * This callback is used to indicate reception of a service discovery 574 * request. Response to the query must be indicated by calling 575 * p2p_sd_response() with the context information from the arguments to 576 * this callback function. 577 * 578 * This callback handler can be set to %NULL to indicate that service 579 * discovery is not supported. 580 */ 581 void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token, 582 u16 update_indic, const u8 *tlvs, size_t tlvs_len); 583 584 /** 585 * sd_response - Callback on Service Discovery Response 586 * @ctx: Callback context from cb_ctx 587 * @sa: Source address of the request 588 * @update_indic: Service Update Indicator from the source of response 589 * @tlvs: P2P Service Response TLV(s) 590 * @tlvs_len: Length of tlvs buffer in octets 591 * 592 * This callback is used to indicate reception of a service discovery 593 * response. This callback handler can be set to %NULL if no service 594 * discovery requests are used. The information provided with this call 595 * is replies to the queries scheduled with p2p_sd_request(). 596 */ 597 void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic, 598 const u8 *tlvs, size_t tlvs_len); 599 600 /** 601 * prov_disc_req - Callback on Provisiong Discovery Request 602 * @ctx: Callback context from cb_ctx 603 * @peer: Source address of the request 604 * @config_methods: Requested WPS Config Method 605 * @dev_addr: P2P Device Address of the found P2P Device 606 * @pri_dev_type: Primary Device Type 607 * @dev_name: Device Name 608 * @supp_config_methods: Supported configuration Methods 609 * @dev_capab: Device Capabilities 610 * @group_capab: Group Capabilities 611 * @group_id: P2P Group ID (or %NULL if not included) 612 * @group_id_len: Length of P2P Group ID 613 * 614 * This callback is used to indicate reception of a Provision Discovery 615 * Request frame that the P2P module accepted. 616 */ 617 void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods, 618 const u8 *dev_addr, const u8 *pri_dev_type, 619 const char *dev_name, u16 supp_config_methods, 620 u8 dev_capab, u8 group_capab, 621 const u8 *group_id, size_t group_id_len); 622 623 /** 624 * prov_disc_resp - Callback on Provisiong Discovery Response 625 * @ctx: Callback context from cb_ctx 626 * @peer: Source address of the response 627 * @config_methods: Value from p2p_prov_disc_req() or 0 on failure 628 * 629 * This callback is used to indicate reception of a Provision Discovery 630 * Response frame for a pending request scheduled with 631 * p2p_prov_disc_req(). This callback handler can be set to %NULL if 632 * provision discovery is not used. 633 */ 634 void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods); 635 636 /** 637 * prov_disc_fail - Callback on Provision Discovery failure 638 * @ctx: Callback context from cb_ctx 639 * @peer: Source address of the response 640 * @status: Cause of failure, will not be %P2P_PROV_DISC_SUCCESS 641 * 642 * This callback is used to indicate either a failure or no response 643 * to an earlier provision discovery request. 644 * 645 * This callback handler can be set to %NULL if provision discovery 646 * is not used or failures do not need to be indicated. 647 */ 648 void (*prov_disc_fail)(void *ctx, const u8 *peer, 649 enum p2p_prov_disc_status status); 650 651 /** 652 * invitation_process - Optional callback for processing Invitations 653 * @ctx: Callback context from cb_ctx 654 * @sa: Source address of the Invitation Request 655 * @bssid: P2P Group BSSID from the request or %NULL if not included 656 * @go_dev_addr: GO Device Address from P2P Group ID 657 * @ssid: SSID from P2P Group ID 658 * @ssid_len: Length of ssid buffer in octets 659 * @go: Variable for returning whether the local end is GO in the group 660 * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO) 661 * @force_freq: Variable for returning forced frequency for the group 662 * @persistent_group: Whether this is an invitation to reinvoke a 663 * persistent group (instead of invitation to join an active 664 * group) 665 * Returns: Status code (P2P_SC_*) 666 * 667 * This optional callback can be used to implement persistent reconnect 668 * by allowing automatic restarting of persistent groups without user 669 * interaction. If this callback is not implemented (i.e., is %NULL), 670 * the received Invitation Request frames are replied with 671 * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the 672 * invitation_result() callback. 673 * 674 * If the requested parameters are acceptable and the group is known, 675 * %P2P_SC_SUCCESS may be returned. If the requested group is unknown, 676 * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED 677 * can be returned if there is not enough data to provide immediate 678 * response, i.e., if some sort of user interaction is needed. The 679 * invitation_received() callback will be called in that case 680 * immediately after this call. 681 */ 682 u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid, 683 const u8 *go_dev_addr, const u8 *ssid, 684 size_t ssid_len, int *go, u8 *group_bssid, 685 int *force_freq, int persistent_group); 686 687 /** 688 * invitation_received - Callback on Invitation Request RX 689 * @ctx: Callback context from cb_ctx 690 * @sa: Source address of the Invitation Request 691 * @bssid: P2P Group BSSID or %NULL if not received 692 * @ssid: SSID of the group 693 * @ssid_len: Length of ssid in octets 694 * @go_dev_addr: GO Device Address 695 * @status: Response Status 696 * @op_freq: Operational frequency for the group 697 * 698 * This callback is used to indicate sending of an Invitation Response 699 * for a received Invitation Request. If status == 0 (success), the 700 * upper layer code is responsible for starting the group. status == 1 701 * indicates need to get user authorization for the group. Other status 702 * values indicate that the invitation request was rejected. 703 */ 704 void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid, 705 const u8 *ssid, size_t ssid_len, 706 const u8 *go_dev_addr, u8 status, 707 int op_freq); 708 709 /** 710 * invitation_result - Callback on Invitation result 711 * @ctx: Callback context from cb_ctx 712 * @status: Negotiation result (Status Code) 713 * @bssid: P2P Group BSSID or %NULL if not received 714 * 715 * This callback is used to indicate result of an Invitation procedure 716 * started with a call to p2p_invite(). The indicated status code is 717 * the value received from the peer in Invitation Response with 0 718 * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a 719 * local failure in transmitting the Invitation Request. 720 */ 721 void (*invitation_result)(void *ctx, int status, const u8 *bssid); 722 723 /** 724 * go_connected - Check whether we are connected to a GO 725 * @ctx: Callback context from cb_ctx 726 * @dev_addr: P2P Device Address of a GO 727 * Returns: 1 if we are connected as a P2P client to the specified GO 728 * or 0 if not. 729 */ 730 int (*go_connected)(void *ctx, const u8 *dev_addr); 731}; 732 733 734/* P2P module initialization/deinitialization */ 735 736/** 737 * p2p_init - Initialize P2P module 738 * @cfg: P2P module configuration 739 * Returns: Pointer to private data or %NULL on failure 740 * 741 * This function is used to initialize global P2P module context (one per 742 * device). The P2P module will keep a copy of the configuration data, so the 743 * caller does not need to maintain this structure. However, the callback 744 * functions and the context parameters to them must be kept available until 745 * the P2P module is deinitialized with p2p_deinit(). 746 */ 747struct p2p_data * p2p_init(const struct p2p_config *cfg); 748 749/** 750 * p2p_deinit - Deinitialize P2P module 751 * @p2p: P2P module context from p2p_init() 752 */ 753void p2p_deinit(struct p2p_data *p2p); 754 755/** 756 * p2p_flush - Flush P2P module state 757 * @p2p: P2P module context from p2p_init() 758 * 759 * This command removes the P2P module state like peer device entries. 760 */ 761void p2p_flush(struct p2p_data *p2p); 762 763/** 764 * p2p_unauthorize - Unauthorize the specified peer device 765 * @p2p: P2P module context from p2p_init() 766 * @addr: P2P peer entry to be unauthorized 767 * Returns: 0 on success, -1 on failure 768 * 769 * This command removes any connection authorization from the specified P2P 770 * peer device address. This can be used, e.g., to cancel effect of a previous 771 * p2p_authorize() or p2p_connect() call that has not yet resulted in completed 772 * GO Negotiation. 773 */ 774int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr); 775 776/** 777 * p2p_set_dev_name - Set device name 778 * @p2p: P2P module context from p2p_init() 779 * Returns: 0 on success, -1 on failure 780 * 781 * This function can be used to update the P2P module configuration with 782 * information that was not available at the time of the p2p_init() call. 783 */ 784int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name); 785 786int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer); 787int p2p_set_model_name(struct p2p_data *p2p, const char *model_name); 788int p2p_set_model_number(struct p2p_data *p2p, const char *model_number); 789int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number); 790 791void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods); 792void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid); 793 794/** 795 * p2p_set_pri_dev_type - Set primary device type 796 * @p2p: P2P module context from p2p_init() 797 * Returns: 0 on success, -1 on failure 798 * 799 * This function can be used to update the P2P module configuration with 800 * information that was not available at the time of the p2p_init() call. 801 */ 802int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type); 803 804/** 805 * p2p_set_sec_dev_types - Set secondary device types 806 * @p2p: P2P module context from p2p_init() 807 * Returns: 0 on success, -1 on failure 808 * 809 * This function can be used to update the P2P module configuration with 810 * information that was not available at the time of the p2p_init() call. 811 */ 812int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8], 813 size_t num_dev_types); 814 815int p2p_set_country(struct p2p_data *p2p, const char *country); 816 817 818/* Commands from upper layer management entity */ 819 820enum p2p_discovery_type { 821 P2P_FIND_START_WITH_FULL, 822 P2P_FIND_ONLY_SOCIAL, 823 P2P_FIND_PROGRESSIVE 824}; 825 826/** 827 * p2p_find - Start P2P Find (Device Discovery) 828 * @p2p: P2P module context from p2p_init() 829 * @timeout: Timeout for find operation in seconds or 0 for no timeout 830 * @type: Device Discovery type 831 * @num_req_dev_types: Number of requested device types 832 * @req_dev_types: Requested device types array, must be an array 833 * containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no 834 * requested device types. 835 * @dev_id: Device ID to search for or %NULL to find all devices 836 * Returns: 0 on success, -1 on failure 837 */ 838int p2p_find(struct p2p_data *p2p, unsigned int timeout, 839 enum p2p_discovery_type type, 840 unsigned int num_req_dev_types, const u8 *req_dev_types, 841 const u8 *dev_id); 842 843/** 844 * p2p_stop_find - Stop P2P Find (Device Discovery) 845 * @p2p: P2P module context from p2p_init() 846 */ 847void p2p_stop_find(struct p2p_data *p2p); 848 849/** 850 * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq 851 * @p2p: P2P module context from p2p_init() 852 * @freq: Frequency in MHz for next operation 853 * 854 * This is like p2p_stop_find(), but Listen state is not stopped if we are 855 * already on the same frequency. 856 */ 857void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq); 858 859/** 860 * p2p_listen - Start P2P Listen state for specified duration 861 * @p2p: P2P module context from p2p_init() 862 * @timeout: Listen state duration in milliseconds 863 * Returns: 0 on success, -1 on failure 864 * 865 * This function can be used to request the P2P module to keep the device 866 * discoverable on the listen channel for an extended set of time. At least in 867 * its current form, this is mainly used for testing purposes and may not be of 868 * much use for normal P2P operations. 869 */ 870int p2p_listen(struct p2p_data *p2p, unsigned int timeout); 871 872/** 873 * p2p_connect - Start P2P group formation (GO negotiation) 874 * @p2p: P2P module context from p2p_init() 875 * @peer_addr: MAC address of the peer P2P client 876 * @wps_method: WPS method to be used in provisioning 877 * @go_intent: Local GO intent value (1..15) 878 * @own_interface_addr: Intended interface address to use with the group 879 * @force_freq: The only allowed channel frequency in MHz or 0 880 * @persistent_group: Whether to create a persistent group (0 = no, 1 = 881 * persistent group without persistent reconnect, 2 = persistent group with 882 * persistent reconnect) 883 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate 884 * a new SSID 885 * @force_ssid_len: Length of $force_ssid buffer 886 * @pd_before_go_neg: Whether to send Provision Discovery prior to GO 887 * Negotiation as an interoperability workaround when initiating group 888 * formation 889 * Returns: 0 on success, -1 on failure 890 */ 891int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr, 892 enum p2p_wps_method wps_method, 893 int go_intent, const u8 *own_interface_addr, 894 unsigned int force_freq, int persistent_group, 895 const u8 *force_ssid, size_t force_ssid_len, 896 int pd_before_go_neg); 897 898/** 899 * p2p_authorize - Authorize P2P group formation (GO negotiation) 900 * @p2p: P2P module context from p2p_init() 901 * @peer_addr: MAC address of the peer P2P client 902 * @wps_method: WPS method to be used in provisioning 903 * @go_intent: Local GO intent value (1..15) 904 * @own_interface_addr: Intended interface address to use with the group 905 * @force_freq: The only allowed channel frequency in MHz or 0 906 * @persistent_group: Whether to create a persistent group (0 = no, 1 = 907 * persistent group without persistent reconnect, 2 = persistent group with 908 * persistent reconnect) 909 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate 910 * a new SSID 911 * @force_ssid_len: Length of $force_ssid buffer 912 * Returns: 0 on success, -1 on failure 913 * 914 * This is like p2p_connect(), but the actual group negotiation is not 915 * initiated automatically, i.e., the other end is expected to do that. 916 */ 917int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, 918 enum p2p_wps_method wps_method, 919 int go_intent, const u8 *own_interface_addr, 920 unsigned int force_freq, int persistent_group, 921 const u8 *force_ssid, size_t force_ssid_len); 922 923/** 924 * p2p_reject - Reject peer device (explicitly block connection attempts) 925 * @p2p: P2P module context from p2p_init() 926 * @peer_addr: MAC address of the peer P2P client 927 * Returns: 0 on success, -1 on failure 928 */ 929int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr); 930 931/** 932 * p2p_prov_disc_req - Send Provision Discovery Request 933 * @p2p: P2P module context from p2p_init() 934 * @peer_addr: MAC address of the peer P2P client 935 * @config_methods: WPS Config Methods value (only one bit set) 936 * @join: Whether this is used by a client joining an active group 937 * @force_freq: Forced TX frequency for the frame (mainly for the join case) 938 * Returns: 0 on success, -1 on failure 939 * 940 * This function can be used to request a discovered P2P peer to display a PIN 941 * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us 942 * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame 943 * is transmitted once immediately and if no response is received, the frame 944 * will be sent again whenever the target device is discovered during device 945 * dsicovery (start with a p2p_find() call). Response from the peer is 946 * indicated with the p2p_config::prov_disc_resp() callback. 947 */ 948int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr, 949 u16 config_methods, int join, int force_freq); 950 951/** 952 * p2p_sd_request - Schedule a service discovery query 953 * @p2p: P2P module context from p2p_init() 954 * @dst: Destination peer or %NULL to apply for all peers 955 * @tlvs: P2P Service Query TLV(s) 956 * Returns: Reference to the query or %NULL on failure 957 * 958 * Response to the query is indicated with the p2p_config::sd_response() 959 * callback. 960 */ 961void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst, 962 const struct wpabuf *tlvs); 963 964/** 965 * p2p_sd_cancel_request - Cancel a pending service discovery query 966 * @p2p: P2P module context from p2p_init() 967 * @req: Query reference from p2p_sd_request() 968 * Returns: 0 if request for cancelled; -1 if not found 969 */ 970int p2p_sd_cancel_request(struct p2p_data *p2p, void *req); 971 972/** 973 * p2p_sd_response - Send response to a service discovery query 974 * @p2p: P2P module context from p2p_init() 975 * @freq: Frequency from p2p_config::sd_request() callback 976 * @dst: Destination address from p2p_config::sd_request() callback 977 * @dialog_token: Dialog token from p2p_config::sd_request() callback 978 * @resp_tlvs: P2P Service Response TLV(s) 979 * 980 * This function is called as a response to the request indicated with 981 * p2p_config::sd_request() callback. 982 */ 983void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst, 984 u8 dialog_token, const struct wpabuf *resp_tlvs); 985 986/** 987 * p2p_sd_service_update - Indicate a change in local services 988 * @p2p: P2P module context from p2p_init() 989 * 990 * This function needs to be called whenever there is a change in availability 991 * of the local services. This will increment the Service Update Indicator 992 * value which will be used in SD Request and Response frames. 993 */ 994#ifdef ANDROID_P2P 995void p2p_sd_service_update(struct p2p_data *p2p, int action); 996#else 997void p2p_sd_service_update(struct p2p_data *p2p); 998#endif 999 1000 1001enum p2p_invite_role { 1002 P2P_INVITE_ROLE_GO, 1003 P2P_INVITE_ROLE_ACTIVE_GO, 1004 P2P_INVITE_ROLE_CLIENT 1005}; 1006 1007/** 1008 * p2p_invite - Invite a P2P Device into a group 1009 * @p2p: P2P module context from p2p_init() 1010 * @peer: Device Address of the peer P2P Device 1011 * @role: Local role in the group 1012 * @bssid: Group BSSID or %NULL if not known 1013 * @ssid: Group SSID 1014 * @ssid_len: Length of ssid in octets 1015 * @force_freq: The only allowed channel frequency in MHz or 0 1016 * @go_dev_addr: Forced GO Device Address or %NULL if none 1017 * @persistent_group: Whether this is to reinvoke a persistent group 1018 * Returns: 0 on success, -1 on failure 1019 */ 1020int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role, 1021 const u8 *bssid, const u8 *ssid, size_t ssid_len, 1022 unsigned int force_freq, const u8 *go_dev_addr, 1023 int persistent_group); 1024 1025/** 1026 * p2p_presence_req - Request GO presence 1027 * @p2p: P2P module context from p2p_init() 1028 * @go_interface_addr: GO P2P Interface Address 1029 * @own_interface_addr: Own P2P Interface Address for this group 1030 * @freq: Group operating frequence (in MHz) 1031 * @duration1: Preferred presence duration in microseconds 1032 * @interval1: Preferred presence interval in microseconds 1033 * @duration2: Acceptable presence duration in microseconds 1034 * @interval2: Acceptable presence interval in microseconds 1035 * Returns: 0 on success, -1 on failure 1036 * 1037 * If both duration and interval values are zero, the parameter pair is not 1038 * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0). 1039 */ 1040int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr, 1041 const u8 *own_interface_addr, unsigned int freq, 1042 u32 duration1, u32 interval1, u32 duration2, 1043 u32 interval2); 1044 1045/** 1046 * p2p_ext_listen - Set Extended Listen Timing 1047 * @p2p: P2P module context from p2p_init() 1048 * @freq: Group operating frequence (in MHz) 1049 * @period: Availability period in milliseconds (1-65535; 0 to disable) 1050 * @interval: Availability interval in milliseconds (1-65535; 0 to disable) 1051 * Returns: 0 on success, -1 on failure 1052 * 1053 * This function can be used to enable or disable (period = interval = 0) 1054 * Extended Listen Timing. When enabled, the P2P Device will become 1055 * discoverable (go into Listen State) every @interval milliseconds for at 1056 * least @period milliseconds. 1057 */ 1058int p2p_ext_listen(struct p2p_data *p2p, unsigned int period, 1059 unsigned int interval); 1060 1061/* Event notifications from upper layer management operations */ 1062 1063/** 1064 * p2p_wps_success_cb - Report successfully completed WPS provisioning 1065 * @p2p: P2P module context from p2p_init() 1066 * @mac_addr: Peer address 1067 * 1068 * This function is used to report successfully completed WPS provisioning 1069 * during group formation in both GO/Registrar and client/Enrollee roles. 1070 */ 1071void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr); 1072 1073/** 1074 * p2p_group_formation_failed - Report failed WPS provisioning 1075 * @p2p: P2P module context from p2p_init() 1076 * 1077 * This function is used to report failed group formation. This can happen 1078 * either due to failed WPS provisioning or due to 15 second timeout during 1079 * the provisioning phase. 1080 */ 1081void p2p_group_formation_failed(struct p2p_data *p2p); 1082 1083/** 1084 * p2p_get_provisioning_info - Get any stored provisioning info 1085 * @p2p: P2P module context from p2p_init() 1086 * @addr: Peer P2P Device Address 1087 * Returns: WPS provisioning information (WPS config method) or 0 if no 1088 * information is available 1089 * 1090 * This function is used to retrieve stored WPS provisioning info for the given 1091 * peer. 1092 */ 1093u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr); 1094 1095/** 1096 * p2p_clear_provisioning_info - Clear any stored provisioning info 1097 * @p2p: P2P module context from p2p_init() 1098 * @iface_addr: Peer P2P Device Address 1099 * 1100 * This function is used to clear stored WPS provisioning info for the given 1101 * peer. 1102 */ 1103void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr); 1104 1105 1106/* Event notifications from lower layer driver operations */ 1107 1108/** 1109 * enum p2p_probe_req_status 1110 * 1111 * @P2P_PREQ_MALFORMED: frame was not well-formed 1112 * @P2P_PREQ_NOT_LISTEN: device isn't in listen state, frame ignored 1113 * @P2P_PREQ_NOT_P2P: frame was not a P2P probe request 1114 * @P2P_PREQ_P2P_NOT_PROCESSED: frame was P2P but wasn't processed 1115 * @P2P_PREQ_P2P_PROCESSED: frame has been processed by P2P 1116 */ 1117enum p2p_probe_req_status { 1118 P2P_PREQ_MALFORMED, 1119 P2P_PREQ_NOT_LISTEN, 1120 P2P_PREQ_NOT_P2P, 1121 P2P_PREQ_NOT_PROCESSED, 1122 P2P_PREQ_PROCESSED 1123}; 1124 1125/** 1126 * p2p_probe_req_rx - Report reception of a Probe Request frame 1127 * @p2p: P2P module context from p2p_init() 1128 * @addr: Source MAC address 1129 * @dst: Destination MAC address if available or %NULL 1130 * @bssid: BSSID if available or %NULL 1131 * @ie: Information elements from the Probe Request frame body 1132 * @ie_len: Length of ie buffer in octets 1133 * Returns: value indicating the type and status of the probe request 1134 */ 1135enum p2p_probe_req_status 1136p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst, 1137 const u8 *bssid, const u8 *ie, size_t ie_len); 1138 1139/** 1140 * p2p_rx_action - Report received Action frame 1141 * @p2p: P2P module context from p2p_init() 1142 * @da: Destination address of the received Action frame 1143 * @sa: Source address of the received Action frame 1144 * @bssid: Address 3 of the received Action frame 1145 * @category: Category of the received Action frame 1146 * @data: Action frame body after the Category field 1147 * @len: Length of the data buffer in octets 1148 * @freq: Frequency (in MHz) on which the frame was received 1149 */ 1150void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, 1151 const u8 *bssid, u8 category, 1152 const u8 *data, size_t len, int freq); 1153 1154/** 1155 * p2p_scan_res_handler - Indicate a P2P scan results 1156 * @p2p: P2P module context from p2p_init() 1157 * @bssid: BSSID of the scan result 1158 * @freq: Frequency of the channel on which the device was found in MHz 1159 * @level: Signal level (signal strength of the received Beacon/Probe Response 1160 * frame) 1161 * @ies: Pointer to IEs from the scan result 1162 * @ies_len: Length of the ies buffer 1163 * Returns: 0 to continue or 1 to stop scan result indication 1164 * 1165 * This function is called to indicate a scan result entry with P2P IE from a 1166 * scan requested with struct p2p_config::p2p_scan(). This can be called during 1167 * the actual scan process (i.e., whenever a new device is found) or as a 1168 * sequence of calls after the full scan has been completed. The former option 1169 * can result in optimized operations, but may not be supported by all 1170 * driver/firmware designs. The ies buffer need to include at least the P2P IE, 1171 * but it is recommended to include all IEs received from the device. The 1172 * caller does not need to check that the IEs contain a P2P IE before calling 1173 * this function since frames will be filtered internally if needed. 1174 * 1175 * This function will return 1 if it wants to stop scan result iteration (and 1176 * scan in general if it is still in progress). This is used to allow faster 1177 * start of a pending operation, e.g., to start a pending GO negotiation. 1178 */ 1179int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, 1180 int level, const u8 *ies, size_t ies_len); 1181 1182/** 1183 * p2p_scan_res_handled - Indicate end of scan results 1184 * @p2p: P2P module context from p2p_init() 1185 * 1186 * This function is called to indicate that all P2P scan results from a scan 1187 * have been reported with zero or more calls to p2p_scan_res_handler(). This 1188 * function must be called as a response to successful 1189 * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler() 1190 * calls stopped iteration. 1191 */ 1192void p2p_scan_res_handled(struct p2p_data *p2p); 1193 1194enum p2p_send_action_result { 1195 P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */, 1196 P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */, 1197 P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */ 1198}; 1199 1200/** 1201 * p2p_send_action_cb - Notify TX status of an Action frame 1202 * @p2p: P2P module context from p2p_init() 1203 * @freq: Channel frequency in MHz 1204 * @dst: Destination MAC address (Address 1) 1205 * @src: Source MAC address (Address 2) 1206 * @bssid: BSSID (Address 3) 1207 * @result: Result of the transmission attempt 1208 * 1209 * This function is used to indicate the result of an Action frame transmission 1210 * that was requested with struct p2p_config::send_action() callback. 1211 */ 1212void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst, 1213 const u8 *src, const u8 *bssid, 1214 enum p2p_send_action_result result); 1215 1216/** 1217 * p2p_listen_cb - Indicate the start of a requested Listen state 1218 * @p2p: P2P module context from p2p_init() 1219 * @freq: Listen channel frequency in MHz 1220 * @duration: Duration for the Listen state in milliseconds 1221 * 1222 * This function is used to indicate that a Listen state requested with 1223 * struct p2p_config::start_listen() callback has started. 1224 */ 1225void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq, 1226 unsigned int duration); 1227 1228/** 1229 * p2p_listen_end - Indicate the end of a requested Listen state 1230 * @p2p: P2P module context from p2p_init() 1231 * @freq: Listen channel frequency in MHz 1232 * Returns: 0 if no operations were started, 1 if an operation was started 1233 * 1234 * This function is used to indicate that a Listen state requested with 1235 * struct p2p_config::start_listen() callback has ended. 1236 */ 1237int p2p_listen_end(struct p2p_data *p2p, unsigned int freq); 1238 1239void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, 1240 const u8 *ie, size_t ie_len); 1241 1242void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, 1243 const u8 *ie, size_t ie_len); 1244 1245 1246/* Per-group P2P state for GO */ 1247 1248struct p2p_group; 1249 1250/** 1251 * struct p2p_group_config - P2P group configuration 1252 * 1253 * This configuration is provided to the P2P module during initialization of 1254 * the per-group information with p2p_group_init(). 1255 */ 1256struct p2p_group_config { 1257 /** 1258 * persistent_group - Whether the group is persistent 1259 * 0 = not a persistent group 1260 * 1 = persistent group without persistent reconnect 1261 * 2 = persistent group with persistent reconnect 1262 */ 1263 int persistent_group; 1264 1265 /** 1266 * interface_addr - P2P Interface Address of the group 1267 */ 1268 u8 interface_addr[ETH_ALEN]; 1269 1270 /** 1271 * max_clients - Maximum number of clients in the group 1272 */ 1273 unsigned int max_clients; 1274 1275 /** 1276 * ssid - Group SSID 1277 */ 1278 u8 ssid[32]; 1279 1280 /** 1281 * ssid_len - Length of SSID 1282 */ 1283 size_t ssid_len; 1284 1285 /** 1286 * cb_ctx - Context to use with callback functions 1287 */ 1288 void *cb_ctx; 1289 1290 /** 1291 * ie_update - Notification of IE update 1292 * @ctx: Callback context from cb_ctx 1293 * @beacon_ies: P2P IE for Beacon frames or %NULL if no change 1294 * @proberesp_ies: P2P Ie for Probe Response frames 1295 * 1296 * P2P module uses this callback function to notify whenever the P2P IE 1297 * in Beacon or Probe Response frames should be updated based on group 1298 * events. 1299 * 1300 * The callee is responsible for freeing the returned buffer(s) with 1301 * wpabuf_free(). 1302 */ 1303 void (*ie_update)(void *ctx, struct wpabuf *beacon_ies, 1304 struct wpabuf *proberesp_ies); 1305 1306 /** 1307 * idle_update - Notification of changes in group idle state 1308 * @ctx: Callback context from cb_ctx 1309 * @idle: Whether the group is idle (no associated stations) 1310 */ 1311 void (*idle_update)(void *ctx, int idle); 1312}; 1313 1314/** 1315 * p2p_group_init - Initialize P2P group 1316 * @p2p: P2P module context from p2p_init() 1317 * @config: P2P group configuration (will be freed by p2p_group_deinit()) 1318 * Returns: Pointer to private data or %NULL on failure 1319 * 1320 * This function is used to initialize per-group P2P module context. Currently, 1321 * this is only used to manage GO functionality and P2P clients do not need to 1322 * create an instance of this per-group information. 1323 */ 1324struct p2p_group * p2p_group_init(struct p2p_data *p2p, 1325 struct p2p_group_config *config); 1326 1327/** 1328 * p2p_group_deinit - Deinitialize P2P group 1329 * @group: P2P group context from p2p_group_init() 1330 */ 1331void p2p_group_deinit(struct p2p_group *group); 1332 1333/** 1334 * p2p_group_notif_assoc - Notification of P2P client association with GO 1335 * @group: P2P group context from p2p_group_init() 1336 * @addr: Interface address of the P2P client 1337 * @ie: IEs from the (Re)association Request frame 1338 * @len: Length of the ie buffer in octets 1339 * Returns: 0 on success, -1 on failure 1340 */ 1341int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr, 1342 const u8 *ie, size_t len); 1343 1344/** 1345 * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response 1346 * @group: P2P group context from p2p_group_init() 1347 * @status: Status value (P2P_SC_SUCCESS if association succeeded) 1348 * Returns: P2P IE for (Re)association Response or %NULL on failure 1349 * 1350 * The caller is responsible for freeing the returned buffer with 1351 * wpabuf_free(). 1352 */ 1353struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status); 1354 1355/** 1356 * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO 1357 * @group: P2P group context from p2p_group_init() 1358 * @addr: Interface address of the P2P client 1359 */ 1360void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr); 1361 1362/** 1363 * p2p_group_notif_formation_done - Notification of completed group formation 1364 * @group: P2P group context from p2p_group_init() 1365 */ 1366void p2p_group_notif_formation_done(struct p2p_group *group); 1367 1368/** 1369 * p2p_group_notif_noa - Notification of NoA change 1370 * @group: P2P group context from p2p_group_init() 1371 * @noa: Notice of Absence attribute payload, %NULL if none 1372 * @noa_len: Length of noa buffer in octets 1373 * Returns: 0 on success, -1 on failure 1374 * 1375 * Notify the P2P group management about a new NoA contents. This will be 1376 * inserted into the P2P IEs in Beacon and Probe Response frames with rest of 1377 * the group information. 1378 */ 1379int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa, 1380 size_t noa_len); 1381 1382/** 1383 * p2p_group_match_dev_type - Match device types in group with requested type 1384 * @group: P2P group context from p2p_group_init() 1385 * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs) 1386 * Returns: 1 on match, 0 on mismatch 1387 * 1388 * This function can be used to match the Requested Device Type attribute in 1389 * WPS IE with the device types of a group member for deciding whether a GO 1390 * should reply to a Probe Request frame. Match will be reported if the WPS IE 1391 * is not requested any specific device type. 1392 */ 1393int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps); 1394 1395/** 1396 * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id 1397 */ 1398int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p); 1399 1400/** 1401 * p2p_group_go_discover - Send GO Discoverability Request to a group client 1402 * @group: P2P group context from p2p_group_init() 1403 * Returns: 0 on success (frame scheduled); -1 if client was not found 1404 */ 1405int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id, 1406 const u8 *searching_dev, int rx_freq); 1407 1408 1409/* Generic helper functions */ 1410 1411/** 1412 * p2p_ie_text - Build text format description of P2P IE 1413 * @p2p_ie: P2P IE 1414 * @buf: Buffer for returning text 1415 * @end: Pointer to the end of the buf area 1416 * Returns: Number of octets written to the buffer or -1 on failure 1417 * 1418 * This function can be used to parse P2P IE contents into text format 1419 * field=value lines. 1420 */ 1421int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end); 1422 1423/** 1424 * p2p_scan_result_text - Build text format description of P2P IE 1425 * @ies: Information elements from scan results 1426 * @ies_len: ies buffer length in octets 1427 * @buf: Buffer for returning text 1428 * @end: Pointer to the end of the buf area 1429 * Returns: Number of octets written to the buffer or -1 on failure 1430 * 1431 * This function can be used to parse P2P IE contents into text format 1432 * field=value lines. 1433 */ 1434int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end); 1435 1436/** 1437 * p2p_parse_dev_addr_in_p2p_ie - Parse P2P Device Address from a concatenated 1438 * P2P IE 1439 * @p2p_ie: P2P IE 1440 * @dev_addr: Buffer for returning P2P Device Address 1441 * Returns: 0 on success or -1 if P2P Device Address could not be parsed 1442 */ 1443int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr); 1444 1445/** 1446 * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s) 1447 * @ies: Information elements from scan results 1448 * @ies_len: ies buffer length in octets 1449 * @dev_addr: Buffer for returning P2P Device Address 1450 * Returns: 0 on success or -1 if P2P Device Address could not be parsed 1451 */ 1452int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr); 1453 1454/** 1455 * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame 1456 * @p2p: P2P module context from p2p_init() 1457 * @bssid: BSSID 1458 * @buf: Buffer for writing the P2P IE 1459 * @len: Maximum buf length in octets 1460 * @p2p_group: Whether this is for association with a P2P GO 1461 * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none 1462 * Returns: Number of octets written into buf or -1 on failure 1463 */ 1464int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, 1465 size_t len, int p2p_group, struct wpabuf *p2p_ie); 1466 1467/** 1468 * p2p_scan_ie - Build P2P IE for Probe Request 1469 * @p2p: P2P module context from p2p_init() 1470 * @ies: Buffer for writing P2P IE 1471 * @dev_id: Device ID to search for or %NULL for any 1472 */ 1473void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id); 1474 1475/** 1476 * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie 1477 * @p2p: P2P module context from p2p_init() 1478 * Returns: Number of octets that p2p_scan_ie() may add to the buffer 1479 */ 1480size_t p2p_scan_ie_buf_len(struct p2p_data *p2p); 1481 1482/** 1483 * p2p_go_params - Generate random P2P group parameters 1484 * @p2p: P2P module context from p2p_init() 1485 * @params: Buffer for parameters 1486 * Returns: 0 on success, -1 on failure 1487 */ 1488int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params); 1489 1490/** 1491 * p2p_get_group_capab - Get Group Capability from P2P IE data 1492 * @p2p_ie: P2P IE(s) contents 1493 * Returns: Group Capability 1494 */ 1495u8 p2p_get_group_capab(const struct wpabuf *p2p_ie); 1496 1497/** 1498 * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection 1499 * @p2p_ie: P2P IE(s) contents 1500 * Returns: 0 if cross connection is allow, 1 if not 1501 */ 1502int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie); 1503 1504/** 1505 * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data 1506 * @p2p_ie: P2P IE(s) contents 1507 * Returns: Pointer to P2P Device Address or %NULL if not included 1508 */ 1509const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie); 1510 1511/** 1512 * p2p_get_peer_info - Get P2P peer information 1513 * @p2p: P2P module context from p2p_init() 1514 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer 1515 * @next: Whether to select the peer entry following the one indicated by addr 1516 * Returns: Pointer to peer info or %NULL if not found 1517 */ 1518const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p, 1519 const u8 *addr, int next); 1520 1521/** 1522 * p2p_get_peer_info_txt - Get internal P2P peer information in text format 1523 * @info: Pointer to P2P peer info from p2p_get_peer_info() 1524 * @buf: Buffer for returning text 1525 * @buflen: Maximum buffer length 1526 * Returns: Number of octets written to the buffer or -1 on failure 1527 * 1528 * Note: This information is internal to the P2P module and subject to change. 1529 * As such, this should not really be used by external programs for purposes 1530 * other than debugging. 1531 */ 1532int p2p_get_peer_info_txt(const struct p2p_peer_info *info, 1533 char *buf, size_t buflen); 1534 1535/** 1536 * p2p_peer_known - Check whether P2P peer is known 1537 * @p2p: P2P module context from p2p_init() 1538 * @addr: P2P Device Address of the peer 1539 * Returns: 1 if the specified device is in the P2P peer table or 0 if not 1540 */ 1541int p2p_peer_known(struct p2p_data *p2p, const u8 *addr); 1542 1543/** 1544 * p2p_set_client_discoverability - Set client discoverability capability 1545 * @p2p: P2P module context from p2p_init() 1546 * @enabled: Whether client discoverability will be enabled 1547 * 1548 * This function can be used to disable (and re-enable) client discoverability. 1549 * This capability is enabled by default and should not be disabled in normal 1550 * use cases, i.e., this is mainly for testing purposes. 1551 */ 1552void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled); 1553 1554/** 1555 * p2p_set_managed_oper - Set managed P2P Device operations capability 1556 * @p2p: P2P module context from p2p_init() 1557 * @enabled: Whether managed P2P Device operations will be enabled 1558 */ 1559void p2p_set_managed_oper(struct p2p_data *p2p, int enabled); 1560 1561int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel); 1562 1563int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len); 1564 1565int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, 1566 u8 *iface_addr); 1567int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr, 1568 u8 *dev_addr); 1569 1570void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr); 1571 1572/** 1573 * p2p_set_cross_connect - Set cross connection capability 1574 * @p2p: P2P module context from p2p_init() 1575 * @enabled: Whether cross connection will be enabled 1576 */ 1577void p2p_set_cross_connect(struct p2p_data *p2p, int enabled); 1578 1579int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr); 1580 1581/** 1582 * p2p_set_intra_bss_dist - Set intra BSS distribution 1583 * @p2p: P2P module context from p2p_init() 1584 * @enabled: Whether intra BSS distribution will be enabled 1585 */ 1586void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled); 1587 1588/** 1589 * p2p_supported_freq - Check whether channel is supported for P2P 1590 * @p2p: P2P module context from p2p_init() 1591 * @freq: Channel frequency in MHz 1592 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P 1593 */ 1594int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq); 1595 1596void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan); 1597 1598/** 1599 * p2p_set_best_channels - Update best channel information 1600 * @p2p: P2P module context from p2p_init() 1601 * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band 1602 * @freq_5: Frequency (MHz) of best channel in 5 GHz band 1603 * @freq_overall: Frequency (MHz) of best channel overall 1604 */ 1605void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5, 1606 int freq_overall); 1607 1608const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p); 1609 1610/** 1611 * p2p_get_group_num_members - Get number of members in group 1612 * @group: P2P group context from p2p_group_init() 1613 * Returns: Number of members in the group 1614 */ 1615unsigned int p2p_get_group_num_members(struct p2p_group *group); 1616 1617/** 1618 * p2p_iterate_group_members - Iterate group members 1619 * @group: P2P group context from p2p_group_init() 1620 * @next: iteration pointer, must be a pointer to a void * that is set to %NULL 1621 * on the first call and not modified later 1622 * Returns: A P2P Interface Address for each call and %NULL for no more members 1623 */ 1624const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next); 1625 1626/** 1627 * p2p_group_get_dev_addr - Get a P2P Device Address of a client in a group 1628 * @group: P2P group context from p2p_group_init() 1629 * @addr: P2P Interface Address of the client 1630 * Returns: P2P Device Address of the client if found or %NULL if no match 1631 * found 1632 */ 1633const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr); 1634 1635/** 1636 * p2p_group_is_client_connected - Check whether a specific client is connected 1637 * @group: P2P group context from p2p_group_init() 1638 * @addr: P2P Device Address of the client 1639 * Returns: 1 if client is connected or 0 if not 1640 */ 1641int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr); 1642 1643/** 1644 * p2p_get_peer_found - Get P2P peer info structure of a found peer 1645 * @p2p: P2P module context from p2p_init() 1646 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer 1647 * @next: Whether to select the peer entry following the one indicated by addr 1648 * Returns: The first P2P peer info available or %NULL if no such peer exists 1649 */ 1650const struct p2p_peer_info * 1651p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next); 1652 1653/** 1654 * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions 1655 * @p2p: P2P module context from p2p_init() 1656 */ 1657void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p); 1658 1659/** 1660 * p2p_add_wps_vendor_extension - Add a WPS vendor extension 1661 * @p2p: P2P module context from p2p_init() 1662 * @vendor_ext: The vendor extensions to add 1663 * Returns: 0 on success, -1 on failure 1664 * 1665 * The wpabuf structures in the array are owned by the P2P 1666 * module after this call. 1667 */ 1668int p2p_add_wps_vendor_extension(struct p2p_data *p2p, 1669 const struct wpabuf *vendor_ext); 1670 1671/** 1672 * p2p_set_oper_channel - Set the P2P operating channel 1673 * @p2p: P2P module context from p2p_init() 1674 * @op_reg_class: Operating regulatory class to set 1675 * @op_channel: operating channel to set 1676 * @cfg_op_channel : Whether op_channel is hardcoded in configuration 1677 * Returns: 0 on success, -1 on failure 1678 */ 1679int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, 1680 int cfg_op_channel); 1681 1682/** 1683 * p2p_set_pref_chan - Set P2P preferred channel list 1684 * @p2p: P2P module context from p2p_init() 1685 * @num_pref_chan: Number of entries in pref_chan list 1686 * @pref_chan: Preferred channels or %NULL to remove preferences 1687 * Returns: 0 on success, -1 on failure 1688 */ 1689int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan, 1690 const struct p2p_channel *pref_chan); 1691 1692/** 1693 * p2p_in_progress - Check whether a P2P operation is progress 1694 * @p2p: P2P module context from p2p_init() 1695 * Returns: 0 if P2P module is idle or 1 if an operation is in progress 1696 */ 1697int p2p_in_progress(struct p2p_data *p2p); 1698 1699#ifdef ANDROID_P2P 1700/** 1701 * p2p_search_in_progress - Check whether a P2P SEARCH is in progress 1702 * @p2p: P2P module context from p2p_init() 1703 * Returns: 0 if P2P module is idle or 1 if an operation is in progress 1704 */ 1705int p2p_search_in_progress(struct p2p_data *p2p); 1706 1707/** 1708 * p2p_search_pending - Check whether there is a deferred P2P SEARCH 1709 * @p2p: P2P module context from p2p_init() 1710 * Returns: 0 if there is no deferred P2P search or 1 if there is one 1711 */ 1712int p2p_search_pending(struct p2p_data *p2p); 1713#endif 1714 1715/** 1716 * p2p_other_scan_completed - Notify completion of non-P2P scan 1717 * @p2p: P2P module context from p2p_init() 1718 * Returns: 0 if P2P module is idle or 1 if an operation was started 1719 */ 1720int p2p_other_scan_completed(struct p2p_data *p2p); 1721 1722const char * p2p_wps_method_text(enum p2p_wps_method method); 1723 1724#endif /* P2P_H */ 1725