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 // LINT.IfChange 60 class HciHal : public ::bluetooth::Module { 61 public: 62 static const ModuleFactory Factory; 63 64 virtual ~HciHal() = default; 65 66 // Register the callback for incoming packets. All incoming packets are dropped before 67 // this callback is registered. Callback can only be registered once. 68 // 69 // @param callback implements BluetoothHciHalCallbacks which will 70 // receive callbacks when incoming HCI packets are received 71 // from the controller to be sent to the host. 72 virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0; 73 74 // Unregister the callback for incoming packets. Drop all further incoming packets. 75 virtual void unregisterIncomingPacketCallback() = 0; 76 77 // Send an HCI command (as specified in the Bluetooth Specification 78 // V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller. 79 // Commands must be executed in order. 80 virtual void sendHciCommand(HciPacket command) = 0; 81 82 // Send an HCI ACL data packet (as specified in the Bluetooth Specification 83 // V4.2, Vol 2, Part 5, Section 5.4.2) to the Bluetooth controller. 84 // Packets must be processed in order. 85 virtual void sendAclData(HciPacket data) = 0; 86 87 // Send an SCO data packet (as specified in the Bluetooth Specification 88 // V4.2, Vol 2, Part 5, Section 5.4.3) to the Bluetooth controller. 89 // Packets must be processed in order. 90 virtual void sendScoData(HciPacket data) = 0; 91 }; 92 // LINT.ThenChange(fuzz/fuzz_hci_hal.h) 93 94 } // namespace hal 95 } // namespace bluetooth 96