Improvement in inform message sending

This commit is contained in:
suvendhu 2023-06-19 20:08:43 +05:30 committed by Suvendhu Hansa
parent 3792c4642c
commit 09b7cd7a6b
5 changed files with 56 additions and 15 deletions

View file

@ -111,7 +111,10 @@ char *download_file_task_function(char *task)
int download_file_in_subprocess(const char *file_path, const char *url, const char *username, const char *password)
{
subprocess_start(download_file_task_function);
if (CWMP_OK != subprocess_start(download_file_task_function)) {
CWMP_LOG(ERROR, "Failed to spawn subprocess to start download");
return 500;
}
if (url == NULL) {
CWMP_LOG(ERROR, "download %s: url is null");

View file

@ -263,14 +263,36 @@ error:
return -1;
}
static void inform_status_check_cb(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg)
{
if (msg == NULL) {
CWMP_LOG(ERROR, "inform ubus call resp msg is null");
return;
}
int *status = (int *)req->priv;
const struct blobmsg_policy p[2] = { { "status", BLOBMSG_TYPE_INT32 }, { "info", BLOBMSG_TYPE_STRING } };
struct blob_attr *tb[2] = { NULL, NULL };
blobmsg_parse(p, 2, tb, blobmsg_data(msg), blobmsg_len(msg));
*status = tb[0] ? blobmsg_get_u32(tb[0]) : -1;
}
static void http_success_cr(void)
{
CWMP_LOG(INFO, "Connection Request triggering ...");
int status = -1, retry = 0, rc = -1;
struct blob_buf b = { 0 };
memset(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0);
icwmp_ubus_invoke("tr069", "inform", b.head, NULL, NULL);
while ((rc < 0 || status != 1) && retry < 5) {
rc = icwmp_ubus_invoke("tr069", "inform", b.head, inform_status_check_cb, &status);
retry = retry + 1;
}
blob_buf_free(&b);
if (rc < 0 || status != 1)
CWMP_LOG(ERROR, "Failed to send Inform message after 5 retry");
}
static void http_cr_new_client(int client, bool service_available)
@ -495,8 +517,7 @@ http_end:
fclose(fp);
}
close(client);
}
else {
} else {
CWMP_LOG(INFO, "Receive Connection Request: Return 401 Unauthorized");
if (fp) {
fputs("HTTP/1.1 401 Unauthorized\r\n", fp);

View file

@ -316,21 +316,34 @@ void rpc_exit()
FREE(cwmp_main->session->rpc_cpe);
}
static void schedule_session_retry(void)
{
cwmp_main->retry_count_session++;
int t = cwmp_get_retry_interval(0);
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
cwmp_uci_reinit();
cwmp_config_load();
trigger_periodic_notify_check();
cwmp_uci_exit();
if (!cwmp_main->session->session_status.is_heartbeat) {
set_cwmp_session_status(SESSION_FAILURE, t);
uloop_timeout_set(&retry_session_timer, 1000 * t);
} else {
uloop_timeout_cancel(&heartbeat_session_timer);
uloop_timeout_set(&heartbeat_session_timer, 1000 * t);
}
}
void start_cwmp_session()
{
int t, error;
int error;
char *exec_download = NULL;
uloop_timeout_cancel(&check_notify_timer);
if (cwmp_session_init() != CWMP_OK) {
CWMP_LOG(ERROR, "Not able to init a CWMP session");
t = cwmp_get_retry_interval(0);
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
cwmp_uci_reinit();
set_cwmp_session_status(SESSION_FAILURE, t);
cwmp_config_load();
trigger_periodic_notify_check();
cwmp_uci_exit();
schedule_session_retry();
return;
}
@ -343,6 +356,8 @@ void start_cwmp_session()
if (is_ipv6_status_changed()) {
if (icwmp_check_http_connection() != CWMP_OK || cwmp_stop) {
CWMP_LOG(INFO, "Failed to check http connection");
if (!cwmp_stop)
schedule_session_retry();
return;
}
}
@ -397,9 +412,11 @@ void start_cwmp_session()
}
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_uci_reinit();
cwmp_config_load();
cwmp_uci_exit();
cwmp_main->retry_count_session++;
t = cwmp_get_retry_interval(0);
int t = cwmp_get_retry_interval(0);
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
if (!cwmp_main->session->session_status.is_heartbeat) {
set_cwmp_session_status(SESSION_FAILURE, t);

View file

@ -94,7 +94,7 @@ int subprocess_start(task_function task_fun)
struct blob_buf bbuf;
memset(&bbuf, 0, sizeof(struct blob_buf));
blob_buf_init(&bbuf, 0);
blobmsg_add_string(&bbuf, "ret", to_child);
blobmsg_add_string(&bbuf, "ret", to_child ? to_child : "500");
char *to_child_json = blobmsg_format_json(bbuf.head, true);
write(pipefd2[1], to_child_json, strlen(to_child_json)+1);
FREE(to_child);

View file

@ -269,7 +269,7 @@ static int icwmp_inform_event(struct blob_buf *bb, char *event)
int event_code = cwmp_get_int_event_code(event);
if (event_code != -1) {
if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) {
blobmsg_add_u32(bb, "status", -1);
blobmsg_add_u32(bb, "status", 1);
blobmsg_add_string(bb, "info", "Session already running, event will be sent at the end of the session");
} else {
blobmsg_add_u32(bb, "status", 1);