| /* |
| * |
| * Copyright (c) 2022 Project CHIP Authors |
| * All rights reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include "Esp32AppServer.h" |
| #include "CHIPDeviceManager.h" |
| #include <app/clusters/network-commissioning/network-commissioning.h> |
| #include <app/server/Dnssd.h> |
| #include <app/server/Server.h> |
| #include <credentials/DeviceAttestationCredsProvider.h> |
| #include <credentials/examples/DeviceAttestationCredsExample.h> |
| #include <platform/ESP32/NetworkCommissioningDriver.h> |
| |
| #if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| #include <platform/ESP32/ESP32FactoryDataProvider.h> |
| #endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| |
| using namespace chip; |
| using namespace chip::Credentials; |
| using namespace chip::DeviceLayer; |
| |
| namespace { |
| #if CHIP_DEVICE_CONFIG_ENABLE_WIFI |
| app::Clusters::NetworkCommissioning::Instance |
| sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance())); |
| #endif |
| |
| #if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| ESP32FactoryDataProvider sFactoryDataProvider; |
| #endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| } // namespace |
| |
| void Esp32AppServer::Init(AppDelegate * sAppDelegate) |
| { |
| // Init ZCL Data Model and CHIP App Server |
| static chip::CommonCaseDeviceServerInitParams initParams; |
| (void) initParams.InitializeStaticResourcesBeforeServerInit(); |
| if (sAppDelegate != nullptr) |
| { |
| initParams.appDelegate = sAppDelegate; |
| } |
| chip::Server::GetInstance().Init(initParams); |
| |
| // Initialize device attestation config |
| #if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider); |
| #else |
| SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); |
| #endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER |
| |
| #if CHIP_DEVICE_CONFIG_ENABLE_WIFI |
| sWiFiNetworkCommissioningInstance.Init(); |
| #endif |
| #if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && |
| (chip::Server::GetInstance().GetFabricTable().FabricCount() != 0)) |
| { |
| ESP_LOGI("ESP32AppServer", "Thread has been provisioned, publish the dns service now"); |
| chip::app::DnssdServer::Instance().StartServer(); |
| } |
| #endif |
| } |