#include "uds_fbl_mgr.h" #include "uds_fbl_service10.h" #include "uds_fbl_service11.h" #include "uds_fbl_service3e.h" #include "uds_fbl_service85.h" #include "uds_fbl_service22.h" #include "uds_fbl_service2E.h" #include "uds_fbl_service28.h" #include "uds_fbl_service27.h" #include "uds_fbl_service31.h" #include "uds_fbl_service34.h" #include "uds_fbl_service36.h" #include "uds_fbl_service37.h" #include "uds_fbl_funcaddr_service.h" #include "../cantp/CanTp.h" #include "uds_vmem.h" #include "crc_drv.h" #define SEED_VAL (0xFFFFFFFFU) static uint8_t kwpdiag_currsess = KWPDIAG_DEFAULT_SESS_ID; static uint16_t crc16Value_u16 = 0x0000; static uint32_t downlodeAddr_u32 = 0; static uint32_t requestEndAddr_u32 = 0; static uint32_t requestStartAddr_u32 = 0; static uint8_t downlodeBlockCnt_u8 = 0; static uint8_t preBlockCnt = 0; static uint16_t maxNumberOfBlockLength = 0; static bool requestIsTrigger = false; static bool fbl_security_access_sts; static bool requestRecved; /* physical address reuqest recesived flag */ static bool func_requestRecved; /* functional address request recesived flag */ /*hash_state md_value;*/ static FLASH_TYPE flash_program_type = FLASH_ERROR; static bool phy_sprmb_flag; static bool func_sprmb_flag; static uint8_t curr_dltype = MEM_ERROR; static uint8_t finish_dl = FALSE; BootIdle_Header_t BootIdle0; UDSpacket_t UDSpacket; UDSpacket_t UDSpacket_Func; /*bool appIsComplete(void);*/ /* FBL diag info list */ DIAG_handler_t sessionhandlerTable[] = { {0x10, 2, true , ApplDiagStartDiagnosticSession_10}, {0x11, 2, true , ApplDiagEcuReset_11}, {0x22, 3, false, ApplDiagReadDataByCommonId_22}, {0x27, 2, false, ApplDiag_SecurityAccess_27}, {0x28, 3, true , ApplDiag_CommunicatinControl_28}, {0x2E, 3, false, ApplDiagWriteDataByCommonId_2e}, {0x31, 4, false, ApplDiagStartRoutineByLocaldentifier_31}, {0x34, 1, false, ApplDiag_RequestDownload_34}, {0x36, 2, false, ApplDiag_TransferData_36}, {0x37, 1, false, ApplDiag_RequestTransferExit_37}, {0x3E, 2, true , ApplDiag_TesterPresentHandler_3e}, {0x85, 5, true , ApplDiag_ControlDTCSetting_85}, }; /*==================================================================================================*/ /* bool Uds_Nrc22_Occur(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if conditions not correct */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc22_Occur(void) { return false; } /*==================================================================================================*/ /* bool Uds_Nrc7E_Occur(uint16_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if subFunction not supported in active session */ /* Arguments: requestsid : sub-service id */ /* funcList : diag service info table */ /* listSize : diag service info table size */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc7E_Occur(uint16_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) { uint16_t index = 0; uint8_t curr_session = udsFbl_GetCurrentSessionMode(); for (index = 0; index < listSize; index++) { if(requestsid == funcList[index].sub_requestsid) { if (0 == (curr_session & funcList[index].session_mask )) { return true; } } } return false; } /*==================================================================================================*/ /* bool Uds_Nrc12_Occur(uint8_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if subFunction is supported */ /* Arguments: requestsid : sub-service id */ /* funcList : diag service info table */ /* listSize : diag service info table size */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc12_Occur(uint8_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) { uint16_t index = 0; for (index = 0; index < listSize; index++) { if (funcList[index].sub_requestsid == requestsid) { return false; } } return true; } /*==================================================================================================*/ /* bool Uds_Nrc13_Occur(uint16_t sourceLength, uint16_t targetLength) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if the length of the service request is wrong */ /* Arguments: sourceLength : Actual service request length */ /* targetLength : Expected service request length */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc13_Occur(uint16_t sourceLength, uint16_t targetLength) { if (sourceLength != targetLength) { return true; } else { return false; } } /*==================================================================================================*/ /* bool Uds_Nrc37_Occur(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check whether the security unlock interval time is reached */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc37_Occur(void) { return false; } /*==================================================================================================*/ /* bool Uds_Nrc24_Occur(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if request sequence error */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc24_Occur(void) { bool rslt = true; #if 0 if (TRUE == UdsFbl_GetSeedSendSts()) { rslt = false; } #endif return rslt; } /*==================================================================================================*/ /* bool Uds_Nrc35_Occur(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if key is valid */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc35_Occur(void) { return false; } /*==================================================================================================*/ /* bool Uds_Nrc36_Occur(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if the maximum number of unlock attempts is exceeded */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc36_Occur(void) { bool rslt = false; #if 0 if(UdsFbl_GetSeckeyErrCnt() >= 3) { rslt = true; } #endif return rslt; } /*==================================================================================================*/ /* bool Uds_Nrc33_Occur(uint16_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if security access denied */ /* Arguments: requestsid : sub-service id */ /* funcList : diag service info table */ /* listSize : diag service info table size */ /* Return: Yes or No */ /*==================================================================================================*/ bool Uds_Nrc33_Occur(uint16_t requestsid, const DIAG_sunfunction_t* funcList, uint16_t listSize) { uint8_t index = 0; bool nrcFlag = false; bool secSts = udsFbl_Get_Security_Access_Sts(); for(index = 0;index < listSize;index ++) { if(requestsid == funcList[index].sub_requestsid) { if((secSts != TRUE) && (TRUE == funcList[index].SecurityLevel)) { nrcFlag = true; } break; } } return nrcFlag; } /*==================================================================================================*/ /* uint8_t udsFbl_GetCurrentSessionMode(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get current session mode */ /* Arguments: - */ /* Return: current session mode */ /*==================================================================================================*/ uint8_t udsFbl_GetCurrentSessionMode(void) { return kwpdiag_currsess; } /*==================================================================================================*/ /* void udsFbl_SetCurrentSessionMode(uint8_t SessionMode) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current session mode */ /* Arguments: session mode */ /* Return: - */ /*==================================================================================================*/ void udsFbl_SetCurrentSessionMode(uint8_t SessionMode) { kwpdiag_currsess = SessionMode; } /*==================================================================================================*/ /* bool udsFbl_Get_Security_Access_Sts(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get current security access status */ /* Arguments: - */ /* Return: current security access status */ /*==================================================================================================*/ bool udsFbl_Get_Security_Access_Sts(void) { return fbl_security_access_sts; } /*==================================================================================================*/ /* void udsFbl_Set_Security_Access_Sts(bool secStatus) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current security access status */ /* Arguments: security access status */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Security_Access_Sts(bool secStatus) { fbl_security_access_sts = secStatus; } /*==================================================================================================*/ /* void udsFbl_SetCrcValue(uint16_t crc) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current crc value */ /* Arguments: crc value */ /* Return: - */ /*==================================================================================================*/ void udsFbl_SetCrcValue(uint16_t crc) { crc16Value_u16 = crc; } /*==================================================================================================*/ /* void udsFbl_SetCrcValue(uint16_t crc) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get current reuqest programming start address */ /* Arguments: - */ /* Return: reuqest programming start address */ /*==================================================================================================*/ uint32_t udsFbl_Get_Request_StartAddr(void) { return requestStartAddr_u32; } /*==================================================================================================*/ /* void udsFbl_Set_Request_StartAddr(uint32_t addr) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current reuqest programming start address */ /* Arguments: programming start address */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Request_StartAddr(uint32_t addr) { requestStartAddr_u32 = addr; } /*==================================================================================================*/ /* uint32_t udsFbl_Get_Request_EndAddr(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get current reuqest programming end address */ /* Arguments: - */ /* Return: programming end address */ /*==================================================================================================*/ uint32_t udsFbl_Get_Request_EndAddr(void) { return requestEndAddr_u32; } /*==================================================================================================*/ /* void udsFbl_Set_Request_EndAddr(uint32_t addr) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current reuqest programming end address */ /* Arguments: programming end address */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Request_EndAddr(uint32_t addr) { requestEndAddr_u32 = addr; } /*==================================================================================================*/ /* bool udsFbl_Get_Request_Is_Trigger(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check if the request to download has been received */ /* Arguments: - */ /* Return: Yes or No */ /*==================================================================================================*/ bool udsFbl_Get_Request_Is_Trigger(void) { return requestIsTrigger; } /*==================================================================================================*/ /* void udsFbl_Set_Request_Is_Trigger(bool flag) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the trigger status of the received download request */ /* Arguments: trigger flag */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Request_Is_Trigger(bool flag) { requestIsTrigger = flag; } /*==================================================================================================*/ /* uint32_t udsFbl_Get_Download_Addr(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get the current request download address */ /* Arguments: - */ /* Return: download start address */ /*==================================================================================================*/ uint32_t udsFbl_Get_Download_Addr(void) { return downlodeAddr_u32; } /*==================================================================================================*/ /* void udsFbl_Set_Download_Addr(uint32_t addr) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the current request download address */ /* Arguments: download start address */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Download_Addr(uint32_t addr) { downlodeAddr_u32 = addr; } /*==================================================================================================*/ /* uint8_t udsFbl_Get_Download_Block_Cnt(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get the current download block counter */ /* Arguments: - */ /* Return: download block counter */ /*==================================================================================================*/ uint8_t udsFbl_Get_Download_Block_Cnt(void) { return downlodeBlockCnt_u8; } /*==================================================================================================*/ /* void udsFbl_Set_Download_Block_Cnt(uint8_t cnt) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the current download block counter */ /* Arguments: download block counter */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Download_Block_Cnt(uint8_t cnt) { downlodeBlockCnt_u8 = cnt; } /*==================================================================================================*/ /* uint8_t udsFbl_Get_PreDownload_Block_Cnt(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get the previous download block counter */ /* Arguments: - */ /* Return: download block counter */ /*==================================================================================================*/ uint8_t udsFbl_Get_PreDownload_Block_Cnt(void) { return preBlockCnt; } /*==================================================================================================*/ /* void udsFbl_Set_PreDownload_Block_Cnt(uint8_t cnt) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the previous download block counter */ /* Arguments: previous download block counter */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_PreDownload_Block_Cnt(uint8_t cnt) { preBlockCnt = cnt; } /*==================================================================================================*/ /* uint8_t udsFbl_Get_Curr_Download_Type(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get current download memory type */ /* Arguments: - */ /* Return: download memory type */ /*==================================================================================================*/ uint8_t udsFbl_Get_Curr_Download_Type(void) { return curr_dltype; } /*==================================================================================================*/ /* void udsFbl_Set_Curr_Download_Type(uint8_t type) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set current download type */ /* Arguments: download type */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Curr_Download_Type(uint8_t type) { curr_dltype = type; } /*==================================================================================================*/ /* uint8_t udsFbl_Get_DownloadStatus(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get the download status */ /* Arguments: - */ /* Return: download status */ /*==================================================================================================*/ uint8_t udsFbl_Get_DownloadStatus(void) { return finish_dl; } /*==================================================================================================*/ /* void udsFbl_Set_DownloadStatus(uint8_t status) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the download status */ /* Arguments: download status */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_DownloadStatus(uint8_t status) { finish_dl = status; } /*==================================================================================================*/ /* uint16_t udsFbl_Get_maxNumberOfBlockLength(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get the maximum allowable length of the data block for each download */ /* Arguments: - */ /* Return: max number of block length */ /*==================================================================================================*/ uint16_t udsFbl_Get_maxNumberOfBlockLength(void) { return maxNumberOfBlockLength; } /*==================================================================================================*/ /* void udsFbl_Set_maxNumberOfBlockLength(uint16_t len) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Set the maximum allowable length of the data block for each download */ /* Arguments: data block length */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_maxNumberOfBlockLength(uint16_t len) { maxNumberOfBlockLength = len; } /*==================================================================================================*/ /* uint16_t udsFbl_GetCrcValue(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Get crc value */ /* Arguments: - */ /* Return: crc value */ /*==================================================================================================*/ uint16_t udsFbl_GetCrcValue(void) { uint8_t curr_memtype; curr_memtype = udsFbl_Get_Curr_Download_Type(); if(curr_memtype == MEM_CAL_APP) { crc16Value_u16 = CRC_CalcCRC16bit((uint8_t *)(COD_APPL_ADDR_START),MEM_COD_APP_LEN, ENABLE, SEED_VAL); } if(curr_memtype == MEM_FLASHDRIVER) { crc16Value_u16 = CRC_CalcCRC16bit((uint8_t *)(DRIVER_ADDR_START),MEM_DRIVER_LEN, ENABLE, SEED_VAL); } if(curr_memtype == MEM_FBL) { crc16Value_u16 = CRC_CalcCRC16bit((uint8_t *)(FLU_FBL_ADDR_START_OnApp),MEM_FBL_LEN, ENABLE, SEED_VAL); } return crc16Value_u16; } /*==================================================================================================*/ /* uint8_t UdsFbl_CheckMinlength(UDSpacket_t* qUDSpacket, uint16_t minLen) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: Check min request length */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* minLen : diag service min request length */ /* Return: NRC13 or positive respond code */ /*==================================================================================================*/ uint8_t UdsFbl_CheckMinlength(UDSpacket_t* qUDSpacket, uint16_t minLen) { uint8_t returnType = UDSpositiveResp; if(qUDSpacket->size < minLen) { returnType = UDSincorrectMessageLengthOrInvalidFormat; } else { /* Do Nothing */ } return returnType; } /********************************************************************************************* * Prototype * function * Parameter * parameter [in] : typedef struct{ uint32 ID; uint16 size; uint8 physical_address ; union { uint8 SID; uint8 Byte[4095]; }Data; }UDSpacket_t; * * Return code * return * * Functional Description * * Particularities and Limitations * * Expected Caller Context * *********************************************************************************************/ uint8_t StdDiagnosticHandler(void) { uint8_t sessionhandlerTableSize = sizeof(sessionhandlerTable) / sizeof(DIAG_handler_t); uint8_t sessionhandlerIndex = 0; uint8_t responseByte = 0; UDSpacket_t* qUDSpacket = &UDSpacket; uint8_t ssp; /* Handling of physical addressing requests */ for (sessionhandlerIndex = 0; sessionhandlerIndex < sessionhandlerTableSize; sessionhandlerIndex++) { /* Check the table to determine whether the current service is supported */ if (sessionhandlerTable[sessionhandlerIndex].serviceid == qUDSpacket->Data.SID) { responseByte = UdsFbl_CheckMinlength(qUDSpacket, sessionhandlerTable[sessionhandlerIndex].minLength); ssp = UDS_GET_SUB_FUNCTION_SUPPRESS_POSRSP(qUDSpacket->Data.Byte[1]); if(UDSpositiveResp == responseByte) { if((ssp == TRUE) &&(sessionhandlerTable[sessionhandlerIndex].SPRMB == TRUE)) { phy_sprmb_flag = true; /* supress positive response */ } else { phy_sprmb_flag = false; } if (sessionhandlerTable[sessionhandlerIndex].diag_sessionhandler != NULL) { responseByte = sessionhandlerTable[sessionhandlerIndex].diag_sessionhandler(qUDSpacket); } } break; } } /* No found diag service in the table */ if(sessionhandlerIndex >= sessionhandlerTableSize) { responseByte = UDSserviceNotSupported; } else { /* do nothing */ } if(UDSpositiveResp == responseByte) { udsFbl_Positive_Rsp(qUDSpacket,qUDSpacket->size,phy_sprmb_flag); } else { udsFbl_Negative_Rsp(qUDSpacket,responseByte); } requestRecved = 0; /* no request need to handle */ return responseByte; } /*==================================================================================================*/ /* uint8_t StdFuncDiagnosticHandler(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: diag service main processing function(functional address) */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ uint8_t StdFuncDiagnosticHandler(void) { uint8_t responseByte = 0; UDSpacket_t* qUDSpacket = &UDSpacket_Func; responseByte = processUdsFunctionAddrReq(qUDSpacket); /* Handling of functional addressing requests */ if((responseByte == UDSserviceNotSupported) || /* functional diagnostics don't return nrc 0x11,0x12,0x31 */ (responseByte == UDSsubfunctionNotSupported) || (responseByte == UDSrequestOutOfRange)) { responseByte = UDSnoReply; } else { /* do nothing */ } if(UDSpositiveResp == responseByte) { udsFbl_Positive_Rsp(qUDSpacket,qUDSpacket->size,func_sprmb_flag); } else { udsFbl_Negative_Rsp(qUDSpacket,responseByte); } func_requestRecved = 0; /* no request need to handle */ return responseByte; } /*==================================================================================================*/ /* void DiagM_MainFunction(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: diag service main processing function */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ void DiagM_MainFunction(void)/*5ms*/ { SessionCounterCheck(&BootIdle0.SessionCounter); eraseCounterCheck(&BootIdle0.eraseCounter); programCounterCheck(&BootIdle0.programCounter); checkRoutineCounterCheck(&BootIdle0.checkRoutineCounter); delayTimerCounterCheck(&BootIdle0.delayTimerCounter); checkDependCounterCheck(&BootIdle0.checkDependency); } /*==================================================================================================*/ /* static void uds_dataff_indication (uint16_t msg_dlc) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: uds first frame indication callback */ /* Arguments: msg_dlc:first frame dlc */ /* Return: - */ /*==================================================================================================*/ static void uds_dataff_indication (uint16_t msg_dlc) { /* stop session counter */ BootIdle0.SessionCounter = (uint16_t)0; } /*==================================================================================================*/ /* static void uds_data_indication (uint8_t msg_buf[], uint16_t msg_dlc, n_result_t n_result) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: uds data request indication callback */ /* Arguments: msg_buf:message buffer */ /* Arguments: msg_dlc:message length */ /* Arguments: n_result:request status */ /* Arguments: addr_type:functional address or physical address */ /* Return: - */ /*==================================================================================================*/ static void uds_data_indication (uint8_t msg_buf[], uint16_t msg_dlc, n_result_t n_result, uint8_t addr_type) { uint16_t u16Count; udsFbl_StopTimer(TIMER_UDS_SESSION); if (n_result != N_OK) { udsFbl_StartTimer(TIMER_UDS_SESSION); return; } else { if(addr_type == N_TATYPE_PHYSICAL) { UDSpacket.ID=0; UDSpacket.size = msg_dlc; UDSpacket.physical_address = 1; /* physical address */ for(u16Count = 0;u16Count < msg_dlc;u16Count++) { UDSpacket.Data.Byte[u16Count] = msg_buf[u16Count]; } requestRecved = 1; } else { UDSpacket_Func.ID=0; UDSpacket_Func.size = msg_dlc; UDSpacket_Func.physical_address = 0; /* functional address */ for(u16Count = 0;u16Count < msg_dlc;u16Count++) { UDSpacket_Func.Data.Byte[u16Count] = msg_buf[u16Count]; } func_requestRecved = 1; } } } /*==================================================================================================*/ /* static void uds_data_confirm (n_result_t n_result) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: uds response confirm */ /* Arguments: confirm result */ /* Return: - */ /*==================================================================================================*/ static void uds_data_confirm (n_result_t n_result) { /* start session counter */ udsFbl_StartTimer(TIMER_UDS_SESSION); } /*==================================================================================================*/ /* static void udsFBL_SendProgRsp(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: send enter program session success response */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ static void udsFBL_SendProgRsp(void) { uint8_t data_buffer[6]; data_buffer[0] = 0x50; data_buffer[1] = 0x02; data_buffer[2] = P2serverValue_L; data_buffer[3] = P2serverValue_H; data_buffer[4] = P2_serverValue_L; data_buffer[5] = P2_serverValue_H; if((*(uint32_t*)0x20000984) == 0x55AA55AA) { udsFbl_SetCurrentSessionMode(KWPDIAG_PROG_SESS_ID); udsFbl_StartTimer(TIMER_UDS_SESSION); network_send_udsmsg(data_buffer,6); } else { } } /*==================================================================================================*/ /* uds_init(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function:init the uds process funciton for cantp */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ int Uds_init (void) { nt_usdata_t usdata; requestRecved = 0; /* init no physical request recesived */ func_requestRecved = 0; /* init no functional request recesived */ phy_sprmb_flag = false; /* init no supress positive response message received flag of physical address */ func_sprmb_flag = false; /* init no supress positive response message received flag of functional address*/ BootIdle0.eraseCounter = (uint16_t)0; BootIdle0.programCounter = (uint16_t)0; BootIdle0.checkRoutineCounter = (uint16_t)0; BootIdle0.delayTimerCounter = (uint16_t)0; /*sha256_init(&md_value); */ /* md initial */ service27_init(); udsFBL_SendProgRsp(); /*IF ProgReq = TRUE,send 50 02 response */ usdata.ffindication = uds_dataff_indication; usdata.indication = uds_data_indication; usdata.confirm = uds_data_confirm; return network_reg_usdata (usdata); } /*==================================================================================================*/ /* bool udsFbl_Get_MsgRecvFlag(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function:get uds physical address message received flag */ /* Arguments: - */ /* Return: uds message received flag */ /*==================================================================================================*/ bool udsFbl_Get_MsgRecvFlag(void) { return requestRecved; } /*==================================================================================================*/ /* bool udsFbl_Get_FuncMsgRecvFlag(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function:get uds functional address message received flag */ /* Arguments: - */ /* Return: uds message received flag */ /*==================================================================================================*/ bool udsFbl_Get_FuncMsgRecvFlag(void) { return func_requestRecved; } /*==================================================================================================*/ /* void udsFbl_StartTimer(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: start specific timer(session keep,erase,flash,check memory...etc ) */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ void udsFbl_StartTimer(uint8_t timer_type) { switch (timer_type) { case TIMER_UDS_SESSION: BootIdle0.SessionCounter = BOOT_SESSIONKEEP_TIMER/5; break; case TIMER_UDS_RESET: BootIdle0.IdleResetApp = BOOT_IDLEAPPRST_TIMER/5; break; case TIMER_UDS_ERASE: BootIdle0.eraseCounter = BOOT_ERASEWAIT_TIMER/5; break; case TIMER_UDS_PROGRAM: BootIdle0.programCounter = BOOT_PROGRAMWAIT_TIMER/5; break; case TIMER_UDS_ROUTINE: BootIdle0.checkRoutineCounter = BOOT_CHECKROUTINE_TIMER/5; break; case TIMER_UDS_DELAY: BootIdle0.delayTimerCounter = BOOT_DELAY_TIMER/5; break; case TIMER_UDS_DEPENDENCY: BootIdle0.checkDependency = BOOT_CHECKDEPENDENCY_TIMER/5; break; default: break; } } /*==================================================================================================*/ /* void udsFbl_StopTimer(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: stop specific timer(session keep,erase,flash,check memory...etc ) */ /* Arguments: - */ /* Return: - */ /*==================================================================================================*/ void udsFbl_StopTimer(uint8_t timer_type) { switch (timer_type) { case TIMER_UDS_SESSION: BootIdle0.SessionCounter = (uint16_t)0; break; case TIMER_UDS_RESET: BootIdle0.IdleResetApp = (uint8_t)0; break; case TIMER_UDS_ERASE: BootIdle0.eraseCounter = (uint16_t)0; break; case TIMER_UDS_PROGRAM: BootIdle0.programCounter = (uint16_t)0; break; case TIMER_UDS_ROUTINE: BootIdle0.checkRoutineCounter = (uint16_t)0; break; case TIMER_UDS_DELAY: BootIdle0.delayTimerCounter = (uint16_t)0; break; case TIMER_UDS_DEPENDENCY: BootIdle0.checkDependency = (uint16_t)0; break; default: break; } } /*==================================================================================================*/ /* void udsFbl_Negative_Rsp(UDSpacket_t* qUDSpacket, uds_nrc nrc_type) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: uds send negative response */ /* Arguments: qUDSpacket:CAN message structure pointer */ /* Arguments: nrc_type:nrc type */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Negative_Rsp(UDSpacket_t* qUDSpacket, uds_nrc nrc_type) { if(nrc_type != UDSreqCorrectlyRx_RespPending) { udsFbl_StartTimer(TIMER_UDS_SESSION); } else { /* do nothing */ /* stop session timer during processing request */ } if(UDSnoReply == nrc_type) { /* do nothing */ } else { qUDSpacket->Data.Byte[2] = nrc_type; qUDSpacket->Data.Byte[1] = qUDSpacket->Data.Byte[0]; qUDSpacket->Data.Byte[0] = (uint8_t)0x7F; qUDSpacket->size = (uint8_t)3; network_send_udsmsg(qUDSpacket->Data.Byte,qUDSpacket->size); } } /*==================================================================================================*/ /* void udsFbl_Positive_Rsp(UDSpacket_t* qUDSpacket, uint16_t length, bool sprmb_flag) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: uds send positive response */ /* Arguments: qUDSpacket:CAN message structure pointer */ /* Arguments: length:message length */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Positive_Rsp(UDSpacket_t* qUDSpacket, uint16_t length, bool sprmb_flag) { /* start S3-server timer */ udsFbl_StartTimer(TIMER_UDS_SESSION); /* SuppressPosRspMsg is true */ if (sprmb_flag == true) { /* do not send positive response */ } else { network_send_udsmsg (qUDSpacket->Data.Byte, length); } } /*==================================================================================================*/ /* FLASH_TYPE udsFbl_Get_FlashProgram_Type(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: get current flash program type */ /* Arguments: - */ /* Return: current flash program type */ /*==================================================================================================*/ FLASH_TYPE udsFbl_Get_FlashProgram_Type(void) { return flash_program_type; } /*==================================================================================================*/ /* void udsFbl_Set_FlashProgram_Type(FLASH_TYPE type) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: set current flash program type */ /* Arguments: type:current flash program type */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_FlashProgram_Type(FLASH_TYPE type) { flash_program_type = type; } /*==================================================================================================*/ /* bool udsFbl_Get_Func_SPRMB(void) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: get supress positive response message bit flag */ /* Arguments: - */ /* Return: sprmb flag */ /*==================================================================================================*/ bool udsFbl_Get_Func_SPRMB(void) { return func_sprmb_flag; } /*==================================================================================================*/ /* void udsFbl_Set_Func_SPRMB(bool flag) */ /* -------------------------------------------------------------------------------------------------*/ /* Function: set supress positive response message bit flag */ /* Arguments: flag: sprmb flag */ /* Return: - */ /*==================================================================================================*/ void udsFbl_Set_Func_SPRMB(bool flag) { func_sprmb_flag = flag; }