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

Wi-Fi Protected Setup. More...

#include "common/ieee802_11_defs.h"
#include "wps_defs.h"

Go to the source code of this file.

Data Structures

struct  wps_credential
 WPS Credential. More...
 
struct  wps_device_data
 WPS Device Data. More...
 
struct  wps_config
 WPS configuration for a single registration protocol run. More...
 
struct  wps_registrar_config
 WPS Registrar configuration. More...
 
union  wps_event_data
 union wps_event_data - WPS event data More...
 
struct  wps_event_data::wps_event_m2d
 M2D event data. More...
 
struct  wps_event_data::wps_event_fail
 Registration failure information. More...
 
struct  wps_event_data::wps_event_success
 
struct  wps_event_data::wps_event_pwd_auth_fail
 
struct  wps_event_data::wps_event_er_ap
 
struct  wps_event_data::wps_event_er_enrollee
 
struct  wps_event_data::wps_event_er_ap_settings
 
struct  wps_event_data::wps_event_er_set_selected_registrar
 
struct  upnp_pending_message
 Pending PutWLANResponse messages. More...
 
struct  wps_context
 Long term WPS context data. More...
 

Macros

#define WPS_DEV_TYPE_LEN   8
 
#define WPS_DEV_TYPE_BUFSIZE   21
 
#define WPS_SEC_DEV_TYPE_MAX_LEN   128
 
#define MAX_WPS_VENDOR_EXTENSIONS   10
 
#define WPS_MAX_VENDOR_EXT_LEN   1024
 
#define MAX_WPS_PARSE_VENDOR_EXT   10
 
#define WPS_SEC_DEVICE_TYPES   5
 

Enumerations

enum  wsc_op_code {
  WSC_UPnP = 0, WSC_Start = 0x01, WSC_ACK = 0x02, WSC_NACK = 0x03,
  WSC_MSG = 0x04, WSC_Done = 0x05, WSC_FRAG_ACK = 0x06
}
 EAP-WSC OP-Code values.
 
enum  wps_process_res { WPS_DONE, WPS_CONTINUE, WPS_FAILURE, WPS_PENDING }
 WPS message processing result. More...
 
enum  wps_event {
  WPS_EV_M2D, WPS_EV_FAIL, WPS_EV_SUCCESS, WPS_EV_PWD_AUTH_FAIL,
  WPS_EV_PBC_OVERLAP, WPS_EV_PBC_TIMEOUT, WPS_EV_PBC_ACTIVE, WPS_EV_PBC_DISABLE,
  WPS_EV_ER_AP_ADD, WPS_EV_ER_AP_REMOVE, WPS_EV_ER_ENROLLEE_ADD, WPS_EV_ER_ENROLLEE_REMOVE,
  WPS_EV_ER_AP_SETTINGS, WPS_EV_ER_SET_SELECTED_REGISTRAR, WPS_EV_AP_PIN_SUCCESS
}
 WPS event types. More...
 

Functions

struct wps_datawps_init (const struct wps_config *cfg)
 Initialize WPS Registration protocol data. More...
 
void wps_deinit (struct wps_data *data)
 Deinitialize WPS Registration protocol data. More...
 
enum wps_process_res wps_process_msg (struct wps_data *wps, enum wsc_op_code op_code, const struct wpabuf *msg)
 Process a WPS message. More...
 
struct wpabufwps_get_msg (struct wps_data *wps, enum wsc_op_code *op_code)
 Build a WPS message. More...
 
int wps_is_selected_pbc_registrar (const struct wpabuf *msg)
 Check whether WPS IE indicates active PBC. More...
 
int wps_is_selected_pin_registrar (const struct wpabuf *msg)
 Check whether WPS IE indicates active PIN. More...
 
int wps_ap_priority_compar (const struct wpabuf *wps_a, const struct wpabuf *wps_b)
 Prioritize WPS IE from two APs. More...
 
int wps_is_addr_authorized (const struct wpabuf *msg, const u8 *addr, int ver1_compat)
 Check whether WPS IE authorizes MAC address. More...
 
const u8 * wps_get_uuid_e (const struct wpabuf *msg)
 Get UUID-E from WPS IE. More...
 
int wps_is_20 (const struct wpabuf *msg)
 Check whether WPS attributes claim support for WPS 2.0.
 
struct wpabufwps_build_assoc_req_ie (enum wps_request_type req_type)
 Build WPS IE for (Re)Association Request. More...
 
struct wpabufwps_build_assoc_resp_ie (void)
 Build WPS IE for (Re)Association Response. More...
 
struct wpabufwps_build_probe_req_ie (u16 pw_id, struct wps_device_data *dev, const u8 *uuid, enum wps_request_type req_type, unsigned int num_req_dev_types, const u8 *req_dev_types)
 Build WPS IE for Probe Request. More...
 
struct wps_registrarwps_registrar_init (struct wps_context *wps, const struct wps_registrar_config *cfg)
 Initialize WPS Registrar data. More...
 
void wps_registrar_deinit (struct wps_registrar *reg)
 Deinitialize WPS Registrar data. More...
 
int wps_registrar_add_pin (struct wps_registrar *reg, const u8 *addr, const u8 *uuid, const u8 *pin, size_t pin_len, int timeout)
 Configure a new PIN for Registrar. More...
 
int wps_registrar_invalidate_pin (struct wps_registrar *reg, const u8 *uuid)
 Invalidate a PIN for a specific UUID-E. More...
 
int wps_registrar_wps_cancel (struct wps_registrar *reg)
 
int wps_registrar_unlock_pin (struct wps_registrar *reg, const u8 *uuid)
 Unlock a PIN for a specific UUID-E. More...
 
int wps_registrar_button_pushed (struct wps_registrar *reg, const u8 *p2p_dev_addr)
 Notify Registrar that AP button was pushed. More...
 
void wps_registrar_complete (struct wps_registrar *registrar, const u8 *uuid_e, const u8 *dev_pw, size_t dev_pw_len)
 
void wps_registrar_probe_req_rx (struct wps_registrar *reg, const u8 *addr, const struct wpabuf *wps_data, int p2p_wildcard)
 Notify Registrar of Probe Request. More...
 
int wps_registrar_update_ie (struct wps_registrar *reg)
 
int wps_registrar_get_info (struct wps_registrar *reg, const u8 *addr, char *buf, size_t buflen)
 
int wps_registrar_config_ap (struct wps_registrar *reg, struct wps_credential *cred)
 
int wps_registrar_add_nfc_pw_token (struct wps_registrar *reg, const u8 *pubkey_hash, u16 pw_id, const u8 *dev_pw, size_t dev_pw_len, int pk_hash_provided_oob)
 
int wps_registrar_add_nfc_password_token (struct wps_registrar *reg, const u8 *oob_dev_pw, size_t oob_dev_pw_len)
 
void wps_registrar_flush (struct wps_registrar *reg)
 
int wps_build_credential_wrap (struct wpabuf *msg, const struct wps_credential *cred)
 
unsigned int wps_pin_checksum (unsigned int pin)
 Compute PIN checksum. More...
 
unsigned int wps_pin_valid (unsigned int pin)
 Check whether a PIN has a valid checksum. More...
 
unsigned int wps_generate_pin (void)
 Generate a random PIN. More...
 
int wps_pin_str_valid (const char *pin)
 
void wps_free_pending_msgs (struct upnp_pending_message *msgs)
 
struct wpabufwps_get_oob_cred (struct wps_context *wps, int rf_band, int channel)
 
int wps_oob_use_cred (struct wps_context *wps, struct wps_parse_attr *attr)
 
int wps_attr_text (struct wpabuf *data, char *buf, char *end)
 
const char * wps_ei_str (enum wps_error_indication ei)
 
struct wps_erwps_er_init (struct wps_context *wps, const char *ifname, const char *filter)
 
void wps_er_refresh (struct wps_er *er)
 
void wps_er_deinit (struct wps_er *er, void(*cb)(void *ctx), void *ctx)
 
void wps_er_set_sel_reg (struct wps_er *er, int sel_reg, u16 dev_passwd_id, u16 sel_reg_config_methods)
 
int wps_er_pbc (struct wps_er *er, const u8 *uuid, const u8 *addr)
 
const u8 * wps_er_get_sta_uuid (struct wps_er *er, const u8 *addr)
 
int wps_er_learn (struct wps_er *er, const u8 *uuid, const u8 *addr, const u8 *pin, size_t pin_len)
 
int wps_er_set_config (struct wps_er *er, const u8 *uuid, const u8 *addr, const struct wps_credential *cred)
 
int wps_er_config (struct wps_er *er, const u8 *uuid, const u8 *addr, const u8 *pin, size_t pin_len, const struct wps_credential *cred)
 
struct wpabufwps_er_config_token_from_cred (struct wps_context *wps, struct wps_credential *cred)
 
struct wpabufwps_er_nfc_config_token (struct wps_er *er, const u8 *uuid, const u8 *addr)
 
struct wpabufwps_er_nfc_handover_sel (struct wps_er *er, struct wps_context *wps, const u8 *uuid, const u8 *addr, struct wpabuf *pubkey)
 
int wps_dev_type_str2bin (const char *str, u8 dev_type[WPS_DEV_TYPE_LEN])
 
char * wps_dev_type_bin2str (const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf, size_t buf_len)
 
void uuid_gen_mac_addr (const u8 *mac_addr, u8 *uuid)
 
u16 wps_config_methods_str2bin (const char *str)
 
struct wpabufwps_build_nfc_pw_token (u16 dev_pw_id, const struct wpabuf *pubkey, const struct wpabuf *dev_pw)
 
struct wpabufwps_nfc_token_build (int ndef, int id, struct wpabuf *pubkey, struct wpabuf *dev_pw)
 
int wps_nfc_gen_dh (struct wpabuf **pubkey, struct wpabuf **privkey)
 
struct wpabufwps_nfc_token_gen (int ndef, int *id, struct wpabuf **pubkey, struct wpabuf **privkey, struct wpabuf **dev_pw)
 
struct wpabufwps_build_nfc_handover_req (struct wps_context *ctx, struct wpabuf *nfc_dh_pubkey)
 
struct wpabufwps_build_nfc_handover_sel (struct wps_context *ctx, struct wpabuf *nfc_dh_pubkey, const u8 *bssid, int freq)
 
struct wpabufwps_build_nfc_handover_req_p2p (struct wps_context *ctx, struct wpabuf *nfc_dh_pubkey)
 
struct wpabufwps_build_nfc_handover_sel_p2p (struct wps_context *ctx, int nfc_dev_pw_id, struct wpabuf *nfc_dh_pubkey, struct wpabuf *nfc_dev_pw)
 
struct wpabufndef_parse_wifi (const struct wpabuf *buf)
 
struct wpabufndef_build_wifi (const struct wpabuf *buf)
 
struct wpabufndef_parse_p2p (const struct wpabuf *buf)
 
struct wpabufndef_build_p2p (const struct wpabuf *buf)
 

Detailed Description

Wi-Fi Protected Setup.

Enumeration Type Documentation

enum wps_event

WPS event types.

Enumerator
WPS_EV_M2D 

M2D received (Registrar did not know us)

WPS_EV_FAIL 

Registration failed.

WPS_EV_SUCCESS 

Registration succeeded.

WPS_EV_PWD_AUTH_FAIL 

Password authentication failed.

WPS_EV_PBC_OVERLAP 

PBC session overlap detected.

WPS_EV_PBC_TIMEOUT 

PBC walktime expired before protocol run start.

WPS_EV_PBC_ACTIVE 

PBC mode was activated.

WPS_EV_PBC_DISABLE 

PBC mode was disabled.

WPS_EV_ER_AP_ADD 

ER: AP added.

WPS_EV_ER_AP_REMOVE 

ER: AP removed.

WPS_EV_ER_ENROLLEE_ADD 

ER: Enrollee added.

WPS_EV_ER_ENROLLEE_REMOVE 

ER: Enrollee removed.

WPS_EV_ER_AP_SETTINGS 

ER: AP Settings learned.

WPS_EV_ER_SET_SELECTED_REGISTRAR 

ER: SetSelectedRegistrar event.

WPS_EV_AP_PIN_SUCCESS 

External Registrar used correct AP PIN.

WPS message processing result.

Enumerator
WPS_DONE 

Processing done.

WPS_CONTINUE 

Processing continues.

WPS_FAILURE 

Processing failed.

WPS_PENDING 

Processing continues, but waiting for an external.

event (e.g., UPnP message from an external Registrar)

Function Documentation

int wps_ap_priority_compar ( const struct wpabuf wps_a,
const struct wpabuf wps_b 
)

Prioritize WPS IE from two APs.

Parameters
wps_aWPS IE contents from Beacon or Probe Response frame
wps_bWPS IE contents from Beacon or Probe Response frame
Returns
1 if wps_b is considered more likely selection for WPS provisioning, -1 if wps_a is considered more like, or 0 if no preference
struct wpabuf* wps_build_assoc_req_ie ( enum wps_request_type  req_type)

Build WPS IE for (Re)Association Request.

Parameters
req_typeValue for Request Type attribute
Returns
WPS IE or NULL on failure

The caller is responsible for freeing the buffer.

struct wpabuf* wps_build_assoc_resp_ie ( void  )

Build WPS IE for (Re)Association Response.

Returns
WPS IE or NULL on failure

The caller is responsible for freeing the buffer.

struct wpabuf* wps_build_probe_req_ie ( u16  pw_id,
struct wps_device_data dev,
const u8 *  uuid,
enum wps_request_type  req_type,
unsigned int  num_req_dev_types,
const u8 *  req_dev_types 
)

Build WPS IE for Probe Request.

Parameters
pw_idPassword ID (DEV_PW_PUSHBUTTON for active PBC and DEV_PW_DEFAULT for most other use cases)
devDevice attributes
uuidOwn UUID
req_typeValue for Request Type attribute
num_req_dev_typesNumber of requested device types
req_dev_typesRequested device types (8 * num_req_dev_types octets) or NULL if none
Returns
WPS IE or NULL on failure

The caller is responsible for freeing the buffer.

void wps_deinit ( struct wps_data data)

Deinitialize WPS Registration protocol data.

Parameters
dataWPS Registration protocol data from wps_init()
unsigned int wps_generate_pin ( void  )

Generate a random PIN.

Returns
Eight digit PIN (i.e., including the checksum digit)
struct wpabuf* wps_get_msg ( struct wps_data wps,
enum wsc_op_code op_code 
)

Build a WPS message.

Parameters
wpsWPS Registration protocol data from wps_init()
op_codeBuffer for returning message OP Code
Returns
The generated WPS message or NULL on failure

This function is used to build a response to a message processed by calling wps_process_msg(). The caller is responsible for freeing the buffer.

const u8* wps_get_uuid_e ( const struct wpabuf msg)

Get UUID-E from WPS IE.

Parameters
msgWPS IE contents from Beacon or Probe Response frame
Returns
Pointer to UUID-E or NULL if not included

The returned pointer is to the msg contents and it remains valid only as long as the msg buffer is valid.

struct wps_data* wps_init ( const struct wps_config cfg)

Initialize WPS Registration protocol data.

Parameters
cfgWPS configuration
Returns
Pointer to allocated data or NULL on failure

This function is used to initialize WPS data for a registration protocol instance (i.e., each run of registration protocol as a Registrar of Enrollee. The caller is responsible for freeing this data after the registration run has been completed by calling wps_deinit().

int wps_is_addr_authorized ( const struct wpabuf msg,
const u8 *  addr,
int  ver1_compat 
)

Check whether WPS IE authorizes MAC address.

Parameters
msgWPS IE contents from Beacon or Probe Response frame
addrMAC address to search for
ver1_compatWhether to use version 1 compatibility mode
Returns
2 if the specified address is explicit authorized, 1 if address is authorized (broadcast), 0 if not
int wps_is_selected_pbc_registrar ( const struct wpabuf msg)

Check whether WPS IE indicates active PBC.

Parameters
msgWPS IE contents from Beacon or Probe Response frame
Returns
1 if PBC Registrar is active, 0 if not
int wps_is_selected_pin_registrar ( const struct wpabuf msg)

Check whether WPS IE indicates active PIN.

Parameters
msgWPS IE contents from Beacon or Probe Response frame
Returns
1 if PIN Registrar is active, 0 if not
unsigned int wps_pin_checksum ( unsigned int  pin)

Compute PIN checksum.

Parameters
pinSeven digit PIN (i.e., eight digit PIN without the checksum digit)
Returns
Checksum digit
unsigned int wps_pin_valid ( unsigned int  pin)

Check whether a PIN has a valid checksum.

Parameters
pinEight digit PIN (i.e., including the checksum digit)
Returns
1 if checksum digit is valid, or 0 if not
enum wps_process_res wps_process_msg ( struct wps_data wps,
enum wsc_op_code  op_code,
const struct wpabuf msg 
)

Process a WPS message.

Parameters
wpsWPS Registration protocol data from wps_init()
op_codeMessage OP Code
msgMessage data
Returns
Processing result

This function is used to process WPS messages with OP Codes WSC_ACK, WSC_NACK, WSC_MSG, and WSC_Done. The caller (e.g., EAP server/peer) is responsible for reassembling the messages before calling this function. Response to this message is built by calling wps_get_msg().

int wps_registrar_add_pin ( struct wps_registrar reg,
const u8 *  addr,
const u8 *  uuid,
const u8 *  pin,
size_t  pin_len,
int  timeout 
)

Configure a new PIN for Registrar.

Parameters
regRegistrar data from wps_registrar_init()
addrEnrollee MAC address or NULL if not known
uuidUUID-E or NULL for wildcard (any UUID)
pinPIN (Device Password)
pin_lenLength of pin in octets
timeoutTime (in seconds) when the PIN will be invalidated; 0 = no timeout
Returns
0 on success, -1 on failure
int wps_registrar_button_pushed ( struct wps_registrar reg,
const u8 *  p2p_dev_addr 
)

Notify Registrar that AP button was pushed.

Parameters
regRegistrar data from wps_registrar_init()
p2p_dev_addrLimit allowed PBC devices to the specified P2P device, NULL indicates no such filtering
Returns
0 on success, -1 on failure, -2 on session overlap

This function is called on an AP when a push button is pushed to activate PBC mode. The PBC mode will be stopped after walk time (2 minutes) timeout or when a PBC registration is completed. If more than one Enrollee in active PBC mode has been detected during the monitor time (previous 2 minutes), the PBC mode is not activated and -2 is returned to indicate session overlap. This is skipped if a specific Enrollee is selected.

void wps_registrar_deinit ( struct wps_registrar reg)

Deinitialize WPS Registrar data.

Parameters
regRegistrar data from wps_registrar_init()
struct wps_registrar* wps_registrar_init ( struct wps_context wps,
const struct wps_registrar_config cfg 
)

Initialize WPS Registrar data.

Parameters
wpsPointer to longterm WPS context
cfgRegistrar configuration
Returns
Pointer to allocated Registrar data or NULL on failure

This function is used to initialize WPS Registrar functionality. It can be used for a single Registrar run (e.g., when run in a supplicant) or multiple runs (e.g., when run as an internal Registrar in an AP). Caller is responsible for freeing the returned data with wps_registrar_deinit() when Registrar functionality is not needed anymore.

int wps_registrar_invalidate_pin ( struct wps_registrar reg,
const u8 *  uuid 
)

Invalidate a PIN for a specific UUID-E.

Parameters
regRegistrar data from wps_registrar_init()
uuidUUID-E
Returns
0 on success, -1 on failure (e.g., PIN not found)
void wps_registrar_probe_req_rx ( struct wps_registrar reg,
const u8 *  addr,
const struct wpabuf wps_data,
int  p2p_wildcard 
)

Notify Registrar of Probe Request.

Parameters
regRegistrar data from wps_registrar_init()
addrMAC address of the Probe Request sender
wps_dataWPS IE contents

This function is called on an AP when a Probe Request with WPS IE is received. This is used to track PBC mode use and to detect possible overlap situation with other WPS APs.

int wps_registrar_unlock_pin ( struct wps_registrar reg,
const u8 *  uuid 
)

Unlock a PIN for a specific UUID-E.

Parameters
regRegistrar data from wps_registrar_init()
uuidUUID-E
Returns
0 on success, -1 on failure

PINs are locked to enforce only one concurrent use. This function unlocks a PIN to allow it to be used again. If the specified PIN was configured using a wildcard UUID, it will be removed instead of allowing multiple uses.