From ebf8b13b10a3c9147cfb2f66d3b8a170cced8be2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Thu, 17 Aug 2023 15:19:37 +0200 Subject: [PATCH] Addressing tcat_agent comments next batch --- src/core/meshcop/tcat_agent.cpp | 89 +++++++++++---------------------- src/core/meshcop/tcat_agent.hpp | 63 ++++++++++++----------- src/core/radio/ble_secure.cpp | 6 +-- 3 files changed, 67 insertions(+), 91 deletions(-) diff --git a/src/core/meshcop/tcat_agent.cpp b/src/core/meshcop/tcat_agent.cpp index 53df04ea64d..cc6fcfa3c9b 100644 --- a/src/core/meshcop/tcat_agent.cpp +++ b/src/core/meshcop/tcat_agent.cpp @@ -56,19 +56,13 @@ RegisterLogModule("TcatAgent"); bool TcatAgent::VendorInfo::IsValid(void) const { - if (mProvisioningUrl != nullptr && !IsValidUtf8String(mProvisioningUrl)) - return false; - - if (mPskdString == nullptr) - return false; - - return true; + return mProvisioningUrl == nullptr || IsValidUtf8String(mProvisioningUrl) || mPskdString != nullptr; } TcatAgent::TcatAgent(Instance &aInstance) : InstanceLocator(aInstance) , mVendorInfo(nullptr) - , mCurrentApplicationLayer(OT_TCAT_MESSAGE_TYPE_NONE) + , mCurrentApplicationLayer(kMessageTypeNone) , mState(kStateDisabled) , mAlreadyCommissioned(false) , mCommissionerHasNetworkName(false) @@ -95,7 +89,7 @@ Error TcatAgent::Start(const TcatAgent::VendorInfo &aVendorInfo, mJoinCallback.Set(aHandler, aContext); mVendorInfo = &aVendorInfo; - mCurrentApplicationLayer = OT_TCAT_MESSAGE_TYPE_NONE; + mCurrentApplicationLayer = kMessageTypeNone; mState = kStateEnabled; mAlreadyCommissioned = false; @@ -106,7 +100,7 @@ Error TcatAgent::Start(const TcatAgent::VendorInfo &aVendorInfo, void TcatAgent::Stop(void) { - mCurrentApplicationLayer = OT_TCAT_MESSAGE_TYPE_NONE; + mCurrentApplicationLayer = kMessageTypeNone; mState = kStateDisabled; mAlreadyCommissioned = false; mAppDataReceiveCallback.Clear(); @@ -162,7 +156,7 @@ Error TcatAgent::Connected(MeshCoP::Dtls &aTlsContext) } } - mCurrentApplicationLayer = OT_TCAT_MESSAGE_TYPE_NONE; + mCurrentApplicationLayer = kMessageTypeNone; mCurrentServiceName[0] = 0; mState = kStateConnected; mAlreadyCommissioned = Get().IsCommissioned(); @@ -174,7 +168,7 @@ Error TcatAgent::Connected(MeshCoP::Dtls &aTlsContext) void TcatAgent::Disconnected(void) { - mCurrentApplicationLayer = OT_TCAT_MESSAGE_TYPE_NONE; + mCurrentApplicationLayer = kMessageTypeNone; mAlreadyCommissioned = false; if (mState != kStateDisabled) @@ -331,7 +325,7 @@ bool TcatAgent::IsCommandClassAuthorized(CommandClass aCommandClass) const return authorized; } -Error TcatAgent::HandleSingleTlv(ot::Message &aIncommingMessage, ot::Message &aOutgoingMessage) +Error TcatAgent::HandleSingleTlv(const Message &aIncommingMessage, Message &aOutgoingMessage) { Error error = kErrorParse; ot::Tlv tlv; @@ -369,7 +363,7 @@ Error TcatAgent::HandleSingleTlv(ot::Message &aIncommingMessage, ot::Message &aO } else { - error = HandleCCM(aIncommingMessage, aOutgoingMessage, tlv.GetType(), offset, lenght, response); + error = kErrorInvalidCommand; } if (!response) @@ -418,12 +412,12 @@ Error TcatAgent::HandleSingleTlv(ot::Message &aIncommingMessage, ot::Message &aO return error; } -Error TcatAgent::HandleGeneral(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse) +Error TcatAgent::HandleGeneral(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse) { Error error = kErrorNone; @@ -446,12 +440,12 @@ Error TcatAgent::HandleGeneral(ot::Message &aIncommingMessage, return error; } -Error TcatAgent::HandleCommissioning(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse) +Error TcatAgent::HandleCommissioning(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse) { Error error = kErrorNone; @@ -492,12 +486,12 @@ Error TcatAgent::HandleCommissioning(ot::Message &aIncommingMessage, return error; } -Error TcatAgent::HandleApplication(const ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse) +Error TcatAgent::HandleApplication(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse) { Error error = kErrorNone; @@ -516,8 +510,8 @@ Error TcatAgent::HandleApplication(const ot::Message &aIncommingMessage, { case kSendApplicationData: LogInfo("Application data len:%d, offset:%d", aLength, aOffset); - mAppDataReceiveCallback.InvokeIfSet(&GetInstance(), &aIncommingMessage, aOffset, mCurrentApplicationLayer, - mCurrentServiceName); + mAppDataReceiveCallback.InvokeIfSet(&GetInstance(), &aIncommingMessage, aOffset, + MapEnum(mCurrentApplicationLayer), mCurrentServiceName); break; default: @@ -528,32 +522,7 @@ Error TcatAgent::HandleApplication(const ot::Message &aIncommingMessage, return error; } -Error TcatAgent::HandleCCM(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse) -{ - Error error = kErrorNone; - - OT_UNUSED_VARIABLE(aIncommingMessage); - OT_UNUSED_VARIABLE(aOutgoingMessage); - OT_UNUSED_VARIABLE(aOffset); - OT_UNUSED_VARIABLE(aLength); - OT_UNUSED_VARIABLE(aHasResponse); - - switch (aTlvType) - { - default: - error = kErrorInvalidCommand; - } - - // exit: - return error; -} - -Error TcatAgent::HandleSetActiveOperationalDataset(ot::Message &aIncommingMessage, uint32_t aOffset, uint32_t aLength) +Error TcatAgent::HandleSetActiveOperationalDataset(Message &aIncommingMessage, uint32_t aOffset, uint32_t aLength) { Dataset dataset; otOperationalDatasetTlvs datasetTlvs; diff --git a/src/core/meshcop/tcat_agent.hpp b/src/core/meshcop/tcat_agent.hpp index d57e779c9ff..71b6adb6362 100644 --- a/src/core/meshcop/tcat_agent.hpp +++ b/src/core/meshcop/tcat_agent.hpp @@ -219,7 +219,20 @@ class TcatAgent : public InstanceLocator, private NonCopyable * Represents TCAT message type. * */ - typedef otTcatMessageType TcatMessageType; + enum TcatMessageType : uint8_t + { + kMessageTypeNone = OT_TCAT_MESSAGE_TYPE_NONE, ///< Message which has been sent without activating the TCAT agent + kMessageTypeStatus = + OT_TCAT_MESSAGE_TYPE_STATUS, ///< Message containing a status code (byte) as defined in otTcatStatusCode + kMessageTypeUdp = OT_TCAT_MESSAGE_TYPE_UDP, ///< Message directed to a UDP service + kMessageTypeTcp = OT_TCAT_MESSAGE_TYPE_TCP, ///< Message directed to a TCP service + kMessageTypeChangedUdpService = + OT_TCAT_MESSAGE_TYPE_CHANGED_TO_UDP_SERVICE, ///< Client has changed to a UDP service + kMessageTypeChangedTcpService = + OT_TCAT_MESSAGE_TYPE_CHANGED_TO_TCP_SERVICE, ///< Client has changed to a TCP service + }; + + DefineMapEnum(otTcatMessageType, TcatAgent::TcatMessageType); /** * Represents TCAT status. @@ -324,35 +337,29 @@ class TcatAgent : public InstanceLocator, private NonCopyable * @retval kErrorAbort The incoming message was a request for terminating the TCAT link. * */ - Error HandleSingleTlv(ot::Message &aIncommingMessage, ot::Message &aOutgoingMessage); + Error HandleSingleTlv(const Message &aIncommingMessage, Message &aOutgoingMessage); private: - Error HandleGeneral(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse); - Error HandleCommissioning(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse); - Error HandleApplication(const ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse); - Error HandleCCM(ot::Message &aIncommingMessage, - ot::Message &aOutgoingMessage, - uint8_t aTlvType, - uint32_t aOffset, - uint32_t aLength, - bool &aHasResponse); - - Error HandleSetActiveOperationalDataset(ot::Message &aIncommingMessage, uint32_t aOffset, uint32_t aLength); + Error HandleGeneral(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse); + Error HandleCommissioning(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse); + Error HandleApplication(const Message &aIncommingMessage, + Message &aOutgoingMessage, + uint8_t aTlvType, + uint32_t aOffset, + uint32_t aLength, + bool &aHasResponse); + + Error HandleSetActiveOperationalDataset(Message &aIncommingMessage, uint32_t aOffset, uint32_t aLength); Error HandleStartThreadInterface(void); static constexpr uint16_t kJoinerUdpPort = OPENTHREAD_CONFIG_JOINER_UDP_PORT; diff --git a/src/core/radio/ble_secure.cpp b/src/core/radio/ble_secure.cpp index 3957f28b401..fcd25b49392 100644 --- a/src/core/radio/ble_secure.cpp +++ b/src/core/radio/ble_secure.cpp @@ -517,10 +517,10 @@ void otPlatBleGattServerOnWriteRequest(otInstance *aInstance, uint16_t aHandle, { OT_UNUSED_VARIABLE(aHandle); // Only a single handle is expected for RX - if (aPacket == NULL) - return; - + VerifyOrExit(aPacket == NULL); AsCoreType(aInstance).Get().HandleBleReceive(aPacket->mValue, aPacket->mLength); +exit: + return; } void otPlatBleGapOnConnected(otInstance *aInstance, uint16_t aConnectionId)