3 * Copyright (c) 2020 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "ThreadUtil.h"
21 #include <platform/CHIPDeviceLayer.h>
22 #include <platform/internal/DeviceNetworkInfo.h>
28 void StartDefaultThreadNetwork(void)
30 chip::DeviceLayer::Internal::DeviceNetworkInfo deviceNetworkInfo;
31 memset(&deviceNetworkInfo, 0, sizeof(deviceNetworkInfo));
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
36 const uint8_t threadMeshPrefix[chip::DeviceLayer::Internal::kThreadMeshPrefixLength] = { 0xfd, 0x11, 0x11, 0x11,
37 0x11, 0x22, 0x00, 0x00 };
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;
48 chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false);
49 chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(deviceNetworkInfo);
50 chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true);