wlantest: Add command for adding WEP keys during run time

This commit is contained in:
Jouni Malinen 2011-01-28 13:33:21 +02:00 committed by Jouni Malinen
parent dfaeda0492
commit 9a994178f1
4 changed files with 35 additions and 6 deletions

View file

@ -788,7 +788,32 @@ static void ctrl_add_passphrase(struct wlantest *wt, int sock, u8 *cmd,
u8 *bssid;
passphrase = attr_get(cmd, clen, WLANTEST_ATTR_PASSPHRASE, &len);
if (passphrase == NULL || len < 8 || len > 63) {
if (passphrase == NULL) {
u8 *wepkey;
char *key;
enum wlantest_ctrl_cmd res;
wepkey = attr_get(cmd, clen, WLANTEST_ATTR_WEPKEY, &len);
if (wepkey == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD);
return;
}
key = os_zalloc(len + 1);
if (key == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
}
os_memcpy(key, wepkey, len);
if (add_wep(wt, key) < 0)
res = WLANTEST_CTRL_FAILURE;
else
res = WLANTEST_CTRL_SUCCESS;
os_free(key);
ctrl_send_simple(wt, sock, res);
return;
}
if (len < 8 || len > 63) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD);
return;
}

View file

@ -136,25 +136,26 @@ static void add_secret(struct wlantest *wt, const char *secret)
}
static void add_wep(struct wlantest *wt, const char *key)
int add_wep(struct wlantest *wt, const char *key)
{
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);
return;
return -1;
}
w = os_zalloc(sizeof(*w));
if (w == NULL)
return;
return -1;
if (hexstr2bin(key, w->key, len / 2) < 0) {
os_free(w);
wpa_printf(MSG_INFO, "Invalid WEP key '%s'", key);
return;
return -1;
}
w->key_len = len / 2;
dl_list_add(&wt->wep, &w->list);
return 0;
}
@ -217,7 +218,8 @@ int main(int argc, char *argv[])
write_file = optarg;
break;
case 'W':
add_wep(&wt, optarg);
if (add_wep(&wt, optarg) < 0)
return -1;
break;
default:
usage();

View file

@ -177,6 +177,7 @@ struct wlantest {
int last_mgmt_valid;
};
int add_wep(struct wlantest *wt, const char *key);
int read_cap_file(struct wlantest *wt, const char *fname);
int read_wired_cap_file(struct wlantest *wt, const char *fname);
int write_pcap_init(struct wlantest *wt, const char *fname);

View file

@ -60,6 +60,7 @@ enum wlantest_ctrl_attr {
WLANTEST_ATTR_FRAME,
WLANTEST_ATTR_TDLS_COUNTER,
WLANTEST_ATTR_STA2_ADDR,
WLANTEST_ATTR_WEPKEY,
};
enum wlantest_bss_counter {