Skip to content

Commit b3de351

Browse files
authored
Send CALLERROR only as response to CALL message (#995)
* 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 e3c135e commit b3de351

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/ocpp/v16/charge_point_impl.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -1366,18 +1366,24 @@ void ChargePointImpl::message_callback(const std::string& message) {
13661366
}
13671367
} catch (json::exception& e) {
13681368
EVLOG_error << "JSON exception during handling of message: " << e.what();
1369+
this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES, std::optional<CiString<255>>(message),
1370+
true);
1371+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
1372+
return; // CALLERROR shall only follow on a CALL message
1373+
}
13691374
if (json_message.is_array() && json_message.size() > MESSAGE_ID) {
13701375
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true));
13711376
this->message_dispatcher->dispatch_call_error(call_error);
1372-
this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES,
1373-
std::optional<CiString<255>>(message), true);
13741377
}
13751378
} catch (const EnumConversionException& e) {
13761379
EVLOG_error << "EnumConversionException during handling of message: " << e.what();
1377-
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true));
1378-
this->message_dispatcher->dispatch_call_error(call_error);
13791380
this->securityEventNotification(ocpp::security_events::INVALIDMESSAGES, std::optional<CiString<255>>(message),
13801381
true);
1382+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
1383+
return; // CALLERROR shall only follow on a CALL message
1384+
}
1385+
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}, true));
1386+
this->message_dispatcher->dispatch_call_error(call_error);
13811387
}
13821388
}
13831389

lib/ocpp/v2/charge_point.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -867,22 +867,37 @@ void ChargePoint::message_callback(const std::string& message) {
867867
}
868868
} catch (const EvseOutOfRangeException& e) {
869869
EVLOG_error << "Exception during handling of message: " << e.what();
870+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
871+
return; // CALLERROR shall only follow on a CALL message
872+
}
870873
auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({}));
871874
this->message_dispatcher->dispatch_call_error(call_error);
872875
} catch (const ConnectorOutOfRangeException& e) {
873876
EVLOG_error << "Exception during handling of message: " << e.what();
877+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
878+
return; // CALLERROR shall only follow on a CALL message
879+
}
874880
auto call_error = CallError(enhanced_message.uniqueId, "OccurrenceConstraintViolation", e.what(), json({}));
875881
this->message_dispatcher->dispatch_call_error(call_error);
876882
} catch (const EnumConversionException& e) {
877883
EVLOG_error << "EnumConversionException during handling of message: " << e.what();
884+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
885+
return; // CALLERROR shall only follow on a CALL message
886+
}
878887
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
879888
this->message_dispatcher->dispatch_call_error(call_error);
880889
} catch (const TimePointParseException& e) {
881890
EVLOG_error << "Exception during handling of message: " << e.what();
891+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
892+
return; // CALLERROR shall only follow on a CALL message
893+
}
882894
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
883895
this->message_dispatcher->dispatch_call_error(call_error);
884896
} catch (json::exception& e) {
885897
EVLOG_error << "JSON exception during handling of message: " << e.what();
898+
if (enhanced_message.messageTypeId != MessageTypeId::CALL) {
899+
return; // CALLERROR shall only follow on a CALL message
900+
}
886901
if (json_message.is_array() and json_message.size() > MESSAGE_ID) {
887902
auto call_error = CallError(enhanced_message.uniqueId, "FormationViolation", e.what(), json({}));
888903
this->message_dispatcher->dispatch_call_error(call_error);

0 commit comments

Comments
 (0)