wpa_psk.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 /** @file
00027  *
00028  * Frontend for WPA using a pre-shared key.
00029  */
00030 
00031 /**
00032  * Initialise WPA-PSK state
00033  *
00034  * @v dev       802.11 device
00035  * @ret rc      Return status code
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  * Start WPA-PSK authentication
00044  *
00045  * @v dev       802.11 device
00046  * @ret rc      Return status code
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  * Step WPA-PSK authentication
00077  *
00078  * @v dev       802.11 device
00079  * @ret rc      Return status code
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  * Do-nothing function; you can't change a WPA key post-authentication
00097  *
00098  * @v dev       802.11 device
00099  * @ret rc      Return status code
00100  */
00101 static int wpa_psk_no_change_key ( struct net80211_device *dev __unused )
00102 {
00103         return 0;
00104 }
00105 
00106 /**
00107  * Disable handling of received WPA authentication frames
00108  *
00109  * @v dev       802.11 device
00110  */
00111 static void wpa_psk_stop ( struct net80211_device *dev )
00112 {
00113         wpa_stop ( dev );
00114 }
00115 
00116 /** WPA-PSK security handshaker */
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 };

Generated on Tue Apr 6 20:01:10 2010 for gPXE by  doxygen 1.5.7.1