mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
646 stars 212 forks source link

`LMICuslike_canMapChannels` should not reject zero mask when setting bank-by-bank #820

Closed terrillmoore closed 2 years ago

terrillmoore commented 2 years ago

In preparing the fix for #819, discovered a similar (but unreported) problem with the setting of channel masks directly here: https://github.com/mcci-catena/arduino-lmic/blob/26326e4fc30fd6ee95cf8d5f78e16f34e957d38b/src/lmic/lmic_us_like.c#L113-L117

Originally posted by @terrillmoore in https://github.com/mcci-catena/arduino-lmic/issues/819#issuecomment-974698990

Filed as a separate bug because it's independent of #819, but want to use same PR.

As with #819, the problem is that we can't reject "all channels off" while processing a MAC command; another in the same message might turn some on. We can only check minimum number of channels after all MAC commands have been parsed. It's fine to have the second part of the if, because out-of-range channels are illegal; but not ok to have the first (because we don't know that all channels off is illegal yet).