@@ -127,7 +127,7 @@ uint8_t LoRaPHY::request_new_channel(int8_t channel_id, channel_params_t* new_ch
127
127
status &= 0xFC ;
128
128
}
129
129
} else {
130
-
130
+ new_channel-> band = lookup_band_for_frequency (new_channel-> frequency );
131
131
switch (add_channel (new_channel, channel_id)) {
132
132
case LORAWAN_STATUS_OK:
133
133
{
@@ -186,13 +186,13 @@ bool LoRaPHY::verify_channel_DR(uint8_t nb_channels, uint16_t* channel_mask,
186
186
return false ;
187
187
}
188
188
189
- uint8_t LoRaPHY::val_in_range ( int8_t value, int8_t min, int8_t max )
189
+ bool LoRaPHY::val_in_range ( int8_t value, int8_t min, int8_t max )
190
190
{
191
191
if ((value >= min) && (value <= max)) {
192
- return 1 ;
192
+ return true ;
193
193
}
194
194
195
- return 0 ;
195
+ return false ;
196
196
}
197
197
198
198
bool LoRaPHY::disable_channel (uint16_t * channel_mask, uint8_t id,
@@ -733,6 +733,9 @@ void LoRaPHY::apply_cf_list(const uint8_t* payload, uint8_t size)
733
733
}
734
734
735
735
if (new_channel.frequency != 0 ) {
736
+ // lookup for band
737
+ new_channel.band = lookup_band_for_frequency (new_channel.frequency );
738
+
736
739
// Try to add channel
737
740
add_channel (&new_channel, channel_id);
738
741
} else {
@@ -1065,21 +1068,30 @@ bool LoRaPHY::accept_tx_param_setup_req(uint8_t ul_dwell_time, uint8_t dl_dwell_
1065
1068
return phy_params.accept_tx_param_setup_req ;
1066
1069
}
1067
1070
1068
- bool LoRaPHY::verify_frequency (uint32_t freq)
1071
+ int LoRaPHY::lookup_band_for_frequency (uint32_t freq) const
1069
1072
{
1070
- band_t *bands_table = (band_t *)phy_params.bands .table ;
1071
-
1072
1073
// check all sub bands (if there are sub-bands) to check if the given
1073
1074
// frequency falls into any of the frequency ranges
1074
1075
1075
- for (uint8_t i=0 ; i<phy_params.bands .size ; i++) {
1076
- if (freq <= bands_table[i].higher_band_freq
1077
- && freq >= bands_table[i].lower_band_freq ) {
1078
- return true ;
1076
+ for (int band=0 ; band<phy_params.bands .size ; band++) {
1077
+ if (verify_frequency_for_band (freq, band)) {
1078
+ return band;
1079
1079
}
1080
1080
}
1081
1081
1082
- return false ;
1082
+ return -1 ;
1083
+ }
1084
+
1085
+ bool LoRaPHY::verify_frequency_for_band (uint32_t freq, uint8_t band) const
1086
+ {
1087
+ band_t *bands_table = (band_t *)phy_params.bands .table ;
1088
+
1089
+ if (freq <= bands_table[band].higher_band_freq
1090
+ && freq >= bands_table[band].lower_band_freq ) {
1091
+ return true ;
1092
+ } else {
1093
+ return false ;
1094
+ }
1083
1095
}
1084
1096
1085
1097
uint8_t LoRaPHY::dl_channel_request (uint8_t channel_id, uint32_t rx1_frequency)
@@ -1091,7 +1103,8 @@ uint8_t LoRaPHY::dl_channel_request(uint8_t channel_id, uint32_t rx1_frequency)
1091
1103
uint8_t status = 0x03 ;
1092
1104
1093
1105
// Verify if the frequency is supported
1094
- if (verify_frequency (rx1_frequency) == false ) {
1106
+ uint8_t band = lookup_band_for_frequency (rx1_frequency);
1107
+ if (verify_frequency_for_band (rx1_frequency, band) == false ) {
1095
1108
status &= 0xFE ;
1096
1109
}
1097
1110
@@ -1263,7 +1276,7 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t* params,
1263
1276
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
1264
1277
}
1265
1278
1266
- lorawan_status_t LoRaPHY::add_channel (channel_params_t * new_channel, uint8_t id)
1279
+ lorawan_status_t LoRaPHY::add_channel (const channel_params_t * new_channel, uint8_t id)
1267
1280
{
1268
1281
bool dr_invalid = false ;
1269
1282
bool freq_invalid = false ;
@@ -1312,7 +1325,9 @@ lorawan_status_t LoRaPHY::add_channel(channel_params_t* new_channel, uint8_t id)
1312
1325
1313
1326
// Check frequency
1314
1327
if (!freq_invalid) {
1315
- if (verify_frequency (new_channel->frequency ) == false ) {
1328
+ if (new_channel->band >= phy_params.bands .size
1329
+ || verify_frequency_for_band (new_channel->frequency ,
1330
+ new_channel->band ) == false ) {
1316
1331
freq_invalid = true ;
1317
1332
}
1318
1333
}
0 commit comments