wpa_psk.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <gpxe/net80211.h>
00022 #include <gpxe/sha1.h>
00023 #include <gpxe/wpa.h>
00024 #include <errno.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 static int wpa_psk_init ( struct net80211_device *dev )
00038 {
00039 return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 static int wpa_psk_start ( struct net80211_device *dev )
00049 {
00050 char passphrase[64+1];
00051 u8 pmk[WPA_PMK_LEN];
00052 int len;
00053 struct wpa_common_ctx *ctx = dev->handshaker->priv;
00054
00055 len = fetch_string_setting ( netdev_settings ( dev->netdev ),
00056 &net80211_key_setting, passphrase,
00057 64 + 1 );
00058
00059 if ( len <= 0 ) {
00060 DBGC ( ctx, "WPA-PSK %p: no passphrase provided!\n", ctx );
00061 net80211_deauthenticate ( dev, -EACCES );
00062 return -EACCES;
00063 }
00064
00065 pbkdf2_sha1 ( passphrase, len, dev->essid, strlen ( dev->essid ),
00066 4096, pmk, WPA_PMK_LEN );
00067
00068 DBGC ( ctx, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx,
00069 passphrase );
00070 DBGC_HD ( ctx, pmk, WPA_PMK_LEN );
00071
00072 return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 static int wpa_psk_step ( struct net80211_device *dev )
00082 {
00083 struct wpa_common_ctx *ctx = dev->handshaker->priv;
00084
00085 switch ( ctx->state ) {
00086 case WPA_SUCCESS:
00087 return 1;
00088 case WPA_FAILURE:
00089 return -EACCES;
00090 default:
00091 return 0;
00092 }
00093 }
00094
00095
00096
00097
00098
00099
00100
00101 static int wpa_psk_no_change_key ( struct net80211_device *dev __unused )
00102 {
00103 return 0;
00104 }
00105
00106
00107
00108
00109
00110
00111 static void wpa_psk_stop ( struct net80211_device *dev )
00112 {
00113 wpa_stop ( dev );
00114 }
00115
00116
00117 struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker = {
00118 .protocol = NET80211_SECPROT_PSK,
00119 .init = wpa_psk_init,
00120 .start = wpa_psk_start,
00121 .step = wpa_psk_step,
00122 .change_key = wpa_psk_no_change_key,
00123 .stop = wpa_psk_stop,
00124 .priv_len = sizeof ( struct wpa_common_ctx ),
00125 };