diff --git a/wlantest/ctrl.c b/wlantest/ctrl.c index e97448d6b..2e470dd96 100644 --- a/wlantest/ctrl.c +++ b/wlantest/ctrl.c @@ -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; } diff --git a/wlantest/wlantest.c b/wlantest/wlantest.c index 17b3dd337..040cda157 100644 --- a/wlantest/wlantest.c +++ b/wlantest/wlantest.c @@ -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(); diff --git a/wlantest/wlantest.h b/wlantest/wlantest.h index 32794caac..a6165cce1 100644 --- a/wlantest/wlantest.h +++ b/wlantest/wlantest.h @@ -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); diff --git a/wlantest/wlantest_ctrl.h b/wlantest/wlantest_ctrl.h index a91b6cd79..91f5af61f 100644 --- a/wlantest/wlantest_ctrl.h +++ b/wlantest/wlantest_ctrl.h @@ -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 {