Skip to content

Commit

Permalink
Removed bypass and added group message permitted
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Dec 10, 2021
1 parent 73014ce commit 4321788
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
8 changes: 0 additions & 8 deletions src/messaging/ApplicationExchangeDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class ApplicationExchangeDispatch : public ExchangeMessageDispatch

virtual ~ApplicationExchangeDispatch() {}

CHIP_ERROR Init(SessionManager * sessionManager)
{
ReturnErrorCodeIf(sessionManager == nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mSessionManager = sessionManager;
return ExchangeMessageDispatch::Init();
}

CHIP_ERROR PrepareMessage(SessionHandle session, PayloadHeader & payloadHeader, System::PacketBufferHandle && message,
EncryptedPacketBufferHandle & preparedMessage) override;
CHIP_ERROR SendPreparedMessage(SessionHandle session, const EncryptedPacketBufferHandle & message) const override;
Expand All @@ -55,7 +48,6 @@ class ApplicationExchangeDispatch : public ExchangeMessageDispatch
bool MessagePermitted(uint16_t protocol, uint8_t type) override;

private:
SessionManager * mSessionManager = nullptr;
};

} // namespace Messaging
Expand Down
7 changes: 6 additions & 1 deletion src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,12 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload
});

// TODO : Remove this bypass for group as to perform the MessagePermitted function Issue # 12101
if (!IsGroupExchangeContext())
if (IsGroupExchangeContext())
{
ReturnErrorOnFailure(
mDispatch->OnGroupMessageReceived(messageCounter, payloadHeader, peerAddress, msgFlags, GetReliableMessageContext()));
}
else
{
ReturnErrorOnFailure(
mDispatch->OnMessageReceived(messageCounter, payloadHeader, peerAddress, msgFlags, GetReliableMessageContext()));
Expand Down
33 changes: 33 additions & 0 deletions src/messaging/ExchangeMessageDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <messaging/ExchangeMessageDispatch.h>
#include <messaging/ReliableMessageContext.h>
#include <messaging/ReliableMessageMgr.h>
#include <protocols/interaction_model/Constants.h>
#include <protocols/secure_channel/Constants.h>

namespace chip {
Expand Down Expand Up @@ -138,5 +139,37 @@ CHIP_ERROR ExchangeMessageDispatch::OnMessageReceived(uint32_t messageCounter, c
return CHIP_NO_ERROR;
}

CHIP_ERROR ExchangeMessageDispatch::OnGroupMessageReceived(uint32_t messageCounter, const PayloadHeader & payloadHeader,
const Transport::PeerAddress & peerAddress, MessageFlags msgFlags,
ReliableMessageContext * reliableMessageContext)
{
ReturnErrorCodeIf(!GroupMessagePermitted(payloadHeader.GetProtocolID().GetProtocolId(), payloadHeader.GetMessageType()),
CHIP_ERROR_INVALID_ARGUMENT);

return CHIP_NO_ERROR;
}

bool ExchangeMessageDispatch::GroupMessagePermitted(uint16_t protocol, uint8_t type)
{
switch (protocol)
{
case Protocols::InteractionModel::Id.GetProtocolId():
switch (type)
{
case static_cast<uint8_t>(Protocols::InteractionModel::MsgType::WriteRequest):
case static_cast<uint8_t>(Protocols::InteractionModel::MsgType::InvokeCommandRequest):
return true;

default:
break;
}
break;

default:
break;
}
return false;
}

} // namespace Messaging
} // namespace chip
15 changes: 14 additions & 1 deletion src/messaging/ExchangeMessageDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class ExchangeMessageDispatch : public ReferenceCounted<ExchangeMessageDispatch>
ExchangeMessageDispatch() {}
virtual ~ExchangeMessageDispatch() {}

CHIP_ERROR Init() { return CHIP_NO_ERROR; }
CHIP_ERROR Init(SessionManager * sessionManager)
{
ReturnErrorCodeIf(sessionManager == nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mSessionManager = sessionManager;

return CHIP_NO_ERROR;
}

virtual bool IsEncryptionRequired() const { return true; }

Expand All @@ -64,11 +70,18 @@ class ExchangeMessageDispatch : public ReferenceCounted<ExchangeMessageDispatch>
const Transport::PeerAddress & peerAddress, MessageFlags msgFlags,
ReliableMessageContext * reliableMessageContext);

virtual CHIP_ERROR OnGroupMessageReceived(uint32_t messageCounter, const PayloadHeader & payloadHeader,
const Transport::PeerAddress & peerAddress, MessageFlags msgFlags,
ReliableMessageContext * reliableMessageContext);

protected:
virtual bool MessagePermitted(uint16_t protocol, uint8_t type) = 0;
virtual bool GroupMessagePermitted(uint16_t protocol, uint8_t type);

// TODO: remove IsReliableTransmissionAllowed, this function should be provided over session.
virtual bool IsReliableTransmissionAllowed() const { return true; }

SessionManager * mSessionManager = nullptr;
};

} // namespace Messaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class SessionEstablishmentExchangeDispatch : public Messaging::ExchangeMessageDi

virtual ~SessionEstablishmentExchangeDispatch() {}

CHIP_ERROR Init(SessionManager * sessionManager)
{
ReturnErrorCodeIf(sessionManager == nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mSessionManager = sessionManager;
return ExchangeMessageDispatch::Init();
}

CHIP_ERROR PrepareMessage(SessionHandle session, PayloadHeader & payloadHeader, System::PacketBufferHandle && message,
EncryptedPacketBufferHandle & out) override;
CHIP_ERROR SendPreparedMessage(SessionHandle session, const EncryptedPacketBufferHandle & preparedMessage) const override;
Expand All @@ -57,7 +50,6 @@ class SessionEstablishmentExchangeDispatch : public Messaging::ExchangeMessageDi
bool IsEncryptionRequired() const override { return false; }

private:
SessionManager * mSessionManager = nullptr;
};

} // namespace chip

0 comments on commit 4321788

Please sign in to comment.