diff --git a/README.md b/README.md index d2d3375a0121e84589249006a29aba9adcf8887c..5e999cb49a33e4b99c632a023230c767f3d5865c 100644 --- a/README.md +++ b/README.md @@ -1023,7 +1023,7 @@ root@iopsys:~# ubus call usp.raw list_inform ] } -root@iopsys:~# ubus call usp.raw init_notify '{"proto":"cwmp", "amd_version":5, "instance_mode": 0}' +root@iopsys:~# ubus call usp.raw list_notify '{"instance_mode": 0}' root@iopsys:~# root@iopsys:~# ubus call usp set '{"path":"Device.Users.User.[Username==\"xyz1\"].", "values":{"Username":"xyz1", "Enable":"dummy", "Password":"yzssssx"}, "proto":"usp"}' { diff --git a/src/get_helper.c b/src/get_helper.c index 43dcb062ba7f3502e48dd702a76013c4f1004aa2..3c1794c7c6feba8b1be307211d2e59a345739807 100644 --- a/src/get_helper.c +++ b/src/get_helper.c @@ -1669,6 +1669,38 @@ int bbf_dm_list_operate(struct dmctx *bbf_ctx) return fault; } +int bbf_dm_list_notify(struct blob_buf *bb, int instance_mode) +{ + int fault = 0; + struct dmctx bbf_ctx = {0}; + void *array, *table; + struct dm_parameter *dm_parameter = NULL; + + memset(&bbf_ctx, 0, sizeof(struct dmctx)); + set_bbfdatamodel_type(BBFDM_CWMP); + bbf_init(&bbf_ctx, instance_mode); + + fault = usp_dm_exec(&bbf_ctx, CMD_LIST_NOTIFY, ROOT_NODE, NULL, NULL); + if(fault) { + ERR("Failed to list notify parameters"); + return fault; + } + array = blobmsg_open_array(bb, "parameters"); + while (bbf_ctx.list_parameter.next != &bbf_ctx.list_parameter) { + dm_parameter = list_entry(bbf_ctx.list_parameter.next, struct dm_parameter, list); + table = blobmsg_open_table(bb, NULL); + bb_add_string(bb, "parameter", dm_parameter->name); + bb_add_string(bb, "value", dm_parameter->data); + bb_add_string(bb, "notification", dm_parameter->notification?dm_parameter->notification:"0"); + bb_add_string(bb, "type", dm_parameter->type); + blobmsg_close_table(bb, table); + del_list_parameter(dm_parameter); + } + blobmsg_close_array(bb, array); + bbf_cleanup(&bbf_ctx); + return 0; +} + bool get_granural_object_paths(struct list_head *path_list, uint8_t maxdepth) { uint8_t count; diff --git a/src/get_helper.h b/src/get_helper.h index 9820534e7ce19eb0e0fb5e6774626e571454deca..4dfbdf641407ae648a271d6bad80c9c8b8fe51b7 100644 --- a/src/get_helper.h +++ b/src/get_helper.h @@ -50,6 +50,7 @@ bool get_granural_object_paths(struct list_head *path_list, int bbf_dm_get_values(struct dmctx *bbf_ctx, char *path); int bbf_dm_get_schema(struct blob_buf *bb); int bbf_dm_get_names(struct dmctx *bbf_ctx, char *path, char *next); +int bbf_dm_list_notify(struct blob_buf *bb, int instance_mode); int bbf_dm_list_operate(struct dmctx *bbf_ctx); void list_inform_params(struct blob_buf *bb); diff --git a/src/usp.c b/src/usp.c index 5e3e7cffd7cd48082f87eb0d140df73aab69ec5e..243210a61aa55f279d8fd98a1dfe9446eac3c4f3 100644 --- a/src/usp.c +++ b/src/usp.c @@ -56,10 +56,8 @@ struct blob_buf g_schema_bb; LIST_HEAD(g_ubus_obj_list); enum { - DM_INIT_NOTIFY_PROTO, - DM_INIT_NOTIFY_AMD, - DM_INIT_NOTIFY_INSTANCE, - __DM_INIT_NOTIFY_MAX, + DM_LIST_NOTIFY_INSTANCE, + __DM_LIST_NOTIFY_MAX, }; struct obNode { @@ -795,41 +793,38 @@ int usp_list_operate(struct ubus_context *actx, struct ubus_object *obj, return 0; } -static const struct blobmsg_policy dm_init_notify_policy[] = { - [DM_INIT_NOTIFY_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING }, - [DM_INIT_NOTIFY_AMD] = { .name = "amd_version", .type = BLOBMSG_TYPE_INT32 }, - [DM_INIT_NOTIFY_INSTANCE] = { .name = "instance_mode", .type = BLOBMSG_TYPE_INT32 }, +static const struct blobmsg_policy dm_list_notify_policy[] = { + [DM_LIST_NOTIFY_INSTANCE] = { .name = "instance_mode", .type = BLOBMSG_TYPE_INT32 }, }; -int usp_init_notify_file(__attribute__((unused)) struct ubus_context *ctx, +int usp_list_notify(__attribute__((unused)) struct ubus_context *ctx, struct ubus_object *obj, __attribute__((unused)) struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - int proto, amd, instance; - struct blob_attr *tb[__DM_INIT_NOTIFY_MAX] = {NULL}; + int instance ; + struct blob_attr *tb[__DM_LIST_NOTIFY_MAX] = {NULL}; + struct blob_buf bb; - if (blobmsg_parse(dm_init_notify_policy, __DM_INIT_NOTIFY_MAX, tb, blob_data(msg), blob_len(msg))) { + if (blobmsg_parse(dm_list_notify_policy, __DM_LIST_NOTIFY_MAX, tb, blob_data(msg), blob_len(msg))) { ERR("Failed to parse blob"); return UBUS_STATUS_UNKNOWN_ERROR; } - if (!tb[DM_INIT_NOTIFY_PROTO] || - !tb[DM_INIT_NOTIFY_AMD]) - return UBUS_STATUS_INVALID_ARGUMENT; - INFO("ubus method|%s|, name|%s|", method, obj->name); - proto = get_bbf_proto_type(tb[DM_INIT_NOTIFY_PROTO]); - amd = blobmsg_get_u32(tb[DM_INIT_NOTIFY_AMD]); - instance = get_instance_mode(tb[DM_INIT_NOTIFY_INSTANCE]); - - DEBUG("proto(%zd), amd(%zd), instance(%zd)", proto, amd, instance); - dmbbf_update_enabled_notify_file(proto, amd, instance); - - DEBUG("init of notify file done"); + instance = get_instance_mode(tb[DM_LIST_NOTIFY_INSTANCE]); + memset(&bb, 0, sizeof(struct blob_buf)); + blob_buf_init(&bb, 0); + if(bbf_dm_list_notify(&bb, instance)) { + blob_buf_free(&bb); + return UBUS_STATUS_UNKNOWN_ERROR; + } + DEBUG("init of notify list done"); + ubus_send_reply(ctx, req, bb.head); + blob_buf_free(&bb); return 0; } @@ -973,7 +968,7 @@ static struct ubus_method usp_raw_methods[] = { UBUS_METHOD("getm_attributes", usp_get_attributes, dm_get_safe_policy), UBUS_METHOD("setm_attributes", usp_set_safe_attributes, dm_sets_policy), UBUS_METHOD("setm_values", handle_set_multi_value, dm_set_multi_policy), - UBUS_METHOD("init_notify", usp_init_notify_file, dm_init_notify_policy), + UBUS_METHOD("list_notify", usp_list_notify, dm_list_notify_policy), UBUS_METHOD_NOARG("transaction_start", usp_transaction_start), UBUS_METHOD_NOARG("transaction_commit", usp_transaction_commit), UBUS_METHOD_NOARG("transaction_abort", usp_transaction_abort),