From 3b6737be25c28e8b33da35f2ee90a8b9f61f248a Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 7 Aug 2025 19:30:24 +0530 Subject: [PATCH] Set cpe port in var state --- bbf_plugin/datamodel.c | 2 +- src/http.c | 20 +++++++++++++++++++- src/uci_utils.c | 2 +- test/files/var/state/icwmp | 5 ++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bbf_plugin/datamodel.c b/bbf_plugin/datamodel.c index accd146..d721c10 100644 --- a/bbf_plugin/datamodel.c +++ b/bbf_plugin/datamodel.c @@ -521,7 +521,7 @@ static void get_management_ip_port(char **listen_addr) dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &interface); dmuci_get_option_value_string("cwmp", "cpe", "interface", &l3_device); - dmuci_get_option_value_string("cwmp", "cpe", "port", &port); + dmuci_get_option_value_string_varstate("icwmp", "cpe", "port", &port); dmuci_get_option_value_string_varstate("icwmp", "acs", "ip_version", &ip_version); if (DM_STRLEN(port) == 0) diff --git a/src/http.c b/src/http.c index 78de059..3504fb0 100644 --- a/src/http.c +++ b/src/http.c @@ -630,12 +630,30 @@ http_end: FREE(cr_path); } +static unsigned short get_prev_connection_request_port(void) +{ + char value[BUF_SIZE_16] = {0}; + unsigned short prev_cr_port = 0; + + prev_cr_port = (unsigned short)(cwmp_ctx.conf.connection_request_port); + + get_uci_path_value(VARSTATE_CONFIG, "icwmp.cpe.port", value, BUF_SIZE_16); + if (strlen(value) != 0) { + unsigned short temp = (unsigned short)strtoul(value, NULL, 10); + if (temp > 0) { + prev_cr_port = temp; + } + } + + return prev_cr_port; +} + void icwmp_http_server_init(void) { int y = 0; struct sockaddr_in6 server = { 0 }; unsigned short cr_port = 0; - unsigned short prev_cr_port = (unsigned short)(cwmp_ctx.conf.connection_request_port); + unsigned short prev_cr_port = get_prev_connection_request_port(); int max_retry = cwmp_ctx.conf.cpe_bind_retries; for (;;) { diff --git a/src/uci_utils.c b/src/uci_utils.c index 7750565..285cead 100644 --- a/src/uci_utils.c +++ b/src/uci_utils.c @@ -1088,6 +1088,6 @@ void set_cpe_port_conf(int cr_cpe_port) if (cr_cpe_port > 0) { char cr_port_str[BUF_SIZE_16] = {0}; snprintf(cr_port_str, sizeof(cr_port_str), "%d", cr_cpe_port); - set_uci_path_value(NULL, "cwmp.cpe.port", cr_port_str); + set_uci_path_value(VARSTATE_CONFIG, "icwmp.cpe.port", cr_port_str); } } diff --git a/test/files/var/state/icwmp b/test/files/var/state/icwmp index 4509d0d..500881d 100644 --- a/test/files/var/state/icwmp +++ b/test/files/var/state/icwmp @@ -1,2 +1,5 @@ config acs 'acs' - option dhcp_url 'http://192.168.103.160:8080/openacs/acs' \ No newline at end of file + option dhcp_url 'http://192.168.103.160:8080/openacs/acs' + +config cpe 'cpe' + option port '7548'