Skip to content

Commit

Permalink
Fix #75, Moved command validation out of command functions
Browse files Browse the repository at this point in the history
  • Loading branch information
havencarlson committed Jun 28, 2023
1 parent e76c2d3 commit b8e9628
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 436 deletions.
129 changes: 59 additions & 70 deletions fsw/src/mm_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ void MM_AppPipe(const CFE_SB_Buffer_t *BufPtr)
** Housekeeping telemetry request
*/
case MM_SEND_HK_MID:
MM_HousekeepingCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_NoArgsCmd_t)))
{
MM_HousekeepingCmd(BufPtr);
}
break;

/*
Expand All @@ -253,55 +256,94 @@ void MM_AppPipe(const CFE_SB_Buffer_t *BufPtr)
switch (CommandCode)
{
case MM_NOOP_CC:
CmdResult = MM_NoopCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_NoArgsCmd_t)))
{
CmdResult = MM_NoopCmd(BufPtr);
}
break;

case MM_RESET_CC:
CmdResult = MM_ResetCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_NoArgsCmd_t)))
{
CmdResult = MM_ResetCmd(BufPtr);
}
break;

case MM_PEEK_CC:
CmdResult = MM_PeekCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_PeekCmd_t)))
{
CmdResult = MM_PeekCmd(BufPtr);
}
break;

case MM_POKE_CC:
CmdResult = MM_PokeCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_PokeCmd_t)))
{
CmdResult = MM_PokeCmd(BufPtr);
}
break;

case MM_LOAD_MEM_WID_CC:
CmdResult = MM_LoadMemWIDCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_LoadMemWIDCmd_t)))
{
CmdResult = MM_LoadMemWIDCmd(BufPtr);
}
break;

case MM_LOAD_MEM_FROM_FILE_CC:
CmdResult = MM_LoadMemFromFileCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_LoadMemFromFileCmd_t)))
{
CmdResult = MM_LoadMemFromFileCmd(BufPtr);
}
break;

case MM_DUMP_MEM_TO_FILE_CC:
CmdResult = MM_DumpMemToFileCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_DumpMemToFileCmd_t)))
{
CmdResult = MM_DumpMemToFileCmd(BufPtr);
}
break;

case MM_DUMP_IN_EVENT_CC:
CmdResult = MM_DumpInEventCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_DumpInEventCmd_t)))
{
CmdResult = MM_DumpInEventCmd(BufPtr);
}
break;

case MM_FILL_MEM_CC:
CmdResult = MM_FillMemCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_FillMemCmd_t)))
{
CmdResult = MM_FillMemCmd(BufPtr);
}
break;

case MM_LOOKUP_SYM_CC:
CmdResult = MM_LookupSymbolCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_LookupSymCmd_t)))
{
CmdResult = MM_LookupSymbolCmd(BufPtr);
}
break;

case MM_SYMTBL_TO_FILE_CC:
CmdResult = MM_SymTblToFileCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_SymTblToFileCmd_t)))
{
CmdResult = MM_SymTblToFileCmd(BufPtr);
}
break;

case MM_ENABLE_EEPROM_WRITE_CC:
CmdResult = MM_EepromWriteEnaCmd(BufPtr);
case MM_ENABLE_EEPROM_WRITE_CC:
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_EepromWriteEnaCmd_t)))
{
CmdResult = MM_EepromWriteEnaCmd(BufPtr);
}
break;

case MM_DISABLE_EEPROM_WRITE_CC:
CmdResult = MM_EepromWriteDisCmd(BufPtr);
if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_EepromWriteDisCmd_t)))
{
CmdResult = MM_EepromWriteDisCmd(BufPtr);
}
break;

default:
Expand Down Expand Up @@ -344,13 +386,6 @@ void MM_AppPipe(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void MM_HousekeepingCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(MM_NoArgsCmd_t);

/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
/*
** Send housekeeping telemetry packet
*/
Expand All @@ -360,8 +395,6 @@ void MM_HousekeepingCmd(const CFE_SB_Buffer_t *BufPtr)
/*
** This command does not affect the command execution counter
*/

} /* end if */
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -371,19 +404,13 @@ void MM_HousekeepingCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(MM_NoArgsCmd_t);
bool Result = false;
/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{

MM_AppData.HkPacket.LastAction = MM_NOOP;
Result = true;

CFE_EVS_SendEvent(MM_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command. Version %d.%d.%d.%d",
MM_MAJOR_VERSION, MM_MINOR_VERSION, MM_REVISION, MM_MISSION_REV);
}

return Result;
}
Expand All @@ -395,20 +422,14 @@ bool MM_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_ResetCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(MM_NoArgsCmd_t);
bool Result = false;
/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{

MM_AppData.HkPacket.LastAction = MM_RESET;
MM_AppData.HkPacket.CmdCounter = 0;
MM_AppData.HkPacket.ErrCounter = 0;

CFE_EVS_SendEvent(MM_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "Reset counters command received");
Result = true;
}

return Result;
}
Expand All @@ -423,15 +444,9 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
cpuaddr ResolvedAddr = 0;
const MM_LookupSymCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_LookupSymCmd_t);
bool Result = false;
char SymName[OS_MAX_SYM_LEN];

/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_LookupSymCmd_t *)BufPtr);

/* Make sure string is null terminated before attempting to process it */
Expand Down Expand Up @@ -469,8 +484,6 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)

} /* end strlen(CmdPtr->SymName) == 0 else */

} /* end MM_VerifyCmdLength if */

return Result;
}

Expand All @@ -484,14 +497,8 @@ bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr)
int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */
char FileName[OS_MAX_PATH_LEN];
const MM_SymTblToFileCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_SymTblToFileCmd_t);
bool Result = false;

/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_SymTblToFileCmd_t *)BufPtr);

/* Make sure string is null terminated before attempting to process it */
Expand Down Expand Up @@ -527,8 +534,6 @@ bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr)

} /* end strlen(FileName) == 0 else */

} /* end MM_VerifyCmdLength if */

return Result;
}

Expand All @@ -541,14 +546,8 @@ bool MM_EepromWriteEnaCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */
MM_EepromWriteEnaCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_EepromWriteEnaCmd_t);
bool Result = false;

/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_EepromWriteEnaCmd_t *)BufPtr);

/*
Expand All @@ -573,8 +572,6 @@ bool MM_EepromWriteEnaCmd(const CFE_SB_Buffer_t *BufPtr)
(unsigned int)cFE_Status);
}

} /* end MM_VerifyCmdLength if */

return Result;
}

Expand All @@ -587,14 +584,8 @@ bool MM_EepromWriteDisCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */
MM_EepromWriteDisCmd_t *CmdPtr = NULL;
size_t ExpectedLength = sizeof(MM_EepromWriteDisCmd_t);
bool Result = false;

/*
** Verify command packet length
*/
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_EepromWriteDisCmd_t *)BufPtr);

/*
Expand All @@ -618,7 +609,5 @@ bool MM_EepromWriteDisCmd(const CFE_SB_Buffer_t *BufPtr)
(unsigned int)cFE_Status);
}

} /* end MM_VerifyCmdLength if */

return Result;
}
18 changes: 0 additions & 18 deletions fsw/src/mm_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr)
bool Valid;
const MM_PeekCmd_t *CmdPtr;
cpuaddr SrcAddress = 0;
size_t ExpectedLength = sizeof(MM_PeekCmd_t);
bool Result = false;
MM_SymAddr_t SrcSymAddress;

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_PeekCmd_t *)BufPtr);

SrcSymAddress = CmdPtr->SrcSymAddress;
Expand Down Expand Up @@ -86,8 +82,6 @@ bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr)
"Symbolic address can't be resolved: Name = '%s'", CmdPtr->SrcSymAddress.SymName);
}

} /* end MM_VerifyCmdLength if */

return Result;
}

Expand Down Expand Up @@ -198,11 +192,7 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
const MM_DumpMemToFileCmd_t *CmdPtr;
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
size_t ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_DumpMemToFileCmd_t *)BufPtr);

SrcSymAddress = CmdPtr->SrcSymAddress;
Expand Down Expand Up @@ -361,8 +351,6 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}

} /* end MM_VerifyCmdLength if */

return Valid;
}

Expand Down Expand Up @@ -483,7 +471,6 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
uint32 i;
int32 EventStringTotalLength = 0;
cpuaddr SrcAddress = 0;
size_t ExpectedLength = sizeof(MM_DumpInEventCmd_t);
uint8 * BytePtr;
char TempString[MM_DUMPINEVENT_TEMP_CHARS];
const char HeaderString[] = "Memory Dump: ";
Expand All @@ -497,9 +484,6 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
*/
uint32 DumpBuffer[(MM_MAX_DUMP_INEVENT_BYTES + 3) / 4];

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_DumpInEventCmd_t *)BufPtr);

SrcSymAddress = CmdPtr->SrcSymAddress;
Expand Down Expand Up @@ -567,8 +551,6 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}

} /* end MM_VerifyCmdLength if */

return Valid;
}

Expand Down
Loading

0 comments on commit b8e9628

Please sign in to comment.