P2P: Add more WPS attributes into Listen state Probe Response
[mech_eap.git] / src / p2p / p2p.h
1 /*
2  * Wi-Fi Direct - P2P module
3  * Copyright (c) 2009-2010, Atheros Communications
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef P2P_H
16 #define P2P_H
17
18 /**
19  * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes
20  */
21 #define P2P_MAX_REG_CLASSES 10
22
23 /**
24  * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class
25  */
26 #define P2P_MAX_REG_CLASS_CHANNELS 20
27
28 /**
29  * struct p2p_channels - List of supported channels
30  */
31 struct p2p_channels {
32         /**
33          * struct p2p_reg_class - Supported regulatory class
34          */
35         struct p2p_reg_class {
36                 /**
37                  * reg_class - Regulatory class (IEEE 802.11-2007, Annex J)
38                  */
39                 u8 reg_class;
40
41                 /**
42                  * channel - Supported channels
43                  */
44                 u8 channel[P2P_MAX_REG_CLASS_CHANNELS];
45
46                 /**
47                  * channels - Number of channel entries in use
48                  */
49                 size_t channels;
50         } reg_class[P2P_MAX_REG_CLASSES];
51
52         /**
53          * reg_classes - Number of reg_class entries in use
54          */
55         size_t reg_classes;
56 };
57
58 enum p2p_wps_method {
59         WPS_NOT_READY, WPS_PIN_LABEL, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC
60 };
61
62 /**
63  * struct p2p_go_neg_results - P2P Group Owner Negotiation results
64  */
65 struct p2p_go_neg_results {
66         /**
67          * status - Negotiation result (Status Code)
68          *
69          * 0 (P2P_SC_SUCCESS) indicates success. Non-zero values indicate
70          * failed negotiation.
71          */
72         int status;
73
74         /**
75          * role_go - Whether local end is Group Owner
76          */
77         int role_go;
78
79         /**
80          * freq - Frequency of the group operational channel in MHz
81          */
82         int freq;
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          * passphrase - WPA2-Personal passphrase for the group (GO only)
96          */
97         char passphrase[64];
98
99         /**
100          * peer_device_addr - P2P Device Address of the peer
101          */
102         u8 peer_device_addr[ETH_ALEN];
103
104         /**
105          * peer_interface_addr - P2P Interface Address of the peer
106          */
107         u8 peer_interface_addr[ETH_ALEN];
108
109         /**
110          * wps_method - WPS method to be used during provisioning
111          */
112         enum p2p_wps_method wps_method;
113
114 #define P2P_MAX_CHANNELS 50
115
116         /**
117          * freq_list - Zero-terminated list of possible operational channels
118          */
119         int freq_list[P2P_MAX_CHANNELS];
120
121         /**
122          * persistent_group - Whether the group should be made persistent
123          */
124         int persistent_group;
125
126         /**
127          * peer_config_timeout - Peer configuration timeout (in 10 msec units)
128          */
129         unsigned int peer_config_timeout;
130 };
131
132 struct p2p_data;
133
134 enum p2p_scan_type {
135         P2P_SCAN_SOCIAL,
136         P2P_SCAN_FULL,
137         P2P_SCAN_SPECIFIC,
138         P2P_SCAN_SOCIAL_PLUS_ONE
139 };
140
141 #define P2P_MAX_WPS_VENDOR_EXT 10
142
143 /**
144  * struct p2p_peer_info - P2P peer information
145  */
146 struct p2p_peer_info {
147         /**
148          * p2p_device_addr - P2P Device Address of the peer
149          */
150         u8 p2p_device_addr[ETH_ALEN];
151
152         /**
153          * pri_dev_type - Primary Device Type
154          */
155         u8 pri_dev_type[8];
156
157         /**
158          * device_name - Device Name
159          */
160         char device_name[33];
161
162         /**
163          * config_methods - WPS Configuration Methods
164          */
165         u16 config_methods;
166
167         /**
168          * dev_capab - Device Capabilities
169          */
170         u8 dev_capab;
171
172         /**
173          * group_capab - Group Capabilities
174          */
175         u8 group_capab;
176
177         /**
178          * wps_sec_dev_type_list - WPS secondary device type list
179          *
180          * This list includes from 0 to 16 Secondary Device Types as indicated
181          * by wps_sec_dev_type_list_len (8 * number of types).
182          */
183         u8 wps_sec_dev_type_list[128];
184
185         /**
186          * wps_sec_dev_type_list_len - Length of secondary device type list
187          */
188         size_t wps_sec_dev_type_list_len;
189
190         struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT];
191 };
192
193 /**
194  * struct p2p_config - P2P configuration
195  *
196  * This configuration is provided to the P2P module during initialization with
197  * p2p_init().
198  */
199 struct p2p_config {
200         /**
201          * country - Country code to use in P2P operations
202          */
203         char country[3];
204
205         /**
206          * reg_class - Regulatory class for own listen channel
207          */
208         u8 reg_class;
209
210         /**
211          * channel - Own listen channel
212          */
213         u8 channel;
214
215         /**
216          * Regulatory class for own operational channel
217          */
218         u8 op_reg_class;
219
220         /**
221          * op_channel - Own operational channel
222          */
223         u8 op_channel;
224
225         /**
226          * cfg_op_channel - Whether op_channel is hardcoded in configuration
227          */
228         u8 cfg_op_channel;
229
230         /**
231          * channels - Own supported regulatory classes and channels
232          *
233          * List of supposerted channels per regulatory class. The regulatory
234          * classes are defined in IEEE Std 802.11-2007 Annex J and the
235          * numbering of the clases depends on the configured country code.
236          */
237         struct p2p_channels channels;
238
239         /**
240          * pri_dev_type - Primary Device Type (see WPS)
241          */
242         u8 pri_dev_type[8];
243
244         /**
245          * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types
246          */
247 #define P2P_SEC_DEVICE_TYPES 5
248
249         /**
250          * sec_dev_type - Optional secondary device types
251          */
252         u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8];
253
254         /**
255          * num_sec_dev_types - Number of sec_dev_type entries
256          */
257         size_t num_sec_dev_types;
258
259         /**
260          * dev_addr - P2P Device Address
261          */
262         u8 dev_addr[ETH_ALEN];
263
264         /**
265          * dev_name - Device Name
266          */
267         char *dev_name;
268
269         char *manufacturer;
270         char *model_name;
271         char *model_number;
272         char *serial_number;
273
274         u8 uuid[16];
275         u16 config_methods;
276
277         /**
278          * concurrent_operations - Whether concurrent operations are supported
279          */
280         int concurrent_operations;
281
282         /**
283          * max_peers - Maximum number of discovered peers to remember
284          *
285          * If more peers are discovered, older entries will be removed to make
286          * room for the new ones.
287          */
288         size_t max_peers;
289
290         /**
291          * p2p_intra_bss - Intra BSS communication is supported
292          */
293         int p2p_intra_bss;
294
295         /**
296          * ssid_postfix - Postfix data to add to the SSID
297          *
298          * This data will be added to the end of the SSID after the
299          * DIRECT-<random two octets> prefix.
300          */
301         u8 ssid_postfix[32 - 9];
302
303         /**
304          * ssid_postfix_len - Length of the ssid_postfix data
305          */
306         size_t ssid_postfix_len;
307
308         /**
309          * msg_ctx - Context to use with wpa_msg() calls
310          */
311         void *msg_ctx;
312
313         /**
314          * cb_ctx - Context to use with callback functions
315          */
316         void *cb_ctx;
317
318
319         /* Callbacks to request lower layer driver operations */
320
321         /**
322          * p2p_scan - Request a P2P scan/search
323          * @ctx: Callback context from cb_ctx
324          * @type: Scan type
325          * @freq: Specific frequency (MHz) to scan or 0 for no restriction
326          * @num_req_dev_types: Number of requested device types
327          * @req_dev_types: Array containing requested device types
328          * Returns: 0 on success, -1 on failure
329          *
330          * This callback function is used to request a P2P scan or search
331          * operation to be completed. Type type argument specifies which type
332          * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the
333          * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL
334          * indicates that all channels are to be scanned. @P2P_SCAN_SPECIFIC
335          * request a scan of a single channel specified by freq.
336          * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels
337          * plus one extra channel specified by freq.
338          *
339          * The full scan is used for the initial scan to find group owners from
340          * all. The other types are used during search phase scan of the social
341          * channels (with potential variation if the Listen channel of the
342          * target peer is known or if other channels are scanned in steps).
343          *
344          * The scan results are returned after this call by calling
345          * p2p_scan_res_handler() for each scan result that has a P2P IE and
346          * then calling p2p_scan_res_handled() to indicate that all scan
347          * results have been indicated.
348          */
349         int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq,
350                         unsigned int num_req_dev_types,
351                         const u8 *req_dev_types);
352
353         /**
354          * send_probe_resp - Transmit a Probe Response frame
355          * @ctx: Callback context from cb_ctx
356          * @buf: Probe Response frame (including the header and body)
357          * Returns: 0 on success, -1 on failure
358          *
359          * This function is used to reply to Probe Request frames that were
360          * indicated with a call to p2p_probe_req_rx(). The response is to be
361          * sent on the same channel or to be dropped if the driver is not
362          * anymore listening to Probe Request frames.
363          *
364          * Alternatively, the responsibility for building the Probe Response
365          * frames in Listen state may be in another system component in which
366          * case this function need to be implemented (i.e., the function
367          * pointer can be %NULL). The WPS and P2P IEs to be added for Probe
368          * Response frames in such a case are available from the
369          * start_listen() callback. It should be noted that the received Probe
370          * Request frames must be indicated by calling p2p_probe_req_rx() even
371          * if this send_probe_resp() is not used.
372          */
373         int (*send_probe_resp)(void *ctx, const struct wpabuf *buf);
374
375         /**
376          * send_action - Transmit an Action frame
377          * @ctx: Callback context from cb_ctx
378          * @freq: Frequency in MHz for the channel on which to transmit
379          * @dst: Destination MAC address (Address 1)
380          * @src: Source MAC address (Address 2)
381          * @bssid: BSSID (Address 3)
382          * @buf: Frame body (starting from Category field)
383          * @len: Length of buf in octets
384          * @wait_time: How many msec to wait for a response frame
385          * Returns: 0 on success, -1 on failure
386          *
387          * The Action frame may not be transmitted immediately and the status
388          * of the transmission must be reported by calling
389          * p2p_send_action_cb() once the frame has either been transmitted or
390          * it has been dropped due to excessive retries or other failure to
391          * transmit.
392          */
393         int (*send_action)(void *ctx, unsigned int freq, const u8 *dst,
394                            const u8 *src, const u8 *bssid, const u8 *buf,
395                            size_t len, unsigned int wait_time);
396
397         /**
398          * send_action_done - Notify that Action frame sequence was completed
399          * @ctx: Callback context from cb_ctx
400          *
401          * This function is called when the Action frame sequence that was
402          * started with send_action() has been completed, i.e., when there is
403          * no need to wait for a response from the destination peer anymore.
404          */
405         void (*send_action_done)(void *ctx);
406
407         /**
408          * start_listen - Start Listen state
409          * @ctx: Callback context from cb_ctx
410          * @freq: Frequency of the listen channel in MHz
411          * @duration: Duration for the Listen state in milliseconds
412          * @probe_resp_ie: IE(s) to be added to Probe Response frames
413          * Returns: 0 on success, -1 on failure
414          *
415          * This Listen state may not start immediately since the driver may
416          * have other pending operations to complete first. Once the Listen
417          * state has started, p2p_listen_cb() must be called to notify the P2P
418          * module. Once the Listen state is stopped, p2p_listen_end() must be
419          * called to notify the P2P module that the driver is not in the Listen
420          * state anymore.
421          *
422          * If the send_probe_resp() is not used for generating the response,
423          * the IEs from probe_resp_ie need to be added to the end of the Probe
424          * Response frame body. If send_probe_resp() is used, the probe_resp_ie
425          * information can be ignored.
426          */
427         int (*start_listen)(void *ctx, unsigned int freq,
428                             unsigned int duration,
429                             const struct wpabuf *probe_resp_ie);
430         /**
431          * stop_listen - Stop Listen state
432          * @ctx: Callback context from cb_ctx
433          *
434          * This callback can be used to stop a Listen state operation that was
435          * previously requested with start_listen().
436          */
437         void (*stop_listen)(void *ctx);
438
439         /**
440          * get_noa - Get current Notice of Absence attribute payload
441          * @ctx: Callback context from cb_ctx
442          * @interface_addr: P2P Interface Address of the GO
443          * @buf: Buffer for returning NoA
444          * @buf_len: Buffer length in octets
445          * Returns: Number of octets used in buf, 0 to indicate no NoA is being
446          * advertized, or -1 on failure
447          *
448          * This function is used to fetch the current Notice of Absence
449          * attribute value from GO.
450          */
451         int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf,
452                        size_t buf_len);
453
454         /* Callbacks to notify events to upper layer management entity */
455
456         /**
457          * dev_found - Notification of a found P2P Device
458          * @ctx: Callback context from cb_ctx
459          * @addr: Source address of the message triggering this notification
460          * @info: P2P peer information
461          * @new_device: Inform if the peer is newly found
462          *
463          * This callback is used to notify that a new P2P Device has been
464          * found. This may happen, e.g., during Search state based on scan
465          * results or during Listen state based on receive Probe Request and
466          * Group Owner Negotiation Request.
467          */
468         void (*dev_found)(void *ctx, const u8 *addr,
469                           const struct p2p_peer_info *info,
470                           int new_device);
471
472         /**
473          * dev_lost - Notification of a lost P2P Device
474          * @ctx: Callback context from cb_ctx
475          * @dev_addr: P2P Device Address of the lost P2P Device
476          *
477          * This callback is used to notify that a P2P Device has been deleted.
478          */
479         void (*dev_lost)(void *ctx, const u8 *dev_addr);
480
481         /**
482          * go_neg_req_rx - Notification of a receive GO Negotiation Request
483          * @ctx: Callback context from cb_ctx
484          * @src: Source address of the message triggering this notification
485          * @dev_passwd_id: WPS Device Password ID
486          *
487          * This callback is used to notify that a P2P Device is requesting
488          * group owner negotiation with us, but we do not have all the
489          * necessary information to start GO Negotiation. This indicates that
490          * the local user has not authorized the connection yet by providing a
491          * PIN or PBC button press. This information can be provided with a
492          * call to p2p_connect().
493          */
494         void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id);
495
496         /**
497          * go_neg_completed - Notification of GO Negotiation results
498          * @ctx: Callback context from cb_ctx
499          * @res: GO Negotiation results
500          *
501          * This callback is used to notify that Group Owner Negotiation has
502          * been completed. Non-zero struct p2p_go_neg_results::status indicates
503          * failed negotiation. In case of success, this function is responsible
504          * for creating a new group interface (or using the existing interface
505          * depending on driver features), setting up the group interface in
506          * proper mode based on struct p2p_go_neg_results::role_go and
507          * initializing WPS provisioning either as a Registrar (if GO) or as an
508          * Enrollee. Successful WPS provisioning must be indicated by calling
509          * p2p_wps_success_cb(). The callee is responsible for timing out group
510          * formation if WPS provisioning cannot be completed successfully
511          * within 15 seconds.
512          */
513         void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res);
514
515         /**
516          * sd_request - Callback on Service Discovery Request
517          * @ctx: Callback context from cb_ctx
518          * @freq: Frequency (in MHz) of the channel
519          * @sa: Source address of the request
520          * @dialog_token: Dialog token
521          * @update_indic: Service Update Indicator from the source of request
522          * @tlvs: P2P Service Request TLV(s)
523          * @tlvs_len: Length of tlvs buffer in octets
524          *
525          * This callback is used to indicate reception of a service discovery
526          * request. Response to the query must be indicated by calling
527          * p2p_sd_response() with the context information from the arguments to
528          * this callback function.
529          *
530          * This callback handler can be set to %NULL to indicate that service
531          * discovery is not supported.
532          */
533         void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token,
534                            u16 update_indic, const u8 *tlvs, size_t tlvs_len);
535
536         /**
537          * sd_response - Callback on Service Discovery Response
538          * @ctx: Callback context from cb_ctx
539          * @sa: Source address of the request
540          * @update_indic: Service Update Indicator from the source of response
541          * @tlvs: P2P Service Response TLV(s)
542          * @tlvs_len: Length of tlvs buffer in octets
543          *
544          * This callback is used to indicate reception of a service discovery
545          * response. This callback handler can be set to %NULL if no service
546          * discovery requests are used. The information provided with this call
547          * is replies to the queries scheduled with p2p_sd_request().
548          */
549         void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic,
550                             const u8 *tlvs, size_t tlvs_len);
551
552         /**
553          * prov_disc_req - Callback on Provisiong Discovery Request
554          * @ctx: Callback context from cb_ctx
555          * @peer: Source address of the request
556          * @config_methods: Requested WPS Config Method
557          * @dev_addr: P2P Device Address of the found P2P Device
558          * @pri_dev_type: Primary Device Type
559          * @dev_name: Device Name
560          * @supp_config_methods: Supported configuration Methods
561          * @dev_capab: Device Capabilities
562          * @group_capab: Group Capabilities
563          *
564          * This callback is used to indicate reception of a Provision Discovery
565          * Request frame that the P2P module accepted.
566          */
567         void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods,
568                               const u8 *dev_addr, const u8 *pri_dev_type,
569                               const char *dev_name, u16 supp_config_methods,
570                               u8 dev_capab, u8 group_capab);
571
572         /**
573          * prov_disc_resp - Callback on Provisiong Discovery Response
574          * @ctx: Callback context from cb_ctx
575          * @peer: Source address of the response
576          * @config_methods: Value from p2p_prov_disc_req() or 0 on failure
577          *
578          * This callback is used to indicate reception of a Provision Discovery
579          * Response frame for a pending request scheduled with
580          * p2p_prov_disc_req(). This callback handler can be set to %NULL if
581          * provision discovery is not used.
582          */
583         void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods);
584
585         /**
586          * invitation_process - Optional callback for processing Invitations
587          * @ctx: Callback context from cb_ctx
588          * @sa: Source address of the Invitation Request
589          * @bssid: P2P Group BSSID from the request or %NULL if not included
590          * @go_dev_addr: GO Device Address from P2P Group ID
591          * @ssid: SSID from P2P Group ID
592          * @ssid_len: Length of ssid buffer in octets
593          * @go: Variable for returning whether the local end is GO in the group
594          * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO)
595          * @force_freq: Variable for returning forced frequency for the group
596          * @persistent_group: Whether this is an invitation to reinvoke a
597          *      persistent group (instead of invitation to join an active
598          *      group)
599          * Returns: Status code (P2P_SC_*)
600          *
601          * This optional callback can be used to implement persistent reconnect
602          * by allowing automatic restarting of persistent groups without user
603          * interaction. If this callback is not implemented (i.e., is %NULL),
604          * the received Invitation Request frames are replied with
605          * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the
606          * invitation_result() callback.
607          *
608          * If the requested parameters are acceptable and the group is known,
609          * %P2P_SC_SUCCESS may be returned. If the requested group is unknown,
610          * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED
611          * can be returned if there is not enough data to provide immediate
612          * response, i.e., if some sort of user interaction is needed. The
613          * invitation_received() callback will be called in that case
614          * immediately after this call.
615          */
616         u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid,
617                                  const u8 *go_dev_addr, const u8 *ssid,
618                                  size_t ssid_len, int *go, u8 *group_bssid,
619                                  int *force_freq, int persistent_group);
620
621         /**
622          * invitation_received - Callback on Invitation Request RX
623          * @ctx: Callback context from cb_ctx
624          * @sa: Source address of the Invitation Request
625          * @bssid: P2P Group BSSID or %NULL if not received
626          * @ssid: SSID of the group
627          * @ssid_len: Length of ssid in octets
628          * @go_dev_addr: GO Device Address
629          * @status: Response Status
630          * @op_freq: Operational frequency for the group
631          *
632          * This callback is used to indicate sending of an Invitation Response
633          * for a received Invitation Request. If status == 0 (success), the
634          * upper layer code is responsible for starting the group. status == 1
635          * indicates need to get user authorization for the group. Other status
636          * values indicate that the invitation request was rejected.
637          */
638         void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid,
639                                     const u8 *ssid, size_t ssid_len,
640                                     const u8 *go_dev_addr, u8 status,
641                                     int op_freq);
642
643         /**
644          * invitation_result - Callback on Invitation result
645          * @ctx: Callback context from cb_ctx
646          * @status: Negotiation result (Status Code)
647          * @bssid: P2P Group BSSID or %NULL if not received
648          *
649          * This callback is used to indicate result of an Invitation procedure
650          * started with a call to p2p_invite(). The indicated status code is
651          * the value received from the peer in Invitation Response with 0
652          * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a
653          * local failure in transmitting the Invitation Request.
654          */
655         void (*invitation_result)(void *ctx, int status, const u8 *bssid);
656 };
657
658
659 /* P2P module initialization/deinitialization */
660
661 /**
662  * p2p_init - Initialize P2P module
663  * @cfg: P2P module configuration
664  * Returns: Pointer to private data or %NULL on failure
665  *
666  * This function is used to initialize global P2P module context (one per
667  * device). The P2P module will keep a copy of the configuration data, so the
668  * caller does not need to maintain this structure. However, the callback
669  * functions and the context parameters to them must be kept available until
670  * the P2P module is deinitialized with p2p_deinit().
671  */
672 struct p2p_data * p2p_init(const struct p2p_config *cfg);
673
674 /**
675  * p2p_deinit - Deinitialize P2P module
676  * @p2p: P2P module context from p2p_init()
677  */
678 void p2p_deinit(struct p2p_data *p2p);
679
680 /**
681  * p2p_flush - Flush P2P module state
682  * @p2p: P2P module context from p2p_init()
683  *
684  * This command removes the P2P module state like peer device entries.
685  */
686 void p2p_flush(struct p2p_data *p2p);
687
688 /**
689  * p2p_unauthorize - Unauthorize the specified peer device
690  * @p2p: P2P module context from p2p_init()
691  * @addr: P2P peer entry to be unauthorized
692  * Returns: 0 on success, -1 on failure
693  *
694  * This command removes any connection authorization from the specified P2P
695  * peer device address. This can be used, e.g., to cancel effect of a previous
696  * p2p_authorize() or p2p_connect() call that has not yet resulted in completed
697  * GO Negotiation.
698  */
699 int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr);
700
701 /**
702  * p2p_set_dev_name - Set device name
703  * @p2p: P2P module context from p2p_init()
704  * Returns: 0 on success, -1 on failure
705  *
706  * This function can be used to update the P2P module configuration with
707  * information that was not available at the time of the p2p_init() call.
708  */
709 int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name);
710
711 int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer);
712 int p2p_set_model_name(struct p2p_data *p2p, const char *model_name);
713 int p2p_set_model_number(struct p2p_data *p2p, const char *model_number);
714 int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number);
715
716 void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods);
717 void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid);
718
719 /**
720  * p2p_set_pri_dev_type - Set primary device type
721  * @p2p: P2P module context from p2p_init()
722  * Returns: 0 on success, -1 on failure
723  *
724  * This function can be used to update the P2P module configuration with
725  * information that was not available at the time of the p2p_init() call.
726  */
727 int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type);
728
729 /**
730  * p2p_set_sec_dev_types - Set secondary device types
731  * @p2p: P2P module context from p2p_init()
732  * Returns: 0 on success, -1 on failure
733  *
734  * This function can be used to update the P2P module configuration with
735  * information that was not available at the time of the p2p_init() call.
736  */
737 int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8],
738                           size_t num_dev_types);
739
740 int p2p_set_country(struct p2p_data *p2p, const char *country);
741
742
743 /* Commands from upper layer management entity */
744
745 enum p2p_discovery_type {
746         P2P_FIND_START_WITH_FULL,
747         P2P_FIND_ONLY_SOCIAL,
748         P2P_FIND_PROGRESSIVE
749 };
750
751 /**
752  * p2p_find - Start P2P Find (Device Discovery)
753  * @p2p: P2P module context from p2p_init()
754  * @timeout: Timeout for find operation in seconds or 0 for no timeout
755  * @type: Device Discovery type
756  * @num_req_dev_types: Number of requested device types
757  * @req_dev_types: Requested device types array, must be an array
758  *      containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no
759  *      requested device types.
760  * Returns: 0 on success, -1 on failure
761  */
762 int p2p_find(struct p2p_data *p2p, unsigned int timeout,
763              enum p2p_discovery_type type,
764              unsigned int num_req_dev_types, const u8 *req_dev_types);
765
766 /**
767  * p2p_stop_find - Stop P2P Find (Device Discovery)
768  * @p2p: P2P module context from p2p_init()
769  */
770 void p2p_stop_find(struct p2p_data *p2p);
771
772 /**
773  * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq
774  * @p2p: P2P module context from p2p_init()
775  * @freq: Frequency in MHz for next operation
776  *
777  * This is like p2p_stop_find(), but Listen state is not stopped if we are
778  * already on the same frequency.
779  */
780 void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq);
781
782 /**
783  * p2p_listen - Start P2P Listen state for specified duration
784  * @p2p: P2P module context from p2p_init()
785  * @timeout: Listen state duration in milliseconds
786  * Returns: 0 on success, -1 on failure
787  *
788  * This function can be used to request the P2P module to keep the device
789  * discoverable on the listen channel for an extended set of time. At least in
790  * its current form, this is mainly used for testing purposes and may not be of
791  * much use for normal P2P operations.
792  */
793 int p2p_listen(struct p2p_data *p2p, unsigned int timeout);
794
795 /**
796  * p2p_connect - Start P2P group formation (GO negotiation)
797  * @p2p: P2P module context from p2p_init()
798  * @peer_addr: MAC address of the peer P2P client
799  * @wps_method: WPS method to be used in provisioning
800  * @go_intent: Local GO intent value (1..15)
801  * @own_interface_addr: Intended interface address to use with the group
802  * @force_freq: The only allowed channel frequency in MHz or 0
803  * @persistent_group: Whether to create a persistent group
804  * Returns: 0 on success, -1 on failure
805  */
806 int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
807                 enum p2p_wps_method wps_method,
808                 int go_intent, const u8 *own_interface_addr,
809                 unsigned int force_freq, int persistent_group);
810
811 /**
812  * p2p_authorize - Authorize P2P group formation (GO negotiation)
813  * @p2p: P2P module context from p2p_init()
814  * @peer_addr: MAC address of the peer P2P client
815  * @wps_method: WPS method to be used in provisioning
816  * @go_intent: Local GO intent value (1..15)
817  * @own_interface_addr: Intended interface address to use with the group
818  * @force_freq: The only allowed channel frequency in MHz or 0
819  * @persistent_group: Whether to create a persistent group
820  * Returns: 0 on success, -1 on failure
821  *
822  * This is like p2p_connect(), but the actual group negotiation is not
823  * initiated automatically, i.e., the other end is expected to do that.
824  */
825 int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
826                   enum p2p_wps_method wps_method,
827                   int go_intent, const u8 *own_interface_addr,
828                   unsigned int force_freq, int persistent_group);
829
830 /**
831  * p2p_reject - Reject peer device (explicitly block connection attempts)
832  * @p2p: P2P module context from p2p_init()
833  * @peer_addr: MAC address of the peer P2P client
834  * Returns: 0 on success, -1 on failure
835  */
836 int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr);
837
838 /**
839  * p2p_prov_disc_req - Send Provision Discovery Request
840  * @p2p: P2P module context from p2p_init()
841  * @peer_addr: MAC address of the peer P2P client
842  * @config_methods: WPS Config Methods value (only one bit set)
843  * @join: Whether this is used by a client joining an active group
844  * Returns: 0 on success, -1 on failure
845  *
846  * This function can be used to request a discovered P2P peer to display a PIN
847  * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us
848  * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame
849  * is transmitted once immediately and if no response is received, the frame
850  * will be sent again whenever the target device is discovered during device
851  * dsicovery (start with a p2p_find() call). Response from the peer is
852  * indicated with the p2p_config::prov_disc_resp() callback.
853  */
854 int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
855                       u16 config_methods, int join);
856
857 /**
858  * p2p_sd_request - Schedule a service discovery query
859  * @p2p: P2P module context from p2p_init()
860  * @dst: Destination peer or %NULL to apply for all peers
861  * @tlvs: P2P Service Query TLV(s)
862  * Returns: Reference to the query or %NULL on failure
863  *
864  * Response to the query is indicated with the p2p_config::sd_response()
865  * callback.
866  */
867 void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
868                       const struct wpabuf *tlvs);
869
870 /**
871  * p2p_sd_cancel_request - Cancel a pending service discovery query
872  * @p2p: P2P module context from p2p_init()
873  * @req: Query reference from p2p_sd_request()
874  * Returns: 0 if request for cancelled; -1 if not found
875  */
876 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req);
877
878 /**
879  * p2p_sd_response - Send response to a service discovery query
880  * @p2p: P2P module context from p2p_init()
881  * @freq: Frequency from p2p_config::sd_request() callback
882  * @dst: Destination address from p2p_config::sd_request() callback
883  * @dialog_token: Dialog token from p2p_config::sd_request() callback
884  * @resp_tlvs: P2P Service Response TLV(s)
885  *
886  * This function is called as a response to the request indicated with
887  * p2p_config::sd_request() callback.
888  */
889 void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
890                      u8 dialog_token, const struct wpabuf *resp_tlvs);
891
892 /**
893  * p2p_sd_service_update - Indicate a change in local services
894  * @p2p: P2P module context from p2p_init()
895  *
896  * This function needs to be called whenever there is a change in availability
897  * of the local services. This will increment the Service Update Indicator
898  * value which will be used in SD Request and Response frames.
899  */
900 void p2p_sd_service_update(struct p2p_data *p2p);
901
902
903 enum p2p_invite_role {
904         P2P_INVITE_ROLE_GO,
905         P2P_INVITE_ROLE_ACTIVE_GO,
906         P2P_INVITE_ROLE_CLIENT
907 };
908
909 /**
910  * p2p_invite - Invite a P2P Device into a group
911  * @p2p: P2P module context from p2p_init()
912  * @peer: Device Address of the peer P2P Device
913  * @role: Local role in the group
914  * @bssid: Group BSSID or %NULL if not known
915  * @ssid: Group SSID
916  * @ssid_len: Length of ssid in octets
917  * @force_freq: The only allowed channel frequency in MHz or 0
918  * @go_dev_addr: Forced GO Device Address or %NULL if none
919  * @persistent_group: Whether this is to reinvoke a persistent group
920  * Returns: 0 on success, -1 on failure
921  */
922 int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
923                const u8 *bssid, const u8 *ssid, size_t ssid_len,
924                unsigned int force_freq, const u8 *go_dev_addr,
925                int persistent_group);
926
927 /**
928  * p2p_presence_req - Request GO presence
929  * @p2p: P2P module context from p2p_init()
930  * @go_interface_addr: GO P2P Interface Address
931  * @own_interface_addr: Own P2P Interface Address for this group
932  * @freq: Group operating frequence (in MHz)
933  * @duration1: Preferred presence duration in microseconds
934  * @interval1: Preferred presence interval in microseconds
935  * @duration2: Acceptable presence duration in microseconds
936  * @interval2: Acceptable presence interval in microseconds
937  * Returns: 0 on success, -1 on failure
938  *
939  * If both duration and interval values are zero, the parameter pair is not
940  * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0).
941  */
942 int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
943                      const u8 *own_interface_addr, unsigned int freq,
944                      u32 duration1, u32 interval1, u32 duration2,
945                      u32 interval2);
946
947 /**
948  * p2p_ext_listen - Set Extended Listen Timing
949  * @p2p: P2P module context from p2p_init()
950  * @freq: Group operating frequence (in MHz)
951  * @period: Availability period in milliseconds (1-65535; 0 to disable)
952  * @interval: Availability interval in milliseconds (1-65535; 0 to disable)
953  * Returns: 0 on success, -1 on failure
954  *
955  * This function can be used to enable or disable (period = interval = 0)
956  * Extended Listen Timing. When enabled, the P2P Device will become
957  * discoverable (go into Listen State) every @interval milliseconds for at
958  * least @period milliseconds.
959  */
960 int p2p_ext_listen(struct p2p_data *p2p, unsigned int period,
961                    unsigned int interval);
962
963 /* Event notifications from upper layer management operations */
964
965 /**
966  * p2p_wps_success_cb - Report successfully completed WPS provisioning
967  * @p2p: P2P module context from p2p_init()
968  * @mac_addr: Peer address
969  *
970  * This function is used to report successfully completed WPS provisioning
971  * during group formation in both GO/Registrar and client/Enrollee roles.
972  */
973 void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr);
974
975 /**
976  * p2p_group_formation_failed - Report failed WPS provisioning
977  * @p2p: P2P module context from p2p_init()
978  *
979  * This function is used to report failed group formation. This can happen
980  * either due to failed WPS provisioning or due to 15 second timeout during
981  * the provisioning phase.
982  */
983 void p2p_group_formation_failed(struct p2p_data *p2p);
984
985
986 /* Event notifications from lower layer driver operations */
987
988 /**
989  * p2p_probe_req_rx - Report reception of a Probe Request frame
990  * @p2p: P2P module context from p2p_init()
991  * @addr: Source MAC address
992  * @ie: Information elements from the Probe Request frame body
993  * @ie_len: Length of ie buffer in octets
994  * Returns: 0 to indicate the frame was not processed or 1 if it was
995  */
996 int p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *ie,
997                      size_t ie_len);
998
999 /**
1000  * p2p_rx_action - Report received Action frame
1001  * @p2p: P2P module context from p2p_init()
1002  * @da: Destination address of the received Action frame
1003  * @sa: Source address of the received Action frame
1004  * @bssid: Address 3 of the received Action frame
1005  * @category: Category of the received Action frame
1006  * @data: Action frame body after the Category field
1007  * @len: Length of the data buffer in octets
1008  * @freq: Frequency (in MHz) on which the frame was received
1009  */
1010 void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
1011                    const u8 *bssid, u8 category,
1012                    const u8 *data, size_t len, int freq);
1013
1014 /**
1015  * p2p_scan_res_handler - Indicate a P2P scan results
1016  * @p2p: P2P module context from p2p_init()
1017  * @bssid: BSSID of the scan result
1018  * @freq: Frequency of the channel on which the device was found in MHz
1019  * @level: Signal level (signal strength of the received Beacon/Probe Response
1020  *      frame)
1021  * @ies: Pointer to IEs from the scan result
1022  * @ies_len: Length of the ies buffer
1023  * Returns: 0 to continue or 1 to stop scan result indication
1024  *
1025  * This function is called to indicate a scan result entry with P2P IE from a
1026  * scan requested with struct p2p_config::p2p_scan(). This can be called during
1027  * the actual scan process (i.e., whenever a new device is found) or as a
1028  * sequence of calls after the full scan has been completed. The former option
1029  * can result in optimized operations, but may not be supported by all
1030  * driver/firmware designs. The ies buffer need to include at least the P2P IE,
1031  * but it is recommended to include all IEs received from the device. The
1032  * caller does not need to check that the IEs contain a P2P IE before calling
1033  * this function since frames will be filtered internally if needed.
1034  *
1035  * This function will return 1 if it wants to stop scan result iteration (and
1036  * scan in general if it is still in progress). This is used to allow faster
1037  * start of a pending operation, e.g., to start a pending GO negotiation.
1038  */
1039 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
1040                          int level, const u8 *ies, size_t ies_len);
1041
1042 /**
1043  * p2p_scan_res_handled - Indicate end of scan results
1044  * @p2p: P2P module context from p2p_init()
1045  *
1046  * This function is called to indicate that all P2P scan results from a scan
1047  * have been reported with zero or more calls to p2p_scan_res_handler(). This
1048  * function must be called as a response to successful
1049  * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler()
1050  * calls stopped iteration.
1051  */
1052 void p2p_scan_res_handled(struct p2p_data *p2p);
1053
1054 enum p2p_send_action_result {
1055         P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */,
1056         P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */,
1057         P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */
1058 };
1059
1060 /**
1061  * p2p_send_action_cb - Notify TX status of an Action frame
1062  * @p2p: P2P module context from p2p_init()
1063  * @freq: Channel frequency in MHz
1064  * @dst: Destination MAC address (Address 1)
1065  * @src: Source MAC address (Address 2)
1066  * @bssid: BSSID (Address 3)
1067  * @result: Result of the transmission attempt
1068  *
1069  * This function is used to indicate the result of an Action frame transmission
1070  * that was requested with struct p2p_config::send_action() callback.
1071  */
1072 void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
1073                         const u8 *src, const u8 *bssid,
1074                         enum p2p_send_action_result result);
1075
1076 /**
1077  * p2p_listen_cb - Indicate the start of a requested Listen state
1078  * @p2p: P2P module context from p2p_init()
1079  * @freq: Listen channel frequency in MHz
1080  * @duration: Duration for the Listen state in milliseconds
1081  *
1082  * This function is used to indicate that a Listen state requested with
1083  * struct p2p_config::start_listen() callback has started.
1084  */
1085 void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
1086                    unsigned int duration);
1087
1088 /**
1089  * p2p_listen_end - Indicate the end of a requested Listen state
1090  * @p2p: P2P module context from p2p_init()
1091  * @freq: Listen channel frequency in MHz
1092  * Returns: 0 if no operations were started, 1 if an operation was started
1093  *
1094  * This function is used to indicate that a Listen state requested with
1095  * struct p2p_config::start_listen() callback has ended.
1096  */
1097 int p2p_listen_end(struct p2p_data *p2p, unsigned int freq);
1098
1099 void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
1100                       const u8 *ie, size_t ie_len);
1101
1102 void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
1103                         const u8 *ie, size_t ie_len);
1104
1105
1106 /* Per-group P2P state for GO */
1107
1108 struct p2p_group;
1109
1110 /**
1111  * struct p2p_group_config - P2P group configuration
1112  *
1113  * This configuration is provided to the P2P module during initialization of
1114  * the per-group information with p2p_group_init().
1115  */
1116 struct p2p_group_config {
1117         /**
1118          * persistent_group - Whether the group is persistent
1119          */
1120         int persistent_group;
1121
1122         /**
1123          * interface_addr - P2P Interface Address of the group
1124          */
1125         u8 interface_addr[ETH_ALEN];
1126
1127         /**
1128          * max_clients - Maximum number of clients in the group
1129          */
1130         unsigned int max_clients;
1131
1132         /**
1133          * cb_ctx - Context to use with callback functions
1134          */
1135         void *cb_ctx;
1136
1137         /**
1138          * ie_update - Notification of IE update
1139          * @ctx: Callback context from cb_ctx
1140          * @beacon_ies: P2P IE for Beacon frames or %NULL if no change
1141          * @proberesp_ies: P2P Ie for Probe Response frames
1142          *
1143          * P2P module uses this callback function to notify whenever the P2P IE
1144          * in Beacon or Probe Response frames should be updated based on group
1145          * events.
1146          *
1147          * The callee is responsible for freeing the returned buffer(s) with
1148          * wpabuf_free().
1149          */
1150         void (*ie_update)(void *ctx, struct wpabuf *beacon_ies,
1151                           struct wpabuf *proberesp_ies);
1152
1153         /**
1154          * idle_update - Notification of changes in group idle state
1155          * @ctx: Callback context from cb_ctx
1156          * @idle: Whether the group is idle (no associated stations)
1157          */
1158         void (*idle_update)(void *ctx, int idle);
1159 };
1160
1161 /**
1162  * p2p_group_init - Initialize P2P group
1163  * @p2p: P2P module context from p2p_init()
1164  * @config: P2P group configuration (will be freed by p2p_group_deinit())
1165  * Returns: Pointer to private data or %NULL on failure
1166  *
1167  * This function is used to initialize per-group P2P module context. Currently,
1168  * this is only used to manage GO functionality and P2P clients do not need to
1169  * create an instance of this per-group information.
1170  */
1171 struct p2p_group * p2p_group_init(struct p2p_data *p2p,
1172                                   struct p2p_group_config *config);
1173
1174 /**
1175  * p2p_group_deinit - Deinitialize P2P group
1176  * @group: P2P group context from p2p_group_init()
1177  */
1178 void p2p_group_deinit(struct p2p_group *group);
1179
1180 /**
1181  * p2p_group_notif_assoc - Notification of P2P client association with GO
1182  * @group: P2P group context from p2p_group_init()
1183  * @addr: Interface address of the P2P client
1184  * @ie: IEs from the (Re)association Request frame
1185  * @len: Length of the ie buffer in octets
1186  * Returns: 0 on success, -1 on failure
1187  */
1188 int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr,
1189                           const u8 *ie, size_t len);
1190
1191 /**
1192  * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response
1193  * @group: P2P group context from p2p_group_init()
1194  * @status: Status value (P2P_SC_SUCCESS if association succeeded)
1195  * Returns: P2P IE for (Re)association Response or %NULL on failure
1196  *
1197  * The caller is responsible for freeing the returned buffer with
1198  * wpabuf_free().
1199  */
1200 struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status);
1201
1202 /**
1203  * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO
1204  * @group: P2P group context from p2p_group_init()
1205  * @addr: Interface address of the P2P client
1206  */
1207 void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr);
1208
1209 /**
1210  * p2p_group_notif_formation_done - Notification of completed group formation
1211  * @group: P2P group context from p2p_group_init()
1212  */
1213 void p2p_group_notif_formation_done(struct p2p_group *group);
1214
1215 /**
1216  * p2p_group_notif_noa - Notification of NoA change
1217  * @group: P2P group context from p2p_group_init()
1218  * @noa: Notice of Absence attribute payload, %NULL if none
1219  * @noa_len: Length of noa buffer in octets
1220  * Returns: 0 on success, -1 on failure
1221  *
1222  * Notify the P2P group management about a new NoA contents. This will be
1223  * inserted into the P2P IEs in Beacon and Probe Response frames with rest of
1224  * the group information.
1225  */
1226 int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa,
1227                         size_t noa_len);
1228
1229 /**
1230  * p2p_group_match_dev_type - Match device types in group with requested type
1231  * @group: P2P group context from p2p_group_init()
1232  * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs)
1233  * Returns: 1 on match, 0 on mismatch
1234  *
1235  * This function can be used to match the Requested Device Type attribute in
1236  * WPS IE with the device types of a group member for deciding whether a GO
1237  * should reply to a Probe Request frame. Match will be reported if the WPS IE
1238  * is not requested any specific device type.
1239  */
1240 int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps);
1241
1242 /**
1243  * p2p_group_go_discover - Send GO Discoverability Request to a group client
1244  * @group: P2P group context from p2p_group_init()
1245  * Returns: 0 on success (frame scheduled); -1 if client was not found
1246  */
1247 int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
1248                           const u8 *searching_dev, int rx_freq);
1249
1250
1251 /* Generic helper functions */
1252
1253 /**
1254  * p2p_ie_text - Build text format description of P2P IE
1255  * @p2p_ie: P2P IE
1256  * @buf: Buffer for returning text
1257  * @end: Pointer to the end of the buf area
1258  * Returns: Number of octets written to the buffer or -1 on failure
1259  *
1260  * This function can be used to parse P2P IE contents into text format
1261  * field=value lines.
1262  */
1263 int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end);
1264
1265 /**
1266  * p2p_scan_result_text - Build text format description of P2P IE
1267  * @ies: Information elements from scan results
1268  * @ies_len: ies buffer length in octets
1269  * @buf: Buffer for returning text
1270  * @end: Pointer to the end of the buf area
1271  * Returns: Number of octets written to the buffer or -1 on failure
1272  *
1273  * This function can be used to parse P2P IE contents into text format
1274  * field=value lines.
1275  */
1276 int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end);
1277
1278 /**
1279  * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame
1280  * @p2p: P2P module context from p2p_init()
1281  * @bssid: BSSID
1282  * @buf: Buffer for writing the P2P IE
1283  * @len: Maximum buf length in octets
1284  * @p2p_group: Whether this is for association with a P2P GO
1285  * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none
1286  * Returns: Number of octets written into buf or -1 on failure
1287  */
1288 int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf,
1289                      size_t len, int p2p_group, struct wpabuf *p2p_ie);
1290
1291 /**
1292  * p2p_scan_ie - Build P2P IE for Probe Request
1293  * @p2p: P2P module context from p2p_init()
1294  * @ies: Buffer for writing P2P IE
1295  */
1296 void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies);
1297
1298 /**
1299  * p2p_go_params - Generate random P2P group parameters
1300  * @p2p: P2P module context from p2p_init()
1301  * @params: Buffer for parameters
1302  * Returns: 0 on success, -1 on failure
1303  */
1304 int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params);
1305
1306 /**
1307  * p2p_get_group_capab - Get Group Capability from P2P IE data
1308  * @p2p_ie: P2P IE(s) contents
1309  * Returns: Group Capability
1310  */
1311 u8 p2p_get_group_capab(const struct wpabuf *p2p_ie);
1312
1313 /**
1314  * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection
1315  * @p2p_ie: P2P IE(s) contents
1316  * Returns: 0 if cross connection is allow, 1 if not
1317  */
1318 int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie);
1319
1320 /**
1321  * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data
1322  * @p2p_ie: P2P IE(s) contents
1323  * Returns: Pointer to P2P Device Address or %NULL if not included
1324  */
1325 const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie);
1326
1327 /**
1328  * p2p_get_peer_info - Get P2P peer information in text format
1329  * @p2p: P2P module context from p2p_init()
1330  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
1331  * @next: Whether to select the peer entry following the one indicated by addr
1332  * @buf: Buffer for returning text
1333  * @buflen: Maximum buffer length
1334  * Returns: Number of octets written to the buffer or -1 on failure
1335  */
1336 int p2p_get_peer_info(struct p2p_data *p2p, const u8 *addr, int next,
1337                       char *buf, size_t buflen);
1338
1339 /**
1340  * p2p_set_client_discoverability - Set client discoverability capability
1341  * @p2p: P2P module context from p2p_init()
1342  * @enabled: Whether client discoverability will be enabled
1343  *
1344  * This function can be used to disable (and re-enable) client discoverability.
1345  * This capability is enabled by default and should not be disabled in normal
1346  * use cases, i.e., this is mainly for testing purposes.
1347  */
1348 void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled);
1349
1350 /**
1351  * p2p_set_manageD_oper - Set managed P2P Device operations capability
1352  * @p2p: P2P module context from p2p_init()
1353  * @enabled: Whether managed P2P Device operations will be enabled
1354  */
1355 void p2p_set_managed_oper(struct p2p_data *p2p, int enabled);
1356
1357 int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel);
1358
1359 int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len);
1360
1361 int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
1362                            u8 *iface_addr);
1363 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
1364                            u8 *dev_addr);
1365
1366 void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr);
1367
1368 /**
1369  * p2p_set_cross_connect - Set cross connection capability
1370  * @p2p: P2P module context from p2p_init()
1371  * @enabled: Whether cross connection will be enabled
1372  */
1373 void p2p_set_cross_connect(struct p2p_data *p2p, int enabled);
1374
1375 int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr);
1376
1377 int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
1378                    const u8 *ies, size_t ies_len);
1379
1380 /**
1381  * p2p_set_intra_bss_dist - Set intra BSS distribution
1382  * @p2p: P2P module context from p2p_init()
1383  * @enabled: Whether intra BSS distribution will be enabled
1384  */
1385 void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled);
1386
1387 /**
1388  * p2p_supported_freq - Check whether channel is supported for P2P
1389  * @p2p: P2P module context from p2p_init()
1390  * @freq: Channel frequency in MHz
1391  * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
1392  */
1393 int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq);
1394
1395 void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan);
1396
1397 /**
1398  * p2p_set_best_channels - Update best channel information
1399  * @p2p: P2P module context from p2p_init()
1400  * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band
1401  * @freq_5: Frequency (MHz) of best channel in 5 GHz band
1402  * @freq_overall: Frequency (MHz) of best channel overall
1403  */
1404 void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
1405                            int freq_overall);
1406
1407 const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p);
1408
1409 /**
1410  * p2p_get_group_num_members - Get number of members in group
1411  * @group: P2P group context from p2p_group_init()
1412  * Returns: Number of members in the group
1413  */
1414 unsigned int p2p_get_group_num_members(struct p2p_group *group);
1415
1416 /**
1417  * p2p_iterate_group_members - Iterate group members
1418  * @group: P2P group context from p2p_group_init()
1419  * @next: iteration pointer, must be a pointer to a void * that is set to %NULL
1420  *      on the first call and not modified later
1421  * Returns: A P2P Interface Address for each call and %NULL for no more members
1422  */
1423 const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next);
1424
1425 /**
1426  * p2p_get_peer_found - Get P2P peer info structure of a found peer
1427  * @p2p: P2P module context from p2p_init()
1428  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
1429  * @next: Whether to select the peer entry following the one indicated by addr
1430  * Returns: The first P2P peer info available or %NULL if no such peer exists
1431  */
1432 const struct p2p_peer_info *
1433 p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next);
1434
1435 /**
1436  * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions
1437  * @p2p: P2P module context from p2p_init()
1438  */
1439 void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p);
1440
1441 /**
1442  * p2p_add_wps_vendor_extension - Add a WPS vendor extension
1443  * @p2p: P2P module context from p2p_init()
1444  * @vendor_ext: The vendor extensions to add
1445  * Returns: 0 on success, -1 on failure
1446  *
1447  * The wpabuf structures in the array are owned by the P2P
1448  * module after this call.
1449  */
1450 int p2p_add_wps_vendor_extension(struct p2p_data *p2p,
1451                                  const struct wpabuf *vendor_ext);
1452
1453 #endif /* P2P_H */