From 492e8a720cd40397e4fcedfa7b46f215ac80764a Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 24 Oct 2024 16:36:50 +0530 Subject: [PATCH] Fix TransferComplete RPC missed after reboot --- src/event.c | 2 - src/session.c | 46 +++++++++++++------ src/session.h | 2 +- test/cmocka/icwmp_cli_unit_test.c | 3 +- .../icwmp_datamodel_interface_unit_test.c | 3 +- test/cmocka/icwmp_notifications_unit_test.c | 3 +- test/cmocka/icwmp_soap_msg_unit_test.c | 3 +- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/event.c b/src/event.c index 8577139..56eff4f 100644 --- a/src/event.c +++ b/src/event.c @@ -151,8 +151,6 @@ int cwmp_root_cause_transfer_complete(struct transfer_complete *p) return CWMP_MEM_ERR; } - CWMP_LOG(INFO, "%s: Added TransferComplete rpc for %d", __func__, p->type); - switch (p->type) { case TYPE_DOWNLOAD: event_container = cwmp_add_event_container(EVENT_IDX_M_Download, p->command_key ? p->command_key : ""); diff --git a/src/session.c b/src/session.c index e22375c..8da2420 100644 --- a/src/session.c +++ b/src/session.c @@ -98,13 +98,6 @@ int cwmp_session_rpc_destructor(struct rpc *rpc) return CWMP_OK; } -int cwmp_session_exit() -{ - rpc_exit(); - icwmp_cleanmem(); - return CWMP_OK; -} - static int cwmp_rpc_cpe_handle_message(struct rpc *rpc_cpe) { if (xml_prepare_msg_out()) @@ -305,8 +298,6 @@ void rpc_exit() if (!rpc) break; - CWMP_LOG(INFO, "%s: Removed rpc %d", __func__, rpc->type); - if (rpc_acs_methods[rpc->type].extra_clean != NULL) rpc_acs_methods[rpc->type].extra_clean(rpc); cwmp_session_rpc_destructor(rpc); @@ -315,6 +306,27 @@ void rpc_exit() FREE(cwmp_main->session->rpc_cpe); } +void remove_inform_getrpc() +{ + if (cwmp_main == NULL || cwmp_main->session == NULL) + return; + + if (!list_empty(&(cwmp_main->session->head_rpc_acs))) { + while (cwmp_main->session->head_rpc_acs.next != &(cwmp_main->session->head_rpc_acs)) { + struct rpc *rpc = list_entry(cwmp_main->session->head_rpc_acs.next, struct rpc, list); + if (!rpc) + break; + + if (rpc->type == RPC_ACS_GET_RPC_METHODS || rpc->type == RPC_ACS_INFORM) { + if (rpc_acs_methods[rpc->type].extra_clean != NULL) + rpc_acs_methods[rpc->type].extra_clean(rpc); + cwmp_session_rpc_destructor(rpc); + } + } + } + FREE(cwmp_main->session->rpc_cpe); +} + static void schedule_session_retry(void) { cwmp_main->retry_count_session++; @@ -350,8 +362,12 @@ void start_cwmp_session(void) 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) + if (!cwmp_stop) { + /* clear inform and getrpc method from rpc list. + * These will be added in next session init */ + remove_inform_getrpc(); schedule_session_retry(); + } return; } } @@ -397,13 +413,15 @@ void start_cwmp_session(void) if (cwmp_stop) { cwmp_remove_all_session_events(); run_session_end_func(); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); return; } 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_LOG(ERROR, "%s: Session will be retried soon", __func__); + // clear inform and getrpc method from rpc list. These will be added in next session init + remove_inform_getrpc(); schedule_session_retry(); } else { save_acs_bkp_config(); @@ -413,6 +431,8 @@ void start_cwmp_session(void) remove_single_event(EVENT_IDX_14HEARTBEAT); } + // clear all rpc from lists if exist any + rpc_exit(); cwmp_main->retry_count_session = 0; set_cwmp_session_status(SESSION_SUCCESS, 0); if (cwmp_main->throttle_session_triggered == true) { @@ -425,7 +445,7 @@ void start_cwmp_session(void) } } run_session_end_func(); - cwmp_session_exit(); + icwmp_cleanmem(); if (cwmp_main->acs_changed) { CWMP_LOG(INFO, "%s: Schedule session with new ACS since URL changed", __func__); diff --git a/src/session.h b/src/session.h index bb4ed14..f703e19 100644 --- a/src/session.h +++ b/src/session.h @@ -110,9 +110,9 @@ 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(); int cwmp_schedule_rpc(); int cwmp_apply_acs_changes(void); void rpc_exit(); +void remove_inform_getrpc(); void trigger_cwmp_restart_timer(void); #endif /* SRC_INC_SESSION_H_ */ diff --git a/test/cmocka/icwmp_cli_unit_test.c b/test/cmocka/icwmp_cli_unit_test.c index 38515ea..350351b 100644 --- a/test/cmocka/icwmp_cli_unit_test.c +++ b/test/cmocka/icwmp_cli_unit_test.c @@ -59,7 +59,8 @@ static int cwmp_cli_unit_tests_init(void **state) static int cwmp_cli_unit_tests_clean(void **state) { icwmp_free_list_services(); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); FREE(cwmp_main->session); FREE(cwmp_main); FREE(add_instance); diff --git a/test/cmocka/icwmp_datamodel_interface_unit_test.c b/test/cmocka/icwmp_datamodel_interface_unit_test.c index 803abb7..0480e1b 100644 --- a/test/cmocka/icwmp_datamodel_interface_unit_test.c +++ b/test/cmocka/icwmp_datamodel_interface_unit_test.c @@ -42,7 +42,8 @@ static int dm_iface_unit_tests_clean(void **state) icwmp_free_list_services(); cwmp_free_all_list_param_fault(&faults_array); cwmp_free_all_dm_parameter_list(&list_set_param_value); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); clean_cwmp_session_structure(); FREE(cwmp_main); return 0; diff --git a/test/cmocka/icwmp_notifications_unit_test.c b/test/cmocka/icwmp_notifications_unit_test.c index 49ffacb..973b3cd 100644 --- a/test/cmocka/icwmp_notifications_unit_test.c +++ b/test/cmocka/icwmp_notifications_unit_test.c @@ -40,7 +40,8 @@ static int cwmp_notifications_unit_tests_clean(void **state) clean_list_param_notify(); clean_list_value_change(); cwmp_free_all_dm_parameter_list(¶meters_list); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); FREE(cwmp_main->session); FREE(cwmp_main); return 0; diff --git a/test/cmocka/icwmp_soap_msg_unit_test.c b/test/cmocka/icwmp_soap_msg_unit_test.c index dd018cb..56360ef 100644 --- a/test/cmocka/icwmp_soap_msg_unit_test.c +++ b/test/cmocka/icwmp_soap_msg_unit_test.c @@ -87,7 +87,8 @@ static int soap_unit_tests_clean(void **state) { icwmp_free_list_services(); clean_name_space(); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); clean_force_inform_list(); FREE(cwmp_main->session); FREE(cwmp_main);