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 for(i = 0;i < dspPDidRef.PDidNr; i++)
\r
195 if(dspPDidRef.dspPDid[i].PDidTxCounterNumber > dspPDidRef.dspPDid[i].PDidTxCounter)
\r
197 dspPDidRef.dspPDid[i].PDidTxCounter++;
\r
201 dspPDidRef.dspPDid[i].PDidTxCounter = 0;
\r
202 /*AutoSar DCM 8.10.5 */
\r
203 DslInternal_ResponseOnOneDataByPeriodicId(dspPDidRef.dspPDid[i].PeriodicDid);
\r
209 DspMemoryMainFunction();
\r
210 DspPeriodicDIDMainFunction();
\r
214 boolean DspCheckSessionLevel(Dcm_DspSessionRowType const* const* sessionLevelRefTable)
\r
216 Std_ReturnType returnStatus;
\r
217 boolean levelFound = FALSE;
\r
218 Dcm_SesCtrlType currentSession;
\r
220 returnStatus = DslGetSesCtrlType(¤tSession);
\r
221 if (returnStatus == E_OK) {
\r
222 while ( ((*sessionLevelRefTable)->DspSessionLevel != currentSession) && (!(*sessionLevelRefTable)->Arc_EOL) ) {
\r
223 sessionLevelRefTable++;
\r
226 if (!(*sessionLevelRefTable)->Arc_EOL) {
\r
235 boolean DspCheckSecurityLevel(Dcm_DspSecurityRowType const* const* securityLevelRefTable)
\r
237 Std_ReturnType returnStatus;
\r
238 boolean levelFound = FALSE;
\r
239 Dcm_SecLevelType currentSecurityLevel;
\r
241 returnStatus = DslGetSecurityLevel(¤tSecurityLevel);
\r
242 if (returnStatus == E_OK) {
\r
243 while ( ((*securityLevelRefTable)->DspSecurityLevel != currentSecurityLevel) && (!(*securityLevelRefTable)->Arc_EOL) ) {
\r
244 securityLevelRefTable++;
\r
246 if (!(*securityLevelRefTable)->Arc_EOL) {
\r
255 static Std_ReturnType askApplicationForSessionPermission(Dcm_SesCtrlType newSessionLevel)
\r
257 Std_ReturnType returnCode = E_OK;
\r
258 const Dcm_DslSessionControlType *sesControl = DCM_Config.Dsl->DslSessionControl;
\r
259 Dcm_SesCtrlType currentSessionLevel;
\r
260 Std_ReturnType result;
\r
262 while ( (!sesControl->Arc_EOL) && (returnCode != E_SESSION_NOT_ALLOWED)) {
\r
263 if (sesControl->GetSesChgPermission != NULL) {
\r
264 result = Dcm_GetSesCtrlType(¤tSessionLevel);
\r
265 if (result == E_OK) {
\r
266 result = sesControl->GetSesChgPermission(currentSessionLevel ,newSessionLevel);
\r
267 if (result != E_OK) {
\r
268 returnCode = result;
\r
271 returnCode = E_NOT_OK;
\r
281 void DspUdsDiagnosticSessionControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
284 const Dcm_DspSessionRowType *sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow;
\r
285 Dcm_SesCtrlType reqSessionType;
\r
286 Std_ReturnType result;
\r
288 if (pduRxData->SduLength == 2) {
\r
289 reqSessionType = pduRxData->SduDataPtr[1];
\r
290 // Check if type exist in session table
\r
291 while ((sessionRow->DspSessionLevel != reqSessionType) && (!sessionRow->Arc_EOL) ) {
\r
295 if (!sessionRow->Arc_EOL) {
\r
296 result = askApplicationForSessionPermission(reqSessionType);
\r
297 if (result == E_OK) {
\r
298 DslSetSesCtrlType(reqSessionType); /** @req DCM311 */
\r
299 // Create positive response
\r
300 pduTxData->SduDataPtr[1] = reqSessionType;
\r
301 pduTxData->SduLength = 2;
\r
302 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
305 // TODO: Add handling of special case of E_FORCE_RCRRP (Dcm138)
\r
306 DsdDspProcessingDone(DCM_E_CONDITIONSNOTCORRECT); /** @req DCM308 */
\r
310 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED); /** @req DCM307 */
\r
315 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
320 void DspUdsEcuReset(const PduInfoType *pduRxData, PduIdType txPduId, PduInfoType *pduTxData)
\r
323 uint8 reqResetType;
\r
325 if (pduRxData->SduLength == 2) {
\r
326 reqResetType = pduRxData->SduDataPtr[1];
\r
328 switch (reqResetType)
\r
330 case 0x01: // Hard reset
\r
331 // TODO: Ask application for permission (Dcm373) (Dcm375) (Dcm377)
\r
333 // Schedule the reset
\r
334 dspUdsEcuResetData.resetPending = TRUE;
\r
335 dspUdsEcuResetData.resetPduId = txPduId;
\r
337 // Create positive response
\r
338 pduTxData->SduDataPtr[1] = reqResetType;
\r
339 pduTxData->SduLength = 2;
\r
340 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
344 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
350 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
355 void DspUdsClearDiagnosticInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
359 Dem_ReturnClearDTCType result;
\r
361 if (pduRxData->SduLength == 4) {
\r
362 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[1], pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3]);
\r
364 result = Dem_ClearDTC(dtc, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY); /** @req DCM005 */
\r
369 // Create positive response
\r
370 pduTxData->SduLength = 1;
\r
371 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
375 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
381 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
386 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x01_0x07_0x11_0x12(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
391 uint8 dtcStatusAvailabilityMask;
\r
392 uint8 dtcFormatIdentifier;
\r
393 uint8 dtcCountHighByte;
\r
394 uint8 dtcCountLowByte;
\r
397 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
398 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
400 // Setup the DTC filter
\r
401 switch (pduRxData->SduDataPtr[1]) /** @req DCM293 */
\r
403 case 0x01: // reportNumberOfDTCByStatusMask
\r
404 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
407 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
408 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
411 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
412 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
415 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
416 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
420 setDtcFilterResult = DEM_WRONG_FILTER;
\r
424 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
425 Std_ReturnType result;
\r
426 Dem_ReturnGetNumberOfFilteredDTCType getNumerResult;
\r
427 uint16 numberOfFilteredDtc;
\r
428 uint8 dtcStatusMask;
\r
429 //lint --e(826) PC-Lint exception - Suspicious pointer conversion
\r
430 //lint --e(927) PC-Lint exception - Pointer to pointer cast
\r
431 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
434 getNumerResult = Dem_GetNumberOfFilteredDtc(&numberOfFilteredDtc);
\r
435 if (getNumerResult == DEM_NUMBER_OK) {
\r
436 result = Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
437 if (result != E_OK) {
\r
441 // Create positive response (ISO 14229-1 table 251)
\r
442 txData->reportType = pduRxData->SduDataPtr[1]; // reportType
\r
443 txData->dtcStatusAvailabilityMask = dtcStatusMask; // DTCStatusAvailabilityMask
\r
444 txData->dtcFormatIdentifier = Dem_GetTranslationType(); // DTCFormatIdentifier
\r
445 txData->dtcCountHighByte = (numberOfFilteredDtc >> 8); // DTCCount high byte
\r
446 txData->dtcCountLowByte = (numberOfFilteredDtc & 0xFFu); // DTCCount low byte
\r
447 pduTxData->SduLength = 6;
\r
449 // TODO: What to do?
\r
450 responseCode = DCM_E_GENERALREJECT;
\r
454 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
457 return responseCode;
\r
461 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
463 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
464 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
468 uint8 dtcMiddleByte;
\r
471 } dtcAndStatusRecordType;
\r
476 uint8 dtcStatusAvailabilityMask;
\r
477 dtcAndStatusRecordType *dtcAndStatusRecord;
\r
480 // Setup the DTC filter
\r
481 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
483 case 0x02: // reportDTCByStatusMask
\r
484 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
487 case 0x0A: // reportSupportedDTC
\r
488 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
491 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
492 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
495 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
496 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
499 case 0x15: // reportDTCWithPermanentStatus
\r
500 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
504 setDtcFilterResult = DEM_WRONG_FILTER;
\r
508 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
509 uint8 dtcStatusMask;
\r
510 //lint --e(826) PC-Lint exception - Suspicious pointer conversion
\r
511 //lint --e(927) PC-Lint exception - Pointer to pointer cast
\r
512 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
513 Dem_ReturnGetNextFilteredDTCType getNextFilteredDtcResult;
\r
515 Dem_EventStatusExtendedType dtcStatus;
\r
516 uint16 nrOfDtcs = 0;
\r
517 Std_ReturnType result;
\r
520 result = Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
521 if (result != E_OK) {
\r
525 // Create positive response (ISO 14229-1 table 252)
\r
526 txData->reportType = pduRxData->SduDataPtr[1];
\r
527 txData->dtcStatusAvailabilityMask = dtcStatusMask;
\r
529 if (dtcStatusMask != 0x00) { /** @req DCM008 */
\r
530 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
531 while (getNextFilteredDtcResult == DEM_FILTERED_OK) {
\r
532 txData->dtcAndStatusRecord[nrOfDtcs].dtcHighByte = DTC_HIGH_BYTE(dtc);
\r
533 txData->dtcAndStatusRecord[nrOfDtcs].dtcMiddleByte = DTC_MID_BYTE(dtc);
\r
534 txData->dtcAndStatusRecord[nrOfDtcs].dtcLowByte = DTC_LOW_BYTE(dtc);
\r
535 txData->dtcAndStatusRecord[nrOfDtcs].statusOfDtc = dtcStatus;
\r
537 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
540 if (getNextFilteredDtcResult != DEM_FILTERED_NO_MATCHING_DTC) {
\r
541 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
544 pduTxData->SduLength = (PduLengthType)(3 + (nrOfDtcs * sizeof(dtcAndStatusRecordType)));
\r
547 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
550 return responseCode;
\r
553 // PC-Lint (715 etc): Remove errors until function is filled.
\r
554 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
555 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x08(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
557 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
559 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
560 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
562 return responseCode;
\r
566 // PC-Lint (715 etc): Remove errors until function is filled.
\r
567 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
568 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x09(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
570 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
572 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
573 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
575 return responseCode;
\r
579 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x06_0x10(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
581 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
582 Dem_DTCOriginType dtcOrigin;
\r
586 // Switch on sub function
\r
587 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
589 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
590 dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY;
\r
593 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
594 dtcOrigin = DEM_DTC_ORIGIN_MIRROR_MEMORY;
\r
598 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
603 // Switch on record number
\r
604 switch (pduRxData->SduDataPtr[5])
\r
606 case 0xFF: // Report all Extended Data Records for a particular DTC
\r
607 startRecNum = 0x00;
\r
611 case 0xFE: // Report all OBD Extended Data Records for a particular DTC
\r
612 startRecNum = 0x90;
\r
616 default: // Report one specific Extended Data Records for a particular DTC
\r
617 startRecNum = pduRxData->SduDataPtr[5];
\r
618 endRecNum = startRecNum;
\r
622 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
623 Dem_ReturnGetStatusOfDTCType getStatusOfDtcResult;
\r
625 Dem_EventStatusExtendedType statusOfDtc;
\r
627 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3], pduRxData->SduDataPtr[4]);
\r
628 getStatusOfDtcResult = Dem_GetStatusOfDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, &statusOfDtc); /** @req DCM295 */ /** @req DCM475 */
\r
629 if (getStatusOfDtcResult == DEM_STATUS_OK) {
\r
630 Dem_ReturnGetExtendedDataRecordByDTCType getExtendedDataRecordByDtcResult;
\r
633 uint16 txIndex = 6;
\r
635 /** @req DCM297 */ /** @req DCM474 */ /** @req DCM386 */
\r
636 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1]; // Sub function
\r
637 pduTxData->SduDataPtr[2] = DTC_HIGH_BYTE(dtc); // DTC high byte
\r
638 pduTxData->SduDataPtr[3] = DTC_MID_BYTE(dtc); // DTC mid byte
\r
639 pduTxData->SduDataPtr[4] = DTC_LOW_BYTE(dtc); // DTC low byte
\r
640 pduTxData->SduDataPtr[5] = statusOfDtc; // DTC status
\r
641 for (recNum = startRecNum; recNum <= endRecNum; recNum++) {
\r
642 recLength = pduTxData->SduLength - (txIndex + 1); // Calculate what's left in buffer
\r
643 /** @req DCM296 */ /** @req DCM476 */ /** @req DCM382 */
\r
644 getExtendedDataRecordByDtcResult = Dem_GetExtendedDataRecordByDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, recNum, &pduTxData->SduDataPtr[txIndex+1], &recLength);
\r
645 if (getExtendedDataRecordByDtcResult == DEM_RECORD_OK) {
\r
646 pduTxData->SduDataPtr[txIndex++] = recNum;
\r
647 /* Instead of calling Dem_GetSizeOfExtendedDataRecordByDTC() the result from Dem_GetExtendedDataRecordByDTC() is used */
\r
648 /** @req DCM478 */ /** @req DCM479 */ /** @req DCM480 */
\r
649 txIndex += recLength;
\r
652 // TODO: What to do here?
\r
655 pduTxData->SduLength = txIndex;
\r
658 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
662 return responseCode;
\r
666 // PC-Lint (715 etc): Remove errors until function is filled.
\r
667 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
668 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x03(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
670 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
672 // TODO: Not supported yet
\r
673 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
675 return responseCode;
\r
679 // PC-Lint (715 etc): Remove errors until function is filled.
\r
680 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
681 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x04(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
683 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
685 // TODO: Not supported yet
\r
686 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
688 return responseCode;
\r
692 // PC-Lint (715 etc): Remove errors until function is filled.
\r
693 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
694 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x05(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
696 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
698 // TODO: Not supported yet
\r
699 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
701 return responseCode;
\r
705 // PC-Lint (715 etc): Remove errors until function is filled.
\r
706 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
707 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
709 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
711 // TODO: Not supported yet
\r
712 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
714 return responseCode;
\r
718 // PC-Lint (715 etc): Remove errors until function is filled.
\r
719 //lint -e{715, 838, 818} Symbol not referenced, responseCode not used, txData should be const
\r
720 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x14(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
722 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
724 // TODO: Not supported yet
\r
725 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
727 return responseCode;
\r
731 void DspUdsReadDtcInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
734 // 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
735 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
737 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
739 uint8 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
742 if (subFunctionNumber <= 0x15) {
\r
743 if (pduRxData->SduLength == sduLength[subFunctionNumber]) {
\r
744 switch (subFunctionNumber)
\r
746 case 0x01: // reportNumberOfDTCByStatusMask
\r
747 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
748 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
749 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
750 responseCode = udsReadDtcInfoSub_0x01_0x07_0x11_0x12(pduRxData, pduTxData);
\r
753 case 0x02: // reportDTCByStatusMask
\r
754 case 0x0A: // reportSupportedDTC
\r
755 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
756 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
757 case 0x15: // reportDTCWithPermanentStatus
\r
758 responseCode = udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(pduRxData, pduTxData);
\r
761 case 0x08: // reportDTCBySeverityMaskRecord
\r
762 responseCode = udsReadDtcInfoSub_0x08(pduRxData, pduTxData);
\r
765 case 0x09: // reportSeverityInformationOfDTC
\r
766 responseCode = udsReadDtcInfoSub_0x09(pduRxData, pduTxData);
\r
769 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
770 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
771 responseCode = udsReadDtcInfoSub_0x06_0x10(pduRxData, pduTxData);
\r
774 case 0x03: // reportDTCSnapshotIdentidication
\r
775 responseCode = udsReadDtcInfoSub_0x03(pduRxData, pduTxData);
\r
778 case 0x04: // reportDTCSnapshotByDtcNumber
\r
779 responseCode = udsReadDtcInfoSub_0x04(pduRxData, pduTxData);
\r
782 case 0x05: // reportDTCSnapshotRecordNumber
\r
783 responseCode = udsReadDtcInfoSub_0x05(pduRxData, pduTxData);
\r
786 case 0x0B: // reportFirstTestFailedDTC
\r
787 case 0x0C: // reportFirstConfirmedDTC
\r
788 case 0x0D: // reportMostRecentTestFailedDTC
\r
789 case 0x0E: // reportMostRecentConfirmedDTC
\r
790 responseCode = udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(pduRxData, pduTxData);
\r
793 case 0x14: // reportDTCFaultDetectionCounter
\r
794 responseCode = udsReadDtcInfoSub_0x14(pduRxData, pduTxData);
\r
798 // Unknown sub function
\r
799 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
805 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
809 // Sub function out of range
\r
810 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
813 DsdDspProcessingDone(responseCode);
\r
816 ** This Function for check the pointer of Dynamically Did Sourced by Did buffer using a didNr
\r
818 static boolean LookupDDD(uint16 didNr, const Dcm_DspDDDType **DDid )
\r
821 boolean ret = FALSE;
\r
822 const Dcm_DspDDDType* DDidptr = &dspDDD[0];
\r
824 for(i = 0;((i < DCM_MAX_DDD_NUMBER) && (ret == FALSE)); i++)
\r
826 if(DDidptr->DynamicallyDid == didNr)
\r
844 static boolean lookupDid(uint16 didNr, const Dcm_DspDidType **didPtr)
\r
846 const Dcm_DspDidType *dspDid = DCM_Config.Dsp->DspDid;
\r
847 boolean didFound = FALSE;
\r
849 while ((dspDid->DspDidIdentifier != didNr) && (!dspDid->Arc_EOL)) {
\r
853 if (!dspDid->Arc_EOL) {
\r
862 static Dcm_NegativeResponseCodeType readDidData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
864 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
866 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL) && (didPtr->DspDidConditionCheckReadFnc != NULL) && (didPtr->DspDidReadDataFnc != NULL)) { /** @req DCM433 */
\r
867 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef)) { /** @req DCM434 */
\r
868 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef)) { /** @req DCM435 */
\r
869 Std_ReturnType result;
\r
870 Dcm_NegativeResponseCodeType errorCode;
\r
871 result = didPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
872 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) { /** @req DCM439 */
\r
875 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM436 */
\r
876 didLen = didPtr->DspDidSize;
\r
880 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
881 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
885 if (result == E_OK) {
\r
886 // Now ready for reading the data!
\r
887 if ((*txPos + didLen + 2) <= pduTxData->SduLength) {
\r
888 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFFu;
\r
890 pduTxData->SduDataPtr[*txPos] = didPtr->DspDidIdentifier & 0xFFu;
\r
892 result = didPtr->DspDidReadDataFnc(&pduTxData->SduDataPtr[*txPos]); /** @req DCM437 */
\r
895 if (result != E_OK) {
\r
896 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
899 else { // tx buffer full
\r
900 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
903 else { // Not possible to obtain did length
\r
904 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
907 else { // CheckRead failed
\r
908 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
911 else { // Not allowed in current security level
\r
912 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
915 else { // Not allowed in current session
\r
916 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
919 else { // Read access not configured
\r
920 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
923 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
924 // Recurse trough the rest of the dids. /** @req DCM440 */
\r
926 for (i=0; (!didPtr->DspDidRef[i]->Arc_EOL) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
927 responseCode = readDidData(didPtr->DspDidRef[i], pduTxData, txPos);
\r
931 return responseCode;
\r
935 ** This Function for read Dynamically Did data buffer Sourced by Memory address using a didNr
\r
937 static Dcm_NegativeResponseCodeType readDDDData( Dcm_DspDDDType *PDidPtr, uint8 *Data,uint16 *Length)
\r
941 uint8 AddressFormat;
\r
942 uint16 SourceDataLength = 0;
\r
943 const Dcm_DspMemoryIdInfo *SourceMemoryInfoptr = NULL;
\r
944 const Dcm_DspDidType *SourceDidPtr = NULL;
\r
945 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
948 for(i = 0;(i < DCM_MAX_DDDSOURCE_NUMBER) && (PDidPtr->DDDSource[i].formatOrPosition != 0)
\r
949 &&(responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
951 if(PDidPtr->DDDSource[i].DDDTpyeID == DCM_DDD_SOURCE_ADDRESS)
\r
954 AddressFormat = PDidPtr->DDDSource[i].formatOrPosition&DCM_FORMAT_HIGH_MASK >> 4;
\r
955 if(TRUE == lookupReadMemory(PDidPtr->DDDSource[i].SourceAddressOrDid,AddressFormat,
\r
956 PDidPtr->DDDSource[i].Size, &SourceMemoryInfoptr))
\r
958 if(DspCheckSecurityLevel(SourceMemoryInfoptr->pReadMemoryInfo->pSecurityLevel) != TRUE)
\r
960 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
965 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
967 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
969 Dcm_ReadMemory(DCM_INITIAL,SourceMemoryInfoptr->MemoryIdValue,
\r
970 PDidPtr->DDDSource[i].SourceAddressOrDid,
\r
971 PDidPtr->DDDSource[i].Size,
\r
973 *Length = *Length + PDidPtr->DDDSource[i].Size;
\r
976 else if(PDidPtr->DDDSource[i].DDDTpyeID == DCM_DDD_SOURCE_DID)
\r
979 if(lookupDid(PDidPtr->DDDSource[i].SourceAddressOrDid,&SourceDidPtr) == TRUE)
\r
981 if(DspCheckSecurityLevel(SourceDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef) != TRUE)
\r
983 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
985 if(SourceDidPtr->DspDidInfoRef->DspDidFixedLength == TRUE)
\r
987 SourceDataLength = SourceDidPtr->DspDidSize;
\r
991 if(SourceDidPtr->DspDidReadDataLengthFnc != NULL)
\r
993 SourceDidPtr->DspDidReadDataLengthFnc(&SourceDataLength);
\r
996 if((SourceDidPtr->DspDidReadDataFnc != NULL) && (SourceDataLength != 0) && (DCM_E_POSITIVERESPONSE == responseCode))
\r
999 SourceDidPtr->DspDidReadDataFnc((Data + *Length));
\r
1000 for(dataCount = 0;dataCount < SourceDataLength;dataCount++)
\r
1002 if(dataCount < PDidPtr->DDDSource[i].Size)
\r
1004 *(Data + *Length + dataCount) = *(Data + *Length + dataCount + PDidPtr->DDDSource[i].formatOrPosition - 1);
\r
1008 *(Data + *Length + dataCount) = 0;
\r
1011 *Length = *Length + PDidPtr->DDDSource[i].Size;
\r
1015 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1020 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1026 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1029 return responseCode;
\r
1032 void DspUdsReadDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1034 /** @req DCM253 */
\r
1035 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1038 const Dcm_DspDidType *didPtr = NULL;
\r
1039 Dcm_DspDDDType *DDidPtr=NULL;
\r
1044 if ( ((pduRxData->SduLength - 1) % 2) == 0 ) {
\r
1045 nrOfDids = (pduRxData->SduLength - 1) / 2;
\r
1047 for (i = 0; (i < nrOfDids) && (responseCode == DCM_E_POSITIVERESPONSE); i++)
\r
1049 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1 + (i * 2)] << 8) + pduRxData->SduDataPtr[2 + (i * 2)];
\r
1050 if (lookupDid(didNr, &didPtr)) { /** @req DCM438 */
\r
1051 responseCode = readDidData(didPtr, pduTxData, &txPos);
\r
1054 else if(LookupDDD(didNr,&DDidPtr) == TRUE)
\r
1056 /*DCM 651,DCM 652*/
\r
1057 pduTxData->SduDataPtr[txPos] = (DDidPtr->DynamicallyDid>>8) & 0xFF;
\r
1059 pduTxData->SduDataPtr[txPos] = (uint8)(DDidPtr->DynamicallyDid & 0xFF);
\r
1061 responseCode = readDDDData(DDidPtr,&(pduTxData->SduDataPtr[txPos]), &Length);
\r
1062 txPos = txPos + Length;
\r
1066 { // DID not found
\r
1067 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1072 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1075 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1076 pduTxData->SduLength = txPos;
\r
1079 DsdDspProcessingDone(responseCode);
\r
1083 static Dcm_NegativeResponseCodeType readDidScalingData(const Dcm_DspDidType *didPtr, const PduInfoType *pduTxData, uint16 *txPos)
\r
1085 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1087 if (didPtr->DspDidGetScalingInfoFnc != NULL) {
\r
1088 uint16 scalingInfoLen;
\r
1090 scalingInfoLen = didPtr->DspDidInfoRef->DspDidScalingInfoSize;
\r
1091 if ((*txPos + scalingInfoLen + 2) <= pduTxData->SduLength) {
\r
1092 Std_ReturnType result;
\r
1093 Dcm_NegativeResponseCodeType errorCode;
\r
1095 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFFu;
\r
1097 pduTxData->SduDataPtr[*txPos] = didPtr->DspDidIdentifier & 0xFFu;
\r
1099 result = didPtr->DspDidGetScalingInfoFnc(&pduTxData->SduDataPtr[*txPos], &errorCode); /** @req DCM394 */
\r
1100 *txPos += scalingInfoLen;
\r
1102 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
1103 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1106 else { // tx buffer full
\r
1107 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1110 else { // DspDidGetScalingInfoFnc null pointer
\r
1111 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1114 return responseCode;
\r
1117 void DspUdsReadScalingDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1119 /** @req DCM258 */
\r
1120 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1122 const Dcm_DspDidType *didPtr = NULL;
\r
1126 if (pduRxData->SduLength == 3) {
\r
1127 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
1128 if (lookupDid(didNr, &didPtr)) {
\r
1129 responseCode = readDidScalingData(didPtr, pduTxData, &txPos);
\r
1131 else { // DID not found
\r
1132 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1135 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1136 pduTxData->SduLength = txPos;
\r
1141 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1144 DsdDspProcessingDone(responseCode);
\r
1148 static Dcm_NegativeResponseCodeType writeDidData(const Dcm_DspDidType *didPtr, const PduInfoType *pduRxData, uint16 writeDidLen)
\r
1150 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1152 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite != NULL) && (didPtr->DspDidConditionCheckWriteFnc != NULL) && (didPtr->DspDidWriteDataFnc != NULL)) { /** @req DCM468 */
\r
1153 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSessionRef)) { /** @req DCM469 */
\r
1154 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSecurityLevelRef)) { /** @req DCM470 */
\r
1155 Std_ReturnType result;
\r
1156 Dcm_NegativeResponseCodeType errorCode;
\r
1157 result = didPtr->DspDidConditionCheckWriteFnc(&errorCode); /** @req DCM471 */
\r
1158 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
1159 uint16 didLen = 0;
\r
1160 result = E_NOT_OK;
\r
1161 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM472 */
\r
1162 didLen = didPtr->DspDidSize;
\r
1166 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
1167 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
1170 if (result == E_OK) {
\r
1171 if (didLen == writeDidLen) { /** @req DCM473 */
\r
1172 result = didPtr->DspDidWriteDataFnc(&pduRxData->SduDataPtr[3], (uint8)didLen, &errorCode); /** @req DCM395 */
\r
1173 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
1174 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1178 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1181 else { // Not possible to obtain did length
\r
1182 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1185 else { // CheckRead failed
\r
1186 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1189 else { // Not allowed in current security level
\r
1190 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1193 else { // Not allowed in current session
\r
1194 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1197 else { // Read access not configured
\r
1198 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1201 return responseCode;
\r
1204 void DspUdsWriteDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1206 /** @req DCM255 */
\r
1207 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1209 const Dcm_DspDidType *didPtr = NULL;
\r
1211 uint16 didDataLength;
\r
1213 didDataLength = pduRxData->SduLength - 3;
\r
1214 didNr = (uint16)((uint16)pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
1215 if (lookupDid(didNr, &didPtr)) { /** @req DCM467 */
\r
1216 responseCode = writeDidData(didPtr, pduRxData, didDataLength);
\r
1218 else { // DID not found
\r
1219 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1222 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1223 pduTxData->SduLength = 3;
\r
1224 pduTxData->SduDataPtr[1] = (didNr >> 8) & 0xFFu;
\r
1225 pduTxData->SduDataPtr[2] = didNr & 0xFFu;
\r
1228 DsdDspProcessingDone(responseCode);
\r
1232 void DspUdsSecurityAccess(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1234 /** @req DCM252 */
\r
1235 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1237 // Check sub function range (0x01 to 0x42)
\r
1238 if ((pduRxData->SduDataPtr[1] >= 0x01) && (pduRxData->SduDataPtr[1] <= 0x42)) {
\r
1239 boolean isRequestSeed = pduRxData->SduDataPtr[1] & 0x01u;
\r
1240 Dcm_SecLevelType requestedSecurityLevel = (pduRxData->SduDataPtr[1]-1)/2;
\r
1241 Dcm_NegativeResponseCodeType getSeedErrorCode;
\r
1243 if (isRequestSeed) {
\r
1244 // requestSeed message
\r
1245 // Check if type exist in security table
\r
1246 const Dcm_DspSecurityRowType *securityRow = &DCM_Config.Dsp->DspSecurity->DspSecurityRow[0];
\r
1247 while ((securityRow->DspSecurityLevel != requestedSecurityLevel) && (!securityRow->Arc_EOL)) {
\r
1250 if (!securityRow->Arc_EOL) {
\r
1252 if (pduRxData->SduLength == (2 + securityRow->DspSecurityADRSize)) { /** @req DCM321.RequestSeed */
\r
1253 Dcm_SecLevelType activeSecLevel;
\r
1254 Std_ReturnType result;
\r
1255 result = Dcm_GetSecurityLevel(&activeSecLevel);
\r
1256 if (result == E_OK) {
\r
1257 if (requestedSecurityLevel == activeSecLevel) { /** @req DCM323 */
\r
1258 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1259 // If same level set the seed to zeroes
\r
1260 memset(&pduTxData->SduDataPtr[2], 0, securityRow->DspSecuritySeedSize);
\r
1261 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1263 // New security level ask for seed
\r
1264 if (securityRow->GetSeed != NULL) {
\r
1265 Std_ReturnType getSeedResult;
\r
1266 getSeedResult = securityRow->GetSeed(&pduRxData->SduDataPtr[2], &pduTxData->SduDataPtr[2], &getSeedErrorCode); /** @req DCM324.RequestSeed */
\r
1267 if ((getSeedResult == E_OK) && (getSeedErrorCode == E_OK)) {
\r
1268 // Everything ok add sub function to tx message and send it.
\r
1269 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1270 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
1272 dspUdsSecurityAccesData.reqSecLevel = requestedSecurityLevel;
\r
1273 dspUdsSecurityAccesData.reqSecLevelRef = securityRow;
\r
1274 dspUdsSecurityAccesData.reqInProgress = TRUE;
\r
1277 // GetSeed returned not ok
\r
1278 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1281 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1285 // TODO: What to do?
\r
1286 responseCode = DCM_E_GENERALREJECT;
\r
1292 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1296 // Requested security level not configured
\r
1297 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1301 // sendKey message
\r
1302 if (dspUdsSecurityAccesData.reqInProgress) {
\r
1303 if (pduRxData->SduLength == (2 + dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityKeySize)) { /** @req DCM321.SendKey */
\r
1304 if (requestedSecurityLevel == dspUdsSecurityAccesData.reqSecLevel) {
\r
1305 if (dspUdsSecurityAccesData.reqSecLevelRef->CompareKey != NULL) {
\r
1306 Std_ReturnType compareKeyResult;
\r
1307 compareKeyResult = dspUdsSecurityAccesData.reqSecLevelRef->CompareKey(&pduRxData->SduDataPtr[2]); /** @req DCM324.SendKey */
\r
1308 if (compareKeyResult == E_OK) {
\r
1309 // Request accepted
\r
1311 DslSetSecurityLevel(dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityLevel); /** @req DCM325 */
\r
1312 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
1313 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1314 pduTxData->SduLength = 2;
\r
1317 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1320 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1324 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1329 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1333 // sendKey request without a preceding requestSeed
\r
1334 responseCode = DCM_E_REQUESTSEQUENCEERROR;
\r
1339 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1342 DsdDspProcessingDone(responseCode);
\r
1346 static boolean lookupRoutine(uint16 routineId, const Dcm_DspRoutineType **routinePtr)
\r
1348 const Dcm_DspRoutineType *dspRoutine = DCM_Config.Dsp->DspRoutine;
\r
1349 boolean routineFound = FALSE;
\r
1351 while ((dspRoutine->DspRoutineIdentifier != routineId) && (!dspRoutine->Arc_EOL)) {
\r
1355 if (!dspRoutine->Arc_EOL) {
\r
1356 routineFound = TRUE;
\r
1357 *routinePtr = dspRoutine;
\r
1360 return routineFound;
\r
1364 static Dcm_NegativeResponseCodeType startRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1366 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1367 Std_ReturnType routineResult;
\r
1370 if ((routinePtr->DspStartRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspStartRoutine != NULL)) {
\r
1371 if (((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1372 && ((routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1373 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspStartRoutine->DspStartRoutineStsOptRecSize + 4;
\r
1374 routineResult = routinePtr->DspStartRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM400 */ /** @req DCM401 */
\r
1375 if (routineResult != E_OK) {
\r
1376 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1380 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1384 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1387 return responseCode;
\r
1391 static Dcm_NegativeResponseCodeType stopRoutine(const Dcm_DspRoutineType *routinePtr, const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1393 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1394 Std_ReturnType routineResult;
\r
1397 if ((routinePtr->DspStopRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineStop != NULL)) {
\r
1398 if (((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineCtrlOptRecSize + 4) == pduRxData->SduLength)
\r
1399 && ((routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4) <= pduTxData->SduLength)) {
\r
1400 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineStop->DspStopRoutineStsOptRecSize + 4;
\r
1401 routineResult = routinePtr->DspStopRoutineFnc(&pduRxData->SduDataPtr[4], &pduTxData->SduDataPtr[4], &responseCode); /** @req DCM402 */ /** @req DCM403 */
\r
1402 if (routineResult != E_OK) {
\r
1403 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1407 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1411 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1414 return responseCode;
\r
1418 static Dcm_NegativeResponseCodeType requestRoutineResults(const Dcm_DspRoutineType *routinePtr, PduInfoType *pduTxData)
\r
1420 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1421 Std_ReturnType routineResult;
\r
1423 // requestRoutineResults
\r
1424 if ((routinePtr->DspRequestResultRoutineFnc != NULL) && (routinePtr->DspRoutineInfoRef->DspRoutineRequestRes != NULL)) {
\r
1425 if ((routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4) <= pduTxData->SduLength) {
\r
1426 pduTxData->SduLength = routinePtr->DspRoutineInfoRef->DspRoutineRequestRes->DspReqResRtnCtrlOptRecSize + 4;
\r
1427 routineResult = routinePtr->DspRequestResultRoutineFnc(&pduTxData->SduDataPtr[4], &responseCode); /** @req DCM404 */ /** @req DCM405 */
\r
1428 if (routineResult != E_OK) {
\r
1429 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1433 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1437 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1440 return responseCode;
\r
1444 void DspUdsRoutineControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1446 /** @req DCM257 */
\r
1447 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1448 uint8 subFunctionNumber = 0;
\r
1449 uint16 routineId = 0;
\r
1450 const Dcm_DspRoutineType *routinePtr = NULL;
\r
1452 if (pduRxData->SduLength >= 4) {
\r
1453 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
1454 if ((subFunctionNumber > 0) && (subFunctionNumber < 4)) {
\r
1455 routineId = (uint16)((uint16)pduRxData->SduDataPtr[2] << 8) + pduRxData->SduDataPtr[3];
\r
1456 if (lookupRoutine(routineId, &routinePtr)) {
\r
1457 if (DspCheckSessionLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSessionRef)) {
\r
1458 if (DspCheckSecurityLevel(routinePtr->DspRoutineInfoRef->DspRoutineAuthorization.DspRoutineSecurityLevelRef)) {
\r
1459 switch (subFunctionNumber) {
\r
1460 case 0x01: // startRoutine
\r
1461 responseCode = startRoutine(routinePtr, pduRxData, pduTxData);
\r
1464 case 0x02: // stopRoutine
\r
1465 responseCode = stopRoutine(routinePtr, pduRxData, pduTxData);
\r
1468 case 0x03: // requestRoutineResults
\r
1469 responseCode = requestRoutineResults(routinePtr, pduTxData);
\r
1472 default: // This shall never happen
\r
1473 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1477 else { // Not allowed in current security level
\r
1478 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
1481 else { // Not allowed in current session
\r
1482 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
1485 else { // Unknown routine identifier
\r
1486 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1489 else { // Sub function not supported
\r
1490 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1495 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1498 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
1499 // Add header to the positive response message
\r
1500 pduTxData->SduDataPtr[1] = subFunctionNumber;
\r
1501 pduTxData->SduDataPtr[2] = (routineId >> 8) & 0xFFu;
\r
1502 pduTxData->SduDataPtr[3] = routineId & 0xFFu;
\r
1505 DsdDspProcessingDone(responseCode);
\r
1509 void DspUdsTesterPresent(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1511 /** @req DCM251 */
\r
1512 if (pduRxData->SduLength == 2) {
\r
1513 switch (pduRxData->SduDataPtr[1])
\r
1515 case ZERO_SUB_FUNCTION:
\r
1516 DslResetSessionTimeoutTimer();
\r
1517 // Create positive response
\r
1518 pduTxData->SduDataPtr[1] = ZERO_SUB_FUNCTION;
\r
1519 pduTxData->SduLength = 2;
\r
1520 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1524 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1530 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1535 void DspUdsControlDtcSetting(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1537 /** @req DCM249 */
\r
1538 Dem_ReturnControlDTCStorageType resultCode;
\r
1540 if (pduRxData->SduLength == 2) {
\r
1541 switch (pduRxData->SduDataPtr[1])
\r
1544 resultCode = Dem_EnableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM304 */
\r
1545 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1546 pduTxData->SduDataPtr[1] = 0x01;
\r
1547 pduTxData->SduLength = 2;
\r
1548 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1551 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1556 resultCode = Dem_DisableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM406 */
\r
1557 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1558 pduTxData->SduDataPtr[1] = 0x02;
\r
1559 pduTxData->SduLength = 2;
\r
1560 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1563 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1568 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1574 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1579 void DspDcmConfirmation(PduIdType confirmPduId)
\r
1581 if (dspUdsEcuResetData.resetPending) {
\r
1582 if (confirmPduId == dspUdsEcuResetData.resetPduId) {
\r
1583 dspUdsEcuResetData.resetPending = FALSE;
\r
1584 #if defined(USE_MCU) && ( MCU_PERFORM_RESET_API == STD_ON )
\r
1585 Mcu_PerformReset();
\r
1587 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_UDS_RESET_ID, DCM_E_NOT_SUPPORTED);
\r
1594 /* REVIEW JB 2012-06-05: Removed iSoft function header - please don't add iSoft specific headers in the future */
\r
1595 static boolean CheckReadMemoryByAddress( boolean useId,uint32 memoryAddress,
\r
1596 uint8 memoryAddressFormat,
\r
1597 uint32 memorySize,
\r
1598 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1600 boolean ret = FALSE;
\r
1603 if(useId == FALSE)
\r
1606 if((memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1607 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1608 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1615 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1616 memoryAddress = (uint32)(memoryAddress & DCM_MEMORY_ADDRESS_MASK);
\r
1618 if((MemoryId == dspMemory->MemoryIdValue)&&
\r
1619 (memoryAddress >= dspMemory->pReadMemoryInfo->MemoryAddressLow)
\r
1620 && (memoryAddress <= dspMemory->pReadMemoryInfo->MemoryAddressHigh)
\r
1621 && (memoryAddress + memorySize - 1 <= dspMemory->pReadMemoryInfo->MemoryAddressHigh))
\r
1630 static boolean lookupReadMemory(uint32 memoryAddress,
\r
1631 uint8 memoryAddressFormat,
\r
1632 uint32 memorySize,
\r
1633 const Dcm_DspMemoryIdInfo **MemoryInfoPtr)
\r
1636 boolean memoryFound = FALSE;
\r
1637 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1639 for(i = 0; (dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE); i++)
\r
1641 if(TRUE == CheckReadMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId,memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1643 memoryFound = TRUE;
\r
1647 (Dcm_DspMemoryIdInfo *)dspMemoryInfo++;
\r
1650 if (memoryFound == TRUE)
\r
1652 *MemoryInfoPtr = dspMemoryInfo;
\r
1655 return memoryFound;
\r
1658 static Dcm_NegativeResponseCodeType readMemoryData( Dcm_OpStatusType *OpStatus,
\r
1659 const Dcm_DspMemoryIdInfo *MemoryPtr,
\r
1660 uint32 MemoryAddress,
\r
1661 uint32 MemorySize,
\r
1662 PduInfoType *pduTxData)
\r
1664 Dcm_ReturnReadMemoryType ReadRet;
\r
1665 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1666 ReadRet = Dcm_ReadMemory(*OpStatus,MemoryPtr->MemoryIdValue,
\r
1669 &pduTxData->SduDataPtr[1]);
\r
1670 if(DCM_READ_FAILED == ReadRet)
\r
1672 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req Dcm644*/
\r
1674 if (DCM_READ_PENDING == ReadRet)
\r
1676 *OpStatus = DCM_READ_PENDING;
\r
1678 return responseCode;
\r
1681 /*@req Dcm442,DCM492*/
\r
1682 void DspUdsReadMemoryByAddress(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1685 uint32 MemoryAddressStart; /* low address of a memory block to read or write*/
\r
1686 uint32 MemoryIdValue; /* memory ID to read or write uint used by parameter */
\r
1687 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1688 Dcm_NegativeResponseCodeType ResponseCode;
\r
1689 uint8 MemorySizeFormat;
\r
1690 uint8 MemoryAddressFormat;
\r
1691 uint32 MemorySize;
\r
1692 uint16 MessageLength;
\r
1693 }DspUdsReadMemoryByAddressType; /*the typed used for SID read memory by address*/
\r
1695 DspUdsReadMemoryByAddressType dspReadMemoryByAddress;
\r
1696 Dcm_OpStatusType OpStatus = 0;
\r
1697 dspReadMemoryByAddress.MemoryAddressStart = 0;
\r
1698 dspReadMemoryByAddress.MemorySize = 0;
\r
1699 dspReadMemoryByAddress.MemoryIdConfigPtr = NULL;
\r
1700 dspReadMemoryByAddress.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1701 dspReadMemoryByAddress.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1702 dspReadMemoryByAddress.MemoryAddressFormat = ((uint8)(pduRxData->SduDataPtr[1])) & 0x0Fu; /*@req UDS_REQ_0x23_1 & UDS_REQ_0x23_5*/
\r
1704 if((dspReadMemoryByAddress.MemoryAddressFormat == 0)||(dspReadMemoryByAddress.MemorySizeFormat == 0))
\r
1706 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*UDS_REQ_0x23_10*/
\r
1710 dspReadMemoryByAddress.MessageLength = (uint16)(dspReadMemoryByAddress.MemoryAddressFormat + dspReadMemoryByAddress.MemorySizeFormat + SID_AND_ALFID_LEN2);
\r
1711 if(dspReadMemoryByAddress.MessageLength == (uint16)(pduRxData->SduLength))
\r
1713 /*take start address out */
\r
1714 for(i = 0; i < dspReadMemoryByAddress.MemoryAddressFormat; i++)
\r
1716 dspReadMemoryByAddress.MemoryAddressStart <<= 8;
\r
1717 dspReadMemoryByAddress.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[SID_AND_ALFID_LEN2 + i]);
\r
1720 /*take value of MemorySize out */
\r
1721 for(i = 0; i < dspReadMemoryByAddress.MemorySizeFormat; i++)
\r
1723 dspReadMemoryByAddress.MemorySize <<= 8;
\r
1724 dspReadMemoryByAddress.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i + dspReadMemoryByAddress.MemoryAddressFormat]);
\r
1726 if(dspReadMemoryByAddress.MemorySize < DCM_PROTOCAL_TP_MAX_LENGTH)
\r
1728 if(TRUE == lookupReadMemory(dspReadMemoryByAddress.MemoryAddressStart,
\r
1729 dspReadMemoryByAddress.MemoryAddressFormat,
\r
1730 dspReadMemoryByAddress.MemorySize,
\r
1731 &dspReadMemoryByAddress.MemoryIdConfigPtr))
\r
1733 if (DspCheckSecurityLevel(dspReadMemoryByAddress.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
1735 dspReadMemoryByAddress.ResponseCode = readMemoryData(&OpStatus,dspReadMemoryByAddress.MemoryIdConfigPtr,
\r
1736 dspReadMemoryByAddress.MemoryAddressStart,
\r
1737 dspReadMemoryByAddress.MemorySize,pduTxData);/*@req UDS_REQ_0x23_9*/
\r
1742 dspReadMemoryByAddress.ResponseCode = DCM_E_SECUTITYACCESSDENIED;/*@req UDS_REQ_0x23_11,@req DCM494*/
\r
1747 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x23_7,UDS_REQ_0x23_8*/
\r
1752 dspReadMemoryByAddress.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1757 dspReadMemoryByAddress.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT; /*@req UDS_REQ_0x23_6*/
\r
1760 if(DCM_E_POSITIVERESPONSE == dspReadMemoryByAddress.ResponseCode)
\r
1762 pduTxData->SduLength = 1 + dspReadMemoryByAddress.MemorySize;
\r
1763 if(OpStatus == DCM_READ_PENDING)
\r
1765 dspMemoryState = DCM_MEMORY_READ;
\r
1769 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1774 DsdDspProcessingDone(dspReadMemoryByAddress.ResponseCode);
\r
1778 static boolean checkWriteMemoryByAddress(boolean useId,uint32 memoryAddress,
\r
1779 uint8 memoryAddressFormat,
\r
1780 uint32 memorySize,
\r
1781 const Dcm_DspMemoryIdInfo *dspMemory)
\r
1783 boolean ret = FALSE;
\r
1786 if(useId == FALSE)
\r
1788 if((memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1789 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1790 && (memoryAddress + memorySize - 1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1797 MemoryId = (uint8)(memoryAddress >> ((memoryAddressFormat - 1)*8));
\r
1798 /* REVIEW JB 2012-06-05: See comment for corresponding read function */
\r
1799 memoryAddress = memoryAddress & DCM_MEMORY_ADDRESS_MASK;
\r
1801 if((MemoryId == dspMemory->MemoryIdValue) &&
\r
1802 (memoryAddress >= dspMemory->pWriteMemoryInfo->MemoryAddressLow)
\r
1803 && (memoryAddress <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh)
\r
1804 && (memoryAddress + memorySize -1 <= dspMemory->pWriteMemoryInfo->MemoryAddressHigh))
\r
1814 static boolean lookupWriteMemory(uint32 memoryAddress,
\r
1815 uint8 memoryAddressFormat,
\r
1816 uint32 memorySize,
\r
1817 const Dcm_DspMemoryIdInfo **MemoryIdConfigPtr)
\r
1820 const Dcm_DspMemoryIdInfo *dspMemoryInfo = DCM_Config.Dsp->DspMemory->DspMemoryIdInfo;
\r
1821 boolean memoryFound = FALSE;
\r
1823 for(i = 0;(dspMemoryInfo->Arc_EOL == FALSE) && (memoryFound == FALSE);i++)
\r
1825 if(TRUE == checkWriteMemoryByAddress(DCM_Config.Dsp->DspMemory->DcmDspUseMemoryId, memoryAddress,memoryAddressFormat,memorySize,dspMemoryInfo))
\r
1827 memoryFound = TRUE;
\r
1834 if (memoryFound == TRUE)
\r
1836 *MemoryIdConfigPtr = dspMemoryInfo;
\r
1839 return memoryFound;
\r
1842 static Dcm_NegativeResponseCodeType writeMemoryData(Dcm_OpStatusType* OpStatus,
\r
1843 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr,
\r
1844 uint32 MemoryAddress,
\r
1845 uint32 MemorySize,
\r
1846 uint8 *SourceData)
\r
1848 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1849 Dcm_ReturnWriteMemoryType writeRet;
\r
1850 writeRet = Dcm_WriteMemory(*OpStatus,
\r
1851 MemoryIdConfigPtr->MemoryIdValue,
\r
1855 if(DCM_READ_FAILED == writeRet)
\r
1857 responseCode = DCM_E_GENERALPROGRAMMINGFAILURE; /*@req UDS_REQ_0X3D_16,DCM643*/
\r
1859 else if(DCM_WRITE_PENDING == writeRet)
\r
1861 *OpStatus = DCM_PENDING;
\r
1865 responseCode = DCM_E_POSITIVERESPONSE;
\r
1868 return responseCode;
\r
1871 void DspUdsWriteMemoryByAddress(const PduInfoType* pduRxData, PduInfoType* pduTxData)
\r
1874 uint32 MemoryAddressStart;
\r
1875 uint32 MemoryIdValue;
\r
1876 const Dcm_DspMemoryIdInfo *MemoryIdConfigPtr;
\r
1877 Dcm_NegativeResponseCodeType ResponseCode;
\r
1878 uint8 MemorySizeFormat;
\r
1879 uint8 MemoryAddressFormat;
\r
1880 uint32 MemorySize ;
\r
1881 uint16 MessageLength;
\r
1882 }DspUdsWriteMemoryType;
\r
1884 DspUdsWriteMemoryType dspUdsWriteMemory;
\r
1885 Dcm_OpStatusType OpStatus = DCM_INITIAL;
\r
1886 dspUdsWriteMemory.MemoryAddressStart = 0;
\r
1887 dspUdsWriteMemory.MemoryIdConfigPtr = NULL;
\r
1888 dspUdsWriteMemory.ResponseCode = DCM_E_POSITIVERESPONSE;
\r
1889 dspUdsWriteMemory.MemorySizeFormat = ((uint8)(pduRxData->SduDataPtr[1] & DCM_FORMAT_HIGH_MASK)) >> 4; /*@req UDS_REQ_0x3D_3 & UDS_REQ_0x3D_5*/
\r
1890 dspUdsWriteMemory.MemoryAddressFormat = ((uint8)pduRxData->SduDataPtr[1]) & DCM_FORMAT_LOW_MASK; /*@req UDS_REQ_0x3D_3& UDS_REQ_0x3D_4*/
\r
1891 dspUdsWriteMemory.MemorySize = 0;
\r
1893 if((dspUdsWriteMemory.MemoryAddressFormat == 0) || (dspUdsWriteMemory.MemorySizeFormat == 0)) /*@req UDS_REQ_0x3D_14*/
\r
1895 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE;
\r
1899 /*take value of MemorySize out */
\r
1900 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat; i++)
\r
1902 dspUdsWriteMemory.MemorySize <<= 8;
\r
1903 dspUdsWriteMemory.MemorySize += (uint32)(pduRxData->SduDataPtr[2 + i +dspUdsWriteMemory.MemoryAddressFormat]);
\r
1905 dspUdsWriteMemory.MessageLength = (uint16)(2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemorySize);
\r
1906 if(dspUdsWriteMemory.MessageLength == pduRxData->SduLength)
\r
1908 /*take Start Address out */
\r
1909 for(i = 0; i < dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
1911 dspUdsWriteMemory.MemoryAddressStart <<= 8;
\r
1912 dspUdsWriteMemory.MemoryAddressStart += (uint32)(pduRxData->SduDataPtr[2 + i]);
\r
1914 if(TRUE == lookupWriteMemory(dspUdsWriteMemory.MemoryAddressStart,
\r
1915 dspUdsWriteMemory.MemoryAddressFormat,
\r
1916 dspUdsWriteMemory.MemorySize,
\r
1917 &dspUdsWriteMemory.MemoryIdConfigPtr))
\r
1919 if (DspCheckSecurityLevel(dspUdsWriteMemory.MemoryIdConfigPtr->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
1921 dspUdsWriteMemory.ResponseCode = writeMemoryData(&OpStatus,
\r
1922 dspUdsWriteMemory.MemoryIdConfigPtr,
\r
1923 dspUdsWriteMemory.MemoryAddressStart,
\r
1924 dspUdsWriteMemory.MemorySize,
\r
1925 &pduRxData->SduDataPtr[2 + dspUdsWriteMemory.MemoryAddressFormat + dspUdsWriteMemory.MemorySizeFormat]);
\r
1929 dspUdsWriteMemory.ResponseCode = DCM_E_SECUTITYACCESSDENIED; /*@req UDS_REQ_0X3D_15,Dcm490*/
\r
1934 dspUdsWriteMemory.ResponseCode = DCM_E_REQUESTOUTOFRANGE; /*@req UDS_REQ_0x3D_11,UDS_REQ_0x3D_12,Dcm489*/
\r
1939 dspUdsWriteMemory.ResponseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;/*@req UDS_REQ_0x3D_9*/
\r
1942 if(DCM_E_POSITIVERESPONSE == dspUdsWriteMemory.ResponseCode)
\r
1944 pduTxData->SduLength = 2 + dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat;
\r
1945 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
1946 for(i = 0; i < dspUdsWriteMemory.MemorySizeFormat + dspUdsWriteMemory.MemoryAddressFormat; i++)
\r
1948 pduTxData->SduDataPtr[2 + i] = pduRxData->SduDataPtr[2 + i];
\r
1949 if(OpStatus != DCM_PENDING)
\r
1951 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
1955 dspMemoryState=DCM_MEMORY_WRITE;
\r
1961 DsdDspProcessingDone(dspUdsWriteMemory.ResponseCode);
\r
1965 static boolean checkPeriodicIdentifierBuffer(uint8 PeriodicDid,uint8 Length,uint8 *postion)
\r
1968 boolean ret = FALSE;
\r
1969 for(i = 0;(i < Length) && (ret == FALSE);i++)
\r
1971 if(PeriodicDid == dspPDidRef.dspPDid[i].PeriodicDid)
\r
1981 /* REVIEW JB 2012-06-05: Please describe the buffer algorithm because it is not obvious when looking at this function. */
\r
1982 static void ClearPeriodicIdentifierBuffer(uint8 BufferEnd,uint8 postion)
\r
1984 dspPDidRef.dspPDid[postion].PeriodicDid = dspPDidRef.dspPDid[BufferEnd ].PeriodicDid;
\r
1985 dspPDidRef.dspPDid[postion].PDidTxCounter = dspPDidRef.dspPDid[BufferEnd].PDidTxCounter;
\r
1986 dspPDidRef.dspPDid[postion].PDidTxCounterNumber = dspPDidRef.dspPDid[BufferEnd].PDidTxCounterNumber;
\r
1987 dspPDidRef.dspPDid[BufferEnd].PeriodicDid = 0;
\r
1988 dspPDidRef.dspPDid[BufferEnd].PDidTxCounter = 0;
\r
1989 dspPDidRef.dspPDid[BufferEnd ].PDidTxCounterNumber = 0;
\r
1992 static Dcm_NegativeResponseCodeType readPeriodDidData(const Dcm_DspDidType *PDidPtr, uint8 *Data,uint16 *Length)
\r
1994 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
1995 if ((PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL)
\r
1996 && (PDidPtr->DspDidConditionCheckReadFnc != NULL)
\r
1997 && (PDidPtr->DspDidReadDataFnc != NULL) )
\r
1999 if (DspCheckSessionLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2001 if (DspCheckSecurityLevel(PDidPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2003 Std_ReturnType result = E_NOT_OK;
\r
2004 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2005 result = PDidPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
2006 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE))
\r
2008 result = E_NOT_OK;
\r
2009 if (PDidPtr->DspDidInfoRef->DspDidFixedLength)
\r
2011 *Length= PDidPtr->DspDidSize;
\r
2016 if(PDidPtr->DspDidReadDataLengthFnc!=NULL)
\r
2018 result = PDidPtr->DspDidReadDataLengthFnc(Length);
\r
2022 responseCode = DCM_E_GENERALREJECT;
\r
2025 if (result == E_OK)
\r
2027 result = PDidPtr->DspDidReadDataFnc(Data);
\r
2028 if (result != E_OK)
\r
2030 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2035 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2040 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2045 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2050 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2055 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2057 return responseCode;
\r
2060 static Dcm_NegativeResponseCodeType DspSavePeriodicData(uint16 didNr, uint32 periodicTransmitCounter,uint8 PdidBufferNr)
\r
2062 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2063 const Dcm_DspDidType *SourceDid = NULL;
\r
2064 Dcm_DspDDDType *DDidPtr = NULL;
\r
2066 if (TRUE == lookupDid(didNr, &SourceDid))
\r
2068 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef) == TRUE)
\r
2070 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef) == TRUE)
\r
2072 Std_ReturnType result = E_NOT_OK;
\r
2073 Dcm_NegativeResponseCodeType errorCode = DCM_E_POSITIVERESPONSE;
\r
2075 if(SourceDid->DspDidConditionCheckReadFnc != NULL)
\r
2077 result = SourceDid->DspDidConditionCheckReadFnc(&errorCode);
\r
2079 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE))
\r
2081 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2083 if((SourceDid->DspDidInfoRef->DspDidFixedLength!=TRUE) && (SourceDid->DspDidReadDataLengthFnc == NULL))
\r
2085 responseCode = DCM_E_GENERALREJECT;
\r
2090 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2095 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2098 else if(LookupDDD(didNr,&DDidPtr) == TRUE)
\r
2100 responseCode = DCM_E_POSITIVERESPONSE;
\r
2104 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2106 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2108 dspPDidRef.dspPDid[PdidBufferNr].PeriodicDid = (uint8)didNr & DCM_DID_LOW_MASK;
\r
2109 /* REVIEW JB 2012-06-05: Why is TxCounter set to PdidBufferNr - it seems wrong. */
\r
2110 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounter = PdidBufferNr*3;
\r
2112 dspPDidRef.dspPDid[PdidBufferNr].PDidTxCounterNumber = periodicTransmitCounter;
\r
2114 return responseCode;
\r
2116 static void ClearPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData )
\r
2118 uint16 PdidNumber;
\r
2119 uint8 PDidLowByte;
\r
2120 uint8 PdidBufferNr;
\r
2121 uint8 PdidPostion;
\r
2123 if( pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE )
\r
2125 PdidNumber = pduRxData->SduLength - 2;
\r
2126 for(i = 0;i < PdidNumber;i++)
\r
2128 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2129 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2131 dspPDidRef.PDidNr--;
\r
2132 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr, PdidPostion);
\r
2136 pduTxData->SduLength = 1;
\r
2141 UDS Service 0x2a - Read Data By Periodic Identifier
\r
2143 void DspReadDataByPeriodicIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2145 /** @req DCM254 */
\r
2146 uint8 PDidLowByte;
\r
2147 uint16 PdidNumber;
\r
2148 uint8 PdidPostion;
\r
2150 uint8 PdidBufferNr;
\r
2151 uint32 periodicTransmitCounter;
\r
2152 uint16 DataLength;
\r
2153 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2154 const Dcm_DspDidType *PDidPtr = NULL;
\r
2155 Dcm_DspDDDType *DDidPtr = NULL;
\r
2156 PdidBufferNr = dspPDidRef.PDidNr;
\r
2157 if(pduRxData->SduLength > 2)
\r
2160 switch(pduRxData->SduDataPtr[1])
\r
2162 case DCM_PERIODICTRANSMIT_DEFAULT_MODE:
\r
2163 periodicTransmitCounter = 0;
\r
2165 case DCM_PERIODICTRANSMIT_SLOWRATE_MODE:
\r
2166 periodicTransmitCounter = DCM_PERIODICTRANSMIT_SLOW;
\r
2168 case DCM_PERIODICTRANSMIT_MEDIUM_MODE:
\r
2169 periodicTransmitCounter = DCM_PERIODICTRANSMIT_MEDIUM;
\r
2171 case DCM_PERIODICTRANSMIT_FAST_MODE:
\r
2172 periodicTransmitCounter = DCM_PERIODICTRANSMIT_FAST;
\r
2174 case DCM_PERIODICTRANSMIT_STOPSENDING_MODE:
\r
2175 ClearPeriodicIdentifier(pduRxData,pduTxData);
\r
2178 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2181 if(pduRxData->SduDataPtr[1] != DCM_PERIODICTRANSMIT_STOPSENDING_MODE)
\r
2183 PdidNumber = pduRxData->SduLength - 2;
\r
2184 if(1 == PdidNumber)
\r
2186 PDidLowByte = pduRxData->SduDataPtr[2];
\r
2187 if(checkPeriodicIdentifierBuffer(PDidLowByte,dspPDidRef.PDidNr,&PdidPostion) == TRUE)
\r
2189 if(0 == periodicTransmitCounter)
\r
2191 if (TRUE == lookupDid(((uint16)PDidLowByte + 0xF200), &PDidPtr)) /*UDS_REQ_0x2A_1*/
\r
2193 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2194 responseCode = readPeriodDidData(PDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2195 pduTxData->SduLength = DataLength + 2;
\r
2197 else if(TRUE == LookupDDD((0xF200 + (uint16)PDidLowByte),&DDidPtr))
\r
2199 pduTxData->SduDataPtr[1] = PDidLowByte;
\r
2200 responseCode = readDDDData(DDidPtr,&pduTxData->SduDataPtr[2],&DataLength);
\r
2201 pduTxData->SduLength = DataLength + 2;
\r
2205 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2207 if(responseCode != DCM_E_POSITIVERESPONSE)
\r
2209 dspPDidRef.PDidNr--;
\r
2210 ClearPeriodicIdentifierBuffer(dspPDidRef.PDidNr,PdidPostion);
\r
2215 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2216 pduTxData->SduLength = 1;
\r
2221 responseCode = DspSavePeriodicData((DCM_PERODICDID_HIHG_MASK + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2223 pduTxData->SduLength = 1;
\r
2226 else if((PdidNumber + PdidBufferNr) <= DCM_LIMITNUMBER_PERIODDATA) /*UDS_REQ_0x2A_6*/
\r
2228 for(i = 0;(i < PdidNumber)&&(responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2230 PDidLowByte = pduRxData->SduDataPtr[2 + i];
\r
2231 if(checkPeriodicIdentifierBuffer(PDidLowByte,PdidBufferNr,&PdidPostion) == TRUE)
\r
2233 if(dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber != periodicTransmitCounter)
\r
2235 dspPDidRef.dspPDid[PdidPostion].PDidTxCounterNumber = periodicTransmitCounter;
\r
2240 responseCode = DspSavePeriodicData((0xF200 + (uint16)PDidLowByte),periodicTransmitCounter,PdidBufferNr);
\r
2243 pduTxData->SduLength = 1;
\r
2248 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2250 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2252 dspPDidRef.PDidNr = PdidBufferNr;
\r
2256 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_PERIODICTRANSMIT_STOPSENDING_MODE))
\r
2258 memset(&dspPDidRef,0,sizeof(dspPDidRef));
\r
2259 pduTxData->SduLength = 1;
\r
2263 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2265 DsdDspProcessingDone(responseCode);
\r
2268 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyDid(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2271 uint16 SourceDidNr;
\r
2272 const Dcm_DspDidType *SourceDid = NULL;
\r
2273 Dcm_DspDDDType *DDid = NULL;
\r
2274 uint16 SourceLength = 0;
\r
2275 uint16 DidLength = 0;
\r
2276 uint16 Length = 0;
\r
2278 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2280 if(FALSE == LookupDDD(DDIdentifier, &DDid))
\r
2282 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2286 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2288 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2292 DDid = &dspDDD[Num];
\r
2297 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2301 if(SourceLength > DCM_MAX_DDDSOURCE_NUMBER)
\r
2303 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2306 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2308 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN4) /SID_AND_ALFID_LEN4;
\r
2309 if(((Length*SID_AND_ALFID_LEN4) == (pduRxData->SduLength - SID_AND_ALFID_LEN4)) && (Length != 0))
\r
2311 if((Length + SourceLength) <= DCM_MAX_DDDSOURCE_NUMBER)
\r
2313 for(i = 0;(i < Length) && (responseCode == DCM_E_POSITIVERESPONSE);i++)
\r
2315 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
2316 if(TRUE == lookupDid(SourceDidNr, &SourceDid))/*UDS_REQ_0x2C_4*/
\r
2318 if(DspCheckSessionLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef))
\r
2320 if(DspCheckSecurityLevel(SourceDid->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef))
\r
2322 if(SourceDid->DspDidInfoRef->DspDidFixedLength == TRUE)
\r
2324 DidLength = SourceDid->DspDidSize;
\r
2328 if( SourceDid->DspDidReadDataLengthFnc != NULL)
\r
2330 SourceDid->DspDidReadDataLengthFnc(&DidLength);
\r
2333 if(DidLength != 0)
\r
2335 if((pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2336 (pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4] != 0) &&
\r
2337 (((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
2339 DDid->DDDSource[i + SourceLength].formatOrPosition = pduRxData->SduDataPtr[SID_AND_ALFID_LEN6 + i*SID_AND_ALFID_LEN4];
\r
2340 DDid->DDDSource[i + SourceLength].Size = pduRxData->SduDataPtr[SID_AND_ALFID_LEN7 + i*SID_AND_ALFID_LEN4];
\r
2341 DDid->DDDSource[i + SourceLength].SourceAddressOrDid = SourceDid->DspDidIdentifier;
\r
2342 DDid->DDDSource[i + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_DID;
\r
2346 /*UDS_REQ_0x2C_6*/
\r
2347 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2353 /*UDS_REQ_0x2C_14*/
\r
2354 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2359 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2364 /*UDS_REQ_0x2C_19,DCM726*/
\r
2365 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2371 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2377 /*UDS_REQ_0x2C_13*/
\r
2378 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2383 /*UDS_REQ_0x2C_11*/
\r
2384 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2386 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2388 DDid->DynamicallyDid = DDIdentifier;
\r
2389 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2392 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2394 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYDID;
\r
2397 return responseCode;
\r
2400 static Dcm_NegativeResponseCodeType dynamicallyDefineDataIdentifierbyAddress(uint16 DDIdentifier,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2402 uint8 LengthCount;
\r
2403 uint8 SourceCount;
\r
2405 uint8 AddressFormat;
\r
2406 uint8 MemorySizeFormat;
\r
2407 uint32 MemoryAddress = 0;
\r
2408 uint16 MemorySize = 0;
\r
2409 uint16 SourceLength = 0;
\r
2410 Dcm_DspDDDType *DDid = NULL;
\r
2411 const Dcm_DspMemoryIdInfo *SourceMemoryInfo = NULL;
\r
2413 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2415 if(FALSE == LookupDDD(DDIdentifier,&DDid))
\r
2417 while((Num < DCM_MAX_DDD_NUMBER) && (dspDDD[Num].DynamicallyDid != 0 ))
\r
2421 if(Num >= DCM_MAX_DDD_NUMBER)
\r
2423 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2427 DDid = &dspDDD[Num];
\r
2432 while((SourceLength < DCM_MAX_DDDSOURCE_NUMBER) && (DDid->DDDSource[SourceLength].formatOrPosition != 0 ))
\r
2436 if(SourceLength >= DCM_MAX_DDDSOURCE_NUMBER)
\r
2438 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2441 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2443 AddressFormat = (uint8)pduRxData->SduDataPtr[4] & DCM_FORMAT_LOW_MASK;
\r
2444 MemorySizeFormat = (uint8)(pduRxData->SduDataPtr[4] >> 4) & DCM_FORMAT_LOW_MASK;
\r
2445 if((AddressFormat+MemorySizeFormat) != 0)
\r
2447 Length = (pduRxData->SduLength - SID_AND_ALFID_LEN5) / (AddressFormat + MemorySizeFormat);
\r
2449 if((AddressFormat != 0) && (MemorySizeFormat != 0) && ((SourceLength+Length) <= DCM_MAX_DDDSOURCE_NUMBER))
\r
2451 if((Length != 0)&&( Length * (AddressFormat + MemorySizeFormat) == (pduRxData->SduLength - 5) ))
\r
2453 /* REVIEW JB 2012-06-05: Use better names than i and j to increase readability */
\r
2454 for(LengthCount = 0; (LengthCount < Length) && (responseCode == DCM_E_POSITIVERESPONSE); LengthCount++)
\r
2456 MemoryAddress = 0;
\r
2457 for(SourceCount = 0; SourceCount < AddressFormat; SourceCount++)
\r
2459 MemoryAddress = MemoryAddress << 8;
\r
2460 MemoryAddress += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2463 /*take value of MemorySize out */
\r
2465 for(SourceCount = 0; SourceCount < MemorySizeFormat; SourceCount++)
\r
2467 MemorySize = MemorySize << 8;
\r
2468 MemorySize += (uint32)(pduRxData->SduDataPtr[5 + SourceCount + AddressFormat + LengthCount * (AddressFormat + MemorySizeFormat)]);
\r
2470 if(TRUE == lookupReadMemory(MemoryAddress, AddressFormat,MemorySize,&SourceMemoryInfo))
\r
2472 if(DspCheckSecurityLevel(SourceMemoryInfo->pReadMemoryInfo->pSecurityLevel) == TRUE)
\r
2474 DDid->DDDSource[LengthCount + SourceLength].formatOrPosition = pduRxData->SduDataPtr[4];
\r
2475 DDid->DDDSource[LengthCount + SourceLength].SourceAddressOrDid = MemoryAddress;
\r
2476 DDid->DDDSource[LengthCount + SourceLength].Size = MemorySize;
\r
2477 DDid->DDDSource[LengthCount + SourceLength].DDDTpyeID = DCM_DDD_SOURCE_ADDRESS;
\r
2478 /*UDS_REQ_0x2C_6*/
\r
2482 /*UDS_REQ_0x2C_19,DCM726*/
\r
2483 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2488 /*UDS_REQ_0x2C_15,UDS_REQ_0x2C_16*/
\r
2489 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2492 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2494 DDid->DynamicallyDid = DDIdentifier;
\r
2499 /*UDS_REQ_0x2C_11*/
\r
2500 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2505 /*UDS_REQ_0x2C_17, UDS_REQ_0x2C_18*/
\r
2506 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2510 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2512 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS;
\r
2515 return responseCode;
\r
2521 UDS Service 0x2c - Clear dynamically Did
\r
2523 static Dcm_NegativeResponseCodeType CleardynamicallyDid(uint16 DDIdentifier,const PduInfoType *pduRxData, PduInfoType * pduTxData)
\r
2525 /*UDS_REQ_0x2C_5*/
\r
2529 uint8 ClearNum = 0;
\r
2530 Dcm_DspDDDType *DDid = NULL;
\r
2531 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2533 if(pduRxData->SduLength == 4)
\r
2535 if(TRUE == LookupDDD(DDIdentifier,&DDid))
\r
2538 if((checkPeriodicIdentifierBuffer(pduRxData->SduDataPtr[3], dspPDidRef.PDidNr, &position) == TRUE)&&(pduRxData->SduDataPtr[2] == 0xF2))
\r
2540 /*UDS_REQ_0x2C_9*/
\r
2541 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2545 for(i = 1;i < DCM_MAX_DDD_NUMBER;i++)
\r
2547 if(0 == dspDDD[i].DynamicallyDid)
\r
2550 DDid->DynamicallyDid = dspDDD[ClearNum].DynamicallyDid;
\r
2551 dspDDD[ClearNum].DynamicallyDid = 0;
\r
2552 for(ClearCount = 0;ClearCount < DCM_MAX_DDDSOURCE_NUMBER;ClearCount++)
\r
2555 DDid->DDDSource[ClearCount].DDDTpyeID = dspDDD[ClearNum].DDDSource[ClearCount].DDDTpyeID;
\r
2556 DDid->DDDSource[ClearCount].formatOrPosition = dspDDD[ClearNum].DDDSource[ClearCount].formatOrPosition;
\r
2557 DDid->DDDSource[ClearCount].SourceAddressOrDid = dspDDD[ClearNum].DDDSource[ClearCount].SourceAddressOrDid;
\r
2558 DDid->DDDSource[ClearCount].Size = dspDDD[ClearNum].DDDSource[ClearCount].Size;
\r
2559 dspDDD[ClearNum].DDDSource[ClearCount].DDDTpyeID = 0;
\r
2560 dspDDD[ClearNum].DDDSource[ClearCount].formatOrPosition = 0;
\r
2561 dspDDD[ClearNum].DDDSource[ClearCount].SourceAddressOrDid = 0;
\r
2562 dspDDD[ClearNum].DDDSource[ClearCount].Size = 0;
\r
2571 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2573 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2575 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2576 pduTxData->SduLength = 2;
\r
2579 return responseCode;
\r
2582 void DspDynamicallyDefineDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2584 /*UDS_REQ_0x2C_1,DCM 259*/
\r
2587 boolean PeriodicdUse = FALSE;
\r
2588 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2589 uint16 DDIdentifier = ((((uint16)pduRxData->SduDataPtr[2]) << 8) & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[3] & DCM_DID_LOW_MASK);
\r
2590 if(pduRxData->SduLength > 2)
\r
2592 /* REVIEW JB 2012-06-05: Clarify that F2 and F3 is included by comment */
\r
2593 if((pduRxData->SduDataPtr[2] & 0xF2) == 0xF2)
\r
2595 switch(pduRxData->SduDataPtr[1]) /*UDS_REQ_0x2C_2,DCM 646*/
\r
2597 case DCM_DDD_SUBFUNCTION_DEFINEBYDID:
\r
2598 responseCode = dynamicallyDefineDataIdentifierbyDid(DDIdentifier,pduRxData,pduTxData);
\r
2600 case DCM_DDD_SUBFUNCTION_DEFINEBYADDRESS:
\r
2601 responseCode = dynamicallyDefineDataIdentifierbyAddress(DDIdentifier,pduRxData,pduTxData);
\r
2603 case DCM_DDD_SUBFUNCTION_CLEAR:
\r
2604 responseCode = CleardynamicallyDid(DDIdentifier,pduRxData,pduTxData);
\r
2607 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
2608 /*UDS_REQ_0x2C_10*/
\r
2614 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2616 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2618 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
2619 pduTxData->SduDataPtr[3] = pduRxData->SduDataPtr[3];
\r
2620 pduTxData->SduLength = 4;
\r
2623 else if((pduRxData->SduLength == 2)&&(pduRxData->SduDataPtr[1] == DCM_DDD_SUBFUNCTION_CLEAR))
\r
2625 /*UDS_REQ_0x2C_7*/
\r
2626 for(i = 0;i < DCM_MAX_DDD_NUMBER;i++)
\r
2628 if(checkPeriodicIdentifierBuffer((uint8)(dspDDD[i].DynamicallyDid & DCM_DID_LOW_MASK),dspPDidRef.PDidNr,&Position) == TRUE)
\r
2630 PeriodicdUse = TRUE;
\r
2633 if(PeriodicdUse == FALSE)
\r
2635 memset(dspDDD,0,sizeof(dspDDD));
\r
2636 pduTxData->SduDataPtr[1] = DCM_DDD_SUBFUNCTION_CLEAR;
\r
2637 pduTxData->SduLength = 2;
\r
2641 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2646 /*UDS_REQ_0x2C_11*/
\r
2647 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2649 DsdDspProcessingDone(responseCode);
\r
2652 static Dcm_NegativeResponseCodeType DspIOControlReturnControlToECU(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2654 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2655 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidReturnControlToEcu == TRUE)
\r
2657 if(pduRxData->SduLength > 4)
\r
2659 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2661 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2663 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2665 DidPtr->DspDidReturnControlToEcuFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2670 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2675 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2680 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2685 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2688 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2690 DidPtr->DspDidReturnControlToEcuFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2691 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2695 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2700 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2706 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2708 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2710 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2711 pduTxData->SduDataPtr[3] = DCM_RETURN_CONTROL_TO_ECU;
\r
2714 return responseCode;
\r
2717 static Dcm_NegativeResponseCodeType DspIOControlResetToDefault(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2719 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2720 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidResetToDefault == TRUE)
\r
2722 if(pduRxData->SduLength > 4)
\r
2724 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2726 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2728 if(DidPtr->DspDidReturnControlToEcuFnc != NULL)
\r
2730 DidPtr->DspDidResetToDeaultFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2734 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2739 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2744 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2749 if(DidPtr->DspDidResetToDeaultFnc != NULL)
\r
2752 if(DidPtr->DspDidControlRecordSize != NULL)
\r
2754 DidPtr->DspDidResetToDeaultFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2755 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2759 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2764 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2770 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2772 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2774 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize+4;
\r
2775 pduTxData->SduDataPtr[3] = DCM_RESET_TO_DEFAULT;
\r
2777 return responseCode;
\r
2781 UDS Service 0x2F - IOControl Freeze Current State
\r
2783 static Dcm_NegativeResponseCodeType DspIOControlFreezeCurrentState(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2785 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2786 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidFreezeCurrentState == TRUE)
\r
2788 if(pduRxData->SduLength > 4)
\r
2790 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2792 if(((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7) >> 3) == (pduRxData->SduLength - 4))
\r
2794 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2796 DidPtr->DspDidFreezeCurrentStateFnc(NULL,&pduRxData->SduDataPtr[4],&pduTxData->SduDataPtr[4],&responseCode);
\r
2800 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2805 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2810 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2815 if(DidPtr->DspDidFreezeCurrentStateFnc != NULL)
\r
2818 if(DidPtr->DspDidControlRecordSize != 0)
\r
2820 DidPtr->DspDidFreezeCurrentStateFnc(NULL,NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2821 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2825 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2830 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2836 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2838 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2840 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2841 pduTxData->SduDataPtr[3] = DCM_FREEZE_CURRENT_STATE;
\r
2844 return responseCode;
\r
2847 static Dcm_NegativeResponseCodeType DspIOControlShortTeamAdjustment(const Dcm_DspDidType *DidPtr,const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2849 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2850 uint8 didControlOptionRecordSize = DidPtr->DspDidControlRecordSize->DspDidControlOptionRecordSize;
\r
2851 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidShortTermAdjustment == TRUE)
\r
2853 if(pduRxData->SduLength > 4)
\r
2855 if(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl != NULL)
\r
2857 if(((((DidPtr->DspDidControlRecordSize->DspDidControlRecordSize + 7)) >> 3) + (didControlOptionRecordSize)) == (pduRxData->SduLength - 4))
\r
2859 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2861 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],&pduRxData->SduDataPtr[4 + didControlOptionRecordSize],&pduTxData->SduDataPtr[4],&responseCode);
\r
2865 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2868 else if((didControlOptionRecordSize) == (pduRxData->SduLength - 4))
\r
2870 if(DidPtr->DspDidShortTermAdjustmentFnc != NULL)
\r
2872 DidPtr->DspDidShortTermAdjustmentFnc(&pduRxData->SduDataPtr[4],NULL,&pduTxData->SduDataPtr[4],&responseCode);
\r
2876 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2881 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2886 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2891 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2896 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2898 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2900 pduTxData->SduLength = DidPtr->DspDidControlRecordSize->DspDidControlStatusRecordSize + 4;
\r
2901 pduTxData->SduDataPtr[3] = DCM_SHORT_TERM_ADJUSTMENT;
\r
2904 return responseCode;
\r
2907 void DspIOControlByDataIdentifier(const PduInfoType *pduRxData,PduInfoType *pduTxData)
\r
2910 const Dcm_DspDidType *DidPtr = NULL;
\r
2911 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
2912 didNr = (pduRxData->SduDataPtr[1] << 8 & DCM_DID_HIGH_MASK) + (pduRxData->SduDataPtr[2] & DCM_DID_LOW_MASK);
\r
2913 if(pduRxData->SduLength > 3)
\r
2915 if(TRUE == lookupDid(didNr, &DidPtr))
\r
2917 if(FALSE == DidPtr->DspDidUsePort)
\r
2919 if(NULL != DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl)
\r
2921 if(TRUE == DspCheckSessionLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSessionRef))
\r
2923 if(TRUE == DspCheckSecurityLevel(DidPtr->DspDidInfoRef->DspDidAccess.DspDidControl->DspDidControlSecurityLevelRef))
\r
2925 switch(pduRxData->SduDataPtr[3])
\r
2927 case DCM_RETURN_CONTROL_TO_ECU:
\r
2928 responseCode = DspIOControlReturnControlToECU(DidPtr,pduRxData,pduTxData);
\r
2930 case DCM_RESET_TO_DEFAULT:
\r
2931 responseCode = DspIOControlResetToDefault(DidPtr,pduRxData,pduTxData);
\r
2933 case DCM_FREEZE_CURRENT_STATE:
\r
2934 responseCode = DspIOControlFreezeCurrentState(DidPtr,pduRxData,pduTxData);
\r
2936 case DCM_SHORT_TERM_ADJUSTMENT:
\r
2937 responseCode = DspIOControlShortTeamAdjustment(DidPtr,pduRxData,pduTxData);
\r
2940 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2947 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
2952 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2957 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2962 /* if UsePort == True, NRC 0x10 */
\r
2963 responseCode = DCM_E_GENERALREJECT;
\r
2968 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
2973 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
2975 if(responseCode == DCM_E_POSITIVERESPONSE)
\r
2977 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
2978 pduTxData->SduDataPtr[2] = pduRxData->SduDataPtr[2];
\r
2980 DsdDspProcessingDone(responseCode);
\r