Skip to content

Commit 758f534

Browse files
author
Mika Leppänen
committed
Added maximum frame counter storing interval
If application has not configured real time clock to nanostack, it will now advance internal time by a day on each start up. Also frame counter (and time) storing is forced to happen once a day.
1 parent b0ea148 commit 758f534

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

source/6LoWPAN/ws/ws_config.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ extern uint8_t DEVICE_MIN_SENS;
157157
/*
158158
* MAC frame counter NVM storing configuration
159159
*/
160-
#define FRAME_COUNTER_STORE_INTERVAL 60 // Time interval (on seconds) between frame counter store operations
161-
#define FRAME_COUNTER_STORE_TRIGGER 5 // Delay (on seconds) before storing, when storing of frame counters is triggered
162-
#define FRAME_COUNTER_INCREMENT 1000 // How much frame counter is incremented on start up
163-
#define FRAME_COUNTER_STORE_THRESHOLD 800 // How much frame counter must increment before it is stored
160+
#define FRAME_COUNTER_STORE_INTERVAL 60 // Time interval (on seconds) between checking if frame counter storing is needed
161+
#define FRAME_COUNTER_STORE_FORCE_INTERVAL (3600 * 20) // Time interval (on seconds) before frame counter storing is forced (if no other storing operations triggered)
162+
#define FRAME_COUNTER_STORE_TRIGGER 5 // Delay (on seconds) before storing, when storing of frame counters is triggered
163+
#define FRAME_COUNTER_INCREMENT 1000 // How much frame counter is incremented on start up
164+
#define FRAME_COUNTER_STORE_THRESHOLD 800 // How much frame counter must increment before it is stored
164165

165166

166167
/*

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ typedef struct {
7272
uint8_t gtkhash[32]; /**< GTK hashes */
7373
sec_prot_certs_t certs; /**< Certificates */
7474
nw_key_t nw_key[GTK_NUM]; /**< Currently active network keys (on MAC) */
75-
uint16_t frame_cnt_store_timer; /**< Timer for storing frame counter value */
75+
uint16_t frame_cnt_store_timer; /**< Timer to check if storing of frame counter value is needed */
76+
uint32_t frame_cnt_store_force_timer; /**< Timer to force storing of frame counter, if no other updates */
7677
frame_counters_t frame_counters; /**< Frame counters */
7778
sec_timer_cfg_t sec_timer_cfg; /**< Timer configuration (configuration set values) */
7879
sec_prot_cfg_t sec_prot_cfg; /**< Configuration */
@@ -669,6 +670,7 @@ static void ws_pae_controller_data_init(pae_controller_t *controller)
669670
controller->frame_counter_read = false;
670671
controller->gtk_index = -1;
671672
controller->frame_cnt_store_timer = FRAME_COUNTER_STORE_INTERVAL;
673+
controller->frame_cnt_store_force_timer = FRAME_COUNTER_STORE_FORCE_INTERVAL;
672674
controller->restart_cnt = 0;
673675
ws_pae_controller_frame_counter_reset(&controller->frame_counters);
674676
sec_prot_keys_gtks_init(&controller->gtks);
@@ -1377,6 +1379,13 @@ static void ws_pae_controller_frame_counter_timer(uint16_t seconds, pae_controll
13771379
entry->frame_cnt_store_timer = FRAME_COUNTER_STORE_INTERVAL;
13781380
ws_pae_controller_frame_counter_store(entry, true);
13791381
}
1382+
1383+
if (entry->frame_cnt_store_force_timer > seconds) {
1384+
entry->frame_cnt_store_force_timer -= seconds;
1385+
} else {
1386+
entry->frame_cnt_store_force_timer = 0;
1387+
ws_pae_controller_frame_counter_store(entry, true);
1388+
}
13801389
}
13811390

13821391
static void ws_pae_controller_frame_counter_timer_trigger(uint16_t seconds, pae_controller_t *entry)
@@ -1430,11 +1439,14 @@ static void ws_pae_controller_frame_counter_store(pae_controller_t *entry, bool
14301439
}
14311440
}
14321441

1433-
if (update_needed) {
1442+
if (update_needed || entry->frame_cnt_store_force_timer == 0) {
14341443
tr_debug("Write frame counters: system time %"PRIu32"", protocol_core_monotonic_time / 10);
14351444
// Writes modified frame counters
14361445
ws_pae_nvm_store_frame_counter_tlv_create((nvm_tlv_t *) &entry->pae_nvm_buffer, entry->restart_cnt, &entry->frame_counters);
14371446
ws_pae_controller_nvm_frame_counter_write((nvm_tlv_t *) &entry->pae_nvm_buffer);
1447+
1448+
// Reset force interval when ever values are stored
1449+
entry->frame_cnt_store_force_timer = FRAME_COUNTER_STORE_FORCE_INTERVAL;
14381450
}
14391451
}
14401452

source/6LoWPAN/ws/ws_pae_time.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
#define TRACE_GROUP "wst"
3232

3333
// Wednesday, January 1, 2020 0:00:00 GMT
34-
#define CURRENT_TIME_INIT_VALUE 1577836800
34+
#define CURRENT_TIME_INIT_VALUE 1577836800
35+
36+
// Increment two hours in addition to maximum storing interval
37+
#define CURRENT_TIME_INCREMENT_VALUE (2 * 3600)
3538

3639
static uint64_t current_time = CURRENT_TIME_INIT_VALUE;
3740
static ns_time_api_system_time_callback *system_time_callback = NULL;
@@ -171,6 +174,8 @@ int8_t ws_pae_current_time_set(uint64_t time)
171174
tr_error("FATAL: system time less than reference time or more than 12 months in future: %"PRIi64" reference time: %"PRIi64, system_time, current_time);
172175
return -1;
173176
}
177+
} else {
178+
current_time += FRAME_COUNTER_STORE_FORCE_INTERVAL + CURRENT_TIME_INCREMENT_VALUE;
174179
}
175180

176181
return 0;

0 commit comments

Comments
 (0)