• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static const uint16_t kDefaultGattMtu = 23;
36 
37 static const bluetooth::Uuid kRangingService = 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 }  // namespace feature
63 
64 enum class Opcode : uint8_t {
65   GET_RANGING_DATA = 0x00,
66   ACK_RANGING_DATA = 0x01,
67   RETRIEVE_LOST_RANGING_DATA_SEGMENTS = 0x02,
68   ABORT_OPERATION = 0x03,
69   FILTER = 0x04,
70 };
71 
72 static const uint8_t OPERATOR_NULL = 0x00;
73 
74 std::string GetOpcodeText(Opcode opcode);
75 
76 enum class EventCode : uint8_t {
77   COMPLETE_RANGING_DATA_RESPONSE = 0x00,
78   COMPLETE_LOST_RANGING_DATA_SEGMENT_RESPONSE = 0x01,
79   RESPONSE_CODE = 0x02,
80 };
81 
82 enum class ResponseCodeValue : uint8_t {
83   RESERVED_FOR_FUTURE_USE = 0x00,
84   SUCCESS = 0x01,
85   OP_CODE_NOT_SUPPORTED = 0x02,
86   INVALID_PARAMETER = 0x03,
87   PERSISTED = 0x04,
88   ABORT_UNSUCCESSFUL = 0x05,
89   PROCEDURE_NOT_COMPLETED = 0x06,
90   SERVER_BUSY = 0x07,
91   NO_RECORDS_FOUND = 0x08,
92 };
93 
94 std::string GetResponseOpcodeValueText(ResponseCodeValue response_code_value);
95 
96 struct ControlPointCommand {
97   Opcode opcode_;
98   uint8_t parameter_[4];
99   bool isValid_;
100 };
101 
102 struct ControlPointResponse {
103   EventCode event_code_;
104   uint8_t parameter_[4];
105 };
106 
107 bool ParseControlPointCommand(ControlPointCommand* command, const uint8_t* value, uint16_t len);
108 
109 bool IsRangingServiceCharacteristic(const bluetooth::Uuid& uuid);
110 
111 }  // namespace ras
112