Skip to content

Commit

Permalink
OpenThread PR comment resolution (August 3).
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnulf Rupp committed Aug 7, 2023
1 parent 01e545a commit ae62ad3
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 233 deletions.
16 changes: 8 additions & 8 deletions include/openthread/ble_secure.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ otError otBleSecureStart(otInstance *aInstance,
* @retval OT_ERROR_INVALID_STATE The BLE function has not been started or line mode is not selected.
*
*/
otError otBleSecureTcatStart(otInstance *aInstance, otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler);
otError otBleSecureTcatStart(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler);

/**
* Stops the BLE Secure server.
Expand Down Expand Up @@ -163,20 +163,20 @@ void otBleSecureSetPsk(otInstance *aInstance,
* @note Requires the build-time features `MBEDTLS_BASE64_C` and
* `MBEDTLS_SSL_KEEP_PEER_CERTIFICATE` to be enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[out] aPeerCert A pointer to the base64 encoded certificate buffer.
* @param[out] aCertLength The length of the base64 encoded peer certificate.
* @param[in] aCertBufferSize The buffer size of aPeerCert.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[out] aPeerCert A pointer to the base64 encoded certificate buffer.
* @param[in,out] aCertLength On input, the size the max size of @p aPeerCert.
* On output, the length of the base64 encoded peer certificate.
*
* @retval OT_ERROR_INVALID_STATE Not connected yet.
* @retval OT_ERROR_NONE Successfully get the peer certificate.
* @retval OT_ERROR_INVALID_ARGS @p aInstance or @p aCertLength is invalid.
* @retval OT_ERROR_INVALID_STATE Not connected yet.
* @retval OT_ERROR_NO_BUFS Can't allocate memory for certificate.
*
*/
otError otBleSecureGetPeerCertificateBase64(otInstance *aInstance,
unsigned char *aPeerCert,
size_t *aCertLength,
size_t aCertBufferSize);
size_t *aCertLength);

/**
* Returns an attribute value identified by its OID from the subject
Expand Down
8 changes: 8 additions & 0 deletions include/openthread/platform/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ extern "C" {

#define OT_BLE_ADV_INTERVAL_UNIT OT_BLE_TIMESLOT_UNIT

/**
* Maximum allowed ATT MTU size (must be >= 23).
*
*/

#define OT_BLE_ATT_MTU_MAX 67


/**
* Represents a BLE packet.
*
Expand Down
79 changes: 8 additions & 71 deletions include/openthread/tcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,69 +67,6 @@ extern "C" {
#define OT_TCAT_MAX_SERVICE_NAME_LENGTH \
15 ///< Maximum string length of a UDP or TCP service name (does not include null char).

/**
* Represents TCAT TLV types.
*
*/
typedef enum otTcatTlvType
{
// Command Class General
OT_TCAT_TLV_COMMAND = 0, ///< TCAT command TLV --> !!!! OBSOLETE!!!!
OT_TCAT_TLV_RESPONSE_WITH_STATUS = 1, ///< TCAT response with status value TLV
OT_TCAT_TLV_RESPONSE_WITH_PAYLOAD = 2, ///< TCAT response with payload TLV
OT_TCAT_TLV_RESPONSE_EVENT = 3, ///< TCAT response event TLV (reserved)
OT_TCAT_TLV_GET_NETWORK_NAME = 8, ///< TCAT network name query TLV
OT_TCAT_TLV_DISCONNECT = 9, ///< TCAT disconnect request TLV
OT_TCAT_TLV_PING = 10, ///< TCAT ping request TLV
OT_TCAT_TLV_GET_DEVICE_ID = 11, ///< TCAT device ID query TLV
OT_TCAT_TLV_GET_EXTENDED_PAN_ID = 12, ///< TCAT extended PAN ID query TLV
OT_TCAT_TLV_PRESENT_PSKD_HASH = 30, // 16, ///< TCAT commissioner rights elevation request TLV using PSKd hash
OT_TCAT_TLV_PRESENT_PSKC_HASH = 17, ///< TCAT commissioner rights elevation request TLV using PSKc hash
OT_TCAT_TLV_PRESENT_INSTALL_CODE_HASH =
31, // 18, ///< TCAT commissioner rights elevation request TLV using install code
OT_TCAT_TLV_REQUEST_RANDOM_NUM_CHALLENGE = 19, ///< TCAT random number challenge query TLV
OT_TCAT_TLV_REQUEST_PSKD_HASH = 20, ///< TCAT PSKd hash request TLV

// Command Class Commissioning
OT_TCAT_TLV_SET_ACTIVE_OPERATIONAL_DATASET = 16, // 32, ///< TCAT active operational dataset TLV
OT_TCAT_TLV_SET_ACTIVE_OPERATIONAL_DATASET1 = 33, ///< TCAT active operational dataset alternative #1 TLV
OT_TCAT_TLV_GET_PROVISIONING_TLVS = 36, ///< TCAT provisioning TLVs query TLV
OT_TCAT_TLV_GET_COMMISSIONER_CERTIFICATE = 37, ///< TCAT commissioner certificate query TLV
OT_TCAT_TLV_GET_DIAGNOSTIC_TLVS = 38, ///< TCAT diagnostics TLVs query TLV
OT_TCAT_TLV_START_THREAD_INTERFACE = 39, ///< TCAT start thread interface request TLV
OT_TCAT_TLV_STOP_THREAD_INTERFACE = 40, ///< TCAT stop thread interface request TLV

// Command Class Extraction
OT_TCAT_TLV_GET_ACTIVE_OPERATIONAL_DATASET = 48, ///< TCAT active oerational dataset query TLV
OT_TCAT_TLV_GET_ACTIVE_OPERATIONAL_DATASET1 = 49, ///< TCAT active oerational dataset alternative #1 query TLV

// Command Class Decommissioning
OT_TCAT_TLV_DECOMMISSION = 96, ///< TCAT decommission request TLV

// Command Class Application
OT_TCAT_TLV_SELECT_APPLICATION_LAYER_UDP = 128, ///< TCAT select UDP protocol application layer request TLV
OT_TCAT_TLV_SELECT_APPLICATION_LAYER_TCP = 129, ///< TCAT select TCP protocol application layer request TLV
OT_TCAT_TLV_SEND_APPLICATION_DATA = 18, // 130, ///< TCAT send application data TLV
OT_TCAT_TLV_SEND_VENDOR_SPECIFIC_DATA = 159, ///< TCAT send vendor specific command or data TLV

// Command Class CCM
OT_TCAT_TLV_SET_LDEVID_OPERATIONAL_CERT = 160, ///< TCAT LDevID operational certificate TLV
OT_TCAT_TLV_SET_LDEVID_PRIVATE_KEY = 161, ///< TCAT LDevID operational certificate pricate key TLV
OT_TCAT_TLV_SET_DOMAIN_CA_CERT = 162, ///< TCAT domain CA certificate TLV

} otTcatTlvType;

/**
* Represents TCAT Command types. ---> OBSOLETE
*
*/
typedef enum otTcatCommandType
{
OT_TCAT_COMMAND_TERMINATE = 0, ///< Terminate connection
OT_TCAT_COMMAND_THREAD_START = 1, ///< Start Thread Interface
OT_TCAT_COMMAND_THREAD_STOP = 2, ///< Stop Thread Interface

} otTcatCommandType;

/**
* Represents TCAT status code.
Expand All @@ -143,9 +80,9 @@ typedef enum otTcatStatusCode
OT_TCAT_STATUS_VALUE_ERROR = 3, ///< The value of the transmitted TLV has an error
OT_TCAT_STATUS_GENERAL_ERROR = 4, ///< An error not matching any other category occurred
OT_TCAT_STATUS_BUSY = 5, ///< Command cannot be executed because the resource is busy
OT_TCAT_STATUS_UNDEFINED = 6, ///< The requested value, data or service is not defined (currently) or not present
OT_TCAT_STATUS_HASH_ERROR = 7, ///< The hash value presented by the commissioner was incorrect
OT_TCAT_STATUS_UNAUTHORIZED = 8, ///< Sender does not have sufficient authorization for the given command
OT_TCAT_STATUS_UNDEFINED = 6, ///< The requested value, data or service is not defined (currently) or not present
OT_TCAT_STATUS_HASH_ERROR = 7, ///< The hash value presented by the commissioner was incorrect
OT_TCAT_STATUS_UNAUTHORIZED = 8, ///< Sender does not have sufficient authorization for the given command

} otTcatStatusCode;

Expand Down Expand Up @@ -187,8 +124,7 @@ typedef uint8_t otTcatCommandClassFlags;

enum
{
OT_TCAT_COMMAND_CLASS_FLAG_ACCESS =
1 << 0, ///< Access to the command class (device: without without additional requirements).
OT_TCAT_COMMAND_CLASS_FLAG_ACCESS = 1 << 0, ///< Access to the command class (device: without without additional requirements).
OT_TCAT_COMMAND_CLASS_FLAG_PSKD = 1 << 1, ///< Access requires proof-of-possession of the device's PSKd
OT_TCAT_COMMAND_CLASS_FLAG_NETWORK_NAME = 1 << 2, ///< Access requires matching network name
OT_TCAT_COMMAND_CLASS_FLAG_XPANID = 1 << 3, ///< Access requires matching XPANID
Expand Down Expand Up @@ -221,6 +157,8 @@ typedef struct otTcatCertificateAuthorizationField otTcatCertificateAuthorizatio

/**
* This structure represents a TCAT vendor information.
*
* The content of this structure MUST persist and remain unchanged while a TCAT session is running.
*
*/
typedef struct otTcatVendorInfo
Expand All @@ -232,7 +170,7 @@ typedef struct otTcatVendorInfo
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)
const char *mDeviceId; ///< Vendor managed device ID string (if NULL: device ID is set to EUI-64 in binary format)

} otTcatVendorInfo;

Expand All @@ -248,7 +186,7 @@ typedef struct otTcatVendorInfo
*
*/
typedef void (*otHandleTcatApplicationDataReceive)(otInstance *aInstance,
otMessage *aMessage,
const otMessage *aMessage,
otTcatMessageType aTcatMessageType,
const char *aServiceName,
void *aContext);
Expand All @@ -258,7 +196,6 @@ typedef void (*otHandleTcatApplicationDataReceive)(otInstance *aInstance,
*
* @param[in] aError OT_ERROR_NONE if the join process succeeded.
* OT_ERROR_SECURITY if the join process failed due to security credentials.
*
* @param[in] aContext A pointer to arbitrary context information.
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli_tcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const char kPskdVendor[] = "J01NM3";
const char kUrl[] = "dummy_url";

static void HandleBleSecureReceive(otInstance *aInstance,
otMessage *aMessage,
const otMessage *aMessage,
otTcatMessageType aTcatMessageType,
const char *aServiceName,
void *aContext)
Expand Down
15 changes: 6 additions & 9 deletions src/core/api/ble_secure_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, The OpenThread Authors.
* Copyright (c) 2023, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,15 +36,14 @@
#if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE

#include <openthread/ble_secure.h>

#include <openthread/platform/ble.h>

#include "common/as_core_type.hpp"
#include "common/code_utils.hpp"
#include "common/locator_getters.hpp"
#include "meshcop/tcat_agent.hpp"
#include "radio/ble_secure.hpp"

#include <openthread/platform/ble.h>

using namespace ot;

Expand All @@ -57,10 +56,10 @@ otError otBleSecureStart(otInstance *aInstance,
return AsCoreType(aInstance).Get<Ble::BleSecure>().Start(aConnectHandler, aReceiveHandler, aTlvMode, aContext);
}

otError otBleSecureTcatStart(otInstance *aInstance, otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler)
otError otBleSecureTcatStart(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler)
{
return AsCoreType(aInstance).Get<Ble::BleSecure>().TcatStart(
static_cast<MeshCoP::TcatAgent::VendorInfo *>(aVendorInfo), aHandler);
static_cast<const MeshCoP::TcatAgent::VendorInfo *>(aVendorInfo), aHandler);
}

void otBleSecureStop(otInstance *aInstance) { AsCoreType(aInstance).Get<Ble::BleSecure>().Stop(); }
Expand All @@ -81,11 +80,9 @@ void otBleSecureSetPsk(otInstance *aInstance,
#if defined(MBEDTLS_BASE64_C) && defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
otError otBleSecureGetPeerCertificateBase64(otInstance *aInstance,
unsigned char *aPeerCert,
size_t *aCertLength,
size_t aCertBufferSize)
size_t *aCertLength)
{
return AsCoreType(aInstance).Get<Ble::BleSecure>().GetPeerCertificateBase64(aPeerCert, aCertLength,
aCertBufferSize);
return AsCoreType(aInstance).Get<Ble::BleSecure>().GetPeerCertificateBase64(aPeerCert, aCertLength);
}
#endif // defined(MBEDTLS_BASE64_C) && defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)

Expand Down
Loading

0 comments on commit ae62ad3

Please sign in to comment.