mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-14 21:10:02 +01:00
T#7935 All devices send inform at same time with unknown periodic inform time
This commit is contained in:
parent
8449a419a8
commit
45dd9c22d2
4 changed files with 38 additions and 21 deletions
25
common.c
25
common.c
|
|
@ -635,16 +635,17 @@ char *string_to_hex(const unsigned char *str, size_t size)
|
|||
{
|
||||
size_t i;
|
||||
|
||||
if (size == 0)
|
||||
return "";
|
||||
|
||||
char* hex = (char*) calloc(size * 2 + 1, sizeof(char));
|
||||
char *hex = (char*) calloc(size * 2 + 1, sizeof(char));
|
||||
|
||||
if (!hex) {
|
||||
CWMP_LOG(ERROR, "Unable to allocate memory for hex string\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return hex;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
snprintf(hex + (i * 2), 3, "%02X", str[i]);
|
||||
|
||||
|
|
@ -739,3 +740,19 @@ bool is_obj_excluded(const char *object_name)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t convert_datetime_to_timestamp(char *value)
|
||||
{
|
||||
struct tm tm = { 0 };
|
||||
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
|
||||
|
||||
sscanf(value, "%4d-%2d-%2dT%2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
|
||||
tm.tm_year = year - 1900; /* years since 1900 */
|
||||
tm.tm_mon = month - 1;
|
||||
tm.tm_mday = day;
|
||||
tm.tm_hour = hour;
|
||||
tm.tm_min = min;
|
||||
tm.tm_sec = sec;
|
||||
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
|
|
|||
23
config.c
23
config.c
|
|
@ -15,6 +15,7 @@
|
|||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "reboot.h"
|
||||
#include "ssl_utils.h"
|
||||
#include "datamodel_interface.h"
|
||||
|
||||
pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
@ -27,22 +28,6 @@ static int check_global_config(struct config *conf)
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
static time_t convert_datetime_to_timestamp(char *value)
|
||||
{
|
||||
struct tm tm = { 0 };
|
||||
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
|
||||
|
||||
sscanf(value, "%4d-%2d-%2dT%2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
|
||||
tm.tm_year = year - 1900; /* years since 1900 */
|
||||
tm.tm_mon = month - 1;
|
||||
tm.tm_mday = day;
|
||||
tm.tm_hour = hour;
|
||||
tm.tm_min = min;
|
||||
tm.tm_sec = sec;
|
||||
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
int get_global_config(struct config *conf)
|
||||
{
|
||||
int error, error2, error3;
|
||||
|
|
@ -402,6 +387,12 @@ int get_global_config(struct config *conf)
|
|||
return error;
|
||||
}
|
||||
|
||||
char *entropy = generate_random_string(sizeof(unsigned int));
|
||||
if (entropy != NULL) {
|
||||
conf->periodic_entropy = (unsigned int)strtoul(entropy, NULL, 16);
|
||||
free(entropy);
|
||||
}
|
||||
|
||||
if ((error = uci_get_value(UCI_PERIODIC_INFORM_INTERVAL_PATH, &value)) == CWMP_OK) {
|
||||
int a = 0;
|
||||
|
||||
|
|
|
|||
9
event.c
9
event.c
|
|
@ -330,17 +330,24 @@ void *thread_event_periodic(void *v)
|
|||
struct timespec periodic_timeout = { 0, 0 };
|
||||
time_t current_time;
|
||||
long int delta_time;
|
||||
time_t unknown_time;
|
||||
|
||||
periodic_interval = cwmp->conf.period;
|
||||
periodic_enable = cwmp->conf.periodic_enable;
|
||||
periodic_time = cwmp->conf.time;
|
||||
unknown_time = convert_datetime_to_timestamp("0001-01-01T00:00:00Z");
|
||||
|
||||
for (;;) {
|
||||
pthread_mutex_lock(&(cwmp->mutex_periodic));
|
||||
if (cwmp->conf.periodic_enable) {
|
||||
current_time = time(NULL);
|
||||
if (periodic_time != 0) {
|
||||
delta_time = (current_time - periodic_time) % periodic_interval;
|
||||
if (periodic_time == unknown_time) {
|
||||
delta_time = (current_time + cwmp->conf.periodic_entropy) % periodic_interval;
|
||||
} else {
|
||||
delta_time = (current_time - periodic_time) % periodic_interval;
|
||||
}
|
||||
|
||||
if (delta_time >= 0)
|
||||
periodic_timeout.tv_sec = current_time + periodic_interval - delta_time;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ typedef struct config {
|
|||
int delay_reboot;
|
||||
time_t schedule_reboot;
|
||||
time_t time;
|
||||
unsigned int periodic_entropy;
|
||||
bool periodic_enable;
|
||||
bool periodic_notify_enable;
|
||||
bool insecure_enable;
|
||||
|
|
@ -529,5 +530,6 @@ int copy_file(char *source_file, char *target_file);
|
|||
int get_connection_interface();
|
||||
char *get_time(time_t t_time);
|
||||
bool is_obj_excluded(const char *object_name);
|
||||
time_t convert_datetime_to_timestamp(char *value);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue