From fc8db3539fe5ec456ea4cc48d7b3a0739b9c45ab Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Sat, 11 May 2024 15:35:16 +0200 Subject: [PATCH] comment fixes --- examples/platforms/simulation/ble.c | 2 +- include/openthread/ble_secure.h | 2 +- include/openthread/platform/ble.h | 7 +- include/openthread/tcat.h | 39 ++-- src/cli/cli_tcat.cpp | 57 +++-- src/core/api/ble_secure_api.cpp | 2 +- src/core/meshcop/meshcop.cpp | 1 + src/core/meshcop/tcat_agent.cpp | 92 ++++---- src/core/meshcop/tcat_agent.hpp | 197 ++---------------- src/posix/platform/ble.cpp | 15 ++ .../scripts/expect/cli-tcat-advertisement.exp | 75 +++++++ tests/unit/test_platform.cpp | 2 +- tests/unit/test_tcat.cpp | 5 +- 13 files changed, 230 insertions(+), 266 deletions(-) create mode 100755 tests/scripts/expect/cli-tcat-advertisement.exp diff --git a/examples/platforms/simulation/ble.c b/examples/platforms/simulation/ble.c index 2f4e39357eb0..5d42053d23f5 100644 --- a/examples/platforms/simulation/ble.c +++ b/examples/platforms/simulation/ble.c @@ -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; } diff --git a/include/openthread/ble_secure.h b/include/openthread/ble_secure.h index 180de6274114..ca0e8706f247 100644 --- a/include/openthread/ble_secure.h +++ b/include/openthread/ble_secure.h @@ -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. diff --git a/include/openthread/platform/ble.h b/include/openthread/platform/ble.h index ff6449505713..97bbf7143f7e 100644 --- a/include/openthread/platform/ble.h +++ b/include/openthread/platform/ble.h @@ -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. * @@ -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); diff --git a/include/openthread/tcat.h b/include/openthread/tcat.h index 8ea0c2cc6d09..137336219e4c 100644 --- a/include/openthread/tcat.h +++ b/include/openthread/tcat.h @@ -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. @@ -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. * @@ -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; /** diff --git a/src/cli/cli_tcat.cpp b/src/cli/cli_tcat.cpp index dde61911df21..8f864eff0bdc 100644 --- a/src/cli/cli_tcat.cpp +++ b/src/cli/cli_tcat.cpp @@ -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, @@ -115,14 +115,23 @@ static void HandleBleSecureReceive(otInstance *aInstance, template <> otError Tcat::Process(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 { @@ -133,24 +142,27 @@ template <> otError Tcat::Process(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 @@ -158,15 +170,22 @@ template <> otError Tcat::Process(Arg aArgs[]) 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: @@ -193,7 +212,7 @@ template <> otError Tcat::Process(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)); diff --git a/src/core/api/ble_secure_api.cpp b/src/core/api/ble_secure_api.cpp index 5399bc85e504..7130f6fc625c 100644 --- a/src/core/api/ble_secure_api.cpp +++ b/src/core/api/ble_secure_api.cpp @@ -55,7 +55,7 @@ otError otBleSecureStart(otInstance *aInstance, return AsCoreType(aInstance).Get().Start(aConnectHandler, aReceiveHandler, aTlvMode, aContext); } -otError otBleTcatSetVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo) +otError otBleSecureSetTcatVendorInfo(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo) { return AsCoreType(aInstance).Get().TcatSetVendorInfo(AsCoreType(aVendorInfo)); } diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index 8bce745829a7..3426e02c3bc1 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -33,6 +33,7 @@ */ #include "meshcop.hpp" +#include #include "common/clearable.hpp" #include "common/crc16.hpp" diff --git a/src/core/meshcop/tcat_agent.cpp b/src/core/meshcop/tcat_agent.cpp index ae73af42907b..1c35847f4249 100644 --- a/src/core/meshcop/tcat_agent.cpp +++ b/src/core/meshcop/tcat_agent.cpp @@ -32,6 +32,7 @@ */ #include "tcat_agent.hpp" +#include #include "common/as_core_type.hpp" #include "common/error.hpp" #include "common/message.hpp" @@ -455,7 +456,7 @@ Error TcatAgent::HandleSingleTlv(const Message &aIncommingMessage, Message &aOut break; } - SuccessOrExit(error = ot::Tlv::Append(aOutgoingMessage, statusCode)); + SuccessOrExit(error = ot::Tlv::Append(aOutgoingMessage, statusCode)); } exit: @@ -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().Allocate(Message::kTypeBle, 0); + aLen = 0; - if (buffer == nullptr || mVendorInfo == nullptr) + if (mVendorInfo == nullptr) { - aLen = 0; return nullptr; } *reinterpret_cast(mAdvertisement) = LittleEndian::HostSwap16(OT_TOBLE_SERVICE_UUID); - mAdvertisement[2] = OT_TCAT_VERSION << 4 | OT_TCAT_OPCODE; + aLen += sizeof(uint16_t); + mAdvertisement[2] = OPENTHREAD_CONFIG_THREAD_VERSION << 4 | OT_TCAT_OPCODE; + aLen++; - IgnoreError(buffer->AppendBytes(mAdvertisement, 3)); - - switch (MapEnum(mVendorInfo->mDeviceIdType)) + if (mVendorInfo->mDeviceIds != nullptr) { - case kTcatDeviceIdOui24: - IgnoreError(ot::Tlv::Append(*buffer, mVendorInfo->mDeviceId)); - break; - case kTcatDeviceIdOui36: - IgnoreError(ot::Tlv::Append(*buffer, mVendorInfo->mDeviceId)); - break; - case kTcatDeviceIdDiscriminator: - IgnoreError(ot::Tlv::Append(*buffer, mVendorInfo->mDeviceId)); - break; - case kTcatDeviceIdIanaPen: - IgnoreError(ot::Tlv::Append(*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(*buffer, *reinterpret_cast(&caps))); + SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvBleLinkCapabilities, kTlvBleLinkCapabilitiesLength, + reinterpret_cast(&caps)); DeviceTypeAndStatus tas; tas.mRsv = 0; @@ -548,32 +574,20 @@ uint8_t *TcatAgent::GetAdvertisementData(uint16_t &aLen) tas.mDeviceType = Get().GetDeviceMode().IsFullThreadDevice(); tas.mRxOnWhenIdle = Get().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(*buffer, *reinterpret_cast(&tas))); - - aLen = buffer->GetLength(); + SeralizeTcatAdvertisementTlv(mAdvertisement, aLen, kTlvDeviceTypeAndStatus, kTlvDeviceTypeAndStatusLength, + reinterpret_cast(&tas)); OT_ASSERT(mAdvertisementLength <= OT_TCAT_ADVERTISEMENT_MAX_LEN); - buffer->ReadBytes(0, mAdvertisement, aLen); - buffer->Free(); return mAdvertisement; } -#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_WARN) -void TcatAgent::LogError(const char *aActionText, Error aError) -{ - if (aError != kErrorNone) - { - LogWarn("Failed to %s: %s", aActionText, ErrorToString(aError)); - } -} -#endif - } // namespace MeshCoP } // namespace ot diff --git a/src/core/meshcop/tcat_agent.hpp b/src/core/meshcop/tcat_agent.hpp index aeb1f4d7e1ff..0e05b910b72e 100644 --- a/src/core/meshcop/tcat_agent.hpp +++ b/src/core/meshcop/tcat_agent.hpp @@ -334,7 +334,7 @@ class TcatAgent : public InstanceLocator, private NonCopyable bool IsCommandClassAuthorized(CommandClass aCommandClass) const; /** - * Indicates whether or not a command class is authorized. + * Gets TCAT advertisement data. * * @param[out] aLen Advertisement length. * @@ -390,7 +390,7 @@ DefineMapEnum(otTcatApplicationProtocol, MeshCoP::TcatAgent::TcatApplicationProt DefineMapEnum(otTcatDeviceIdType, MeshCoP::TcatAgent::TcatDeviceIdType); // Command class TLVs -typedef UintTlvInfo ResponseWithStatusCommandTlv; +typedef UintTlvInfo ResponseWithStatusTlv; /** * Represent Device Type and Status @@ -406,187 +406,22 @@ struct DeviceTypeAndStatus bool mDeviceType : 1; }; -// Advertisement TLVs +static constexpr uint8_t kTlvVendorOui24Length = 3; +static constexpr uint8_t kTlvVendorOui36Length = 5; +static constexpr uint8_t kTlvDeviceDiscriminatorLength = 5; +static constexpr uint8_t kTlvBleLinkCapabilitiesLength = 1; +static constexpr uint8_t kTlvDeviceTypeAndStatusLength = 1; +static constexpr uint8_t kTlvVendorIanaPenLength = 4; -OT_TOOL_PACKED_BEGIN -class AdvertisementTlv : public ot::Tlv +enum TcatAdvertisementTlvType : uint8_t { -public: - /** - * TCAT Advertisement TLV Types. - * - */ - enum Type : uint8_t - { - kTlvVendorOui24 = 1, ///< TCAT vendor OUI 24 - kTlvVendorOui36 = 2, ///< TCAT vendor OUI 36 - kTlvDeviceDiscriminator = 3, ///< TCAT random vendor discriminator - kTlvDeviceTypeAndStatus = 4, ///< TCAT Thread device type and status - kTlvBleLinkCapabilities = 5, ///< TCAT BLE link capabilities of device - kTlvVendorIanaPen = 6, ///< TCAT Vendor IANA PEN - }; - - /** - * Max length of Advertisement TLVs. - * - */ - static constexpr uint8_t kTlvVendorOui24Length = 3; - static constexpr uint8_t kTlvVendorOui36Length = 5; - static constexpr uint8_t kTlvDeviceDiscriminatorLength = 5; - static constexpr uint8_t kTlvVendorIanaPenLength = 4; - - /** - * Returns the Type value. - * - * @returns The Type value. - * - */ - Type GetType(void) const { return static_cast(ot::Tlv::GetType()); } - - /** - * Sets the Type value. - * - * @param[in] aType The Type value. - * - */ - void SetType(Type aType) { ot::Tlv::SetType(static_cast(aType)); } - - /** - * Returns a pointer to the next TLV. - * - * @returns A pointer to the next TLV. - * - */ - Tlv *GetNext(void) { return As(ot::Tlv::GetNext()); } - - /** - * Returns a pointer to the next TLV. - * - * @returns A pointer to the next TLV. - * - */ - const Tlv *GetNext(void) const { return As(ot::Tlv::GetNext()); } - - /** - * Indicates whether a TLV appears to be well-formed. - * - * @param[in] aTlv A reference to the TLV. - * - * @returns TRUE if the TLV appears to be well-formed, FALSE otherwise. - * - */ - static bool IsValid(const AdvertisementTlv &aTlv); - -} OT_TOOL_PACKED_END; - -typedef StringTlvInfo VendorOuiTlv24; -typedef StringTlvInfo VendorOuiTlv36; -typedef StringTlvInfo - DeviceDiscriminatorTlv; - -/** - * Implements Device Type And Status TLV generation and parsing. - * - */ -OT_TOOL_PACKED_BEGIN -class DeviceTypeAndStatusTlv : public AdvertisementTlv, - public UintTlvInfo -{ -public: - /** - * Initializes the TLV. - * - */ - void Init(void) - { - SetType(kTlvDeviceTypeAndStatus); - SetLength(sizeof(*this) - sizeof(Tlv)); - } - - /** - * Indicates whether or not the TLV appears to be well-formed. - * - * @retval TRUE If the TLV appears to be well-formed. - * @retval FALSE If the TLV does not appear to be well-formed. - * - */ - bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } - - /** - * Returns the Device Type and Status. - * - * @returns The Device Type and Status. - * - */ - DeviceTypeAndStatus GetDeviceTypeAndStatus(void) const { return *(DeviceTypeAndStatus *)&mFlags; } - - /** - * Sets the Device Type and Status. - * - * @param[in] aDeviceTypeAndStatus The Device type and status which will be set. - * - */ - void SeyDeviceTypeAndStatus(const DeviceTypeAndStatus &aDeviceTypeAndStatus) - { - mFlags = *(uint8_t *)&aDeviceTypeAndStatus; - } - -private: - uint8_t mFlags; -} OT_TOOL_PACKED_END; - -/** - * Implements BLE Link Capabilities TLV generation and parsing. - * - */ -OT_TOOL_PACKED_BEGIN -class BleLinkCapabilitiesTlv : public AdvertisementTlv, - public UintTlvInfo -{ -public: - /** - * Initializes the TLV. - * - */ - void Init(void) - { - SetType(kTlvBleLinkCapabilities); - SetLength(sizeof(*this) - sizeof(Tlv)); - } - - /** - * Indicates whether or not the TLV appears to be well-formed. - * - * @retval TRUE If the TLV appears to be well-formed. - * @retval FALSE If the TLV does not appear to be well-formed. - * - */ - bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } - - /** - * Returns the BLE Link Capabilities. - * - * @returns The Device Type and Status. - * - */ - otBleLinkCapabilities GetBleLinkCapabilities(void) const { return *(otBleLinkCapabilities *)&mFlags; } - - /** - * Sets the Device Type and Status. - * - * @param[in] aDeviceTypeAndStatus The Security Policy which will be set. - * - */ - void SetBleLinkCapabilities(const otBleLinkCapabilities &aBleLinkCapabilities) - { - mFlags = *(uint8_t *)&aBleLinkCapabilities; - } - -private: - uint8_t mFlags; -} OT_TOOL_PACKED_END; - -typedef StringTlvInfo VendorIanaPenTlv; + kTlvVendorOui24 = 1, ///< TCAT vendor OUI 24 + kTlvVendorOui36 = 2, ///< TCAT vendor OUI 36 + kTlvDeviceDiscriminator = 3, ///< TCAT random vendor discriminator + kTlvDeviceTypeAndStatus = 4, ///< TCAT Thread device type and status + kTlvBleLinkCapabilities = 5, ///< TCAT BLE link capabilities of device + kTlvVendorIanaPen = 6, ///< TCAT Vendor IANA PEN +}; } // namespace ot diff --git a/src/posix/platform/ble.cpp b/src/posix/platform/ble.cpp index 2fe3c64535d5..629758824cc4 100644 --- a/src/posix/platform/ble.cpp +++ b/src/posix/platform/ble.cpp @@ -73,3 +73,18 @@ otError otPlatBleGattServerIndicate(otInstance *aInstance, uint16_t aHandle, con OT_UNUSED_VARIABLE(aPacket); return OT_ERROR_NOT_IMPLEMENTED; } + +otBleLinkCapabilities otPlatGetBleLinkCapabilities(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + otBleLinkCapabilities dummy = {0,0,0}; + return dummy; +} + +otError otPlatBleGapAdvSetData(otInstance *aInstance, uint8_t *aAdvertisementData, uint16_t aAdvertisementLen) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aAdvertisementData); + OT_UNUSED_VARIABLE(aAdvertisementLen); + return OT_ERROR_NONE; +} diff --git a/tests/scripts/expect/cli-tcat-advertisement.exp b/tests/scripts/expect/cli-tcat-advertisement.exp new file mode 100755 index 000000000000..37628459dea5 --- /dev/null +++ b/tests/scripts/expect/cli-tcat-advertisement.exp @@ -0,0 +1,75 @@ +#!/usr/bin/expect -f +# +# Copyright (c) 2022, The OpenThread Authors. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +source "tests/scripts/expect/_common.exp" + +spawn_node 1 "cli" + +switch_node 1 +send "tcat vendorid ianapen f378\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "type ianapen, value: f378" +expect_line "Done" + +send "tcat vendorid ianapen f378aabb\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "type ianapen, value: f378aabb" +expect_line "Done" + +send "tcat vendorid oui24 f378aa\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "type oui24, value: f378aa" +expect_line "Done" + +send "tcat vendorid oui36 f378aabbcc\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "type oui36, value: f378aabbcc" +expect_line "Done" + +send "tcat vendorid discriminator f378aabbdd\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "type discriminator, value: f378aabbdd" +expect_line "Done" + +send "tcat vendorid empty\n" +expect_line "Done" + +send "tcat vendorid\n" +expect_line "empty" +expect_line "Done" diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index 8a8f0d8c7de4..dc438d17f6a1 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -778,7 +778,7 @@ 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; } #endif // OPENTHREAD_CONFIG_BLE_TCAT_ENABLE diff --git a/tests/unit/test_tcat.cpp b/tests/unit/test_tcat.cpp index 6767a0f49f71..75afb9ab72b1 100644 --- a/tests/unit/test_tcat.cpp +++ b/tests/unit/test_tcat.cpp @@ -122,10 +122,11 @@ void TestTcat(void) otBleSecureSetSslAuthMode(instance, true); // Validate BLE secure and Tcat start APIs - VerifyOrQuit(otBleSecureTcatStart(instance, &vendorInfo, nullptr) == kErrorInvalidState); + SuccessOrQuit(otBleSecureSetTcatVendorInfo(instance, &vendorInfo)); + VerifyOrQuit(otBleSecureTcatStart(instance, nullptr) == kErrorInvalidState); SuccessOrQuit(otBleSecureStart(instance, HandleBleSecureConnect, nullptr, true, &ble)); VerifyOrQuit(otBleSecureStart(instance, HandleBleSecureConnect, nullptr, true, nullptr) == kErrorAlready); - SuccessOrQuit(otBleSecureTcatStart(instance, &vendorInfo, nullptr)); + SuccessOrQuit(otBleSecureTcatStart(instance, nullptr)); // Validate connection callbacks when platform informs that peer has connected/disconnected otPlatBleGapOnConnected(instance, kConnectionId);