Author: wmb
Date: 2007-11-07 08:37:39 +0100 (Wed, 07 Nov 2007)
New Revision: 716
Modified:
cpu/x86/pc/olpc/fsupdate.fth
cpu/x86/pc/olpc/fw.bth
ofw/wifi/data.fth
ofw/wifi/eapol.fth
ofw/wifi/wifi-cfg.fth
Log:
OLPC trac 2740 - Added the ability to associate with one of a list
of Access Point SSIDs and fixed the IP address of the school server.
Filesystem update over the network is now working.
Modified: cpu/x86/pc/olpc/fsupdate.fth
===================================================================
--- cpu/x86/pc/olpc/fsupdate.fth 2007-11-07 07:34:31 UTC (rev 715)
+++ cpu/x86/pc/olpc/fsupdate.fth 2007-11-07 07:37:39 UTC (rev 716)
@@ -180,8 +180,8 @@
repeat ( rem$ )
2drop
;
-: update-devices " disk: sd: http:\\177.18.16.1" ;
+: update-devices " disk: sd: http:\\172.18.0.1" ;
: try-fs-update ( -- )
." Searching for a NAND file system update image." cr
- all-devices$ fs-update-from-list
+ update-devices fs-update-from-list
;
Modified: cpu/x86/pc/olpc/fw.bth
===================================================================
--- cpu/x86/pc/olpc/fw.bth 2007-11-07 07:34:31 UTC (rev 715)
+++ cpu/x86/pc/olpc/fw.bth 2007-11-07 07:37:39 UTC (rev 716)
@@ -413,9 +413,11 @@
support-package: supplicant
fload ${BP}/ofw/wifi/loadpkg.fth
end-support-package
-stand-init:
- " ??,OLPCOFW" $wifi
+
+: olpc-ssids ( -- $ )
+ " OLPCOFW"nschool-mesh-0"nschool-mesh-1"nschool-mesh-2"
;
+' olpc-ssids to default-ssids
[ifdef] use-ppp
fload ${BP}/ofw/ppp/loadppp.fth
Modified: ofw/wifi/data.fth
===================================================================
--- ofw/wifi/data.fth 2007-11-07 07:34:31 UTC (rev 715)
+++ ofw/wifi/data.fth 2007-11-07 07:37:39 UTC (rev 716)
@@ -12,7 +12,7 @@
: enable-rsn ( -- ) " enable-rsn" $call-parent drop ;
: disable-rsn ( -- ) " disable-rsn" $call-parent drop ;
: disable-wep ( -- ) " disable-wep" $call-parent drop ;
-: set-wep ( wep4$ wep3$ wep2$ wep1$ -- ) " set-wep" $call-parent drop ;
+: set-wep ( wep4$ wep3$ wep2$ wep1$ idx -- ) " set-wep" $call-parent drop ;
: associate ( ch ssid$ target-mac$ -- ok? ) " associate" $call-parent ;
: supported-rates$ ( -- adr len ) " supported-rates$" $call-parent ;
: set-common-rates ( adr len -- ) " set-common-rates" $call-parent ;
@@ -80,15 +80,80 @@
1 constant at-eap
2 constant at-preshared
-0 0 2value country-ie \ Address of country IE
+\ =====================================================================
+\ Country/region tables
+: $, ( adr len -- ) here over allot swap move ;
-\ =======================================================================
-\ Instance data
+create countries
+ " US " $, h# 10 c, \ US FCC
+ " CA " $, h# 10 c, \ IC Canada
+ " SG " $, h# 10 c, \ Singapore
+ " EU " $, h# 30 c, \ ETSI
+ " AU " $, h# 30 c, \ Australia
+ " KR " $, h# 30 c, \ Republic of Korea
+ " ES " $, h# 31 c, \ Spain
+ " FR " $, h# 32 c, \ France
+ " JP " $, h# 40 c, \ Japan
+ " " $, h# 0 c, \ END OF LIST
+: country>region ( country$ -- region )
+ countries begin dup 3 + c@ while ( country$ adr )
+ 3dup swap comp 0= if ( country$ adr )
+ nip nip 3 + c@ exit
+ then ( country$ adr )
+ 4 + ( country$ adr' )
+ repeat ( country$ adr' )
+ 3drop 0
+;
+
+create regions
+ \ US Len Channels 1-11, 100mW
+ h# 10 c, 3 c, 1 c, d# 11 c, d# 20 c,
+
+ \ EU Len Channels 1-13, 100mW
+ h# 30 c, 3 c, 1 c, d# 13 c, d# 20 c,
+
+ \ ES Len Channels 10-11, 100mW
+ h# 31 c, 3 c, d# 10 c, 2 c, d# 20 c,
+
+ \ FR Len Channels 10-13, 100mW
+ h# 32 c, 3 c, d# 10 c, 4 c, d# 20 c,
+
+ \ JP Len Channels 1-13, 50mW Channel 14, 50mW
+ h# 40 c, 6 c, 1 c, d# 13 c, d# 16 c, d# 14 c, 1 c, d# 16 c,
+
+ 0 c, \ END OF LIST
+
+\ Seach the regions table
+: region>ch/pwr ( region-code -- ch-adr,len )
+ regions begin dup c@ while ( region-code adr )
+ 2dup c@ = if ( region-code adr )
+ nip ca1+ count exit ( region-code adr )
+ then ( region-code adr )
+ ca1+ count + ( region-code adr' )
+ repeat ( region-code adr )
+ 2drop null$
+;
+
+d# 15 3 * dup constant /country-ie buffer: country-ie-buf
+
+\ country>ie fills country-ie with the country followed by the region info
+
+0 instance value country-ie-len
+
+: set-country-ie ( country$ -- )
+ country-ie-buf /country-ie erase ( country$ )
+ 2dup country>region ?dup 0= if 2drop exit then ( country$ region# )
+ region>ch/pwr dup 0= if 4drop exit then ( country$ ch-adr,len )
+ tuck country-ie-buf 3 + swap move ( country$ len )
+ over + to country-ie-len ( country$ )
+ 3 max country-ie-buf swap move ( )
+;
+
false instance value debug?
false instance value scan?
-false instance value country?
+
0 instance value wifi \ Current wifi-node
: ptk ( -- adr ) wifi >ptk ;
@@ -142,23 +207,6 @@
last-rcnt /rcnt ff fill
;
-
-\ =======================================================================
-\ wifi-cfg data
-
-: adrlen@ ( src -- adr len ) dup @ swap na1+ @ ;
-: wifi-ssid$ ( -- $ ) wifi-cfg >wc-ssid adrlen@ ;
-: wifi-pmk$ ( -- $ ) wifi-cfg >wc-pmk adrlen@ ;
-: wifi-wep1$ ( -- $ ) wifi-cfg >wc-wep1 adrlen@ ;
-: wifi-wep2$ ( -- $ ) wifi-cfg >wc-wep2 adrlen@ ;
-: wifi-wep3$ ( -- $ ) wifi-cfg >wc-wep3 adrlen@ ;
-: wifi-wep4$ ( -- $ ) wifi-cfg >wc-wep4 adrlen@ ;
-: wifi-wep-idx ( -- n ) wifi-cfg >wc-wep-idx @ 1- 0 max 4 min ;
-: wifi-country$ ( -- $ ) wifi-cfg >wc-country 3 ;
-
-: set-country ( adr len -- ) 2dup upper country>ie to country-ie ;
-
-
\ LICENSE_BEGIN
\ Copyright (c) 2007 FirmWorks
\
Modified: ofw/wifi/eapol.fth
===================================================================
--- ofw/wifi/eapol.fth 2007-11-07 07:34:31 UTC (rev 715)
+++ ofw/wifi/eapol.fth 2007-11-07 07:37:39 UTC (rev 716)
@@ -626,8 +626,8 @@
: set-bss-type ( bss-type -- ) dup to bss-type set-bss-type ;
-: set-country-info ( adr len -- )
- country? if 2drop country-ie then \ Overwrite the country IE
+: do-set-country-info ( adr len -- )
+ country-ie-len if 2drop country-ie-buf country-ie-len then \ Override the country IE
3 / 3 * \ Remove pad byte
?dup 0= if drop exit then \ Nothing to set
set-country-info
@@ -680,7 +680,7 @@
kt-wep of wep-ok? endof
( default ) pmk-ok? swap
endcase
- dup 0= if ." Keys in wifi-cfg are not valid" cr then
+ dup if ." found" else ." Keys in wifi-cfg are not valid" then cr
;
h# 0050.f201 constant wpa-tag
@@ -707,15 +707,16 @@
dup 3 find-ie 0= if ." Cannot locate the channel #" cr drop false exit then
drop c@ channel! \ Channel number
dup 6 find-ie if drop 2 + le-w@ set-atim-window then \ ATIM window
- dup 7 find-ie 0= if null$ then set-country-info \ Country channel/power info
+ dup 7 find-ie 0= if null$ then do-set-country-info \ Country channel/power info
dup d# 48 find-ie if set-wpa2-ktype drop key-ok? exit then \ Favor RSN(WPA2) over WPA
dup d# 221 find-ie if 2 pick process-wpa-ie then
drop key-ok?
;
: (do-associate) ( -- ok? )
- ??cr ." Associate with: " ssid$ type cr
+ ??cr ." Associate with: " ssid$ type space
channel ssid$ target-mac$ associate 0= if false exit then
+ cr
ktype=wpa? if
do-key-handshakes
done-group-key?
@@ -724,23 +725,40 @@
then
;
-: do-scan? ( -- scan? ) wifi-ssid$ ssid$ $= not scan? or valid? 0= or ;
+\ Don't rescan the second time unless forced to
+: must-scan? ( -- flag )
+ ssid-reset? false to ssid-reset? ( flag )
+ scan? or false to scan? ( flag' )
+ valid? 0= or
+;
+: scan-ssid? ( ssid$ -- found? )
+ dup 0= if 2drop false exit then
+ ssid!
+ ssid$ " set-ssid" $call-parent
+ ??cr ." Scan for: " ssid$ type space
+ scanbuf /buf scan 0= if ." not found" cr false exit then
+ debug? if scanbuf .scan then
+ ssid$ scanbuf find-ssid 0= if ." not found" cr false exit then
+ init-common-rates
+ ssid-valid? 0= if exit then
+ true valid!
+ report-associate-info
+ true
+;
+: try-scan ( -- okay? )
+ wifi-ssid$ scan-ssid? if true exit then
+ default-ssids begin dup while ( rem$ )
+ newline left-parse-string ( rem$' ssid$ )
+ scan-ssid? if 2drop true exit then ( rem$ )
+ repeat ( rem$ )
+ 2drop false
+;
+
: do-associate ( -- ok? )
disable-protection
- do-scan? if
- wifi-ssid$ ssid!
- wifi-ssid$ " set-ssid" $call-parent
- ??cr ." Scan for: " ssid$ type cr
- scanbuf /buf scan 0= if ." Failed to find: " ssid$ type cr false exit then
- debug? if scanbuf .scan then
- ssid$ scanbuf find-ssid 0= if ." Cannot find: " ssid$ type cr false exit then
- init-common-rates
- ssid-valid? 0= if false exit then
- true valid!
- report-associate-info
- then
- (do-associate)
+ must-scan? if try-scan 0= if false exit then then
+ (do-associate) dup 0= if true to scan? then
;
@@ -771,17 +789,15 @@
ascii , left-parse-string
2dup " debug" $= if true to debug? then
2dup " scan" $= if true to scan? then \ Force scan even if ssid$ is same
- 2dup drop " country" comp 0= if \ Force different country IE
+ 2dup drop " country" comp 0= if \ Force different country IE
2dup [char] = left-parse-string 2drop
- set-country
- true to country?
+ 2dup upper set-country-ie
then
2drop
repeat drop
;
: open ( -- ok? )
- wifi-country$ set-country
my-args parse-args
mac-adr$ init-wifi-data
first-open? if
Modified: ofw/wifi/wifi-cfg.fth
===================================================================
--- ofw/wifi/wifi-cfg.fth 2007-11-07 07:34:31 UTC (rev 715)
+++ ofw/wifi/wifi-cfg.fth 2007-11-07 07:37:39 UTC (rev 716)
@@ -1,155 +1,69 @@
purpose: /package/supplicant configuration data
\ See license at end of file
-
\ =====================================================================
\ Arguments passed onto the /supplicant support package
struct
- 3 field >wc-country \ Country code
- /n 3 - + \ Padding
- /n 2* field >wc-ssid \ adr len (upto 32 ascii bytes)
- /n field >wc-wep-idx \ 1-4
- /n 2* field >wc-wep1 \ adr len (binary, len=5 or 13)
- /n 2* field >wc-wep2 \ adr len
- /n 2* field >wc-wep3 \ adr len
- /n 2* field >wc-wep4 \ adr len
- /n 2* field >wc-pmk \ adr len (binary, len=32)
+ /n field >wc-ssid \ pstr (upto 32 ASCII characters)
+ /n field >wc-wep-idx \ 1-4
+ /n field >wc-wep1 \ pstr (binary, len=5 or 13)
+ /n field >wc-wep2 \ pstr (binary, len=5 or 13)
+ /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)
constant /wifi-cfg
-/wifi-cfg buffer: wifi-cfg
+/wifi-cfg buffer: ram-wifi-cfg
+defer wifi-cfg ' ram-wifi-cfg to wifi-cfg
-\ =====================================================================
-\ Country/region tables
+\ =======================================================================
+\ wifi-cfg data
-: $, ( adr len -- ) here over allot swap move ;
-
-create country-region
-here
- " US " $, 10 c, \ US FCC
- " CA " $, 10 c, \ IC Canada
- " SG " $, 10 c, \ Singapore
- " EU " $, 30 c, \ ETSI
- " AU " $, 30 c, \ Australia
- " KR " $, 30 c, \ Republic of Korea
- " ES " $, 31 c, \ Spain
- " FR " $, 32 c, \ France
- " JP " $, 40 c, \ Japan
-here swap - 4 / constant #country-region
-
-create region-ie-US
-here
- 1 c, d# 11 c, d# 20 c, \ Channels 1-11, 100mW
-here swap - constant /region-ie-US
-
-create region-ie-EU
-here
- 1 c, d# 13 c, d# 20 c, \ Channels 1-13, 100mW
-here swap - constant /region-ie-EU
-
-create region-ie-ES
-here
- d# 10 c, 2 c, d# 20 c, \ Channels 10-11, 100mW
-here swap - constant /region-ie-ES
-
-create region-ie-FR
-here
- d# 10 c, 4 c, d# 20 c, \ Channels 10-13, 100mW
-here swap - constant /region-ie-FR
-
-create region-ie-JP
-here
- 1 c, d# 13 c, d# 16 c, \ Channels 1-13, 50mW
- d# 14 c, 1 c, d# 16 c, \ Channel 14, 50mW
-here swap - constant /region-ie-JP
-
-d# 15 3 * dup constant /country-ie buffer: country-ie
-
-: country>region ( country$ -- region )
- 0 -rot #country-region 0 do ( region adr len )
- country-region i 4 * + 2 pick 2 pick comp
- 0= if rot drop country-region i 4 * + 3 + c@ -rot leave then
- loop 2drop ( region )
+\ Make a packed string of $, optimizing for the case where
+\ $ is already in the dictionary as a packed string.
+: $>pstr ( $ -- pstr )
+ over in-dictionary? if ( $ )
+ over c@ over = if drop 1- exit then
+ then ( $ )
+ here >r ", r> ( pstr )
;
-: region>ch/pwr ( region -- ch-adr,len )
- case
- 10 of region-ie-US /region-ie-US endof
- 30 of region-ie-EU /region-ie-EU endof
- 31 of region-ie-ES /region-ie-ES endof
- 32 of region-ie-FR /region-ie-FR endof
- 40 of region-ie-JP /region-ie-JP endof
- ( default ) null$ rot
- endcase
-;
+: pstr! ( adr len dst -- ) >r $>pstr r> ! ;
-: country>ie ( country$ -- ie-adr,len )
- country-ie /country-ie erase
- 2dup country>region ?dup 0= if 2drop null$ exit then
- region>ch/pwr ?dup 0= if 3drop null$ exit then
- tuck country-ie 3 + swap move
- over + -rot 3 max country-ie swap move
- country-ie swap
-;
+: pstr@ ( src -- adr len ) @ ?dup if count else " " then ;
+: wifi-ssid$ ( -- $ ) wifi-cfg >wc-ssid pstr@ ;
+: wifi-pmk$ ( -- $ ) wifi-cfg >wc-pmk 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 ;
+defer default-ssids ( -- $ ) ' null$ to default-ssids
-\ =====================================================================
-\ Scan wireless networks
-
-: wifi-children ( -- )
- \ Ignore nodes that do not have device_type = wireless-network
- " device_type" get-property if exit then
- get-encoded-string " wireless-network" $= if
- " scan-wifi" method-name 2! do-method?
- then
-;
-
-: scan-wifi ( -- )
- optional-arg-or-/$ ['] wifi-children scan-subtree
-;
-
-: adrlen! ( adr len dst -- ) tuck na1+ ! ! ;
-
-\ Some syntactic sugar
-: preserve$ ( $ -- $' )
- over in-dictionary? if exit then ( $ )
- here >r ", r> count
-;
-
-: $wifi ( country,ssid$ -- )
- dup 0= abort" Empty country,SSID string"
+0 value ssid-reset?
+: $essid ( essid$ -- )
+ dup 0= abort" Empty ESSID string"
wifi-cfg /wifi-cfg erase ( adr len )
- wifi-cfg 3 blank ( adr len )
- [char] , left-parse-string ( tail$ head$ )
- 2 pick 0= if ( null$ ssid$ )
- 2swap 2drop " US" ( ssid$ country$ )
- then ( ssid$ country$ )
- dup 3 > if
- type ." is too long to be a country name." cr
- abort
- then
- wifi-cfg >wc-country swap move ( ssid$ )
- preserve$ ( ssid$' ) \ Save the string
- wifi-cfg >wc-ssid adrlen! ( )
+ wifi-cfg >wc-ssid pstr! ( )
+ true to ssid-reset?
;
: $wep ( wep$ -- )
dup 5 <> over d# 13 <> and abort" WEP key must be 5 or 13 bytes"
- preserve$ ( 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+ adrlen! ( )
+ 2* na+ na1+ pstr! ( )
;
: $pmk ( pmk$ -- )
dup d# 32 <> abort" PMK must be 32 bytes"
- preserve$ ( pmk$' )
- wifi-cfg >wc-pmk adrlen! ( )
+ wifi-cfg >wc-pmk pstr! ( )
;
-
\ Stores the result at here
: decode-hex ( hex$ -- bin$ )
here >r
@@ -163,56 +77,40 @@
r> here over - ( bin-adr bin-len )
;
-: wifi ( "country,ssid" -- ) 0 parse $wifi ;
+: 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 ;
+\ =====================================================================
+\ Scan wireless networks
+
+: wifi-children ( -- )
+ \ Ignore nodes that do not have device_type = wireless-network
+ " device_type" get-property if exit then
+ get-encoded-string " wireless-network" $= if
+ " scan-wifi" method-name 2! do-method?
+ then
+;
+
+: scan-wifi ( -- )
+ optional-arg-or-/$ ['] wifi-children scan-subtree
+;
+
+
0 [if]
\ Sample usage:
-: us$ ( -- $ ) " US " ;
-: dlink-ssid ( -- $ ) " dlink" ;
-: dlink-wep1 ( -- $ ) " "(11 22 33 44 55)" ;
-: dlink-pmk ( -- $ ) " "(db 91 ee 34 a9 3c 73 48 18 35 a2 64 5b 11 d1 34 ec f3 b3 a2 ee ae 33 96 a9 0b 7d b5 1f 2f 48 78)" ;
-: bad-pmk ( -- $ ) " "(00 91 ee 34 a9 3c 73 48 18 35 a2 64 5b 11 d1 34 ec f3 b3 a2 ee ae 33 96 a9 0b 7d b5 1f 2f 48 78)" ;
: set-dlink-wifi-cfg ( -- )
- wifi-cfg /wifi-cfg erase
- us$ wifi-cfg >wc-country swap move
- dlink-ssid wifi-cfg >wc-ssid adrlen!
- 1 wifi-cfg >wc-wep-idx !
- dlink-wep1 wifi-cfg >wc-wep1 adrlen!
- dlink-pmk wifi-cfg >wc-pmk adrlen!
+ " dlink" $ssid
+ " "(11 22 33 44 55)" $wep
+ " "(db 91 ee 34 a9 3c 73 48 18 35 a2 64 5b 11 d1 34 ec f3 b3 a2 ee ae 33 96 a9 0b 7d b5 1f 2f 48 78)" $pmk
;
set-dlink-wifi-cfg
-: us$ ( -- $ ) " US " ;
-: linksys-ssid ( -- $ ) " linksys" ;
-: linksys-wep1 ( -- $ ) " "(11 22 33 44 55)" ;
-: linksys-pmk ( -- $ ) " "(35 8b b7 41 ac fc 04 08 73 67 fb 79 11 cb 18 38 36 ca 54 47 49 73 cd 7a 59 35 e8 6c 4f 20 5f 13)" ;
-: set-linksys-wifi-cfg ( -- )
- wifi-cfg /wifi-cfg erase
- us$ wifi-cfg >wc-country swap move
- linksys-ssid wifi-cfg >wc-ssid adrlen!
- 1 wifi-cfg >wc-wep-idx !
- linksys-wep1 wifi-cfg >wc-wep1 adrlen!
- linksys-pmk wifi-cfg >wc-pmk adrlen!
-;
-set-linksys-wifi-cfg
-
-: us$ ( -- $ ) " US " ;
-: olpc-ssid ( -- $ ) " olpc" ;
-: olpc-wep1 ( -- $ ) " "(11 22 33 44 55)" ;
-: set-olpc-wifi-cfg ( -- )
- wifi-cfg /wifi-cfg erase
- us$ wifi-cfg >wc-country swap move
- olpc-ssid wifi-cfg >wc-ssid adrlen!
- 1 wifi-cfg >wc-wep-idx !
- olpc-wep1 wifi-cfg >wc-wep1 adrlen!
-;
-set-olpc-wifi-cfg
-
[then]
\ LICENSE_BEGIN