iPXE
wpa_psk.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 FILE_SECBOOT ( FORBIDDEN );
22 
23 #include <string.h>
24 #include <ipxe/net80211.h>
25 #include <ipxe/sha1.h>
26 #include <ipxe/wpa.h>
27 #include <errno.h>
28 
29 /** @file
30  *
31  * Frontend for WPA using a pre-shared key.
32  */
33 
34 /**
35  * Initialise WPA-PSK state
36  *
37  * @v dev 802.11 device
38  * @ret rc Return status code
39  */
40 static int wpa_psk_init ( struct net80211_device *dev )
41 {
42  return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
43 }
44 
45 /**
46  * Start WPA-PSK authentication
47  *
48  * @v dev 802.11 device
49  * @ret rc Return status code
50  */
51 static int wpa_psk_start ( struct net80211_device *dev )
52 {
53  char passphrase[64+1];
54  u8 pmk[WPA_PMK_LEN];
55  int len;
56  struct wpa_common_ctx *ctx = dev->handshaker->priv;
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 );
73  DBGC_HD ( ctx, pmk, WPA_PMK_LEN );
74 
75  return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
76 }
77 
78 /**
79  * Step WPA-PSK authentication
80  *
81  * @v dev 802.11 device
82  * @ret rc Return status code
83  */
84 static int wpa_psk_step ( struct net80211_device *dev )
85 {
86  struct wpa_common_ctx *ctx = dev->handshaker->priv;
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 }
97 
98 /**
99  * Do-nothing function; you can't change a WPA key post-authentication
100  *
101  * @v dev 802.11 device
102  * @ret rc Return status code
103  */
105 {
106  return 0;
107 }
108 
109 /**
110  * Disable handling of received WPA authentication frames
111  *
112  * @v dev 802.11 device
113  */
114 static void wpa_psk_stop ( struct net80211_device *dev )
115 {
116  wpa_stop ( dev );
117 }
118 
119 /** WPA-PSK security handshaker */
120 struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker = {
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 };
struct net80211_device * dev
802.11 device we are authenticating for
Definition: wpa.h:294
static int wpa_psk_step(struct net80211_device *dev)
Step WPA-PSK authentication.
Definition: wpa_psk.c:84
Error codes.
static int wpa_psk_start(struct net80211_device *dev)
Start WPA-PSK authentication.
Definition: wpa_psk.c:51
#define DBGC(...)
Definition: compiler.h:505
union ieee80211_ie * rsn_ie
RSN or WPA information element to include with association.
Definition: net80211.h:932
#define EACCES
Permission denied.
Definition: errno.h:299
FILE_LICENCE(GPL2_OR_LATER)
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void net80211_deauthenticate(struct net80211_device *dev, int rc)
Deauthenticate from current network and try again.
Definition: net80211.c:2391
FILE_SECBOOT(FORBIDDEN)
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:587
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 definitions for all types of WPA-protected networks.
Pre-shared key handshaking.
Definition: net80211.h:112
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
ring len
Length.
Definition: dwmac.h:231
4-Way Handshake succeeded
Definition: wpa.h:187
enum net80211_security_proto protocol
The security handshaking protocol implemented.
Definition: net80211.h:567
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_init(struct net80211_device *dev)
Initialise WPA-PSK state.
Definition: wpa_psk.c:40
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: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
int wpa_make_rsn_ie(struct net80211_device *dev, union ieee80211_ie **ie_ret)
Construct RSN or WPA information element.
Definition: wpa.c:125
The iPXE 802.11 MAC layer.
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
#define DBGC_HD(...)
Definition: compiler.h:507
void wpa_stop(struct net80211_device *dev)
Disable handling of received WPA handshake frames.
Definition: wpa.c:261
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
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:217
Interface to an 802.11 security handshaking protocol.
Definition: net80211.h:564
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
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
SHA-1 algorithm.
struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker
WPA-PSK security handshaker.
Definition: wpa_psk.c:120
String functions.
uint8_t u8
Definition: stdint.h:20
4-Way Handshake failed
Definition: wpa.h:190