Skip to content

Commit a9383bf

Browse files
Allow disabling some MAC commands
This causes these commands to be silently ignored, but they are recognized and skipped, so MAC commands coming after them can still be processed. Not all commands can be disabled, since commands like ADR are typically needed to prevent nodes from interfering with proper network operation.
1 parent be0e710 commit a9383bf

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

src/lmic/config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@
3030
// Requires ping to be disabled too
3131
//#define DISABLE_BEACONS
3232

33+
// Uncomment these to disable the corresponding MAC commands.
34+
// Class A
35+
//#define DISABLE_MCMD_DCAP_REQ // duty cycle cap
36+
//#define DISABLE_MCMD_DN2P_SET // 2nd DN window param
37+
//#define DISABLE_MCMD_SNCH_REQ // set new channel
38+
// Class B
39+
//#define DISABLE_MCMD_PING_SET // set ping freq, automatically disabled by DISABLE_PING
40+
//#define DISABLE_MCMD_BCNI_ANS // next beacon start, automatical disabled by DISABLE_BEACON
41+
3342
#endif // _lmic_config_h_

src/lmic/lmic.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,17 @@ static void stateJustJoined (void) {
917917
LMIC.seqnoDn = LMIC.seqnoUp = 0;
918918
LMIC.rejoinCnt = 0;
919919
LMIC.dnConf = LMIC.adrChanged = LMIC.ladrAns = LMIC.devsAns = 0;
920-
LMIC.moreData = LMIC.dn2Ans = LMIC.snchAns = LMIC.dutyCapAns = 0;
921-
#if !defined(DISABLE_PING)
920+
#if !defined(DISABLE_MCMD_SNCH_REQ)
921+
LMIC.snchAns = 0;
922+
#endif
923+
#if !defined(DISABLE_MCMD_DN2P_SET)
924+
LMIC.dn2Ans = 0;
925+
#endif
926+
LMIC.moreData = 0;
927+
#if !defined(DISABLE_MCMD_DCAP_REQ)
928+
LMIC.dutyCapAns = 0;
929+
#endif
930+
#if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING)
922931
LMIC.pingSetAns = 0;
923932
#endif
924933
LMIC.upRepeat = 0;
@@ -1122,9 +1131,9 @@ static bit_t decodeFrame (void) {
11221131
continue;
11231132
}
11241133
case MCMD_DN2P_SET: {
1134+
#if !defined(DISABLE_MCMD_DN2P_SET)
11251135
dr_t dr = (dr_t)(opts[oidx+1] & 0x0F);
11261136
u4_t freq = convFreq(&opts[oidx+2]);
1127-
oidx += 5;
11281137
LMIC.dn2Ans = 0x80; // answer pending
11291138
if( validDR(dr) )
11301139
LMIC.dn2Ans |= MCMD_DN2P_ANS_DRACK;
@@ -1136,32 +1145,38 @@ static bit_t decodeFrame (void) {
11361145
DO_DEVDB(LMIC.dn2Dr,dn2Dr);
11371146
DO_DEVDB(LMIC.dn2Freq,dn2Freq);
11381147
}
1148+
#endif // !DISABLE_MCMD_DN2P_SET
1149+
oidx += 5;
11391150
continue;
11401151
}
11411152
case MCMD_DCAP_REQ: {
1153+
#if !defined(DISABLE_MCMD_DCAP_REQ)
11421154
u1_t cap = opts[oidx+1];
1143-
oidx += 2;
11441155
// A value cap=0xFF means device is OFF unless enabled again manually.
11451156
if( cap==0xFF )
11461157
LMIC.opmode |= OP_SHUTDOWN; // stop any sending
11471158
LMIC.globalDutyRate = cap & 0xF;
11481159
LMIC.globalDutyAvail = os_getTime();
11491160
DO_DEVDB(cap,dutyCap);
11501161
LMIC.dutyCapAns = 1;
1162+
oidx += 2;
1163+
#endif // !DISABLE_MCMD_DCAP_REQ
11511164
continue;
11521165
}
11531166
case MCMD_SNCH_REQ: {
1167+
#if !defined(DISABLE_MCMD_SNCH_REQ)
11541168
u1_t chidx = opts[oidx+1]; // channel
11551169
u4_t freq = convFreq(&opts[oidx+2]); // freq
11561170
u1_t drs = opts[oidx+5]; // datarate span
11571171
LMIC.snchAns = 0x80;
11581172
if( freq != 0 && LMIC_setupChannel(chidx, freq, DR_RANGE_MAP(drs&0xF,drs>>4), -1) )
11591173
LMIC.snchAns |= MCMD_SNCH_ANS_DRACK|MCMD_SNCH_ANS_FQACK;
1174+
#endif // !DISABLE_MCMD_SNCH_REQ
11601175
oidx += 6;
11611176
continue;
11621177
}
11631178
case MCMD_PING_SET: {
1164-
#if !defined(DISABLE_PING)
1179+
#if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING)
11651180
u4_t freq = convFreq(&opts[oidx+1]);
11661181
u1_t flags = 0x80;
11671182
if( freq != 0 ) {
@@ -1172,12 +1187,12 @@ static bit_t decodeFrame (void) {
11721187
DO_DEVDB(LMIC.ping.dr, pingDr);
11731188
}
11741189
LMIC.pingSetAns = flags;
1175-
#endif // !DISABLE_PING
1190+
#endif // !DISABLE_MCMD_PING_SET && !DISABLE_PING
11761191
oidx += 4;
11771192
continue;
11781193
}
11791194
case MCMD_BCNI_ANS: {
1180-
#if !defined(DISABLE_BEACONS)
1195+
#if !defined(DISABLE_MCMD_BCNI_ANS) && !defined(DISABLE_BEACONS)
11811196
// Ignore if tracking already enabled
11821197
if( (LMIC.opmode & OP_TRACK) == 0 ) {
11831198
LMIC.bcnChnl = opts[oidx+3];
@@ -1201,7 +1216,7 @@ static bit_t decodeFrame (void) {
12011216
- LMIC.bcnRxtime) << 8)),
12021217
e_.time = MAIN::CDEV->ostime2ustime(LMIC.bcninfo.txtime + BCN_INTV_osticks)));
12031218
}
1204-
#endif // !DISABLE_BEACONS
1219+
#endif // !DISABLE_MCMD_BCNI_ANS && !DISABLE_BEACONS
12051220
oidx += 4;
12061221
continue;
12071222
}
@@ -1530,17 +1545,21 @@ static void buildDataFrame (void) {
15301545
end += 2;
15311546
}
15321547
#endif // !DISABLE_PING
1548+
#if !defined(DISABLE_MCMD_DCAP_REQ)
15331549
if( LMIC.dutyCapAns ) {
15341550
LMIC.frame[end] = MCMD_DCAP_ANS;
15351551
end += 1;
15361552
LMIC.dutyCapAns = 0;
15371553
}
1554+
#endif // !DISABLE_MCMD_DCAP_REQ
1555+
#if !defined(DISABLE_MCMD_DN2P_SET)
15381556
if( LMIC.dn2Ans ) {
15391557
LMIC.frame[end+0] = MCMD_DN2P_ANS;
15401558
LMIC.frame[end+1] = LMIC.dn2Ans & ~MCMD_DN2P_ANS_RFU;
15411559
end += 2;
15421560
LMIC.dn2Ans = 0;
15431561
}
1562+
#endif // !DISABLE_MCMD_DN2P_SET
15441563
if( LMIC.devsAns ) { // answer to device status
15451564
LMIC.frame[end+0] = MCMD_DEVS_ANS;
15461565
LMIC.frame[end+1] = LMIC.margin;
@@ -1565,20 +1584,22 @@ static void buildDataFrame (void) {
15651584
LMIC.adrAckReq = 0;
15661585
LMIC.adrChanged = 0;
15671586
}
1568-
#if !defined(DISABLE_PING)
1587+
#if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING)
15691588
if( LMIC.pingSetAns != 0 ) {
15701589
LMIC.frame[end+0] = MCMD_PING_ANS;
15711590
LMIC.frame[end+1] = LMIC.pingSetAns & ~MCMD_PING_ANS_RFU;
15721591
end += 2;
15731592
LMIC.pingSetAns = 0;
15741593
}
1575-
#endif // !DISABLE_PING
1594+
#endif // !DISABLE_MCMD_PING_SET && !DISABLE_PING
1595+
#if !defined(DISABLE_MCMD_SNCH_REQ)
15761596
if( LMIC.snchAns ) {
15771597
LMIC.frame[end+0] = MCMD_SNCH_ANS;
15781598
LMIC.frame[end+1] = LMIC.snchAns & ~MCMD_SNCH_ANS_RFU;
15791599
end += 2;
15801600
LMIC.snchAns = 0;
15811601
}
1602+
#endif // !DISABLE_MCMD_SNCH_REQ
15821603
ASSERT(end <= OFF_DAT_OPTS+16);
15831604

15841605
u1_t flen = end + (txdata ? 5+dlen : 4);

src/lmic/lmic.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,25 @@ struct lmic_t {
206206
bit_t devsAns; // device status answer pending
207207
u1_t adrEnabled;
208208
u1_t moreData; // NWK has more data pending
209+
#if !defined(DISABLE_MCMD_DCAP_REQ)
209210
bit_t dutyCapAns; // have to ACK duty cycle settings
211+
#endif
212+
#if !defined(DISABLE_MCMD_SNCH_REQ)
210213
u1_t snchAns; // answer set new channel
214+
#endif
211215
// 2nd RX window (after up stream)
212216
u1_t dn2Dr;
213217
u4_t dn2Freq;
218+
#if !defined(DISABLE_MCMD_DN2P_SET)
214219
u1_t dn2Ans; // 0=no answer pend, 0x80+ACKs
220+
#endif
215221

216222
// Class B state
217223
#if !defined(DISABLE_BEACONS)
218224
u1_t missedBcns; // unable to track last N beacons
219225
u1_t bcninfoTries; // how often to try (scan mode only)
220226
#endif
221-
#if !defined(DISABLE_PING)
227+
#if !defined(DISABLE_MCMD_PING_SET) && !defined(DISABLE_PING)
222228
u1_t pingSetAns; // answer set cmd and ACK bits
223229
#endif
224230
#if !defined(DISABLE_PING)

0 commit comments

Comments
 (0)