From a1e77afd6f921eb88ac33a889dfa2d4041d8e59c Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 24 Oct 2024 17:31:22 +0530 Subject: [PATCH] Fix TransferComplete RPC missed after reboot --- src/session.c | 45 ++++++++++++++----- 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 +- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/session.c b/src/session.c index 622bddd..a01e1a0 100644 --- a/src/session.c +++ b/src/session.c @@ -103,13 +103,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()) @@ -312,6 +305,29 @@ void rpc_exit() FREE(cwmp_ctx.session->rpc_cpe); } +void remove_inform_getrpc() +{ + if (cwmp_ctx.session == NULL) + return; + + if (!list_empty(&(cwmp_ctx.session->head_rpc_acs))) { + struct list_head *ilist, *q; + + list_for_each_safe (ilist, q, &(cwmp_ctx.session->head_rpc_acs)) { + struct rpc *rpc = list_entry(ilist, 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_ctx.session->rpc_cpe); +} + static void schedule_session_retry(void) { cwmp_ctx.retry_count_session++; @@ -347,8 +363,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; } } @@ -394,12 +414,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_ctx.session->error == CWMP_RETRY_SESSION && (!list_empty(&(cwmp_ctx.session->events)) || (list_empty(&(cwmp_ctx.session->events)) && cwmp_ctx.cwmp_cr_event == 0))) { //CWMP Retry session + // 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(); @@ -409,6 +432,8 @@ void start_cwmp_session(void) remove_single_event(EVENT_IDX_14HEARTBEAT); } + // clear all rpc from lists if exist any + rpc_exit(); cwmp_ctx.retry_count_session = 0; set_cwmp_session_status(SESSION_SUCCESS, 0); @@ -431,7 +456,7 @@ void start_cwmp_session(void) } } run_session_end_func(); - cwmp_session_exit(); + icwmp_cleanmem(); if (cwmp_ctx.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 463a44f..b78032e 100644 --- a/src/session.h +++ b/src/session.h @@ -103,8 +103,8 @@ void start_cwmp_session(); int create_cwmp_session_structure(); int clean_cwmp_session_structure(); int cwmp_session_init(); -int cwmp_session_exit(); 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 7b43022..7897dbd 100644 --- a/test/cmocka/icwmp_cli_unit_test.c +++ b/test/cmocka/icwmp_cli_unit_test.c @@ -56,7 +56,8 @@ static int cwmp_cli_unit_tests_init(void **state) static int cwmp_cli_unit_tests_clean(void **state) { - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); FREE(cwmp_ctx.session); FREE(add_instance); return 0; diff --git a/test/cmocka/icwmp_datamodel_interface_unit_test.c b/test/cmocka/icwmp_datamodel_interface_unit_test.c index 01762ec..d92f32b 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) cwmp_free_all_list_param_fault(&faults_array); cwmp_free_all_dm_parameter_list(&list_set_param_value); cwmp_free_all_xml_data_list(&xml_param_list); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); clean_cwmp_session_structure(); return 0; } diff --git a/test/cmocka/icwmp_notifications_unit_test.c b/test/cmocka/icwmp_notifications_unit_test.c index 9f7e9e2..c083a8a 100644 --- a/test/cmocka/icwmp_notifications_unit_test.c +++ b/test/cmocka/icwmp_notifications_unit_test.c @@ -38,7 +38,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_ctx.session); return 0; } diff --git a/test/cmocka/icwmp_soap_msg_unit_test.c b/test/cmocka/icwmp_soap_msg_unit_test.c index 08e7809..917ec8b 100644 --- a/test/cmocka/icwmp_soap_msg_unit_test.c +++ b/test/cmocka/icwmp_soap_msg_unit_test.c @@ -84,7 +84,8 @@ static int soap_unit_tests_init(void **state) static int soap_unit_tests_clean(void **state) { clean_name_space(); - cwmp_session_exit(); + rpc_exit(); + icwmp_cleanmem(); clean_force_inform_list(); FREE(cwmp_ctx.session); return 0;