diff --git a/src/cntlr.c b/src/cntlr.c index 370db8850792452745783d52dbb1333de94aa11d..ee04438ce808d6c0f7187bae3b46a8a014159bcb 100644 --- a/src/cntlr.c +++ b/src/cntlr.c @@ -1636,24 +1636,27 @@ static void cntlr_signal_periodic_run(atimer_t *t) static void combined_link_metric_periodic_collection(struct controller *c) { trace("%s: --->\n", __func__); - struct cmdu_buff *cmdu; struct node *p; - struct netif_radio *r; - struct netif_iface *bss; - uint8_t *bsslist = NULL, *new_bsslist = NULL; - uint8_t *radiolist = NULL, *new_radiolist = NULL; - int num_bss, num_radio; - int radio_index, bss_index; - uint8_t hwaddr[6]; + uint8_t *radiolist = NULL, *bsslist = NULL; /* AP metrics query for each agent */ /* For each agent */ list_for_each_entry(p, &c->nodelist, list) { + uint8_t *new_radiolist; + struct node *n; + struct cmdu_buff *cmdu; + struct netif_radio *r; + int num_bss = 0, num_radio = 0; + uint8_t hwaddr[6]; + num_radio = 0; num_bss = 0; memcpy(hwaddr, p->alid, 6); /* For each radio */ list_for_each_entry(r, &p->radiolist, list) { + struct netif_iface *bss; + int radio_index; + /* Building a radiolist of all radios */ new_radiolist = (uint8_t *)realloc(radiolist, 6 * (num_radio + 1) * sizeof(uint8_t)); @@ -1670,6 +1673,9 @@ static void combined_link_metric_periodic_collection(struct controller *c) /* For each bss in radio */ list_for_each_entry(bss, &r->iflist, list) { + int bss_index; + uint8_t *new_bsslist; + if (!bss->bss->is_fbss && !bss->bss->is_bbss) /* if bss is a bsta */ continue; @@ -1696,9 +1702,21 @@ static void combined_link_metric_periodic_collection(struct controller *c) } send_cmdu(c, cmdu); + cmdu_free(cmdu); + + /* query i1905d base CMDU */ + cmdu = ieee1905_ubus_buildcmdu(c->ubus_ctx, CMDU_TYPE_LINK_METRIC_RESPONSE); + if (!cmdu) + dbg("No response from stack when generating 0x%04x\n", + CMDU_TYPE_LINK_METRIC_RESPONSE); + + n = cntlr_find_node(c, c->almac); + if (!n) { + cmdu_free(cmdu); + goto error; + } - /* 1905 Link metric query */ - ieee1905_buildcmdu_linkmetric_resp(c, CMDU_TYPE_LINK_METRIC_RESPONSE); //FIXME: why here? + handle_link_metrics_response(c, cmdu, n); cmdu_free(cmdu); } error: diff --git a/src/cntlr_ubus.c b/src/cntlr_ubus.c index c1c2389e512a01155b3d1897f2a493f45e2ec239..805824cd62aefebdd7da3d024069fb05b8ddc8c5 100644 --- a/src/cntlr_ubus.c +++ b/src/cntlr_ubus.c @@ -3676,89 +3676,122 @@ int ubus_call_object(struct controller *c, uint32_t obj, return 0; } -static void ieee1905_buildcmdu_lm_cb(struct ubus_request *req, int type, - struct blob_attr *msg) + +struct buildcmdu_ctx { + struct cmdu_buff *buff; + int status; +}; + +static void ieee1905_ubus_buildcmdu_cb(struct ubus_request *req, + int type, struct blob_attr *msg) { - char tlv_str[500] = {0}; - int len, b_len; - uint16_t msg_type; - uint8_t *tlv = NULL; - struct cmdu_buff *cmdu = NULL; - struct controller *c; - uint16_t mid = 0; struct blob_attr *tb[2]; - static const struct blobmsg_policy cb_attr[2] = { + static const struct blobmsg_policy ev_attr[2] = { [0] = { .name = "type", .type = BLOBMSG_TYPE_INT32 }, - [1] = { .name = "data", .type = BLOBMSG_TYPE_STRING }, + [1] = { .name = "data", .type = BLOBMSG_TYPE_STRING } }; + uint16_t cmdu_type = 0, mid = 0; + char *data; + uint8_t origin[6] = { 0 }; + uint8_t *tlv; + uint32_t b_len; + struct buildcmdu_ctx *ctx = req->priv; + struct cmdu_buff **buff = NULL; + + if (!ctx) { + err("%s: No priv\n", __func__); + return; + } - blobmsg_parse(cb_attr, 2, tb, blob_data(msg), blob_len(msg)); + buff = &ctx->buff; - if (!tb[1] || !tb[0]) + if (!msg) { + err("%s: Message NULL\n", __func__); + ctx->status = -1; return; + } - c = (struct controller *)req->priv; - msg_type = (uint16_t)blobmsg_get_u32(tb[0]); - strncpy(tlv_str, blobmsg_data(tb[1]), sizeof(tlv_str) - 1); - len = strlen(tlv_str); - b_len = (len/2); - tlv = (uint8_t *) malloc((b_len) * sizeof(uint8_t)); - if (tlv == NULL) { - err("No Memory\n"); + + blobmsg_parse(ev_attr, 2, tb, blob_data(msg), blob_len(msg)); + + if (!tb[0] || !tb[1]) + return; + + cmdu_type = blobmsg_get_u32(tb[0]); + data = blobmsg_get_string(tb[1]); + if (!data) { + err("%s: No data\n", __func__); + ctx->status = -1; return; } - strtob(tlv_str, b_len, tlv); - if (msg_type == CMDU_TYPE_LINK_METRIC_RESPONSE) { - struct node *n; + dbg("|%s:%d| type = %u data = %s\n", __func__, __LINE__, + cmdu_type, data); - cmdu = cmdu_alloc_custom(msg_type, &mid, NULL, c->almac, tlv, b_len); - if (!cmdu) - goto out; - n = cntlr_find_node(c, c->almac); - if (!n) - goto out; + b_len = (strlen(data)/2) - 3; - handle_link_metrics_response(c, cmdu, n); - cmdu_free(cmdu); + tlv = (uint8_t *) calloc(1, b_len); + if (!tlv) { + err("%s: No memory\n", __func__); + ctx->status = -1; + return; } -out: + strtob(data, b_len, tlv); + + *buff = cmdu_alloc_custom(cmdu_type, &mid, NULL, origin, + tlv, b_len); free(tlv); - return; + + if (!*buff) { + err("%s: Couldn't allocate cmdu buff\n", __func__); + ctx->status = -1; + return; + } + + ctx->status = 0; } -int ieee1905_buildcmdu_linkmetric_resp(struct controller *c, uint16_t msg_type) +struct cmdu_buff *ieee1905_ubus_buildcmdu(struct ubus_context *ubus_ctx, + uint16_t msg_type) { struct blob_buf b = { 0 }; int ret = 0; uint32_t id; + struct buildcmdu_ctx ctx = { + .buff = NULL, + .status = -1, + }; + + dbg("|%s:%d| Entry\n", __func__, __LINE__); - memset(&b, 0, sizeof(struct blob_buf)); blob_buf_init(&b, 0); blobmsg_add_u32(&b, "type", (uint32_t)msg_type); - if (!c->ubus_ctx) - trace("I think that the ubus_ctx is NULL\n"); - if (ubus_lookup_id(c->ubus_ctx, "ieee1905", &id)) { - dbg("[%s:%d] not present i1905", __func__, __LINE__); + if (ubus_lookup_id(ubus_ctx, "ieee1905", &id)) { + dbg("|%s:%d| not present ieee1905", __func__, __LINE__); goto out; } - trace("\t\t%s: %d\n", __func__, __LINE__); + ret = ubus_invoke(ubus_ctx, id, "buildcmdu", + b.head, ieee1905_ubus_buildcmdu_cb, + &ctx, 2000); + + if (ctx.status) + ret = ctx.status; - ret = ubus_invoke(c->ubus_ctx, id, "buildcmdu", - b.head, ieee1905_buildcmdu_lm_cb, c, 5000); if (ret) { - dbg("[%s:%d] ubus call failed for |i1905 buildcmdu|", - __func__, __LINE__); + dbg("|%s:%d| ubus call failed for |ieee1905 buildcmdu|", + __func__, __LINE__); goto out; } out: blob_buf_free(&b); - return ret; -} + return ctx.buff; + } + + int cntlr_wait_for_object_timeout(struct controller *c, void *object, diff --git a/src/cntlr_ubus.h b/src/cntlr_ubus.h index 4bd785889f5c6e247795da4cbcd85bafe7ee1764..1986f44de368d7d0337efcc1fae07d2f803d5fd9 100644 --- a/src/cntlr_ubus.h +++ b/src/cntlr_ubus.h @@ -29,7 +29,8 @@ int ubus_call_object(struct controller *c, uint32_t obj, int cntlr_wait_for_object_timeout(struct controller *c, void *object, uint32_t tmo_msecs, void *res); -int ieee1905_buildcmdu_linkmetric_resp(struct controller *c, uint16_t msg_type); +struct cmdu_buff *ieee1905_ubus_buildcmdu(struct ubus_context *ubus_ctx, + uint16_t msg_type); int cntlr_get_ieee1905_almac(struct controller *c, uint8_t *almac); void cntlr_status_add_opclass(struct blob_buf *bb, struct wifi_radio_opclass *opclass,