Passive Client Taxonomy
[mech_eap.git] / src / ap / ctrl_iface_ap.c
index 9760933..3680fda 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Control interface for shared AP commands
- * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -10,7 +10,9 @@
 
 #include "utils/common.h"
 #include "common/ieee802_11_defs.h"
+#include "common/sae.h"
 #include "eapol_auth/eapol_auth_sm.h"
+#include "fst/fst_ctrl_iface.h"
 #include "hostapd.h"
 #include "ieee802_1x.h"
 #include "wpa_auth.h"
@@ -20,6 +22,8 @@
 #include "p2p_hostapd.h"
 #include "ctrl_iface_ap.h"
 #include "ap_drv_ops.h"
+#include "mbo_ap.h"
+#include "taxonomy.h"
 
 
 static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
@@ -33,10 +37,10 @@ static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
                return 0;
 
        ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n"
-                         "rx_bytes=%lu\ntx_bytes=%lu\n",
+                         "rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n",
                          data.rx_packets, data.tx_packets,
-                         data.rx_bytes, data.tx_bytes);
-       if (ret < 0 || (size_t) ret >= buflen)
+                         data.rx_bytes, data.tx_bytes, data.inactive_msec);
+       if (os_snprintf_error(buflen, ret))
                return 0;
        return ret;
 }
@@ -55,7 +59,7 @@ static int hostapd_get_sta_conn_time(struct sta_info *sta,
 
        ret = os_snprintf(buf, buflen, "connected_time=%u\n",
                          (unsigned int) age.sec);
-       if (ret < 0 || (size_t) ret >= buflen)
+       if (os_snprintf_error(buflen, ret))
                return 0;
        return ret;
 }
@@ -92,7 +96,7 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
        len = 0;
        ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
                          MAC2STR(sta->addr));
-       if (ret < 0 || (size_t) ret >= buflen - len)
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
 
@@ -104,7 +108,7 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
        ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
                          "listen_interval=%d\nsupported_rates=",
                          sta->aid, sta->capability, sta->listen_interval);
-       if (ret < 0 || (size_t) ret >= buflen - len)
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
 
@@ -112,14 +116,14 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
                ret = os_snprintf(buf + len, buflen - len, "%02x%s",
                                  sta->supported_rates[i],
                                  i + 1 < sta->supported_rates_len ? " " : "");
-               if (ret < 0 || (size_t) ret >= buflen - len)
+               if (os_snprintf_error(buflen - len, ret))
                        return len;
                len += ret;
        }
 
        ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n",
                          timeout_next_str(sta->timeout_next));
-       if (ret < 0 || (size_t) ret >= buflen - len)
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
 
@@ -143,6 +147,35 @@ static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
        len += hostapd_get_sta_tx_rx(hapd, sta, buf + len, buflen - len);
        len += hostapd_get_sta_conn_time(sta, buf + len, buflen - len);
 
+#ifdef CONFIG_SAE
+       if (sta->sae && sta->sae->state == SAE_ACCEPTED) {
+               res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n",
+                                 sta->sae->group);
+               if (!os_snprintf_error(buflen - len, res))
+                       len += res;
+       }
+#endif /* CONFIG_SAE */
+
+       if (sta->vlan_id > 0) {
+               res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n",
+                                 sta->vlan_id);
+               if (!os_snprintf_error(buflen - len, res))
+                       len += res;
+       }
+
+       res = mbo_ap_get_info(sta, buf + len, buflen - len);
+       if (res >= 0)
+               len += res;
+
+       if (sta->supp_op_classes &&
+           buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) {
+               len += os_snprintf(buf + len, buflen - len, "supp_op_classes=");
+               len += wpa_snprintf_hex(buf + len, buflen - len,
+                                       sta->supp_op_classes + 1,
+                                       sta->supp_op_classes[0]);
+               len += os_snprintf(buf + len, buflen - len, "\n");
+       }
+
        return len;
 }
 
@@ -164,7 +197,7 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
 
        if (hwaddr_aton(txtaddr, addr)) {
                ret = os_snprintf(buf, buflen, "FAIL\n");
-               if (ret < 0 || (size_t) ret >= buflen)
+               if (os_snprintf_error(buflen, ret))
                        return 0;
                return ret;
        }
@@ -189,7 +222,10 @@ int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
                return -1;
        }
 
-       return hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen);
+       ret = hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen);
+       ret += fst_ctrl_iface_mb_info(addr, buf + ret, buflen - ret);
+
+       return ret;
 }
 
 
@@ -203,7 +239,7 @@ int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
        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)
+               if (os_snprintf_error(buflen, ret))
                        return 0;
                return ret;
        }
@@ -223,18 +259,19 @@ static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
        int ret;
        u8 *pos;
 
-       if (hapd->driver->send_frame == NULL)
+       if (!hapd->drv_priv || !hapd->driver->send_frame)
                return -1;
 
        mgmt = os_zalloc(sizeof(*mgmt) + 100);
        if (mgmt == NULL)
                return -1;
 
+       mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
        wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR
-               " with minor reason code %u (stype=%u)",
-               MAC2STR(addr), minor_reason_code, stype);
+               " with minor reason code %u (stype=%u (%s))",
+               MAC2STR(addr), minor_reason_code, stype,
+               fc2str(le_to_host16(mgmt->frame_control)));
 
-       mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
        os_memcpy(mgmt->da, addr, ETH_ALEN);
        os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
        os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
@@ -289,7 +326,7 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
        if (pos) {
                struct ieee80211_mgmt mgmt;
                int encrypt;
-               if (hapd->driver->send_frame == NULL)
+               if (!hapd->drv_priv || !hapd->driver->send_frame)
                        return -1;
                pos += 6;
                encrypt = atoi(pos);
@@ -316,7 +353,10 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
        }
 #endif /* CONFIG_P2P_MANAGER */
 
-       hostapd_drv_sta_deauth(hapd, addr, reason);
+       if (os_strstr(txtaddr, " tx=0"))
+               hostapd_drv_sta_remove(hapd, addr);
+       else
+               hostapd_drv_sta_deauth(hapd, addr, reason);
        sta = ap_get_sta(hapd, addr);
        if (sta)
                ap_sta_deauthenticate(hapd, sta, reason);
@@ -349,7 +389,7 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
        if (pos) {
                struct ieee80211_mgmt mgmt;
                int encrypt;
-               if (hapd->driver->send_frame == NULL)
+               if (!hapd->drv_priv || !hapd->driver->send_frame)
                        return -1;
                pos += 6;
                encrypt = atoi(pos);
@@ -376,7 +416,10 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
        }
 #endif /* CONFIG_P2P_MANAGER */
 
-       hostapd_drv_sta_disassoc(hapd, addr, reason);
+       if (os_strstr(txtaddr, " tx=0"))
+               hostapd_drv_sta_remove(hapd, addr);
+       else
+               hostapd_drv_sta_disassoc(hapd, addr, reason);
        sta = ap_get_sta(hapd, addr);
        if (sta)
                ap_sta_disassociate(hapd, sta, reason);
@@ -387,6 +430,49 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
 }
 
 
+#ifdef CONFIG_TAXONOMY
+int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
+                                const char *txtaddr,
+                                char *buf, size_t buflen)
+{
+       u8 addr[ETH_ALEN];
+       struct sta_info *sta;
+
+       wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE SIGNATURE %s", txtaddr);
+
+       if (hwaddr_aton(txtaddr, addr))
+               return -1;
+
+       sta = ap_get_sta(hapd, addr);
+       if (!sta)
+               return -1;
+
+       return retrieve_sta_taxonomy(hapd, sta, buf, buflen);
+}
+#endif /* CONFIG_TAXONOMY */
+
+
+int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
+                               const char *txtaddr)
+{
+       u8 addr[ETH_ALEN];
+       struct sta_info *sta;
+
+       wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE POLL_STA %s", txtaddr);
+
+       if (hwaddr_aton(txtaddr, addr))
+               return -1;
+
+       sta = ap_get_sta(hapd, addr);
+       if (!sta)
+               return -1;
+
+       hostapd_drv_poll_client(hapd, hapd->own_addr, addr,
+                               sta->flags & WLAN_STA_WMM);
+       return 0;
+}
+
+
 int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                              size_t buflen)
 {
@@ -405,6 +491,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                          "num_sta_ht_no_gf=%d\n"
                          "num_sta_no_ht=%d\n"
                          "num_sta_ht_20_mhz=%d\n"
+                         "num_sta_ht40_intolerant=%d\n"
                          "olbc_ht=%d\n"
                          "ht_op_mode=0x%x\n",
                          hostapd_state_text(iface->state),
@@ -417,9 +504,10 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                          iface->num_sta_ht_no_gf,
                          iface->num_sta_no_ht,
                          iface->num_sta_ht_20mhz,
+                         iface->num_sta_ht40_intolerant,
                          iface->olbc_ht,
                          iface->ht_op_mode);
-       if (ret < 0 || (size_t) ret >= buflen - len)
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
 
@@ -441,7 +529,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                                  iface->dfs_cac_ms / 1000,
                                  left_time);
        }
-       if (ret < 0 || (size_t) ret >= buflen - len)
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
 
@@ -449,20 +537,28 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                          "channel=%u\n"
                          "secondary_channel=%d\n"
                          "ieee80211n=%d\n"
-                         "ieee80211ac=%d\n"
-                         "vht_oper_chwidth=%d\n"
-                         "vht_oper_centr_freq_seg0_idx=%d\n"
-                         "vht_oper_centr_freq_seg1_idx=%d\n",
+                         "ieee80211ac=%d\n",
                          iface->conf->channel,
-                         iface->conf->secondary_channel,
-                         iface->conf->ieee80211n,
-                         iface->conf->ieee80211ac,
-                         iface->conf->vht_oper_chwidth,
-                         iface->conf->vht_oper_centr_freq_seg0_idx,
-                         iface->conf->vht_oper_centr_freq_seg1_idx);
-       if (ret < 0 || (size_t) ret >= buflen - len)
+                         iface->conf->ieee80211n && !hapd->conf->disable_11n ?
+                         iface->conf->secondary_channel : 0,
+                         iface->conf->ieee80211n && !hapd->conf->disable_11n,
+                         iface->conf->ieee80211ac &&
+                         !hapd->conf->disable_11ac);
+       if (os_snprintf_error(buflen - len, ret))
                return len;
        len += ret;
+       if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac) {
+               ret = os_snprintf(buf + len, buflen - len,
+                                 "vht_oper_chwidth=%d\n"
+                                 "vht_oper_centr_freq_seg0_idx=%d\n"
+                                 "vht_oper_centr_freq_seg1_idx=%d\n",
+                                 iface->conf->vht_oper_chwidth,
+                                 iface->conf->vht_oper_centr_freq_seg0_idx,
+                                 iface->conf->vht_oper_centr_freq_seg1_idx);
+               if (os_snprintf_error(buflen - len, ret))
+                       return len;
+               len += ret;
+       }
 
        for (i = 0; i < iface->num_bss; i++) {
                struct hostapd_data *bss = iface->bss[i];
@@ -477,7 +573,7 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
                                  wpa_ssid_txt(bss->conf->ssid.ssid,
                                               bss->conf->ssid.ssid_len),
                                  (int) i, bss->num_sta);
-               if (ret < 0 || (size_t) ret >= buflen - len)
+               if (os_snprintf_error(buflen - len, ret))
                        return len;
                len += ret;
        }
@@ -524,3 +620,22 @@ int hostapd_parse_csa_settings(const char *pos,
 
        return 0;
 }
+
+
+int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
+{
+       return hostapd_drv_stop_ap(hapd);
+}
+
+
+int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
+                                 size_t len)
+{
+       return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len);
+}
+
+
+void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd)
+{
+       wpa_auth_pmksa_flush(hapd->wpa_auth);
+}