# iwlwifi (iwl3945) association issue

## forceflow2

For some reason my wireless device won't associate correctly. I use a little script to manually set the information, (essid, network key, rate) and pull an IP, which used to work just fine. This has been going on some time so I am unsure as to exactly when it first started (a couple of months ago, maybe) but my script no longer functions correctly. It gets to the pulling of an IP address, but it cannot find any AP by the name I have given it (link quality 0, no AP MAC address). However, as soon as I run iwlist, it finds it immediately, associates, and pulls an IP (well, pulls after running dhcpcd). I added running iwlist after a short wait upon setting the information and it seems to work ok so far, but there has to be something that's causing this. I am currently utilizing zen-sources which has the latest (1.2.23) version of iwlwifi and the latest wireless-tools (wireless-tools-29). This occurs with all AP I attempt to use so I am fairly certain it is not a router issue. Any help or ides would be appreciated. TIA

----------

## tarpman

Any particular reason why you don't want to use the Gentoo net scripts and /etc/conf.d/net?

----------

## forceflow2

Mainly because I've made it so I just have to type the name of the AP to connect to the one I want (I am switching around to about 4 different ones) and I'm now just use to simply typing the name into the console instead of using the net scripts. That doesn't really help with my issue, though   :Wink: 

Edit: Just because I didn't see any reason not to try, I went ahead and setup the net scripts to see if it worked. It does the same thing   :Sad: 

----------

## forceflow2

Bump?

----------

## bhagany

Well, I'm no expert, but are you using any wireless encryption?  If so, what sort?

----------

## forceflow2

Everything I connect to uses WEP

----------

## bhagany

Okay.  Would you mind posting your script, sans network keys?  And also any errors that occur when you run your script (check dmesg).  Just so you know, I'm probably going to steer you toward using the net scripts, especially if you're almost always on the same networks.  It's what I know.

----------

## beatryder

why not use wpa_supplicant and the default init scripts?

----------

## forceflow2

The "scripts" are just basically calls to commands put into a file so I can call them without having to type them out. They are all of the form

```
iwconfig wlan0 essid <essid> rate <rate, varies based on AP, either 11M or 54M> enc open key <WEP key for the AP> mode Managed

iwlist wlan0 scan

dhcpcd wlan0
```

As stated, without the iwlist wlan0 scan in there, it will never associate with the AP, it just sits there like it isn't in range. dmesg doesn't have any errors with it. Like I said before, the scripts themselves work perfectly fine, but upon removing the iwlist call, they never function. And I did setup the net scripts, but they have the exact same result as the above script run without iwlist. I'd have no qualms with using the net scripts, if they didn't suffer from this issue as well.

----------

## beatryder

 *forceflow2 wrote:*   

> The "scripts" are just basically calls to commands put into a file so I can call them without having to type them out. They are all of the form
> 
> ```
> iwconfig wlan0 essid <essid> rate <rate, varies based on AP, either 11M or 54M> enc open key <WEP key for the AP> mode Managed
> 
> ...

 

oh

I think I have a solution for you:

First try an "ifconfig wlan0 up" at the beginning of your script. 

If that doesn't work then try this: 

This is what I have in my conf.d/net but you can use them anyway you like.

```
preup(){

        if [[ ${IFACE} = "eth1" ]]; then

                echo 0 > /sys/devices/pci0000:00/0000:00:1c.1/0000:0c:00.0/rf_kill

                sleep 3

        fi

        return 0;

}
```

edit: I also use the init scripts and they work flawlessly. If you want I can post my configs for you.

----------

## bhagany

Well, I'll be honest, I have no idea off the top of my head.  I'm especially perplexed about no errors.  Does it give you any errors when you run the commands in your script directly on the command line?  I would expect something like: 

```
# iwconfig wlan0 blah blah blah

Error for wireless request "Set ESSID" (8B1A) :

SET failed on device wlan0 ; Operation not permitted.
```

That would at least be something I've seen before.

What does 

```
iwconfig wlan0
```

 give you without any other arguments, when you're not associated?

----------

## bhagany

If you do decide to use that preup function that beatryder posted, you'll have to modify that /sys/devices path to correspond to your particular machine (unless you happen to have the same setup).  I think doing a find for rf_kill in /sys/devices would work.

----------

## forceflow2

 *beatryder wrote:*   

> 
> 
> First try an "ifconfig wlan0 up" at the beginning of your script. 
> 
> 

 

Sorry, missed the transcribing of that from the scripts. It's in there though.

 *beatryder wrote:*   

> 
> 
> If that doesn't work then try this: 
> 
> This is what I have in my conf.d/net but you can use them anyway you like.
> ...

 

I tried that (although edited it to be wlan0 and echoing into /sys/devices/pci0000:00/0000:00:1c.2/0000:06:00.0/rf_kill since that's where mine is at) but it didn't seem to really do anything.

iwconfig wlan0

```

wlan0     IEEE 802.11a  ESSID:""

          Mode:Managed  Channel:0  Access Point: Not-Associated

          Tx-Power=0 dBm

          Retry min limit:7   RTS thr:off   Fragment thr=2352 B

          Encryption key:off

          Power Management:off

          Link Quality:0  Signal level:0  Noise level:0

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

```

After script call without iwlist command in it (this never changes no matter how long I wait)

```
wlan0     IEEE 802.11g  ESSID:"Numfar"

          Mode:Managed  Frequency:2.412 GHz  Access Point: Not-Associated

          Tx-Power=27 dBm

          Retry min limit:7   RTS thr:off   Fragment thr=2352 B

          Encryption key:[key was here]

          Power Management:off

          Link Quality:0  Signal level:0  Noise level:0

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

```

Immediately after running iwlist wlan0 scan

```
wlan0     IEEE 802.11g  ESSID:"Numfar"

          Mode:Managed  Frequency:2.412 GHz  Access Point: [MAC of router]

          Bit Rate=54 Mb/s   Tx-Power=27 dBm

          Retry min limit:7   RTS thr:off   Fragment thr=2352 B

          Encryption key:[key was here]

          Power Management:off

          Link Quality=92/100  Signal level=-39 dBm  Noise level=-127 dBm

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

```

Pertinent dmesg after iwlist is run (nothing is outputted until this)

```
wlan0: Initial auth_alg=0

wlan0: authenticate with AP [MAC addr]

wlan0: RX authentication from [MAC addr] (alg=0 transaction=2 status=0)

wlan0: authenticated

wlan0: associate with AP [MAC addr]

wlan0: RX AssocResp from [MAC addr] (capab=0x411 status=0 aid=1)

wlan0: associated

```

----------

## beatryder

what version of drivers are you using? Which Kernel? What kind of laptop?

----------

## forceflow2

zen-sources (Although it has happened when I used gentoo-sources before)

```
Linux Galileo 2.6.24-zen1 #24 SMP Sun Feb 3 14:07:49 EST 2008 i686 Intel(R) Core(TM)2 CPU T5600 @ 1.83GHz GenuineIntel GNU/Linux

```

It has version 1.2.23 of iwlwifi in it.

My laptop is a Sony Vaio VGN-FE770G.

----------

