mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-14 04:49:58 +01:00
Wait for usp.raw to be available
This commit is contained in:
parent
7a9643c94b
commit
7c91fd390b
4 changed files with 99 additions and 13 deletions
87
cwmp.c
87
cwmp.c
|
|
@ -345,7 +345,7 @@ static void cwmp_schedule_session(struct cwmp *cwmp)
|
|||
}
|
||||
|
||||
pthread_cond_timedwait(&(cwmp->threshold_session_send), &(cwmp->mutex_session_send), &time_to_wait);
|
||||
|
||||
|
||||
if (thread_end) {
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
return;
|
||||
|
|
@ -571,6 +571,87 @@ int create_cwmp_var_state_files()
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
static bool g_usp_object_available = false;
|
||||
|
||||
static void lookup_event_cb(struct ubus_context *ctx, struct ubus_event_handler *ev,
|
||||
const char *type, struct blob_attr *msg)
|
||||
{
|
||||
static const struct blobmsg_policy policy = {
|
||||
"path", BLOBMSG_TYPE_STRING
|
||||
};
|
||||
struct blob_attr *attr;
|
||||
const char *path;
|
||||
|
||||
if (strcmp(type, "ubus.object.add") != 0)
|
||||
return;
|
||||
|
||||
blobmsg_parse(&policy, 1, &attr, blob_data(msg), blob_len(msg));
|
||||
if (!attr)
|
||||
return;
|
||||
|
||||
path = blobmsg_data(attr);
|
||||
if (strcmp(path, USP_OBJECT_NAME) == 0) {
|
||||
g_usp_object_available = true;
|
||||
uloop_end();
|
||||
}
|
||||
}
|
||||
|
||||
static void lookup_timeout_cb(struct uloop_timeout *timeout)
|
||||
{
|
||||
uloop_end();
|
||||
}
|
||||
|
||||
static int wait_for_usp_raw_object()
|
||||
{
|
||||
#define USP_RAW_WAIT_TIMEOUT 60
|
||||
|
||||
struct ubus_context *uctx;
|
||||
int ret;
|
||||
uint32_t ubus_id;
|
||||
struct ubus_event_handler add_event;
|
||||
struct uloop_timeout u_timeout;
|
||||
|
||||
g_usp_object_available = false;
|
||||
uctx = ubus_connect(NULL);
|
||||
if (uctx == NULL) {
|
||||
CWMP_LOG(ERROR, "Can't create ubus context");
|
||||
return FAULT_CPE_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
uloop_init();
|
||||
ubus_add_uloop(uctx);
|
||||
|
||||
// register for add event
|
||||
memset(&add_event, 0, sizeof(struct ubus_event_handler));
|
||||
add_event.cb = lookup_event_cb;
|
||||
ubus_register_event_handler(uctx, &add_event, "ubus.object.add");
|
||||
|
||||
// check if object already present
|
||||
ret = ubus_lookup_id(uctx, USP_OBJECT_NAME, &ubus_id);
|
||||
if (ret == 0) {
|
||||
g_usp_object_available = true;
|
||||
goto end;
|
||||
}
|
||||
|
||||
// Set timeout to expire lookup
|
||||
memset(&u_timeout, 0, sizeof(struct uloop_timeout));
|
||||
u_timeout.cb = lookup_timeout_cb;
|
||||
uloop_timeout_set(&u_timeout, USP_RAW_WAIT_TIMEOUT * 1000);
|
||||
|
||||
uloop_run();
|
||||
uloop_done();
|
||||
|
||||
end:
|
||||
ubus_free(uctx);
|
||||
|
||||
if (g_usp_object_available == false) {
|
||||
CWMP_LOG(ERROR, "%s object not found", USP_OBJECT_NAME);
|
||||
return FAULT_CPE_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
|
||||
{
|
||||
int error;
|
||||
|
|
@ -580,6 +661,10 @@ static int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
|
|||
if ((error = global_env_init(argc, argv, &env)))
|
||||
return error;
|
||||
|
||||
error = wait_for_usp_raw_object();
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
icwmp_init_list_services();
|
||||
|
||||
/* Only One instance should run*/
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ bool cwmp_transaction_start(char *app)
|
|||
{
|
||||
CWMP_LOG(INFO, "Starting transaction ...");
|
||||
bool status = false;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_start", CWMP_UBUS_ARGS{ { "app", { .str_val = app }, UBUS_String } }, 1, ubus_transaction_callback, &status);
|
||||
int e = cwmp_ubus_call(USP_OBJECT_NAME, "transaction_start", CWMP_UBUS_ARGS{ { "app", { .str_val = app }, UBUS_String } }, 1, ubus_transaction_callback, &status);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction start failed: Ubus err code: %d", e);
|
||||
status = false;
|
||||
|
|
@ -214,7 +214,7 @@ bool cwmp_transaction_commit()
|
|||
{
|
||||
CWMP_LOG(INFO, "Transaction Commit ...");
|
||||
bool status = false;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_commit", CWMP_UBUS_ARGS{ { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "restart_services", { .bool_val = false }, UBUS_Bool } }, 2, ubus_transaction_commit_callback, &status);
|
||||
int e = cwmp_ubus_call(USP_OBJECT_NAME, "transaction_commit", CWMP_UBUS_ARGS{ { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "restart_services", { .bool_val = false }, UBUS_Bool } }, 2, ubus_transaction_commit_callback, &status);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction commit failed: Ubus err code: %d", e);
|
||||
status = false;
|
||||
|
|
@ -231,7 +231,7 @@ bool cwmp_transaction_abort()
|
|||
{
|
||||
CWMP_LOG(INFO, "Transaction Abort ...");
|
||||
bool status = false;
|
||||
int e = cwmp_ubus_call("usp.raw", "transaction_abort", CWMP_UBUS_ARGS{ { "transaction_id", { .int_val = transaction_id }, UBUS_Integer } }, 1, ubus_transaction_callback, &status);
|
||||
int e = cwmp_ubus_call(USP_OBJECT_NAME, "transaction_abort", CWMP_UBUS_ARGS{ { "transaction_id", { .int_val = transaction_id }, UBUS_Integer } }, 1, ubus_transaction_callback, &status);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Transaction abort failed: Ubus err code: %d", e);
|
||||
status = false;
|
||||
|
|
@ -247,7 +247,7 @@ 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);
|
||||
int e = cwmp_ubus_call(USP_OBJECT_NAME, "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;
|
||||
|
|
@ -292,7 +292,7 @@ char *cwmp_get_single_parameter_value(char *parameter_name, struct cwmp_dm_param
|
|||
{
|
||||
int e;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{ { "path", { .str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 3, ubus_get_single_parameter_callback, dm_parameter);
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "get", CWMP_UBUS_ARGS{ { "path", { .str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 3, ubus_get_single_parameter_callback, dm_parameter);
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "get ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
|
|
@ -332,7 +332,7 @@ char *cwmp_get_parameter_values(char *parameter_name, struct list_head *paramete
|
|||
int e;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct list_params_result get_result = { .parameters_list = parameters_list };
|
||||
e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{ { "path", { .str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 3, ubus_get_parameter_callback, &get_result);
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "get", CWMP_UBUS_ARGS{ { "path", { .str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 3, ubus_get_parameter_callback, &get_result);
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "get ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
|
|
@ -350,7 +350,7 @@ char *cwmp_get_multiple_parameters_values(struct list_head *arg_params_list, str
|
|||
int e;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct list_params_result get_result = { .parameters_list = parameters_list };
|
||||
e = cwmp_ubus_call("usp.raw", "getm_values", CWMP_UBUS_ARGS{ { "paths", { .param_value_list = arg_params_list }, UBUS_List_Param_Get }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 2, ubus_get_parameter_callback, &get_result );
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "getm_values", CWMP_UBUS_ARGS{ { "paths", { .param_value_list = arg_params_list }, UBUS_List_Param_Get }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 2, ubus_get_parameter_callback, &get_result );
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "getm_values ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
|
|
@ -368,7 +368,7 @@ char *cwmp_get_parameter_names(char *object_name, bool next_level, struct list_h
|
|||
int e;
|
||||
struct list_params_result get_result = { .parameters_list = parameters_list };
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
e = cwmp_ubus_call("usp.raw", "object_names", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "next-level", { .bool_val = next_level }, UBUS_Bool }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 4, ubus_get_parameter_callback, &get_result);
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "object_names", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "next-level", { .bool_val = next_level }, UBUS_Bool }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 4, ubus_get_parameter_callback, &get_result);
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "object_names ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
|
|
@ -420,7 +420,7 @@ int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list
|
|||
int e;
|
||||
struct setm_values_res set_result = { .flag = flag, .faults_list = faults_list };
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
e = cwmp_ubus_call("usp.raw", "setm_values",
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "setm_values",
|
||||
CWMP_UBUS_ARGS{ { "pv_tuple", { .param_value_list = parameters_values_list }, UBUS_List_Param_Set }, { "key", { .str_val = parameter_key }, UBUS_String }, { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 5,
|
||||
ubus_setm_values_callback, &set_result);
|
||||
|
||||
|
|
@ -473,7 +473,7 @@ char *cwmp_add_object(char *object_name, char *key, char **instance)
|
|||
int e;
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
struct object_result add_result = { .instance = instance };
|
||||
e = cwmp_ubus_call("usp.raw", "add_object", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "key", { .str_val = key }, UBUS_String }, { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 5,
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "add_object", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "key", { .str_val = key }, UBUS_String }, { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 5,
|
||||
ubus_objects_callback, &add_result);
|
||||
|
||||
if (e < 0) {
|
||||
|
|
@ -492,7 +492,7 @@ char *cwmp_delete_object(char *object_name, char *key)
|
|||
int e;
|
||||
struct object_result add_result = { .instance = NULL };
|
||||
struct cwmp *cwmp = &cwmp_main;
|
||||
e = cwmp_ubus_call("usp.raw", "del_object", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "key", { .str_val = key }, UBUS_String }, { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 5,
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "del_object", CWMP_UBUS_ARGS{ { "path", { .str_val = object_name }, UBUS_String }, { "key", { .str_val = key }, UBUS_String }, { "transaction_id", { .int_val = transaction_id }, UBUS_Integer }, { "proto", { .str_val = "cwmp" }, UBUS_String }, { "instance_mode", { .int_val = cwmp->conf.instance_mode }, UBUS_Integer } }, 5,
|
||||
ubus_objects_callback, &add_result);
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "del_object ubus method failed: Ubus err code: %d", e);
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ static int cwmp_diagnostics_operate(char *diagnostics_object, char *action_name,
|
|||
continue;
|
||||
add_dm_parameter_to_list(&diagnostics_param_value_list, diagnostics_array[i].input_name, diagnostics_array[i].value, NULL, 0, false);
|
||||
}
|
||||
e = cwmp_ubus_call("usp.raw", "operate", CWMP_UBUS_ARGS{ { "path", {.str_val = diagnostics_object }, UBUS_String }, { "action", {.str_val = action_name }, UBUS_String }, { "input", {.param_value_list = &diagnostics_param_value_list }, UBUS_Obj_Obj } }, 3, empty_ubus_callback, NULL);
|
||||
e = cwmp_ubus_call(USP_OBJECT_NAME, "operate", CWMP_UBUS_ARGS{ { "path", {.str_val = diagnostics_object }, UBUS_String }, { "action", {.str_val = action_name }, UBUS_String }, { "input", {.param_value_list = &diagnostics_param_value_list }, UBUS_Obj_Obj } }, 3, empty_ubus_callback, NULL);
|
||||
if (e)
|
||||
return -1;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#define ARRAYSIZEOF(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
#define USP_OBJECT_NAME "usp.raw"
|
||||
#define MAX_EVENTS 64
|
||||
#define MAX_INT32 2147483646
|
||||
#define MAX_INT_ID MAX_INT32
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue