diff --git a/src/cntlr_ubus.c b/src/cntlr_ubus.c index 5a9adff93da3e84b260d3c9d47c9100824261bb7..11a20d559a174d8ac1bba2414c4b553a95690a13 100644 --- a/src/cntlr_ubus.c +++ b/src/cntlr_ubus.c @@ -3721,3 +3721,82 @@ int cntlr_get_ieee1905_almac(struct controller *c, uint8_t *almac) return ret; } + +static void ieee1905_cb_get_neighbors(struct ubus_request *req, int type, + struct blob_attr *msg) +{ + enum { + NEIGHBOR_ARRAY, + POLICY_LEN + }; + static const struct blobmsg_policy policy[POLICY_LEN] = { + [NEIGHBOR_ARRAY] = { .name = "neighbors", .type = BLOBMSG_TYPE_ARRAY }, + }; + struct blob_attr *tb[POLICY_LEN]; + struct ieee1905_neighbor_array *output_array = + (struct ieee1905_neighbor_array *)req->priv; + + blobmsg_parse(policy, POLICY_LEN, tb, blob_data(msg), blob_len(msg)); + + if (tb[NEIGHBOR_ARRAY]) { + struct blob_attr *cur; + int i = 0, rem = 0; + const int neighbor_number = + blobmsg_check_array(tb[NEIGHBOR_ARRAY], BLOBMSG_TYPE_TABLE); + + if (neighbor_number <= 0) + return; + + output_array->neighbors_size = neighbor_number; + output_array->neighbors = + calloc(neighbor_number, sizeof(struct ieee1905_neighbor)); + + if (!output_array->neighbors) + return; + + blobmsg_for_each_attr(cur, tb[NEIGHBOR_ARRAY], rem) { + enum { + AL_MAC, + IMMEDIATE, + NEIGHBOR_POLICY_LEN + }; + const struct blobmsg_policy nb_attribs_policy[NEIGHBOR_POLICY_LEN] = { + [AL_MAC] = { .name = "ieee1905id", .type = BLOBMSG_TYPE_STRING }, + [IMMEDIATE] = { .name = "immediate", .type = BLOBMSG_TYPE_BOOL }, + }; + struct blob_attr *tb_nb_attribs[NEIGHBOR_POLICY_LEN]; + struct ieee1905_neighbor *output_neighbor = + &output_array->neighbors[i++]; + + blobmsg_parse(nb_attribs_policy, NEIGHBOR_POLICY_LEN, + tb_nb_attribs, blobmsg_data(cur), + blobmsg_data_len(cur)); + + if (tb_nb_attribs[AL_MAC]) + hwaddr_aton(blobmsg_get_string(tb_nb_attribs[AL_MAC]), + output_neighbor->al_mac); + + if (tb_nb_attribs[IMMEDIATE]) + output_neighbor->is_immediate = + blobmsg_get_bool(tb_nb_attribs[IMMEDIATE]); + }; + } +} + +int cntrl_get_ieee1905_neighbors(struct controller *c, + struct ieee1905_neighbor_array *neighbors) +{ + uint32_t obj; + int ret; + + neighbors->neighbors = NULL; + neighbors->neighbors_size = 0; + + ret = cntlr_wait_for_object_timeout(c, "ieee1905", -1, &obj); + if (!ret) + ret = ubus_call_object(c, obj, "neighbors", + ieee1905_cb_get_neighbors, + neighbors); + + return ret; +} diff --git a/src/cntlr_ubus.h b/src/cntlr_ubus.h index f7b439e4de58cb33eb8468d52c4c56b6e2793038..6acbb3fc9665a809358c3a788bc3315b2dd0ba92 100644 --- a/src/cntlr_ubus.h +++ b/src/cntlr_ubus.h @@ -33,4 +33,17 @@ int ieee1905_buildcmdu_linkmetric_resp(struct controller *c, uint16_t msg_type); int cntlr_get_ieee1905_almac(struct controller *c, uint8_t *almac); +struct ieee1905_neighbor { + uint8_t al_mac[6]; + bool is_immediate; +}; + +struct ieee1905_neighbor_array { + struct ieee1905_neighbor *neighbors; + uint32_t neighbors_size; +}; + +int cntrl_get_ieee1905_neighbors(struct controller *c, + struct ieee1905_neighbor_array *neighbors); + #endif /* CNTLR_UBUS_H */ diff --git a/src/config.c b/src/config.c index 1b0d72348feeaa03b6892aa9e8be393f4d4e69e7..ebc756c4fe5f7cca6df098b684e2152d0da6dd58 100644 --- a/src/config.c +++ b/src/config.c @@ -632,6 +632,7 @@ static int cntlr_config_get_base(struct controller_config *c, CNTLR_DEFAULT_PCP, CNTLR_ENABLE_TS, CNTLR_PROFILE, + CNTRL_MAX_NODE_BH_HOPS, NUM_CNTLR_ATTRS }; @@ -648,6 +649,7 @@ static int cntlr_config_get_base(struct controller_config *c, [CNTLR_DEFAULT_PCP] = { .name = "default_pcp", .type = UCI_TYPE_STRING }, [CNTLR_ENABLE_TS] = { .name = "enable_ts", .type = UCI_TYPE_STRING }, [CNTLR_PROFILE] = { .name = "profile", .type = UCI_TYPE_STRING }, + [CNTRL_MAX_NODE_BH_HOPS] = { .name = "max_node_bh_hops", .type = UCI_TYPE_STRING }, }; struct uci_option *tb[NUM_CNTLR_ATTRS]; @@ -734,6 +736,13 @@ static int cntlr_config_get_base(struct controller_config *c, c->enable_ts = !!atoi(val); } + if (tb[CNTRL_MAX_NODE_BH_HOPS]) { + const char *val = tb[CNTRL_MAX_NODE_BH_HOPS]->v.string; + const int max_hops = atoi(val); + + c->max_node_bh_hops = (max_hops > 0) ? max_hops : 0; + } + return 0; } diff --git a/src/config.h b/src/config.h index c057daa2e79e9d28b49cb5fb68777a26cff4937b..a7e8b85aaa3df725f43b9e557edc4081792fcac8 100644 --- a/src/config.h +++ b/src/config.h @@ -167,6 +167,7 @@ struct controller_config { unsigned int default_pcp; int map_profile; bool enable_ts; + unsigned int max_node_bh_hops; #if (EASYMESH_VERSION > 2) char *dpp_uri_file; #endif