Move STA list ctrl_iface handlers to a separate file
authorJouni Malinen <jouni.malinen@atheros.com>
Tue, 8 Sep 2009 09:56:07 +0000 (12:56 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 8 Sep 2009 09:56:07 +0000 (12:56 +0300)
This makes it easier to share the hostapd station table query
functionality with wpa_supplicant AP mode operations.

hostapd/Makefile
hostapd/ctrl_iface.c
hostapd/ctrl_iface_ap.c [new file with mode: 0644]
hostapd/ctrl_iface_ap.h [new file with mode: 0644]

index 9f8ec81..f87e38a 100644 (file)
@@ -86,6 +86,7 @@ ifdef CONFIG_NO_CTRL_IFACE
 CFLAGS += -DCONFIG_NO_CTRL_IFACE
 else
 OBJS += ctrl_iface.o
+OBJS += ctrl_iface_ap.o
 endif
 
 OBJS += ../src/crypto/md5.o
index bdc02f0..ff739f2 100644 (file)
@@ -32,6 +32,7 @@
 #include "accounting.h"
 #include "wps_hostapd.h"
 #include "drivers/driver.h"
+#include "ctrl_iface_ap.h"
 
 
 struct wpa_ctrl_dst {
@@ -126,88 +127,6 @@ static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
 }
 
 
-static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
-                                     struct sta_info *sta,
-                                     char *buf, size_t buflen)
-{
-       int len, res, ret;
-
-       if (sta == NULL) {
-               ret = os_snprintf(buf, buflen, "FAIL\n");
-               if (ret < 0 || (size_t) ret >= buflen)
-                       return 0;
-               return ret;
-       }
-
-       len = 0;
-       ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
-                         MAC2STR(sta->addr));
-       if (ret < 0 || (size_t) ret >= buflen - len)
-               return len;
-       len += ret;
-
-       res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
-       if (res >= 0)
-               len += res;
-       res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
-       if (res >= 0)
-               len += res;
-       res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
-       if (res >= 0)
-               len += res;
-       res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
-                                     buflen - len);
-       if (res >= 0)
-               len += res;
-
-       return len;
-}
-
-
-static int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
-                                       char *buf, size_t buflen)
-{
-       return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
-}
-
-
-static int hostapd_ctrl_iface_sta(struct hostapd_data *hapd,
-                                 const char *txtaddr,
-                                 char *buf, size_t buflen)
-{
-       u8 addr[ETH_ALEN];
-       int ret;
-
-       if (hwaddr_aton(txtaddr, addr)) {
-               ret = os_snprintf(buf, buflen, "FAIL\n");
-               if (ret < 0 || (size_t) ret >= buflen)
-                       return 0;
-               return ret;
-       }
-       return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
-                                         buf, buflen);
-}
-
-
-static int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd,
-                                      const char *txtaddr,
-                                      char *buf, size_t buflen)
-{
-       u8 addr[ETH_ALEN];
-       struct sta_info *sta;
-       int ret;
-
-       if (hwaddr_aton(txtaddr, addr) ||
-           (sta = ap_get_sta(hapd, addr)) == NULL) {
-               ret = os_snprintf(buf, buflen, "FAIL\n");
-               if (ret < 0 || (size_t) ret >= buflen)
-                       return 0;
-               return ret;
-       }               
-       return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
-}
-
-
 static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
                                      const char *txtaddr)
 {
diff --git a/hostapd/ctrl_iface_ap.c b/hostapd/ctrl_iface_ap.c
new file mode 100644 (file)
index 0000000..b98eb97
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Control interface for shared AP commands
+ * Copyright (c) 2004-2009, 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
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "hostapd.h"
+#include "ieee802_1x.h"
+#include "wpa.h"
+#include "ieee802_11.h"
+#include "sta_info.h"
+#include "wps_hostapd.h"
+#include "ctrl_iface_ap.h"
+
+
+static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
+                                     struct sta_info *sta,
+                                     char *buf, size_t buflen)
+{
+       int len, res, ret;
+
+       if (sta == NULL) {
+               ret = os_snprintf(buf, buflen, "FAIL\n");
+               if (ret < 0 || (size_t) ret >= buflen)
+                       return 0;
+               return ret;
+       }
+
+       len = 0;
+       ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
+                         MAC2STR(sta->addr));
+       if (ret < 0 || (size_t) ret >= buflen - len)
+               return len;
+       len += ret;
+
+       res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
+       if (res >= 0)
+               len += res;
+       res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
+       if (res >= 0)
+               len += res;
+       res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
+       if (res >= 0)
+               len += res;
+       res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
+                                     buflen - len);
+       if (res >= 0)
+               len += res;
+
+       return len;
+}
+
+
+int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
+                                char *buf, size_t buflen)
+{
+       return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
+}
+
+
+int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
+                          char *buf, size_t buflen)
+{
+       u8 addr[ETH_ALEN];
+       int ret;
+
+       if (hwaddr_aton(txtaddr, addr)) {
+               ret = os_snprintf(buf, buflen, "FAIL\n");
+               if (ret < 0 || (size_t) ret >= buflen)
+                       return 0;
+               return ret;
+       }
+       return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
+                                         buf, buflen);
+}
+
+
+int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
+                               char *buf, size_t buflen)
+{
+       u8 addr[ETH_ALEN];
+       struct sta_info *sta;
+       int ret;
+
+       if (hwaddr_aton(txtaddr, addr) ||
+           (sta = ap_get_sta(hapd, addr)) == NULL) {
+               ret = os_snprintf(buf, buflen, "FAIL\n");
+               if (ret < 0 || (size_t) ret >= buflen)
+                       return 0;
+               return ret;
+       }               
+       return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
+}
diff --git a/hostapd/ctrl_iface_ap.h b/hostapd/ctrl_iface_ap.h
new file mode 100644 (file)
index 0000000..8690bea
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Control interface for shared AP commands
+ * Copyright (c) 2004-2009, 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
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef CTRL_IFACE_AP_H
+#define CTRL_IFACE_AP_H
+
+int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
+                                char *buf, size_t buflen);
+int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
+                          char *buf, size_t buflen);
+int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
+                               char *buf, size_t buflen);
+
+#endif /* CTRL_IFACE_AP_H */