Skip to content

Commit f54a161

Browse files
committed
Implemented a check of the enhanced_message to handle in message_callback so that only send CALLERROR on CALL messages
Signed-off-by: Piet Gömpel <pietgoempel@gmail.com>
1 parent 260bcec commit f54a161

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/ocpp/v16/charge_point_impl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,9 @@ void ChargePointImpl::message_callback(const std::string& message) {
13561356
}
13571357
} catch (json::exception& e) {
13581358
EVLOG_error << "JSON exception during handling of message: " << e.what();
1359+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
1360+
return; // CALLERROR shall only follow on a CALL message
1361+
}
13591362
if (json_message.is_array() && json_message.size() > MESSAGE_ID) {
13601363
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true));
13611364
this->message_dispatcher->dispatch_call_error(call_error);
@@ -1364,6 +1367,9 @@ void ChargePointImpl::message_callback(const std::string& message) {
13641367
}
13651368
} catch (const EnumConversionException& e) {
13661369
EVLOG_error << "EnumConversionException during handling of message: " << e.what();
1370+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
1371+
return; // CALLERROR shall only follow on a CALL message
1372+
}
13671373
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true));
13681374
this->message_dispatcher->dispatch_call_error(call_error);
13691375
this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES, std::optional<CiString<255>>(message),

lib/ocpp/v201/charge_point.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -771,22 +771,37 @@ void ChargePoint::message_callback(const std::string& message) {
771771
}
772772
} catch (const EvseOutOfRangeException& e) {
773773
EVLOG_error << "Exception during handling of message: " << e.what();
774+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
775+
return; // CALLERROR shall only follow on a CALL message
776+
}
774777
auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({}));
775778
this->message_dispatcher->dispatch_call_error(call_error);
776779
} catch (const ConnectorOutOfRangeException& e) {
777780
EVLOG_error << "Exception during handling of message: " << e.what();
781+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
782+
return; // CALLERROR shall only follow on a CALL message
783+
}
778784
auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({}));
779785
this->message_dispatcher->dispatch_call_error(call_error);
780786
} catch (const EnumConversionException& e) {
781787
EVLOG_error << "EnumConversionException during handling of message: " << e.what();
788+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
789+
return; // CALLERROR shall only follow on a CALL message
790+
}
782791
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
783792
this->message_dispatcher->dispatch_call_error(call_error);
784793
} catch (const TimePointParseException& e) {
785794
EVLOG_error << "Exception during handling of message: " << e.what();
795+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
796+
return; // CALLERROR shall only follow on a CALL message
797+
}
786798
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
787799
this->message_dispatcher->dispatch_call_error(call_error);
788800
} catch (json::exception& e) {
789801
EVLOG_error << "JSON exception during handling of message: " << e.what();
802+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
803+
return; // CALLERROR shall only follow on a CALL message
804+
}
790805
if (json_message.is_array() and json_message.size() > MESSAGE_ID) {
791806
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
792807
this->message_dispatcher->dispatch_call_error(call_error);

0 commit comments

Comments
 (0)