forked from nrfconnect/sdk-connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
176 lines (145 loc) · 4.96 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
*
* Copyright (c) 2020 Project CHIP Authors
*
* 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 <lib/shell/Engine.h>
#include <app/server/Dnssd.h>
#include <lib/core/CHIPCore.h>
#include <lib/support/Base64.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <lib/support/CHIPMem.h>
#include <platform/CHIPDeviceLayer.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <zephyr/logging/log.h>
#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL
#include <ChipShellCollection.h>
#endif
#ifdef CONFIG_CHIP_PW_RPC
#include "Rpc.h"
#endif
#ifdef CONFIG_CHIP_CRYPTO_PSA
#include <crypto/PSAOperationalKeystore.h>
#ifdef CONFIG_CHIP_MIGRATE_OPERATIONAL_KEYS_TO_ITS
#include "MigrationManager.h"
#endif
#endif
LOG_MODULE_REGISTER(app, CONFIG_CHIP_APP_LOG_LEVEL);
using namespace chip;
using namespace chip::Shell;
using namespace chip::DeviceLayer;
namespace {
constexpr int kExtDiscoveryTimeoutSecs = 20;
#ifdef CONFIG_CHIP_CRYPTO_PSA
chip::Crypto::PSAOperationalKeystore sPSAOperationalKeystore{};
#endif
} // namespace
int main()
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifdef CONFIG_CHIP_PW_RPC
rpc::Init();
#endif
err = chip::Platform::MemoryInit();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Platform::MemoryInit() failed");
return 1;
}
err = PlatformMgr().InitChipStack();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "PlatformMgr().InitChipStack() failed");
return 1;
}
// Network connectivity
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
ConnectivityManagerImpl().StartWiFiManagement();
#endif
#if defined(CHIP_ENABLE_OPENTHREAD)
err = ThreadStackMgr().InitThreadStack();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "ThreadStackMgr().InitThreadStack() failed");
return 1;
}
#ifdef CONFIG_OPENTHREAD_MTD
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#else
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#endif
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "ConnectivityMgr().SetThreadDeviceType() failed");
return 1;
}
#elif !defined(CONFIG_WIFI_NRF70)
return CHIP_ERROR_INTERNAL;
#endif
// Device Attestation & Onboarding codes
chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(kExtDiscoveryTimeoutSecs);
#endif /* CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY */
// Start IM server
static chip::CommonCaseDeviceServerInitParams initParams;
#ifdef CONFIG_CHIP_CRYPTO_PSA
initParams.operationalKeystore = &sPSAOperationalKeystore;
#endif
(void) initParams.InitializeStaticResourcesBeforeServerInit();
err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR)
{
return 1;
}
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig();
err = chip::DeviceLayer::PlatformMgr().StartEventLoopTask();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "PlatformMgr().StartEventLoopTask() failed");
}
// When SoftAP support becomes available, it should be added here.
#if CONFIG_NETWORK_LAYER_BLE
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
#else
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork));
#endif /* CONFIG_NETWORK_LAYER_BLE */
// Starts commissioning window automatically. Starts BLE advertising when BLE enabled
if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "OpenBasicCommissioningWindow() failed");
}
#if CONFIG_CHIP_LIB_SHELL
int rc = Engine::Root().Init();
if (rc != 0)
{
ChipLogError(AppServer, "Streamer initialization failed: %d", rc);
return 1;
}
cmd_misc_init();
cmd_otcli_init();
#endif
#if CHIP_SHELL_ENABLE_CMD_SERVER
cmd_app_server_init();
#endif
#if CONFIG_CHIP_LIB_SHELL
Engine::Root().RunMainLoop();
#endif
return 0;
}