3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2014-2017 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include "ChipDeviceController-BlePlatformDelegate.h"
21 #include <ble/BlePlatformDelegate.h>
23 using namespace chip::Ble;
25 DeviceController_BlePlatformDelegate::DeviceController_BlePlatformDelegate(BleLayer * ble)
33 bool DeviceController_BlePlatformDelegate::SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj,
34 const chip::Ble::ChipBleUUID * svcId,
35 const chip::Ble::ChipBleUUID * charId)
37 const bool subscribe = true;
39 if (subscribeCB && svcId && charId)
41 return subscribeCB(connObj, static_cast<const void *>(svcId->bytes), static_cast<const void *>(charId->bytes), subscribe);
47 bool DeviceController_BlePlatformDelegate::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj,
48 const chip::Ble::ChipBleUUID * svcId,
49 const chip::Ble::ChipBleUUID * charId)
51 const bool subscribe = true;
53 if (subscribeCB && svcId && charId)
55 return subscribeCB(connObj, static_cast<const void *>(svcId->bytes), static_cast<const void *>(charId->bytes), !subscribe);
61 bool DeviceController_BlePlatformDelegate::CloseConnection(BLE_CONNECTION_OBJECT connObj)
65 return closeCB(connObj);
71 uint16_t DeviceController_BlePlatformDelegate::GetMTU(BLE_CONNECTION_OBJECT connObj) const
73 // TODO Python queue-based implementation
77 bool DeviceController_BlePlatformDelegate::SendIndication(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
78 const chip::Ble::ChipBleUUID * charId,
79 chip::System::PacketBufferHandle pBuf)
81 // TODO Python queue-based implementation
83 // Going out of scope releases delegate's reference to pBuf. pBuf will be freed when both platform delegate and Chip stack free
84 // their references to it.
88 bool DeviceController_BlePlatformDelegate::SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
89 const chip::Ble::ChipBleUUID * charId,
90 chip::System::PacketBufferHandle pBuf)
94 if (writeCB && svcId && charId && !pBuf.IsNull())
96 ret = writeCB(connObj, static_cast<const void *>(svcId->bytes), static_cast<const void *>(charId->bytes),
97 static_cast<void *>(pBuf->Start()), pBuf->DataLength());
100 // Going out of scope releases delegate's reference to pBuf. pBuf will be freed when both platform delegate and Chip stack free
101 // their references to it. We release pBuf's reference here since its payload bytes were copied into a new NSData object by
102 // ChipBleMgr.py's writeCB, and in both the error and succees cases this code has no further use for the pBuf PacketBuffer.
106 bool DeviceController_BlePlatformDelegate::SendReadRequest(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBleUUID * svcId,
107 const chip::Ble::ChipBleUUID * charId,
108 chip::System::PacketBufferHandle pBuf)
110 // TODO Python queue-based implementation
114 bool DeviceController_BlePlatformDelegate::SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext,
115 const chip::Ble::ChipBleUUID * svcId,
116 const chip::Ble::ChipBleUUID * charId)
118 // TODO Python queue-based implementation