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