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 "bluetooth/uuid.h" 20 21 namespace ras { 22 static const uint16_t kFeatureSize = 0x04; 23 static const uint16_t kRingingCounterSize = 0x02; 24 static const uint16_t kCccValueSize = 0x02; 25 26 namespace uuid { 27 static const uint16_t kRangingService16Bit = 0x7F7D; 28 static const uint16_t kRasFeaturesCharacteristic16bit = 0x7F7C; 29 static const uint16_t kRasRealTimeRangingDataCharacteristic16bit = 0x7F7B; 30 static const uint16_t kRasOnDemandDataCharacteristic16bit = 0x7F7A; 31 static const uint16_t kRasControlPointCharacteristic16bit = 0x7F79; 32 static const uint16_t kRasRangingDataReadyCharacteristic16bit = 0x7F78; 33 static const uint16_t kRasRangingDataOverWrittenCharacteristic16bit = 0x7F77; 34 static const uint16_t kClientCharacteristicConfiguration16bit = 0x2902; 35 36 static const bluetooth::Uuid kRangingService = 37 bluetooth::Uuid::From16Bit(kRangingService16Bit); 38 static const bluetooth::Uuid kRasFeaturesCharacteristic = 39 bluetooth::Uuid::From16Bit(kRasFeaturesCharacteristic16bit); 40 static const bluetooth::Uuid kRasRealTimeRangingDataCharacteristic = 41 bluetooth::Uuid::From16Bit(kRasRealTimeRangingDataCharacteristic16bit); 42 static const bluetooth::Uuid kRasOnDemandDataCharacteristic = 43 bluetooth::Uuid::From16Bit(kRasOnDemandDataCharacteristic16bit); 44 static const bluetooth::Uuid kRasControlPointCharacteristic = 45 bluetooth::Uuid::From16Bit(kRasControlPointCharacteristic16bit); 46 static const bluetooth::Uuid kRasRangingDataReadyCharacteristic = 47 bluetooth::Uuid::From16Bit(kRasRangingDataReadyCharacteristic16bit); 48 static const bluetooth::Uuid kRasRangingDataOverWrittenCharacteristic = 49 bluetooth::Uuid::From16Bit(kRasRangingDataOverWrittenCharacteristic16bit); 50 static const bluetooth::Uuid kClientCharacteristicConfiguration = 51 bluetooth::Uuid::From16Bit(kClientCharacteristicConfiguration16bit); 52 53 std::string getUuidName(const bluetooth::Uuid& uuid); 54 55 } // namespace uuid 56 57 namespace feature { 58 static const uint32_t kRealTimeRangingData = 0x01; 59 static const uint32_t kRetrieveLostRangingDataSegments = 0x02; 60 static const uint32_t kAbortOperation = 0x04; 61 static const uint32_t kFilterRangingData = 0x08; 62 static const uint32_t kPctPhaseFormat = 0xA0; 63 } // namespace feature 64 65 enum class Opcode : uint8_t { 66 GET_RANGING_DATA = 0x00, 67 ACK_RANGING_DATA = 0x01, 68 RETRIEVE_LOST_RANGING_DATA_SEGMENTS = 0x02, 69 ABORT_OPERATION = 0x03, 70 FILTER = 0x04, 71 PCT_FORMAT = 0x05, 72 }; 73 74 static const uint8_t OPERATOR_NULL = 0x00; 75 76 std::string GetOpcodeText(Opcode opcode); 77 78 enum class EventCode : uint8_t { 79 COMPLETE_RANGING_DATA_RESPONSE = 0x00, 80 COMPLETE_LOST_RANGING_DATA_SEGMENT_RESPONSE = 0x01, 81 RESPONSE_CODE = 0x02, 82 }; 83 84 enum class ResponseCodeValue : uint8_t { 85 RESERVED_FOR_FUTURE_USE = 0x00, 86 SUCCESS = 0x01, 87 OP_CODE_NOT_SUPPORTED = 0x02, 88 INVALID_OPERATOR = 0x03, 89 OPERATOR_NOT_SUPPORTED = 0x04, 90 INVALID_OPERAND = 0x05, 91 ABORT_UNSUCCESSFUL = 0x06, 92 PROCEDURE_NOT_COMPLETED = 0x07, 93 OPERAND_NOT_SUPPORTED = 0x08, 94 NO_RECORDS_FOUND = 0x09, 95 }; 96 97 std::string GetResponseOpcodeValueText(ResponseCodeValue response_code_value); 98 99 struct ControlPointCommand { 100 Opcode opcode_; 101 uint8_t parameter_[4]; 102 }; 103 104 struct ControlPointResponse { 105 EventCode event_code_; 106 uint8_t parameter_[4]; 107 }; 108 109 bool ParseControlPointCommand(ControlPointCommand* command, 110 const uint8_t* value, uint16_t len); 111 112 bool IsRangingServiceCharacteristic(const bluetooth::Uuid& uuid); 113 114 } // namespace ras 115