Skip to content

Commit

Permalink
Addressing tcat_agent comments next batch
Browse files Browse the repository at this point in the history
  • Loading branch information
canisLupus1313 committed Aug 17, 2023
1 parent c687692 commit ebf8b13
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 91 deletions.
89 changes: 29 additions & 60 deletions src/core/meshcop/tcat_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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<ActiveDatasetManager>().IsCommissioned();
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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:
Expand All @@ -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;
Expand Down
63 changes: 35 additions & 28 deletions src/core/meshcop/tcat_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/radio/ble_secure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ble::BleSecure>().HandleBleReceive(aPacket->mValue, aPacket->mLength);
exit:
return;
}

void otPlatBleGapOnConnected(otInstance *aInstance, uint16_t aConnectionId)
Expand Down

0 comments on commit ebf8b13

Please sign in to comment.