1 /* 2 * Copyright 2024 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 <complex> 20 21 #include "module.h" 22 23 namespace bluetooth { 24 namespace hal { 25 26 struct VendorSpecificCharacteristic { 27 std::array<uint8_t, 16> characteristicUuid_; 28 std::vector<uint8_t> value_; 29 }; 30 31 struct ChannelSoundingRawData { 32 uint8_t num_antenna_paths_; 33 std::vector<uint8_t> step_channel_; 34 std::vector<std::vector<std::complex<double>>> tone_pct_initiator_; 35 std::vector<std::vector<std::complex<double>>> tone_pct_reflector_; 36 std::vector<std::vector<uint8_t>> tone_quality_indicator_initiator_; 37 std::vector<std::vector<uint8_t>> tone_quality_indicator_reflector_; 38 }; 39 40 struct RangingResult { 41 double result_meters_; 42 }; 43 44 class RangingHalCallback { 45 public: 46 virtual ~RangingHalCallback() = default; 47 virtual void OnOpened( 48 uint16_t connection_handle, 49 const std::vector<VendorSpecificCharacteristic>& vendor_specific_reply) = 0; 50 virtual void OnOpenFailed(uint16_t connection_handle) = 0; 51 virtual void OnHandleVendorSpecificReplyComplete(uint16_t connection_handle, bool success) = 0; 52 virtual void OnResult(uint16_t connection_handle, const RangingResult& ranging_result) = 0; 53 }; 54 55 class RangingHal : public ::bluetooth::Module { 56 public: 57 static const ModuleFactory Factory; 58 59 virtual ~RangingHal() = default; 60 virtual bool IsBound() = 0; 61 virtual void RegisterCallback(RangingHalCallback* callback) = 0; 62 virtual std::vector<VendorSpecificCharacteristic> GetVendorSpecificCharacteristics() = 0; 63 virtual void OpenSession( 64 uint16_t connection_handle, 65 uint16_t att_handle, 66 const std::vector<hal::VendorSpecificCharacteristic>& vendor_specific_data) = 0; 67 virtual void HandleVendorSpecificReply( 68 uint16_t connection_handle, 69 const std::vector<hal::VendorSpecificCharacteristic>& vendor_specific_reply) = 0; 70 virtual void WriteRawData(uint16_t connection_handle, const ChannelSoundingRawData& raw_data) = 0; 71 }; 72 73 } // namespace hal 74 } // namespace bluetooth 75