T#14683: reduce cpu usages

This commit is contained in:
Amin Ben Romdhane 2024-08-07 11:12:13 +00:00 committed by IOPSYS Dev
parent 3a3b00b8e4
commit 75195a112e
No known key found for this signature in database
31 changed files with 995 additions and 1109 deletions

View file

@ -94,7 +94,6 @@ static void bbfdm_cleanup(struct bbfdm_context *u)
free_services_from_list(&head_registered_service);
}
blob_buf_free(&u->dm_schema);
/* DotSo Plugin */
free_dotso_plugin(deamon_lib_handle);
deamon_lib_handle = NULL;
@ -258,9 +257,11 @@ err_out:
static bool is_object_schema_update_available(struct bbfdm_context *u)
{
size_t ll, min_len;
bool ret = false;
LIST_HEAD(paths_list);
bbfdm_data_t data = {
.ctx = 0,
.req = 0,
.is_raw = true,
.plist = &paths_list,
.bbf_ctx.nextlevel = false,
@ -270,27 +271,22 @@ static bool is_object_schema_update_available(struct bbfdm_context *u)
.bbf_ctx.dm_type = BBFDM_USP
};
memset(&data.bb, 0, sizeof(struct blob_buf));
int schema_len = blobmsg_len(u->dm_schema.head);
blob_buf_free(&u->dm_schema);
blob_buf_init(&u->dm_schema, 0);
data.bbp = &u->dm_schema;
int old_schema_len = u->schema_len;
// If new parameter gets added it would be a minimum tuple of three params
min_len = 100;
int min_len = 100;
add_path_list(ROOT_NODE, &paths_list);
bool ret = bbf_dm_get_supported_dm(&data);
if (ret != 0) {
int new_schema_len = bbfdm_get_supported_dm(&data);
if (new_schema_len == 0) {
WARNING("Failed to get schema");
free_path_list(&paths_list);
return ret;
}
ll = blobmsg_len(data.bbp->head);
if (ll - schema_len > min_len) {
DEBUG("DM Schema update available old:new[%zd:%zd]", schema_len, ll);
if (schema_len != 0) {
if (new_schema_len - old_schema_len > min_len) {
DEBUG("DM Schema update available old:new[%zd:%zd]", old_schema_len, new_schema_len);
if (old_schema_len != 0) {
ret = true;
}
}
@ -429,27 +425,24 @@ static int bbfdm_schema_handler(struct ubus_context *ctx, struct ubus_object *ob
unsigned int dm_type = data.bbf_ctx.dm_type;
data.ctx = ctx;
data.req = req;
data.bbf_ctx.nextlevel = (tb[DM_SCHEMA_FIRST_LEVEL]) ? blobmsg_get_bool(tb[DM_SCHEMA_FIRST_LEVEL]) : false;
data.bbf_ctx.iscommand = (dm_type == BBFDM_CWMP) ? false : true;
data.bbf_ctx.isevent = (dm_type == BBFDM_CWMP) ? false : true;
data.bbf_ctx.isinfo = (dm_type == BBFDM_CWMP) ? false : true;
data.plist = &paths_list;
blob_buf_init(&data.bb, 0);
#ifdef BBF_SCHEMA_FULL_TREE
data.bbf_ctx.isinfo = true;
bbf_dm_get_supported_dm(&data);
bbfdm_get_supported_dm(&data);
#else
if (dm_type == BBFDM_CWMP)
bbfdm_get_names(&data);
else
get_schema_from_blob(&u->dm_schema, &data);
bbfdm_get_supported_dm(&data);
#endif
ubus_send_reply(ctx, req, data.bb.head);
blob_buf_free(&data.bb);
free_path_list(&paths_list);
return 0;
}
@ -496,16 +489,15 @@ static int bbfdm_instances_handler(struct ubus_context *ctx, struct ubus_object
}
}
data.ctx = ctx;
data.req = req;
data.bbf_ctx.nextlevel = (tb[DM_INSTANCES_FIRST_LEVEL]) ? blobmsg_get_bool(tb[DM_INSTANCES_FIRST_LEVEL]) : false;
data.plist = &paths_list;
fill_optional_data(&data, tb[DM_INSTANCES_OPTIONAL]);
blob_buf_init(&data.bb, 0);
bbfdm_get_instances(&data);
ubus_send_reply(ctx, req, data.bb.head);
blob_buf_free(&data.bb);
free_path_list(&paths_list);
return 0;
}
@ -1187,10 +1179,20 @@ static void update_instances_list(struct list_head *inst)
ret = bbfdm_cmd_exec(&bbf_ctx, BBF_INSTANCES);
if (ret == 0) {
struct dm_parameter *nptr_dp;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(nptr_dp, &bbf_ctx.list_parameter, list) {
add_path_list(nptr_dp->name, inst);
blobmsg_for_each_attr(cur, bbf_ctx.bb.head, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "path", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
add_path_list(name, inst);
}
} else {
WARNING("Failed to get instances, err code %d", ret);
@ -1724,7 +1726,6 @@ static void bbf_config_change_cb(struct ubus_context *ctx, struct ubus_event_han
static void bbfdm_ctx_init(struct bbfdm_context *bbfdm_ctx)
{
memset(bbfdm_ctx, 0, sizeof(struct bbfdm_context));
blob_buf_init(&bbfdm_ctx->dm_schema, 0);
INIT_LIST_HEAD(&bbfdm_ctx->instances);
INIT_LIST_HEAD(&bbfdm_ctx->old_instances);
INIT_LIST_HEAD(&bbfdm_ctx->event_handlers);

View file

@ -40,11 +40,11 @@ typedef struct bbfdm_config {
struct bbfdm_context {
bbfdm_config_t config;
struct ubus_context ubus_ctx;
struct blob_buf dm_schema;
struct uloop_timeout instance_timer;
struct list_head event_handlers;
struct list_head instances;
struct list_head old_instances;
int schema_len;
};
struct ev_handler_node {
@ -59,7 +59,6 @@ typedef struct bbfdm_data {
struct ubus_request_data *req;
struct list_head *plist;
struct dmctx bbf_ctx;
struct blob_buf *bbp;
struct blob_buf bb;
uint8_t depth;
bool is_raw;

View file

@ -263,10 +263,22 @@ static int in_dotso_out_cli_exec_get(cli_data_t *cli_data, char *argv[])
err = bbf_entry_method(&cli_data->bbf_ctx, BBF_GET_VALUE);
if (!err) {
struct dm_parameter *n;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(n, &cli_data->bbf_ctx.list_parameter, list) {
printf("%s => %s\n", n->name, n->data);
blobmsg_for_each_attr(cur, cli_data->bbf_ctx.bb.head, rem) {
struct blob_attr *tb[2] = {0};
const struct blobmsg_policy p[2] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 2, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
printf("%s => %s\n", name, data);
}
dmuci_commit_bbfdm();
} else {
@ -421,10 +433,18 @@ static int in_dotso_out_cli_exec_instances(cli_data_t *cli_data, char *argv[])
err = bbf_entry_method(&cli_data->bbf_ctx, BBF_INSTANCES);
if (!err) {
struct dm_parameter *n;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(n, &cli_data->bbf_ctx.list_parameter, list) {
printf("%s\n", n->name);
blobmsg_for_each_attr(cur, cli_data->bbf_ctx.bb.head, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "path", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
printf("%s\n", (tb[0]) ? blobmsg_get_string(tb[0]) : "");
}
} else {
printf("ERROR: %d retrieving %s\n", err, cli_data->bbf_ctx.in_param);
@ -465,11 +485,25 @@ static int in_dotso_out_cli_exec_schema(cli_data_t *cli_data, char *argv[])
err = bbf_entry_method(&cli_data->bbf_ctx, BBF_SCHEMA);
if (!err) {
struct dm_parameter *n;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(n, &cli_data->bbf_ctx.list_parameter, list) {
int cmd = get_dm_type(n->type);
printf("%s %s %s\n", n->name, n->type, (cmd != DMT_EVENT && cmd != DMT_COMMAND) ? n->data : "0");
blobmsg_for_each_attr(cur, cli_data->bbf_ctx.bb.head, rem) {
struct blob_attr *tb[3] = {0};
const struct blobmsg_policy p[3] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
char *type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
int cmd = get_dm_type(type);
printf("%s %s %s\n", name, type, (cmd != DMT_EVENT && cmd != DMT_COMMAND) ? data : "0");
}
} else {
printf("ERROR: %d retrieving %s\n", err, cli_data->bbf_ctx.in_param);

View file

@ -135,12 +135,12 @@ int count_delim(const char *path)
bool validate_msglen(bbfdm_data_t *data)
{
size_t data_len = blob_pad_len(data->bb.head);
size_t data_len = blob_pad_len(data->bbf_ctx.bb.head);
if (data_len >= DEF_IPC_DATA_LEN) {
ERR("Blob exceed max len(%zd), data len(%zd)", DEF_IPC_DATA_LEN, data_len);
blob_buf_free(&data->bb);
blob_buf_init(&data->bb, 0);
blob_buf_free(&data->bbf_ctx.bb);
blob_buf_init(&data->bbf_ctx.bb, 0);
fill_err_code_table(data, FAULT_9002);
return false;
}

View file

@ -130,12 +130,22 @@ int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list)
bbf_init(&bbf_ctx);
if (0 == bbfdm_cmd_exec(&bbf_ctx, BBF_SCHEMA)) {
struct dm_parameter *param;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(param, &bbf_ctx.list_parameter, list) {
event_args *event = (event_args *)param->data;
blobmsg_for_each_attr(cur, bbf_ctx.bb.head, rem) {
struct blob_attr *tb[2] = {0};
const struct blobmsg_policy p[2] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING }
};
if (!param->name || !event || !event->name || !strlen(event->name))
blobmsg_parse(p, 2, tb, blobmsg_data(cur), blobmsg_len(cur));
char *param_name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *event_name = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
if (!param_name || !event_name || !strlen(event_name))
continue;
struct ubus_event_handler *ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler));
@ -148,13 +158,13 @@ int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list)
memset(ev, 0, sizeof(struct ubus_event_handler));
ev->cb = bbfdm_event_handler;
if (0 != ubus_register_event_handler(ctx, ev, event->name)) {
ERR("Failed to register: %s", event->name);
if (0 != ubus_register_event_handler(ctx, ev, event_name)) {
ERR("Failed to register: %s", event_name);
err = -1;
goto end;
}
add_ubus_event_handler(ev, event->name, param->name, ev_list);
add_ubus_event_handler(ev, event_name, param_name, ev_list);
}
}

View file

@ -137,14 +137,24 @@ static bool get_next_param(char *qPath, size_t *pos, char *param)
static bool is_present_in_datamodel(struct dmctx *bbf_ctx, char *path)
{
struct blob_attr *cur = NULL;
size_t plen = 0, rem = 0;
bool found = false;
struct dm_parameter *n;
size_t plen;
DEBUG("path(%s)", path);
plen = DM_STRLEN(path);
list_for_each_entry(n, &bbf_ctx->list_parameter, list) {
if (strncmp(n->name, path, plen) == 0) {
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "path", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
if (strncmp(name, path, plen) == 0) {
found = true;
break;
}
@ -630,9 +640,9 @@ static int search_n_apply(char *bPath, char *para, enum operation oper, char *va
static int solve_all_filters(struct dmctx *bbf_ctx, char *bPath, char *param, struct list_head *resolved_plist)
{
char *token, *save;
struct dm_parameter *n;
size_t blen;
struct blob_attr *cur = NULL;
char *token = NULL, *save = NULL;
size_t blen = 0, rem = 0;
int ret = 0;
LIST_HEAD(pv_local);
@ -642,9 +652,23 @@ static int solve_all_filters(struct dmctx *bbf_ctx, char *bPath, char *param, st
// Use shorter list for rest of the operation
blen = DM_STRLEN(bPath);
list_for_each_entry(n, &bbf_ctx->list_parameter, list) {
if (strncmp(n->name, bPath, blen) == 0) {
add_pv_list(n->name, n->data, n->type, &pv_local);
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
struct blob_attr *tb[3] = {0};
const struct blobmsg_policy p[3] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
char *type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
if (strncmp(name, bPath, blen) == 0) {
add_pv_list(name, data, type, &pv_local);
}
}
@ -846,9 +870,8 @@ void bbfdm_get_value(bbfdm_data_t *data, void *output)
if (data->is_raw)
blobmsg_close_array(&data->bb, array);
if (!validate_msglen(data)) {
if (!validate_msglen(data))
ERR("IPC failed for path(%s)", data->bbf_ctx.in_param);
}
if (output)
memcpy(output, data->bb.head, blob_pad_len(data->bb.head));
@ -862,12 +885,12 @@ void bbfdm_get_value(bbfdm_data_t *data, void *output)
void bbfdm_get_names(bbfdm_data_t *data)
{
struct pathNode *pn = NULL;
int fault = 0;
struct pathNode *pn;
bbf_init(&data->bbf_ctx);
void *array = blobmsg_open_array(&data->bb, "results");
void *array = blobmsg_open_array(&data->bbf_ctx.bb, "results");
list_for_each_entry(pn, data->plist, list) {
bbf_sub_init(&data->bbf_ctx);
@ -876,37 +899,32 @@ void bbfdm_get_names(bbfdm_data_t *data)
fault = bbfdm_cmd_exec(&data->bbf_ctx, BBF_GET_NAME);
if (fault) {
fill_err_code_table(data, fault);
} else {
struct dm_parameter *n = NULL;
void *table = NULL;
list_for_each_entry(n, &data->bbf_ctx.list_parameter, list) {
table = blobmsg_open_table(&data->bb, NULL);
blobmsg_add_string(&data->bb, "path", n->name);
blobmsg_add_string(&data->bb, "data", n->data);
blobmsg_add_string(&data->bb, "type", n->type);
blobmsg_add_string(&data->bb, "info", n->additional_data ? n->additional_data : "");
blobmsg_close_table(&data->bb, table);
}
void *table = blobmsg_open_table(&data->bbf_ctx.bb, NULL);
blobmsg_add_string(&data->bbf_ctx.bb, "path", data->bbf_ctx.in_param ? data->bbf_ctx.in_param : "");
blobmsg_add_u32(&data->bbf_ctx.bb, "fault", bbf_fault_map(&data->bbf_ctx, fault));
bb_add_string(&data->bbf_ctx.bb, "fault_msg", data->bbf_ctx.fault_msg);
blobmsg_close_table(&data->bbf_ctx.bb, table);
}
bbf_sub_cleanup(&data->bbf_ctx);
}
blobmsg_close_array(&data->bb, array);
blobmsg_close_array(&data->bbf_ctx.bb, array);
if (data->ctx && data->req)
ubus_send_reply(data->ctx, data->req, data->bbf_ctx.bb.head);
bbf_cleanup(&data->bbf_ctx);
}
void bbfdm_get_instances(bbfdm_data_t *data)
{
struct pathNode *pn = NULL;
int fault = 0;
struct pathNode *pn;
bbf_init(&data->bbf_ctx);
void *array = blobmsg_open_array(&data->bb, "results");
void *array = blobmsg_open_array(&data->bbf_ctx.bb, "results");
list_for_each_entry(pn, data->plist, list) {
bbf_sub_init(&data->bbf_ctx);
@ -915,192 +933,33 @@ void bbfdm_get_instances(bbfdm_data_t *data)
fault = bbfdm_cmd_exec(&data->bbf_ctx, BBF_INSTANCES);
if (fault) {
fill_err_code_table(data, fault);
} else {
struct dm_parameter *n;
list_for_each_entry(n, &data->bbf_ctx.list_parameter, list) {
void *table = blobmsg_open_table(&data->bb, NULL);
blobmsg_add_string(&data->bb, "path", n->name);
blobmsg_close_table(&data->bb, table);
}
void *table = blobmsg_open_table(&data->bbf_ctx.bb, NULL);
blobmsg_add_string(&data->bbf_ctx.bb, "path", data->bbf_ctx.in_param ? data->bbf_ctx.in_param : "");
blobmsg_add_u32(&data->bbf_ctx.bb, "fault", bbf_fault_map(&data->bbf_ctx, fault));
bb_add_string(&data->bbf_ctx.bb, "fault_msg", data->bbf_ctx.fault_msg);
blobmsg_close_table(&data->bbf_ctx.bb, table);
}
bbf_sub_cleanup(&data->bbf_ctx);
}
blobmsg_close_array(&data->bb, array);
blobmsg_close_array(&data->bbf_ctx.bb, array);
if (data->ctx && data->req)
ubus_send_reply(data->ctx, data->req, data->bbf_ctx.bb.head);
bbf_cleanup(&data->bbf_ctx);
}
static void fill_operate_schema(struct blob_buf *bb, struct dm_parameter *param)
int bbfdm_get_supported_dm(bbfdm_data_t *data)
{
blobmsg_add_string(bb, "path", param->name);
blobmsg_add_string(bb, "type", param->type);
blobmsg_add_string(bb, "data", param->additional_data);
if (param->data) {
void *array, *table;
const char **in, **out;
operation_args *args;
int i;
args = (operation_args *) param->data;
in = args->in;
if (in) {
array = blobmsg_open_array(bb, "input");
for (i = 0; in[i] != NULL; i++) {
table = blobmsg_open_table(bb, NULL);
blobmsg_add_string(bb, "path", in[i]);
blobmsg_close_table(bb, table);
}
blobmsg_close_array(bb, array);
}
out = args->out;
if (out) {
array = blobmsg_open_array(bb, "output");
for (i = 0; out[i] != NULL; i++) {
table = blobmsg_open_table(bb, NULL);
blobmsg_add_string(bb, "path", out[i]);
blobmsg_close_table(bb, table);
}
blobmsg_close_array(bb, array);
}
}
}
static void fill_event_schema(struct blob_buf *bb, struct dm_parameter *param)
{
blobmsg_add_string(bb, "path", param->name);
blobmsg_add_string(bb, "type", param->type);
if (param->data) {
event_args *ev;
void *table;
ev = (event_args *)param->data;
if (ev->param) {
const char **in = ev->param;
void *key = blobmsg_open_array(bb, "input");
for (int i = 0; in[i] != NULL; i++) {
table = blobmsg_open_table(bb, NULL);
blobmsg_add_string(bb, "path", in[i]);
blobmsg_close_table(bb, table);
}
blobmsg_close_array(bb, key);
}
}
}
static void fill_param_schema(struct blob_buf *bb, struct dm_parameter *param)
{
bb_add_string(bb, "path", param->name);
bb_add_string(bb, "data", param->data ? param->data : "0");
bb_add_string(bb, "type", param->type);
bb_add_flags_arr(bb, param->additional_data);
}
struct blob_attr *get_parameters(struct blob_attr *msg, const char *key)
{
struct blob_attr *params = NULL;
struct blob_attr *cur;
int rem;
blobmsg_for_each_attr(cur, msg, rem) {
const char *name = blobmsg_name(cur);
if (strcmp(key, name) == 0) {
params = cur;
break;
}
}
return params;
}
bool valid_entry(bbfdm_data_t *data, struct blob_attr *input)
{
bool ret = false;
struct blob_attr *p;
char *name;
size_t len;
struct pathNode *pn;
p = get_parameters(input, "path");
if (p) {
name = blobmsg_get_string(p);
list_for_each_entry(pn, data->plist, list) {
len = strlen(pn->path);
if (pn->path[len - 1] != '.') {
continue;
}
if (strncmp(pn->path, name, len) == 0) {
ret = true;
break;
}
}
}
return ret;
}
void get_schema_from_blob(struct blob_buf *schema_bp, bbfdm_data_t *data)
{
struct blob_buf *bp = &data->bb;
struct blob_attr *schema_blob = NULL;
struct blob_attr *params;
struct blob_attr *cur;
size_t rem = 0;
void *array = blobmsg_open_array(bp, "results");
schema_blob = blob_memdup(schema_bp->head);
if (schema_blob == NULL) {
goto end;
}
params = get_parameters(schema_blob, "results");
if (params == NULL) {
goto end;
}
blobmsg_for_each_attr(cur, params, rem) {
if (valid_entry(data, cur)) {
blobmsg_add_blob(bp, cur);
}
}
end:
blobmsg_close_array(bp, array);
FREE(schema_blob);
}
int bbf_dm_get_supported_dm(bbfdm_data_t *data)
{
struct dm_parameter *param;
struct pathNode *pn;
struct pathNode *pn = NULL;
int schema_len = 0;
int fault = 0;
struct blob_buf *bp;
bbf_init(&data->bbf_ctx);
if (data->bbp) {
bp = data->bbp;
} else {
bp = &data->bb;
}
void *array = blobmsg_open_array(bp, "results");
void *array = blobmsg_open_array(&data->bbf_ctx.bb, "results");
list_for_each_entry(pn, data->plist, list) {
bbf_sub_init(&data->bbf_ctx);
@ -1109,30 +968,24 @@ int bbf_dm_get_supported_dm(bbfdm_data_t *data)
fault = bbfdm_cmd_exec(&data->bbf_ctx, BBF_SCHEMA);
if (fault) {
fill_err_code_table(data, fault);
} else {
INFO("Preparing result for(%s)", data->bbf_ctx.in_param);
list_for_each_entry(param, &data->bbf_ctx.list_parameter, list) {
int cmd = get_dm_type(param->type);
void *table = blobmsg_open_table(bp, NULL);
if (cmd == DMT_COMMAND) {
fill_operate_schema(bp, param);
} else if (cmd == DMT_EVENT) {
fill_event_schema(bp, param);
} else {
fill_param_schema(bp, param);
}
blobmsg_close_table(bp, table);
}
void *table = blobmsg_open_table(&data->bbf_ctx.bb, NULL);
blobmsg_add_string(&data->bbf_ctx.bb, "path", data->bbf_ctx.in_param ? data->bbf_ctx.in_param : "");
blobmsg_add_u32(&data->bbf_ctx.bb, "fault", bbf_fault_map(&data->bbf_ctx, fault));
bb_add_string(&data->bbf_ctx.bb, "fault_msg", data->bbf_ctx.fault_msg);
blobmsg_close_table(&data->bbf_ctx.bb, table);
}
bbf_sub_cleanup(&data->bbf_ctx);
}
blobmsg_close_array(bp, array);
blobmsg_close_array(&data->bbf_ctx.bb, array);
schema_len = blobmsg_len(data->bbf_ctx.bb.head);
if (data->ctx && data->req)
ubus_send_reply(data->ctx, data->req, data->bbf_ctx.bb.head);
bbf_cleanup(&data->bbf_ctx);
return fault;
return schema_len;
}

View file

@ -34,7 +34,6 @@ void bbfdm_get_names(bbfdm_data_t *data);
void bbfdm_get_instances(bbfdm_data_t *data);
int bbf_dm_get_supported_dm(bbfdm_data_t *data);
int bbfdm_get_supported_dm(bbfdm_data_t *data);
void get_schema_from_blob(struct blob_buf *schema_bp, bbfdm_data_t *data);
#endif /* GET_H */

View file

@ -94,27 +94,6 @@ void bbf_sub_cleanup(struct dmctx *dm_ctx)
bbf_ctx_clean_sub(dm_ctx);
}
void bb_add_flags_arr(struct blob_buf *bb, char *data)
{
uint32_t *dm_falgs = (uint32_t *)data;
if (!bb || !dm_falgs)
return;
void *flags_arr = blobmsg_open_array(bb, "flags");
if (*dm_falgs & DM_FLAG_REFERENCE)
bb_add_string(bb, NULL, "Reference");
if (*dm_falgs & DM_FLAG_UNIQUE)
bb_add_string(bb, NULL, "Unique");
if (*dm_falgs & DM_FLAG_LINKER)
bb_add_string(bb, NULL, "Linker");
if (*dm_falgs & DM_FLAG_SECURE)
bb_add_string(bb, NULL, "Secure");
blobmsg_close_array(bb, flags_arr);
}
bool present_in_path_list(struct list_head *plist, char *entry)
{
struct pathNode *pos;

View file

@ -40,8 +40,6 @@ void fill_err_code_array(bbfdm_data_t *data, int fault);
void bb_add_string(struct blob_buf *bb, const char *name, const char *value);
void bb_add_flags_arr(struct blob_buf *bb, char *data);
int transaction_start(bbfdm_data_t *data, char *app, uint32_t max_timeout);
int transaction_commit(bbfdm_data_t *data, int trans_id, bool is_service_restart);
int transaction_abort(bbfdm_data_t *data, int trans_id);

View file

@ -56,9 +56,9 @@ void bbfdm_operate_cmd(bbfdm_data_t *data, void *output)
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
char *op_name = blobmsg_get_string(tb[0]);
char *op_data = blobmsg_get_string(tb[1]);
char *op_type = blobmsg_get_string(tb[2]);
char *op_name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *op_data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
char *op_type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
add_pv_list(op_name, op_data, op_type, &pv_local);
}

View file

@ -147,7 +147,8 @@ static size_t get_glob_len(char *path)
static void resulting(uint8_t maxdepth, char *path, struct dmctx *bbf_ctx, struct list_head *pv_local)
{
struct dm_parameter *n;
struct blob_attr *cur = NULL;
size_t rem = 0;
uint8_t count;
size_t plen = get_glob_len(bbf_ctx->in_param);
@ -155,17 +156,30 @@ static void resulting(uint8_t maxdepth, char *path, struct dmctx *bbf_ctx, struc
if (path_len == 0)
return;
list_for_each_entry(n, &bbf_ctx->list_parameter, list) {
if (match(n->name, path, 0, NULL)) {
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
struct blob_attr *tb[3] = {0};
const struct blobmsg_policy p[3] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
char *type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
if (match(name, path, 0, NULL)) {
if (is_search_by_reference(bbf_ctx->in_param))
plen = 0;
if (maxdepth > 4 || maxdepth == 0) {
add_pv_list(n->name + plen, n->data, n->type, pv_local);
add_pv_list(name + plen, data, type, pv_local);
} else {
count = count_delim(n->name + path_len);
count = count_delim(name + path_len);
if (count < maxdepth)
add_pv_list(n->name + plen, n->data, n->type, pv_local);
add_pv_list(name + plen, data, type, pv_local);
}
}
}
@ -388,21 +402,25 @@ void prepare_result_blob(struct blob_buf *bb, struct list_head *pv_list)
void prepare_raw_result(struct blob_buf *bb, struct dmctx *bbf_ctx, struct list_head *rslvd)
{
struct pathNode *iter = NULL;
struct dm_parameter *n = NULL;
void *table = NULL;
struct blob_attr *cur = NULL;
size_t rem = 0;
list_for_each_entry(iter, rslvd, list) {
if (DM_STRLEN(iter->path) == 0)
continue;
list_for_each_entry(n, &bbf_ctx->list_parameter, list) {
if (match(n->name, iter->path, 0, NULL)) {
table = blobmsg_open_table(bb, NULL);
bb_add_string(bb, "path", n->name);
bb_add_string(bb, "data", n->data);
bb_add_string(bb, "type", n->type);
bb_add_flags_arr(bb, n->additional_data);
blobmsg_close_table(bb, table);
blobmsg_for_each_attr(cur, bbf_ctx->bb.head, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "path", BLOBMSG_TYPE_STRING }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
if (match(name, iter->path, 0, NULL)) {
blobmsg_add_blob(bb, cur);
}
}
}

View file

@ -42,20 +42,18 @@ int bbfdm_set_value(bbfdm_data_t *data)
return fault;
}
static int set_resolved_paths(unsigned int dm_type, char *path, char *value, struct list_head *pv_list)
static int set_resolved_paths(bbfdm_data_t *data, char *path, char *value, struct list_head *pv_list)
{
int fault = 0;
struct dmctx bbf_ctx = {
.dm_type = dm_type
};
if (!path || !value || !pv_list)
return -1;
LIST_HEAD(resolved_paths);
bbf_sub_init(&bbf_ctx);
bbf_sub_init(&data->bbf_ctx);
fault = get_resolved_paths(&data->bbf_ctx, path, &resolved_paths);
fault = get_resolved_paths(&bbf_ctx, path, &resolved_paths);
if (!fault) {
struct pathNode *p;
@ -64,7 +62,7 @@ static int set_resolved_paths(unsigned int dm_type, char *path, char *value, str
}
}
bbf_sub_cleanup(&bbf_ctx);
bbf_sub_cleanup(&data->bbf_ctx);
free_path_list(&resolved_paths);
return fault;
@ -87,7 +85,7 @@ int fill_pvlist_set(bbfdm_data_t *data, char *param_name, char *param_value, str
if (param_name[plen - 1] == '.')
return USP_FAULT_INVALID_PATH;
fault = set_resolved_paths(data->bbf_ctx.dm_type, param_name, param_value, pv_list);
fault = set_resolved_paths(data, param_name, param_value, pv_list);
if (fault)
return fault;
@ -123,7 +121,7 @@ blob__table:
}
snprintf(path, MAX_DM_PATH, "%s%s", param_name, (char *)hdr->name);
fault = set_resolved_paths(data->bbf_ctx.dm_type, path, value, pv_list);
fault = set_resolved_paths(data, path, value, pv_list);
if (fault)
return fault;
}

View file

@ -202,9 +202,6 @@
"type": "string",
"Description": "Any discrepancy in input will result in fault. The type of fault can be identified by fault code"
},
"info": {
"type": "string"
},
"input": {
"type": "array",
"items": [

View file

@ -1738,9 +1738,6 @@ All items must be of the type: Unknown type ``.
"type": "string",
"Description": "Any discrepancy in input will result in fault. The type of fault can be identified by fault code"
},
"info": {
"type": "string"
},
"input": {
"type": "array",
"items": [
@ -1798,7 +1795,6 @@ All items must be of the type: Unknown type ``.
"type": "xsd:int",
"fault": 8767,
"fault_msg": "cupidatat amet",
"info": "laborum",
"input": [{ "path": "quiselit ad", "data": "0", "type": "xsd:hexBinary" }],
"output": [{ "path": "ipsum do Lorem nulla officia", "data": "0", "type": "xsd:unsignedLong" }]
}

View file

@ -114,12 +114,6 @@
"pretty"
]
},
"instance_mode_t": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 1
},
"trans_id_t": {
"description": "Required for CUD operation, it shall be same number as got from transaction->start",
"type": "integer",
@ -208,9 +202,6 @@
"type": "string",
"Description": "Any discrepancy in input will result in fault. The type of fault can be identified by fault code"
},
"info": {
"type": "string"
},
"input": {
"type": "array",
"items": [
@ -299,9 +290,6 @@
},
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}
@ -370,9 +358,6 @@
"properties": {
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}
@ -593,9 +578,6 @@
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
},
"transaction_id": {
"$ref": "#/definitions/trans_id_t"
}
@ -674,9 +656,6 @@
},
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}

View file

@ -509,7 +509,6 @@ Integer to decide the depth of data model to be parsed
| Property | Type | Required | Default |
| --------------- | ------- | -------- | ---------- |
| `format` | string | Optional | `"pretty"` |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### format
@ -533,21 +532,6 @@ The value of this property **must** be equal to one of the [known values below](
| raw |
| pretty |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -637,7 +621,7 @@ All items must be of the type: Unknown type ``.
### Ubus CLI Example
```
ubus call bbf get {"path":"officia","paths":["aliqua nisi sunt"],"maxdepth":-49153948,"optional":{"format":"raw","proto":"cwmp","instance_mode":0}}
ubus call bbf get {"path":"officia","paths":["aliqua nisi sunt"],"maxdepth":-49153948,"optional":{"format":"raw","proto":"cwmp"}}
```
### JSONRPC Example
@ -655,7 +639,7 @@ ubus call bbf get {"path":"officia","paths":["aliqua nisi sunt"],"maxdepth":-491
"path": "officia",
"paths": ["aliqua nisi sunt"],
"maxdepth": -49153948,
"optional": { "format": "raw", "proto": "cwmp", "instance_mode": 0 }
"optional": { "format": "raw", "proto": "cwmp" }
}
]
}
@ -799,24 +783,8 @@ gets only first level objects if true
| Property | Type | Required | Default |
| --------------- | ------- | -------- | -------- |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -880,7 +848,7 @@ Device.WiFi.
### Ubus CLI Example
```
ubus call bbf instances {"path":"id aliquip","first_level":false,"optional":{"proto":"usp","instance_mode":1}}
ubus call bbf instances {"path":"id aliquip","first_level":false,"optional":{"proto":"usp"}}
```
### JSONRPC Example
@ -894,7 +862,7 @@ ubus call bbf instances {"path":"id aliquip","first_level":false,"optional":{"pr
"<SID>",
"bbf",
"instances",
{ "path": "id aliquip", "first_level": false, "optional": { "proto": "usp", "instance_mode": 1 } }
{ "path": "id aliquip", "first_level": false, "optional": { "proto": "usp" } }
]
}
```
@ -1074,7 +1042,6 @@ Input arguments for the operate command as defined in TR-181-2.13
| Property | Type | Required | Default |
| --------------- | ------- | -------- | ---------- |
| `format` | string | Optional | `"pretty"` |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### format
@ -1098,21 +1065,6 @@ The value of this property **must** be equal to one of the [known values below](
| raw |
| pretty |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -1138,7 +1090,7 @@ The value of this property **must** be equal to one of the [known values below](
### Ubus CLI Example
```
ubus call bbf operate {"command":"et sit dolor","command_key":"nulla velit ut in Excepteur","input":{},"optional":{"format":"raw","proto":"both","instance_mode":0}}
ubus call bbf operate {"command":"et sit dolor","command_key":"nulla velit ut in Excepteur","input":{},"optional":{"format":"raw","proto":"both"}}
```
### JSONRPC Example
@ -1156,7 +1108,7 @@ ubus call bbf operate {"command":"et sit dolor","command_key":"nulla velit ut in
"command": "et sit dolor",
"command_key": "nulla velit ut in Excepteur",
"input": {},
"optional": { "format": "raw", "proto": "both", "instance_mode": 0 }
"optional": { "format": "raw", "proto": "both" }
}
]
}
@ -1529,9 +1481,6 @@ All items must be of the type: Unknown type ``.
"type": "string",
"Description": "Any discrepancy in input will result in fault. The type of fault can be identified by fault code"
},
"info": {
"type": "string"
},
"input": {
"type": "array",
"items": [
@ -1589,7 +1538,6 @@ All items must be of the type: Unknown type ``.
"type": "xsd:dateTime",
"fault": 7546,
"fault_msg": "cupidatat Excepteur",
"info": "ullamco dolor occaecat",
"input": [{ "path": "minim pariatur id laboris ut", "data": "1", "type": "xsd:unsignedInt" }],
"output": [{ "path": "ea enim Excepteur proident est", "data": "1", "type": "xsd:long" }]
}
@ -1674,25 +1622,9 @@ To set multiple values at once, path should be relative to object elements
| Property | Type | Required | Default |
| ---------------- | ------- | -------- | -------- |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
| `transaction_id` | integer | Optional | |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -1798,7 +1730,7 @@ value of the object element provided in path, path should contains valid writabl
### Ubus CLI Example
```
ubus call bbf set {"path":"nonmagna ut anim","value":"cupidatat","optional":{"proto":"usp","instance_mode":0,"transaction_id":45864115},"obj_path":{}}
ubus call bbf set {"path":"nonmagna ut anim","value":"cupidatat","optional":{"proto":"usp","transaction_id":45864115},"obj_path":{}}
```
### JSONRPC Example
@ -1815,7 +1747,7 @@ ubus call bbf set {"path":"nonmagna ut anim","value":"cupidatat","optional":{"pr
{
"path": "nonmagna ut anim",
"value": "cupidatat",
"optional": { "proto": "usp", "instance_mode": 0, "transaction_id": 45864115 },
"optional": { "proto": "usp", "transaction_id": 45864115 },
"obj_path": {}
}
]

View file

@ -119,7 +119,7 @@ Each leaf in the **DMLEAF** table can be a **Parameter**, **Command** or **Event
| `getvalue` | The function which return the value of this parameter |
| `setvalue` | The function which set the value of this parameter |
| `bbfdm_type` | The bbfdm type of the parameter. Could be **BBFDM_CWMP**, **BBFDM_USP**, **BBFDM_BOTH** or **BBFDM_NONE**.If it's **BBFDM_BOTH** then we can see this parameter in all protocols (CWMP, USP,...) |
| `dm_falgs` | An enumeration value used to specify the displayed parameter value. Could be **DM_FLAG_REFERENCE**, **DM_FLAG_UNIQUE**, **DM_FLAG_LINKER** or **DM_FLAG_SECURE**. |
| `dm_flags` | An enumeration value used to specify the displayed parameter value. Could be **DM_FLAG_REFERENCE**, **DM_FLAG_UNIQUE**, **DM_FLAG_LINKER** or **DM_FLAG_SECURE**. |
#### 2.Command definition

View file

@ -155,13 +155,11 @@ Each datamodel micro-service expose their own ubus object, which is slightly dif
> Note1: `optional` table are present in all methods and it supports below options:
```console
"optional":{"proto":"String", "instance_mode":"Integer", "transaction_id":"Integer", "format":"String"}
"optional":{"proto":"String", "transaction_id":"Integer", "format":"String"}
```
- `proto` in each method specify the data-model prototype('cwmp', 'usp') to use, if not provided default data-model will be used.
- `instance_mode` could be 0 or 1, for instance number, instance alias respectively.
- `transaction_id` to define the transaction id number.
- `format` could be 'raw' or 'pretty', to specify the format to use as output, if not provided 'pretty' format will be used.
@ -327,6 +325,7 @@ In Devices, datamodel micro-services started and managed by `/etc/init.d/bbfdm.s
> In plugins approach, the 3rd party datamodel gets attached to main bbfdm process, which further increases nodes in main datamodel tree, which overtime become a huge tree, results in slower turn around service time for the APIs. Also, any unhandled fault in plugin result in segfault in main bbfdmd process, which takes down the whole tree along with plugin, resulting in complete failure from cwmp and USP, with micro-services plugins runs as an individual processes, so impact of fault limited to its own micro-service only.
Micro-service approach, disintegrate the plugins further and run them as individual daemons with the help of "bbfdmd" "-m" command line options.
## Datamodel debugging tools
To debug the datamodel objects/parameters, `bbfdmd` provides a command line interface, which can

View file

@ -186,6 +186,8 @@ Following table has list of APIs/datatypes which no longer exists in libbbfdm-ap
| function | `dm_validate_hexBinary_list` | `bbfdm_validate_hexBinary_list` | To support fault_msg in case of errors |
| function | `dm_entry_validate_allowed_objects`| `dm_validate_allowed_objects` | Replaced with a generic API that is accessible for both internal (bbfdm core) and external (microservices) data models |
| function | `dm_entry_validate_external_linker_allowed_objects` | `dm_validate_allowed_objects` | Replaced with a generic API that is accessible for both internal (bbfdm core) and external (microservices) data models |
| function | `add_list_parameter` | | Removed, no more required |
| function | `free_all_list_parameter` | | Removed, no more required |
| function | `adm_entry_get_linker_param` | | Removed, no more required |
| function | `adm_entry_get_linker_value` | | Removed, no more required |
| enum | `CMD_SUCCESS` | | Removed, no more required |

View file

@ -70,7 +70,6 @@ function install_libbbf()
echo "installing libbbf"
exec_cmd_verbose make install
ln -sf /usr/share/bbfdm/scripts/bbf.diag /usr/libexec/rpcd/bbf.diag
echo "371d530c95a17d1ca223a29b7a6cdc97e1135c1e0959b51106cca91a0b148b5e42742d372a359760742803f2a44bd88fca67ccdcfaeed26d02ce3b6049cb1e04" > /etc/bbfdm/.secure_hash
cd ..
}

View file

@ -124,7 +124,7 @@ typedef struct dm_leaf_s {
int (*getvalue)(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int (*setvalue)(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int bbfdm_type;
uint32_t dm_falgs;
uint32_t dm_flags;
} DMLEAF;
@ -171,7 +171,6 @@ struct dmctx {
int (*method_obj)(DMOBJECT_ARGS);
int (*checkobj)(DMOBJECT_ARGS);
int (*checkleaf)(DMOBJECT_ARGS);
struct list_head list_parameter;
struct list_head *memhead;
struct blob_buf bb;
DMOBJ *dm_entryobj;

View file

@ -671,34 +671,6 @@ int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, cha
return 0;
}
void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *additional_data)
{
struct dm_parameter *dm_parameter;
dm_parameter = dmcalloc(1, sizeof(struct dm_parameter));
list_add_tail(&dm_parameter->list, &ctx->list_parameter);
dm_parameter->name = param_name;
dm_parameter->data = param_data;
dm_parameter->type = param_type;
dm_parameter->additional_data = additional_data;
}
static void api_del_list_parameter(struct dm_parameter *dm_parameter)
{
list_del(&dm_parameter->list);
dmfree(dm_parameter->name);
dmfree(dm_parameter);
}
void free_all_list_parameter(struct dmctx *ctx)
{
struct dm_parameter *dm_parameter = NULL;
while (ctx->list_parameter.next != &ctx->list_parameter) {
dm_parameter = list_entry(ctx->list_parameter.next, struct dm_parameter, list);
api_del_list_parameter(dm_parameter);
}
}
static void bb_add_flags_arr(struct blob_buf *bb, uint32_t dm_flags)
{
if (!bb || !dm_flags)
@ -1064,273 +1036,243 @@ static int ubus_call_blob_msg(char *obj, char *method, struct blob_buf *blob, in
ms_callback, callback_arg, timeout);
}
if (ubus_ctx) {
ubus_free(ubus_ctx);
ubus_ctx = NULL;
}
return rc;
}
static uint32_t get_dm_flags(struct blob_attr *flags_arr)
{
struct blob_attr *flag = NULL;
uint32_t dm_flags = 0;
int rem = 0;
if (!flags_arr)
return 0;
blobmsg_for_each_attr(flag, flags_arr, rem) {
char *flag_str = blobmsg_get_string(flag);
if (DM_LSTRCMP(flag_str, "Reference") == 0)
dm_flags |= DM_FLAG_REFERENCE;
if (DM_LSTRCMP(flag_str, "Unique") == 0)
dm_flags |= DM_FLAG_UNIQUE;
if (DM_LSTRCMP(flag_str, "Linker") == 0)
dm_flags |= DM_FLAG_LINKER;
if (DM_LSTRCMP(flag_str, "Secure") == 0)
dm_flags |= DM_FLAG_SECURE;
}
return dm_flags;
}
static void __get_ubus_value(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct blob_attr *cur = NULL;
int rem = 0;
if (!msg || !req)
return;
struct dmctx *dmctx = (struct dmctx *)req->priv;
struct blob_attr *parameters = get_results_array(msg);
if (parameters == NULL) {
dmctx->faultcode = FAULT_9005;
return;
}
int array_len = blobmsg_len(parameters);
if (array_len == 0) {
dmctx->findparam = 1;
return;
}
blobmsg_for_each_attr(cur, parameters, rem) {
struct blob_attr *tb[5] = {0};
const struct blobmsg_policy p[5] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "flags", BLOBMSG_TYPE_ARRAY },
{ "fault", BLOBMSG_TYPE_INT32 }
};
blobmsg_parse(p, 5, tb, blobmsg_data(cur), blobmsg_len(cur));
if (tb[4]) {
int fault = blobmsg_get_u32(tb[4]);
dmctx->faultcode = fault;
return;
} else {
dmctx->faultcode = 0;
}
dmctx->findparam = 1;
uint32_t dm_flags = get_dm_flags(tb[3]);
bool is_reference = dm_flags & DM_FLAG_REFERENCE;
if (is_reference) {
char *dm_path = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
char *dm_data = (tb[1]) ? get_value_by_reference(dmctx, blobmsg_get_string(tb[1])) : "";
char *dm_type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
fill_blob_param(&dmctx->bb, dm_path, dm_data, dm_type, dm_flags);
} else {
blobmsg_add_blob(&dmctx->bb, cur);
}
}
}
static int get_ubus_value(struct dmctx *dmctx, struct dmnode *node)
{
json_object *res = NULL, *res_obj = NULL;
char *ubus_name = node->obj->checkdep;
char *in_path = (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, "Device") == 0) ? node->current_object : dmctx->in_param;
struct blob_buf blob = {0};
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
memset(&blob, 0, sizeof(struct blob_buf));
blob_buf_init(&blob, 0);
dmubus_call(ubus_name, "get",
UBUS_ARGS{
{"path", in_path, String},
{"optional", json_object_to_json_string(in_args), Table}
},
2, &res);
blobmsg_add_string(&blob, "path", in_path);
prepare_optional_table(dmctx, &blob);
json_object_put(in_args);
int res = ubus_call_blob_msg(ubus_name, "get", &blob, 5000, __get_ubus_value, dmctx);
if (!res)
blob_buf_free(&blob);
if (res)
return FAULT_9005;
json_object *res_array = dmjson_get_obj(res, 1, "results");
if (!res_array)
return FAULT_9005;
size_t nbre_obj = json_object_array_length(res_array);
if (nbre_obj == 0) {
dmctx->findparam = 1;
return 0;
}
for (size_t i = 0; i < nbre_obj; i++) {
uint32_t *dm_flags = NULL;
res_obj = json_object_array_get_idx(res_array, i);
char *fault = dmjson_get_value(res_obj, 1, "fault");
if (DM_STRLEN(fault))
return DM_STRTOUL(fault);
dmctx->findparam = 1;
char *path = dmjson_get_value(res_obj, 1, "path");
char *data = dmjson_get_value(res_obj, 1, "data");
char *type = dmjson_get_value(res_obj, 1, "type");
json_object *flags_array = dmjson_get_obj(res_obj, 1, "flags");
if (flags_array) {
size_t nbre_falgs = json_object_array_length(flags_array);
dm_flags = (uint32_t *)dmcalloc(1, sizeof(uint32_t));
for (size_t j = 0; j < nbre_falgs; j++) {
json_object *flag_obj = json_object_array_get_idx(flags_array, j);
const char *flag = json_object_get_string(flag_obj);
if (DM_LSTRCMP(flag, "Reference") == 0) {
data = get_value_by_reference(dmctx, data);
*dm_flags |= DM_FLAG_REFERENCE;
} else if (DM_LSTRCMP(flag, "Unique") == 0) {
*dm_flags |= DM_FLAG_UNIQUE;
} else if (DM_LSTRCMP(flag, "Linker") == 0) {
*dm_flags |= DM_FLAG_LINKER;
} else if (DM_LSTRCMP(flag, "Secure") == 0) {
*dm_flags |= DM_FLAG_SECURE;
}
}
}
add_list_parameter(dmctx, dmstrdup(path), dmstrdup(data), dmstrdup(type), (char *)dm_flags);
}
if (dmctx->faultcode)
return dmctx->faultcode;
return 0;
}
static void __get_ubus_supported_dm(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct blob_attr *cur = NULL;
int rem = 0;
if (!msg || !req)
return;
struct dmctx *dmctx = (struct dmctx *)req->priv;
struct blob_attr *parameters = get_results_array(msg);
if (parameters == NULL)
return;
int array_len = blobmsg_len(parameters);
if (array_len == 0) {
dmctx->findparam = 1;
return;
}
blobmsg_for_each_attr(cur, parameters, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "fault", BLOBMSG_TYPE_INT32 }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
if (tb[0])
continue;
dmctx->findparam = 1;
blobmsg_add_blob(&dmctx->bb, cur);
}
}
static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node)
{
json_object *res = NULL, *res_obj = NULL, *tmp_obj = NULL;
char *ubus_name = node->obj->checkdep;
char *in_path = (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, "Device") == 0) ? node->current_object : dmctx->in_param;
char *tmp;
struct blob_buf blob = {0};
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
memset(&blob, 0, sizeof(struct blob_buf));
blob_buf_init(&blob, 0);
dmubus_call(ubus_name, "schema",
UBUS_ARGS{
{"path", in_path, String},
{"first_level", dmctx->nextlevel ? "1" : "0", Boolean},
{"optional", json_object_to_json_string(in_args), Table}
},
3, &res);
blobmsg_add_string(&blob, "path", in_path);
blobmsg_add_u8(&blob, "first_level", dmctx->nextlevel);
prepare_optional_table(dmctx, &blob);
json_object_put(in_args);
ubus_call_blob_msg(ubus_name, "schema", &blob, 5000, __get_ubus_supported_dm, dmctx);
if (!res)
return 0;
json_object *res_array = dmjson_get_obj(res, 1, "results");
if (!res_array)
return 0;
size_t nbre_obj = json_object_array_length(res_array);
if (nbre_obj == 0) {
dmctx->findparam = 1;
return 0;
}
for (size_t i = 0; i < nbre_obj; i++) {
res_obj = json_object_array_get_idx(res_array, i);
char *fault = dmjson_get_value(res_obj, 1, "fault");
if (DM_STRLEN(fault))
continue;
dmctx->findparam = 1;
char *path = dmjson_get_value(res_obj, 1, "path");
char *data = dmjson_get_value(res_obj, 1, "data");
char *type = dmjson_get_value(res_obj, 1, "type");
if (DM_LSTRCMP(type, "xsd:object") == 0) { //Object
add_list_parameter(dmctx, dmstrdup(path), dmstrdup(data), "xsd:object", NULL);
} else if (DM_LSTRCMP(type, "xsd:command") == 0) { //Command Leaf
operation_args *op = NULL;
op = dmcalloc(1, sizeof(operation_args));
json_object *input_array = dmjson_get_obj(res_obj, 1, "input");
if (input_array) {
size_t j = 0;
size_t in_nbre = json_object_array_length(input_array);
op->in = dmcalloc(in_nbre + 1, sizeof(char *));
for (j = 0; j < in_nbre; j++) {
tmp_obj = json_object_array_get_idx(input_array, j);
tmp = dmjson_get_value(tmp_obj, 1, "path");
op->in[j] = dmstrdup(tmp);
}
op->in[j] = NULL;
}
json_object *output_array = dmjson_get_obj(res_obj, 1, "output");
if (output_array) {
size_t j = 0;
size_t out_nbre = json_object_array_length(output_array);
op->out = dmcalloc(out_nbre + 1, sizeof(char *));
for (j = 0; j < out_nbre; j++) {
tmp_obj = json_object_array_get_idx(output_array, j);
tmp = dmjson_get_value(tmp_obj, 1, "path");
op->out[j] = dmstrdup(tmp);
}
op->out[j] = NULL;
}
add_list_parameter(dmctx, dmstrdup(path), (char *)op, "xsd:command", dmstrdup(data));
} else if (DM_LSTRCMP(type, "xsd:event") == 0) { //Event Leaf
event_args *ev = NULL;
json_object *input_array = dmjson_get_obj(res_obj, 1, "input");
if (input_array) {
ev = dmcalloc(1, sizeof(event_args));
size_t j = 0;
size_t in_nbre = json_object_array_length(input_array);
ev->param = dmcalloc(in_nbre + 1, sizeof(char *));
for (j = 0; j < in_nbre; j++) {
tmp_obj = json_object_array_get_idx(input_array, j);
tmp = dmjson_get_value(tmp_obj, 1, "path");
ev->param[j] = dmstrdup(tmp);
}
ev->param[j] = NULL;
}
add_list_parameter(dmctx, dmstrdup(path), (char *)ev, "xsd:event", NULL);
} else { //Param Leaf
uint32_t *dm_flags = NULL;
json_object *flags_array = dmjson_get_obj(res_obj, 1, "flags");
if (flags_array) {
size_t nbre_falgs = json_object_array_length(flags_array);
dm_flags = (uint32_t *)dmcalloc(1, sizeof(uint32_t));
for (size_t j = 0; j < nbre_falgs; j++) {
json_object *flag_obj = json_object_array_get_idx(flags_array, j);
const char *flag = json_object_get_string(flag_obj);
if (DM_LSTRCMP(flag, "Reference") == 0) {
data = get_value_by_reference(dmctx, data);
*dm_flags |= DM_FLAG_REFERENCE;
} else if (DM_LSTRCMP(flag, "Unique") == 0) {
*dm_flags |= DM_FLAG_UNIQUE;
} else if (DM_LSTRCMP(flag, "Linker") == 0) {
*dm_flags |= DM_FLAG_LINKER;
} else if (DM_LSTRCMP(flag, "Secure") == 0) {
*dm_flags |= DM_FLAG_SECURE;
}
}
}
add_list_parameter(dmctx, dmstrdup(path), dmstrdup(data), dmstrdup(type), (char *)dm_flags);
}
}
blob_buf_free(&blob);
return 0;
}
static void __get_ubus_instances(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct blob_attr *cur = NULL;
int rem = 0;
if (!msg || !req)
return;
struct dmctx *dmctx = (struct dmctx *)req->priv;
struct blob_attr *parameters = get_results_array(msg);
if (parameters == NULL) {
dmctx->faultcode = FAULT_9005;
return;
}
int array_len = blobmsg_len(parameters);
if (array_len == 0) {
dmctx->findparam = 1;
return;
}
blobmsg_for_each_attr(cur, parameters, rem) {
struct blob_attr *tb[1] = {0};
const struct blobmsg_policy p[1] = {
{ "fault", BLOBMSG_TYPE_INT32 }
};
blobmsg_parse(p, 1, tb, blobmsg_data(cur), blobmsg_len(cur));
if (tb[0]) {
int fault = blobmsg_get_u32(tb[0]);
dmctx->faultcode = fault;
return;
} else {
dmctx->faultcode = 0;
}
dmctx->findparam = 1;
blobmsg_add_blob(&dmctx->bb, cur);
}
}
static int get_ubus_instances(struct dmctx *dmctx, struct dmnode *node)
{
json_object *res = NULL, *res_obj = NULL;
char *ubus_name = node->obj->checkdep;
struct blob_buf blob = {0};
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
memset(&blob, 0, sizeof(struct blob_buf));
blob_buf_init(&blob, 0);
dmubus_call(ubus_name, "instances",
UBUS_ARGS{
{"path", dmctx->in_param, String},
{"first_level", dmctx->nextlevel ? "1" : "0", Boolean},
{"optional", json_object_to_json_string(in_args), Table}
},
3, &res);
blobmsg_add_string(&blob, "path", dmctx->in_param);
blobmsg_add_u8(&blob, "first_level", dmctx->nextlevel);
prepare_optional_table(dmctx, &blob);
json_object_put(in_args);
int res = ubus_call_blob_msg(ubus_name, "instances", &blob, 5000, __get_ubus_instances, dmctx);
if (!res)
blob_buf_free(&blob);
if (res)
return FAULT_9005;
json_object *res_array = dmjson_get_obj(res, 1, "results");
if (!res_array)
return FAULT_9005;
size_t nbre_obj = json_object_array_length(res_array);
if (nbre_obj == 0) {
dmctx->findparam = 1;
return 0;
}
for (size_t i = 0; i < nbre_obj; i++) {
res_obj = json_object_array_get_idx(res_array, i);
char *fault = dmjson_get_value(res_obj, 1, "fault");
if (DM_STRLEN(fault))
return DM_STRTOUL(fault);
dmctx->findparam = 1;
char *path = dmjson_get_value(res_obj, 1, "path");
add_list_parameter(dmctx, dmstrdup(path), NULL, "xsd:object", NULL);
}
if (dmctx->faultcode)
return dmctx->faultcode;
return 0;
}
@ -1515,59 +1457,50 @@ static int set_ubus_value(struct dmctx *dmctx, struct dmnode *node)
return 0;
}
static int get_ubus_name(struct dmctx *dmctx, struct dmnode *node)
static void __get_ubus_name(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct blob_attr *cur = NULL;
int rem = 0, idx = 0;
if (!msg || !req)
return;
struct dmctx *dmctx = (struct dmctx *)req->priv;
unsigned int in_path_dot_num = count_occurrences(dmctx->in_param, '.');
json_object *res = NULL, *res_obj = NULL;
char *ubus_name = node->obj->checkdep;
char *in_path = (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, "Device") == 0) ? node->current_object : dmctx->in_param;
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string("cwmp"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
struct blob_attr *parameters = get_results_array(msg);
if (parameters == NULL)
return;
dmubus_call(ubus_name, "schema",
UBUS_ARGS{
{"path", in_path, String},
{"first_level", dmctx->nextlevel ? "1" : "0", Boolean},
{"optional", json_object_to_json_string(in_args), Table}
},
3, &res);
json_object_put(in_args);
if (!res)
return 0;
json_object *res_array = dmjson_get_obj(res, 1, "results");
if (!res_array)
return 0;
size_t nbre_obj = json_object_array_length(res_array);
if (nbre_obj == 0) {
int array_len = blobmsg_len(parameters);
if (array_len == 0) {
dmctx->findparam = 1;
return 0;
return;
}
for (size_t i = 0; i < nbre_obj; i++) {
res_obj = json_object_array_get_idx(res_array, i);
blobmsg_for_each_attr(cur, parameters, rem) {
struct blob_attr *tb[2] = {0};
const struct blobmsg_policy p[2] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "fault", BLOBMSG_TYPE_INT32 }
};
char *fault = dmjson_get_value(res_obj, 1, "fault");
if (DM_STRLEN(fault))
return DM_STRTOUL(fault);
blobmsg_parse(p, 2, tb, blobmsg_data(cur), blobmsg_len(cur));
if (tb[1]) {
dmctx->faultcode = blobmsg_get_u32(tb[1]);
return;
}
dmctx->findparam = 1;
if (i == 0 && dmctx->nextlevel && (count_occurrences(node->current_object, '.') == in_path_dot_num + 1))
add_list_parameter(dmctx, dmstrdup(node->current_object), "0", "xsd:object", NULL);
char *path = dmjson_get_value(res_obj, 1, "path");
char *data = dmjson_get_value(res_obj, 1, "data");
char *type = dmjson_get_value(res_obj, 1, "type");
char *info = dmjson_get_value(res_obj, 1, "info");
if (idx == 0 && dmctx->nextlevel && (count_occurrences(dmctx->in_value, '.') == in_path_dot_num + 1)) {
fill_blob_param(&dmctx->bb, dmctx->in_value, "0", "xsd:object", 0);
idx++;
}
if (dmctx->nextlevel) {
char *path = tb[0] ? blobmsg_get_string(tb[0]) : "";
unsigned int path_dot_num = count_occurrences(path, '.');
size_t len = DM_STRLEN(path);
@ -1576,8 +1509,27 @@ static int get_ubus_name(struct dmctx *dmctx, struct dmnode *node)
continue;
}
add_list_parameter(dmctx, dmstrdup(path), dmstrdup(data), dmstrdup(type), info);
blobmsg_add_blob(&dmctx->bb, cur);
}
}
static int get_ubus_name(struct dmctx *dmctx, struct dmnode *node)
{
char *in_path = (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, "Device") == 0) ? node->current_object : dmctx->in_param;
char *ubus_name = node->obj->checkdep;
dmctx->in_value = node->current_object;
struct blob_buf blob = {0};
memset(&blob, 0, sizeof(struct blob_buf));
blob_buf_init(&blob, 0);
blobmsg_add_string(&blob, "path", in_path);
blobmsg_add_u8(&blob, "first_level", dmctx->nextlevel);
prepare_optional_table(dmctx, &blob);
ubus_call_blob_msg(ubus_name, "schema", &blob, 5000, __get_ubus_name, dmctx);
blob_buf_free(&blob);
return 0;
}
@ -1655,7 +1607,7 @@ static int operate_ubus(struct dmctx *dmctx, struct dmnode *node)
prepare_optional_table(dmctx, &blob);
int res = ubus_call_blob_msg(ubus_name, "operate", &blob, 20000, __operate_ubus, dmctx);
int res = ubus_call_blob_msg(ubus_name, "operate", &blob, 120000, __operate_ubus, dmctx);
blob_buf_free(&blob);
@ -1746,16 +1698,17 @@ static int get_value_param(DMPARAM_ARGS)
if (node->is_ubus_service) {
return get_ubus_value(dmctx, node);
} else {
char *full_param;
char full_param[MAX_DM_PATH] = {0};
char *value = "";
dmastrcat(&full_param, node->current_object, leaf->parameter);
snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter);
(leaf->getvalue)(full_param, dmctx, data, instance, &value);
if ((leaf->dm_falgs & DM_FLAG_SECURE) && (dmctx->dm_type == BBFDM_CWMP)) {
if ((leaf->dm_flags & DM_FLAG_SECURE) && (dmctx->dm_type == BBFDM_CWMP)) {
value = "";
} else if (value && *value) {
if (leaf->dm_falgs & DM_FLAG_REFERENCE) {
if (leaf->dm_flags & DM_FLAG_REFERENCE) {
value = get_value_by_reference(dmctx, value);
} else {
value = check_value_by_type(value, leaf->type);
@ -1764,7 +1717,7 @@ static int get_value_param(DMPARAM_ARGS)
value = get_default_value_by_type(leaf->type);
}
add_list_parameter(dmctx, full_param, value, DMT_TYPE[leaf->type], leaf->dm_falgs ? (char *)&leaf->dm_falgs : NULL);
fill_blob_param(&dmctx->bb, full_param, value, DMT_TYPE[leaf->type], leaf->dm_flags);
}
return 0;
@ -1784,29 +1737,25 @@ static int mparam_get_value_in_param(DMPARAM_ARGS)
dmctx->findparam = (dmctx->iswildcard) ? 1 : 0;
dmctx->stop = (dmctx->iswildcard) ? false : true;
} else {
char *full_param;
char full_param[MAX_DM_PATH] = {0};
char *value = "";
dmastrcat(&full_param, node->current_object, leaf->parameter);
snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter);
if (dmctx->iswildcard) {
if (dm_strcmp_wildcard(dmctx->in_param, full_param) != 0) {
dmfree(full_param);
if (dm_strcmp_wildcard(dmctx->in_param, full_param) != 0)
return FAULT_9005;
}
} else {
if (DM_STRCMP(dmctx->in_param, full_param) != 0) {
dmfree(full_param);
if (DM_STRCMP(dmctx->in_param, full_param) != 0)
return FAULT_9005;
}
}
(leaf->getvalue)(full_param, dmctx, data, instance, &value);
if ((leaf->dm_falgs & DM_FLAG_SECURE) && (dmctx->dm_type == BBFDM_CWMP)) {
if ((leaf->dm_flags & DM_FLAG_SECURE) && (dmctx->dm_type == BBFDM_CWMP)) {
value = "";
} else if (value && *value) {
if (leaf->dm_falgs & DM_FLAG_REFERENCE) {
if (leaf->dm_flags & DM_FLAG_REFERENCE) {
value = get_value_by_reference(dmctx, value);
} else
value = check_value_by_type(value, leaf->type);
@ -1814,7 +1763,7 @@ static int mparam_get_value_in_param(DMPARAM_ARGS)
value = get_default_value_by_type(leaf->type);
}
add_list_parameter(dmctx, full_param, value, DMT_TYPE[leaf->type], leaf->dm_falgs ? (char *)&leaf->dm_falgs : NULL);
fill_blob_param(&dmctx->bb, full_param, value, DMT_TYPE[leaf->type], leaf->dm_flags);
dmctx->findparam = (dmctx->iswildcard) ? 1 : 0;
dmctx->stop = (dmctx->iswildcard) ? false : true;
@ -1872,6 +1821,28 @@ int dm_entry_get_value(struct dmctx *dmctx)
/* **********
* get name
* **********/
static void fill_blob_alias_param(struct blob_buf *bb, char *path, char *data, char *type, char *alias)
{
if (!bb || !path || !data || !type || !alias)
return;
void *table = blobmsg_open_table(bb, NULL);
blobmsg_add_string(bb, "path", path);
blobmsg_add_string(bb, "data", data);
blobmsg_add_string(bb, "type", type);
void *array = blobmsg_open_array(bb, "output");
void *out_table = blobmsg_open_table(bb, NULL);
blobmsg_add_string(bb, "data", alias);
blobmsg_close_table(bb, out_table);
blobmsg_close_array(bb, array);
blobmsg_close_table(bb, table);
}
static int mobj_get_name(DMOBJECT_ARGS)
{
if (node->is_ubus_service) {
@ -1883,7 +1854,7 @@ static int mobj_get_name(DMOBJECT_ARGS)
if (permission->get_permission != NULL)
perm = permission->get_permission(refparam, dmctx, data, instance);
add_list_parameter(dmctx, refparam, perm, "xsd:object", NULL);
fill_blob_param(&dmctx->bb, refparam, perm, "xsd:object", 0);
return 0;
}
}
@ -1894,19 +1865,23 @@ static int mparam_get_name(DMPARAM_ARGS)
get_ubus_name(dmctx, node);
return 0;
} else {
char *refparam;
char *perm = leaf->permission->val;
char *alias = "";
char refparam[MAX_DM_PATH] = {0};
snprintf(refparam, sizeof(refparam), "%s%s", node->current_object, leaf->parameter);
dmastrcat(&refparam, node->current_object, leaf->parameter);
if (leaf->permission->get_permission != NULL)
perm = leaf->permission->get_permission(refparam, dmctx, data, instance);
if (DM_LSTRCMP(leaf->parameter, "Alias") == 0) {
char *alias = "";
(leaf->getvalue)(refparam, dmctx, data, instance, &alias);
fill_blob_alias_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], alias);
} else {
fill_blob_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], 0);
}
add_list_parameter(dmctx, refparam, perm, DMT_TYPE[leaf->type], alias);
return 0;
}
}
@ -1923,29 +1898,23 @@ static int mparam_get_name_in_param(DMPARAM_ARGS)
dmctx->stop = true;
return err ? err : 0;
} else {
char *refparam;
char *perm = leaf->permission->val;
char *alias = "";
char refparam[MAX_DM_PATH] = {0};
dmastrcat(&refparam, node->current_object, leaf->parameter);
snprintf(refparam, sizeof(refparam), "%s%s", node->current_object, leaf->parameter);
if (dmctx->iswildcard) {
if (dm_strcmp_wildcard(refparam, dmctx->in_param) != 0) {
dmfree(refparam);
if (dm_strcmp_wildcard(refparam, dmctx->in_param) != 0)
return FAULT_9005;
}
} else {
if (DM_STRCMP(refparam, dmctx->in_param) != 0) {
dmfree(refparam);
if (DM_STRCMP(refparam, dmctx->in_param) != 0)
return FAULT_9005;
}
}
dmctx->stop = (dmctx->iswildcard) ? 0 : 1;
if (dmctx->nextlevel == 1) {
dmctx->stop = 1;
dmfree(refparam);
return FAULT_9003;
}
@ -1953,10 +1922,14 @@ static int mparam_get_name_in_param(DMPARAM_ARGS)
perm = leaf->permission->get_permission(refparam, dmctx, data, instance);
if (DM_LSTRCMP(leaf->parameter, "Alias") == 0) {
char *alias = "";
(leaf->getvalue)(refparam, dmctx, data, instance, &alias);
fill_blob_alias_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], alias);
} else {
fill_blob_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], 0);
}
add_list_parameter(dmctx, refparam, perm, DMT_TYPE[leaf->type], alias);
dmctx->findparam = (dmctx->iswildcard) ? 1 : 0;
return 0;
}
@ -1984,7 +1957,7 @@ static int mobj_get_name_in_obj(DMOBJECT_ARGS)
if (permission->get_permission != NULL)
perm = permission->get_permission(refparam, dmctx, data, instance);
add_list_parameter(dmctx, refparam, perm, "xsd:object", NULL);
fill_blob_param(&dmctx->bb, refparam, perm, "xsd:object", 0);
return 0;
}
}
@ -1994,20 +1967,23 @@ static int mparam_get_name_in_obj(DMPARAM_ARGS)
if (node->is_ubus_service) {
return get_ubus_name(dmctx, node);
} else {
char *refparam;
char *perm = leaf->permission->val;
char *alias = "";
char refparam[MAX_DM_PATH] = {0};
dmastrcat(&refparam, node->current_object, leaf->parameter);
snprintf(refparam, sizeof(refparam), "%s%s", node->current_object, leaf->parameter);
if (leaf->permission->get_permission != NULL)
perm = leaf->permission->get_permission(refparam, dmctx, data, instance);
if (DM_LSTRCMP(leaf->parameter, "Alias") == 0) {
char *alias = "";
(leaf->getvalue)(refparam, dmctx, data, instance, &alias);
fill_blob_alias_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], alias);
} else {
fill_blob_param(&dmctx->bb, refparam, perm, DMT_TYPE[leaf->type], 0);
}
add_list_parameter(dmctx, refparam, perm, DMT_TYPE[leaf->type], alias);
return 0;
}
}
@ -2086,7 +2062,7 @@ static int mobj_get_supported_dm(DMOBJECT_ARGS)
char *refparam = node->current_object;
if (node->matched && dmctx->isinfo) {
add_list_parameter(dmctx, refparam, perm, "xsd:object", NULL);
fill_blob_param(&dmctx->bb, refparam, perm, "xsd:object", 0);
}
}
@ -2098,10 +2074,10 @@ static int mparam_get_supported_dm(DMPARAM_ARGS)
if (node->is_ubus_service) {
return get_ubus_supported_dm(dmctx, node);
} else {
char refparam[MAX_DM_PATH] = {0};
char *value = NULL;
char *refparam;
dmastrcat(&refparam, node->current_object, leaf->parameter);
snprintf(refparam, sizeof(refparam), "%s%s", node->current_object, leaf->parameter);
if (node->matched) {
if (leaf->type == DMT_EVENT) {
@ -2109,7 +2085,7 @@ static int mparam_get_supported_dm(DMPARAM_ARGS)
if (leaf->getvalue)
(leaf->getvalue)(refparam, dmctx, data, instance, &value);
add_list_parameter(dmctx, refparam, value, DMT_TYPE[leaf->type], NULL);
fill_blob_event(&dmctx->bb, refparam, DMT_TYPE[leaf->type], value);
}
} else if (leaf->type == DMT_COMMAND) {
@ -2118,10 +2094,10 @@ static int mparam_get_supported_dm(DMPARAM_ARGS)
if (leaf->getvalue)
(leaf->getvalue)(refparam, dmctx, data, instance, &value);
add_list_parameter(dmctx, refparam, value, DMT_TYPE[leaf->type], leaf->permission->val);
fill_blob_operate(&dmctx->bb, refparam, leaf->permission->val, DMT_TYPE[leaf->type], value);
}
} else {
add_list_parameter(dmctx, refparam, leaf->permission->val, DMT_TYPE[leaf->type], leaf->dm_falgs ? (char *)&leaf->dm_falgs : NULL);
fill_blob_param(&dmctx->bb, refparam, leaf->permission->val, DMT_TYPE[leaf->type], leaf->dm_flags);
}
}
@ -2162,11 +2138,18 @@ static int mobj_get_instances_in_obj(DMOBJECT_ARGS)
return get_ubus_instances(dmctx, node);
} else {
if (node->matched && node->is_instanceobj) {
char *name = dmstrdup(node->current_object);
char path[MAX_DM_PATH] = {0};
if (name) {
name[DM_STRLEN(name) - 1] = 0;
add_list_parameter(dmctx, name, NULL, "xsd:object", NULL);
snprintf(path, sizeof(path), "%s", node->current_object);
int len = DM_STRLEN(path);
if (len) {
path[len - 1] = 0;
void *table = blobmsg_open_table(&dmctx->bb, NULL);
blobmsg_add_string(&dmctx->bb, "path", path);
blobmsg_close_table(&dmctx->bb, table);
}
}
}
@ -2381,7 +2364,7 @@ static int mparam_set_value(DMPARAM_ARGS)
BBF_DEBUG("Requested value (%s) is same as current value (%s).", dmctx->in_value, value);
return 0;
}
} else if (leaf->dm_falgs & DM_FLAG_REFERENCE) {
} else if (leaf->dm_flags & DM_FLAG_REFERENCE) {
value = get_value_by_reference(dmctx, value);
if (DM_STRCMP(value, dmctx->in_value) == 0) {
@ -2498,15 +2481,13 @@ static int get_key_check_param(DMPARAM_ARGS)
dmctx->stop = true;
return err ? err : 0;
} else {
char *full_param;
char full_param[MAX_DM_PATH] = {0};
char *value = "";
dmastrcat(&full_param, node->current_object, leaf->parameter);
snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter);
if (dm_strcmp_wildcard(dmctx->in_param, full_param) != 0) {
dmfree(full_param);
if (dm_strcmp_wildcard(dmctx->in_param, full_param) != 0)
return FAULT_9005;
}
(leaf->getvalue)(full_param, dmctx, data, instance, &value);
@ -2557,11 +2538,11 @@ static int get_reference_value_check_obj(DMOBJECT_ARGS)
for (; (leaf && leaf->parameter); leaf++) {
if (leaf->dm_falgs & DM_FLAG_LINKER) {
char *full_param = NULL;
if (leaf->dm_flags & DM_FLAG_LINKER) {
char full_param[MAX_DM_PATH] = {0};
char *link_val = NULL;
dmastrcat(&full_param, node->current_object, leaf->parameter);
snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter);
(leaf->getvalue)(full_param, dmctx, data, instance, &link_val);

View file

@ -31,8 +31,6 @@ int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*b
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt);
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *additional_data);
void free_all_list_parameter(struct dmctx *ctx);
void fill_blob_param(struct blob_buf *bb, char *path, char *data, char *type, uint32_t dm_flags);
void fill_blob_event(struct blob_buf *bb, char *path, char *type, void *data);

View file

@ -46,7 +46,7 @@ void bbf_ctx_init(struct dmctx *ctx, DMOBJ *tEntryObj)
{
memset(&ctx->bb, 0, sizeof(struct blob_buf));
blob_buf_init(&ctx->bb, 0);
INIT_LIST_HEAD(&ctx->list_parameter);
ctx->dm_entryobj = tEntryObj;
bbfdm_init_mem(ctx);
dm_uci_init();
@ -55,7 +55,6 @@ void bbf_ctx_init(struct dmctx *ctx, DMOBJ *tEntryObj)
void bbf_ctx_clean(struct dmctx *ctx)
{
blob_buf_free(&ctx->bb);
free_all_list_parameter(ctx);
dm_uci_exit();
dmubus_free();
@ -64,13 +63,11 @@ void bbf_ctx_clean(struct dmctx *ctx)
void bbf_ctx_init_sub(struct dmctx *ctx, DMOBJ *tEntryObj)
{
INIT_LIST_HEAD(&ctx->list_parameter);
ctx->dm_entryobj = tEntryObj;
}
void bbf_ctx_clean_sub(struct dmctx *ctx)
{
free_all_list_parameter(ctx);
}
static char *get_fault_message(int fault_code)
@ -339,12 +336,15 @@ bool adm_entry_object_exists(struct dmctx *ctx, char *param) // To be removed la
snprintf(linker, sizeof(linker), "%s%c", param, (param[DM_STRLEN(param) - 1] != '.') ? '.' : '\0');
bbf_ctx_init_sub(&dmctx, ctx->dm_entryobj);
memset(&dmctx.bb, 0, sizeof(struct blob_buf));
blob_buf_init(&dmctx.bb, 0);
dmctx.in_param = linker;
dm_entry_object_exists(&dmctx);
bbf_ctx_clean_sub(&dmctx);
blob_buf_free(&dmctx.bb);
return dmctx.match;
}

View file

@ -285,22 +285,3 @@ int bbfdm_asprintf(struct dmctx *ctx, char **s, const char *format, ...)
return 0;
}
int bbfdm_astrcat(struct dmctx *ctx, char **s, char *obj, char *lastname)
{
char buf[2048] = {0};
if (obj == NULL || lastname == NULL)
return -1;
int olen = strlen(obj);
memcpy(buf, obj, olen);
int llen = strlen(lastname) + 1;
memcpy(buf + olen, lastname, llen);
*s = bbfdm_strdup(ctx, buf);
if (*s == NULL)
return -1;
return 0;
}

View file

@ -87,23 +87,11 @@ char *bbfdm_strdup(struct dmctx *ctx, const char *s);
*/
int bbfdm_asprintf(struct dmctx *ctx, char **s, const char *format, ...);
/*
* Concatenate the string lastname to the string obj.
* @param ctx - Pointer to bbf context
* @param s - Pointer to store the resulting string
* @param obj - Pointer to the first string
* @param lastname - Pointer to the second string to concatenate
* @return 0 on success, -1 on failure
*/
int bbfdm_astrcat(struct dmctx *ctx, char **s, char *obj, char *lastname);
#define dmmalloc(x) bbfdm_malloc(0, x)
#define dmcalloc(n, x) bbfdm_calloc(0, n, x)
#define dmrealloc(x, n) bbfdm_realloc(0, x, n)
#define dmstrdup(x) bbfdm_strdup(0, x)
#define dmasprintf(s, format, ...) bbfdm_asprintf(0, s, format, ## __VA_ARGS__)
#define dmastrcat(s, b, m) bbfdm_astrcat(0, s, b, m)
#define dm_dynamic_malloc(m, x) __dmmalloc(m, x)
#define dm_dynamic_calloc(m, n, x) __dmcalloc(m, n, x)

View file

@ -1829,19 +1829,19 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl
json_object_object_get_ex(jobj, "protocols", &protocols);
pleaf[i].bbfdm_type = get_bbfdm_type(protocols);
//dm_falgs
//dm_flags
json_object_object_get_ex(jobj, "flags", &flags);
n_flags = flags ? json_object_array_length(flags) : 0;
for (int idx = 0; idx < n_flags; idx++) {
struct json_object *falg_val = json_object_array_get_idx(flags, idx);
if (falg_val && strcmp(json_object_get_string(falg_val), "Linker") == 0)
pleaf[i].dm_falgs |= DM_FLAG_LINKER;
pleaf[i].dm_flags |= DM_FLAG_LINKER;
else if (falg_val && strcmp(json_object_get_string(falg_val), "Reference") == 0)
pleaf[i].dm_falgs |= DM_FLAG_REFERENCE;
pleaf[i].dm_flags |= DM_FLAG_REFERENCE;
else if (falg_val && strcmp(json_object_get_string(falg_val), "Unique") == 0)
pleaf[i].dm_falgs |= DM_FLAG_UNIQUE;
pleaf[i].dm_flags |= DM_FLAG_UNIQUE;
else if (falg_val && strcmp(json_object_get_string(falg_val), "Secure") == 0)
pleaf[i].dm_falgs |= DM_FLAG_SECURE;
pleaf[i].dm_flags |= DM_FLAG_SECURE;
}
snprintf(full_param, sizeof(full_param), "%s%s", object, param_ext);

View file

@ -2,7 +2,7 @@ LIB = libbbf_test.so
LIB_OBJS = libbbf_test.o
LIB_CFLAGS = $(CFLAGS) -Wall -Werror -fPIC -I /usr/local/include/
LIB_LDFLAGS = $(LDFLAGS) -L/usr/share/bbfdm -lbbfdm-api
LIB_LDFLAGS = $(LDFLAGS) -lbbfdm-api
%.o: %.c
$(CC) $(LIB_CFLAGS) $(FPIC) -c -o $@ $<
@ -13,4 +13,4 @@ $(LIB): $(LIB_OBJS)
$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
clean:
rm -fv *.o $(LIB)
rm -fv *.o $(LIB)

View file

@ -53,23 +53,35 @@ static int group_teardown(void **state)
static void validate_parameter(struct dmctx *ctx, const char *name, const char *value, const char *type)
{
struct dm_parameter *n;
struct blob_attr *cur = NULL;
size_t rem = 0;
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[3] = {0};
const struct blobmsg_policy p[3] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING }
};
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
char *dm_name = blobmsg_get_string(tb[0]);
char *dm_data = blobmsg_get_string(tb[1]);
char *dm_type = blobmsg_get_string(tb[2]);
// check the returned path
assert_string_equal(n->name, name);
assert_string_equal(dm_name, name);
// check the returned value
assert_string_equal(n->data, value);
assert_string_equal(dm_data, value);
// check the returned type
assert_string_equal(n->type, type);
assert_string_equal(dm_type, type);
}
bbf_ctx_clean_sub(ctx);
bbf_ctx_init_sub(ctx, TR181_ROOT_TREE);
bbf_ctx_clean(ctx);
bbf_ctx_init(ctx, TR181_ROOT_TREE);
}
static void test_api_bbfdm_get_set_standard_parameter(void **state)
@ -1253,8 +1265,9 @@ static void test_api_bbfdm_valid_standard_operate(void **state)
static void test_api_bbfdm_valid_standard_list_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, i = 0;
struct blob_attr *cur = NULL;
size_t rem = 0;
int fault = 0, idx = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1266,64 +1279,88 @@ static void test_api_bbfdm_valid_standard_list_operate(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *_cur = NULL;
size_t _rem = 0;
struct blob_attr *tb[5] = {0};
const struct blobmsg_policy p[5] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY },
{ "output", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.FactoryReset()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "sync");
assert_null(n->data);
blobmsg_parse(p, 5, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *command_in = tb[3];
struct blob_attr *command_out = tb[4];
if (DM_STRCMP(name, "Device.FactoryReset()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "sync");
assert_null(data);
}
if (DM_STRCMP(n->name, "Device.DeviceInfo.VendorLogFile.{i}.Upload()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "async");
operation_args *args = (operation_args *)n->data;
assert_non_null(args);
const char **command_in = args->in;
const char **command_out = args->out;
if (DM_STRCMP(name, "Device.DeviceInfo.VendorLogFile.{i}.Upload()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "async");
assert_non_null(command_in);
assert_null(command_out);
for (i = 0; command_in[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_in[i], "URL");
break;
case 1:
assert_string_equal(command_in[i], "Username");
break;
case 2:
assert_string_equal(command_in[i], "Password");
break;
blobmsg_for_each_attr(_cur, command_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "URL");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Username");
break;
case 2:
assert_string_equal(blobmsg_get_string(__cur), "Password");
break;
}
idx++;
}
}
assert_int_equal(i, 3);
assert_int_equal(idx, 3);
}
if (DM_STRCMP(n->name, "Device.WiFi.NeighboringWiFiDiagnostic()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "async");
operation_args *args = (operation_args *)n->data;
assert_non_null(args);
const char **command_in = args->in;
const char **command_out = args->out;
if (DM_STRCMP(name, "Device.WiFi.NeighboringWiFiDiagnostic()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "async");
assert_null(command_in);
assert_non_null(command_out);
for (i = 0; command_out[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_out[i], "Status");
break;
case 1:
assert_string_equal(command_out[i], "Result.{i}.Radio");
break;
case 2:
assert_string_equal(command_out[i], "Result.{i}.SSID");
break;
idx = 0;
blobmsg_for_each_attr(_cur, command_out, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Status");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Result.{i}.Radio");
break;
case 2:
assert_string_equal(blobmsg_get_string(__cur), "Result.{i}.SSID");
break;
}
idx++;
}
}
assert_int_equal(i, 18);
assert_int_equal(idx, 18);
}
}
}
@ -1361,8 +1398,9 @@ static void test_api_bbfdm_valid_library_operate(void **state)
static void test_api_bbfdm_valid_library_list_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, i = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
size_t rem = 0, _rem = 0;
int fault = 0, idx = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1374,47 +1412,74 @@ static void test_api_bbfdm_valid_library_list_operate(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[5] = {0};
const struct blobmsg_policy p[5] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY },
{ "output", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Reboot()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "sync");
assert_null(n->data);
blobmsg_parse(p, 5, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *command_in = tb[3];
struct blob_attr *command_out = tb[4];
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_Reboot()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "sync");
assert_null(command_in);
assert_null(command_out);
}
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_PingTEST.Run()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "async");
operation_args *args = (operation_args *)n->data;
assert_non_null(args);
const char **command_in = args->in;
const char **command_out = args->out;
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_PingTEST.Run()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "async");
assert_non_null(command_in);
assert_non_null(command_out);
for (i = 0; command_in[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_in[i], "Host");
break;
}
}
assert_int_equal(i, 1);
blobmsg_for_each_attr(_cur, command_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
for (i = 0; command_out[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_out[i], "AverageResponseTime");
break;
case 1:
assert_string_equal(command_out[i], "MinimumResponseTime");
break;
case 2:
assert_string_equal(command_out[i], "MaximumResponseTime");
break;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Host");
break;
}
idx++;
}
}
assert_int_equal(i, 3);
assert_int_equal(idx, 1);
idx = 0;
blobmsg_for_each_attr(_cur, command_out, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "AverageResponseTime");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "MinimumResponseTime");
break;
case 2:
assert_string_equal(blobmsg_get_string(__cur), "MaximumResponseTime");
break;
}
idx++;
}
}
assert_int_equal(idx, 3);
}
}
}
@ -1454,8 +1519,9 @@ static void test_api_bbfdm_valid_json_operate(void **state)
static void test_api_bbfdm_valid_json_list_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, i = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
size_t rem = 0, _rem = 0;
int fault = 0, idx = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1467,35 +1533,61 @@ static void test_api_bbfdm_valid_json_list_operate(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[5] = {0};
const struct blobmsg_policy p[5] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY },
{ "output", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Status()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "async");
operation_args *args = (operation_args *)n->data;
assert_non_null(args);
const char **command_in = args->in;
const char **command_out = args->out;
blobmsg_parse(p, 5, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *command_in = tb[3];
struct blob_attr *command_out = tb[4];
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_TEST.{i}.Status()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "async");
assert_non_null(command_in);
assert_non_null(command_out);
for (i = 0; command_in[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_in[i], "Option");
break;
}
}
assert_int_equal(i, 1);
blobmsg_for_each_attr(_cur, command_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
for (i = 0; command_out[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_out[i], "Result");
break;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Option");
break;
}
idx++;
}
}
assert_int_equal(i, 1);
assert_int_equal(idx, 1);
idx = 0;
blobmsg_for_each_attr(_cur, command_out, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Result");
break;
}
idx++;
}
}
assert_int_equal(idx, 1);
}
}
}
@ -1535,8 +1627,9 @@ static void test_api_bbfdm_valid_json_v1_operate(void **state)
static void test_api_bbfdm_valid_json_v1_list_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, i = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
int fault = 0, _rem = 0, idx = 0;
size_t rem = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1548,41 +1641,67 @@ static void test_api_bbfdm_valid_json_v1_list_operate(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[5] = {0};
const struct blobmsg_policy p[5] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY },
{ "output", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Status()") == 0) {
assert_string_equal(n->type, "xsd:command");
assert_string_equal(n->additional_data, "async");
operation_args *args = (operation_args *)n->data;
assert_non_null(args);
const char **command_in = args->in;
const char **command_out = args->out;
blobmsg_parse(p, 5, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *command_in = tb[3];
struct blob_attr *command_out = tb[4];
if (DM_STRCMP(name, "Device.UBUS_TEST_V1.Interface.{i}.Status()") == 0) {
assert_string_equal(type, "xsd:command");
assert_string_equal(data, "async");
assert_non_null(command_in);
assert_non_null(command_out);
for (i = 0; command_in[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_in[i], "Option");
break;
case 1:
assert_string_equal(command_out[i], "Value");
break;
}
}
assert_int_equal(i, 2);
blobmsg_for_each_attr(_cur, command_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
for (i = 0; command_out[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(command_out[i], "Result");
break;
case 1:
assert_string_equal(command_out[i], "Value");
break;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Option");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Value");
break;
}
idx++;
}
}
assert_int_equal(i, 2);
assert_int_equal(idx, 2);
idx = 0;
blobmsg_for_each_attr(_cur, command_out, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Result");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Value");
break;
}
idx++;
}
}
assert_int_equal(idx, 2);
}
}
}
@ -1590,8 +1709,9 @@ static void test_api_bbfdm_valid_json_v1_list_operate(void **state)
static void test_api_bbfdm_valid_library_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, idx = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
int fault = 0, _rem = 0, idx = 0, event_num = 0;
size_t rem = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1603,48 +1723,68 @@ static void test_api_bbfdm_valid_library_event(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[4] = {0};
const struct blobmsg_policy p[4] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_WakeUp!") == 0) {
assert_string_equal(n->type, "xsd:event");
assert_null(n->data);
blobmsg_parse(p, 4, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *event_in = tb[3];
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_WakeUp!") == 0) {
assert_string_equal(type, "xsd:event");
assert_null(data);
}
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Boot!") == 0) {
assert_string_equal(n->type, "xsd:event");
event_args *args = (event_args *)n->data;
assert_non_null(args);
const char **event_param = args->param;
assert_non_null(event_param);
for (int i = 0; event_param[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(event_param[i], "CommandKey");
break;
case 1:
assert_string_equal(event_param[i], "Cause");
break;
case 2:
assert_string_equal(event_param[i], "FirmwareUpdated");
break;
case 3:
assert_string_equal(event_param[i], "ParameterMap");
break;
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_Boot!") == 0) {
assert_string_equal(type, "xsd:event");
assert_non_null(event_in);
blobmsg_for_each_attr(_cur, event_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "CommandKey");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Cause");
break;
case 2:
assert_string_equal(blobmsg_get_string(__cur), "FirmwareUpdated");
break;
case 3:
assert_string_equal(blobmsg_get_string(__cur), "ParameterMap");
break;
}
idx++;
}
}
assert_int_equal(idx, 4);
}
idx++;
event_num++;
}
assert_int_not_equal(idx, 0);
assert_int_not_equal(event_num, 0);
}
static void test_api_bbfdm_valid_json_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, idx = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
int fault = 0, _rem = 0, idx = 0, event_num = 0;
size_t rem = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1656,42 +1796,62 @@ static void test_api_bbfdm_valid_json_event(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[4] = {0};
const struct blobmsg_policy p[4] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY }
};
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Periodic!") == 0) {
assert_string_equal(n->type, "xsd:event");
assert_null(n->data);
blobmsg_parse(p, 4, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *event_in = tb[3];
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_TEST.{i}.Periodic!") == 0) {
assert_string_equal(type, "xsd:event");
assert_null(data);
}
if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Push!") == 0) {
assert_string_equal(n->type, "xsd:event");
event_args *args = (event_args *)n->data;
assert_non_null(args);
const char **event_param = args->param;
assert_non_null(event_param);
for (int i = 0; event_param[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(event_param[i], "Data");
break;
case 1:
assert_string_equal(event_param[i], "Status");
break;
if (DM_STRCMP(name, "Device.X_IOPSYS_EU_TEST.{i}.Push!") == 0) {
assert_string_equal(type, "xsd:event");
assert_non_null(event_in);
blobmsg_for_each_attr(_cur, event_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Data");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Status");
break;
}
idx++;
}
}
assert_int_equal(idx, 2);
}
idx++;
event_num++;
}
assert_int_not_equal(idx, 0);
assert_int_not_equal(event_num, 0);
}
static void test_api_bbfdm_valid_json_v1_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, idx = 0;
struct blob_attr *cur = NULL, *_cur = NULL;
int fault = 0, _rem = 0, idx = 0, event_num = 0;
size_t rem = 0;
ctx->in_param = "Device.";
ctx->dm_type = BBFDM_USP;
@ -1703,37 +1863,57 @@ static void test_api_bbfdm_valid_json_v1_event(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Periodic!") == 0) {
assert_string_equal(n->type, "xsd:event");
assert_null(n->data);
blobmsg_for_each_attr(cur, ctx->bb.head, rem) {
struct blob_attr *tb[4] = {0};
const struct blobmsg_policy p[4] = {
{ "path", BLOBMSG_TYPE_STRING },
{ "data", BLOBMSG_TYPE_STRING },
{ "type", BLOBMSG_TYPE_STRING },
{ "input", BLOBMSG_TYPE_ARRAY }
};
blobmsg_parse(p, 4, tb, blobmsg_data(cur), blobmsg_len(cur));
char *name = blobmsg_get_string(tb[0]);
char *data = blobmsg_get_string(tb[1]);
char *type = blobmsg_get_string(tb[2]);
struct blob_attr *event_in = tb[3];
if (DM_STRCMP(name, "Device.UBUS_TEST_V1.Interface.{i}.Periodic!") == 0) {
assert_string_equal(type, "xsd:event");
assert_null(data);
}
if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Push!") == 0) {
assert_string_equal(n->type, "xsd:event");
event_args *args = (event_args *)n->data;
assert_non_null(args);
const char **event_param = args->param;
assert_non_null(event_param);
for (int i = 0; event_param[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(event_param[i], "Data");
break;
case 1:
assert_string_equal(event_param[i], "Status");
break;
case 2:
assert_string_equal(event_param[i], "Value");
break;
if (DM_STRCMP(name, "Device.UBUS_TEST_V1.Interface.{i}.Push!") == 0) {
assert_string_equal(type, "xsd:event");
assert_non_null(event_in);
blobmsg_for_each_attr(_cur, event_in, _rem) {
struct blob_attr *__cur = NULL;
size_t __rem = 0;
blobmsg_for_each_attr(__cur, _cur, __rem) {
switch (idx) {
case 0:
assert_string_equal(blobmsg_get_string(__cur), "Data");
break;
case 1:
assert_string_equal(blobmsg_get_string(__cur), "Status");
break;
case 2:
assert_string_equal(blobmsg_get_string(__cur), "Value");
break;
}
idx++;
}
}
assert_int_equal(idx, 3);
}
idx++;
event_num++;
}
assert_int_not_equal(idx, 0);
assert_int_not_equal(event_num, 0);
}
int main(void)

View file

@ -65,7 +65,6 @@ static int group_teardown(void **state)
static void test_api_bbfdm_get_value_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -73,14 +72,12 @@ static void test_api_bbfdm_get_value_object(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_value_parameter(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFi.Radio.1.Alias";
@ -88,14 +85,12 @@ static void test_api_bbfdm_get_value_parameter(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_value_empty(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "";
@ -103,14 +98,12 @@ static void test_api_bbfdm_get_value_empty(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_value_wrong_object_path(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.DSLL.";
@ -118,14 +111,12 @@ static void test_api_bbfdm_get_value_wrong_object_path(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, FAULT_9005);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list == &ctx->list_parameter);
assert_int_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_value_wrong_parameter_path(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.Users.User.1.Enabl";
@ -133,14 +124,12 @@ static void test_api_bbfdm_get_value_wrong_parameter_path(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, FAULT_9005);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list == &ctx->list_parameter);
assert_int_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_name_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -149,14 +138,12 @@ static void test_api_bbfdm_get_name_object(void **state)
fault = bbf_entry_method(ctx, BBF_GET_NAME);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_name_parameter(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFi.Radio.1.Enable";
@ -165,14 +152,12 @@ static void test_api_bbfdm_get_name_parameter(void **state)
fault = bbf_entry_method(ctx, BBF_GET_NAME);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_name_dot(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = ".";
@ -181,14 +166,12 @@ static void test_api_bbfdm_get_name_dot(void **state)
fault = bbf_entry_method(ctx, BBF_GET_NAME);
assert_int_equal(fault, FAULT_9005);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list == &ctx->list_parameter);
assert_int_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_name_wrong_object_path(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFii.";
@ -197,8 +180,7 @@ static void test_api_bbfdm_get_name_wrong_object_path(void **state)
fault = bbf_entry_method(ctx, BBF_GET_NAME);
assert_int_equal(fault, FAULT_9005);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list == &ctx->list_parameter);
assert_int_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_set_value_object(void **state)
@ -406,7 +388,6 @@ static void test_api_bbfdm_wrong_operate(void **state)
static void test_api_bbfdm_get_list_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -419,14 +400,12 @@ static void test_api_bbfdm_get_list_operate(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_list_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -439,14 +418,12 @@ static void test_api_bbfdm_get_list_event(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_schema(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -459,14 +436,12 @@ static void test_api_bbfdm_get_schema(void **state)
fault = bbf_entry_method(ctx, BBF_SCHEMA);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_instances_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
@ -475,14 +450,12 @@ static void test_api_bbfdm_get_instances_object(void **state)
fault = bbf_entry_method(ctx, BBF_INSTANCES);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_instances_wrong_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFii.";
@ -491,14 +464,12 @@ static void test_api_bbfdm_get_instances_wrong_object(void **state)
fault = bbf_entry_method(ctx, BBF_INSTANCES);
assert_int_equal(fault, FAULT_9005);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list == &ctx->list_parameter);
assert_int_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_get_instances_without_next_level(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFi.";
@ -507,14 +478,12 @@ static void test_api_bbfdm_get_instances_without_next_level(void **state)
fault = bbf_entry_method(ctx, BBF_INSTANCES);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_json_get_value(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
/*
@ -524,11 +493,10 @@ static void test_api_bbfdm_json_get_value(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
bbf_ctx_clean_sub(ctx);
bbf_ctx_init_sub(ctx, TR181_ROOT_TREE);
bbf_ctx_clean(ctx);
bbf_ctx_init(ctx, TR181_ROOT_TREE);
/*
* Test of JSON Parameter Path
@ -537,8 +505,7 @@ static void test_api_bbfdm_json_get_value(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_json_add_object(void **state)
@ -574,7 +541,6 @@ static void test_api_bbfdm_json_delete_object(void **state)
static void test_api_bbfdm_library_get_value(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.X_IOPSYS_EU_Syslog.";
@ -582,19 +548,17 @@ static void test_api_bbfdm_library_get_value(void **state)
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
bbf_ctx_clean_sub(ctx);
bbf_ctx_init_sub(ctx, TR181_ROOT_TREE);
bbf_ctx_clean(ctx);
bbf_ctx_init(ctx, TR181_ROOT_TREE);
ctx->in_param = "Device.WiFi.SSID.1.Enable";
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
assert_int_not_equal(blobmsg_len(ctx->bb.head), 0);
}
static void test_api_bbfdm_library_add_object(void **state)

View file

@ -1,7 +1,9 @@
{
"daemon": {
"config": {
"loglevel": "1"
"loglevel": "1",
"transaction_timeout": "30",
"subprocess_level": "2"
},
"input": {
"type": "DotSo",