From 7d422812c7aa0f8cca24c5fdb01a8f2a287af3c1 Mon Sep 17 00:00:00 2001 From: maheshkkv Date: Thu, 16 Nov 2023 17:32:50 -0800 Subject: [PATCH] Add HAL support for IEEE 802.11 az ranging Bug: 295619650 Test: m Change-Id: Ieba17a1414afa8fddca7d0d87e786c760c6789e5 --- .../hardware/wifi/RttCapabilities.aidl | 5 + .../android/hardware/wifi/RttConfig.aidl | 3 + .../android/hardware/wifi/RttPreamble.aidl | 1 + .../android/hardware/wifi/RttResult.aidl | 3 + .../android/hardware/wifi/RttType.aidl | 2 + .../hardware/wifi/RttCapabilities.aidl | 34 +++- .../aidl/android/hardware/wifi/RttConfig.aidl | 26 ++- .../android/hardware/wifi/RttPreamble.aidl | 1 + .../aidl/android/hardware/wifi/RttResult.aidl | 59 ++++-- wifi/aidl/android/hardware/wifi/RttType.aidl | 13 ++ wifi/aidl/default/aidl_struct_util.cpp | 168 +++++++++++++++--- wifi/aidl/default/aidl_struct_util.h | 11 ++ wifi/aidl/default/wifi_legacy_hal.cpp | 52 ++++++ wifi/aidl/default/wifi_legacy_hal.h | 14 ++ wifi/aidl/default/wifi_legacy_hal_stubs.cpp | 2 + wifi/aidl/default/wifi_rtt_controller.cpp | 60 ++++++- 16 files changed, 401 insertions(+), 53 deletions(-) diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttCapabilities.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttCapabilities.aidl index cf64687c50..56ef2d204d 100644 --- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttCapabilities.aidl +++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttCapabilities.aidl @@ -42,4 +42,9 @@ parcelable RttCapabilities { android.hardware.wifi.RttPreamble preambleSupport; android.hardware.wifi.RttBw bwSupport; byte mcVersion; + android.hardware.wifi.RttPreamble azPreambleSupport; + android.hardware.wifi.RttBw azBwSupport; + boolean ntbInitiatorSupported; + boolean ntbResponderSupported; + int maxTxLtfRepetitionCount; } diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttConfig.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttConfig.aidl index ccdf2cee68..b7830bd126 100644 --- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttConfig.aidl +++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttConfig.aidl @@ -48,4 +48,7 @@ parcelable RttConfig { int burstDuration; android.hardware.wifi.RttPreamble preamble; android.hardware.wifi.RttBw bw; + int ntbMinMeasurementTimeMillis; + int ntbMaxMeasurementTimeMillis; + int txLtfRepetitionCount; } diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttPreamble.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttPreamble.aidl index de26f28f81..280246451e 100644 --- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttPreamble.aidl +++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttPreamble.aidl @@ -34,6 +34,7 @@ package android.hardware.wifi; @Backing(type="int") @VintfStability enum RttPreamble { + INVALID = 0, LEGACY = 0x1, HT = 0x2, VHT = 0x4, diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttResult.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttResult.aidl index 8375dcb148..30f5f58b52 100644 --- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttResult.aidl +++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttResult.aidl @@ -59,4 +59,7 @@ parcelable RttResult { android.hardware.wifi.WifiInformationElement lcr; int channelFreqMHz; android.hardware.wifi.RttBw packetBw; + int txLtfRepetitionCount; + int ntbMinMeasurementTimeMillis; + int ntbMaxMeasurementTimeMillis; } diff --git a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttType.aidl b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttType.aidl index 2b6087a6bc..cb25673af3 100644 --- a/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttType.aidl +++ b/wifi/aidl/aidl_api/android.hardware.wifi/current/android/hardware/wifi/RttType.aidl @@ -36,4 +36,6 @@ package android.hardware.wifi; enum RttType { ONE_SIDED = 1, TWO_SIDED = 2, + TWO_SIDED_11MC = TWO_SIDED /* 2 */, + TWO_SIDED_11AZ_NTB = 3, } diff --git a/wifi/aidl/android/hardware/wifi/RttCapabilities.aidl b/wifi/aidl/android/hardware/wifi/RttCapabilities.aidl index 7c47ed5f9c..0352ec8ea6 100644 --- a/wifi/aidl/android/hardware/wifi/RttCapabilities.aidl +++ b/wifi/aidl/android/hardware/wifi/RttCapabilities.aidl @@ -33,24 +33,25 @@ parcelable RttCapabilities { */ boolean rttFtmSupported; /** - * Whether initiator supports LCI request. Applies to 2-sided RTT. + * Whether initiator supports Location Configuration Information (LCI) request. Applies to + * 2-sided RTT. */ boolean lciSupported; /** - * Whether initiator supports LCR request. Applies to 2-sided RTT. + * Whether initiator supports Location Civic Report (LCR) request. Applies to 2-sided RTT. */ boolean lcrSupported; /** - * Whether 11mc responder mode is supported. + * Whether IEEE 802.11mc responder mode is supported. */ boolean responderSupported; /** - * Bit mask indicating what preamble is supported by initiator. + * Bit mask indicating what preamble is supported by IEEE 802.11mc initiator. * Combination of |RttPreamble| values. */ RttPreamble preambleSupport; /** - * Bit mask indicating what BW is supported by initiator. + * Bit mask indicating what BW is supported by IEEE 802.11mc initiator. * Combination of |RttBw| values. */ RttBw bwSupport; @@ -59,4 +60,27 @@ parcelable RttCapabilities { * For instance, version 4.0 must be 40 and version 4.3 must be 43 etc. */ byte mcVersion; + /** + * Bit mask indicating what preamble is supported by IEEE 802.11az initiator. + * Combination of |RttPreamble| values. + */ + RttPreamble azPreambleSupport; + /** + * Bit mask indicating what BW is supported by IEEE 802.11az initiator. + * Combination of |RttBw| values. + */ + RttBw azBwSupport; + /** + * Whether the initiator supports IEEE 802.11az Non-Trigger-based (non-TB) measurement. + */ + boolean ntbInitiatorSupported; + /** + * Whether IEEE 802.11az Non-Trigger-based (non-TB) responder mode is supported. + */ + boolean ntbResponderSupported; + /** + * Maximum HE LTF repetitions the IEEE 802.11az initiator is capable of transmitting in the + * preamble of I2R NDP. + */ + int maxTxLtfRepetitionCount; } diff --git a/wifi/aidl/android/hardware/wifi/RttConfig.aidl b/wifi/aidl/android/hardware/wifi/RttConfig.aidl index fc2c2e0e7e..e970656229 100644 --- a/wifi/aidl/android/hardware/wifi/RttConfig.aidl +++ b/wifi/aidl/android/hardware/wifi/RttConfig.aidl @@ -32,7 +32,7 @@ parcelable RttConfig { */ byte[6] addr; /** - * 1-sided or 2-sided RTT. + * 1-sided or 2-sided RTT (IEEE 802.11mc or IEEE 802. 11az). */ RttType type; /** @@ -47,6 +47,8 @@ parcelable RttConfig { * Time interval between bursts (units: 100 ms). * Applies to 1-sided and 2-sided RTT multi-burst requests. * Range: 0-31, 0: no preference by initiator (2-sided RTT). + * + * Note: Applicable to IEEE 802.11mc only. */ int burstPeriod; /** @@ -60,6 +62,9 @@ parcelable RttConfig { * number of RTT results is the following: * for 1-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst) * for 2-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst - 1) + * + * Note: Applicable to IEEE 802.11mc only. For IEEE 802.11az refer + * |RttConfig.txLtfRepetitionCount|. */ int numBurst; /** @@ -70,6 +75,8 @@ parcelable RttConfig { * equals the number of FTM frames that the * initiator will request that the responder sends * in a single frame. + * + * Note: Applicable to IEEE 802.11mc only. */ int numFramesPerBurst; /** @@ -95,8 +102,8 @@ parcelable RttConfig { */ boolean mustRequestLcr; /** - * Applies to 1-sided and 2-sided RTT. Valid values will - * be 2-11 and 15 as specified by the 802.11mc std for + * Applies to 1-sided and 2-sided IEEE 802.11mc RTT. Valid values will + * be 2-11 and 15 as specified by the IEEE 802.11mc std for * the FTM parameter burst duration. In a multi-burst * request, if responder overrides with larger value, * the initiator will return failure. In a single-burst @@ -113,4 +120,17 @@ parcelable RttConfig { * RTT BW to be used in the RTT frames. */ RttBw bw; + /** + * IEEE 802.11az Non-Trigger-based (non-TB) minimum measurement time in milliseconds. + */ + int ntbMinMeasurementTimeMillis; + /** + * IEEE 802.11az Non-Trigger-based (non-TB) maximum measurement time in milliseconds. + */ + int ntbMaxMeasurementTimeMillis; + /** + * Multiple transmissions of HE-LTF symbols in an HE Ranging NDP. A value of 1 indicates no + * repetition. + */ + int txLtfRepetitionCount; } diff --git a/wifi/aidl/android/hardware/wifi/RttPreamble.aidl b/wifi/aidl/android/hardware/wifi/RttPreamble.aidl index e460a94978..21df171bf6 100644 --- a/wifi/aidl/android/hardware/wifi/RttPreamble.aidl +++ b/wifi/aidl/android/hardware/wifi/RttPreamble.aidl @@ -22,6 +22,7 @@ package android.hardware.wifi; @VintfStability @Backing(type="int") enum RttPreamble { + INVALID = 0, LEGACY = 0x1, HT = 0x2, VHT = 0x4, diff --git a/wifi/aidl/android/hardware/wifi/RttResult.aidl b/wifi/aidl/android/hardware/wifi/RttResult.aidl index 6c45e2c349..2cb0afa317 100644 --- a/wifi/aidl/android/hardware/wifi/RttResult.aidl +++ b/wifi/aidl/android/hardware/wifi/RttResult.aidl @@ -33,6 +33,8 @@ parcelable RttResult { byte[6] addr; /** * Burst number in a multi-burst request. + * + * Note: Applicable to 1-sided RTT and 2-sided IEEE 802.11mc only. */ int burstNum; /** @@ -45,7 +47,7 @@ parcelable RttResult { int successNumber; /** * Maximum number of "FTM frames per burst" supported by - * the responder STA. Applies to 2-sided RTT only. + * the responder STA. Applies to 2-sided IEEE 802.11mc RTT only. * If reponder overrides with larger value: * - for single-burst request, initiator will truncate the * larger value and send a TMR_STOP after receiving as @@ -59,10 +61,8 @@ parcelable RttResult { */ RttStatus status; /** - * If status is RTT_STATUS_FAIL_BUSY_TRY_LATER, - * this will be the time provided by the responder as to - * when the request can be tried again. Applies to 2-sided - * RTT only. In sec, 1-31 sec. + * If status is RTT_STATUS_FAIL_BUSY_TRY_LATER, this will be the time provided by the responder + * as to when the request can be tried again. Applies to 2-sided RTT only. In sec, 1-31 sec. */ byte retryAfterDuration; /** @@ -104,11 +104,13 @@ parcelable RttResult { */ int distanceInMm; /** - * Standard deviation in mm (optional). + * Standard deviation in mm. */ int distanceSdInMm; /** * Difference between max and min distance recorded in mm (optional). + * + * Note: Only applicable for IEEE 802.11mc */ int distanceSpreadInMm; /** @@ -116,21 +118,20 @@ parcelable RttResult { */ long timeStampInUs; /** - * Actual time taken by the FW to finish one burst - * measurement (in ms). Applies to 1-sided and 2-sided RTT. + * Actual time taken by the FW to finish one burst measurement (in ms). Applies to 1-sided + * and 2-sided IEEE 802.11mc RTT. */ int burstDurationInMs; /** - * Number of bursts allowed by the responder. Applies - * to 2-sided RTT only. + * Number of bursts allowed by the responder. Applies to 2-sided IEEE 802.11mc RTT only. */ int negotiatedBurstNum; /** - * For 11mc only. + * For IEEE 802.11mc and IEEE 802.11az only. */ WifiInformationElement lci; /** - * For 11mc only. + * For IEEE 802.11mc and IEEE 802.11az only. */ WifiInformationElement lcr; /** @@ -140,8 +141,38 @@ parcelable RttResult { int channelFreqMHz; /** * RTT packet bandwidth. - * This value is an average bandwidth of the bandwidths of measurement - * frames. Cap the average close to a specific valid RttBw. + * This value is an average bandwidth of the bandwidths of measurement frames. Cap the average + * close to a specific valid RttBw. */ RttBw packetBw; + /** + * IEEE 802.11az Transmit LTF repetitions used to get this result. + */ + int txLtfRepetitionCount; + /** + * Minimum non-trigger based (non-TB) dynamic measurement time in milliseconds assigned by the + * IEEE 802.11az responder. + * + * After initial non-TB negotiation, if the next ranging request for this peer comes in between + * [ntbMinMeasurementTime, ntbMaxMeasurementTime], vendor software shall do the NDPA sounding + * sequence for dynamic non-TB measurement. + * + * If the ranging request for this peer comes sooner than minimum measurement time, vendor + * software shall return the cached result of the last measurement including the time stamp + * |RttResult.timestamp|. + */ + int ntbMinMeasurementTimeMillis; + /** + * Maximum non-trigger based (non-TB) dynamic measurement time in milliseconds assigned by the + * IEEE 802.11az responder. + * + * After initial non-TB negotiation, if the next ranging request for this peer comes in between + * [ntbMinMeasurementTime, ntbMaxMeasurementTime], vendor software shall do the NDPA sounding + * sequence for dynamic non-TB measurement. + * + * If the ranging request for this peer comes later than the maximum measurement time, vendor + * software shall clean up any existing IEEE 802.11ax non-TB ranging session and re-do the + * non-TB ranging negotiation. + */ + int ntbMaxMeasurementTimeMillis; } diff --git a/wifi/aidl/android/hardware/wifi/RttType.aidl b/wifi/aidl/android/hardware/wifi/RttType.aidl index e95a92875a..3f1a2f165b 100644 --- a/wifi/aidl/android/hardware/wifi/RttType.aidl +++ b/wifi/aidl/android/hardware/wifi/RttType.aidl @@ -23,5 +23,18 @@ package android.hardware.wifi; @Backing(type="int") enum RttType { ONE_SIDED = 1, + /** + * Two-sided RTT 11mc type. + * + * Note: TWO_SIDED was used for IEEE 802.11mc. Use TWO_SIDED_11MC for IEEE 802.11mc instead. + */ TWO_SIDED = 2, + /** + * Two-sided RTT 11mc type is same as two-sided. + */ + TWO_SIDED_11MC = TWO_SIDED, + /** + * Two-sided RTT 11az non trigger based (non-TB) type. + */ + TWO_SIDED_11AZ_NTB = 3, } diff --git a/wifi/aidl/default/aidl_struct_util.cpp b/wifi/aidl/default/aidl_struct_util.cpp index 99420bd2bc..95ff7a2466 100644 --- a/wifi/aidl/default/aidl_struct_util.cpp +++ b/wifi/aidl/default/aidl_struct_util.cpp @@ -2418,8 +2418,11 @@ legacy_hal::wifi_rtt_type convertAidlRttTypeToLegacy(RttType type) { switch (type) { case RttType::ONE_SIDED: return legacy_hal::RTT_TYPE_1_SIDED; - case RttType::TWO_SIDED: - return legacy_hal::RTT_TYPE_2_SIDED; + case RttType::TWO_SIDED_11MC: + // Same as RttType::TWO_SIDED + return legacy_hal::RTT_TYPE_2_SIDED_11MC; + case RttType::TWO_SIDED_11AZ_NTB: + return legacy_hal::RTT_TYPE_2_SIDED_11AZ_NTB; }; CHECK(false); } @@ -2428,8 +2431,11 @@ RttType convertLegacyRttTypeToAidl(legacy_hal::wifi_rtt_type type) { switch (type) { case legacy_hal::RTT_TYPE_1_SIDED: return RttType::ONE_SIDED; - case legacy_hal::RTT_TYPE_2_SIDED: - return RttType::TWO_SIDED; + case legacy_hal::RTT_TYPE_2_SIDED_11MC: + // Same as legacy_hal::RTT_TYPE_2_SIDED + return RttType::TWO_SIDED_11MC; + case legacy_hal::RTT_TYPE_2_SIDED_11AZ_NTB: + return RttType::TWO_SIDED_11AZ_NTB; }; CHECK(false) << "Unknown legacy type: " << type; } @@ -2509,6 +2515,8 @@ legacy_hal::wifi_rtt_preamble convertAidlRttPreambleToLegacy(RttPreamble type) { return legacy_hal::WIFI_RTT_PREAMBLE_HE; case RttPreamble::EHT: return legacy_hal::WIFI_RTT_PREAMBLE_EHT; + case RttPreamble::INVALID: + return legacy_hal::WIFI_RTT_PREAMBLE_INVALID; }; CHECK(false); } @@ -2525,6 +2533,8 @@ RttPreamble convertLegacyRttPreambleToAidl(legacy_hal::wifi_rtt_preamble type) { return RttPreamble::HE; case legacy_hal::WIFI_RTT_PREAMBLE_EHT: return RttPreamble::EHT; + case legacy_hal::WIFI_RTT_PREAMBLE_INVALID: + return RttPreamble::INVALID; }; CHECK(false) << "Unknown legacy type: " << type; } @@ -2714,6 +2724,21 @@ bool convertAidlRttConfigToLegacy(const RttConfig& aidl_config, return true; } +bool convertAidlRttConfigToLegacyV3(const RttConfig& aidl_config, + legacy_hal::wifi_rtt_config_v3* legacy_config) { + if (!legacy_config) { + return false; + } + *legacy_config = {}; + if (!convertAidlRttConfigToLegacy(aidl_config, &(legacy_config->rtt_config))) { + return false; + } + legacy_config->tx_ltf_repetition_count = aidl_config.txLtfRepetitionCount; + legacy_config->ntb_min_measurement_time_millis = aidl_config.ntbMinMeasurementTimeMillis; + legacy_config->ntb_max_measurement_time_millis = aidl_config.ntbMaxMeasurementTimeMillis; + return true; +} + bool convertAidlVectorOfRttConfigToLegacy( const std::vector& aidl_configs, std::vector* legacy_configs) { @@ -2723,7 +2748,24 @@ bool convertAidlVectorOfRttConfigToLegacy( *legacy_configs = {}; for (const auto& aidl_config : aidl_configs) { legacy_hal::wifi_rtt_config legacy_config; - if (!convertAidlRttConfigToLegacy(aidl_config, &legacy_config)) { + if (!convertAidlRttConfigToLegacy(aidl_config, &(legacy_config))) { + return false; + } + legacy_configs->push_back(legacy_config); + } + return true; +} + +bool convertAidlVectorOfRttConfigToLegacyV3( + const std::vector& aidl_configs, + std::vector* legacy_configs) { + if (!legacy_configs) { + return false; + } + *legacy_configs = {}; + for (const auto& aidl_config : aidl_configs) { + legacy_hal::wifi_rtt_config_v3 legacy_config; + if (!convertAidlRttConfigToLegacyV3(aidl_config, &legacy_config)) { return false; } legacy_configs->push_back(legacy_config); @@ -2792,6 +2834,34 @@ bool convertLegacyRttResponderToAidl(const legacy_hal::wifi_rtt_responder& legac return true; } +RttPreamble convertLegacyRttPreambleBitmapToAidl(byte legacyPreambleBitmap) { + int32_t aidlPreambleBitmap = 0; + for (const auto flag : {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, legacy_hal::WIFI_RTT_PREAMBLE_HT, + legacy_hal::WIFI_RTT_PREAMBLE_VHT, legacy_hal::WIFI_RTT_PREAMBLE_HE, + legacy_hal::WIFI_RTT_PREAMBLE_EHT}) { + if (legacyPreambleBitmap & flag) { + aidlPreambleBitmap |= static_cast::type>( + convertLegacyRttPreambleToAidl(flag)); + } + } + + return static_cast(aidlPreambleBitmap); +} + +RttBw convertLegacyRttBwBitmapToAidl(byte legacyBwBitmap) { + int32_t aidlBwBitmap = 0; + for (const auto flag : + {legacy_hal::WIFI_RTT_BW_5, legacy_hal::WIFI_RTT_BW_10, legacy_hal::WIFI_RTT_BW_20, + legacy_hal::WIFI_RTT_BW_40, legacy_hal::WIFI_RTT_BW_80, legacy_hal::WIFI_RTT_BW_160, + legacy_hal::WIFI_RTT_BW_320}) { + if (legacyBwBitmap & flag) { + aidlBwBitmap |= + static_cast::type>(convertLegacyRttBwToAidl(flag)); + } + } + return static_cast(aidlBwBitmap); +} + bool convertLegacyRttCapabilitiesToAidl( const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, RttCapabilities* aidl_capabilities) { @@ -2804,28 +2874,44 @@ bool convertLegacyRttCapabilitiesToAidl( aidl_capabilities->lciSupported = legacy_capabilities.lci_support; aidl_capabilities->lcrSupported = legacy_capabilities.lcr_support; aidl_capabilities->responderSupported = legacy_capabilities.responder_supported; - int32_t preambleSupport = 0; - for (const auto flag : {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, legacy_hal::WIFI_RTT_PREAMBLE_HT, - legacy_hal::WIFI_RTT_PREAMBLE_VHT, legacy_hal::WIFI_RTT_PREAMBLE_HE, - legacy_hal::WIFI_RTT_PREAMBLE_EHT}) { - if (legacy_capabilities.preamble_support & flag) { - preambleSupport |= static_cast::type>( - convertLegacyRttPreambleToAidl(flag)); - } - } - aidl_capabilities->preambleSupport = static_cast(preambleSupport); - int32_t bwSupport = 0; - for (const auto flag : - {legacy_hal::WIFI_RTT_BW_5, legacy_hal::WIFI_RTT_BW_10, legacy_hal::WIFI_RTT_BW_20, - legacy_hal::WIFI_RTT_BW_40, legacy_hal::WIFI_RTT_BW_80, legacy_hal::WIFI_RTT_BW_160, - legacy_hal::WIFI_RTT_BW_320}) { - if (legacy_capabilities.bw_support & flag) { - bwSupport |= - static_cast::type>(convertLegacyRttBwToAidl(flag)); - } - } - aidl_capabilities->bwSupport = static_cast(bwSupport); + aidl_capabilities->preambleSupport = + convertLegacyRttPreambleBitmapToAidl(legacy_capabilities.preamble_support); + aidl_capabilities->bwSupport = convertLegacyRttBwBitmapToAidl(legacy_capabilities.bw_support); aidl_capabilities->mcVersion = legacy_capabilities.mc_version; + // Initialize 11az parameters to default + aidl_capabilities->azPreambleSupport = RttPreamble::INVALID; + aidl_capabilities->azBwSupport = RttBw::BW_UNSPECIFIED; + aidl_capabilities->ntbInitiatorSupported = false; + aidl_capabilities->ntbResponderSupported = false; + aidl_capabilities->maxTxLtfRepetitionCount = 0; + return true; +} + +bool convertLegacyRttCapabilitiesV3ToAidl( + const legacy_hal::wifi_rtt_capabilities_v3& legacy_capabilities_v3, + RttCapabilities* aidl_capabilities) { + if (!aidl_capabilities) { + return false; + } + *aidl_capabilities = {}; + aidl_capabilities->rttOneSidedSupported = + legacy_capabilities_v3.rtt_capab.rtt_one_sided_supported; + aidl_capabilities->rttFtmSupported = legacy_capabilities_v3.rtt_capab.rtt_ftm_supported; + aidl_capabilities->lciSupported = legacy_capabilities_v3.rtt_capab.lci_support; + aidl_capabilities->lcrSupported = legacy_capabilities_v3.rtt_capab.lcr_support; + aidl_capabilities->responderSupported = legacy_capabilities_v3.rtt_capab.responder_supported; + aidl_capabilities->preambleSupport = + convertLegacyRttPreambleBitmapToAidl(legacy_capabilities_v3.rtt_capab.preamble_support); + aidl_capabilities->bwSupport = + convertLegacyRttBwBitmapToAidl(legacy_capabilities_v3.rtt_capab.bw_support); + aidl_capabilities->mcVersion = legacy_capabilities_v3.rtt_capab.mc_version; + aidl_capabilities->azPreambleSupport = + convertLegacyRttPreambleBitmapToAidl(legacy_capabilities_v3.az_preamble_support); + aidl_capabilities->azBwSupport = + convertLegacyRttBwBitmapToAidl(legacy_capabilities_v3.az_bw_support); + aidl_capabilities->ntbInitiatorSupported = legacy_capabilities_v3.ntb_initiator_supported; + aidl_capabilities->ntbResponderSupported = legacy_capabilities_v3.ntb_responder_supported; + aidl_capabilities->maxTxLtfRepetitionCount = legacy_capabilities_v3.max_tx_ltf_repetition_count; return true; } @@ -2900,6 +2986,9 @@ bool convertLegacyVectorOfRttResultToAidl( } aidl_result.channelFreqMHz = 0; aidl_result.packetBw = RttBw::BW_UNSPECIFIED; + aidl_result.txLtfRepetitionCount = 0; + aidl_result.ntbMinMeasurementTimeMillis = 0; + aidl_result.ntbMaxMeasurementTimeMillis = 0; aidl_results->push_back(aidl_result); } return true; @@ -2920,6 +3009,33 @@ bool convertLegacyVectorOfRttResultV2ToAidl( aidl_result.channelFreqMHz = legacy_result->frequency != UNSPECIFIED ? legacy_result->frequency : 0; aidl_result.packetBw = convertLegacyRttBwToAidl(legacy_result->packet_bw); + aidl_result.txLtfRepetitionCount = 0; + aidl_result.ntbMinMeasurementTimeMillis = 0; + aidl_result.ntbMaxMeasurementTimeMillis = 0; + aidl_results->push_back(aidl_result); + } + return true; +} + +bool convertLegacyVectorOfRttResultV3ToAidl( + const std::vector& legacy_results, + std::vector* aidl_results) { + if (!aidl_results) { + return false; + } + *aidl_results = {}; + for (const auto legacy_result : legacy_results) { + RttResult aidl_result; + if (!convertLegacyRttResultToAidl(legacy_result->rtt_result.rtt_result, &aidl_result)) { + return false; + } + aidl_result.channelFreqMHz = legacy_result->rtt_result.frequency != UNSPECIFIED + ? legacy_result->rtt_result.frequency + : 0; + aidl_result.packetBw = convertLegacyRttBwToAidl(legacy_result->rtt_result.packet_bw); + aidl_result.txLtfRepetitionCount = legacy_result->tx_ltf_repetition_count; + aidl_result.ntbMinMeasurementTimeMillis = legacy_result->ntb_min_measurement_time_millis; + aidl_result.ntbMaxMeasurementTimeMillis = legacy_result->ntb_max_measurement_time_millis; aidl_results->push_back(aidl_result); } return true; diff --git a/wifi/aidl/default/aidl_struct_util.h b/wifi/aidl/default/aidl_struct_util.h index e4ff9638bb..3b9c81dc11 100644 --- a/wifi/aidl/default/aidl_struct_util.h +++ b/wifi/aidl/default/aidl_struct_util.h @@ -148,6 +148,10 @@ bool convertLegacyNanDataPathScheduleUpdateIndToAidl( // RTT controller conversion methods. bool convertAidlVectorOfRttConfigToLegacy(const std::vector& aidl_configs, std::vector* legacy_configs); +bool convertAidlVectorOfRttConfigToLegacyV3( + const std::vector& aidl_configs, + std::vector* legacy_configs); + bool convertAidlRttLciInformationToLegacy(const RttLciInformation& aidl_info, legacy_hal::wifi_lci_information* legacy_info); bool convertAidlRttLcrInformationToLegacy(const RttLcrInformation& aidl_info, @@ -161,12 +165,19 @@ bool convertLegacyRttResponderToAidl(const legacy_hal::wifi_rtt_responder& legac bool convertLegacyRttCapabilitiesToAidl( const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, RttCapabilities* aidl_capabilities); +bool convertLegacyRttCapabilitiesV3ToAidl( + const legacy_hal::wifi_rtt_capabilities_v3& legacy_capabilities_v3, + RttCapabilities* aidl_capabilities); + bool convertLegacyVectorOfRttResultToAidl( const std::vector& legacy_results, std::vector* aidl_results); bool convertLegacyVectorOfRttResultV2ToAidl( const std::vector& legacy_results, std::vector* aidl_results); +bool convertLegacyVectorOfRttResultV3ToAidl( + const std::vector& legacy_results, + std::vector* aidl_results); uint32_t convertAidlWifiBandToLegacyMacBand(WifiBand band); uint32_t convertAidlWifiIfaceModeToLegacy(uint32_t aidl_iface_mask); uint32_t convertAidlUsableChannelFilterToLegacy(uint32_t aidl_filter_mask); diff --git a/wifi/aidl/default/wifi_legacy_hal.cpp b/wifi/aidl/default/wifi_legacy_hal.cpp index 209670bc69..c411f296e7 100644 --- a/wifi/aidl/default/wifi_legacy_hal.cpp +++ b/wifi/aidl/default/wifi_legacy_hal.cpp @@ -183,10 +183,13 @@ std::function on_rtt_results_internal_callback_v2; +std::function + on_rtt_results_internal_callback_v3; void invalidateRttResultsCallbacks() { on_rtt_results_internal_callback = nullptr; on_rtt_results_internal_callback_v2 = nullptr; + on_rtt_results_internal_callback_v3 = nullptr; }; void onAsyncRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result* rtt_results[]) { @@ -206,6 +209,15 @@ void onAsyncRttResultsV2(wifi_request_id id, unsigned num_results, } } +void onAsyncRttResultsV3(wifi_request_id id, unsigned num_results, + wifi_rtt_result_v3* rtt_results_v3[]) { + const auto lock = aidl_sync_util::acquireGlobalLock(); + if (on_rtt_results_internal_callback_v3) { + on_rtt_results_internal_callback_v3(id, num_results, rtt_results_v3); + invalidateRttResultsCallbacks(); + } +} + // Callbacks for the various NAN operations. // NOTE: These have very little conversions to perform before invoking the user // callbacks. @@ -1251,6 +1263,38 @@ wifi_error WifiLegacyHal::registerSubsystemRestartCallbackHandler( return status; } +wifi_error WifiLegacyHal::startRttRangeRequestV3( + const std::string& iface_name, wifi_request_id id, + const std::vector& rtt_configs, + const on_rtt_results_callback_v3& on_results_user_callback_v3) { + if (on_rtt_results_internal_callback_v3) { + return WIFI_ERROR_NOT_AVAILABLE; + } + + on_rtt_results_internal_callback_v3 = [on_results_user_callback_v3]( + wifi_request_id id, unsigned num_results, + wifi_rtt_result_v3* rtt_results_v3[]) { + if (num_results > 0 && !rtt_results_v3) { + LOG(ERROR) << "Unexpected nullptr in RTT v3 results"; + return; + } + std::vector rtt_results_vec_v3; + std::copy_if(rtt_results_v3, rtt_results_v3 + num_results, + back_inserter(rtt_results_vec_v3), + [](wifi_rtt_result_v3* rtt_result_v3) { return rtt_result_v3 != nullptr; }); + on_results_user_callback_v3(id, rtt_results_vec_v3); + }; + + std::vector rtt_configs_internal(rtt_configs); + wifi_error status = global_func_table_.wifi_rtt_range_request_v3( + id, getIfaceHandle(iface_name), rtt_configs.size(), rtt_configs_internal.data(), + {onAsyncRttResultsV3}); + if (status != WIFI_SUCCESS) { + invalidateRttResultsCallbacks(); + } + return status; +} + wifi_error WifiLegacyHal::startRttRangeRequest( const std::string& iface_name, wifi_request_id id, const std::vector& rtt_configs, @@ -1327,6 +1371,14 @@ std::pair WifiLegacyHal::getRttCapabilities( return {status, rtt_caps}; } +std::pair WifiLegacyHal::getRttCapabilitiesV3( + const std::string& iface_name) { + wifi_rtt_capabilities_v3 rtt_caps_v3; + wifi_error status = global_func_table_.wifi_get_rtt_capabilities_v3(getIfaceHandle(iface_name), + &rtt_caps_v3); + return {status, rtt_caps_v3}; +} + std::pair WifiLegacyHal::getRttResponderInfo( const std::string& iface_name) { wifi_rtt_responder rtt_responder; diff --git a/wifi/aidl/default/wifi_legacy_hal.h b/wifi/aidl/default/wifi_legacy_hal.h index 6f012ec857..0f49f423c8 100644 --- a/wifi/aidl/default/wifi_legacy_hal.h +++ b/wifi/aidl/default/wifi_legacy_hal.h @@ -215,6 +215,8 @@ using ::RTT_STATUS_NO_WIFI; using ::RTT_STATUS_SUCCESS; using ::RTT_TYPE_1_SIDED; using ::RTT_TYPE_2_SIDED; +using ::RTT_TYPE_2_SIDED_11AZ_NTB; +using ::RTT_TYPE_2_SIDED_11MC; using ::RX_PKT_FATE_DRV_DROP_FILTER; using ::RX_PKT_FATE_DRV_DROP_INVALID; using ::RX_PKT_FATE_DRV_DROP_NOBUFS; @@ -350,16 +352,20 @@ using ::WIFI_RTT_BW_5; using ::WIFI_RTT_BW_80; using ::WIFI_RTT_BW_UNSPECIFIED; using ::wifi_rtt_capabilities; +using ::wifi_rtt_capabilities_v3; using ::wifi_rtt_config; +using ::wifi_rtt_config_v3; using ::wifi_rtt_preamble; using ::WIFI_RTT_PREAMBLE_EHT; using ::WIFI_RTT_PREAMBLE_HE; using ::WIFI_RTT_PREAMBLE_HT; +using ::WIFI_RTT_PREAMBLE_INVALID; using ::WIFI_RTT_PREAMBLE_LEGACY; using ::WIFI_RTT_PREAMBLE_VHT; using ::wifi_rtt_responder; using ::wifi_rtt_result; using ::wifi_rtt_result_v2; +using ::wifi_rtt_result_v3; using ::wifi_rtt_status; using ::wifi_rtt_type; using ::wifi_rx_packet_fate; @@ -486,6 +492,8 @@ using on_rtt_results_callback = std::function&)>; using on_rtt_results_callback_v2 = std::function&)>; +using on_rtt_results_callback_v3 = + std::function&)>; // Callback for ring buffer data. using on_ring_buffer_data_callback = std::function& rtt_configs, const on_rtt_results_callback& on_results_callback, const on_rtt_results_callback_v2& on_results_callback_v2); + wifi_error startRttRangeRequestV3(const std::string& iface_name, wifi_request_id id, + const std::vector& rtt_configs, + const on_rtt_results_callback_v3& on_results_callback); + wifi_error cancelRttRangeRequest(const std::string& iface_name, wifi_request_id id, const std::vector>& mac_addrs); std::pair getRttCapabilities(const std::string& iface_name); + std::pair getRttCapabilitiesV3( + const std::string& iface_name); std::pair getRttResponderInfo(const std::string& iface_name); wifi_error enableRttResponder(const std::string& iface_name, wifi_request_id id, const wifi_channel_info& channel_hint, uint32_t max_duration_secs, diff --git a/wifi/aidl/default/wifi_legacy_hal_stubs.cpp b/wifi/aidl/default/wifi_legacy_hal_stubs.cpp index b5196c9af6..3d59c658a1 100644 --- a/wifi/aidl/default/wifi_legacy_hal_stubs.cpp +++ b/wifi/aidl/default/wifi_legacy_hal_stubs.cpp @@ -179,6 +179,8 @@ bool initHalFuncTableWithStubs(wifi_hal_fn* hal_fn) { populateStubFor(&hal_fn->wifi_set_scan_mode); populateStubFor(&hal_fn->wifi_set_mlo_mode); populateStubFor(&hal_fn->wifi_get_supported_iface_concurrency_matrix); + populateStubFor(&hal_fn->wifi_get_rtt_capabilities_v3); + populateStubFor(&hal_fn->wifi_rtt_range_request_v3); return true; } diff --git a/wifi/aidl/default/wifi_rtt_controller.cpp b/wifi/aidl/default/wifi_rtt_controller.cpp index a5f6768951..9dee45ca4a 100644 --- a/wifi/aidl/default/wifi_rtt_controller.cpp +++ b/wifi/aidl/default/wifi_rtt_controller.cpp @@ -136,11 +136,45 @@ ndk::ScopedAStatus WifiRttController::registerEventCallbackInternal( ndk::ScopedAStatus WifiRttController::rangeRequestInternal( int32_t cmd_id, const std::vector& rtt_configs) { + // Try 11mc & 11az ranging (v3) + std::vector legacy_configs_v3; + if (!aidl_struct_util::convertAidlVectorOfRttConfigToLegacyV3(rtt_configs, + &legacy_configs_v3)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + std::weak_ptr weak_ptr_this = weak_ptr_this_; + const auto& on_results_callback_v3 = + [weak_ptr_this](legacy_hal::wifi_request_id id, + const std::vector& results) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "v3 Callback invoked on an invalid object"; + return; + } + std::vector aidl_results; + if (!aidl_struct_util::convertLegacyVectorOfRttResultV3ToAidl(results, + &aidl_results)) { + LOG(ERROR) << "Failed to convert rtt results v3 to AIDL structs"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onResults(id, aidl_results).isOk()) { + LOG(ERROR) << "Failed to invoke the v3 callback"; + } + } + }; + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRttRangeRequestV3( + ifname_, cmd_id, legacy_configs_v3, on_results_callback_v3); + + if (legacy_status != legacy_hal::WIFI_ERROR_NOT_SUPPORTED) { + return createWifiStatusFromLegacyError(legacy_status); + } + + // Fallback to 11mc ranging. std::vector legacy_configs; if (!aidl_struct_util::convertAidlVectorOfRttConfigToLegacy(rtt_configs, &legacy_configs)) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); } - std::weak_ptr weak_ptr_this = weak_ptr_this_; const auto& on_results_callback = [weak_ptr_this](legacy_hal::wifi_request_id id, const std::vector& results) { @@ -181,7 +215,7 @@ ndk::ScopedAStatus WifiRttController::rangeRequestInternal( } } }; - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRttRangeRequest( + legacy_status = legacy_hal_.lock()->startRttRangeRequest( ifname_, cmd_id, legacy_configs, on_results_callback, on_results_callback_v2); return createWifiStatusFromLegacyError(legacy_status); } @@ -201,13 +235,29 @@ ndk::ScopedAStatus WifiRttController::rangeCancelInternal(int32_t cmd_id, std::pair WifiRttController::getCapabilitiesInternal() { legacy_hal::wifi_error legacy_status; - legacy_hal::wifi_rtt_capabilities legacy_caps; - std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRttCapabilities(ifname_); + legacy_hal::wifi_rtt_capabilities_v3 legacy_caps_v3; + std::tie(legacy_status, legacy_caps_v3) = legacy_hal_.lock()->getRttCapabilitiesV3(ifname_); + // Try v3 API first, if it is not supported fallback. + if (legacy_status == legacy_hal::WIFI_ERROR_NOT_SUPPORTED) { + legacy_hal::wifi_rtt_capabilities legacy_caps; + std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRttCapabilities(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {RttCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; + } + + RttCapabilities aidl_caps; + if (!aidl_struct_util::convertLegacyRttCapabilitiesToAidl(legacy_caps, &aidl_caps)) { + return {RttCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_caps, ndk::ScopedAStatus::ok()}; + } + if (legacy_status != legacy_hal::WIFI_SUCCESS) { return {RttCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; } + RttCapabilities aidl_caps; - if (!aidl_struct_util::convertLegacyRttCapabilitiesToAidl(legacy_caps, &aidl_caps)) { + if (!aidl_struct_util::convertLegacyRttCapabilitiesV3ToAidl(legacy_caps_v3, &aidl_caps)) { return {RttCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; } return {aidl_caps, ndk::ScopedAStatus::ok()};