# Wireless scanning and connection issues

## rcxAsh

I've been trying to setup the wireless connectivity on my notebook, and since there doesn't seem to be a definative guide (at least that I am understanding), I'm not at all sure what's going on.  

Nevertheless, I've somehow managed to stumble my way through and have managed to connect wirelessly _sometimes_.  However, somethings still seem missing.  

Firstly:

```
noteputer conf.d # /etc/init.d/net.ath0 start

 * Starting ath0

 *   Loading networking modules for ath0

 *     modules: iwconfig essidnet iptunnel ifconfig dhcpcd apipa

 *       iwconfig provides wireless

 *       ifconfig provides interface

 *       dhcpcd provides dhcp

 *   Configuring wireless network for ath0

 *   Scanning for access points

 *   ath0 does not support scanning

 *   You either need to set a preferred_aps list in /etc/conf.d/wireless

 *      preferred_aps=( "ESSID1" "ESSID2" )

 *      and set associate_order_ath0="forcepreferred"

 *      or set associate_order_ath0="forcepreferredonly"

 *   or hardcode the ESSID to "any" and let the driver find an Access Point

 *      essid_ath0="any"

 *   or configure defaulting to Ad-Hoc when Managed fails

 *      adhoc_essid_ath0="WLAN"

 *   or hardcode the ESSID against the interface (not recommended)

 *      essid_ath0="ESSID"

 *   Failed to configure wireless for ath0
```

Breaks there.  

However, I followed the last suggestion (not recommended) and it works:

```
noteputer conf.d # /etc/init.d/net.ath0 start

 * Starting ath0

 *   Loading networking modules for ath0

 *     modules: iwconfig essidnet iptunnel ifconfig dhcpcd apipa

 *       iwconfig provides wireless

 *       ifconfig provides interface

 *       dhcpcd provides dhcp

 *   Configuring wireless network for ath0

 *   Connecting to "ziyou" (WEP enabled - restricted) ...                                                                                              [ ok ]

 *     ath0 connected to "ziyou" at xx:xx:xx:xx:xx:xx

 *     in managed mode (WEP enabled - restricted)

 *   Configuring ath0 for "ziyou" ...                                                                                                                  [ ok ]

 *   Bringing up ath0

 *     Configuration not set for ath0 - assuming dhcp

 *     dhcp

 *       Running dhcpcd ...                                                                                                                            [ ok ]

 *       ath0 received address 192.168.2.16
```

So it works.. but then, I stopped net.ath0 and tried to start it again.. and:

```
noteputer init.d # /etc/init.d/net.ath0 start

 * Starting ath0

 *   Loading networking modules for ath0

 *     modules: iwconfig essidnet iptunnel ifconfig dhcpcd apipa

 *       iwconfig provides wireless

 *       ifconfig provides interface

 *       dhcpcd provides dhcp

 *   Configuring wireless network for ath0

 *   Connecting to "ziyou" (WEP enabled - restricted) ...                                                                                              [ !! ]

 *   Failed to configure wireless for ath0
```

Oops!  What happened?!  It was just working!  I wrote half of this post wirelessly, and then after I tried to restart the wireless interface, it stopped working.  I now have to go back to a wired network.  

In addition, If I try to use iwlist to scan, usually one of two things will happen:

```
ath0      Interface doesn't support scanning : Invalid argument
```

Or:

```
ath0      Failed to read scan data : Resource temporarily unavailable
```

One time, it performed a scan, but I'm not sure what I did then.  Subsequent scans after the successful one resulted in "Interface doesn't support scanning..."

I'm trying to recollect what I've done so far.. (haven't followed a single guide verbatim)..

I've enabled the wireless in the kernel, and emerged madwifi-drivers.  Also modprobed the modules from madwifi; all of them going in successfully except for wlan_ccmp (unknown symbols crypto_alloc_tfm and crypto_free_tfm).  

Put this into my /etc/conf.d/wireless:

```
key_ziyou="[wepkeyhere]"

preferred_aps=( "ziyou" )

essid_ath0="ziyou"
```

NB the last line was added as per the suggestions in the init script that failed.  

net.ath0 is a symbolic link to net.lo.  I can't remember if I created this or not.  

Any suggestions are appreciated!  Thanks

EDIT:

Oh, after a reboot, I seem to be able to start and stop net.ath0 ok.  But I still need to hard code the ssid.

----------

## IamBorg

It seems like you've answered your question.  From the information posted, you card doesn't support scanning.  If it doesn't support scanning, then you have to hard-code the essid.  However, you should be able to give it a list of ESSIDs to try.  I had this 'problem' with an older wireless NIC.  When I upgraded, I made sure that it supported scanning.

----------

## rcxAsh

Thanks for the reply!  

Oh, the thing is, I thought that I mentioned it in my post (perhaps too casually), but I did manage to get a result from scanning once.  I am not sure what I did though.  After that successful scan, however, subsequent ones failed to work.  

My notebook is relatively new.  From 2004.  It's a Fujitsu Lifebook T4010D; uses Atheros' Super AG (a/b/g) wireless.

----------

## IamBorg

After experimenting with mine (DLink-G650 -- Atheros chipset using madwifi-driver) (getting turbo mode working),  I found that my card has several modes (0 = auto, 1=802.11a, 2=802.11b, 3 = 802.11g) and it only supports scanning in mode 0.  There is several things you can try.  You can try setting sleep before scan to some number to give the driver some time to initialize.  Also, are you using any iwpriv commands to change settings on the card?  What type of wireless network are you trying to connect to (a,b,g)?   btw, scanning always worked on mine before I was playing with iwpriv commands to get turbo mode working.

 Well, off I go to continue tying to get my pre_associate to do different things according to the ESSID... (I only want to go to turbo mode for mine.)

EDIT -- scratch the scan only works in mode 0.  (It just worked for me in turbo). After iwpriv commands, maybe it has to wait some.

----------

## rcxAsh

Hey, sorry for the late reply.  I was away for the past week.  

So can you explain to me what you did to get the scanning working?  Thanks again

----------

## IamBorg

 *rcxAsh wrote:*   

> Hey, sorry for the late reply.  I was away for the past week.  
> 
> So can you explain to me what you did to get the scanning working?  Thanks again

 

Well, it sometimes works and sometimes not.  It works when I do the 'iwlist ath0 scan' manually (or something close to that  -- I'm not on my laptop right now).  After I've changed modes, it seems to not work until I wait for some time.  I know that if I'm in g mode, then I only see g APs, b - b compatible APs, etc.  will have to make a better reply when I've got a little bit more time.

----------

## theche

Hi!

Could you please tell how to enable the turbo mode? In the MAdWiki there is given some information like 

```
iwpriv ath0 mode 3 (this forces it to G-only mode)

iwpriv ath0 turbo 1 (enable turbo)
```

(from http://madwifi.sourceforge.net/dokuwiki/doku.php?id=turbo_mode&DokuWiki=39f1e634bd6e66df477eb705844ed33b)

I tried this, but it gives

```
notebook mac # iwpriv ath0 turbo 1

Interface doesn't accept private ioctl...

turbo (8BE0): No such device or address

```

But there might be the Option of a turbo Mode...

```
notebook mac # iwpriv

eth0      no private ioctls.

lo        no private ioctls.

ath0      Available private ioctl :

          setoptie         (8BE8) : set 256 byte  & get   0

          getoptie         (8BE9) : set   0       & get 256 byte

          setkey           (8BE2) : set  60 byte  & get   0

          delkey           (8BE4) : set   7 byte  & get   0

          setmlme          (8BE6) : set  10 byte  & get   0

          addmac           (8BEA) : set   1 addr  & get   0

          delmac           (8BEC) : set   1 addr  & get   0

          chanlist         (8BEE) : set  32 byte  & get   0

          setparam         (8BE0) : set   2 int   & get   0

          getparam         (8BE1) : set   1 int   & get   1 int

[b]          turbo            (0001) : set   1 int   & get   0[/b]

          get_turbo        (0001) : set   0       & get   1 int

          mode             (0002) : set   1 int   & get   0

          get_mode         (0002) : set   0       & get   1 int

          authmode         (0003) : set   1 int   & get   0

          get_authmode     (0003) : set   0       & get   1 int

          protmode         (0004) : set   1 int   & get   0

          get_protmode     (0004) : set   0       & get   1 int

          mcastcipher      (0005) : set   1 int   & get   0

          get_mcastcipher  (0005) : set   0       & get   1 int

          mcastkeylen      (0006) : set   1 int   & get   0

          get_mcastkeylen  (0006) : set   0       & get   1 int

          ucastciphers     (0007) : set   1 int   & get   0

          get_uciphers     (0007) : set   0       & get   1 int

          ucastcipher      (0008) : set   1 int   & get   0

          get_ucastcipher  (0008) : set   0       & get   1 int

          ucastkeylen      (0009) : set   1 int   & get   0

          get_ucastkeylen  (0009) : set   0       & get   1 int

          keymgtalgs       (0015) : set   1 int   & get   0

          get_keymgtalgs   (0015) : set   0       & get   1 int

          rsncaps          (0016) : set   1 int   & get   0

          get_rsncaps      (0016) : set   0       & get   1 int

          roaming          (000C) : set   1 int   & get   0

          get_roaming      (000C) : set   0       & get   1 int

          privacy          (000D) : set   1 int   & get   0

          get_privacy      (000D) : set   0       & get   1 int

          countermeasures  (000E) : set   1 int   & get   0

          get_countermeas  (000E) : set   0       & get   1 int

          dropunencrypted  (000F) : set   1 int   & get   0

          get_dropunencry  (000F) : set   0       & get   1 int

          wpa              (000A) : set   1 int   & get   0

          get_wpa          (000A) : set   0       & get   1 int

          driver_caps      (0010) : set   1 int   & get   0

          get_driver_caps  (0010) : set   0       & get   1 int

          maccmd           (0011) : set   1 int   & get   0

          wme              (0012) : set   1 int   & get   0

          get_wme          (0012) : set   0       & get   1 int

          hide_ssid        (0013) : set   1 int   & get   0

          get_hide_ssid    (0013) : set   0       & get   1 int

          ap_bridge        (0014) : set   1 int   & get   0

          get_ap_bridge    (0014) : set   0       & get   1 int

          inact            (0017) : set   1 int   & get   0

          get_inact        (0017) : set   0       & get   1 int

          inact_auth       (0018) : set   1 int   & get   0

          get_inact_auth   (0018) : set   0       & get   1 int

          inact_init       (0019) : set   1 int   & get   0

          get_inact_init   (0019) : set   0       & get   1 int

```

This NIC has an AR5212 Chipset.

 *lspci -v wrote:*   

> 
> 
> 0000:07:00.0 Ethernet controller: Atheros Communications, Inc. AR5212 802.11abg NIC (rev 01)

 

any instructions?

----------

## IamBorg

it gives me that when I'm not in mode 3.  In your code section you just had the turbo.  Here is what I can type to enable it.

```
iwpriv ath0 mode 3

iwpriv ath0 turbo 1
```

Of course, you need to have your AP set to Turbo only in order for it to actually connect.  Also, if you want to do it automagically for trying out an AP (either force-preferred or discovered during scanning), then in /etc/conf.d/wireless have

```
preassociate(){

    if [[ ${ESSIDVAR} == "My_AP_ESSID"; then

        iwpriv ath0 mode 3;

        iwpriv ath0 turbo 1;

    else

        iwpriv ath0 mode 3;

        iwpriv ath0 turbo 0;

        iwpriv ath0 mode 0;

    fi

    return 0;

}
```

Note: I'm not sure if you need to explicitly turn turbo off, but I figured it can't hurt too much.

Also, lspci -v | grep Atheros returned exactly the same thing for me...

----------

## pdr

I started using the "new" net.lo initscript for wireless yesterday; previously it didn't support stuff I wanted. So prior to yesterday (and at times still) I ran my own initscripts for wireless with madwifi and my T42 thinkpad.

One thing I learned with the Atheros is that

```
1. if you don't initialize correctly, it reports somehow that scanning is not supported.

2. When it does scan, it ONLY scans the currently selected channel (unless there is some way I have not learned to get it to scan multiple channels).
```

For example, I have a work-in-progress script that does various wireless stuff. Here's the function that scans for APs:

```
function scan {

        /sbin/iwconfig ath0 mode Managed channel 1 rate auto

        /sbin/ifconfig ath0 up

        for CH in $(/sbin/iwlist ath0 channel | grep -E 'Channel [0-9]{2,3} :' | sed 's/^.*Channel \([0-9][0-9]*\) :.*$/\1/'); do

                /sbin/iwconfig ath0 channel $CH

                INFO=$(/sbin/iwlist ath0 scanning 2>/dev/null)

                TMP=$(echo "$INFO" | grep -E 'No scan results')

                if [ "$TMP" == "" ]; then

                        ESSID=$(echo "$INFO" | grep -E 'ESSID:' | sed 's/^ *ESSID:\"\([^"]*\)\" *$/\1/')

                        MODE=$(echo "$INFO" | grep -E 'Mode:' | sed 's/^ *Mode:\([^ ]*\) *$/\1/')

                        if [ "$MODE" == "Master" ]; then

                                CHANNEL=$(echo "$INFO" | grep -E 'Frequency:' | sed 's/^ *Frequency:[^ ]* *[^ ]* *(Channel *\([^)]*\)) *$/\1/')

                                QUALITY=$(echo "$INFO" | grep -E 'Quality=' | sed 's/^.*Quality=\([^ ]*\) .*$/\1/')

                                ENC=$(echo "$INFO" | grep -E 'Encryption key:' | sed 's/^.*Encryption key:\([^ ]*\).*$/\1/')

                                echo "ESSID=\"$ESSID\" Channel=\"$CHANNEL\" Quality=\"$QUALITY\" Encryption=\"$ENC\""

                        fi

                fi

        done

        /sbin/ifconfig ath0 down

}
```

Not necessarily pretty because I'm still quasi-new to bash scripting. However the algorithm is:

```
1. Initialize the atheros by setting the mode (Managed), rate (auto), and any channel (I use 1).

2. Bring up the ath0 interface.

3. Use "iwlist ath0 channel" to get a list of channels the chip supports. For each channel do:

  a. Switch to that channel.

  b. Now can use "iwlist ath0 scanning" to scan this channel.
```

You can get the first step by setting that in /etc/init.d/net with

```
iwconfig_ath0="mode Managed rate auto channel 3"
```

However now it will only scan channel 3, not any of the other channels. As far as I can tell the initscripts don't support any scan looping, or hooks into it. Unless can just write our own iwconfig_scan() function in /etc/conf.d/net and it will "override" the one in the iwconfig module...

----------

## pdr

Addendum: Atheros DOES support scanning all channels; you just have to not have it set to a specific channel. I changed the channel to "auto" (I think - at work right now and can't check) and scan checked all channels...

----------

## tbart

just a guess:

read in /etc/conf.d/wireless that some cards can only scan in ad-hoc mode.

sounds close to your problems.

there even is an option to automatically do that in the mentioned file.

hth,

tbart

----------

