about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-07-06 21:42:01 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-07-06 21:42:01 +0000
commit330f54ac7f780872223f9cac62347393ffb4ef86 (patch)
tree1de817bd4b556e487b93884ac21561e1e5779635 /src
downloadbcnm-330f54ac7f780872223f9cac62347393ffb4ef86.tar.gz
bcnm-330f54ac7f780872223f9cac62347393ffb4ef86.tar.xz
bcnm-330f54ac7f780872223f9cac62347393ffb4ef86.zip
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/include/bcnm/wpactrl.h210
-rw-r--r--src/libwpactrl/deps-lib/wpactrl12
-rw-r--r--src/libwpactrl/wpactrl-internal.h18
-rw-r--r--src/libwpactrl/wpactrl_command.c41
-rw-r--r--src/libwpactrl/wpactrl_end.c11
-rw-r--r--src/libwpactrl/wpactrl_fd_recv.c47
-rw-r--r--src/libwpactrl/wpactrl_fd_timed_recv.c29
-rw-r--r--src/libwpactrl/wpactrl_filter_add.c12
-rw-r--r--src/libwpactrl/wpactrl_filter_exact_search.c12
-rw-r--r--src/libwpactrl/wpactrl_filter_remove.c16
-rw-r--r--src/libwpactrl/wpactrl_query.c11
-rw-r--r--src/libwpactrl/wpactrl_querysa.c15
-rw-r--r--src/libwpactrl/wpactrl_start.c45
-rw-r--r--src/libwpactrl/wpactrl_update.c48
-rw-r--r--src/libwpactrl/wpactrl_zero.c5
15 files changed, 532 insertions, 0 deletions
diff --git a/src/include/bcnm/wpactrl.h b/src/include/bcnm/wpactrl.h
new file mode 100644
index 0000000..af105c3
--- /dev/null
+++ b/src/include/bcnm/wpactrl.h
@@ -0,0 +1,210 @@
+/* ISC license. */
+
+#ifndef BCNM_WPACTRL_H
+#define BCNM_WPACTRL_H
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <skalibs/tai.h>
+#include <skalibs/stralloc.h>
+
+typedef enum wparesponse_e wparesponse_t, *wparesponse_t_ref ;
+enum wparesponse_e
+{
+  WPA_ERROR = -1,
+  WPA_OK = 0,
+  WPA_PONG,
+  WPA_UNKNOWNCOMMAND,
+  WPA_FAIL,
+  WPA_FAILBUSY,
+  WPA_FAILCHECKSUM,
+  WPA_FAILINVALIDPIN,
+  WPA_FAILCHANNELUNAVAILABLE,
+  WPA_FAILCHANNELUNSUPPORTED,
+  WPA_FAILINVALIDRANGE,
+  WPA_FAILTOOLONGRESPONSE,
+  WPA_FAILPBCOVERLAP,
+  WPA_FAILUNKNOWNUUID,
+  WPA_FAILNOAPSETTINGS,
+  WPA_FAILNOIFNAMEATTACH,
+  WPA_UNKNOWNRESPONSE
+} ;
+
+typedef struct wpactrl_s wpactrl_t, *wpactrl_t_ref ;
+struct wpactrl_s
+{
+  int fds ;
+  int fda ;
+  uint32_t options ;
+  stralloc data ;
+  stralloc filters ;
+} ;
+#define WPACTRL_ZERO { .fds = -1, .fda = -1, .options = 0, .data = STRALLOC_ZERO, .filters = STRALLOC_ZERO }
+
+#define WPACTRL_OPTION_NOFILTER 0x0001U
+
+extern wpactrl_t const wpactrl_zero ;
+
+extern int wpactrl_start (wpactrl_t *, char const *, tain_t const *, tain_t *) ;
+#define wpactrl_start_g(a, path, deadline) wpactrl_start(a, path, (deadline), &STAMP)
+extern void wpactrl_end (wpactrl_t *) ;
+
+extern wparesponse_t wpactrl_command (wpactrl_t *, char const *, size_t, tain_t const *, tain_t *) ;
+#define wpactrl_command_g(a, q, qlen, deadline) wpactrl_command(a, q, qlen, (deadline), &STAMP)
+extern ssize_t wpactrl_query (wpactrl_t *, char const *, size_t, char *, size_t, tain_t const *, tain_t *) ;
+#define wpactrl_query_g(a, q, qlen, ans, ansmax, deadline) wpactrl_query(a, q, qlen, ans, ansmax, (deadline), &STAMP)
+extern int wpactrl_querysa (wpactrl_t *, char const *, size_t, stralloc *, tain_t const *, tain_t *) ;
+#define wpactrl_querysa_g(a, q, qlen, sa, deadline) wpactrl_querysa(a, q, qlen, sa, (deadline), &STAMP)
+
+extern int wpactrl_filter_add (wpactrl_t *, char const *) ;
+extern void wpactrl_filter_remove (wpactrl_t *, char const *) ;
+
+#define wpactrl_filter_activate(a) ((a)->options &= ~(uint32_t)WPACTRL_OPTION_NOFILTER)
+#define wpactrl_filter_deactivate(a) ((a)->options |= WPACTRL_OPTION_NOFILTER)
+
+extern int wpactrl_update (wpactrl_t *) ;
+#define wpactrl_data(a) ((a)->data.s)
+#define wpactrl_datalen(a) ((a)->data.len))
+#define wpactrl_ackdata(a) ((a)->data.len = 0)
+
+
+ /*
+    The following is taken from wpa_supplicant's wpa_ctrl.h.
+ */
+
+#define WPA_CTRL_REQ "CTRL-REQ-"
+#define WPA_CTRL_RSP "CTRL-RSP-"
+#define WPA_EVENT_CONNECTED "CTRL-EVENT-CONNECTED "
+#define WPA_EVENT_DISCONNECTED "CTRL-EVENT-DISCONNECTED "
+#define WPA_EVENT_ASSOC_REJECT "CTRL-EVENT-ASSOC-REJECT "
+#define WPA_EVENT_AUTH_REJECT "CTRL-EVENT-AUTH-REJECT "
+#define WPA_EVENT_TERMINATING "CTRL-EVENT-TERMINATING "
+#define WPA_EVENT_PASSWORD_CHANGED "CTRL-EVENT-PASSWORD-CHANGED "
+#define WPA_EVENT_EAP_NOTIFICATION "CTRL-EVENT-EAP-NOTIFICATION "
+#define WPA_EVENT_EAP_STARTED "CTRL-EVENT-EAP-STARTED "
+#define WPA_EVENT_EAP_PROPOSED_METHOD "CTRL-EVENT-EAP-PROPOSED-METHOD "
+#define WPA_EVENT_EAP_METHOD "CTRL-EVENT-EAP-METHOD "
+#define WPA_EVENT_EAP_PEER_CERT "CTRL-EVENT-EAP-PEER-CERT "
+#define WPA_EVENT_EAP_PEER_ALT "CTRL-EVENT-EAP-PEER-ALT "
+#define WPA_EVENT_EAP_TLS_CERT_ERROR "CTRL-EVENT-EAP-TLS-CERT-ERROR "
+#define WPA_EVENT_EAP_STATUS "CTRL-EVENT-EAP-STATUS "
+#define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
+#define WPA_EVENT_EAP_FAILURE "CTRL-EVENT-EAP-FAILURE "
+#define WPA_EVENT_TEMP_DISABLED "CTRL-EVENT-SSID-TEMP-DISABLED "
+#define WPA_EVENT_REENABLED "CTRL-EVENT-SSID-REENABLED "
+#define WPA_EVENT_SCAN_STARTED "CTRL-EVENT-SCAN-STARTED "
+#define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS "
+#define WPA_EVENT_SCAN_FAILED "CTRL-EVENT-SCAN-FAILED "
+#define WPA_EVENT_STATE_CHANGE "CTRL-EVENT-STATE-CHANGE "
+#define WPA_EVENT_BSS_ADDED "CTRL-EVENT-BSS-ADDED "
+#define WPA_EVENT_BSS_REMOVED "CTRL-EVENT-BSS-REMOVED "
+#define WPA_EVENT_NETWORK_NOT_FOUND "CTRL-EVENT-NETWORK-NOT-FOUND "
+#define WPA_EVENT_SIGNAL_CHANGE "CTRL-EVENT-SIGNAL-CHANGE "
+#define WPA_EVENT_BEACON_LOSS "CTRL-EVENT-BEACON-LOSS "
+#define WPA_EVENT_REGDOM_CHANGE "CTRL-EVENT-REGDOM-CHANGE "
+#define WPA_EVENT_CHANNEL_SWITCH "CTRL-EVENT-CHANNEL-SWITCH "
+#define WPA_EVENT_SUBNET_STATUS_UPDATE "CTRL-EVENT-SUBNET-STATUS-UPDATE "
+#define IBSS_RSN_COMPLETED "IBSS-RSN-COMPLETED "
+#define WPA_EVENT_FREQ_CONFLICT "CTRL-EVENT-FREQ-CONFLICT "
+#define WPA_EVENT_AVOID_FREQ "CTRL-EVENT-AVOID-FREQ "
+#define WPS_EVENT_OVERLAP "WPS-OVERLAP-DETECTED "
+#define WPS_EVENT_AP_AVAILABLE_PBC "WPS-AP-AVAILABLE-PBC "
+#define WPS_EVENT_AP_AVAILABLE_AUTH "WPS-AP-AVAILABLE-AUTH "
+#define WPS_EVENT_AP_AVAILABLE_PIN "WPS-AP-AVAILABLE-PIN "
+#define WPS_EVENT_AP_AVAILABLE "WPS-AP-AVAILABLE "
+#define WPS_EVENT_CRED_RECEIVED "WPS-CRED-RECEIVED "
+#define WPS_EVENT_M2D "WPS-M2D "
+#define WPS_EVENT_FAIL "WPS-FAIL "
+#define WPS_EVENT_SUCCESS "WPS-SUCCESS "
+#define WPS_EVENT_TIMEOUT "WPS-TIMEOUT "
+#define WPS_EVENT_ACTIVE "WPS-PBC-ACTIVE "
+#define WPS_EVENT_DISABLE "WPS-PBC-DISABLE "
+#define WPS_EVENT_ENROLLEE_SEEN "WPS-ENROLLEE-SEEN "
+#define WPS_EVENT_OPEN_NETWORK "WPS-OPEN-NETWORK "
+#define WPS_EVENT_ER_AP_ADD "WPS-ER-AP-ADD "
+#define WPS_EVENT_ER_AP_REMOVE "WPS-ER-AP-REMOVE "
+#define WPS_EVENT_ER_ENROLLEE_ADD "WPS-ER-ENROLLEE-ADD "
+#define WPS_EVENT_ER_ENROLLEE_REMOVE "WPS-ER-ENROLLEE-REMOVE "
+#define WPS_EVENT_ER_AP_SETTINGS "WPS-ER-AP-SETTINGS "
+#define WPS_EVENT_ER_SET_SEL_REG "WPS-ER-AP-SET-SEL-REG "
+#define DPP_EVENT_AUTH_SUCCESS "DPP-AUTH-SUCCESS "
+#define DPP_EVENT_NOT_COMPATIBLE "DPP-NOT-COMPATIBLE "
+#define DPP_EVENT_RESPONSE_PENDING "DPP-RESPONSE-PENDING "
+#define DPP_EVENT_SCAN_PEER_QR_CODE "DPP-SCAN-PEER-QR-CODE "
+#define DPP_EVENT_CONF_RECEIVED "DPP-CONF-RECEIVED "
+#define DPP_EVENT_CONF_SENT "DPP-CONF-SENT "
+#define DPP_EVENT_CONF_FAILED "DPP-CONF-FAILED "
+#define DPP_EVENT_CONFOBJ_SSID "DPP-CONFOBJ-SSID "
+#define DPP_EVENT_CONNECTOR "DPP-CONNECTOR "
+#define DPP_EVENT_C_SIGN_KEY "DPP-C-SIGN-KEY "
+#define DPP_EVENT_NET_ACCESS_KEY "DPP-NET-ACCESS-KEY "
+#define DPP_EVENT_MISSING_CONNECTOR "DPP-MISSING-CONNECTOR "
+#define DPP_EVENT_NETWORK_ID "DPP-NETWORK-ID "
+#define MESH_GROUP_STARTED "MESH-GROUP-STARTED "
+#define MESH_GROUP_REMOVED "MESH-GROUP-REMOVED "
+#define MESH_PEER_CONNECTED "MESH-PEER-CONNECTED "
+#define MESH_PEER_DISCONNECTED "MESH-PEER-DISCONNECTED "
+#define MESH_SAE_AUTH_FAILURE "MESH-SAE-AUTH-FAILURE "
+#define MESH_SAE_AUTH_BLOCKED "MESH-SAE-AUTH-BLOCKED "
+#define WMM_AC_EVENT_TSPEC_ADDED "TSPEC-ADDED "
+#define WMM_AC_EVENT_TSPEC_REMOVED "TSPEC-REMOVED "
+#define WMM_AC_EVENT_TSPEC_REQ_FAILED "TSPEC-REQ-FAILED "
+#define P2P_EVENT_DEVICE_FOUND "P2P-DEVICE-FOUND "
+#define P2P_EVENT_DEVICE_LOST "P2P-DEVICE-LOST "
+#define P2P_EVENT_GO_NEG_REQUEST "P2P-GO-NEG-REQUEST "
+#define P2P_EVENT_GO_NEG_SUCCESS "P2P-GO-NEG-SUCCESS "
+#define P2P_EVENT_GO_NEG_FAILURE "P2P-GO-NEG-FAILURE "
+#define P2P_EVENT_GROUP_FORMATION_SUCCESS "P2P-GROUP-FORMATION-SUCCESS "
+#define P2P_EVENT_GROUP_FORMATION_FAILURE "P2P-GROUP-FORMATION-FAILURE "
+#define P2P_EVENT_GROUP_STARTED "P2P-GROUP-STARTED "
+#define P2P_EVENT_GROUP_REMOVED "P2P-GROUP-REMOVED "
+#define P2P_EVENT_CROSS_CONNECT_ENABLE "P2P-CROSS-CONNECT-ENABLE "
+#define P2P_EVENT_CROSS_CONNECT_DISABLE "P2P-CROSS-CONNECT-DISABLE "
+#define P2P_EVENT_PROV_DISC_SHOW_PIN "P2P-PROV-DISC-SHOW-PIN "
+#define P2P_EVENT_PROV_DISC_ENTER_PIN "P2P-PROV-DISC-ENTER-PIN "
+#define P2P_EVENT_PROV_DISC_PBC_REQ "P2P-PROV-DISC-PBC-REQ "
+#define P2P_EVENT_PROV_DISC_PBC_RESP "P2P-PROV-DISC-PBC-RESP "
+#define P2P_EVENT_PROV_DISC_FAILURE "P2P-PROV-DISC-FAILURE"
+#define P2P_EVENT_SERV_DISC_REQ "P2P-SERV-DISC-REQ "
+#define P2P_EVENT_SERV_DISC_RESP "P2P-SERV-DISC-RESP "
+#define P2P_EVENT_SERV_ASP_RESP "P2P-SERV-ASP-RESP "
+#define P2P_EVENT_INVITATION_RECEIVED "P2P-INVITATION-RECEIVED "
+#define P2P_EVENT_INVITATION_RESULT "P2P-INVITATION-RESULT "
+#define P2P_EVENT_INVITATION_ACCEPTED "P2P-INVITATION-ACCEPTED "
+#define P2P_EVENT_FIND_STOPPED "P2P-FIND-STOPPED "
+#define P2P_EVENT_PERSISTENT_PSK_FAIL "P2P-PERSISTENT-PSK-FAIL id="
+#define P2P_EVENT_PRESENCE_RESPONSE "P2P-PRESENCE-RESPONSE "
+#define P2P_EVENT_NFC_BOTH_GO "P2P-NFC-BOTH-GO "
+#define P2P_EVENT_NFC_PEER_CLIENT "P2P-NFC-PEER-CLIENT "
+#define P2P_EVENT_NFC_WHILE_CLIENT "P2P-NFC-WHILE-CLIENT "
+#define P2P_EVENT_FALLBACK_TO_GO_NEG "P2P-FALLBACK-TO-GO-NEG "
+#define P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED "P2P-FALLBACK-TO-GO-NEG-ENABLED "
+#define ESS_DISASSOC_IMMINENT "ESS-DISASSOC-IMMINENT "
+#define P2P_EVENT_REMOVE_AND_REFORM_GROUP "P2P-REMOVE-AND-REFORM-GROUP "
+#define P2P_EVENT_P2PS_PROVISION_START "P2PS-PROV-START "
+#define P2P_EVENT_P2PS_PROVISION_DONE "P2PS-PROV-DONE "
+#define INTERWORKING_AP "INTERWORKING-AP "
+#define INTERWORKING_BLACKLISTED "INTERWORKING-BLACKLISTED "
+#define INTERWORKING_NO_MATCH "INTERWORKING-NO-MATCH "
+#define INTERWORKING_ALREADY_CONNECTED "INTERWORKING-ALREADY-CONNECTED "
+#define INTERWORKING_SELECTED "INTERWORKING-SELECTED "
+#define CRED_ADDED "CRED-ADDED "
+#define CRED_MODIFIED "CRED-MODIFIED "
+#define CRED_REMOVED "CRED-REMOVED "
+#define GAS_RESPONSE_INFO "GAS-RESPONSE-INFO "
+#define GAS_QUERY_START "GAS-QUERY-START "
+#define GAS_QUERY_DONE "GAS-QUERY-DONE "
+#define ANQP_QUERY_DONE "ANQP-QUERY-DONE "
+#define RX_ANQP "RX-ANQP "
+#define RX_HS20_ANQP "RX-HS20-ANQP "
+#define RX_HS20_ANQP_ICON "RX-HS20-ANQP-ICON "
+#define RX_HS20_ICON "RX-HS20-ICON "
+#define RX_MBO_ANQP "RX-MBO-ANQP "
+#define HS20_SUBSCRIPTION_REMEDIATION "HS20-SUBSCRIPTION-REMEDIATION "
+#define HS20_DEAUTH_IMMINENT_NOTICE "HS20-DEAUTH-IMMINENT-NOTICE "
+#define EXT_RADIO_WORK_START "EXT-RADIO-WORK-START "
+#define EXT_RADIO_WORK_TIMEOUT "EXT-RADIO-WORK-TIMEOUT "
+#define RRM_EVENT_NEIGHBOR_REP_RXED "RRM-NEIGHBOR-REP-RECEIVED "
+#define RRM_EVENT_NEIGHBOR_REP_FAILED "RRM-NEIGHBOR-REP-REQUEST-FAILED "
+
+#endif
diff --git a/src/libwpactrl/deps-lib/wpactrl b/src/libwpactrl/deps-lib/wpactrl
new file mode 100644
index 0000000..98cd9e6
--- /dev/null
+++ b/src/libwpactrl/deps-lib/wpactrl
@@ -0,0 +1,12 @@
+wpactrl_command.o
+wpactrl_end.o
+wpactrl_fd_recv.o
+wpactrl_fd_timed_recv.o
+wpactrl_filter_add.o
+wpactrl_filter_exact_search.o
+wpactrl_filter_remove.o
+wpactrl_query.o
+wpactrl_querysa.o
+wpactrl_start.o
+wpactrl_update.o
+wpactrl_zero.o
diff --git a/src/libwpactrl/wpactrl-internal.h b/src/libwpactrl/wpactrl-internal.h
new file mode 100644
index 0000000..b271eae
--- /dev/null
+++ b/src/libwpactrl/wpactrl-internal.h
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#ifndef BCNM_WPACTRL_INTERNAL_H
+#define BCNM_WPACTRL_INTERNAL_H
+
+#include <sys/types.h>
+#include <skalibs/gccattributes.h>
+#include <skalibs/tai.h>
+#include <bcnm/wpactrl.h>
+
+#define WPACTRL_PACKET_MAX 8192
+#define WPACTRL_RECV_MAX 32
+
+extern ssize_t wpactrl_fd_recv (int, char *, size_t) ;
+extern ssize_t wpactrl_fd_timed_recv (int, char *, size_t, tain_t const *, tain_t *) ;
+extern size_t wpactrl_filter_exact_search (wpactrl_t const *, char const *) gccattr_pure ;
+
+#endif
diff --git a/src/libwpactrl/wpactrl_command.c b/src/libwpactrl/wpactrl_command.c
new file mode 100644
index 0000000..c29a58a
--- /dev/null
+++ b/src/libwpactrl/wpactrl_command.c
@@ -0,0 +1,41 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+#include <bcnm/wpactrl.h>
+
+#define WPARESPONSE_MAXLEN 28
+
+wparesponse_t wpactrl_command (wpactrl_t *a, char const *s, size_t len, tain_t const *deadline, tain_t *stamp)
+{
+  static char const *wparesponses[] =
+  {
+    "OK\n",
+    "PONG\n",
+    "UNKNOWN COMMAND\n",
+    "FAIL\n",
+    "FAIL-BUSY\n",
+    "FAIL-CHECKSUM\n",
+    "FAIL-INVALID-PIN\n",
+    "FAIL-CHANNEL-UNAVAILABLE\n",
+    "FAIL-CHANNEL-UNSUPPORTED\n",
+    "FAIL-Invalid range\n",
+    "FAIL-Too long response\n",
+    "FAIL-PBC-OVERLAP\n",
+    "FAIL-UNKNOWN-UUID\n",
+    "FAIL-NO-AP-SETTINGS\n",
+    "FAIL-NO-IFNAME-MATCH\n",
+    0
+  } ;
+  char buf[WPARESPONSE_MAXLEN] ;
+  ssize_t r = wpactrl_query(a, s, len, buf, WPARESPONSE_MAXLEN, deadline, stamp) ;
+  if (r < 0) return WPA_ERROR ;
+  if (!r) return (errno = EPIPE, WPA_ERROR) ;
+  {
+    wparesponse_t i = 0 ;
+    for (; wparesponses[i] ; i++)
+      if (!strncmp(buf, wparesponses[i], r))
+        break ;
+    return i ;
+  }
+}
diff --git a/src/libwpactrl/wpactrl_end.c b/src/libwpactrl/wpactrl_end.c
new file mode 100644
index 0000000..40fdb4a
--- /dev/null
+++ b/src/libwpactrl/wpactrl_end.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/djbunix.h>
+#include <bcnm/wpactrl.h>
+
+void wpactrl_free (wpactrl_t *a)
+{
+  fd_close(a->fda) ;
+  fd_close(a->fds) ;
+  *a = wpactrl_zero ;
+}
diff --git a/src/libwpactrl/wpactrl_fd_recv.c b/src/libwpactrl/wpactrl_fd_recv.c
new file mode 100644
index 0000000..3e2a006
--- /dev/null
+++ b/src/libwpactrl/wpactrl_fd_recv.c
@@ -0,0 +1,47 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/nonposix.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <errno.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+ssize_t wpactrl_fd_recv (int fd, char *s, size_t len)
+{
+  static int const bsd_braindeadness_workaround_flags =
+#ifdef SKALIBS_HASMSGDONTWAIT
+    MSG_DONTWAIT
+#else
+    0
+#endif
+    |
+#ifdef SKALIBS_HASNBWAITALL
+    MSG_WAITALL
+#else
+    0
+#endif
+    |
+#ifdef SKALIBS_HASCMSGCLOEXEC
+    MSG_CMSG_CLOEXEC
+#else
+    0
+#endif
+    ;
+  struct iovec iov = { .iov_base = s, .iov_len = len } ;
+  struct msghdr msghdr =
+  {
+    .msg_name = 0,
+    .msg_namelen = 0,
+    .msg_iov = &iov,
+    .msg_iovlen = 1,
+    .msg_flags = 0,
+    .msg_control = 0,
+    .msg_controllen = 0
+  } ;
+  ssize_t r ;
+  do r = recvmsg(fd, &msghdr, bsd_braindeadness_workaround_flags) ;
+  while (r == -1 && errno == EINTR) ;
+  return r > 0 && msghdr.msg_flags | MSG_TRUNC ? (errno = EMSGSIZE, -1) : r ;
+}
diff --git a/src/libwpactrl/wpactrl_fd_timed_recv.c b/src/libwpactrl/wpactrl_fd_timed_recv.c
new file mode 100644
index 0000000..db181c1
--- /dev/null
+++ b/src/libwpactrl/wpactrl_fd_timed_recv.c
@@ -0,0 +1,29 @@
+/* ISC license. */
+
+#include <skalibs/functypes.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/unix-timed.h>
+#include "wpactrl-internal.h"
+
+struct blah_s
+{
+  int fd ;
+  char *s ;
+  size_t len ;
+} ;
+
+static int getfd (struct blah_s *blah)
+{
+  return blah->fd ;
+}
+
+static ssize_t get (struct blah_s *blah)
+{
+  return sanitize_read(wpactrl_fd_recv(blah->fd, blah->s, blah->len)) ;
+}
+
+ssize_t wpactrl_fd_timed_recv (int fd, char *s, size_t len, tain_t const *deadline, tain_t *stamp)
+{
+  struct blah_s blah = { .fd = fd, .s = s, .len = len } ;
+  return timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ;
+}
diff --git a/src/libwpactrl/wpactrl_filter_add.c b/src/libwpactrl/wpactrl_filter_add.c
new file mode 100644
index 0000000..8896e23
--- /dev/null
+++ b/src/libwpactrl/wpactrl_filter_add.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <string.h>
+#include <skalibs/stralloc.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+int wpactrl_filter_add (wpactrl_t *a, char const *s)
+{
+  if (wpactrl_filter_exact_search(a, s) < a->filters.len) return 1 ;
+  return stralloc_catb(&a->filters, s, strlen(s)) ;
+}
diff --git a/src/libwpactrl/wpactrl_filter_exact_search.c b/src/libwpactrl/wpactrl_filter_exact_search.c
new file mode 100644
index 0000000..c7197d7
--- /dev/null
+++ b/src/libwpactrl/wpactrl_filter_exact_search.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <string.h>
+#include "wpactrl-internal.h"
+
+size_t wpactrl_filter_exact_search (wpactrl_t const *a, char const *s)
+{
+  size_t pos = 0 ;
+  for ( ; pos < a->filters.len ; pos += strlen(a->filters.s + pos) + 1)
+    if (!strcmp(s, a->filters.s + pos)) break ;
+  return pos ;
+}
diff --git a/src/libwpactrl/wpactrl_filter_remove.c b/src/libwpactrl/wpactrl_filter_remove.c
new file mode 100644
index 0000000..d41ad6e
--- /dev/null
+++ b/src/libwpactrl/wpactrl_filter_remove.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <string.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+void wpactrl_filter_remove (wpactrl_t *a, char const *s)
+{
+  size_t pos = wpactrl_filter_exact_search(a, s) ;
+  if (pos >= a->filters.len)
+  {
+    size_t after = pos + strlen(a->filters.s + pos) + 1 ;
+    memmove(a->filters.s + pos, a->filters.s + after, a->filters.len - after) ;
+    a->filters.len -= after - pos ;
+  }
+}
diff --git a/src/libwpactrl/wpactrl_query.c b/src/libwpactrl/wpactrl_query.c
new file mode 100644
index 0000000..951c536
--- /dev/null
+++ b/src/libwpactrl/wpactrl_query.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/unix-timed.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+ssize_t wpactrl_query (wpactrl_t *a, char const *q, size_t qlen, char *ans, size_t ansmax, tain_t const *deadline, tain_t *stamp)
+{
+  if (!ipc_timed_send(a->fds, q, qlen, deadline, stamp)) return WPA_ERROR ;
+  return wpactrl_fd_timed_recv(a->fds, ans, ansmax, deadline, stamp) ;
+}
diff --git a/src/libwpactrl/wpactrl_querysa.c b/src/libwpactrl/wpactrl_querysa.c
new file mode 100644
index 0000000..fe06202
--- /dev/null
+++ b/src/libwpactrl/wpactrl_querysa.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/stralloc.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+int wpactrl_querysa (wpactrl_t *a, char const *s, size_t len, stralloc *sa, tain_t const *deadline, tain_t *stamp)
+{
+  char buf[WPACTRL_PACKET_MAX] ;
+  ssize_t r = wpactrl_query(a, s, len, buf, WPACTRL_PACKET_MAX, deadline, stamp) ;
+  if (r < 0) return 0 ;
+  if (!r) return (errno = EPIPE, 0) ;
+  return stralloc_catb(sa, buf, r) ;
+}
diff --git a/src/libwpactrl/wpactrl_start.c b/src/libwpactrl/wpactrl_start.c
new file mode 100644
index 0000000..86a266b
--- /dev/null
+++ b/src/libwpactrl/wpactrl_start.c
@@ -0,0 +1,45 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/webipc.h>
+#include <skalibs/unix-timed.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+int wpactrl_start (wpactrl_t *a, char const *path, tain_t const *deadline, tain_t *stamp)
+{
+  int fda, fds ;
+  fds = ipc_datagram_nbcoe() ;
+  if (fds < 0) goto err ;
+  if (!ipc_timed_connect(fds, path, deadline, stamp)) goto errs ;
+  fda = ipc_datagram_nbcoe() ;
+  if (fda < 0) goto errs ;
+  if (!ipc_timed_connect(fda, path, deadline, stamp)) goto erra ;
+  if (!ipc_timed_send(fda, "ATTACH", 6, deadline, stamp)) goto erra ;
+  {
+    ssize_t r ;
+    char answer[3] ;
+    r = wpactrl_fd_timed_recv(fda, answer, 3, deadline, stamp) ;
+    if (r != 3 || memcmp(answer, "OK\n", 3)) goto erra ;
+  }
+  a->fds = fds ;
+  a->fda = fda ;
+  return 1 ;
+
+ erra:
+  {
+    int e = errno ;
+    fd_close(fda) ;
+    errno = e ;
+  }
+ errs:
+  {
+    int e = errno ;
+    fd_close(fds) ;
+    errno = e ;
+  }
+ err:
+  return 0 ;
+}
diff --git a/src/libwpactrl/wpactrl_update.c b/src/libwpactrl/wpactrl_update.c
new file mode 100644
index 0000000..edbdc6f
--- /dev/null
+++ b/src/libwpactrl/wpactrl_update.c
@@ -0,0 +1,48 @@
+/* ISC license. */
+
+#include <string.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/stralloc.h>
+#include <bcnm/wpactrl.h>
+#include "wpactrl-internal.h"
+
+static inline int filter_search (char const *s, size_t len, char const *filters, size_t filterlen)
+{
+  while (filterlen)
+  {
+    size_t flen = strlen(filters) ;
+    if (len >= flen && !strncmp(filters, s, flen)) return 1 ;
+    filters += flen+1 ;
+    filterlen -= flen+1 ;
+  }
+  return 0 ;
+}
+
+static inline int validate (char const *s, size_t len)
+{
+  if (len < 4) return 0 ;
+  if (s[0] != '<') return 0 ;
+  if (!memchr("123456789", s[1], 9)) return 0 ;
+  if (s[2] != '>') return 0 ;
+  return s[len-1] == '\n' ;
+}
+
+int wpactrl_update (wpactrl_t *a)
+{
+  unsigned int n = WPACTRL_RECV_MAX ;
+  unsigned int count = 0 ;
+  char buf[WPACTRL_PACKET_MAX] ;
+  while (n--)
+  {
+    ssize_t r = sanitize_read(wpactrl_fd_recv(a->fda, buf, WPACTRL_PACKET_MAX)) ;
+    if (r < 0) return -1 ;
+    if (!r) break ;
+    if (a->options & WPACTRL_OPTION_NOFILTER
+     || (validate(buf, r) && filter_search(buf, r, a->filters.s, a->filters.len)))
+    {
+      if (!stralloc_catb(&a->data, buf, r)) return -1 ;
+      count++ ;
+    }
+  }
+  return (int)count ;
+}
diff --git a/src/libwpactrl/wpactrl_zero.c b/src/libwpactrl/wpactrl_zero.c
new file mode 100644
index 0000000..89b4356
--- /dev/null
+++ b/src/libwpactrl/wpactrl_zero.c
@@ -0,0 +1,5 @@
+/* ISC license. */
+
+#include <bcnm/wpactrl.h>
+
+wpactrl_t const wpactrl_zero = WPACTRL_ZERO ;