OpenWrt Forum Archive

Topic: b43, STA mode. scanning problem

The content of this topic has been archived on 14 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm running the Feb 16th snapshot on a Linksys WRTSL54GS. From reading this forum, the b43 support should be fairly stable.  dmesg sees the adapter.  When I try to scan for available APs I get

root@OpenWrt:/etc/config# iwlist wlan0 scan 
wlan0     Interface doesn't support scanning : Device or resource busy

root@OpenWrt:/etc/config#

Is scanning broken? (I know it's a work in progress, and I'm not complaining.  I'm asking for information to see if I need to go back to the 2.4 kernel.)

b44.c:v2.0
eth0: Broadcom 44xx/47xx 10/100BaseT Ethernet 00:14:bf:e5:2c:50
b44: eth1: PHY Reset would not complete.
eth1: Broadcom 44xx/47xx 10/100BaseT Ethernet 00:90:4c:60:00:2b
BCM47xx Watchdog Timer enabled (30 seconds, nowayout)
TCP westwood registered
NET: Registered protocol family 17
Bridge firewalling registered
802.1Q VLAN Support v1.8 Ben Greear <greearb@candelatech.com>
All bugs added by David S. Miller <davem@redhat.com>
VFS: Mounted root (squashfs filesystem) readonly on device 31:2.
Freeing unused kernel memory: 136k freed
Please be patient, while OpenWrt loads ...
diag: Detected 'Linksys WRTSL54GS'
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
roboswitch: Probing device eth0: found a 5325! It's a 5350.
b44: eth0: powering down PHY
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth0: powering down PHY
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth0: powering down PHY
mini_fo: using base directory: /
mini_fo: using storage directory: /jffs
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth0: powering down PHY
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth0: powering down PHY
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth0: powering down PHY
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
b44: eth1: Link is up at 100 Mbps, full duplex.
b44: eth1: Flow control is off for TX and off for RX.
b44: eth1: powering down PHY
b44: eth1: Link is up at 100 Mbps, full duplex.
b44: eth1: Flow control is off for TX and off for RX.
Generic kernel compatibility enabled based on linux-next next-20100113
cfg80211: Calling CRDA to update world regulatory domain
cfg80211: World regulatory domain updated:
    (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
    (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
    (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
    (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
    (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
    (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
usbcore: Unknown symbol utf16s_to_utf8s
b43-phy0: Broadcom 4318 WLAN found (core revision 9)
phy0: Selected rate control algorithm 'minstrel'
Registered led device: b43-phy0::tx
Registered led device: b43-phy0::rx
Registered led device: b43-phy0::radio
Broadcom 43xx driver loaded [ Features: PNL, Firmware-ID: FW13 ]
Broadcom 43xx-legacy driver loaded [ Features: PLID, Firmware-ID: FW10 ]
b43 ssb1:0: firmware: requesting b43/ucode5.fw
b43 ssb1:0: firmware: requesting b43/pcm5.fw
b43 ssb1:0: firmware: requesting b43/b0g0initvals5.fw
b43 ssb1:0: firmware: requesting b43/b0g0bsinitvals5.fw
b43-phy0: Loading firmware version 478.104 (2008-07-01 00:50:23)
b43-phy0: Loading firmware version 478.104 (2008-07-01 00:50:23)
root@OpenWrt:~# iwconfig
lo        no wireless extensions.

eth0      no wireless extensions.

eth1      no wireless extensions.

wlan0     IEEE 802.11bg  Mode:Managed  Access Point: Not-Associated   
          Tx-Power=20 dBm   
          RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
root@OpenWrt:/etc/config# cat network
#### VLAN configuration 
config switch eth0
    option enable   1

config switch_vlan eth0_0
    option device   "eth0"
    option vlan     0
    option ports    "0 1 2 3 4 5u"

#### Loopback configuration
config interface loopback
    option ifname    "lo"
    option proto    static
    option ipaddr    127.0.0.1
    option netmask    255.0.0.0


#### LAN configuration
config interface lan
#    option type     bridge
    option ifname    "eth0"
    option macaddr    "00:14:BF:E5:2C:50"
    option proto    static
    option ipaddr    192.168.1.1
    option netmask    255.255.255.0


#### WAN configuration
config interface    wan
    option ifname    "eth1"
    option macaddr    "00:14:bf:e5:2c:51"
    option proto    dhcp
    
#### WiFi configuration
config interface wifi
#    option ifname   "wlan0"
    option proto    dhcp
    option defaultroute 1
root@OpenWrt:/etc/config# cat  wireless
config wifi-device  radio0
    option type     mac80211
    option channel  5
    option macaddr    00:10:18:90:20:db
#    option hwmode    11g

    # REMOVE THIS LINE TO ENABLE WIFI:
#    option disabled 1

config wifi-iface
    option device   radio0
    option network  wifi
    option mode     sta
    option ssid     xxx
    option encryption psk2
    option key    xxx

OK, I got it figured out. In order for it to scan, wifi must be up, but it must not be running wpa_supplicant - no WPA encryption.  Then scanning works.

Which brings me to my next problem:  I can't get WPA2 to work. Here's my home AP, which worked fine with 2.4 + evil binary blob.

          Cell 04 - Address: xx:xx:xx
                    Channel:5
                    Frequency:2.432 GHz (Channel 5)
                    Quality=37/70  Signal level=-73 dBm  
                    Encryption key:on
                    ESSID:"EluOnHea2"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=00000029b6f006f3
                    Extra: Last beacon: 776ms ago
                    (Unknown Wireless Token 0x8C05)

Note the Unknown Wireless Token part.  I have no idea what that's about, other than the fact that the scan is not picking up the WPA2 encryption on the AP.  Does b43 work?  Or should I cut my losses and revert back to 2.4?

Hi I have the same problem on tp-link tl-wr941nd V4. How did you off wpa_supplicant?

cat /etc/config/wireless

config 'wifi-device' 'radio0'
        option 'type' 'mac80211'
        option 'macaddr' '00:27:19:1b:cc:62'
        option 'htmode' 'HT20'             
        list 'ht_capab' 'SHORT-GI-40'       
        list 'ht_capab' 'DSSS_CCK-40'       
        option 'country' 'ru'               
        option 'hwmode' '11bg'             
        option 'channel' '6'               
        option 'disabled' '0'

config 'wifi-iface'
        option 'device' 'radio0'
        option 'ssid' 'OpenWrt'
        option 'encryption' 'none'
        option 'network' 'wan'
        option 'bssid' ''
        option 'mode' 'sta'
        option 'hidden' '0'
        option 'isolate' '0'
        option 'txpower' '20'
        option 'bgscan' '0'

cat /etc/config/network
config interface loopback
        option ifname   lo
        option proto    static
        option ipaddr   127.0.0.1
        option netmask  255.0.0.0
config interface lan
        option ifname   eth0
        option type     bridge
        option proto    static
        option ipaddr   192.168.1.1
        option netmask  255.255.255.0
config interface wan
        option ifname   eth1
        option proto    dhcp

(Last edited by alif on 2 Mar 2010, 20:03)

This is the code I use - look in the /tmp/broken if statement.  I use a couple of ports on my home server to test for connectivity; one on 13999 returns the date and the other on port 13998 just returns a known string.

#!/bin/ash

aap_connect () {
        echo connecting $2 $3
        mkdir -p /tmp/cell
        rm -f /tmp/cell/*

        if [ -f /tmp/broken ] ; then
                for p in /var/run/*$3.pid ; do
                        echo killing $p
                        kill -9 `cat $p`
                        rm $p
                        done
                sleep 1
                echo bringing up $3
                ifconfig $3 up
#               wifi up
                sleep 1
        fi

        sleep 3

        iwlist $3 scan > /tmp/scan.out

        awk 'BEGIN{IGNORECASE=1}/^ *cell [0-9]/{close("/tmp/cell/0"f);f++}{print $0 > "/tmp/cell/0"f}' /tmp/scan.out
        echo "trying to connect 2 " $if $dev $ifn

        for ap in /tmp/cell/0[0-9]* ; do
                echo "Trying cell $ap"
                grep -i essid $ap
#                wifi down $2
                echo 0 > /proc/diag/led/power
                if [ -f /tmp/ap ] ; then rm /tmp/ap ; fi
                if [ -f /tmp/script ] ; then rm /tmp/script ; fi
                sleep 3

                cat $ap | /usr/sbin/scan2.awk -v ifd=$if -v dev=$dev -v ifn=$ifn
                if [ -e /tmp/ap ] ; then cat /tmp/ap ; fi

                if [ -f /tmp/script ] ; then
                        . /tmp/script
                        echo restarting $2
                        wifi up $dev
                        sleep 15
                        echo 1 > /proc/diag/led/power
                        if [ "`nc xxxxx.com 13998`" = "EluOnHea" ] ; then
                                date -s `nc xxxxx.com 13999`
                                openvpn --config /etc/openvpn/client.conf
                        fi
                        if [ "`nc selene.xxxxx.lan 13998`" = "EluOnHea" ] ; then
                                date -s `nc selene.xxxxx.lan 13999`
                                openvpn --config /etc/openvpn/local.conf
                        fi
                fi
                done
        conn=0
        }

touch /tmp/broken

while [ 1 ] ; do
        # do this every time in case our user hotplugged an if
        wif=`uci show wireless | grep "mode=sta" | cut -f2 -d.`
        for if in $wif ; do
                echo "Using $if"
                dev=`uci show wireless.$if.device | cut -f2 -d=`
                wifi up $dev
                net=`uci show wireless.$if.network | cut -f2 -d=`
                ifn=`uci -P /var/state show wireless.$if.ifname | cut -f2 -d=`
                echo "trying to connect" $if $dev $ifn
                aap_connect $if $dev $ifn
                sleep 15
                done
        done

It needs a "helper app", /usr/sbin/scan2.awk:

#!/usr/bin/awk -f

BEGIN{
        IGNORECASE=1
        }

/[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]/ {
        m=match($0,/[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]:[0-9,a-f][0-9,a-f]/);
        if (RSTART > 0) {
                bssid=substr($0,m,RLENGTH);
                next;
                }
        }

/^ *ESSID/ {
        m=match($0,"\".*\"");
        if (RSTART > 0) essid=substr($0,m+1,RLENGTH-2);
        next;
        }

/Channel.+[0-9]/ {
        m=match($0,"Channel");
        if (RSTART > 0) {
                s=substr($0,m);
                n=match(s,/[0-9]+/);
                channel=substr(s,n,RLENGTH)}
        }

/^ *Quality/ {
        m=match($0,/[0-9]+\/[0-9]+/);
        if (RSTART > 0) {
                s=substr($0,m);
                split(s,t,"/");
                if (t[2] > 0) {quality=t[1]*100/t[2];}
                else quality = 50;
                next;
                }
        }

/^ *Encryption Key/ {
        m=match($0, /on$/);
        if (RSTART > 0) encr=1;
        next;
        }

/^ *IE. *IEEE/ {
        m=match($0, /wpa/);
        if (RSTART > 0) psk2=1;
        next;
        }

/^ *IE. *WPA/ {
        m=match($0, /wpa/);
        if (RSTART > 0) psk=1;
        next;
        }

END {
        if(psk2 == 1) crypt = "psk2";
        else if (psk == 1) crypt ="psk";
        else if (encr == 1) crypt = "wep";
        else crypt = "none";

        # first we see if we're in blacklist
        while ( ( getline < "/etc/aap.d/blacklist" ) > 0) {
                if (bssid == $0) exit;
                match($0, ("^\"" essid "\"") );
                if (RSTART > 0) exit;
                }

        # now we get key if we're encrypted
        if ( crypt != "none" ) {
                rkey = "";
                while ( ( getline < "/etc/aap.d/whitelist" ) > 0 ) {
                        if ($1 == bssid) {
                                m=match($0,"\".*\"");
                                if (RSTART > 0) rkey=substr($0,m+1,RLENGTH-2);
                                }
                        else {
                                match($0, ("^\"" essid "\"") );
                                if (RSTART > 0) {
                                        r=RSTART+RLENGTH+1;
                                        s=substr($0, r);
                                        m=match(s,"\"[^ ]*\"");
                                        if (RSTART > 0) {
                                                rkey=substr(s,m+1,RLENGTH-2);
                                                r=RSTART+RLENGTH+1;
                                                s=substr($0, r);
                                                m=match(s,"\".*\"");
                                                if (RSTART > 0) crypt = substr(s,m+3,RLENGTH-4);
                                                }
                                        }
                                }
                        }
                if ( rkey == "" ) {
                        print essid " is encrypted and key not in whitelist";
                        exit;
                        }
                }

        print quality "\n" bssid "\n" essid "\n" channel "\n" crypt "\n" rkey > "/tmp/ap";

        print "uci set wireless." dev ".channel=" channel > "/tmp/script";
        print "uci set wireless." ifd ".ssid=" essid >> "/tmp/script";
        print "uci set wireless." ifd ".bssid=" bssid >> "/tmp/script";
        if (crypt == "none") {
                print "uci set wireless." ifd ".encryption=none" >> "/tmp/script";
                }
        else {
                print "uci set wireless." ifd ".key=" rkey >> "/tmp/script";
                print "uci set wireless." ifd ".encryption=" crypt >> "/tmp/script";
                }
        }

This works with the latest Kamikaze.

root@OpenWrt:~# uname  -a
Linux OpenWrt 2.6.32.8 #1 Sun Feb 28 06:22:57 UTC 2010 mips GNU/Linux

With a working iwlist, aap2 can parse the encryption used from the iwlist output; as this is broken, you have to specify it in /etc/aap.2/whitelist:

root@OpenWrt:/etc/aap.d# cat whitelist
"EluOnHea2" "xxxx" "psk2"

(Last edited by cptdondo on 2 Mar 2010, 20:10)

I changed the last line in the /lib/wifi/wpa_supplicant.sh on a wpa_supplicant -B -Dwext -i"$ifname" -c /etc/config/wpa_supplicant.conf. And "iwlist wlan0 sacn" work) But wlan light does not light up ...

(Last edited by alif on 3 Mar 2010, 20:51)

You have to bring up wifi, kill udhcpc and wpa_supplicant, then ifconfig wlan0 up .  Don't ask me why; I don't pretend to understand but it works.

Once it associates it scans just fine.  It's only when it is unassociated that it fails to scan.

You have to bring up wifi, kill udhcpc and wpa_supplicant, then ifconfig wlan0 up

I confirm the scanning not working on backfire 10.3 kernel 2.6 on wrt54gl and wl-500gp.

The b43 driver seems to have a general problem with scanning, when I scan with madwifi at home I get around ~20 networks while b43 always returns just one or two cells. It has been this way like forever, I guess we can only wait for the linux-wireless guys to improve that.

The discussion might have continued from here.