2010-11-06 15:20:45 +01:00
|
|
|
/*
|
|
|
|
* wlantest - IEEE 802.11 protocol monitoring and testing tool
|
|
|
|
* Copyright (c) 2010, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* See README and COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/includes.h"
|
|
|
|
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "wlantest.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern int wpa_debug_level;
|
2010-11-06 21:57:49 +01:00
|
|
|
extern int wpa_debug_show_keys;
|
2010-11-06 15:20:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void wlantest_terminate(int sig, void *signal_ctx)
|
|
|
|
{
|
|
|
|
eloop_terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2010-11-13 17:38:19 +01:00
|
|
|
printf("wlantest [-cddhqq] [-i<ifname>] [-r<pcap file>] "
|
2010-11-07 16:59:50 +01:00
|
|
|
"[-p<passphrase>]\n"
|
2010-11-07 18:43:10 +01:00
|
|
|
" [-I<wired ifname>] [-R<wired pcap file>] "
|
2010-11-12 00:00:31 +01:00
|
|
|
"[-P<RADIUS shared secret>]\n"
|
|
|
|
" [-w<write pcap file>]\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);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
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);
|
2011-01-14 16:43:17 +01:00
|
|
|
dl_list_for_each_safe(wep, nw, &wt->wep, struct wlantest_wep, list)
|
|
|
|
os_free(wep);
|
2010-11-12 00:00:31 +01:00
|
|
|
write_pcap_deinit(wt);
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
const char *read_file = NULL;
|
2010-11-07 16:59:50 +01:00
|
|
|
const char *read_wired_file = NULL;
|
2010-11-12 00:00:31 +01:00
|
|
|
const char *write_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;
|
2010-11-06 15:20:45 +01:00
|
|
|
struct wlantest wt;
|
2010-11-13 17:38:19 +01:00
|
|
|
int ctrl_iface = 0;
|
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 (;;) {
|
2011-01-14 16:43:17 +01:00
|
|
|
c = getopt(argc, argv, "cdhi:I:p:P:qr:R: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;
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
case 'i':
|
|
|
|
ifname = optarg;
|
|
|
|
break;
|
2010-11-07 16:59:50 +01:00
|
|
|
case 'I':
|
|
|
|
ifname_wired = optarg;
|
|
|
|
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':
|
|
|
|
read_file = optarg;
|
|
|
|
break;
|
2010-11-07 16:59:50 +01:00
|
|
|
case 'R':
|
|
|
|
read_wired_file = optarg;
|
|
|
|
break;
|
2010-11-12 00:00:31 +01:00
|
|
|
case 'w':
|
|
|
|
write_file = optarg;
|
|
|
|
break;
|
2011-01-14 16:43:17 +01:00
|
|
|
case 'W':
|
2011-01-28 12:33:21 +01:00
|
|
|
if (add_wep(&wt, optarg) < 0)
|
|
|
|
return -1;
|
2011-01-14 16:43:17 +01:00
|
|
|
break;
|
2010-11-06 15:20:45 +01:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 16:59:50 +01:00
|
|
|
if (ifname == NULL && ifname_wired == NULL &&
|
|
|
|
read_file == NULL && read_wired_file == NULL) {
|
2010-11-06 15:20:45 +01:00
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eloop_init())
|
|
|
|
return -1;
|
|
|
|
|
2010-11-12 00:00:31 +01:00
|
|
|
if (write_file && write_pcap_init(&wt, write_file) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-11-07 16:59:50 +01:00
|
|
|
if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
if (read_file && read_cap_file(&wt, read_file) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ifname && monitor_init(&wt, ifname) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-11-07 16:59:50 +01:00
|
|
|
if (ifname_wired && monitor_init_wired(&wt, ifname_wired) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-11-13 17:38:19 +01:00
|
|
|
if (ctrl_iface && ctrl_init(&wt) < 0)
|
|
|
|
return -1;
|
|
|
|
|
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);
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
wlantest_deinit(&wt);
|
2010-11-06 15:20:45 +01:00
|
|
|
|
|
|
|
eloop_destroy();
|
|
|
|
os_program_deinit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|