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, &errorCode); /** @req DCM395 */
\r
1268 if ((result != E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
1269 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1273 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1276 else { // Not possible to obtain did length
\r
1277 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1280 else { // CheckRead failed
\r
1281 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1284 else { // Not allowed in current security level
\r
1285 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1288 else { // Not allowed in current session
\r
1289 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1292 else { // Read access not configured
\r
1293 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1296 return responseCode;
\r
1299 void DspUdsWriteDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1301 /** @req DCM255 */
\r
1302 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1304 const Dcm_DspDidType *didPtr = NULL;
\r
1306 uint16 didDataLength;
\r
1308 didDataLength = pduRxData->SduLength - 3;
\r
1309 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
1310 if (lookupDid(didNr, &didPtr)) { /** @req DCM467 */
\r
1311 responseCode = writeDidData(didPtr, pduRxData, didDataLength);
\r
1313 else { // DID not found
\r
1314 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1317 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1318 pduTxData->SduLength = 3;
\r
1319 pduTxData->SduDataPtr[1] = (didNr >> 8) & 0xFFu;
\r
1320 pduTxData->SduDataPtr[2] = didNr & 0xFFu;
\r
1323 DsdDspProcessingDone(responseCode);
\r
1327 void DspUdsSecurityAccess(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1329 /** @req DCM252 */
\r
1330 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1332 // Check sub function range (0x01 to 0x42)
\r
1333 if ((pduRxData->SduDataPtr[1] >= 0x01) && (pduRxData->SduDataPtr[1] <= 0x42)) {
\r
1334 boolean isRequestSeed = pduRxData->SduDataPtr[1] & 0x01u;
\r
1335 Dcm_SecLevelType requestedSecurityLevel = (pduRxData->SduDataPtr[1]-1)/2;
\r
1336 Dcm_NegativeResponseCodeType getSeedErrorCode;
\r
1338 if (isRequestSeed) {
\r
1339 // requestSeed message
\r
1340 // Check if type exist in security table
\r
1341 const Dcm_DspSecurityRowType *securityRow = &DCM_Config.Dsp->DspSecurity->DspSecurityRow[0];
\r
1342 while ((securityRow->DspSecurityLevel != requestedSecurityLevel) && (!securityRow->Arc_EOL)) {
\r
1345 if (!securityRow->Arc_EOL) {
\r
1347 if (pduRxData->SduLength == (2 + securityRow->DspSecurityADRSize)) { /** @req DCM321.RequestSeed */
\r
1348 Dcm_SecLevelType activeSecLevel;
\r
1349 Std_ReturnType result;
\r
1350 result = Dcm_GetSecurityLevel(&activeSecLevel);
\r
1351 if (result == E_OK) {
\r
1352 if (requestedSecurityLevel == activeSecLevel) { /** @req DCM323 */
\r
1353 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1354 // If same level set the seed to zeroes
\r
1355 memset(&pduTxData->SduDataPtr[2], 0, securityRow->DspSecuritySeedSize);
\r
1356 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1358 // New security level ask for seed
\r
1359 if (securityRow->GetSeed != NULL) {
\r
1360 Std_ReturnType getSeedResult;
\r
1361 getSeedResult = securityRow->GetSeed(&pduRxData->SduDataPtr[2], &pduTxData->SduDataPtr[2], &getSeedErrorCode); /** @req DCM324.RequestSeed */
\r
1362 if ((getSeedResult == E_OK) && (getSeedErrorCode == E_OK)) {
\r
1363 // Everything ok add sub function to tx message and send it.
\r
1364 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1365 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1367 dspUdsSecurityAccesData.reqSecLevel = requestedSecurityLevel;
\r
1368 dspUdsSecurityAccesData.reqSecLevelRef = securityRow;
\r
1369 dspUdsSecurityAccesData.reqInProgress = TRUE;
\r
1372 // GetSeed returned not ok
\r
1373 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1376 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1380 // TODO: What to do?
\r
1381 responseCode = DCM_E_GENERALREJECT;
\r
1387 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1391 // Requested security level not configured
\r
1392 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1396 // sendKey message
\r
1397 if (dspUdsSecurityAccesData.reqInProgress) {
\r
1398 if (pduRxData->SduLength == (2 + dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityKeySize)) { /** @req DCM321.SendKey */
\r
1399 if (requestedSecurityLevel == dspUdsSecurityAccesData.reqSecLevel) {
\r
1400 if (dspUdsSecurityAccesData.reqSecLevelRef->CompareKey != NULL) {
\r
1401 Std_ReturnType compareKeyResult;
\r
1402 compareKeyResult = dspUdsSecurityAccesData.reqSecLevelRef->CompareKey(&pduRxData->SduDataPtr[2]); /** @req DCM324.SendKey */
\r
1403 if (compareKeyResult == E_OK) {
\r
1404 // Request accepted
\r
1406 DslSetSecurityLevel(dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityLevel); /** @req DCM325 */
\r
1407 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
1408 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1409 pduTxData->SduLength = 2;
\r
1412 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1415 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1419 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1424 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1428 // sendKey request without a preceding requestSeed
\r
1429 responseCode = DCM_E_REQUESTSEQUENCEERROR;
\r
1434 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1437 DsdDspProcessingDone(responseCode);
\r
1441 static boolean lookupRoutine(uint16 routineId, const Dcm_DspRoutineType **routinePtr)
\r
1443 const Dcm_DspRoutineType *dspRoutine = DCM_Config.Dsp->DspRoutine;
\r
1444 boolean routineFound = FALSE;
\r
1446 while ((dspRoutine->DspRoutineIdentifier != routineId) && (!dspRoutine->Arc_EOL)) {
\r
1450 if (!dspRoutine->Arc_EOL) {
\r
1451 routineFound = TRUE;
\r
1452 *routinePtr = dspRoutine;
\r
1455 return routineFound;
\r
1459 static Dcm_NegativeResponseCodeType startRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1461 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1462 Std_ReturnType routineResult;
\r
1465 if ((routinePtr->DspStartRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspStartRoutine != NULL)) {
\r
1466 if (((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1467 && ((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1468 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4;
\r
1469 routineResult = routinePtr->DspStartRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM400 */ /** @req DCM401 */
\r
1470 if (routineResult != E_OK) {
\r
1471 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1475 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1479 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1482 return responseCode;
\r
1486 static Dcm_NegativeResponseCodeType stopRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1488 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1489 Std_ReturnType routineResult;
\r
1492 if ((routinePtr->DspStopRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineStop != NULL)) {
\r
1493 if (((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1494 && ((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1495 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4;
\r
1496 routineResult = routinePtr->DspStopRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM402 */ /** @req DCM403 */
\r
1497 if (routineResult != E_OK) {
\r
1498 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1502 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1506 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1509 return responseCode;
\r
1513 static Dcm_NegativeResponseCodeType requestRoutineResults(const Dcm_DspRoutineType *routinePtr, PduInfoType *pduTxData)
\r
1515 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1516 Std_ReturnType routineResult;
\r
1518 // requestRoutineResults
\r
1519 if ((routinePtr->DspRequestResultRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineRequestRes != NULL)) {
\r
1520 if ((routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4) <= pduTxData->SduLength) {
\r
1521 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4;
\r
1522 routineResult = routinePtr->DspRequestResultRoutineFnc(&pduTxData->SduDataPtr[4], &responseCode); /** @req DCM404 */ /** @req DCM405 */
\r
1523 if (routineResult != E_OK) {
\r
1524 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1528 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1532 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1535 return responseCode;
\r
1539 void DspUdsRoutineControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1541 /** @req DCM257 */
\r
1542 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1543 uint8 subFunctionNumber = 0;
\r
1544 uint16 routineId = 0;
\r
1545 const Dcm_DspRoutineType *routinePtr = NULL;
\r
1547 if (pduRxData->SduLength >= 4) {
\r
1548 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
1549 if ((subFunctionNumber > 0) && (subFunctionNumber < 4)) {
\r
1550 routineId = (uint16)((uint16)pduRxData->SduDataPtr[2] << 8) + pduRxData->SduDataPtr[3];
\r
1551 if (lookupRoutine(routineId, &routinePtr)) {
\r
1552 if (DspCheckSessionLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSessionRef)) {
\r
1553 if (DspCheckSecurityLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSecurityLevelRef)) {
\r
1554 switch (subFunctionNumber) {
\r
1555 case 0x01: // startRoutine
\r
1556 responseCode = startRoutine(routinePtr, pduRxData, pduTxData);
\r
1559 case 0x02: // stopRoutine
\r
1560 responseCode = stopRoutine(routinePtr, pduRxData, pduTxData);
\r
1563 case 0x03: // requestRoutineResults
\r
1564 responseCode = requestRoutineResults(routinePtr, pduTxData);
\r
1567 default: // This shall never happen
\r
1568 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1572 else { // Not allowed in current security level
\r
1573 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1576 else { // Not allowed in current session
\r
1577 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1580 else { // Unknown routine identifier
\r
1581 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1584 else { // Sub function not supported
\r
1585 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1590 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1593 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1594 // Add header to the positive response message
\r
1595 pduTxData->SduDataPtr[1] = subFunctionNumber;
\r
1596 pduTxData->SduDataPtr[2] = (routineId >> 8) & 0xFFu;
\r
1597 pduTxData->SduDataPtr[3] = routineId & 0xFFu;
\r
1600 DsdDspProcessingDone(responseCode);
\r
1604 void DspUdsTesterPresent(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1606 /** @req DCM251 */
\r
1607 if (pduRxData->SduLength == 2) {
\r
1608 switch (pduRxData->SduDataPtr[1])
\r
1610 case ZERO_SUB_FUNCTION:
\r
1611 DslResetSessionTimeoutTimer();
\r
1612 // Create positive response
\r
1613 pduTxData->SduDataPtr[1] = ZERO_SUB_FUNCTION;
\r
1614 pduTxData->SduLength = 2;
\r
1615 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1619 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1625 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1630 void DspUdsControlDtcSetting(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1632 /** @req DCM249 */
\r
1633 Dem_ReturnControlDTCStorageType resultCode;
\r
1635 if (pduRxData->SduLength == 2) {
\r
1636 switch (pduRxData->SduDataPtr[1])
\r
1639 resultCode = Dem_EnableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM304 */
\r
1640 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1641 pduTxData->SduDataPtr[1] = 0x01;
\r
1642 pduTxData->SduLength = 2;
\r
1643 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1646 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1651 resultCode = Dem_DisableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM406 */
\r
1652 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1653 pduTxData->SduDataPtr[1] = 0x02;
\r
1654 pduTxData->SduLength = 2;
\r
1655 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1658 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1663 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1669 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1674 void DspDcmConfirmation(PduIdType confirmPduId)
\r
1676 if (dspUdsEcuResetData.resetPending) {
\r
1677 if (confirmPduId == dspUdsEcuResetData.resetPduId) {
\r
1678 dspUdsEcuResetData.resetPending = FALSE;
\r
1679 #if defined(USE_MCU) && ( MCU_PERFORM_RESET_API == STD_ON )
\r
1680 Mcu_PerformReset();
\r
1682 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_UDS_RESET_ID, DCM_E_NOT_SUPPORTED);
\r
1689 static boolean CheckReadMemoryByAddress( boolean useId,uint32 memoryAddress,
\r
1690 uint8 memoryAddressFormat,
\r
1691 uint32 memorySize,
\r
1692 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1694 boolean ret = FALSE;
\r
1697 if(useId == FALSE)
\r
1700 if((memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1701 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1702 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1709 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1710 memoryAddress = (uint32)(memoryAddress & DCM_MEMORY_ADDRESS_MASK);
\r
1712 if((MemoryId == dspMemory->MemoryIdValue)&&
\r
1713 (memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1714 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1715 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1724 static boolean lookupReadMemory(uint32 memoryAddress,
\r
1725 uint8 memoryAddressFormat,
\r
1726 uint32 memorySize,
\r
1727 const Dcm_DspMemoryIdInfo **MemoryInfoPtr)
\r
1730 boolean memoryFound = FALSE;
\r
1731 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1733 for(i = 0; (dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE); i++)
\r
1735 if(TRUE == CheckReadMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId,memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1737 memoryFound = TRUE;
\r
1744 if (memoryFound == TRUE)
\r
1746 *MemoryInfoPtr = dspMemoryInfo;
\r
1749 return memoryFound;
\r
1752 static Dcm_NegativeResponseCodeType readMemoryData( Dcm_OpStatusType *OpStatus,
\r
1753 const Dcm_DspMemoryIdInfo *MemoryPtr,
\r
1754 uint32 MemoryAddress,
\r
1755 uint32 MemorySize,
\r
1756 PduInfoType *pduTxData)
\r
1758 Dcm_ReturnReadMemoryType ReadRet;
\r
1759 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1760 ReadRet = Dcm_ReadMemory(*OpStatus,MemoryPtr->MemoryIdValue,
\r
1763 &pduTxData->SduDataPtr[1]);
\r
1764 if(DCM_READ_FAILED == ReadRet)
\r
1766 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req Dcm644*/
\r
1768 if (DCM_READ_PENDING == ReadRet)
\r
1770 *OpStatus = DCM_READ_PENDING;
\r
1772 return responseCode;
\r
1775 /*@req Dcm442,DCM492*/
\r
1776 void DspUdsReadMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1779 uint32 MemoryAddressStart; /* low address of a memory block to read or write*/
\r
1780 uint32 MemoryIdValue; /* memory ID to read or write uint used by parameter */
\r
1781 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1782 Dcm_NegativeResponseCodeType ResponseCode;
\r
1783 uint8 MemorySizeFormat;
\r
1784 uint8 MemoryAddressFormat;
\r
1785 uint32 MemorySize;
\r
1786 uint16 MessageLength;
\r
1787 }DspUdsReadMemoryByAddressType; /*the typed used for SID read memory by address*/
\r
1789 DspUdsReadMemoryByAddressType dspReadMemoryByAddress;
\r
1790 Dcm_OpStatusType OpStatus = 0;
\r
1791 dspReadMemoryByAddress.MemoryAddressStart = 0;
\r
1792 dspReadMemoryByAddress.MemorySize = 0;
\r
1793 dspReadMemoryByAddress.MemoryIdConfigPtr = NULL;
\r
1794 dspReadMemoryByAddress.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1795 dspReadMemoryByAddress.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1796 dspReadMemoryByAddress.MemoryAddressFormat = ((uint8)(pduRxData->SduDataPtr[1])) & 0x0Fu; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1798 if((dspReadMemoryByAddress.MemoryAddressFormat == 0)||(dspReadMemoryByAddress.MemorySizeFormat == 0))
\r
1800 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/
\r
1804 dspReadMemoryByAddress.MessageLength = (uint16)(dspReadMemoryByAddress.MemoryAddressFormat + dspReadMemoryByAddress.MemorySizeFormat + SID_AND_ALFID_LEN2);
\r
1805 if(dspReadMemoryByAddress.MessageLength == (uint16)(pduRxData->SduLength))
\r
1807 /*take start address out */
\r
1808 for(i = 0; i < dspReadMemoryByAddress.MemoryAddressFormat; i++)
\r
1810 dspReadMemoryByAddress.MemoryAddressStart <<= 8;
\r
1811 dspReadMemoryByAddress.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[SID_AND_ALFID_LEN2 + i]);
\r
1814 /*take value of MemorySize out */
\r
1815 for(i = 0; i < dspReadMemoryByAddress.MemorySizeFormat; i++)
\r
1817 dspReadMemoryByAddress.MemorySize <<= 8;
\r
1818 dspReadMemoryByAddress.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i + dspReadMemoryByAddress.MemoryAddressFormat]);
\r
1820 if(dspReadMemoryByAddress.MemorySize < DCM_PROTOCAL_TP_MAX_LENGTH)
\r
1822 if(TRUE == lookupReadMemory(dspReadMemoryByAddress.MemoryAddressStart,
\r
1823 dspReadMemoryByAddress.MemoryAddressFormat,
\r
1824 dspReadMemoryByAddress.MemorySize,
\r
1825 &dspReadMemoryByAddress.MemoryIdConfigPtr))
\r
1827 if (DspCheckSecurityLevel(dspReadMemoryByAddress.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
1829 dspReadMemoryByAddress.ResponseCode = readMemoryData(&OpStatus,dspReadMemoryByAddress.MemoryIdConfigPtr,
\r
1830 dspReadMemoryByAddress.MemoryAddressStart,
\r
1831 dspReadMemoryByAddress.MemorySize,pduTxData);/*@req UDS_REQ_0x23_9*/
\r
1836 dspReadMemoryByAddress.ResponseCode = DCM_E_SECUTITYACCESSDENIED;/*@req UDS_REQ_0x23_11,@req DCM494*/
\r
1841 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x23_7,UDS_REQ_0x23_8*/
\r
1846 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1851 dspReadMemoryByAddress.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT; /*@req UDS_REQ_0x23_6*/
\r
1854 if(DCM_E_POSITIVERESPONSE == dspReadMemoryByAddress.ResponseCode)
\r
1856 pduTxData->SduLength = 1 + dspReadMemoryByAddress.MemorySize;
\r
1857 if(OpStatus == DCM_READ_PENDING)
\r
1859 dspMemoryState = DCM_MEMORY_READ;
\r
1863 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1868 DsdDspProcessingDone(dspReadMemoryByAddress.ResponseCode);
\r
1872 static boolean checkWriteMemoryByAddress(boolean useId,uint32 memoryAddress,
\r
1873 uint8 memoryAddressFormat,
\r
1874 uint32 memorySize,
\r
1875 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1877 boolean ret = FALSE;
\r
1880 if(useId == FALSE)
\r
1882 if((memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1883 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1884 && (memoryAddress + memorySize - 1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1891 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1892 memoryAddress = memoryAddress & DCM_MEMORY_ADDRESS_MASK;
\r
1894 if((MemoryId == dspMemory->MemoryIdValue) &&
\r
1895 (memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1896 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1897 && (memoryAddress + memorySize -1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1907 static boolean lookupWriteMemory(uint32 memoryAddress,
\r
1908 uint8 memoryAddressFormat,
\r
1909 uint32 memorySize,
\r
1910 const Dcm_DspMemoryIdInfo **MemoryIdConfigPtr)
\r
1913 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1914 boolean memoryFound = FALSE;
\r
1916 for(i = 0;(dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE);i++)
\r
1918 if(TRUE == checkWriteMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId, memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1920 memoryFound = TRUE;
\r
1927 if (memoryFound == TRUE)
\r
1929 *MemoryIdConfigPtr = dspMemoryInfo;
\r
1932 return memoryFound;
\r
1935 static Dcm_NegativeResponseCodeType writeMemoryData(Dcm_OpStatusType* OpStatus,
\r
1936 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr,
\r
1937 uint32 MemoryAddress,
\r
1938 uint32 MemorySize,
\r
1939 uint8 *SourceData)
\r
1941 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1942 Dcm_ReturnWriteMemoryType writeRet;
\r
1943 writeRet = Dcm_WriteMemory(*OpStatus,
\r
1944 MemoryIdConfigPtr->MemoryIdValue,
\r
1948 if(DCM_READ_FAILED == writeRet)
\r
1950 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req UDS_REQ_0X3D_16,DCM643*/
\r
1952 else if(DCM_WRITE_PENDING == writeRet)
\r
1954 *OpStatus = DCM_PENDING;
\r
1958 responseCode = DCM_E_POSITIVERESPONSE;
\r
1961 return responseCode;
\r
1964 void DspUdsWriteMemoryByAddress(const PduInfoType* pduRxData, PduInfoType* pduTxData)
\r
1967 uint32 MemoryAddressStart;
\r
1968 uint32 MemoryIdValue;
\r
1969 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1970 Dcm_NegativeResponseCodeType ResponseCode;
\r
1971 uint8 MemorySizeFormat;
\r
1972 uint8 MemoryAddressFormat;
\r
1973 uint32 MemorySize ;
\r
1974 uint16 MessageLength;
\r
1975 }DspUdsWriteMemoryType;
\r
1977 DspUdsWriteMemoryType dspUdsWriteMemory;
\r
1978 Dcm_OpStatusType OpStatus = DCM_INITIAL;
\r
1979 dspUdsWriteMemory.MemoryAddressStart = 0;
\r
1980 dspUdsWriteMemory.MemoryIdConfigPtr = NULL;
\r
1981 dspUdsWriteMemory.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1982 dspUdsWriteMemory.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x3D_3 & UDS_REQ_0x3D_5*/
\r
1983 dspUdsWriteMemory.MemoryAddressFormat = ((uint8)pduRxData->SduDataPtr[1]) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x3D_3& UDS_REQ_0x3D_4*/
\r
1984 dspUdsWriteMemory.MemorySize = 0;
\r
1986 if((dspUdsWriteMemory.MemoryAddressFormat == 0) || (dspUdsWriteMemory.MemorySizeFormat == 0)) /*@req UDS_REQ_0x3D_14*/
\r
1988 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1992 /*take value of MemorySize out */
\r
1993 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat; i++)
\r
1995 dspUdsWriteMemory.MemorySize <<= 8;
\r
1996 dspUdsWriteMemory.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i +dspUdsWriteMemory.MemoryAddressFormat]);
\r
1998 dspUdsWriteMemory.MessageLength = (uint16)(2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemorySize);
\r
1999 if(dspUdsWriteMemory.MessageLength == pduRxData->SduLength)
\r
2001 /*take Start Address out */
\r
2002 for(i = 0; i < dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
2004 dspUdsWriteMemory.MemoryAddressStart <<= 8;
\r
2005 dspUdsWriteMemory.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[2 + i]);
\r
2007 if(TRUE == lookupWriteMemory(dspUdsWriteMemory.MemoryAddressStart,
\r
2008 dspUdsWriteMemory.MemoryAddressFormat,
\r
2009 dspUdsWriteMemory.MemorySize,
\r
2010 &dspUdsWriteMemory.MemoryIdConfigPtr))
\r
2012 if (DspCheckSecurityLevel(dspUdsWriteMemory.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
2014 dspUdsWriteMemory.ResponseCode = writeMemoryData(&OpStatus,
\r
2015 dspUdsWriteMemory.MemoryIdConfigPtr,
\r
2016 dspUdsWriteMemory.MemoryAddressStart,
\r
2017 dspUdsWriteMemory.MemorySize,
\r
2018 &pduRxData->SduDataPtr[2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat]);
\r
2022 dspUdsWriteMemory.ResponseCode = DCM_E_SECUTITYACCESSDENIED; /*@req UDS_REQ_0X3D_15,Dcm490*/
\r
2027 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x3D_11,UDS_REQ_0x3D_12,Dcm489*/
\r
2032 dspUdsWriteMemory.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;/*@req UDS_REQ_0x3D_9*/
\r
2035 if(DCM_E_POSITIVERESPONSE == dspUdsWriteMemory.ResponseCode)
\r
2037 pduTxData->SduLength = 2 + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat;
\r
2038 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
2039 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
2041 pduTxData->SduDataPtr[2 + i] = pduRxData->SduDataPtr[2 + i];
\r
2042 if(OpStatus != DCM_PENDING)
\r
2044 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
2048 dspMemoryState=DCM_MEMORY_WRITE;
\r
2054 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
2058 static boolean checkPeriodicIdentifierBuffer(uint8 PeriodicDid,uint8 Length,uint8 *postion)
\r
2061 boolean ret = FALSE;
\r
2062 for(i = 0;(i < Length) && (ret == FALSE);i++)
\r
2064 if(PeriodicDid == dspPDidRef.dspPDid[i].PeriodicDid)
\r
2074 static void ClearPeriodicIdentifierBuffer(uint8 BufferEnd,uint8 postion)
\r
2076 dspPDidRef.dspPDid[postion].PeriodicDid = dspPDidRef.dspPDid[BufferEnd ].PeriodicDid;
\r
2077 dspPDidRef.dspPDid[postion].PDidTxCounter = dspPDidRef.dspPDid[BufferEnd].PDidTxCounter;
\r
2078 dspPDidRef.dspPDid[postion].PDidTxCounterNumber = dspPDidRef.dspPDid[BufferEnd].PDidTxCounterNumber;
\r
2079 dspPDidRef.dspPDid[BufferEnd].PeriodicDid = 0;
\r
2080 dspPDidRef.dspPDid[BufferEnd].PDidTxCounter = 0;
\r
2081 dspPDidRef.dspPDid[BufferEnd ].PDidTxCounterNumber = 0;
\r
2084 static Dcm_NegativeResponseCodeType readPeriodDidData(const Dcm_DspDidType *PDidPtr, uint8 *Data,uint16 *Length)
\r
2086 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2087 if ((PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL)
\r
2088 && (PDidPtr->DspDidConditionCheckReadFnc != NULL)
\r
2089 && (PDidPtr->DspDidReadDataFnc != NULL) )
\r
2091 if (DspCheckSessionLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2093 if (DspCheckSecurityLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2095 Std_ReturnType result = E_NOT_OK;
\r
2096 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2097 result = PDidPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
2098 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE))
\r
2100 result = E_NOT_OK;
\r
2101 if (PDidPtr->DspDidInfoRef->DspDidFixedLength)
\r
2103 *Length= PDidPtr->DspDidSize;
\r
2108 if(PDidPtr->DspDidReadDataLengthFnc!=NULL)
\r
2110 result = PDidPtr->DspDidReadDataLengthFnc(Length);
\r
2114 responseCode = DCM_E_GENERALREJECT;
\r
2117 if (result == E_OK)
\r
2119 result = PDidPtr->DspDidReadDataFnc(Data);
\r
2120 if (result != E_OK)
\r
2122 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2127 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2132 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2137 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2142 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2147 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2149 return responseCode;
\r
2152 static Dcm_NegativeResponseCodeType DspSavePeriodicData(uint16 didNr, uint32 periodicTransmitCounter,uint8 PdidBufferNr)
\r
2154 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2155 const Dcm_DspDidType *SourceDid = NULL;
\r
2156 Dcm_DspDDDType *DDidPtr = NULL;
\r
2158 if (TRUE == lookupDid(didNr, &SourceDid))
\r
2160 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef) == TRUE)
\r
2162 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef) == TRUE)
\r
2164 Std_ReturnType result = E_NOT_OK;
\r
2165 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2167 if(SourceDid->DspDidConditionCheckReadFnc != NULL)
\r
2169 result = SourceDid->DspDidConditionCheckReadFnc(&errorCode);
\r
2171 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE))
\r
2173 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2175 if((SourceDid->DspDidInfoRef->DspDidFixedLength!=TRUE) && (SourceDid->DspDidReadDataLengthFnc == NULL))
\r
2177 responseCode = DCM_E_GENERALREJECT;
\r
2182 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2187 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2190 else if(LookupDDD(didNr, (const Dcm_DspDDDType **)&DDidPtr) == TRUE)
\r
2192 responseCode = DCM_E_POSITIVERESPONSE;
\r
2196 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2198 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2200 dspPDidRef.dspPDid[PdidBufferNr].PeriodicDid = (uint8)didNr & DCM_DID_LOW_MASK;
\r
2201 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounter = 0;
\r
2202 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounterNumber = periodicTransmitCounter;
\r
2204 return responseCode;
\r
2206 static void ClearPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData )
\r
2208 uint16 PdidNumber;
\r
2209 uint8 PDidLowByte;
\r
2210 uint8 PdidPostion;
\r
2212 if( pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE )
\r
2214 PdidNumber = pduRxData->SduLength - 2;
\r
2215 for(i = 0;i < PdidNumber;i++)
\r
2217 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2218 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2220 dspPDidRef.PDidNr--;
\r
2221 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr, PdidPostion);
\r
2225 pduTxData->SduLength = 1;
\r
2230 UDS Service 0x2a - Read Data By Periodic Identifier
\r
2232 void DspReadDataByPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2234 /** @req DCM254 */
\r
2235 uint8 PDidLowByte;
\r
2236 uint16 PdidNumber;
\r
2237 uint8 PdidPostion;
\r
2239 uint8 PdidBufferNr;
\r
2240 uint32 periodicTransmitCounter;
\r
2241 uint16 DataLength;
\r
2242 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2243 const Dcm_DspDidType *PDidPtr = NULL;
\r
2244 Dcm_DspDDDType *DDidPtr = NULL;
\r
2245 PdidBufferNr = dspPDidRef.PDidNr;
\r
2246 if(pduRxData->SduLength > 2)
\r
2249 switch(pduRxData->SduDataPtr[1])
\r
2251 case DCM_PERIODICTRANSMIT_DEFAULT_MODE:
\r
2252 periodicTransmitCounter = 0;
\r
2254 case DCM_PERIODICTRANSMIT_SLOWRATE_MODE:
\r
2255 periodicTransmitCounter = DCM_PERIODICTRANSMIT_SLOW;
\r
2257 case DCM_PERIODICTRANSMIT_MEDIUM_MODE:
\r
2258 periodicTransmitCounter = DCM_PERIODICTRANSMIT_MEDIUM;
\r
2260 case DCM_PERIODICTRANSMIT_FAST_MODE:
\r
2261 periodicTransmitCounter = DCM_PERIODICTRANSMIT_FAST;
\r
2263 case DCM_PERIODICTRANSMIT_STOPSENDING_MODE:
\r
2264 ClearPeriodicIdentifier(pduRxData,pduTxData);
\r
2267 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2270 if((pduRxData->SduDataPtr[1] != DCM_PERIODICTRANSMIT_STOPSENDING_MODE) && responseCode == DCM_E_POSITIVERESPONSE)
\r
2272 PdidNumber = pduRxData->SduLength - 2;
\r
2273 if(1 == PdidNumber)
\r
2275 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2276 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2278 if(0 == periodicTransmitCounter)
\r
2280 if (TRUE == lookupDid(((uint16)PDidLowByte + 0xF200), &PDidPtr)) /*UDS_REQ_0x2A_1*/
\r
2282 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2283 responseCode = readPeriodDidData(PDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2284 pduTxData->SduLength = DataLength + 2;
\r
2286 else if(TRUE == LookupDDD((0xF200 + (uint16)PDidLowByte), (const Dcm_DspDDDType **)&DDidPtr))
\r
2288 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2289 responseCode = readDDDData(DDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2290 pduTxData->SduLength = DataLength + 2;
\r
2294 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2296 if(responseCode != DCM_E_POSITIVERESPONSE)
\r
2298 dspPDidRef.PDidNr--;
\r
2299 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr,PdidPostion);
\r
2304 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2305 pduTxData->SduLength = 1;
\r
2310 responseCode = DspSavePeriodicData((DCM_PERODICDID_HIHG_MASK + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2312 pduTxData->SduLength = 1;
\r
2315 else if(((PdidNumber + PdidBufferNr) <= DCM_LIMITNUMBER_PERIODDATA) && (responseCode == DCM_E_POSITIVERESPONSE)) /*UDS_REQ_0x2A_6*/
\r
2317 for(i = 0;(i < PdidNumber)&&(responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2319 PDidLowByte = pduRxData->SduDataPtr[2 + i];
\r
2320 if(checkPeriodicIdentifierBuffer(PDidLowByte,PdidBufferNr,&PdidPostion) == TRUE)
\r
2322 if(dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber != periodicTransmitCounter)
\r
2324 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2329 responseCode = DspSavePeriodicData((0xF200 + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2332 pduTxData->SduLength = 1;
\r
2337 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2339 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2341 dspPDidRef.PDidNr = PdidBufferNr;
\r
2345 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE))
\r
2347 memset(&dspPDidRef,0,sizeof(dspPDidRef));
\r
2348 pduTxData->SduLength = 1;
\r
2352 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2354 DsdDspProcessingDone(responseCode);
\r
2357 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyDid(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2360 uint16 SourceDidNr;
\r
2361 const Dcm_DspDidType *SourceDid = NULL;
\r
2362 Dcm_DspDDDType *DDid = NULL;
\r
2363 uint16 SourceLength = 0;
\r
2364 uint16 DidLength = 0;
\r
2365 uint16 Length = 0;
\r
2367 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2369 if(FALSE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2371 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2375 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2377 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2381 DDid = &dspDDD[Num];
\r
2386 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2390 if(SourceLength > DCM_MAX_DDDSOURCE_NUMBER)
\r
2392 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2395 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2397 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN4) /SID_AND_ALFID_LEN4;
\r
2398 if(((Length*SID_AND_ALFID_LEN4) == (pduRxData->SduLength - SID_AND_ALFID_LEN4)) && (Length != 0))
\r
2400 if((Length + SourceLength) <= DCM_MAX_DDDSOURCE_NUMBER)
\r
2402 for(i = 0;(i < Length) && (responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2404 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
2405 if(TRUE == lookupDid(SourceDidNr, &SourceDid))/*UDS_REQ_0x2C_4*/
\r
2407 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2409 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2411 if(SourceDid->DspDidInfoRef->DspDidFixedLength == TRUE)
\r
2413 DidLength = SourceDid->DspDidSize;
\r
2417 if( SourceDid->DspDidReadDataLengthFnc != NULL)
\r
2419 SourceDid->DspDidReadDataLengthFnc(&DidLength);
\r
2422 if(DidLength != 0)
\r
2424 if((pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2425 (pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2426 (((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
2428 DDid->DDDSource[i + SourceLength].formatOrPosition = pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4];
\r
2429 DDid->DDDSource[i + SourceLength].Size = pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4];
\r
2430 DDid->DDDSource[i + SourceLength].SourceAddressOrDid = SourceDid->DspDidIdentifier;
\r
2431 DDid->DDDSource[i + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_DID;
\r
2435 /*UDS_REQ_0x2C_6*/
\r
2436 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2442 /*UDS_REQ_0x2C_14*/
\r
2443 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2448 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2453 /*UDS_REQ_0x2C_19,DCM726*/
\r
2454 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2460 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2466 /*UDS_REQ_0x2C_13*/
\r
2467 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2472 /*UDS_REQ_0x2C_11*/
\r
2473 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2475 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2477 DDid->DynamicallyDid = DDIdentifier;
\r
2478 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2481 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2483 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2486 return responseCode;
\r
2489 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyAddress(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2491 uint8 LengthCount;
\r
2492 uint8 SourceCount;
\r
2494 uint8 AddressFormat;
\r
2495 uint8 MemorySizeFormat;
\r
2496 uint32 MemoryAddress = 0;
\r
2497 uint16 MemorySize = 0;
\r
2498 uint16 SourceLength = 0;
\r
2499 Dcm_DspDDDType *DDid = NULL;
\r
2500 const Dcm_DspMemoryIdInfo *SourceMemoryInfo = NULL;
\r
2502 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2504 if(FALSE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2506 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2510 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2512 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2516 DDid = &dspDDD[Num];
\r
2521 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2525 if(SourceLength >= DCM_MAX_DDDSOURCE_NUMBER)
\r
2527 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2530 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2532 AddressFormat = (uint8)pduRxData->SduDataPtr[4] & DCM_FORMAT_LOW_MASK;
\r
2533 MemorySizeFormat = (uint8)(pduRxData->SduDataPtr[4] >> 4) & DCM_FORMAT_LOW_MASK;
\r
2534 if((AddressFormat+MemorySizeFormat) != 0)
\r
2536 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN5) / (AddressFormat + MemorySizeFormat);
\r
2538 if((AddressFormat != 0) && (MemorySizeFormat != 0) && ((SourceLength+Length) <= DCM_MAX_DDDSOURCE_NUMBER))
\r
2540 if((Length != 0)&&( Length * (AddressFormat + MemorySizeFormat) == (pduRxData->SduLength - 5) ))
\r
2542 for(LengthCount = 0; (LengthCount < Length) && (responseCode == DCM_E_POSITIVERESPONSE); LengthCount++)
\r
2544 MemoryAddress = 0;
\r
2545 for(SourceCount = 0; SourceCount < AddressFormat; SourceCount++)
\r
2547 MemoryAddress = MemoryAddress << 8;
\r
2548 MemoryAddress += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2551 /*take value of MemorySize out */
\r
2553 for(SourceCount = 0; SourceCount < MemorySizeFormat; SourceCount++)
\r
2555 MemorySize = MemorySize << 8;
\r
2556 MemorySize += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + AddressFormat + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2558 if(TRUE == lookupReadMemory(MemoryAddress, AddressFormat,MemorySize,&SourceMemoryInfo))
\r
2560 if(DspCheckSecurityLevel(SourceMemoryInfo->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
2562 DDid->DDDSource[LengthCount + SourceLength].formatOrPosition = pduRxData->SduDataPtr[4];
\r
2563 DDid->DDDSource[LengthCount + SourceLength].SourceAddressOrDid = MemoryAddress;
\r
2564 DDid->DDDSource[LengthCount + SourceLength].Size = MemorySize;
\r
2565 DDid->DDDSource[LengthCount + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_ADDRESS;
\r
2566 /*UDS_REQ_0x2C_6*/
\r
2570 /*UDS_REQ_0x2C_19,DCM726*/
\r
2571 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2576 /*UDS_REQ_0x2C_15,UDS_REQ_0x2C_16*/
\r
2577 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2580 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2582 DDid->DynamicallyDid = DDIdentifier;
\r
2587 /*UDS_REQ_0x2C_11*/
\r
2588 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2593 /*UDS_REQ_0x2C_17, UDS_REQ_0x2C_18*/
\r
2594 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2598 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2600 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS;
\r
2603 return responseCode;
\r
2609 UDS Service 0x2c - Clear dynamically Did
\r
2611 static Dcm_NegativeResponseCodeType CleardynamicallyDid(uint16 DDIdentifier,const PduInfoType *pduRxData, PduInfoType * pduTxData)
\r
2613 /*UDS_REQ_0x2C_5*/
\r
2617 uint8 ClearNum = 0;
\r
2618 Dcm_DspDDDType *DDid = NULL;
\r
2619 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2621 if(pduRxData->SduLength == 4)
\r
2623 if(TRUE == LookupDDD(DDIdentifier, (const Dcm_DspDDDType **)&DDid))
\r
2626 if((checkPeriodicIdentifierBuffer(pduRxData->SduDataPtr[3], dspPDidRef.PDidNr, &position) == TRUE)&&(pduRxData->SduDataPtr[2] == 0xF2))
\r
2628 /*UDS_REQ_0x2C_9*/
\r
2629 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2633 memset(DDid, 0, sizeof(Dcm_DspDDDType));
\r
2634 for(i = DCM_MAX_DDD_NUMBER - 1;i >= 0 ;i--) { /* find the first DDDid from bottom */
\r
2635 if (0 != dspDDD[i].DynamicallyDid) {
\r
2636 for (j = 0; j <DCM_MAX_DDD_NUMBER; j++) { /* find the first empty slot from top */
\r
2638 /* Rearrange finished */
\r
2639 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2640 pduTxData->SduLength = 2;
\r
2641 return responseCode;
\r
2643 else if (0 == dspDDD[j].DynamicallyDid) { /* find, exchange */
\r
2644 memcpy(&dspDDD[j], &dspDDD[i], sizeof(Dcm_DspDDDType));
\r
2645 memset(&dspDDD[i], 0, sizeof(Dcm_DspDDDType));
\r
2653 responseCode = DCM_E_REQUESTOUTOFRANGE; /* DDDid not found */
\r
2656 else if (pduRxData->SduDataPtr[1] == 0x03 && pduRxData->SduLength == 2){
\r
2658 memset(dspDDD, 0, (sizeof(Dcm_DspDDDType) * DCM_MAX_DDD_NUMBER));
\r
2662 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2664 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2666 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2667 pduTxData->SduLength = 2;
\r
2670 return responseCode;
\r
2673 void DspDynamicallyDefineDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2675 /*UDS_REQ_0x2C_1,DCM 259*/
\r
2678 boolean PeriodicdUse = FALSE;
\r
2679 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2680 uint16 DDIdentifier = ((((uint16)pduRxData->SduDataPtr[2]) << 8) & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[3] & DCM_DID_LOW_MASK);
\r
2681 if(pduRxData->SduLength > 2)
\r
2683 /* Check if DDID equals 0xF2 or 0xF3 */
\r
2684 if((pduRxData->SduDataPtr[2] & 0xF2) == 0xF2)
\r
2686 switch(pduRxData->SduDataPtr[1]) /*UDS_REQ_0x2C_2,DCM 646*/
\r
2688 case DCM_DDD_SUBFUNCTION_DEFINEBYDID:
\r
2689 responseCode = dynamicallyDefineDataIdentifierbyDid(DDIdentifier,pduRxData,pduTxData);
\r
2691 case DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS:
\r
2692 responseCode = dynamicallyDefineDataIdentifierbyAddress(DDIdentifier,pduRxData,pduTxData);
\r
2694 case DCM_DDD_SUBFUNCTION_CLEAR:
\r
2695 responseCode = CleardynamicallyDid(DDIdentifier,pduRxData,pduTxData);
\r
2698 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
2699 /*UDS_REQ_0x2C_10*/
\r
2705 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2707 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2709 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
2710 pduTxData->SduDataPtr[3] = pduRxData->SduDataPtr[3];
\r
2711 pduTxData->SduLength = 4;
\r
2714 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_DDD_SUBFUNCTION_CLEAR))
\r
2716 /*UDS_REQ_0x2C_7*/
\r
2717 for(i = 0;i < DCM_MAX_DDD_NUMBER;i++)
\r
2719 if(checkPeriodicIdentifierBuffer((uint8)(dspDDD[i].DynamicallyDid & DCM_DID_LOW_MASK),dspPDidRef.PDidNr,&Position) == TRUE)
\r
2721 PeriodicdUse = TRUE;
\r
2724 if(PeriodicdUse == FALSE)
\r
2726 memset(dspDDD,0,sizeof(dspDDD));
\r
2727 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2728 pduTxData->SduLength = 2;
\r
2732 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2737 /*UDS_REQ_0x2C_11*/
\r
2738 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2740 DsdDspProcessingDone(responseCode);
\r
2743 static Dcm_NegativeResponseCodeType DspIOControlReturnControlToECU(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2745 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2746 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidReturnControlToEcu == TRUE)
\r
2748 if(pduRxData->SduLength > 4)
\r
2750 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2752 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2754 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2756 DidPtr->DspDidReturnControlToEcuFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2761 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2766 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2771 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2776 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2779 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2781 DidPtr->DspDidReturnControlToEcuFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2782 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2786 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2791 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2797 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2799 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2801 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2802 pduTxData->SduDataPtr[3] = DCM_RETURN_CONTROL_TO_ECU;
\r
2805 return responseCode;
\r
2808 static Dcm_NegativeResponseCodeType DspIOControlResetToDefault(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2810 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2811 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidResetToDefault == TRUE)
\r
2813 if(pduRxData->SduLength > 4)
\r
2815 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2817 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2819 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2821 DidPtr->DspDidResetToDeaultFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2825 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2830 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2835 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2840 if(DidPtr->DspDidResetToDeaultFnc != NULL)
\r
2843 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2845 DidPtr->DspDidResetToDeaultFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2846 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2850 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2855 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2861 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2863 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2865 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize+4;
\r
2866 pduTxData->SduDataPtr[3] = DCM_RESET_TO_DEFAULT;
\r
2868 return responseCode;
\r
2872 UDS Service 0x2F - IOControl Freeze Current State
\r
2874 static Dcm_NegativeResponseCodeType DspIOControlFreezeCurrentState(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2876 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2877 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidFreezeCurrentState == TRUE)
\r
2879 if(pduRxData->SduLength > 4)
\r
2881 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2883 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2885 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2887 DidPtr->DspDidFreezeCurrentStateFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2891 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2896 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2901 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2906 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2909 if(DidPtr->DspDidControlRecordSize != 0)
\r
2911 DidPtr->DspDidFreezeCurrentStateFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2912 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2916 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2921 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2927 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2929 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2931 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2932 pduTxData->SduDataPtr[3] = DCM_FREEZE_CURRENT_STATE;
\r
2935 return responseCode;
\r
2938 static Dcm_NegativeResponseCodeType DspIOControlShortTeamAdjustment(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2940 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2941 uint8 didControlOptionRecordSize = DidPtr->DspDidControlRecordSize->DspDidControlOptionRecordSize;
\r
2942 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidShortTermAdjustment == TRUE)
\r
2944 if(pduRxData->SduLength > 4)
\r
2946 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2948 if(((((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7)) >> 3) + (didControlOptionRecordSize)) == (pduRxData->SduLength - 4))
\r
2950 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2952 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],&pduRxData->SduDataPtr[4 + didControlOptionRecordSize],&pduTxData->SduDataPtr[4],&responseCode);
\r
2956 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2959 else if((didControlOptionRecordSize) == (pduRxData->SduLength - 4))
\r
2961 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2963 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2967 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2972 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2977 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2982 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2987 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2989 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2991 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2992 pduTxData->SduDataPtr[3] = DCM_SHORT_TERM_ADJUSTMENT;
\r
2995 return responseCode;
\r
2998 void DspIOControlByDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
3001 const Dcm_DspDidType *DidPtr = NULL;
\r
3002 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
3003 didNr = (pduRxData->SduDataPtr[1] << 8 & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[2] & DCM_DID_LOW_MASK);
\r
3004 if(pduRxData->SduLength > 3)
\r
3006 if(TRUE == lookupDid(didNr, &DidPtr))
\r
3008 if(FALSE == DidPtr->DspDidUsePort)
\r
3010 if(NULL != DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl)
\r
3012 if(TRUE == DspCheckSessionLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSessionRef))
\r
3014 if(TRUE == DspCheckSecurityLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSecurityLevelRef))
\r
3016 switch(pduRxData->SduDataPtr[3])
\r
3018 case DCM_RETURN_CONTROL_TO_ECU:
\r
3019 responseCode = DspIOControlReturnControlToECU(DidPtr,pduRxData,pduTxData);
\r
3021 case DCM_RESET_TO_DEFAULT:
\r
3022 responseCode = DspIOControlResetToDefault(DidPtr,pduRxData,pduTxData);
\r
3024 case DCM_FREEZE_CURRENT_STATE:
\r
3025 responseCode = DspIOControlFreezeCurrentState(DidPtr,pduRxData,pduTxData);
\r
3027 case DCM_SHORT_TERM_ADJUSTMENT:
\r
3028 responseCode = DspIOControlShortTeamAdjustment(DidPtr,pduRxData,pduTxData);
\r
3031 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3038 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
3043 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3048 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3053 /* if UsePort == True, NRC 0x10 */
\r
3054 responseCode = DCM_E_GENERALREJECT;
\r
3059 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
3064 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
3066 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
3068 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
3069 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
3071 DsdDspProcessingDone(responseCode);
\r