diff --git a/wifi/1.4/Android.bp b/wifi/1.4/Android.bp index aba8b4443a..e19785967a 100644 --- a/wifi/1.4/Android.bp +++ b/wifi/1.4/Android.bp @@ -7,8 +7,12 @@ hidl_interface { enabled: true, }, srcs: [ + "types.hal", "IWifi.hal", "IWifiApIface.hal", + "IWifiChip.hal", + "IWifiRttController.hal", + "IWifiRttControllerEventCallback.hal", ], interfaces: [ "android.hardware.wifi@1.0", diff --git a/wifi/1.4/IWifiApIface.hal b/wifi/1.4/IWifiApIface.hal index af88afbea0..80c576dbfc 100644 --- a/wifi/1.4/IWifiApIface.hal +++ b/wifi/1.4/IWifiApIface.hal @@ -49,5 +49,5 @@ interface IWifiApIface extends @1.0::IWifiApIface { * |WifiStatusCode.ERROR_UNKNOWN| * @return mac factory MAC address of the interface */ - getFactoryMacAddress() generates (WifiStatus status, MacAddress mac); + getFactoryMacAddress() generates (WifiStatus status, MacAddress mac); }; diff --git a/wifi/1.4/IWifiChip.hal b/wifi/1.4/IWifiChip.hal new file mode 100644 index 0000000000..d269427a6d --- /dev/null +++ b/wifi/1.4/IWifiChip.hal @@ -0,0 +1,46 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.wifi@1.4; + +import @1.0::WifiStatus; +import @1.0::IWifiIface; +import @1.3::IWifiChip; +import IWifiRttController; + +/** + * Interface that represents a chip that must be configured as a single unit. + */ +interface IWifiChip extends @1.3::IWifiChip { + /** + * Create a RTTController instance. + * + * RTT controller can be either: + * a) Bound to a specific iface by passing in the corresponding |IWifiIface| + * object in |iface| param, OR + * b) Let the implementation decide the iface to use for RTT operations by + * passing null in |iface| param. + * + * @param boundIface HIDL interface object representing the iface if + * the responder must be bound to a specific iface, null otherwise. + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_CHIP_INVALID| + */ + createRttController_1_4(IWifiIface boundIface) + generates (WifiStatus status, IWifiRttController rtt); +}; diff --git a/wifi/1.4/IWifiRttController.hal b/wifi/1.4/IWifiRttController.hal new file mode 100644 index 0000000000..5c71975f2f --- /dev/null +++ b/wifi/1.4/IWifiRttController.hal @@ -0,0 +1,102 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.wifi@1.4; + +import @1.0::IWifiRttController; +import @1.0::CommandId; +import @1.0::WifiChannelInfo; +import @1.0::WifiStatus; +import IWifiRttControllerEventCallback; + +/** + * Interface used to perform RTT(Round trip time) operations. + */ +interface IWifiRttController extends @1.0::IWifiRttController { + /** + * Requests notifications of significant events on this rtt controller. + * Multiple calls to this must register multiple callbacks each of which must + * receive all events. + * + * @param callback An instance of the |IWifiRttControllerEventCallback| HIDL + * interface object. + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_IFACE_INVALID| + */ + registerEventCallback_1_4(IWifiRttControllerEventCallback callback) + generates (WifiStatus status); + + /** + * API to request RTT measurement. + * + * @param cmdId command Id to use for this invocation. + * @param rttConfigs Vector of |RttConfig| parameters. + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID|, + * |WifiStatusCode.ERROR_INVALID_ARGS|, + * |WifiStatusCode.ERROR_NOT_AVAILABLE|, + * |WifiStatusCode.ERROR_UNKNOWN| + */ + rangeRequest_1_4(CommandId cmdId, vec rttConfigs) generates (WifiStatus status); + + /** + * RTT capabilities of the device. + * + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID|, + * |WifiStatusCode.ERROR_UNKNOWN| + * @return capabilities Instance of |RttCapabilities|. + */ + getCapabilities_1_4() generates (WifiStatus status, RttCapabilities capabilities); + + /** + * Get RTT responder information e.g. WiFi channel to enable responder on. + * + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID|, + * |WifiStatusCode.ERROR_NOT_AVAILABLE|, + * |WifiStatusCode.ERROR_UNKNOWN| + * @return info Instance of |RttResponderInfo|. + */ + getResponderInfo_1_4() generates (WifiStatus status, RttResponder info); + + /** + * Enable RTT responder mode. + * + * @param cmdId command Id to use for this invocation. + * @parm channelHint Hint of the channel information where RTT responder must + * be enabled on. + * @param maxDurationInSeconds Timeout of responder mode. + * @param info Instance of |RttResponderInfo|. + * @return status WifiStatus of the operation. + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID|, + * |WifiStatusCode.ERROR_INVALID_ARGS|, + * |WifiStatusCode.ERROR_NOT_AVAILABLE|, + * |WifiStatusCode.ERROR_UNKNOWN| + */ + enableResponder_1_4(CommandId cmdId, WifiChannelInfo channelHint, + uint32_t maxDurationInSeconds, RttResponder info) generates (WifiStatus status); +}; diff --git a/wifi/1.4/IWifiRttControllerEventCallback.hal b/wifi/1.4/IWifiRttControllerEventCallback.hal new file mode 100644 index 0000000000..75de3d43d3 --- /dev/null +++ b/wifi/1.4/IWifiRttControllerEventCallback.hal @@ -0,0 +1,33 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.wifi@1.4; + +import @1.0::IWifiRttControllerEventCallback; +import @1.0::CommandId; + +/** + * RTT Response and Event Callbacks. + */ +interface IWifiRttControllerEventCallback extends @1.0::IWifiRttControllerEventCallback { + /* + * Invoked when an RTT result is available. + * + * @param cmdId command Id corresponding to the original request. + * @param results Vector of |RttResult| instances. + */ + oneway onResults_1_4(CommandId cmdId, vec results); +}; diff --git a/wifi/1.4/default/hidl_struct_util.cpp b/wifi/1.4/default/hidl_struct_util.cpp index 47713cde22..61f311ec24 100644 --- a/wifi/1.4/default/hidl_struct_util.cpp +++ b/wifi/1.4/default/hidl_struct_util.cpp @@ -2279,6 +2279,8 @@ legacy_hal::wifi_rtt_preamble convertHidlRttPreambleToLegacy(RttPreamble type) { return legacy_hal::WIFI_RTT_PREAMBLE_HT; case RttPreamble::VHT: return legacy_hal::WIFI_RTT_PREAMBLE_VHT; + case RttPreamble::HE: + return legacy_hal::WIFI_RTT_PREAMBLE_HE; }; CHECK(false); } @@ -2291,6 +2293,8 @@ RttPreamble convertLegacyRttPreambleToHidl(legacy_hal::wifi_rtt_preamble type) { return RttPreamble::HT; case legacy_hal::WIFI_RTT_PREAMBLE_VHT: return RttPreamble::VHT; + case legacy_hal::WIFI_RTT_PREAMBLE_HE: + return RttPreamble::HE; }; CHECK(false) << "Unknown legacy type: " << type; } @@ -2354,6 +2358,8 @@ WifiRatePreamble convertLegacyWifiRatePreambleToHidl(uint8_t preamble) { return WifiRatePreamble::HT; case 3: return WifiRatePreamble::VHT; + case 4: + return WifiRatePreamble::HE; default: return WifiRatePreamble::RESERVED; }; @@ -2579,9 +2585,10 @@ bool convertLegacyRttCapabilitiesToHidl( hidl_capabilities->responderSupported = legacy_capabilities.responder_supported; hidl_capabilities->preambleSupport = 0; - for (const auto flag : {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, - legacy_hal::WIFI_RTT_PREAMBLE_HT, - legacy_hal::WIFI_RTT_PREAMBLE_VHT}) { + 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}) { if (legacy_capabilities.preamble_support & flag) { hidl_capabilities->preambleSupport |= static_cast::type>( diff --git a/wifi/1.4/default/hidl_struct_util.h b/wifi/1.4/default/hidl_struct_util.h index c9f1c262d5..a99c1ac051 100644 --- a/wifi/1.4/default/hidl_struct_util.h +++ b/wifi/1.4/default/hidl_struct_util.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "wifi_legacy_hal.h" diff --git a/wifi/1.4/default/tests/wifi_chip_unit_tests.cpp b/wifi/1.4/default/tests/wifi_chip_unit_tests.cpp index b0357ba980..90e81e12c1 100644 --- a/wifi/1.4/default/tests/wifi_chip_unit_tests.cpp +++ b/wifi/1.4/default/tests/wifi_chip_unit_tests.cpp @@ -252,7 +252,7 @@ class WifiChipTest : public Test { bool createRttController() { bool success = false; - chip_->createRttController( + chip_->createRttController_1_4( NULL, [&success](const WifiStatus& status, const sp& rtt) { if (WifiStatusCode::SUCCESS == status.code) { @@ -750,7 +750,7 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, // Create RTT controller sp rtt_controller; - chip_->createRttController( + chip_->createRttController_1_4( NULL, [&rtt_controller](const WifiStatus& status, const sp& rtt) { if (WifiStatusCode::SUCCESS == status.code) { diff --git a/wifi/1.4/default/wifi_chip.cpp b/wifi/1.4/default/wifi_chip.cpp index 408096fdc0..7685ac61d9 100644 --- a/wifi/1.4/default/wifi_chip.cpp +++ b/wifi/1.4/default/wifi_chip.cpp @@ -620,6 +620,14 @@ Return WifiChip::debug(const hidl_handle& handle, return Void(); } +Return WifiChip::createRttController_1_4( + const sp& bound_iface, + createRttController_1_4_cb hidl_status_cb) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, + &WifiChip::createRttControllerInternal_1_4, + hidl_status_cb, bound_iface); +} + void WifiChip::invalidateAndRemoveAllIfaces() { invalidateAndClearAll(ap_ifaces_); invalidateAndClearAll(nan_ifaces_); @@ -669,30 +677,6 @@ std::pair WifiChip::getCapabilitiesInternal() { return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; } -std::pair WifiChip::getCapabilitiesInternal_1_3() { - legacy_hal::wifi_error legacy_status; - uint32_t legacy_feature_set; - uint32_t legacy_logger_feature_set; - const auto ifname = getFirstActiveWlanIfaceName(); - std::tie(legacy_status, legacy_feature_set) = - legacy_hal_.lock()->getSupportedFeatureSet(ifname); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), 0}; - } - std::tie(legacy_status, legacy_logger_feature_set) = - legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - // some devices don't support querying logger feature set - legacy_logger_feature_set = 0; - } - uint32_t hidl_caps; - if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( - legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; -} - std::pair> WifiChip::getAvailableModesInternal() { return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; @@ -996,18 +980,10 @@ WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { return createWifiStatus(WifiStatusCode::SUCCESS); } -std::pair> -WifiChip::createRttControllerInternal(const sp& bound_iface) { - if (sta_ifaces_.size() == 0 && - !canCurrentModeSupportIfaceOfType(IfaceType::STA)) { - LOG(ERROR) << "createRttControllerInternal: Chip cannot support STAs " - "(and RTT by extension)"; - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; - } - sp rtt = new WifiRttController( - getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); - rtt_controllers_.emplace_back(rtt); - return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; +std::pair> +WifiChip::createRttControllerInternal(const sp& /*bound_iface*/) { + LOG(ERROR) << "createRttController is not supported on this HAL"; + return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; } std::pair> @@ -1158,6 +1134,45 @@ WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2( return createWifiStatusFromLegacyError(legacy_status); } +std::pair WifiChip::getCapabilitiesInternal_1_3() { + legacy_hal::wifi_error legacy_status; + uint32_t legacy_feature_set; + uint32_t legacy_logger_feature_set; + const auto ifname = getFirstActiveWlanIfaceName(); + std::tie(legacy_status, legacy_feature_set) = + legacy_hal_.lock()->getSupportedFeatureSet(ifname); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {createWifiStatusFromLegacyError(legacy_status), 0}; + } + std::tie(legacy_status, legacy_logger_feature_set) = + legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + // some devices don't support querying logger feature set + legacy_logger_feature_set = 0; + } + uint32_t hidl_caps; + if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( + legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { + return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; +} + +std::pair> +WifiChip::createRttControllerInternal_1_4(const sp& bound_iface) { + if (sta_ifaces_.size() == 0 && + !canCurrentModeSupportIfaceOfType(IfaceType::STA)) { + LOG(ERROR) + << "createRttControllerInternal_1_4: Chip cannot support STAs " + "(and RTT by extension)"; + return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + } + sp rtt = new WifiRttController( + getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); + rtt_controllers_.emplace_back(rtt); + return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; +} + WifiStatus WifiChip::handleChipConfiguration( /* NONNULL */ std::unique_lock* lock, ChipModeId mode_id) { diff --git a/wifi/1.4/default/wifi_chip.h b/wifi/1.4/default/wifi_chip.h index 0d7061c0e3..3bf18475ae 100644 --- a/wifi/1.4/default/wifi_chip.h +++ b/wifi/1.4/default/wifi_chip.h @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "hidl_callback_util.h" #include "ringbuffer.h" @@ -46,7 +47,7 @@ using namespace android::hardware::wifi::V1_0; * Since there is only a single chip instance used today, there is no * identifying handle information stored here. */ -class WifiChip : public V1_3::IWifiChip { +class WifiChip : public V1_4::IWifiChip { public: WifiChip( ChipId chip_id, @@ -152,6 +153,9 @@ class WifiChip : public V1_3::IWifiChip { getCapabilities_cb hidl_status_cb) override; Return debug(const hidl_handle& handle, const hidl_vec& options) override; + Return createRttController_1_4( + const sp& bound_iface, + createRttController_1_4_cb hidl_status_cb) override; private: void invalidateAndRemoveAllIfaces(); @@ -195,8 +199,8 @@ class WifiChip : public V1_3::IWifiChip { std::pair> getStaIfaceInternal( const std::string& ifname); WifiStatus removeStaIfaceInternal(const std::string& ifname); - std::pair> createRttControllerInternal( - const sp& bound_iface); + std::pair> + createRttControllerInternal(const sp& bound_iface); std::pair> getDebugRingBuffersStatusInternal(); WifiStatus startLoggingToDebugRingBufferInternal( @@ -217,6 +221,8 @@ class WifiChip : public V1_3::IWifiChip { const sp& event_callback); WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario); std::pair getCapabilitiesInternal_1_3(); + std::pair> + createRttControllerInternal_1_4(const sp& bound_iface); WifiStatus handleChipConfiguration( std::unique_lock* lock, ChipModeId mode_id); WifiStatus registerDebugRingBufferCallback(); diff --git a/wifi/1.4/default/wifi_rtt_controller.cpp b/wifi/1.4/default/wifi_rtt_controller.cpp index d50c7cf68a..594a11660f 100644 --- a/wifi/1.4/default/wifi_rtt_controller.cpp +++ b/wifi/1.4/default/wifi_rtt_controller.cpp @@ -58,7 +58,7 @@ Return WifiRttController::getBoundIface(getBoundIface_cb hidl_status_cb) { } Return WifiRttController::registerEventCallback( - const sp& callback, + const sp& callback, registerEventCallback_cb hidl_status_cb) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, @@ -67,7 +67,7 @@ Return WifiRttController::registerEventCallback( } Return WifiRttController::rangeRequest( - uint32_t cmd_id, const hidl_vec& rtt_configs, + uint32_t cmd_id, const hidl_vec& rtt_configs, rangeRequest_cb hidl_status_cb) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, @@ -115,7 +115,7 @@ Return WifiRttController::getResponderInfo( Return WifiRttController::enableResponder( uint32_t cmd_id, const WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, const RttResponder& info, + uint32_t max_duration_seconds, const V1_0::RttResponder& info, enableResponder_cb hidl_status_cb) { return validateAndCall( this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, @@ -130,49 +130,64 @@ Return WifiRttController::disableResponder( &WifiRttController::disableResponderInternal, hidl_status_cb, cmd_id); } +Return WifiRttController::registerEventCallback_1_4( + const sp& callback, + registerEventCallback_1_4_cb hidl_status_cb) { + return validateAndCall( + this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::registerEventCallbackInternal_1_4, hidl_status_cb, + callback); +} + +Return WifiRttController::rangeRequest_1_4( + uint32_t cmd_id, const hidl_vec& rtt_configs, + rangeRequest_1_4_cb hidl_status_cb) { + return validateAndCall(this, + WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::rangeRequestInternal_1_4, + hidl_status_cb, cmd_id, rtt_configs); +} + +Return WifiRttController::getCapabilities_1_4( + getCapabilities_1_4_cb hidl_status_cb) { + return validateAndCall( + this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::getCapabilitiesInternal_1_4, hidl_status_cb); +} + +Return WifiRttController::getResponderInfo_1_4( + getResponderInfo_1_4_cb hidl_status_cb) { + return validateAndCall( + this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::getResponderInfoInternal_1_4, hidl_status_cb); +} + +Return WifiRttController::enableResponder_1_4( + uint32_t cmd_id, const WifiChannelInfo& channel_hint, + uint32_t max_duration_seconds, const RttResponder& info, + enableResponder_1_4_cb hidl_status_cb) { + return validateAndCall( + this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::enableResponderInternal_1_4, hidl_status_cb, cmd_id, + channel_hint, max_duration_seconds, info); +} + std::pair> WifiRttController::getBoundIfaceInternal() { return {createWifiStatus(WifiStatusCode::SUCCESS), bound_iface_}; } WifiStatus WifiRttController::registerEventCallbackInternal( - const sp& callback) { - // TODO(b/31632518): remove the callback when the client is destroyed - event_callbacks_.emplace_back(callback); - return createWifiStatus(WifiStatusCode::SUCCESS); + const sp& /* callback */) { + // Deprecated support for this api + return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); } WifiStatus WifiRttController::rangeRequestInternal( - uint32_t cmd_id, const std::vector& rtt_configs) { - std::vector legacy_configs; - if (!hidl_struct_util::convertHidlVectorOfRttConfigToLegacy( - rtt_configs, &legacy_configs)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - android::wp weak_ptr_this(this); - const auto& on_results_callback = - [weak_ptr_this]( - legacy_hal::wifi_request_id id, - const std::vector& results) { - const auto shared_ptr_this = weak_ptr_this.promote(); - if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { - LOG(ERROR) << "Callback invoked on an invalid object"; - return; - } - std::vector hidl_results; - if (!hidl_struct_util::convertLegacyVectorOfRttResultToHidl( - results, &hidl_results)) { - LOG(ERROR) << "Failed to convert rtt results to HIDL structs"; - return; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - callback->onResults(id, hidl_results); - } - }; - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->startRttRangeRequest( - ifname_, cmd_id, legacy_configs, on_results_callback); - return createWifiStatusFromLegacyError(legacy_status); + uint32_t /* cmd_id */, + const std::vector& /* rtt_configs */) { + // Deprecated support for this api + return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); } WifiStatus WifiRttController::rangeCancelInternal( @@ -187,21 +202,10 @@ WifiStatus WifiRttController::rangeCancelInternal( return createWifiStatusFromLegacyError(legacy_status); } -std::pair +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_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - RttCapabilities hidl_caps; - if (!hidl_struct_util::convertLegacyRttCapabilitiesToHidl(legacy_caps, - &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; + // Deprecated support for this api + return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; } WifiStatus WifiRttController::setLciInternal(uint32_t cmd_id, @@ -228,8 +232,84 @@ WifiStatus WifiRttController::setLcrInternal(uint32_t cmd_id, return createWifiStatusFromLegacyError(legacy_status); } -std::pair +std::pair WifiRttController::getResponderInfoInternal() { + // Deprecated support for this api + return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; +} + +WifiStatus WifiRttController::enableResponderInternal( + uint32_t /* cmd_id */, const WifiChannelInfo& /* channel_hint */, + uint32_t /* max_duration_seconds */, const V1_0::RttResponder& /* info */) { + // Deprecated support for this api + return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED)}; +} + +WifiStatus WifiRttController::disableResponderInternal(uint32_t cmd_id) { + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->disableRttResponder(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +WifiStatus WifiRttController::registerEventCallbackInternal_1_4( + const sp& callback) { + // TODO(b/31632518): remove the callback when the client is destroyed + event_callbacks_.emplace_back(callback); + return createWifiStatus(WifiStatusCode::SUCCESS); +} + +WifiStatus WifiRttController::rangeRequestInternal_1_4( + uint32_t cmd_id, const std::vector& rtt_configs) { + std::vector legacy_configs; + if (!hidl_struct_util::convertHidlVectorOfRttConfigToLegacy( + rtt_configs, &legacy_configs)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + android::wp weak_ptr_this(this); + const auto& on_results_callback = + [weak_ptr_this]( + legacy_hal::wifi_request_id id, + const std::vector& results) { + const auto shared_ptr_this = weak_ptr_this.promote(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + std::vector hidl_results; + if (!hidl_struct_util::convertLegacyVectorOfRttResultToHidl( + results, &hidl_results)) { + LOG(ERROR) << "Failed to convert rtt results to HIDL structs"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + callback->onResults_1_4(id, hidl_results); + } + }; + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->startRttRangeRequest( + ifname_, cmd_id, legacy_configs, on_results_callback); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair +WifiRttController::getCapabilitiesInternal_1_4() { + legacy_hal::wifi_error legacy_status; + 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 {createWifiStatusFromLegacyError(legacy_status), {}}; + } + RttCapabilities hidl_caps; + if (!hidl_struct_util::convertLegacyRttCapabilitiesToHidl(legacy_caps, + &hidl_caps)) { + return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; + } + return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; +} + +std::pair +WifiRttController::getResponderInfoInternal_1_4() { legacy_hal::wifi_error legacy_status; legacy_hal::wifi_rtt_responder legacy_responder; std::tie(legacy_status, legacy_responder) = @@ -245,7 +325,7 @@ WifiRttController::getResponderInfoInternal() { return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_responder}; } -WifiStatus WifiRttController::enableResponderInternal( +WifiStatus WifiRttController::enableResponderInternal_1_4( uint32_t cmd_id, const WifiChannelInfo& channel_hint, uint32_t max_duration_seconds, const RttResponder& info) { legacy_hal::wifi_channel_info legacy_channel_info; @@ -264,12 +344,6 @@ WifiStatus WifiRttController::enableResponderInternal( legacy_responder); return createWifiStatusFromLegacyError(legacy_status); } - -WifiStatus WifiRttController::disableResponderInternal(uint32_t cmd_id) { - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->disableRttResponder(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} } // namespace implementation } // namespace V1_4 } // namespace wifi diff --git a/wifi/1.4/default/wifi_rtt_controller.h b/wifi/1.4/default/wifi_rtt_controller.h index 1415ff7ce6..1f125555d0 100644 --- a/wifi/1.4/default/wifi_rtt_controller.h +++ b/wifi/1.4/default/wifi_rtt_controller.h @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include #include "wifi_legacy_hal.h" @@ -33,7 +33,7 @@ namespace implementation { /** * HIDL interface object used to control all RTT operations. */ -class WifiRttController : public V1_0::IWifiRttController { +class WifiRttController : public V1_4::IWifiRttController { public: WifiRttController( const std::string& iface_name, const sp& bound_iface, @@ -47,10 +47,10 @@ class WifiRttController : public V1_0::IWifiRttController { // HIDL methods exposed. Return getBoundIface(getBoundIface_cb hidl_status_cb) override; Return registerEventCallback( - const sp& callback, + const sp& callback, registerEventCallback_cb hidl_status_cb) override; Return rangeRequest(uint32_t cmd_id, - const hidl_vec& rtt_configs, + const hidl_vec& rtt_configs, rangeRequest_cb hidl_status_cb) override; Return rangeCancel(uint32_t cmd_id, const hidl_vec>& addrs, @@ -64,29 +64,53 @@ class WifiRttController : public V1_0::IWifiRttController { Return enableResponder(uint32_t cmd_id, const WifiChannelInfo& channel_hint, uint32_t max_duration_seconds, - const RttResponder& info, + const V1_0::RttResponder& info, enableResponder_cb hidl_status_cb) override; Return disableResponder(uint32_t cmd_id, disableResponder_cb hidl_status_cb) override; + Return registerEventCallback_1_4( + const sp& callback, + registerEventCallback_1_4_cb hidl_status_cb) override; + Return rangeRequest_1_4(uint32_t cmd_id, + const hidl_vec& rtt_configs, + rangeRequest_1_4_cb hidl_status_cb) override; + Return getCapabilities_1_4( + getCapabilities_1_4_cb hidl_status_cb) override; + Return getResponderInfo_1_4( + getResponderInfo_1_4_cb hidl_status_cb) override; + Return enableResponder_1_4( + uint32_t cmd_id, const WifiChannelInfo& channel_hint, + uint32_t max_duration_seconds, const RttResponder& info, + enableResponder_1_4_cb hidl_status_cb) override; private: // Corresponding worker functions for the HIDL methods. std::pair> getBoundIfaceInternal(); WifiStatus registerEventCallbackInternal( - const sp& callback); - WifiStatus rangeRequestInternal(uint32_t cmd_id, - const std::vector& rtt_configs); + const sp& callback); + WifiStatus rangeRequestInternal( + uint32_t cmd_id, const std::vector& rtt_configs); WifiStatus rangeCancelInternal( uint32_t cmd_id, const std::vector>& addrs); - std::pair getCapabilitiesInternal(); + std::pair getCapabilitiesInternal(); WifiStatus setLciInternal(uint32_t cmd_id, const RttLciInformation& lci); WifiStatus setLcrInternal(uint32_t cmd_id, const RttLcrInformation& lcr); - std::pair getResponderInfoInternal(); + std::pair getResponderInfoInternal(); WifiStatus enableResponderInternal(uint32_t cmd_id, const WifiChannelInfo& channel_hint, uint32_t max_duration_seconds, - const RttResponder& info); + const V1_0::RttResponder& info); WifiStatus disableResponderInternal(uint32_t cmd_id); + WifiStatus registerEventCallbackInternal_1_4( + const sp& callback); + WifiStatus rangeRequestInternal_1_4( + uint32_t cmd_id, const std::vector& rtt_configs); + std::pair getCapabilitiesInternal_1_4(); + std::pair getResponderInfoInternal_1_4(); + WifiStatus enableResponderInternal_1_4(uint32_t cmd_id, + const WifiChannelInfo& channel_hint, + uint32_t max_duration_seconds, + const RttResponder& info); std::string ifname_; sp bound_iface_; diff --git a/wifi/1.4/default/wifi_status_util.h b/wifi/1.4/default/wifi_status_util.h index 41bcfaf741..3ff58f0c0a 100644 --- a/wifi/1.4/default/wifi_status_util.h +++ b/wifi/1.4/default/wifi_status_util.h @@ -17,7 +17,7 @@ #ifndef WIFI_STATUS_UTIL_H_ #define WIFI_STATUS_UTIL_H_ -#include +#include #include "wifi_legacy_hal.h" diff --git a/wifi/1.4/types.hal b/wifi/1.4/types.hal new file mode 100644 index 0000000000..232e26ff80 --- /dev/null +++ b/wifi/1.4/types.hal @@ -0,0 +1,380 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.wifi@1.4; + +import @1.0::MacAddress; +import @1.0::Rssi; +import @1.0::RttBw; +import @1.0::RttConfig; +import @1.0::RttPeerType; +import @1.0::RttPreamble; +import @1.0::RttStatus; +import @1.0::RttType; +import @1.0::TimeSpanInPs; +import @1.0::TimeStampInUs; +import @1.0::WifiChannelInfo; +import @1.0::WifiChannelWidthInMhz; +import @1.0::WifiInformationElement; +import @1.0::WifiRateNss; +import @1.0::WifiRatePreamble; + +/** + * Wifi Rate Preamble + */ +enum WifiRatePreamble : @1.0::WifiRatePreamble { + /** + * Preamble type for 11ax + */ + HE = 5, +}; + +/** + * RTT Measurement Preamble. + */ +enum RttPreamble : @1.0::RttPreamble { + /** + * Preamble type for 11ax + */ + HE = 0x8, +}; + +/** + * RTT configuration. + */ +struct RttConfig { + /** + * Peer device mac address. + */ + MacAddress addr; + + /** + * 1-sided or 2-sided RTT. + */ + RttType type; + + /** + * Optional - peer device hint (STA, P2P, AP). + */ + RttPeerType peer; + + /** + * Required for STA-AP mode, optional for P2P, NBD etc. + */ + WifiChannelInfo channel; + + /** + * 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). + */ + uint32_t burstPeriod; + + /** + * Total number of RTT bursts to be executed. It will be + * specified in the same way as the parameter "Number of + * Burst Exponent" found in the FTM frame format. It + * applies to both: 1-sided RTT and 2-sided RTT. Valid + * values are 0 to 15 as defined in 802.11mc std. + * 0 means single shot + * The implication of this parameter on the maximum + * 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) + */ + uint32_t numBurst; + + /** + * Num of frames per burst. + * Minimum value = 1, Maximum value = 31 + * For 2-sided this equals the number of FTM frames + * to be attempted in a single burst. This also + * equals the number of FTM frames that the + * initiator will request that the responder send + * in a single frame. + */ + uint32_t numFramesPerBurst; + + /** + * Number of retries for a failed RTT frame. + * Applies to 1-sided RTT only. Minimum value = 0, Maximum value = 3 + */ + uint32_t numRetriesPerRttFrame; + + /** + * Following fields are only valid for 2-side RTT. + * + * + * Maximum number of retries that the initiator can + * retry an FTMR frame. + * Minimum value = 0, Maximum value = 3 + */ + uint32_t numRetriesPerFtmr; + + /** + * Whether to request location civic info or not. + */ + bool mustRequestLci; + + /** + * Whether to request location civic records or not. + */ + bool 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 + * 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 + * request if responder overrides with larger value, + * the initiator will sent TMR_STOP to terminate RTT + * at the end of the burst_duration it requested. + */ + uint32_t burstDuration; + + /** + * RTT preamble to be used in the RTT frames. + */ + RttPreamble preamble; + + /** + * RTT BW to be used in the RTT frames. + */ + RttBw bw; +}; + +/** + * RTT Capabilities. + */ +struct RttCapabilities { + /** + * if 1-sided rtt data collection is supported. + */ + bool rttOneSidedSupported; + + /** + * if ftm rtt data collection is supported. + */ + bool rttFtmSupported; + + /** + * if initiator supports LCI request. Applies to 2-sided RTT. + */ + bool lciSupported; + + /** + * if initiator supports LCR request. Applies to 2-sided RTT. + */ + bool lcrSupported; + + /** + * if 11mc responder mode is supported. + */ + bool responderSupported; + + /** + * Bit mask indicates what preamble is supported by initiator. + * Combination of |RttPreamble| values. + */ + bitfield preambleSupport; + + /** + * Bit mask indicates what BW is supported by initiator. + * Combination of |RttBw| values. + */ + bitfield bwSupport; + + /** + * Draft 11mc spec version supported by chip. + * For instance, version 4.0 must be 40 and version 4.3 must be 43 etc. + */ + uint8_t mcVersion; +}; + +/** + * RTT Responder information + */ +struct RttResponder { + WifiChannelInfo channel; + + RttPreamble preamble; +}; + +/** + * Wifi rate info. + */ +struct WifiRateInfo { + /** + * Preamble used for RTT measurements. + */ + WifiRatePreamble preamble; + + /** + * Number of spatial streams. + */ + WifiRateNss nss; + + /** + * Bandwidth of channel. + */ + WifiChannelWidthInMhz bw; + + /** + * OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps. + * HT/VHT/HE it would be mcs index. + */ + uint8_t rateMcsIdx; + + /** + * Bitrate in units of 100 Kbps. + */ + uint32_t bitRateInKbps; +}; + +/** + * RTT results. + */ +struct RttResult { + /** + * Peer device mac address. + */ + MacAddress addr; + + /** + * Burst number in a multi-burst request. + */ + uint32_t burstNum; + + /** + * Total RTT measurement frames attempted. + */ + uint32_t measurementNumber; + + /** + * Total successful RTT measurement frames. + */ + uint32_t successNumber; + + /** + * Maximum number of "FTM frames per burst" supported by + * the responder STA. Applies to 2-sided 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 + * many frames as originally requested. + * - for multi-burst request, initiator will return + * failure right away. + */ + uint8_t numberPerBurstPeer; + + /** + * Ranging status. + */ + RttStatus status; + + /** + * When status == 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-31sec. + */ + uint8_t retryAfterDuration; + + /** + * RTT type. + */ + RttType type; + + /** + * Average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB. + */ + Rssi rssi; + + /** + * Rssi spread in 0.5 dB steps e.g. 5 implies 2.5 dB spread (optional). + */ + Rssi rssiSpread; + + /** + * 1-sided RTT: TX rate of RTT frame. + * 2-sided RTT: TX rate of initiator's Ack in response to FTM frame. + */ + WifiRateInfo txRate; + + /** + * 1-sided RTT: TX rate of Ack from other side. + * 2-sided RTT: TX rate of FTM frame coming from responder. + */ + WifiRateInfo rxRate; + + /** + * Round trip time in picoseconds + */ + TimeSpanInPs rtt; + + /** + * Rtt standard deviation in picoseconds. + */ + TimeSpanInPs rttSd; + + /** + * Difference between max and min rtt times recorded in picoseconds. + */ + TimeSpanInPs rttSpread; + + /** + * Distance in mm (optional). + */ + int32_t distanceInMm; + + /** + * Standard deviation in mm (optional). + */ + int32_t distanceSdInMm; + + /** + * Difference between max and min distance recorded in mm (optional). + */ + int32_t distanceSpreadInMm; + + /** + * Time of the measurement (in microseconds since boot). + */ + TimeStampInUs timeStampInUs; + + /** + * in ms, actual time taken by the FW to finish one burst + * measurement. Applies to 1-sided and 2-sided RTT. + */ + uint32_t burstDurationInMs; + + /** + * Number of bursts allowed by the responder. Applies + * to 2-sided RTT only. + */ + uint32_t negotiatedBurstNum; + + /** + * for 11mc only. + */ + WifiInformationElement lci; + + /** + * for 11mc only. + */ + WifiInformationElement lcr; +};