blob: 60a4a34011c64666928c1b6f767506cdd614c73b [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Wi-Fi Direct - P2P module
3 * Copyright (c) 2009-2010, Atheros Communications
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#ifndef P2P_H
10#define P2P_H
11
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -070012#include "common/ieee802_11_defs.h"
13#include "wps/wps.h"
Sunil Ravi79e6c4f2025-01-04 00:47:06 +000014#include "common/wpa_common.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080015
Sunil Ravic0f5d412024-09-11 22:12:49 +000016#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
Sunil8cd6f4d2022-06-28 18:40:46 +000026struct weighted_pcl;
27
Dmitry Shmidt216983b2015-02-06 10:50:36 -080028/* 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
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080037#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
Dmitry Shmidt216983b2015-02-06 10:50:36 -080043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044/**
45 * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes
46 */
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080047#define P2P_MAX_REG_CLASSES 15
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048
49/**
50 * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class
51 */
Hai Shalomfdcde762020-04-02 11:19:20 -070052#define P2P_MAX_REG_CLASS_CHANNELS 60
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54/**
55 * struct p2p_channels - List of supported channels
56 */
57struct 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
84enum p2p_wps_method {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080085 WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC, WPS_NFC,
86 WPS_P2PS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087};
88
89/**
90 * struct p2p_go_neg_results - P2P Group Owner Negotiation results
91 */
92struct 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
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700111 int ht40;
112
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700113 int vht;
114
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800115 int edmg;
116
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800117 u8 max_oper_chwidth;
118
119 unsigned int vht_center_freq2;
120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121 /**
Hai Shalom74f70d42019-02-11 14:42:39 -0800122 * he - Indicates if IEEE 802.11ax HE is enabled
123 */
124 int he;
125
126 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700127 * ssid - SSID of the group
128 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700129 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130
131 /**
132 * ssid_len - Length of SSID in octets
133 */
134 size_t ssid_len;
135
136 /**
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800137 * 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 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700147 * 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
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800175 * 0 = not persistent
176 * 1 = persistent group without persistent reconnect
177 * 2 = persistent group with persistent reconnect
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 */
179 int persistent_group;
180
181 /**
182 * peer_config_timeout - Peer configuration timeout (in 10 msec units)
183 */
184 unsigned int peer_config_timeout;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000185
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];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220};
221
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800222struct p2ps_provision {
223 /**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800224 * pd_seeker - P2PS provision discovery seeker role
225 */
226 unsigned int pd_seeker:1;
227
228 /**
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800229 * 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 /**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800269 * 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 /**
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800296 * info - Vendor defined extra Provisioning information
297 */
298 char info[0];
299};
300
301struct 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 /**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800335 * 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 /**
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800352 * svc_name - NULL Terminated UTF-8 Service Name, and svc_info storage
353 */
354 char svc_name[0];
355};
356
357
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358struct p2p_data;
359
360enum p2p_scan_type {
361 P2P_SCAN_SOCIAL,
362 P2P_SCAN_FULL,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800363 P2P_SCAN_SPECIFIC,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 P2P_SCAN_SOCIAL_PLUS_ONE
365};
366
367#define P2P_MAX_WPS_VENDOR_EXT 10
368
369/**
Sunil Ravic0f5d412024-09-11 22:12:49 +0000370 * struct p2p_pairing_config - P2P pairing configuration
371 */
372struct 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 /**
Sunil Ravic0f5d412024-09-11 22:12:49 +0000389 * 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/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 * struct p2p_peer_info - P2P peer information
410 */
411struct 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 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700425 char device_name[WPS_DEV_NAME_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426
427 /**
428 * manufacturer - Manufacturer (0..64 octets encoded in UTF-8)
429 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700430 char manufacturer[WPS_MANUFACTURER_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431
432 /**
433 * model_name - Model Name (0..32 octets encoded in UTF-8)
434 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700435 char model_name[WPS_MODEL_NAME_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436
437 /**
438 * model_number - Model Number (0..32 octets encoded in UTF-8)
439 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700440 char model_number[WPS_MODEL_NUMBER_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441
442 /**
443 * serial_number - Serial Number (0..32 octets encoded in UTF-8)
444 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700445 char serial_number[WPS_SERIAL_NUMBER_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446
447 /**
Jouni Malinen75ecf522011-06-27 15:19:46 -0700448 * level - Signal level
449 */
450 int level;
451
452 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 * 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 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700473 u8 wps_sec_dev_type_list[WPS_SEC_DEV_TYPE_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474
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];
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700481
482 /**
483 * wfd_subelems - Wi-Fi Display subelements from WFD IE(s)
484 */
485 struct wpabuf *wfd_subelems;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700486
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;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800494
495 /**
496 * p2ps_instance - P2PS Application Service Info
497 */
498 struct wpabuf *p2ps_instance;
Sunil Ravic0f5d412024-09-11 22:12:49 +0000499
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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514};
515
Jouni Malinen75ecf522011-06-27 15:19:46 -0700516enum p2p_prov_disc_status {
517 P2P_PROV_DISC_SUCCESS,
518 P2P_PROV_DISC_TIMEOUT,
519 P2P_PROV_DISC_REJECTED,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800520 P2P_PROV_DISC_TIMEOUT_JOIN,
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800521 P2P_PROV_DISC_INFO_UNAVAILABLE,
Jouni Malinen75ecf522011-06-27 15:19:46 -0700522};
523
Dmitry Shmidt04949592012-07-19 12:16:46 -0700524struct p2p_channel {
525 u8 op_class;
526 u8 chan;
527};
528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529/**
530 * struct p2p_config - P2P configuration
531 *
532 * This configuration is provided to the P2P module during initialization with
533 * p2p_init().
534 */
535struct p2p_config {
536 /**
537 * country - Country code to use in P2P operations
538 */
539 char country[3];
540
541 /**
542 * reg_class - Regulatory class for own listen channel
543 */
544 u8 reg_class;
545
546 /**
547 * channel - Own listen channel
548 */
549 u8 channel;
550
551 /**
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700552 * channel_forced - the listen channel was forced by configuration
553 * or by control interface and cannot be overridden
554 */
555 u8 channel_forced;
556
557 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 * Regulatory class for own operational channel
559 */
560 u8 op_reg_class;
561
562 /**
563 * op_channel - Own operational channel
564 */
565 u8 op_channel;
566
567 /**
568 * cfg_op_channel - Whether op_channel is hardcoded in configuration
569 */
570 u8 cfg_op_channel;
571
572 /**
573 * channels - Own supported regulatory classes and channels
574 *
575 * List of supposerted channels per regulatory class. The regulatory
576 * classes are defined in IEEE Std 802.11-2007 Annex J and the
577 * numbering of the clases depends on the configured country code.
578 */
579 struct p2p_channels channels;
580
581 /**
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700582 * cli_channels - Additional client channels
583 *
584 * This list of channels (if any) will be used when advertising local
585 * channels during GO Negotiation or Invitation for the cases where the
586 * local end may become the client. This may allow the peer to become a
587 * GO on additional channels if it supports these options. The main use
588 * case for this is to include passive-scan channels on devices that may
589 * not know their current location and have configured most channels to
590 * not allow initiation of radition (i.e., another device needs to take
591 * master responsibilities).
592 */
593 struct p2p_channels cli_channels;
594
595 /**
Dmitry Shmidt04949592012-07-19 12:16:46 -0700596 * num_pref_chan - Number of pref_chan entries
597 */
598 unsigned int num_pref_chan;
599
600 /**
601 * pref_chan - Preferred channels for GO Negotiation
602 */
603 struct p2p_channel *pref_chan;
604
605 /**
Hai Shalom60840252021-02-19 19:02:11 -0800606 * p2p_6ghz_disable - Disable 6GHz for P2P operations
607 */
608 bool p2p_6ghz_disable;
609
610 /**
Shuibing Daie2fad412023-05-05 14:08:11 -0700611 * p2p_dfs_chan_enable - Enable p2p Go to operate on dfs channel
612 */
613 bool p2p_dfs_chan_enable;
614
615 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 * pri_dev_type - Primary Device Type (see WPS)
617 */
618 u8 pri_dev_type[8];
619
620 /**
621 * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types
622 */
623#define P2P_SEC_DEVICE_TYPES 5
624
625 /**
626 * sec_dev_type - Optional secondary device types
627 */
628 u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8];
629
630 /**
631 * num_sec_dev_types - Number of sec_dev_type entries
632 */
633 size_t num_sec_dev_types;
634
635 /**
636 * dev_addr - P2P Device Address
637 */
638 u8 dev_addr[ETH_ALEN];
639
640 /**
641 * dev_name - Device Name
642 */
643 char *dev_name;
644
645 char *manufacturer;
646 char *model_name;
647 char *model_number;
648 char *serial_number;
649
650 u8 uuid[16];
651 u16 config_methods;
652
653 /**
654 * concurrent_operations - Whether concurrent operations are supported
655 */
656 int concurrent_operations;
657
658 /**
659 * max_peers - Maximum number of discovered peers to remember
660 *
661 * If more peers are discovered, older entries will be removed to make
662 * room for the new ones.
663 */
664 size_t max_peers;
665
666 /**
667 * p2p_intra_bss - Intra BSS communication is supported
668 */
669 int p2p_intra_bss;
670
671 /**
672 * ssid_postfix - Postfix data to add to the SSID
673 *
674 * This data will be added to the end of the SSID after the
675 * DIRECT-<random two octets> prefix.
676 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700677 u8 ssid_postfix[SSID_MAX_LEN - 9];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678
679 /**
680 * ssid_postfix_len - Length of the ssid_postfix data
681 */
682 size_t ssid_postfix_len;
683
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800684 /**
685 * max_listen - Maximum listen duration in ms
686 */
687 unsigned int max_listen;
688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 /**
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700690 * passphrase_len - Passphrase length (8..63)
691 *
692 * This parameter controls the length of the random passphrase that is
693 * generated at the GO.
694 */
695 unsigned int passphrase_len;
696
697 /**
Sunil Ravic0f5d412024-09-11 22:12:49 +0000698 * p2p_pairing_config - P2P pairing configuration
699 */
700 struct p2p_pairing_config pairing_config;
701
702 /**
703 * reg_info - Regulatory info encoding for operation in 6 GHz band
704 */
705 u8 reg_info;
706
707 /**
708 * dfs_owner - Enable P2P GO to act as DFS Owner
709 */
710 bool dfs_owner;
711
712 /**
713 * twt_power_mgmt - Enable TWT based power management for P2P
714 */
715 bool twt_power_mgmt;
716
717 /**
718 * comeback_after - Bootstrap request unauthorized for peer
719 *
720 * Ask to come back after this many TUs.
721 */
722 u16 comeback_after;
723
724 /**
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000725 * chan_switch_req_enable - Enable P2P client channel switch request
726 */
727 bool chan_switch_req_enable;
728
729#ifdef CONFIG_TESTING_OPTIONS
730 /**
731 * Operating class for own operational channel in Invitation Response
732 */
733 u8 inv_op_class;
734
735 /**
736 * inv_op_channel - Own operational channel in Invitation Response
737 */
738 u8 inv_op_channel;
739#endif /* CONFIG_TESTING_OPTIONS */
740
741 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 * cb_ctx - Context to use with callback functions
743 */
744 void *cb_ctx;
745
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700746 /**
747 * debug_print - Debug print
748 * @ctx: Callback context from cb_ctx
749 * @level: Debug verbosity level (MSG_*)
750 * @msg: Debug message
751 */
752 void (*debug_print)(void *ctx, int level, const char *msg);
753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754
755 /* Callbacks to request lower layer driver operations */
756
757 /**
758 * p2p_scan - Request a P2P scan/search
759 * @ctx: Callback context from cb_ctx
760 * @type: Scan type
761 * @freq: Specific frequency (MHz) to scan or 0 for no restriction
762 * @num_req_dev_types: Number of requested device types
763 * @req_dev_types: Array containing requested device types
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800764 * @dev_id: Device ID to search for or %NULL to find all devices
Dmitry Shmidt04949592012-07-19 12:16:46 -0700765 * @pw_id: Device Password ID
Hai Shaloma20dcd72022-02-04 13:43:00 -0800766 * @include_6ghz: Include 6 GHz channels in P2P scan
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 * Returns: 0 on success, -1 on failure
768 *
769 * This callback function is used to request a P2P scan or search
770 * operation to be completed. Type type argument specifies which type
771 * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the
772 * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800773 * indicates that all channels are to be scanned. @P2P_SCAN_SPECIFIC
774 * request a scan of a single channel specified by freq.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels
776 * plus one extra channel specified by freq.
777 *
778 * The full scan is used for the initial scan to find group owners from
779 * all. The other types are used during search phase scan of the social
780 * channels (with potential variation if the Listen channel of the
781 * target peer is known or if other channels are scanned in steps).
782 *
783 * The scan results are returned after this call by calling
784 * p2p_scan_res_handler() for each scan result that has a P2P IE and
785 * then calling p2p_scan_res_handled() to indicate that all scan
786 * results have been indicated.
787 */
788 int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq,
789 unsigned int num_req_dev_types,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800790 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id,
791 bool include_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792
793 /**
794 * send_probe_resp - Transmit a Probe Response frame
795 * @ctx: Callback context from cb_ctx
796 * @buf: Probe Response frame (including the header and body)
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700797 * @freq: Forced frequency (in MHz) to use or 0.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 * Returns: 0 on success, -1 on failure
799 *
800 * This function is used to reply to Probe Request frames that were
801 * indicated with a call to p2p_probe_req_rx(). The response is to be
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700802 * sent on the same channel, unless otherwise specified, or to be
803 * dropped if the driver is not listening to Probe Request frames
804 * anymore.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805 *
806 * Alternatively, the responsibility for building the Probe Response
807 * frames in Listen state may be in another system component in which
808 * case this function need to be implemented (i.e., the function
809 * pointer can be %NULL). The WPS and P2P IEs to be added for Probe
810 * Response frames in such a case are available from the
811 * start_listen() callback. It should be noted that the received Probe
812 * Request frames must be indicated by calling p2p_probe_req_rx() even
813 * if this send_probe_resp() is not used.
814 */
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700815 int (*send_probe_resp)(void *ctx, const struct wpabuf *buf,
816 unsigned int freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817
818 /**
819 * send_action - Transmit an Action frame
820 * @ctx: Callback context from cb_ctx
821 * @freq: Frequency in MHz for the channel on which to transmit
822 * @dst: Destination MAC address (Address 1)
823 * @src: Source MAC address (Address 2)
824 * @bssid: BSSID (Address 3)
825 * @buf: Frame body (starting from Category field)
826 * @len: Length of buf in octets
827 * @wait_time: How many msec to wait for a response frame
Hai Shalom021b0b52019-04-10 11:17:58 -0700828 * @scheduled: Return value indicating whether the transmissions was
829 * scheduled to happen once the radio is available
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830 * Returns: 0 on success, -1 on failure
831 *
832 * The Action frame may not be transmitted immediately and the status
833 * of the transmission must be reported by calling
834 * p2p_send_action_cb() once the frame has either been transmitted or
835 * it has been dropped due to excessive retries or other failure to
836 * transmit.
837 */
838 int (*send_action)(void *ctx, unsigned int freq, const u8 *dst,
839 const u8 *src, const u8 *bssid, const u8 *buf,
Hai Shalom021b0b52019-04-10 11:17:58 -0700840 size_t len, unsigned int wait_time, int *scheduled);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841
842 /**
843 * send_action_done - Notify that Action frame sequence was completed
844 * @ctx: Callback context from cb_ctx
845 *
846 * This function is called when the Action frame sequence that was
847 * started with send_action() has been completed, i.e., when there is
848 * no need to wait for a response from the destination peer anymore.
849 */
850 void (*send_action_done)(void *ctx);
851
852 /**
853 * start_listen - Start Listen state
854 * @ctx: Callback context from cb_ctx
855 * @freq: Frequency of the listen channel in MHz
856 * @duration: Duration for the Listen state in milliseconds
857 * @probe_resp_ie: IE(s) to be added to Probe Response frames
858 * Returns: 0 on success, -1 on failure
859 *
860 * This Listen state may not start immediately since the driver may
861 * have other pending operations to complete first. Once the Listen
862 * state has started, p2p_listen_cb() must be called to notify the P2P
863 * module. Once the Listen state is stopped, p2p_listen_end() must be
864 * called to notify the P2P module that the driver is not in the Listen
865 * state anymore.
866 *
867 * If the send_probe_resp() is not used for generating the response,
868 * the IEs from probe_resp_ie need to be added to the end of the Probe
869 * Response frame body. If send_probe_resp() is used, the probe_resp_ie
870 * information can be ignored.
871 */
872 int (*start_listen)(void *ctx, unsigned int freq,
873 unsigned int duration,
874 const struct wpabuf *probe_resp_ie);
875 /**
876 * stop_listen - Stop Listen state
877 * @ctx: Callback context from cb_ctx
878 *
879 * This callback can be used to stop a Listen state operation that was
880 * previously requested with start_listen().
881 */
882 void (*stop_listen)(void *ctx);
883
884 /**
885 * get_noa - Get current Notice of Absence attribute payload
886 * @ctx: Callback context from cb_ctx
887 * @interface_addr: P2P Interface Address of the GO
888 * @buf: Buffer for returning NoA
889 * @buf_len: Buffer length in octets
890 * Returns: Number of octets used in buf, 0 to indicate no NoA is being
891 * advertized, or -1 on failure
892 *
893 * This function is used to fetch the current Notice of Absence
894 * attribute value from GO.
895 */
896 int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf,
897 size_t buf_len);
898
899 /* Callbacks to notify events to upper layer management entity */
900
901 /**
902 * dev_found - Notification of a found P2P Device
903 * @ctx: Callback context from cb_ctx
904 * @addr: Source address of the message triggering this notification
905 * @info: P2P peer information
906 * @new_device: Inform if the peer is newly found
907 *
908 * This callback is used to notify that a new P2P Device has been
909 * found. This may happen, e.g., during Search state based on scan
910 * results or during Listen state based on receive Probe Request and
911 * Group Owner Negotiation Request.
912 */
913 void (*dev_found)(void *ctx, const u8 *addr,
914 const struct p2p_peer_info *info,
915 int new_device);
916
917 /**
918 * dev_lost - Notification of a lost P2P Device
919 * @ctx: Callback context from cb_ctx
920 * @dev_addr: P2P Device Address of the lost P2P Device
921 *
922 * This callback is used to notify that a P2P Device has been deleted.
923 */
924 void (*dev_lost)(void *ctx, const u8 *dev_addr);
925
926 /**
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700927 * find_stopped - Notification of a p2p_find operation stopping
928 * @ctx: Callback context from cb_ctx
929 */
930 void (*find_stopped)(void *ctx);
931
932 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933 * go_neg_req_rx - Notification of a receive GO Negotiation Request
934 * @ctx: Callback context from cb_ctx
935 * @src: Source address of the message triggering this notification
936 * @dev_passwd_id: WPS Device Password ID
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700937 * @go_intent: Peer's GO Intent
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938 *
939 * This callback is used to notify that a P2P Device is requesting
940 * group owner negotiation with us, but we do not have all the
941 * necessary information to start GO Negotiation. This indicates that
942 * the local user has not authorized the connection yet by providing a
943 * PIN or PBC button press. This information can be provided with a
944 * call to p2p_connect().
945 */
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700946 void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id,
947 u8 go_intent);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700948
949 /**
950 * go_neg_completed - Notification of GO Negotiation results
951 * @ctx: Callback context from cb_ctx
952 * @res: GO Negotiation results
953 *
954 * This callback is used to notify that Group Owner Negotiation has
955 * been completed. Non-zero struct p2p_go_neg_results::status indicates
956 * failed negotiation. In case of success, this function is responsible
957 * for creating a new group interface (or using the existing interface
958 * depending on driver features), setting up the group interface in
959 * proper mode based on struct p2p_go_neg_results::role_go and
960 * initializing WPS provisioning either as a Registrar (if GO) or as an
961 * Enrollee. Successful WPS provisioning must be indicated by calling
962 * p2p_wps_success_cb(). The callee is responsible for timing out group
963 * formation if WPS provisioning cannot be completed successfully
964 * within 15 seconds.
965 */
966 void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res);
967
968 /**
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000969 * set_go_security_config - Set security configuration for P2P GO
970 * @ctx: Callback context from cb_ctx
971 * @res: GO Negotiation results
972 *
973 * This callback is used to set PMK/passphrase derived during PASN
974 * authentication with a P2P client. This will fetch an active P2P group
975 * owner instance and configure PMKSA in case of password based PASN, or
976 * configures the passphrase and derive PT in case of unauthenticated
977 * PASN.
978 */
979 void (*set_go_security_config)(void *ctx,
980 struct p2p_go_neg_results *res);
981
982 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983 * sd_request - Callback on Service Discovery Request
984 * @ctx: Callback context from cb_ctx
985 * @freq: Frequency (in MHz) of the channel
986 * @sa: Source address of the request
987 * @dialog_token: Dialog token
988 * @update_indic: Service Update Indicator from the source of request
989 * @tlvs: P2P Service Request TLV(s)
990 * @tlvs_len: Length of tlvs buffer in octets
991 *
992 * This callback is used to indicate reception of a service discovery
993 * request. Response to the query must be indicated by calling
994 * p2p_sd_response() with the context information from the arguments to
995 * this callback function.
996 *
997 * This callback handler can be set to %NULL to indicate that service
998 * discovery is not supported.
999 */
1000 void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token,
1001 u16 update_indic, const u8 *tlvs, size_t tlvs_len);
1002
1003 /**
1004 * sd_response - Callback on Service Discovery Response
1005 * @ctx: Callback context from cb_ctx
1006 * @sa: Source address of the request
1007 * @update_indic: Service Update Indicator from the source of response
1008 * @tlvs: P2P Service Response TLV(s)
1009 * @tlvs_len: Length of tlvs buffer in octets
1010 *
1011 * This callback is used to indicate reception of a service discovery
1012 * response. This callback handler can be set to %NULL if no service
1013 * discovery requests are used. The information provided with this call
1014 * is replies to the queries scheduled with p2p_sd_request().
1015 */
1016 void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic,
1017 const u8 *tlvs, size_t tlvs_len);
1018
1019 /**
1020 * prov_disc_req - Callback on Provisiong Discovery Request
1021 * @ctx: Callback context from cb_ctx
1022 * @peer: Source address of the request
1023 * @config_methods: Requested WPS Config Method
1024 * @dev_addr: P2P Device Address of the found P2P Device
1025 * @pri_dev_type: Primary Device Type
1026 * @dev_name: Device Name
1027 * @supp_config_methods: Supported configuration Methods
1028 * @dev_capab: Device Capabilities
1029 * @group_capab: Group Capabilities
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001030 * @group_id: P2P Group ID (or %NULL if not included)
1031 * @group_id_len: Length of P2P Group ID
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001032 *
1033 * This callback is used to indicate reception of a Provision Discovery
1034 * Request frame that the P2P module accepted.
1035 */
1036 void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods,
1037 const u8 *dev_addr, const u8 *pri_dev_type,
1038 const char *dev_name, u16 supp_config_methods,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001039 u8 dev_capab, u8 group_capab,
1040 const u8 *group_id, size_t group_id_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041
1042 /**
1043 * prov_disc_resp - Callback on Provisiong Discovery Response
1044 * @ctx: Callback context from cb_ctx
1045 * @peer: Source address of the response
1046 * @config_methods: Value from p2p_prov_disc_req() or 0 on failure
1047 *
1048 * This callback is used to indicate reception of a Provision Discovery
1049 * Response frame for a pending request scheduled with
1050 * p2p_prov_disc_req(). This callback handler can be set to %NULL if
1051 * provision discovery is not used.
1052 */
1053 void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods);
1054
1055 /**
Jouni Malinen75ecf522011-06-27 15:19:46 -07001056 * prov_disc_fail - Callback on Provision Discovery failure
1057 * @ctx: Callback context from cb_ctx
1058 * @peer: Source address of the response
1059 * @status: Cause of failure, will not be %P2P_PROV_DISC_SUCCESS
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001060 * @adv_id: If non-zero, then the adv_id of the PD Request
1061 * @adv_mac: P2P Device Address of the advertizer
1062 * @deferred_session_resp: Deferred session response sent by advertizer
Jouni Malinen75ecf522011-06-27 15:19:46 -07001063 *
1064 * This callback is used to indicate either a failure or no response
1065 * to an earlier provision discovery request.
1066 *
1067 * This callback handler can be set to %NULL if provision discovery
1068 * is not used or failures do not need to be indicated.
1069 */
1070 void (*prov_disc_fail)(void *ctx, const u8 *peer,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001071 enum p2p_prov_disc_status status,
1072 u32 adv_id, const u8 *adv_mac,
1073 const char *deferred_session_resp);
Jouni Malinen75ecf522011-06-27 15:19:46 -07001074
1075 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 * invitation_process - Optional callback for processing Invitations
1077 * @ctx: Callback context from cb_ctx
1078 * @sa: Source address of the Invitation Request
1079 * @bssid: P2P Group BSSID from the request or %NULL if not included
1080 * @go_dev_addr: GO Device Address from P2P Group ID
1081 * @ssid: SSID from P2P Group ID
1082 * @ssid_len: Length of ssid buffer in octets
1083 * @go: Variable for returning whether the local end is GO in the group
1084 * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO)
1085 * @force_freq: Variable for returning forced frequency for the group
1086 * @persistent_group: Whether this is an invitation to reinvoke a
1087 * persistent group (instead of invitation to join an active
1088 * group)
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001089 * @channels: Available operating channels for the group
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001090 * @dev_pw_id: Device Password ID for NFC static handover or -1 if not
1091 * used
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001092 * @p2p2: Whether invitation request was wrapped in PASN authentication
1093 * received from a P2P2 device
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 * Returns: Status code (P2P_SC_*)
1095 *
1096 * This optional callback can be used to implement persistent reconnect
1097 * by allowing automatic restarting of persistent groups without user
1098 * interaction. If this callback is not implemented (i.e., is %NULL),
1099 * the received Invitation Request frames are replied with
1100 * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the
1101 * invitation_result() callback.
1102 *
1103 * If the requested parameters are acceptable and the group is known,
1104 * %P2P_SC_SUCCESS may be returned. If the requested group is unknown,
1105 * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED
1106 * can be returned if there is not enough data to provide immediate
1107 * response, i.e., if some sort of user interaction is needed. The
1108 * invitation_received() callback will be called in that case
1109 * immediately after this call.
1110 */
1111 u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid,
1112 const u8 *go_dev_addr, const u8 *ssid,
1113 size_t ssid_len, int *go, u8 *group_bssid,
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001114 int *force_freq, int persistent_group,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001115 const struct p2p_channels *channels,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001116 int dev_pw_id, bool p2p2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117
1118 /**
1119 * invitation_received - Callback on Invitation Request RX
1120 * @ctx: Callback context from cb_ctx
1121 * @sa: Source address of the Invitation Request
1122 * @bssid: P2P Group BSSID or %NULL if not received
1123 * @ssid: SSID of the group
1124 * @ssid_len: Length of ssid in octets
1125 * @go_dev_addr: GO Device Address
1126 * @status: Response Status
1127 * @op_freq: Operational frequency for the group
1128 *
1129 * This callback is used to indicate sending of an Invitation Response
1130 * for a received Invitation Request. If status == 0 (success), the
1131 * upper layer code is responsible for starting the group. status == 1
1132 * indicates need to get user authorization for the group. Other status
1133 * values indicate that the invitation request was rejected.
1134 */
1135 void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid,
1136 const u8 *ssid, size_t ssid_len,
1137 const u8 *go_dev_addr, u8 status,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001138 int op_freq, const u8 *pmkid, const u8 *pmk,
1139 size_t pmk_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140
1141 /**
1142 * invitation_result - Callback on Invitation result
1143 * @ctx: Callback context from cb_ctx
1144 * @status: Negotiation result (Status Code)
1145 * @bssid: P2P Group BSSID or %NULL if not received
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08001146 * @channels: Available operating channels for the group
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001147 * @addr: Peer address
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001148 * @freq: Frequency (in MHz) indicated during invitation or 0
Dmitry Shmidt15907092014-03-25 10:42:57 -07001149 * @peer_oper_freq: Operating frequency (in MHz) advertized by the peer
1150 * during invitation or 0
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 *
1152 * This callback is used to indicate result of an Invitation procedure
1153 * started with a call to p2p_invite(). The indicated status code is
1154 * the value received from the peer in Invitation Response with 0
1155 * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a
1156 * local failure in transmitting the Invitation Request.
1157 */
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08001158 void (*invitation_result)(void *ctx, int status, const u8 *bssid,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001159 const struct p2p_channels *channels,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001160 const u8 *addr, int freq, int peer_oper_freq,
1161 const u8 *pmkid, const u8 *pmk,
1162 size_t pmk_len);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001163
1164 /**
1165 * go_connected - Check whether we are connected to a GO
1166 * @ctx: Callback context from cb_ctx
1167 * @dev_addr: P2P Device Address of a GO
1168 * Returns: 1 if we are connected as a P2P client to the specified GO
1169 * or 0 if not.
1170 */
1171 int (*go_connected)(void *ctx, const u8 *dev_addr);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001172
1173 /**
1174 * presence_resp - Callback on Presence Response
1175 * @ctx: Callback context from cb_ctx
1176 * @src: Source address (GO's P2P Interface Address)
1177 * @status: Result of the request (P2P_SC_*)
1178 * @noa: Returned NoA value
1179 * @noa_len: Length of the NoA buffer in octets
1180 */
1181 void (*presence_resp)(void *ctx, const u8 *src, u8 status,
1182 const u8 *noa, size_t noa_len);
Dmitry Shmidt18463232014-01-24 12:29:41 -08001183
1184 /**
1185 * is_concurrent_session_active - Check whether concurrent session is
1186 * active on other virtual interfaces
1187 * @ctx: Callback context from cb_ctx
1188 * Returns: 1 if concurrent session is active on other virtual interface
1189 * or 0 if not.
1190 */
1191 int (*is_concurrent_session_active)(void *ctx);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -07001192
1193 /**
1194 * is_p2p_in_progress - Check whether P2P operation is in progress
1195 * @ctx: Callback context from cb_ctx
1196 * Returns: 1 if P2P operation (e.g., group formation) is in progress
1197 * or 0 if not.
1198 */
1199 int (*is_p2p_in_progress)(void *ctx);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001200
1201 /**
1202 * Determine if we have a persistent group we share with remote peer
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001203 * and allocate interface for this group if needed
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001204 * @ctx: Callback context from cb_ctx
1205 * @addr: Peer device address to search for
1206 * @ssid: Persistent group SSID or %NULL if any
1207 * @ssid_len: Length of @ssid
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001208 * @go_dev_addr: Buffer for returning GO P2P Device Address
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001209 * @ret_ssid: Buffer for returning group SSID
1210 * @ret_ssid_len: Buffer for returning length of @ssid
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001211 * @intended_iface_addr: Buffer for returning intended iface address
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001212 * Returns: 1 if a matching persistent group was found, 0 otherwise
1213 */
1214 int (*get_persistent_group)(void *ctx, const u8 *addr, const u8 *ssid,
1215 size_t ssid_len, u8 *go_dev_addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001216 u8 *ret_ssid, size_t *ret_ssid_len,
1217 u8 *intended_iface_addr);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001218
1219 /**
1220 * Get information about a possible local GO role
1221 * @ctx: Callback context from cb_ctx
1222 * @intended_addr: Buffer for returning intended GO interface address
1223 * @ssid: Buffer for returning group SSID
1224 * @ssid_len: Buffer for returning length of @ssid
1225 * @group_iface: Buffer for returning whether a separate group interface
1226 * would be used
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001227 * @freq: Variable for returning the current operating frequency of a
1228 * currently running P2P GO.
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001229 * Returns: 1 if GO info found, 0 otherwise
1230 *
1231 * This is used to compose New Group settings (SSID, and intended
1232 * address) during P2PS provisioning if results of provisioning *might*
1233 * result in our being an autonomous GO.
1234 */
1235 int (*get_go_info)(void *ctx, u8 *intended_addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001236 u8 *ssid, size_t *ssid_len, int *group_iface,
1237 unsigned int *freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001238
1239 /**
1240 * remove_stale_groups - Remove stale P2PS groups
1241 *
1242 * Because P2PS stages *potential* GOs, and remote devices can remove
1243 * credentials unilaterally, we need to make sure we don't let stale
1244 * unusable groups build up.
1245 */
1246 int (*remove_stale_groups)(void *ctx, const u8 *peer, const u8 *go,
1247 const u8 *ssid, size_t ssid_len);
1248
1249 /**
1250 * p2ps_prov_complete - P2PS provisioning complete
1251 *
1252 * When P2PS provisioning completes (successfully or not) we must
1253 * transmit all of the results to the upper layers.
1254 */
Sunil Ravic0f5d412024-09-11 22:12:49 +00001255 void (*p2ps_prov_complete)(void *ctx, enum p2p_status_code status,
1256 const u8 *dev,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001257 const u8 *adv_mac, const u8 *ses_mac,
1258 const u8 *grp_mac, u32 adv_id, u32 ses_id,
1259 u8 conncap, int passwd_id,
1260 const u8 *persist_ssid,
1261 size_t persist_ssid_size, int response_done,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001262 int prov_start, const char *session_info,
1263 const u8 *feat_cap, size_t feat_cap_len,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001264 unsigned int freq, const u8 *group_ssid,
1265 size_t group_ssid_len);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001266
1267 /**
1268 * prov_disc_resp_cb - Callback for indicating completion of PD Response
1269 * @ctx: Callback context from cb_ctx
1270 * Returns: 1 if operation was started, 0 otherwise
1271 *
1272 * This callback can be used to perform any pending actions after
1273 * provisioning. It is mainly used for P2PS pending group creation.
1274 */
1275 int (*prov_disc_resp_cb)(void *ctx);
1276
1277 /**
1278 * p2ps_group_capability - Determine group capability
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001279 * @ctx: Callback context from cb_ctx
1280 * @incoming: Peer requested roles, expressed with P2PS_SETUP_* bitmap.
1281 * @role: Local roles, expressed with P2PS_SETUP_* bitmap.
1282 * @force_freq: Variable for returning forced frequency for the group.
1283 * @pref_freq: Variable for returning preferred frequency for the group.
1284 * Returns: P2PS_SETUP_* bitmap of group capability result.
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001285 *
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001286 * This function can be used to determine group capability and
1287 * frequencies based on information from P2PS PD exchange and the
1288 * current state of ongoing groups and driver capabilities.
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001289 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001290 u8 (*p2ps_group_capability)(void *ctx, u8 incoming, u8 role,
1291 unsigned int *force_freq,
1292 unsigned int *pref_freq);
1293
1294 /**
1295 * get_pref_freq_list - Get preferred frequency list for an interface
1296 * @ctx: Callback context from cb_ctx
1297 * @go: Whether the use if for GO role
1298 * @len: Length of freq_list in entries (both IN and OUT)
1299 * @freq_list: Buffer for returning the preferred frequencies (MHz)
1300 * Returns: 0 on success, -1 on failure
1301 *
1302 * This function can be used to query the preferred frequency list from
1303 * the driver specific to a particular interface type.
1304 */
1305 int (*get_pref_freq_list)(void *ctx, int go,
Sunil8cd6f4d2022-06-28 18:40:46 +00001306 unsigned int *len,
1307 struct weighted_pcl *freq_list);
Sunil Ravic0f5d412024-09-11 22:12:49 +00001308
1309 /**
1310 * register_bootstrap_comeback - Register timeout to initiate bootstrap
1311 * comeback request
1312 * @ctx: Callback context from cb_ctx
1313 * @addr: P2P Device Address to which comeback request is to be sent
1314 * @comeback_after: Time in TUs after which comeback request is sent
1315 *
1316 * This function can be used to send comeback request after given
1317 * timeout.
1318 */
1319 void (*register_bootstrap_comeback)(void *ctx, const u8 *addr,
1320 u16 comeback_after);
1321
1322 /**
1323 * bootstrap_req_rx - Indicate bootstrap request from a P2P peer
1324 * @ctx: Callback context from cb_ctx
1325 * @addr: P2P device address from which bootstrap request was received
1326 * @bootstrap_method: Bootstrapping method request by the peer device
1327 *
1328 * This function can be used to notify that bootstrap request is
1329 * received from a P2P peer.
1330 */
1331 void (*bootstrap_req_rx)(void *ctx, const u8 *addr,
1332 u16 bootstrap_method);
1333
1334 /**
1335 * bootstrap_completed - Indicate bootstrapping completed with P2P peer
1336 * @ctx: Callback context from cb_ctx
1337 * @addr: P2P device address with which bootstrapping is completed
1338 * @status: P2P Status Code of bootstrapping handshake
1339 * @freq: Frequency in which bootstrapping is done
1340 *
1341 * This function can be used to notify the status of bootstrapping
1342 * handshake.
1343 */
1344 void (*bootstrap_completed)(void *ctx, const u8 *addr,
1345 enum p2p_status_code status, int freq);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001346
1347 /**
1348 * validate_dira - Indicate reception of DIRA to be validated against a
1349 * list of available device identity keys
1350 * @ctx: Callback context from cb_ctx
1351 * @peer_addr: P2P Device address of the peer
1352 * @dira: DIRA attribute present in the USD frames
1353 * @dira_len: Length of DIRA
1354 *
1355 * This function can be used to validate DIRA and configure PMK of a
1356 * paired/persistent peer from configuration. The handler function is
1357 * expected to call p2p_pasn_pmksa_set_pmk() to set the PMK/PMKID in
1358 * case a matching entry is found.
1359 */
1360 void (*validate_dira)(void *ctx, const u8 *peer_addr,
1361 const u8 *dira, size_t dira_len);
1362
1363 /**
1364 * pasn_send_mgmt - Function handler to transmit a Management frame
1365 * @ctx: Callback context from cb_ctx
1366 * @data: Frame to transmit
1367 * @data_len: Length of frame to transmit
1368 * @noack: No ack flag
1369 * @freq: Frequency in MHz for the channel on which to transmit
1370 * @wait: How many milliseconds to wait for a response frame
1371 * Returns: 0 on success, -1 on failure
1372 */
1373 int (*pasn_send_mgmt)(void *ctx, const u8 *data, size_t data_len,
1374 int noack, unsigned int freq, unsigned int wait);
1375
1376 /**
1377 * prepare_data_element - Function handler to update protocol specific
1378 * elements in PASN authentication frames
1379 * @ctx: Callback context from cb_ctx
1380 * @peer_addr: Peer MAC address
1381 * Returns: 0 on success, -1 on failure
1382 */
1383 int (*prepare_data_element)(void *ctx, const u8 *peer_addr);
1384
1385 /**
1386 * parse_data_element - Function handler to parse P2P data element
1387 * @ctx: Callback context from cb_ctx
1388 * @data: Data to be parsed
1389 * @len: Length of data
1390 * Returns: 0 on success, -1 on failure
1391 */
1392 int (*parse_data_element)(void *ctx, const u8 *data, size_t len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001393};
1394
1395
1396/* P2P module initialization/deinitialization */
1397
1398/**
1399 * p2p_init - Initialize P2P module
1400 * @cfg: P2P module configuration
1401 * Returns: Pointer to private data or %NULL on failure
1402 *
1403 * This function is used to initialize global P2P module context (one per
1404 * device). The P2P module will keep a copy of the configuration data, so the
1405 * caller does not need to maintain this structure. However, the callback
1406 * functions and the context parameters to them must be kept available until
1407 * the P2P module is deinitialized with p2p_deinit().
1408 */
1409struct p2p_data * p2p_init(const struct p2p_config *cfg);
1410
1411/**
1412 * p2p_deinit - Deinitialize P2P module
1413 * @p2p: P2P module context from p2p_init()
1414 */
1415void p2p_deinit(struct p2p_data *p2p);
1416
1417/**
1418 * p2p_flush - Flush P2P module state
1419 * @p2p: P2P module context from p2p_init()
1420 *
1421 * This command removes the P2P module state like peer device entries.
1422 */
1423void p2p_flush(struct p2p_data *p2p);
1424
1425/**
1426 * p2p_unauthorize - Unauthorize the specified peer device
1427 * @p2p: P2P module context from p2p_init()
1428 * @addr: P2P peer entry to be unauthorized
1429 * Returns: 0 on success, -1 on failure
1430 *
1431 * This command removes any connection authorization from the specified P2P
1432 * peer device address. This can be used, e.g., to cancel effect of a previous
1433 * p2p_authorize() or p2p_connect() call that has not yet resulted in completed
1434 * GO Negotiation.
1435 */
1436int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr);
1437
1438/**
1439 * p2p_set_dev_name - Set device name
1440 * @p2p: P2P module context from p2p_init()
1441 * Returns: 0 on success, -1 on failure
1442 *
1443 * This function can be used to update the P2P module configuration with
1444 * information that was not available at the time of the p2p_init() call.
1445 */
1446int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name);
1447
1448int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer);
1449int p2p_set_model_name(struct p2p_data *p2p, const char *model_name);
1450int p2p_set_model_number(struct p2p_data *p2p, const char *model_number);
1451int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number);
1452
1453void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods);
1454void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid);
1455
1456/**
1457 * p2p_set_pri_dev_type - Set primary device type
1458 * @p2p: P2P module context from p2p_init()
1459 * Returns: 0 on success, -1 on failure
1460 *
1461 * This function can be used to update the P2P module configuration with
1462 * information that was not available at the time of the p2p_init() call.
1463 */
1464int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type);
1465
1466/**
1467 * p2p_set_sec_dev_types - Set secondary device types
1468 * @p2p: P2P module context from p2p_init()
1469 * Returns: 0 on success, -1 on failure
1470 *
1471 * This function can be used to update the P2P module configuration with
1472 * information that was not available at the time of the p2p_init() call.
1473 */
1474int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8],
1475 size_t num_dev_types);
1476
1477int p2p_set_country(struct p2p_data *p2p, const char *country);
1478
1479
1480/* Commands from upper layer management entity */
1481
1482enum p2p_discovery_type {
1483 P2P_FIND_START_WITH_FULL,
1484 P2P_FIND_ONLY_SOCIAL,
1485 P2P_FIND_PROGRESSIVE
1486};
1487
1488/**
1489 * p2p_find - Start P2P Find (Device Discovery)
1490 * @p2p: P2P module context from p2p_init()
1491 * @timeout: Timeout for find operation in seconds or 0 for no timeout
1492 * @type: Device Discovery type
1493 * @num_req_dev_types: Number of requested device types
1494 * @req_dev_types: Requested device types array, must be an array
1495 * containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no
1496 * requested device types.
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001497 * @dev_id: Device ID to search for or %NULL to find all devices
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001498 * @search_delay: Extra delay in milliseconds between search iterations
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001499 * @seek_count: Number of ASP Service Strings in the seek_string array
1500 * @seek_string: ASP Service Strings to query for in Probe Requests
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001501 * @freq: Requested first scan frequency (in MHz) to modify type ==
1502 * P2P_FIND_START_WITH_FULL behavior. 0 = Use normal full scan.
1503 * If p2p_find is already in progress, this parameter is ignored and full
1504 * scan will be executed.
Hai Shaloma20dcd72022-02-04 13:43:00 -08001505 * @include_6ghz: Include 6 GHz channels in P2P find
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001506 * Returns: 0 on success, -1 on failure
1507 */
1508int p2p_find(struct p2p_data *p2p, unsigned int timeout,
1509 enum p2p_discovery_type type,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001510 unsigned int num_req_dev_types, const u8 *req_dev_types,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001511 const u8 *dev_id, unsigned int search_delay,
Hai Shaloma20dcd72022-02-04 13:43:00 -08001512 u8 seek_count, const char **seek_string, int freq,
1513 bool include_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001514
1515/**
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001516 * p2p_notify_scan_trigger_status - Indicate scan trigger status
1517 * @p2p: P2P module context from p2p_init()
1518 * @status: 0 on success, -1 on failure
1519 */
1520void p2p_notify_scan_trigger_status(struct p2p_data *p2p, int status);
1521
1522/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001523 * p2p_stop_find - Stop P2P Find (Device Discovery)
1524 * @p2p: P2P module context from p2p_init()
1525 */
1526void p2p_stop_find(struct p2p_data *p2p);
1527
1528/**
1529 * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq
1530 * @p2p: P2P module context from p2p_init()
1531 * @freq: Frequency in MHz for next operation
1532 *
1533 * This is like p2p_stop_find(), but Listen state is not stopped if we are
1534 * already on the same frequency.
1535 */
1536void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq);
1537
1538/**
1539 * p2p_listen - Start P2P Listen state for specified duration
1540 * @p2p: P2P module context from p2p_init()
1541 * @timeout: Listen state duration in milliseconds
1542 * Returns: 0 on success, -1 on failure
1543 *
1544 * This function can be used to request the P2P module to keep the device
1545 * discoverable on the listen channel for an extended set of time. At least in
1546 * its current form, this is mainly used for testing purposes and may not be of
1547 * much use for normal P2P operations.
1548 */
1549int p2p_listen(struct p2p_data *p2p, unsigned int timeout);
1550
1551/**
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001552 * p2p_stop_listen - Stop P2P Listen
1553 * @p2p: P2P module context from p2p_init()
1554 */
1555void p2p_stop_listen(struct p2p_data *p2p);
1556
1557/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001558 * p2p_connect - Start P2P group formation (GO negotiation)
1559 * @p2p: P2P module context from p2p_init()
1560 * @peer_addr: MAC address of the peer P2P client
1561 * @wps_method: WPS method to be used in provisioning
1562 * @go_intent: Local GO intent value (1..15)
1563 * @own_interface_addr: Intended interface address to use with the group
1564 * @force_freq: The only allowed channel frequency in MHz or 0
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001565 * @persistent_group: Whether to create a persistent group (0 = no, 1 =
1566 * persistent group without persistent reconnect, 2 = persistent group with
1567 * persistent reconnect)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001568 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
1569 * a new SSID
1570 * @force_ssid_len: Length of $force_ssid buffer
1571 * @pd_before_go_neg: Whether to send Provision Discovery prior to GO
1572 * Negotiation as an interoperability workaround when initiating group
1573 * formation
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001574 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1575 * force_freq == 0)
Sunil Ravic0f5d412024-09-11 22:12:49 +00001576 * @oob_pw_id: OOB password identifier
1577 * @p2p2: Device supports P2P2 features
1578 * @bootstrap: Bootstrapping method requested for P2P2 provision discovery
1579 * @password: P2P2 pairing password or %NULL for opportunistic method
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580 * Returns: 0 on success, -1 on failure
1581 */
1582int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
1583 enum p2p_wps_method wps_method,
1584 int go_intent, const u8 *own_interface_addr,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001585 unsigned int force_freq, int persistent_group,
1586 const u8 *force_ssid, size_t force_ssid_len,
Sunil Ravic0f5d412024-09-11 22:12:49 +00001587 int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id,
1588 bool p2p2, u16 bootstrap, const char *password);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589
1590/**
1591 * p2p_authorize - Authorize P2P group formation (GO negotiation)
1592 * @p2p: P2P module context from p2p_init()
1593 * @peer_addr: MAC address of the peer P2P client
1594 * @wps_method: WPS method to be used in provisioning
1595 * @go_intent: Local GO intent value (1..15)
1596 * @own_interface_addr: Intended interface address to use with the group
1597 * @force_freq: The only allowed channel frequency in MHz or 0
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001598 * @persistent_group: Whether to create a persistent group (0 = no, 1 =
1599 * persistent group without persistent reconnect, 2 = persistent group with
1600 * persistent reconnect)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001601 * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
1602 * a new SSID
1603 * @force_ssid_len: Length of $force_ssid buffer
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001604 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1605 * force_freq == 0)
Sunil Ravic0f5d412024-09-11 22:12:49 +00001606 * @oob_pw_id: OOB password identifier
1607 * @bootstrap: Bootstrapping method requested for P2P2 provision discovery
1608 * @password: P2P2 pairing password or %NULL for opportunistic method
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001609 * Returns: 0 on success, -1 on failure
1610 *
1611 * This is like p2p_connect(), but the actual group negotiation is not
1612 * initiated automatically, i.e., the other end is expected to do that.
1613 */
1614int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
1615 enum p2p_wps_method wps_method,
1616 int go_intent, const u8 *own_interface_addr,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001617 unsigned int force_freq, int persistent_group,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001618 const u8 *force_ssid, size_t force_ssid_len,
Sunil Ravic0f5d412024-09-11 22:12:49 +00001619 unsigned int pref_freq, u16 oob_pw_id, u16 bootstrap,
1620 const char *password);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621
1622/**
1623 * p2p_reject - Reject peer device (explicitly block connection attempts)
1624 * @p2p: P2P module context from p2p_init()
1625 * @peer_addr: MAC address of the peer P2P client
1626 * Returns: 0 on success, -1 on failure
1627 */
1628int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr);
1629
1630/**
1631 * p2p_prov_disc_req - Send Provision Discovery Request
1632 * @p2p: P2P module context from p2p_init()
1633 * @peer_addr: MAC address of the peer P2P client
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001634 * @p2ps_prov: Provisioning info for P2PS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635 * @config_methods: WPS Config Methods value (only one bit set)
1636 * @join: Whether this is used by a client joining an active group
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001637 * @force_freq: Forced TX frequency for the frame (mainly for the join case)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001638 * @user_initiated_pd: Flag to indicate if initiated by user or not
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639 * Returns: 0 on success, -1 on failure
1640 *
1641 * This function can be used to request a discovered P2P peer to display a PIN
1642 * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us
1643 * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame
1644 * is transmitted once immediately and if no response is received, the frame
1645 * will be sent again whenever the target device is discovered during device
1646 * dsicovery (start with a p2p_find() call). Response from the peer is
1647 * indicated with the p2p_config::prov_disc_resp() callback.
1648 */
1649int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001650 struct p2ps_provision *p2ps_prov, u16 config_methods,
1651 int join, int force_freq,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001652 int user_initiated_pd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653
1654/**
1655 * p2p_sd_request - Schedule a service discovery query
1656 * @p2p: P2P module context from p2p_init()
1657 * @dst: Destination peer or %NULL to apply for all peers
1658 * @tlvs: P2P Service Query TLV(s)
1659 * Returns: Reference to the query or %NULL on failure
1660 *
1661 * Response to the query is indicated with the p2p_config::sd_response()
1662 * callback.
1663 */
1664void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
1665 const struct wpabuf *tlvs);
1666
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001667#ifdef CONFIG_WIFI_DISPLAY
1668void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst,
1669 const struct wpabuf *tlvs);
1670#endif /* CONFIG_WIFI_DISPLAY */
1671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672/**
1673 * p2p_sd_cancel_request - Cancel a pending service discovery query
1674 * @p2p: P2P module context from p2p_init()
1675 * @req: Query reference from p2p_sd_request()
1676 * Returns: 0 if request for cancelled; -1 if not found
1677 */
1678int p2p_sd_cancel_request(struct p2p_data *p2p, void *req);
1679
1680/**
1681 * p2p_sd_response - Send response to a service discovery query
1682 * @p2p: P2P module context from p2p_init()
1683 * @freq: Frequency from p2p_config::sd_request() callback
1684 * @dst: Destination address from p2p_config::sd_request() callback
1685 * @dialog_token: Dialog token from p2p_config::sd_request() callback
1686 * @resp_tlvs: P2P Service Response TLV(s)
1687 *
1688 * This function is called as a response to the request indicated with
1689 * p2p_config::sd_request() callback.
1690 */
1691void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
1692 u8 dialog_token, const struct wpabuf *resp_tlvs);
1693
1694/**
1695 * p2p_sd_service_update - Indicate a change in local services
1696 * @p2p: P2P module context from p2p_init()
1697 *
1698 * This function needs to be called whenever there is a change in availability
1699 * of the local services. This will increment the Service Update Indicator
1700 * value which will be used in SD Request and Response frames.
1701 */
1702void p2p_sd_service_update(struct p2p_data *p2p);
1703
1704
1705enum p2p_invite_role {
1706 P2P_INVITE_ROLE_GO,
1707 P2P_INVITE_ROLE_ACTIVE_GO,
1708 P2P_INVITE_ROLE_CLIENT
1709};
1710
1711/**
1712 * p2p_invite - Invite a P2P Device into a group
1713 * @p2p: P2P module context from p2p_init()
1714 * @peer: Device Address of the peer P2P Device
1715 * @role: Local role in the group
1716 * @bssid: Group BSSID or %NULL if not known
1717 * @ssid: Group SSID
1718 * @ssid_len: Length of ssid in octets
1719 * @force_freq: The only allowed channel frequency in MHz or 0
1720 * @go_dev_addr: Forced GO Device Address or %NULL if none
1721 * @persistent_group: Whether this is to reinvoke a persistent group
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08001722 * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
1723 * force_freq == 0)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001724 * @dev_pw_id: Device Password ID from OOB Device Password (NFC) static handover
1725 * case or -1 if not used
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001726 * @p2p2: Operating in P2P2 mode
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727 * Returns: 0 on success, -1 on failure
1728 */
1729int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
1730 const u8 *bssid, const u8 *ssid, size_t ssid_len,
1731 unsigned int force_freq, const u8 *go_dev_addr,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001732 int persistent_group, unsigned int pref_freq, int dev_pw_id,
1733 bool p2p2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734
1735/**
1736 * p2p_presence_req - Request GO presence
1737 * @p2p: P2P module context from p2p_init()
1738 * @go_interface_addr: GO P2P Interface Address
1739 * @own_interface_addr: Own P2P Interface Address for this group
1740 * @freq: Group operating frequence (in MHz)
1741 * @duration1: Preferred presence duration in microseconds
1742 * @interval1: Preferred presence interval in microseconds
1743 * @duration2: Acceptable presence duration in microseconds
1744 * @interval2: Acceptable presence interval in microseconds
1745 * Returns: 0 on success, -1 on failure
1746 *
1747 * If both duration and interval values are zero, the parameter pair is not
1748 * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0).
1749 */
1750int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
1751 const u8 *own_interface_addr, unsigned int freq,
1752 u32 duration1, u32 interval1, u32 duration2,
1753 u32 interval2);
1754
1755/**
1756 * p2p_ext_listen - Set Extended Listen Timing
1757 * @p2p: P2P module context from p2p_init()
1758 * @freq: Group operating frequence (in MHz)
1759 * @period: Availability period in milliseconds (1-65535; 0 to disable)
1760 * @interval: Availability interval in milliseconds (1-65535; 0 to disable)
1761 * Returns: 0 on success, -1 on failure
1762 *
1763 * This function can be used to enable or disable (period = interval = 0)
1764 * Extended Listen Timing. When enabled, the P2P Device will become
1765 * discoverable (go into Listen State) every @interval milliseconds for at
1766 * least @period milliseconds.
1767 */
1768int p2p_ext_listen(struct p2p_data *p2p, unsigned int period,
1769 unsigned int interval);
1770
1771/* Event notifications from upper layer management operations */
1772
1773/**
1774 * p2p_wps_success_cb - Report successfully completed WPS provisioning
1775 * @p2p: P2P module context from p2p_init()
1776 * @mac_addr: Peer address
1777 *
1778 * This function is used to report successfully completed WPS provisioning
1779 * during group formation in both GO/Registrar and client/Enrollee roles.
1780 */
1781void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr);
1782
1783/**
1784 * p2p_group_formation_failed - Report failed WPS provisioning
1785 * @p2p: P2P module context from p2p_init()
1786 *
1787 * This function is used to report failed group formation. This can happen
1788 * either due to failed WPS provisioning or due to 15 second timeout during
1789 * the provisioning phase.
1790 */
1791void p2p_group_formation_failed(struct p2p_data *p2p);
1792
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001793/**
1794 * p2p_get_provisioning_info - Get any stored provisioning info
1795 * @p2p: P2P module context from p2p_init()
1796 * @addr: Peer P2P Device Address
1797 * Returns: WPS provisioning information (WPS config method) or 0 if no
1798 * information is available
1799 *
1800 * This function is used to retrieve stored WPS provisioning info for the given
1801 * peer.
1802 */
1803u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr);
1804
1805/**
1806 * p2p_clear_provisioning_info - Clear any stored provisioning info
1807 * @p2p: P2P module context from p2p_init()
Dmitry Shmidt04949592012-07-19 12:16:46 -07001808 * @iface_addr: Peer P2P Device Address
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001809 *
1810 * This function is used to clear stored WPS provisioning info for the given
1811 * peer.
1812 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001813void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001814
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001815
1816/* Event notifications from lower layer driver operations */
1817
1818/**
Dmitry Shmidt04949592012-07-19 12:16:46 -07001819 * enum p2p_probe_req_status
1820 *
1821 * @P2P_PREQ_MALFORMED: frame was not well-formed
1822 * @P2P_PREQ_NOT_LISTEN: device isn't in listen state, frame ignored
1823 * @P2P_PREQ_NOT_P2P: frame was not a P2P probe request
1824 * @P2P_PREQ_P2P_NOT_PROCESSED: frame was P2P but wasn't processed
1825 * @P2P_PREQ_P2P_PROCESSED: frame has been processed by P2P
1826 */
1827enum p2p_probe_req_status {
1828 P2P_PREQ_MALFORMED,
1829 P2P_PREQ_NOT_LISTEN,
1830 P2P_PREQ_NOT_P2P,
1831 P2P_PREQ_NOT_PROCESSED,
1832 P2P_PREQ_PROCESSED
1833};
1834
1835/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 * p2p_probe_req_rx - Report reception of a Probe Request frame
1837 * @p2p: P2P module context from p2p_init()
1838 * @addr: Source MAC address
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 * @dst: Destination MAC address if available or %NULL
1840 * @bssid: BSSID if available or %NULL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 * @ie: Information elements from the Probe Request frame body
1842 * @ie_len: Length of ie buffer in octets
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001843 * @rx_freq: Probe Request frame RX frequency
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001844 * @p2p_lo_started: Whether P2P Listen Offload is started
Dmitry Shmidt04949592012-07-19 12:16:46 -07001845 * Returns: value indicating the type and status of the probe request
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001846 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001847enum p2p_probe_req_status
1848p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001849 const u8 *bssid, const u8 *ie, size_t ie_len,
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001850 unsigned int rx_freq, int p2p_lo_started);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851
1852/**
1853 * p2p_rx_action - Report received Action frame
1854 * @p2p: P2P module context from p2p_init()
1855 * @da: Destination address of the received Action frame
1856 * @sa: Source address of the received Action frame
1857 * @bssid: Address 3 of the received Action frame
1858 * @category: Category of the received Action frame
1859 * @data: Action frame body after the Category field
1860 * @len: Length of the data buffer in octets
1861 * @freq: Frequency (in MHz) on which the frame was received
1862 */
1863void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
1864 const u8 *bssid, u8 category,
1865 const u8 *data, size_t len, int freq);
1866
1867/**
1868 * p2p_scan_res_handler - Indicate a P2P scan results
1869 * @p2p: P2P module context from p2p_init()
1870 * @bssid: BSSID of the scan result
1871 * @freq: Frequency of the channel on which the device was found in MHz
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001872 * @rx_time: Time when the result was received
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873 * @level: Signal level (signal strength of the received Beacon/Probe Response
1874 * frame)
1875 * @ies: Pointer to IEs from the scan result
1876 * @ies_len: Length of the ies buffer
1877 * Returns: 0 to continue or 1 to stop scan result indication
1878 *
1879 * This function is called to indicate a scan result entry with P2P IE from a
1880 * scan requested with struct p2p_config::p2p_scan(). This can be called during
1881 * the actual scan process (i.e., whenever a new device is found) or as a
1882 * sequence of calls after the full scan has been completed. The former option
1883 * can result in optimized operations, but may not be supported by all
1884 * driver/firmware designs. The ies buffer need to include at least the P2P IE,
1885 * but it is recommended to include all IEs received from the device. The
1886 * caller does not need to check that the IEs contain a P2P IE before calling
1887 * this function since frames will be filtered internally if needed.
1888 *
1889 * This function will return 1 if it wants to stop scan result iteration (and
1890 * scan in general if it is still in progress). This is used to allow faster
1891 * start of a pending operation, e.g., to start a pending GO negotiation.
1892 */
1893int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001894 struct os_reltime *rx_time, int level, const u8 *ies,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001895 size_t ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896
1897/**
1898 * p2p_scan_res_handled - Indicate end of scan results
1899 * @p2p: P2P module context from p2p_init()
Hai Shalom60840252021-02-19 19:02:11 -08001900 * @delay: Search delay for next scan in ms
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901 *
1902 * This function is called to indicate that all P2P scan results from a scan
1903 * have been reported with zero or more calls to p2p_scan_res_handler(). This
1904 * function must be called as a response to successful
1905 * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler()
1906 * calls stopped iteration.
1907 */
Hai Shalom60840252021-02-19 19:02:11 -08001908void p2p_scan_res_handled(struct p2p_data *p2p, unsigned int delay);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001909
1910enum p2p_send_action_result {
1911 P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */,
1912 P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */,
1913 P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */
1914};
1915
1916/**
1917 * p2p_send_action_cb - Notify TX status of an Action frame
1918 * @p2p: P2P module context from p2p_init()
1919 * @freq: Channel frequency in MHz
1920 * @dst: Destination MAC address (Address 1)
1921 * @src: Source MAC address (Address 2)
1922 * @bssid: BSSID (Address 3)
1923 * @result: Result of the transmission attempt
1924 *
1925 * This function is used to indicate the result of an Action frame transmission
1926 * that was requested with struct p2p_config::send_action() callback.
1927 */
1928void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
1929 const u8 *src, const u8 *bssid,
1930 enum p2p_send_action_result result);
1931
1932/**
1933 * p2p_listen_cb - Indicate the start of a requested Listen state
1934 * @p2p: P2P module context from p2p_init()
1935 * @freq: Listen channel frequency in MHz
1936 * @duration: Duration for the Listen state in milliseconds
1937 *
1938 * This function is used to indicate that a Listen state requested with
1939 * struct p2p_config::start_listen() callback has started.
1940 */
1941void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
1942 unsigned int duration);
1943
1944/**
1945 * p2p_listen_end - Indicate the end of a requested Listen state
1946 * @p2p: P2P module context from p2p_init()
1947 * @freq: Listen channel frequency in MHz
1948 * Returns: 0 if no operations were started, 1 if an operation was started
1949 *
1950 * This function is used to indicate that a Listen state requested with
1951 * struct p2p_config::start_listen() callback has ended.
1952 */
1953int p2p_listen_end(struct p2p_data *p2p, unsigned int freq);
1954
1955void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
1956 const u8 *ie, size_t ie_len);
1957
1958void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
1959 const u8 *ie, size_t ie_len);
1960
1961
1962/* Per-group P2P state for GO */
1963
1964struct p2p_group;
1965
1966/**
1967 * struct p2p_group_config - P2P group configuration
1968 *
1969 * This configuration is provided to the P2P module during initialization of
1970 * the per-group information with p2p_group_init().
1971 */
1972struct p2p_group_config {
1973 /**
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001974 * p2p2 - Whether the group was formed using P2P2
1975 */
1976 bool p2p2;
1977
1978 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 * persistent_group - Whether the group is persistent
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001980 * 0 = not a persistent group
1981 * 1 = persistent group without persistent reconnect
1982 * 2 = persistent group with persistent reconnect
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001983 */
1984 int persistent_group;
1985
1986 /**
1987 * interface_addr - P2P Interface Address of the group
1988 */
1989 u8 interface_addr[ETH_ALEN];
1990
1991 /**
1992 * max_clients - Maximum number of clients in the group
1993 */
1994 unsigned int max_clients;
1995
1996 /**
Dmitry Shmidt04949592012-07-19 12:16:46 -07001997 * ssid - Group SSID
1998 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001999 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt04949592012-07-19 12:16:46 -07002000
2001 /**
2002 * ssid_len - Length of SSID
2003 */
2004 size_t ssid_len;
2005
2006 /**
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002007 * freq - Operating channel of the group
2008 */
2009 int freq;
2010
2011 /**
Dmitry Shmidte4663042016-04-04 10:07:49 -07002012 * ip_addr_alloc - Whether IP address allocation within 4-way handshake
2013 * is supported
2014 */
2015 int ip_addr_alloc;
2016
2017 /**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018 * cb_ctx - Context to use with callback functions
2019 */
2020 void *cb_ctx;
2021
2022 /**
2023 * ie_update - Notification of IE update
2024 * @ctx: Callback context from cb_ctx
2025 * @beacon_ies: P2P IE for Beacon frames or %NULL if no change
2026 * @proberesp_ies: P2P Ie for Probe Response frames
2027 *
2028 * P2P module uses this callback function to notify whenever the P2P IE
2029 * in Beacon or Probe Response frames should be updated based on group
2030 * events.
2031 *
2032 * The callee is responsible for freeing the returned buffer(s) with
2033 * wpabuf_free().
2034 */
2035 void (*ie_update)(void *ctx, struct wpabuf *beacon_ies,
2036 struct wpabuf *proberesp_ies);
2037
2038 /**
2039 * idle_update - Notification of changes in group idle state
2040 * @ctx: Callback context from cb_ctx
2041 * @idle: Whether the group is idle (no associated stations)
2042 */
2043 void (*idle_update)(void *ctx, int idle);
2044};
2045
2046/**
2047 * p2p_group_init - Initialize P2P group
2048 * @p2p: P2P module context from p2p_init()
2049 * @config: P2P group configuration (will be freed by p2p_group_deinit())
2050 * Returns: Pointer to private data or %NULL on failure
2051 *
2052 * This function is used to initialize per-group P2P module context. Currently,
2053 * this is only used to manage GO functionality and P2P clients do not need to
2054 * create an instance of this per-group information.
2055 */
2056struct p2p_group * p2p_group_init(struct p2p_data *p2p,
2057 struct p2p_group_config *config);
2058
2059/**
2060 * p2p_group_deinit - Deinitialize P2P group
2061 * @group: P2P group context from p2p_group_init()
2062 */
2063void p2p_group_deinit(struct p2p_group *group);
2064
2065/**
2066 * p2p_group_notif_assoc - Notification of P2P client association with GO
2067 * @group: P2P group context from p2p_group_init()
2068 * @addr: Interface address of the P2P client
2069 * @ie: IEs from the (Re)association Request frame
2070 * @len: Length of the ie buffer in octets
2071 * Returns: 0 on success, -1 on failure
2072 */
2073int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr,
2074 const u8 *ie, size_t len);
2075
2076/**
2077 * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response
2078 * @group: P2P group context from p2p_group_init()
2079 * @status: Status value (P2P_SC_SUCCESS if association succeeded)
2080 * Returns: P2P IE for (Re)association Response or %NULL on failure
2081 *
2082 * The caller is responsible for freeing the returned buffer with
2083 * wpabuf_free().
2084 */
2085struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status);
2086
2087/**
2088 * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO
2089 * @group: P2P group context from p2p_group_init()
2090 * @addr: Interface address of the P2P client
2091 */
2092void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr);
2093
2094/**
2095 * p2p_group_notif_formation_done - Notification of completed group formation
2096 * @group: P2P group context from p2p_group_init()
2097 */
2098void p2p_group_notif_formation_done(struct p2p_group *group);
2099
2100/**
2101 * p2p_group_notif_noa - Notification of NoA change
2102 * @group: P2P group context from p2p_group_init()
2103 * @noa: Notice of Absence attribute payload, %NULL if none
2104 * @noa_len: Length of noa buffer in octets
2105 * Returns: 0 on success, -1 on failure
2106 *
2107 * Notify the P2P group management about a new NoA contents. This will be
2108 * inserted into the P2P IEs in Beacon and Probe Response frames with rest of
2109 * the group information.
2110 */
2111int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa,
2112 size_t noa_len);
2113
2114/**
2115 * p2p_group_match_dev_type - Match device types in group with requested type
2116 * @group: P2P group context from p2p_group_init()
2117 * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs)
2118 * Returns: 1 on match, 0 on mismatch
2119 *
2120 * This function can be used to match the Requested Device Type attribute in
2121 * WPS IE with the device types of a group member for deciding whether a GO
2122 * should reply to a Probe Request frame. Match will be reported if the WPS IE
2123 * is not requested any specific device type.
2124 */
2125int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps);
2126
2127/**
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002128 * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id
2129 */
2130int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p);
2131
2132/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002133 * p2p_group_go_discover - Send GO Discoverability Request to a group client
2134 * @group: P2P group context from p2p_group_init()
2135 * Returns: 0 on success (frame scheduled); -1 if client was not found
2136 */
2137int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
2138 const u8 *searching_dev, int rx_freq);
2139
2140
2141/* Generic helper functions */
2142
2143/**
2144 * p2p_ie_text - Build text format description of P2P IE
2145 * @p2p_ie: P2P IE
2146 * @buf: Buffer for returning text
2147 * @end: Pointer to the end of the buf area
2148 * Returns: Number of octets written to the buffer or -1 on failure
2149 *
2150 * This function can be used to parse P2P IE contents into text format
2151 * field=value lines.
2152 */
2153int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end);
2154
2155/**
2156 * p2p_scan_result_text - Build text format description of P2P IE
2157 * @ies: Information elements from scan results
2158 * @ies_len: ies buffer length in octets
2159 * @buf: Buffer for returning text
2160 * @end: Pointer to the end of the buf area
2161 * Returns: Number of octets written to the buffer or -1 on failure
2162 *
2163 * This function can be used to parse P2P IE contents into text format
2164 * field=value lines.
2165 */
2166int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end);
2167
2168/**
Dmitry Shmidt04949592012-07-19 12:16:46 -07002169 * p2p_parse_dev_addr_in_p2p_ie - Parse P2P Device Address from a concatenated
2170 * P2P IE
2171 * @p2p_ie: P2P IE
2172 * @dev_addr: Buffer for returning P2P Device Address
2173 * Returns: 0 on success or -1 if P2P Device Address could not be parsed
2174 */
2175int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr);
2176
2177/**
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002178 * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s)
2179 * @ies: Information elements from scan results
2180 * @ies_len: ies buffer length in octets
2181 * @dev_addr: Buffer for returning P2P Device Address
2182 * Returns: 0 on success or -1 if P2P Device Address could not be parsed
2183 */
2184int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr);
2185
2186/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002187 * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame
2188 * @p2p: P2P module context from p2p_init()
2189 * @bssid: BSSID
2190 * @buf: Buffer for writing the P2P IE
2191 * @len: Maximum buf length in octets
2192 * @p2p_group: Whether this is for association with a P2P GO
2193 * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none
2194 * Returns: Number of octets written into buf or -1 on failure
2195 */
2196int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf,
2197 size_t len, int p2p_group, struct wpabuf *p2p_ie);
2198
2199/**
2200 * p2p_scan_ie - Build P2P IE for Probe Request
2201 * @p2p: P2P module context from p2p_init()
2202 * @ies: Buffer for writing P2P IE
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002203 * @dev_id: Device ID to search for or %NULL for any
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002204 * @bands: Frequency bands used in the scan (enum wpa_radio_work_band bitmap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002206void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id,
2207 unsigned int bands);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002208
2209/**
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002210 * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie
2211 * @p2p: P2P module context from p2p_init()
2212 * Returns: Number of octets that p2p_scan_ie() may add to the buffer
2213 */
2214size_t p2p_scan_ie_buf_len(struct p2p_data *p2p);
2215
2216/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 * p2p_go_params - Generate random P2P group parameters
2218 * @p2p: P2P module context from p2p_init()
2219 * @params: Buffer for parameters
2220 * Returns: 0 on success, -1 on failure
2221 */
2222int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params);
2223
2224/**
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002225 * p2p_set_go_role - Set the current role of P2P device
2226 * @p2p: P2P module context from p2p_init()
2227 * @val: 1 if P2P GO, 0 to reset the role variable
2228 *
2229 * This role is configured as P2P GO when authorizing a P2P Client to join the
2230 * group. Once PASN authentication with GO negotiation with predefined GO intent
2231 * values (15 for P2P GO) is completed, the role helps to configure PMK derived
2232 * during the PASN authentication.
2233 */
2234void p2p_set_go_role(struct p2p_data *p2p, bool val);
2235
2236/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 * p2p_get_group_capab - Get Group Capability from P2P IE data
2238 * @p2p_ie: P2P IE(s) contents
2239 * Returns: Group Capability
2240 */
2241u8 p2p_get_group_capab(const struct wpabuf *p2p_ie);
2242
2243/**
2244 * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection
2245 * @p2p_ie: P2P IE(s) contents
2246 * Returns: 0 if cross connection is allow, 1 if not
2247 */
2248int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie);
2249
2250/**
2251 * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data
2252 * @p2p_ie: P2P IE(s) contents
2253 * Returns: Pointer to P2P Device Address or %NULL if not included
2254 */
2255const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie);
2256
2257/**
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002258 * p2p_get_peer_info - Get P2P peer information
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002259 * @p2p: P2P module context from p2p_init()
2260 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
2261 * @next: Whether to select the peer entry following the one indicated by addr
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002262 * Returns: Pointer to peer info or %NULL if not found
2263 */
2264const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p,
2265 const u8 *addr, int next);
2266
2267/**
2268 * p2p_get_peer_info_txt - Get internal P2P peer information in text format
2269 * @info: Pointer to P2P peer info from p2p_get_peer_info()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 * @buf: Buffer for returning text
2271 * @buflen: Maximum buffer length
2272 * Returns: Number of octets written to the buffer or -1 on failure
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002273 *
2274 * Note: This information is internal to the P2P module and subject to change.
2275 * As such, this should not really be used by external programs for purposes
2276 * other than debugging.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002278int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
2279 char *buf, size_t buflen);
2280
2281/**
2282 * p2p_peer_known - Check whether P2P peer is known
2283 * @p2p: P2P module context from p2p_init()
2284 * @addr: P2P Device Address of the peer
2285 * Returns: 1 if the specified device is in the P2P peer table or 0 if not
2286 */
2287int p2p_peer_known(struct p2p_data *p2p, const u8 *addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002288
2289/**
2290 * p2p_set_client_discoverability - Set client discoverability capability
2291 * @p2p: P2P module context from p2p_init()
2292 * @enabled: Whether client discoverability will be enabled
2293 *
2294 * This function can be used to disable (and re-enable) client discoverability.
2295 * This capability is enabled by default and should not be disabled in normal
2296 * use cases, i.e., this is mainly for testing purposes.
2297 */
2298void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled);
2299
2300/**
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002301 * p2p_set_managed_oper - Set managed P2P Device operations capability
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002302 * @p2p: P2P module context from p2p_init()
2303 * @enabled: Whether managed P2P Device operations will be enabled
2304 */
2305void p2p_set_managed_oper(struct p2p_data *p2p, int enabled);
2306
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002307/**
2308 * p2p_config_get_random_social - Return a random social channel
2309 * @p2p: P2P config
2310 * @op_class: Selected operating class
2311 * @op_channel: Selected social channel
Hai Shalom74f70d42019-02-11 14:42:39 -08002312 * @avoid_list: Channel ranges to try to avoid or %NULL
2313 * @disallow_list: Channel ranges to discard or %NULL
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002314 * Returns: 0 on success, -1 on failure
2315 *
2316 * This function is used before p2p_init is called. A random social channel
2317 * from supports bands 2.4 GHz (channels 1,6,11) and 60 GHz (channel 2) is
2318 * returned on success.
2319 */
2320int p2p_config_get_random_social(struct p2p_config *p2p, u8 *op_class,
Hai Shalom74f70d42019-02-11 14:42:39 -08002321 u8 *op_channel,
2322 struct wpa_freq_range_list *avoid_list,
2323 struct wpa_freq_range_list *disallow_list);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002324
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07002325int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel,
2326 u8 forced);
2327
2328u8 p2p_get_listen_channel(struct p2p_data *p2p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329
2330int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len);
2331
2332int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
2333 u8 *iface_addr);
2334int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
2335 u8 *dev_addr);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002336int p2p_get_dev_identity_key(struct p2p_data *p2p, const u8 *dev_addr,
2337 const u8 **dik_data, size_t *dik_len, u8 *cipher);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002338
2339void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr);
2340
2341/**
2342 * p2p_set_cross_connect - Set cross connection capability
2343 * @p2p: P2P module context from p2p_init()
2344 * @enabled: Whether cross connection will be enabled
2345 */
2346void p2p_set_cross_connect(struct p2p_data *p2p, int enabled);
2347
2348int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr);
2349
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350/**
2351 * p2p_set_intra_bss_dist - Set intra BSS distribution
2352 * @p2p: P2P module context from p2p_init()
2353 * @enabled: Whether intra BSS distribution will be enabled
2354 */
2355void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled);
2356
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08002357int p2p_channels_includes_freq(const struct p2p_channels *channels,
2358 unsigned int freq);
2359
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002360int p2p_channels_to_freqs(const struct p2p_channels *channels,
2361 int *freq_list, unsigned int max_len);
2362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002363/**
2364 * p2p_supported_freq - Check whether channel is supported for P2P
2365 * @p2p: P2P module context from p2p_init()
2366 * @freq: Channel frequency in MHz
2367 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
2368 */
2369int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq);
2370
Dmitry Shmidt44c95782013-05-17 09:51:35 -07002371/**
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002372 * p2p_supported_freq_go - Check whether channel is supported for P2P GO operation
2373 * @p2p: P2P module context from p2p_init()
2374 * @freq: Channel frequency in MHz
2375 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
2376 */
2377int p2p_supported_freq_go(struct p2p_data *p2p, unsigned int freq);
2378
2379/**
2380 * p2p_supported_freq_cli - Check whether channel is supported for P2P client operation
2381 * @p2p: P2P module context from p2p_init()
2382 * @freq: Channel frequency in MHz
2383 * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
2384 */
2385int p2p_supported_freq_cli(struct p2p_data *p2p, unsigned int freq);
2386
2387/**
Dmitry Shmidt44c95782013-05-17 09:51:35 -07002388 * p2p_get_pref_freq - Get channel from preferred channel list
2389 * @p2p: P2P module context from p2p_init()
2390 * @channels: List of channels
2391 * Returns: Preferred channel
2392 */
2393unsigned int p2p_get_pref_freq(struct p2p_data *p2p,
2394 const struct p2p_channels *channels);
2395
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002396void p2p_update_channel_list(struct p2p_data *p2p,
2397 const struct p2p_channels *chan,
2398 const struct p2p_channels *cli_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002399
Hai Shalom60840252021-02-19 19:02:11 -08002400bool is_p2p_6ghz_disabled(struct p2p_data *p2p);
Shuibing Daie2fad412023-05-05 14:08:11 -07002401bool is_p2p_dfs_chan_enabled(struct p2p_data *p2p);
Hai Shalom60840252021-02-19 19:02:11 -08002402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403/**
2404 * p2p_set_best_channels - Update best channel information
2405 * @p2p: P2P module context from p2p_init()
2406 * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band
2407 * @freq_5: Frequency (MHz) of best channel in 5 GHz band
2408 * @freq_overall: Frequency (MHz) of best channel overall
2409 */
2410void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
2411 int freq_overall);
2412
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002413/**
2414 * p2p_set_own_freq_preference - Set own preference for channel
2415 * @p2p: P2P module context from p2p_init()
2416 * @freq: Frequency (MHz) of the preferred channel or 0 if no preference
2417 *
2418 * This function can be used to set a preference on the operating channel based
2419 * on frequencies used on the other virtual interfaces that share the same
2420 * radio. If non-zero, this is used to try to avoid multi-channel concurrency.
2421 */
2422void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq);
2423
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002424const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p);
2425
2426/**
2427 * p2p_get_group_num_members - Get number of members in group
2428 * @group: P2P group context from p2p_group_init()
2429 * Returns: Number of members in the group
2430 */
2431unsigned int p2p_get_group_num_members(struct p2p_group *group);
2432
2433/**
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002434 * p2p_client_limit_reached - Check if client limit is reached
2435 * @group: P2P group context from p2p_group_init()
2436 * Returns: 1 if no of clients limit reached
2437 */
2438int p2p_client_limit_reached(struct p2p_group *group);
2439
2440/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002441 * p2p_iterate_group_members - Iterate group members
2442 * @group: P2P group context from p2p_group_init()
2443 * @next: iteration pointer, must be a pointer to a void * that is set to %NULL
2444 * on the first call and not modified later
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002445 * Returns: A P2P Device Address for each call and %NULL for no more members
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002446 */
2447const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next);
2448
2449/**
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002450 * p2p_group_get_client_interface_addr - Get P2P Interface Address of a client in a group
2451 * @group: P2P group context from p2p_group_init()
2452 * @dev_addr: P2P Device Address of the client
2453 * Returns: P2P Interface Address of the client if found or %NULL if no match
2454 * found
2455 */
2456const u8 * p2p_group_get_client_interface_addr(struct p2p_group *group,
2457 const u8 *dev_addr);
2458
2459/**
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002460 * p2p_group_get_dev_addr - Get a P2P Device Address of a client in a group
2461 * @group: P2P group context from p2p_group_init()
2462 * @addr: P2P Interface Address of the client
2463 * Returns: P2P Device Address of the client if found or %NULL if no match
2464 * found
2465 */
2466const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr);
2467
2468/**
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002469 * p2p_group_is_client_connected - Check whether a specific client is connected
2470 * @group: P2P group context from p2p_group_init()
2471 * @addr: P2P Device Address of the client
2472 * Returns: 1 if client is connected or 0 if not
2473 */
2474int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr);
2475
2476/**
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002477 * p2p_group_get_config - Get the group configuration
2478 * @group: P2P group context from p2p_group_init()
2479 * Returns: The group configuration pointer
2480 */
2481const struct p2p_group_config * p2p_group_get_config(struct p2p_group *group);
2482
2483/**
2484 * p2p_loop_on_all_groups - Run the given callback on all groups
2485 * @p2p: P2P module context from p2p_init()
2486 * @group_callback: The callback function pointer
2487 * @user_data: Some user data pointer which can be %NULL
2488 *
2489 * The group_callback function can stop the iteration by returning 0.
2490 */
2491void p2p_loop_on_all_groups(struct p2p_data *p2p,
2492 int (*group_callback)(struct p2p_group *group,
2493 void *user_data),
2494 void *user_data);
2495
2496/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002497 * p2p_get_peer_found - Get P2P peer info structure of a found peer
2498 * @p2p: P2P module context from p2p_init()
2499 * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
2500 * @next: Whether to select the peer entry following the one indicated by addr
2501 * Returns: The first P2P peer info available or %NULL if no such peer exists
2502 */
2503const struct p2p_peer_info *
2504p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next);
2505
2506/**
2507 * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions
2508 * @p2p: P2P module context from p2p_init()
2509 */
2510void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p);
2511
2512/**
2513 * p2p_add_wps_vendor_extension - Add a WPS vendor extension
2514 * @p2p: P2P module context from p2p_init()
2515 * @vendor_ext: The vendor extensions to add
2516 * Returns: 0 on success, -1 on failure
2517 *
2518 * The wpabuf structures in the array are owned by the P2P
2519 * module after this call.
2520 */
2521int p2p_add_wps_vendor_extension(struct p2p_data *p2p,
2522 const struct wpabuf *vendor_ext);
2523
Jouni Malinen75ecf522011-06-27 15:19:46 -07002524/**
2525 * p2p_set_oper_channel - Set the P2P operating channel
2526 * @p2p: P2P module context from p2p_init()
2527 * @op_reg_class: Operating regulatory class to set
2528 * @op_channel: operating channel to set
2529 * @cfg_op_channel : Whether op_channel is hardcoded in configuration
2530 * Returns: 0 on success, -1 on failure
2531 */
2532int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel,
2533 int cfg_op_channel);
2534
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002535/**
Dmitry Shmidt04949592012-07-19 12:16:46 -07002536 * p2p_set_pref_chan - Set P2P preferred channel list
2537 * @p2p: P2P module context from p2p_init()
2538 * @num_pref_chan: Number of entries in pref_chan list
2539 * @pref_chan: Preferred channels or %NULL to remove preferences
2540 * Returns: 0 on success, -1 on failure
2541 */
2542int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan,
2543 const struct p2p_channel *pref_chan);
2544
2545/**
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002546 * p2p_set_no_go_freq - Set no GO channel ranges
2547 * @p2p: P2P module context from p2p_init()
2548 * @list: Channel ranges or %NULL to remove restriction
2549 * Returns: 0 on success, -1 on failure
2550 */
2551int p2p_set_no_go_freq(struct p2p_data *p2p,
2552 const struct wpa_freq_range_list *list);
2553
2554/**
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002555 * p2p_in_progress - Check whether a P2P operation is progress
2556 * @p2p: P2P module context from p2p_init()
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002557 * Returns: 0 if P2P module is idle, 1 if an operation is in progress but not
2558 * in search state, or 2 if search state operation is in progress
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002559 */
2560int p2p_in_progress(struct p2p_data *p2p);
2561
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002562const char * p2p_wps_method_text(enum p2p_wps_method method);
2563
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002564/**
2565 * p2p_set_config_timeout - Set local config timeouts
2566 * @p2p: P2P module context from p2p_init()
2567 * @go_timeout: Time in 10 ms units it takes to start the GO mode
2568 * @client_timeout: Time in 10 ms units it takes to start the client mode
2569 */
2570void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout,
2571 u8 client_timeout);
2572
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002573int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie);
2574int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie);
2575int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie);
2576int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie);
2577int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie);
2578int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie);
2579int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie);
2580int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie);
2581int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002582int p2p_set_wfd_r2_dev_info(struct p2p_data *p2p, const struct wpabuf *elem);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002583int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem);
2584int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p,
2585 const struct wpabuf *elem);
2586struct wpabuf * wifi_display_encaps(struct wpabuf *subelems);
2587
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002588/**
2589 * p2p_set_disc_int - Set min/max discoverable interval for p2p_find
2590 * @p2p: P2P module context from p2p_init()
2591 * @min_disc_int: minDiscoverableInterval (in units of 100 TU); default 1
2592 * @max_disc_int: maxDiscoverableInterval (in units of 100 TU); default 3
2593 * @max_disc_tu: Maximum number of TUs (1.024 ms) for discoverable interval; or
2594 * -1 not to limit
2595 * Returns: 0 on success, or -1 on failure
2596 *
2597 * This function can be used to configure minDiscoverableInterval and
2598 * maxDiscoverableInterval parameters for the Listen state during device
2599 * discovery (p2p_find). A random number of 100 TU units is picked for each
2600 * Listen state iteration from [min_disc_int,max_disc_int] range.
2601 *
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002602 * max_disc_tu can be used to further limit the discoverable duration. However,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002603 * it should be noted that use of this parameter is not recommended since it
2604 * would not be compliant with the P2P specification.
2605 */
2606int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
2607 int max_disc_tu);
2608
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002609/**
2610 * p2p_get_state_txt - Get current P2P state for debug purposes
2611 * @p2p: P2P module context from p2p_init()
2612 * Returns: Name of the current P2P module state
2613 *
2614 * It should be noted that the P2P module state names are internal information
2615 * and subject to change at any point, i.e., this information should be used
2616 * mainly for debugging purposes.
2617 */
2618const char * p2p_get_state_txt(struct p2p_data *p2p);
2619
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002620struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p,
2621 int client_freq,
2622 const u8 *go_dev_addr,
2623 const u8 *ssid, size_t ssid_len);
2624struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p,
2625 int client_freq,
2626 const u8 *go_dev_addr,
2627 const u8 *ssid, size_t ssid_len);
2628
Sunil8cd6f4d2022-06-28 18:40:46 +00002629bool p2p_pref_freq_allowed(const struct weighted_pcl *freq_list, bool go);
2630
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002631struct p2p_nfc_params {
2632 int sel;
2633 const u8 *wsc_attr;
2634 size_t wsc_len;
2635 const u8 *p2p_attr;
2636 size_t p2p_len;
2637
2638 enum {
2639 NO_ACTION, JOIN_GROUP, AUTH_JOIN, INIT_GO_NEG, RESP_GO_NEG,
2640 BOTH_GO, PEER_CLIENT
2641 } next_step;
2642 struct p2p_peer_info *peer;
2643 u8 oob_dev_pw[WPS_OOB_PUBKEY_HASH_LEN + 2 +
2644 WPS_OOB_DEVICE_PASSWORD_LEN];
2645 size_t oob_dev_pw_len;
2646 int go_freq;
2647 u8 go_dev_addr[ETH_ALEN];
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002648 u8 go_ssid[SSID_MAX_LEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002649 size_t go_ssid_len;
2650};
2651
2652int p2p_process_nfc_connection_handover(struct p2p_data *p2p,
2653 struct p2p_nfc_params *params);
2654
2655void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id,
2656 int go_intent,
2657 const u8 *own_interface_addr);
2658
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07002659int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len);
2660
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002661void p2p_loop_on_known_peers(struct p2p_data *p2p,
2662 void (*peer_callback)(struct p2p_peer_info *peer,
2663 void *user_data),
2664 void *user_data);
2665
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07002666void p2p_set_vendor_elems(struct p2p_data *p2p, struct wpabuf **vendor_elem);
2667
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002668void p2p_set_intended_addr(struct p2p_data *p2p, const u8 *intended_addr);
2669
2670struct p2ps_advertisement *
2671p2p_service_p2ps_id(struct p2p_data *p2p, u32 adv_id);
2672int p2p_service_add_asp(struct p2p_data *p2p, int auto_accept, u32 adv_id,
2673 const char *adv_str, u8 svc_state,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002674 u16 config_methods, const char *svc_info,
2675 const u8 *cpt_priority);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002676int p2p_service_del_asp(struct p2p_data *p2p, u32 adv_id);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002677void p2p_service_flush_asp(struct p2p_data *p2p);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002678struct p2ps_advertisement * p2p_get_p2ps_adv_list(struct p2p_data *p2p);
2679
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002680/**
2681 * p2p_expire_peers - Periodic cleanup function to expire peers
2682 * @p2p: P2P module context from p2p_init()
2683 *
2684 * This is a cleanup function that the entity calling p2p_init() is
2685 * expected to call periodically to clean up expired peer entries.
2686 */
2687void p2p_expire_peers(struct p2p_data *p2p);
2688
2689void p2p_set_own_pref_freq_list(struct p2p_data *p2p,
Sunil8cd6f4d2022-06-28 18:40:46 +00002690 const struct weighted_pcl *pref_freq_list,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002691 unsigned int size);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002692void p2p_set_override_pref_op_chan(struct p2p_data *p2p, u8 op_class,
2693 u8 chan);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002694
2695/**
2696 * p2p_group_get_common_freqs - Get the group common frequencies
2697 * @group: P2P group context from p2p_group_init()
2698 * @common_freqs: On return will hold the group common frequencies
2699 * @num: On return will hold the number of group common frequencies
2700 * Returns: 0 on success, -1 otherwise
2701 */
2702int p2p_group_get_common_freqs(struct p2p_group *group, int *common_freqs,
2703 unsigned int *num);
2704
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002705struct wpabuf * p2p_build_probe_resp_template(struct p2p_data *p2p,
2706 unsigned int freq);
2707
Hai Shaloma20dcd72022-02-04 13:43:00 -08002708void p2p_set_6ghz_dev_capab(struct p2p_data *p2p, bool allow_6ghz);
2709bool is_p2p_6ghz_capable(struct p2p_data *p2p);
2710bool p2p_is_peer_6ghz_capab(struct p2p_data *p2p, const u8 *addr);
2711bool p2p_peer_wfd_enabled(struct p2p_data *p2p, const u8 *peer_addr);
2712bool p2p_wfd_enabled(struct p2p_data *p2p);
2713bool is_p2p_allow_6ghz(struct p2p_data *p2p);
2714void set_p2p_allow_6ghz(struct p2p_data *p2p, bool value);
Sunil8cd6f4d2022-06-28 18:40:46 +00002715int p2p_remove_6ghz_channels(struct weighted_pcl *pref_freq_list, int size);
Sunil Ravi89eba102022-09-13 21:04:37 -07002716int p2p_channel_to_freq(int op_class, int channel);
Sunil Ravic0f5d412024-09-11 22:12:49 +00002717struct wpabuf * p2p_usd_elems(struct p2p_data *p2p);
2718void p2p_process_usd_elems(struct p2p_data *p2p, const u8 *ies, u16 ies_len,
2719 const u8 *peer_addr, unsigned int freq);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002720
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002721void p2p_set_pairing_setup(struct p2p_data *p2p, int pairing_setup);
2722void p2p_set_pairing_cache(struct p2p_data *p2p, int pairing_cache);
2723void p2p_set_bootstrapmethods(struct p2p_data *p2p, int bootstrap_methods);
2724void p2p_set_pasn_type(struct p2p_data *p2p, u8 pasn_type);
2725void p2p_set_comeback_after(struct p2p_data *p2p, int comeback_after);
2726void p2p_set_reg_info(struct p2p_data *p2p, u8 val);
2727void p2p_set_twt_power_mgmt(struct p2p_data *p2p, int val);
2728void p2p_set_dev_addr(struct p2p_data *p2p, const u8 *addr);
2729void p2p_set_chan_switch_req_enable(struct p2p_data *p2p, bool val);
2730void p2p_set_invitation_op_freq(struct p2p_data *p2p, int freq);
2731
2732int p2p_get_listen_freq(struct p2p_data *p2p, const u8 *peer_addr);
2733int p2p_initiate_pasn_auth(struct p2p_data *p2p, const u8 *addr, int freq);
2734int p2p_initiate_pasn_verify(struct p2p_data *p2p, const u8 *peer_addr,
2735 int freq, enum p2p_invite_role role,
2736 const u8 *bssid, const u8 *ssid, size_t ssid_len,
2737 unsigned int force_freq, const u8 *go_dev_addr,
2738 unsigned int pref_freq);
2739int p2p_pasn_auth_rx(struct p2p_data *p2p, const struct ieee80211_mgmt *mgmt,
2740 size_t len, int freq);
2741int p2p_prepare_data_element(struct p2p_data *p2p, const u8 *peer_addr);
2742int p2p_parse_data_element(struct p2p_data *p2p, const u8 *data, size_t len);
2743int p2p_pasn_auth_tx_status(struct p2p_data *p2p, const u8 *data,
2744 size_t data_len, bool acked, bool verify);
2745int p2p_config_sae_password(struct p2p_data *p2p, const char *pw);
2746void p2p_pasn_pmksa_set_pmk(struct p2p_data *p2p, const u8 *src, const u8 *dst,
2747 const u8 *pmk, size_t pmk_len, const u8 *pmkid);
2748void p2p_set_store_pasn_ptk(struct p2p_data *p2p, u8 val);
2749void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk);
2750int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len);
2751
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002752#endif /* P2P_H */