Skip to content

Commit 2663621

Browse files
s07641069restyled-commits
authored andcommitted
[Telink] Add Amazon ecosystem support (#26753)
* [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 <commits@restyled.io>
1 parent d47e6a2 commit 2663621

File tree

7 files changed

+78
-9
lines changed

7 files changed

+78
-9
lines changed

.github/workflows/examples-telink.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
if: github.actor != 'restyled-io[bot]'
3939

4040
container:
41-
image: connectedhomeip/chip-build-telink:0.7.11
41+
image: connectedhomeip/chip-build-telink:0.7.14
4242
volumes:
4343
- "/tmp/bloat_reports:/tmp/bloat_reports"
4444

config/telink/chip-module/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ config CHIP_OTA_IMAGE_BUILD
6060
bool
6161
default y if CHIP_OTA_REQUESTOR
6262

63+
config CHIP_ROTATING_DEVICE_ID
64+
bool "Generate rotating device ID"
65+
default y
66+
help
67+
Enables the rotating device identifier that provides a non-trackable
68+
identifier. The identifier is unique per device and rotates at pre-defined
69+
moments.
70+
6371
config CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
6472
bool "Include default device information provider build"
6573
default y

scripts/tools/telink/mfg_tool.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
SHORT_MANUALCODE_LEN = 11
5050
LONG_MANUALCODE_LEN = 21
5151
QRCODE_LEN = 22
52-
ROTATING_DEVICE_ID_UNIQUE_ID_LEN_BITS = 128
52+
ROTATING_DEVICE_ID_UNIQUE_ID_LEN = 16
5353
HEX_PREFIX = "hex:"
5454
DEV_SN_CSV_HDR = "Serial Number,\n"
5555

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

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

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

677676
# Validates the attestation related arguments
678677
# DAC key and DAC cert both should be present or none

src/platform/telink/BLEManagerImpl.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ BLEManagerImpl BLEManagerImpl::sInstance;
147147

148148
CHIP_ERROR BLEManagerImpl::_Init(void)
149149
{
150-
mBLERadioInitialized = false;
151-
mconId = NULL;
150+
mBLERadioInitialized = false;
151+
mconId = NULL;
152+
mInternalScanCallback = new InternalScanCallback(this);
152153

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

279280
CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
280281
{
281-
int err;
282-
283282
if (ConnectivityMgr().IsThreadProvisioned())
284283
{
285284
ChipLogProgress(DeviceLayer, "Thread provisioned, can't StartAdvertising");
286285

287286
return CHIP_ERROR_INCORRECT_STATE;
288287
}
288+
else if (!mBLERadioInitialized)
289+
{
290+
ThreadStackMgrImpl().StartThreadScan(mInternalScanCallback);
291+
}
292+
else
293+
{
294+
return StartAdvertisingProcess();
295+
}
296+
297+
return CHIP_NO_ERROR;
298+
}
299+
300+
CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void)
301+
{
302+
int err;
289303

290304
if (!mBLERadioInitialized)
291305
{

src/platform/telink/BLEManagerImpl.h

+21
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
2828

29+
#include <platform/NetworkCommissioning.h>
2930
#include <platform/Zephyr/BLEAdvertisingArbiter.h>
3031

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

3940
using namespace chip::Ble;
4041

42+
class InternalScanCallback;
43+
4144
/**
4245
* Concrete implementation of the BLEManager singleton object for the Zephyr platforms.
4346
*/
@@ -130,6 +133,8 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
130133
CHIP_ERROR HandleThreadStateChange(const ChipDeviceEvent * event);
131134
CHIP_ERROR HandleOperationalNetworkEnabled(const ChipDeviceEvent * event);
132135

136+
InternalScanCallback * mInternalScanCallback;
137+
133138
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
134139
CHIP_ERROR PrepareC3CharData(void);
135140
#endif
@@ -165,6 +170,22 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
165170

166171
/* Switch to IEEE802154 interface. @todo: remove to other module? */
167172
void SwitchToIeee802154(void);
173+
174+
CHIP_ERROR StartAdvertisingProcess(void);
175+
};
176+
177+
class InternalScanCallback : public DeviceLayer::NetworkCommissioning::ThreadDriver::ScanCallback
178+
{
179+
public:
180+
explicit InternalScanCallback(BLEManagerImpl * aBLEManagerImpl) { mBLEManagerImpl = aBLEManagerImpl; }
181+
void OnFinished(NetworkCommissioning::Status err, CharSpan debugText,
182+
NetworkCommissioning::ThreadScanResponseIterator * networks)
183+
{
184+
mBLEManagerImpl->StartAdvertisingProcess();
185+
};
186+
187+
private:
188+
BLEManagerImpl * mBLEManagerImpl;
168189
};
169190

170191
/**

src/platform/telink/ThreadStackManagerImpl.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,29 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset
112112
return result;
113113
}
114114

115+
CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback)
116+
{
117+
mpScanCallback = callback;
118+
119+
/* On Telink platform it's not possible to rise Thread network when its used by BLE,
120+
so Thread networks scanning performed before start BLE and also available after switch into Thread */
121+
if (mRadioBlocked)
122+
{
123+
if (mpScanCallback != nullptr)
124+
{
125+
DeviceLayer::SystemLayer().ScheduleLambda([this]() {
126+
mpScanCallback->OnFinished(NetworkCommissioning::Status::kSuccess, CharSpan(), &mScanResponseIter);
127+
mpScanCallback = nullptr;
128+
});
129+
}
130+
}
131+
else
132+
{
133+
return Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::_StartThreadScan(mpScanCallback);
134+
}
135+
136+
return CHIP_NO_ERROR;
137+
}
138+
115139
} // namespace DeviceLayer
116140
} // namespace chip

src/platform/telink/ThreadStackManagerImpl.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
7878
void _ProcessThreadActivity() {}
7979
CHIP_ERROR _AttachToThreadNetwork(const Thread::OperationalDataset & dataset,
8080
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback);
81+
CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback);
8182

8283
//} // namespace Internal
8384

@@ -92,6 +93,8 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
9293
// ===== Private members for use by this class only.
9394
bool mRadioBlocked;
9495
bool mReadyToAttach;
96+
97+
NetworkCommissioning::ThreadDriver::ScanCallback * mpScanCallback;
9598
};
9699

97100
/**

0 commit comments

Comments
 (0)