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 package com.android.server.uwb.jni; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.util.Log; 21 22 import com.android.internal.annotations.Keep; 23 import com.android.server.uwb.UciLogModeStore; 24 import com.android.server.uwb.UwbInjector; 25 import com.android.server.uwb.data.DtTagUpdateRangingRoundsStatus; 26 import com.android.server.uwb.data.UwbConfigStatusData; 27 import com.android.server.uwb.data.UwbDeviceInfoResponse; 28 import com.android.server.uwb.data.UwbMulticastListUpdateStatus; 29 import com.android.server.uwb.data.UwbRadarData; 30 import com.android.server.uwb.data.UwbRangingData; 31 import com.android.server.uwb.data.UwbTlvData; 32 import com.android.server.uwb.data.UwbUciConstants; 33 import com.android.server.uwb.data.UwbVendorUciResponse; 34 import com.android.server.uwb.info.UwbPowerStats; 35 import com.android.server.uwb.multchip.UwbMultichipData; 36 import com.android.server.uwb.rftest.UwbTestPerRxResult; 37 import com.android.server.uwb.rftest.UwbTestPeriodicTxResult; 38 39 import java.util.Arrays; 40 import java.util.HashMap; 41 import java.util.Map; 42 43 @Keep 44 public class NativeUwbManager { 45 private static final String TAG = NativeUwbManager.class.getSimpleName(); 46 47 public final Object mNativeLock = new Object(); 48 private final UwbInjector mUwbInjector; 49 private final UciLogModeStore mUciLogModeStore; 50 private final UwbMultichipData mUwbMultichipData; 51 protected INativeUwbManager.DeviceNotification mDeviceListener; 52 protected INativeUwbManager.SessionNotification mSessionListener; 53 private long mDispatcherPointer; 54 protected INativeUwbManager.VendorNotification mVendorListener; 55 NativeUwbManager(@onNull UwbInjector uwbInjector, UciLogModeStore uciLogModeStore, UwbMultichipData uwbMultichipData)56 public NativeUwbManager(@NonNull UwbInjector uwbInjector, UciLogModeStore uciLogModeStore, 57 UwbMultichipData uwbMultichipData) { 58 mUwbInjector = uwbInjector; 59 mUciLogModeStore = uciLogModeStore; 60 mUwbMultichipData = uwbMultichipData; 61 loadLibrary(); 62 } 63 loadLibrary()64 protected void loadLibrary() { 65 System.loadLibrary("uwb_uci_jni_rust"); 66 synchronized (mNativeLock) { 67 nativeInit(); 68 } 69 } 70 setDeviceListener(INativeUwbManager.DeviceNotification deviceListener)71 public void setDeviceListener(INativeUwbManager.DeviceNotification deviceListener) { 72 mDeviceListener = deviceListener; 73 } 74 setSessionListener(INativeUwbManager.SessionNotification sessionListener)75 public void setSessionListener(INativeUwbManager.SessionNotification sessionListener) { 76 mSessionListener = sessionListener; 77 } 78 setVendorListener(INativeUwbManager.VendorNotification vendorListener)79 public void setVendorListener(INativeUwbManager.VendorNotification vendorListener) { 80 mVendorListener = vendorListener; 81 } 82 83 /** 84 * Device status callback invoked via the JNI 85 */ onDeviceStatusNotificationReceived(int deviceState, String chipId)86 public void onDeviceStatusNotificationReceived(int deviceState, String chipId) { 87 Log.d(TAG, "onDeviceStatusNotificationReceived(" + deviceState + ", " + chipId + ")"); 88 mDeviceListener.onDeviceStatusNotificationReceived(deviceState, chipId); 89 } 90 91 /** 92 * Error callback invoked via the JNI 93 */ onCoreGenericErrorNotificationReceived(int status, String chipId)94 public void onCoreGenericErrorNotificationReceived(int status, String chipId) { 95 Log.d(TAG, "onCoreGenericErrorNotificationReceived(" + status + ", " + chipId + ")"); 96 mDeviceListener.onCoreGenericErrorNotificationReceived(status, chipId); 97 } 98 onSessionStatusNotificationReceived(long id, int token, int state, int reasonCode)99 public void onSessionStatusNotificationReceived(long id, int token, int state, int reasonCode) { 100 Log.d(TAG, "onSessionStatusNotificationReceived(" + id + ", " + token + ", " 101 + state + ", " + reasonCode + ")"); 102 mSessionListener.onSessionStatusNotificationReceived(id, token, state, reasonCode); 103 } 104 onRangeDataNotificationReceived(UwbRangingData rangeData)105 public void onRangeDataNotificationReceived(UwbRangingData rangeData) { 106 Log.d(TAG, "onRangeDataNotificationReceived : " + rangeData); 107 mSessionListener.onRangeDataNotificationReceived(rangeData); 108 } 109 onMulticastListUpdateNotificationReceived( UwbMulticastListUpdateStatus multicastListUpdateData)110 public void onMulticastListUpdateNotificationReceived( 111 UwbMulticastListUpdateStatus multicastListUpdateData) { 112 Log.d(TAG, "onMulticastListUpdateNotificationReceived : " + multicastListUpdateData); 113 mSessionListener.onMulticastListUpdateNotificationReceived(multicastListUpdateData); 114 } 115 116 /** 117 * Radar data message callback invoked via the JNI 118 */ onRadarDataMessageReceived(UwbRadarData radarData)119 public void onRadarDataMessageReceived(UwbRadarData radarData) { 120 Log.d(TAG, "onRadarDataMessageReceived : " + radarData); 121 mSessionListener.onRadarDataMessageReceived(radarData); 122 } 123 124 /** 125 * Vendor callback invoked via the JNI 126 */ onVendorUciNotificationReceived(int gid, int oid, byte[] payload)127 public void onVendorUciNotificationReceived(int gid, int oid, byte[] payload) { 128 Log.d(TAG, "onVendorUciNotificationReceived: " + gid + ", " + oid + ", " 129 + Arrays.toString(payload)); 130 mVendorListener.onVendorUciNotificationReceived(gid, oid, payload); 131 } 132 133 /** 134 * RfTestPeriodicTx callback invoked via the JNI 135 */ onPeriodicTxDataNotificationReceived(UwbTestPeriodicTxResult periodicTx)136 public void onPeriodicTxDataNotificationReceived(UwbTestPeriodicTxResult periodicTx) { 137 Log.d(TAG, "onPeriodicTxDataNotificationReceived : " + periodicTx); 138 mSessionListener.onRfTestNotificationReceived(periodicTx); 139 } 140 onPerRxDataNotificationReceived(UwbTestPerRxResult perRxResult)141 public void onPerRxDataNotificationReceived(UwbTestPerRxResult perRxResult) { 142 Log.d(TAG, "onPerRxDataNotificationReceived : " + perRxResult); 143 mSessionListener.onRfTestNotificationReceived(perRxResult); 144 } 145 146 /** 147 * Enable UWB hardware. 148 * 149 * @return : {@code Map<String,UwbDeviceInfoResponse>}, error is indicated by it being null. 150 * The key for the map is the ChipId (string). 151 */ 152 @Nullable doInitialize()153 public Map<String, UwbDeviceInfoResponse> doInitialize() { 154 UwbDeviceInfoResponse deviceInfoResponse = null; 155 Map<String, UwbDeviceInfoResponse> chipIdToDeviceInfoResponseMap = new HashMap<>(); 156 synchronized (mNativeLock) { 157 mDispatcherPointer = nativeDispatcherNew(mUwbMultichipData.getChipIds().toArray()); 158 for (String chipId : mUwbMultichipData.getChipIds()) { 159 deviceInfoResponse = nativeDoInitialize(chipId); 160 if (deviceInfoResponse == null 161 || deviceInfoResponse.mStatusCode != UwbUciConstants.STATUS_CODE_OK) { 162 return null; 163 } 164 chipIdToDeviceInfoResponseMap.put(chipId, deviceInfoResponse); 165 } 166 nativeSetLogMode(mUciLogModeStore.getMode()); 167 } 168 return chipIdToDeviceInfoResponseMap; 169 } 170 171 /** 172 * Disable UWB hardware. 173 * 174 * @return : If this returns true, UWB is off 175 */ doDeinitialize()176 public boolean doDeinitialize() { 177 synchronized (mNativeLock) { 178 for (String chipId : mUwbMultichipData.getChipIds()) { 179 nativeDoDeinitialize(chipId); 180 } 181 182 nativeDispatcherDestroy(); 183 mDispatcherPointer = 0L; 184 } 185 return true; 186 } 187 188 /** 189 * Gets the timestamp resolution in nanosecond 190 * 191 * @return : timestamp resolution in nanosecond 192 */ getTimestampResolutionNanos()193 public long getTimestampResolutionNanos() { 194 return 0L; 195 /* TODO: Not Implemented in native stack 196 return nativeGetTimestampResolutionNanos(); */ 197 } 198 199 /** 200 * Retrieves power related stats 201 */ getPowerStats(String chipId)202 public UwbPowerStats getPowerStats(String chipId) { 203 synchronized (mNativeLock) { 204 return nativeGetPowerStats(chipId); 205 } 206 } 207 208 /** 209 * Creates the new UWB session with parameter session ID and type of the session. 210 * 211 * @param sessionId : Session ID is 4 Octets unique random number generated by application 212 * @param sessionType : Type of session 0x00: Ranging session 0x01: Data transfer 0x02-0x9F: RFU 213 * 0xA0-0xCF: Reserved for Vendor Specific use case 0xD0: Device Test Mode 214 * 0xD1-0xDF: RFU 0xE0-0xFF: Vendor Specific use 215 * @param chipId : Identifier of UWB chip for multi-HAL devices 216 * @return : {@link UwbUciConstants} Status code 217 */ initSession(int sessionId, byte sessionType, String chipId)218 public byte initSession(int sessionId, byte sessionType, String chipId) { 219 synchronized (mNativeLock) { 220 return nativeSessionInit(sessionId, sessionType, chipId); 221 } 222 } 223 224 /** 225 * De-initializes the session. 226 * 227 * @param sessionId : Session ID for which session to be de-initialized 228 * @param chipId : Identifier of UWB chip for multi-HAL devices 229 * @return : {@link UwbUciConstants} Status code 230 */ deInitSession(int sessionId, String chipId)231 public byte deInitSession(int sessionId, String chipId) { 232 synchronized (mNativeLock) { 233 return nativeSessionDeInit(sessionId, chipId); 234 } 235 } 236 237 /** 238 * reset the UWBs 239 * 240 * @param resetConfig : Reset config 241 * @param chipId : Identifier of UWB chip for multi-HAL devices 242 * @return : {@link UwbUciConstants} Status code 243 */ deviceReset(byte resetConfig, String chipId)244 public byte deviceReset(byte resetConfig, String chipId) { 245 synchronized (mNativeLock) { 246 return nativeDeviceReset(resetConfig, chipId); 247 } 248 } 249 250 /** 251 * Retrieves number of UWB sessions in the UWBS. 252 * 253 * @param chipId : Identifier of UWB chip for multi-HAL devices 254 * @return : Number of UWB sessions present in the UWBS. 255 */ getSessionCount(String chipId)256 public byte getSessionCount(String chipId) { 257 synchronized (mNativeLock) { 258 return nativeGetSessionCount(chipId); 259 } 260 } 261 262 /** 263 * Queries the current state of the UWB session. 264 * 265 * @param sessionId : Session of the UWB session for which current session state to be queried 266 * @param chipId : Identifier of UWB chip for multi-HAL devices 267 * @return : {@link UwbUciConstants} Session State 268 */ getSessionState(int sessionId, String chipId)269 public byte getSessionState(int sessionId, String chipId) { 270 synchronized (mNativeLock) { 271 return nativeGetSessionState(sessionId, chipId); 272 } 273 } 274 275 /** 276 * Starts a UWB session. 277 * 278 * @param sessionId : Session ID for which ranging shall start 279 * @param chipId : Identifier of UWB chip for multi-HAL devices 280 * @return : {@link UwbUciConstants} Status code 281 */ startRanging(int sessionId, String chipId)282 public byte startRanging(int sessionId, String chipId) { 283 synchronized (mNativeLock) { 284 return nativeRangingStart(sessionId, chipId); 285 } 286 } 287 288 /** 289 * Stops the ongoing UWB session. 290 * 291 * @param sessionId : Stop the requested ranging session. 292 * @param chipId : Identifier of UWB chip for multi-HAL devices 293 * @return : {@link UwbUciConstants} Status code 294 */ stopRanging(int sessionId, String chipId)295 public byte stopRanging(int sessionId, String chipId) { 296 synchronized (mNativeLock) { 297 return nativeRangingStop(sessionId, chipId); 298 } 299 } 300 301 /** 302 * Set APP Configuration Parameters for the requested UWB session 303 * 304 * @param noOfParams : The number (n) of APP Configuration Parameters 305 * @param appConfigParamLen : The length of APP Configuration Parameters 306 * @param appConfigParams : APP Configuration Parameter 307 * @param chipId : Identifier of UWB chip for multi-HAL devices 308 * @return : {@link UwbConfigStatusData} : Contains statuses for all cfg_id 309 */ setAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)310 public UwbConfigStatusData setAppConfigurations(int sessionId, int noOfParams, 311 int appConfigParamLen, byte[] appConfigParams, String chipId) { 312 synchronized (mNativeLock) { 313 return nativeSetAppConfigurations(sessionId, noOfParams, appConfigParamLen, 314 appConfigParams, chipId); 315 } 316 } 317 318 /** 319 * set RF Test Configuration Parameters for the requested UWB Test session 320 * 321 * @param noOfParams : The number (n) of APP Configuration Parameters 322 * @param appConfigParamLen : The length of APP Configuration Parameters 323 * @param appConfigParams : APP Configuration Parameter 324 * @param chipId : Identifier of UWB chip for multi-HAL devices 325 * @return : {@link UwbConfigStatusData} : Contains statuses for all cfg_id 326 */ setRfTestAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)327 public UwbConfigStatusData setRfTestAppConfigurations(int sessionId, int noOfParams, 328 int appConfigParamLen, byte[] appConfigParams, String chipId) { 329 synchronized (mNativeLock) { 330 return nativeSetRfTestAppConfigurations(sessionId, noOfParams, appConfigParamLen, 331 appConfigParams, chipId); 332 } 333 } 334 335 /** 336 * Starts a Periodic Tx test 337 * 338 * @param psduData : PSDU data 339 * @param chipId : Identifier of UWB chip for multi-HAL devices 340 * @return : {@link UwbUciConstants} Status code 341 */ testPeriodicTx(byte[] psduData, String chipId)342 public byte testPeriodicTx(byte[] psduData, String chipId) { 343 synchronized (mNativeLock) { 344 return nativeTestPeriodicTx(psduData, chipId); 345 } 346 } 347 348 /** 349 * Starts a Per Rx test 350 * 351 * @param psduData : PSDU data 352 * @param chipId : Identifier of UWB chip for multi-HAL devices 353 * @return : {@link UwbUciConstants} Status code 354 */ testPerRx(byte[] psduData, String chipId)355 public byte testPerRx(byte[] psduData, String chipId) { 356 synchronized (mNativeLock) { 357 return nativeTestPerRx(psduData, chipId); 358 } 359 } 360 361 /* 362 * Stops the ongoing Rf test session. 363 * 364 * @param chipId : Identifier of UWB chip for multi-HAL devices 365 * @return : {@link UwbUciConstants} Status code 366 */ stopRfTest(String chipId)367 public byte stopRfTest(String chipId) { 368 synchronized (mNativeLock) { 369 return nativeStopRfTest(chipId); 370 } 371 } 372 373 /** 374 * Set radar APP Configuration Parameters for the requested UWB radar session 375 * 376 * @param noOfParams : The number (n) of APP Configuration Parameters 377 * @param appConfigParamLen : The length of APP Configuration Parameters 378 * @param appConfigParams : APP Configuration Parameter 379 * @param chipId : Identifier of UWB chip for multi-HAL devices 380 * @return : {@link UwbConfigStatusData} : Contains statuses for all cfg_id 381 */ setRadarAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)382 public UwbConfigStatusData setRadarAppConfigurations(int sessionId, int noOfParams, 383 int appConfigParamLen, byte[] appConfigParams, String chipId) { 384 synchronized (mNativeLock) { 385 return nativeSetRadarAppConfigurations(sessionId, noOfParams, appConfigParamLen, 386 appConfigParams, chipId); 387 } 388 } 389 390 /** 391 * Get APP Configuration Parameters for the requested UWB session 392 * 393 * @param noOfParams : The number (n) of APP Configuration Parameters 394 * @param appConfigParamLen : The length of APP Configuration Parameters 395 * @param appConfigIds : APP Configuration Parameter 396 * @param chipId : Identifier of UWB chip for multi-HAL devices 397 * @return : {@link UwbTlvData} : All tlvs that are to be decoded 398 */ getAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigIds, String chipId)399 public UwbTlvData getAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, 400 byte[] appConfigIds, String chipId) { 401 synchronized (mNativeLock) { 402 return nativeGetAppConfigurations(sessionId, noOfParams, appConfigParamLen, 403 appConfigIds, chipId); 404 } 405 } 406 407 /** 408 * Get Core Capabilities information 409 * 410 * @param chipId : Identifier of UWB chip for multi-HAL devices 411 * @return : {@link UwbTlvData} : All tlvs that are to be decoded 412 */ getCapsInfo(String chipId)413 public UwbTlvData getCapsInfo(String chipId) { 414 synchronized (mNativeLock) { 415 return nativeGetCapsInfo(chipId); 416 } 417 } 418 419 /** 420 * Update Multicast list for the requested UWB session using V1 command. 421 * 422 * @param sessionId : Session ID to which multicast list to be updated 423 * @param action : Update the multicast list by adding or removing 424 * 0x00 - Adding 425 * 0x01 - removing 426 * 0x02 - Adding with 16 bits sub-session key 427 * 0x03 - Adding with 32 bits sub-session key 428 * @param noOfControlee : The number(n) of Controlees 429 * @param addresses : address list of Controlees 430 * @param subSessionIds : Specific sub-session ID list of Controlees 431 * @param subSessionKeyList : Sub-session key list of Controlees 432 * @return : refer to SESSION_SET_APP_CONFIG_RSP 433 * in the Table 16: Control messages to set Application configurations 434 */ controllerMulticastListUpdate(int sessionId, int action, int noOfControlee, byte[] addresses, int[] subSessionIds, byte[] subSessionKeyList, String chipId)435 public UwbMulticastListUpdateStatus controllerMulticastListUpdate(int sessionId, int action, 436 int noOfControlee, byte[] addresses, int[] subSessionIds, byte[] subSessionKeyList, 437 String chipId) { 438 synchronized (mNativeLock) { 439 return nativeControllerMulticastListUpdate(sessionId, (byte) action, 440 (byte) noOfControlee, addresses, subSessionIds, subSessionKeyList, chipId, 441 mUwbInjector.isMulticastListNtfV2Supported(), 442 mUwbInjector.isMulticastListRspV2Supported()); 443 } 444 } 445 446 /** 447 * Set country code. 448 * 449 * @param countryCode 2 char ISO country code 450 */ setCountryCode(byte[] countryCode)451 public byte setCountryCode(byte[] countryCode) { 452 Log.i(TAG, "setCountryCode: " + new String(countryCode)); 453 454 synchronized (mNativeLock) { 455 for (String chipId : mUwbMultichipData.getChipIds()) { 456 byte status = nativeSetCountryCode(countryCode, chipId); 457 if (status != UwbUciConstants.STATUS_CODE_OK) { 458 return status; 459 } 460 } 461 return UwbUciConstants.STATUS_CODE_OK; 462 } 463 } 464 465 /** 466 * Sets the log mode for the current and future UWB UCI messages. 467 * 468 * @param logModeStr is one of Disabled, Filtered, or Unfiltered (case insensitive). 469 * @return true if the log mode is set successfully, false otherwise. 470 */ setLogMode(String logModeStr)471 public boolean setLogMode(String logModeStr) { 472 synchronized (mNativeLock) { 473 return nativeSetLogMode(mUciLogModeStore.getMode()); 474 } 475 } 476 477 @NonNull sendRawVendorCmd(int mt, int gid, int oid, byte[] payload, String chipId)478 public UwbVendorUciResponse sendRawVendorCmd(int mt, int gid, int oid, byte[] payload, 479 String chipId) { 480 synchronized (mNativeLock) { 481 return nativeSendRawVendorCmd(mt, gid, oid, payload, chipId); 482 } 483 } 484 485 /** 486 * Receive payload data from a remote device in a UWB ranging session. 487 */ onDataReceived( long sessionID, int status, long sequenceNum, byte[] address, byte[] data)488 public void onDataReceived( 489 long sessionID, int status, long sequenceNum, byte[] address, byte[] data) { 490 Log.d(TAG, "onDataReceived "); 491 mSessionListener.onDataReceived(sessionID, status, sequenceNum, address, data); 492 } 493 494 /** 495 * Send payload data to a remote device in a UWB ranging session. 496 */ sendData( int sessionId, byte[] address, short sequenceNum, byte[] appData, String chipId)497 public byte sendData( 498 int sessionId, byte[] address, short sequenceNum, byte[] appData, String chipId) { 499 synchronized (mNativeLock) { 500 return nativeSendData(sessionId, address, sequenceNum, appData, chipId); 501 } 502 } 503 504 /** 505 * Receive the data transfer status for a UCI data packet earlier sent from Host to UWBS. 506 */ onDataSendStatus(long sessionId, int dataTransferStatus, long sequenceNum, int txCount)507 public void onDataSendStatus(long sessionId, int dataTransferStatus, long sequenceNum, 508 int txCount) { 509 Log.d(TAG, "onDataSendStatus "); 510 mSessionListener.onDataSendStatus(sessionId, dataTransferStatus, sequenceNum, txCount); 511 } 512 513 /** 514 * Set Data transfer phase configuration 515 */ setDataTransferPhaseConfig(int sessionId, byte dtpcmRepetition, byte dataTransferControl, byte dtpmlSize, byte[] macAddress, byte[] slotBitmap, byte[] stopDataTransfer, String chipId)516 public byte setDataTransferPhaseConfig(int sessionId, byte dtpcmRepetition, 517 byte dataTransferControl, byte dtpmlSize, byte[] macAddress, byte[] slotBitmap, 518 byte[] stopDataTransfer, String chipId) { 519 synchronized (mNativeLock) { 520 return nativeSessionDataTransferPhaseConfig(sessionId, dtpcmRepetition, 521 dataTransferControl, dtpmlSize, macAddress, slotBitmap, stopDataTransfer, chipId); 522 } 523 } 524 525 /** 526 * Receive the data transfer phase config status 527 */ onDataTransferPhaseConfigNotificationReceived(long sessionId, int dataTransferPhaseConfigStatus)528 public void onDataTransferPhaseConfigNotificationReceived(long sessionId, 529 int dataTransferPhaseConfigStatus) { 530 Log.d(TAG, "onDataTransferPhaseConfigNotificationReceived "); 531 mSessionListener.onDataTransferPhaseConfigNotificationReceived(sessionId, 532 dataTransferPhaseConfigStatus); 533 } 534 535 /** 536 * Update Ranging Rounds for DT Tag 537 * 538 * @param sessionId Session ID to which ranging round to be updated 539 * @param noOfRangingRounds new active ranging round 540 * @param rangingRoundIndexes Indexes of ranging rounds 541 * @return refer to SESSION_SET_APP_CONFIG_RSP 542 * in the Table 16: Control messages to set Application configurations 543 */ sessionUpdateDtTagRangingRounds(int sessionId, int noOfRangingRounds, byte[] rangingRoundIndexes, String chipId)544 public DtTagUpdateRangingRoundsStatus sessionUpdateDtTagRangingRounds(int sessionId, 545 int noOfRangingRounds, byte[] rangingRoundIndexes, String chipId) { 546 synchronized (mNativeLock) { 547 return nativeSessionUpdateDtTagRangingRounds(sessionId, noOfRangingRounds, 548 rangingRoundIndexes, chipId); 549 } 550 } 551 552 /** 553 * Queries the max Application data size for the UWB session. 554 * 555 * @param sessionId : Session of the UWB session for which current max data size to be queried 556 * @param chipId : Identifier of UWB chip for multi-HAL devices 557 * @return : Max application data size that can be sent by UWBS. 558 */ queryMaxDataSizeBytes(int sessionId, String chipId)559 public int queryMaxDataSizeBytes(int sessionId, String chipId) { 560 synchronized (mNativeLock) { 561 return nativeQueryDataSize(sessionId, chipId); 562 } 563 } 564 565 /** 566 * query device timestamp 567 * 568 * @return : uwb device timestamp 569 */ queryUwbsTimestamp(String chipId)570 public long queryUwbsTimestamp(String chipId) { 571 synchronized (mNativeLock) { 572 return nativeQueryUwbTimestamp(chipId); 573 } 574 } 575 576 /** 577 * Get session token from session id. 578 * 579 * @param sessionId : session id of uwb session 580 * @param chipId : Identifier of UWB chip for multi-HAL devices 581 * @return : session token generated for the session. 582 */ getSessionToken(int sessionId, String chipId)583 public int getSessionToken(int sessionId, String chipId) { 584 synchronized (mNativeLock) { 585 return nativeGetSessionToken(sessionId, chipId); 586 } 587 } 588 589 /** 590 * Sets the Hybrid UWB Session Controller Configuration 591 * 592 * @param sessionId : Primary session ID 593 * @param numberOfPhases : Number of secondary sessions 594 * @param phaseList : list of secondary sessions which have been previously initialized and 595 * configured 596 * @param chipId : Identifier of UWB chip for multi-HAL devices 597 * @return Byte representing the status of the operation 598 */ setHybridSessionControllerConfiguration(int sessionId, int numberOfPhases, byte[] phaseList, String chipId)599 public byte setHybridSessionControllerConfiguration(int sessionId, int numberOfPhases, 600 byte[] phaseList, String chipId) { 601 synchronized (mNativeLock) { 602 return nativeSetHybridSessionControllerConfigurations(sessionId, numberOfPhases, 603 phaseList, chipId); 604 } 605 } 606 607 /** 608 * Sets the Hybrid UWB Session Controlee Configuration 609 * 610 * @param sessionId : Primary session ID 611 * @param numberOfPhases : Number of secondary sessions 612 * @param phaseList : list of secondary sessions 613 * @param chipId : Identifier of UWB chip for multi-HAL devices 614 * @return Byte representing the status of the operation 615 */ setHybridSessionControleeConfiguration(int sessionId, int numberOfPhases, byte[] phaseList, String chipId)616 public byte setHybridSessionControleeConfiguration(int sessionId, int numberOfPhases, 617 byte[] phaseList, String chipId) { 618 synchronized (mNativeLock) { 619 return nativeSetHybridSessionControleeConfigurations(sessionId, numberOfPhases, 620 phaseList, chipId); 621 } 622 } 623 nativeSendData(int sessionId, byte[] address, short sequenceNum, byte[] appData, String chipId)624 private native byte nativeSendData(int sessionId, byte[] address, 625 short sequenceNum, byte[] appData, String chipId); 626 nativeSessionDataTransferPhaseConfig(int sessionId, byte dtpcmRepetition, byte dataTransferControl, byte dtpmlSize, byte[] macAddress, byte[] slotBitmap, byte[] stopDataTransfer, String chipId)627 private native byte nativeSessionDataTransferPhaseConfig(int sessionId, byte dtpcmRepetition, 628 byte dataTransferControl, byte dtpmlSize, byte[] macAddress, byte[] slotBitmap, 629 byte[] stopDataTransfer, String chipId); 630 nativeDispatcherNew(Object[] chipIds)631 private native long nativeDispatcherNew(Object[] chipIds); 632 nativeDispatcherDestroy()633 private native void nativeDispatcherDestroy(); 634 nativeInit()635 private native boolean nativeInit(); 636 nativeDoInitialize(String chipIds)637 private native UwbDeviceInfoResponse nativeDoInitialize(String chipIds); 638 nativeDoDeinitialize(String chipId)639 private native boolean nativeDoDeinitialize(String chipId); 640 nativeGetTimestampResolutionNanos()641 private native long nativeGetTimestampResolutionNanos(); 642 nativeGetPowerStats(String chipId)643 private native UwbPowerStats nativeGetPowerStats(String chipId); 644 nativeDeviceReset(byte resetConfig, String chipId)645 private native byte nativeDeviceReset(byte resetConfig, String chipId); 646 nativeSessionInit(int sessionId, byte sessionType, String chipId)647 private native byte nativeSessionInit(int sessionId, byte sessionType, String chipId); 648 nativeSessionDeInit(int sessionId, String chipId)649 private native byte nativeSessionDeInit(int sessionId, String chipId); 650 nativeGetSessionCount(String chipId)651 private native byte nativeGetSessionCount(String chipId); 652 nativeRangingStart(int sessionId, String chipId)653 private native byte nativeRangingStart(int sessionId, String chipId); 654 nativeRangingStop(int sessionId, String chipId)655 private native byte nativeRangingStop(int sessionId, String chipId); 656 nativeGetSessionState(int sessionId, String chipId)657 private native byte nativeGetSessionState(int sessionId, String chipId); 658 nativeSetAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)659 private native UwbConfigStatusData nativeSetAppConfigurations(int sessionId, int noOfParams, 660 int appConfigParamLen, byte[] appConfigParams, String chipId); 661 nativeGetAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)662 private native UwbTlvData nativeGetAppConfigurations(int sessionId, int noOfParams, 663 int appConfigParamLen, byte[] appConfigParams, String chipId); 664 nativeSetRadarAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)665 private native UwbConfigStatusData nativeSetRadarAppConfigurations(int sessionId, 666 int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId); 667 nativeGetCapsInfo(String chipId)668 private native UwbTlvData nativeGetCapsInfo(String chipId); 669 nativeControllerMulticastListUpdate(int sessionId, byte action, byte noOfControlee, byte[] address, int[] subSessionId, byte[] subSessionKeyList, String chipId, boolean isMulticastListNtfV2Supported, boolean isMulticastListRspV2Supported)670 private native UwbMulticastListUpdateStatus nativeControllerMulticastListUpdate(int sessionId, 671 byte action, byte noOfControlee, byte[] address, int[] subSessionId, 672 byte[] subSessionKeyList, String chipId, boolean isMulticastListNtfV2Supported, 673 boolean isMulticastListRspV2Supported); 674 nativeSetCountryCode(byte[] countryCode, String chipId)675 private native byte nativeSetCountryCode(byte[] countryCode, String chipId); 676 nativeSetLogMode(String logMode)677 private native boolean nativeSetLogMode(String logMode); 678 nativeSendRawVendorCmd(int mt, int gid, int oid, byte[] payload, String chipId)679 private native UwbVendorUciResponse nativeSendRawVendorCmd(int mt, int gid, int oid, 680 byte[] payload, String chipId); 681 nativeSessionUpdateDtTagRangingRounds( int sessionId, int noOfActiveRangingRounds, byte[] rangingRoundIndexes, String chipId)682 private native DtTagUpdateRangingRoundsStatus nativeSessionUpdateDtTagRangingRounds( 683 int sessionId, int noOfActiveRangingRounds, byte[] rangingRoundIndexes, String chipId); 684 nativeQueryDataSize(int sessionId, String chipId)685 private native short nativeQueryDataSize(int sessionId, String chipId); 686 nativeQueryUwbTimestamp(String chipId)687 private native long nativeQueryUwbTimestamp(String chipId); 688 nativeGetSessionToken(int sessionId, String chipId)689 private native int nativeGetSessionToken(int sessionId, String chipId); 690 nativeSetHybridSessionControllerConfigurations(int sessionId, int noOfPhases, byte[] phaseList, String chipId)691 private native byte nativeSetHybridSessionControllerConfigurations(int sessionId, 692 int noOfPhases, byte[] phaseList, String chipId); 693 nativeSetHybridSessionControleeConfigurations(int sessionId, int noOfPhases, byte[] phaseList, String chipId)694 private native byte nativeSetHybridSessionControleeConfigurations(int sessionId, 695 int noOfPhases, byte[] phaseList, String chipId); 696 nativeSetRfTestAppConfigurations(int sessionId, int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId)697 private native UwbConfigStatusData nativeSetRfTestAppConfigurations(int sessionId, 698 int noOfParams, int appConfigParamLen, byte[] appConfigParams, String chipId); 699 nativeTestPeriodicTx(byte[] psduData, String chipId)700 private native byte nativeTestPeriodicTx(byte[] psduData, String chipId); 701 nativeTestPerRx(byte[] psduData, String chipId)702 private native byte nativeTestPerRx(byte[] psduData, String chipId); 703 nativeStopRfTest(String chipId)704 private native byte nativeStopRfTest(String chipId); 705 } 706