2 * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
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.
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.
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
20 FILE_LICENCE ( GPL2_OR_LATER );
23 #include <ipxe/net80211.h>
24 #include <ipxe/sha1.h>
30 * Frontend for WPA using a pre-shared key.
34 * Initialise WPA-PSK state
36 * @v dev 802.11 device
37 * @ret rc Return status code
39 static int wpa_psk_init ( struct net80211_device *dev )
41 return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
45 * Start WPA-PSK authentication
47 * @v dev 802.11 device
48 * @ret rc Return status code
50 static int wpa_psk_start ( struct net80211_device *dev )
52 char passphrase[64+1];
55 struct wpa_common_ctx *ctx = dev->handshaker->priv;
57 len = fetch_string_setting ( netdev_settings ( dev->netdev ),
58 &net80211_key_setting, passphrase,
62 DBGC ( ctx, "WPA-PSK %p: no passphrase provided!\n", ctx );
63 net80211_deauthenticate ( dev, -EACCES );
67 pbkdf2_sha1 ( passphrase, len, dev->essid, strlen ( dev->essid ),
68 4096, pmk, WPA_PMK_LEN );
70 DBGC ( ctx, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx,
72 DBGC_HD ( ctx, pmk, WPA_PMK_LEN );
74 return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
78 * Step WPA-PSK authentication
80 * @v dev 802.11 device
81 * @ret rc Return status code
83 static int wpa_psk_step ( struct net80211_device *dev )
85 struct wpa_common_ctx *ctx = dev->handshaker->priv;
87 switch ( ctx->state ) {
98 * Do-nothing function; you can't change a WPA key post-authentication
100 * @v dev 802.11 device
101 * @ret rc Return status code
103 static int wpa_psk_no_change_key ( struct net80211_device *dev __unused )
109 * Disable handling of received WPA authentication frames
111 * @v dev 802.11 device
113 static void wpa_psk_stop ( struct net80211_device *dev )
118 /** WPA-PSK security handshaker */
119 struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker = {
120 .protocol = NET80211_SECPROT_PSK,
121 .init = wpa_psk_init,
122 .start = wpa_psk_start,
123 .step = wpa_psk_step,
124 .change_key = wpa_psk_no_change_key,
125 .stop = wpa_psk_stop,
126 .priv_len = sizeof ( struct wpa_common_ctx ),