2010-11-06 15:20:45 +01:00
|
|
|
/*
|
|
|
|
* wlantest - IEEE 802.11 protocol monitoring and testing tool
|
2019-12-27 22:15:14 +01:00
|
|
|
* Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
|
2010-11-06 15:20:45 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2010-11-06 15:20:45 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/includes.h"
|
|
|
|
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "wlantest.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void wlantest_terminate(int sig, void *signal_ctx)
|
|
|
|
{
|
|
|
|
eloop_terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2019-12-27 22:15:14 +01:00
|
|
|
printf("wlantest [-cddehqqFNt] [-i<ifname>] [-r<pcap file>] "
|
2010-11-07 16:59:50 +01:00
|
|
|
"[-p<passphrase>]\n"
|
2013-05-26 18:39:48 +02:00
|
|
|
" [-I<wired ifname>] [-R<wired pcap file>] "
|
2010-11-12 00:00:31 +01:00
|
|
|
"[-P<RADIUS shared secret>]\n"
|
2013-05-26 18:39:48 +02:00
|
|
|
" [-n<write pcapng file>]\n"
|
2013-11-17 20:16:29 +01:00
|
|
|
" [-w<write pcap file>] [-f<MSK/PMK file>]\n"
|
2021-11-03 17:50:24 +01:00
|
|
|
" [-L<log file>] [-T<PTK file>] [-W<WEP key>]\n");
|
2010-11-06 21:57:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void passphrase_deinit(struct wlantest_passphrase *p)
|
|
|
|
{
|
|
|
|
dl_list_del(&p->list);
|
|
|
|
os_free(p);
|
2010-11-06 15:20:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 18:43:10 +01:00
|
|
|
static void secret_deinit(struct wlantest_radius_secret *r)
|
|
|
|
{
|
|
|
|
dl_list_del(&r->list);
|
|
|
|
os_free(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
static void wlantest_init(struct wlantest *wt)
|
|
|
|
{
|
2010-11-13 17:38:19 +01:00
|
|
|
int i;
|
2010-11-06 16:11:12 +01:00
|
|
|
os_memset(wt, 0, sizeof(*wt));
|
|
|
|
wt->monitor_sock = -1;
|
2010-11-13 17:38:19 +01:00
|
|
|
wt->ctrl_sock = -1;
|
|
|
|
for (i = 0; i < MAX_CTRL_CONNECTIONS; i++)
|
|
|
|
wt->ctrl_socks[i] = -1;
|
2010-11-06 21:57:49 +01:00
|
|
|
dl_list_init(&wt->passphrase);
|
2010-11-06 16:11:12 +01:00
|
|
|
dl_list_init(&wt->bss);
|
2010-11-07 18:43:10 +01:00
|
|
|
dl_list_init(&wt->secret);
|
|
|
|
dl_list_init(&wt->radius);
|
|
|
|
dl_list_init(&wt->pmk);
|
2013-11-17 21:52:15 +01:00
|
|
|
dl_list_init(&wt->ptk);
|
2011-01-14 16:43:17 +01:00
|
|
|
dl_list_init(&wt->wep);
|
2010-11-07 18:43:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void radius_deinit(struct wlantest_radius *r)
|
|
|
|
{
|
|
|
|
dl_list_del(&r->list);
|
|
|
|
os_free(r);
|
2010-11-06 16:11:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-17 21:52:15 +01:00
|
|
|
static void ptk_deinit(struct wlantest_ptk *ptk)
|
|
|
|
{
|
|
|
|
dl_list_del(&ptk->list);
|
|
|
|
os_free(ptk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-03 17:50:23 +01:00
|
|
|
static void wep_deinit(struct wlantest_wep *wep)
|
|
|
|
{
|
|
|
|
dl_list_del(&wep->list);
|
|
|
|
os_free(wep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
static void wlantest_deinit(struct wlantest *wt)
|
|
|
|
{
|
2010-11-06 21:57:49 +01:00
|
|
|
struct wlantest_passphrase *p, *pn;
|
2010-11-07 18:43:10 +01:00
|
|
|
struct wlantest_radius_secret *s, *sn;
|
|
|
|
struct wlantest_radius *r, *rn;
|
|
|
|
struct wlantest_pmk *pmk, *np;
|
2013-11-17 21:52:15 +01:00
|
|
|
struct wlantest_ptk *ptk, *npt;
|
2011-01-14 16:43:17 +01:00
|
|
|
struct wlantest_wep *wep, *nw;
|
2010-11-07 18:43:10 +01:00
|
|
|
|
2010-11-13 17:38:19 +01:00
|
|
|
if (wt->ctrl_sock >= 0)
|
|
|
|
ctrl_deinit(wt);
|
2010-11-06 16:11:12 +01:00
|
|
|
if (wt->monitor_sock >= 0)
|
|
|
|
monitor_deinit(wt);
|
2010-11-18 16:36:08 +01:00
|
|
|
bss_flush(wt);
|
2010-11-06 21:57:49 +01:00
|
|
|
dl_list_for_each_safe(p, pn, &wt->passphrase,
|
|
|
|
struct wlantest_passphrase, list)
|
|
|
|
passphrase_deinit(p);
|
2010-11-07 18:43:10 +01:00
|
|
|
dl_list_for_each_safe(s, sn, &wt->secret,
|
|
|
|
struct wlantest_radius_secret, list)
|
|
|
|
secret_deinit(s);
|
|
|
|
dl_list_for_each_safe(r, rn, &wt->radius, struct wlantest_radius, list)
|
|
|
|
radius_deinit(r);
|
|
|
|
dl_list_for_each_safe(pmk, np, &wt->pmk, struct wlantest_pmk, list)
|
|
|
|
pmk_deinit(pmk);
|
2013-11-17 21:52:15 +01:00
|
|
|
dl_list_for_each_safe(ptk, npt, &wt->ptk, struct wlantest_ptk, list)
|
|
|
|
ptk_deinit(ptk);
|
2011-01-14 16:43:17 +01:00
|
|
|
dl_list_for_each_safe(wep, nw, &wt->wep, struct wlantest_wep, list)
|
2021-11-03 17:50:23 +01:00
|
|
|
wep_deinit(wep);
|
2010-11-12 00:00:31 +01:00
|
|
|
write_pcap_deinit(wt);
|
2013-05-26 18:39:48 +02:00
|
|
|
write_pcapng_deinit(wt);
|
|
|
|
clear_notes(wt);
|
|
|
|
os_free(wt->decrypted);
|
|
|
|
wt->decrypted = NULL;
|
2021-02-08 17:38:39 +01:00
|
|
|
wpabuf_free(wt->tkip_frag.buf);
|
|
|
|
wt->tkip_frag.buf = NULL;
|
2010-11-06 21:57:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_passphrase(struct wlantest *wt, const char *passphrase)
|
|
|
|
{
|
|
|
|
struct wlantest_passphrase *p;
|
|
|
|
size_t len = os_strlen(passphrase);
|
|
|
|
|
|
|
|
if (len < 8 || len > 63)
|
|
|
|
return;
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
os_memcpy(p->passphrase, passphrase, len);
|
|
|
|
dl_list_add(&wt->passphrase, &p->list);
|
2010-11-06 16:11:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 18:43:10 +01:00
|
|
|
static void add_secret(struct wlantest *wt, const char *secret)
|
|
|
|
{
|
|
|
|
struct wlantest_radius_secret *s;
|
|
|
|
size_t len = os_strlen(secret);
|
|
|
|
|
|
|
|
if (len >= MAX_RADIUS_SECRET_LEN)
|
|
|
|
return;
|
|
|
|
s = os_zalloc(sizeof(*s));
|
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
os_memcpy(s->secret, secret, len);
|
|
|
|
dl_list_add(&wt->secret, &s->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-08 23:12:27 +01:00
|
|
|
static int add_pmk_file(struct wlantest *wt, const char *pmk_file)
|
|
|
|
{
|
|
|
|
FILE *f;
|
2017-09-05 18:01:14 +02:00
|
|
|
u8 pmk[PMK_LEN_MAX];
|
|
|
|
size_t pmk_len;
|
2011-12-08 23:12:27 +01:00
|
|
|
char buf[300], *pos;
|
|
|
|
struct wlantest_pmk *p;
|
|
|
|
|
|
|
|
f = fopen(pmk_file, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "Could not open '%s'", pmk_file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
|
|
|
pos = buf;
|
|
|
|
while (*pos && *pos != '\r' && *pos != '\n')
|
|
|
|
pos++;
|
|
|
|
*pos = '\0';
|
|
|
|
if (pos - buf < 2 * 32)
|
|
|
|
continue;
|
2017-09-05 18:01:14 +02:00
|
|
|
pmk_len = (pos - buf) / 2;
|
|
|
|
if (pmk_len > PMK_LEN_MAX)
|
|
|
|
pmk_len = PMK_LEN_MAX;
|
|
|
|
if (hexstr2bin(buf, pmk, pmk_len) < 0)
|
2011-12-08 23:12:27 +01:00
|
|
|
continue;
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
2017-09-05 18:01:14 +02:00
|
|
|
os_memcpy(p->pmk, pmk, pmk_len);
|
|
|
|
p->pmk_len = pmk_len;
|
2011-12-08 23:12:27 +01:00
|
|
|
dl_list_add(&wt->pmk, &p->list);
|
2017-09-05 18:01:14 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "Added PMK from file", pmk, pmk_len);
|
2017-03-24 19:54:47 +01:00
|
|
|
|
|
|
|
/* For FT, the send half of MSK is used */
|
2017-09-05 18:01:14 +02:00
|
|
|
if (hexstr2bin(&buf[2 * PMK_LEN], pmk, PMK_LEN) < 0)
|
2017-03-24 19:54:47 +01:00
|
|
|
continue;
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
2017-09-05 18:01:14 +02:00
|
|
|
os_memcpy(p->pmk, pmk, PMK_LEN);
|
|
|
|
p->pmk_len = PMK_LEN;
|
2017-03-24 19:54:47 +01:00
|
|
|
dl_list_add(&wt->pmk, &p->list);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "Added PMK from file (2nd half of MSK)",
|
2017-09-05 18:01:14 +02:00
|
|
|
pmk, PMK_LEN);
|
2011-12-08 23:12:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-17 21:52:15 +01:00
|
|
|
static int add_ptk_file(struct wlantest *wt, const char *ptk_file)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
u8 ptk[64];
|
|
|
|
size_t ptk_len;
|
|
|
|
char buf[300], *pos;
|
|
|
|
struct wlantest_ptk *p;
|
|
|
|
|
|
|
|
f = fopen(ptk_file, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "Could not open '%s'", ptk_file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
|
|
|
pos = buf;
|
|
|
|
while (*pos && *pos != '\r' && *pos != '\n')
|
|
|
|
pos++;
|
|
|
|
*pos = '\0';
|
|
|
|
ptk_len = pos - buf;
|
|
|
|
if (ptk_len & 1)
|
|
|
|
continue;
|
|
|
|
ptk_len /= 2;
|
|
|
|
if (ptk_len != 16 && ptk_len != 32 &&
|
|
|
|
ptk_len != 48 && ptk_len != 64)
|
|
|
|
continue;
|
|
|
|
if (hexstr2bin(buf, ptk, ptk_len) < 0)
|
|
|
|
continue;
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
|
|
|
if (ptk_len < 48) {
|
2015-01-25 15:49:18 +01:00
|
|
|
os_memcpy(p->ptk.tk, ptk, ptk_len);
|
|
|
|
p->ptk.tk_len = ptk_len;
|
2013-11-17 21:52:15 +01:00
|
|
|
p->ptk_len = 32 + ptk_len;
|
|
|
|
} else {
|
2015-01-25 15:49:18 +01:00
|
|
|
os_memcpy(p->ptk.kck, ptk, 16);
|
|
|
|
p->ptk.kck_len = 16;
|
|
|
|
os_memcpy(p->ptk.kek, ptk + 16, 16);
|
|
|
|
p->ptk.kek_len = 16;
|
|
|
|
os_memcpy(p->ptk.tk, ptk + 32, ptk_len - 32);
|
|
|
|
p->ptk.tk_len = ptk_len - 32;
|
2013-11-17 21:52:15 +01:00
|
|
|
p->ptk_len = ptk_len;
|
|
|
|
}
|
|
|
|
dl_list_add(&wt->ptk, &p->list);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "Added PTK from file", ptk, ptk_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-28 12:33:21 +01:00
|
|
|
int add_wep(struct wlantest *wt, const char *key)
|
2011-01-14 16:43:17 +01:00
|
|
|
{
|
|
|
|
struct wlantest_wep *w;
|
|
|
|
size_t len = os_strlen(key);
|
|
|
|
|
|
|
|
if (len != 2 * 5 && len != 2 * 13) {
|
|
|
|
wpa_printf(MSG_INFO, "Invalid WEP key '%s'", key);
|
2011-01-28 12:33:21 +01:00
|
|
|
return -1;
|
2011-01-14 16:43:17 +01:00
|
|
|
}
|
|
|
|
w = os_zalloc(sizeof(*w));
|
|
|
|
if (w == NULL)
|
2011-01-28 12:33:21 +01:00
|
|
|
return -1;
|
2011-01-14 16:43:17 +01:00
|
|
|
if (hexstr2bin(key, w->key, len / 2) < 0) {
|
|
|
|
os_free(w);
|
|
|
|
wpa_printf(MSG_INFO, "Invalid WEP key '%s'", key);
|
2011-01-28 12:33:21 +01:00
|
|
|
return -1;
|
2011-01-14 16:43:17 +01:00
|
|
|
}
|
|
|
|
w->key_len = len / 2;
|
|
|
|
dl_list_add(&wt->wep, &w->list);
|
2011-01-28 12:33:21 +01:00
|
|
|
return 0;
|
2011-01-14 16:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-26 18:39:48 +02:00
|
|
|
void add_note(struct wlantest *wt, int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
size_t len = 1000;
|
|
|
|
int wlen;
|
|
|
|
|
|
|
|
if (wt->num_notes == MAX_NOTES)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wt->notes[wt->num_notes] = os_malloc(len);
|
|
|
|
if (wt->notes[wt->num_notes] == NULL)
|
|
|
|
return;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
wlen = vsnprintf(wt->notes[wt->num_notes], len, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
if (wlen < 0) {
|
|
|
|
os_free(wt->notes[wt->num_notes]);
|
|
|
|
wt->notes[wt->num_notes] = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (wlen >= len)
|
|
|
|
wt->notes[wt->num_notes][len - 1] = '\0';
|
|
|
|
wpa_printf(level, "%s", wt->notes[wt->num_notes]);
|
|
|
|
wt->num_notes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void clear_notes(struct wlantest *wt)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < wt->num_notes; i++) {
|
|
|
|
os_free(wt->notes[i]);
|
|
|
|
wt->notes[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wt->num_notes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t notes_len(struct wlantest *wt, size_t hdrlen)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t len = wt->num_notes * hdrlen;
|
|
|
|
|
|
|
|
for (i = 0; i < wt->num_notes; i++)
|
|
|
|
len += os_strlen(wt->notes[i]);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-07 10:37:58 +01:00
|
|
|
void write_decrypted_note(struct wlantest *wt, const u8 *decrypted,
|
|
|
|
const u8 *tk, size_t tk_len, int keyid)
|
|
|
|
{
|
|
|
|
char tk_hex[65];
|
|
|
|
|
|
|
|
if (!decrypted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wpa_snprintf_hex(tk_hex, sizeof(tk_hex), tk, tk_len);
|
|
|
|
add_note(wt, MSG_EXCESSIVE, "TK[%d] %s", keyid, tk_hex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-17 20:11:35 +01:00
|
|
|
int wlantest_relog(struct wlantest *wt)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "Re-open log/capture files");
|
2013-11-17 20:16:29 +01:00
|
|
|
if (wpa_debug_reopen_file())
|
|
|
|
ret = -1;
|
2013-11-17 20:11:35 +01:00
|
|
|
|
|
|
|
if (wt->write_file) {
|
|
|
|
write_pcap_deinit(wt);
|
|
|
|
if (write_pcap_init(wt, wt->write_file) < 0)
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wt->pcapng_file) {
|
|
|
|
write_pcapng_deinit(wt);
|
|
|
|
if (write_pcapng_init(wt, wt->pcapng_file) < 0)
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-11-03 17:50:20 +01:00
|
|
|
int c, ret = 0;
|
2023-08-08 10:00:42 +02:00
|
|
|
const unsigned int MAX_READ_FILE = 20;
|
|
|
|
const char *read_file[MAX_READ_FILE];
|
|
|
|
unsigned int rf, num_read_file = 0;
|
2010-11-07 16:59:50 +01:00
|
|
|
const char *read_wired_file = NULL;
|
2010-11-06 15:20:45 +01:00
|
|
|
const char *ifname = NULL;
|
2010-11-07 16:59:50 +01:00
|
|
|
const char *ifname_wired = NULL;
|
2013-11-17 20:16:29 +01:00
|
|
|
const char *logfile = NULL;
|
2010-11-06 15:20:45 +01:00
|
|
|
struct wlantest wt;
|
2010-11-13 17:38:19 +01:00
|
|
|
int ctrl_iface = 0;
|
2021-11-03 17:50:20 +01:00
|
|
|
bool eloop_init_done = false;
|
2010-11-06 15:20:45 +01:00
|
|
|
|
|
|
|
wpa_debug_level = MSG_INFO;
|
2010-11-06 21:57:49 +01:00
|
|
|
wpa_debug_show_keys = 1;
|
2010-11-06 15:20:45 +01:00
|
|
|
|
|
|
|
if (os_program_init())
|
|
|
|
return -1;
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
wlantest_init(&wt);
|
2010-11-06 15:20:45 +01:00
|
|
|
|
|
|
|
for (;;) {
|
2019-12-27 22:15:14 +01:00
|
|
|
c = getopt(argc, argv, "cdef:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
|
2010-11-06 15:20:45 +01:00
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
switch (c) {
|
2010-11-13 17:38:19 +01:00
|
|
|
case 'c':
|
|
|
|
ctrl_iface = 1;
|
|
|
|
break;
|
2010-11-06 15:20:45 +01:00
|
|
|
case 'd':
|
|
|
|
if (wpa_debug_level > 0)
|
|
|
|
wpa_debug_level--;
|
|
|
|
break;
|
2019-12-27 22:15:14 +01:00
|
|
|
case 'e':
|
|
|
|
wt.ethernet = 1;
|
|
|
|
break;
|
2011-12-08 23:12:27 +01:00
|
|
|
case 'f':
|
2021-11-03 17:50:20 +01:00
|
|
|
if (add_pmk_file(&wt, optarg) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
2011-12-08 23:12:27 +01:00
|
|
|
break;
|
2013-01-17 11:55:30 +01:00
|
|
|
case 'F':
|
|
|
|
wt.assume_fcs = 1;
|
|
|
|
break;
|
2010-11-06 15:20:45 +01:00
|
|
|
case 'h':
|
|
|
|
usage();
|
2021-11-03 17:50:20 +01:00
|
|
|
ret = 0;
|
|
|
|
goto deinit;
|
2010-11-06 15:20:45 +01:00
|
|
|
case 'i':
|
|
|
|
ifname = optarg;
|
|
|
|
break;
|
2010-11-07 16:59:50 +01:00
|
|
|
case 'I':
|
|
|
|
ifname_wired = optarg;
|
|
|
|
break;
|
2013-11-17 20:16:29 +01:00
|
|
|
case 'L':
|
|
|
|
logfile = optarg;
|
|
|
|
break;
|
2013-05-26 18:39:48 +02:00
|
|
|
case 'n':
|
2013-11-17 20:11:35 +01:00
|
|
|
wt.pcapng_file = optarg;
|
2013-05-26 18:39:48 +02:00
|
|
|
break;
|
2015-11-26 23:10:53 +01:00
|
|
|
case 'N':
|
|
|
|
wt.pcap_no_buffer = 1;
|
|
|
|
break;
|
2010-11-06 21:57:49 +01:00
|
|
|
case 'p':
|
|
|
|
add_passphrase(&wt, optarg);
|
|
|
|
break;
|
2010-11-07 18:43:10 +01:00
|
|
|
case 'P':
|
|
|
|
add_secret(&wt, optarg);
|
|
|
|
break;
|
2010-11-06 15:20:45 +01:00
|
|
|
case 'q':
|
|
|
|
wpa_debug_level++;
|
|
|
|
break;
|
|
|
|
case 'r':
|
2023-08-08 10:00:42 +02:00
|
|
|
if (num_read_file == MAX_READ_FILE) {
|
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"Too many read files (-r) - ignored %s",
|
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
read_file[num_read_file++] = optarg;
|
2010-11-06 15:20:45 +01:00
|
|
|
break;
|
2010-11-07 16:59:50 +01:00
|
|
|
case 'R':
|
|
|
|
read_wired_file = optarg;
|
|
|
|
break;
|
2013-11-17 20:44:53 +01:00
|
|
|
case 't':
|
|
|
|
wpa_debug_timestamp = 1;
|
|
|
|
break;
|
2013-11-17 21:52:15 +01:00
|
|
|
case 'T':
|
2021-11-03 17:50:20 +01:00
|
|
|
if (add_ptk_file(&wt, optarg) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
2013-11-17 21:52:15 +01:00
|
|
|
break;
|
2010-11-12 00:00:31 +01:00
|
|
|
case 'w':
|
2013-11-17 20:11:35 +01:00
|
|
|
wt.write_file = optarg;
|
2010-11-12 00:00:31 +01:00
|
|
|
break;
|
2011-01-14 16:43:17 +01:00
|
|
|
case 'W':
|
2021-11-03 17:50:20 +01:00
|
|
|
if (add_wep(&wt, optarg) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
2011-01-14 16:43:17 +01:00
|
|
|
break;
|
2010-11-06 15:20:45 +01:00
|
|
|
default:
|
|
|
|
usage();
|
2021-11-03 17:50:20 +01:00
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
2010-11-06 15:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 16:59:50 +01:00
|
|
|
if (ifname == NULL && ifname_wired == NULL &&
|
2023-08-08 10:00:42 +02:00
|
|
|
num_read_file == 0 && read_wired_file == NULL) {
|
2010-11-06 15:20:45 +01:00
|
|
|
usage();
|
2021-11-03 17:50:20 +01:00
|
|
|
ret = 0;
|
|
|
|
goto deinit;
|
2010-11-06 15:20:45 +01:00
|
|
|
}
|
|
|
|
|
2021-11-03 17:50:20 +01:00
|
|
|
if (eloop_init()) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
|
|
|
eloop_init_done = true;
|
2010-11-06 15:20:45 +01:00
|
|
|
|
2013-11-17 20:16:29 +01:00
|
|
|
if (logfile)
|
|
|
|
wpa_debug_open_file(logfile);
|
|
|
|
|
2021-11-03 17:50:20 +01:00
|
|
|
if ((wt.write_file && write_pcap_init(&wt, wt.write_file) < 0) ||
|
|
|
|
(wt.pcapng_file && write_pcapng_init(&wt, wt.pcapng_file) < 0) ||
|
|
|
|
(read_wired_file &&
|
2023-08-08 10:00:42 +02:00
|
|
|
read_wired_cap_file(&wt, read_wired_file) < 0))
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (rf = 0; rf < num_read_file; rf++) {
|
|
|
|
if (read_cap_file(&wt, read_file[rf]) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ifname && monitor_init(&wt, ifname) < 0) ||
|
2021-11-03 17:50:20 +01:00
|
|
|
(ifname_wired && monitor_init_wired(&wt, ifname_wired) < 0) ||
|
|
|
|
(ctrl_iface && ctrl_init(&wt) < 0)) {
|
|
|
|
ret = -1;
|
|
|
|
goto deinit;
|
|
|
|
}
|
2010-11-13 17:38:19 +01:00
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
eloop_register_signal_terminate(wlantest_terminate, &wt);
|
|
|
|
|
|
|
|
eloop_run();
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "Processed: rx_mgmt=%u rx_ctrl=%u rx_data=%u "
|
|
|
|
"fcs_error=%u",
|
|
|
|
wt.rx_mgmt, wt.rx_ctrl, wt.rx_data, wt.fcs_error);
|
|
|
|
|
2021-11-03 17:50:20 +01:00
|
|
|
deinit:
|
2010-11-06 16:11:12 +01:00
|
|
|
wlantest_deinit(&wt);
|
2010-11-06 15:20:45 +01:00
|
|
|
|
2013-11-17 20:16:29 +01:00
|
|
|
wpa_debug_close_file();
|
2021-11-03 17:50:20 +01:00
|
|
|
if (eloop_init_done)
|
|
|
|
eloop_destroy();
|
2010-11-06 15:20:45 +01:00
|
|
|
os_program_deinit();
|
|
|
|
|
2021-11-03 17:50:20 +01:00
|
|
|
return ret;
|
2010-11-06 15:20:45 +01:00
|
|
|
}
|