Skip to content

Commit e4571f4

Browse files
committed
Fix #419: invalid DRs caused by TxParamSetupReq
1 parent 279ff2d commit e4571f4

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

src/lmic/lmic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ static void resetJoinParams(void) {
577577
LMIC.rx1DrOffset = 0;
578578
LMIC.dn2Dr = DR_DNW2;
579579
LMIC.dn2Freq = FREQ_DNW2;
580+
#if LMIC_ENABLE_TxParamSetupReq
581+
LMIC.txParam = 0xFF;
582+
#endif
580583
}
581584

582585
static void stateJustJoined (void) {
@@ -2676,14 +2679,14 @@ void LMIC_reset (void) {
26762679
LMIC.opmode = OP_NONE;
26772680
LMIC.errcr = CR_4_5;
26782681
LMIC.adrEnabled = FCT_ADREN;
2679-
LMIC.dn2Dr = DR_DNW2; // we need this for 2nd DN window of join accept
2680-
LMIC.dn2Freq = FREQ_DNW2; // ditto
2682+
resetJoinParams();
26812683
LMIC.rxDelay = DELAY_DNW1;
26822684
#if !defined(DISABLE_PING)
26832685
LMIC.ping.freq = FREQ_PING; // defaults for ping
26842686
LMIC.ping.dr = DR_PING; // ditto
26852687
LMIC.ping.intvExp = 0xFF;
26862688
#endif // !DISABLE_PING
2689+
26872690
LMICbandplan_resetDefaultChannels();
26882691
DO_DEVDB(LMIC.devaddr, devaddr);
26892692
DO_DEVDB(LMIC.devNonce, devNonce);

src/lmic/lmic_as923.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,18 @@ static CONST_TABLE(u1_t, maxFrameLens_dwell1)[] = {
7676

7777
static uint8_t
7878
LMICas923_getUplinkDwellBit(uint8_t mcmd_txparam) {
79-
LMIC_API_PARAMETER(mcmd_txparam);
79+
if (mcmd_txparam == 0xFF)
80+
return 0;
8081

81-
return (LMIC.txParam & MCMD_TxParam_TxDWELL_MASK) != 0;
82+
return (mcmd_txparam & MCMD_TxParam_TxDWELL_MASK) != 0;
8283
}
8384

8485
static uint8_t
8586
LMICas923_getDownlinkDwellBit(uint8_t mcmd_txparam) {
86-
LMIC_API_PARAMETER(mcmd_txparam);
87+
if (mcmd_txparam == 0xFF)
88+
return 0;
8789

88-
return (LMIC.txParam & MCMD_TxParam_RxDWELL_MASK) != 0;
90+
return (mcmd_txparam & MCMD_TxParam_RxDWELL_MASK) != 0;
8991
}
9092

9193
uint8_t LMICas923_maxFrameLen(uint8_t dr) {
@@ -118,6 +120,7 @@ static CONST_TABLE(s1_t, TXMAXEIRP)[16] = {
118120
};
119121

120122
static int8_t LMICas923_getMaxEIRP(uint8_t mcmd_txparam) {
123+
// if uninitialized, return default.
121124
if (mcmd_txparam == 0xFF)
122125
return AS923_TX_EIRP_MAX_DBM;
123126
else
@@ -368,7 +371,7 @@ LMICas923_txDoneFSK(ostime_t delay, osjobcb_t func) {
368371

369372
void
370373
LMICas923_initJoinLoop(void) {
371-
LMIC.txParam = 0xFF;
374+
// LMIC.txParam is set to 0xFF by the central code at init time.
372375
LMICeulike_initJoinLoop(NUM_DEFAULT_CHANNELS, /* adr dBm */ AS923_TX_EIRP_MAX_DBM);
373376
}
374377

src/lmic/lmic_au921.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ static CONST_TABLE(u1_t, maxFrameLens_dwell1)[] = {
6565

6666
static bit_t
6767
LMICau921_getUplinkDwellBit() {
68+
// if uninitialized, return default.
69+
if (LMIC.txParam == 0xFF) {
70+
return 0;
71+
}
6872
return (LMIC.txParam & MCMD_TxParam_TxDWELL_MASK) != 0;
6973
}
7074

@@ -82,11 +86,29 @@ uint8_t LMICau921_maxFrameLen(uint8_t dr) {
8286
}
8387
}
8488

89+
// from LoRaWAN 5.8: mapping from txParam to MaxEIRP
90+
static CONST_TABLE(s1_t, TXMAXEIRP)[16] = {
91+
8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36
92+
};
93+
94+
static int8_t LMICau921_getMaxEIRP(uint8_t mcmd_txparam) {
95+
// if uninitialized, return default.
96+
if (mcmd_txparam == 0xFF)
97+
return AU921_TX_EIRP_MAX_DBM;
98+
else
99+
return TABLE_GET_S1(
100+
TXMAXEIRP,
101+
(mcmd_txparam & MCMD_TxParam_MaxEIRP_MASK) >>
102+
MCMD_TxParam_MaxEIRP_SHIFT
103+
);
104+
}
105+
85106
int8_t LMICau921_pow2dbm(uint8_t mcmd_ladr_p1) {
86107
if ((mcmd_ladr_p1 & MCMD_LinkADRReq_POW_MASK) == MCMD_LinkADRReq_POW_MASK)
87108
return -128;
88-
else
89-
return ((s1_t)(30 - (((mcmd_ladr_p1)&MCMD_LinkADRReq_POW_MASK)<<1)));
109+
else {
110+
return ((s1_t)(LMICau921_getMaxEIRP(LMIC.txParam) - (((mcmd_ladr_p1)&MCMD_LinkADRReq_POW_MASK)<<1)));
111+
}
90112
}
91113

92114
static CONST_TABLE(ostime_t, DR2HSYM_osticks)[] = {
@@ -209,7 +231,7 @@ bit_t LMIC_selectSubBand(u1_t band) {
209231

210232
void LMICau921_updateTx(ostime_t txbeg) {
211233
u1_t chnl = LMIC.txChnl;
212-
LMIC.txpow = AU921_TX_EIRP_MAX_DBM;
234+
LMIC.txpow = LMICau921_getMaxEIRP(LMIC.txParam);
213235
if (chnl < 64) {
214236
LMIC.freq = AU921_125kHz_UPFBASE + chnl*AU921_125kHz_UPFSTEP;
215237
} else {
@@ -252,10 +274,11 @@ void LMICau921_setRx1Params(void) {
252274
}
253275

254276
void LMICau921_initJoinLoop(void) {
277+
// LMIC.txParam is set to 0xFF by the central code at init time.
255278
LMICuslike_initJoinLoop();
256279

257280
// initialize the adrTxPower.
258-
LMIC.adrTxPow = 30; // dBm
281+
LMIC.adrTxPow = LMICau921_getMaxEIRP(LMIC.txParam); // dBm
259282

260283
}
261284

src/lmic/lmic_eu_like.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ bit_t LMICeulike_mapChannels(u1_t chpage, u2_t chmap) {
107107
}
108108

109109
bit_t LMICeulike_isDataRateFeasible(dr_t dr) {
110+
// if the region uses TxpParam, then someone
111+
// could have changed TxDwell, which makes some
112+
// otherwise-legal DRs infeasible.
113+
#if LMIC_ENABLE_TxParamSetupReq
114+
if (LMICbandplan_maxFrameLen(dr) == 0) {
115+
return 0;
116+
}
117+
#endif
110118
for (u1_t chnl = 0; chnl < MAX_CHANNELS; ++chnl) {
111119
if ((LMIC.channelMap & (1 << chnl)) != 0 && // channel enabled
112120
(LMIC.channelDrMap[chnl] & (1 << dr)) != 0)

0 commit comments

Comments
 (0)