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