4 * Copyright (c) 2020 Project CHIP Authors
5 * Copyright (c) 2014-2017 Nest Labs, Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <ble/BleLayer.h>
23 #include <ble/BlePlatformDelegate.h>
25 typedef bool (*WriteBleCharacteristicCBFunct)(void * connObj, const void * svcId, const void * charId, const void * buffer,
27 typedef bool (*SubscribeBleCharacteristicCBFunct)(void * connObj, const void * svcId, const void * charId, bool subscribe);
28 typedef bool (*CloseBleCBFunct)(void * connObj);
30 class DeviceController_BlePlatformDelegate : public chip::Ble::BlePlatformDelegate
33 DeviceController_BlePlatformDelegate(chip::Ble::BleLayer * ble);
35 // Set callback used to send GATT write request
36 inline void SetWriteCharCB(WriteBleCharacteristicCBFunct cb) { writeCB = cb; };
37 inline void SetSubscribeCharCB(SubscribeBleCharacteristicCBFunct cb) { subscribeCB = cb; };
38 inline void SetCloseCB(CloseBleCBFunct cb) { closeCB = cb; };
40 // Virtuals from BlePlatformDelegate:
41 bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
42 const chip::Ble::ChipBleUUID * charId);
43 bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
44 const chip::Ble::ChipBleUUID * charId);
45 bool CloseConnection(BLE_CONNECTION_OBJECT connObj);
46 uint16_t GetMTU(BLE_CONNECTION_OBJECT connObj) const;
47 bool SendIndication(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId,
48 chip::System::PacketBufferHandle pBuf);
49 bool SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
50 const chip::Ble::ChipBleUUID * charId, chip::System::PacketBufferHandle pBuf);
51 bool SendReadRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId,
52 chip::System::PacketBufferHandle pBuf);
53 bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext,
54 const chip::Ble::ChipBleUUID * svcId, const chip::Ble::ChipBleUUID * charId);
57 chip::Ble::BleLayer * Ble;
58 WriteBleCharacteristicCBFunct writeCB;
59 SubscribeBleCharacteristicCBFunct subscribeCB;
60 CloseBleCBFunct closeCB;