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 157 : DiagJobRoot::DiagJobRoot() : AbstractDiagJob(nullptr, 0U, 0U)
25 : {
26 157 : fDefaultDiagReturnCode = DiagReturnCode::ISO_SERVICE_NOT_SUPPORTED;
27 157 : sfpDiagJobRoot = this;
28 157 : }
29 :
30 162 : 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 : ::etl::span<uint8_t const> const requestView(request, requestLength);
45 9 : if (connection.serviceId == 0x7FU) // no response to incoming NRC
46 : {
47 0 : connection.terminate();
48 0 : return DiagReturnCode::OK;
49 : }
50 9 : if (TransportConfiguration::isFunctionalAddress(connection.targetAddress))
51 : {
52 5 : if (connection.serviceId == uds::ServiceId::TESTER_PRESENT)
53 : {
54 7 : if ((!getDiagSessionManager().isSessionTimeoutActive()) && (requestLength > 1U)
55 7 : && (((requestView[1U] & SUPPRESS_POSITIVE_RESPONSE_MASK)) > 0U))
56 : {
57 1 : connection.terminate();
58 1 : return DiagReturnCode::OK;
59 : }
60 : }
61 : }
62 8 : DiagReturnCode::Type const ret = verify(request, requestLength);
63 8 : if (ret != DiagReturnCode::OK)
64 : {
65 0 : (void)getDiagSessionManager().acceptedJob(connection, *this, request, requestLength);
66 0 : return ret;
67 : }
68 8 : if (!fAllowedSessions.match(getSession()))
69 : {
70 0 : acceptJob(connection, request, requestLength);
71 0 : return DiagReturnCode::ISO_REQUEST_OUT_OF_RANGE;
72 : }
73 8 : return process(connection, request, requestLength);
74 : }
75 :
76 : DiagReturnCode::Type
77 59 : DiagJobRoot::verifySupplierIndication(uint8_t const* const request, uint16_t const requestLength)
78 : {
79 : (void)request;
80 : (void)requestLength;
81 59 : return DiagReturnCode::OK;
82 : }
83 :
84 : } // namespace uds
|