Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / platform / nrfconnect / util / ThreadUtil.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 #include "ThreadUtil.h"
20
21 #include <platform/CHIPDeviceLayer.h>
22 #include <platform/internal/DeviceNetworkInfo.h>
23
24 #include <zephyr.h>
25
26 #include <cstring>
27
28 void StartDefaultThreadNetwork(void)
29 {
30     chip::DeviceLayer::Internal::DeviceNetworkInfo deviceNetworkInfo;
31     memset(&deviceNetworkInfo, 0, sizeof(deviceNetworkInfo));
32
33     const uint8_t masterKey[chip::DeviceLayer::Internal::kThreadMasterKeyLength] = {
34         0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
35     };
36     const uint8_t threadMeshPrefix[chip::DeviceLayer::Internal::kThreadMeshPrefixLength] = { 0xfd, 0x11, 0x11, 0x11,
37                                                                                              0x11, 0x22, 0x00, 0x00 };
38
39     memcpy(deviceNetworkInfo.ThreadNetworkName, CONFIG_OPENTHREAD_NETWORK_NAME, strlen(CONFIG_OPENTHREAD_NETWORK_NAME));
40     net_bytes_from_str(deviceNetworkInfo.ThreadExtendedPANId, 8, CONFIG_OPENTHREAD_XPANID);
41     deviceNetworkInfo.FieldPresent.ThreadExtendedPANId = true;
42     memcpy(deviceNetworkInfo.ThreadMasterKey, masterKey, sizeof(masterKey));
43     deviceNetworkInfo.FieldPresent.ThreadMeshPrefix = true;
44     memcpy(deviceNetworkInfo.ThreadMeshPrefix, threadMeshPrefix, sizeof(threadMeshPrefix));
45     deviceNetworkInfo.ThreadPANId   = CONFIG_OPENTHREAD_PANID;
46     deviceNetworkInfo.ThreadChannel = CONFIG_OPENTHREAD_CHANNEL;
47
48     chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false);
49     chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(deviceNetworkInfo);
50     chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true);
51 }