# WLAN only works if manually started

## Tareb

Hi,

i have a problem with starting my wlan via the normal net.eht1 init script.

If i start it up via wpa_supplicant everything is working. So i think, i did something wrong in my /etc/conf.d/net file.

But i am unable to find my error, so here is what i did.

My /etc/conf.d/net file:

```

# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

config_eth0=("dhcpcd")

config_eth1=("dhcpcd")

modules_eth1=( "wpa_supplicant" )

modules=( "wpa_supplicant" )

wpa_supplicant_eth1=" -Dwext "

associate_timeout_eth1=20

```

My /etc/wpa_supplicant/wpa_supplicant.conf file

```

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=0

update_config=1

network={

        ssid="UNITRADE"

        scan_ssid=1

        psk="thisissecret"

        key_mgmt=WPA-PSK

        eap=TTLS PEAP TLS

        priority=2

}

network={

        ssid="UNITY"

        scan_ssid=1

        psk="thisissecretalso"

        key_mgmt=WPA-PSK

        priority=1

}

```

Here my /etc/init.d/net.* files as ls shows them up

```

lrwxrwxrwx 1 root root     6 Aug 14 15:51 /etc/init.d/net.eth0 -> net.lo

lrwxrwxrwx 1 root root    18 Aug 19 17:37 /etc/init.d/net.eth1 -> /etc/init.d/net.lo

-rwxr-xr-x 1 root root 15179 Aug 18 08:56 /etc/init.d/net.lo

lrwxrwxrwx 1 root root     6 Aug 19 17:01 /etc/init.d/net.wlan0 -> net.lo

```

so. If i fire this command, i am connected to my WLAN:

```
wpa_supplicant -Dwext -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf -B
```

After this, i try to get an ip-adress

```
dhcpcd eth1
```

and anything is going smooth.

And now i fire /etc/init.d/net.eth1 start (of course after a reboot to restore anything)

```

jost_laptop ~ # /etc/init.d/net.eth1 start

* Bringing up interface eth1

*   Configuring wireless network for eth1

*   Scanning for access points

*     Found "UNITY" at 00:22:3F:34:D4:30, managed, encrypted

*     Found "hlan" at 00:04:0E:8E:9E:A5, managed, encrypted

*     Found "TJ-51" at 00:1B:2F:58:DC:82, managed, encrypted

*     Found "Funk-Netz" at 00:18:4D:CB:67:F6, managed, encrypted

*     Found "homesweethome" at 00:15:E9:07:63:FA, managed, encrypted

*     Found "sroka" at 00:1E:2A:7B:7F:4C, managed, encrypted

*   WEP key is not set for "UNITY"

*   WEP key is not set for "hlan"

*   WEP key is not set for "TJ-51"

*   WEP key is not set for "Funk-Netz"

*   WEP key is not set for "homesweethome"

*   WEP key is not set for "sroka"

*   Couldn't associate with any access points on eth1

*   Failed to configure wireless for eth1

* ERROR: net.eth1 failed to start

```

As far as i can see, the network starting process is not using wpa_supplicant.conf. But i do not understand why.

Here is a list of my files in /etc/conf.d just in case, something is there, what should better be away

```

jost_laptop ~ # ls /etc/conf.d

alsasound     device-mapper   fsck      keymaps      lvm           net.example  pydoc-2.6  saslauthd  syslog-ng         xdm

bootmisc      dmcrypt         gpm       local        modules       openvpn      pydoc-3.1  slapd      udev

consolefont   dmesg           hald      local.start  mysql         pciparm      rc_old     sshd       urandom

cpufrequtils  dolilo.example  hostname  local.stop   mysqlmanager  pure-ftpd    rsyncd     svnserve   wireless.example

crypto-loop   env_whitelist   hwclock   localmount   net           pydoc-2.5    samba      syndaemon  wireless.jost

```

Can someone point me in the right direction?

Thx in advance

Tareb

----------

## pdw_hu

You should try using wpa_passphrase to convert your "plaintext" password into a hash and inputting that data into the psk= field (don't use "-s) of wpa_supplicant.conf.

----------

## Tareb

thx for your replay, but my problem seems to be, that net.eth1 start with wireless-tools. 

I did configure wpa_supplicant in /etc/conf.d/net but the starting process stands on wireless-tools.

So the question is why?

----------

## Bones McCracker

I have exactly the same problem: can't get gentoo to use wpa_supplicant.  My conclusion is that the rc scripts in openrc are broken.  I have been using a work-around (my own initscript and wpa_cli action script).

My take on the problem:  Regardless of how I tweak /etc/conf.d/net, openrc checks for a WEP key, and not finding one, fails, emitting an error message.

```
# /etc/init.d/net.ra0 start

* Caching service dependencies...                                              [ ok ]

* Bringing up interface ra0

*   Configuring wireless network for ra0

*   Scanning for access points

*     Found "mynetwork" at 00:17:3F:9C:77:42, managed, encrypted

*     Found "yournetwork" at 00:1A:70:E8:43:58, managed, encrypted

*   WEP key is not set for "mynetwork"

*   WEP key is not set for "yournetwork"

*   Couldn't associate with any access points on ra0

*   Failed to configure wireless for ra0

* ERROR: net.ra0 failed to start
```

This error occurs with a wpa_supplicant.conf file known to work flawlessly when initiated manually:

```

# /etc/wpa_supplicant/wpa_supplicant.conf

# Re:

# /usr/share/doc/wpa_supplicant-<ver>/wpa_supplicant.conf.bz2

# man pages WPA_SUPPLICANT(8), WPA_SUPPLICANT.CONF(5)

# Notes:

# To reduce startup time, pre-generate wpa psk from passrphrase with utility:

# wpa_passphrase <ssid> <passphrase>

#### global configuration (shared by all network blocks)

# allow frontend (e.g., wpa_cli) to be used by all users in wheel group

#ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=10

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=0

# delegate scanning to the driver, select by SSID and security policy

ap_scan=2

#### per-essid configuration

network={

        ssid="mynetwork"

        scan_ssid=1

        proto=RSN

        key_mgmt=WPA-PSK

        auth_alg=OPEN

        pairwise=CCMP

        group=CCMP

        #psk="S0m3 v3ry C0mpl3x pA5sPhr@se y0u w1ll N0t Gu335!"

        psk=098733928d7d8d9b0h9870687648653743k542sf80ad0980ad98jj7643ad3h2h6

        proactive_key_caching=1

}
```

And using a /etc/conf.d/net configuration in accordance with the Gentoo Handbook and networking portion of the OpenRC upgrade guide:

```
# /etc/conf.d/net

# Re: /etc/conf.d/net.example

# wired

config_eth0="dhcp"

# wireless

modules="wpa_supplicant"

config_ra0="dhcp"

wpa_supplicant_ra0="-Dwext"
```

Plugging in a dummy WEP key causes the scripts to continue, attempting to form a WEP association with the AP.  So it seems that the scripts are completely ignoring the invocation of the wpa_supplicant module.

Looking at the scripts (in /lib/rc/net/*), one thing that is notable is that we are not seeing the output of this code from /lib/rc/net/wpa_supplicant.sh, which I think should run in any case the script is called:

```
ebegin "Starting wpa_supplicant on ${IFVAR}"
```

So I take that to mean the wpa_supplicant module is not being run (i.e., the /etc/conf.d/net option of modules="wpa_supplicant" is being ignored).

I am going to continue troubleshooting this, to see if I can figure out why the wpa_supplicant module doesn't appear to be called, but in the meantime, using the following as a replacement for the initscript bypasses the gentoo networking scripts and works for me (manually replace "ra0" with whatever your interface name is; for example "wlan0"):

```
#!/sbin/runscript

# /etc/init.d/net.ra0

depend() {

        need localmount

        use logger

        after net.lo

        provide net

}

start() {

        ebegin "Starting wireless network connection"

                start-stop-daemon --start \

                  --exec /usr/sbin/wpa_supplicant \

                  --pidfile /var/run/wpa_supplicant-ra0.pid \

                  -- -c /etc/wpa_supplicant/wpa_supplicant.conf \

                  -W -B -i ra0 -P /var/run/wpa_supplicant-ra0.pid

        wpa_cli -i ra0 -B -a /etc/wpa_supplicant/wpa_action.sh

        eend $? "Failed to start wireless network connection"

}

stop() {

        ebegin "Stopping wireless network connection"

                start-stop-daemon --stop \

                        --pidfile /var/run/wpa_supplicant-ra0.pid \

                        --exec /usr/sbin/wpa_supplicant

        eend $? "Failed to stop wireless network connection"

}
```

Note: I have found the -D option to the wpa_supplicant command to be unnecessary.  If you have trouble, you may want to include it, with the appropriate driver.  For example:

```
 ...

                start-stop-daemon --start \

                  --exec /usr/sbin/wpa_supplicant \

                  --pidfile /var/run/wpa_supplicant-ra0.pid \

                  -- -Dwext -c /etc/wpa_supplicant/wpa_supplicant.conf \

                  -W -B -i ra0 -P /var/run/wpa_supplicant-ra0.pid
```

This line:

```
        wpa_cli -i ra0 -B -a /etc/wpa_supplicant/wpa_action.sh
```

Is really kind of optional.  It calls a script run in the background, that does stuff when wpa_supplicant connects or disconnects.  The one provided by gentoo stops the initscript if disconnection occurs and starts it if connection occurs.  I have used it more simply, only to trigger dhcp when connection occurs.  (So, you could leave this out and manually fire up dhcp yourself, if you prefer).  And if you're not using dhclient, you might want to replace the command line (e.g. dhcpcd -blah).

#!/bin/sh

```
# /etc/wpa_supplicant/wpa_action.sh

# Purpose: start and stop dhcp when wpa supplicant emits a

# CONNECTED or DISCONNECTED event. This script is run as a

# daemon along with wpa_supplicant, using the command:

# wpa_cli -a /etc/wpa_supplicant/wpa_action.sh -B

# This is just a workaround to handle dhcp until I figure out how

# to get the openrc scripts working properly with wpa_supplicant.

if [ -z "$1" -o -z "$2" ]; then

        logger -t wpa_action "Insufficient parameters"

        exit 1

fi

iface="$1"

event="$2"

case ${event} in

        CONNECTED)

                action="/sbin/dhclient ${iface}"

                ;;

        DISCONNECTED)

                action="/sbin/dhclient -x ${iface}"

                ;;

        *)

                logger -t wpa_action "received bogus wpa_supplicant event: ${event}"

                exit 1

                ;;

esac

${action} || logger -t wpa_action "'${action}' failed"
```

----------

## Bones McCracker

Well, this is odd.

I re-emerged openrc, and now it's working fine.  That doesn't make any sense, since I've never edited any of the scripts, but it's now working.

----------

## d2_racing

What kind of wireless card do you own ?

eth1 is pretty weird, I see nowadays a lot of wlan0 interface instead.

----------

## wthrowe

 *BoneKracker wrote:*   

> Well, this is odd.
> 
> I re-emerged openrc, and now it's working fine.  That doesn't make any sense, since I've never edited any of the scripts, but it's now working.

 

You probably hit the same openrc bug I hit a while back.  The networking services cache file doesn't get updated when it should.  Remerging might have wiped the cache.

From the syntax of his /etc/conf.d/net file, it looks like the OP is still on baselayout-1 though.

----------

## Tareb

 *wthrowe wrote:*   

>  *BoneKracker wrote:*   Well, this is odd.
> 
> I re-emerged openrc, and now it's working fine.  That doesn't make any sense, since I've never edited any of the scripts, but it's now working. 
> 
> You probably hit the same openrc bug I hit a while back.  The networking services cache file doesn't get updated when it should.  Remerging might have wiped the cache.
> ...

 

No, i just did not realise, that there is a new syntax for /etc/conf.d/net because the net.example file in /etc/conf.d was not in the new syntax. Only in /usr/share/doc/openrc/net.example the new syntax is used.

The machine is newly installed and uses Baselayout 2.0.1

Now my /etc/conf.d/net looks 

```

config_eth0="dhcpcd"

config_wlan0="dhcpcd"

modules_wlan0="wpa_supplicant"

wpa_supplicant_wlan0=" -Dwext "

associate_timeout_wlan0=20

```

----------

## Tareb

so, the new installation of openrc solved the problem for me.

Strange, but ok.

Thanks for everyone for replying and helping.

Tareb

----------

## d2_racing

Nice then.

----------

