]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add ctrl_iface command 'GET version'
authorJouni Malinen <j@w1.fi>
Sun, 31 Oct 2010 15:07:31 +0000 (17:07 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 31 Oct 2010 15:07:31 +0000 (17:07 +0200)
This can be used to fetch the wpa_supplicant/hostapd version
string.

hostapd/ctrl_iface.c
hostapd/hostapd_cli.c
wpa_supplicant/ctrl_iface.c
wpa_supplicant/wpa_cli.c

index d0ed897c86eb6444e6fe264da852f028171dd30f..84a1b7e765d8552903394e5aab2405befce83f61 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd / UNIX domain socket -based control interface
- * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-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
@@ -22,6 +22,7 @@
 
 #include "utils/common.h"
 #include "utils/eloop.h"
+#include "common/version.h"
 #include "common/ieee802_11_defs.h"
 #include "drivers/driver.h"
 #include "radius/radius_client.h"
@@ -729,6 +730,24 @@ static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
 }
 
 
+static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
+                                 char *buf, size_t buflen)
+{
+       int res;
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
+
+       if (os_strcmp(cmd, "version") == 0) {
+               res = os_snprintf(buf, buflen, "%s", VERSION_STR);
+               if (res < 0 || (unsigned int) res >= buflen)
+                       return -1;
+               return res;
+       }
+
+       return -1;
+}
+
+
 static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
                                       void *sock_ctx)
 {
@@ -858,6 +877,9 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
        } else if (os_strncmp(buf, "SET ", 4) == 0) {
                if (hostapd_ctrl_iface_set(hapd, buf + 4))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "GET ", 4) == 0) {
+               reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
+                                                  reply_size);
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;
index 3fdaa159616de784684a9c8893db0f68c2a83bf7..7cc84bb98f7dfffd3b2de703714cdbdef5d351d0 100644 (file)
@@ -670,6 +670,26 @@ static int hostapd_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int hostapd_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid GET command: needs one argument (variable "
+                      "name)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "GET %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long GET command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 struct hostapd_cli_cmd {
        const char *cmd;
        int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
@@ -703,6 +723,7 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
        { "license", hostapd_cli_cmd_license },
        { "quit", hostapd_cli_cmd_quit },
        { "set", hostapd_cli_cmd_set },
+       { "get", hostapd_cli_cmd_get },
        { NULL, NULL }
 };
 
@@ -717,6 +738,11 @@ static void wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
        while (cmd->cmd) {
                if (strncasecmp(cmd->cmd, argv[0], strlen(argv[0])) == 0) {
                        match = cmd;
+                       if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
+                               /* we have an exact match */
+                               count = 1;
+                               break;
+                       }
                        count++;
                }
                cmd++;
index bcf544b39270040c1d3a32361b53602f734bfb76..197d9a1a43feb0673a548fa2db016c07bbba9c32 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "utils/common.h"
 #include "utils/eloop.h"
+#include "common/version.h"
 #include "common/ieee802_11_defs.h"
 #include "common/wpa_ctrl.h"
 #include "eap_peer/eap.h"
@@ -118,6 +119,24 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
 }
 
 
+static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
+                                        char *cmd, char *buf, size_t buflen)
+{
+       int res;
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
+
+       if (os_strcmp(cmd, "version") == 0) {
+               res = os_snprintf(buf, buflen, "%s", VERSION_STR);
+               if (res < 0 || (unsigned int) res >= buflen)
+                       return -1;
+               return res;
+       }
+
+       return -1;
+}
+
+
 #ifdef IEEE8021X_EAPOL
 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
                                             char *addr)
@@ -2731,6 +2750,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "SET ", 4) == 0) {
                if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "GET ", 4) == 0) {
+               reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
+                                                         reply, reply_size);
        } else if (os_strcmp(buf, "LOGON") == 0) {
                eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
        } else if (os_strcmp(buf, "LOGOFF") == 0) {
index 17afc5faac49896004a47ca3464234a0be16d0bf..30d1f7b7e87fd33e6578dfa926758586f1cb1433 100644 (file)
@@ -462,6 +462,26 @@ static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid GET command: need one argument (variable "
+                      "name)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "GET %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long GET command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
        return wpa_ctrl_command(ctrl, "LOGOFF");
@@ -2209,6 +2229,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
          cli_cmd_flag_none,
          "= set variables (shows list of variables when run without "
          "arguments)" },
+       { "get", wpa_cli_cmd_get,
+         cli_cmd_flag_none,
+         "<name> = get information" },
        { "logon", wpa_cli_cmd_logon,
          cli_cmd_flag_none,
          "= IEEE 802.1X EAPOL state machine logon" },