1 /*
2  * Copyright (C) 2021 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 package com.google.uwb.support.ccc;
18 
19 import android.os.Build.VERSION_CODES;
20 import android.os.PersistableBundle;
21 
22 import androidx.annotation.IntDef;
23 import androidx.annotation.IntRange;
24 import androidx.annotation.RequiresApi;
25 
26 import com.google.uwb.support.base.Params;
27 
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 
31 /** Defines parameters for CCC operation */
32 @RequiresApi(VERSION_CODES.LOLLIPOP)
33 public abstract class CccParams extends Params {
34     public static final String PROTOCOL_NAME = "ccc";
35 
36     @Override
getProtocolName()37     public final String getProtocolName() {
38         return PROTOCOL_NAME;
39     }
40 
isCorrectProtocol(PersistableBundle bundle)41     public static boolean isCorrectProtocol(PersistableBundle bundle) {
42         return isProtocol(bundle, PROTOCOL_NAME);
43     }
44 
isCorrectProtocol(String protocolName)45     public static boolean isCorrectProtocol(String protocolName) {
46         return protocolName.equals(PROTOCOL_NAME);
47     }
48 
49     public static final CccProtocolVersion PROTOCOL_VERSION_1_0 = new CccProtocolVersion(1, 0);
50 
51     /** Pulse Shapse (details below) */
52     @Retention(RetentionPolicy.SOURCE)
53     @IntDef(
54             value = {
55                 PULSE_SHAPE_SYMMETRICAL_ROOT_RAISED_COSINE,
56                 PULSE_SHAPE_PRECURSOR_FREE,
57                 PULSE_SHAPE_PRECURSOR_FREE_SPECIAL
58             })
59     public @interface PulseShape {}
60 
61     /**
62      * Indicates the symmetrical root raised cosine pulse shape as defined by Digital Key R3 Section
63      * 21.5.
64      */
65     public static final int PULSE_SHAPE_SYMMETRICAL_ROOT_RAISED_COSINE = 0x0;
66 
67     /** Indicates the precursor-free pulse shape as defined by Digital Key R3 Section 21.5. */
68     public static final int PULSE_SHAPE_PRECURSOR_FREE = 0x1;
69 
70     /**
71      * Indicates a special case of the precursor-free pulse shape as defined by Digital Key R3
72      * Section 21.5.
73      */
74     public static final int PULSE_SHAPE_PRECURSOR_FREE_SPECIAL = 0x2;
75 
76     /** Config (details below) */
77     @Retention(RetentionPolicy.SOURCE)
78     @IntDef(
79             value = {
80                 UWB_CONFIG_0,
81                 UWB_CONFIG_1,
82             })
83     public @interface UwbConfig {}
84 
85     /** Indicates UWB Config 0 as defined by Digital Key R3 Section 21.4. */
86     public static final int UWB_CONFIG_0 = 0;
87 
88     /** Indicates UWB Config 1 as defined by Digital Key R3 Section 21.4. */
89     public static final int UWB_CONFIG_1 = 1;
90 
91     /** Channels */
92     @Retention(RetentionPolicy.SOURCE)
93     @IntDef(
94             value = {
95                 UWB_CHANNEL_5,
96                 UWB_CHANNEL_9,
97             })
98     public @interface Channel {}
99 
100     public static final int UWB_CHANNEL_5 = 5;
101     public static final int UWB_CHANNEL_9 = 9;
102 
103     /** Sync Codes */
104     @Retention(RetentionPolicy.SOURCE)
105     @IntRange(from = 1, to = 32)
106     public @interface SyncCodeIndex {}
107 
108     /** Hopping Config */
109     @Retention(RetentionPolicy.SOURCE)
110     @IntDef(
111             value = {
112                 HOPPING_CONFIG_MODE_NONE,
113                 HOPPING_CONFIG_MODE_CONTINUOUS,
114                 HOPPING_CONFIG_MODE_ADAPTIVE,
115             })
116     public @interface HoppingConfigMode {}
117 
118     public static final int HOPPING_CONFIG_MODE_NONE = 0;
119     public static final int HOPPING_CONFIG_MODE_CONTINUOUS = 1;
120     public static final int HOPPING_CONFIG_MODE_ADAPTIVE = 2;
121 
122     /** Hopping Sequence */
123     @Retention(RetentionPolicy.SOURCE)
124     @IntDef(
125             value = {
126                 HOPPING_SEQUENCE_DEFAULT,
127                 HOPPING_SEQUENCE_AES,
128             })
129     public @interface HoppingSequence {}
130 
131     public static final int HOPPING_SEQUENCE_DEFAULT = 0;
132     public static final int HOPPING_SEQUENCE_AES = 1;
133 
134     /** Chaps per Slot (i.e. slot duration) */
135     @Retention(RetentionPolicy.SOURCE)
136     @IntDef(
137             value = {
138                 CHAPS_PER_SLOT_3,
139                 CHAPS_PER_SLOT_4,
140                 CHAPS_PER_SLOT_6,
141                 CHAPS_PER_SLOT_8,
142                 CHAPS_PER_SLOT_9,
143                 CHAPS_PER_SLOT_12,
144                 CHAPS_PER_SLOT_24,
145             })
146     public @interface ChapsPerSlot {}
147 
148     public static final int CHAPS_PER_SLOT_3 = 3;
149     public static final int CHAPS_PER_SLOT_4 = 4;
150     public static final int CHAPS_PER_SLOT_6 = 6;
151     public static final int CHAPS_PER_SLOT_8 = 8;
152     public static final int CHAPS_PER_SLOT_9 = 9;
153     public static final int CHAPS_PER_SLOT_12 = 12;
154     public static final int CHAPS_PER_SLOT_24 = 24;
155 
156     /** Slots per Round */
157     @Retention(RetentionPolicy.SOURCE)
158     @IntDef(
159             value = {
160                 SLOTS_PER_ROUND_6,
161                 SLOTS_PER_ROUND_8,
162                 SLOTS_PER_ROUND_9,
163                 SLOTS_PER_ROUND_12,
164                 SLOTS_PER_ROUND_16,
165                 SLOTS_PER_ROUND_18,
166                 SLOTS_PER_ROUND_24,
167                 SLOTS_PER_ROUND_32,
168                 SLOTS_PER_ROUND_36,
169                 SLOTS_PER_ROUND_48,
170                 SLOTS_PER_ROUND_72,
171                 SLOTS_PER_ROUND_96,
172             })
173     public @interface SlotsPerRound {}
174 
175     public static final int SLOTS_PER_ROUND_6 = 6;
176     public static final int SLOTS_PER_ROUND_8 = 8;
177     public static final int SLOTS_PER_ROUND_9 = 9;
178     public static final int SLOTS_PER_ROUND_12 = 12;
179     public static final int SLOTS_PER_ROUND_16 = 16;
180     public static final int SLOTS_PER_ROUND_18 = 18;
181     public static final int SLOTS_PER_ROUND_24 = 24;
182     public static final int SLOTS_PER_ROUND_32 = 32;
183     public static final int SLOTS_PER_ROUND_36 = 36;
184     public static final int SLOTS_PER_ROUND_48 = 48;
185     public static final int SLOTS_PER_ROUND_72 = 72;
186     public static final int SLOTS_PER_ROUND_96 = 96;
187 
188     /** Error Reason */
189     @Retention(RetentionPolicy.SOURCE)
190     @IntDef(
191             value = {
192                 PROTOCOL_ERROR_UNKNOWN,
193                 PROTOCOL_ERROR_SE_BUSY,
194                 PROTOCOL_ERROR_LIFECYCLE,
195                 PROTOCOL_ERROR_NOT_FOUND,
196             })
197     public @interface ProtocolError {}
198 
199     public static final int PROTOCOL_ERROR_UNKNOWN = 0;
200     public static final int PROTOCOL_ERROR_SE_BUSY = 1;
201     public static final int PROTOCOL_ERROR_LIFECYCLE = 2;
202     public static final int PROTOCOL_ERROR_NOT_FOUND = 3;
203 
204     /** Session Type */
205     @Retention(RetentionPolicy.SOURCE)
206     @IntDef(
207             value = {SESSION_TYPE_CCC})
208     public @interface SessionType {}
209 
210     /** Range Data Notification Config */
211     @IntDef(
212             value = {
213                 RANGE_DATA_NTF_CONFIG_DISABLE,
214                 RANGE_DATA_NTF_CONFIG_ENABLE,
215                 RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_LEVEL_TRIG,
216                 RANGE_DATA_NTF_CONFIG_ENABLE_AOA_LEVEL_TRIG,
217                 RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_LEVEL_TRIG,
218                 RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_EDGE_TRIG,
219                 RANGE_DATA_NTF_CONFIG_ENABLE_AOA_EDGE_TRIG,
220                 RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_EDGE_TRIG,
221             })
222     public @interface RangeDataNtfConfig {}
223 
224     public static final int RANGE_DATA_NTF_CONFIG_DISABLE = 0;
225     public static final int RANGE_DATA_NTF_CONFIG_ENABLE = 1;
226     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_LEVEL_TRIG = 2;
227     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_AOA_LEVEL_TRIG = 3;
228     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_LEVEL_TRIG = 4;
229     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_EDGE_TRIG = 5;
230     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_AOA_EDGE_TRIG = 6;
231     public static final int RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_EDGE_TRIG = 7;
232 
233     public static final int RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT = 0;
234     public static final int RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT = 20000;
235     public static final double RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT = -Math.PI;
236     public static final double RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT = Math.PI;
237     public static final double RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT = -Math.PI / 2;
238     public static final double RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT = Math.PI / 2;
239 
240     public static final int SESSION_TYPE_CCC = 160;
241 
242     public static final long UWB_INITIATION_TIME_MS_UNSET = 0;
243 
244     public static final int STS_INDEX_UNSET = 0;
245 }
246