Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Rob Walker | e812e67 | 2020-03-31 17:51:57 -0700 | [diff] [blame] | 3 | * Copyright (c) 2020 Project CHIP Authors |
| 4 | * Copyright (c) 2014-2017 Nest Labs, Inc. |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 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 | /** |
| 20 | * @file |
| 21 | * This file defines the interface for downcalls from BleLayer |
| 22 | * to a platform's BLE framework. |
| 23 | */ |
| 24 | |
Andrei Litvin | 1873e8c | 2020-10-12 10:52:26 -0400 | [diff] [blame] | 25 | #pragma once |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 26 | |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 27 | #include <ble/BleConfig.h> |
Martin Turon | 7802654 | 2020-03-17 17:24:59 -0700 | [diff] [blame] | 28 | |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 29 | #include <ble/BleUUID.h> |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 30 | |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 31 | #include <support/DLLUtil.h> |
Rob Walker | 5bbe5c0 | 2020-05-13 15:05:11 -0700 | [diff] [blame] | 32 | #include <system/SystemPacketBuffer.h> |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 33 | |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 34 | namespace chip { |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 35 | namespace Ble { |
| 36 | |
Kevin Schoedel | 316a6f5 | 2020-12-01 14:49:51 -0500 | [diff] [blame] | 37 | using ::chip::System::PacketBufferHandle; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 38 | |
| 39 | // Platform-agnostic BLE interface |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 40 | class DLL_EXPORT BlePlatformDelegate |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 41 | { |
| 42 | public: |
Vivien Nicolas | 7c14a33 | 2020-11-13 18:53:48 +0100 | [diff] [blame] | 43 | virtual ~BlePlatformDelegate() {} |
| 44 | |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 45 | // Following APIs must be implemented by platform: |
| 46 | |
| 47 | // Subscribe to updates and indications on the specfied characteristic |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 48 | virtual bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 49 | |
| 50 | // Unsubscribe from updates and indications on the specified characteristic |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 51 | virtual bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, |
| 52 | const ChipBleUUID * charId) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 53 | |
| 54 | // Close the underlying BLE connection. |
| 55 | virtual bool CloseConnection(BLE_CONNECTION_OBJECT connObj) = 0; |
| 56 | |
| 57 | // Get MTU size negotiated for specified BLE connection. Return value of 0 means MTU size could not be determined. |
| 58 | virtual uint16_t GetMTU(BLE_CONNECTION_OBJECT connObj) const = 0; |
| 59 | |
| 60 | // Data path calling convention: |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 61 | // A 'true' return value from a Send* function indicates that the characteristic was written or updated |
| 62 | // successfully. A 'false' value indicates failure, and is used to report this failure to the user via the return |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 63 | // value of chipConnection::SendMessage. |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 64 | |
| 65 | // Send GATT characteristic indication request |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 66 | virtual bool SendIndication(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId, |
Kevin Schoedel | 316a6f5 | 2020-12-01 14:49:51 -0500 | [diff] [blame] | 67 | PacketBufferHandle pBuf) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 68 | |
| 69 | // Send GATT characteristic write request |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 70 | virtual bool SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId, |
Kevin Schoedel | 316a6f5 | 2020-12-01 14:49:51 -0500 | [diff] [blame] | 71 | PacketBufferHandle pBuf) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 72 | |
| 73 | // Send GATT characteristic read request |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 74 | virtual bool SendReadRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId, |
Kevin Schoedel | 316a6f5 | 2020-12-01 14:49:51 -0500 | [diff] [blame] | 75 | PacketBufferHandle pBuf) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 76 | |
| 77 | // Send response to remote host's GATT chacteristic read response |
Pankaj Garg | 43c9c68 | 2020-03-20 15:06:18 -0700 | [diff] [blame] | 78 | virtual bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, |
| 79 | const ChipBleUUID * charId) = 0; |
Pankaj Garg | 362e2a3 | 2020-03-10 13:54:37 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } /* namespace Ble */ |
Pankaj Garg | fe3bbc8 | 2020-03-10 14:27:26 -0700 | [diff] [blame] | 83 | } /* namespace chip */ |