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