#ifndef _UDS_FBL_SERVICE_10_SOURCE #define _UDS_FBL_SERVICE_10_SOURCE /******************************************************************************* ** Include Section ** *******************************************************************************/ #include "uds_fbl_mgr.h" #include "uds_fbl_service10.h" #include "uds_fbl_service11.h" #include "uds_fbl_service27.h" /******************************************************************************* ** Version Information ** *******************************************************************************/ /******************************************************************************* ** Version Check ** *******************************************************************************/ /******************************************************************************* ** Macro definition ** *******************************************************************************/ /******************************************************************************* ** Global Data ** *******************************************************************************/ const uds_nrc nrc_1001[1] = { UDSincorrectMessageLengthOrInvalidFormat }; const uds_nrc nrc_1002[2] = { UDSincorrectMessageLengthOrInvalidFormat,\ UDSsubFuncNotSupportedInActSes }; const uds_nrc nrc_1003[2] = { UDSincorrectMessageLengthOrInvalidFormat,\ UDSsubFuncNotSupportedInActSes }; /*--------- <0x10> sub function config start-------------*/ static const DIAG_sunfunction_t SessionSubfunction[] = { {0x01 ,7,false,2,6,NULL,{nrc_1001, 1}}, {0x02 ,6,false,2,6,NULL,{nrc_1002, 2}}, {0x03 ,5,false,2,6,NULL,{nrc_1003, 2}} }; /*--------- <0x10>sub function config end---------------*/ /*-------------------------------------------------------*/ static uint8_t g_rece_1002_frameFlag; /******************************************************************************* ** Function Definitions ** *******************************************************************************/ static void service10_SetReceFlag(uint8_t flag); /* Set 10 02 receive flag */ /********************************************************************************************* * Prototype * uds_nrc service10_nrc_check(uint8_t session, unsigned char* pdiagdata, unsigned short diagrequestlength) * Parameter * parameter [in] : * * Return code * return * * Functional Description * * Particularities and Limitations * * Expected Caller Context * *********************************************************************************************/ uds_nrc service10_nrc_check(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t const kwpdiag_num = (sizeof(SessionSubfunction)/sizeof(DIAG_sunfunction_t)); uint8_t index = 0; uint8_t requestsid; nrc_table_t nrc_table; uint16_t length; uint8_t index_nrc = 0; uint8_t currentSession = 0; currentSession = udsFbl_GetCurrentSessionMode(); requestsid = UDS_GET_SUB_FUNCTION(qUDSpacket->Data.Byte[1]); /* Check whether the sub-function is supported */ for (index = 0; index < kwpdiag_num; index++) { if(requestsid == SessionSubfunction[index].sub_requestsid) { break; } } if(index != kwpdiag_num) { nrc_table = SessionSubfunction[index].nrc_table; for (index_nrc = 0; (index_nrc < nrc_table.nrc_cnt) && (returnType == 0); index_nrc++) { length = SessionSubfunction[index].rx_dataLen; switch (nrc_table.nrc_list[index_nrc]) { case UDSincorrectMessageLengthOrInvalidFormat: if (Uds_Nrc13_Occur(qUDSpacket->size, length)) { returnType = UDSincorrectMessageLengthOrInvalidFormat; } break; case UDSsubFuncNotSupportedInActSes: if ((currentSession & SessionSubfunction[index].session_mask) == 0) { returnType = UDSsubFuncNotSupportedInActSes; } break; default: break; } } } else { returnType = UDSsubfunctionNotSupported; } return returnType; /* return highest priority nrc*/ } /********************************************************************************************* * Prototype * void ApplDiagStartDiagnosticSession_10(unsigned char* pdiagdata, unsigned short diagrequestlength) * Parameter * pdiagdata [in] : * diagrequestlength [in] : * * Functional Description * * Particularities and Limitations * * Expected Caller Context * *********************************************************************************************/ uint8_t ApplDiagStartDiagnosticSession_10(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t subFunction; returnType = service10_nrc_check(qUDSpacket); subFunction = UDS_GET_SUB_FUNCTION(qUDSpacket->Data.Byte[1]); if (UDSpositiveResp == returnType) { switch (subFunction) { case 0x01: UdsFbl_SetDefaultDiagSession(); break; case 0x02: UdsFbl_SetProgDiagSession(); service10_SetReceFlag(0x01); break; case 0x03: UdsFbl_SetExtendDiagSession(); break; default: break; } } if(UDSpositiveResp == returnType) { qUDSpacket->Data.Byte[0] = UDS_GET_POSITIVE_RSP(qUDSpacket->Data.Byte[0]); qUDSpacket->Data.Byte[2u] = P2serverValue_L; qUDSpacket->Data.Byte[3u] = P2serverValue_H; qUDSpacket->Data.Byte[4u] = P2_serverValue_L; qUDSpacket->Data.Byte[5u] = P2_serverValue_H; qUDSpacket->size = 6; } else { /* do nothing */ } return returnType; } /*===============================================================================================*/ /* bool UdsFbl_SetDefaultDiagSession(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Set default session */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: app is completed or not */ /*===============================================================================================*/ void UdsFbl_SetDefaultDiagSession(void) { uint8_t u8CurrentSession; u8CurrentSession = udsFbl_GetCurrentSessionMode(); udsFbl_SetCurrentSessionMode(KWPDIAG_DEFAULT_SESS_ID); /*According to customer requirement: when current session is in extend session, then only change back to default session and without system reset. when current session is in program session, then reset external reprogram flag and do system reset*/ if(u8CurrentSession == KWPDIAG_PROG_SESS_ID) { /*reset to app*/ service11_set_rstflag((uint8_t)0x03,TRUE); } } /*===============================================================================================*/ /* void UdsFbl_SetProgDiagSession(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Set programming session */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: - */ /*===============================================================================================*/ void UdsFbl_SetProgDiagSession(void) { udsFbl_SetCurrentSessionMode(KWPDIAG_PROG_SESS_ID); udsFbl_StartTimer(TIMER_UDS_SESSION); } /*===============================================================================================*/ /* void UdsFbl_SetExtendDiagSession(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Set extend session */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: - */ /*===============================================================================================*/ void UdsFbl_SetExtendDiagSession(void) { udsFbl_SetCurrentSessionMode(KWPDIAG_EXTEND_SESS_ID); udsFbl_StartTimer(TIMER_UDS_SESSION); } /*===============================================================================================*/ /* void SessionCounterCheck(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Check if session keep timer timeout */ /* Arguments: pSessionCounter : session counter */ /* Return: - */ /*===============================================================================================*/ void SessionCounterCheck(uint16_t* pSessionCounter) { if((*pSessionCounter)) { (*pSessionCounter)--; if (((*pSessionCounter) == 0) && (KWPDIAG_DEFAULT_SESS_ID != udsFbl_GetCurrentSessionMode())) { UdsFbl_SetDefaultDiagSession(); /*according to E16 FBL requirement, when occur S3 timeout, the security level need re-lock*/ service27_set_currsa(UDS_SA_NON); } } } /*===============================================================================================*/ /* uint8_t service10_GetReceFlag(void) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Get 10 02 receive flag */ /* Arguments: - */ /* Return: receive flag */ /*===============================================================================================*/ uint8_t service10_GetReceFlag(void) { return g_rece_1002_frameFlag; } /*===============================================================================================*/ /* static void service10_SetReceFlag(uint8_t flag) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Set 10 02 receive flag */ /* Arguments: flag : receive flag */ /* Return: - */ /*===============================================================================================*/ static void service10_SetReceFlag(uint8_t flag) { g_rece_1002_frameFlag = flag; } /******************************************************************************* ** End of File ** *******************************************************************************/ #endif /*_UDS_FBL_SERVICE_10_SOURCE*/