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