wlantest: Add RELOG command to reopen log/capture files
authorJouni Malinen <j@w1.fi>
Sun, 17 Nov 2013 19:11:35 +0000 (21:11 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 17 Nov 2013 19:39:22 +0000 (21:39 +0200)
This can be used similarly to the wpa_supplicant RELOG command to
rotate log and capture files.

Signed-hostap: Jouni Malinen <j@w1.fi>

wlantest/ctrl.c
wlantest/wlantest.c
wlantest/wlantest.h
wlantest/wlantest_cli.c
wlantest/wlantest_ctrl.h

index bed5d6c..86bd672 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest control interface
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -1187,6 +1187,14 @@ static void ctrl_send_(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
 }
 
 
+static void ctrl_relog(struct wlantest *wt, int sock)
+{
+       int res = wlantest_relog(wt);
+       ctrl_send_simple(wt, sock, res ? WLANTEST_CTRL_FAILURE :
+                        WLANTEST_CTRL_SUCCESS);
+}
+
+
 static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
 {
        struct wlantest *wt = eloop_ctx;
@@ -1270,6 +1278,9 @@ static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
        case WLANTEST_CTRL_SEND:
                ctrl_send_(wt, sock, buf + 4, len - 4);
                break;
+       case WLANTEST_CTRL_RELOG:
+               ctrl_relog(wt, sock);
+               break;
        default:
                ctrl_send_simple(wt, sock, WLANTEST_CTRL_UNKNOWN_CMD);
                break;
index 5b691fa..2966458 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010-2011, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -245,15 +245,35 @@ size_t notes_len(struct wlantest *wt, size_t hdrlen)
 }
 
 
+int wlantest_relog(struct wlantest *wt)
+{
+       int ret = 0;
+
+       wpa_printf(MSG_INFO, "Re-open log/capture files");
+
+       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;
+}
+
+
 int main(int argc, char *argv[])
 {
        int c;
        const char *read_file = NULL;
        const char *read_wired_file = NULL;
-       const char *write_file = NULL;
        const char *ifname = NULL;
        const char *ifname_wired = NULL;
-       const char *pcapng_file = NULL;
        struct wlantest wt;
        int ctrl_iface = 0;
 
@@ -294,7 +314,7 @@ int main(int argc, char *argv[])
                        ifname_wired = optarg;
                        break;
                case 'n':
-                       pcapng_file = optarg;
+                       wt.pcapng_file = optarg;
                        break;
                case 'p':
                        add_passphrase(&wt, optarg);
@@ -312,7 +332,7 @@ int main(int argc, char *argv[])
                        read_wired_file = optarg;
                        break;
                case 'w':
-                       write_file = optarg;
+                       wt.write_file = optarg;
                        break;
                case 'W':
                        if (add_wep(&wt, optarg) < 0)
@@ -333,10 +353,10 @@ int main(int argc, char *argv[])
        if (eloop_init())
                return -1;
 
-       if (write_file && write_pcap_init(&wt, write_file) < 0)
+       if (wt.write_file && write_pcap_init(&wt, wt.write_file) < 0)
                return -1;
 
-       if (pcapng_file && write_pcapng_init(&wt, pcapng_file) < 0)
+       if (wt.pcapng_file && write_pcapng_init(&wt, wt.pcapng_file) < 0)
                return -1;
 
        if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0)
index 1ff3229..6146830 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -188,6 +188,9 @@ struct wlantest {
 
        char *notes[MAX_NOTES];
        size_t num_notes;
+
+       const char *write_file;
+       const char *pcapng_file;
 };
 
 void add_note(struct wlantest *wt, int level, const char *fmt, ...)
@@ -286,4 +289,6 @@ int wlantest_inject(struct wlantest *wt, struct wlantest_bss *bss,
                    struct wlantest_sta *sta, u8 *frame, size_t len,
                    enum wlantest_inject_protection prot);
 
+int wlantest_relog(struct wlantest *wt);
+
 #endif /* WLANTEST_H */
index fe81bfc..afe38c4 100644 (file)
@@ -740,6 +740,12 @@ static char ** complete_get_bss_counter(int s, const char *str, int pos)
 }
 
 
+static int cmd_relog(int s, int argc, char *argv[])
+{
+       return cmd_simple(s, WLANTEST_CTRL_RELOG);
+}
+
+
 struct tdls_counters {
        const char *name;
        enum wlantest_tdls_counter num;
@@ -1496,6 +1502,7 @@ static const struct wlantest_cli_cmd wlantest_cli_commands[] = {
        { "get_bss_counter", cmd_get_bss_counter,
          "<counter> <BSSID> = get BSS counter value",
          complete_get_bss_counter },
+       { "relog", cmd_relog, "= re-open log-file (allow rolling logs)", NULL },
        { NULL, NULL, NULL, NULL }
 };
 
index 618cf8c..41b6583 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest control interface
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -35,6 +35,7 @@ enum wlantest_ctrl_cmd {
        WLANTEST_CTRL_SEND,
        WLANTEST_CTRL_CLEAR_TDLS_COUNTERS,
        WLANTEST_CTRL_GET_TDLS_COUNTER,
+       WLANTEST_CTRL_RELOG,
 };
 
 enum wlantest_ctrl_attr {