wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
p2p.c File Reference

Wi-Fi Direct - P2P module. More...

#include "includes.h"
#include "common.h"
#include "eloop.h"
#include "common/ieee802_11_defs.h"
#include "common/ieee802_11_common.h"
#include "common/wpa_ctrl.h"
#include "crypto/sha256.h"
#include "crypto/crypto.h"
#include "wps/wps_i.h"
#include "p2p_i.h"
#include "p2p.h"

Macros

#define P2P_SCAN_TIMEOUT   35
 
#define P2P_PEER_EXPIRATION_AGE   60
 Number of seconds after which inactive peer entries will be removed.
 

Functions

void p2p_expire_peers (struct p2p_data *p2p)
 Periodic cleanup function to expire peers. More...
 
const char * p2p_get_state_txt (struct p2p_data *p2p)
 Get current P2P state for debug purposes. More...
 
struct p2ps_advertisementp2p_get_p2ps_adv_list (struct p2p_data *p2p)
 
void p2p_set_intended_addr (struct p2p_data *p2p, const u8 *intended_addr)
 
u16 p2p_get_provisioning_info (struct p2p_data *p2p, const u8 *addr)
 Get any stored provisioning info. More...
 
void p2p_clear_provisioning_info (struct p2p_data *p2p, const u8 *addr)
 Clear any stored provisioning info. More...
 
void p2p_set_state (struct p2p_data *p2p, int new_state)
 
void p2p_set_timeout (struct p2p_data *p2p, unsigned int sec, unsigned int usec)
 
void p2p_clear_timeout (struct p2p_data *p2p)
 
void p2p_go_neg_failed (struct p2p_data *p2p, int status)
 
int p2p_listen (struct p2p_data *p2p, unsigned int timeout)
 Start P2P Listen state for specified duration. More...
 
struct p2p_devicep2p_get_device (struct p2p_data *p2p, const u8 *addr)
 Fetch a peer entry. More...
 
struct p2p_devicep2p_get_device_interface (struct p2p_data *p2p, const u8 *addr)
 Fetch a peer entry based on P2P Interface Address. More...
 
int p2p_add_device (struct p2p_data *p2p, const u8 *addr, int freq, struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len, int scan_res)
 Add peer entries based on scan results or P2P frames. More...
 
void p2p_notify_scan_trigger_status (struct p2p_data *p2p, int status)
 Indicate scan trigger status. More...
 
int p2p_find (struct p2p_data *p2p, unsigned int timeout, enum p2p_discovery_type type, unsigned int num_req_dev_types, const u8 *req_dev_types, const u8 *dev_id, unsigned int search_delay, u8 seek_count, const char **seek, int freq)
 Start P2P Find (Device Discovery) More...
 
void p2p_stop_find_for_freq (struct p2p_data *p2p, int freq)
 Stop P2P Find for next oper on specific freq. More...
 
void p2p_stop_listen_for_freq (struct p2p_data *p2p, int freq)
 
void p2p_stop_listen (struct p2p_data *p2p)
 Stop P2P Listen. More...
 
void p2p_stop_find (struct p2p_data *p2p)
 Stop P2P Find (Device Discovery) More...
 
int p2p_prepare_channel (struct p2p_data *p2p, struct p2p_device *dev, unsigned int force_freq, unsigned int pref_freq, int go)
 Select operating channel for GO Negotiation. More...
 
int p2p_connect (struct p2p_data *p2p, const u8 *peer_addr, enum p2p_wps_method wps_method, int go_intent, const u8 *own_interface_addr, unsigned int force_freq, int persistent_group, const u8 *force_ssid, size_t force_ssid_len, int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id)
 Start P2P group formation (GO negotiation) More...
 
int p2p_authorize (struct p2p_data *p2p, const u8 *peer_addr, enum p2p_wps_method wps_method, int go_intent, const u8 *own_interface_addr, unsigned int force_freq, int persistent_group, const u8 *force_ssid, size_t force_ssid_len, unsigned int pref_freq, u16 oob_pw_id)
 Authorize P2P group formation (GO negotiation) More...
 
void p2p_add_dev_info (struct p2p_data *p2p, const u8 *addr, struct p2p_device *dev, struct p2p_message *msg)
 
void p2p_build_ssid (struct p2p_data *p2p, u8 *ssid, size_t *ssid_len)
 
int p2p_go_params (struct p2p_data *p2p, struct p2p_go_neg_results *params)
 Generate random P2P group parameters. More...
 
void p2p_go_complete (struct p2p_data *p2p, struct p2p_device *peer)
 
void p2p_rx_action (struct p2p_data *p2p, const u8 *da, const u8 *sa, const u8 *bssid, u8 category, const u8 *data, size_t len, int freq)
 Report received Action frame. More...
 
struct p2p_devicep2p_add_dev_from_go_neg_req (struct p2p_data *p2p, const u8 *addr, struct p2p_message *msg)
 
int dev_type_list_match (const u8 *dev_type, const u8 *req_dev_type[], size_t num_req_dev_type)
 
int p2p_match_dev_type (struct p2p_data *p2p, struct wpabuf *wps)
 Match local device type with requested type. More...
 
struct wpabufp2p_build_probe_resp_ies (struct p2p_data *p2p, const u8 *query_hash, u8 query_count)
 
enum p2p_probe_req_status p2p_probe_req_rx (struct p2p_data *p2p, const u8 *addr, const u8 *dst, const u8 *bssid, const u8 *ie, size_t ie_len, unsigned int rx_freq)
 Report reception of a Probe Request frame. More...
 
int p2p_assoc_req_ie (struct p2p_data *p2p, const u8 *bssid, u8 *buf, size_t len, int p2p_group, struct wpabuf *p2p_ie)
 Build P2P IE for (Re)Association Request frame. More...
 
int p2p_scan_result_text (const u8 *ies, size_t ies_len, char *buf, char *end)
 Build text format description of P2P IE. More...
 
struct p2ps_advertisementp2p_service_p2ps_id (struct p2p_data *p2p, u32 adv_id)
 
int p2p_service_del_asp (struct p2p_data *p2p, u32 adv_id)
 
int p2p_service_add_asp (struct p2p_data *p2p, int auto_accept, u32 adv_id, const char *adv_str, u8 svc_state, u16 config_methods, const char *svc_info, const u8 *cpt_priority)
 
void p2p_service_flush_asp (struct p2p_data *p2p)
 
int p2p_parse_dev_addr_in_p2p_ie (struct wpabuf *p2p_ie, u8 *dev_addr)
 Parse P2P Device Address from a concatenated P2P IE. More...
 
int p2p_parse_dev_addr (const u8 *ies, size_t ies_len, u8 *dev_addr)
 Parse P2P Device Address from P2P IE(s) More...
 
void p2p_wps_success_cb (struct p2p_data *p2p, const u8 *mac_addr)
 Report successfully completed WPS provisioning. More...
 
void p2p_group_formation_failed (struct p2p_data *p2p)
 Report failed WPS provisioning. More...
 
struct p2p_datap2p_init (const struct p2p_config *cfg)
 Initialize P2P module. More...
 
void p2p_deinit (struct p2p_data *p2p)
 Deinitialize P2P module. More...
 
void p2p_flush (struct p2p_data *p2p)
 Flush P2P module state. More...
 
int p2p_unauthorize (struct p2p_data *p2p, const u8 *addr)
 Unauthorize the specified peer device. More...
 
int p2p_set_dev_name (struct p2p_data *p2p, const char *dev_name)
 Set device name. More...
 
int p2p_set_manufacturer (struct p2p_data *p2p, const char *manufacturer)
 
int p2p_set_model_name (struct p2p_data *p2p, const char *model_name)
 
int p2p_set_model_number (struct p2p_data *p2p, const char *model_number)
 
int p2p_set_serial_number (struct p2p_data *p2p, const char *serial_number)
 
void p2p_set_config_methods (struct p2p_data *p2p, u16 config_methods)
 
void p2p_set_uuid (struct p2p_data *p2p, const u8 *uuid)
 
int p2p_set_pri_dev_type (struct p2p_data *p2p, const u8 *pri_dev_type)
 Set primary device type. More...
 
int p2p_set_sec_dev_types (struct p2p_data *p2p, const u8 dev_types[][8], size_t num_dev_types)
 Set secondary device types. More...
 
void p2p_remove_wps_vendor_extensions (struct p2p_data *p2p)
 Remove WPS vendor extensions. More...
 
int p2p_add_wps_vendor_extension (struct p2p_data *p2p, const struct wpabuf *vendor_ext)
 Add a WPS vendor extension. More...
 
int p2p_set_country (struct p2p_data *p2p, const char *country)
 
void p2p_continue_find (struct p2p_data *p2p)
 
int p2p_scan_res_handler (struct p2p_data *p2p, const u8 *bssid, int freq, struct os_reltime *rx_time, int level, const u8 *ies, size_t ies_len)
 Indicate a P2P scan results. More...
 
void p2p_scan_res_handled (struct p2p_data *p2p)
 Indicate end of scan results. More...
 
void p2p_scan_ie (struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id)
 Build P2P IE for Probe Request. More...
 
size_t p2p_scan_ie_buf_len (struct p2p_data *p2p)
 Get maximum buffer length needed for p2p_scan_ie. More...
 
int p2p_ie_text (struct wpabuf *p2p_ie, char *buf, char *end)
 Build text format description of P2P IE. More...
 
void p2p_send_action_cb (struct p2p_data *p2p, unsigned int freq, const u8 *dst, const u8 *src, const u8 *bssid, enum p2p_send_action_result result)
 Notify TX status of an Action frame. More...
 
void p2p_listen_cb (struct p2p_data *p2p, unsigned int freq, unsigned int duration)
 Indicate the start of a requested Listen state. More...
 
int p2p_listen_end (struct p2p_data *p2p, unsigned int freq)
 Indicate the end of a requested Listen state. More...
 
int p2p_reject (struct p2p_data *p2p, const u8 *peer_addr)
 Reject peer device (explicitly block connection attempts) More...
 
const char * p2p_wps_method_text (enum p2p_wps_method method)
 
const struct p2p_peer_infop2p_get_peer_info (struct p2p_data *p2p, const u8 *addr, int next)
 Get P2P peer information. More...
 
int p2p_get_peer_info_txt (const struct p2p_peer_info *info, char *buf, size_t buflen)
 Get internal P2P peer information in text format. More...
 
int p2p_peer_known (struct p2p_data *p2p, const u8 *addr)
 Check whether P2P peer is known. More...
 
void p2p_set_client_discoverability (struct p2p_data *p2p, int enabled)
 Set client discoverability capability. More...
 
int p2p_presence_req (struct p2p_data *p2p, const u8 *go_interface_addr, const u8 *own_interface_addr, unsigned int freq, u32 duration1, u32 interval1, u32 duration2, u32 interval2)
 Request GO presence. More...
 
int p2p_ext_listen (struct p2p_data *p2p, unsigned int period, unsigned int interval)
 Set Extended Listen Timing. More...
 
void p2p_deauth_notif (struct p2p_data *p2p, const u8 *bssid, u16 reason_code, const u8 *ie, size_t ie_len)
 
void p2p_disassoc_notif (struct p2p_data *p2p, const u8 *bssid, u16 reason_code, const u8 *ie, size_t ie_len)
 
void p2p_set_managed_oper (struct p2p_data *p2p, int enabled)
 Set managed P2P Device operations capability. More...
 
int p2p_config_get_random_social (struct p2p_config *p2p, u8 *op_class, u8 *op_channel)
 Return a random social channel. More...
 
int p2p_set_listen_channel (struct p2p_data *p2p, u8 reg_class, u8 channel, u8 forced)
 
u8 p2p_get_listen_channel (struct p2p_data *p2p)
 
int p2p_set_ssid_postfix (struct p2p_data *p2p, const u8 *postfix, size_t len)
 
int p2p_set_oper_channel (struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, int cfg_op_channel)
 Set the P2P operating channel. More...
 
int p2p_set_pref_chan (struct p2p_data *p2p, unsigned int num_pref_chan, const struct p2p_channel *pref_chan)
 Set P2P preferred channel list. More...
 
int p2p_set_no_go_freq (struct p2p_data *p2p, const struct wpa_freq_range_list *list)
 Set no GO channel ranges. More...
 
int p2p_get_interface_addr (struct p2p_data *p2p, const u8 *dev_addr, u8 *iface_addr)
 
int p2p_get_dev_addr (struct p2p_data *p2p, const u8 *iface_addr, u8 *dev_addr)
 
void p2p_set_peer_filter (struct p2p_data *p2p, const u8 *addr)
 
void p2p_set_cross_connect (struct p2p_data *p2p, int enabled)
 Set cross connection capability. More...
 
int p2p_get_oper_freq (struct p2p_data *p2p, const u8 *iface_addr)
 
void p2p_set_intra_bss_dist (struct p2p_data *p2p, int enabled)
 Set intra BSS distribution. More...
 
void p2p_update_channel_list (struct p2p_data *p2p, const struct p2p_channels *chan, const struct p2p_channels *cli_chan)
 
int p2p_send_action (struct p2p_data *p2p, unsigned int freq, const u8 *dst, const u8 *src, const u8 *bssid, const u8 *buf, size_t len, unsigned int wait_time)
 
void p2p_set_best_channels (struct p2p_data *p2p, int freq_24, int freq_5, int freq_overall)
 Update best channel information. More...
 
void p2p_set_own_freq_preference (struct p2p_data *p2p, int freq)
 Set own preference for channel. More...
 
const u8 * p2p_get_go_neg_peer (struct p2p_data *p2p)
 
const struct p2p_peer_infop2p_get_peer_found (struct p2p_data *p2p, const u8 *addr, int next)
 Get P2P peer info structure of a found peer. More...
 
int p2p_in_progress (struct p2p_data *p2p)
 Check whether a P2P operation is progress. More...
 
void p2p_set_config_timeout (struct p2p_data *p2p, u8 go_timeout, u8 client_timeout)
 Set local config timeouts. More...
 
int p2p_set_disc_int (struct p2p_data *p2p, int min_disc_int, int max_disc_int, int max_disc_tu)
 Set min/max discoverable interval for p2p_find. More...
 
void p2p_dbg (struct p2p_data *p2p, const char *fmt,...)
 
void p2p_info (struct p2p_data *p2p, const char *fmt,...)
 
void p2p_err (struct p2p_data *p2p, const char *fmt,...)
 
void p2p_loop_on_known_peers (struct p2p_data *p2p, void(*peer_callback)(struct p2p_peer_info *peer, void *user_data), void *user_data)
 
int p2p_set_passphrase_len (struct p2p_data *p2p, unsigned int len)
 
void p2p_set_vendor_elems (struct p2p_data *p2p, struct wpabuf **vendor_elem)
 
void p2p_go_neg_wait_timeout (void *eloop_ctx, void *timeout_ctx)
 
void p2p_set_own_pref_freq_list (struct p2p_data *p2p, const unsigned int *pref_freq_list, unsigned int size)
 

Detailed Description

Wi-Fi Direct - P2P module.

Function Documentation

int p2p_add_device ( struct p2p_data p2p,
const u8 *  addr,
int  freq,
struct os_reltime rx_time,
int  level,
const u8 *  ies,
size_t  ies_len,
int  scan_res 
)

Add peer entries based on scan results or P2P frames.

Parameters
p2pP2P module context from p2p_init()
addrSource address of Beacon or Probe Response frame (may be either P2P Device Address or P2P Interface Address)
levelSignal level (signal strength of the received frame from the peer)
freqFrequency on which the Beacon or Probe Response frame was received
rx_timeTime when the result was received
iesIEs from the Beacon or Probe Response frame
ies_lenLength of ies buffer in octets
scan_resWhether this was based on scan results
Returns
0 on success, -1 on failure

If the scan result is for a GO, the clients in the group will also be added to the peer table. This function can also be used with some other frames like Provision Discovery Request that contains P2P Capability and P2P Device Info attributes.

int p2p_add_wps_vendor_extension ( struct p2p_data p2p,
const struct wpabuf vendor_ext 
)

Add a WPS vendor extension.

Parameters
p2pP2P module context from p2p_init()
vendor_extThe vendor extensions to add
Returns
0 on success, -1 on failure

The wpabuf structures in the array are owned by the P2P module after this call.

int p2p_assoc_req_ie ( struct p2p_data p2p,
const u8 *  bssid,
u8 *  buf,
size_t  len,
int  p2p_group,
struct wpabuf p2p_ie 
)

Build P2P IE for (Re)Association Request frame.

Parameters
p2pP2P module context from p2p_init()
bssidBSSID
bufBuffer for writing the P2P IE
lenMaximum buf length in octets
p2p_groupWhether this is for association with a P2P GO
p2p_ieReassembled P2P IE data from scan results or NULL if none
Returns
Number of octets written into buf or -1 on failure
int p2p_authorize ( struct p2p_data p2p,
const u8 *  peer_addr,
enum p2p_wps_method  wps_method,
int  go_intent,
const u8 *  own_interface_addr,
unsigned int  force_freq,
int  persistent_group,
const u8 *  force_ssid,
size_t  force_ssid_len,
unsigned int  pref_freq,
u16  oob_pw_id 
)

Authorize P2P group formation (GO negotiation)

Parameters
p2pP2P module context from p2p_init()
peer_addrMAC address of the peer P2P client
wps_methodWPS method to be used in provisioning
go_intentLocal GO intent value (1..15)
own_interface_addrIntended interface address to use with the group
force_freqThe only allowed channel frequency in MHz or 0
persistent_groupWhether to create a persistent group (0 = no, 1 = persistent group without persistent reconnect, 2 = persistent group with persistent reconnect)
force_ssidForced SSID for the group if we become GO or NULL to generate a new SSID
force_ssid_lenLength of $force_ssid buffer
pref_freqPreferred operating frequency in MHz or 0 (this is only used if force_freq == 0)
Returns
0 on success, -1 on failure

This is like p2p_connect(), but the actual group negotiation is not initiated automatically, i.e., the other end is expected to do that.

void p2p_clear_provisioning_info ( struct p2p_data p2p,
const u8 *  addr 
)

Clear any stored provisioning info.

Parameters
p2pP2P module context from p2p_init()
iface_addrPeer P2P Device Address

This function is used to clear stored WPS provisioning info for the given peer.

int p2p_config_get_random_social ( struct p2p_config p2p,
u8 *  op_class,
u8 *  op_channel 
)

Return a random social channel.

Parameters
p2pP2P config
op_classSelected operating class
op_channelSelected social channel
Returns
0 on success, -1 on failure

This function is used before p2p_init is called. A random social channel from supports bands 2.4 GHz (channels 1,6,11) and 60 GHz (channel 2) is returned on success.

int p2p_connect ( struct p2p_data p2p,
const u8 *  peer_addr,
enum p2p_wps_method  wps_method,
int  go_intent,
const u8 *  own_interface_addr,
unsigned int  force_freq,
int  persistent_group,
const u8 *  force_ssid,
size_t  force_ssid_len,
int  pd_before_go_neg,
unsigned int  pref_freq,
u16  oob_pw_id 
)

Start P2P group formation (GO negotiation)

Parameters
p2pP2P module context from p2p_init()
peer_addrMAC address of the peer P2P client
wps_methodWPS method to be used in provisioning
go_intentLocal GO intent value (1..15)
own_interface_addrIntended interface address to use with the group
force_freqThe only allowed channel frequency in MHz or 0
persistent_groupWhether to create a persistent group (0 = no, 1 = persistent group without persistent reconnect, 2 = persistent group with persistent reconnect)
force_ssidForced SSID for the group if we become GO or NULL to generate a new SSID
force_ssid_lenLength of $force_ssid buffer
pd_before_go_negWhether to send Provision Discovery prior to GO Negotiation as an interoperability workaround when initiating group formation
pref_freqPreferred operating frequency in MHz or 0 (this is only used if force_freq == 0)
Returns
0 on success, -1 on failure
void p2p_deinit ( struct p2p_data p2p)

Deinitialize P2P module.

Parameters
p2pP2P module context from p2p_init()
void p2p_expire_peers ( struct p2p_data p2p)

Periodic cleanup function to expire peers.

Parameters
p2pP2P module context from p2p_init()

This is a cleanup function that the entity calling p2p_init() is expected to call periodically to clean up expired peer entries.

int p2p_ext_listen ( struct p2p_data p2p,
unsigned int  period,
unsigned int  interval 
)

Set Extended Listen Timing.

Parameters
p2pP2P module context from p2p_init()
freqGroup operating frequence (in MHz)
periodAvailability period in milliseconds (1-65535; 0 to disable)
intervalAvailability interval in milliseconds (1-65535; 0 to disable)
Returns
0 on success, -1 on failure

This function can be used to enable or disable (period = interval = 0) Extended Listen Timing. When enabled, the P2P Device will become discoverable (go into Listen State) every interval milliseconds for at least period milliseconds.

int p2p_find ( struct p2p_data p2p,
unsigned int  timeout,
enum p2p_discovery_type  type,
unsigned int  num_req_dev_types,
const u8 *  req_dev_types,
const u8 *  dev_id,
unsigned int  search_delay,
u8  seek_count,
const char **  seek_string,
int  freq 
)

Start P2P Find (Device Discovery)

Parameters
p2pP2P module context from p2p_init()
timeoutTimeout for find operation in seconds or 0 for no timeout
typeDevice Discovery type
num_req_dev_typesNumber of requested device types
req_dev_typesRequested device types array, must be an array containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; NULL if no requested device types.
dev_idDevice ID to search for or NULL to find all devices
search_delayExtra delay in milliseconds between search iterations
seek_countNumber of ASP Service Strings in the seek_string array
seek_stringASP Service Strings to query for in Probe Requests
freqRequested first scan frequency (in MHz) to modify type == P2P_FIND_START_WITH_FULL behavior. 0 = Use normal full scan. If p2p_find is already in progress, this parameter is ignored and full scan will be executed.
Returns
0 on success, -1 on failure
void p2p_flush ( struct p2p_data p2p)

Flush P2P module state.

Parameters
p2pP2P module context from p2p_init()

This command removes the P2P module state like peer device entries.

struct p2p_device* p2p_get_device ( struct p2p_data p2p,
const u8 *  addr 
)

Fetch a peer entry.

Parameters
p2pP2P module context from p2p_init()
addrP2P Device Address of the peer
Returns
Pointer to the device entry or NULL if not found
struct p2p_device* p2p_get_device_interface ( struct p2p_data p2p,
const u8 *  addr 
)

Fetch a peer entry based on P2P Interface Address.

Parameters
p2pP2P module context from p2p_init()
addrP2P Interface Address of the peer
Returns
Pointer to the device entry or NULL if not found
const struct p2p_peer_info* p2p_get_peer_found ( struct p2p_data p2p,
const u8 *  addr,
int  next 
)

Get P2P peer info structure of a found peer.

Parameters
p2pP2P module context from p2p_init()
addrP2P Device Address of the peer or NULL to indicate the first peer
nextWhether to select the peer entry following the one indicated by addr
Returns
The first P2P peer info available or NULL if no such peer exists
const struct p2p_peer_info* p2p_get_peer_info ( struct p2p_data p2p,
const u8 *  addr,
int  next 
)

Get P2P peer information.

Parameters
p2pP2P module context from p2p_init()
addrP2P Device Address of the peer or NULL to indicate the first peer
nextWhether to select the peer entry following the one indicated by addr
Returns
Pointer to peer info or NULL if not found
int p2p_get_peer_info_txt ( const struct p2p_peer_info info,
char *  buf,
size_t  buflen 
)

Get internal P2P peer information in text format.

Parameters
infoPointer to P2P peer info from p2p_get_peer_info()
bufBuffer for returning text
buflenMaximum buffer length
Returns
Number of octets written to the buffer or -1 on failure

Note: This information is internal to the P2P module and subject to change. As such, this should not really be used by external programs for purposes other than debugging.

u16 p2p_get_provisioning_info ( struct p2p_data p2p,
const u8 *  addr 
)

Get any stored provisioning info.

Parameters
p2pP2P module context from p2p_init()
addrPeer P2P Device Address
Returns
WPS provisioning information (WPS config method) or 0 if no information is available

This function is used to retrieve stored WPS provisioning info for the given peer.

const char* p2p_get_state_txt ( struct p2p_data p2p)

Get current P2P state for debug purposes.

Parameters
p2pP2P module context from p2p_init()
Returns
Name of the current P2P module state

It should be noted that the P2P module state names are internal information and subject to change at any point, i.e., this information should be used mainly for debugging purposes.

int p2p_go_params ( struct p2p_data p2p,
struct p2p_go_neg_results params 
)

Generate random P2P group parameters.

Parameters
p2pP2P module context from p2p_init()
paramsBuffer for parameters
Returns
0 on success, -1 on failure
void p2p_group_formation_failed ( struct p2p_data p2p)

Report failed WPS provisioning.

Parameters
p2pP2P module context from p2p_init()

This function is used to report failed group formation. This can happen either due to failed WPS provisioning or due to 15 second timeout during the provisioning phase.

int p2p_ie_text ( struct wpabuf p2p_ie,
char *  buf,
char *  end 
)

Build text format description of P2P IE.

Parameters
p2p_ieP2P IE
bufBuffer for returning text
endPointer to the end of the buf area
Returns
Number of octets written to the buffer or -1 on failure

This function can be used to parse P2P IE contents into text format field=value lines.

int p2p_in_progress ( struct p2p_data p2p)

Check whether a P2P operation is progress.

Parameters
p2pP2P module context from p2p_init()
Returns
0 if P2P module is idle, 1 if an operation is in progress but not in search state, or 2 if search state operation is in progress
struct p2p_data* p2p_init ( const struct p2p_config cfg)

Initialize P2P module.

Parameters
cfgP2P module configuration
Returns
Pointer to private data or NULL on failure

This function is used to initialize global P2P module context (one per device). The P2P module will keep a copy of the configuration data, so the caller does not need to maintain this structure. However, the callback functions and the context parameters to them must be kept available until the P2P module is deinitialized with p2p_deinit().

int p2p_listen ( struct p2p_data p2p,
unsigned int  timeout 
)

Start P2P Listen state for specified duration.

Parameters
p2pP2P module context from p2p_init()
timeoutListen state duration in milliseconds
Returns
0 on success, -1 on failure

This function can be used to request the P2P module to keep the device discoverable on the listen channel for an extended set of time. At least in its current form, this is mainly used for testing purposes and may not be of much use for normal P2P operations.

void p2p_listen_cb ( struct p2p_data p2p,
unsigned int  freq,
unsigned int  duration 
)

Indicate the start of a requested Listen state.

Parameters
p2pP2P module context from p2p_init()
freqListen channel frequency in MHz
durationDuration for the Listen state in milliseconds

This function is used to indicate that a Listen state requested with struct p2p_config::start_listen() callback has started.

int p2p_listen_end ( struct p2p_data p2p,
unsigned int  freq 
)

Indicate the end of a requested Listen state.

Parameters
p2pP2P module context from p2p_init()
freqListen channel frequency in MHz
Returns
0 if no operations were started, 1 if an operation was started

This function is used to indicate that a Listen state requested with struct p2p_config::start_listen() callback has ended.

int p2p_match_dev_type ( struct p2p_data p2p,
struct wpabuf wps 
)

Match local device type with requested type.

Parameters
p2pP2P module context from p2p_init()
wpsWPS TLVs from Probe Request frame (concatenated WPS IEs)
Returns
1 on match, 0 on mismatch

This function can be used to match the Requested Device Type attribute in WPS IE with the local device types for deciding whether to reply to a Probe Request frame.

void p2p_notify_scan_trigger_status ( struct p2p_data p2p,
int  status 
)

Indicate scan trigger status.

Parameters
p2pP2P module context from p2p_init()
status0 on success, -1 on failure
int p2p_parse_dev_addr ( const u8 *  ies,
size_t  ies_len,
u8 *  dev_addr 
)

Parse P2P Device Address from P2P IE(s)

Parameters
iesInformation elements from scan results
ies_lenies buffer length in octets
dev_addrBuffer for returning P2P Device Address
Returns
0 on success or -1 if P2P Device Address could not be parsed
int p2p_parse_dev_addr_in_p2p_ie ( struct wpabuf p2p_ie,
u8 *  dev_addr 
)

Parse P2P Device Address from a concatenated P2P IE.

Parameters
p2p_ieP2P IE
dev_addrBuffer for returning P2P Device Address
Returns
0 on success or -1 if P2P Device Address could not be parsed
int p2p_peer_known ( struct p2p_data p2p,
const u8 *  addr 
)

Check whether P2P peer is known.

Parameters
p2pP2P module context from p2p_init()
addrP2P Device Address of the peer
Returns
1 if the specified device is in the P2P peer table or 0 if not
int p2p_prepare_channel ( struct p2p_data p2p,
struct p2p_device dev,
unsigned int  force_freq,
unsigned int  pref_freq,
int  go 
)

Select operating channel for GO Negotiation.

Parameters
p2pP2P module context from p2p_init()
devSelected peer device
force_freqForced frequency in MHz or 0 if not forced
pref_freqPreferred frequency in MHz or 0 if no preference
goWhether the local end will be forced to be GO
Returns
0 on success, -1 on failure (channel not supported for P2P)

This function is used to do initial operating channel selection for GO Negotiation prior to having received peer information. The selected channel may be further optimized in p2p_reselect_channel() once the peer information is available.

int p2p_presence_req ( struct p2p_data p2p,
const u8 *  go_interface_addr,
const u8 *  own_interface_addr,
unsigned int  freq,
u32  duration1,
u32  interval1,
u32  duration2,
u32  interval2 
)

Request GO presence.

Parameters
p2pP2P module context from p2p_init()
go_interface_addrGO P2P Interface Address
own_interface_addrOwn P2P Interface Address for this group
freqGroup operating frequence (in MHz)
duration1Preferred presence duration in microseconds
interval1Preferred presence interval in microseconds
duration2Acceptable presence duration in microseconds
interval2Acceptable presence interval in microseconds
Returns
0 on success, -1 on failure

If both duration and interval values are zero, the parameter pair is not specified (i.e., to remove Presence Request, use duration1 = interval1 = 0).

enum p2p_probe_req_status p2p_probe_req_rx ( struct p2p_data p2p,
const u8 *  addr,
const u8 *  dst,
const u8 *  bssid,
const u8 *  ie,
size_t  ie_len,
unsigned int  rx_freq 
)

Report reception of a Probe Request frame.

Parameters
p2pP2P module context from p2p_init()
addrSource MAC address
dstDestination MAC address if available or NULL
bssidBSSID if available or NULL
ieInformation elements from the Probe Request frame body
ie_lenLength of ie buffer in octets
rx_freqProbe Request frame RX frequency
Returns
value indicating the type and status of the probe request
int p2p_reject ( struct p2p_data p2p,
const u8 *  peer_addr 
)

Reject peer device (explicitly block connection attempts)

Parameters
p2pP2P module context from p2p_init()
peer_addrMAC address of the peer P2P client
Returns
0 on success, -1 on failure
void p2p_remove_wps_vendor_extensions ( struct p2p_data p2p)

Remove WPS vendor extensions.

Parameters
p2pP2P module context from p2p_init()
void p2p_rx_action ( struct p2p_data p2p,
const u8 *  da,
const u8 *  sa,
const u8 *  bssid,
u8  category,
const u8 *  data,
size_t  len,
int  freq 
)

Report received Action frame.

Parameters
p2pP2P module context from p2p_init()
daDestination address of the received Action frame
saSource address of the received Action frame
bssidAddress 3 of the received Action frame
categoryCategory of the received Action frame
dataAction frame body after the Category field
lenLength of the data buffer in octets
freqFrequency (in MHz) on which the frame was received
void p2p_scan_ie ( struct p2p_data p2p,
struct wpabuf ies,
const u8 *  dev_id 
)

Build P2P IE for Probe Request.

Parameters
p2pP2P module context from p2p_init()
iesBuffer for writing P2P IE
dev_idDevice ID to search for or NULL for any
size_t p2p_scan_ie_buf_len ( struct p2p_data p2p)

Get maximum buffer length needed for p2p_scan_ie.

Parameters
p2pP2P module context from p2p_init()
Returns
Number of octets that p2p_scan_ie() may add to the buffer
void p2p_scan_res_handled ( struct p2p_data p2p)

Indicate end of scan results.

Parameters
p2pP2P module context from p2p_init()

This function is called to indicate that all P2P scan results from a scan have been reported with zero or more calls to p2p_scan_res_handler(). This function must be called as a response to successful struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler() calls stopped iteration.

int p2p_scan_res_handler ( struct p2p_data p2p,
const u8 *  bssid,
int  freq,
struct os_reltime rx_time,
int  level,
const u8 *  ies,
size_t  ies_len 
)

Indicate a P2P scan results.

Parameters
p2pP2P module context from p2p_init()
bssidBSSID of the scan result
freqFrequency of the channel on which the device was found in MHz
rx_timeTime when the result was received
levelSignal level (signal strength of the received Beacon/Probe Response frame)
iesPointer to IEs from the scan result
ies_lenLength of the ies buffer
Returns
0 to continue or 1 to stop scan result indication

This function is called to indicate a scan result entry with P2P IE from a scan requested with struct p2p_config::p2p_scan(). This can be called during the actual scan process (i.e., whenever a new device is found) or as a sequence of calls after the full scan has been completed. The former option can result in optimized operations, but may not be supported by all driver/firmware designs. The ies buffer need to include at least the P2P IE, but it is recommended to include all IEs received from the device. The caller does not need to check that the IEs contain a P2P IE before calling this function since frames will be filtered internally if needed.

This function will return 1 if it wants to stop scan result iteration (and scan in general if it is still in progress). This is used to allow faster start of a pending operation, e.g., to start a pending GO negotiation.

int p2p_scan_result_text ( const u8 *  ies,
size_t  ies_len,
char *  buf,
char *  end 
)

Build text format description of P2P IE.

Parameters
iesInformation elements from scan results
ies_lenies buffer length in octets
bufBuffer for returning text
endPointer to the end of the buf area
Returns
Number of octets written to the buffer or -1 on failure

This function can be used to parse P2P IE contents into text format field=value lines.

void p2p_send_action_cb ( struct p2p_data p2p,
unsigned int  freq,
const u8 *  dst,
const u8 *  src,
const u8 *  bssid,
enum p2p_send_action_result  result 
)

Notify TX status of an Action frame.

Parameters
p2pP2P module context from p2p_init()
freqChannel frequency in MHz
dstDestination MAC address (Address 1)
srcSource MAC address (Address 2)
bssidBSSID (Address 3)
resultResult of the transmission attempt

This function is used to indicate the result of an Action frame transmission that was requested with struct p2p_config::send_action() callback.

void p2p_set_best_channels ( struct p2p_data p2p,
int  freq_24,
int  freq_5,
int  freq_overall 
)

Update best channel information.

Parameters
p2pP2P module context from p2p_init()
freq_24Frequency (MHz) of best channel in 2.4 GHz band
freq_5Frequency (MHz) of best channel in 5 GHz band
freq_overallFrequency (MHz) of best channel overall
void p2p_set_client_discoverability ( struct p2p_data p2p,
int  enabled 
)

Set client discoverability capability.

Parameters
p2pP2P module context from p2p_init()
enabledWhether client discoverability will be enabled

This function can be used to disable (and re-enable) client discoverability. This capability is enabled by default and should not be disabled in normal use cases, i.e., this is mainly for testing purposes.

void p2p_set_config_timeout ( struct p2p_data p2p,
u8  go_timeout,
u8  client_timeout 
)

Set local config timeouts.

Parameters
p2pP2P module context from p2p_init()
go_timeoutTime in 10 ms units it takes to start the GO mode
client_timeoutTime in 10 ms units it takes to start the client mode
void p2p_set_cross_connect ( struct p2p_data p2p,
int  enabled 
)

Set cross connection capability.

Parameters
p2pP2P module context from p2p_init()
enabledWhether cross connection will be enabled
int p2p_set_dev_name ( struct p2p_data p2p,
const char *  dev_name 
)

Set device name.

Parameters
p2pP2P module context from p2p_init()
Returns
0 on success, -1 on failure

This function can be used to update the P2P module configuration with information that was not available at the time of the p2p_init() call.

int p2p_set_disc_int ( struct p2p_data p2p,
int  min_disc_int,
int  max_disc_int,
int  max_disc_tu 
)

Set min/max discoverable interval for p2p_find.

Parameters
p2pP2P module context from p2p_init()
min_disc_intminDiscoverableInterval (in units of 100 TU); default 1
max_disc_intmaxDiscoverableInterval (in units of 100 TU); default 3
max_disc_tuMaximum number of TUs (1.024 ms) for discoverable interval; or -1 not to limit
Returns
0 on success, or -1 on failure

This function can be used to configure minDiscoverableInterval and maxDiscoverableInterval parameters for the Listen state during device discovery (p2p_find). A random number of 100 TU units is picked for each Listen state iteration from [min_disc_int,max_disc_int] range.

max_disc_tu can be used to futher limit the discoverable duration. However, it should be noted that use of this parameter is not recommended since it would not be compliant with the P2P specification.

void p2p_set_intra_bss_dist ( struct p2p_data p2p,
int  enabled 
)

Set intra BSS distribution.

Parameters
p2pP2P module context from p2p_init()
enabledWhether intra BSS distribution will be enabled
void p2p_set_managed_oper ( struct p2p_data p2p,
int  enabled 
)

Set managed P2P Device operations capability.

Parameters
p2pP2P module context from p2p_init()
enabledWhether managed P2P Device operations will be enabled
int p2p_set_no_go_freq ( struct p2p_data p2p,
const struct wpa_freq_range_list list 
)

Set no GO channel ranges.

Parameters
p2pP2P module context from p2p_init()
listChannel ranges or NULL to remove restriction
Returns
0 on success, -1 on failure
int p2p_set_oper_channel ( struct p2p_data p2p,
u8  op_reg_class,
u8  op_channel,
int  cfg_op_channel 
)

Set the P2P operating channel.

Parameters
p2pP2P module context from p2p_init()
op_reg_classOperating regulatory class to set
op_channeloperating channel to set
cfg_op_channel: Whether op_channel is hardcoded in configuration
Returns
0 on success, -1 on failure
void p2p_set_own_freq_preference ( struct p2p_data p2p,
int  freq 
)

Set own preference for channel.

Parameters
p2pP2P module context from p2p_init()
freqFrequency (MHz) of the preferred channel or 0 if no preference

This function can be used to set a preference on the operating channel based on frequencies used on the other virtual interfaces that share the same radio. If non-zero, this is used to try to avoid multi-channel concurrency.

int p2p_set_pref_chan ( struct p2p_data p2p,
unsigned int  num_pref_chan,
const struct p2p_channel pref_chan 
)

Set P2P preferred channel list.

Parameters
p2pP2P module context from p2p_init()
num_pref_chanNumber of entries in pref_chan list
pref_chanPreferred channels or NULL to remove preferences
Returns
0 on success, -1 on failure
int p2p_set_pri_dev_type ( struct p2p_data p2p,
const u8 *  pri_dev_type 
)

Set primary device type.

Parameters
p2pP2P module context from p2p_init()
Returns
0 on success, -1 on failure

This function can be used to update the P2P module configuration with information that was not available at the time of the p2p_init() call.

int p2p_set_sec_dev_types ( struct p2p_data p2p,
const u8  dev_types[][8],
size_t  num_dev_types 
)

Set secondary device types.

Parameters
p2pP2P module context from p2p_init()
Returns
0 on success, -1 on failure

This function can be used to update the P2P module configuration with information that was not available at the time of the p2p_init() call.

void p2p_stop_find ( struct p2p_data p2p)

Stop P2P Find (Device Discovery)

Parameters
p2pP2P module context from p2p_init()
void p2p_stop_find_for_freq ( struct p2p_data p2p,
int  freq 
)

Stop P2P Find for next oper on specific freq.

Parameters
p2pP2P module context from p2p_init()
freqFrequency in MHz for next operation

This is like p2p_stop_find(), but Listen state is not stopped if we are already on the same frequency.

void p2p_stop_listen ( struct p2p_data p2p)

Stop P2P Listen.

Parameters
p2pP2P module context from p2p_init()
int p2p_unauthorize ( struct p2p_data p2p,
const u8 *  addr 
)

Unauthorize the specified peer device.

Parameters
p2pP2P module context from p2p_init()
addrP2P peer entry to be unauthorized
Returns
0 on success, -1 on failure

This command removes any connection authorization from the specified P2P peer device address. This can be used, e.g., to cancel effect of a previous p2p_authorize() or p2p_connect() call that has not yet resulted in completed GO Negotiation.

void p2p_wps_success_cb ( struct p2p_data p2p,
const u8 *  mac_addr 
)

Report successfully completed WPS provisioning.

Parameters
p2pP2P module context from p2p_init()
mac_addrPeer address

This function is used to report successfully completed WPS provisioning during group formation in both GO/Registrar and client/Enrollee roles.