diff --git a/src/agent.c b/src/agent.c index 5076003fd588a9cf06731129c072de3f792c168f..af95060e0de7fd3b96de1a629b5ce1b54a6f9c86 100644 --- a/src/agent.c +++ b/src/agent.c @@ -3271,6 +3271,59 @@ static void ethport_event_handler(void *agent, struct blob_attr *msg) return; } + +static void parse_i1905_info(struct ubus_request *req, int type, + struct blob_attr *msg) +{ + struct agent *a = (struct agent *)req->priv; + struct blob_attr *tb[2]; + static const struct blobmsg_policy ieee_attrs[2] = { + [0] = { .name = "ieee1905id", .type = BLOBMSG_TYPE_STRING }, + [1] = { .name = "interface", .type = BLOBMSG_TYPE_ARRAY } + }; + + blobmsg_parse(ieee_attrs, 2, tb, blob_data(msg), blob_len(msg)); + + if (tb[0]) { + char *mac; + + mac = blobmsg_get_string(tb[0]); + hwaddr_aton(mac, a->almac); + dbg("almac = " MACFMT "\n", MAC2STR(a->almac)); + } + + + if (tb[1] && a->cfg.ts_enabled) { + struct blob_attr *cur; + int rem; + + blobmsg_for_each_attr(cur, tb[1], rem) { + struct blob_attr *data[1]; + static const struct blobmsg_policy intf_attrs[1] = { + [0] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING } + }; + char *ifname; + char fmt[64] = {0}; + + if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) + continue; + + blobmsg_parse(intf_attrs, 1, data, blobmsg_data(cur), + blobmsg_data_len(cur)); + + if (!data[0]) + continue; + + ifname = blobmsg_get_string(data[0]); + if (!ifname) + continue; + + snprintf(fmt, sizeof(fmt), "ts multicast %s", ifname); + agent_exec_platform_scripts(fmt); + } + } +} + static void uobj_add_event_handler(void *agent, struct blob_attr *msg) { char path[32] = {0}; @@ -3302,6 +3355,15 @@ static void uobj_add_event_handler(void *agent, struct blob_attr *msg) return; fh->wifi = id; dbg("|%s:%d|wifi object added is [%d] [%u]\n", __func__, __LINE__, fh->wifi, fh->wifi); + } else if (!strncmp(path, "ieee1905.al.", 12)) { + uint32_t ieee1905_obj = 0; + int ret; + + ret = ubus_lookup_id(a->ubus_ctx, "ieee1905", &ieee1905_obj); + if (ret) + return; + + ubus_call_object(a, ieee1905_obj, "info", parse_i1905_info, a); } } @@ -4076,57 +4138,6 @@ static int run_agent(struct agent *a) } #endif -static void parse_i1905_info(struct ubus_request *req, int type, - struct blob_attr *msg) -{ - struct agent *a = (struct agent *)req->priv; - struct blob_attr *tb[2]; - static const struct blobmsg_policy ieee_attrs[2] = { - [0] = { .name = "ieee1905id", .type = BLOBMSG_TYPE_STRING }, - [1] = { .name = "interface", .type = BLOBMSG_TYPE_ARRAY } - }; - - blobmsg_parse(ieee_attrs, 2, tb, blob_data(msg), blob_len(msg)); - - if (tb[0]) { - char *mac; - - mac = blobmsg_get_string(tb[0]); - hwaddr_aton(mac, a->almac); - dbg("almac = " MACFMT "\n", MAC2STR(a->almac)); - } - - if (tb[1] && a->cfg.ts_enabled) { - struct blob_attr *cur; - int rem; - - blobmsg_for_each_attr(cur, tb[1], rem) { - struct blob_attr *data[1]; - static const struct blobmsg_policy intf_attrs[1] = { - [0] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING } - }; - char *ifname; - char fmt[64] = {0}; - - if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) - continue; - - blobmsg_parse(intf_attrs, 1, data, blobmsg_data(cur), - blobmsg_data_len(cur)); - - if (!data[0]) - continue; - - ifname = blobmsg_get_string(data[0]); - if (!ifname) - continue; - - snprintf(fmt, sizeof(fmt), "ts multicast %s", ifname); - agent_exec_platform_scripts(fmt); - } - } -} - static void parse_radio(struct ubus_request *req, int type, struct blob_attr *msg) {