summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_command.c
blob: c29a58ad0ab38d526a511d14d86b88467f95a1b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 ;
  }
}