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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER
);
21 #include <gpxe/net80211.h>
22 #include <gpxe/sha1.h>
28 * Frontend for WPA using a pre-shared key.
32 * Initialise WPA-PSK state
34 * @v dev 802.11 device
35 * @ret rc Return status code
37 static int wpa_psk_init ( struct net80211_device
*dev
)
39 return wpa_make_rsn_ie ( dev
, &dev
->rsn_ie
);
43 * Start WPA-PSK authentication
45 * @v dev 802.11 device
46 * @ret rc Return status code
48 static int wpa_psk_start ( struct net80211_device
*dev
)
50 char passphrase
[64+1];
53 struct wpa_common_ctx
*ctx
= dev
->handshaker
->priv
;
55 len
= fetch_string_setting ( netdev_settings ( dev
->netdev
),
56 &net80211_key_setting
, passphrase
,
60 DBGC ( ctx
, "WPA-PSK %p: no passphrase provided!\n", ctx
);
61 net80211_deauthenticate ( dev
, -EACCES
);
65 pbkdf2_sha1 ( passphrase
, len
, dev
->essid
, strlen ( dev
->essid
),
66 4096, pmk
, WPA_PMK_LEN
);
68 DBGC ( ctx
, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx
,
70 DBGC_HD ( ctx
, pmk
, WPA_PMK_LEN
);
72 return wpa_start ( dev
, ctx
, pmk
, WPA_PMK_LEN
);
76 * Step WPA-PSK authentication
78 * @v dev 802.11 device
79 * @ret rc Return status code
81 static int wpa_psk_step ( struct net80211_device
*dev
)
83 struct wpa_common_ctx
*ctx
= dev
->handshaker
->priv
;
85 switch ( ctx
->state
) {
96 * Do-nothing function; you can't change a WPA key post-authentication
98 * @v dev 802.11 device
99 * @ret rc Return status code
101 static int wpa_psk_no_change_key ( struct net80211_device
*dev __unused
)
107 * Disable handling of received WPA authentication frames
109 * @v dev 802.11 device
111 static void wpa_psk_stop ( struct net80211_device
*dev
)
116 /** WPA-PSK security handshaker */
117 struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker
= {
118 .protocol
= NET80211_SECPROT_PSK
,
119 .init
= wpa_psk_init
,
120 .start
= wpa_psk_start
,
121 .step
= wpa_psk_step
,
122 .change_key
= wpa_psk_no_change_key
,
123 .stop
= wpa_psk_stop
,
124 .priv_len
= sizeof ( struct wpa_common_ctx
),