Skip to content

Commit

Permalink
Address 9154 and CM/AC DNS-SD convergence (#9348)
Browse files Browse the repository at this point in the history
* Address 9154 and CM/AC DNS-SD convergence

* Attempt to fix CI build caused by weird branch confusion

* Merge with TOT

* fix merge

* fix unit tests, non-linux builds

* fix CI

* fix CI

* fix CI

* fix CI

* fix unit tests

* fix CI

* fix CI

* Address feedback, move Mdns to MdnsServer singleton

* Address feedback

* Address feedback

* Fix build

* editorial - rearrange header file

* fix python

* fix build

* address comments
  • Loading branch information
chrisdecenzo authored Sep 14, 2021
1 parent 6fd3811 commit 97d9f7e
Show file tree
Hide file tree
Showing 36 changed files with 588 additions and 414 deletions.
6 changes: 3 additions & 3 deletions examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
break;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
wifiLED.Set(true);
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -137,7 +137,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
3 changes: 2 additions & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ class SetupListModel : public ListScreen::Model
}
else if (i == 2)
{
app::Mdns::AdvertiseCommissionableNode(app::Mdns::CommissioningMode::kEnabledBasic);
app::MdnsServer::Instance().StartServer(Mdns::CommissioningMode::kEnabledBasic);

chip::Server::GetInstance().GetCommissionManager().OpenBasicCommissioningWindow(
ResetFabrics::kYes, kNoCommissioningTimeout, CommissioningWindowAdvertisement::kMdns);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/bridge-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
break;
}
Expand All @@ -71,7 +71,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -80,7 +80,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void DiscoverCommissionablesCommand::Shutdown()

ChipLogProgress(Discovery, "Commissionable Node %d", i);
ChipLogProgress(Discovery, "\tHost name:\t\t%s", dnsSdInfo->hostName);
ChipLogProgress(Discovery, "\tPort:\t\t\t%u", dnsSdInfo->port);
ChipLogProgress(Discovery, "\tLong discriminator:\t%u", dnsSdInfo->longDiscriminator);
ChipLogProgress(Discovery, "\tVendor ID:\t\t%u", dnsSdInfo->vendorId);
ChipLogProgress(Discovery, "\tProduct ID:\t\t%u", dnsSdInfo->productId);
ChipLogProgress(Discovery, "\tAdditional Pairing\t%u", dnsSdInfo->additionalPairing);
ChipLogProgress(Discovery, "\tCommissioning Mode\t%u", dnsSdInfo->commissioningMode);
ChipLogProgress(Discovery, "\tDevice Type\t\t%u", dnsSdInfo->deviceType);
ChipLogProgress(Discovery, "\tDevice Name\t\t%s", dnsSdInfo->deviceName);
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int AppTask::Init()
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established ||
event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
break;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -102,7 +102,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int AppTask::Init()
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established ||
event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/p6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CHIP_ERROR AppTask::Init()
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established ||
event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
}
},
Expand Down
63 changes: 31 additions & 32 deletions examples/minimal-mdns/advertiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ struct Options
Optional<const char *> deviceName;

// commisionable node params
uint8_t shortDiscriminator = 52;
uint16_t longDiscriminator = 840;
bool commissioningMode = false;
bool commissioningModeOpenWindow = false;
uint8_t shortDiscriminator = 52;
uint16_t longDiscriminator = 840;
Mdns::CommissioningMode commissioningMode = Mdns::CommissioningMode::kDisabled;
Optional<const char *> rotatingId;
Optional<const char *> pairingInstr;
Optional<uint16_t> pairingHint;
Expand All @@ -78,14 +77,14 @@ constexpr uint16_t kOptionCommisioningPairingHint = 0x300;
constexpr uint16_t kOptionCommisioningDeviceType = 0x400;
constexpr uint16_t kOptionCommisioningDeviceName = 0x500;
constexpr uint16_t kOptionCommisioningMode = 0x600;
constexpr uint16_t kOptionCommisioningModeOpenWindow = 0x700;
constexpr uint16_t kOptionCommisioningRotatingId = 0x800;
constexpr uint16_t kOptionCommisioningRotatingId = 0x700;

constexpr uint16_t kOptionOperationalFabricId = 'f';
constexpr uint16_t kOptionOperationalNodeId = 'n';

bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
{
uint8_t cm;
switch (aIdentifier)
{
case kOptionEnableIpV4:
Expand Down Expand Up @@ -124,10 +123,15 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
gOptions.productId = Optional<uint16_t>::Value(static_cast<uint16_t>(atoi(aValue)));
return true;
case kOptionCommisioningMode:
gOptions.commissioningMode = true;
return true;
case kOptionCommisioningModeOpenWindow:
gOptions.commissioningModeOpenWindow = true;
cm = static_cast<uint8_t>(atoi(aValue));
if (cm == 1)
{
gOptions.commissioningMode = Mdns::CommissioningMode::kEnabledBasic;
}
if (cm == 2)
{
gOptions.commissioningMode = Mdns::CommissioningMode::kEnabledEnhanced;
}
return true;
case kOptionCommisioningDeviceType:
gOptions.deviceType = Optional<uint16_t>::Value(static_cast<uint16_t>(atoi(aValue)));
Expand Down Expand Up @@ -174,8 +178,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "long-discriminator", kArgumentRequired, kOptionCommisioningLongDiscriminaotr },
{ "vendor-id", kArgumentRequired, kOptionCommisioningVendorId },
{ "product-id", kArgumentRequired, kOptionCommisioningProductId },
{ "commissioning-mode-enabled", kNoArgument, kOptionCommisioningMode },
{ "commissioning-mode-open-window", kNoArgument, kOptionCommisioningModeOpenWindow },
{ "commissioning-mode", kNoArgument, kOptionCommisioningMode },
{ "device-type", kArgumentRequired, kOptionCommisioningDeviceType },
{ "device-name", kArgumentRequired, kOptionCommisioningDeviceName },
{ "rotating-id", kArgumentRequired, kOptionCommisioningRotatingId },
Expand Down Expand Up @@ -207,10 +210,8 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" --product-id <value>\n"
" -p <value>\n"
" Commisioning/commisionable product id.\n"
" --commissioning-mode-enabled\n"
" Commissioning Mode Enabled.\n"
" --commissioning-mode-open-window\n"
" Commissioning Mode as a result of Open Commissioning Window.\n"
" --commissioning-mode <value>\n"
" Commissioning Mode (0=disabled, 1=basic, 2=enhanced).\n"
" --device-type <value>\n"
" Device type id.\n"
" --device-name <value>\n"
Expand Down Expand Up @@ -265,22 +266,20 @@ int main(int argc, char ** args)
if (gOptions.advertisingMode == AdvertisingMode::kCommissionableNode)
{
printf("Advertise Commissionable Node\n");
err = chip::Mdns::ServiceAdvertiser::Instance().Advertise(
chip::Mdns::CommissionAdvertisingParameters()
.EnableIpV4(gOptions.enableIpV4)
.SetPort(CHIP_PORT)
.SetShortDiscriminator(gOptions.shortDiscriminator)
.SetLongDiscriminator(gOptions.longDiscriminator)
.SetMac(chip::ByteSpan(gOptions.mac, 6))
.SetVendorId(gOptions.vendorId)
.SetProductId(gOptions.productId)
.SetCommissioningMode(gOptions.commissioningMode)
.SetAdditionalCommissioning(gOptions.commissioningModeOpenWindow)
.SetDeviceType(gOptions.deviceType)
.SetDeviceName(gOptions.deviceName)
.SetRotatingId(gOptions.rotatingId)
.SetPairingInstr(gOptions.pairingInstr)
.SetPairingHint(gOptions.pairingHint));
err = chip::Mdns::ServiceAdvertiser::Instance().Advertise(chip::Mdns::CommissionAdvertisingParameters()
.EnableIpV4(gOptions.enableIpV4)
.SetPort(CHIP_PORT)
.SetShortDiscriminator(gOptions.shortDiscriminator)
.SetLongDiscriminator(gOptions.longDiscriminator)
.SetMac(chip::ByteSpan(gOptions.mac, 6))
.SetVendorId(gOptions.vendorId)
.SetProductId(gOptions.productId)
.SetCommissioningMode(gOptions.commissioningMode)
.SetDeviceType(gOptions.deviceType)
.SetDeviceName(gOptions.deviceName)
.SetRotatingId(gOptions.rotatingId)
.SetPairingInstr(gOptions.pairingInstr)
.SetPairingHint(gOptions.pairingHint));
}
else if (gOptions.advertisingMode == AdvertisingMode::kOperational)
{
Expand Down
5 changes: 3 additions & 2 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,15 @@ int main(int argc, char ** args)

mdns::Minimal::Server<20> mdnsServer;
ReportDelegate reporter;
CHIP_ERROR err;

mdnsServer.SetDelegate(&reporter);

{

MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4);

CHIP_ERROR err = mdnsServer.Listen(&chip::DeviceLayer::InetLayer, &allInterfaces, gOptions.listenPort);
err = mdnsServer.Listen(&chip::DeviceLayer::InetLayer, &allInterfaces, gOptions.listenPort);
if (err != CHIP_NO_ERROR)
{
printf("Server failed to listen on all interfaces: %s\n", chip::ErrorStr(err));
Expand All @@ -326,7 +327,7 @@ int main(int argc, char ** args)

BroadcastPacket(&mdnsServer);

CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(
err = DeviceLayer::SystemLayer().StartTimer(
gOptions.runtimeMs,
[](System::Layer *, void *) {
DeviceLayer::PlatformMgr().StopEventLoopTask();
Expand Down
29 changes: 26 additions & 3 deletions examples/platform/linux/CommissioneeShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ static CHIP_ERROR PrintAllCommands()
streamer_printf(sout,
" sendudc <address> <port> Send UDC message to address. Usage: commissionee sendudc 127.0.0.1 5543\r\n");
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
streamer_printf(
sout, " setdiscoverytimeout <timeout> Set discovery timeout in seconds. Usage: commissionee setdiscoverytimeout 30\r\n");
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
streamer_printf(sout,
" setextendeddiscoverytimeout <timeout> Set extendeddiscovery timeout in seconds. Usage: commissionee "
"setextendeddiscoverytimeout 30\r\n");
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
streamer_printf(sout,
" restartmdns <commissioningMode> (disabled|enabled_basic|enabled_enhanced) Start Mdns with given "
"settings. Usage: commissionee "
Expand Down Expand Up @@ -89,6 +96,22 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv)
return error = SendUDC(true, chip::Transport::PeerAddress::UDP(commissioner, port));
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
else if (strcmp(argv[0], "setdiscoverytimeout") == 0)
{
char * eptr;
int16_t timeout = (int16_t) strtol(argv[1], &eptr, 10);
chip::app::MdnsServer::Instance().SetDiscoveryTimeoutSecs(timeout);
return CHIP_NO_ERROR;
}
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
else if (strcmp(argv[0], "setextendeddiscoverytimeout") == 0)
{
char * eptr;
int16_t timeout = (int16_t) strtol(argv[1], &eptr, 10);
chip::app::MdnsServer::Instance().SetExtendedDiscoveryTimeoutSecs(timeout);
return CHIP_NO_ERROR;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
else if (strcmp(argv[0], "restartmdns") == 0)
{
if (argc < 2)
Expand All @@ -97,17 +120,17 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv)
}
if (strcmp(argv[1], "disabled") == 0)
{
chip::app::Mdns::StartServer(chip::app::Mdns::CommissioningMode::kDisabled);
chip::app::MdnsServer::Instance().StartServer(chip::Mdns::CommissioningMode::kDisabled);
return CHIP_NO_ERROR;
}
if (strcmp(argv[1], "enabled_basic") == 0)
{
chip::app::Mdns::StartServer(chip::app::Mdns::CommissioningMode::kEnabledBasic);
chip::app::MdnsServer::Instance().StartServer(chip::Mdns::CommissioningMode::kEnabledBasic);
return CHIP_NO_ERROR;
}
else if (strcmp(argv[1], "enabled_enhanced") == 0)
{
chip::app::Mdns::StartServer(chip::app::Mdns::CommissioningMode::kEnabledEnhanced);
chip::app::MdnsServer::Instance().StartServer(chip::Mdns::CommissioningMode::kEnabledEnhanced);
return CHIP_NO_ERROR;
}
return PrintAllCommands();
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/nrfconnect/util/ThreadUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ void StartDefaultThreadNetwork(void)
chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(dataset.AsByteSpan());
chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true);

chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
break;
}
Expand All @@ -82,7 +82,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -91,7 +91,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
chip::app::MdnsServer::Instance().StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
4 changes: 2 additions & 2 deletions examples/tv-casting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ void PrepareForCommissioning(const Mdns::DiscoveredNodeData * selectedCommission
if (selectedCommissioner != nullptr)
{
// Advertise self as Commissionable Node over mDNS
ReturnOnFailure(app::Mdns::AdvertiseCommissionableNode(app::Mdns::CommissioningMode::kEnabledBasic));
app::MdnsServer::Instance().StartServer(Mdns::CommissioningMode::kEnabledBasic);

// Send User Directed commissioning request
ReturnOnFailure(SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(
ReturnOnFailure(Server::GetInstance().SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(
selectedCommissioner->ipAddress[0], selectedCommissioner->port, selectedCommissioner->interfaceId[0])));
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
Expand Down
Loading

0 comments on commit 97d9f7e

Please sign in to comment.