Wpa_supplicant : Be notified of a state change

Jouni Malinen jkmaline
Sun Aug 20 09:20:19 PDT 2006

On Fri, Aug 18, 2006 at 03:29:48PM +0200, Vincent Maurin wrote:

> I use wpa supplicant as a library in a Visual Studio project.

> I can access to the wpa state with the wpa_supplicant_get_state function.
> My code look like this :
> wpa_supplicant_associate(...)
> while (state != associated)
> {
>     sleep serveral seconds ....
> }
> echo ("I'm associated !")

Are you running wpa_supplicant in a separate thread (including eloop) or
how is this sleeping done?

> It's very bad. I want to do something like this :
> event_associated ()
> {
>     echo("I'm associated !")
> }
> wpa_supplicant_register_event_associated (event_associated);
> wpa_supplicant_associate()

Yes, this looks like quite a bit nicer way of doing this.

> I have searched in the code, but I don't find anything already done.
> Is a function register_event_associated implemented in wpa_supplicant or 
> I have to do it myself ?

No, there has not been enough need for this internally, so only external
notification (ctrl_iface message to other processes) is included.
Depending on your program design, that may be enough if you open an
ctrl_iface monitor from your code. However, if you are running your code
in the same process (but likely different thread), you could add such
callback registration and call the registered callback functions from
wpa_supplicant_set_state(). Though, this would need some synchronization
between the threads.

Jouni Malinen                                            PGP id EFC895FA

More information about the Hostap mailing list