Author: wmb Date: Fri Sep 23 07:00:36 2011 New Revision: 2528 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2528
Log: Wifi - improved user interface for WPA authentication.
Modified: ofw/wifi/eapol.fth ofw/wifi/wifi-cfg.fth
Modified: ofw/wifi/eapol.fth ============================================================================== --- ofw/wifi/eapol.fth Fri Sep 23 06:59:53 2011 (r2527) +++ ofw/wifi/eapol.fth Fri Sep 23 07:00:36 2011 (r2528) @@ -699,8 +699,24 @@ ;
: pmk-ok? ( -- flag ) - wifi-pmk$ nip d# 32 = - atype at-preshared = and + atype at-preshared <> if false exit then + + \ If necessary, compute the PMK (pairwise master key) from the PSK (pre-shared key) + \ The PSK is the user-visible password, whereas the PMK is a hash of the PSK and + \ the SSID which is used in the key exchange. + wifi-pmk$ nip case ( length ) + 0 of ( ) + wifi-psk$ wifi-ssid$ pad d# 32 pbkdf2-sha1 ( ) + pad d# 32 $pmk ( ) + true ( okay? ) + endof + + d# 32 of + true ( okay? ) + endof + + ( default ) false swap + endcase ( okay? ) ;
: key-ok? ( -- ok? )
Modified: ofw/wifi/wifi-cfg.fth ============================================================================== --- ofw/wifi/wifi-cfg.fth Fri Sep 23 06:59:53 2011 (r2527) +++ ofw/wifi/wifi-cfg.fth Fri Sep 23 07:00:36 2011 (r2528) @@ -12,6 +12,7 @@ /n field >wc-wep3 \ pstr (binary, len=5 or 13) /n field >wc-wep4 \ pstr (binary, len=5 or 13) /n field >wc-pmk \ pstr (binary, len=32) + /n field >wc-psk \ pstr (ASCII, arbitrary length) constant /wifi-cfg
/wifi-cfg buffer: ram-wifi-cfg @@ -35,12 +36,22 @@ : pstr@ ( src -- adr len ) @ ?dup if count else " " then ; : wifi-ssid$ ( -- $ ) wifi-cfg >wc-ssid pstr@ ; : wifi-pmk$ ( -- $ ) wifi-cfg >wc-pmk pstr@ ; +: wifi-psk$ ( -- $ ) wifi-cfg >wc-psk pstr@ ; : wifi-wep1$ ( -- $ ) wifi-cfg >wc-wep1 pstr@ ; : wifi-wep2$ ( -- $ ) wifi-cfg >wc-wep2 pstr@ ; : wifi-wep3$ ( -- $ ) wifi-cfg >wc-wep3 pstr@ ; : wifi-wep4$ ( -- $ ) wifi-cfg >wc-wep4 pstr@ ; : wifi-wep-idx ( -- n ) wifi-cfg >wc-wep-idx @ 1- 0 max 4 min ;
+\ The PMK is used internally, rarely entered directly +\ Computing it from the user-visible PSK is relatively expensive, so +\ we store the value for later reuse. The supplicant package calls $pmk +\ to store the computed value in the wifi-cfg data structure. +: $pmk ( pmk$ -- ) + dup d# 32 <> abort" PMK must be 32 bytes" + wifi-cfg >wc-pmk pstr! ( ) +; + defer default-ssids ( -- $ ) ' null$ to default-ssids
0 value ssid-reset? @@ -53,19 +64,6 @@ ['] null$ to default-ssids ;
-: $wep ( wep$ -- ) - dup 5 <> over d# 13 <> and abort" WEP key must be 5 or 13 bytes" - wifi-cfg >wc-wep-idx dup @ ( wep$ adr idx ) - dup 4 >= abort" Too many WEP keys" ( wep$ adr idx ) - 2dup 1+ swap ! ( wep$ adr idx ) - 2* na+ na1+ pstr! ( ) -; - -: $pmk ( pmk$ -- ) - dup d# 32 <> abort" PMK must be 32 bytes" - wifi-cfg >wc-pmk pstr! ( ) -; - \ Stores the result at here : decode-hex ( hex$ -- bin$ ) here >r @@ -79,12 +77,30 @@ r> here over - ( bin-adr bin-len ) ;
+\ WEP keys are fundamentally either 5 or 13 bytes long, but they can be +\ expressed either in straight ASCII or in hexadecimal. In hex, the +\ length is either 10 or 26 bytes, which converts to 5 or 13 ASCII bytes. +: $wep ( wep$ -- ) + dup d# 10 = over d# 26 = if ( wep$ ) + decode-hex ( wep$' ) + else ( wep$ ) + dup 5 <> over d# 13 <> and abort" WEP key must be 5 or 13 ASCII characters or 10 or 26 hex digits" + then ( wep$ ) + + wifi-cfg >wc-wep-idx dup @ ( wep$ adr idx ) + dup 4 >= abort" Too many WEP keys" ( wep$ adr idx ) + 2dup 1+ swap ! ( wep$ adr idx ) + 2* na+ na1+ pstr! ( ) +; + +: $wpa ( psk$ -- ) wifi-cfg >wc-psk pstr! ; + : essid ( "ssid" -- ) 0 parse $essid ; alias wifi essid alias ssid essid -: wep ( "wep" -- ) parse-word decode-hex $wep ; -: pmk ( "pmk" -- ) parse-word decode-hex $pmk ;
+: wep ( "wep" -- ) parse-word $wep ; +: wpa ( "psk" -- ) parse-word $wpa ;
\ ===================================================================== \ Scan wireless networks