diff --git a/wifi/1.6/default/android.hardware.wifi@1.0-service-lazy.rc b/wifi/1.6/default/android.hardware.wifi@1.0-service-lazy.rc deleted file mode 100644 index ee8c818d90..0000000000 --- a/wifi/1.6/default/android.hardware.wifi@1.0-service-lazy.rc +++ /dev/null @@ -1,14 +0,0 @@ -service vendor.wifi_hal_legacy /vendor/bin/hw/android.hardware.wifi@1.0-service-lazy - interface android.hardware.wifi@1.0::IWifi default - interface android.hardware.wifi@1.1::IWifi default - interface android.hardware.wifi@1.2::IWifi default - interface android.hardware.wifi@1.3::IWifi default - interface android.hardware.wifi@1.4::IWifi default - interface android.hardware.wifi@1.5::IWifi default - interface android.hardware.wifi@1.6::IWifi default - oneshot - disabled - class hal - capabilities NET_ADMIN NET_RAW SYS_MODULE - user wifi - group wifi gps diff --git a/wifi/1.6/default/android.hardware.wifi@1.0-service.rc b/wifi/1.6/default/android.hardware.wifi@1.0-service.rc deleted file mode 100644 index 18f40d0bb5..0000000000 --- a/wifi/1.6/default/android.hardware.wifi@1.0-service.rc +++ /dev/null @@ -1,12 +0,0 @@ -service vendor.wifi_hal_legacy /vendor/bin/hw/android.hardware.wifi@1.0-service - interface android.hardware.wifi@1.0::IWifi default - interface android.hardware.wifi@1.1::IWifi default - interface android.hardware.wifi@1.2::IWifi default - interface android.hardware.wifi@1.3::IWifi default - interface android.hardware.wifi@1.4::IWifi default - interface android.hardware.wifi@1.5::IWifi default - interface android.hardware.wifi@1.6::IWifi default - class hal - capabilities NET_ADMIN NET_RAW SYS_MODULE - user wifi - group wifi gps diff --git a/wifi/1.6/default/android.hardware.wifi@1.0-service.xml b/wifi/1.6/default/android.hardware.wifi@1.0-service.xml deleted file mode 100644 index 771fbaaf42..0000000000 --- a/wifi/1.6/default/android.hardware.wifi@1.0-service.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.wifi - hwbinder - 1.6 - - IWifi - default - - - diff --git a/wifi/1.6/default/hidl_callback_util.h b/wifi/1.6/default/hidl_callback_util.h deleted file mode 100644 index aab0ae5393..0000000000 --- a/wifi/1.6/default/hidl_callback_util.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ - -#ifndef HIDL_CALLBACK_UTIL_H_ -#define HIDL_CALLBACK_UTIL_H_ - -#include - -#include -#include - -namespace { -// Type of callback invoked by the death handler. -using on_death_cb_function = std::function; - -// Private class used to keep track of death of individual -// callbacks stored in HidlCallbackHandler. -template -class HidlDeathHandler : public android::hardware::hidl_death_recipient { - public: - HidlDeathHandler(const on_death_cb_function& user_cb_function) - : cb_function_(user_cb_function) {} - ~HidlDeathHandler() = default; - - // Death notification for callbacks. - void serviceDied(uint64_t cookie, - const android::wp& /* who */) override { - cb_function_(cookie); - } - - private: - on_death_cb_function cb_function_; - - DISALLOW_COPY_AND_ASSIGN(HidlDeathHandler); -}; -} // namespace - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_callback_util { -template -// Provides a class to manage callbacks for the various HIDL interfaces and -// handle the death of the process hosting each callback. -class HidlCallbackHandler { - public: - HidlCallbackHandler() - : death_handler_(new HidlDeathHandler( - std::bind(&HidlCallbackHandler::onObjectDeath, this, std::placeholders::_1))) {} - ~HidlCallbackHandler() = default; - - bool addCallback(const sp& cb) { - // TODO(b/33818800): Can't compare proxies yet. So, use the cookie - // (callback proxy's raw pointer) to track the death of individual - // clients. - uint64_t cookie = reinterpret_cast(cb.get()); - for (const auto& s : cb_set_) { - if (interfacesEqual(cb, s)) { - LOG(ERROR) << "Duplicate death notification registration"; - return true; - } - } - if (!cb->linkToDeath(death_handler_, cookie)) { - LOG(ERROR) << "Failed to register death notification"; - return false; - } - cb_set_.insert(cb); - return true; - } - - const std::set>& getCallbacks() { return cb_set_; } - - // Death notification for callbacks. - void onObjectDeath(uint64_t cookie) { - CallbackType* cb = reinterpret_cast(cookie); - const auto& iter = cb_set_.find(cb); - if (iter == cb_set_.end()) { - LOG(ERROR) << "Unknown callback death notification received"; - return; - } - cb_set_.erase(iter); - LOG(DEBUG) << "Dead callback removed from list"; - } - - void invalidate() { - for (const sp& cb : cb_set_) { - if (!cb->unlinkToDeath(death_handler_)) { - LOG(ERROR) << "Failed to deregister death notification"; - } - } - cb_set_.clear(); - } - - private: - std::set> cb_set_; - sp> death_handler_; - - DISALLOW_COPY_AND_ASSIGN(HidlCallbackHandler); -}; - -} // namespace hidl_callback_util -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android -#endif // HIDL_CALLBACK_UTIL_H_ diff --git a/wifi/1.6/default/hidl_return_util.h b/wifi/1.6/default/hidl_return_util.h deleted file mode 100644 index a0efac2c57..0000000000 --- a/wifi/1.6/default/hidl_return_util.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef HIDL_RETURN_UTIL_H_ -#define HIDL_RETURN_UTIL_H_ - -#include "hidl_sync_util.h" -#include "wifi_status_util.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_return_util { -using namespace android::hardware::wifi::V1_0; - -/** - * These utility functions are used to invoke a method on the provided - * HIDL interface object. - * These functions checks if the provided HIDL interface object is valid. - * a) if valid, Invokes the corresponding internal implementation function of - * the HIDL method. It then invokes the HIDL continuation callback with - * the status and any returned values. - * b) if invalid, invokes the HIDL continuation callback with the - * provided error status and default values. - */ -// Use for HIDL methods which return only an instance of WifiStatus. -template -Return validateAndCall(ObjT* obj, WifiStatusCode status_code_if_invalid, WorkFuncT&& work, - const std::function& hidl_cb, - Args&&... args) { - const auto lock = hidl_sync_util::acquireGlobalLock(); - if (obj->isValid()) { - hidl_cb((obj->*work)(std::forward(args)...)); - } else { - hidl_cb(createWifiStatus(status_code_if_invalid)); - } - return Void(); -} - -// Use for HIDL methods which return only an instance of WifiStatus. -// This version passes the global lock acquired to the body of the method. -// Note: Only used by IWifi::stop() currently. -template -Return validateAndCallWithLock(ObjT* obj, WifiStatusCode status_code_if_invalid, - WorkFuncT&& work, - const std::function& hidl_cb, - Args&&... args) { - auto lock = hidl_sync_util::acquireGlobalLock(); - if (obj->isValid()) { - hidl_cb((obj->*work)(&lock, std::forward(args)...)); - } else { - hidl_cb(createWifiStatus(status_code_if_invalid)); - } - return Void(); -} - -// Use for HIDL methods which return instance of WifiStatus and a single return -// value. -template -Return validateAndCall(ObjT* obj, WifiStatusCode status_code_if_invalid, WorkFuncT&& work, - const std::function& hidl_cb, - Args&&... args) { - const auto lock = hidl_sync_util::acquireGlobalLock(); - if (obj->isValid()) { - const auto& ret_pair = (obj->*work)(std::forward(args)...); - const WifiStatus& status = std::get<0>(ret_pair); - const auto& ret_value = std::get<1>(ret_pair); - hidl_cb(status, ret_value); - } else { - hidl_cb(createWifiStatus(status_code_if_invalid), - typename std::remove_reference::type()); - } - return Void(); -} - -// Use for HIDL methods which return instance of WifiStatus and 2 return -// values. -template -Return validateAndCall( - ObjT* obj, WifiStatusCode status_code_if_invalid, WorkFuncT&& work, - const std::function& hidl_cb, Args&&... args) { - const auto lock = hidl_sync_util::acquireGlobalLock(); - if (obj->isValid()) { - const auto& ret_tuple = (obj->*work)(std::forward(args)...); - const WifiStatus& status = std::get<0>(ret_tuple); - const auto& ret_value1 = std::get<1>(ret_tuple); - const auto& ret_value2 = std::get<2>(ret_tuple); - hidl_cb(status, ret_value1, ret_value2); - } else { - hidl_cb(createWifiStatus(status_code_if_invalid), - typename std::remove_reference::type(), - typename std::remove_reference::type()); - } - return Void(); -} - -} // namespace hidl_return_util -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android -#endif // HIDL_RETURN_UTIL_H_ diff --git a/wifi/1.6/default/hidl_struct_util.cpp b/wifi/1.6/default/hidl_struct_util.cpp deleted file mode 100644 index 2112b260f3..0000000000 --- a/wifi/1.6/default/hidl_struct_util.cpp +++ /dev/null @@ -1,3007 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#include -#include - -#include "hidl_struct_util.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_struct_util { - -using V1_6::NanConfigRequestSupplemental; - -WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl(legacy_hal::wifi_channel_width type); - -hidl_string safeConvertChar(const char* str, size_t max_len) { - const char* c = str; - size_t size = 0; - while (*c && (unsigned char)*c < 128 && size < max_len) { - ++size; - ++c; - } - return hidl_string(str, size); -} - -IWifiChip::ChipCapabilityMask convertLegacyLoggerFeatureToHidlChipCapability(uint32_t feature) { - using HidlChipCaps = IWifiChip::ChipCapabilityMask; - switch (feature) { - case legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED: - return HidlChipCaps::DEBUG_MEMORY_FIRMWARE_DUMP; - case legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED: - return HidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP; - case legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED: - return HidlChipCaps::DEBUG_RING_BUFFER_CONNECT_EVENT; - case legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED: - return HidlChipCaps::DEBUG_RING_BUFFER_POWER_EVENT; - case legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED: - return HidlChipCaps::DEBUG_RING_BUFFER_WAKELOCK_EVENT; - }; - CHECK(false) << "Unknown legacy feature: " << feature; - return {}; -} - -IWifiStaIface::StaIfaceCapabilityMask convertLegacyLoggerFeatureToHidlStaIfaceCapability( - uint32_t feature) { - using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; - switch (feature) { - case legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED: - return HidlStaIfaceCaps::DEBUG_PACKET_FATE; - }; - CHECK(false) << "Unknown legacy feature: " << feature; - return {}; -} - -V1_5::IWifiChip::ChipCapabilityMask convertLegacyFeatureToHidlChipCapability(uint64_t feature) { - using HidlChipCaps = V1_5::IWifiChip::ChipCapabilityMask; - switch (feature) { - case WIFI_FEATURE_SET_TX_POWER_LIMIT: - return HidlChipCaps::SET_TX_POWER_LIMIT; - case WIFI_FEATURE_USE_BODY_HEAD_SAR: - return HidlChipCaps::USE_BODY_HEAD_SAR; - case WIFI_FEATURE_D2D_RTT: - return HidlChipCaps::D2D_RTT; - case WIFI_FEATURE_D2AP_RTT: - return HidlChipCaps::D2AP_RTT; - case WIFI_FEATURE_INFRA_60G: - return HidlChipCaps::WIGIG; - case WIFI_FEATURE_SET_LATENCY_MODE: - return HidlChipCaps::SET_LATENCY_MODE; - case WIFI_FEATURE_P2P_RAND_MAC: - return HidlChipCaps::P2P_RAND_MAC; - }; - CHECK(false) << "Unknown legacy feature: " << feature; - return {}; -} - -IWifiStaIface::StaIfaceCapabilityMask convertLegacyFeatureToHidlStaIfaceCapability( - uint64_t feature) { - using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; - switch (feature) { - case WIFI_FEATURE_GSCAN: - return HidlStaIfaceCaps::BACKGROUND_SCAN; - case WIFI_FEATURE_LINK_LAYER_STATS: - return HidlStaIfaceCaps::LINK_LAYER_STATS; - case WIFI_FEATURE_RSSI_MONITOR: - return HidlStaIfaceCaps::RSSI_MONITOR; - case WIFI_FEATURE_CONTROL_ROAMING: - return HidlStaIfaceCaps::CONTROL_ROAMING; - case WIFI_FEATURE_IE_WHITELIST: - return HidlStaIfaceCaps::PROBE_IE_WHITELIST; - case WIFI_FEATURE_SCAN_RAND: - return HidlStaIfaceCaps::SCAN_RAND; - case WIFI_FEATURE_INFRA_5G: - return HidlStaIfaceCaps::STA_5G; - case WIFI_FEATURE_HOTSPOT: - return HidlStaIfaceCaps::HOTSPOT; - case WIFI_FEATURE_PNO: - return HidlStaIfaceCaps::PNO; - case WIFI_FEATURE_TDLS: - return HidlStaIfaceCaps::TDLS; - case WIFI_FEATURE_TDLS_OFFCHANNEL: - return HidlStaIfaceCaps::TDLS_OFFCHANNEL; - case WIFI_FEATURE_CONFIG_NDO: - return HidlStaIfaceCaps::ND_OFFLOAD; - case WIFI_FEATURE_MKEEP_ALIVE: - return HidlStaIfaceCaps::KEEP_ALIVE; - }; - CHECK(false) << "Unknown legacy feature: " << feature; - return {}; -} - -bool convertLegacyFeaturesToHidlChipCapabilities(uint64_t legacy_feature_set, - uint32_t legacy_logger_feature_set, - uint32_t* hidl_caps) { - if (!hidl_caps) { - return false; - } - *hidl_caps = {}; - using HidlChipCaps = IWifiChip::ChipCapabilityMask; - for (const auto feature : {legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED, - legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED, - legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED, - legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED, - legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED}) { - if (feature & legacy_logger_feature_set) { - *hidl_caps |= convertLegacyLoggerFeatureToHidlChipCapability(feature); - } - } - std::vector features = {WIFI_FEATURE_SET_TX_POWER_LIMIT, - WIFI_FEATURE_USE_BODY_HEAD_SAR, - WIFI_FEATURE_D2D_RTT, - WIFI_FEATURE_D2AP_RTT, - WIFI_FEATURE_INFRA_60G, - WIFI_FEATURE_SET_LATENCY_MODE, - WIFI_FEATURE_P2P_RAND_MAC}; - for (const auto feature : features) { - if (feature & legacy_feature_set) { - *hidl_caps |= convertLegacyFeatureToHidlChipCapability(feature); - } - } - - // There are no flags for these 3 in the legacy feature set. Adding them to - // the set because all the current devices support it. - *hidl_caps |= HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA; - *hidl_caps |= HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS; - *hidl_caps |= HidlChipCaps::DEBUG_ERROR_ALERTS; - return true; -} - -WifiDebugRingBufferFlags convertLegacyDebugRingBufferFlagsToHidl(uint32_t flag) { - switch (flag) { - case WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES: - return WifiDebugRingBufferFlags::HAS_BINARY_ENTRIES; - case WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES: - return WifiDebugRingBufferFlags::HAS_ASCII_ENTRIES; - }; - CHECK(false) << "Unknown legacy flag: " << flag; - return {}; -} - -bool convertLegacyDebugRingBufferStatusToHidl( - const legacy_hal::wifi_ring_buffer_status& legacy_status, - WifiDebugRingBufferStatus* hidl_status) { - if (!hidl_status) { - return false; - } - *hidl_status = {}; - hidl_status->ringName = safeConvertChar(reinterpret_cast(legacy_status.name), - sizeof(legacy_status.name)); - hidl_status->flags = 0; - for (const auto flag : - {WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES, WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES}) { - if (flag & legacy_status.flags) { - hidl_status->flags |= static_cast::type>( - convertLegacyDebugRingBufferFlagsToHidl(flag)); - } - } - hidl_status->ringId = legacy_status.ring_id; - hidl_status->sizeInBytes = legacy_status.ring_buffer_byte_size; - // Calculate free size of the ring the buffer. We don't need to send the - // exact read/write pointers that were there in the legacy HAL interface. - if (legacy_status.written_bytes >= legacy_status.read_bytes) { - hidl_status->freeSizeInBytes = legacy_status.ring_buffer_byte_size - - (legacy_status.written_bytes - legacy_status.read_bytes); - } else { - hidl_status->freeSizeInBytes = legacy_status.read_bytes - legacy_status.written_bytes; - } - hidl_status->verboseLevel = legacy_status.verbose_level; - return true; -} - -bool convertLegacyVectorOfDebugRingBufferStatusToHidl( - const std::vector& legacy_status_vec, - std::vector* hidl_status_vec) { - if (!hidl_status_vec) { - return false; - } - *hidl_status_vec = {}; - for (const auto& legacy_status : legacy_status_vec) { - WifiDebugRingBufferStatus hidl_status; - if (!convertLegacyDebugRingBufferStatusToHidl(legacy_status, &hidl_status)) { - return false; - } - hidl_status_vec->push_back(hidl_status); - } - return true; -} - -bool convertLegacyWakeReasonStatsToHidl(const legacy_hal::WakeReasonStats& legacy_stats, - WifiDebugHostWakeReasonStats* hidl_stats) { - if (!hidl_stats) { - return false; - } - *hidl_stats = {}; - hidl_stats->totalCmdEventWakeCnt = legacy_stats.wake_reason_cnt.total_cmd_event_wake; - hidl_stats->cmdEventWakeCntPerType = legacy_stats.cmd_event_wake_cnt; - hidl_stats->totalDriverFwLocalWakeCnt = legacy_stats.wake_reason_cnt.total_driver_fw_local_wake; - hidl_stats->driverFwLocalWakeCntPerType = legacy_stats.driver_fw_local_wake_cnt; - hidl_stats->totalRxPacketWakeCnt = legacy_stats.wake_reason_cnt.total_rx_data_wake; - hidl_stats->rxPktWakeDetails.rxUnicastCnt = - legacy_stats.wake_reason_cnt.rx_wake_details.rx_unicast_cnt; - hidl_stats->rxPktWakeDetails.rxMulticastCnt = - legacy_stats.wake_reason_cnt.rx_wake_details.rx_multicast_cnt; - hidl_stats->rxPktWakeDetails.rxBroadcastCnt = - legacy_stats.wake_reason_cnt.rx_wake_details.rx_broadcast_cnt; - hidl_stats->rxMulticastPkWakeDetails.ipv4RxMulticastAddrCnt = - legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv4_rx_multicast_addr_cnt; - hidl_stats->rxMulticastPkWakeDetails.ipv6RxMulticastAddrCnt = - legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv6_rx_multicast_addr_cnt; - hidl_stats->rxMulticastPkWakeDetails.otherRxMulticastAddrCnt = - legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.other_rx_multicast_addr_cnt; - hidl_stats->rxIcmpPkWakeDetails.icmpPkt = - legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp_pkt; - hidl_stats->rxIcmpPkWakeDetails.icmp6Pkt = - legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_pkt; - hidl_stats->rxIcmpPkWakeDetails.icmp6Ra = - legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ra; - hidl_stats->rxIcmpPkWakeDetails.icmp6Na = - legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_na; - hidl_stats->rxIcmpPkWakeDetails.icmp6Ns = - legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ns; - return true; -} - -legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy( - V1_1::IWifiChip::TxPowerScenario hidl_scenario) { - switch (hidl_scenario) { - // This is the only supported scenario for V1_1 - case V1_1::IWifiChip::TxPowerScenario::VOICE_CALL: - return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; - }; - CHECK(false); -} - -legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy_1_2( - V1_2::IWifiChip::TxPowerScenario hidl_scenario) { - switch (hidl_scenario) { - // This is the only supported scenario for V1_1 - case V1_2::IWifiChip::TxPowerScenario::VOICE_CALL: - return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; - // Those are the supported scenarios for V1_2 - case V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF: - return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF; - case V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_ON: - return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON; - case V1_2::IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF: - return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF; - case V1_2::IWifiChip::TxPowerScenario::ON_BODY_CELL_ON: - return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON; - }; - CHECK(false); -} - -legacy_hal::wifi_latency_mode convertHidlLatencyModeToLegacy( - V1_3::IWifiChip::LatencyMode hidl_latency_mode) { - switch (hidl_latency_mode) { - case V1_3::IWifiChip::LatencyMode::NORMAL: - return legacy_hal::WIFI_LATENCY_MODE_NORMAL; - case V1_3::IWifiChip::LatencyMode::LOW: - return legacy_hal::WIFI_LATENCY_MODE_LOW; - } - CHECK(false); -} - -bool convertLegacyWifiMacInfoToHidl( - const legacy_hal::WifiMacInfo& legacy_mac_info, - V1_4::IWifiChipEventCallback::RadioModeInfo* hidl_radio_mode_info) { - if (!hidl_radio_mode_info) { - return false; - } - *hidl_radio_mode_info = {}; - - hidl_radio_mode_info->radioId = legacy_mac_info.wlan_mac_id; - // Convert from bitmask of bands in the legacy HAL to enum value in - // the HIDL interface. - if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && - legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND && - legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ_5GHZ_6GHZ; - } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && - legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_5GHZ_6GHZ; - } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_6GHZ; - } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND && - legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ_5GHZ; - } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ; - } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_5GHZ; - } else { - hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_UNSPECIFIED; - } - std::vector iface_info_vec; - for (const auto& legacy_iface_info : legacy_mac_info.iface_infos) { - V1_2::IWifiChipEventCallback::IfaceInfo iface_info; - iface_info.name = legacy_iface_info.name; - iface_info.channel = legacy_iface_info.channel; - iface_info_vec.push_back(iface_info); - } - hidl_radio_mode_info->ifaceInfos = iface_info_vec; - return true; -} - -uint32_t convertHidlWifiBandToLegacyMacBand(V1_5::WifiBand hidl_band) { - switch (hidl_band) { - case V1_5::WifiBand::BAND_24GHZ: - return legacy_hal::WLAN_MAC_2_4_BAND; - case V1_5::WifiBand::BAND_5GHZ: - case V1_5::WifiBand::BAND_5GHZ_DFS: - case V1_5::WifiBand::BAND_5GHZ_WITH_DFS: - return legacy_hal::WLAN_MAC_5_0_BAND; - case V1_5::WifiBand::BAND_24GHZ_5GHZ: - case V1_5::WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: - return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND); - case V1_5::WifiBand::BAND_6GHZ: - return legacy_hal::WLAN_MAC_6_0_BAND; - case V1_5::WifiBand::BAND_5GHZ_6GHZ: - return (legacy_hal::WLAN_MAC_5_0_BAND | legacy_hal::WLAN_MAC_6_0_BAND); - case V1_5::WifiBand::BAND_24GHZ_5GHZ_6GHZ: - case V1_5::WifiBand::BAND_24GHZ_5GHZ_WITH_DFS_6GHZ: - return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | - legacy_hal::WLAN_MAC_6_0_BAND); - case V1_5::WifiBand::BAND_60GHZ: - return legacy_hal::WLAN_MAC_60_0_BAND; - default: - return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | - legacy_hal::WLAN_MAC_6_0_BAND | legacy_hal::WLAN_MAC_60_0_BAND); - } -} - -V1_5::WifiBand convertLegacyMacBandToHidlWifiBand(uint32_t band) { - switch (band) { - case legacy_hal::WLAN_MAC_2_4_BAND: - return V1_5::WifiBand::BAND_24GHZ; - case legacy_hal::WLAN_MAC_5_0_BAND: - return V1_5::WifiBand::BAND_5GHZ; - case legacy_hal::WLAN_MAC_6_0_BAND: - return V1_5::WifiBand::BAND_6GHZ; - case legacy_hal::WLAN_MAC_60_0_BAND: - return V1_5::WifiBand::BAND_60GHZ; - default: - return V1_5::WifiBand::BAND_UNSPECIFIED; - } -} - -uint32_t convertHidlWifiIfaceModeToLegacy(uint32_t hidl_iface_mask) { - uint32_t legacy_iface_mask = 0; - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_STA) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_STA); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_SOFTAP) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_SOFTAP); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_P2P_CLIENT) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_P2P_GO) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_GO); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_NAN) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_NAN); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_TDLS) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_TDLS); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_MESH) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_MESH); - } - if (hidl_iface_mask & V1_5::WifiIfaceMode::IFACE_MODE_IBSS) { - legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_IBSS); - } - return legacy_iface_mask; -} - -uint32_t convertLegacyWifiInterfaceModeToHidl(uint32_t legacy_iface_mask) { - uint32_t hidl_iface_mask = 0; - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_STA)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_STA; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_SOFTAP)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_SOFTAP; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_P2P_CLIENT; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_GO)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_P2P_GO; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_NAN)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_NAN; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_TDLS)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_TDLS; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_MESH)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_MESH; - } - if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_IBSS)) { - hidl_iface_mask |= V1_5::WifiIfaceMode::IFACE_MODE_IBSS; - } - return hidl_iface_mask; -} - -uint32_t convertHidlUsableChannelFilterToLegacy(uint32_t hidl_filter_mask) { - uint32_t legacy_filter_mask = 0; - if (hidl_filter_mask & V1_5::IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE) { - legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE; - } - if (hidl_filter_mask & V1_5::IWifiChip::UsableChannelFilter::CONCURRENCY) { - legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY; - } - if (hidl_filter_mask & V1_6::IWifiChip::UsableChannelFilter::NAN_INSTANT_MODE) { - legacy_filter_mask |= WIFI_USABLE_CHANNEL_FILTER_NAN_INSTANT_MODE; - } - return legacy_filter_mask; -} - -bool convertLegacyWifiUsableChannelToHidl( - const legacy_hal::wifi_usable_channel& legacy_usable_channel, - V1_6::WifiUsableChannel* hidl_usable_channel) { - if (!hidl_usable_channel) { - return false; - } - *hidl_usable_channel = {}; - hidl_usable_channel->channel = legacy_usable_channel.freq; - hidl_usable_channel->channelBandwidth = - convertLegacyWifiChannelWidthToHidl(legacy_usable_channel.width); - hidl_usable_channel->ifaceModeMask = - convertLegacyWifiInterfaceModeToHidl(legacy_usable_channel.iface_mode_mask); - - return true; -} - -bool convertLegacyWifiUsableChannelsToHidl( - const std::vector& legacy_usable_channels, - std::vector* hidl_usable_channels) { - if (!hidl_usable_channels) { - return false; - } - *hidl_usable_channels = {}; - for (const auto& legacy_usable_channel : legacy_usable_channels) { - V1_6::WifiUsableChannel hidl_usable_channel; - if (!convertLegacyWifiUsableChannelToHidl(legacy_usable_channel, &hidl_usable_channel)) { - return false; - } - hidl_usable_channels->push_back(hidl_usable_channel); - } - return true; -} - -bool convertLegacyWifiMacInfosToHidl( - const std::vector& legacy_mac_infos, - std::vector* hidl_radio_mode_infos) { - if (!hidl_radio_mode_infos) { - return false; - } - *hidl_radio_mode_infos = {}; - - for (const auto& legacy_mac_info : legacy_mac_infos) { - V1_4::IWifiChipEventCallback::RadioModeInfo hidl_radio_mode_info; - if (!convertLegacyWifiMacInfoToHidl(legacy_mac_info, &hidl_radio_mode_info)) { - return false; - } - hidl_radio_mode_infos->push_back(hidl_radio_mode_info); - } - return true; -} - -bool convertLegacyFeaturesToHidlStaCapabilities(uint64_t legacy_feature_set, - uint32_t legacy_logger_feature_set, - uint32_t* hidl_caps) { - if (!hidl_caps) { - return false; - } - *hidl_caps = {}; - using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; - for (const auto feature : {legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED}) { - if (feature & legacy_logger_feature_set) { - *hidl_caps |= convertLegacyLoggerFeatureToHidlStaIfaceCapability(feature); - } - } - for (const auto feature : - {WIFI_FEATURE_GSCAN, WIFI_FEATURE_LINK_LAYER_STATS, WIFI_FEATURE_RSSI_MONITOR, - WIFI_FEATURE_CONTROL_ROAMING, WIFI_FEATURE_IE_WHITELIST, WIFI_FEATURE_SCAN_RAND, - WIFI_FEATURE_INFRA_5G, WIFI_FEATURE_HOTSPOT, WIFI_FEATURE_PNO, WIFI_FEATURE_TDLS, - WIFI_FEATURE_TDLS_OFFCHANNEL, WIFI_FEATURE_CONFIG_NDO, WIFI_FEATURE_MKEEP_ALIVE}) { - if (feature & legacy_feature_set) { - *hidl_caps |= convertLegacyFeatureToHidlStaIfaceCapability(feature); - } - } - // There is no flag for this one in the legacy feature set. Adding it to the - // set because all the current devices support it. - *hidl_caps |= HidlStaIfaceCaps::APF; - return true; -} - -bool convertLegacyApfCapabilitiesToHidl(const legacy_hal::PacketFilterCapabilities& legacy_caps, - StaApfPacketFilterCapabilities* hidl_caps) { - if (!hidl_caps) { - return false; - } - *hidl_caps = {}; - hidl_caps->version = legacy_caps.version; - hidl_caps->maxLength = legacy_caps.max_len; - return true; -} - -uint8_t convertHidlGscanReportEventFlagToLegacy( - StaBackgroundScanBucketEventReportSchemeMask hidl_flag) { - using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; - switch (hidl_flag) { - case HidlFlag::EACH_SCAN: - return REPORT_EVENTS_EACH_SCAN; - case HidlFlag::FULL_RESULTS: - return REPORT_EVENTS_FULL_RESULTS; - case HidlFlag::NO_BATCH: - return REPORT_EVENTS_NO_BATCH; - }; - CHECK(false); -} - -StaScanDataFlagMask convertLegacyGscanDataFlagToHidl(uint8_t legacy_flag) { - switch (legacy_flag) { - case legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED: - return StaScanDataFlagMask::INTERRUPTED; - }; - CHECK(false) << "Unknown legacy flag: " << legacy_flag; - // To silence the compiler warning about reaching the end of non-void - // function. - return {}; -} - -bool convertLegacyGscanCapabilitiesToHidl(const legacy_hal::wifi_gscan_capabilities& legacy_caps, - StaBackgroundScanCapabilities* hidl_caps) { - if (!hidl_caps) { - return false; - } - *hidl_caps = {}; - hidl_caps->maxCacheSize = legacy_caps.max_scan_cache_size; - hidl_caps->maxBuckets = legacy_caps.max_scan_buckets; - hidl_caps->maxApCachePerScan = legacy_caps.max_ap_cache_per_scan; - hidl_caps->maxReportingThreshold = legacy_caps.max_scan_reporting_threshold; - return true; -} - -legacy_hal::wifi_band convertHidlWifiBandToLegacy(V1_0::WifiBand band) { - switch (band) { - case V1_0::WifiBand::BAND_UNSPECIFIED: - return legacy_hal::WIFI_BAND_UNSPECIFIED; - case V1_0::WifiBand::BAND_24GHZ: - return legacy_hal::WIFI_BAND_BG; - case V1_0::WifiBand::BAND_5GHZ: - return legacy_hal::WIFI_BAND_A; - case V1_0::WifiBand::BAND_5GHZ_DFS: - return legacy_hal::WIFI_BAND_A_DFS; - case V1_0::WifiBand::BAND_5GHZ_WITH_DFS: - return legacy_hal::WIFI_BAND_A_WITH_DFS; - case V1_0::WifiBand::BAND_24GHZ_5GHZ: - return legacy_hal::WIFI_BAND_ABG; - case V1_0::WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: - return legacy_hal::WIFI_BAND_ABG_WITH_DFS; - }; - CHECK(false); -} - -bool convertHidlGscanParamsToLegacy(const StaBackgroundScanParameters& hidl_scan_params, - legacy_hal::wifi_scan_cmd_params* legacy_scan_params) { - if (!legacy_scan_params) { - return false; - } - *legacy_scan_params = {}; - legacy_scan_params->base_period = hidl_scan_params.basePeriodInMs; - legacy_scan_params->max_ap_per_scan = hidl_scan_params.maxApPerScan; - legacy_scan_params->report_threshold_percent = hidl_scan_params.reportThresholdPercent; - legacy_scan_params->report_threshold_num_scans = hidl_scan_params.reportThresholdNumScans; - if (hidl_scan_params.buckets.size() > MAX_BUCKETS) { - return false; - } - legacy_scan_params->num_buckets = hidl_scan_params.buckets.size(); - for (uint32_t bucket_idx = 0; bucket_idx < hidl_scan_params.buckets.size(); bucket_idx++) { - const StaBackgroundScanBucketParameters& hidl_bucket_spec = - hidl_scan_params.buckets[bucket_idx]; - legacy_hal::wifi_scan_bucket_spec& legacy_bucket_spec = - legacy_scan_params->buckets[bucket_idx]; - if (hidl_bucket_spec.bucketIdx >= MAX_BUCKETS) { - return false; - } - legacy_bucket_spec.bucket = hidl_bucket_spec.bucketIdx; - legacy_bucket_spec.band = convertHidlWifiBandToLegacy(hidl_bucket_spec.band); - legacy_bucket_spec.period = hidl_bucket_spec.periodInMs; - legacy_bucket_spec.max_period = hidl_bucket_spec.exponentialMaxPeriodInMs; - legacy_bucket_spec.base = hidl_bucket_spec.exponentialBase; - legacy_bucket_spec.step_count = hidl_bucket_spec.exponentialStepCount; - legacy_bucket_spec.report_events = 0; - using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; - for (const auto flag : {HidlFlag::EACH_SCAN, HidlFlag::FULL_RESULTS, HidlFlag::NO_BATCH}) { - if (hidl_bucket_spec.eventReportScheme & - static_cast::type>(flag)) { - legacy_bucket_spec.report_events |= convertHidlGscanReportEventFlagToLegacy(flag); - } - } - if (hidl_bucket_spec.frequencies.size() > MAX_CHANNELS) { - return false; - } - legacy_bucket_spec.num_channels = hidl_bucket_spec.frequencies.size(); - for (uint32_t freq_idx = 0; freq_idx < hidl_bucket_spec.frequencies.size(); freq_idx++) { - legacy_bucket_spec.channels[freq_idx].channel = hidl_bucket_spec.frequencies[freq_idx]; - } - } - return true; -} - -bool convertLegacyIeToHidl(const legacy_hal::wifi_information_element& legacy_ie, - WifiInformationElement* hidl_ie) { - if (!hidl_ie) { - return false; - } - *hidl_ie = {}; - hidl_ie->id = legacy_ie.id; - hidl_ie->data = std::vector(legacy_ie.data, legacy_ie.data + legacy_ie.len); - return true; -} - -bool convertLegacyIeBlobToHidl(const uint8_t* ie_blob, uint32_t ie_blob_len, - std::vector* hidl_ies) { - if (!ie_blob || !hidl_ies) { - return false; - } - *hidl_ies = {}; - const uint8_t* ies_begin = ie_blob; - const uint8_t* ies_end = ie_blob + ie_blob_len; - const uint8_t* next_ie = ies_begin; - using wifi_ie = legacy_hal::wifi_information_element; - constexpr size_t kIeHeaderLen = sizeof(wifi_ie); - // Each IE should atleast have the header (i.e |id| & |len| fields). - while (next_ie + kIeHeaderLen <= ies_end) { - const wifi_ie& legacy_ie = (*reinterpret_cast(next_ie)); - uint32_t curr_ie_len = kIeHeaderLen + legacy_ie.len; - if (next_ie + curr_ie_len > ies_end) { - LOG(ERROR) << "Error parsing IE blob. Next IE: " << (void*)next_ie - << ", Curr IE len: " << curr_ie_len << ", IEs End: " << (void*)ies_end; - break; - } - WifiInformationElement hidl_ie; - if (!convertLegacyIeToHidl(legacy_ie, &hidl_ie)) { - LOG(ERROR) << "Error converting IE. Id: " << legacy_ie.id << ", len: " << legacy_ie.len; - break; - } - hidl_ies->push_back(std::move(hidl_ie)); - next_ie += curr_ie_len; - } - // Check if the blob has been fully consumed. - if (next_ie != ies_end) { - LOG(ERROR) << "Failed to fully parse IE blob. Next IE: " << (void*)next_ie - << ", IEs End: " << (void*)ies_end; - } - return true; -} - -bool convertLegacyGscanResultToHidl(const legacy_hal::wifi_scan_result& legacy_scan_result, - bool has_ie_data, StaScanResult* hidl_scan_result) { - if (!hidl_scan_result) { - return false; - } - *hidl_scan_result = {}; - hidl_scan_result->timeStampInUs = legacy_scan_result.ts; - hidl_scan_result->ssid = std::vector( - legacy_scan_result.ssid, - legacy_scan_result.ssid + - strnlen(legacy_scan_result.ssid, sizeof(legacy_scan_result.ssid) - 1)); - memcpy(hidl_scan_result->bssid.data(), legacy_scan_result.bssid, - hidl_scan_result->bssid.size()); - hidl_scan_result->frequency = legacy_scan_result.channel; - hidl_scan_result->rssi = legacy_scan_result.rssi; - hidl_scan_result->beaconPeriodInMs = legacy_scan_result.beacon_period; - hidl_scan_result->capability = legacy_scan_result.capability; - if (has_ie_data) { - std::vector ies; - if (!convertLegacyIeBlobToHidl(reinterpret_cast(legacy_scan_result.ie_data), - legacy_scan_result.ie_length, &ies)) { - return false; - } - hidl_scan_result->informationElements = std::move(ies); - } - return true; -} - -bool convertLegacyCachedGscanResultsToHidl( - const legacy_hal::wifi_cached_scan_results& legacy_cached_scan_result, - StaScanData* hidl_scan_data) { - if (!hidl_scan_data) { - return false; - } - *hidl_scan_data = {}; - hidl_scan_data->flags = 0; - for (const auto flag : {legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED}) { - if (legacy_cached_scan_result.flags & flag) { - hidl_scan_data->flags |= static_cast::type>( - convertLegacyGscanDataFlagToHidl(flag)); - } - } - hidl_scan_data->bucketsScanned = legacy_cached_scan_result.buckets_scanned; - - CHECK(legacy_cached_scan_result.num_results >= 0 && - legacy_cached_scan_result.num_results <= MAX_AP_CACHE_PER_SCAN); - std::vector hidl_scan_results; - for (int32_t result_idx = 0; result_idx < legacy_cached_scan_result.num_results; result_idx++) { - StaScanResult hidl_scan_result; - if (!convertLegacyGscanResultToHidl(legacy_cached_scan_result.results[result_idx], false, - &hidl_scan_result)) { - return false; - } - hidl_scan_results.push_back(hidl_scan_result); - } - hidl_scan_data->results = std::move(hidl_scan_results); - return true; -} - -bool convertLegacyVectorOfCachedGscanResultsToHidl( - const std::vector& legacy_cached_scan_results, - std::vector* hidl_scan_datas) { - if (!hidl_scan_datas) { - return false; - } - *hidl_scan_datas = {}; - for (const auto& legacy_cached_scan_result : legacy_cached_scan_results) { - StaScanData hidl_scan_data; - if (!convertLegacyCachedGscanResultsToHidl(legacy_cached_scan_result, &hidl_scan_data)) { - return false; - } - hidl_scan_datas->push_back(hidl_scan_data); - } - return true; -} - -WifiDebugTxPacketFate convertLegacyDebugTxPacketFateToHidl(legacy_hal::wifi_tx_packet_fate fate) { - switch (fate) { - case legacy_hal::TX_PKT_FATE_ACKED: - return WifiDebugTxPacketFate::ACKED; - case legacy_hal::TX_PKT_FATE_SENT: - return WifiDebugTxPacketFate::SENT; - case legacy_hal::TX_PKT_FATE_FW_QUEUED: - return WifiDebugTxPacketFate::FW_QUEUED; - case legacy_hal::TX_PKT_FATE_FW_DROP_INVALID: - return WifiDebugTxPacketFate::FW_DROP_INVALID; - case legacy_hal::TX_PKT_FATE_FW_DROP_NOBUFS: - return WifiDebugTxPacketFate::FW_DROP_NOBUFS; - case legacy_hal::TX_PKT_FATE_FW_DROP_OTHER: - return WifiDebugTxPacketFate::FW_DROP_OTHER; - case legacy_hal::TX_PKT_FATE_DRV_QUEUED: - return WifiDebugTxPacketFate::DRV_QUEUED; - case legacy_hal::TX_PKT_FATE_DRV_DROP_INVALID: - return WifiDebugTxPacketFate::DRV_DROP_INVALID; - case legacy_hal::TX_PKT_FATE_DRV_DROP_NOBUFS: - return WifiDebugTxPacketFate::DRV_DROP_NOBUFS; - case legacy_hal::TX_PKT_FATE_DRV_DROP_OTHER: - return WifiDebugTxPacketFate::DRV_DROP_OTHER; - }; - CHECK(false) << "Unknown legacy fate type: " << fate; -} - -WifiDebugRxPacketFate convertLegacyDebugRxPacketFateToHidl(legacy_hal::wifi_rx_packet_fate fate) { - switch (fate) { - case legacy_hal::RX_PKT_FATE_SUCCESS: - return WifiDebugRxPacketFate::SUCCESS; - case legacy_hal::RX_PKT_FATE_FW_QUEUED: - return WifiDebugRxPacketFate::FW_QUEUED; - case legacy_hal::RX_PKT_FATE_FW_DROP_FILTER: - return WifiDebugRxPacketFate::FW_DROP_FILTER; - case legacy_hal::RX_PKT_FATE_FW_DROP_INVALID: - return WifiDebugRxPacketFate::FW_DROP_INVALID; - case legacy_hal::RX_PKT_FATE_FW_DROP_NOBUFS: - return WifiDebugRxPacketFate::FW_DROP_NOBUFS; - case legacy_hal::RX_PKT_FATE_FW_DROP_OTHER: - return WifiDebugRxPacketFate::FW_DROP_OTHER; - case legacy_hal::RX_PKT_FATE_DRV_QUEUED: - return WifiDebugRxPacketFate::DRV_QUEUED; - case legacy_hal::RX_PKT_FATE_DRV_DROP_FILTER: - return WifiDebugRxPacketFate::DRV_DROP_FILTER; - case legacy_hal::RX_PKT_FATE_DRV_DROP_INVALID: - return WifiDebugRxPacketFate::DRV_DROP_INVALID; - case legacy_hal::RX_PKT_FATE_DRV_DROP_NOBUFS: - return WifiDebugRxPacketFate::DRV_DROP_NOBUFS; - case legacy_hal::RX_PKT_FATE_DRV_DROP_OTHER: - return WifiDebugRxPacketFate::DRV_DROP_OTHER; - }; - CHECK(false) << "Unknown legacy fate type: " << fate; -} - -WifiDebugPacketFateFrameType convertLegacyDebugPacketFateFrameTypeToHidl( - legacy_hal::frame_type type) { - switch (type) { - case legacy_hal::FRAME_TYPE_UNKNOWN: - return WifiDebugPacketFateFrameType::UNKNOWN; - case legacy_hal::FRAME_TYPE_ETHERNET_II: - return WifiDebugPacketFateFrameType::ETHERNET_II; - case legacy_hal::FRAME_TYPE_80211_MGMT: - return WifiDebugPacketFateFrameType::MGMT_80211; - }; - CHECK(false) << "Unknown legacy frame type: " << type; -} - -bool convertLegacyDebugPacketFateFrameToHidl(const legacy_hal::frame_info& legacy_frame, - WifiDebugPacketFateFrameInfo* hidl_frame) { - if (!hidl_frame) { - return false; - } - *hidl_frame = {}; - hidl_frame->frameType = convertLegacyDebugPacketFateFrameTypeToHidl(legacy_frame.payload_type); - hidl_frame->frameLen = legacy_frame.frame_len; - hidl_frame->driverTimestampUsec = legacy_frame.driver_timestamp_usec; - hidl_frame->firmwareTimestampUsec = legacy_frame.firmware_timestamp_usec; - const uint8_t* frame_begin = - reinterpret_cast(legacy_frame.frame_content.ethernet_ii_bytes); - hidl_frame->frameContent = - std::vector(frame_begin, frame_begin + legacy_frame.frame_len); - return true; -} - -bool convertLegacyDebugTxPacketFateToHidl(const legacy_hal::wifi_tx_report& legacy_fate, - WifiDebugTxPacketFateReport* hidl_fate) { - if (!hidl_fate) { - return false; - } - *hidl_fate = {}; - hidl_fate->fate = convertLegacyDebugTxPacketFateToHidl(legacy_fate.fate); - return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, &hidl_fate->frameInfo); -} - -bool convertLegacyVectorOfDebugTxPacketFateToHidl( - const std::vector& legacy_fates, - std::vector* hidl_fates) { - if (!hidl_fates) { - return false; - } - *hidl_fates = {}; - for (const auto& legacy_fate : legacy_fates) { - WifiDebugTxPacketFateReport hidl_fate; - if (!convertLegacyDebugTxPacketFateToHidl(legacy_fate, &hidl_fate)) { - return false; - } - hidl_fates->push_back(hidl_fate); - } - return true; -} - -bool convertLegacyDebugRxPacketFateToHidl(const legacy_hal::wifi_rx_report& legacy_fate, - WifiDebugRxPacketFateReport* hidl_fate) { - if (!hidl_fate) { - return false; - } - *hidl_fate = {}; - hidl_fate->fate = convertLegacyDebugRxPacketFateToHidl(legacy_fate.fate); - return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, &hidl_fate->frameInfo); -} - -bool convertLegacyVectorOfDebugRxPacketFateToHidl( - const std::vector& legacy_fates, - std::vector* hidl_fates) { - if (!hidl_fates) { - return false; - } - *hidl_fates = {}; - for (const auto& legacy_fate : legacy_fates) { - WifiDebugRxPacketFateReport hidl_fate; - if (!convertLegacyDebugRxPacketFateToHidl(legacy_fate, &hidl_fate)) { - return false; - } - hidl_fates->push_back(hidl_fate); - } - return true; -} - -bool convertLegacyLinkLayerRadioStatsToHidl( - const legacy_hal::LinkLayerRadioStats& legacy_radio_stat, - V1_6::StaLinkLayerRadioStats* hidl_radio_stat) { - if (!hidl_radio_stat) { - return false; - } - *hidl_radio_stat = {}; - - hidl_radio_stat->radioId = legacy_radio_stat.stats.radio; - hidl_radio_stat->V1_0.onTimeInMs = legacy_radio_stat.stats.on_time; - hidl_radio_stat->V1_0.txTimeInMs = legacy_radio_stat.stats.tx_time; - hidl_radio_stat->V1_0.rxTimeInMs = legacy_radio_stat.stats.rx_time; - hidl_radio_stat->V1_0.onTimeInMsForScan = legacy_radio_stat.stats.on_time_scan; - hidl_radio_stat->V1_0.txTimeInMsPerLevel = legacy_radio_stat.tx_time_per_levels; - hidl_radio_stat->onTimeInMsForNanScan = legacy_radio_stat.stats.on_time_nbd; - hidl_radio_stat->onTimeInMsForBgScan = legacy_radio_stat.stats.on_time_gscan; - hidl_radio_stat->onTimeInMsForRoamScan = legacy_radio_stat.stats.on_time_roam_scan; - hidl_radio_stat->onTimeInMsForPnoScan = legacy_radio_stat.stats.on_time_pno_scan; - hidl_radio_stat->onTimeInMsForHs20Scan = legacy_radio_stat.stats.on_time_hs20; - - std::vector hidl_channel_stats; - - for (const auto& channel_stat : legacy_radio_stat.channel_stats) { - V1_6::WifiChannelStats hidl_channel_stat; - hidl_channel_stat.onTimeInMs = channel_stat.on_time; - hidl_channel_stat.ccaBusyTimeInMs = channel_stat.cca_busy_time; - /* - * TODO once b/119142899 is fixed, - * replace below code with convertLegacyWifiChannelInfoToHidl() - */ - hidl_channel_stat.channel.width = WifiChannelWidthInMhz::WIDTH_20; - hidl_channel_stat.channel.centerFreq = channel_stat.channel.center_freq; - hidl_channel_stat.channel.centerFreq0 = channel_stat.channel.center_freq0; - hidl_channel_stat.channel.centerFreq1 = channel_stat.channel.center_freq1; - hidl_channel_stats.push_back(hidl_channel_stat); - } - - hidl_radio_stat->channelStats = hidl_channel_stats; - - return true; -} - -bool convertLegacyLinkLayerStatsToHidl(const legacy_hal::LinkLayerStats& legacy_stats, - V1_6::StaLinkLayerStats* hidl_stats) { - if (!hidl_stats) { - return false; - } - *hidl_stats = {}; - // iface legacy_stats conversion. - hidl_stats->iface.V1_0.beaconRx = legacy_stats.iface.beacon_rx; - hidl_stats->iface.V1_0.avgRssiMgmt = legacy_stats.iface.rssi_mgmt; - hidl_stats->iface.V1_0.wmeBePktStats.rxMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; - hidl_stats->iface.V1_0.wmeBePktStats.txMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; - hidl_stats->iface.V1_0.wmeBePktStats.lostMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; - hidl_stats->iface.V1_0.wmeBePktStats.retries = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries; - hidl_stats->iface.wmeBeContentionTimeStats.contentionTimeMinInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_min; - hidl_stats->iface.wmeBeContentionTimeStats.contentionTimeMaxInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_max; - hidl_stats->iface.wmeBeContentionTimeStats.contentionTimeAvgInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_avg; - hidl_stats->iface.wmeBeContentionTimeStats.contentionNumSamples = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_num_samples; - hidl_stats->iface.V1_0.wmeBkPktStats.rxMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; - hidl_stats->iface.V1_0.wmeBkPktStats.txMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; - hidl_stats->iface.V1_0.wmeBkPktStats.lostMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; - hidl_stats->iface.V1_0.wmeBkPktStats.retries = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries; - hidl_stats->iface.wmeBkContentionTimeStats.contentionTimeMinInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_min; - hidl_stats->iface.wmeBkContentionTimeStats.contentionTimeMaxInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_max; - hidl_stats->iface.wmeBkContentionTimeStats.contentionTimeAvgInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_avg; - hidl_stats->iface.wmeBkContentionTimeStats.contentionNumSamples = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_num_samples; - hidl_stats->iface.V1_0.wmeViPktStats.rxMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; - hidl_stats->iface.V1_0.wmeViPktStats.txMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; - hidl_stats->iface.V1_0.wmeViPktStats.lostMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; - hidl_stats->iface.V1_0.wmeViPktStats.retries = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries; - hidl_stats->iface.wmeViContentionTimeStats.contentionTimeMinInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_min; - hidl_stats->iface.wmeViContentionTimeStats.contentionTimeMaxInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_max; - hidl_stats->iface.wmeViContentionTimeStats.contentionTimeAvgInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_avg; - hidl_stats->iface.wmeViContentionTimeStats.contentionNumSamples = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_num_samples; - hidl_stats->iface.V1_0.wmeVoPktStats.rxMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; - hidl_stats->iface.V1_0.wmeVoPktStats.txMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; - hidl_stats->iface.V1_0.wmeVoPktStats.lostMpdu = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; - hidl_stats->iface.V1_0.wmeVoPktStats.retries = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries; - hidl_stats->iface.wmeVoContentionTimeStats.contentionTimeMinInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_min; - hidl_stats->iface.wmeVoContentionTimeStats.contentionTimeMaxInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_max; - hidl_stats->iface.wmeVoContentionTimeStats.contentionTimeAvgInUsec = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_avg; - hidl_stats->iface.wmeVoContentionTimeStats.contentionNumSamples = - legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_num_samples; - hidl_stats->iface.timeSliceDutyCycleInPercent = - legacy_stats.iface.info.time_slicing_duty_cycle_percent; - // peer info legacy_stats conversion. - std::vector hidl_peers_info_stats; - for (const auto& legacy_peer_info_stats : legacy_stats.peers) { - V1_6::StaPeerInfo hidl_peer_info_stats; - if (!convertLegacyPeerInfoStatsToHidl(legacy_peer_info_stats, &hidl_peer_info_stats)) { - return false; - } - hidl_peers_info_stats.push_back(hidl_peer_info_stats); - } - hidl_stats->iface.peers = hidl_peers_info_stats; - // radio legacy_stats conversion. - std::vector hidl_radios_stats; - for (const auto& legacy_radio_stats : legacy_stats.radios) { - V1_6::StaLinkLayerRadioStats hidl_radio_stats; - if (!convertLegacyLinkLayerRadioStatsToHidl(legacy_radio_stats, &hidl_radio_stats)) { - return false; - } - hidl_radios_stats.push_back(hidl_radio_stats); - } - hidl_stats->radios = hidl_radios_stats; - // Timestamp in the HAL wrapper here since it's not provided in the legacy - // HAL API. - hidl_stats->timeStampInMs = uptimeMillis(); - return true; -} - -bool convertLegacyPeerInfoStatsToHidl(const legacy_hal::WifiPeerInfo& legacy_peer_info_stats, - V1_6::StaPeerInfo* hidl_peer_info_stats) { - if (!hidl_peer_info_stats) { - return false; - } - *hidl_peer_info_stats = {}; - hidl_peer_info_stats->staCount = legacy_peer_info_stats.peer_info.bssload.sta_count; - hidl_peer_info_stats->chanUtil = legacy_peer_info_stats.peer_info.bssload.chan_util; - - std::vector hidlRateStats; - for (const auto& legacy_rate_stats : legacy_peer_info_stats.rate_stats) { - V1_6::StaRateStat rateStat; - if (!convertLegacyWifiRateInfoToHidl(legacy_rate_stats.rate, &rateStat.rateInfo)) { - return false; - } - rateStat.txMpdu = legacy_rate_stats.tx_mpdu; - rateStat.rxMpdu = legacy_rate_stats.rx_mpdu; - rateStat.mpduLost = legacy_rate_stats.mpdu_lost; - rateStat.retries = legacy_rate_stats.retries; - hidlRateStats.push_back(rateStat); - } - hidl_peer_info_stats->rateStats = hidlRateStats; - return true; -} - -bool convertLegacyRoamingCapabilitiesToHidl( - const legacy_hal::wifi_roaming_capabilities& legacy_caps, - StaRoamingCapabilities* hidl_caps) { - if (!hidl_caps) { - return false; - } - *hidl_caps = {}; - hidl_caps->maxBlacklistSize = legacy_caps.max_blacklist_size; - hidl_caps->maxWhitelistSize = legacy_caps.max_whitelist_size; - return true; -} - -bool convertHidlRoamingConfigToLegacy(const StaRoamingConfig& hidl_config, - legacy_hal::wifi_roaming_config* legacy_config) { - if (!legacy_config) { - return false; - } - *legacy_config = {}; - if (hidl_config.bssidBlacklist.size() > MAX_BLACKLIST_BSSID || - hidl_config.ssidWhitelist.size() > MAX_WHITELIST_SSID) { - return false; - } - legacy_config->num_blacklist_bssid = hidl_config.bssidBlacklist.size(); - uint32_t i = 0; - for (const auto& bssid : hidl_config.bssidBlacklist) { - CHECK(bssid.size() == sizeof(legacy_hal::mac_addr)); - memcpy(legacy_config->blacklist_bssid[i++], bssid.data(), bssid.size()); - } - legacy_config->num_whitelist_ssid = hidl_config.ssidWhitelist.size(); - i = 0; - for (const auto& ssid : hidl_config.ssidWhitelist) { - CHECK(ssid.size() <= sizeof(legacy_hal::ssid_t::ssid_str)); - legacy_config->whitelist_ssid[i].length = ssid.size(); - memcpy(legacy_config->whitelist_ssid[i].ssid_str, ssid.data(), ssid.size()); - i++; - } - return true; -} - -legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy(StaRoamingState state) { - switch (state) { - case StaRoamingState::ENABLED: - return legacy_hal::ROAMING_ENABLE; - case StaRoamingState::DISABLED: - return legacy_hal::ROAMING_DISABLE; - }; - CHECK(false); -} - -legacy_hal::NanMatchAlg convertHidlNanMatchAlgToLegacy(NanMatchAlg type) { - switch (type) { - case NanMatchAlg::MATCH_ONCE: - return legacy_hal::NAN_MATCH_ALG_MATCH_ONCE; - case NanMatchAlg::MATCH_CONTINUOUS: - return legacy_hal::NAN_MATCH_ALG_MATCH_CONTINUOUS; - case NanMatchAlg::MATCH_NEVER: - return legacy_hal::NAN_MATCH_ALG_MATCH_NEVER; - } - CHECK(false); -} - -legacy_hal::NanPublishType convertHidlNanPublishTypeToLegacy(NanPublishType type) { - switch (type) { - case NanPublishType::UNSOLICITED: - return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED; - case NanPublishType::SOLICITED: - return legacy_hal::NAN_PUBLISH_TYPE_SOLICITED; - case NanPublishType::UNSOLICITED_SOLICITED: - return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED; - } - CHECK(false); -} - -legacy_hal::NanTxType convertHidlNanTxTypeToLegacy(NanTxType type) { - switch (type) { - case NanTxType::BROADCAST: - return legacy_hal::NAN_TX_TYPE_BROADCAST; - case NanTxType::UNICAST: - return legacy_hal::NAN_TX_TYPE_UNICAST; - } - CHECK(false); -} - -legacy_hal::NanSubscribeType convertHidlNanSubscribeTypeToLegacy(NanSubscribeType type) { - switch (type) { - case NanSubscribeType::PASSIVE: - return legacy_hal::NAN_SUBSCRIBE_TYPE_PASSIVE; - case NanSubscribeType::ACTIVE: - return legacy_hal::NAN_SUBSCRIBE_TYPE_ACTIVE; - } - CHECK(false); -} - -legacy_hal::NanSRFType convertHidlNanSrfTypeToLegacy(NanSrfType type) { - switch (type) { - case NanSrfType::BLOOM_FILTER: - return legacy_hal::NAN_SRF_ATTR_BLOOM_FILTER; - case NanSrfType::PARTIAL_MAC_ADDR: - return legacy_hal::NAN_SRF_ATTR_PARTIAL_MAC_ADDR; - } - CHECK(false); -} - -legacy_hal::NanDataPathChannelCfg convertHidlNanDataPathChannelCfgToLegacy( - NanDataPathChannelCfg type) { - switch (type) { - case NanDataPathChannelCfg::CHANNEL_NOT_REQUESTED: - return legacy_hal::NAN_DP_CHANNEL_NOT_REQUESTED; - case NanDataPathChannelCfg::REQUEST_CHANNEL_SETUP: - return legacy_hal::NAN_DP_REQUEST_CHANNEL_SETUP; - case NanDataPathChannelCfg::FORCE_CHANNEL_SETUP: - return legacy_hal::NAN_DP_FORCE_CHANNEL_SETUP; - } - CHECK(false); -} - -NanStatusType convertLegacyNanStatusTypeToHidl(legacy_hal::NanStatusType type) { - switch (type) { - case legacy_hal::NAN_STATUS_SUCCESS: - return NanStatusType::SUCCESS; - case legacy_hal::NAN_STATUS_INTERNAL_FAILURE: - return NanStatusType::INTERNAL_FAILURE; - case legacy_hal::NAN_STATUS_PROTOCOL_FAILURE: - return NanStatusType::PROTOCOL_FAILURE; - case legacy_hal::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID: - return NanStatusType::INVALID_SESSION_ID; - case legacy_hal::NAN_STATUS_NO_RESOURCE_AVAILABLE: - return NanStatusType::NO_RESOURCES_AVAILABLE; - case legacy_hal::NAN_STATUS_INVALID_PARAM: - return NanStatusType::INVALID_ARGS; - case legacy_hal::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID: - return NanStatusType::INVALID_PEER_ID; - case legacy_hal::NAN_STATUS_INVALID_NDP_ID: - return NanStatusType::INVALID_NDP_ID; - case legacy_hal::NAN_STATUS_NAN_NOT_ALLOWED: - return NanStatusType::NAN_NOT_ALLOWED; - case legacy_hal::NAN_STATUS_NO_OTA_ACK: - return NanStatusType::NO_OTA_ACK; - case legacy_hal::NAN_STATUS_ALREADY_ENABLED: - return NanStatusType::ALREADY_ENABLED; - case legacy_hal::NAN_STATUS_FOLLOWUP_QUEUE_FULL: - return NanStatusType::FOLLOWUP_TX_QUEUE_FULL; - case legacy_hal::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED: - return NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED; - } - CHECK(false); -} - -void convertToWifiNanStatus(legacy_hal::NanStatusType type, const char* str, size_t max_len, - WifiNanStatus* wifiNanStatus) { - wifiNanStatus->status = convertLegacyNanStatusTypeToHidl(type); - wifiNanStatus->description = safeConvertChar(str, max_len); -} - -bool convertHidlNanEnableRequestToLegacy(const V1_4::NanEnableRequest& hidl_request, - legacy_hal::NanEnableRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: null legacy_request"; - return false; - } - *legacy_request = {}; - - legacy_request->config_2dot4g_support = 1; - legacy_request->support_2dot4g_val = - hidl_request.operateInBand[(size_t)NanBandIndex::NAN_BAND_24GHZ]; - legacy_request->config_support_5g = 1; - legacy_request->support_5g_val = - hidl_request.operateInBand[(size_t)NanBandIndex::NAN_BAND_5GHZ]; - legacy_request->config_hop_count_limit = 1; - legacy_request->hop_count_limit_val = hidl_request.hopCountMax; - legacy_request->master_pref = hidl_request.configParams.masterPref; - legacy_request->discovery_indication_cfg = 0; - legacy_request->discovery_indication_cfg |= - hidl_request.configParams.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; - legacy_request->discovery_indication_cfg |= - hidl_request.configParams.disableStartedClusterIndication ? 0x2 : 0x0; - legacy_request->discovery_indication_cfg |= - hidl_request.configParams.disableJoinedClusterIndication ? 0x4 : 0x0; - legacy_request->config_sid_beacon = 1; - if (hidl_request.configParams.numberOfPublishServiceIdsInBeacon > 127) { - LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " - "numberOfPublishServiceIdsInBeacon > 127"; - return false; - } - legacy_request->sid_beacon_val = - (hidl_request.configParams.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | - (hidl_request.configParams.numberOfPublishServiceIdsInBeacon << 1); - legacy_request->config_subscribe_sid_beacon = 1; - if (hidl_request.configParams.numberOfSubscribeServiceIdsInBeacon > 127) { - LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " - "numberOfSubscribeServiceIdsInBeacon > 127"; - return false; - } - legacy_request->subscribe_sid_beacon_val = - (hidl_request.configParams.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | - (hidl_request.configParams.numberOfSubscribeServiceIdsInBeacon << 1); - legacy_request->config_rssi_window_size = 1; - legacy_request->rssi_window_size_val = hidl_request.configParams.rssiWindowSize; - legacy_request->config_disc_mac_addr_randomization = 1; - legacy_request->disc_mac_addr_rand_interval_sec = - hidl_request.configParams.macAddressRandomizationIntervalSec; - legacy_request->config_2dot4g_rssi_close = 1; - if (hidl_request.configParams.bandSpecificConfig.size() != 3) { - LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " - "bandSpecificConfig.size() != 3"; - return false; - } - legacy_request->rssi_close_2dot4g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .rssiClose; - legacy_request->config_2dot4g_rssi_middle = 1; - legacy_request->rssi_middle_2dot4g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .rssiMiddle; - legacy_request->config_2dot4g_rssi_proximity = 1; - legacy_request->rssi_proximity_2dot4g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .rssiCloseProximity; - legacy_request->config_scan_params = 1; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .scanPeriodSec; - legacy_request->config_dw.config_2dot4g_dw_band = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .validDiscoveryWindowIntervalVal; - legacy_request->config_dw.dw_2dot4g_interval_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .discoveryWindowIntervalVal; - legacy_request->config_5g_rssi_close = 1; - legacy_request->rssi_close_5g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .rssiClose; - legacy_request->config_5g_rssi_middle = 1; - legacy_request->rssi_middle_5g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .rssiMiddle; - legacy_request->config_5g_rssi_close_proximity = 1; - legacy_request->rssi_close_proximity_5g_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .rssiCloseProximity; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .scanPeriodSec; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .scanPeriodSec; - legacy_request->config_dw.config_5g_dw_band = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .validDiscoveryWindowIntervalVal; - legacy_request->config_dw.dw_5g_interval_val = - hidl_request.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .discoveryWindowIntervalVal; - if (hidl_request.debugConfigs.validClusterIdVals) { - legacy_request->cluster_low = hidl_request.debugConfigs.clusterIdBottomRangeVal; - legacy_request->cluster_high = hidl_request.debugConfigs.clusterIdTopRangeVal; - } else { // need 'else' since not configurable in legacy HAL - legacy_request->cluster_low = 0x0000; - legacy_request->cluster_high = 0xFFFF; - } - legacy_request->config_intf_addr = hidl_request.debugConfigs.validIntfAddrVal; - memcpy(legacy_request->intf_addr_val, hidl_request.debugConfigs.intfAddrVal.data(), 6); - legacy_request->config_oui = hidl_request.debugConfigs.validOuiVal; - legacy_request->oui_val = hidl_request.debugConfigs.ouiVal; - legacy_request->config_random_factor_force = - hidl_request.debugConfigs.validRandomFactorForceVal; - legacy_request->random_factor_force_val = hidl_request.debugConfigs.randomFactorForceVal; - legacy_request->config_hop_count_force = hidl_request.debugConfigs.validHopCountForceVal; - legacy_request->hop_count_force_val = hidl_request.debugConfigs.hopCountForceVal; - legacy_request->config_24g_channel = hidl_request.debugConfigs.validDiscoveryChannelVal; - legacy_request->channel_24g_val = - hidl_request.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; - legacy_request->config_5g_channel = hidl_request.debugConfigs.validDiscoveryChannelVal; - legacy_request->channel_5g_val = - hidl_request.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; - legacy_request->config_2dot4g_beacons = hidl_request.debugConfigs.validUseBeaconsInBandVal; - legacy_request->beacon_2dot4g_val = - hidl_request.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; - legacy_request->config_5g_beacons = hidl_request.debugConfigs.validUseBeaconsInBandVal; - legacy_request->beacon_5g_val = - hidl_request.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; - legacy_request->config_2dot4g_sdf = hidl_request.debugConfigs.validUseSdfInBandVal; - legacy_request->sdf_2dot4g_val = - hidl_request.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; - legacy_request->config_5g_sdf = hidl_request.debugConfigs.validUseSdfInBandVal; - legacy_request->sdf_5g_val = - hidl_request.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; - - /* TODO: b/145609058 - * Missing updates needed to legacy_hal::NanEnableRequest and conversion to - * it for 6GHz band */ - - return true; -} - -bool convertHidlNanEnableRequest_1_6ToLegacy(const V1_4::NanEnableRequest& hidl_request1, - const NanConfigRequestSupplemental& hidl_request2, - legacy_hal::NanEnableRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanEnableRequest_1_6ToLegacy: null legacy_request"; - return false; - } - - *legacy_request = {}; - if (!convertHidlNanEnableRequestToLegacy(hidl_request1, legacy_request)) { - return false; - } - - legacy_request->config_discovery_beacon_int = 1; - legacy_request->discovery_beacon_interval = hidl_request2.V1_5.V1_2.discoveryBeaconIntervalMs; - legacy_request->config_nss = 1; - legacy_request->nss = hidl_request2.V1_5.V1_2.numberOfSpatialStreamsInDiscovery; - legacy_request->config_dw_early_termination = 1; - legacy_request->enable_dw_termination = - hidl_request2.V1_5.V1_2.enableDiscoveryWindowEarlyTermination; - legacy_request->config_enable_ranging = 1; - legacy_request->enable_ranging = hidl_request2.V1_5.V1_2.enableRanging; - - legacy_request->config_enable_instant_mode = 1; - legacy_request->enable_instant_mode = hidl_request2.V1_5.enableInstantCommunicationMode; - legacy_request->config_instant_mode_channel = 1; - legacy_request->instant_mode_channel = hidl_request2.instantModeChannel; - - return true; -} - -bool convertHidlNanConfigRequest_1_6ToLegacy(const V1_4::NanConfigRequest& hidl_request1, - const NanConfigRequestSupplemental& hidl_request2, - legacy_hal::NanConfigRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanConfigRequest_1_6ToLegacy: null legacy_request"; - return false; - } - - *legacy_request = {}; - if (!convertHidlNanConfigRequestToLegacy(hidl_request1, legacy_request)) { - return false; - } - - legacy_request->config_discovery_beacon_int = 1; - legacy_request->discovery_beacon_interval = hidl_request2.V1_5.V1_2.discoveryBeaconIntervalMs; - legacy_request->config_nss = 1; - legacy_request->nss = hidl_request2.V1_5.V1_2.numberOfSpatialStreamsInDiscovery; - legacy_request->config_dw_early_termination = 1; - legacy_request->enable_dw_termination = - hidl_request2.V1_5.V1_2.enableDiscoveryWindowEarlyTermination; - legacy_request->config_enable_ranging = 1; - legacy_request->enable_ranging = hidl_request2.V1_5.V1_2.enableRanging; - - legacy_request->config_enable_instant_mode = 1; - legacy_request->enable_instant_mode = hidl_request2.V1_5.enableInstantCommunicationMode; - legacy_request->config_instant_mode_channel = 1; - legacy_request->instant_mode_channel = hidl_request2.instantModeChannel; - - return true; -} - -bool convertHidlNanPublishRequestToLegacy(const V1_6::NanPublishRequest& hidl_request, - legacy_hal::NanPublishRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: null legacy_request"; - return false; - } - *legacy_request = {}; - - legacy_request->publish_id = hidl_request.baseConfigs.sessionId; - legacy_request->ttl = hidl_request.baseConfigs.ttlSec; - legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; - legacy_request->publish_count = hidl_request.baseConfigs.discoveryCount; - legacy_request->service_name_len = hidl_request.baseConfigs.serviceName.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: service_name_len " - "too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.baseConfigs.serviceName.data(), - legacy_request->service_name_len); - legacy_request->publish_match_indicator = - convertHidlNanMatchAlgToLegacy(hidl_request.baseConfigs.discoveryMatchIndicator); - legacy_request->service_specific_info_len = hidl_request.baseConfigs.serviceSpecificInfo.size(); - if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->service_specific_info, - hidl_request.baseConfigs.serviceSpecificInfo.data(), - legacy_request->service_specific_info_len); - legacy_request->sdea_service_specific_info_len = - hidl_request.baseConfigs.extendedServiceSpecificInfo.size(); - if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "sdea_service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->sdea_service_specific_info, - hidl_request.baseConfigs.extendedServiceSpecificInfo.data(), - legacy_request->sdea_service_specific_info_len); - legacy_request->rx_match_filter_len = hidl_request.baseConfigs.rxMatchFilter.size(); - if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "rx_match_filter_len too large"; - return false; - } - memcpy(legacy_request->rx_match_filter, hidl_request.baseConfigs.rxMatchFilter.data(), - legacy_request->rx_match_filter_len); - legacy_request->tx_match_filter_len = hidl_request.baseConfigs.txMatchFilter.size(); - if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "tx_match_filter_len too large"; - return false; - } - memcpy(legacy_request->tx_match_filter, hidl_request.baseConfigs.txMatchFilter.data(), - legacy_request->tx_match_filter_len); - legacy_request->rssi_threshold_flag = hidl_request.baseConfigs.useRssiThreshold; - legacy_request->recv_indication_cfg = 0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; - legacy_request->recv_indication_cfg |= 0x8; - legacy_request->cipher_type = (unsigned int)hidl_request.baseConfigs.securityConfig.cipherType; - - legacy_request->scid_len = hidl_request.baseConfigs.securityConfig.scid.size(); - if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: scid_len too large"; - return false; - } - memcpy(legacy_request->scid, hidl_request.baseConfigs.securityConfig.scid.data(), - legacy_request->scid_len); - - if (hidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = - hidl_request.baseConfigs.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, - hidl_request.baseConfigs.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.baseConfigs.securityConfig.securityType == - NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.baseConfigs.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.baseConfigs.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->sdea_params.security_cfg = - (hidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - - legacy_request->sdea_params.ranging_state = hidl_request.baseConfigs.rangingRequired - ? legacy_hal::NAN_RANGING_ENABLE - : legacy_hal::NAN_RANGING_DISABLE; - legacy_request->ranging_cfg.ranging_interval_msec = - hidl_request.baseConfigs.rangingIntervalMsec; - legacy_request->ranging_cfg.config_ranging_indications = - hidl_request.baseConfigs.configRangingIndications; - legacy_request->ranging_cfg.distance_ingress_mm = - hidl_request.baseConfigs.distanceIngressCm * 10; - legacy_request->ranging_cfg.distance_egress_mm = hidl_request.baseConfigs.distanceEgressCm * 10; - legacy_request->ranging_auto_response = hidl_request.baseConfigs.rangingRequired - ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE - : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; - legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; - legacy_request->publish_type = convertHidlNanPublishTypeToLegacy(hidl_request.publishType); - legacy_request->tx_type = convertHidlNanTxTypeToLegacy(hidl_request.txType); - legacy_request->service_responder_policy = hidl_request.autoAcceptDataPathRequests - ? legacy_hal::NAN_SERVICE_ACCEPT_POLICY_ALL - : legacy_hal::NAN_SERVICE_ACCEPT_POLICY_NONE; - - return true; -} - -bool convertHidlNanSubscribeRequestToLegacy(const V1_0::NanSubscribeRequest& hidl_request, - legacy_hal::NanSubscribeRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->subscribe_id = hidl_request.baseConfigs.sessionId; - legacy_request->ttl = hidl_request.baseConfigs.ttlSec; - legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; - legacy_request->subscribe_count = hidl_request.baseConfigs.discoveryCount; - legacy_request->service_name_len = hidl_request.baseConfigs.serviceName.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "service_name_len too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.baseConfigs.serviceName.data(), - legacy_request->service_name_len); - legacy_request->subscribe_match_indicator = - convertHidlNanMatchAlgToLegacy(hidl_request.baseConfigs.discoveryMatchIndicator); - legacy_request->service_specific_info_len = hidl_request.baseConfigs.serviceSpecificInfo.size(); - if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->service_specific_info, - hidl_request.baseConfigs.serviceSpecificInfo.data(), - legacy_request->service_specific_info_len); - legacy_request->sdea_service_specific_info_len = - hidl_request.baseConfigs.extendedServiceSpecificInfo.size(); - if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "sdea_service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->sdea_service_specific_info, - hidl_request.baseConfigs.extendedServiceSpecificInfo.data(), - legacy_request->sdea_service_specific_info_len); - legacy_request->rx_match_filter_len = hidl_request.baseConfigs.rxMatchFilter.size(); - if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "rx_match_filter_len too large"; - return false; - } - memcpy(legacy_request->rx_match_filter, hidl_request.baseConfigs.rxMatchFilter.data(), - legacy_request->rx_match_filter_len); - legacy_request->tx_match_filter_len = hidl_request.baseConfigs.txMatchFilter.size(); - if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "tx_match_filter_len too large"; - return false; - } - memcpy(legacy_request->tx_match_filter, hidl_request.baseConfigs.txMatchFilter.data(), - legacy_request->tx_match_filter_len); - legacy_request->rssi_threshold_flag = hidl_request.baseConfigs.useRssiThreshold; - legacy_request->recv_indication_cfg = 0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; - legacy_request->recv_indication_cfg |= - hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; - legacy_request->cipher_type = (unsigned int)hidl_request.baseConfigs.securityConfig.cipherType; - if (hidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = - hidl_request.baseConfigs.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, - hidl_request.baseConfigs.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.baseConfigs.securityConfig.securityType == - NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.baseConfigs.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.baseConfigs.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->sdea_params.security_cfg = - (hidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - legacy_request->sdea_params.ranging_state = hidl_request.baseConfigs.rangingRequired - ? legacy_hal::NAN_RANGING_ENABLE - : legacy_hal::NAN_RANGING_DISABLE; - legacy_request->ranging_cfg.ranging_interval_msec = - hidl_request.baseConfigs.rangingIntervalMsec; - legacy_request->ranging_cfg.config_ranging_indications = - hidl_request.baseConfigs.configRangingIndications; - legacy_request->ranging_cfg.distance_ingress_mm = - hidl_request.baseConfigs.distanceIngressCm * 10; - legacy_request->ranging_cfg.distance_egress_mm = hidl_request.baseConfigs.distanceEgressCm * 10; - legacy_request->ranging_auto_response = hidl_request.baseConfigs.rangingRequired - ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE - : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; - legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; - legacy_request->subscribe_type = - convertHidlNanSubscribeTypeToLegacy(hidl_request.subscribeType); - legacy_request->serviceResponseFilter = convertHidlNanSrfTypeToLegacy(hidl_request.srfType); - legacy_request->serviceResponseInclude = hidl_request.srfRespondIfInAddressSet - ? legacy_hal::NAN_SRF_INCLUDE_RESPOND - : legacy_hal::NAN_SRF_INCLUDE_DO_NOT_RESPOND; - legacy_request->useServiceResponseFilter = - hidl_request.shouldUseSrf ? legacy_hal::NAN_USE_SRF : legacy_hal::NAN_DO_NOT_USE_SRF; - legacy_request->ssiRequiredForMatchIndication = - hidl_request.isSsiRequiredForMatch ? legacy_hal::NAN_SSI_REQUIRED_IN_MATCH_IND - : legacy_hal::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND; - legacy_request->num_intf_addr_present = hidl_request.intfAddr.size(); - if (legacy_request->num_intf_addr_present > NAN_MAX_SUBSCRIBE_MAX_ADDRESS) { - LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " - "num_intf_addr_present - too many"; - return false; - } - for (int i = 0; i < legacy_request->num_intf_addr_present; i++) { - memcpy(legacy_request->intf_addr[i], hidl_request.intfAddr[i].data(), 6); - } - - return true; -} - -bool convertHidlNanTransmitFollowupRequestToLegacy( - const NanTransmitFollowupRequest& hidl_request, - legacy_hal::NanTransmitFollowupRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " - "legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->publish_subscribe_id = hidl_request.discoverySessionId; - legacy_request->requestor_instance_id = hidl_request.peerId; - memcpy(legacy_request->addr, hidl_request.addr.data(), 6); - legacy_request->priority = hidl_request.isHighPriority ? legacy_hal::NAN_TX_PRIORITY_HIGH - : legacy_hal::NAN_TX_PRIORITY_NORMAL; - legacy_request->dw_or_faw = hidl_request.shouldUseDiscoveryWindow - ? legacy_hal::NAN_TRANSMIT_IN_DW - : legacy_hal::NAN_TRANSMIT_IN_FAW; - legacy_request->service_specific_info_len = hidl_request.serviceSpecificInfo.size(); - if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " - "service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->service_specific_info, hidl_request.serviceSpecificInfo.data(), - legacy_request->service_specific_info_len); - legacy_request->sdea_service_specific_info_len = - hidl_request.extendedServiceSpecificInfo.size(); - if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { - LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " - "sdea_service_specific_info_len too large"; - return false; - } - memcpy(legacy_request->sdea_service_specific_info, - hidl_request.extendedServiceSpecificInfo.data(), - legacy_request->sdea_service_specific_info_len); - legacy_request->recv_indication_cfg = hidl_request.disableFollowupResultIndication ? 0x1 : 0x0; - - return true; -} - -bool convertHidlNanConfigRequestToLegacy(const V1_4::NanConfigRequest& hidl_request, - legacy_hal::NanConfigRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: legacy_request is null"; - return false; - } - *legacy_request = {}; - - // TODO: b/34059183 tracks missing configurations in legacy HAL or uknown - // defaults - legacy_request->master_pref = hidl_request.masterPref; - legacy_request->discovery_indication_cfg = 0; - legacy_request->discovery_indication_cfg |= - hidl_request.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; - legacy_request->discovery_indication_cfg |= - hidl_request.disableStartedClusterIndication ? 0x2 : 0x0; - legacy_request->discovery_indication_cfg |= - hidl_request.disableJoinedClusterIndication ? 0x4 : 0x0; - legacy_request->config_sid_beacon = 1; - if (hidl_request.numberOfPublishServiceIdsInBeacon > 127) { - LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: " - "numberOfPublishServiceIdsInBeacon > 127"; - return false; - } - legacy_request->sid_beacon = (hidl_request.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | - (hidl_request.numberOfPublishServiceIdsInBeacon << 1); - legacy_request->config_subscribe_sid_beacon = 1; - if (hidl_request.numberOfSubscribeServiceIdsInBeacon > 127) { - LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: " - "numberOfSubscribeServiceIdsInBeacon > 127"; - return false; - } - legacy_request->subscribe_sid_beacon_val = - (hidl_request.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | - (hidl_request.numberOfSubscribeServiceIdsInBeacon << 1); - legacy_request->config_rssi_window_size = 1; - legacy_request->rssi_window_size_val = hidl_request.rssiWindowSize; - legacy_request->config_disc_mac_addr_randomization = 1; - legacy_request->disc_mac_addr_rand_interval_sec = - hidl_request.macAddressRandomizationIntervalSec; - /* TODO : missing - legacy_request->config_2dot4g_rssi_close = 1; - legacy_request->rssi_close_2dot4g_val = - hidl_request.bandSpecificConfig[ - (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiClose; - legacy_request->config_2dot4g_rssi_middle = 1; - legacy_request->rssi_middle_2dot4g_val = - hidl_request.bandSpecificConfig[ - (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiMiddle; - legacy_request->config_2dot4g_rssi_proximity = 1; - legacy_request->rssi_proximity_2dot4g_val = - hidl_request.bandSpecificConfig[ - (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiCloseProximity; - */ - legacy_request->config_scan_params = 1; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].scanPeriodSec; - legacy_request->config_dw.config_2dot4g_dw_band = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .validDiscoveryWindowIntervalVal; - legacy_request->config_dw.dw_2dot4g_interval_val = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] - .discoveryWindowIntervalVal; - /* TODO: missing - legacy_request->config_5g_rssi_close = 1; - legacy_request->rssi_close_5g_val = - hidl_request.bandSpecificConfig[ - (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiClose; - legacy_request->config_5g_rssi_middle = 1; - legacy_request->rssi_middle_5g_val = - hidl_request.bandSpecificConfig[ - (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiMiddle; - */ - legacy_request->config_5g_rssi_close_proximity = 1; - legacy_request->rssi_close_proximity_5g_val = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].rssiCloseProximity; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; - legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; - legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; - legacy_request->config_dw.config_5g_dw_band = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .validDiscoveryWindowIntervalVal; - legacy_request->config_dw.dw_5g_interval_val = - hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] - .discoveryWindowIntervalVal; - /* TODO: b/145609058 - * Missing updates needed to legacy_hal::NanConfigRequest and conversion to - * it for 6GHz band */ - - return true; -} - -bool convertHidlNanDataPathInitiatorRequestToLegacy( - const V1_0::NanInitiateDataPathRequest& hidl_request, - legacy_hal::NanDataPathInitiatorRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->requestor_instance_id = hidl_request.peerId; - memcpy(legacy_request->peer_disc_mac_addr, hidl_request.peerDiscMacAddr.data(), 6); - legacy_request->channel_request_type = - convertHidlNanDataPathChannelCfgToLegacy(hidl_request.channelRequestType); - legacy_request->channel = hidl_request.channel; - if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "ifaceName too long"; - return false; - } - strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1); - legacy_request->ndp_cfg.security_cfg = - (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); - if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "ndp_app_info_len too large"; - return false; - } - memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), - legacy_request->app_info.ndp_app_info_len); - legacy_request->cipher_type = (unsigned int)hidl_request.securityConfig.cipherType; - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = hidl_request.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, hidl_request.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " - "service_name_len too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.serviceNameOutOfBand.data(), - legacy_request->service_name_len); - - return true; -} - -bool convertHidlNanDataPathInitiatorRequest_1_6ToLegacy( - const V1_6::NanInitiateDataPathRequest& hidl_request, - legacy_hal::NanDataPathInitiatorRequest* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->requestor_instance_id = hidl_request.peerId; - memcpy(legacy_request->peer_disc_mac_addr, hidl_request.peerDiscMacAddr.data(), 6); - legacy_request->channel_request_type = - convertHidlNanDataPathChannelCfgToLegacy(hidl_request.channelRequestType); - legacy_request->channel = hidl_request.channel; - if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "ifaceName too long"; - return false; - } - strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1); - legacy_request->ndp_cfg.security_cfg = - (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); - if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "ndp_app_info_len too large"; - return false; - } - memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), - legacy_request->app_info.ndp_app_info_len); - legacy_request->cipher_type = (unsigned int)hidl_request.securityConfig.cipherType; - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = hidl_request.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, hidl_request.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: " - "service_name_len too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.serviceNameOutOfBand.data(), - legacy_request->service_name_len); - legacy_request->scid_len = hidl_request.securityConfig.scid.size(); - if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { - LOG(ERROR) << "convertHidlNanDataPathInitiatorRequest_1_6ToLegacy: scid_len too large"; - return false; - } - memcpy(legacy_request->scid, hidl_request.securityConfig.scid.data(), legacy_request->scid_len); - - return true; -} - -bool convertHidlNanDataPathIndicationResponseToLegacy( - const V1_0::NanRespondToDataPathIndicationRequest& hidl_request, - legacy_hal::NanDataPathIndicationResponse* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->rsp_code = hidl_request.acceptRequest ? legacy_hal::NAN_DP_REQUEST_ACCEPT - : legacy_hal::NAN_DP_REQUEST_REJECT; - legacy_request->ndp_instance_id = hidl_request.ndpInstanceId; - if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "ifaceName too long"; - return false; - } - strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1); - legacy_request->ndp_cfg.security_cfg = - (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); - if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "ndp_app_info_len too large"; - return false; - } - memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), - legacy_request->app_info.ndp_app_info_len); - legacy_request->cipher_type = (unsigned int)hidl_request.securityConfig.cipherType; - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = hidl_request.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, hidl_request.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " - "service_name_len too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.serviceNameOutOfBand.data(), - legacy_request->service_name_len); - - return true; -} - -bool convertHidlNanDataPathIndicationResponse_1_6ToLegacy( - const V1_6::NanRespondToDataPathIndicationRequest& hidl_request, - legacy_hal::NanDataPathIndicationResponse* legacy_request) { - if (!legacy_request) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "legacy_request is null"; - return false; - } - *legacy_request = {}; - - legacy_request->rsp_code = hidl_request.acceptRequest ? legacy_hal::NAN_DP_REQUEST_ACCEPT - : legacy_hal::NAN_DP_REQUEST_REJECT; - legacy_request->ndp_instance_id = hidl_request.ndpInstanceId; - if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "ifaceName too long"; - return false; - } - strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1); - legacy_request->ndp_cfg.security_cfg = - (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) - ? legacy_hal::NAN_DP_CONFIG_SECURITY - : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; - legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); - if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "ndp_app_info_len too large"; - return false; - } - memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), - legacy_request->app_info.ndp_app_info_len); - legacy_request->cipher_type = (unsigned int)hidl_request.securityConfig.cipherType; - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; - legacy_request->key_info.body.pmk_info.pmk_len = hidl_request.securityConfig.pmk.size(); - if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "invalid pmk_len"; - return false; - } - memcpy(legacy_request->key_info.body.pmk_info.pmk, hidl_request.securityConfig.pmk.data(), - legacy_request->key_info.body.pmk_info.pmk_len); - } - if (hidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { - legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; - legacy_request->key_info.body.passphrase_info.passphrase_len = - hidl_request.securityConfig.passphrase.size(); - if (legacy_request->key_info.body.passphrase_info.passphrase_len < - NAN_SECURITY_MIN_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "passphrase_len too small"; - return false; - } - if (legacy_request->key_info.body.passphrase_info.passphrase_len > - NAN_SECURITY_MAX_PASSPHRASE_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "passphrase_len too large"; - return false; - } - memcpy(legacy_request->key_info.body.passphrase_info.passphrase, - hidl_request.securityConfig.passphrase.data(), - legacy_request->key_info.body.passphrase_info.passphrase_len); - } - legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); - if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: " - "service_name_len too large"; - return false; - } - memcpy(legacy_request->service_name, hidl_request.serviceNameOutOfBand.data(), - legacy_request->service_name_len); - legacy_request->scid_len = hidl_request.securityConfig.scid.size(); - if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { - LOG(ERROR) << "convertHidlNanDataPathIndicationResponse_1_6ToLegacy: scid_len too large"; - return false; - } - memcpy(legacy_request->scid, hidl_request.securityConfig.scid.data(), legacy_request->scid_len); - - return true; -} - -bool convertLegacyNanResponseHeaderToHidl(const legacy_hal::NanResponseMsg& legacy_response, - WifiNanStatus* wifiNanStatus) { - if (!wifiNanStatus) { - LOG(ERROR) << "convertLegacyNanResponseHeaderToHidl: wifiNanStatus is null"; - return false; - } - *wifiNanStatus = {}; - - convertToWifiNanStatus(legacy_response.status, legacy_response.nan_error, - sizeof(legacy_response.nan_error), wifiNanStatus); - return true; -} - -bool convertLegacyNanCapabilitiesResponseToHidl(const legacy_hal::NanCapabilities& legacy_response, - V1_6::NanCapabilities* hidl_response) { - if (!hidl_response) { - LOG(ERROR) << "convertLegacyNanCapabilitiesResponseToHidl: " - "hidl_response is null"; - return false; - } - *hidl_response = {}; - - hidl_response->maxConcurrentClusters = legacy_response.max_concurrent_nan_clusters; - hidl_response->maxPublishes = legacy_response.max_publishes; - hidl_response->maxSubscribes = legacy_response.max_subscribes; - hidl_response->maxServiceNameLen = legacy_response.max_service_name_len; - hidl_response->maxMatchFilterLen = legacy_response.max_match_filter_len; - hidl_response->maxTotalMatchFilterLen = legacy_response.max_total_match_filter_len; - hidl_response->maxServiceSpecificInfoLen = legacy_response.max_service_specific_info_len; - hidl_response->maxExtendedServiceSpecificInfoLen = - legacy_response.max_sdea_service_specific_info_len; - hidl_response->maxNdiInterfaces = legacy_response.max_ndi_interfaces; - hidl_response->maxNdpSessions = legacy_response.max_ndp_sessions; - hidl_response->maxAppInfoLen = legacy_response.max_app_info_len; - hidl_response->maxQueuedTransmitFollowupMsgs = - legacy_response.max_queued_transmit_followup_msgs; - hidl_response->maxSubscribeInterfaceAddresses = legacy_response.max_subscribe_address; - hidl_response->supportedCipherSuites = legacy_response.cipher_suites_supported; - hidl_response->instantCommunicationModeSupportFlag = legacy_response.is_instant_mode_supported; - - return true; -} - -bool convertLegacyNanMatchIndToHidl(const legacy_hal::NanMatchInd& legacy_ind, - V1_6::NanMatchInd* hidl_ind) { - if (!hidl_ind) { - LOG(ERROR) << "convertLegacyNanMatchIndToHidl: hidl_ind is null"; - return false; - } - *hidl_ind = {}; - - hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; - hidl_ind->peerId = legacy_ind.requestor_instance_id; - hidl_ind->addr = hidl_array(legacy_ind.addr); - hidl_ind->serviceSpecificInfo = std::vector( - legacy_ind.service_specific_info, - legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); - hidl_ind->extendedServiceSpecificInfo = std::vector( - legacy_ind.sdea_service_specific_info, - legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); - hidl_ind->matchFilter = - std::vector(legacy_ind.sdf_match_filter, - legacy_ind.sdf_match_filter + legacy_ind.sdf_match_filter_len); - hidl_ind->matchOccuredInBeaconFlag = legacy_ind.match_occured_flag == 1; - hidl_ind->outOfResourceFlag = legacy_ind.out_of_resource_flag == 1; - hidl_ind->rssiValue = legacy_ind.rssi_value; - hidl_ind->peerCipherType = (V1_6::NanCipherSuiteType)legacy_ind.peer_cipher_type; - hidl_ind->peerRequiresSecurityEnabledInNdp = - legacy_ind.peer_sdea_params.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; - hidl_ind->peerRequiresRanging = - legacy_ind.peer_sdea_params.ranging_state == legacy_hal::NAN_RANGING_ENABLE; - hidl_ind->rangingMeasurementInMm = legacy_ind.range_info.range_measurement_mm; - hidl_ind->rangingIndicationType = legacy_ind.range_info.ranging_event_type; - hidl_ind->scid = std::vector(legacy_ind.scid, legacy_ind.scid + legacy_ind.scid_len); - return true; -} - -bool convertLegacyNanFollowupIndToHidl(const legacy_hal::NanFollowupInd& legacy_ind, - NanFollowupReceivedInd* hidl_ind) { - if (!hidl_ind) { - LOG(ERROR) << "convertLegacyNanFollowupIndToHidl: hidl_ind is null"; - return false; - } - *hidl_ind = {}; - - hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; - hidl_ind->peerId = legacy_ind.requestor_instance_id; - hidl_ind->addr = hidl_array(legacy_ind.addr); - hidl_ind->receivedInFaw = legacy_ind.dw_or_faw == 1; - hidl_ind->serviceSpecificInfo = std::vector( - legacy_ind.service_specific_info, - legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); - hidl_ind->extendedServiceSpecificInfo = std::vector( - legacy_ind.sdea_service_specific_info, - legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); - - return true; -} - -bool convertLegacyNanDataPathRequestIndToHidl(const legacy_hal::NanDataPathRequestInd& legacy_ind, - NanDataPathRequestInd* hidl_ind) { - if (!hidl_ind) { - LOG(ERROR) << "convertLegacyNanDataPathRequestIndToHidl: hidl_ind is null"; - return false; - } - *hidl_ind = {}; - - hidl_ind->discoverySessionId = legacy_ind.service_instance_id; - hidl_ind->peerDiscMacAddr = hidl_array(legacy_ind.peer_disc_mac_addr); - hidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; - hidl_ind->securityRequired = - legacy_ind.ndp_cfg.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; - hidl_ind->appInfo = std::vector( - legacy_ind.app_info.ndp_app_info, - legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); - - return true; -} - -bool convertLegacyNdpChannelInfoToHidl(const legacy_hal::NanChannelInfo& legacy_struct, - V1_6::NanDataPathChannelInfo* hidl_struct) { - if (!hidl_struct) { - LOG(ERROR) << "convertLegacyNdpChannelInfoToHidl: hidl_struct is null"; - return false; - } - *hidl_struct = {}; - - hidl_struct->channelFreq = legacy_struct.channel; - hidl_struct->channelBandwidth = convertLegacyWifiChannelWidthToHidl( - (legacy_hal::wifi_channel_width)legacy_struct.bandwidth); - hidl_struct->numSpatialStreams = legacy_struct.nss; - - return true; -} - -bool convertLegacyNanDataPathConfirmIndToHidl(const legacy_hal::NanDataPathConfirmInd& legacy_ind, - V1_6::NanDataPathConfirmInd* hidl_ind) { - if (!hidl_ind) { - LOG(ERROR) << "convertLegacyNanDataPathConfirmIndToHidl: hidl_ind is null"; - return false; - } - *hidl_ind = {}; - - hidl_ind->V1_0.ndpInstanceId = legacy_ind.ndp_instance_id; - hidl_ind->V1_0.dataPathSetupSuccess = legacy_ind.rsp_code == legacy_hal::NAN_DP_REQUEST_ACCEPT; - hidl_ind->V1_0.peerNdiMacAddr = hidl_array(legacy_ind.peer_ndi_mac_addr); - hidl_ind->V1_0.appInfo = std::vector( - legacy_ind.app_info.ndp_app_info, - legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); - hidl_ind->V1_0.status.status = convertLegacyNanStatusTypeToHidl(legacy_ind.reason_code); - hidl_ind->V1_0.status.description = ""; // TODO: b/34059183 - - std::vector channelInfo; - for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { - V1_6::NanDataPathChannelInfo hidl_struct; - if (!convertLegacyNdpChannelInfoToHidl(legacy_ind.channel_info[i], &hidl_struct)) { - return false; - } - channelInfo.push_back(hidl_struct); - } - hidl_ind->channelInfo = channelInfo; - - return true; -} - -bool convertLegacyNanDataPathScheduleUpdateIndToHidl( - const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, - V1_6::NanDataPathScheduleUpdateInd* hidl_ind) { - if (!hidl_ind) { - LOG(ERROR) << "convertLegacyNanDataPathScheduleUpdateIndToHidl: " - "hidl_ind is null"; - return false; - } - *hidl_ind = {}; - - hidl_ind->peerDiscoveryAddress = hidl_array(legacy_ind.peer_mac_addr); - std::vector channelInfo; - for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { - V1_6::NanDataPathChannelInfo hidl_struct; - if (!convertLegacyNdpChannelInfoToHidl(legacy_ind.channel_info[i], &hidl_struct)) { - return false; - } - channelInfo.push_back(hidl_struct); - } - hidl_ind->channelInfo = channelInfo; - std::vector ndpInstanceIds; - for (unsigned int i = 0; i < legacy_ind.num_ndp_instances; ++i) { - ndpInstanceIds.push_back(legacy_ind.ndp_instance_id[i]); - } - hidl_ind->ndpInstanceIds = ndpInstanceIds; - - return true; -} - -legacy_hal::wifi_rtt_type convertHidlRttTypeToLegacy(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; - }; - CHECK(false); -} - -RttType convertLegacyRttTypeToHidl(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; - }; - CHECK(false) << "Unknown legacy type: " << type; -} - -legacy_hal::rtt_peer_type convertHidlRttPeerTypeToLegacy(RttPeerType type) { - switch (type) { - case RttPeerType::AP: - return legacy_hal::RTT_PEER_AP; - case RttPeerType::STA: - return legacy_hal::RTT_PEER_STA; - case RttPeerType::P2P_GO: - return legacy_hal::RTT_PEER_P2P_GO; - case RttPeerType::P2P_CLIENT: - return legacy_hal::RTT_PEER_P2P_CLIENT; - case RttPeerType::NAN: - return legacy_hal::RTT_PEER_NAN; - }; - CHECK(false); -} - -legacy_hal::wifi_channel_width convertHidlWifiChannelWidthToLegacy(WifiChannelWidthInMhz type) { - switch (type) { - case WifiChannelWidthInMhz::WIDTH_20: - return legacy_hal::WIFI_CHAN_WIDTH_20; - case WifiChannelWidthInMhz::WIDTH_40: - return legacy_hal::WIFI_CHAN_WIDTH_40; - case WifiChannelWidthInMhz::WIDTH_80: - return legacy_hal::WIFI_CHAN_WIDTH_80; - case WifiChannelWidthInMhz::WIDTH_160: - return legacy_hal::WIFI_CHAN_WIDTH_160; - case WifiChannelWidthInMhz::WIDTH_80P80: - return legacy_hal::WIFI_CHAN_WIDTH_80P80; - case WifiChannelWidthInMhz::WIDTH_5: - return legacy_hal::WIFI_CHAN_WIDTH_5; - case WifiChannelWidthInMhz::WIDTH_10: - return legacy_hal::WIFI_CHAN_WIDTH_10; - case V1_6::WifiChannelWidthInMhz::WIDTH_320: - return legacy_hal::WIFI_CHAN_WIDTH_320; - case WifiChannelWidthInMhz::WIDTH_INVALID: - return legacy_hal::WIFI_CHAN_WIDTH_INVALID; - }; - CHECK(false); -} - -V1_6::WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl( - legacy_hal::wifi_channel_width type) { - switch (type) { - case legacy_hal::WIFI_CHAN_WIDTH_20: - return WifiChannelWidthInMhz::WIDTH_20; - case legacy_hal::WIFI_CHAN_WIDTH_40: - return WifiChannelWidthInMhz::WIDTH_40; - case legacy_hal::WIFI_CHAN_WIDTH_80: - return WifiChannelWidthInMhz::WIDTH_80; - case legacy_hal::WIFI_CHAN_WIDTH_160: - return WifiChannelWidthInMhz::WIDTH_160; - case legacy_hal::WIFI_CHAN_WIDTH_80P80: - return WifiChannelWidthInMhz::WIDTH_80P80; - case legacy_hal::WIFI_CHAN_WIDTH_5: - return WifiChannelWidthInMhz::WIDTH_5; - case legacy_hal::WIFI_CHAN_WIDTH_10: - return WifiChannelWidthInMhz::WIDTH_10; - case legacy_hal::WIFI_CHAN_WIDTH_320: - return V1_6::WifiChannelWidthInMhz::WIDTH_320; - default: - return WifiChannelWidthInMhz::WIDTH_INVALID; - }; -} - -legacy_hal::wifi_rtt_preamble convertHidlRttPreambleToLegacy(V1_6::RttPreamble type) { - switch (type) { - case V1_6::RttPreamble::LEGACY: - return legacy_hal::WIFI_RTT_PREAMBLE_LEGACY; - case V1_6::RttPreamble::HT: - return legacy_hal::WIFI_RTT_PREAMBLE_HT; - case V1_6::RttPreamble::VHT: - return legacy_hal::WIFI_RTT_PREAMBLE_VHT; - case V1_6::RttPreamble::HE: - return legacy_hal::WIFI_RTT_PREAMBLE_HE; - case V1_6::RttPreamble::EHT: - return legacy_hal::WIFI_RTT_PREAMBLE_EHT; - }; - CHECK(false); -} - -V1_6::RttPreamble convertLegacyRttPreambleToHidl(legacy_hal::wifi_rtt_preamble type) { - switch (type) { - case legacy_hal::WIFI_RTT_PREAMBLE_LEGACY: - return V1_6::RttPreamble::LEGACY; - case legacy_hal::WIFI_RTT_PREAMBLE_HT: - return V1_6::RttPreamble::HT; - case legacy_hal::WIFI_RTT_PREAMBLE_VHT: - return V1_6::RttPreamble::VHT; - case legacy_hal::WIFI_RTT_PREAMBLE_HE: - return V1_6::RttPreamble::HE; - case legacy_hal::WIFI_RTT_PREAMBLE_EHT: - return V1_6::RttPreamble::EHT; - }; - CHECK(false) << "Unknown legacy type: " << type; -} - -legacy_hal::wifi_rtt_bw convertHidlRttBwToLegacy(RttBw type) { - switch (type) { - case RttBw::BW_5MHZ: - return legacy_hal::WIFI_RTT_BW_5; - case RttBw::BW_10MHZ: - return legacy_hal::WIFI_RTT_BW_10; - case RttBw::BW_20MHZ: - return legacy_hal::WIFI_RTT_BW_20; - case RttBw::BW_40MHZ: - return legacy_hal::WIFI_RTT_BW_40; - case RttBw::BW_80MHZ: - return legacy_hal::WIFI_RTT_BW_80; - case RttBw::BW_160MHZ: - return legacy_hal::WIFI_RTT_BW_160; - case RttBw::BW_320MHZ: - return legacy_hal::WIFI_RTT_BW_320; - }; - CHECK(false); -} - -RttBw convertLegacyRttBwToHidl(legacy_hal::wifi_rtt_bw type) { - switch (type) { - case legacy_hal::WIFI_RTT_BW_5: - return RttBw::BW_5MHZ; - case legacy_hal::WIFI_RTT_BW_10: - return RttBw::BW_10MHZ; - case legacy_hal::WIFI_RTT_BW_20: - return RttBw::BW_20MHZ; - case legacy_hal::WIFI_RTT_BW_40: - return RttBw::BW_40MHZ; - case legacy_hal::WIFI_RTT_BW_80: - return RttBw::BW_80MHZ; - case legacy_hal::WIFI_RTT_BW_160: - return RttBw::BW_160MHZ; - case legacy_hal::WIFI_RTT_BW_320: - return RttBw::BW_320MHZ; - }; - CHECK(false) << "Unknown legacy type: " << type; -} - -legacy_hal::wifi_motion_pattern convertHidlRttMotionPatternToLegacy(RttMotionPattern type) { - switch (type) { - case RttMotionPattern::NOT_EXPECTED: - return legacy_hal::WIFI_MOTION_NOT_EXPECTED; - case RttMotionPattern::EXPECTED: - return legacy_hal::WIFI_MOTION_EXPECTED; - case RttMotionPattern::UNKNOWN: - return legacy_hal::WIFI_MOTION_UNKNOWN; - }; - CHECK(false); -} - -V1_6::WifiRatePreamble convertLegacyWifiRatePreambleToHidl(uint8_t preamble) { - switch (preamble) { - case 0: - return V1_6::WifiRatePreamble::OFDM; - case 1: - return V1_6::WifiRatePreamble::CCK; - case 2: - return V1_6::WifiRatePreamble::HT; - case 3: - return V1_6::WifiRatePreamble::VHT; - case 4: - return V1_6::WifiRatePreamble::HE; - case 5: - return V1_6::WifiRatePreamble::EHT; - default: - return V1_6::WifiRatePreamble::RESERVED; - }; - CHECK(false) << "Unknown legacy preamble: " << preamble; -} - -WifiRateNss convertLegacyWifiRateNssToHidl(uint8_t nss) { - switch (nss) { - case 0: - return WifiRateNss::NSS_1x1; - case 1: - return WifiRateNss::NSS_2x2; - case 2: - return WifiRateNss::NSS_3x3; - case 3: - return WifiRateNss::NSS_4x4; - }; - CHECK(false) << "Unknown legacy nss: " << nss; - return {}; -} - -RttStatus convertLegacyRttStatusToHidl(legacy_hal::wifi_rtt_status status) { - switch (status) { - case legacy_hal::RTT_STATUS_SUCCESS: - return RttStatus::SUCCESS; - case legacy_hal::RTT_STATUS_FAILURE: - return RttStatus::FAILURE; - case legacy_hal::RTT_STATUS_FAIL_NO_RSP: - return RttStatus::FAIL_NO_RSP; - case legacy_hal::RTT_STATUS_FAIL_REJECTED: - return RttStatus::FAIL_REJECTED; - case legacy_hal::RTT_STATUS_FAIL_NOT_SCHEDULED_YET: - return RttStatus::FAIL_NOT_SCHEDULED_YET; - case legacy_hal::RTT_STATUS_FAIL_TM_TIMEOUT: - return RttStatus::FAIL_TM_TIMEOUT; - case legacy_hal::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL: - return RttStatus::FAIL_AP_ON_DIFF_CHANNEL; - case legacy_hal::RTT_STATUS_FAIL_NO_CAPABILITY: - return RttStatus::FAIL_NO_CAPABILITY; - case legacy_hal::RTT_STATUS_ABORTED: - return RttStatus::ABORTED; - case legacy_hal::RTT_STATUS_FAIL_INVALID_TS: - return RttStatus::FAIL_INVALID_TS; - case legacy_hal::RTT_STATUS_FAIL_PROTOCOL: - return RttStatus::FAIL_PROTOCOL; - case legacy_hal::RTT_STATUS_FAIL_SCHEDULE: - return RttStatus::FAIL_SCHEDULE; - case legacy_hal::RTT_STATUS_FAIL_BUSY_TRY_LATER: - return RttStatus::FAIL_BUSY_TRY_LATER; - case legacy_hal::RTT_STATUS_INVALID_REQ: - return RttStatus::INVALID_REQ; - case legacy_hal::RTT_STATUS_NO_WIFI: - return RttStatus::NO_WIFI; - case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE: - return RttStatus::FAIL_FTM_PARAM_OVERRIDE; - case legacy_hal::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE: - return RttStatus::FAILURE; // TODO: add HIDL enumeration - case legacy_hal::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED: - return RttStatus::FAILURE; // TODO: add HIDL enumeration - }; - CHECK(false) << "Unknown legacy status: " << status; -} - -bool convertHidlWifiChannelInfoToLegacy(const WifiChannelInfo& hidl_info, - legacy_hal::wifi_channel_info* legacy_info) { - if (!legacy_info) { - return false; - } - *legacy_info = {}; - legacy_info->width = convertHidlWifiChannelWidthToLegacy(hidl_info.width); - legacy_info->center_freq = hidl_info.centerFreq; - legacy_info->center_freq0 = hidl_info.centerFreq0; - legacy_info->center_freq1 = hidl_info.centerFreq1; - return true; -} - -bool convertLegacyWifiChannelInfoToHidl(const legacy_hal::wifi_channel_info& legacy_info, - WifiChannelInfo* hidl_info) { - if (!hidl_info) { - return false; - } - *hidl_info = {}; - hidl_info->width = convertLegacyWifiChannelWidthToHidl(legacy_info.width); - hidl_info->centerFreq = legacy_info.center_freq; - hidl_info->centerFreq0 = legacy_info.center_freq0; - hidl_info->centerFreq1 = legacy_info.center_freq1; - return true; -} - -bool convertHidlRttConfigToLegacy(const V1_6::RttConfig& hidl_config, - legacy_hal::wifi_rtt_config* legacy_config) { - if (!legacy_config) { - return false; - } - *legacy_config = {}; - CHECK(hidl_config.addr.size() == sizeof(legacy_config->addr)); - memcpy(legacy_config->addr, hidl_config.addr.data(), hidl_config.addr.size()); - legacy_config->type = convertHidlRttTypeToLegacy(hidl_config.type); - legacy_config->peer = convertHidlRttPeerTypeToLegacy(hidl_config.peer); - if (!convertHidlWifiChannelInfoToLegacy(hidl_config.channel, &legacy_config->channel)) { - return false; - } - legacy_config->burst_period = hidl_config.burstPeriod; - legacy_config->num_burst = hidl_config.numBurst; - legacy_config->num_frames_per_burst = hidl_config.numFramesPerBurst; - legacy_config->num_retries_per_rtt_frame = hidl_config.numRetriesPerRttFrame; - legacy_config->num_retries_per_ftmr = hidl_config.numRetriesPerFtmr; - legacy_config->LCI_request = hidl_config.mustRequestLci; - legacy_config->LCR_request = hidl_config.mustRequestLcr; - legacy_config->burst_duration = hidl_config.burstDuration; - legacy_config->preamble = convertHidlRttPreambleToLegacy(hidl_config.preamble); - legacy_config->bw = convertHidlRttBwToLegacy(hidl_config.bw); - return true; -} - -bool convertHidlVectorOfRttConfigToLegacy( - const std::vector& hidl_configs, - std::vector* legacy_configs) { - if (!legacy_configs) { - return false; - } - *legacy_configs = {}; - for (const auto& hidl_config : hidl_configs) { - legacy_hal::wifi_rtt_config legacy_config; - if (!convertHidlRttConfigToLegacy(hidl_config, &legacy_config)) { - return false; - } - legacy_configs->push_back(legacy_config); - } - return true; -} - -bool convertHidlRttLciInformationToLegacy(const RttLciInformation& hidl_info, - legacy_hal::wifi_lci_information* legacy_info) { - if (!legacy_info) { - return false; - } - *legacy_info = {}; - legacy_info->latitude = hidl_info.latitude; - legacy_info->longitude = hidl_info.longitude; - legacy_info->altitude = hidl_info.altitude; - legacy_info->latitude_unc = hidl_info.latitudeUnc; - legacy_info->longitude_unc = hidl_info.longitudeUnc; - legacy_info->altitude_unc = hidl_info.altitudeUnc; - legacy_info->motion_pattern = convertHidlRttMotionPatternToLegacy(hidl_info.motionPattern); - legacy_info->floor = hidl_info.floor; - legacy_info->height_above_floor = hidl_info.heightAboveFloor; - legacy_info->height_unc = hidl_info.heightUnc; - return true; -} - -bool convertHidlRttLcrInformationToLegacy(const RttLcrInformation& hidl_info, - legacy_hal::wifi_lcr_information* legacy_info) { - if (!legacy_info) { - return false; - } - *legacy_info = {}; - CHECK(hidl_info.countryCode.size() == sizeof(legacy_info->country_code)); - memcpy(legacy_info->country_code, hidl_info.countryCode.data(), hidl_info.countryCode.size()); - if (hidl_info.civicInfo.size() > sizeof(legacy_info->civic_info)) { - return false; - } - legacy_info->length = hidl_info.civicInfo.size(); - memcpy(legacy_info->civic_info, hidl_info.civicInfo.c_str(), hidl_info.civicInfo.size()); - return true; -} - -bool convertHidlRttResponderToLegacy(const V1_6::RttResponder& hidl_responder, - legacy_hal::wifi_rtt_responder* legacy_responder) { - if (!legacy_responder) { - return false; - } - *legacy_responder = {}; - if (!convertHidlWifiChannelInfoToLegacy(hidl_responder.channel, &legacy_responder->channel)) { - return false; - } - legacy_responder->preamble = convertHidlRttPreambleToLegacy(hidl_responder.preamble); - return true; -} - -bool convertLegacyRttResponderToHidl(const legacy_hal::wifi_rtt_responder& legacy_responder, - V1_6::RttResponder* hidl_responder) { - if (!hidl_responder) { - return false; - } - *hidl_responder = {}; - if (!convertLegacyWifiChannelInfoToHidl(legacy_responder.channel, &hidl_responder->channel)) { - return false; - } - hidl_responder->preamble = convertLegacyRttPreambleToHidl(legacy_responder.preamble); - return true; -} - -bool convertLegacyRttCapabilitiesToHidl( - const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, - V1_6::RttCapabilities* hidl_capabilities) { - if (!hidl_capabilities) { - return false; - } - *hidl_capabilities = {}; - hidl_capabilities->rttOneSidedSupported = legacy_capabilities.rtt_one_sided_supported; - hidl_capabilities->rttFtmSupported = legacy_capabilities.rtt_ftm_supported; - hidl_capabilities->lciSupported = legacy_capabilities.lci_support; - hidl_capabilities->lcrSupported = legacy_capabilities.lcr_support; - 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, legacy_hal::WIFI_RTT_PREAMBLE_HE, - legacy_hal::WIFI_RTT_PREAMBLE_EHT}) { - if (legacy_capabilities.preamble_support & flag) { - hidl_capabilities->preambleSupport |= - static_cast::type>( - convertLegacyRttPreambleToHidl(flag)); - } - } - hidl_capabilities->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) { - hidl_capabilities->bwSupport |= - static_cast::type>(convertLegacyRttBwToHidl(flag)); - } - } - hidl_capabilities->mcVersion = legacy_capabilities.mc_version; - return true; -} - -bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate, - V1_6::WifiRateInfo* hidl_rate) { - if (!hidl_rate) { - return false; - } - *hidl_rate = {}; - hidl_rate->preamble = convertLegacyWifiRatePreambleToHidl(legacy_rate.preamble); - hidl_rate->nss = convertLegacyWifiRateNssToHidl(legacy_rate.nss); - hidl_rate->bw = convertLegacyWifiChannelWidthToHidl( - static_cast(legacy_rate.bw)); - hidl_rate->rateMcsIdx = legacy_rate.rateMcsIdx; - hidl_rate->bitRateInKbps = legacy_rate.bitrate; - return true; -} - -bool convertLegacyRttResultToHidl(const legacy_hal::wifi_rtt_result& legacy_result, - V1_6::RttResult* hidl_result) { - if (!hidl_result) { - return false; - } - *hidl_result = {}; - CHECK(sizeof(legacy_result.addr) == hidl_result->addr.size()); - memcpy(hidl_result->addr.data(), legacy_result.addr, sizeof(legacy_result.addr)); - hidl_result->burstNum = legacy_result.burst_num; - hidl_result->measurementNumber = legacy_result.measurement_number; - hidl_result->successNumber = legacy_result.success_number; - hidl_result->numberPerBurstPeer = legacy_result.number_per_burst_peer; - hidl_result->status = convertLegacyRttStatusToHidl(legacy_result.status); - hidl_result->retryAfterDuration = legacy_result.retry_after_duration; - hidl_result->type = convertLegacyRttTypeToHidl(legacy_result.type); - hidl_result->rssi = legacy_result.rssi; - hidl_result->rssiSpread = legacy_result.rssi_spread; - if (!convertLegacyWifiRateInfoToHidl(legacy_result.tx_rate, &hidl_result->txRate)) { - return false; - } - if (!convertLegacyWifiRateInfoToHidl(legacy_result.rx_rate, &hidl_result->rxRate)) { - return false; - } - hidl_result->rtt = legacy_result.rtt; - hidl_result->rttSd = legacy_result.rtt_sd; - hidl_result->rttSpread = legacy_result.rtt_spread; - hidl_result->distanceInMm = legacy_result.distance_mm; - hidl_result->distanceSdInMm = legacy_result.distance_sd_mm; - hidl_result->distanceSpreadInMm = legacy_result.distance_spread_mm; - hidl_result->timeStampInUs = legacy_result.ts; - hidl_result->burstDurationInMs = legacy_result.burst_duration; - hidl_result->negotiatedBurstNum = legacy_result.negotiated_burst_num; - if (legacy_result.LCI && !convertLegacyIeToHidl(*legacy_result.LCI, &hidl_result->lci)) { - return false; - } - if (legacy_result.LCR && !convertLegacyIeToHidl(*legacy_result.LCR, &hidl_result->lcr)) { - return false; - } - return true; -} - -bool convertLegacyVectorOfRttResultToHidl( - const std::vector& legacy_results, - std::vector* hidl_results) { - if (!hidl_results) { - return false; - } - *hidl_results = {}; - for (const auto legacy_result : legacy_results) { - V1_6::RttResult hidl_result; - if (!convertLegacyRttResultToHidl(*legacy_result, &hidl_result)) { - return false; - } - hidl_results->push_back(hidl_result); - } - return true; -} - -legacy_hal::wifi_interface_type convertHidlIfaceTypeToLegacy(IfaceType hidl_interface_type) { - switch (hidl_interface_type) { - case IfaceType::STA: - return legacy_hal::WIFI_INTERFACE_TYPE_STA; - case IfaceType::AP: - return legacy_hal::WIFI_INTERFACE_TYPE_AP; - case IfaceType::P2P: - return legacy_hal::WIFI_INTERFACE_TYPE_P2P; - case IfaceType::NAN: - return legacy_hal::WIFI_INTERFACE_TYPE_NAN; - } - CHECK(false); -} - -legacy_hal::wifi_multi_sta_use_case convertHidlMultiStaUseCaseToLegacy( - V1_5::IWifiChip::MultiStaUseCase use_case) { - switch (use_case) { - case V1_5::IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY: - return legacy_hal::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY; - case V1_5::IWifiChip::MultiStaUseCase::DUAL_STA_NON_TRANSIENT_UNBIASED: - return legacy_hal::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED; - } - CHECK(false); -} - -bool convertHidlCoexUnsafeChannelToLegacy( - const V1_5::IWifiChip::CoexUnsafeChannel& hidl_unsafe_channel, - legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel) { - if (!legacy_unsafe_channel) { - return false; - } - *legacy_unsafe_channel = {}; - switch (hidl_unsafe_channel.band) { - case V1_5::WifiBand::BAND_24GHZ: - legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_2_4_BAND; - break; - case V1_5::WifiBand::BAND_5GHZ: - legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_5_0_BAND; - break; - default: - return false; - }; - legacy_unsafe_channel->channel = hidl_unsafe_channel.channel; - legacy_unsafe_channel->power_cap_dbm = hidl_unsafe_channel.powerCapDbm; - return true; -} - -bool convertHidlVectorOfCoexUnsafeChannelToLegacy( - const std::vector& hidl_unsafe_channels, - std::vector* legacy_unsafe_channels) { - if (!legacy_unsafe_channels) { - return false; - } - *legacy_unsafe_channels = {}; - for (const auto& hidl_unsafe_channel : hidl_unsafe_channels) { - legacy_hal::wifi_coex_unsafe_channel legacy_unsafe_channel; - if (!hidl_struct_util::convertHidlCoexUnsafeChannelToLegacy(hidl_unsafe_channel, - &legacy_unsafe_channel)) { - return false; - } - legacy_unsafe_channels->push_back(legacy_unsafe_channel); - } - return true; -} - -V1_6::WifiAntennaMode convertLegacyAntennaConfigurationToHidl(uint32_t antenna_cfg) { - switch (antenna_cfg) { - case legacy_hal::WIFI_ANTENNA_1X1: - return V1_6::WifiAntennaMode::WIFI_ANTENNA_MODE_1X1; - case legacy_hal::WIFI_ANTENNA_2X2: - return V1_6::WifiAntennaMode::WIFI_ANTENNA_MODE_2X2; - case legacy_hal::WIFI_ANTENNA_3X3: - return V1_6::WifiAntennaMode::WIFI_ANTENNA_MODE_3X3; - case legacy_hal::WIFI_ANTENNA_4X4: - return V1_6::WifiAntennaMode::WIFI_ANTENNA_MODE_4X4; - default: - return V1_6::WifiAntennaMode::WIFI_ANTENNA_MODE_UNSPECIFIED; - } -} - -bool convertLegacyWifiRadioConfigurationToHidl( - legacy_hal::wifi_radio_configuration* radio_configuration, - V1_6::WifiRadioConfiguration* hidl_radio_configuration) { - if (!hidl_radio_configuration) { - return false; - } - *hidl_radio_configuration = {}; - hidl_radio_configuration->bandInfo = - hidl_struct_util::convertLegacyMacBandToHidlWifiBand(radio_configuration->band); - if (hidl_radio_configuration->bandInfo == V1_5::WifiBand::BAND_UNSPECIFIED) { - LOG(ERROR) << "Unspecified band"; - return false; - } - hidl_radio_configuration->antennaMode = - hidl_struct_util::convertLegacyAntennaConfigurationToHidl( - radio_configuration->antenna_cfg); - return true; -} - -bool convertLegacyRadioCombinationsMatrixToHidl( - legacy_hal::wifi_radio_combination_matrix* legacy_matrix, - WifiRadioCombinationMatrix* hidl_matrix) { - if (!hidl_matrix || !legacy_matrix) { - return false; - } - *hidl_matrix = {}; - - int num_combinations = legacy_matrix->num_radio_combinations; - std::vector radio_combinations_vec; - if (!num_combinations) { - LOG(ERROR) << "zero radio combinations"; - return false; - } - wifi_radio_combination* l_radio_combinations_ptr = legacy_matrix->radio_combinations; - for (int i = 0; i < num_combinations; i++) { - int num_configurations = l_radio_combinations_ptr->num_radio_configurations; - WifiRadioCombination radioCombination; - std::vector radio_configurations_vec; - if (!num_configurations) { - LOG(ERROR) << "zero radio configurations"; - return false; - } - for (int j = 0; j < num_configurations; j++) { - WifiRadioConfiguration radioConfiguration; - wifi_radio_configuration* l_radio_configurations_ptr = - &l_radio_combinations_ptr->radio_configurations[j]; - if (!hidl_struct_util::convertLegacyWifiRadioConfigurationToHidl( - l_radio_configurations_ptr, &radioConfiguration)) { - LOG(ERROR) << "Error converting wifi radio configuration"; - return false; - } - radio_configurations_vec.push_back(radioConfiguration); - } - radioCombination.radioConfigurations = radio_configurations_vec; - radio_combinations_vec.push_back(radioCombination); - l_radio_combinations_ptr = - (wifi_radio_combination*)((u8*)l_radio_combinations_ptr + - sizeof(wifi_radio_combination) + - (sizeof(wifi_radio_configuration) * num_configurations)); - } - hidl_matrix->radioCombinations = radio_combinations_vec; - return true; -} - -} // namespace hidl_struct_util -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android diff --git a/wifi/1.6/default/hidl_struct_util.h b/wifi/1.6/default/hidl_struct_util.h deleted file mode 100644 index 2d4a5f13f4..0000000000 --- a/wifi/1.6/default/hidl_struct_util.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef HIDL_STRUCT_UTIL_H_ -#define HIDL_STRUCT_UTIL_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wifi_legacy_hal.h" - -/** - * This file contains a bunch of functions to convert structs from the legacy - * HAL to HIDL and vice versa. - * TODO(b/32093047): Add unit tests for these conversion methods in the VTS test - * suite. - */ -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_struct_util { -using namespace android::hardware::wifi::V1_0; - -// Chip conversion methods. -bool convertLegacyFeaturesToHidlChipCapabilities(uint64_t legacy_feature_set, - uint32_t legacy_logger_feature_set, - uint32_t* hidl_caps); -bool convertLegacyDebugRingBufferStatusToHidl( - const legacy_hal::wifi_ring_buffer_status& legacy_status, - WifiDebugRingBufferStatus* hidl_status); -bool convertLegacyVectorOfDebugRingBufferStatusToHidl( - const std::vector& legacy_status_vec, - std::vector* hidl_status_vec); -bool convertLegacyWakeReasonStatsToHidl(const legacy_hal::WakeReasonStats& legacy_stats, - WifiDebugHostWakeReasonStats* hidl_stats); -legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy( - V1_1::IWifiChip::TxPowerScenario hidl_scenario); -legacy_hal::wifi_latency_mode convertHidlLatencyModeToLegacy( - V1_3::IWifiChip::LatencyMode hidl_latency_mode); -legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy_1_2( - V1_2::IWifiChip::TxPowerScenario hidl_scenario); -bool convertLegacyWifiMacInfosToHidl( - const std::vector& legacy_mac_infos, - std::vector* hidl_radio_mode_infos); -legacy_hal::wifi_interface_type convertHidlIfaceTypeToLegacy(IfaceType hidl_interface_type); -legacy_hal::wifi_multi_sta_use_case convertHidlMultiStaUseCaseToLegacy( - V1_5::IWifiChip::MultiStaUseCase use_case); -bool convertHidlCoexUnsafeChannelToLegacy( - const V1_5::IWifiChip::CoexUnsafeChannel& hidl_unsafe_channel, - legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel); -bool convertHidlVectorOfCoexUnsafeChannelToLegacy( - const std::vector& hidl_unsafe_channels, - std::vector* legacy_unsafe_channels); -bool convertLegacyRadioCombinationsMatrixToHidl( - legacy_hal::wifi_radio_combination_matrix* legacy_matrix, - V1_6::WifiRadioCombinationMatrix* hidl_matrix); -V1_5::WifiBand convertLegacyMacBandToHidlWifiBand(uint32_t band); -V1_6::WifiAntennaMode convertLegacyAntennaConfigurationToHidl(uint32_t antenna_cfg); - -// STA iface conversion methods. -bool convertLegacyFeaturesToHidlStaCapabilities(uint64_t legacy_feature_set, - uint32_t legacy_logger_feature_set, - uint32_t* hidl_caps); -bool convertLegacyApfCapabilitiesToHidl(const legacy_hal::PacketFilterCapabilities& legacy_caps, - StaApfPacketFilterCapabilities* hidl_caps); -bool convertLegacyGscanCapabilitiesToHidl(const legacy_hal::wifi_gscan_capabilities& legacy_caps, - StaBackgroundScanCapabilities* hidl_caps); -legacy_hal::wifi_band convertHidlWifiBandToLegacy(V1_0::WifiBand band); -bool convertHidlGscanParamsToLegacy(const StaBackgroundScanParameters& hidl_scan_params, - legacy_hal::wifi_scan_cmd_params* legacy_scan_params); -// |has_ie_data| indicates whether or not the wifi_scan_result includes 802.11 -// Information Elements (IEs) -bool convertLegacyGscanResultToHidl(const legacy_hal::wifi_scan_result& legacy_scan_result, - bool has_ie_data, StaScanResult* hidl_scan_result); -// |cached_results| is assumed to not include IEs. -bool convertLegacyVectorOfCachedGscanResultsToHidl( - const std::vector& legacy_cached_scan_results, - std::vector* hidl_scan_datas); -bool convertLegacyLinkLayerStatsToHidl(const legacy_hal::LinkLayerStats& legacy_stats, - V1_6::StaLinkLayerStats* hidl_stats); -bool convertLegacyRoamingCapabilitiesToHidl( - const legacy_hal::wifi_roaming_capabilities& legacy_caps, - StaRoamingCapabilities* hidl_caps); -bool convertHidlRoamingConfigToLegacy(const StaRoamingConfig& hidl_config, - legacy_hal::wifi_roaming_config* legacy_config); -legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy(StaRoamingState state); -bool convertLegacyVectorOfDebugTxPacketFateToHidl( - const std::vector& legacy_fates, - std::vector* hidl_fates); -bool convertLegacyVectorOfDebugRxPacketFateToHidl( - const std::vector& legacy_fates, - std::vector* hidl_fates); - -// NAN iface conversion methods. -void convertToWifiNanStatus(legacy_hal::NanStatusType type, const char* str, size_t max_len, - WifiNanStatus* wifiNanStatus); -bool convertHidlNanEnableRequestToLegacy(const V1_4::NanEnableRequest& hidl_request, - legacy_hal::NanEnableRequest* legacy_request); -bool convertHidlNanConfigRequestToLegacy(const V1_4::NanConfigRequest& hidl_request, - legacy_hal::NanConfigRequest* legacy_request); -bool convertHidlNanEnableRequest_1_6ToLegacy( - const V1_4::NanEnableRequest& hidl_request1, - const V1_6::NanConfigRequestSupplemental& hidl_request2, - legacy_hal::NanEnableRequest* legacy_request); -bool convertHidlNanConfigRequest_1_6ToLegacy( - const V1_4::NanConfigRequest& hidl_request1, - const V1_6::NanConfigRequestSupplemental& hidl_request2, - legacy_hal::NanConfigRequest* legacy_request); -bool convertHidlNanPublishRequestToLegacy(const V1_6::NanPublishRequest& hidl_request, - legacy_hal::NanPublishRequest* legacy_request); -bool convertHidlNanSubscribeRequestToLegacy(const V1_0::NanSubscribeRequest& hidl_request, - legacy_hal::NanSubscribeRequest* legacy_request); -bool convertHidlNanTransmitFollowupRequestToLegacy( - const NanTransmitFollowupRequest& hidl_request, - legacy_hal::NanTransmitFollowupRequest* legacy_request); -bool convertHidlNanDataPathInitiatorRequestToLegacy( - const V1_0::NanInitiateDataPathRequest& hidl_request, - legacy_hal::NanDataPathInitiatorRequest* legacy_request); -bool convertHidlNanDataPathIndicationResponseToLegacy( - const V1_0::NanRespondToDataPathIndicationRequest& hidl_response, - legacy_hal::NanDataPathIndicationResponse* legacy_response); -bool convertHidlNanDataPathInitiatorRequest_1_6ToLegacy( - const V1_6::NanInitiateDataPathRequest& hidl_request, - legacy_hal::NanDataPathInitiatorRequest* legacy_request); -bool convertHidlNanDataPathIndicationResponse_1_6ToLegacy( - const V1_6::NanRespondToDataPathIndicationRequest& hidl_response, - legacy_hal::NanDataPathIndicationResponse* legacy_response); - -bool convertLegacyNanResponseHeaderToHidl(const legacy_hal::NanResponseMsg& legacy_response, - WifiNanStatus* wifiNanStatus); -bool convertLegacyNanCapabilitiesResponseToHidl(const legacy_hal::NanCapabilities& legacy_response, - V1_6::NanCapabilities* hidl_response); -bool convertLegacyNanMatchIndToHidl(const legacy_hal::NanMatchInd& legacy_ind, - V1_6::NanMatchInd* hidl_ind); -bool convertLegacyNanFollowupIndToHidl(const legacy_hal::NanFollowupInd& legacy_ind, - NanFollowupReceivedInd* hidl_ind); -bool convertLegacyNanDataPathRequestIndToHidl(const legacy_hal::NanDataPathRequestInd& legacy_ind, - NanDataPathRequestInd* hidl_ind); -bool convertLegacyNanDataPathConfirmIndToHidl(const legacy_hal::NanDataPathConfirmInd& legacy_ind, - V1_6::NanDataPathConfirmInd* hidl_ind); -bool convertLegacyNanDataPathScheduleUpdateIndToHidl( - const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, - V1_6::NanDataPathScheduleUpdateInd* hidl_ind); - -// RTT controller conversion methods. -bool convertHidlVectorOfRttConfigToLegacy(const std::vector& hidl_configs, - std::vector* legacy_configs); -bool convertHidlRttLciInformationToLegacy(const RttLciInformation& hidl_info, - legacy_hal::wifi_lci_information* legacy_info); -bool convertHidlRttLcrInformationToLegacy(const RttLcrInformation& hidl_info, - legacy_hal::wifi_lcr_information* legacy_info); -bool convertHidlRttResponderToLegacy(const V1_6::RttResponder& hidl_responder, - legacy_hal::wifi_rtt_responder* legacy_responder); -bool convertHidlWifiChannelInfoToLegacy(const V1_6::WifiChannelInfo& hidl_info, - legacy_hal::wifi_channel_info* legacy_info); -bool convertLegacyRttResponderToHidl(const legacy_hal::wifi_rtt_responder& legacy_responder, - V1_6::RttResponder* hidl_responder); -bool convertLegacyRttCapabilitiesToHidl( - const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, - V1_6::RttCapabilities* hidl_capabilities); -bool convertLegacyVectorOfRttResultToHidl( - const std::vector& legacy_results, - std::vector* hidl_results); -uint32_t convertHidlWifiBandToLegacyMacBand(V1_5::WifiBand band); -uint32_t convertHidlWifiIfaceModeToLegacy(uint32_t hidl_iface_mask); -uint32_t convertHidlUsableChannelFilterToLegacy(uint32_t hidl_filter_mask); -bool convertLegacyWifiUsableChannelsToHidl( - const std::vector& legacy_usable_channels, - std::vector* hidl_usable_channels); -bool convertLegacyPeerInfoStatsToHidl(const legacy_hal::WifiPeerInfo& legacy_peer_info_stats, - V1_6::StaPeerInfo* hidl_peer_info_stats); -bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate, - V1_6::WifiRateInfo* hidl_rate); -} // namespace hidl_struct_util -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // HIDL_STRUCT_UTIL_H_ diff --git a/wifi/1.6/default/service.cpp b/wifi/1.6/default/service.cpp deleted file mode 100644 index c874d8b199..0000000000 --- a/wifi/1.6/default/service.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#include -#include -#include -#include -#include -#include - -#include "wifi.h" -#include "wifi_feature_flags.h" -#include "wifi_legacy_hal.h" -#include "wifi_legacy_hal_factory.h" -#include "wifi_mode_controller.h" - -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; -using android::hardware::LazyServiceRegistrar; -using android::hardware::wifi::V1_6::implementation::feature_flags::WifiFeatureFlags; -using android::hardware::wifi::V1_6::implementation::legacy_hal::WifiLegacyHal; -using android::hardware::wifi::V1_6::implementation::legacy_hal::WifiLegacyHalFactory; -using android::hardware::wifi::V1_6::implementation::mode_controller::WifiModeController; - -#ifdef LAZY_SERVICE -const bool kLazyService = true; -#else -const bool kLazyService = false; -#endif - -int main(int /*argc*/, char** argv) { - signal(SIGPIPE, SIG_IGN); - android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); - LOG(INFO) << "Wifi Hal is booting up..."; - - configureRpcThreadpool(1, true /* callerWillJoin */); - - const auto iface_tool = std::make_shared(); - const auto legacy_hal_factory = std::make_shared(iface_tool); - - // Setup hwbinder service - android::sp service = - new android::hardware::wifi::V1_6::implementation::Wifi( - iface_tool, legacy_hal_factory, std::make_shared(), - std::make_shared()); - if (kLazyService) { - auto registrar = LazyServiceRegistrar::getInstance(); - CHECK_EQ(registrar.registerService(service), android::NO_ERROR) - << "Failed to register wifi HAL"; - } else { - CHECK_EQ(service->registerAsService(), android::NO_ERROR) << "Failed to register wifi HAL"; - } - - joinRpcThreadpool(); - - LOG(INFO) << "Wifi Hal is terminating..."; - return 0; -} diff --git a/wifi/1.6/default/tests/wifi_nan_iface_unit_tests.cpp b/wifi/1.6/default/tests/wifi_nan_iface_unit_tests.cpp deleted file mode 100644 index 8a5ddcd998..0000000000 --- a/wifi/1.6/default/tests/wifi_nan_iface_unit_tests.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 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. - */ - -#include -#include -#include -#include - -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 -#include "wifi_nan_iface.h" - -#include "mock_interface_tool.h" -#include "mock_wifi_feature_flags.h" -#include "mock_wifi_iface_util.h" -#include "mock_wifi_legacy_hal.h" - -using testing::NiceMock; -using testing::Return; -using testing::Test; - -namespace { -constexpr char kIfaceName[] = "mockWlan0"; -} // namespace - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { - -using android::hardware::wifi::V1_2::NanDataPathConfirmInd; - -bool CaptureIfaceEventHandlers(const std::string& /* iface_name*/, - iface_util::IfaceEventHandlers in_iface_event_handlers, - iface_util::IfaceEventHandlers* out_iface_event_handlers) { - *out_iface_event_handlers = in_iface_event_handlers; - return true; -} - -class MockNanIfaceEventCallback : public V1_5::IWifiNanIfaceEventCallback { - public: - MockNanIfaceEventCallback() = default; - - MOCK_METHOD3(notifyCapabilitiesResponse, - Return(uint16_t, const WifiNanStatus&, - const android::hardware::wifi::V1_0::NanCapabilities&)); - MOCK_METHOD2(notifyEnableResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyConfigResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyDisableResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD3(notifyStartPublishResponse, Return(uint16_t, const WifiNanStatus&, uint8_t)); - MOCK_METHOD2(notifyStopPublishResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD3(notifyStartSubscribeResponse, - Return(uint16_t, const WifiNanStatus&, uint8_t)); - MOCK_METHOD2(notifyStopSubscribeResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyTransmitFollowupResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyCreateDataInterfaceResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyDeleteDataInterfaceResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD3(notifyInitiateDataPathResponse, - Return(uint16_t, const WifiNanStatus&, uint32_t)); - MOCK_METHOD2(notifyRespondToDataPathIndicationResponse, - Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD2(notifyTerminateDataPathResponse, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD1(eventClusterEvent, Return(const NanClusterEventInd&)); - MOCK_METHOD1(eventDisabled, Return(const WifiNanStatus&)); - MOCK_METHOD2(eventPublishTerminated, Return(uint8_t, const WifiNanStatus&)); - MOCK_METHOD2(eventSubscribeTerminated, Return(uint8_t, const WifiNanStatus&)); - MOCK_METHOD1(eventMatch, Return(const V1_0::NanMatchInd&)); - MOCK_METHOD1(eventMatch_1_6, Return(const NanMatchInd&)); - MOCK_METHOD2(eventMatchExpired, Return(uint8_t, uint32_t)); - MOCK_METHOD1(eventFollowupReceived, Return(const NanFollowupReceivedInd&)); - MOCK_METHOD2(eventTransmitFollowup, Return(uint16_t, const WifiNanStatus&)); - MOCK_METHOD1(eventDataPathRequest, Return(const NanDataPathRequestInd&)); - MOCK_METHOD1(eventDataPathConfirm, - Return(const android::hardware::wifi::V1_0::NanDataPathConfirmInd&)); - MOCK_METHOD1(eventDataPathTerminated, Return(uint32_t)); - MOCK_METHOD1(eventDataPathConfirm_1_2, - Return(const android::hardware::wifi::V1_2::NanDataPathConfirmInd&)); - MOCK_METHOD1(eventDataPathConfirm_1_6, Return(const NanDataPathConfirmInd&)); - MOCK_METHOD1(eventDataPathScheduleUpdate, - Return(const android::hardware::wifi::V1_2::NanDataPathScheduleUpdateInd&)); - MOCK_METHOD1(eventDataPathScheduleUpdate_1_6, - Return(const NanDataPathScheduleUpdateInd&)); - MOCK_METHOD3(notifyCapabilitiesResponse_1_5, - Return(uint16_t, const WifiNanStatus&, const V1_5::NanCapabilities&)); -}; - -class WifiNanIfaceTest : public Test { - protected: - legacy_hal::wifi_hal_fn fake_func_table_; - std::shared_ptr> iface_tool_{ - new NiceMock}; - std::shared_ptr> legacy_hal_{ - new NiceMock(iface_tool_, fake_func_table_, true)}; - std::shared_ptr> iface_util_{ - new NiceMock(iface_tool_, legacy_hal_)}; -}; - -TEST_F(WifiNanIfaceTest, IfacEventHandlers_OnStateToggleOffOn) { - iface_util::IfaceEventHandlers captured_iface_event_handlers = {}; - EXPECT_CALL(*legacy_hal_, nanRegisterCallbackHandlers(testing::_, testing::_)) - .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); - EXPECT_CALL(*iface_util_, registerIfaceEventHandlers(testing::_, testing::_)) - .WillOnce(testing::Invoke(bind(CaptureIfaceEventHandlers, std::placeholders::_1, - std::placeholders::_2, &captured_iface_event_handlers))); - sp nan_iface = new WifiNanIface(kIfaceName, false, legacy_hal_, iface_util_); - - // Register a mock nan event callback. - sp> mock_event_callback{ - new NiceMock}; - nan_iface->registerEventCallback(mock_event_callback, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); - // Ensure that the eventDisabled() function in mock callback will be - // invoked. - WifiNanStatus expected_nan_status = {NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""}; - EXPECT_CALL(*mock_event_callback, eventDisabled(expected_nan_status)).Times(1); - - // Trigger the iface state toggle callback. - captured_iface_event_handlers.on_state_toggle_off_on(kIfaceName); -} -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android diff --git a/wifi/1.6/default/wifi.h b/wifi/1.6/default/wifi.h deleted file mode 100644 index 435358e797..0000000000 --- a/wifi/1.6/default/wifi.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_H_ -#define WIFI_H_ - -// HACK: NAN is a macro defined in math.h, which can be included in various -// headers. This wifi HAL uses an enum called NAN, which does not compile when -// the macro is defined. Undefine NAN to work around it. -#undef NAN -#include - -#include -#include -#include - -#include "hidl_callback_util.h" -#include "wifi_chip.h" -#include "wifi_feature_flags.h" -#include "wifi_legacy_hal.h" -#include "wifi_legacy_hal_factory.h" -#include "wifi_mode_controller.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { - -/** - * Root HIDL interface object used to control the Wifi HAL. - */ -class Wifi : public V1_6::IWifi { - public: - Wifi(const std::shared_ptr iface_tool, - const std::shared_ptr legacy_hal_factory, - const std::shared_ptr mode_controller, - const std::shared_ptr feature_flags); - - bool isValid(); - - // HIDL methods exposed. - Return registerEventCallback(const sp& event_callback, - registerEventCallback_cb hidl_status_cb) override; - Return registerEventCallback_1_5(const sp& event_callback, - registerEventCallback_1_5_cb hidl_status_cb) override; - Return isStarted() override; - Return start(start_cb hidl_status_cb) override; - Return stop(stop_cb hidl_status_cb) override; - Return getChipIds(getChipIds_cb hidl_status_cb) override; - Return getChip(ChipId chip_id, getChip_cb hidl_status_cb) override; - Return debug(const hidl_handle& handle, const hidl_vec& options) override; - - private: - enum class RunState { STOPPED, STARTED, STOPPING }; - - // Corresponding worker functions for the HIDL methods. - WifiStatus registerEventCallbackInternal( - const sp& event_callback __unused); - WifiStatus registerEventCallbackInternal_1_5( - const sp& event_callback); - WifiStatus startInternal(); - WifiStatus stopInternal(std::unique_lock* lock); - std::pair> getChipIdsInternal(); - std::pair> getChipInternal(ChipId chip_id); - - WifiStatus initializeModeControllerAndLegacyHal(); - WifiStatus stopLegacyHalAndDeinitializeModeController( - std::unique_lock* lock); - ChipId getChipIdFromWifiChip(sp& chip); - - // Instance is created in this root level |IWifi| HIDL interface object - // and shared with all the child HIDL interface objects. - std::shared_ptr iface_tool_; - std::shared_ptr legacy_hal_factory_; - std::shared_ptr mode_controller_; - std::vector> legacy_hals_; - std::shared_ptr feature_flags_; - RunState run_state_; - std::vector> chips_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_; - - DISALLOW_COPY_AND_ASSIGN(Wifi); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_H_ diff --git a/wifi/1.6/default/wifi_ap_iface.h b/wifi/1.6/default/wifi_ap_iface.h deleted file mode 100644 index d1c06424df..0000000000 --- a/wifi/1.6/default/wifi_ap_iface.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_AP_IFACE_H_ -#define WIFI_AP_IFACE_H_ - -#include -#include - -#include "wifi_iface_util.h" -#include "wifi_legacy_hal.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; - -/** - * HIDL interface object used to control a AP Iface instance. - */ -class WifiApIface : public V1_5::IWifiApIface { - public: - WifiApIface(const std::string& ifname, const std::vector& instances, - const std::weak_ptr legacy_hal, - const std::weak_ptr iface_util); - // Refer to |WifiChip::invalidate()|. - void invalidate(); - bool isValid(); - std::string getName(); - void removeInstance(std::string instance); - - // HIDL methods exposed. - Return getName(getName_cb hidl_status_cb) override; - Return getType(getType_cb hidl_status_cb) override; - Return setCountryCode(const hidl_array& code, - setCountryCode_cb hidl_status_cb) override; - Return getValidFrequenciesForBand(V1_0::WifiBand band, - getValidFrequenciesForBand_cb hidl_status_cb) override; - Return setMacAddress(const hidl_array& mac, - setMacAddress_cb hidl_status_cb) override; - Return getFactoryMacAddress(getFactoryMacAddress_cb hidl_status_cb) override; - Return resetToFactoryMacAddress(resetToFactoryMacAddress_cb hidl_status_cb) override; - - Return getBridgedInstances(getBridgedInstances_cb hidl_status_cb) override; - - private: - // Corresponding worker functions for the HIDL methods. - std::pair getNameInternal(); - std::pair getTypeInternal(); - WifiStatus setCountryCodeInternal(const std::array& code); - std::pair> getValidFrequenciesForBandInternal( - V1_0::WifiBand band); - WifiStatus setMacAddressInternal(const std::array& mac); - std::pair> getFactoryMacAddressInternal( - const std::string& ifaceName); - WifiStatus resetToFactoryMacAddressInternal(); - std::pair> getBridgedInstancesInternal(); - - std::string ifname_; - std::vector instances_; - std::weak_ptr legacy_hal_; - std::weak_ptr iface_util_; - bool is_valid_; - - DISALLOW_COPY_AND_ASSIGN(WifiApIface); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_AP_IFACE_H_ diff --git a/wifi/1.6/default/wifi_chip.h b/wifi/1.6/default/wifi_chip.h deleted file mode 100644 index e8ddaa6f9e..0000000000 --- a/wifi/1.6/default/wifi_chip.h +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_CHIP_H_ -#define WIFI_CHIP_H_ - -// HACK: NAN is a macro defined in math.h, which can be included in various -// headers. This wifi HAL uses an enum called NAN, which does not compile when -// the macro is defined. Undefine NAN to work around it. -#undef NAN - -#include -#include -#include - -#include -#include -#include -#include - -#include "hidl_callback_util.h" -#include "ringbuffer.h" -#include "wifi_ap_iface.h" -#include "wifi_feature_flags.h" -#include "wifi_legacy_hal.h" -#include "wifi_mode_controller.h" -#include "wifi_nan_iface.h" -#include "wifi_p2p_iface.h" -#include "wifi_rtt_controller.h" -#include "wifi_sta_iface.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; -using V1_5::WifiBand; - -/** - * HIDL interface object used to control a Wifi HAL chip instance. - * Since there is only a single chip instance used today, there is no - * identifying handle information stored here. - */ -class WifiChip : public V1_6::IWifiChip { - public: - WifiChip(ChipId chip_id, bool is_primary, - const std::weak_ptr legacy_hal, - const std::weak_ptr mode_controller, - const std::shared_ptr iface_util, - const std::weak_ptr feature_flags, - const std::function& subsystemCallbackHandler); - // HIDL does not provide a built-in mechanism to let the server invalidate - // a HIDL interface object after creation. If any client process holds onto - // a reference to the object in their context, any method calls on that - // reference will continue to be directed to the server. - // - // However Wifi HAL needs to control the lifetime of these objects. So, add - // a public |invalidate| method to |WifiChip| and it's child objects. This - // will be used to mark an object invalid when either: - // a) Wifi HAL is stopped, or - // b) Wifi Chip is reconfigured. - // - // All HIDL method implementations should check if the object is still - // marked valid before processing them. - void invalidate(); - bool isValid(); - std::set> getEventCallbacks(); - - // HIDL methods exposed. - Return getId(getId_cb hidl_status_cb) override; - // Deprecated support for this callback - Return registerEventCallback(const sp& event_callback, - registerEventCallback_cb hidl_status_cb) override; - Return getCapabilities(getCapabilities_cb hidl_status_cb) override; - Return getAvailableModes(getAvailableModes_cb hidl_status_cb) override; - Return configureChip(ChipModeId mode_id, configureChip_cb hidl_status_cb) override; - Return getMode(getMode_cb hidl_status_cb) override; - Return requestChipDebugInfo(requestChipDebugInfo_cb hidl_status_cb) override; - Return requestDriverDebugDump(requestDriverDebugDump_cb hidl_status_cb) override; - Return requestFirmwareDebugDump(requestFirmwareDebugDump_cb hidl_status_cb) override; - Return createApIface(createApIface_cb hidl_status_cb) override; - Return createBridgedApIface(createBridgedApIface_cb hidl_status_cb) override; - Return getApIfaceNames(getApIfaceNames_cb hidl_status_cb) override; - Return getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) override; - Return removeApIface(const hidl_string& ifname, removeApIface_cb hidl_status_cb) override; - Return removeIfaceInstanceFromBridgedApIface( - const hidl_string& brIfaceName, const hidl_string& ifaceInstanceName, - removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) override; - Return createNanIface(createNanIface_cb hidl_status_cb) override; - Return getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) override; - Return getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) override; - Return removeNanIface(const hidl_string& ifname, - removeNanIface_cb hidl_status_cb) override; - Return createP2pIface(createP2pIface_cb hidl_status_cb) override; - Return getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) override; - Return getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) override; - Return removeP2pIface(const hidl_string& ifname, - removeP2pIface_cb hidl_status_cb) override; - Return createStaIface(createStaIface_cb hidl_status_cb) override; - Return getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) override; - Return getStaIface(const hidl_string& ifname, getStaIface_cb hidl_status_cb) override; - Return removeStaIface(const hidl_string& ifname, - removeStaIface_cb hidl_status_cb) override; - Return createRttController(const sp& bound_iface, - createRttController_cb hidl_status_cb) override; - Return getDebugRingBuffersStatus(getDebugRingBuffersStatus_cb hidl_status_cb) override; - Return startLoggingToDebugRingBuffer( - const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, - uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes, - startLoggingToDebugRingBuffer_cb hidl_status_cb) override; - Return forceDumpToDebugRingBuffer(const hidl_string& ring_name, - forceDumpToDebugRingBuffer_cb hidl_status_cb) override; - Return flushRingBufferToFile(flushRingBufferToFile_cb hidl_status_cb) override; - Return stopLoggingToDebugRingBuffer( - stopLoggingToDebugRingBuffer_cb hidl_status_cb) override; - Return getDebugHostWakeReasonStats( - getDebugHostWakeReasonStats_cb hidl_status_cb) override; - Return enableDebugErrorAlerts(bool enable, - enableDebugErrorAlerts_cb hidl_status_cb) override; - Return selectTxPowerScenario(V1_1::IWifiChip::TxPowerScenario scenario, - selectTxPowerScenario_cb hidl_status_cb) override; - Return resetTxPowerScenario(resetTxPowerScenario_cb hidl_status_cb) override; - Return setLatencyMode(LatencyMode mode, setLatencyMode_cb hidl_status_cb) override; - Return registerEventCallback_1_2(const sp& event_callback, - registerEventCallback_1_2_cb hidl_status_cb) override; - Return selectTxPowerScenario_1_2(TxPowerScenario scenario, - selectTxPowerScenario_cb hidl_status_cb) override; - Return getCapabilities_1_3(getCapabilities_cb hidl_status_cb) override; - Return getCapabilities_1_5(getCapabilities_1_5_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; - Return registerEventCallback_1_4(const sp& event_callback, - registerEventCallback_1_4_cb hidl_status_cb) override; - Return setMultiStaPrimaryConnection( - const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) override; - Return setMultiStaUseCase(MultiStaUseCase use_case, - setMultiStaUseCase_cb hidl_status_cb) override; - Return setCoexUnsafeChannels(const hidl_vec& unsafe_channels, - hidl_bitfield restrictions, - setCoexUnsafeChannels_cb hidl_status_cb) override; - Return setCountryCode(const hidl_array& code, - setCountryCode_cb _hidl_cb) override; - Return getUsableChannels(WifiBand band, hidl_bitfield ifaceModeMask, - hidl_bitfield filterMask, - getUsableChannels_cb _hidl_cb) override; - Return triggerSubsystemRestart(triggerSubsystemRestart_cb hidl_status_cb) override; - Return createRttController_1_6(const sp& bound_iface, - createRttController_1_6_cb hidl_status_cb) override; - Return getUsableChannels_1_6(WifiBand band, - hidl_bitfield ifaceModeMask, - hidl_bitfield filterMask, - getUsableChannels_1_6_cb _hidl_cb) override; - Return getSupportedRadioCombinationsMatrix( - getSupportedRadioCombinationsMatrix_cb hidl_status_cb) override; - Return getAvailableModes_1_6(getAvailableModes_1_6_cb hidl_status_cb) override; - - private: - void invalidateAndRemoveAllIfaces(); - // When a STA iface is removed any dependent NAN-ifaces/RTT-controllers are - // invalidated & removed. - void invalidateAndRemoveDependencies(const std::string& removed_iface_name); - - // Corresponding worker functions for the HIDL methods. - std::pair getIdInternal(); - // Deprecated support for this callback - WifiStatus registerEventCallbackInternal( - const sp& event_callback); - std::pair getCapabilitiesInternal(); - std::pair> getAvailableModesInternal(); - WifiStatus configureChipInternal(std::unique_lock* lock, - ChipModeId mode_id); - std::pair getModeInternal(); - std::pair requestChipDebugInfoInternal(); - std::pair> requestDriverDebugDumpInternal(); - std::pair> requestFirmwareDebugDumpInternal(); - sp newWifiApIface(std::string& ifname); - WifiStatus createVirtualApInterface(const std::string& apVirtIf); - std::pair> createApIfaceInternal(); - std::pair> createBridgedApIfaceInternal(); - std::pair> getApIfaceNamesInternal(); - std::pair> getApIfaceInternal(const std::string& ifname); - WifiStatus removeApIfaceInternal(const std::string& ifname); - WifiStatus removeIfaceInstanceFromBridgedApIfaceInternal(const std::string& brIfaceName, - const std::string& ifInstanceName); - std::pair> createNanIfaceInternal(); - std::pair> getNanIfaceNamesInternal(); - std::pair> getNanIfaceInternal(const std::string& ifname); - WifiStatus removeNanIfaceInternal(const std::string& ifname); - std::pair> createP2pIfaceInternal(); - std::pair> getP2pIfaceNamesInternal(); - std::pair> getP2pIfaceInternal(const std::string& ifname); - WifiStatus removeP2pIfaceInternal(const std::string& ifname); - std::pair> createStaIfaceInternal(); - std::pair> getStaIfaceNamesInternal(); - std::pair> getStaIfaceInternal(const std::string& ifname); - WifiStatus removeStaIfaceInternal(const std::string& ifname); - std::pair> createRttControllerInternal( - const sp& bound_iface); - std::pair> - getDebugRingBuffersStatusInternal(); - WifiStatus startLoggingToDebugRingBufferInternal(const hidl_string& ring_name, - WifiDebugRingBufferVerboseLevel verbose_level, - uint32_t max_interval_in_sec, - uint32_t min_data_size_in_bytes); - WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name); - WifiStatus flushRingBufferToFileInternal(); - WifiStatus stopLoggingToDebugRingBufferInternal(); - std::pair getDebugHostWakeReasonStatsInternal(); - WifiStatus enableDebugErrorAlertsInternal(bool enable); - WifiStatus selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario); - WifiStatus resetTxPowerScenarioInternal(); - WifiStatus setLatencyModeInternal(LatencyMode mode); - WifiStatus registerEventCallbackInternal_1_2( - const sp& event_callback); - WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario); - std::pair getCapabilitiesInternal_1_3(); - std::pair getCapabilitiesInternal_1_5(); - std::pair> createRttControllerInternal_1_4( - const sp& bound_iface); - WifiStatus registerEventCallbackInternal_1_4( - const sp& event_callback); - WifiStatus setMultiStaPrimaryConnectionInternal(const std::string& ifname); - WifiStatus setMultiStaUseCaseInternal(MultiStaUseCase use_case); - WifiStatus setCoexUnsafeChannelsInternal(std::vector unsafe_channels, - uint32_t restrictions); - WifiStatus setCountryCodeInternal(const std::array& code); - std::pair> getUsableChannelsInternal( - WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask); - WifiStatus handleChipConfiguration(std::unique_lock* lock, - ChipModeId mode_id); - WifiStatus registerDebugRingBufferCallback(); - WifiStatus registerRadioModeChangeCallback(); - std::vector - getCurrentModeConcurrencyCombinations(); - std::map getCurrentConcurrencyCombination(); - std::vector> expandConcurrencyCombinations( - const V1_6::IWifiChip::ChipConcurrencyCombination& combination); - bool canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes( - const std::map& expanded_combo, - IfaceConcurrencyType requested_type); - bool canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType requested_type); - bool canExpandedConcurrencyComboSupportConcurrencyCombo( - const std::map& expanded_combo, - const std::map& req_combo); - bool canCurrentModeSupportConcurrencyCombo( - const std::map& req_combo); - bool canCurrentModeSupportConcurrencyType(IfaceConcurrencyType requested_type); - bool isValidModeId(ChipModeId mode_id); - bool isStaApConcurrencyAllowedInCurrentMode(); - bool isDualStaConcurrencyAllowedInCurrentMode(); - uint32_t startIdxOfApIface(); - std::string getFirstActiveWlanIfaceName(); - std::string allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx); - std::string allocateApIfaceName(); - std::vector allocateBridgedApInstanceNames(); - std::string allocateStaIfaceName(); - bool writeRingbufferFilesInternal(); - std::string getWlanIfaceNameWithType(IfaceType type, unsigned idx); - void invalidateAndClearBridgedApAll(); - void deleteApIface(const std::string& if_name); - bool findUsingNameFromBridgedApInstances(const std::string& name); - WifiStatus triggerSubsystemRestartInternal(); - std::pair> createRttControllerInternal_1_6( - const sp& bound_iface); - std::pair> getUsableChannelsInternal_1_6( - WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask); - std::pair getSupportedRadioCombinationsMatrixInternal(); - std::pair> getAvailableModesInternal_1_6(); - - ChipId chip_id_; - std::weak_ptr legacy_hal_; - std::weak_ptr mode_controller_; - std::shared_ptr iface_util_; - std::vector> ap_ifaces_; - std::vector> nan_ifaces_; - std::vector> p2p_ifaces_; - std::vector> sta_ifaces_; - std::vector> rtt_controllers_; - std::map ringbuffer_map_; - bool is_valid_; - // Members pertaining to chip configuration. - uint32_t current_mode_id_; - std::mutex lock_t; - std::vector modes_; - // The legacy ring buffer callback API has only a global callback - // registration mechanism. Use this to check if we have already - // registered a callback. - bool debug_ring_buffer_cb_registered_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_; - - const std::function subsystemCallbackHandler_; - std::map> br_ifaces_ap_instances_; - DISALLOW_COPY_AND_ASSIGN(WifiChip); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_CHIP_H_ diff --git a/wifi/1.6/default/wifi_nan_iface.cpp b/wifi/1.6/default/wifi_nan_iface.cpp deleted file mode 100644 index ac2ebc940e..0000000000 --- a/wifi/1.6/default/wifi_nan_iface.cpp +++ /dev/null @@ -1,1016 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#include - -#include "hidl_return_util.h" -#include "hidl_struct_util.h" -#include "wifi_nan_iface.h" -#include "wifi_status_util.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; - -WifiNanIface::WifiNanIface(const std::string& ifname, bool is_dedicated_iface, - const std::weak_ptr legacy_hal, - const std::weak_ptr iface_util) - : ifname_(ifname), - is_dedicated_iface_(is_dedicated_iface), - legacy_hal_(legacy_hal), - iface_util_(iface_util), - is_valid_(true) { - if (is_dedicated_iface_) { - // If using a dedicated iface, set the iface up first. - if (!iface_util_.lock()->setUpState(ifname_, true)) { - // Fatal failure, invalidate the iface object. - invalidate(); - return; - } - } - // Register all the callbacks here. these should be valid for the lifetime - // of the object. Whenever the mode changes legacy HAL will remove - // all of these callbacks. - legacy_hal::NanCallbackHandlers callback_handlers; - android::wp weak_ptr_this(this); - - // Callback for response. - callback_handlers.on_notify_response = [weak_ptr_this](legacy_hal::transaction_id id, - const legacy_hal::NanResponseMsg& msg) { - 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; - } - WifiNanStatus wifiNanStatus; - if (!hidl_struct_util::convertLegacyNanResponseHeaderToHidl(msg, &wifiNanStatus)) { - LOG(ERROR) << "Failed to convert nan response header"; - return; - } - - switch (msg.response_type) { - case legacy_hal::NAN_RESPONSE_ENABLED: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyEnableResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_DISABLED: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyDisableResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_PUBLISH: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyStartPublishResponse(id, wifiNanStatus, - msg.body.publish_response.publish_id) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyStopPublishResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyTransmitFollowupResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_SUBSCRIBE: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyStartSubscribeResponse( - id, wifiNanStatus, - msg.body.subscribe_response.subscribe_id) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyStopSubscribeResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_CONFIG: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyConfigResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_GET_CAPABILITIES: { - V1_6::NanCapabilities hidl_struct; - if (!hidl_struct_util::convertLegacyNanCapabilitiesResponseToHidl( - msg.body.nan_capabilities, &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) { - if (!callback->notifyCapabilitiesResponse_1_6(id, wifiNanStatus, hidl_struct) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_DP_INTERFACE_CREATE: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyCreateDataInterfaceResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_DP_INTERFACE_DELETE: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyDeleteDataInterfaceResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_DP_INITIATOR_RESPONSE: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyInitiateDataPathResponse( - id, wifiNanStatus, - msg.body.data_request_response.ndp_instance_id) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_DP_RESPONDER_RESPONSE: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyRespondToDataPathIndicationResponse(id, wifiNanStatus) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_DP_END: { - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->notifyTerminateDataPathResponse(id, wifiNanStatus).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - break; - } - case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD: - /* fall through */ - case legacy_hal::NAN_RESPONSE_TCA: - /* fall through */ - case legacy_hal::NAN_RESPONSE_STATS: - /* fall through */ - case legacy_hal::NAN_RESPONSE_ERROR: - /* fall through */ - default: - LOG(ERROR) << "Unknown or unhandled response type: " << msg.response_type; - return; - } - }; - - callback_handlers.on_event_disc_eng_event = - [weak_ptr_this](const legacy_hal::NanDiscEngEventInd& msg) { - 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; - } - NanClusterEventInd hidl_struct; - // event types defined identically - hence can be cast - hidl_struct.eventType = (NanClusterEventType)msg.event_type; - hidl_struct.addr = msg.data.mac_addr.addr; - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventClusterEvent(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_disabled = [weak_ptr_this](const legacy_hal::NanDisabledInd& msg) { - 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; - } - WifiNanStatus status; - hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason), - &status); - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventDisabled(status).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_publish_terminated = - [weak_ptr_this](const legacy_hal::NanPublishTerminatedInd& msg) { - 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; - } - WifiNanStatus status; - hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, - sizeof(msg.nan_reason), &status); - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventPublishTerminated(msg.publish_id, status).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_subscribe_terminated = - [weak_ptr_this](const legacy_hal::NanSubscribeTerminatedInd& msg) { - 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; - } - WifiNanStatus status; - hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, - sizeof(msg.nan_reason), &status); - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventSubscribeTerminated(msg.subscribe_id, status).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_match = [weak_ptr_this](const legacy_hal::NanMatchInd& msg) { - 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; - } - V1_6::NanMatchInd hidl_struct; - if (!hidl_struct_util::convertLegacyNanMatchIndToHidl(msg, &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - - for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) { - if (!callback->eventMatch_1_6(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_match_expired = [weak_ptr_this]( - const legacy_hal::NanMatchExpiredInd& msg) { - 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; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventMatchExpired(msg.publish_subscribe_id, msg.requestor_instance_id) - .isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_followup = [weak_ptr_this](const legacy_hal::NanFollowupInd& msg) { - 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; - } - NanFollowupReceivedInd hidl_struct; - if (!hidl_struct_util::convertLegacyNanFollowupIndToHidl(msg, &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventFollowupReceived(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_transmit_follow_up = - [weak_ptr_this](const legacy_hal::NanTransmitFollowupInd& msg) { - 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; - } - WifiNanStatus status; - hidl_struct_util::convertToWifiNanStatus(msg.reason, msg.nan_reason, - sizeof(msg.nan_reason), &status); - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventTransmitFollowup(msg.id, status).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_data_path_request = - [weak_ptr_this](const legacy_hal::NanDataPathRequestInd& msg) { - 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; - } - NanDataPathRequestInd hidl_struct; - if (!hidl_struct_util::convertLegacyNanDataPathRequestIndToHidl(msg, - &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventDataPathRequest(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_data_path_confirm = - [weak_ptr_this](const legacy_hal::NanDataPathConfirmInd& msg) { - 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; - } - V1_6::NanDataPathConfirmInd hidl_struct; - if (!hidl_struct_util::convertLegacyNanDataPathConfirmIndToHidl(msg, - &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - - for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) { - if (!callback->eventDataPathConfirm_1_6(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - callback_handlers.on_event_data_path_end = - [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) { - 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; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - for (int i = 0; i < msg.num_ndp_instances; ++i) { - if (!callback->eventDataPathTerminated(msg.ndp_instance_id[i]).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - } - }; - - callback_handlers.on_event_beacon_sdf_payload = - [weak_ptr_this](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) { - LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called"; - }; - - callback_handlers.on_event_range_request = - [weak_ptr_this](const legacy_hal::NanRangeRequestInd& /* msg */) { - LOG(ERROR) << "on_event_range_request - should not be called"; - }; - - callback_handlers.on_event_range_report = - [weak_ptr_this](const legacy_hal::NanRangeReportInd& /* msg */) { - LOG(ERROR) << "on_event_range_report - should not be called"; - }; - - callback_handlers.on_event_schedule_update = - [weak_ptr_this](const legacy_hal::NanDataPathScheduleUpdateInd& msg) { - 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; - } - V1_6::NanDataPathScheduleUpdateInd hidl_struct; - if (!hidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToHidl( - msg, &hidl_struct)) { - LOG(ERROR) << "Failed to convert nan capabilities response"; - return; - } - - for (const auto& callback : shared_ptr_this->getEventCallbacks_1_6()) { - if (!callback->eventDataPathScheduleUpdate_1_6(hidl_struct).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_, callback_handlers); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - LOG(ERROR) << "Failed to register nan callbacks. Invalidating object"; - invalidate(); - } - - // Register for iface state toggle events. - iface_util::IfaceEventHandlers event_handlers = {}; - event_handlers.on_state_toggle_off_on = [weak_ptr_this](const std::string& /* iface_name */) { - 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; - } - // Tell framework that NAN has been disabled. - WifiNanStatus status = {NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""}; - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->eventDisabled(status).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers); -} - -void WifiNanIface::invalidate() { - if (!isValid()) { - return; - } - // send commands to HAL to actually disable and destroy interfaces - legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF); - legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0"); - legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1"); - iface_util_.lock()->unregisterIfaceEventHandlers(ifname_); - legacy_hal_.reset(); - event_cb_handler_.invalidate(); - event_cb_handler_1_2_.invalidate(); - event_cb_handler_1_5_.invalidate(); - is_valid_ = false; - if (is_dedicated_iface_) { - // If using a dedicated iface, set the iface down. - iface_util_.lock()->setUpState(ifname_, false); - } -} - -bool WifiNanIface::isValid() { - return is_valid_; -} - -std::string WifiNanIface::getName() { - return ifname_; -} - -std::set> WifiNanIface::getEventCallbacks() { - return event_cb_handler_.getCallbacks(); -} - -std::set> WifiNanIface::getEventCallbacks_1_2() { - return event_cb_handler_1_2_.getCallbacks(); -} - -std::set> WifiNanIface::getEventCallbacks_1_5() { - return event_cb_handler_1_5_.getCallbacks(); -} - -std::set> WifiNanIface::getEventCallbacks_1_6() { - return event_cb_handler_1_6_.getCallbacks(); -} - -Return WifiNanIface::getName(getName_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::getNameInternal, hidl_status_cb); -} - -Return WifiNanIface::getType(getType_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::getTypeInternal, hidl_status_cb); -} - -Return WifiNanIface::registerEventCallback( - const sp& callback, - registerEventCallback_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::registerEventCallbackInternal, hidl_status_cb, callback); -} - -Return WifiNanIface::getCapabilitiesRequest(uint16_t cmd_id, - getCapabilitiesRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::getCapabilitiesRequestInternal, hidl_status_cb, cmd_id); -} - -Return WifiNanIface::enableRequest(uint16_t cmd_id, const V1_0::NanEnableRequest& msg, - enableRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::enableRequestInternal, hidl_status_cb, cmd_id, msg); -} - -Return WifiNanIface::configRequest(uint16_t cmd_id, const V1_0::NanConfigRequest& msg, - configRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::configRequestInternal, hidl_status_cb, cmd_id, msg); -} - -Return WifiNanIface::disableRequest(uint16_t cmd_id, disableRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::disableRequestInternal, hidl_status_cb, cmd_id); -} - -Return WifiNanIface::startPublishRequest(uint16_t cmd_id, const V1_0::NanPublishRequest& msg, - startPublishRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::startPublishRequestInternal, hidl_status_cb, cmd_id, msg); -} - -Return WifiNanIface::stopPublishRequest(uint16_t cmd_id, uint8_t sessionId, - stopPublishRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::stopPublishRequestInternal, hidl_status_cb, cmd_id, - sessionId); -} - -Return WifiNanIface::startSubscribeRequest(uint16_t cmd_id, - const V1_0::NanSubscribeRequest& msg, - startSubscribeRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::startSubscribeRequestInternal, hidl_status_cb, cmd_id, - msg); -} - -Return WifiNanIface::stopSubscribeRequest(uint16_t cmd_id, uint8_t sessionId, - stopSubscribeRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::stopSubscribeRequestInternal, hidl_status_cb, cmd_id, - sessionId); -} - -Return WifiNanIface::transmitFollowupRequest(uint16_t cmd_id, - const NanTransmitFollowupRequest& msg, - transmitFollowupRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::transmitFollowupRequestInternal, hidl_status_cb, cmd_id, - msg); -} - -Return WifiNanIface::createDataInterfaceRequest( - uint16_t cmd_id, const hidl_string& iface_name, - createDataInterfaceRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::createDataInterfaceRequestInternal, hidl_status_cb, - cmd_id, iface_name); -} - -Return WifiNanIface::deleteDataInterfaceRequest( - uint16_t cmd_id, const hidl_string& iface_name, - deleteDataInterfaceRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::deleteDataInterfaceRequestInternal, hidl_status_cb, - cmd_id, iface_name); -} - -Return WifiNanIface::initiateDataPathRequest(uint16_t cmd_id, - const V1_0::NanInitiateDataPathRequest& msg, - initiateDataPathRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::initiateDataPathRequestInternal, hidl_status_cb, cmd_id, - msg); -} - -Return WifiNanIface::respondToDataPathIndicationRequest( - uint16_t cmd_id, const V1_0::NanRespondToDataPathIndicationRequest& msg, - respondToDataPathIndicationRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::respondToDataPathIndicationRequestInternal, - hidl_status_cb, cmd_id, msg); -} - -Return WifiNanIface::terminateDataPathRequest(uint16_t cmd_id, uint32_t ndpInstanceId, - terminateDataPathRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::terminateDataPathRequestInternal, hidl_status_cb, cmd_id, - ndpInstanceId); -} - -Return WifiNanIface::registerEventCallback_1_2( - const sp& callback, - registerEventCallback_1_2_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::registerEventCallback_1_2Internal, hidl_status_cb, - callback); -} - -Return WifiNanIface::enableRequest_1_2(uint16_t cmd_id, const V1_0::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - enableRequest_1_2_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::enableRequest_1_2Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::configRequest_1_2(uint16_t cmd_id, const V1_0::NanConfigRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - configRequest_1_2_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::configRequest_1_2Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::enableRequest_1_4(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - enableRequest_1_4_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::enableRequest_1_4Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::configRequest_1_4(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - configRequest_1_4_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::configRequest_1_4Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::registerEventCallback_1_5( - const sp& callback, - registerEventCallback_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::registerEventCallback_1_5Internal, hidl_status_cb, - callback); -} - -Return WifiNanIface::enableRequest_1_5(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_5::NanConfigRequestSupplemental& msg2, - enableRequest_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::enableRequest_1_5Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::configRequest_1_5(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_5::NanConfigRequestSupplemental& msg2, - configRequest_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::configRequest_1_5Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::getCapabilitiesRequest_1_5( - uint16_t cmd_id, getCapabilitiesRequest_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::getCapabilitiesRequest_1_5Internal, hidl_status_cb, - cmd_id); -} - -Return WifiNanIface::enableRequest_1_6(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2, - enableRequest_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::enableRequest_1_6Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::configRequest_1_6(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2, - configRequest_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::configRequest_1_6Internal, hidl_status_cb, cmd_id, msg1, - msg2); -} - -Return WifiNanIface::initiateDataPathRequest_1_6(uint16_t cmd_id, - const V1_6::NanInitiateDataPathRequest& msg, - initiateDataPathRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::initiateDataPathRequest_1_6Internal, hidl_status_cb, - cmd_id, msg); -} - -Return WifiNanIface::respondToDataPathIndicationRequest_1_6( - uint16_t cmd_id, const V1_6::NanRespondToDataPathIndicationRequest& msg, - respondToDataPathIndicationRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::respondToDataPathIndicationRequest_1_6Internal, - hidl_status_cb, cmd_id, msg); -} - -Return WifiNanIface::startPublishRequest_1_6(uint16_t cmd_id, - const V1_6::NanPublishRequest& msg, - startPublishRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::startPublishRequest_1_6Internal, hidl_status_cb, cmd_id, - msg); -} - -std::pair WifiNanIface::getNameInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; -} - -std::pair WifiNanIface::getTypeInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::NAN}; -} - -Return WifiNanIface::registerEventCallback_1_6( - const sp& callback, - registerEventCallback_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiNanIface::registerEventCallback_1_6Internal, hidl_status_cb, - callback); -} - -WifiStatus WifiNanIface::registerEventCallbackInternal( - const sp& callback) { - if (!event_cb_handler_.addCallback(callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -WifiStatus WifiNanIface::getCapabilitiesRequestInternal(uint16_t /* cmd_id */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::enableRequestInternal(uint16_t /* cmd_id */, - const V1_0::NanEnableRequest& /* msg */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::configRequestInternal(uint16_t /* cmd_id */, - const V1_0::NanConfigRequest& /* msg */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::disableRequestInternal(uint16_t cmd_id) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::startPublishRequestInternal(uint16_t /* cmd_id */, - const V1_0::NanPublishRequest& /* msg */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::stopPublishRequestInternal(uint16_t cmd_id, uint8_t sessionId) { - legacy_hal::NanPublishCancelRequest legacy_msg; - legacy_msg.publish_id = sessionId; - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::startSubscribeRequestInternal(uint16_t cmd_id, - const V1_0::NanSubscribeRequest& msg) { - legacy_hal::NanSubscribeRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanSubscribeRequestToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::stopSubscribeRequestInternal(uint16_t cmd_id, uint8_t sessionId) { - legacy_hal::NanSubscribeCancelRequest legacy_msg; - legacy_msg.subscribe_id = sessionId; - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::transmitFollowupRequestInternal(uint16_t cmd_id, - const NanTransmitFollowupRequest& msg) { - legacy_hal::NanTransmitFollowupRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::createDataInterfaceRequestInternal(uint16_t cmd_id, - const std::string& iface_name) { - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name); - return createWifiStatusFromLegacyError(legacy_status); -} -WifiStatus WifiNanIface::deleteDataInterfaceRequestInternal(uint16_t cmd_id, - const std::string& iface_name) { - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name); - return createWifiStatusFromLegacyError(legacy_status); -} -WifiStatus WifiNanIface::initiateDataPathRequestInternal( - uint16_t cmd_id, const V1_0::NanInitiateDataPathRequest& msg) { - legacy_hal::NanDataPathInitiatorRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} -WifiStatus WifiNanIface::respondToDataPathIndicationRequestInternal( - uint16_t cmd_id, const V1_0::NanRespondToDataPathIndicationRequest& msg) { - legacy_hal::NanDataPathIndicationResponse legacy_msg; - if (!hidl_struct_util::convertHidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} -WifiStatus WifiNanIface::terminateDataPathRequestInternal(uint16_t cmd_id, uint32_t ndpInstanceId) { - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::registerEventCallback_1_2Internal( - const sp& callback) { - sp callback_1_0 = callback; - if (!event_cb_handler_.addCallback(callback_1_0)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - if (!event_cb_handler_1_2_.addCallback(callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -WifiStatus WifiNanIface::enableRequest_1_2Internal( - uint16_t /* cmd_id */, const V1_0::NanEnableRequest& /* msg1 */, - const V1_2::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::configRequest_1_2Internal( - uint16_t /* cmd_id */, const V1_0::NanConfigRequest& /* msg1 */, - const V1_2::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::enableRequest_1_4Internal( - uint16_t /* cmd_id */, const V1_4::NanEnableRequest& /* msg1 */, - const V1_2::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::configRequest_1_4Internal( - uint16_t /* cmd_id */, const V1_4::NanConfigRequest& /* msg1 */, - const V1_2::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::registerEventCallback_1_5Internal( - const sp& callback) { - sp callback_1_0 = callback; - if (!event_cb_handler_.addCallback(callback_1_0)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - sp callback_1_2 = callback; - if (!event_cb_handler_1_2_.addCallback(callback_1_2)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - if (!event_cb_handler_1_5_.addCallback(callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -WifiStatus WifiNanIface::getCapabilitiesRequest_1_5Internal(uint16_t cmd_id) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::enableRequest_1_5Internal( - uint16_t /* cmd_id */, const V1_4::NanEnableRequest& /* msg1 */, - const V1_5::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::configRequest_1_5Internal( - uint16_t /* cmd_id */, const V1_4::NanConfigRequest& /* msg1 */, - const V1_5::NanConfigRequestSupplemental& /* msg2 */) { - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiNanIface::enableRequest_1_6Internal(uint16_t cmd_id, - const V1_4::NanEnableRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2) { - legacy_hal::NanEnableRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanEnableRequest_1_6ToLegacy(msg1, msg2, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::configRequest_1_6Internal(uint16_t cmd_id, - const V1_4::NanConfigRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2) { - legacy_hal::NanConfigRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanConfigRequest_1_6ToLegacy(msg1, msg2, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::initiateDataPathRequest_1_6Internal( - uint16_t cmd_id, const V1_6::NanInitiateDataPathRequest& msg) { - legacy_hal::NanDataPathInitiatorRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanDataPathInitiatorRequest_1_6ToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::respondToDataPathIndicationRequest_1_6Internal( - uint16_t cmd_id, const V1_6::NanRespondToDataPathIndicationRequest& msg) { - legacy_hal::NanDataPathIndicationResponse legacy_msg; - if (!hidl_struct_util::convertHidlNanDataPathIndicationResponse_1_6ToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::startPublishRequest_1_6Internal(uint16_t cmd_id, - const V1_6::NanPublishRequest& msg) { - legacy_hal::NanPublishRequest legacy_msg; - if (!hidl_struct_util::convertHidlNanPublishRequestToLegacy(msg, &legacy_msg)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiNanIface::registerEventCallback_1_6Internal( - const sp& callback) { - sp callback_1_0 = callback; - if (!event_cb_handler_.addCallback(callback_1_0)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - sp callback_1_2 = callback; - if (!event_cb_handler_1_2_.addCallback(callback_1_2)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - sp callback_1_5 = callback; - if (!event_cb_handler_1_5_.addCallback(callback_1_5)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - if (!event_cb_handler_1_6_.addCallback(callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android diff --git a/wifi/1.6/default/wifi_nan_iface.h b/wifi/1.6/default/wifi_nan_iface.h deleted file mode 100644 index 15bf57298c..0000000000 --- a/wifi/1.6/default/wifi_nan_iface.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_NAN_IFACE_H_ -#define WIFI_NAN_IFACE_H_ - -#include -#include -#include - -#include "hidl_callback_util.h" -#include "wifi_iface_util.h" -#include "wifi_legacy_hal.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; -using namespace android::hardware::wifi::V1_2; -using namespace android::hardware::wifi::V1_4; -using namespace android::hardware::wifi::V1_6; - -/** - * HIDL interface object used to control a NAN Iface instance. - */ -class WifiNanIface : public V1_6::IWifiNanIface { - public: - WifiNanIface(const std::string& ifname, bool is_dedicated_iface, - const std::weak_ptr legacy_hal, - const std::weak_ptr iface_util); - // Refer to |WifiChip::invalidate()|. - void invalidate(); - bool isValid(); - std::string getName(); - - // HIDL methods exposed. - Return getName(getName_cb hidl_status_cb) override; - Return getType(getType_cb hidl_status_cb) override; - Return registerEventCallback(const sp& callback, - registerEventCallback_cb hidl_status_cb) override; - Return getCapabilitiesRequest(uint16_t cmd_id, - getCapabilitiesRequest_cb hidl_status_cb) override; - Return enableRequest(uint16_t cmd_id, const V1_0::NanEnableRequest& msg, - enableRequest_cb hidl_status_cb) override; - Return configRequest(uint16_t cmd_id, const V1_0::NanConfigRequest& msg, - configRequest_cb hidl_status_cb) override; - Return disableRequest(uint16_t cmd_id, disableRequest_cb hidl_status_cb) override; - Return startPublishRequest(uint16_t cmd_id, const V1_0::NanPublishRequest& msg, - startPublishRequest_cb hidl_status_cb) override; - Return stopPublishRequest(uint16_t cmd_id, uint8_t sessionId, - stopPublishRequest_cb hidl_status_cb) override; - Return startSubscribeRequest(uint16_t cmd_id, const V1_0::NanSubscribeRequest& msg, - startSubscribeRequest_cb hidl_status_cb) override; - Return stopSubscribeRequest(uint16_t cmd_id, uint8_t sessionId, - stopSubscribeRequest_cb hidl_status_cb) override; - Return transmitFollowupRequest(uint16_t cmd_id, const NanTransmitFollowupRequest& msg, - transmitFollowupRequest_cb hidl_status_cb) override; - Return createDataInterfaceRequest(uint16_t cmd_id, const hidl_string& iface_name, - createDataInterfaceRequest_cb hidl_status_cb) override; - Return deleteDataInterfaceRequest(uint16_t cmd_id, const hidl_string& iface_name, - deleteDataInterfaceRequest_cb hidl_status_cb) override; - Return initiateDataPathRequest(uint16_t cmd_id, - const V1_0::NanInitiateDataPathRequest& msg, - initiateDataPathRequest_cb hidl_status_cb) override; - Return respondToDataPathIndicationRequest( - uint16_t cmd_id, const V1_0::NanRespondToDataPathIndicationRequest& msg, - respondToDataPathIndicationRequest_cb hidl_status_cb) override; - Return terminateDataPathRequest(uint16_t cmd_id, uint32_t ndpInstanceId, - terminateDataPathRequest_cb hidl_status_cb) override; - - Return registerEventCallback_1_2(const sp& callback, - registerEventCallback_1_2_cb hidl_status_cb) override; - Return enableRequest_1_2(uint16_t cmd_id, const V1_0::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - enableRequest_1_2_cb hidl_status_cb) override; - Return configRequest_1_2(uint16_t cmd_id, const V1_0::NanConfigRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - configRequest_1_2_cb hidl_status_cb) override; - Return enableRequest_1_4(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - enableRequest_1_4_cb hidl_status_cb) override; - Return configRequest_1_4(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2, - configRequest_1_4_cb hidl_status_cb) override; - Return registerEventCallback_1_5(const sp& callback, - registerEventCallback_1_5_cb hidl_status_cb) override; - Return enableRequest_1_5(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_5::NanConfigRequestSupplemental& msg2, - enableRequest_1_5_cb hidl_status_cb) override; - Return configRequest_1_5(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_5::NanConfigRequestSupplemental& msg2, - configRequest_1_5_cb hidl_status_cb) override; - Return getCapabilitiesRequest_1_5(uint16_t cmd_id, - getCapabilitiesRequest_cb hidl_status_cb) override; - Return registerEventCallback_1_6(const sp& callback, - registerEventCallback_1_6_cb hidl_status_cb) override; - Return initiateDataPathRequest_1_6( - uint16_t cmd_id, const V1_6::NanInitiateDataPathRequest& msg, - initiateDataPathRequest_1_6_cb hidl_status_cb) override; - Return respondToDataPathIndicationRequest_1_6( - uint16_t cmd_id, const V1_6::NanRespondToDataPathIndicationRequest& msg, - respondToDataPathIndicationRequest_1_6_cb hidl_status_cb) override; - Return enableRequest_1_6(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2, - enableRequest_1_6_cb hidl_status_cb) override; - Return configRequest_1_6(uint16_t cmd_id, const V1_4::NanConfigRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2, - configRequest_1_6_cb hidl_status_cb) override; - Return startPublishRequest_1_6(uint16_t cmd_id, const V1_6::NanPublishRequest& msg, - startPublishRequest_cb hidl_status_cb) override; - - private: - // Corresponding worker functions for the HIDL methods. - std::pair getNameInternal(); - std::pair getTypeInternal(); - WifiStatus registerEventCallbackInternal(const sp& callback); - WifiStatus getCapabilitiesRequestInternal(uint16_t cmd_id); - WifiStatus enableRequestInternal(uint16_t cmd_id, const V1_0::NanEnableRequest& msg); - WifiStatus configRequestInternal(uint16_t cmd_id, const V1_0::NanConfigRequest& msg); - WifiStatus disableRequestInternal(uint16_t cmd_id); - WifiStatus startPublishRequestInternal(uint16_t cmd_id, const V1_0::NanPublishRequest& msg); - WifiStatus stopPublishRequestInternal(uint16_t cmd_id, uint8_t sessionId); - WifiStatus startSubscribeRequestInternal(uint16_t cmd_id, const V1_0::NanSubscribeRequest& msg); - WifiStatus stopSubscribeRequestInternal(uint16_t cmd_id, uint8_t sessionId); - WifiStatus transmitFollowupRequestInternal(uint16_t cmd_id, - const NanTransmitFollowupRequest& msg); - WifiStatus createDataInterfaceRequestInternal(uint16_t cmd_id, const std::string& iface_name); - WifiStatus deleteDataInterfaceRequestInternal(uint16_t cmd_id, const std::string& iface_name); - WifiStatus initiateDataPathRequestInternal(uint16_t cmd_id, - const V1_0::NanInitiateDataPathRequest& msg); - WifiStatus respondToDataPathIndicationRequestInternal( - uint16_t cmd_id, const V1_0::NanRespondToDataPathIndicationRequest& msg); - WifiStatus terminateDataPathRequestInternal(uint16_t cmd_id, uint32_t ndpInstanceId); - - WifiStatus registerEventCallback_1_2Internal( - const sp& callback); - WifiStatus enableRequest_1_2Internal(uint16_t cmd_id, const V1_0::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2); - WifiStatus configRequest_1_2Internal(uint16_t cmd_id, const V1_0::NanConfigRequest& msg, - const V1_2::NanConfigRequestSupplemental& msg2); - WifiStatus enableRequest_1_4Internal(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_2::NanConfigRequestSupplemental& msg2); - WifiStatus configRequest_1_4Internal(uint16_t cmd_id, const V1_4::NanConfigRequest& msg, - const V1_2::NanConfigRequestSupplemental& msg2); - WifiStatus registerEventCallback_1_5Internal( - const sp& callback); - WifiStatus enableRequest_1_5Internal(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_5::NanConfigRequestSupplemental& msg2); - WifiStatus configRequest_1_5Internal(uint16_t cmd_id, const V1_4::NanConfigRequest& msg, - const V1_5::NanConfigRequestSupplemental& msg2); - WifiStatus getCapabilitiesRequest_1_5Internal(uint16_t cmd_id); - WifiStatus registerEventCallback_1_6Internal( - const sp& callback); - - WifiStatus enableRequest_1_6Internal(uint16_t cmd_id, const V1_4::NanEnableRequest& msg1, - const V1_6::NanConfigRequestSupplemental& msg2); - WifiStatus configRequest_1_6Internal(uint16_t cmd_id, const V1_4::NanConfigRequest& msg, - const V1_6::NanConfigRequestSupplemental& msg2); - WifiStatus startPublishRequest_1_6Internal(uint16_t cmd_id, const V1_6::NanPublishRequest& msg); - WifiStatus initiateDataPathRequest_1_6Internal(uint16_t cmd_id, - const V1_6::NanInitiateDataPathRequest& msg); - WifiStatus respondToDataPathIndicationRequest_1_6Internal( - uint16_t cmd_id, const V1_6::NanRespondToDataPathIndicationRequest& msg); - - // all 1_0 and descendant callbacks - std::set> getEventCallbacks(); - // all 1_2 and descendant callbacks - std::set> getEventCallbacks_1_2(); - // all 1_5 and descendant callbacks - std::set> getEventCallbacks_1_5(); - // all 1_6 and descendant callbacks - std::set> getEventCallbacks_1_6(); - - std::string ifname_; - bool is_dedicated_iface_; - std::weak_ptr legacy_hal_; - std::weak_ptr iface_util_; - bool is_valid_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_1_2_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_1_5_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_1_6_; - - DISALLOW_COPY_AND_ASSIGN(WifiNanIface); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_NAN_IFACE_H_ diff --git a/wifi/1.6/default/wifi_rtt_controller.cpp b/wifi/1.6/default/wifi_rtt_controller.cpp deleted file mode 100644 index aa9ee2f520..0000000000 --- a/wifi/1.6/default/wifi_rtt_controller.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#include - -#include "hidl_return_util.h" -#include "hidl_struct_util.h" -#include "wifi_rtt_controller.h" -#include "wifi_status_util.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; - -WifiRttController::WifiRttController(const std::string& iface_name, - const sp& bound_iface, - const std::weak_ptr legacy_hal) - : ifname_(iface_name), bound_iface_(bound_iface), legacy_hal_(legacy_hal), is_valid_(true) {} - -void WifiRttController::invalidate() { - legacy_hal_.reset(); - event_callbacks_.clear(); - is_valid_ = false; -} - -bool WifiRttController::isValid() { - return is_valid_; -} - -std::vector> WifiRttController::getEventCallbacks() { - return event_callbacks_; -} - -std::string WifiRttController::getIfaceName() { - return ifname_; -} - -Return WifiRttController::getBoundIface(getBoundIface_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::getBoundIfaceInternal, hidl_status_cb); -} - -Return WifiRttController::registerEventCallback( - const sp& callback, - registerEventCallback_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::registerEventCallbackInternal, hidl_status_cb, - callback); -} - -Return WifiRttController::rangeRequest(uint32_t cmd_id, - const hidl_vec& rtt_configs, - rangeRequest_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::rangeRequestInternal, hidl_status_cb, cmd_id, - rtt_configs); -} - -Return WifiRttController::rangeCancel(uint32_t cmd_id, - const hidl_vec>& addrs, - rangeCancel_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::rangeCancelInternal, hidl_status_cb, cmd_id, addrs); -} - -Return WifiRttController::getCapabilities(getCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::getCapabilitiesInternal, hidl_status_cb); -} - -Return WifiRttController::setLci(uint32_t cmd_id, const RttLciInformation& lci, - setLci_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::setLciInternal, hidl_status_cb, cmd_id, lci); -} - -Return WifiRttController::setLcr(uint32_t cmd_id, const RttLcrInformation& lcr, - setLcr_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::setLcrInternal, hidl_status_cb, cmd_id, lcr); -} - -Return WifiRttController::getResponderInfo(getResponderInfo_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::getResponderInfoInternal, hidl_status_cb); -} - -Return WifiRttController::enableResponder(uint32_t cmd_id, - const V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_0::RttResponder& info, - enableResponder_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::enableResponderInternal, hidl_status_cb, cmd_id, - channel_hint, max_duration_seconds, info); -} - -Return WifiRttController::disableResponder(uint32_t cmd_id, - disableResponder_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &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 V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_4::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); -} - -Return WifiRttController::registerEventCallback_1_6( - const sp& callback, - registerEventCallback_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::registerEventCallbackInternal_1_6, hidl_status_cb, - callback); -} - -Return WifiRttController::rangeRequest_1_6(uint32_t cmd_id, - const hidl_vec& rtt_configs, - rangeRequest_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::rangeRequestInternal_1_6, hidl_status_cb, cmd_id, - rtt_configs); -} - -Return WifiRttController::getCapabilities_1_6(getCapabilities_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::getCapabilitiesInternal_1_6, hidl_status_cb); -} - -Return WifiRttController::getResponderInfo_1_6(getResponderInfo_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::getResponderInfoInternal_1_6, hidl_status_cb); -} - -Return WifiRttController::enableResponder_1_6(uint32_t cmd_id, - const V1_6::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_6::RttResponder& info, - enableResponder_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, - &WifiRttController::enableResponderInternal_1_6, 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 */) { - // Deprecated support for this api - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiRttController::rangeRequestInternal( - uint32_t /* cmd_id */, const std::vector& /* rtt_configs */) { - // Deprecated support for this api - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiRttController::rangeCancelInternal( - uint32_t cmd_id, const std::vector>& addrs) { - std::vector> legacy_addrs; - for (const auto& addr : addrs) { - legacy_addrs.push_back(addr); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->cancelRttRangeRequest(ifname_, cmd_id, legacy_addrs); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair WifiRttController::getCapabilitiesInternal() { - // Deprecated support for this api - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -WifiStatus WifiRttController::setLciInternal(uint32_t cmd_id, const RttLciInformation& lci) { - legacy_hal::wifi_lci_information legacy_lci; - if (!hidl_struct_util::convertHidlRttLciInformationToLegacy(lci, &legacy_lci)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->setRttLci(ifname_, cmd_id, legacy_lci); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiRttController::setLcrInternal(uint32_t cmd_id, const RttLcrInformation& lcr) { - legacy_hal::wifi_lcr_information legacy_lcr; - if (!hidl_struct_util::convertHidlRttLcrInformationToLegacy(lcr, &legacy_lcr)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->setRttLcr(ifname_, cmd_id, legacy_lcr); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair WifiRttController::getResponderInfoInternal() { - // Deprecated support for this api - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -WifiStatus WifiRttController::enableResponderInternal( - uint32_t /* cmd_id */, const V1_0::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 */) { - // Deprecated support for this api - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiRttController::rangeRequestInternal_1_4( - uint32_t /* cmd_id */, const std::vector& /* rtt_configs */) { - // Deprecated support for this api - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -std::pair WifiRttController::getCapabilitiesInternal_1_4() { - // Deprecated support for this api - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -std::pair WifiRttController::getResponderInfoInternal_1_4() { - // Deprecated support for this api - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -WifiStatus WifiRttController::enableResponderInternal_1_4( - uint32_t /* cmd_id */, const V1_0::WifiChannelInfo& /* channel_hint */, - uint32_t /* max_duration_seconds */, const V1_4::RttResponder& /* info */) { - // Deprecated support for this api - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED)}; -} - -WifiStatus WifiRttController::registerEventCallbackInternal_1_6( - 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_6( - 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()) { - if (!callback->onResults_1_6(id, hidl_results).isOk()) { - LOG(ERROR) << "Failed to invoke the callback"; - } - } - }; - 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_6() { - 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), {}}; - } - V1_6::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_6() { - legacy_hal::wifi_error legacy_status; - legacy_hal::wifi_rtt_responder legacy_responder; - std::tie(legacy_status, legacy_responder) = legacy_hal_.lock()->getRttResponderInfo(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - V1_6::RttResponder hidl_responder; - if (!hidl_struct_util::convertLegacyRttResponderToHidl(legacy_responder, &hidl_responder)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_responder}; -} - -WifiStatus WifiRttController::enableResponderInternal_1_6(uint32_t cmd_id, - const V1_6::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_6::RttResponder& info) { - legacy_hal::wifi_channel_info legacy_channel_info; - if (!hidl_struct_util::convertHidlWifiChannelInfoToLegacy(channel_hint, &legacy_channel_info)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_rtt_responder legacy_responder; - if (!hidl_struct_util::convertHidlRttResponderToLegacy(info, &legacy_responder)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableRttResponder( - ifname_, cmd_id, legacy_channel_info, max_duration_seconds, legacy_responder); - return createWifiStatusFromLegacyError(legacy_status); -} -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android diff --git a/wifi/1.6/default/wifi_rtt_controller.h b/wifi/1.6/default/wifi_rtt_controller.h deleted file mode 100644 index fd5f68b6a8..0000000000 --- a/wifi/1.6/default/wifi_rtt_controller.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_RTT_CONTROLLER_H_ -#define WIFI_RTT_CONTROLLER_H_ - -#include -#include -#include -#include - -#include "wifi_legacy_hal.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { - -/** - * HIDL interface object used to control all RTT operations. - */ -class WifiRttController : public V1_6::IWifiRttController { - public: - WifiRttController(const std::string& iface_name, const sp& bound_iface, - const std::weak_ptr legacy_hal); - // Refer to |WifiChip::invalidate()|. - void invalidate(); - bool isValid(); - std::vector> getEventCallbacks(); - std::string getIfaceName(); - - // HIDL methods exposed. - Return getBoundIface(getBoundIface_cb hidl_status_cb) override; - Return registerEventCallback(const sp& callback, - registerEventCallback_cb hidl_status_cb) override; - Return rangeRequest(uint32_t cmd_id, const hidl_vec& rtt_configs, - rangeRequest_cb hidl_status_cb) override; - Return rangeCancel(uint32_t cmd_id, const hidl_vec>& addrs, - rangeCancel_cb hidl_status_cb) override; - Return getCapabilities(getCapabilities_cb hidl_status_cb) override; - Return setLci(uint32_t cmd_id, const RttLciInformation& lci, - setLci_cb hidl_status_cb) override; - Return setLcr(uint32_t cmd_id, const RttLcrInformation& lcr, - setLcr_cb hidl_status_cb) override; - Return getResponderInfo(getResponderInfo_cb hidl_status_cb) override; - Return enableResponder(uint32_t cmd_id, const V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, 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 V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, const V1_4::RttResponder& info, - enableResponder_1_4_cb hidl_status_cb) override; - Return registerEventCallback_1_6( - const sp& callback, - registerEventCallback_1_6_cb hidl_status_cb) override; - Return rangeRequest_1_6(uint32_t cmd_id, const hidl_vec& rtt_configs, - rangeRequest_1_6_cb hidl_status_cb) override; - Return getCapabilities_1_6(getCapabilities_1_6_cb hidl_status_cb) override; - Return getResponderInfo_1_6(getResponderInfo_1_6_cb hidl_status_cb) override; - Return enableResponder_1_6(uint32_t cmd_id, const V1_6::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, const V1_6::RttResponder& info, - enableResponder_1_6_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); - WifiStatus rangeCancelInternal(uint32_t cmd_id, - const std::vector>& addrs); - std::pair getCapabilitiesInternal(); - WifiStatus setLciInternal(uint32_t cmd_id, const RttLciInformation& lci); - WifiStatus setLcrInternal(uint32_t cmd_id, const RttLcrInformation& lcr); - std::pair getResponderInfoInternal(); - WifiStatus enableResponderInternal(uint32_t cmd_id, const V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - 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 V1_0::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_4::RttResponder& info); - WifiStatus registerEventCallbackInternal_1_6( - const sp& callback); - WifiStatus rangeRequestInternal_1_6(uint32_t cmd_id, - const std::vector& rtt_configs); - std::pair getCapabilitiesInternal_1_6(); - std::pair getResponderInfoInternal_1_6(); - WifiStatus enableResponderInternal_1_6(uint32_t cmd_id, - const V1_6::WifiChannelInfo& channel_hint, - uint32_t max_duration_seconds, - const V1_6::RttResponder& info); - - std::string ifname_; - sp bound_iface_; - std::weak_ptr legacy_hal_; - std::vector> event_callbacks_; - bool is_valid_; - - DISALLOW_COPY_AND_ASSIGN(WifiRttController); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_RTT_CONTROLLER_H_ diff --git a/wifi/1.6/default/wifi_sta_iface.cpp b/wifi/1.6/default/wifi_sta_iface.cpp deleted file mode 100644 index dd11839c97..0000000000 --- a/wifi/1.6/default/wifi_sta_iface.cpp +++ /dev/null @@ -1,592 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#include - -#include "hidl_return_util.h" -#include "hidl_struct_util.h" -#include "wifi_sta_iface.h" -#include "wifi_status_util.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; - -WifiStaIface::WifiStaIface(const std::string& ifname, - const std::weak_ptr legacy_hal, - const std::weak_ptr iface_util) - : ifname_(ifname), legacy_hal_(legacy_hal), iface_util_(iface_util), is_valid_(true) { - // Turn on DFS channel usage for STA iface. - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDfsFlag(ifname_, true); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - LOG(ERROR) << "Failed to set DFS flag; DFS channels may be unavailable."; - } -} - -void WifiStaIface::invalidate() { - legacy_hal_.reset(); - event_cb_handler_.invalidate(); - is_valid_ = false; -} - -bool WifiStaIface::isValid() { - return is_valid_; -} - -std::string WifiStaIface::getName() { - return ifname_; -} - -std::set> WifiStaIface::getEventCallbacks() { - return event_cb_handler_.getCallbacks(); -} - -Return WifiStaIface::getName(getName_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getNameInternal, hidl_status_cb); -} - -Return WifiStaIface::getType(getType_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getTypeInternal, hidl_status_cb); -} - -Return WifiStaIface::registerEventCallback(const sp& callback, - registerEventCallback_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::registerEventCallbackInternal, hidl_status_cb, callback); -} - -Return WifiStaIface::getCapabilities(getCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getCapabilitiesInternal, hidl_status_cb); -} - -Return WifiStaIface::getApfPacketFilterCapabilities( - getApfPacketFilterCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getApfPacketFilterCapabilitiesInternal, hidl_status_cb); -} - -Return WifiStaIface::installApfPacketFilter(uint32_t cmd_id, const hidl_vec& program, - installApfPacketFilter_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::installApfPacketFilterInternal, hidl_status_cb, cmd_id, - program); -} - -Return WifiStaIface::readApfPacketFilterData(readApfPacketFilterData_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::readApfPacketFilterDataInternal, hidl_status_cb); -} - -Return WifiStaIface::getBackgroundScanCapabilities( - getBackgroundScanCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getBackgroundScanCapabilitiesInternal, hidl_status_cb); -} - -Return WifiStaIface::getValidFrequenciesForBand( - V1_0::WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getValidFrequenciesForBandInternal, hidl_status_cb, band); -} - -Return WifiStaIface::startBackgroundScan(uint32_t cmd_id, - const StaBackgroundScanParameters& params, - startBackgroundScan_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::startBackgroundScanInternal, hidl_status_cb, cmd_id, - params); -} - -Return WifiStaIface::stopBackgroundScan(uint32_t cmd_id, - stopBackgroundScan_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::stopBackgroundScanInternal, hidl_status_cb, cmd_id); -} - -Return WifiStaIface::enableLinkLayerStatsCollection( - bool debug, enableLinkLayerStatsCollection_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::enableLinkLayerStatsCollectionInternal, hidl_status_cb, - debug); -} - -Return WifiStaIface::disableLinkLayerStatsCollection( - disableLinkLayerStatsCollection_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::disableLinkLayerStatsCollectionInternal, hidl_status_cb); -} - -Return WifiStaIface::getLinkLayerStats(getLinkLayerStats_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getLinkLayerStatsInternal, hidl_status_cb); -} - -Return WifiStaIface::getLinkLayerStats_1_3(getLinkLayerStats_1_3_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getLinkLayerStatsInternal_1_3, hidl_status_cb); -} - -Return WifiStaIface::getLinkLayerStats_1_5(getLinkLayerStats_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getLinkLayerStatsInternal_1_5, hidl_status_cb); -} - -Return WifiStaIface::getLinkLayerStats_1_6(getLinkLayerStats_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getLinkLayerStatsInternal_1_6, hidl_status_cb); -} - -Return WifiStaIface::startRssiMonitoring(uint32_t cmd_id, int32_t max_rssi, int32_t min_rssi, - startRssiMonitoring_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::startRssiMonitoringInternal, hidl_status_cb, cmd_id, - max_rssi, min_rssi); -} - -Return WifiStaIface::stopRssiMonitoring(uint32_t cmd_id, - stopRssiMonitoring_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::stopRssiMonitoringInternal, hidl_status_cb, cmd_id); -} - -Return WifiStaIface::getRoamingCapabilities(getRoamingCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getRoamingCapabilitiesInternal, hidl_status_cb); -} - -Return WifiStaIface::configureRoaming(const StaRoamingConfig& config, - configureRoaming_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::configureRoamingInternal, hidl_status_cb, config); -} - -Return WifiStaIface::setRoamingState(StaRoamingState state, - setRoamingState_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::setRoamingStateInternal, hidl_status_cb, state); -} - -Return WifiStaIface::enableNdOffload(bool enable, enableNdOffload_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::enableNdOffloadInternal, hidl_status_cb, enable); -} - -Return WifiStaIface::startSendingKeepAlivePackets( - uint32_t cmd_id, const hidl_vec& ip_packet_data, uint16_t ether_type, - const hidl_array& src_address, const hidl_array& dst_address, - uint32_t period_in_ms, startSendingKeepAlivePackets_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::startSendingKeepAlivePacketsInternal, hidl_status_cb, - cmd_id, ip_packet_data, ether_type, src_address, dst_address, - period_in_ms); -} - -Return WifiStaIface::stopSendingKeepAlivePackets( - uint32_t cmd_id, stopSendingKeepAlivePackets_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::stopSendingKeepAlivePacketsInternal, hidl_status_cb, - cmd_id); -} - -Return WifiStaIface::setScanningMacOui(const hidl_array& oui, - setScanningMacOui_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::setScanningMacOuiInternal, hidl_status_cb, oui); -} - -Return WifiStaIface::startDebugPacketFateMonitoring( - startDebugPacketFateMonitoring_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::startDebugPacketFateMonitoringInternal, hidl_status_cb); -} - -Return WifiStaIface::getDebugTxPacketFates(getDebugTxPacketFates_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getDebugTxPacketFatesInternal, hidl_status_cb); -} - -Return WifiStaIface::getDebugRxPacketFates(getDebugRxPacketFates_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getDebugRxPacketFatesInternal, hidl_status_cb); -} - -Return WifiStaIface::setMacAddress(const hidl_array& mac, - setMacAddress_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::setMacAddressInternal, hidl_status_cb, mac); -} - -Return WifiStaIface::getFactoryMacAddress(getFactoryMacAddress_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::getFactoryMacAddressInternal, hidl_status_cb); -} - -Return WifiStaIface::setScanMode(bool enable, setScanMode_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiStaIface::setScanModeInternal, hidl_status_cb, enable); -} - -std::pair WifiStaIface::getNameInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; -} - -std::pair WifiStaIface::getTypeInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::STA}; -} - -WifiStatus WifiStaIface::registerEventCallbackInternal( - const sp& callback) { - if (!event_cb_handler_.addCallback(callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -std::pair WifiStaIface::getCapabilitiesInternal() { - legacy_hal::wifi_error legacy_status; - uint64_t legacy_feature_set; - std::tie(legacy_status, legacy_feature_set) = - legacy_hal_.lock()->getSupportedFeatureSet(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), 0}; - } - uint32_t legacy_logger_feature_set; - 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::convertLegacyFeaturesToHidlStaCapabilities( - legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; -} - -std::pair -WifiStaIface::getApfPacketFilterCapabilitiesInternal() { - legacy_hal::wifi_error legacy_status; - legacy_hal::PacketFilterCapabilities legacy_caps; - std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getPacketFilterCapabilities(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - StaApfPacketFilterCapabilities hidl_caps; - if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; -} - -WifiStatus WifiStaIface::installApfPacketFilterInternal(uint32_t /* cmd_id */, - const std::vector& program) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setPacketFilter(ifname_, program); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair> WifiStaIface::readApfPacketFilterDataInternal() { - const std::pair> legacy_status_and_data = - legacy_hal_.lock()->readApfPacketFilterData(ifname_); - return {createWifiStatusFromLegacyError(legacy_status_and_data.first), - std::move(legacy_status_and_data.second)}; -} - -std::pair -WifiStaIface::getBackgroundScanCapabilitiesInternal() { - legacy_hal::wifi_error legacy_status; - legacy_hal::wifi_gscan_capabilities legacy_caps; - std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getGscanCapabilities(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - StaBackgroundScanCapabilities hidl_caps; - if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; -} - -std::pair> -WifiStaIface::getValidFrequenciesForBandInternal(V1_0::WifiBand band) { - static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); - legacy_hal::wifi_error legacy_status; - std::vector valid_frequencies; - std::tie(legacy_status, valid_frequencies) = legacy_hal_.lock()->getValidFrequenciesForBand( - ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band)); - return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; -} - -WifiStatus WifiStaIface::startBackgroundScanInternal(uint32_t cmd_id, - const StaBackgroundScanParameters& params) { - legacy_hal::wifi_scan_cmd_params legacy_params; - if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, &legacy_params)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - android::wp weak_ptr_this(this); - const auto& on_failure_callback = [weak_ptr_this](legacy_hal::wifi_request_id id) { - 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; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->onBackgroundScanFailure(id).isOk()) { - LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; - } - } - }; - 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_scan_datas; - if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( - results, &hidl_scan_datas)) { - LOG(ERROR) << "Failed to convert scan results to HIDL structs"; - return; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->onBackgroundScanResults(id, hidl_scan_datas).isOk()) { - LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; - } - } - }; - const auto& on_full_result_callback = [weak_ptr_this]( - legacy_hal::wifi_request_id id, - const legacy_hal::wifi_scan_result* result, - uint32_t buckets_scanned) { - 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; - } - StaScanResult hidl_scan_result; - if (!hidl_struct_util::convertLegacyGscanResultToHidl(*result, true, &hidl_scan_result)) { - LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; - return; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->onBackgroundFullScanResult(id, buckets_scanned, hidl_scan_result) - .isOk()) { - LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; - } - } - }; - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->startGscan(ifname_, cmd_id, legacy_params, on_failure_callback, - on_results_callback, on_full_result_callback); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableLinkLayerStats(ifname_, debug); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableLinkLayerStats(ifname_); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair WifiStaIface::getLinkLayerStatsInternal() { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -std::pair WifiStaIface::getLinkLayerStatsInternal_1_3() { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -std::pair WifiStaIface::getLinkLayerStatsInternal_1_5() { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -std::pair WifiStaIface::getLinkLayerStatsInternal_1_6() { - legacy_hal::wifi_error legacy_status; - legacy_hal::LinkLayerStats legacy_stats; - std::tie(legacy_status, legacy_stats) = legacy_hal_.lock()->getLinkLayerStats(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - V1_6::StaLinkLayerStats hidl_stats; - if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, &hidl_stats)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; -} - -WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, int32_t max_rssi, - int32_t min_rssi) { - android::wp weak_ptr_this(this); - const auto& on_threshold_breached_callback = [weak_ptr_this](legacy_hal::wifi_request_id id, - std::array bssid, - int8_t rssi) { - 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; - } - for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { - LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; - } - } - }; - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring( - ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair WifiStaIface::getRoamingCapabilitiesInternal() { - legacy_hal::wifi_error legacy_status; - legacy_hal::wifi_roaming_capabilities legacy_caps; - std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - StaRoamingCapabilities hidl_caps; - if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, &hidl_caps)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; -} - -WifiStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) { - legacy_hal::wifi_roaming_config legacy_config; - if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, &legacy_config)) { - return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); - } - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->configureRoaming(ifname_, legacy_config); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming( - ifname_, hidl_struct_util::convertHidlRoamingStateToLegacy(state)); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::startSendingKeepAlivePacketsInternal( - uint32_t cmd_id, const std::vector& ip_packet_data, uint16_t ether_type, - const std::array& src_address, const std::array& dst_address, - uint32_t period_in_ms) { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket( - ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(uint32_t cmd_id) { - legacy_hal::wifi_error legacy_status = - legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id); - return createWifiStatusFromLegacyError(legacy_status); -} - -WifiStatus WifiStaIface::setScanningMacOuiInternal(const std::array& /* oui */) { - // deprecated. - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair> -WifiStaIface::getDebugTxPacketFatesInternal() { - legacy_hal::wifi_error legacy_status; - std::vector legacy_fates; - std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - std::vector hidl_fates; - if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl(legacy_fates, - &hidl_fates)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; -} - -std::pair> -WifiStaIface::getDebugRxPacketFatesInternal() { - legacy_hal::wifi_error legacy_status; - std::vector legacy_fates; - std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; - } - std::vector hidl_fates; - if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl(legacy_fates, - &hidl_fates)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; -} - -WifiStatus WifiStaIface::setMacAddressInternal(const std::array& mac) { - bool status = iface_util_.lock()->setMacAddress(ifname_, mac); - if (!status) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -std::pair> WifiStaIface::getFactoryMacAddressInternal() { - std::array mac = iface_util_.lock()->getFactoryMacAddress(ifname_); - if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), mac}; - } - return {createWifiStatus(WifiStatusCode::SUCCESS), mac}; -} - -WifiStatus WifiStaIface::setScanModeInternal(bool enable) { - // OEM's need to implement this on their devices if needed. - LOG(WARNING) << "setScanModeInternal(" << enable << ") not supported"; - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android diff --git a/wifi/1.6/default/wifi_sta_iface.h b/wifi/1.6/default/wifi_sta_iface.h deleted file mode 100644 index c01c50b612..0000000000 --- a/wifi/1.6/default/wifi_sta_iface.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef WIFI_STA_IFACE_H_ -#define WIFI_STA_IFACE_H_ - -#include -#include -#include - -#include "hidl_callback_util.h" -#include "wifi_iface_util.h" -#include "wifi_legacy_hal.h" - -namespace android { -namespace hardware { -namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; - -/** - * HIDL interface object used to control a STA Iface instance. - */ -class WifiStaIface : public V1_6::IWifiStaIface { - public: - WifiStaIface(const std::string& ifname, - const std::weak_ptr legacy_hal, - const std::weak_ptr iface_util); - // Refer to |WifiChip::invalidate()|. - void invalidate(); - bool isValid(); - std::set> getEventCallbacks(); - std::string getName(); - - // HIDL methods exposed. - Return getName(getName_cb hidl_status_cb) override; - Return getType(getType_cb hidl_status_cb) override; - Return registerEventCallback(const sp& callback, - registerEventCallback_cb hidl_status_cb) override; - Return getCapabilities(getCapabilities_cb hidl_status_cb) override; - Return getApfPacketFilterCapabilities( - getApfPacketFilterCapabilities_cb hidl_status_cb) override; - Return installApfPacketFilter(uint32_t cmd_id, const hidl_vec& program, - installApfPacketFilter_cb hidl_status_cb) override; - Return readApfPacketFilterData(readApfPacketFilterData_cb hidl_status_cb) override; - Return getBackgroundScanCapabilities( - getBackgroundScanCapabilities_cb hidl_status_cb) override; - Return getValidFrequenciesForBand(V1_0::WifiBand band, - getValidFrequenciesForBand_cb hidl_status_cb) override; - Return startBackgroundScan(uint32_t cmd_id, const StaBackgroundScanParameters& params, - startBackgroundScan_cb hidl_status_cb) override; - Return stopBackgroundScan(uint32_t cmd_id, stopBackgroundScan_cb hidl_status_cb) override; - Return enableLinkLayerStatsCollection( - bool debug, enableLinkLayerStatsCollection_cb hidl_status_cb) override; - Return disableLinkLayerStatsCollection( - disableLinkLayerStatsCollection_cb hidl_status_cb) override; - Return getLinkLayerStats(getLinkLayerStats_cb hidl_status_cb) override; - Return getLinkLayerStats_1_3(getLinkLayerStats_1_3_cb hidl_status_cb) override; - Return getLinkLayerStats_1_5(getLinkLayerStats_1_5_cb hidl_status_cb) override; - Return getLinkLayerStats_1_6(getLinkLayerStats_1_6_cb hidl_status_cb) override; - Return startRssiMonitoring(uint32_t cmd_id, int32_t max_rssi, int32_t min_rssi, - startRssiMonitoring_cb hidl_status_cb) override; - Return stopRssiMonitoring(uint32_t cmd_id, stopRssiMonitoring_cb hidl_status_cb) override; - Return getRoamingCapabilities(getRoamingCapabilities_cb hidl_status_cb) override; - Return configureRoaming(const StaRoamingConfig& config, - configureRoaming_cb hidl_status_cb) override; - Return setRoamingState(StaRoamingState state, setRoamingState_cb hidl_status_cb) override; - Return enableNdOffload(bool enable, enableNdOffload_cb hidl_status_cb) override; - Return startSendingKeepAlivePackets( - uint32_t cmd_id, const hidl_vec& ip_packet_data, uint16_t ether_type, - const hidl_array& src_address, const hidl_array& dst_address, - uint32_t period_in_ms, startSendingKeepAlivePackets_cb hidl_status_cb) override; - Return stopSendingKeepAlivePackets( - uint32_t cmd_id, stopSendingKeepAlivePackets_cb hidl_status_cb) override; - Return setScanningMacOui(const hidl_array& oui, - setScanningMacOui_cb hidl_status_cb) override; - Return startDebugPacketFateMonitoring( - startDebugPacketFateMonitoring_cb hidl_status_cb) override; - Return getDebugTxPacketFates(getDebugTxPacketFates_cb hidl_status_cb) override; - Return getDebugRxPacketFates(getDebugRxPacketFates_cb hidl_status_cb) override; - Return setMacAddress(const hidl_array& mac, - setMacAddress_cb hidl_status_cb) override; - Return getFactoryMacAddress(getFactoryMacAddress_cb hidl_status_cb) override; - Return setScanMode(bool enable, setScanMode_cb hidl_status_cb) override; - - private: - // Corresponding worker functions for the HIDL methods. - std::pair getNameInternal(); - std::pair getTypeInternal(); - WifiStatus registerEventCallbackInternal(const sp& callback); - std::pair getCapabilitiesInternal(); - std::pair getApfPacketFilterCapabilitiesInternal(); - WifiStatus installApfPacketFilterInternal(uint32_t cmd_id, const std::vector& program); - std::pair> readApfPacketFilterDataInternal(); - std::pair getBackgroundScanCapabilitiesInternal(); - std::pair> getValidFrequenciesForBandInternal( - V1_0::WifiBand band); - WifiStatus startBackgroundScanInternal(uint32_t cmd_id, - const StaBackgroundScanParameters& params); - WifiStatus stopBackgroundScanInternal(uint32_t cmd_id); - WifiStatus enableLinkLayerStatsCollectionInternal(bool debug); - WifiStatus disableLinkLayerStatsCollectionInternal(); - std::pair getLinkLayerStatsInternal(); - std::pair getLinkLayerStatsInternal_1_3(); - std::pair getLinkLayerStatsInternal_1_5(); - std::pair getLinkLayerStatsInternal_1_6(); - WifiStatus startRssiMonitoringInternal(uint32_t cmd_id, int32_t max_rssi, int32_t min_rssi); - WifiStatus stopRssiMonitoringInternal(uint32_t cmd_id); - std::pair getRoamingCapabilitiesInternal(); - WifiStatus configureRoamingInternal(const StaRoamingConfig& config); - WifiStatus setRoamingStateInternal(StaRoamingState state); - WifiStatus enableNdOffloadInternal(bool enable); - WifiStatus startSendingKeepAlivePacketsInternal(uint32_t cmd_id, - const std::vector& ip_packet_data, - uint16_t ether_type, - const std::array& src_address, - const std::array& dst_address, - uint32_t period_in_ms); - WifiStatus stopSendingKeepAlivePacketsInternal(uint32_t cmd_id); - WifiStatus setScanningMacOuiInternal(const std::array& oui); - WifiStatus startDebugPacketFateMonitoringInternal(); - std::pair> getDebugTxPacketFatesInternal(); - std::pair> getDebugRxPacketFatesInternal(); - WifiStatus setMacAddressInternal(const std::array& mac); - std::pair> getFactoryMacAddressInternal(); - WifiStatus setScanModeInternal(bool enable); - - std::string ifname_; - std::weak_ptr legacy_hal_; - std::weak_ptr iface_util_; - bool is_valid_; - hidl_callback_util::HidlCallbackHandler event_cb_handler_; - - DISALLOW_COPY_AND_ASSIGN(WifiStaIface); -}; - -} // namespace implementation -} // namespace V1_6 -} // namespace wifi -} // namespace hardware -} // namespace android - -#endif // WIFI_STA_IFACE_H_ diff --git a/wifi/1.6/default/Android.bp b/wifi/aidl/default/Android.bp similarity index 67% rename from wifi/1.6/default/Android.bp rename to wifi/aidl/default/Android.bp index 0f98e71445..441d461b78 100644 --- a/wifi/1.6/default/Android.bp +++ b/wifi/aidl/default/Android.bp @@ -1,4 +1,4 @@ -// Copyright (C) 2021 The Android Open Source Project +// Copyright (C) 2022 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. @@ -36,7 +36,7 @@ soong_config_module_type { } wifi_hal_cc_defaults { - name: "android.hardware.wifi@1.0-service-cppflags-defaults", + name: "android.hardware.wifi-service-cppflags-defaults", soong_config_variables: { hidl_feature_aware: { cppflags: ["-DWIFI_HIDL_FEATURE_AWARE"], @@ -60,8 +60,8 @@ wifi_hal_cc_defaults { } cc_library_static { - name: "android.hardware.wifi@1.0-service-lib", - defaults: ["android.hardware.wifi@1.0-service-cppflags-defaults"], + name: "android.hardware.wifi-service-lib", + defaults: ["android.hardware.wifi-service-cppflags-defaults"], proprietary: true, compile_multilib: "first", cppflags: [ @@ -72,8 +72,8 @@ cc_library_static { // Allow implicit fallthroughs in wifi_legacy_hal.cpp until they are fixed. cflags: ["-Wno-error=implicit-fallthrough"], srcs: [ - "hidl_struct_util.cpp", - "hidl_sync_util.cpp", + "aidl_struct_util.cpp", + "aidl_sync_util.cpp", "ringbuffer.cpp", "wifi.cpp", "wifi_ap_iface.cpp", @@ -93,29 +93,23 @@ cc_library_static { shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", - "libhidlbase", "liblog", "libnl", "libutils", "libwifi-hal", "libwifi-system-iface", "libxml2", - "android.hardware.wifi@1.0", - "android.hardware.wifi@1.1", - "android.hardware.wifi@1.2", - "android.hardware.wifi@1.3", - "android.hardware.wifi@1.4", - "android.hardware.wifi@1.5", - "android.hardware.wifi@1.6", + "android.hardware.wifi-V1-ndk", ], export_include_dirs: ["."], } cc_binary { - name: "android.hardware.wifi@1.0-service", - vintf_fragments: ["android.hardware.wifi@1.0-service.xml"], + name: "android.hardware.wifi-service", + vintf_fragments: ["android.hardware.wifi-service.xml"], relative_install_path: "hw", proprietary: true, cppflags: [ @@ -126,30 +120,24 @@ cc_binary { srcs: ["service.cpp"], shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", - "libhidlbase", "liblog", "libnl", "libutils", "libwifi-hal", "libwifi-system-iface", "libxml2", - "android.hardware.wifi@1.0", - "android.hardware.wifi@1.1", - "android.hardware.wifi@1.2", - "android.hardware.wifi@1.3", - "android.hardware.wifi@1.4", - "android.hardware.wifi@1.5", - "android.hardware.wifi@1.6", + "android.hardware.wifi-V1-ndk", ], - static_libs: ["android.hardware.wifi@1.0-service-lib"], - init_rc: ["android.hardware.wifi@1.0-service.rc"], + static_libs: ["android.hardware.wifi-service-lib"], + init_rc: ["android.hardware.wifi-service.rc"], } cc_binary { - name: "android.hardware.wifi@1.0-service-lazy", - vintf_fragments: ["android.hardware.wifi@1.0-service.xml"], - overrides: ["android.hardware.wifi@1.0-service"], + name: "android.hardware.wifi-service-lazy", + vintf_fragments: ["android.hardware.wifi-service.xml"], + overrides: ["android.hardware.wifi-service"], cflags: ["-DLAZY_SERVICE"], relative_install_path: "hw", proprietary: true, @@ -161,28 +149,22 @@ cc_binary { srcs: ["service.cpp"], shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", - "libhidlbase", "liblog", "libnl", "libutils", "libwifi-hal", "libwifi-system-iface", "libxml2", - "android.hardware.wifi@1.0", - "android.hardware.wifi@1.1", - "android.hardware.wifi@1.2", - "android.hardware.wifi@1.3", - "android.hardware.wifi@1.4", - "android.hardware.wifi@1.5", - "android.hardware.wifi@1.6", + "android.hardware.wifi-V1-ndk", ], - static_libs: ["android.hardware.wifi@1.0-service-lib"], - init_rc: ["android.hardware.wifi@1.0-service-lazy.rc"], + static_libs: ["android.hardware.wifi-service-lib"], + init_rc: ["android.hardware.wifi-service-lazy.rc"], } cc_test { - name: "android.hardware.wifi@1.0-service-tests", + name: "android.hardware.wifi-service-tests", proprietary: true, compile_multilib: "first", cppflags: [ @@ -191,7 +173,7 @@ cc_test { "-Wextra", ], srcs: [ - "tests/hidl_struct_util_unit_tests.cpp", + "tests/aidl_struct_util_unit_tests.cpp", "tests/main.cpp", "tests/mock_interface_tool.cpp", "tests/mock_wifi_feature_flags.cpp", @@ -206,19 +188,13 @@ cc_test { static_libs: [ "libgmock", "libgtest", - "android.hardware.wifi@1.0", - "android.hardware.wifi@1.1", - "android.hardware.wifi@1.2", - "android.hardware.wifi@1.3", - "android.hardware.wifi@1.4", - "android.hardware.wifi@1.5", - "android.hardware.wifi@1.6", - "android.hardware.wifi@1.0-service-lib", + "android.hardware.wifi-V1-ndk", + "android.hardware.wifi-service-lib", ], shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", - "libhidlbase", "liblog", "libnl", "libutils", @@ -228,11 +204,11 @@ cc_test { } filegroup { - name: "default-android.hardware.wifi@1.0-service.rc", - srcs: ["android.hardware.wifi@1.0-service.rc"], + name: "default-android.hardware.wifi-service.rc", + srcs: ["android.hardware.wifi-service.rc"], } filegroup { - name: "default-android.hardware.wifi@1.0-service.xml", - srcs: ["android.hardware.wifi@1.0-service.xml"], + name: "default-android.hardware.wifi-service.xml", + srcs: ["android.hardware.wifi-service.xml"], } diff --git a/wifi/1.6/default/THREADING.README b/wifi/aidl/default/THREADING.README similarity index 82% rename from wifi/1.6/default/THREADING.README rename to wifi/aidl/default/THREADING.README index 8366ca0201..45679da069 100644 --- a/wifi/1.6/default/THREADING.README +++ b/wifi/aidl/default/THREADING.README @@ -1,7 +1,7 @@ Vendor HAL Threading Model ========================== The vendor HAL service has two threads: -1. HIDL thread: This is the main thread which processes all the incoming HIDL +1. AIDL thread: This is the main thread which processes all the incoming AIDL RPC's. 2. Legacy HAL event loop thread: This is the thread forked off for processing the legacy HAL event loop (wifi_event_loop()). This thread is used to process @@ -11,9 +11,9 @@ callbacks passed to the legacy HAL API's are invoked on this thread. Synchronization Concerns ======================== wifi_legacy_hal.cpp has a bunch of global "C" style functions to handle the -legacy callbacks. Each of these "C" style function invokes a corresponding +legacy callbacks. Each of these "C" style functions invokes a corresponding "std::function" version of the callback which does the actual processing. -The variables holding these "std::function" callbacks are reset from the HIDL +The variables holding these "std::function" callbacks are reset from the AIDL thread when they are no longer used. For example: stopGscan() will reset the corresponding "on_gscan_*" callback variables which were set when startGscan() was invoked. This is not thread safe since these callback variables are @@ -24,12 +24,12 @@ Synchronization Solution Adding a global lock seems to be the most trivial solution to the problem. a) All of the asynchronous "C" style callbacks will acquire the global lock before invoking the corresponding "std::function" callback variables. -b) All of the HIDL methods will also acquire the global lock before processing -(in hidl_return_util::validateAndCall()). +b) All of the AIDL methods will also acquire the global lock before processing +(in aidl_return_util::validateAndCall()). Note: It's important that we only acquire the global lock for asynchronous callbacks, because there is no guarantee (or documentation to clarify) that the synchronous callbacks are invoked on the same invocation thread. If that is not the case in some implementation, we will end up deadlocking the system since the -HIDL thread would have acquired the global lock which is needed by the +AIDL thread would have acquired the global lock which is needed by the synchronous callback executed on the legacy hal event loop thread. diff --git a/wifi/aidl/default/aidl_callback_util.h b/wifi/aidl/default/aidl_callback_util.h new file mode 100644 index 0000000000..41d70a53aa --- /dev/null +++ b/wifi/aidl/default/aidl_callback_util.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef AIDL_CALLBACK_UTIL_H_ +#define AIDL_CALLBACK_UTIL_H_ + +#include + +#include +#include + +namespace { +std::unordered_map callback_handler_map_; +} + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +namespace aidl_callback_util { + +// Provides a class to manage callbacks for the various AIDL interfaces and +// handle the death of the process hosting each callback. +template +class AidlCallbackHandler { + public: + AidlCallbackHandler() { + death_handler_ = AIBinder_DeathRecipient_new(AidlCallbackHandler::onCallbackDeath); + } + ~AidlCallbackHandler() { invalidate(); } + + bool addCallback(const std::shared_ptr& cb) { + void* cbPtr = reinterpret_cast(cb->asBinder().get()); + const auto& cbPosition = findCbInSet(cbPtr); + if (cbPosition != cb_set_.end()) { + LOG(WARNING) << "Duplicate death notification registration"; + return true; + } + + if (AIBinder_linkToDeath(cb->asBinder().get(), death_handler_, cbPtr /* cookie */) != + STATUS_OK) { + LOG(ERROR) << "Failed to register death notification"; + return false; + } + + callback_handler_map_[cbPtr] = reinterpret_cast(this); + cb_set_.insert(cb); + return true; + } + + const std::set>& getCallbacks() { return cb_set_; } + + void invalidate() { + for (auto cb : cb_set_) { + void* cookie = reinterpret_cast(cb->asBinder().get()); + if (AIBinder_unlinkToDeath(cb->asBinder().get(), death_handler_, cookie) != STATUS_OK) { + LOG(ERROR) << "Failed to deregister death notification"; + } + if (!removeCbFromHandlerMap(cookie)) { + LOG(ERROR) << "Failed to remove callback from handler map"; + } + } + cb_set_.clear(); + } + + // Entry point for the death handling logic. AIBinder_DeathRecipient + // can only call a static function, so use the cookie to find the + // proper handler and route the request there. + static void onCallbackDeath(void* cookie) { + auto cbQuery = callback_handler_map_.find(cookie); + if (cbQuery == callback_handler_map_.end()) { + LOG(ERROR) << "Invalid death cookie received"; + return; + } + + AidlCallbackHandler* cbHandler = reinterpret_cast(cbQuery->second); + if (cbHandler == nullptr) { + LOG(ERROR) << "Handler mapping contained an invalid handler"; + return; + } + cbHandler->handleCallbackDeath(cbQuery->first); + } + + private: + std::set> cb_set_; + AIBinder_DeathRecipient* death_handler_; + + typename std::set>::iterator findCbInSet(void* cbPtr) { + const auto& cbPosition = std::find_if( + cb_set_.begin(), cb_set_.end(), [cbPtr](const std::shared_ptr& p) { + return cbPtr == reinterpret_cast(p->asBinder().get()); + }); + return cbPosition; + } + + bool removeCbFromHandlerMap(void* cbPtr) { + auto cbQuery = callback_handler_map_.find(cbPtr); + if (cbQuery != callback_handler_map_.end()) { + callback_handler_map_.erase(cbQuery); + return true; + } + return false; + } + + void handleCallbackDeath(void* cbPtr) { + const auto& cbPosition = findCbInSet(cbPtr); + if (cbPosition == cb_set_.end()) { + LOG(ERROR) << "Unknown callback death notification received"; + return; + } + cb_set_.erase(cbPosition); + + if (!removeCbFromHandlerMap(cbPtr)) { + LOG(ERROR) << "Callback was not in callback handler map"; + } + } + + DISALLOW_COPY_AND_ASSIGN(AidlCallbackHandler); +}; + +} // namespace aidl_callback_util +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // AIDL_CALLBACK_UTIL_H_ diff --git a/wifi/aidl/default/aidl_return_util.h b/wifi/aidl/default/aidl_return_util.h new file mode 100644 index 0000000000..9a49a22e2a --- /dev/null +++ b/wifi/aidl/default/aidl_return_util.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef AIDL_RETURN_UTIL_H_ +#define AIDL_RETURN_UTIL_H_ + +#include "aidl_sync_util.h" +#include "wifi_status_util.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +namespace aidl_return_util { +using aidl::android::hardware::wifi::WifiStatusCode; +using aidl::android::hardware::wifi::aidl_sync_util::acquireGlobalLock; + +/** + * These utility functions are used to invoke a method on the provided + * AIDL interface object. + * These functions checks if the provided AIDL interface object is valid. + * a) If valid, Invokes the corresponding internal implementation function of + * the AIDL method. + * b) If invalid, return without calling the internal implementation function. + */ + +// Use for AIDL methods which return only an AIDL status. +template +::ndk::ScopedAStatus validateAndCall(ObjT* obj, WifiStatusCode status_code_if_invalid, + WorkFuncT&& work, Args&&... args) { + const auto lock = acquireGlobalLock(); + if (obj->isValid()) { + return (obj->*work)(std::forward(args)...); + } else { + return createWifiStatus(status_code_if_invalid); + } +} + +// Use for AIDL methods which return only an AIDL status. +// This version passes the global lock acquired to the body of the method. +template +::ndk::ScopedAStatus validateAndCallWithLock(ObjT* obj, WifiStatusCode status_code_if_invalid, + WorkFuncT&& work, Args&&... args) { + auto lock = acquireGlobalLock(); + if (obj->isValid()) { + return (obj->*work)(&lock, std::forward(args)...); + } else { + return createWifiStatus(status_code_if_invalid); + } +} + +// Use for AIDL methods which have a return value along with the AIDL status +template +::ndk::ScopedAStatus validateAndCall(ObjT* obj, WifiStatusCode status_code_if_invalid, + WorkFuncT&& work, ReturnT* ret_val, Args&&... args) { + const auto lock = acquireGlobalLock(); + if (obj->isValid()) { + auto call_pair = (obj->*work)(std::forward(args)...); + *ret_val = call_pair.first; + return std::forward<::ndk::ScopedAStatus>(call_pair.second); + } else { + return ndk::ScopedAStatus::fromServiceSpecificError( + static_cast(status_code_if_invalid)); + } +} + +} // namespace aidl_return_util +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl +#endif // AIDL_RETURN_UTIL_H_ diff --git a/wifi/aidl/default/aidl_struct_util.cpp b/wifi/aidl/default/aidl_struct_util.cpp new file mode 100644 index 0000000000..07612b65c5 --- /dev/null +++ b/wifi/aidl/default/aidl_struct_util.cpp @@ -0,0 +1,2775 @@ +/* + * Copyright (C) 2022 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. + */ + +#include +#include + +#include "aidl_struct_util.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +namespace aidl_struct_util { + +WifiChannelWidthInMhz convertLegacyWifiChannelWidthToAidl(legacy_hal::wifi_channel_width type); + +std::string safeConvertChar(const char* str, size_t max_len) { + const char* c = str; + size_t size = 0; + while (*c && (unsigned char)*c < 128 && size < max_len) { + ++size; + ++c; + } + return std::string(str, size); +} + +inline std::vector uintToIntVec(const std::vector& in) { + return std::vector(in.begin(), in.end()); +} + +IWifiChip::ChipCapabilityMask convertLegacyLoggerFeatureToAidlChipCapability(uint32_t feature) { + switch (feature) { + case legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED: + return IWifiChip::ChipCapabilityMask::DEBUG_MEMORY_FIRMWARE_DUMP; + case legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED: + return IWifiChip::ChipCapabilityMask::DEBUG_MEMORY_DRIVER_DUMP; + case legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED: + return IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_CONNECT_EVENT; + case legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED: + return IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_POWER_EVENT; + case legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED: + return IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_WAKELOCK_EVENT; + }; + CHECK(false) << "Unknown legacy feature: " << feature; + return {}; +} + +IWifiStaIface::StaIfaceCapabilityMask convertLegacyLoggerFeatureToAidlStaIfaceCapability( + uint32_t feature) { + switch (feature) { + case legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED: + return IWifiStaIface::StaIfaceCapabilityMask::DEBUG_PACKET_FATE; + }; + CHECK(false) << "Unknown legacy feature: " << feature; + return {}; +} + +IWifiChip::ChipCapabilityMask convertLegacyFeatureToAidlChipCapability(uint64_t feature) { + switch (feature) { + case WIFI_FEATURE_SET_TX_POWER_LIMIT: + return IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT; + case WIFI_FEATURE_USE_BODY_HEAD_SAR: + return IWifiChip::ChipCapabilityMask::USE_BODY_HEAD_SAR; + case WIFI_FEATURE_D2D_RTT: + return IWifiChip::ChipCapabilityMask::D2D_RTT; + case WIFI_FEATURE_D2AP_RTT: + return IWifiChip::ChipCapabilityMask::D2AP_RTT; + case WIFI_FEATURE_INFRA_60G: + return IWifiChip::ChipCapabilityMask::WIGIG; + case WIFI_FEATURE_SET_LATENCY_MODE: + return IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE; + case WIFI_FEATURE_P2P_RAND_MAC: + return IWifiChip::ChipCapabilityMask::P2P_RAND_MAC; + }; + CHECK(false) << "Unknown legacy feature: " << feature; + return {}; +} + +IWifiStaIface::StaIfaceCapabilityMask convertLegacyFeatureToAidlStaIfaceCapability( + uint64_t feature) { + switch (feature) { + case WIFI_FEATURE_GSCAN: + return IWifiStaIface::StaIfaceCapabilityMask::BACKGROUND_SCAN; + case WIFI_FEATURE_LINK_LAYER_STATS: + return IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS; + case WIFI_FEATURE_RSSI_MONITOR: + return IWifiStaIface::StaIfaceCapabilityMask::RSSI_MONITOR; + case WIFI_FEATURE_CONTROL_ROAMING: + return IWifiStaIface::StaIfaceCapabilityMask::CONTROL_ROAMING; + case WIFI_FEATURE_IE_WHITELIST: + return IWifiStaIface::StaIfaceCapabilityMask::PROBE_IE_ALLOWLIST; + case WIFI_FEATURE_SCAN_RAND: + return IWifiStaIface::StaIfaceCapabilityMask::SCAN_RAND; + case WIFI_FEATURE_INFRA_5G: + return IWifiStaIface::StaIfaceCapabilityMask::STA_5G; + case WIFI_FEATURE_HOTSPOT: + return IWifiStaIface::StaIfaceCapabilityMask::HOTSPOT; + case WIFI_FEATURE_PNO: + return IWifiStaIface::StaIfaceCapabilityMask::PNO; + case WIFI_FEATURE_TDLS: + return IWifiStaIface::StaIfaceCapabilityMask::TDLS; + case WIFI_FEATURE_TDLS_OFFCHANNEL: + return IWifiStaIface::StaIfaceCapabilityMask::TDLS_OFFCHANNEL; + case WIFI_FEATURE_CONFIG_NDO: + return IWifiStaIface::StaIfaceCapabilityMask::ND_OFFLOAD; + case WIFI_FEATURE_MKEEP_ALIVE: + return IWifiStaIface::StaIfaceCapabilityMask::KEEP_ALIVE; + }; + CHECK(false) << "Unknown legacy feature: " << feature; + return {}; +} + +bool convertLegacyFeaturesToAidlChipCapabilities(uint64_t legacy_feature_set, + uint32_t legacy_logger_feature_set, + uint32_t* aidl_caps) { + if (!aidl_caps) { + return false; + } + *aidl_caps = {}; + for (const auto feature : {legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED, + legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED, + legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED, + legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED, + legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED}) { + if (feature & legacy_logger_feature_set) { + *aidl_caps |= + static_cast(convertLegacyLoggerFeatureToAidlChipCapability(feature)); + } + } + std::vector features = {WIFI_FEATURE_SET_TX_POWER_LIMIT, + WIFI_FEATURE_USE_BODY_HEAD_SAR, + WIFI_FEATURE_D2D_RTT, + WIFI_FEATURE_D2AP_RTT, + WIFI_FEATURE_INFRA_60G, + WIFI_FEATURE_SET_LATENCY_MODE, + WIFI_FEATURE_P2P_RAND_MAC}; + for (const auto feature : features) { + if (feature & legacy_feature_set) { + *aidl_caps |= static_cast(convertLegacyFeatureToAidlChipCapability(feature)); + } + } + + // There are no flags for these 3 in the legacy feature set. Adding them to + // the set because all the current devices support it. + *aidl_caps |= + static_cast(IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_VENDOR_DATA); + *aidl_caps |= + static_cast(IWifiChip::ChipCapabilityMask::DEBUG_HOST_WAKE_REASON_STATS); + *aidl_caps |= static_cast(IWifiChip::ChipCapabilityMask::DEBUG_ERROR_ALERTS); + return true; +} + +WifiDebugRingBufferFlags convertLegacyDebugRingBufferFlagsToAidl(uint32_t flag) { + switch (flag) { + case WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES: + return WifiDebugRingBufferFlags::HAS_BINARY_ENTRIES; + case WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES: + return WifiDebugRingBufferFlags::HAS_ASCII_ENTRIES; + }; + CHECK(false) << "Unknown legacy flag: " << flag; + return {}; +} + +bool convertLegacyDebugRingBufferStatusToAidl( + const legacy_hal::wifi_ring_buffer_status& legacy_status, + WifiDebugRingBufferStatus* aidl_status) { + if (!aidl_status) { + return false; + } + *aidl_status = {}; + aidl_status->ringName = safeConvertChar(reinterpret_cast(legacy_status.name), + sizeof(legacy_status.name)); + aidl_status->flags = 0; + for (const auto flag : + {WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES, WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES}) { + if (flag & legacy_status.flags) { + aidl_status->flags |= static_cast::type>( + convertLegacyDebugRingBufferFlagsToAidl(flag)); + } + } + aidl_status->ringId = legacy_status.ring_id; + aidl_status->sizeInBytes = legacy_status.ring_buffer_byte_size; + // Calculate free size of the ring the buffer. We don't need to send the + // exact read/write pointers that were there in the legacy HAL interface. + if (legacy_status.written_bytes >= legacy_status.read_bytes) { + aidl_status->freeSizeInBytes = legacy_status.ring_buffer_byte_size - + (legacy_status.written_bytes - legacy_status.read_bytes); + } else { + aidl_status->freeSizeInBytes = legacy_status.read_bytes - legacy_status.written_bytes; + } + aidl_status->verboseLevel = legacy_status.verbose_level; + return true; +} + +bool convertLegacyVectorOfDebugRingBufferStatusToAidl( + const std::vector& legacy_status_vec, + std::vector* aidl_status_vec) { + if (!aidl_status_vec) { + return false; + } + *aidl_status_vec = {}; + for (const auto& legacy_status : legacy_status_vec) { + WifiDebugRingBufferStatus aidl_status; + if (!convertLegacyDebugRingBufferStatusToAidl(legacy_status, &aidl_status)) { + return false; + } + aidl_status_vec->push_back(aidl_status); + } + return true; +} + +bool convertLegacyWakeReasonStatsToAidl(const legacy_hal::WakeReasonStats& legacy_stats, + WifiDebugHostWakeReasonStats* aidl_stats) { + if (!aidl_stats) { + return false; + } + *aidl_stats = {}; + aidl_stats->totalCmdEventWakeCnt = legacy_stats.wake_reason_cnt.total_cmd_event_wake; + aidl_stats->cmdEventWakeCntPerType = uintToIntVec(legacy_stats.cmd_event_wake_cnt); + aidl_stats->totalDriverFwLocalWakeCnt = legacy_stats.wake_reason_cnt.total_driver_fw_local_wake; + aidl_stats->driverFwLocalWakeCntPerType = uintToIntVec(legacy_stats.driver_fw_local_wake_cnt); + aidl_stats->totalRxPacketWakeCnt = legacy_stats.wake_reason_cnt.total_rx_data_wake; + aidl_stats->rxPktWakeDetails.rxUnicastCnt = + legacy_stats.wake_reason_cnt.rx_wake_details.rx_unicast_cnt; + aidl_stats->rxPktWakeDetails.rxMulticastCnt = + legacy_stats.wake_reason_cnt.rx_wake_details.rx_multicast_cnt; + aidl_stats->rxPktWakeDetails.rxBroadcastCnt = + legacy_stats.wake_reason_cnt.rx_wake_details.rx_broadcast_cnt; + aidl_stats->rxMulticastPkWakeDetails.ipv4RxMulticastAddrCnt = + legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv4_rx_multicast_addr_cnt; + aidl_stats->rxMulticastPkWakeDetails.ipv6RxMulticastAddrCnt = + legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv6_rx_multicast_addr_cnt; + aidl_stats->rxMulticastPkWakeDetails.otherRxMulticastAddrCnt = + legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.other_rx_multicast_addr_cnt; + aidl_stats->rxIcmpPkWakeDetails.icmpPkt = + legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp_pkt; + aidl_stats->rxIcmpPkWakeDetails.icmp6Pkt = + legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_pkt; + aidl_stats->rxIcmpPkWakeDetails.icmp6Ra = + legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ra; + aidl_stats->rxIcmpPkWakeDetails.icmp6Na = + legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_na; + aidl_stats->rxIcmpPkWakeDetails.icmp6Ns = + legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ns; + return true; +} + +legacy_hal::wifi_power_scenario convertAidlTxPowerScenarioToLegacy( + IWifiChip::TxPowerScenario aidl_scenario) { + switch (aidl_scenario) { + case IWifiChip::TxPowerScenario::VOICE_CALL: + return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; + case IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF: + return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF; + case IWifiChip::TxPowerScenario::ON_HEAD_CELL_ON: + return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON; + case IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF: + return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF; + case IWifiChip::TxPowerScenario::ON_BODY_CELL_ON: + return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON; + }; + CHECK(false); +} + +legacy_hal::wifi_latency_mode convertAidlLatencyModeToLegacy( + IWifiChip::LatencyMode aidl_latency_mode) { + switch (aidl_latency_mode) { + case IWifiChip::LatencyMode::NORMAL: + return legacy_hal::WIFI_LATENCY_MODE_NORMAL; + case IWifiChip::LatencyMode::LOW: + return legacy_hal::WIFI_LATENCY_MODE_LOW; + } + CHECK(false); +} + +bool convertLegacyWifiMacInfoToAidl(const legacy_hal::WifiMacInfo& legacy_mac_info, + IWifiChipEventCallback::RadioModeInfo* aidl_radio_mode_info) { + if (!aidl_radio_mode_info) { + return false; + } + *aidl_radio_mode_info = {}; + + aidl_radio_mode_info->radioId = legacy_mac_info.wlan_mac_id; + // Convert from bitmask of bands in the legacy HAL to enum value in + // the AIDL interface. + if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && + legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND && + legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ_5GHZ_6GHZ; + } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && + legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_5GHZ_6GHZ; + } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_6GHZ; + } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND && + legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ_5GHZ; + } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ; + } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_5GHZ; + } else { + aidl_radio_mode_info->bandInfo = WifiBand::BAND_UNSPECIFIED; + } + std::vector iface_info_vec; + for (const auto& legacy_iface_info : legacy_mac_info.iface_infos) { + IWifiChipEventCallback::IfaceInfo iface_info; + iface_info.name = legacy_iface_info.name; + iface_info.channel = legacy_iface_info.channel; + iface_info_vec.push_back(iface_info); + } + aidl_radio_mode_info->ifaceInfos = iface_info_vec; + return true; +} + +uint32_t convertAidlWifiBandToLegacyMacBand(WifiBand aidl_band) { + switch (aidl_band) { + case WifiBand::BAND_24GHZ: + return legacy_hal::WLAN_MAC_2_4_BAND; + case WifiBand::BAND_5GHZ: + case WifiBand::BAND_5GHZ_DFS: + case WifiBand::BAND_5GHZ_WITH_DFS: + return legacy_hal::WLAN_MAC_5_0_BAND; + case WifiBand::BAND_24GHZ_5GHZ: + case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: + return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND); + case WifiBand::BAND_6GHZ: + return legacy_hal::WLAN_MAC_6_0_BAND; + case WifiBand::BAND_5GHZ_6GHZ: + return (legacy_hal::WLAN_MAC_5_0_BAND | legacy_hal::WLAN_MAC_6_0_BAND); + case WifiBand::BAND_24GHZ_5GHZ_6GHZ: + case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS_6GHZ: + return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | + legacy_hal::WLAN_MAC_6_0_BAND); + case WifiBand::BAND_60GHZ: + return legacy_hal::WLAN_MAC_60_0_BAND; + default: + return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | + legacy_hal::WLAN_MAC_6_0_BAND | legacy_hal::WLAN_MAC_60_0_BAND); + } +} + +WifiBand convertLegacyMacBandToAidlWifiBand(uint32_t band) { + switch (band) { + case legacy_hal::WLAN_MAC_2_4_BAND: + return WifiBand::BAND_24GHZ; + case legacy_hal::WLAN_MAC_5_0_BAND: + return WifiBand::BAND_5GHZ; + case legacy_hal::WLAN_MAC_6_0_BAND: + return WifiBand::BAND_6GHZ; + case legacy_hal::WLAN_MAC_60_0_BAND: + return WifiBand::BAND_60GHZ; + default: + return WifiBand::BAND_UNSPECIFIED; + } +} + +uint32_t convertAidlWifiIfaceModeToLegacy(uint32_t aidl_iface_mask) { + uint32_t legacy_iface_mask = 0; + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_STA)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_STA); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_SOFTAP)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_SOFTAP); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_P2P_CLIENT)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_P2P_GO)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_GO); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_NAN)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_NAN); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_TDLS)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_TDLS); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_MESH)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_MESH); + } + if (aidl_iface_mask & static_cast(WifiIfaceMode::IFACE_MODE_IBSS)) { + legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_IBSS); + } + return legacy_iface_mask; +} + +uint32_t convertLegacyWifiInterfaceModeToAidl(uint32_t legacy_iface_mask) { + uint32_t aidl_iface_mask = 0; + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_STA)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_STA); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_SOFTAP)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_SOFTAP); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_P2P_CLIENT); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_GO)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_P2P_GO); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_NAN)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_NAN); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_TDLS)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_TDLS); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_MESH)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_MESH); + } + if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_IBSS)) { + aidl_iface_mask |= static_cast(WifiIfaceMode::IFACE_MODE_IBSS); + } + return aidl_iface_mask; +} + +uint32_t convertAidlUsableChannelFilterToLegacy(uint32_t aidl_filter_mask) { + uint32_t legacy_filter_mask = 0; + if (aidl_filter_mask & + static_cast(IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE)) { + legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE; + } + if (aidl_filter_mask & static_cast(IWifiChip::UsableChannelFilter::CONCURRENCY)) { + legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY; + } + if (aidl_filter_mask & static_cast(IWifiChip::UsableChannelFilter::NAN_INSTANT_MODE)) { + legacy_filter_mask |= WIFI_USABLE_CHANNEL_FILTER_NAN_INSTANT_MODE; + } + return legacy_filter_mask; +} + +bool convertLegacyWifiUsableChannelToAidl( + const legacy_hal::wifi_usable_channel& legacy_usable_channel, + WifiUsableChannel* aidl_usable_channel) { + if (!aidl_usable_channel) { + return false; + } + *aidl_usable_channel = {}; + aidl_usable_channel->channel = legacy_usable_channel.freq; + aidl_usable_channel->channelBandwidth = + convertLegacyWifiChannelWidthToAidl(legacy_usable_channel.width); + aidl_usable_channel->ifaceModeMask = static_cast( + convertLegacyWifiInterfaceModeToAidl(legacy_usable_channel.iface_mode_mask)); + + return true; +} + +bool convertLegacyWifiUsableChannelsToAidl( + const std::vector& legacy_usable_channels, + std::vector* aidl_usable_channels) { + if (!aidl_usable_channels) { + return false; + } + *aidl_usable_channels = {}; + for (const auto& legacy_usable_channel : legacy_usable_channels) { + WifiUsableChannel aidl_usable_channel; + if (!convertLegacyWifiUsableChannelToAidl(legacy_usable_channel, &aidl_usable_channel)) { + return false; + } + aidl_usable_channels->push_back(aidl_usable_channel); + } + return true; +} + +bool convertLegacyWifiMacInfosToAidl( + const std::vector& legacy_mac_infos, + std::vector* aidl_radio_mode_infos) { + if (!aidl_radio_mode_infos) { + return false; + } + *aidl_radio_mode_infos = {}; + + for (const auto& legacy_mac_info : legacy_mac_infos) { + IWifiChipEventCallback::RadioModeInfo aidl_radio_mode_info; + if (!convertLegacyWifiMacInfoToAidl(legacy_mac_info, &aidl_radio_mode_info)) { + return false; + } + aidl_radio_mode_infos->push_back(aidl_radio_mode_info); + } + return true; +} + +bool convertLegacyFeaturesToAidlStaCapabilities(uint64_t legacy_feature_set, + uint32_t legacy_logger_feature_set, + uint32_t* aidl_caps) { + if (!aidl_caps) { + return false; + } + *aidl_caps = {}; + for (const auto feature : {legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED}) { + if (feature & legacy_logger_feature_set) { + *aidl_caps |= static_cast( + convertLegacyLoggerFeatureToAidlStaIfaceCapability(feature)); + } + } + for (const auto feature : + {WIFI_FEATURE_GSCAN, WIFI_FEATURE_LINK_LAYER_STATS, WIFI_FEATURE_RSSI_MONITOR, + WIFI_FEATURE_CONTROL_ROAMING, WIFI_FEATURE_IE_WHITELIST, WIFI_FEATURE_SCAN_RAND, + WIFI_FEATURE_INFRA_5G, WIFI_FEATURE_HOTSPOT, WIFI_FEATURE_PNO, WIFI_FEATURE_TDLS, + WIFI_FEATURE_TDLS_OFFCHANNEL, WIFI_FEATURE_CONFIG_NDO, WIFI_FEATURE_MKEEP_ALIVE}) { + if (feature & legacy_feature_set) { + *aidl_caps |= + static_cast(convertLegacyFeatureToAidlStaIfaceCapability(feature)); + } + } + // There is no flag for this one in the legacy feature set. Adding it to the + // set because all the current devices support it. + *aidl_caps |= static_cast(IWifiStaIface::StaIfaceCapabilityMask::APF); + return true; +} + +bool convertLegacyApfCapabilitiesToAidl(const legacy_hal::PacketFilterCapabilities& legacy_caps, + StaApfPacketFilterCapabilities* aidl_caps) { + if (!aidl_caps) { + return false; + } + *aidl_caps = {}; + aidl_caps->version = legacy_caps.version; + aidl_caps->maxLength = legacy_caps.max_len; + return true; +} + +uint8_t convertAidlGscanReportEventFlagToLegacy( + StaBackgroundScanBucketEventReportSchemeMask aidl_flag) { + using AidlFlag = StaBackgroundScanBucketEventReportSchemeMask; + switch (aidl_flag) { + case AidlFlag::EACH_SCAN: + return REPORT_EVENTS_EACH_SCAN; + case AidlFlag::FULL_RESULTS: + return REPORT_EVENTS_FULL_RESULTS; + case AidlFlag::NO_BATCH: + return REPORT_EVENTS_NO_BATCH; + }; + CHECK(false); +} + +StaScanDataFlagMask convertLegacyGscanDataFlagToAidl(uint8_t legacy_flag) { + switch (legacy_flag) { + case legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED: + return StaScanDataFlagMask::INTERRUPTED; + }; + CHECK(false) << "Unknown legacy flag: " << legacy_flag; + // To silence the compiler warning about reaching the end of non-void + // function. + return {}; +} + +bool convertLegacyGscanCapabilitiesToAidl(const legacy_hal::wifi_gscan_capabilities& legacy_caps, + StaBackgroundScanCapabilities* aidl_caps) { + if (!aidl_caps) { + return false; + } + *aidl_caps = {}; + aidl_caps->maxCacheSize = legacy_caps.max_scan_cache_size; + aidl_caps->maxBuckets = legacy_caps.max_scan_buckets; + aidl_caps->maxApCachePerScan = legacy_caps.max_ap_cache_per_scan; + aidl_caps->maxReportingThreshold = legacy_caps.max_scan_reporting_threshold; + return true; +} + +legacy_hal::wifi_band convertAidlWifiBandToLegacy(WifiBand band) { + switch (band) { + case WifiBand::BAND_UNSPECIFIED: + return legacy_hal::WIFI_BAND_UNSPECIFIED; + case WifiBand::BAND_24GHZ: + return legacy_hal::WIFI_BAND_BG; + case WifiBand::BAND_5GHZ: + return legacy_hal::WIFI_BAND_A; + case WifiBand::BAND_5GHZ_DFS: + return legacy_hal::WIFI_BAND_A_DFS; + case WifiBand::BAND_5GHZ_WITH_DFS: + return legacy_hal::WIFI_BAND_A_WITH_DFS; + case WifiBand::BAND_24GHZ_5GHZ: + return legacy_hal::WIFI_BAND_ABG; + case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: + return legacy_hal::WIFI_BAND_ABG_WITH_DFS; + default: + CHECK(false); + return {}; + }; +} + +bool convertAidlGscanParamsToLegacy(const StaBackgroundScanParameters& aidl_scan_params, + legacy_hal::wifi_scan_cmd_params* legacy_scan_params) { + if (!legacy_scan_params) { + return false; + } + *legacy_scan_params = {}; + legacy_scan_params->base_period = aidl_scan_params.basePeriodInMs; + legacy_scan_params->max_ap_per_scan = aidl_scan_params.maxApPerScan; + legacy_scan_params->report_threshold_percent = aidl_scan_params.reportThresholdPercent; + legacy_scan_params->report_threshold_num_scans = aidl_scan_params.reportThresholdNumScans; + if (aidl_scan_params.buckets.size() > MAX_BUCKETS) { + return false; + } + legacy_scan_params->num_buckets = aidl_scan_params.buckets.size(); + for (uint32_t bucket_idx = 0; bucket_idx < aidl_scan_params.buckets.size(); bucket_idx++) { + const StaBackgroundScanBucketParameters& aidl_bucket_spec = + aidl_scan_params.buckets[bucket_idx]; + legacy_hal::wifi_scan_bucket_spec& legacy_bucket_spec = + legacy_scan_params->buckets[bucket_idx]; + if (aidl_bucket_spec.bucketIdx >= MAX_BUCKETS) { + return false; + } + legacy_bucket_spec.bucket = aidl_bucket_spec.bucketIdx; + legacy_bucket_spec.band = convertAidlWifiBandToLegacy(aidl_bucket_spec.band); + legacy_bucket_spec.period = aidl_bucket_spec.periodInMs; + legacy_bucket_spec.max_period = aidl_bucket_spec.exponentialMaxPeriodInMs; + legacy_bucket_spec.base = aidl_bucket_spec.exponentialBase; + legacy_bucket_spec.step_count = aidl_bucket_spec.exponentialStepCount; + legacy_bucket_spec.report_events = 0; + using AidlFlag = StaBackgroundScanBucketEventReportSchemeMask; + for (const auto flag : {AidlFlag::EACH_SCAN, AidlFlag::FULL_RESULTS, AidlFlag::NO_BATCH}) { + if (static_cast(aidl_bucket_spec.eventReportScheme) & + static_cast::type>(flag)) { + legacy_bucket_spec.report_events |= convertAidlGscanReportEventFlagToLegacy(flag); + } + } + if (aidl_bucket_spec.frequencies.size() > MAX_CHANNELS) { + return false; + } + legacy_bucket_spec.num_channels = aidl_bucket_spec.frequencies.size(); + for (uint32_t freq_idx = 0; freq_idx < aidl_bucket_spec.frequencies.size(); freq_idx++) { + legacy_bucket_spec.channels[freq_idx].channel = aidl_bucket_spec.frequencies[freq_idx]; + } + } + return true; +} + +bool convertLegacyIeToAidl(const legacy_hal::wifi_information_element& legacy_ie, + WifiInformationElement* aidl_ie) { + if (!aidl_ie) { + return false; + } + *aidl_ie = {}; + aidl_ie->id = legacy_ie.id; + aidl_ie->data = std::vector(legacy_ie.data, legacy_ie.data + legacy_ie.len); + return true; +} + +bool convertLegacyIeBlobToAidl(const uint8_t* ie_blob, uint32_t ie_blob_len, + std::vector* aidl_ies) { + if (!ie_blob || !aidl_ies) { + return false; + } + *aidl_ies = {}; + const uint8_t* ies_begin = ie_blob; + const uint8_t* ies_end = ie_blob + ie_blob_len; + const uint8_t* next_ie = ies_begin; + using wifi_ie = legacy_hal::wifi_information_element; + constexpr size_t kIeHeaderLen = sizeof(wifi_ie); + // Each IE should at least have the header (i.e |id| & |len| fields). + while (next_ie + kIeHeaderLen <= ies_end) { + const wifi_ie& legacy_ie = (*reinterpret_cast(next_ie)); + uint32_t curr_ie_len = kIeHeaderLen + legacy_ie.len; + if (next_ie + curr_ie_len > ies_end) { + LOG(ERROR) << "Error parsing IE blob. Next IE: " << (void*)next_ie + << ", Curr IE len: " << curr_ie_len << ", IEs End: " << (void*)ies_end; + break; + } + WifiInformationElement aidl_ie; + if (!convertLegacyIeToAidl(legacy_ie, &aidl_ie)) { + LOG(ERROR) << "Error converting IE. Id: " << legacy_ie.id << ", len: " << legacy_ie.len; + break; + } + aidl_ies->push_back(std::move(aidl_ie)); + next_ie += curr_ie_len; + } + // Check if the blob has been fully consumed. + if (next_ie != ies_end) { + LOG(ERROR) << "Failed to fully parse IE blob. Next IE: " << (void*)next_ie + << ", IEs End: " << (void*)ies_end; + } + return true; +} + +bool convertLegacyGscanResultToAidl(const legacy_hal::wifi_scan_result& legacy_scan_result, + bool has_ie_data, StaScanResult* aidl_scan_result) { + if (!aidl_scan_result) { + return false; + } + *aidl_scan_result = {}; + aidl_scan_result->timeStampInUs = legacy_scan_result.ts; + aidl_scan_result->ssid = std::vector( + legacy_scan_result.ssid, + legacy_scan_result.ssid + + strnlen(legacy_scan_result.ssid, sizeof(legacy_scan_result.ssid) - 1)); + aidl_scan_result->bssid = std::array(); + std::copy(legacy_scan_result.bssid, legacy_scan_result.bssid + 6, + std::begin(aidl_scan_result->bssid)); + aidl_scan_result->frequency = legacy_scan_result.channel; + aidl_scan_result->rssi = legacy_scan_result.rssi; + aidl_scan_result->beaconPeriodInMs = legacy_scan_result.beacon_period; + aidl_scan_result->capability = legacy_scan_result.capability; + if (has_ie_data) { + std::vector ies; + if (!convertLegacyIeBlobToAidl(reinterpret_cast(legacy_scan_result.ie_data), + legacy_scan_result.ie_length, &ies)) { + return false; + } + aidl_scan_result->informationElements = std::move(ies); + } + return true; +} + +bool convertLegacyCachedGscanResultsToAidl( + const legacy_hal::wifi_cached_scan_results& legacy_cached_scan_result, + StaScanData* aidl_scan_data) { + if (!aidl_scan_data) { + return false; + } + *aidl_scan_data = {}; + int32_t flags = 0; + for (const auto flag : {legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED}) { + if (legacy_cached_scan_result.flags & flag) { + flags |= static_cast::type>( + convertLegacyGscanDataFlagToAidl(flag)); + } + } + aidl_scan_data->flags = static_cast(flags); + aidl_scan_data->bucketsScanned = legacy_cached_scan_result.buckets_scanned; + + CHECK(legacy_cached_scan_result.num_results >= 0 && + legacy_cached_scan_result.num_results <= MAX_AP_CACHE_PER_SCAN); + std::vector aidl_scan_results; + for (int32_t result_idx = 0; result_idx < legacy_cached_scan_result.num_results; result_idx++) { + StaScanResult aidl_scan_result; + if (!convertLegacyGscanResultToAidl(legacy_cached_scan_result.results[result_idx], false, + &aidl_scan_result)) { + return false; + } + aidl_scan_results.push_back(aidl_scan_result); + } + aidl_scan_data->results = std::move(aidl_scan_results); + return true; +} + +bool convertLegacyVectorOfCachedGscanResultsToAidl( + const std::vector& legacy_cached_scan_results, + std::vector* aidl_scan_datas) { + if (!aidl_scan_datas) { + return false; + } + *aidl_scan_datas = {}; + for (const auto& legacy_cached_scan_result : legacy_cached_scan_results) { + StaScanData aidl_scan_data; + if (!convertLegacyCachedGscanResultsToAidl(legacy_cached_scan_result, &aidl_scan_data)) { + return false; + } + aidl_scan_datas->push_back(aidl_scan_data); + } + return true; +} + +WifiDebugTxPacketFate convertLegacyDebugTxPacketFateToAidl(legacy_hal::wifi_tx_packet_fate fate) { + switch (fate) { + case legacy_hal::TX_PKT_FATE_ACKED: + return WifiDebugTxPacketFate::ACKED; + case legacy_hal::TX_PKT_FATE_SENT: + return WifiDebugTxPacketFate::SENT; + case legacy_hal::TX_PKT_FATE_FW_QUEUED: + return WifiDebugTxPacketFate::FW_QUEUED; + case legacy_hal::TX_PKT_FATE_FW_DROP_INVALID: + return WifiDebugTxPacketFate::FW_DROP_INVALID; + case legacy_hal::TX_PKT_FATE_FW_DROP_NOBUFS: + return WifiDebugTxPacketFate::FW_DROP_NOBUFS; + case legacy_hal::TX_PKT_FATE_FW_DROP_OTHER: + return WifiDebugTxPacketFate::FW_DROP_OTHER; + case legacy_hal::TX_PKT_FATE_DRV_QUEUED: + return WifiDebugTxPacketFate::DRV_QUEUED; + case legacy_hal::TX_PKT_FATE_DRV_DROP_INVALID: + return WifiDebugTxPacketFate::DRV_DROP_INVALID; + case legacy_hal::TX_PKT_FATE_DRV_DROP_NOBUFS: + return WifiDebugTxPacketFate::DRV_DROP_NOBUFS; + case legacy_hal::TX_PKT_FATE_DRV_DROP_OTHER: + return WifiDebugTxPacketFate::DRV_DROP_OTHER; + }; + CHECK(false) << "Unknown legacy fate type: " << fate; +} + +WifiDebugRxPacketFate convertLegacyDebugRxPacketFateToAidl(legacy_hal::wifi_rx_packet_fate fate) { + switch (fate) { + case legacy_hal::RX_PKT_FATE_SUCCESS: + return WifiDebugRxPacketFate::SUCCESS; + case legacy_hal::RX_PKT_FATE_FW_QUEUED: + return WifiDebugRxPacketFate::FW_QUEUED; + case legacy_hal::RX_PKT_FATE_FW_DROP_FILTER: + return WifiDebugRxPacketFate::FW_DROP_FILTER; + case legacy_hal::RX_PKT_FATE_FW_DROP_INVALID: + return WifiDebugRxPacketFate::FW_DROP_INVALID; + case legacy_hal::RX_PKT_FATE_FW_DROP_NOBUFS: + return WifiDebugRxPacketFate::FW_DROP_NOBUFS; + case legacy_hal::RX_PKT_FATE_FW_DROP_OTHER: + return WifiDebugRxPacketFate::FW_DROP_OTHER; + case legacy_hal::RX_PKT_FATE_DRV_QUEUED: + return WifiDebugRxPacketFate::DRV_QUEUED; + case legacy_hal::RX_PKT_FATE_DRV_DROP_FILTER: + return WifiDebugRxPacketFate::DRV_DROP_FILTER; + case legacy_hal::RX_PKT_FATE_DRV_DROP_INVALID: + return WifiDebugRxPacketFate::DRV_DROP_INVALID; + case legacy_hal::RX_PKT_FATE_DRV_DROP_NOBUFS: + return WifiDebugRxPacketFate::DRV_DROP_NOBUFS; + case legacy_hal::RX_PKT_FATE_DRV_DROP_OTHER: + return WifiDebugRxPacketFate::DRV_DROP_OTHER; + }; + CHECK(false) << "Unknown legacy fate type: " << fate; +} + +WifiDebugPacketFateFrameType convertLegacyDebugPacketFateFrameTypeToAidl( + legacy_hal::frame_type type) { + switch (type) { + case legacy_hal::FRAME_TYPE_UNKNOWN: + return WifiDebugPacketFateFrameType::UNKNOWN; + case legacy_hal::FRAME_TYPE_ETHERNET_II: + return WifiDebugPacketFateFrameType::ETHERNET_II; + case legacy_hal::FRAME_TYPE_80211_MGMT: + return WifiDebugPacketFateFrameType::MGMT_80211; + }; + CHECK(false) << "Unknown legacy frame type: " << type; +} + +bool convertLegacyDebugPacketFateFrameToAidl(const legacy_hal::frame_info& legacy_frame, + WifiDebugPacketFateFrameInfo* aidl_frame) { + if (!aidl_frame) { + return false; + } + *aidl_frame = {}; + aidl_frame->frameType = convertLegacyDebugPacketFateFrameTypeToAidl(legacy_frame.payload_type); + aidl_frame->frameLen = legacy_frame.frame_len; + aidl_frame->driverTimestampUsec = legacy_frame.driver_timestamp_usec; + aidl_frame->firmwareTimestampUsec = legacy_frame.firmware_timestamp_usec; + const uint8_t* frame_begin = + reinterpret_cast(legacy_frame.frame_content.ethernet_ii_bytes); + aidl_frame->frameContent = + std::vector(frame_begin, frame_begin + legacy_frame.frame_len); + return true; +} + +bool convertLegacyDebugTxPacketFateToAidl(const legacy_hal::wifi_tx_report& legacy_fate, + WifiDebugTxPacketFateReport* aidl_fate) { + if (!aidl_fate) { + return false; + } + *aidl_fate = {}; + aidl_fate->fate = convertLegacyDebugTxPacketFateToAidl(legacy_fate.fate); + return convertLegacyDebugPacketFateFrameToAidl(legacy_fate.frame_inf, &aidl_fate->frameInfo); +} + +bool convertLegacyVectorOfDebugTxPacketFateToAidl( + const std::vector& legacy_fates, + std::vector* aidl_fates) { + if (!aidl_fates) { + return false; + } + *aidl_fates = {}; + for (const auto& legacy_fate : legacy_fates) { + WifiDebugTxPacketFateReport aidl_fate; + if (!convertLegacyDebugTxPacketFateToAidl(legacy_fate, &aidl_fate)) { + return false; + } + aidl_fates->push_back(aidl_fate); + } + return true; +} + +bool convertLegacyDebugRxPacketFateToAidl(const legacy_hal::wifi_rx_report& legacy_fate, + WifiDebugRxPacketFateReport* aidl_fate) { + if (!aidl_fate) { + return false; + } + *aidl_fate = {}; + aidl_fate->fate = convertLegacyDebugRxPacketFateToAidl(legacy_fate.fate); + return convertLegacyDebugPacketFateFrameToAidl(legacy_fate.frame_inf, &aidl_fate->frameInfo); +} + +bool convertLegacyVectorOfDebugRxPacketFateToAidl( + const std::vector& legacy_fates, + std::vector* aidl_fates) { + if (!aidl_fates) { + return false; + } + *aidl_fates = {}; + for (const auto& legacy_fate : legacy_fates) { + WifiDebugRxPacketFateReport aidl_fate; + if (!convertLegacyDebugRxPacketFateToAidl(legacy_fate, &aidl_fate)) { + return false; + } + aidl_fates->push_back(aidl_fate); + } + return true; +} + +bool convertLegacyLinkLayerRadioStatsToAidl( + const legacy_hal::LinkLayerRadioStats& legacy_radio_stat, + StaLinkLayerRadioStats* aidl_radio_stat) { + if (!aidl_radio_stat) { + return false; + } + *aidl_radio_stat = {}; + + aidl_radio_stat->radioId = legacy_radio_stat.stats.radio; + aidl_radio_stat->onTimeInMs = legacy_radio_stat.stats.on_time; + aidl_radio_stat->txTimeInMs = legacy_radio_stat.stats.tx_time; + aidl_radio_stat->rxTimeInMs = legacy_radio_stat.stats.rx_time; + aidl_radio_stat->onTimeInMsForScan = legacy_radio_stat.stats.on_time_scan; + aidl_radio_stat->txTimeInMsPerLevel = uintToIntVec(legacy_radio_stat.tx_time_per_levels); + aidl_radio_stat->onTimeInMsForNanScan = legacy_radio_stat.stats.on_time_nbd; + aidl_radio_stat->onTimeInMsForBgScan = legacy_radio_stat.stats.on_time_gscan; + aidl_radio_stat->onTimeInMsForRoamScan = legacy_radio_stat.stats.on_time_roam_scan; + aidl_radio_stat->onTimeInMsForPnoScan = legacy_radio_stat.stats.on_time_pno_scan; + aidl_radio_stat->onTimeInMsForHs20Scan = legacy_radio_stat.stats.on_time_hs20; + + std::vector aidl_channel_stats; + + for (const auto& channel_stat : legacy_radio_stat.channel_stats) { + WifiChannelStats aidl_channel_stat; + aidl_channel_stat.onTimeInMs = channel_stat.on_time; + aidl_channel_stat.ccaBusyTimeInMs = channel_stat.cca_busy_time; + aidl_channel_stat.channel.width = WifiChannelWidthInMhz::WIDTH_20; + aidl_channel_stat.channel.centerFreq = channel_stat.channel.center_freq; + aidl_channel_stat.channel.centerFreq0 = channel_stat.channel.center_freq0; + aidl_channel_stat.channel.centerFreq1 = channel_stat.channel.center_freq1; + aidl_channel_stats.push_back(aidl_channel_stat); + } + + aidl_radio_stat->channelStats = aidl_channel_stats; + + return true; +} + +bool convertLegacyLinkLayerStatsToAidl(const legacy_hal::LinkLayerStats& legacy_stats, + StaLinkLayerStats* aidl_stats) { + if (!aidl_stats) { + return false; + } + *aidl_stats = {}; + // iface legacy_stats conversion. + aidl_stats->iface.beaconRx = legacy_stats.iface.beacon_rx; + aidl_stats->iface.avgRssiMgmt = legacy_stats.iface.rssi_mgmt; + aidl_stats->iface.wmeBePktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; + aidl_stats->iface.wmeBePktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; + aidl_stats->iface.wmeBePktStats.lostMpdu = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; + aidl_stats->iface.wmeBePktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries; + aidl_stats->iface.wmeBeContentionTimeStats.contentionTimeMinInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_min; + aidl_stats->iface.wmeBeContentionTimeStats.contentionTimeMaxInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_max; + aidl_stats->iface.wmeBeContentionTimeStats.contentionTimeAvgInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_avg; + aidl_stats->iface.wmeBeContentionTimeStats.contentionNumSamples = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_num_samples; + aidl_stats->iface.wmeBkPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; + aidl_stats->iface.wmeBkPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; + aidl_stats->iface.wmeBkPktStats.lostMpdu = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; + aidl_stats->iface.wmeBkPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries; + aidl_stats->iface.wmeBkContentionTimeStats.contentionTimeMinInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_min; + aidl_stats->iface.wmeBkContentionTimeStats.contentionTimeMaxInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_max; + aidl_stats->iface.wmeBkContentionTimeStats.contentionTimeAvgInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_avg; + aidl_stats->iface.wmeBkContentionTimeStats.contentionNumSamples = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_num_samples; + aidl_stats->iface.wmeViPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; + aidl_stats->iface.wmeViPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; + aidl_stats->iface.wmeViPktStats.lostMpdu = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; + aidl_stats->iface.wmeViPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries; + aidl_stats->iface.wmeViContentionTimeStats.contentionTimeMinInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_min; + aidl_stats->iface.wmeViContentionTimeStats.contentionTimeMaxInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_max; + aidl_stats->iface.wmeViContentionTimeStats.contentionTimeAvgInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_avg; + aidl_stats->iface.wmeViContentionTimeStats.contentionNumSamples = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_num_samples; + aidl_stats->iface.wmeVoPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; + aidl_stats->iface.wmeVoPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; + aidl_stats->iface.wmeVoPktStats.lostMpdu = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; + aidl_stats->iface.wmeVoPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries; + aidl_stats->iface.wmeVoContentionTimeStats.contentionTimeMinInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_min; + aidl_stats->iface.wmeVoContentionTimeStats.contentionTimeMaxInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_max; + aidl_stats->iface.wmeVoContentionTimeStats.contentionTimeAvgInUsec = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_avg; + aidl_stats->iface.wmeVoContentionTimeStats.contentionNumSamples = + legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_num_samples; + aidl_stats->iface.timeSliceDutyCycleInPercent = + legacy_stats.iface.info.time_slicing_duty_cycle_percent; + // peer info legacy_stats conversion. + std::vector aidl_peers_info_stats; + for (const auto& legacy_peer_info_stats : legacy_stats.peers) { + StaPeerInfo aidl_peer_info_stats; + if (!convertLegacyPeerInfoStatsToAidl(legacy_peer_info_stats, &aidl_peer_info_stats)) { + return false; + } + aidl_peers_info_stats.push_back(aidl_peer_info_stats); + } + aidl_stats->iface.peers = aidl_peers_info_stats; + // radio legacy_stats conversion. + std::vector aidl_radios_stats; + for (const auto& legacy_radio_stats : legacy_stats.radios) { + StaLinkLayerRadioStats aidl_radio_stats; + if (!convertLegacyLinkLayerRadioStatsToAidl(legacy_radio_stats, &aidl_radio_stats)) { + return false; + } + aidl_radios_stats.push_back(aidl_radio_stats); + } + aidl_stats->radios = aidl_radios_stats; + aidl_stats->timeStampInMs = ::android::uptimeMillis(); + return true; +} + +bool convertLegacyPeerInfoStatsToAidl(const legacy_hal::WifiPeerInfo& legacy_peer_info_stats, + StaPeerInfo* aidl_peer_info_stats) { + if (!aidl_peer_info_stats) { + return false; + } + *aidl_peer_info_stats = {}; + aidl_peer_info_stats->staCount = legacy_peer_info_stats.peer_info.bssload.sta_count; + aidl_peer_info_stats->chanUtil = legacy_peer_info_stats.peer_info.bssload.chan_util; + + std::vector aidlRateStats; + for (const auto& legacy_rate_stats : legacy_peer_info_stats.rate_stats) { + StaRateStat rateStat; + if (!convertLegacyWifiRateInfoToAidl(legacy_rate_stats.rate, &rateStat.rateInfo)) { + return false; + } + rateStat.txMpdu = legacy_rate_stats.tx_mpdu; + rateStat.rxMpdu = legacy_rate_stats.rx_mpdu; + rateStat.mpduLost = legacy_rate_stats.mpdu_lost; + rateStat.retries = legacy_rate_stats.retries; + aidlRateStats.push_back(rateStat); + } + aidl_peer_info_stats->rateStats = aidlRateStats; + return true; +} + +bool convertLegacyRoamingCapabilitiesToAidl( + const legacy_hal::wifi_roaming_capabilities& legacy_caps, + StaRoamingCapabilities* aidl_caps) { + if (!aidl_caps) { + return false; + } + *aidl_caps = {}; + aidl_caps->maxBlocklistSize = legacy_caps.max_blacklist_size; + aidl_caps->maxAllowlistSize = legacy_caps.max_whitelist_size; + return true; +} + +bool convertAidlRoamingConfigToLegacy(const StaRoamingConfig& aidl_config, + legacy_hal::wifi_roaming_config* legacy_config) { + if (!legacy_config) { + return false; + } + *legacy_config = {}; + if (aidl_config.bssidBlocklist.size() > MAX_BLACKLIST_BSSID || + aidl_config.ssidAllowlist.size() > MAX_WHITELIST_SSID) { + return false; + } + legacy_config->num_blacklist_bssid = aidl_config.bssidBlocklist.size(); + uint32_t i = 0; + for (const auto& bssid : aidl_config.bssidBlocklist) { + CHECK(bssid.data.size() == sizeof(legacy_hal::mac_addr)); + memcpy(legacy_config->blacklist_bssid[i++], bssid.data.data(), bssid.data.size()); + } + legacy_config->num_whitelist_ssid = aidl_config.ssidAllowlist.size(); + i = 0; + for (const auto& ssid : aidl_config.ssidAllowlist) { + CHECK(ssid.data.size() <= sizeof(legacy_hal::ssid_t::ssid_str)); + legacy_config->whitelist_ssid[i].length = ssid.data.size(); + memcpy(legacy_config->whitelist_ssid[i].ssid_str, ssid.data.data(), ssid.data.size()); + i++; + } + return true; +} + +legacy_hal::fw_roaming_state_t convertAidlRoamingStateToLegacy(StaRoamingState state) { + switch (state) { + case StaRoamingState::ENABLED: + return legacy_hal::ROAMING_ENABLE; + case StaRoamingState::DISABLED: + return legacy_hal::ROAMING_DISABLE; + }; + CHECK(false); +} + +legacy_hal::NanMatchAlg convertAidlNanMatchAlgToLegacy(NanMatchAlg type) { + switch (type) { + case NanMatchAlg::MATCH_ONCE: + return legacy_hal::NAN_MATCH_ALG_MATCH_ONCE; + case NanMatchAlg::MATCH_CONTINUOUS: + return legacy_hal::NAN_MATCH_ALG_MATCH_CONTINUOUS; + case NanMatchAlg::MATCH_NEVER: + return legacy_hal::NAN_MATCH_ALG_MATCH_NEVER; + } + CHECK(false); +} + +legacy_hal::NanPublishType convertAidlNanPublishTypeToLegacy(NanPublishType type) { + switch (type) { + case NanPublishType::UNSOLICITED: + return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED; + case NanPublishType::SOLICITED: + return legacy_hal::NAN_PUBLISH_TYPE_SOLICITED; + case NanPublishType::UNSOLICITED_SOLICITED: + return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED; + } + CHECK(false); +} + +legacy_hal::NanTxType convertAidlNanTxTypeToLegacy(NanTxType type) { + switch (type) { + case NanTxType::BROADCAST: + return legacy_hal::NAN_TX_TYPE_BROADCAST; + case NanTxType::UNICAST: + return legacy_hal::NAN_TX_TYPE_UNICAST; + } + CHECK(false); +} + +legacy_hal::NanSubscribeType convertAidlNanSubscribeTypeToLegacy(NanSubscribeType type) { + switch (type) { + case NanSubscribeType::PASSIVE: + return legacy_hal::NAN_SUBSCRIBE_TYPE_PASSIVE; + case NanSubscribeType::ACTIVE: + return legacy_hal::NAN_SUBSCRIBE_TYPE_ACTIVE; + } + CHECK(false); +} + +legacy_hal::NanSRFType convertAidlNanSrfTypeToLegacy(NanSrfType type) { + switch (type) { + case NanSrfType::BLOOM_FILTER: + return legacy_hal::NAN_SRF_ATTR_BLOOM_FILTER; + case NanSrfType::PARTIAL_MAC_ADDR: + return legacy_hal::NAN_SRF_ATTR_PARTIAL_MAC_ADDR; + } + CHECK(false); +} + +legacy_hal::NanDataPathChannelCfg convertAidlNanDataPathChannelCfgToLegacy( + NanDataPathChannelCfg type) { + switch (type) { + case NanDataPathChannelCfg::CHANNEL_NOT_REQUESTED: + return legacy_hal::NAN_DP_CHANNEL_NOT_REQUESTED; + case NanDataPathChannelCfg::REQUEST_CHANNEL_SETUP: + return legacy_hal::NAN_DP_REQUEST_CHANNEL_SETUP; + case NanDataPathChannelCfg::FORCE_CHANNEL_SETUP: + return legacy_hal::NAN_DP_FORCE_CHANNEL_SETUP; + } + CHECK(false); +} + +NanStatusCode convertLegacyNanStatusTypeToAidl(legacy_hal::NanStatusType type) { + switch (type) { + case legacy_hal::NAN_STATUS_SUCCESS: + return NanStatusCode::SUCCESS; + case legacy_hal::NAN_STATUS_INTERNAL_FAILURE: + return NanStatusCode::INTERNAL_FAILURE; + case legacy_hal::NAN_STATUS_PROTOCOL_FAILURE: + return NanStatusCode::PROTOCOL_FAILURE; + case legacy_hal::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID: + return NanStatusCode::INVALID_SESSION_ID; + case legacy_hal::NAN_STATUS_NO_RESOURCE_AVAILABLE: + return NanStatusCode::NO_RESOURCES_AVAILABLE; + case legacy_hal::NAN_STATUS_INVALID_PARAM: + return NanStatusCode::INVALID_ARGS; + case legacy_hal::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID: + return NanStatusCode::INVALID_PEER_ID; + case legacy_hal::NAN_STATUS_INVALID_NDP_ID: + return NanStatusCode::INVALID_NDP_ID; + case legacy_hal::NAN_STATUS_NAN_NOT_ALLOWED: + return NanStatusCode::NAN_NOT_ALLOWED; + case legacy_hal::NAN_STATUS_NO_OTA_ACK: + return NanStatusCode::NO_OTA_ACK; + case legacy_hal::NAN_STATUS_ALREADY_ENABLED: + return NanStatusCode::ALREADY_ENABLED; + case legacy_hal::NAN_STATUS_FOLLOWUP_QUEUE_FULL: + return NanStatusCode::FOLLOWUP_TX_QUEUE_FULL; + case legacy_hal::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED: + return NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED; + } + CHECK(false); +} + +void convertToNanStatus(legacy_hal::NanStatusType type, const char* str, size_t max_len, + NanStatus* nanStatus) { + nanStatus->status = convertLegacyNanStatusTypeToAidl(type); + nanStatus->description = safeConvertChar(str, max_len); +} + +bool convertAidlNanEnableRequestToLegacy(const NanEnableRequest& aidl_request1, + const NanConfigRequestSupplemental& aidl_request2, + legacy_hal::NanEnableRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: null legacy_request"; + return false; + } + *legacy_request = {}; + + legacy_request->config_2dot4g_support = 1; + legacy_request->support_2dot4g_val = + aidl_request1.operateInBand[(size_t)NanBandIndex::NAN_BAND_24GHZ]; + legacy_request->config_support_5g = 1; + legacy_request->support_5g_val = + aidl_request1.operateInBand[(size_t)NanBandIndex::NAN_BAND_5GHZ]; + legacy_request->config_hop_count_limit = 1; + legacy_request->hop_count_limit_val = aidl_request1.hopCountMax; + legacy_request->master_pref = aidl_request1.configParams.masterPref; + legacy_request->discovery_indication_cfg = 0; + legacy_request->discovery_indication_cfg |= + aidl_request1.configParams.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; + legacy_request->discovery_indication_cfg |= + aidl_request1.configParams.disableStartedClusterIndication ? 0x2 : 0x0; + legacy_request->discovery_indication_cfg |= + aidl_request1.configParams.disableJoinedClusterIndication ? 0x4 : 0x0; + legacy_request->config_sid_beacon = 1; + if (aidl_request1.configParams.numberOfPublishServiceIdsInBeacon < 0) { + LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " + "numberOfPublishServiceIdsInBeacon < 0"; + return false; + } + legacy_request->sid_beacon_val = + (aidl_request1.configParams.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | + (aidl_request1.configParams.numberOfPublishServiceIdsInBeacon << 1); + legacy_request->config_subscribe_sid_beacon = 1; + if (aidl_request1.configParams.numberOfSubscribeServiceIdsInBeacon < 0) { + LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " + "numberOfSubscribeServiceIdsInBeacon < 0"; + return false; + } + legacy_request->subscribe_sid_beacon_val = + (aidl_request1.configParams.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | + (aidl_request1.configParams.numberOfSubscribeServiceIdsInBeacon << 1); + legacy_request->config_rssi_window_size = 1; + legacy_request->rssi_window_size_val = aidl_request1.configParams.rssiWindowSize; + legacy_request->config_disc_mac_addr_randomization = 1; + legacy_request->disc_mac_addr_rand_interval_sec = + aidl_request1.configParams.macAddressRandomizationIntervalSec; + legacy_request->config_2dot4g_rssi_close = 1; + if (aidl_request1.configParams.bandSpecificConfig.size() != 3) { + LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " + "bandSpecificConfig.size() != 3"; + return false; + } + legacy_request->rssi_close_2dot4g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .rssiClose; + legacy_request->config_2dot4g_rssi_middle = 1; + legacy_request->rssi_middle_2dot4g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .rssiMiddle; + legacy_request->config_2dot4g_rssi_proximity = 1; + legacy_request->rssi_proximity_2dot4g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .rssiCloseProximity; + legacy_request->config_scan_params = 1; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .scanPeriodSec; + legacy_request->config_dw.config_2dot4g_dw_band = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .validDiscoveryWindowIntervalVal; + legacy_request->config_dw.dw_2dot4g_interval_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .discoveryWindowIntervalVal; + legacy_request->config_5g_rssi_close = 1; + legacy_request->rssi_close_5g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .rssiClose; + legacy_request->config_5g_rssi_middle = 1; + legacy_request->rssi_middle_5g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .rssiMiddle; + legacy_request->config_5g_rssi_close_proximity = 1; + legacy_request->rssi_close_proximity_5g_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .rssiCloseProximity; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .scanPeriodSec; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .scanPeriodSec; + legacy_request->config_dw.config_5g_dw_band = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .validDiscoveryWindowIntervalVal; + legacy_request->config_dw.dw_5g_interval_val = + aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .discoveryWindowIntervalVal; + if (aidl_request1.debugConfigs.validClusterIdVals) { + legacy_request->cluster_low = aidl_request1.debugConfigs.clusterIdBottomRangeVal; + legacy_request->cluster_high = aidl_request1.debugConfigs.clusterIdTopRangeVal; + } else { // need 'else' since not configurable in legacy HAL + legacy_request->cluster_low = 0x0000; + legacy_request->cluster_high = 0xFFFF; + } + legacy_request->config_intf_addr = aidl_request1.debugConfigs.validIntfAddrVal; + memcpy(legacy_request->intf_addr_val, aidl_request1.debugConfigs.intfAddrVal.data(), 6); + legacy_request->config_oui = aidl_request1.debugConfigs.validOuiVal; + legacy_request->oui_val = aidl_request1.debugConfigs.ouiVal; + legacy_request->config_random_factor_force = + aidl_request1.debugConfigs.validRandomFactorForceVal; + legacy_request->random_factor_force_val = aidl_request1.debugConfigs.randomFactorForceVal; + legacy_request->config_hop_count_force = aidl_request1.debugConfigs.validHopCountForceVal; + legacy_request->hop_count_force_val = aidl_request1.debugConfigs.hopCountForceVal; + legacy_request->config_24g_channel = aidl_request1.debugConfigs.validDiscoveryChannelVal; + legacy_request->channel_24g_val = + aidl_request1.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; + legacy_request->config_5g_channel = aidl_request1.debugConfigs.validDiscoveryChannelVal; + legacy_request->channel_5g_val = + aidl_request1.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; + legacy_request->config_2dot4g_beacons = aidl_request1.debugConfigs.validUseBeaconsInBandVal; + legacy_request->beacon_2dot4g_val = + aidl_request1.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; + legacy_request->config_5g_beacons = aidl_request1.debugConfigs.validUseBeaconsInBandVal; + legacy_request->beacon_5g_val = + aidl_request1.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; + legacy_request->config_2dot4g_sdf = aidl_request1.debugConfigs.validUseSdfInBandVal; + legacy_request->sdf_2dot4g_val = + aidl_request1.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; + legacy_request->config_5g_sdf = aidl_request1.debugConfigs.validUseSdfInBandVal; + legacy_request->sdf_5g_val = + aidl_request1.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; + + legacy_request->config_discovery_beacon_int = 1; + legacy_request->discovery_beacon_interval = aidl_request2.discoveryBeaconIntervalMs; + legacy_request->config_nss = 1; + legacy_request->nss = aidl_request2.numberOfSpatialStreamsInDiscovery; + legacy_request->config_dw_early_termination = 1; + legacy_request->enable_dw_termination = aidl_request2.enableDiscoveryWindowEarlyTermination; + legacy_request->config_enable_ranging = 1; + legacy_request->enable_ranging = aidl_request2.enableRanging; + + legacy_request->config_enable_instant_mode = 1; + legacy_request->enable_instant_mode = aidl_request2.enableInstantCommunicationMode; + legacy_request->config_instant_mode_channel = 1; + legacy_request->instant_mode_channel = aidl_request2.instantModeChannel; + + return true; +} + +bool convertAidlNanConfigRequestToLegacy(const NanConfigRequest& aidl_request1, + const NanConfigRequestSupplemental& aidl_request2, + legacy_hal::NanConfigRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: null legacy_request"; + return false; + } + *legacy_request = {}; + + legacy_request->master_pref = aidl_request1.masterPref; + legacy_request->discovery_indication_cfg = 0; + legacy_request->discovery_indication_cfg |= + aidl_request1.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; + legacy_request->discovery_indication_cfg |= + aidl_request1.disableStartedClusterIndication ? 0x2 : 0x0; + legacy_request->discovery_indication_cfg |= + aidl_request1.disableJoinedClusterIndication ? 0x4 : 0x0; + legacy_request->config_sid_beacon = 1; + if (aidl_request1.numberOfPublishServiceIdsInBeacon < 0) { + LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: " + "numberOfPublishServiceIdsInBeacon < 0"; + return false; + } + legacy_request->sid_beacon = (aidl_request1.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | + (aidl_request1.numberOfPublishServiceIdsInBeacon << 1); + legacy_request->config_subscribe_sid_beacon = 1; + if (aidl_request1.numberOfSubscribeServiceIdsInBeacon < 0) { + LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: " + "numberOfSubscribeServiceIdsInBeacon < 0"; + return false; + } + legacy_request->subscribe_sid_beacon_val = + (aidl_request1.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | + (aidl_request1.numberOfSubscribeServiceIdsInBeacon << 1); + legacy_request->config_rssi_window_size = 1; + legacy_request->rssi_window_size_val = aidl_request1.rssiWindowSize; + legacy_request->config_disc_mac_addr_randomization = 1; + legacy_request->disc_mac_addr_rand_interval_sec = + aidl_request1.macAddressRandomizationIntervalSec; + + legacy_request->config_scan_params = 1; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].scanPeriodSec; + legacy_request->config_dw.config_2dot4g_dw_band = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .validDiscoveryWindowIntervalVal; + legacy_request->config_dw.dw_2dot4g_interval_val = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] + .discoveryWindowIntervalVal; + + legacy_request->config_5g_rssi_close_proximity = 1; + legacy_request->rssi_close_proximity_5g_val = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .rssiCloseProximity; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; + legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; + legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; + legacy_request->config_dw.config_5g_dw_band = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .validDiscoveryWindowIntervalVal; + legacy_request->config_dw.dw_5g_interval_val = + aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] + .discoveryWindowIntervalVal; + + legacy_request->config_discovery_beacon_int = 1; + legacy_request->discovery_beacon_interval = aidl_request2.discoveryBeaconIntervalMs; + legacy_request->config_nss = 1; + legacy_request->nss = aidl_request2.numberOfSpatialStreamsInDiscovery; + legacy_request->config_dw_early_termination = 1; + legacy_request->enable_dw_termination = aidl_request2.enableDiscoveryWindowEarlyTermination; + legacy_request->config_enable_ranging = 1; + legacy_request->enable_ranging = aidl_request2.enableRanging; + + legacy_request->config_enable_instant_mode = 1; + legacy_request->enable_instant_mode = aidl_request2.enableInstantCommunicationMode; + legacy_request->config_instant_mode_channel = 1; + legacy_request->instant_mode_channel = aidl_request2.instantModeChannel; + + return true; +} + +bool convertAidlNanPublishRequestToLegacy(const NanPublishRequest& aidl_request, + legacy_hal::NanPublishRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: null legacy_request"; + return false; + } + *legacy_request = {}; + + legacy_request->publish_id = aidl_request.baseConfigs.sessionId; + legacy_request->ttl = aidl_request.baseConfigs.ttlSec; + legacy_request->period = aidl_request.baseConfigs.discoveryWindowPeriod; + legacy_request->publish_count = aidl_request.baseConfigs.discoveryCount; + legacy_request->service_name_len = aidl_request.baseConfigs.serviceName.size(); + if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: service_name_len " + "too large"; + return false; + } + memcpy(legacy_request->service_name, aidl_request.baseConfigs.serviceName.data(), + legacy_request->service_name_len); + legacy_request->publish_match_indicator = + convertAidlNanMatchAlgToLegacy(aidl_request.baseConfigs.discoveryMatchIndicator); + legacy_request->service_specific_info_len = aidl_request.baseConfigs.serviceSpecificInfo.size(); + if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->service_specific_info, + aidl_request.baseConfigs.serviceSpecificInfo.data(), + legacy_request->service_specific_info_len); + legacy_request->sdea_service_specific_info_len = + aidl_request.baseConfigs.extendedServiceSpecificInfo.size(); + if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "sdea_service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->sdea_service_specific_info, + aidl_request.baseConfigs.extendedServiceSpecificInfo.data(), + legacy_request->sdea_service_specific_info_len); + legacy_request->rx_match_filter_len = aidl_request.baseConfigs.rxMatchFilter.size(); + if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "rx_match_filter_len too large"; + return false; + } + memcpy(legacy_request->rx_match_filter, aidl_request.baseConfigs.rxMatchFilter.data(), + legacy_request->rx_match_filter_len); + legacy_request->tx_match_filter_len = aidl_request.baseConfigs.txMatchFilter.size(); + if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "tx_match_filter_len too large"; + return false; + } + memcpy(legacy_request->tx_match_filter, aidl_request.baseConfigs.txMatchFilter.data(), + legacy_request->tx_match_filter_len); + legacy_request->rssi_threshold_flag = aidl_request.baseConfigs.useRssiThreshold; + legacy_request->recv_indication_cfg = 0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; + legacy_request->recv_indication_cfg |= 0x8; + legacy_request->cipher_type = (unsigned int)aidl_request.baseConfigs.securityConfig.cipherType; + + legacy_request->scid_len = aidl_request.baseConfigs.securityConfig.scid.size(); + if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: scid_len too large"; + return false; + } + memcpy(legacy_request->scid, aidl_request.baseConfigs.securityConfig.scid.data(), + legacy_request->scid_len); + + if (aidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; + legacy_request->key_info.body.pmk_info.pmk_len = + aidl_request.baseConfigs.securityConfig.pmk.size(); + if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: invalid pmk_len"; + return false; + } + memcpy(legacy_request->key_info.body.pmk_info.pmk, + aidl_request.baseConfigs.securityConfig.pmk.data(), + legacy_request->key_info.body.pmk_info.pmk_len); + } + if (aidl_request.baseConfigs.securityConfig.securityType == + NanDataPathSecurityType::PASSPHRASE) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; + legacy_request->key_info.body.passphrase_info.passphrase_len = + aidl_request.baseConfigs.securityConfig.passphrase.size(); + if (legacy_request->key_info.body.passphrase_info.passphrase_len < + NAN_SECURITY_MIN_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "passphrase_len too small"; + return false; + } + if (legacy_request->key_info.body.passphrase_info.passphrase_len > + NAN_SECURITY_MAX_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " + "passphrase_len too large"; + return false; + } + memcpy(legacy_request->key_info.body.passphrase_info.passphrase, + aidl_request.baseConfigs.securityConfig.passphrase.data(), + legacy_request->key_info.body.passphrase_info.passphrase_len); + } + legacy_request->sdea_params.security_cfg = + (aidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) + ? legacy_hal::NAN_DP_CONFIG_SECURITY + : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; + + legacy_request->sdea_params.ranging_state = aidl_request.baseConfigs.rangingRequired + ? legacy_hal::NAN_RANGING_ENABLE + : legacy_hal::NAN_RANGING_DISABLE; + legacy_request->ranging_cfg.ranging_interval_msec = aidl_request.baseConfigs.rangingIntervalMs; + legacy_request->ranging_cfg.config_ranging_indications = + static_cast(aidl_request.baseConfigs.configRangingIndications); + legacy_request->ranging_cfg.distance_ingress_mm = + aidl_request.baseConfigs.distanceIngressCm * 10; + legacy_request->ranging_cfg.distance_egress_mm = aidl_request.baseConfigs.distanceEgressCm * 10; + legacy_request->ranging_auto_response = aidl_request.baseConfigs.rangingRequired + ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE + : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; + legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; + legacy_request->publish_type = convertAidlNanPublishTypeToLegacy(aidl_request.publishType); + legacy_request->tx_type = convertAidlNanTxTypeToLegacy(aidl_request.txType); + legacy_request->service_responder_policy = aidl_request.autoAcceptDataPathRequests + ? legacy_hal::NAN_SERVICE_ACCEPT_POLICY_ALL + : legacy_hal::NAN_SERVICE_ACCEPT_POLICY_NONE; + + return true; +} + +bool convertAidlNanSubscribeRequestToLegacy(const NanSubscribeRequest& aidl_request, + legacy_hal::NanSubscribeRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: legacy_request is null"; + return false; + } + *legacy_request = {}; + + legacy_request->subscribe_id = aidl_request.baseConfigs.sessionId; + legacy_request->ttl = aidl_request.baseConfigs.ttlSec; + legacy_request->period = aidl_request.baseConfigs.discoveryWindowPeriod; + legacy_request->subscribe_count = aidl_request.baseConfigs.discoveryCount; + legacy_request->service_name_len = aidl_request.baseConfigs.serviceName.size(); + if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "service_name_len too large"; + return false; + } + memcpy(legacy_request->service_name, aidl_request.baseConfigs.serviceName.data(), + legacy_request->service_name_len); + legacy_request->subscribe_match_indicator = + convertAidlNanMatchAlgToLegacy(aidl_request.baseConfigs.discoveryMatchIndicator); + legacy_request->service_specific_info_len = aidl_request.baseConfigs.serviceSpecificInfo.size(); + if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->service_specific_info, + aidl_request.baseConfigs.serviceSpecificInfo.data(), + legacy_request->service_specific_info_len); + legacy_request->sdea_service_specific_info_len = + aidl_request.baseConfigs.extendedServiceSpecificInfo.size(); + if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "sdea_service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->sdea_service_specific_info, + aidl_request.baseConfigs.extendedServiceSpecificInfo.data(), + legacy_request->sdea_service_specific_info_len); + legacy_request->rx_match_filter_len = aidl_request.baseConfigs.rxMatchFilter.size(); + if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "rx_match_filter_len too large"; + return false; + } + memcpy(legacy_request->rx_match_filter, aidl_request.baseConfigs.rxMatchFilter.data(), + legacy_request->rx_match_filter_len); + legacy_request->tx_match_filter_len = aidl_request.baseConfigs.txMatchFilter.size(); + if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "tx_match_filter_len too large"; + return false; + } + memcpy(legacy_request->tx_match_filter, aidl_request.baseConfigs.txMatchFilter.data(), + legacy_request->tx_match_filter_len); + legacy_request->rssi_threshold_flag = aidl_request.baseConfigs.useRssiThreshold; + legacy_request->recv_indication_cfg = 0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; + legacy_request->recv_indication_cfg |= + aidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; + legacy_request->cipher_type = (unsigned int)aidl_request.baseConfigs.securityConfig.cipherType; + if (aidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; + legacy_request->key_info.body.pmk_info.pmk_len = + aidl_request.baseConfigs.securityConfig.pmk.size(); + if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: invalid pmk_len"; + return false; + } + memcpy(legacy_request->key_info.body.pmk_info.pmk, + aidl_request.baseConfigs.securityConfig.pmk.data(), + legacy_request->key_info.body.pmk_info.pmk_len); + } + if (aidl_request.baseConfigs.securityConfig.securityType == + NanDataPathSecurityType::PASSPHRASE) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; + legacy_request->key_info.body.passphrase_info.passphrase_len = + aidl_request.baseConfigs.securityConfig.passphrase.size(); + if (legacy_request->key_info.body.passphrase_info.passphrase_len < + NAN_SECURITY_MIN_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "passphrase_len too small"; + return false; + } + if (legacy_request->key_info.body.passphrase_info.passphrase_len > + NAN_SECURITY_MAX_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "passphrase_len too large"; + return false; + } + memcpy(legacy_request->key_info.body.passphrase_info.passphrase, + aidl_request.baseConfigs.securityConfig.passphrase.data(), + legacy_request->key_info.body.passphrase_info.passphrase_len); + } + legacy_request->sdea_params.security_cfg = + (aidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) + ? legacy_hal::NAN_DP_CONFIG_SECURITY + : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; + legacy_request->sdea_params.ranging_state = aidl_request.baseConfigs.rangingRequired + ? legacy_hal::NAN_RANGING_ENABLE + : legacy_hal::NAN_RANGING_DISABLE; + legacy_request->ranging_cfg.ranging_interval_msec = aidl_request.baseConfigs.rangingIntervalMs; + legacy_request->ranging_cfg.config_ranging_indications = + static_cast(aidl_request.baseConfigs.configRangingIndications); + legacy_request->ranging_cfg.distance_ingress_mm = + aidl_request.baseConfigs.distanceIngressCm * 10; + legacy_request->ranging_cfg.distance_egress_mm = aidl_request.baseConfigs.distanceEgressCm * 10; + legacy_request->ranging_auto_response = aidl_request.baseConfigs.rangingRequired + ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE + : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; + legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; + legacy_request->subscribe_type = + convertAidlNanSubscribeTypeToLegacy(aidl_request.subscribeType); + legacy_request->serviceResponseFilter = convertAidlNanSrfTypeToLegacy(aidl_request.srfType); + legacy_request->serviceResponseInclude = aidl_request.srfRespondIfInAddressSet + ? legacy_hal::NAN_SRF_INCLUDE_RESPOND + : legacy_hal::NAN_SRF_INCLUDE_DO_NOT_RESPOND; + legacy_request->useServiceResponseFilter = + aidl_request.shouldUseSrf ? legacy_hal::NAN_USE_SRF : legacy_hal::NAN_DO_NOT_USE_SRF; + legacy_request->ssiRequiredForMatchIndication = + aidl_request.isSsiRequiredForMatch ? legacy_hal::NAN_SSI_REQUIRED_IN_MATCH_IND + : legacy_hal::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND; + legacy_request->num_intf_addr_present = aidl_request.intfAddr.size(); + if (legacy_request->num_intf_addr_present > NAN_MAX_SUBSCRIBE_MAX_ADDRESS) { + LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " + "num_intf_addr_present - too many"; + return false; + } + for (int i = 0; i < legacy_request->num_intf_addr_present; i++) { + memcpy(legacy_request->intf_addr[i], aidl_request.intfAddr[i].data.data(), 6); + } + + return true; +} + +bool convertAidlNanTransmitFollowupRequestToLegacy( + const NanTransmitFollowupRequest& aidl_request, + legacy_hal::NanTransmitFollowupRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " + "legacy_request is null"; + return false; + } + *legacy_request = {}; + + legacy_request->publish_subscribe_id = aidl_request.discoverySessionId; + legacy_request->requestor_instance_id = aidl_request.peerId; + memcpy(legacy_request->addr, aidl_request.addr.data(), 6); + legacy_request->priority = aidl_request.isHighPriority ? legacy_hal::NAN_TX_PRIORITY_HIGH + : legacy_hal::NAN_TX_PRIORITY_NORMAL; + legacy_request->dw_or_faw = aidl_request.shouldUseDiscoveryWindow + ? legacy_hal::NAN_TRANSMIT_IN_DW + : legacy_hal::NAN_TRANSMIT_IN_FAW; + legacy_request->service_specific_info_len = aidl_request.serviceSpecificInfo.size(); + if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " + "service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->service_specific_info, aidl_request.serviceSpecificInfo.data(), + legacy_request->service_specific_info_len); + legacy_request->sdea_service_specific_info_len = + aidl_request.extendedServiceSpecificInfo.size(); + if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { + LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " + "sdea_service_specific_info_len too large"; + return false; + } + memcpy(legacy_request->sdea_service_specific_info, + aidl_request.extendedServiceSpecificInfo.data(), + legacy_request->sdea_service_specific_info_len); + legacy_request->recv_indication_cfg = aidl_request.disableFollowupResultIndication ? 0x1 : 0x0; + + return true; +} + +bool convertAidlNanDataPathInitiatorRequestToLegacy( + const NanInitiateDataPathRequest& aidl_request, + legacy_hal::NanDataPathInitiatorRequest* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "legacy_request is null"; + return false; + } + *legacy_request = {}; + + legacy_request->requestor_instance_id = aidl_request.peerId; + memcpy(legacy_request->peer_disc_mac_addr, aidl_request.peerDiscMacAddr.data(), 6); + legacy_request->channel_request_type = + convertAidlNanDataPathChannelCfgToLegacy(aidl_request.channelRequestType); + legacy_request->channel = aidl_request.channel; + if (strnlen(aidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "ifaceName too long"; + return false; + } + strlcpy(legacy_request->ndp_iface, aidl_request.ifaceName.c_str(), IFNAMSIZ + 1); + legacy_request->ndp_cfg.security_cfg = + (aidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) + ? legacy_hal::NAN_DP_CONFIG_SECURITY + : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; + legacy_request->app_info.ndp_app_info_len = aidl_request.appInfo.size(); + if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "ndp_app_info_len too large"; + return false; + } + memcpy(legacy_request->app_info.ndp_app_info, aidl_request.appInfo.data(), + legacy_request->app_info.ndp_app_info_len); + legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; + if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; + legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); + if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "invalid pmk_len"; + return false; + } + memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), + legacy_request->key_info.body.pmk_info.pmk_len); + } + if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; + legacy_request->key_info.body.passphrase_info.passphrase_len = + aidl_request.securityConfig.passphrase.size(); + if (legacy_request->key_info.body.passphrase_info.passphrase_len < + NAN_SECURITY_MIN_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "passphrase_len too small"; + return false; + } + if (legacy_request->key_info.body.passphrase_info.passphrase_len > + NAN_SECURITY_MAX_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "passphrase_len too large"; + return false; + } + memcpy(legacy_request->key_info.body.passphrase_info.passphrase, + aidl_request.securityConfig.passphrase.data(), + legacy_request->key_info.body.passphrase_info.passphrase_len); + } + legacy_request->service_name_len = aidl_request.serviceNameOutOfBand.size(); + if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " + "service_name_len too large"; + return false; + } + memcpy(legacy_request->service_name, aidl_request.serviceNameOutOfBand.data(), + legacy_request->service_name_len); + legacy_request->scid_len = aidl_request.securityConfig.scid.size(); + if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { + LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: scid_len too large"; + return false; + } + memcpy(legacy_request->scid, aidl_request.securityConfig.scid.data(), legacy_request->scid_len); + + return true; +} + +bool convertAidlNanDataPathIndicationResponseToLegacy( + const NanRespondToDataPathIndicationRequest& aidl_request, + legacy_hal::NanDataPathIndicationResponse* legacy_request) { + if (!legacy_request) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "legacy_request is null"; + return false; + } + *legacy_request = {}; + + legacy_request->rsp_code = aidl_request.acceptRequest ? legacy_hal::NAN_DP_REQUEST_ACCEPT + : legacy_hal::NAN_DP_REQUEST_REJECT; + legacy_request->ndp_instance_id = aidl_request.ndpInstanceId; + if (strnlen(aidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "ifaceName too long"; + return false; + } + strlcpy(legacy_request->ndp_iface, aidl_request.ifaceName.c_str(), IFNAMSIZ + 1); + legacy_request->ndp_cfg.security_cfg = + (aidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) + ? legacy_hal::NAN_DP_CONFIG_SECURITY + : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; + legacy_request->app_info.ndp_app_info_len = aidl_request.appInfo.size(); + if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "ndp_app_info_len too large"; + return false; + } + memcpy(legacy_request->app_info.ndp_app_info, aidl_request.appInfo.data(), + legacy_request->app_info.ndp_app_info_len); + legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; + if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; + legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); + if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "invalid pmk_len"; + return false; + } + memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), + legacy_request->key_info.body.pmk_info.pmk_len); + } + if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { + legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; + legacy_request->key_info.body.passphrase_info.passphrase_len = + aidl_request.securityConfig.passphrase.size(); + if (legacy_request->key_info.body.passphrase_info.passphrase_len < + NAN_SECURITY_MIN_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "passphrase_len too small"; + return false; + } + if (legacy_request->key_info.body.passphrase_info.passphrase_len > + NAN_SECURITY_MAX_PASSPHRASE_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "passphrase_len too large"; + return false; + } + memcpy(legacy_request->key_info.body.passphrase_info.passphrase, + aidl_request.securityConfig.passphrase.data(), + legacy_request->key_info.body.passphrase_info.passphrase_len); + } + legacy_request->service_name_len = aidl_request.serviceNameOutOfBand.size(); + if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " + "service_name_len too large"; + return false; + } + memcpy(legacy_request->service_name, aidl_request.serviceNameOutOfBand.data(), + legacy_request->service_name_len); + legacy_request->scid_len = aidl_request.securityConfig.scid.size(); + if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { + LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: scid_len too large"; + return false; + } + memcpy(legacy_request->scid, aidl_request.securityConfig.scid.data(), legacy_request->scid_len); + + return true; +} + +bool convertLegacyNanResponseHeaderToAidl(const legacy_hal::NanResponseMsg& legacy_response, + NanStatus* nanStatus) { + if (!nanStatus) { + LOG(ERROR) << "convertLegacyNanResponseHeaderToAidl: nanStatus is null"; + return false; + } + *nanStatus = {}; + + convertToNanStatus(legacy_response.status, legacy_response.nan_error, + sizeof(legacy_response.nan_error), nanStatus); + return true; +} + +bool convertLegacyNanCapabilitiesResponseToAidl(const legacy_hal::NanCapabilities& legacy_response, + NanCapabilities* aidl_response) { + if (!aidl_response) { + LOG(ERROR) << "convertLegacyNanCapabilitiesResponseToAidl: " + "aidl_response is null"; + return false; + } + *aidl_response = {}; + + aidl_response->maxConcurrentClusters = legacy_response.max_concurrent_nan_clusters; + aidl_response->maxPublishes = legacy_response.max_publishes; + aidl_response->maxSubscribes = legacy_response.max_subscribes; + aidl_response->maxServiceNameLen = legacy_response.max_service_name_len; + aidl_response->maxMatchFilterLen = legacy_response.max_match_filter_len; + aidl_response->maxTotalMatchFilterLen = legacy_response.max_total_match_filter_len; + aidl_response->maxServiceSpecificInfoLen = legacy_response.max_service_specific_info_len; + aidl_response->maxExtendedServiceSpecificInfoLen = + legacy_response.max_sdea_service_specific_info_len; + aidl_response->maxNdiInterfaces = legacy_response.max_ndi_interfaces; + aidl_response->maxNdpSessions = legacy_response.max_ndp_sessions; + aidl_response->maxAppInfoLen = legacy_response.max_app_info_len; + aidl_response->maxQueuedTransmitFollowupMsgs = + legacy_response.max_queued_transmit_followup_msgs; + aidl_response->maxSubscribeInterfaceAddresses = legacy_response.max_subscribe_address; + aidl_response->supportedCipherSuites = + static_cast(legacy_response.cipher_suites_supported); + aidl_response->instantCommunicationModeSupportFlag = legacy_response.is_instant_mode_supported; + + return true; +} + +bool convertLegacyNanMatchIndToAidl(const legacy_hal::NanMatchInd& legacy_ind, + NanMatchInd* aidl_ind) { + if (!aidl_ind) { + LOG(ERROR) << "convertLegacyNanMatchIndToAidl: aidl_ind is null"; + return false; + } + *aidl_ind = {}; + + aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; + aidl_ind->peerId = legacy_ind.requestor_instance_id; + aidl_ind->addr = std::array(); + std::copy(legacy_ind.addr, legacy_ind.addr + 6, std::begin(aidl_ind->addr)); + aidl_ind->serviceSpecificInfo = std::vector( + legacy_ind.service_specific_info, + legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); + aidl_ind->extendedServiceSpecificInfo = std::vector( + legacy_ind.sdea_service_specific_info, + legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); + aidl_ind->matchFilter = + std::vector(legacy_ind.sdf_match_filter, + legacy_ind.sdf_match_filter + legacy_ind.sdf_match_filter_len); + aidl_ind->matchOccurredInBeaconFlag = legacy_ind.match_occured_flag == 1; // NOTYPO + aidl_ind->outOfResourceFlag = legacy_ind.out_of_resource_flag == 1; + aidl_ind->rssiValue = legacy_ind.rssi_value; + aidl_ind->peerCipherType = (NanCipherSuiteType)legacy_ind.peer_cipher_type; + aidl_ind->peerRequiresSecurityEnabledInNdp = + legacy_ind.peer_sdea_params.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; + aidl_ind->peerRequiresRanging = + legacy_ind.peer_sdea_params.ranging_state == legacy_hal::NAN_RANGING_ENABLE; + aidl_ind->rangingMeasurementInMm = legacy_ind.range_info.range_measurement_mm; + aidl_ind->rangingIndicationType = + static_cast(legacy_ind.range_info.ranging_event_type); + aidl_ind->scid = std::vector(legacy_ind.scid, legacy_ind.scid + legacy_ind.scid_len); + return true; +} + +bool convertLegacyNanFollowupIndToAidl(const legacy_hal::NanFollowupInd& legacy_ind, + NanFollowupReceivedInd* aidl_ind) { + if (!aidl_ind) { + LOG(ERROR) << "convertLegacyNanFollowupIndToAidl: aidl_ind is null"; + return false; + } + *aidl_ind = {}; + + aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; + aidl_ind->peerId = legacy_ind.requestor_instance_id; + aidl_ind->addr = std::array(); + std::copy(legacy_ind.addr, legacy_ind.addr + 6, std::begin(aidl_ind->addr)); + aidl_ind->receivedInFaw = legacy_ind.dw_or_faw == 1; + aidl_ind->serviceSpecificInfo = std::vector( + legacy_ind.service_specific_info, + legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); + aidl_ind->extendedServiceSpecificInfo = std::vector( + legacy_ind.sdea_service_specific_info, + legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); + + return true; +} + +bool convertLegacyNanDataPathRequestIndToAidl(const legacy_hal::NanDataPathRequestInd& legacy_ind, + NanDataPathRequestInd* aidl_ind) { + if (!aidl_ind) { + LOG(ERROR) << "convertLegacyNanDataPathRequestIndToAidl: aidl_ind is null"; + return false; + } + *aidl_ind = {}; + + aidl_ind->discoverySessionId = legacy_ind.service_instance_id; + aidl_ind->peerDiscMacAddr = std::array(); + std::copy(legacy_ind.peer_disc_mac_addr, legacy_ind.peer_disc_mac_addr + 6, + std::begin(aidl_ind->peerDiscMacAddr)); + aidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; + aidl_ind->securityRequired = + legacy_ind.ndp_cfg.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; + aidl_ind->appInfo = std::vector( + legacy_ind.app_info.ndp_app_info, + legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); + + return true; +} + +bool convertLegacyNdpChannelInfoToAidl(const legacy_hal::NanChannelInfo& legacy_struct, + NanDataPathChannelInfo* aidl_struct) { + if (!aidl_struct) { + LOG(ERROR) << "convertLegacyNdpChannelInfoToAidl: aidl_struct is null"; + return false; + } + *aidl_struct = {}; + + aidl_struct->channelFreq = legacy_struct.channel; + aidl_struct->channelBandwidth = convertLegacyWifiChannelWidthToAidl( + (legacy_hal::wifi_channel_width)legacy_struct.bandwidth); + aidl_struct->numSpatialStreams = legacy_struct.nss; + + return true; +} + +bool convertLegacyNanDataPathConfirmIndToAidl(const legacy_hal::NanDataPathConfirmInd& legacy_ind, + NanDataPathConfirmInd* aidl_ind) { + if (!aidl_ind) { + LOG(ERROR) << "convertLegacyNanDataPathConfirmIndToAidl: aidl_ind is null"; + return false; + } + *aidl_ind = {}; + + aidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; + aidl_ind->dataPathSetupSuccess = legacy_ind.rsp_code == legacy_hal::NAN_DP_REQUEST_ACCEPT; + aidl_ind->peerNdiMacAddr = std::array(); + std::copy(legacy_ind.peer_ndi_mac_addr, legacy_ind.peer_ndi_mac_addr + 6, + std::begin(aidl_ind->peerNdiMacAddr)); + aidl_ind->appInfo = std::vector( + legacy_ind.app_info.ndp_app_info, + legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); + aidl_ind->status.status = convertLegacyNanStatusTypeToAidl(legacy_ind.reason_code); + aidl_ind->status.description = ""; + + std::vector channelInfo; + for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { + NanDataPathChannelInfo aidl_struct; + if (!convertLegacyNdpChannelInfoToAidl(legacy_ind.channel_info[i], &aidl_struct)) { + return false; + } + channelInfo.push_back(aidl_struct); + } + aidl_ind->channelInfo = channelInfo; + + return true; +} + +bool convertLegacyNanDataPathScheduleUpdateIndToAidl( + const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, + NanDataPathScheduleUpdateInd* aidl_ind) { + if (!aidl_ind) { + LOG(ERROR) << "convertLegacyNanDataPathScheduleUpdateIndToAidl: " + "aidl_ind is null"; + return false; + } + *aidl_ind = {}; + + aidl_ind->peerDiscoveryAddress = std::array(); + std::copy(legacy_ind.peer_mac_addr, legacy_ind.peer_mac_addr + 6, + std::begin(aidl_ind->peerDiscoveryAddress)); + std::vector channelInfo; + for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { + NanDataPathChannelInfo aidl_struct; + if (!convertLegacyNdpChannelInfoToAidl(legacy_ind.channel_info[i], &aidl_struct)) { + return false; + } + channelInfo.push_back(aidl_struct); + } + aidl_ind->channelInfo = channelInfo; + std::vector ndpInstanceIds; + for (unsigned int i = 0; i < legacy_ind.num_ndp_instances; ++i) { + ndpInstanceIds.push_back(legacy_ind.ndp_instance_id[i]); + } + aidl_ind->ndpInstanceIds = uintToIntVec(ndpInstanceIds); + + return true; +} + +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; + }; + CHECK(false); +} + +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; + }; + CHECK(false) << "Unknown legacy type: " << type; +} + +legacy_hal::rtt_peer_type convertAidlRttPeerTypeToLegacy(RttPeerType type) { + switch (type) { + case RttPeerType::AP: + return legacy_hal::RTT_PEER_AP; + case RttPeerType::STA: + return legacy_hal::RTT_PEER_STA; + case RttPeerType::P2P_GO: + return legacy_hal::RTT_PEER_P2P_GO; + case RttPeerType::P2P_CLIENT: + return legacy_hal::RTT_PEER_P2P_CLIENT; + case RttPeerType::NAN_TYPE: + return legacy_hal::RTT_PEER_NAN; + }; + CHECK(false); +} + +legacy_hal::wifi_channel_width convertAidlWifiChannelWidthToLegacy(WifiChannelWidthInMhz type) { + switch (type) { + case WifiChannelWidthInMhz::WIDTH_20: + return legacy_hal::WIFI_CHAN_WIDTH_20; + case WifiChannelWidthInMhz::WIDTH_40: + return legacy_hal::WIFI_CHAN_WIDTH_40; + case WifiChannelWidthInMhz::WIDTH_80: + return legacy_hal::WIFI_CHAN_WIDTH_80; + case WifiChannelWidthInMhz::WIDTH_160: + return legacy_hal::WIFI_CHAN_WIDTH_160; + case WifiChannelWidthInMhz::WIDTH_80P80: + return legacy_hal::WIFI_CHAN_WIDTH_80P80; + case WifiChannelWidthInMhz::WIDTH_5: + return legacy_hal::WIFI_CHAN_WIDTH_5; + case WifiChannelWidthInMhz::WIDTH_10: + return legacy_hal::WIFI_CHAN_WIDTH_10; + case WifiChannelWidthInMhz::WIDTH_320: + return legacy_hal::WIFI_CHAN_WIDTH_320; + case WifiChannelWidthInMhz::WIDTH_INVALID: + return legacy_hal::WIFI_CHAN_WIDTH_INVALID; + }; + CHECK(false); +} + +WifiChannelWidthInMhz convertLegacyWifiChannelWidthToAidl(legacy_hal::wifi_channel_width type) { + switch (type) { + case legacy_hal::WIFI_CHAN_WIDTH_20: + return WifiChannelWidthInMhz::WIDTH_20; + case legacy_hal::WIFI_CHAN_WIDTH_40: + return WifiChannelWidthInMhz::WIDTH_40; + case legacy_hal::WIFI_CHAN_WIDTH_80: + return WifiChannelWidthInMhz::WIDTH_80; + case legacy_hal::WIFI_CHAN_WIDTH_160: + return WifiChannelWidthInMhz::WIDTH_160; + case legacy_hal::WIFI_CHAN_WIDTH_80P80: + return WifiChannelWidthInMhz::WIDTH_80P80; + case legacy_hal::WIFI_CHAN_WIDTH_5: + return WifiChannelWidthInMhz::WIDTH_5; + case legacy_hal::WIFI_CHAN_WIDTH_10: + return WifiChannelWidthInMhz::WIDTH_10; + case legacy_hal::WIFI_CHAN_WIDTH_320: + return WifiChannelWidthInMhz::WIDTH_320; + default: + return WifiChannelWidthInMhz::WIDTH_INVALID; + }; +} + +legacy_hal::wifi_rtt_preamble convertAidlRttPreambleToLegacy(RttPreamble type) { + switch (type) { + case RttPreamble::LEGACY: + return legacy_hal::WIFI_RTT_PREAMBLE_LEGACY; + case RttPreamble::HT: + 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; + case RttPreamble::EHT: + return legacy_hal::WIFI_RTT_PREAMBLE_EHT; + }; + CHECK(false); +} + +RttPreamble convertLegacyRttPreambleToAidl(legacy_hal::wifi_rtt_preamble type) { + switch (type) { + case legacy_hal::WIFI_RTT_PREAMBLE_LEGACY: + return RttPreamble::LEGACY; + case legacy_hal::WIFI_RTT_PREAMBLE_HT: + return RttPreamble::HT; + case legacy_hal::WIFI_RTT_PREAMBLE_VHT: + return RttPreamble::VHT; + case legacy_hal::WIFI_RTT_PREAMBLE_HE: + return RttPreamble::HE; + case legacy_hal::WIFI_RTT_PREAMBLE_EHT: + return RttPreamble::EHT; + }; + CHECK(false) << "Unknown legacy type: " << type; +} + +legacy_hal::wifi_rtt_bw convertAidlRttBwToLegacy(RttBw type) { + switch (type) { + case RttBw::BW_5MHZ: + return legacy_hal::WIFI_RTT_BW_5; + case RttBw::BW_10MHZ: + return legacy_hal::WIFI_RTT_BW_10; + case RttBw::BW_20MHZ: + return legacy_hal::WIFI_RTT_BW_20; + case RttBw::BW_40MHZ: + return legacy_hal::WIFI_RTT_BW_40; + case RttBw::BW_80MHZ: + return legacy_hal::WIFI_RTT_BW_80; + case RttBw::BW_160MHZ: + return legacy_hal::WIFI_RTT_BW_160; + case RttBw::BW_320MHZ: + return legacy_hal::WIFI_RTT_BW_320; + }; + CHECK(false); +} + +RttBw convertLegacyRttBwToAidl(legacy_hal::wifi_rtt_bw type) { + switch (type) { + case legacy_hal::WIFI_RTT_BW_5: + return RttBw::BW_5MHZ; + case legacy_hal::WIFI_RTT_BW_10: + return RttBw::BW_10MHZ; + case legacy_hal::WIFI_RTT_BW_20: + return RttBw::BW_20MHZ; + case legacy_hal::WIFI_RTT_BW_40: + return RttBw::BW_40MHZ; + case legacy_hal::WIFI_RTT_BW_80: + return RttBw::BW_80MHZ; + case legacy_hal::WIFI_RTT_BW_160: + return RttBw::BW_160MHZ; + case legacy_hal::WIFI_RTT_BW_320: + return RttBw::BW_320MHZ; + }; + CHECK(false) << "Unknown legacy type: " << type; +} + +legacy_hal::wifi_motion_pattern convertAidlRttMotionPatternToLegacy(RttMotionPattern type) { + switch (type) { + case RttMotionPattern::NOT_EXPECTED: + return legacy_hal::WIFI_MOTION_NOT_EXPECTED; + case RttMotionPattern::EXPECTED: + return legacy_hal::WIFI_MOTION_EXPECTED; + case RttMotionPattern::UNKNOWN: + return legacy_hal::WIFI_MOTION_UNKNOWN; + }; + CHECK(false); +} + +WifiRatePreamble convertLegacyWifiRatePreambleToAidl(uint8_t preamble) { + switch (preamble) { + case 0: + return WifiRatePreamble::OFDM; + case 1: + return WifiRatePreamble::CCK; + case 2: + return WifiRatePreamble::HT; + case 3: + return WifiRatePreamble::VHT; + case 4: + return WifiRatePreamble::HE; + case 5: + return WifiRatePreamble::EHT; + default: + return WifiRatePreamble::RESERVED; + }; + CHECK(false) << "Unknown legacy preamble: " << preamble; +} + +WifiRateNss convertLegacyWifiRateNssToAidl(uint8_t nss) { + switch (nss) { + case 0: + return WifiRateNss::NSS_1x1; + case 1: + return WifiRateNss::NSS_2x2; + case 2: + return WifiRateNss::NSS_3x3; + case 3: + return WifiRateNss::NSS_4x4; + }; + CHECK(false) << "Unknown legacy nss: " << nss; + return {}; +} + +RttStatus convertLegacyRttStatusToAidl(legacy_hal::wifi_rtt_status status) { + switch (status) { + case legacy_hal::RTT_STATUS_SUCCESS: + return RttStatus::SUCCESS; + case legacy_hal::RTT_STATUS_FAILURE: + return RttStatus::FAILURE; + case legacy_hal::RTT_STATUS_FAIL_NO_RSP: + return RttStatus::FAIL_NO_RSP; + case legacy_hal::RTT_STATUS_FAIL_REJECTED: + return RttStatus::FAIL_REJECTED; + case legacy_hal::RTT_STATUS_FAIL_NOT_SCHEDULED_YET: + return RttStatus::FAIL_NOT_SCHEDULED_YET; + case legacy_hal::RTT_STATUS_FAIL_TM_TIMEOUT: + return RttStatus::FAIL_TM_TIMEOUT; + case legacy_hal::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL: + return RttStatus::FAIL_AP_ON_DIFF_CHANNEL; + case legacy_hal::RTT_STATUS_FAIL_NO_CAPABILITY: + return RttStatus::FAIL_NO_CAPABILITY; + case legacy_hal::RTT_STATUS_ABORTED: + return RttStatus::ABORTED; + case legacy_hal::RTT_STATUS_FAIL_INVALID_TS: + return RttStatus::FAIL_INVALID_TS; + case legacy_hal::RTT_STATUS_FAIL_PROTOCOL: + return RttStatus::FAIL_PROTOCOL; + case legacy_hal::RTT_STATUS_FAIL_SCHEDULE: + return RttStatus::FAIL_SCHEDULE; + case legacy_hal::RTT_STATUS_FAIL_BUSY_TRY_LATER: + return RttStatus::FAIL_BUSY_TRY_LATER; + case legacy_hal::RTT_STATUS_INVALID_REQ: + return RttStatus::INVALID_REQ; + case legacy_hal::RTT_STATUS_NO_WIFI: + return RttStatus::NO_WIFI; + case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE: + return RttStatus::FAIL_FTM_PARAM_OVERRIDE; + case legacy_hal::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE: + return RttStatus::NAN_RANGING_PROTOCOL_FAILURE; + case legacy_hal::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED: + return RttStatus::NAN_RANGING_CONCURRENCY_NOT_SUPPORTED; + }; + CHECK(false) << "Unknown legacy status: " << status; +} + +bool convertAidlWifiChannelInfoToLegacy(const WifiChannelInfo& aidl_info, + legacy_hal::wifi_channel_info* legacy_info) { + if (!legacy_info) { + return false; + } + *legacy_info = {}; + legacy_info->width = convertAidlWifiChannelWidthToLegacy(aidl_info.width); + legacy_info->center_freq = aidl_info.centerFreq; + legacy_info->center_freq0 = aidl_info.centerFreq0; + legacy_info->center_freq1 = aidl_info.centerFreq1; + return true; +} + +bool convertLegacyWifiChannelInfoToAidl(const legacy_hal::wifi_channel_info& legacy_info, + WifiChannelInfo* aidl_info) { + if (!aidl_info) { + return false; + } + *aidl_info = {}; + aidl_info->width = convertLegacyWifiChannelWidthToAidl(legacy_info.width); + aidl_info->centerFreq = legacy_info.center_freq; + aidl_info->centerFreq0 = legacy_info.center_freq0; + aidl_info->centerFreq1 = legacy_info.center_freq1; + return true; +} + +bool convertAidlRttConfigToLegacy(const RttConfig& aidl_config, + legacy_hal::wifi_rtt_config* legacy_config) { + if (!legacy_config) { + return false; + } + *legacy_config = {}; + CHECK(aidl_config.addr.size() == sizeof(legacy_config->addr)); + memcpy(legacy_config->addr, aidl_config.addr.data(), aidl_config.addr.size()); + legacy_config->type = convertAidlRttTypeToLegacy(aidl_config.type); + legacy_config->peer = convertAidlRttPeerTypeToLegacy(aidl_config.peer); + if (!convertAidlWifiChannelInfoToLegacy(aidl_config.channel, &legacy_config->channel)) { + return false; + } + legacy_config->burst_period = aidl_config.burstPeriod; + legacy_config->num_burst = aidl_config.numBurst; + legacy_config->num_frames_per_burst = aidl_config.numFramesPerBurst; + legacy_config->num_retries_per_rtt_frame = aidl_config.numRetriesPerRttFrame; + legacy_config->num_retries_per_ftmr = aidl_config.numRetriesPerFtmr; + legacy_config->LCI_request = aidl_config.mustRequestLci; + legacy_config->LCR_request = aidl_config.mustRequestLcr; + legacy_config->burst_duration = aidl_config.burstDuration; + legacy_config->preamble = convertAidlRttPreambleToLegacy(aidl_config.preamble); + legacy_config->bw = convertAidlRttBwToLegacy(aidl_config.bw); + return true; +} + +bool convertAidlVectorOfRttConfigToLegacy( + 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 legacy_config; + if (!convertAidlRttConfigToLegacy(aidl_config, &legacy_config)) { + return false; + } + legacy_configs->push_back(legacy_config); + } + return true; +} + +bool convertAidlRttLciInformationToLegacy(const RttLciInformation& aidl_info, + legacy_hal::wifi_lci_information* legacy_info) { + if (!legacy_info) { + return false; + } + *legacy_info = {}; + legacy_info->latitude = aidl_info.latitude; + legacy_info->longitude = aidl_info.longitude; + legacy_info->altitude = aidl_info.altitude; + legacy_info->latitude_unc = aidl_info.latitudeUnc; + legacy_info->longitude_unc = aidl_info.longitudeUnc; + legacy_info->altitude_unc = aidl_info.altitudeUnc; + legacy_info->motion_pattern = convertAidlRttMotionPatternToLegacy(aidl_info.motionPattern); + legacy_info->floor = aidl_info.floor; + legacy_info->height_above_floor = aidl_info.heightAboveFloor; + legacy_info->height_unc = aidl_info.heightUnc; + return true; +} + +bool convertAidlRttLcrInformationToLegacy(const RttLcrInformation& aidl_info, + legacy_hal::wifi_lcr_information* legacy_info) { + if (!legacy_info) { + return false; + } + *legacy_info = {}; + CHECK(aidl_info.countryCode.size() == sizeof(legacy_info->country_code)); + memcpy(legacy_info->country_code, aidl_info.countryCode.data(), aidl_info.countryCode.size()); + if (aidl_info.civicInfo.size() > sizeof(legacy_info->civic_info)) { + return false; + } + legacy_info->length = aidl_info.civicInfo.size(); + memcpy(legacy_info->civic_info, aidl_info.civicInfo.c_str(), aidl_info.civicInfo.size()); + return true; +} + +bool convertAidlRttResponderToLegacy(const RttResponder& aidl_responder, + legacy_hal::wifi_rtt_responder* legacy_responder) { + if (!legacy_responder) { + return false; + } + *legacy_responder = {}; + if (!convertAidlWifiChannelInfoToLegacy(aidl_responder.channel, &legacy_responder->channel)) { + return false; + } + legacy_responder->preamble = convertAidlRttPreambleToLegacy(aidl_responder.preamble); + return true; +} + +bool convertLegacyRttResponderToAidl(const legacy_hal::wifi_rtt_responder& legacy_responder, + RttResponder* aidl_responder) { + if (!aidl_responder) { + return false; + } + *aidl_responder = {}; + if (!convertLegacyWifiChannelInfoToAidl(legacy_responder.channel, &aidl_responder->channel)) { + return false; + } + aidl_responder->preamble = convertLegacyRttPreambleToAidl(legacy_responder.preamble); + return true; +} + +bool convertLegacyRttCapabilitiesToAidl( + const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, + RttCapabilities* aidl_capabilities) { + if (!aidl_capabilities) { + return false; + } + *aidl_capabilities = {}; + aidl_capabilities->rttOneSidedSupported = legacy_capabilities.rtt_one_sided_supported; + aidl_capabilities->rttFtmSupported = legacy_capabilities.rtt_ftm_supported; + 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->mcVersion = legacy_capabilities.mc_version; + return true; +} + +bool convertLegacyWifiRateInfoToAidl(const legacy_hal::wifi_rate& legacy_rate, + WifiRateInfo* aidl_rate) { + if (!aidl_rate) { + return false; + } + *aidl_rate = {}; + aidl_rate->preamble = convertLegacyWifiRatePreambleToAidl(legacy_rate.preamble); + aidl_rate->nss = convertLegacyWifiRateNssToAidl(legacy_rate.nss); + aidl_rate->bw = convertLegacyWifiChannelWidthToAidl( + static_cast(legacy_rate.bw)); + aidl_rate->rateMcsIdx = legacy_rate.rateMcsIdx; + aidl_rate->bitRateInKbps = legacy_rate.bitrate; + return true; +} + +bool convertLegacyRttResultToAidl(const legacy_hal::wifi_rtt_result& legacy_result, + RttResult* aidl_result) { + if (!aidl_result) { + return false; + } + *aidl_result = {}; + aidl_result->addr = std::array(); + CHECK(sizeof(legacy_result.addr) == aidl_result->addr.size()); + std::copy(legacy_result.addr, legacy_result.addr + 6, std::begin(aidl_result->addr)); + aidl_result->burstNum = legacy_result.burst_num; + aidl_result->measurementNumber = legacy_result.measurement_number; + aidl_result->successNumber = legacy_result.success_number; + aidl_result->numberPerBurstPeer = legacy_result.number_per_burst_peer; + aidl_result->status = convertLegacyRttStatusToAidl(legacy_result.status); + aidl_result->retryAfterDuration = legacy_result.retry_after_duration; + aidl_result->type = convertLegacyRttTypeToAidl(legacy_result.type); + aidl_result->rssi = legacy_result.rssi; + aidl_result->rssiSpread = legacy_result.rssi_spread; + if (!convertLegacyWifiRateInfoToAidl(legacy_result.tx_rate, &aidl_result->txRate)) { + return false; + } + if (!convertLegacyWifiRateInfoToAidl(legacy_result.rx_rate, &aidl_result->rxRate)) { + return false; + } + aidl_result->rtt = legacy_result.rtt; + aidl_result->rttSd = legacy_result.rtt_sd; + aidl_result->rttSpread = legacy_result.rtt_spread; + aidl_result->distanceInMm = legacy_result.distance_mm; + aidl_result->distanceSdInMm = legacy_result.distance_sd_mm; + aidl_result->distanceSpreadInMm = legacy_result.distance_spread_mm; + aidl_result->timeStampInUs = legacy_result.ts; + aidl_result->burstDurationInMs = legacy_result.burst_duration; + aidl_result->negotiatedBurstNum = legacy_result.negotiated_burst_num; + if (legacy_result.LCI && !convertLegacyIeToAidl(*legacy_result.LCI, &aidl_result->lci)) { + return false; + } + if (legacy_result.LCR && !convertLegacyIeToAidl(*legacy_result.LCR, &aidl_result->lcr)) { + return false; + } + return true; +} + +bool convertLegacyVectorOfRttResultToAidl( + 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, &aidl_result)) { + return false; + } + aidl_results->push_back(aidl_result); + } + return true; +} + +legacy_hal::wifi_interface_type convertAidlIfaceTypeToLegacy(IfaceType aidl_interface_type) { + switch (aidl_interface_type) { + case IfaceType::STA: + return legacy_hal::WIFI_INTERFACE_TYPE_STA; + case IfaceType::AP: + return legacy_hal::WIFI_INTERFACE_TYPE_AP; + case IfaceType::P2P: + return legacy_hal::WIFI_INTERFACE_TYPE_P2P; + case IfaceType::NAN_IFACE: + return legacy_hal::WIFI_INTERFACE_TYPE_NAN; + } + CHECK(false); +} + +legacy_hal::wifi_multi_sta_use_case convertAidlMultiStaUseCaseToLegacy( + IWifiChip::MultiStaUseCase use_case) { + switch (use_case) { + case IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY: + return legacy_hal::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY; + case IWifiChip::MultiStaUseCase::DUAL_STA_NON_TRANSIENT_UNBIASED: + return legacy_hal::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED; + } + CHECK(false); +} + +bool convertAidlCoexUnsafeChannelToLegacy( + const IWifiChip::CoexUnsafeChannel& aidl_unsafe_channel, + legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel) { + if (!legacy_unsafe_channel) { + return false; + } + *legacy_unsafe_channel = {}; + switch (aidl_unsafe_channel.band) { + case WifiBand::BAND_24GHZ: + legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_2_4_BAND; + break; + case WifiBand::BAND_5GHZ: + legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_5_0_BAND; + break; + default: + return false; + }; + legacy_unsafe_channel->channel = aidl_unsafe_channel.channel; + legacy_unsafe_channel->power_cap_dbm = aidl_unsafe_channel.powerCapDbm; + return true; +} + +bool convertAidlVectorOfCoexUnsafeChannelToLegacy( + const std::vector& aidl_unsafe_channels, + std::vector* legacy_unsafe_channels) { + if (!legacy_unsafe_channels) { + return false; + } + *legacy_unsafe_channels = {}; + for (const auto& aidl_unsafe_channel : aidl_unsafe_channels) { + legacy_hal::wifi_coex_unsafe_channel legacy_unsafe_channel; + if (!aidl_struct_util::convertAidlCoexUnsafeChannelToLegacy(aidl_unsafe_channel, + &legacy_unsafe_channel)) { + return false; + } + legacy_unsafe_channels->push_back(legacy_unsafe_channel); + } + return true; +} + +WifiAntennaMode convertLegacyAntennaConfigurationToAidl(uint32_t antenna_cfg) { + switch (antenna_cfg) { + case legacy_hal::WIFI_ANTENNA_1X1: + return WifiAntennaMode::WIFI_ANTENNA_MODE_1X1; + case legacy_hal::WIFI_ANTENNA_2X2: + return WifiAntennaMode::WIFI_ANTENNA_MODE_2X2; + case legacy_hal::WIFI_ANTENNA_3X3: + return WifiAntennaMode::WIFI_ANTENNA_MODE_3X3; + case legacy_hal::WIFI_ANTENNA_4X4: + return WifiAntennaMode::WIFI_ANTENNA_MODE_4X4; + default: + return WifiAntennaMode::WIFI_ANTENNA_MODE_UNSPECIFIED; + } +} + +bool convertLegacyWifiRadioConfigurationToAidl( + legacy_hal::wifi_radio_configuration* radio_configuration, + WifiRadioConfiguration* aidl_radio_configuration) { + if (!aidl_radio_configuration) { + return false; + } + *aidl_radio_configuration = {}; + aidl_radio_configuration->bandInfo = + aidl_struct_util::convertLegacyMacBandToAidlWifiBand(radio_configuration->band); + if (aidl_radio_configuration->bandInfo == WifiBand::BAND_UNSPECIFIED) { + LOG(ERROR) << "Unspecified band"; + return false; + } + aidl_radio_configuration->antennaMode = + aidl_struct_util::convertLegacyAntennaConfigurationToAidl( + radio_configuration->antenna_cfg); + return true; +} + +bool convertLegacyRadioCombinationsMatrixToAidl( + legacy_hal::wifi_radio_combination_matrix* legacy_matrix, + WifiRadioCombinationMatrix* aidl_matrix) { + if (!aidl_matrix || !legacy_matrix) { + return false; + } + *aidl_matrix = {}; + + int num_combinations = legacy_matrix->num_radio_combinations; + std::vector radio_combinations_vec; + if (!num_combinations) { + LOG(ERROR) << "zero radio combinations"; + return false; + } + wifi_radio_combination* l_radio_combinations_ptr = legacy_matrix->radio_combinations; + for (int i = 0; i < num_combinations; i++) { + int num_configurations = l_radio_combinations_ptr->num_radio_configurations; + WifiRadioCombination radioCombination; + std::vector radio_configurations_vec; + if (!num_configurations) { + LOG(ERROR) << "zero radio configurations"; + return false; + } + for (int j = 0; j < num_configurations; j++) { + WifiRadioConfiguration radioConfiguration; + wifi_radio_configuration* l_radio_configurations_ptr = + &l_radio_combinations_ptr->radio_configurations[j]; + if (!aidl_struct_util::convertLegacyWifiRadioConfigurationToAidl( + l_radio_configurations_ptr, &radioConfiguration)) { + LOG(ERROR) << "Error converting wifi radio configuration"; + return false; + } + radio_configurations_vec.push_back(radioConfiguration); + } + radioCombination.radioConfigurations = radio_configurations_vec; + radio_combinations_vec.push_back(radioCombination); + l_radio_combinations_ptr = + (wifi_radio_combination*)((u8*)l_radio_combinations_ptr + + sizeof(wifi_radio_combination) + + (sizeof(wifi_radio_configuration) * num_configurations)); + } + aidl_matrix->radioCombinations = radio_combinations_vec; + return true; +} + +} // namespace aidl_struct_util +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/aidl_struct_util.h b/wifi/aidl/default/aidl_struct_util.h new file mode 100644 index 0000000000..4ebfc10787 --- /dev/null +++ b/wifi/aidl/default/aidl_struct_util.h @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef AIDL_STRUCT_UTIL_H_ +#define AIDL_STRUCT_UTIL_H_ + +#include +#include +#include +#include + +#include + +#include "wifi_legacy_hal.h" + +/** + * This file contains a bunch of functions to convert structs from the legacy + * HAL to AIDL and vice versa. + */ +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +namespace aidl_struct_util { + +// Chip conversion methods. +bool convertLegacyFeaturesToAidlChipCapabilities(uint64_t legacy_feature_set, + uint32_t legacy_logger_feature_set, + uint32_t* aidl_caps); +bool convertLegacyDebugRingBufferStatusToAidl( + const legacy_hal::wifi_ring_buffer_status& legacy_status, + WifiDebugRingBufferStatus* aidl_status); +bool convertLegacyVectorOfDebugRingBufferStatusToAidl( + const std::vector& legacy_status_vec, + std::vector* aidl_status_vec); +bool convertLegacyWakeReasonStatsToAidl(const legacy_hal::WakeReasonStats& legacy_stats, + WifiDebugHostWakeReasonStats* aidl_stats); +legacy_hal::wifi_power_scenario convertAidlTxPowerScenarioToLegacy( + IWifiChip::TxPowerScenario aidl_scenario); +legacy_hal::wifi_latency_mode convertAidlLatencyModeToLegacy( + IWifiChip::LatencyMode aidl_latency_mode); +bool convertLegacyWifiMacInfosToAidl( + const std::vector& legacy_mac_infos, + std::vector* aidl_radio_mode_infos); +legacy_hal::wifi_interface_type convertAidlIfaceTypeToLegacy(IfaceType aidl_interface_type); +legacy_hal::wifi_multi_sta_use_case convertAidlMultiStaUseCaseToLegacy( + IWifiChip::MultiStaUseCase use_case); +bool convertAidlCoexUnsafeChannelToLegacy( + const IWifiChip::CoexUnsafeChannel& aidl_unsafe_channel, + legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel); +bool convertAidlVectorOfCoexUnsafeChannelToLegacy( + const std::vector& aidl_unsafe_channels, + std::vector* legacy_unsafe_channels); +bool convertLegacyRadioCombinationsMatrixToAidl( + legacy_hal::wifi_radio_combination_matrix* legacy_matrix, + WifiRadioCombinationMatrix* aidl_matrix); +WifiBand convertLegacyMacBandToAidlWifiBand(uint32_t band); +WifiAntennaMode convertLegacyAntennaConfigurationToAidl(uint32_t antenna_cfg); + +// STA iface conversion methods. +bool convertLegacyFeaturesToAidlStaCapabilities(uint64_t legacy_feature_set, + uint32_t legacy_logger_feature_set, + uint32_t* aidl_caps); +bool convertLegacyApfCapabilitiesToAidl(const legacy_hal::PacketFilterCapabilities& legacy_caps, + StaApfPacketFilterCapabilities* aidl_caps); +bool convertLegacyGscanCapabilitiesToAidl(const legacy_hal::wifi_gscan_capabilities& legacy_caps, + StaBackgroundScanCapabilities* aidl_caps); +legacy_hal::wifi_band convertAidlWifiBandToLegacy(WifiBand band); +bool convertAidlGscanParamsToLegacy(const StaBackgroundScanParameters& aidl_scan_params, + legacy_hal::wifi_scan_cmd_params* legacy_scan_params); +// |has_ie_data| indicates whether or not the wifi_scan_result includes 802.11 +// Information Elements (IEs) +bool convertLegacyGscanResultToAidl(const legacy_hal::wifi_scan_result& legacy_scan_result, + bool has_ie_data, StaScanResult* aidl_scan_result); +// |cached_results| is assumed to not include IEs. +bool convertLegacyVectorOfCachedGscanResultsToAidl( + const std::vector& legacy_cached_scan_results, + std::vector* aidl_scan_datas); +bool convertLegacyLinkLayerStatsToAidl(const legacy_hal::LinkLayerStats& legacy_stats, + StaLinkLayerStats* aidl_stats); +bool convertLegacyRoamingCapabilitiesToAidl( + const legacy_hal::wifi_roaming_capabilities& legacy_caps, + StaRoamingCapabilities* aidl_caps); +bool convertAidlRoamingConfigToLegacy(const StaRoamingConfig& aidl_config, + legacy_hal::wifi_roaming_config* legacy_config); +legacy_hal::fw_roaming_state_t convertAidlRoamingStateToLegacy(StaRoamingState state); +bool convertLegacyVectorOfDebugTxPacketFateToAidl( + const std::vector& legacy_fates, + std::vector* aidl_fates); +bool convertLegacyVectorOfDebugRxPacketFateToAidl( + const std::vector& legacy_fates, + std::vector* aidl_fates); + +// NAN iface conversion methods. +void convertToNanStatus(legacy_hal::NanStatusType type, const char* str, size_t max_len, + NanStatus* nanStatus); +bool convertAidlNanEnableRequestToLegacy(const NanEnableRequest& aidl_request1, + const NanConfigRequestSupplemental& aidl_request2, + legacy_hal::NanEnableRequest* legacy_request); +bool convertAidlNanConfigRequestToLegacy(const NanConfigRequest& aidl_request1, + const NanConfigRequestSupplemental& aidl_request2, + legacy_hal::NanConfigRequest* legacy_request); +bool convertAidlNanPublishRequestToLegacy(const NanPublishRequest& aidl_request, + legacy_hal::NanPublishRequest* legacy_request); +bool convertAidlNanSubscribeRequestToLegacy(const NanSubscribeRequest& aidl_request, + legacy_hal::NanSubscribeRequest* legacy_request); +bool convertAidlNanTransmitFollowupRequestToLegacy( + const NanTransmitFollowupRequest& aidl_request, + legacy_hal::NanTransmitFollowupRequest* legacy_request); +bool convertAidlNanDataPathInitiatorRequestToLegacy( + const NanInitiateDataPathRequest& aidl_request, + legacy_hal::NanDataPathInitiatorRequest* legacy_request); +bool convertAidlNanDataPathIndicationResponseToLegacy( + const NanRespondToDataPathIndicationRequest& aidl_response, + legacy_hal::NanDataPathIndicationResponse* legacy_response); +bool convertLegacyNanResponseHeaderToAidl(const legacy_hal::NanResponseMsg& legacy_response, + NanStatus* nanStatus); +bool convertLegacyNanCapabilitiesResponseToAidl(const legacy_hal::NanCapabilities& legacy_response, + NanCapabilities* aidl_response); +bool convertLegacyNanMatchIndToAidl(const legacy_hal::NanMatchInd& legacy_ind, + NanMatchInd* aidl_ind); +bool convertLegacyNanFollowupIndToAidl(const legacy_hal::NanFollowupInd& legacy_ind, + NanFollowupReceivedInd* aidl_ind); +bool convertLegacyNanDataPathRequestIndToAidl(const legacy_hal::NanDataPathRequestInd& legacy_ind, + NanDataPathRequestInd* aidl_ind); +bool convertLegacyNanDataPathConfirmIndToAidl(const legacy_hal::NanDataPathConfirmInd& legacy_ind, + NanDataPathConfirmInd* aidl_ind); +bool convertLegacyNanDataPathScheduleUpdateIndToAidl( + const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, + NanDataPathScheduleUpdateInd* aidl_ind); + +// RTT controller conversion methods. +bool convertAidlVectorOfRttConfigToLegacy(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, + legacy_hal::wifi_lcr_information* legacy_info); +bool convertAidlRttResponderToLegacy(const RttResponder& aidl_responder, + legacy_hal::wifi_rtt_responder* legacy_responder); +bool convertAidlWifiChannelInfoToLegacy(const WifiChannelInfo& aidl_info, + legacy_hal::wifi_channel_info* legacy_info); +bool convertLegacyRttResponderToAidl(const legacy_hal::wifi_rtt_responder& legacy_responder, + RttResponder* aidl_responder); +bool convertLegacyRttCapabilitiesToAidl( + const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, + RttCapabilities* aidl_capabilities); +bool convertLegacyVectorOfRttResultToAidl( + 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); +bool convertLegacyWifiUsableChannelsToAidl( + const std::vector& legacy_usable_channels, + std::vector* aidl_usable_channels); +bool convertLegacyPeerInfoStatsToAidl(const legacy_hal::WifiPeerInfo& legacy_peer_info_stats, + StaPeerInfo* aidl_peer_info_stats); +bool convertLegacyWifiRateInfoToAidl(const legacy_hal::wifi_rate& legacy_rate, + WifiRateInfo* aidl_rate); +} // namespace aidl_struct_util +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // AIDL_STRUCT_UTIL_H_ diff --git a/wifi/1.6/default/hidl_sync_util.cpp b/wifi/aidl/default/aidl_sync_util.cpp similarity index 78% rename from wifi/1.6/default/hidl_sync_util.cpp rename to wifi/aidl/default/aidl_sync_util.cpp index 358d95e668..d81eb81182 100644 --- a/wifi/1.6/default/hidl_sync_util.cpp +++ b/wifi/aidl/default/aidl_sync_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,26 +14,24 @@ * limitations under the License. */ -#include "hidl_sync_util.h" +#include "aidl_sync_util.h" namespace { std::recursive_mutex g_mutex; } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_sync_util { +namespace aidl_sync_util { std::unique_lock acquireGlobalLock() { return std::unique_lock{g_mutex}; } -} // namespace hidl_sync_util -} // namespace implementation -} // namespace V1_6 +} // namespace aidl_sync_util } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/hidl_sync_util.h b/wifi/aidl/default/aidl_sync_util.h similarity index 71% rename from wifi/1.6/default/hidl_sync_util.h rename to wifi/aidl/default/aidl_sync_util.h index 2c1c37b0ad..a61cd3f57c 100644 --- a/wifi/1.6/default/hidl_sync_util.h +++ b/wifi/aidl/default/aidl_sync_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,24 +14,22 @@ * limitations under the License. */ -#ifndef HIDL_SYNC_UTIL_H_ -#define HIDL_SYNC_UTIL_H_ +#ifndef AIDL_SYNC_UTIL_H_ +#define AIDL_SYNC_UTIL_H_ #include // Utility that provides a global lock to synchronize access between -// the HIDL thread and the legacy HAL's event loop. +// the AIDL thread and the legacy HAL's event loop. +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -namespace hidl_sync_util { +namespace aidl_sync_util { std::unique_lock acquireGlobalLock(); -} // namespace hidl_sync_util -} // namespace implementation -} // namespace V1_6 +} // namespace aidl_sync_util } // namespace wifi } // namespace hardware } // namespace android -#endif // HIDL_SYNC_UTIL_H_ +} // namespace aidl +#endif // AIDL_SYNC_UTIL_H_ diff --git a/wifi/aidl/default/android.hardware.wifi-service-lazy.rc b/wifi/aidl/default/android.hardware.wifi-service-lazy.rc new file mode 100644 index 0000000000..12d3ff7bde --- /dev/null +++ b/wifi/aidl/default/android.hardware.wifi-service-lazy.rc @@ -0,0 +1,8 @@ +service vendor.wifi_hal_legacy /vendor/bin/hw/android.hardware.wifi-service-lazy + interface aidl android.hardware.wifi.IWifi/default + oneshot + disabled + class hal + capabilities NET_ADMIN NET_RAW SYS_MODULE + user wifi + group wifi gps diff --git a/wifi/aidl/default/android.hardware.wifi-service.rc b/wifi/aidl/default/android.hardware.wifi-service.rc new file mode 100644 index 0000000000..ec8acf5767 --- /dev/null +++ b/wifi/aidl/default/android.hardware.wifi-service.rc @@ -0,0 +1,6 @@ +service vendor.wifi_hal_legacy /vendor/bin/hw/android.hardware.wifi-service + interface aidl android.hardware.wifi.IWifi/default + class hal + capabilities NET_ADMIN NET_RAW SYS_MODULE + user wifi + group wifi gps diff --git a/wifi/aidl/default/android.hardware.wifi-service.xml b/wifi/aidl/default/android.hardware.wifi-service.xml new file mode 100644 index 0000000000..5398ee77b5 --- /dev/null +++ b/wifi/aidl/default/android.hardware.wifi-service.xml @@ -0,0 +1,6 @@ + + + android.hardware.wifi + IWifi/default + + diff --git a/wifi/1.6/default/ringbuffer.cpp b/wifi/aidl/default/ringbuffer.cpp similarity index 92% rename from wifi/1.6/default/ringbuffer.cpp rename to wifi/aidl/default/ringbuffer.cpp index 981bf7bce7..9d08a7368e 100644 --- a/wifi/1.6/default/ringbuffer.cpp +++ b/wifi/aidl/default/ringbuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,15 +14,14 @@ * limitations under the License. */ -#include - #include "ringbuffer.h" +#include + +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { Ringbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {} @@ -57,8 +56,7 @@ void Ringbuffer::clear() { size_ = 0; } -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/ringbuffer.h b/wifi/aidl/default/ringbuffer.h similarity index 90% rename from wifi/1.6/default/ringbuffer.h rename to wifi/aidl/default/ringbuffer.h index c6a1e4c52d..80c0c11045 100644 --- a/wifi/1.6/default/ringbuffer.h +++ b/wifi/aidl/default/ringbuffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2022 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. @@ -20,11 +20,10 @@ #include #include +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { /** * Ringbuffer object used to store debug data. @@ -53,10 +52,9 @@ class Ringbuffer { size_t maxSize_; }; -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // RINGBUFFER_H_ diff --git a/wifi/aidl/default/service.cpp b/wifi/aidl/default/service.cpp new file mode 100644 index 0000000000..789a7a5868 --- /dev/null +++ b/wifi/aidl/default/service.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 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. + */ + +#include +#include +#include +#include + +#include "wifi.h" +#include "wifi_feature_flags.h" +#include "wifi_legacy_hal.h" +#include "wifi_legacy_hal_factory.h" +#include "wifi_mode_controller.h" + +using aidl::android::hardware::wifi::feature_flags::WifiFeatureFlags; +using aidl::android::hardware::wifi::legacy_hal::WifiLegacyHal; +using aidl::android::hardware::wifi::legacy_hal::WifiLegacyHalFactory; +using aidl::android::hardware::wifi::mode_controller::WifiModeController; + +#ifdef LAZY_SERVICE +const bool kLazyService = true; +#else +const bool kLazyService = false; +#endif + +int main(int /*argc*/, char** argv) { + signal(SIGPIPE, SIG_IGN); + android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); + LOG(INFO) << "Wifi Hal is booting up..."; + + // Prepare the RPC-serving thread pool. Allocate 1 thread in the pool, + // which our main thread will join below. + ABinderProcess_setThreadPoolMaxThreadCount(1); + + const auto iface_tool = std::make_shared<::android::wifi_system::InterfaceTool>(); + const auto legacy_hal_factory = std::make_shared(iface_tool); + + // Setup binder service + std::shared_ptr service = + ndk::SharedRefBase::make( + iface_tool, legacy_hal_factory, std::make_shared(), + std::make_shared()); + std::string instance = + std::string() + aidl::android::hardware::wifi::Wifi::descriptor + "/default"; + if (kLazyService) { + auto result = + AServiceManager_registerLazyService(service->asBinder().get(), instance.c_str()); + CHECK_EQ(result, STATUS_OK) << "Failed to register lazy wifi HAL"; + } else { + auto result = AServiceManager_addService(service->asBinder().get(), instance.c_str()); + CHECK_EQ(result, STATUS_OK) << "Failed to register wifi HAL"; + } + + ABinderProcess_startThreadPool(); + LOG(INFO) << "Joining RPC thread pool"; + ABinderProcess_joinThreadPool(); + + LOG(INFO) << "Wifi Hal is terminating..."; + return 0; +} diff --git a/wifi/1.6/default/tests/hidl_struct_util_unit_tests.cpp b/wifi/aidl/default/tests/aidl_struct_util_unit_tests.cpp similarity index 69% rename from wifi/1.6/default/tests/hidl_struct_util_unit_tests.cpp rename to wifi/aidl/default/tests/aidl_struct_util_unit_tests.cpp index 0dd0aa15bb..4a69c2426b 100644 --- a/wifi/1.6/default/tests/hidl_struct_util_unit_tests.cpp +++ b/wifi/aidl/default/tests/aidl_struct_util_unit_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,8 +18,7 @@ #include #include -#undef NAN -#include "hidl_struct_util.h" +#include "aidl_struct_util.h" using testing::Test; @@ -31,17 +30,15 @@ constexpr uint32_t kIfaceChannel2 = 5; constexpr char kIfaceName1[] = "wlan0"; constexpr char kIfaceName2[] = "wlan1"; } // namespace + +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; -using ::android::hardware::wifi::V1_6::WifiChannelWidthInMhz; -class HidlStructUtilTest : public Test {}; +class AidlStructUtilTest : public Test {}; -TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithOneMac) { +TEST_F(AidlStructUtilTest, CanConvertLegacyWifiMacInfosToAidlWithOneMac) { std::vector legacy_mac_infos; legacy_hal::WifiMacInfo legacy_mac_info1 = { .wlan_mac_id = kMacId1, @@ -52,24 +49,24 @@ TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithOneMac) { legacy_mac_info1.iface_infos.push_back(legacy_iface_info2); legacy_mac_infos.push_back(legacy_mac_info1); - std::vector hidl_radio_mode_infos; - ASSERT_TRUE(hidl_struct_util::convertLegacyWifiMacInfosToHidl(legacy_mac_infos, - &hidl_radio_mode_infos)); + std::vector aidl_radio_mode_infos; + ASSERT_TRUE(aidl_struct_util::convertLegacyWifiMacInfosToAidl(legacy_mac_infos, + &aidl_radio_mode_infos)); - ASSERT_EQ(1u, hidl_radio_mode_infos.size()); - auto hidl_radio_mode_info1 = hidl_radio_mode_infos[0]; - EXPECT_EQ(legacy_mac_info1.wlan_mac_id, hidl_radio_mode_info1.radioId); - EXPECT_EQ(V1_4::WifiBand::BAND_24GHZ_5GHZ, hidl_radio_mode_info1.bandInfo); - ASSERT_EQ(2u, hidl_radio_mode_info1.ifaceInfos.size()); - auto hidl_iface_info1 = hidl_radio_mode_info1.ifaceInfos[0]; - EXPECT_EQ(legacy_iface_info1.name, hidl_iface_info1.name); - EXPECT_EQ(static_cast(legacy_iface_info1.channel), hidl_iface_info1.channel); - auto hidl_iface_info2 = hidl_radio_mode_info1.ifaceInfos[1]; - EXPECT_EQ(legacy_iface_info2.name, hidl_iface_info2.name); - EXPECT_EQ(static_cast(legacy_iface_info2.channel), hidl_iface_info2.channel); + ASSERT_EQ(1u, aidl_radio_mode_infos.size()); + auto aidl_radio_mode_info1 = aidl_radio_mode_infos[0]; + EXPECT_EQ(legacy_mac_info1.wlan_mac_id, (uint32_t)aidl_radio_mode_info1.radioId); + EXPECT_EQ(WifiBand::BAND_24GHZ_5GHZ, aidl_radio_mode_info1.bandInfo); + ASSERT_EQ(2u, aidl_radio_mode_info1.ifaceInfos.size()); + auto aidl_iface_info1 = aidl_radio_mode_info1.ifaceInfos[0]; + EXPECT_EQ(legacy_iface_info1.name, aidl_iface_info1.name); + EXPECT_EQ(static_cast(legacy_iface_info1.channel), aidl_iface_info1.channel); + auto aidl_iface_info2 = aidl_radio_mode_info1.ifaceInfos[1]; + EXPECT_EQ(legacy_iface_info2.name, aidl_iface_info2.name); + EXPECT_EQ(static_cast(legacy_iface_info2.channel), aidl_iface_info2.channel); } -TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithTwoMac) { +TEST_F(AidlStructUtilTest, CanConvertLegacyWifiMacInfosToAidlWithTwoMac) { std::vector legacy_mac_infos; legacy_hal::WifiMacInfo legacy_mac_info1 = {.wlan_mac_id = kMacId1, .mac_band = legacy_hal::WLAN_MAC_5_0_BAND}; @@ -82,40 +79,40 @@ TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithTwoMac) { legacy_mac_info2.iface_infos.push_back(legacy_iface_info2); legacy_mac_infos.push_back(legacy_mac_info2); - std::vector hidl_radio_mode_infos; - ASSERT_TRUE(hidl_struct_util::convertLegacyWifiMacInfosToHidl(legacy_mac_infos, - &hidl_radio_mode_infos)); + std::vector aidl_radio_mode_infos; + ASSERT_TRUE(aidl_struct_util::convertLegacyWifiMacInfosToAidl(legacy_mac_infos, + &aidl_radio_mode_infos)); - ASSERT_EQ(2u, hidl_radio_mode_infos.size()); + ASSERT_EQ(2u, aidl_radio_mode_infos.size()); // Find mac info 1. - const auto hidl_radio_mode_info1 = - std::find_if(hidl_radio_mode_infos.begin(), hidl_radio_mode_infos.end(), - [&legacy_mac_info1](const V1_4::IWifiChipEventCallback::RadioModeInfo& x) { - return x.radioId == legacy_mac_info1.wlan_mac_id; + const auto aidl_radio_mode_info1 = + std::find_if(aidl_radio_mode_infos.begin(), aidl_radio_mode_infos.end(), + [&legacy_mac_info1](const IWifiChipEventCallback::RadioModeInfo& x) { + return (uint32_t)x.radioId == legacy_mac_info1.wlan_mac_id; }); - ASSERT_NE(hidl_radio_mode_infos.end(), hidl_radio_mode_info1); - EXPECT_EQ(V1_4::WifiBand::BAND_5GHZ, hidl_radio_mode_info1->bandInfo); - ASSERT_EQ(1u, hidl_radio_mode_info1->ifaceInfos.size()); - auto hidl_iface_info1 = hidl_radio_mode_info1->ifaceInfos[0]; - EXPECT_EQ(legacy_iface_info1.name, hidl_iface_info1.name); - EXPECT_EQ(static_cast(legacy_iface_info1.channel), hidl_iface_info1.channel); + ASSERT_NE(aidl_radio_mode_infos.end(), aidl_radio_mode_info1); + EXPECT_EQ(WifiBand::BAND_5GHZ, aidl_radio_mode_info1->bandInfo); + ASSERT_EQ(1u, aidl_radio_mode_info1->ifaceInfos.size()); + auto aidl_iface_info1 = aidl_radio_mode_info1->ifaceInfos[0]; + EXPECT_EQ(legacy_iface_info1.name, aidl_iface_info1.name); + EXPECT_EQ(static_cast(legacy_iface_info1.channel), aidl_iface_info1.channel); // Find mac info 2. - const auto hidl_radio_mode_info2 = - std::find_if(hidl_radio_mode_infos.begin(), hidl_radio_mode_infos.end(), - [&legacy_mac_info2](const V1_4::IWifiChipEventCallback::RadioModeInfo& x) { - return x.radioId == legacy_mac_info2.wlan_mac_id; + const auto aidl_radio_mode_info2 = + std::find_if(aidl_radio_mode_infos.begin(), aidl_radio_mode_infos.end(), + [&legacy_mac_info2](const IWifiChipEventCallback::RadioModeInfo& x) { + return (uint32_t)x.radioId == legacy_mac_info2.wlan_mac_id; }); - ASSERT_NE(hidl_radio_mode_infos.end(), hidl_radio_mode_info2); - EXPECT_EQ(V1_4::WifiBand::BAND_24GHZ, hidl_radio_mode_info2->bandInfo); - ASSERT_EQ(1u, hidl_radio_mode_info2->ifaceInfos.size()); - auto hidl_iface_info2 = hidl_radio_mode_info2->ifaceInfos[0]; - EXPECT_EQ(legacy_iface_info2.name, hidl_iface_info2.name); - EXPECT_EQ(static_cast(legacy_iface_info2.channel), hidl_iface_info2.channel); + ASSERT_NE(aidl_radio_mode_infos.end(), aidl_radio_mode_info2); + EXPECT_EQ(WifiBand::BAND_24GHZ, aidl_radio_mode_info2->bandInfo); + ASSERT_EQ(1u, aidl_radio_mode_info2->ifaceInfos.size()); + auto aidl_iface_info2 = aidl_radio_mode_info2->ifaceInfos[0]; + EXPECT_EQ(legacy_iface_info2.name, aidl_iface_info2.name); + EXPECT_EQ(static_cast(legacy_iface_info2.channel), aidl_iface_info2.channel); } -TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) { +TEST_F(AidlStructUtilTest, canConvertLegacyLinkLayerStatsToAidl) { legacy_hal::LinkLayerStats legacy_stats{}; legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{}); legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{}); @@ -216,77 +213,77 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) { peer.rate_stats.push_back(rate_stat2); } - V1_6::StaLinkLayerStats converted{}; - hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, &converted); - EXPECT_EQ(legacy_stats.iface.beacon_rx, converted.iface.V1_0.beaconRx); - EXPECT_EQ(legacy_stats.iface.rssi_mgmt, converted.iface.V1_0.avgRssiMgmt); + StaLinkLayerStats converted{}; + aidl_struct_util::convertLegacyLinkLayerStatsToAidl(legacy_stats, &converted); + EXPECT_EQ(legacy_stats.iface.beacon_rx, (uint32_t)converted.iface.beaconRx); + EXPECT_EQ(legacy_stats.iface.rssi_mgmt, converted.iface.avgRssiMgmt); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu, - converted.iface.V1_0.wmeBePktStats.rxMpdu); + converted.iface.wmeBePktStats.rxMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu, - converted.iface.V1_0.wmeBePktStats.txMpdu); + converted.iface.wmeBePktStats.txMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost, - converted.iface.V1_0.wmeBePktStats.lostMpdu); + converted.iface.wmeBePktStats.lostMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries, - converted.iface.V1_0.wmeBePktStats.retries); + converted.iface.wmeBePktStats.retries); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_min, - converted.iface.wmeBeContentionTimeStats.contentionTimeMinInUsec); + (uint32_t)converted.iface.wmeBeContentionTimeStats.contentionTimeMinInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_max, - converted.iface.wmeBeContentionTimeStats.contentionTimeMaxInUsec); + (uint32_t)converted.iface.wmeBeContentionTimeStats.contentionTimeMaxInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_avg, - converted.iface.wmeBeContentionTimeStats.contentionTimeAvgInUsec); + (uint32_t)converted.iface.wmeBeContentionTimeStats.contentionTimeAvgInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_num_samples, - converted.iface.wmeBeContentionTimeStats.contentionNumSamples); + (uint32_t)converted.iface.wmeBeContentionTimeStats.contentionNumSamples); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu, - converted.iface.V1_0.wmeBkPktStats.rxMpdu); + converted.iface.wmeBkPktStats.rxMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu, - converted.iface.V1_0.wmeBkPktStats.txMpdu); + converted.iface.wmeBkPktStats.txMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost, - converted.iface.V1_0.wmeBkPktStats.lostMpdu); + converted.iface.wmeBkPktStats.lostMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries, - converted.iface.V1_0.wmeBkPktStats.retries); + converted.iface.wmeBkPktStats.retries); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_min, - converted.iface.wmeBkContentionTimeStats.contentionTimeMinInUsec); + (uint32_t)converted.iface.wmeBkContentionTimeStats.contentionTimeMinInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_max, - converted.iface.wmeBkContentionTimeStats.contentionTimeMaxInUsec); + (uint32_t)converted.iface.wmeBkContentionTimeStats.contentionTimeMaxInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_avg, - converted.iface.wmeBkContentionTimeStats.contentionTimeAvgInUsec); + (uint32_t)converted.iface.wmeBkContentionTimeStats.contentionTimeAvgInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_num_samples, - converted.iface.wmeBkContentionTimeStats.contentionNumSamples); + (uint32_t)converted.iface.wmeBkContentionTimeStats.contentionNumSamples); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu, - converted.iface.V1_0.wmeViPktStats.rxMpdu); + converted.iface.wmeViPktStats.rxMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu, - converted.iface.V1_0.wmeViPktStats.txMpdu); + converted.iface.wmeViPktStats.txMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost, - converted.iface.V1_0.wmeViPktStats.lostMpdu); + converted.iface.wmeViPktStats.lostMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries, - converted.iface.V1_0.wmeViPktStats.retries); + converted.iface.wmeViPktStats.retries); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_min, - converted.iface.wmeViContentionTimeStats.contentionTimeMinInUsec); + (uint32_t)converted.iface.wmeViContentionTimeStats.contentionTimeMinInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_max, - converted.iface.wmeViContentionTimeStats.contentionTimeMaxInUsec); + (uint32_t)converted.iface.wmeViContentionTimeStats.contentionTimeMaxInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_avg, - converted.iface.wmeViContentionTimeStats.contentionTimeAvgInUsec); + (uint32_t)converted.iface.wmeViContentionTimeStats.contentionTimeAvgInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_num_samples, - converted.iface.wmeViContentionTimeStats.contentionNumSamples); + (uint32_t)converted.iface.wmeViContentionTimeStats.contentionNumSamples); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu, - converted.iface.V1_0.wmeVoPktStats.rxMpdu); + converted.iface.wmeVoPktStats.rxMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu, - converted.iface.V1_0.wmeVoPktStats.txMpdu); + converted.iface.wmeVoPktStats.txMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost, - converted.iface.V1_0.wmeVoPktStats.lostMpdu); + converted.iface.wmeVoPktStats.lostMpdu); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries, - converted.iface.V1_0.wmeVoPktStats.retries); + converted.iface.wmeVoPktStats.retries); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_min, - converted.iface.wmeVoContentionTimeStats.contentionTimeMinInUsec); + (uint32_t)converted.iface.wmeVoContentionTimeStats.contentionTimeMinInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_max, - converted.iface.wmeVoContentionTimeStats.contentionTimeMaxInUsec); + (uint32_t)converted.iface.wmeVoContentionTimeStats.contentionTimeMaxInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_avg, - converted.iface.wmeVoContentionTimeStats.contentionTimeAvgInUsec); + (uint32_t)converted.iface.wmeVoContentionTimeStats.contentionTimeAvgInUsec); EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_num_samples, - converted.iface.wmeVoContentionTimeStats.contentionNumSamples); + (uint32_t)converted.iface.wmeVoContentionTimeStats.contentionNumSamples); EXPECT_EQ(legacy_stats.iface.info.time_slicing_duty_cycle_percent, converted.iface.timeSliceDutyCycleInPercent); @@ -294,42 +291,43 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) { EXPECT_EQ(legacy_stats.radios.size(), converted.radios.size()); for (size_t i = 0; i < legacy_stats.radios.size(); i++) { EXPECT_EQ(legacy_stats.radios[i].stats.radio, converted.radios[i].radioId); - EXPECT_EQ(legacy_stats.radios[i].stats.on_time, converted.radios[i].V1_0.onTimeInMs); - EXPECT_EQ(legacy_stats.radios[i].stats.tx_time, converted.radios[i].V1_0.txTimeInMs); - EXPECT_EQ(legacy_stats.radios[i].stats.rx_time, converted.radios[i].V1_0.rxTimeInMs); + EXPECT_EQ(legacy_stats.radios[i].stats.on_time, (uint32_t)converted.radios[i].onTimeInMs); + EXPECT_EQ(legacy_stats.radios[i].stats.tx_time, (uint32_t)converted.radios[i].txTimeInMs); + EXPECT_EQ(legacy_stats.radios[i].stats.rx_time, (uint32_t)converted.radios[i].rxTimeInMs); EXPECT_EQ(legacy_stats.radios[i].stats.on_time_scan, - converted.radios[i].V1_0.onTimeInMsForScan); + (uint32_t)converted.radios[i].onTimeInMsForScan); EXPECT_EQ(legacy_stats.radios[i].tx_time_per_levels.size(), - converted.radios[i].V1_0.txTimeInMsPerLevel.size()); + converted.radios[i].txTimeInMsPerLevel.size()); for (size_t j = 0; j < legacy_stats.radios[i].tx_time_per_levels.size(); j++) { EXPECT_EQ(legacy_stats.radios[i].tx_time_per_levels[j], - converted.radios[i].V1_0.txTimeInMsPerLevel[j]); + (uint32_t)converted.radios[i].txTimeInMsPerLevel[j]); } EXPECT_EQ(legacy_stats.radios[i].stats.on_time_nbd, - converted.radios[i].onTimeInMsForNanScan); + (uint32_t)converted.radios[i].onTimeInMsForNanScan); EXPECT_EQ(legacy_stats.radios[i].stats.on_time_gscan, - converted.radios[i].onTimeInMsForBgScan); + (uint32_t)converted.radios[i].onTimeInMsForBgScan); EXPECT_EQ(legacy_stats.radios[i].stats.on_time_roam_scan, - converted.radios[i].onTimeInMsForRoamScan); + (uint32_t)converted.radios[i].onTimeInMsForRoamScan); EXPECT_EQ(legacy_stats.radios[i].stats.on_time_pno_scan, - converted.radios[i].onTimeInMsForPnoScan); + (uint32_t)converted.radios[i].onTimeInMsForPnoScan); EXPECT_EQ(legacy_stats.radios[i].stats.on_time_hs20, - converted.radios[i].onTimeInMsForHs20Scan); + (uint32_t)converted.radios[i].onTimeInMsForHs20Scan); EXPECT_EQ(legacy_stats.radios[i].channel_stats.size(), converted.radios[i].channelStats.size()); for (size_t k = 0; k < legacy_stats.radios[i].channel_stats.size(); k++) { auto& legacy_channel_st = legacy_stats.radios[i].channel_stats[k]; EXPECT_EQ(WifiChannelWidthInMhz::WIDTH_20, converted.radios[i].channelStats[k].channel.width); - EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq), + EXPECT_EQ(legacy_channel_st.channel.center_freq, converted.radios[i].channelStats[k].channel.centerFreq); - EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq0), + EXPECT_EQ(legacy_channel_st.channel.center_freq0, converted.radios[i].channelStats[k].channel.centerFreq0); - EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq1), + EXPECT_EQ(legacy_channel_st.channel.center_freq1, converted.radios[i].channelStats[k].channel.centerFreq1); EXPECT_EQ(legacy_channel_st.cca_busy_time, - converted.radios[i].channelStats[k].ccaBusyTimeInMs); - EXPECT_EQ(legacy_channel_st.on_time, converted.radios[i].channelStats[k].onTimeInMs); + (uint32_t)converted.radios[i].channelStats[k].ccaBusyTimeInMs); + EXPECT_EQ(legacy_channel_st.on_time, + (uint32_t)converted.radios[i].channelStats[k].onTimeInMs); } } @@ -347,35 +345,36 @@ TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) { EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].rate.bw, (uint32_t)converted.iface.peers[i].rateStats[j].rateInfo.bw); EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].rate.rateMcsIdx, - converted.iface.peers[i].rateStats[j].rateInfo.rateMcsIdx); + (uint32_t)converted.iface.peers[i].rateStats[j].rateInfo.rateMcsIdx); EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].tx_mpdu, - converted.iface.peers[i].rateStats[j].txMpdu); + (uint32_t)converted.iface.peers[i].rateStats[j].txMpdu); EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].rx_mpdu, - converted.iface.peers[i].rateStats[j].rxMpdu); + (uint32_t)converted.iface.peers[i].rateStats[j].rxMpdu); EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].mpdu_lost, - converted.iface.peers[i].rateStats[j].mpduLost); + (uint32_t)converted.iface.peers[i].rateStats[j].mpduLost); EXPECT_EQ(legacy_stats.peers[i].rate_stats[j].retries, - converted.iface.peers[i].rateStats[j].retries); + (uint32_t)converted.iface.peers[i].rateStats[j].retries); } } } -TEST_F(HidlStructUtilTest, CanConvertLegacyFeaturesToHidl) { - using HidlChipCaps = V1_3::IWifiChip::ChipCapabilityMask; +TEST_F(AidlStructUtilTest, CanConvertLegacyFeaturesToAidl) { + using AidlChipCaps = IWifiChip::ChipCapabilityMask; - uint32_t hidle_caps; + uint32_t aidl_caps; uint32_t legacy_feature_set = WIFI_FEATURE_D2D_RTT | WIFI_FEATURE_SET_LATENCY_MODE; uint32_t legacy_logger_feature_set = legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED; - ASSERT_TRUE(hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( - legacy_feature_set, legacy_logger_feature_set, &hidle_caps)); + ASSERT_TRUE(aidl_struct_util::convertLegacyFeaturesToAidlChipCapabilities( + legacy_feature_set, legacy_logger_feature_set, &aidl_caps)); - EXPECT_EQ(HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA | - HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS | - HidlChipCaps::DEBUG_ERROR_ALERTS | HidlChipCaps::D2D_RTT | - HidlChipCaps::SET_LATENCY_MODE | HidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP, - hidle_caps); + EXPECT_EQ((uint32_t)AidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA | + (uint32_t)AidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS | + (uint32_t)AidlChipCaps::DEBUG_ERROR_ALERTS | (uint32_t)AidlChipCaps::D2D_RTT | + (uint32_t)AidlChipCaps::SET_LATENCY_MODE | + (uint32_t)AidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP, + aidl_caps); } void insertRadioCombination(legacy_hal::wifi_radio_combination* dst_radio_combination_ptr, @@ -390,16 +389,16 @@ void verifyRadioCombination(WifiRadioCombination* radioCombination, size_t num_r legacy_hal::wifi_radio_configuration* radio_configuration) { EXPECT_EQ(num_radio_configurations, radioCombination->radioConfigurations.size()); for (size_t i = 0; i < num_radio_configurations; i++) { - EXPECT_EQ(hidl_struct_util::convertLegacyMacBandToHidlWifiBand(radio_configuration->band), + EXPECT_EQ(aidl_struct_util::convertLegacyMacBandToAidlWifiBand(radio_configuration->band), radioCombination->radioConfigurations[i].bandInfo); - EXPECT_EQ(hidl_struct_util::convertLegacyAntennaConfigurationToHidl( + EXPECT_EQ(aidl_struct_util::convertLegacyAntennaConfigurationToAidl( radio_configuration->antenna_cfg), radioCombination->radioConfigurations[i].antennaMode); radio_configuration++; } } -TEST_F(HidlStructUtilTest, canConvertLegacyRadioCombinationsMatrixToHidl) { +TEST_F(AidlStructUtilTest, canConvertLegacyRadioCombinationsMatrixToAidl) { legacy_hal::wifi_radio_configuration radio_configurations_array1[] = { {.band = legacy_hal::WLAN_MAC_2_4_BAND, .antenna_cfg = legacy_hal::WIFI_ANTENNA_1X1}, }; @@ -461,8 +460,8 @@ TEST_F(HidlStructUtilTest, canConvertLegacyRadioCombinationsMatrixToHidl) { sizeof(radio_configurations_array3) / sizeof(radio_configurations_array3[0]), radio_configurations_array3); - V1_6::WifiRadioCombinationMatrix converted_matrix{}; - hidl_struct_util::convertLegacyRadioCombinationsMatrixToHidl(legacy_matrix, &converted_matrix); + WifiRadioCombinationMatrix converted_matrix{}; + aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix, &converted_matrix); // Verify the conversion EXPECT_EQ(legacy_matrix->num_radio_combinations, converted_matrix.radioCombinations.size()); @@ -479,8 +478,8 @@ TEST_F(HidlStructUtilTest, canConvertLegacyRadioCombinationsMatrixToHidl) { sizeof(radio_configurations_array3) / sizeof(radio_configurations_array3[0]), radio_configurations_array3); } -} // namespace implementation -} // namespace V1_6 + } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/main.cpp b/wifi/aidl/default/tests/main.cpp similarity index 94% rename from wifi/1.6/default/tests/main.cpp rename to wifi/aidl/default/tests/main.cpp index 9aac837242..767422c408 100644 --- a/wifi/1.6/default/tests/main.cpp +++ b/wifi/aidl/default/tests/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. diff --git a/wifi/1.6/default/tests/mock_interface_tool.cpp b/wifi/aidl/default/tests/mock_interface_tool.cpp similarity index 86% rename from wifi/1.6/default/tests/mock_interface_tool.cpp rename to wifi/aidl/default/tests/mock_interface_tool.cpp index b99a16446c..79f3d1e638 100644 --- a/wifi/1.6/default/tests/mock_interface_tool.cpp +++ b/wifi/aidl/default/tests/mock_interface_tool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,7 +17,6 @@ #include #include -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "mock_interface_tool.h" namespace android { diff --git a/wifi/1.6/default/tests/mock_interface_tool.h b/wifi/aidl/default/tests/mock_interface_tool.h similarity index 96% rename from wifi/1.6/default/tests/mock_interface_tool.h rename to wifi/aidl/default/tests/mock_interface_tool.h index 7ce3992c7e..9795de8014 100644 --- a/wifi/1.6/default/tests/mock_interface_tool.h +++ b/wifi/aidl/default/tests/mock_interface_tool.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. diff --git a/wifi/1.6/default/tests/mock_wifi_feature_flags.cpp b/wifi/aidl/default/tests/mock_wifi_feature_flags.cpp similarity index 85% rename from wifi/1.6/default/tests/mock_wifi_feature_flags.cpp rename to wifi/aidl/default/tests/mock_wifi_feature_flags.cpp index d10b74c3a0..0c4e59deb3 100644 --- a/wifi/1.6/default/tests/mock_wifi_feature_flags.cpp +++ b/wifi/aidl/default/tests/mock_wifi_feature_flags.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,18 +18,16 @@ #include "mock_wifi_feature_flags.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace feature_flags { MockWifiFeatureFlags::MockWifiFeatureFlags() {} } // namespace feature_flags -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/mock_wifi_feature_flags.h b/wifi/aidl/default/tests/mock_wifi_feature_flags.h similarity index 77% rename from wifi/1.6/default/tests/mock_wifi_feature_flags.h rename to wifi/aidl/default/tests/mock_wifi_feature_flags.h index fbe1f7a5ac..9143d15d61 100644 --- a/wifi/1.6/default/tests/mock_wifi_feature_flags.h +++ b/wifi/aidl/default/tests/mock_wifi_feature_flags.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,30 +18,27 @@ #define MOCK_WIFI_FEATURE_FLAGS_H_ #include -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "wifi_feature_flags.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace feature_flags { class MockWifiFeatureFlags : public WifiFeatureFlags { public: MockWifiFeatureFlags(); - MOCK_METHOD1(getChipModes, std::vector(bool is_primary)); + MOCK_METHOD1(getChipModes, std::vector(bool is_primary)); MOCK_METHOD0(isApMacRandomizationDisabled, bool()); }; } // namespace feature_flags -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // MOCK_WIFI_FEATURE_FLAGS_H_ diff --git a/wifi/1.6/default/tests/mock_wifi_iface_util.cpp b/wifi/aidl/default/tests/mock_wifi_iface_util.cpp similarity index 68% rename from wifi/1.6/default/tests/mock_wifi_iface_util.cpp rename to wifi/aidl/default/tests/mock_wifi_iface_util.cpp index 24b16cb469..0f787f22b2 100644 --- a/wifi/1.6/default/tests/mock_wifi_iface_util.cpp +++ b/wifi/aidl/default/tests/mock_wifi_iface_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,22 +18,21 @@ #include #include -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "mock_wifi_iface_util.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace iface_util { -MockWifiIfaceUtil::MockWifiIfaceUtil(const std::weak_ptr iface_tool, - const std::weak_ptr legacy_hal) +MockWifiIfaceUtil::MockWifiIfaceUtil( + const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, + const std::weak_ptr legacy_hal) : WifiIfaceUtil(iface_tool, legacy_hal) {} + } // namespace iface_util -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/mock_wifi_iface_util.h b/wifi/aidl/default/tests/mock_wifi_iface_util.h similarity index 79% rename from wifi/1.6/default/tests/mock_wifi_iface_util.h rename to wifi/aidl/default/tests/mock_wifi_iface_util.h index 2701c36d76..49a8636345 100644 --- a/wifi/1.6/default/tests/mock_wifi_iface_util.h +++ b/wifi/aidl/default/tests/mock_wifi_iface_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,30 +21,30 @@ #include "wifi_iface_util.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace iface_util { -class MockWifiIfaceUtil : public WifiIfaceUtil { +class MockWifiIfaceUtil : public iface_util::WifiIfaceUtil { public: - MockWifiIfaceUtil(const std::weak_ptr iface_tool, + MockWifiIfaceUtil(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, const std::weak_ptr legacy_hal); MOCK_METHOD1(getFactoryMacAddress, std::array(const std::string&)); MOCK_METHOD2(setMacAddress, bool(const std::string&, const std::array&)); MOCK_METHOD0(getOrCreateRandomMacAddress, std::array()); - MOCK_METHOD2(registerIfaceEventHandlers, void(const std::string&, IfaceEventHandlers)); + MOCK_METHOD2(registerIfaceEventHandlers, + void(const std::string&, iface_util::IfaceEventHandlers)); MOCK_METHOD1(unregisterIfaceEventHandlers, void(const std::string&)); MOCK_METHOD2(setUpState, bool(const std::string&, bool)); MOCK_METHOD1(ifNameToIndex, unsigned(const std::string&)); }; + } // namespace iface_util -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // MOCK_WIFI_IFACE_UTIL_H_ diff --git a/wifi/1.6/default/tests/mock_wifi_legacy_hal.cpp b/wifi/aidl/default/tests/mock_wifi_legacy_hal.cpp similarity index 69% rename from wifi/1.6/default/tests/mock_wifi_legacy_hal.cpp rename to wifi/aidl/default/tests/mock_wifi_legacy_hal.cpp index 2c558612e3..33b2b1ce36 100644 --- a/wifi/1.6/default/tests/mock_wifi_legacy_hal.cpp +++ b/wifi/aidl/default/tests/mock_wifi_legacy_hal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,22 +18,20 @@ #include #include -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "mock_wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { -MockWifiLegacyHal::MockWifiLegacyHal(const std::weak_ptr iface_tool, - const wifi_hal_fn& fn, bool is_primary) +MockWifiLegacyHal::MockWifiLegacyHal( + const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, + const wifi_hal_fn& fn, bool is_primary) : WifiLegacyHal(iface_tool, fn, is_primary) {} } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/mock_wifi_legacy_hal.h b/wifi/aidl/default/tests/mock_wifi_legacy_hal.h similarity index 92% rename from wifi/1.6/default/tests/mock_wifi_legacy_hal.h rename to wifi/aidl/default/tests/mock_wifi_legacy_hal.h index 85dbf0fe49..28129a9947 100644 --- a/wifi/1.6/default/tests/mock_wifi_legacy_hal.h +++ b/wifi/aidl/default/tests/mock_wifi_legacy_hal.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,16 +21,15 @@ #include "wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { class MockWifiLegacyHal : public WifiLegacyHal { public: - MockWifiLegacyHal(const std::weak_ptr iface_tool, + MockWifiLegacyHal(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, const wifi_hal_fn& fn, bool is_primary); MOCK_METHOD0(initialize, wifi_error()); MOCK_METHOD0(start, wifi_error()); @@ -62,10 +61,9 @@ class MockWifiLegacyHal : public WifiLegacyHal { MOCK_METHOD1(getSupportedFeatureSet, std::pair(const std::string&)); }; } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // MOCK_WIFI_LEGACY_HAL_H_ diff --git a/wifi/1.6/default/tests/mock_wifi_mode_controller.cpp b/wifi/aidl/default/tests/mock_wifi_mode_controller.cpp similarity index 87% rename from wifi/1.6/default/tests/mock_wifi_mode_controller.cpp rename to wifi/aidl/default/tests/mock_wifi_mode_controller.cpp index 446f8296f8..f4cc4c4108 100644 --- a/wifi/1.6/default/tests/mock_wifi_mode_controller.cpp +++ b/wifi/aidl/default/tests/mock_wifi_mode_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,17 +21,16 @@ #undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "mock_wifi_mode_controller.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace mode_controller { MockWifiModeController::MockWifiModeController() : WifiModeController() {} + } // namespace mode_controller -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/mock_wifi_mode_controller.h b/wifi/aidl/default/tests/mock_wifi_mode_controller.h similarity index 89% rename from wifi/1.6/default/tests/mock_wifi_mode_controller.h rename to wifi/aidl/default/tests/mock_wifi_mode_controller.h index addcc81591..f77f7d0f96 100644 --- a/wifi/1.6/default/tests/mock_wifi_mode_controller.h +++ b/wifi/aidl/default/tests/mock_wifi_mode_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,11 +21,10 @@ #include "wifi_mode_controller.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace mode_controller { class MockWifiModeController : public WifiModeController { @@ -37,10 +36,9 @@ class MockWifiModeController : public WifiModeController { MOCK_METHOD0(deinitialize, bool()); }; } // namespace mode_controller -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // MOCK_WIFI_MODE_CONTROLLER_H_ diff --git a/wifi/1.6/default/tests/ringbuffer_unit_tests.cpp b/wifi/aidl/default/tests/ringbuffer_unit_tests.cpp similarity index 95% rename from wifi/1.6/default/tests/ringbuffer_unit_tests.cpp rename to wifi/aidl/default/tests/ringbuffer_unit_tests.cpp index eb86194ff0..c257100be9 100644 --- a/wifi/1.6/default/tests/ringbuffer_unit_tests.cpp +++ b/wifi/aidl/default/tests/ringbuffer_unit_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,11 +21,10 @@ using testing::Return; using testing::Test; +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { class RingbufferTest : public Test { public: @@ -90,8 +89,8 @@ TEST_F(RingbufferTest, OversizedAppendDoesNotDropExistingData) { ASSERT_EQ(1u, buffer_.getData().size()); EXPECT_EQ(input, buffer_.getData().front()); } -} // namespace implementation -} // namespace V1_6 + } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/runtests.sh b/wifi/aidl/default/tests/runtests.sh similarity index 79% rename from wifi/1.6/default/tests/runtests.sh rename to wifi/aidl/default/tests/runtests.sh index 6bce3ef8c4..1f53ab8e05 100755 --- a/wifi/1.6/default/tests/runtests.sh +++ b/wifi/aidl/default/tests/runtests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright(C) 2017 The Android Open Source Project +# Copyright(C) 2022 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. @@ -20,7 +20,7 @@ if [ -z $ANDROID_BUILD_TOP ]; then fi set -e -$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode android.hardware.wifi@1.0-service-tests +$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode android.hardware.wifi-service-tests adb root adb sync data -adb shell /data/nativetest64/vendor/android.hardware.wifi@1.0-service-tests/android.hardware.wifi@1.0-service-tests +adb shell /data/nativetest64/vendor/android.hardware.wifi-service-tests/android.hardware.wifi-service-tests diff --git a/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp b/wifi/aidl/default/tests/wifi_chip_unit_tests.cpp similarity index 66% rename from wifi/1.6/default/tests/wifi_chip_unit_tests.cpp rename to wifi/aidl/default/tests/wifi_chip_unit_tests.cpp index 81117c5e06..e66b650ded 100644 --- a/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp +++ b/wifi/aidl/default/tests/wifi_chip_unit_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, The Android Open Source Project + * Copyright (C) 2022 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. @@ -19,7 +19,6 @@ #include #include -#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38 #include "wifi_chip.h" #include "mock_interface_tool.h" @@ -33,28 +32,38 @@ using testing::Return; using testing::Test; namespace { -using android::hardware::wifi::V1_0::ChipId; - -constexpr ChipId kFakeChipId = 5; +constexpr int kFakeChipId = 5; } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { class WifiChipTest : public Test { protected: void setupV1IfaceCombination() { // clang-format off - const hidl_vec combinationsSta = { - {{{{IfaceConcurrencyType::STA}, 1}, {{IfaceConcurrencyType::P2P}, 1}}} + // 1 STA + 1 P2P + const std::vector combinationsSta = + { + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::P2P}, 1} + } + } + }; + // 1 AP + const std::vector combinationsAp = + { + { + { + {{IfaceConcurrencyType::AP}, 1} + } + } }; - const hidl_vec combinationsAp = { - {{{{IfaceConcurrencyType::AP}, 1}}} - }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV1Sta, combinationsSta}, {feature_flags::chip_mode_ids::kV1Ap, combinationsAp} }; @@ -64,14 +73,26 @@ class WifiChipTest : public Test { void setupV1_AwareIfaceCombination() { // clang-format off - const hidl_vec combinationsSta = { - {{{{IfaceConcurrencyType::STA}, 1}, - {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN}, 1}}} + // 1 STA + 1 of (P2P or NAN) + const std::vector combinationsSta = + { + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN_IFACE}, 1} + } + } }; - const hidl_vec combinationsAp = { - {{{{IfaceConcurrencyType::AP}, 1}}} + // 1 AP + const std::vector combinationsAp = + { + { + { + {{IfaceConcurrencyType::AP}, 1} + } + } }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV1Sta, combinationsSta}, {feature_flags::chip_mode_ids::kV1Ap, combinationsAp} }; @@ -81,11 +102,17 @@ class WifiChipTest : public Test { void setupV1_AwareDisabledApIfaceCombination() { // clang-format off - const hidl_vec combinationsSta = { - {{{{IfaceConcurrencyType::STA}, 1}, - {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN}, 1}}} + // 1 STA + 1 of (P2P or NAN) + const std::vector combinationsSta = + { + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN_IFACE}, 1} + } + } }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV1Sta, combinationsSta} }; // clang-format on @@ -94,12 +121,23 @@ class WifiChipTest : public Test { void setupV2_AwareIfaceCombination() { // clang-format off - const hidl_vec combinations = { - {{{{IfaceConcurrencyType::STA}, 1}, {{IfaceConcurrencyType::AP}, 1}}}, - {{{{IfaceConcurrencyType::STA}, 1}, - {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN}, 1}}} + // (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN)) + const std::vector combinations = + { + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::AP}, 1} + } + }, + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN_IFACE}, 1} + } + } }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV3, combinations} }; // clang-format on @@ -108,11 +146,17 @@ class WifiChipTest : public Test { void setupV2_AwareDisabledApIfaceCombination() { // clang-format off - const hidl_vec combinations = { - {{{{IfaceConcurrencyType::STA}, 1}, - {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN}, 1}}} + // 1 STA + 1 of (P2P or NAN) + const std::vector combinations = + { + { + { + {{IfaceConcurrencyType::STA}, 1}, + {{IfaceConcurrencyType::P2P, IfaceConcurrencyType::NAN_IFACE}, 1} + } + } }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV3, combinations} }; // clang-format on @@ -121,10 +165,17 @@ class WifiChipTest : public Test { void setup_MultiIfaceCombination() { // clang-format off - const hidl_vec combinations = { - {{{{IfaceConcurrencyType::STA}, 3}, {{IfaceConcurrencyType::AP}, 1}}} + // 3 STA + 1 AP + const std::vector combinations = + { + { + { + {{IfaceConcurrencyType::STA}, 3}, + {{IfaceConcurrencyType::AP}, 1} + } + } }; - const std::vector modes = { + const std::vector modes = { {feature_flags::chip_mode_ids::kV3, combinations} }; // clang-format on @@ -132,134 +183,93 @@ class WifiChipTest : public Test { } void assertNumberOfModes(uint32_t num_modes) { - chip_->getAvailableModes_1_6([num_modes](const WifiStatus& status, - const std::vector& modes) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - // V2_Aware has 1 mode of operation. - ASSERT_EQ(num_modes, modes.size()); - }); + std::vector modes; + ASSERT_TRUE(chip_->getAvailableModes(&modes).isOk()); + // V2_Aware has 1 mode of operation. + ASSERT_EQ(num_modes, modes.size()); } void findModeAndConfigureForIfaceType(const IfaceConcurrencyType& type) { - // This should be aligned with kInvalidModeId in wifi_chip.cpp. - ChipModeId mode_id = UINT32_MAX; - chip_->getAvailableModes_1_6([&mode_id, &type]( - const WifiStatus& status, - const std::vector& modes) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - for (const auto& mode : modes) { - for (const auto& combination : mode.availableCombinations) { - for (const auto& limit : combination.limits) { - if (limit.types.end() != - std::find(limit.types.begin(), limit.types.end(), type)) { - mode_id = mode.id; - } + // This should be aligned with kInvalidModeId in wifi_chip.cpp + int32_t mode_id = INT32_MAX; + std::vector modes; + ASSERT_TRUE(chip_->getAvailableModes(&modes).isOk()); + + for (const auto& mode : modes) { + for (const auto& combination : mode.availableCombinations) { + for (const auto& limit : combination.limits) { + if (limit.types.end() != + std::find(limit.types.begin(), limit.types.end(), type)) { + mode_id = mode.id; } } } - }); - ASSERT_NE(UINT32_MAX, mode_id); + } - chip_->configureChip(mode_id, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); + ASSERT_NE(INT32_MAX, mode_id); + ASSERT_TRUE(chip_->configureChip(mode_id).isOk()); } // Returns an empty string on error. std::string createIface(const IfaceType& type) { std::string iface_name; if (type == IfaceType::AP) { - chip_->createApIface( - [&iface_name](const WifiStatus& status, const sp& iface) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(iface.get(), nullptr); - iface->getName([&iface_name](const WifiStatus& status, - const hidl_string& name) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - iface_name = name.c_str(); - }); - } - }); - } else if (type == IfaceType::NAN) { - chip_->createNanIface( - [&iface_name](const WifiStatus& status, - const sp& iface) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(iface.get(), nullptr); - iface->getName([&iface_name](const WifiStatus& status, - const hidl_string& name) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - iface_name = name.c_str(); - }); - } - }); + std::shared_ptr iface; + if (!chip_->createApIface(&iface).isOk()) { + return ""; + } + EXPECT_NE(iface.get(), nullptr); + EXPECT_TRUE(iface->getName(&iface_name).isOk()); + } else if (type == IfaceType::NAN_IFACE) { + std::shared_ptr iface; + if (!chip_->createNanIface(&iface).isOk()) { + return ""; + } + EXPECT_NE(iface.get(), nullptr); + EXPECT_TRUE(iface->getName(&iface_name).isOk()); } else if (type == IfaceType::P2P) { - chip_->createP2pIface( - [&iface_name](const WifiStatus& status, const sp& iface) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(iface.get(), nullptr); - iface->getName([&iface_name](const WifiStatus& status, - const hidl_string& name) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - iface_name = name.c_str(); - }); - } - }); + std::shared_ptr iface; + if (!chip_->createP2pIface(&iface).isOk()) { + return ""; + } + EXPECT_NE(iface.get(), nullptr); + EXPECT_TRUE(iface->getName(&iface_name).isOk()); } else if (type == IfaceType::STA) { - chip_->createStaIface( - [&iface_name](const WifiStatus& status, const sp& iface) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(iface.get(), nullptr); - iface->getName([&iface_name](const WifiStatus& status, - const hidl_string& name) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - iface_name = name.c_str(); - }); - } - }); + std::shared_ptr iface; + if (!chip_->createStaIface(&iface).isOk()) { + return ""; + } + EXPECT_NE(iface.get(), nullptr); + EXPECT_TRUE(iface->getName(&iface_name).isOk()); } return iface_name; } void removeIface(const IfaceType& type, const std::string& iface_name) { if (type == IfaceType::AP) { - chip_->removeApIface(iface_name, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); - } else if (type == IfaceType::NAN) { - chip_->removeNanIface(iface_name, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); + ASSERT_TRUE(chip_->removeApIface(iface_name).isOk()); + } else if (type == IfaceType::NAN_IFACE) { + ASSERT_TRUE(chip_->removeNanIface(iface_name).isOk()); } else if (type == IfaceType::P2P) { - chip_->removeP2pIface(iface_name, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); + ASSERT_TRUE(chip_->removeP2pIface(iface_name).isOk()); } else if (type == IfaceType::STA) { - chip_->removeStaIface(iface_name, [](const WifiStatus& status) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - }); + ASSERT_TRUE(chip_->removeStaIface(iface_name).isOk()); } } bool createRttController() { - bool success = false; - chip_->createRttController_1_6( - NULL, [&success](const WifiStatus& status, const sp& rtt) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(rtt.get(), nullptr); - success = true; - } - }); - return success; + std::shared_ptr rtt_controller; + auto status = chip_->createRttController(nullptr, &rtt_controller); + return status.isOk(); } static void subsystemRestartHandler(const std::string& /*error*/) {} - sp chip_; - ChipId chip_id_ = kFakeChipId; + std::shared_ptr chip_; + int chip_id_ = kFakeChipId; legacy_hal::wifi_hal_fn fake_func_table_; - std::shared_ptr> iface_tool_{ - new NiceMock}; + std::shared_ptr> iface_tool_{ + new NiceMock<::android::wifi_system::MockInterfaceTool>}; std::shared_ptr> legacy_hal_{ new NiceMock(iface_tool_, fake_func_table_, true)}; std::shared_ptr> mode_controller_{ @@ -271,8 +281,8 @@ class WifiChipTest : public Test { public: void SetUp() override { - chip_ = new WifiChip(chip_id_, true, legacy_hal_, mode_controller_, iface_util_, - feature_flags_, subsystemRestartHandler); + chip_ = WifiChip::create(chip_id_, true, legacy_hal_, mode_controller_, iface_util_, + feature_flags_, subsystemRestartHandler); EXPECT_CALL(*mode_controller_, changeFirmwareMode(testing::_)) .WillRepeatedly(testing::Return(true)); @@ -301,7 +311,7 @@ class WifiChipV1IfaceCombinationTest : public WifiChipTest { setupV1IfaceCombination(); WifiChipTest::SetUp(); // V1 has 2 modes of operation. - assertNumberOfModes(2u); + assertNumberOfModes(2); } }; @@ -317,7 +327,7 @@ TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateP2p_ShouldSucceed) { TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1IfaceCombinationTest, StaMode_CreateAp_ShouldFail) { @@ -348,7 +358,7 @@ TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateP2p_ShouldFail) { TEST_F(WifiChipV1IfaceCombinationTest, ApMode_CreateNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::AP); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } ////////// V1 + Aware Iface Combinations //////////// @@ -376,7 +386,7 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateP2p_ShouldSucceed) { TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateNan_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateAp_ShouldFail) { @@ -393,37 +403,37 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateStaP2p_ShouldSucceed) TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateStaNan_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateStaP2PNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); ASSERT_FALSE(createIface(IfaceType::P2P).empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto p2p_iface_name = createIface(IfaceType::P2P); + std::string p2p_iface_name = createIface(IfaceType::P2P); ASSERT_FALSE(p2p_iface_name.empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); // After removing P2P iface, NAN iface creation should succeed. removeIface(IfaceType::P2P, p2p_iface_name); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto nan_iface_name = createIface(IfaceType::NAN); + std::string nan_iface_name = createIface(IfaceType::NAN_IFACE); ASSERT_FALSE(nan_iface_name.empty()); ASSERT_TRUE(createIface(IfaceType::P2P).empty()); // After removing NAN iface, P2P iface creation should succeed. - removeIface(IfaceType::NAN, nan_iface_name); + removeIface(IfaceType::NAN_IFACE, nan_iface_name); ASSERT_FALSE(createIface(IfaceType::P2P).empty()); } @@ -444,7 +454,7 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateP2p_ShouldFail) { TEST_F(WifiChipV1_AwareIfaceCombinationTest, ApMode_CreateNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::AP); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeNoSta) { @@ -460,7 +470,7 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowStaModeWithSta) { TEST_F(WifiChipV1_AwareIfaceCombinationTest, RttControllerFlowApToSta) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::AP); - const auto ap_iface_name = createIface(IfaceType::AP); + std::string ap_iface_name = createIface(IfaceType::AP); ASSERT_FALSE(ap_iface_name.empty()); ASSERT_FALSE(createRttController()); @@ -475,9 +485,7 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) { ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_)) .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); - chip_->selectTxPowerScenario_1_2( - V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF, - [](const WifiStatus& status) { ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); }); + ASSERT_TRUE(chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF).isOk()); } TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) { @@ -485,9 +493,7 @@ TEST_F(WifiChipV1_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) { ASSERT_EQ(createIface(IfaceType::AP), "wlan0"); EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_)) .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); - chip_->selectTxPowerScenario_1_2( - V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF, - [](const WifiStatus& status) { ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); }); + ASSERT_TRUE(chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF).isOk()); } ////////// V2 + Aware Iface Combinations //////////// @@ -515,7 +521,7 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateP2p_ShouldSucceed) { TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateNan_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateAp_ShouldSucceed) { @@ -543,9 +549,9 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApSta_ShouldSucceed) { TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateSta_AfterStaApRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); - const auto sta_iface_name = createIface(IfaceType::STA); + std::string sta_iface_name = createIface(IfaceType::STA); ASSERT_FALSE(sta_iface_name.empty()); - const auto ap_iface_name = createIface(IfaceType::AP); + std::string ap_iface_name = createIface(IfaceType::AP); ASSERT_FALSE(ap_iface_name.empty()); ASSERT_TRUE(createIface(IfaceType::STA).empty()); @@ -565,44 +571,44 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaP2p_ShouldSucceed) { TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaNan_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaP2PNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); ASSERT_FALSE(createIface(IfaceType::P2P).empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaNan_AfterP2pRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto p2p_iface_name = createIface(IfaceType::P2P); + std::string p2p_iface_name = createIface(IfaceType::P2P); ASSERT_FALSE(p2p_iface_name.empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); // After removing P2P iface, NAN iface creation should succeed. removeIface(IfaceType::P2P, p2p_iface_name); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaP2p_AfterNanRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto nan_iface_name = createIface(IfaceType::NAN); + std::string nan_iface_name = createIface(IfaceType::NAN_IFACE); ASSERT_FALSE(nan_iface_name.empty()); ASSERT_TRUE(createIface(IfaceType::P2P).empty()); // After removing NAN iface, P2P iface creation should succeed. - removeIface(IfaceType::NAN, nan_iface_name); + removeIface(IfaceType::NAN_IFACE, nan_iface_name); ASSERT_FALSE(createIface(IfaceType::P2P).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApNan_ShouldFail) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::AP); ASSERT_FALSE(createIface(IfaceType::AP).empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApP2p_ShouldFail) { @@ -614,31 +620,31 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateApP2p_ShouldFail) { TEST_F(WifiChipV2_AwareIfaceCombinationTest, StaMode_CreateStaNan_AfterP2pRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto p2p_iface_name = createIface(IfaceType::P2P); + std::string p2p_iface_name = createIface(IfaceType::P2P); ASSERT_FALSE(p2p_iface_name.empty()); - ASSERT_TRUE(createIface(IfaceType::NAN).empty()); + ASSERT_TRUE(createIface(IfaceType::NAN_IFACE).empty()); // After removing P2P iface, NAN iface creation should succeed. removeIface(IfaceType::P2P, p2p_iface_name); - ASSERT_FALSE(createIface(IfaceType::NAN).empty()); + ASSERT_FALSE(createIface(IfaceType::NAN_IFACE).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, StaMode_CreateStaP2p_AfterNanRemove_ShouldSucceed) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_FALSE(createIface(IfaceType::STA).empty()); - const auto nan_iface_name = createIface(IfaceType::NAN); + std::string nan_iface_name = createIface(IfaceType::NAN_IFACE); ASSERT_FALSE(nan_iface_name.empty()); ASSERT_TRUE(createIface(IfaceType::P2P).empty()); // After removing NAN iface, P2P iface creation should succeed. - removeIface(IfaceType::NAN, nan_iface_name); + removeIface(IfaceType::NAN_IFACE, nan_iface_name); ASSERT_FALSE(createIface(IfaceType::P2P).empty()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateStaAp_EnsureDifferentIfaceNames) { findModeAndConfigureForIfaceType(IfaceConcurrencyType::AP); - const auto sta_iface_name = createIface(IfaceType::STA); - const auto ap_iface_name = createIface(IfaceType::AP); + std::string sta_iface_name = createIface(IfaceType::STA); + std::string ap_iface_name = createIface(IfaceType::AP); ASSERT_FALSE(sta_iface_name.empty()); ASSERT_FALSE(ap_iface_name.empty()); ASSERT_NE(sta_iface_name, ap_iface_name); @@ -667,9 +673,7 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlySta) { ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan0", testing::_)) .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); - chip_->selectTxPowerScenario_1_2( - V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF, - [](const WifiStatus& status) { ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); }); + ASSERT_TRUE(chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF).isOk()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) { @@ -677,9 +681,7 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, SelectTxScenarioWithOnlyAp) { ASSERT_EQ(createIface(IfaceType::AP), "wlan1"); EXPECT_CALL(*legacy_hal_, selectTxPowerScenario("wlan1", testing::_)) .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); - chip_->selectTxPowerScenario_1_2( - V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF, - [](const WifiStatus& status) { ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); }); + ASSERT_TRUE(chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF).isOk()); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, InvalidateAndRemoveNanOnStaRemove) { @@ -687,35 +689,29 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, InvalidateAndRemoveNanOnStaRemove) ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); // Create NAN iface - ASSERT_EQ(createIface(IfaceType::NAN), "wlan0"); + ASSERT_EQ(createIface(IfaceType::NAN_IFACE), "wlan0"); // We should have 1 nan iface. - chip_->getNanIfaceNames([](const WifiStatus& status, const hidl_vec& iface_names) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - ASSERT_EQ(iface_names.size(), 1u); - ASSERT_EQ(iface_names[0], "wlan0"); - }); - // Retrieve the exact iface object. - sp nan_iface; - chip_->getNanIface("wlan0", - [&nan_iface](const WifiStatus& status, - const sp& iface) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - ASSERT_NE(iface.get(), nullptr); - nan_iface = iface; - }); + std::vector iface_names; + ASSERT_TRUE(chip_->getNanIfaceNames(&iface_names).isOk()); + ASSERT_EQ(iface_names.size(), 1u); + ASSERT_EQ(iface_names[0], "wlan0"); - // Remove the STA iface. + // Retrieve the nan iface object. + std::shared_ptr nan_iface; + ASSERT_TRUE(chip_->getNanIface("wlan0", &nan_iface).isOk()); + ASSERT_NE(nan_iface.get(), nullptr); + + // Remove the STA iface. We should have 0 nan ifaces now. removeIface(IfaceType::STA, "wlan0"); - // We should have 0 nan iface now. - chip_->getNanIfaceNames([](const WifiStatus& status, const hidl_vec& iface_names) { - ASSERT_EQ(WifiStatusCode::SUCCESS, status.code); - ASSERT_EQ(iface_names.size(), 0u); - }); - // Any operation on the nan iface object should return error now. - nan_iface->getName([](const WifiStatus& status, const std::string& /* iface_name */) { - ASSERT_EQ(WifiStatusCode::ERROR_WIFI_IFACE_INVALID, status.code); - }); + ASSERT_TRUE(chip_->getNanIfaceNames(&iface_names).isOk()); + ASSERT_EQ(iface_names.size(), 0u); + + // Any operation on the nan iface object should now return an error. + std::string name; + auto status = nan_iface->getName(&name); + ASSERT_EQ(status.getServiceSpecificError(), + static_cast(WifiStatusCode::ERROR_WIFI_IFACE_INVALID)); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, InvalidateAndRemoveRttControllerOnStaRemove) { @@ -723,30 +719,25 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, InvalidateAndRemoveRttControllerOnS ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); // Create RTT controller - sp rtt_controller; - chip_->createRttController_1_6( - NULL, [&rtt_controller](const WifiStatus& status, const sp& rtt) { - if (WifiStatusCode::SUCCESS == status.code) { - ASSERT_NE(rtt.get(), nullptr); - rtt_controller = rtt; - } - }); + std::shared_ptr rtt_controller; + ASSERT_TRUE(chip_->createRttController(nullptr, &rtt_controller).isOk()); // Remove the STA iface. removeIface(IfaceType::STA, "wlan0"); - // Any operation on the rtt controller object should return error now. - rtt_controller->getBoundIface([](const WifiStatus& status, const sp& /* iface */) { - ASSERT_EQ(WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, status.code); - }); + // Any operation on the rtt controller object should now return an error. + std::shared_ptr bound_iface; + auto status = rtt_controller->getBoundIface(&bound_iface); + ASSERT_EQ(status.getServiceSpecificError(), + static_cast(WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID)); } TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateNanWithSharedNanIface) { property_set("wifi.aware.interface", nullptr); findModeAndConfigureForIfaceType(IfaceConcurrencyType::STA); ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); - ASSERT_EQ(createIface(IfaceType::NAN), "wlan0"); - removeIface(IfaceType::NAN, "wlan0"); + ASSERT_EQ(createIface(IfaceType::NAN_IFACE), "wlan0"); + removeIface(IfaceType::NAN_IFACE, "wlan0"); EXPECT_CALL(*iface_util_, setUpState(testing::_, testing::_)).Times(0); } @@ -756,10 +747,10 @@ TEST_F(WifiChipV2_AwareIfaceCombinationTest, CreateNanWithDedicatedNanIface) { ASSERT_EQ(createIface(IfaceType::STA), "wlan0"); EXPECT_CALL(*iface_util_, ifNameToIndex("aware0")).WillOnce(testing::Return(4)); EXPECT_CALL(*iface_util_, setUpState("aware0", true)).WillOnce(testing::Return(true)); - ASSERT_EQ(createIface(IfaceType::NAN), "aware0"); + ASSERT_EQ(createIface(IfaceType::NAN_IFACE), "aware0"); EXPECT_CALL(*iface_util_, setUpState("aware0", false)).WillOnce(testing::Return(true)); - removeIface(IfaceType::NAN, "aware0"); + removeIface(IfaceType::NAN_IFACE, "aware0"); } ////////// V1 Iface Combinations when AP creation is disabled ////////// @@ -857,8 +848,8 @@ TEST_F(WifiChip_MultiIfaceTest, CreateApStartsWithIdx1) { ASSERT_EQ(createIface(IfaceType::STA), "wlan1"); ASSERT_EQ(createIface(IfaceType::STA), "wlan3"); } -} // namespace implementation -} // namespace V1_6 + } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/tests/wifi_iface_util_unit_tests.cpp b/wifi/aidl/default/tests/wifi_iface_util_unit_tests.cpp similarity index 92% rename from wifi/1.6/default/tests/wifi_iface_util_unit_tests.cpp rename to wifi/aidl/default/tests/wifi_iface_util_unit_tests.cpp index cc9a3340a5..e0db6fdc90 100644 --- a/wifi/1.6/default/tests/wifi_iface_util_unit_tests.cpp +++ b/wifi/aidl/default/tests/wifi_iface_util_unit_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019, The Android Open Source Project + * Copyright (C) 2022 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. @@ -18,7 +18,6 @@ #include #include -#undef NAN #include "wifi_iface_util.h" #include "mock_interface_tool.h" @@ -38,16 +37,16 @@ bool isValidUnicastLocallyAssignedMacAddress(const std::array& mac_a } } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace iface_util { + class WifiIfaceUtilTest : public Test { protected: - std::shared_ptr> iface_tool_{ - new NiceMock}; + std::shared_ptr> iface_tool_{ + new NiceMock<::android::wifi_system::MockInterfaceTool>}; legacy_hal::wifi_hal_fn fake_func_table_; std::shared_ptr> legacy_hal_{ new NiceMock(iface_tool_, fake_func_table_, true)}; @@ -89,8 +88,7 @@ TEST_F(WifiIfaceUtilTest, IfaceEventHandlers_SetMacAddress) { ASSERT_FALSE(callback_invoked); } } // namespace iface_util -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/tests/wifi_nan_iface_unit_tests.cpp b/wifi/aidl/default/tests/wifi_nan_iface_unit_tests.cpp new file mode 100644 index 0000000000..d40801faef --- /dev/null +++ b/wifi/aidl/default/tests/wifi_nan_iface_unit_tests.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2022 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. + */ + +#include +#include +#include +#include + +#include "wifi_nan_iface.h" + +#include "mock_interface_tool.h" +#include "mock_wifi_feature_flags.h" +#include "mock_wifi_iface_util.h" +#include "mock_wifi_legacy_hal.h" + +using testing::NiceMock; +using testing::Return; +using testing::Test; + +namespace { +constexpr char kIfaceName[] = "mockWlan0"; +} // namespace + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +bool CaptureIfaceEventHandlers(const std::string& /* iface_name*/, + iface_util::IfaceEventHandlers in_iface_event_handlers, + iface_util::IfaceEventHandlers* out_iface_event_handlers) { + *out_iface_event_handlers = in_iface_event_handlers; + return true; +} + +class MockNanIface : public WifiNanIface { + public: + MockNanIface(const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) + : WifiNanIface(ifname, is_dedicated_iface, legacy_hal, iface_util) {} + + static std::shared_ptr createMock( + const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) { + std::shared_ptr ptr = ndk::SharedRefBase::make( + ifname, is_dedicated_iface, legacy_hal, iface_util); + std::weak_ptr weak_ptr_this(ptr); + ptr->setWeakPtr(weak_ptr_this); + ptr->registerCallbackHandlers(); + return ptr; + } + + // Override getEventCallbacks() so that we can return a mocked callback object. + std::set> getEventCallbacks() override { + return {callback_}; + } + + void setMockCallback(std::shared_ptr cb) { callback_ = cb; } + + private: + std::shared_ptr callback_; +}; + +class MockNanIfaceEventCallback : public IWifiNanIfaceEventCallback { + public: + ndk::SpAIBinder asBinder() override { return ::ndk::SpAIBinder{}; } + bool isRemote() override { return false; } + + ::ndk::ScopedAStatus getInterfaceVersion(int32_t* _aidl_return) override { + *_aidl_return = 1; + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus getInterfaceHash(std::string* _aidl_return) override { + *_aidl_return = "some_hash"; + return ndk::ScopedAStatus::ok(); + } + + MOCK_METHOD3(notifyCapabilitiesResponse, + ndk::ScopedAStatus(char16_t, const NanStatus&, const NanCapabilities&)); + MOCK_METHOD2(notifyEnableResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyConfigResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyDisableResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD3(notifyStartPublishResponse, + ndk::ScopedAStatus(char16_t, const NanStatus&, int8_t)); + MOCK_METHOD2(notifyStopPublishResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD3(notifyStartSubscribeResponse, + ndk::ScopedAStatus(char16_t, const NanStatus&, int8_t)); + MOCK_METHOD2(notifyStopSubscribeResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyTransmitFollowupResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyCreateDataInterfaceResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyDeleteDataInterfaceResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD3(notifyInitiateDataPathResponse, + ndk::ScopedAStatus(char16_t, const NanStatus&, int32_t)); + MOCK_METHOD2(notifyRespondToDataPathIndicationResponse, + ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD2(notifyTerminateDataPathResponse, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD1(eventClusterEvent, ndk::ScopedAStatus(const NanClusterEventInd&)); + MOCK_METHOD1(eventDisabled, ndk::ScopedAStatus(const NanStatus&)); + MOCK_METHOD2(eventPublishTerminated, ndk::ScopedAStatus(int8_t, const NanStatus&)); + MOCK_METHOD2(eventSubscribeTerminated, ndk::ScopedAStatus(int8_t, const NanStatus&)); + MOCK_METHOD1(eventMatch, ndk::ScopedAStatus(const NanMatchInd&)); + MOCK_METHOD2(eventMatchExpired, ndk::ScopedAStatus(int8_t, int32_t)); + MOCK_METHOD1(eventFollowupReceived, ndk::ScopedAStatus(const NanFollowupReceivedInd&)); + MOCK_METHOD2(eventTransmitFollowup, ndk::ScopedAStatus(char16_t, const NanStatus&)); + MOCK_METHOD1(eventDataPathRequest, ndk::ScopedAStatus(const NanDataPathRequestInd&)); + MOCK_METHOD1(eventDataPathConfirm, ndk::ScopedAStatus(const NanDataPathConfirmInd&)); + MOCK_METHOD1(eventDataPathTerminated, ndk::ScopedAStatus(int32_t)); + MOCK_METHOD1(eventDataPathScheduleUpdate, + ndk::ScopedAStatus(const NanDataPathScheduleUpdateInd&)); +}; + +class WifiNanIfaceTest : public Test { + protected: + legacy_hal::wifi_hal_fn fake_func_table_; + std::shared_ptr> iface_tool_{ + new NiceMock<::android::wifi_system::MockInterfaceTool>}; + std::shared_ptr> legacy_hal_{ + new NiceMock(iface_tool_, fake_func_table_, true)}; + std::shared_ptr> iface_util_{ + new NiceMock(iface_tool_, legacy_hal_)}; +}; + +TEST_F(WifiNanIfaceTest, IfacEventHandlers_OnStateToggleOffOn) { + // Ensure that event handlers are registered during nan iface creation. + iface_util::IfaceEventHandlers captured_iface_event_handlers = {}; + EXPECT_CALL(*legacy_hal_, nanRegisterCallbackHandlers(testing::_, testing::_)) + .WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS)); + EXPECT_CALL(*iface_util_, registerIfaceEventHandlers(testing::_, testing::_)) + .WillOnce(testing::Invoke(bind(CaptureIfaceEventHandlers, std::placeholders::_1, + std::placeholders::_2, &captured_iface_event_handlers))); + + // Create nan iface and register a callback. + // Note: Since we can't register a callback directly (gTest fails on + // AIBinder_linkToDeath), simulate the registration by overriding + // getEventCallbacks() to return our mock callback object. + std::shared_ptr mock_nan_iface = + MockNanIface::createMock(kIfaceName, false, legacy_hal_, iface_util_); + std::shared_ptr mock_event_callback = + ndk::SharedRefBase::make(); + mock_nan_iface->setMockCallback(mock_event_callback); + + // Ensure that the eventDisabled() function in the mock callback will be invoked. + NanStatus expected_nan_status = {NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""}; + EXPECT_CALL(*mock_event_callback, eventDisabled(expected_nan_status)).Times(1); + + // Trigger the iface state toggle callback. + captured_iface_event_handlers.on_state_toggle_off_on(kIfaceName); +} + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi.cpp b/wifi/aidl/default/wifi.cpp similarity index 60% rename from wifi/1.6/default/wifi.cpp rename to wifi/aidl/default/wifi.cpp index c302ce2434..e30c38abcf 100644 --- a/wifi/1.6/default/wifi.cpp +++ b/wifi/aidl/default/wifi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,26 +14,26 @@ * limitations under the License. */ +#include "wifi.h" + #include -#include "hidl_return_util.h" -#include "wifi.h" +#include "aidl_return_util.h" #include "wifi_status_util.h" namespace { // Starting Chip ID, will be assigned to primary chip -static constexpr android::hardware::wifi::V1_0::ChipId kPrimaryChipId = 0; +static constexpr int32_t kPrimaryChipId = 0; } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; -using hidl_return_util::validateAndCallWithLock; +using aidl_return_util::validateAndCall; +using aidl_return_util::validateAndCallWithLock; -Wifi::Wifi(const std::shared_ptr iface_tool, +Wifi::Wifi(const std::shared_ptr<::android::wifi_system::InterfaceTool> iface_tool, const std::shared_ptr legacy_hal_factory, const std::shared_ptr mode_controller, const std::shared_ptr feature_flags) @@ -48,86 +48,74 @@ bool Wifi::isValid() { return true; } -Return Wifi::registerEventCallback(const sp& event_callback, - registerEventCallback_cb hidl_status_cb) { +ndk::ScopedAStatus Wifi::registerEventCallback( + const std::shared_ptr& in_callback) { return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, - &Wifi::registerEventCallbackInternal, hidl_status_cb, event_callback); + &Wifi::registerEventCallbackInternal, in_callback); } -Return Wifi::registerEventCallback_1_5(const sp& event_callback, - registerEventCallback_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, - &Wifi::registerEventCallbackInternal_1_5, hidl_status_cb, - event_callback); +ndk::ScopedAStatus Wifi::isStarted(bool* _aidl_return) { + *_aidl_return = (run_state_ != RunState::STOPPED); + return ndk::ScopedAStatus::ok(); } -Return Wifi::isStarted() { - return run_state_ != RunState::STOPPED; +ndk::ScopedAStatus Wifi::start() { + return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::startInternal); } -Return Wifi::start(start_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::startInternal, - hidl_status_cb); +ndk::ScopedAStatus Wifi::stop() { + return validateAndCallWithLock(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::stopInternal); } -Return Wifi::stop(stop_cb hidl_status_cb) { - return validateAndCallWithLock(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::stopInternal, - hidl_status_cb); -} - -Return Wifi::getChipIds(getChipIds_cb hidl_status_cb) { +ndk::ScopedAStatus Wifi::getChipIds(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::getChipIdsInternal, - hidl_status_cb); + _aidl_return); } -Return Wifi::getChip(ChipId chip_id, getChip_cb hidl_status_cb) { +ndk::ScopedAStatus Wifi::getChip(int32_t in_chipId, std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::getChipInternal, - hidl_status_cb, chip_id); + _aidl_return, in_chipId); } -Return Wifi::debug(const hidl_handle& handle, const hidl_vec&) { - LOG(INFO) << "-----------Debug is called----------------"; +binder_status_t Wifi::dump(int fd, const char** args, uint32_t numArgs) { + LOG(INFO) << "-----------Debug was called----------------"; if (chips_.size() == 0) { - return Void(); + LOG(INFO) << "No chips to display."; + return STATUS_OK; } - for (sp chip : chips_) { + for (std::shared_ptr chip : chips_) { if (!chip.get()) continue; - - chip->debug(handle, {}); + chip->dump(fd, args, numArgs); } - return Void(); + return STATUS_OK; } -WifiStatus Wifi::registerEventCallbackInternal( - const sp& event_callback __unused) { - // Deprecated support for this callback. - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus Wifi::registerEventCallbackInternal_1_5( - const sp& event_callback) { +ndk::ScopedAStatus Wifi::registerEventCallbackInternal( + const std::shared_ptr& event_callback) { if (!event_cb_handler_.addCallback(event_callback)) { return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -WifiStatus Wifi::startInternal() { +ndk::ScopedAStatus Wifi::startInternal() { if (run_state_ == RunState::STARTED) { - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } else if (run_state_ == RunState::STOPPING) { return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, "HAL is stopping"); } - WifiStatus wifi_status = initializeModeControllerAndLegacyHal(); - if (wifi_status.code == WifiStatusCode::SUCCESS) { + ndk::ScopedAStatus wifi_status = initializeModeControllerAndLegacyHal(); + if (wifi_status.isOk()) { // Register the callback for subsystem restart const auto& on_subsystem_restart_callback = [this](const std::string& error) { - WifiStatus wifi_status = createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, error); + ndk::ScopedAStatus wifi_status = createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, error); for (const auto& callback : event_cb_handler_.getCallbacks()) { LOG(INFO) << "Attempting to invoke onSubsystemRestart " "callback"; - if (!callback->onSubsystemRestart(wifi_status).isOk()) { + WifiStatusCode errorCode = + static_cast(wifi_status.getServiceSpecificError()); + if (!callback->onSubsystemRestart(errorCode).isOk()) { LOG(ERROR) << "Failed to invoke onSubsystemRestart callback"; } else { LOG(INFO) << "Succeeded to invoke onSubsystemRestart " @@ -137,12 +125,12 @@ WifiStatus Wifi::startInternal() { }; // Create the chip instance once the HAL is started. - android::hardware::wifi::V1_0::ChipId chipId = kPrimaryChipId; + int32_t chipId = kPrimaryChipId; for (auto& hal : legacy_hals_) { chips_.push_back( - new WifiChip(chipId, chipId == kPrimaryChipId, hal, mode_controller_, - std::make_shared(iface_tool_, hal), - feature_flags_, on_subsystem_restart_callback)); + WifiChip::create(chipId, chipId == kPrimaryChipId, hal, mode_controller_, + std::make_shared(iface_tool_, hal), + feature_flags_, on_subsystem_restart_callback)); chipId++; } run_state_ = RunState::STARTED; @@ -154,7 +142,9 @@ WifiStatus Wifi::startInternal() { LOG(INFO) << "Wifi HAL started"; } else { for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onFailure(wifi_status).isOk()) { + WifiStatusCode errorCode = + static_cast(wifi_status.getServiceSpecificError()); + if (!callback->onFailure(errorCode).isOk()) { LOG(ERROR) << "Failed to invoke onFailure callback"; } } @@ -165,10 +155,10 @@ WifiStatus Wifi::startInternal() { return wifi_status; } -WifiStatus Wifi::stopInternal( +ndk::ScopedAStatus Wifi::stopInternal( /* NONNULL */ std::unique_lock* lock) { if (run_state_ == RunState::STOPPED) { - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } else if (run_state_ == RunState::STOPPING) { return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, "HAL is stopping"); } @@ -177,12 +167,12 @@ WifiStatus Wifi::stopInternal( for (auto& chip : chips_) { if (chip.get()) { chip->invalidate(); - chip.clear(); + chip.reset(); } } chips_.clear(); - WifiStatus wifi_status = stopLegacyHalAndDeinitializeModeController(lock); - if (wifi_status.code == WifiStatusCode::SUCCESS) { + ndk::ScopedAStatus wifi_status = stopLegacyHalAndDeinitializeModeController(lock); + if (wifi_status.isOk()) { for (const auto& callback : event_cb_handler_.getCallbacks()) { if (!callback->onStop().isOk()) { LOG(ERROR) << "Failed to invoke onStop callback"; @@ -191,7 +181,9 @@ WifiStatus Wifi::stopInternal( LOG(INFO) << "Wifi HAL stopped"; } else { for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onFailure(wifi_status).isOk()) { + WifiStatusCode errorCode = + static_cast(wifi_status.getServiceSpecificError()); + if (!callback->onFailure(errorCode).isOk()) { LOG(ERROR) << "Failed to invoke onFailure callback"; } } @@ -202,27 +194,26 @@ WifiStatus Wifi::stopInternal( return wifi_status; } -std::pair> Wifi::getChipIdsInternal() { - std::vector chip_ids; +std::pair, ndk::ScopedAStatus> Wifi::getChipIdsInternal() { + std::vector chip_ids; for (auto& chip : chips_) { - ChipId chip_id = getChipIdFromWifiChip(chip); - if (chip_id != UINT32_MAX) chip_ids.emplace_back(chip_id); + int32_t chip_id = getChipIdFromWifiChip(chip); + if (chip_id != INT32_MAX) chip_ids.emplace_back(chip_id); } - return {createWifiStatus(WifiStatusCode::SUCCESS), std::move(chip_ids)}; + return {std::move(chip_ids), ndk::ScopedAStatus::ok()}; } -std::pair> Wifi::getChipInternal(ChipId chip_id) { +std::pair, ndk::ScopedAStatus> Wifi::getChipInternal(int32_t chip_id) { for (auto& chip : chips_) { - ChipId cand_id = getChipIdFromWifiChip(chip); - if ((cand_id != UINT32_MAX) && (cand_id == chip_id)) - return {createWifiStatus(WifiStatusCode::SUCCESS), chip}; + int32_t cand_id = getChipIdFromWifiChip(chip); + if ((cand_id != INT32_MAX) && (cand_id == chip_id)) return {chip, ndk::ScopedAStatus::ok()}; } - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } -WifiStatus Wifi::initializeModeControllerAndLegacyHal() { +ndk::ScopedAStatus Wifi::initializeModeControllerAndLegacyHal() { if (!mode_controller_->initialize()) { LOG(ERROR) << "Failed to initialize firmware mode controller"; return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); @@ -244,10 +235,10 @@ WifiStatus Wifi::initializeModeControllerAndLegacyHal() { } index++; } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -WifiStatus Wifi::stopLegacyHalAndDeinitializeModeController( +ndk::ScopedAStatus Wifi::stopLegacyHalAndDeinitializeModeController( /* NONNULL */ std::unique_lock* lock) { legacy_hal::wifi_error legacy_status = legacy_hal::WIFI_SUCCESS; int index = 0; @@ -272,23 +263,22 @@ WifiStatus Wifi::stopLegacyHalAndDeinitializeModeController( LOG(ERROR) << "Failed to deinitialize firmware mode controller"; return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -ChipId Wifi::getChipIdFromWifiChip(sp& chip) { - ChipId chip_id = UINT32_MAX; +int32_t Wifi::getChipIdFromWifiChip(std::shared_ptr& chip) { + int32_t chip_id = INT32_MAX; if (chip.get()) { - chip->getId([&](WifiStatus status, uint32_t id) { - if (status.code == WifiStatusCode::SUCCESS) { - chip_id = id; - } - }); + ndk::ScopedAStatus status = chip->getId(&chip_id); + if (!status.isOk()) { + // Reset value if operation failed. + chip_id = INT32_MAX; + } } - return chip_id; } -} // namespace implementation -} // namespace V1_6 + } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi.h b/wifi/aidl/default/wifi.h new file mode 100644 index 0000000000..933452448e --- /dev/null +++ b/wifi/aidl/default/wifi.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_H_ +#define WIFI_H_ + +#include +#include +#include + +#include + +#include "aidl_callback_util.h" +#include "wifi_chip.h" +#include "wifi_feature_flags.h" +#include "wifi_legacy_hal.h" +#include "wifi_legacy_hal_factory.h" +#include "wifi_mode_controller.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * Root AIDL interface object used to control the Wifi HAL. + */ +class Wifi : public BnWifi { + public: + Wifi(const std::shared_ptr<::android::wifi_system::InterfaceTool> iface_tool, + const std::shared_ptr legacy_hal_factory, + const std::shared_ptr mode_controller, + const std::shared_ptr feature_flags); + + bool isValid(); + + // AIDL methods exposed. + ndk::ScopedAStatus registerEventCallback( + const std::shared_ptr& in_callback) override; + ndk::ScopedAStatus isStarted(bool* _aidl_return) override; + ndk::ScopedAStatus start() override; + ndk::ScopedAStatus stop() override; + ndk::ScopedAStatus getChipIds(std::vector* _aidl_return) override; + ndk::ScopedAStatus getChip(int32_t in_chipId, + std::shared_ptr* _aidl_return) override; + binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; + + private: + enum class RunState { STOPPED, STARTED, STOPPING }; + + // Corresponding worker functions for the AIDL methods. + ndk::ScopedAStatus registerEventCallbackInternal( + const std::shared_ptr& event_callback __unused); + ndk::ScopedAStatus startInternal(); + ndk::ScopedAStatus stopInternal(std::unique_lock* lock); + std::pair, ndk::ScopedAStatus> getChipIdsInternal(); + std::pair, ndk::ScopedAStatus> getChipInternal(int32_t chip_id); + + ndk::ScopedAStatus initializeModeControllerAndLegacyHal(); + ndk::ScopedAStatus stopLegacyHalAndDeinitializeModeController( + std::unique_lock* lock); + int32_t getChipIdFromWifiChip(std::shared_ptr& chip); + + // Instance is created in this root level |IWifi| AIDL interface object + // and shared with all the child AIDL interface objects. + std::shared_ptr<::android::wifi_system::InterfaceTool> iface_tool_; + std::shared_ptr legacy_hal_factory_; + std::shared_ptr mode_controller_; + std::vector> legacy_hals_; + std::shared_ptr feature_flags_; + RunState run_state_; + std::vector> chips_; + aidl_callback_util::AidlCallbackHandler event_cb_handler_; + + DISALLOW_COPY_AND_ASSIGN(Wifi); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_H_ diff --git a/wifi/1.6/default/wifi_ap_iface.cpp b/wifi/aidl/default/wifi_ap_iface.cpp similarity index 59% rename from wifi/1.6/default/wifi_ap_iface.cpp rename to wifi/aidl/default/wifi_ap_iface.cpp index b2957db13f..6cd932df41 100644 --- a/wifi/1.6/default/wifi_ap_iface.cpp +++ b/wifi/aidl/default/wifi_ap_iface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,19 +14,19 @@ * limitations under the License. */ +#include "wifi_ap_iface.h" + #include -#include "hidl_return_util.h" -#include "hidl_struct_util.h" -#include "wifi_ap_iface.h" +#include "aidl_return_util.h" +#include "aidl_struct_util.h" #include "wifi_status_util.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; +using aidl_return_util::validateAndCall; WifiApIface::WifiApIface(const std::string& ifname, const std::vector& instances, const std::weak_ptr legacy_hal, @@ -54,76 +54,66 @@ void WifiApIface::removeInstance(std::string instance) { instances_.erase(std::remove(instances_.begin(), instances_.end(), instance), instances_.end()); } -Return WifiApIface::getName(getName_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::getName(std::string* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::getNameInternal, hidl_status_cb); + &WifiApIface::getNameInternal, _aidl_return); } -Return WifiApIface::getType(getType_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::setCountryCode(const std::array& in_code) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::getTypeInternal, hidl_status_cb); + &WifiApIface::setCountryCodeInternal, in_code); } -Return WifiApIface::setCountryCode(const hidl_array& code, - setCountryCode_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::getValidFrequenciesForBand(WifiBand in_band, + std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::setCountryCodeInternal, hidl_status_cb, code); + &WifiApIface::getValidFrequenciesForBandInternal, _aidl_return, in_band); } -Return WifiApIface::getValidFrequenciesForBand(V1_0::WifiBand band, - getValidFrequenciesForBand_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::setMacAddress(const std::array& in_mac) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::getValidFrequenciesForBandInternal, hidl_status_cb, band); + &WifiApIface::setMacAddressInternal, in_mac); } -Return WifiApIface::setMacAddress(const hidl_array& mac, - setMacAddress_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::getFactoryMacAddress(std::array* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::setMacAddressInternal, hidl_status_cb, mac); -} - -Return WifiApIface::getFactoryMacAddress(getFactoryMacAddress_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::getFactoryMacAddressInternal, hidl_status_cb, + &WifiApIface::getFactoryMacAddressInternal, _aidl_return, instances_.size() > 0 ? instances_[0] : ifname_); } -Return WifiApIface::resetToFactoryMacAddress(resetToFactoryMacAddress_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::resetToFactoryMacAddress() { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::resetToFactoryMacAddressInternal, hidl_status_cb); + &WifiApIface::resetToFactoryMacAddressInternal); } -Return WifiApIface::getBridgedInstances(getBridgedInstances_cb hidl_status_cb) { +ndk::ScopedAStatus WifiApIface::getBridgedInstances(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiApIface::getBridgedInstancesInternal, hidl_status_cb); + &WifiApIface::getBridgedInstancesInternal, _aidl_return); } -std::pair WifiApIface::getNameInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; +std::pair WifiApIface::getNameInternal() { + return {ifname_, ndk::ScopedAStatus::ok()}; } -std::pair WifiApIface::getTypeInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP}; -} - -WifiStatus WifiApIface::setCountryCodeInternal(const std::array& code) { +ndk::ScopedAStatus WifiApIface::setCountryCodeInternal(const std::array& code) { legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setCountryCode( instances_.size() > 0 ? instances_[0] : ifname_, code); return createWifiStatusFromLegacyError(legacy_status); } -std::pair> -WifiApIface::getValidFrequenciesForBandInternal(V1_0::WifiBand band) { - static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); +std::pair, ndk::ScopedAStatus> WifiApIface::getValidFrequenciesForBandInternal( + WifiBand band) { + static_assert(sizeof(WifiChannelWidthInMhz) == sizeof(int32_t), "Size mismatch"); legacy_hal::wifi_error legacy_status; std::vector valid_frequencies; std::tie(legacy_status, valid_frequencies) = legacy_hal_.lock()->getValidFrequenciesForBand( instances_.size() > 0 ? instances_[0] : ifname_, - hidl_struct_util::convertHidlWifiBandToLegacy(band)); - return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; + aidl_struct_util::convertAidlWifiBandToLegacy(band)); + return {std::vector(valid_frequencies.begin(), valid_frequencies.end()), + createWifiStatusFromLegacyError(legacy_status)}; } -WifiStatus WifiApIface::setMacAddressInternal(const std::array& mac) { +ndk::ScopedAStatus WifiApIface::setMacAddressInternal(const std::array& mac) { // Support random MAC up to 2 interfaces if (instances_.size() == 2) { int rbyte = 1; @@ -145,35 +135,35 @@ WifiStatus WifiApIface::setMacAddressInternal(const std::array& mac) LOG(ERROR) << "Fail to config MAC for interface " << ifname_; return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiApIface::getFactoryMacAddressInternal( +std::pair, ndk::ScopedAStatus> WifiApIface::getFactoryMacAddressInternal( const std::string& ifaceName) { std::array mac = iface_util_.lock()->getFactoryMacAddress(ifaceName); if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), mac}; + return {mac, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), mac}; + return {mac, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiApIface::resetToFactoryMacAddressInternal() { - std::pair> getMacResult; +ndk::ScopedAStatus WifiApIface::resetToFactoryMacAddressInternal() { + std::pair, ndk::ScopedAStatus> getMacResult; if (instances_.size() == 2) { for (auto const& intf : instances_) { getMacResult = getFactoryMacAddressInternal(intf); LOG(DEBUG) << "Reset MAC to factory MAC on " << intf; - if (getMacResult.first.code != WifiStatusCode::SUCCESS || - !iface_util_.lock()->setMacAddress(intf, getMacResult.second)) { + if (!getMacResult.second.isOk() || + !iface_util_.lock()->setMacAddress(intf, getMacResult.first)) { return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } } - // It needs to set mac address for bridged interface, otherwise the mac + // We need to set mac address for bridged interface, otherwise the mac // address of the bridged interface will be changed after one of the - // instance down. Thus we are generating a random MAC address for the - // bridged interface even if we got the request to reset the Factory - // MAC. Since the bridged interface is an internal interface for the - // operation of bpf and others networking operation. + // instances goes down. Thus we are generating a random MAC address for + // the bridged interface even if we got the request to reset the Factory + // MAC. This is because the bridged interface is an internal interface + // for the operation of bpf and other networking operations. if (!iface_util_.lock()->setMacAddress(ifname_, iface_util_.lock()->createRandomMacAddress())) { LOG(ERROR) << "Fail to config MAC for bridged interface " << ifname_; @@ -182,23 +172,19 @@ WifiStatus WifiApIface::resetToFactoryMacAddressInternal() { } else { getMacResult = getFactoryMacAddressInternal(ifname_); LOG(DEBUG) << "Reset MAC to factory MAC on " << ifname_; - if (getMacResult.first.code != WifiStatusCode::SUCCESS || - !iface_util_.lock()->setMacAddress(ifname_, getMacResult.second)) { + if (!getMacResult.second.isOk() || + !iface_util_.lock()->setMacAddress(ifname_, getMacResult.first)) { return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiApIface::getBridgedInstancesInternal() { - std::vector instances; - for (const auto& instance_name : instances_) { - instances.push_back(instance_name); - } - return {createWifiStatus(WifiStatusCode::SUCCESS), instances}; +std::pair, ndk::ScopedAStatus> WifiApIface::getBridgedInstancesInternal() { + return {instances_, ndk::ScopedAStatus::ok()}; } -} // namespace implementation -} // namespace V1_6 + } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi_ap_iface.h b/wifi/aidl/default/wifi_ap_iface.h new file mode 100644 index 0000000000..b5673fcaac --- /dev/null +++ b/wifi/aidl/default/wifi_ap_iface.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_AP_IFACE_H_ +#define WIFI_AP_IFACE_H_ + +#include +#include + +#include "wifi_iface_util.h" +#include "wifi_legacy_hal.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * AIDL interface object used to control an AP Iface instance. + */ +class WifiApIface : public BnWifiApIface { + public: + WifiApIface(const std::string& ifname, const std::vector& instances, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util); + // Refer to |WifiChip::invalidate()|. + void invalidate(); + bool isValid(); + std::string getName(); + void removeInstance(std::string instance); + + // AIDL methods exposed. + ndk::ScopedAStatus getName(std::string* _aidl_return) override; + ndk::ScopedAStatus setCountryCode(const std::array& in_code) override; + ndk::ScopedAStatus getValidFrequenciesForBand(WifiBand in_band, + std::vector* _aidl_return) override; + ndk::ScopedAStatus setMacAddress(const std::array& in_mac) override; + ndk::ScopedAStatus getFactoryMacAddress(std::array* _aidl_return) override; + ndk::ScopedAStatus resetToFactoryMacAddress() override; + ndk::ScopedAStatus getBridgedInstances(std::vector* _aidl_return) override; + + private: + // Corresponding worker functions for the AIDL methods. + std::pair getNameInternal(); + ndk::ScopedAStatus setCountryCodeInternal(const std::array& code); + std::pair, ndk::ScopedAStatus> getValidFrequenciesForBandInternal( + WifiBand band); + ndk::ScopedAStatus setMacAddressInternal(const std::array& mac); + std::pair, ndk::ScopedAStatus> getFactoryMacAddressInternal( + const std::string& ifaceName); + ndk::ScopedAStatus resetToFactoryMacAddressInternal(); + std::pair, ndk::ScopedAStatus> getBridgedInstancesInternal(); + + std::string ifname_; + std::vector instances_; + std::weak_ptr legacy_hal_; + std::weak_ptr iface_util_; + bool is_valid_; + + DISALLOW_COPY_AND_ASSIGN(WifiApIface); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_AP_IFACE_H_ diff --git a/wifi/1.6/default/wifi_chip.cpp b/wifi/aidl/default/wifi_chip.cpp similarity index 64% rename from wifi/1.6/default/wifi_chip.cpp rename to wifi/aidl/default/wifi_chip.cpp index 920beb8778..076f351448 100644 --- a/wifi/1.6/default/wifi_chip.cpp +++ b/wifi/aidl/default/wifi_chip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,30 +14,27 @@ * limitations under the License. */ -#include +#include "wifi_chip.h" #include #include #include +#include #include #include #include -#include "hidl_return_util.h" -#include "hidl_struct_util.h" -#include "wifi_chip.h" +#include "aidl_return_util.h" +#include "aidl_struct_util.h" #include "wifi_status_util.h" #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" namespace { -using android::sp; +using aidl::android::hardware::wifi::IfaceType; +using aidl::android::hardware::wifi::IWifiChip; +using CoexRestriction = aidl::android::hardware::wifi::IWifiChip::CoexRestriction; using android::base::unique_fd; -using android::hardware::hidl_string; -using android::hardware::hidl_vec; -using android::hardware::wifi::V1_0::ChipModeId; -using android::hardware::wifi::V1_0::IfaceType; -using android::hardware::wifi::V1_0::IWifiChip; constexpr char kCpioMagic[] = "070701"; constexpr size_t kMaxBufferSizeBytes = 1024 * 1024 * 3; @@ -50,13 +47,13 @@ constexpr unsigned kMaxWlanIfaces = 5; constexpr char kApBridgeIfacePrefix[] = "ap_br_"; template -void invalidateAndClear(std::vector>& ifaces, sp iface) { +void invalidateAndClear(std::vector>& ifaces, std::shared_ptr iface) { iface->invalidate(); ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), ifaces.end()); } template -void invalidateAndClearAll(std::vector>& ifaces) { +void invalidateAndClearAll(std::vector>& ifaces) { for (const auto& iface : ifaces) { iface->invalidate(); } @@ -64,8 +61,8 @@ void invalidateAndClearAll(std::vector>& ifaces) { } template -std::vector getNames(std::vector>& ifaces) { - std::vector names; +std::vector getNames(std::vector>& ifaces) { + std::vector names; for (const auto& iface : ifaces) { names.emplace_back(iface->getName()); } @@ -73,8 +70,9 @@ std::vector getNames(std::vector>& ifaces) { } template -sp findUsingName(std::vector>& ifaces, const std::string& name) { - std::vector names; +std::shared_ptr findUsingName(std::vector>& ifaces, + const std::string& name) { + std::vector names; for (const auto& iface : ifaces) { if (name == iface->getName()) { return iface; @@ -169,8 +167,8 @@ void setActiveWlanIfaceNameProperty(const std::string& ifname) { } } -// delete files that meet either conditions: -// 1. older than a predefined time in the wifi tombstone dir. +// Delete files that meet either condition: +// 1. Older than a predefined time in the wifi tombstone dir. // 2. Files in excess to a predefined amount, starting from the oldest ones bool removeOldFilesInternal() { time_t now = time(0); @@ -354,15 +352,14 @@ std::vector makeCharVec(const std::string& str) { } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; -using hidl_return_util::validateAndCallWithLock; +using aidl_return_util::validateAndCall; +using aidl_return_util::validateAndCallWithLock; -WifiChip::WifiChip(ChipId chip_id, bool is_primary, +WifiChip::WifiChip(int32_t chip_id, bool is_primary, const std::weak_ptr legacy_hal, const std::weak_ptr mode_controller, const std::shared_ptr iface_util, @@ -380,6 +377,19 @@ WifiChip::WifiChip(ChipId chip_id, bool is_primary, setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue); } +std::shared_ptr WifiChip::create( + int32_t chip_id, bool is_primary, const std::weak_ptr legacy_hal, + const std::weak_ptr mode_controller, + const std::shared_ptr iface_util, + const std::weak_ptr feature_flags, + const std::function& handler) { + std::shared_ptr ptr = ndk::SharedRefBase::make( + chip_id, is_primary, legacy_hal, mode_controller, iface_util, feature_flags, handler); + std::weak_ptr weak_ptr_this(ptr); + ptr->setWeakPtr(weak_ptr_this); + return ptr; +} + void WifiChip::invalidate() { if (!writeRingbufferFilesInternal()) { LOG(ERROR) << "Error writing files to flash"; @@ -391,348 +401,283 @@ void WifiChip::invalidate() { is_valid_ = false; } +void WifiChip::setWeakPtr(std::weak_ptr ptr) { + weak_ptr_this_ = ptr; +} + bool WifiChip::isValid() { return is_valid_; } -std::set> WifiChip::getEventCallbacks() { +std::set> WifiChip::getEventCallbacks() { return event_cb_handler_.getCallbacks(); } -Return WifiChip::getId(getId_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getId(int32_t* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, &WifiChip::getIdInternal, - hidl_status_cb); + _aidl_return); } -// Deprecated support for this callback -Return WifiChip::registerEventCallback(const sp& event_callback, - registerEventCallback_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::registerEventCallback( + const std::shared_ptr& event_callback) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::registerEventCallbackInternal, hidl_status_cb, - event_callback); + &WifiChip::registerEventCallbackInternal, event_callback); } -Return WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getCapabilities(IWifiChip::ChipCapabilityMask* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getCapabilitiesInternal, hidl_status_cb); + &WifiChip::getCapabilitiesInternal, _aidl_return); } -Return WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getAvailableModes(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getAvailableModesInternal, hidl_status_cb); + &WifiChip::getAvailableModesInternal, _aidl_return); } -Return WifiChip::configureChip(ChipModeId mode_id, configureChip_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::configureChip(int32_t in_modeId) { return validateAndCallWithLock(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::configureChipInternal, hidl_status_cb, mode_id); + &WifiChip::configureChipInternal, in_modeId); } -Return WifiChip::getMode(getMode_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getMode(int32_t* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getModeInternal, hidl_status_cb); + &WifiChip::getModeInternal, _aidl_return); } -Return WifiChip::requestChipDebugInfo(requestChipDebugInfo_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::requestChipDebugInfo(IWifiChip::ChipDebugInfo* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::requestChipDebugInfoInternal, hidl_status_cb); + &WifiChip::requestChipDebugInfoInternal, _aidl_return); } -Return WifiChip::requestDriverDebugDump(requestDriverDebugDump_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::requestDriverDebugDump(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::requestDriverDebugDumpInternal, hidl_status_cb); + &WifiChip::requestDriverDebugDumpInternal, _aidl_return); } -Return WifiChip::requestFirmwareDebugDump(requestFirmwareDebugDump_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::requestFirmwareDebugDump(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::requestFirmwareDebugDumpInternal, hidl_status_cb); + &WifiChip::requestFirmwareDebugDumpInternal, _aidl_return); } -Return WifiChip::createApIface(createApIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createApIface(std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createApIfaceInternal, hidl_status_cb); + &WifiChip::createApIfaceInternal, _aidl_return); } -Return WifiChip::createBridgedApIface(createBridgedApIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createBridgedApIface(std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createBridgedApIfaceInternal, hidl_status_cb); + &WifiChip::createBridgedApIfaceInternal, _aidl_return); } -Return WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getApIfaceNames(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getApIfaceNamesInternal, hidl_status_cb); + &WifiChip::getApIfaceNamesInternal, _aidl_return); } -Return WifiChip::getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getApIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getApIfaceInternal, hidl_status_cb, ifname); + &WifiChip::getApIfaceInternal, _aidl_return, in_ifname); } -Return WifiChip::removeApIface(const hidl_string& ifname, removeApIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::removeApIface(const std::string& in_ifname) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::removeApIfaceInternal, hidl_status_cb, ifname); + &WifiChip::removeApIfaceInternal, in_ifname); } -Return WifiChip::removeIfaceInstanceFromBridgedApIface( - const hidl_string& ifname, const hidl_string& ifInstanceName, - removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::removeIfaceInstanceFromBridgedApIface( + const std::string& in_brIfaceName, const std::string& in_ifaceInstanceName) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal, hidl_status_cb, - ifname, ifInstanceName); + &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal, in_brIfaceName, + in_ifaceInstanceName); } -Return WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createNanIface(std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createNanIfaceInternal, hidl_status_cb); + &WifiChip::createNanIfaceInternal, _aidl_return); } -Return WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getNanIfaceNames(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getNanIfaceNamesInternal, hidl_status_cb); + &WifiChip::getNanIfaceNamesInternal, _aidl_return); } -Return WifiChip::getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getNanIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getNanIfaceInternal, hidl_status_cb, ifname); + &WifiChip::getNanIfaceInternal, _aidl_return, in_ifname); } -Return WifiChip::removeNanIface(const hidl_string& ifname, removeNanIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::removeNanIface(const std::string& in_ifname) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::removeNanIfaceInternal, hidl_status_cb, ifname); + &WifiChip::removeNanIfaceInternal, in_ifname); } -Return WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createP2pIface(std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createP2pIfaceInternal, hidl_status_cb); + &WifiChip::createP2pIfaceInternal, _aidl_return); } -Return WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getP2pIfaceNames(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb); + &WifiChip::getP2pIfaceNamesInternal, _aidl_return); } -Return WifiChip::getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getP2pIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getP2pIfaceInternal, hidl_status_cb, ifname); + &WifiChip::getP2pIfaceInternal, _aidl_return, in_ifname); } -Return WifiChip::removeP2pIface(const hidl_string& ifname, removeP2pIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::removeP2pIface(const std::string& in_ifname) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::removeP2pIfaceInternal, hidl_status_cb, ifname); + &WifiChip::removeP2pIfaceInternal, in_ifname); } -Return WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createStaIface(std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createStaIfaceInternal, hidl_status_cb); + &WifiChip::createStaIfaceInternal, _aidl_return); } -Return WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getStaIfaceNames(std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getStaIfaceNamesInternal, hidl_status_cb); + &WifiChip::getStaIfaceNamesInternal, _aidl_return); } -Return WifiChip::getStaIface(const hidl_string& ifname, getStaIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getStaIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getStaIfaceInternal, hidl_status_cb, ifname); + &WifiChip::getStaIfaceInternal, _aidl_return, in_ifname); } -Return WifiChip::removeStaIface(const hidl_string& ifname, removeStaIface_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::removeStaIface(const std::string& in_ifname) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::removeStaIfaceInternal, hidl_status_cb, ifname); + &WifiChip::removeStaIfaceInternal, in_ifname); } -Return WifiChip::createRttController(const sp& bound_iface, - createRttController_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::createRttController( + const std::shared_ptr& in_boundIface, + std::shared_ptr* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createRttControllerInternal, hidl_status_cb, bound_iface); + &WifiChip::createRttControllerInternal, _aidl_return, in_boundIface); } -Return WifiChip::getDebugRingBuffersStatus(getDebugRingBuffersStatus_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getDebugRingBuffersStatus( + std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getDebugRingBuffersStatusInternal, hidl_status_cb); + &WifiChip::getDebugRingBuffersStatusInternal, _aidl_return); } -Return WifiChip::startLoggingToDebugRingBuffer( - const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, - uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes, - startLoggingToDebugRingBuffer_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::startLoggingToDebugRingBuffer( + const std::string& in_ringName, WifiDebugRingBufferVerboseLevel in_verboseLevel, + int32_t in_maxIntervalInSec, int32_t in_minDataSizeInBytes) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::startLoggingToDebugRingBufferInternal, hidl_status_cb, - ring_name, verbose_level, max_interval_in_sec, min_data_size_in_bytes); + &WifiChip::startLoggingToDebugRingBufferInternal, in_ringName, + in_verboseLevel, in_maxIntervalInSec, in_minDataSizeInBytes); } -Return WifiChip::forceDumpToDebugRingBuffer(const hidl_string& ring_name, - forceDumpToDebugRingBuffer_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::forceDumpToDebugRingBuffer(const std::string& in_ringName) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::forceDumpToDebugRingBufferInternal, hidl_status_cb, - ring_name); + &WifiChip::forceDumpToDebugRingBufferInternal, in_ringName); } -Return WifiChip::flushRingBufferToFile(flushRingBufferToFile_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::flushRingBufferToFile() { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::flushRingBufferToFileInternal, hidl_status_cb); + &WifiChip::flushRingBufferToFileInternal); } -Return WifiChip::stopLoggingToDebugRingBuffer( - stopLoggingToDebugRingBuffer_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::stopLoggingToDebugRingBuffer() { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::stopLoggingToDebugRingBufferInternal, hidl_status_cb); + &WifiChip::stopLoggingToDebugRingBufferInternal); } -Return WifiChip::getDebugHostWakeReasonStats(getDebugHostWakeReasonStats_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getDebugHostWakeReasonStats( + WifiDebugHostWakeReasonStats* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getDebugHostWakeReasonStatsInternal, hidl_status_cb); + &WifiChip::getDebugHostWakeReasonStatsInternal, _aidl_return); } -Return WifiChip::enableDebugErrorAlerts(bool enable, - enableDebugErrorAlerts_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::enableDebugErrorAlerts(bool in_enable) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::enableDebugErrorAlertsInternal, hidl_status_cb, enable); + &WifiChip::enableDebugErrorAlertsInternal, in_enable); } -Return WifiChip::selectTxPowerScenario(V1_1::IWifiChip::TxPowerScenario scenario, - selectTxPowerScenario_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::selectTxPowerScenario(IWifiChip::TxPowerScenario in_scenario) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::selectTxPowerScenarioInternal, hidl_status_cb, scenario); + &WifiChip::selectTxPowerScenarioInternal, in_scenario); } -Return WifiChip::resetTxPowerScenario(resetTxPowerScenario_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::resetTxPowerScenario() { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::resetTxPowerScenarioInternal, hidl_status_cb); + &WifiChip::resetTxPowerScenarioInternal); } -Return WifiChip::setLatencyMode(LatencyMode mode, setLatencyMode_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::setLatencyMode(IWifiChip::LatencyMode in_mode) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::setLatencyModeInternal, hidl_status_cb, mode); + &WifiChip::setLatencyModeInternal, in_mode); } -Return WifiChip::registerEventCallback_1_2( - const sp& event_callback, - registerEventCallback_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::registerEventCallbackInternal_1_2, hidl_status_cb, - event_callback); -} - -Return WifiChip::selectTxPowerScenario_1_2(TxPowerScenario scenario, - selectTxPowerScenario_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::selectTxPowerScenarioInternal_1_2, hidl_status_cb, scenario); -} - -Return WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getCapabilitiesInternal_1_3, hidl_status_cb); -} - -Return WifiChip::getCapabilities_1_5(getCapabilities_1_5_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getCapabilitiesInternal_1_5, hidl_status_cb); -} - -Return WifiChip::debug(const hidl_handle& handle, const hidl_vec&) { - if (handle != nullptr && handle->numFds >= 1) { - { - std::unique_lock lk(lock_t); - for (const auto& item : ringbuffer_map_) { - forceDumpToDebugRingBufferInternal(item.first); - } - // unique_lock unlocked here +binder_status_t WifiChip::dump(int fd, const char**, uint32_t) { + { + std::unique_lock lk(lock_t); + for (const auto& item : ringbuffer_map_) { + forceDumpToDebugRingBufferInternal(item.first); } - usleep(100 * 1000); // sleep for 100 milliseconds to wait for - // ringbuffer updates. - int fd = handle->data[0]; - if (!writeRingbufferFilesInternal()) { - LOG(ERROR) << "Error writing files to flash"; - } - uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath); - if (n_error != 0) { - LOG(ERROR) << n_error << " errors occured in cpio function"; - } - fsync(fd); - } else { - LOG(ERROR) << "File handle error"; + // unique_lock unlocked here } - return Void(); + usleep(100 * 1000); // sleep for 100 milliseconds to wait for + // ringbuffer updates. + if (!writeRingbufferFilesInternal()) { + LOG(ERROR) << "Error writing files to flash"; + } + uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath); + if (n_error != 0) { + LOG(ERROR) << n_error << " errors occurred in cpio function"; + } + fsync(fd); + return STATUS_OK; } -Return WifiChip::createRttController_1_4(const sp& bound_iface, - createRttController_1_4_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::setMultiStaPrimaryConnection(const std::string& in_ifName) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createRttControllerInternal_1_4, hidl_status_cb, bound_iface); + &WifiChip::setMultiStaPrimaryConnectionInternal, in_ifName); } -Return WifiChip::registerEventCallback_1_4( - const sp& event_callback, - registerEventCallback_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::setMultiStaUseCase(IWifiChip::MultiStaUseCase in_useCase) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::registerEventCallbackInternal_1_4, hidl_status_cb, - event_callback); + &WifiChip::setMultiStaUseCaseInternal, in_useCase); } -Return WifiChip::setMultiStaPrimaryConnection( - const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::setCoexUnsafeChannels( + const std::vector& in_unsafeChannels, + CoexRestriction in_restrictions) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::setMultiStaPrimaryConnectionInternal, hidl_status_cb, ifname); + &WifiChip::setCoexUnsafeChannelsInternal, in_unsafeChannels, + in_restrictions); } -Return WifiChip::setMultiStaUseCase(MultiStaUseCase use_case, - setMultiStaUseCase_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::setMultiStaUseCaseInternal, hidl_status_cb, use_case); -} - -Return WifiChip::setCoexUnsafeChannels(const hidl_vec& unsafeChannels, - hidl_bitfield restrictions, - setCoexUnsafeChannels_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::setCoexUnsafeChannelsInternal, hidl_status_cb, unsafeChannels, - restrictions); -} - -Return WifiChip::setCountryCode(const hidl_array& code, - setCountryCode_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::setCountryCode(const std::array& in_code) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiChip::setCountryCodeInternal, hidl_status_cb, code); + &WifiChip::setCountryCodeInternal, in_code); } -Return WifiChip::getUsableChannels( - WifiBand band, hidl_bitfield ifaceModeMask, - hidl_bitfield filterMask, - getUsableChannels_cb _hidl_cb) { +ndk::ScopedAStatus WifiChip::getUsableChannels(WifiBand in_band, WifiIfaceMode in_ifaceModeMask, + UsableChannelFilter in_filterMask, + std::vector* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getUsableChannelsInternal, _hidl_cb, band, ifaceModeMask, - filterMask); + &WifiChip::getUsableChannelsInternal, _aidl_return, in_band, + in_ifaceModeMask, in_filterMask); } -Return WifiChip::triggerSubsystemRestart(triggerSubsystemRestart_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::triggerSubsystemRestart() { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::triggerSubsystemRestartInternal, hidl_status_cb); + &WifiChip::triggerSubsystemRestartInternal); } -Return WifiChip::createRttController_1_6(const sp& bound_iface, - createRttController_1_6_cb hidl_status_cb) { +ndk::ScopedAStatus WifiChip::getSupportedRadioCombinationsMatrix( + WifiRadioCombinationMatrix* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::createRttControllerInternal_1_6, hidl_status_cb, bound_iface); -} - -Return WifiChip::getUsableChannels_1_6( - WifiBand band, hidl_bitfield ifaceModeMask, - hidl_bitfield filterMask, - getUsableChannels_1_6_cb _hidl_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getUsableChannelsInternal_1_6, _hidl_cb, band, ifaceModeMask, - filterMask); -} - -Return WifiChip::getSupportedRadioCombinationsMatrix( - getSupportedRadioCombinationsMatrix_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getSupportedRadioCombinationsMatrixInternal, hidl_status_cb); -} - -Return WifiChip::getAvailableModes_1_6(getAvailableModes_1_6_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, - &WifiChip::getAvailableModesInternal_1_6, hidl_status_cb); + &WifiChip::getSupportedRadioCombinationsMatrixInternal, _aidl_return); } void WifiChip::invalidateAndRemoveAllIfaces() { @@ -755,7 +700,7 @@ void WifiChip::invalidateAndRemoveDependencies(const std::string& removed_iface_ if (nan_iface->getName() == removed_iface_name) { nan_iface->invalidate(); for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onIfaceRemoved(IfaceType::NAN, removed_iface_name).isOk()) { + if (!callback->onIfaceRemoved(IfaceType::NAN_IFACE, removed_iface_name).isOk()) { LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; } } @@ -776,89 +721,61 @@ void WifiChip::invalidateAndRemoveDependencies(const std::string& removed_iface_ } } -std::pair WifiChip::getIdInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; +std::pair WifiChip::getIdInternal() { + return {chip_id_, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::registerEventCallbackInternal( - const sp& /* event_callback */) { - // Deprecated support for this callback. - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -std::pair WifiChip::getCapabilitiesInternal() { - // Deprecated support for this callback. - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; -} - -std::pair> -WifiChip::getAvailableModesInternal() { - // Deprecated support -- use getAvailableModes_1_6 for more granular concurrency combinations. - std::vector modes_1_0 = {}; - for (const auto& mode_1_6 : modes_) { - std::vector combos_1_0; - for (const auto& combo_1_6 : mode_1_6.availableCombinations) { - std::vector limits_1_0; - for (const auto& limit_1_6 : combo_1_6.limits) { - std::vector types_1_0; - for (IfaceConcurrencyType type_1_6 : limit_1_6.types) { - switch (type_1_6) { - case IfaceConcurrencyType::STA: - types_1_0.push_back(IfaceType::STA); - break; - case IfaceConcurrencyType::AP: - types_1_0.push_back(IfaceType::AP); - break; - case IfaceConcurrencyType::AP_BRIDGED: - // Ignore AP_BRIDGED - break; - case IfaceConcurrencyType::P2P: - types_1_0.push_back(IfaceType::P2P); - break; - case IfaceConcurrencyType::NAN: - types_1_0.push_back(IfaceType::NAN); - break; - } - } - if (types_1_0.empty()) { - continue; - } - V1_0::IWifiChip::ChipIfaceCombinationLimit limit_1_0; - limit_1_0.types = hidl_vec(types_1_0); - limit_1_0.maxIfaces = limit_1_6.maxIfaces; - limits_1_0.push_back(limit_1_0); - } - if (limits_1_0.empty()) { - continue; - } - V1_0::IWifiChip::ChipIfaceCombination combo_1_0; - combo_1_0.limits = hidl_vec(limits_1_0); - combos_1_0.push_back(combo_1_0); - } - if (combos_1_0.empty()) { - continue; - } - V1_0::IWifiChip::ChipMode mode_1_0; - mode_1_0.id = mode_1_6.id; - mode_1_0.availableCombinations = hidl_vec(combos_1_0); - modes_1_0.push_back(mode_1_0); +ndk::ScopedAStatus WifiChip::registerEventCallbackInternal( + const std::shared_ptr& event_callback) { + if (!event_cb_handler_.addCallback(event_callback)) { + return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } - return {createWifiStatus(WifiStatusCode::SUCCESS), modes_1_0}; + return ndk::ScopedAStatus::ok(); } -WifiStatus WifiChip::configureChipInternal( - /* NONNULL */ std::unique_lock* lock, ChipModeId mode_id) { +std::pair WifiChip::getCapabilitiesInternal() { + legacy_hal::wifi_error legacy_status; + uint64_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 {IWifiChip::ChipCapabilityMask{}, createWifiStatusFromLegacyError(legacy_status)}; + } + 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 aidl_caps; + if (!aidl_struct_util::convertLegacyFeaturesToAidlChipCapabilities( + legacy_feature_set, legacy_logger_feature_set, &aidl_caps)) { + return {IWifiChip::ChipCapabilityMask{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {static_cast(aidl_caps), ndk::ScopedAStatus::ok()}; +} + +std::pair, ndk::ScopedAStatus> +WifiChip::getAvailableModesInternal() { + return {modes_, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiChip::configureChipInternal( + /* NONNULL */ std::unique_lock* lock, int32_t mode_id) { if (!isValidModeId(mode_id)) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); } if (mode_id == current_mode_id_) { LOG(DEBUG) << "Already in the specified mode " << mode_id; - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } - WifiStatus status = handleChipConfiguration(lock, mode_id); - if (status.code != WifiStatusCode::SUCCESS) { + ndk::ScopedAStatus status = handleChipConfiguration(lock, mode_id); + if (!status.isOk()) { + WifiStatusCode errorCode = static_cast(status.getServiceSpecificError()); for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onChipReconfigureFailure(status).isOk()) { + if (!callback->onChipReconfigureFailure(errorCode).isOk()) { LOG(ERROR) << "Failed to invoke onChipReconfigureFailure callback"; } } @@ -878,24 +795,24 @@ WifiStatus WifiChip::configureChipInternal( return status; } -std::pair WifiChip::getModeInternal() { +std::pair WifiChip::getModeInternal() { if (!isValidModeId(current_mode_id_)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), current_mode_id_}; + return {current_mode_id_, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; + return {current_mode_id_, ndk::ScopedAStatus::ok()}; } -std::pair WifiChip::requestChipDebugInfoInternal() { - V1_4::IWifiChip::ChipDebugInfo result; +std::pair WifiChip::requestChipDebugInfoInternal() { + IWifiChip::ChipDebugInfo result; legacy_hal::wifi_error legacy_status; std::string driver_desc; const auto ifname = getFirstActiveWlanIfaceName(); std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(ifname); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get driver version: " << legacyErrorToString(legacy_status); - WifiStatus status = + ndk::ScopedAStatus status = createWifiStatusFromLegacyError(legacy_status, "failed to get driver version"); - return {status, result}; + return {std::move(result), std::move(status)}; } result.driverDescription = driver_desc.c_str(); @@ -903,59 +820,60 @@ std::pair WifiChip::requestChipDebug std::tie(legacy_status, firmware_desc) = legacy_hal_.lock()->getFirmwareVersion(ifname); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get firmware version: " << legacyErrorToString(legacy_status); - WifiStatus status = + ndk::ScopedAStatus status = createWifiStatusFromLegacyError(legacy_status, "failed to get firmware version"); - return {status, result}; + return {std::move(result), std::move(status)}; } result.firmwareDescription = firmware_desc.c_str(); - return {createWifiStatus(WifiStatusCode::SUCCESS), result}; + return {std::move(result), ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::requestDriverDebugDumpInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::requestDriverDebugDumpInternal() { legacy_hal::wifi_error legacy_status; std::vector driver_dump; std::tie(legacy_status, driver_dump) = legacy_hal_.lock()->requestDriverMemoryDump(getFirstActiveWlanIfaceName()); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get driver debug dump: " << legacyErrorToString(legacy_status); - return {createWifiStatusFromLegacyError(legacy_status), std::vector()}; + return {std::vector(), createWifiStatusFromLegacyError(legacy_status)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; + return {driver_dump, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::requestFirmwareDebugDumpInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::requestFirmwareDebugDumpInternal() { legacy_hal::wifi_error legacy_status; std::vector firmware_dump; std::tie(legacy_status, firmware_dump) = legacy_hal_.lock()->requestFirmwareMemoryDump(getFirstActiveWlanIfaceName()); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get firmware debug dump: " << legacyErrorToString(legacy_status); - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {std::vector(), createWifiStatusFromLegacyError(legacy_status)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; + return {firmware_dump, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) { +ndk::ScopedAStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) { legacy_hal::wifi_error legacy_status; legacy_status = legacy_hal_.lock()->createVirtualInterface( - apVirtIf, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::AP)); + apVirtIf, aidl_struct_util::convertAidlIfaceTypeToLegacy(IfaceType::AP)); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to add interface: " << apVirtIf << " " << legacyErrorToString(legacy_status); return createWifiStatusFromLegacyError(legacy_status); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -sp WifiChip::newWifiApIface(std::string& ifname) { +std::shared_ptr WifiChip::newWifiApIface(std::string& ifname) { std::vector ap_instances; for (auto const& it : br_ifaces_ap_instances_) { if (it.first == ifname) { ap_instances = it.second; } } - sp iface = new WifiApIface(ifname, ap_instances, legacy_hal_, iface_util_); + std::shared_ptr iface = + ndk::SharedRefBase::make(ifname, ap_instances, legacy_hal_, iface_util_); ap_ifaces_.push_back(iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { @@ -966,75 +884,77 @@ sp WifiChip::newWifiApIface(std::string& ifname) { return iface; } -std::pair> WifiChip::createApIfaceInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::createApIfaceInternal() { if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + return {std::shared_ptr(), + createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } std::string ifname = allocateApIfaceName(); - WifiStatus status = createVirtualApInterface(ifname); - if (status.code != WifiStatusCode::SUCCESS) { - return {status, {}}; + ndk::ScopedAStatus status = createVirtualApInterface(ifname); + if (!status.isOk()) { + return {std::shared_ptr(), std::move(status)}; } - sp iface = newWifiApIface(ifname); - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + std::shared_ptr iface = newWifiApIface(ifname); + return {iface, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::createBridgedApIfaceInternal() { +std::pair, ndk::ScopedAStatus> +WifiChip::createBridgedApIfaceInternal() { if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP_BRIDGED)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } std::vector ap_instances = allocateBridgedApInstanceNames(); if (ap_instances.size() < 2) { LOG(ERROR) << "Fail to allocate two instances"; - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } std::string br_ifname = kApBridgeIfacePrefix + ap_instances[0]; for (int i = 0; i < 2; i++) { - WifiStatus status = createVirtualApInterface(ap_instances[i]); - if (status.code != WifiStatusCode::SUCCESS) { + ndk::ScopedAStatus status = createVirtualApInterface(ap_instances[i]); + if (!status.isOk()) { if (i != 0) { // The failure happened when creating second virtual // iface. legacy_hal_.lock()->deleteVirtualInterface( ap_instances.front()); // Remove the first virtual iface. } - return {status, {}}; + return {nullptr, std::move(status)}; } } br_ifaces_ap_instances_[br_ifname] = ap_instances; if (!iface_util_->createBridge(br_ifname)) { LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str(); - deleteApIface(br_ifname); - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + invalidateAndClearBridgedAp(br_ifname); + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } for (auto const& instance : ap_instances) { // Bind ap instance interface to AP bridge if (!iface_util_->addIfaceToBridge(br_ifname, instance)) { LOG(ERROR) << "Failed add if to Bridge - if_name=" << instance.c_str(); - deleteApIface(br_ifname); - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + invalidateAndClearBridgedAp(br_ifname); + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } } - sp iface = newWifiApIface(br_ifname); - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + std::shared_ptr iface = newWifiApIface(br_ifname); + return {iface, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getApIfaceNamesInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::getApIfaceNamesInternal() { if (ap_ifaces_.empty()) { - return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + return {std::vector(), ndk::ScopedAStatus::ok()}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; + return {getNames(ap_ifaces_), ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getApIfaceInternal( +std::pair, ndk::ScopedAStatus> WifiChip::getApIfaceInternal( const std::string& ifname) { const auto iface = findUsingName(ap_ifaces_, ifname); if (!iface.get()) { - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { +ndk::ScopedAStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { const auto iface = findUsingName(ap_ifaces_, ifname); if (!iface.get()) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); @@ -1044,7 +964,8 @@ WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { // nan/rtt objects over AP iface. But, there is no harm to do it // here and not make that assumption all over the place. invalidateAndRemoveDependencies(ifname); - deleteApIface(ifname); + // Clear the bridge interface and the iface instance. + invalidateAndClearBridgedAp(ifname); invalidateAndClear(ap_ifaces_, iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { @@ -1052,10 +973,10 @@ WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { } } setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal( +ndk::ScopedAStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal( const std::string& ifname, const std::string& ifInstanceName) { const auto iface = findUsingName(ap_ifaces_, ifname); if (!iface.get() || ifInstanceName.empty()) { @@ -1092,12 +1013,12 @@ WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal( iface->removeInstance(ifInstanceName); setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiChip::createNanIfaceInternal() { - if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::NAN)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; +std::pair, ndk::ScopedAStatus> WifiChip::createNanIfaceInternal() { + if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::NAN_IFACE)) { + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } bool is_dedicated_iface = true; std::string ifname = getPredefinedNanIfaceName(); @@ -1107,77 +1028,80 @@ std::pair> WifiChip::createNanIfaceInternal( ifname = getFirstActiveWlanIfaceName(); is_dedicated_iface = false; } - sp iface = new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_); + std::shared_ptr iface = + WifiNanIface::create(ifname, is_dedicated_iface, legacy_hal_, iface_util_); nan_ifaces_.push_back(iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { + if (!callback->onIfaceAdded(IfaceType::NAN_IFACE, ifname).isOk()) { LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; } } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getNanIfaceNamesInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::getNanIfaceNamesInternal() { if (nan_ifaces_.empty()) { - return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + return {std::vector(), ndk::ScopedAStatus::ok()}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; + return {getNames(nan_ifaces_), ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getNanIfaceInternal( +std::pair, ndk::ScopedAStatus> WifiChip::getNanIfaceInternal( const std::string& ifname) { const auto iface = findUsingName(nan_ifaces_, ifname); if (!iface.get()) { - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { +ndk::ScopedAStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { const auto iface = findUsingName(nan_ifaces_, ifname); if (!iface.get()) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); } invalidateAndClear(nan_ifaces_, iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { - if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { + if (!callback->onIfaceRemoved(IfaceType::NAN_IFACE, ifname).isOk()) { LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; } } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiChip::createP2pIfaceInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::createP2pIfaceInternal() { if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::P2P)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } std::string ifname = getPredefinedP2pIfaceName(); - sp iface = new WifiP2pIface(ifname, legacy_hal_); + std::shared_ptr iface = + ndk::SharedRefBase::make(ifname, legacy_hal_); p2p_ifaces_.push_back(iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; } } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getP2pIfaceNamesInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::getP2pIfaceNamesInternal() { if (p2p_ifaces_.empty()) { - return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + return {std::vector(), ndk::ScopedAStatus::ok()}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; + return {getNames(p2p_ifaces_), ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getP2pIfaceInternal(const std::string& ifname) { +std::pair, ndk::ScopedAStatus> WifiChip::getP2pIfaceInternal( + const std::string& ifname) { const auto iface = findUsingName(p2p_ifaces_, ifname); if (!iface.get()) { - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { +ndk::ScopedAStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { const auto iface = findUsingName(p2p_ifaces_, ifname); if (!iface.get()) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); @@ -1188,22 +1112,23 @@ WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; } } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiChip::createStaIfaceInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::createStaIfaceInternal() { if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { - return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; } std::string ifname = allocateStaIfaceName(); legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->createVirtualInterface( - ifname, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA)); + ifname, aidl_struct_util::convertAidlIfaceTypeToLegacy(IfaceType::STA)); if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to add interface: " << ifname << " " << legacyErrorToString(legacy_status); - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {nullptr, createWifiStatusFromLegacyError(legacy_status)}; } - sp iface = new WifiStaIface(ifname, legacy_hal_, iface_util_); + std::shared_ptr iface = + ndk::SharedRefBase::make(ifname, legacy_hal_, iface_util_); sta_ifaces_.push_back(iface); for (const auto& callback : event_cb_handler_.getCallbacks()) { if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { @@ -1211,26 +1136,26 @@ std::pair> WifiChip::createStaIfaceInternal( } } setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getStaIfaceNamesInternal() { +std::pair, ndk::ScopedAStatus> WifiChip::getStaIfaceNamesInternal() { if (sta_ifaces_.empty()) { - return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; + return {std::vector(), ndk::ScopedAStatus::ok()}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; + return {getNames(sta_ifaces_), ndk::ScopedAStatus::ok()}; } -std::pair> WifiChip::getStaIfaceInternal( +std::pair, ndk::ScopedAStatus> WifiChip::getStaIfaceInternal( const std::string& ifname) { const auto iface = findUsingName(sta_ifaces_, ifname); if (!iface.get()) { - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; + return {iface, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { +ndk::ScopedAStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { const auto iface = findUsingName(sta_ifaces_, ifname); if (!iface.get()) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); @@ -1249,37 +1174,47 @@ WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { } } setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -std::pair> WifiChip::createRttControllerInternal( - const sp& /*bound_iface*/) { - LOG(ERROR) << "createRttController is not supported on this HAL"; - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; +std::pair, ndk::ScopedAStatus> +WifiChip::createRttControllerInternal(const std::shared_ptr& bound_iface) { + if (sta_ifaces_.size() == 0 && + !canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { + LOG(ERROR) << "createRttControllerInternal: Chip cannot support STAs " + "(and RTT by extension)"; + return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; + } + std::shared_ptr rtt = + WifiRttController::create(getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); + rtt_controllers_.emplace_back(rtt); + return {rtt, ndk::ScopedAStatus::ok()}; } -std::pair> +std::pair, ndk::ScopedAStatus> WifiChip::getDebugRingBuffersStatusInternal() { legacy_hal::wifi_error legacy_status; std::vector legacy_ring_buffer_status_vec; std::tie(legacy_status, legacy_ring_buffer_status_vec) = legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName()); if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {std::vector(), + createWifiStatusFromLegacyError(legacy_status)}; } - std::vector hidl_ring_buffer_status_vec; - if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( - legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; + std::vector aidl_ring_buffer_status_vec; + if (!aidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToAidl( + legacy_ring_buffer_status_vec, &aidl_ring_buffer_status_vec)) { + return {std::vector(), + createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_ring_buffer_status_vec}; + return {aidl_ring_buffer_status_vec, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( - const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, +ndk::ScopedAStatus WifiChip::startLoggingToDebugRingBufferInternal( + const std::string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { - WifiStatus status = registerDebugRingBufferCallback(); - if (status.code != WifiStatusCode::SUCCESS) { + ndk::ScopedAStatus status = registerDebugRingBufferCallback(); + if (!status.isOk()) { return status; } legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRingBufferLogging( @@ -1290,16 +1225,16 @@ WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( std::pair(ring_name, Ringbuffer(kMaxBufferSizeBytes))); // if verbose logging enabled, turn up HAL daemon logging as well. if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) { - android::base::SetMinimumLogSeverity(android::base::DEBUG); + ::android::base::SetMinimumLogSeverity(::android::base::DEBUG); } else { - android::base::SetMinimumLogSeverity(android::base::VERBOSE); + ::android::base::SetMinimumLogSeverity(::android::base::VERBOSE); } return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(const hidl_string& ring_name) { - WifiStatus status = registerDebugRingBufferCallback(); - if (status.code != WifiStatusCode::SUCCESS) { +ndk::ScopedAStatus WifiChip::forceDumpToDebugRingBufferInternal(const std::string& ring_name) { + ndk::ScopedAStatus status = registerDebugRingBufferCallback(); + if (!status.isOk()) { return status; } legacy_hal::wifi_error legacy_status = @@ -1308,15 +1243,15 @@ WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(const hidl_string& ring_ return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::flushRingBufferToFileInternal() { +ndk::ScopedAStatus WifiChip::flushRingBufferToFileInternal() { if (!writeRingbufferFilesInternal()) { LOG(ERROR) << "Error writing files to flash"; return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { +ndk::ScopedAStatus WifiChip::stopLoggingToDebugRingBufferInternal() { legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deregisterRingBufferCallbackHandler(getFirstActiveWlanIfaceName()); if (legacy_status == legacy_hal::WIFI_SUCCESS) { @@ -1325,29 +1260,29 @@ WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { return createWifiStatusFromLegacyError(legacy_status); } -std::pair +std::pair WifiChip::getDebugHostWakeReasonStatsInternal() { legacy_hal::wifi_error legacy_status; legacy_hal::WakeReasonStats legacy_stats; std::tie(legacy_status, legacy_stats) = legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName()); if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {WifiDebugHostWakeReasonStats{}, createWifiStatusFromLegacyError(legacy_status)}; } - WifiDebugHostWakeReasonStats hidl_stats; - if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, &hidl_stats)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; + WifiDebugHostWakeReasonStats aidl_stats; + if (!aidl_struct_util::convertLegacyWakeReasonStatsToAidl(legacy_stats, &aidl_stats)) { + return {WifiDebugHostWakeReasonStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; + return {aidl_stats, ndk::ScopedAStatus::ok()}; } -WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { +ndk::ScopedAStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { legacy_hal::wifi_error legacy_status; if (enable) { - android::wp weak_ptr_this(this); + std::weak_ptr weak_ptr_this = weak_ptr_this_; const auto& on_alert_callback = [weak_ptr_this](int32_t error_code, std::vector debug_data) { - const auto shared_ptr_this = weak_ptr_this.promote(); + const auto shared_ptr_this = weak_ptr_this.lock(); if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { LOG(ERROR) << "Callback invoked on an invalid object"; return; @@ -1367,106 +1302,51 @@ WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario) { +ndk::ScopedAStatus WifiChip::selectTxPowerScenarioInternal(IWifiChip::TxPowerScenario scenario) { auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( getFirstActiveWlanIfaceName(), - hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); + aidl_struct_util::convertAidlTxPowerScenarioToLegacy(scenario)); return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::resetTxPowerScenarioInternal() { +ndk::ScopedAStatus WifiChip::resetTxPowerScenarioInternal() { auto legacy_status = legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName()); return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) { +ndk::ScopedAStatus WifiChip::setLatencyModeInternal(IWifiChip::LatencyMode mode) { auto legacy_status = legacy_hal_.lock()->setLatencyMode( - getFirstActiveWlanIfaceName(), hidl_struct_util::convertHidlLatencyModeToLegacy(mode)); + getFirstActiveWlanIfaceName(), aidl_struct_util::convertAidlLatencyModeToLegacy(mode)); return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::registerEventCallbackInternal_1_2( - const sp& /* event_callback */) { - // Deprecated support for this callback. - return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); -} - -WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario) { - auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( - getFirstActiveWlanIfaceName(), - hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario)); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair WifiChip::getCapabilitiesInternal_1_3() { - // Deprecated support for this callback. - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; -} - -std::pair WifiChip::getCapabilitiesInternal_1_5() { - legacy_hal::wifi_error legacy_status; - uint64_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*/) { - LOG(ERROR) << "createRttController_1_4 is not supported on this HAL"; - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -WifiStatus WifiChip::registerEventCallbackInternal_1_4( - const sp& event_callback) { - if (!event_cb_handler_.addCallback(event_callback)) { - return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); - } - return createWifiStatus(WifiStatusCode::SUCCESS); -} - -WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(const std::string& ifname) { +ndk::ScopedAStatus WifiChip::setMultiStaPrimaryConnectionInternal(const std::string& ifname) { auto legacy_status = legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname); return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) { +ndk::ScopedAStatus WifiChip::setMultiStaUseCaseInternal(IWifiChip::MultiStaUseCase use_case) { auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase( - hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case)); + aidl_struct_util::convertAidlMultiStaUseCaseToLegacy(use_case)); return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::setCoexUnsafeChannelsInternal(std::vector unsafe_channels, - uint32_t restrictions) { +ndk::ScopedAStatus WifiChip::setCoexUnsafeChannelsInternal( + std::vector unsafe_channels, CoexRestriction restrictions) { std::vector legacy_unsafe_channels; - if (!hidl_struct_util::convertHidlVectorOfCoexUnsafeChannelToLegacy(unsafe_channels, + if (!aidl_struct_util::convertAidlVectorOfCoexUnsafeChannelToLegacy(unsafe_channels, &legacy_unsafe_channels)) { return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); } + uint32_t aidl_restrictions = static_cast(restrictions); uint32_t legacy_restrictions = 0; - if (restrictions & CoexRestriction::WIFI_DIRECT) { + if (aidl_restrictions & static_cast(CoexRestriction::WIFI_DIRECT)) { legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_DIRECT; } - if (restrictions & CoexRestriction::SOFTAP) { + if (aidl_restrictions & static_cast(CoexRestriction::SOFTAP)) { legacy_restrictions |= legacy_hal::wifi_coex_restriction::SOFTAP; } - if (restrictions & CoexRestriction::WIFI_AWARE) { + if (aidl_restrictions & static_cast(CoexRestriction::WIFI_AWARE)) { legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_AWARE; } auto legacy_status = @@ -1474,57 +1354,34 @@ WifiStatus WifiChip::setCoexUnsafeChannelsInternal(std::vector& code) { +ndk::ScopedAStatus WifiChip::setCountryCodeInternal(const std::array& code) { auto legacy_status = legacy_hal_.lock()->setCountryCode(getFirstActiveWlanIfaceName(), code); return createWifiStatusFromLegacyError(legacy_status); } -std::pair> WifiChip::getUsableChannelsInternal( - WifiBand /*band*/, uint32_t /*ifaceModeMask*/, uint32_t /*filterMask*/) { - LOG(ERROR) << "getUsableChannels is not supported on this HAL"; - return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; -} - -WifiStatus WifiChip::triggerSubsystemRestartInternal() { - auto legacy_status = legacy_hal_.lock()->triggerSubsystemRestart(); - return createWifiStatusFromLegacyError(legacy_status); -} - -std::pair> WifiChip::createRttControllerInternal_1_6( - const sp& bound_iface) { - if (sta_ifaces_.size() == 0 && - !canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { - LOG(ERROR) << "createRttControllerInternal_1_6: 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::getUsableChannelsInternal_1_6( - WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask) { +std::pair, ndk::ScopedAStatus> WifiChip::getUsableChannelsInternal( + WifiBand band, WifiIfaceMode ifaceModeMask, UsableChannelFilter filterMask) { legacy_hal::wifi_error legacy_status; std::vector legacy_usable_channels; std::tie(legacy_status, legacy_usable_channels) = legacy_hal_.lock()->getUsableChannels( - hidl_struct_util::convertHidlWifiBandToLegacyMacBand(band), - hidl_struct_util::convertHidlWifiIfaceModeToLegacy(ifaceModeMask), - hidl_struct_util::convertHidlUsableChannelFilterToLegacy(filterMask)); + aidl_struct_util::convertAidlWifiBandToLegacyMacBand(band), + aidl_struct_util::convertAidlWifiIfaceModeToLegacy( + static_cast(ifaceModeMask)), + aidl_struct_util::convertAidlUsableChannelFilterToLegacy( + static_cast(filterMask))); if (legacy_status != legacy_hal::WIFI_SUCCESS) { - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {std::vector(), createWifiStatusFromLegacyError(legacy_status)}; } - std::vector hidl_usable_channels; - if (!hidl_struct_util::convertLegacyWifiUsableChannelsToHidl(legacy_usable_channels, - &hidl_usable_channels)) { - return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; + std::vector aidl_usable_channels; + if (!aidl_struct_util::convertLegacyWifiUsableChannelsToAidl(legacy_usable_channels, + &aidl_usable_channels)) { + return {std::vector(), createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_usable_channels}; + return {aidl_usable_channels, ndk::ScopedAStatus::ok()}; } -std::pair +std::pair WifiChip::getSupportedRadioCombinationsMatrixInternal() { legacy_hal::wifi_error legacy_status; legacy_hal::wifi_radio_combination_matrix* legacy_matrix; @@ -1534,25 +1391,25 @@ WifiChip::getSupportedRadioCombinationsMatrixInternal() { if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: " << legacyErrorToString(legacy_status); - return {createWifiStatusFromLegacyError(legacy_status), {}}; + return {WifiRadioCombinationMatrix{}, createWifiStatusFromLegacyError(legacy_status)}; } - V1_6::WifiRadioCombinationMatrix hidl_matrix; - if (!hidl_struct_util::convertLegacyRadioCombinationsMatrixToHidl(legacy_matrix, - &hidl_matrix)) { - LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToHidl() "; - return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), {}}; + WifiRadioCombinationMatrix aidl_matrix; + if (!aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix, + &aidl_matrix)) { + LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToAidl() "; + return {WifiRadioCombinationMatrix(), createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } - return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_matrix}; + return {aidl_matrix, ndk::ScopedAStatus::ok()}; } -std::pair> -WifiChip::getAvailableModesInternal_1_6() { - return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; +ndk::ScopedAStatus WifiChip::triggerSubsystemRestartInternal() { + auto legacy_status = legacy_hal_.lock()->triggerSubsystemRestart(); + return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::handleChipConfiguration( - /* NONNULL */ std::unique_lock* lock, ChipModeId mode_id) { +ndk::ScopedAStatus WifiChip::handleChipConfiguration( + /* NONNULL */ std::unique_lock* lock, int32_t mode_id) { // If the chip is already configured in a different mode, stop // the legacy HAL and then start it after firmware mode change. if (isValidModeId(current_mode_id_)) { @@ -1581,41 +1438,41 @@ WifiStatus WifiChip::handleChipConfiguration( } // Every time the HAL is restarted, we need to register the // radio mode change callback. - WifiStatus status = registerRadioModeChangeCallback(); - if (status.code != WifiStatusCode::SUCCESS) { - // This probably is not a critical failure? + ndk::ScopedAStatus status = registerRadioModeChangeCallback(); + if (!status.isOk()) { + // This is probably not a critical failure? LOG(ERROR) << "Failed to register radio mode change callback"; } // Extract and save the version information into property. - std::pair version_info; + std::pair version_info; version_info = WifiChip::requestChipDebugInfoInternal(); - if (WifiStatusCode::SUCCESS == version_info.first.code) { + if (version_info.second.isOk()) { property_set("vendor.wlan.firmware.version", - version_info.second.firmwareDescription.c_str()); - property_set("vendor.wlan.driver.version", version_info.second.driverDescription.c_str()); + version_info.first.firmwareDescription.c_str()); + property_set("vendor.wlan.driver.version", version_info.first.driverDescription.c_str()); } - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } -WifiStatus WifiChip::registerDebugRingBufferCallback() { +ndk::ScopedAStatus WifiChip::registerDebugRingBufferCallback() { if (debug_ring_buffer_cb_registered_) { - return createWifiStatus(WifiStatusCode::SUCCESS); + return ndk::ScopedAStatus::ok(); } - android::wp weak_ptr_this(this); + std::weak_ptr weak_ptr_this = weak_ptr_this_; const auto& on_ring_buffer_data_callback = [weak_ptr_this](const std::string& name, const std::vector& data, const legacy_hal::wifi_ring_buffer_status& status) { - const auto shared_ptr_this = weak_ptr_this.promote(); + const auto shared_ptr_this = weak_ptr_this.lock(); if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { LOG(ERROR) << "Callback invoked on an invalid object"; return; } - WifiDebugRingBufferStatus hidl_status; + WifiDebugRingBufferStatus aidl_status; Ringbuffer::AppendStatus appendstatus; - if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(status, - &hidl_status)) { + if (!aidl_struct_util::convertLegacyDebugRingBufferStatusToAidl(status, + &aidl_status)) { LOG(ERROR) << "Error converting ring buffer status"; return; } @@ -1636,7 +1493,6 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() { shared_ptr_this->writeRingbufferFilesInternal(); return; } - }; legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->registerRingBufferCallbackHandler( getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback); @@ -1647,25 +1503,24 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() { return createWifiStatusFromLegacyError(legacy_status); } -WifiStatus WifiChip::registerRadioModeChangeCallback() { - android::wp weak_ptr_this(this); +ndk::ScopedAStatus WifiChip::registerRadioModeChangeCallback() { + std::weak_ptr weak_ptr_this = weak_ptr_this_; const auto& on_radio_mode_change_callback = [weak_ptr_this](const std::vector& mac_infos) { - const auto shared_ptr_this = weak_ptr_this.promote(); + const auto shared_ptr_this = weak_ptr_this.lock(); if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { LOG(ERROR) << "Callback invoked on an invalid object"; return; } - std::vector hidl_radio_mode_infos; - if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(mac_infos, - &hidl_radio_mode_infos)) { + std::vector aidl_radio_mode_infos; + if (!aidl_struct_util::convertLegacyWifiMacInfosToAidl(mac_infos, + &aidl_radio_mode_infos)) { LOG(ERROR) << "Error converting wifi mac info"; return; } for (const auto& callback : shared_ptr_this->getEventCallbacks()) { - if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos).isOk()) { - LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4" - << " callback on: " << toString(callback); + if (!callback->onRadioModeChange(aidl_radio_mode_infos).isOk()) { + LOG(ERROR) << "Failed to invoke onRadioModeChange callback"; } } }; @@ -1675,11 +1530,11 @@ WifiStatus WifiChip::registerRadioModeChangeCallback() { return createWifiStatusFromLegacyError(legacy_status); } -std::vector +std::vector WifiChip::getCurrentModeConcurrencyCombinations() { if (!isValidModeId(current_mode_id_)) { LOG(ERROR) << "Chip not configured in a mode yet"; - return {}; + return std::vector(); } for (const auto& mode : modes_) { if (mode.id == current_mode_id_) { @@ -1687,7 +1542,7 @@ WifiChip::getCurrentModeConcurrencyCombinations() { } } CHECK(0) << "Expected to find concurrency combinations for current mode!"; - return {}; + return std::vector(); } // Returns a map indexed by IfaceConcurrencyType with the number of ifaces currently @@ -1707,7 +1562,7 @@ std::map WifiChip::getCurrentConcurrencyCombinatio } iface_counts[IfaceConcurrencyType::AP] = num_ap; iface_counts[IfaceConcurrencyType::AP_BRIDGED] = num_ap_bridged; - iface_counts[IfaceConcurrencyType::NAN] = nan_ifaces_.size(); + iface_counts[IfaceConcurrencyType::NAN_IFACE] = nan_ifaces_.size(); iface_counts[IfaceConcurrencyType::P2P] = p2p_ifaces_.size(); iface_counts[IfaceConcurrencyType::STA] = sta_ifaces_.size(); return iface_counts; @@ -1718,10 +1573,10 @@ std::map WifiChip::getCurrentConcurrencyCombinatio // of each concurrency type in the combination. // This method is a port of HalDeviceManager.expandConcurrencyCombos() from framework. std::vector> WifiChip::expandConcurrencyCombinations( - const V1_6::IWifiChip::ChipConcurrencyCombination& combination) { - uint32_t num_expanded_combos = 1; + const IWifiChip::ChipConcurrencyCombination& combination) { + int32_t num_expanded_combos = 1; for (const auto& limit : combination.limits) { - for (uint32_t i = 0; i < limit.maxIfaces; i++) { + for (int32_t i = 0; i < limit.maxIfaces; i++) { num_expanded_combos *= limit.types.size(); } } @@ -1731,17 +1586,17 @@ std::vector> WifiChip::expandConcurrencyC std::vector> expanded_combos; expanded_combos.resize(num_expanded_combos); for (auto& expanded_combo : expanded_combos) { - for (const auto type : - {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, - IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { + for (const auto type : {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, + IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, + IfaceConcurrencyType::STA}) { expanded_combo[type] = 0; } } - uint32_t span = num_expanded_combos; + int32_t span = num_expanded_combos; for (const auto& limit : combination.limits) { - for (uint32_t i = 0; i < limit.maxIfaces; i++) { + for (int32_t i = 0; i < limit.maxIfaces; i++) { span /= limit.types.size(); - for (uint32_t k = 0; k < num_expanded_combos; ++k) { + for (int32_t k = 0; k < num_expanded_combos; ++k) { const auto iface_type = limit.types[(k / span) % limit.types.size()]; expanded_combos[k][iface_type]++; } @@ -1757,8 +1612,8 @@ bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes // Check if we have space for 1 more iface of |type| in this combo for (const auto type : - {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, - IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { + {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, + IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { size_t num_ifaces_needed = current_combo.at(type); if (type == requested_type) { num_ifaces_needed++; @@ -1802,8 +1657,8 @@ bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyCombo( const std::map& req_combo) { // Check if we have space for 1 more |type| in this combo for (const auto type : - {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, - IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { + {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, + IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { if (req_combo.count(type) == 0) { // Concurrency type not in the req_combo. continue; @@ -1816,6 +1671,7 @@ bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyCombo( } return true; } + // This method does the following: // a) Enumerate all possible concurrency combos by expanding the current // ChipConcurrencyCombination. @@ -1851,7 +1707,7 @@ bool WifiChip::canCurrentModeSupportConcurrencyType(IfaceConcurrencyType request return canCurrentModeSupportConcurrencyCombo(req_iface_combo); } -bool WifiChip::isValidModeId(ChipModeId mode_id) { +bool WifiChip::isValidModeId(int32_t mode_id) { for (const auto& mode : modes_) { if (mode.id == mode_id) { return true; @@ -2017,28 +1873,21 @@ void WifiChip::invalidateAndClearBridgedApAll() { br_ifaces_ap_instances_.clear(); } -void WifiChip::deleteApIface(const std::string& if_name) { - if (if_name.empty()) return; - // delete bridged interfaces if have +void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) { + if (br_name.empty()) return; + // delete managed interfaces for (auto const& it : br_ifaces_ap_instances_) { - if (it.first == if_name) { + if (it.first == br_name) { for (auto const& iface : it.second) { - iface_util_->removeIfaceFromBridge(if_name, iface); + iface_util_->removeIfaceFromBridge(br_name, iface); legacy_hal_.lock()->deleteVirtualInterface(iface); } - iface_util_->deleteBridge(if_name); - br_ifaces_ap_instances_.erase(if_name); - // ifname is bridged AP, return here. - return; + iface_util_->deleteBridge(br_name); + br_ifaces_ap_instances_.erase(br_name); + break; } } - - // No bridged AP case, delete AP iface - legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(if_name); - if (legacy_status != legacy_hal::WIFI_SUCCESS) { - LOG(ERROR) << "Failed to remove interface: " << if_name << " " - << legacyErrorToString(legacy_status); - } + return; } bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) { @@ -2055,8 +1904,7 @@ bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) { return false; } -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi_chip.h b/wifi/aidl/default/wifi_chip.h new file mode 100644 index 0000000000..59eaa4a58c --- /dev/null +++ b/wifi/aidl/default/wifi_chip.h @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_CHIP_H_ +#define WIFI_CHIP_H_ + +#include +#include +#include + +#include +#include +#include + +#include "aidl_callback_util.h" +#include "ringbuffer.h" +#include "wifi_ap_iface.h" +#include "wifi_feature_flags.h" +#include "wifi_legacy_hal.h" +#include "wifi_mode_controller.h" +#include "wifi_nan_iface.h" +#include "wifi_p2p_iface.h" +#include "wifi_rtt_controller.h" +#include "wifi_sta_iface.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * AIDL interface object used to control a Wifi HAL chip instance. + * Since there is only a single chip instance used today, there is no + * identifying handle information stored here. + */ +class WifiChip : public BnWifiChip { + public: + WifiChip(int32_t chip_id, bool is_primary, + const std::weak_ptr legacy_hal, + const std::weak_ptr mode_controller, + const std::shared_ptr iface_util, + const std::weak_ptr feature_flags, + const std::function& subsystemCallbackHandler); + + // Factory method - use instead of default constructor. + static std::shared_ptr create( + int32_t chip_id, bool is_primary, + const std::weak_ptr legacy_hal, + const std::weak_ptr mode_controller, + const std::shared_ptr iface_util, + const std::weak_ptr feature_flags, + const std::function& subsystemCallbackHandler); + + // AIDL does not provide a built-in mechanism to let the server invalidate + // an AIDL interface object after creation. If any client process holds onto + // a reference to the object in their context, any method calls on that + // reference will continue to be directed to the server. + // + // However Wifi HAL needs to control the lifetime of these objects. So, add + // a public |invalidate| method to |WifiChip| and its child objects. This + // will be used to mark an object invalid when either: + // a) Wifi HAL is stopped, or + // b) Wifi Chip is reconfigured. + // + // All AIDL method implementations should check if the object is still + // marked valid before processing them. + void invalidate(); + bool isValid(); + std::set> getEventCallbacks(); + + // AIDL methods exposed. + ndk::ScopedAStatus getId(int32_t* _aidl_return) override; + ndk::ScopedAStatus registerEventCallback( + const std::shared_ptr& in_callback) override; + ndk::ScopedAStatus getCapabilities(IWifiChip::ChipCapabilityMask* _aidl_return) override; + ndk::ScopedAStatus getAvailableModes(std::vector* _aidl_return) override; + ndk::ScopedAStatus configureChip(int32_t in_modeId) override; + ndk::ScopedAStatus getMode(int32_t* _aidl_return) override; + ndk::ScopedAStatus requestChipDebugInfo(IWifiChip::ChipDebugInfo* _aidl_return) override; + ndk::ScopedAStatus requestDriverDebugDump(std::vector* _aidl_return) override; + ndk::ScopedAStatus requestFirmwareDebugDump(std::vector* _aidl_return) override; + ndk::ScopedAStatus createApIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus createBridgedApIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus getApIfaceNames(std::vector* _aidl_return) override; + ndk::ScopedAStatus getApIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus removeApIface(const std::string& in_ifname) override; + ndk::ScopedAStatus removeIfaceInstanceFromBridgedApIface( + const std::string& in_brIfaceName, const std::string& in_ifaceInstanceName) override; + ndk::ScopedAStatus createNanIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus getNanIfaceNames(std::vector* _aidl_return) override; + ndk::ScopedAStatus getNanIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus removeNanIface(const std::string& in_ifname) override; + ndk::ScopedAStatus createP2pIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus getP2pIfaceNames(std::vector* _aidl_return) override; + ndk::ScopedAStatus getP2pIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus removeP2pIface(const std::string& in_ifname) override; + ndk::ScopedAStatus createStaIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus getStaIfaceNames(std::vector* _aidl_return) override; + ndk::ScopedAStatus getStaIface(const std::string& in_ifname, + std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus removeStaIface(const std::string& in_ifname) override; + ndk::ScopedAStatus createRttController( + const std::shared_ptr& in_boundIface, + std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus getDebugRingBuffersStatus( + std::vector* _aidl_return) override; + ndk::ScopedAStatus startLoggingToDebugRingBuffer( + const std::string& in_ringName, WifiDebugRingBufferVerboseLevel in_verboseLevel, + int32_t in_maxIntervalInSec, int32_t in_minDataSizeInBytes) override; + ndk::ScopedAStatus forceDumpToDebugRingBuffer(const std::string& in_ringName) override; + ndk::ScopedAStatus flushRingBufferToFile() override; + ndk::ScopedAStatus stopLoggingToDebugRingBuffer() override; + ndk::ScopedAStatus getDebugHostWakeReasonStats( + WifiDebugHostWakeReasonStats* _aidl_return) override; + ndk::ScopedAStatus enableDebugErrorAlerts(bool in_enable) override; + ndk::ScopedAStatus selectTxPowerScenario(IWifiChip::TxPowerScenario in_scenario) override; + ndk::ScopedAStatus resetTxPowerScenario() override; + ndk::ScopedAStatus setLatencyMode(IWifiChip::LatencyMode in_mode) override; + ndk::ScopedAStatus setMultiStaPrimaryConnection(const std::string& in_ifName) override; + ndk::ScopedAStatus setMultiStaUseCase(IWifiChip::MultiStaUseCase in_useCase) override; + ndk::ScopedAStatus setCoexUnsafeChannels( + const std::vector& in_unsafeChannels, + CoexRestriction in_restrictions) override; + ndk::ScopedAStatus setCountryCode(const std::array& in_code) override; + ndk::ScopedAStatus getUsableChannels(WifiBand in_band, WifiIfaceMode in_ifaceModeMask, + UsableChannelFilter in_filterMask, + std::vector* _aidl_return) override; + ndk::ScopedAStatus triggerSubsystemRestart() override; + ndk::ScopedAStatus getSupportedRadioCombinationsMatrix( + WifiRadioCombinationMatrix* _aidl_return) override; + binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; + + private: + void invalidateAndRemoveAllIfaces(); + // When a STA iface is removed any dependent NAN-ifaces/RTT-controllers are + // invalidated & removed. + void invalidateAndRemoveDependencies(const std::string& removed_iface_name); + + // Corresponding worker functions for the AIDL methods. + std::pair getIdInternal(); + ndk::ScopedAStatus registerEventCallbackInternal( + const std::shared_ptr& event_callback); + std::pair getCapabilitiesInternal(); + std::pair, ndk::ScopedAStatus> getAvailableModesInternal(); + ndk::ScopedAStatus configureChipInternal(std::unique_lock* lock, + int32_t mode_id); + std::pair getModeInternal(); + std::pair requestChipDebugInfoInternal(); + std::pair, ndk::ScopedAStatus> requestDriverDebugDumpInternal(); + std::pair, ndk::ScopedAStatus> requestFirmwareDebugDumpInternal(); + std::shared_ptr newWifiApIface(std::string& ifname); + ndk::ScopedAStatus createVirtualApInterface(const std::string& apVirtIf); + std::pair, ndk::ScopedAStatus> createApIfaceInternal(); + std::pair, ndk::ScopedAStatus> createBridgedApIfaceInternal(); + std::pair, ndk::ScopedAStatus> getApIfaceNamesInternal(); + std::pair, ndk::ScopedAStatus> getApIfaceInternal( + const std::string& ifname); + ndk::ScopedAStatus removeApIfaceInternal(const std::string& ifname); + ndk::ScopedAStatus removeIfaceInstanceFromBridgedApIfaceInternal( + const std::string& brIfaceName, const std::string& ifInstanceName); + std::pair, ndk::ScopedAStatus> createNanIfaceInternal(); + std::pair, ndk::ScopedAStatus> getNanIfaceNamesInternal(); + std::pair, ndk::ScopedAStatus> getNanIfaceInternal( + const std::string& ifname); + ndk::ScopedAStatus removeNanIfaceInternal(const std::string& ifname); + std::pair, ndk::ScopedAStatus> createP2pIfaceInternal(); + std::pair, ndk::ScopedAStatus> getP2pIfaceNamesInternal(); + std::pair, ndk::ScopedAStatus> getP2pIfaceInternal( + const std::string& ifname); + ndk::ScopedAStatus removeP2pIfaceInternal(const std::string& ifname); + std::pair, ndk::ScopedAStatus> createStaIfaceInternal(); + std::pair, ndk::ScopedAStatus> getStaIfaceNamesInternal(); + std::pair, ndk::ScopedAStatus> getStaIfaceInternal( + const std::string& ifname); + ndk::ScopedAStatus removeStaIfaceInternal(const std::string& ifname); + std::pair, ndk::ScopedAStatus> createRttControllerInternal( + const std::shared_ptr& bound_iface); + std::pair, ndk::ScopedAStatus> + getDebugRingBuffersStatusInternal(); + ndk::ScopedAStatus startLoggingToDebugRingBufferInternal( + const std::string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, + uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes); + ndk::ScopedAStatus forceDumpToDebugRingBufferInternal(const std::string& ring_name); + ndk::ScopedAStatus flushRingBufferToFileInternal(); + ndk::ScopedAStatus stopLoggingToDebugRingBufferInternal(); + std::pair + getDebugHostWakeReasonStatsInternal(); + ndk::ScopedAStatus enableDebugErrorAlertsInternal(bool enable); + ndk::ScopedAStatus selectTxPowerScenarioInternal(IWifiChip::TxPowerScenario scenario); + ndk::ScopedAStatus resetTxPowerScenarioInternal(); + ndk::ScopedAStatus setLatencyModeInternal(IWifiChip::LatencyMode mode); + ndk::ScopedAStatus setMultiStaPrimaryConnectionInternal(const std::string& ifname); + ndk::ScopedAStatus setMultiStaUseCaseInternal(IWifiChip::MultiStaUseCase use_case); + ndk::ScopedAStatus setCoexUnsafeChannelsInternal( + std::vector unsafe_channels, + CoexRestriction restrictions); + ndk::ScopedAStatus setCountryCodeInternal(const std::array& in_code); + std::pair, ndk::ScopedAStatus> getUsableChannelsInternal( + WifiBand band, WifiIfaceMode ifaceModeMask, UsableChannelFilter filterMask); + ndk::ScopedAStatus handleChipConfiguration(std::unique_lock* lock, + int32_t mode_id); + ndk::ScopedAStatus registerDebugRingBufferCallback(); + ndk::ScopedAStatus registerRadioModeChangeCallback(); + + std::vector getCurrentModeConcurrencyCombinations(); + std::map getCurrentConcurrencyCombination(); + std::vector> expandConcurrencyCombinations( + const ChipConcurrencyCombination& combination); + bool canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes( + const std::map& expanded_combo, + IfaceConcurrencyType requested_type); + bool canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType requested_type); + bool canExpandedConcurrencyComboSupportConcurrencyCombo( + const std::map& expanded_combo, + const std::map& req_combo); + bool canCurrentModeSupportConcurrencyCombo( + const std::map& req_combo); + bool canCurrentModeSupportConcurrencyType(IfaceConcurrencyType requested_type); + + bool isValidModeId(int32_t mode_id); + bool isStaApConcurrencyAllowedInCurrentMode(); + bool isDualStaConcurrencyAllowedInCurrentMode(); + uint32_t startIdxOfApIface(); + std::string getFirstActiveWlanIfaceName(); + std::string allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx); + std::string allocateApIfaceName(); + std::vector allocateBridgedApInstanceNames(); + std::string allocateStaIfaceName(); + bool writeRingbufferFilesInternal(); + std::string getWlanIfaceNameWithType(IfaceType type, unsigned idx); + void invalidateAndClearBridgedApAll(); + void invalidateAndClearBridgedAp(const std::string& br_name); + bool findUsingNameFromBridgedApInstances(const std::string& name); + ndk::ScopedAStatus triggerSubsystemRestartInternal(); + std::pair + getSupportedRadioCombinationsMatrixInternal(); + void setWeakPtr(std::weak_ptr ptr); + + int32_t chip_id_; + std::weak_ptr legacy_hal_; + std::weak_ptr mode_controller_; + std::shared_ptr iface_util_; + std::vector> ap_ifaces_; + std::vector> nan_ifaces_; + std::vector> p2p_ifaces_; + std::vector> sta_ifaces_; + std::vector> rtt_controllers_; + std::map ringbuffer_map_; + bool is_valid_; + // Members pertaining to chip configuration. + int32_t current_mode_id_; + std::mutex lock_t; + std::vector modes_; + // The legacy ring buffer callback API has only a global callback + // registration mechanism. Use this to check if we have already + // registered a callback. + bool debug_ring_buffer_cb_registered_; + aidl_callback_util::AidlCallbackHandler event_cb_handler_; + std::weak_ptr weak_ptr_this_; + + const std::function subsystemCallbackHandler_; + std::map> br_ifaces_ap_instances_; + DISALLOW_COPY_AND_ASSIGN(WifiChip); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_CHIP_H_ diff --git a/wifi/1.6/default/wifi_feature_flags.cpp b/wifi/aidl/default/wifi_feature_flags.cpp similarity index 59% rename from wifi/1.6/default/wifi_feature_flags.cpp rename to wifi/aidl/default/wifi_feature_flags.cpp index e80a3cdcb6..3c9f042607 100644 --- a/wifi/1.6/default/wifi_feature_flags.cpp +++ b/wifi/aidl/default/wifi_feature_flags.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,17 +21,12 @@ #include "wifi_feature_flags.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace feature_flags { -using V1_0::ChipModeId; -using V1_0::IWifiChip; -using V1_6::IfaceConcurrencyType; - /* The chip may either have a single mode supporting any number of combinations, * or a fixed dual-mode (so it involves firmware loading to switch between * modes) setting. If there is a need to support more modes, it needs to be @@ -41,7 +36,7 @@ using V1_6::IfaceConcurrencyType; * Supported combinations are defined in device's makefile, for example: * WIFI_HAL_INTERFACE_COMBINATIONS := {{{STA, AP}, 1}, {{P2P, NAN}, 1}}, * WIFI_HAL_INTERFACE_COMBINATIONS += {{{STA}, 1}, {{AP}, 2}} - * What means: + * What this means: * Interface concurrency combination 1: 1 STA or AP and 1 P2P or NAN concurrent iface * operations. * Interface concurrency combination 2: 1 STA and 2 AP concurrent iface operations. @@ -71,10 +66,10 @@ using V1_6::IfaceConcurrencyType; */ // clang-format off #ifdef WIFI_HAL_INTERFACE_COMBINATIONS -constexpr ChipModeId kMainModeId = chip_mode_ids::kV3; +constexpr int kMainModeId = chip_mode_ids::kV3; #elif defined(WIFI_HIDL_FEATURE_DUAL_INTERFACE) // former V2 (fixed dual interface) setup expressed as V3 -constexpr ChipModeId kMainModeId = chip_mode_ids::kV3; +constexpr int kMainModeId = chip_mode_ids::kV3; # ifdef WIFI_HIDL_FEATURE_DISABLE_AP # ifdef WIFI_HIDL_FEATURE_AWARE // 1 STA + 1 of (P2P or NAN) @@ -96,7 +91,7 @@ constexpr ChipModeId kMainModeId = chip_mode_ids::kV3; # endif #else // V1 (fixed single interface, dual-mode chip) -constexpr ChipModeId kMainModeId = chip_mode_ids::kV1Sta; +constexpr int kMainModeId = chip_mode_ids::kV1Sta; # ifdef WIFI_HIDL_FEATURE_AWARE // 1 STA + 1 of (P2P or NAN) # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P, NAN}, 1}} @@ -111,44 +106,35 @@ constexpr ChipModeId kMainModeId = chip_mode_ids::kV1Sta; #endif // clang-format on -/** - * Helper class to convert a collection of combination limits to a combination. - * - * The main point here is to simplify the syntax required by - * WIFI_HAL_INTERFACE_COMBINATIONS. - */ -struct ChipConcurrencyCombination - : public hidl_vec { - ChipConcurrencyCombination( - const std::initializer_list list) - : hidl_vec(list) {} - - operator V1_6::IWifiChip::ChipConcurrencyCombination() const { return {*this}; } - - static hidl_vec make_vec( - const std::initializer_list list) { - return hidl_vec( // - std::begin(list), std::end(list)); +// Convert from the legacy format (used by the WIFI_HAL_INTERFACE_COMBINATIONS +// config variable) to a list of ChipConcurrencyCombination objects. +std::vector legacyToChipConcurrencyComboList( + std::vector> legacyLimits) { + std::vector combos; + for (auto& legacyLimit : legacyLimits) { + IWifiChip::ChipConcurrencyCombination combo = {legacyLimit}; + combos.push_back(combo); } -}; + return combos; +} #define STA IfaceConcurrencyType::STA #define AP IfaceConcurrencyType::AP #define AP_BRIDGED IfaceConcurrencyType::AP_BRIDGED #define P2P IfaceConcurrencyType::P2P -#define NAN IfaceConcurrencyType::NAN -static const std::vector kChipModesPrimary{ - {kMainModeId, ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS})}, +#define NAN IfaceConcurrencyType::NAN_IFACE +static const std::vector kChipModesPrimary{ + {kMainModeId, legacyToChipConcurrencyComboList({WIFI_HAL_INTERFACE_COMBINATIONS})}, #ifdef WIFI_HAL_INTERFACE_COMBINATIONS_AP {chip_mode_ids::kV1Ap, - ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_AP})}, + legacyToChipConcurrencyComboList({WIFI_HAL_INTERFACE_COMBINATIONS_AP})}, #endif }; -static const std::vector kChipModesSecondary{ +static const std::vector kChipModesSecondary{ #ifdef WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP {chip_mode_ids::kV3, - ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP})}, + legacyToChipConcurrencyComboList({WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP})}, #endif }; @@ -157,50 +143,46 @@ constexpr char kDebugPresetInterfaceCombinationIdxProperty[] = // List of pre-defined concurrency combinations that can be enabled at runtime via // setting the property: "kDebugPresetInterfaceCombinationIdxProperty" to the // corresponding index value. -static const std::vector>> - kDebugChipModes{// Legacy combination - No STA/AP concurrencies. - // 0 - (1 AP) or (1 STA + 1 of (P2P or NAN)) - {"No STA/AP Concurrency", - {{kMainModeId, ChipConcurrencyCombination::make_vec( - {{{{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, +static const std::vector>> kDebugChipModes{ + // Legacy combination - No STA/AP concurrencies. + // 0 - (1 AP) or (1 STA + 1 of (P2P or NAN)) + {"No STA/AP Concurrency", + {{kMainModeId, + legacyToChipConcurrencyComboList({{{{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, - // STA + AP concurrency - // 1 - (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN)) - {"STA + AP Concurrency", - {{kMainModeId, - ChipConcurrencyCombination::make_vec( - {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, + // STA + AP concurrency + // 1 - (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN)) + {"STA + AP Concurrency", + {{kMainModeId, legacyToChipConcurrencyComboList( + {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, - // STA + STA concurrency - // 2 - (1 STA + 1 AP) or (2 STA + 1 of (P2P or NAN)) - {"Dual STA Concurrency", - {{kMainModeId, - ChipConcurrencyCombination::make_vec( - {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, + // STA + STA concurrency + // 2 - (1 STA + 1 AP) or (2 STA + 1 of (P2P or NAN)) + {"Dual STA Concurrency", + {{kMainModeId, legacyToChipConcurrencyComboList( + {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, - // AP + AP + STA concurrency - // 3 - (1 STA + 2 AP) or (1 STA + 1 of (P2P or NAN)) - {"Dual AP Concurrency", - {{kMainModeId, - ChipConcurrencyCombination::make_vec( - {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, + // AP + AP + STA concurrency + // 3 - (1 STA + 2 AP) or (1 STA + 1 of (P2P or NAN)) + {"Dual AP Concurrency", + {{kMainModeId, legacyToChipConcurrencyComboList( + {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, - // STA + STA concurrency and AP + AP + STA concurrency - // 4 - (1 STA + 2 AP) or (2 STA + 1 of (P2P or NAN)) - {"Dual STA & Dual AP Concurrency", - {{kMainModeId, - ChipConcurrencyCombination::make_vec( - {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, + // STA + STA concurrency and AP + AP + STA concurrency + // 4 - (1 STA + 2 AP) or (2 STA + 1 of (P2P or NAN)) + {"Dual STA & Dual AP Concurrency", + {{kMainModeId, legacyToChipConcurrencyComboList( + {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, - // STA + STA concurrency - // 5 - (1 STA + 1 AP (bridged or single) | P2P | NAN), or (2 STA)) - {"Dual STA or STA plus single other interface", - {{kMainModeId, ChipConcurrencyCombination::make_vec( - {{{{STA}, 1}, {{P2P, NAN, AP, AP_BRIDGED}, 1}}, - {{{STA}, 2}}})}}}}; + // STA + STA concurrency + // 5 - (1 STA + 1 AP (bridged or single) | P2P | NAN), or (2 STA)) + {"Dual STA or STA plus single other interface", + {{kMainModeId, legacyToChipConcurrencyComboList( + {{{{STA}, 1}, {{P2P, NAN, AP, AP_BRIDGED}, 1}}, {{{STA}, 2}}})}}}}; #undef STA #undef AP +#undef AP_BRIDGED #undef P2P #undef NAN @@ -214,7 +196,7 @@ static const std::vector WifiFeatureFlags::getChipModesForPrimary() { +std::vector WifiFeatureFlags::getChipModesForPrimary() { std::array buffer; auto res = property_get(kDebugPresetInterfaceCombinationIdxProperty, buffer.data(), nullptr); // Debug property not set, use the device preset concurrency combination. @@ -228,20 +210,19 @@ std::vector WifiFeatureFlags::getChipModesForPrimary( return kChipModesPrimary; } std::string name; - std::vector chip_modes; + std::vector chip_modes; std::tie(name, chip_modes) = kDebugChipModes[idx]; LOG(INFO) << "Using debug chip mode: <" << name << "> set via property: " << kDebugPresetInterfaceCombinationIdxProperty; return chip_modes; } -std::vector WifiFeatureFlags::getChipModes(bool is_primary) { +std::vector WifiFeatureFlags::getChipModes(bool is_primary) { return (is_primary) ? getChipModesForPrimary() : kChipModesSecondary; } } // namespace feature_flags -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_feature_flags.h b/wifi/aidl/default/wifi_feature_flags.h similarity index 67% rename from wifi/1.6/default/wifi_feature_flags.h rename to wifi/aidl/default/wifi_feature_flags.h index 1635341e3f..af1b6a674d 100644 --- a/wifi/1.6/default/wifi_feature_flags.h +++ b/wifi/aidl/default/wifi_feature_flags.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,24 +17,23 @@ #ifndef WIFI_FEATURE_FLAGS_H_ #define WIFI_FEATURE_FLAGS_H_ -#include +#include +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace feature_flags { namespace chip_mode_ids { // These mode ID's should be unique (even across combo versions). Refer to -// handleChipConfiguration() for it's usage. -constexpr V1_0::ChipModeId kInvalid = UINT32_MAX; +// handleChipConfiguration() for its usage. +constexpr uint32_t kInvalid = UINT32_MAX; // Mode ID's for V1 -constexpr V1_0::ChipModeId kV1Sta = 0; -constexpr V1_0::ChipModeId kV1Ap = 1; +constexpr uint32_t kV1Sta = 0; +constexpr uint32_t kV1Ap = 1; // Mode ID for V3 -constexpr V1_0::ChipModeId kV3 = 3; +constexpr uint32_t kV3 = 3; } // namespace chip_mode_ids class WifiFeatureFlags { @@ -42,17 +41,16 @@ class WifiFeatureFlags { WifiFeatureFlags(); virtual ~WifiFeatureFlags() = default; - virtual std::vector getChipModes(bool is_primary); + virtual std::vector getChipModes(bool is_primary); private: - std::vector getChipModesForPrimary(); + std::vector getChipModesForPrimary(); }; } // namespace feature_flags -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_FEATURE_FLAGS_H_ diff --git a/wifi/1.6/default/wifi_iface_util.cpp b/wifi/aidl/default/wifi_iface_util.cpp similarity index 95% rename from wifi/1.6/default/wifi_iface_util.cpp rename to wifi/aidl/default/wifi_iface_util.cpp index d55e4f8251..f788217dcf 100644 --- a/wifi/1.6/default/wifi_iface_util.cpp +++ b/wifi/aidl/default/wifi_iface_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,33 +14,32 @@ * limitations under the License. */ +#include +#include #include +#include + #include #include #include #include -#include -#include -#include - -#undef NAN #include "wifi_iface_util.h" namespace { // Constants to set the local bit & clear the multicast bit. constexpr uint8_t kMacAddressMulticastMask = 0x01; constexpr uint8_t kMacAddressLocallyAssignedMask = 0x02; + } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace iface_util { -WifiIfaceUtil::WifiIfaceUtil(const std::weak_ptr iface_tool, +WifiIfaceUtil::WifiIfaceUtil(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, const std::weak_ptr legacy_hal) : iface_tool_(iface_tool), legacy_hal_(legacy_hal), @@ -169,8 +168,7 @@ bool WifiIfaceUtil::removeIfaceFromBridge(const std::string& br_name, const std: } } // namespace iface_util -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_iface_util.h b/wifi/aidl/default/wifi_iface_util.h similarity index 89% rename from wifi/1.6/default/wifi_iface_util.h rename to wifi/aidl/default/wifi_iface_util.h index c5db5deed1..a3236a5622 100644 --- a/wifi/1.6/default/wifi_iface_util.h +++ b/wifi/aidl/default/wifi_iface_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,17 +17,15 @@ #ifndef WIFI_IFACE_UTIL_H_ #define WIFI_IFACE_UTIL_H_ +#include #include -#include - #include "wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace iface_util { // Iface event handlers. @@ -42,7 +40,7 @@ struct IfaceEventHandlers { */ class WifiIfaceUtil { public: - WifiIfaceUtil(const std::weak_ptr iface_tool, + WifiIfaceUtil(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, const std::weak_ptr legacy_hal); virtual ~WifiIfaceUtil() = default; @@ -71,17 +69,16 @@ class WifiIfaceUtil { virtual std::array createRandomMacAddress(); private: - std::weak_ptr iface_tool_; + std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_; std::weak_ptr legacy_hal_; std::unique_ptr> random_mac_address_; std::map event_handlers_map_; }; } // namespace iface_util -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_IFACE_UTIL_H_ diff --git a/wifi/1.6/default/wifi_legacy_hal.cpp b/wifi/aidl/default/wifi_legacy_hal.cpp similarity index 94% rename from wifi/1.6/default/wifi_legacy_hal.cpp rename to wifi/aidl/default/wifi_legacy_hal.cpp index 43cb7c42a1..43e73cae9f 100644 --- a/wifi/1.6/default/wifi_legacy_hal.cpp +++ b/wifi/aidl/default/wifi_legacy_hal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,15 +14,16 @@ * limitations under the License. */ -#include -#include +#include "wifi_legacy_hal.h" #include #include #include -#include "hidl_sync_util.h" -#include "wifi_legacy_hal.h" +#include +#include + +#include "aidl_sync_util.h" #include "wifi_legacy_hal_stubs.h" namespace { @@ -38,7 +39,7 @@ static constexpr uint32_t kMaxWakeReasonStatsArraySize = 32; static constexpr uint32_t kMaxRingBuffers = 10; static constexpr uint32_t kMaxWifiUsableChannels = 256; static constexpr uint32_t kMaxSupportedRadioCombinationsMatrixLength = 256; -// need a long timeout (1000ms) for chips that unload their driver. +// Need a long timeout (1000ms) for chips that unload their driver. static constexpr uint32_t kMaxStopCompleteWaitMs = 1000; static constexpr char kDriverPropName[] = "wlan.driver.status"; @@ -51,11 +52,10 @@ std::vector makeCharVec(const std::string& str) { } } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { // Legacy HAL functions accept "C" style function pointers, so use global @@ -65,7 +65,7 @@ namespace legacy_hal { // Callback to be invoked once |stop| is complete std::function on_stop_complete_internal_callback; void onAsyncStopComplete(wifi_handle handle) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_stop_complete_internal_callback) { on_stop_complete_internal_callback(handle); // Invalidate this callback since we don't want this firing again. @@ -92,7 +92,7 @@ void onSyncFirmwareMemoryDump(char* buffer, int buffer_size) { // Callback to be invoked for Gscan events. std::function on_gscan_event_internal_callback; void onAsyncGscanEvent(wifi_request_id id, wifi_scan_event event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_gscan_event_internal_callback) { on_gscan_event_internal_callback(id, event); } @@ -103,7 +103,7 @@ std::function on_gscan_full_result_internal_callback; void onAsyncGscanFullResult(wifi_request_id id, wifi_scan_result* result, uint32_t buckets_scanned) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_gscan_full_result_internal_callback) { on_gscan_full_result_internal_callback(id, result, buckets_scanned); } @@ -123,7 +123,7 @@ void onSyncLinkLayerStatsResult(wifi_request_id id, wifi_iface_stat* iface_stat, std::function on_rssi_threshold_breached_internal_callback; void onAsyncRssiThresholdBreached(wifi_request_id id, uint8_t* bssid, int8_t rssi) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_rssi_threshold_breached_internal_callback) { on_rssi_threshold_breached_internal_callback(id, bssid, rssi); } @@ -134,7 +134,7 @@ std::function on_ring_buffer_data_internal_callback; void onAsyncRingBufferData(char* ring_name, char* buffer, int buffer_size, wifi_ring_buffer_status* status) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_ring_buffer_data_internal_callback) { on_ring_buffer_data_internal_callback(ring_name, buffer, buffer_size, status); } @@ -143,7 +143,7 @@ void onAsyncRingBufferData(char* ring_name, char* buffer, int buffer_size, // Callback to be invoked for error alert indication. std::function on_error_alert_internal_callback; void onAsyncErrorAlert(wifi_request_id id, char* buffer, int buffer_size, int err_code) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_error_alert_internal_callback) { on_error_alert_internal_callback(id, buffer, buffer_size, err_code); } @@ -153,7 +153,7 @@ void onAsyncErrorAlert(wifi_request_id id, char* buffer, int buffer_size, int er std::function on_radio_mode_change_internal_callback; void onAsyncRadioModeChange(wifi_request_id id, uint32_t num_macs, wifi_mac_info* mac_infos) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_radio_mode_change_internal_callback) { on_radio_mode_change_internal_callback(id, num_macs, mac_infos); } @@ -162,7 +162,7 @@ void onAsyncRadioModeChange(wifi_request_id id, uint32_t num_macs, wifi_mac_info // Callback to be invoked to report subsystem restart std::function on_subsystem_restart_internal_callback; void onAsyncSubsystemRestart(const char* error) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_subsystem_restart_internal_callback) { on_subsystem_restart_internal_callback(error); } @@ -172,7 +172,7 @@ void onAsyncSubsystemRestart(const char* error) { std::function on_rtt_results_internal_callback; void onAsyncRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result* rtt_results[]) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_rtt_results_internal_callback) { on_rtt_results_internal_callback(id, num_results, rtt_results); on_rtt_results_internal_callback = nullptr; @@ -184,37 +184,37 @@ void onAsyncRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result // callbacks. // So, handle all of them here directly to avoid adding an unnecessary layer. std::function on_nan_notify_response_user_callback; -void onAysncNanNotifyResponse(transaction_id id, NanResponseMsg* msg) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanNotifyResponse(transaction_id id, NanResponseMsg* msg) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_notify_response_user_callback && msg) { on_nan_notify_response_user_callback(id, *msg); } } std::function on_nan_event_publish_replied_user_callback; -void onAysncNanEventPublishReplied(NanPublishRepliedInd* /* event */) { - LOG(ERROR) << "onAysncNanEventPublishReplied triggered"; +void onAsyncNanEventPublishReplied(NanPublishRepliedInd* /* event */) { + LOG(ERROR) << "onAsyncNanEventPublishReplied triggered"; } std::function on_nan_event_publish_terminated_user_callback; -void onAysncNanEventPublishTerminated(NanPublishTerminatedInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventPublishTerminated(NanPublishTerminatedInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_publish_terminated_user_callback && event) { on_nan_event_publish_terminated_user_callback(*event); } } std::function on_nan_event_match_user_callback; -void onAysncNanEventMatch(NanMatchInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventMatch(NanMatchInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_match_user_callback && event) { on_nan_event_match_user_callback(*event); } } std::function on_nan_event_match_expired_user_callback; -void onAysncNanEventMatchExpired(NanMatchExpiredInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventMatchExpired(NanMatchExpiredInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_match_expired_user_callback && event) { on_nan_event_match_expired_user_callback(*event); } @@ -222,95 +222,95 @@ void onAysncNanEventMatchExpired(NanMatchExpiredInd* event) { std::function on_nan_event_subscribe_terminated_user_callback; -void onAysncNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_subscribe_terminated_user_callback && event) { on_nan_event_subscribe_terminated_user_callback(*event); } } std::function on_nan_event_followup_user_callback; -void onAysncNanEventFollowup(NanFollowupInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventFollowup(NanFollowupInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_followup_user_callback && event) { on_nan_event_followup_user_callback(*event); } } std::function on_nan_event_disc_eng_event_user_callback; -void onAysncNanEventDiscEngEvent(NanDiscEngEventInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventDiscEngEvent(NanDiscEngEventInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_disc_eng_event_user_callback && event) { on_nan_event_disc_eng_event_user_callback(*event); } } std::function on_nan_event_disabled_user_callback; -void onAysncNanEventDisabled(NanDisabledInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventDisabled(NanDisabledInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_disabled_user_callback && event) { on_nan_event_disabled_user_callback(*event); } } std::function on_nan_event_tca_user_callback; -void onAysncNanEventTca(NanTCAInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventTca(NanTCAInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_tca_user_callback && event) { on_nan_event_tca_user_callback(*event); } } std::function on_nan_event_beacon_sdf_payload_user_callback; -void onAysncNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_beacon_sdf_payload_user_callback && event) { on_nan_event_beacon_sdf_payload_user_callback(*event); } } std::function on_nan_event_data_path_request_user_callback; -void onAysncNanEventDataPathRequest(NanDataPathRequestInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventDataPathRequest(NanDataPathRequestInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_data_path_request_user_callback && event) { on_nan_event_data_path_request_user_callback(*event); } } std::function on_nan_event_data_path_confirm_user_callback; -void onAysncNanEventDataPathConfirm(NanDataPathConfirmInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventDataPathConfirm(NanDataPathConfirmInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_data_path_confirm_user_callback && event) { on_nan_event_data_path_confirm_user_callback(*event); } } std::function on_nan_event_data_path_end_user_callback; -void onAysncNanEventDataPathEnd(NanDataPathEndInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventDataPathEnd(NanDataPathEndInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_data_path_end_user_callback && event) { on_nan_event_data_path_end_user_callback(*event); } } std::function on_nan_event_transmit_follow_up_user_callback; -void onAysncNanEventTransmitFollowUp(NanTransmitFollowupInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventTransmitFollowUp(NanTransmitFollowupInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_transmit_follow_up_user_callback && event) { on_nan_event_transmit_follow_up_user_callback(*event); } } std::function on_nan_event_range_request_user_callback; -void onAysncNanEventRangeRequest(NanRangeRequestInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventRangeRequest(NanRangeRequestInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_range_request_user_callback && event) { on_nan_event_range_request_user_callback(*event); } } std::function on_nan_event_range_report_user_callback; -void onAysncNanEventRangeReport(NanRangeReportInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); +void onAsyncNanEventRangeReport(NanRangeReportInd* event) { + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_range_report_user_callback && event) { on_nan_event_range_report_user_callback(*event); } @@ -318,7 +318,7 @@ void onAysncNanEventRangeReport(NanRangeReportInd* event) { std::function on_nan_event_schedule_update_user_callback; void onAsyncNanEventScheduleUpdate(NanDataPathScheduleUpdateInd* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_nan_event_schedule_update_user_callback && event) { on_nan_event_schedule_update_user_callback(*event); } @@ -327,7 +327,7 @@ void onAsyncNanEventScheduleUpdate(NanDataPathScheduleUpdateInd* event) { // Callbacks for the various TWT operations. std::function on_twt_event_setup_response_callback; void onAsyncTwtEventSetupResponse(TwtSetupResponse* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_twt_event_setup_response_callback && event) { on_twt_event_setup_response_callback(*event); } @@ -335,7 +335,7 @@ void onAsyncTwtEventSetupResponse(TwtSetupResponse* event) { std::function on_twt_event_teardown_completion_callback; void onAsyncTwtEventTeardownCompletion(TwtTeardownCompletion* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_twt_event_teardown_completion_callback && event) { on_twt_event_teardown_completion_callback(*event); } @@ -343,7 +343,7 @@ void onAsyncTwtEventTeardownCompletion(TwtTeardownCompletion* event) { std::function on_twt_event_info_frame_received_callback; void onAsyncTwtEventInfoFrameReceived(TwtInfoFrameReceived* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_twt_event_info_frame_received_callback && event) { on_twt_event_info_frame_received_callback(*event); } @@ -351,7 +351,7 @@ void onAsyncTwtEventInfoFrameReceived(TwtInfoFrameReceived* event) { std::function on_twt_event_device_notify_callback; void onAsyncTwtEventDeviceNotify(TwtDeviceNotify* event) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_twt_event_device_notify_callback && event) { on_twt_event_device_notify_callback(*event); } @@ -360,7 +360,7 @@ void onAsyncTwtEventDeviceNotify(TwtDeviceNotify* event) { // Callback to report current CHRE NAN state std::function on_chre_nan_rtt_internal_callback; void onAsyncChreNanRttState(chre_nan_rtt_state state) { - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (on_chre_nan_rtt_internal_callback) { on_chre_nan_rtt_internal_callback(state); } @@ -376,7 +376,7 @@ void onSyncCachedScanResults(wifi_cached_scan_report* cache_report) { // End of the free-standing "C" style callbacks. -WifiLegacyHal::WifiLegacyHal(const std::weak_ptr iface_tool, +WifiLegacyHal::WifiLegacyHal(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, const wifi_hal_fn& fn, bool is_primary) : global_func_table_(fn), global_handle_(nullptr), @@ -769,7 +769,7 @@ wifi_error WifiLegacyHal::startRssiMonitoring( if (!bssid_ptr) { return; } - std::array bssid_arr; + std::array bssid_arr; // |bssid_ptr| pointer is assumed to have 6 bytes for the mac // address. std::copy(bssid_ptr, bssid_ptr + 6, std::begin(bssid_arr)); @@ -820,12 +820,12 @@ wifi_error WifiLegacyHal::configureNdOffload(const std::string& iface_name, bool return global_func_table_.wifi_configure_nd_offload(getIfaceHandle(iface_name), enable); } -wifi_error WifiLegacyHal::startSendingOffloadedPacket(const std::string& iface_name, - uint32_t cmd_id, uint16_t ether_type, +wifi_error WifiLegacyHal::startSendingOffloadedPacket(const std::string& iface_name, int32_t cmd_id, + uint16_t ether_type, const std::vector& ip_packet_data, const std::array& src_address, const std::array& dst_address, - uint32_t period_in_ms) { + int32_t period_in_ms) { std::vector ip_packet_data_internal(ip_packet_data); std::vector src_address_internal(src_address.data(), src_address.data() + src_address.size()); @@ -1120,14 +1120,15 @@ wifi_error WifiLegacyHal::startRttRangeRequest( wifi_error WifiLegacyHal::cancelRttRangeRequest( const std::string& iface_name, wifi_request_id id, - const std::vector>& mac_addrs) { + const std::vector>& mac_addrs) { if (!on_rtt_results_internal_callback) { return WIFI_ERROR_NOT_AVAILABLE; } - static_assert(sizeof(mac_addr) == sizeof(std::array), "MAC address size mismatch"); + static_assert(sizeof(mac_addr) == sizeof(std::array), + "MAC address size mismatch"); // TODO: How do we handle partial cancels (i.e only a subset of enabled mac // addressed are cancelled). - std::vector> mac_addrs_internal(mac_addrs); + std::vector> mac_addrs_internal(mac_addrs); wifi_error status = global_func_table_.wifi_rtt_range_cancel( id, getIfaceHandle(iface_name), mac_addrs.size(), reinterpret_cast(mac_addrs_internal.data())); @@ -1202,14 +1203,14 @@ wifi_error WifiLegacyHal::nanRegisterCallbackHandlers(const std::string& iface_n return global_func_table_.wifi_nan_register_handler( getIfaceHandle(iface_name), - {onAysncNanNotifyResponse, onAysncNanEventPublishReplied, - onAysncNanEventPublishTerminated, onAysncNanEventMatch, onAysncNanEventMatchExpired, - onAysncNanEventSubscribeTerminated, onAysncNanEventFollowup, - onAysncNanEventDiscEngEvent, onAysncNanEventDisabled, onAysncNanEventTca, - onAysncNanEventBeaconSdfPayload, onAysncNanEventDataPathRequest, - onAysncNanEventDataPathConfirm, onAysncNanEventDataPathEnd, - onAysncNanEventTransmitFollowUp, onAysncNanEventRangeRequest, - onAysncNanEventRangeReport, onAsyncNanEventScheduleUpdate}); + {onAsyncNanNotifyResponse, onAsyncNanEventPublishReplied, + onAsyncNanEventPublishTerminated, onAsyncNanEventMatch, onAsyncNanEventMatchExpired, + onAsyncNanEventSubscribeTerminated, onAsyncNanEventFollowup, + onAsyncNanEventDiscEngEvent, onAsyncNanEventDisabled, onAsyncNanEventTca, + onAsyncNanEventBeaconSdfPayload, onAsyncNanEventDataPathRequest, + onAsyncNanEventDataPathConfirm, onAsyncNanEventDataPathEnd, + onAsyncNanEventTransmitFollowUp, onAsyncNanEventRangeRequest, + onAsyncNanEventRangeReport, onAsyncNanEventScheduleUpdate}); } wifi_error WifiLegacyHal::nanEnableRequest(const std::string& iface_name, transaction_id id, @@ -1340,7 +1341,7 @@ wifi_error WifiLegacyHal::nanDataEnd(const std::string& iface_name, transaction_ } wifi_error WifiLegacyHal::setCountryCode(const std::string& iface_name, - std::array code) { + const std::array code) { std::string code_str(code.data(), code.data() + code.size()); return global_func_table_.wifi_set_country_code(getIfaceHandle(iface_name), code_str.c_str()); } @@ -1384,7 +1385,7 @@ wifi_interface_handle WifiLegacyHal::getIfaceHandle(const std::string& iface_nam void WifiLegacyHal::runEventLoop() { LOG(DEBUG) << "Starting legacy HAL event loop"; global_func_table_.wifi_event_loop(global_handle_); - const auto lock = hidl_sync_util::acquireGlobalLock(); + const auto lock = aidl_sync_util::acquireGlobalLock(); if (!awaiting_event_loop_termination_) { LOG(FATAL) << "Legacy HAL event loop terminated, but HAL was not stopping"; } @@ -1647,8 +1648,7 @@ void WifiLegacyHal::invalidate() { } } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_legacy_hal.h b/wifi/aidl/default/wifi_legacy_hal.h similarity index 97% rename from wifi/1.6/default/wifi_legacy_hal.h rename to wifi/aidl/default/wifi_legacy_hal.h index 1fd784ad43..cd8c0b1136 100644 --- a/wifi/1.6/default/wifi_legacy_hal.h +++ b/wifi/aidl/default/wifi_legacy_hal.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,22 +17,22 @@ #ifndef WIFI_LEGACY_HAL_H_ #define WIFI_LEGACY_HAL_H_ -#include -#include -#include -#include -#include - #include #include +#include +#include +#include +#include +#include +#include + +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { // This is in a separate namespace to prevent typename conflicts between -// the legacy HAL types and the HIDL interface types. +// the legacy HAL types and the AIDL interface types. namespace legacy_hal { // Import all the types defined inside the legacy HAL header files into this // namespace. @@ -411,7 +411,7 @@ using on_gscan_results_callback = // Invoked when the rssi value breaches the thresholds set. using on_rssi_threshold_breached_callback = - std::function, int8_t)>; + std::function, int8_t)>; // Callback for RTT range request results. // Rtt results contain IE info and are hence passed by reference, to @@ -481,8 +481,8 @@ struct CachedScanResultsCallbackHandlers { */ class WifiLegacyHal { public: - WifiLegacyHal(const std::weak_ptr iface_tool, const wifi_hal_fn& fn, - bool is_primary); + WifiLegacyHal(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, + const wifi_hal_fn& fn, bool is_primary); virtual ~WifiLegacyHal() = default; // Initialize the legacy HAL function table. @@ -521,7 +521,7 @@ class WifiLegacyHal { // |on_results_user_callback| on success. // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan // results - // triggers the externally provided |on_failure_user_callback|. + // Triggers the externally provided |on_failure_user_callback|. // c) Full scan result event triggers the externally provided // |on_full_result_user_callback|. wifi_error startGscan(const std::string& iface_name, wifi_request_id id, @@ -547,12 +547,12 @@ class WifiLegacyHal { wifi_error configureRoaming(const std::string& iface_name, const wifi_roaming_config& config); wifi_error enableFirmwareRoaming(const std::string& iface_name, fw_roaming_state_t state); wifi_error configureNdOffload(const std::string& iface_name, bool enable); - wifi_error startSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id, + wifi_error startSendingOffloadedPacket(const std::string& iface_name, int32_t cmd_id, uint16_t ether_type, const std::vector& ip_packet_data, const std::array& src_address, const std::array& dst_address, - uint32_t period_in_ms); + int32_t period_in_ms); wifi_error stopSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id); virtual wifi_error selectTxPowerScenario(const std::string& iface_name, wifi_power_scenario scenario); @@ -591,7 +591,7 @@ class WifiLegacyHal { const std::vector& rtt_configs, const on_rtt_results_callback& on_results_callback); wifi_error cancelRttRangeRequest(const std::string& iface_name, wifi_request_id id, - const std::vector>& mac_addrs); + const std::vector>& mac_addrs); std::pair getRttCapabilities(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, @@ -638,9 +638,9 @@ class WifiLegacyHal { const NanDataPathIndicationResponse& msg); wifi_error nanDataEnd(const std::string& iface_name, transaction_id id, uint32_t ndpInstanceId); // AP functions. - wifi_error setCountryCode(const std::string& iface_name, std::array code); + wifi_error setCountryCode(const std::string& iface_name, const std::array code); - // interface functions. + // Interface functions. virtual wifi_error createVirtualInterface(const std::string& ifname, wifi_interface_type iftype); virtual wifi_error deleteVirtualInterface(const std::string& ifname); @@ -721,8 +721,8 @@ class WifiLegacyHal { std::condition_variable_any stop_wait_cv_; // Flag to indicate if the legacy HAL has been started. bool is_started_; - std::weak_ptr iface_tool_; - // flag to indicate if this HAL is for the primary chip. This is used + std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_; + // Flag to indicate if this HAL is for the primary chip. This is used // in order to avoid some hard-coded behavior used with older HALs, // such as bring wlan0 interface up/down on start/stop HAL. // it may be removed once vendor HALs are updated. @@ -730,10 +730,9 @@ class WifiLegacyHal { }; } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_LEGACY_HAL_H_ diff --git a/wifi/1.6/default/wifi_legacy_hal_factory.cpp b/wifi/aidl/default/wifi_legacy_hal_factory.cpp similarity index 97% rename from wifi/1.6/default/wifi_legacy_hal_factory.cpp rename to wifi/aidl/default/wifi_legacy_hal_factory.cpp index 147bf4d7cc..60f81ed764 100644 --- a/wifi/1.6/default/wifi_legacy_hal_factory.cpp +++ b/wifi/aidl/default/wifi_legacy_hal_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,17 +14,17 @@ * limitations under the License. */ -#include -#include -#include +#include "wifi_legacy_hal_factory.h" #include +#include #include #include #include #include +#include +#include -#include "wifi_legacy_hal_factory.h" #include "wifi_legacy_hal_stubs.h" namespace { @@ -59,15 +59,14 @@ bool isFileExtension(const char* name, const char* ext) { } }; // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { WifiLegacyHalFactory::WifiLegacyHalFactory( - const std::weak_ptr iface_tool) + const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool) : iface_tool_(iface_tool) {} std::vector> WifiLegacyHalFactory::getHals() { @@ -247,8 +246,7 @@ out_err: } } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_legacy_hal_factory.h b/wifi/aidl/default/wifi_legacy_hal_factory.h similarity index 82% rename from wifi/1.6/default/wifi_legacy_hal_factory.h rename to wifi/aidl/default/wifi_legacy_hal_factory.h index 9f4423efb7..e7b287a6f5 100644 --- a/wifi/1.6/default/wifi_legacy_hal_factory.h +++ b/wifi/aidl/default/wifi_legacy_hal_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2022 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. @@ -21,20 +21,19 @@ #include "wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { // This is in a separate namespace to prevent typename conflicts between -// the legacy HAL types and the HIDL interface types. +// the legacy HAL types and the AIDL interface types. namespace legacy_hal { /** * Class that creates WifiLegacyHal objects for vendor HALs in the system. */ class WifiLegacyHalFactory { public: - WifiLegacyHalFactory(const std::weak_ptr iface_tool); + WifiLegacyHalFactory(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool); virtual ~WifiLegacyHalFactory() = default; std::vector> getHals(); @@ -51,16 +50,15 @@ class WifiLegacyHalFactory { bool initLinkedHalFunctionTable(wifi_hal_fn* hal_fn); bool loadVendorHalLib(const std::string& path, wifi_hal_lib_desc& desc); - std::weak_ptr iface_tool_; + std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_; std::vector descs_; std::vector> legacy_hals_; }; } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_LEGACY_HAL_FACTORY_H_ diff --git a/wifi/1.6/default/wifi_legacy_hal_stubs.cpp b/wifi/aidl/default/wifi_legacy_hal_stubs.cpp similarity index 98% rename from wifi/1.6/default/wifi_legacy_hal_stubs.cpp rename to wifi/aidl/default/wifi_legacy_hal_stubs.cpp index 8f8527a4cc..cff7f6977b 100644 --- a/wifi/1.6/default/wifi_legacy_hal_stubs.cpp +++ b/wifi/aidl/default/wifi_legacy_hal_stubs.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,11 +17,10 @@ #include "wifi_legacy_hal_stubs.h" // TODO: Remove these stubs from HalTool in libwifi-system. +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { template struct stubFunction; @@ -170,9 +169,9 @@ bool initHalFuncTableWithStubs(wifi_hal_fn* hal_fn) { populateStubFor(&hal_fn->wifi_get_cached_scan_results); return true; } + } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_legacy_hal_stubs.h b/wifi/aidl/default/wifi_legacy_hal_stubs.h similarity index 86% rename from wifi/1.6/default/wifi_legacy_hal_stubs.h rename to wifi/aidl/default/wifi_legacy_hal_stubs.h index c9a03bf4c9..603ecf2eae 100644 --- a/wifi/1.6/default/wifi_legacy_hal_stubs.h +++ b/wifi/aidl/default/wifi_legacy_hal_stubs.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -19,19 +19,17 @@ #include +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace legacy_hal { bool initHalFuncTableWithStubs(wifi_hal_fn* hal_fn); } // namespace legacy_hal -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_LEGACY_HAL_STUBS_H_ diff --git a/wifi/1.6/default/wifi_mode_controller.cpp b/wifi/aidl/default/wifi_mode_controller.cpp similarity index 91% rename from wifi/1.6/default/wifi_mode_controller.cpp rename to wifi/aidl/default/wifi_mode_controller.cpp index 4b8ac7dd1c..07cb072363 100644 --- a/wifi/1.6/default/wifi_mode_controller.cpp +++ b/wifi/aidl/default/wifi_mode_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,16 +14,16 @@ * limitations under the License. */ +#include "wifi_mode_controller.h" + #include #include #include -#include "wifi_mode_controller.h" - -using android::hardware::wifi::V1_0::IfaceType; +namespace { +using aidl::android::hardware::wifi::IfaceType; using android::wifi_hal::DriverTool; -namespace { int convertIfaceTypeToFirmwareMode(IfaceType type) { int mode; switch (type) { @@ -33,7 +33,7 @@ int convertIfaceTypeToFirmwareMode(IfaceType type) { case IfaceType::P2P: mode = DriverTool::kFirmwareModeP2p; break; - case IfaceType::NAN: + case IfaceType::NAN_IFACE: // NAN is exposed in STA mode currently. mode = DriverTool::kFirmwareModeSta; break; @@ -45,11 +45,10 @@ int convertIfaceTypeToFirmwareMode(IfaceType type) { } } // namespace +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace mode_controller { WifiModeController::WifiModeController() : driver_tool_(new DriverTool) {} @@ -81,9 +80,9 @@ bool WifiModeController::deinitialize() { } return true; } + } // namespace mode_controller -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_mode_controller.h b/wifi/aidl/default/wifi_mode_controller.h similarity index 84% rename from wifi/1.6/default/wifi_mode_controller.h rename to wifi/aidl/default/wifi_mode_controller.h index fee2b66d4e..1a9fb1a498 100644 --- a/wifi/1.6/default/wifi_mode_controller.h +++ b/wifi/aidl/default/wifi_mode_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,17 +17,14 @@ #ifndef WIFI_MODE_CONTROLLER_H_ #define WIFI_MODE_CONTROLLER_H_ +#include #include -#include - +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { namespace mode_controller { -using namespace android::hardware::wifi::V1_0; /** * Class that encapsulates all firmware mode configuration. @@ -50,14 +47,13 @@ class WifiModeController { virtual bool deinitialize(); private: - std::unique_ptr driver_tool_; + std::unique_ptr<::android::wifi_hal::DriverTool> driver_tool_; }; } // namespace mode_controller -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_MODE_CONTROLLER_H_ diff --git a/wifi/aidl/default/wifi_nan_iface.cpp b/wifi/aidl/default/wifi_nan_iface.cpp new file mode 100644 index 0000000000..9edef09b7b --- /dev/null +++ b/wifi/aidl/default/wifi_nan_iface.cpp @@ -0,0 +1,751 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "wifi_nan_iface.h" + +#include + +#include "aidl_return_util.h" +#include "aidl_struct_util.h" +#include "wifi_status_util.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +using aidl_return_util::validateAndCall; + +WifiNanIface::WifiNanIface(const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) + : ifname_(ifname), + is_dedicated_iface_(is_dedicated_iface), + legacy_hal_(legacy_hal), + iface_util_(iface_util), + is_valid_(true) {} + +std::shared_ptr WifiNanIface::create( + const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) { + std::shared_ptr ptr = ndk::SharedRefBase::make( + ifname, is_dedicated_iface, legacy_hal, iface_util); + if (is_dedicated_iface) { + // If using a dedicated iface, set the iface up first. + if (!iface_util.lock()->setUpState(ifname, true)) { + // Fatal failure, invalidate the iface object. + ptr->invalidate(); + return nullptr; + } + } + std::weak_ptr weak_ptr_this(ptr); + ptr->setWeakPtr(weak_ptr_this); + ptr->registerCallbackHandlers(); + return ptr; +} + +void WifiNanIface::registerCallbackHandlers() { + // Register all the callbacks here. These should be valid for the lifetime + // of the object. Whenever the mode changes legacy HAL will remove + // all of these callbacks. + legacy_hal::NanCallbackHandlers callback_handlers; + std::weak_ptr weak_ptr_this = weak_ptr_this_; + + // Callback for response. + callback_handlers.on_notify_response = [weak_ptr_this](legacy_hal::transaction_id id, + const legacy_hal::NanResponseMsg& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanStatus nanStatus; + if (!aidl_struct_util::convertLegacyNanResponseHeaderToAidl(msg, &nanStatus)) { + LOG(ERROR) << "Failed to convert nan response header"; + return; + } + + switch (msg.response_type) { + case legacy_hal::NAN_RESPONSE_ENABLED: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyEnableResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_DISABLED: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyDisableResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_PUBLISH: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyStartPublishResponse(id, nanStatus, + msg.body.publish_response.publish_id) + .isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_PUBLISH_CANCEL: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyStopPublishResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_TRANSMIT_FOLLOWUP: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyTransmitFollowupResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_SUBSCRIBE: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyStartSubscribeResponse( + id, nanStatus, msg.body.subscribe_response.subscribe_id) + .isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_SUBSCRIBE_CANCEL: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyStopSubscribeResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_CONFIG: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyConfigResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_GET_CAPABILITIES: { + NanCapabilities aidl_struct; + if (!aidl_struct_util::convertLegacyNanCapabilitiesResponseToAidl( + msg.body.nan_capabilities, &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyCapabilitiesResponse(id, nanStatus, aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_DP_INTERFACE_CREATE: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyCreateDataInterfaceResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_DP_INTERFACE_DELETE: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyDeleteDataInterfaceResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_DP_INITIATOR_RESPONSE: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyInitiateDataPathResponse( + id, nanStatus, + msg.body.data_request_response.ndp_instance_id) + .isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_DP_RESPONDER_RESPONSE: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyRespondToDataPathIndicationResponse(id, nanStatus) + .isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_DP_END: { + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->notifyTerminateDataPathResponse(id, nanStatus).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + break; + } + case legacy_hal::NAN_RESPONSE_BEACON_SDF_PAYLOAD: + /* fall through */ + case legacy_hal::NAN_RESPONSE_TCA: + /* fall through */ + case legacy_hal::NAN_RESPONSE_STATS: + /* fall through */ + case legacy_hal::NAN_RESPONSE_ERROR: + /* fall through */ + default: + LOG(ERROR) << "Unknown or unhandled response type: " << msg.response_type; + return; + } + }; + + callback_handlers.on_event_disc_eng_event = [weak_ptr_this]( + const legacy_hal::NanDiscEngEventInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanClusterEventInd aidl_struct; + // event types defined identically - hence can be cast + aidl_struct.eventType = (NanClusterEventType)msg.event_type; + aidl_struct.addr = std::array(); + std::copy(msg.data.mac_addr.addr, msg.data.mac_addr.addr + 6, std::begin(aidl_struct.addr)); + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventClusterEvent(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_disabled = [weak_ptr_this](const legacy_hal::NanDisabledInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanStatus status; + aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason, sizeof(msg.nan_reason), + &status); + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventDisabled(status).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_publish_terminated = + [weak_ptr_this](const legacy_hal::NanPublishTerminatedInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanStatus status; + aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason, + sizeof(msg.nan_reason), &status); + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventPublishTerminated(msg.publish_id, status).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_subscribe_terminated = + [weak_ptr_this](const legacy_hal::NanSubscribeTerminatedInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanStatus status; + aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason, + sizeof(msg.nan_reason), &status); + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventSubscribeTerminated(msg.subscribe_id, status).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_match = [weak_ptr_this](const legacy_hal::NanMatchInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanMatchInd aidl_struct; + if (!aidl_struct_util::convertLegacyNanMatchIndToAidl(msg, &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventMatch(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_match_expired = [weak_ptr_this]( + const legacy_hal::NanMatchExpiredInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventMatchExpired(msg.publish_subscribe_id, msg.requestor_instance_id) + .isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_followup = [weak_ptr_this](const legacy_hal::NanFollowupInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanFollowupReceivedInd aidl_struct; + if (!aidl_struct_util::convertLegacyNanFollowupIndToAidl(msg, &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventFollowupReceived(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_transmit_follow_up = + [weak_ptr_this](const legacy_hal::NanTransmitFollowupInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanStatus status; + aidl_struct_util::convertToNanStatus(msg.reason, msg.nan_reason, + sizeof(msg.nan_reason), &status); + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventTransmitFollowup(msg.id, status).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_data_path_request = + [weak_ptr_this](const legacy_hal::NanDataPathRequestInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanDataPathRequestInd aidl_struct; + if (!aidl_struct_util::convertLegacyNanDataPathRequestIndToAidl(msg, + &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventDataPathRequest(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_data_path_confirm = + [weak_ptr_this](const legacy_hal::NanDataPathConfirmInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanDataPathConfirmInd aidl_struct; + if (!aidl_struct_util::convertLegacyNanDataPathConfirmIndToAidl(msg, + &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventDataPathConfirm(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + callback_handlers.on_event_data_path_end = + [weak_ptr_this](const legacy_hal::NanDataPathEndInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + for (int i = 0; i < msg.num_ndp_instances; ++i) { + if (!callback->eventDataPathTerminated(msg.ndp_instance_id[i]).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + } + }; + + callback_handlers.on_event_beacon_sdf_payload = + [](const legacy_hal::NanBeaconSdfPayloadInd& /* msg */) { + LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called"; + }; + + callback_handlers.on_event_range_request = [](const legacy_hal::NanRangeRequestInd& /* msg */) { + LOG(ERROR) << "on_event_range_request - should not be called"; + }; + + callback_handlers.on_event_range_report = [](const legacy_hal::NanRangeReportInd& /* msg */) { + LOG(ERROR) << "on_event_range_report - should not be called"; + }; + + callback_handlers.on_event_schedule_update = + [weak_ptr_this](const legacy_hal::NanDataPathScheduleUpdateInd& msg) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + NanDataPathScheduleUpdateInd aidl_struct; + if (!aidl_struct_util::convertLegacyNanDataPathScheduleUpdateIndToAidl( + msg, &aidl_struct)) { + LOG(ERROR) << "Failed to convert nan capabilities response"; + return; + } + + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventDataPathScheduleUpdate(aidl_struct).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanRegisterCallbackHandlers(ifname_, callback_handlers); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + LOG(ERROR) << "Failed to register nan callbacks. Invalidating object"; + invalidate(); + } + + // Register for iface state toggle events. + iface_util::IfaceEventHandlers event_handlers = {}; + event_handlers.on_state_toggle_off_on = [weak_ptr_this](const std::string& /* iface_name */) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + // Tell framework that NAN has been disabled. + NanStatus status = {NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""}; + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->eventDisabled(status).isOk()) { + LOG(ERROR) << "Failed to invoke the callback"; + } + } + }; + iface_util_.lock()->registerIfaceEventHandlers(ifname_, event_handlers); +} + +void WifiNanIface::setWeakPtr(std::weak_ptr ptr) { + weak_ptr_this_ = ptr; +} + +void WifiNanIface::invalidate() { + if (!isValid()) { + return; + } + // send commands to HAL to actually disable and destroy interfaces + legacy_hal_.lock()->nanDisableRequest(ifname_, 0xFFFF); + legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFE, "aware_data0"); + legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, 0xFFFD, "aware_data1"); + iface_util_.lock()->unregisterIfaceEventHandlers(ifname_); + legacy_hal_.reset(); + event_cb_handler_.invalidate(); + is_valid_ = false; + if (is_dedicated_iface_) { + // If using a dedicated iface, set the iface down. + iface_util_.lock()->setUpState(ifname_, false); + } +} + +bool WifiNanIface::isValid() { + return is_valid_; +} + +std::string WifiNanIface::getName() { + return ifname_; +} + +std::set> WifiNanIface::getEventCallbacks() { + LOG(ERROR) << "Using original getEventCallbacks"; + return event_cb_handler_.getCallbacks(); +} + +ndk::ScopedAStatus WifiNanIface::getName(std::string* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::getNameInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiNanIface::registerEventCallback( + const std::shared_ptr& callback) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::registerEventCallbackInternal, callback); +} + +ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequest(char16_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::getCapabilitiesRequestInternal, in_cmdId); +} + +ndk::ScopedAStatus WifiNanIface::enableRequest(char16_t in_cmdId, const NanEnableRequest& in_msg1, + const NanConfigRequestSupplemental& in_msg2) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::enableRequestInternal, in_cmdId, in_msg1, in_msg2); +} + +ndk::ScopedAStatus WifiNanIface::configRequest(char16_t in_cmdId, const NanConfigRequest& in_msg1, + const NanConfigRequestSupplemental& in_msg2) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::configRequestInternal, in_cmdId, in_msg1, in_msg2); +} + +ndk::ScopedAStatus WifiNanIface::disableRequest(char16_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::disableRequestInternal, in_cmdId); +} + +ndk::ScopedAStatus WifiNanIface::startPublishRequest(char16_t in_cmdId, + const NanPublishRequest& in_msg) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::startPublishRequestInternal, in_cmdId, in_msg); +} + +ndk::ScopedAStatus WifiNanIface::stopPublishRequest(char16_t in_cmdId, int8_t in_sessionId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::stopPublishRequestInternal, in_cmdId, in_sessionId); +} + +ndk::ScopedAStatus WifiNanIface::startSubscribeRequest(char16_t in_cmdId, + const NanSubscribeRequest& in_msg) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::startSubscribeRequestInternal, in_cmdId, in_msg); +} + +ndk::ScopedAStatus WifiNanIface::stopSubscribeRequest(char16_t in_cmdId, int8_t in_sessionId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::stopSubscribeRequestInternal, in_cmdId, in_sessionId); +} + +ndk::ScopedAStatus WifiNanIface::transmitFollowupRequest(char16_t in_cmdId, + const NanTransmitFollowupRequest& in_msg) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::transmitFollowupRequestInternal, in_cmdId, in_msg); +} + +ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequest(char16_t in_cmdId, + const std::string& in_ifaceName) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::createDataInterfaceRequestInternal, in_cmdId, + in_ifaceName); +} + +ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequest(char16_t in_cmdId, + const std::string& in_ifaceName) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::deleteDataInterfaceRequestInternal, in_cmdId, + in_ifaceName); +} + +ndk::ScopedAStatus WifiNanIface::initiateDataPathRequest(char16_t in_cmdId, + const NanInitiateDataPathRequest& in_msg) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::initiateDataPathRequestInternal, in_cmdId, in_msg); +} + +ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequest( + char16_t in_cmdId, const NanRespondToDataPathIndicationRequest& in_msg) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::respondToDataPathIndicationRequestInternal, in_cmdId, + in_msg); +} + +ndk::ScopedAStatus WifiNanIface::terminateDataPathRequest(char16_t in_cmdId, + int32_t in_ndpInstanceId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiNanIface::terminateDataPathRequestInternal, in_cmdId, + in_ndpInstanceId); +} + +std::pair WifiNanIface::getNameInternal() { + return {ifname_, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiNanIface::registerEventCallbackInternal( + const std::shared_ptr& callback) { + if (!event_cb_handler_.addCallback(callback)) { + return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); + } + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus WifiNanIface::getCapabilitiesRequestInternal(char16_t cmd_id) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanGetCapabilities(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::enableRequestInternal(char16_t cmd_id, + const NanEnableRequest& msg1, + const NanConfigRequestSupplemental& msg2) { + legacy_hal::NanEnableRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanEnableRequestToLegacy(msg1, msg2, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanEnableRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::configRequestInternal(char16_t cmd_id, + const NanConfigRequest& msg1, + const NanConfigRequestSupplemental& msg2) { + legacy_hal::NanConfigRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanConfigRequestToLegacy(msg1, msg2, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanConfigRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::disableRequestInternal(char16_t cmd_id) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->nanDisableRequest(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::startPublishRequestInternal(char16_t cmd_id, + const NanPublishRequest& msg) { + legacy_hal::NanPublishRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanPublishRequestToLegacy(msg, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanPublishRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId) { + legacy_hal::NanPublishCancelRequest legacy_msg; + legacy_msg.publish_id = sessionId; + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanPublishCancelRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::startSubscribeRequestInternal(char16_t cmd_id, + const NanSubscribeRequest& msg) { + legacy_hal::NanSubscribeRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanSubscribeRequestToLegacy(msg, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanSubscribeRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId) { + legacy_hal::NanSubscribeCancelRequest legacy_msg; + legacy_msg.subscribe_id = sessionId; + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanSubscribeCancelRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::transmitFollowupRequestInternal( + char16_t cmd_id, const NanTransmitFollowupRequest& msg) { + legacy_hal::NanTransmitFollowupRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanTransmitFollowupRequestToLegacy(msg, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanTransmitFollowupRequest(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiNanIface::createDataInterfaceRequestInternal(char16_t cmd_id, + const std::string& iface_name) { + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanDataInterfaceCreate(ifname_, cmd_id, iface_name); + return createWifiStatusFromLegacyError(legacy_status); +} +ndk::ScopedAStatus WifiNanIface::deleteDataInterfaceRequestInternal(char16_t cmd_id, + const std::string& iface_name) { + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanDataInterfaceDelete(ifname_, cmd_id, iface_name); + return createWifiStatusFromLegacyError(legacy_status); +} +ndk::ScopedAStatus WifiNanIface::initiateDataPathRequestInternal( + char16_t cmd_id, const NanInitiateDataPathRequest& msg) { + legacy_hal::NanDataPathInitiatorRequest legacy_msg; + if (!aidl_struct_util::convertAidlNanDataPathInitiatorRequestToLegacy(msg, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanDataRequestInitiator(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} +ndk::ScopedAStatus WifiNanIface::respondToDataPathIndicationRequestInternal( + char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg) { + legacy_hal::NanDataPathIndicationResponse legacy_msg; + if (!aidl_struct_util::convertAidlNanDataPathIndicationResponseToLegacy(msg, &legacy_msg)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanDataIndicationResponse(ifname_, cmd_id, legacy_msg); + return createWifiStatusFromLegacyError(legacy_status); +} +ndk::ScopedAStatus WifiNanIface::terminateDataPathRequestInternal(char16_t cmd_id, + int32_t ndpInstanceId) { + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->nanDataEnd(ifname_, cmd_id, ndpInstanceId); + return createWifiStatusFromLegacyError(legacy_status); +} + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi_nan_iface.h b/wifi/aidl/default/wifi_nan_iface.h new file mode 100644 index 0000000000..101890594c --- /dev/null +++ b/wifi/aidl/default/wifi_nan_iface.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_NAN_IFACE_H_ +#define WIFI_NAN_IFACE_H_ + +#include +#include +#include + +#include "aidl_callback_util.h" +#include "wifi_iface_util.h" +#include "wifi_legacy_hal.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * AIDL interface object used to control a NAN Iface instance. + */ +class WifiNanIface : public BnWifiNanIface { + public: + WifiNanIface(const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util); + + // Factory method - use instead of default constructor. + static std::shared_ptr create( + const std::string& ifname, bool is_dedicated_iface, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util); + + // Refer to |WifiChip::invalidate()|. + void invalidate(); + bool isValid(); + std::string getName(); + + // AIDL methods exposed. + ndk::ScopedAStatus getName(std::string* _aidl_return) override; + ndk::ScopedAStatus registerEventCallback( + const std::shared_ptr& in_callback) override; + ndk::ScopedAStatus getCapabilitiesRequest(char16_t in_cmdId) override; + ndk::ScopedAStatus enableRequest(char16_t in_cmdId, const NanEnableRequest& in_msg1, + const NanConfigRequestSupplemental& in_msg2) override; + ndk::ScopedAStatus configRequest(char16_t in_cmdId, const NanConfigRequest& in_msg1, + const NanConfigRequestSupplemental& in_msg2) override; + ndk::ScopedAStatus disableRequest(char16_t in_cmdId) override; + ndk::ScopedAStatus startPublishRequest(char16_t in_cmdId, + const NanPublishRequest& in_msg) override; + ndk::ScopedAStatus stopPublishRequest(char16_t in_cmdId, int8_t in_sessionId) override; + ndk::ScopedAStatus startSubscribeRequest(char16_t in_cmdId, + const NanSubscribeRequest& in_msg) override; + ndk::ScopedAStatus stopSubscribeRequest(char16_t in_cmdId, int8_t in_sessionId) override; + ndk::ScopedAStatus transmitFollowupRequest(char16_t in_cmdId, + const NanTransmitFollowupRequest& in_msg) override; + ndk::ScopedAStatus createDataInterfaceRequest(char16_t in_cmdId, + const std::string& in_ifaceName) override; + ndk::ScopedAStatus deleteDataInterfaceRequest(char16_t in_cmdId, + const std::string& in_ifaceName) override; + ndk::ScopedAStatus initiateDataPathRequest(char16_t in_cmdId, + const NanInitiateDataPathRequest& in_msg) override; + ndk::ScopedAStatus respondToDataPathIndicationRequest( + char16_t in_cmdId, const NanRespondToDataPathIndicationRequest& in_msg) override; + ndk::ScopedAStatus terminateDataPathRequest(char16_t in_cmdId, + int32_t in_ndpInstanceId) override; + + protected: + // Accessible to child class in the gTest suite. + void setWeakPtr(std::weak_ptr ptr); + void registerCallbackHandlers(); + + private: + // Corresponding worker functions for the AIDL methods. + std::pair getNameInternal(); + ndk::ScopedAStatus registerEventCallbackInternal( + const std::shared_ptr& callback); + ndk::ScopedAStatus getCapabilitiesRequestInternal(char16_t cmd_id); + ndk::ScopedAStatus enableRequestInternal(char16_t cmd_id, const NanEnableRequest& msg1, + const NanConfigRequestSupplemental& msg2); + ndk::ScopedAStatus configRequestInternal(char16_t cmd_id, const NanConfigRequest& msg1, + const NanConfigRequestSupplemental& msg2); + ndk::ScopedAStatus disableRequestInternal(char16_t cmd_id); + ndk::ScopedAStatus startPublishRequestInternal(char16_t cmd_id, const NanPublishRequest& msg); + ndk::ScopedAStatus stopPublishRequestInternal(char16_t cmd_id, int8_t sessionId); + ndk::ScopedAStatus startSubscribeRequestInternal(char16_t cmd_id, + const NanSubscribeRequest& msg); + ndk::ScopedAStatus stopSubscribeRequestInternal(char16_t cmd_id, int8_t sessionId); + ndk::ScopedAStatus transmitFollowupRequestInternal(char16_t cmd_id, + const NanTransmitFollowupRequest& msg); + ndk::ScopedAStatus createDataInterfaceRequestInternal(char16_t cmd_id, + const std::string& iface_name); + ndk::ScopedAStatus deleteDataInterfaceRequestInternal(char16_t cmd_id, + const std::string& iface_name); + ndk::ScopedAStatus initiateDataPathRequestInternal(char16_t cmd_id, + const NanInitiateDataPathRequest& msg); + ndk::ScopedAStatus respondToDataPathIndicationRequestInternal( + char16_t cmd_id, const NanRespondToDataPathIndicationRequest& msg); + ndk::ScopedAStatus terminateDataPathRequestInternal(char16_t cmd_id, int32_t ndpInstanceId); + + // Overridden in the gTest suite. + virtual std::set> getEventCallbacks(); + + std::string ifname_; + bool is_dedicated_iface_; + std::weak_ptr legacy_hal_; + std::weak_ptr iface_util_; + bool is_valid_; + std::weak_ptr weak_ptr_this_; + aidl_callback_util::AidlCallbackHandler event_cb_handler_; + + DISALLOW_COPY_AND_ASSIGN(WifiNanIface); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_NAN_IFACE_H_ diff --git a/wifi/1.6/default/wifi_p2p_iface.cpp b/wifi/aidl/default/wifi_p2p_iface.cpp similarity index 60% rename from wifi/1.6/default/wifi_p2p_iface.cpp rename to wifi/aidl/default/wifi_p2p_iface.cpp index d4b1fcabf1..48ec6d6d87 100644 --- a/wifi/1.6/default/wifi_p2p_iface.cpp +++ b/wifi/aidl/default/wifi_p2p_iface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -14,18 +14,18 @@ * limitations under the License. */ +#include "wifi_p2p_iface.h" + #include -#include "hidl_return_util.h" -#include "wifi_p2p_iface.h" +#include "aidl_return_util.h" #include "wifi_status_util.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using hidl_return_util::validateAndCall; +using aidl_return_util::validateAndCall; WifiP2pIface::WifiP2pIface(const std::string& ifname, const std::weak_ptr legacy_hal) @@ -44,26 +44,16 @@ std::string WifiP2pIface::getName() { return ifname_; } -Return WifiP2pIface::getName(getName_cb hidl_status_cb) { +ndk::ScopedAStatus WifiP2pIface::getName(std::string* _aidl_return) { return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiP2pIface::getNameInternal, hidl_status_cb); + &WifiP2pIface::getNameInternal, _aidl_return); } -Return WifiP2pIface::getType(getType_cb hidl_status_cb) { - return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, - &WifiP2pIface::getTypeInternal, hidl_status_cb); +std::pair WifiP2pIface::getNameInternal() { + return {ifname_, ndk::ScopedAStatus::ok()}; } -std::pair WifiP2pIface::getNameInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; -} - -std::pair WifiP2pIface::getTypeInternal() { - return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::P2P}; -} - -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_p2p_iface.h b/wifi/aidl/default/wifi_p2p_iface.h similarity index 64% rename from wifi/1.6/default/wifi_p2p_iface.h rename to wifi/aidl/default/wifi_p2p_iface.h index 00894437cf..d17470ed23 100644 --- a/wifi/1.6/default/wifi_p2p_iface.h +++ b/wifi/aidl/default/wifi_p2p_iface.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,22 +17,20 @@ #ifndef WIFI_P2P_IFACE_H_ #define WIFI_P2P_IFACE_H_ +#include #include -#include #include "wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; /** - * HIDL interface object used to control a P2P Iface instance. + * AIDL interface object used to control a P2P Iface instance. */ -class WifiP2pIface : public V1_0::IWifiP2pIface { +class WifiP2pIface : public BnWifiP2pIface { public: WifiP2pIface(const std::string& ifname, const std::weak_ptr legacy_hal); @@ -41,14 +39,12 @@ class WifiP2pIface : public V1_0::IWifiP2pIface { bool isValid(); std::string getName(); - // HIDL methods exposed. - Return getName(getName_cb hidl_status_cb) override; - Return getType(getType_cb hidl_status_cb) override; + // AIDL methods exposed. + ndk::ScopedAStatus getName(std::string* _aidl_return) override; private: - // Corresponding worker functions for the HIDL methods. - std::pair getNameInternal(); - std::pair getTypeInternal(); + // Corresponding worker functions for the AIDL methods. + std::pair getNameInternal(); std::string ifname_; std::weak_ptr legacy_hal_; @@ -57,10 +53,9 @@ class WifiP2pIface : public V1_0::IWifiP2pIface { DISALLOW_COPY_AND_ASSIGN(WifiP2pIface); }; -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_P2P_IFACE_H_ diff --git a/wifi/aidl/default/wifi_rtt_controller.cpp b/wifi/aidl/default/wifi_rtt_controller.cpp new file mode 100644 index 0000000000..856c3cd054 --- /dev/null +++ b/wifi/aidl/default/wifi_rtt_controller.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "wifi_rtt_controller.h" + +#include + +#include "aidl_return_util.h" +#include "aidl_struct_util.h" +#include "wifi_status_util.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +using aidl_return_util::validateAndCall; + +WifiRttController::WifiRttController(const std::string& iface_name, + const std::shared_ptr& bound_iface, + const std::weak_ptr legacy_hal) + : ifname_(iface_name), bound_iface_(bound_iface), legacy_hal_(legacy_hal), is_valid_(true) {} + +std::shared_ptr WifiRttController::create( + const std::string& iface_name, const std::shared_ptr& bound_iface, + const std::weak_ptr legacy_hal) { + std::shared_ptr ptr = + ndk::SharedRefBase::make(iface_name, bound_iface, legacy_hal); + std::weak_ptr weak_ptr_this(ptr); + ptr->setWeakPtr(weak_ptr_this); + return ptr; +} + +void WifiRttController::invalidate() { + legacy_hal_.reset(); + event_callbacks_.clear(); + is_valid_ = false; +}; + +bool WifiRttController::isValid() { + return is_valid_; +} + +void WifiRttController::setWeakPtr(std::weak_ptr ptr) { + weak_ptr_this_ = ptr; +} + +std::vector> +WifiRttController::getEventCallbacks() { + return event_callbacks_; +} + +std::string WifiRttController::getIfaceName() { + return ifname_; +} + +ndk::ScopedAStatus WifiRttController::getBoundIface(std::shared_ptr* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::getBoundIfaceInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiRttController::registerEventCallback( + const std::shared_ptr& callback) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::registerEventCallbackInternal, callback); +} + +ndk::ScopedAStatus WifiRttController::rangeRequest(int32_t in_cmdId, + const std::vector& in_rttConfigs) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::rangeRequestInternal, in_cmdId, in_rttConfigs); +} + +ndk::ScopedAStatus WifiRttController::rangeCancel(int32_t in_cmdId, + const std::vector& in_addrs) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::rangeCancelInternal, in_cmdId, in_addrs); +} + +ndk::ScopedAStatus WifiRttController::getCapabilities(RttCapabilities* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::getCapabilitiesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiRttController::setLci(int32_t in_cmdId, const RttLciInformation& in_lci) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::setLciInternal, in_cmdId, in_lci); +} + +ndk::ScopedAStatus WifiRttController::setLcr(int32_t in_cmdId, const RttLcrInformation& in_lcr) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::setLcrInternal, in_cmdId, in_lcr); +} + +ndk::ScopedAStatus WifiRttController::getResponderInfo(RttResponder* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::getResponderInfoInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiRttController::enableResponder(int32_t in_cmdId, + const WifiChannelInfo& in_channelHint, + int32_t in_maxDurationInSeconds, + const RttResponder& in_info) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::enableResponderInternal, in_cmdId, in_channelHint, + in_maxDurationInSeconds, in_info); +} + +ndk::ScopedAStatus WifiRttController::disableResponder(int32_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_RTT_CONTROLLER_INVALID, + &WifiRttController::disableResponderInternal, in_cmdId); +} + +std::pair, ndk::ScopedAStatus> +WifiRttController::getBoundIfaceInternal() { + return {bound_iface_, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiRttController::registerEventCallbackInternal( + const std::shared_ptr& callback) { + event_callbacks_.emplace_back(callback); + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus WifiRttController::rangeRequestInternal( + int32_t cmd_id, const std::vector& rtt_configs) { + 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) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + std::vector aidl_results; + if (!aidl_struct_util::convertLegacyVectorOfRttResultToAidl(results, + &aidl_results)) { + LOG(ERROR) << "Failed to convert rtt results 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 callback"; + } + } + }; + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRttRangeRequest( + ifname_, cmd_id, legacy_configs, on_results_callback); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiRttController::rangeCancelInternal(int32_t cmd_id, + const std::vector& addrs) { + std::vector> legacy_addrs; + for (const auto& addr : addrs) { + std::array addr_array; + std::copy_n(addr.data.begin(), ETH_ALEN, addr_array.begin()); + legacy_addrs.push_back(addr_array); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->cancelRttRangeRequest(ifname_, cmd_id, legacy_addrs); + return createWifiStatusFromLegacyError(legacy_status); +} + +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 {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()}; +} + +ndk::ScopedAStatus WifiRttController::setLciInternal(int32_t cmd_id, const RttLciInformation& lci) { + legacy_hal::wifi_lci_information legacy_lci; + if (!aidl_struct_util::convertAidlRttLciInformationToLegacy(lci, &legacy_lci)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->setRttLci(ifname_, cmd_id, legacy_lci); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiRttController::setLcrInternal(int32_t cmd_id, const RttLcrInformation& lcr) { + legacy_hal::wifi_lcr_information legacy_lcr; + if (!aidl_struct_util::convertAidlRttLcrInformationToLegacy(lcr, &legacy_lcr)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->setRttLcr(ifname_, cmd_id, legacy_lcr); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair WifiRttController::getResponderInfoInternal() { + legacy_hal::wifi_error legacy_status; + legacy_hal::wifi_rtt_responder legacy_responder; + std::tie(legacy_status, legacy_responder) = legacy_hal_.lock()->getRttResponderInfo(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {RttResponder{}, createWifiStatusFromLegacyError(legacy_status)}; + } + RttResponder aidl_responder; + if (!aidl_struct_util::convertLegacyRttResponderToAidl(legacy_responder, &aidl_responder)) { + return {RttResponder{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_responder, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiRttController::enableResponderInternal(int32_t cmd_id, + const WifiChannelInfo& channel_hint, + int32_t max_duration_seconds, + const RttResponder& info) { + legacy_hal::wifi_channel_info legacy_channel_info; + if (!aidl_struct_util::convertAidlWifiChannelInfoToLegacy(channel_hint, &legacy_channel_info)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_rtt_responder legacy_responder; + if (!aidl_struct_util::convertAidlRttResponderToLegacy(info, &legacy_responder)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableRttResponder( + ifname_, cmd_id, legacy_channel_info, max_duration_seconds, legacy_responder); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiRttController::disableResponderInternal(int32_t cmd_id) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableRttResponder(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi_rtt_controller.h b/wifi/aidl/default/wifi_rtt_controller.h new file mode 100644 index 0000000000..db690c3ad3 --- /dev/null +++ b/wifi/aidl/default/wifi_rtt_controller.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_RTT_CONTROLLER_H_ +#define WIFI_RTT_CONTROLLER_H_ + +#include +#include +#include +#include + +#include "wifi_legacy_hal.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * AIDL interface object used to control all RTT operations. + */ +class WifiRttController : public BnWifiRttController { + public: + WifiRttController(const std::string& iface_name, + const std::shared_ptr& bound_iface, + const std::weak_ptr legacy_hal); + // Factory method - use instead of default constructor. + static std::shared_ptr create( + const std::string& iface_name, const std::shared_ptr& bound_iface, + const std::weak_ptr legacy_hal); + + // Refer to |WifiChip::invalidate()|. + void invalidate(); + bool isValid(); + std::vector> getEventCallbacks(); + std::string getIfaceName(); + + // AIDL methods exposed. + ndk::ScopedAStatus getBoundIface(std::shared_ptr* _aidl_return) override; + ndk::ScopedAStatus registerEventCallback( + const std::shared_ptr& callback) override; + ndk::ScopedAStatus rangeRequest(int32_t in_cmdId, + const std::vector& in_rttConfigs) override; + ndk::ScopedAStatus rangeCancel(int32_t in_cmdId, + const std::vector& in_addrs) override; + ndk::ScopedAStatus getCapabilities(RttCapabilities* _aidl_return) override; + ndk::ScopedAStatus setLci(int32_t in_cmdId, const RttLciInformation& in_lci) override; + ndk::ScopedAStatus setLcr(int32_t in_cmdId, const RttLcrInformation& in_lcr) override; + ndk::ScopedAStatus getResponderInfo(RttResponder* _aidl_return) override; + ndk::ScopedAStatus enableResponder(int32_t in_cmdId, const WifiChannelInfo& in_channelHint, + int32_t in_maxDurationInSeconds, + const RttResponder& in_info) override; + ndk::ScopedAStatus disableResponder(int32_t in_cmdId) override; + + private: + // Corresponding worker functions for the AIDL methods. + std::pair, ndk::ScopedAStatus> getBoundIfaceInternal(); + ndk::ScopedAStatus registerEventCallbackInternal( + const std::shared_ptr& callback); + ndk::ScopedAStatus rangeRequestInternal(int32_t cmd_id, + const std::vector& rtt_configs); + ndk::ScopedAStatus rangeCancelInternal(int32_t cmd_id, const std::vector& addrs); + std::pair getCapabilitiesInternal(); + ndk::ScopedAStatus setLciInternal(int32_t cmd_id, const RttLciInformation& lci); + ndk::ScopedAStatus setLcrInternal(int32_t cmd_id, const RttLcrInformation& lcr); + std::pair getResponderInfoInternal(); + ndk::ScopedAStatus enableResponderInternal(int32_t cmd_id, const WifiChannelInfo& channel_hint, + int32_t max_duration_seconds, + const RttResponder& info); + ndk::ScopedAStatus disableResponderInternal(int32_t cmd_id); + + void setWeakPtr(std::weak_ptr ptr); + + std::string ifname_; + std::shared_ptr bound_iface_; + std::weak_ptr legacy_hal_; + std::vector> event_callbacks_; + std::weak_ptr weak_ptr_this_; + bool is_valid_; + + DISALLOW_COPY_AND_ASSIGN(WifiRttController); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_RTT_CONTROLLER_H_ diff --git a/wifi/aidl/default/wifi_sta_iface.cpp b/wifi/aidl/default/wifi_sta_iface.cpp new file mode 100644 index 0000000000..ce90349bc5 --- /dev/null +++ b/wifi/aidl/default/wifi_sta_iface.cpp @@ -0,0 +1,558 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "wifi_sta_iface.h" + +#include + +#include "aidl_return_util.h" +#include "aidl_struct_util.h" +#include "wifi_status_util.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { +using aidl_return_util::validateAndCall; + +WifiStaIface::WifiStaIface(const std::string& ifname, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) + : ifname_(ifname), legacy_hal_(legacy_hal), iface_util_(iface_util), is_valid_(true) { + // Turn on DFS channel usage for STA iface. + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDfsFlag(ifname_, true); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + LOG(ERROR) << "Failed to set DFS flag; DFS channels may be unavailable."; + } +} + +std::shared_ptr WifiStaIface::create( + const std::string& ifname, const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util) { + std::shared_ptr ptr = + ndk::SharedRefBase::make(ifname, legacy_hal, iface_util); + std::weak_ptr weak_ptr_this(ptr); + ptr->setWeakPtr(weak_ptr_this); + return ptr; +} + +void WifiStaIface::invalidate() { + legacy_hal_.reset(); + event_cb_handler_.invalidate(); + is_valid_ = false; +} + +void WifiStaIface::setWeakPtr(std::weak_ptr ptr) { + weak_ptr_this_ = ptr; +} + +bool WifiStaIface::isValid() { + return is_valid_; +} + +std::string WifiStaIface::getName() { + return ifname_; +} + +std::set> WifiStaIface::getEventCallbacks() { + return event_cb_handler_.getCallbacks(); +} + +ndk::ScopedAStatus WifiStaIface::getName(std::string* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getNameInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::registerEventCallback( + const std::shared_ptr& in_callback) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::registerEventCallbackInternal, in_callback); +} + +ndk::ScopedAStatus WifiStaIface::getCapabilities( + IWifiStaIface::StaIfaceCapabilityMask* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getCapabilitiesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::getApfPacketFilterCapabilities( + StaApfPacketFilterCapabilities* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getApfPacketFilterCapabilitiesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::installApfPacketFilter(const std::vector& in_program) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::installApfPacketFilterInternal, in_program); +} + +ndk::ScopedAStatus WifiStaIface::readApfPacketFilterData(std::vector* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::readApfPacketFilterDataInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::getBackgroundScanCapabilities( + StaBackgroundScanCapabilities* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getBackgroundScanCapabilitiesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::getValidFrequenciesForBand(WifiBand in_band, + std::vector* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getValidFrequenciesForBandInternal, _aidl_return, + in_band); +} + +ndk::ScopedAStatus WifiStaIface::startBackgroundScan(int32_t in_cmdId, + const StaBackgroundScanParameters& in_params) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::startBackgroundScanInternal, in_cmdId, in_params); +} + +ndk::ScopedAStatus WifiStaIface::stopBackgroundScan(int32_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::stopBackgroundScanInternal, in_cmdId); +} + +ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollection(bool in_debug) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::enableLinkLayerStatsCollectionInternal, in_debug); +} + +ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollection() { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::disableLinkLayerStatsCollectionInternal); +} + +ndk::ScopedAStatus WifiStaIface::getLinkLayerStats(StaLinkLayerStats* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getLinkLayerStatsInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::startRssiMonitoring(int32_t in_cmdId, int32_t in_maxRssi, + int32_t in_minRssi) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::startRssiMonitoringInternal, in_cmdId, in_maxRssi, + in_minRssi); +} + +ndk::ScopedAStatus WifiStaIface::stopRssiMonitoring(int32_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::stopRssiMonitoringInternal, in_cmdId); +} + +ndk::ScopedAStatus WifiStaIface::getRoamingCapabilities(StaRoamingCapabilities* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getRoamingCapabilitiesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::configureRoaming(const StaRoamingConfig& in_config) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::configureRoamingInternal, in_config); +} + +ndk::ScopedAStatus WifiStaIface::setRoamingState(StaRoamingState in_state) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::setRoamingStateInternal, in_state); +} + +ndk::ScopedAStatus WifiStaIface::enableNdOffload(bool in_enable) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::enableNdOffloadInternal, in_enable); +} + +ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePackets( + int32_t in_cmdId, const std::vector& in_ipPacketData, char16_t in_etherType, + const std::array& in_srcAddress, const std::array& in_dstAddress, + int32_t in_periodInMs) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::startSendingKeepAlivePacketsInternal, in_cmdId, + in_ipPacketData, in_etherType, in_srcAddress, in_dstAddress, + in_periodInMs); +} + +ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePackets(int32_t in_cmdId) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::stopSendingKeepAlivePacketsInternal, in_cmdId); +} + +ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoring() { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::startDebugPacketFateMonitoringInternal); +} + +ndk::ScopedAStatus WifiStaIface::getDebugTxPacketFates( + std::vector* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getDebugTxPacketFatesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::getDebugRxPacketFates( + std::vector* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getDebugRxPacketFatesInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::setMacAddress(const std::array& in_mac) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::setMacAddressInternal, in_mac); +} + +ndk::ScopedAStatus WifiStaIface::getFactoryMacAddress(std::array* _aidl_return) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getFactoryMacAddressInternal, _aidl_return); +} + +ndk::ScopedAStatus WifiStaIface::setScanMode(bool in_enable) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::setScanModeInternal, in_enable); +} + +std::pair WifiStaIface::getNameInternal() { + return {ifname_, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::registerEventCallbackInternal( + const std::shared_ptr& callback) { + if (!event_cb_handler_.addCallback(callback)) { + return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); + } + return ndk::ScopedAStatus::ok(); +} + +std::pair +WifiStaIface::getCapabilitiesInternal() { + legacy_hal::wifi_error legacy_status; + uint64_t legacy_feature_set; + std::tie(legacy_status, legacy_feature_set) = + legacy_hal_.lock()->getSupportedFeatureSet(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {IWifiStaIface::StaIfaceCapabilityMask{}, + createWifiStatusFromLegacyError(legacy_status)}; + } + uint32_t legacy_logger_feature_set; + 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 aidl_caps; + if (!aidl_struct_util::convertLegacyFeaturesToAidlStaCapabilities( + legacy_feature_set, legacy_logger_feature_set, &aidl_caps)) { + return {IWifiStaIface::StaIfaceCapabilityMask{}, + createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {static_cast(aidl_caps), + ndk::ScopedAStatus::ok()}; +} + +std::pair +WifiStaIface::getApfPacketFilterCapabilitiesInternal() { + legacy_hal::wifi_error legacy_status; + legacy_hal::PacketFilterCapabilities legacy_caps; + std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getPacketFilterCapabilities(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {StaApfPacketFilterCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; + } + StaApfPacketFilterCapabilities aidl_caps; + if (!aidl_struct_util::convertLegacyApfCapabilitiesToAidl(legacy_caps, &aidl_caps)) { + return {StaApfPacketFilterCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_caps, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::installApfPacketFilterInternal( + const std::vector& program) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setPacketFilter(ifname_, program); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair, ndk::ScopedAStatus> +WifiStaIface::readApfPacketFilterDataInternal() { + const std::pair> legacy_status_and_data = + legacy_hal_.lock()->readApfPacketFilterData(ifname_); + return {std::move(legacy_status_and_data.second), + createWifiStatusFromLegacyError(legacy_status_and_data.first)}; +} + +std::pair +WifiStaIface::getBackgroundScanCapabilitiesInternal() { + legacy_hal::wifi_error legacy_status; + legacy_hal::wifi_gscan_capabilities legacy_caps; + std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getGscanCapabilities(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {StaBackgroundScanCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; + } + StaBackgroundScanCapabilities aidl_caps; + if (!aidl_struct_util::convertLegacyGscanCapabilitiesToAidl(legacy_caps, &aidl_caps)) { + return {StaBackgroundScanCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_caps, ndk::ScopedAStatus::ok()}; +} + +std::pair, ndk::ScopedAStatus> +WifiStaIface::getValidFrequenciesForBandInternal(WifiBand band) { + static_assert(sizeof(WifiChannelWidthInMhz) == sizeof(int32_t), "Size mismatch"); + legacy_hal::wifi_error legacy_status; + std::vector valid_frequencies; + std::tie(legacy_status, valid_frequencies) = legacy_hal_.lock()->getValidFrequenciesForBand( + ifname_, aidl_struct_util::convertAidlWifiBandToLegacy(band)); + return {std::vector(valid_frequencies.begin(), valid_frequencies.end()), + createWifiStatusFromLegacyError(legacy_status)}; +} + +ndk::ScopedAStatus WifiStaIface::startBackgroundScanInternal( + int32_t cmd_id, const StaBackgroundScanParameters& params) { + legacy_hal::wifi_scan_cmd_params legacy_params; + if (!aidl_struct_util::convertAidlGscanParamsToLegacy(params, &legacy_params)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + std::weak_ptr weak_ptr_this = weak_ptr_this_; + const auto& on_failure_callback = [weak_ptr_this](legacy_hal::wifi_request_id id) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onBackgroundScanFailure(id).isOk()) { + LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; + } + } + }; + 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.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + std::vector aidl_scan_datas; + if (!aidl_struct_util::convertLegacyVectorOfCachedGscanResultsToAidl( + results, &aidl_scan_datas)) { + LOG(ERROR) << "Failed to convert scan results to AIDL structs"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onBackgroundScanResults(id, aidl_scan_datas).isOk()) { + LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; + } + } + }; + const auto& on_full_result_callback = [weak_ptr_this]( + legacy_hal::wifi_request_id id, + const legacy_hal::wifi_scan_result* result, + uint32_t buckets_scanned) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + StaScanResult aidl_scan_result; + if (!aidl_struct_util::convertLegacyGscanResultToAidl(*result, true, &aidl_scan_result)) { + LOG(ERROR) << "Failed to convert full scan results to AIDL structs"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onBackgroundFullScanResult(id, buckets_scanned, aidl_scan_result) + .isOk()) { + LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; + } + } + }; + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->startGscan(ifname_, cmd_id, legacy_params, on_failure_callback, + on_results_callback, on_full_result_callback); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::stopBackgroundScanInternal(int32_t cmd_id) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableLinkLayerStats(ifname_, debug); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableLinkLayerStats(ifname_); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair WifiStaIface::getLinkLayerStatsInternal() { + legacy_hal::wifi_error legacy_status; + legacy_hal::LinkLayerStats legacy_stats; + std::tie(legacy_status, legacy_stats) = legacy_hal_.lock()->getLinkLayerStats(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {StaLinkLayerStats{}, createWifiStatusFromLegacyError(legacy_status)}; + } + StaLinkLayerStats aidl_stats; + if (!aidl_struct_util::convertLegacyLinkLayerStatsToAidl(legacy_stats, &aidl_stats)) { + return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_stats, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi, + int32_t min_rssi) { + std::weak_ptr weak_ptr_this = weak_ptr_this_; + const auto& on_threshold_breached_callback = + [weak_ptr_this](legacy_hal::wifi_request_id id, std::array bssid, + int8_t rssi) { + const auto shared_ptr_this = weak_ptr_this.lock(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { + LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; + } + } + }; + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring( + ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::stopRssiMonitoringInternal(int32_t cmd_id) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair +WifiStaIface::getRoamingCapabilitiesInternal() { + legacy_hal::wifi_error legacy_status; + legacy_hal::wifi_roaming_capabilities legacy_caps; + std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {StaRoamingCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; + } + StaRoamingCapabilities aidl_caps; + if (!aidl_struct_util::convertLegacyRoamingCapabilitiesToAidl(legacy_caps, &aidl_caps)) { + return {StaRoamingCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_caps, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) { + legacy_hal::wifi_roaming_config legacy_config; + if (!aidl_struct_util::convertAidlRoamingConfigToLegacy(config, &legacy_config)) { + return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); + } + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->configureRoaming(ifname_, legacy_config); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming( + ifname_, aidl_struct_util::convertAidlRoamingStateToLegacy(state)); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::enableNdOffloadInternal(bool enable) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePacketsInternal( + int32_t cmd_id, const std::vector& ip_packet_data, char16_t ether_type, + const std::array& src_address, const std::array& dst_address, + int32_t period_in_ms) { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket( + ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(int32_t cmd_id) { + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id); + return createWifiStatusFromLegacyError(legacy_status); +} + +ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { + legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_); + return createWifiStatusFromLegacyError(legacy_status); +} + +std::pair, ndk::ScopedAStatus> +WifiStaIface::getDebugTxPacketFatesInternal() { + legacy_hal::wifi_error legacy_status; + std::vector legacy_fates; + std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {std::vector(), + createWifiStatusFromLegacyError(legacy_status)}; + } + std::vector aidl_fates; + if (!aidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToAidl(legacy_fates, + &aidl_fates)) { + return {std::vector(), + createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_fates, ndk::ScopedAStatus::ok()}; +} + +std::pair, ndk::ScopedAStatus> +WifiStaIface::getDebugRxPacketFatesInternal() { + legacy_hal::wifi_error legacy_status; + std::vector legacy_fates; + std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_); + if (legacy_status != legacy_hal::WIFI_SUCCESS) { + return {std::vector(), + createWifiStatusFromLegacyError(legacy_status)}; + } + std::vector aidl_fates; + if (!aidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToAidl(legacy_fates, + &aidl_fates)) { + return {std::vector(), + createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {aidl_fates, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::setMacAddressInternal(const std::array& mac) { + bool status = iface_util_.lock()->setMacAddress(ifname_, mac); + if (!status) { + return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); + } + return ndk::ScopedAStatus::ok(); +} + +std::pair, ndk::ScopedAStatus> WifiStaIface::getFactoryMacAddressInternal() { + std::array mac = iface_util_.lock()->getFactoryMacAddress(ifname_); + if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) { + return {mac, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; + } + return {mac, ndk::ScopedAStatus::ok()}; +} + +ndk::ScopedAStatus WifiStaIface::setScanModeInternal(bool enable) { + // OEM's need to implement this on their devices if needed. + LOG(WARNING) << "setScanModeInternal(" << enable << ") not supported"; + return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); +} + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/wifi/aidl/default/wifi_sta_iface.h b/wifi/aidl/default/wifi_sta_iface.h new file mode 100644 index 0000000000..8ac3470edb --- /dev/null +++ b/wifi/aidl/default/wifi_sta_iface.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef WIFI_STA_IFACE_H_ +#define WIFI_STA_IFACE_H_ + +#include +#include +#include + +#include "aidl_callback_util.h" +#include "wifi_iface_util.h" +#include "wifi_legacy_hal.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace wifi { + +/** + * AIDL interface object used to control a STA Iface instance. + */ +class WifiStaIface : public BnWifiStaIface { + public: + WifiStaIface(const std::string& ifname, + const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util); + + // Factory method - use instead of default constructor. + static std::shared_ptr create( + const std::string& ifname, const std::weak_ptr legacy_hal, + const std::weak_ptr iface_util); + + // Refer to |WifiChip::invalidate()|. + void invalidate(); + bool isValid(); + std::set> getEventCallbacks(); + std::string getName(); + + // AIDL methods exposed. + ndk::ScopedAStatus getName(std::string* _aidl_return) override; + ndk::ScopedAStatus registerEventCallback( + const std::shared_ptr& in_callback) override; + ndk::ScopedAStatus getCapabilities( + IWifiStaIface::StaIfaceCapabilityMask* _aidl_return) override; + ndk::ScopedAStatus getApfPacketFilterCapabilities( + StaApfPacketFilterCapabilities* _aidl_return) override; + ndk::ScopedAStatus installApfPacketFilter(const std::vector& in_program) override; + ndk::ScopedAStatus readApfPacketFilterData(std::vector* _aidl_return) override; + ndk::ScopedAStatus getBackgroundScanCapabilities( + StaBackgroundScanCapabilities* _aidl_return) override; + ndk::ScopedAStatus getValidFrequenciesForBand(WifiBand in_band, + std::vector* _aidl_return) override; + ndk::ScopedAStatus startBackgroundScan(int32_t in_cmdId, + const StaBackgroundScanParameters& in_params) override; + ndk::ScopedAStatus stopBackgroundScan(int32_t in_cmdId) override; + ndk::ScopedAStatus enableLinkLayerStatsCollection(bool in_debug) override; + ndk::ScopedAStatus disableLinkLayerStatsCollection() override; + ndk::ScopedAStatus getLinkLayerStats(StaLinkLayerStats* _aidl_return) override; + ndk::ScopedAStatus startRssiMonitoring(int32_t in_cmdId, int32_t in_maxRssi, + int32_t in_minRssi) override; + ndk::ScopedAStatus stopRssiMonitoring(int32_t in_cmdId) override; + ndk::ScopedAStatus getRoamingCapabilities(StaRoamingCapabilities* _aidl_return) override; + ndk::ScopedAStatus configureRoaming(const StaRoamingConfig& in_config) override; + ndk::ScopedAStatus setRoamingState(StaRoamingState in_state) override; + ndk::ScopedAStatus enableNdOffload(bool in_enable) override; + ndk::ScopedAStatus startSendingKeepAlivePackets(int32_t in_cmdId, + const std::vector& in_ipPacketData, + char16_t in_etherType, + const std::array& in_srcAddress, + const std::array& in_dstAddress, + int32_t in_periodInMs) override; + ndk::ScopedAStatus stopSendingKeepAlivePackets(int32_t in_cmdId) override; + ndk::ScopedAStatus startDebugPacketFateMonitoring() override; + ndk::ScopedAStatus getDebugTxPacketFates( + std::vector* _aidl_return) override; + ndk::ScopedAStatus getDebugRxPacketFates( + std::vector* _aidl_return) override; + ndk::ScopedAStatus setMacAddress(const std::array& in_mac) override; + ndk::ScopedAStatus getFactoryMacAddress(std::array* _aidl_return) override; + ndk::ScopedAStatus setScanMode(bool in_enable) override; + + private: + // Corresponding worker functions for the AIDL methods. + std::pair getNameInternal(); + ndk::ScopedAStatus registerEventCallbackInternal( + const std::shared_ptr& callback); + std::pair getCapabilitiesInternal(); + std::pair + getApfPacketFilterCapabilitiesInternal(); + ndk::ScopedAStatus installApfPacketFilterInternal(const std::vector& program); + std::pair, ndk::ScopedAStatus> readApfPacketFilterDataInternal(); + std::pair + getBackgroundScanCapabilitiesInternal(); + std::pair, ndk::ScopedAStatus> getValidFrequenciesForBandInternal( + WifiBand band); + ndk::ScopedAStatus startBackgroundScanInternal(int32_t cmd_id, + const StaBackgroundScanParameters& params); + ndk::ScopedAStatus stopBackgroundScanInternal(int32_t cmd_id); + ndk::ScopedAStatus enableLinkLayerStatsCollectionInternal(bool debug); + ndk::ScopedAStatus disableLinkLayerStatsCollectionInternal(); + std::pair getLinkLayerStatsInternal(); + ndk::ScopedAStatus startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi, + int32_t min_rssi); + ndk::ScopedAStatus stopRssiMonitoringInternal(int32_t cmd_id); + std::pair getRoamingCapabilitiesInternal(); + ndk::ScopedAStatus configureRoamingInternal(const StaRoamingConfig& config); + ndk::ScopedAStatus setRoamingStateInternal(StaRoamingState state); + ndk::ScopedAStatus enableNdOffloadInternal(bool enable); + ndk::ScopedAStatus startSendingKeepAlivePacketsInternal( + int32_t cmd_id, const std::vector& ip_packet_data, char16_t ether_type, + const std::array& src_address, const std::array& dst_address, + int32_t period_in_ms); + ndk::ScopedAStatus stopSendingKeepAlivePacketsInternal(int32_t cmd_id); + ndk::ScopedAStatus startDebugPacketFateMonitoringInternal(); + std::pair, ndk::ScopedAStatus> + getDebugTxPacketFatesInternal(); + std::pair, ndk::ScopedAStatus> + getDebugRxPacketFatesInternal(); + ndk::ScopedAStatus setMacAddressInternal(const std::array& mac); + std::pair, ndk::ScopedAStatus> getFactoryMacAddressInternal(); + ndk::ScopedAStatus setScanModeInternal(bool enable); + + void setWeakPtr(std::weak_ptr ptr); + + std::string ifname_; + std::weak_ptr legacy_hal_; + std::weak_ptr iface_util_; + std::weak_ptr weak_ptr_this_; + bool is_valid_; + aidl_callback_util::AidlCallbackHandler event_cb_handler_; + + DISALLOW_COPY_AND_ASSIGN(WifiStaIface); +}; + +} // namespace wifi +} // namespace hardware +} // namespace android +} // namespace aidl + +#endif // WIFI_STA_IFACE_H_ diff --git a/wifi/1.6/default/wifi_status_util.cpp b/wifi/aidl/default/wifi_status_util.cpp similarity index 80% rename from wifi/1.6/default/wifi_status_util.cpp rename to wifi/aidl/default/wifi_status_util.cpp index 3b18e537cd..25ecd716da 100644 --- a/wifi/1.6/default/wifi_status_util.cpp +++ b/wifi/aidl/default/wifi_status_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -16,11 +16,10 @@ #include "wifi_status_util.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { std::string legacyErrorToString(legacy_hal::wifi_error error) { switch (error) { @@ -51,16 +50,21 @@ std::string legacyErrorToString(legacy_hal::wifi_error error) { } } -WifiStatus createWifiStatus(WifiStatusCode code, const std::string& description) { - return {code, description}; +ndk::ScopedAStatus createWifiStatus(WifiStatusCode code, const std::string& description) { + return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(static_cast(code), + description.c_str()); } -WifiStatus createWifiStatus(WifiStatusCode code) { - return createWifiStatus(code, ""); +ndk::ScopedAStatus createWifiStatus(WifiStatusCode code) { + return ndk::ScopedAStatus::fromServiceSpecificError(static_cast(code)); } -WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, const std::string& desc) { +ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, + const std::string& desc) { switch (error) { + case legacy_hal::WIFI_ERROR_NONE: + return ndk::ScopedAStatus::ok(); + case legacy_hal::WIFI_ERROR_UNINITIALIZED: case legacy_hal::WIFI_ERROR_NOT_AVAILABLE: return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc); @@ -84,9 +88,6 @@ WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, const s case legacy_hal::WIFI_ERROR_BUSY: return createWifiStatus(WifiStatusCode::ERROR_BUSY); - case legacy_hal::WIFI_ERROR_NONE: - return createWifiStatus(WifiStatusCode::SUCCESS, desc); - case legacy_hal::WIFI_ERROR_UNKNOWN: return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown"); @@ -95,12 +96,11 @@ WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, const s } } -WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) { +ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) { return createWifiStatusFromLegacyError(error, ""); } -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl diff --git a/wifi/1.6/default/wifi_status_util.h b/wifi/aidl/default/wifi_status_util.h similarity index 59% rename from wifi/1.6/default/wifi_status_util.h rename to wifi/aidl/default/wifi_status_util.h index ea1c29486b..633811dbf6 100644 --- a/wifi/1.6/default/wifi_status_util.h +++ b/wifi/aidl/default/wifi_status_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2022 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. @@ -17,28 +17,26 @@ #ifndef WIFI_STATUS_UTIL_H_ #define WIFI_STATUS_UTIL_H_ -#include +#include #include "wifi_legacy_hal.h" +namespace aidl { namespace android { namespace hardware { namespace wifi { -namespace V1_6 { -namespace implementation { -using namespace android::hardware::wifi::V1_0; +using ::aidl::android::hardware::wifi::WifiStatusCode; std::string legacyErrorToString(legacy_hal::wifi_error error); -WifiStatus createWifiStatus(WifiStatusCode code, const std::string& description); -WifiStatus createWifiStatus(WifiStatusCode code); -WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, - const std::string& description); -WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error); +ndk::ScopedAStatus createWifiStatus(WifiStatusCode code, const std::string& description); +ndk::ScopedAStatus createWifiStatus(WifiStatusCode code); +ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, + const std::string& description); +ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error); -} // namespace implementation -} // namespace V1_6 } // namespace wifi } // namespace hardware } // namespace android +} // namespace aidl #endif // WIFI_STATUS_UTIL_H_ diff --git a/wifi/aidl/vts/functional/Android.bp b/wifi/aidl/vts/functional/Android.bp new file mode 100644 index 0000000000..1277182493 --- /dev/null +++ b/wifi/aidl/vts/functional/Android.bp @@ -0,0 +1,169 @@ +// +// Copyright (C) 2022 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 { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +cc_test { + name: "VtsHalWifiChipTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: [ + "wifi_chip_aidl_test.cpp", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libvndksupport", + ], + static_libs: [ + "VtsHalWifiTargetTestUtil", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], + test_suites: [ + "general-tests", + "vts", + ], +} + +cc_test { + name: "VtsHalWifiStaIfaceTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: [ + "wifi_sta_iface_aidl_test.cpp", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libvndksupport", + ], + static_libs: [ + "VtsHalWifiTargetTestUtil", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], + test_suites: [ + "general-tests", + "vts", + ], +} + +cc_test { + name: "VtsHalWifiApIfaceTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: [ + "wifi_ap_iface_aidl_test.cpp", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libvndksupport", + ], + static_libs: [ + "VtsHalWifiTargetTestUtil", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], + test_suites: [ + "general-tests", + "vts", + ], +} + +cc_test { + name: "VtsHalWifiNanIfaceTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: [ + "wifi_nan_iface_aidl_test.cpp", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libvndksupport", + ], + static_libs: [ + "VtsHalWifiTargetTestUtil", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], + test_suites: [ + "general-tests", + "vts", + ], +} + +cc_test { + name: "VtsHalWifiRttControllerTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: [ + "wifi_rtt_controller_aidl_test.cpp", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libvndksupport", + ], + static_libs: [ + "VtsHalWifiTargetTestUtil", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], + test_suites: [ + "general-tests", + "vts", + ], +} + +cc_library_static { + name: "VtsHalWifiTargetTestUtil", + defaults: ["VtsHalTargetTestDefaults"], + srcs: [ + "wifi_aidl_test_utils.cpp", + ], + export_include_dirs: [ + ".", + ], + shared_libs: [ + "libbinder", + "libbinder_ndk", + "libnativehelper", + ], + static_libs: [ + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + ], +} diff --git a/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp b/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp new file mode 100644 index 0000000000..6722f36dc9 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "wifi_aidl_test_utils.h" + +using ::android::wifi_system::InterfaceTool; + +namespace { +bool findAnyModeSupportingConcurrencyType(IfaceConcurrencyType desired_type, + const std::vector& modes, + int* mode_id) { + for (const auto& mode : modes) { + for (const auto& combination : mode.availableCombinations) { + for (const auto& iface_limit : combination.limits) { + const auto& iface_types = iface_limit.types; + if (std::find(iface_types.begin(), iface_types.end(), desired_type) != + iface_types.end()) { + *mode_id = mode.id; + return true; + } + } + } + } + return false; +} + +bool configureChipToSupportConcurrencyTypeInternal(const std::shared_ptr& wifi_chip, + IfaceConcurrencyType type, + int* configured_mode_id) { + if (!configured_mode_id) { + return false; + } + std::vector chip_modes; + auto status = wifi_chip->getAvailableModes(&chip_modes); + if (!status.isOk()) { + return false; + } + if (!findAnyModeSupportingConcurrencyType(type, chip_modes, configured_mode_id)) { + return false; + } + if (!wifi_chip->configureChip(*configured_mode_id).isOk()) { + return false; + } + return true; +} + +bool configureChipToSupportConcurrencyTypeInternal(const std::shared_ptr& wifi_chip, + IfaceConcurrencyType type) { + int mode_id; + return configureChipToSupportConcurrencyTypeInternal(wifi_chip, type, &mode_id); +} +} // namespace + +bool checkStatusCode(ndk::ScopedAStatus* status, WifiStatusCode expected_code) { + if (status == nullptr) { + return false; + } + return status->getServiceSpecificError() == static_cast(expected_code); +} + +std::shared_ptr getWifi(const char* instance_name) { + return IWifi::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService(instance_name))); +} + +std::shared_ptr getWifiChip(const char* instance_name) { + std::shared_ptr wifi = getWifi(instance_name); + if (!wifi.get()) { + return nullptr; + } + + const int retry_interval_ms = 2; + const int max_retries = 5; + int retry_count = 0; + auto status = wifi->start(); + while (retry_count < max_retries && !status.isOk()) { + retry_count++; + usleep(retry_interval_ms * 1000); + status = wifi->start(); + } + if (!status.isOk()) { + return nullptr; + } + + std::vector chip_ids = {}; + status = wifi->getChipIds(&chip_ids); + if (!status.isOk() || chip_ids.size() == 0) { + return nullptr; + } + std::shared_ptr chip; + status = wifi->getChip(chip_ids[0], &chip); + if (!status.isOk()) { + return nullptr; + } + return chip; +} + +void setupStaIface(const std::shared_ptr& iface) { + std::string iface_name; + auto status = iface->getName(&iface_name); + if (status.isOk()) { + InterfaceTool iface_tool; + iface_tool.SetUpState(iface_name.c_str(), true); + } +} + +void setupNanIface(const std::shared_ptr& iface) { + std::string iface_name; + auto status = iface->getName(&iface_name); + if (status.isOk()) { + InterfaceTool iface_tool; + iface_tool.SetUpState(iface_name.c_str(), true); + } +} + +std::shared_ptr getWifiStaIface(const char* instance_name) { + std::shared_ptr wifi_chip = getWifiChip(instance_name); + if (!wifi_chip.get()) { + return nullptr; + } + if (!configureChipToSupportConcurrencyTypeInternal(wifi_chip, IfaceConcurrencyType::STA)) { + return nullptr; + } + std::shared_ptr iface; + auto status = wifi_chip->createStaIface(&iface); + if (!status.isOk()) { + return nullptr; + } + setupStaIface(iface); + return iface; +} + +std::shared_ptr getWifiNanIface(const char* instance_name) { + std::shared_ptr wifi_chip = getWifiChip(instance_name); + if (!wifi_chip.get()) { + return nullptr; + } + if (!configureChipToSupportConcurrencyTypeInternal(wifi_chip, + IfaceConcurrencyType::NAN_IFACE)) { + return nullptr; + } + std::shared_ptr iface; + auto status = wifi_chip->createNanIface(&iface); + if (!status.isOk()) { + return nullptr; + } + setupNanIface(iface); + return iface; +} + +std::shared_ptr getWifiApIface(const char* instance_name) { + std::shared_ptr wifi_chip = getWifiChip(instance_name); + if (!wifi_chip.get()) { + return nullptr; + } + if (!configureChipToSupportConcurrencyTypeInternal(wifi_chip, IfaceConcurrencyType::AP)) { + return nullptr; + } + std::shared_ptr iface; + auto status = wifi_chip->createApIface(&iface); + if (!status.isOk()) { + return nullptr; + } + return iface; +} + +std::shared_ptr getBridgedWifiApIface(std::shared_ptr wifi_chip) { + if (!wifi_chip.get()) { + return nullptr; + } + int mode_id; + std::shared_ptr iface; + configureChipToSupportConcurrencyTypeInternal(wifi_chip, IfaceConcurrencyType::AP, &mode_id); + auto status = wifi_chip->createBridgedApIface(&iface); + if (!status.isOk()) { + return nullptr; + } + return iface; +} + +std::shared_ptr getBridgedWifiApIface(const char* instance_name) { + std::shared_ptr wifi_chip = getWifiChip(instance_name); + return getBridgedWifiApIface(wifi_chip); +} + +bool configureChipToSupportConcurrencyType(const std::shared_ptr& wifi_chip, + IfaceConcurrencyType type, int* configured_mode_id) { + return configureChipToSupportConcurrencyTypeInternal(wifi_chip, type, configured_mode_id); +} + +void stopWifiService(const char* instance_name) { + std::shared_ptr wifi = getWifi(instance_name); + if (wifi != nullptr) { + wifi->stop(); + } +} + +int32_t getChipCapabilities(const std::shared_ptr& wifi_chip) { + IWifiChip::ChipCapabilityMask caps = {}; + if (wifi_chip->getCapabilities(&caps).isOk()) { + return static_cast(caps); + } + return 0; +} diff --git a/wifi/aidl/vts/functional/wifi_aidl_test_utils.h b/wifi/aidl/vts/functional/wifi_aidl_test_utils.h new file mode 100644 index 0000000000..ad16603dd3 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_aidl_test_utils.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 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. + */ + +#pragma once + +#include + +#include +#include +#include +#include + +using aidl::android::hardware::wifi::IfaceConcurrencyType; +using aidl::android::hardware::wifi::IWifi; +using aidl::android::hardware::wifi::IWifiApIface; +using aidl::android::hardware::wifi::IWifiChip; +using aidl::android::hardware::wifi::IWifiNanIface; +using aidl::android::hardware::wifi::IWifiStaIface; +using aidl::android::hardware::wifi::WifiStatusCode; + +// Helper functions to obtain references to the various AIDL interface objects. +std::shared_ptr getWifi(const char* instance_name); +std::shared_ptr getWifiChip(const char* instance_name); +std::shared_ptr getWifiStaIface(const char* instance_name); +std::shared_ptr getWifiNanIface(const char* instance_name); +std::shared_ptr getWifiApIface(const char* instance_name); +std::shared_ptr getBridgedWifiApIface(const char* instance_name); +std::shared_ptr getBridgedWifiApIface(std::shared_ptr wifi_chip); +// Configure the chip in a mode to support the creation of the provided iface type. +bool configureChipToSupportConcurrencyType(const std::shared_ptr& wifi_chip, + IfaceConcurrencyType type, int* configured_mode_id); +// Used to trigger IWifi.stop() at the end of every test. +void stopWifiService(const char* instance_name); +int32_t getChipCapabilities(const std::shared_ptr& wifi_chip); +bool checkStatusCode(ndk::ScopedAStatus* status, WifiStatusCode expected_code); diff --git a/wifi/aidl/vts/functional/wifi_ap_iface_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_ap_iface_aidl_test.cpp new file mode 100644 index 0000000000..0eaf660d49 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_ap_iface_aidl_test.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Staache 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using aidl::android::hardware::wifi::IWifiApIface; +using aidl::android::hardware::wifi::WifiBand; + +class WifiApIfaceAidlTest : public testing::TestWithParam { + public: + void SetUp() override { + isBridgedSupport_ = testing::checkSubstringInCommandOutput( + "/system/bin/cmd wifi get-softap-supported-features", + "wifi_softap_bridged_ap_supported"); + stopWifiService(getInstanceName()); + } + + void TearDown() override { stopWifiService(getInstanceName()); } + + protected: + bool isBridgedSupport_ = false; + const char* getInstanceName() { return GetParam().c_str(); } +}; + +/* + * SetMacAddress + */ +TEST_P(WifiApIfaceAidlTest, SetMacAddress) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + std::array mac = {0x12, 0x22, 0x33, 0x52, 0x10, 0x44}; + EXPECT_TRUE(wifi_ap_iface->setMacAddress(mac).isOk()); +} + +/* + * SetCountryCode + */ +TEST_P(WifiApIfaceAidlTest, SetCountryCode) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + const std::array country_code = {0x55, 0x53}; + EXPECT_TRUE(wifi_ap_iface->setCountryCode(country_code).isOk()); +} + +/* + * GetValidFrequenciesForBand + * Ensures that we can retrieve valid frequencies for the 2.4 GHz band. + */ +TEST_P(WifiApIfaceAidlTest, GetValidFrequenciesForBand) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + std::vector freqs; + EXPECT_TRUE(wifi_ap_iface->getValidFrequenciesForBand(WifiBand::BAND_24GHZ, &freqs).isOk()); + EXPECT_NE(freqs.size(), 0); +} + +/* + * GetFactoryMacAddress + */ +TEST_P(WifiApIfaceAidlTest, GetFactoryMacAddress) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + std::array mac; + EXPECT_TRUE(wifi_ap_iface->getFactoryMacAddress(&mac).isOk()); + std::array all_zero_mac = {0, 0, 0, 0, 0, 0}; + EXPECT_NE(mac, all_zero_mac); +} + +/** + * GetBridgedInstances - non-bridged mode + */ +TEST_P(WifiApIfaceAidlTest, GetBridgedInstances) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + std::vector instances; + EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk()); + EXPECT_EQ(instances.size(), 0); +} + +/** + * GetBridgedInstances - bridged AP mode. + */ +TEST_P(WifiApIfaceAidlTest, GetBridgedInstances_Bridged) { + if (!isBridgedSupport_) { + GTEST_SKIP() << "Missing Bridged AP support"; + } + std::shared_ptr wifi_ap_iface = getBridgedWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + std::vector instances; + EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk()); + EXPECT_EQ(instances.size(), 2); +} + +/** + * ResetToFactoryMacAddress - non-bridged mode + */ +TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress) { + std::shared_ptr wifi_ap_iface = getWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk()); +} + +/** + * ResetToFactoryMacAddress - bridged AP mode + */ +TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress_Bridged) { + if (!isBridgedSupport_) { + GTEST_SKIP() << "Missing Bridged AP support"; + } + std::shared_ptr wifi_ap_iface = getBridgedWifiApIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk()); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceAidlTest); +INSTANTIATE_TEST_SUITE_P(WifiTest, WifiApIfaceAidlTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + android::ProcessState::self()->setThreadPoolMaxThreadCount(1); + android::ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} diff --git a/wifi/aidl/vts/functional/wifi_chip_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_chip_aidl_test.cpp new file mode 100644 index 0000000000..0806ed289d --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_chip_aidl_test.cpp @@ -0,0 +1,889 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Staache 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. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using aidl::android::hardware::wifi::BnWifiChipEventCallback; +using aidl::android::hardware::wifi::IfaceType; +using aidl::android::hardware::wifi::IWifiApIface; +using aidl::android::hardware::wifi::IWifiChip; +using aidl::android::hardware::wifi::IWifiNanIface; +using aidl::android::hardware::wifi::IWifiP2pIface; +using aidl::android::hardware::wifi::IWifiRttController; +using aidl::android::hardware::wifi::WifiBand; +using aidl::android::hardware::wifi::WifiDebugHostWakeReasonStats; +using aidl::android::hardware::wifi::WifiDebugRingBufferStatus; +using aidl::android::hardware::wifi::WifiDebugRingBufferVerboseLevel; +using aidl::android::hardware::wifi::WifiIfaceMode; +using aidl::android::hardware::wifi::WifiRadioCombinationMatrix; +using aidl::android::hardware::wifi::WifiStatusCode; +using aidl::android::hardware::wifi::WifiUsableChannel; + +class WifiChipAidlTest : public testing::TestWithParam { + public: + void SetUp() override { + stopWifiService(getInstanceName()); + wifi_chip_ = getWifiChip(getInstanceName()); + ASSERT_NE(nullptr, wifi_chip_.get()); + } + + void TearDown() override { stopWifiService(getInstanceName()); } + + protected: + int configureChipForConcurrencyType(IfaceConcurrencyType type) { + int mode_id; + EXPECT_TRUE(configureChipToSupportConcurrencyType(wifi_chip_, type, &mode_id)); + return mode_id; + } + + std::shared_ptr configureChipForStaAndGetIface() { + std::shared_ptr iface; + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + EXPECT_TRUE(wifi_chip_->createStaIface(&iface).isOk()); + EXPECT_NE(nullptr, iface.get()); + return iface; + } + + std::shared_ptr configureChipForP2pAndGetIface() { + std::shared_ptr iface; + configureChipForConcurrencyType(IfaceConcurrencyType::P2P); + EXPECT_TRUE(wifi_chip_->createP2pIface(&iface).isOk()); + EXPECT_NE(nullptr, iface.get()); + return iface; + } + + std::shared_ptr configureChipForApAndGetIface() { + std::shared_ptr iface; + configureChipForConcurrencyType(IfaceConcurrencyType::AP); + EXPECT_TRUE(wifi_chip_->createApIface(&iface).isOk()); + EXPECT_NE(nullptr, iface.get()); + return iface; + } + + std::shared_ptr configureChipForNanAndGetIface() { + std::shared_ptr iface; + configureChipForConcurrencyType(IfaceConcurrencyType::NAN_IFACE); + EXPECT_TRUE(wifi_chip_->createNanIface(&iface).isOk()); + EXPECT_NE(nullptr, iface.get()); + return iface; + } + + std::string getStaIfaceName(const std::shared_ptr& iface) { + std::string iface_name; + EXPECT_TRUE(iface->getName(&iface_name).isOk()); + return iface_name; + } + + std::string getP2pIfaceName(const std::shared_ptr& iface) { + std::string iface_name; + EXPECT_TRUE(iface->getName(&iface_name).isOk()); + return iface_name; + } + + std::string getApIfaceName(const std::shared_ptr& iface) { + std::string iface_name; + EXPECT_TRUE(iface->getName(&iface_name).isOk()); + return iface_name; + } + + std::string getNanIfaceName(const std::shared_ptr& iface) { + std::string iface_name; + EXPECT_TRUE(iface->getName(&iface_name).isOk()); + return iface_name; + } + + std::vector> create2StaIfacesIfPossible() { + std::shared_ptr iface1 = configureChipForStaAndGetIface(); + + // Try create a create second iface. + std::shared_ptr iface2; + bool add_second_success = wifi_chip_->createStaIface(&iface2).isOk(); + if (!add_second_success) { + return {iface1}; + } + EXPECT_NE(nullptr, iface2.get()); + return {iface1, iface2}; + } + + bool hasAnyRingBufferCapabilities(int32_t caps) { + return caps & + (static_cast( + IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_CONNECT_EVENT) | + static_cast(IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_POWER_EVENT) | + static_cast( + IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_WAKELOCK_EVENT) | + static_cast(IWifiChip::ChipCapabilityMask::DEBUG_RING_BUFFER_VENDOR_DATA)); + } + + const char* getInstanceName() { return GetParam().c_str(); } + + std::shared_ptr wifi_chip_; +}; + +class WifiChipEventCallback : public BnWifiChipEventCallback { + public: + WifiChipEventCallback() = default; + + ::ndk::ScopedAStatus onChipReconfigureFailure(WifiStatusCode /* status */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onChipReconfigured(int /* modeId */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onDebugErrorAlert(int /* errorCode */, + const std::vector& /* debugData */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onDebugRingBufferDataAvailable( + const WifiDebugRingBufferStatus& /* status */, + const std::vector& /* data */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onIfaceAdded(IfaceType /* type */, + const std::string& /* name */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onIfaceRemoved(IfaceType /* type */, + const std::string& /* name */) override { + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onRadioModeChange( + const std::vector& /* radioModeInfos */) override { + return ndk::ScopedAStatus::ok(); + } +}; + +/* + * RegisterEventCallback + * + * Note: it is not feasible to test the invocation of the callback function, + * since events are triggered internally in the HAL implementation and cannot be + * triggered from the test case. + */ +TEST_P(WifiChipAidlTest, RegisterEventCallback) { + std::shared_ptr callback = + ndk::SharedRefBase::make(); + ASSERT_NE(nullptr, callback.get()); + EXPECT_TRUE(wifi_chip_->registerEventCallback(callback).isOk()); +} + +/* + * GetCapabilities + */ +TEST_P(WifiChipAidlTest, GetCapabilities) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + EXPECT_NE(static_cast(caps), 0); +} + +/* + * GetId + */ +TEST_P(WifiChipAidlTest, GetId) { + int id; + EXPECT_TRUE(wifi_chip_->getId(&id).isOk()); +} + +/* + * GetAvailableModes + */ +TEST_P(WifiChipAidlTest, GetAvailableModes) { + std::vector modes; + EXPECT_TRUE(wifi_chip_->getAvailableModes(&modes).isOk()); + EXPECT_NE(modes.size(), 0); +} + +/* + * GetMode + */ +TEST_P(WifiChipAidlTest, GetMode) { + int expected_mode = configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int retrieved_mode; + EXPECT_TRUE(wifi_chip_->getMode(&retrieved_mode).isOk()); + EXPECT_EQ(retrieved_mode, expected_mode); +} + +/* + * GetUsableChannels + */ +TEST_P(WifiChipAidlTest, GetUsableChannels) { + WifiBand band = WifiBand::BAND_24GHZ_5GHZ_6GHZ; + uint32_t ifaceModeMask = static_cast(WifiIfaceMode::IFACE_MODE_P2P_CLIENT) | + static_cast(WifiIfaceMode::IFACE_MODE_P2P_GO); + uint32_t filterMask = + static_cast(IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE) | + static_cast(IWifiChip::UsableChannelFilter::CONCURRENCY); + + std::vector channels; + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + auto status = wifi_chip_->getUsableChannels( + band, static_cast(ifaceModeMask), + static_cast(filterMask), &channels); + if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + GTEST_SKIP() << "getUsableChannels() is not supported by vendor."; + } + EXPECT_TRUE(status.isOk()); +} + +/* + * GetSupportedRadioCombinationsMatrix + */ +TEST_P(WifiChipAidlTest, GetSupportedRadioCombinationsMatrix) { + WifiRadioCombinationMatrix combination_matrix = {}; + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + auto status = wifi_chip_->getSupportedRadioCombinationsMatrix(&combination_matrix); + if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + GTEST_SKIP() << "Skipping this test since getSupportedRadioCombinationsMatrix() " + "is not supported by vendor."; + } + EXPECT_TRUE(status.isOk()); +} + +/* + * SetCountryCode + */ +TEST_P(WifiChipAidlTest, SetCountryCode) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + std::array country_code = {0x55, 0x53}; + EXPECT_TRUE(wifi_chip_->setCountryCode(country_code).isOk()); +} + +/* + * SetLatencyMode_normal + * Tests the setLatencyMode() API with Latency mode NORMAL. + */ +TEST_P(WifiChipAidlTest, SetLatencyMode_normal) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + auto status = wifi_chip_->setLatencyMode(IWifiChip::LatencyMode::NORMAL); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SetLatencyMode_low + * Tests the setLatencyMode() API with Latency mode LOW. + */ +TEST_P(WifiChipAidlTest, SetLatencyMode_low) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + auto status = wifi_chip_->setLatencyMode(IWifiChip::LatencyMode::LOW); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SetMultiStaPrimaryConnection + * + * Only runs if the device supports 2 STA ifaces. + */ +TEST_P(WifiChipAidlTest, SetMultiStaPrimaryConnection) { + auto ifaces = create2StaIfacesIfPossible(); + if (ifaces.size() < 2) { + GTEST_SKIP() << "Device does not support more than 1 STA concurrently"; + } + + auto status = wifi_chip_->setMultiStaPrimaryConnection(getStaIfaceName(ifaces[0])); + if (!status.isOk()) { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SetMultiStaUseCase + * + * Only runs if the device supports 2 STA ifaces. + */ +TEST_P(WifiChipAidlTest, setMultiStaUseCase) { + auto ifaces = create2StaIfacesIfPossible(); + if (ifaces.size() < 2) { + GTEST_SKIP() << "Device does not support more than 1 STA concurrently"; + } + + auto status = wifi_chip_->setMultiStaUseCase( + IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY); + if (!status.isOk()) { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SetCoexUnsafeChannels + */ +TEST_P(WifiChipAidlTest, SetCoexUnsafeChannels) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + + // Test with an empty vector of CoexUnsafeChannels. + std::vector vec; + IWifiChip::CoexRestriction restrictions = static_cast(0); + auto status = wifi_chip_->setCoexUnsafeChannels(vec, restrictions); + if (!status.isOk()) { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } + + // Test with a non-empty vector of CoexUnsafeChannels. + IWifiChip::CoexUnsafeChannel unsafeChannel24Ghz; + unsafeChannel24Ghz.band = WifiBand::BAND_24GHZ; + unsafeChannel24Ghz.channel = 6; + vec.push_back(unsafeChannel24Ghz); + IWifiChip::CoexUnsafeChannel unsafeChannel5Ghz; + unsafeChannel5Ghz.band = WifiBand::BAND_5GHZ; + unsafeChannel5Ghz.channel = 36; + vec.push_back(unsafeChannel5Ghz); + restrictions = static_cast( + static_cast(IWifiChip::CoexRestriction::WIFI_AWARE) | + static_cast(IWifiChip::CoexRestriction::SOFTAP) | + static_cast(IWifiChip::CoexRestriction::WIFI_DIRECT)); + + status = wifi_chip_->setCoexUnsafeChannels(vec, restrictions); + if (!status.isOk()) { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SelectTxPowerScenario - Body + */ +TEST_P(WifiChipAidlTest, SelectTxPowerScenario_body) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + int32_t expected_caps = + static_cast(IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT) | + static_cast(IWifiChip::ChipCapabilityMask::USE_BODY_HEAD_SAR); + auto status = wifi_chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF); + if (caps & expected_caps) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * SelectTxPowerScenario - Voice Call + */ +TEST_P(WifiChipAidlTest, SelectTxPowerScenario_voiceCall) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + auto status = wifi_chip_->selectTxPowerScenario(IWifiChip::TxPowerScenario::VOICE_CALL); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * ResetTxPowerScenario + */ +TEST_P(WifiChipAidlTest, ResetTxPowerScenario) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + auto status = wifi_chip_->resetTxPowerScenario(); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * ConfigureChip + */ +TEST_P(WifiChipAidlTest, ConfigureChip) { + std::vector modes; + EXPECT_TRUE(wifi_chip_->getAvailableModes(&modes).isOk()); + EXPECT_NE(modes.size(), 0); + for (const auto& mode : modes) { + // configureChip() requires a fresh IWifiChip object. + wifi_chip_ = getWifiChip(getInstanceName()); + ASSERT_NE(nullptr, wifi_chip_.get()); + EXPECT_TRUE(wifi_chip_->configureChip(mode.id).isOk()); + stopWifiService(getInstanceName()); + // Sleep for 5 milliseconds between each wifi state toggle. + usleep(5000); + } +} + +/* + * RequestChipDebugInfo + */ +TEST_P(WifiChipAidlTest, RequestChipDebugInfo) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + IWifiChip::ChipDebugInfo debug_info = {}; + EXPECT_TRUE(wifi_chip_->requestChipDebugInfo(&debug_info).isOk()); + EXPECT_NE(debug_info.driverDescription.size(), 0); + EXPECT_NE(debug_info.firmwareDescription.size(), 0); +} + +/* + * RequestFirmwareDebugDump + */ +TEST_P(WifiChipAidlTest, RequestFirmwareDebugDump) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + std::vector debug_dump; + auto status = wifi_chip_->requestFirmwareDebugDump(&debug_dump); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::DEBUG_MEMORY_FIRMWARE_DUMP)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * RequestDriverDebugDump + */ +TEST_P(WifiChipAidlTest, RequestDriverDebugDump) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + std::vector debug_dump; + auto status = wifi_chip_->requestDriverDebugDump(&debug_dump); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::DEBUG_MEMORY_DRIVER_DUMP)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * GetDebugRingBuffersStatus + */ +TEST_P(WifiChipAidlTest, GetDebugRingBuffersStatus) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + std::vector ring_buffer_status; + auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status); + if (hasAnyRingBufferCapabilities(caps)) { + EXPECT_TRUE(status.isOk()); + ASSERT_NE(ring_buffer_status.size(), 0); + for (const auto& ring_buffer : ring_buffer_status) { + EXPECT_NE(ring_buffer.ringName.size(), 0); + } + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * GetDebugHostWakeReasonStats + */ +TEST_P(WifiChipAidlTest, GetDebugHostWakeReasonStats) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + WifiDebugHostWakeReasonStats wake_reason_stats = {}; + auto status = wifi_chip_->getDebugHostWakeReasonStats(&wake_reason_stats); + if (caps & static_cast(IWifiChip::ChipCapabilityMask::DEBUG_HOST_WAKE_REASON_STATS)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * StartLoggingToDebugRingBuffer + */ +TEST_P(WifiChipAidlTest, StartLoggingToDebugRingBuffer) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + std::string ring_name; + std::vector ring_buffer_status; + auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status); + + if (hasAnyRingBufferCapabilities(caps)) { + EXPECT_TRUE(status.isOk()); + ASSERT_NE(ring_buffer_status.size(), 0); + ring_name = ring_buffer_status[0].ringName; + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } + + status = wifi_chip_->startLoggingToDebugRingBuffer( + ring_name, WifiDebugRingBufferVerboseLevel::VERBOSE, 5, 1024); + if (hasAnyRingBufferCapabilities(caps)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * ForceDumpToDebugRingBuffer + */ +TEST_P(WifiChipAidlTest, ForceDumpToDebugRingBuffer) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + int32_t caps = getChipCapabilities(wifi_chip_); + std::string ring_name; + std::vector ring_buffer_status; + auto status = wifi_chip_->getDebugRingBuffersStatus(&ring_buffer_status); + + if (hasAnyRingBufferCapabilities(caps)) { + EXPECT_TRUE(status.isOk()); + ASSERT_NE(ring_buffer_status.size(), 0); + ring_name = ring_buffer_status[0].ringName; + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } + + status = wifi_chip_->forceDumpToDebugRingBuffer(ring_name); + if (hasAnyRingBufferCapabilities(caps)) { + EXPECT_TRUE(status.isOk()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/* + * CreateStaIface + * Configures the chip in STA mode and creates an iface. + */ +TEST_P(WifiChipAidlTest, CreateStaIface) { + configureChipForStaAndGetIface(); +} + +/* + * CreateApIface + */ +TEST_P(WifiChipAidlTest, CreateApIface) { + configureChipForApAndGetIface(); +} + +/* + * CreateNanIface + */ +TEST_P(WifiChipAidlTest, CreateNanIface) { + configureChipForNanAndGetIface(); +} + +/* + * CreateP2pIface + */ +TEST_P(WifiChipAidlTest, CreateP2pIface) { + configureChipForNanAndGetIface(); +} + +/* + * GetStaIfaceNames + * Configures the chip in STA mode and ensures that the iface name list is + * empty before creating the iface. Then create the iface and ensure that + * iface name is returned in the iface name list. + */ +TEST_P(WifiChipAidlTest, GetStaIfaceNames) { + configureChipForConcurrencyType(IfaceConcurrencyType::STA); + + std::vector iface_names; + EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); + + std::shared_ptr iface; + EXPECT_TRUE(wifi_chip_->createStaIface(&iface).isOk()); + ASSERT_NE(nullptr, iface.get()); + + std::string iface_name = getStaIfaceName(iface); + EXPECT_TRUE(wifi_chip_->getStaIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 1); + EXPECT_EQ(iface_name, iface_names[0]); + + EXPECT_TRUE(wifi_chip_->removeStaIface(iface_name).isOk()); + EXPECT_TRUE(wifi_chip_->getStaIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); +} + +/* + * GetP2pIfaceNames + */ +TEST_P(WifiChipAidlTest, GetP2pIfaceNames) { + configureChipForConcurrencyType(IfaceConcurrencyType::P2P); + + std::vector iface_names; + EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); + + std::shared_ptr iface; + EXPECT_TRUE(wifi_chip_->createP2pIface(&iface).isOk()); + ASSERT_NE(nullptr, iface.get()); + + std::string iface_name = getP2pIfaceName(iface); + EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 1); + EXPECT_EQ(iface_name, iface_names[0]); + + EXPECT_TRUE(wifi_chip_->removeP2pIface(iface_name).isOk()); + EXPECT_TRUE(wifi_chip_->getP2pIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); +} + +/* + * GetApIfaceNames + */ +TEST_P(WifiChipAidlTest, GetApIfaceNames) { + configureChipForConcurrencyType(IfaceConcurrencyType::AP); + + std::vector iface_names; + EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); + + std::shared_ptr iface; + EXPECT_TRUE(wifi_chip_->createApIface(&iface).isOk()); + ASSERT_NE(nullptr, iface.get()); + + std::string iface_name = getApIfaceName(iface); + EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 1); + EXPECT_EQ(iface_name, iface_names[0]); + + EXPECT_TRUE(wifi_chip_->removeApIface(iface_name).isOk()); + EXPECT_TRUE(wifi_chip_->getApIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); +} + +/* + * GetNanIfaceNames + */ +TEST_P(WifiChipAidlTest, GetNanIfaceNames) { + configureChipForConcurrencyType(IfaceConcurrencyType::NAN_IFACE); + + std::vector iface_names; + EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); + + std::shared_ptr iface; + EXPECT_TRUE(wifi_chip_->createNanIface(&iface).isOk()); + ASSERT_NE(nullptr, iface.get()); + + std::string iface_name = getNanIfaceName(iface); + EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 1); + EXPECT_EQ(iface_name, iface_names[0]); + + EXPECT_TRUE(wifi_chip_->removeNanIface(iface_name).isOk()); + EXPECT_TRUE(wifi_chip_->getNanIfaceNames(&iface_names).isOk()); + EXPECT_EQ(iface_names.size(), 0); +} + +/* + * GetStaIface + * Configures the chip in STA mode and creates an iface. Then retrieves + * the iface object using its name and ensures that any other name + * doesn't retrieve a valid iface object. + */ +TEST_P(WifiChipAidlTest, GetStaIface) { + std::shared_ptr iface = configureChipForStaAndGetIface(); + std::string iface_name = getStaIfaceName(iface); + + std::shared_ptr retrieved_iface; + EXPECT_TRUE(wifi_chip_->getStaIface(iface_name, &retrieved_iface).isOk()); + EXPECT_NE(nullptr, retrieved_iface.get()); + + std::string invalid_name = iface_name + "0"; + std::shared_ptr invalid_iface; + auto status = wifi_chip_->getStaIface(invalid_name, &invalid_iface); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_EQ(nullptr, invalid_iface.get()); +} + +/* + * GetP2pIface + */ +TEST_P(WifiChipAidlTest, GetP2pIface) { + std::shared_ptr iface = configureChipForP2pAndGetIface(); + std::string iface_name = getP2pIfaceName(iface); + + std::shared_ptr retrieved_iface; + EXPECT_TRUE(wifi_chip_->getP2pIface(iface_name, &retrieved_iface).isOk()); + EXPECT_NE(nullptr, retrieved_iface.get()); + + std::string invalid_name = iface_name + "0"; + std::shared_ptr invalid_iface; + auto status = wifi_chip_->getP2pIface(invalid_name, &invalid_iface); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_EQ(nullptr, invalid_iface.get()); +} + +/* + * GetApIface + */ +TEST_P(WifiChipAidlTest, GetApIface) { + std::shared_ptr iface = configureChipForApAndGetIface(); + std::string iface_name = getApIfaceName(iface); + + std::shared_ptr retrieved_iface; + EXPECT_TRUE(wifi_chip_->getApIface(iface_name, &retrieved_iface).isOk()); + EXPECT_NE(nullptr, retrieved_iface.get()); + + std::string invalid_name = iface_name + "0"; + std::shared_ptr invalid_iface; + auto status = wifi_chip_->getApIface(invalid_name, &invalid_iface); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_EQ(nullptr, invalid_iface.get()); +} + +/* + * GetNanIface + */ +TEST_P(WifiChipAidlTest, GetNanIface) { + std::shared_ptr iface = configureChipForNanAndGetIface(); + std::string iface_name = getNanIfaceName(iface); + + std::shared_ptr retrieved_iface; + EXPECT_TRUE(wifi_chip_->getNanIface(iface_name, &retrieved_iface).isOk()); + EXPECT_NE(nullptr, retrieved_iface.get()); + + std::string invalid_name = iface_name + "0"; + std::shared_ptr invalid_iface; + auto status = wifi_chip_->getNanIface(invalid_name, &invalid_iface); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_EQ(nullptr, invalid_iface.get()); +} + +/* + * RemoveStaIface + * Configures the chip in STA mode and creates an iface. Then removes + * the iface object using the correct name and ensures that any other + * name doesn't remove the iface. + */ +TEST_P(WifiChipAidlTest, RemoveStaIface) { + std::shared_ptr iface = configureChipForStaAndGetIface(); + std::string iface_name = getStaIfaceName(iface); + + std::string invalid_name = iface_name + "0"; + auto status = wifi_chip_->removeStaIface(invalid_name); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_TRUE(wifi_chip_->removeStaIface(iface_name).isOk()); + + // No such iface exists now, so this should return failure. + EXPECT_FALSE(wifi_chip_->removeStaIface(iface_name).isOk()); +} + +/* + * RemoveP2pIface + */ +TEST_P(WifiChipAidlTest, RemoveP2pIface) { + std::shared_ptr iface = configureChipForP2pAndGetIface(); + std::string iface_name = getP2pIfaceName(iface); + + std::string invalid_name = iface_name + "0"; + auto status = wifi_chip_->removeP2pIface(invalid_name); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_TRUE(wifi_chip_->removeP2pIface(iface_name).isOk()); + + // No such iface exists now, so this should return failure. + EXPECT_FALSE(wifi_chip_->removeP2pIface(iface_name).isOk()); +} + +/* + * RemoveApIface + */ +TEST_P(WifiChipAidlTest, RemoveApIface) { + std::shared_ptr iface = configureChipForApAndGetIface(); + std::string iface_name = getApIfaceName(iface); + + std::string invalid_name = iface_name + "0"; + auto status = wifi_chip_->removeApIface(invalid_name); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_TRUE(wifi_chip_->removeApIface(iface_name).isOk()); + + // No such iface exists now, so this should return failure. + EXPECT_FALSE(wifi_chip_->removeApIface(iface_name).isOk()); +} + +/* + * RemoveNanIface + */ +TEST_P(WifiChipAidlTest, RemoveNanIface) { + std::shared_ptr iface = configureChipForNanAndGetIface(); + std::string iface_name = getNanIfaceName(iface); + + std::string invalid_name = iface_name + "0"; + auto status = wifi_chip_->removeNanIface(invalid_name); + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + EXPECT_TRUE(wifi_chip_->removeNanIface(iface_name).isOk()); + + // No such iface exists now, so this should return failure. + EXPECT_FALSE(wifi_chip_->removeNanIface(iface_name).isOk()); +} + +/* + * CreateRttController + */ +TEST_P(WifiChipAidlTest, CreateRttController) { + std::shared_ptr iface = configureChipForStaAndGetIface(); + std::shared_ptr rtt_controller; + auto status = wifi_chip_->createRttController(iface, &rtt_controller); + if (status.isOk()) { + EXPECT_NE(nullptr, rtt_controller.get()); + } else { + EXPECT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + } +} + +/** + * CreateBridgedApIface & RemoveIfaceInstanceFromBridgedApIface + */ +TEST_P(WifiChipAidlTest, CreateBridgedApIfaceAndremoveIfaceInstanceFromBridgedApIfaceTest) { + bool isBridgedSupport = testing::checkSubstringInCommandOutput( + "/system/bin/cmd wifi get-softap-supported-features", + "wifi_softap_bridged_ap_supported"); + if (!isBridgedSupport) { + GTEST_SKIP() << "Missing Bridged AP support"; + } + + std::shared_ptr wifi_chip = getWifiChip(getInstanceName()); + ASSERT_NE(nullptr, wifi_chip.get()); + std::shared_ptr wifi_ap_iface = getBridgedWifiApIface(wifi_chip); + ASSERT_NE(nullptr, wifi_ap_iface.get()); + + std::string br_name; + std::vector instances; + EXPECT_TRUE(wifi_ap_iface->getName(&br_name).isOk()); + EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk()); + EXPECT_EQ(instances.size(), 2); + + std::vector instances_after_remove; + EXPECT_TRUE(wifi_chip->removeIfaceInstanceFromBridgedApIface(br_name, instances[0]).isOk()); + EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances_after_remove).isOk()); + EXPECT_EQ(instances_after_remove.size(), 1); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipAidlTest); +INSTANTIATE_TEST_SUITE_P(WifiTest, WifiChipAidlTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + android::ProcessState::self()->setThreadPoolMaxThreadCount(1); + android::ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} diff --git a/wifi/aidl/vts/functional/wifi_nan_iface_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_nan_iface_aidl_test.cpp new file mode 100644 index 0000000000..457d57ad75 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_nan_iface_aidl_test.cpp @@ -0,0 +1,627 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Staache 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using aidl::android::hardware::wifi::BnWifiNanIfaceEventCallback; +using aidl::android::hardware::wifi::IWifiNanIface; +using aidl::android::hardware::wifi::NanBandIndex; +using aidl::android::hardware::wifi::NanBandSpecificConfig; +using aidl::android::hardware::wifi::NanCapabilities; +using aidl::android::hardware::wifi::NanClusterEventInd; +using aidl::android::hardware::wifi::NanConfigRequest; +using aidl::android::hardware::wifi::NanConfigRequestSupplemental; +using aidl::android::hardware::wifi::NanDataPathConfirmInd; +using aidl::android::hardware::wifi::NanDataPathRequestInd; +using aidl::android::hardware::wifi::NanDataPathScheduleUpdateInd; +using aidl::android::hardware::wifi::NanDataPathSecurityType; +using aidl::android::hardware::wifi::NanEnableRequest; +using aidl::android::hardware::wifi::NanFollowupReceivedInd; +using aidl::android::hardware::wifi::NanInitiateDataPathRequest; +using aidl::android::hardware::wifi::NanMatchAlg; +using aidl::android::hardware::wifi::NanMatchInd; +using aidl::android::hardware::wifi::NanPublishRequest; +using aidl::android::hardware::wifi::NanPublishType; +using aidl::android::hardware::wifi::NanRespondToDataPathIndicationRequest; +using aidl::android::hardware::wifi::NanStatus; +using aidl::android::hardware::wifi::NanStatusCode; +using aidl::android::hardware::wifi::NanTxType; + +#define TIMEOUT_PERIOD 10 + +class WifiNanIfaceAidlTest : public testing::TestWithParam { + public: + void SetUp() override { + if (!::testing::deviceSupportsFeature("android.hardware.wifi.aware")) + GTEST_SKIP() << "Skipping this test since NAN is not supported."; + stopWifiService(getInstanceName()); + + wifi_nan_iface_ = getWifiNanIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_nan_iface_.get()); + std::shared_ptr callback = + ndk::SharedRefBase::make(*this); + EXPECT_TRUE(wifi_nan_iface_->registerEventCallback(callback).isOk()); + } + + void TearDown() override { stopWifiService(getInstanceName()); } + + // Used as a mechanism to inform the test about data/event callbacks. + inline void notify() { + std::unique_lock lock(mtx_); + count_++; + cv_.notify_one(); + } + + enum CallbackType { + INVALID = -2, + ANY_CALLBACK = -1, + + NOTIFY_CAPABILITIES_RESPONSE = 0, + NOTIFY_ENABLE_RESPONSE, + NOTIFY_CONFIG_RESPONSE, + NOTIFY_DISABLE_RESPONSE, + NOTIFY_START_PUBLISH_RESPONSE, + NOTIFY_STOP_PUBLISH_RESPONSE, + NOTIFY_START_SUBSCRIBE_RESPONSE, + NOTIFY_STOP_SUBSCRIBE_RESPONSE, + NOTIFY_TRANSMIT_FOLLOWUP_RESPONSE, + NOTIFY_CREATE_DATA_INTERFACE_RESPONSE, + NOTIFY_DELETE_DATA_INTERFACE_RESPONSE, + NOTIFY_INITIATE_DATA_PATH_RESPONSE, + NOTIFY_RESPOND_TO_DATA_PATH_INDICATION_RESPONSE, + NOTIFY_TERMINATE_DATA_PATH_RESPONSE, + + EVENT_CLUSTER_EVENT, + EVENT_DISABLED, + EVENT_PUBLISH_TERMINATED, + EVENT_SUBSCRIBE_TERMINATED, + EVENT_MATCH, + EVENT_MATCH_EXPIRED, + EVENT_FOLLOWUP_RECEIVED, + EVENT_TRANSMIT_FOLLOWUP, + EVENT_DATA_PATH_REQUEST, + EVENT_DATA_PATH_CONFIRM, + EVENT_DATA_PATH_TERMINATED, + EVENT_DATA_PATH_SCHEDULE_UPDATE, + }; + + // Test code calls this function to wait for data/event callback. + // Must set callbackType = INVALID before calling this function. + inline std::cv_status wait(CallbackType waitForCallbackType) { + std::unique_lock lock(mtx_); + EXPECT_NE(INVALID, waitForCallbackType); + + std::cv_status status = std::cv_status::no_timeout; + auto now = std::chrono::system_clock::now(); + while (count_ == 0) { + status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD)); + if (status == std::cv_status::timeout) return status; + if (waitForCallbackType != ANY_CALLBACK && callback_type_ != INVALID && + callback_type_ != waitForCallbackType) { + count_--; + } + } + count_--; + return status; + } + + class WifiNanIfaceEventCallback : public BnWifiNanIfaceEventCallback { + public: + WifiNanIfaceEventCallback(WifiNanIfaceAidlTest& parent) : parent_(parent){}; + + ::ndk::ScopedAStatus eventClusterEvent(const NanClusterEventInd& event) override { + parent_.callback_type_ = EVENT_CLUSTER_EVENT; + parent_.nan_cluster_event_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventDataPathConfirm(const NanDataPathConfirmInd& event) override { + parent_.callback_type_ = EVENT_DATA_PATH_CONFIRM; + parent_.nan_data_path_confirm_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventDataPathRequest(const NanDataPathRequestInd& event) override { + parent_.callback_type_ = EVENT_DATA_PATH_REQUEST; + parent_.nan_data_path_request_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventDataPathScheduleUpdate( + const NanDataPathScheduleUpdateInd& event) override { + parent_.callback_type_ = EVENT_DATA_PATH_SCHEDULE_UPDATE; + parent_.nan_data_path_schedule_update_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventDataPathTerminated(int32_t ndpInstanceId) override { + parent_.callback_type_ = EVENT_DATA_PATH_TERMINATED; + parent_.ndp_instance_id_ = ndpInstanceId; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventDisabled(const NanStatus& status) override { + parent_.callback_type_ = EVENT_DISABLED; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventFollowupReceived(const NanFollowupReceivedInd& event) override { + parent_.callback_type_ = EVENT_FOLLOWUP_RECEIVED; + parent_.nan_followup_received_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventMatch(const NanMatchInd& event) override { + parent_.callback_type_ = EVENT_MATCH; + parent_.nan_match_ind_ = event; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventMatchExpired(int8_t discoverySessionId, int32_t peerId) override { + parent_.callback_type_ = EVENT_MATCH_EXPIRED; + parent_.session_id_ = discoverySessionId; + parent_.peer_id_ = peerId; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventPublishTerminated(int8_t sessionId, + const NanStatus& status) override { + parent_.callback_type_ = EVENT_PUBLISH_TERMINATED; + parent_.session_id_ = sessionId; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventSubscribeTerminated(int8_t sessionId, + const NanStatus& status) override { + parent_.callback_type_ = EVENT_SUBSCRIBE_TERMINATED; + parent_.session_id_ = sessionId; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus eventTransmitFollowup(char16_t id, const NanStatus& status) override { + parent_.callback_type_ = EVENT_TRANSMIT_FOLLOWUP; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyCapabilitiesResponse( + char16_t id, const NanStatus& status, + const NanCapabilities& capabilities) override { + parent_.callback_type_ = NOTIFY_CAPABILITIES_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.capabilities_ = capabilities; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyConfigResponse(char16_t id, const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_CONFIG_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyCreateDataInterfaceResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_CREATE_DATA_INTERFACE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyDeleteDataInterfaceResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_DELETE_DATA_INTERFACE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyDisableResponse(char16_t id, const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_DISABLE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyEnableResponse(char16_t id, const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_ENABLE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyInitiateDataPathResponse(char16_t id, const NanStatus& status, + int32_t ndpInstanceId) override { + parent_.callback_type_ = NOTIFY_INITIATE_DATA_PATH_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.ndp_instance_id_ = ndpInstanceId; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyRespondToDataPathIndicationResponse( + char16_t id, const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_RESPOND_TO_DATA_PATH_INDICATION_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyStartPublishResponse(char16_t id, const NanStatus& status, + int8_t sessionId) override { + parent_.callback_type_ = NOTIFY_START_PUBLISH_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.session_id_ = sessionId; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyStartSubscribeResponse(char16_t id, const NanStatus& status, + int8_t sessionId) override { + parent_.callback_type_ = NOTIFY_START_SUBSCRIBE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.session_id_ = sessionId; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyStopPublishResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_STOP_PUBLISH_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyStopSubscribeResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_STOP_SUBSCRIBE_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyTerminateDataPathResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_TERMINATE_DATA_PATH_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus notifyTransmitFollowupResponse(char16_t id, + const NanStatus& status) override { + parent_.callback_type_ = NOTIFY_TRANSMIT_FOLLOWUP_RESPONSE; + parent_.id_ = id; + parent_.status_ = status; + parent_.notify(); + return ndk::ScopedAStatus::ok(); + } + + private: + WifiNanIfaceAidlTest& parent_; + }; + + protected: + std::shared_ptr wifi_nan_iface_; + CallbackType callback_type_; + uint16_t id_; + uint8_t session_id_; + uint32_t ndp_instance_id_; + uint32_t peer_id_; + NanCapabilities capabilities_; + NanClusterEventInd nan_cluster_event_ind_; + NanDataPathConfirmInd nan_data_path_confirm_ind_; + NanDataPathRequestInd nan_data_path_request_ind_; + NanDataPathScheduleUpdateInd nan_data_path_schedule_update_ind_; + NanFollowupReceivedInd nan_followup_received_ind_; + NanMatchInd nan_match_ind_; + NanStatus status_; + + const char* getInstanceName() { return GetParam().c_str(); } + + private: + // synchronization objects + std::mutex mtx_; + std::condition_variable cv_; + int count_ = 0; +}; + +/* + * FailOnIfaceInvalid + * Ensure that API calls to an interface fail with code ERROR_WIFI_IFACE_INVALID + * after wifi is disabled. + */ +TEST_P(WifiNanIfaceAidlTest, FailOnIfaceInvalid) { + stopWifiService(getInstanceName()); + sleep(5); // Ensure that all chips/interfaces are invalidated. + auto status = wifi_nan_iface_->getCapabilitiesRequest(0); + ASSERT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_WIFI_IFACE_INVALID)); +} + +/* + * EnableRequest - Invalid Args + */ +TEST_P(WifiNanIfaceAidlTest, EnableRequest_InvalidArgs) { + uint16_t inputCmdId = 10; + callback_type_ = INVALID; + NanEnableRequest nanEnableRequest = {}; + NanConfigRequestSupplemental nanConfigRequestSupp = {}; + auto status = + wifi_nan_iface_->enableRequest(inputCmdId, nanEnableRequest, nanConfigRequestSupp); + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(status.isOk()); + + // Wait for a callback. + ASSERT_EQ(std::cv_status::no_timeout, wait(NOTIFY_ENABLE_RESPONSE)); + ASSERT_EQ(NOTIFY_ENABLE_RESPONSE, callback_type_); + ASSERT_EQ(id_, inputCmdId); + ASSERT_EQ(status_.status, NanStatusCode::INVALID_ARGS); + } +} + +/* + * ConfigRequest - Invalid Args + */ +TEST_P(WifiNanIfaceAidlTest, ConfigRequest_InvalidArgs) { + uint16_t inputCmdId = 10; + callback_type_ = INVALID; + NanConfigRequest nanConfigRequest = {}; + NanConfigRequestSupplemental nanConfigRequestSupp = {}; + auto status = + wifi_nan_iface_->configRequest(inputCmdId, nanConfigRequest, nanConfigRequestSupp); + + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(status.isOk()); + + // Wait for a callback. + ASSERT_EQ(std::cv_status::no_timeout, wait(NOTIFY_CONFIG_RESPONSE)); + ASSERT_EQ(NOTIFY_CONFIG_RESPONSE, callback_type_); + ASSERT_EQ(id_, inputCmdId); + ASSERT_EQ(status_.status, NanStatusCode::INVALID_ARGS); + } +} + +/* + * EnableRequest - Invalid Args in Shim Conversion + */ +TEST_P(WifiNanIfaceAidlTest, EnableRequest_InvalidShimArgs) { + uint16_t inputCmdId = 10; + NanEnableRequest nanEnableRequest = {}; + nanEnableRequest.configParams.numberOfPublishServiceIdsInBeacon = -15; // must be > 0 + NanConfigRequestSupplemental nanConfigRequestSupp = {}; + auto status = + wifi_nan_iface_->enableRequest(inputCmdId, nanEnableRequest, nanConfigRequestSupp); + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + } +} + +/* + * ConfigRequest - Invalid Args in Shim Conversion + */ +TEST_P(WifiNanIfaceAidlTest, ConfigRequest_InvalidShimArgs) { + uint16_t inputCmdId = 10; + NanConfigRequest nanConfigRequest = {}; + nanConfigRequest.numberOfPublishServiceIdsInBeacon = -15; // must be > 0 + NanConfigRequestSupplemental nanConfigRequestSupp = {}; + auto status = + wifi_nan_iface_->configRequest(inputCmdId, nanConfigRequest, nanConfigRequestSupp); + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(checkStatusCode(&status, WifiStatusCode::ERROR_INVALID_ARGS)); + } +} + +/* + * NotifyCapabilitiesResponse + */ +TEST_P(WifiNanIfaceAidlTest, NotifyCapabilitiesResponse) { + uint16_t inputCmdId = 10; + callback_type_ = INVALID; + EXPECT_TRUE(wifi_nan_iface_->getCapabilitiesRequest(inputCmdId).isOk()); + + // Wait for a callback. + ASSERT_EQ(std::cv_status::no_timeout, wait(NOTIFY_CAPABILITIES_RESPONSE)); + ASSERT_EQ(NOTIFY_CAPABILITIES_RESPONSE, callback_type_); + ASSERT_EQ(id_, inputCmdId); + ASSERT_EQ(status_.status, NanStatusCode::SUCCESS); + + // Check for reasonable capability values. + EXPECT_GT(capabilities_.maxConcurrentClusters, 0); + EXPECT_GT(capabilities_.maxPublishes, 0); + EXPECT_GT(capabilities_.maxSubscribes, 0); + EXPECT_EQ(capabilities_.maxServiceNameLen, 255); + EXPECT_EQ(capabilities_.maxMatchFilterLen, 255); + EXPECT_GT(capabilities_.maxTotalMatchFilterLen, 255); + EXPECT_EQ(capabilities_.maxServiceSpecificInfoLen, 255); + EXPECT_GE(capabilities_.maxExtendedServiceSpecificInfoLen, 255); + EXPECT_GT(capabilities_.maxNdiInterfaces, 0); + EXPECT_GT(capabilities_.maxNdpSessions, 0); + EXPECT_GT(capabilities_.maxAppInfoLen, 0); + EXPECT_GT(capabilities_.maxQueuedTransmitFollowupMsgs, 0); + EXPECT_GT(capabilities_.maxSubscribeInterfaceAddresses, 0); + EXPECT_NE(static_cast(capabilities_.supportedCipherSuites), 0); +} + +/* + * StartPublishRequest + */ +TEST_P(WifiNanIfaceAidlTest, StartPublishRequest) { + uint16_t inputCmdId = 10; + NanBandSpecificConfig config24 = {}; + config24.rssiClose = 60; + config24.rssiMiddle = 70; + config24.rssiCloseProximity = 60; + config24.dwellTimeMs = 200; + config24.scanPeriodSec = 20; + config24.validDiscoveryWindowIntervalVal = false; + config24.discoveryWindowIntervalVal = 0; + + NanBandSpecificConfig config5 = {}; + config5.rssiClose = 60; + config5.rssiMiddle = 75; + config5.rssiCloseProximity = 60; + config5.dwellTimeMs = 200; + config5.scanPeriodSec = 20; + config5.validDiscoveryWindowIntervalVal = false; + config5.discoveryWindowIntervalVal = 0; + + NanEnableRequest req = {}; + req.operateInBand[static_cast(NanBandIndex::NAN_BAND_24GHZ)] = true; + req.operateInBand[static_cast(NanBandIndex::NAN_BAND_5GHZ)] = false; + req.hopCountMax = 2; + req.configParams.masterPref = 0; + req.configParams.disableDiscoveryAddressChangeIndication = true; + req.configParams.disableStartedClusterIndication = true; + req.configParams.disableJoinedClusterIndication = true; + req.configParams.includePublishServiceIdsInBeacon = true; + req.configParams.numberOfPublishServiceIdsInBeacon = 0; + req.configParams.includeSubscribeServiceIdsInBeacon = true; + req.configParams.numberOfSubscribeServiceIdsInBeacon = 0; + req.configParams.rssiWindowSize = 8; + req.configParams.macAddressRandomizationIntervalSec = 1800; + req.configParams.bandSpecificConfig[static_cast(NanBandIndex::NAN_BAND_24GHZ)] = + config24; + req.configParams.bandSpecificConfig[static_cast(NanBandIndex::NAN_BAND_5GHZ)] = + config5; + + req.debugConfigs.validClusterIdVals = true; + req.debugConfigs.clusterIdTopRangeVal = 65535; + req.debugConfigs.clusterIdBottomRangeVal = 0; + req.debugConfigs.validIntfAddrVal = false; + req.debugConfigs.validOuiVal = false; + req.debugConfigs.ouiVal = 0; + req.debugConfigs.validRandomFactorForceVal = false; + req.debugConfigs.randomFactorForceVal = 0; + req.debugConfigs.validHopCountForceVal = false; + req.debugConfigs.hopCountForceVal = 0; + req.debugConfigs.validDiscoveryChannelVal = false; + req.debugConfigs.discoveryChannelMhzVal[static_cast(NanBandIndex::NAN_BAND_24GHZ)] = 0; + req.debugConfigs.discoveryChannelMhzVal[static_cast(NanBandIndex::NAN_BAND_5GHZ)] = 0; + req.debugConfigs.validUseBeaconsInBandVal = false; + req.debugConfigs.useBeaconsInBandVal[static_cast(NanBandIndex::NAN_BAND_24GHZ)] = true; + req.debugConfigs.useBeaconsInBandVal[static_cast(NanBandIndex::NAN_BAND_5GHZ)] = true; + req.debugConfigs.validUseSdfInBandVal = false; + req.debugConfigs.useSdfInBandVal[static_cast(NanBandIndex::NAN_BAND_24GHZ)] = true; + req.debugConfigs.useSdfInBandVal[static_cast(NanBandIndex::NAN_BAND_5GHZ)] = true; + + NanConfigRequestSupplemental nanConfigRequestSupp = {}; + nanConfigRequestSupp.discoveryBeaconIntervalMs = 20; + nanConfigRequestSupp.numberOfSpatialStreamsInDiscovery = 0; + nanConfigRequestSupp.enableDiscoveryWindowEarlyTermination = false; + + callback_type_ = INVALID; + auto status = wifi_nan_iface_->enableRequest(inputCmdId, req, nanConfigRequestSupp); + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(status.isOk()); + + // Wait for a callback. + ASSERT_EQ(std::cv_status::no_timeout, wait(NOTIFY_ENABLE_RESPONSE)); + ASSERT_EQ(NOTIFY_ENABLE_RESPONSE, callback_type_); + ASSERT_EQ(id_, inputCmdId); + ASSERT_EQ(status_.status, NanStatusCode::SUCCESS); + } + + NanPublishRequest nanPublishRequest = {}; + nanPublishRequest.baseConfigs.sessionId = 0; + nanPublishRequest.baseConfigs.ttlSec = 0; + nanPublishRequest.baseConfigs.discoveryWindowPeriod = 1; + nanPublishRequest.baseConfigs.discoveryCount = 0; + nanPublishRequest.baseConfigs.serviceName = {97}; + nanPublishRequest.baseConfigs.discoveryMatchIndicator = NanMatchAlg::MATCH_NEVER; + nanPublishRequest.baseConfigs.useRssiThreshold = false; + nanPublishRequest.baseConfigs.disableDiscoveryTerminationIndication = false; + nanPublishRequest.baseConfigs.disableMatchExpirationIndication = true; + nanPublishRequest.baseConfigs.disableFollowupReceivedIndication = false; + nanPublishRequest.baseConfigs.securityConfig.securityType = NanDataPathSecurityType::OPEN; + nanPublishRequest.autoAcceptDataPathRequests = false; + nanPublishRequest.publishType = NanPublishType::UNSOLICITED; + nanPublishRequest.txType = NanTxType::BROADCAST; + + status = wifi_nan_iface_->startPublishRequest(inputCmdId + 1, nanPublishRequest); + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_TRUE(status.isOk()); + + // Wait for a callback. + ASSERT_EQ(std::cv_status::no_timeout, wait(NOTIFY_START_PUBLISH_RESPONSE)); + ASSERT_EQ(NOTIFY_START_PUBLISH_RESPONSE, callback_type_); + ASSERT_EQ(id_, inputCmdId + 1); + ASSERT_EQ(status_.status, NanStatusCode::SUCCESS); + } +} + +/* + * RespondToDataPathIndicationRequest - Invalid Args + */ +TEST_P(WifiNanIfaceAidlTest, RespondToDataPathIndicationRequest_InvalidArgs) { + uint16_t inputCmdId = 10; + callback_type_ = INVALID; + NanRespondToDataPathIndicationRequest nanRespondToDataPathIndicationRequest = {}; + nanRespondToDataPathIndicationRequest.ifaceName = "AwareInterfaceNameTooLong"; + auto status = wifi_nan_iface_->respondToDataPathIndicationRequest( + inputCmdId, nanRespondToDataPathIndicationRequest); + + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_EQ(status.getServiceSpecificError(), + static_cast(WifiStatusCode::ERROR_INVALID_ARGS)); + } +} + +/* + * InitiateDataPathRequest - Invalid Args + */ +TEST_P(WifiNanIfaceAidlTest, InitiateDataPathRequest_InvalidArgs) { + uint16_t inputCmdId = 10; + callback_type_ = INVALID; + NanInitiateDataPathRequest nanInitiateDataPathRequest = {}; + nanInitiateDataPathRequest.ifaceName = "AwareInterfaceNameTooLong"; + auto status = wifi_nan_iface_->initiateDataPathRequest(inputCmdId, nanInitiateDataPathRequest); + + if (!checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + ASSERT_EQ(status.getServiceSpecificError(), + static_cast(WifiStatusCode::ERROR_INVALID_ARGS)); + } +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiNanIfaceAidlTest); +INSTANTIATE_TEST_SUITE_P(WifiTest, WifiNanIfaceAidlTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + android::ProcessState::self()->setThreadPoolMaxThreadCount(1); + android::ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} diff --git a/wifi/aidl/vts/functional/wifi_rtt_controller_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_rtt_controller_aidl_test.cpp new file mode 100644 index 0000000000..d763fe64a5 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_rtt_controller_aidl_test.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Staache 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using aidl::android::hardware::wifi::BnWifiRttControllerEventCallback; +using aidl::android::hardware::wifi::IWifiRttController; +using aidl::android::hardware::wifi::RttBw; +using aidl::android::hardware::wifi::RttCapabilities; +using aidl::android::hardware::wifi::RttConfig; +using aidl::android::hardware::wifi::RttPeerType; +using aidl::android::hardware::wifi::RttPreamble; +using aidl::android::hardware::wifi::RttResponder; +using aidl::android::hardware::wifi::RttResult; +using aidl::android::hardware::wifi::RttType; +using aidl::android::hardware::wifi::WifiChannelInfo; +using aidl::android::hardware::wifi::WifiChannelWidthInMhz; +using aidl::android::hardware::wifi::WifiStatusCode; + +class WifiRttControllerAidlTest : public testing::TestWithParam { + public: + void SetUp() override { + if (!::testing::deviceSupportsFeature("android.hardware.wifi.rtt")) + GTEST_SKIP() << "Skipping this test since RTT is not supported."; + stopWifiService(getInstanceName()); + wifi_rtt_controller_ = getWifiRttController(); + ASSERT_NE(nullptr, wifi_rtt_controller_.get()); + + // Check RTT support before we run the test. + RttCapabilities caps = {}; + auto status = wifi_rtt_controller_->getCapabilities(&caps); + if (checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)) { + GTEST_SKIP() << "Skipping this test since RTT is not supported."; + } + } + + void TearDown() override { stopWifiService(getInstanceName()); } + + protected: + std::shared_ptr getWifiRttController() { + std::shared_ptr wifi_chip = getWifiChip(getInstanceName()); + EXPECT_NE(nullptr, wifi_chip.get()); + + std::shared_ptr wifi_sta_iface = getWifiStaIface(getInstanceName()); + EXPECT_NE(nullptr, wifi_sta_iface.get()); + + std::shared_ptr rtt_controller; + EXPECT_TRUE(wifi_chip->createRttController(wifi_sta_iface, &rtt_controller).isOk()); + EXPECT_NE(nullptr, rtt_controller.get()); + return rtt_controller; + } + + std::shared_ptr wifi_rtt_controller_; + + private: + const char* getInstanceName() { return GetParam().c_str(); } +}; + +class WifiRttControllerEventCallback : public BnWifiRttControllerEventCallback { + public: + WifiRttControllerEventCallback() = default; + + ::ndk::ScopedAStatus onResults(int /* cmdId */, + const std::vector& /* results */) override { + return ndk::ScopedAStatus::ok(); + } +}; + +/* + * RegisterEventCallback + * + * Note: it is not feasible to test the invocation of the callback function, + * since events are triggered internally in the HAL implementation and cannot be + * triggered from the test case. + */ +TEST_P(WifiRttControllerAidlTest, RegisterEventCallback) { + std::shared_ptr callback = + ndk::SharedRefBase::make(); + ASSERT_NE(nullptr, callback.get()); + EXPECT_TRUE(wifi_rtt_controller_->registerEventCallback(callback).isOk()); +} + +/* + * GetCapabilities + */ +TEST_P(WifiRttControllerAidlTest, GetCapabilities) { + RttCapabilities caps = {}; + EXPECT_TRUE(wifi_rtt_controller_->getCapabilities(&caps).isOk()); +} + +/* + * GetResponderInfo + */ +TEST_P(WifiRttControllerAidlTest, GetResponderInfo) { + RttResponder responder = {}; + EXPECT_TRUE(wifi_rtt_controller_->getResponderInfo(&responder).isOk()); +} + +/* + * EnableResponder + */ +TEST_P(WifiRttControllerAidlTest, EnableResponder) { + int cmdId = 55; + WifiChannelInfo channelInfo; + channelInfo.width = WifiChannelWidthInMhz::WIDTH_80; + channelInfo.centerFreq = 5660; + channelInfo.centerFreq0 = 5660; + channelInfo.centerFreq1 = 0; + + RttResponder responder = {}; + EXPECT_TRUE(wifi_rtt_controller_->getResponderInfo(&responder).isOk()); + EXPECT_TRUE(wifi_rtt_controller_->enableResponder(cmdId, channelInfo, 10, responder).isOk()); +} + +/* + * Request2SidedRangeMeasurement + * Tests the two sided ranging - 802.11mc FTM protocol. + */ +TEST_P(WifiRttControllerAidlTest, Request2SidedRangeMeasurement) { + RttCapabilities caps = {}; + EXPECT_TRUE(wifi_rtt_controller_->getCapabilities(&caps).isOk()); + if (!caps.rttFtmSupported) { + GTEST_SKIP() << "Skipping two sided RTT since driver/fw does not support"; + } + + RttConfig config; + config.addr = {{0x00, 0x01, 0x02, 0x03, 0x04, 0x05}}; + config.type = RttType::TWO_SIDED; + config.peer = RttPeerType::AP; + config.channel.width = WifiChannelWidthInMhz::WIDTH_80; + config.channel.centerFreq = 5180; + config.channel.centerFreq0 = 5210; + config.channel.centerFreq1 = 0; + config.bw = RttBw::BW_20MHZ; + config.preamble = RttPreamble::HT; + config.mustRequestLci = false; + config.mustRequestLcr = false; + config.burstPeriod = 0; + config.numBurst = 0; + config.numFramesPerBurst = 8; + config.numRetriesPerRttFrame = 0; + config.numRetriesPerFtmr = 0; + config.burstDuration = 9; + + int cmdId = 55; + std::vector configs = {config}; + EXPECT_TRUE(wifi_rtt_controller_->rangeRequest(cmdId, configs).isOk()); + + // Sleep for 2 seconds to wait for driver/firmware to complete RTT. + sleep(2); +} + +/* + * RangeRequest + */ +TEST_P(WifiRttControllerAidlTest, RangeRequest) { + RttCapabilities caps = {}; + EXPECT_TRUE(wifi_rtt_controller_->getCapabilities(&caps).isOk()); + if (!caps.rttOneSidedSupported) { + GTEST_SKIP() << "Skipping one sided RTT since driver/fw does not support"; + } + + // Get the highest supported preamble. + int preamble = 1; + int caps_preamble_support = static_cast(caps.preambleSupport); + caps_preamble_support >>= 1; + while (caps_preamble_support != 0) { + caps_preamble_support >>= 1; + preamble <<= 1; + } + + RttConfig config; + config.addr = {{0x00, 0x01, 0x02, 0x03, 0x04, 0x05}}; + config.type = RttType::ONE_SIDED; + config.peer = RttPeerType::AP; + config.channel.width = WifiChannelWidthInMhz::WIDTH_80; + config.channel.centerFreq = 5765; + config.channel.centerFreq0 = 5775; + config.channel.centerFreq1 = 0; + config.bw = RttBw::BW_80MHZ; + config.preamble = static_cast(preamble); + config.mustRequestLci = false; + config.mustRequestLcr = false; + config.burstPeriod = 0; + config.numBurst = 0; + config.numFramesPerBurst = 8; + config.numRetriesPerRttFrame = 3; + config.numRetriesPerFtmr = 3; + config.burstDuration = 9; + + int cmdId = 55; + std::vector configs = {config}; + EXPECT_TRUE(wifi_rtt_controller_->rangeRequest(cmdId, configs).isOk()); + + // Sleep for 2 seconds to wait for driver/firmware to complete RTT. + sleep(2); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiRttControllerAidlTest); +INSTANTIATE_TEST_SUITE_P(WifiTest, WifiRttControllerAidlTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + android::ProcessState::self()->setThreadPoolMaxThreadCount(1); + android::ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} diff --git a/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp new file mode 100644 index 0000000000..ef7e2747c9 --- /dev/null +++ b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp @@ -0,0 +1,282 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Staache 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using aidl::android::hardware::wifi::IWifi; +using aidl::android::hardware::wifi::IWifiStaIface; +using aidl::android::hardware::wifi::MacAddress; +using aidl::android::hardware::wifi::Ssid; +using aidl::android::hardware::wifi::StaApfPacketFilterCapabilities; +using aidl::android::hardware::wifi::StaBackgroundScanCapabilities; +using aidl::android::hardware::wifi::StaLinkLayerStats; +using aidl::android::hardware::wifi::StaRoamingCapabilities; +using aidl::android::hardware::wifi::StaRoamingConfig; +using aidl::android::hardware::wifi::StaRoamingState; +using aidl::android::hardware::wifi::WifiBand; +using aidl::android::hardware::wifi::WifiDebugRxPacketFateReport; +using aidl::android::hardware::wifi::WifiDebugTxPacketFateReport; +using aidl::android::hardware::wifi::WifiStatusCode; + +class WifiStaIfaceAidlTest : public testing::TestWithParam { + public: + void SetUp() override { + stopWifiService(getInstanceName()); + wifi_sta_iface_ = getWifiStaIface(getInstanceName()); + ASSERT_NE(nullptr, wifi_sta_iface_.get()); + } + + void TearDown() override { stopWifiService(getInstanceName()); } + + protected: + bool isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask expected) { + IWifiStaIface::StaIfaceCapabilityMask caps = {}; + EXPECT_TRUE(wifi_sta_iface_->getCapabilities(&caps).isOk()); + return static_cast(caps) & static_cast(expected); + } + + ndk::ScopedAStatus createStaIface(std::shared_ptr* sta_iface) { + std::shared_ptr wifi_chip = getWifiChip(getInstanceName()); + EXPECT_NE(nullptr, wifi_chip.get()); + return wifi_chip->createStaIface(sta_iface); + } + + std::shared_ptr wifi_sta_iface_; + + private: + const char* getInstanceName() { return GetParam().c_str(); } +}; + +/* + * GetFactoryMacAddress + * Ensures that calls to getFactoryMacAddress will retrieve a non-zero MAC. + */ +TEST_P(WifiStaIfaceAidlTest, GetFactoryMacAddress) { + std::array mac; + EXPECT_TRUE(wifi_sta_iface_->getFactoryMacAddress(&mac).isOk()); + std::array all_zero_mac = {0, 0, 0, 0, 0, 0}; + EXPECT_NE(mac, all_zero_mac); +} + +/* + * GetCapabilities + */ +TEST_P(WifiStaIfaceAidlTest, GetCapabilities) { + IWifiStaIface::StaIfaceCapabilityMask caps = {}; + EXPECT_TRUE(wifi_sta_iface_->getCapabilities(&caps).isOk()); + EXPECT_NE(static_cast(caps), 0); +} + +/* + * GetApfPacketFilterCapabilities + */ +TEST_P(WifiStaIfaceAidlTest, GetApfPacketFilterCapabilities) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::APF)) { + GTEST_SKIP() << "APF packet filter capabilities are not supported."; + } + StaApfPacketFilterCapabilities apf_caps = {}; + EXPECT_TRUE(wifi_sta_iface_->getApfPacketFilterCapabilities(&apf_caps).isOk()); +} + +/* + * GetBackgroundScanCapabilities + */ +TEST_P(WifiStaIfaceAidlTest, GetBackgroundScanCapabilities) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::BACKGROUND_SCAN)) { + GTEST_SKIP() << "Background scan capabilities are not supported."; + } + StaBackgroundScanCapabilities caps = {}; + EXPECT_TRUE(wifi_sta_iface_->getBackgroundScanCapabilities(&caps).isOk()); +} + +/* + * GetValidFrequenciesForBand + * Ensures that we can retrieve valid frequencies for the 2.4 GHz band. + */ +TEST_P(WifiStaIfaceAidlTest, GetValidFrequenciesForBand) { + std::vector freqs; + EXPECT_TRUE(wifi_sta_iface_->getValidFrequenciesForBand(WifiBand::BAND_24GHZ, &freqs).isOk()); + EXPECT_NE(freqs.size(), 0); +} + +/* + * GetLinkLayerStats + * Ensures that calls to getLinkLayerStats will retrieve a non-empty + * StaLinkLayerStats after link layer stats collection is enabled. + */ +TEST_P(WifiStaIfaceAidlTest, GetLinkLayerStats) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS)) { + GTEST_SKIP() << "Skipping this test since link layer stats are not supported."; + } + + // Enable link layer stats collection. + EXPECT_TRUE(wifi_sta_iface_->enableLinkLayerStatsCollection(true).isOk()); + + // Retrieve link layer stats. + StaLinkLayerStats link_layer_stats = {}; + EXPECT_TRUE(wifi_sta_iface_->getLinkLayerStats(&link_layer_stats).isOk()); + EXPECT_GT(link_layer_stats.timeStampInMs, 0); + + // Try to create a 2nd iface. If successful, it should fill the duty cycle field. + std::shared_ptr iface; + auto status = createStaIface(&iface); + if (status.isOk()) { + EXPECT_GT(link_layer_stats.iface.timeSliceDutyCycleInPercent, 0); + } + + // Disable link layer stats collection. + EXPECT_TRUE(wifi_sta_iface_->disableLinkLayerStatsCollection().isOk()); +} + +/* + * SetMacAddress + * Ensures that calls to setMacAddress will return successfully. + */ +TEST_P(WifiStaIfaceAidlTest, SetMacAddress) { + std::array mac = {0x12, 0x22, 0x33, 0x52, 0x10, 0x41}; + EXPECT_TRUE(wifi_sta_iface_->setMacAddress(mac).isOk()); +} + +/* + * SetScanMode + */ +TEST_P(WifiStaIfaceAidlTest, SetScanMode) { + auto status = wifi_sta_iface_->setScanMode(true); + EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); + + status = wifi_sta_iface_->setScanMode(false); + EXPECT_TRUE(status.isOk() || checkStatusCode(&status, WifiStatusCode::ERROR_NOT_SUPPORTED)); +} + +/* + * LinkLayerStatsCollection + */ +TEST_P(WifiStaIfaceAidlTest, LinkLayerStatsCollection) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS)) { + GTEST_SKIP() << "Link layer stats collection is not supported."; + } + + // Enable link layer stats collection. + EXPECT_TRUE(wifi_sta_iface_->enableLinkLayerStatsCollection(true).isOk()); + + // Retrieve link layer stats. + StaLinkLayerStats link_layer_stats = {}; + EXPECT_TRUE(wifi_sta_iface_->getLinkLayerStats(&link_layer_stats).isOk()); + + // Disable link layer stats collection. + EXPECT_TRUE(wifi_sta_iface_->disableLinkLayerStatsCollection().isOk()); +} + +/* + * RSSIMonitoring + * Ensures that calls to startRssiMonitoring and stopRssiMonitoring will fail + * if the device is not connected to an AP. + */ +TEST_P(WifiStaIfaceAidlTest, RSSIMonitoring) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::RSSI_MONITOR)) { + GTEST_SKIP() << "RSSI monitoring is not supported."; + } + + const int cmd = 1; + const int maxRssi = -50; + const int minRssi = -90; + // Expected to fail because device is not connected to an AP. + EXPECT_FALSE(wifi_sta_iface_->startRssiMonitoring(cmd, maxRssi, minRssi).isOk()); + EXPECT_FALSE(wifi_sta_iface_->stopRssiMonitoring(cmd).isOk()); +} + +/* + * RoamingControl + */ +TEST_P(WifiStaIfaceAidlTest, RoamingControl) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::CONTROL_ROAMING)) { + GTEST_SKIP() << "Roaming control is not supported."; + } + + // Retrieve roaming capabilities. + StaRoamingCapabilities caps = {}; + EXPECT_TRUE(wifi_sta_iface_->getRoamingCapabilities(&caps).isOk()); + + // Set up roaming configuration based on roaming capabilities. + StaRoamingConfig roaming_config = {}; + if (caps.maxBlocklistSize > 0) { + MacAddress block_list_entry; + block_list_entry.data = std::array{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}; + roaming_config.bssidBlocklist = {block_list_entry}; + } + if (caps.maxAllowlistSize > 0) { + Ssid allow_list_entry = {}; + allow_list_entry.data = std::array{{0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC}}; + roaming_config.ssidAllowlist = {allow_list_entry}; + } + + // Configure roaming. + EXPECT_TRUE(wifi_sta_iface_->configureRoaming(roaming_config).isOk()); + + // Enable roaming. + EXPECT_TRUE(wifi_sta_iface_->setRoamingState(StaRoamingState::ENABLED).isOk()); +} + +/* + * EnableNDOffload + */ +TEST_P(WifiStaIfaceAidlTest, EnableNDOffload) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::ND_OFFLOAD)) { + GTEST_SKIP() << "ND offload is not supported."; + } + EXPECT_TRUE(wifi_sta_iface_->enableNdOffload(true).isOk()); +} + +/* + * PacketFateMonitoring + */ +TEST_P(WifiStaIfaceAidlTest, PacketFateMonitoring) { + if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::DEBUG_PACKET_FATE)) { + GTEST_SKIP() << "Packet fate monitoring is not supported."; + } + + // Start packet fate monitoring. + EXPECT_TRUE(wifi_sta_iface_->startDebugPacketFateMonitoring().isOk()); + + // Retrieve packets. + std::vector rx_reports; + std::vector tx_reports; + EXPECT_TRUE(wifi_sta_iface_->getDebugRxPacketFates(&rx_reports).isOk()); + EXPECT_TRUE(wifi_sta_iface_->getDebugTxPacketFates(&tx_reports).isOk()); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiStaIfaceAidlTest); +INSTANTIATE_TEST_SUITE_P(WifiTest, WifiStaIfaceAidlTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + android::ProcessState::self()->setThreadPoolMaxThreadCount(1); + android::ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} diff --git a/wifi/apex/Android.bp b/wifi/apex/Android.bp index 0afb96b85d..e1fefb9575 100644 --- a/wifi/apex/Android.bp +++ b/wifi/apex/Android.bp @@ -15,7 +15,7 @@ android_app_certificate { genrule { name: "gen-android.hardware.wifi.rc", - srcs: [":default-android.hardware.wifi@1.0-service.rc"], + srcs: [":default-android.hardware.wifi-service.rc"], out: ["com.android.hardware.wifi-service.rc"], cmd: "sed -e 's@/vendor/bin/@/apex/com.android.hardware.wifi/bin/@' $(in) > $(out)", } @@ -28,7 +28,7 @@ prebuilt_etc { prebuilt_etc { name: "com.android.hardware.wifi.xml", - src: ":default-android.hardware.wifi@1.0-service.xml", + src: ":default-android.hardware.wifi-service.xml", installable: false, } @@ -43,13 +43,13 @@ apex { updatable: false, soc_specific: true, binaries: [ - "android.hardware.wifi@1.0-service", + "android.hardware.wifi-service", ], prebuilts: [ "com.android.hardware.wifi.rc", "com.android.hardware.wifi.xml", ], overrides: [ - "android.hardware.wifi@1.0-service", + "android.hardware.wifi-service", ], } diff --git a/wifi/apex/file_contexts b/wifi/apex/file_contexts index 812d51db58..6368729c9a 100644 --- a/wifi/apex/file_contexts +++ b/wifi/apex/file_contexts @@ -1,3 +1,3 @@ (/.*)? u:object_r:vendor_file:s0 -/bin/hw/android\.hardware\.wifi@1.0-service u:object_r:hal_wifi_default_exec:s0 +/bin/hw/android\.hardware\.wifi-service u:object_r:hal_wifi_default_exec:s0