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

WPA Supplicant - WPA state machine and EAPOL-Key processing. More...

#include "includes.h"
#include "common.h"
#include "crypto/aes_wrap.h"
#include "crypto/crypto.h"
#include "crypto/random.h"
#include "common/ieee802_11_defs.h"
#include "eapol_supp/eapol_supp_sm.h"
#include "wpa.h"
#include "eloop.h"
#include "preauth.h"
#include "pmksa_cache.h"
#include "wpa_i.h"
#include "wpa_ie.h"
#include "peerkey.h"

Data Structures

struct  wpa_gtk_data
 

Macros

#define RSN_SUITE   "%02x-%02x-%02x-%d"
 
#define RSN_SUITE_ARG(s)   ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
 

Functions

void wpa_eapol_key_send (struct wpa_sm *sm, const u8 *kck, size_t kck_len, int ver, const u8 *dest, u16 proto, u8 *msg, size_t msg_len, u8 *key_mic)
 Send WPA/RSN EAPOL-Key message. More...
 
void wpa_sm_key_request (struct wpa_sm *sm, int error, int pairwise)
 Send EAPOL-Key Request. More...
 
int wpa_supplicant_send_2_of_4 (struct wpa_sm *sm, const unsigned char *dst, const struct wpa_eapol_key *key, int ver, const u8 *nonce, const u8 *wpa_ie, size_t wpa_ie_len, struct wpa_ptk *ptk)
 Send message 2 of WPA/RSN 4-Way Handshake. More...
 
int wpa_supplicant_send_4_of_4 (struct wpa_sm *sm, const unsigned char *dst, const struct wpa_eapol_key *key, u16 ver, u16 key_info, struct wpa_ptk *ptk)
 Send message 4 of WPA/RSN 4-Way Handshake. More...
 
void wpa_sm_aborted_cached (struct wpa_sm *sm)
 Notify WPA that PMKSA caching was aborted. More...
 
int wpa_sm_rx_eapol (struct wpa_sm *sm, const u8 *src_addr, const u8 *buf, size_t len)
 Process received WPA EAPOL frames. More...
 
int wpa_sm_get_mib (struct wpa_sm *sm, char *buf, size_t buflen)
 Dump text list of MIB entries. More...
 
struct wpa_smwpa_sm_init (struct wpa_sm_ctx *ctx)
 Initialize WPA state machine. More...
 
void wpa_sm_deinit (struct wpa_sm *sm)
 Deinitialize WPA state machine. More...
 
void wpa_sm_notify_assoc (struct wpa_sm *sm, const u8 *bssid)
 Notify WPA state machine about association. More...
 
void wpa_sm_notify_disassoc (struct wpa_sm *sm)
 Notify WPA state machine about disassociation. More...
 
void wpa_sm_set_pmk (struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, const u8 *bssid)
 Set PMK. More...
 
void wpa_sm_set_pmk_from_pmksa (struct wpa_sm *sm)
 Set PMK based on the current PMKSA. More...
 
void wpa_sm_set_fast_reauth (struct wpa_sm *sm, int fast_reauth)
 Set fast reauthentication (EAP) enabled/disabled. More...
 
void wpa_sm_set_scard_ctx (struct wpa_sm *sm, void *scard_ctx)
 Set context pointer for smartcard callbacks. More...
 
void wpa_sm_set_config (struct wpa_sm *sm, struct rsn_supp_config *config)
 Notification of current configration change. More...
 
void wpa_sm_set_own_addr (struct wpa_sm *sm, const u8 *addr)
 Set own MAC address. More...
 
void wpa_sm_set_ifname (struct wpa_sm *sm, const char *ifname, const char *bridge_ifname)
 Set network interface name. More...
 
void wpa_sm_set_eapol (struct wpa_sm *sm, struct eapol_sm *eapol)
 Set EAPOL state machine pointer. More...
 
int wpa_sm_set_param (struct wpa_sm *sm, enum wpa_sm_conf_params param, unsigned int value)
 Set WPA state machine parameters. More...
 
int wpa_sm_get_status (struct wpa_sm *sm, char *buf, size_t buflen, int verbose)
 Get WPA state machine. More...
 
int wpa_sm_pmf_enabled (struct wpa_sm *sm)
 
int wpa_sm_set_assoc_wpa_ie_default (struct wpa_sm *sm, u8 *wpa_ie, size_t *wpa_ie_len)
 Generate own WPA/RSN IE from configuration. More...
 
int wpa_sm_set_assoc_wpa_ie (struct wpa_sm *sm, const u8 *ie, size_t len)
 Set own WPA/RSN IE from (Re)AssocReq. More...
 
int wpa_sm_set_ap_wpa_ie (struct wpa_sm *sm, const u8 *ie, size_t len)
 Set AP WPA IE from Beacon/ProbeResp. More...
 
int wpa_sm_set_ap_rsn_ie (struct wpa_sm *sm, const u8 *ie, size_t len)
 Set AP RSN IE from Beacon/ProbeResp. More...
 
int wpa_sm_parse_own_wpa_ie (struct wpa_sm *sm, struct wpa_ie_data *data)
 Parse own WPA/RSN IE. More...
 
int wpa_sm_pmksa_cache_list (struct wpa_sm *sm, char *buf, size_t len)
 
void wpa_sm_drop_sa (struct wpa_sm *sm)
 
int wpa_sm_has_ptk (struct wpa_sm *sm)
 
void wpa_sm_update_replay_ctr (struct wpa_sm *sm, const u8 *replay_ctr)
 
void wpa_sm_pmksa_cache_flush (struct wpa_sm *sm, void *network_ctx)
 
int wpa_sm_get_p2p_ip_addr (struct wpa_sm *sm, u8 *buf)
 
void wpa_sm_set_rx_replay_ctr (struct wpa_sm *sm, const u8 *rx_replay_counter)
 
void wpa_sm_set_ptk_kck_kek (struct wpa_sm *sm, const u8 *ptk_kck, size_t ptk_kck_len, const u8 *ptk_kek, size_t ptk_kek_len)
 

Detailed Description

WPA Supplicant - WPA state machine and EAPOL-Key processing.

Function Documentation

void wpa_eapol_key_send ( struct wpa_sm sm,
const u8 *  kck,
size_t  kck_len,
int  ver,
const u8 *  dest,
u16  proto,
u8 *  msg,
size_t  msg_len,
u8 *  key_mic 
)

Send WPA/RSN EAPOL-Key message.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
kckKey Confirmation Key (KCK, part of PTK)
kck_lenKCK length in octets
verVersion field from Key Info
destDestination address for the frame
protoEthertype (usually ETH_P_EAPOL)
msgEAPOL-Key message
msg_lenLength of message
key_micPointer to the buffer to which the EAPOL-Key MIC is written
void wpa_sm_aborted_cached ( struct wpa_sm sm)

Notify WPA that PMKSA caching was aborted.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
void wpa_sm_deinit ( struct wpa_sm sm)

Deinitialize WPA state machine.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
int wpa_sm_get_mib ( struct wpa_sm sm,
char *  buf,
size_t  buflen 
)

Dump text list of MIB entries.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
bufBuffer for the list
buflenLength of the buffer
Returns
Number of bytes written to buffer

This function is used fetch dot11 MIB variables.

int wpa_sm_get_status ( struct wpa_sm sm,
char *  buf,
size_t  buflen,
int  verbose 
)

Get WPA state machine.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
bufBuffer for status information
buflenMaximum buffer length
verboseWhether to include verbose status information
Returns
Number of bytes written to buf.

Query WPA state machine for status information. This function fills in a text area with current status information. If the buffer (buf) is not large enough, status information will be truncated to fit the buffer.

struct wpa_sm* wpa_sm_init ( struct wpa_sm_ctx ctx)

Initialize WPA state machine.

Parameters
ctxContext pointer for callbacks; this needs to be an allocated buffer
Returns
Pointer to the allocated WPA state machine data

This function is used to allocate a new WPA state machine and the returned value is passed to all WPA state machine calls.

void wpa_sm_key_request ( struct wpa_sm sm,
int  error,
int  pairwise 
)

Send EAPOL-Key Request.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
errorIndicate whether this is an Michael MIC error report
pairwise1 = error report for pairwise packet, 0 = for group packet

Send an EAPOL-Key Request to the current authenticator. This function is used to request rekeying and it is usually called when a local Michael MIC failure is detected.

void wpa_sm_notify_assoc ( struct wpa_sm sm,
const u8 *  bssid 
)

Notify WPA state machine about association.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
bssidThe BSSID of the new association

This function is called to let WPA state machine know that the connection was established.

void wpa_sm_notify_disassoc ( struct wpa_sm sm)

Notify WPA state machine about disassociation.

Parameters
smPointer to WPA state machine data from wpa_sm_init()

This function is called to let WPA state machine know that the connection was lost. This will abort any existing pre-authentication session.

int wpa_sm_parse_own_wpa_ie ( struct wpa_sm sm,
struct wpa_ie_data data 
)

Parse own WPA/RSN IE.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
dataPointer to data area for parsing results
Returns
0 on success, -1 if IE is not known, or -2 on parsing failure

Parse the contents of the own WPA or RSN IE from (Re)AssocReq and write the parsed data into data.

int wpa_sm_rx_eapol ( struct wpa_sm sm,
const u8 *  src_addr,
const u8 *  buf,
size_t  len 
)

Process received WPA EAPOL frames.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
src_addrSource MAC address of the EAPOL packet
bufPointer to the beginning of the EAPOL data (EAPOL header)
lenLength of the EAPOL frame
Returns
1 = WPA EAPOL-Key processed, 0 = not a WPA EAPOL-Key, -1 failure

This function is called for each received EAPOL frame. Other than EAPOL-Key frames can be skipped if filtering is done elsewhere. wpa_sm_rx_eapol() is only processing WPA and WPA2 EAPOL-Key frames.

The received EAPOL-Key packets are validated and valid packets are replied to. In addition, key material (PTK, GTK) is configured at the end of a successful key handshake.

int wpa_sm_set_ap_rsn_ie ( struct wpa_sm sm,
const u8 *  ie,
size_t  len 
)

Set AP RSN IE from Beacon/ProbeResp.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
iePointer to IE data (starting from id)
lenIE length
Returns
0 on success, -1 on failure

Inform WPA state machine about the RSN IE used in Beacon / Probe Response frame.

int wpa_sm_set_ap_wpa_ie ( struct wpa_sm sm,
const u8 *  ie,
size_t  len 
)

Set AP WPA IE from Beacon/ProbeResp.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
iePointer to IE data (starting from id)
lenIE length
Returns
0 on success, -1 on failure

Inform WPA state machine about the WPA IE used in Beacon / Probe Response frame.

int wpa_sm_set_assoc_wpa_ie ( struct wpa_sm sm,
const u8 *  ie,
size_t  len 
)

Set own WPA/RSN IE from (Re)AssocReq.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
iePointer to IE data (starting from id)
lenIE length
Returns
0 on success, -1 on failure

Inform WPA state machine about the WPA/RSN IE used in (Re)Association Request frame. The IE will be used to override the default value generated with wpa_sm_set_assoc_wpa_ie_default().

int wpa_sm_set_assoc_wpa_ie_default ( struct wpa_sm sm,
u8 *  wpa_ie,
size_t *  wpa_ie_len 
)

Generate own WPA/RSN IE from configuration.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
wpa_iePointer to buffer for WPA/RSN IE
wpa_ie_lenPointer to the length of the wpa_ie buffer
Returns
0 on success, -1 on failure
void wpa_sm_set_config ( struct wpa_sm sm,
struct rsn_supp_config config 
)

Notification of current configration change.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
configPointer to current network configuration

Notify WPA state machine that configuration has changed. config will be stored as a backpointer to network configuration. This can be NULL to clear the stored pointed.

void wpa_sm_set_eapol ( struct wpa_sm sm,
struct eapol_sm eapol 
)

Set EAPOL state machine pointer.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
eapolPointer to EAPOL state machine allocated with eapol_sm_init()
void wpa_sm_set_fast_reauth ( struct wpa_sm sm,
int  fast_reauth 
)

Set fast reauthentication (EAP) enabled/disabled.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
fast_reauthWhether fast reauthentication (EAP) is allowed
void wpa_sm_set_ifname ( struct wpa_sm sm,
const char *  ifname,
const char *  bridge_ifname 
)

Set network interface name.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
ifnameInterface name
bridge_ifnameOptional bridge interface name (for pre-auth)
void wpa_sm_set_own_addr ( struct wpa_sm sm,
const u8 *  addr 
)

Set own MAC address.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
addrOwn MAC address
int wpa_sm_set_param ( struct wpa_sm sm,
enum wpa_sm_conf_params  param,
unsigned int  value 
)

Set WPA state machine parameters.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
paramParameter field
valueParameter value
Returns
0 on success, -1 on failure
void wpa_sm_set_pmk ( struct wpa_sm sm,
const u8 *  pmk,
size_t  pmk_len,
const u8 *  bssid 
)

Set PMK.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
pmkThe new PMK
pmk_lenThe length of the new PMK in bytes
bssidAA to add into PMKSA cache or NULL to not cache the PMK

Configure the PMK for WPA state machine.

void wpa_sm_set_pmk_from_pmksa ( struct wpa_sm sm)

Set PMK based on the current PMKSA.

Parameters
smPointer to WPA state machine data from wpa_sm_init()

Take the PMK from the current PMKSA into use. If no PMKSA is active, the PMK will be cleared.

void wpa_sm_set_scard_ctx ( struct wpa_sm sm,
void *  scard_ctx 
)

Set context pointer for smartcard callbacks.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
scard_ctxContext pointer for smartcard related callback functions
int wpa_supplicant_send_2_of_4 ( struct wpa_sm sm,
const unsigned char *  dst,
const struct wpa_eapol_key key,
int  ver,
const u8 *  nonce,
const u8 *  wpa_ie,
size_t  wpa_ie_len,
struct wpa_ptk ptk 
)

Send message 2 of WPA/RSN 4-Way Handshake.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
dstDestination address for the frame
keyPointer to the EAPOL-Key frame header
verVersion bits from EAPOL-Key Key Info
nonceNonce value for the EAPOL-Key frame
wpa_ieWPA/RSN IE
wpa_ie_lenLength of the WPA/RSN IE
ptkPTK to use for keyed hash and encryption
Returns
0 on success, -1 on failure
int wpa_supplicant_send_4_of_4 ( struct wpa_sm sm,
const unsigned char *  dst,
const struct wpa_eapol_key key,
u16  ver,
u16  key_info,
struct wpa_ptk ptk 
)

Send message 4 of WPA/RSN 4-Way Handshake.

Parameters
smPointer to WPA state machine data from wpa_sm_init()
dstDestination address for the frame
keyPointer to the EAPOL-Key frame header
verVersion bits from EAPOL-Key Key Info
key_infoKey Info
ptkPTK to use for keyed hash and encryption
Returns
0 on success, -1 on failure