Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2025 Pionix GmbH and Contributors to EVerest
#pragma once

#include <iso15118/message/d2/msg_data_types.hpp>

Check warning on line 5 in lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp#L5

Include file: <iso15118/message/d2/msg_data_types.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <optional>

Check warning on line 7 in lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp#L7

Include file: <optional> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string>

Check warning on line 8 in lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp#L8

Include file: <string> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace iso15118::d2::msg {

namespace data_types {} // namespace data_types

struct AuthorizationRequest {
Header header;
std::string id;

Check warning on line 16 in lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/include/iso15118/message/d2/authorization.hpp#L16

struct member 'AuthorizationRequest::id' is never used.
std::optional<data_types::GEN_CHALLENGE> gen_challenge;
};

struct AuthorizationResponse {
Header header;
data_types::ResponseCode response_code;
data_types::EVSEProcessing evse_processing;
};

} // namespace iso15118::d2::msg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace data_types {
constexpr auto SESSION_ID_LENGTH = 8;
using SESSION_ID = std::array<uint8_t, SESSION_ID_LENGTH>; // hexBinary, max length 8

constexpr auto GEN_CHALLENGE_LENGTH = 16;
using GEN_CHALLENGE = std::array<char, GEN_CHALLENGE_LENGTH>; // base64 binary

enum class ResponseCode {
OK,
OK_NewSessionEstablished,
Expand Down Expand Up @@ -52,6 +55,12 @@ enum class FaultCode {
UnknownError,
};

enum class EVSEProcessing {
Finished,
Ongoing,
Ongoing_WaitingForCustomerInteraction
};

struct Notification {
FaultCode fault_code;
std::optional<std::string> fault_msg;
Expand Down
4 changes: 4 additions & 0 deletions lib/everest/iso15118/include/iso15118/message/d2/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ enum class Type {
SupportedAppProtocolRes,
SessionSetupReq,
SessionSetupRes,
AuthorizationReq,
AuthorizationRes,
};

template <typename T> struct TypeTrait {
Expand Down Expand Up @@ -39,6 +41,8 @@ CREATE_TYPE_TRAIT(SupportedAppProtocolRequest, SupportedAppProtocolReq);
CREATE_TYPE_TRAIT(SupportedAppProtocolResponse, SupportedAppProtocolRes);
CREATE_TYPE_TRAIT(SessionSetupRequest, SessionSetupReq);
CREATE_TYPE_TRAIT(SessionSetupResponse, SessionSetupRes);
CREATE_TYPE_TRAIT(AuthorizationRequest, AuthorizationReq);
CREATE_TYPE_TRAIT(AuthorizationResponse, AuthorizationRes);

#ifdef CREATE_TYPE_TRAIT_PUSHED
#define CREATE_TYPE_TRAIT CREATE_TYPE_TRAIT_PUSHED
Expand Down
1 change: 1 addition & 0 deletions lib/everest/iso15118/src/iso15118/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ target_sources(iso15118
message/dc_welding_detection.cpp
message/session_stop.cpp

message/d2/authorization.cpp
message/d2/variant.cpp
message/d2/msg_data_types.cpp
message/d2/session_setup.cpp
Expand Down
52 changes: 52 additions & 0 deletions lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2025 Pionix GmbH and Contributors to EVerest
#include <iso15118/message/d2/authorization.hpp>

Check warning on line 3 in lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp#L3

Include file: <iso15118/message/d2/authorization.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <iso15118/detail/variant_access.hpp>

Check warning on line 5 in lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp#L5

Include file: <iso15118/detail/variant_access.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <cbv2g/iso_2/iso2_msgDefDecoder.h>

Check warning on line 7 in lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp#L7

Include file: <cbv2g/iso_2/iso2_msgDefDecoder.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cbv2g/iso_2/iso2_msgDefEncoder.h>

Check warning on line 8 in lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp#L8

Include file: <cbv2g/iso_2/iso2_msgDefEncoder.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <iso15118/detail/helper.hpp>

Check warning on line 10 in lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/src/iso15118/message/d2/authorization.cpp#L10

Include file: <iso15118/detail/helper.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace iso15118::d2::msg {

template <> void convert(const struct iso2_AuthorizationReqType& in, AuthorizationRequest& out) {
std::copy(in.Id.characters, in.Id.characters + in.Id.charactersLen, out.id.begin());
if (in.GenChallenge_isUsed) {
std::copy(in.GenChallenge.bytes, in.GenChallenge.bytes + in.GenChallenge.bytesLen,
out.gen_challenge.value().begin());
}
}

template <>
void insert_type(VariantAccess& va, const struct iso2_AuthorizationReqType& in,
const struct iso2_MessageHeaderType& header) {
va.insert_type<AuthorizationRequest>(in, header);
}

template <> void convert(const AuthorizationResponse& in, struct iso2_AuthorizationResType& out) {
init_iso2_AuthorizationResType(&out);

cb_convert_enum(in.response_code, out.ResponseCode);
cb_convert_enum(in.evse_processing, out.EVSEProcessing);
}

template <> int serialize_to_exi(const AuthorizationResponse& in, exi_bitstream_t& out) {

iso2_exiDocument doc;
init_iso2_exiDocument(&doc);

convert(in.header, doc.V2G_Message.Header);

CB_SET_USED(doc.V2G_Message.Body.AuthorizationRes);
convert(in, doc.V2G_Message.Body.AuthorizationRes);

return encode_iso2_exiDocument(&out, &doc);
}

template <> size_t serialize(const AuthorizationResponse& in, const io::StreamOutputView& out) {
return serialize_helper(in, out);
}

} // namespace iso15118::d2::msg
2 changes: 2 additions & 0 deletions lib/everest/iso15118/src/iso15118/message/d2/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void handle_v2g(VariantAccess& va) {

if (doc.V2G_Message.Body.SessionSetupReq_isUsed) {
insert_type(va, doc.V2G_Message.Body.SessionSetupReq, doc.V2G_Message.Header);
} else if (doc.V2G_Message.Body.AuthorizationReq_isUsed) {
insert_type(va, doc.V2G_Message.Body.AuthorizationReq, doc.V2G_Message.Header);
} else {
va.error = "chosen message type unhandled";
}
Expand Down
1 change: 1 addition & 0 deletions lib/everest/iso15118/test/exi/cb/iso2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ function(create_exi_test_target NAME)
endfunction()

create_exi_test_target(session_setup)
create_exi_test_target(authorization)

49 changes: 49 additions & 0 deletions lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <catch2/catch_test_macros.hpp>

Check warning on line 1 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L1

Include file: <catch2/catch_test_macros.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <cstdint>

Check warning on line 3 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L3

Include file: <cstdint> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iso15118/message/d2/authorization.hpp>

Check warning on line 4 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L4

Include file: <iso15118/message/d2/authorization.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iso15118/message/d2/variant.hpp>

Check warning on line 5 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L5

Include file: <iso15118/message/d2/variant.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "helper.hpp"

#include <iomanip>

Check warning on line 9 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L9

Include file: <iomanip> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iostream>

Check warning on line 10 in lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/iso15118/test/exi/cb/iso2/authorization.cpp#L10

Include file: <iostream> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace iso15118;

SCENARIO("Ser/Deserialize d2 authorization messages") {
GIVEN("Deserialize authorization req") {
// TODO(kd): Test deserialization of GenChallenge field

uint8_t doc_raw[] = {0x80, 0x98, 0x2, 0x0, 0xb6, 0xc8, 0x81, 0xce, 0xc2, 0x13, 0x4b, 0x50, 0x8};

const io::StreamInputView stream_view{doc_raw, sizeof(doc_raw)};

d2::msg::Variant variant(io::v2gtp::PayloadType::SAP, stream_view, false);

THEN("It should be deserialized successfully") {
REQUIRE(variant.get_type() == d2::msg::Type::AuthorizationReq);

const auto& msg = variant.get<d2::msg::AuthorizationRequest>();
const auto& header = msg.header;

REQUIRE(header.session_id == std::array<uint8_t, 8>{0x02, 0xDB, 0x22, 0x07, 0x3B, 0x08, 0x4D, 0x2D});

REQUIRE(msg.id == "");
}
}
GIVEN("Serialize authorization res") {

const auto header = d2::msg::Header{{0x02, 0xDB, 0x22, 0x07, 0x3B, 0x08, 0x4D, 0x2D}, std::nullopt};

const auto res = d2::msg::AuthorizationResponse{header, d2::msg::data_types::ResponseCode::OK,
d2::msg::data_types::EVSEProcessing::Ongoing};

std::vector<uint8_t> expected = {0x80, 0x98, 0x2, 0x0, 0xb6, 0xc8, 0x81, 0xce,
0xc2, 0x13, 0x4b, 0x50, 0x10, 0x1, 0x0};

THEN("It should be serialized successfully") {
REQUIRE(serialize_helper(res) == expected);
}
}
}