Skip to content

Commit 7eaa4c3

Browse files
authored
Merge pull request #406 from mcci-catena/issue397
Improve EU868 compliance
2 parents 7315dc1 + 5d9017a commit 7eaa4c3

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/lmic/lmic.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ scan_mac_cmds_link_adr(
832832

833833
// can we advance?
834834
if (olen - oidx < kAdrReqSize) {
835-
// ignore the malformed one at the end
835+
// ignore the malformed one at the end; but fail it.
836+
adrAns = 0;
836837
break;
837838
}
838839
u1_t p1 = opts[oidx+1]; // txpow + DR
@@ -841,8 +842,10 @@ scan_mac_cmds_link_adr(
841842
// u1_t uprpt = opts[oidx+4] & MCMD_LinkADRReq_Redundancy_NbTrans_MASK; // up repeat count
842843
dr_t dr = (dr_t)(p1>>MCMD_LinkADRReq_DR_SHIFT);
843844

844-
if( !LMICbandplan_canMapChannels(chpage, chmap) )
845+
if( !LMICbandplan_canMapChannels(chpage, chmap) ) {
845846
adrAns &= ~MCMD_LinkADRAns_ChannelACK;
847+
LMICOS_logEventUint32("scan_mac_cmds_link_adr: failed canMapChannels", (chpage << UINT32_C(16))|(chmap << UINT32_C(0)));
848+
}
846849

847850
if( !validDR(dr) ) {
848851
adrAns &= ~MCMD_LinkADRAns_DataRateACK;
@@ -970,9 +973,6 @@ scan_mac_cmds(
970973
case MCMD_DutyCycleReq: {
971974
#if !defined(DISABLE_MCMD_DutyCycleReq)
972975
u1_t cap = opts[oidx+1];
973-
// A value cap=0xFF means device is OFF unless enabled again manually.
974-
if( cap==0xFF )
975-
LMIC.opmode |= OP_SHUTDOWN; // stop any sending
976976
LMIC.globalDutyRate = cap & 0xF;
977977
LMIC.globalDutyAvail = os_getTime();
978978
DO_DEVDB(cap,dutyCap);

src/lmic/lmic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extern "C"{
105105
#define ARDUINO_LMIC_VERSION_CALC(major, minor, patch, local) \
106106
(((major) << 24u) | ((minor) << 16u) | ((patch) << 8u) | (local))
107107

108-
#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(2, 3, 2, 71) /* v2.3.2.71 */
108+
#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(2, 3, 2, 73) /* v2.3.2.73 */
109109

110110
#define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \
111111
(((v) >> 24u) & 0xFFu)

src/lmic/lmic_as923.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) {
224224
}
225225

226226
bit_t LMIC_setupChannel(u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
227+
// zero the band bits in freq, just in case.
228+
freq &= ~3;
229+
227230
if (chidx < NUM_DEFAULT_CHANNELS) {
228231
// can't disable a default channel.
229232
if (freq == 0)

src/lmic/lmic_eu868.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) {
138138
}
139139

140140
bit_t LMIC_setupChannel(u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
141+
// zero the band bits in freq, just in case.
142+
freq &= ~3;
143+
141144
if (chidx < NUM_DEFAULT_CHANNELS) {
142145
// can't disable a default channel.
143146
if (freq == 0)
@@ -149,13 +152,17 @@ bit_t LMIC_setupChannel(u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
149152
bit_t fEnable = (freq != 0);
150153
if (chidx >= MAX_CHANNELS)
151154
return 0;
155+
152156
if (band == -1) {
153157
if (freq >= 869400000 && freq <= 869650000)
158+
// this is the g2 band
154159
freq |= BAND_DECI; // 10% 27dBm
155-
else if ((freq >= 868000000 && freq <= 868600000) ||
156-
(freq >= 869700000 && freq <= 870000000))
160+
else if ((865000000 <= freq && freq <= 868600000) || // note 9
161+
(freq >= 869700000 && freq <= 870000000)) // g4
162+
// this is the special g, g1 or g4 band
157163
freq |= BAND_CENTI; // 1% 14dBm
158164
else
165+
// this is elsewhere in the g band
159166
freq |= BAND_MILLI; // 0.1% 14dBm
160167
}
161168
else {

src/lmic/lmic_eu_like.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ bit_t LMIC_enableChannel(u1_t channel) {
6363
bit_t LMICeulike_canMapChannels(u1_t chpage, u2_t chmap) {
6464
switch (chpage) {
6565
case MCMD_LinkADRReq_ChMaskCntl_EULIKE_DIRECT:
66-
if ((chmap & ~LMIC.channelMap) != 0 ) {
67-
return 0;
68-
}
66+
// we don't allow any channel to be turned on if its frequency is zero.
6967
for (u1_t chnl = 0; chnl<MAX_CHANNELS; chnl++) {
7068
if ((chmap & (1 << chnl)) != 0 && (LMIC.channelFreq[chnl]&~3) == 0)
7169
return 0; // fail - channel is not defined
@@ -93,7 +91,7 @@ bit_t LMICeulike_mapChannels(u1_t chpage, u2_t chmap) {
9391
case MCMD_LinkADRReq_ChMaskCntl_EULIKE_ALL_ON: {
9492
u2_t new_chmap = 0;
9593
for (u1_t chnl = 0; chnl<MAX_CHANNELS; chnl++) {
96-
if (LMIC.channelFreq[chnl] != 0) {
94+
if ((LMIC.channelFreq[chnl]&~3) != 0) {
9795
new_chmap |= (1 << chnl);
9896
}
9997
}

src/lmic/lmic_in866.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) {
133133
}
134134

135135
bit_t LMIC_setupChannel(u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
136+
// zero the band bits in freq, just in case.
137+
freq &= ~3;
138+
136139
if (chidx < NUM_DEFAULT_CHANNELS) {
137140
// can't disable a default channel.
138141
if (freq == 0)

src/lmic/lmic_kr920.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ bit_t LMIC_setupBand(u1_t bandidx, s1_t txpow, u2_t txcap) {
144144
}
145145

146146
bit_t LMIC_setupChannel(u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
147+
// zero the band bits in freq, just in case.
148+
freq &= ~3;
149+
147150
if (chidx < NUM_DEFAULT_CHANNELS) {
148151
// can't disable a default channel.
149152
if (freq == 0)

0 commit comments

Comments
 (0)