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