1 /*
2  * Copyright (C) 2022 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.android.server.uwb.data;
18 
19 import static com.google.uwb.support.fira.FiraParams.CONSTRAINT_LENGTH_3;
20 import static com.google.uwb.support.fira.FiraParams.CONSTRAINT_LENGTH_7;
21 import static com.google.uwb.support.fira.FiraParams.HOPPING_MODE_DISABLE;
22 import static com.google.uwb.support.fira.FiraParams.MAC_FCS_TYPE_CRC_16;
23 import static com.google.uwb.support.fira.FiraParams.PRF_MODE_BPRF;
24 import static com.google.uwb.support.fira.FiraParams.PSDU_DATA_RATE_27M2;
25 import static com.google.uwb.support.fira.FiraParams.PSDU_DATA_RATE_31M2;
26 import static com.google.uwb.support.fira.FiraParams.PSDU_DATA_RATE_6M81;
27 import static com.google.uwb.support.fira.FiraParams.PSDU_DATA_RATE_7M80;
28 import static com.google.uwb.support.fira.FiraParams.RANGING_ROUND_USAGE_DS_TWR_DEFERRED_MODE;
29 import static com.google.uwb.support.fira.FiraParams.RFRAME_CONFIG_SP3;
30 import static com.google.uwb.support.fira.FiraParams.STS_CONFIG_DYNAMIC;
31 import static com.google.uwb.support.fira.FiraParams.TIME_SCHEDULED_RANGING;
32 import static com.google.uwb.support.fira.FiraParams.UWB_CHANNEL_9;
33 import static com.google.uwb.support.fira.FiraParams.UWB_PREAMBLE_CODE_INDEX_10;
34 
35 import android.annotation.IntDef;
36 import android.annotation.Nullable;
37 
38 import androidx.annotation.NonNull;
39 
40 import com.android.server.uwb.pm.RangingSessionController;
41 import com.android.server.uwb.secure.csml.ConfigurationParams;
42 import com.android.server.uwb.secure.csml.SessionData;
43 
44 import com.google.uwb.support.base.RequiredParam;
45 import com.google.uwb.support.fira.FiraOpenSessionParams;
46 import com.google.uwb.support.fira.FiraParams;
47 import com.google.uwb.support.fira.FiraParams.MacFcsType;
48 import com.google.uwb.support.fira.FiraParams.MultiNodeMode;
49 import com.google.uwb.support.fira.FiraParams.PrfMode;
50 import com.google.uwb.support.fira.FiraParams.RangingRoundUsage;
51 import com.google.uwb.support.fira.FiraParams.RframeConfig;
52 import com.google.uwb.support.fira.FiraParams.StsConfig;
53 import com.google.uwb.support.fira.FiraParams.UwbChannel;
54 import com.google.uwb.support.fira.FiraParams.UwbPreambleCodeIndex;
55 import com.google.uwb.support.fira.FiraProtocolVersion;
56 
57 public class UwbConfig {
58 
59     /** UWB OOB types */
60     @IntDef(
61             value = {
62                     OOB_TYPE_NONE,
63                     OOB_TYPE_BLE,
64             })
65     public @interface OobType {
66     }
67 
68     public static final int OOB_TYPE_NONE = 0;
69     public static final int OOB_TYPE_BLE = 1;
70 
71     /** UWB OOB roles */
72     @IntDef(
73             value = {
74                     CENTRAL_GATT_CLIENT,
75                     PERIPHERAL_GATT_SERVER,
76                     PERIPHERAL,
77                     CENTRAL,
78             })
79     public @interface OobBleRole {
80     }
81 
82     public static final int CENTRAL_GATT_CLIENT = 0;
83     public static final int PERIPHERAL_GATT_SERVER = 1;
84     public static final int PERIPHERAL = 2;
85     public static final int CENTRAL = 3;
86 
87     /** UWB device role */
88     @IntDef(
89             value = {
90                     CONTROLEE_AND_RESPONDER,
91                     CONTROLEE_AND_INITIATOR,
92                     CONTROLLER_AND_RESPONDER,
93                     CONTROLLER_AND_INITIATOR,
94             })
95     public @interface UwbRole {
96     }
97 
98     public static final int CONTROLEE_AND_RESPONDER = 0;
99     public static final int CONTROLEE_AND_INITIATOR = 1;
100     public static final int CONTROLLER_AND_RESPONDER = 2;
101     public static final int CONTROLLER_AND_INITIATOR = 3;
102 
103     public static final int DEVICE_TYPE_BITMASK = 0b00000001; // 1
104     public static final int DEVICE_ROLE_BITMASK = 0b00000010; // 2
105 
106     @UwbRole
107     public final int mUwbRole;
108     @RangingRoundUsage
109     public final int mRangingRoundUsage;
110     @MultiNodeMode
111     public final int mMultiNodeMode;
112     @RframeConfig
113     public final int mRframeConfig;
114     @StsConfig
115     public final int mStsConfig;
116     public final int mRoundHopping;
117     @FiraParams.SchedulingMode
118     public final int mScheduleMode;
119     public final int mMaxContentionPhaseLength;
120     public final boolean mTofReport;
121     public final boolean mAoaAzimuthReport;
122     public final boolean mAoaElevationReport;
123     public final boolean mAoaFomReport;
124     public final boolean mBlockStriding;
125     public final int mSlotDurationRstu;
126     public final int mSlotsPerRangingRound;
127     public final int mRangingIntervalMs;
128     @UwbChannel
129     public final int mUwbChannel;
130     @UwbPreambleCodeIndex
131     public final int mUwbPreambleCodeIndex;
132     public final int mSp0PhyParameterSet;
133     public final int mSp1PhyParameterSet;
134     public final int mSp3PhyParameterSet;
135     public final int mMaxRetry;
136     @PrfMode
137     public final int mPrfMode;
138     public final int mConstraintLengthConvolutionalCode;
139     public final int mUwbInitiationTimeMs;
140     public final int mKeyRotationRate;
141     @MacFcsType
142     public final int mMacFcsType;
143     public final int mRangingRoundControl;
144     @Nullable
145     public final byte[] mVendorID;
146     @Nullable
147     public final byte[] mStaticStsIV;
148     @OobType
149     public final int mOobType;
150     @OobBleRole
151     public final int mOobBleRole;
152 
UwbConfig( @wbRole int uwbRole, @RangingRoundUsage int rangingRoundUsage, @MultiNodeMode int multiNodeMode, @RframeConfig int rframeConfig, @StsConfig int stsConfig, int roundHopping, @FiraParams.SchedulingMode int scheduleMode, int maxContentionPhaseLength, boolean tofReport, boolean aoaAzimuthReport, boolean aoaElevationReport, boolean aoaFomReport, boolean blockStriding, int slotDurationRstu, int slotsPerRangingRound, int rangingIntervalMs, @UwbChannel int uwbChannel, @UwbPreambleCodeIndex int uwbPreambleCodeIndex, int sp0PhyParameterSet, int sp1PhyParameterSet, int sp3PhyParameterSet, int maxRetry, @PrfMode int prfMode, int constraintLengthConvolutionalCode, int uwbInitiationTimeMs, int keyRotationRate, @MacFcsType int macFcsType, int rangingRoundControl, @Nullable byte[] vendorID, @Nullable byte[] staticStsIV, @OobType int oobType, @OobBleRole int oobBleRole)153     private UwbConfig(
154             @UwbRole int uwbRole,
155             @RangingRoundUsage int rangingRoundUsage,
156             @MultiNodeMode int multiNodeMode,
157             @RframeConfig int rframeConfig,
158             @StsConfig int stsConfig,
159             int roundHopping,
160             @FiraParams.SchedulingMode int scheduleMode,
161             int maxContentionPhaseLength,
162             boolean tofReport,
163             boolean aoaAzimuthReport,
164             boolean aoaElevationReport,
165             boolean aoaFomReport,
166             boolean blockStriding,
167             int slotDurationRstu,
168             int slotsPerRangingRound,
169             int rangingIntervalMs,
170             @UwbChannel int uwbChannel,
171             @UwbPreambleCodeIndex int uwbPreambleCodeIndex,
172             int sp0PhyParameterSet,
173             int sp1PhyParameterSet,
174             int sp3PhyParameterSet,
175             int maxRetry,
176             @PrfMode int prfMode,
177             int constraintLengthConvolutionalCode,
178             int uwbInitiationTimeMs,
179             int keyRotationRate,
180             @MacFcsType int macFcsType,
181             int rangingRoundControl,
182             @Nullable byte[] vendorID,
183             @Nullable byte[] staticStsIV,
184             @OobType int oobType,
185             @OobBleRole int oobBleRole) {
186         mUwbRole = uwbRole;
187         mRangingRoundUsage = rangingRoundUsage;
188         mMultiNodeMode = multiNodeMode;
189         mRframeConfig = rframeConfig;
190         mStsConfig = stsConfig;
191         mRoundHopping = roundHopping;
192         mScheduleMode = scheduleMode;
193         mMaxContentionPhaseLength = maxContentionPhaseLength;
194         mTofReport = tofReport;
195         mAoaAzimuthReport = aoaAzimuthReport;
196         mAoaElevationReport = aoaElevationReport;
197         mAoaFomReport = aoaFomReport;
198         mBlockStriding = blockStriding;
199         mSlotDurationRstu = slotDurationRstu;
200         mSlotsPerRangingRound = slotsPerRangingRound;
201         mRangingIntervalMs = rangingIntervalMs;
202         mUwbChannel = uwbChannel;
203         mUwbPreambleCodeIndex = uwbPreambleCodeIndex;
204         mSp0PhyParameterSet = sp0PhyParameterSet;
205         mSp1PhyParameterSet = sp1PhyParameterSet;
206         mSp3PhyParameterSet = sp3PhyParameterSet;
207         mMaxRetry = maxRetry;
208         mPrfMode = prfMode;
209         mConstraintLengthConvolutionalCode = constraintLengthConvolutionalCode;
210         mUwbInitiationTimeMs = uwbInitiationTimeMs;
211         mKeyRotationRate = keyRotationRate;
212         mMacFcsType = macFcsType;
213         mRangingRoundControl = rangingRoundControl;
214         this.mVendorID = vendorID;
215         this.mStaticStsIV = staticStsIV;
216         mOobType = oobType;
217         mOobBleRole = oobBleRole;
218     }
219 
220     public static final class Builder {
221         private final RequiredParam<Integer> mUwbRole = new RequiredParam<>();
222         private final RequiredParam<Integer> mMultiNodeMode = new RequiredParam<>();
223         private final RequiredParam<Integer> mOobType = new RequiredParam<>();
224         private final RequiredParam<Integer> mOobBleRole = new RequiredParam<>();
225 
226         @StsConfig
227         private int mStsConfig = STS_CONFIG_DYNAMIC;
228 
229         /** UCI spec default: DS-TWR with deferred mode */
230         @RangingRoundUsage
231         private int mRangingRoundUsage = RANGING_ROUND_USAGE_DS_TWR_DEFERRED_MODE;
232 
233         /** UCI spec default: SP3 */
234         @RframeConfig
235         private int mRframeConfig = RFRAME_CONFIG_SP3;
236 
237         /** Round hopping disabled */
238         private int mRoundHopping = HOPPING_MODE_DISABLE;
239 
240         /** UCI spec default: Time Based */
241         @FiraParams.SchedulingMode
242         private int mScheduleMode = TIME_SCHEDULED_RANGING;
243 
244         /** Time based used by default */
245         private int mMaxContentionPhaseLength = 0;
246 
247         /** UCI spec default: time of flight report enabled */
248         private boolean mTofReport = true;
249 
250         /** UCI spec default: No AoA azimuth report */
251         private boolean mAoaAzimuthReport = false;
252 
253         /** UCI spec default: No AoA Elevation report */
254         private boolean mAoaElevationReport = false;
255 
256         /** UCI spec default: No AoA FOM report */
257         private boolean mAoaFomReport = false;
258 
259         /** UCI spec default: No Block Striding */
260         private boolean mBlockStriding = false;
261 
262         /** UCI spec default: 2400 RSTU (2 ms). */
263         private int mSlotDurationRstu = 2400;
264 
265         /** UCI spec default: 30 slots per ranging round. */
266         private int mSlotsPerRangingRound = 30;
267 
268         /** UCI spec default: RANGING_INTERVAL(Fira 2.0: RANGING_DURATION) 200 ms */
269         private int mRangingIntervalMs = 200;
270 
271         /** UCI spec default: Channel 9, which is the only mandatory channel. */
272         @UwbChannel
273         private int mUwbChannel = UWB_CHANNEL_9;
274 
275         /** UCI spec default: index 10 */
276         @UwbPreambleCodeIndex
277         private int mUwbPreambleCodeIndex = UWB_PREAMBLE_CODE_INDEX_10;
278 
279         /** SP0 PHY parameter set */
280         private int mSp0PhyParameterSet = 1;
281 
282         /** SP1 PHY parameter set */
283         private int mSp1PhyParameterSet = 3;
284 
285         /** SP3 PHY parameter set */
286         private int mSp3PhyParameterSet = 4;
287 
288         /** UCI spec default: Unlimited */
289         private int mMaxRetry = 0;
290 
291         /** UCI spec default: BPRF */
292         @PrfMode
293         private int mPrfMode = PRF_MODE_BPRF;
294         @FiraParams.CcConstraintLength
295         private int mConstraintLengthConvolutionalCode = CONSTRAINT_LENGTH_3;
296 
297         /** UCI spec default: 0ms */
298         private int mUwbInitiationTimeMs = 0;
299 
300         /** UCI spec default: No key rotation */
301         private int mKeyRotationRate = 0;
302 
303         /** UCI spec default: CRC-16 */
304         @MacFcsType
305         private int mMacFcsType = MAC_FCS_TYPE_CRC_16;
306 
307         private int mRangingRoundControl = 0;
308 
309         @Nullable
310         private byte[] mVendorID = null;
311         @Nullable
312         private byte[] mStaticStsIV = null;
313 
314         /** Sets UWB role */
setUwbRole(@wbRole int uwbRole)315         public UwbConfig.Builder setUwbRole(@UwbRole int uwbRole) {
316             mUwbRole.set(uwbRole);
317             return this;
318         }
319 
320         /** Sets the multiple node mode, unicast or multicast. */
setMultiNodeMode(@ultiNodeMode int multiNodeMode)321         public UwbConfig.Builder setMultiNodeMode(@MultiNodeMode int multiNodeMode) {
322             mMultiNodeMode.set(multiNodeMode);
323             return this;
324         }
325 
326         /** Sets the STS config mode */
setStsConfig(@tsConfig int stsConfig)327         public UwbConfig.Builder setStsConfig(@StsConfig int stsConfig) {
328             mStsConfig = stsConfig;
329             return this;
330         }
331 
setRangingRoundUsage(@angingRoundUsage int rangingRoundUsage)332         UwbConfig.Builder setRangingRoundUsage(@RangingRoundUsage int rangingRoundUsage) {
333             mRangingRoundUsage = rangingRoundUsage;
334             return this;
335         }
336 
337         /** Sets the RFrame config, sp3, sp1 or sp0 */
setRframeConfig(@frameConfig int rframeConfig)338         public UwbConfig.Builder setRframeConfig(@RframeConfig int rframeConfig) {
339             mRframeConfig = rframeConfig;
340             return this;
341         }
342 
setRoundHopping(int roundHopping)343         UwbConfig.Builder setRoundHopping(int roundHopping) {
344             mRoundHopping = roundHopping;
345             return this;
346         }
347 
setScheduleMode(@iraParams.SchedulingMode int scheduleMode)348         UwbConfig.Builder setScheduleMode(@FiraParams.SchedulingMode int scheduleMode) {
349             mScheduleMode = scheduleMode;
350             return this;
351         }
352 
setMaxContentionPhaseLength(int maxContentionPhaseLength)353         UwbConfig.Builder setMaxContentionPhaseLength(int maxContentionPhaseLength) {
354             mMaxContentionPhaseLength = maxContentionPhaseLength;
355             return this;
356         }
357 
358         /** Sets TOF report */
setTofReport(boolean tofReport)359         public UwbConfig.Builder setTofReport(boolean tofReport) {
360             mTofReport = tofReport;
361             return this;
362         }
363 
setAoaAzimuthReport(boolean aoaAzimuthReport)364         UwbConfig.Builder setAoaAzimuthReport(boolean aoaAzimuthReport) {
365             mAoaAzimuthReport = aoaAzimuthReport;
366             return this;
367         }
368 
setAoaElevationReport(boolean aoaElevationReport)369         UwbConfig.Builder setAoaElevationReport(boolean aoaElevationReport) {
370             mAoaElevationReport = aoaElevationReport;
371             return this;
372         }
373 
setAoaFomReport(boolean aoaFomReport)374         UwbConfig.Builder setAoaFomReport(boolean aoaFomReport) {
375             mAoaFomReport = aoaFomReport;
376             return this;
377         }
378 
setBlockStriding(boolean blockStriding)379         UwbConfig.Builder setBlockStriding(boolean blockStriding) {
380             mBlockStriding = blockStriding;
381             return this;
382         }
383 
setSlotDurationRstu(int slotDurationRstu)384         UwbConfig.Builder setSlotDurationRstu(int slotDurationRstu) {
385             mSlotDurationRstu = slotDurationRstu;
386             return this;
387         }
388 
setSlotsPerRangingRound(int slotsPerRangingRound)389         UwbConfig.Builder setSlotsPerRangingRound(int slotsPerRangingRound) {
390             mSlotsPerRangingRound = slotsPerRangingRound;
391             return this;
392         }
393 
setRangingIntervalMs(int rangingIntervalMs)394         UwbConfig.Builder setRangingIntervalMs(int rangingIntervalMs) {
395             mRangingIntervalMs = rangingIntervalMs;
396             return this;
397         }
398 
setUwbChannel(@wbChannel int uwbChannel)399         UwbConfig.Builder setUwbChannel(@UwbChannel int uwbChannel) {
400             mUwbChannel = uwbChannel;
401             return this;
402         }
403 
setUwbPreambleCodeIndex(@wbPreambleCodeIndex int uwbPreambleCodeIndex)404         UwbConfig.Builder setUwbPreambleCodeIndex(@UwbPreambleCodeIndex
405                 int uwbPreambleCodeIndex) {
406             mUwbPreambleCodeIndex = uwbPreambleCodeIndex;
407             return this;
408         }
409 
setSp0PhyParameterSet(int sp0PhyParameterSet)410         UwbConfig.Builder setSp0PhyParameterSet(int sp0PhyParameterSet) {
411             mSp0PhyParameterSet = sp0PhyParameterSet;
412             return this;
413         }
414 
setSp1PhyParameterSet(int sp1PhyParameterSet)415         UwbConfig.Builder setSp1PhyParameterSet(int sp1PhyParameterSet) {
416             mSp1PhyParameterSet = sp1PhyParameterSet;
417             return this;
418         }
419 
setSp3PhyParameterSet(int sp3PhyParameterSet)420         UwbConfig.Builder setSp3PhyParameterSet(int sp3PhyParameterSet) {
421             mSp3PhyParameterSet = sp3PhyParameterSet;
422             return this;
423         }
424 
setMaxRetry(int maxRetry)425         UwbConfig.Builder setMaxRetry(int maxRetry) {
426             mMaxRetry = maxRetry;
427             return this;
428         }
429 
setPrfMode(@rfMode int prfMode)430         UwbConfig.Builder setPrfMode(@PrfMode int prfMode) {
431             mPrfMode = prfMode;
432             return this;
433         }
434 
setConstraintLengthConvolutionalCode( int constraintLengthConvolutionalCode)435         UwbConfig.Builder setConstraintLengthConvolutionalCode(
436                 int constraintLengthConvolutionalCode) {
437             mConstraintLengthConvolutionalCode = constraintLengthConvolutionalCode;
438             return this;
439         }
440 
setUwbInitiationTimeMs(int uwbInitiationTimeMs)441         UwbConfig.Builder setUwbInitiationTimeMs(int uwbInitiationTimeMs) {
442             mUwbInitiationTimeMs = uwbInitiationTimeMs;
443             return this;
444         }
445 
setKeyRotationRate(int keyRotationRate)446         UwbConfig.Builder setKeyRotationRate(int keyRotationRate) {
447             mKeyRotationRate = keyRotationRate;
448             return this;
449         }
450 
setKMacFcsType(@acFcsType int macFcsType)451         UwbConfig.Builder setKMacFcsType(@MacFcsType int macFcsType) {
452             mMacFcsType = macFcsType;
453             return this;
454         }
455 
setRangingRoundControl(int rangingRoundControl)456         UwbConfig.Builder setRangingRoundControl(int rangingRoundControl) {
457             mRangingRoundControl = rangingRoundControl;
458             return this;
459         }
460 
setVendorID(byte[] vendorID)461         UwbConfig.Builder setVendorID(byte[] vendorID) {
462             mVendorID = vendorID;
463             return this;
464         }
465 
setStaticStsIV(byte[] staticStsIV)466         UwbConfig.Builder setStaticStsIV(byte[] staticStsIV) {
467             mStaticStsIV = staticStsIV;
468             return this;
469         }
470 
471         /** Sets the OOB type */
setOobType(@obType int uwbRole)472         public UwbConfig.Builder setOobType(@OobType int uwbRole) {
473             mOobType.set(uwbRole);
474             return this;
475         }
476 
477         /** Sets BLE role */
setOobBleRole(@obBleRole int uwbRole)478         public UwbConfig.Builder setOobBleRole(@OobBleRole int uwbRole) {
479             mOobBleRole.set(uwbRole);
480             return this;
481         }
482 
483         /** build the instance of {@link UwbConfig}. */
build()484         public UwbConfig build() {
485             return new UwbConfig(
486                     mUwbRole.get(),
487                     mRangingRoundUsage,
488                     mMultiNodeMode.get(),
489                     mRframeConfig,
490                     mStsConfig,
491                     mRoundHopping,
492                     mScheduleMode,
493                     mMaxContentionPhaseLength,
494                     mTofReport,
495                     mAoaAzimuthReport,
496                     mAoaElevationReport,
497                     mAoaFomReport,
498                     mBlockStriding,
499                     mSlotDurationRstu,
500                     mSlotsPerRangingRound,
501                     mRangingIntervalMs,
502                     mUwbChannel,
503                     mUwbPreambleCodeIndex,
504                     mSp0PhyParameterSet,
505                     mSp1PhyParameterSet,
506                     mSp3PhyParameterSet,
507                     mMaxRetry,
508                     mPrfMode,
509                     mConstraintLengthConvolutionalCode,
510                     mUwbInitiationTimeMs,
511                     mKeyRotationRate,
512                     mMacFcsType,
513                     mRangingRoundControl,
514                     mVendorID,
515                     mStaticStsIV,
516                     mOobType.get(),
517                     mOobBleRole.get());
518         }
519     }
520 
521     @FiraParams.PsduDataRate
getPsduDataRate()522     int getPsduDataRate() {
523         if (mPrfMode == PRF_MODE_BPRF) {
524             if (mConstraintLengthConvolutionalCode == CONSTRAINT_LENGTH_3) {
525                 return PSDU_DATA_RATE_27M2;
526             } else {
527                 return PSDU_DATA_RATE_6M81;
528             }
529         } else { // PRF_MODE_HPRF
530             if (mConstraintLengthConvolutionalCode == CONSTRAINT_LENGTH_7) {
531                 return PSDU_DATA_RATE_31M2;
532             } else {
533                 return PSDU_DATA_RATE_7M80;
534             }
535         }
536     }
537 
538     /**
539      * Convert UwbConfig to FiraOpenSessionParams
540      */
getOpenSessionParams( RangingSessionController.SessionInfo sessionInfo, UwbConfig uwbConfig)541     public static FiraOpenSessionParams getOpenSessionParams(
542             RangingSessionController.SessionInfo sessionInfo, UwbConfig uwbConfig) {
543 
544         FiraProtocolVersion protocolVersion = FiraParams.PROTOCOL_VERSION_1_1;
545         FiraOpenSessionParams.Builder firaOpenSessionBuilder = new FiraOpenSessionParams.Builder()
546                 .setSessionId(sessionInfo.getSessionId())
547                 .setDeviceAddress(sessionInfo.getDeviceAddress())
548                 .setDestAddressList(sessionInfo.mDestAddressList)
549                 .setProtocolVersion(protocolVersion)
550                 .setDeviceType(uwbConfig.mUwbRole & DEVICE_TYPE_BITMASK)
551                 .setDeviceRole(uwbConfig.mUwbRole & DEVICE_ROLE_BITMASK)
552                 .setRangingRoundUsage(uwbConfig.mRangingRoundUsage)
553                 .setMultiNodeMode(uwbConfig.mMultiNodeMode)
554                 .setRframeConfig(uwbConfig.mRframeConfig)
555                 .setStsConfig(uwbConfig.mStsConfig)
556                 .setHoppingMode(uwbConfig.mRoundHopping)
557                 .setHasTimeOfFlightReport(uwbConfig.mTofReport)
558                 .setHasAngleOfArrivalAzimuthReport(uwbConfig.mAoaAzimuthReport)
559                 .setHasAngleOfArrivalElevationReport(uwbConfig.mAoaElevationReport)
560                 .setRangingIntervalMs(uwbConfig.mRangingIntervalMs)
561                 .setPsduDataRate(uwbConfig.getPsduDataRate())
562                 .setPrfMode(uwbConfig.mPrfMode)
563                 .setScheduledMode(uwbConfig.mScheduleMode);
564 
565         sessionInfo.subSessionId.ifPresent(firaOpenSessionBuilder::setSubSessionId);
566         sessionInfo.mSubSessionKey.ifPresent(firaOpenSessionBuilder::setSubsessionKey);
567         sessionInfo.mSessionKey.ifPresent(firaOpenSessionBuilder::setSessionKey);
568 
569         return firaOpenSessionBuilder.build();
570     }
571 
572     /** Converts the fields of {@link SessionData} to those fields of UwbConfig. */
fromSessionData( @onNull UwbConfig.Builder uwbConfigBuilder, @NonNull SessionData sessionData)573     public static UwbConfig fromSessionData(
574             @NonNull UwbConfig.Builder uwbConfigBuilder, @NonNull SessionData sessionData) {
575         if (sessionData.mConfigurationParams.isPresent()) {
576             ConfigurationParams configurationParams =
577                     sessionData.mConfigurationParams.get();
578             configurationParams.mScheduleMode.ifPresent(uwbConfigBuilder::setScheduleMode);
579             configurationParams.mBlockStriding.ifPresent(uwbConfigBuilder::setBlockStriding);
580             configurationParams.mStsConfig.ifPresent(uwbConfigBuilder::setStsConfig);
581             configurationParams.mChannel.ifPresent(uwbConfigBuilder::setUwbChannel);
582             configurationParams.mSp0PhyParameterSet.ifPresent(
583                     uwbConfigBuilder::setSp0PhyParameterSet);
584             configurationParams.mSp1PhyParameterSet.ifPresent(
585                     uwbConfigBuilder::setSp1PhyParameterSet);
586             configurationParams.mSp3PhyParameterSet.ifPresent(
587                     uwbConfigBuilder::setSp3PhyParameterSet);
588             configurationParams.mPreambleCodeIndex.ifPresent(
589                     uwbConfigBuilder::setUwbPreambleCodeIndex);
590             configurationParams.mSlotsPerRangingRound.ifPresent(
591                     uwbConfigBuilder::setSlotsPerRangingRound);
592             configurationParams.mMaxContentionPhaseLength.ifPresent(
593                     uwbConfigBuilder::setMaxContentionPhaseLength);
594             configurationParams.mSlotDuration.ifPresent(
595                     uwbConfigBuilder::setSlotDurationRstu);
596             configurationParams.mRangingIntervalMs.ifPresent(
597                     uwbConfigBuilder::setRangingIntervalMs);
598             configurationParams.mKeyRotationRate.ifPresent(
599                     uwbConfigBuilder::setKeyRotationRate);
600             configurationParams.mMacFcsType.ifPresent(uwbConfigBuilder::setKMacFcsType);
601             configurationParams.mRangingMethod.ifPresent(
602                     uwbConfigBuilder::setRangingRoundUsage);
603             configurationParams.mPrfMode.ifPresent(uwbConfigBuilder::setPrfMode);
604             configurationParams.mCcConstraintLength.ifPresent(
605                     uwbConfigBuilder::setConstraintLengthConvolutionalCode);
606             configurationParams.mRframeConfig.ifPresent(uwbConfigBuilder::setRframeConfig);
607         }
608 
609         return uwbConfigBuilder.build();
610     }
611 }
612