diff --git a/config/v16/profile_schemas/Internal.json b/config/v16/profile_schemas/Internal.json index 19377d726..06764ad0b 100644 --- a/config/v16/profile_schemas/Internal.json +++ b/config/v16/profile_schemas/Internal.json @@ -57,6 +57,11 @@ "minLength": 1, "maxLength": 20 }, + "HostName": { + "type": "string", + "readOnly": true, + "minLength": 1 + }, "IMSI": { "type": "string", "readOnly": true, diff --git a/include/ocpp/common/websocket/websocket_base.hpp b/include/ocpp/common/websocket/websocket_base.hpp index 17b9e0d25..542f17977 100644 --- a/include/ocpp/common/websocket/websocket_base.hpp +++ b/include/ocpp/common/websocket/websocket_base.hpp @@ -34,6 +34,7 @@ struct WebsocketConnectionOptions { int pong_timeout_s; bool use_ssl_default_verify_paths; std::optional additional_root_certificate_check; + std::optional hostName; }; /// diff --git a/include/ocpp/v16/charge_point_configuration.hpp b/include/ocpp/v16/charge_point_configuration.hpp index cdb707efb..55272ea77 100644 --- a/include/ocpp/v16/charge_point_configuration.hpp +++ b/include/ocpp/v16/charge_point_configuration.hpp @@ -100,6 +100,9 @@ class ChargePointConfiguration { int32_t getWebsocketPongTimeout(); KeyValue getWebsocketPongTimeoutKeyValue(); + std::optional getHostName(); + std::optional getHostNameKeyValue(); + // Core Profile - optional std::optional getAllowOfflineTxForUnknownId(); void setAllowOfflineTxForUnknownId(bool enabled); diff --git a/lib/ocpp/common/websocket/websocket_plain.cpp b/lib/ocpp/common/websocket/websocket_plain.cpp index 09557de71..25dd47694 100644 --- a/lib/ocpp/common/websocket/websocket_plain.cpp +++ b/lib/ocpp/common/websocket/websocket_plain.cpp @@ -126,6 +126,11 @@ void WebsocketPlain::connect_plain() { EVLOG_error << "Connection initialization error for plain websocket: " << ec.message(); } + if (this->connection_options.hostName.has_value()){ + EVLOG_info << "User-Host is set to " << this->connection_options.hostName.value(); + con->append_header("User-Host", this->connection_options.hostName.value()); + } + if (this->connection_options.security_profile == 0) { EVLOG_debug << "Connecting with security profile: 0"; } else if (this->connection_options.security_profile == 1) { diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index a1ce141b9..92ec50947 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -670,6 +670,14 @@ int32_t ChargePointConfiguration::getWebsocketPongTimeout() { return this->config["Internal"]["WebsocketPongTimeout"]; } +std::optional ChargePointConfiguration::getHostName() { + std::optional hostName_key = std::nullopt; + if (this->config["Internal"].contains("HostName")) { + hostName_key.emplace(this->config["Internal"]["HostName"]); + } + return hostName_key; +} + // Core Profile - optional std::optional ChargePointConfiguration::getAllowOfflineTxForUnknownId() { std::optional unknown_offline_auth = std::nullopt; @@ -1363,6 +1371,20 @@ std::optional ChargePointConfiguration::getWebsocketPingIntervalKeyVal return websocket_ping_interval_kv; } +std::optional ChargePointConfiguration::getHostNameKeyValue() { + std::optional host_name_kv = std::nullopt; + auto host_name = this->getHostName(); + if (host_name != std::nullopt) { + KeyValue kv; + kv.key = "HostName"; + kv.readonly = true; + kv.value.emplace(host_name.value()); + host_name_kv.emplace(kv); + } + return host_name_kv; +} + + // Core Profile end int32_t ChargePointConfiguration::getChargeProfileMaxStackLevel() { @@ -2139,6 +2161,9 @@ std::optional ChargePointConfiguration::get(CiString<50> key) { if (key == "WaitForStopTransactionsOnResetTimeout") { return this->getWaitForStopTransactionsOnResetTimeoutKeyValue(); } + if (key == "HostName") { + return this->getHostNameKeyValue(); + } // Core Profile if (key == "AllowOfflineTxForUnknownId") { diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 84464785b..b93f115ad 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -219,7 +219,8 @@ WebsocketConnectionOptions ChargePointImpl::get_ws_connection_options() { this->configuration->getWebsocketPingPayload(), this->configuration->getWebsocketPongTimeout(), this->configuration->getUseSslDefaultVerifyPaths(), - this->configuration->getAdditionalRootCertificateCheck()}; + this->configuration->getAdditionalRootCertificateCheck(), + this->configuration->getHostName()}; return connection_options; }