wpa_supplicant.c File Reference

WPA Supplicant. More...

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <netinet/in.h>
#include "common.h"
#include "eapol_sm.h"
#include "eap.h"
#include "wpa.h"
#include "eloop.h"
#include "wpa_supplicant.h"
#include "config.h"
#include "l2_packet.h"
#include "wpa_supplicant_i.h"
#include "ctrl_iface.h"
#include "pcsc_funcs.h"
#include "version.h"
#include "preauth.h"
#include "wpa_ctrl.h"

Include dependency graph for wpa_supplicant.c:

Go to the source code of this file.

Defines

#define SCAN_AP_LIMIT   128

Functions

void wpa_msg (struct wpa_supplicant *wpa_s, int level, char *fmt,...)
wpa_blacklist * wpa_blacklist_get (struct wpa_supplicant *wpa_s, const u8 *bssid)
 Get the blacklist entry for a BSSID.
int wpa_blacklist_add (struct wpa_supplicant *wpa_s, const u8 *bssid)
 Add an BSSID to the blacklist.
void wpa_blacklist_clear (struct wpa_supplicant *wpa_s)
 Clear the blacklist of all entries.
const char * wpa_ssid_txt (u8 *ssid, size_t ssid_len)
 Convert SSID to a printable string.
void wpa_supplicant_req_scan (struct wpa_supplicant *wpa_s, int sec, int usec)
 Schedule a scan for neighboring access points.
void wpa_supplicant_cancel_scan (struct wpa_supplicant *wpa_s)
 Cancel a scheduled scan request.
void wpa_supplicant_req_auth_timeout (struct wpa_supplicant *wpa_s, int sec, int usec)
 Schedule a timeout for authentication.
void wpa_supplicant_cancel_auth_timeout (struct wpa_supplicant *wpa_s)
 Cancel authentication timeout.
void wpa_supplicant_initiate_eapol (struct wpa_supplicant *wpa_s)
 Configure EAPOL state machine.
void wpa_supplicant_set_non_wpa_policy (struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
 Set WPA parameters to non-WPA mode.
void wpa_clear_keys (struct wpa_supplicant *wpa_s, const u8 *addr)
 Clear keys configured for the driver.
const char * wpa_supplicant_state_txt (int state)
 Get the connection state name as a text string.
void wpa_supplicant_set_state (struct wpa_supplicant *wpa_s, wpa_states state)
 Set current connection state.
wpa_states wpa_supplicant_get_state (struct wpa_supplicant *wpa_s)
 Get the connection state.
int wpa_supplicant_reload_configuration (struct wpa_supplicant *wpa_s)
 Reload configuration data.
int wpa_supplicant_set_suites (struct wpa_supplicant *wpa_s, struct wpa_scan_result *bss, struct wpa_ssid *ssid, u8 *wpa_ie, size_t *wpa_ie_len)
 Set authentication and encryption parameters.
void wpa_supplicant_associate (struct wpa_supplicant *wpa_s, struct wpa_scan_result *bss, struct wpa_ssid *ssid)
 Request association.
void wpa_supplicant_disassociate (struct wpa_supplicant *wpa_s, int reason_code)
 Disassociate the current connection.
void wpa_supplicant_deauthenticate (struct wpa_supplicant *wpa_s, int reason_code)
 Deauthenticate the current connection.
int wpa_supplicant_get_scan_results (struct wpa_supplicant *wpa_s)
 Get scan results.
wpa_ssidwpa_supplicant_get_ssid (struct wpa_supplicant *wpa_s)
 Get a pointer to the current network structure.
void wpa_supplicant_rx_eapol (void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
 Deliver a received EAPOL frame to wpa_supplicant.
int wpa_supplicant_driver_init (struct wpa_supplicant *wpa_s, int wait_for_interface)
 Initialize driver interface parameters.
wpa_supplicantwpa_supplicant_add_iface (struct wpa_global *global, struct wpa_interface *iface)
 Add a new network interface.
int wpa_supplicant_remove_iface (struct wpa_global *global, struct wpa_supplicant *wpa_s)
 Remove a network interface.
wpa_supplicantwpa_supplicant_get_iface (struct wpa_global *global, const char *ifname)
 Get a new network interface.
wpa_globalwpa_supplicant_init (struct wpa_params *params)
 Initialize wpa_supplicant.
int wpa_supplicant_run (struct wpa_global *global)
 Run the wpa_supplicant main event loop.
void wpa_supplicant_deinit (struct wpa_global *global)
 Deinitialize wpa_supplicant.

Variables

const char * wpa_supplicant_version
const char * wpa_supplicant_license
const char * wpa_supplicant_full_license
wpa_driver_opswpa_supplicant_drivers []
int wpa_debug_level
int wpa_debug_show_keys
int wpa_debug_timestamp


Detailed Description

WPA Supplicant.

Copyright
Copyright (c) 2003-2006, Jouni Malinen <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

Alternatively, this software may be distributed under the terms of BSD license.

See README and COPYING for more details.

This file implements functions for registering and unregistering wpa_supplicant interfaces. In addition, this file contains number of functions for managing network connections.

Definition in file wpa_supplicant.c.


Function Documentation

int wpa_blacklist_add struct wpa_supplicant wpa_s,
const u8 *  bssid
 

Add an BSSID to the blacklist.

Parameters:
wpa_s Pointer to wpa_supplicant data
bssid BSSID to be added to the blacklist
Returns:
0 on success, -1 on failure
This function adds the specified BSSID to the blacklist or increases the blacklist count if the BSSID was already listed. It should be called when an association attempt fails either due to the selected BSS rejecting association or due to timeout.

This blacklist is used to force wpa_supplicant to go through all available BSSes before retrying to associate with an BSS that rejected or timed out association. It does not prevent the listed BSS from being used; it only changes the order in which they are tried.

Definition at line 433 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_blacklist_clear struct wpa_supplicant wpa_s  ) 
 

Clear the blacklist of all entries.

Parameters:
wpa_s Pointer to wpa_supplicant data

Definition at line 490 of file wpa_supplicant.c.

Here is the call graph for this function:

struct wpa_blacklist* wpa_blacklist_get struct wpa_supplicant wpa_s,
const u8 *  bssid
 

Get the blacklist entry for a BSSID.

Parameters:
wpa_s Pointer to wpa_supplicant data
bssid BSSID
Returns:
Matching blacklist entry for the BSSID or NULL if not found

Definition at line 400 of file wpa_supplicant.c.

void wpa_clear_keys struct wpa_supplicant wpa_s,
const u8 *  addr
 

Clear keys configured for the driver.

Parameters:
wpa_s Pointer to wpa_supplicant data
addr Previously used BSSID or NULL if not available
This function clears the encryption keys that has been previously configured for the driver.

Definition at line 767 of file wpa_supplicant.c.

Here is the call graph for this function:

const char* wpa_ssid_txt u8 *  ssid,
size_t  ssid_len
 

Convert SSID to a printable string.

Parameters:
ssid SSID (32-octet string)
ssid_len Length of ssid in octets
Returns:
Pointer to a printable string
This function can be used to convert SSIDs into printable form. In most cases, SSIDs do not use unprintable characters, but IEEE 802.11 standard does not limit the used character set, so anything could be used in an SSID.

This function uses a static buffer, so only one call can be used at the time, i.e., this is not re-entrant and the returned buffer must be used before calling this again.

Definition at line 521 of file wpa_supplicant.c.

struct wpa_supplicant* wpa_supplicant_add_iface struct wpa_global global,
struct wpa_interface iface
 

Add a new network interface.

Parameters:
global Pointer to global data from wpa_supplicant_init()
iface Interface configuration options
Returns:
Pointer to the created interface or NULL on failure
This function is used to add new network interfaces for wpa_supplicant. This can be called before wpa_supplicant_run() to add interfaces before the main event loop has been started. In addition, new interfaces can be added dynamically while wpa_supplicant is already running. This could happen, e.g., when a hotplug network adapter is inserted.

Definition at line 2211 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_associate struct wpa_supplicant wpa_s,
struct wpa_scan_result bss,
struct wpa_ssid ssid
 

Request association.

Parameters:
wpa_s Pointer to wpa_supplicant data
bss Scan results for the selected BSS, or NULL if not available
ssid Configuration data for the selected network
This function is used to request wpa_supplicant to associate with a BSS.

Definition at line 1276 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_cancel_auth_timeout struct wpa_supplicant wpa_s  ) 
 

Cancel authentication timeout.

Parameters:
wpa_s Pointer to wpa_supplicant data
This function is used to cancel authentication timeout scheduled with wpa_supplicant_req_auth_timeout() and it is called when authentication has been completed.

Definition at line 618 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_cancel_scan struct wpa_supplicant wpa_s  ) 
 

Cancel a scheduled scan request.

Parameters:
wpa_s Pointer to wpa_supplicant data
This function is used to cancel a scan request scheduled with wpa_supplicant_req_scan().

Definition at line 565 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_deauthenticate struct wpa_supplicant wpa_s,
int  reason_code
 

Deauthenticate the current connection.

Parameters:
wpa_s Pointer to wpa_supplicant data
reason_code IEEE 802.11 reason code for the deauthenticate frame
This function is used to request wpa_supplicant to disassociate with the current AP.

Definition at line 1503 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_deinit struct wpa_global global  ) 
 

Deinitialize wpa_supplicant.

Parameters:
global Pointer to global data from wpa_supplicant_init()
This function is called to deinitialize wpa_supplicant and to free all allocated resources. Remaining network interfaces will also be removed.

Definition at line 2395 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_disassociate struct wpa_supplicant wpa_s,
int  reason_code
 

Disassociate the current connection.

Parameters:
wpa_s Pointer to wpa_supplicant data
reason_code IEEE 802.11 reason code for the disassociate frame
This function is used to request wpa_supplicant to disassociate with the current AP.

Definition at line 1476 of file wpa_supplicant.c.

Here is the call graph for this function:

int wpa_supplicant_driver_init struct wpa_supplicant wpa_s,
int  wait_for_interface
 

Initialize driver interface parameters.

Parameters:
wpa_s Pointer to wpa_supplicant data
wait_for_interface 0 = do not wait for the interface (reports a failure if the interface is not present), 1 = wait until the interface is available
Returns:
0 on success, -1 on failure
This function is called to initialize driver interface parameters. wpa_drv_init() must have been called before this function to initialize the driver interface.

Definition at line 1837 of file wpa_supplicant.c.

Here is the call graph for this function:

struct wpa_supplicant* wpa_supplicant_get_iface struct wpa_global global,
const char *  ifname
 

Get a new network interface.

Parameters:
global Pointer to global data from wpa_supplicant_init()
ifname Interface name
Returns:
Pointer to the interface or NULL if not found

Definition at line 2288 of file wpa_supplicant.c.

int wpa_supplicant_get_scan_results struct wpa_supplicant wpa_s  ) 
 

Get scan results.

Parameters:
wpa_s Pointer to wpa_supplicant data
Returns:
0 on success, -1 on failure
This function is request the current scan results from the driver and stores a local copy of the results in wpa_s->scan_results.

Definition at line 1530 of file wpa_supplicant.c.

Here is the call graph for this function:

struct wpa_ssid* wpa_supplicant_get_ssid struct wpa_supplicant wpa_s  ) 
 

Get a pointer to the current network structure.

Parameters:
wpa_s Pointer to wpa_supplicant data
Returns:
A pointer to the current network structure or NULL on failure

Definition at line 1626 of file wpa_supplicant.c.

Here is the call graph for this function:

wpa_states wpa_supplicant_get_state struct wpa_supplicant wpa_s  ) 
 

Get the connection state.

Parameters:
wpa_s Pointer to wpa_supplicant data
Returns:
The current connection state (WPA_*)

Definition at line 862 of file wpa_supplicant.c.

struct wpa_global* wpa_supplicant_init struct wpa_params params  ) 
 

Initialize wpa_supplicant.

Parameters:
params Parameters for wpa_supplicant
Returns:
Pointer to global wpa_supplicant data, or NULL on failure
This function is used to initialize wpa_supplicant. After successful initialization, the returned data pointer can be used to add and remove network interfaces, and eventually, to deinitialize wpa_supplicant.

Definition at line 2311 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_initiate_eapol struct wpa_supplicant wpa_s  ) 
 

Configure EAPOL state machine.

Parameters:
wpa_s Pointer to wpa_supplicant data
This function is used to configure EAPOL state machine based on the selected authentication mode.

Definition at line 634 of file wpa_supplicant.c.

Here is the call graph for this function:

int wpa_supplicant_reload_configuration struct wpa_supplicant wpa_s  ) 
 

Reload configuration data.

Parameters:
wpa_s Pointer to wpa_supplicant data
Returns:
0 on success or -1 if configuration parsing failed
This function can be used to request that the configuration data is reloaded (e.g., after configuration file change). This function is reloading configuration only for one interface, so this may need to be called multiple times if wpa_supplicant is controlling multiple interfaces and all interfaces need reconfiguration.

Definition at line 893 of file wpa_supplicant.c.

Here is the call graph for this function:

int wpa_supplicant_remove_iface struct wpa_global global,
struct wpa_supplicant wpa_s
 

Remove a network interface.

Parameters:
global Pointer to global data from wpa_supplicant_init()
wpa_s Pointer to the network interface to be removed
Returns:
0 if interface was removed, -1 if interface was not found
This function can be used to dynamically remove network interfaces from wpa_supplicant, e.g., when a hotplug network adapter is ejected. In addition, this function is used to remove all remaining interdaces when wpa_supplicant is terminated.

Definition at line 2255 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_req_auth_timeout struct wpa_supplicant wpa_s,
int  sec,
int  usec
 

Schedule a timeout for authentication.

Parameters:
wpa_s Pointer to wpa_supplicant data
sec Number of seconds after which to time out authentication
usec Number of microseconds after which to time out authentication
This function is used to schedule a timeout for the current authentication attempt.

Definition at line 595 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_req_scan struct wpa_supplicant wpa_s,
int  sec,
int  usec
 

Schedule a scan for neighboring access points.

Parameters:
wpa_s Pointer to wpa_supplicant data
sec Number of seconds after which to scan
usec Number of microseconds after which to scan
This function is used to schedule a scan for neighboring access points after the specified time.

Definition at line 548 of file wpa_supplicant.c.

Here is the call graph for this function:

int wpa_supplicant_run struct wpa_global global  ) 
 

Run the wpa_supplicant main event loop.

Parameters:
global Pointer to global data from wpa_supplicant_init()
Returns:
0 after successful event loop run, -1 on failure
This function starts the main event loop and continues running as long as there are any remaining events. In most cases, this function is running as long as the wpa_supplicant process in still in use.

Definition at line 2362 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_rx_eapol void *  ctx,
const u8 *  src_addr,
const u8 *  buf,
size_t  len
 

Deliver a received EAPOL frame to wpa_supplicant.

Parameters:
ctx Context pointer (wpa_s)
src_addr Source address of the EAPOL frame
buf EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
len Length of the EAPOL data
This function is called for each received EAPOL frame.

Definition at line 1780 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_set_non_wpa_policy struct wpa_supplicant wpa_s,
struct wpa_ssid ssid
 

Set WPA parameters to non-WPA mode.

Parameters:
wpa_s Pointer to wpa_supplicant data
ssid Configuration data for the network
This function is used to configure WPA state machine and related parameters to a mode where WPA is not enabled. This is called as part of the authentication configuration when the selected network does not use WPA.

Definition at line 684 of file wpa_supplicant.c.

Here is the call graph for this function:

void wpa_supplicant_set_state struct wpa_supplicant wpa_s,
wpa_states  state
 

Set current connection state.

Parameters:
wpa_s Pointer to wpa_supplicant data
state The new connection state
This function is called whenever the connection state changes, e.g., association is completed for WPA/WPA2 4-Way Handshake is started.

Definition at line 836 of file wpa_supplicant.c.

Here is the call graph for this function:

int wpa_supplicant_set_suites struct wpa_supplicant wpa_s,
struct wpa_scan_result bss,
struct wpa_ssid ssid,
u8 *  wpa_ie,
size_t *  wpa_ie_len
 

Set authentication and encryption parameters.

Parameters:
wpa_s Pointer to wpa_supplicant data
bss Scan results for the selected BSS, or NULL if not available
ssid Configuration data for the selected network
wpa_ie Buffer for the WPA/RSN IE
wpa_ie_len Maximum wpa_ie buffer size on input. This is changed to be the used buffer length in case the functions returns success.
Returns:
0 on success or -1 on failure
This function is used to configure authentication and encryption parameters based on the network configuration and scan result for the selected BSS (if available).

Definition at line 1146 of file wpa_supplicant.c.

Here is the call graph for this function:

const char* wpa_supplicant_state_txt int  state  ) 
 

Get the connection state name as a text string.

Parameters:
state State (wpa_state; WPA_*)
Returns:
The state name as a printable text string

Definition at line 802 of file wpa_supplicant.c.


Variable Documentation

const char* wpa_supplicant_license
 

Initial value:

"This program is free software. You can distribute it and/or modify it\n"
"under the terms of the GNU General Public License version 2.\n"
"\n"
"Alternatively, this software may be distributed under the terms of the\n"
"BSD license. See README and COPYING for more details.\n"

Definition at line 50 of file wpa_supplicant.c.

const char* wpa_supplicant_version
 

Initial value:

"wpa_supplicant v" VERSION_STR "\n"
"Copyright (c) 2003-2006, Jouni Malinen <[email protected]> and contributors"

Definition at line 46 of file wpa_supplicant.c.


Generated on Sat May 6 21:19:54 2006 for wpa_supplicant by  doxygen 1.4.2