diff --git a/bbf_plugin/datamodel.c b/bbf_plugin/datamodel.c index 6a93148..fb0d5e6 100644 --- a/bbf_plugin/datamodel.c +++ b/bbf_plugin/datamodel.c @@ -357,6 +357,7 @@ static int set_management_server_url(char *refparam, struct dmctx *ctx, void *da break; case VALUESET: dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable"); + dmuci_set_value("cwmp", "acs", "dhcp_url", ""); dmuci_set_value("cwmp", "acs", "url", value); break; } diff --git a/src/config.c b/src/config.c index dafae1f..7f1aa7b 100755 --- a/src/config.c +++ b/src/config.c @@ -26,6 +26,22 @@ #include "heartbeat.h" #include "cwmp_http.h" +static bool dhcp_discovered_acs() +{ + char dhcp_url[BUF_SIZE_2048] = {0}; + get_uci_path_value(NULL, "cwmp.acs.dhcp_url", dhcp_url, BUF_SIZE_2048); + + if (CWMP_STRLEN(cwmp_ctx.conf.acs_url) == 0) + return false; + + if (CWMP_STRCMP(dhcp_url, cwmp_ctx.conf.acs_url) == 0) { + // CWMP trying to reach with DHCP discovered ACS url + return true; + } + + return false; +} + int get_preinit_config() { char value[BUF_SIZE_256] = {0}; @@ -85,19 +101,69 @@ static void global_conf_init() void cwmp_config_load() { int error; + struct timeval start_time, current_time; global_conf_init(); cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); error = icwmp_check_http_connection(); + if (error != CWMP_OK && dhcp_discovered_acs() == true) { + gettimeofday(&start_time, NULL); + } while (error != CWMP_OK) { + if (dhcp_discovered_acs() == true) { + gettimeofday(¤t_time, NULL); + + long long start_microseconds = (long long)start_time.tv_sec * 1000000 + start_time.tv_usec; + long long current_microseconds = (long long)current_time.tv_sec * 1000000 + current_time.tv_usec; + long long elapsed_microseconds = current_microseconds - start_microseconds; + long long elapsed_seconds = elapsed_microseconds / 1000000; + + if (elapsed_seconds >= 300) { + // CWMP not able to connect DHCP discovered ACS url for 300 seconds + // let's renew the lease in search of new ACS URL from DHCP server + if (cwmp_ctx.conf.dhcp_discovery == false) { + set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "1"); + } + + // Renew DHCP lease + if (CWMP_STRLEN(cwmp_ctx.conf.default_wan_iface) != 0) { + struct blob_buf b = {0}; + + CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "interface", cwmp_ctx.conf.default_wan_iface); + + icwmp_ubus_invoke("network.interface", "renew", b.head, NULL, NULL); + blob_buf_free(&b); + } + + // Reset start time + gettimeofday(&start_time, NULL); + } + } + CWMP_LOG(DEBUG, "Init: failed to check http connection"); sleep(UCI_OPTION_READ_INTERVAL); global_conf_init(); cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); error = icwmp_check_http_connection(); } + + if (dhcp_discovered_acs() == true) { + // CWMP connected to DHCP discovered ACS URL + if (cwmp_ctx.conf.dhcp_discovery == true) { + set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "0"); + } + + char cur_url[BUF_SIZE_2048] = {0}; + get_uci_path_value(NULL, "cwmp.acs.url", cur_url, BUF_SIZE_2048); + + if (CWMP_STRCMP(cwmp_ctx.conf.acs_url, cur_url) != 0) { + set_uci_path_value(NULL, "cwmp.acs.url", cwmp_ctx.conf.acs_url); + } + } } static void cwmp_get_device_info(const char *param, char *value, size_t size) { diff --git a/src/session.c b/src/session.c index 831551f..6c4a807 100644 --- a/src/session.c +++ b/src/session.c @@ -158,18 +158,6 @@ int cwmp_schedule_rpc() if (rpc_acs_methods[rpc_acs->type].parse_response) { if (rpc_acs_methods[rpc_acs->type].parse_response(rpc_acs)) goto retry; - - if (rpc_acs->type == RPC_ACS_INFORM) { - /* Inform response received from ACS and parsed successfully - * now disable DHCP discovery and set url */ - if (cwmp_ctx.conf.dhcp_discovery == true) - set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "0"); - - char cur_url[BUF_SIZE_2048] = {0}; - get_uci_path_value(NULL, "cwmp.acs.url", cur_url, BUF_SIZE_2048); - if (CWMP_STRCMP(cwmp_ctx.conf.acs_url, cur_url) != 0) - set_uci_path_value(NULL, "cwmp.acs.url", cwmp_ctx.conf.acs_url); - } } ilist = ilist->prev;