Skip to content

Commit ffa6d06

Browse files
committed
* added optional BootReason to charge_point start function
* added optional BootReason to charge_point restart function * using string definitions for all SecurityEventNotifications in 1.6 * Sending SecurityEventNotification on startup if StartUpOfTheDevice or ResetOrReboot Signed-off-by: pietfried <pietgoempel@gmail.com>
1 parent 84b604a commit ffa6d06

File tree

5 files changed

+56
-17
lines changed

5 files changed

+56
-17
lines changed

include/ocpp/v16/charge_point.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ class ChargePoint {
7373
/// \param connector_status_map initial state of connectors including connector 0 with reduced set of states
7474
/// (Available, Unavailable, Faulted). connector_status_map is empty, last availability states from the persistant
7575
/// storage will be used
76+
/// \param bootreason reason for calling the start function
7677
/// \return
77-
bool start(const std::map<int, ChargePointStatus>& connector_status_map = {});
78+
bool start(const std::map<int, ChargePointStatus>& connector_status_map = {}, BootReasonEnum bootreason = BootReasonEnum::PowerUp);
7879

7980
/// \brief Restarts the ChargePoint if it has been stopped before. The ChargePoint is reinitialized, connects to the
8081
/// websocket and starts to communicate OCPP messages again
8182
/// \param connector_status_map initial state of connectors including connector 0 with reduced set of states
8283
/// (Available, Unavailable, Faulted). connector_status_map is empty, last availability states from the persistant
8384
/// storage will be used
84-
bool restart(const std::map<int, ChargePointStatus>& connector_status_map = {});
85+
/// \param bootreason reason for calling the start function
86+
bool restart(const std::map<int, ChargePointStatus>& connector_status_map = {}, BootReasonEnum bootreason = BootReasonEnum::ApplicationReset);
8587

8688
// \brief Resets the internal state machine for the connectors using the given \p connector_status_map
8789
/// \param connector_status_map state of connectors including connector 0 with reduced set of states (Available,

include/ocpp/v16/charge_point_impl.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace v16 {
8686
class ChargePointImpl : ocpp::ChargingStationBase {
8787
private:
8888
bool initialized;
89+
BootReasonEnum bootreason;
8990
ChargePointConnectionState connection_state;
9091
bool boot_notification_callerror;
9192
RegistrationStatus registration_status;
@@ -373,15 +374,18 @@ class ChargePointImpl : ocpp::ChargingStationBase {
373374
/// \brief Starts the ChargePoint, initializes and connects to the Websocket endpoint and initializes a
374375
/// BootNotification.req
375376
/// \param connector_status_map initial state of connectors including connector 0 with reduced set of states
376-
/// (Available, Unavailable, Faulted) \return
377-
bool start(const std::map<int, ChargePointStatus>& connector_status_map);
377+
/// (Available, Unavailable, Faulted)
378+
/// \param bootreason reason for calling the start function
379+
/// \return
380+
bool start(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason);
378381

379382
/// \brief Restarts the ChargePoint if it has been stopped before. The ChargePoint is reinitialized, connects to the
380383
/// websocket and starts to communicate OCPP messages again
381384
/// \param connector_status_map initial state of connectors including connector 0 with reduced set of states
382385
/// (Available, Unavailable, Faulted). connector_status_map is empty, last availability states from the persistant
383386
/// storage will be used
384-
bool restart(const std::map<int, ChargePointStatus>& connector_status_map);
387+
/// \param bootreason reason for calling the restart function
388+
bool restart(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason);
385389

386390
/// \brief Resets the internal state machine for the connectors using the given \p connector_status_map
387391
/// \param connector_status_map state of connectors including connector 0 with reduced set of states (Available,

include/ocpp/v16/types.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ struct AvailabilityChange {
186186
bool persist;
187187
};
188188

189+
/// \brief BootReasonEnum contains the different boot reasons of the charge point (copied from OCPP2.0.1 definition)
190+
enum BootReasonEnum {
191+
ApplicationReset,
192+
FirmwareUpdate,
193+
LocalReset,
194+
PowerUp,
195+
RemoteReset,
196+
ScheduledReset,
197+
Triggered,
198+
Unknown,
199+
Watchdog
200+
};
201+
189202
} // namespace v16
190203
} // namespace ocpp
191204

lib/ocpp/v16/charge_point.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ ChargePoint::ChargePoint(const std::string& config, const fs::path& share_path,
2121

2222
ChargePoint::~ChargePoint() = default;
2323

24-
bool ChargePoint::start(const std::map<int, ChargePointStatus>& connector_status_map) {
25-
return this->charge_point->start(connector_status_map);
24+
bool ChargePoint::start(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason) {
25+
return this->charge_point->start(connector_status_map, bootreason);
2626
}
2727

28-
bool ChargePoint::restart(const std::map<int, ChargePointStatus>& connector_status_map) {
29-
return this->charge_point->restart(connector_status_map);
28+
bool ChargePoint::restart(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason) {
29+
return this->charge_point->restart(connector_status_map, bootreason);
3030
}
3131

3232
bool ChargePoint::stop() {

lib/ocpp/v16/charge_point_impl.cpp

+28-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ChargePointImpl::ChargePointImpl(const std::string& config, const fs::path& shar
2828
ocpp::ChargingStationBase(evse_security, security_configuration),
2929
boot_notification_callerror(false),
3030
initialized(false),
31+
bootreason(BootReasonEnum::PowerUp),
3132
connection_state(ChargePointConnectionState::Disconnected),
3233
registration_status(RegistrationStatus::Pending),
3334
diagnostics_status(DiagnosticsStatus::Idle),
@@ -789,7 +790,8 @@ void ChargePointImpl::send_meter_value(int32_t connector, MeterValue meter_value
789790
this->send<MeterValuesRequest>(call, initiated_by_trigger_message);
790791
}
791792

792-
bool ChargePointImpl::start(const std::map<int, ChargePointStatus>& connector_status_map) {
793+
bool ChargePointImpl::start(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason) {
794+
this->bootreason = bootreason;
793795
this->init_state_machine(connector_status_map);
794796
this->init_websocket();
795797
this->websocket->connect();
@@ -800,15 +802,15 @@ bool ChargePointImpl::start(const std::map<int, ChargePointStatus>& connector_st
800802
return true;
801803
}
802804

803-
bool ChargePointImpl::restart(const std::map<int, ChargePointStatus>& connector_status_map) {
805+
bool ChargePointImpl::restart(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason) {
804806
if (this->stopped) {
805807
EVLOG_info << "Restarting OCPP Chargepoint";
806808
this->database_handler->open_db_connection(this->configuration->getNumberOfConnectors());
807809
// instantiating new message queue on restart
808810
this->message_queue = this->create_message_queue();
809811
this->initialized = true;
810812

811-
return this->start(connector_status_map);
813+
return this->start(connector_status_map, bootreason);
812814
} else {
813815
EVLOG_warning << "Attempting to restart Chargepoint while it has not been stopped before";
814816
return false;
@@ -1013,6 +1015,7 @@ void ChargePointImpl::message_callback(const std::string& message) {
10131015
auto call_error = CallError(MessageId(json_message.at(MESSAGE_ID).get<std::string>()), "FormationViolation",
10141016
e.what(), json({}, true));
10151017
this->send(call_error);
1018+
this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES, message, true);
10161019
}
10171020
}
10181021
}
@@ -1198,6 +1201,19 @@ void ChargePointImpl::handleBootNotificationResponse(ocpp::CallResult<BootNotifi
11981201
this->ocsp_request_timer->timeout(INITIAL_CERTIFICATE_REQUESTS_DELAY);
11991202
}
12001203

1204+
if (this->bootreason == BootReasonEnum::RemoteReset) {
1205+
this->securityEventNotification(
1206+
CiString<50>(ocpp::security_events::RESET_OR_REBOOT),
1207+
"Charging Station rebooted due to requested remote reset!", true);
1208+
} else if (this->bootreason == BootReasonEnum::ScheduledReset) {
1209+
this->securityEventNotification(
1210+
CiString<50>(ocpp::security_events::RESET_OR_REBOOT),
1211+
"Charging Station rebooted due to a scheduled reset!", true);
1212+
} else if (this->bootreason == BootReasonEnum::PowerUp) {
1213+
this->securityEventNotification(CiString<50>(ocpp::security_events::STARTUP_OF_THE_DEVICE),
1214+
"The Charge Point has booted", true);
1215+
}
1216+
12011217
this->stop_pending_transactions();
12021218

12031219
break;
@@ -2229,7 +2245,7 @@ void ChargePointImpl::handleCertificateSignedRequest(ocpp::Call<CertificateSigne
22292245
this->send<CertificateSignedResponse>(call_result);
22302246

22312247
if (response.status == CertificateSignedStatusEnumType::Rejected) {
2232-
this->securityEventNotification("InvalidChargePointCertificate",
2248+
this->securityEventNotification(ocpp::security_events::INVALIDCHARGINGSTATIONCERTIFICATE,
22332249
ocpp::conversions::install_certificate_result_to_string(result), true);
22342250
}
22352251

@@ -2312,7 +2328,7 @@ void ChargePointImpl::handleInstallCertificateRequest(ocpp::Call<InstallCertific
23122328
this->send<InstallCertificateResponse>(call_result);
23132329

23142330
if (response.status == InstallCertificateStatusEnumType::Rejected) {
2315-
this->securityEventNotification("InvalidCentralSystemCertificate",
2331+
this->securityEventNotification(ocpp::security_events::INVALIDCSMSCERTIFICATE,
23162332
ocpp::conversions::install_certificate_result_to_string(result), true);
23172333
}
23182334
}
@@ -2348,7 +2364,7 @@ void ChargePointImpl::handleSignedUpdateFirmware(ocpp::Call<SignedUpdateFirmware
23482364
}
23492365

23502366
if (response.status == UpdateFirmwareStatusEnumType::InvalidCertificate) {
2351-
this->securityEventNotification("InvalidFirmwareSigningCertificate", "Certificate is invalid.", true);
2367+
this->securityEventNotification(ocpp::security_events::INVALIDFIRMWARESIGNINGCERTIFICATE, "Certificate is invalid.", true);
23522368
}
23532369
}
23542370

@@ -2413,7 +2429,7 @@ void ChargePointImpl::signed_firmware_update_status_notification(FirmwareStatusE
24132429
this->send<SignedFirmwareStatusNotificationRequest>(call, initiated_by_trigger_message);
24142430

24152431
if (status == FirmwareStatusEnumType::InvalidSignature) {
2416-
this->securityEventNotification("InvalidFirmwareSignature", "", true);
2432+
this->securityEventNotification(ocpp::security_events::INVALIDFIRMWARESIGNATURE, "", true);
24172433
}
24182434

24192435
if (this->firmware_update_is_pending) {
@@ -2957,7 +2973,7 @@ void ChargePointImpl::handle_data_transfer_pnc_certificate_signed(Call<DataTrans
29572973
this->send<DataTransferResponse>(call_result);
29582974

29592975
if (certificate_response.status == CertificateSignedStatusEnumType::Rejected) {
2960-
this->securityEventNotification("InvalidChargePointCertificate", tech_info, true);
2976+
this->securityEventNotification(ocpp::security_events::INVALIDCHARGINGSTATIONCERTIFICATE, tech_info, true);
29612977
}
29622978
} catch (const json::exception& e) {
29632979
EVLOG_warning << "Could not parse data of DataTransfer message CertificateSigned.req: " << e.what();
@@ -3424,6 +3440,10 @@ void ChargePointImpl::on_firmware_update_status_notification(int32_t request_id,
34243440
} catch (const std::out_of_range& e) {
34253441
EVLOG_debug << "Could not convert incoming FirmwareStatusNotification to OCPP type";
34263442
}
3443+
3444+
if (firmware_update_status == FirmwareStatusNotification::Installed) {
3445+
this->securityEventNotification(ocpp::security_events::FIRMWARE_UPDATED, "Firmware update was installed", true);
3446+
}
34273447
}
34283448

34293449
void ChargePointImpl::diagnostic_status_notification(DiagnosticsStatus status) {

0 commit comments

Comments
 (0)