/* BEGIN_FILE_HDR ******************************************************************************* * NOTICE * This software is the property of HiRain Technologies. Any information * contained in this doc should not be reproduced, or used, or disclosed * without the written authorization from HiRain Technologies. ******************************************************************************* * File Name : E2E_P07m.c ******************************************************************************* * Project/Product : AUTOSAR R21-11 * Title : End-to-End protect module * Author : Hirain ******************************************************************************* * Description : The source file of the End-to-End module. * ******************************************************************************* * Limitations : None * ******************************************************************************* * ******************************************************************************* * Revision History: * * Version Date Initials CR# Descriptions * --------- ---------- ------------ ---------- --------------- * 04.00.00 11/08/2022 Wenbo.Cui N/A Original ******************************************************************************* * END_FILE_HDR*/ /****************************************************************************** * Includes ******************************************************************************/ #include "E2E_P07m.h" /******************************************************************************* * General QAC Suppression *******************************************************************************/ /*PRQA S 3214,0862,3614 EOF*/ /* According to the requirements of AUTOSAR Specification,when locating address segments in the files of each module,#include "E2E_MemMap.h" is required.Defined XXX_START_SEC_ will undefine in E2E_MemMap.h */ /*PRQA S 3432 EOF*/ /* P2VAR and other macros in the Compiler conforms to AUTOSAR standard.There's no need to revise. */ /***************************************************************************** * E2E QAC Suppression *****************************************************************************/ /*PRQA S 4640,4641 EOF*/ /* Function, macrodefinition is named with a fixed requirement and does not make changes */ /*PRQA S 3429,3453 EOF*/ /* Allow the use of macrofunction access definitions, and the department is verified and there is no problem. */ /*PRQA S 3435,3456 EOF*/ /* Allow multiple use parameters in macros */ /*PRQA S 3383,3384 EOF*/ /* The previously logical judgment of the data is guaranteed that the data value will not overflow */ /****************************************************************************** * Macro ******************************************************************************/ /*header length and offset defined in bytes*/ #define E2E_P07M_HEADER_BYTE_LENGTH ((uint32)24) #define E2E_P07M_CRC_BYTE_LENGTH ((uint16)8) #define E2E_P07M_CRC_OFFSET ((uint32)0) #define E2E_P07M_LENGTH_OFFSET ((uint32)8) #define E2E_P07M_COUNTER_OFFSET ((uint32)12) #define E2E_P07M_DATAID_OFFSET ((uint32)16) #define E2E_P07M_SOURCEID_OFFSET ((uint32)20) #define E2E_P07M_BYTE_OFFSET_BIT ((uint64)8) #define E2E_P07M_TWOBYTE_OFFSET_BIT ((uint64)16) #define E2E_P07M_THRESSBYTE_OFFSET_BIT ((uint64)24) #define E2E_P07M_FOURBYTE_OFFSET_BIT ((uint64)32) #define E2E_P07M_FIVEBYTE_OFFSET_BIT ((uint64)40) #define E2E_P07M_SIXBYTE_OFFSET_BIT ((uint64)48) #define E2E_P07M_SEVENBYTE_OFFSET_BIT ((uint64)56) #define E2E_P07M_BYTE_MASK ((uint8)0xFF) #define E2E_P07M_CRC_INIT_VALUE ((uint64)0xFFFFFFFFFFFFFFFF) #define E2E_P07M_INDEX_2 (2) #define E2E_P07M_INDEX_3 (3) #define E2E_P07M_INDEX_4 (4) #define E2E_P07M_INDEX_5 (5) #define E2E_P07M_INDEX_6 (6) #define E2E_P07M_INDEX_7 (7) #define E2E_SOURCE_MASK ((uint32)0xFFFFFFF) /*data length defined in bits*/ #define E2E_P07M_MAX_DATA_LENGTH ((uint32)0x8000) #define E2E_P07M_MIN_DATA_LENGTH ((uint32)(E2E_P07M_HEADER_BYTE_LENGTH * (uint32)8)) #define E2E_P07M_DATA_UINT_BIT ((uint32)8) #define E2E_P07M_MAX_COUNTER_VALUE ((uint32)0xFFFF) #define E2E_P07M_MAX_SOURCEID_VALUE ((uint32)0xFFFFFFF) #define E2E_P07M_GET_HEADEROFFSET(config) (((config)->Offset) >> (uint32)3) #define E2E_P07M_LOWDATA_ALIGNED(data) ((uint8)((data) & (uint8)0x3F)) #define E2E_P07M_HIGHDATA_ALIGNED(data) ((uint8)((data) & (uint8)0xCF)) #define E2E_P07M_MESSAGETYPE_ALIGNED(data) ((uint8)(((data) & (uint8)0x03) << (uint8)6)) #define E2E_P07M_MESSAGERESULT_ALIGNED(data) ((uint8)(((data) & (uint8)0x03) << (uint8)4)) #define E2E_P07M_READMTYPE_ALIGNED(data) ((uint8)(((data) & (uint8)0xC0) >> (uint8)6)) #define E2E_P07M_READMRESULT_ALIGNED(data) ((uint8)(((data) & (uint8)0x30) >> (uint8)4)) #define E2E_P07M_BETOMCU32(data) (uint32)( (((uint32)(data)[0] & (uint32)0xFF) << (uint32)24)\ | (((uint32)(data)[1] & (uint32)0xFF) << (uint32)16)\ | (((uint32)(data)[2] & (uint32)0xFF) << (uint32)8)\ | (((uint32)(data)[3] & (uint32)0xFF) << (uint32)0)) #define E2E_P07M_BETOMCU64(data) (uint64)( (((uint64)(data)[0] & (uint64)0xFF) << (uint64)56)\ | (((uint64)(data)[1] & (uint64)0xFF) << (uint64)48)\ | (((uint64)(data)[2] & (uint64)0xFF) << (uint64)40)\ | (((uint64)(data)[3] & (uint64)0xFF) << (uint64)32)\ | (((uint64)(data)[4] & (uint64)0xFF) << (uint64)24)\ | (((uint64)(data)[5] & (uint64)0xFF) << (uint64)16)\ | (((uint64)(data)[6] & (uint64)0xFF) << (uint64)8)\ | (((uint64)(data)[7] & (uint64)0xFF) << (uint64)0)) #define E2E_P07M_BYTE_ALIGNED_MASK ((uint32)0x0007) #define E2E_P07M_IS_NOT_BYTE_ALIGNED(bit) ((uint32)((bit) & E2E_P07M_BYTE_ALIGNED_MASK) != (uint32)0) #define E2E_START_SEC_CODE #include "E2E_MemMap.h" /****************************************************************************** * Private Functions Declare ******************************************************************************/ STATIC FUNC(void, E2E_CODE) E2E_P07mCheckRecvCounter ( uint32 Counter, P2CONST(E2E_P07mConfigType, AUTOMATIC, E2E_APPL_CONST) Config, P2VAR(E2E_P07mCheckStateType, AUTOMATIC, E2E_APPL_DATA) State ); STATIC FUNC(uint32, E2E_CODE) E2E_P07mGetDeltaCounter ( uint32 Counter, uint32 LastValidCounter ); STATIC FUNC(uint64, E2E_CODE)E2E_P07mGetCrc ( uint32 Offset, uint32 Length, P2CONST(uint8, AUTOMATIC, E2E_APPL_DATA) Data ); STATIC FUNC(void, E2E_CODE)E2E_P07mMcu64ToBeData ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint64 data ); STATIC FUNC(void, E2E_CODE)E2E_P07mMcu32ToBeData ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint32 data ); STATIC FUNC(void, E2E_CODE)E2E_P07mWriteMessageType ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, Std_MessageTypeType MessageType ); STATIC FUNC(void, E2E_CODE)E2E_P07mWriteMessageResult ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, Std_MessageResultType MessageResult ); /****************************************************************************** * Private Functions ******************************************************************************/ /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mCheckRecvCounter * * Description: Check the received counter. * * Inputs: Counter : Received counter. * Config : Pointer to static configuration. * State : Pointer to port/data communication state. * * Outputs: None. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*PRS_E2E_00501*/ STATIC FUNC(void, E2E_CODE) E2E_P07mCheckRecvCounter ( uint32 Counter, P2CONST(E2E_P07mConfigType, AUTOMATIC, E2E_APPL_CONST) Config, P2VAR(E2E_P07mCheckStateType, AUTOMATIC, E2E_APPL_DATA) State ) { uint32 DeltaCounter; /*compute delta counter*/ DeltaCounter = E2E_P07mGetDeltaCounter(Counter, State->Counter); if((uint32)0 == DeltaCounter) { State->Status = E2E_P07MSTATUS_REPEATED; } else if((uint32)1 == DeltaCounter) { State->Status = E2E_P07MSTATUS_OK; } else if(DeltaCounter <= Config->MaxDeltaCounter) { State->Status = E2E_P07MSTATUS_OKSOMELOST; } else { State->Status = E2E_P07MSTATUS_WRONGSEQUENCE; } State->Counter = Counter; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mGetDeltaCounter * * Description: Calculate the delta counter. * * Inputs: Counter : Received counter. * LastValidCounter : The last valid counter value. * * Outputs: The delta counter value. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(uint32, E2E_CODE) E2E_P07mGetDeltaCounter ( uint32 Counter, uint32 LastValidCounter ) { uint32 DeltaCounter; if(Counter >= LastValidCounter) { DeltaCounter = Counter - LastValidCounter; } else { DeltaCounter = ((uint32)(E2E_P07M_MAX_COUNTER_VALUE - LastValidCounter) + (uint32)1) + Counter; } return DeltaCounter; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mGetCrc * * Description: Calculate the crc value. * * Inputs: Offset : Protect header offset in bytes. * Length : Data length in bytes. * Data : Pointer to the data to be protected. * * Outputs: The crc value. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(uint64, E2E_CODE)E2E_P07mGetCrc ( uint32 Offset, uint32 Length, P2CONST(uint8, AUTOMATIC, E2E_APPL_DATA) Data ) { uint64 crc = E2E_P07M_CRC_INIT_VALUE; /*compute CRC over bytes that are before CRC.*//*PRS_E2E_00808*/ if(Offset > (uint32)0) { crc = Crc_CalculateCRC64(&Data[0], (uint32)Offset, crc, TRUE); /*Compute CRC over bytes that are after CRC*/ crc = Crc_CalculateCRC64(&Data[Offset + E2E_P07M_CRC_BYTE_LENGTH], (uint32)(Length - Offset - E2E_P07M_CRC_BYTE_LENGTH), crc, FALSE); } else { /*Compute CRC over bytes that are after CRC*/ crc = Crc_CalculateCRC64(&Data[E2E_P07M_CRC_BYTE_LENGTH], (uint32)(Length - E2E_P07M_CRC_BYTE_LENGTH), crc, TRUE); } return crc; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07Mcu64ToBeData * * Description: Converte the 64-bit data to big endian 8-bit data * * Inputs: DataPtr : Pointer to the data. * Data : Data to be converted. * * Outputs: None. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(void, E2E_CODE)E2E_P07mMcu64ToBeData ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint64 data ) { DataPtr[0] = (uint8)((uint8)(data >> E2E_P07M_SEVENBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[1] = (uint8)((uint8)(data >> E2E_P07M_SIXBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_2] = (uint8)((uint8)(data >> E2E_P07M_FIVEBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_3] = (uint8)((uint8)(data >> E2E_P07M_FOURBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_4] = (uint8)((uint8)(data >> E2E_P07M_THRESSBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_5] = (uint8)((uint8)(data >> E2E_P07M_TWOBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_6] = (uint8)((uint8)(data >> E2E_P07M_BYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_7] = (uint8)((uint8)data & E2E_P07M_BYTE_MASK); } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mMcu32ToBeData * * Description: Converte the 32-bit data to big endian 8-bit data * * Inputs: DataPtr : Pointer to the data. * Data : Data to be converted. * * Outputs: None. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(void, E2E_CODE)E2E_P07mMcu32ToBeData ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint32 data ) { DataPtr[0] = (uint8)((uint8)(data >> E2E_P07M_THRESSBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[1] = (uint8)((uint8)(data >> E2E_P07M_TWOBYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_2] = (uint8)((uint8)(data >> E2E_P07M_BYTE_OFFSET_BIT) & E2E_P07M_BYTE_MASK); DataPtr[E2E_P07M_INDEX_3] = (uint8)((uint8)data & E2E_P07M_BYTE_MASK); } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mWriteMessageType * * Description: Converte the MessageType data to big endian 8-bit data * * Inputs: DataPtr : Pointer to the data. * Data : Data to be converted. * * Outputs: None. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(void, E2E_CODE)E2E_P07mWriteMessageType ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, Std_MessageTypeType MessageType ) { uint8 data = DataPtr[0]; uint8 Mtype = (uint8)MessageType; /*PRQA S 4571 ++*/ DataPtr[0] = (E2E_P07M_LOWDATA_ALIGNED(data) | E2E_P07M_MESSAGETYPE_ALIGNED(Mtype)); /*PRQA S 4571 --*/ } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mWriteMessageResult * * Description: Converte the MessageResult data to big endian 8-bit data * * Inputs: DataPtr : Pointer to the data. * MessageResult * * Outputs: None. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ STATIC FUNC(void, E2E_CODE)E2E_P07mWriteMessageResult ( P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, Std_MessageResultType MessageResult ) { uint8 data = DataPtr[0]; uint8 MResult = (uint8)MessageResult; /*PRQA S 4571 ++*/ DataPtr[0] = (E2E_P07M_HIGHDATA_ALIGNED(data) | E2E_P07M_MESSAGERESULT_ALIGNED(MResult)); /*PRQA S 4571 --*/ } /****************************************************************************** * Public Funtions ******************************************************************************/ /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mProtectInit * * Description: Initializes the protection state. * * Inputs: StatePtr : Pointer to port/data communication state. * * Outputs: E2E_E_INPUTERR_NULL, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_91015*/ FUNC(Std_ReturnType, E2E_CODE) E2E_P07mProtectInit ( P2VAR(E2E_P07mProtectStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr ) { Std_ReturnType ret; /*SWS_E2E_00596*/ if(NULL_PTR == StatePtr) { ret = E2E_E_INPUTERR_NULL; } else { ret = E2E_E_OK; StatePtr->Counter = (uint32)0; } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mProtect * * Description: Protects the array/buffer to be transmitted using the E2E profile 7m. * This includes CRC calculation, handling of Counter, Data ID, * Message Type, Message Result, and Source ID. * * Inputs: ConfigPtr : Pointer to static configuration. * SourceID : A system-unique identifier of the Data Source. * MessageType : Type of the message (request/response). * MessageResult: Result of the message (OK/ERROR). * Length : Length of the data in bytes. * * InOut: StatePtr : Pointer to port/data communication state. * DataPtr : Pointer to Data to be transmitted. * * Return value: E2E_E_INPUTERR_NULL, * E2E_E_INPUTERR_WRONG, * E2E_E_INTERR, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_91014*/ FUNC(Std_ReturnType, E2E_CODE) E2E_P07mProtect ( P2CONST(E2E_P07mConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_P07mProtectStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr, uint32 SourceID, Std_MessageTypeType MessageType, Std_MessageResultType MessageResult, P2VAR(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint32 Length ) { Std_ReturnType ret = E2E_E_OK; uint32 headerOffset; uint64 crc; /*verify input parameters*//*PRS_E2E_00800*/ if((NULL_PTR == ConfigPtr) || (NULL_PTR == StatePtr) || (NULL_PTR == DataPtr)) { ret = E2E_E_INPUTERR_NULL; } else if (((ConfigPtr->MinDataLength) < E2E_P07M_MIN_DATA_LENGTH) || (ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength) || (ConfigPtr->MaxDataLength > E2E_P07M_MAX_DATA_LENGTH) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MinDataLength)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MaxDataLength))) { ret = E2E_E_INPUTERR_WRONG; } else if ((SourceID > E2E_P07M_MAX_SOURCEID_VALUE) ||(MessageType < TypeRequest) || (MessageType > TypeResponse) ||(MessageResult < ResultOk) || (MessageResult > ResultError)) { ret = E2E_E_INPUTERR_WRONG; } else if (((Length * E2E_P07M_DATA_UINT_BIT) < ConfigPtr->MinDataLength) || ((Length * E2E_P07M_DATA_UINT_BIT) > ConfigPtr->MaxDataLength)) { ret = E2E_E_INPUTERR_WRONG; } else if ((ConfigPtr->Offset > ((Length - E2E_P07M_HEADER_BYTE_LENGTH) * E2E_P07M_DATA_UINT_BIT)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->Offset))) { ret = E2E_E_INPUTERR_WRONG; } else { /*Compute offset*/ /*PRS_E2E_00801*/ headerOffset = E2E_P07M_GET_HEADEROFFSET(ConfigPtr); /*Write Length to data in big endian order*//*PRS_E2E_00802*/ E2E_P07mMcu32ToBeData(&DataPtr[headerOffset + E2E_P07M_LENGTH_OFFSET], Length); /*Write Counter to data in big endian order*//*PRS_E2E_00803*/ E2E_P07mMcu32ToBeData(&DataPtr[headerOffset + E2E_P07M_COUNTER_OFFSET], StatePtr->Counter); /*Write DataID to data in big endian order*//*PRS_E2E_00804*/ E2E_P07mMcu32ToBeData(&DataPtr[headerOffset + E2E_P07M_DATAID_OFFSET], ConfigPtr->DataID); /*Write SourceID to data in big endian order*//*PRS_E2E_00805*/ E2E_P07mMcu32ToBeData(&DataPtr[headerOffset + E2E_P07M_SOURCEID_OFFSET], SourceID); /*Write Message Type to data in big endian order*//*PRS_E2E_00806*/ E2E_P07mWriteMessageType(&DataPtr[headerOffset + E2E_P07M_SOURCEID_OFFSET], MessageType); /*Write Message Result to data in big endian order*//*PRS_E2E_00807*/ E2E_P07mWriteMessageResult(&DataPtr[headerOffset + E2E_P07M_SOURCEID_OFFSET], MessageResult); /*calculate crc*//*PRS_E2E_00808*/ crc = E2E_P07mGetCrc(headerOffset, Length, DataPtr); /*Write crc to data in big endian order*//*PRS_E2E_00809*/ E2E_P07mMcu64ToBeData(&DataPtr[headerOffset + E2E_P07M_CRC_OFFSET], crc); /*Increment Counter*//*PRS_E2E_00810*/ StatePtr->Counter++; } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mSourceCheck * * Description: Checks the Data received using the E2E profile 7m. * This includes CRC calculation,handling of Counter, Data ID, * Message Type, Message Result, and Source ID. * * Inputs: ConfigPtr : Pointer to static configuration. * SourceID : A system-unique identifier of the Data Source. * MessageType : Type of the message (request/response). * MessageResult: Result of the message (OK/ERROR). * DataPtr : Pointer to received data. * Length : Length of the data in bytes. * * InOut: StatePtr : Pointer to received data. * * Return vlaue: E2E_E_INPUTERR_NULL, * E2E_E_INPUTERR_WRONG, * E2E_E_INTERR, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_91018*/ FUNC(Std_ReturnType, E2E_CODE)E2E_P07mSourceCheck ( P2CONST(E2E_P07mConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_P07mCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr, uint32 SourceID, Std_MessageTypeType MessageType, Std_MessageResultType MessageResult, P2CONST(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint32 Length ) { Std_ReturnType ret = E2E_E_OK; uint64 calCrc; uint64 recvCrc; uint32 headOffset; uint32 recvCounter; uint32 recvLength; uint32 recvDataID; uint32 recvSourceID; uint8 recvMessageType; uint8 recvMessageResult; /*PRS_E2E_00815*//*PRS_E2E_00816*/ if((NULL_PTR == ConfigPtr) || (NULL_PTR == StatePtr)) { ret = E2E_E_INPUTERR_NULL; } /*check config data length*/ else if (((ConfigPtr->MinDataLength) < E2E_P07M_MIN_DATA_LENGTH) || (ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength) || (ConfigPtr->MaxDataLength > E2E_P07M_MAX_DATA_LENGTH) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MinDataLength)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MaxDataLength))) { ret = E2E_E_INPUTERR_WRONG; } else if (DataPtr == NULL_PTR) { /*check the length of received data*//*PRS_E2E_00496*/ if(Length != (uint32)0) { ret = E2E_E_INPUTERR_WRONG; } else { /*No data has been received*//*PRS_E2E_00501*/ StatePtr->Status = E2E_P07MSTATUS_NONEWDATA; } } else if ((SourceID > E2E_P07M_MAX_SOURCEID_VALUE) || (MessageType < TypeRequest) || (MessageType > TypeResponse) || (MessageResult < ResultOk) || (MessageResult > ResultError)) { ret = E2E_E_INPUTERR_WRONG; } /*check the length of received data*/ else if (((Length * E2E_P07M_DATA_UINT_BIT) > ConfigPtr->MaxDataLength) || ((Length * E2E_P07M_DATA_UINT_BIT) < ConfigPtr->MinDataLength)) { ret = E2E_E_INPUTERR_WRONG; } /*the length of the data received is correct*/ else if((ConfigPtr->Offset > ((Length - E2E_P07M_HEADER_BYTE_LENGTH) * E2E_P07M_DATA_UINT_BIT)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->Offset))) { ret = E2E_E_INPUTERR_WRONG; } else { /*compute offset*/ headOffset = E2E_P07M_GET_HEADEROFFSET(ConfigPtr); /*read received length from data*//*PRS_E2E_00817*/ recvLength = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_LENGTH_OFFSET]); /*read received counter from data*//*PRS_E2E_00818*/ recvCounter = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_COUNTER_OFFSET]); /*read data id from data*//*PRS_E2E_00819*/ recvDataID = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_DATAID_OFFSET]); /*read received SourceID from data*//*PRS_E2E_00820*/ recvSourceID = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]) & E2E_SOURCE_MASK; /*read received Message Type from data*//*PRS_E2E_00821*/ recvMessageType = (uint8)E2E_P07M_READMTYPE_ALIGNED(DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]); /*read received Message Result from data*//*PRS_E2E_00822*/ recvMessageResult = (uint8)E2E_P07M_READMRESULT_ALIGNED(DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]); /*read received crc from data*//*PRS_E2E_00823*/ recvCrc = E2E_P07M_BETOMCU64(&DataPtr[headOffset + E2E_P07M_CRC_OFFSET]); /*Compute CRC*/ calCrc = E2E_P07mGetCrc(headOffset, Length, DataPtr); /*Check if the received crc is equal to the calculated crc*//*PRS_E2E_00824*/ if((recvCrc == calCrc) && (recvDataID == ConfigPtr->DataID) && (recvLength == Length) &&(recvSourceID == SourceID) && (recvMessageType == (uint8)MessageType)\ && (recvMessageResult == (uint8)MessageResult)) { /*check counter*/ E2E_P07mCheckRecvCounter(recvCounter, ConfigPtr, StatePtr); } else { StatePtr->Status = E2E_P07MSTATUS_ERROR; } } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mSinkCheck * * Description: Checks the Data received using the E2E profile 7m. * This includes CRC calculation,handling of Counter, Data ID, * Message Type, Message Result, and Source ID. * * Inputs: ConfigPtr : Pointer to static configuration. * MessageType : Type of the message (request/response). * MessageResult: Result of the message (OK/ERROR). * DataPtr : Pointer to received data. * Length : Length of the data in bytes. * * InOut: StatePtr : Pointer to received data. * * Outputs: SourceID : A system-unique identifier of the Data Source. * * Return vlaue: E2E_E_INPUTERR_NULL, * E2E_E_INPUTERR_WRONG, * E2E_E_INTERR, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_91017*/ FUNC(Std_ReturnType, E2E_CODE)E2E_P07mSinkCheck ( P2CONST(E2E_P07mConfigType, AUTOMATIC, E2E_APPL_CONST) ConfigPtr, P2VAR(E2E_P07mCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr, P2VAR(uint32, AUTOMATIC, E2E_APPL_DATA) SourceID, Std_MessageTypeType MessageType, Std_MessageResultType MessageResult, P2CONST(uint8, AUTOMATIC, E2E_APPL_DATA) DataPtr, uint32 Length ) { Std_ReturnType ret = E2E_E_OK; uint64 calCrc; uint64 recvCrc; uint32 headOffset; uint32 recvCounter; uint32 recvLength; uint32 recvDataID; uint32 recvSourceID; uint8 recvMessageType; uint8 recvMessageResult; /*PRS_E2E_00841*//*PRS_E2E_00842*/ if((NULL_PTR == ConfigPtr) || (NULL_PTR == StatePtr)) { ret = E2E_E_INPUTERR_NULL; } /*check config data length*/ else if (((ConfigPtr->MinDataLength) < E2E_P07M_MIN_DATA_LENGTH) || (ConfigPtr->MinDataLength > ConfigPtr->MaxDataLength) || (ConfigPtr->MaxDataLength > E2E_P07M_MAX_DATA_LENGTH) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MinDataLength)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->MaxDataLength))) { ret = E2E_E_INPUTERR_WRONG; } else if (DataPtr == NULL_PTR) { /*check the length of received data*/ if(Length != (uint32)0) { ret = E2E_E_INPUTERR_WRONG; } else { /*No data has been received*/ StatePtr->Status = E2E_P07MSTATUS_NONEWDATA; } } else if ((*SourceID > E2E_P07M_MAX_SOURCEID_VALUE) || (MessageType < TypeRequest) || (MessageType > TypeResponse) || (MessageResult < ResultOk) || (MessageResult > ResultError)) { ret = E2E_E_INPUTERR_WRONG; } /*check the length of received data*//*PRS_E2E_00496*/ else if (((Length * E2E_P07M_DATA_UINT_BIT) > ConfigPtr->MaxDataLength) || ((Length * E2E_P07M_DATA_UINT_BIT) < ConfigPtr->MinDataLength)) { ret = E2E_E_INPUTERR_WRONG; } /*the length of the data received is correct*/ else if ((ConfigPtr->Offset > ((Length - E2E_P07M_HEADER_BYTE_LENGTH) * E2E_P07M_DATA_UINT_BIT)) || (E2E_P07M_IS_NOT_BYTE_ALIGNED(ConfigPtr->Offset))) { ret = E2E_E_INPUTERR_WRONG; } else { /*compute offset*/ headOffset = E2E_P07M_GET_HEADEROFFSET(ConfigPtr); /*read received length from data*//*PRS_E2E_00497*/ recvLength = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_LENGTH_OFFSET]); /*read received counter from data*//*PRS_E2E_00498*/ recvCounter = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_COUNTER_OFFSET]); /*read data id from data*//*PRS_E2E_00499*/ recvDataID = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_DATAID_OFFSET]); /*read Source id from data*//*PRS_E2E_00843*/ recvSourceID = E2E_P07M_BETOMCU32(&DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]) & E2E_SOURCE_MASK; *SourceID = recvSourceID; /*read Message Type from data*//*PRS_E2E_00821*/ recvMessageType = (uint8)E2E_P07M_READMTYPE_ALIGNED(DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]); /*read Message Result from data*//*PRS_E2E_00822*/ recvMessageResult = (uint8)E2E_P07M_READMRESULT_ALIGNED(DataPtr[headOffset + E2E_P07M_SOURCEID_OFFSET]); /*read received crc from data*//*PRS_E2E_00500*/ recvCrc = E2E_P07M_BETOMCU64(&DataPtr[headOffset + E2E_P07M_CRC_OFFSET]); /*Compute CRC*/ calCrc = E2E_P07mGetCrc(headOffset, Length, DataPtr); /*Check if the received crc is equal to the calculated crc*//*PRS_E2E_00501*/ if((recvCrc == calCrc) && (recvDataID == ConfigPtr->DataID) && (recvLength == Length) && (recvMessageType == (uint8)MessageType) && (recvMessageResult == (uint8)MessageResult)) { /*check counter*/ E2E_P07mCheckRecvCounter(recvCounter, ConfigPtr, StatePtr); } else { /*PRS_E2E_00501*/ StatePtr->Status = E2E_P07MSTATUS_ERROR; } } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mCheckInit * * Description: Initializes the check state. * * Inputs: StatePtr : Pointer to port/data communication state. * * Outputs: E2E_E_INPUTERR_NULL, * E2E_E_OK * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_91012*/ FUNC(Std_ReturnType, E2E_CODE) E2E_P07mCheckInit ( P2VAR(E2E_P07mCheckStateType, AUTOMATIC, E2E_APPL_DATA) StatePtr ) { Std_ReturnType ret; /*SWS_E2E_00597*/ if(NULL_PTR == StatePtr) { ret = E2E_E_INPUTERR_NULL; } else { StatePtr->Status = E2E_P07MSTATUS_ERROR; StatePtr->Counter = E2E_P07M_MAX_COUNTER_VALUE; ret = E2E_E_OK; } return ret; } /* BEGIN_FUNCTION_HDR ******************************************************************************* * Function Name: E2E_P07mMapStatusToSM * * Description: The function maps the check status of Profile 7m to a generic check status, * which can be used by E2E state machine check function. * The E2E Profile 7m delivers a more fine-granular status, * but this is not relevant for the E2E state machine. * * Inputs: CheckReturn : Return value of the E2E_P07mSinkCheck/E2E_P07mSourceCheck function. * Status : Status determined by E2E_P07mSinkCheck/E2E_P07mSourceCheck function. * * Return value: E2E_PCheckStatusType : Profile-independent status of the reception * on one single Data in one cycle. * * Limitations: None ******************************************************************************* END_FUNCTION_HDR */ /*SWS_E2E_00550*/ FUNC(E2E_PCheckStatusType, E2E_CODE) E2E_P07mMapStatusToSM ( Std_ReturnType CheckReturn, E2E_P07mCheckStatusType Status ) { E2E_PCheckStatusType CheckStatus; /*SWS_E2E_00598*/ if(E2E_E_OK == CheckReturn) { if((E2E_P07MSTATUS_OK == Status) || (E2E_P07MSTATUS_OKSOMELOST == Status)) { CheckStatus = E2E_P_OK; } else if(E2E_P07MSTATUS_ERROR == Status) { CheckStatus = E2E_P_ERROR; } else if(E2E_P07MSTATUS_REPEATED == Status) { CheckStatus = E2E_P_REPEATED; } else if(E2E_P07MSTATUS_NONEWDATA == Status) { CheckStatus = E2E_P_NONEWDATA; } else { CheckStatus = E2E_P_WRONGSEQUENCE; } } /*SWS_E2E_00599*/ else { CheckStatus = E2E_P_ERROR; } return CheckStatus; } #define E2E_STOP_SEC_CODE #include "E2E_MemMap.h"