Skip to content

Commit

Permalink
[Telink] Add Amazon ecosystem support (#26753)
Browse files Browse the repository at this point in the history
* [Telink] Add Thread networks prescanning due to non concurrent radio mode

* [Telink] Fix rotating device id generation by factory data script

* [Telink] Enable rotating device ID by default for Amazon support

* [Telink] Update docker image to 0.7.14

* Restyled by whitespace

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 15, 2023
1 parent 224cde7 commit 1745810
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
image: connectedhomeip/chip-build-telink:0.7.11
image: connectedhomeip/chip-build-telink:0.7.14
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"

Expand Down
8 changes: 8 additions & 0 deletions config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ config CHIP_OTA_IMAGE_BUILD
bool
default y if CHIP_OTA_REQUESTOR

config CHIP_ROTATING_DEVICE_ID
bool "Generate rotating device ID"
default y
help
Enables the rotating device identifier that provides a non-trackable
identifier. The identifier is unique per device and rotates at pre-defined
moments.

config CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
bool "Include default device information provider build"
default y
Expand Down
7 changes: 3 additions & 4 deletions scripts/tools/telink/mfg_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
SHORT_MANUALCODE_LEN = 11
LONG_MANUALCODE_LEN = 21
QRCODE_LEN = 22
ROTATING_DEVICE_ID_UNIQUE_ID_LEN_BITS = 128
ROTATING_DEVICE_ID_UNIQUE_ID_LEN = 16
HEX_PREFIX = "hex:"
DEV_SN_CSV_HDR = "Serial Number,\n"

Expand Down Expand Up @@ -464,8 +464,7 @@ def write_device_unique_data(args, out_dirs, pai_cert):
nvs_memory_append('cert_dclrn', read_der_file(args.cert_dclrn))

if (args.enable_rotating_device_id is True) and (args.rd_id_uid is None):
nvs_memory_update('rd_uid', binascii.b2a_hex(os.urandom(
int(ROTATING_DEVICE_ID_UNIQUE_ID_LEN_BITS / 8))).decode('utf-8'))
nvs_memory_update('rd_uid', os.urandom(ROTATING_DEVICE_ID_UNIQUE_ID_LEN))

# Generate onboarding data
generate_onboarding_data(args, out_dirs, int(row['Discriminator']), int(row['PIN Code']))
Expand Down Expand Up @@ -672,7 +671,7 @@ def base64_str(s): return base64.b64decode(s)
check_str_range(args.product_name, 1, 32, 'Product name')
check_str_range(args.hw_ver_str, 1, 64, 'Hardware version string')
check_str_range(args.mfg_date, 8, 16, 'Manufacturing date')
check_str_range(args.rd_id_uid, 32, 32, 'Rotating device Unique id')
check_str_range(args.rd_id_uid, 16, 32, 'Rotating device Unique id')

# Validates the attestation related arguments
# DAC key and DAC cert both should be present or none
Expand Down
22 changes: 18 additions & 4 deletions src/platform/telink/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ BLEManagerImpl BLEManagerImpl::sInstance;

CHIP_ERROR BLEManagerImpl::_Init(void)
{
mBLERadioInitialized = false;
mconId = NULL;
mBLERadioInitialized = false;
mconId = NULL;
mInternalScanCallback = new InternalScanCallback(this);

mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
Expand Down Expand Up @@ -278,14 +279,27 @@ inline CHIP_ERROR BLEManagerImpl::PrepareAdvertisingRequest(void)

CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
{
int err;

if (ConnectivityMgr().IsThreadProvisioned())
{
ChipLogProgress(DeviceLayer, "Thread provisioned, can't StartAdvertising");

return CHIP_ERROR_INCORRECT_STATE;
}
else if (!mBLERadioInitialized)
{
ThreadStackMgrImpl().StartThreadScan(mInternalScanCallback);
}
else
{
return StartAdvertisingProcess();
}

return CHIP_NO_ERROR;
}

CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void)
{
int err;

if (!mBLERadioInitialized)
{
Expand Down
21 changes: 21 additions & 0 deletions src/platform/telink/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

#include <platform/NetworkCommissioning.h>
#include <platform/Zephyr/BLEAdvertisingArbiter.h>

#include <zephyr/bluetooth/bluetooth.h>
Expand All @@ -38,6 +39,8 @@ namespace Internal {

using namespace chip::Ble;

class InternalScanCallback;

/**
* Concrete implementation of the BLEManager singleton object for the Zephyr platforms.
*/
Expand Down Expand Up @@ -130,6 +133,8 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
CHIP_ERROR HandleThreadStateChange(const ChipDeviceEvent * event);
CHIP_ERROR HandleOperationalNetworkEnabled(const ChipDeviceEvent * event);

InternalScanCallback * mInternalScanCallback;

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
CHIP_ERROR PrepareC3CharData(void);
#endif
Expand Down Expand Up @@ -165,6 +170,22 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla

/* Switch to IEEE802154 interface. @todo: remove to other module? */
void SwitchToIeee802154(void);

CHIP_ERROR StartAdvertisingProcess(void);
};

class InternalScanCallback : public DeviceLayer::NetworkCommissioning::ThreadDriver::ScanCallback
{
public:
explicit InternalScanCallback(BLEManagerImpl * aBLEManagerImpl) { mBLEManagerImpl = aBLEManagerImpl; }
void OnFinished(NetworkCommissioning::Status err, CharSpan debugText,
NetworkCommissioning::ThreadScanResponseIterator * networks)
{
mBLEManagerImpl->StartAdvertisingProcess();
};

private:
BLEManagerImpl * mBLEManagerImpl;
};

/**
Expand Down
24 changes: 24 additions & 0 deletions src/platform/telink/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,29 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset
return result;
}

CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback)
{
mpScanCallback = callback;

/* On Telink platform it's not possible to rise Thread network when its used by BLE,
so Thread networks scanning performed before start BLE and also available after switch into Thread */
if (mRadioBlocked)
{
if (mpScanCallback != nullptr)
{
DeviceLayer::SystemLayer().ScheduleLambda([this]() {
mpScanCallback->OnFinished(NetworkCommissioning::Status::kSuccess, CharSpan(), &mScanResponseIter);
mpScanCallback = nullptr;
});
}
}
else
{
return Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::_StartThreadScan(mpScanCallback);
}

return CHIP_NO_ERROR;
}

} // namespace DeviceLayer
} // namespace chip
3 changes: 3 additions & 0 deletions src/platform/telink/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
void _ProcessThreadActivity() {}
CHIP_ERROR _AttachToThreadNetwork(const Thread::OperationalDataset & dataset,
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback);
CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback);

//} // namespace Internal

Expand All @@ -92,6 +93,8 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
// ===== Private members for use by this class only.
bool mRadioBlocked;
bool mReadyToAttach;

NetworkCommissioning::ThreadDriver::ScanCallback * mpScanCallback;
};

/**
Expand Down

0 comments on commit 1745810

Please sign in to comment.