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 DCM600 */ // Generated by BSW builder
\r
26 #include "Dcm_Internal.h"
\r
30 const PduInfoType *pduRxData;
\r
31 PduInfoType *pduTxData;
\r
32 const Dcm_DsdServiceTableType *serviceTable;
\r
33 Dcm_ProtocolAddrTypeType addrType;
\r
38 // In "queue" to DSD
\r
39 static boolean dsdDslDataIndication = FALSE;
\r
40 static MsgDataType msgData;
\r
42 static uint8 currentSid;
\r
43 static boolean suppressPosRspMsg;
\r
50 static Std_ReturnType askApplicationForServicePermission(uint8 *requestData, uint16 dataSize)
\r
52 Std_ReturnType returnCode = E_OK;
\r
53 const Dcm_DslServiceRequestIndicationType *serviceRequestIndication = DCM_Config.Dsl->DslServiceRequestIndication;
\r
54 Std_ReturnType result;
\r
56 while ((!serviceRequestIndication->Arc_EOL) && (returnCode != E_REQUEST_NOT_ACCEPTED)) {
\r
57 if (serviceRequestIndication->Indication != NULL) {
\r
58 result = serviceRequestIndication->Indication(requestData, dataSize);
\r
59 if (result != E_OK){
\r
60 returnCode = result;
\r
63 serviceRequestIndication++;
\r
70 static void createAndSendNcr(Dcm_NegativeResponseCodeType responseCode)
\r
72 if (!((msgData.addrType == DCM_PROTOCOL_FUNCTIONAL_ADDR_TYPE)
\r
73 && ((responseCode == DCM_E_SERVICENOTSUPPORTED) || (responseCode == DCM_E_SUBFUNCTIONNOTSUPPORTED) || (responseCode == DCM_E_REQUESTOUTOFRANGE)))) { /** @req DCM001 */
\r
74 msgData.pduTxData->SduDataPtr[0] = SID_NEGATIVE_RESPONSE;
\r
75 msgData.pduTxData->SduDataPtr[1] = currentSid;
\r
76 msgData.pduTxData->SduDataPtr[2] = responseCode;
\r
77 msgData.pduTxData->SduLength = 3;
\r
78 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_READY); /** @req DCM114 */ /** @req DCM232.Ncr */
\r
81 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_SUPPRESSED);
\r
86 static void selectServiceFunction(uint8 sid)
\r
88 /** @req DCM442.Partially */
\r
89 switch (sid) /** @req DCM221 */
\r
91 case SID_DIAGNOSTIC_SESSION_CONTROL:
\r
92 DspUdsDiagnosticSessionControl(msgData.pduRxData, msgData.pduTxData);
\r
96 DspUdsEcuReset(msgData.pduRxData, msgData.txPduId, msgData.pduTxData);
\r
99 case SID_CLEAR_DIAGNOSTIC_INFORMATION:
\r
100 DspUdsClearDiagnosticInformation(msgData.pduRxData, msgData.pduTxData);
\r
103 case SID_READ_DTC_INFORMATION:
\r
104 DspUdsReadDtcInformation(msgData.pduRxData, msgData.pduTxData);
\r
107 case SID_READ_DATA_BY_IDENTIFIER:
\r
108 DspUdsReadDataByIdentifier(msgData.pduRxData, msgData.pduTxData);
\r
111 case SID_READ_SCALING_DATA_BY_IDENTIFIER:
\r
112 DspUdsReadScalingDataByIdentifier(msgData.pduRxData, msgData.pduTxData);
\r
115 case SID_SECURITY_ACCESS:
\r
116 DspUdsSecurityAccess(msgData.pduRxData, msgData.pduTxData);
\r
119 case SID_WRITE_DATA_BY_IDENTIFIER:
\r
120 DspUdsWriteDataByIdentifier(msgData.pduRxData, msgData.pduTxData);
\r
123 case SID_ROUTINE_CONTROL:
\r
124 DspUdsRoutineControl(msgData.pduRxData, msgData.pduTxData);
\r
127 case SID_TESTER_PRESENT:
\r
128 DspUdsTesterPresent(msgData.pduRxData, msgData.pduTxData);
\r
131 case SID_CONTROL_DTC_SETTING:
\r
132 DspUdsControlDtcSetting(msgData.pduRxData, msgData.pduTxData);
\r
135 case SID_READ_DATA_BY_PERIODIC_IDENTIFIER:
\r
136 case SID_DYNAMICALLY_DEFINE_DATA_IDENTIFIER:
\r
137 case SID_INPUT_OUTPUT_CONTROL_BY_IDENTIFIER:
\r
139 /* Non implemented service */
\r
140 createAndSendNcr(DCM_E_SERVICENOTSUPPORTED);
\r
146 static boolean lookupSid(uint8 sid, const Dcm_DsdServiceType **sidPtr)
\r
148 boolean returnStatus = TRUE;
\r
149 const Dcm_DsdServiceType *service = msgData.serviceTable->DsdService;
\r
151 while ((service->DsdSidTabServiceId != sid) && (!service->Arc_EOL)) {
\r
155 if (!service->Arc_EOL) {
\r
159 returnStatus = FALSE;
\r
163 return returnStatus;
\r
168 * Exported functions
\r
179 if (dsdDslDataIndication) {
\r
180 dsdDslDataIndication = FALSE;
\r
181 DsdHandleRequest();
\r
186 void DsdHandleRequest(void)
\r
188 Std_ReturnType result;
\r
189 const Dcm_DsdServiceType *sidConfPtr = NULL;
\r
191 currentSid = msgData.pduRxData->SduDataPtr[0]; /** @req DCM198 */
\r
194 //lint --e(506, 774) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
195 if ((DCM_RESPOND_ALL_REQUEST == STD_ON) || ((currentSid & 0x7Fu) < 0x40)) { /** @req DCM084 */
\r
196 if (lookupSid(currentSid, &sidConfPtr)) { /** @req DCM192 */ /** @req DCM193 */ /** @req DCM196 */
\r
198 if (DspCheckSessionLevel(sidConfPtr->DsdSidTabSessionLevelRef)) { /** @req DCM211 */
\r
199 if (DspCheckSecurityLevel(sidConfPtr->DsdSidTabSecurityLevelRef)) { /** @req DCM217 */
\r
200 //lint --e(506, 774) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
201 if (DCM_REQUEST_INDICATION_ENABLED == STD_ON) { /** @req DCM218 */
\r
202 result = askApplicationForServicePermission(msgData.pduRxData->SduDataPtr, msgData.pduRxData->SduLength);
\r
206 //lint --e(506, 774) PC-Lint exception Misra 13.7, 14.1 Allow configuration variables in boolean expression
\r
207 if (result == E_OK) {
\r
208 // Yes! All conditions met!
\r
209 // Check if response shall be suppressed
\r
210 if ( (sidConfPtr->DsdSidTabSubfuncAvail) && (msgData.pduRxData->SduDataPtr[1] & SUPPRESS_POS_RESP_BIT) ) { /** @req DCM204 */
\r
211 suppressPosRspMsg = TRUE; /** @req DCM202 */
\r
212 msgData.pduRxData->SduDataPtr[1] &= ~SUPPRESS_POS_RESP_BIT; /** @req DCM201 */
\r
216 suppressPosRspMsg = FALSE; /** @req DCM202 */
\r
218 selectServiceFunction(currentSid);
\r
221 if (result == E_REQUEST_ENV_NOK) {
\r
222 createAndSendNcr(DCM_E_CONDITIONSNOTCORRECT); /** @req DCM463 */
\r
225 // Do not send any response /** @req DCM462 */
\r
226 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_SUPPRESSED);
\r
231 createAndSendNcr(DCM_E_SECUTITYACCESSDENIED); /** @req DCM217 */
\r
235 createAndSendNcr(DCM_E_SERVICENOTSUPPORTEDINACTIVESESSION); /** @req DCM211 */
\r
239 createAndSendNcr(DCM_E_SERVICENOTSUPPORTED); /** @req DCM197 */
\r
243 // Inform DSL that message has been discard
\r
244 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_SUPPRESSED);
\r
250 void DsdDspProcessingDone(Dcm_NegativeResponseCodeType responseCode)
\r
252 if (responseCode == DCM_E_POSITIVERESPONSE) {
\r
253 if (!suppressPosRspMsg) { /** @req DCM200 */ /** @req DCM231 */
\r
255 msgData.pduTxData->SduDataPtr[0] = currentSid | SID_RESPONSE_BIT; /** @req DCM223 */ /** @req DCM224 */
\r
256 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_READY); /** @req DCM114 */ /** @req DCM225 */ /** @req DCM232.Ok */
\r
259 DspDcmConfirmation(msgData.txPduId); /** @req DCM236 */ /** @req DCM240 */
\r
260 DslDsdProcessingDone(msgData.rxPduId, DSD_TX_RESPONSE_SUPPRESSED);
\r
264 createAndSendNcr(responseCode); /** @req DCM228 */
\r
270 void DsdDataConfirmation(PduIdType confirmPduId, NotifResultType result)
\r
272 (void)result; /* Currently not used */
\r
273 DspDcmConfirmation(confirmPduId); /** @req DCM236 */
\r
277 void DsdDslDataIndication(const PduInfoType *pduRxData, const Dcm_DsdServiceTableType *protocolSIDTable, Dcm_ProtocolAddrTypeType addrType, PduIdType txPduId, PduInfoType *pduTxData, PduIdType rxContextPduId)
\r
279 msgData.rxPduId = rxContextPduId;
\r
280 msgData.txPduId = txPduId;
\r
281 msgData.pduRxData = pduRxData;
\r
282 msgData.pduTxData = pduTxData;
\r
283 msgData.addrType = addrType;
\r
284 msgData.serviceTable = protocolSIDTable;
\r
286 dsdDslDataIndication = TRUE;
\r