Skip to content

Commit

Permalink
Implemented a check of the enhanced_message to handle in message_call…
Browse files Browse the repository at this point in the history
…back so that only send CALLERROR on CALL messages

Signed-off-by: Piet Gömpel <[email protected]>
  • Loading branch information
Pietfried committed Feb 25, 2025
1 parent 04059e2 commit a37e8e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<CiString<255>>(message),
Expand Down
15 changes: 15 additions & 0 deletions lib/ocpp/v2/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a37e8e6

Please sign in to comment.