Skip to content

Commit

Permalink
Fix rendezvous flags in QR code. (#5711)
Browse files Browse the repository at this point in the history
* Fix rendezvous flags in QR code.

Spec specifies soft-ap, ble and on-network as flags. Ethernet
and thread are both advertised over mdns (thread through BR) and
the commissioner won't need that info.

Please see Table 30. Discovery Capabilities Bitmask

* Use BitFlags for RendezvousFlags

* Fix build for nrf

* Remove OR'd enums from darwin

* fix typo on lighting app.

* Fix nRF build from change that came in on merge.

* Fixes for when NFC commissioning is on.

* Change rendezvous flags on esp32 lock app from master.

* Fix rendezvous flags for new window example.

* Fix again.
  • Loading branch information
cecille authored Apr 9, 2021
1 parent 3588d78 commit 6cbb522
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 121 deletions.
23 changes: 10 additions & 13 deletions examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,28 @@ void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event,
CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
{
CHIP_ERROR err;
mCB = cb;
mCB = cb;
RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE);

// Initialize the CHIP stack.
err = PlatformMgr().InitChipStack();
SuccessOrExit(err);

switch (static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE))
if (flags.Has(RendezvousInformationFlag::kBLE))
{
case RendezvousInformationFlags::kBLE:
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
break;

case RendezvousInformationFlags::kWiFi:
}
else if (flags.Has(RendezvousInformationFlag::kSoftAP))
{
// TODO(cecille): Fix for the case where BLE and SoftAP are both enabled.`
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

case RendezvousInformationFlags::kNone:
}
else
{
// If rendezvous is bypassed, enable SoftAP so that the device can still
// be communicated with via its SoftAP as needed.
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

default:
break;
}

err = Platform::MemoryInit();
Expand Down
21 changes: 12 additions & 9 deletions examples/all-clusters-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ menu "Demo"

config RENDEZVOUS_MODE_BYPASS
bool "Bypass"
config RENDEZVOUS_MODE_WIFI
bool "Wi-Fi"
config RENDEZVOUS_MODE_SOFTAP
bool "Soft-AP"
config RENDEZVOUS_MODE_BLE
bool "BLE"
config RENDEZVOUS_MODE_THREAD
bool "Thread"
config RENDEZVOUS_MODE_ETHERNET
bool "Ethernet"
config RENDEZVOUS_MODE_ON_NETWORK
bool "On-Network"
config RENDEZVOUS_MODE_SOFTAP_ON_NETWORK
bool "Soft-AP / On-Network"
config RENDEZVOUS_MODE_BLE_ON_NETWORK
bool "BLE / On-Network"
endchoice

config ECHO_HOST_IP
Expand All @@ -76,10 +78,11 @@ menu "Demo"
int
range 0 8
default 0 if RENDEZVOUS_MODE_BYPASS
default 1 if RENDEZVOUS_MODE_WIFI
default 1 if RENDEZVOUS_MODE_SOFTAP
default 2 if RENDEZVOUS_MODE_BLE
default 4 if RENDEZVOUS_MODE_THREAD
default 8 if RENDEZVOUS_MODE_ETHERNET
default 4 if RENDEZVOUS_MODE_ON_NETWORK
default 5 if RENDEZVOUS_MODE_SOFTAP_ON_NETWORK
default 6 if RENDEZVOUS_MODE_BLE_ON_NETWORK

config DISPLAY_AUTO_OFF
bool "Automatically turn off the M5Stack's Display after a few seconds"
Expand Down
5 changes: 3 additions & 2 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ void GetGatewayIP(char * ip_buf, size_t ip_len)

bool isRendezvousBLE()
{
return static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE) == RendezvousInformationFlags::kBLE;
RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE);
return flags.Has(RendezvousInformationFlag::kBLE);
}

std::string createSetupPayload()
Expand Down Expand Up @@ -414,7 +415,7 @@ std::string createSetupPayload()
payload.version = 0;
payload.discriminator = discriminator;
payload.setUpPINCode = setupPINCode;
payload.rendezvousInformation = static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE);
payload.rendezvousInformation = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE);
payload.vendorID = vendorId;
payload.productID = productId;

Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int AppTask::Init()
#ifdef DISPLAY_ENABLED
std::string QRCode;

if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
if (GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR)
{
LCDWriteQRCode((uint8_t *) QRCode.c_str());
}
Expand All @@ -157,7 +157,7 @@ int AppTask::Init()
EFR32_LOG("Getting QR code failed!");
}
#else
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#endif

return err;
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int AppTask::Init()
InitServer();

// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

TMR_Init();

Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int AppTask::Init()
// Init ZCL Data Model and start server
InitServer();
ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

#ifdef CONFIG_CHIP_NFC_COMMISSIONING
PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0);
Expand Down Expand Up @@ -371,7 +371,7 @@ void AppTask::StartBLEAdvertisementHandler(AppEvent * aEvent)
}
else
{
ShareQRCodeOverNFC(chip::RendezvousInformationFlags::kBLE);
ShareQRCodeOverNFC(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int AppTask::Init()
UpdateClusterState();

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

return err;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int AppTask::Init()
ConfigurationMgr().LogDeviceConfig();

// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int AppTask::Init()
#ifdef DISPLAY_ENABLED
std::string QRCode;

if (GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
if (GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR)
{
LCDWriteQRCode((uint8_t *) QRCode.c_str());
}
Expand All @@ -153,7 +153,7 @@ int AppTask::Init()
EFR32_LOG("Getting QR code failed!");
}
#else
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#endif

return err;
Expand Down
22 changes: 9 additions & 13 deletions examples/lock-app/esp32/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,27 @@ void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event,
CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
{
CHIP_ERROR err;
mCB = cb;
mCB = cb RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE);

// Initialize the CHIP stack.
err = PlatformMgr().InitChipStack();
SuccessOrExit(err);

switch (static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE))
if (flags.Has(RendezvousInformationFlag::kBLE))
{
case RendezvousInformationFlags::kBLE:
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
break;

case RendezvousInformationFlags::kWiFi:
}
else if (flags.Has(RendezvousInformationFlag::kSoftAP))
{
// TODO(cecille): Fix for the case where BLE and SoftAP are both enabled.`
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

case RendezvousInformationFlags::kNone:
}
else
{
// If rendezvous is bypassed, enable SoftAP so that the device can still
// be communicated with via its SoftAP as needed.
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

default:
break;
}

err = Platform::MemoryInit();
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int AppTask::Init()
InitServer();

// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

TMR_Init();

Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int AppTask::Init()
// Init ZCL Data Model and start server
InitServer();
ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));

#ifdef CONFIG_CHIP_NFC_COMMISSIONING
PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0);
Expand Down Expand Up @@ -372,7 +372,7 @@ void AppTask::StartBLEAdvertisementHandler(AppEvent * aEvent)
}
else
{
ShareQRCodeOverNFC(chip::RendezvousInformationFlags::kBLE);
ShareQRCodeOverNFC(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int AppTask::Init()
UpdateClusterState();

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags::kBLE);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

return err;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,22 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
err = PlatformMgr().InitChipStack();
SuccessOrExit(err);

switch (static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE))
RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE);
if (flags.Has(RendezvousInformationFlag::kBLE))
{
case RendezvousInformationFlags::kBLE:
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
break;

case RendezvousInformationFlags::kWiFi:
}
else if (flags.Has(RendezvousInformationFlag::kSoftAP))
{
// TODO(cecille): Fix for the case where BLE and SoftAP are both enabled.`
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

case RendezvousInformationFlags::kNone:
}
else
{
// If rendezvous is bypassed, enable SoftAP so that the device can still
// be communicated with via its SoftAP as needed.
ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
break;

default:
break;
}

err = Platform::MemoryInit();
Expand Down
4 changes: 2 additions & 2 deletions examples/window-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ int AppTask::Init()

// Print setup info on LCD if available
#ifdef DISPLAY_ENABLED
if (!GetQRCode(mQRCode, chip::RendezvousInformationFlags::kBLE) == CHIP_NO_ERROR)
if (!GetQRCode(mQRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR)
{
EFR32_LOG("Getting QR code failed!");
}
#else
PrintQRCode(chip::RendezvousInformationFlags::kBLE);
PrintQRCode(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
#endif
mResetWarning = false;
// Force LCD refresh
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/OnboardingCodesUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ShareQRCodeOverNFC(chip::RendezvousInformationFlags rendezvousFlags)
{
// Get QR Code and emulate its content using NFC tag
std::string QRCode;
ReturnOnFailure(GetQRCode(QRCode, chip::RendezvousInformationFlags::kBLE));
ReturnOnFailure(GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)));

// TODO: Issue #4504 - Remove replacing spaces with _ after problem described in #415 will be fixed.
std::replace(QRCode.begin(), QRCode.end(), ' ', '_');
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ constexpr bool isRendezvousBypassed()
#if defined(CHIP_BYPASS_RENDEZVOUS) && CHIP_BYPASS_RENDEZVOUS
return true;
#elif defined(CONFIG_RENDEZVOUS_MODE)
return static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE) == RendezvousInformationFlags::kNone;
return static_cast<RendezvousInformationFlag>(CONFIG_RENDEZVOUS_MODE) == RendezvousInformationFlag::kNone;
#else
return false;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ CHIP_ERROR Device::OpenPairingWindow(uint32_t timeout, PairingWindowOption optio
ReturnErrorOnFailure(SendMessage(std::move(outBuffer), header));

setupPayload.version = 0;
setupPayload.rendezvousInformation = RendezvousInformationFlags::kBLE;
setupPayload.rendezvousInformation = RendezvousInformationFlags(RendezvousInformationFlag::kBLE);

return CHIP_NO_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,11 @@ - (void)parseOptionalData:(CHIPSetupPayload *)payload
- (void)handleRendezVous:(CHIPSetupPayload *)payload
{
switch (payload.rendezvousInformation) {
case kRendezvousInformationThread:
case kRendezvousInformationEthernet:
case kRendendezvousInformationOnNetwork:
case kRendezvousInformationAllMask:
NSLog(@"Rendezvous Unknown");
break;
case kRendezvousInformationWiFi:
case kRendezvousInformationSoftAP:
NSLog(@"Rendezvous Wi-Fi");
[self handleRendezVousWiFi:[self getNetworkName:payload.discriminator]];
break;
Expand Down
8 changes: 3 additions & 5 deletions src/darwin/Framework/CHIP/CHIPSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, RendezvousInformationFlags) {
kRendezvousInformationNone = 0, // Device does not support any method for rendezvous
kRendezvousInformationWiFi = 1 << 0, // Device supports WiFi
kRendezvousInformationSoftAP = 1 << 0, // Device supports WiFi softAP
kRendezvousInformationBLE = 1 << 1, // Device supports BLE
kRendezvousInformationThread = 1 << 2, // Device supports Thread
kRendezvousInformationEthernet = 1 << 3, // Device MAY be attached to a wired 802." connection"
kRendezvousInformationOnNetwork = 1 << 2, // Device supports On Network setup

kRendezvousInformationAllMask
= kRendezvousInformationWiFi | kRendezvousInformationBLE | kRendezvousInformationThread | kRendezvousInformationEthernet,
kRendezvousInformationAllMask = kRendezvousInformationSoftAP | kRendezvousInformationBLE | kRendezvousInformationOnNetwork,
};

typedef NS_ENUM(NSUInteger, OptionalQRCodeInfoType) {
Expand Down
Loading

0 comments on commit 6cbb522

Please sign in to comment.