1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <vector> 20 21 #include "module.h" 22 23 namespace bluetooth { 24 namespace hal { 25 26 using HciPacket = std::vector<uint8_t>; 27 28 enum class Status : int32_t { SUCCESS, TRANSPORT_ERROR, INITIALIZATION_ERROR, UNKNOWN }; 29 30 // Mirrors hardware/interfaces/bluetooth/1.0/IBluetoothHciCallbacks.hal in Android, but moved initializationComplete 31 // callback to BluetoothInitializationCompleteCallback 32 33 // The interface from the Bluetooth Controller to the stack 34 class HciHalCallbacks { 35 public: 36 virtual ~HciHalCallbacks() = default; 37 38 // This function is invoked when an HCI event is received from the 39 // Bluetooth controller to be forwarded to the Bluetooth stack 40 // @param event is the HCI event to be sent to the Bluetooth stack 41 virtual void hciEventReceived(HciPacket event) = 0; 42 43 // Send an ACL data packet form the controller to the host 44 // @param data the ACL HCI packet to be passed to the host stack 45 virtual void aclDataReceived(HciPacket data) = 0; 46 47 // Send a SCO data packet form the controller to the host 48 // @param data the SCO HCI packet to be passed to the host stack 49 virtual void scoDataReceived(HciPacket data) = 0; 50 }; 51 52 // Mirrors hardware/interfaces/bluetooth/1.0/IBluetoothHci.hal in Android 53 // The Host Controller Interface (HCI) is the layer defined by the Bluetooth 54 // specification between the software that runs on the host and the Bluetooth 55 // controller chip. This boundary is the natural choice for a Hardware 56 // Abstraction Layer (HAL). Dealing only in HCI packets and events simplifies 57 // the stack and abstracts away power management, initialization, and other 58 // implementation-specific details related to the hardware. 59 class HciHal : public ::bluetooth::Module { 60 public: 61 static const ModuleFactory Factory; 62 63 virtual ~HciHal() = default; 64 65 // Register the callback for incoming packets. All incoming packets are dropped before 66 // this callback is registered. Callback can only be registered once. 67 // 68 // @param callback implements BluetoothHciHalCallbacks which will 69 // receive callbacks when incoming HCI packets are received 70 // from the controller to be sent to the host. 71 virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0; 72 73 // Unregister the callback for incoming packets. Drop all further incoming packets. 74 virtual void unregisterIncomingPacketCallback() = 0; 75 76 // Send an HCI command (as specified in the Bluetooth Specification 77 // V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller. 78 // Commands must be executed in order. 79 virtual void sendHciCommand(HciPacket command) = 0; 80 81 // Send an HCI ACL data packet (as specified in the Bluetooth Specification 82 // V4.2, Vol 2, Part 5, Section 5.4.2) to the Bluetooth controller. 83 // Packets must be processed in order. 84 virtual void sendAclData(HciPacket data) = 0; 85 86 // Send an SCO data packet (as specified in the Bluetooth Specification 87 // V4.2, Vol 2, Part 5, Section 5.4.3) to the Bluetooth controller. 88 // Packets must be processed in order. 89 virtual void sendScoData(HciPacket data) = 0; 90 }; 91 92 } // namespace hal 93 } // namespace bluetooth 94