summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_command.c
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/libwpactrl/wpactrl_command.c
downloadbcnm-330f54ac7f780872223f9cac62347393ffb4ef86.tar.xz
Initial commit
Diffstat (limited to 'src/libwpactrl/wpactrl_command.c')
-rw-r--r--src/libwpactrl/wpactrl_command.c41
1 files changed, 41 insertions, 0 deletions
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 ;
+ }
+}