Using the wpa_ctrl socket interface from an external project

John Beard john.j.beard at gmail.com
Fri May 10 07:11:03 EDT 2013


Hi,

I am hoping to use the wpa_ctrl socket interface to communicate with
wpa_supplicant in order to get information about wifi signal strengths.

I have tried to use the DBus interface, but I couldn't find much in the
way of useful information about the library I was using (libdbus-c++)
and when I asked further, I was told it is no longer usefully maintained
and that I should look elsewhere. I'd rather keep things smaller than
pulling in big deps, so I don't really want to use something like GDBus.
The control socket should be fine for my purposes, but I'm having a bit
of trouble using it.

I can compile wpa_supplicant just fine, but I don't know how to compile
into a library suitable for linking into my project. I looked in
libutils.a, but that doesn't seem to have the wpa_ctrl_open() function
in it.

I can see how I can add my own code to the wpa_supplicant tree (like
wpa_cli), but I'm more looking to add to another project, rather than
extend wpa_supplicant, and I couldn't see any likely-looking targets in
the Makefiles.

The minimal code that I am trying to get to work is below (wpa_ctrl.h is
copied into my working dir for now):

===============

#include <stdio.h>
#include "wpa_ctrl.h"

#define CTRL_PATH "/var/run/wpa_supplicant.pid"

int main(int argc, char** argv)
{
    struct wpa_ctrl* wpac;

    wpac = wpa_ctrl_open(CTRL_PATH);

    if (!wpac){
        printf("Could not get ctrl interface!\n");
        return -1;
    }

    return 0;
}

===============

Could someone provide a quick pointer on how to correctly link against
wpa_ctrl for control socket access to wpa_supplicant?

Thanks and best regards,

John Beard


More information about the HostAP mailing list