Skip to content

Commit 60934e1

Browse files
committed
Fix #420: slim code, don't respond to unimplemented cmds
1 parent e4571f4 commit 60934e1

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/lmic/lmic.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,8 @@ scan_mac_cmds(
923923
break;
924924
}
925925

926-
case MCMD_RXParamSetupReq: {
927926
#if !defined(DISABLE_MCMD_RXParamSetupReq)
927+
case MCMD_RXParamSetupReq: {
928928
dr_t dr = (dr_t)(opts[oidx+1] & 0x0F);
929929
u1_t rx1DrOffset = (u1_t)((opts[oidx+1] & 0x70) >> 4);
930930
u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]);
@@ -946,36 +946,37 @@ scan_mac_cmds(
946946

947947
/* put the first copy of the message */
948948
response_fit = put_mac_uplink_byte2(MCMD_RXParamSetupAns, LMIC.dn2Ans & ~MCMD_RXParamSetupAns_RFU);
949-
#endif // !DISABLE_MCMD_RXParamSetupReq
950949
break;
951950
}
951+
#endif // !DISABLE_MCMD_RXParamSetupReq
952952

953-
case MCMD_RXTimingSetupReq: {
954953
#if !defined(DISABLE_MCMD_RXTimingSetupReq)
954+
case MCMD_RXTimingSetupReq: {
955955
u1_t delay = opts[oidx+1] & MCMD_RXTimingSetupReq_Delay;
956956
if (delay == 0)
957957
delay = 1;
958958

959959
LMIC.rxDelay = delay;
960960
LMIC.macRxTimingSetupAns = 2;
961961
response_fit = put_mac_uplink_byte(MCMD_RXTimingSetupAns);
962-
#endif // !DISABLE_MCMD_RXTimingSetupReq
963962
break;
964963
}
965-
case MCMD_DutyCycleReq: {
964+
#endif // !DISABLE_MCMD_RXTimingSetupReq
965+
966966
#if !defined(DISABLE_MCMD_DutyCycleReq)
967+
case MCMD_DutyCycleReq: {
967968
u1_t cap = opts[oidx+1];
968969
LMIC.globalDutyRate = cap & 0xF;
969970
LMIC.globalDutyAvail = os_getTime();
970971
DO_DEVDB(cap,dutyCap);
971972

972973
response_fit = put_mac_uplink_byte(MCMD_DutyCycleAns);
973-
#endif // !DISABLE_MCMD_DutyCycleReq
974974
break;
975975
}
976+
#endif // !DISABLE_MCMD_DutyCycleReq
976977

977-
case MCMD_NewChannelReq: {
978978
#if !defined(DISABLE_MCMD_NewChannelReq) && CFG_LMIC_EU_like
979+
case MCMD_NewChannelReq: {
979980
u1_t chidx = opts[oidx+1]; // channel
980981
u4_t raw_f_not_zero = opts[oidx+2] | opts[oidx+3] | opts[oidx+4];
981982
u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]); // freq
@@ -999,12 +1000,12 @@ scan_mac_cmds(
9991000
}
10001001

10011002
response_fit = put_mac_uplink_byte2(MCMD_NewChannelAns, ans);
1002-
#endif // !DISABLE_MCMD_NewChannelReq
10031003
break;
10041004
}
1005+
#endif // !DISABLE_MCMD_NewChannelReq
10051006

1006-
case MCMD_DlChannelReq: {
10071007
#if !defined(DISABLE_MCMD_DlChannelReq) && CFG_LMIC_EU_like
1008+
case MCMD_DlChannelReq: {
10081009
u1_t chidx = opts[oidx+1]; // channel
10091010
u4_t freq = LMICbandplan_convFreq(&opts[oidx+2]); // freq
10101011
u1_t ans = MCMD_DlChannelAns_FreqACK|MCMD_DlChannelAns_ChannelACK;
@@ -1027,12 +1028,12 @@ scan_mac_cmds(
10271028
response_fit = put_mac_uplink_byte2(MCMD_DlChannelAns, ans);
10281029
// set sticky answer.
10291030
LMIC.macDlChannelAns = ans | 0xC0;
1030-
#endif // !DISABLE_MCMD_DlChannelReq
10311031
break;
10321032
}
1033+
#endif // !DISABLE_MCMD_DlChannelReq
10331034

1034-
case MCMD_PingSlotChannelReq: {
10351035
#if !defined(DISABLE_MCMD_PingSlotChannelReq) && !defined(DISABLE_PING)
1036+
case MCMD_PingSlotChannelReq: {
10361037
u4_t raw_f_not_zero = opts[oidx+1] | opts[oidx+2] | opts[oidx+3];
10371038
u4_t freq = LMICbandplan_convFreq(&opts[oidx+1]);
10381039
u1_t dr = opts[oidx+4] & 0xF;
@@ -1053,12 +1054,12 @@ scan_mac_cmds(
10531054
DO_DEVDB(LMIC.ping.dr, pingDr);
10541055
}
10551056
response_fit = put_mac_uplink_byte2(MCMD_PingSlotChannelAns, ans);
1056-
#endif // !DISABLE_MCMD_PingSlotChannelReq && !DISABLE_PING
10571057
break;
10581058
}
1059+
#endif // !DISABLE_MCMD_PingSlotChannelReq && !DISABLE_PING
10591060

1060-
case MCMD_BeaconTimingAns: {
10611061
#if defined(ENABLE_MCMD_BeaconTimingAns) && !defined(DISABLE_BEACONS)
1062+
case MCMD_BeaconTimingAns: {
10621063
// Ignore if tracking already enabled
10631064
if( (LMIC.opmode & OP_TRACK) == 0 ) {
10641065
LMIC.bcnChnl = opts[oidx+3];
@@ -1082,12 +1083,12 @@ scan_mac_cmds(
10821083
- LMIC.bcnRxtime) << 8)),
10831084
e_.time = MAIN::CDEV->ostime2ustime(LMIC.bcninfo.txtime + BCN_INTV_osticks)));
10841085
}
1085-
#endif // !ENABLE_MCMD_BeaconTimingAns && !DISABLE_BEACONS
10861086
break;
10871087
} /* end case */
1088+
#endif // !ENABLE_MCMD_BeaconTimingAns && !DISABLE_BEACONS
10881089

1089-
case MCMD_TxParamSetupReq: {
10901090
#if LMIC_ENABLE_TxParamSetupReq
1091+
case MCMD_TxParamSetupReq: {
10911092
uint8_t txParam;
10921093
txParam = opts[oidx+1];
10931094

@@ -1097,12 +1098,12 @@ scan_mac_cmds(
10971098
MCMD_TxParam_MaxEIRP_MASK);
10981099
LMIC.txParam = txParam;
10991100
response_fit = put_mac_uplink_byte(MCMD_TxParamSetupAns);
1100-
#endif // LMIC_ENABLE_TxParamSetupReq
11011101
break;
11021102
} /* end case */
1103+
#endif // LMIC_ENABLE_TxParamSetupReq
11031104

1104-
case MCMD_DeviceTimeAns: {
11051105
#if LMIC_ENABLE_DeviceTimeReq
1106+
case MCMD_DeviceTimeAns: {
11061107
// don't process a spurious downlink.
11071108
if ( LMIC.txDeviceTimeReqState == lmic_RequestTimeState_rx ) {
11081109
// remember that it's time to notify the client.
@@ -1129,9 +1130,9 @@ scan_mac_cmds(
11291130
LMIC_DEBUG_PRINTF("%"LMIC_PRId_ostime_t": MAC command DeviceTimeAns received: seconds_since_gps_epoch=%"PRIu32", fractional_seconds=%d\n", os_getTime(), LMIC.netDeviceTime, LMIC.netDeviceTimeFrac);
11301131
#endif
11311132
}
1132-
#endif // LMIC_ENABLE_DeviceTimeReq
11331133
break;
11341134
} /* end case */
1135+
#endif // LMIC_ENABLE_DeviceTimeReq
11351136

11361137
default: {
11371138
// force olen to current oidx so we'll exit the while()

0 commit comments

Comments
 (0)