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
31 #if defined(USE_MCU)
\r
35 #define ZERO_SUB_FUNCTION 0x00
\r
40 #define BYTES_TO_DTC(hb, mb, lb) (((uint32)(hb) << 16) | ((uint32)(mb) << 8) | (uint32)(lb))
\r
41 #define DTC_HIGH_BYTE(dtc) (((uint32)(dtc) >> 16) & 0xFF)
\r
42 #define DTC_MID_BYTE(dtc) (((uint32)(dtc) >> 8) & 0xFF)
\r
43 #define DTC_LOW_BYTE(dtc) ((uint32)(dtc) & 0xFF)
\r
47 boolean resetPending;
\r
48 PduIdType resetPduId;
\r
49 } DspUdsEcuResetDataType;
\r
51 static DspUdsEcuResetDataType dspUdsEcuResetData;
\r
55 boolean reqInProgress;
\r
56 Dcm_SecLevelType reqSecLevel;
\r
57 const Dcm_DspSecurityRowType *reqSecLevelRef;
\r
58 } DspUdsSecurityAccessDataType;
\r
60 static DspUdsSecurityAccessDataType dspUdsSecurityAccesData;
\r
65 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
66 dspUdsEcuResetData.resetPending = FALSE;
\r
76 boolean DspCheckSessionLevel(const Dcm_DspSessionRowType **sessionLevelRefTable)
\r
78 boolean returnStatus = TRUE;
\r
79 Dcm_SesCtrlType currentSession;
\r
81 DslGetSesCtrlType(¤tSession);
\r
82 while (((*sessionLevelRefTable)->DspSessionLevel != currentSession) && !(*sessionLevelRefTable)->Arc_EOL) {
\r
83 sessionLevelRefTable++;
\r
86 if ((*sessionLevelRefTable)->Arc_EOL) {
\r
87 returnStatus = FALSE;
\r
90 return returnStatus;
\r
94 boolean DspCheckSecurityLevel(const Dcm_DspSecurityRowType **securityLevelRefTable)
\r
96 boolean returnStatus = TRUE;
\r
97 Dcm_SecLevelType currentSecurityLevel;
\r
99 DslGetSecurityLevel(¤tSecurityLevel);
\r
100 while (((*securityLevelRefTable)->DspSecurityLevel != currentSecurityLevel) && !(*securityLevelRefTable)->Arc_EOL) {
\r
101 securityLevelRefTable++;
\r
103 if ((*securityLevelRefTable)->Arc_EOL) {
\r
104 returnStatus = FALSE;
\r
107 return returnStatus;
\r
111 static Std_ReturnType askApplicationForSessionPermission(Dcm_SesCtrlType newSessionLevel)
\r
113 Std_ReturnType returnCode = E_OK;
\r
114 const Dcm_DslSessionControlType *sesControl = DCM_Config.Dsl->DslSessionControl;
\r
115 Dcm_SesCtrlType currentSessionLevel;
\r
116 Std_ReturnType result;
\r
118 while (!sesControl->Arc_EOL && (returnCode != E_SESSION_NOT_ALLOWED)) {
\r
119 if (sesControl->GetSesChgPermission != NULL) {
\r
120 Dcm_GetSesCtrlType(¤tSessionLevel);
\r
121 result = sesControl->GetSesChgPermission(currentSessionLevel ,newSessionLevel);
\r
122 if (result != E_OK) {
\r
123 returnCode = result;
\r
133 void DspUdsDiagnosticSessionControl(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
136 const Dcm_DspSessionRowType *sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow;
\r
137 Dcm_SesCtrlType reqSessionType;
\r
138 Std_ReturnType result;
\r
140 if (pduRxData->SduLength == 2) {
\r
141 reqSessionType = pduRxData->SduDataPtr[1];
\r
142 // Check if type exist in session table
\r
143 while ((sessionRow->DspSessionLevel != reqSessionType) && !sessionRow->Arc_EOL) {
\r
147 if (!sessionRow->Arc_EOL) {
\r
148 result = askApplicationForSessionPermission(reqSessionType);
\r
149 if (result == E_OK) {
\r
150 DslSetSesCtrlType(reqSessionType); /** @req DCM311 */
\r
151 // Create positive response
\r
152 pduTxData->SduDataPtr[1] = reqSessionType;
\r
153 pduTxData->SduLength = 2;
\r
154 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
157 // TODO: Add handling of special case of E_FORCE_RCRRP (Dcm138)
\r
158 DsdDspProcessingDone(DCM_E_CONDITIONSNOTCORRECT); /** @req DCM308 */
\r
162 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED); /** @req DCM307 */
\r
167 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
172 void DspUdsEcuReset(const PduInfoType *pduRxData, PduIdType txPduId, PduInfoType *pduTxData)
\r
175 uint8 reqResetType;
\r
177 if (pduRxData->SduLength == 2) {
\r
178 reqResetType = pduRxData->SduDataPtr[1];
\r
180 switch (reqResetType)
\r
182 case 0x01: // Hard reset
\r
183 // TODO: Ask application for permission (Dcm373) (Dcm375) (Dcm377)
\r
185 // Schedule the reset
\r
186 dspUdsEcuResetData.resetPending = TRUE;
\r
187 dspUdsEcuResetData.resetPduId = txPduId;
\r
189 // Create positive response
\r
190 pduTxData->SduDataPtr[1] = reqResetType;
\r
191 pduTxData->SduLength = 2;
\r
192 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
196 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
202 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
207 void DspUdsClearDiagnosticInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
211 Dem_ReturnClearDTCType result;
\r
213 if (pduRxData->SduLength == 4) {
\r
214 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[1], pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3]);
\r
216 result = Dem_ClearDTC(dtc, DEM_DTC_KIND_ALL_DTCS, DEM_DTC_ORIGIN_PRIMARY_MEMORY); /** @req DCM005 */
\r
221 // Create positive response
\r
222 pduTxData->SduLength = 1;
\r
223 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
227 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
233 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
238 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x01_0x07_0x11_0x12(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
243 uint8 dtcStatusAvailabilityMask;
\r
244 uint8 dtcFormatIdentifier;
\r
245 uint8 dtcCountHighByte;
\r
246 uint8 dtcCountLowByte;
\r
249 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
250 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
252 // Setup the DTC filter
\r
253 switch (pduRxData->SduDataPtr[1]) /** @req DCM293 */
\r
255 case 0x01: // reportNumberOfDTCByStatusMask
\r
256 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
259 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
260 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
263 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
264 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
267 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
268 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
272 setDtcFilterResult = DEM_WRONG_FILTER;
\r
276 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
277 uint16 numberOfFilteredDtc;
\r
278 uint8 dtcStatusMask;
\r
279 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
282 Dem_GetNumberOfFilteredDtc(&numberOfFilteredDtc);
\r
283 Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
285 // Create positive response (ISO 14229-1 table 251)
\r
286 txData->reportType = pduRxData->SduDataPtr[1]; // reportType
\r
287 txData->dtcStatusAvailabilityMask = dtcStatusMask; // DTCStatusAvailabilityMask
\r
288 txData->dtcFormatIdentifier = Dem_GetTranslationType(); // DTCFormatIdentifier
\r
289 txData->dtcCountHighByte = (numberOfFilteredDtc >> 8); // DTCCount high byte
\r
290 txData->dtcCountLowByte = (numberOfFilteredDtc & 0xFF); // DTCCount low byte
\r
291 pduTxData->SduLength = 6;
\r
294 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
297 return responseCode;
\r
301 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
303 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
304 Dem_ReturnSetDTCFilterType setDtcFilterResult;
\r
308 uint8 dtcMiddleByte;
\r
311 } dtcAndStatusRecordType;
\r
316 uint8 dtcStatusAvailabilityMask;
\r
317 dtcAndStatusRecordType dtcAndStatusRecord[];
\r
320 // Setup the DTC filter
\r
321 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
323 case 0x02: // reportDTCByStatusMask
\r
324 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
327 case 0x0A: // reportSupportedDTC
\r
328 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
331 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
332 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
335 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
336 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
339 case 0x15: // reportDTCWithPermanentStatus
\r
340 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
344 setDtcFilterResult = DEM_WRONG_FILTER;
\r
348 if (setDtcFilterResult == DEM_FILTER_ACCEPTED) {
\r
349 uint8 dtcStatusMask;
\r
350 TxDataType *txData = (TxDataType*)pduTxData->SduDataPtr;
\r
351 Dem_ReturnGetNextFilteredDTCType getNextFilteredDtcResult;
\r
353 Dem_EventStatusExtendedType dtcStatus;
\r
354 uint16 nrOfDtcs = 0;
\r
357 Dem_GetDTCStatusAvailabilityMask(&dtcStatusMask);
\r
359 // Create positive response (ISO 14229-1 table 252)
\r
360 txData->reportType = pduRxData->SduDataPtr[1];
\r
361 txData->dtcStatusAvailabilityMask = dtcStatusMask;
\r
363 if (dtcStatusMask != 0x00) { /** @req DCM008 */
\r
364 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
365 while (getNextFilteredDtcResult == DEM_FILTERED_OK) {
\r
366 txData->dtcAndStatusRecord[nrOfDtcs].dtcHighByte = DTC_HIGH_BYTE(dtc);
\r
367 txData->dtcAndStatusRecord[nrOfDtcs].dtcMiddleByte = DTC_MID_BYTE(dtc);
\r
368 txData->dtcAndStatusRecord[nrOfDtcs].dtcLowByte = DTC_LOW_BYTE(dtc);
\r
369 txData->dtcAndStatusRecord[nrOfDtcs].statusOfDtc = dtcStatus;
\r
371 getNextFilteredDtcResult = Dem_GetNextFilteredDTC(&dtc, &dtcStatus);
\r
374 if (getNextFilteredDtcResult != DEM_FILTERED_NO_MATCHING_DTC) {
\r
375 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
378 pduTxData->SduLength = 3 + nrOfDtcs * sizeof(dtcAndStatusRecordType);
\r
381 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
384 return responseCode;
\r
388 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x08(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
390 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
392 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
393 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
395 return responseCode;
\r
399 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x09(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
401 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
403 // TODO: Not supported yet, (DEM module does not currently support severity).
\r
404 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
406 return responseCode;
\r
410 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x06_0x10(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
412 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
413 Dem_DTCOriginType dtcOrigin;
\r
417 // Switch on sub function
\r
418 switch (pduRxData->SduDataPtr[1]) /** @req DCM378 */
\r
420 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
421 dtcOrigin = DEM_DTC_ORIGIN_PRIMARY_MEMORY;
\r
424 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
425 dtcOrigin = DEM_DTC_ORIGIN_MIRROR_MEMORY;
\r
429 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
434 // Switch on record number
\r
435 switch (pduRxData->SduDataPtr[5])
\r
437 case 0xFF: // Report all Extended Data Records for a particular DTC
\r
438 startRecNum = 0x00;
\r
442 case 0xFE: // Report all OBD Extended Data Records for a particular DTC
\r
443 startRecNum = 0x90;
\r
447 default: // Report one specific Extended Data Records for a particular DTC
\r
448 startRecNum = pduRxData->SduDataPtr[5];
\r
449 endRecNum = startRecNum;
\r
453 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
454 Dem_ReturnGetStatusOfDTCType getStatusOfDtcResult;
\r
456 Dem_EventStatusExtendedType statusOfDtc;
\r
458 dtc = BYTES_TO_DTC(pduRxData->SduDataPtr[2], pduRxData->SduDataPtr[3], pduRxData->SduDataPtr[4]);
\r
459 getStatusOfDtcResult = Dem_GetStatusOfDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, &statusOfDtc); /** @req DCM295 */ /** @req DCM475 */
\r
460 if (getStatusOfDtcResult == DEM_STATUS_OK) {
\r
461 Dem_ReturnGetExtendedDataRecordByDTCType getExtendedDataRecordByDtcResult;
\r
464 uint16 txIndex = 6;
\r
466 /** @req DCM297 */ /** @req DCM474 */ /** @req DCM386 */
\r
467 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1]; // Sub function
\r
468 pduTxData->SduDataPtr[2] = DTC_HIGH_BYTE(dtc); // DTC high byte
\r
469 pduTxData->SduDataPtr[3] = DTC_MID_BYTE(dtc); // DTC mid byte
\r
470 pduTxData->SduDataPtr[4] = DTC_LOW_BYTE(dtc); // DTC low byte
\r
471 pduTxData->SduDataPtr[5] = statusOfDtc; // DTC status
\r
472 for (recNum = startRecNum; recNum <= endRecNum; recNum++) {
\r
473 recLength = pduTxData->SduLength - txIndex -1; // Calculate what's left in buffer
\r
474 /** @req DCM296 */ /** @req DCM476 */ /** @req DCM382 */
\r
475 getExtendedDataRecordByDtcResult = Dem_GetExtendedDataRecordByDTC(dtc, DEM_DTC_KIND_ALL_DTCS, dtcOrigin, recNum, &pduTxData->SduDataPtr[txIndex+1], &recLength);
\r
476 if (getExtendedDataRecordByDtcResult == DEM_RECORD_OK) {
\r
477 pduTxData->SduDataPtr[txIndex++] = recNum;
\r
478 /* Instead of calling Dem_GetSizeOfExtendedDataRecordByDTC() the result from Dem_GetExtendedDataRecordByDTC() is used */
\r
479 /** @req DCM478 */ /** @req DCM479 */ /** @req DCM480 */
\r
480 txIndex += recLength;
\r
483 // TODO: What to do here?
\r
486 pduTxData->SduLength = txIndex;
\r
489 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
493 return responseCode;
\r
497 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x03(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
499 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
501 // TODO: Not supported yet
\r
502 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
504 return responseCode;
\r
508 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x04(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
510 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
512 // TODO: Not supported yet
\r
513 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
515 return responseCode;
\r
519 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x05(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
521 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
523 // TODO: Not supported yet
\r
524 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
526 return responseCode;
\r
530 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
532 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
534 // TODO: Not supported yet
\r
535 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
537 return responseCode;
\r
541 static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x14(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
543 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
545 // TODO: Not supported yet
\r
546 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
548 return responseCode;
\r
552 void DspUdsReadDtcInformation(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
555 // 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
556 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
558 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
560 uint8 subFunctionNumber = pduRxData->SduDataPtr[1];
\r
563 if (subFunctionNumber <= 0x15) {
\r
564 if (pduRxData->SduLength == sduLength[subFunctionNumber]) {
\r
565 switch (subFunctionNumber)
\r
567 case 0x01: // reportNumberOfDTCByStatusMask
\r
568 case 0x07: // reportNumberOfDTCBySeverityMaskRecord
\r
569 case 0x11: // reportNumberOfMirrorMemoryDTCByStatusMask
\r
570 case 0x12: // reportNumberOfEmissionRelatedOBDDTCByStatusMask
\r
571 responseCode = udsReadDtcInfoSub_0x01_0x07_0x11_0x12(pduRxData, pduTxData);
\r
574 case 0x02: // reportDTCByStatusMask
\r
575 case 0x0A: // reportSupportedDTC
\r
576 case 0x0F: // reportMirrorMemoryDTCByStatusMask
\r
577 case 0x13: // reportEmissionRelatedOBDDTCByStatusMask
\r
578 case 0x15: // reportDTCWithPermanentStatus
\r
579 responseCode = udsReadDtcInfoSub_0x02_0x0A_0x0F_0x13_0x15(pduRxData, pduTxData);
\r
582 case 0x08: // reportDTCBySeverityMaskRecord
\r
583 responseCode = udsReadDtcInfoSub_0x08(pduRxData, pduTxData);
\r
586 case 0x09: // reportSeverityInformationOfDTC
\r
587 responseCode = udsReadDtcInfoSub_0x09(pduRxData, pduTxData);
\r
590 case 0x06: // reportDTCExtendedDataRecordByDTCNumber
\r
591 case 0x10: // reportMirrorMemoryDTCExtendedDataRecordByDTCNumber
\r
592 responseCode = udsReadDtcInfoSub_0x06_0x10(pduRxData, pduTxData);
\r
595 case 0x03: // reportDTCSnapshotIdentidication
\r
596 responseCode = udsReadDtcInfoSub_0x03(pduRxData, pduTxData);
\r
599 case 0x04: // reportDTCSnapshotByDtcNumber
\r
600 responseCode = udsReadDtcInfoSub_0x04(pduRxData, pduTxData);
\r
603 case 0x05: // reportDTCSnapshotRecordNumber
\r
604 responseCode = udsReadDtcInfoSub_0x05(pduRxData, pduTxData);
\r
607 case 0x0B: // reportFirstTestFailedDTC
\r
608 case 0x0C: // reportFirstConfirmedDTC
\r
609 case 0x0D: // reportMostRecentTestFailedDTC
\r
610 case 0x0E: // reportMostRecentConfirmedDTC
\r
611 responseCode = udsReadDtcInfoSub_0x0B_0x0C_0x0D_0x0E(pduRxData, pduTxData);
\r
614 case 0x14: // reportDTCFaultDetectionCounter
\r
615 responseCode = udsReadDtcInfoSub_0x14(pduRxData, pduTxData);
\r
619 // Unknown sub function
\r
620 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
626 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
630 // Sub function out of range
\r
631 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
634 DsdDspProcessingDone(responseCode);
\r
638 static boolean lookupDid(uint16 didNr, const Dcm_DspDidType **didPtr)
\r
640 const Dcm_DspDidType *dspDid = DCM_Config.Dsp->DspDid;
\r
641 boolean didFound = FALSE;
\r
643 while ((dspDid->DspDidIdentifier != didNr) && !dspDid->Arc_EOL) {
\r
647 if (!dspDid->Arc_EOL) {
\r
656 static Dcm_NegativeResponseCodeType readDidData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
658 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
660 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidRead != NULL) && (didPtr->DspDidConditionCheckReadFnc != NULL) && (didPtr->DspDidReadDataFnc != NULL)) { /** @req DCM433 */
\r
661 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSessionRef)) { /** @req DCM434 */
\r
662 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidRead->DspDidReadSecurityLevelRef)) { /** @req DCM435 */
\r
663 Std_ReturnType result;
\r
664 Dcm_NegativeResponseCodeType errorCode;
\r
665 result = didPtr->DspDidConditionCheckReadFnc(&errorCode);
\r
666 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) { /** @req DCM439 */
\r
669 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM436 */
\r
670 didLen = didPtr->DspDidSize;
\r
674 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
675 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
679 if (result == E_OK) {
\r
680 // Now ready for reading the data!
\r
681 if ((*txPos + didLen + 2) <= pduTxData->SduLength) {
\r
682 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFF;
\r
684 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 0) & 0xFF;
\r
686 result = didPtr->DspDidReadDataFnc(&pduTxData->SduDataPtr[*txPos]); /** @req DCM437 */
\r
689 if (result != E_OK) {
\r
690 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
693 else { // tx buffer full
\r
694 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
697 else { // Not possible to obtain did length
\r
698 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
701 else { // CheckRead failed
\r
702 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
705 else { // Not allowed in current security level
\r
706 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
709 else { // Not allowed in current session
\r
710 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
713 else { // Read access not configured
\r
714 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
717 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
718 // Recurse trough the rest of the dids. /** @req DCM440 */
\r
720 for (i=0; (!didPtr->DspDidRef[i]->Arc_EOL) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
721 responseCode = readDidData(didPtr->DspDidRef[i], pduTxData, txPos);
\r
725 return responseCode;
\r
728 void DspUdsReadDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
731 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
734 const Dcm_DspDidType *didPtr = NULL;
\r
739 if ((pduRxData->SduLength - 1) % 2 == 0 ) {
\r
740 nrOfDids = (pduRxData->SduLength - 1) / 2;
\r
742 for (i = 0; (i < nrOfDids) && (responseCode == DCM_E_POSITIVERESPONSE); i++) {
\r
743 didNr = (pduRxData->SduDataPtr[1+i*2] << 8) + pduRxData->SduDataPtr[2+i*2];
\r
744 if (lookupDid(didNr, &didPtr)) { /** @req DCM438 */
\r
745 responseCode = readDidData(didPtr, pduTxData, &txPos);
\r
747 else { // DID not found
\r
748 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
753 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
756 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
757 pduTxData->SduLength = txPos;
\r
760 DsdDspProcessingDone(responseCode);
\r
764 static Dcm_NegativeResponseCodeType readDidScalingData(const Dcm_DspDidType *didPtr, PduInfoType *pduTxData, uint16 *txPos)
\r
766 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
768 if (didPtr->DspDidGetScalingInfoFnc != NULL) {
\r
769 uint16 scalingInfoLen;
\r
771 scalingInfoLen = didPtr->DspDidInfoRef->DspDidScalingInfoSize;
\r
772 if ((*txPos + scalingInfoLen + 2) <= pduTxData->SduLength) {
\r
773 Std_ReturnType result;
\r
774 Dcm_NegativeResponseCodeType errorCode;
\r
776 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 8) & 0xFF;
\r
778 pduTxData->SduDataPtr[*txPos] = (didPtr->DspDidIdentifier >> 0) & 0xFF;
\r
780 result = didPtr->DspDidGetScalingInfoFnc(&pduTxData->SduDataPtr[*txPos], &errorCode); /** @req DCM394 */
\r
781 *txPos += scalingInfoLen;
\r
783 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
784 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
787 else { // tx buffer full
\r
788 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
791 else { // DspDidGetScalingInfoFnc null pointer
\r
792 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
795 return responseCode;
\r
798 void DspUdsReadScalingDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
801 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
803 const Dcm_DspDidType *didPtr = NULL;
\r
807 if (pduRxData->SduLength == 3) {
\r
808 didNr = (pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
809 if (lookupDid(didNr, &didPtr)) {
\r
810 responseCode = readDidScalingData(didPtr, pduTxData, &txPos);
\r
812 else { // DID not found
\r
813 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
816 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
817 pduTxData->SduLength = txPos;
\r
822 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
825 DsdDspProcessingDone(responseCode);
\r
829 static Dcm_NegativeResponseCodeType writeDidData(const Dcm_DspDidType *didPtr, const PduInfoType *pduRxData, uint16 writeDidLen)
\r
831 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
833 if ((didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite != NULL) && (didPtr->DspDidConditionCheckWriteFnc != NULL) && (didPtr->DspDidWriteDataFnc != NULL)) { /** @req DCM468 */
\r
834 if (DspCheckSessionLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSessionRef)) { /** @req DCM469 */
\r
835 if (DspCheckSecurityLevel(didPtr->DspDidInfoRef->DspDidAccess.DspDidWrite->DspDidWriteSecurityLevelRef)) { /** @req DCM470 */
\r
836 Std_ReturnType result;
\r
837 Dcm_NegativeResponseCodeType errorCode;
\r
838 result = didPtr->DspDidConditionCheckWriteFnc(&errorCode); /** @req DCM471 */
\r
839 if ((result == E_OK) && (errorCode == DCM_E_POSITIVERESPONSE)) {
\r
842 if (didPtr->DspDidInfoRef->DspDidFixedLength) { /** @req DCM472 */
\r
843 didLen = didPtr->DspDidSize;
\r
847 if (didPtr->DspDidReadDataLengthFnc != NULL) {
\r
848 result = didPtr->DspDidReadDataLengthFnc(&didLen);
\r
852 if (result == E_OK) {
\r
853 if (didLen == writeDidLen) { /** @req DCM473 */
\r
854 result = didPtr->DspDidWriteDataFnc(&pduRxData->SduDataPtr[3], didLen, &errorCode); /** @req DCM395 */
\r
855 if ((result != E_OK) || (errorCode != DCM_E_POSITIVERESPONSE)) {
\r
856 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
860 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
863 else { // Not possible to obtain did length
\r
864 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
867 else { // CheckRead failed
\r
868 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
871 else { // Not allowed in current security level
\r
872 responseCode = DCM_E_SECUTITYACCESSDENIED;
\r
875 else { // Not allowed in current session
\r
876 responseCode = DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION;
\r
879 else { // Read access not configured
\r
880 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
883 return responseCode;
\r
886 void DspUdsWriteDataByIdentifier(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
889 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
891 const Dcm_DspDidType *didPtr = NULL;
\r
893 uint16 didDataLength;
\r
895 didDataLength = pduRxData->SduLength - 3;
\r
896 didNr = (pduRxData->SduDataPtr[1] << 8) + pduRxData->SduDataPtr[2];
\r
897 if (lookupDid(didNr, &didPtr)) { /** @req DCM467 */
\r
898 responseCode = writeDidData(didPtr, pduRxData, didDataLength);
\r
900 else { // DID not found
\r
901 responseCode = DCM_E_REQUESTOUTOFRANGE;
\r
904 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
905 pduTxData->SduLength = 3;
\r
906 pduTxData->SduDataPtr[1] = (didNr >> 8) & 0xFF;
\r
907 pduTxData->SduDataPtr[2] = (didNr >> 0) & 0xFF;
\r
910 DsdDspProcessingDone(responseCode);
\r
914 void DspUdsSecurityAccess(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
917 Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE;
\r
919 // Check sub function range (0x01 to 0x42)
\r
920 if ((pduRxData->SduDataPtr[1] >= 0x01) && (pduRxData->SduDataPtr[1] <= 0x42)) {
\r
921 boolean isRequestSeed = pduRxData->SduDataPtr[1] & 0x01;
\r
922 Dcm_SecLevelType requestedSecurityLevel = (pduRxData->SduDataPtr[1]-1)/2;
\r
923 Dcm_NegativeResponseCodeType getSeedErrorCode;
\r
925 if (isRequestSeed) {
\r
926 // requestSeed message
\r
927 // Check if type exist in security table
\r
928 const Dcm_DspSecurityRowType *securityRow = &DCM_Config.Dsp->DspSecurity->DspSecurityRow[0];
\r
929 while ((securityRow->DspSecurityLevel != requestedSecurityLevel) && !securityRow->Arc_EOL) {
\r
932 if (!securityRow->Arc_EOL) {
\r
934 if (pduRxData->SduLength == (2 + securityRow->DspSecurityADRSize)) { /** @req DCM321.RequestSeed */
\r
935 Dcm_SecLevelType activeSecLevel;
\r
936 Dcm_GetSecurityLevel(&activeSecLevel);
\r
937 if (requestedSecurityLevel == activeSecLevel) { /** @req DCM323 */
\r
938 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
939 // If same level set the seed to zeroes
\r
940 memset(&pduTxData->SduDataPtr[2], 0, securityRow->DspSecuritySeedSize);
\r
941 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
944 // New security level ask for seed
\r
945 if (securityRow->GetSeed != NULL) {
\r
946 Std_ReturnType getSeedResult;
\r
947 getSeedResult = securityRow->GetSeed(&pduRxData->SduDataPtr[2], &pduTxData->SduDataPtr[2], &getSeedErrorCode); /** @req DCM324.RequestSeed */
\r
948 if ((getSeedResult == E_OK) && (getSeedErrorCode == E_OK)) {
\r
949 // Everything ok add sub function to tx message and send it.
\r
950 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
951 pduTxData->SduLength = 2 + securityRow->DspSecuritySeedSize;
\r
953 dspUdsSecurityAccesData.reqSecLevel = requestedSecurityLevel;
\r
954 dspUdsSecurityAccesData.reqSecLevelRef = securityRow;
\r
955 dspUdsSecurityAccesData.reqInProgress = TRUE;
\r
958 // GetSeed returned not ok
\r
959 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
962 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
968 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
972 // Requested security level not configured
\r
973 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
978 if (dspUdsSecurityAccesData.reqInProgress) {
\r
979 if (pduRxData->SduLength == (2 + dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityKeySize)) { /** @req DCM321.SendKey */
\r
980 if (requestedSecurityLevel == dspUdsSecurityAccesData.reqSecLevel) {
\r
981 if (dspUdsSecurityAccesData.reqSecLevelRef->CompareKey != NULL) {
\r
982 Std_ReturnType compareKeyResult;
\r
983 compareKeyResult = dspUdsSecurityAccesData.reqSecLevelRef->CompareKey(&pduRxData->SduDataPtr[2]); /** @req DCM324.SendKey */
\r
984 if (compareKeyResult == E_OK) {
\r
985 // Request accepted
\r
987 DslSetSecurityLevel(dspUdsSecurityAccesData.reqSecLevelRef->DspSecurityLevel); /** @req DCM325 */
\r
988 dspUdsSecurityAccesData.reqInProgress = FALSE;
\r
989 pduTxData->SduDataPtr[1] = pduRxData->SduDataPtr[1];
\r
990 pduTxData->SduLength = 2;
\r
993 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
996 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1000 responseCode = DCM_E_CONDITIONSNOTCORRECT;
\r
1005 responseCode = DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT;
\r
1009 // sendKey request without a preceding requestSeed
\r
1010 responseCode = DCM_E_REQUESTSEQUENCEERROR;
\r
1015 responseCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
\r
1018 DsdDspProcessingDone(responseCode);
\r
1022 void DspUdsTesterPresent(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1024 /** @req DCM251 */
\r
1025 if (pduRxData->SduLength == 2) {
\r
1026 switch (pduRxData->SduDataPtr[1])
\r
1028 case ZERO_SUB_FUNCTION:
\r
1029 DslResetSessionTimeoutTimer();
\r
1030 // Create positive response
\r
1031 pduTxData->SduDataPtr[1] = ZERO_SUB_FUNCTION;
\r
1032 pduTxData->SduLength = 2;
\r
1033 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1037 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1043 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1048 void DspUdsControlDtcSetting(const PduInfoType *pduRxData, PduInfoType *pduTxData)
\r
1050 /** @req DCM249 */
\r
1051 Dem_ReturnControlDTCStorageType resultCode;
\r
1053 if (pduRxData->SduLength == 2) {
\r
1054 switch (pduRxData->SduDataPtr[1])
\r
1057 resultCode = Dem_EnableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM304 */
\r
1058 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1059 pduTxData->SduDataPtr[1] = 0x01;
\r
1060 pduTxData->SduLength = 2;
\r
1061 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1064 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1069 resultCode = Dem_DisableDTCStorage(DEM_DTC_GROUP_ALL_DTCS, DEM_DTC_KIND_ALL_DTCS); /** @req DCM406 */
\r
1070 if (resultCode == DEM_CONTROL_DTC_STORAGE_OK) {
\r
1071 pduTxData->SduDataPtr[1] = 0x02;
\r
1072 pduTxData->SduLength = 2;
\r
1073 DsdDspProcessingDone(DCM_E_POSITIVERESPONSE);
\r
1076 DsdDspProcessingDone(DCM_E_REQUESTOUTOFRANGE);
\r
1081 DsdDspProcessingDone(DCM_E_SUBFUNCTIONNOTSUPPORTED);
\r
1087 DsdDspProcessingDone(DCM_E_INCORRECTMESSAGELENGTHORINVALIDFORMAT);
\r
1092 void DspDcmConfirmation(PduIdType confirmPduId)
\r
1094 if (dspUdsEcuResetData.resetPending) {
\r
1095 if (confirmPduId == dspUdsEcuResetData.resetPduId) {
\r
1096 dspUdsEcuResetData.resetPending = FALSE;
\r
1097 #if defined(USE_MCU) && ( MCU_PERFORM_RESET_API == STD_ON )
\r
1098 Mcu_PerformReset();
\r
1100 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_UDS_RESET_ID, DCM_E_NOT_SUPPORTED);
\r