Author: wmb Date: 2008-12-14 18:43:28 +0100 (Sun, 14 Dec 2008) New Revision: 1033
Modified: cpu/x86/pc/olpc/nandcastui.fth cpu/x86/pc/olpc/versions.fth cpu/x86/pc/olpc/wifichannel.fth ofw/wifi/eapol.fth Log: OLPC - Improved NANDblaster WIFI spectrum analysis, with ".wifi" command.
Modified: cpu/x86/pc/olpc/nandcastui.fth =================================================================== --- cpu/x86/pc/olpc/nandcastui.fth 2008-12-12 00:13:49 UTC (rev 1032) +++ cpu/x86/pc/olpc/nandcastui.fth 2008-12-14 17:43:28 UTC (rev 1033) @@ -101,3 +101,27 @@ false to already-go? " boot rom:nb_rx 10.20.0.16,,10.20.0.44" eval ; + +\ LICENSE_BEGIN +\ Copyright (c) 2008 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Modified: cpu/x86/pc/olpc/versions.fth =================================================================== --- cpu/x86/pc/olpc/versions.fth 2008-12-12 00:13:49 UTC (rev 1032) +++ cpu/x86/pc/olpc/versions.fth 2008-12-14 17:43:28 UTC (rev 1033) @@ -2,7 +2,7 @@
\ The overall firmware revision macro: FW_MAJOR E -macro: FW_MINOR 24 +macro: FW_MINOR 24b
\ The EC microcode macro: EC_VERSION e21
Modified: cpu/x86/pc/olpc/wifichannel.fth =================================================================== --- cpu/x86/pc/olpc/wifichannel.fth 2008-12-12 00:13:49 UTC (rev 1032) +++ cpu/x86/pc/olpc/wifichannel.fth 2008-12-14 17:43:28 UTC (rev 1033) @@ -1,13 +1,22 @@ +purpose: Analyze WIFI spectrum to find good channels for NANDblaster +\ See license at end of file
- 0 value wlan-ih d# 2048 buffer: scan-buf
+: $call-wlan ( args method$ -- res ) wlan-ih $call-method ; +: stop-mesh ( -- ) " mesh-stop" $call-wlan drop ; +: start-mesh ( channel# -- ) + " mesh-start" $call-wlan drop + d# 100 0 " set-beacon" $call-wlan +; + : open-wlan ( -- ) " /wlan:force" open-dev to wlan-ih wlan-ih 0= abort" Can't open wireless LAN" - " " " set-ssid" wlan-ih $call-method + " " " set-ssid" $call-wlan ; +: close-wlan ( -- ) wlan-ih ?dup if close-dev 0 to wlan-ih then ;
: analyze-beacons ( -- total-rssi max-rssi #beacons ) 0 0 ( tot-rssi max-rssi ) @@ -39,18 +48,64 @@ drop r> ( tot-rssi max-rssi #beacons ) ;
+0 value this-rssi +0 0 2value this-ssid +0 value this-channel +: brief-.ap ( adr -- adr' ) + dup 8 + c@ to this-rssi ( adr ) + dup le-w@ ( adr len ) + swap 2 + swap d# 19 /string ( adr' len' ) + begin dup 0> while ( adr len ) + over c@ case ( adr len ) + 0 of over 2+ dup 1- c@ to this-ssid endof + 3 of over 2+ c@ to this-channel endof + endcase ( adr len ) + over 1+ c@ 2 + /string ( adr' len' ) + repeat drop ( adr ) + + push-decimal + ." Channel: " this-channel 2 u.r ( adr ) + ." Strength: " this-rssi 2 u.r ( adr ) + pop-base + ." SSID: " this-ssid type ( adr ) + cr ( adr ) +; + +0 value this-#beacons + +d# 14 constant max-channel# +max-channel# 1+ array >#beacons +max-channel# 1+ array >channel-speed + +1 1 lshift 1 6 lshift or 1 d# 11 lshift or constant def-channel-mask + +: channel-bounds ( -- limit start ) max-channel# 1+ 1 ; + +: channel-avail? ( channel# -- flag ) 1 swap lshift def-channel-mask and ; + +: show-beacons ( -- #beacons ) + \ The first AP structure begins at offset 3 within the scan result + scan-buf 3 + ( 'ap ) + scan-buf 2 + c@ dup >r ( 'ap #beacons ) + 0 ?do ( 'ap ) \ Byte 2 is number of beacons + brief-.ap ( 'ap' ) + loop ( 'ap ) + drop r> ( #beacons ) +; + +: scan-channel ( channel# -- actual ) + 1 swap lshift " set-channel-mask" $call-wlan + scan-buf d# 2048 " scan" $call-wlan ( actual ) +; + : channel-stats ( channel# -- total-rssi max-rssi #beacons ) - 1 swap lshift " set-channel-mask" wlan-ih $call-method - scan-buf d# 2048 " scan" wlan-ih $call-method ( actual ) - if + scan-channel if analyze-beacons else 0 0 0 then ;
-d# 15 constant rssi-limit - \ Keep the rssi,chan pair with the lowest max-rssi value : lowest-rssi ( max-rssiN chanN max-rssiM chanM -- max-rssiP P ) 3 pick 2 pick ( max-rssiN chanN max-rssiM chanM max-rssiN max-rssiM ) @@ -67,46 +122,59 @@ then ( max-rssiN' N' no-beacons? ) ;
-: scan-mesh-channels ( -- max-rssi chan# ) - h# ffffffff 0 ( max-rssi0 0 ) \ This high rssi always loses - d# 11 try-channel if exit then ( max-rssiN chanN ) - d# 6 try-channel if exit then ( max-rssiN chanN ) - d# 1 try-channel drop ( max-rssi chan# ) -; - : quietest-mesh-channel ( -- max-rssi chan# ) open-wlan - scan-mesh-channels - wlan-ih close-dev + h# ffffffff 0 \ High RSSI for starters ( max-rssi0 0 ) + channel-bounds do ( max-rssiN chanN ) + i channel-avail? if ( max-rssiN chanN ) + i try-channel ?leave ( max-rssiN chanN ) + then + loop + close-wlan ;
+d# 10 constant rssi-threshold +: quietest-auto-channel ( -- chan# ) + quietest-mesh-channel ( rssi chan# ) + swap rssi-threshold > if ( chan# ) + ." No wireless channels are quiet. The quietest is channel " dup .d cr ( chan# ) + " Do you want to use that channel" confirmedn? ( chan# proceed? ) + 0= abort" Stopping." + then ( chan# ) +; + : multinand-traffic? ( channel# -- flag ) - " mesh-start" wlan-ih $call-method drop - d# 100 0 " set-beacon" wlan-ih $call-method - " "(01 00 5e 7e 01 02)" " set-multicast" wlan-ih $call-method + start-mesh + " "(01 00 5e 7e 01 02)" " set-multicast" $call-wlan d# 300 0 do - scan-buf d# 2048 " read" wlan-ih $call-method ( actual ) + scan-buf d# 2048 " read" $call-wlan ( actual ) 0> if ( ) scan-buf d# 12 + " XO" comp 0= if ( ) - " mesh-stop" wlan-ih $call-method drop ( ) + stop-mesh ( ) true unloop exit then then 1 ms loop - " mesh-stop" wlan-ih $call-method drop + stop-mesh false ; + : search-channels ( -- true | chan# false ) - d# 11 multinand-traffic? if d# 11 false exit then - d# 6 multinand-traffic? if d# 6 false exit then - d# 1 multinand-traffic? if d# 1 false exit then + channel-bounds do ( ) + i channel-avail? if ( ) + i multinand-traffic? if ( ) + i unloop false exit + then ( ) + then ( ) + loop ( ) true ; + : find-multinand-server ( -- true | chan# false ) open-wlan search-channels - wlan-ih close-dev + close-wlan ; : nandblaster ( -- ) find-multinand-server abort" No multicast NAND server" ( chan# ) @@ -114,16 +182,146 @@ ; alias nb nandblaster
-d# 10 constant rssi-threshold +d# 1514 buffer: mesh-test-buf + +: (channel-speed) ( channel# -- kb/sec ) + dup >r start-mesh + " enable-multicast" $call-wlan + 1 " mesh-set-ttl" $call-wlan + h# b " mesh-set-bcast" $call-wlan + + " "(00 00 00 00 00 00 01 00 5e 7e 01 01)XO" mesh-test-buf swap move + + tsc@ + d# 1000 0 do + mesh-test-buf d# 1514 " write" $call-wlan drop + loop + tsc@ 2swap d- ms-factor um/mod nip ( ms ) + d# 1,514,000 swap / ( kb/sec ) + stop-mesh ( kb/sec ) + dup r> >channel-speed ! ( kb/sec ) +; +: channel-speed ( channel# -- kb/sec ) + open-wlan (channel-speed) close-wlan +; + +: ?faster ( chan# kb/sec this-chan# -- chan#' kb/sec ) + dup (channel-speed) ( chan# kb/sec this-chan# this-kb/sec ) + 2 pick over u< if 2swap then ( chan# kb/sec this-chan# this-kb/sec ) + 2drop +; + +: (.channel-speed) ( channel# -- ) + push-decimal + ." Channel: " dup 2 u.r ." " + (channel-speed) + <# u# u# u# [char] . hold u# u#> type ." Mbytes/sec" cr + pop-base +; + +: .wifi-speeds ( -- ) + open-wlan + channel-bounds do + i channel-avail? if + i (.channel-speed) + then + loop + close-wlan +; + +: (.channel-beacons) ( channel# -- ) + dup >r ( r: channel# ) + scan-channel if ( r: channel# ) + show-beacons ( #beacons r: channel# ) + else ( r: channel# ) + 0 ( #beacons r: channel# ) + then ( #beacons r: channel# ) + r> >#beacons ! ( ) +; + +: .wifi-beacons ( -- ) + open-wlan + channel-bounds do + i channel-avail? if + i (.channel-beacons) + then + loop + close-wlan +; + +: .wifi ( -- ) + ." Beacons: " cr + .wifi-beacons + cr + ." Max transmit speeds: (congestion dependent)" cr + .wifi-speeds +; + +d# 2000 constant wifi-speed-threshold +: quiet&fast? ( channel# -- flag ) + dup >#beacons @ if drop false exit then ( channel# ) + >channel-speed @ wifi-speed-threshold > +; + +: quiet-channel-mask ( -- mask ) + 0 ( mask ) + channel-bounds do ( mask ) + i channel-avail? if ( mask ) + i >#beacons @ 0= if ( mask ) + 1 i lshift or ( mask' ) + then ( mask ) + then ( mask ) + loop ( mask ) +; + +: fastest-of ( mask -- chan# ) + 0 0 + channel-bounds do ( mask chan# speed ) + 2 pick 1 i lshift and if ( mask chan# speed ) + dup i >channel-speed @ < if ( mask chan# speed ) + 2drop i i >channel-speed @ ( mask chan#' speed' ) + then ( mask chan# speed ) + then ( mask chan# speed ) + loop ( mask chan# speed ) + rot 2drop +; + : nb-auto-channel ( -- chan# ) - quietest-mesh-channel ( rssi chan# ) - swap rssi-threshold > if ( chan# ) - ." No wireless channels are quiet. The quietest is channel " dup .d cr ( chan# ) - " Do you want to use that channel" confirmedn? ( chan# proceed? ) - 0= abort" Stopping." - then ( chan# ) + ." Analyzing WIFI spectrum" cr + cr + .wifi + + quiet-channel-mask ?dup 0= if def-channel-mask then + fastest-of + cr + ." Using channel " dup .d cr + d# 4000 ms ;
: nb-clone ( -- ) nb-auto-channel #nb-clone ; : nb-secure ( -- ) nb-auto-channel #nb-secure-def ; : nb-update ( -- ) nb-auto-channel #nb-update-def ; + +\ LICENSE_BEGIN +\ Copyright (c) 2008 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Modified: ofw/wifi/eapol.fth =================================================================== --- ofw/wifi/eapol.fth 2008-12-12 00:13:49 UTC (rev 1032) +++ ofw/wifi/eapol.fth 2008-12-14 17:43:28 UTC (rev 1033) @@ -500,7 +500,7 @@
: .ap ( adr -- ) ." Address: " dup 2 + .enaddr cr - ." RSSI: " dup 8 + c@ u. cr + ." RSSI: " dup 8 + c@ .d cr ." Beacon interval: " dup d# 17 + le-w@ .d cr ." Capabilities: " dup d# 19 + le-w@ cr .cap dup le-w@ swap 2 + swap d# 19 /string ( adr' len' )
openfirmware@openfirmware.info