Skip to content

Commit 8e72b80

Browse files
author
Jarkko Paso
authored
MAC CCA thr: Check if channel out of range (#2363)
1 parent 146a0a3 commit 8e72b80

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

source/MAC/IEEE802_15_4/mac_cca_threshold.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ int8_t mac_cca_thr_get_dbm(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t ch
7474
if (!rf_ptr->cca_threshold) {
7575
return CCA_FAILED_DBM;
7676
}
77+
// If channel is unknown, use default threshold
78+
if (channel > (rf_ptr->cca_threshold->number_of_channels - 1)) {
79+
return rf_ptr->cca_threshold->default_dbm;
80+
}
7781
return rf_ptr->cca_threshold->ch_thresholds[channel];
7882
}
7983

@@ -118,6 +122,12 @@ static int8_t mac_cca_thr_channel_failed(protocol_interface_rf_mac_setup_s *rf_p
118122

119123
int8_t mac_cca_threshold_update(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t channel, int8_t dbm)
120124
{
125+
if (!rf_ptr->cca_threshold) {
126+
return -1;
127+
}
128+
if (channel > (rf_ptr->cca_threshold->number_of_channels - 1)) {
129+
return -1;
130+
}
121131
if (dbm == CCA_FAILED_DBM) {
122132
if (mac_cca_thr_channel_failed(rf_ptr, channel)) {
123133
return -1;

0 commit comments

Comments
 (0)