iPXE
wpa_psk.c File Reference

Frontend for WPA using a pre-shared key. More...

#include <string.h>
#include <ipxe/net80211.h>
#include <ipxe/sha1.h>
#include <ipxe/wpa.h>
#include <errno.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FILE_SECBOOT (FORBIDDEN)
static int wpa_psk_init (struct net80211_device *dev)
 Initialise WPA-PSK state.
static int wpa_psk_start (struct net80211_device *dev)
 Start WPA-PSK authentication.
static int wpa_psk_step (struct net80211_device *dev)
 Step WPA-PSK authentication.
static int wpa_psk_no_change_key (struct net80211_device *dev __unused)
 Do-nothing function; you can't change a WPA key post-authentication.
static void wpa_psk_stop (struct net80211_device *dev)
 Disable handling of received WPA authentication frames.

Variables

struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker
 WPA-PSK security handshaker.

Detailed Description

Frontend for WPA using a pre-shared key.

Definition in file wpa_psk.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( FORBIDDEN )

◆ wpa_psk_init()

int wpa_psk_init ( struct net80211_device * dev)
static

Initialise WPA-PSK state.

Parameters
dev802.11 device
Return values
rcReturn status code

Definition at line 40 of file wpa_psk.c.

41{
42 return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
43}
union ieee80211_ie * rsn_ie
RSN or WPA information element to include with association.
Definition net80211.h:932
int wpa_make_rsn_ie(struct net80211_device *dev, union ieee80211_ie **ie_ret)
Construct RSN or WPA information element.
Definition wpa.c:125

References net80211_device::rsn_ie, and wpa_make_rsn_ie().

◆ wpa_psk_start()

int wpa_psk_start ( struct net80211_device * dev)
static

Start WPA-PSK authentication.

Parameters
dev802.11 device
Return values
rcReturn status code

Definition at line 51 of file wpa_psk.c.

52{
53 char passphrase[64+1];
54 u8 pmk[WPA_PMK_LEN];
55 int len;
57
59 &net80211_key_setting, passphrase,
60 64 + 1 );
61
62 if ( len <= 0 ) {
63 DBGC ( ctx, "WPA-PSK %p: no passphrase provided!\n", ctx );
65 return -EACCES;
66 }
67
68 pbkdf2_sha1 ( passphrase, len, dev->essid, strlen ( dev->essid ),
69 4096, pmk, WPA_PMK_LEN );
70
71 DBGC ( ctx, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx,
72 passphrase );
74
75 return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
76}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
ring len
Length.
Definition dwmac.h:226
#define DBGC_HD(...)
Definition compiler.h:507
#define DBGC(...)
Definition compiler.h:505
void net80211_deauthenticate(struct net80211_device *dev, int rc)
Deauthenticate from current network and try again.
Definition net80211.c:2391
#define EACCES
Permission denied.
Definition errno.h:299
#define u8
Definition igbvf_osdep.h:40
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:587
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition settings.c:842
void pbkdf2_sha1(const void *passphrase, size_t pass_len, const void *salt, size_t salt_len, int iterations, void *key, size_t key_len)
PBKDF2 key derivation function using SHA1.
Definition sha1extra.c:148
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
struct net_device * netdev
The net_device that wraps us.
Definition net80211.h:789
char essid[IEEE80211_MAX_SSID_LEN+1]
SSID of the access point we are or will be associated with.
Definition net80211.h:962
struct net80211_handshaker * handshaker
Security handshaker being used.
Definition net80211.h:879
void * priv
Pointer to private data.
Definition net80211.h:672
Common context for WPA security handshaking.
Definition wpa.h:292
struct net80211_device * dev
802.11 device we are authenticating for
Definition wpa.h:294
u8 pmk[WPA_PMK_LEN]
The Pairwise Master Key to use in handshaking.
Definition wpa.h:303
int wpa_start(struct net80211_device *dev, struct wpa_common_ctx *ctx, const void *pmk, size_t pmk_len)
Set up generic WPA support to handle 4-Way Handshake.
Definition wpa.c:217
#define WPA_PMK_LEN
Usual length of a Pairwise Master Key.
Definition wpa.h:222

References ctx, DBGC, DBGC_HD, wpa_common_ctx::dev, EACCES, net80211_device::essid, fetch_string_setting(), net80211_device::handshaker, len, net80211_deauthenticate(), net80211_device::netdev, netdev_settings(), pbkdf2_sha1(), wpa_common_ctx::pmk, net80211_handshaker::priv, strlen(), u8, WPA_PMK_LEN, and wpa_start().

◆ wpa_psk_step()

int wpa_psk_step ( struct net80211_device * dev)
static

Step WPA-PSK authentication.

Parameters
dev802.11 device
Return values
rcReturn status code

Definition at line 84 of file wpa_psk.c.

85{
87
88 switch ( ctx->state ) {
89 case WPA_SUCCESS:
90 return 1;
91 case WPA_FAILURE:
92 return -EACCES;
93 default:
94 return 0;
95 }
96}
@ WPA_FAILURE
4-Way Handshake failed
Definition wpa.h:190
@ WPA_SUCCESS
4-Way Handshake succeeded
Definition wpa.h:187

References ctx, wpa_common_ctx::dev, EACCES, net80211_device::handshaker, net80211_handshaker::priv, WPA_FAILURE, and WPA_SUCCESS.

◆ wpa_psk_no_change_key()

int wpa_psk_no_change_key ( struct net80211_device *dev __unused)
static

Do-nothing function; you can't change a WPA key post-authentication.

Parameters
dev802.11 device
Return values
rcReturn status code

Definition at line 104 of file wpa_psk.c.

105{
106 return 0;
107}

References __unused.

◆ wpa_psk_stop()

void wpa_psk_stop ( struct net80211_device * dev)
static

Disable handling of received WPA authentication frames.

Parameters
dev802.11 device

Definition at line 114 of file wpa_psk.c.

115{
116 wpa_stop ( dev );
117}
void wpa_stop(struct net80211_device *dev)
Disable handling of received WPA handshake frames.
Definition wpa.c:261

References wpa_common_ctx::dev, and wpa_stop().

Variable Documentation

◆ __net80211_handshaker

struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker
Initial value:
= {
.protocol = NET80211_SECPROT_PSK,
.init = wpa_psk_init,
.start = wpa_psk_start,
.step = wpa_psk_step,
.change_key = wpa_psk_no_change_key,
.stop = wpa_psk_stop,
.priv_len = sizeof ( struct wpa_common_ctx ),
}
@ NET80211_SECPROT_PSK
Pre-shared key handshaking.
Definition net80211.h:112
static int wpa_psk_no_change_key(struct net80211_device *dev __unused)
Do-nothing function; you can't change a WPA key post-authentication.
Definition wpa_psk.c:104
static int wpa_psk_init(struct net80211_device *dev)
Initialise WPA-PSK state.
Definition wpa_psk.c:40
static int wpa_psk_step(struct net80211_device *dev)
Step WPA-PSK authentication.
Definition wpa_psk.c:84
static void wpa_psk_stop(struct net80211_device *dev)
Disable handling of received WPA authentication frames.
Definition wpa_psk.c:114
static int wpa_psk_start(struct net80211_device *dev)
Start WPA-PSK authentication.
Definition wpa_psk.c:51

WPA-PSK security handshaker.

Definition at line 120 of file wpa_psk.c.

120 {
121 .protocol = NET80211_SECPROT_PSK,
122 .init = wpa_psk_init,
123 .start = wpa_psk_start,
124 .step = wpa_psk_step,
125 .change_key = wpa_psk_no_change_key,
126 .stop = wpa_psk_stop,
127 .priv_len = sizeof ( struct wpa_common_ctx ),
128};