blob: 0c56e4800c64ccba09bcbaf0e3f46ab1f446a2aa [file] [log] [blame]
Pankaj Garg362e2a32020-03-10 13:54:37 -07001/*
2 *
Rob Walkere812e672020-03-31 17:51:57 -07003 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2014-2017 Nest Labs, Inc.
Pankaj Garg362e2a32020-03-10 13:54:37 -07005 *
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 Litvin1873e8c2020-10-12 10:52:26 -040025#pragma once
Pankaj Garg362e2a32020-03-10 13:54:37 -070026
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070027#include <ble/BleConfig.h>
Martin Turon78026542020-03-17 17:24:59 -070028
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070029#include <ble/BleUUID.h>
Pankaj Garg362e2a32020-03-10 13:54:37 -070030
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070031#include <support/DLLUtil.h>
Rob Walker5bbe5c02020-05-13 15:05:11 -070032#include <system/SystemPacketBuffer.h>
Pankaj Garg362e2a32020-03-10 13:54:37 -070033
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070034namespace chip {
Pankaj Garg362e2a32020-03-10 13:54:37 -070035namespace Ble {
36
Kevin Schoedel316a6f52020-12-01 14:49:51 -050037using ::chip::System::PacketBufferHandle;
Pankaj Garg362e2a32020-03-10 13:54:37 -070038
39// Platform-agnostic BLE interface
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070040class DLL_EXPORT BlePlatformDelegate
Pankaj Garg362e2a32020-03-10 13:54:37 -070041{
42public:
Vivien Nicolas7c14a332020-11-13 18:53:48 +010043 virtual ~BlePlatformDelegate() {}
44
Pankaj Garg362e2a32020-03-10 13:54:37 -070045 // Following APIs must be implemented by platform:
46
47 // Subscribe to updates and indications on the specfied characteristic
Pankaj Garg43c9c682020-03-20 15:06:18 -070048 virtual bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070049
50 // Unsubscribe from updates and indications on the specified characteristic
Pankaj Garg43c9c682020-03-20 15:06:18 -070051 virtual bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId,
52 const ChipBleUUID * charId) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070053
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 Garg362e2a32020-03-10 13:54:37 -070061 // 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 Gargfe3bbc82020-03-10 14:27:26 -070063 // value of chipConnection::SendMessage.
Pankaj Garg362e2a32020-03-10 13:54:37 -070064
65 // Send GATT characteristic indication request
Pankaj Garg43c9c682020-03-20 15:06:18 -070066 virtual bool SendIndication(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId,
Kevin Schoedel316a6f52020-12-01 14:49:51 -050067 PacketBufferHandle pBuf) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070068
69 // Send GATT characteristic write request
Pankaj Garg43c9c682020-03-20 15:06:18 -070070 virtual bool SendWriteRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId,
Kevin Schoedel316a6f52020-12-01 14:49:51 -050071 PacketBufferHandle pBuf) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070072
73 // Send GATT characteristic read request
Pankaj Garg43c9c682020-03-20 15:06:18 -070074 virtual bool SendReadRequest(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId,
Kevin Schoedel316a6f52020-12-01 14:49:51 -050075 PacketBufferHandle pBuf) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070076
77 // Send response to remote host's GATT chacteristic read response
Pankaj Garg43c9c682020-03-20 15:06:18 -070078 virtual bool SendReadResponse(BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId,
79 const ChipBleUUID * charId) = 0;
Pankaj Garg362e2a32020-03-10 13:54:37 -070080};
81
82} /* namespace Ble */
Pankaj Gargfe3bbc82020-03-10 14:27:26 -070083} /* namespace chip */