B#11466: Failed to send inform on CR

This commit is contained in:
Amin Ben Romdhane 2023-07-11 11:46:13 +02:00
parent bd76686d11
commit ac260ccad3
8 changed files with 63 additions and 58 deletions

View file

@ -821,6 +821,11 @@ bool is_ipv6_status_changed(void)
bool ipv6_status_changed = (curr_ipv6_status != cwmp_main->net.ipv6_status); bool ipv6_status_changed = (curr_ipv6_status != cwmp_main->net.ipv6_status);
cwmp_main->net.ipv6_status = curr_ipv6_status; cwmp_main->net.ipv6_status = curr_ipv6_status;
if (ipv6_status_changed) {
CWMP_LOG(INFO, "IPv6 status (%d) changed for interface: (%s) && device: (%s)",
cwmp_main->net.ipv6_status, cwmp_main->conf.default_wan_iface, cwmp_main->net.interface);
}
return ipv6_status_changed; return ipv6_status_changed;
} }

View file

@ -570,6 +570,7 @@ int global_conf_init()
} }
cwmp_main->init_complete = true; cwmp_main->init_complete = true;
/* Launch reboot methods if needed */ /* Launch reboot methods if needed */
launch_reboot_methods(); launch_reboot_methods();

View file

@ -14,21 +14,24 @@
#include "backupSession.h" #include "backupSession.h"
#include "log.h" #include "log.h"
static struct event_container *__cwmp_add_event_container(int event_code, char *command_key) struct event_container *cwmp_add_event_container(int event_code, char *command_key)
{ {
struct event_container *event_container = NULL; struct event_container *event_container = NULL;
list_for_each_entry(event_container, &cwmp_main->session->events, list) { list_for_each_entry(event_container, &cwmp_main->session->events, list) {
if (event_container->code == event_code) {
if (event_container->code == event_code)
return event_container; return event_container;
}
if (event_container->code > event_code) { if (event_container->code > event_code)
break; break;
} }
}
event_container = calloc(1, sizeof(struct event_container)); event_container = calloc(1, sizeof(struct event_container));
if (event_container == NULL) { if (event_container == NULL) {
return NULL; return NULL;
} }
INIT_LIST_HEAD(&(event_container->head_dm_parameter)); INIT_LIST_HEAD(&(event_container->head_dm_parameter));
list_add_tail(&(event_container->list), &(cwmp_main->session->events)); list_add_tail(&(event_container->list), &(cwmp_main->session->events));
event_container->code = event_code; event_container->code = event_code;
@ -39,13 +42,8 @@ static struct event_container *__cwmp_add_event_container(int event_code, char *
} }
cwmp_main->event_id++; cwmp_main->event_id++;
event_container->id = cwmp_main->event_id; event_container->id = cwmp_main->event_id;
return event_container;
}
struct event_container *cwmp_add_event_container(int event_code, char *command_key) return event_container;
{
struct event_container *event = __cwmp_add_event_container(event_code, command_key);
return event;
} }
void move_next_session_events_to_actual_session() void move_next_session_events_to_actual_session()

View file

@ -1,8 +1,21 @@
/*
* 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-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef CWMP_EVENT_H #ifndef CWMP_EVENT_H
#define CWMP_EVENT_H #define CWMP_EVENT_H
#include "event.h" #include "event.h"
struct event_container *cwmp_add_event_container(int event_code, char *command_key); struct event_container *cwmp_add_event_container(int event_code, char *command_key);
void move_next_session_events_to_actual_session(); void move_next_session_events_to_actual_session();
int cwmp_remove_all_session_events(); int cwmp_remove_all_session_events();
int remove_single_event(int event_code); int remove_single_event(int event_code);
#endif
#endif //CWMP_EVENT_H

View file

@ -19,19 +19,6 @@ struct uloop_fd http_event6;
pthread_t http_cr_server_thread; pthread_t http_cr_server_thread;
void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsigned events __attribute__((unused)))
{
icwmp_http_server_listen();
}
void http_server_start_uloop(void)
{
icwmp_http_server_init();
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);
}
static void *thread_http_cr_server_listen(void *v __attribute__((unused))) static void *thread_http_cr_server_listen(void *v __attribute__((unused)))
{ {
icwmp_http_server_listen(); icwmp_http_server_listen();

View file

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "digauth.h" #include "digauth.h"
#include "session.h" #include "session.h"
#include "cwmp_event.h"
#define REALM "authenticate@cwmp" #define REALM "authenticate@cwmp"
#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" #define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
@ -260,36 +261,23 @@ error:
return -1; 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) static void http_success_cr(void)
{ {
CWMP_LOG(INFO, "Connection Request triggering ..."); CWMP_LOG(INFO, "Connection Request triggering ...");
int status = -1, retry = 0, rc = -1;
struct blob_buf b = { 0 }; if (cwmp_main->init_complete == false) {
memset(&b, 0, sizeof(struct blob_buf)); CWMP_LOG(ERROR, "Inform can't be sent since icwmpd is still in init state");
blob_buf_init(&b, 0); return;
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); struct event_container *event_container = NULL;
if (rc < 0 || status != 1)
CWMP_LOG(ERROR, "Failed to send Inform message after 5 retry"); event_container = cwmp_add_event_container(EVENT_IDX_6CONNECTION_REQUEST, "");
if (event_container == NULL) {
CWMP_LOG(ERROR, "Not able to add the event '6 CONNECTION REQUEST' for the new session");
}
start_cwmp_session();
} }
static void http_cr_new_client(int client, bool service_available) static void http_cr_new_client(int client, bool service_available)

View file

@ -63,6 +63,7 @@ int cwmp_session_init()
cwmp_main->cwmp_cr_event = 0; cwmp_main->cwmp_cr_event = 0;
cwmp_uci_init(); cwmp_uci_init();
/* /*
* Set Required methods as initial value of * Set Required methods as initial value of
*/ */
@ -79,8 +80,10 @@ int cwmp_session_init()
cwmp_main->session->rpc_cpe = NULL; cwmp_main->session->rpc_cpe = NULL;
set_cwmp_session_status(SESSION_RUNNING, 0); set_cwmp_session_status(SESSION_RUNNING, 0);
if (file_exists(fc_cookies)) if (file_exists(fc_cookies))
remove(fc_cookies); remove(fc_cookies);
return CWMP_OK; return CWMP_OK;
} }
@ -283,6 +286,7 @@ void set_cwmp_session_status(int status, int retry_time)
{ {
cwmp_main->session->session_status.last_status = status; cwmp_main->session->session_status.last_status = status;
set_cwmp_session_status_state(status); set_cwmp_session_status_state(status);
if (status == SESSION_SUCCESS) { if (status == SESSION_SUCCESS) {
cwmp_main->session->session_status.last_end_time = time(NULL); cwmp_main->session->session_status.last_end_time = time(NULL);
cwmp_main->session->session_status.next_retry = 0; cwmp_main->session->session_status.next_retry = 0;
@ -346,6 +350,7 @@ void start_cwmp_session(void)
} }
if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) { if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) {
CWMP_LOG(ERROR, "Last session was failed, load again cwmp config");
cwmp_config_load(); cwmp_config_load();
} }
@ -363,17 +368,21 @@ void start_cwmp_session(void)
*/ */
if (!cwmp_main->session->session_status.is_heartbeat) { if (!cwmp_main->session->session_status.is_heartbeat) {
int is_notify = 0; int is_notify = 0;
if (file_exists(DM_ENABLED_NOTIFY)) { if (file_exists(DM_ENABLED_NOTIFY)) {
if (!event_exist_in_list(EVENT_IDX_4VALUE_CHANGE)) if (!event_exist_in_list(EVENT_IDX_4VALUE_CHANGE))
is_notify = check_value_change(); is_notify = check_value_change();
} }
if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp_main->custom_notify_active) { if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp_main->custom_notify_active) {
cwmp_main->custom_notify_active = false; cwmp_main->custom_notify_active = false;
cwmp_update_enabled_notify_file(); cwmp_update_enabled_notify_file();
} }
cwmp_prepare_value_change(cwmp_main); cwmp_prepare_value_change(cwmp_main);
clean_list_value_change(); clean_list_value_change();
} }
/* /*
* Start session * Start session
*/ */
@ -396,6 +405,7 @@ void start_cwmp_session(void)
/* /*
* End session * End session
*/ */
CWMP_LOG(INFO, "End session"); CWMP_LOG(INFO, "End session");
if (cwmp_stop) { if (cwmp_stop) {
@ -437,9 +447,11 @@ void start_cwmp_session(void)
cwmp_main->throttle_session = false; cwmp_main->throttle_session = false;
} }
} }
run_session_end_func(); run_session_end_func();
cwmp_session_exit(); cwmp_session_exit();
CWMP_LOG(INFO, "Waiting the next session"); CWMP_LOG(INFO, "Waiting the next session");
if (cwmp_main->session->session_status.next_heartbeat && (cwmp_main->session->session_status.last_status == SESSION_SUCCESS)) { if (cwmp_main->session->session_status.next_heartbeat && (cwmp_main->session->session_status.last_status == SESSION_SUCCESS)) {
cwmp_main->session->session_status.next_heartbeat = false; cwmp_main->session->session_status.next_heartbeat = false;
uloop_timeout_cancel(&heartbeat_session_timer); uloop_timeout_cancel(&heartbeat_session_timer);
@ -490,8 +502,10 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout)
CWMP_LOG(ERROR, "session %s: session_event is null", __FUNCTION__); CWMP_LOG(ERROR, "session %s: session_event is null", __FUNCTION__);
return; return;
} }
FREE(global_session_event); FREE(global_session_event);
global_session_event = session_event; global_session_event = session_event;
if (session_event->event == TransferClt_Evt) { if (session_event->event == TransferClt_Evt) {
struct transfer_complete *ptransfer_complete = (struct transfer_complete *)session_event->extra_data; struct transfer_complete *ptransfer_complete = (struct transfer_complete *)session_event->extra_data;
cwmp_root_cause_transfer_complete(ptransfer_complete); cwmp_root_cause_transfer_complete(ptransfer_complete);

View file

@ -280,7 +280,12 @@ static int icwmp_inform_event(struct blob_buf *bb, char *event)
static int icwmp_inform_handler(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg) static int icwmp_inform_handler(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg)
{ {
struct blob_attr *tb[__INFORM_MAX] = {0};
struct blob_buf bb; struct blob_buf bb;
int event_code = -1, ret = -1;
bool is_get_rpc = false;
char *event = "";
memset(&bb, 0, sizeof(struct blob_buf)); memset(&bb, 0, sizeof(struct blob_buf));
blob_buf_init(&bb, 0); blob_buf_init(&bb, 0);
@ -291,13 +296,6 @@ static int icwmp_inform_handler(struct ubus_context *ctx, struct ubus_object *ob
goto end; goto end;
} }
struct blob_attr *tb[__INFORM_MAX] = {0};
bool is_get_rpc = false;
char *event = "";
int ret = -1;
int event_code = -1;
ret = blobmsg_parse(icwmp_inform_policy, ARRAY_SIZE(icwmp_inform_policy), tb, blob_data(msg), blob_len(msg)); ret = blobmsg_parse(icwmp_inform_policy, ARRAY_SIZE(icwmp_inform_policy), tb, blob_data(msg), blob_len(msg));
if (ret == 0 && tb[INFORM_GET_RPC_METHODS] != NULL) { if (ret == 0 && tb[INFORM_GET_RPC_METHODS] != NULL) {
@ -313,6 +311,7 @@ static int icwmp_inform_handler(struct ubus_context *ctx, struct ubus_object *ob
} else { } else {
event_code = icwmp_inform_event(&bb, event); event_code = icwmp_inform_event(&bb, event);
} }
if (event_code == -1) { if (event_code == -1) {
CWMP_LOG(WARNING, "tr069 ubus: ubus inform method not able to get the event code"); CWMP_LOG(WARNING, "tr069 ubus: ubus inform method not able to get the event code");
blobmsg_add_u32(&bb, "status", -1); blobmsg_add_u32(&bb, "status", -1);
@ -387,7 +386,7 @@ int icwmp_uloop_ubus_init()
void icwmp_uloop_ubus_exit() void icwmp_uloop_ubus_exit()
{ {
if (ubus_ctx) { if (ubus_ctx) {
ubus_remove_object(ubus_ctx, &tr069_object); icwmp_delete_object(ubus_ctx);
ubus_free(ubus_ctx); ubus_free(ubus_ctx);
ubus_ctx = NULL; ubus_ctx = NULL;
} }