From 6b7df42eff5b954cee88ae9fe4b546aafb5d3afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= Date: Wed, 13 Nov 2024 11:01:51 +0100 Subject: [PATCH] Fixed an issue when setting the NetworkConfigurationPriority. During the validation, every entry of the new priority list was checked using the connectivity_managers cached slots. The slots of the connectivity manager are only initialized at startup. A new profile could have been send using a SetNetworkProfile.req by the CSMS at runtime, so when validating the NetworkConfigurationPriority we shall not use the cached connectivity_manager slots but the NetworkConnectionProfiles stored in the device model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piet Gömpel --- lib/ocpp/v201/charge_point.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 8fc4f5387..ec6afde3d 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -1855,16 +1855,22 @@ bool ChargePoint::validate_set_variable(const SetVariableData& set_variable_data const auto network_configuration_priorities = ocpp::split_string(set_variable_data.attributeValue.get(), ','); const auto active_security_profile = this->device_model->get_value(ControllerComponentVariables::SecurityProfile); + const auto network_connection_profiles = json::parse( + this->device_model->get_value(ControllerComponentVariables::NetworkConnectionProfiles)); for (const auto configuration_slot : network_configuration_priorities) { try { - auto network_profile_opt = - this->connectivity_manager->get_network_connection_profile(std::stoi(configuration_slot)); - if (!network_profile_opt.has_value()) { + auto network_profile_it = + std::find_if(network_connection_profiles.begin(), network_connection_profiles.end(), + [configuration_slot](const SetNetworkProfileRequest& network_profile) { + return network_profile.configurationSlot == std::stoi(configuration_slot); + }); + + if (network_profile_it == network_connection_profiles.end()) { EVLOG_warning << "Could not find network profile for configurationSlot: " << configuration_slot; return false; } - auto network_profile = network_profile_opt.value(); + auto network_profile = SetNetworkProfileRequest(*network_profile_it).connectionData; if (network_profile.securityProfile <= active_security_profile) { continue; @@ -1887,6 +1893,8 @@ bool ChargePoint::validate_set_variable(const SetVariableData& set_variable_data } catch (const std::invalid_argument& e) { EVLOG_warning << "NetworkConfigurationPriority is not an integer: " << configuration_slot; return false; + } catch (const json::exception& e) { + EVLOG_warning << "Could not parse data of SetNetworkProfileRequest: " << e.what(); } } }