Skip to content

Commit

Permalink
Fix #2262, separate dispatcher for messages
Browse files Browse the repository at this point in the history
Isolate the message verification and dispatch from the general message
processing.  Functions in the "task" source file now strictly handle the
command content, and do not get involved in general validation.

Also note: this is mostly a simple code move but does add a "const"
qualifier to the task pipe function where it was missing before.  All of
the handlers were already "const".
  • Loading branch information
jphickey committed Mar 23, 2023
1 parent 7c03369 commit 918d433
Show file tree
Hide file tree
Showing 33 changed files with 1,530 additions and 1,187 deletions.
2 changes: 1 addition & 1 deletion modules/core_private/ut-stubs/inc/ut_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MS
** \returns
** This function does not return a value.
******************************************************************************/
void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_Buffer_t *), CFE_MSG_Message_t *MsgPtr, size_t MsgSize,
void UT_CallTaskPipe(void (*TaskPipeFunc)(const CFE_SB_Buffer_t *), const CFE_MSG_Message_t *MsgPtr, size_t MsgSize,
UT_TaskPipeDispatchId_t DispatchId);

/*****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MS
** This first sets up the various stubs according to the test case,
** then invokes the pipe function.
*/
void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_Buffer_t *), CFE_MSG_Message_t *MsgPtr, size_t MsgSize,
void UT_CallTaskPipe(void (*TaskPipeFunc)(const CFE_SB_Buffer_t *), const CFE_MSG_Message_t *MsgPtr, size_t MsgSize,
UT_TaskPipeDispatchId_t DispatchId)
{
union
Expand Down
1 change: 1 addition & 0 deletions modules/es/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(es_SOURCES
fsw/src/cfe_es_backgroundtask.c
fsw/src/cfe_es_cds.c
fsw/src/cfe_es_cds_mempool.c
fsw/src/cfe_es_dispatch.c
fsw/src/cfe_es_erlog.c
fsw/src/cfe_es_generic_pool.c
fsw/src/cfe_es_mempool.c
Expand Down
285 changes: 285 additions & 0 deletions modules/es/fsw/src/cfe_es_dispatch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* @file
*
* Msg pipe dispatcher routines for CFE ES
*/

/*
* Includes
*/
#include "cfe_es_module_all.h"

#include "cfe_version.h"
#include "target_config.h"
#include "cfe_es_verify.h"

#include "cfe_config.h"

#include <string.h>

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
bool CFE_ES_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length
*/
if (ExpectedLength != ActualLength)
{
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength,
(unsigned int)ExpectedLength);
result = false;
CFE_ES_Global.TaskData.CommandErrorCounter++;
}

return result;
}

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
{
/*
** Housekeeping telemetry request
*/
case CFE_ES_SEND_HK_MID:
CFE_ES_HousekeepingCmd((CFE_ES_SendHkCmd_t *)SBBufPtr);
break;

/*
** ES task ground commands
*/
case CFE_ES_CMD_MID:

CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);
switch (CommandCode)
{
case CFE_ES_NOOP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t)))
{
CFE_ES_NoopCmd((CFE_ES_NoopCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESET_COUNTERS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t)))
{
CFE_ES_ResetCountersCmd((CFE_ES_ResetCountersCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESTART_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t)))
{
CFE_ES_RestartCmd((CFE_ES_RestartCmd_t *)SBBufPtr);
}
break;

case CFE_ES_START_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t)))
{
CFE_ES_StartAppCmd((CFE_ES_StartAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_STOP_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t)))
{
CFE_ES_StopAppCmd((CFE_ES_StopAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESTART_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t)))
{
CFE_ES_RestartAppCmd((CFE_ES_RestartAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RELOAD_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t)))
{
CFE_ES_ReloadAppCmd((CFE_ES_ReloadAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ONE_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t)))
{
CFE_ES_QueryOneCmd((CFE_ES_QueryOneCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ALL_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t)))
{
CFE_ES_QueryAllCmd((CFE_ES_QueryAllCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ALL_TASKS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t)))
{
CFE_ES_QueryAllTasksCmd((CFE_ES_QueryAllTasksCmd_t *)SBBufPtr);
}
break;

case CFE_ES_CLEAR_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t)))
{
CFE_ES_ClearSysLogCmd((CFE_ES_ClearSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_WRITE_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t)))
{
CFE_ES_WriteSysLogCmd((CFE_ES_WriteSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_OVER_WRITE_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t)))
{
CFE_ES_OverWriteSysLogCmd((CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_CLEAR_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t)))
{
CFE_ES_ClearERLogCmd((CFE_ES_ClearERLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_WRITE_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t)))
{
CFE_ES_WriteERLogCmd((CFE_ES_WriteERLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_START_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t)))
{
CFE_ES_StartPerfDataCmd((CFE_ES_StartPerfDataCmd_t *)SBBufPtr);
}
break;

case CFE_ES_STOP_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t)))
{
CFE_ES_StopPerfDataCmd((CFE_ES_StopPerfDataCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_PERF_FILTER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t)))
{
CFE_ES_SetPerfFilterMaskCmd((CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_PERF_TRIGGER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t)))
{
CFE_ES_SetPerfTriggerMaskCmd((CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESET_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t)))
{
CFE_ES_ResetPRCountCmd((CFE_ES_ResetPRCountCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_MAX_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t)))
{
CFE_ES_SetMaxPRCountCmd((CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr);
}
break;

case CFE_ES_DELETE_CDS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t)))
{
CFE_ES_DeleteCDSCmd((CFE_ES_DeleteCDSCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SEND_MEM_POOL_STATS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t)))
{
CFE_ES_SendMemPoolStatsCmd((CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr);
}
break;

case CFE_ES_DUMP_CDS_REGISTRY_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t)))
{
CFE_ES_DumpCDSRegistryCmd((CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr);
}
break;

default:
CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ground command code: ID = 0x%X, CC = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode);
CFE_ES_Global.TaskData.CommandErrorCounter++;
break;
}
break;

default:

CFE_EVS_SendEvent(CFE_ES_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%X",
(unsigned int)CFE_SB_MsgIdToValue(MessageID));
CFE_ES_Global.TaskData.CommandErrorCounter++;
break;
}
}
44 changes: 44 additions & 0 deletions modules/es/fsw/src/cfe_es_dispatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* @file
*
* cFE Executive Services (ES) dispatch header file
*
*/

#ifndef CFE_ES_DISPATCH_H
#define CFE_ES_DISPATCH_H

/*
** Includes
*/
#include "common_types.h"

#include "cfe_es_api_typedefs.h"
#include "cfe_sb_api_typedefs.h"
#include "cfe_msg_api_typedefs.h"

/*---------------------------------------------------------------------------------------*/
/**
* Reads and processes messages from the executive services command pipe
*/
void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr);

#endif /* CFE_ES_DISPATCH_H */
1 change: 1 addition & 0 deletions modules/es/fsw/src/cfe_es_module_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "cfe_es_events.h"
#include "cfe_es_start.h"
#include "cfe_es_task.h"
#include "cfe_es_dispatch.h"
#include "cfe_es_resource.h"
#include "cfe_es_log.h"

Expand Down
Loading

0 comments on commit 918d433

Please sign in to comment.