Non-remote control of wpa_supplicant

Ted Merrill ted
Tue Nov 13 10:27:07 PST 2007


The wpa_ctrl feature allows control of wpa_supplicant from another 
process/program.  For control within the same process/program, calls can be 
made "directly" to the needed subroutines.
But one thing that is missing is that there is general way to monitor state 
changes from within the same process except perhaps by periodic polling.
I've added the following to my local copy (in wpa_supplicant_i.h):

----------------------------------------------

/**
 * struct wpa_supplicant_cb - State change callback
 *
 * Callback function is called AFTER the state is marked as changed.
 * Information from the callback struct should be obtained via
 * the access functions (below).
 */
struct wpa_supplicant_cb {
        struct wpa_supplicant_cb *next;
        struct wpa_supplicant_cb *prev;
        void (*cb_func)(struct wpa_supplicant_cb *cb);
        struct wpa_supplicant *wpa_s;
        void *cookie;   /* passed to cb */
};

/**
 * wpa_supplicant_cb_create -- set up a state change callback.
 * @wpa_s: wpa_supplicant instance whose state is to be monitored
 * @cb_func: function to call back on state change
 *
 * The call back function is called after each state change.
 * Returns handle to control structure for this callback, which
 * may be used to query for information and for cleanup when the
 * callback is no longer appropriate.
 *
 * IMPORTANT: the call back function MUST check the state
 * (using e.g. wpa_supplicant_cb_state_get()) and if the
 * state is WPA_TERMINATED it must call
 * wpa_supplicant_cb_destroy() to remove the callback.
 */
struct wpa_supplicant_cb *wpa_supplicant_cb_create(
        struct wpa_supplicant *wpa_s,
        void (*cb_func)(struct wpa_supplicant_cb *cb));

/**
 * wpa_supplicant_cb_wpa_s_get - get wpa_supplicant instance of callback.
 * @cb: callback handle from wpa_supplicant_cb_create()
 */
static inline struct wpa_supplicant *wpa_supplicant_cb_wpa_s_get(
        struct wpa_supplicant_cb *cb)
{
        return cb->wpa_s;
}

/**
 * wpa_supplicant_cb_state_get - get wpa_supplicant state.
 * @cb: callback handle from wpa_supplicant_cb_create()
 */
static inline wpa_state wpa_supplicant_cb_state_get(
        struct wpa_supplicant_cb *cb)
{
        return cb->wpa_s->wpa_state;
}

/**
 * wpa_supplicant_cb_last_state_get - get last wpa_supplicant state.
 * @cb: callback handle from wpa_supplicant_cb_create()
 */
static inline wpa_state wpa_supplicant_cb_last_state_get(
        struct wpa_supplicant_cb *cb)
{
        return cb->wpa_s->last_wpa_state;
}

/**
 * wpa_supplicant_cb_cookie_set - set an application cookie for later use.
 * @cb: callback handle from wpa_supplicant_cb_create()
 */
static inline void wpa_supplicant_cb_cookie_set(
        struct wpa_supplicant_cb *cb,
        void *cookie)
{
        cb->cookie = cookie;
}

/**
 * wpa_supplicant_cb_cookie_get - get application cookie.
 * @cb: callback handle from wpa_supplicant_cb_create()
 */
static inline void *wpa_supplicant_cb_cookie_get(
        struct wpa_supplicant_cb *cb)
{
        return cb->cookie;
}

/**
 * wpa_supplicant_cb_destroy -- remove state change callback.
 * @cb: callback handle from wpa_supplicant_cb_create()
 *
 * After calling this, the cb resource is freed and must not be
 * used again.
 */
void wpa_supplicant_cb_destroy(
        struct wpa_supplicant_cb *cb);

-------------------------------------------------------------------------


In addition, i've added a new state WPA_TERMINATED (== 0) to wpa_states whose 
use is explained in the comments above.

I'll submit this as a patch, but i'm interested in getting comments as soon as 
possible.

-Ted Merrill
Atheros Communications





More information about the Hostap mailing list