# Autostarting wlan0 using wpa_supplicant [SOLVED]

## Grant1219

Currently I'm trying to get my wireless autoconnecting to my home access point. It seems like it is trying, but failing to connect. I'll paste some useful info below.

rc.log

```

* Bringing up interface lo

 *   127.0.0.1/8 ...

 [ ok ]

 *   Adding routes

 *     127.0.0.0/8 via 127.0.0.1 ...

 [ ok ]

 * Bringing up interface wlan0

 *   Configuring wireless network for wlan0

 *   Connecting to "phobos" in managed mode (WEP Disabled) ...

 [ !! ]

 *   Failed to configure wireless for wlan0

 * ERROR: net.wlan0 failed to start

```

/etc/conf.d/net

```

modules="wpa_supplicant"

wpa_supplicant_wlan0="-Dmadwifi -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf"

wpa_timeout_wlan0=60

essid_wlan0="phobos"

config_wlan0="dhcp"

dhcpcd_wlan0="-t 30"

preferred_aps="phobos"

config_eth0="dhcp"

dhcp_eth0="release"

```

wpa_supplicant.conf

```

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=0

ap_scan=1

network={

  ssid="phobos"

  psk="********"

  priority=99

}

```

iwconfig

```

wlan0     IEEE 802.11bgn  Mode:Managed  Access Point: Not-Associated   

          Tx-Power=off   

          Retry  long limit:7   RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:off

```

In /etc/rc.conf I have this option set: rc_hotplug="net.wlan0 !net.*"

It's not a driver issue because I started the wireless manually without a problem. It's just that autostarting it is a problem. If anyone needs more info just ask. Thank you.Last edited by Grant1219 on Wed Sep 01, 2010 5:03 am; edited 1 time in total

----------

## mikegpitt

Try this instead (spaces next to parentheses are important):

/etc/conf.d/net

```
config_eth0=( "dhcp" )

config_wlan0=( "dhcp" )

modules=( "wpa_supplicant" )

wpa_supplicant_wlan0="-Dwext"

wpa_timeout_wlan0=30
```

Set can set your preferred access points in your /etc/wpa_supplicant/wpa_supplicant.conf.  I recommend using wpa_gui to create this file, although there is nothing wrong by doing it by hand.

----------

## Grant1219

I thought the parenthesis were unneeded because I am using OpenRC and baselayout 2?

Anyway, when I take out this line:

```
preferred_aps="phobos"
```

The wireless just scans and connects to a unsecured wireless in my area, and I'm not sure why it is trying to use WEP.

----------

## mikegpitt

 *Grant1219 wrote:*   

> I thought the parenthesis were unneeded because I am using OpenRC and baselayout 2?

 I didn't know you were using baselayout-2... you are correct it looks like in that case the parens aren't necessary.

Try this instead:

```
config_eth0="dhcp" 

config_wlan0="dhcp"

modules="wpa_supplicant"

wpa_supplicant_wlan0="-Dwext" 

wpa_timeout_wlan0=30
```

Can you post the contents of your /etc/wpa_supplicant/wpa_supplicant.conf?  This is most likely the reason your machine is connecting to random hotspots.  You should be able to eliminate that functionality and also set priorities for various networks if the file is configured correctly.

----------

## wjb

The (relevant) output from dmesg would probably also be useful. Just to see whats actually happening on the connection front.

----------

## Grant1219

Well "dmesg | grep wlan0" returns this:

```

[   12.007046] ADDRCONF(NETDEV_UP): wlan0: link is not ready

[   15.527429] wlan0: deauthenticating from 00:02:8a:fc:7f:7e by local choice (reason=3)

[   15.546269] wlan0: deauthenticating from 00:02:8a:fc:7f:7e by local choice (reason=3)

[   15.581692] wlan0: authenticate with 00:02:8a:fc:7f:7e (try 1)

[   15.583800] wlan0: authenticated

[   15.583832] wlan0: associate with 00:02:8a:fc:7f:7e (try 1)

[   15.586334] wlan0: RX AssocResp from 00:02:8a:fc:7f:7e (capab=0x401 status=0 aid=6)

[   15.586338] wlan0: associated

[   15.586798] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

[   26.550316] wlan0: no IPv6 routers present

```

Also...

If I stop net.wlan0, and then issue these commands, I am able to connect to my router.

```

rfkill block all

rfkill unblock all

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf

```

But that's quite annoying when I want it to connect at startup. Do I need to add the wpa_supplicant service to the init process?

----------

## mikegpitt

 *mikegpitt wrote:*   

> Can you post the contents of your /etc/wpa_supplicant/wpa_supplicant.conf?

 Please still post this... the answer likely is in there...

----------

## Grant1219

I did post it actually, in the very first post, but I have changed it since then so I'll post it again.

Sorry for some reason I didn't see your request.

```

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=wheel

ap_scan=0

network={

  ssid="phobos"

  proto=WPA2

  key_mgmt=WPA-PSK

  pairwise=TKIP

  group=TKIP

  psk="password"

  priority=5

}

```

----------

## d2_racing

Can you post this :

```

# iwlist scan

```

----------

## Grant1219

Sure thing.

```

wlan0     Scan completed :

          Cell 01 - Address: 00:22:68:A1:95:F5

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=24/70  Signal level=-86 dBm  

                    Encryption key:on

                    ESSID:"a5e8"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c2895b189

                    Extra: Last beacon: 194ms ago

                    IE: Unknown: 000461356538

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 030101

                    IE: Unknown: 050400010000

                    IE: Unknown: 2A0100

                    IE: Unknown: 2F0100

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD06001018020000

          Cell 02 - Address: 00:1D:7E:58:77:A6

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=68/70  Signal level=-42 dBm  

                    Encryption key:on

                    ESSID:"phobos"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=000000028817c38c

                    Extra: Last beacon: 1ms ago

                    IE: Unknown: 000670686F626F73

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 030101

                    IE: Unknown: 2A0100

                    IE: Unknown: 2F0100

                    IE: IEEE 802.11i/WPA2 Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (1) : TKIP

                        Authentication Suites (1) : PSK

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD090010180202F0000000

          Cell 03 - Address: 00:1C:10:A9:F2:24

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=21/70  Signal level=-89 dBm  

                    Encryption key:on

                    ESSID:"dd-wrt"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c28a87183

                    Extra: Last beacon: 2664ms ago

                    IE: Unknown: 000664642D777274

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 030106

                    IE: Unknown: 2A0104

                    IE: Unknown: 2F0104

                    IE: Unknown: 32040C121860

                    IE: Unknown: 2D1A1C181AFFFF000000000000000000000000000000000000000000

                    IE: Unknown: 3D1606001F00000000000000000000000000000000000000

                    IE: Unknown: 7F0101

                    IE: Unknown: DD090010180202F0010000

                    IE: WPA Version 1

                        Group Cipher : CCMP

                        Pairwise Ciphers (1) : CCMP

                        Authentication Suites (1) : PSK

                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00

                    IE: Unknown: DD1E00904C331C181AFFFF000000000000000000000000000000000000000000

                    IE: Unknown: DD1A00904C3406001F00000000000000000000000000000000000000

          Cell 04 - Address: 00:16:B6:AD:9C:FC

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=20/70  Signal level=-90 dBm  

                    Encryption key:on

                    ESSID:"Jungle-Net"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c28e3d188

                    Extra: Last beacon: 500ms ago

                    IE: Unknown: 000A4A756E676C652D4E6574

                    IE: Unknown: 010882848B96A4B0C8EC

                    IE: Unknown: 03010B

                    IE: Unknown: 050400010000

                    IE: Unknown: 2A0104

                    IE: Unknown: 2F0104

                    IE: Unknown: 32048C9298E0

                    IE: Unknown: DD06001018020017

                    IE: WPA Version 1

                        Group Cipher : CCMP

                        Pairwise Ciphers (1) : CCMP

                        Authentication Suites (1) : PSK

          Cell 05 - Address: 00:23:69:EA:1C:D3

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=18/70  Signal level=-92 dBm  

                    Encryption key:on

                    ESSID:""

                    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=00015c4eeafab180

                    Extra: Last beacon: 132ms ago

                    IE: Unknown: 0000

                    IE: Unknown: 010882848B968C129824

                    IE: Unknown: 030101

                    IE: Unknown: 050400010000

                    IE: Unknown: 2A0100

                    IE: IEEE 802.11i/WPA2 Version 1

                        Group Cipher : CCMP

                        Pairwise Ciphers (1) : CCMP

                        Authentication Suites (1) : PSK

                    IE: Unknown: 3204B048606C

                    IE: Unknown: DD0900037F01010000FF7F

                    IE: Unknown: DD0A00037F04010002004000

                    IE: Unknown: DD0E0050F204104A0001101044000102

          Cell 06 - Address: 00:02:8A:FC:7F:7E

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=27/70  Signal level=-83 dBm  

                    Encryption key:off

                    ESSID:"4739"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s

                              36 Mb/s; 48 Mb/s; 54 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c2983318d

                    Extra: Last beacon: 2670ms ago

                    IE: Unknown: 000434373339

                    IE: Unknown: 010482848B96

                    IE: Unknown: 030106

                    IE: Unknown: 2A0104

                    IE: Unknown: 2F0104

                    IE: Unknown: 32080C1218243048606C

                    IE: Unknown: DD050010180101

          Cell 07 - Address: 00:13:10:93:F9:60

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=25/70  Signal level=-85 dBm  

                    Encryption key:on

                    ESSID:"Mango"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c2891badb

                    Extra: Last beacon: 2681ms ago

                    IE: Unknown: 00054D616E676F

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 030106

                    IE: Unknown: 2A0104

                    IE: Unknown: 2F0104

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD06001018010100

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (1) : TKIP

                        Authentication Suites (1) : PSK

          Cell 08 - Address: 00:26:F2:C9:C2:E4

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=21/70  Signal level=-89 dBm  

                    Encryption key:on

                    ESSID:"smuncil"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c283e3183

                    Extra: Last beacon: 871ms ago

                    IE: Unknown: 0007736D756E63696C

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 03010B

                    IE: Unknown: 050401030000

                    IE: Unknown: 2A0100

                    IE: Unknown: 2F0100

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD090010180200F0000000

                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00

          Cell 09 - Address: 00:0E:E8:64:2D:F5

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=16/70  Signal level=-94 dBm  

                    Encryption key:off

                    ESSID:"Wireless G Router 523431"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s

                              36 Mb/s; 48 Mb/s; 54 Mb/s

                    Mode:Master

                    Extra:tsf=0000008c2862b6bf

                    Extra: Last beacon: 1671ms ago

                    IE: Unknown: 0018576972656C657373204720526F7574657220353233343331

                    IE: Unknown: 010482848B96

                    IE: Unknown: 030101

                    IE: Unknown: 050400010000

                    IE: Unknown: 2A0104

                    IE: Unknown: 32080C1218243048606C

                    IE: Unknown: DD07000C4301000000

          Cell 10 - Address: 00:21:04:6E:7B:30

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=17/70  Signal level=-93 dBm  

                    Encryption key:on

                    ESSID:"hagenbach"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 22 Mb/s

                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s

                              36 Mb/s; 48 Mb/s; 54 Mb/s

                    Mode:Master

                    Extra:tsf=00000062134a5fa1

                    Extra: Last beacon: 883ms ago

                    IE: Unknown: 0009686167656E62616368

                    IE: Unknown: 010582848B962C

                    IE: Unknown: 03010B

                    IE: Unknown: 2A0104

                    IE: Unknown: 32080C1218243048606C

```

----------

## d2_racing

Hi, try to comment that line : ap_scan=0 

And retry.

Your wpa_supplicant.conf seems to be good.

----------

## Grant1219

Okay, I changed my config file and I will try that tomorrow. I can't at the moment since I'm rebuilding the system.

X started segfaulting and hardlocking for some reason, so I want to try and fix that first. Otherwise, fixing the wireless is kind of meaningless...

----------

## Grant1219

Okay well it seems to be trying to use wpa_supplicant now, which is good. There is still a small issue it seems.

```

* Bringing up interface wlan0

*    Starting wpa_supplicant on wlan0 ...

ioctl[IEE80211_IOCTL_SETPARAM]: Operation not supported

Failed to initialize driver interface

*    start-stop-daemon: failed to start '/usr/sbin/wpa_supplicant'

[ !! ]

* ERROR: net.wlan0 failed to start

```

EDIT:

I changed the params in /etc/conf.d/net to this:

```
wpa_supplicant_wlan0="-iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf"
```

And now the init process reports this:

```

* Bringing up interface wlan0

*    Starting wpa_supplicant on wlan0 ...

*    Starting wpa_cli on wlan0 ...

*    Backgrounding ... ...

* WARNING: net.wlan0 has started, but is inactive

```

Do I need to do something to run DHCP on it, or something else?Last edited by Grant1219 on Tue Aug 31, 2010 5:23 pm; edited 1 time in total

----------

## mikegpitt

 *Grant1219 wrote:*   

> I did post it actually, in the very first post, but I have changed it since then so I'll post it again.
> 
> Sorry for some reason I didn't see your request.

 Sorry I didn't see it in the first post!  It looks like d2_racing's advice worked...  I think by including the ap_scan parameter it makes wpa_supplicant scan for new networks.

 *Grant1219 wrote:*   

> Okay well it seems to be trying to use wpa_supplicant now, which is good. There is still a small issue it seems.
> 
> ```
> 
> * Bringing up interface wlan0
> ...

 

Sometimes errors like this occur when the interface is down.  What happens if you do this?

```
ifconfig wlan0 up

/etc/init.d/net.wlan0 restart
```

----------

## Grant1219

Check my edited post above you.

Also wireless is starting up, and is getting an IP, so everything works, but that warning message still worries me.

----------

## mikegpitt

 *Grant1219 wrote:*   

> 
> 
> And now the init process reports this:
> 
> ```
> ...

 The "started, but is inactive" warning happens if the init script is waiting for another init script to start before it actually becomes active.  An example would be the ntp-client script waiting for a net device to become active.  I've never seen it for one of the net.* init scripts though.

What do you have set for the RC_NET_STRICT_CHECKING variable in your /etc/conf.d/rc?  You might also want to set your RC_PLUG_SERVICES="", since this could be causing the warning.

----------

## Grant1219

Here are the relevant parts of my rc.conf:

```

rc_depend_strict="NO"

rc_hotplug="net.wlan0 !net.eth0"

```

I guess as long as it works it's fine, but if I could fix it that would be even better.

----------

