1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
16 //lint -esym(754, SID) //Structure member SID not used in udsReadDtcInfoSub_0x01_0x07_0x11_0x12() and udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15()
\r
20 * General requirements
\r
22 /** @req DCM273 */ /** @req DCM272 */
\r
23 /** @req DCM039 */ /** @req DCM038 */ /** @req DCM269 */
\r
24 /** @req DCM271 */ /** @req DCM274 */ /** @req DCM275 */ /** @req DCM424 */
\r
28 #include "Dcm_Internal.h"
\r
31 #if defined(USE_MCU)
\r
38 #define ZERO_SUB_FUNCTION 0x00
\r
39 #define DCM_FORMAT_LOW_MASK 0x0F
\r
40 #define DCM_FORMAT_HIGH_MASK 0xF0
\r
41 #define DCM_MEMORY_ADDRESS_MASK 0xFFFFFF
\r
42 #define DCM_DID_HIGH_MASK 0xFF00
\r
43 #define DCM_DID_LOW_MASK 0xFF
\r
44 #define DCM_PERODICDID_HIHG_MASK 0xF200
\r
45 #define SID_AND_ALFID_LEN2 0x2
\r
46 #define SID_AND_ALFID_LEN4 0x4
\r
47 #define SID_AND_ALFID_LEN5 0x5
\r
48 #define SID_AND_ALFID_LEN6 0x6
\r
49 #define SID_AND_ALFID_LEN7 0x7
\r
51 #define BYTES_TO_DTC(hb, mb, lb) (((uint32)(hb) << 16) | ((uint32)(mb) << 8) | (uint32)(lb))
\r
52 #define DTC_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFFu)
\r
53 #define DTC_MID_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFFu)
\r
54 #define DTC_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFFu)
\r
58 boolean resetPending;
\r
59 PduIdType resetPduId;
\r
60 } DspUdsEcuResetDataType;
\r
62 static DspUdsEcuResetDataType dspUdsEcuResetData;
\r
63 static boolean dspWritePending;
\r
66 boolean reqInProgress;
\r
67 Dcm_SecLevelType reqSecLevel;
\r
68 const Dcm_DspSecurityRowType *reqSecLevelRef;
\r
69 } DspUdsSecurityAccessDataType;
\r
71 static DspUdsSecurityAccessDataType dspUdsSecurityAccesData;
\r
78 }Dcm_DspMemoryStateType;
\r
79 Dcm_DspMemoryStateType dspMemoryState;
\r
82 DCM_DDD_SOURCE_DEFAULT,
\r
84 DCM_DDD_SOURCE_ADDRESS
\r
88 uint32 PDidTxCounter;
\r
89 uint32 PDidTxCounterNumber;
\r
91 }Dcm_pDidType;/* a type to save the periodic DID and cycle */
\r
94 Dcm_pDidType dspPDid[DCM_LIMITNUMBER_PERIODDATA]; /*a buffer to save the periodic DID and cycle */
\r
95 uint8 PDidNr; /* note the number of periodic DID is used */
\r
98 Dsp_pDidRefType dspPDidRef;
\r
101 uint8 formatOrPosition; /*note the formate of address and size*/
\r
102 uint32 SourceAddressOrDid; /*note the memory address */
\r
103 uint16 Size; /*note the memory size */
\r
104 Dcm_DspDDDTpyeID DDDTpyeID;
\r
105 }Dcm_DspDDDSourceType;
\r
108 uint16 DynamicallyDid;
\r
109 Dcm_DspDDDSourceType DDDSource[DCM_MAX_DDDSOURCE_NUMBER];
\r
113 Dcm_DspDDDType dspDDD[DCM_MAX_DDD_NUMBER];
\r
117 * * static Function
\r
120 static boolean lookupReadMemory(uint32 memoryAddress,
\r
121 uint8 memoryAddressFormat,
\r
123 const Dcm_DspMemoryIdInfo **MemoryPtr);
\r
125 static boolean LookupDDD(uint16 didNr, const Dcm_DspDDDType **DDid);
\r
127 static boolean checkWriteMemoryByAddress(boolean useId,
\r
128 uint32 memoryAddress,
\r
129 uint8 memoryAddressFormat,
\r
131 const Dcm_DspMemoryIdInfo *dspMemory);
\r
140 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
141 dspUdsEcuResetData.resetPending = FALSE;
\r
143 dspWritePending = FALSE;
\r
144 dspMemoryState=DCM_MEMORY_UNUSED;
\r
145 /* clear periodic send buffer */
\r
146 memset(&dspPDidRef,0,sizeof(dspPDidRef));
\r
147 /* clear dynamically Did buffer */
\r
148 memset(&dspDDD[0],0,sizeof(dspDDD));
\r
151 void DspMemoryMainFunction(void)
\r
153 Dcm_ReturnWriteMemoryType WriteRet;
\r
154 Dcm_ReturnReadMemoryType ReadRet;
\r
155 switch(dspMemoryState)
\r
157 case DCM_MEMORY_UNUSED:
\r
159 case DCM_MEMORY_READ:
\r
160 ReadRet = Dcm_ReadMemory(DCM_PENDING,0,0,0,0);
\r
161 if(ReadRet == DCM_READ_OK)/*asynchronous writing is ok*/
\r
163 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
164 dspMemoryState = DCM_MEMORY_UNUSED;
\r
166 if(ReadRet == DCM_READ_FAILED)
\r
168 dspMemoryState = DCM_MEMORY_FAILED;
\r
171 case DCM_MEMORY_WRITE:
\r
172 WriteRet = Dcm_WriteMemory(DCM_PENDING,0,0,0,0);
\r
173 if(WriteRet == DCM_WRITE_OK)/*asynchronous writing is ok*/
\r
175 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
176 dspMemoryState = DCM_MEMORY_UNUSED;
\r
178 if(WriteRet == DCM_WRITE_FAILED)
\r
180 dspMemoryState = DCM_MEMORY_FAILED;
\r
183 case DCM_MEMORY_FAILED:
\r
184 DsdDspProcessingDone(DCM_E_GENERALPROGRAMMINGFAILURE);
\r
185 dspMemoryState = DCM_MEMORY_UNUSED;
\r
190 void DspPeriodicDIDMainFunction()
\r
193 boolean sentResponseThisLoop = FALSE;
\r
195 for(i = 0;i < dspPDidRef.PDidNr; i++)
\r
197 if(dspPDidRef.dspPDid[i].PDidTxCounterNumber > dspPDidRef.dspPDid[i].PDidTxCounter)
\r
199 dspPDidRef.dspPDid[i].PDidTxCounter++;
\r
203 if( sentResponseThisLoop == FALSE ) {
\r
204 if (E_OK == DslInternal_ResponseOnOneDataByPeriodicId(dspPDidRef.dspPDid[i].PeriodicDid)){
\r
205 dspPDidRef.dspPDid[i].PDidTxCounter = 0;
\r
206 /*AutoSar DCM 8.10.5 */
\r
207 sentResponseThisLoop = TRUE;
\r
211 /* Don't do anything - PDid will be sent next loop */
\r
218 DspMemoryMainFunction();
\r
219 DspPeriodicDIDMainFunction();
\r
223 boolean DspCheckSessionLevel(Dcm_DspSessionRowType const* const* sessionLevelRefTable)
\r
225 Std_ReturnType returnStatus;
\r
226 boolean levelFound = FALSE;
\r
227 Dcm_SesCtrlType currentSession;
\r
229 returnStatus = DslGetSesCtrlType(¤tSession);
\r
230 if (returnStatus == E_OK) {
\r
231 while ( ((*sessionLevelRefTable)->DspSessionLevel != currentSession) && (!(*sessionLevelRefTable)->Arc_EOL) ) {
\r
232 sessionLevelRefTable++;
\r
235 if (!(*sessionLevelRefTable)->Arc_EOL) {
\r
244 boolean DspCheckSecurityLevel(Dcm_DspSecurityRowType const* const* securityLevelRefTable)
\r
246 Std_ReturnType returnStatus;
\r
247 boolean levelFound = FALSE;
\r
248 Dcm_SecLevelType currentSecurityLevel;
\r
250 returnStatus = DslGetSecurityLevel(¤tSecurityLevel);
\r
251 if (returnStatus == E_OK) {
\r
252 while ( ((*securityLevelRefTable)->DspSecurityLevel != currentSecurityLevel) && (!(*securityLevelRefTable)->Arc_EOL) ) {
\r
253 securityLevelRefTable++;
\r
255 if (!(*securityLevelRefTable)->Arc_EOL) {
\r
264 static Std_ReturnType askApplicationForSessionPermission(Dcm_SesCtrlType newSessionLevel)
\r
266 Std_ReturnType returnCode = E_OK;
\r
267 const Dcm_DslSessionControlType *sesControl = DCM_Config.Dsl->DslSessionControl;
\r
268 Dcm_SesCtrlType currentSessionLevel;
\r
269 Std_ReturnType result;
\r
271 while ( (!sesControl->Arc_EOL) && (returnCode != E_SESSION_NOT_ALLOWED)) {
\r
272 if (sesControl->GetSesChgPermission != NULL) {
\r
273 result = Dcm_GetSesCtrlType(¤tSessionLevel);
\r
274 if (result == E_OK) {
\r
275 result = sesControl->GetSesChgPermission(currentSessionLevel ,newSessionLevel);
\r
276 if (result != E_OK) {
\r
277 returnCode = result;
\r
280 returnCode = E_NOT_OK;
\r
290 void DspUdsDiagnosticSessionControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
293 const Dcm_DspSessionRowType *sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow;
\r
294 Dcm_SesCtrlType reqSessionType;
\r
295 Std_ReturnType result;
\r
297 if (pduRxData->SduLength == 2) {
\r
298 reqSessionType = pduRxData->SduDataPtr[1];
\r
299 // Check if type exist in session table
\r
300 while ((sessionRow->DspSessionLevel != reqSessionType) && (!sessionRow->Arc_EOL) ) {
\r
304 if (!sessionRow->Arc_EOL) {
\r
305 result = askApplicationForSessionPermission(reqSessionType);
\r
306 if (result == E_OK) {
\r
307 DslSetSesCtrlType(reqSessionType); /** @req DCM311 */
\r
308 // Create positive response
\r
309 pduTxData->SduDataPtr[1] = reqSessionType;
\r
310 pduTxData->SduLength = 2;
\r
311 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
314 // TODO: Add handling of special case of E_FORCE_RCRRP (Dcm138)
\r
315 DsdDspProcessingDone(DCM_E_CONDITIONSNOTCORRECT); /** @req DCM308 */
\r
319 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED); /** @req DCM307 */
\r
324 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
329 void DspUdsEcuReset(const PduInfoType *pduRxData, PduIdType txPduId, PduInfoType *pduTxData)
\r
332 uint8 reqResetType;
\r
334 if (pduRxData->SduLength == 2) {
\r
335 reqResetType = pduRxData->SduDataPtr[1];
\r
337 switch (reqResetType)
\r
339 case 0x01: // Hard reset
\r
340 // TODO: Ask application for permission (Dcm373) (Dcm375) (Dcm377)
\r
342 // Schedule the reset
\r
343 dspUdsEcuResetData.resetPending = TRUE;
\r
344 dspUdsEcuResetData.resetPduId = txPduId;
\r
346 // Create positive response
\r
347 pduTxData->SduDataPtr[1] = reqResetType;
\r
348 pduTxData->SduLength = 2;
\r
349 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
353 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
359 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
364 void DspUdsClearDiagnosticInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
368 Dem_ReturnClearDTCType result;
\r
370 if (pduRxData->SduLength == 4) {
\r
371 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[1], pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3]);
\r
373 result = Dem_ClearDTC(dtc, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY); /** @req DCM005 */
\r
378 // Create positive response
\r
379 pduTxData->SduLength = 1;
\r
380 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
384 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
390 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
395 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x01_0x07_0x11_0x12(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
400 uint8 dtcStatusAvailabilityMask;
\r
401 uint8 dtcFormatIdentifier;
\r
402 uint8 dtcCountHighByte;
\r
403 uint8 dtcCountLowByte;
\r
406 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
407 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
409 // Setup the DTC filter
\r
410 switch (pduRxData->SduDataPtr[1]) /** @req DCM293 */
\r
412 case 0x01: // reportNumberOfDTCByStatusMask
\r
413 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
416 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
417 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[3], DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_YES, pduRxData->SduDataPtr[2], DEM_FILTER_FOR_FDC_NO);
\r
420 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
421 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_MIRROR_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
424 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
425 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_EMISSION_REL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
429 setDtcFilterResult = DEM_WRONG_FILTER;
\r
433 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
434 Std_ReturnType result;
\r
435 Dem_ReturnGetNumberOfFilteredDTCType getNumerResult;
\r
436 uint16 numberOfFilteredDtc;
\r
437 uint8 dtcStatusMask;
\r
438 //lint --e(826) PC-Lint exception - Suspicious pointer conversion
\r
439 //lint --e(927) PC-Lint exception - Pointer to pointer cast
\r
440 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
443 getNumerResult = Dem_GetNumberOfFilteredDtc(&numberOfFilteredDtc);
\r
444 if (getNumerResult == DEM_NUMBER_OK) {
\r
445 result = Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
446 if (result != E_OK) {
\r
450 // Create positive response (ISO 14229-1 table 251)
\r
451 txData->reportType = pduRxData->SduDataPtr[1]; // reportType
\r
452 txData->dtcStatusAvailabilityMask = dtcStatusMask; // DTCStatusAvailabilityMask
\r
453 txData->dtcFormatIdentifier = Dem_GetTranslationType(); // DTCFormatIdentifier
\r
454 txData->dtcCountHighByte = (numberOfFilteredDtc >> 8); // DTCCount high byte
\r
455 txData->dtcCountLowByte = (numberOfFilteredDtc & 0xFFu); // DTCCount low byte
\r
456 pduTxData->SduLength = 6;
\r
458 // TODO: What to do?
\r
459 responseCode = DCM_E_GENERALREJECT;
\r
463 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
466 return responseCode;
\r
470 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
472 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
473 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
477 uint8 dtcMiddleByte;
\r
480 } dtcAndStatusRecordType;
\r
485 uint8 dtcStatusAvailabilityMask;
\r
486 dtcAndStatusRecordType dtcAndStatusRecord[];
\r
489 // Setup the DTC filter
\r
490 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
492 case 0x02: // reportDTCByStatusMask
\r
493 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
496 case 0x0A: // reportSupportedDTC
\r
497 setDtcFilterResult = Dem_SetDTCFilter(DEM_DTC_STATUS_MASK_ALL, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
500 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
501 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_MIRROR_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
504 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
505 setDtcFilterResult = Dem_SetDTCFilter(pduRxData->SduDataPtr[2], DEM_DTC_KIND_EMISSION_REL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
508 case 0x15: // reportDTCWithPermanentStatus
\r
509 setDtcFilterResult = Dem_SetDTCFilter(DEM_DTC_STATUS_MASK_ALL, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PERMANENT_MEMORY, DEM_FILTER_WITH_SEVERITY_NO, VALUE_IS_NOT_USED, DEM_FILTER_FOR_FDC_NO);
\r
513 setDtcFilterResult = DEM_WRONG_FILTER;
\r
517 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
518 uint8 dtcStatusMask;
\r
519 //lint --e(826) PC-Lint exception - Suspicious pointer conversion
\r
520 //lint --e(927) PC-Lint exception - Pointer to pointer cast
\r
521 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
522 Dem_ReturnGetNextFilteredDTCType getNextFilteredDtcResult;
\r
524 Dem_EventStatusExtendedType dtcStatus;
\r
525 uint16 nrOfDtcs = 0;
\r
526 Std_ReturnType result;
\r
529 result = Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
530 if (result != E_OK) {
\r
534 // Create positive response (ISO 14229-1 table 252)
\r
535 txData->reportType = pduRxData->SduDataPtr[1];
\r
536 txData->dtcStatusAvailabilityMask = dtcStatusMask;
\r
538 if (dtcStatusMask != 0x00) { /** @req DCM008 */
\r
539 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
540 while (getNextFilteredDtcResult == DEM_FILTERED_OK) {
\r
541 txData->dtcAndStatusRecord[nrOfDtcs].dtcHighByte = DTC_HIGH_BYTE(dtc);
\r
542 txData->dtcAndStatusRecord[nrOfDtcs].dtcMiddleByte = DTC_MID_BYTE(dtc);
\r
543 txData->dtcAndStatusRecord[nrOfDtcs].dtcLowByte = DTC_LOW_BYTE(dtc);
\r
544 txData->dtcAndStatusRecord[nrOfDtcs].statusOfDtc = dtcStatus;
\r
546 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
549 if (getNextFilteredDtcResult != DEM_FILTERED_NO_MATCHING_DTC) {
\r
550 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
553 pduTxData->SduLength = (PduLengthType)(3 + (nrOfDtcs * sizeof(dtcAndStatusRecordType)));
\r
556 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
559 return responseCode;
\r
562 // PC-Lint (715 etc): Remove errors until function is filled.
\r
563 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
564 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x08(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
566 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
568 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
569 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
571 return responseCode;
\r
575 // PC-Lint (715 etc): Remove errors until function is filled.
\r
576 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
577 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x09(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
579 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
581 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
582 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
584 return responseCode;
\r
588 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x06_0x10(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
590 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
591 Dem_DTCOriginType dtcOrigin;
\r
595 // Switch on sub function
\r
596 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
598 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
599 dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY;
\r
602 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
603 dtcOrigin = DEM_DTC_ORIGIN_MIRROR_MEMORY;
\r
607 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
612 // Switch on record number
\r
613 switch (pduRxData->SduDataPtr[5])
\r
615 case 0xFF: // Report all Extended Data Records for a particular DTC
\r
616 startRecNum = 0x00;
\r
620 case 0xFE: // Report all OBD Extended Data Records for a particular DTC
\r
621 startRecNum = 0x90;
\r
625 default: // Report one specific Extended Data Records for a particular DTC
\r
626 startRecNum = pduRxData->SduDataPtr[5];
\r
627 endRecNum = startRecNum;
\r
631 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
632 Dem_ReturnGetStatusOfDTCType getStatusOfDtcResult;
\r
634 Dem_EventStatusExtendedType statusOfDtc;
\r
636 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3], pduRxData->SduDataPtr[4]);
\r
637 getStatusOfDtcResult = Dem_GetStatusOfDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, &statusOfDtc); /** @req DCM295 */ /** @req DCM475 */
\r
638 if (getStatusOfDtcResult == DEM_STATUS_OK) {
\r
639 Dem_ReturnGetExtendedDataRecordByDTCType getExtendedDataRecordByDtcResult;
\r
642 uint16 txIndex = 6;
\r
644 /** @req DCM297 */ /** @req DCM474 */ /** @req DCM386 */
\r
645 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1]; // Sub function
\r
646 pduTxData->SduDataPtr[2] = DTC_HIGH_BYTE(dtc); // DTC high byte
\r
647 pduTxData->SduDataPtr[3] = DTC_MID_BYTE(dtc); // DTC mid byte
\r
648 pduTxData->SduDataPtr[4] = DTC_LOW_BYTE(dtc); // DTC low byte
\r
649 pduTxData->SduDataPtr[5] = statusOfDtc; // DTC status
\r
650 for (recNum = startRecNum; recNum <= endRecNum; recNum++) {
\r
651 recLength = pduTxData->SduLength - (txIndex + 1); // Calculate what's left in buffer
\r
652 /** @req DCM296 */ /** @req DCM476 */ /** @req DCM382 */
\r
653 getExtendedDataRecordByDtcResult = Dem_GetExtendedDataRecordByDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, recNum, &pduTxData->SduDataPtr[txIndex+1], &recLength);
\r
654 if (getExtendedDataRecordByDtcResult == DEM_RECORD_OK) {
\r
655 pduTxData->SduDataPtr[txIndex++] = recNum;
\r
656 /* Instead of calling Dem_GetSizeOfExtendedDataRecordByDTC() the result from Dem_GetExtendedDataRecordByDTC() is used */
\r
657 /** @req DCM478 */ /** @req DCM479 */ /** @req DCM480 */
\r
658 txIndex += recLength;
\r
661 // TODO: What to do here?
\r
664 pduTxData->SduLength = txIndex;
\r
667 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
671 return responseCode;
\r
675 // PC-Lint (715 etc): Remove errors until function is filled.
\r
676 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
677 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x03(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
679 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
681 // TODO: Not supported yet
\r
682 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
684 return responseCode;
\r
688 // PC-Lint (715 etc): Remove errors until function is filled.
\r
689 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
690 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x04(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
692 // 1. Only consider Negative Response 0x10
\r
694 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
695 Dem_DTCKindType DtcType = 0;
\r
696 Dem_DTCOriginType DtcOrigin = 0;
\r
697 uint32 DtcNumber = 0;
\r
698 uint8 RecordNumber = 0;
\r
699 uint8 SizeOfTxBuf = pduTxData->SduLength;
\r
700 uint8 AvailableBufSize = 0;
\r
701 uint8 RecNumOffset = 0;
\r
703 uint16 EventIndex =0;
\r
704 uint16 FFIdNumber = 0;
\r
705 Dem_ReturnGetFreezeFrameDataByDTCType GetFFbyDtcReturnCode = DEM_GET_FFDATABYDTC_OK;
\r
706 Dem_ReturnGetStatusOfDTCType GetStatusOfDtc = DEM_STATUS_OK;
\r
707 Dem_EventStatusExtendedType DtcStatus = 0;
\r
708 Dem_EventParameterType *pEventParaTemp = NULL;
\r
710 // Now let's assume DTC has 3 bytes.
\r
711 DtcNumber = (((uint32)pduRxData->SduDataPtr[2])<<16) +
\r
712 (((uint32)pduRxData->SduDataPtr[3])<<8) +
\r
713 ((uint32)pduRxData->SduDataPtr[4]);
\r
715 RecordNumber = pduRxData->SduDataPtr[5];
\r
717 for (EventIndex = 0; DEM_Config.ConfigSet->EventParameter[EventIndex].Arc_EOL != TRUE; EventIndex++){
\r
718 // search each event linked to this DTC
\r
719 if (DEM_Config.ConfigSet->EventParameter[EventIndex].DTCClassRef->DTC == DtcNumber){
\r
720 pEventParaTemp = (Dem_EventParameterType *)(&DEM_Config.ConfigSet->EventParameter[EventIndex]);
\r
723 pEventParaTemp = NULL;
\r
726 if (pEventParaTemp != NULL) {
\r
727 DtcType = pEventParaTemp->DTCClassRef->DTCKind;
\r
728 //DtcOrigin = pEventParaTemp->EventClass->EventDestination[?];
\r
729 // now use DEM_DTC_ORIGIN_PRIMARY_MEMORY as default.
\r
730 DtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY;
\r
731 pduTxData->SduDataPtr[6 + RecNumOffset] = RecordNumber;
\r
733 // get Dids' number
\r
734 for (index = 0; pEventParaTemp->FreezeFrameClassRef[index] != NULL; index++){
\r
735 if (pEventParaTemp->FreezeFrameClassRef[index]->FFRecordNumber == RecordNumber) {
\r
736 // Calculate the Number of Dids in FF
\r
737 for (FFIdNumber = 0; pEventParaTemp->FreezeFrameClassRef[index]->FFIdClassRef[FFIdNumber].Arc_EOL != FALSE; FFIdNumber++) {
\r
742 pduTxData->SduDataPtr[7 + RecNumOffset] = FFIdNumber;
\r
745 AvailableBufSize = SizeOfTxBuf - 7 - RecNumOffset;
\r
746 GetFFbyDtcReturnCode = Dem_GetFreezeFrameDataByDTC(DtcNumber, DtcType, DtcOrigin,
\r
747 RecordNumber, &pduTxData->SduDataPtr[8 + RecNumOffset], &AvailableBufSize);
\r
748 if (GetFFbyDtcReturnCode != DEM_GET_FFDATABYDTC_OK){
\r
751 RecNumOffset = RecNumOffset + AvailableBufSize;
\r
752 pduTxData->SduLength = 8 + RecNumOffset;
\r
756 // Negative response
\r
757 switch (GetFFbyDtcReturnCode) {
\r
758 case DEM_GET_FFDATABYDTC_OK:
\r
761 responseCode = DCM_E_GENERALREJECT;
\r
762 return responseCode;
\r
765 GetStatusOfDtc = Dem_GetStatusOfDTC(DtcNumber, DtcType, DtcOrigin, &DtcStatus); /** @req DEM212 */
\r
766 switch (GetStatusOfDtc) {
\r
767 case DEM_STATUS_OK:
\r
770 responseCode = DCM_E_GENERALREJECT;
\r
771 return responseCode;
\r
775 // Positive response
\r
776 // See ISO 14229(2006) Table 254
\r
777 pduTxData->SduDataPtr[0] = 0x59; // positive response
\r
778 pduTxData->SduDataPtr[1] = 0x04; // subid
\r
779 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2]; // DTC
\r
780 pduTxData->SduDataPtr[3] = pduRxData->SduDataPtr[3];
\r
781 pduTxData->SduDataPtr[4] = pduRxData->SduDataPtr[4];
\r
782 pduTxData->SduDataPtr[5] = (uint8)DtcStatus; //status
\r
783 return responseCode;
\r
787 // PC-Lint (715 etc): Remove errors until function is filled.
\r
788 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
789 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x05(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
791 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
793 // TODO: Not supported yet
\r
794 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
796 return responseCode;
\r
800 // PC-Lint (715 etc): Remove errors until function is filled.
\r
801 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
802 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
804 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
806 // TODO: Not supported yet
\r
807 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
809 return responseCode;
\r
813 // PC-Lint (715 etc): Remove errors until function is filled.
\r
814 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
815 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x14(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
817 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
819 // TODO: Not supported yet
\r
820 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
822 return responseCode;
\r
826 void DspUdsReadDtcInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
829 // Sub function number 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15
\r
830 const uint8 sduLength[0x16] = {0, 3, 3, 6, 6, 3, 6, 4, 4, 5, 2, 2, 2, 2, 2, 3, 6, 3, 3, 3, 2, 2};
\r
832 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
834 uint8 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
837 if (subFunctionNumber <= 0x15) {
\r
838 if (pduRxData->SduLength == sduLength[subFunctionNumber]) {
\r
839 switch (subFunctionNumber)
\r
841 case 0x01: // reportNumberOfDTCByStatusMask
\r
842 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
843 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
844 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
845 responseCode = udsReadDtcInfoSub_0x01_0x07_0x11_0x12(pduRxData, pduTxData);
\r
848 case 0x02: // reportDTCByStatusMask
\r
849 case 0x0A: // reportSupportedDTC
\r
850 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
851 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
852 case 0x15: // reportDTCWithPermanentStatus
\r
853 responseCode = udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(pduRxData, pduTxData);
\r
856 case 0x08: // reportDTCBySeverityMaskRecord
\r
857 responseCode = udsReadDtcInfoSub_0x08(pduRxData, pduTxData);
\r
860 case 0x09: // reportSeverityInformationOfDTC
\r
861 responseCode = udsReadDtcInfoSub_0x09(pduRxData, pduTxData);
\r
864 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
865 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
866 responseCode = udsReadDtcInfoSub_0x06_0x10(pduRxData, pduTxData);
\r
869 case 0x03: // reportDTCSnapshotIdentidication
\r
870 responseCode = udsReadDtcInfoSub_0x03(pduRxData, pduTxData);
\r
873 case 0x04: // reportDTCSnapshotByDtcNumber
\r
874 responseCode = udsReadDtcInfoSub_0x04(pduRxData, pduTxData);
\r
877 case 0x05: // reportDTCSnapshotRecordNumber
\r
878 responseCode = udsReadDtcInfoSub_0x05(pduRxData, pduTxData);
\r
881 case 0x0B: // reportFirstTestFailedDTC
\r
882 case 0x0C: // reportFirstConfirmedDTC
\r
883 case 0x0D: // reportMostRecentTestFailedDTC
\r
884 case 0x0E: // reportMostRecentConfirmedDTC
\r
885 responseCode = udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(pduRxData, pduTxData);
\r
888 case 0x14: // reportDTCFaultDetectionCounter
\r
889 responseCode = udsReadDtcInfoSub_0x14(pduRxData, pduTxData);
\r
893 // Unknown sub function
\r
894 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
900 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
904 // Sub function out of range
\r
905 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
908 DsdDspProcessingDone(responseCode);
\r
911 ** This Function for check the pointer of Dynamically Did Sourced by Did buffer using a didNr
\r
913 static boolean LookupDDD(uint16 didNr, const Dcm_DspDDDType **DDid )
\r
916 boolean ret = FALSE;
\r
917 const Dcm_DspDDDType* DDidptr = &dspDDD[0];
\r
919 for(i = 0;((i < DCM_MAX_DDD_NUMBER) && (ret == FALSE)); i++)
\r
921 if(DDidptr->DynamicallyDid == didNr)
\r
939 static boolean lookupDid(uint16 didNr, const Dcm_DspDidType **didPtr)
\r
941 const Dcm_DspDidType *dspDid = DCM_Config.Dsp->DspDid;
\r
942 boolean didFound = FALSE;
\r
944 while ((dspDid->DspDidIdentifier != didNr) && (!dspDid->Arc_EOL)) {
\r
948 if (!dspDid->Arc_EOL) {
\r
957 static Dcm_NegativeResponseCodeType readDidData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
959 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
961 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL) && (didPtr->DspDidConditionCheckReadFnc != NULL) && (didPtr->DspDidReadDataFnc != NULL)) { /** @req DCM433 */
\r
962 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef)) { /** @req DCM434 */
\r
963 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef)) { /** @req DCM435 */
\r
964 Std_ReturnType result;
\r
965 Dcm_NegativeResponseCodeType errorCode;
\r
966 result = didPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
967 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) { /** @req DCM439 */
\r
970 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM436 */
\r
971 didLen = didPtr->DspDidSize;
\r
975 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
976 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
980 if (result == E_OK) {
\r
981 // Now ready for reading the data!
\r
982 if ((*txPos + didLen + 2) <= pduTxData->SduLength) {
\r
983 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFFu;
\r
985 pduTxData->SduDataPtr[*txPos] = didPtr->DspDidIdentifier & 0xFFu;
\r
987 result = didPtr->DspDidReadDataFnc(&pduTxData->SduDataPtr[*txPos]); /** @req DCM437 */
\r
990 if (result != E_OK) {
\r
991 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
994 else { // tx buffer full
\r
995 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
998 else { // Not possible to obtain did length
\r
999 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1002 else { // CheckRead failed
\r
1003 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1006 else { // Not allowed in current security level
\r
1007 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1010 else { // Not allowed in current session
\r
1011 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1014 else { // Read access not configured
\r
1015 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1018 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1019 // Recurse trough the rest of the dids. /** @req DCM440 */
\r
1021 for (i=0; (!didPtr->DspDidRef[i]->Arc_EOL) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
1022 responseCode = readDidData(didPtr->DspDidRef[i], pduTxData, txPos);
\r
1026 return responseCode;
\r
1030 ** This Function for read Dynamically Did data buffer Sourced by Memory address using a didNr
\r
1032 static Dcm_NegativeResponseCodeType readDDDData( Dcm_DspDDDType *PDidPtr, uint8 *Data,uint16 *Length)
\r
1036 uint8 AddressFormat;
\r
1037 uint16 SourceDataLength = 0;
\r
1038 const Dcm_DspMemoryIdInfo *SourceMemoryInfoptr = NULL;
\r
1039 const Dcm_DspDidType *SourceDidPtr = NULL;
\r
1040 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1043 for(i = 0;(i < DCM_MAX_DDDSOURCE_NUMBER) && (PDidPtr->DDDSource[i].formatOrPosition != 0)
\r
1044 &&(responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
1046 if(PDidPtr->DDDSource[i].DDDTpyeID == DCM_DDD_SOURCE_ADDRESS)
\r
1049 AddressFormat = PDidPtr->DDDSource[i].formatOrPosition&DCM_FORMAT_HIGH_MASK >> 4;
\r
1050 if(TRUE == lookupReadMemory(PDidPtr->DDDSource[i].SourceAddressOrDid,AddressFormat,
\r
1051 PDidPtr->DDDSource[i].Size, &SourceMemoryInfoptr))
\r
1053 if(DspCheckSecurityLevel(SourceMemoryInfoptr->pReadMemoryInfo->pSecurityLevel) != TRUE)
\r
1055 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1060 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1062 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
1064 Dcm_ReadMemory(DCM_INITIAL,SourceMemoryInfoptr->MemoryIdValue,
\r
1065 PDidPtr->DDDSource[i].SourceAddressOrDid,
\r
1066 PDidPtr->DDDSource[i].Size,
\r
1067 (Data + *Length));
\r
1068 *Length = *Length + PDidPtr->DDDSource[i].Size;
\r
1071 else if(PDidPtr->DDDSource[i].DDDTpyeID == DCM_DDD_SOURCE_DID)
\r
1074 if(lookupDid(PDidPtr->DDDSource[i].SourceAddressOrDid,&SourceDidPtr) == TRUE)
\r
1076 if(DspCheckSecurityLevel(SourceDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef) != TRUE)
\r
1078 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1080 if(SourceDidPtr->DspDidInfoRef->DspDidFixedLength == TRUE)
\r
1082 SourceDataLength = SourceDidPtr->DspDidSize;
\r
1086 if(SourceDidPtr->DspDidReadDataLengthFnc != NULL)
\r
1088 SourceDidPtr->DspDidReadDataLengthFnc(&SourceDataLength);
\r
1091 if((SourceDidPtr->DspDidReadDataFnc != NULL) && (SourceDataLength != 0) && (DCM_E_POSITIVERESPONSE == responseCode))
\r
1094 SourceDidPtr->DspDidReadDataFnc((Data + *Length));
\r
1095 for(dataCount = 0;dataCount < SourceDataLength;dataCount++)
\r
1097 if(dataCount < PDidPtr->DDDSource[i].Size)
\r
1099 *(Data + *Length + dataCount) = *(Data + *Length + dataCount + PDidPtr->DDDSource[i].formatOrPosition - 1);
\r
1103 *(Data + *Length + dataCount) = 0;
\r
1106 *Length = *Length + PDidPtr->DDDSource[i].Size;
\r
1110 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1115 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1121 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1124 return responseCode;
\r
1127 void DspUdsReadDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1129 /** @req DCM253 */
\r
1130 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1133 const Dcm_DspDidType *didPtr = NULL;
\r
1134 Dcm_DspDDDType *DDidPtr=NULL;
\r
1139 if ( ((pduRxData->SduLength - 1) % 2) == 0 ) {
\r
1140 nrOfDids = (pduRxData->SduLength - 1) / 2;
\r
1142 for (i = 0; (i < nrOfDids) && (responseCode == DCM_E_POSITIVERESPONSE); i++)
\r
1144 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1 + (i * 2)] << 8) + pduRxData->SduDataPtr[2 + (i * 2)];
\r
1145 if (lookupDid(didNr, &didPtr)) { /** @req DCM438 */
\r
1146 responseCode = readDidData(didPtr, pduTxData, &txPos);
\r
1149 else if(LookupDDD(didNr,(const Dcm_DspDDDType **)&DDidPtr) == TRUE)
\r
1151 /*DCM 651,DCM 652*/
\r
1152 pduTxData->SduDataPtr[txPos] = (DDidPtr->DynamicallyDid>>8) & 0xFF;
\r
1154 pduTxData->SduDataPtr[txPos] = (uint8)(DDidPtr->DynamicallyDid & 0xFF);
\r
1156 responseCode = readDDDData(DDidPtr,&(pduTxData->SduDataPtr[txPos]), &Length);
\r
1157 txPos = txPos + Length;
\r
1161 { // DID not found
\r
1162 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1167 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1170 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1171 pduTxData->SduLength = txPos;
\r
1174 DsdDspProcessingDone(responseCode);
\r
1178 static Dcm_NegativeResponseCodeType readDidScalingData(const Dcm_DspDidType *didPtr, const PduInfoType *pduTxData, uint16 *txPos)
\r
1180 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1182 if (didPtr->DspDidGetScalingInfoFnc != NULL) {
\r
1183 uint16 scalingInfoLen;
\r
1185 scalingInfoLen = didPtr->DspDidInfoRef->DspDidScalingInfoSize;
\r
1186 if ((*txPos + scalingInfoLen + 2) <= pduTxData->SduLength) {
\r
1187 Std_ReturnType result;
\r
1188 Dcm_NegativeResponseCodeType errorCode;
\r
1190 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFFu;
\r
1192 pduTxData->SduDataPtr[*txPos] = didPtr->DspDidIdentifier & 0xFFu;
\r
1194 result = didPtr->DspDidGetScalingInfoFnc(&pduTxData->SduDataPtr[*txPos], &errorCode); /** @req DCM394 */
\r
1195 *txPos += scalingInfoLen;
\r
1197 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
1198 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1201 else { // tx buffer full
\r
1202 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1205 else { // DspDidGetScalingInfoFnc null pointer
\r
1206 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1209 return responseCode;
\r
1212 void DspUdsReadScalingDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1214 /** @req DCM258 */
\r
1215 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1217 const Dcm_DspDidType *didPtr = NULL;
\r
1221 if (pduRxData->SduLength == 3) {
\r
1222 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
1223 if (lookupDid(didNr, &didPtr)) {
\r
1224 responseCode = readDidScalingData(didPtr, pduTxData, &txPos);
\r
1226 else { // DID not found
\r
1227 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1230 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1231 pduTxData->SduLength = txPos;
\r
1236 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1239 DsdDspProcessingDone(responseCode);
\r
1243 static Dcm_NegativeResponseCodeType writeDidData(const Dcm_DspDidType *didPtr, const PduInfoType *pduRxData, uint16 writeDidLen)
\r
1245 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1247 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite != NULL) && (didPtr->DspDidConditionCheckWriteFnc != NULL) && (didPtr->DspDidWriteDataFnc != NULL)) { /** @req DCM468 */
\r
1248 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSessionRef)) { /** @req DCM469 */
\r
1249 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSecurityLevelRef)) { /** @req DCM470 */
\r
1250 Std_ReturnType result;
\r
1251 Dcm_NegativeResponseCodeType errorCode;
\r
1252 result = didPtr->DspDidConditionCheckWriteFnc(&errorCode); /** @req DCM471 */
\r
1253 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
1254 uint16 didLen = 0;
\r
1255 result = E_NOT_OK;
\r
1256 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM472 */
\r
1257 didLen = didPtr->DspDidSize;
\r
1261 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
1262 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
1265 if (result == E_OK) {
\r
1266 if (didLen == writeDidLen) { /** @req DCM473 */
\r
1267 result = didPtr->DspDidWriteDataFnc(&pduRxData->SduDataPtr[3], (uint8)didLen, &responseCode); /** @req DCM395 */
\r
1270 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1273 else { // Not possible to obtain did length
\r
1274 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1277 else { // CheckRead failed
\r
1278 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1281 else { // Not allowed in current security level
\r
1282 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1285 else { // Not allowed in current session
\r
1286 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1289 else { // Read access not configured
\r
1290 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1293 return responseCode;
\r
1296 void DspUdsWriteDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1298 /** @req DCM255 */
\r
1299 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1301 const Dcm_DspDidType *didPtr = NULL;
\r
1303 uint16 didDataLength;
\r
1305 didDataLength = pduRxData->SduLength - 3;
\r
1306 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
1307 if (lookupDid(didNr, &didPtr)) { /** @req DCM467 */
\r
1308 responseCode = writeDidData(didPtr, pduRxData, didDataLength);
\r
1310 else { // DID not found
\r
1311 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1314 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1315 pduTxData->SduLength = 3;
\r
1316 pduTxData->SduDataPtr[1] = (didNr >> 8) & 0xFFu;
\r
1317 pduTxData->SduDataPtr[2] = didNr & 0xFFu;
\r
1320 DsdDspProcessingDone(responseCode);
\r
1324 void DspUdsSecurityAccess(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1326 /** @req DCM252 */
\r
1327 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1329 // Check sub function range (0x01 to 0x42)
\r
1330 if ((pduRxData->SduDataPtr[1] >= 0x01) && (pduRxData->SduDataPtr[1] <= 0x42)) {
\r
1331 boolean isRequestSeed = pduRxData->SduDataPtr[1] & 0x01u;
\r
1332 Dcm_SecLevelType requestedSecurityLevel = (pduRxData->SduDataPtr[1]-1)/2;
\r
1333 Dcm_NegativeResponseCodeType getSeedErrorCode;
\r
1335 if (isRequestSeed) {
\r
1336 // requestSeed message
\r
1337 // Check if type exist in security table
\r
1338 const Dcm_DspSecurityRowType *securityRow = &DCM_Config.Dsp->DspSecurity->DspSecurityRow[0];
\r
1339 while ((securityRow->DspSecurityLevel != requestedSecurityLevel) && (!securityRow->Arc_EOL)) {
\r
1342 if (!securityRow->Arc_EOL) {
\r
1344 if (pduRxData->SduLength == (2 + securityRow->DspSecurityADRSize)) { /** @req DCM321.RequestSeed */
\r
1345 Dcm_SecLevelType activeSecLevel;
\r
1346 Std_ReturnType result;
\r
1347 result = Dcm_GetSecurityLevel(&activeSecLevel);
\r
1348 if (result == E_OK) {
\r
1349 if (requestedSecurityLevel == activeSecLevel) { /** @req DCM323 */
\r
1350 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1351 // If same level set the seed to zeroes
\r
1352 memset(&pduTxData->SduDataPtr[2], 0, securityRow->DspSecuritySeedSize);
\r
1353 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1355 // New security level ask for seed
\r
1356 if (securityRow->GetSeed != NULL) {
\r
1357 Std_ReturnType getSeedResult;
\r
1358 getSeedResult = securityRow->GetSeed(&pduRxData->SduDataPtr[2], &pduTxData->SduDataPtr[2], &getSeedErrorCode); /** @req DCM324.RequestSeed */
\r
1359 if ((getSeedResult == E_OK) && (getSeedErrorCode == E_OK)) {
\r
1360 // Everything ok add sub function to tx message and send it.
\r
1361 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1362 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1364 dspUdsSecurityAccesData.reqSecLevel = requestedSecurityLevel;
\r
1365 dspUdsSecurityAccesData.reqSecLevelRef = securityRow;
\r
1366 dspUdsSecurityAccesData.reqInProgress = TRUE;
\r
1369 // GetSeed returned not ok
\r
1370 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1373 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1377 // TODO: What to do?
\r
1378 responseCode = DCM_E_GENERALREJECT;
\r
1384 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1388 // Requested security level not configured
\r
1389 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1393 // sendKey message
\r
1394 if (dspUdsSecurityAccesData.reqInProgress) {
\r
1395 if (pduRxData->SduLength == (2 + dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityKeySize)) { /** @req DCM321.SendKey */
\r
1396 if (requestedSecurityLevel == dspUdsSecurityAccesData.reqSecLevel) {
\r
1397 if (dspUdsSecurityAccesData.reqSecLevelRef->CompareKey != NULL) {
\r
1398 Std_ReturnType compareKeyResult;
\r
1399 compareKeyResult = dspUdsSecurityAccesData.reqSecLevelRef->CompareKey(&pduRxData->SduDataPtr[2]); /** @req DCM324.SendKey */
\r
1400 if (compareKeyResult == E_OK) {
\r
1401 // Request accepted
\r
1403 DslSetSecurityLevel(dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityLevel); /** @req DCM325 */
\r
1404 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
1405 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1406 pduTxData->SduLength = 2;
\r
1409 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1412 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1416 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1421 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1425 // sendKey request without a preceding requestSeed
\r
1426 responseCode = DCM_E_REQUESTSEQUENCEERROR;
\r
1431 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1434 DsdDspProcessingDone(responseCode);
\r
1438 static boolean lookupRoutine(uint16 routineId, const Dcm_DspRoutineType **routinePtr)
\r
1440 const Dcm_DspRoutineType *dspRoutine = DCM_Config.Dsp->DspRoutine;
\r
1441 boolean routineFound = FALSE;
\r
1443 while ((dspRoutine->DspRoutineIdentifier != routineId) && (!dspRoutine->Arc_EOL)) {
\r
1447 if (!dspRoutine->Arc_EOL) {
\r
1448 routineFound = TRUE;
\r
1449 *routinePtr = dspRoutine;
\r
1452 return routineFound;
\r
1456 static Dcm_NegativeResponseCodeType startRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1458 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1459 Std_ReturnType routineResult;
\r
1462 if ((routinePtr->DspStartRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspStartRoutine != NULL)) {
\r
1463 if (((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1464 && ((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1465 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4;
\r
1466 routineResult = routinePtr->DspStartRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM400 */ /** @req DCM401 */
\r
1467 if (routineResult != E_OK) {
\r
1468 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1472 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1476 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1479 return responseCode;
\r
1483 static Dcm_NegativeResponseCodeType stopRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1485 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1486 Std_ReturnType routineResult;
\r
1489 if ((routinePtr->DspStopRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineStop != NULL)) {
\r
1490 if (((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1491 && ((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1492 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4;
\r
1493 routineResult = routinePtr->DspStopRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM402 */ /** @req DCM403 */
\r
1494 if (routineResult != E_OK) {
\r
1495 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1499 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1503 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1506 return responseCode;
\r
1510 static Dcm_NegativeResponseCodeType requestRoutineResults(const Dcm_DspRoutineType *routinePtr, PduInfoType *pduTxData)
\r
1512 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1513 Std_ReturnType routineResult;
\r
1515 // requestRoutineResults
\r
1516 if ((routinePtr->DspRequestResultRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineRequestRes != NULL)) {
\r
1517 if ((routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4) <= pduTxData->SduLength) {
\r
1518 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4;
\r
1519 routineResult = routinePtr->DspRequestResultRoutineFnc(&pduTxData->SduDataPtr[4], &responseCode); /** @req DCM404 */ /** @req DCM405 */
\r
1520 if (routineResult != E_OK) {
\r
1521 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1525 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1529 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1532 return responseCode;
\r
1536 void DspUdsRoutineControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1538 /** @req DCM257 */
\r
1539 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1540 uint8 subFunctionNumber = 0;
\r
1541 uint16 routineId = 0;
\r
1542 const Dcm_DspRoutineType *routinePtr = NULL;
\r
1544 if (pduRxData->SduLength >= 4) {
\r
1545 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
1546 if ((subFunctionNumber > 0) && (subFunctionNumber < 4)) {
\r
1547 routineId = (uint16)((uint16)pduRxData->SduDataPtr[2] << 8) + pduRxData->SduDataPtr[3];
\r
1548 if (lookupRoutine(routineId, &routinePtr)) {
\r
1549 if (DspCheckSessionLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSessionRef)) {
\r
1550 if (DspCheckSecurityLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSecurityLevelRef)) {
\r
1551 switch (subFunctionNumber) {
\r
1552 case 0x01: // startRoutine
\r
1553 responseCode = startRoutine(routinePtr, pduRxData, pduTxData);
\r
1556 case 0x02: // stopRoutine
\r
1557 responseCode = stopRoutine(routinePtr, pduRxData, pduTxData);
\r
1560 case 0x03: // requestRoutineResults
\r
1561 responseCode = requestRoutineResults(routinePtr, pduTxData);
\r
1564 default: // This shall never happen
\r
1565 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1569 else { // Not allowed in current security level
\r
1570 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1573 else { // Not allowed in current session
\r
1574 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1577 else { // Unknown routine identifier
\r
1578 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1581 else { // Sub function not supported
\r
1582 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1587 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1590 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1591 // Add header to the positive response message
\r
1592 pduTxData->SduDataPtr[1] = subFunctionNumber;
\r
1593 pduTxData->SduDataPtr[2] = (routineId >> 8) & 0xFFu;
\r
1594 pduTxData->SduDataPtr[3] = routineId & 0xFFu;
\r
1597 DsdDspProcessingDone(responseCode);
\r
1601 void DspUdsTesterPresent(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1603 /** @req DCM251 */
\r
1604 if (pduRxData->SduLength == 2) {
\r
1605 switch (pduRxData->SduDataPtr[1])
\r
1607 case ZERO_SUB_FUNCTION:
\r
1608 DslResetSessionTimeoutTimer();
\r
1609 // Create positive response
\r
1610 pduTxData->SduDataPtr[1] = ZERO_SUB_FUNCTION;
\r
1611 pduTxData->SduLength = 2;
\r
1612 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1616 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1622 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1627 void DspUdsControlDtcSetting(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1629 /** @req DCM249 */
\r
1630 Dem_ReturnControlDTCStorageType resultCode;
\r
1632 if (pduRxData->SduLength == 2) {
\r
1633 switch (pduRxData->SduDataPtr[1])
\r
1636 resultCode = Dem_EnableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM304 */
\r
1637 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1638 pduTxData->SduDataPtr[1] = 0x01;
\r
1639 pduTxData->SduLength = 2;
\r
1640 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1643 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1648 resultCode = Dem_DisableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM406 */
\r
1649 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1650 pduTxData->SduDataPtr[1] = 0x02;
\r
1651 pduTxData->SduLength = 2;
\r
1652 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1655 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1660 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1666 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1671 void DspDcmConfirmation(PduIdType confirmPduId)
\r
1673 if (dspUdsEcuResetData.resetPending) {
\r
1674 if (confirmPduId == dspUdsEcuResetData.resetPduId) {
\r
1675 dspUdsEcuResetData.resetPending = FALSE;
\r
1676 #if defined(USE_MCU) && ( MCU_PERFORM_RESET_API == STD_ON )
\r
1677 Mcu_PerformReset();
\r
1679 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_UDS_RESET_ID, DCM_E_NOT_SUPPORTED);
\r
1686 static boolean CheckReadMemoryByAddress( boolean useId,uint32 memoryAddress,
\r
1687 uint8 memoryAddressFormat,
\r
1688 uint32 memorySize,
\r
1689 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1691 boolean ret = FALSE;
\r
1694 if(useId == FALSE)
\r
1697 if((memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1698 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1699 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1706 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1707 memoryAddress = (uint32)(memoryAddress & DCM_MEMORY_ADDRESS_MASK);
\r
1709 if((MemoryId == dspMemory->MemoryIdValue)&&
\r
1710 (memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1711 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1712 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1721 static boolean lookupReadMemory(uint32 memoryAddress,
\r
1722 uint8 memoryAddressFormat,
\r
1723 uint32 memorySize,
\r
1724 const Dcm_DspMemoryIdInfo **MemoryInfoPtr)
\r
1727 boolean memoryFound = FALSE;
\r
1728 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1730 for(i = 0; (dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE); i++)
\r
1732 if(TRUE == CheckReadMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId,memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1734 memoryFound = TRUE;
\r
1741 if (memoryFound == TRUE)
\r
1743 *MemoryInfoPtr = dspMemoryInfo;
\r
1746 return memoryFound;
\r
1749 static Dcm_NegativeResponseCodeType readMemoryData( Dcm_OpStatusType *OpStatus,
\r
1750 const Dcm_DspMemoryIdInfo *MemoryPtr,
\r
1751 uint32 MemoryAddress,
\r
1752 uint32 MemorySize,
\r
1753 PduInfoType *pduTxData)
\r
1755 Dcm_ReturnReadMemoryType ReadRet;
\r
1756 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1757 ReadRet = Dcm_ReadMemory(*OpStatus,MemoryPtr->MemoryIdValue,
\r
1760 &pduTxData->SduDataPtr[1]);
\r
1761 if(DCM_READ_FAILED == ReadRet)
\r
1763 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req Dcm644*/
\r
1765 if (DCM_READ_PENDING == ReadRet)
\r
1767 *OpStatus = DCM_READ_PENDING;
\r
1769 return responseCode;
\r
1772 /*@req Dcm442,DCM492*/
\r
1773 void DspUdsReadMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1776 uint32 MemoryAddressStart; /* low address of a memory block to read or write*/
\r
1777 uint32 MemoryIdValue; /* memory ID to read or write uint used by parameter */
\r
1778 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1779 Dcm_NegativeResponseCodeType ResponseCode;
\r
1780 uint8 MemorySizeFormat;
\r
1781 uint8 MemoryAddressFormat;
\r
1782 uint32 MemorySize;
\r
1783 uint16 MessageLength;
\r
1784 }DspUdsReadMemoryByAddressType; /*the typed used for SID read memory by address*/
\r
1786 DspUdsReadMemoryByAddressType dspReadMemoryByAddress;
\r
1787 Dcm_OpStatusType OpStatus = 0;
\r
1788 dspReadMemoryByAddress.MemoryAddressStart = 0;
\r
1789 dspReadMemoryByAddress.MemorySize = 0;
\r
1790 dspReadMemoryByAddress.MemoryIdConfigPtr = NULL;
\r
1791 dspReadMemoryByAddress.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1792 dspReadMemoryByAddress.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1793 dspReadMemoryByAddress.MemoryAddressFormat = ((uint8)(pduRxData->SduDataPtr[1])) & 0x0Fu; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1795 if((dspReadMemoryByAddress.MemoryAddressFormat == 0)||(dspReadMemoryByAddress.MemorySizeFormat == 0))
\r
1797 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/
\r
1801 dspReadMemoryByAddress.MessageLength = (uint16)(dspReadMemoryByAddress.MemoryAddressFormat + dspReadMemoryByAddress.MemorySizeFormat + SID_AND_ALFID_LEN2);
\r
1802 if(dspReadMemoryByAddress.MessageLength == (uint16)(pduRxData->SduLength))
\r
1804 /*take start address out */
\r
1805 for(i = 0; i < dspReadMemoryByAddress.MemoryAddressFormat; i++)
\r
1807 dspReadMemoryByAddress.MemoryAddressStart <<= 8;
\r
1808 dspReadMemoryByAddress.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[SID_AND_ALFID_LEN2 + i]);
\r
1811 /*take value of MemorySize out */
\r
1812 for(i = 0; i < dspReadMemoryByAddress.MemorySizeFormat; i++)
\r
1814 dspReadMemoryByAddress.MemorySize <<= 8;
\r
1815 dspReadMemoryByAddress.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i + dspReadMemoryByAddress.MemoryAddressFormat]);
\r
1817 if(dspReadMemoryByAddress.MemorySize < DCM_PROTOCAL_TP_MAX_LENGTH)
\r
1819 if(TRUE == lookupReadMemory(dspReadMemoryByAddress.MemoryAddressStart,
\r
1820 dspReadMemoryByAddress.MemoryAddressFormat,
\r
1821 dspReadMemoryByAddress.MemorySize,
\r
1822 &dspReadMemoryByAddress.MemoryIdConfigPtr))
\r
1824 if (DspCheckSecurityLevel(dspReadMemoryByAddress.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
1826 dspReadMemoryByAddress.ResponseCode = readMemoryData(&OpStatus,dspReadMemoryByAddress.MemoryIdConfigPtr,
\r
1827 dspReadMemoryByAddress.MemoryAddressStart,
\r
1828 dspReadMemoryByAddress.MemorySize,pduTxData);/*@req UDS_REQ_0x23_9*/
\r
1833 dspReadMemoryByAddress.ResponseCode = DCM_E_SECUTITYACCESSDENIED;/*@req UDS_REQ_0x23_11,@req DCM494*/
\r
1838 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x23_7,UDS_REQ_0x23_8*/
\r
1843 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1848 dspReadMemoryByAddress.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT; /*@req UDS_REQ_0x23_6*/
\r
1851 if(DCM_E_POSITIVERESPONSE == dspReadMemoryByAddress.ResponseCode)
\r
1853 pduTxData->SduLength = 1 + dspReadMemoryByAddress.MemorySize;
\r
1854 if(OpStatus == DCM_READ_PENDING)
\r
1856 dspMemoryState = DCM_MEMORY_READ;
\r
1860 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1865 DsdDspProcessingDone(dspReadMemoryByAddress.ResponseCode);
\r
1869 static boolean checkWriteMemoryByAddress(boolean useId,uint32 memoryAddress,
\r
1870 uint8 memoryAddressFormat,
\r
1871 uint32 memorySize,
\r
1872 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1874 boolean ret = FALSE;
\r
1877 if(useId == FALSE)
\r
1879 if((memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1880 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1881 && (memoryAddress + memorySize - 1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1888 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1889 memoryAddress = memoryAddress & DCM_MEMORY_ADDRESS_MASK;
\r
1891 if((MemoryId == dspMemory->MemoryIdValue) &&
\r
1892 (memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1893 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1894 && (memoryAddress + memorySize -1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1904 static boolean lookupWriteMemory(uint32 memoryAddress,
\r
1905 uint8 memoryAddressFormat,
\r
1906 uint32 memorySize,
\r
1907 const Dcm_DspMemoryIdInfo **MemoryIdConfigPtr)
\r
1910 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1911 boolean memoryFound = FALSE;
\r
1913 for(i = 0;(dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE);i++)
\r
1915 if(TRUE == checkWriteMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId, memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1917 memoryFound = TRUE;
\r
1924 if (memoryFound == TRUE)
\r
1926 *MemoryIdConfigPtr = dspMemoryInfo;
\r
1929 return memoryFound;
\r
1932 static Dcm_NegativeResponseCodeType writeMemoryData(Dcm_OpStatusType* OpStatus,
\r
1933 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr,
\r
1934 uint32 MemoryAddress,
\r
1935 uint32 MemorySize,
\r
1936 uint8 *SourceData)
\r
1938 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1939 Dcm_ReturnWriteMemoryType writeRet;
\r
1940 writeRet = Dcm_WriteMemory(*OpStatus,
\r
1941 MemoryIdConfigPtr->MemoryIdValue,
\r
1945 if(DCM_READ_FAILED == writeRet)
\r
1947 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req UDS_REQ_0X3D_16,DCM643*/
\r
1949 else if(DCM_WRITE_PENDING == writeRet)
\r
1951 *OpStatus = DCM_PENDING;
\r
1955 responseCode = DCM_E_POSITIVERESPONSE;
\r
1958 return responseCode;
\r
1961 void DspUdsWriteMemoryByAddress(const PduInfoType* pduRxData, PduInfoType* pduTxData)
\r
1964 uint32 MemoryAddressStart;
\r
1965 uint32 MemoryIdValue;
\r
1966 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1967 Dcm_NegativeResponseCodeType ResponseCode;
\r
1968 uint8 MemorySizeFormat;
\r
1969 uint8 MemoryAddressFormat;
\r
1970 uint32 MemorySize ;
\r
1971 uint16 MessageLength;
\r
1972 }DspUdsWriteMemoryType;
\r
1974 DspUdsWriteMemoryType dspUdsWriteMemory;
\r
1975 Dcm_OpStatusType OpStatus = DCM_INITIAL;
\r
1976 dspUdsWriteMemory.MemoryAddressStart = 0;
\r
1977 dspUdsWriteMemory.MemoryIdConfigPtr = NULL;
\r
1978 dspUdsWriteMemory.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1979 dspUdsWriteMemory.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x3D_3 & UDS_REQ_0x3D_5*/
\r
1980 dspUdsWriteMemory.MemoryAddressFormat = ((uint8)pduRxData->SduDataPtr[1]) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x3D_3& UDS_REQ_0x3D_4*/
\r
1981 dspUdsWriteMemory.MemorySize = 0;
\r
1983 if((dspUdsWriteMemory.MemoryAddressFormat == 0) || (dspUdsWriteMemory.MemorySizeFormat == 0)) /*@req UDS_REQ_0x3D_14*/
\r
1985 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1989 /*take value of MemorySize out */
\r
1990 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat; i++)
\r
1992 dspUdsWriteMemory.MemorySize <<= 8;
\r
1993 dspUdsWriteMemory.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i +dspUdsWriteMemory.MemoryAddressFormat]);
\r
1995 dspUdsWriteMemory.MessageLength = (uint16)(2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemorySize);
\r
1996 if(dspUdsWriteMemory.MessageLength == pduRxData->SduLength)
\r
1998 /*take Start Address out */
\r
1999 for(i = 0; i < dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
2001 dspUdsWriteMemory.MemoryAddressStart <<= 8;
\r
2002 dspUdsWriteMemory.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[2 + i]);
\r
2004 if(TRUE == lookupWriteMemory(dspUdsWriteMemory.MemoryAddressStart,
\r
2005 dspUdsWriteMemory.MemoryAddressFormat,
\r
2006 dspUdsWriteMemory.MemorySize,
\r
2007 &dspUdsWriteMemory.MemoryIdConfigPtr))
\r
2009 if (DspCheckSecurityLevel(dspUdsWriteMemory.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
2011 dspUdsWriteMemory.ResponseCode = writeMemoryData(&OpStatus,
\r
2012 dspUdsWriteMemory.MemoryIdConfigPtr,
\r
2013 dspUdsWriteMemory.MemoryAddressStart,
\r
2014 dspUdsWriteMemory.MemorySize,
\r
2015 &pduRxData->SduDataPtr[2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat]);
\r
2019 dspUdsWriteMemory.ResponseCode = DCM_E_SECUTITYACCESSDENIED; /*@req UDS_REQ_0X3D_15,Dcm490*/
\r
2024 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x3D_11,UDS_REQ_0x3D_12,Dcm489*/
\r
2029 dspUdsWriteMemory.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;/*@req UDS_REQ_0x3D_9*/
\r
2032 if(DCM_E_POSITIVERESPONSE == dspUdsWriteMemory.ResponseCode)
\r
2034 pduTxData->SduLength = 2 + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat;
\r
2035 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
2036 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
2038 pduTxData->SduDataPtr[2 + i] = pduRxData->SduDataPtr[2 + i];
\r
2039 if(OpStatus != DCM_PENDING)
\r
2041 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
2045 dspMemoryState=DCM_MEMORY_WRITE;
\r
2051 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
2055 static boolean checkPeriodicIdentifierBuffer(uint8 PeriodicDid,uint8 Length,uint8 *postion)
\r
2058 boolean ret = FALSE;
\r
2059 for(i = 0;(i < Length) && (ret == FALSE);i++)
\r
2061 if(PeriodicDid == dspPDidRef.dspPDid[i].PeriodicDid)
\r
2071 static void ClearPeriodicIdentifierBuffer(uint8 BufferEnd,uint8 postion)
\r
2073 dspPDidRef.dspPDid[postion].PeriodicDid = dspPDidRef.dspPDid[BufferEnd ].PeriodicDid;
\r
2074 dspPDidRef.dspPDid[postion].PDidTxCounter = dspPDidRef.dspPDid[BufferEnd].PDidTxCounter;
\r
2075 dspPDidRef.dspPDid[postion].PDidTxCounterNumber = dspPDidRef.dspPDid[BufferEnd].PDidTxCounterNumber;
\r
2076 dspPDidRef.dspPDid[BufferEnd].PeriodicDid = 0;
\r
2077 dspPDidRef.dspPDid[BufferEnd].PDidTxCounter = 0;
\r
2078 dspPDidRef.dspPDid[BufferEnd ].PDidTxCounterNumber = 0;
\r
2081 static Dcm_NegativeResponseCodeType readPeriodDidData(const Dcm_DspDidType *PDidPtr, uint8 *Data,uint16 *Length)
\r
2083 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2084 if ((PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL)
\r
2085 && (PDidPtr->DspDidConditionCheckReadFnc != NULL)
\r
2086 && (PDidPtr->DspDidReadDataFnc != NULL) )
\r
2088 if (DspCheckSessionLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2090 if (DspCheckSecurityLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2092 Std_ReturnType result = E_NOT_OK;
\r
2093 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2094 result = PDidPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
2095 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE))
\r
2097 result = E_NOT_OK;
\r
2098 if (PDidPtr->DspDidInfoRef->DspDidFixedLength)
\r
2100 *Length= PDidPtr->DspDidSize;
\r
2105 if(PDidPtr->DspDidReadDataLengthFnc!=NULL)
\r
2107 result = PDidPtr->DspDidReadDataLengthFnc(Length);
\r
2111 responseCode = DCM_E_GENERALREJECT;
\r
2114 if (result == E_OK)
\r
2116 result = PDidPtr->DspDidReadDataFnc(Data);
\r
2117 if (result != E_OK)
\r
2119 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2124 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2129 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2134 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2139 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2144 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2146 return responseCode;
\r
2149 static Dcm_NegativeResponseCodeType DspSavePeriodicData(uint16 didNr, uint32 periodicTransmitCounter,uint8 PdidBufferNr)
\r
2151 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2152 const Dcm_DspDidType *SourceDid = NULL;
\r
2153 Dcm_DspDDDType *DDidPtr = NULL;
\r
2155 if (TRUE == lookupDid(didNr, &SourceDid))
\r
2157 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef) == TRUE)
\r
2159 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef) == TRUE)
\r
2161 Std_ReturnType result = E_NOT_OK;
\r
2162 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2164 if(SourceDid->DspDidConditionCheckReadFnc != NULL)
\r
2166 result = SourceDid->DspDidConditionCheckReadFnc(&errorCode);
\r
2168 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE))
\r
2170 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2172 if((SourceDid->DspDidInfoRef->DspDidFixedLength!=TRUE) && (SourceDid->DspDidReadDataLengthFnc == NULL))
\r
2174 responseCode = DCM_E_GENERALREJECT;
\r
2179 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2184 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2187 else if(LookupDDD(didNr, (const Dcm_DspDDDType **)&DDidPtr) == TRUE)
\r
2189 responseCode = DCM_E_POSITIVERESPONSE;
\r
2193 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2195 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2197 dspPDidRef.dspPDid[PdidBufferNr].PeriodicDid = (uint8)didNr & DCM_DID_LOW_MASK;
\r
2198 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounter = 0;
\r
2199 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounterNumber = periodicTransmitCounter;
\r
2201 return responseCode;
\r
2203 static void ClearPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData )
\r
2205 uint16 PdidNumber;
\r
2206 uint8 PDidLowByte;
\r
2207 uint8 PdidPostion;
\r
2209 if( pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE )
\r
2211 PdidNumber = pduRxData->SduLength - 2;
\r
2212 for(i = 0;i < PdidNumber;i++)
\r
2214 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2215 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2217 dspPDidRef.PDidNr--;
\r
2218 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr, PdidPostion);
\r
2222 pduTxData->SduLength = 1;
\r
2227 UDS Service 0x2a - Read Data By Periodic Identifier
\r
2229 void DspReadDataByPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2231 /** @req DCM254 */
\r
2232 uint8 PDidLowByte;
\r
2233 uint16 PdidNumber;
\r
2234 uint8 PdidPostion;
\r
2236 uint8 PdidBufferNr;
\r
2237 uint32 periodicTransmitCounter;
\r
2238 uint16 DataLength;
\r
2239 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2240 const Dcm_DspDidType *PDidPtr = NULL;
\r
2241 Dcm_DspDDDType *DDidPtr = NULL;
\r
2242 PdidBufferNr = dspPDidRef.PDidNr;
\r
2243 if(pduRxData->SduLength > 2)
\r
2246 switch(pduRxData->SduDataPtr[1])
\r
2248 case DCM_PERIODICTRANSMIT_DEFAULT_MODE:
\r
2249 periodicTransmitCounter = 0;
\r
2251 case DCM_PERIODICTRANSMIT_SLOWRATE_MODE:
\r
2252 periodicTransmitCounter = DCM_PERIODICTRANSMIT_SLOW;
\r
2254 case DCM_PERIODICTRANSMIT_MEDIUM_MODE:
\r
2255 periodicTransmitCounter = DCM_PERIODICTRANSMIT_MEDIUM;
\r
2257 case DCM_PERIODICTRANSMIT_FAST_MODE:
\r
2258 periodicTransmitCounter = DCM_PERIODICTRANSMIT_FAST;
\r
2260 case DCM_PERIODICTRANSMIT_STOPSENDING_MODE:
\r
2261 ClearPeriodicIdentifier(pduRxData,pduTxData);
\r
2264 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2267 if((pduRxData->SduDataPtr[1] != DCM_PERIODICTRANSMIT_STOPSENDING_MODE) && responseCode == DCM_E_POSITIVERESPONSE)
\r
2269 PdidNumber = pduRxData->SduLength - 2;
\r
2270 if(1 == PdidNumber)
\r
2272 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2273 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2275 if(0 == periodicTransmitCounter)
\r
2277 if (TRUE == lookupDid(((uint16)PDidLowByte + 0xF200), &PDidPtr)) /*UDS_REQ_0x2A_1*/
\r
2279 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2280 responseCode = readPeriodDidData(PDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2281 pduTxData->SduLength = DataLength + 2;
\r
2283 else if(TRUE == LookupDDD((0xF200 + (uint16)PDidLowByte), (const Dcm_DspDDDType **)&DDidPtr))
\r
2285 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2286 responseCode = readDDDData(DDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2287 pduTxData->SduLength = DataLength + 2;
\r
2291 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2293 if(responseCode != DCM_E_POSITIVERESPONSE)
\r
2295 dspPDidRef.PDidNr--;
\r
2296 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr,PdidPostion);
\r
2301 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2302 pduTxData->SduLength = 1;
\r
2307 responseCode = DspSavePeriodicData((DCM_PERODICDID_HIHG_MASK + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2309 pduTxData->SduLength = 1;
\r
2312 else if(((PdidNumber + PdidBufferNr) <= DCM_LIMITNUMBER_PERIODDATA) && (responseCode == DCM_E_POSITIVERESPONSE)) /*UDS_REQ_0x2A_6*/
\r
2314 for(i = 0;(i < PdidNumber)&&(responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2316 PDidLowByte = pduRxData->SduDataPtr[2 + i];
\r
2317 if(checkPeriodicIdentifierBuffer(PDidLowByte,PdidBufferNr,&PdidPostion) == TRUE)
\r
2319 if(dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber != periodicTransmitCounter)
\r
2321 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2326 responseCode = DspSavePeriodicData((0xF200 + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2329 pduTxData->SduLength = 1;
\r
2334 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2336 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2338 dspPDidRef.PDidNr = PdidBufferNr;
\r
2342 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE))
\r
2344 memset(&dspPDidRef,0,sizeof(dspPDidRef));
\r
2345 pduTxData->SduLength = 1;
\r
2349 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2351 DsdDspProcessingDone(responseCode);
\r
2354 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyDid(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2357 uint16 SourceDidNr;
\r
2358 const Dcm_DspDidType *SourceDid = NULL;
\r
2359 Dcm_DspDDDType *DDid = NULL;
\r
2360 uint16 SourceLength = 0;
\r
2361 uint16 DidLength = 0;
\r
2362 uint16 Length = 0;
\r
2364 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2366 if(FALSE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2368 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2372 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2374 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2378 DDid = &dspDDD[Num];
\r
2383 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2387 if(SourceLength > DCM_MAX_DDDSOURCE_NUMBER)
\r
2389 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2392 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2394 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN4) /SID_AND_ALFID_LEN4;
\r
2395 if(((Length*SID_AND_ALFID_LEN4) == (pduRxData->SduLength - SID_AND_ALFID_LEN4)) && (Length != 0))
\r
2397 if((Length + SourceLength) <= DCM_MAX_DDDSOURCE_NUMBER)
\r
2399 for(i = 0;(i < Length) && (responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2401 SourceDidNr = (((uint16)pduRxData->SduDataPtr[SID_AND_ALFID_LEN4 + i*SID_AND_ALFID_LEN4] << 8) & DCM_DID_HIGH_MASK) + (((uint16)pduRxData->SduDataPtr[(5 + i*SID_AND_ALFID_LEN4)]) & DCM_DID_LOW_MASK);
\r
2402 if(TRUE == lookupDid(SourceDidNr, &SourceDid))/*UDS_REQ_0x2C_4*/
\r
2404 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2406 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2408 if(SourceDid->DspDidInfoRef->DspDidFixedLength == TRUE)
\r
2410 DidLength = SourceDid->DspDidSize;
\r
2414 if( SourceDid->DspDidReadDataLengthFnc != NULL)
\r
2416 SourceDid->DspDidReadDataLengthFnc(&DidLength);
\r
2419 if(DidLength != 0)
\r
2421 if((pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2422 (pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2423 (((uint16)pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4] + (uint16)pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4] - 1) <= DidLength))
\r
2425 DDid->DDDSource[i + SourceLength].formatOrPosition = pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4];
\r
2426 DDid->DDDSource[i + SourceLength].Size = pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4];
\r
2427 DDid->DDDSource[i + SourceLength].SourceAddressOrDid = SourceDid->DspDidIdentifier;
\r
2428 DDid->DDDSource[i + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_DID;
\r
2432 /*UDS_REQ_0x2C_6*/
\r
2433 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2439 /*UDS_REQ_0x2C_14*/
\r
2440 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2445 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2450 /*UDS_REQ_0x2C_19,DCM726*/
\r
2451 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2457 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2463 /*UDS_REQ_0x2C_13*/
\r
2464 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2469 /*UDS_REQ_0x2C_11*/
\r
2470 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2472 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2474 DDid->DynamicallyDid = DDIdentifier;
\r
2475 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2478 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2480 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2483 return responseCode;
\r
2486 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyAddress(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2488 uint8 LengthCount;
\r
2489 uint8 SourceCount;
\r
2491 uint8 AddressFormat;
\r
2492 uint8 MemorySizeFormat;
\r
2493 uint32 MemoryAddress = 0;
\r
2494 uint16 MemorySize = 0;
\r
2495 uint16 SourceLength = 0;
\r
2496 Dcm_DspDDDType *DDid = NULL;
\r
2497 const Dcm_DspMemoryIdInfo *SourceMemoryInfo = NULL;
\r
2499 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2501 if(FALSE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2503 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2507 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2509 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2513 DDid = &dspDDD[Num];
\r
2518 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2522 if(SourceLength >= DCM_MAX_DDDSOURCE_NUMBER)
\r
2524 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2527 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2529 AddressFormat = (uint8)pduRxData->SduDataPtr[4] & DCM_FORMAT_LOW_MASK;
\r
2530 MemorySizeFormat = (uint8)(pduRxData->SduDataPtr[4] >> 4) & DCM_FORMAT_LOW_MASK;
\r
2531 if((AddressFormat+MemorySizeFormat) != 0)
\r
2533 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN5) / (AddressFormat + MemorySizeFormat);
\r
2535 if((AddressFormat != 0) && (MemorySizeFormat != 0) && ((SourceLength+Length) <= DCM_MAX_DDDSOURCE_NUMBER))
\r
2537 if((Length != 0)&&( Length * (AddressFormat + MemorySizeFormat) == (pduRxData->SduLength - 5) ))
\r
2539 for(LengthCount = 0; (LengthCount < Length) && (responseCode == DCM_E_POSITIVERESPONSE); LengthCount++)
\r
2541 MemoryAddress = 0;
\r
2542 for(SourceCount = 0; SourceCount < AddressFormat; SourceCount++)
\r
2544 MemoryAddress = MemoryAddress << 8;
\r
2545 MemoryAddress += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2548 /*take value of MemorySize out */
\r
2550 for(SourceCount = 0; SourceCount < MemorySizeFormat; SourceCount++)
\r
2552 MemorySize = MemorySize << 8;
\r
2553 MemorySize += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + AddressFormat + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2555 if(TRUE == lookupReadMemory(MemoryAddress, AddressFormat,MemorySize,&SourceMemoryInfo))
\r
2557 if(DspCheckSecurityLevel(SourceMemoryInfo->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
2559 DDid->DDDSource[LengthCount + SourceLength].formatOrPosition = pduRxData->SduDataPtr[4];
\r
2560 DDid->DDDSource[LengthCount + SourceLength].SourceAddressOrDid = MemoryAddress;
\r
2561 DDid->DDDSource[LengthCount + SourceLength].Size = MemorySize;
\r
2562 DDid->DDDSource[LengthCount + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_ADDRESS;
\r
2563 /*UDS_REQ_0x2C_6*/
\r
2567 /*UDS_REQ_0x2C_19,DCM726*/
\r
2568 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2573 /*UDS_REQ_0x2C_15,UDS_REQ_0x2C_16*/
\r
2574 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2577 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2579 DDid->DynamicallyDid = DDIdentifier;
\r
2584 /*UDS_REQ_0x2C_11*/
\r
2585 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2590 /*UDS_REQ_0x2C_17, UDS_REQ_0x2C_18*/
\r
2591 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2595 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2597 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS;
\r
2600 return responseCode;
\r
2606 UDS Service 0x2c - Clear dynamically Did
\r
2608 static Dcm_NegativeResponseCodeType CleardynamicallyDid(uint16 DDIdentifier,const PduInfoType *pduRxData, PduInfoType * pduTxData)
\r
2610 /*UDS_REQ_0x2C_5*/
\r
2614 uint8 ClearNum = 0;
\r
2615 Dcm_DspDDDType *DDid = NULL;
\r
2616 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2618 if(pduRxData->SduLength == 4)
\r
2620 if(TRUE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2623 if((checkPeriodicIdentifierBuffer(pduRxData->SduDataPtr[3], dspPDidRef.PDidNr, &position) == TRUE)&&(pduRxData->SduDataPtr[2] == 0xF2))
\r
2625 /*UDS_REQ_0x2C_9*/
\r
2626 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2630 memset(DDid, 0, sizeof(Dcm_DspDDDType));
\r
2631 for(i = DCM_MAX_DDD_NUMBER - 1;i >= 0 ;i--) { /* find the first DDDid from bottom */
\r
2632 if (0 != dspDDD[i].DynamicallyDid) {
\r
2633 for (j = 0; j <DCM_MAX_DDD_NUMBER; j++) { /* find the first empty slot from top */
\r
2635 /* Rearrange finished */
\r
2636 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2637 pduTxData->SduLength = 2;
\r
2638 return responseCode;
\r
2640 else if (0 == dspDDD[j].DynamicallyDid) { /* find, exchange */
\r
2641 memcpy(&dspDDD[j], &dspDDD[i], sizeof(Dcm_DspDDDType));
\r
2642 memset(&dspDDD[i], 0, sizeof(Dcm_DspDDDType));
\r
2650 responseCode = DCM_E_REQUESTOUTOFRANGE; /* DDDid not found */
\r
2653 else if (pduRxData->SduDataPtr[1] == 0x03 && pduRxData->SduLength == 2){
\r
2655 memset(dspDDD, 0, (sizeof(Dcm_DspDDDType) * DCM_MAX_DDD_NUMBER));
\r
2659 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2661 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2663 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2664 pduTxData->SduLength = 2;
\r
2667 return responseCode;
\r
2670 void DspDynamicallyDefineDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2672 /*UDS_REQ_0x2C_1,DCM 259*/
\r
2675 boolean PeriodicdUse = FALSE;
\r
2676 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2677 uint16 DDIdentifier = ((((uint16)pduRxData->SduDataPtr[2]) << 8) & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[3] & DCM_DID_LOW_MASK);
\r
2678 if(pduRxData->SduLength > 2)
\r
2680 /* Check if DDID equals 0xF2 or 0xF3 */
\r
2681 if((pduRxData->SduDataPtr[2] & 0xF2) == 0xF2)
\r
2683 switch(pduRxData->SduDataPtr[1]) /*UDS_REQ_0x2C_2,DCM 646*/
\r
2685 case DCM_DDD_SUBFUNCTION_DEFINEBYDID:
\r
2686 responseCode = dynamicallyDefineDataIdentifierbyDid(DDIdentifier,pduRxData,pduTxData);
\r
2688 case DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS:
\r
2689 responseCode = dynamicallyDefineDataIdentifierbyAddress(DDIdentifier,pduRxData,pduTxData);
\r
2691 case DCM_DDD_SUBFUNCTION_CLEAR:
\r
2692 responseCode = CleardynamicallyDid(DDIdentifier,pduRxData,pduTxData);
\r
2695 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
2696 /*UDS_REQ_0x2C_10*/
\r
2702 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2704 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2706 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
2707 pduTxData->SduDataPtr[3] = pduRxData->SduDataPtr[3];
\r
2708 pduTxData->SduLength = 4;
\r
2711 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_DDD_SUBFUNCTION_CLEAR))
\r
2713 /*UDS_REQ_0x2C_7*/
\r
2714 for(i = 0;i < DCM_MAX_DDD_NUMBER;i++)
\r
2716 if(checkPeriodicIdentifierBuffer((uint8)(dspDDD[i].DynamicallyDid & DCM_DID_LOW_MASK),dspPDidRef.PDidNr,&Position) == TRUE)
\r
2718 PeriodicdUse = TRUE;
\r
2721 if(PeriodicdUse == FALSE)
\r
2723 memset(dspDDD,0,sizeof(dspDDD));
\r
2724 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2725 pduTxData->SduLength = 2;
\r
2729 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2734 /*UDS_REQ_0x2C_11*/
\r
2735 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2737 DsdDspProcessingDone(responseCode);
\r
2740 static Dcm_NegativeResponseCodeType DspIOControlReturnControlToECU(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2742 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2743 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidReturnControlToEcu == TRUE)
\r
2745 if(pduRxData->SduLength > 4)
\r
2747 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2749 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2751 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2753 DidPtr->DspDidReturnControlToEcuFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2758 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2763 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2768 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2773 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2776 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2778 DidPtr->DspDidReturnControlToEcuFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2779 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2783 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2788 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2794 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2796 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2798 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2799 pduTxData->SduDataPtr[3] = DCM_RETURN_CONTROL_TO_ECU;
\r
2802 return responseCode;
\r
2805 static Dcm_NegativeResponseCodeType DspIOControlResetToDefault(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2807 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2808 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidResetToDefault == TRUE)
\r
2810 if(pduRxData->SduLength > 4)
\r
2812 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2814 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2816 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2818 DidPtr->DspDidResetToDeaultFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2822 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2827 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2832 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2837 if(DidPtr->DspDidResetToDeaultFnc != NULL)
\r
2840 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2842 DidPtr->DspDidResetToDeaultFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2843 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2847 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2852 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2858 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2860 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2862 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize+4;
\r
2863 pduTxData->SduDataPtr[3] = DCM_RESET_TO_DEFAULT;
\r
2865 return responseCode;
\r
2869 UDS Service 0x2F - IOControl Freeze Current State
\r
2871 static Dcm_NegativeResponseCodeType DspIOControlFreezeCurrentState(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2873 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2874 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidFreezeCurrentState == TRUE)
\r
2876 if(pduRxData->SduLength > 4)
\r
2878 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2880 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2882 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2884 DidPtr->DspDidFreezeCurrentStateFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2888 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2893 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2898 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2903 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2906 if(DidPtr->DspDidControlRecordSize != 0)
\r
2908 DidPtr->DspDidFreezeCurrentStateFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2909 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2913 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2918 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2924 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2926 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2928 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2929 pduTxData->SduDataPtr[3] = DCM_FREEZE_CURRENT_STATE;
\r
2932 return responseCode;
\r
2935 static Dcm_NegativeResponseCodeType DspIOControlShortTeamAdjustment(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2937 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2938 uint8 didControlOptionRecordSize = DidPtr->DspDidControlRecordSize->DspDidControlOptionRecordSize;
\r
2939 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidShortTermAdjustment == TRUE)
\r
2941 if(pduRxData->SduLength > 4)
\r
2943 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2945 if(((((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7)) >> 3) + (didControlOptionRecordSize)) == (pduRxData->SduLength - 4))
\r
2947 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2949 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],&pduRxData->SduDataPtr[4 + didControlOptionRecordSize],&pduTxData->SduDataPtr[4],&responseCode);
\r
2953 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2956 else if((didControlOptionRecordSize) == (pduRxData->SduLength - 4))
\r
2958 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2960 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2964 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2969 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2974 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2979 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2984 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2986 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2988 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2989 pduTxData->SduDataPtr[3] = DCM_SHORT_TERM_ADJUSTMENT;
\r
2992 return responseCode;
\r
2995 void DspIOControlByDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2998 const Dcm_DspDidType *DidPtr = NULL;
\r
2999 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
3000 didNr = (pduRxData->SduDataPtr[1] << 8 & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[2] & DCM_DID_LOW_MASK);
\r
3001 if(pduRxData->SduLength > 3)
\r
3003 if(TRUE == lookupDid(didNr, &DidPtr))
\r
3005 if(FALSE == DidPtr->DspDidUsePort)
\r
3007 if(NULL != DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl)
\r
3009 if(TRUE == DspCheckSessionLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSessionRef))
\r
3011 if(TRUE == DspCheckSecurityLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSecurityLevelRef))
\r
3013 switch(pduRxData->SduDataPtr[3])
\r
3015 case DCM_RETURN_CONTROL_TO_ECU:
\r
3016 responseCode = DspIOControlReturnControlToECU(DidPtr,pduRxData,pduTxData);
\r
3018 case DCM_RESET_TO_DEFAULT:
\r
3019 responseCode = DspIOControlResetToDefault(DidPtr,pduRxData,pduTxData);
\r
3021 case DCM_FREEZE_CURRENT_STATE:
\r
3022 responseCode = DspIOControlFreezeCurrentState(DidPtr,pduRxData,pduTxData);
\r
3024 case DCM_SHORT_TERM_ADJUSTMENT:
\r
3025 responseCode = DspIOControlShortTeamAdjustment(DidPtr,pduRxData,pduTxData);
\r
3028 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3035 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
3040 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3045 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3050 /* if UsePort == True, NRC 0x10 */
\r
3051 responseCode = DCM_E_GENERALREJECT;
\r
3056 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3061 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
3063 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
3065 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
3066 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
3068 DsdDspProcessingDone(responseCode);
\r