diff --git a/src/cwmp.c b/src/cwmp.c index b25a693..ac036df 100644 --- a/src/cwmp.c +++ b/src/cwmp.c @@ -305,6 +305,8 @@ int main(int argc, char **argv) return error; } + cwmp_initiate_get_DM(); + if ((error = create_cwmp_temporary_files())) { icwmp_free_ubus(); return error; diff --git a/src/ubus_utils.c b/src/ubus_utils.c index ffc1554..6f52828 100644 --- a/src/ubus_utils.c +++ b/src/ubus_utils.c @@ -33,6 +33,11 @@ struct command_cb { char *help; }; +struct get_result { + struct blob_buf bb; + bool service_added; +}; + static const char *arr_session_status[] = { [SESSION_WAITING] = "waiting", [SESSION_RUNNING] = "running", @@ -702,3 +707,65 @@ void icwmp_free_ubus() ubus_ctx = NULL; } } + +static void ubus_changed_uci_cb(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) +{ + int rem = 0; + struct blob_attr *cur = NULL; + + if (msg == NULL || req == NULL) + return; + + struct blob_attr *tb[1] = {0}; + const struct blobmsg_policy p[1] = { + { "modified_uci", BLOBMSG_TYPE_ARRAY } + }; + + blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg)); + if (!tb[0]) { + return; + } + + struct get_result *res = (struct get_result *)req->priv; + if (res == NULL) { + return; + } + + res->service_added = false; + + void *array = blobmsg_open_array(&res->bb, "services"); + blobmsg_for_each_attr(cur, tb[0], rem) { + char *config_name = blobmsg_get_string(cur); + blobmsg_add_string(&res->bb, NULL, config_name); + res->service_added = true; + } + blobmsg_close_array(&res->bb, array); + blobmsg_add_string(&res->bb, "proto", "cwmp"); +} + +void cwmp_initiate_get_DM(void) +{ + struct blob_buf b = {0}; + struct get_result res = {0}; + + CWMP_MEMSET(&res, 0, sizeof(struct get_result)); + blob_buf_init(&res.bb, 0); + + CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); + blob_buf_init(&b, 0); + bb_add_string(&b, "path", "Device."); + + void *table = blobmsg_open_table(&b, "optional"); + bb_add_string(&b, "proto", "cwmp"); + bb_add_string(&b, "format", "raw"); + blobmsg_close_table(&b, table); + + icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "get", b.head, ubus_changed_uci_cb, &res); + blob_buf_free(&b); + + if (res.service_added) { + icwmp_ubus_invoke("bbf.config", "commit", res.bb.head, NULL, NULL); + } + + blob_buf_free(&res.bb); +} diff --git a/src/ubus_utils.h b/src/ubus_utils.h index 6bd5bc5..bcde36d 100644 --- a/src/ubus_utils.h +++ b/src/ubus_utils.h @@ -34,4 +34,5 @@ void clean_interface_update(void); int icwmp_connect_ubus(void); int wait_for_bbf_object(void); void icwmp_free_ubus(void); +void cwmp_initiate_get_DM(void); #endif /* __ICWMP_UBUS_UTILS_H__ */