#ifndef _UDS_FBL_SERVICE_37_SOURCE #define _UDS_FBL_SERVICE_37_SOURCE /******************************************************************************* ** Include Section ** *******************************************************************************/ #include "uds_fbl_mgr.h" #include "uds_fbl_service37.h" /******************************************************************************* ** Version Information ** *******************************************************************************/ /******************************************************************************* ** Version Check ** *******************************************************************************/ /******************************************************************************* ** Macro definition ** *******************************************************************************/ /******************************************************************************* ** Global Data ** *******************************************************************************/ const uds_nrc nrc_3700[2] = { UDSrequestSequenceError,\ UDSincorrectMessageLengthOrInvalidFormat }; /*--------- <0x37> sub function config start-------------*/ static const DIAG_sunfunction_t SessionSubfunction[] = { {0x00,2,true,1,1,NULL,{nrc_3700, 2}} }; extern uint8_t uds_u8FLUFBLFlashSession; extern void service31_Set_Program_Info(uint8_t type, uint8_t download_sts, uint8_t check_sts); /*--------- <0x37>sub function config end---------------*/ /*-------------------------------------------------------*/ /******************************************************************************* ** Function Definitions ** *******************************************************************************/ /*===============================================================================================*/ /* static bool Check_Nrc_24_Of_Service37(uint32_t downloadAddr, uint32_t requestEndAddr) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: Check whether the data has been downloaded before 37 service implementation */ /* Arguments: downloadAddr : download address */ /* requestEndAddr : request end address */ /* Return: Yes or No */ /*===============================================================================================*/ static bool Check_Nrc_24_Of_Service37(uint32_t downloadAddr, uint32_t requestEndAddr) { bool nrcFlag; bool requestdl; requestdl = udsFbl_Get_Request_Is_Trigger(); if((downloadAddr != requestEndAddr + 1) || /* The programming process is not completed */ (requestdl == false)) /* The RequestDownload service is not active */ { nrcFlag = true; } else { nrcFlag = false; } return nrcFlag; } /*===============================================================================================*/ /* static bool Check_Nrc_13_Of_Service37(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 */ /*===============================================================================================*/ static bool Check_Nrc_13_Of_Service37(uint16_t sourceLength, uint16_t targetLength) { if (sourceLength != targetLength) { return true; } else { return false; } } /*===============================================================================================*/ /* uds_nrc UdsFbl_RequestTransferExit37xx(UDSpacket_t* qUDSpacket, uint16_t crcValue) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 37 Service specific processing functions */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* crcValue : Block checksum bytes */ /* Return: Response type */ /*===============================================================================================*/ uds_nrc UdsFbl_RequestTransferExit37xx(UDSpacket_t* qUDSpacket, uint16_t crcValue) { udsFbl_Set_Request_Is_Trigger(false); udsFbl_Set_DownloadStatus(TRUE); udsFbl_Set_Download_Addr(0); qUDSpacket->Data.Byte[0] = UDS_GET_POSITIVE_RSP(qUDSpacket->Data.Byte[0]); qUDSpacket->Data.Byte[1] = (uint8_t)((crcValue>>8) & 0xFF); qUDSpacket->Data.Byte[2] = (uint8_t)(crcValue & 0xFF); qUDSpacket->size = 3; return 0; } /*===============================================================================================*/ /* uds_nrc service37_nrc_check(UDSpacket_t* qUDSpacket) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 37 service negative response judgment */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: Response type */ /*===============================================================================================*/ uds_nrc service37_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 currentSession; uint32_t downloadAddr = udsFbl_Get_Download_Addr(); uint32_t requestEndAddr = udsFbl_Get_Request_EndAddr(); for (index = 0; index < kwpdiag_num; index++) { nrc_table_t nrc_table = SessionSubfunction[index].nrc_table; uint16_t length = SessionSubfunction[index].rx_dataLen; uint8_t index_nrc = 0; /* Judge abnormal situations according to NRC priority */ for (index_nrc = 0; (index_nrc < nrc_table.nrc_cnt) && (returnType == 0); index_nrc++) { switch (nrc_table.nrc_list[index_nrc]) { case UDSserviceNotSupportedInActSes: currentSession = udsFbl_GetCurrentSessionMode(); if ((currentSession & SessionSubfunction[index].session_mask) == 0) { returnType = UDSserviceNotSupportedInActSes; } break; /*case UDSsecurityAccessDenied: if (Uds_Nrc33_Occur((uint16_t)subFunc, SessionSubfunction, kwpdiag_num)) { returnType = UDSsecurityAccessDenied; } break;*/ case UDSrequestSequenceError: if (Check_Nrc_24_Of_Service37(downloadAddr, requestEndAddr)) { returnType = UDSrequestSequenceError; } break; case UDSincorrectMessageLengthOrInvalidFormat: if (Check_Nrc_13_Of_Service37(qUDSpacket->size, length)) { returnType = UDSincorrectMessageLengthOrInvalidFormat; } break; default: break; } } } return returnType; /* return highest priority nrc*/ } /*===============================================================================================*/ /* uint8_t ApplDiag_RequestTransferExit_37(UDSpacket_t* qUDSpacket) */ /* ----------------------------------------------------------------------------------------------*/ /* Function: 37 service entry processing function */ /* Arguments: qUDSpacket : CAN message structure pointer */ /* Return: Response type */ /*===============================================================================================*/ uint8_t ApplDiag_RequestTransferExit_37(UDSpacket_t* qUDSpacket) { uds_nrc returnType; uint8_t curr_memtype; uint16_t crcValue; crcValue = udsFbl_GetCrcValue(); returnType = service37_nrc_check(qUDSpacket); if(uds_u8FLUFBLFlashSession == 0x01) { uds_u8FLUFBLFlashSession = 0x00; } curr_memtype = udsFbl_Get_Curr_Download_Type(); service31_Set_Program_Info(curr_memtype,TRUE,FALSE); if(UDSpositiveResp == returnType) { returnType = UdsFbl_RequestTransferExit37xx(qUDSpacket, crcValue); } else { /* do nothing */ } return returnType; } /******************************************************************************* ** End of File ** *******************************************************************************/ #endif /*_UDS_FBL_SERVICE_37_SOURCE*/