diff --git a/src/Makefile b/src/Makefile index f1bf9f9454f9f7098025f5798c13b3f552ae7f42..c143efeff947da5e61fde9abadca3f0cc115c95a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ PROG_CFLAGS = $(CFLAGS) \ -Wformat-signedness -fPIC PROG_LDFLAGS = $(LDFLAGS) -PROG_LDFLAGS += -luci -lubus -lubox -ljson-c -lblobmsg_json -lbbfdm +PROG_LDFLAGS += -luci -lubus -lubox -ljson-c -lblobmsg_json -lbbf_api -lbbf_dm ifeq ($(USE_MBEDTLS),yes) PROG_LDFLAGS += -lmbedcrypto -lmbedtls diff --git a/src/add_delete.c b/src/add_delete.c index 3004e2927d23b9c7514c53b751d3ad85aa2fc7c1..2cc837062b15b57fdf63428163e4f0e4396a9dd7 100644 --- a/src/add_delete.c +++ b/src/add_delete.c @@ -23,7 +23,7 @@ #include "common.h" #include "add_delete.h" #include "get_helper.h" -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> typedef int (*ADD_DEL_CB_T)(struct dmctx *bbf_ctx, struct blob_buf *bb, char *path, const char *pkey); diff --git a/src/common.c b/src/common.c index 56945dcafb1595f1f1615f0f8583155001d34b2f..76cb233e4c7f2714a57496ef387e6c7f4b6c9431 100644 --- a/src/common.c +++ b/src/common.c @@ -21,7 +21,6 @@ */ #include "common.h" -#include <libbbfdm/dmbbfcommon.h> #include "ipc.h" #include "get_helper.h" @@ -145,7 +144,7 @@ bool get_uci_option_string(char *package, char *section, if (!uci_ctx) return false; - if (bbfdmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) { + if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) { *value = NULL; ret = false; } else if (ptr.o && ptr.o->v.string) { @@ -208,3 +207,36 @@ bool validate_msglen(struct blob_buf *bb) return true; } + +int get_dm_type(char *dm_type) +{ + if (dm_type == NULL) + return DMT_STRING; + + if (DM_STRCMP(dm_type, DMT_TYPE[DMT_STRING]) == 0) + return DMT_STRING; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_UNINT]) == 0) + return DMT_UNINT; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_INT]) == 0) + return DMT_INT; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_UNLONG]) == 0) + return DMT_UNLONG; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_LONG]) == 0) + return DMT_LONG; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_BOOL]) == 0) + return DMT_BOOL; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_TIME]) == 0) + return DMT_TIME; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_HEXBIN]) == 0) + return DMT_HEXBIN; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_BASE64]) == 0) + return DMT_BASE64; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_COMMAND]) == 0) + return DMT_COMMAND; + else if (DM_STRCMP(dm_type, DMT_TYPE[DMT_EVENT]) == 0) + return DMT_EVENT; + else + return DMT_STRING; + + return DMT_STRING; +} diff --git a/src/common.h b/src/common.h index 93a8cc1a2a2df7a918eb9f147ae1030698737cc0..ce0d13906dd8394d690e6ab32bc3b05a64e28cfd 100644 --- a/src/common.h +++ b/src/common.h @@ -46,7 +46,7 @@ void print_info(const char *format, ...); void print_debug(const char *format, ...); bool get_boolean_string(char *value); bool validate_msglen(struct blob_buf *bb); - +int get_dm_type(char *dm_type); #define DEBUG(fmt, args...) \ print_debug("[%s:%d]"fmt, __func__, __LINE__, ##args) diff --git a/src/events.c b/src/events.c index 2f1c13d41ad1cae6fcaf809bea08427a90c20287..150420174e6d234dd60f5ac6bccc82702bdaef58 100644 --- a/src/events.c +++ b/src/events.c @@ -23,7 +23,7 @@ #include "common.h" #include "events.h" #include "get_helper.h" -#include <libbbfdm/dmentry.h> +#include <libbbf_api/dmentry.h> #include <libubus.h> static struct event_map_list ev_map_list[] = { diff --git a/src/get.c b/src/get.c index c24b97efcd5c351536587bcbd4eaa731479d3019..992a4c968351b6e88a5399d39f4e8f46379ffd77 100644 --- a/src/get.c +++ b/src/get.c @@ -25,7 +25,7 @@ #include "pretty_print.h" #include "ipc.h" #include <libubus.h> -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> void init_dmmap(void) { @@ -38,7 +38,7 @@ void init_dmmap(void) get_resolved_paths(&bbf_ctx, ROOT_NODE, &resolved_list); // Commit dmmap - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); free_path_list(&resolved_list); bbf_cleanup(&bbf_ctx); @@ -130,7 +130,7 @@ void usp_get_value(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -177,7 +177,7 @@ void usp_validate_path(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -227,7 +227,7 @@ void usp_get_instance(usp_data_t *data) // Apply all bbfdm changes if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); @@ -278,7 +278,7 @@ void usp_get_name(usp_data_t *data) // Commit all bbfdm changes if transaction is not in progress if (is_transaction_running() == false) - bbf_uci_commit_bbfdm(); + dmuci_commit_bbfdm(); // free blob_buf_free(&bb); diff --git a/src/get_helper.c b/src/get_helper.c index d5600fa957a95cd204b22a4bd3daddf8c0bd8f8e..f259cabf4062cfa787464c907fec3b11724b3bdf 100644 --- a/src/get_helper.c +++ b/src/get_helper.c @@ -26,12 +26,21 @@ #include <time.h> #include <setjmp.h> -#include <libbbfdm/dmbbfcommon.h> - #include "get_helper.h" #include "common.h" #include "pretty_print.h" +#include <libbbf_api/dmentry.h> +#include <libbbf_dm/device.h> +#include <libbbf_dm/vendor.h> + +DMOBJ *DM_ROOT_OBJ = tEntry181Obj; +DM_MAP_VENDOR *DM_VENDOR_EXTENSION[2] = { + tVendorExtension, + tVendorExtensionOverwrite +}; +DM_MAP_VENDOR_EXCLUDE *DM_VENDOR_EXTENSION_EXCLUDE = tVendorExtensionExclude; + // uloop.h does not have versions, below line is to use // deprecated uloop_timeout_remaining for the time being #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -97,7 +106,7 @@ void bbf_configure_ubus(struct ubus_context *ctx) void bbf_init(struct dmctx *dm_ctx, int instance) { - dm_ctx_init(dm_ctx, instance); + dm_ctx_init(dm_ctx, DM_ROOT_OBJ, DM_VENDOR_EXTENSION, DM_VENDOR_EXTENSION_EXCLUDE, instance); } void bbf_cleanup(struct dmctx *dm_ctx) @@ -117,7 +126,7 @@ static void bbf_sub_init(struct dmctx *dm_ctx, char *path) instance = INSTANCE_MODE_ALIAS; } DEBUG("instance|%u|", instance); - dm_ctx_init_sub(dm_ctx, instance); + dm_ctx_init_sub(dm_ctx, DM_ROOT_OBJ, DM_VENDOR_EXTENSION, DM_VENDOR_EXTENSION_EXCLUDE, instance); } static void bbf_sub_cleanup(struct dmctx *dm_ctx) diff --git a/src/get_helper.h b/src/get_helper.h index 159adb2425e278b9f915415df04291376d0b36e1..e23970cc4f309db1d00b2f0c03599e4344eb2d44 100644 --- a/src/get_helper.h +++ b/src/get_helper.h @@ -28,6 +28,8 @@ struct pathNode { char path[MAX_DM_PATH]; }; +extern DMOBJ *DM_ROOT_OBJ; + int resolve_path(struct dmctx *bbf_ctx, char *qPath, size_t pos, struct list_head *resolved_plist); diff --git a/src/operate.c b/src/operate.c index 59e5c68c8b57d39152af12bad07fe9b7e488ea1e..ead8745e8405b6b13fbb769e75a2217232d9e7fc 100644 --- a/src/operate.c +++ b/src/operate.c @@ -25,8 +25,8 @@ #include "get_helper.h" #include "pretty_print.h" #include "ipc.h" -#include <libbbfdm/dmbbfcommon.h> #include <libubus.h> +#include <libbbf_api/dmentry.h> static void usp_operate_cmd(usp_data_t *data, struct blob_buf *bb) { diff --git a/src/pretty_print.c b/src/pretty_print.c index 4aff473879852ab29f451c66ee7114f7e8c216f3..3cb4fd2d42d9d003f7ea164d7184cb553824b01e 100644 --- a/src/pretty_print.c +++ b/src/pretty_print.c @@ -23,7 +23,6 @@ #include "common.h" #include "get_helper.h" #include "pretty_print.h" -#include <libbbfdm/dmbbfcommon.h> // private function and structures diff --git a/src/set.c b/src/set.c index f5f12cf755d05c7df8d5c6d821ddce44e93458ca..80cb27e1566b5365b5bf0c1b3487a2303c9d09b6 100644 --- a/src/set.c +++ b/src/set.c @@ -23,8 +23,7 @@ #include "set.h" #include "get_helper.h" #include <libubus.h> -#include <libbbfdm/dmbbfcommon.h> - +#include <libbbf_api/dmentry.h> static const struct blobmsg_policy dm_setm_value_policy[] = { [DM_SET_V_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING }, @@ -78,7 +77,7 @@ int usp_set_value(usp_data_t *data) blobmsg_add_u8(&bb, "status", false); blobmsg_add_u32(&bb, "fault", (uint32_t)p->fault); blobmsg_close_table(&bb, table); - del_list_fault_param(p); + bbf_api_del_list_fault_param(p); } } } diff --git a/src/usp.c b/src/usp.c index a071dd25768599ef8b319c9e5395dfca7937f672..e9e37cec827ccd9cb4c96cdd8f9ed2c62d2808b4 100644 --- a/src/usp.c +++ b/src/usp.c @@ -30,8 +30,7 @@ #include <libubox/uloop.h> #include <libubus.h> #include <sys/prctl.h> - -#include <libbbfdm/dmbbfcommon.h> +#include <libbbf_api/dmentry.h> #include "usp.h" #include "set.h" @@ -1594,7 +1593,7 @@ bool usp_cleanup(struct usp_context *u) free_ubus_obj_list(&u->obj_list); free_path_list(&u->instances); free_path_list(&u->old_instances); - bbf_dm_cleanup(); + bbf_dm_cleanup(DM_ROOT_OBJ); return true; } diff --git a/test/cmocka/Makefile b/test/cmocka/Makefile index 85d22c48fbd8b2de53ba04c5127efb2c51077af2..493c74e9fdd79ed120e5266add32913b53541803 100644 --- a/test/cmocka/Makefile +++ b/test/cmocka/Makefile @@ -2,7 +2,7 @@ CC = gcc USPD_LIB_DIR ?= $(shell dirname $(PWD)) USPD_LIB = -luspd -L$(USPD_LIB_DIR) CMOCKA_LIB = -l cmocka -LIBS = $(USPD_LIB) $(CMOCKA_LIB) -luci -pthread -lubus -lubox -ljson-c -lblobmsg_json -lbbfdm -lpthread +LIBS = $(USPD_LIB) $(CMOCKA_LIB) -luci -pthread -lubus -lubox -ljson-c -lblobmsg_json -lpthread CFLAGS = -g -Wall -I../../src LDFLAGS = $(LIBS) -Wl,-rpath=$(USPD_LIB_DIR) -I$(USPD_LIB_DIR) UNIT_TESTS = unit_test_uspd