#ifndef _UDS_FBL_SERVICE_2E_SOURCE #define _UDS_FBL_SERVICE_2E_SOURCE /******************************************************************************* ** Include Section ** *******************************************************************************/ #include "uds_fbl_mgr.h" #include "uds_fbl_service2E.h" #include /******************************************************************************* ** Version Information ** *******************************************************************************/ /******************************************************************************* ** Version Check ** *******************************************************************************/ /******************************************************************************* ** Macro definition ** *******************************************************************************/ /******************************************************************************* ** Global Data ** *******************************************************************************/ const uds_nrc nrc_2EF184[4] = { UDSrequestOutOfRange,\ UDSincorrectMessageLengthOrInvalidFormat,\ UDSsecurityAccessDenied,\ UDSconditionNotCorrect }; /*--------- <0x2E> sub function config start-------------*/ static const DIAG_sunfunction_t SessionSubfunction[] = { { 0xF184,2,true,10,3 ,vd_s_Write_Fingerprint,{nrc_2EF184, 4}} /* Write Fingerprint */ }; /*--------- <0x22> sub function config end---------------*/ /*-------------------------------------------------------*/ /******************************************************************************* ** Function Definitions ** *******************************************************************************/ static uint8_t vd_BCDToUChar(uint8_t bcdData); /* transfer BCD data to unsigned char */ static bool Check_Nrc_13_Of_Service2E(uint16_t sourceLength, uint16_t targetLength); /* Check if the length of the service request is wrong */ /*==============================================================================================================*/ /* static uint8_t vd_BCDToUChar(uint8_t bcdData) */ /* -------------------------------------------------------------------------------------------------------------*/ /* Function: transfer BCD to unsigned char */ /* Arguments: bcdData : BCD data to be transfer */ /* Return: transfered BCD data */ /*==============================================================================================================*/ static uint8_t vd_BCDToUChar(uint8_t bcdData) { uint8_t uchar; uint8_t bcd; uint8_t digit; if(bcdData <= 0x99) { uchar = 0; bcd = bcdData; digit = 1; while(bcd > 0) { uchar = ((bcd & 0x0F)*digit) + uchar; digit = digit*10; bcd = bcd >> 4; } } else { uchar = 0xFF; } return uchar; } /*==============================================================================================================*/ /* static bool Check_Nrc_13_Of_Service2E(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_Service2E(uint16_t sourceLength, uint16_t targetLength) { if (sourceLength != targetLength) { return true; } else { return false; } } /********************************************************************************************* * Prototype * uds_nrc service2E_nrc_check(UDSpacket_t* qUDSpacket) * Parameter * parameter [in] : * * Return code * return * * Functional Description * * Particularities and Limitations * * Expected Caller Context * *********************************************************************************************/ uds_nrc service2E_nrc_check(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t const kwpdiag_num = (sizeof(SessionSubfunction)/sizeof(DIAG_sunfunction_t)); uint8_t index = 0; uint16_t did = 0; uint8_t index_nrc = 0; nrc_table_t nrc_table; uint16_t length; did = (((uint16_t)qUDSpacket->Data.Byte[1])<<8); did |= ((uint16_t)qUDSpacket->Data.Byte[2]); for (index = 0; index < kwpdiag_num; index++) { if(did == SessionSubfunction[index].sub_requestsid) { break; } } if(index != kwpdiag_num) { nrc_table = SessionSubfunction[index].nrc_table; length = SessionSubfunction[index].rx_dataLen; uint8_t currentSession = 0; for (index_nrc = 0; (index_nrc < nrc_table.nrc_cnt) && (returnType == 0); index_nrc++) { switch (nrc_table.nrc_list[index_nrc]) { case UDSincorrectMessageLengthOrInvalidFormat: if (Check_Nrc_13_Of_Service2E(qUDSpacket->size, length)) { returnType = UDSincorrectMessageLengthOrInvalidFormat; } break; case UDSconditionNotCorrect: currentSession = udsFbl_GetCurrentSessionMode(); if ((currentSession & SessionSubfunction[index].session_mask) == 0) { returnType = UDSconditionNotCorrect; } break; case UDSsecurityAccessDenied: if (Uds_Nrc33_Occur(did, SessionSubfunction, kwpdiag_num)) { returnType = UDSsecurityAccessDenied; } break; default: break; } } } else { returnType = UDSrequestOutOfRange; } return returnType; /* highest priority nrc*/ } /********************************************************************************************* * Prototype * uint8_t ApplDiagWriteDataByCommonId_2E(UDSpacket_t* qUDSpacket) * Parameter * pdiagdata [in] : * diagrequestlength [in] : * * Functional Description * * Particularities and Limitations * * Expected Caller Context * *********************************************************************************************/ uint8_t ApplDiagWriteDataByCommonId_2e(UDSpacket_t* qUDSpacket) { uds_nrc returnType = 0; uint8_t index = 0; uint8_t const kwpdiag_num = (sizeof(SessionSubfunction)/sizeof(DIAG_sunfunction_t)); uint16_t did = 0; did = (((uint16_t)qUDSpacket->Data.Byte[1])<<8); did |= ((uint16_t)qUDSpacket->Data.Byte[2]); returnType = service2E_nrc_check(qUDSpacket); if (UDSpositiveResp == returnType) { for(index = 0;index < kwpdiag_num;index ++) { if(did == SessionSubfunction[index].sub_requestsid) { returnType = SessionSubfunction[index].diag_subfunc(&qUDSpacket->Data.Byte[3]); qUDSpacket->size = SessionSubfunction[index].tx_dataLen; qUDSpacket->Data.Byte[0] = UDS_GET_POSITIVE_RSP(qUDSpacket->Data.Byte[0]); } } } else { /* do nothing */ } return returnType; } /*==============================================================================================================*/ /* uint8_t vd_s_Write_Fingerprint(uint8* pdidData) */ /* -------------------------------------------------------------------------------------------------------------*/ /* Function: write finger print */ /* Arguments: pdidData : finger print info */ /* Return: write status */ /*==============================================================================================================*/ uint8_t vd_s_Write_Fingerprint(uint8_t* pdidData) { uds_nrc returnType = 0; uint8_t date_year; uint8_t date_month; uint8_t date_day; uint8_t i; uint8_t fingerprint[12]; for(i = 0; i < 12 ; i++) { fingerprint[i] = pdidData[i]; } date_year = vd_BCDToUChar(pdidData[0]); /* get year 00-99 */ date_month = vd_BCDToUChar(pdidData[1]); /* get month 01-12 */ date_day = vd_BCDToUChar(pdidData[2]); /* get day 01-31 */ if((date_year > 99) || (date_month > 12) || (date_month == 0) || (date_day > 31) || (date_day == 0)) { returnType = UDSrequestOutOfRange; /* invalid date data */ } else { returnType = Dataflash_Common_WriteToRAM(DID_FINGERPRINTF,fingerprint); if(returnType != 0) { returnType = UDSgeneralProgrammingFailure; } else { /* do nothing */ } } return returnType; } /******************************************************************************* ** End of File ** *******************************************************************************/ #endif /*_UDS_FBL_SERVICE_2E_SOURCE*/