remote: close file on usteer_init_local_id fread fail
[project/usteer.git] / sta.c
diff --git a/sta.c b/sta.c
index 54bcaeb2a5c4e827ed7bcf1dcc7217ac3e860863..ed7e40ecb032224828378f42b262812eeceb6f7b 100644 (file)
--- a/sta.c
+++ b/sta.c
@@ -35,6 +35,7 @@ usteer_sta_del(struct sta *sta)
            MAC_ADDR_DATA(sta->addr));
 
        avl_delete(&stations, &sta->avl);
+       usteer_measurement_report_sta_cleanup(sta);
        free(sta);
 }
 
@@ -105,8 +106,7 @@ usteer_sta_info_get(struct sta *sta, struct usteer_node *node, bool *create)
        *create = true;
 
        /* Node is by default not connected. */
-       si->connected = STA_NOT_CONNECTED;
-       usteer_sta_info_update_timeout(si, config.local_sta_timeout);
+       usteer_sta_disconnected(si);
 
        return si;
 }
@@ -141,10 +141,19 @@ usteer_sta_get(const uint8_t *addr, bool create)
        sta->avl.key = sta->addr;
        avl_insert(&stations, &sta->avl);
        INIT_LIST_HEAD(&sta->nodes);
+       INIT_LIST_HEAD(&sta->measurements);
 
        return sta;
 }
 
+void usteer_sta_disconnected(struct sta_info *si)
+{
+       si->connected = STA_NOT_CONNECTED;
+       si->kick_time = 0;
+       si->connected_since = 0;
+       usteer_sta_info_update_timeout(si, config.local_sta_timeout);
+}
+
 void
 usteer_sta_info_update(struct sta_info *si, int signal, bool avg)
 {
@@ -152,10 +161,18 @@ usteer_sta_info_update(struct sta_info *si, int signal, bool avg)
        if (si->connected == STA_CONNECTED && si->signal != NO_SIGNAL && !avg)
                signal = NO_SIGNAL;
 
-       if (signal != NO_SIGNAL)
+       if (signal != NO_SIGNAL) {
                si->signal = signal;
+               usteer_band_steering_sta_update(si);
+       }
 
        si->seen = current_time;
+
+       if (si->node->freq < 4000)
+               si->sta->seen_2ghz = 1;
+       else
+               si->sta->seen_5ghz = 1;
+
        usteer_sta_info_update_timeout(si, config.local_sta_timeout);
 }
 
@@ -173,14 +190,8 @@ usteer_handle_sta_event(struct usteer_node *node, const uint8_t *addr,
        if (!sta)
                return -1;
 
-       if (freq < 4000)
-               sta->seen_2ghz = 1;
-       else
-               sta->seen_5ghz = 1;
-
        si = usteer_sta_info_get(sta, node, &create);
        usteer_sta_info_update(si, signal, false);
-       si->roam_scan_done = current_time;
        si->stats[type].requests++;
 
        diff = si->stats[type].blocked_last_time - current_time;
@@ -202,6 +213,27 @@ usteer_handle_sta_event(struct usteer_node *node, const uint8_t *addr,
        return ret;
 }
 
+bool
+usteer_sta_supports_beacon_measurement_mode(struct sta_info *si, enum usteer_beacon_measurement_mode mode)
+{
+       switch (mode) {
+               case BEACON_MEASUREMENT_PASSIVE:
+                       return si->rrm & (1 << 4);
+               case BEACON_MEASUREMENT_ACTIVE:
+                       return si->rrm & (1 << 5);
+               case BEACON_MEASUREMENT_TABLE:
+                       return si->rrm & (1 << 6);
+       }
+
+       return false;
+}
+
+bool
+usteer_sta_supports_link_measurement(struct sta_info *si)
+{
+       return si->rrm & (1 << 0);
+}
+
 static void __usteer_init usteer_sta_init(void)
 {
        usteer_timeout_init(&tq);