Ticket #6702: icwmp migrate from multithreading to ulooop (enhance sessions events manipulations)

This commit is contained in:
Omar Kallel 2021-12-23 16:47:11 +01:00
parent bb5c690146
commit 24f856aad7
45 changed files with 1387 additions and 1695 deletions

View file

@ -23,7 +23,13 @@ run_unit_test:
when: always
paths:
- timestamp.log
- memory-report.xml
- icwmp_datamodel_interface_unit_testd-mem-report.xml
- icwmp_soap_msg_unit_testd-mem-report.xml
- icwmp_backup_session_unit_testd-mem-report.xml
- icwmp_custom_inform_parameters_unit_testd-mem-report.xml
- icwmp_notifications_unit_testd-mem-report.xml
- icwmp_uci_unit_testd-mem-report.xml
- icwmp_cli_unit_testd-mem-report.xml
- unit-test-coverage.xml
run_api_test:

View file

@ -19,7 +19,7 @@
#include "event.h"
#include "download.h"
#include "cwmp_du_state.h"
#include "rpc_soap.h"
#include "soap.h"
#include "upload.h"
#include "sched_inform.h"
@ -753,11 +753,9 @@ void bkp_session_delete_transfer_complete(struct transfer_complete *ptransfer_co
pthread_mutex_unlock(&mutex_backup_session);
}
int save_acs_bkp_config(struct cwmp *cwmp)
int save_acs_bkp_config()
{
struct config *conf;
conf = &(cwmp->conf);
struct config *conf = &(cwmp_main->conf);
bkp_session_simple_insert("acs", "url", conf->acsurl);
bkp_session_save();
return CWMP_OK;
@ -785,7 +783,7 @@ char *load_child_value(mxml_node_t *tree, char *sub_name)
return value;
}
void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp)
void load_queue_event(mxml_node_t *tree)
{
char *command_key = NULL;
mxml_node_t *b = tree, *c;
@ -802,7 +800,7 @@ void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp)
if (strcmp(b->value.element.name, "command_key") == 0) {
if (idx != -1) {
if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) {
event_container_save = cwmp_add_event_container(cwmp, idx, ((command_key != NULL) ? command_key : ""));
event_container_save = cwmp_add_event_container(idx, ((command_key != NULL) ? command_key : ""));
if (event_container_save != NULL) {
event_container_save->id = id;
}
@ -1003,7 +1001,7 @@ void load_change_du_state(mxml_node_t *tree)
list_add_tail(&(change_du_state_request->list_operation), &(list_change_du_state));
}
void load_du_state_change_complete(mxml_node_t *tree, struct cwmp *cwmp)
void load_du_state_change_complete(mxml_node_t *tree)
{
mxml_node_t *b = tree;
struct du_state_change_complete *du_state_change_complete_request = NULL;
@ -1037,10 +1035,10 @@ void load_du_state_change_complete(mxml_node_t *tree, struct cwmp *cwmp)
}
b = mxmlWalkNext(b, tree, MXML_NO_DESCEND);
}
cwmp_root_cause_changedustate_complete(cwmp, du_state_change_complete_request);
cwmp_root_cause_changedustate_complete(du_state_change_complete_request);
}
void load_transfer_complete(mxml_node_t *tree, struct cwmp *cwmp)
void load_transfer_complete(mxml_node_t *tree)
{
struct transfer_complete *ptransfer_complete;
@ -1054,8 +1052,8 @@ void load_transfer_complete(mxml_node_t *tree, struct cwmp *cwmp)
.type = &ptransfer_complete->type };
load_specific_backup_attributes(tree, &bkp_attrs);
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
sotfware_version_value_change(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
sotfware_version_value_change(ptransfer_complete);
}
void bkp_session_create_file()
@ -1100,16 +1098,16 @@ int bkp_session_check_file()
return 0;
}
int cwmp_init_backup_session(struct cwmp *cwmp, char **ret, enum backup_loading load)
int cwmp_init_backup_session(char **ret, enum backup_loading load)
{
int error;
if (bkp_session_check_file())
return 0;
error = cwmp_load_saved_session(cwmp, ret, load);
error = cwmp_load_saved_session(ret, load);
return error;
}
int cwmp_load_saved_session(struct cwmp *cwmp, char **ret, enum backup_loading load)
int cwmp_load_saved_session(char **ret, enum backup_loading load)
{
mxml_node_t *b;
@ -1142,19 +1140,19 @@ int cwmp_load_saved_session(struct cwmp *cwmp, char **ret, enum backup_loading l
}
if (load == ALL) {
if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "queue_event") == 0) {
load_queue_event(b, cwmp);
load_queue_event(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "download") == 0) {
load_download(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "upload") == 0) {
load_upload(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "transfer_complete") == 0) {
load_transfer_complete(b, cwmp);
load_transfer_complete(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "schedule_inform") == 0) {
load_schedule_inform(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "change_du_state") == 0) {
load_change_du_state(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "du_state_change_complete") == 0) {
load_du_state_change_complete(b, cwmp);
load_du_state_change_complete(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "schedule_download") == 0) {
load_schedule_download(b);
} else if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "apply_schedule_download") == 0) {

View file

@ -25,7 +25,7 @@ icwmpd_SOURCES = \
../upload.c \
../sched_inform.c \
../xml.c \
../rpc_soap.c \
../soap.c \
../diagnostic.c \
../reboot.c \
../cwmp.c
@ -37,7 +37,7 @@ icwmpd_CFLAGS = \
$(LIBUBUS_CFLAGS) \
$(MICROXML_CFLAGS) \
$(LIBCURL_CFLAGS) \
-Wall -Wextra \
-g -Wall -Wextra \
-Wformat
icwmpd_LDFLAGS = \

View file

@ -32,13 +32,13 @@
#endif
char *commandKey = NULL;
bool thread_end = false;
bool signal_exit = false;
bool cwmp_stop = false;
bool ubus_exit = false;
long int flashsize = 256000000;
struct cwmp cwmp_main = { 0 };
struct cwmp *cwmp_main = NULL;
static int nbre_services = 0;
static char *list_services[MAX_NBRE_SERVICES] = { 0 };
bool g_firewall_restart = false;
LIST_HEAD(cwmp_memory_list);
struct cwmp_mem {
@ -54,51 +54,33 @@ struct option cwmp_long_options[] = {
struct FAULT_CPE FAULT_CPE_ARRAY[] = {
[FAULT_CPE_METHOD_NOT_SUPPORTED] = { "9000", FAULT_9000, FAULT_CPE_TYPE_SERVER, "Method not supported" },
[FAULT_CPE_REQUEST_DENIED] = { "9001", FAULT_9001, FAULT_CPE_TYPE_SERVER,
"Request denied (no reason specified)" },
[FAULT_CPE_REQUEST_DENIED] = { "9001", FAULT_9001, FAULT_CPE_TYPE_SERVER, "Request denied (no reason specified)" },
[FAULT_CPE_INTERNAL_ERROR] = { "9002", FAULT_9002, FAULT_CPE_TYPE_SERVER, "Internal error" },
[FAULT_CPE_INVALID_ARGUMENTS] = { "9003", FAULT_9003, FAULT_CPE_TYPE_CLIENT, "Invalid arguments" },
[FAULT_CPE_RESOURCES_EXCEEDED] = { "9004", FAULT_9004, FAULT_CPE_TYPE_SERVER, "Resources exceeded" },
[FAULT_CPE_INVALID_PARAMETER_NAME] = { "9005", FAULT_9005, FAULT_CPE_TYPE_CLIENT, "Invalid parameter name" },
[FAULT_CPE_INVALID_PARAMETER_TYPE] = { "9006", FAULT_9006, FAULT_CPE_TYPE_CLIENT, "Invalid parameter type" },
[FAULT_CPE_INVALID_PARAMETER_VALUE] = { "9007", FAULT_9007, FAULT_CPE_TYPE_CLIENT, "Invalid parameter value" },
[FAULT_CPE_NON_WRITABLE_PARAMETER] = { "9008", FAULT_9008, FAULT_CPE_TYPE_CLIENT,
"Attempt to set a non-writable parameter" },
[FAULT_CPE_NOTIFICATION_REJECTED] = { "9009", FAULT_9009, FAULT_CPE_TYPE_SERVER,
"Notification request rejected" },
[FAULT_CPE_NON_WRITABLE_PARAMETER] = { "9008", FAULT_9008, FAULT_CPE_TYPE_CLIENT, "Attempt to set a non-writable parameter" },
[FAULT_CPE_NOTIFICATION_REJECTED] = { "9009", FAULT_9009, FAULT_CPE_TYPE_SERVER, "Notification request rejected" },
[FAULT_CPE_DOWNLOAD_FAILURE] = { "9010", FAULT_9010, FAULT_CPE_TYPE_SERVER, "Download failure" },
[FAULT_CPE_UPLOAD_FAILURE] = { "9011", FAULT_9011, FAULT_CPE_TYPE_SERVER, "Upload failure" },
[FAULT_CPE_FILE_TRANSFER_AUTHENTICATION_FAILURE] = { "9012", FAULT_9012, FAULT_CPE_TYPE_SERVER,
"File transfer server authentication failure" },
[FAULT_CPE_FILE_TRANSFER_UNSUPPORTED_PROTOCOL] = { "9013", FAULT_9013, FAULT_CPE_TYPE_SERVER,
"Unsupported protocol for file transfer" },
[FAULT_CPE_DOWNLOAD_FAIL_MULTICAST_GROUP] = { "9014", FAULT_9014, FAULT_CPE_TYPE_SERVER,
"Download failure: unable to join multicast group" },
[FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER] = { "9015", FAULT_9015, FAULT_CPE_TYPE_SERVER,
"Download failure: unable to contact file server" },
[FAULT_CPE_DOWNLOAD_FAIL_ACCESS_FILE] = { "9016", FAULT_9016, FAULT_CPE_TYPE_SERVER,
"Download failure: unable to access file" },
[FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD] = { "9017", FAULT_9017, FAULT_CPE_TYPE_SERVER,
"Download failure: unable to complete download" },
[FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED] = { "9018", FAULT_9018, FAULT_CPE_TYPE_SERVER,
"Download failure: file corrupted" },
[FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION] = { "9019", FAULT_9019, FAULT_CPE_TYPE_SERVER,
"Download failure: file authentication failure" },
[FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW] = { "9020", FAULT_9020, FAULT_CPE_TYPE_SERVER,
"Download failure: unable to complete download" },
[FAULT_CPE_DUPLICATE_DEPLOYMENT_UNIT] = { "9026", FAULT_9026, FAULT_CPE_TYPE_SERVER,
"Duplicate deployment unit" },
[FAULT_CPE_SYSTEM_RESOURCES_EXCEEDED] = { "9027", FAULT_9027, FAULT_CPE_TYPE_SERVER,
"System ressources exceeded" },
[FAULT_CPE_FILE_TRANSFER_AUTHENTICATION_FAILURE] = { "9012", FAULT_9012, FAULT_CPE_TYPE_SERVER, "File transfer server authentication failure" },
[FAULT_CPE_FILE_TRANSFER_UNSUPPORTED_PROTOCOL] = { "9013", FAULT_9013, FAULT_CPE_TYPE_SERVER, "Unsupported protocol for file transfer" },
[FAULT_CPE_DOWNLOAD_FAIL_MULTICAST_GROUP] = { "9014", FAULT_9014, FAULT_CPE_TYPE_SERVER, "Download failure: unable to join multicast group" },
[FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER] = { "9015", FAULT_9015, FAULT_CPE_TYPE_SERVER, "Download failure: unable to contact file server" },
[FAULT_CPE_DOWNLOAD_FAIL_ACCESS_FILE] = { "9016", FAULT_9016, FAULT_CPE_TYPE_SERVER, "Download failure: unable to access file" },
[FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD] = { "9017", FAULT_9017, FAULT_CPE_TYPE_SERVER, "Download failure: unable to complete download" },
[FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED] = { "9018", FAULT_9018, FAULT_CPE_TYPE_SERVER, "Download failure: file corrupted" },
[FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION] = { "9019", FAULT_9019, FAULT_CPE_TYPE_SERVER, "Download failure: file authentication failure" },
[FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW] = { "9020", FAULT_9020, FAULT_CPE_TYPE_SERVER, "Download failure: unable to complete download" },
[FAULT_CPE_DUPLICATE_DEPLOYMENT_UNIT] = { "9026", FAULT_9026, FAULT_CPE_TYPE_SERVER, "Duplicate deployment unit" },
[FAULT_CPE_SYSTEM_RESOURCES_EXCEEDED] = { "9027", FAULT_9027, FAULT_CPE_TYPE_SERVER, "System ressources exceeded" },
[FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT] = { "9028", FAULT_9028, FAULT_CPE_TYPE_SERVER, "Unknown deployment unit" },
[FAULT_CPE_INVALID_DEPLOYMENT_UNIT_STATE] = { "9029", FAULT_9029, FAULT_CPE_TYPE_SERVER,
"Invalid deployment unit state" },
[FAULT_CPE_INVALID_DOWNGRADE_REJECTED] = { "9030", FAULT_9030, FAULT_CPE_TYPE_SERVER,
"Invalid deployment unit Update: Downgrade not permitted" },
[FAULT_CPE_INVALID_UPDATE_VERSION_UNSPECIFIED] = { "9031", FAULT_9031, FAULT_CPE_TYPE_SERVER,
"Invalid deployment unit Update: Version not specified" },
[FAULT_CPE_INVALID_UPDATE_VERSION_EXIST] = { "9031", FAULT_9032, FAULT_CPE_TYPE_SERVER,
"Invalid deployment unit Update: Version already exist" }
[FAULT_CPE_INVALID_DEPLOYMENT_UNIT_STATE] = { "9029", FAULT_9029, FAULT_CPE_TYPE_SERVER, "Invalid deployment unit state" },
[FAULT_CPE_INVALID_DOWNGRADE_REJECTED] = { "9030", FAULT_9030, FAULT_CPE_TYPE_SERVER, "Invalid deployment unit Update: Downgrade not permitted" },
[FAULT_CPE_INVALID_UPDATE_VERSION_UNSPECIFIED] = { "9031", FAULT_9031, FAULT_CPE_TYPE_SERVER, "Invalid deployment unit Update: Version not specified" },
[FAULT_CPE_INVALID_UPDATE_VERSION_EXIST] = { "9031", FAULT_9032, FAULT_CPE_TYPE_SERVER, "Invalid deployment unit Update: Version already exist" }
};
static void show_help(void)
@ -292,6 +274,44 @@ void get_firewall_zone_name_by_wan_iface(char *if_wan, char **zone_name)
}
}
int get_firewall_restart_state(char **state)
{
cwmp_uci_reinit();
return uci_get_state_value(UCI_CPE_FIREWALL_RESTART_STATE, state);
}
// wait till firewall restart is not complete or 5 sec, whichever is less
void check_firewall_restart_state()
{
int count = 0;
bool init = false;
do {
char *state = NULL;
if (get_firewall_restart_state(&state) != CWMP_OK)
break;
if (state != NULL && strcmp(state, "init") == 0) {
init = true;
FREE(state);
break;
}
usleep(500 * 1000);
FREE(state);
count++;
} while(count < 10);
// mark the firewall restart as done
g_firewall_restart = false;
if (init == false) { // In case of timeout reset the firewall_restart flag
CWMP_LOG(ERROR, "Firewall restart took longer than usual");
cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "init");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
}
}
/*
* Reboot
*/

View file

@ -18,8 +18,9 @@
pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER;
static int check_global_config(struct config *conf)
static int check_global_config()
{
struct config *conf = &(cwmp_main->conf);
if (conf->acsurl == NULL) {
conf->acsurl = strdup(DEFAULT_ACSURL);
}
@ -42,8 +43,9 @@ static time_t convert_datetime_to_timestamp(char *value)
return mktime(&tm);
}
int get_global_config(struct config *conf)
int get_global_config()
{
struct config *conf = &(cwmp_main->conf);
int error, error2, error3;
char *value = NULL, *value2 = NULL, *value3 = NULL;
@ -604,20 +606,19 @@ int get_global_config(struct config *conf)
return CWMP_OK;
}
int global_conf_init(struct cwmp *cwmp)
int global_conf_init()
{
int error = CWMP_OK;
pthread_mutex_lock(&mutex_config_load);
if ((error = get_global_config(&(cwmp->conf))))
if ((error = get_global_config(&(cwmp_main->conf))))
goto end;
if ((error = check_global_config(&(cwmp->conf))))
if ((error = check_global_config(&(cwmp_main->conf))))
goto end;
/* Launch reboot methods if needed */
launch_reboot_methods(cwmp);
launch_reboot_methods();
end:
pthread_mutex_unlock(&mutex_config_load);
@ -625,7 +626,7 @@ end:
return error;
}
int cwmp_get_deviceid(struct cwmp *cwmp)
int cwmp_get_deviceid()
{
cwmp_get_leaf_value("Device.DeviceInfo.Manufacturer", &cwmp->deviceid.manufacturer);
cwmp_get_leaf_value("Device.DeviceInfo.SerialNumber", &cwmp->deviceid.serialnumber);
@ -635,9 +636,9 @@ int cwmp_get_deviceid(struct cwmp *cwmp)
return CWMP_OK;
}
int cwmp_config_reload(struct cwmp *cwmp)
int cwmp_config_reload()
{
memset(&cwmp->env, 0, sizeof(struct env));
memset(&cwmp_main->env, 0, sizeof(struct env));
return global_conf_init(cwmp);
return global_conf_init();
}

276
cwmp.c
View file

@ -32,65 +32,25 @@
#include "download.h"
#include "upload.h"
#include "sched_inform.h"
#include "rpc_soap.h"
#include "digestauth.h"
#include "soap.h"
#include "netlink.h"
bool g_firewall_restart = false;
int get_firewall_restart_state(char **state)
{
cwmp_uci_reinit();
return uci_get_state_value(UCI_CPE_FIREWALL_RESTART_STATE, state);
}
// wait till firewall restart is not complete or 5 sec, whichever is less
void check_firewall_restart_state()
{
int count = 0;
bool init = false;
do {
char *state = NULL;
if (get_firewall_restart_state(&state) != CWMP_OK)
break;
if (state != NULL && strcmp(state, "init") == 0) {
init = true;
FREE(state);
break;
}
usleep(500 * 1000);
FREE(state);
count++;
} while(count < 10);
// mark the firewall restart as done
g_firewall_restart = false;
if (init == false) { // In case of timeout reset the firewall_restart flag
CWMP_LOG(ERROR, "Firewall restart took longer than usual");
cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "init");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
}
}
void load_forced_inform_json_file(struct cwmp *cwmp)
void load_forced_inform_json_file()
{
struct blob_buf bbuf;
struct blob_attr *cur;
struct blob_attr *custom_forced_inform_list = NULL;
int rem;
if (cwmp->conf.forced_inform_json_file == NULL || !file_exists(cwmp->conf.forced_inform_json_file))
if (cwmp_main->conf.forced_inform_json_file == NULL || !file_exists(cwmp_main->conf.forced_inform_json_file))
return;
memset(&bbuf, 0, sizeof(struct blob_buf));
blob_buf_init(&bbuf, 0);
if (blobmsg_add_json_from_file(&bbuf, cwmp->conf.forced_inform_json_file) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.forced_inform_json_file);
if (blobmsg_add_json_from_file(&bbuf, cwmp_main->conf.forced_inform_json_file) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_main->conf.forced_inform_json_file);
blob_buf_free(&bbuf);
return;
}
@ -101,7 +61,7 @@ void load_forced_inform_json_file(struct cwmp *cwmp)
return;
custom_forced_inform_list = tb[0];
if (custom_forced_inform_list == NULL) {
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a forced inform parameters list", cwmp->conf.custom_notify_json);
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a forced inform parameters list", cwmp_main->conf.custom_notify_json);
blob_buf_free(&bbuf);
return;
}
@ -127,21 +87,36 @@ void load_forced_inform_json_file(struct cwmp *cwmp)
}
void load_boot_inform_json_file(struct cwmp *cwmp)
void clean_custom_inform_parameters()
{
int i;
for (i=0; i < nbre_custom_inform; i++) {
free(custom_forced_inform_parameters[i]);
custom_forced_inform_parameters[i] = NULL;
}
nbre_custom_inform = 0;
for (i=0; i < nbre_boot_inform; i++) {
free(boot_inform_parameters[i]);
boot_inform_parameters[i] = NULL;
}
nbre_boot_inform = 0;
}
void load_boot_inform_json_file()
{
struct blob_buf bbuf;
struct blob_attr *cur;
struct blob_attr *custom_boot_inform_list = NULL;
int rem;
if (cwmp->conf.boot_inform_json_file == NULL || !file_exists(cwmp->conf.boot_inform_json_file))
if (cwmp_main->conf.boot_inform_json_file == NULL || !file_exists(cwmp_main->conf.boot_inform_json_file))
return;
memset(&bbuf, 0, sizeof(struct blob_buf));
blob_buf_init(&bbuf, 0);
if (blobmsg_add_json_from_file(&bbuf, cwmp->conf.boot_inform_json_file) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.boot_inform_json_file);
if (blobmsg_add_json_from_file(&bbuf, cwmp_main->conf.boot_inform_json_file) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_main->conf.boot_inform_json_file);
blob_buf_free(&bbuf);
return;
}
@ -153,7 +128,7 @@ void load_boot_inform_json_file(struct cwmp *cwmp)
custom_boot_inform_list = tb[0];
if (custom_boot_inform_list == NULL) {
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a boot inform parameters list", cwmp->conf.custom_notify_json);
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a boot inform parameters list", cwmp_main->conf.custom_notify_json);
blob_buf_free(&bbuf);
return;
}
@ -179,21 +154,6 @@ void load_boot_inform_json_file(struct cwmp *cwmp)
blob_buf_free(&bbuf);
}
void clean_custom_inform_parameters()
{
int i;
for (i=0; i < nbre_custom_inform; i++) {
free(custom_forced_inform_parameters[i]);
custom_forced_inform_parameters[i] = NULL;
}
nbre_custom_inform = 0;
for (i=0; i < nbre_boot_inform; i++) {
free(boot_inform_parameters[i]);
boot_inform_parameters[i] = NULL;
}
nbre_boot_inform = 0;
}
int create_cwmp_var_state_files()
{
/*
@ -301,21 +261,44 @@ int cwmp_apply_acs_changes(void)
{
int error;
if ((error = cwmp_config_reload(&cwmp_main)))
if ((error = cwmp_config_reload()))
return error;
if ((error = cwmp_root_cause_events(&cwmp_main)))
if ((error = cwmp_root_cause_events()))
return error;
return CWMP_OK;
}
static void configure_var_state()
{
char *zone_name = NULL;
static int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
cwmp_uci_init();
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG);
cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG);
get_firewall_zone_name_by_wan_iface(cwmp_main->conf.default_wan_iface, &zone_name);
cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
cwmp_uci_exit();
}
static int cwmp_init(int argc, char **argv)
{
int error;
struct env env;
openlog("cwmp", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
CWMP_LOG(INFO, "STARTING ICWMP with PID :%d", getpid());
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
memset(&env, 0, sizeof(struct env));
if ((error = global_env_init(argc, argv, &env)))
return error;
@ -326,9 +309,9 @@ static int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
icwmp_init_list_services();
/* Only One instance should run*/
cwmp->pid_file = fopen("/var/run/icwmpd.pid", "w+");
fcntl(fileno(cwmp->pid_file), F_SETFD, fcntl(fileno(cwmp->pid_file), F_GETFD) | FD_CLOEXEC);
int rc = flock(fileno(cwmp->pid_file), LOCK_EX | LOCK_NB);
cwmp_main->pid_file = fopen("/var/run/icwmpd.pid", "w+");
fcntl(fileno(cwmp_main->pid_file), F_SETFD, fcntl(fileno(cwmp_main->pid_file), F_GETFD) | FD_CLOEXEC);
int rc = flock(fileno(cwmp_main->pid_file), LOCK_EX | LOCK_NB);
if (rc) {
if (EWOULDBLOCK != errno) {
char *piderr = "PID file creation failed: Quit the daemon!";
@ -338,135 +321,107 @@ static int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
} else
exit(EXIT_SUCCESS);
}
if (cwmp->pid_file)
fclose(cwmp->pid_file);
if (cwmp_main->pid_file)
fclose(cwmp_main->pid_file);
pthread_mutex_init(&cwmp->mutex_periodic, NULL);
pthread_mutex_init(&cwmp->mutex_session_queue, NULL);
pthread_mutex_init(&cwmp->mutex_session_send, NULL);
memcpy(&(cwmp->env), &env, sizeof(struct env));
INIT_LIST_HEAD(&(cwmp->head_session_queue));
memcpy(&(cwmp_main->env), &env, sizeof(struct env));
if ((error = create_cwmp_var_state_files()))
return error;
cwmp_uci_init();
if ((error = global_conf_init(cwmp)))
if ((error = global_conf_init()))
return error;
cwmp_get_deviceid(cwmp);
load_forced_inform_json_file(cwmp);
load_boot_inform_json_file(cwmp);
load_custom_notify_json(cwmp);
cwmp_get_deviceid();
load_forced_inform_json_file();
load_boot_inform_json_file();
load_custom_notify_json();
init_list_param_notify();
http_server_init();
//http_server_init();
create_cwmp_session_structure();
cwmp_uci_exit();
generate_nonce_priv_key();
cwmp_main->start_time = time(NULL);
return CWMP_OK;
}
static void cwmp_free(struct cwmp *cwmp)
static void cwmp_exit()
{
FREE(cwmp->deviceid.manufacturer);
FREE(cwmp->deviceid.serialnumber);
FREE(cwmp->deviceid.productclass);
FREE(cwmp->deviceid.oui);
FREE(cwmp->deviceid.softwareversion);
FREE(cwmp->conf.lw_notification_hostname);
FREE(cwmp->conf.ip);
FREE(cwmp->conf.ipv6);
FREE(cwmp->conf.acsurl);
FREE(cwmp->conf.acs_userid);
FREE(cwmp->conf.acs_passwd);
FREE(cwmp->conf.interface);
FREE(cwmp->conf.cpe_userid);
FREE(cwmp->conf.cpe_passwd);
FREE(cwmp->conf.ubus_socket);
FREE(cwmp->conf.connection_request_path);
FREE(cwmp->conf.default_wan_iface);
FREE(cwmp->conf.forced_inform_json_file);
FREE(cwmp->conf.custom_notify_json);
FREE(cwmp->conf.boot_inform_json_file);
pthread_join(http_cr_server_thread, NULL);
FREE(cwmp_main->deviceid.manufacturer);
FREE(cwmp_main->deviceid.serialnumber);
FREE(cwmp_main->deviceid.productclass);
FREE(cwmp_main->deviceid.oui);
FREE(cwmp_main->deviceid.softwareversion);
FREE(cwmp_main->conf.lw_notification_hostname);
FREE(cwmp_main->conf.ip);
FREE(cwmp_main->conf.ipv6);
FREE(cwmp_main->conf.acsurl);
FREE(cwmp_main->conf.acs_userid);
FREE(cwmp_main->conf.acs_passwd);
FREE(cwmp_main->conf.interface);
FREE(cwmp_main->conf.cpe_userid);
FREE(cwmp_main->conf.cpe_passwd);
FREE(cwmp_main->conf.ubus_socket);
FREE(cwmp_main->conf.connection_request_path);
FREE(cwmp_main->conf.default_wan_iface);
FREE(cwmp_main->conf.forced_inform_json_file);
FREE(cwmp_main->conf.custom_notify_json);
FREE(cwmp_main->conf.boot_inform_json_file);
FREE(nonce_privacy_key);
clean_list_param_notify();
bkp_tree_clean();
cwmp_ubus_exit();
clean_custom_inform_parameters();
icwmp_cleanmem();
cwmp_uci_exit();
CWMP_LOG(INFO, "EXIT ICWMP");
closelog();
clean_cwmp_session_structure();
FREE(cwmp_main);
}
/*static void *thread_cwmp_signal_handler_thread(void *arg)
void cwmp_end_handler(int signal_num __attribute__((unused)))
{
sigset_t *set = (sigset_t *)arg;
cwmp_stop = true;
for (;;) {
int s, signal_num;
s = sigwait(set, &signal_num);
if (s == -1) {
CWMP_LOG(ERROR, "Error in sigwait");
} else {
CWMP_LOG(INFO, "Catch of Signal(%d)", signal_num);
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING)
http_set_timeout();
if (signal_num == SIGINT || signal_num == SIGTERM) {
signal_exit = true;
if (!ubus_exit)
cwmp_ubus_call("tr069", "command", CWMP_UBUS_ARGS{ { "command", { .str_val = "exit" }, UBUS_String } }, 1, NULL, NULL);
break;
}
}
}
return NULL;
}*/
static void configure_var_state(struct cwmp *cwmp)
{
char *zone_name = NULL;
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp_uci_reinit();
cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG);
cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG);
get_firewall_zone_name_by_wan_iface(cwmp->conf.default_wan_iface, &zone_name);
cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
uloop_timeout_cancel(&retry_session_timer);
uloop_timeout_cancel(&priodic_session_timer);
uloop_timeout_cancel(&session_timer);
uloop_end();
shutdown(cwmp_main->cr_socket_desc, SHUT_RDWR);
}
int main(int argc, char **argv)
{
struct cwmp *cwmp = &cwmp_main;
sigset_t set;
int error;
openlog("cwmp", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
if ((error = cwmp_init(argc, argv, cwmp)))
if ((error = cwmp_init(argc, argv)))
return error;
CWMP_LOG(INFO, "STARTING ICWMP with PID :%d", getpid());
cwmp->start_time = time(NULL);
if ((error = cwmp_init_backup_session(cwmp, NULL, ALL)))
if ((error = cwmp_init_backup_session(NULL, ALL)))
return error;
if ((error = cwmp_root_cause_events(cwmp)))
if ((error = cwmp_root_cause_events()))
return error;
configure_var_state(cwmp);
signal(SIGINT, cwmp_end_handler);
signal(SIGTERM, cwmp_end_handler);
configure_var_state();
http_server_init();
uloop_init();
cwmp_netlink_init();
cwmp_ubus_init(cwmp);
cwmp_ubus_init();
trigger_cwmp_session_timer();
@ -474,15 +429,10 @@ int main(int argc, char **argv)
http_server_start();
uloop_run();
uloop_done();
cwmp_exit();
/* Free all memory allocation */
cwmp_free(cwmp);
CWMP_LOG(INFO, "EXIT ICWMP");
closelog();
return CWMP_OK;
}

View file

@ -318,9 +318,8 @@ static int cwmp_launch_du_uninstall(char *package_name, char *package_env, struc
return error;
}
void *thread_cwmp_rpc_cpe_change_du_state(void *v)
void *thread_cwmp_rpc_cpe_change_du_state(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct timespec change_du_state_timeout = { 50, 0 };
int error = FAULT_CPE_NO_FAULT;
struct du_state_change_complete *pdu_state_change_complete;
@ -337,7 +336,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
for (;;) {
if (thread_end)
if (cwmp_stop)
break;
if (list_change_du_state.next != &(list_change_du_state)) {
@ -365,7 +364,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
}
bkp_session_insert_du_state_change_complete(pdu_state_change_complete);
bkp_session_save();
cwmp_root_cause_changedustate_complete(cwmp, pdu_state_change_complete);
cwmp_root_cause_changedustate_complete(pdu_state_change_complete);
}
list_del(&(pchange_du_state->list));
cwmp_free_change_du_state_request(pchange_du_state);
@ -374,7 +373,6 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
}
if ((timeout >= 0) && (timeout <= time_of_grace)) {
pthread_mutex_lock(&(cwmp->mutex_session_send));
pdu_state_change_complete = calloc(1, sizeof(struct du_state_change_complete));
if (pdu_state_change_complete != NULL) {
error = FAULT_CPE_NO_FAULT;
@ -502,17 +500,13 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
bkp_session_save();
bkp_session_insert_du_state_change_complete(pdu_state_change_complete);
bkp_session_save();
cwmp_root_cause_changedustate_complete(cwmp, pdu_state_change_complete);
cwmp_root_cause_changedustate_complete(pdu_state_change_complete);
}
}
pthread_mutex_lock(&mutex_change_du_state);
pthread_cond_timedwait(&threshold_change_du_state, &mutex_change_du_state, &change_du_state_timeout);
pthread_mutex_unlock(&mutex_change_du_state);
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_change_du_state);
list_del(&(pchange_du_state->list));
cwmp_free_change_du_state_request(pchange_du_state);
@ -527,7 +521,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
return NULL;
}
int cwmp_rpc_acs_destroy_data_du_state_change_complete(struct session *session __attribute__((unused)), struct rpc *rpc)
int cwmp_rpc_acs_destroy_data_du_state_change_complete(struct rpc *rpc)
{
if (rpc->extra_data != NULL) {
struct du_state_change_complete *p;

View file

@ -291,8 +291,7 @@ void ubus_get_single_parameter_callback(struct ubus_request *req, int type __att
char *cwmp_get_single_parameter_value(char *parameter_name, struct cwmp_dm_parameter *dm_parameter)
{
int e;
struct cwmp *cwmp = &cwmp_main;
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);
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_main->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";
@ -367,9 +366,8 @@ void ubus_get_parameter_callback(struct ubus_request *req, int type __attribute_
char *cwmp_get_parameter_values(char *parameter_name, struct list_head *parameters_list)
{
int e;
struct cwmp *cwmp = &cwmp_main;
struct list_params_result get_result = { .parameters_list = parameters_list };
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);
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_main->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";
@ -385,9 +383,8 @@ char *cwmp_get_parameter_values(char *parameter_name, struct list_head *paramete
char *cwmp_get_multiple_parameters_values(struct list_head *arg_params_list, struct list_head *parameters_list)
{
int e;
struct cwmp *cwmp = &cwmp_main;
struct list_params_result get_result = { .parameters_list = parameters_list };
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 );
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_main->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";
@ -404,8 +401,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_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);
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_main->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";
@ -456,9 +452,8 @@ 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_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,
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_main->conf.instance_mode }, UBUS_Integer } }, 5,
ubus_setm_values_callback, &set_result);
if (e < 0) {
@ -508,9 +503,8 @@ void ubus_objects_callback(struct ubus_request *req, int type __attribute__((unu
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_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,
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_main->conf.instance_mode }, UBUS_Integer } }, 5,
ubus_objects_callback, &add_result);
if (e < 0) {
@ -528,8 +522,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_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,
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_main->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);

View file

@ -18,7 +18,7 @@
#include "ubus.h"
#include "cwmp_uci.h"
#include "event.h"
#include "rpc_soap.h"
#include "soap.h"
#include "log.h"
struct diagnostic_input {

View file

@ -328,9 +328,9 @@ int http_digest_auth_fail_response(FILE *fp, const char *http_method, const char
*/
int http_digest_auth_check(const char *http_method, const char *url, const char *header, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
{
size_t len;
size_t len = 0;
char *end;
char nonce[MAX_NONCE_LENGTH];
char nonce[MAX_NONCE_LENGTH] = {0};
size_t left; /* number of characters left in 'header' for 'uri' */
DD(DEBUG, "%s: header: %s", __FUNCTION__, header);
@ -338,7 +338,7 @@ int http_digest_auth_check(const char *http_method, const char *url, const char
left = strlen(header);
{
char un[MAX_USERNAME_LENGTH];
char un[MAX_USERNAME_LENGTH] = {0};
len = lookup_sub_value(un, sizeof(un), header, "username");
if (0 != strcmp(username, un))
@ -347,7 +347,7 @@ int http_digest_auth_check(const char *http_method, const char *url, const char
}
{
char r[MAX_REALM_LENGTH];
char r[MAX_REALM_LENGTH] = {0};
len = lookup_sub_value(r, sizeof(r), header, "realm");
if ((0 == len) || (0 != strcmp(realm, r)))
@ -361,13 +361,14 @@ int http_digest_auth_check(const char *http_method, const char *url, const char
{
char uri[left];
char cnonce[MAX_NONCE_LENGTH];
char qop[15]; /* auth,auth-int */
char nc[20];
char response[MAX_AUTH_RESPONSE_LENGTH];
char ha1[HASH_MD5_HEX_LEN + 1];
char respexp[HASH_MD5_HEX_LEN + 1];
char noncehashexp[HASH_MD5_HEX_LEN + 9];
memset( uri, 0, sizeof(uri) );
char cnonce[MAX_NONCE_LENGTH] = {0};
char qop[15] = {0}; /* auth,auth-int */
char nc[20] = {0};
char response[MAX_AUTH_RESPONSE_LENGTH] = {0};
char ha1[HASH_MD5_HEX_LEN + 1] = {0};
char respexp[HASH_MD5_HEX_LEN + 1] = {0};
char noncehashexp[HASH_MD5_HEX_LEN + 9] = {0};
uint32_t nonce_time;
unsigned long int nci;
uint32_t t;

View file

@ -264,11 +264,11 @@ char *get_file_name_by_download_url(char *url)
return slash+1;
}
int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *download_file_name, struct transfer_complete *ptransfer_complete)
int apply_downloaded_file(struct download *pdownload, char *download_file_name, struct transfer_complete *ptransfer_complete)
{
int error = FAULT_CPE_NO_FAULT;
if (pdownload->file_type[0] == '1') {
ptransfer_complete->old_software_version = cwmp->deviceid.softwareversion;
ptransfer_complete->old_software_version = cwmp_main->deviceid.softwareversion;
}
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
@ -336,11 +336,11 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *d
}
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
return error;
}
struct transfer_complete *set_download_error_transfer_complete(struct cwmp *cwmp, struct download *pdownload, enum load_type ltype)
struct transfer_complete *set_download_error_transfer_complete(struct download *pdownload, enum load_type ltype)
{
struct transfer_complete *ptransfer_complete;
ptransfer_complete = calloc(1, sizeof(struct transfer_complete));
@ -351,14 +351,13 @@ struct transfer_complete *set_download_error_transfer_complete(struct cwmp *cwmp
ptransfer_complete->fault_code = ltype == TYPE_DOWNLOAD ? FAULT_CPE_DOWNLOAD_FAILURE : FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW;
ptransfer_complete->type = ltype;
bkp_session_insert_transfer_complete(ptransfer_complete);
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
}
return ptransfer_complete;
}
void *thread_cwmp_rpc_cpe_download(void *v)
void *thread_cwmp_rpc_cpe_download(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct download *pdownload;
struct timespec download_timeout = { 0, 0 };
time_t current_time, stime;
@ -368,7 +367,7 @@ void *thread_cwmp_rpc_cpe_download(void *v)
for (;;) {
if (thread_end)
if (cwmp_stop)
break;
if (list_download.next != &(list_download)) {
@ -383,7 +382,7 @@ void *thread_cwmp_rpc_cpe_download(void *v)
pthread_mutex_lock(&mutex_download);
bkp_session_delete_download(pdownload);
error = FAULT_CPE_DOWNLOAD_FAILURE;
ptransfer_complete = set_download_error_transfer_complete(cwmp, pdownload, TYPE_DOWNLOAD);
ptransfer_complete = set_download_error_transfer_complete(pdownload, TYPE_DOWNLOAD);
list_del(&(pdownload->list));
if (pdownload->scheduled_time != 0)
count_download_queue--;
@ -392,7 +391,6 @@ void *thread_cwmp_rpc_cpe_download(void *v)
continue;
}
if ((timeout >= 0) && (timeout <= time_of_grace)) {
pthread_mutex_lock(&(cwmp->mutex_session_send));
char *download_file_name = get_file_name_by_download_url(pdownload->url);
CWMP_LOG(INFO, "Launch download file %s", pdownload->url);
error = cwmp_launch_download(pdownload, download_file_name, TYPE_DOWNLOAD, &ptransfer_complete);
@ -400,17 +398,15 @@ void *thread_cwmp_rpc_cpe_download(void *v)
if (error != FAULT_CPE_NO_FAULT) {
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
bkp_session_delete_transfer_complete(ptransfer_complete);
} else {
error = apply_downloaded_file(cwmp, pdownload, download_file_name, ptransfer_complete);
error = apply_downloaded_file(pdownload, download_file_name, ptransfer_complete);
if (error || pdownload->file_type[0] == '6')
bkp_session_delete_transfer_complete(ptransfer_complete);
}
if (pdownload->file_type[0] == '6')
sleep(30);
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_download);
list_del(&(pdownload->list));
if (pdownload->scheduled_time != 0)
@ -465,9 +461,8 @@ end:
return 0;
}
void *thread_cwmp_rpc_cpe_schedule_download(void *v)
void *thread_cwmp_rpc_cpe_schedule_download(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct timespec download_timeout = { 0, 0 };
int error = FAULT_CPE_NO_FAULT;
struct transfer_complete *ptransfer_complete;
@ -478,7 +473,7 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
for (;;) {
time_t current_time;
if (thread_end)
if (cwmp_stop)
break;
current_time = time(NULL);
@ -495,7 +490,7 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
pthread_mutex_lock(&mutex_schedule_download);
bkp_session_delete_schedule_download(p);
error = FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW;
ptransfer_complete = set_download_error_transfer_complete(cwmp, p, TYPE_SCHEDULE_DOWNLOAD);
ptransfer_complete = set_download_error_transfer_complete(p, TYPE_SCHEDULE_DOWNLOAD);
list_del(&(p->list));
if (p->timewindowstruct[0].windowstart != 0)
count_download_queue--;
@ -519,7 +514,7 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
pthread_mutex_lock(&mutex_schedule_download);
bkp_session_delete_schedule_download(p);
error = FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW;
ptransfer_complete = set_download_error_transfer_complete(cwmp, p, TYPE_SCHEDULE_DOWNLOAD);
ptransfer_complete = set_download_error_transfer_complete(p, TYPE_SCHEDULE_DOWNLOAD);
list_del(&(p->list));
if (p->timewindowstruct[0].windowstart != 0)
count_download_queue--;
@ -546,24 +541,24 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
if (error != FAULT_CPE_NO_FAULT) {
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
bkp_session_delete_transfer_complete(ptransfer_complete);
} else {
pthread_mutex_unlock(&mutex_schedule_download);
if (pthread_mutex_trylock(&(cwmp->mutex_session_send)) == 0) {
/*pthread_mutex_unlock(&mutex_schedule_download);
if (pthread_mutex_trylock(&(cwmp_main->mutex_session_send)) == 0) {
pthread_mutex_lock(&mutex_apply_schedule_download);
pthread_mutex_lock(&mutex_schedule_download);
error = apply_downloaded_file(cwmp, current_download, download_file_name, ptransfer_complete);
error = apply_downloaded_file(cwmp, current_download, ptransfer_complete);
if (error == FAULT_CPE_NO_FAULT)
exit(EXIT_SUCCESS);
pthread_mutex_unlock(&mutex_schedule_download);
pthread_mutex_unlock(&mutex_apply_schedule_download);
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
} else {
pthread_mutex_unlock(&(cwmp_main->mutex_session_send));
pthread_cond_signal(&(cwmp_main->threshold_session_send));
} else {*/
cwmp_add_apply_schedule_download(current_download, ptransfer_complete->start_time);
}
//}
}
pthread_mutex_lock(&mutex_schedule_download);
bkp_session_delete_schedule_download(current_download);
@ -576,21 +571,18 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
continue;
} //AT ANY TIME OR WHEN IDLE
else {
pthread_mutex_lock(&(cwmp->mutex_session_send));
CWMP_LOG(INFO, "Launch download file %s", current_download->url);
error = cwmp_launch_download(current_download, download_file_name, TYPE_SCHEDULE_DOWNLOAD, &ptransfer_complete);
if (error != FAULT_CPE_NO_FAULT) {
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
bkp_session_delete_transfer_complete(ptransfer_complete);
} else {
error = apply_downloaded_file(cwmp, current_download, download_file_name, ptransfer_complete);
error = apply_downloaded_file(current_download, download_file_name, ptransfer_complete);
if (error == FAULT_CPE_NO_FAULT)
exit(EXIT_SUCCESS);
}
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_schedule_download);
list_del(&(current_download->list));
if (current_download->timewindowstruct[0].windowstart != 0)
@ -616,9 +608,8 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
return NULL;
}
void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct timespec apply_timeout = { 0, 0 };
int error = FAULT_CPE_NO_FAULT;
struct transfer_complete *ptransfer_complete;
@ -629,7 +620,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
for (;;) {
time_t current_time;
if (thread_end)
if (cwmp_stop)
break;
current_time = time(NULL);
@ -646,7 +637,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
pthread_mutex_lock(&mutex_apply_schedule_download);
bkp_session_delete_apply_schedule_download(p);
error = FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW;
ptransfer_complete = set_download_error_transfer_complete(cwmp, (struct download *)p, TYPE_SCHEDULE_DOWNLOAD);
ptransfer_complete = set_download_error_transfer_complete((struct download *)p, TYPE_SCHEDULE_DOWNLOAD);
list_del(&(p->list));
if (p->timeintervals[0].windowstart != 0)
count_download_queue--;
@ -670,7 +661,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
pthread_mutex_lock(&mutex_apply_schedule_download);
bkp_session_delete_apply_schedule_download(p);
error = FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW;
ptransfer_complete = set_download_error_transfer_complete(cwmp, (struct download *)p, TYPE_SCHEDULE_DOWNLOAD);
ptransfer_complete = set_download_error_transfer_complete((struct download *)p, TYPE_SCHEDULE_DOWNLOAD);
list_del(&(p->list));
/*if(p->timewindowintervals[0].windowstart != 0)
count_download_queue--;*/
@ -688,13 +679,12 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
if (min_time == 0) {
continue;
} else if (min_time <= current_time) {
pthread_mutex_lock(&(cwmp->mutex_session_send));
pthread_mutex_lock(&mutex_schedule_download);
bkp_session_delete_apply_schedule_download(apply_download);
bkp_session_save();
ptransfer_complete = calloc(1, sizeof(struct transfer_complete));
if (apply_download->file_type[0] == '1') {
ptransfer_complete->old_software_version = cwmp->deviceid.softwareversion;
ptransfer_complete->old_software_version = cwmp_main->deviceid.softwareversion;
}
ptransfer_complete->command_key = strdup(apply_download->command_key);
ptransfer_complete->start_time = strdup(apply_download->start_time);
@ -737,11 +727,9 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
}
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
pthread_mutex_unlock(&mutex_schedule_download);
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_apply_schedule_download);
list_del(&(apply_download->list));
/*if(pdownload->timeintervals[0].windowstart != 0)
@ -887,7 +875,7 @@ int cwmp_apply_scheduled_Download_remove_all()
return CWMP_OK;
}
int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session __attribute__((unused)), struct rpc *rpc)
int cwmp_rpc_acs_destroy_data_transfer_complete(struct rpc *rpc)
{
if (rpc->extra_data != NULL) {
struct transfer_complete *p = (struct transfer_complete *)rpc->extra_data;

237
event.c
View file

@ -19,7 +19,7 @@
#include "session.h"
#include "cwmp_du_state.h"
#include "download.h"
#include "rpc_soap.h"
#include "soap.h"
#include "upload.h"
#include "sched_inform.h"
@ -61,23 +61,11 @@ void cwmp_save_event_container(struct event_container *event_container) //to be
}
}
struct event_container *__cwmp_add_event_container(struct cwmp *cwmp, int event_code, char *command_key)
struct event_container *__cwmp_add_event_container(int event_code, char *command_key)
{
static int id;
struct event_container *event_container;
struct session *session;
struct list_head *ilist;
if (cwmp->head_event_container == NULL) {
session = cwmp_add_queue_session(cwmp);
if (session == NULL) {
return NULL;
}
cwmp->head_event_container = &(session->head_event_container);
}
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
list_for_each (ilist, cwmp->head_event_container) {
event_container = list_entry(ilist, struct event_container, list);
list_for_each_entry(event_container, &cwmp_main->session->events, list) {
if (event_container->code == event_code && EVENT_CONST[event_code].TYPE == EVENT_TYPE_SINGLE) {
return event_container;
}
@ -90,7 +78,7 @@ struct event_container *__cwmp_add_event_container(struct cwmp *cwmp, int event_
return NULL;
}
INIT_LIST_HEAD(&(event_container->head_dm_parameter));
list_add(&(event_container->list), ilist->prev);
list_add_tail(&(event_container->list), &(cwmp_main->session->events));
event_container->code = event_code;
event_container->command_key = command_key ? strdup(command_key) : strdup("");
if ((id < 0) || (id >= MAX_INT_ID)) {
@ -101,53 +89,45 @@ struct event_container *__cwmp_add_event_container(struct cwmp *cwmp, int event_
return event_container;
}
struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_code, char *command_key)
struct event_container *cwmp_add_event_container(int event_code, char *command_key)
{
pthread_mutex_lock(&add_event_mutext);
struct event_container *event = __cwmp_add_event_container(cwmp, event_code, command_key);
struct event_container *event = __cwmp_add_event_container(event_code, command_key);
pthread_mutex_unlock(&add_event_mutext);
return event;
}
void cwmp_root_cause_event_ipdiagnostic(void)
{
struct cwmp *cwmp = &cwmp_main;
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_8DIAGNOSTICS_COMPLETE, "");
event_container = cwmp_add_event_container(EVENT_IDX_8DIAGNOSTICS_COMPLETE, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return;
}
cwmp_save_event_container(event_container);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
pthread_cond_signal(&(cwmp->threshold_session_send));
return;
}
int cwmp_root_cause_event_boot(struct cwmp *cwmp)
int cwmp_root_cause_event_boot()
{
if (cwmp->env.boot == CWMP_START_BOOT) {
if (cwmp_main->env.boot == CWMP_START_BOOT) {
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->env.boot = 0;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_1BOOT, "");
cwmp_main->env.boot = 0;
event_container = cwmp_add_event_container(EVENT_IDX_1BOOT, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
cwmp_save_event_container(event_container);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
}
return CWMP_OK;
}
int event_remove_all_event_container(struct session *session, int rem_from)
int event_remove_all_event_container(int rem_from)
{
while (session->head_event_container.next != &(session->head_event_container)) {
while (cwmp_main->session->events.next != &cwmp_main->session->events) {
struct event_container *event_container;
event_container = list_entry(session->head_event_container.next, struct event_container, list);
event_container = list_entry(cwmp_main->session->events.next, struct event_container, list);
bkp_session_delete_event(event_container->id, rem_from ? "send" : "queue");
free(event_container->command_key);
cwmp_free_all_dm_parameter_list(&(event_container->head_dm_parameter));
@ -158,16 +138,16 @@ int event_remove_all_event_container(struct session *session, int rem_from)
return CWMP_OK;
}
int event_remove_noretry_event_container(struct session *session, struct cwmp *cwmp)
int event_remove_noretry_event_container()
{
struct list_head *ilist, *q;
list_for_each_safe (ilist, q, &(session->head_event_container)) {
list_for_each_safe (ilist, q, &cwmp_main->session->events) {
struct event_container *event_container;
event_container = list_entry(ilist, struct event_container, list);
if (EVENT_CONST[event_container->code].CODE[0] == '6')
cwmp->cwmp_cr_event = 1;
cwmp_main->cwmp_cr_event = 1;
if (EVENT_CONST[event_container->code].RETRY == 0) {
free(event_container->command_key);
@ -179,29 +159,22 @@ int event_remove_noretry_event_container(struct session *session, struct cwmp *c
return CWMP_OK;
}
int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp)
int cwmp_root_cause_event_bootstrap()
{
struct event_container *event_container;
char *acsurl = NULL;
int cmp = 0;
cwmp_load_saved_session(cwmp, &acsurl, ACS);
cwmp_load_saved_session(&acsurl, ACS);
if (acsurl == NULL)
save_acs_bkp_config(cwmp);
save_acs_bkp_config();
if (acsurl == NULL || ((cmp = strcmp(cwmp->conf.acsurl, acsurl)) != 0)) {
pthread_mutex_lock(&(cwmp->mutex_session_queue));
if (cwmp->head_event_container != NULL && cwmp->head_session_queue.next != &(cwmp->head_session_queue)) {
struct session *session;
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
event_remove_all_event_container(session, RPC_QUEUE);
}
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_0BOOTSTRAP, "");
if (acsurl == NULL || ((cmp = strcmp(cwmp_main->conf.acsurl, acsurl)) != 0)) {
event_container = cwmp_add_event_container(EVENT_IDX_0BOOTSTRAP, "");
FREE(acsurl);
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
cwmp_save_event_container(event_container);
@ -210,202 +183,117 @@ int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp)
cwmp_scheduled_Download_remove_all();
cwmp_apply_scheduled_Download_remove_all();
cwmp_scheduledUpload_remove_all();
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
} else {
FREE(acsurl);
}
if (cmp) {
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
char buf[64] = "Device.ManagementServer.URL";
add_dm_parameter_to_list(&(event_container->head_dm_parameter), buf, NULL, NULL, 0, false);
cwmp_save_event_container(event_container);
save_acs_bkp_config(cwmp);
save_acs_bkp_config(cwmp_main);
cwmp_scheduleInform_remove_all();
cwmp_scheduledDownload_remove_all();
cwmp_apply_scheduled_Download_remove_all();
cwmp_scheduled_Download_remove_all();
cwmp_scheduledUpload_remove_all();
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
}
return CWMP_OK;
}
int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complete *p)
int cwmp_root_cause_transfer_complete(struct transfer_complete *p)
{
struct event_container *event_container;
struct session *session;
struct rpc *rpc_acs;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_7TRANSFER_COMPLETE, "");
event_container = cwmp_add_event_container(EVENT_IDX_7TRANSFER_COMPLETE, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
switch (p->type) {
case TYPE_DOWNLOAD:
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Download, p->command_key ? p->command_key : "");
event_container = cwmp_add_event_container(EVENT_IDX_M_Download, p->command_key ? p->command_key : "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
break;
case TYPE_UPLOAD:
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Upload, p->command_key ? p->command_key : "");
event_container = cwmp_add_event_container(EVENT_IDX_M_Upload, p->command_key ? p->command_key : "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
break;
case TYPE_SCHEDULE_DOWNLOAD:
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Schedule_Download, p->command_key ? p->command_key : "");
event_container = cwmp_add_event_container(EVENT_IDX_M_Schedule_Download, p->command_key ? p->command_key : "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
break;
}
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
if ((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_TRANSFER_COMPLETE)) == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
if ((rpc_acs = cwmp_add_session_rpc_acs(RPC_ACS_TRANSFER_COMPLETE)) == NULL) {
return CWMP_MEM_ERR;
}
rpc_acs->extra_data = (void *)p;
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_OK;
}
int cwmp_root_cause_changedustate_complete(struct cwmp *cwmp, struct du_state_change_complete *p)
int cwmp_root_cause_changedustate_complete(struct du_state_change_complete *p)
{
struct event_container *event_container;
struct session *session;
struct rpc *rpc_acs;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_11DU_STATE_CHANGE_COMPLETE, "");
event_container = cwmp_add_event_container(EVENT_IDX_11DU_STATE_CHANGE_COMPLETE, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_ChangeDUState, p->command_key ? p->command_key : "");
event_container = cwmp_add_event_container(EVENT_IDX_M_ChangeDUState, p->command_key ? p->command_key : "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
if ((rpc_acs = cwmp_add_session_rpc_acs(session, RPC_ACS_DU_STATE_CHANGE_COMPLETE)) == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
if ((rpc_acs = cwmp_add_session_rpc_acs(RPC_ACS_DU_STATE_CHANGE_COMPLETE)) == NULL) {
return CWMP_MEM_ERR;
}
rpc_acs->extra_data = (void *)p;
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_OK;
}
int cwmp_root_cause_get_rpc_method(struct cwmp *cwmp)
int cwmp_root_cause_get_rpc_method()
{
if (cwmp->env.periodic == CWMP_START_PERIODIC) {
if (cwmp_main->env.periodic == CWMP_START_PERIODIC) {
struct event_container *event_container;
struct session *session;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->env.periodic = 0;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, "");
cwmp_main->env.periodic = 0;
event_container = cwmp_add_event_container(EVENT_IDX_2PERIODIC, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
cwmp_save_event_container(event_container);
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
if (cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
if (cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL) {
return CWMP_MEM_ERR;
}
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
}
return CWMP_OK;
}
void *thread_event_periodic(void *v)
{
struct cwmp *cwmp = (struct cwmp *)v;
struct event_container *event_container;
static int periodic_interval;
static bool periodic_enable;
static time_t periodic_time;
static struct timespec periodic_timeout = { 0, 0 };
time_t current_time;
long int delta_time;
periodic_interval = cwmp->conf.period;
periodic_enable = cwmp->conf.periodic_enable;
periodic_time = cwmp->conf.time;
for (;;) {
pthread_mutex_lock(&(cwmp->mutex_periodic));
if (cwmp->conf.periodic_enable) {
current_time = time(NULL);
if (periodic_time != 0) {
delta_time = (current_time - periodic_time) % periodic_interval;
if (delta_time >= 0)
periodic_timeout.tv_sec = current_time + periodic_interval - delta_time;
else
periodic_timeout.tv_sec = current_time - delta_time;
} else {
periodic_timeout.tv_sec = current_time + periodic_interval;
}
cwmp->session_status.next_periodic = periodic_timeout.tv_sec;
pthread_cond_timedwait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic), &periodic_timeout);
} else {
cwmp->session_status.next_periodic = 0;
pthread_cond_wait(&(cwmp->threshold_periodic), &(cwmp->mutex_periodic));
}
pthread_mutex_unlock(&(cwmp->mutex_periodic));
if (thread_end)
break;
if (periodic_interval != cwmp->conf.period || periodic_enable != cwmp->conf.periodic_enable || periodic_time != cwmp->conf.time) {
periodic_enable = cwmp->conf.periodic_enable;
periodic_interval = cwmp->conf.period;
periodic_time = cwmp->conf.time;
continue;
}
CWMP_LOG(INFO, "Periodic thread: add periodic event in the queue");
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
continue;
}
cwmp_save_event_container(event_container);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
pthread_cond_signal(&(cwmp->threshold_session_send));
}
return NULL;
}
bool event_exist_in_list(struct cwmp *cwmp, int event)
bool event_exist_in_list(int event)
{
struct event_container *event_container;
list_for_each_entry (event_container, cwmp->head_event_container, list) {
list_for_each_entry (event_container, &cwmp_main->session->events, list) {
if (event_container->code == event)
return true;
}
return false;
}
int cwmp_root_cause_event_periodic(struct cwmp *cwmp)
int cwmp_root_cause_event_periodic()
{
static int period = 0;
static bool periodic_enable = false;
@ -413,13 +301,12 @@ int cwmp_root_cause_event_periodic(struct cwmp *cwmp)
char local_time[27] = { 0 };
struct tm *t_tm;
if (period == cwmp->conf.period && periodic_enable == cwmp->conf.periodic_enable && periodic_time == cwmp->conf.time)
if (period == cwmp_main->conf.period && periodic_enable == cwmp_main->conf.periodic_enable && periodic_time == cwmp_main->conf.time)
return CWMP_OK;
pthread_mutex_lock(&(cwmp->mutex_periodic));
period = cwmp->conf.period;
periodic_enable = cwmp->conf.periodic_enable;
periodic_time = cwmp->conf.time;
period = cwmp_main->conf.period;
periodic_enable = cwmp_main->conf.periodic_enable;
periodic_time = cwmp_main->conf.time;
CWMP_LOG(INFO, periodic_enable ? "Periodic event is enabled. Interval period = %ds" : "Periodic event is disabled", period);
t_tm = localtime(&periodic_time);
@ -435,21 +322,19 @@ int cwmp_root_cause_event_periodic(struct cwmp *cwmp)
local_time[26] = '\0';
CWMP_LOG(INFO, periodic_time ? "Periodic time is %s" : "Periodic time is Unknown", local_time);
pthread_mutex_unlock(&(cwmp->mutex_periodic));
pthread_cond_signal(&(cwmp->threshold_periodic));
return CWMP_OK;
}
void connection_request_ip_value_change(struct cwmp *cwmp, int version)
void connection_request_ip_value_change(int version)
{
char *bip = NULL;
char *ip_version = (version == IPv6) ? "ipv6" : "ip";
char *ip_value = (version == IPv6) ? cwmp->conf.ipv6 : cwmp->conf.ip;
char *ip_value = (version == IPv6) ? cwmp_main->conf.ipv6 : cwmp_main->conf.ip;
if (version == IPv6)
cwmp_load_saved_session(cwmp, &bip, CR_IPv6);
cwmp_load_saved_session(&bip, CR_IPv6);
else
cwmp_load_saved_session(cwmp, &bip, CR_IP);
cwmp_load_saved_session(&bip, CR_IP);
if (bip == NULL) {
bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value);
@ -458,30 +343,26 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version)
}
if (strcmp(bip, ip_value) != 0) {
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
FREE(bip);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return;
}
cwmp_save_event_container(event_container);
bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value);
bkp_session_save();
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
pthread_cond_signal(&(cwmp->threshold_session_send));
}
FREE(bip);
}
void connection_request_port_value_change(struct cwmp *cwmp, int port)
void connection_request_port_value_change(int port)
{
char *bport = NULL;
char bufport[16];
snprintf(bufport, sizeof(bufport), "%d", port);
cwmp_load_saved_session(cwmp, &bport, CR_PORT);
cwmp_load_saved_session(&bport, CR_PORT);
if (bport == NULL) {
bkp_session_simple_insert_in_parent("connection_request", "port", bufport);
@ -490,7 +371,7 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port)
}
if (strcmp(bport, bufport) != 0) {
struct event_container *event_container;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
FREE(bport);
return;
@ -502,20 +383,20 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port)
FREE(bport);
}
int cwmp_root_cause_events(struct cwmp *cwmp)
int cwmp_root_cause_events()
{
int error;
if ((error = cwmp_root_cause_event_bootstrap(cwmp)))
if ((error = cwmp_root_cause_event_bootstrap()))
return error;
if ((error = cwmp_root_cause_event_boot(cwmp)))
if ((error = cwmp_root_cause_event_boot()))
return error;
if ((error = cwmp_root_cause_get_rpc_method(cwmp)))
if ((error = cwmp_root_cause_get_rpc_method()))
return error;
if ((error = cwmp_root_cause_event_periodic(cwmp)))
if ((error = cwmp_root_cause_event_periodic()))
return error;
return CWMP_OK;

View file

@ -64,7 +64,7 @@ cp test/files/etc/config/wireless /etc/config/
#fi
#
#test_num=$(( test_num + 1 ))
#echo "1..${test_num}" >> ./funl-test-result.log
echo "1..${test_num}" >> ./funl-test-result.log
# Artefact
gcovr -r . 2> /dev/null --xml -o ./funl-test-coverage.xml

86
http.c
View file

@ -36,7 +36,7 @@
static struct http_client http_c;
static pthread_t http_cr_server_thread;
pthread_t http_cr_server_thread;
static CURL *curl = NULL;
@ -49,14 +49,14 @@ void http_set_timeout(void)
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1);
}
int http_client_init(struct cwmp *cwmp)
int http_client_init()
{
char *dhcp_dis = NULL;
char *acs_var_stat = NULL;
uci_get_value(UCI_DHCP_DISCOVERY_PATH, &dhcp_dis);
if (dhcp_dis && cwmp->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) {
if (dhcp_dis && cwmp_main->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) {
uci_get_state_value(UCI_DHCP_ACS_URL, &acs_var_stat);
if (acs_var_stat) {
if (icwmp_asprintf(&http_c.url, "%s", acs_var_stat) == -1) {
@ -65,13 +65,13 @@ int http_client_init(struct cwmp *cwmp)
return -1;
}
} else {
if (icwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
if (icwmp_asprintf(&http_c.url, "%s", cwmp_main->conf.acsurl) == -1) {
FREE(dhcp_dis);
return -1;
}
}
} else {
if (icwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
if (icwmp_asprintf(&http_c.url, "%s", cwmp_main->conf.acsurl) == -1) {
FREE(dhcp_dis);
return -1;
}
@ -89,7 +89,7 @@ int http_client_init(struct cwmp *cwmp)
if (!curl)
return -1;
if (cwmp->conf.ipv6_enable) {
if (cwmp_main->conf.ipv6_enable) {
unsigned char buf[sizeof(struct in6_addr)];
char *ip = NULL;
@ -141,7 +141,7 @@ static size_t http_get_response(void *buffer, size_t size, size_t rxed, char **m
return size * rxed;
}
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in)
int http_send_message(char *msg_out, int msg_out_len, char **msg_in)
{
unsigned char buf[sizeof(struct in6_addr)];
int tmp = 0;
@ -163,21 +163,21 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
if (!http_c.header_list)
return -1;
#endif /* ACS_FUSION */
if (cwmp->conf.http_disable_100continue) {
if (cwmp_main->conf.http_disable_100continue) {
http_c.header_list = curl_slist_append(http_c.header_list, "Expect:");
if (!http_c.header_list)
return -1;
}
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid);
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd);
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp_main->conf.acs_userid);
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp_main->conf.acs_passwd);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
switch (cwmp->conf.compression) {
switch (cwmp_main->conf.compression) {
case COMP_NONE:
break;
case COMP_GZIP:
@ -207,14 +207,14 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
if (cwmp->conf.acs_ssl_capath)
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath);
if (cwmp->conf.insecure_enable) {
if (cwmp_main->conf.acs_ssl_capath)
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp_main->conf.acs_ssl_capath);
if (cwmp_main->conf.insecure_enable) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp->conf.interface);
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp_main->conf.interface);
*msg_in = (char *)calloc(1, sizeof(char));
res = curl_easy_perform(curl);
@ -257,7 +257,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
}
if (http_code == 415) {
cwmp->conf.compression = COMP_NONE;
cwmp_main->conf.compression = COMP_NONE;
goto error;
}
if (http_code != 200 && http_code != 204)
@ -287,9 +287,8 @@ error:
void http_success_cr(void)
{
CWMP_LOG(INFO, "Connection Request thread: add connection request event in the queue");
cwmp_add_event_container(&cwmp_main, EVENT_IDX_6CONNECTION_REQUEST, "");
pthread_mutex_lock(&start_session_mutext);
start_cwmp_session(&cwmp_main);
cwmp_ubus_call("tr069", "inform", CWMP_UBUS_ARGS{ {} }, 0, NULL, NULL);
pthread_mutex_unlock(&start_session_mutext);
}
@ -297,25 +296,25 @@ static void http_cr_new_client(int client, bool service_available)
{
FILE *fp;
char buffer[BUFSIZ];
char auth_digest_buffer[BUFSIZ];
char auth_digest_buffer[BUFSIZ] = {0};
int8_t auth_status = 0;
bool auth_digest_checked = false;
bool method_is_get = false;
bool internal_error = false;
char cr_http_get_head[512];
pthread_mutex_lock(&mutex_config_load);
fp = fdopen(client, "r+");
char *username = cwmp_main.conf.cpe_userid;
char *password = cwmp_main.conf.cpe_passwd;
char *username = cwmp_main->conf.cpe_userid;
char *password = cwmp_main->conf.cpe_passwd;
if (!username || !password) {
// if we dont have username or password configured proceed with connecting to ACS
service_available = false;
goto http_end;
}
snprintf(cr_http_get_head, sizeof(cr_http_get_head), "GET %s HTTP/1.1", cwmp_main.conf.connection_request_path);
snprintf(cr_http_get_head, sizeof(cr_http_get_head), "GET %s HTTP/1.1", cwmp_main->conf.connection_request_path);
pthread_mutex_unlock(&mutex_config_load);
while (fgets(buffer, sizeof(buffer), fp)) {
if (!strncasecmp(buffer, cr_http_get_head, strlen(cr_http_get_head)))
method_is_get = true;
@ -352,24 +351,28 @@ http_end:
fputs("HTTP/1.1 200 OK\r\n", fp);
fputs("Connection: close\r\n", fp);
fputs("Content-Length: 0\r\n", fp);
fputs("\r\n", fp);
fclose(fp);
close(client);
http_success_cr();
} else if (internal_error) {
CWMP_LOG(INFO, "Receive Connection Request: Return 500 Internal Error");
fputs("HTTP/1.1 500 Internal Server Error\r\n", fp);
fputs("Connection: close\r\n", fp);
fputs("Content-Length: 0\r\n", fp);
}
else {
fputs("\r\n", fp);
fclose(fp);
close(client);
} else {
CWMP_LOG(INFO, "Receive Connection Request: Return 401 Unauthorized");
fputs("HTTP/1.1 401 Unauthorized\r\n", fp);
fputs("Connection: close\r\n", fp);
http_digest_auth_fail_response(fp, "GET", "/", REALM, OPAQUE);
fputs("\r\n", fp);
}
fputs("\r\n", fp);
fclose(fp);
pthread_mutex_unlock(&mutex_config_load);
close(client);
}
}
void http_server_init(void)
@ -378,20 +381,20 @@ void http_server_init(void)
unsigned short cr_port;
for (;;) {
cr_port = (unsigned short)(cwmp_main.conf.connection_request_port);
cr_port = (unsigned short)(cwmp_main->conf.connection_request_port);
unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port) ? 1 : 0;
//Create socket
cwmp_main.cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0);
if (cwmp_main.cr_socket_desc == -1) {
cwmp_main->cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0);
if (cwmp_main->cr_socket_desc == -1) {
CWMP_LOG(ERROR, "Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno));
sleep(1);
continue;
}
fcntl(cwmp_main.cr_socket_desc, F_SETFD, fcntl(cwmp_main.cr_socket_desc, F_GETFD) | FD_CLOEXEC);
fcntl(cwmp_main->cr_socket_desc, F_SETFD, fcntl(cwmp_main->cr_socket_desc, F_GETFD) | FD_CLOEXEC);
int reusaddr = 1;
if (setsockopt(cwmp_main.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) {
if (setsockopt(cwmp_main->cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) {
CWMP_LOG(WARNING, "setsockopt(SO_REUSEADDR) failed");
}
@ -402,7 +405,7 @@ void http_server_init(void)
for (;; i++) {
server.sin6_port = htons(cr_port);
//Bind
if (bind(cwmp_main.cr_socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
if (bind(cwmp_main->cr_socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
//print the error message
CWMP_LOG(ERROR, "Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno));
cr_port = DEFAULT_CONNECTION_REQUEST_PORT + i;
@ -416,9 +419,11 @@ void http_server_init(void)
char cr_port_str[6];
snprintf(cr_port_str, 6, "%hu", cr_port);
cr_port_str[5] = '\0';
cwmp_uci_init();
cwmp_uci_set_value("cwmp", "cpe", "port", cr_port_str);
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
connection_request_port_value_change(&cwmp_main, cr_port);
connection_request_port_value_change(cr_port);
cwmp_uci_exit();
CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port);
}
@ -430,15 +435,15 @@ void http_server_listen(void)
struct sockaddr_in6 client;
//Listen
listen(cwmp_main.cr_socket_desc, 3);
listen(cwmp_main->cr_socket_desc, 3);
//Accept and incoming connection
c = sizeof(struct sockaddr_in);
while ((client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
while ((client_sock = accept(cwmp_main->cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
bool service_available;
time_t current_time;
if (thread_end)
if (cwmp_stop)
return;
current_time = time(NULL);
@ -454,7 +459,6 @@ void http_server_listen(void)
}
}
http_cr_new_client(client_sock, service_available);
close(client_sock);
}
if (client_sock < 0) {
@ -463,7 +467,7 @@ void http_server_listen(void)
}
}
void http_server_listen_uloop(struct uloop_fd *ufd, unsigned events)
void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsigned events __attribute__((unused)))
{
http_server_listen();
}
@ -471,7 +475,7 @@ void http_server_listen_uloop(struct uloop_fd *ufd, unsigned events)
void http_server_start_uloop(void)
{
http_server_init();
http_event6.fd = cwmp_main.cr_socket_desc;
http_event6.fd = cwmp_main->cr_socket_desc;
http_event6.cb = http_server_listen_uloop;
uloop_fd_add(&http_event6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
}

View file

@ -38,9 +38,9 @@ struct search_keywords {
extern pthread_mutex_t mutex_backup_session;
int cwmp_init_backup_session(struct cwmp *cwmp, char **ret, enum backup_loading load);
int cwmp_init_backup_session(char **ret, enum backup_loading load);
void bkp_session_save();
int cwmp_load_saved_session(struct cwmp *cwmp, char **acsurl, enum backup_loading load);
int cwmp_load_saved_session(char **acsurl, enum backup_loading load);
mxml_node_t *bkp_session_insert_event(int index, char *command_key, int id, char *status);
void bkp_session_delete_event(int id, char *status);
void bkp_session_simple_insert_in_parent(char *parent, char *child, char *value);
@ -58,7 +58,7 @@ void bkp_session_insert_change_du_state(struct change_du_state *pchange_du_state
void bkp_session_delete_change_du_state(struct change_du_state *pchange_du_state);
void bkp_session_insert_transfer_complete(struct transfer_complete *ptransfer_complete);
void bkp_session_delete_transfer_complete(struct transfer_complete *ptransfer_complete);
int save_acs_bkp_config(struct cwmp *cwmp);
int save_acs_bkp_config();
void bkp_session_insert_schedule_download(struct download *pschedule_download);
void bkp_session_insert_apply_schedule_download(struct apply_schedule_download *papply_schedule_download);

View file

@ -56,10 +56,11 @@
#define CWMP_VARSTATE_UCI_PACKAGE "/var/state/cwmp"
extern char *commandKey;
extern bool thread_end;
extern bool signal_exit;
extern bool cwmp_stop;
extern bool ubus_exit;
extern struct uloop_timeout session_timer;
extern struct uloop_timeout priodic_session_timer;
extern struct uloop_timeout retry_session_timer;
extern bool g_firewall_restart;
typedef struct env {
@ -90,7 +91,6 @@ typedef struct config {
int periodic_notify_interval;
int compression;
int delay_reboot;
int cr_auth_type;
time_t schedule_reboot;
time_t time;
bool periodic_enable;
@ -117,42 +117,20 @@ struct deviceid {
char *softwareversion;
};
typedef struct session_status {
time_t last_start_time;
time_t last_end_time;
int last_status;
time_t next_periodic;
time_t next_retry;
unsigned int success_session;
unsigned int failure_session;
} session_status;
typedef struct cwmp {
struct env env;
struct config conf;
struct deviceid deviceid;
struct list_head head_session_queue;
pthread_mutex_t mutex_session_queue;
struct session *session_send;
struct session *session;
bool cwmp_cr_event;
pthread_mutex_t mutex_session_send;
pthread_cond_t threshold_session_send;
pthread_mutex_t mutex_periodic;
pthread_mutex_t mutex_notify_periodic;
pthread_cond_t threshold_periodic;
pthread_cond_t threshold_notify_periodic;
pthread_cond_t threshold_handle_notify;
int count_handle_notify;
int retry_count_session;
struct list_head *head_event_container;
FILE *pid_file;
time_t start_time;
struct session_status session_status;
unsigned int cwmp_id;
int cr_socket_desc;
bool is_boot;
bool custom_notify_active;
struct uloop_fd http_event;
} cwmp;
enum action {
@ -331,15 +309,15 @@ enum client_server_faults { FAULT_CPE_TYPE_CLIENT, FAULT_CPE_TYPE_SERVER };
struct rpc_cpe_method {
const char *name;
int (*handler)(struct session *session, struct rpc *rpc);
int (*handler)(struct rpc *rpc);
int amd;
};
struct rpc_acs_method {
const char *name;
int (*prepare_message)(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int (*parse_response)(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int (*extra_clean)(struct session *session, struct rpc *rpc);
int (*prepare_message)(struct rpc *rpc);
int (*parse_response)(struct rpc *rpc);
int (*extra_clean)(struct rpc *rpc);
};
typedef struct FAULT_CPE {
@ -451,7 +429,7 @@ typedef struct opfault {
char *fault_string;
} opfault;
extern struct cwmp cwmp_main;
extern struct cwmp *cwmp_main;
extern long int flashsize;
extern struct FAULT_CPE FAULT_CPE_ARRAY[];
extern struct cwmp_namespaces ns;
@ -493,13 +471,16 @@ bool icwmp_validate_string_length(char *arg, int max_length);
bool icwmp_validate_boolean_value(char *arg);
bool icwmp_validate_unsignedint(char *arg);
bool icwmp_validate_int_in_range(char *arg, int min, int max);
void load_forced_inform_json_file(struct cwmp *cwmp);
void load_forced_inform_json_file();
void clean_custom_inform_parameters();
char *string_to_hex(const unsigned char *str, size_t size);
char *generate_random_string(size_t size);
int copy_file(char *source_file, char *target_file);
int cwmp_get_session_retry_interval(struct cwmp *cwmp);
int cwmp_get_session_retry_interval();
int cwmp_apply_acs_changes();
void check_firewall_restart_state();
void cwmp_end_handler(int signal_num __attribute__((unused)));
#ifndef FREE
#define FREE(x) \
do { \

View file

@ -18,9 +18,9 @@
extern pthread_mutex_t mutex_config_load;
int global_conf_init(struct cwmp *cwmp);
int get_global_config(struct config *conf);
int cwmp_get_deviceid(struct cwmp *cwmp);
int cwmp_config_reload(struct cwmp *cwmp);
int global_conf_init();
int get_global_config();
int cwmp_get_deviceid();
int cwmp_config_reload();
#endif

View file

@ -18,7 +18,7 @@ extern pthread_cond_t threshold_change_du_state;
int cwmp_du_install(char *url, char *uuid, char *user, char *pass, char *env, char **package_version, char **package_name, char **package_uuid, char **package_env, char **fault_code);
int cwmp_du_update(char *url, char *uuid, char *user, char *pass, char **package_version, char **package_name, char **package_uuid, char **package_env, char **fault_code);
int cwmp_du_uninstall(char *package_name, char *package_env, char **fault_code);
int cwmp_rpc_acs_destroy_data_du_state_change_complete(struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_destroy_data_du_state_change_complete(struct rpc *rpc);
void *thread_cwmp_rpc_cpe_change_du_state(void *v);
int cwmp_free_change_du_state_request(struct change_du_state *change_du_state);
#endif

View file

@ -37,7 +37,7 @@ int cwmp_free_apply_schedule_download_request(struct apply_schedule_download *ap
int cwmp_scheduledDownload_remove_all();
int cwmp_scheduled_Download_remove_all();
int cwmp_apply_scheduled_Download_remove_all();
int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_destroy_data_transfer_complete(struct rpc *rpc);
void *thread_cwmp_rpc_cpe_download(void *v);
void *thread_cwmp_rpc_cpe_schedule_download(void *v);
void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v);

View file

@ -68,17 +68,16 @@ enum event_idx_enum
extern const struct EVENT_CONST_STRUCT EVENT_CONST[__EVENT_IDX_MAX];
extern pthread_mutex_t add_event_mutext;
struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_idx, char *command_key);
int event_remove_all_event_container(struct session *session, int rem_from);
int event_remove_noretry_event_container(struct session *session, struct cwmp *cwmp);
struct event_container *cwmp_add_event_container(int event_idx, char *command_key);
int event_remove_all_event_container(int rem_from);
int event_remove_noretry_event_container();
void cwmp_save_event_container(struct event_container *event_container);
void *thread_event_periodic(void *v);
void connection_request_ip_value_change(struct cwmp *cwmp, int version);
void connection_request_port_value_change(struct cwmp *cwmp, int port);
void connection_request_ip_value_change(int version);
void connection_request_port_value_change(int port);
int cwmp_get_int_event_code(char *code);
bool event_exist_in_list(struct cwmp *cwmp, int event);
int cwmp_root_cause_events(struct cwmp *cwmp);
int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complete *p);
int cwmp_root_cause_changedustate_complete(struct cwmp *cwmp, struct du_state_change_complete *p);
bool event_exist_in_list(int event);
int cwmp_root_cause_events();
int cwmp_root_cause_transfer_complete(struct transfer_complete *p);
int cwmp_root_cause_changedustate_complete(struct du_state_change_complete *p);
void cwmp_root_cause_event_ipdiagnostic(void);
#endif /* SRC_INC_EVENT_H_ */

View file

@ -13,6 +13,8 @@
#include "common.h"
extern char *fc_cookies;
extern pthread_t http_cr_server_thread;
#define HTTP_TIMEOUT 30
struct http_client {
@ -22,12 +24,12 @@ struct http_client {
void http_set_timeout(void);
int http_client_init(struct cwmp *cwmp);
int http_client_init();
void http_client_exit(void);
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in);
int http_send_message(char *msg_out, int msg_out_len, char **msg_in);
int http_cr_server_init(void);
void http_server_start(void);
void http_success_cr(void);
void http_server_init(void);
#endif

View file

@ -19,7 +19,7 @@
#include "common.h"
#include "event.h"
#include "datamodel_interface.h"
#include "rpc_soap.h"
#include "soap.h"
enum NOTIFICATION_STATUS
{
@ -55,19 +55,19 @@ void cwmp_update_enabled_notify_file(void);
int check_value_change(void);
void create_list_param_obj_notify();
void create_list_param_leaf_notify();
void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *p);
void sotfware_version_value_change(struct transfer_complete *p);
void *thread_periodic_check_notify(void *v);
void send_active_value_change(void);
void add_list_value_change(char *param_name, char *param_data, char *param_type);
void clean_list_value_change();
char *cwmp_set_parameter_attributes(char *parameter_name, int notification);
char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *parameters_list);
void load_custom_notify_json(struct cwmp *cwmp);
void load_custom_notify_json();
void add_lw_list_value_change(char *param_name, char *param_data, char *param_type);
char *calculate_lwnotification_cnonce();
void cwmp_lwnotification();
void clean_list_param_notify();
void init_list_param_notify();
void reinit_list_param_notify();
void cwmp_prepare_value_change(struct cwmp *cwmp);
void cwmp_prepare_value_change();
#endif /* SRC_INC_NOTIFICATIONS_H_ */

View file

@ -13,7 +13,7 @@
#include "common.h"
void launch_reboot_methods(struct cwmp *cwmp);
void launch_reboot_methods();
#endif //_REBOOT_H__

View file

@ -1,60 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*
*/
#ifndef __RPC__SOAP__H_
#define __RPC__SOAP__H_
#include <microxml.h>
#include "common.h"
#include "session.h"
#include "xml.h"
#define MAX_NBRE_CUSTOM_INFORM 256
extern char *custom_forced_inform_parameters[MAX_NBRE_CUSTOM_INFORM];
extern char *boot_inform_parameters[MAX_NBRE_CUSTOM_INFORM];
extern int nbre_custom_inform;
extern int nbre_boot_inform;
extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX];
extern const struct rpc_acs_method rpc_acs_methods[__RPC_ACS_MAX];
int cwmp_handle_rpc_cpe_get_rpc_methods(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_reboot(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_factory_reset(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct session *session, struct rpc *rpc);
int cancel_transfer(char *key);
int cwmp_handle_rpc_cpe_cancel_transfer(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_schedule_inform(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc);
int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_message_inform(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_parse_response_inform(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_get_rpc_methods(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_transfer_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_du_state_change_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_destroy_data_inform(struct session *session, struct rpc *rpc);
int xml_handle_message(struct session *session);
int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code);
#endif

View file

@ -18,11 +18,21 @@
extern struct uloop_timeout retry_session_timer;
extern pthread_mutex_t start_session_mutext;
typedef struct session_status {
time_t last_start_time;
time_t last_end_time;
int last_status;
time_t next_periodic;
time_t next_retry;
unsigned int success_session;
unsigned int failure_session;
} session_status;
typedef struct session {
struct list_head list;
struct list_head head_event_container;
struct list_head head_rpc_cpe;
struct list_head head_rpc_acs;
struct list_head events;
struct session_status session_status;
mxml_node_t *tree_in;
mxml_node_t *tree_out;
mxml_node_t *body_in;
@ -62,17 +72,18 @@ enum enum_session_status
extern unsigned int end_session_flag;
void cwmp_set_end_session(unsigned int flag);
struct rpc *cwmp_add_session_rpc_cpe(struct session *session, int type);
struct session *cwmp_add_queue_session(struct cwmp *cwmp);
struct rpc *cwmp_add_session_rpc_acs(struct session *session, int type);
int cwmp_move_session_to_session_send(struct cwmp *cwmp, struct session *session);
struct rpc *cwmp_add_session_rpc_acs_head(struct session *session, int type);
struct rpc *cwmp_add_session_rpc_cpe(int type);
struct rpc *cwmp_add_session_rpc_acs(int type);
struct rpc *cwmp_add_session_rpc_acs_head(int type);
int cwmp_session_rpc_destructor(struct rpc *rpc);
int cwmp_session_destructor(struct session *session);
int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *session);
void trigger_cwmp_session_timer();
void initiate_cwmp_periodic_session_feature();
int run_session_end_func(void);
void cwmp_schedule_session(struct uloop_timeout *timeout);
void start_cwmp_session(struct cwmp *cwmp);
void start_cwmp_session();
int create_cwmp_session_structure();
int clean_cwmp_session_structure();
void set_cwmp_session_status(int status, int retry_time);
int cwmp_session_init();
int cwmp_session_exit();
#endif /* SRC_INC_SESSION_H_ */

60
inc/soap.h Normal file
View file

@ -0,0 +1,60 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*
*/
#ifndef __RPC__SOAP__H_
#define __RPC__SOAP__H_
#include <microxml.h>
#include "common.h"
#include "session.h"
#include "xml.h"
#define MAX_NBRE_CUSTOM_INFORM 256
extern char *custom_forced_inform_parameters[MAX_NBRE_CUSTOM_INFORM];
extern char *boot_inform_parameters[MAX_NBRE_CUSTOM_INFORM];
extern int nbre_custom_inform;
extern int nbre_boot_inform;
extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX];
extern const struct rpc_acs_method rpc_acs_methods[__RPC_ACS_MAX];
int cwmp_handle_rpc_cpe_get_rpc_methods(struct rpc *rpc);
int cwmp_handle_rpc_cpe_set_parameter_values(struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_values(struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_names(struct rpc *rpc);
int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc);
int cwmp_handle_rpc_cpe_get_parameter_attributes(struct rpc *rpc);
int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc);
int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc);
int cwmp_handle_rpc_cpe_reboot(struct rpc *rpc);
int cwmp_handle_rpc_cpe_download(struct rpc *rpc);
int cwmp_handle_rpc_cpe_upload(struct rpc *rpc);
int cwmp_handle_rpc_cpe_factory_reset(struct rpc *rpc);
int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct rpc *rpc);
int cancel_transfer(char *key);
int cwmp_handle_rpc_cpe_cancel_transfer(struct rpc *rpc);
int cwmp_handle_rpc_cpe_schedule_inform(struct rpc *rpc);
int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc);
int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc);
int cwmp_handle_rpc_cpe_fault(struct rpc *rpc);
int cwmp_rpc_acs_prepare_message_inform(struct rpc *rpc);
int cwmp_rpc_acs_parse_response_inform(struct rpc *rpc);
int cwmp_rpc_acs_prepare_get_rpc_methods(struct rpc *rpc);
int cwmp_rpc_acs_prepare_transfer_complete(struct rpc *rpc);
int cwmp_rpc_acs_prepare_du_state_change_complete(struct rpc *rpc);
int cwmp_rpc_acs_destroy_data_inform(struct rpc *rpc);
int xml_handle_message();
int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code);
#endif

View file

@ -18,7 +18,7 @@
#include "common.h"
#define ARRAY_MAX 8
int cwmp_ubus_init(struct cwmp *cwmp);
int cwmp_ubus_init();
void cwmp_ubus_exit(void);
enum cwmp_ubus_arg_type

View file

@ -19,13 +19,13 @@
} while (0)
extern const char *cwmp_urls[];
int xml_prepare_msg_out(struct session *session);
int xml_prepare_msg_out();
int xml_prepare_lwnotification_message(char **msg_out);
int xml_set_cwmp_id_rpc_cpe(struct session *session);
int xml_set_cwmp_id_rpc_cpe();
int xml_recreate_namespace(mxml_node_t *tree);
const char *whitespace_cb(mxml_node_t *node, int where);
int xml_set_cwmp_id(struct session *session);
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int xml_set_cwmp_id();
int xml_send_message(struct rpc *rpc);
mxml_node_t *mxmlFindElementOpaque(mxml_node_t *node, mxml_node_t *top, const char *text, int descend);
char *xml_get_cwmp_version(int version);
void xml_exit(void);

View file

@ -117,18 +117,18 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
}
if_indextoname(ifa->ifa_index, if_name);
if (itfcmp(cwmp_main.conf.interface, if_name)) {
if (itfcmp(cwmp_main->conf.interface, if_name)) {
rth = RTA_NEXT(rth, rtl);
continue;
}
inet_ntop(AF_INET, &(addr), if_addr, INET_ADDRSTRLEN);
FREE(cwmp_main.conf.ip);
cwmp_main.conf.ip = strdup(if_addr);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", cwmp_main.conf.ip);
FREE(cwmp_main->conf.ip);
cwmp_main->conf.ip = strdup(if_addr);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", cwmp_main->conf.ip);
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
connection_request_ip_value_change(&cwmp_main, IPv4);
connection_request_ip_value_change(IPv4);
break;
}
} else { //CASE IPv6
@ -140,16 +140,16 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
}
inet_ntop(AF_INET6, RTA_DATA(rth), pradd_v6, sizeof(pradd_v6));
if_indextoname(ifa->ifa_index, if_name);
if (strncmp(cwmp_main.conf.interface, if_name, IFNAMSIZ)) {
if (strncmp(cwmp_main->conf.interface, if_name, IFNAMSIZ)) {
rth = RTA_NEXT(rth, rtl);
continue;
}
FREE(cwmp_main.conf.ipv6);
cwmp_main.conf.ipv6 = strdup(pradd_v6);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", cwmp_main.conf.ip);
FREE(cwmp_main->conf.ipv6);
cwmp_main->conf.ipv6 = strdup(pradd_v6);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", cwmp_main->conf.ip);
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
connection_request_ip_value_change(&cwmp_main, IPv6);
connection_request_ip_value_change(IPv6);
break;
}
}
@ -293,7 +293,7 @@ void cwmp_netlink_init(void)
CWMP_LOG(ERROR, "netlink initialization failed");
}
if (cwmp_main.conf.ipv6_enable) {
if (cwmp_main->conf.ipv6_enable) {
if (netlink_init_v6()) {
CWMP_LOG(ERROR, "netlink initialization failed");
}

View file

@ -385,15 +385,15 @@ void cwmp_update_enabled_notify_file(void)
/*
* Load custom notify json file
*/
void load_custom_notify_json(struct cwmp *cwmp)
void load_custom_notify_json()
{
struct blob_buf bbuf;
struct blob_attr *cur;
struct blob_attr *custom_notify_list = NULL;
int rem;
cwmp->custom_notify_active = false;
if (cwmp->conf.custom_notify_json == NULL || !file_exists(cwmp->conf.custom_notify_json))
cwmp_main->custom_notify_active = false;
if (cwmp_main->conf.custom_notify_json == NULL || !file_exists(cwmp_main->conf.custom_notify_json))
return;
if (file_exists(NOTIFY_FILE))
@ -402,8 +402,8 @@ void load_custom_notify_json(struct cwmp *cwmp)
memset(&bbuf, 0, sizeof(struct blob_buf));
blob_buf_init(&bbuf, 0);
if (blobmsg_add_json_from_file(&bbuf, cwmp->conf.custom_notify_json) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.custom_notify_json);
if (blobmsg_add_json_from_file(&bbuf, cwmp_main->conf.custom_notify_json) == false) {
CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_main->conf.custom_notify_json);
blob_buf_free(&bbuf);
creat(NOTIFY_FILE , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return;
@ -419,7 +419,7 @@ void load_custom_notify_json(struct cwmp *cwmp)
custom_notify_list = tb_notif[0];
if (custom_notify_list == NULL) {
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a notify parameters list", cwmp->conf.custom_notify_json);
CWMP_LOG(WARNING, "The JSON file %s doesn't contain a notify parameters list", cwmp_main->conf.custom_notify_json);
blob_buf_free(&bbuf);
creat(NOTIFY_FILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return;
@ -449,7 +449,7 @@ void load_custom_notify_json(struct cwmp *cwmp)
}
blob_buf_free(&bbuf);
creat(NOTIFY_FILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp->custom_notify_active = true;
cwmp_main->custom_notify_active = true;
}
/*
@ -540,75 +540,59 @@ int check_value_change(void)
return int_ret;
}
void cwmp_prepare_value_change(struct cwmp *cwmp)
void cwmp_prepare_value_change()
{
struct event_container *event_container;
if (list_value_change.next == &(list_value_change))
return;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
if (!event_container)
goto end;
return;
pthread_mutex_lock(&(mutex_value_change));
list_splice_init(&(list_value_change), &(event_container->head_dm_parameter));
pthread_mutex_unlock(&(mutex_value_change));
cwmp_save_event_container(event_container);
end:
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
}
void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *p)
void sotfware_version_value_change(struct transfer_complete *p)
{
char *current_software_version = NULL;
if (!p->old_software_version || p->old_software_version[0] == 0)
return;
current_software_version = cwmp->deviceid.softwareversion;
current_software_version = cwmp_main->deviceid.softwareversion;
if (p->old_software_version && current_software_version && strcmp(p->old_software_version, current_software_version) != 0) {
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
}
}
void *thread_periodic_check_notify(void *v)
void *thread_periodic_check_notify(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
static int periodic_interval;
//static int periodic_interval;
static bool periodic_enable;
static struct timespec periodic_timeout = { 0, 0 };
time_t current_time;
int is_notify = 0;
periodic_interval = cwmp->conf.periodic_notify_interval;
periodic_enable = cwmp->conf.periodic_notify_enable;
//periodic_interval = cwmp_main->conf.periodic_notify_interval;
periodic_enable = cwmp_main->conf.periodic_notify_enable;
for (;;) {
if (periodic_enable) {
pthread_mutex_lock(&(cwmp->mutex_notify_periodic));
current_time = time(NULL);
periodic_timeout.tv_sec = current_time + periodic_interval;
// pthread_mutex_lock(&(cwmp_main->mutex_notify_periodic));
if (thread_end)
if (cwmp_stop)
break;
pthread_cond_timedwait(&(cwmp->threshold_notify_periodic), &(cwmp->mutex_notify_periodic), &periodic_timeout);
//pthread_cond_timedwait(&(cwmp_main->threshold_notify_periodic), &(cwmp_main->mutex_notify_periodic), &periodic_timeout);
if (thread_end)
break;
pthread_mutex_lock(&(cwmp->mutex_session_send));
is_notify = check_value_change();
if (is_notify > 0)
cwmp_update_enabled_notify_file();
pthread_mutex_unlock(&(cwmp->mutex_session_send));
if (is_notify & NOTIF_ACTIVE)
send_active_value_change();
if (is_notify & NOTIF_LW_ACTIVE)
cwmp_lwnotification();
pthread_mutex_unlock(&(cwmp->mutex_notify_periodic));
//pthread_mutex_unlock(&(cwmp_main->mutex_notify_periodic));
} else
break;
}
@ -631,19 +615,14 @@ void clean_list_value_change()
void send_active_value_change(void)
{
struct cwmp *cwmp = &cwmp_main;
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return;
}
cwmp_save_event_container(event_container);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
pthread_cond_signal(&(cwmp->threshold_session_send));
return;
}
@ -654,10 +633,9 @@ void add_lw_list_value_change(char *param_name, char *param_data, char *param_ty
static void udplw_server_param(struct addrinfo **res)
{
struct addrinfo hints = { 0 };
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
struct config *conf = &(cwmp_main->conf);
char port[32];
conf = &(cwmp->conf);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
snprintf(port, sizeof(port), "%d", conf->lw_notification_port);
@ -669,9 +647,7 @@ static void message_compute_signature(char *msg_out, char *signature)
int i;
int result_len = 20;
unsigned char *result;
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
struct config *conf = &(cwmp_main->conf);
/* unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
const unsigned char *d, size_t n, unsigned char *md,
unsigned int *md_len);*/
@ -728,9 +704,7 @@ void cwmp_lwnotification()
char msg[1024], *msg_out;
char signature[41];
struct addrinfo *servaddr;
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
struct config *conf = &(cwmp_main->conf);
udplw_server_param(&servaddr);
xml_prepare_lwnotification_message(&msg_out);

View file

@ -18,38 +18,35 @@
static pthread_t delay_reboot_thread;
static pthread_t delay_schedule_thread;
static void *thread_delay_reboot(void *arg)
static void *thread_delay_reboot(void *arg __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)arg;
CWMP_LOG(INFO, "The device will reboot after %d seconds", cwmp->conf.delay_reboot);
sleep(cwmp->conf.delay_reboot);
CWMP_LOG(INFO, "The device will reboot after %d seconds", cwmp_main->conf.delay_reboot);
sleep(cwmp_main->conf.delay_reboot);
cwmp_uci_set_value("cwmp", "cpe", "delay_reboot", "-1");
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
/* check if the session is running before calling reboot method */
/* if the session is in progress, wait until the end of the session */
/* else calling reboot method */
if (cwmp->session_status.last_status == SESSION_RUNNING) {
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) {
cwmp_set_end_session(END_SESSION_REBOOT);
} else {
cwmp_reboot("delay_reboot");
exit(EXIT_SUCCESS);
}
return NULL;
}
static void create_delay_reboot_thread(struct cwmp *cwmp, bool thread_exist)
static void create_delay_reboot_thread(bool thread_exist)
{
if (thread_exist) {
CWMP_LOG(INFO, "There is already a delay reboot thread!, Cancel the current thread");
pthread_cancel(delay_reboot_thread);
create_delay_reboot_thread(cwmp, false);
create_delay_reboot_thread(false);
} else {
CWMP_LOG(INFO, "Create a delay reboot thread");
if (pthread_create(&delay_reboot_thread, NULL, &thread_delay_reboot, (void *)cwmp)) {
if (pthread_create(&delay_reboot_thread, NULL, &thread_delay_reboot, (void *)cwmp_main)) {
CWMP_LOG(ERROR, "Error when creating the delay reboot thread!");
}
@ -59,10 +56,9 @@ static void create_delay_reboot_thread(struct cwmp *cwmp, bool thread_exist)
}
}
static void *thread_schedule_reboot(void *arg)
static void *thread_schedule_reboot(void *arg __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)arg;
time_t remaining_time = cwmp->conf.schedule_reboot - time(NULL);
time_t remaining_time = cwmp_main->conf.schedule_reboot - time(NULL);
CWMP_LOG(INFO, "The device will reboot after %ld seconds", remaining_time);
sleep(remaining_time);
@ -72,7 +68,7 @@ static void *thread_schedule_reboot(void *arg)
/* check if the session is running before calling reboot method */
/* if the session is in progress, wait until the end of the session */
/* else calling reboot method */
if (cwmp->session_status.last_status == SESSION_RUNNING) {
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) {
cwmp_set_end_session(END_SESSION_REBOOT);
} else {
cwmp_reboot("schedule_reboot");
@ -82,17 +78,17 @@ static void *thread_schedule_reboot(void *arg)
return NULL;
}
static void create_schedule_reboot_thread(struct cwmp *cwmp, bool thread_exist)
static void create_schedule_reboot_thread(bool thread_exist)
{
if (thread_exist) {
CWMP_LOG(INFO, "There is already a schedule reboot thread!, Cancel the current thread");
pthread_cancel(delay_schedule_thread);
create_schedule_reboot_thread(cwmp, false);
create_schedule_reboot_thread(false);
} else {
CWMP_LOG(INFO, "Create a schedule reboot thread");
if (pthread_create(&delay_schedule_thread, NULL, &thread_schedule_reboot, (void *)cwmp)) {
if (pthread_create(&delay_schedule_thread, NULL, &thread_schedule_reboot, (void *)cwmp_main)) {
CWMP_LOG(ERROR, "Error when creating the schedule reboot thread!");
}
@ -102,20 +98,20 @@ static void create_schedule_reboot_thread(struct cwmp *cwmp, bool thread_exist)
}
}
void launch_reboot_methods(struct cwmp *cwmp)
void launch_reboot_methods()
{
static int curr_delay_reboot = -1;
static time_t curr_schedule_redoot = 0;
if (cwmp->conf.delay_reboot != curr_delay_reboot && cwmp->conf.delay_reboot > 0) {
if (cwmp_main->conf.delay_reboot != curr_delay_reboot && cwmp_main->conf.delay_reboot > 0) {
create_delay_reboot_thread(cwmp, (curr_delay_reboot != -1));
curr_delay_reboot = cwmp->conf.delay_reboot;
create_delay_reboot_thread(curr_delay_reboot != -1);
curr_delay_reboot = cwmp_main->conf.delay_reboot;
}
if (cwmp->conf.schedule_reboot != curr_schedule_redoot && (cwmp->conf.schedule_reboot - time(NULL)) > 0) {
if (cwmp_main->conf.schedule_reboot != curr_schedule_redoot && (cwmp_main->conf.schedule_reboot - time(NULL)) > 0) {
create_schedule_reboot_thread(cwmp, (curr_schedule_redoot != 0));
curr_schedule_redoot = cwmp->conf.schedule_reboot;
create_schedule_reboot_thread((curr_schedule_redoot != 0));
curr_schedule_redoot = cwmp_main->conf.schedule_reboot;
}
}

View file

@ -20,9 +20,8 @@ pthread_cond_t threshold_schedule_inform;
int count_schedule_inform_queue = 0;
void *thread_cwmp_rpc_cpe_scheduleInform(void *v)
void *thread_cwmp_rpc_cpe_scheduleInform(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct event_container *event_container;
struct schedule_inform *schedule_inform;
struct timespec si_timeout = { 0, 0 };
@ -31,7 +30,7 @@ void *thread_cwmp_rpc_cpe_scheduleInform(void *v)
for (;;) {
if (thread_end)
if (cwmp_stop)
break;
if (list_schedule_inform.next != &(list_schedule_inform)) {
@ -50,18 +49,15 @@ void *thread_cwmp_rpc_cpe_scheduleInform(void *v)
pthread_mutex_unlock(&mutex_schedule_inform);
continue;
}
pthread_mutex_lock(&(cwmp->mutex_session_queue));
CWMP_LOG(INFO, "Schedule Inform thread: add ScheduleInform event in the queue");
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_3SCHEDULED, "");
event_container = cwmp_add_event_container(EVENT_IDX_3SCHEDULED, "");
if (event_container != NULL) {
cwmp_save_event_container(event_container);
}
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_ScheduleInform, schedule_inform->commandKey);
event_container = cwmp_add_event_container(EVENT_IDX_M_ScheduleInform, schedule_inform->commandKey);
if (event_container != NULL) {
cwmp_save_event_container(event_container);
}
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_schedule_inform);
list_del(&(schedule_inform->list));
if (schedule_inform->commandKey != NULL) {

449
session.c
View file

@ -13,12 +13,12 @@
#include "event.h"
#include "backupSession.h"
#include "config.h"
#include "rpc_soap.h"
#include "cwmp_uci.h"
#include "log.h"
#include "http.h"
#include "notifications.h"
#include "diagnostic.h"
#include "soap.h"
pthread_mutex_t start_session_mutext = PTHREAD_MUTEX_INITIALIZER;
static void cwmp_priodic_session_timer(struct uloop_timeout *timeout);
@ -28,61 +28,125 @@ struct uloop_timeout retry_session_timer = { .cb = cwmp_schedule_session };
unsigned int end_session_flag = 0;
static int cwmp_rpc_cpe_handle_message(struct session *session, struct rpc *rpc_cpe)
int create_cwmp_session_structure()
{
if (xml_prepare_msg_out(session))
cwmp_main->session = calloc(1, sizeof(struct session));
if (cwmp_main->session == NULL)
return CWMP_GEN_ERR;
INIT_LIST_HEAD(&(cwmp_main->session->events));
INIT_LIST_HEAD(&(cwmp_main->session->head_rpc_acs));
INIT_LIST_HEAD(&(cwmp_main->session->head_rpc_cpe));
return CWMP_OK;
}
int cwmp_session_init()
{
struct rpc *rpc_acs;
cwmp_main->cwmp_cr_event = 0;
cwmp_uci_init();
if ((rpc_acs = cwmp_add_session_rpc_acs_head(RPC_ACS_INFORM)) == NULL)
return CWMP_GEN_ERR;
set_cwmp_session_status(SESSION_RUNNING, 0);
if (file_exists(fc_cookies))
remove(fc_cookies);
return CWMP_OK;
}
int clean_cwmp_session_structure()
{
FREE(cwmp_main->session);
return 0;
}
int cwmp_session_rpc_destructor(struct rpc *rpc)
{
list_del(&(rpc->list));
free(rpc);
return CWMP_OK;
}
int cwmp_session_exit()
{
struct rpc *rpc;
while (cwmp_main->session->head_rpc_acs.next != &(cwmp_main->session->head_rpc_acs)) {
rpc = list_entry(cwmp_main->session->head_rpc_acs.next, struct rpc, list);
if (!rpc)
break;
if (rpc_acs_methods[rpc->type].extra_clean != NULL)
rpc_acs_methods[rpc->type].extra_clean(rpc);
cwmp_session_rpc_destructor(rpc);
}
while (cwmp_main->session->head_rpc_cpe.next != &(cwmp_main->session->head_rpc_cpe)) {
rpc = list_entry(cwmp_main->session->head_rpc_cpe.next, struct rpc, list);
if (!rpc)
break;
cwmp_session_rpc_destructor(rpc);
}
cwmp_uci_exit();
icwmp_cleanmem();
return CWMP_OK;
}
static int cwmp_rpc_cpe_handle_message(struct rpc *rpc_cpe)
{
if (xml_prepare_msg_out(cwmp_main->session))
return -1;
if (rpc_cpe_methods[rpc_cpe->type].handler(session, rpc_cpe))
if (rpc_cpe_methods[rpc_cpe->type].handler(rpc_cpe))
return -1;
if (xml_set_cwmp_id_rpc_cpe(session))
if (xml_set_cwmp_id_rpc_cpe())
return -1;
return 0;
}
static int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session)
static int cwmp_schedule_rpc()
{
struct list_head *ilist;
struct rpc *rpc_acs, *rpc_cpe;
if (http_client_init(cwmp) || thread_end) {
if (http_client_init() || cwmp_stop) {
CWMP_LOG(INFO, "Initializing http client failed");
goto retry;
}
while (1) {
list_for_each (ilist, &(session->head_rpc_acs)) {
list_for_each (ilist, &(cwmp_main->session->head_rpc_acs)) {
rpc_acs = list_entry(ilist, struct rpc, list);
if (!rpc_acs->type || thread_end)
if (!rpc_acs->type || cwmp_stop)
goto retry;
CWMP_LOG(INFO, "Preparing the %s RPC message to send to the ACS", rpc_acs_methods[rpc_acs->type].name);
if (rpc_acs_methods[rpc_acs->type].prepare_message(cwmp, session, rpc_acs) || thread_end)
if (rpc_acs_methods[rpc_acs->type].prepare_message(rpc_acs) || cwmp_stop)
goto retry;
if (xml_set_cwmp_id(session) || thread_end)
if (xml_set_cwmp_id() || cwmp_stop)
goto retry;
CWMP_LOG(INFO, "Send the %s RPC message to the ACS", rpc_acs_methods[rpc_acs->type].name);
if (xml_send_message(cwmp, session, rpc_acs) || thread_end)
if (xml_send_message(rpc_acs) || cwmp_stop)
goto retry;
CWMP_LOG(INFO, "Get the %sResponse message from the ACS", rpc_acs_methods[rpc_acs->type].name);
if (rpc_acs_methods[rpc_acs->type].parse_response || thread_end)
if (rpc_acs_methods[rpc_acs->type].parse_response(cwmp, session, rpc_acs))
if (rpc_acs_methods[rpc_acs->type].parse_response || cwmp_stop)
if (rpc_acs_methods[rpc_acs->type].parse_response(rpc_acs))
goto retry;
ilist = ilist->prev;
if (rpc_acs_methods[rpc_acs->type].extra_clean != NULL)
rpc_acs_methods[rpc_acs->type].extra_clean(session, rpc_acs);
rpc_acs_methods[rpc_acs->type].extra_clean(rpc_acs);
cwmp_session_rpc_destructor(rpc_acs);
MXML_DELETE(session->tree_in);
MXML_DELETE(session->tree_out);
if (session->hold_request || thread_end)
MXML_DELETE(cwmp_main->session->tree_in);
MXML_DELETE(cwmp_main->session->tree_out);
if (cwmp_main->session->hold_request || cwmp_stop)
break;
}
@ -91,117 +155,112 @@ static int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session)
check_firewall_restart_state();
CWMP_LOG(INFO, "Send empty message to the ACS");
if (xml_send_message(cwmp, session, NULL) || thread_end)
if (xml_send_message(NULL) || cwmp_stop)
goto retry;
if (!session->tree_in || thread_end)
if (!cwmp_main->session->tree_in || cwmp_stop)
goto next;
CWMP_LOG(INFO, "Receive request from the ACS");
if (xml_handle_message(session) || thread_end)
if (xml_handle_message() || cwmp_stop)
goto retry;
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
while (cwmp_main->session->head_rpc_cpe.next != &(cwmp_main->session->head_rpc_cpe)) {
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
if (!rpc_cpe->type || thread_end)
rpc_cpe = list_entry(cwmp_main->session->head_rpc_cpe.next, struct rpc, list);
if (!rpc_cpe->type || cwmp_stop)
goto retry;
CWMP_LOG(INFO, "Preparing the %s%s message", rpc_cpe_methods[rpc_cpe->type].name, (rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
if (cwmp_rpc_cpe_handle_message(session, rpc_cpe) || thread_end)
if (cwmp_rpc_cpe_handle_message(rpc_cpe) || cwmp_stop)
goto retry;
MXML_DELETE(session->tree_in);
MXML_DELETE(cwmp_main->session->tree_in);
CWMP_LOG(INFO, "Send the %s%s message to the ACS", rpc_cpe_methods[rpc_cpe->type].name, (rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
if (xml_send_message(cwmp, session, rpc_cpe) || thread_end)
if (xml_send_message(rpc_cpe) || cwmp_stop)
goto retry;
MXML_DELETE(session->tree_out);
MXML_DELETE(cwmp_main->session->tree_out);
cwmp_session_rpc_destructor(rpc_cpe);
if (!session->tree_in || thread_end)
if (!cwmp_main->session->tree_in || cwmp_stop)
break;
CWMP_LOG(INFO, "Receive request from the ACS");
if (xml_handle_message(session) || thread_end)
if (xml_handle_message() || cwmp_stop)
goto retry;
}
next:
if (session->head_rpc_acs.next == &(session->head_rpc_acs))
if (cwmp_main->session->head_rpc_acs.next == &(cwmp_main->session->head_rpc_acs))
break;
MXML_DELETE(session->tree_in);
MXML_DELETE(session->tree_out);
MXML_DELETE(cwmp_main->session->tree_in);
MXML_DELETE(cwmp_main->session->tree_out);
}
session->error = CWMP_OK;
cwmp_main->session->error = CWMP_OK;
goto end;
retry:
CWMP_LOG(INFO, "Failed");
session->error = CWMP_RETRY_SESSION;
event_remove_noretry_event_container(session, cwmp);
cwmp_main->session->error = CWMP_RETRY_SESSION;
event_remove_noretry_event_container();
end:
MXML_DELETE(session->tree_in);
MXML_DELETE(session->tree_out);
MXML_DELETE(cwmp_main->session->tree_in);
MXML_DELETE(cwmp_main->session->tree_out);
http_client_exit();
xml_exit();
return session->error;
return cwmp_main->session->error;
}
void start_cwmp_session(struct cwmp *cwmp)
void set_cwmp_session_status(int status, int retry_time)
{
int t, error = CWMP_OK;
static struct timespec time_to_wait = { 0, 0 };
cwmp_main->session->session_status.last_status = status;
if (status == SESSION_SUCCESS) {
cwmp_main->session->session_status.last_end_time = time(NULL);
cwmp_main->session->session_status.next_retry = 0;
cwmp_main->session->session_status.success_session++;
} else if (status == SESSION_RUNNING) {
cwmp_main->session->session_status.last_end_time = 0;
cwmp_main->session->session_status.next_retry = 0;
cwmp_main->session->session_status.last_start_time = time(NULL);
} else {
cwmp_main->session->session_status.last_end_time = time(NULL);
cwmp_main->session->session_status.next_retry = time(NULL) + retry_time;
cwmp_main->session->session_status.failure_session++;
}
}
void start_cwmp_session()
{
int t, error;
char *exec_download = NULL;
int is_notify = 0;
printf("%s:%s line %d\n", __FILE__, __FUNCTION__, __LINE__);
cwmp->cwmp_cr_event = 0;
struct list_head *ilist;
struct session *session;
/*
* Get the session to be executed
*/
ilist = (&(cwmp->head_session_queue))->next;
session = list_entry(ilist, struct session, list);
/*
* Initiate UCI
*/
cwmp_uci_init();
if (cwmp_session_init() != CWMP_OK) {
CWMP_LOG(ERROR, "Not able to init a CWMP session");
t = cwmp_get_session_retry_interval();
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
set_cwmp_session_status(SESSION_FAILURE, t);
uloop_timeout_set(&retry_session_timer, 1000 * t);
}
/*
* Value changes
*/
if (file_exists(DM_ENABLED_NOTIFY)) {
if (!event_exist_in_list(cwmp, EVENT_IDX_4VALUE_CHANGE))
if (!event_exist_in_list(EVENT_IDX_4VALUE_CHANGE))
is_notify = check_value_change();
}
if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp->custom_notify_active) {
cwmp->custom_notify_active = false;
if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp_main->custom_notify_active) {
cwmp_main->custom_notify_active = false;
cwmp_update_enabled_notify_file();
}
cwmp_prepare_value_change(cwmp);
cwmp_prepare_value_change(cwmp_main);
clean_list_value_change();
/*
* Start session
*/
if ((error = cwmp_move_session_to_session_send(cwmp, session))) {
CWMP_LOG(EMERG, "FATAL error in the mutex process in the session scheduler!");
exit(EXIT_FAILURE);
}
printf("%s:%s line %d\n", __FILE__, __FUNCTION__, __LINE__);
cwmp->session_status.last_end_time = 0;
cwmp->session_status.last_start_time = time(NULL);
cwmp->session_status.last_status = SESSION_RUNNING;
cwmp->session_status.next_retry = 0;
if (file_exists(fc_cookies))
remove(fc_cookies);
CWMP_LOG(INFO, "Start session");
@ -212,41 +271,33 @@ void start_cwmp_session(struct cwmp *cwmp)
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
}
FREE(exec_download);
error = cwmp_schedule_rpc(cwmp, session);
error = cwmp_schedule_rpc();
if (error != CWMP_OK)
CWMP_LOG(ERROR, "CWMP session error: %d", error);
/*
* End session
*/
CWMP_LOG(INFO, "End session");
if (thread_end) {
event_remove_all_event_container(session, RPC_SEND);
if (cwmp_stop) {
event_remove_all_event_container(RPC_SEND);
run_session_end_func();
cwmp_session_destructor(session);
return;
}
run_session_end_func();
if (session->error == CWMP_RETRY_SESSION && (!list_empty(&(session->head_event_container)) || (list_empty(&(session->head_event_container)) && cwmp->cwmp_cr_event == 0))) { //CWMP Retry session
error = cwmp_move_session_to_session_queue(cwmp, session);
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp->retry_count_session, cwmp_get_session_retry_interval(cwmp));
cwmp->session_status.last_end_time = time(NULL);
cwmp->session_status.last_status = SESSION_FAILURE;
cwmp->session_status.next_retry = time(NULL) + cwmp_get_session_retry_interval(cwmp);
cwmp->session_status.failure_session++;
t = cwmp_get_session_retry_interval(cwmp);
time_to_wait.tv_sec = time(NULL) + t;
if (cwmp_main->session->error == CWMP_RETRY_SESSION && (!list_empty(&(cwmp_main->session->events)) || (list_empty(&(cwmp_main->session->events)) && cwmp_main->cwmp_cr_event == 0))) { //CWMP Retry session
cwmp_main->retry_count_session++;
t = cwmp_get_session_retry_interval();
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
set_cwmp_session_status(SESSION_FAILURE, t);
uloop_timeout_set(&retry_session_timer, 1000 * t);
} else {
event_remove_all_event_container(session, RPC_SEND);
cwmp_session_destructor(session);
cwmp->session_send = NULL;
cwmp->retry_count_session = 0;
cwmp->session_status.last_end_time = time(NULL);
cwmp->session_status.last_status = SESSION_SUCCESS;
cwmp->session_status.next_retry = 0;
cwmp->session_status.success_session++;
event_remove_all_event_container(RPC_SEND);
cwmp_main->retry_count_session = 0;
set_cwmp_session_status(SESSION_SUCCESS, 0);
}
run_session_end_func();
cwmp_session_exit();
CWMP_LOG(INFO, "Waiting the next session");
}
@ -257,21 +308,21 @@ void trigger_cwmp_session_timer()
uloop_timeout_set(&session_timer, 10);
}
void cwmp_schedule_session(struct uloop_timeout *timeout)
void cwmp_schedule_session(struct uloop_timeout *timeout __attribute__((unused)))
{
pthread_mutex_lock(&start_session_mutext);
start_cwmp_session(&cwmp_main);
start_cwmp_session();
pthread_mutex_unlock(&start_session_mutext);
}
static void cwmp_priodic_session_timer(struct uloop_timeout *timeout)
static void cwmp_priodic_session_timer(struct uloop_timeout *timeout __attribute__((unused)))
{
if (cwmp_main.conf.periodic_enable && cwmp_main.conf.period > 0) {
cwmp_main.session_status.next_periodic = time(NULL) + cwmp_main.conf.period;
uloop_timeout_set(&priodic_session_timer, cwmp_main.conf.period * 1000);
if (cwmp_main->conf.periodic_enable && cwmp_main->conf.period > 0) {
cwmp_main->session->session_status.next_periodic = time(NULL) + cwmp_main->conf.period;
uloop_timeout_set(&priodic_session_timer, cwmp_main->conf.period * 1000);
}
if (cwmp_main.conf.periodic_enable) {
cwmp_add_event_container(&cwmp_main, EVENT_IDX_2PERIODIC, "");
if (cwmp_main->conf.periodic_enable) {
cwmp_add_event_container(EVENT_IDX_2PERIODIC, "");
trigger_cwmp_session_timer();
}
}
@ -281,33 +332,33 @@ long int cwmp_periodic_session_time(void)
long int delta_time;
long int periodic_time;
delta_time = time(NULL) - cwmp_main.conf.time;
delta_time = time(NULL) - cwmp_main->conf.time;
if(delta_time > 0)
periodic_time = cwmp_main.conf.period - (delta_time % cwmp_main.conf.period);
periodic_time = cwmp_main->conf.period - (delta_time % cwmp_main->conf.period);
else
periodic_time = (-delta_time) % cwmp_main.conf.period;
periodic_time = (-delta_time) % cwmp_main->conf.period;
cwmp_main.session_status.next_periodic = time(NULL) + periodic_time;
cwmp_main->session->session_status.next_periodic = time(NULL) + periodic_time;
return periodic_time;
}
void initiate_cwmp_periodic_session_feature()
{
uloop_timeout_cancel(&priodic_session_timer);
if (cwmp_main.conf.periodic_enable && cwmp_main.conf.period > 0) {
if (cwmp_main.conf.time >= 0){
CWMP_LOG(INFO, "init periodic inform: reference time = %ld, interval = %d\n", cwmp_main.conf.time, cwmp_main.conf.period);
if (cwmp_main->conf.periodic_enable && cwmp_main->conf.period > 0) {
if (cwmp_main->conf.time >= 0){
CWMP_LOG(INFO, "Init periodic inform: periodic_inform time = %ld, interval = %d\n", cwmp_main->conf.time, cwmp_main->conf.period);
uloop_timeout_set(&priodic_session_timer, cwmp_periodic_session_time() * 1000);
}
else {
CWMP_LOG(INFO, "init periodic inform: reference time = n/a, interval = %d\n", cwmp_main.conf.period);
cwmp_main.session_status.next_periodic = time(NULL) + cwmp_main.conf.period;
uloop_timeout_set(&priodic_session_timer, cwmp_main.conf.period * 1000);
CWMP_LOG(INFO, "Init periodic inform: interval = %d\n", cwmp_main->conf.period);
cwmp_main->session->session_status.next_periodic = time(NULL) + cwmp_main->conf.period;
uloop_timeout_set(&priodic_session_timer, cwmp_main->conf.period * 1000);
}
}
}
struct rpc *cwmp_add_session_rpc_cpe(struct session *session, int type)
struct rpc *cwmp_add_session_rpc_cpe(int type)
{
struct rpc *rpc_cpe;
@ -316,11 +367,11 @@ struct rpc *cwmp_add_session_rpc_cpe(struct session *session, int type)
return NULL;
}
rpc_cpe->type = type;
list_add_tail(&(rpc_cpe->list), &(session->head_rpc_cpe));
list_add_tail(&(rpc_cpe->list), &(cwmp_main->session->head_rpc_cpe));
return rpc_cpe;
}
struct rpc *cwmp_add_session_rpc_acs(struct session *session, int type)
struct rpc *cwmp_add_session_rpc_acs(int type)
{
struct rpc *rpc_acs;
@ -329,18 +380,18 @@ struct rpc *cwmp_add_session_rpc_acs(struct session *session, int type)
return NULL;
}
rpc_acs->type = type;
list_add_tail(&(rpc_acs->list), &(session->head_rpc_acs));
list_add_tail(&(rpc_acs->list), &(cwmp_main->session->head_rpc_acs));
return rpc_acs;
}
int cwmp_get_session_retry_interval(struct cwmp *cwmp)
int cwmp_get_session_retry_interval()
{
int retry_count = 0;
double min = 0;
double max = 0;
int m = cwmp->conf.retry_min_wait_interval;
int k = cwmp->conf.retry_interval_multiplier;
int exp = cwmp->retry_count_session;
int m = cwmp_main->conf.retry_min_wait_interval;
int k = cwmp_main->conf.retry_interval_multiplier;
int exp = cwmp_main->retry_count_session;
if (exp == 0)
return MAX_INT32;
if (exp > 10)
@ -352,23 +403,7 @@ int cwmp_get_session_retry_interval(struct cwmp *cwmp)
return (retry_count);
}
int cwmp_move_session_to_session_send(struct cwmp *cwmp, struct session *session)
{
pthread_mutex_lock(&(cwmp->mutex_session_queue));
if (cwmp->session_send != NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MUTEX_ERR;
}
list_del(&(session->list));
cwmp->session_send = session;
cwmp->head_event_container = NULL;
bkp_session_move_inform_to_inform_send();
bkp_session_save();
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_OK;
}
struct rpc *cwmp_add_session_rpc_acs_head(struct session *session, int type)
struct rpc *cwmp_add_session_rpc_acs_head(int type)
{
struct rpc *rpc_acs;
@ -377,137 +412,10 @@ struct rpc *cwmp_add_session_rpc_acs_head(struct session *session, int type)
return NULL;
}
rpc_acs->type = type;
list_add(&(rpc_acs->list), &(session->head_rpc_acs));
list_add(&(rpc_acs->list), &(cwmp_main->session->head_rpc_acs));
return rpc_acs;
}
struct session *cwmp_add_queue_session(struct cwmp *cwmp)
{
struct session *session = NULL;
struct rpc *rpc_acs;
session = calloc(1, sizeof(struct session));
if (session == NULL)
return NULL;
list_add_tail(&(session->list), &(cwmp->head_session_queue));
INIT_LIST_HEAD(&(session->head_event_container));
INIT_LIST_HEAD(&(session->head_rpc_acs));
INIT_LIST_HEAD(&(session->head_rpc_cpe));
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
FREE(session);
return NULL;
}
return session;
}
int cwmp_session_rpc_destructor(struct rpc *rpc)
{
list_del(&(rpc->list));
free(rpc);
return CWMP_OK;
}
int cwmp_session_destructor(struct session *session)
{
struct rpc *rpc;
while (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
rpc = list_entry(session->head_rpc_acs.next, struct rpc, list);
if (!rpc)
break;
if (rpc_acs_methods[rpc->type].extra_clean != NULL)
rpc_acs_methods[rpc->type].extra_clean(session, rpc);
cwmp_session_rpc_destructor(rpc);
}
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
rpc = list_entry(session->head_rpc_cpe.next, struct rpc, list);
if (!rpc)
break;
cwmp_session_rpc_destructor(rpc);
}
if (session->list.next != NULL && session->list.prev != NULL)
list_del(&(session->list));
free(session);
return CWMP_OK;
}
int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *session)
{
struct list_head *ilist, *jlist;
struct rpc *rpc_acs, *queue_rpc_acs;
struct session *session_queue;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->retry_count_session++;
cwmp->session_send = NULL;
if (cwmp->head_session_queue.next == &(cwmp->head_session_queue)) {
list_add_tail(&(session->list), &(cwmp->head_session_queue));
session->hold_request = 0;
session->digest_auth = 0;
cwmp->head_event_container = &(session->head_event_container);
if (session->head_rpc_acs.next != &(session->head_rpc_acs)) {
rpc_acs = list_entry(session->head_rpc_acs.next, struct rpc, list);
if (rpc_acs->type != RPC_ACS_INFORM) {
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
}
} else {
if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
}
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
struct rpc *rpc_cpe;
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
cwmp_session_rpc_destructor(rpc_cpe);
}
bkp_session_move_inform_to_inform_queue();
bkp_session_save();
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_OK;
}
list_for_each (ilist, &(session->head_event_container)) {
struct event_container *event_container_new, *event_container_old;
event_container_old = list_entry(ilist, struct event_container, list);
event_container_new = cwmp_add_event_container(cwmp, event_container_old->code, event_container_old->command_key);
if (event_container_new == NULL) {
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
list_splice_init(&(event_container_old->head_dm_parameter), &(event_container_new->head_dm_parameter));
cwmp_save_event_container(event_container_new);
}
session_queue = list_entry(cwmp->head_event_container, struct session, head_event_container);
list_for_each (ilist, &(session->head_rpc_acs)) {
rpc_acs = list_entry(ilist, struct rpc, list);
bool dup;
dup = false;
list_for_each (jlist, &(session_queue->head_rpc_acs)) {
queue_rpc_acs = list_entry(jlist, struct rpc, list);
if (queue_rpc_acs->type == rpc_acs->type && (rpc_acs->type == RPC_ACS_INFORM || rpc_acs->type == RPC_ACS_GET_RPC_METHODS)) {
dup = true;
break;
}
}
if (dup) {
continue;
}
ilist = ilist->prev;
list_del(&(rpc_acs->list));
list_add_tail(&(rpc_acs->list), &(session_queue->head_rpc_acs));
}
cwmp_session_destructor(session);
pthread_mutex_unlock(&(cwmp->mutex_session_queue));
return CWMP_OK;
}
void cwmp_set_end_session(unsigned int flag)
{
end_session_flag |= flag;
@ -524,6 +432,7 @@ int run_session_end_func(void)
CWMP_LOG(INFO, "Config reload: end session request");
cwmp_uci_reinit();
cwmp_apply_acs_changes();
initiate_cwmp_periodic_session_feature();
}
if (end_session_flag & END_SESSION_INIT_NOTIFY) {
@ -588,8 +497,6 @@ int run_session_end_func(void)
cwmp_factory_reset();
exit(EXIT_SUCCESS);
}
cwmp_uci_exit();
icwmp_cleanmem();
end_session_flag = 0;
return CWMP_OK;
}

File diff suppressed because it is too large Load diff

View file

@ -7,13 +7,12 @@ LDFLAGS = -lmicroxml -luci -lblobmsg_json -lubox -ljson-c -lubus -lpthread -lcur
LIBCFLAGS = -g -Wall -fPIC -c -I../../inc
LIBOBJ = libobj
UNIT_TESTS = icwmp_datamodel_interface_unit_testd icwmp_soap_msg_unit_testd icwmp_backup_session_unit_testd icwmp_custom_inform_parameters_unit_testd icwmp_notifications_unit_testd icwmp_uci_unit_testd icwmp_cli_unit_testd
VALGRIND = valgrind --xml=yes --xml-file=/builds/iopsys/icwmp/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all
VALGRIND = valgrind --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all
libobj:
$(CC) $(LIBCFLAGS) ../../download.c ../../upload.c ../../log.c ../../md5.c ../../digestauth.c ../../netlink.c ../../cwmp_cli.c ../../cwmp_du_state.c ../../sched_inform.c \
../../diagnostic.c ../../reboot.c ../../notifications.c ../../cwmp_zlib.c ../../datamodel_interface.c ../../http.c ../../backupSession.c \
../../cwmp_time.c ../../config.c ../../event.c ../../session.c ../../ubus.c ../../common.c ../../xml.c ../../rpc_soap.c ../../cwmp_uci.c ../../cwmp.c $(LDFLAGS)
../../cwmp_time.c ../../config.c ../../event.c ../../session.c ../../ubus.c ../../common.c ../../xml.c ../../soap.c ../../cwmp_uci.c ../../cwmp.c $(LDFLAGS)
libicwmp: $(LIBOBJ)
$(CC) -shared -Wl,-soname,libicwmp.so.1 -o libicwmp.so.1.0 *.o
@ -57,7 +56,7 @@ icwmp_custom_inform_parameters_unit_testd: icwmp_custom_inform_parameters_unit_t
unit-test: $(UNIT_TESTS)
for testprog in $(UNIT_TESTS); do \
sudo $(VALGRIND) ./$$testprog; \
sudo $(VALGRIND) --xml=yes --xml-file=/builds/iopsys/icwmp/$$testprog-mem-report.xml ./$$testprog; \
cp ../files/etc/config/* /etc/config; \
cp ../files/var/state/* /var/state; \
done

View file

@ -23,22 +23,30 @@
struct cwmp cwmp_main_test = { 0 };
static int bkp_session_unit_tests_init(void **state)
{
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
create_cwmp_session_structure();
return 0;
}
static int bkp_session_unit_tests_clean(void **state)
{
icwmp_cleanmem();
clean_cwmp_session_structure();
FREE(cwmp_main);
return 0;
}
static void cwmp_backup_session_unit_test(void **state)
{
remove(CWMP_BKP_FILE);
struct cwmp *cwmp_test = &cwmp_main_test;
mxml_node_t *backup_tree = NULL, *n = NULL;
/*
* Init backup session
*/
int error = cwmp_init_backup_session(cwmp_test, NULL, ALL);
int error = cwmp_init_backup_session(NULL, ALL);
assert_int_equal(error, 0);
bkp_session_save();
FILE *pFile;
@ -301,5 +309,5 @@ int main(void)
cmocka_unit_test(cwmp_backup_session_unit_test),
};
return cmocka_run_group_tests(tests, NULL, bkp_session_unit_tests_clean);
return cmocka_run_group_tests(tests, bkp_session_unit_tests_init, bkp_session_unit_tests_clean);
}

View file

@ -29,15 +29,20 @@ static char *add_instance = NULL;
static int cwmp_cli_unit_tests_init(void **state)
{
cwmp_uci_init();
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
create_cwmp_session_structure();
memcpy(&(cwmp_main->env), &cwmp_main, sizeof(struct env));
cwmp_session_init();
return 0;
}
static int cwmp_cli_unit_tests_clean(void **state)
{
icwmp_cleanmem();
FREE(add_instance);
icwmp_free_list_services();
cwmp_uci_exit();
cwmp_session_exit();
FREE(cwmp_main->session);
FREE(cwmp_main);
FREE(add_instance);
return 0;
}

View file

@ -18,9 +18,44 @@
#include <libicwmp/common.h>
#include <libicwmp/config.h>
#include <libicwmp/rpc_soap.h>
#include <libicwmp/soap.h>
struct cwmp cwmp_main_test = { 0 };
static int custom_inform_unit_tests_init(void **state)
{
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
get_global_config();
return 0;
}
void clean_config()
{
FREE(cwmp_main->deviceid.manufacturer);
FREE(cwmp_main->deviceid.serialnumber);
FREE(cwmp_main->deviceid.productclass);
FREE(cwmp_main->deviceid.oui);
FREE(cwmp_main->deviceid.softwareversion);
FREE(cwmp_main->conf.lw_notification_hostname);
FREE(cwmp_main->conf.ip);
FREE(cwmp_main->conf.ipv6);
FREE(cwmp_main->conf.acsurl);
FREE(cwmp_main->conf.acs_userid);
FREE(cwmp_main->conf.acs_passwd);
FREE(cwmp_main->conf.interface);
FREE(cwmp_main->conf.cpe_userid);
FREE(cwmp_main->conf.cpe_passwd);
FREE(cwmp_main->conf.ubus_socket);
FREE(cwmp_main->conf.connection_request_path);
FREE(cwmp_main->conf.default_wan_iface);
FREE(cwmp_main->conf.interface);
}
static int custom_inform_unit_tests_clean(void **state)
{
clean_config();
icwmp_cleanmem();
FREE(cwmp_main);
return 0;
}
static int verify_inform_parameter_in_list(char *parameter)
{
@ -32,60 +67,32 @@ static int verify_inform_parameter_in_list(char *parameter)
return 0;
}
void clean_config(struct cwmp *cwmp_test)
{
FREE(cwmp_test->deviceid.manufacturer);
FREE(cwmp_test->deviceid.serialnumber);
FREE(cwmp_test->deviceid.productclass);
FREE(cwmp_test->deviceid.oui);
FREE(cwmp_test->deviceid.softwareversion);
FREE(cwmp_test->conf.lw_notification_hostname);
FREE(cwmp_test->conf.ip);
FREE(cwmp_test->conf.ipv6);
FREE(cwmp_test->conf.acsurl);
FREE(cwmp_test->conf.acs_userid);
FREE(cwmp_test->conf.acs_passwd);
FREE(cwmp_test->conf.interface);
FREE(cwmp_test->conf.cpe_userid);
FREE(cwmp_test->conf.cpe_passwd);
FREE(cwmp_test->conf.ubus_socket);
FREE(cwmp_test->conf.connection_request_path);
FREE(cwmp_test->conf.default_wan_iface);
FREE(cwmp_test->conf.interface);
}
static void cwmp_custom_inform_unit_test(void **state)
{
struct cwmp *cwmp_test = &cwmp_main_test;
get_global_config(&(cwmp_test->conf));
cwmp_test->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_valid.json");
load_forced_inform_json_file(cwmp_test);
cwmp_main->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_valid.json");
load_forced_inform_json_file();
assert_int_equal(nbre_custom_inform, 2);
assert_int_equal(verify_inform_parameter_in_list("Device.DeviceInfo.X_IOPSYS_EU_BaseMACAddress"), 1);
assert_int_equal(verify_inform_parameter_in_list("Device.DeviceInfo.UpTime"), 1);
FREE(cwmp_test->conf.forced_inform_json_file);
FREE(cwmp_main->conf.forced_inform_json_file);
clean_custom_inform_parameters();
cwmp_test->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_invalid_json.json");
load_forced_inform_json_file(cwmp_test);
cwmp_main->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_invalid_json.json");
load_forced_inform_json_file();
assert_int_equal(nbre_custom_inform, 0);
assert_int_equal(verify_inform_parameter_in_list("Device.DeviceInfo.X_IOPSYS_EU_BaseMACAddress"), 0);
assert_int_equal(verify_inform_parameter_in_list("Device.DeviceInfo.UpTime"), 0);
FREE(cwmp_test->conf.forced_inform_json_file);
FREE(cwmp_main->conf.forced_inform_json_file);
clean_custom_inform_parameters();
cwmp_test->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_invalid_parameter.json");
load_forced_inform_json_file(cwmp_test);
cwmp_main->conf.forced_inform_json_file = strdup("/etc/icwmpd/forced_inform_invalid_parameter.json");
load_forced_inform_json_file();
assert_int_equal(nbre_custom_inform, 1);
assert_int_equal(verify_inform_parameter_in_list("Devie.DeviceInfo.X_IOPSYS_EU_BaseMACAddress"), 0);
assert_int_equal(verify_inform_parameter_in_list("Device."), 0);
assert_int_equal(verify_inform_parameter_in_list("Device.DeviceInfo.UpTime"), 1);
FREE(cwmp_test->conf.forced_inform_json_file);
FREE(cwmp_main->conf.forced_inform_json_file);
clean_custom_inform_parameters();
clean_config(cwmp_test);
icwmp_cleanmem();
}
int main(void)
@ -94,5 +101,5 @@ int main(void)
cmocka_unit_test(cwmp_custom_inform_unit_test),
};
return cmocka_run_group_tests(tests, NULL, NULL);
return cmocka_run_group_tests(tests, custom_inform_unit_tests_init, custom_inform_unit_tests_clean);
}

View file

@ -19,13 +19,50 @@
#include <libicwmp/datamodel_interface.h>
#include <libicwmp/event.h>
#include <libicwmp/xml.h>
#include <libicwmp/rpc_soap.h>
#include <libicwmp/soap.h>
#include <libicwmp/session.h>
#include <libicwmp/log.h>
LIST_HEAD(list_set_param_value);
LIST_HEAD(faults_list);
LIST_HEAD(parameters_list);
static int dm_iface_unit_tests_init(void **state)
{
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
create_cwmp_session_structure();
global_conf_init();
return 0;
}
static int dm_iface_unit_tests_clean(void **state)
{
icwmp_free_list_services();
icwmp_cleanmem();
clean_cwmp_session_structure();
FREE(cwmp_main->deviceid.manufacturer);
FREE(cwmp_main->deviceid.serialnumber);
FREE(cwmp_main->deviceid.productclass);
FREE(cwmp_main->deviceid.oui);
FREE(cwmp_main->deviceid.softwareversion);
FREE(cwmp_main->conf.lw_notification_hostname);
FREE(cwmp_main->conf.ip);
FREE(cwmp_main->conf.ipv6);
FREE(cwmp_main->conf.acsurl);
FREE(cwmp_main->conf.acs_userid);
FREE(cwmp_main->conf.acs_passwd);
FREE(cwmp_main->conf.interface);
FREE(cwmp_main->conf.cpe_userid);
FREE(cwmp_main->conf.cpe_passwd);
FREE(cwmp_main->conf.ubus_socket);
FREE(cwmp_main->conf.connection_request_path);
FREE(cwmp_main->conf.default_wan_iface);
FREE(cwmp_main->conf.forced_inform_json_file);
FREE(cwmp_main->conf.custom_notify_json);
FREE(cwmp_main->conf.boot_inform_json_file);
FREE(cwmp_main);
cwmp_free_all_list_param_fault(&faults_list);
cwmp_free_all_dm_parameter_list(&list_set_param_value);
return 0;
}
@ -35,7 +72,7 @@ static int dm_iface_unit_tests_clean(void **state)
static void dm_get_parameter_values_test(void **state)
{
char *fault = NULL;
LIST_HEAD(parameters_list);
/*
* Test of valid parameter path
*/
@ -89,15 +126,13 @@ static void dm_set_multiple_parameter_values_test(void **state)
int fault_code = 0;
char *fault_name = NULL;
struct cwmp_param_fault *param_fault = NULL;
LIST_HEAD(list_set_param_value);
LIST_HEAD(faults_array);
/*
* Test of one valid parameter
*/
add_dm_parameter_to_list(&list_set_param_value, "Device.WiFi.SSID.1.Alias", "wifi_alias_1", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_list);
assert_int_equal(fault, 0);
assert_in_set(flag, flag_values, 15);
cwmp_transaction_commit();
@ -106,7 +141,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
add_dm_parameter_to_list(&list_set_param_value, "Device.ManagementServer.Username", "iopsys_user", NULL, 0, false); //for other flag value
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "mngt_server_user", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "mngt_server_user", &flag, &faults_list);
assert_int_equal(fault, 0);
assert_in_set(flag, flag_values, 15);
cwmp_transaction_commit();
@ -119,9 +154,9 @@ static void dm_set_multiple_parameter_values_test(void **state)
*/
add_dm_parameter_to_list(&list_set_param_value, "Device.WiFi.SSID.1.Alis", "wifi_alias_1", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_list);
assert_non_null(fault);
list_for_each_entry (param_fault, &faults_array, list) {
list_for_each_entry (param_fault, &faults_list, list) {
fault_code = param_fault->fault;
fault_name = param_fault->name;
break;
@ -131,7 +166,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
assert_non_null(fault_name);
cwmp_transaction_abort();
cwmp_free_all_dm_parameter_list(&list_set_param_value);
cwmp_free_all_list_param_fault(&faults_array);
cwmp_free_all_list_param_fault(&faults_list);
fault_code = 0;
fault_name = NULL;
param_fault = NULL;
@ -142,9 +177,9 @@ static void dm_set_multiple_parameter_values_test(void **state)
*/
add_dm_parameter_to_list(&list_set_param_value, "Device.ATM.Link.1.Status", "Up", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_atm_link_status", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_atm_link_status", &flag, &faults_list);
assert_int_not_equal(fault, 0);
list_for_each_entry (param_fault, &faults_array, list) {
list_for_each_entry (param_fault, &faults_list, list) {
fault_code = param_fault->fault;
fault_name = param_fault->name;
break;
@ -154,7 +189,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
assert_non_null(fault_name);
cwmp_transaction_abort();
cwmp_free_all_dm_parameter_list(&list_set_param_value);
cwmp_free_all_list_param_fault(&faults_array);
cwmp_free_all_list_param_fault(&faults_list);
fault = 0;
fault_code = 0;
fault_name = NULL;
@ -165,9 +200,9 @@ static void dm_set_multiple_parameter_values_test(void **state)
*/
add_dm_parameter_to_list(&list_set_param_value, "Device.WiFi.SSID.1.Enable", "tre", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssid_alias", &flag, &faults_list);
assert_non_null(fault);
list_for_each_entry (param_fault, &faults_array, list) {
list_for_each_entry (param_fault, &faults_list, list) {
fault_code = param_fault->fault;
fault_name = param_fault->name;
break;
@ -177,7 +212,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
assert_non_null(fault_name);
cwmp_transaction_abort();
cwmp_free_all_dm_parameter_list(&list_set_param_value);
cwmp_free_all_list_param_fault(&faults_array);
cwmp_free_all_list_param_fault(&faults_list);
fault_code = 0;
fault_name = NULL;
param_fault = NULL;
@ -190,7 +225,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
add_dm_parameter_to_list(&list_set_param_value, "Device.WiFi.SSID.1.SSID", "wifi_ssid_2", NULL, 0, false);
add_dm_parameter_to_list(&list_set_param_value, "Device.ManagementServer.Username", "iopsys_user_1", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssids_aliases", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wifi_ssids_aliases", &flag, &faults_list);
assert_int_equal(fault, 0);
assert_in_set(flag, flag_values, 15);
cwmp_transaction_commit();
@ -204,12 +239,13 @@ static void dm_set_multiple_parameter_values_test(void **state)
add_dm_parameter_to_list(&list_set_param_value, "Device.WiFi.SSID.2.Alis", "wifi_2", NULL, 0, false);
add_dm_parameter_to_list(&list_set_param_value, "Device.ATM.Link.1.Status", "Up", NULL, 0, false);
cwmp_transaction_start("cwmp");
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wrongs", &flag, &faults_array);
fault = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_wrongs", &flag, &faults_list);
assert_int_not_equal(fault, 0);
list_for_each_entry (param_fault, &faults_array, list) {
list_for_each_entry (param_fault, &faults_list, list) {
assert_in_set(param_fault->fault, faults_values, 3);
}
cwmp_transaction_commit();
cwmp_free_all_list_param_fault(&faults_list);
cwmp_free_all_dm_parameter_list(&list_set_param_value);
}
@ -331,5 +367,5 @@ int main(void)
cmocka_unit_test(dm_get_parameter_names_test),
};
return cmocka_run_group_tests(tests, NULL, dm_iface_unit_tests_clean);
return cmocka_run_group_tests(tests, dm_iface_unit_tests_init, dm_iface_unit_tests_clean);
}

View file

@ -26,22 +26,28 @@ LIST_HEAD(parameters_list);
static int cwmp_notifications_unit_tests_init(void **state)
{
cwmp_uci_init();
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
create_cwmp_session_structure();
memcpy(&(cwmp_main->env), &cwmp_main, sizeof(struct env));
cwmp_session_init();
return 0;
}
static int cwmp_notifications_unit_tests_clean(void **state)
{
icwmp_cleanmem();
clean_list_param_notify();
clean_list_value_change();
cwmp_free_all_dm_parameter_list(&parameters_list);
cwmp_uci_exit();
cwmp_session_exit();
FREE(cwmp_main->session);
FREE(cwmp_main);
return 0;
}
int check_notify_file(char *param, int *ret_notification)
{
struct blob_buf bbuf;
char *parameter = NULL, *value = NULL;
char *parameter = NULL;
int notification = 0;
FILE *fp;
int nbre_iterations = 0;
@ -265,6 +271,7 @@ static void cwmp_check_value_change_1_unit_test(void **state)
assert_int_equal((int)list_empty(&list_value_change), 0);
assert_int_equal((int)list_empty(&list_lw_value_change), 1);
assert_int_equal(get_parameter_in_list_value_change("Device.DeviceInfo.UpTime"), 1);
clean_list_value_change();
}
int main(void)

File diff suppressed because it is too large Load diff

View file

@ -31,9 +31,9 @@ static int cwmp_uci_unit_tests_init(void **state)
static int cwmp_uci_unit_tests_clean(void **state)
{
icwmp_cleanmem();
cwmp_uci_exit();
if (list != NULL)
cwmp_free_uci_list(list);
cwmp_uci_exit();
return 0;
}
@ -142,21 +142,19 @@ static void cwmp_uci_set_tests(void **state)
static void cwmp_uci_add_tests(void **state)
{
struct uci_section *s = NULL;
int error = UCI_OK;
int error = UCI_OK, cmp_cfg = 0;
error = cwmp_uci_add_section("cwmp", "acs", UCI_STANDARD_CONFIG, &s);
assert_non_null(s);
assert_int_equal(error, UCI_OK);
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
assert_int_equal(strncmp(section_name(s), "cfg", 3), 0);
s = NULL;
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
error = cwmp_uci_add_section("new_package", "new_section", UCI_STANDARD_CONFIG, &s);
assert_non_null(s);
assert_int_equal(error, UCI_OK);
cwmp_commit_package("new_package", UCI_STANDARD_CONFIG);
assert_int_equal(strncmp(section_name(s), "cfg", 3), 0);
s = NULL;
cwmp_commit_package("new_package", UCI_STANDARD_CONFIG);
error = cwmp_uci_add_section_with_specific_name("cwmp", "acs", "new_acs", UCI_STANDARD_CONFIG);
assert_int_equal(error, UCI_OK);
@ -170,7 +168,6 @@ static void cwmp_uci_add_tests(void **state)
static void cwmp_uci_list_tests(void **state)
{
struct uci_section *s = NULL;
int error = UCI_OK;
char *list_string = NULL;
@ -178,28 +175,26 @@ static void cwmp_uci_list_tests(void **state)
assert_int_equal(error, UCI_OK);
error = cwmp_uci_add_list_value("cwmp", "cpe", "optionlist", "val2", UCI_STANDARD_CONFIG);
assert_int_equal(error, UCI_OK);
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
error = cwmp_uci_get_cwmp_standard_option_value_list("cwmp", "cpe", "optionlist", &list);
assert_int_equal(error, UCI_TYPE_LIST);
list_string = cwmp_uci_list_to_string(list, ",");
assert_non_null(list_string);
assert_string_equal(list_string, "val1,val2");
list_string = NULL;
if(list != NULL)
if(list != NULL) {
cwmp_free_uci_list(list);
list = NULL;
}
error = cwmp_uci_add_list_value("cwmp", "wrong_section", "optionlist", "val1", UCI_STANDARD_CONFIG);
assert_int_equal(error, UCI_ERR_INVAL);
error = cwmp_uci_add_list_value("cwmp", "wrong_section", "optionlist", "val2", UCI_STANDARD_CONFIG);
assert_int_equal(error, UCI_ERR_INVAL);
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
error = cwmp_uci_get_cwmp_standard_option_value_list("cwmp", "wrong_section", "optionlist", &list);
assert_int_equal(error, UCI_ERR_NOTFOUND);
assert_null(list);
list_string = cwmp_uci_list_to_string(list, ",");
assert_null(list_string);
if(list != NULL)
cwmp_free_uci_list(list);
}
int main(void)

77
ubus.c
View file

@ -24,7 +24,7 @@
#include "download.h"
#include "upload.h"
#include "http.h"
#include "rpc_soap.h"
#include "soap.h"
static struct ubus_context *ctx = NULL;
@ -68,15 +68,13 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
return -1;
} else if (!strcmp("reload", cmd)) {
CWMP_LOG(INFO, "triggered ubus reload");
if (cwmp_main.session_status.last_status == SESSION_RUNNING) {
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) {
cwmp_set_end_session(END_SESSION_RELOAD);
blobmsg_add_u32(&b, "status", 0);
if (snprintf(info, sizeof(info), "Session running, reload at the end of the session") == -1)
return -1;
} else {
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
cwmp_apply_acs_changes();
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
blobmsg_add_u32(&b, "status", 0);
if (snprintf(info, sizeof(info), "icwmpd config reloaded") == -1)
return -1;
@ -95,30 +93,12 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
return -1;
} else if (!strcmp("exit", cmd)) {
ubus_exit = true;
thread_end = true;
if (cwmp_main.session_status.last_status == SESSION_RUNNING)
http_set_timeout();
pthread_cond_signal(&(cwmp_main.threshold_session_send));
pthread_cond_signal(&(cwmp_main.threshold_periodic));
pthread_cond_signal(&(cwmp_main.threshold_notify_periodic));
pthread_cond_signal(&threshold_schedule_inform);
pthread_cond_signal(&threshold_download);
pthread_cond_signal(&threshold_change_du_state);
pthread_cond_signal(&threshold_schedule_download);
pthread_cond_signal(&threshold_apply_schedule_download);
pthread_cond_signal(&threshold_upload);
uloop_end();
shutdown(cwmp_main.cr_socket_desc, SHUT_RDWR);
if (!signal_exit)
kill(getpid(), SIGTERM);
if (snprintf(info, sizeof(info), "icwmpd daemon stopped") == -1)
return -1;
cwmp_end_handler(SIGTERM);
} else {
blobmsg_add_u32(&b, "status", -1);
if (snprintf(info, sizeof(info), "%s command is not supported", cmd) == -1)
@ -126,6 +106,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
}
blobmsg_add_string(&b, "info", info);
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
@ -140,11 +121,11 @@ static inline time_t get_session_status_next_time()
schedule_inform = list_entry(list_schedule_inform.next, struct schedule_inform, list);
ntime = schedule_inform->scheduled_time;
}
if (!ntime || (cwmp_main.session_status.next_retry && ntime > cwmp_main.session_status.next_retry)) {
ntime = cwmp_main.session_status.next_retry;
if (!ntime || (cwmp_main->session->session_status.next_retry && ntime > cwmp_main->session->session_status.next_retry)) {
ntime = cwmp_main->session->session_status.next_retry;
}
if (!ntime || (cwmp_main.session_status.next_periodic && ntime > cwmp_main.session_status.next_periodic)) {
ntime = cwmp_main.session_status.next_periodic;
if (!ntime || (cwmp_main->session->session_status.next_periodic && ntime > cwmp_main->session->session_status.next_periodic)) {
ntime = cwmp_main->session->session_status.next_periodic;
}
return ntime;
}
@ -159,14 +140,14 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj
c = blobmsg_open_table(&b, "cwmp");
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_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->session_status.last_start_time ? arr_session_status[cwmp_main->session->session_status.last_status] : "N/A");
blobmsg_add_string(&b, "start_time", cwmp_main->session->session_status.last_start_time ? mix_get_time_of(cwmp_main->session->session_status.last_start_time) : "N/A");
blobmsg_add_string(&b, "end_time", cwmp_main->session->session_status.last_end_time ? mix_get_time_of(cwmp_main->session->session_status.last_end_time) : "N/A");
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "next_session");
@ -177,9 +158,9 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "statistics");
blobmsg_add_u32(&b, "success_sessions", cwmp_main.session_status.success_session);
blobmsg_add_u32(&b, "failure_sessions", cwmp_main.session_status.failure_session);
blobmsg_add_u32(&b, "total_sessions", cwmp_main.session_status.success_session + cwmp_main.session_status.failure_session);
blobmsg_add_u32(&b, "success_sessions", cwmp_main->session->session_status.success_session);
blobmsg_add_u32(&b, "failure_sessions", cwmp_main->session->session_status.failure_session);
blobmsg_add_u32(&b, "total_sessions", cwmp_main->session->session_status.success_session + cwmp_main->session->session_status.failure_session);
blobmsg_close_table(&b, c);
ubus_send_reply(ctx, req, b.head);
@ -217,25 +198,25 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
if (tb[INFORM_EVENT]) {
event = blobmsg_data(tb[INFORM_EVENT]);
}
if (grm) {
struct event_container *event_container;
struct session *session;
event_container = cwmp_add_event_container(&cwmp_main, EVENT_IDX_2PERIODIC, "");
event_container = cwmp_add_event_container(EVENT_IDX_2PERIODIC, "");
if (event_container == NULL)
return 0;
cwmp_save_event_container(event_container);
session = list_entry(cwmp_main.head_event_container, struct session, head_event_container);
if (cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL)
//session = list_entry(cwmp_main.head_event_container, struct session, head_event_container);
if (cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL)
return 0;
trigger_cwmp_session_timer();
blobmsg_add_u32(&b, "status", 1);
blobmsg_add_string(&b, "info", "Session with GetRPCMethods will start");
} else {
int event_code = cwmp_get_int_event_code(event);
cwmp_add_event_container(&cwmp_main, event_code, "");
trigger_cwmp_session_timer();
if (cwmp_main.session_status.last_status == SESSION_RUNNING) {
cwmp_add_event_container(event_code, "");
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) {
blobmsg_add_u32(&b, "status", -1);
blobmsg_add_string(&b, "info", "Session already running, event will be sent at the end of the session");
} else {
@ -243,9 +224,9 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
blobmsg_add_string(&b, "info", "Session started");
}
}
trigger_cwmp_session_timer();
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
return 0;
}
@ -264,9 +245,9 @@ static struct ubus_object main_object = {
.n_methods = ARRAYSIZEOF(freecwmp_methods),
};
int cwmp_ubus_init(struct cwmp *cwmp)
int cwmp_ubus_init()
{
ctx = ubus_connect(cwmp->conf.ubus_socket);
ctx = ubus_connect(cwmp_main->conf.ubus_socket);
if (!ctx)
return -1;

View file

@ -160,9 +160,8 @@ end_upload:
return error;
}
void *thread_cwmp_rpc_cpe_upload(void *v)
void *thread_cwmp_rpc_cpe_upload(void *v __attribute__((unused)))
{
struct cwmp *cwmp = (struct cwmp *)v;
struct upload *pupload;
struct timespec upload_timeout = { 0, 0 };
time_t current_time, stime;
@ -172,7 +171,7 @@ void *thread_cwmp_rpc_cpe_upload(void *v)
for (;;) {
if (thread_end)
if (cwmp_stop)
break;
if (list_upload.next != &(list_upload)) {
@ -196,7 +195,7 @@ void *thread_cwmp_rpc_cpe_upload(void *v)
ptransfer_complete->fault_code = error;
ptransfer_complete->type = TYPE_UPLOAD;
bkp_session_insert_transfer_complete(ptransfer_complete);
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
}
list_del(&(pupload->list));
if (pupload->scheduled_time != 0)
@ -206,23 +205,20 @@ void *thread_cwmp_rpc_cpe_upload(void *v)
continue;
}
if ((timeout >= 0) && (timeout <= time_of_grace)) {
pthread_mutex_lock(&(cwmp->mutex_session_send));
CWMP_LOG(INFO, "Launch upload file %s", pupload->url);
error = cwmp_launch_upload(pupload, &ptransfer_complete);
if (error != FAULT_CPE_NO_FAULT) {
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
bkp_session_delete_transfer_complete(ptransfer_complete);
} else {
bkp_session_delete_transfer_complete(ptransfer_complete);
ptransfer_complete->fault_code = error;
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
cwmp_root_cause_transfer_complete(ptransfer_complete);
}
pthread_mutex_unlock(&(cwmp->mutex_session_send));
pthread_cond_signal(&(cwmp->threshold_session_send));
pthread_mutex_lock(&mutex_upload);
list_del(&(pupload->list));
if (pupload->scheduled_time != 0)

70
xml.c
View file

@ -116,19 +116,19 @@ void xml_exit(void)
FREE(ns.cwmp);
}
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc)
int xml_send_message(struct rpc *rpc)
{
char *s, *msg_out = NULL, *msg_in = NULL;
char c[512];
int msg_out_len = 0, f, r = 0;
mxml_node_t *b;
if (session->tree_out) {
if (cwmp_main->session->tree_out) {
unsigned char *zmsg_out;
msg_out = mxmlSaveAllocString(session->tree_out, whitespace_cb);
msg_out = mxmlSaveAllocString(cwmp_main->session->tree_out, whitespace_cb);
CWMP_LOG_XML_MSG(DEBUG, msg_out, XML_MSG_OUT);
if (cwmp->conf.compression != COMP_NONE) {
if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp->conf.compression)) {
if (cwmp_main->conf.compression != COMP_NONE) {
if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp_main->conf.compression)) {
return -1;
}
FREE(msg_out);
@ -139,7 +139,7 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc
}
while (1) {
f = 0;
if (http_send_message(cwmp, msg_out, msg_out_len, &msg_in)) {
if (http_send_message(msg_out, msg_out_len, &msg_in)) {
goto error;
}
if (msg_in) {
@ -167,31 +167,31 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc
}
}
session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK);
if (!session->tree_in)
cwmp_main->session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK);
if (!cwmp_main->session->tree_in)
goto error;
xml_recreate_namespace(session->tree_in);
xml_recreate_namespace(cwmp_main->session->tree_in);
/* get NoMoreRequests or HolRequest*/
session->hold_request = false;
cwmp_main->session->hold_request = false;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "NoMoreRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST);
if (b && b->type == MXML_OPAQUE && b->value.opaque)
session->hold_request = atoi(b->value.opaque);
cwmp_main->session->hold_request = atoi(b->value.opaque);
} else {
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "HoldRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST);
if (b && b->type == MXML_OPAQUE && b->value.opaque)
session->hold_request = atoi(b->value.opaque);
cwmp_main->session->hold_request = atoi(b->value.opaque);
}
}
@ -206,36 +206,34 @@ error:
return -1;
}
int xml_prepare_msg_out(struct session *session)
int xml_prepare_msg_out()
{
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
struct config *conf = &(cwmp_main->conf);
mxml_node_t *n;
session->tree_out = mxmlLoadString(NULL, CWMP_RESPONSE_MESSAGE, MXML_OPAQUE_CALLBACK);
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND);
cwmp_main->session->tree_out = mxmlLoadString(NULL, CWMP_RESPONSE_MESSAGE, MXML_OPAQUE_CALLBACK);
n = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND);
if (!n) {
return -1;
}
mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(conf->amd_version) - 1]);
if (!session->tree_out)
if (!cwmp_main->session->tree_out)
return -1;
return 0;
}
int xml_set_cwmp_id(struct session *session)
int xml_set_cwmp_id()
{
char c[32];
mxml_node_t *b;
/* define cwmp id */
if (snprintf(c, sizeof(c), "%u", ++(cwmp_main.cwmp_id)) == -1)
if (snprintf(c, sizeof(c), "%u", ++(cwmp_main->cwmp_id)) == -1)
return -1;
b = mxmlFindElement(session->tree_out, session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
b = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
if (!b)
return -1;
@ -246,7 +244,7 @@ int xml_set_cwmp_id(struct session *session)
return 0;
}
int xml_set_cwmp_id_rpc_cpe(struct session *session)
int xml_set_cwmp_id_rpc_cpe()
{
char c[512];
mxml_node_t *b;
@ -255,16 +253,16 @@ int xml_set_cwmp_id_rpc_cpe(struct session *session)
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ID") == -1)
return -1;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
/* ACS send ID parameter */
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST);
if (!b || b->type != MXML_OPAQUE || !b->value.opaque)
return 0;
snprintf(c, sizeof(c), "%s", b->value.opaque);
b = mxmlFindElement(session->tree_out, session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
b = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
if (!b)
return -1;
@ -273,7 +271,7 @@ int xml_set_cwmp_id_rpc_cpe(struct session *session)
return -1;
} else {
/* ACS does not send ID parameter */
int r = xml_set_cwmp_id(session);
int r = xml_set_cwmp_id(cwmp_main->session);
return r;
}
return 0;
@ -363,9 +361,7 @@ error:
int xml_prepare_lwnotification_message(char **msg_out)
{
mxml_node_t *lw_tree, *b, *parameter_list;
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
struct config *conf = &(cwmp_main->conf);
char *c = NULL;
lw_tree = mxmlLoadString(NULL, CWMP_LWNOTIFICATION_MESSAGE, MXML_OPAQUE_CALLBACK);
@ -405,7 +401,7 @@ int xml_prepare_lwnotification_message(char **msg_out)
if (!b)
goto error;
b = mxmlNewOpaque(b, cwmp->deviceid.oui);
b = mxmlNewOpaque(b, cwmp_main->deviceid.oui);
if (!b)
goto error;
@ -413,7 +409,7 @@ int xml_prepare_lwnotification_message(char **msg_out)
if (!b)
goto error;
b = mxmlNewOpaque(b, cwmp->deviceid.productclass ? cwmp->deviceid.productclass : "");
b = mxmlNewOpaque(b, cwmp_main->deviceid.productclass ? cwmp_main->deviceid.productclass : "");
if (!b)
goto error;
@ -421,7 +417,7 @@ int xml_prepare_lwnotification_message(char **msg_out)
if (!b)
goto error;
b = mxmlNewOpaque(b, cwmp->deviceid.serialnumber ? cwmp->deviceid.serialnumber : "");
b = mxmlNewOpaque(b, cwmp_main->deviceid.serialnumber ? cwmp_main->deviceid.serialnumber : "");
if (!b)
goto error;