remote: close file on usteer_init_local_id fread fail
[project/usteer.git] / sta.c
diff --git a/sta.c b/sta.c
index d9fcb60bbe833c52c56bf5dbdceeb8226e6a2557..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);
 }
 
@@ -72,9 +73,6 @@ usteer_sta_info_timeout(struct usteer_timeout_queue *q, struct usteer_timeout *t
 {
        struct sta_info *si = container_of(t, struct sta_info, timeout);
 
-       MSG_T_STA("local_sta_timeout", si->sta->addr,
-               "timeout expired, deleting sta info\n");
-
        usteer_sta_info_del(si);
 }
 
@@ -107,6 +105,9 @@ usteer_sta_info_get(struct sta *sta, struct usteer_node *node, bool *create)
        si->created = current_time;
        *create = true;
 
+       /* Node is by default not connected. */
+       usteer_sta_disconnected(si);
+
        return si;
 }
 
@@ -114,7 +115,7 @@ usteer_sta_info_get(struct sta *sta, struct usteer_node *node, bool *create)
 void
 usteer_sta_info_update_timeout(struct sta_info *si, int timeout)
 {
-       if (si->connected == 1)
+       if (si->connected == STA_CONNECTED)
                usteer_timeout_cancel(&tq, &si->timeout);
        else if (timeout > 0)
                usteer_timeout_set(&tq, &si->timeout, timeout);
@@ -140,21 +141,38 @@ 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)
 {
        /* ignore probe request signal when connected */
-       if (si->connected == 1 && si->signal != NO_SIGNAL && !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);
 }
 
@@ -172,21 +190,13 @@ 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;
-       if (diff > config.sta_block_timeout) {
+       if (diff > config.sta_block_timeout)
                si->stats[type].blocked_cur = 0;
-               MSG_T_STA("sta_block_timeout", addr, "timeout expired\n");
-       }
 
        ret = usteer_check_request(si, type);
        if (!ret) {
@@ -203,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);