]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wlantest: Add command for adding WEP keys during run time
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 28 Jan 2011 11:33:21 +0000 (13:33 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 28 Jan 2011 11:33:21 +0000 (13:33 +0200)
wlantest/ctrl.c
wlantest/wlantest.c
wlantest/wlantest.h
wlantest/wlantest_ctrl.h

index e97448d6b519da69e98a0c3708c242842ce193d1..2e470dd96987445beea01fb64403c441fab15ac5 100644 (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;
        }
index 17b3dd3379f3a9dfc635c70a3a561eeabf1906b7..040cda157d2bd9ec59cdf88069c042df350a5492 100644 (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();
index 32794caaccd401bc8f627b5bc39ac9da91d757c6..a6165cce186273b7590bd14a1b84f99a5771d12d 100644 (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);
index a91b6cd7990dfbba22a04ea02e8205a12f6d50d5..91f5af61f3ae53abb874e8764c9a77452eef6176 100644 (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 {