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
19 * General requirements
\r
21 /** @req DCM273 */ /** @req DCM272 */
\r
22 /** @req DCM039 */ /** @req DCM038 */ /** @req DCM269 */
\r
23 /** @req DCM271 */ /** @req DCM274 */ /** @req DCM275 */ /** @req DCM424 */
\r
28 #include "Dcm_Internal.h"
\r
33 #define ZERO_SUB_FUNCTION 0x00
\r
38 #define BYTES_TO_DTC(hb, mb, lb) (((uint32)(hb) << 16) | ((uint32)(mb) << 8) | (uint32)(lb))
\r
39 #define DTC_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFF)
\r
40 #define DTC_MID_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFF)
\r
41 #define DTC_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFF)
\r
45 boolean resetPending;
\r
46 PduIdType resetPduId;
\r
47 } DspUdsEcuResetDataType;
\r
49 static DspUdsEcuResetDataType dspUdsEcuResetData;
\r
53 boolean reqInProgress;
\r
54 Dcm_SecLevelType reqSecLevel;
\r
55 const Dcm_DspSecurityRowType *reqSecLevelRef;
\r
56 } DspUdsSecurityAccessDataType;
\r
58 static DspUdsSecurityAccessDataType dspUdsSecurityAccesData;
\r
63 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
64 dspUdsEcuResetData.resetPending = FALSE;
\r
74 boolean DspCheckSessionLevel(const Dcm_DspSessionRowType **sessionLevelRefTable)
\r
76 boolean returnStatus = TRUE;
\r
77 Dcm_SesCtrlType currentSession;
\r
79 DslGetSesCtrlType(¤tSession);
\r
80 while (((*sessionLevelRefTable)->DspSessionLevel != currentSession) && !(*sessionLevelRefTable)->Arc_EOL) {
\r
81 sessionLevelRefTable++;
\r
84 if ((*sessionLevelRefTable)->Arc_EOL) {
\r
85 returnStatus = FALSE;
\r
88 return returnStatus;
\r
92 boolean DspCheckSecurityLevel(const Dcm_DspSecurityRowType **securityLevelRefTable)
\r
94 boolean returnStatus = TRUE;
\r
95 Dcm_SecLevelType currentSecurityLevel;
\r
97 DslGetSecurityLevel(¤tSecurityLevel);
\r
98 while (((*securityLevelRefTable)->DspSecurityLevel != currentSecurityLevel) && !(*securityLevelRefTable)->Arc_EOL) {
\r
99 securityLevelRefTable++;
\r
101 if ((*securityLevelRefTable)->Arc_EOL) {
\r
102 returnStatus = FALSE;
\r
105 return returnStatus;
\r
109 static Std_ReturnType askApplicationForSessionPermission(Dcm_SesCtrlType newSessionLevel)
\r
111 Std_ReturnType returnCode = E_OK;
\r
112 const Dcm_DslSessionControlType *sesControl = DCM_Config.Dsl->DslSessionControl;
\r
113 Dcm_SesCtrlType currentSessionLevel;
\r
114 Std_ReturnType result;
\r
116 while (!sesControl->Arc_EOL && (returnCode != E_SESSION_NOT_ALLOWED)) {
\r
117 if (sesControl->GetSesChgPermission != NULL) {
\r
118 Dcm_GetSesCtrlType(¤tSessionLevel);
\r
119 result = sesControl->GetSesChgPermission(currentSessionLevel ,newSessionLevel);
\r
120 if (result != E_OK) {
\r
121 returnCode = result;
\r
131 void DspUdsDiagnosticSessionControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
134 const Dcm_DspSessionRowType *sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow;
\r
135 Dcm_SesCtrlType reqSessionType;
\r
136 Std_ReturnType result;
\r
138 if (pduRxData->SduLength == 2) {
\r
139 reqSessionType = pduRxData->SduDataPtr[1];
\r
140 // Check if type exist in session table
\r
141 while ((sessionRow->DspSessionLevel != reqSessionType) && !sessionRow->Arc_EOL) {
\r
145 if (!sessionRow->Arc_EOL) {
\r
146 result = askApplicationForSessionPermission(reqSessionType);
\r
147 if (result == E_OK) {
\r
148 DslSetSesCtrlType(reqSessionType); /** @req DCM311 */
\r
149 // Create positive response
\r
150 pduTxData->SduDataPtr[1] = reqSessionType;
\r
151 pduTxData->SduLength = 2;
\r
152 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
155 // TODO: Add handling of special case of E_FORCE_RCRRP (Dcm138)
\r
156 DsdDspProcessingDone(DCM_E_CONDITIONSNOTCORRECT); /** @req DCM308 */
\r
160 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED); /** @req DCM307 */
\r
165 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
170 void DspUdsEcuReset(const PduInfoType *pduRxData, PduIdType txPduId, PduInfoType *pduTxData)
\r
173 uint8 reqResetType;
\r
175 if (pduRxData->SduLength == 2) {
\r
176 reqResetType = pduRxData->SduDataPtr[1];
\r
178 switch (reqResetType)
\r
180 case 0x01: // Hard reset
\r
181 // TODO: Ask application for permission (Dcm373) (Dcm375) (Dcm377)
\r
183 // Schedule the reset
\r
184 dspUdsEcuResetData.resetPending = TRUE;
\r
185 dspUdsEcuResetData.resetPduId = txPduId;
\r
187 // Create positive response
\r
188 pduTxData->SduDataPtr[1] = reqResetType;
\r
189 pduTxData->SduLength = 2;
\r
190 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
194 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
200 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
205 void DspUdsClearDiagnosticInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
209 Dem_ReturnClearDTCType result;
\r
211 if (pduRxData->SduLength == 4) {
\r
212 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[1], pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3]);
\r
214 result = Dem_ClearDTC(dtc, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY); /** @req DCM005 */
\r
219 // Create positive response
\r
220 pduTxData->SduLength = 1;
\r
221 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
225 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
231 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
236 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x01_0x07_0x11_0x12(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
241 uint8 dtcStatusAvailabilityMask;
\r
242 uint8 dtcFormatIdentifier;
\r
243 uint8 dtcCountHighByte;
\r
244 uint8 dtcCountLowByte;
\r
247 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
248 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
250 // Setup the DTC filter
\r
251 switch (pduRxData->SduDataPtr[1]) /** @req DCM293 */
\r
253 case 0x01: // reportNumberOfDTCByStatusMask
\r
254 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
257 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
258 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
261 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
262 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
265 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
266 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
270 setDtcFilterResult = DEM_WRONG_FILTER;
\r
274 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
275 uint16 numberOfFilteredDtc;
\r
276 uint8 dtcStatusMask;
\r
277 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
280 Dem_GetNumberOfFilteredDtc(&numberOfFilteredDtc);
\r
281 Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
283 // Create positive response (ISO 14229-1 table 251)
\r
284 txData->reportType = pduRxData->SduDataPtr[1]; // reportType
\r
285 txData->dtcStatusAvailabilityMask = dtcStatusMask; // DTCStatusAvailabilityMask
\r
286 txData->dtcFormatIdentifier = Dem_GetTranslationType(); // DTCFormatIdentifier
\r
287 txData->dtcCountHighByte = (numberOfFilteredDtc >> 8); // DTCCount high byte
\r
288 txData->dtcCountLowByte = (numberOfFilteredDtc & 0xFF); // DTCCount low byte
\r
289 pduTxData->SduLength = 6;
\r
292 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
295 return responseCode;
\r
299 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
301 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
302 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
306 uint8 dtcMiddleByte;
\r
309 } dtcAndStatusRecordType;
\r
314 uint8 dtcStatusAvailabilityMask;
\r
315 dtcAndStatusRecordType dtcAndStatusRecord[];
\r
318 // Setup the DTC filter
\r
319 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
321 case 0x02: // reportDTCByStatusMask
\r
322 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
325 case 0x0A: // reportSupportedDTC
\r
326 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
329 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
330 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
333 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
334 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
337 case 0x15: // reportDTCWithPermanentStatus
\r
338 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
342 setDtcFilterResult = DEM_WRONG_FILTER;
\r
346 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
347 uint8 dtcStatusMask;
\r
348 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
349 Dem_ReturnGetNextFilteredDTCType getNextFilteredDtcResult;
\r
351 Dem_EventStatusExtendedType dtcStatus;
\r
352 uint16 nrOfDtcs = 0;
\r
355 Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
357 // Create positive response (ISO 14229-1 table 252)
\r
358 txData->reportType = pduRxData->SduDataPtr[1];
\r
359 txData->dtcStatusAvailabilityMask = dtcStatusMask;
\r
361 if (dtcStatusMask != 0x00) { /** @req DCM008 */
\r
362 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
363 while (getNextFilteredDtcResult == DEM_FILTERED_OK) {
\r
364 txData->dtcAndStatusRecord[nrOfDtcs].dtcHighByte = DTC_HIGH_BYTE(dtc);
\r
365 txData->dtcAndStatusRecord[nrOfDtcs].dtcMiddleByte = DTC_MID_BYTE(dtc);
\r
366 txData->dtcAndStatusRecord[nrOfDtcs].dtcLowByte = DTC_LOW_BYTE(dtc);
\r
367 txData->dtcAndStatusRecord[nrOfDtcs].statusOfDtc = dtcStatus;
\r
369 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
372 if (getNextFilteredDtcResult != DEM_FILTERED_NO_MATCHING_DTC) {
\r
373 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
376 pduTxData->SduLength = 3 + nrOfDtcs * sizeof(dtcAndStatusRecordType);
\r
379 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
382 return responseCode;
\r
386 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x08(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
388 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
390 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
391 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
393 return responseCode;
\r
397 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x09(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
399 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
401 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
402 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
404 return responseCode;
\r
408 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x06_0x10(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
410 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
411 Dem_DTCOriginType dtcOrigin = NULL;
\r
415 // Switch on sub function
\r
416 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
418 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
419 dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY;
\r
422 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
423 dtcOrigin = DEM_DTC_ORIGIN_MIRROR_MEMORY;
\r
427 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
431 // Switch on record number
\r
432 switch (pduRxData->SduDataPtr[5])
\r
434 case 0xFF: // Report all Extended Data Records for a particular DTC
\r
435 startRecNum = 0x00;
\r
439 case 0xFE: // Report all OBD Extended Data Records for a particular DTC
\r
440 startRecNum = 0x90;
\r
444 default: // Report one specific Extended Data Records for a particular DTC
\r
445 startRecNum = pduRxData->SduDataPtr[5];
\r
446 endRecNum = startRecNum;
\r
450 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
451 Dem_ReturnGetStatusOfDTCType getStatusOfDtcResult;
\r
453 Dem_EventStatusExtendedType statusOfDtc;
\r
455 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3], pduRxData->SduDataPtr[4]);
\r
456 getStatusOfDtcResult = Dem_GetStatusOfDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, &statusOfDtc); /** @req DCM295 */ /** @req DCM475 */
\r
457 if (getStatusOfDtcResult == DEM_STATUS_OK) {
\r
458 Dem_ReturnGetExtendedDataRecordByDTCType getExtendedDataRecordByDtcResult;
\r
461 uint16 txIndex = 6;
\r
463 /** @req DCM297 */ /** @req DCM474 */ /** @req DCM386 */
\r
464 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1]; // Sub function
\r
465 pduTxData->SduDataPtr[2] = DTC_HIGH_BYTE(dtc); // DTC high byte
\r
466 pduTxData->SduDataPtr[3] = DTC_MID_BYTE(dtc); // DTC mid byte
\r
467 pduTxData->SduDataPtr[4] = DTC_LOW_BYTE(dtc); // DTC low byte
\r
468 pduTxData->SduDataPtr[5] = statusOfDtc; // DTC status
\r
469 for (recNum = startRecNum; recNum <= endRecNum; recNum++) {
\r
470 recLength = pduTxData->SduLength - txIndex -1; // Calculate what's left in buffer
\r
471 /** @req DCM296 */ /** @req DCM476 */ /** @req DCM382 */
\r
472 getExtendedDataRecordByDtcResult = Dem_GetExtendedDataRecordByDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, recNum, &pduTxData->SduDataPtr[txIndex+1], &recLength);
\r
473 if (getExtendedDataRecordByDtcResult == DEM_RECORD_OK) {
\r
474 pduTxData->SduDataPtr[txIndex++] = recNum;
\r
475 /* Instead of calling Dem_GetSizeOfExtendedDataRecordByDTC() the result from Dem_GetExtendedDataRecordByDTC() is used */
\r
476 /** @req DCM478 */ /** @req DCM479 */ /** @req DCM480 */
\r
477 txIndex += recLength;
\r
480 // TODO: What to do here?
\r
483 pduTxData->SduLength = txIndex;
\r
486 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
490 return responseCode;
\r
494 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x03(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
496 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
498 // TODO: Not supported yet
\r
499 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
501 return responseCode;
\r
505 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x04(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
507 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
509 // TODO: Not supported yet
\r
510 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
512 return responseCode;
\r
516 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x05(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
518 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
520 // TODO: Not supported yet
\r
521 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
523 return responseCode;
\r
527 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
529 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
531 // TODO: Not supported yet
\r
532 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
534 return responseCode;
\r
538 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x14(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
540 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
542 // TODO: Not supported yet
\r
543 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
545 return responseCode;
\r
549 void DspUdsReadDtcInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
552 // 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
553 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
555 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
557 uint8 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
560 if (subFunctionNumber <= 0x15) {
\r
561 if (pduRxData->SduLength == sduLength[subFunctionNumber]) {
\r
562 switch (subFunctionNumber)
\r
564 case 0x01: // reportNumberOfDTCByStatusMask
\r
565 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
566 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
567 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
568 responseCode = udsReadDtcInfoSub_0x01_0x07_0x11_0x12(pduRxData, pduTxData);
\r
571 case 0x02: // reportDTCByStatusMask
\r
572 case 0x0A: // reportSupportedDTC
\r
573 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
574 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
575 case 0x15: // reportDTCWithPermanentStatus
\r
576 responseCode = udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(pduRxData, pduTxData);
\r
579 case 0x08: // reportDTCBySeverityMaskRecord
\r
580 responseCode = udsReadDtcInfoSub_0x08(pduRxData, pduTxData);
\r
583 case 0x09: // reportSeverityInformationOfDTC
\r
584 responseCode = udsReadDtcInfoSub_0x09(pduRxData, pduTxData);
\r
587 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
588 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
589 responseCode = udsReadDtcInfoSub_0x06_0x10(pduRxData, pduTxData);
\r
592 case 0x03: // reportDTCSnapshotIdentidication
\r
593 responseCode = udsReadDtcInfoSub_0x03(pduRxData, pduTxData);
\r
596 case 0x04: // reportDTCSnapshotByDtcNumber
\r
597 responseCode = udsReadDtcInfoSub_0x04(pduRxData, pduTxData);
\r
600 case 0x05: // reportDTCSnapshotRecordNumber
\r
601 responseCode = udsReadDtcInfoSub_0x05(pduRxData, pduTxData);
\r
604 case 0x0B: // reportFirstTestFailedDTC
\r
605 case 0x0C: // reportFirstConfirmedDTC
\r
606 case 0x0D: // reportMostRecentTestFailedDTC
\r
607 case 0x0E: // reportMostRecentConfirmedDTC
\r
608 responseCode = udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(pduRxData, pduTxData);
\r
611 case 0x14: // reportDTCFaultDetectionCounter
\r
612 responseCode = udsReadDtcInfoSub_0x14(pduRxData, pduTxData);
\r
616 // Unknown sub function
\r
617 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
623 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
627 // Sub function out of range
\r
628 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
631 DsdDspProcessingDone(responseCode);
\r
635 static boolean lookupDid(uint16 didNr, const Dcm_DspDidType **didPtr)
\r
637 const Dcm_DspDidType *dspDid = DCM_Config.Dsp->DspDid;
\r
638 boolean didFound = FALSE;
\r
640 while ((dspDid->DspDidIdentifier != didNr) && !dspDid->Arc_EOL) {
\r
644 if (!dspDid->Arc_EOL) {
\r
653 static Dcm_NegativeResponseCodeType readDidData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
655 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
657 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL) && (didPtr->DspDidConditionCheckReadFnc != NULL) && (didPtr->DspDidReadDataFnc != NULL)) { /** @req DCM433 */
\r
658 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef)) { /** @req DCM434 */
\r
659 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef)) { /** @req DCM435 */
\r
660 Std_ReturnType result;
\r
661 Dcm_NegativeResponseCodeType errorCode;
\r
662 result = didPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
663 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) { /** @req DCM439 */
\r
666 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM436 */
\r
667 didLen = didPtr->DspDidSize;
\r
671 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
672 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
676 if (result == E_OK) {
\r
677 // Now ready for reading the data!
\r
678 if ((*txPos + didLen + 2) <= pduTxData->SduLength) {
\r
679 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFF;
\r
681 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 0) & 0xFF;
\r
683 result = didPtr->DspDidReadDataFnc(&pduTxData->SduDataPtr[*txPos]); /** @req DCM437 */
\r
686 if (result != E_OK) {
\r
687 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
690 else { // tx buffer full
\r
691 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
694 else { // Not possible to obtain did length
\r
695 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
698 else { // CheckRead failed
\r
699 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
702 else { // Not allowed in current security level
\r
703 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
706 else { // Not allowed in current session
\r
707 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
710 else { // Read access not configured
\r
711 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
714 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
715 // Recurse trough the rest of the dids. /** @req DCM440 */
\r
717 for (i=0; (!didPtr->DspDidRef[i]->Arc_EOL) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
718 responseCode = readDidData(didPtr->DspDidRef[i], pduTxData, txPos);
\r
722 return responseCode;
\r
725 void DspUdsReadDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
728 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
731 const Dcm_DspDidType *didPtr = NULL;
\r
736 if ((pduRxData->SduLength - 1) % 2 == 0 ) {
\r
737 nrOfDids = (pduRxData->SduLength - 1) / 2;
\r
739 for (i = 0; (i < nrOfDids) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
740 didNr = (pduRxData->SduDataPtr[1+i*2] << 8) + pduRxData->SduDataPtr[2+i*2];
\r
741 if (lookupDid(didNr, &didPtr)) { /** @req DCM438 */
\r
742 responseCode = readDidData(didPtr, pduTxData, &txPos);
\r
744 else { // DID not found
\r
745 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
750 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
753 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
754 pduTxData->SduLength = txPos;
\r
757 DsdDspProcessingDone(responseCode);
\r
761 static Dcm_NegativeResponseCodeType readDidScalingData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
763 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
765 if (didPtr->DspDidGetScalingInfoFnc != NULL) {
\r
766 uint16 scalingInfoLen;
\r
768 scalingInfoLen = didPtr->DspDidInfoRef->DspDidScalingInfoSize;
\r
769 if ((*txPos + scalingInfoLen + 2) <= pduTxData->SduLength) {
\r
770 Std_ReturnType result;
\r
771 Dcm_NegativeResponseCodeType errorCode;
\r
773 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFF;
\r
775 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 0) & 0xFF;
\r
777 result = didPtr->DspDidGetScalingInfoFnc(&pduTxData->SduDataPtr[*txPos], &errorCode); /** @req DCM394 */
\r
778 *txPos += scalingInfoLen;
\r
780 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
781 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
784 else { // tx buffer full
\r
785 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
788 else { // DspDidGetScalingInfoFnc null pointer
\r
789 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
792 return responseCode;
\r
795 void DspUdsReadScalingDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
798 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
800 const Dcm_DspDidType *didPtr = NULL;
\r
804 if (pduRxData->SduLength == 3) {
\r
805 didNr = (pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
806 if (lookupDid(didNr, &didPtr)) {
\r
807 responseCode = readDidScalingData(didPtr, pduTxData, &txPos);
\r
809 else { // DID not found
\r
810 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
813 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
814 pduTxData->SduLength = txPos;
\r
819 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
822 DsdDspProcessingDone(responseCode);
\r
826 static Dcm_NegativeResponseCodeType writeDidData(const Dcm_DspDidType *didPtr, const PduInfoType *pduRxData, uint16 writeDidLen)
\r
828 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
830 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite != NULL) && (didPtr->DspDidConditionCheckWriteFnc != NULL) && (didPtr->DspDidWriteDataFnc != NULL)) { /** @req DCM468 */
\r
831 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSessionRef)) { /** @req DCM469 */
\r
832 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSecurityLevelRef)) { /** @req DCM470 */
\r
833 Std_ReturnType result;
\r
834 Dcm_NegativeResponseCodeType errorCode;
\r
835 result = didPtr->DspDidConditionCheckWriteFnc(&errorCode); /** @req DCM471 */
\r
836 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
839 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM472 */
\r
840 didLen = didPtr->DspDidSize;
\r
844 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
845 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
849 if (result == E_OK) {
\r
850 if (didLen == writeDidLen) { /** @req DCM473 */
\r
851 result = didPtr->DspDidWriteDataFnc(&pduRxData->SduDataPtr[3], didLen, &errorCode); /** @req DCM395 */
\r
852 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
853 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
857 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
860 else { // Not possible to obtain did length
\r
861 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
864 else { // CheckRead failed
\r
865 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
868 else { // Not allowed in current security level
\r
869 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
872 else { // Not allowed in current session
\r
873 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
876 else { // Read access not configured
\r
877 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
880 return responseCode;
\r
883 void DspUdsWriteDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
886 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
888 const Dcm_DspDidType *didPtr = NULL;
\r
890 uint16 didDataLength;
\r
892 didDataLength = pduRxData->SduLength - 3;
\r
893 didNr = (pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
894 if (lookupDid(didNr, &didPtr)) { /** @req DCM467 */
\r
895 responseCode = writeDidData(didPtr, pduRxData, didDataLength);
\r
897 else { // DID not found
\r
898 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
901 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
902 pduTxData->SduLength = 3;
\r
903 pduTxData->SduDataPtr[1] = (didNr >> 8) & 0xFF;
\r
904 pduTxData->SduDataPtr[2] = (didNr >> 0) & 0xFF;
\r
907 DsdDspProcessingDone(responseCode);
\r
911 void DspUdsSecurityAccess(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
914 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
916 // Check sub function range (0x01 to 0x42)
\r
917 if ((pduRxData->SduDataPtr[1] >= 0x01) && (pduRxData->SduDataPtr[1] <= 0x42)) {
\r
918 boolean isRequestSeed = pduRxData->SduDataPtr[1] & 0x01;
\r
919 Dcm_SecLevelType requestedSecurityLevel = (pduRxData->SduDataPtr[1]-1)/2;
\r
920 Dcm_NegativeResponseCodeType getSeedErrorCode;
\r
922 if (isRequestSeed) {
\r
923 // requestSeed message
\r
924 // Check if type exist in security table
\r
925 const Dcm_DspSecurityRowType *securityRow = &DCM_Config.Dsp->DspSecurity->DspSecurityRow[0];
\r
926 while ((securityRow->DspSecurityLevel != requestedSecurityLevel) && !securityRow->Arc_EOL) {
\r
929 if (!securityRow->Arc_EOL) {
\r
931 if (pduRxData->SduLength == (2 + securityRow->DspSecurityADRSize)) { /** @req DCM321.RequestSeed */
\r
932 Dcm_SecLevelType activeSecLevel;
\r
933 Dcm_GetSecurityLevel(&activeSecLevel);
\r
934 if (requestedSecurityLevel == activeSecLevel) { /** @req DCM323 */
\r
935 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
936 // If same level set the seed to zeroes
\r
937 memset(&pduTxData->SduDataPtr[2], 0, securityRow->DspSecuritySeedSize);
\r
938 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
941 // New security level ask for seed
\r
942 if (securityRow->GetSeed != NULL) {
\r
943 Std_ReturnType getSeedResult;
\r
944 getSeedResult = securityRow->GetSeed(&pduRxData->SduDataPtr[2], &pduTxData->SduDataPtr[2], &getSeedErrorCode); /** @req DCM324.RequestSeed */
\r
945 if ((getSeedResult == E_OK) && (getSeedErrorCode == E_OK)) {
\r
946 // Everything ok add sub function to tx message and send it.
\r
947 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
948 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
950 dspUdsSecurityAccesData.reqSecLevel = requestedSecurityLevel;
\r
951 dspUdsSecurityAccesData.reqSecLevelRef = securityRow;
\r
952 dspUdsSecurityAccesData.reqInProgress = TRUE;
\r
955 // GetSeed returned not ok
\r
956 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
959 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
965 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
969 // Requested security level not configured
\r
970 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
975 if (dspUdsSecurityAccesData.reqInProgress) {
\r
976 if (pduRxData->SduLength == (2 + dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityKeySize)) { /** @req DCM321.SendKey */
\r
977 if (requestedSecurityLevel == dspUdsSecurityAccesData.reqSecLevel) {
\r
978 if (dspUdsSecurityAccesData.reqSecLevelRef->CompareKey != NULL) {
\r
979 Std_ReturnType compareKeyResult;
\r
980 compareKeyResult = dspUdsSecurityAccesData.reqSecLevelRef->CompareKey(&pduRxData->SduDataPtr[2]); /** @req DCM324.SendKey */
\r
981 if (compareKeyResult == E_OK) {
\r
982 // Request accepted
\r
984 DslSetSecurityLevel(dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityLevel); /** @req DCM325 */
\r
985 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
986 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
987 pduTxData->SduLength = 2;
\r
990 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
993 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
997 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1002 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1006 // sendKey request without a preceding requestSeed
\r
1007 responseCode = DCM_E_REQUESTSEQUENCEERROR;
\r
1012 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1015 DsdDspProcessingDone(responseCode);
\r
1019 void DspUdsTesterPresent(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1021 /** @req DCM251 */
\r
1022 if (pduRxData->SduLength == 2) {
\r
1023 switch (pduRxData->SduDataPtr[1])
\r
1025 case ZERO_SUB_FUNCTION:
\r
1026 DslResetSessionTimeoutTimer();
\r
1027 // Create positive response
\r
1028 pduTxData->SduDataPtr[1] = ZERO_SUB_FUNCTION;
\r
1029 pduTxData->SduLength = 2;
\r
1030 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1034 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1040 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1045 void DspUdsControlDtcSetting(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1047 /** @req DCM249 */
\r
1048 Dem_ReturnControlDTCStorageType resultCode;
\r
1050 if (pduRxData->SduLength == 2) {
\r
1051 switch (pduRxData->SduDataPtr[1])
\r
1054 resultCode = Dem_EnableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM304 */
\r
1055 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1056 pduTxData->SduDataPtr[1] = 0x01;
\r
1057 pduTxData->SduLength = 2;
\r
1058 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1061 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1066 resultCode = Dem_DisableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM406 */
\r
1067 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1068 pduTxData->SduDataPtr[1] = 0x02;
\r
1069 pduTxData->SduLength = 2;
\r
1070 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1073 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1078 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1084 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1089 void DspDcmConfirmation(PduIdType confirmPduId)
\r
1091 if (dspUdsEcuResetData.resetPending) {
\r
1092 if (confirmPduId == dspUdsEcuResetData.resetPduId) {
\r
1093 dspUdsEcuResetData.resetPending = FALSE;
\r
1094 #if ( MCU_PERFORM_RESET_API == STD_ON )
\r
1095 Mcu_PerformReset();
\r
1097 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_UDS_RESET_ID, DCM_E_NOT_SUPPORTED);
\r