Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 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 "someip/SdOptions.h"
12 : #include "someip/SdConstants.h"
13 :
14 : #include <etl/unaligned_type.h>
15 :
16 : namespace someip
17 : {
18 32 : bool SdOptions::init(::etl::span<uint8_t const> const& payload, size_t const entriesLength)
19 : {
20 32 : size_t const optionsLengthOffset = 8U + entriesLength;
21 64 : if ((optionsLengthOffset + static_cast<uint16_t>(SdConstants::SD_OPTIONS_LENGTH_FIELD_LENGTH))
22 32 : > payload.size())
23 : {
24 1 : return false;
25 : }
26 :
27 31 : uint32_t const optionsLength = ::etl::be_uint32_t(&payload[optionsLengthOffset]);
28 31 : if ((optionsLengthOffset + static_cast<uint16_t>(SdConstants::SD_OPTIONS_LENGTH_FIELD_LENGTH)
29 31 : + optionsLength)
30 31 : > payload.size())
31 : {
32 1 : return false;
33 : }
34 :
35 30 : size_t const optionsPosition
36 : = optionsLengthOffset + static_cast<uint16_t>(SdConstants::SD_OPTIONS_LENGTH_FIELD_LENGTH);
37 :
38 30 : if (optionsPosition == payload.size())
39 : {
40 1 : _optionsData = decltype(_optionsData)();
41 : }
42 : else
43 : {
44 29 : _optionsData = payload.subspan(optionsPosition, optionsLength);
45 : }
46 :
47 30 : return true;
48 : }
49 :
50 23 : void SdOptions::readIndexValues(::etl::span<uint8_t const> const& entry)
51 : {
52 23 : _options1Index = entry[static_cast<uint16_t>(SdConstants::SD_OPTIONS_1_INDEX_OFFSET)];
53 23 : _options2Index = entry[static_cast<uint16_t>(SdConstants::SD_OPTIONS_2_INDEX_OFFSET)];
54 23 : _options1Num = entry[static_cast<uint16_t>(SdConstants::SD_OPTIONS_NUM_OFFSET)]
55 23 : >> static_cast<uint8_t>(4U);
56 23 : _options2Num = entry[static_cast<uint16_t>(SdConstants::SD_OPTIONS_NUM_OFFSET)]
57 23 : & static_cast<uint8_t>(0x0FU);
58 23 : }
59 :
60 : } // namespace someip
|