From f12f649d8a6a454172d5e231fb07709a14a8b077 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 30 May 2021 20:41:44 -0400 Subject: [PATCH 1/3] Fix #739: fix #740: improve JoinAccept CFList processing --- src/lmic/lmic.c | 18 +++--------------- src/lmic/lmic_bandplan.h | 4 ++++ src/lmic/lmic_eu_like.c | 21 +++++++++++++++++++++ src/lmic/lmic_eu_like.h | 5 +++++ src/lmic/lmic_us_like.c | 26 ++++++++++++++++++++++++++ src/lmic/lmic_us_like.h | 10 ++++++++-- src/lmic/lorabase.h | 7 +++++++ 7 files changed, 74 insertions(+), 17 deletions(-) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 6a6f288c..9d4c90ea 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -1621,21 +1621,9 @@ static bit_t processJoinAccept (void) { // initDefaultChannels(0) for EU-like, nothing otherwise LMICbandplan_joinAcceptChannelClear(); - if (!LMICbandplan_hasJoinCFlist() && dlen > LEN_JA) { - // if no JoinCFList, we're supposed to continue - // the join per 2.2.5 of LoRaWAN regional 2.2.4 - // https://github.com/mcci-catena/arduino-lmic/issues/19 - } else if ( LMICbandplan_hasJoinCFlist() && dlen > LEN_JA ) { - dlen = OFF_CFLIST; - for( u1_t chidx=3; chidx<8; chidx++, dlen+=3 ) { - u4_t freq = LMICbandplan_convFreq(&LMIC.frame[dlen]); - if( freq ) { - LMIC_setupChannel(chidx, freq, 0, -1); -#if LMIC_DEBUG_LEVEL > 1 - LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel, idx=%d, freq=%"PRIu32"\n", os_getTime(), chidx, freq); -#endif - } - } + // process the CFList if present + if (dlen == LEN_JAEXT) { + LMICbandplan_processJoinAcceptCFList(); } // already incremented when JOIN REQ got sent off diff --git a/src/lmic/lmic_bandplan.h b/src/lmic/lmic_bandplan.h index e43a7ba0..3921819f 100644 --- a/src/lmic/lmic_bandplan.h +++ b/src/lmic/lmic_bandplan.h @@ -170,6 +170,10 @@ # error "LMICbandplan_validDR() not defined by bandplan" #endif +#if !defined(LMICbandplan_processJoinAcceptCFList) +# error "LMICbandplan_processJoinAcceptCFList() not defined by bandplan" +#endif + // // Things common to lmic.c code // diff --git a/src/lmic/lmic_eu_like.c b/src/lmic/lmic_eu_like.c index 44533790..733ff3c8 100644 --- a/src/lmic/lmic_eu_like.c +++ b/src/lmic/lmic_eu_like.c @@ -227,6 +227,27 @@ ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) { } #endif // !DISABLE_JOIN +#if !defined(DISABLE_JOIN) +void LMICeulike_processJoinAcceptCFList(void) { + if ( LMICbandplan_hasJoinCFlist() && + LMIC.frame[OFF_CFLIST + 15] == LORAWAN_JoinAccept_CFListType_FREQUENCIES) { + u1_t dlen; + u1_t nDefault = LMIC_queryNumDefaultChannels(); + + dlen = OFF_CFLIST; + for( u1_t chidx = nDefault; chidx < nDefault + 5; chidx++, dlen+=3 ) { + u4_t freq = LMICbandplan_convFreq(&LMIC.frame[dlen]); + if( freq ) { + LMIC_setupChannel(chidx, freq, 0, -1); +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel, idx=%d, freq=%"PRIu32"\n", os_getTime(), chidx, freq); +#endif + } + } + } +} +#endif // !DISABLE_JOIN + void LMICeulike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer) { os_copyMem( pStateBuffer->channelFreq, diff --git a/src/lmic/lmic_eu_like.h b/src/lmic/lmic_eu_like.h index c9bbeac1..729af643 100644 --- a/src/lmic/lmic_eu_like.h +++ b/src/lmic/lmic_eu_like.h @@ -66,6 +66,11 @@ enum { BAND_MILLI = 0, BAND_CENTI = 1, BAND_DECI = 2, BAND_AUX = 3 }; // there's a CFList on joins for EU-like plans #define LMICbandplan_hasJoinCFlist() (1) +/// \brief process CFLists from JoinAccept for EU-like regions +void LMICeulike_processJoinAcceptCFList(void); +/// \brief by default, EU-like plans use LMICeulike_processJoinAcceptCFList +#define LMICbandplan_processJoinAcceptCFList LMICeulike_processJoinAcceptCFList + #define LMICbandplan_advanceBeaconChannel() \ do { /* nothing */ } while (0) diff --git a/src/lmic/lmic_us_like.c b/src/lmic/lmic_us_like.c index d2e89d36..31e4cc18 100644 --- a/src/lmic/lmic_us_like.c +++ b/src/lmic/lmic_us_like.c @@ -315,6 +315,32 @@ ostime_t LMICuslike_nextJoinState(void) { } #endif +#if !defined(DISABLE_JOIN) +void LMICuslike_processJoinAcceptCFList(void) { + if ( LMICbandplan_hasJoinCFlist() && + LMIC.frame[OFF_CFLIST + 15] == LORAWAN_JoinAccept_CFListType_MASK ) { + u1_t dlen; + + dlen = OFF_CFLIST; + for( u1_t chidx = 0; chidx < 8 * sizeof(LMIC.channelMap); chidx += 16, dlen += 2 ) { + u2_t mask = os_rlsbf2(&LMIC.frame[dlen]); +#if LMIC_DEBUG_LEVEL > 1 + LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel mask, group=%u, mask=%04x\n", os_getTime(), chidx, mask); +#endif + for ( u1_t chnum = chidx; chnum < chidx + 16; ++chnum, mask >>= 1) { + if (chnum >= 72) { + break; + } else if (mask & 1) { + LMIC_enableChannel(chnum); + } else { + LMIC_disableChannel(chnum); + } + } + } + } +} +#endif // !DISABLE_JOIN + void LMICuslike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer) { os_copyMem( pStateBuffer->channelMap, diff --git a/src/lmic/lmic_us_like.h b/src/lmic/lmic_us_like.h index 62812369..f3e8bfca 100644 --- a/src/lmic/lmic_us_like.h +++ b/src/lmic/lmic_us_like.h @@ -63,8 +63,14 @@ LMICuslike_isValidBeacon1(const uint8_t *d) { // provide a default LMICbandplan_joinAcceptChannelClear() #define LMICbandplan_joinAcceptChannelClear() do { } while (0) -// no CFList on joins for US-like plans -#define LMICbandplan_hasJoinCFlist() (0) +/// \brief there's a CFList on joins for US-like plans +#define LMICbandplan_hasJoinCFlist() (1) + +/// \brief process CFLists from JoinAccept for EU-like regions +void LMICuslike_processJoinAcceptCFList(void); +/// \brief by default, EU-like plans use LMICuslike_processJoinAcceptCFList +#define LMICbandplan_processJoinAcceptCFList LMICuslike_processJoinAcceptCFList + #define LMICbandplan_advanceBeaconChannel() \ do { LMIC.bcnChnl = (LMIC.bcnChnl+1) & 7; } while (0) diff --git a/src/lmic/lorabase.h b/src/lmic/lorabase.h index f668f42a..632a8b42 100644 --- a/src/lmic/lorabase.h +++ b/src/lmic/lorabase.h @@ -445,6 +445,13 @@ enum { LEN_JA = 17, LEN_JAEXT = 17+16 }; + +enum { + // JoinAccept CFList types + LORAWAN_JoinAccept_CFListType_FREQUENCIES = 0, ///< the CFList contains 5 frequencies + LORAWAN_JoinAccept_CFListType_MASK = 1, ///< the CFList contains channel-mask data +}; + enum { // Data frame format OFF_DAT_HDR = 0, From 5b767c33c90144b084a69b974dd4441a3f1eee57 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sun, 30 May 2021 20:42:33 -0400 Subject: [PATCH 2/3] This is v3.99.0-3 --- src/lmic/lmic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index b959511e..56539031 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -105,8 +105,8 @@ extern "C"{ #define ARDUINO_LMIC_VERSION_CALC(major, minor, patch, local) \ ((((major)*UINT32_C(1)) << 24) | (((minor)*UINT32_C(1)) << 16) | (((patch)*UINT32_C(1)) << 8) | (((local)*UINT32_C(1)) << 0)) -#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(3, 99, 0, 2) - /* 3.99.0-1 */ +#define ARDUINO_LMIC_VERSION \ + ARDUINO_LMIC_VERSION_CALC(3, 99, 0, 3) /* 3.99.0-3 */ #define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \ ((((v)*UINT32_C(1)) >> 24u) & 0xFFu) From 496266d6273c6ba1b761bdb8e2f7388124eaf097 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Mon, 31 May 2021 00:06:06 -0400 Subject: [PATCH 3/3] Update release notes --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 394c53f3..06e523fa 100644 --- a/README.md +++ b/README.md @@ -1239,7 +1239,18 @@ function uflt12f(rawUflt12) - HEAD has the following changes. + - Fix some broken documentation references [#644](https://github.com/mcci-catena/arduino-lmic/issues/644), [#646](https://github.com/mcci-catena/arduino-lmic/pulls/646), [#673](https://github.com/mcci-catena/arduino-lmic/pulls/673). - Re-added CI testing, since Travis CI no longer works for us [#647](https://github.com/mcci-catena/arduino-lmic/issues/647); fixed AVR compliance CI compile [#679](https://github.com/mcci-catena/arduino-lmic/issues/679). + - Don't use `defined()` in macro definitions [#606](https://github.com/mcci-catena/arduino-lmic/issues/606) + - Fix a warning on AVR32 [#709](https://github.com/mcci-catena/arduino-lmic/pulls/709). + - Fix Helium link in examples [#715](https://github.com/mcci-catena/arduino-lmic/issues/715), [#718](https://github.com/mcci-catena/arduino-lmic/pulls/718). + - Remove `XCHANNEL` support from US region [#404](https://github.com/mcci-catena/arduino-lmic/issues/404) + - Assign channels randomly without replacement [#515](https://github.com/mcci-catena/arduino-lmic/issues/515), [#619](https://github.com/mcci-catena/arduino-lmic/issues/619), [#730](https://github.com/mcci-catena/arduino-lmic/issues/730). + - Don't allow `LMIC_setupChannel()` to change default channels [#722](https://github.com/mcci-catena/arduino-lmic/issues/722). + - Don't accept out-of-range DRs from MAC downlink messages [#723](https://github.com/mcci-catena/arduino-lmic/issues/723) + - Adopt semantic versions completely [#726](https://github.com/mcci-catena/arduino-lmic/issues/726). + - Implement JoinAccept CFList processing for US/AU [#739](https://github.com/mcci-catena/arduino-lmic/issues/739). + - Correct JoinAccept CFList processing for AS923 [#740](https://github.com/mcci-catena/arduino-lmic/issues/740). - v3.3.0 is primarily a maintenance and roll-up release.