3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * This file implements the CHIP Device Interface that is used by
21 * applications to interact with the CHIP stack
27 #include "CHIPDeviceManager.h"
28 #include <app/util/basic-types.h>
29 #include <setup_payload/SetupPayload.h>
30 #include <support/CHIPMem.h>
31 #include <support/CodeUtils.h>
32 #include <support/ErrorStr.h>
34 using namespace ::chip;
38 namespace DeviceManager {
40 using namespace ::chip::DeviceLayer;
42 void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
44 CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
47 cb->DeviceEventCallback(event, reinterpret_cast<intptr_t>(cb));
54 CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
59 // Initialize the CHIP stack.
60 err = PlatformMgr().InitChipStack();
63 switch (static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE))
65 case RendezvousInformationFlags::kBLE:
66 ConnectivityMgr().SetBLEAdvertisingEnabled(true);
69 case RendezvousInformationFlags::kWiFi:
70 ConnectivityMgr().SetBLEAdvertisingEnabled(false);
71 ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
74 case RendezvousInformationFlags::kNone:
75 // If rendezvous is bypassed, enable SoftAP so that the device can still
76 // be communicated with via its SoftAP as needed.
77 ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
84 err = Platform::MemoryInit();
87 // Register a function to receive events from the CHIP device layer. Note that calls to
88 // this function will happen on the CHIP event loop thread, not the app_main thread.
89 PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
91 // Start a task to run the CHIP Device event loop.
92 err = PlatformMgr().StartEventLoopTask();
98 } // namespace DeviceManager
101 void emberAfPostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
102 uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value)
104 chip::DeviceManager::CHIPDeviceManagerCallbacks * cb =
105 chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks();
108 cb->PostAttributeChangeCallback(endpointId, clusterId, attributeId, mask, manufacturerCode, type, size, value);