Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #include "uds/base/DiagJobRoot.h"
12 :
13 : #include "transport/TransportConfiguration.h"
14 : #include "uds/UdsConstants.h"
15 : #include "uds/authentication/DefaultDiagAuthenticator.h"
16 : #include "uds/authentication/IDiagAuthenticator.h"
17 : #include "uds/connection/IncomingDiagConnection.h"
18 : #include "uds/session/IDiagSessionManager.h"
19 :
20 : namespace uds
21 : {
22 : using ::transport::TransportConfiguration;
23 :
24 154 : DiagJobRoot::DiagJobRoot() : AbstractDiagJob(nullptr, 0U, 0U)
25 : {
26 154 : fDefaultDiagReturnCode = DiagReturnCode::ISO_SERVICE_NOT_SUPPORTED;
27 154 : sfpDiagJobRoot = this;
28 154 : }
29 :
30 159 : DiagJobRoot::~DiagJobRoot() { sfpDiagJobRoot = nullptr; }
31 :
32 12 : DiagReturnCode::Type DiagJobRoot::verify(uint8_t const* const request, uint16_t const requestLength)
33 : {
34 12 : if ((request == nullptr) || (requestLength < 1U))
35 : { // no empty requests!
36 3 : return DiagReturnCode::ISO_GENERAL_REJECT;
37 : }
38 9 : return DiagReturnCode::OK;
39 : }
40 :
41 9 : DiagReturnCode::Type DiagJobRoot::execute(
42 : IncomingDiagConnection& connection, uint8_t const* const request, uint16_t const requestLength)
43 : {
44 9 : if (connection.serviceId == 0x7FU) // no response to incoming NRC
45 : {
46 0 : connection.terminate();
47 0 : return DiagReturnCode::OK;
48 : }
49 9 : if (TransportConfiguration::isFunctionalAddress(connection.targetAddress))
50 : {
51 5 : if (connection.serviceId == uds::ServiceId::TESTER_PRESENT)
52 : {
53 7 : if ((!getDiagSessionManager().isSessionTimeoutActive()) && (requestLength > 1U)
54 7 : && (((request[1] & SUPPRESS_POSITIVE_RESPONSE_MASK)) > 0U))
55 : {
56 1 : connection.terminate();
57 1 : return DiagReturnCode::OK;
58 : }
59 : }
60 : }
61 8 : DiagReturnCode::Type const ret = verify(request, requestLength);
62 8 : if (ret != DiagReturnCode::OK)
63 : {
64 0 : (void)getDiagSessionManager().acceptedJob(connection, *this, request, requestLength);
65 0 : return ret;
66 : }
67 8 : if (!fAllowedSessions.match(getSession()))
68 : {
69 0 : acceptJob(connection, request, requestLength);
70 0 : return DiagReturnCode::ISO_REQUEST_OUT_OF_RANGE;
71 : }
72 8 : return process(connection, request, requestLength);
73 : }
74 :
75 : DiagReturnCode::Type
76 59 : DiagJobRoot::verifySupplierIndication(uint8_t const* const request, uint16_t const requestLength)
77 : {
78 : (void)request;
79 : (void)requestLength;
80 59 : return DiagReturnCode::OK;
81 : }
82 :
83 : } // namespace uds
|