Skip to content

Commit 7406149

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1684 from ARMmbed/IOTTHD-2476
FHSS: validate received synch info
2 parents c48f0ef + cc5f6d8 commit 7406149

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int fhss_sync_with_beacon(fhss_structure_t *fhss_structure,
347347

348348
if (fhss_structure) {
349349
// Do not allow synchronising devices above 253 hops.
350-
if (payload->hop_count > 253) {
350+
if (payload->hop_count > (FHSS_MAX_ALLOWED_HOPS-1)) {
351351
return 0;
352352
}
353353
// To make synchronization monitoring more effective, drop extra Beacons.
@@ -868,6 +868,35 @@ static void fhss_beacon_decode(fhss_synchronization_beacon_payload_s* dest, cons
868868
}
869869
}
870870

871+
static int fhss_synch_info_validate(fhss_synchronization_beacon_payload_s *payload)
872+
{
873+
if (!payload) {
874+
return -1;
875+
}
876+
if (payload->data_start_delimeter != 0) {
877+
return -1;
878+
}
879+
if (payload->current_superframe >= payload->number_of_superframes_per_channel) {
880+
return -1;
881+
}
882+
if (payload->remaining_slots >= payload->superframe_length) {
883+
return -1;
884+
}
885+
if (payload->hop_count > FHSS_MAX_ALLOWED_HOPS-1) {
886+
return -1;
887+
}
888+
if (payload->number_of_broadcast_channels == 0) {
889+
return -1;
890+
}
891+
if (payload->number_of_tx_slots == 0) {
892+
return -1;
893+
}
894+
if (payload->number_of_superframes_per_channel == 0) {
895+
return -1;
896+
}
897+
return 0;
898+
}
899+
871900
static void fhss_beacon_received(fhss_structure_t *fhss_structure, const uint8_t *synch_info, const uint32_t elapsed_time)
872901
{
873902

@@ -877,9 +906,11 @@ static void fhss_beacon_received(fhss_structure_t *fhss_structure, const uint8_t
877906
fhss_synchronization_beacon_payload_s temp_payload;
878907
temp_payload.processing_delay = fhss_structure->bs->fhss_configuration.fhss_tuning_parameters.rx_processing_delay;
879908
fhss_beacon_decode(&temp_payload, synch_info, elapsed_time, fhss_structure->number_of_channels);
880-
881-
// use the received information
882-
fhss_sync_with_beacon(fhss_structure, &temp_payload);
909+
if (!fhss_synch_info_validate(&temp_payload)) {
910+
fhss_sync_with_beacon(fhss_structure, &temp_payload);
911+
} else {
912+
tr_err("Invalid synch info received");
913+
}
883914
}
884915
}
885916
}

source/Service_Libs/fhss/fhss.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define MAX_SYNCH_INFOS_PER_CHANNEL_LIST 2
2424
// FHSS randomly selects the starting superframe for broadcast channel. This defines how many superframes are used for randomization.
2525
#define NUMBER_OF_BC_START_SUPERFRAMES 3
26+
#define FHSS_MAX_ALLOWED_HOPS 254
2627
#define MAX_FHSS_TIMER_DIVIDER 100
2728
#define SYNCH_MONITOR_AVG_SAMPLES 5
2829
#define FHSS_DATA_START_DELIMETER 0x00

0 commit comments

Comments
 (0)