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.fira;
18 
19 import static com.google.common.base.Preconditions.checkArgument;
20 import static com.google.common.base.Preconditions.checkNotNull;
21 
22 import static java.util.Objects.requireNonNull;
23 
24 import android.os.PersistableBundle;
25 import android.uwb.UwbAddress;
26 import android.uwb.UwbManager;
27 
28 import androidx.annotation.FloatRange;
29 import androidx.annotation.IntRange;
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 
33 import com.google.uwb.support.base.RequiredParam;
34 
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38 
39 /**
40  * UWB parameters used to open a FiRa session.
41  *
42  * <p>This is passed as a bundle to the service API {@link UwbManager#openRangingSession}.
43  */
44 public class FiraOpenSessionParams extends FiraParams {
45     private final FiraProtocolVersion mProtocolVersion;
46 
47     private final int mSessionId;
48     @SessionType private final int mSessionType;
49     @RangingDeviceType private final int mDeviceType;
50     @RangingDeviceRole private final int mDeviceRole;
51     @RangingRoundUsage private final int mRangingRoundUsage;
52     @MultiNodeMode private final int mMultiNodeMode;
53 
54     private final UwbAddress mDeviceAddress;
55 
56     // Dest address list
57     private final List<UwbAddress> mDestAddressList;
58 
59     // FiRa 1.0: Relative time (in milli-seconds).
60     // FiRa 2.0: Relative time (in milli-seconds).
61     private final long mInitiationTime;
62     // FiRa 2.0: Absolute time in UWB time domain, as specified in CR-272 (in micro-seconds).
63     private final long mAbsoluteInitiationTime;
64     private final int mSlotDurationRstu;
65     private final int mSlotsPerRangingRound;
66     private final int mRangingIntervalMs;
67     private final int mBlockStrideLength;
68     private final int mHoppingMode;
69 
70     @IntRange(from = 0, to = 65535)
71     private final int mMaxRangingRoundRetries;
72 
73     private final int mSessionPriority;
74     @MacAddressMode final int mMacAddressMode;
75     private final boolean mHasRangingResultReportMessage;
76     private final boolean mHasControlMessage;
77     private final boolean mHasRangingControlPhase;
78     @MeasurementReportType private final int mMeasurementReportType;
79     @MeasurementReportPhase private final int mMeasurementReportPhase;
80 
81     @IntRange(from = 1, to = 10)
82     private final int mInBandTerminationAttemptCount;
83 
84     @UwbChannel private final int mChannelNumber;
85     private final int mPreambleCodeIndex;
86     @RframeConfig private final int mRframeConfig;
87     @PrfMode private final int mPrfMode;
88     private final byte[] mCapSize;
89     @SchedulingMode private final int mScheduledMode;
90     @PreambleDuration private final int mPreambleDuration;
91     @SfdIdValue private final int mSfdId;
92     @StsSegmentCountValue private final int mStsSegmentCount;
93     @StsLength private final int mStsLength;
94 
95     // 16-byte or 32-byte long array
96     @Nullable private final byte[] mSessionKey;
97 
98     // 16-byte or 32-byte long array
99     @Nullable private final byte[] mSubSessionKey;
100 
101     @PsduDataRate private final int mPsduDataRate;
102     @BprfPhrDataRate private final int mBprfPhrDataRate;
103     @MacFcsType private final int mFcsType;
104     private final boolean mIsTxAdaptivePayloadPowerEnabled;
105     @StsConfig private final int mStsConfig;
106     private final int mSubSessionId;
107     @AoaType private final int mAoaType;
108 
109     // 2-byte long array
110     @Nullable private final byte[] mVendorId;
111 
112     // 6-byte long array
113     @Nullable private final byte[] mStaticStsIV;
114 
115     private final boolean mIsRssiReportingEnabled;
116     private final boolean mIsDiagnosticsEnabled;
117     private final byte mDiagramsFrameReportsFieldsFlags;
118     private final byte mAntennaMode;
119     private final boolean mIsKeyRotationEnabled;
120     private final int mKeyRotationRate;
121     @AoaResultRequestMode private final int mAoaResultRequest;
122     @RangeDataNtfConfig private final int mRangeDataNtfConfig;
123     private final int mRangeDataNtfProximityNear;
124     private final int mRangeDataNtfProximityFar;
125     private double mRangeDataNtfAoaAzimuthLower;
126     private double mRangeDataNtfAoaAzimuthUpper;
127     private double mRangeDataNtfAoaElevationLower;
128     private double mRangeDataNtfAoaElevationUpper;
129     private final boolean mHasTimeOfFlightReport;
130     private final boolean mHasAngleOfArrivalAzimuthReport;
131     private final boolean mHasAngleOfArrivalElevationReport;
132     private final boolean mHasAngleOfArrivalFigureOfMeritReport;
133     private final int mNumOfMsrmtFocusOnRange;
134     private final int mNumOfMsrmtFocusOnAoaAzimuth;
135     private final int mNumOfMsrmtFocusOnAoaElevation;
136     private final Long mRangingErrorStreakTimeoutMs;
137     private final int mLinkLayerMode;
138     private final int mDataRepetitionCount;
139     @RangingTimeStruct
140     private final int mRangingTimeStruct;
141     private final int mMinFramesPerRr;
142     private final int mMtuSize;
143     private final int mInterFrameInterval;
144     private final int mDlTdoaBlockStriding;
145     private final int mUlTdoaTxIntervalMs;
146     private final int mUlTdoaRandomWindowMs;
147     @UlTdoaDeviceIdType private final int mUlTdoaDeviceIdType;
148     @Nullable private final byte[] mUlTdoaDeviceId;
149     @UlTdoaTxTimestampType private final int mUlTdoaTxTimestampType;
150     @FilterType private final int mFilterType;
151     private final int mMaxNumberOfMeasurements;
152     private final boolean mSessionDataTransferStatusNtfConfig;
153     @Nullable private final int mReferenceTimeBase;
154     @Nullable private final int mReferenceSessionHandle;
155     @Nullable private final int mSessionOffsetInMicroSeconds;
156     private final int mApplicationDataEndpoint;
157 
158     private static final int BUNDLE_VERSION_1 = 1;
159     private static final int BUNDLE_VERSION_CURRENT = BUNDLE_VERSION_1;
160 
161     private static final String KEY_PROTOCOL_VERSION = "protocol_version";
162     private static final String KEY_SESSION_ID = "session_id";
163     private static final String KEY_SESSION_TYPE = "session_type";
164     private static final String KEY_DEVICE_TYPE = "device_type";
165     private static final String KEY_DEVICE_ROLE = "device_role";
166     private static final String KEY_RANGING_ROUND_USAGE = "ranging_round_usage";
167     private static final String KEY_MULTI_NODE_MODE = "multi_node_mode";
168     private static final String KEY_DEVICE_ADDRESS = "device_address";
169     private static final String KEY_DEST_ADDRESS_LIST = "dest_address_list";
170     private static final String KEY_INITIATION_TIME_MS = "initiation_time_ms";
171     private static final String KEY_ABSOLUTE_INITIATION_TIME_US = "absolute_initiation_time_us";
172     private static final String KEY_SLOT_DURATION_RSTU = "slot_duration_rstu";
173     private static final String KEY_SLOTS_PER_RANGING_ROUND = "slots_per_ranging_round";
174     private static final String KEY_RANGING_INTERVAL_MS = "ranging_interval_ms";
175     private static final String KEY_BLOCK_STRIDE_LENGTH = "block_stride_length";
176     private static final String KEY_HOPPING_MODE = "hopping_mode";
177     private static final String KEY_MAX_RANGING_ROUND_RETRIES = "max_ranging_round_retries";
178     private static final String KEY_SESSION_PRIORITY = "session_priority";
179     private static final String KEY_MAC_ADDRESS_MODE = "mac_address_mode";
180     private static final String KEY_IN_BAND_TERMINATION_ATTEMPT_COUNT =
181             "in_band_termination_attempt_count";
182     private static final String KEY_CHANNEL_NUMBER = "channel_number";
183     private static final String KEY_PREAMBLE_CODE_INDEX = "preamble_code_index";
184     private static final String KEY_RFRAME_CONFIG = "rframe_config";
185     private static final String KEY_PRF_MODE = "prf_mode";
186     private static final String KEY_CAP_SIZE_RANGE = "cap_size_range";
187     private static final String KEY_SCHEDULED_MODE = "scheduled_mode";
188     private static final String KEY_PREAMBLE_DURATION = "preamble_duration";
189     private static final String KEY_SFD_ID = "sfd_id";
190     private static final String KEY_STS_SEGMENT_COUNT = "sts_segment_count";
191     private static final String KEY_STS_LENGTH = "sts_length";
192     private static final String KEY_SESSION_KEY = "session_key";
193     private static final String KEY_SUBSESSION_KEY = "subsession_key";
194     private static final String KEY_PSDU_DATA_RATE = "psdu_data_rate";
195     private static final String KEY_BPRF_PHR_DATA_RATE = "bprf_phr_data_rate";
196     private static final String KEY_FCS_TYPE = "fcs_type";
197     private static final String KEY_IS_TX_ADAPTIVE_PAYLOAD_POWER_ENABLED =
198             "is_tx_adaptive_payload_power_enabled";
199     private static final String KEY_STS_CONFIG = "sts_config";
200     private static final String KEY_SUB_SESSION_ID = "sub_session_id";
201     private static final String KEY_VENDOR_ID = "vendor_id";
202     private static final String KEY_STATIC_STS_IV = "static_sts_iv";
203     private static final String KEY_IS_RSSI_REPORTING_ENABLED = "is_rssi_reporting_enabled";
204     private static final String KEY_IS_DIAGNOSTICS_ENABLED = "is_diagnostics_enabled";
205     private static final String KEY_DIAGRAMS_FRAME_REPORTS_FIELDS_FLAGS =
206             "diagrams_frame_reports_fields_flags";
207     private static final String KEY_IS_KEY_ROTATION_ENABLED = "is_key_rotation_enabled";
208     private static final String KEY_KEY_ROTATION_RATE = "key_rotation_rate";
209     private static final String KEY_AOA_RESULT_REQUEST = "aoa_result_request";
210     private static final String KEY_RANGE_DATA_NTF_CONFIG = "range_data_ntf_config";
211     private static final String KEY_RANGE_DATA_NTF_PROXIMITY_NEAR = "range_data_ntf_proximity_near";
212     private static final String KEY_RANGE_DATA_NTF_PROXIMITY_FAR = "range_data_ntf_proximity_far";
213     private static final String KEY_RANGE_DATA_NTF_AOA_AZIMUTH_LOWER =
214             "range_data_ntf_aoa_azimuth_lower";
215     private static final String KEY_RANGE_DATA_NTF_AOA_AZIMUTH_UPPER =
216             "range_data_ntf_aoa_azimuth_upper";
217     private static final String KEY_RANGE_DATA_NTF_AOA_ELEVATION_LOWER =
218             "range_data_ntf_aoa_elevation_lower";
219     private static final String KEY_RANGE_DATA_NTF_AOA_ELEVATION_UPPER =
220             "range_data_ntf_aoa_elevation_upper";
221     private static final String KEY_HAS_TIME_OF_FLIGHT_REPORT = "has_time_of_flight_report";
222     private static final String KEY_HAS_ANGLE_OF_ARRIVAL_AZIMUTH_REPORT =
223             "has_angle_of_arrival_azimuth_report";
224     private static final String KEY_HAS_ANGLE_OF_ARRIVAL_ELEVATION_REPORT =
225             "has_angle_of_arrival_elevation_report";
226     private static final String KEY_HAS_ANGLE_OF_ARRIVAL_FIGURE_OF_MERIT_REPORT =
227             "has_angle_of_arrival_figure_of_merit_report";
228     // key value not the same as constant name to maintain backwards compatibility.
229     private static final String KEY_HAS_RANGING_RESULT_REPORT_MESSAGE = "has_result_report_phase";
230     private static final String KEY_HAS_CONTROL_MESSAGE = "has_control_message";
231     private static final String KEY_HAS_RANGING_CONTROL_PHASE = "has_ranging_control_phase";
232     private static final String KEY_MEASUREMENT_REPORT_TYPE = "measurement_report_type";
233     private static final String KEY_MEASUREMENT_REPORT_PHASE = "measurement_report_phase";
234     private static final String KEY_AOA_TYPE = "aoa_type";
235     private static final String KEY_NUM_OF_MSRMT_FOCUS_ON_RANGE =
236             "num_of_msrmt_focus_on_range";
237     private static final String KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_AZIMUTH =
238             "num_of_msrmt_focus_on_aoa_azimuth";
239     private static final String KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_ELEVATION =
240             "num_of_msrmt_focus_on_aoa_elevation";
241     private static final String RANGING_ERROR_STREAK_TIMEOUT_MS =
242             "ranging_error_streak_timeout_ms";
243     private static final String KEY_LINK_LAYER_MODE =
244             "link_layer_mode";
245     private static final String KEY_DATA_REPETITION_COUNT = "data_repetition_count";
246     private static final String KEY_RANGING_TIME_STRUCT = "ranging_time_struct";
247     private static final String KEY_MIN_FRAMES_PER_RR =
248             "min_frames_per_rr";
249     private static final String KEY_MTU_SIZE =
250             "mtu_size";
251     private static final String KEY_INTER_FRAME_INTERVAL =
252             "inter_frame_interval";
253     private static final String KEY_DLTDOA_BLOCK_STRIDING = "dltdoa_block_striding";
254     private static final String UL_TDOA_TX_INTERVAL = "ul_tdoa_tx_interval";
255     private static final String UL_TDOA_RANDOM_WINDOW = "ul_tdoa_random_window";
256     private static final String UL_TDOA_DEVICE_ID_TYPE = "ul_tdoa_device_id_type";
257     private static final String UL_TDOA_DEVICE_ID = "ul_tdoa_device_id";
258     private static final String UL_TDOA_TX_TIMESTAMP_TYPE = "ul_tdoa_tx_timestamp_type";
259     private static final String KEY_FILTER_TYPE = "filter_type";
260     private static final String KEY_MAX_NUMBER_OF_MEASUREMENTS = "max_number_of_measurements";
261     private static final String KEY_SESSION_DATA_TRANSFER_STATUS_NTF_CONFIG =
262             "session_data_transfer_status_ntf_config";
263     private static final String KEY_REFERENCE_TIME_BASE = "reference_time_base";
264     private static final String KEY_REFERENCE_SESSION_HANDLE = "reference_session_handle";
265     private static final String KEY_SESSION_OFFSET_IN_MICRO_SECONDS =
266                 "session_offset_in_micro_seconds";
267     private static final String KEY_APPLICATION_DATA_ENDPOINT = "application_data_endpoint";
268     private static final String KEY_ANTENNA_MODE = "antenna_mode";
269 
FiraOpenSessionParams( FiraProtocolVersion protocolVersion, int sessionId, @SessionType int sessionType, @RangingDeviceType int deviceType, @RangingDeviceRole int deviceRole, @RangingRoundUsage int rangingRoundUsage, @MultiNodeMode int multiNodeMode, UwbAddress deviceAddress, List<UwbAddress> destAddressList, long initiationTime, long absoluteInitiationTime, int slotDurationRstu, int slotsPerRangingRound, int rangingIntervalMs, int blockStrideLength, int hoppingMode, @IntRange(from = 0, to = 65535) int maxRangingRoundRetries, int sessionPriority, @MacAddressMode int macAddressMode, boolean hasRangingResultReportMessage, boolean hasControlMessage, boolean hasRangingControlPhase, @MeasurementReportType int measurementReportType, @MeasurementReportPhase int measurementReportPhase, @IntRange(from = 1, to = 10) int inBandTerminationAttemptCount, @UwbChannel int channelNumber, int preambleCodeIndex, @RframeConfig int rframeConfig, @PrfMode int prfMode, byte[] capSize, @SchedulingMode int scheduledMode, @PreambleDuration int preambleDuration, @SfdIdValue int sfdId, @StsSegmentCountValue int stsSegmentCount, @StsLength int stsLength, @Nullable byte[] sessionKey, @Nullable byte[] subsessionKey, @PsduDataRate int psduDataRate, @BprfPhrDataRate int bprfPhrDataRate, @MacFcsType int fcsType, boolean isTxAdaptivePayloadPowerEnabled, @StsConfig int stsConfig, int subSessionId, @Nullable byte[] vendorId, @Nullable byte[] staticStsIV, boolean isRssiReportingEnabled, boolean isDiagnosticsEnabled, byte diagramsFrameReportsFieldsFlags, @AntennaMode byte antennaMode, boolean isKeyRotationEnabled, int keyRotationRate, @AoaResultRequestMode int aoaResultRequest, @RangeDataNtfConfig int rangeDataNtfConfig, int rangeDataNtfProximityNear, int rangeDataNtfProximityFar, double rangeDataNtfAoaAzimuthLower, double rangeDataNtfAoaAzimuthUpper, double rangeDataNtfAoaElevationLower, double rangeDataNtfAoaElevationUpper, boolean hasTimeOfFlightReport, boolean hasAngleOfArrivalAzimuthReport, boolean hasAngleOfArrivalElevationReport, boolean hasAngleOfArrivalFigureOfMeritReport, @AoaType int aoaType, int numOfMsrmtFocusOnRange, int numOfMsrmtFocusOnAoaAzimuth, int numOfMsrmtFocusOnAoaElevation, Long rangingErrorStreakTimeoutMs, int linkLayerMode, int dataRepetitionCount, @RangingTimeStruct int rangingTimeStruct, int minFramePerRr, int mtuSize, int interFrameInterval, int dlTdoaBlockStriding, int ulTdoaTxIntervalMs, int ulTdoaRandomWindowMs, int ulTdoaDeviceIdType, @Nullable byte[] ulTdoaDeviceId, int ulTdoaTxTimestampType, int filterType, int maxNumberOfMeasurements, boolean sessionDataTransferStatusNtfConfig, int referenceTimeBase, int referenceSessionHandle, int sessionOffsetInMicroSecond, int applicationDataEndpoint)270     private FiraOpenSessionParams(
271             FiraProtocolVersion protocolVersion,
272             int sessionId,
273             @SessionType int sessionType,
274             @RangingDeviceType int deviceType,
275             @RangingDeviceRole int deviceRole,
276             @RangingRoundUsage int rangingRoundUsage,
277             @MultiNodeMode int multiNodeMode,
278             UwbAddress deviceAddress,
279             List<UwbAddress> destAddressList,
280             long initiationTime,
281             long absoluteInitiationTime,
282             int slotDurationRstu,
283             int slotsPerRangingRound,
284             int rangingIntervalMs,
285             int blockStrideLength,
286             int hoppingMode,
287             @IntRange(from = 0, to = 65535) int maxRangingRoundRetries,
288             int sessionPriority,
289             @MacAddressMode int macAddressMode,
290             boolean hasRangingResultReportMessage,
291             boolean hasControlMessage,
292             boolean hasRangingControlPhase,
293             @MeasurementReportType int measurementReportType,
294             @MeasurementReportPhase int measurementReportPhase,
295             @IntRange(from = 1, to = 10) int inBandTerminationAttemptCount,
296             @UwbChannel int channelNumber,
297             int preambleCodeIndex,
298             @RframeConfig int rframeConfig,
299             @PrfMode int prfMode,
300             byte[] capSize,
301             @SchedulingMode int scheduledMode,
302             @PreambleDuration int preambleDuration,
303             @SfdIdValue int sfdId,
304             @StsSegmentCountValue int stsSegmentCount,
305             @StsLength int stsLength,
306             @Nullable byte[] sessionKey,
307             @Nullable byte[] subsessionKey,
308             @PsduDataRate int psduDataRate,
309             @BprfPhrDataRate int bprfPhrDataRate,
310             @MacFcsType int fcsType,
311             boolean isTxAdaptivePayloadPowerEnabled,
312             @StsConfig int stsConfig,
313             int subSessionId,
314             @Nullable byte[] vendorId,
315             @Nullable byte[] staticStsIV,
316             boolean isRssiReportingEnabled,
317             boolean isDiagnosticsEnabled,
318             byte diagramsFrameReportsFieldsFlags,
319             @AntennaMode byte antennaMode,
320             boolean isKeyRotationEnabled,
321             int keyRotationRate,
322             @AoaResultRequestMode int aoaResultRequest,
323             @RangeDataNtfConfig int rangeDataNtfConfig,
324             int rangeDataNtfProximityNear,
325             int rangeDataNtfProximityFar,
326             double rangeDataNtfAoaAzimuthLower,
327             double rangeDataNtfAoaAzimuthUpper,
328             double rangeDataNtfAoaElevationLower,
329             double rangeDataNtfAoaElevationUpper,
330             boolean hasTimeOfFlightReport,
331             boolean hasAngleOfArrivalAzimuthReport,
332             boolean hasAngleOfArrivalElevationReport,
333             boolean hasAngleOfArrivalFigureOfMeritReport,
334             @AoaType int aoaType,
335             int numOfMsrmtFocusOnRange,
336             int numOfMsrmtFocusOnAoaAzimuth,
337             int numOfMsrmtFocusOnAoaElevation,
338             Long rangingErrorStreakTimeoutMs,
339             int linkLayerMode,
340             int dataRepetitionCount,
341             @RangingTimeStruct int rangingTimeStruct,
342             int minFramePerRr,
343             int mtuSize,
344             int interFrameInterval,
345             int dlTdoaBlockStriding,
346             int ulTdoaTxIntervalMs,
347             int ulTdoaRandomWindowMs,
348             int ulTdoaDeviceIdType,
349             @Nullable byte[] ulTdoaDeviceId,
350             int ulTdoaTxTimestampType,
351             int filterType,
352             int maxNumberOfMeasurements,
353             boolean sessionDataTransferStatusNtfConfig,
354             int referenceTimeBase,
355             int referenceSessionHandle,
356             int sessionOffsetInMicroSecond,
357             int applicationDataEndpoint) {
358         mProtocolVersion = protocolVersion;
359         mSessionId = sessionId;
360         mSessionType = sessionType;
361         mDeviceType = deviceType;
362         mDeviceRole = deviceRole;
363         mRangingRoundUsage = rangingRoundUsage;
364         mMultiNodeMode = multiNodeMode;
365         mDeviceAddress = deviceAddress;
366         mDestAddressList = destAddressList;
367         mInitiationTime = initiationTime;
368         mAbsoluteInitiationTime = absoluteInitiationTime;
369         mSlotDurationRstu = slotDurationRstu;
370         mSlotsPerRangingRound = slotsPerRangingRound;
371         mRangingIntervalMs = rangingIntervalMs;
372         mBlockStrideLength = blockStrideLength;
373         mHoppingMode = hoppingMode;
374         mMaxRangingRoundRetries = maxRangingRoundRetries;
375         mSessionPriority = sessionPriority;
376         mMacAddressMode = macAddressMode;
377         mHasRangingResultReportMessage = hasRangingResultReportMessage;
378         mHasControlMessage = hasControlMessage;
379         mHasRangingControlPhase = hasRangingControlPhase;
380         mMeasurementReportType = measurementReportType;
381         mMeasurementReportPhase = measurementReportPhase;
382         mInBandTerminationAttemptCount = inBandTerminationAttemptCount;
383         mChannelNumber = channelNumber;
384         mPreambleCodeIndex = preambleCodeIndex;
385         mRframeConfig = rframeConfig;
386         mPrfMode = prfMode;
387         mCapSize = capSize;
388         mScheduledMode = scheduledMode;
389         mPreambleDuration = preambleDuration;
390         mSfdId = sfdId;
391         mStsSegmentCount = stsSegmentCount;
392         mStsLength = stsLength;
393         mSessionKey = sessionKey;
394         mSubSessionKey = subsessionKey;
395         mPsduDataRate = psduDataRate;
396         mBprfPhrDataRate = bprfPhrDataRate;
397         mFcsType = fcsType;
398         mIsTxAdaptivePayloadPowerEnabled = isTxAdaptivePayloadPowerEnabled;
399         mStsConfig = stsConfig;
400         mSubSessionId = subSessionId;
401         mVendorId = vendorId;
402         mStaticStsIV = staticStsIV;
403         mIsRssiReportingEnabled = isRssiReportingEnabled;
404         mIsDiagnosticsEnabled = isDiagnosticsEnabled;
405         mDiagramsFrameReportsFieldsFlags = diagramsFrameReportsFieldsFlags;
406         mAntennaMode = antennaMode;
407         mIsKeyRotationEnabled = isKeyRotationEnabled;
408         mKeyRotationRate = keyRotationRate;
409         mAoaResultRequest = aoaResultRequest;
410         mRangeDataNtfConfig = rangeDataNtfConfig;
411         mRangeDataNtfProximityNear = rangeDataNtfProximityNear;
412         mRangeDataNtfProximityFar = rangeDataNtfProximityFar;
413         mRangeDataNtfAoaAzimuthLower = rangeDataNtfAoaAzimuthLower;
414         mRangeDataNtfAoaAzimuthUpper = rangeDataNtfAoaAzimuthUpper;
415         mRangeDataNtfAoaElevationLower = rangeDataNtfAoaElevationLower;
416         mRangeDataNtfAoaElevationUpper = rangeDataNtfAoaElevationUpper;
417         mHasTimeOfFlightReport = hasTimeOfFlightReport;
418         mHasAngleOfArrivalAzimuthReport = hasAngleOfArrivalAzimuthReport;
419         mHasAngleOfArrivalElevationReport = hasAngleOfArrivalElevationReport;
420         mHasAngleOfArrivalFigureOfMeritReport = hasAngleOfArrivalFigureOfMeritReport;
421         mAoaType = aoaType;
422         mNumOfMsrmtFocusOnRange = numOfMsrmtFocusOnRange;
423         mNumOfMsrmtFocusOnAoaAzimuth = numOfMsrmtFocusOnAoaAzimuth;
424         mNumOfMsrmtFocusOnAoaElevation = numOfMsrmtFocusOnAoaElevation;
425         mRangingErrorStreakTimeoutMs = rangingErrorStreakTimeoutMs;
426         mLinkLayerMode = linkLayerMode;
427         mDataRepetitionCount = dataRepetitionCount;
428         mRangingTimeStruct = rangingTimeStruct;
429         mMinFramesPerRr = minFramePerRr;
430         mMtuSize = mtuSize;
431         mInterFrameInterval = interFrameInterval;
432         mDlTdoaBlockStriding = dlTdoaBlockStriding;
433         mUlTdoaTxIntervalMs = ulTdoaTxIntervalMs;
434         mUlTdoaRandomWindowMs = ulTdoaRandomWindowMs;
435         mUlTdoaDeviceIdType = ulTdoaDeviceIdType;
436         mUlTdoaDeviceId = ulTdoaDeviceId;
437         mUlTdoaTxTimestampType = ulTdoaTxTimestampType;
438         mFilterType = filterType;
439         mMaxNumberOfMeasurements = maxNumberOfMeasurements;
440         mSessionDataTransferStatusNtfConfig = sessionDataTransferStatusNtfConfig;
441         mReferenceTimeBase = referenceTimeBase;
442         mReferenceSessionHandle = referenceSessionHandle;
443         mSessionOffsetInMicroSeconds = sessionOffsetInMicroSecond;
444         mApplicationDataEndpoint = applicationDataEndpoint;
445     }
446 
447     @Override
getBundleVersion()448     protected int getBundleVersion() {
449         return BUNDLE_VERSION_CURRENT;
450     }
451 
getSessionId()452     public int getSessionId() {
453         return mSessionId;
454     }
455 
456     @SessionType
getSessionType()457     public int getSessionType() {
458         return mSessionType;
459     }
460 
461     @RangingDeviceType
getDeviceType()462     public int getDeviceType() {
463         return mDeviceType;
464     }
465 
466     @RangingDeviceRole
getDeviceRole()467     public int getDeviceRole() {
468         return mDeviceRole;
469     }
470 
471     @RangingRoundUsage
getRangingRoundUsage()472     public int getRangingRoundUsage() {
473         return mRangingRoundUsage;
474     }
475 
476     @MultiNodeMode
getMultiNodeMode()477     public int getMultiNodeMode() {
478         return mMultiNodeMode;
479     }
480 
getDeviceAddress()481     public UwbAddress getDeviceAddress() {
482         return mDeviceAddress;
483     }
484 
getDestAddressList()485     public List<UwbAddress> getDestAddressList() {
486         return mDestAddressList != null ? Collections.unmodifiableList(mDestAddressList) : null;
487     }
488 
getInitiationTime()489     public long getInitiationTime() {
490         return mInitiationTime;
491     }
492 
getAbsoluteInitiationTime()493     public long getAbsoluteInitiationTime() {
494         return mAbsoluteInitiationTime;
495     }
496 
getSlotDurationRstu()497     public int getSlotDurationRstu() {
498         return mSlotDurationRstu;
499     }
500 
getSlotsPerRangingRound()501     public int getSlotsPerRangingRound() {
502         return mSlotsPerRangingRound;
503     }
504 
getRangingIntervalMs()505     public int getRangingIntervalMs() {
506         return mRangingIntervalMs;
507     }
508 
getBlockStrideLength()509     public int getBlockStrideLength() {
510         return mBlockStrideLength;
511     }
512 
getHoppingMode()513     public int getHoppingMode() {
514         return mHoppingMode;
515     }
516 
517     @IntRange(from = 0, to = 65535)
getMaxRangingRoundRetries()518     public int getMaxRangingRoundRetries() {
519         return mMaxRangingRoundRetries;
520     }
521 
getSessionPriority()522     public int getSessionPriority() {
523         return mSessionPriority;
524     }
525 
526     @MacAddressMode
getMacAddressMode()527     public int getMacAddressMode() {
528         return mMacAddressMode;
529     }
530 
hasRangingResultReportMessage()531     public boolean hasRangingResultReportMessage() {
532         return mHasRangingResultReportMessage;
533     }
534 
hasControlMessage()535     public boolean hasControlMessage() {
536         return mHasControlMessage;
537     }
538 
hasRangingControlPhase()539     public boolean hasRangingControlPhase() {
540         return mHasRangingControlPhase;
541     }
542 
543     @MeasurementReportType
getMeasurementReportType()544     public int getMeasurementReportType() {
545         return mMeasurementReportType;
546     }
547 
548     @MeasurementReportPhase
getMeasurementReportPhase()549     public int getMeasurementReportPhase() {
550         return mMeasurementReportPhase;
551     }
552 
553     @IntRange(from = 1, to = 10)
getInBandTerminationAttemptCount()554     public int getInBandTerminationAttemptCount() {
555         return mInBandTerminationAttemptCount;
556     }
557 
558     @UwbChannel
getChannelNumber()559     public int getChannelNumber() {
560         return mChannelNumber;
561     }
562 
getPreambleCodeIndex()563     public int getPreambleCodeIndex() {
564         return mPreambleCodeIndex;
565     }
566 
567     @RframeConfig
getRframeConfig()568     public int getRframeConfig() {
569         return mRframeConfig;
570     }
571 
572     @PrfMode
getPrfMode()573     public int getPrfMode() {
574         return mPrfMode;
575     }
576 
getCapSize()577     public byte[] getCapSize() {
578         return mCapSize;
579     }
580 
581     @SchedulingMode
getScheduledMode()582     public int getScheduledMode() {
583         return mScheduledMode;
584     }
585 
586     @PreambleDuration
getPreambleDuration()587     public int getPreambleDuration() {
588         return mPreambleDuration;
589     }
590 
591     @SfdIdValue
getSfdId()592     public int getSfdId() {
593         return mSfdId;
594     }
595 
596     @StsSegmentCountValue
getStsSegmentCount()597     public int getStsSegmentCount() {
598         return mStsSegmentCount;
599     }
600 
601     @StsLength
getStsLength()602     public int getStsLength() {
603         return mStsLength;
604     }
605 
606     @Nullable
getSessionKey()607     public byte[] getSessionKey() {
608         return mSessionKey;
609     }
610 
611     @Nullable
getSubsessionKey()612     public byte[] getSubsessionKey() {
613         return mSubSessionKey;
614     }
615 
616     @PsduDataRate
getPsduDataRate()617     public int getPsduDataRate() {
618         return mPsduDataRate;
619     }
620 
621     @BprfPhrDataRate
getBprfPhrDataRate()622     public int getBprfPhrDataRate() {
623         return mBprfPhrDataRate;
624     }
625 
626     @MacFcsType
getFcsType()627     public int getFcsType() {
628         return mFcsType;
629     }
630 
isTxAdaptivePayloadPowerEnabled()631     public boolean isTxAdaptivePayloadPowerEnabled() {
632         return mIsTxAdaptivePayloadPowerEnabled;
633     }
634 
635     @StsConfig
getStsConfig()636     public int getStsConfig() {
637         return mStsConfig;
638     }
639 
getSubSessionId()640     public int getSubSessionId() {
641         return mSubSessionId;
642     }
643 
644     @Nullable
getVendorId()645     public byte[] getVendorId() {
646         return mVendorId;
647     }
648 
649     @Nullable
getStaticStsIV()650     public byte[] getStaticStsIV() {
651         return mStaticStsIV;
652     }
653 
isRssiReportingEnabled()654     public boolean isRssiReportingEnabled() {
655         return mIsRssiReportingEnabled;
656     }
657 
isDiagnosticsEnabled()658     public boolean isDiagnosticsEnabled() {
659         return mIsDiagnosticsEnabled;
660     }
661 
getDiagramsFrameReportsFieldsFlags()662     public byte getDiagramsFrameReportsFieldsFlags() {
663         return mDiagramsFrameReportsFieldsFlags;
664     }
665 
666     @AntennaMode
getAntennaMode()667     public byte getAntennaMode() {
668         return mAntennaMode;
669     }
670 
isKeyRotationEnabled()671     public boolean isKeyRotationEnabled() {
672         return mIsKeyRotationEnabled;
673     }
674 
getKeyRotationRate()675     public int getKeyRotationRate() {
676         return mKeyRotationRate;
677     }
678 
679     @AoaResultRequestMode
getAoaResultRequest()680     public int getAoaResultRequest() {
681         return mAoaResultRequest;
682     }
683 
684     @RangeDataNtfConfig
getRangeDataNtfConfig()685     public int getRangeDataNtfConfig() {
686         return mRangeDataNtfConfig;
687     }
688 
getRangeDataNtfProximityNear()689     public int getRangeDataNtfProximityNear() {
690         return mRangeDataNtfProximityNear;
691     }
692 
getRangeDataNtfProximityFar()693     public int getRangeDataNtfProximityFar() {
694         return mRangeDataNtfProximityFar;
695     }
696 
getRangeDataNtfAoaAzimuthLower()697     public double getRangeDataNtfAoaAzimuthLower() {
698         return mRangeDataNtfAoaAzimuthLower;
699     }
700 
getRangeDataNtfAoaAzimuthUpper()701     public double getRangeDataNtfAoaAzimuthUpper() {
702         return mRangeDataNtfAoaAzimuthUpper;
703     }
704 
getRangeDataNtfAoaElevationLower()705     public double getRangeDataNtfAoaElevationLower() {
706         return mRangeDataNtfAoaElevationLower;
707     }
708 
getRangeDataNtfAoaElevationUpper()709     public double getRangeDataNtfAoaElevationUpper() {
710         return mRangeDataNtfAoaElevationUpper;
711     }
712 
hasTimeOfFlightReport()713     public boolean hasTimeOfFlightReport() {
714         return mHasTimeOfFlightReport;
715     }
716 
hasAngleOfArrivalAzimuthReport()717     public boolean hasAngleOfArrivalAzimuthReport() {
718         return mHasAngleOfArrivalAzimuthReport;
719     }
720 
hasAngleOfArrivalElevationReport()721     public boolean hasAngleOfArrivalElevationReport() {
722         return mHasAngleOfArrivalElevationReport;
723     }
724 
hasAngleOfArrivalFigureOfMeritReport()725     public boolean hasAngleOfArrivalFigureOfMeritReport() {
726         return mHasAngleOfArrivalFigureOfMeritReport;
727     }
728 
729     @AoaType
getAoaType()730     public int getAoaType() {
731         return mAoaType;
732     }
733 
getNumOfMsrmtFocusOnRange()734     public int getNumOfMsrmtFocusOnRange() {
735         return mNumOfMsrmtFocusOnRange;
736     }
737 
getNumOfMsrmtFocusOnAoaAzimuth()738     public int getNumOfMsrmtFocusOnAoaAzimuth() {
739         return mNumOfMsrmtFocusOnAoaAzimuth;
740     }
741 
getNumOfMsrmtFocusOnAoaElevation()742     public int getNumOfMsrmtFocusOnAoaElevation() {
743         return mNumOfMsrmtFocusOnAoaElevation;
744     }
745 
getRangingErrorStreakTimeoutMs()746     public long getRangingErrorStreakTimeoutMs() {
747         return mRangingErrorStreakTimeoutMs;
748     }
749 
getLinkLayerMode()750     public int getLinkLayerMode() {
751         return mLinkLayerMode;
752     }
753 
getDataRepetitionCount()754     public int getDataRepetitionCount() {
755         return mDataRepetitionCount;
756     }
757 
758     @RangingTimeStruct
getRangingTimeStruct()759     public int getRangingTimeStruct() {
760         return mRangingTimeStruct;
761     }
762 
getMinFramesPerRr()763     public int getMinFramesPerRr() {
764         return mMinFramesPerRr;
765     }
766 
getMtuSize()767     public int getMtuSize() {
768         return mMtuSize;
769     }
770 
getInterFrameInterval()771     public int getInterFrameInterval() {
772         return mInterFrameInterval;
773     }
774 
getDlTdoaBlockStriding()775     public int getDlTdoaBlockStriding() {
776         return mDlTdoaBlockStriding;
777     }
778 
getUlTdoaTxIntervalMs()779     public int getUlTdoaTxIntervalMs() {
780         return mUlTdoaTxIntervalMs;
781     }
782 
getUlTdoaRandomWindowMs()783     public int getUlTdoaRandomWindowMs() {
784         return mUlTdoaRandomWindowMs;
785     }
786 
getUlTdoaDeviceIdType()787     public int getUlTdoaDeviceIdType() {
788         return mUlTdoaDeviceIdType;
789     }
790 
791     @Nullable
getUlTdoaDeviceId()792     public byte[] getUlTdoaDeviceId() {
793         return mUlTdoaDeviceId;
794     }
795 
getUlTdoaTxTimestampType()796     public int getUlTdoaTxTimestampType() {
797         return mUlTdoaTxTimestampType;
798     }
799 
800     @FilterType
getFilterType()801     public int getFilterType() {
802         return mFilterType;
803     }
804 
getMaxNumberOfMeasurements()805     public int getMaxNumberOfMeasurements() { return mMaxNumberOfMeasurements; }
806 
getSessionDataTransferStatusNtfConfig()807     public boolean getSessionDataTransferStatusNtfConfig() {
808         return mSessionDataTransferStatusNtfConfig;
809     }
810 
getReferenceTimeBase()811     public int getReferenceTimeBase() {
812         return mReferenceTimeBase;
813     }
814 
getReferenceSessionHandle()815     public int getReferenceSessionHandle() {
816         return mReferenceSessionHandle;
817     }
818 
getSessionOffsetInMicroSeconds()819     public int getSessionOffsetInMicroSeconds() {
820         return mSessionOffsetInMicroSeconds;
821     }
822 
getApplicationDataEndpoint()823     public int getApplicationDataEndpoint() {
824         return mApplicationDataEndpoint;
825     }
826 
827     @Nullable
byteArrayToIntArray(@ullable byte[] bytes)828     private static int[] byteArrayToIntArray(@Nullable byte[] bytes) {
829         if (bytes == null) {
830             return null;
831         }
832 
833         int[] values = new int[bytes.length];
834         for (int i = 0; i < values.length; i++) {
835             values[i] = bytes[i];
836         }
837         return values;
838     }
839 
840     @Nullable
intArrayToByteArray(@ullable int[] values)841     private static byte[] intArrayToByteArray(@Nullable int[] values) {
842         if (values == null) {
843             return null;
844         }
845         byte[] bytes = new byte[values.length];
846         for (int i = 0; i < values.length; i++) {
847             bytes[i] = (byte) values[i];
848         }
849         return bytes;
850     }
851 
852     @Override
toBundle()853     public PersistableBundle toBundle() {
854         PersistableBundle bundle = super.toBundle();
855         bundle.putString(KEY_PROTOCOL_VERSION, mProtocolVersion.toString());
856         bundle.putInt(KEY_SESSION_ID, mSessionId);
857         bundle.putInt(KEY_SESSION_TYPE, mSessionType);
858         bundle.putInt(KEY_DEVICE_TYPE, mDeviceType);
859         bundle.putInt(KEY_DEVICE_ROLE, mDeviceRole);
860         bundle.putInt(KEY_RANGING_ROUND_USAGE, mRangingRoundUsage);
861         bundle.putInt(KEY_MULTI_NODE_MODE, mMultiNodeMode);
862         // Always store address as long in bundle.
863         bundle.putLong(KEY_DEVICE_ADDRESS, uwbAddressToLong(mDeviceAddress));
864 
865         if (mDeviceRole != RANGING_DEVICE_DT_TAG &&
866             mScheduledMode != CONTENTION_BASED_RANGING) {
867             // Dest Address list needs to be converted to long array.
868             long[] destAddressList = new long[mDestAddressList.size()];
869             int i = 0;
870             for (UwbAddress destAddress : mDestAddressList) {
871                 destAddressList[i++] = uwbAddressToLong(destAddress);
872             }
873             bundle.putLongArray(KEY_DEST_ADDRESS_LIST, destAddressList);
874         } else {
875             bundle.putInt(KEY_DLTDOA_BLOCK_STRIDING, mDlTdoaBlockStriding);
876         }
877 
878         bundle.putLong(KEY_INITIATION_TIME_MS, mInitiationTime);
879         bundle.putLong(KEY_ABSOLUTE_INITIATION_TIME_US, mAbsoluteInitiationTime);
880         bundle.putInt(KEY_SLOT_DURATION_RSTU, mSlotDurationRstu);
881         bundle.putInt(KEY_SLOTS_PER_RANGING_ROUND, mSlotsPerRangingRound);
882         bundle.putInt(KEY_RANGING_INTERVAL_MS, mRangingIntervalMs);
883         bundle.putInt(KEY_BLOCK_STRIDE_LENGTH, mBlockStrideLength);
884         bundle.putInt(KEY_HOPPING_MODE, mHoppingMode);
885         bundle.putInt(KEY_MAX_RANGING_ROUND_RETRIES, mMaxRangingRoundRetries);
886         bundle.putInt(KEY_SESSION_PRIORITY, mSessionPriority);
887         bundle.putInt(KEY_MAC_ADDRESS_MODE, mMacAddressMode);
888         bundle.putBoolean(KEY_HAS_RANGING_RESULT_REPORT_MESSAGE, mHasRangingResultReportMessage);
889         bundle.putBoolean(KEY_HAS_CONTROL_MESSAGE, mHasControlMessage);
890         bundle.putBoolean(KEY_HAS_RANGING_CONTROL_PHASE, mHasRangingControlPhase);
891         bundle.putInt(KEY_MEASUREMENT_REPORT_TYPE, mMeasurementReportType);
892         bundle.putInt(KEY_MEASUREMENT_REPORT_PHASE, mMeasurementReportPhase);
893         bundle.putInt(KEY_IN_BAND_TERMINATION_ATTEMPT_COUNT, mInBandTerminationAttemptCount);
894         bundle.putInt(KEY_CHANNEL_NUMBER, mChannelNumber);
895         bundle.putInt(KEY_PREAMBLE_CODE_INDEX, mPreambleCodeIndex);
896         bundle.putInt(KEY_RFRAME_CONFIG, mRframeConfig);
897         bundle.putInt(KEY_PRF_MODE, mPrfMode);
898         bundle.putInt(KEY_SCHEDULED_MODE, mScheduledMode);
899         if (mScheduledMode == CONTENTION_BASED_RANGING) {
900             bundle.putIntArray(KEY_CAP_SIZE_RANGE, byteArrayToIntArray(mCapSize));
901         }
902         bundle.putInt(KEY_PREAMBLE_DURATION, mPreambleDuration);
903         bundle.putInt(KEY_SFD_ID, mSfdId);
904         bundle.putInt(KEY_STS_SEGMENT_COUNT, mStsSegmentCount);
905         bundle.putInt(KEY_STS_LENGTH, mStsLength);
906         bundle.putInt(KEY_PSDU_DATA_RATE, mPsduDataRate);
907         bundle.putInt(KEY_BPRF_PHR_DATA_RATE, mBprfPhrDataRate);
908         bundle.putInt(KEY_FCS_TYPE, mFcsType);
909         bundle.putBoolean(
910                 KEY_IS_TX_ADAPTIVE_PAYLOAD_POWER_ENABLED, mIsTxAdaptivePayloadPowerEnabled);
911         bundle.putInt(KEY_STS_CONFIG, mStsConfig);
912         if (mStsConfig == STS_CONFIG_DYNAMIC_FOR_CONTROLEE_INDIVIDUAL_KEY
913             || mStsConfig == STS_CONFIG_PROVISIONED_FOR_CONTROLEE_INDIVIDUAL_KEY) {
914             bundle.putInt(KEY_SUB_SESSION_ID, mSubSessionId);
915         }
916         if (mSessionKey != null) {
917             bundle.putIntArray(KEY_SESSION_KEY, byteArrayToIntArray(mSessionKey));
918         }
919         if (mSubSessionKey != null) {
920             bundle.putIntArray(KEY_SUBSESSION_KEY, byteArrayToIntArray(mSubSessionKey));
921         }
922         bundle.putIntArray(KEY_VENDOR_ID, byteArrayToIntArray(mVendorId));
923         bundle.putIntArray(KEY_STATIC_STS_IV, byteArrayToIntArray(mStaticStsIV));
924         bundle.putBoolean(KEY_IS_RSSI_REPORTING_ENABLED, mIsRssiReportingEnabled);
925         bundle.putBoolean(KEY_IS_DIAGNOSTICS_ENABLED, mIsDiagnosticsEnabled);
926         bundle.putInt(KEY_DIAGRAMS_FRAME_REPORTS_FIELDS_FLAGS, mDiagramsFrameReportsFieldsFlags);
927         bundle.putInt(KEY_ANTENNA_MODE, mAntennaMode);
928         bundle.putBoolean(KEY_IS_KEY_ROTATION_ENABLED, mIsKeyRotationEnabled);
929         bundle.putInt(KEY_KEY_ROTATION_RATE, mKeyRotationRate);
930         bundle.putInt(KEY_AOA_RESULT_REQUEST, mAoaResultRequest);
931         bundle.putInt(KEY_RANGE_DATA_NTF_CONFIG, mRangeDataNtfConfig);
932         bundle.putInt(KEY_RANGE_DATA_NTF_PROXIMITY_NEAR, mRangeDataNtfProximityNear);
933         bundle.putInt(KEY_RANGE_DATA_NTF_PROXIMITY_FAR, mRangeDataNtfProximityFar);
934         bundle.putDouble(KEY_RANGE_DATA_NTF_AOA_AZIMUTH_LOWER, mRangeDataNtfAoaAzimuthLower);
935         bundle.putDouble(KEY_RANGE_DATA_NTF_AOA_AZIMUTH_UPPER, mRangeDataNtfAoaAzimuthUpper);
936         bundle.putDouble(KEY_RANGE_DATA_NTF_AOA_ELEVATION_LOWER, mRangeDataNtfAoaElevationLower);
937         bundle.putDouble(KEY_RANGE_DATA_NTF_AOA_ELEVATION_UPPER, mRangeDataNtfAoaElevationUpper);
938         bundle.putBoolean(KEY_HAS_TIME_OF_FLIGHT_REPORT, mHasTimeOfFlightReport);
939         bundle.putBoolean(KEY_HAS_ANGLE_OF_ARRIVAL_AZIMUTH_REPORT, mHasAngleOfArrivalAzimuthReport);
940         bundle.putBoolean(
941                 KEY_HAS_ANGLE_OF_ARRIVAL_ELEVATION_REPORT, mHasAngleOfArrivalElevationReport);
942         bundle.putBoolean(
943                 KEY_HAS_ANGLE_OF_ARRIVAL_FIGURE_OF_MERIT_REPORT,
944                 mHasAngleOfArrivalFigureOfMeritReport);
945         bundle.putInt(KEY_AOA_TYPE, mAoaType);
946         bundle.putInt(KEY_NUM_OF_MSRMT_FOCUS_ON_RANGE, mNumOfMsrmtFocusOnRange);
947         bundle.putInt(KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_AZIMUTH, mNumOfMsrmtFocusOnAoaAzimuth);
948         bundle.putInt(KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_ELEVATION, mNumOfMsrmtFocusOnAoaElevation);
949         bundle.putLong(RANGING_ERROR_STREAK_TIMEOUT_MS, mRangingErrorStreakTimeoutMs);
950         bundle.putInt(KEY_LINK_LAYER_MODE, mLinkLayerMode);
951         bundle.putInt(KEY_DATA_REPETITION_COUNT, mDataRepetitionCount);
952         bundle.putInt(KEY_RANGING_TIME_STRUCT, mRangingTimeStruct);
953         bundle.putInt(KEY_MIN_FRAMES_PER_RR, mMinFramesPerRr);
954         bundle.putInt(KEY_MTU_SIZE, mMtuSize);
955         bundle.putInt(KEY_INTER_FRAME_INTERVAL, mInterFrameInterval);
956         bundle.putInt(UL_TDOA_TX_INTERVAL, mUlTdoaTxIntervalMs);
957         bundle.putInt(UL_TDOA_RANDOM_WINDOW, mUlTdoaRandomWindowMs);
958         bundle.putInt(UL_TDOA_DEVICE_ID_TYPE, mUlTdoaDeviceIdType);
959         bundle.putIntArray(UL_TDOA_DEVICE_ID, byteArrayToIntArray(mUlTdoaDeviceId));
960         bundle.putInt(UL_TDOA_TX_TIMESTAMP_TYPE, mUlTdoaTxTimestampType);
961         bundle.putInt(KEY_FILTER_TYPE, mFilterType);
962         bundle.putInt(KEY_MAX_NUMBER_OF_MEASUREMENTS, mMaxNumberOfMeasurements);
963         bundle.putBoolean(
964                 KEY_SESSION_DATA_TRANSFER_STATUS_NTF_CONFIG, mSessionDataTransferStatusNtfConfig);
965         if (mDeviceType == FiraParams.RANGING_DEVICE_TYPE_CONTROLLER) {
966             bundle.putInt(KEY_REFERENCE_TIME_BASE, mReferenceTimeBase);
967             bundle.putInt(KEY_REFERENCE_SESSION_HANDLE, mReferenceSessionHandle);
968             bundle.putInt(KEY_SESSION_OFFSET_IN_MICRO_SECONDS, mSessionOffsetInMicroSeconds);
969         }
970         bundle.putInt(KEY_APPLICATION_DATA_ENDPOINT, mApplicationDataEndpoint);
971         return bundle;
972     }
973 
fromBundle(PersistableBundle bundle)974     public static FiraOpenSessionParams fromBundle(PersistableBundle bundle) {
975         if (!isCorrectProtocol(bundle)) {
976             throw new IllegalArgumentException("Invalid protocol");
977         }
978 
979         switch (getBundleVersion(bundle)) {
980             case BUNDLE_VERSION_1:
981                 return parseBundleVersion1(bundle);
982 
983             default:
984                 throw new IllegalArgumentException("unknown bundle version");
985         }
986     }
987 
parseBundleVersion1(PersistableBundle bundle)988     private static FiraOpenSessionParams parseBundleVersion1(PersistableBundle bundle) {
989         int macAddressMode = bundle.getInt(KEY_MAC_ADDRESS_MODE);
990         int addressByteLength = 2;
991         if (macAddressMode == MAC_ADDRESS_MODE_8_BYTES) {
992             addressByteLength = 8;
993         }
994         UwbAddress deviceAddress =
995                 longToUwbAddress(bundle.getLong(KEY_DEVICE_ADDRESS), addressByteLength);
996 
997         FiraOpenSessionParams.Builder builder = new FiraOpenSessionParams.Builder()
998                 .setProtocolVersion(
999                         FiraProtocolVersion.fromString(
1000                                 requireNonNull(bundle.getString(KEY_PROTOCOL_VERSION))))
1001                 .setSessionId(bundle.getInt(KEY_SESSION_ID))
1002                 .setSessionType(bundle.getInt(KEY_SESSION_TYPE, FiraParams.SESSION_TYPE_RANGING))
1003                 .setDeviceType(bundle.getInt(KEY_DEVICE_TYPE))
1004                 .setDeviceRole(bundle.getInt(KEY_DEVICE_ROLE))
1005                 .setRangingRoundUsage(bundle.getInt(KEY_RANGING_ROUND_USAGE))
1006                 .setMultiNodeMode(bundle.getInt(KEY_MULTI_NODE_MODE))
1007                 .setDeviceAddress(deviceAddress)
1008                 // Changed from int to long. Look for int value, if long value not found to
1009                 // maintain backwards compatibility.
1010                 .setInitiationTime(bundle.getLong(KEY_INITIATION_TIME_MS))
1011                 .setAbsoluteInitiationTime(bundle.getLong(KEY_ABSOLUTE_INITIATION_TIME_US))
1012                 .setSlotDurationRstu(bundle.getInt(KEY_SLOT_DURATION_RSTU))
1013                 .setSlotsPerRangingRound(bundle.getInt(KEY_SLOTS_PER_RANGING_ROUND))
1014                 .setRangingIntervalMs(bundle.getInt(KEY_RANGING_INTERVAL_MS))
1015                 .setBlockStrideLength(bundle.getInt(KEY_BLOCK_STRIDE_LENGTH))
1016                 .setHoppingMode(bundle.getInt(KEY_HOPPING_MODE))
1017                 .setMaxRangingRoundRetries(bundle.getInt(KEY_MAX_RANGING_ROUND_RETRIES))
1018                 .setSessionPriority(bundle.getInt(KEY_SESSION_PRIORITY))
1019                 .setMacAddressMode(bundle.getInt(KEY_MAC_ADDRESS_MODE))
1020                 .setHasRangingResultReportMessage(
1021                         bundle.getBoolean(KEY_HAS_RANGING_RESULT_REPORT_MESSAGE))
1022                 .setHasControlMessage(
1023                         bundle.getBoolean(KEY_HAS_CONTROL_MESSAGE, true))
1024                 .setHasRangingControlPhase(
1025                         bundle.getBoolean(KEY_HAS_RANGING_CONTROL_PHASE, false))
1026                 .setMeasurementReportType(bundle.getInt(KEY_MEASUREMENT_REPORT_TYPE))
1027                 .setMeasurementReportPhase(bundle.getInt(KEY_MEASUREMENT_REPORT_PHASE))
1028                 .setInBandTerminationAttemptCount(
1029                         bundle.getInt(KEY_IN_BAND_TERMINATION_ATTEMPT_COUNT))
1030                 .setChannelNumber(bundle.getInt(KEY_CHANNEL_NUMBER))
1031                 .setPreambleCodeIndex(bundle.getInt(KEY_PREAMBLE_CODE_INDEX))
1032                 .setRframeConfig(bundle.getInt(KEY_RFRAME_CONFIG))
1033                 .setPrfMode(bundle.getInt(KEY_PRF_MODE))
1034                 .setCapSize(intArrayToByteArray(bundle.getIntArray(KEY_CAP_SIZE_RANGE)))
1035                 .setScheduledMode(bundle.getInt(KEY_SCHEDULED_MODE, TIME_SCHEDULED_RANGING))
1036                 .setPreambleDuration(bundle.getInt(KEY_PREAMBLE_DURATION))
1037                 .setSfdId(bundle.getInt(KEY_SFD_ID))
1038                 .setStsSegmentCount(bundle.getInt(KEY_STS_SEGMENT_COUNT))
1039                 .setStsLength(bundle.getInt(KEY_STS_LENGTH))
1040                 .setSessionKey(intArrayToByteArray(bundle.getIntArray(KEY_SESSION_KEY)))
1041                 .setSubsessionKey(intArrayToByteArray(bundle.getIntArray(KEY_SUBSESSION_KEY)))
1042                 .setPsduDataRate(bundle.getInt(KEY_PSDU_DATA_RATE))
1043                 .setBprfPhrDataRate(bundle.getInt(KEY_BPRF_PHR_DATA_RATE))
1044                 .setFcsType(bundle.getInt(KEY_FCS_TYPE))
1045                 .setIsTxAdaptivePayloadPowerEnabled(
1046                         bundle.getBoolean(KEY_IS_TX_ADAPTIVE_PAYLOAD_POWER_ENABLED))
1047                 .setStsConfig(bundle.getInt(KEY_STS_CONFIG))
1048                 .setSubSessionId(bundle.getInt(KEY_SUB_SESSION_ID))
1049                 .setVendorId(intArrayToByteArray(bundle.getIntArray(KEY_VENDOR_ID)))
1050                 .setStaticStsIV(intArrayToByteArray(bundle.getIntArray(KEY_STATIC_STS_IV)))
1051                 .setIsRssiReportingEnabled(bundle.getBoolean(KEY_IS_RSSI_REPORTING_ENABLED))
1052                 .setIsDiagnosticsEnabled(bundle.getBoolean(KEY_IS_DIAGNOSTICS_ENABLED, false))
1053                 .setDiagramsFrameReportsFieldsFlags((byte)
1054                         bundle.getInt(KEY_DIAGRAMS_FRAME_REPORTS_FIELDS_FLAGS, 0))
1055                 .setAntennaMode((byte) bundle.getInt(KEY_ANTENNA_MODE, ANTENNA_MODE_OMNI))
1056                 .setIsKeyRotationEnabled(bundle.getBoolean(KEY_IS_KEY_ROTATION_ENABLED))
1057                 .setKeyRotationRate(bundle.getInt(KEY_KEY_ROTATION_RATE))
1058                 .setAoaResultRequest(bundle.getInt(KEY_AOA_RESULT_REQUEST))
1059                 .setRangeDataNtfConfig(bundle.getInt(KEY_RANGE_DATA_NTF_CONFIG))
1060                 .setRangeDataNtfProximityNear(bundle.getInt(KEY_RANGE_DATA_NTF_PROXIMITY_NEAR))
1061                 .setRangeDataNtfProximityFar(bundle.getInt(KEY_RANGE_DATA_NTF_PROXIMITY_FAR))
1062                 .setRangeDataNtfAoaAzimuthLower(
1063                         bundle.getDouble(KEY_RANGE_DATA_NTF_AOA_AZIMUTH_LOWER,
1064                                 RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT))
1065                 .setRangeDataNtfAoaAzimuthUpper(
1066                         bundle.getDouble(KEY_RANGE_DATA_NTF_AOA_AZIMUTH_UPPER,
1067                                 RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT))
1068                 .setRangeDataNtfAoaElevationLower(
1069                         bundle.getDouble(KEY_RANGE_DATA_NTF_AOA_ELEVATION_LOWER,
1070                                 RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT))
1071                 .setRangeDataNtfAoaElevationUpper(
1072                         bundle.getDouble(KEY_RANGE_DATA_NTF_AOA_ELEVATION_UPPER,
1073                                 RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT))
1074                 .setHasTimeOfFlightReport(bundle.getBoolean(KEY_HAS_TIME_OF_FLIGHT_REPORT))
1075                 .setHasAngleOfArrivalAzimuthReport(
1076                         bundle.getBoolean(KEY_HAS_ANGLE_OF_ARRIVAL_AZIMUTH_REPORT))
1077                 .setHasAngleOfArrivalElevationReport(
1078                         bundle.getBoolean(KEY_HAS_ANGLE_OF_ARRIVAL_ELEVATION_REPORT))
1079                 .setHasAngleOfArrivalFigureOfMeritReport(
1080                         bundle.getBoolean(KEY_HAS_ANGLE_OF_ARRIVAL_FIGURE_OF_MERIT_REPORT))
1081                 .setAoaType(bundle.getInt(KEY_AOA_TYPE))
1082                 .setMeasurementFocusRatio(
1083                         bundle.getInt(KEY_NUM_OF_MSRMT_FOCUS_ON_RANGE),
1084                         bundle.getInt(KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_AZIMUTH),
1085                         bundle.getInt(KEY_NUM_OF_MSRMT_FOCUS_ON_AOA_ELEVATION))
1086                 .setRangingErrorStreakTimeoutMs(bundle
1087                         .getLong(RANGING_ERROR_STREAK_TIMEOUT_MS, 10_000L))
1088                 .setLinkLayerMode(bundle.getInt(KEY_LINK_LAYER_MODE, 0))
1089                 .setDataRepetitionCount(bundle.getInt(KEY_DATA_REPETITION_COUNT, 0))
1090                 .setRangingTimeStruct(bundle.getInt(KEY_RANGING_TIME_STRUCT,
1091                     BLOCK_BASED_SCHEDULING))
1092                 .setMinFramePerRr(bundle.getInt(KEY_MIN_FRAMES_PER_RR, 1))
1093                 .setMtuSize(bundle.getInt(KEY_MTU_SIZE, 1048))
1094                 .setInterFrameInterval(bundle.getInt(KEY_INTER_FRAME_INTERVAL, 1))
1095                 .setDlTdoaBlockStriding(bundle.getInt(KEY_DLTDOA_BLOCK_STRIDING))
1096                 .setUlTdoaTxIntervalMs(bundle.getInt(UL_TDOA_TX_INTERVAL))
1097                 .setUlTdoaRandomWindowMs(bundle.getInt(UL_TDOA_RANDOM_WINDOW))
1098                 .setUlTdoaDeviceIdType(bundle.getInt(UL_TDOA_DEVICE_ID_TYPE))
1099                 .setUlTdoaDeviceId(intArrayToByteArray(bundle.getIntArray(UL_TDOA_DEVICE_ID)))
1100                 .setUlTdoaTxTimestampType(bundle.getInt(UL_TDOA_TX_TIMESTAMP_TYPE))
1101                 .setFilterType(bundle.getInt(KEY_FILTER_TYPE, FILTER_TYPE_DEFAULT))
1102                 .setMaxNumberOfMeasurements(bundle.getInt(
1103                         KEY_MAX_NUMBER_OF_MEASUREMENTS, MAX_NUMBER_OF_MEASUREMENTS_DEFAULT))
1104                 .setSessionDataTransferStatusNtfConfig(bundle.getBoolean(
1105                         KEY_SESSION_DATA_TRANSFER_STATUS_NTF_CONFIG))
1106                 .setSessionTimeBase(bundle.getInt(KEY_REFERENCE_TIME_BASE),
1107                         bundle.getInt(KEY_REFERENCE_SESSION_HANDLE),
1108                         bundle.getInt(KEY_SESSION_OFFSET_IN_MICRO_SECONDS))
1109                 .setApplicationDataEndpoint(bundle.getInt(
1110                         KEY_APPLICATION_DATA_ENDPOINT, APPLICATION_DATA_ENDPOINT_DEFAULT));
1111 
1112         if (builder.isTimeScheduledTwrSession()) {
1113             long[] destAddresses = bundle.getLongArray(KEY_DEST_ADDRESS_LIST);
1114             if (destAddresses != null) {
1115                 List<UwbAddress> destAddressList = new ArrayList<>();
1116                 for (long address : destAddresses) {
1117                     destAddressList.add(longToUwbAddress(address, addressByteLength));
1118                 }
1119                 builder.setDestAddressList(destAddressList);
1120             }
1121         }
1122         return builder.build();
1123     }
1124 
getProtocolVersion()1125     public FiraProtocolVersion getProtocolVersion() {
1126         return mProtocolVersion;
1127     }
1128 
1129     /** Returns a builder from the params. */
toBuilder()1130     public Builder toBuilder() {
1131         return new Builder(this);
1132     }
1133 
1134     /** Builder */
1135     public static final class Builder {
1136         private final RequiredParam<FiraProtocolVersion> mProtocolVersion = new RequiredParam<>();
1137 
1138         private final RequiredParam<Integer> mSessionId = new RequiredParam<>();
1139         @SessionType
1140         private int mSessionType = FiraParams.SESSION_TYPE_RANGING;
1141         private final RequiredParam<Integer> mDeviceType = new RequiredParam<>();
1142         private final RequiredParam<Integer> mDeviceRole = new RequiredParam<>();
1143 
1144         /** UCI spec default: DS-TWR with deferred mode */
1145         @RangingRoundUsage
1146         private int mRangingRoundUsage = RANGING_ROUND_USAGE_DS_TWR_DEFERRED_MODE;
1147 
1148         private final RequiredParam<Integer> mMultiNodeMode = new RequiredParam<>();
1149         private UwbAddress mDeviceAddress = null;
1150         private List<UwbAddress> mDestAddressList = null;
1151 
1152         /** UCI spec default: 0ms */
1153         private long mInitiationTime = 0;
1154         private long mAbsoluteInitiationTime = 0;
1155 
1156         /** UCI spec default: 2400 RSTU (2 ms). */
1157         private int mSlotDurationRstu = 2400;
1158 
1159         /** UCI spec default: 25 slots per ranging round. */
1160         private int mSlotsPerRangingRound = SLOTS_PER_RR;
1161 
1162         /** UCI spec default: RANGING_INTERVAL(Fira 2.0: RANGING_DURATION) 200 ms */
1163         private int mRangingIntervalMs = 200;
1164 
1165         /** UCI spec default: no block striding. */
1166         private int mBlockStrideLength = 0;
1167 
1168         /** UCI spec default: no hopping. */
1169         private int mHoppingMode = HOPPING_MODE_DISABLE;
1170 
1171         /** UCI spec default: Termination is disabled and ranging round attempt is infinite */
1172         @IntRange(from = 0, to = 65535)
1173         private int mMaxRangingRoundRetries = 0;
1174 
1175         /** UCI spec default: priority 50 */
1176         private int mSessionPriority = 50;
1177 
1178         /** UCI spec default: 2-byte short address */
1179         @MacAddressMode private int mMacAddressMode = MAC_ADDRESS_MODE_2_BYTES;
1180 
1181         /** UCI spec default: RANGING_ROUND_CONTROL bit 0 default 1 */
1182         private boolean mHasRangingResultReportMessage = true;
1183 
1184         /** UCI spec default: RANGING_ROUND_CONTROL bit 1 default 1 */
1185         private boolean mHasControlMessage = true;
1186 
1187         /** UCI spec default: RANGING_ROUND_CONTROL bit 2 default 0 */
1188         private boolean mHasRangingControlPhase = false;
1189 
1190         /** UCI spec default: RANGING_ROUND_CONTROL bit 7 default 0 */
1191         @MeasurementReportType
1192         private int mMeasurementReportType = MEASUREMENT_REPORT_TYPE_INITIATOR_TO_RESPONDER;
1193 
1194         /** UCI spec default: RANGING_ROUND_CONTROL bit 6 default 0 */
1195         @MeasurementReportPhase
1196         private int mMeasurementReportPhase = MEASUREMENT_REPORT_PHASE_NOTSET;
1197 
1198         /** UCI spec default: in-band termination signal will be sent once. */
1199         @IntRange(from = 1, to = 10)
1200         private int mInBandTerminationAttemptCount = 1;
1201 
1202         /** UCI spec default: Channel 9, which is the only mandatory channel. */
1203         @UwbChannel private int mChannelNumber = UWB_CHANNEL_9;
1204 
1205         /** UCI spec default: index 10 */
1206         @UwbPreambleCodeIndex private int mPreambleCodeIndex = UWB_PREAMBLE_CODE_INDEX_10;
1207 
1208         /** UCI spec default: SP3 */
1209         private int mRframeConfig = RFRAME_CONFIG_SP3;
1210 
1211         /** UCI spec default: BPRF */
1212         @PrfMode private int mPrfMode = PRF_MODE_BPRF;
1213 
1214         /** UCI spec default: Octet [0] = SLOTS_PER_RR-1 Octet [1] = 0x05 */
1215         private byte[] mCapSize = {(SLOTS_PER_RR - 1) , MIN_CAP_SIZE};
1216 
1217         /** UCI spec default: Time scheduled ranging */
1218         @SchedulingMode private int mScheduledMode = TIME_SCHEDULED_RANGING;
1219 
1220         /** UCI spec default: 64 symbols */
1221         @PreambleDuration private int mPreambleDuration = PREAMBLE_DURATION_T64_SYMBOLS;
1222 
1223         /** UCI spec default: ID 2 */
1224         @SfdIdValue private int mSfdId = SFD_ID_VALUE_2;
1225 
1226         /** UCI spec default: one STS segment */
1227         @StsSegmentCountValue private int mStsSegmentCount = STS_SEGMENT_COUNT_VALUE_1;
1228 
1229         /** UCI spec default: 64 symbols */
1230         @StsLength private int mStsLength = STS_LENGTH_64_SYMBOLS;
1231 
1232         /** PROVISIONED STS only. 128-bit or 256-bit long */
1233         @Nullable private byte[] mSessionKey = null;
1234 
1235         /** PROVISIONED STS only. 128-bit or 256-bit long */
1236         @Nullable private byte[] mSubsessionKey = null;
1237 
1238         /** UCI spec default: 6.81Mb/s */
1239         @PsduDataRate private int mPsduDataRate = PSDU_DATA_RATE_6M81;
1240 
1241         /** UCI spec default: 850kb/s */
1242         @BprfPhrDataRate private int mBprfPhrDataRate = BPRF_PHR_DATA_RATE_850K;
1243 
1244         /** UCI spec default: CRC-16 */
1245         @MacFcsType private int mFcsType = MAC_FCS_TYPE_CRC_16;
1246 
1247         /** UCI spec default: adaptive payload power for TX disabled */
1248         private boolean mIsTxAdaptivePayloadPowerEnabled = false;
1249 
1250         /** UCI spec default: static STS */
1251         @StsConfig private int mStsConfig = STS_CONFIG_STATIC;
1252 
1253         /**
1254          * Per UCI spec, only required when STS config is
1255          * STS_CONFIG_DYNAMIC_FOR_CONTROLEE_INDIVIDUAL_KEY.
1256          */
1257         private final RequiredParam<Integer> mSubSessionId = new RequiredParam<>();
1258 
1259         /** STATIC STS only. For Key generation. 16-bit long */
1260         @Nullable private byte[] mVendorId = null;
1261 
1262         /** STATIC STS only. For Key generation. 48-bit long */
1263         @Nullable private byte[] mStaticStsIV = null;
1264 
1265         /** UCI spec default: RSSI reporting disabled */
1266         private boolean mIsRssiReportingEnabled = false;
1267 
1268         /** Diagnostics is Disabled by default */
1269         private boolean mIsDiagnosticsEnabled = false;
1270 
1271         /** All fields are set to 0 by default */
1272         private byte mDiagramsFrameReportsFieldsFlags = 0;
1273 
1274         /** Defaults to omni mode **/
1275         @AntennaMode private byte mAntennaMode = ANTENNA_MODE_OMNI;
1276 
1277         /** UCI spec default: no key rotation */
1278         private boolean mIsKeyRotationEnabled = false;
1279 
1280         /** UCI spec default: 0 */
1281         private int mKeyRotationRate = 0;
1282 
1283         /** UCI spec default: AoA enabled. */
1284         @AoaResultRequestMode
1285         private int mAoaResultRequest = AOA_RESULT_REQUEST_MODE_REQ_AOA_RESULTS;
1286 
1287         /** UCI spec default: Ranging notification enabled. */
1288         @RangeDataNtfConfig private int mRangeDataNtfConfig = RANGE_DATA_NTF_CONFIG_ENABLE;
1289 
1290         /** UCI spec default: 0 (No low-bound filtering) */
1291         private int mRangeDataNtfProximityNear = RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT;
1292 
1293         /** UCI spec default: 20000 cm (or 200 meters) */
1294         private int mRangeDataNtfProximityFar = RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT;
1295 
1296         /** UCI spec default: -180 (No low-bound filtering) */
1297         private double mRangeDataNtfAoaAzimuthLower = RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT;
1298 
1299         /** UCI spec default: +180 (No upper-bound filtering) */
1300         private double mRangeDataNtfAoaAzimuthUpper = RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT;
1301 
1302         /** UCI spec default: -90 (No low-bound filtering) */
1303         private double mRangeDataNtfAoaElevationLower = RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT;
1304 
1305         /** UCI spec default: +90 (No upper-bound filtering) */
1306         private double mRangeDataNtfAoaElevationUpper = RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT;
1307 
1308         /** UCI spec default: RESULT_REPORT_CONFIG bit 0 is 1 */
1309         private boolean mHasTimeOfFlightReport = true;
1310 
1311         /** UCI spec default: RESULT_REPORT_CONFIG bit 1 is 0 */
1312         private boolean mHasAngleOfArrivalAzimuthReport = false;
1313 
1314         /** UCI spec default: RESULT_REPORT_CONFIG bit 2 is 0 */
1315         private boolean mHasAngleOfArrivalElevationReport = false;
1316 
1317         /** UCI spec default: RESULT_REPORT_CONFIG bit 3 is 0 */
1318         private boolean mHasAngleOfArrivalFigureOfMeritReport = false;
1319 
1320         /** Not defined in UCI, we use Azimuth-only as default */
1321         @AoaType private int mAoaType = AOA_TYPE_AZIMUTH;
1322 
1323         /** Interleaving ratios are not set by default */
1324         private int mNumOfMsrmtFocusOnRange = 0;
1325         private int mNumOfMsrmtFocusOnAoaAzimuth = 0;
1326         private int mNumOfMsrmtFocusOnAoaElevation = 0;
1327 
1328         /** Ranging result error streak timeout in Milliseconds*/
1329         private long mRangingErrorStreakTimeoutMs = 10_000L;
1330 
1331         /** UCI spec default: 0 */
1332         private int mLinkLayerMode = 0;
1333 
1334         /** UCI spec default: 0x00(No repetition) */
1335         private int mDataRepetitionCount = 0;
1336 
1337         /** UCI spec default: 0x01 */
1338         private int mRangingTimeStruct = BLOCK_BASED_SCHEDULING;
1339 
1340         /** UCI spec default: 1 */
1341         public int mMinFramesPerRr = 1;
1342 
1343         /** No UCI spec default*/
1344         public int mMtuSize = 1048;
1345 
1346         /** UCI spec default: 1 */
1347         public int mInterFrameInterval = 1;
1348 
1349         /** UCI spec default: no dltdoa block striding. */
1350         private int mDlTdoaBlockStriding = 0;
1351 
1352         /** Ul-TDoA Tx Interval in Milliseconds */
1353         private int mUlTdoaTxIntervalMs = 2000;
1354 
1355         /** Ul-TDoA Random Window in Milliseconds */
1356         private int mUlTdoaRandomWindowMs = 0;
1357 
1358         /** Ul-TDoA Device ID type */
1359         @UlTdoaDeviceIdType private int mUlTdoaDeviceIdType = UL_TDOA_DEVICE_ID_NONE;
1360 
1361         /** Ul-TDoA Device ID */
1362         @Nullable private byte[] mUlTdoaDeviceId;
1363 
1364         /** Ul-TDoA Tx Timestamp Type */
1365         @UlTdoaTxTimestampType private int mUlTdoaTxTimestampType = TX_TIMESTAMP_NONE;
1366 
1367         /** AoA/distance filtering type */
1368         @FilterType private int mFilterType = FILTER_TYPE_DEFAULT;
1369 
1370         private int mMaxNumberOfMeasurements = MAX_NUMBER_OF_MEASUREMENTS_DEFAULT;
1371 
1372         /** UCI spec default: 0x00(Disable) */
1373         private boolean mSessionDataTransferStatusNtfConfig = false;
1374 
1375         /** UCI spec default: 9 Octets of SESSION_TIME_BASE as per UCI spec*/
1376         private int mReferenceTimeBase = 0;
1377 
1378         private int mReferenceSessionHandle = 0;
1379 
1380         private int mSessionOffsetInMicroSeconds = 0;
1381 
1382         private int mApplicationDataEndpoint = APPLICATION_DATA_ENDPOINT_DEFAULT;
1383 
Builder()1384         public Builder() {}
1385 
Builder(@onNull Builder builder)1386         public Builder(@NonNull Builder builder) {
1387             mProtocolVersion.set(builder.mProtocolVersion.get());
1388             mSessionId.set(builder.mSessionId.get());
1389             mSessionType = builder.mSessionType;
1390             mDeviceType.set(builder.mDeviceType.get());
1391             mDeviceRole.set(builder.mDeviceRole.get());
1392             mRangingRoundUsage = builder.mRangingRoundUsage;
1393             mMultiNodeMode.set(builder.mMultiNodeMode.get());
1394             mDeviceAddress = builder.mDeviceAddress;
1395             mDestAddressList = builder.mDestAddressList;
1396             mInitiationTime = builder.mInitiationTime;
1397             mAbsoluteInitiationTime = builder.mAbsoluteInitiationTime;
1398             mSlotDurationRstu = builder.mSlotDurationRstu;
1399             mSlotsPerRangingRound = builder.mSlotsPerRangingRound;
1400             mRangingIntervalMs = builder.mRangingIntervalMs;
1401             mBlockStrideLength = builder.mBlockStrideLength;
1402             mHoppingMode = builder.mHoppingMode;
1403             mMaxRangingRoundRetries = builder.mMaxRangingRoundRetries;
1404             mSessionPriority = builder.mSessionPriority;
1405             mMacAddressMode = builder.mMacAddressMode;
1406             mHasRangingResultReportMessage = builder.mHasRangingResultReportMessage;
1407             mHasControlMessage = builder.mHasControlMessage;
1408             mHasRangingControlPhase = builder.mHasRangingControlPhase;
1409             mMeasurementReportType = builder.mMeasurementReportType;
1410             mMeasurementReportPhase = builder.mMeasurementReportPhase;
1411             mInBandTerminationAttemptCount = builder.mInBandTerminationAttemptCount;
1412             mChannelNumber = builder.mChannelNumber;
1413             mPreambleCodeIndex = builder.mPreambleCodeIndex;
1414             mRframeConfig = builder.mRframeConfig;
1415             mPrfMode = builder.mPrfMode;
1416             mScheduledMode = builder.mScheduledMode;
1417             if (builder.mScheduledMode == CONTENTION_BASED_RANGING) {
1418                 mCapSize = builder.mCapSize;
1419             }
1420             mPreambleDuration = builder.mPreambleDuration;
1421             mSfdId = builder.mSfdId;
1422             mStsSegmentCount = builder.mStsSegmentCount;
1423             mStsLength = builder.mStsLength;
1424             mSessionKey = builder.mSessionKey;
1425             mSubsessionKey = builder.mSubsessionKey;
1426             mPsduDataRate = builder.mPsduDataRate;
1427             mBprfPhrDataRate = builder.mBprfPhrDataRate;
1428             mFcsType = builder.mFcsType;
1429             mIsTxAdaptivePayloadPowerEnabled = builder.mIsTxAdaptivePayloadPowerEnabled;
1430             mStsConfig = builder.mStsConfig;
1431             if (builder.mSubSessionId.isSet()) mSubSessionId.set(builder.mSubSessionId.get());
1432             mVendorId = builder.mVendorId;
1433             mStaticStsIV = builder.mStaticStsIV;
1434             mIsRssiReportingEnabled = builder.mIsRssiReportingEnabled;
1435             mIsDiagnosticsEnabled = builder.mIsDiagnosticsEnabled;
1436             mDiagramsFrameReportsFieldsFlags = builder.mDiagramsFrameReportsFieldsFlags;
1437             mAntennaMode = builder.mAntennaMode;
1438             mIsKeyRotationEnabled = builder.mIsKeyRotationEnabled;
1439             mKeyRotationRate = builder.mKeyRotationRate;
1440             mAoaResultRequest = builder.mAoaResultRequest;
1441             mRangeDataNtfConfig = builder.mRangeDataNtfConfig;
1442             mRangeDataNtfProximityNear = builder.mRangeDataNtfProximityNear;
1443             mRangeDataNtfProximityFar = builder.mRangeDataNtfProximityFar;
1444             mRangeDataNtfAoaAzimuthLower = builder.mRangeDataNtfAoaAzimuthLower;
1445             mRangeDataNtfAoaAzimuthUpper = builder.mRangeDataNtfAoaAzimuthUpper;
1446             mRangeDataNtfAoaElevationLower = builder.mRangeDataNtfAoaElevationLower;
1447             mRangeDataNtfAoaElevationUpper = builder.mRangeDataNtfAoaElevationUpper;
1448             mHasTimeOfFlightReport = builder.mHasTimeOfFlightReport;
1449             mHasAngleOfArrivalAzimuthReport = builder.mHasAngleOfArrivalAzimuthReport;
1450             mHasAngleOfArrivalElevationReport = builder.mHasAngleOfArrivalElevationReport;
1451             mHasAngleOfArrivalFigureOfMeritReport = builder.mHasAngleOfArrivalFigureOfMeritReport;
1452             mAoaType = builder.mAoaType;
1453             mNumOfMsrmtFocusOnRange = builder.mNumOfMsrmtFocusOnRange;
1454             mNumOfMsrmtFocusOnAoaAzimuth = builder.mNumOfMsrmtFocusOnAoaAzimuth;
1455             mNumOfMsrmtFocusOnAoaElevation = builder.mNumOfMsrmtFocusOnAoaElevation;
1456             mRangingErrorStreakTimeoutMs = builder.mRangingErrorStreakTimeoutMs;
1457             mLinkLayerMode = builder.mLinkLayerMode;
1458             mDataRepetitionCount = builder.mDataRepetitionCount;
1459             mRangingTimeStruct = builder.mRangingTimeStruct;
1460             mMinFramesPerRr = builder.mMinFramesPerRr;
1461             mMtuSize = builder.mMtuSize;
1462             mInterFrameInterval = builder.mInterFrameInterval;
1463             mDlTdoaBlockStriding = builder.mDlTdoaBlockStriding;
1464             mUlTdoaTxIntervalMs = builder.mUlTdoaTxIntervalMs;
1465             mUlTdoaRandomWindowMs = builder.mUlTdoaRandomWindowMs;
1466             mUlTdoaDeviceIdType = builder.mUlTdoaDeviceIdType;
1467             mUlTdoaDeviceId = builder.mUlTdoaDeviceId;
1468             mUlTdoaTxTimestampType = builder.mUlTdoaTxTimestampType;
1469             mMaxNumberOfMeasurements = builder.mMaxNumberOfMeasurements;
1470             mSessionDataTransferStatusNtfConfig = builder.mSessionDataTransferStatusNtfConfig;
1471             mReferenceTimeBase = builder.mReferenceTimeBase;
1472             mReferenceSessionHandle = builder.mReferenceSessionHandle;
1473             mSessionOffsetInMicroSeconds = builder.mSessionOffsetInMicroSeconds;
1474             mApplicationDataEndpoint = builder.mApplicationDataEndpoint;
1475         }
1476 
Builder(@onNull FiraOpenSessionParams params)1477         public Builder(@NonNull FiraOpenSessionParams params) {
1478             mProtocolVersion.set(params.mProtocolVersion);
1479             mSessionId.set(params.mSessionId);
1480             mSessionType = params.mSessionType;
1481             mDeviceType.set(params.mDeviceType);
1482             mDeviceRole.set(params.mDeviceRole);
1483             mRangingRoundUsage = params.mRangingRoundUsage;
1484             mMultiNodeMode.set(params.mMultiNodeMode);
1485             mDeviceAddress = params.mDeviceAddress;
1486             mDestAddressList = params.mDestAddressList;
1487             mInitiationTime = params.mInitiationTime;
1488             mAbsoluteInitiationTime = params.mAbsoluteInitiationTime;
1489             mSlotDurationRstu = params.mSlotDurationRstu;
1490             mSlotsPerRangingRound = params.mSlotsPerRangingRound;
1491             mRangingIntervalMs = params.mRangingIntervalMs;
1492             mBlockStrideLength = params.mBlockStrideLength;
1493             mHoppingMode = params.mHoppingMode;
1494             mMaxRangingRoundRetries = params.mMaxRangingRoundRetries;
1495             mSessionPriority = params.mSessionPriority;
1496             mMacAddressMode = params.mMacAddressMode;
1497             mHasRangingResultReportMessage = params.mHasRangingResultReportMessage;
1498             mHasControlMessage = params.mHasControlMessage;
1499             mHasRangingControlPhase = params.mHasRangingControlPhase;
1500             mMeasurementReportType = params.mMeasurementReportType;
1501             mMeasurementReportPhase = params.mMeasurementReportPhase;
1502             mInBandTerminationAttemptCount = params.mInBandTerminationAttemptCount;
1503             mChannelNumber = params.mChannelNumber;
1504             mPreambleCodeIndex = params.mPreambleCodeIndex;
1505             mRframeConfig = params.mRframeConfig;
1506             mPrfMode = params.mPrfMode;
1507             mScheduledMode = params.mScheduledMode;
1508             if (params.mScheduledMode == CONTENTION_BASED_RANGING) {
1509                 mCapSize = params.mCapSize;
1510             }
1511             mPreambleDuration = params.mPreambleDuration;
1512             mSfdId = params.mSfdId;
1513             mStsSegmentCount = params.mStsSegmentCount;
1514             mStsLength = params.mStsLength;
1515             mSessionKey = params.mSessionKey;
1516             mSubsessionKey = params.mSubSessionKey;
1517             mPsduDataRate = params.mPsduDataRate;
1518             mBprfPhrDataRate = params.mBprfPhrDataRate;
1519             mFcsType = params.mFcsType;
1520             mIsTxAdaptivePayloadPowerEnabled = params.mIsTxAdaptivePayloadPowerEnabled;
1521             mStsConfig = params.mStsConfig;
1522             mSubSessionId.set(params.mSubSessionId);
1523             mVendorId = params.mVendorId;
1524             mStaticStsIV = params.mStaticStsIV;
1525             mIsRssiReportingEnabled = params.mIsRssiReportingEnabled;
1526             mIsDiagnosticsEnabled = params.mIsDiagnosticsEnabled;
1527             mDiagramsFrameReportsFieldsFlags = params.mDiagramsFrameReportsFieldsFlags;
1528             mAntennaMode = params.mAntennaMode;
1529             mIsKeyRotationEnabled = params.mIsKeyRotationEnabled;
1530             mKeyRotationRate = params.mKeyRotationRate;
1531             mAoaResultRequest = params.mAoaResultRequest;
1532             mRangeDataNtfConfig = params.mRangeDataNtfConfig;
1533             mRangeDataNtfProximityNear = params.mRangeDataNtfProximityNear;
1534             mRangeDataNtfProximityFar = params.mRangeDataNtfProximityFar;
1535             mRangeDataNtfAoaAzimuthLower = params.mRangeDataNtfAoaAzimuthLower;
1536             mRangeDataNtfAoaAzimuthUpper = params.mRangeDataNtfAoaAzimuthUpper;
1537             mRangeDataNtfAoaElevationLower = params.mRangeDataNtfAoaElevationLower;
1538             mRangeDataNtfAoaElevationUpper = params.mRangeDataNtfAoaElevationUpper;
1539             mHasTimeOfFlightReport = params.mHasTimeOfFlightReport;
1540             mHasAngleOfArrivalAzimuthReport = params.mHasAngleOfArrivalAzimuthReport;
1541             mHasAngleOfArrivalElevationReport = params.mHasAngleOfArrivalElevationReport;
1542             mHasAngleOfArrivalFigureOfMeritReport = params.mHasAngleOfArrivalFigureOfMeritReport;
1543             mAoaType = params.mAoaType;
1544             mNumOfMsrmtFocusOnRange = params.mNumOfMsrmtFocusOnRange;
1545             mNumOfMsrmtFocusOnAoaAzimuth = params.mNumOfMsrmtFocusOnAoaAzimuth;
1546             mNumOfMsrmtFocusOnAoaElevation = params.mNumOfMsrmtFocusOnAoaElevation;
1547             mRangingErrorStreakTimeoutMs = params.mRangingErrorStreakTimeoutMs;
1548             mLinkLayerMode = params.mLinkLayerMode;
1549             mDataRepetitionCount = params.mDataRepetitionCount;
1550             mRangingTimeStruct = params.mRangingTimeStruct;
1551             mMinFramesPerRr = params.mMinFramesPerRr;
1552             mMtuSize = params.mMtuSize;
1553             mInterFrameInterval = params.mInterFrameInterval;
1554             mDlTdoaBlockStriding = params.mDlTdoaBlockStriding;
1555             mUlTdoaTxIntervalMs = params.mUlTdoaTxIntervalMs;
1556             mUlTdoaRandomWindowMs = params.mUlTdoaRandomWindowMs;
1557             mUlTdoaDeviceIdType = params.mUlTdoaDeviceIdType;
1558             mUlTdoaDeviceId = params.mUlTdoaDeviceId;
1559             mUlTdoaTxTimestampType = params.mUlTdoaTxTimestampType;
1560             mFilterType = params.mFilterType;
1561             mMaxNumberOfMeasurements = params.mMaxNumberOfMeasurements;
1562             mSessionDataTransferStatusNtfConfig = params.mSessionDataTransferStatusNtfConfig;
1563             mReferenceTimeBase = params.mReferenceTimeBase;
1564             mReferenceSessionHandle = params.mReferenceSessionHandle;
1565             mSessionOffsetInMicroSeconds = params.mSessionOffsetInMicroSeconds;
1566             mApplicationDataEndpoint = params.mApplicationDataEndpoint;
1567         }
1568 
setProtocolVersion(FiraProtocolVersion version)1569         public FiraOpenSessionParams.Builder setProtocolVersion(FiraProtocolVersion version) {
1570             mProtocolVersion.set(version);
1571             return this;
1572         }
1573 
setSessionId(int sessionId)1574         public FiraOpenSessionParams.Builder setSessionId(int sessionId) {
1575             mSessionId.set(sessionId);
1576             return this;
1577         }
1578 
setSessionType(@essionType int sessionType)1579         public FiraOpenSessionParams.Builder setSessionType(@SessionType int sessionType) {
1580             mSessionType = sessionType;
1581             return this;
1582         }
1583 
setDeviceType(@angingDeviceType int deviceType)1584         public FiraOpenSessionParams.Builder setDeviceType(@RangingDeviceType int deviceType) {
1585             mDeviceType.set(deviceType);
1586             return this;
1587         }
1588 
setDeviceRole(@angingDeviceRole int deviceRole)1589         public FiraOpenSessionParams.Builder setDeviceRole(@RangingDeviceRole int deviceRole) {
1590             mDeviceRole.set(deviceRole);
1591             return this;
1592         }
1593 
setRangingRoundUsage( @angingRoundUsage int rangingRoundUsage)1594         public FiraOpenSessionParams.Builder setRangingRoundUsage(
1595                 @RangingRoundUsage int rangingRoundUsage) {
1596             mRangingRoundUsage = rangingRoundUsage;
1597             return this;
1598         }
1599 
setMultiNodeMode(@ultiNodeMode int multiNodeMode)1600         public FiraOpenSessionParams.Builder setMultiNodeMode(@MultiNodeMode int multiNodeMode) {
1601             mMultiNodeMode.set(multiNodeMode);
1602             return this;
1603         }
1604 
setDeviceAddress(UwbAddress deviceAddress)1605         public FiraOpenSessionParams.Builder setDeviceAddress(UwbAddress deviceAddress) {
1606             mDeviceAddress = deviceAddress;
1607             return this;
1608         }
1609 
setDestAddressList(List<UwbAddress> destAddressList)1610         public FiraOpenSessionParams.Builder setDestAddressList(List<UwbAddress> destAddressList) {
1611             mDestAddressList = destAddressList;
1612             return this;
1613         }
1614 
1615         /**
1616          * Sets the UWB initiation time.
1617          *
1618          * @param initiationTime UWB initiation time:
1619          *        FiRa 1.0: Relative time (in milli-seconds).
1620          *        FiRa 2.0: Relative time (in milli-seconds).
1621          *            For a FiRa 2.0 device, the UWB Service will query the absolute UWBS timestamp
1622          *            and add the relative time (in milli-seconds) configured here, to compute the
1623          *            absolute time that will be configured in the UWB_INITIATION_TIME parameter.
1624          */
setInitiationTime(long initiationTime)1625         public FiraOpenSessionParams.Builder setInitiationTime(long initiationTime) {
1626             mInitiationTime = initiationTime;
1627             return this;
1628         }
1629 
1630         /**
1631          * Sets the Absolute UWB initiation time.
1632          *
1633          * @param absoluteInitiationTime Absolute UWB initiation time (in micro-seconds). This is
1634          *        applicable only for FiRa 2.0+ devices, as specified in CR-272.
1635          */
setAbsoluteInitiationTime( long absoluteInitiationTime)1636         public FiraOpenSessionParams.Builder setAbsoluteInitiationTime(
1637                 long absoluteInitiationTime) {
1638             mAbsoluteInitiationTime = absoluteInitiationTime;
1639             return this;
1640         }
1641 
setSlotDurationRstu(int slotDurationRstu)1642         public FiraOpenSessionParams.Builder setSlotDurationRstu(int slotDurationRstu) {
1643             mSlotDurationRstu = slotDurationRstu;
1644             return this;
1645         }
1646 
setSlotsPerRangingRound(int slotsPerRangingRound)1647         public FiraOpenSessionParams.Builder setSlotsPerRangingRound(int slotsPerRangingRound) {
1648             mSlotsPerRangingRound = slotsPerRangingRound;
1649             return this;
1650         }
1651 
setRangingIntervalMs(int rangingIntervalMs)1652         public FiraOpenSessionParams.Builder setRangingIntervalMs(int rangingIntervalMs) {
1653             mRangingIntervalMs = rangingIntervalMs;
1654             return this;
1655         }
1656 
setBlockStrideLength(int blockStrideLength)1657         public FiraOpenSessionParams.Builder setBlockStrideLength(int blockStrideLength) {
1658             mBlockStrideLength = blockStrideLength;
1659             return this;
1660         }
1661 
setHoppingMode(int hoppingMode)1662         public FiraOpenSessionParams.Builder setHoppingMode(int hoppingMode) {
1663             this.mHoppingMode = hoppingMode;
1664             return this;
1665         }
1666 
setMaxRangingRoundRetries( @ntRangefrom = 0, to = 65535) int maxRangingRoundRetries)1667         public FiraOpenSessionParams.Builder setMaxRangingRoundRetries(
1668                 @IntRange(from = 0, to = 65535) int maxRangingRoundRetries) {
1669             mMaxRangingRoundRetries = maxRangingRoundRetries;
1670             return this;
1671         }
1672 
setSessionPriority(int sessionPriority)1673         public FiraOpenSessionParams.Builder setSessionPriority(int sessionPriority) {
1674             mSessionPriority = sessionPriority;
1675             return this;
1676         }
1677 
setMacAddressMode(int macAddressMode)1678         public FiraOpenSessionParams.Builder setMacAddressMode(int macAddressMode) {
1679             this.mMacAddressMode = macAddressMode;
1680             return this;
1681         }
1682 
setHasRangingResultReportMessage( boolean hasRangingResultReportMessage)1683         public FiraOpenSessionParams.Builder setHasRangingResultReportMessage(
1684                 boolean hasRangingResultReportMessage) {
1685             mHasRangingResultReportMessage = hasRangingResultReportMessage;
1686             return this;
1687         }
1688 
setHasControlMessage(boolean hasControlMessage)1689         public FiraOpenSessionParams.Builder setHasControlMessage(boolean hasControlMessage) {
1690             mHasControlMessage = hasControlMessage;
1691             return this;
1692         }
1693 
setHasRangingControlPhase( boolean hasRangingControlPhase)1694         public FiraOpenSessionParams.Builder setHasRangingControlPhase(
1695                 boolean hasRangingControlPhase) {
1696             mHasRangingControlPhase = hasRangingControlPhase;
1697             return this;
1698         }
1699 
setMeasurementReportType( @easurementReportType int measurementReportType)1700         public FiraOpenSessionParams.Builder setMeasurementReportType(
1701                 @MeasurementReportType int measurementReportType) {
1702             mMeasurementReportType = measurementReportType;
1703             return this;
1704         }
1705 
setMeasurementReportPhase( @easurementReportPhase int measurementReportPhase)1706         public FiraOpenSessionParams.Builder setMeasurementReportPhase(
1707                 @MeasurementReportPhase int measurementReportPhase) {
1708             mMeasurementReportPhase = measurementReportPhase;
1709             return this;
1710         }
1711 
setInBandTerminationAttemptCount( @ntRangefrom = 1, to = 10) int inBandTerminationAttemptCount)1712         public FiraOpenSessionParams.Builder setInBandTerminationAttemptCount(
1713                 @IntRange(from = 1, to = 10) int inBandTerminationAttemptCount) {
1714             mInBandTerminationAttemptCount = inBandTerminationAttemptCount;
1715             return this;
1716         }
1717 
setChannelNumber(@wbChannel int channelNumber)1718         public FiraOpenSessionParams.Builder setChannelNumber(@UwbChannel int channelNumber) {
1719             mChannelNumber = channelNumber;
1720             return this;
1721         }
1722 
setPreambleCodeIndex( @wbPreambleCodeIndex int preambleCodeIndex)1723         public FiraOpenSessionParams.Builder setPreambleCodeIndex(
1724                 @UwbPreambleCodeIndex int preambleCodeIndex) {
1725             mPreambleCodeIndex = preambleCodeIndex;
1726             return this;
1727         }
1728 
setRframeConfig(@frameConfig int rframeConfig)1729         public FiraOpenSessionParams.Builder setRframeConfig(@RframeConfig int rframeConfig) {
1730             mRframeConfig = rframeConfig;
1731             return this;
1732         }
1733 
setPrfMode(@rfMode int prfMode)1734         public FiraOpenSessionParams.Builder setPrfMode(@PrfMode int prfMode) {
1735             mPrfMode = prfMode;
1736             return this;
1737         }
1738 
setCapSize(byte[] capSize)1739         public FiraOpenSessionParams.Builder setCapSize(byte[] capSize) {
1740             mCapSize = capSize;
1741             return this;
1742         }
1743 
setScheduledMode(@chedulingMode int scheduledMode)1744         public FiraOpenSessionParams.Builder setScheduledMode(@SchedulingMode int scheduledMode) {
1745             mScheduledMode = scheduledMode;
1746             return this;
1747         }
1748 
setPreambleDuration( @reambleDuration int preambleDuration)1749         public FiraOpenSessionParams.Builder setPreambleDuration(
1750                 @PreambleDuration int preambleDuration) {
1751             mPreambleDuration = preambleDuration;
1752             return this;
1753         }
1754 
setSfdId(@fdIdValue int sfdId)1755         public FiraOpenSessionParams.Builder setSfdId(@SfdIdValue int sfdId) {
1756             mSfdId = sfdId;
1757             return this;
1758         }
1759 
setStsSegmentCount( @tsSegmentCountValue int stsSegmentCount)1760         public FiraOpenSessionParams.Builder setStsSegmentCount(
1761                 @StsSegmentCountValue int stsSegmentCount) {
1762             mStsSegmentCount = stsSegmentCount;
1763             return this;
1764         }
1765 
setStsLength(@tsLength int stsLength)1766         public FiraOpenSessionParams.Builder setStsLength(@StsLength int stsLength) {
1767             mStsLength = stsLength;
1768             return this;
1769         }
1770 
1771         /** set session key */
setSessionKey(@ullable byte[] sessionKey)1772         public FiraOpenSessionParams.Builder setSessionKey(@Nullable byte[] sessionKey) {
1773             mSessionKey = sessionKey;
1774             return this;
1775         }
1776 
1777         /** set subsession key */
setSubsessionKey(@ullable byte[] subsessionKey)1778         public FiraOpenSessionParams.Builder setSubsessionKey(@Nullable byte[] subsessionKey) {
1779             mSubsessionKey = subsessionKey;
1780             return this;
1781         }
1782 
setPsduDataRate(@sduDataRate int psduDataRate)1783         public FiraOpenSessionParams.Builder setPsduDataRate(@PsduDataRate int psduDataRate) {
1784             mPsduDataRate = psduDataRate;
1785             return this;
1786         }
1787 
setBprfPhrDataRate( @prfPhrDataRate int bprfPhrDataRate)1788         public FiraOpenSessionParams.Builder setBprfPhrDataRate(
1789                 @BprfPhrDataRate int bprfPhrDataRate) {
1790             mBprfPhrDataRate = bprfPhrDataRate;
1791             return this;
1792         }
1793 
setFcsType(@acFcsType int fcsType)1794         public FiraOpenSessionParams.Builder setFcsType(@MacFcsType int fcsType) {
1795             mFcsType = fcsType;
1796             return this;
1797         }
1798 
setIsTxAdaptivePayloadPowerEnabled( boolean isTxAdaptivePayloadPowerEnabled)1799         public FiraOpenSessionParams.Builder setIsTxAdaptivePayloadPowerEnabled(
1800                 boolean isTxAdaptivePayloadPowerEnabled) {
1801             mIsTxAdaptivePayloadPowerEnabled = isTxAdaptivePayloadPowerEnabled;
1802             return this;
1803         }
1804 
setStsConfig(@tsConfig int stsConfig)1805         public FiraOpenSessionParams.Builder setStsConfig(@StsConfig int stsConfig) {
1806             mStsConfig = stsConfig;
1807             return this;
1808         }
1809 
setSubSessionId(int subSessionId)1810         public FiraOpenSessionParams.Builder setSubSessionId(int subSessionId) {
1811             mSubSessionId.set(subSessionId);
1812             return this;
1813         }
1814 
setVendorId(@ullable byte[] vendorId)1815         public FiraOpenSessionParams.Builder setVendorId(@Nullable byte[] vendorId) {
1816             mVendorId = vendorId;
1817             return this;
1818         }
1819 
setStaticStsIV(@ullable byte[] staticStsIV)1820         public FiraOpenSessionParams.Builder setStaticStsIV(@Nullable byte[] staticStsIV) {
1821             mStaticStsIV = staticStsIV;
1822             return this;
1823         }
1824 
1825         /** Set whether rssi reporting is enabled */
1826         public FiraOpenSessionParams.Builder
setIsRssiReportingEnabled(boolean isRssiReportingEnabled)1827                 setIsRssiReportingEnabled(boolean isRssiReportingEnabled) {
1828             mIsRssiReportingEnabled = isRssiReportingEnabled;
1829             return this;
1830         }
1831 
1832         /** Set whether diagnostics is enabled */
setIsDiagnosticsEnabled(boolean isDiagnosticsEnabled)1833         public FiraOpenSessionParams.Builder setIsDiagnosticsEnabled(boolean isDiagnosticsEnabled) {
1834             mIsDiagnosticsEnabled = isDiagnosticsEnabled;
1835             return this;
1836         }
1837 
1838         /** Set the activated field
1839          *  b0: Activate RSSIs field
1840          *  b1: Activate AoAs field
1841          *  b2: Activate CIRs field
1842          *  b3 - b7: RFU
1843          */
1844         public FiraOpenSessionParams.Builder
setDiagramsFrameReportsFieldsFlags(byte diagramsFrameReportsFieldsFlags)1845                 setDiagramsFrameReportsFieldsFlags(byte diagramsFrameReportsFieldsFlags) {
1846             mDiagramsFrameReportsFieldsFlags = diagramsFrameReportsFieldsFlags;
1847             return this;
1848         }
1849 
1850         /** Set the antenna mode **/
setAntennaMode(@ntennaMode byte antennaMode)1851         public FiraOpenSessionParams.Builder setAntennaMode(@AntennaMode byte antennaMode) {
1852             mAntennaMode = antennaMode;
1853             return this;
1854         }
1855 
setIsKeyRotationEnabled(boolean isKeyRotationEnabled)1856         public FiraOpenSessionParams.Builder setIsKeyRotationEnabled(boolean isKeyRotationEnabled) {
1857             mIsKeyRotationEnabled = isKeyRotationEnabled;
1858             return this;
1859         }
1860 
setKeyRotationRate(int keyRotationRate)1861         public FiraOpenSessionParams.Builder setKeyRotationRate(int keyRotationRate) {
1862             mKeyRotationRate = keyRotationRate;
1863             return this;
1864         }
1865 
setAoaResultRequest( @oaResultRequestMode int aoaResultRequest)1866         public FiraOpenSessionParams.Builder setAoaResultRequest(
1867                 @AoaResultRequestMode int aoaResultRequest) {
1868             mAoaResultRequest = aoaResultRequest;
1869             return this;
1870         }
1871 
setRangeDataNtfConfig( @angeDataNtfConfig int rangeDataNtfConfig)1872         public FiraOpenSessionParams.Builder setRangeDataNtfConfig(
1873                 @RangeDataNtfConfig int rangeDataNtfConfig) {
1874             mRangeDataNtfConfig = rangeDataNtfConfig;
1875             return this;
1876         }
1877 
setRangeDataNtfProximityNear( @ntRangefrom = RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT, to = RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT) int rangeDataNtfProximityNear)1878         public FiraOpenSessionParams.Builder setRangeDataNtfProximityNear(
1879                 @IntRange(from = RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT,
1880                         to = RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT)
1881                         int rangeDataNtfProximityNear) {
1882             mRangeDataNtfProximityNear = rangeDataNtfProximityNear;
1883             return this;
1884         }
1885 
setRangeDataNtfProximityFar( @ntRangefrom = RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT, to = RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT) int rangeDataNtfProximityFar)1886         public FiraOpenSessionParams.Builder setRangeDataNtfProximityFar(
1887                 @IntRange(from = RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT,
1888                         to = RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT)
1889                         int rangeDataNtfProximityFar) {
1890             mRangeDataNtfProximityFar = rangeDataNtfProximityFar;
1891             return this;
1892         }
1893 
setRangeDataNtfAoaAzimuthLower( @loatRangefrom = RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT, to = RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT) double rangeDataNtfAoaAzimuthLower)1894         public FiraOpenSessionParams.Builder setRangeDataNtfAoaAzimuthLower(
1895                 @FloatRange(from = RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT,
1896                         to = RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT)
1897                         double rangeDataNtfAoaAzimuthLower) {
1898             mRangeDataNtfAoaAzimuthLower = rangeDataNtfAoaAzimuthLower;
1899             return this;
1900         }
1901 
setRangeDataNtfAoaAzimuthUpper( @loatRangefrom = RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT, to = RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT) double rangeDataNtfAoaAzimuthUpper)1902         public FiraOpenSessionParams.Builder setRangeDataNtfAoaAzimuthUpper(
1903                 @FloatRange(from = RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT,
1904                         to = RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT)
1905                         double rangeDataNtfAoaAzimuthUpper) {
1906             mRangeDataNtfAoaAzimuthUpper = rangeDataNtfAoaAzimuthUpper;
1907             return this;
1908         }
1909 
setRangeDataNtfAoaElevationLower( @loatRangefrom = RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT, to = RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT) double rangeDataNtfAoaElevationLower)1910         public FiraOpenSessionParams.Builder setRangeDataNtfAoaElevationLower(
1911                 @FloatRange(from = RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT,
1912                         to = RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT)
1913                         double rangeDataNtfAoaElevationLower) {
1914             mRangeDataNtfAoaElevationLower = rangeDataNtfAoaElevationLower;
1915             return this;
1916         }
1917 
setRangeDataNtfAoaElevationUpper( @loatRangefrom = RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT, to = RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT) double rangeDataNtfAoaElevationUpper)1918         public FiraOpenSessionParams.Builder setRangeDataNtfAoaElevationUpper(
1919                 @FloatRange(from = RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT,
1920                         to = RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT)
1921                         double rangeDataNtfAoaElevationUpper) {
1922             mRangeDataNtfAoaElevationUpper = rangeDataNtfAoaElevationUpper;
1923             return this;
1924         }
1925 
setHasTimeOfFlightReport( boolean hasTimeOfFlightReport)1926         public FiraOpenSessionParams.Builder setHasTimeOfFlightReport(
1927                 boolean hasTimeOfFlightReport) {
1928             mHasTimeOfFlightReport = hasTimeOfFlightReport;
1929             return this;
1930         }
1931 
setHasAngleOfArrivalAzimuthReport( boolean hasAngleOfArrivalAzimuthReport)1932         public FiraOpenSessionParams.Builder setHasAngleOfArrivalAzimuthReport(
1933                 boolean hasAngleOfArrivalAzimuthReport) {
1934             mHasAngleOfArrivalAzimuthReport = hasAngleOfArrivalAzimuthReport;
1935             return this;
1936         }
1937 
setHasAngleOfArrivalElevationReport( boolean hasAngleOfArrivalElevationReport)1938         public FiraOpenSessionParams.Builder setHasAngleOfArrivalElevationReport(
1939                 boolean hasAngleOfArrivalElevationReport) {
1940             mHasAngleOfArrivalElevationReport = hasAngleOfArrivalElevationReport;
1941             return this;
1942         }
1943 
setHasAngleOfArrivalFigureOfMeritReport( boolean hasAngleOfArrivalFigureOfMeritReport)1944         public FiraOpenSessionParams.Builder setHasAngleOfArrivalFigureOfMeritReport(
1945                 boolean hasAngleOfArrivalFigureOfMeritReport) {
1946             mHasAngleOfArrivalFigureOfMeritReport = hasAngleOfArrivalFigureOfMeritReport;
1947             return this;
1948         }
1949 
setAoaType(int aoaType)1950         public FiraOpenSessionParams.Builder setAoaType(int aoaType) {
1951             mAoaType = aoaType;
1952             return this;
1953         }
1954 
setRangingErrorStreakTimeoutMs( long rangingErrorStreakTimeoutMs)1955         public FiraOpenSessionParams.Builder setRangingErrorStreakTimeoutMs(
1956                 long rangingErrorStreakTimeoutMs) {
1957             mRangingErrorStreakTimeoutMs = rangingErrorStreakTimeoutMs;
1958             return this;
1959         }
1960 
setLinkLayerMode(int linkLayerMode)1961         public FiraOpenSessionParams.Builder setLinkLayerMode(int linkLayerMode) {
1962             mLinkLayerMode = linkLayerMode;
1963             return this;
1964         }
1965 
setDataRepetitionCount(int dataRepetitionCount)1966         public FiraOpenSessionParams.Builder setDataRepetitionCount(int dataRepetitionCount) {
1967             mDataRepetitionCount = dataRepetitionCount;
1968             return this;
1969         }
1970 
setRangingTimeStruct( @angingTimeStruct int rangingTimeStruct)1971         public FiraOpenSessionParams.Builder setRangingTimeStruct(
1972                 @RangingTimeStruct int rangingTimeStruct) {
1973             mRangingTimeStruct = rangingTimeStruct;
1974             return this;
1975         }
1976 
setMinFramePerRr(int minFramePerRr)1977         public FiraOpenSessionParams.Builder setMinFramePerRr(int minFramePerRr) {
1978             mMinFramesPerRr = minFramePerRr;
1979             return this;
1980         }
1981 
setMtuSize(int mtuSize)1982         public FiraOpenSessionParams.Builder setMtuSize(int mtuSize) {
1983             mMtuSize = mtuSize;
1984             return this;
1985         }
1986 
setInterFrameInterval(int interFrameInterval)1987         public FiraOpenSessionParams.Builder setInterFrameInterval(int interFrameInterval) {
1988             mInterFrameInterval = interFrameInterval;
1989             return this;
1990         }
1991 
setDlTdoaBlockStriding(int dlTdoaBlockStriding)1992         public FiraOpenSessionParams.Builder setDlTdoaBlockStriding(int dlTdoaBlockStriding) {
1993             mDlTdoaBlockStriding = dlTdoaBlockStriding;
1994             return this;
1995         }
1996 
setUlTdoaTxIntervalMs( int ulTdoaTxIntervalMs)1997         public FiraOpenSessionParams.Builder setUlTdoaTxIntervalMs(
1998                 int ulTdoaTxIntervalMs) {
1999             mUlTdoaTxIntervalMs = ulTdoaTxIntervalMs;
2000             return this;
2001         }
2002 
setUlTdoaRandomWindowMs( int ulTdoaRandomWindowMs)2003         public FiraOpenSessionParams.Builder setUlTdoaRandomWindowMs(
2004                 int ulTdoaRandomWindowMs) {
2005             mUlTdoaRandomWindowMs = ulTdoaRandomWindowMs;
2006             return this;
2007         }
2008 
setUlTdoaDeviceIdType( int ulTdoaDeviceIdType)2009         public FiraOpenSessionParams.Builder setUlTdoaDeviceIdType(
2010                 int ulTdoaDeviceIdType) {
2011             mUlTdoaDeviceIdType = ulTdoaDeviceIdType;
2012             return this;
2013         }
2014 
setUlTdoaDeviceId( byte[] ulTdoaDeviceId)2015         public FiraOpenSessionParams.Builder setUlTdoaDeviceId(
2016                 byte[] ulTdoaDeviceId) {
2017             mUlTdoaDeviceId = ulTdoaDeviceId;
2018             return this;
2019         }
2020 
setUlTdoaTxTimestampType( int ulTdoatxTimestampType)2021         public FiraOpenSessionParams.Builder setUlTdoaTxTimestampType(
2022                 int ulTdoatxTimestampType) {
2023             mUlTdoaTxTimestampType = ulTdoatxTimestampType;
2024             return this;
2025         }
2026 
2027        /**
2028         * After the session has been started, the device starts by
2029         * performing numOfMsrmtFocusOnRange range-only measurements (no
2030         * AoA), then it proceeds with numOfMsrmtFocusOnAoaAzimuth AoA
2031         * azimuth measurements followed by numOfMsrmtFocusOnAoaElevation
2032         * AoA elevation measurements.
2033         * If this is not invoked, the focus of each measurement is left
2034         * to the UWB vendor.
2035         *
2036         * Only valid when {@link #setAoaResultRequest(int)} is set to
2037         * {@link FiraParams#AOA_RESULT_REQUEST_MODE_REQ_AOA_RESULTS_INTERLEAVED}.
2038         */
setMeasurementFocusRatio( int numOfMsrmtFocusOnRange, int numOfMsrmtFocusOnAoaAzimuth, int numOfMsrmtFocusOnAoaElevation)2039         public FiraOpenSessionParams.Builder setMeasurementFocusRatio(
2040                 int numOfMsrmtFocusOnRange,
2041                 int numOfMsrmtFocusOnAoaAzimuth,
2042                 int numOfMsrmtFocusOnAoaElevation) {
2043             mNumOfMsrmtFocusOnRange = numOfMsrmtFocusOnRange;
2044             mNumOfMsrmtFocusOnAoaAzimuth = numOfMsrmtFocusOnAoaAzimuth;
2045             mNumOfMsrmtFocusOnAoaElevation = numOfMsrmtFocusOnAoaElevation;
2046             return this;
2047         }
2048 
setMaxNumberOfMeasurements( int maxNumberOfMeasurements)2049         public FiraOpenSessionParams.Builder setMaxNumberOfMeasurements(
2050                 int maxNumberOfMeasurements) {
2051             mMaxNumberOfMeasurements = maxNumberOfMeasurements;
2052             return this;
2053         }
2054 
setSessionDataTransferStatusNtfConfig( boolean sessionDataTransferStatusNtfConfig)2055         public FiraOpenSessionParams.Builder setSessionDataTransferStatusNtfConfig(
2056                 boolean sessionDataTransferStatusNtfConfig) {
2057             mSessionDataTransferStatusNtfConfig = sessionDataTransferStatusNtfConfig;
2058             return this;
2059         }
2060 
setSessionTimeBase(int referenceTimeBase, int referenceSessionHandle, int sessionOffsetInMicroSecond)2061         public FiraOpenSessionParams.Builder setSessionTimeBase(int referenceTimeBase,
2062                 int referenceSessionHandle, int sessionOffsetInMicroSecond) {
2063             mReferenceTimeBase = referenceTimeBase;
2064             mReferenceSessionHandle = referenceSessionHandle;
2065             mSessionOffsetInMicroSeconds = sessionOffsetInMicroSecond;
2066             return this;
2067         }
2068 
setApplicationDataEndpoint( int applicationDataEndpoint)2069         public FiraOpenSessionParams.Builder setApplicationDataEndpoint(
2070                 int applicationDataEndpoint) {
2071             mApplicationDataEndpoint = applicationDataEndpoint;
2072             return this;
2073         }
2074 
checkAddress()2075         private void checkAddress() {
2076             checkArgument(
2077                     mMacAddressMode == MAC_ADDRESS_MODE_2_BYTES
2078                             || mMacAddressMode == MAC_ADDRESS_MODE_8_BYTES);
2079             int addressByteLength = UwbAddress.SHORT_ADDRESS_BYTE_LENGTH;
2080             if (mMacAddressMode == MAC_ADDRESS_MODE_8_BYTES) {
2081                 addressByteLength = UwbAddress.EXTENDED_ADDRESS_BYTE_LENGTH;
2082             }
2083 
2084             // Make sure address length matches the address mode
2085             checkArgument(mDeviceAddress != null && mDeviceAddress.size() == addressByteLength);
2086             if (isTimeScheduledTwrSession()
2087                     && mStsConfig != STS_CONFIG_PROVISIONED_FOR_CONTROLEE_INDIVIDUAL_KEY) {
2088                 checkNotNull(mDestAddressList);
2089                 for (UwbAddress destAddress : mDestAddressList) {
2090                     checkArgument(destAddress != null
2091                             && destAddress.size() == addressByteLength);
2092                 }
2093             }
2094         }
2095 
checkStsConfig()2096         private void checkStsConfig() {
2097             if (mStsConfig == STS_CONFIG_STATIC) {
2098                 // These two fields are used by Static STS only.
2099                 checkArgument(mVendorId != null && mVendorId.length == 2);
2100                 checkArgument(mStaticStsIV != null && mStaticStsIV.length == 6);
2101             }
2102 
2103             if ((mStsConfig == STS_CONFIG_DYNAMIC_FOR_CONTROLEE_INDIVIDUAL_KEY ||
2104                  mStsConfig == STS_CONFIG_PROVISIONED_FOR_CONTROLEE_INDIVIDUAL_KEY) &&
2105                  (mDeviceType.get() == RANGING_DEVICE_TYPE_CONTROLEE)) {
2106                 // Sub Session ID is used for dynamic/Provisional individual key and
2107                 // for controlee device.
2108                 checkArgument(mSubSessionId.isSet());
2109             } else {
2110                 mSubSessionId.set(0);
2111             }
2112 
2113             if (mStsConfig == STS_CONFIG_PROVISIONED && mSessionKey != null) {
2114                 checkArgument(mSessionKey.length == 16 || mSessionKey.length == 32);
2115             }
2116 
2117             if (mStsConfig == STS_CONFIG_PROVISIONED_FOR_CONTROLEE_INDIVIDUAL_KEY
2118                 && mDeviceType.get() == RANGING_DEVICE_TYPE_CONTROLEE && mSubsessionKey != null) {
2119                 checkArgument(mSessionKey != null &&
2120                         (mSessionKey.length == 16 || mSessionKey.length == 32));
2121                 checkArgument(mSubsessionKey.length == 16 || mSubsessionKey.length == 32);
2122             }
2123         }
2124 
checkInterleavingRatio()2125         private void checkInterleavingRatio() {
2126             if (mAoaResultRequest != AOA_RESULT_REQUEST_MODE_REQ_AOA_RESULTS_INTERLEAVED) {
2127                 checkArgument(mNumOfMsrmtFocusOnRange == 0);
2128                 checkArgument(mNumOfMsrmtFocusOnAoaAzimuth == 0);
2129                 checkArgument(mNumOfMsrmtFocusOnAoaElevation == 0);
2130             } else {
2131                 // at-least one of the ratio params should be set for interleaving mode.
2132                 checkArgument(mNumOfMsrmtFocusOnRange > 0
2133                         || mNumOfMsrmtFocusOnAoaAzimuth > 0
2134                         || mNumOfMsrmtFocusOnAoaElevation > 0);
2135             }
2136         }
2137 
checkRangeDataNtfConfig()2138         private void checkRangeDataNtfConfig() {
2139             if (mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_DISABLE) {
2140                 checkArgument(mRangeDataNtfProximityNear
2141                         == RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT);
2142                 checkArgument(mRangeDataNtfProximityFar
2143                         == RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT);
2144                 checkArgument(mRangeDataNtfAoaAzimuthLower
2145                         == RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT);
2146                 checkArgument(mRangeDataNtfAoaAzimuthUpper
2147                         == RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT);
2148                 checkArgument(mRangeDataNtfAoaElevationLower
2149                         == RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT);
2150                 checkArgument(mRangeDataNtfAoaElevationUpper
2151                         == RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT);
2152             } else if (mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_LEVEL_TRIG
2153                     || mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_EDGE_TRIG) {
2154                 checkArgument(
2155                         mRangeDataNtfProximityNear != RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT
2156                         || mRangeDataNtfProximityFar != RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT);
2157                 checkArgument(mRangeDataNtfAoaAzimuthLower
2158                         == RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT);
2159                 checkArgument(mRangeDataNtfAoaAzimuthUpper
2160                         == RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT);
2161                 checkArgument(mRangeDataNtfAoaElevationLower
2162                         == RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT);
2163                 checkArgument(mRangeDataNtfAoaElevationUpper
2164                         == RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT);
2165             } else if (mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_ENABLE_AOA_LEVEL_TRIG
2166                     || mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_ENABLE_AOA_EDGE_TRIG) {
2167                 checkArgument(mRangeDataNtfProximityNear
2168                         == RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT);
2169                 checkArgument(mRangeDataNtfProximityFar
2170                         == RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT);
2171                 checkArgument(mRangeDataNtfAoaAzimuthLower
2172                             != RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT
2173                         || mRangeDataNtfAoaAzimuthUpper
2174                             != RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT
2175                         || mRangeDataNtfAoaElevationLower
2176                             != RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT
2177                         || mRangeDataNtfAoaElevationUpper
2178                             != RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT);
2179             } else if (mRangeDataNtfConfig == RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_LEVEL_TRIG
2180                     || mRangeDataNtfConfig
2181                     == RANGE_DATA_NTF_CONFIG_ENABLE_PROXIMITY_AOA_EDGE_TRIG) {
2182                 checkArgument(
2183                         mRangeDataNtfProximityNear != RANGE_DATA_NTF_PROXIMITY_NEAR_DEFAULT
2184                         || mRangeDataNtfProximityFar != RANGE_DATA_NTF_PROXIMITY_FAR_DEFAULT
2185                         || mRangeDataNtfAoaAzimuthLower
2186                             != RANGE_DATA_NTF_AOA_AZIMUTH_LOWER_DEFAULT
2187                         || mRangeDataNtfAoaAzimuthUpper
2188                             != RANGE_DATA_NTF_AOA_AZIMUTH_UPPER_DEFAULT
2189                         || mRangeDataNtfAoaElevationLower
2190                             != RANGE_DATA_NTF_AOA_ELEVATION_LOWER_DEFAULT
2191                         || mRangeDataNtfAoaElevationUpper
2192                             != RANGE_DATA_NTF_AOA_ELEVATION_UPPER_DEFAULT);
2193             }
2194         }
checkDlTdoaParameters()2195         private void checkDlTdoaParameters() {
2196             if (mDeviceRole.get() == RANGING_DEVICE_DT_TAG) {
2197                 checkArgument(mStsConfig == STS_CONFIG_STATIC
2198                             && mMultiNodeMode.get() == MULTI_NODE_MODE_ONE_TO_MANY
2199                             && mRframeConfig == RFRAME_CONFIG_SP1);
2200             }
2201         }
2202 
2203         /** Sets the type of filtering used by the session. Defaults to FILTER_TYPE_DEFAULT */
setFilterType(@ilterType int filterType)2204         public FiraOpenSessionParams.Builder setFilterType(@FilterType int filterType) {
2205             this.mFilterType = filterType;
2206             return this;
2207         }
2208 
2209         /**
2210          * Returns true when (RangingRoundUsage = 1, 2, 3, 4) and
2211          * SCHEDULED_MODE == 0x01 (TIME_SCHEDULED_RANGING)
2212          **/
isTimeScheduledTwrSession()2213         public boolean isTimeScheduledTwrSession() {
2214             if (mScheduledMode == FiraParams.TIME_SCHEDULED_RANGING) {
2215                 if (mRangingRoundUsage == RANGING_ROUND_USAGE_SS_TWR_DEFERRED_MODE
2216                         || mRangingRoundUsage == RANGING_ROUND_USAGE_DS_TWR_DEFERRED_MODE
2217                         || mRangingRoundUsage == RANGING_ROUND_USAGE_SS_TWR_NON_DEFERRED_MODE
2218                         || mRangingRoundUsage == RANGING_ROUND_USAGE_DS_TWR_NON_DEFERRED_MODE) {
2219                     return true;
2220                 }
2221             }
2222             return false;
2223         }
2224 
build()2225         public FiraOpenSessionParams build() {
2226             checkAddress();
2227             checkStsConfig();
2228             checkInterleavingRatio();
2229             checkRangeDataNtfConfig();
2230             checkDlTdoaParameters();
2231             return new FiraOpenSessionParams(
2232                     mProtocolVersion.get(),
2233                     mSessionId.get(),
2234                     mSessionType,
2235                     mDeviceType.get(),
2236                     mDeviceRole.get(),
2237                     mRangingRoundUsage,
2238                     mMultiNodeMode.get(),
2239                     mDeviceAddress,
2240                     mDestAddressList,
2241                     mInitiationTime,
2242                     mAbsoluteInitiationTime,
2243                     mSlotDurationRstu,
2244                     mSlotsPerRangingRound,
2245                     mRangingIntervalMs,
2246                     mBlockStrideLength,
2247                     mHoppingMode,
2248                     mMaxRangingRoundRetries,
2249                     mSessionPriority,
2250                     mMacAddressMode,
2251                     mHasRangingResultReportMessage,
2252                     mHasControlMessage,
2253                     mHasRangingControlPhase,
2254                     mMeasurementReportType,
2255                     mMeasurementReportPhase,
2256                     mInBandTerminationAttemptCount,
2257                     mChannelNumber,
2258                     mPreambleCodeIndex,
2259                     mRframeConfig,
2260                     mPrfMode,
2261                     mCapSize,
2262                     mScheduledMode,
2263                     mPreambleDuration,
2264                     mSfdId,
2265                     mStsSegmentCount,
2266                     mStsLength,
2267                     mSessionKey,
2268                     mSubsessionKey,
2269                     mPsduDataRate,
2270                     mBprfPhrDataRate,
2271                     mFcsType,
2272                     mIsTxAdaptivePayloadPowerEnabled,
2273                     mStsConfig,
2274                     mSubSessionId.get(),
2275                     mVendorId,
2276                     mStaticStsIV,
2277                     mIsRssiReportingEnabled,
2278                     mIsDiagnosticsEnabled,
2279                     mDiagramsFrameReportsFieldsFlags,
2280                     mAntennaMode,
2281                     mIsKeyRotationEnabled,
2282                     mKeyRotationRate,
2283                     mAoaResultRequest,
2284                     mRangeDataNtfConfig,
2285                     mRangeDataNtfProximityNear,
2286                     mRangeDataNtfProximityFar,
2287                     mRangeDataNtfAoaAzimuthLower,
2288                     mRangeDataNtfAoaAzimuthUpper,
2289                     mRangeDataNtfAoaElevationLower,
2290                     mRangeDataNtfAoaElevationUpper,
2291                     mHasTimeOfFlightReport,
2292                     mHasAngleOfArrivalAzimuthReport,
2293                     mHasAngleOfArrivalElevationReport,
2294                     mHasAngleOfArrivalFigureOfMeritReport,
2295                     mAoaType,
2296                     mNumOfMsrmtFocusOnRange,
2297                     mNumOfMsrmtFocusOnAoaAzimuth,
2298                     mNumOfMsrmtFocusOnAoaElevation,
2299                     mRangingErrorStreakTimeoutMs,
2300                     mLinkLayerMode,
2301                     mDataRepetitionCount,
2302                     mRangingTimeStruct,
2303                     mMinFramesPerRr,
2304                     mMtuSize,
2305                     mInterFrameInterval,
2306                     mDlTdoaBlockStriding,
2307                     mUlTdoaTxIntervalMs,
2308                     mUlTdoaRandomWindowMs,
2309                     mUlTdoaDeviceIdType,
2310                     mUlTdoaDeviceId,
2311                     mUlTdoaTxTimestampType,
2312                     mFilterType,
2313                     mMaxNumberOfMeasurements,
2314                     mSessionDataTransferStatusNtfConfig,
2315                     mReferenceTimeBase,
2316                     mReferenceSessionHandle,
2317                     mSessionOffsetInMicroSeconds,
2318                     mApplicationDataEndpoint);
2319         }
2320     }
2321 }
2322