From: David Bauer Date: Wed, 29 Dec 2021 20:14:25 +0000 (+0100) Subject: node: add methods to access nodes by bssid X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=76ccae62df64ad2cb01690e64178a7db4e63c434;p=project%2Fusteer.git node: add methods to access nodes by bssid Add methods which returns a given node for a provided BSSID. This is required to retrieve the node object from information available with a neighbor report. Signed-off-by: David Bauer --- diff --git a/local_node.c b/local_node.c index e441266..e69ec21 100644 --- a/local_node.c +++ b/local_node.c @@ -79,6 +79,19 @@ usteer_free_node(struct ubus_context *ctx, struct usteer_local_node *ln) free(ln); } +struct usteer_local_node *usteer_local_node_by_bssid(uint8_t *bssid) { + struct usteer_local_node *ln; + struct usteer_node *n; + + for_each_local_node(n) { + ln = container_of(n, struct usteer_local_node, node); + if (!memcmp(n->bssid, bssid, 6)) + return ln; + } + + return NULL; +} + static void usteer_handle_remove(struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id) diff --git a/node.c b/node.c index 8fd1069..02dd30a 100644 --- a/node.c +++ b/node.c @@ -20,6 +20,32 @@ #include "node.h" #include "usteer.h" +struct usteer_remote_node *usteer_remote_node_by_bssid(uint8_t *bssid) { + struct usteer_remote_node *rn; + + for_each_remote_node(rn) { + if (!memcmp(rn->node.bssid, bssid, 6)) + return rn; + } + + return NULL; +} + +struct usteer_node *usteer_node_by_bssid(uint8_t *bssid) { + struct usteer_remote_node *rn; + struct usteer_local_node *ln; + + rn = usteer_remote_node_by_bssid(bssid); + if (rn) + return &rn->node; + + ln = usteer_local_node_by_bssid(bssid); + if (ln) + return &ln->node; + + return NULL; +} + void usteer_node_set_blob(struct blob_attr **dest, struct blob_attr *val) { int new_len; diff --git a/usteer.h b/usteer.h index 23c9e41..0ad9499 100644 --- a/usteer.h +++ b/usteer.h @@ -307,6 +307,10 @@ static inline const char *usteer_node_name(struct usteer_node *node) } void usteer_node_set_blob(struct blob_attr **dest, struct blob_attr *val); +struct usteer_local_node *usteer_local_node_by_bssid(uint8_t *bssid); +struct usteer_remote_node *usteer_remote_node_by_bssid(uint8_t *bssid); +struct usteer_node *usteer_node_by_bssid(uint8_t *bssid); + struct usteer_node *usteer_node_get_next_neighbor(struct usteer_node *current_node, struct usteer_node *last); bool usteer_check_request(struct sta_info *si, enum usteer_event_type type);