diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index b1fd70bdd..ff026e9d6 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -1356,6 +1356,9 @@ void ChargePointImpl::message_callback(const std::string& message) { } } catch (json::exception& e) { EVLOG_error << "JSON exception during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } if (json_message.is_array() && json_message.size() > MESSAGE_ID) { auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true)); this->message_dispatcher->dispatch_call_error(call_error); @@ -1364,6 +1367,9 @@ void ChargePointImpl::message_callback(const std::string& message) { } } catch (const EnumConversionException& e) { EVLOG_error << "EnumConversionException during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true)); this->message_dispatcher->dispatch_call_error(call_error); this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES, std::optional>(message), diff --git a/lib/ocpp/v2/charge_point.cpp b/lib/ocpp/v2/charge_point.cpp index a4cfd59d4..06c0ab39b 100644 --- a/lib/ocpp/v2/charge_point.cpp +++ b/lib/ocpp/v2/charge_point.cpp @@ -781,22 +781,37 @@ void ChargePoint::message_callback(const std::string& message) { } } catch (const EvseOutOfRangeException& e) { EVLOG_error << "Exception during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({})); this->message_dispatcher->dispatch_call_error(call_error); } catch (const ConnectorOutOfRangeException& e) { EVLOG_error << "Exception during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({})); this->message_dispatcher->dispatch_call_error(call_error); } catch (const EnumConversionException& e) { EVLOG_error << "EnumConversionException during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({})); this->message_dispatcher->dispatch_call_error(call_error); } catch (const TimePointParseException& e) { EVLOG_error << "Exception during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({})); this->message_dispatcher->dispatch_call_error(call_error); } catch (json::exception& e) { EVLOG_error << "JSON exception during handling of message: " << e.what(); + if (enhanced_message.messageTypeId != MessageTypeId::CALL) { + return; // CALLERROR shall only follow on a CALL message + } if (json_message.is_array() and json_message.size() > MESSAGE_ID) { auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({})); this->message_dispatcher->dispatch_call_error(call_error);