# Choose iwconfig/wpa_supplicant based on ESSID?

## schiotz

The new baselayout is really flexible - but users always want more.  :Very Happy: 

Is there a way to choose between iwconfig and wpa_supplicant based on the ESSID?  

There is one misbehaving laptop that I cannot get to connect to the universitys unencrypted net (see this thread), so I would like to evade the problem and only use wpa_supplicant at the home network.

/Jakob

----------

## UberLord

 *schiotz wrote:*   

> The new baselayout is really flexible - but users always want more. 

 

Greedy, greedy :p

 *Quote:*   

> 
> 
> Is there a way to choose between iwconfig and wpa_supplicant based on the ESSID?

 

Short answer: no

Long answer: no, but you can write some code todo this

Summary

iwconfig and wpa_supplicant modules work independantly of each other so you don't need wireless-tools installed for wpa_supplicant to work and vice versa.

However, wpa_supplicant cannot do a "pre scan" and report back essid's - you need wireless-tools for this

Not all wireless cards/drivers support scanning

If wpa_supplicant cannot associate with an AP then it's a bug with wpa_supplicant or a configuration issue - neither of which I'm willing to fix

So, in summary Gentoo will not provide this option.

However, it is possible to fix the module order using code - here's how

/etc/conf.d/net

```

if iwlist ${IFACE} 2>/dev/null | grep -q 'ESSID: "home"' ; then

   modules=( "wpa_supplicant" )

else

   modules=( "iwconfig" )

fi
```

----------

## schiotz

 *UberLord wrote:*   

> 
> 
>  *Quote:*   
> 
> Is there a way to choose between iwconfig and wpa_supplicant based on the ESSID? 
> ...

 

I like that kind of answers!  Of course it is obvious once you know the answer - and it even works!

I modified the code a little, so I don't run iwlist on my cabled ethernet:

```
if [[ $IFACE == wlan0 ]]; then

  if iwlist ${IFACE} scanning 2>/dev/null | grep -q 'ESSID:"AsgardWPA"' ; then

    modules=( "wpa_supplicant" )

    wpa_supplicant_wlan0="-Dndiswrapper -d"

    einfo "Using WPA supplicant on $IFACE"

  else

    modules=( "iwconfig" )

    mode_wlan0="managed"

    einfo "Using iwconfig on $IFACE"

  fi

fi

```

Thank you very much indeed!

 :Very Happy:   :Smile:   :Smile:   :Smile:   :Smile:   :Very Happy: 

Jakob

----------

## Jtb

 *schiotz wrote:*   

> 
> 
> I modified the code a little, so I don't run iwlist on my cabled ethernet:
> 
> ```
> ...

 

a little bit more modified:

```
if [[ $IFACE == wlan0 ]]; then

  if iwlist ${IFACE} scanning 2>/dev/null | grep -q 'Extra:wpa_ie=' ; then

    modules=( "wpa_supplicant" )

    einfo "Using WPA supplicant on $IFACE"

  else

    modules=( "iwconfig" )

    einfo "Using iwconfig on $IFACE"

  fi

fi

```

Check for WPA based on wpa_ie and not the essid..

The wpa_supplicant_wlan0 and mode can be always set  :Wink: 

----------

## UberLord

The check for wlan0 is redundant btw ..... unless you have more than one wireless card and only want it to work on wlan0. It should not affect wired cards in the slightest - and as we're dumping errors to /dev/null you won't see any errors.

And the iwconfig module can load for wired devices - it just won't do anything.

----------

## schiotz

 *UberLord wrote:*   

> The check for wlan0 is redundant btw ..... unless you have more than one wireless card and only want it to work on wlan0. It should not affect wired cards in the slightest - and as we're dumping errors to /dev/null you won't see any errors.
> 
> 

 

Good point.  It might at most cost a few milliseconds while bringing up the wired interface.  :Smile: 

I had halfway convinced myself that the script should not work when I pull out the card - then iwlist will fail while taking down the net, and presumably the iwconfig module rather than the wpa_supplicant module takes the net down.  But it works, wpa_supplicant stops as it should, and the net comes back up when the card is reinserted.  Either you have made some very robust logic behind the scenes, or wpa_supplicant just crashes with good timing.  :Very Happy: 

/Jakob

----------

## UberLord

 *schiotz wrote:*   

> Either you have made some very robust logic behind the scenes, or wpa_supplicant just crashes with good timing. 

 

I don't actually know what happens to wpa_supplicant if an interface is pulled out underneath it - however when somethings does "net.wlan0 stop" then every module is loaded and then stopped if the software is installed. This is important if you change from dhcp to static whilst dhcp is running and then stop the interface  :Wink: 

----------

## schiotz

It sound like you Do The Right Thing (TM).  :Cool: 

----------

