xref: /freebsd/contrib/wpa/src/p2p/p2p.h (revision 71e72c9e91c4b8007a4292e09669e8b549c29e97)
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 20
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 	/**
745 	 * Operating class for own operational channel in Invitation Response
746 	 */
747 	u8 inv_op_class;
748 
749 	/**
750 	 * inv_op_channel - Own operational channel in Invitation Response
751 	 */
752 	u8 inv_op_channel;
753 
754 	/**
755 	 * cb_ctx - Context to use with callback functions
756 	 */
757 	void *cb_ctx;
758 
759 	/**
760 	 * debug_print - Debug print
761 	 * @ctx: Callback context from cb_ctx
762 	 * @level: Debug verbosity level (MSG_*)
763 	 * @msg: Debug message
764 	 */
765 	void (*debug_print)(void *ctx, int level, const char *msg);
766 
767 
768 	/* Callbacks to request lower layer driver operations */
769 
770 	/**
771 	 * p2p_scan - Request a P2P scan/search
772 	 * @ctx: Callback context from cb_ctx
773 	 * @type: Scan type
774 	 * @freq: Specific frequency (MHz) to scan or 0 for no restriction
775 	 * @num_req_dev_types: Number of requested device types
776 	 * @req_dev_types: Array containing requested device types
777 	 * @dev_id: Device ID to search for or %NULL to find all devices
778 	 * @pw_id: Device Password ID
779 	 * @include_6ghz: Include 6 GHz channels in P2P scan
780 	 * Returns: 0 on success, -1 on failure
781 	 *
782 	 * This callback function is used to request a P2P scan or search
783 	 * operation to be completed. Type type argument specifies which type
784 	 * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the
785 	 * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL
786 	 * indicates that all channels are to be scanned. @P2P_SCAN_SPECIFIC
787 	 * request a scan of a single channel specified by freq.
788 	 * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels
789 	 * plus one extra channel specified by freq.
790 	 *
791 	 * The full scan is used for the initial scan to find group owners from
792 	 * all. The other types are used during search phase scan of the social
793 	 * channels (with potential variation if the Listen channel of the
794 	 * target peer is known or if other channels are scanned in steps).
795 	 *
796 	 * The scan results are returned after this call by calling
797 	 * p2p_scan_res_handler() for each scan result that has a P2P IE and
798 	 * then calling p2p_scan_res_handled() to indicate that all scan
799 	 * results have been indicated.
800 	 */
801 	int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq,
802 			unsigned int num_req_dev_types,
803 			const u8 *req_dev_types, const u8 *dev_id, u16 pw_id,
804 			bool include_6ghz);
805 
806 	/**
807 	 * send_probe_resp - Transmit a Probe Response frame
808 	 * @ctx: Callback context from cb_ctx
809 	 * @buf: Probe Response frame (including the header and body)
810 	 * @freq: Forced frequency (in MHz) to use or 0.
811 	 * Returns: 0 on success, -1 on failure
812 	 *
813 	 * This function is used to reply to Probe Request frames that were
814 	 * indicated with a call to p2p_probe_req_rx(). The response is to be
815 	 * sent on the same channel, unless otherwise specified, or to be
816 	 * dropped if the driver is not listening to Probe Request frames
817 	 * anymore.
818 	 *
819 	 * Alternatively, the responsibility for building the Probe Response
820 	 * frames in Listen state may be in another system component in which
821 	 * case this function need to be implemented (i.e., the function
822 	 * pointer can be %NULL). The WPS and P2P IEs to be added for Probe
823 	 * Response frames in such a case are available from the
824 	 * start_listen() callback. It should be noted that the received Probe
825 	 * Request frames must be indicated by calling p2p_probe_req_rx() even
826 	 * if this send_probe_resp() is not used.
827 	 */
828 	int (*send_probe_resp)(void *ctx, const struct wpabuf *buf,
829 			       unsigned int freq);
830 
831 	/**
832 	 * send_action - Transmit an Action frame
833 	 * @ctx: Callback context from cb_ctx
834 	 * @freq: Frequency in MHz for the channel on which to transmit
835 	 * @dst: Destination MAC address (Address 1)
836 	 * @src: Source MAC address (Address 2)
837 	 * @bssid: BSSID (Address 3)
838 	 * @buf: Frame body (starting from Category field)
839 	 * @len: Length of buf in octets
840 	 * @wait_time: How many msec to wait for a response frame
841 	 * @scheduled: Return value indicating whether the transmissions was
842 	 *	scheduled to happen once the radio is available
843 	 * Returns: 0 on success, -1 on failure
844 	 *
845 	 * The Action frame may not be transmitted immediately and the status
846 	 * of the transmission must be reported by calling
847 	 * p2p_send_action_cb() once the frame has either been transmitted or
848 	 * it has been dropped due to excessive retries or other failure to
849 	 * transmit.
850 	 */
851 	int (*send_action)(void *ctx, unsigned int freq, const u8 *dst,
852 			   const u8 *src, const u8 *bssid, const u8 *buf,
853 			   size_t len, unsigned int wait_time, int *scheduled);
854 
855 	/**
856 	 * send_action_done - Notify that Action frame sequence was completed
857 	 * @ctx: Callback context from cb_ctx
858 	 *
859 	 * This function is called when the Action frame sequence that was
860 	 * started with send_action() has been completed, i.e., when there is
861 	 * no need to wait for a response from the destination peer anymore.
862 	 */
863 	void (*send_action_done)(void *ctx);
864 
865 	/**
866 	 * start_listen - Start Listen state
867 	 * @ctx: Callback context from cb_ctx
868 	 * @freq: Frequency of the listen channel in MHz
869 	 * @duration: Duration for the Listen state in milliseconds
870 	 * @probe_resp_ie: IE(s) to be added to Probe Response frames
871 	 * Returns: 0 on success, -1 on failure
872 	 *
873 	 * This Listen state may not start immediately since the driver may
874 	 * have other pending operations to complete first. Once the Listen
875 	 * state has started, p2p_listen_cb() must be called to notify the P2P
876 	 * module. Once the Listen state is stopped, p2p_listen_end() must be
877 	 * called to notify the P2P module that the driver is not in the Listen
878 	 * state anymore.
879 	 *
880 	 * If the send_probe_resp() is not used for generating the response,
881 	 * the IEs from probe_resp_ie need to be added to the end of the Probe
882 	 * Response frame body. If send_probe_resp() is used, the probe_resp_ie
883 	 * information can be ignored.
884 	 */
885 	int (*start_listen)(void *ctx, unsigned int freq,
886 			    unsigned int duration,
887 			    const struct wpabuf *probe_resp_ie);
888 	/**
889 	 * stop_listen - Stop Listen state
890 	 * @ctx: Callback context from cb_ctx
891 	 *
892 	 * This callback can be used to stop a Listen state operation that was
893 	 * previously requested with start_listen().
894 	 */
895 	void (*stop_listen)(void *ctx);
896 
897 	/**
898 	 * get_noa - Get current Notice of Absence attribute payload
899 	 * @ctx: Callback context from cb_ctx
900 	 * @interface_addr: P2P Interface Address of the GO
901 	 * @buf: Buffer for returning NoA
902 	 * @buf_len: Buffer length in octets
903 	 * Returns: Number of octets used in buf, 0 to indicate no NoA is being
904 	 * advertized, or -1 on failure
905 	 *
906 	 * This function is used to fetch the current Notice of Absence
907 	 * attribute value from GO.
908 	 */
909 	int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf,
910 		       size_t buf_len);
911 
912 	/* Callbacks to notify events to upper layer management entity */
913 
914 	/**
915 	 * dev_found - Notification of a found P2P Device
916 	 * @ctx: Callback context from cb_ctx
917 	 * @addr: Source address of the message triggering this notification
918 	 * @info: P2P peer information
919 	 * @new_device: Inform if the peer is newly found
920 	 *
921 	 * This callback is used to notify that a new P2P Device has been
922 	 * found. This may happen, e.g., during Search state based on scan
923 	 * results or during Listen state based on receive Probe Request and
924 	 * Group Owner Negotiation Request.
925 	 */
926 	void (*dev_found)(void *ctx, const u8 *addr,
927 			  const struct p2p_peer_info *info,
928 			  int new_device);
929 
930 	/**
931 	 * dev_lost - Notification of a lost P2P Device
932 	 * @ctx: Callback context from cb_ctx
933 	 * @dev_addr: P2P Device Address of the lost P2P Device
934 	 *
935 	 * This callback is used to notify that a P2P Device has been deleted.
936 	 */
937 	void (*dev_lost)(void *ctx, const u8 *dev_addr);
938 
939 	/**
940 	 * find_stopped - Notification of a p2p_find operation stopping
941 	 * @ctx: Callback context from cb_ctx
942 	 */
943 	void (*find_stopped)(void *ctx);
944 
945 	/**
946 	 * go_neg_req_rx - Notification of a receive GO Negotiation Request
947 	 * @ctx: Callback context from cb_ctx
948 	 * @src: Source address of the message triggering this notification
949 	 * @dev_passwd_id: WPS Device Password ID
950 	 * @go_intent: Peer's GO Intent
951 	 *
952 	 * This callback is used to notify that a P2P Device is requesting
953 	 * group owner negotiation with us, but we do not have all the
954 	 * necessary information to start GO Negotiation. This indicates that
955 	 * the local user has not authorized the connection yet by providing a
956 	 * PIN or PBC button press. This information can be provided with a
957 	 * call to p2p_connect().
958 	 */
959 	void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id,
960 			      u8 go_intent);
961 
962 	/**
963 	 * go_neg_completed - Notification of GO Negotiation results
964 	 * @ctx: Callback context from cb_ctx
965 	 * @res: GO Negotiation results
966 	 *
967 	 * This callback is used to notify that Group Owner Negotiation has
968 	 * been completed. Non-zero struct p2p_go_neg_results::status indicates
969 	 * failed negotiation. In case of success, this function is responsible
970 	 * for creating a new group interface (or using the existing interface
971 	 * depending on driver features), setting up the group interface in
972 	 * proper mode based on struct p2p_go_neg_results::role_go and
973 	 * initializing WPS provisioning either as a Registrar (if GO) or as an
974 	 * Enrollee. Successful WPS provisioning must be indicated by calling
975 	 * p2p_wps_success_cb(). The callee is responsible for timing out group
976 	 * formation if WPS provisioning cannot be completed successfully
977 	 * within 15 seconds.
978 	 */
979 	void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res);
980 
981 	/**
982 	 * set_go_security_config - Set security configuration for P2P GO
983 	 * @ctx: Callback context from cb_ctx
984 	 * @res: GO Negotiation results
985 	 *
986 	 * This callback is used to set PMK/passphrase derived during PASN
987 	 * authentication with a P2P client. This will fetch an active P2P group
988 	 * owner instance and configure PMKSA in case of password based PASN, or
989 	 * configures the passphrase and derive PT in case of unauthenticated
990 	 * PASN.
991 	 */
992 	void (*set_go_security_config)(void *ctx,
993 				       struct p2p_go_neg_results *res);
994 
995 	/**
996 	 * sd_request - Callback on Service Discovery Request
997 	 * @ctx: Callback context from cb_ctx
998 	 * @freq: Frequency (in MHz) of the channel
999 	 * @sa: Source address of the request
1000 	 * @dialog_token: Dialog token
1001 	 * @update_indic: Service Update Indicator from the source of request
1002 	 * @tlvs: P2P Service Request TLV(s)
1003 	 * @tlvs_len: Length of tlvs buffer in octets
1004 	 *
1005 	 * This callback is used to indicate reception of a service discovery
1006 	 * request. Response to the query must be indicated by calling
1007 	 * p2p_sd_response() with the context information from the arguments to
1008 	 * this callback function.
1009 	 *
1010 	 * This callback handler can be set to %NULL to indicate that service
1011 	 * discovery is not supported.
1012 	 */
1013 	void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token,
1014 			   u16 update_indic, const u8 *tlvs, size_t tlvs_len);
1015 
1016 	/**
1017 	 * sd_response - Callback on Service Discovery Response
1018 	 * @ctx: Callback context from cb_ctx
1019 	 * @sa: Source address of the request
1020 	 * @update_indic: Service Update Indicator from the source of response
1021 	 * @tlvs: P2P Service Response TLV(s)
1022 	 * @tlvs_len: Length of tlvs buffer in octets
1023 	 *
1024 	 * This callback is used to indicate reception of a service discovery
1025 	 * response. This callback handler can be set to %NULL if no service
1026 	 * discovery requests are used. The information provided with this call
1027 	 * is replies to the queries scheduled with p2p_sd_request().
1028 	 */
1029 	void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic,
1030 			    const u8 *tlvs, size_t tlvs_len);
1031 
1032 	/**
1033 	 * prov_disc_req - Callback on Provisiong Discovery Request
1034 	 * @ctx: Callback context from cb_ctx
1035 	 * @peer: Source address of the request
1036 	 * @config_methods: Requested WPS Config Method
1037 	 * @dev_addr: P2P Device Address of the found P2P Device
1038 	 * @pri_dev_type: Primary Device Type
1039 	 * @dev_name: Device Name
1040 	 * @supp_config_methods: Supported configuration Methods
1041 	 * @dev_capab: Device Capabilities
1042 	 * @group_capab: Group Capabilities
1043 	 * @group_id: P2P Group ID (or %NULL if not included)
1044 	 * @group_id_len: Length of P2P Group ID
1045 	 *
1046 	 * This callback is used to indicate reception of a Provision Discovery
1047 	 * Request frame that the P2P module accepted.
1048 	 */
1049 	void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods,
1050 			      const u8 *dev_addr, const u8 *pri_dev_type,
1051 			      const char *dev_name, u16 supp_config_methods,
1052 			      u8 dev_capab, u8 group_capab,
1053 			      const u8 *group_id, size_t group_id_len);
1054 
1055 	/**
1056 	 * prov_disc_resp - Callback on Provisiong Discovery Response
1057 	 * @ctx: Callback context from cb_ctx
1058 	 * @peer: Source address of the response
1059 	 * @config_methods: Value from p2p_prov_disc_req() or 0 on failure
1060 	 *
1061 	 * This callback is used to indicate reception of a Provision Discovery
1062 	 * Response frame for a pending request scheduled with
1063 	 * p2p_prov_disc_req(). This callback handler can be set to %NULL if
1064 	 * provision discovery is not used.
1065 	 */
1066 	void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods);
1067 
1068 	/**
1069 	 * prov_disc_fail - Callback on Provision Discovery failure
1070 	 * @ctx: Callback context from cb_ctx
1071 	 * @peer: Source address of the response
1072 	 * @status: Cause of failure, will not be %P2P_PROV_DISC_SUCCESS
1073 	 * @adv_id: If non-zero, then the adv_id of the PD Request
1074 	 * @adv_mac: P2P Device Address of the advertizer
1075 	 * @deferred_session_resp: Deferred session response sent by advertizer
1076 	 *
1077 	 * This callback is used to indicate either a failure or no response
1078 	 * to an earlier provision discovery request.
1079 	 *
1080 	 * This callback handler can be set to %NULL if provision discovery
1081 	 * is not used or failures do not need to be indicated.
1082 	 */
1083 	void (*prov_disc_fail)(void *ctx, const u8 *peer,
1084 			       enum p2p_prov_disc_status status,
1085 			       u32 adv_id, const u8 *adv_mac,
1086 			       const char *deferred_session_resp);
1087 
1088 	/**
1089 	 * invitation_process - Optional callback for processing Invitations
1090 	 * @ctx: Callback context from cb_ctx
1091 	 * @sa: Source address of the Invitation Request
1092 	 * @bssid: P2P Group BSSID from the request or %NULL if not included
1093 	 * @go_dev_addr: GO Device Address from P2P Group ID
1094 	 * @ssid: SSID from P2P Group ID
1095 	 * @ssid_len: Length of ssid buffer in octets
1096 	 * @go: Variable for returning whether the local end is GO in the group
1097 	 * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO)
1098 	 * @force_freq: Variable for returning forced frequency for the group
1099 	 * @persistent_group: Whether this is an invitation to reinvoke a
1100 	 *	persistent group (instead of invitation to join an active
1101 	 *	group)
1102 	 * @channels: Available operating channels for the group
1103 	 * @dev_pw_id: Device Password ID for NFC static handover or -1 if not
1104 	 *	used
1105 	 * @p2p2: Whether invitation request was wrapped in PASN authentication
1106 	 * received from a P2P2 device
1107 	 * @new_ssid: Pointer to hold new SSID
1108 	 * @new_ssid_len: Length of new SSID buffer in octets
1109 	 * Returns: Status code (P2P_SC_*)
1110 	 *
1111 	 * This optional callback can be used to implement persistent reconnect
1112 	 * by allowing automatic restarting of persistent groups without user
1113 	 * interaction. If this callback is not implemented (i.e., is %NULL),
1114 	 * the received Invitation Request frames are replied with
1115 	 * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the
1116 	 * invitation_result() callback.
1117 	 *
1118 	 * If the requested parameters are acceptable and the group is known,
1119 	 * %P2P_SC_SUCCESS may be returned. If the requested group is unknown,
1120 	 * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED
1121 	 * can be returned if there is not enough data to provide immediate
1122 	 * response, i.e., if some sort of user interaction is needed. The
1123 	 * invitation_received() callback will be called in that case
1124 	 * immediately after this call.
1125 	 */
1126 	u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid,
1127 				 const u8 *go_dev_addr, const u8 *ssid,
1128 				 size_t ssid_len, int *go, u8 *group_bssid,
1129 				 int *force_freq, int persistent_group,
1130 				 const struct p2p_channels *channels,
1131 				 int dev_pw_id, bool p2p2, const u8 **new_ssid,
1132 				 size_t *new_ssid_len);
1133 
1134 	/**
1135 	 * invitation_received - Callback on Invitation Request RX
1136 	 * @ctx: Callback context from cb_ctx
1137 	 * @sa: Source address of the Invitation Request
1138 	 * @bssid: P2P Group BSSID or %NULL if not received
1139 	 * @ssid: SSID of the group
1140 	 * @ssid_len: Length of ssid in octets
1141 	 * @go_dev_addr: GO Device Address
1142 	 * @status: Response Status
1143 	 * @op_freq: Operational frequency for the group
1144 	 *
1145 	 * This callback is used to indicate sending of an Invitation Response
1146 	 * for a received Invitation Request. If status == 0 (success), the
1147 	 * upper layer code is responsible for starting the group. status == 1
1148 	 * indicates need to get user authorization for the group. Other status
1149 	 * values indicate that the invitation request was rejected.
1150 	 */
1151 	void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid,
1152 				    const u8 *ssid, size_t ssid_len,
1153 				    const u8 *go_dev_addr, u8 status,
1154 				    int op_freq, const u8 *pmkid, const u8 *pmk,
1155 				    size_t pmk_len);
1156 
1157 	/**
1158 	 * invitation_result - Callback on Invitation result
1159 	 * @ctx: Callback context from cb_ctx
1160 	 * @status: Negotiation result (Status Code)
1161 	 * @new_ssid: New SSID received in invitation response
1162 	 * @new_ssid_len: Length of new SSID received
1163 	 * @bssid: P2P Group BSSID or %NULL if not received
1164 	 * @channels: Available operating channels for the group
1165 	 * @addr: Peer address
1166 	 * @freq: Frequency (in MHz) indicated during invitation or 0
1167 	 * @peer_oper_freq: Operating frequency (in MHz) advertized by the peer
1168 	 * during invitation or 0
1169 	 * @pmkid: PMKID used during invitation handshake
1170 	 * @pmk: The derived PMK
1171 	 * @pmk_len: PMK length in octets
1172 	 * @go_dev_addr: The P2P Device Address of the GO
1173 	 *
1174 	 * This callback is used to indicate result of an Invitation procedure
1175 	 * started with a call to p2p_invite(). The indicated status code is
1176 	 * the value received from the peer in Invitation Response with 0
1177 	 * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a
1178 	 * local failure in transmitting the Invitation Request.
1179 	 */
1180 	void (*invitation_result)(void *ctx, int status, const u8 *new_ssid,
1181 				  size_t new_ssid_len, const u8 *bssid,
1182 				  const struct p2p_channels *channels,
1183 				  const u8 *addr, int freq, int peer_oper_freq,
1184 				  const u8 *pmkid, const u8 *pmk,
1185 				  size_t pmk_len, const u8 *go_dev_addr);
1186 
1187 	/**
1188 	 * go_connected - Check whether we are connected to a GO
1189 	 * @ctx: Callback context from cb_ctx
1190 	 * @dev_addr: P2P Device Address of a GO
1191 	 * Returns: 1 if we are connected as a P2P client to the specified GO
1192 	 * or 0 if not.
1193 	 */
1194 	int (*go_connected)(void *ctx, const u8 *dev_addr);
1195 
1196 	/**
1197 	 * presence_resp - Callback on Presence Response
1198 	 * @ctx: Callback context from cb_ctx
1199 	 * @src: Source address (GO's P2P Interface Address)
1200 	 * @status: Result of the request (P2P_SC_*)
1201 	 * @noa: Returned NoA value
1202 	 * @noa_len: Length of the NoA buffer in octets
1203 	 */
1204 	void (*presence_resp)(void *ctx, const u8 *src, u8 status,
1205 			      const u8 *noa, size_t noa_len);
1206 
1207 	/**
1208 	 * is_concurrent_session_active - Check whether concurrent session is
1209 	 * active on other virtual interfaces
1210 	 * @ctx: Callback context from cb_ctx
1211 	 * Returns: 1 if concurrent session is active on other virtual interface
1212 	 * or 0 if not.
1213 	 */
1214 	int (*is_concurrent_session_active)(void *ctx);
1215 
1216 	/**
1217 	 * is_p2p_in_progress - Check whether P2P operation is in progress
1218 	 * @ctx: Callback context from cb_ctx
1219 	 * Returns: 1 if P2P operation (e.g., group formation) is in progress
1220 	 * or 0 if not.
1221 	 */
1222 	int (*is_p2p_in_progress)(void *ctx);
1223 
1224 	/**
1225 	 * Determine if we have a persistent group we share with remote peer
1226 	 * and allocate interface for this group if needed
1227 	 * @ctx: Callback context from cb_ctx
1228 	 * @addr: Peer device address to search for
1229 	 * @ssid: Persistent group SSID or %NULL if any
1230 	 * @ssid_len: Length of @ssid
1231 	 * @go_dev_addr: Buffer for returning GO P2P Device Address
1232 	 * @ret_ssid: Buffer for returning group SSID
1233 	 * @ret_ssid_len: Buffer for returning length of @ssid
1234 	 * @intended_iface_addr: Buffer for returning intended iface address
1235 	 * Returns: 1 if a matching persistent group was found, 0 otherwise
1236 	 */
1237 	int (*get_persistent_group)(void *ctx, const u8 *addr, const u8 *ssid,
1238 				    size_t ssid_len, u8 *go_dev_addr,
1239 				    u8 *ret_ssid, size_t *ret_ssid_len,
1240 				    u8 *intended_iface_addr);
1241 
1242 	/**
1243 	 * Get information about a possible local GO role
1244 	 * @ctx: Callback context from cb_ctx
1245 	 * @intended_addr: Buffer for returning intended GO interface address
1246 	 * @ssid: Buffer for returning group SSID
1247 	 * @ssid_len: Buffer for returning length of @ssid
1248 	 * @group_iface: Buffer for returning whether a separate group interface
1249 	 *	would be used
1250 	 * @freq: Variable for returning the current operating frequency of a
1251 	 *	currently running P2P GO.
1252 	 * Returns: 1 if GO info found, 0 otherwise
1253 	 *
1254 	 * This is used to compose New Group settings (SSID, and intended
1255 	 * address) during P2PS provisioning if results of provisioning *might*
1256 	 * result in our being an autonomous GO.
1257 	 */
1258 	int (*get_go_info)(void *ctx, u8 *intended_addr,
1259 			   u8 *ssid, size_t *ssid_len, int *group_iface,
1260 			   unsigned int *freq);
1261 
1262 	/**
1263 	 * remove_stale_groups - Remove stale P2PS groups
1264 	 *
1265 	 * Because P2PS stages *potential* GOs, and remote devices can remove
1266 	 * credentials unilaterally, we need to make sure we don't let stale
1267 	 * unusable groups build up.
1268 	 */
1269 	int (*remove_stale_groups)(void *ctx, const u8 *peer, const u8 *go,
1270 				   const u8 *ssid, size_t ssid_len);
1271 
1272 	/**
1273 	 * p2ps_prov_complete - P2PS provisioning complete
1274 	 *
1275 	 * When P2PS provisioning completes (successfully or not) we must
1276 	 * transmit all of the results to the upper layers.
1277 	 */
1278 	void (*p2ps_prov_complete)(void *ctx, enum p2p_status_code status,
1279 				   const u8 *dev,
1280 				   const u8 *adv_mac, const u8 *ses_mac,
1281 				   const u8 *grp_mac, u32 adv_id, u32 ses_id,
1282 				   u8 conncap, int passwd_id,
1283 				   const u8 *persist_ssid,
1284 				   size_t persist_ssid_size, int response_done,
1285 				   int prov_start, const char *session_info,
1286 				   const u8 *feat_cap, size_t feat_cap_len,
1287 				   unsigned int freq, const u8 *group_ssid,
1288 				   size_t group_ssid_len);
1289 
1290 	/**
1291 	 * prov_disc_resp_cb - Callback for indicating completion of PD Response
1292 	 * @ctx: Callback context from cb_ctx
1293 	 * Returns: 1 if operation was started, 0 otherwise
1294 	 *
1295 	 * This callback can be used to perform any pending actions after
1296 	 * provisioning. It is mainly used for P2PS pending group creation.
1297 	 */
1298 	int (*prov_disc_resp_cb)(void *ctx);
1299 
1300 	/**
1301 	 * p2ps_group_capability - Determine group capability
1302 	 * @ctx: Callback context from cb_ctx
1303 	 * @incoming: Peer requested roles, expressed with P2PS_SETUP_* bitmap.
1304 	 * @role: Local roles, expressed with P2PS_SETUP_* bitmap.
1305 	 * @force_freq: Variable for returning forced frequency for the group.
1306 	 * @pref_freq: Variable for returning preferred frequency for the group.
1307 	 * Returns: P2PS_SETUP_* bitmap of group capability result.
1308 	 *
1309 	 * This function can be used to determine group capability and
1310 	 * frequencies based on information from P2PS PD exchange and the
1311 	 * current state of ongoing groups and driver capabilities.
1312 	 */
1313 	u8 (*p2ps_group_capability)(void *ctx, u8 incoming, u8 role,
1314 				    unsigned int *force_freq,
1315 				    unsigned int *pref_freq);
1316 
1317 	/**
1318 	 * get_pref_freq_list - Get preferred frequency list for an interface
1319 	 * @ctx: Callback context from cb_ctx
1320 	 * @go: Whether the use if for GO role
1321 	 * @len: Length of freq_list in entries (both IN and OUT)
1322 	 * @freq_list: Buffer for returning the preferred frequencies (MHz)
1323 	 * Returns: 0 on success, -1 on failure
1324 	 *
1325 	 * This function can be used to query the preferred frequency list from
1326 	 * the driver specific to a particular interface type.
1327 	 */
1328 	int (*get_pref_freq_list)(void *ctx, int go,
1329 				  unsigned int *len,
1330 				  struct weighted_pcl *freq_list);
1331 
1332 	/**
1333 	 * register_bootstrap_comeback - Register timeout to initiate bootstrap
1334 	 *	comeback request
1335 	 * @ctx: Callback context from cb_ctx
1336 	 * @addr: P2P Device Address to which comeback request is to be sent
1337 	 * @comeback_after: Time in TUs after which comeback request is sent
1338 	 *
1339 	 * This function can be used to send comeback request after given
1340 	 * timeout.
1341 	 */
1342 	void (*register_bootstrap_comeback)(void *ctx, const u8 *addr,
1343 					    u16 comeback_after);
1344 
1345 	/**
1346 	 * bootstrap_req_rx - Indicate bootstrap request from a P2P peer
1347 	 * @ctx: Callback context from cb_ctx
1348 	 * @addr: P2P device address from which bootstrap request was received
1349 	 * @bootstrap_method: Bootstrapping method request by the peer device
1350 	 *
1351 	 * This function can be used to notify that bootstrap request is
1352 	 * received from a P2P peer.
1353 	 */
1354 	void (*bootstrap_req_rx)(void *ctx, const u8 *addr,
1355 				 u16 bootstrap_method);
1356 
1357 	/**
1358 	 * bootstrap_rsp_rx - Indicate bootstrapping response from a P2P peer
1359 	 * @ctx: Callback context from cb_ctx
1360 	 * @addr: P2P device address with which bootstrapping is completed
1361 	 * @status: P2P Status Code of bootstrapping handshake
1362 	 * @freq: Frequency in which bootstrapping is done
1363 	 * @bootstrap_method: Bootstrapping method by the peer device
1364 	 *
1365 	 * This function can be used to notify the status of bootstrapping
1366 	 * handshake.
1367 	 */
1368 	void (*bootstrap_rsp_rx)(void *ctx, const u8 *addr,
1369 				 enum p2p_status_code status, int freq,
1370 				 u16 bootstrap_method);
1371 
1372 	/**
1373 	 * validate_dira - Indicate reception of DIRA to be validated against a
1374 	 *	list of available device identity keys
1375 	 * @ctx: Callback context from cb_ctx
1376 	 * @peer_addr: P2P Device address of the peer
1377 	 * @dira_nonce: DIRA Nonce
1378 	 * @dira_tag: DIRA Tag
1379 	 * Returns: Identity block ID on success, 0 on failure
1380 	 *
1381 	 * This function can be used to validate DIRA.
1382 	 */
1383 	int (*validate_dira)(void *ctx, const u8 *peer_addr,
1384 			     const u8 *dira_nonce, const u8 *dira_tag);
1385 
1386 	/**
1387 	 * set_pmksa - Configure PMK of a paired/persistent peer from
1388 	 *	configuration
1389 	 * @ctx: Callback context from cb_ctx
1390 	 * @peer_addr: P2P Device address of the peer
1391 	 * @dik_id: Identity block ID
1392 	 * Returns: 0 on success
1393 	 *
1394 	 * It is expected to call p2p_pasn_pmksa_set_pmk() to set the PMK/PMKID
1395 	 * for given dik_id.
1396 	 */
1397 	int (*set_pmksa)(void *ctx, const u8 *peer_addr, int dik_id);
1398 
1399 	/**
1400 	 * pasn_send_mgmt - Function handler to transmit a Management frame
1401 	 * @ctx: Callback context from cb_ctx
1402 	 * @data: Frame to transmit
1403 	 * @data_len: Length of frame to transmit
1404 	 * @noack: No ack flag
1405 	 * @freq: Frequency in MHz for the channel on which to transmit
1406 	 * @wait: How many milliseconds to wait for a response frame
1407 	 * Returns: 0 on success, -1 on failure
1408 	 */
1409 	int (*pasn_send_mgmt)(void *ctx, const u8 *data, size_t data_len,
1410 			      int noack, unsigned int freq, unsigned int wait);
1411 
1412 	/**
1413 	 * prepare_data_element - Function handler to update protocol specific
1414 	 *	elements in PASN authentication frames
1415 	 * @ctx: Callback context from cb_ctx
1416 	 * @peer_addr: Peer MAC address
1417 	 * Returns: 0 on success, -1 on failure
1418 	 */
1419 	int (*prepare_data_element)(void *ctx, const u8 *peer_addr);
1420 
1421 	/**
1422 	 * parse_data_element - Function handler to parse P2P data element
1423 	 * @ctx: Callback context from cb_ctx
1424 	 * @data: Data to be parsed
1425 	 * @len: Length of data
1426 	 * Returns: 0 on success, -1 on failure
1427 	 */
1428 	int (*parse_data_element)(void *ctx, const u8 *data, size_t len);
1429 
1430 	/**
1431 	 * pasn_validate_pmkid - Function handler to validate RSN PMKID
1432 	 * @ctx: Callback context from cb_ctx
1433 	 * @addr: Peer MAC address
1434 	 * @pmkid: PMKID in the PASN frame
1435 	 * Returns: 0 on success, -1 on failure
1436 	 */
1437 	int (*pasn_validate_pmkid)(void *ctx, const u8 *addr, const u8 *pmkid);
1438 
1439 	/**
1440 	 *
1441 	 * is_p2p_dfs_chan - DFS channel check
1442 	 *
1443 	 * To check if a channel is a DFS channel.
1444 	 */
1445 	bool (*is_p2p_dfs_chan)(void *ctx, int freq, u8 op_class, u8 chan);
1446 };
1447 
1448 
1449 /* P2P module initialization/deinitialization */
1450 
1451 /**
1452  * p2p_init - Initialize P2P module
1453  * @cfg: P2P module configuration
1454  * Returns: Pointer to private data or %NULL on failure
1455  *
1456  * This function is used to initialize global P2P module context (one per
1457  * device). The P2P module will keep a copy of the configuration data, so the
1458  * caller does not need to maintain this structure. However, the callback
1459  * functions and the context parameters to them must be kept available until
1460  * the P2P module is deinitialized with p2p_deinit().
1461  */
1462 struct p2p_data * p2p_init(const struct p2p_config *cfg);
1463 
1464 /**
1465  * p2p_deinit - Deinitialize P2P module
1466  * @p2p: P2P module context from p2p_init()
1467  */
1468 void p2p_deinit(struct p2p_data *p2p);
1469 
1470 /**
1471  * p2p_flush - Flush P2P module state
1472  * @p2p: P2P module context from p2p_init()
1473  *
1474  * This command removes the P2P module state like peer device entries.
1475  */
1476 void p2p_flush(struct p2p_data *p2p);
1477 
1478 /**
1479  * p2p_unauthorize - Unauthorize the specified peer device
1480  * @p2p: P2P module context from p2p_init()
1481  * @addr: P2P peer entry to be unauthorized
1482  * Returns: 0 on success, -1 on failure
1483  *
1484  * This command removes any connection authorization from the specified P2P
1485  * peer device address. This can be used, e.g., to cancel effect of a previous
1486  * p2p_authorize() or p2p_connect() call that has not yet resulted in completed
1487  * GO Negotiation.
1488  */
1489 int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr);
1490 
1491 /**
1492  * p2p_set_dev_name - Set device name
1493  * @p2p: P2P module context from p2p_init()
1494  * Returns: 0 on success, -1 on failure
1495  *
1496  * This function can be used to update the P2P module configuration with
1497  * information that was not available at the time of the p2p_init() call.
1498  */
1499 int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name);
1500 
1501 int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer);
1502 int p2p_set_model_name(struct p2p_data *p2p, const char *model_name);
1503 int p2p_set_model_number(struct p2p_data *p2p, const char *model_number);
1504 int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number);
1505 
1506 void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods);
1507 void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid);
1508 
1509 /**
1510  * p2p_set_pri_dev_type - Set primary device type
1511  * @p2p: P2P module context from p2p_init()
1512  * Returns: 0 on success, -1 on failure
1513  *
1514  * This function can be used to update the P2P module configuration with
1515  * information that was not available at the time of the p2p_init() call.
1516  */
1517 int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type);
1518 
1519 /**
1520  * p2p_set_sec_dev_types - Set secondary device types
1521  * @p2p: P2P module context from p2p_init()
1522  * Returns: 0 on success, -1 on failure
1523  *
1524  * This function can be used to update the P2P module configuration with
1525  * information that was not available at the time of the p2p_init() call.
1526  */
1527 int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8],
1528 			  size_t num_dev_types);
1529 
1530 int p2p_set_country(struct p2p_data *p2p, const char *country);
1531 
1532 
1533 /* Commands from upper layer management entity */
1534 
1535 enum p2p_discovery_type {
1536 	P2P_FIND_START_WITH_FULL,
1537 	P2P_FIND_ONLY_SOCIAL,
1538 	P2P_FIND_PROGRESSIVE
1539 };
1540 
1541 /**
1542  * p2p_find - Start P2P Find (Device Discovery)
1543  * @p2p: P2P module context from p2p_init()
1544  * @timeout: Timeout for find operation in seconds or 0 for no timeout
1545  * @type: Device Discovery type
1546  * @num_req_dev_types: Number of requested device types
1547  * @req_dev_types: Requested device types array, must be an array
1548  *	containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no
1549  *	requested device types.
1550  * @dev_id: Device ID to search for or %NULL to find all devices
1551  * @search_delay: Extra delay in milliseconds between search iterations
1552  * @seek_count: Number of ASP Service Strings in the seek_string array
1553  * @seek_string: ASP Service Strings to query for in Probe Requests
1554  * @freq: Requested first scan frequency (in MHz) to modify type ==
1555  *	P2P_FIND_START_WITH_FULL behavior. 0 = Use normal full scan.
1556  *	If p2p_find is already in progress, this parameter is ignored and full
1557  *	scan will be executed.
1558  * @include_6ghz: Include 6 GHz channels in P2P find
1559  * Returns: 0 on success, -1 on failure
1560  */
1561 int p2p_find(struct p2p_data *p2p, unsigned int timeout,
1562 	     enum p2p_discovery_type type,
1563 	     unsigned int num_req_dev_types, const u8 *req_dev_types,
1564 	     const u8 *dev_id, unsigned int search_delay,
1565 	     u8 seek_count, const char **seek_string, int freq,
1566 	     bool include_6ghz);
1567 
1568 /**
1569  * p2p_notify_scan_trigger_status - Indicate scan trigger status
1570  * @p2p: P2P module context from p2p_init()
1571  * @status: 0 on success, -1 on failure
1572  */
1573 void p2p_notify_scan_trigger_status(struct p2p_data *p2p, int status);
1574 
1575 /**
1576  * p2p_stop_find - Stop P2P Find (Device Discovery)
1577  * @p2p: P2P module context from p2p_init()
1578  */
1579 void p2p_stop_find(struct p2p_data *p2p);
1580 
1581 /**
1582  * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq
1583  * @p2p: P2P module context from p2p_init()
1584  * @freq: Frequency in MHz for next operation
1585  *
1586  * This is like p2p_stop_find(), but Listen state is not stopped if we are
1587  * already on the same frequency.
1588  */
1589 void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq);
1590 
1591 /**
1592  * p2p_listen - Start P2P Listen state for specified duration
1593  * @p2p: P2P module context from p2p_init()
1594  * @timeout: Listen state duration in milliseconds
1595  * Returns: 0 on success, -1 on failure
1596  *
1597  * This function can be used to request the P2P module to keep the device
1598  * discoverable on the listen channel for an extended set of time. At least in
1599  * its current form, this is mainly used for testing purposes and may not be of
1600  * much use for normal P2P operations.
1601  */
1602 int p2p_listen(struct p2p_data *p2p, unsigned int timeout);
1603 
1604 /**
1605  * p2p_stop_listen - Stop P2P Listen
1606  * @p2p: P2P module context from p2p_init()
1607  */
1608 void p2p_stop_listen(struct p2p_data *p2p);
1609 
1610 /**
1611  * p2p_connect - Start P2P group formation (GO negotiation)
1612  * @p2p: P2P module context from p2p_init()
1613  * @peer_addr: MAC address of the peer P2P client
1614  * @wps_method: WPS method to be used in provisioning
1615  * @go_intent: Local GO intent value (1..15)
1616  * @own_interface_addr: Intended interface address to use with the group
1617  * @force_freq: The only allowed channel frequency in MHz or 0
1618  * @persistent_group: Whether to create a persistent group (0 = no, 1 =
1619  * persistent group without persistent reconnect, 2 = persistent group with
1620  * persistent reconnect)
1621  * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
1622  *	a new SSID
1623  * @force_ssid_len: Length of $force_ssid buffer
1624  * @pd_before_go_neg: Whether to send Provision Discovery prior to GO
1625  *	Negotiation as an interoperability workaround when initiating group
1626  *	formation
1627  * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1628  *	force_freq == 0)
1629  * @oob_pw_id: OOB password identifier
1630  * @p2p2: Device supports P2P2 features
1631  * @bootstrap: Bootstrapping method requested for P2P2 provision discovery
1632  * @password: P2P2 pairing password or %NULL for opportunistic method
1633  * Returns: 0 on success, -1 on failure
1634  */
1635 int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
1636 		enum p2p_wps_method wps_method,
1637 		int go_intent, const u8 *own_interface_addr,
1638 		unsigned int force_freq, int persistent_group,
1639 		const u8 *force_ssid, size_t force_ssid_len,
1640 		int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id,
1641 		bool p2p2, u16 bootstrap, const char *password);
1642 
1643 /**
1644  * p2p_authorize - Authorize P2P group formation (GO negotiation)
1645  * @p2p: P2P module context from p2p_init()
1646  * @peer_addr: MAC address of the peer P2P client
1647  * @wps_method: WPS method to be used in provisioning
1648  * @go_intent: Local GO intent value (1..15)
1649  * @own_interface_addr: Intended interface address to use with the group
1650  * @force_freq: The only allowed channel frequency in MHz or 0
1651  * @persistent_group: Whether to create a persistent group (0 = no, 1 =
1652  * persistent group without persistent reconnect, 2 = persistent group with
1653  * persistent reconnect)
1654  * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
1655  *	a new SSID
1656  * @force_ssid_len: Length of $force_ssid buffer
1657  * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1658  *	force_freq == 0)
1659  * @oob_pw_id: OOB password identifier
1660  * @bootstrap: Bootstrapping method requested for P2P2 provision discovery
1661  * @password: P2P2 pairing password or %NULL for opportunistic method
1662  * Returns: 0 on success, -1 on failure
1663  *
1664  * This is like p2p_connect(), but the actual group negotiation is not
1665  * initiated automatically, i.e., the other end is expected to do that.
1666  */
1667 int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
1668 		  enum p2p_wps_method wps_method,
1669 		  int go_intent, const u8 *own_interface_addr,
1670 		  unsigned int force_freq, int persistent_group,
1671 		  const u8 *force_ssid, size_t force_ssid_len,
1672 		  unsigned int pref_freq, u16 oob_pw_id, u16 bootstrap,
1673 		  const char *password);
1674 
1675 /**
1676  * p2p_reject - Reject peer device (explicitly block connection attempts)
1677  * @p2p: P2P module context from p2p_init()
1678  * @peer_addr: MAC address of the peer P2P client
1679  * Returns: 0 on success, -1 on failure
1680  */
1681 int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr);
1682 
1683 /**
1684  * p2p_set_req_bootstrap_method - Send Provision Discovery Request to initiate
1685  *	 bootstrapping
1686  * @p2p: P2P module context from p2p_init()
1687  * @peer_addr: MAC address of the peer P2P client
1688  * @boostrap: Bootstrapping method
1689  * Returns: 0 on success, -1 on failure
1690  */
1691 int p2p_set_req_bootstrap_method(struct p2p_data *p2p, const u8 *peer_addr,
1692 				 u16 bootstrap);
1693 
1694 /**
1695  * p2p_prov_disc_req - Send Provision Discovery Request
1696  * @p2p: P2P module context from p2p_init()
1697  * @peer_addr: MAC address of the peer P2P client
1698  * @p2ps_prov: Provisioning info for P2PS
1699  * @config_methods: WPS Config Methods value (only one bit set)
1700  * @join: Whether this is used by a client joining an active group
1701  * @force_freq: Forced TX frequency for the frame (mainly for the join case)
1702  * @user_initiated_pd: Flag to indicate if initiated by user or not
1703  * Returns: 0 on success, -1 on failure
1704  *
1705  * This function can be used to request a discovered P2P peer to display a PIN
1706  * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us
1707  * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame
1708  * is transmitted once immediately and if no response is received, the frame
1709  * will be sent again whenever the target device is discovered during device
1710  * dsicovery (start with a p2p_find() call). Response from the peer is
1711  * indicated with the p2p_config::prov_disc_resp() callback.
1712  */
1713 int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
1714 		      struct p2ps_provision *p2ps_prov, u16 config_methods,
1715 		      int join, int force_freq,
1716 		      int user_initiated_pd);
1717 
1718 /**
1719  * p2p_sd_request - Schedule a service discovery query
1720  * @p2p: P2P module context from p2p_init()
1721  * @dst: Destination peer or %NULL to apply for all peers
1722  * @tlvs: P2P Service Query TLV(s)
1723  * Returns: Reference to the query or %NULL on failure
1724  *
1725  * Response to the query is indicated with the p2p_config::sd_response()
1726  * callback.
1727  */
1728 void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
1729 		      const struct wpabuf *tlvs);
1730 
1731 #ifdef CONFIG_WIFI_DISPLAY
1732 void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst,
1733 			  const struct wpabuf *tlvs);
1734 #endif /* CONFIG_WIFI_DISPLAY */
1735 
1736 /**
1737  * p2p_sd_cancel_request - Cancel a pending service discovery query
1738  * @p2p: P2P module context from p2p_init()
1739  * @req: Query reference from p2p_sd_request()
1740  * Returns: 0 if request for cancelled; -1 if not found
1741  */
1742 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req);
1743 
1744 /**
1745  * p2p_sd_response - Send response to a service discovery query
1746  * @p2p: P2P module context from p2p_init()
1747  * @freq: Frequency from p2p_config::sd_request() callback
1748  * @dst: Destination address from p2p_config::sd_request() callback
1749  * @dialog_token: Dialog token from p2p_config::sd_request() callback
1750  * @resp_tlvs: P2P Service Response TLV(s)
1751  *
1752  * This function is called as a response to the request indicated with
1753  * p2p_config::sd_request() callback.
1754  */
1755 void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
1756 		     u8 dialog_token, const struct wpabuf *resp_tlvs);
1757 
1758 /**
1759  * p2p_sd_service_update - Indicate a change in local services
1760  * @p2p: P2P module context from p2p_init()
1761  *
1762  * This function needs to be called whenever there is a change in availability
1763  * of the local services. This will increment the Service Update Indicator
1764  * value which will be used in SD Request and Response frames.
1765  */
1766 void p2p_sd_service_update(struct p2p_data *p2p);
1767 
1768 
1769 enum p2p_invite_role {
1770 	P2P_INVITE_ROLE_GO,
1771 	P2P_INVITE_ROLE_ACTIVE_GO,
1772 	P2P_INVITE_ROLE_CLIENT
1773 };
1774 
1775 /**
1776  * p2p_invite - Invite a P2P Device into a group
1777  * @p2p: P2P module context from p2p_init()
1778  * @peer: Device Address of the peer P2P Device
1779  * @role: Local role in the group
1780  * @bssid: Group BSSID or %NULL if not known
1781  * @ssid: Group SSID
1782  * @ssid_len: Length of ssid in octets
1783  * @force_freq: The only allowed channel frequency in MHz or 0
1784  * @go_dev_addr: Forced GO Device Address or %NULL if none
1785  * @persistent_group: Whether this is to reinvoke a persistent group
1786  * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1787  *	force_freq == 0)
1788  * @dev_pw_id: Device Password ID from OOB Device Password (NFC) static handover
1789  *	case or -1 if not used
1790  * @p2p2: Operating in P2P2 mode
1791  * Returns: 0 on success, -1 on failure
1792  */
1793 int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
1794 	       const u8 *bssid, const u8 *ssid, size_t ssid_len,
1795 	       unsigned int force_freq, const u8 *go_dev_addr,
1796 	       int persistent_group, unsigned int pref_freq, int dev_pw_id,
1797 	       bool p2p2);
1798 
1799 /**
1800  * p2p_presence_req - Request GO presence
1801  * @p2p: P2P module context from p2p_init()
1802  * @go_interface_addr: GO P2P Interface Address
1803  * @own_interface_addr: Own P2P Interface Address for this group
1804  * @freq: Group operating frequence (in MHz)
1805  * @duration1: Preferred presence duration in microseconds
1806  * @interval1: Preferred presence interval in microseconds
1807  * @duration2: Acceptable presence duration in microseconds
1808  * @interval2: Acceptable presence interval in microseconds
1809  * Returns: 0 on success, -1 on failure
1810  *
1811  * If both duration and interval values are zero, the parameter pair is not
1812  * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0).
1813  */
1814 int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
1815 		     const u8 *own_interface_addr, unsigned int freq,
1816 		     u32 duration1, u32 interval1, u32 duration2,
1817 		     u32 interval2);
1818 
1819 /**
1820  * p2p_ext_listen - Set Extended Listen Timing
1821  * @p2p: P2P module context from p2p_init()
1822  * @freq: Group operating frequence (in MHz)
1823  * @period: Availability period in milliseconds (1-65535; 0 to disable)
1824  * @interval: Availability interval in milliseconds (1-65535; 0 to disable)
1825  * Returns: 0 on success, -1 on failure
1826  *
1827  * This function can be used to enable or disable (period = interval = 0)
1828  * Extended Listen Timing. When enabled, the P2P Device will become
1829  * discoverable (go into Listen State) every @interval milliseconds for at
1830  * least @period milliseconds.
1831  */
1832 int p2p_ext_listen(struct p2p_data *p2p, unsigned int period,
1833 		   unsigned int interval);
1834 
1835 /* Event notifications from upper layer management operations */
1836 
1837 /**
1838  * p2p_wps_success_cb - Report successfully completed WPS provisioning
1839  * @p2p: P2P module context from p2p_init()
1840  * @mac_addr: Peer address
1841  *
1842  * This function is used to report successfully completed WPS provisioning
1843  * during group formation in both GO/Registrar and client/Enrollee roles.
1844  */
1845 void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr);
1846 
1847 /**
1848  * p2p_group_formation_failed - Report failed WPS provisioning
1849  * @p2p: P2P module context from p2p_init()
1850  *
1851  * This function is used to report failed group formation. This can happen
1852  * either due to failed WPS provisioning or due to 15 second timeout during
1853  * the provisioning phase.
1854  */
1855 void p2p_group_formation_failed(struct p2p_data *p2p);
1856 
1857 /**
1858  * p2p_get_provisioning_info - Get any stored provisioning info
1859  * @p2p: P2P module context from p2p_init()
1860  * @addr: Peer P2P Device Address
1861  * Returns: WPS provisioning information (WPS config method) or 0 if no
1862  * information is available
1863  *
1864  * This function is used to retrieve stored WPS provisioning info for the given
1865  * peer.
1866  */
1867 u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr);
1868 
1869 /**
1870  * p2p_clear_provisioning_info - Clear any stored provisioning info
1871  * @p2p: P2P module context from p2p_init()
1872  * @iface_addr: Peer P2P Device Address
1873  *
1874  * This function is used to clear stored WPS provisioning info for the given
1875  * peer.
1876  */
1877 void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr);
1878 
1879 
1880 /* Event notifications from lower layer driver operations */
1881 
1882 /**
1883  * enum p2p_probe_req_status
1884  *
1885  * @P2P_PREQ_MALFORMED: frame was not well-formed
1886  * @P2P_PREQ_NOT_LISTEN: device isn't in listen state, frame ignored
1887  * @P2P_PREQ_NOT_P2P: frame was not a P2P probe request
1888  * @P2P_PREQ_P2P_NOT_PROCESSED: frame was P2P but wasn't processed
1889  * @P2P_PREQ_P2P_PROCESSED: frame has been processed by P2P
1890  */
1891 enum p2p_probe_req_status {
1892 	P2P_PREQ_MALFORMED,
1893 	P2P_PREQ_NOT_LISTEN,
1894 	P2P_PREQ_NOT_P2P,
1895 	P2P_PREQ_NOT_PROCESSED,
1896 	P2P_PREQ_PROCESSED
1897 };
1898 
1899 /**
1900  * p2p_probe_req_rx - Report reception of a Probe Request frame
1901  * @p2p: P2P module context from p2p_init()
1902  * @addr: Source MAC address
1903  * @dst: Destination MAC address if available or %NULL
1904  * @bssid: BSSID if available or %NULL
1905  * @ie: Information elements from the Probe Request frame body
1906  * @ie_len: Length of ie buffer in octets
1907  * @rx_freq: Probe Request frame RX frequency
1908  * @p2p_lo_started: Whether P2P Listen Offload is started
1909  * Returns: value indicating the type and status of the probe request
1910  */
1911 enum p2p_probe_req_status
1912 p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
1913 		 const u8 *bssid, const u8 *ie, size_t ie_len,
1914 		 unsigned int rx_freq, int p2p_lo_started);
1915 
1916 /**
1917  * p2p_rx_action - Report received Action frame
1918  * @p2p: P2P module context from p2p_init()
1919  * @da: Destination address of the received Action frame
1920  * @sa: Source address of the received Action frame
1921  * @bssid: Address 3 of the received Action frame
1922  * @category: Category of the received Action frame
1923  * @data: Action frame body after the Category field
1924  * @len: Length of the data buffer in octets
1925  * @freq: Frequency (in MHz) on which the frame was received
1926  */
1927 void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
1928 		   const u8 *bssid, u8 category,
1929 		   const u8 *data, size_t len, int freq);
1930 
1931 /**
1932  * p2p_scan_res_handler - Indicate a P2P scan results
1933  * @p2p: P2P module context from p2p_init()
1934  * @bssid: BSSID of the scan result
1935  * @freq: Frequency of the channel on which the device was found in MHz
1936  * @rx_time: Time when the result was received
1937  * @level: Signal level (signal strength of the received Beacon/Probe Response
1938  *	frame)
1939  * @ies: Pointer to IEs from the scan result
1940  * @ies_len: Length of the ies buffer
1941  * Returns: 0 to continue or 1 to stop scan result indication
1942  *
1943  * This function is called to indicate a scan result entry with P2P IE from a
1944  * scan requested with struct p2p_config::p2p_scan(). This can be called during
1945  * the actual scan process (i.e., whenever a new device is found) or as a
1946  * sequence of calls after the full scan has been completed. The former option
1947  * can result in optimized operations, but may not be supported by all
1948  * driver/firmware designs. The ies buffer need to include at least the P2P IE,
1949  * but it is recommended to include all IEs received from the device. The
1950  * caller does not need to check that the IEs contain a P2P IE before calling
1951  * this function since frames will be filtered internally if needed.
1952  *
1953  * This function will return 1 if it wants to stop scan result iteration (and
1954  * scan in general if it is still in progress). This is used to allow faster
1955  * start of a pending operation, e.g., to start a pending GO negotiation.
1956  */
1957 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
1958 			 struct os_reltime *rx_time, int level, const u8 *ies,
1959 			 size_t ies_len);
1960 
1961 /**
1962  * p2p_scan_res_handled - Indicate end of scan results
1963  * @p2p: P2P module context from p2p_init()
1964  * @delay: Search delay for next scan in ms
1965  *
1966  * This function is called to indicate that all P2P scan results from a scan
1967  * have been reported with zero or more calls to p2p_scan_res_handler(). This
1968  * function must be called as a response to successful
1969  * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler()
1970  * calls stopped iteration.
1971  */
1972 void p2p_scan_res_handled(struct p2p_data *p2p, unsigned int delay);
1973 
1974 enum p2p_send_action_result {
1975 	P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */,
1976 	P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */,
1977 	P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */
1978 };
1979 
1980 /**
1981  * p2p_send_action_cb - Notify TX status of an Action frame
1982  * @p2p: P2P module context from p2p_init()
1983  * @freq: Channel frequency in MHz
1984  * @dst: Destination MAC address (Address 1)
1985  * @src: Source MAC address (Address 2)
1986  * @bssid: BSSID (Address 3)
1987  * @result: Result of the transmission attempt
1988  *
1989  * This function is used to indicate the result of an Action frame transmission
1990  * that was requested with struct p2p_config::send_action() callback.
1991  */
1992 void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
1993 			const u8 *src, const u8 *bssid,
1994 			enum p2p_send_action_result result);
1995 
1996 /**
1997  * p2p_listen_cb - Indicate the start of a requested Listen state
1998  * @p2p: P2P module context from p2p_init()
1999  * @freq: Listen channel frequency in MHz
2000  * @duration: Duration for the Listen state in milliseconds
2001  *
2002  * This function is used to indicate that a Listen state requested with
2003  * struct p2p_config::start_listen() callback has started.
2004  */
2005 void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
2006 		   unsigned int duration);
2007 
2008 /**
2009  * p2p_listen_end - Indicate the end of a requested Listen state
2010  * @p2p: P2P module context from p2p_init()
2011  * @freq: Listen channel frequency in MHz
2012  * Returns: 0 if no operations were started, 1 if an operation was started
2013  *
2014  * This function is used to indicate that a Listen state requested with
2015  * struct p2p_config::start_listen() callback has ended.
2016  */
2017 int p2p_listen_end(struct p2p_data *p2p, unsigned int freq);
2018 
2019 void p2p_listen_failed(struct p2p_data *p2p, unsigned int freq);
2020 
2021 void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
2022 		      const u8 *ie, size_t ie_len);
2023 
2024 void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
2025 			const u8 *ie, size_t ie_len);
2026 
2027 
2028 /* Per-group P2P state for GO */
2029 
2030 struct p2p_group;
2031 
2032 /**
2033  * struct p2p_group_config - P2P group configuration
2034  *
2035  * This configuration is provided to the P2P module during initialization of
2036  * the per-group information with p2p_group_init().
2037  */
2038 struct p2p_group_config {
2039 	/**
2040 	 * p2p2 - Whether the group was formed using P2P2
2041 	 */
2042 	bool p2p2;
2043 
2044 	/**
2045 	 * persistent_group - Whether the group is persistent
2046 	 * 0 = not a persistent group
2047 	 * 1 = persistent group without persistent reconnect
2048 	 * 2 = persistent group with persistent reconnect
2049 	 */
2050 	int persistent_group;
2051 
2052 	/**
2053 	 * interface_addr - P2P Interface Address of the group
2054 	 */
2055 	u8 interface_addr[ETH_ALEN];
2056 
2057 	/**
2058 	 * max_clients - Maximum number of clients in the group
2059 	 */
2060 	unsigned int max_clients;
2061 
2062 	/**
2063 	 * ssid - Group SSID
2064 	 */
2065 	u8 ssid[SSID_MAX_LEN];
2066 
2067 	/**
2068 	 * ssid_len - Length of SSID
2069 	 */
2070 	size_t ssid_len;
2071 
2072 	/**
2073 	 * freq - Operating channel of the group
2074 	 */
2075 	int freq;
2076 
2077 	/**
2078 	 * ip_addr_alloc - Whether IP address allocation within 4-way handshake
2079 	 *	is supported
2080 	 */
2081 	int ip_addr_alloc;
2082 
2083 	/**
2084 	 * cb_ctx - Context to use with callback functions
2085 	 */
2086 	void *cb_ctx;
2087 
2088 	/**
2089 	 * ie_update - Notification of IE update
2090 	 * @ctx: Callback context from cb_ctx
2091 	 * @beacon_ies: P2P IE for Beacon frames or %NULL if no change
2092 	 * @proberesp_ies: P2P Ie for Probe Response frames
2093 	 *
2094 	 * P2P module uses this callback function to notify whenever the P2P IE
2095 	 * in Beacon or Probe Response frames should be updated based on group
2096 	 * events.
2097 	 *
2098 	 * The callee is responsible for freeing the returned buffer(s) with
2099 	 * wpabuf_free().
2100 	 */
2101 	void (*ie_update)(void *ctx, struct wpabuf *beacon_ies,
2102 			  struct wpabuf *proberesp_ies);
2103 
2104 	/**
2105 	 * idle_update - Notification of changes in group idle state
2106 	 * @ctx: Callback context from cb_ctx
2107 	 * @idle: Whether the group is idle (no associated stations)
2108 	 */
2109 	void (*idle_update)(void *ctx, int idle);
2110 };
2111 
2112 /**
2113  * p2p_group_init - Initialize P2P group
2114  * @p2p: P2P module context from p2p_init()
2115  * @config: P2P group configuration (will be freed by p2p_group_deinit())
2116  * Returns: Pointer to private data or %NULL on failure
2117  *
2118  * This function is used to initialize per-group P2P module context. Currently,
2119  * this is only used to manage GO functionality and P2P clients do not need to
2120  * create an instance of this per-group information.
2121  */
2122 struct p2p_group * p2p_group_init(struct p2p_data *p2p,
2123 				  struct p2p_group_config *config);
2124 
2125 /**
2126  * p2p_group_deinit - Deinitialize P2P group
2127  * @group: P2P group context from p2p_group_init()
2128  */
2129 void p2p_group_deinit(struct p2p_group *group);
2130 
2131 /**
2132  * p2p_group_notif_assoc - Notification of P2P client association with GO
2133  * @group: P2P group context from p2p_group_init()
2134  * @addr: Interface address of the P2P client
2135  * @ie: IEs from the (Re)association Request frame
2136  * @len: Length of the ie buffer in octets
2137  * Returns: 0 on success, -1 on failure
2138  */
2139 int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr,
2140 			  const u8 *ie, size_t len);
2141 
2142 /**
2143  * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response
2144  * @group: P2P group context from p2p_group_init()
2145  * @status: Status value (P2P_SC_SUCCESS if association succeeded)
2146  * Returns: P2P IE for (Re)association Response or %NULL on failure
2147  *
2148  * The caller is responsible for freeing the returned buffer with
2149  * wpabuf_free().
2150  */
2151 struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status);
2152 
2153 /**
2154  * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO
2155  * @group: P2P group context from p2p_group_init()
2156  * @addr: Interface address of the P2P client
2157  */
2158 void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr);
2159 
2160 /**
2161  * p2p_group_notif_formation_done - Notification of completed group formation
2162  * @group: P2P group context from p2p_group_init()
2163  */
2164 void p2p_group_notif_formation_done(struct p2p_group *group);
2165 
2166 /**
2167  * p2p_group_notif_noa - Notification of NoA change
2168  * @group: P2P group context from p2p_group_init()
2169  * @noa: Notice of Absence attribute payload, %NULL if none
2170  * @noa_len: Length of noa buffer in octets
2171  * Returns: 0 on success, -1 on failure
2172  *
2173  * Notify the P2P group management about a new NoA contents. This will be
2174  * inserted into the P2P IEs in Beacon and Probe Response frames with rest of
2175  * the group information.
2176  */
2177 int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa,
2178 			size_t noa_len);
2179 
2180 /**
2181  * p2p_group_match_dev_type - Match device types in group with requested type
2182  * @group: P2P group context from p2p_group_init()
2183  * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs)
2184  * Returns: 1 on match, 0 on mismatch
2185  *
2186  * This function can be used to match the Requested Device Type attribute in
2187  * WPS IE with the device types of a group member for deciding whether a GO
2188  * should reply to a Probe Request frame. Match will be reported if the WPS IE
2189  * is not requested any specific device type.
2190  */
2191 int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps);
2192 
2193 /**
2194  * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id
2195  */
2196 int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p);
2197 
2198 /**
2199  * p2p_group_go_discover - Send GO Discoverability Request to a group client
2200  * @group: P2P group context from p2p_group_init()
2201  * Returns: 0 on success (frame scheduled); -1 if client was not found
2202  */
2203 int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
2204 			  const u8 *searching_dev, int rx_freq);
2205 
2206 
2207 /* Generic helper functions */
2208 
2209 /**
2210  * p2p_ie_text - Build text format description of P2P IE
2211  * @p2p_ie: P2P IE
2212  * @buf: Buffer for returning text
2213  * @end: Pointer to the end of the buf area
2214  * Returns: Number of octets written to the buffer or -1 on failure
2215  *
2216  * This function can be used to parse P2P IE contents into text format
2217  * field=value lines.
2218  */
2219 int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end);
2220 
2221 /**
2222  * p2p_scan_result_text - Build text format description of P2P IE
2223  * @ies: Information elements from scan results
2224  * @ies_len: ies buffer length in octets
2225  * @buf: Buffer for returning text
2226  * @end: Pointer to the end of the buf area
2227  * Returns: Number of octets written to the buffer or -1 on failure
2228  *
2229  * This function can be used to parse P2P IE contents into text format
2230  * field=value lines.
2231  */
2232 int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end);
2233 
2234 /**
2235  * p2p_parse_dev_addr_in_p2p_ie - Parse P2P Device Address from a concatenated
2236  * P2P IE
2237  * @p2p_ie: P2P IE
2238  * @dev_addr: Buffer for returning P2P Device Address
2239  * Returns: 0 on success or -1 if P2P Device Address could not be parsed
2240  */
2241 int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr);
2242 
2243 /**
2244  * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s)
2245  * @ies: Information elements from scan results
2246  * @ies_len: ies buffer length in octets
2247  * @dev_addr: Buffer for returning P2P Device Address
2248  * Returns: 0 on success or -1 if P2P Device Address could not be parsed
2249  */
2250 int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr);
2251 
2252 /**
2253  * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame
2254  * @p2p: P2P module context from p2p_init()
2255  * @bssid: BSSID
2256  * @buf: Buffer for writing the P2P IE
2257  * @len: Maximum buf length in octets
2258  * @p2p_group: Whether this is for association with a P2P GO
2259  * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none
2260  * Returns: Number of octets written into buf or -1 on failure
2261  */
2262 int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf,
2263 		     size_t len, int p2p_group, struct wpabuf *p2p_ie);
2264 
2265 /**
2266  * p2p_scan_ie - Build P2P IE for Probe Request
2267  * @p2p: P2P module context from p2p_init()
2268  * @ies: Buffer for writing P2P IE
2269  * @dev_id: Device ID to search for or %NULL for any
2270  * @bands: Frequency bands used in the scan (enum wpa_radio_work_band bitmap)
2271  */
2272 void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id,
2273 		 unsigned int bands);
2274 
2275 /**
2276  * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie
2277  * @p2p: P2P module context from p2p_init()
2278  * Returns: Number of octets that p2p_scan_ie() may add to the buffer
2279  */
2280 size_t p2p_scan_ie_buf_len(struct p2p_data *p2p);
2281 
2282 /**
2283  * p2p_build_ssid - Generate a random P2P SSID
2284  * @p2p: P2P module context from p2p_init()
2285  * @ssid: Buffer for SSID
2286  * @ssid_len: Pointer to hold SSID length
2287  */
2288 void p2p_build_ssid(struct p2p_data *p2p, u8 *ssid, size_t *ssid_len);
2289 
2290 /**
2291  * p2p_go_params - Generate random P2P group parameters
2292  * @p2p: P2P module context from p2p_init()
2293  * @params: Buffer for parameters
2294  * Returns: 0 on success, -1 on failure
2295  */
2296 int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params);
2297 
2298 /**
2299  * p2p_set_go_role - Set the current role of P2P device
2300  * @p2p: P2P module context from p2p_init()
2301  * @val: 1 if P2P GO, 0 to reset the role variable
2302  *
2303  * This role is configured as P2P GO when authorizing a P2P Client to join the
2304  * group. Once PASN authentication with GO negotiation with predefined GO intent
2305  * values (15 for P2P GO) is completed, the role helps to configure PMK derived
2306  * during the PASN authentication.
2307  */
2308 void p2p_set_go_role(struct p2p_data *p2p, bool val);
2309 
2310 /**
2311  * p2p_get_group_capab - Get Group Capability from P2P IE data
2312  * @p2p_ie: P2P IE(s) contents
2313  * Returns: Group Capability
2314  */
2315 u8 p2p_get_group_capab(const struct wpabuf *p2p_ie);
2316 
2317 /**
2318  * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection
2319  * @p2p_ie: P2P IE(s) contents
2320  * Returns: 0 if cross connection is allow, 1 if not
2321  */
2322 int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie);
2323 
2324 /**
2325  * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data
2326  * @p2p_ie: P2P IE(s) contents
2327  * Returns: Pointer to P2P Device Address or %NULL if not included
2328  */
2329 const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie);
2330 
2331 /**
2332  * p2p_get_peer_info - Get P2P peer information
2333  * @p2p: P2P module context from p2p_init()
2334  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
2335  * @next: Whether to select the peer entry following the one indicated by addr
2336  * Returns: Pointer to peer info or %NULL if not found
2337  */
2338 const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p,
2339 					       const u8 *addr, int next);
2340 
2341 /**
2342  * p2p_get_peer_info_txt - Get internal P2P peer information in text format
2343  * @info: Pointer to P2P peer info from p2p_get_peer_info()
2344  * @buf: Buffer for returning text
2345  * @buflen: Maximum buffer length
2346  * Returns: Number of octets written to the buffer or -1 on failure
2347  *
2348  * Note: This information is internal to the P2P module and subject to change.
2349  * As such, this should not really be used by external programs for purposes
2350  * other than debugging.
2351  */
2352 int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
2353 			  char *buf, size_t buflen);
2354 
2355 /**
2356  * p2p_peer_known - Check whether P2P peer is known
2357  * @p2p: P2P module context from p2p_init()
2358  * @addr: P2P Device Address of the peer
2359  * Returns: 1 if the specified device is in the P2P peer table or 0 if not
2360  */
2361 int p2p_peer_known(struct p2p_data *p2p, const u8 *addr);
2362 
2363 /**
2364  * p2p_set_client_discoverability - Set client discoverability capability
2365  * @p2p: P2P module context from p2p_init()
2366  * @enabled: Whether client discoverability will be enabled
2367  *
2368  * This function can be used to disable (and re-enable) client discoverability.
2369  * This capability is enabled by default and should not be disabled in normal
2370  * use cases, i.e., this is mainly for testing purposes.
2371  */
2372 void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled);
2373 
2374 /**
2375  * p2p_set_managed_oper - Set managed P2P Device operations capability
2376  * @p2p: P2P module context from p2p_init()
2377  * @enabled: Whether managed P2P Device operations will be enabled
2378  */
2379 void p2p_set_managed_oper(struct p2p_data *p2p, int enabled);
2380 
2381 /**
2382  * p2p_config_get_random_social - Return a random social channel
2383  * @p2p: P2P config
2384  * @op_class: Selected operating class
2385  * @op_channel: Selected social channel
2386  * @avoid_list: Channel ranges to try to avoid or %NULL
2387  * @disallow_list: Channel ranges to discard or %NULL
2388  * Returns: 0 on success, -1 on failure
2389  *
2390  * This function is used before p2p_init is called. A random social channel
2391  * from supports bands 2.4 GHz (channels 1,6,11) and 60 GHz (channel 2) is
2392  * returned on success.
2393  */
2394 int p2p_config_get_random_social(struct p2p_config *p2p, u8 *op_class,
2395 				 u8 *op_channel,
2396 				 struct wpa_freq_range_list *avoid_list,
2397 				 struct wpa_freq_range_list *disallow_list);
2398 
2399 int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel,
2400 			   u8 forced);
2401 
2402 u8 p2p_get_listen_channel(struct p2p_data *p2p);
2403 
2404 int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len);
2405 
2406 int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
2407 			   u8 *iface_addr);
2408 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
2409 			   u8 *dev_addr);
2410 int p2p_get_dev_identity_key(struct p2p_data *p2p, const u8 *dev_addr,
2411 			     const u8 **dik_data, size_t *dik_len, u8 *cipher);
2412 
2413 void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr);
2414 
2415 /**
2416  * p2p_set_cross_connect - Set cross connection capability
2417  * @p2p: P2P module context from p2p_init()
2418  * @enabled: Whether cross connection will be enabled
2419  */
2420 void p2p_set_cross_connect(struct p2p_data *p2p, int enabled);
2421 
2422 int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr);
2423 
2424 /**
2425  * p2p_set_intra_bss_dist - Set intra BSS distribution
2426  * @p2p: P2P module context from p2p_init()
2427  * @enabled: Whether intra BSS distribution will be enabled
2428  */
2429 void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled);
2430 
2431 int p2p_channels_includes_freq(const struct p2p_channels *channels,
2432 			       unsigned int freq);
2433 
2434 int p2p_channels_to_freqs(const struct p2p_channels *channels,
2435 			  int *freq_list, unsigned int max_len);
2436 
2437 /**
2438  * p2p_supported_freq - Check whether channel is supported for P2P
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(struct p2p_data *p2p, unsigned int freq);
2444 
2445 /**
2446  * p2p_supported_freq_go - Check whether channel is supported for P2P GO operation
2447  * @p2p: P2P module context from p2p_init()
2448  * @freq: Channel frequency in MHz
2449  * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
2450  */
2451 int p2p_supported_freq_go(struct p2p_data *p2p, unsigned int freq);
2452 
2453 /**
2454  * p2p_supported_freq_cli - Check whether channel is supported for P2P client operation
2455  * @p2p: P2P module context from p2p_init()
2456  * @freq: Channel frequency in MHz
2457  * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
2458  */
2459 int p2p_supported_freq_cli(struct p2p_data *p2p, unsigned int freq);
2460 
2461 /**
2462  * p2p_get_pref_freq - Get channel from preferred channel list
2463  * @p2p: P2P module context from p2p_init()
2464  * @channels: List of channels
2465  * Returns: Preferred channel
2466  */
2467 unsigned int p2p_get_pref_freq(struct p2p_data *p2p,
2468 			       const struct p2p_channels *channels);
2469 
2470 void p2p_update_channel_list(struct p2p_data *p2p,
2471 			     const struct p2p_channels *chan,
2472 			     const struct p2p_channels *cli_chan);
2473 
2474 bool is_p2p_6ghz_disabled(struct p2p_data *p2p);
2475 
2476 /**
2477  * p2p_set_best_channels - Update best channel information
2478  * @p2p: P2P module context from p2p_init()
2479  * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band
2480  * @freq_5: Frequency (MHz) of best channel in 5 GHz band
2481  * @freq_overall: Frequency (MHz) of best channel overall
2482  */
2483 void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
2484 			   int freq_overall);
2485 
2486 /**
2487  * p2p_set_own_freq_preference - Set own preference for channel
2488  * @p2p: P2P module context from p2p_init()
2489  * @freq: Frequency (MHz) of the preferred channel or 0 if no preference
2490  *
2491  * This function can be used to set a preference on the operating channel based
2492  * on frequencies used on the other virtual interfaces that share the same
2493  * radio. If non-zero, this is used to try to avoid multi-channel concurrency.
2494  */
2495 void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq);
2496 
2497 const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p);
2498 
2499 /**
2500  * p2p_get_group_num_members - Get number of members in group
2501  * @group: P2P group context from p2p_group_init()
2502  * Returns: Number of members in the group
2503  */
2504 unsigned int p2p_get_group_num_members(struct p2p_group *group);
2505 
2506 /**
2507  * p2p_client_limit_reached - Check if client limit is reached
2508  * @group: P2P group context from p2p_group_init()
2509  * Returns: 1 if no of clients limit reached
2510  */
2511 int p2p_client_limit_reached(struct p2p_group *group);
2512 
2513 /**
2514  * p2p_iterate_group_members - Iterate group members
2515  * @group: P2P group context from p2p_group_init()
2516  * @next: iteration pointer, must be a pointer to a void * that is set to %NULL
2517  *	on the first call and not modified later
2518  * Returns: A P2P Device Address for each call and %NULL for no more members
2519  */
2520 const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next);
2521 
2522 /**
2523  * p2p_group_get_client_interface_addr - Get P2P Interface Address of a client in a group
2524  * @group: P2P group context from p2p_group_init()
2525  * @dev_addr: P2P Device Address of the client
2526  * Returns: P2P Interface Address of the client if found or %NULL if no match
2527  * found
2528  */
2529 const u8 * p2p_group_get_client_interface_addr(struct p2p_group *group,
2530 					       const u8 *dev_addr);
2531 
2532 /**
2533  * p2p_group_get_dev_addr - Get a P2P Device Address of a client in a group
2534  * @group: P2P group context from p2p_group_init()
2535  * @addr: P2P Interface Address of the client
2536  * Returns: P2P Device Address of the client if found or %NULL if no match
2537  * found
2538  */
2539 const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr);
2540 
2541 /**
2542  * p2p_group_is_client_connected - Check whether a specific client is connected
2543  * @group: P2P group context from p2p_group_init()
2544  * @addr: P2P Device Address of the client
2545  * Returns: 1 if client is connected or 0 if not
2546  */
2547 int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr);
2548 
2549 /**
2550  * p2p_group_get_config - Get the group configuration
2551  * @group: P2P group context from p2p_group_init()
2552  * Returns: The group configuration pointer
2553  */
2554 const struct p2p_group_config * p2p_group_get_config(struct p2p_group *group);
2555 
2556 /**
2557  * p2p_loop_on_all_groups - Run the given callback on all groups
2558  * @p2p: P2P module context from p2p_init()
2559  * @group_callback: The callback function pointer
2560  * @user_data: Some user data pointer which can be %NULL
2561  *
2562  * The group_callback function can stop the iteration by returning 0.
2563  */
2564 void p2p_loop_on_all_groups(struct p2p_data *p2p,
2565 			    int (*group_callback)(struct p2p_group *group,
2566 						  void *user_data),
2567 			    void *user_data);
2568 
2569 /**
2570  * p2p_get_peer_found - Get P2P peer info structure of a found peer
2571  * @p2p: P2P module context from p2p_init()
2572  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
2573  * @next: Whether to select the peer entry following the one indicated by addr
2574  * Returns: The first P2P peer info available or %NULL if no such peer exists
2575  */
2576 const struct p2p_peer_info *
2577 p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next);
2578 
2579 /**
2580  * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions
2581  * @p2p: P2P module context from p2p_init()
2582  */
2583 void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p);
2584 
2585 /**
2586  * p2p_add_wps_vendor_extension - Add a WPS vendor extension
2587  * @p2p: P2P module context from p2p_init()
2588  * @vendor_ext: The vendor extensions to add
2589  * Returns: 0 on success, -1 on failure
2590  *
2591  * The wpabuf structures in the array are owned by the P2P
2592  * module after this call.
2593  */
2594 int p2p_add_wps_vendor_extension(struct p2p_data *p2p,
2595 				 const struct wpabuf *vendor_ext);
2596 
2597 /**
2598  * p2p_set_oper_channel - Set the P2P operating channel
2599  * @p2p: P2P module context from p2p_init()
2600  * @op_reg_class: Operating regulatory class to set
2601  * @op_channel: operating channel to set
2602  * @cfg_op_channel : Whether op_channel is hardcoded in configuration
2603  * Returns: 0 on success, -1 on failure
2604  */
2605 int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel,
2606 			 int cfg_op_channel);
2607 
2608 /**
2609  * p2p_set_pref_chan - Set P2P preferred channel list
2610  * @p2p: P2P module context from p2p_init()
2611  * @num_pref_chan: Number of entries in pref_chan list
2612  * @pref_chan: Preferred channels or %NULL to remove preferences
2613  * Returns: 0 on success, -1 on failure
2614  */
2615 int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan,
2616 		      const struct p2p_channel *pref_chan);
2617 
2618 /**
2619  * p2p_set_no_go_freq - Set no GO channel ranges
2620  * @p2p: P2P module context from p2p_init()
2621  * @list: Channel ranges or %NULL to remove restriction
2622  * Returns: 0 on success, -1 on failure
2623  */
2624 int p2p_set_no_go_freq(struct p2p_data *p2p,
2625 		       const struct wpa_freq_range_list *list);
2626 
2627 /**
2628  * p2p_in_progress - Check whether a P2P operation is progress
2629  * @p2p: P2P module context from p2p_init()
2630  * Returns: 0 if P2P module is idle, 1 if an operation is in progress but not
2631  * in search state, or 2 if search state operation is in progress
2632  */
2633 int p2p_in_progress(struct p2p_data *p2p);
2634 
2635 const char * p2p_wps_method_text(enum p2p_wps_method method);
2636 
2637 /**
2638  * p2p_set_config_timeout - Set local config timeouts
2639  * @p2p: P2P module context from p2p_init()
2640  * @go_timeout: Time in 10 ms units it takes to start the GO mode
2641  * @client_timeout: Time in 10 ms units it takes to start the client mode
2642  */
2643 void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout,
2644 			    u8 client_timeout);
2645 
2646 int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie);
2647 int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie);
2648 int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie);
2649 int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie);
2650 int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie);
2651 int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie);
2652 int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie);
2653 int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie);
2654 int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem);
2655 int p2p_set_wfd_r2_dev_info(struct p2p_data *p2p, const struct wpabuf *elem);
2656 int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem);
2657 int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p,
2658 				  const struct wpabuf *elem);
2659 struct wpabuf * wifi_display_encaps(struct wpabuf *subelems);
2660 
2661 /**
2662  * p2p_set_disc_int - Set min/max discoverable interval for p2p_find
2663  * @p2p: P2P module context from p2p_init()
2664  * @min_disc_int: minDiscoverableInterval (in units of 100 TU); default 1
2665  * @max_disc_int: maxDiscoverableInterval (in units of 100 TU); default 3
2666  * @max_disc_tu: Maximum number of TUs (1.024 ms) for discoverable interval; or
2667  *	-1 not to limit
2668  * Returns: 0 on success, or -1 on failure
2669  *
2670  * This function can be used to configure minDiscoverableInterval and
2671  * maxDiscoverableInterval parameters for the Listen state during device
2672  * discovery (p2p_find). A random number of 100 TU units is picked for each
2673  * Listen state iteration from [min_disc_int,max_disc_int] range.
2674  *
2675  * max_disc_tu can be used to further limit the discoverable duration. However,
2676  * it should be noted that use of this parameter is not recommended since it
2677  * would not be compliant with the P2P specification.
2678  */
2679 int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
2680 		     int max_disc_tu);
2681 
2682 /**
2683  * p2p_get_state_txt - Get current P2P state for debug purposes
2684  * @p2p: P2P module context from p2p_init()
2685  * Returns: Name of the current P2P module state
2686  *
2687  * It should be noted that the P2P module state names are internal information
2688  * and subject to change at any point, i.e., this information should be used
2689  * mainly for debugging purposes.
2690  */
2691 const char * p2p_get_state_txt(struct p2p_data *p2p);
2692 
2693 struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p,
2694 					   int client_freq,
2695 					   const u8 *go_dev_addr,
2696 					   const u8 *ssid, size_t ssid_len);
2697 struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p,
2698 					   int client_freq,
2699 					   const u8 *go_dev_addr,
2700 					   const u8 *ssid, size_t ssid_len);
2701 
2702 bool p2p_pref_freq_allowed(const struct weighted_pcl *freq_list, bool go);
2703 
2704 struct p2p_nfc_params {
2705 	int sel;
2706 	const u8 *wsc_attr;
2707 	size_t wsc_len;
2708 	const u8 *p2p_attr;
2709 	size_t p2p_len;
2710 
2711 	enum {
2712 		NO_ACTION, JOIN_GROUP, AUTH_JOIN, INIT_GO_NEG, RESP_GO_NEG,
2713 		BOTH_GO, PEER_CLIENT
2714 	} next_step;
2715 	struct p2p_peer_info *peer;
2716 	u8 oob_dev_pw[WPS_OOB_PUBKEY_HASH_LEN + 2 +
2717 		      WPS_OOB_DEVICE_PASSWORD_LEN];
2718 	size_t oob_dev_pw_len;
2719 	int go_freq;
2720 	u8 go_dev_addr[ETH_ALEN];
2721 	u8 go_ssid[SSID_MAX_LEN];
2722 	size_t go_ssid_len;
2723 };
2724 
2725 int p2p_process_nfc_connection_handover(struct p2p_data *p2p,
2726 					struct p2p_nfc_params *params);
2727 
2728 void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id,
2729 				      int go_intent,
2730 				      const u8 *own_interface_addr);
2731 
2732 int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len);
2733 
2734 void p2p_loop_on_known_peers(struct p2p_data *p2p,
2735 			     void (*peer_callback)(struct p2p_peer_info *peer,
2736 						   void *user_data),
2737 			     void *user_data);
2738 
2739 void p2p_set_vendor_elems(struct p2p_data *p2p, struct wpabuf **vendor_elem);
2740 
2741 void p2p_set_intended_addr(struct p2p_data *p2p, const u8 *intended_addr);
2742 
2743 struct p2ps_advertisement *
2744 p2p_service_p2ps_id(struct p2p_data *p2p, u32 adv_id);
2745 int p2p_service_add_asp(struct p2p_data *p2p, int auto_accept, u32 adv_id,
2746 			const char *adv_str, u8 svc_state,
2747 			u16 config_methods, const char *svc_info,
2748 			const u8 *cpt_priority);
2749 int p2p_service_del_asp(struct p2p_data *p2p, u32 adv_id);
2750 void p2p_service_flush_asp(struct p2p_data *p2p);
2751 struct p2ps_advertisement * p2p_get_p2ps_adv_list(struct p2p_data *p2p);
2752 
2753 /**
2754  * p2p_expire_peers - Periodic cleanup function to expire peers
2755  * @p2p: P2P module context from p2p_init()
2756  *
2757  * This is a cleanup function that the entity calling p2p_init() is
2758  * expected to call periodically to clean up expired peer entries.
2759  */
2760 void p2p_expire_peers(struct p2p_data *p2p);
2761 
2762 void p2p_set_own_pref_freq_list(struct p2p_data *p2p,
2763 				const struct weighted_pcl *pref_freq_list,
2764 				unsigned int size);
2765 void p2p_set_override_pref_op_chan(struct p2p_data *p2p, u8 op_class,
2766 				   u8 chan);
2767 
2768 /**
2769  * p2p_group_get_common_freqs - Get the group common frequencies
2770  * @group: P2P group context from p2p_group_init()
2771  * @common_freqs: On return will hold the group common frequencies
2772  * @num: On return will hold the number of group common frequencies
2773  * Returns: 0 on success, -1 otherwise
2774  */
2775 int p2p_group_get_common_freqs(struct p2p_group *group, int *common_freqs,
2776 			       unsigned int *num);
2777 
2778 struct wpabuf * p2p_build_probe_resp_template(struct p2p_data *p2p,
2779 					      unsigned int freq);
2780 
2781 void p2p_set_6ghz_dev_capab(struct p2p_data *p2p, bool allow_6ghz);
2782 bool is_p2p_6ghz_capable(struct p2p_data *p2p);
2783 bool p2p_is_peer_6ghz_capab(struct p2p_data *p2p, const u8 *addr);
2784 bool p2p_peer_wfd_enabled(struct p2p_data *p2p, const u8 *peer_addr);
2785 bool p2p_wfd_enabled(struct p2p_data *p2p);
2786 bool is_p2p_allow_6ghz(struct p2p_data *p2p);
2787 void set_p2p_allow_6ghz(struct p2p_data *p2p, bool value);
2788 int p2p_remove_6ghz_channels(struct weighted_pcl *pref_freq_list, int size);
2789 int p2p_channel_to_freq(int op_class, int channel);
2790 struct wpabuf * p2p_usd_elems(struct p2p_data *p2p);
2791 void p2p_process_usd_elems(struct p2p_data *p2p, const u8 *ies, u16 ies_len,
2792 			   const u8 *peer_addr, unsigned int freq);
2793 int p2p_get_dik_id(struct p2p_data *p2p, const u8 *peer);
2794 
2795 void p2p_set_bootstrapmethods(struct p2p_data *p2p, int bootstrap_methods);
2796 void p2p_set_pasn_type(struct p2p_data *p2p, u8 pasn_type);
2797 void p2p_set_comeback_after(struct p2p_data *p2p, int comeback_after);
2798 void p2p_set_reg_info(struct p2p_data *p2p, u8 val);
2799 void p2p_set_twt_power_mgmt(struct p2p_data *p2p, int val);
2800 void p2p_set_dev_addr(struct p2p_data *p2p, const u8 *addr);
2801 void p2p_set_chan_switch_req_enable(struct p2p_data *p2p, bool val);
2802 void p2p_set_invitation_op_freq(struct p2p_data *p2p, int freq);
2803 
2804 int p2p_get_listen_freq(struct p2p_data *p2p, const u8 *peer_addr);
2805 int p2p_initiate_pasn_auth(struct p2p_data *p2p, const u8 *addr, int freq);
2806 int p2p_initiate_pasn_verify(struct p2p_data *p2p, const u8 *peer_addr,
2807 			     int freq, enum p2p_invite_role role,
2808 			     const u8 *bssid, const u8 *ssid, size_t ssid_len,
2809 			     unsigned int force_freq, const u8 *go_dev_addr,
2810 			     unsigned int pref_freq);
2811 int p2p_pasn_auth_rx(struct p2p_data *p2p, const struct ieee80211_mgmt *mgmt,
2812 		     size_t len, int freq);
2813 int p2p_prepare_data_element(struct p2p_data *p2p, const u8 *peer_addr);
2814 int p2p_parse_data_element(struct p2p_data *p2p, const u8 *data, size_t len);
2815 int p2p_pasn_validate_and_update_pmkid(struct p2p_data *p2p, const u8 *addr,
2816 				       const u8 *pmkid);
2817 int p2p_pasn_auth_tx_status(struct p2p_data *p2p, const u8 *data,
2818 			    size_t data_len, bool acked, bool verify);
2819 int p2p_config_sae_password(struct p2p_data *p2p, const char *pw);
2820 void p2p_pasn_pmksa_set_pmk(struct p2p_data *p2p, const u8 *src, const u8 *dst,
2821 			    const u8 *pmk, size_t pmk_len, const u8 *pmkid);
2822 void p2p_set_store_pasn_ptk(struct p2p_data *p2p, u8 val);
2823 void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk);
2824 int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len);
2825 void p2p_usd_service_hash(struct p2p_data *p2p, const char *service_name);
2826 int p2p_get_dira_info(struct p2p_data *p2p, char *buf, size_t buflen);
2827 
2828 void p2p_update_dfs_ap_info(struct p2p_data *p2p, int freq,
2829 			    enum chan_width ap_ch_width, bool disconnect_evt);
2830 
2831 #endif /* P2P_H */
2832