iPXE
Functions | Variables
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)
 
static int wpa_psk_init (struct net80211_device *dev)
 Initialise WPA-PSK state. More...
 
static int wpa_psk_start (struct net80211_device *dev)
 Start WPA-PSK authentication. More...
 
static int wpa_psk_step (struct net80211_device *dev)
 Step WPA-PSK authentication. More...
 
static int wpa_psk_no_change_key (struct net80211_device *dev __unused)
 Do-nothing function; you can't change a WPA key post-authentication. More...
 
static void wpa_psk_stop (struct net80211_device *dev)
 Disable handling of received WPA authentication frames. More...
 

Variables

struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker
 WPA-PSK security handshaker. More...
 

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  )

◆ wpa_psk_init()

static 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 39 of file wpa_psk.c.

40 {
41  return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
42 }
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:124

References net80211_device::rsn_ie, and wpa_make_rsn_ie().

◆ wpa_psk_start()

static 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 50 of file wpa_psk.c.

51 {
52  char passphrase[64+1];
53  u8 pmk[WPA_PMK_LEN];
54  int len;
55  struct wpa_common_ctx *ctx = dev->handshaker->priv;
56 
58  &net80211_key_setting, passphrase,
59  64 + 1 );
60 
61  if ( len <= 0 ) {
62  DBGC ( ctx, "WPA-PSK %p: no passphrase provided!\n", ctx );
64  return -EACCES;
65  }
66 
67  pbkdf2_sha1 ( passphrase, len, dev->essid, strlen ( dev->essid ),
68  4096, pmk, WPA_PMK_LEN );
69 
70  DBGC ( ctx, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx,
71  passphrase );
72  DBGC_HD ( ctx, pmk, WPA_PMK_LEN );
73 
74  return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
75 }
struct net80211_device * dev
802.11 device we are authenticating for
Definition: wpa.h:294
#define DBGC(...)
Definition: compiler.h:505
#define EACCES
Permission denied.
Definition: errno.h:298
void net80211_deauthenticate(struct net80211_device *dev, int rc)
Deauthenticate from current network and try again.
Definition: net80211.c:2390
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
u8 pmk[WPA_PMK_LEN]
The Pairwise Master Key to use in handshaking.
Definition: wpa.h:303
char essid[IEEE80211_MAX_SSID_LEN+1]
SSID of the access point we are or will be associated with.
Definition: net80211.h:962
#define WPA_PMK_LEN
Usual length of a Pairwise Master Key.
Definition: wpa.h:222
void * priv
Pointer to private data.
Definition: net80211.h:672
Common context for WPA security handshaking.
Definition: wpa.h:291
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:841
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
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define DBGC_HD(...)
Definition: compiler.h:507
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
struct net80211_handshaker * handshaker
Security handshaker being used.
Definition: net80211.h:879
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:216
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
uint32_t len
Length.
Definition: ena.h:14
uint8_t u8
Definition: stdint.h:19

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(), WPA_PMK_LEN, and wpa_start().

◆ wpa_psk_step()

static 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 83 of file wpa_psk.c.

84 {
85  struct wpa_common_ctx *ctx = dev->handshaker->priv;
86 
87  switch ( ctx->state ) {
88  case WPA_SUCCESS:
89  return 1;
90  case WPA_FAILURE:
91  return -EACCES;
92  default:
93  return 0;
94  }
95 }
struct net80211_device * dev
802.11 device we are authenticating for
Definition: wpa.h:294
#define EACCES
Permission denied.
Definition: errno.h:298
void * priv
Pointer to private data.
Definition: net80211.h:672
4-Way Handshake succeeded
Definition: wpa.h:187
Common context for WPA security handshaking.
Definition: wpa.h:291
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct net80211_handshaker * handshaker
Security handshaker being used.
Definition: net80211.h:879
4-Way Handshake failed
Definition: wpa.h:190

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

◆ wpa_psk_no_change_key()

static 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 103 of file wpa_psk.c.

104 {
105  return 0;
106 }

◆ wpa_psk_stop()

static void wpa_psk_stop ( struct net80211_device dev)
static

Disable handling of received WPA authentication frames.

Parameters
dev802.11 device

Definition at line 113 of file wpa_psk.c.

114 {
115  wpa_stop ( dev );
116 }
struct net80211_device * dev
802.11 device we are authenticating for
Definition: wpa.h:294
void wpa_stop(struct net80211_device *dev)
Disable handling of received WPA handshake frames.
Definition: wpa.c:260

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 ),
}
static int wpa_psk_step(struct net80211_device *dev)
Step WPA-PSK authentication.
Definition: wpa_psk.c:83
static int wpa_psk_start(struct net80211_device *dev)
Start WPA-PSK authentication.
Definition: wpa_psk.c:50
Pre-shared key handshaking.
Definition: net80211.h:112
static void wpa_psk_stop(struct net80211_device *dev)
Disable handling of received WPA authentication frames.
Definition: wpa_psk.c:113
static int wpa_psk_init(struct net80211_device *dev)
Initialise WPA-PSK state.
Definition: wpa_psk.c:39
Common context for WPA security handshaking.
Definition: wpa.h:291
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:103

WPA-PSK security handshaker.

Definition at line 119 of file wpa_psk.c.