# Help: Can't set wep key via iwconfig

## Sunnz

Here's the actuall command what I used:

modprobe ath_pci;

ifconfig ath0 up;

iwconfig ath0 essid "myEssid";

iwconfig ath0 key theKeyInHex;

Where the last line gives this error:

Error for wireless request "Set Encode" (8B2A)

SET failed on device ath0; Invalid argument.

I also tried iwconfig ath0 enc theKeyInHex;

But it gives the same error as above.

----------

## NeddySeagoon

Sunnz,

Heres my net file, for setting up wireless.

```
# Use iwconfig for wireless

modules=("iwconfig")

#############  This is Grytpype-Thynne ##################

key_RadioNet="[1] 207c-9c4d-84 key [1] enc open"

#iwconfig_rausb0="essid RadioNet"

essid_rausb0="RadioNet"

#iwconfig_rausb0="channel 2"

channel_rausb0="2"

#iwconfig_rausb0="mode managed"

mode_rausb0="managed"

#iwconfig_rausb0="enc 207C-9C4D-84"

#enc_rausb0="207c-9c4d-84"

config_rausb0=( "192.168.100.90 netmask 255.255.255.0" )

routes_rausb0=( "default gw 192.168.100.1"

              "-net 192.168.0.0/24 gw 192.168.100.6"
```

Read 

```
iwconfig -h
```

iwconfig ath0 key theKeyInHex should be 

iwconfig ath0 enc theKeyInHex

----------

## Sunnz

Is that the /etc/conf.d/net file? I don't get what it means... do I just copy it??? I am using DHCP so an ip would be assigned automatically... I tried both key and enc, but they gives the same error.

----------

## NeddySeagoon

Sunnz,

Thats my working /etc/conf.d/net file - it sets up everything statically.

Its intended as an example for you to follow, not something to copy and paste.

Since 

```
iwconfig <iface> enc <key>
```

fails, there must be an error in the syntax you are supplying.

Are you sure your key is the right lenght?

What about the case of hex digits A-F, it may be important since normally A<>a ?

----------

## Sunnz

But I ain't setting it up statically, it is DHCP... do I just leave net blank then?

I tried both uppercase and lowercase for the key, but it doesn't work...

This is the error I am getting:

Error for wireless request "Set Encode" (8B2A)

SET failed on device ath0; Invalid argument. 

This is the command:

iwconfig ath0 enc theKeyInHex

----------

## NeddySeagoon

Sunnz.

How many hex chararacters are there in your key?

Show me a sample of *exatly* what you type, you may change the charaters in the key is you want but be aware it only takes about an hour to crack anyway.

----------

## Sunnz

Let's not worry about the WEP key the moment, I have turned off WEP on the router.

Here's the commands that I have tried:

modprobe ath_pci;

ifconfig ath0 up;

iwconfig ath0 essid "myID"

dhcpcd ath0

But dhcpcd ath0 couldn't get an IP... it just turns off ath0, with no error message.

So what's wrong?

We'll try WEP later.

----------

## NeddySeagoon

Sunnz,

You are leaving the mode and channel to chance, or rather you are making the unstated assumption that your AP and PC both have the same defualts. There are 13 channels and 3 modes to choose from so thats a 1:39 chance it works.

Explicitly use iwconfig to set all the radio link variables, then dhcp can use the radio link to get an IP address.

The order is important. Theres no point in dhcpd broadcasting for an IP address on channel 3 (the Gentoo defult) if the AP is listening on channel 12.

If you want to model a net file on mine but to use dhcp, then remove the 

config_rausb0= and routes_rausb0= entries, dhcpd being the defualt.

The commented out lines above the 'live' entries show how to gibe the command manually.

----------

## Sunnz

Ok, now I have tried:

modprobe ath_pci;

iwconfig ath0 essid "myID" channel 12 enc open;

ifconfig ath0 up;

dhcpcd ath0;

My router is on channel 12 and its mode is "g & b".

But the above commands didn't make any difference...

How do I set the mode to g&b for the wifi card using iwconfig?[/list]

----------

## NeddySeagoon

Sunnz,

Take baby steps.

Only give iwconfig one command at a time.  Do

```
modprobe ath_pci

ifconfig -a
```

and make sure that you have an interface called ath0.

If thats OK continue.

```
iwconfig ath0 essid "myID"

iwconfig ath0 channel 12

iwconfig ath0 enc off

iwconfig ath0 mode managed

iwconfig ath0
```

should show that the changes have been made.

If not, read 

```
man iwconfig
```

and experiment with syntax.

Don't worry about link quality and other reported link related numbers, they are not all meaningful until the link is up.

If that all looks good, try to get an IP address.

```
dhcpcd ath0
```

You post contains ';' at the end of every line - they are not required. I'm not sure if they are harmless or not.

----------

## Sunnz

dhcpcd ath0 still couldn't get an ip...

Is it ok to leave /etc/conf.d/net blank at this stage?

I also tried ifconfig ath0 up before I do dhcpcd ath0; but that doesn't help...

----------

## Sunnz

Ok dhcpcd now works somehow...

Now, how do I set it up so it connects to the AP automatically during boot? I have to edit the /etc/conf.d/net file, do I? What do I put in it for dhcp with essid keys channels and stuff?

----------

## NeddySeagoon

Sunnz,

dhcpd is what you get if you don't put any configuration information in your /etc/conf.d/net file.

As to the syntax for the wireless settings, see my setup earlier in the thread.

That can go in /etc/conf.d/net or in /etc/conf.d/wireless although the latter is depreciated.

----------

## Sunnz

Umm I don't quite get the net file... lines like:

#iwconfig_rausb0="essid RadioNet" 

Are commands, right? I have this:

modules=("iwconfig")

essid_ath0="my.essid"

mode_ath0="managed"

channel_ath0="11"

key_my_essid="XXXX-XXXX-XXXX-XXXX-XX enc open"

But /etc/init.d/net.ath0 start says:

For Wireless Support, emerge wireless-tools.

But I have already done that and I am able to connect using iwconfig!!!!

----------

## NeddySeagoon

Sunnz,

Lines starting with a # are comments. They are ignored by scripts.

```
key_RadioNet="[1] 207c-9c4d-84 key [1] enc open"
```

sets the WEP encryption key in /etc/conf.d/net.

This key will be used with the network with an ESSID of RadioNet.

----------

## Sunnz

Ohhh right! Everything works perfect now! Thank you very much!!!! *hugs NeddySeagoon*

----------

