Skip to content

Commit b680117

Browse files
authored
Merge pull request #741 from mcci-catena/issue739
Improve JoinAccept CFList Processing
2 parents f35e6e3 + 496266d commit b680117

File tree

9 files changed

+87
-19
lines changed

9 files changed

+87
-19
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,18 @@ function uflt12f(rawUflt12)
12391239

12401240
- HEAD has the following changes.
12411241

1242+
- 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).
12421243
- 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).
1244+
- Don't use `defined()` in macro definitions [#606](https://github.com/mcci-catena/arduino-lmic/issues/606)
1245+
- Fix a warning on AVR32 [#709](https://github.com/mcci-catena/arduino-lmic/pulls/709).
1246+
- 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).
1247+
- Remove `XCHANNEL` support from US region [#404](https://github.com/mcci-catena/arduino-lmic/issues/404)
1248+
- 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).
1249+
- Don't allow `LMIC_setupChannel()` to change default channels [#722](https://github.com/mcci-catena/arduino-lmic/issues/722).
1250+
- Don't accept out-of-range DRs from MAC downlink messages [#723](https://github.com/mcci-catena/arduino-lmic/issues/723)
1251+
- Adopt semantic versions completely [#726](https://github.com/mcci-catena/arduino-lmic/issues/726).
1252+
- Implement JoinAccept CFList processing for US/AU [#739](https://github.com/mcci-catena/arduino-lmic/issues/739).
1253+
- Correct JoinAccept CFList processing for AS923 [#740](https://github.com/mcci-catena/arduino-lmic/issues/740).
12431254

12441255
- v3.3.0 is primarily a maintenance and roll-up release.
12451256

src/lmic/lmic.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,21 +1621,9 @@ static bit_t processJoinAccept (void) {
16211621
// initDefaultChannels(0) for EU-like, nothing otherwise
16221622
LMICbandplan_joinAcceptChannelClear();
16231623

1624-
if (!LMICbandplan_hasJoinCFlist() && dlen > LEN_JA) {
1625-
// if no JoinCFList, we're supposed to continue
1626-
// the join per 2.2.5 of LoRaWAN regional 2.2.4
1627-
// https://github.com/mcci-catena/arduino-lmic/issues/19
1628-
} else if ( LMICbandplan_hasJoinCFlist() && dlen > LEN_JA ) {
1629-
dlen = OFF_CFLIST;
1630-
for( u1_t chidx=3; chidx<8; chidx++, dlen+=3 ) {
1631-
u4_t freq = LMICbandplan_convFreq(&LMIC.frame[dlen]);
1632-
if( freq ) {
1633-
LMIC_setupChannel(chidx, freq, 0, -1);
1634-
#if LMIC_DEBUG_LEVEL > 1
1635-
LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel, idx=%d, freq=%"PRIu32"\n", os_getTime(), chidx, freq);
1636-
#endif
1637-
}
1638-
}
1624+
// process the CFList if present
1625+
if (dlen == LEN_JAEXT) {
1626+
LMICbandplan_processJoinAcceptCFList();
16391627
}
16401628

16411629
// already incremented when JOIN REQ got sent off

src/lmic/lmic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ extern "C"{
105105
#define ARDUINO_LMIC_VERSION_CALC(major, minor, patch, local) \
106106
((((major)*UINT32_C(1)) << 24) | (((minor)*UINT32_C(1)) << 16) | (((patch)*UINT32_C(1)) << 8) | (((local)*UINT32_C(1)) << 0))
107107

108-
#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(3, 99, 0, 2)
109-
/* 3.99.0-1 */
108+
#define ARDUINO_LMIC_VERSION \
109+
ARDUINO_LMIC_VERSION_CALC(3, 99, 0, 3) /* 3.99.0-3 */
110110

111111
#define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \
112112
((((v)*UINT32_C(1)) >> 24u) & 0xFFu)

src/lmic/lmic_bandplan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@
170170
# error "LMICbandplan_validDR() not defined by bandplan"
171171
#endif
172172

173+
#if !defined(LMICbandplan_processJoinAcceptCFList)
174+
# error "LMICbandplan_processJoinAcceptCFList() not defined by bandplan"
175+
#endif
176+
173177
//
174178
// Things common to lmic.c code
175179
//

src/lmic/lmic_eu_like.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,27 @@ ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) {
227227
}
228228
#endif // !DISABLE_JOIN
229229

230+
#if !defined(DISABLE_JOIN)
231+
void LMICeulike_processJoinAcceptCFList(void) {
232+
if ( LMICbandplan_hasJoinCFlist() &&
233+
LMIC.frame[OFF_CFLIST + 15] == LORAWAN_JoinAccept_CFListType_FREQUENCIES) {
234+
u1_t dlen;
235+
u1_t nDefault = LMIC_queryNumDefaultChannels();
236+
237+
dlen = OFF_CFLIST;
238+
for( u1_t chidx = nDefault; chidx < nDefault + 5; chidx++, dlen+=3 ) {
239+
u4_t freq = LMICbandplan_convFreq(&LMIC.frame[dlen]);
240+
if( freq ) {
241+
LMIC_setupChannel(chidx, freq, 0, -1);
242+
#if LMIC_DEBUG_LEVEL > 1
243+
LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel, idx=%d, freq=%"PRIu32"\n", os_getTime(), chidx, freq);
244+
#endif
245+
}
246+
}
247+
}
248+
}
249+
#endif // !DISABLE_JOIN
250+
230251
void LMICeulike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer) {
231252
os_copyMem(
232253
pStateBuffer->channelFreq,

src/lmic/lmic_eu_like.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ enum { BAND_MILLI = 0, BAND_CENTI = 1, BAND_DECI = 2, BAND_AUX = 3 };
6666
// there's a CFList on joins for EU-like plans
6767
#define LMICbandplan_hasJoinCFlist() (1)
6868

69+
/// \brief process CFLists from JoinAccept for EU-like regions
70+
void LMICeulike_processJoinAcceptCFList(void);
71+
/// \brief by default, EU-like plans use LMICeulike_processJoinAcceptCFList
72+
#define LMICbandplan_processJoinAcceptCFList LMICeulike_processJoinAcceptCFList
73+
6974
#define LMICbandplan_advanceBeaconChannel() \
7075
do { /* nothing */ } while (0)
7176

src/lmic/lmic_us_like.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,32 @@ ostime_t LMICuslike_nextJoinState(void) {
315315
}
316316
#endif
317317

318+
#if !defined(DISABLE_JOIN)
319+
void LMICuslike_processJoinAcceptCFList(void) {
320+
if ( LMICbandplan_hasJoinCFlist() &&
321+
LMIC.frame[OFF_CFLIST + 15] == LORAWAN_JoinAccept_CFListType_MASK ) {
322+
u1_t dlen;
323+
324+
dlen = OFF_CFLIST;
325+
for( u1_t chidx = 0; chidx < 8 * sizeof(LMIC.channelMap); chidx += 16, dlen += 2 ) {
326+
u2_t mask = os_rlsbf2(&LMIC.frame[dlen]);
327+
#if LMIC_DEBUG_LEVEL > 1
328+
LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": Setup channel mask, group=%u, mask=%04x\n", os_getTime(), chidx, mask);
329+
#endif
330+
for ( u1_t chnum = chidx; chnum < chidx + 16; ++chnum, mask >>= 1) {
331+
if (chnum >= 72) {
332+
break;
333+
} else if (mask & 1) {
334+
LMIC_enableChannel(chnum);
335+
} else {
336+
LMIC_disableChannel(chnum);
337+
}
338+
}
339+
}
340+
}
341+
}
342+
#endif // !DISABLE_JOIN
343+
318344
void LMICuslike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer) {
319345
os_copyMem(
320346
pStateBuffer->channelMap,

src/lmic/lmic_us_like.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ LMICuslike_isValidBeacon1(const uint8_t *d) {
6363
// provide a default LMICbandplan_joinAcceptChannelClear()
6464
#define LMICbandplan_joinAcceptChannelClear() do { } while (0)
6565

66-
// no CFList on joins for US-like plans
67-
#define LMICbandplan_hasJoinCFlist() (0)
66+
/// \brief there's a CFList on joins for US-like plans
67+
#define LMICbandplan_hasJoinCFlist() (1)
68+
69+
/// \brief process CFLists from JoinAccept for EU-like regions
70+
void LMICuslike_processJoinAcceptCFList(void);
71+
/// \brief by default, EU-like plans use LMICuslike_processJoinAcceptCFList
72+
#define LMICbandplan_processJoinAcceptCFList LMICuslike_processJoinAcceptCFList
73+
6874

6975
#define LMICbandplan_advanceBeaconChannel() \
7076
do { LMIC.bcnChnl = (LMIC.bcnChnl+1) & 7; } while (0)

src/lmic/lorabase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ enum {
445445
LEN_JA = 17,
446446
LEN_JAEXT = 17+16
447447
};
448+
449+
enum {
450+
// JoinAccept CFList types
451+
LORAWAN_JoinAccept_CFListType_FREQUENCIES = 0, ///< the CFList contains 5 frequencies
452+
LORAWAN_JoinAccept_CFListType_MASK = 1, ///< the CFList contains channel-mask data
453+
};
454+
448455
enum {
449456
// Data frame format
450457
OFF_DAT_HDR = 0,

0 commit comments

Comments
 (0)