Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #745 - getlastsenderid now returns appid #750

Closed
Closed
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
27 changes: 4 additions & 23 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,6 @@ typedef struct {
extern CFE_SB_Qos_t CFE_SB_Default_Qos;/**< \brief Defines a default priority and reliabilty for off-board routing */


/** \brief Message Sender Identification Type Definition
**
** Parameter used in #CFE_SB_GetLastSenderId API which allows the receiver of a message
** to validate the sender of the message.
**/
typedef struct {
uint32 ProcessorId;/**< \brief Processor Id from which the message was sent */
char AppName[OS_MAX_API_NAME];/**< \brief Application that sent the message */
} CFE_SB_SenderId_t;

/****************** Function Prototypes **********************/

/** @defgroup CFEAPISBPipe cFE Pipe Management APIs
Expand Down Expand Up @@ -1186,23 +1176,14 @@ CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr);
** random. Therefore, it is recommended that the return code be tested
** for CFE_SUCCESS before reading the sender information.
**
** \param[in] Ptr A pointer to a local variable of type #CFE_SB_SenderId_t.
** Typically a caller declares a ptr of type CFE_SB_SenderId_t
** (i.e. CFE_SB_SenderId_t *Ptr) then gives the address of that
** pointer (&Ptr) for this parameter. After a successful call
** to this API, *Ptr will point to the first byte of the
** CFE_SB_SenderId_t structure containing the sender information
** for the last message received on the given pipe. This should
** be used as a read-only pointer (in systems with an MMU, writes
** to this pointer may cause a memory protection fault). The *Ptr
** is valid only until the next call to CFE_SB_RcvMsg for the
** same pipe.
** \param[out] SenderAppIdPtr A pointer to a buffer to receive the AppId of
** the last sender.
**
** \param[in] PipeId The pipe ID of the pipe the message was taken from.
**
** \return The last sender's application ID
** \return CFE_SUCCESS
**/
uint32 CFE_SB_GetLastSenderId(CFE_SB_SenderId_t **Ptr,CFE_SB_PipeId_t PipeId);
int32 CFE_SB_GetLastSenderId(uint32 *AppIdPtr, CFE_SB_PipeId_t PipeId);

/******************************************************************************/
/**
Expand Down
41 changes: 11 additions & 30 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,13 +1320,6 @@ int32 CFE_SB_SendMsgFull(CFE_SB_Msg_t *MsgPtr,
RtgTblPtr->SeqCnt);
}/* end if */

/* store the sender information */
if(CFE_SB.SenderReporting != 0)
{
BufDscPtr->Sender.ProcessorId = CFE_PSP_GetProcessorId();
strncpy(&BufDscPtr->Sender.AppName[0],CFE_SB_GetAppTskName(TskId,FullName),OS_MAX_API_NAME);
}

/* At this point there must be at least one destination for pkt */

/* Send the packet to all destinations */
Expand All @@ -1347,6 +1340,8 @@ int32 CFE_SB_SendMsgFull(CFE_SB_Msg_t *MsgPtr,

PipeDscPtr = &CFE_SB.PipeTbl[DestPtr->PipeId];

PipeDscPtr->LastSender = CFE_SB.AppId;

if(PipeDscPtr->Opts & CFE_SB_PIPEOPTS_IGNOREMINE)
{
uint32 AppId = 0xFFFFFFFF;
Expand Down Expand Up @@ -1623,19 +1618,20 @@ int32 CFE_SB_RcvMsg(CFE_SB_MsgPtr_t *BufPtr,
/*
* Function: CFE_SB_GetLastSenderId - See API and header file for details
*/
uint32 CFE_SB_GetLastSenderId(CFE_SB_SenderId_t **Ptr,CFE_SB_PipeId_t PipeId)
int32 CFE_SB_GetLastSenderId(uint32 *SenderAppIdPtr, CFE_SB_PipeId_t PipeId)
{

CFE_SB_BufferD_t *Ptr2BufDescriptor;
uint32 TskId = 0;
uint32 AppId = 0xFFFFFFFF;
char FullName[(OS_MAX_API_NAME * 2)];

TskId = OS_TaskGetId();

CFE_ES_GetAppID(&AppId);

/* validate ptr - note: must validate ptr before pipe id validation */
/* because an invalid pipe id sets the callers pointer to NULL */
if(Ptr == NULL){
if(SenderAppIdPtr == NULL){
CFE_EVS_SendEventWithAppID(CFE_SB_LSTSNDER_ERR1_EID,CFE_EVS_EventType_ERROR,CFE_SB.AppId,
"SB GetLastSender Err:Rcvd Null Ptr,Pipe=%d,App=%s",
(int)PipeId,CFE_SB_GetAppTskName(TskId,FullName));
Expand All @@ -1644,45 +1640,30 @@ uint32 CFE_SB_GetLastSenderId(CFE_SB_SenderId_t **Ptr,CFE_SB_PipeId_t PipeId)

/* validate pipe id */
if(CFE_SB_ValidatePipeId(PipeId)!=CFE_SUCCESS){
*Ptr = NULL;
*SenderAppIdPtr = 0;
CFE_EVS_SendEventWithAppID(CFE_SB_LSTSNDER_ERR2_EID,CFE_EVS_EventType_ERROR,CFE_SB.AppId,
"SB GetLastSender Err:Rcvd Invalid Pipe=%d,App=%s",
(int)PipeId,CFE_SB_GetAppTskName(TskId,FullName));
return CFE_SB_BAD_ARGUMENT;
}/* end if */

CFE_ES_GetAppID(&AppId);

CFE_SB_LockSharedData(__func__,__LINE__);

/* verify requestor is owner of pipe */
if(CFE_SB.PipeTbl[PipeId].AppId != AppId){
*Ptr = NULL;
*SenderAppIdPtr = 0;
CFE_SB_UnlockSharedData(__func__,__LINE__);
CFE_EVS_SendEventWithAppID(CFE_SB_GLS_INV_CALLER_EID,CFE_EVS_EventType_ERROR,CFE_SB.AppId,
"SB GetLastSender Err:Caller(%s) is not the owner of pipe %d",
CFE_SB_GetAppTskName(TskId,FullName),(int)PipeId);
return CFE_SB_BAD_ARGUMENT;
}/* end if */

/* Get ptr to buffer descriptor for the last msg received on the given pipe */
Ptr2BufDescriptor = CFE_SB.PipeTbl[PipeId].CurrentBuff;
*SenderAppIdPtr = CFE_SB.PipeTbl[PipeId].LastSender;

if ( Ptr2BufDescriptor == NULL )
{
*Ptr = NULL;
CFE_SB.PipeTbl[PipeId].LastSender = CFE_SB_INVALID_MSG_ID;
CFE_SB_UnlockSharedData(__func__,__LINE__);
return CFE_SB_NO_MSG_RECV;
}
else
{
/* Set the receivers pointer to the adr of 'Sender' struct in buf descriptor */
*Ptr = (CFE_SB_SenderId_t *) &Ptr2BufDescriptor -> Sender;
CFE_SB_UnlockSharedData(__func__,__LINE__);
return CFE_SUCCESS;
}
CFE_SB_UnlockSharedData(__func__,__LINE__);

return CFE_SUCCESS;
}/* end CFE_SB_GetLastSenderId */


Expand Down
1 change: 0 additions & 1 deletion fsw/cfe-core/src/sb/cfe_sb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ typedef struct {
uint16 UseCount;
uint32 Size;
void *Buffer;
CFE_SB_SenderId_t Sender;
} CFE_SB_BufferD_t;


Expand Down
16 changes: 8 additions & 8 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3432,12 +3432,12 @@ void Test_RcvMsg_GetLastSenderInvalidPipe(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_PipeId_t InvalidPipeId = 250;
CFE_SB_SenderId_t *GLSPtr;
uint32 AppId;
uint32 PipeDepth = 10;

SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "RcvMsgTestPipe"));

ASSERT_EQ(CFE_SB_GetLastSenderId(&GLSPtr, InvalidPipeId), CFE_SB_BAD_ARGUMENT);
ASSERT_EQ(CFE_SB_GetLastSenderId(&AppId, InvalidPipeId), CFE_SB_BAD_ARGUMENT);

EVTCNT(2);

Expand All @@ -3453,7 +3453,7 @@ void Test_RcvMsg_GetLastSenderInvalidPipe(void)
void Test_RcvMsg_GetLastSenderInvalidCaller(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_SenderId_t *GLSPtr;
uint32 AppId;
uint32 PipeDepth = 10;
uint32 OrigPipeOwner;

Expand All @@ -3462,7 +3462,7 @@ void Test_RcvMsg_GetLastSenderInvalidCaller(void)
/* Change pipe owner ID to execute 'invalid caller' code */
OrigPipeOwner = CFE_SB.PipeTbl[PipeId].AppId;
CFE_SB.PipeTbl[PipeId].AppId = OrigPipeOwner + 1;
ASSERT_EQ(CFE_SB_GetLastSenderId(&GLSPtr, PipeId), CFE_SB_BAD_ARGUMENT);
ASSERT_EQ(CFE_SB_GetLastSenderId(&AppId, PipeId), CFE_SB_BAD_ARGUMENT);

EVTCNT(2);

Expand All @@ -3478,11 +3478,11 @@ void Test_RcvMsg_GetLastSenderInvalidCaller(void)
void Test_RcvMsg_GetLastSenderNoValidSender(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_SenderId_t *GLSPtr;
uint32 AppId;
uint32 PipeDepth = 10;

SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "RcvMsgTestPipe"));
ASSERT_EQ(CFE_SB_GetLastSenderId(&GLSPtr, PipeId), CFE_SB_NO_MSG_RECV);
ASSERT_EQ(CFE_SB_GetLastSenderId(&AppId, PipeId), CFE_SB_NO_MSG_RECV);

EVTCNT(1);

Expand All @@ -3497,7 +3497,7 @@ void Test_RcvMsg_GetLastSenderNoValidSender(void)
void Test_RcvMsg_GetLastSenderSuccess(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_SenderId_t *GLSPtr;
uint32 AppId;
SB_UT_Test_Tlm_t TlmPkt;
CFE_SB_MsgPtr_t TlmPktPtr = (CFE_SB_MsgPtr_t) &TlmPkt;
CFE_SB_MsgPtr_t PtrToMsg;
Expand All @@ -3508,7 +3508,7 @@ void Test_RcvMsg_GetLastSenderSuccess(void)
SETUP(CFE_SB_Subscribe(SB_UT_TLM_MID, PipeId));
SETUP(CFE_SB_SendMsg(TlmPktPtr));
SETUP(CFE_SB_RcvMsg(&PtrToMsg, PipeId,CFE_SB_PEND_FOREVER));
ASSERT(CFE_SB_GetLastSenderId(&GLSPtr, PipeId));
ASSERT(CFE_SB_GetLastSenderId(&AppId, PipeId));

EVTCNT(3);

Expand Down