about summary refs log tree commit diff
path: root/src/libwpactrl/wpactrl_associate.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-08-04 22:46:45 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-08-04 22:46:45 +0000
commitbabf43abf301d072192bda1f72a47440c354b072 (patch)
treed917d33ebb97d2b783e163f299b360be4f5b3a0a /src/libwpactrl/wpactrl_associate.c
parent69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd (diff)
downloadbcnm-babf43abf301d072192bda1f72a47440c354b072.tar.gz
bcnm-babf43abf301d072192bda1f72a47440c354b072.tar.xz
bcnm-babf43abf301d072192bda1f72a47440c354b072.zip
Add the higher layer of libwpactrl
Diffstat (limited to 'src/libwpactrl/wpactrl_associate.c')
-rw-r--r--src/libwpactrl/wpactrl_associate.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libwpactrl/wpactrl_associate.c b/src/libwpactrl/wpactrl_associate.c
new file mode 100644
index 0000000..59900d6
--- /dev/null
+++ b/src/libwpactrl/wpactrl_associate.c
@@ -0,0 +1,34 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <errno.h>
+#include <bcnm/wpactrl.h>
+
+int wpactrl_associate (wpactrl_t *a, char const *ssid, char const *psk, tain_t *stamp)
+{
+  uint32_t id ;
+  int r = wpactrl_findnetwork(a, ssid, &id, stamp) ;
+  if (r < 0) return 0 ;
+  if (!r)
+  {
+    if (!wpactrl_addnetwork(a, &id, stamp)) goto err ;
+  }
+
+  if (psk)
+  {
+    if (wpactrl_setnetworkoption(a, id, "key_mgmt", "WPA-PSK WPA-PSK-SHA256", stamp) != WPA_OK
+     || wpactrl_setnetworkoption(a, id, "mem_only_psk", "1", stamp) != WPA_OK
+     || wpactrl_setnetworkoption(a, id, "psk", psk, stamp) != WPA_OK) goto err ;
+  }
+  else
+  {
+    if (wpactrl_setnetworkoption(a, id, "key_mgmt", "NONE", stamp) != WPA_OK)
+      goto err ;
+  }
+
+  if (wpactrl_selectnetwork(a, id, stamp) != WPA_OK) goto err ;
+  return 1 ;
+
+ err:
+  return (errno = EIO, 0) ;
+}