diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-01 19:36:38 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-01 19:36:38 +0000 |
commit | 69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd (patch) | |
tree | 9c97923869ff4f56717d7e0ac97c8588f816c798 /src/include | |
parent | 22a1dc61ef8e4e1c98e3a088db1dbc84d424c7a7 (diff) | |
download | bcnm-69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd.tar.xz |
Flesh out libwpactrl
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/bcnm/wpactrl.h | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/src/include/bcnm/wpactrl.h b/src/include/bcnm/wpactrl.h index df5f2c1..1c5610c 100644 --- a/src/include/bcnm/wpactrl.h +++ b/src/include/bcnm/wpactrl.h @@ -5,6 +5,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <skalibs/gccattributes.h> #include <skalibs/tai.h> #include <skalibs/stralloc.h> @@ -13,23 +14,23 @@ 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 + WPA_PONG = 1, + WPA_ERROR = -1, + WPA_UNKNOWNCOMMAND = -2, + WPA_FAIL = -3, + WPA_FAILBUSY = -4, + WPA_FAILCHECKSUM = -5, + WPA_FAILINVALIDPIN = -6, + WPA_FAILCHANNELUNAVAILABLE = -7, + WPA_FAILCHANNELUNSUPPORTED = -8, + WPA_FAILINVALIDRANGE = -9, + WPA_FAILTOOLONGRESPONSE = -10, + WPA_FAILPBCOVERLAP = -11, + WPA_FAILUNKNOWNUUID = -12, + WPA_FAILNOAPSETTINGS = -13, + WPA_FAILNOIFNAMEMATCH = -14, + WPA_UNKNOWNRESPONSE = -999 } ; typedef struct wpactrl_s wpactrl_t, *wpactrl_t_ref ; @@ -38,29 +39,31 @@ struct wpactrl_s int fds ; int fda ; uint32_t options ; + tain_t tto ; size_t datahead ; stralloc data ; stralloc filters ; } ; -#define WPACTRL_ZERO { .fds = -1, .fda = -1, .options = 0, .datahead = 0, .data = STRALLOC_ZERO, .filters = STRALLOC_ZERO } +#define WPACTRL_ZERO { .fds = -1, .fda = -1, .options = 0, .tto = TAIN_ZERO, .datahead = 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 int wpactrl_start (wpactrl_t *, char const *, unsigned int, tain_t *) ; +#define wpactrl_start_g(a, path, timeout) wpactrl_start(a, path, (timeout), &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 wparesponse_t wpactrl_command (wpactrl_t *, char const *, size_t, tain_t *) ; +#define wpactrl_command_g(a, q, qlen) wpactrl_command(a, q, (qlen), &STAMP) +extern ssize_t wpactrl_query (wpactrl_t *, char const *, size_t, char *, size_t, tain_t *) ; +#define wpactrl_query_g(a, q, qlen, ans, ansmax) wpactrl_query(a, q, qlen, ans, (ansmax), &STAMP) +extern int wpactrl_querysa (wpactrl_t *, char const *, size_t, stralloc *, tain_t *) ; +#define wpactrl_querysa_g(a, q, qlen, sa) wpactrl_querysa(a, q, qlen, (sa), &STAMP) extern int wpactrl_filter_add (wpactrl_t *, char const *) ; extern void wpactrl_filter_remove (wpactrl_t *, char const *) ; +extern int wpactrl_filter_match (wpactrl_t const *, char const *, size_t) ; #define wpactrl_filter_activate(a) ((a)->options &= ~(uint32_t)WPACTRL_OPTION_NOFILTER) #define wpactrl_filter_deactivate(a) ((a)->options |= WPACTRL_OPTION_NOFILTER) @@ -70,7 +73,7 @@ extern char *wpactrl_msg (wpactrl_t *) gccattr_pure ; extern void wpactrl_ackmsg (wpactrl_t *) ; - /* High-level functions */ + /* Helper functions for parsing answers from wpa_supplicant */ typedef struct wpactrl_scanres_s wpactrl_scanres_t, *wpactrl_scanres_t_ref ; struct wpactrl_scanres_s @@ -78,13 +81,53 @@ struct wpactrl_scanres_s char bssid[6] ; uint16_t frequency ; uint16_t signal_level ; - uint32_t flags ; - size_t ssid ; + size_t flags_start ; + size_t flags_len ; + size_t ssid_start ; + size_t ssid_len ; } ; -#define WPACTRL_SCANRES_ZERO { .bssid = "\0\0\0\0\0", .frequency = 0, .signal_level = 0, .flags = 0, .ssid = 0 } +#define WPACTRL_SCANRES_ZERO { .bssid = "\0\0\0\0\0", .frequency = 0, .signal_level = 0, .flags_start = 0, .flags_len = 0, .ssid_start = 0, .ssid_len = 0 } extern int wpactrl_scan_parse (char const *, size_t, genalloc * /* wpactrl_scanres_t */, stralloc *) ; +extern unsigned int wpactrl_env_parse (char *, size_t) ; + + + /* Higher-level functions for easy iopause */ + +typedef int wpactrl_xchg_func_t (wpactrl_t *, char const *, size_t, void *, tain_t *) ; +typedef wpactrl_xchg_func_t *wpactrl_xchg_func_t_ref ; + +typedef struct wpactrl_xchgitem_s wpactrl_xchgitem_t, *wpactrl_xchgitem_t_ref ; +struct wpactrl_xchgitem_s +{ + char const *filter ; + wpactrl_xchg_func_t_ref f ; +} ; + +typedef struct wpactrl_xchg_s wpactrl_xchg_t, *wpactrl_xchg_t_ref ; +struct wpactrl_xchg_s +{ + stralloc sa ; + wpactrl_xchgitem_t const *tab ; + unsigned int n ; + unsigned int i ; + tain_t deadline ; + int status ; + void *aux ; +} ; +#define WPACTRL_XCHG_ZERO { .sa = STRALLOC_ZERO, .tab = 0, .n = 0, .i = 0, .deadline = TAIN_ZERO, .status = ECONNABORTED, .aux = 0 } +#define WPACTRL_XCHG_INIT(array, size, limit, extra) { .sa = STRALLOC_ZERO, .tab = array, .n = size, .i = 0, .deadline = limit, .status = ECONNABORTED, .aux = extra } + +extern wpactrl_xchg_t const wpactrl_xchg_zero ; +extern void wpactrl_xchg_free (wpactrl_xchg_t *) ; +extern int wpactrl_xchg_init (wpactrl_xchg_t *, wpactrl_xchgitem_t const *, unsigned int, tain_t const *, void *) ; +extern int wpactrl_xchg_start (wpactrl_t *, wpactrl_xchg_t *) ; +extern void wpactrl_xchg_computedeadline (wpactrl_xchg_t const *, tain_t *) ; +extern int wpactrl_xchg_timeout (wpactrl_xchg_t *, tain_t const *) ; +#define wpactrl_xchg_timeout_g(dt) wpactrl_xchg_timeout((dt), &STAMP) +extern int wpactrl_xchg_event (wpactrl_t *, wpactrl_xchg_t *, tain_t *) ; +#define wpactrl_xchg_event_g(a, dt) wpactrl_xchg_event(a, (dt), &STAMP) /* |