I am trying to get a notification every time a client get associated/disassociated, from a C/C++ program. I've tried to make a program which uses the hostapd control interface and it worked great. Except that the resulting api looks quite unstable: it returns a simple string when returning the MAC address of the client getting associated.
Here is the sample program:
#include <stdio.h>
#include "wpa_ctrl.h"
int main() {
struct wpa_ctrl *ctrl_conn = wpa_ctrl_open("/var/run/hostapd/wlan0");
if (ctrl_conn == NULL) {
printf("Impossible to reconnect to /var/run/hostapd/wlan0\n");
return 1;
}
printf("/var/run/hostapd/wlan0 is connected.\n");
int res = wpa_ctrl_attach(ctrl_conn);
if (res != 0) {
printf("Impossible to attach /var/run/hostapd/wlan0.\n");
return 1;
}
printf("/var/run/hostapd/wlan0 is attached.\n");
char buf[4096];
size_t len = sizeof(buf) - 1;
while (wpa_ctrl_recv(ctrl_conn, buf, &len) == -1) {
printf("Impossible to recv msgs.\n");
sleep(1);
// return 1;
}
buf[len] = '\0';
printf("recv a msg : len=%d. buf=%s\n", len, buf);
return 0;
}
The output is :
...
recv a msg : len=37. buf=<3>AP-STA-CONNECTED 52:14:9f:54:e7:40
As you can see, the ouput is not the kind of stable API one can dream about.
So my question is: is there a better way to get the notifications when someone gets associated/dissociated?
If not so, do you think it is possible to extend hostapd to bring those kind of notifications into ubus? (And support those code modifications into the git repository?)