# starting wireless via scripts

## soloslinger

Hey all,

I finally got wireless working on my laptop.  The only problem is, I can't start it by /etc/init.d/net.wlan0.

I can connect manually by doing the following:

```

ifconfig wlan0 up

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

dhcpcd wlan0

ping www.google.com

```

...that works, I can send packets out to the world.

however, if I copy /etc/init.d/net.lo to /etc/init.d/net.wlan0 and then run that script, I get a bunch of output that has the appearance of a misformed wpa_supplicant command.  Below is my /etc/conf.d/net:

```

cat /etc/conf.d/net

# 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=( "dhcp" )

ap_scan=0

modules={ "wpa_supplicant" }

wpa_supplicant_eth0="-Dwext"

config_wlan0=( "dhcp" )

```

The setup docs I have followed came from the handbook and the wiki, they don't mention copying the startup script, and I believe I have followed their examples for /etc/conf.d/net.  I have an ath9k card for which I compiled the drivers directly into my kernel (no module action).

Would someone be as so kind to save me from myself?  

soloslinger

----------

## BradN

First, it's generally recommended to symlink net.lo to other network devices instead of copying (so updates don't leave stale files in the copies)

At first glance the only difference between your manual command and what net.wlan0 might invoke is that no driver is specified in the manual command, but since there's no special ath9k driver, that shouldn't matter.

However, the problem is that you've typed the wrong interface  :Smile: 

```
wpa_supplicant_eth0="-Dwext"
```

----------

## erik258

If you don't divulge from a standard wireless configuration you can typically just put one line in /etc/conf.d/net for your wireless: 

```
modules_wlan0="wpa_supplicant"
```

Incidentally, I highly recommend 2.6.33.2 for ath9k users.  2.6.33.3 is probably even better, but I haven't tested it yet.  Both changelogs mention changes for ath9k, and mine worked much better when I moved to 2.6.33.2.

----------

## soloslinger

BradN, Nice catch, but I have changed that to be wlan0 in efforts to make this work and have had no luck.  I forgot to edit that part out before my initial post.  Thanks for the tip on the symlink, I will make sure to mend my ways.

erik258, huh.  Is 2.6.33 even out?  I --sync'd and used 2.6.32-r7 because I had read about stability problems in 2.6.31.  Either way, it's always nice to know that one particular piece of my hardware is getting so much dev love.

I will try both of your suggestions and get back to you (working from a dual booting machine).

soloslinger

----------

## mr.sande

Another slight difference between the manual connect and conf.d/net is that you don't specify the config in conf.d/net.

----------

## d2_racing

There is something wrong :

```

wpa_supplicant_eth0="-Dwext" 

```

should be 

```

wpa_supplicant_wlan0="-Dwext" 

```

----------

## soloslinger

Okay.  I have corrected my interface name and still no luck.  Anyone got any other ideas or things I can try?

----------

## BradN

I'm starting to run out of ideas here... you could replace wpa_supplicant with a wrapper script that logs its parameters and then runs the real program (perhaps with extra verbosity) - then you could see if there are differences in the actual invocation of the command or if gentoo's network init scripts might be doing something with the wireless first that messes it up.

----------

## d2_racing

Hi, can you post this :

```

# ifconfig -a

# iwconfig

# iwlist scan

# cat /etc/conf.d/net

# cat /etc/wpa_supplicant/wpa_supplicant.conf

```

----------

## soloslinger

 *d2_racing wrote:*   

> Hi, can you post this :
> 
> ```
> 
> # ifconfig -a
> ...

 

Certainly.

```
lappy soloslinger # ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:24:be:b2:b2:15

          inet addr:10.10.5.157  Bcast:10.10.5.255  Mask:255.255.255.0

          inet6 addr: fe80::224:beff:feb2:b215/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:120 errors:0 dropped:0 overruns:0 frame:0

          TX packets:82 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:13204 (12.8 KiB)  TX bytes:12720 (12.4 KiB)

          Interrupt:18

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

sit0      Link encap:IPv6-in-IPv4

          NOARP  MTU:1480  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 2c:81:58:eb:5b:85

          BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)lappy soloslinger # iwconfig

lo        no wireless extensions.

eth0      no wireless extensions.

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

          Tx-Power=0 dBm

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

          Encryption key:off

          Power Management:off

sit0      no wireless extensions.

```

```
lappy soloslinger # iwlist scan | more

lo        Interface doesn't support scanning.

eth0      Interface doesn't support scanning.

wlan0     Interface doesn't support scanning : Network is down

sit0      Interface doesn't support scanning.

```

Everything is commented out currently.  Unfortunately, I have tried every combination of those below except the one that works.

```
lappy soloslinger # cat /etc/conf.d/net

# 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=( "dhcp" )

#ap_scan=0

#modules={ "wpa_supplicant" }

#modules_wlan0="wpa_supplicant"

#wpa_supplicant_wlan0="-Dwext"

#config_wlan0=( "dhcp" )

```

```
lappy soloslinger # cat /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=0

network={

        ssid="FishBowl"

        proto=WPA

        key_mgmt=WPA-PSK

        pairwise=CCMP TKIP

        group=CCMP TKIP WEP104 WEP40

        psk="I bet you like waffles as much as I do (<snip snip>)"

}

```

Edit :: I appreciate your time very much, thanks.

soloslinger

----------

## d2_racing

Hi,can you post this:

#ifconfig wlan0 up

#iwlist scan

----------

## erik258

[quote] [ asks for iwlist output after interface is brought up ] [/qoute]

Yes, do please post that.   It will help us determine whether it's the kernel side of things that's giving you troubles, or userspace config/utilities.  

I use an /etc/conf.d/net that looks like this: 

```
modules_wlan0="wpa_supplicant"
```

Works fine for me.  

 *Quote:*   

> erik258, huh. Is 2.6.33 even out? I --sync'd and used 2.6.32-r7 because I had read about stability problems in 2.6.31. Either way, it's always nice to know that one particular piece of my hardware is getting so much dev love. 

 

Actually, 2.6.34 just came out monday (the 17th).  Of course, I'm talking stable vanilla from kernel.org; the gentoo kernel package managers are generally a few releases behind.  They do good work, but I'm continually rewarded by staying on the cutting edge of kernels these days.  Just switched to 2.6.34 myself and ath9k is working better than ever.  

If you'd like to see some of the changes in 2.6.34 (and there's way more than I could possibly describe in detail), you can see a nice overview on my blog: http://linuxcommando.com/2010/05/2-6-34-released/

----------

## soloslinger

 *d2_racing wrote:*   

> Hi,can you post this:
> 
> #ifconfig wlan0 up
> 
> #iwlist scan

 

My fault, I kinda figured that was the case.  Or you are bored, working for Google and tryin to locate me via the wireless access points near me.  Just teasing of course.  This was the result of an iwlist scan > file.txt.  It does drop out a few other things about not being able to scan off of the other interfaces, if that's necessary I can replicate that here for you.

```
wlan0     Scan completed :

          Cell 01 - Address: 00:22:6B:5D:F2:10

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=22/70  Signal level=-88 dBm  

                    Encryption key:on

                    ESSID:"Sadpanda"

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

                              18 Mb/s; 36 Mb/s; 54 Mb/s

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

                    Mode:Master

                    Extra:tsf=000004486ba3408e

                    Extra: Last beacon: 866ms ago

                    IE: Unknown: 000853616470616E6461

                    IE: Unknown: 010882848B961224486C

                    IE: Unknown: 030101

                    IE: Unknown: 2A0104

                    IE: Unknown: 32040C183060

                    IE: Unknown: 2D1AEC0117FFFF0000000000000000000000000000000C0000000000

                    IE: Unknown: 3D1601000400000000000000000000000000000000000000

                    IE: Unknown: 3E0100

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (2) : TKIP CCMP

                        Authentication Suites (1) : PSK

                    IE: IEEE 802.11i/WPA2 Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (2) : TKIP CCMP

                        Authentication Suites (1) : PSK

                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00

                    IE: Unknown: 7F0101

                    IE: Unknown: DD07000C4307000000

                    IE: Unknown: 0706555320010B10

                    IE: Unknown: DD1E00904C33EC0117FFFF0000000000000000000000000000000C0000000000

                    IE: Unknown: DD1A00904C3401000400000000000000000000000000000000000000

                    IE: Unknown: DD820050F204104A0001101044000102103B000103104700102880288028801880A88000226B5DF2101021000C4C696E6B73797320496E632E102300095752543136304E76321024000776322E302E3032104200033030381054000800060050F2040001101100114C696E6B737973205752543136304E7632100800020084103C000101

          Cell 02 - Address: 00:19:E3:FB:F5:DB

                    Channel:1

                    Frequency:2.412 GHz (Channel 1)

                    Quality=53/70  Signal level=-57 dBm  

                    Encryption key:on

                    ESSID:"Purple Rain"

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s

                              11 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=00000194fdcd3180

                    Extra: Last beacon: 946ms ago

                    IE: Unknown: 000B507572706C65205261696E

                    IE: Unknown: 010882848B0C12961824

                    IE: Unknown: 030101

                    IE: Unknown: 0706555320010B1B

                    IE: Unknown: 200100

                    IE: Unknown: 2A0102

                    IE: Unknown: 32043048606C

                    IE: IEEE 802.11i/WPA2 Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (2) : CCMP TKIP

                        Authentication Suites (1) : PSK

                    IE: Unknown: 2D1A0C101BFFFF000000000000000000000000000000000000000000

                    IE: Unknown: 3D1601001B00000000000000000000000000000000000000

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (1) : TKIP

                        Authentication Suites (1) : PSK

                    IE: Unknown: DD180050F2020101040003A4000027A4000042435E0062322F00

                    IE: Unknown: DD0700039301680120

                    IE: Unknown: DD0B0017F20100010100000003

          Cell 03 - Address: 00:18:F8:53:76:B3

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=36/70  Signal level=-74 dBm  

                    Encryption key:on

                    ESSID:"FishBowl"

                    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=00000066c597bfe0

                    Extra: Last beacon: 338ms ago

                    IE: Unknown: 000846697368426F776C

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 030106

                    IE: Unknown: 2A0104

                    IE: Unknown: 2F0104

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD060010180203F4

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (1) : TKIP

                        Authentication Suites (1) : PSK

          Cell 04 - Address: 00:1A:C4:DA:74:31

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=30/70  Signal level=-80 dBm  

                    Encryption key:on

                    ESSID:"2WIRE552"

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

                    Mode:Master

                    Extra:tsf=00000000cf8cd181

                    Extra: Last beacon: 564ms ago

                    IE: Unknown: 00083257495245353532

                    IE: Unknown: 010482840B16

                    IE: Unknown: 030106

                    IE: Unknown: 0706555320010B1B

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (1) : TKIP

                        Authentication Suites (1) : PSK

          Cell 05 - Address: 00:1C:DF:3B:91:E3

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=33/70  Signal level=-77 dBm  

                    Encryption key:on

                    ESSID:"toocold"

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

                              12 Mb/s; 24 Mb/s; 36 Mb/s

                    Bit Rates:9 Mb/s; 18 Mb/s; 48 Mb/s; 54 Mb/s

                    Mode:Master

                    Extra:tsf=000000e0011e0181

                    Extra: Last beacon: 160ms ago

                    IE: Unknown: 0007746F6F636F6C64

                    IE: Unknown: 010882848B960C183048

                    IE: Unknown: 03010B

                    IE: Unknown: 0706555320010B1B

                    IE: Unknown: 2A0100

                    IE: Unknown: 32041224606C

          Cell 06 - Address: 00:25:86:F2:1B:12

                    Channel:6

                    Frequency:2.437 GHz (Channel 6)

                    Quality=25/70  Signal level=-85 dBm  

                    Encryption key:on

                    ESSID:"terminator"

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

                              12 Mb/s; 24 Mb/s; 36 Mb/s

                    Bit Rates:9 Mb/s; 18 Mb/s; 48 Mb/s; 54 Mb/s

                    Mode:Master

                    Extra:tsf=00000001e3e62181

                    Extra: Last beacon: 584ms ago

                    IE: Unknown: 000A7465726D696E61746F72

                    IE: Unknown: 010882848B960C183048

                    IE: Unknown: 030106

                    IE: Unknown: 050400010000

                    IE: Unknown: 2A0102

                    IE: Unknown: 32041224606C

                    IE: IEEE 802.11i/WPA2 Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (2) : TKIP CCMP

                        Authentication Suites (1) : PSK

                       Preauthentication Supported

                    IE: WPA Version 1

                        Group Cipher : TKIP

                        Pairwise Ciphers (2) : TKIP CCMP

                        Authentication Suites (1) : PSK

                    IE: Unknown: DD0900037F01010008FF7F

                    IE: Unknown: DD1A00037F0301000000002586F21B12022586F21B1264002C010808

```

There ya be, will that tell ya whatcha need?  Let me know if you need anything more.

As far as the kernels go, my Gentoo-foo is a little weak.  Updates are still a little scary.  I'll hafta get a little bolder with the kernel update side of things.  Especially if this makes my card work better   :Very Happy:  .

Thanks again my friends, I appreciate it.

soloslinger

----------

## soloslinger

Well, I realized I had only looked at the output of ifconfig with the modules_wlan0="wpa_supplicant" and an /etc/init.d/net.wlan0.  Sloppy me.  Here's a tail -40 /var/log/messages after I try that:

```

May 21 00:12:28 lappy kernel: [   11.567584] Adding 4194716k swap on /dev/sda3.  Priority:-1 extents:1 across:4194716k 

May 21 00:12:28 lappy sshd[3074]: Server listening on 0.0.0.0 port 22.

May 21 00:12:28 lappy sshd[3074]: Server listening on :: port 22.

May 21 00:12:29 lappy cron[3190]: (CRON) STARTUP (V5.0)

May 21 00:12:46 lappy login[3255]: pam_unix(login:session): session opened for user soloslinger by LOGIN(uid=0)

May 21 00:12:50 lappy su[3266]: Successful su for root by soloslinger

May 21 00:12:50 lappy su[3266]: + tty1 soloslinger:root

May 21 00:12:50 lappy su[3266]: pam_unix(su:session): session opened for user root by soloslinger(uid=1000)

May 21 00:14:01 lappy kernel: [  111.360656] ADDRCONF(NETDEV_UP): wlan0: link is not ready

May 21 00:14:02 lappy kernel: [  113.021277] wlan0: deauthenticating from 00:18:f8:53:76:b3 by local choice (reason=3)

May 21 00:14:02 lappy kernel: [  113.021310] wlan0: direct probe to AP 00:18:f8:53:76:b3 (try 1)

May 21 00:14:02 lappy kernel: [  113.024715] wlan0: direct probe responded

May 21 00:14:02 lappy kernel: [  113.024720] wlan0: authenticate with AP 00:18:f8:53:76:b3 (try 1)

May 21 00:14:02 lappy kernel: [  113.026767] wlan0: authenticated

May 21 00:14:02 lappy kernel: [  113.026787] wlan0: associate with AP 00:18:f8:53:76:b3 (try 1)

May 21 00:14:02 lappy kernel: [  113.030985] wlan0: RX AssocResp from 00:18:f8:53:76:b3 (capab=0x411 status=0 aid=4)

May 21 00:14:02 lappy kernel: [  113.030990] wlan0: associated

May 21 00:14:02 lappy kernel: [  113.032182] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

May 21 00:14:03 lappy wpa_cli: interface wlan0 CONNECTED

May 21 00:14:04 lappy rc-scripts: Configuration not set for wlan0 - assuming DHCP

May 21 00:14:04 lappy dhcpcd[4152]: wlan0: dhcpcd 4.0.15 starting

May 21 00:14:04 lappy dhcpcd[4152]: wlan0: broadcasting for a lease

May 21 00:14:05 lappy dhcpcd[4152]: wlan0: offered 192.168.1.106 from 192.168.1.1

May 21 00:14:05 lappy dhcpcd[4152]: wlan0: acknowledged 192.168.1.106 from 192.168.1.1

May 21 00:14:05 lappy dhcpcd[4152]: wlan0: checking 192.168.1.106 is available on attached networks

May 21 00:14:09 lappy dhcpcd[4161]: wlan0: dhcpcd already running on pid 4152 (/var/run/dhcpcd-wlan0.pid)

May 21 00:14:11 lappy dhcpcd[4152]: wlan0: leased 192.168.1.106 for 86400 seconds

May 21 00:14:13 lappy kernel: [  123.461559] wlan0: no IPv6 routers present

```

The IP scheme fits too, so it is getting issued an IP by my wireless 'router'.  But when I do an ifconfig afterwords, wlan0 isn't assigned an interface, and I can't make any traffic fly.  If I try to manually run dhcp I get an error that says it's already running.  Also, if I stop the interface from that init script, then try to restart it, I get a kernel error to the effect of SIOCIFFLAGS unknown error 132.

----------

## erik258

Well, from your messages, it seems as though all is well.  You associate successfully and you're given a dhcp lease.

Are you plugged into any other networks at the time?

I don't know why you're having problems with the ip disappearing.  But I will say this: apparently something else is trying to manage your wireless for you at the same time: (note middle line, and PID differing)  

 *Quote:*   

> 
> 
> May 21 00:14:05 lappy dhcpcd[4152]: wlan0: checking 192.168.1.106 is available on attached networks
> 
> May 21 00:14:09 lappy dhcpcd[4161]: wlan0: dhcpcd already running on pid 4152 (/var/run/dhcpcd-wlan0.pid)
> ...

 

My preferred way of messing with dhcpcd after the fact is to killall dhcpcd and then run manually afterwords.  Alternatively, you can also set up your network manually with ip/netmask and default route.  Same as dhcp except your lease never expires, and you also need to set nameservers.  

 *Quote:*   

> SIOCIFFLAGS unknown error 132.

 

I get that almost every time I bring my wlan0 down/up to reassociate.  But it's very rarely problematic (only when I get 4 at once).

----------

