wlantest: Add command for fetching wlantest version
This commit is contained in:
parent
990153b4dd
commit
a16c859034
3 changed files with 63 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "utils/common.h"
|
||||
#include "utils/eloop.h"
|
||||
#include "common/version.h"
|
||||
#include "common/ieee802_11_defs.h"
|
||||
#include "wlantest.h"
|
||||
#include "wlantest_ctrl.h"
|
||||
|
@ -73,6 +74,23 @@ static int attr_get_int(u8 *buf, size_t buflen, enum wlantest_ctrl_attr attr)
|
|||
}
|
||||
|
||||
|
||||
static u8 * attr_add_str(u8 *pos, u8 *end, enum wlantest_ctrl_attr attr,
|
||||
const char *str)
|
||||
{
|
||||
size_t len = os_strlen(str);
|
||||
|
||||
if (pos == NULL || end - pos < 8 + len)
|
||||
return NULL;
|
||||
WPA_PUT_BE32(pos, attr);
|
||||
pos += 4;
|
||||
WPA_PUT_BE32(pos, len);
|
||||
pos += 4;
|
||||
os_memcpy(pos, str, len);
|
||||
pos += len;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
static u8 * attr_add_be32(u8 *pos, u8 *end, enum wlantest_ctrl_attr attr,
|
||||
u32 val)
|
||||
{
|
||||
|
@ -655,6 +673,19 @@ static void ctrl_inject(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
|
|||
}
|
||||
|
||||
|
||||
static void ctrl_version(struct wlantest *wt, int sock)
|
||||
{
|
||||
u8 buf[WLANTEST_CTRL_MAX_RESP_LEN], *pos;
|
||||
|
||||
pos = buf;
|
||||
WPA_PUT_BE32(pos, WLANTEST_CTRL_SUCCESS);
|
||||
pos += 4;
|
||||
pos = attr_add_str(pos, buf + sizeof(buf), WLANTEST_ATTR_VERSION,
|
||||
VERSION_STR);
|
||||
ctrl_send(wt, sock, buf, pos - buf);
|
||||
}
|
||||
|
||||
|
||||
static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
|
||||
{
|
||||
struct wlantest *wt = eloop_ctx;
|
||||
|
@ -717,6 +748,9 @@ static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
|
|||
case WLANTEST_CTRL_INJECT:
|
||||
ctrl_inject(wt, sock, buf + 4, len - 4);
|
||||
break;
|
||||
case WLANTEST_CTRL_VERSION:
|
||||
ctrl_version(wt, sock);
|
||||
break;
|
||||
default:
|
||||
ctrl_send_simple(wt, sock, WLANTEST_CTRL_UNKNOWN_CMD);
|
||||
break;
|
||||
|
|
|
@ -530,6 +530,32 @@ static int cmd_inject(int s, int argc, char *argv[])
|
|||
}
|
||||
|
||||
|
||||
static int cmd_version(int s, int argc, char *argv[])
|
||||
{
|
||||
u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
|
||||
u8 buf[4];
|
||||
char *version;
|
||||
size_t len;
|
||||
int rlen, i;
|
||||
|
||||
WPA_PUT_BE32(buf, WLANTEST_CTRL_VERSION);
|
||||
rlen = cmd_send_and_recv(s, buf, sizeof(buf), resp, sizeof(resp));
|
||||
if (rlen < 0)
|
||||
return -1;
|
||||
|
||||
version = (char *) attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_VERSION,
|
||||
&len);
|
||||
if (version == NULL)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
putchar(version[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct wlantest_cli_cmd {
|
||||
const char *cmd;
|
||||
int (*handler)(int s, int argc, char *argv[]);
|
||||
|
@ -552,6 +578,7 @@ static const struct wlantest_cli_cmd wlantest_cli_commands[] = {
|
|||
"<counter> <BSSID> = get BSS counter value" },
|
||||
{ "inject", cmd_inject,
|
||||
"<frame> <prot> <sender> <BSSID> <STA/ff:ff:ff:ff:ff:ff>" },
|
||||
{ "version", cmd_version, "= get wlantest version" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ enum wlantest_ctrl_cmd {
|
|||
WLANTEST_CTRL_GET_STA_COUNTER,
|
||||
WLANTEST_CTRL_GET_BSS_COUNTER,
|
||||
WLANTEST_CTRL_INJECT,
|
||||
WLANTEST_CTRL_VERSION,
|
||||
};
|
||||
|
||||
enum wlantest_ctrl_attr {
|
||||
|
@ -45,6 +46,7 @@ enum wlantest_ctrl_attr {
|
|||
WLANTEST_ATTR_INJECT_FRAME,
|
||||
WLANTEST_ATTR_INJECT_SENDER_AP,
|
||||
WLANTEST_ATTR_INJECT_PROTECTION,
|
||||
WLANTEST_ATTR_VERSION,
|
||||
};
|
||||
|
||||
enum wlantest_bss_counter {
|
||||
|
|
Loading…
Reference in a new issue