From e6586067f97fd83acbfd2ea0ab2dc21fe4a4f974 Mon Sep 17 00:00:00 2001 From: vdutta Date: Mon, 17 May 2021 19:27:51 +0530 Subject: [PATCH] Revert ubus -s changes --- common.c | 11 ++++------- config.c | 16 +++++++++++---- cwmp.c | 8 ++------ datamodel_interface.c | 5 +---- inc/common.h | 2 +- inc/cwmp_uci.h | 1 + ubus.c | 45 +++++++++++++++++-------------------------- 7 files changed, 39 insertions(+), 49 deletions(-) diff --git a/common.c b/common.c index c3f574b..a2f206e 100644 --- a/common.c +++ b/common.c @@ -27,12 +27,11 @@ char *commandKey = NULL; long int flashsize = 256000000; static unsigned long int next_rand_seed = 1; -struct option cwmp_long_options[] = { { "boot-event", no_argument, NULL, 'b' }, { "get-rpc-methods", no_argument, NULL, 'g' }, { "command-input", no_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, {"ubus_socket", required_argument, NULL, 's'}, { NULL, 0, NULL, 0 } }; +struct option cwmp_long_options[] = { { "boot-event", no_argument, NULL, 'b' }, { "get-rpc-methods", no_argument, NULL, 'g' }, { "command-input", no_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; static void show_help(void) { printf("Usage: icwmpd [OPTIONS]\n"); - printf(" -s, --ubus_socket Ubus socket path for IPC\n"); printf(" -b, --boot-event (CWMP daemon) Start CWMP with BOOT event\n"); printf(" -g, --get-rpc-methods (CWMP daemon) Start CWMP with GetRPCMethods request to ACS\n"); printf(" -c, --cli CWMP CLI\n"); @@ -49,11 +48,11 @@ static void show_version() #endif } -int global_env_init(int argc, char **argv, struct env *env, struct config *conf) +int global_env_init(int argc, char **argv, struct env *env) { int c, option_index = 0; - while ((c = getopt_long(argc, argv, "bgchvs:", cwmp_long_options, &option_index)) != -1) { + while ((c = getopt_long(argc, argv, "bgchv", cwmp_long_options, &option_index)) != -1) { switch (c) { case 'b': env->boot = CWMP_START_BOOT; @@ -68,9 +67,7 @@ int global_env_init(int argc, char **argv, struct env *env, struct config *conf) case 'h': show_help(); exit(0); - case 's': - conf->ubus_socket = strdup(optarg); - break; + case 'v': show_version(); exit(0); diff --git a/config.c b/config.c index 048f465..c71ff62 100644 --- a/config.c +++ b/config.c @@ -10,13 +10,9 @@ * Author Omar Kallel */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include "config.h" #include "cwmp_uci.h" #include "log.h" -#include pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER; @@ -266,6 +262,18 @@ int get_global_config(struct config *conf) return error; } + if ((error = uci_get_value(UCI_CPE_UBUS_SOCKET_PATH, &value)) == CWMP_OK) { + if (value != NULL) { + if (conf->ubus_socket != NULL) { + free(conf->ubus_socket); + } + conf->ubus_socket = value; + value = NULL; + } + } else { + return error; + } + if ((error = uci_get_value(UCI_LOG_SEVERITY_PATH, &value)) == CWMP_OK) { if (value != NULL) { log_set_severity_idx(value); diff --git a/cwmp.c b/cwmp.c index 8f673a5..662ee8b 100644 --- a/cwmp.c +++ b/cwmp.c @@ -440,6 +440,8 @@ int cwmp_init(int argc, char **argv, struct cwmp *cwmp) struct env env; memset(&env, 0, sizeof(struct env)); + if ((error = global_env_init(argc, argv, &env))) + return error; /* Only One instance should run*/ cwmp->pid_file = fopen("/var/run/icwmpd.pid", "w+"); @@ -455,10 +457,6 @@ int cwmp_init(int argc, char **argv, struct cwmp *cwmp) exit(EXIT_SUCCESS); } - if ((error = global_env_init(argc, argv, &env, &cwmp->conf))) - return error; - - pthread_mutex_init(&cwmp->mutex_periodic, NULL); pthread_mutex_init(&cwmp->mutex_session_queue, NULL); pthread_mutex_init(&cwmp->mutex_session_send, NULL); @@ -514,8 +512,6 @@ int main(int argc, char **argv) struct sigaction act = { 0 }; - memset(&cwmp_main, 0, sizeof(struct cwmp)); - if ((error = cwmp_init(argc, argv, cwmp))) return error; diff --git a/datamodel_interface.c b/datamodel_interface.c index 3718a87..4dff9ac 100644 --- a/datamodel_interface.c +++ b/datamodel_interface.c @@ -194,15 +194,12 @@ bool cwmp_transaction_status() CWMP_LOG(INFO, "Transaction Status"); bool status = false; int e = cwmp_ubus_call("usp.raw", "transaction_status", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, ubus_transaction_status_callback, &status); - if (e != 0) { CWMP_LOG(INFO, "Transaction status failed: Ubus err code: %d", e); return false; } - if (!status) { + if (!status) CWMP_LOG(INFO, "Transaction with id: %d is not available anymore\n", transaction_id); - } - return status; } /* diff --git a/inc/common.h b/inc/common.h index 860026f..a748aff 100644 --- a/inc/common.h +++ b/inc/common.h @@ -446,7 +446,7 @@ int cwmp_exit(void); void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *param_data, char *param_type, int notification, bool writable); void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter); void cwmp_free_all_dm_parameter_list(struct list_head *list); -int global_env_init(int argc, char **argv, struct env *env, struct config *conf); +int global_env_init(int argc, char **argv, struct env *env); void cwmp_add_list_fault_param(char *param, int fault, struct list_head *list_set_value_fault); void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault); void cwmp_free_all_list_param_fault(struct list_head *list_param_fault); diff --git a/inc/cwmp_uci.h b/inc/cwmp_uci.h index 2469cd1..9c8021e 100644 --- a/inc/cwmp_uci.h +++ b/inc/cwmp_uci.h @@ -37,6 +37,7 @@ #define UCI_CPE_USERID_PATH "cwmp.cpe.userid" #define UCI_CPE_PASSWD_PATH "cwmp.cpe.passwd" #define UCI_CPE_INTERFACE_PATH "cwmp.cpe.interface" +#define UCI_CPE_UBUS_SOCKET_PATH "cwmp.cpe.ubus_socket" #define UCI_CPE_PORT_PATH "cwmp.cpe.port" #define UCI_CPE_DEFAULT_WAN_IFACE "cwmp.cpe.default_wan_interface" #define UCI_CPE_CRPATH_PATH "cwmp.cpe.path" diff --git a/ubus.c b/ubus.c index 346ac5d..34065ca 100644 --- a/ubus.c +++ b/ubus.c @@ -50,15 +50,6 @@ void *thread_exit_program(void *v __attribute__((unused))) exit(EXIT_SUCCESS); } -static void add_kv_string_to_blob(struct blob_buf *bb, const char *key, const char *val) -{ - if (val) { - blobmsg_add_string(bb, key, val); - } else { - blobmsg_add_string(bb, key, ""); - } -} - static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg) { struct blob_attr *tb[__COMMAND_MAX]; @@ -119,7 +110,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj blobmsg_add_u32(&b, "status", 0); if (cwmp_asprintf(&info, "icwmpd daemon stopped") == -1) return -1; - add_kv_string_to_blob(&b, "info", info); + blobmsg_add_string(&b, "info", info); free(info); ubus_send_reply(ctx, req, b.head); @@ -141,7 +132,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj return -1; } - add_kv_string_to_blob(&b, "info", info); + blobmsg_add_string(&b, "info", info); free(info); ubus_send_reply(ctx, req, b.head); @@ -176,22 +167,22 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj blob_buf_init(&b, 0); c = blobmsg_open_table(&b, "cwmp"); - add_kv_string_to_blob(&b, "status", "up"); - add_kv_string_to_blob(&b, "start_time", mix_get_time_of(cwmp_main.start_time)); - add_kv_string_to_blob(&b, "acs_url", cwmp_main.conf.acsurl); + blobmsg_add_string(&b, "status", "up"); + blobmsg_add_string(&b, "start_time", mix_get_time_of(cwmp_main.start_time)); + blobmsg_add_string(&b, "acs_url", cwmp_main.conf.acsurl); blobmsg_close_table(&b, c); c = blobmsg_open_table(&b, "last_session"); - blobmsg_add_string(&b, "status", (cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A")); - blobmsg_add_string(&b, "start_time", (cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A")); - blobmsg_add_string(&b, "end_time", (cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A")); + blobmsg_add_string(&b, "status", cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A"); + blobmsg_add_string(&b, "start_time", cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A"); + blobmsg_add_string(&b, "end_time", cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A"); blobmsg_close_table(&b, c); c = blobmsg_open_table(&b, "next_session"); blobmsg_add_string(&b, "status", arr_session_status[SESSION_WAITING]); ntime = get_session_status_next_time(); - blobmsg_add_string(&b, "start_time", (ntime ? mix_get_time_of(ntime) : "N/A")); - add_kv_string_to_blob(&b, "end_time", "N/A"); + blobmsg_add_string(&b, "start_time", ntime ? mix_get_time_of(ntime) : "N/A"); + blobmsg_add_string(&b, "end_time", "N/A"); blobmsg_close_table(&b, c); c = blobmsg_open_table(&b, "statistics"); @@ -251,7 +242,7 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj pthread_mutex_unlock(&(cwmp_main.mutex_session_queue)); pthread_cond_signal(&(cwmp_main.threshold_session_send)); blobmsg_add_u32(&b, "status", 1); - add_kv_string_to_blob(&b, "info", "Session with GetRPCMethods will start"); + blobmsg_add_string(&b, "info", "Session with GetRPCMethods will start"); } else { int event_code = cwmp_get_int_event_code(event); pthread_mutex_lock(&(cwmp_main.mutex_session_queue)); @@ -260,10 +251,10 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj pthread_cond_signal(&(cwmp_main.threshold_session_send)); if (cwmp_main.session_status.last_status == SESSION_RUNNING) { blobmsg_add_u32(&b, "status", -1); - add_kv_string_to_blob(&b, "info", "Session already running, event will be sent at the end of the session"); + blobmsg_add_string(&b, "info", "Session already running, event will be sent at the end of the session"); } else { blobmsg_add_u32(&b, "status", 1); - add_kv_string_to_blob(&b, "info", "Session started"); + blobmsg_add_string(&b, "info", "Session started"); } } ubus_send_reply(ctx, req, b.head); @@ -334,7 +325,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a blob_buf_init(&b, 0); for (i = 0; i < u_args_size; i++) { if (u_args[i].type == UBUS_String) - add_kv_string_to_blob(&b, u_args[i].key, u_args[i].val.str_val); + blobmsg_add_string(&b, u_args[i].key, u_args[i].val.str_val); else if (u_args[i].type == UBUS_Integer) { blobmsg_add_u32(&b, u_args[i].key, u_args[i].val.int_val); } else if (u_args[i].type == UBUS_Array_Obj || u_args[i].type == UBUS_Array_Str) { @@ -346,7 +337,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a for (j = 0; j < ARRAY_MAX; j++) { if (u_args[i].val.array_value[j].param_value.key == NULL || strlen(u_args[i].val.array_value[j].param_value.key) <= 0) break; - add_kv_string_to_blob(&b, u_args[i].val.array_value[j].param_value.key, u_args[i].val.array_value[j].param_value.value); + blobmsg_add_string(&b, u_args[i].val.array_value[j].param_value.key, u_args[i].val.array_value[j].param_value.value); } blobmsg_close_table(&b, t); } @@ -354,7 +345,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a for (j = 0; j < ARRAY_MAX; j++) { if (u_args[i].val.array_value[j].str_value == NULL || strlen(u_args[i].val.array_value[j].str_value) <= 0) break; - add_kv_string_to_blob(&b, NULL, u_args[i].val.array_value[j].str_value); + blobmsg_add_string(&b, NULL, u_args[i].val.array_value[j].str_value); } } blobmsg_close_array(&b, a); @@ -366,8 +357,8 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a if (!param_value->name) break; t = blobmsg_open_table(&b, ""); - add_kv_string_to_blob(&b, "path", param_value->name); - add_kv_string_to_blob(&b, "value", param_value->value); + blobmsg_add_string(&b, "path", param_value->name); + blobmsg_add_string(&b, "value", param_value->value); blobmsg_close_table(&b, t); } blobmsg_close_array(&b, a);