Skip to content

Commit

Permalink
[platform] make setup constants configurable in gn
Browse files Browse the repository at this point in the history
Now you can use:
```
extra_args="chip_device_test_setup_pincode=87654321 \
chip_device_test_setup_discriminator=1024" ./gn_build.sh
```
to specify the setup constants.
  • Loading branch information
gjc13 committed Aug 24, 2020
1 parent cc2423a commit cda99fd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions examples/lock-app/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

// For convenience, Chip Security Test Mode can be enabled and the
// requirement for authentication in various protocols can be disabled.
Expand Down
5 changes: 5 additions & 0 deletions examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
#define CHIP_PROJECT_CONFIG_H

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

#endif // CHIP_PROJECT_CONFIG_H
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

/**
* CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER
Expand Down
5 changes: 2 additions & 3 deletions gn_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ echo ninja -C "$CHIP_ROOT/out/custom"

# nRF5 SDK setup
nrf5_sdk_args=""
extra_args=""

if [[ -d "$NRF5_SDK_ROOT/components/libraries" ]]; then
nrf5_sdk_args+="nrf5_sdk_root=\"$NRF5_SDK_ROOT\""
Expand Down Expand Up @@ -103,8 +102,8 @@ echo

_chip_banner "Build: GN configure"

gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args"
gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/release" --args='target_os="all" is_debug=false'"$extra_args"
gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/debug" --args='target_os="all"'" $extra_args"
gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/release" --args='target_os="all" is_debug=false'" $extra_args"

_chip_banner "Build: Ninja build"

Expand Down
13 changes: 13 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {

# Time the firmware was built.
chip_device_config_firmware_build_time = ""

# Test setup pincode
chip_device_test_setup_pincode = ""

# Test setup discriminator
chip_device_test_setup_discriminator = ""
}

config("platform_config") {
Expand All @@ -58,6 +64,13 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
defines += [ "CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME=\"${chip_device_config_firmware_build_time}\"" ]
}

if (chip_device_test_setup_pincode != "") {
defines += [ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${chip_device_test_setup_pincode}" ]
}
if (chip_device_test_setup_discriminator != "") {
defines += [ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${chip_device_test_setup_discriminator}" ]
}

if (chip_device_platform == "darwin") {
frameworks = [
"CoreFoundation.framework",
Expand Down
7 changes: 5 additions & 2 deletions src/platform/nRF5/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <ble/CHIPBleServiceData.h>
#include <platform/internal/BLEManager.h>
#include <platform/ConfigurationManager.h>

#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
Expand Down Expand Up @@ -253,8 +254,10 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * devName)
}
else
{
// FIXME: the name should be derived from factory data
snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0);
uint32_t discriminator = 0;

ConfigurationMgr().GetSetupDiscriminator(discriminator);
snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator);
devNameBuf[kMaxDeviceNameLength] = 0;
}

Expand Down

0 comments on commit cda99fd

Please sign in to comment.