Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4218,14 +4218,15 @@ bool mspFCProcessInOutCommand(uint16_t cmdMSP, sbuf_t *dst, sbuf_t *src, mspResu
break;
#endif

#ifdef USE_BARO
#ifdef USE_GPS
case MSP2_INAV_SET_ALT_TARGET:
if (dataSize != (sizeof(int32_t) + sizeof(uint8_t))) {
Comment on lines +4221 to 4223
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Msp set_alt gps-gated 🐞 Bug ≡ Correctness

MSP2_INAV_SET_ALT_TARGET is now compiled only when USE_GPS is defined, which removes MSP
altitude-target control from barometer-only builds. This is a functional regression because
navigationSetAltitudeTargetWithDatum() supports NAV_WP_TAKEOFF_DATUM without requiring GPS
origin.
Agent Prompt
### Issue description
`MSP2_INAV_SET_ALT_TARGET` is now wrapped in `#ifdef USE_GPS`, which disables MSP altitude-target changes for barometer-only builds even though `navigationSetAltitudeTargetWithDatum()` supports `NAV_WP_TAKEOFF_DATUM` without GPS.

### Issue Context
`navigationSetAltitudeTargetWithDatum()` only requires `posControl.gpsOrigin.valid` for the MSL datum path; the takeoff datum path is GPS-independent. Also, altitude estimation can be valid without a GPS fix.

### Fix Focus Areas
- Update the compile guard to allow non-GPS altitude sources (e.g., `#if defined(USE_BARO) || defined(USE_GPS)`), or otherwise ensure the handler is available whenever `navigationSetAltitudeTargetWithDatum()` is linked.

- src/main/fc/fc_msp.c[4221-4236]
- src/main/navigation/navigation.c[5204-5236]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

*ret = MSP_RESULT_ERROR;
break;
}

if (navigationSetAltitudeTargetWithDatum((geoAltitudeDatumFlag_e)sbufReadU8(src), (int32_t)sbufReadU32(src))) {
uint8_t setAltDatum = (geoAltitudeDatumFlag_e)sbufReadU8(src);
int32_t setNewAlt = sbufReadU32(src);
if (navigationSetAltitudeTargetWithDatum(setAltDatum, setNewAlt)) {
Comment on lines +4227 to +4229
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. setnewalt lacks validation 📘 Rule violation ≡ Correctness

The MSP handler assigns sbufReadU32(src) into int32_t setNewAlt without validating it fits in
int32_t, so a crafted payload can trigger implementation-defined signed conversion rather than a
deterministic error. External input fields (setAltDatum, altitude) should be range/enum-validated
before use and rejected with a specific error result.
Agent Prompt
## Issue description
`MSP2_INAV_SET_ALT_TARGET` reads external payload fields (`datum`, `altitude`) but does not validate that `sbufReadU32()` fits into `int32_t` (deterministic failure) and does not validate `datum` values before calling `navigationSetAltitudeTargetWithDatum`.

## Issue Context
C signed conversion from an out-of-range `uint32_t` to `int32_t` is implementation-defined, which violates the requirement to handle malformed inputs deterministically.

## Fix Focus Areas
- src/main/fc/fc_msp.c[4227-4229]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

*ret = MSP_RESULT_ACK;
break;
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/navigation/navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -5204,7 +5204,14 @@ bool navigationIsControllingAltitude(void) {
bool navigationSetAltitudeTargetWithDatum(geoAltitudeDatumFlag_e datumFlag, int32_t targetAltitudeCm)
{
const navigationFSMStateFlags_t stateFlags = navGetCurrentStateFlags();
if (!(stateFlags & NAV_CTL_ALT) || (stateFlags & NAV_CTL_LAND) || navigationIsExecutingAnEmergencyLanding() || posControl.flags.estAltStatus == EST_NONE) {
if (!(stateFlags & NAV_CTL_ALT) ||
(stateFlags & NAV_CTL_LAND) ||
navigationIsExecutingAnEmergencyLanding() ||
posControl.flags.estAltStatus == EST_NONE ||
(stateFlags & NAV_MIXERAT) ||
FLIGHT_MODE(NAV_FW_AUTOLAND) ||
FLIGHT_MODE(NAV_SEND_TO) ||
((stateFlags & NAV_AUTO_RTH) && posControl.navState != NAV_STATE_RTH_HEAD_HOME)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/telemetry/mavlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ static bool handleIncoming_COMMAND_INT(void)
mavlinkSendMessage();
}
} else {
#ifdef USE_BARO
#ifdef USE_GPS
if (msg.command == MAV_CMD_DO_CHANGE_ALTITUDE) {
const float altitudeMeters = msg.param1;
const uint8_t frame = (uint8_t)msg.frame;
Comment on lines +1218 to 1221
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Mavlink set_alt gps-gated 🐞 Bug ≡ Correctness

MAV_CMD_DO_CHANGE_ALTITUDE handling is now compiled only when USE_GPS is defined, causing
barometer-only builds to always respond UNSUPPORTED to altitude-change commands. This breaks the
MAV_FRAME_GLOBAL_RELATIVE_ALT path which maps to takeoff datum and does not require GPS origin.
Agent Prompt
### Issue description
`MAV_CMD_DO_CHANGE_ALTITUDE` support is now wrapped in `#ifdef USE_GPS`, which disables the command even for takeoff-datum (relative altitude) changes that do not require GPS origin.

### Issue Context
The MAVLink handler maps `MAV_FRAME_GLOBAL_RELATIVE_ALT` / `_INT` to `NAV_WP_TAKEOFF_DATUM` and then calls `navigationSetAltitudeTargetWithDatum()`. That navigation function only requires GPS origin for MSL datum.

### Fix Focus Areas
- Change the compile guard to include barometer-only builds (e.g., `#if defined(USE_BARO) || defined(USE_GPS)`) or otherwise align it with when altitude control is available.

- src/main/telemetry/mavlink.c[1218-1257]
- src/main/navigation/navigation.c[5204-5236]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Expand Down
Loading