taxonomy: Store Probe Request frames in hostapd_sta_info
[mech_eap.git] / src / ap / sta_info.c
index 47b35f0..f12d408 100644 (file)
@@ -32,6 +32,7 @@
 #include "ap_drv_ops.h"
 #include "gas_serv.h"
 #include "wnm_ap.h"
+#include "mbo_ap.h"
 #include "ndisc_snoop.h"
 #include "sta_info.h"
 #include "vlan.h"
@@ -170,8 +171,10 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
        ap_sta_ip6addr_del(hapd, sta);
 
        if (!hapd->iface->driver_ap_teardown &&
-           !(sta->flags & WLAN_STA_PREAUTH))
+           !(sta->flags & WLAN_STA_PREAUTH)) {
                hostapd_drv_sta_remove(hapd, sta->addr);
+               sta->added_unassoc = 0;
+       }
 
        ap_sta_hash_del(hapd, sta);
        ap_sta_list_del(hapd, sta);
@@ -219,6 +222,13 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
                hapd->iface->num_sta_ht_20mhz--;
        }
 
+#ifdef CONFIG_TAXONOMY
+       wpabuf_free(sta->probe_ie_taxonomy);
+       sta->probe_ie_taxonomy = NULL;
+       wpabuf_free(sta->assoc_ie_taxonomy);
+       sta->assoc_ie_taxonomy = NULL;
+#endif /* CONFIG_TAXONOMY */
+
 #ifdef CONFIG_IEEE80211N
        ht40_intolerant_remove(hapd->iface, sta);
 #endif /* CONFIG_IEEE80211N */
@@ -275,8 +285,10 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
                 * VLAN.
                 */
                if (hapd->iface->driver_ap_teardown &&
-                   !(sta->flags & WLAN_STA_PREAUTH))
+                   !(sta->flags & WLAN_STA_PREAUTH)) {
                        hostapd_drv_sta_remove(hapd, sta->addr);
+                       sta->added_unassoc = 0;
+               }
                vlan_remove_dynamic(hapd, sta->vlan_id_bound);
        }
 #endif /* CONFIG_NO_VLAN */
@@ -322,6 +334,9 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
        os_free(sta->sae);
 #endif /* CONFIG_SAE */
 
+       mbo_ap_sta_free(sta);
+       os_free(sta->supp_op_classes);
+
        os_free(sta);
 }
 
@@ -652,6 +667,11 @@ struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
        sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
        dl_list_init(&sta->ip6addr);
 
+#ifdef CONFIG_TAXONOMY
+       sta_track_claim_taxonomy_info(hapd->iface, addr,
+                                     &sta->probe_ie_taxonomy);
+#endif /* CONFIG_TAXONOMY */
+
        return sta;
 }
 
@@ -673,6 +693,7 @@ static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
                           hapd->conf->iface, MAC2STR(sta->addr));
                return -1;
        }
+       sta->added_unassoc = 0;
        return 0;
 }
 
@@ -805,18 +826,61 @@ int ap_sta_wps_cancel(struct hostapd_data *hapd,
 #endif /* CONFIG_WPS */
 
 
+static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
+{
+       struct hostapd_vlan *vlan;
+       int vlan_id = MAX_VLAN_ID + 2;
+
+retry:
+       for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
+               if (vlan->vlan_id == vlan_id) {
+                       vlan_id++;
+                       goto retry;
+               }
+       }
+       return vlan_id;
+}
+
+
 int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
                    struct vlan_description *vlan_desc)
 {
        struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
        int old_vlan_id, vlan_id = 0, ret = 0;
 
-       if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED) {
+       if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
                vlan_desc = NULL;
-       } else if (vlan_desc && vlan_desc->notempty) {
-               if (!vlan_compare(vlan_desc, sta->vlan_desc))
-                       return 0; /* nothing to change */
 
+       /* Check if there is something to do */
+       if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
+               /* This sta is lacking its own vif */
+       } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
+                  !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
+               /* sta->vlan_id needs to be reset */
+       } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
+               return 0; /* nothing to change */
+       }
+
+       /* Now the real VLAN changed or the STA just needs its own vif */
+       if (hapd->conf->ssid.per_sta_vif) {
+               /* Assign a new vif, always */
+               /* find a free vlan_id sufficiently big */
+               vlan_id = ap_sta_get_free_vlan_id(hapd);
+               /* Get wildcard VLAN */
+               for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
+                       if (vlan->vlan_id == VLAN_ID_WILDCARD)
+                               break;
+               }
+               if (!vlan) {
+                       hostapd_logger(hapd, sta->addr,
+                                      HOSTAPD_MODULE_IEEE80211,
+                                      HOSTAPD_LEVEL_DEBUG,
+                                      "per_sta_vif missing wildcard");
+                       vlan_id = 0;
+                       ret = -1;
+                       goto done;
+               }
+       } else if (vlan_desc && vlan_desc->notempty) {
                for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
                        if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
                                break;
@@ -828,12 +892,17 @@ int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
                } else if (wildcard_vlan) {
                        vlan = wildcard_vlan;
                        vlan_id = vlan_desc->untagged;
+                       if (vlan_desc->tagged[0]) {
+                               /* Tagged VLAN configuration */
+                               vlan_id = ap_sta_get_free_vlan_id(hapd);
+                       }
                } else {
                        hostapd_logger(hapd, sta->addr,
                                       HOSTAPD_MODULE_IEEE80211,
                                       HOSTAPD_LEVEL_DEBUG,
-                                      "missing VLAN and wildcard for vlan=%d",
-                                      vlan_desc->untagged);
+                                      "missing vlan and wildcard for vlan=%d%s",
+                                      vlan_desc->untagged,
+                                      vlan_desc->tagged[0] ? "+" : "");
                        vlan_id = 0;
                        ret = -1;
                        goto done;
@@ -846,8 +915,10 @@ int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
                        hostapd_logger(hapd, sta->addr,
                                       HOSTAPD_MODULE_IEEE80211,
                                       HOSTAPD_LEVEL_DEBUG,
-                                      "could not add dynamic VLAN interface for vlan=%d",
-                                      vlan_desc->untagged);
+                                      "could not add dynamic VLAN interface for vlan=%d%s",
+                                      vlan_desc ? vlan_desc->untagged : -1,
+                                      (vlan_desc && vlan_desc->tagged[0]) ?
+                                      "+" : "");
                        vlan_id = 0;
                        ret = -1;
                        goto done;