Skip to content

Commit

Permalink
Extend OCPP security event with "critical" and "timestamp" parameters (
Browse files Browse the repository at this point in the history
…#868)

* Extend OCPP security event with "critical" and "timestamp" parameters

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Sep 24, 2024
1 parent 7dde66b commit 17555a7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libevse-security:
# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: 4a62b490fb89efd9c2f36d21d7949ee273d2c8b9
git_tag: 5dedd1f92d3414e8304887c1d2bca19bbee31f63
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP"
# Josev
Josev:
Expand Down
13 changes: 5 additions & 8 deletions interfaces/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ cmds:
false
security_event:
description: >-
Triggers a SecurityEventNotification.req at the CSMS. This event is queued with a guaranteed delivery
to the CSMS.
Triggers a SecurityEventNotification.req at the CSMS if it is deemed critical, either by setting the flag in this event or if absent automatically by libocpp
arguments:
type:
description: type of the security event
type: string
info:
description: Additional information about the occurred security event
type: string
event:
description: A security event
type: object
$ref: /ocpp#/SecurityEvent
get_variables:
description: >-
Command to get a variable from OCPP.
Expand Down
5 changes: 4 additions & 1 deletion modules/OCPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ target_sources(${MODULE_NAME}
"data_transfer/ocpp_data_transferImpl.cpp"
"ocpp_generic/ocppImpl.cpp"
"session_cost/session_costImpl.cpp"
"conversions.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
target_sources(${MODULE_NAME}
PRIVATE
"conversions.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
12 changes: 10 additions & 2 deletions modules/OCPP/ocpp_generic/ocppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@ bool ocppImpl::handle_restart() {
return success;
}

void ocppImpl::handle_security_event(std::string& type, std::string& info) {
this->mod->charge_point->on_security_event(type, info);
void ocppImpl::handle_security_event(types::ocpp::SecurityEvent& event) {
std::optional<ocpp::DateTime> timestamp;
if (event.timestamp.has_value()) {
try {
timestamp = ocpp::DateTime(event.timestamp.value());
} catch (...) {
EVLOG_warning << "Timestamp in security event could not be parsed, using current datetime.";
}
}
this->mod->charge_point->on_security_event(event.type, event.info, event.critical, timestamp);
}

std::vector<types::ocpp::GetVariableResult>
Expand Down
2 changes: 1 addition & 1 deletion modules/OCPP/ocpp_generic/ocppImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ocppImpl : public ocppImplBase {
// command handler functions (virtual)
virtual bool handle_stop() override;
virtual bool handle_restart() override;
virtual void handle_security_event(std::string& type, std::string& info) override;
virtual void handle_security_event(types::ocpp::SecurityEvent& event) override;
virtual std::vector<types::ocpp::GetVariableResult>
handle_get_variables(std::vector<types::ocpp::GetVariableRequest>& requests) override;
virtual std::vector<types::ocpp::SetVariableResult>
Expand Down
8 changes: 6 additions & 2 deletions modules/OCPP201/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ target_sources(${MODULE_NAME}
"auth_validator/auth_token_validatorImpl.cpp"
"auth_provider/auth_token_providerImpl.cpp"
"data_transfer/ocpp_data_transferImpl.cpp"
"conversions.cpp"
"transaction_handler.cpp"
"ocpp_generic/ocppImpl.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
target_sources(${MODULE_NAME}
PRIVATE
"conversions.cpp"
"transaction_handler.cpp"
)

if(EVEREST_CORE_BUILD_TESTING)
add_subdirectory(tests)
endif()
Expand Down
12 changes: 10 additions & 2 deletions modules/OCPP201/ocpp_generic/ocppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ bool ocppImpl::handle_restart() {
return true;
}

void ocppImpl::handle_security_event(std::string& type, std::string& info) {
this->mod->charge_point->on_security_event(type, info);
void ocppImpl::handle_security_event(types::ocpp::SecurityEvent& event) {
std::optional<ocpp::DateTime> timestamp;
if (event.timestamp.has_value()) {
try {
timestamp = ocpp::DateTime(event.timestamp.value());
} catch (...) {
EVLOG_warning << "Timestamp in security event could not be parsed, using current datetime.";
}
}
this->mod->charge_point->on_security_event(event.type, event.info, event.critical, timestamp);
}

std::vector<types::ocpp::GetVariableResult>
Expand Down
2 changes: 1 addition & 1 deletion modules/OCPP201/ocpp_generic/ocppImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ocppImpl : public ocppImplBase {
// command handler functions (virtual)
virtual bool handle_stop() override;
virtual bool handle_restart() override;
virtual void handle_security_event(std::string& type, std::string& info) override;
virtual void handle_security_event(types::ocpp::SecurityEvent& event) override;
virtual std::vector<types::ocpp::GetVariableResult>
handle_get_variables(std::vector<types::ocpp::GetVariableRequest>& requests) override;
virtual std::vector<types::ocpp::SetVariableResult>
Expand Down
9 changes: 9 additions & 0 deletions types/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ types:
info:
description: Additional information about the occurred security event
type: string
critical:
description: >-
If set this overwrites the default criticality recommended in the OCPP 2.0.1 appendix.
A critical security event is transmitted as a message to the CSMS, a non-critical one is just written to the security log
type: boolean
timestamp:
description: Timestamp of the moment the security event was generated, if absent the current datetime is assumed
type: string
format: date-time
EVSE:
description: >-
Type of an EVSE. If only the id is present, this type identifies an EVSE.
Expand Down

0 comments on commit 17555a7

Please sign in to comment.