summaryrefslogtreecommitdiff
path: root/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
blob: e4c0504c8d6808604de4def5d3a1f60d72fc2a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "../../../../../e2e_protection/include/e2e/profile/profile01/checker.hpp"
#include "../../../../../logging/include/logger.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <algorithm>

namespace vsomeip {
namespace e2e {
namespace profile01 {

// [SWS_E2E_00196]
void profile_01_checker::check(const e2e_buffer &_buffer,
                               e2e::profile_interface::generic_check_status &_generic_check_status) {
    std::lock_guard<std::mutex> lock(check_mutex_);
    _generic_check_status = e2e::profile_interface::generic_check_status::E2E_ERROR;

    if (profile_01::is_buffer_length_valid(config_, _buffer)) {
        uint8_t received_crc(0);
        uint8_t calculated_crc(0);
        received_crc = _buffer[config_.crc_offset_];
        calculated_crc = profile_01::compute_crc(config_, _buffer);
        if (received_crc == calculated_crc) {
            _generic_check_status = e2e::profile_interface::generic_check_status::E2E_OK;
        } else {
            _generic_check_status = e2e::profile_interface::generic_check_status::E2E_WRONG_CRC;
            VSOMEIP_INFO << std::hex << "E2E protection: CRC8 does not match: calculated CRC: "
                    << (uint32_t) calculated_crc << " received CRC: " << (uint32_t) received_crc;
        }
    }
    return;
}

} // namespace profile01
} // namespace e2e
} // namespace vsomeip