Skip to content

Commit

Permalink
comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemyslaw Bida committed May 12, 2024
1 parent 2e0fa63 commit e65b42a
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 256 deletions.
2 changes: 1 addition & 1 deletion examples/platforms/simulation/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ otError otPlatBleGapAdvSetData(otInstance *aInstance, uint8_t *aAdvertisementDat
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aAdvertisementData);
OT_UNUSED_VARIABLE(aAdvertisementLen);
return OT_ERROR_NOT_IMPLEMENTED;
return OT_ERROR_NONE;
}
2 changes: 1 addition & 1 deletion include/openthread/ble_secure.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ otError otBleSecureStart(otInstance *aInstance,
* @retval OT_ERROR_NONE Successfully set value.
* @retval OT_ERROR_INVALID_ARGS Value not set.
*/
otError otBleTcatSetVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo);
otError otBleSecureSetTcatVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo);

/**
* Enables the TCAT protocol over BLE Secure.
Expand Down
7 changes: 2 additions & 5 deletions include/openthread/platform/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,8 @@ otError otPlatBleDisable(otInstance *aInstance);
***************************************************************************/

/**
* Starts BLE Advertising procedure.
* Sets BLE Advertising data.
*
* The BLE device shall use undirected advertising with no filter applied.
* A single BLE Advertising packet must be sent on all advertising
* channels (37, 38 and 39).
*
* @note This function shall be used only for BLE Peripheral role.
*
Expand All @@ -184,7 +181,7 @@ otError otPlatBleDisable(otInstance *aInstance);
*
* @retval OT_ERROR_NONE Advertising procedure has been started.
* @retval OT_ERROR_INVALID_STATE BLE Device is in invalid state.
* @retval OT_ERROR_INVALID_ARGS Invalid interval value has been supplied.
* @retval OT_ERROR_INVALID_ARGS Invalid value has been supplied.
*
*/
otError otPlatBleGapAdvSetData(otInstance *aInstance, uint8_t *aAdvertisementData, uint16_t aAdvertisementLen);
Expand Down
39 changes: 23 additions & 16 deletions include/openthread/tcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ extern "C" {
15 ///< Maximum string length of a UDP or TCP service name (does not include null char).

#define OT_TCAT_ADVERTISEMENT_MAX_LEN 29 ///< Maximum length of TCAT advertisement.
#define OT_TCAT_VERSION 0x5 ///< TCAT version number.
#define OT_TCAT_OPCODE 0x2 ///< TCAT Operation Code.
#define OT_TCAT_MAX_VENDORID_SIZE 6 ///< TCAT max size of vendor ID including null as termination.
#define OT_TCAT_OPCODE 0x2 ///< TCAT Advertisement Operation Code.
#define OT_TCAT_MAX_VENDORID_SIZE 5 ///< TCAT max size of vendor ID including null as termination.

/**
* Represents TCAT status code.
Expand Down Expand Up @@ -123,12 +122,20 @@ typedef enum otTcatCommandClass
typedef enum otTcatDeviceIdType
{
OT_TCAT_DEVICE_ID_EMPTY = 0, ///< Vendor device ID type not set
OT_TCAT_DEVICE_ID_OUI24 = 1, ///< Vendor device ID type OUI24
OT_TCAT_DEVICE_ID_OUI36 = 2, ///< Vendor device ID type OUI36
OT_TCAT_DEVICE_ID_DISCRIMINATOR = 3, ///< Vendor device ID type Discriminator
OT_TCAT_DEVICE_ID_OUI24 = 1, ///< Vendor device ID type IEEE OUI-24
OT_TCAT_DEVICE_ID_OUI36 = 2, ///< Vendor device ID type IEEE OUI-36
OT_TCAT_DEVICE_ID_DISCRIMINATOR = 3, ///< Vendor device ID type Device Discriminator
OT_TCAT_DEVICE_ID_IANAPEN = 4, ///< Vendor device ID type IANA PEN
OT_TCAT_DEVICE_ID_MAX = 5, ///< Vendor device ID type size
} otTcatDeviceIdType;

typedef struct otTcatDeviceId
{
otTcatDeviceIdType mDeviceIdType;
uint16_t mDeviceIdLen;
uint8_t mDeviceId[OT_TCAT_MAX_VENDORID_SIZE];
} otTcatDeviceId;

/**
* This structure represents a TCAT vendor information.
*
Expand All @@ -137,16 +144,16 @@ typedef enum otTcatDeviceIdType
*/
typedef struct otTcatVendorInfo
{
const char *mProvisioningUrl; ///< Provisioning URL path string
const char *mVendorName; ///< Vendor name string
const char *mVendorModel; ///< Vendor model string
const char *mVendorSwVersion; ///< Vendor software version string
const char *mVendorData; ///< Vendor specific data string
const char *mPskdString; ///< Vendor managed pre-shared key for device
const char *mInstallCode; ///< Vendor managed install code string
const char *mDeviceId; ///< Vendor managed device ID string (if NULL: device ID is set to EUI-64 in binary format)
otTcatDeviceIdType mDeviceIdType; ///< Vendor managed device id type

const char *mProvisioningUrl; ///< Provisioning URL path string
const char *mVendorName; ///< Vendor name string
const char *mVendorModel; ///< Vendor model string
const char *mVendorSwVersion; ///< Vendor software version string
const char *mVendorData; ///< Vendor specific data string
const char *mPskdString; ///< Vendor managed pre-shared key for device
const char *mInstallCode; ///< Vendor managed install code string
const otTcatDeviceId *mDeviceIds; /** Vendor managed device ID array.
(if NULL: device ID is set to EUI-64 in binary format)
Array is terminated like C string with OT_TCAT_DEVICE_ID_EMPTY */
} otTcatVendorInfo;

/**
Expand Down
57 changes: 38 additions & 19 deletions src/cli/cli_tcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ namespace ot {

namespace Cli {

otTcatVendorInfo sVendorInfo;
const char kPskdVendor[] = "J01NM3";
const char kUrl[] = "dummy_url";
static char sVendorId[OT_TCAT_MAX_VENDORID_SIZE];
otTcatDeviceId sVendorDeviceIds[OT_TCAT_DEVICE_ID_MAX];

const char kPskdVendor[] = "JJJJJJ";
const char kUrl[] = "dummy_url";

static void HandleBleSecureReceive(otInstance *aInstance,
const otMessage *aMessage,
Expand Down Expand Up @@ -115,14 +115,23 @@ static void HandleBleSecureReceive(otInstance *aInstance,

template <> otError Tcat::Process<Cmd("vendorid")>(Arg aArgs[])
{
otError error = OT_ERROR_NONE;
otError error = OT_ERROR_NONE;
otTcatDeviceId devId;
static const char *const kVendorIdTypes[] = {"empty", "oui24", "oui36", "discriminator", "ianapen"};

mVendorInfo.mDeviceIds = sVendorDeviceIds;

if (aArgs[0].IsEmpty())
{
if (sVendorInfo.mDeviceId != nullptr)
if (mVendorInfo.mDeviceIds[0].mDeviceIdType != OT_TCAT_DEVICE_ID_EMPTY)
{
OutputLine("type %s, value: %s", kVendorIdTypes[sVendorInfo.mDeviceIdType], sVendorInfo.mDeviceId);
OutputLine("Set vendorIds:");
for (size_t i = 0; mVendorInfo.mDeviceIds[i].mDeviceIdType != OT_TCAT_DEVICE_ID_EMPTY; i++)
{
OutputFormat("type %s, value: ", kVendorIdTypes[mVendorInfo.mDeviceIds[i].mDeviceIdType]);
OutputBytesLine((uint8_t *)mVendorInfo.mDeviceIds[i].mDeviceId,
(uint16_t)mVendorInfo.mDeviceIds[i].mDeviceIdLen);
}
}
else
{
Expand All @@ -133,40 +142,50 @@ template <> otError Tcat::Process<Cmd("vendorid")>(Arg aArgs[])

if (aArgs[0] == kVendorIdTypes[OT_TCAT_DEVICE_ID_OUI24])
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_OUI24;
devId.mDeviceIdType = OT_TCAT_DEVICE_ID_OUI24;
}
else if (aArgs[0] == kVendorIdTypes[OT_TCAT_DEVICE_ID_OUI36])
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_OUI36;
devId.mDeviceIdType = OT_TCAT_DEVICE_ID_OUI36;
}
else if (aArgs[0] == kVendorIdTypes[OT_TCAT_DEVICE_ID_DISCRIMINATOR])
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_DISCRIMINATOR;
devId.mDeviceIdType = OT_TCAT_DEVICE_ID_DISCRIMINATOR;
}
else if (aArgs[0] == kVendorIdTypes[OT_TCAT_DEVICE_ID_IANAPEN])
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_IANAPEN;
devId.mDeviceIdType = OT_TCAT_DEVICE_ID_IANAPEN;
}
else if (aArgs[0] == kVendorIdTypes[OT_TCAT_DEVICE_ID_EMPTY])
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_EMPTY;
sVendorInfo.mDeviceId = nullptr;
for (auto &vendorDeviceId : sVendorDeviceIds)
{
vendorDeviceId.mDeviceIdType = OT_TCAT_DEVICE_ID_EMPTY;
vendorDeviceId.mDeviceIdLen = 0;
}
ExitNow();
}
else
{
ExitNow(error = OT_ERROR_INVALID_ARGS);
}

if (aArgs[1].GetLength() < (OT_TCAT_MAX_VENDORID_SIZE) && !aArgs[1].IsEmpty())
if (!aArgs[1].IsEmpty() && aArgs[1].GetLength() < (OT_TCAT_MAX_VENDORID_SIZE * 2 + 1))
{
strcpy(sVendorId, aArgs[1].GetCString());
sVendorInfo.mDeviceId = sVendorId;
devId.mDeviceIdLen = OT_TCAT_MAX_VENDORID_SIZE;
SuccessOrExit(error = aArgs[1].ParseAsHexString(devId.mDeviceIdLen, devId.mDeviceId));
for (auto &vendorDeviceId : sVendorDeviceIds)
{
if (vendorDeviceId.mDeviceIdType == devId.mDeviceIdType ||
vendorDeviceId.mDeviceIdType == OT_TCAT_DEVICE_ID_EMPTY)
{
vendorDeviceId = devId;
break;
}
}
}
else
{
sVendorInfo.mDeviceIdType = OT_TCAT_DEVICE_ID_EMPTY;
sVendorInfo.mDeviceId = nullptr;
ExitNow(error = OT_ERROR_INVALID_ARGS);
}
exit:
Expand All @@ -193,7 +212,7 @@ template <> otError Tcat::Process<Cmd("start")>(Arg aArgs[])

otBleSecureSetSslAuthMode(GetInstancePtr(), true);

SuccessOrExit(error = otBleTcatSetVendorInfo(GetInstancePtr(), &sVendorInfo));
SuccessOrExit(error = otBleSecureSetTcatVendorInfo(GetInstancePtr(), &mVendorInfo));
SuccessOrExit(error = otBleSecureStart(GetInstancePtr(), nullptr, HandleBleSecureReceive, true, nullptr));
SuccessOrExit(error = otBleSecureTcatStart(GetInstancePtr(), nullptr));

Expand Down
2 changes: 1 addition & 1 deletion src/core/api/ble_secure_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ otError otBleSecureStart(otInstance *aInstance,
return AsCoreType(aInstance).Get<Ble::BleSecure>().Start(aConnectHandler, aReceiveHandler, aTlvMode, aContext);
}

otError otBleTcatSetVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo)
otError otBleSecureSetTcatVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo)
{
return AsCoreType(aInstance).Get<Ble::BleSecure>().TcatSetVendorInfo(AsCoreType(aVendorInfo));
}
Expand Down
1 change: 1 addition & 0 deletions src/core/meshcop/meshcop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include "meshcop.hpp"
#include <openthread/platform/toolchain.h>

#include "common/clearable.hpp"
#include "common/crc16.hpp"
Expand Down
82 changes: 53 additions & 29 deletions src/core/meshcop/tcat_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "tcat_agent.hpp"
#include <openthread/tcat.h>
#include "common/as_core_type.hpp"
#include "common/error.hpp"
#include "common/message.hpp"
Expand Down Expand Up @@ -455,7 +456,7 @@ Error TcatAgent::HandleSingleTlv(const Message &aIncommingMessage, Message &aOut
break;
}

SuccessOrExit(error = ot::Tlv::Append<ResponseWithStatusCommandTlv>(aOutgoingMessage, statusCode));
SuccessOrExit(error = ot::Tlv::Append<ResponseWithStatusTlv>(aOutgoingMessage, statusCode));
}

exit:
Expand Down Expand Up @@ -504,42 +505,67 @@ Error TcatAgent::HandleStartThreadInterface(void)
return error;
}

void SeralizeTcatAdvertisementTlv(uint8_t *aBuffer,
uint16_t &aOffset,
TcatAdvertisementTlvType aType,
uint8_t aLength,
const uint8_t *aValue)
{
aBuffer[aOffset++] = aType << 4 | (aLength & 0xf);
memcpy(aBuffer + aOffset, aValue, aLength);
aOffset += aLength;
}

uint8_t *TcatAgent::GetAdvertisementData(uint16_t &aLen)
{
Message *buffer = Get<MessagePool>().Allocate(Message::kTypeBle, 0);
aLen = 0;

if (buffer == nullptr || mVendorInfo == nullptr)
if (mVendorInfo == nullptr)
{
aLen = 0;
return nullptr;
}

*reinterpret_cast<uint16_t *>(mAdvertisement) = LittleEndian::HostSwap16(OT_TOBLE_SERVICE_UUID);
mAdvertisement[2] = OT_TCAT_VERSION << 4 | OT_TCAT_OPCODE;

IgnoreError(buffer->AppendBytes(mAdvertisement, 3));
aLen += sizeof(uint16_t);
mAdvertisement[2] = OPENTHREAD_CONFIG_THREAD_VERSION << 4 | OT_TCAT_OPCODE;
aLen++;

switch (MapEnum(mVendorInfo->mDeviceIdType))
if (mVendorInfo->mDeviceIds != nullptr)
{
case kTcatDeviceIdOui24:
IgnoreError(ot::Tlv::Append<VendorOuiTlv24>(*buffer, mVendorInfo->mDeviceId));
break;
case kTcatDeviceIdOui36:
IgnoreError(ot::Tlv::Append<VendorOuiTlv36>(*buffer, mVendorInfo->mDeviceId));
break;
case kTcatDeviceIdDiscriminator:
IgnoreError(ot::Tlv::Append<DeviceDiscriminatorTlv>(*buffer, mVendorInfo->mDeviceId));
break;
case kTcatDeviceIdIanaPen:
IgnoreError(ot::Tlv::Append<VendorIanaPenTlv>(*buffer, mVendorInfo->mDeviceId));
break;
default:
break;
for (uint8_t i = 0; mVendorInfo->mDeviceIds[i].mDeviceIdType != OT_TCAT_DEVICE_ID_EMPTY; i++)
{
switch (MapEnum(mVendorInfo->mDeviceIds[i].mDeviceIdType))
{
case kTcatDeviceIdOui24:
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvVendorOui24,
mVendorInfo->mDeviceIds[i].mDeviceIdLen,
mVendorInfo->mDeviceIds[i].mDeviceId);
break;
case kTcatDeviceIdOui36:
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvVendorOui36,
mVendorInfo->mDeviceIds[i].mDeviceIdLen,
mVendorInfo->mDeviceIds[i].mDeviceId);
break;
case kTcatDeviceIdDiscriminator:
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvDeviceDiscriminator,
mVendorInfo->mDeviceIds[i].mDeviceIdLen,
mVendorInfo->mDeviceIds[i].mDeviceId);
break;
case kTcatDeviceIdIanaPen:
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvVendorIanaPen,
mVendorInfo->mDeviceIds[i].mDeviceIdLen,
mVendorInfo->mDeviceIds[i].mDeviceId);
break;
default:
break;
}
}
}

otBleLinkCapabilities caps = otPlatGetBleLinkCapabilities(&GetInstance());

IgnoreError(ot::Tlv::Append<BleLinkCapabilitiesTlv>(*buffer, *reinterpret_cast<uint8_t *>(&caps)));
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvBleLinkCapabilities, kTlvBleLinkCapabilitiesLength,
reinterpret_cast<uint8_t *>(&caps));

DeviceTypeAndStatus tas;
tas.mRsv = 0;
Expand All @@ -548,19 +574,17 @@ uint8_t *TcatAgent::GetAdvertisementData(uint16_t &aLen)
tas.mDeviceType = Get<Mle::Mle>().GetDeviceMode().IsFullThreadDevice();
tas.mRxOnWhenIdle = Get<Mle::Mle>().GetDeviceMode().IsRxOnWhenIdle();

#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE || OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE)
#if OPENTHREAD_FTD && (OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE || OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE || \
OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE)
tas.mIsBorderRouter = true;
#else
tas.mIsBorderRouter = false;
#endif

IgnoreError(ot::Tlv::Append<DeviceTypeAndStatusTlv>(*buffer, *reinterpret_cast<uint8_t *>(&tas)));

aLen = buffer->GetLength();
SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvDeviceTypeAndStatus, kTlvDeviceTypeAndStatusLength,
reinterpret_cast<uint8_t *>(&tas));
OT_ASSERT(mAdvertisementLength <= OT_TCAT_ADVERTISEMENT_MAX_LEN);

buffer->ReadBytes(0, mAdvertisement, aLen);
buffer->Free();
return mAdvertisement;
}

Expand Down
Loading

0 comments on commit e65b42a

Please sign in to comment.