Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <android-base/logging.h> |
| 18 | #include <utils/SystemClock.h> |
| 19 | |
| 20 | #include "hidl_struct_util.h" |
| 21 | |
| 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace wifi { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 25 | namespace V1_5 { |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 26 | namespace implementation { |
| 27 | namespace hidl_struct_util { |
| 28 | |
Etan Cohen | b1b7a82 | 2018-02-07 14:44:32 -0800 | [diff] [blame] | 29 | WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl( |
| 30 | legacy_hal::wifi_channel_width type); |
| 31 | |
Etan Cohen | bbc0f09 | 2017-04-26 16:52:34 -0700 | [diff] [blame] | 32 | hidl_string safeConvertChar(const char* str, size_t max_len) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 33 | const char* c = str; |
| 34 | size_t size = 0; |
| 35 | while (*c && (unsigned char)*c < 128 && size < max_len) { |
| 36 | ++size; |
| 37 | ++c; |
| 38 | } |
| 39 | return hidl_string(str, size); |
Etan Cohen | bbc0f09 | 2017-04-26 16:52:34 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 42 | IWifiChip::ChipCapabilityMask convertLegacyLoggerFeatureToHidlChipCapability( |
| 43 | uint32_t feature) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 44 | using HidlChipCaps = IWifiChip::ChipCapabilityMask; |
| 45 | switch (feature) { |
| 46 | case legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED: |
| 47 | return HidlChipCaps::DEBUG_MEMORY_FIRMWARE_DUMP; |
| 48 | case legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED: |
| 49 | return HidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP; |
| 50 | case legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED: |
| 51 | return HidlChipCaps::DEBUG_RING_BUFFER_CONNECT_EVENT; |
| 52 | case legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED: |
| 53 | return HidlChipCaps::DEBUG_RING_BUFFER_POWER_EVENT; |
| 54 | case legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED: |
| 55 | return HidlChipCaps::DEBUG_RING_BUFFER_WAKELOCK_EVENT; |
| 56 | }; |
| 57 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 58 | return {}; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | IWifiStaIface::StaIfaceCapabilityMask |
| 62 | convertLegacyLoggerFeatureToHidlStaIfaceCapability(uint32_t feature) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 63 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 64 | switch (feature) { |
| 65 | case legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED: |
| 66 | return HidlStaIfaceCaps::DEBUG_PACKET_FATE; |
| 67 | }; |
| 68 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 69 | return {}; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 72 | V1_5::IWifiChip::ChipCapabilityMask convertLegacyFeatureToHidlChipCapability( |
| 73 | uint64_t feature) { |
| 74 | using HidlChipCaps = V1_5::IWifiChip::ChipCapabilityMask; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 75 | switch (feature) { |
| 76 | case WIFI_FEATURE_SET_TX_POWER_LIMIT: |
| 77 | return HidlChipCaps::SET_TX_POWER_LIMIT; |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 78 | case WIFI_FEATURE_USE_BODY_HEAD_SAR: |
| 79 | return HidlChipCaps::USE_BODY_HEAD_SAR; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 80 | case WIFI_FEATURE_D2D_RTT: |
| 81 | return HidlChipCaps::D2D_RTT; |
| 82 | case WIFI_FEATURE_D2AP_RTT: |
| 83 | return HidlChipCaps::D2AP_RTT; |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 84 | case WIFI_FEATURE_INFRA_60G: |
| 85 | return HidlChipCaps::WIGIG; |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 86 | case WIFI_FEATURE_SET_LATENCY_MODE: |
| 87 | return HidlChipCaps::SET_LATENCY_MODE; |
Jimmy Chen | d87a0ee | 2018-12-14 15:38:58 +0800 | [diff] [blame] | 88 | case WIFI_FEATURE_P2P_RAND_MAC: |
| 89 | return HidlChipCaps::P2P_RAND_MAC; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 90 | }; |
| 91 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 92 | return {}; |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 95 | IWifiStaIface::StaIfaceCapabilityMask |
Ahmed ElArabawy | 95e36b7 | 2019-11-15 21:24:53 +0000 | [diff] [blame] | 96 | convertLegacyFeatureToHidlStaIfaceCapability(uint64_t feature) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 97 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 98 | switch (feature) { |
| 99 | case WIFI_FEATURE_GSCAN: |
| 100 | return HidlStaIfaceCaps::BACKGROUND_SCAN; |
| 101 | case WIFI_FEATURE_LINK_LAYER_STATS: |
| 102 | return HidlStaIfaceCaps::LINK_LAYER_STATS; |
| 103 | case WIFI_FEATURE_RSSI_MONITOR: |
| 104 | return HidlStaIfaceCaps::RSSI_MONITOR; |
| 105 | case WIFI_FEATURE_CONTROL_ROAMING: |
| 106 | return HidlStaIfaceCaps::CONTROL_ROAMING; |
| 107 | case WIFI_FEATURE_IE_WHITELIST: |
| 108 | return HidlStaIfaceCaps::PROBE_IE_WHITELIST; |
| 109 | case WIFI_FEATURE_SCAN_RAND: |
| 110 | return HidlStaIfaceCaps::SCAN_RAND; |
| 111 | case WIFI_FEATURE_INFRA_5G: |
| 112 | return HidlStaIfaceCaps::STA_5G; |
| 113 | case WIFI_FEATURE_HOTSPOT: |
| 114 | return HidlStaIfaceCaps::HOTSPOT; |
| 115 | case WIFI_FEATURE_PNO: |
| 116 | return HidlStaIfaceCaps::PNO; |
| 117 | case WIFI_FEATURE_TDLS: |
| 118 | return HidlStaIfaceCaps::TDLS; |
| 119 | case WIFI_FEATURE_TDLS_OFFCHANNEL: |
| 120 | return HidlStaIfaceCaps::TDLS_OFFCHANNEL; |
| 121 | case WIFI_FEATURE_CONFIG_NDO: |
| 122 | return HidlStaIfaceCaps::ND_OFFLOAD; |
| 123 | case WIFI_FEATURE_MKEEP_ALIVE: |
| 124 | return HidlStaIfaceCaps::KEEP_ALIVE; |
| 125 | }; |
| 126 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 127 | return {}; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | bool convertLegacyFeaturesToHidlChipCapabilities( |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 131 | uint64_t legacy_feature_set, uint32_t legacy_logger_feature_set, |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 132 | uint32_t* hidl_caps) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 133 | if (!hidl_caps) { |
| 134 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 135 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 136 | *hidl_caps = {}; |
| 137 | using HidlChipCaps = IWifiChip::ChipCapabilityMask; |
| 138 | for (const auto feature : {legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED, |
| 139 | legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED, |
| 140 | legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED, |
| 141 | legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED, |
| 142 | legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED}) { |
| 143 | if (feature & legacy_logger_feature_set) { |
| 144 | *hidl_caps |= |
| 145 | convertLegacyLoggerFeatureToHidlChipCapability(feature); |
| 146 | } |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 147 | } |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 148 | std::vector<uint64_t> features = {WIFI_FEATURE_SET_TX_POWER_LIMIT, |
Jimmy Chen | d87a0ee | 2018-12-14 15:38:58 +0800 | [diff] [blame] | 149 | WIFI_FEATURE_USE_BODY_HEAD_SAR, |
| 150 | WIFI_FEATURE_D2D_RTT, |
| 151 | WIFI_FEATURE_D2AP_RTT, |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 152 | WIFI_FEATURE_INFRA_60G, |
Jimmy Chen | d87a0ee | 2018-12-14 15:38:58 +0800 | [diff] [blame] | 153 | WIFI_FEATURE_SET_LATENCY_MODE, |
| 154 | WIFI_FEATURE_P2P_RAND_MAC}; |
| 155 | for (const auto feature : features) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 156 | if (feature & legacy_feature_set) { |
| 157 | *hidl_caps |= convertLegacyFeatureToHidlChipCapability(feature); |
| 158 | } |
| 159 | } |
Jimmy Chen | d87a0ee | 2018-12-14 15:38:58 +0800 | [diff] [blame] | 160 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 161 | // There are no flags for these 3 in the legacy feature set. Adding them to |
| 162 | // the set because all the current devices support it. |
| 163 | *hidl_caps |= HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA; |
| 164 | *hidl_caps |= HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS; |
| 165 | *hidl_caps |= HidlChipCaps::DEBUG_ERROR_ALERTS; |
| 166 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | WifiDebugRingBufferFlags convertLegacyDebugRingBufferFlagsToHidl( |
| 170 | uint32_t flag) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 171 | switch (flag) { |
| 172 | case WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES: |
| 173 | return WifiDebugRingBufferFlags::HAS_BINARY_ENTRIES; |
| 174 | case WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES: |
| 175 | return WifiDebugRingBufferFlags::HAS_ASCII_ENTRIES; |
| 176 | }; |
| 177 | CHECK(false) << "Unknown legacy flag: " << flag; |
| 178 | return {}; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | bool convertLegacyDebugRingBufferStatusToHidl( |
| 182 | const legacy_hal::wifi_ring_buffer_status& legacy_status, |
| 183 | WifiDebugRingBufferStatus* hidl_status) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 184 | if (!hidl_status) { |
| 185 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 186 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 187 | *hidl_status = {}; |
| 188 | hidl_status->ringName = |
| 189 | safeConvertChar(reinterpret_cast<const char*>(legacy_status.name), |
| 190 | sizeof(legacy_status.name)); |
| 191 | hidl_status->flags = 0; |
| 192 | for (const auto flag : {WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES, |
| 193 | WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES}) { |
| 194 | if (flag & legacy_status.flags) { |
| 195 | hidl_status->flags |= static_cast< |
| 196 | std::underlying_type<WifiDebugRingBufferFlags>::type>( |
| 197 | convertLegacyDebugRingBufferFlagsToHidl(flag)); |
| 198 | } |
| 199 | } |
| 200 | hidl_status->ringId = legacy_status.ring_id; |
| 201 | hidl_status->sizeInBytes = legacy_status.ring_buffer_byte_size; |
| 202 | // Calculate free size of the ring the buffer. We don't need to send the |
| 203 | // exact read/write pointers that were there in the legacy HAL interface. |
| 204 | if (legacy_status.written_bytes >= legacy_status.read_bytes) { |
| 205 | hidl_status->freeSizeInBytes = |
| 206 | legacy_status.ring_buffer_byte_size - |
| 207 | (legacy_status.written_bytes - legacy_status.read_bytes); |
| 208 | } else { |
| 209 | hidl_status->freeSizeInBytes = |
| 210 | legacy_status.read_bytes - legacy_status.written_bytes; |
| 211 | } |
| 212 | hidl_status->verboseLevel = legacy_status.verbose_level; |
| 213 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | bool convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 217 | const std::vector<legacy_hal::wifi_ring_buffer_status>& legacy_status_vec, |
| 218 | std::vector<WifiDebugRingBufferStatus>* hidl_status_vec) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 219 | if (!hidl_status_vec) { |
| 220 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 221 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 222 | *hidl_status_vec = {}; |
| 223 | for (const auto& legacy_status : legacy_status_vec) { |
| 224 | WifiDebugRingBufferStatus hidl_status; |
| 225 | if (!convertLegacyDebugRingBufferStatusToHidl(legacy_status, |
| 226 | &hidl_status)) { |
| 227 | return false; |
| 228 | } |
| 229 | hidl_status_vec->push_back(hidl_status); |
| 230 | } |
| 231 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | bool convertLegacyWakeReasonStatsToHidl( |
| 235 | const legacy_hal::WakeReasonStats& legacy_stats, |
| 236 | WifiDebugHostWakeReasonStats* hidl_stats) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 237 | if (!hidl_stats) { |
| 238 | return false; |
| 239 | } |
| 240 | *hidl_stats = {}; |
| 241 | hidl_stats->totalCmdEventWakeCnt = |
| 242 | legacy_stats.wake_reason_cnt.total_cmd_event_wake; |
| 243 | hidl_stats->cmdEventWakeCntPerType = legacy_stats.cmd_event_wake_cnt; |
| 244 | hidl_stats->totalDriverFwLocalWakeCnt = |
| 245 | legacy_stats.wake_reason_cnt.total_driver_fw_local_wake; |
| 246 | hidl_stats->driverFwLocalWakeCntPerType = |
| 247 | legacy_stats.driver_fw_local_wake_cnt; |
| 248 | hidl_stats->totalRxPacketWakeCnt = |
| 249 | legacy_stats.wake_reason_cnt.total_rx_data_wake; |
| 250 | hidl_stats->rxPktWakeDetails.rxUnicastCnt = |
| 251 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_unicast_cnt; |
| 252 | hidl_stats->rxPktWakeDetails.rxMulticastCnt = |
| 253 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_multicast_cnt; |
| 254 | hidl_stats->rxPktWakeDetails.rxBroadcastCnt = |
| 255 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_broadcast_cnt; |
| 256 | hidl_stats->rxMulticastPkWakeDetails.ipv4RxMulticastAddrCnt = |
| 257 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 258 | .ipv4_rx_multicast_addr_cnt; |
| 259 | hidl_stats->rxMulticastPkWakeDetails.ipv6RxMulticastAddrCnt = |
| 260 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 261 | .ipv6_rx_multicast_addr_cnt; |
| 262 | hidl_stats->rxMulticastPkWakeDetails.otherRxMulticastAddrCnt = |
| 263 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 264 | .other_rx_multicast_addr_cnt; |
| 265 | hidl_stats->rxIcmpPkWakeDetails.icmpPkt = |
| 266 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp_pkt; |
| 267 | hidl_stats->rxIcmpPkWakeDetails.icmp6Pkt = |
| 268 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_pkt; |
| 269 | hidl_stats->rxIcmpPkWakeDetails.icmp6Ra = |
| 270 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ra; |
| 271 | hidl_stats->rxIcmpPkWakeDetails.icmp6Na = |
| 272 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_na; |
| 273 | hidl_stats->rxIcmpPkWakeDetails.icmp6Ns = |
| 274 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ns; |
| 275 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 278 | legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy( |
| 279 | V1_1::IWifiChip::TxPowerScenario hidl_scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 280 | switch (hidl_scenario) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 281 | // This is the only supported scenario for V1_1 |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 282 | case V1_1::IWifiChip::TxPowerScenario::VOICE_CALL: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 283 | return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; |
| 284 | }; |
| 285 | CHECK(false); |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 288 | legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy_1_2( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 289 | V1_2::IWifiChip::TxPowerScenario hidl_scenario) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 290 | switch (hidl_scenario) { |
| 291 | // This is the only supported scenario for V1_1 |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 292 | case V1_2::IWifiChip::TxPowerScenario::VOICE_CALL: |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 293 | return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; |
| 294 | // Those are the supported scenarios for V1_2 |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 295 | case V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF: |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 296 | return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF; |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 297 | case V1_2::IWifiChip::TxPowerScenario::ON_HEAD_CELL_ON: |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 298 | return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON; |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 299 | case V1_2::IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF: |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 300 | return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF; |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 301 | case V1_2::IWifiChip::TxPowerScenario::ON_BODY_CELL_ON: |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 302 | return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON; |
| 303 | }; |
| 304 | CHECK(false); |
| 305 | } |
| 306 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 307 | legacy_hal::wifi_latency_mode convertHidlLatencyModeToLegacy( |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 308 | V1_3::IWifiChip::LatencyMode hidl_latency_mode) { |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 309 | switch (hidl_latency_mode) { |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 310 | case V1_3::IWifiChip::LatencyMode::NORMAL: |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 311 | return legacy_hal::WIFI_LATENCY_MODE_NORMAL; |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 312 | case V1_3::IWifiChip::LatencyMode::LOW: |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 313 | return legacy_hal::WIFI_LATENCY_MODE_LOW; |
| 314 | } |
| 315 | CHECK(false); |
| 316 | } |
| 317 | |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 318 | bool convertLegacyWifiMacInfoToHidl( |
| 319 | const legacy_hal::WifiMacInfo& legacy_mac_info, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 320 | V1_4::IWifiChipEventCallback::RadioModeInfo* hidl_radio_mode_info) { |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 321 | if (!hidl_radio_mode_info) { |
| 322 | return false; |
| 323 | } |
| 324 | *hidl_radio_mode_info = {}; |
| 325 | |
| 326 | hidl_radio_mode_info->radioId = legacy_mac_info.wlan_mac_id; |
| 327 | // Convert from bitmask of bands in the legacy HAL to enum value in |
| 328 | // the HIDL interface. |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 329 | if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && |
| 330 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND && |
| 331 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 332 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ_5GHZ_6GHZ; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 333 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && |
| 334 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 335 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_5GHZ_6GHZ; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 336 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 337 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_6GHZ; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 338 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND && |
| 339 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 340 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ_5GHZ; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 341 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 342 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_24GHZ; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 343 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 344 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_5GHZ; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 345 | } else { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 346 | hidl_radio_mode_info->bandInfo = V1_4::WifiBand::BAND_UNSPECIFIED; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 347 | } |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 348 | std::vector<V1_2::IWifiChipEventCallback::IfaceInfo> iface_info_vec; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 349 | for (const auto& legacy_iface_info : legacy_mac_info.iface_infos) { |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 350 | V1_2::IWifiChipEventCallback::IfaceInfo iface_info; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 351 | iface_info.name = legacy_iface_info.name; |
| 352 | iface_info.channel = legacy_iface_info.channel; |
| 353 | iface_info_vec.push_back(iface_info); |
| 354 | } |
| 355 | hidl_radio_mode_info->ifaceInfos = iface_info_vec; |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | bool convertLegacyWifiMacInfosToHidl( |
| 360 | const std::vector<legacy_hal::WifiMacInfo>& legacy_mac_infos, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 361 | std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo>* |
| 362 | hidl_radio_mode_infos) { |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 363 | if (!hidl_radio_mode_infos) { |
| 364 | return false; |
| 365 | } |
| 366 | *hidl_radio_mode_infos = {}; |
| 367 | |
| 368 | for (const auto& legacy_mac_info : legacy_mac_infos) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 369 | V1_4::IWifiChipEventCallback::RadioModeInfo hidl_radio_mode_info; |
Roshan Pius | 1a7b1db | 2018-01-22 17:57:20 -0800 | [diff] [blame] | 370 | if (!convertLegacyWifiMacInfoToHidl(legacy_mac_info, |
| 371 | &hidl_radio_mode_info)) { |
| 372 | return false; |
| 373 | } |
| 374 | hidl_radio_mode_infos->push_back(hidl_radio_mode_info); |
| 375 | } |
| 376 | return true; |
| 377 | } |
| 378 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 379 | bool convertLegacyFeaturesToHidlStaCapabilities( |
Ahmed ElArabawy | 95e36b7 | 2019-11-15 21:24:53 +0000 | [diff] [blame] | 380 | uint64_t legacy_feature_set, uint32_t legacy_logger_feature_set, |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 381 | uint32_t* hidl_caps) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 382 | if (!hidl_caps) { |
| 383 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 384 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 385 | *hidl_caps = {}; |
| 386 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 387 | for (const auto feature : {legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED}) { |
| 388 | if (feature & legacy_logger_feature_set) { |
| 389 | *hidl_caps |= |
| 390 | convertLegacyLoggerFeatureToHidlStaIfaceCapability(feature); |
| 391 | } |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 392 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 393 | for (const auto feature : |
| 394 | {WIFI_FEATURE_GSCAN, WIFI_FEATURE_LINK_LAYER_STATS, |
| 395 | WIFI_FEATURE_RSSI_MONITOR, WIFI_FEATURE_CONTROL_ROAMING, |
| 396 | WIFI_FEATURE_IE_WHITELIST, WIFI_FEATURE_SCAN_RAND, |
| 397 | WIFI_FEATURE_INFRA_5G, WIFI_FEATURE_HOTSPOT, WIFI_FEATURE_PNO, |
| 398 | WIFI_FEATURE_TDLS, WIFI_FEATURE_TDLS_OFFCHANNEL, |
Ahmed ElArabawy | b23485d | 2019-12-09 15:24:16 -0800 | [diff] [blame] | 399 | WIFI_FEATURE_CONFIG_NDO, WIFI_FEATURE_MKEEP_ALIVE}) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 400 | if (feature & legacy_feature_set) { |
| 401 | *hidl_caps |= convertLegacyFeatureToHidlStaIfaceCapability(feature); |
| 402 | } |
| 403 | } |
| 404 | // There is no flag for this one in the legacy feature set. Adding it to the |
| 405 | // set because all the current devices support it. |
| 406 | *hidl_caps |= HidlStaIfaceCaps::APF; |
| 407 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | bool convertLegacyApfCapabilitiesToHidl( |
| 411 | const legacy_hal::PacketFilterCapabilities& legacy_caps, |
| 412 | StaApfPacketFilterCapabilities* hidl_caps) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 413 | if (!hidl_caps) { |
| 414 | return false; |
| 415 | } |
| 416 | *hidl_caps = {}; |
| 417 | hidl_caps->version = legacy_caps.version; |
| 418 | hidl_caps->maxLength = legacy_caps.max_len; |
| 419 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 422 | uint8_t convertHidlGscanReportEventFlagToLegacy( |
| 423 | StaBackgroundScanBucketEventReportSchemeMask hidl_flag) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 424 | using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 425 | switch (hidl_flag) { |
| 426 | case HidlFlag::EACH_SCAN: |
| 427 | return REPORT_EVENTS_EACH_SCAN; |
| 428 | case HidlFlag::FULL_RESULTS: |
| 429 | return REPORT_EVENTS_FULL_RESULTS; |
| 430 | case HidlFlag::NO_BATCH: |
| 431 | return REPORT_EVENTS_NO_BATCH; |
| 432 | }; |
| 433 | CHECK(false); |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | StaScanDataFlagMask convertLegacyGscanDataFlagToHidl(uint8_t legacy_flag) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 437 | switch (legacy_flag) { |
| 438 | case legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED: |
| 439 | return StaScanDataFlagMask::INTERRUPTED; |
| 440 | }; |
| 441 | CHECK(false) << "Unknown legacy flag: " << legacy_flag; |
| 442 | // To silence the compiler warning about reaching the end of non-void |
| 443 | // function. |
| 444 | return {}; |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | bool convertLegacyGscanCapabilitiesToHidl( |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 448 | const legacy_hal::wifi_gscan_capabilities& legacy_caps, |
| 449 | StaBackgroundScanCapabilities* hidl_caps) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 450 | if (!hidl_caps) { |
| 451 | return false; |
| 452 | } |
| 453 | *hidl_caps = {}; |
| 454 | hidl_caps->maxCacheSize = legacy_caps.max_scan_cache_size; |
| 455 | hidl_caps->maxBuckets = legacy_caps.max_scan_buckets; |
| 456 | hidl_caps->maxApCachePerScan = legacy_caps.max_ap_cache_per_scan; |
| 457 | hidl_caps->maxReportingThreshold = legacy_caps.max_scan_reporting_threshold; |
| 458 | return true; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 461 | legacy_hal::wifi_band convertHidlWifiBandToLegacy(V1_0::WifiBand band) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 462 | switch (band) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 463 | case V1_0::WifiBand::BAND_UNSPECIFIED: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 464 | return legacy_hal::WIFI_BAND_UNSPECIFIED; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 465 | case V1_0::WifiBand::BAND_24GHZ: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 466 | return legacy_hal::WIFI_BAND_BG; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 467 | case V1_0::WifiBand::BAND_5GHZ: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 468 | return legacy_hal::WIFI_BAND_A; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 469 | case V1_0::WifiBand::BAND_5GHZ_DFS: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 470 | return legacy_hal::WIFI_BAND_A_DFS; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 471 | case V1_0::WifiBand::BAND_5GHZ_WITH_DFS: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 472 | return legacy_hal::WIFI_BAND_A_WITH_DFS; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 473 | case V1_0::WifiBand::BAND_24GHZ_5GHZ: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 474 | return legacy_hal::WIFI_BAND_ABG; |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 475 | case V1_0::WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 476 | return legacy_hal::WIFI_BAND_ABG_WITH_DFS; |
| 477 | }; |
| 478 | CHECK(false); |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | bool convertHidlGscanParamsToLegacy( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 482 | const StaBackgroundScanParameters& hidl_scan_params, |
| 483 | legacy_hal::wifi_scan_cmd_params* legacy_scan_params) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 484 | if (!legacy_scan_params) { |
| 485 | return false; |
Roshan Pius | 4cf4059 | 2017-03-07 11:17:08 -0800 | [diff] [blame] | 486 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 487 | *legacy_scan_params = {}; |
| 488 | legacy_scan_params->base_period = hidl_scan_params.basePeriodInMs; |
| 489 | legacy_scan_params->max_ap_per_scan = hidl_scan_params.maxApPerScan; |
| 490 | legacy_scan_params->report_threshold_percent = |
| 491 | hidl_scan_params.reportThresholdPercent; |
| 492 | legacy_scan_params->report_threshold_num_scans = |
| 493 | hidl_scan_params.reportThresholdNumScans; |
| 494 | if (hidl_scan_params.buckets.size() > MAX_BUCKETS) { |
| 495 | return false; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 496 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 497 | legacy_scan_params->num_buckets = hidl_scan_params.buckets.size(); |
| 498 | for (uint32_t bucket_idx = 0; bucket_idx < hidl_scan_params.buckets.size(); |
| 499 | bucket_idx++) { |
| 500 | const StaBackgroundScanBucketParameters& hidl_bucket_spec = |
| 501 | hidl_scan_params.buckets[bucket_idx]; |
| 502 | legacy_hal::wifi_scan_bucket_spec& legacy_bucket_spec = |
| 503 | legacy_scan_params->buckets[bucket_idx]; |
| 504 | if (hidl_bucket_spec.bucketIdx >= MAX_BUCKETS) { |
| 505 | return false; |
| 506 | } |
| 507 | legacy_bucket_spec.bucket = hidl_bucket_spec.bucketIdx; |
| 508 | legacy_bucket_spec.band = |
| 509 | convertHidlWifiBandToLegacy(hidl_bucket_spec.band); |
| 510 | legacy_bucket_spec.period = hidl_bucket_spec.periodInMs; |
| 511 | legacy_bucket_spec.max_period = |
| 512 | hidl_bucket_spec.exponentialMaxPeriodInMs; |
| 513 | legacy_bucket_spec.base = hidl_bucket_spec.exponentialBase; |
| 514 | legacy_bucket_spec.step_count = hidl_bucket_spec.exponentialStepCount; |
| 515 | legacy_bucket_spec.report_events = 0; |
| 516 | using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 517 | for (const auto flag : {HidlFlag::EACH_SCAN, HidlFlag::FULL_RESULTS, |
| 518 | HidlFlag::NO_BATCH}) { |
| 519 | if (hidl_bucket_spec.eventReportScheme & |
| 520 | static_cast<std::underlying_type<HidlFlag>::type>(flag)) { |
| 521 | legacy_bucket_spec.report_events |= |
| 522 | convertHidlGscanReportEventFlagToLegacy(flag); |
| 523 | } |
| 524 | } |
| 525 | if (hidl_bucket_spec.frequencies.size() > MAX_CHANNELS) { |
| 526 | return false; |
| 527 | } |
| 528 | legacy_bucket_spec.num_channels = hidl_bucket_spec.frequencies.size(); |
| 529 | for (uint32_t freq_idx = 0; |
| 530 | freq_idx < hidl_bucket_spec.frequencies.size(); freq_idx++) { |
| 531 | legacy_bucket_spec.channels[freq_idx].channel = |
| 532 | hidl_bucket_spec.frequencies[freq_idx]; |
| 533 | } |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 534 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 535 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 538 | bool convertLegacyIeToHidl( |
| 539 | const legacy_hal::wifi_information_element& legacy_ie, |
| 540 | WifiInformationElement* hidl_ie) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 541 | if (!hidl_ie) { |
| 542 | return false; |
| 543 | } |
| 544 | *hidl_ie = {}; |
| 545 | hidl_ie->id = legacy_ie.id; |
| 546 | hidl_ie->data = |
| 547 | std::vector<uint8_t>(legacy_ie.data, legacy_ie.data + legacy_ie.len); |
| 548 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 551 | bool convertLegacyIeBlobToHidl(const uint8_t* ie_blob, uint32_t ie_blob_len, |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 552 | std::vector<WifiInformationElement>* hidl_ies) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 553 | if (!ie_blob || !hidl_ies) { |
| 554 | return false; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 555 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 556 | *hidl_ies = {}; |
| 557 | const uint8_t* ies_begin = ie_blob; |
| 558 | const uint8_t* ies_end = ie_blob + ie_blob_len; |
| 559 | const uint8_t* next_ie = ies_begin; |
| 560 | using wifi_ie = legacy_hal::wifi_information_element; |
| 561 | constexpr size_t kIeHeaderLen = sizeof(wifi_ie); |
| 562 | // Each IE should atleast have the header (i.e |id| & |len| fields). |
| 563 | while (next_ie + kIeHeaderLen <= ies_end) { |
| 564 | const wifi_ie& legacy_ie = (*reinterpret_cast<const wifi_ie*>(next_ie)); |
| 565 | uint32_t curr_ie_len = kIeHeaderLen + legacy_ie.len; |
| 566 | if (next_ie + curr_ie_len > ies_end) { |
| 567 | LOG(ERROR) << "Error parsing IE blob. Next IE: " << (void*)next_ie |
| 568 | << ", Curr IE len: " << curr_ie_len |
| 569 | << ", IEs End: " << (void*)ies_end; |
| 570 | break; |
| 571 | } |
| 572 | WifiInformationElement hidl_ie; |
| 573 | if (!convertLegacyIeToHidl(legacy_ie, &hidl_ie)) { |
| 574 | LOG(ERROR) << "Error converting IE. Id: " << legacy_ie.id |
| 575 | << ", len: " << legacy_ie.len; |
| 576 | break; |
| 577 | } |
| 578 | hidl_ies->push_back(std::move(hidl_ie)); |
| 579 | next_ie += curr_ie_len; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 580 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 581 | // Check if the blob has been fully consumed. |
| 582 | if (next_ie != ies_end) { |
| 583 | LOG(ERROR) << "Failed to fully parse IE blob. Next IE: " |
| 584 | << (void*)next_ie << ", IEs End: " << (void*)ies_end; |
| 585 | } |
| 586 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 587 | } |
| 588 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 589 | bool convertLegacyGscanResultToHidl( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 590 | const legacy_hal::wifi_scan_result& legacy_scan_result, bool has_ie_data, |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 591 | StaScanResult* hidl_scan_result) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 592 | if (!hidl_scan_result) { |
| 593 | return false; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 594 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 595 | *hidl_scan_result = {}; |
| 596 | hidl_scan_result->timeStampInUs = legacy_scan_result.ts; |
| 597 | hidl_scan_result->ssid = std::vector<uint8_t>( |
| 598 | legacy_scan_result.ssid, |
| 599 | legacy_scan_result.ssid + strnlen(legacy_scan_result.ssid, |
| 600 | sizeof(legacy_scan_result.ssid) - 1)); |
| 601 | memcpy(hidl_scan_result->bssid.data(), legacy_scan_result.bssid, |
| 602 | hidl_scan_result->bssid.size()); |
| 603 | hidl_scan_result->frequency = legacy_scan_result.channel; |
| 604 | hidl_scan_result->rssi = legacy_scan_result.rssi; |
| 605 | hidl_scan_result->beaconPeriodInMs = legacy_scan_result.beacon_period; |
| 606 | hidl_scan_result->capability = legacy_scan_result.capability; |
| 607 | if (has_ie_data) { |
| 608 | std::vector<WifiInformationElement> ies; |
| 609 | if (!convertLegacyIeBlobToHidl( |
| 610 | reinterpret_cast<const uint8_t*>(legacy_scan_result.ie_data), |
| 611 | legacy_scan_result.ie_length, &ies)) { |
| 612 | return false; |
| 613 | } |
| 614 | hidl_scan_result->informationElements = std::move(ies); |
| 615 | } |
| 616 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 619 | bool convertLegacyCachedGscanResultsToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 620 | const legacy_hal::wifi_cached_scan_results& legacy_cached_scan_result, |
| 621 | StaScanData* hidl_scan_data) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 622 | if (!hidl_scan_data) { |
| 623 | return false; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 624 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 625 | *hidl_scan_data = {}; |
| 626 | hidl_scan_data->flags = 0; |
| 627 | for (const auto flag : {legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED}) { |
| 628 | if (legacy_cached_scan_result.flags & flag) { |
| 629 | hidl_scan_data->flags |= |
| 630 | static_cast<std::underlying_type<StaScanDataFlagMask>::type>( |
| 631 | convertLegacyGscanDataFlagToHidl(flag)); |
| 632 | } |
| 633 | } |
| 634 | hidl_scan_data->bucketsScanned = legacy_cached_scan_result.buckets_scanned; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 635 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 636 | CHECK(legacy_cached_scan_result.num_results >= 0 && |
| 637 | legacy_cached_scan_result.num_results <= MAX_AP_CACHE_PER_SCAN); |
| 638 | std::vector<StaScanResult> hidl_scan_results; |
| 639 | for (int32_t result_idx = 0; |
| 640 | result_idx < legacy_cached_scan_result.num_results; result_idx++) { |
| 641 | StaScanResult hidl_scan_result; |
| 642 | if (!convertLegacyGscanResultToHidl( |
| 643 | legacy_cached_scan_result.results[result_idx], false, |
| 644 | &hidl_scan_result)) { |
| 645 | return false; |
| 646 | } |
| 647 | hidl_scan_results.push_back(hidl_scan_result); |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 648 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 649 | hidl_scan_data->results = std::move(hidl_scan_results); |
| 650 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 653 | bool convertLegacyVectorOfCachedGscanResultsToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 654 | const std::vector<legacy_hal::wifi_cached_scan_results>& |
| 655 | legacy_cached_scan_results, |
| 656 | std::vector<StaScanData>* hidl_scan_datas) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 657 | if (!hidl_scan_datas) { |
| 658 | return false; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 659 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 660 | *hidl_scan_datas = {}; |
| 661 | for (const auto& legacy_cached_scan_result : legacy_cached_scan_results) { |
| 662 | StaScanData hidl_scan_data; |
| 663 | if (!convertLegacyCachedGscanResultsToHidl(legacy_cached_scan_result, |
| 664 | &hidl_scan_data)) { |
| 665 | return false; |
| 666 | } |
| 667 | hidl_scan_datas->push_back(hidl_scan_data); |
| 668 | } |
| 669 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 672 | WifiDebugTxPacketFate convertLegacyDebugTxPacketFateToHidl( |
| 673 | legacy_hal::wifi_tx_packet_fate fate) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 674 | switch (fate) { |
| 675 | case legacy_hal::TX_PKT_FATE_ACKED: |
| 676 | return WifiDebugTxPacketFate::ACKED; |
| 677 | case legacy_hal::TX_PKT_FATE_SENT: |
| 678 | return WifiDebugTxPacketFate::SENT; |
| 679 | case legacy_hal::TX_PKT_FATE_FW_QUEUED: |
| 680 | return WifiDebugTxPacketFate::FW_QUEUED; |
| 681 | case legacy_hal::TX_PKT_FATE_FW_DROP_INVALID: |
| 682 | return WifiDebugTxPacketFate::FW_DROP_INVALID; |
| 683 | case legacy_hal::TX_PKT_FATE_FW_DROP_NOBUFS: |
| 684 | return WifiDebugTxPacketFate::FW_DROP_NOBUFS; |
| 685 | case legacy_hal::TX_PKT_FATE_FW_DROP_OTHER: |
| 686 | return WifiDebugTxPacketFate::FW_DROP_OTHER; |
| 687 | case legacy_hal::TX_PKT_FATE_DRV_QUEUED: |
| 688 | return WifiDebugTxPacketFate::DRV_QUEUED; |
| 689 | case legacy_hal::TX_PKT_FATE_DRV_DROP_INVALID: |
| 690 | return WifiDebugTxPacketFate::DRV_DROP_INVALID; |
| 691 | case legacy_hal::TX_PKT_FATE_DRV_DROP_NOBUFS: |
| 692 | return WifiDebugTxPacketFate::DRV_DROP_NOBUFS; |
| 693 | case legacy_hal::TX_PKT_FATE_DRV_DROP_OTHER: |
| 694 | return WifiDebugTxPacketFate::DRV_DROP_OTHER; |
| 695 | }; |
| 696 | CHECK(false) << "Unknown legacy fate type: " << fate; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | WifiDebugRxPacketFate convertLegacyDebugRxPacketFateToHidl( |
| 700 | legacy_hal::wifi_rx_packet_fate fate) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 701 | switch (fate) { |
| 702 | case legacy_hal::RX_PKT_FATE_SUCCESS: |
| 703 | return WifiDebugRxPacketFate::SUCCESS; |
| 704 | case legacy_hal::RX_PKT_FATE_FW_QUEUED: |
| 705 | return WifiDebugRxPacketFate::FW_QUEUED; |
| 706 | case legacy_hal::RX_PKT_FATE_FW_DROP_FILTER: |
| 707 | return WifiDebugRxPacketFate::FW_DROP_FILTER; |
| 708 | case legacy_hal::RX_PKT_FATE_FW_DROP_INVALID: |
| 709 | return WifiDebugRxPacketFate::FW_DROP_INVALID; |
| 710 | case legacy_hal::RX_PKT_FATE_FW_DROP_NOBUFS: |
| 711 | return WifiDebugRxPacketFate::FW_DROP_NOBUFS; |
| 712 | case legacy_hal::RX_PKT_FATE_FW_DROP_OTHER: |
| 713 | return WifiDebugRxPacketFate::FW_DROP_OTHER; |
| 714 | case legacy_hal::RX_PKT_FATE_DRV_QUEUED: |
| 715 | return WifiDebugRxPacketFate::DRV_QUEUED; |
| 716 | case legacy_hal::RX_PKT_FATE_DRV_DROP_FILTER: |
| 717 | return WifiDebugRxPacketFate::DRV_DROP_FILTER; |
| 718 | case legacy_hal::RX_PKT_FATE_DRV_DROP_INVALID: |
| 719 | return WifiDebugRxPacketFate::DRV_DROP_INVALID; |
| 720 | case legacy_hal::RX_PKT_FATE_DRV_DROP_NOBUFS: |
| 721 | return WifiDebugRxPacketFate::DRV_DROP_NOBUFS; |
| 722 | case legacy_hal::RX_PKT_FATE_DRV_DROP_OTHER: |
| 723 | return WifiDebugRxPacketFate::DRV_DROP_OTHER; |
| 724 | }; |
| 725 | CHECK(false) << "Unknown legacy fate type: " << fate; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | WifiDebugPacketFateFrameType convertLegacyDebugPacketFateFrameTypeToHidl( |
| 729 | legacy_hal::frame_type type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 730 | switch (type) { |
| 731 | case legacy_hal::FRAME_TYPE_UNKNOWN: |
| 732 | return WifiDebugPacketFateFrameType::UNKNOWN; |
| 733 | case legacy_hal::FRAME_TYPE_ETHERNET_II: |
| 734 | return WifiDebugPacketFateFrameType::ETHERNET_II; |
| 735 | case legacy_hal::FRAME_TYPE_80211_MGMT: |
| 736 | return WifiDebugPacketFateFrameType::MGMT_80211; |
| 737 | }; |
| 738 | CHECK(false) << "Unknown legacy frame type: " << type; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | bool convertLegacyDebugPacketFateFrameToHidl( |
| 742 | const legacy_hal::frame_info& legacy_frame, |
| 743 | WifiDebugPacketFateFrameInfo* hidl_frame) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 744 | if (!hidl_frame) { |
| 745 | return false; |
| 746 | } |
| 747 | *hidl_frame = {}; |
| 748 | hidl_frame->frameType = |
| 749 | convertLegacyDebugPacketFateFrameTypeToHidl(legacy_frame.payload_type); |
| 750 | hidl_frame->frameLen = legacy_frame.frame_len; |
| 751 | hidl_frame->driverTimestampUsec = legacy_frame.driver_timestamp_usec; |
| 752 | hidl_frame->firmwareTimestampUsec = legacy_frame.firmware_timestamp_usec; |
| 753 | const uint8_t* frame_begin = reinterpret_cast<const uint8_t*>( |
| 754 | legacy_frame.frame_content.ethernet_ii_bytes); |
| 755 | hidl_frame->frameContent = |
| 756 | std::vector<uint8_t>(frame_begin, frame_begin + legacy_frame.frame_len); |
| 757 | return true; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | bool convertLegacyDebugTxPacketFateToHidl( |
| 761 | const legacy_hal::wifi_tx_report& legacy_fate, |
| 762 | WifiDebugTxPacketFateReport* hidl_fate) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 763 | if (!hidl_fate) { |
| 764 | return false; |
| 765 | } |
| 766 | *hidl_fate = {}; |
| 767 | hidl_fate->fate = convertLegacyDebugTxPacketFateToHidl(legacy_fate.fate); |
| 768 | return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, |
| 769 | &hidl_fate->frameInfo); |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 772 | bool convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 773 | const std::vector<legacy_hal::wifi_tx_report>& legacy_fates, |
| 774 | std::vector<WifiDebugTxPacketFateReport>* hidl_fates) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 775 | if (!hidl_fates) { |
| 776 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 777 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 778 | *hidl_fates = {}; |
| 779 | for (const auto& legacy_fate : legacy_fates) { |
| 780 | WifiDebugTxPacketFateReport hidl_fate; |
| 781 | if (!convertLegacyDebugTxPacketFateToHidl(legacy_fate, &hidl_fate)) { |
| 782 | return false; |
| 783 | } |
| 784 | hidl_fates->push_back(hidl_fate); |
| 785 | } |
| 786 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 789 | bool convertLegacyDebugRxPacketFateToHidl( |
| 790 | const legacy_hal::wifi_rx_report& legacy_fate, |
| 791 | WifiDebugRxPacketFateReport* hidl_fate) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 792 | if (!hidl_fate) { |
| 793 | return false; |
| 794 | } |
| 795 | *hidl_fate = {}; |
| 796 | hidl_fate->fate = convertLegacyDebugRxPacketFateToHidl(legacy_fate.fate); |
| 797 | return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, |
| 798 | &hidl_fate->frameInfo); |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 799 | } |
| 800 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 801 | bool convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 802 | const std::vector<legacy_hal::wifi_rx_report>& legacy_fates, |
| 803 | std::vector<WifiDebugRxPacketFateReport>* hidl_fates) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 804 | if (!hidl_fates) { |
| 805 | return false; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 806 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 807 | *hidl_fates = {}; |
| 808 | for (const auto& legacy_fate : legacy_fates) { |
| 809 | WifiDebugRxPacketFateReport hidl_fate; |
| 810 | if (!convertLegacyDebugRxPacketFateToHidl(legacy_fate, &hidl_fate)) { |
| 811 | return false; |
| 812 | } |
| 813 | hidl_fates->push_back(hidl_fate); |
| 814 | } |
| 815 | return true; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 818 | bool convertLegacyLinkLayerRadioStatsToHidl( |
| 819 | const legacy_hal::LinkLayerRadioStats& legacy_radio_stat, |
| 820 | V1_3::StaLinkLayerRadioStats* hidl_radio_stat) { |
| 821 | if (!hidl_radio_stat) { |
| 822 | return false; |
| 823 | } |
| 824 | *hidl_radio_stat = {}; |
| 825 | |
| 826 | hidl_radio_stat->V1_0.onTimeInMs = legacy_radio_stat.stats.on_time; |
| 827 | hidl_radio_stat->V1_0.txTimeInMs = legacy_radio_stat.stats.tx_time; |
| 828 | hidl_radio_stat->V1_0.rxTimeInMs = legacy_radio_stat.stats.rx_time; |
| 829 | hidl_radio_stat->V1_0.onTimeInMsForScan = |
| 830 | legacy_radio_stat.stats.on_time_scan; |
| 831 | hidl_radio_stat->V1_0.txTimeInMsPerLevel = |
| 832 | legacy_radio_stat.tx_time_per_levels; |
| 833 | hidl_radio_stat->onTimeInMsForNanScan = legacy_radio_stat.stats.on_time_nbd; |
| 834 | hidl_radio_stat->onTimeInMsForBgScan = |
| 835 | legacy_radio_stat.stats.on_time_gscan; |
| 836 | hidl_radio_stat->onTimeInMsForRoamScan = |
| 837 | legacy_radio_stat.stats.on_time_roam_scan; |
| 838 | hidl_radio_stat->onTimeInMsForPnoScan = |
| 839 | legacy_radio_stat.stats.on_time_pno_scan; |
| 840 | hidl_radio_stat->onTimeInMsForHs20Scan = |
| 841 | legacy_radio_stat.stats.on_time_hs20; |
| 842 | |
| 843 | std::vector<V1_3::WifiChannelStats> hidl_channel_stats; |
| 844 | |
| 845 | for (const auto& channel_stat : legacy_radio_stat.channel_stats) { |
| 846 | V1_3::WifiChannelStats hidl_channel_stat; |
| 847 | hidl_channel_stat.onTimeInMs = channel_stat.on_time; |
| 848 | hidl_channel_stat.ccaBusyTimeInMs = channel_stat.cca_busy_time; |
| 849 | /* |
| 850 | * TODO once b/119142899 is fixed, |
| 851 | * replace below code with convertLegacyWifiChannelInfoToHidl() |
| 852 | */ |
| 853 | hidl_channel_stat.channel.width = WifiChannelWidthInMhz::WIDTH_20; |
| 854 | hidl_channel_stat.channel.centerFreq = channel_stat.channel.center_freq; |
| 855 | hidl_channel_stat.channel.centerFreq0 = |
| 856 | channel_stat.channel.center_freq0; |
| 857 | hidl_channel_stat.channel.centerFreq1 = |
| 858 | channel_stat.channel.center_freq1; |
| 859 | hidl_channel_stats.push_back(hidl_channel_stat); |
| 860 | } |
| 861 | |
| 862 | hidl_radio_stat->channelStats = hidl_channel_stats; |
| 863 | |
| 864 | return true; |
| 865 | } |
| 866 | |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 867 | bool convertLegacyLinkLayerStatsToHidl( |
| 868 | const legacy_hal::LinkLayerStats& legacy_stats, |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 869 | StaLinkLayerStats* hidl_stats) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 870 | if (!hidl_stats) { |
| 871 | return false; |
| 872 | } |
| 873 | *hidl_stats = {}; |
| 874 | // iface legacy_stats conversion. |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 875 | hidl_stats->iface.V1_0.beaconRx = legacy_stats.iface.beacon_rx; |
| 876 | hidl_stats->iface.V1_0.avgRssiMgmt = legacy_stats.iface.rssi_mgmt; |
| 877 | hidl_stats->iface.V1_0.wmeBePktStats.rxMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 878 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 879 | hidl_stats->iface.V1_0.wmeBePktStats.txMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 880 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 881 | hidl_stats->iface.V1_0.wmeBePktStats.lostMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 882 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 883 | hidl_stats->iface.V1_0.wmeBePktStats.retries = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 884 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 885 | hidl_stats->iface.V1_0.wmeBkPktStats.rxMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 886 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 887 | hidl_stats->iface.V1_0.wmeBkPktStats.txMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 888 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 889 | hidl_stats->iface.V1_0.wmeBkPktStats.lostMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 890 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 891 | hidl_stats->iface.V1_0.wmeBkPktStats.retries = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 892 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 893 | hidl_stats->iface.V1_0.wmeViPktStats.rxMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 894 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 895 | hidl_stats->iface.V1_0.wmeViPktStats.txMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 896 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 897 | hidl_stats->iface.V1_0.wmeViPktStats.lostMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 898 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 899 | hidl_stats->iface.V1_0.wmeViPktStats.retries = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 900 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 901 | hidl_stats->iface.V1_0.wmeVoPktStats.rxMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 902 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 903 | hidl_stats->iface.V1_0.wmeVoPktStats.txMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 904 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 905 | hidl_stats->iface.V1_0.wmeVoPktStats.lostMpdu = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 906 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 907 | hidl_stats->iface.V1_0.wmeVoPktStats.retries = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 908 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries; |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 909 | hidl_stats->iface.timeSliceDutyCycleInPercent = |
| 910 | legacy_stats.iface.info.time_slicing_duty_cycle_percent; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 911 | // radio legacy_stats conversion. |
xshu | e987325 | 2018-08-07 11:04:34 -0700 | [diff] [blame] | 912 | std::vector<V1_3::StaLinkLayerRadioStats> hidl_radios_stats; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 913 | for (const auto& legacy_radio_stats : legacy_stats.radios) { |
xshu | e987325 | 2018-08-07 11:04:34 -0700 | [diff] [blame] | 914 | V1_3::StaLinkLayerRadioStats hidl_radio_stats; |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 915 | if (!convertLegacyLinkLayerRadioStatsToHidl(legacy_radio_stats, |
| 916 | &hidl_radio_stats)) { |
| 917 | return false; |
| 918 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 919 | hidl_radios_stats.push_back(hidl_radio_stats); |
| 920 | } |
| 921 | hidl_stats->radios = hidl_radios_stats; |
| 922 | // Timestamp in the HAL wrapper here since it's not provided in the legacy |
| 923 | // HAL API. |
| 924 | hidl_stats->timeStampInMs = uptimeMillis(); |
| 925 | return true; |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 926 | } |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 927 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 928 | bool convertLegacyRoamingCapabilitiesToHidl( |
| 929 | const legacy_hal::wifi_roaming_capabilities& legacy_caps, |
| 930 | StaRoamingCapabilities* hidl_caps) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 931 | if (!hidl_caps) { |
| 932 | return false; |
| 933 | } |
| 934 | *hidl_caps = {}; |
| 935 | hidl_caps->maxBlacklistSize = legacy_caps.max_blacklist_size; |
| 936 | hidl_caps->maxWhitelistSize = legacy_caps.max_whitelist_size; |
| 937 | return true; |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | bool convertHidlRoamingConfigToLegacy( |
| 941 | const StaRoamingConfig& hidl_config, |
| 942 | legacy_hal::wifi_roaming_config* legacy_config) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 943 | if (!legacy_config) { |
| 944 | return false; |
| 945 | } |
| 946 | *legacy_config = {}; |
| 947 | if (hidl_config.bssidBlacklist.size() > MAX_BLACKLIST_BSSID || |
| 948 | hidl_config.ssidWhitelist.size() > MAX_WHITELIST_SSID) { |
| 949 | return false; |
| 950 | } |
| 951 | legacy_config->num_blacklist_bssid = hidl_config.bssidBlacklist.size(); |
| 952 | uint32_t i = 0; |
| 953 | for (const auto& bssid : hidl_config.bssidBlacklist) { |
| 954 | CHECK(bssid.size() == sizeof(legacy_hal::mac_addr)); |
| 955 | memcpy(legacy_config->blacklist_bssid[i++], bssid.data(), bssid.size()); |
| 956 | } |
| 957 | legacy_config->num_whitelist_ssid = hidl_config.ssidWhitelist.size(); |
| 958 | i = 0; |
| 959 | for (const auto& ssid : hidl_config.ssidWhitelist) { |
| 960 | CHECK(ssid.size() <= sizeof(legacy_hal::ssid_t::ssid_str)); |
| 961 | legacy_config->whitelist_ssid[i].length = ssid.size(); |
| 962 | memcpy(legacy_config->whitelist_ssid[i].ssid_str, ssid.data(), |
| 963 | ssid.size()); |
| 964 | i++; |
| 965 | } |
| 966 | return true; |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy( |
| 970 | StaRoamingState state) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 971 | switch (state) { |
| 972 | case StaRoamingState::ENABLED: |
| 973 | return legacy_hal::ROAMING_ENABLE; |
| 974 | case StaRoamingState::DISABLED: |
| 975 | return legacy_hal::ROAMING_DISABLE; |
| 976 | }; |
| 977 | CHECK(false); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 978 | } |
| 979 | |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 980 | legacy_hal::NanMatchAlg convertHidlNanMatchAlgToLegacy(NanMatchAlg type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 981 | switch (type) { |
| 982 | case NanMatchAlg::MATCH_ONCE: |
| 983 | return legacy_hal::NAN_MATCH_ALG_MATCH_ONCE; |
| 984 | case NanMatchAlg::MATCH_CONTINUOUS: |
| 985 | return legacy_hal::NAN_MATCH_ALG_MATCH_CONTINUOUS; |
| 986 | case NanMatchAlg::MATCH_NEVER: |
| 987 | return legacy_hal::NAN_MATCH_ALG_MATCH_NEVER; |
| 988 | } |
| 989 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 992 | legacy_hal::NanPublishType convertHidlNanPublishTypeToLegacy( |
| 993 | NanPublishType type) { |
| 994 | switch (type) { |
| 995 | case NanPublishType::UNSOLICITED: |
| 996 | return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED; |
| 997 | case NanPublishType::SOLICITED: |
| 998 | return legacy_hal::NAN_PUBLISH_TYPE_SOLICITED; |
| 999 | case NanPublishType::UNSOLICITED_SOLICITED: |
| 1000 | return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED; |
| 1001 | } |
| 1002 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | legacy_hal::NanTxType convertHidlNanTxTypeToLegacy(NanTxType type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1006 | switch (type) { |
| 1007 | case NanTxType::BROADCAST: |
| 1008 | return legacy_hal::NAN_TX_TYPE_BROADCAST; |
| 1009 | case NanTxType::UNICAST: |
| 1010 | return legacy_hal::NAN_TX_TYPE_UNICAST; |
| 1011 | } |
| 1012 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1015 | legacy_hal::NanSubscribeType convertHidlNanSubscribeTypeToLegacy( |
| 1016 | NanSubscribeType type) { |
| 1017 | switch (type) { |
| 1018 | case NanSubscribeType::PASSIVE: |
| 1019 | return legacy_hal::NAN_SUBSCRIBE_TYPE_PASSIVE; |
| 1020 | case NanSubscribeType::ACTIVE: |
| 1021 | return legacy_hal::NAN_SUBSCRIBE_TYPE_ACTIVE; |
| 1022 | } |
| 1023 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | legacy_hal::NanSRFType convertHidlNanSrfTypeToLegacy(NanSrfType type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1027 | switch (type) { |
| 1028 | case NanSrfType::BLOOM_FILTER: |
| 1029 | return legacy_hal::NAN_SRF_ATTR_BLOOM_FILTER; |
| 1030 | case NanSrfType::PARTIAL_MAC_ADDR: |
| 1031 | return legacy_hal::NAN_SRF_ATTR_PARTIAL_MAC_ADDR; |
| 1032 | } |
| 1033 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | legacy_hal::NanDataPathChannelCfg convertHidlNanDataPathChannelCfgToLegacy( |
| 1037 | NanDataPathChannelCfg type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1038 | switch (type) { |
| 1039 | case NanDataPathChannelCfg::CHANNEL_NOT_REQUESTED: |
| 1040 | return legacy_hal::NAN_DP_CHANNEL_NOT_REQUESTED; |
| 1041 | case NanDataPathChannelCfg::REQUEST_CHANNEL_SETUP: |
| 1042 | return legacy_hal::NAN_DP_REQUEST_CHANNEL_SETUP; |
| 1043 | case NanDataPathChannelCfg::FORCE_CHANNEL_SETUP: |
| 1044 | return legacy_hal::NAN_DP_FORCE_CHANNEL_SETUP; |
| 1045 | } |
| 1046 | CHECK(false); |
Etan Cohen | 67d378d | 2017-04-03 16:10:54 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1049 | NanStatusType convertLegacyNanStatusTypeToHidl(legacy_hal::NanStatusType type) { |
| 1050 | switch (type) { |
| 1051 | case legacy_hal::NAN_STATUS_SUCCESS: |
| 1052 | return NanStatusType::SUCCESS; |
| 1053 | case legacy_hal::NAN_STATUS_INTERNAL_FAILURE: |
| 1054 | return NanStatusType::INTERNAL_FAILURE; |
| 1055 | case legacy_hal::NAN_STATUS_PROTOCOL_FAILURE: |
| 1056 | return NanStatusType::PROTOCOL_FAILURE; |
| 1057 | case legacy_hal::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID: |
| 1058 | return NanStatusType::INVALID_SESSION_ID; |
| 1059 | case legacy_hal::NAN_STATUS_NO_RESOURCE_AVAILABLE: |
| 1060 | return NanStatusType::NO_RESOURCES_AVAILABLE; |
| 1061 | case legacy_hal::NAN_STATUS_INVALID_PARAM: |
| 1062 | return NanStatusType::INVALID_ARGS; |
| 1063 | case legacy_hal::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID: |
| 1064 | return NanStatusType::INVALID_PEER_ID; |
| 1065 | case legacy_hal::NAN_STATUS_INVALID_NDP_ID: |
| 1066 | return NanStatusType::INVALID_NDP_ID; |
| 1067 | case legacy_hal::NAN_STATUS_NAN_NOT_ALLOWED: |
| 1068 | return NanStatusType::NAN_NOT_ALLOWED; |
| 1069 | case legacy_hal::NAN_STATUS_NO_OTA_ACK: |
| 1070 | return NanStatusType::NO_OTA_ACK; |
| 1071 | case legacy_hal::NAN_STATUS_ALREADY_ENABLED: |
| 1072 | return NanStatusType::ALREADY_ENABLED; |
| 1073 | case legacy_hal::NAN_STATUS_FOLLOWUP_QUEUE_FULL: |
| 1074 | return NanStatusType::FOLLOWUP_TX_QUEUE_FULL; |
| 1075 | case legacy_hal::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED: |
| 1076 | return NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED; |
| 1077 | } |
| 1078 | CHECK(false); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1081 | void convertToWifiNanStatus(legacy_hal::NanStatusType type, const char* str, |
| 1082 | size_t max_len, WifiNanStatus* wifiNanStatus) { |
| 1083 | wifiNanStatus->status = convertLegacyNanStatusTypeToHidl(type); |
| 1084 | wifiNanStatus->description = safeConvertChar(str, max_len); |
Etan Cohen | bbc0f09 | 2017-04-26 16:52:34 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1087 | bool convertHidlNanEnableRequestToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1088 | const V1_4::NanEnableRequest& hidl_request, |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1089 | legacy_hal::NanEnableRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1090 | if (!legacy_request) { |
| 1091 | LOG(ERROR) |
| 1092 | << "convertHidlNanEnableRequestToLegacy: null legacy_request"; |
| 1093 | return false; |
| 1094 | } |
| 1095 | *legacy_request = {}; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1096 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1097 | legacy_request->config_2dot4g_support = 1; |
| 1098 | legacy_request->support_2dot4g_val = |
| 1099 | hidl_request.operateInBand[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1100 | legacy_request->config_support_5g = 1; |
| 1101 | legacy_request->support_5g_val = |
| 1102 | hidl_request.operateInBand[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1103 | legacy_request->config_hop_count_limit = 1; |
| 1104 | legacy_request->hop_count_limit_val = hidl_request.hopCountMax; |
| 1105 | legacy_request->master_pref = hidl_request.configParams.masterPref; |
| 1106 | legacy_request->discovery_indication_cfg = 0; |
| 1107 | legacy_request->discovery_indication_cfg |= |
| 1108 | hidl_request.configParams.disableDiscoveryAddressChangeIndication ? 0x1 |
| 1109 | : 0x0; |
| 1110 | legacy_request->discovery_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1111 | hidl_request.configParams.disableStartedClusterIndication ? 0x2 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1112 | legacy_request->discovery_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1113 | hidl_request.configParams.disableJoinedClusterIndication ? 0x4 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1114 | legacy_request->config_sid_beacon = 1; |
| 1115 | if (hidl_request.configParams.numberOfPublishServiceIdsInBeacon > 127) { |
| 1116 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " |
| 1117 | "numberOfPublishServiceIdsInBeacon > 127"; |
| 1118 | return false; |
| 1119 | } |
| 1120 | legacy_request->sid_beacon_val = |
| 1121 | (hidl_request.configParams.includePublishServiceIdsInBeacon ? 0x1 |
| 1122 | : 0x0) | |
| 1123 | (hidl_request.configParams.numberOfPublishServiceIdsInBeacon << 1); |
| 1124 | legacy_request->config_subscribe_sid_beacon = 1; |
| 1125 | if (hidl_request.configParams.numberOfSubscribeServiceIdsInBeacon > 127) { |
| 1126 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " |
| 1127 | "numberOfSubscribeServiceIdsInBeacon > 127"; |
| 1128 | return false; |
| 1129 | } |
| 1130 | legacy_request->subscribe_sid_beacon_val = |
| 1131 | (hidl_request.configParams.includeSubscribeServiceIdsInBeacon ? 0x1 |
| 1132 | : 0x0) | |
| 1133 | (hidl_request.configParams.numberOfSubscribeServiceIdsInBeacon << 1); |
| 1134 | legacy_request->config_rssi_window_size = 1; |
| 1135 | legacy_request->rssi_window_size_val = |
| 1136 | hidl_request.configParams.rssiWindowSize; |
| 1137 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 1138 | legacy_request->disc_mac_addr_rand_interval_sec = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1139 | hidl_request.configParams.macAddressRandomizationIntervalSec; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1140 | legacy_request->config_2dot4g_rssi_close = 1; |
Nate(Qiang) Jiang | 18b38eb | 2019-12-11 12:48:13 -0800 | [diff] [blame] | 1141 | if (hidl_request.configParams.bandSpecificConfig.size() != 3) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1142 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: " |
Nate(Qiang) Jiang | 18b38eb | 2019-12-11 12:48:13 -0800 | [diff] [blame] | 1143 | "bandSpecificConfig.size() != 3"; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1144 | return false; |
| 1145 | } |
| 1146 | legacy_request->rssi_close_2dot4g_val = |
| 1147 | hidl_request.configParams |
| 1148 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1149 | .rssiClose; |
| 1150 | legacy_request->config_2dot4g_rssi_middle = 1; |
| 1151 | legacy_request->rssi_middle_2dot4g_val = |
| 1152 | hidl_request.configParams |
| 1153 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1154 | .rssiMiddle; |
| 1155 | legacy_request->config_2dot4g_rssi_proximity = 1; |
| 1156 | legacy_request->rssi_proximity_2dot4g_val = |
| 1157 | hidl_request.configParams |
| 1158 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1159 | .rssiCloseProximity; |
| 1160 | legacy_request->config_scan_params = 1; |
| 1161 | legacy_request->scan_params_val |
| 1162 | .dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1163 | hidl_request.configParams |
| 1164 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1165 | .dwellTimeMs; |
| 1166 | legacy_request->scan_params_val |
| 1167 | .scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1168 | hidl_request.configParams |
| 1169 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1170 | .scanPeriodSec; |
| 1171 | legacy_request->config_dw.config_2dot4g_dw_band = |
| 1172 | hidl_request.configParams |
| 1173 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1174 | .validDiscoveryWindowIntervalVal; |
| 1175 | legacy_request->config_dw.dw_2dot4g_interval_val = |
| 1176 | hidl_request.configParams |
| 1177 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1178 | .discoveryWindowIntervalVal; |
| 1179 | legacy_request->config_5g_rssi_close = 1; |
| 1180 | legacy_request->rssi_close_5g_val = |
| 1181 | hidl_request.configParams |
| 1182 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1183 | .rssiClose; |
| 1184 | legacy_request->config_5g_rssi_middle = 1; |
| 1185 | legacy_request->rssi_middle_5g_val = |
| 1186 | hidl_request.configParams |
| 1187 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1188 | .rssiMiddle; |
| 1189 | legacy_request->config_5g_rssi_close_proximity = 1; |
| 1190 | legacy_request->rssi_close_proximity_5g_val = |
| 1191 | hidl_request.configParams |
| 1192 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1193 | .rssiCloseProximity; |
| 1194 | legacy_request->scan_params_val |
| 1195 | .dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1196 | hidl_request.configParams |
| 1197 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1198 | .dwellTimeMs; |
| 1199 | legacy_request->scan_params_val |
| 1200 | .scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1201 | hidl_request.configParams |
| 1202 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1203 | .scanPeriodSec; |
| 1204 | legacy_request->scan_params_val |
| 1205 | .dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1206 | hidl_request.configParams |
| 1207 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1208 | .dwellTimeMs; |
| 1209 | legacy_request->scan_params_val |
| 1210 | .scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1211 | hidl_request.configParams |
| 1212 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1213 | .scanPeriodSec; |
| 1214 | legacy_request->config_dw.config_5g_dw_band = |
| 1215 | hidl_request.configParams |
| 1216 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1217 | .validDiscoveryWindowIntervalVal; |
| 1218 | legacy_request->config_dw.dw_5g_interval_val = |
| 1219 | hidl_request.configParams |
| 1220 | .bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1221 | .discoveryWindowIntervalVal; |
| 1222 | if (hidl_request.debugConfigs.validClusterIdVals) { |
| 1223 | legacy_request->cluster_low = |
| 1224 | hidl_request.debugConfigs.clusterIdBottomRangeVal; |
| 1225 | legacy_request->cluster_high = |
| 1226 | hidl_request.debugConfigs.clusterIdTopRangeVal; |
| 1227 | } else { // need 'else' since not configurable in legacy HAL |
| 1228 | legacy_request->cluster_low = 0x0000; |
| 1229 | legacy_request->cluster_high = 0xFFFF; |
| 1230 | } |
| 1231 | legacy_request->config_intf_addr = |
| 1232 | hidl_request.debugConfigs.validIntfAddrVal; |
| 1233 | memcpy(legacy_request->intf_addr_val, |
| 1234 | hidl_request.debugConfigs.intfAddrVal.data(), 6); |
| 1235 | legacy_request->config_oui = hidl_request.debugConfigs.validOuiVal; |
| 1236 | legacy_request->oui_val = hidl_request.debugConfigs.ouiVal; |
| 1237 | legacy_request->config_random_factor_force = |
| 1238 | hidl_request.debugConfigs.validRandomFactorForceVal; |
| 1239 | legacy_request->random_factor_force_val = |
| 1240 | hidl_request.debugConfigs.randomFactorForceVal; |
| 1241 | legacy_request->config_hop_count_force = |
| 1242 | hidl_request.debugConfigs.validHopCountForceVal; |
| 1243 | legacy_request->hop_count_force_val = |
| 1244 | hidl_request.debugConfigs.hopCountForceVal; |
| 1245 | legacy_request->config_24g_channel = |
| 1246 | hidl_request.debugConfigs.validDiscoveryChannelVal; |
| 1247 | legacy_request->channel_24g_val = |
| 1248 | hidl_request.debugConfigs |
| 1249 | .discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1250 | legacy_request->config_5g_channel = |
| 1251 | hidl_request.debugConfigs.validDiscoveryChannelVal; |
| 1252 | legacy_request->channel_5g_val = |
| 1253 | hidl_request.debugConfigs |
| 1254 | .discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1255 | legacy_request->config_2dot4g_beacons = |
| 1256 | hidl_request.debugConfigs.validUseBeaconsInBandVal; |
| 1257 | legacy_request->beacon_2dot4g_val = |
| 1258 | hidl_request.debugConfigs |
| 1259 | .useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1260 | legacy_request->config_5g_beacons = |
| 1261 | hidl_request.debugConfigs.validUseBeaconsInBandVal; |
| 1262 | legacy_request->beacon_5g_val = |
| 1263 | hidl_request.debugConfigs |
| 1264 | .useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1265 | legacy_request->config_2dot4g_sdf = |
| 1266 | hidl_request.debugConfigs.validUseSdfInBandVal; |
| 1267 | legacy_request->sdf_2dot4g_val = |
| 1268 | hidl_request.debugConfigs |
| 1269 | .useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1270 | legacy_request->config_5g_sdf = |
| 1271 | hidl_request.debugConfigs.validUseSdfInBandVal; |
| 1272 | legacy_request->sdf_5g_val = |
| 1273 | hidl_request.debugConfigs |
| 1274 | .useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1275 | |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1276 | /* TODO: b/145609058 |
| 1277 | * Missing updates needed to legacy_hal::NanEnableRequest and conversion to |
| 1278 | * it for 6GHz band */ |
| 1279 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1280 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1283 | bool convertHidlNanEnableRequest_1_4ToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1284 | const V1_4::NanEnableRequest& hidl_request1, |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1285 | const NanConfigRequestSupplemental& hidl_request2, |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1286 | legacy_hal::NanEnableRequest* legacy_request) { |
| 1287 | if (!legacy_request) { |
| 1288 | LOG(ERROR) |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1289 | << "convertHidlNanEnableRequest_1_4ToLegacy: null legacy_request"; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | *legacy_request = {}; |
| 1294 | if (!convertHidlNanEnableRequestToLegacy(hidl_request1, legacy_request)) { |
| 1295 | return false; |
| 1296 | } |
| 1297 | |
| 1298 | legacy_request->config_discovery_beacon_int = 1; |
| 1299 | legacy_request->discovery_beacon_interval = |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1300 | hidl_request2.V1_2.discoveryBeaconIntervalMs; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1301 | legacy_request->config_nss = 1; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1302 | legacy_request->nss = hidl_request2.V1_2.numberOfSpatialStreamsInDiscovery; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1303 | legacy_request->config_dw_early_termination = 1; |
| 1304 | legacy_request->enable_dw_termination = |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1305 | hidl_request2.V1_2.enableDiscoveryWindowEarlyTermination; |
Etan Cohen | 4f5bc6c | 2017-12-28 13:08:08 -0800 | [diff] [blame] | 1306 | legacy_request->config_enable_ranging = 1; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1307 | legacy_request->enable_ranging = hidl_request2.V1_2.enableRanging; |
| 1308 | |
| 1309 | return true; |
| 1310 | } |
| 1311 | |
| 1312 | bool convertHidlNanEnableRequest_1_5ToLegacy( |
| 1313 | const V1_4::NanEnableRequest& hidl_request1, |
| 1314 | const NanConfigRequestSupplemental& hidl_request2, |
| 1315 | legacy_hal::NanEnableRequest* legacy_request) { |
| 1316 | if (!legacy_request) { |
| 1317 | LOG(ERROR) |
| 1318 | << "convertHidlNanEnableRequest_1_5ToLegacy: null legacy_request"; |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | *legacy_request = {}; |
| 1323 | if (!convertHidlNanEnableRequest_1_4ToLegacy(hidl_request1, hidl_request2, |
| 1324 | legacy_request)) { |
| 1325 | return false; |
| 1326 | } |
| 1327 | |
| 1328 | legacy_request->config_enable_instant_mode = 1; |
| 1329 | legacy_request->enable_instant_mode = |
| 1330 | hidl_request2.enableInstantCommunicationMode; |
| 1331 | |
| 1332 | return true; |
| 1333 | } |
| 1334 | |
| 1335 | bool convertHidlNanConfigRequest_1_5ToLegacy( |
| 1336 | const V1_4::NanConfigRequest& hidl_request1, |
| 1337 | const NanConfigRequestSupplemental& hidl_request2, |
| 1338 | legacy_hal::NanConfigRequest* legacy_request) { |
| 1339 | if (!legacy_request) { |
| 1340 | LOG(ERROR) |
| 1341 | << "convertHidlNanConfigRequest_1_5ToLegacy: null legacy_request"; |
| 1342 | return false; |
| 1343 | } |
| 1344 | |
| 1345 | *legacy_request = {}; |
| 1346 | if (!convertHidlNanConfigRequest_1_4ToLegacy(hidl_request1, hidl_request2, |
| 1347 | legacy_request)) { |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
| 1351 | legacy_request->config_enable_instant_mode = 1; |
| 1352 | legacy_request->enable_instant_mode = |
| 1353 | hidl_request2.enableInstantCommunicationMode; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1354 | |
| 1355 | return true; |
| 1356 | } |
| 1357 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1358 | bool convertHidlNanPublishRequestToLegacy( |
| 1359 | const NanPublishRequest& hidl_request, |
| 1360 | legacy_hal::NanPublishRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1361 | if (!legacy_request) { |
| 1362 | LOG(ERROR) |
| 1363 | << "convertHidlNanPublishRequestToLegacy: null legacy_request"; |
| 1364 | return false; |
| 1365 | } |
| 1366 | *legacy_request = {}; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1367 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1368 | legacy_request->publish_id = hidl_request.baseConfigs.sessionId; |
| 1369 | legacy_request->ttl = hidl_request.baseConfigs.ttlSec; |
| 1370 | legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; |
| 1371 | legacy_request->publish_count = hidl_request.baseConfigs.discoveryCount; |
| 1372 | legacy_request->service_name_len = |
| 1373 | hidl_request.baseConfigs.serviceName.size(); |
| 1374 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 1375 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: service_name_len " |
| 1376 | "too large"; |
| 1377 | return false; |
| 1378 | } |
| 1379 | memcpy(legacy_request->service_name, |
| 1380 | hidl_request.baseConfigs.serviceName.data(), |
| 1381 | legacy_request->service_name_len); |
| 1382 | legacy_request->publish_match_indicator = convertHidlNanMatchAlgToLegacy( |
| 1383 | hidl_request.baseConfigs.discoveryMatchIndicator); |
| 1384 | legacy_request->service_specific_info_len = |
| 1385 | hidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 1386 | if (legacy_request->service_specific_info_len > |
| 1387 | NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1388 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1389 | "service_specific_info_len too large"; |
| 1390 | return false; |
| 1391 | } |
| 1392 | memcpy(legacy_request->service_specific_info, |
| 1393 | hidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 1394 | legacy_request->service_specific_info_len); |
| 1395 | legacy_request->sdea_service_specific_info_len = |
Etan Cohen | a7543a7 | 2017-02-17 13:46:19 -0800 | [diff] [blame] | 1396 | hidl_request.baseConfigs.extendedServiceSpecificInfo.size(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1397 | if (legacy_request->sdea_service_specific_info_len > |
| 1398 | NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 1399 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1400 | "sdea_service_specific_info_len too large"; |
| 1401 | return false; |
| 1402 | } |
| 1403 | memcpy(legacy_request->sdea_service_specific_info, |
| 1404 | hidl_request.baseConfigs.extendedServiceSpecificInfo.data(), |
| 1405 | legacy_request->sdea_service_specific_info_len); |
| 1406 | legacy_request->rx_match_filter_len = |
| 1407 | hidl_request.baseConfigs.rxMatchFilter.size(); |
| 1408 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1409 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1410 | "rx_match_filter_len too large"; |
| 1411 | return false; |
| 1412 | } |
| 1413 | memcpy(legacy_request->rx_match_filter, |
| 1414 | hidl_request.baseConfigs.rxMatchFilter.data(), |
| 1415 | legacy_request->rx_match_filter_len); |
| 1416 | legacy_request->tx_match_filter_len = |
| 1417 | hidl_request.baseConfigs.txMatchFilter.size(); |
| 1418 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1419 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1420 | "tx_match_filter_len too large"; |
| 1421 | return false; |
| 1422 | } |
| 1423 | memcpy(legacy_request->tx_match_filter, |
| 1424 | hidl_request.baseConfigs.txMatchFilter.data(), |
| 1425 | legacy_request->tx_match_filter_len); |
| 1426 | legacy_request->rssi_threshold_flag = |
| 1427 | hidl_request.baseConfigs.useRssiThreshold; |
| 1428 | legacy_request->recv_indication_cfg = 0; |
| 1429 | legacy_request->recv_indication_cfg |= |
| 1430 | hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 |
| 1431 | : 0x0; |
| 1432 | legacy_request->recv_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1433 | hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1434 | legacy_request->recv_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1435 | hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1436 | legacy_request->recv_indication_cfg |= 0x8; |
| 1437 | legacy_request->cipher_type = |
| 1438 | (unsigned int)hidl_request.baseConfigs.securityConfig.cipherType; |
| 1439 | if (hidl_request.baseConfigs.securityConfig.securityType == |
| 1440 | NanDataPathSecurityType::PMK) { |
| 1441 | legacy_request->key_info.key_type = |
| 1442 | legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 1443 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 1444 | hidl_request.baseConfigs.securityConfig.pmk.size(); |
| 1445 | if (legacy_request->key_info.body.pmk_info.pmk_len != |
| 1446 | NAN_PMK_INFO_LEN) { |
| 1447 | LOG(ERROR) |
| 1448 | << "convertHidlNanPublishRequestToLegacy: invalid pmk_len"; |
| 1449 | return false; |
| 1450 | } |
| 1451 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 1452 | hidl_request.baseConfigs.securityConfig.pmk.data(), |
| 1453 | legacy_request->key_info.body.pmk_info.pmk_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1454 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1455 | if (hidl_request.baseConfigs.securityConfig.securityType == |
| 1456 | NanDataPathSecurityType::PASSPHRASE) { |
| 1457 | legacy_request->key_info.key_type = |
| 1458 | legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 1459 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 1460 | hidl_request.baseConfigs.securityConfig.passphrase.size(); |
| 1461 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 1462 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 1463 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1464 | "passphrase_len too small"; |
| 1465 | return false; |
| 1466 | } |
| 1467 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 1468 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 1469 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: " |
| 1470 | "passphrase_len too large"; |
| 1471 | return false; |
| 1472 | } |
| 1473 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 1474 | hidl_request.baseConfigs.securityConfig.passphrase.data(), |
| 1475 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1476 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1477 | legacy_request->sdea_params.security_cfg = |
| 1478 | (hidl_request.baseConfigs.securityConfig.securityType != |
| 1479 | NanDataPathSecurityType::OPEN) |
| 1480 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1481 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1482 | legacy_request->sdea_params.ranging_state = |
| 1483 | hidl_request.baseConfigs.rangingRequired |
| 1484 | ? legacy_hal::NAN_RANGING_ENABLE |
| 1485 | : legacy_hal::NAN_RANGING_DISABLE; |
| 1486 | legacy_request->ranging_cfg.ranging_interval_msec = |
| 1487 | hidl_request.baseConfigs.rangingIntervalMsec; |
| 1488 | legacy_request->ranging_cfg.config_ranging_indications = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1489 | hidl_request.baseConfigs.configRangingIndications; |
Etan Cohen | 7b8c5d7 | 2017-12-14 18:12:04 -0800 | [diff] [blame] | 1490 | legacy_request->ranging_cfg.distance_ingress_mm = |
| 1491 | hidl_request.baseConfigs.distanceIngressCm * 10; |
| 1492 | legacy_request->ranging_cfg.distance_egress_mm = |
| 1493 | hidl_request.baseConfigs.distanceEgressCm * 10; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1494 | legacy_request->ranging_auto_response = |
| 1495 | hidl_request.baseConfigs.rangingRequired |
| 1496 | ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE |
| 1497 | : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
| 1498 | legacy_request->sdea_params.range_report = |
| 1499 | legacy_hal::NAN_DISABLE_RANGE_REPORT; |
| 1500 | legacy_request->publish_type = |
| 1501 | convertHidlNanPublishTypeToLegacy(hidl_request.publishType); |
| 1502 | legacy_request->tx_type = convertHidlNanTxTypeToLegacy(hidl_request.txType); |
| 1503 | legacy_request->service_responder_policy = |
| 1504 | hidl_request.autoAcceptDataPathRequests |
| 1505 | ? legacy_hal::NAN_SERVICE_ACCEPT_POLICY_ALL |
| 1506 | : legacy_hal::NAN_SERVICE_ACCEPT_POLICY_NONE; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1507 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1508 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | bool convertHidlNanSubscribeRequestToLegacy( |
| 1512 | const NanSubscribeRequest& hidl_request, |
| 1513 | legacy_hal::NanSubscribeRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1514 | if (!legacy_request) { |
| 1515 | LOG(ERROR) |
| 1516 | << "convertHidlNanSubscribeRequestToLegacy: legacy_request is null"; |
| 1517 | return false; |
| 1518 | } |
| 1519 | *legacy_request = {}; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1520 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1521 | legacy_request->subscribe_id = hidl_request.baseConfigs.sessionId; |
| 1522 | legacy_request->ttl = hidl_request.baseConfigs.ttlSec; |
| 1523 | legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; |
| 1524 | legacy_request->subscribe_count = hidl_request.baseConfigs.discoveryCount; |
| 1525 | legacy_request->service_name_len = |
| 1526 | hidl_request.baseConfigs.serviceName.size(); |
| 1527 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 1528 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1529 | "service_name_len too large"; |
| 1530 | return false; |
| 1531 | } |
| 1532 | memcpy(legacy_request->service_name, |
| 1533 | hidl_request.baseConfigs.serviceName.data(), |
| 1534 | legacy_request->service_name_len); |
| 1535 | legacy_request->subscribe_match_indicator = convertHidlNanMatchAlgToLegacy( |
| 1536 | hidl_request.baseConfigs.discoveryMatchIndicator); |
| 1537 | legacy_request->service_specific_info_len = |
| 1538 | hidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 1539 | if (legacy_request->service_specific_info_len > |
| 1540 | NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1541 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1542 | "service_specific_info_len too large"; |
| 1543 | return false; |
| 1544 | } |
| 1545 | memcpy(legacy_request->service_specific_info, |
| 1546 | hidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 1547 | legacy_request->service_specific_info_len); |
| 1548 | legacy_request->sdea_service_specific_info_len = |
Etan Cohen | a7543a7 | 2017-02-17 13:46:19 -0800 | [diff] [blame] | 1549 | hidl_request.baseConfigs.extendedServiceSpecificInfo.size(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1550 | if (legacy_request->sdea_service_specific_info_len > |
| 1551 | NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 1552 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1553 | "sdea_service_specific_info_len too large"; |
| 1554 | return false; |
| 1555 | } |
| 1556 | memcpy(legacy_request->sdea_service_specific_info, |
| 1557 | hidl_request.baseConfigs.extendedServiceSpecificInfo.data(), |
| 1558 | legacy_request->sdea_service_specific_info_len); |
| 1559 | legacy_request->rx_match_filter_len = |
| 1560 | hidl_request.baseConfigs.rxMatchFilter.size(); |
| 1561 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1562 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1563 | "rx_match_filter_len too large"; |
| 1564 | return false; |
| 1565 | } |
| 1566 | memcpy(legacy_request->rx_match_filter, |
| 1567 | hidl_request.baseConfigs.rxMatchFilter.data(), |
| 1568 | legacy_request->rx_match_filter_len); |
| 1569 | legacy_request->tx_match_filter_len = |
| 1570 | hidl_request.baseConfigs.txMatchFilter.size(); |
| 1571 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1572 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1573 | "tx_match_filter_len too large"; |
| 1574 | return false; |
| 1575 | } |
| 1576 | memcpy(legacy_request->tx_match_filter, |
| 1577 | hidl_request.baseConfigs.txMatchFilter.data(), |
| 1578 | legacy_request->tx_match_filter_len); |
| 1579 | legacy_request->rssi_threshold_flag = |
| 1580 | hidl_request.baseConfigs.useRssiThreshold; |
| 1581 | legacy_request->recv_indication_cfg = 0; |
| 1582 | legacy_request->recv_indication_cfg |= |
| 1583 | hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 |
| 1584 | : 0x0; |
| 1585 | legacy_request->recv_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1586 | hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1587 | legacy_request->recv_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1588 | hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1589 | legacy_request->cipher_type = |
| 1590 | (unsigned int)hidl_request.baseConfigs.securityConfig.cipherType; |
| 1591 | if (hidl_request.baseConfigs.securityConfig.securityType == |
| 1592 | NanDataPathSecurityType::PMK) { |
| 1593 | legacy_request->key_info.key_type = |
| 1594 | legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 1595 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 1596 | hidl_request.baseConfigs.securityConfig.pmk.size(); |
| 1597 | if (legacy_request->key_info.body.pmk_info.pmk_len != |
| 1598 | NAN_PMK_INFO_LEN) { |
| 1599 | LOG(ERROR) |
| 1600 | << "convertHidlNanSubscribeRequestToLegacy: invalid pmk_len"; |
| 1601 | return false; |
| 1602 | } |
| 1603 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 1604 | hidl_request.baseConfigs.securityConfig.pmk.data(), |
| 1605 | legacy_request->key_info.body.pmk_info.pmk_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1606 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1607 | if (hidl_request.baseConfigs.securityConfig.securityType == |
| 1608 | NanDataPathSecurityType::PASSPHRASE) { |
| 1609 | legacy_request->key_info.key_type = |
| 1610 | legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 1611 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 1612 | hidl_request.baseConfigs.securityConfig.passphrase.size(); |
| 1613 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 1614 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 1615 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1616 | "passphrase_len too small"; |
| 1617 | return false; |
| 1618 | } |
| 1619 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 1620 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 1621 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1622 | "passphrase_len too large"; |
| 1623 | return false; |
| 1624 | } |
| 1625 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 1626 | hidl_request.baseConfigs.securityConfig.passphrase.data(), |
| 1627 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1628 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1629 | legacy_request->sdea_params.security_cfg = |
| 1630 | (hidl_request.baseConfigs.securityConfig.securityType != |
| 1631 | NanDataPathSecurityType::OPEN) |
| 1632 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
| 1633 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1634 | legacy_request->sdea_params.ranging_state = |
| 1635 | hidl_request.baseConfigs.rangingRequired |
| 1636 | ? legacy_hal::NAN_RANGING_ENABLE |
| 1637 | : legacy_hal::NAN_RANGING_DISABLE; |
| 1638 | legacy_request->ranging_cfg.ranging_interval_msec = |
| 1639 | hidl_request.baseConfigs.rangingIntervalMsec; |
| 1640 | legacy_request->ranging_cfg.config_ranging_indications = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1641 | hidl_request.baseConfigs.configRangingIndications; |
Etan Cohen | 7b8c5d7 | 2017-12-14 18:12:04 -0800 | [diff] [blame] | 1642 | legacy_request->ranging_cfg.distance_ingress_mm = |
| 1643 | hidl_request.baseConfigs.distanceIngressCm * 10; |
| 1644 | legacy_request->ranging_cfg.distance_egress_mm = |
| 1645 | hidl_request.baseConfigs.distanceEgressCm * 10; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1646 | legacy_request->ranging_auto_response = |
| 1647 | hidl_request.baseConfigs.rangingRequired |
| 1648 | ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE |
| 1649 | : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
| 1650 | legacy_request->sdea_params.range_report = |
| 1651 | legacy_hal::NAN_DISABLE_RANGE_REPORT; |
| 1652 | legacy_request->subscribe_type = |
| 1653 | convertHidlNanSubscribeTypeToLegacy(hidl_request.subscribeType); |
| 1654 | legacy_request->serviceResponseFilter = |
| 1655 | convertHidlNanSrfTypeToLegacy(hidl_request.srfType); |
| 1656 | legacy_request->serviceResponseInclude = |
| 1657 | hidl_request.srfRespondIfInAddressSet |
| 1658 | ? legacy_hal::NAN_SRF_INCLUDE_RESPOND |
| 1659 | : legacy_hal::NAN_SRF_INCLUDE_DO_NOT_RESPOND; |
| 1660 | legacy_request->useServiceResponseFilter = |
| 1661 | hidl_request.shouldUseSrf ? legacy_hal::NAN_USE_SRF |
| 1662 | : legacy_hal::NAN_DO_NOT_USE_SRF; |
| 1663 | legacy_request->ssiRequiredForMatchIndication = |
| 1664 | hidl_request.isSsiRequiredForMatch |
| 1665 | ? legacy_hal::NAN_SSI_REQUIRED_IN_MATCH_IND |
| 1666 | : legacy_hal::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND; |
| 1667 | legacy_request->num_intf_addr_present = hidl_request.intfAddr.size(); |
| 1668 | if (legacy_request->num_intf_addr_present > NAN_MAX_SUBSCRIBE_MAX_ADDRESS) { |
| 1669 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: " |
| 1670 | "num_intf_addr_present - too many"; |
| 1671 | return false; |
| 1672 | } |
| 1673 | for (int i = 0; i < legacy_request->num_intf_addr_present; i++) { |
| 1674 | memcpy(legacy_request->intf_addr[i], hidl_request.intfAddr[i].data(), |
| 1675 | 6); |
| 1676 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1677 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1678 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1681 | bool convertHidlNanTransmitFollowupRequestToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1682 | const NanTransmitFollowupRequest& hidl_request, |
| 1683 | legacy_hal::NanTransmitFollowupRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1684 | if (!legacy_request) { |
| 1685 | LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " |
| 1686 | "legacy_request is null"; |
| 1687 | return false; |
| 1688 | } |
| 1689 | *legacy_request = {}; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1690 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1691 | legacy_request->publish_subscribe_id = hidl_request.discoverySessionId; |
| 1692 | legacy_request->requestor_instance_id = hidl_request.peerId; |
| 1693 | memcpy(legacy_request->addr, hidl_request.addr.data(), 6); |
| 1694 | legacy_request->priority = hidl_request.isHighPriority |
| 1695 | ? legacy_hal::NAN_TX_PRIORITY_HIGH |
| 1696 | : legacy_hal::NAN_TX_PRIORITY_NORMAL; |
| 1697 | legacy_request->dw_or_faw = hidl_request.shouldUseDiscoveryWindow |
| 1698 | ? legacy_hal::NAN_TRANSMIT_IN_DW |
| 1699 | : legacy_hal::NAN_TRANSMIT_IN_FAW; |
| 1700 | legacy_request->service_specific_info_len = |
| 1701 | hidl_request.serviceSpecificInfo.size(); |
| 1702 | if (legacy_request->service_specific_info_len > |
| 1703 | NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1704 | LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " |
| 1705 | "service_specific_info_len too large"; |
| 1706 | return false; |
| 1707 | } |
| 1708 | memcpy(legacy_request->service_specific_info, |
| 1709 | hidl_request.serviceSpecificInfo.data(), |
| 1710 | legacy_request->service_specific_info_len); |
| 1711 | legacy_request->sdea_service_specific_info_len = |
| 1712 | hidl_request.extendedServiceSpecificInfo.size(); |
| 1713 | if (legacy_request->sdea_service_specific_info_len > |
| 1714 | NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 1715 | LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: " |
| 1716 | "sdea_service_specific_info_len too large"; |
| 1717 | return false; |
| 1718 | } |
| 1719 | memcpy(legacy_request->sdea_service_specific_info, |
| 1720 | hidl_request.extendedServiceSpecificInfo.data(), |
| 1721 | legacy_request->sdea_service_specific_info_len); |
| 1722 | legacy_request->recv_indication_cfg = |
| 1723 | hidl_request.disableFollowupResultIndication ? 0x1 : 0x0; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1724 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1725 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | bool convertHidlNanConfigRequestToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1729 | const V1_4::NanConfigRequest& hidl_request, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1730 | legacy_hal::NanConfigRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1731 | if (!legacy_request) { |
| 1732 | LOG(ERROR) |
| 1733 | << "convertHidlNanConfigRequestToLegacy: legacy_request is null"; |
| 1734 | return false; |
| 1735 | } |
| 1736 | *legacy_request = {}; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1737 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1738 | // TODO: b/34059183 tracks missing configurations in legacy HAL or uknown |
| 1739 | // defaults |
| 1740 | legacy_request->master_pref = hidl_request.masterPref; |
| 1741 | legacy_request->discovery_indication_cfg = 0; |
| 1742 | legacy_request->discovery_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1743 | hidl_request.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1744 | legacy_request->discovery_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1745 | hidl_request.disableStartedClusterIndication ? 0x2 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1746 | legacy_request->discovery_indication_cfg |= |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1747 | hidl_request.disableJoinedClusterIndication ? 0x4 : 0x0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1748 | legacy_request->config_sid_beacon = 1; |
| 1749 | if (hidl_request.numberOfPublishServiceIdsInBeacon > 127) { |
| 1750 | LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: " |
| 1751 | "numberOfPublishServiceIdsInBeacon > 127"; |
| 1752 | return false; |
| 1753 | } |
| 1754 | legacy_request->sid_beacon = |
| 1755 | (hidl_request.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1756 | (hidl_request.numberOfPublishServiceIdsInBeacon << 1); |
| 1757 | legacy_request->config_subscribe_sid_beacon = 1; |
| 1758 | if (hidl_request.numberOfSubscribeServiceIdsInBeacon > 127) { |
| 1759 | LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: " |
| 1760 | "numberOfSubscribeServiceIdsInBeacon > 127"; |
| 1761 | return false; |
| 1762 | } |
| 1763 | legacy_request->subscribe_sid_beacon_val = |
| 1764 | (hidl_request.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1765 | (hidl_request.numberOfSubscribeServiceIdsInBeacon << 1); |
| 1766 | legacy_request->config_rssi_window_size = 1; |
| 1767 | legacy_request->rssi_window_size_val = hidl_request.rssiWindowSize; |
| 1768 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 1769 | legacy_request->disc_mac_addr_rand_interval_sec = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1770 | hidl_request.macAddressRandomizationIntervalSec; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1771 | /* TODO : missing |
| 1772 | legacy_request->config_2dot4g_rssi_close = 1; |
| 1773 | legacy_request->rssi_close_2dot4g_val = |
| 1774 | hidl_request.bandSpecificConfig[ |
| 1775 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiClose; |
| 1776 | legacy_request->config_2dot4g_rssi_middle = 1; |
| 1777 | legacy_request->rssi_middle_2dot4g_val = |
| 1778 | hidl_request.bandSpecificConfig[ |
| 1779 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiMiddle; |
| 1780 | legacy_request->config_2dot4g_rssi_proximity = 1; |
| 1781 | legacy_request->rssi_proximity_2dot4g_val = |
| 1782 | hidl_request.bandSpecificConfig[ |
| 1783 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiCloseProximity; |
| 1784 | */ |
| 1785 | legacy_request->config_scan_params = 1; |
| 1786 | legacy_request->scan_params_val |
| 1787 | .dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1788 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1789 | .dwellTimeMs; |
| 1790 | legacy_request->scan_params_val |
| 1791 | .scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1792 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1793 | .scanPeriodSec; |
| 1794 | legacy_request->config_dw.config_2dot4g_dw_band = |
| 1795 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1796 | .validDiscoveryWindowIntervalVal; |
| 1797 | legacy_request->config_dw.dw_2dot4g_interval_val = |
| 1798 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1799 | .discoveryWindowIntervalVal; |
| 1800 | /* TODO: missing |
| 1801 | legacy_request->config_5g_rssi_close = 1; |
| 1802 | legacy_request->rssi_close_5g_val = |
| 1803 | hidl_request.bandSpecificConfig[ |
| 1804 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiClose; |
| 1805 | legacy_request->config_5g_rssi_middle = 1; |
| 1806 | legacy_request->rssi_middle_5g_val = |
| 1807 | hidl_request.bandSpecificConfig[ |
| 1808 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiMiddle; |
| 1809 | */ |
| 1810 | legacy_request->config_5g_rssi_close_proximity = 1; |
| 1811 | legacy_request->rssi_close_proximity_5g_val = |
| 1812 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1813 | .rssiCloseProximity; |
| 1814 | legacy_request->scan_params_val |
| 1815 | .dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1816 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1817 | .dwellTimeMs; |
| 1818 | legacy_request->scan_params_val |
| 1819 | .scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1820 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1821 | .scanPeriodSec; |
| 1822 | legacy_request->scan_params_val |
| 1823 | .dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1824 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1825 | .dwellTimeMs; |
| 1826 | legacy_request->scan_params_val |
| 1827 | .scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1828 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1829 | .scanPeriodSec; |
| 1830 | legacy_request->config_dw.config_5g_dw_band = |
| 1831 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1832 | .validDiscoveryWindowIntervalVal; |
| 1833 | legacy_request->config_dw.dw_5g_interval_val = |
| 1834 | hidl_request.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1835 | .discoveryWindowIntervalVal; |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1836 | /* TODO: b/145609058 |
| 1837 | * Missing updates needed to legacy_hal::NanConfigRequest and conversion to |
| 1838 | * it for 6GHz band */ |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1839 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1840 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1843 | bool convertHidlNanConfigRequest_1_4ToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1844 | const V1_4::NanConfigRequest& hidl_request1, |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1845 | const NanConfigRequestSupplemental& hidl_request2, |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1846 | legacy_hal::NanConfigRequest* legacy_request) { |
| 1847 | if (!legacy_request) { |
Ahmed ElArabawy | 83baffd | 2019-11-15 19:20:41 -0800 | [diff] [blame] | 1848 | LOG(ERROR) << "convertHidlNanConfigRequest_1_4ToLegacy: legacy_request " |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1849 | "is null"; |
| 1850 | return false; |
| 1851 | } |
| 1852 | |
| 1853 | *legacy_request = {}; |
| 1854 | if (!convertHidlNanConfigRequestToLegacy(hidl_request1, legacy_request)) { |
| 1855 | return false; |
| 1856 | } |
| 1857 | |
| 1858 | legacy_request->config_discovery_beacon_int = 1; |
| 1859 | legacy_request->discovery_beacon_interval = |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1860 | hidl_request2.V1_2.discoveryBeaconIntervalMs; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1861 | legacy_request->config_nss = 1; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1862 | legacy_request->nss = hidl_request2.V1_2.numberOfSpatialStreamsInDiscovery; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1863 | legacy_request->config_dw_early_termination = 1; |
| 1864 | legacy_request->enable_dw_termination = |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1865 | hidl_request2.V1_2.enableDiscoveryWindowEarlyTermination; |
Etan Cohen | 4f5bc6c | 2017-12-28 13:08:08 -0800 | [diff] [blame] | 1866 | legacy_request->config_enable_ranging = 1; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 1867 | legacy_request->enable_ranging = hidl_request2.V1_2.enableRanging; |
Etan Cohen | 9e7a405 | 2017-12-21 13:45:26 -0800 | [diff] [blame] | 1868 | |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1872 | bool convertHidlNanDataPathInitiatorRequestToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1873 | const NanInitiateDataPathRequest& hidl_request, |
| 1874 | legacy_hal::NanDataPathInitiatorRequest* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1875 | if (!legacy_request) { |
| 1876 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1877 | "legacy_request is null"; |
| 1878 | return false; |
| 1879 | } |
| 1880 | *legacy_request = {}; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1881 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1882 | legacy_request->requestor_instance_id = hidl_request.peerId; |
| 1883 | memcpy(legacy_request->peer_disc_mac_addr, |
| 1884 | hidl_request.peerDiscMacAddr.data(), 6); |
| 1885 | legacy_request->channel_request_type = |
| 1886 | convertHidlNanDataPathChannelCfgToLegacy( |
| 1887 | hidl_request.channelRequestType); |
| 1888 | legacy_request->channel = hidl_request.channel; |
Etan Cohen | 1cefaf6 | 2019-11-25 11:41:58 -0800 | [diff] [blame] | 1889 | if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { |
| 1890 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1891 | "ifaceName too long"; |
| 1892 | return false; |
| 1893 | } |
| 1894 | strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), |
| 1895 | IFNAMSIZ + 1); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1896 | legacy_request->ndp_cfg.security_cfg = |
| 1897 | (hidl_request.securityConfig.securityType != |
| 1898 | NanDataPathSecurityType::OPEN) |
| 1899 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1900 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1901 | legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); |
| 1902 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
| 1903 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1904 | "ndp_app_info_len too large"; |
| 1905 | return false; |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1906 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1907 | memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), |
| 1908 | legacy_request->app_info.ndp_app_info_len); |
| 1909 | legacy_request->cipher_type = |
| 1910 | (unsigned int)hidl_request.securityConfig.cipherType; |
| 1911 | if (hidl_request.securityConfig.securityType == |
| 1912 | NanDataPathSecurityType::PMK) { |
| 1913 | legacy_request->key_info.key_type = |
| 1914 | legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 1915 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 1916 | hidl_request.securityConfig.pmk.size(); |
| 1917 | if (legacy_request->key_info.body.pmk_info.pmk_len != |
| 1918 | NAN_PMK_INFO_LEN) { |
| 1919 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1920 | "invalid pmk_len"; |
| 1921 | return false; |
| 1922 | } |
| 1923 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 1924 | hidl_request.securityConfig.pmk.data(), |
| 1925 | legacy_request->key_info.body.pmk_info.pmk_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1926 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1927 | if (hidl_request.securityConfig.securityType == |
| 1928 | NanDataPathSecurityType::PASSPHRASE) { |
| 1929 | legacy_request->key_info.key_type = |
| 1930 | legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 1931 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 1932 | hidl_request.securityConfig.passphrase.size(); |
| 1933 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 1934 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 1935 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1936 | "passphrase_len too small"; |
| 1937 | return false; |
| 1938 | } |
| 1939 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 1940 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 1941 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1942 | "passphrase_len too large"; |
| 1943 | return false; |
| 1944 | } |
| 1945 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 1946 | hidl_request.securityConfig.passphrase.data(), |
| 1947 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1948 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1949 | legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); |
| 1950 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 1951 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: " |
| 1952 | "service_name_len too large"; |
| 1953 | return false; |
| 1954 | } |
| 1955 | memcpy(legacy_request->service_name, |
| 1956 | hidl_request.serviceNameOutOfBand.data(), |
| 1957 | legacy_request->service_name_len); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1958 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1959 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | bool convertHidlNanDataPathIndicationResponseToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1963 | const NanRespondToDataPathIndicationRequest& hidl_request, |
| 1964 | legacy_hal::NanDataPathIndicationResponse* legacy_request) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1965 | if (!legacy_request) { |
| 1966 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 1967 | "legacy_request is null"; |
| 1968 | return false; |
| 1969 | } |
| 1970 | *legacy_request = {}; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1971 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1972 | legacy_request->rsp_code = hidl_request.acceptRequest |
| 1973 | ? legacy_hal::NAN_DP_REQUEST_ACCEPT |
| 1974 | : legacy_hal::NAN_DP_REQUEST_REJECT; |
| 1975 | legacy_request->ndp_instance_id = hidl_request.ndpInstanceId; |
Etan Cohen | 1cefaf6 | 2019-11-25 11:41:58 -0800 | [diff] [blame] | 1976 | if (strnlen(hidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { |
| 1977 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 1978 | "ifaceName too long"; |
| 1979 | return false; |
| 1980 | } |
| 1981 | strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), |
| 1982 | IFNAMSIZ + 1); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1983 | legacy_request->ndp_cfg.security_cfg = |
| 1984 | (hidl_request.securityConfig.securityType != |
| 1985 | NanDataPathSecurityType::OPEN) |
| 1986 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1987 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1988 | legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); |
| 1989 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
| 1990 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 1991 | "ndp_app_info_len too large"; |
| 1992 | return false; |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 1993 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1994 | memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), |
| 1995 | legacy_request->app_info.ndp_app_info_len); |
| 1996 | legacy_request->cipher_type = |
| 1997 | (unsigned int)hidl_request.securityConfig.cipherType; |
| 1998 | if (hidl_request.securityConfig.securityType == |
| 1999 | NanDataPathSecurityType::PMK) { |
| 2000 | legacy_request->key_info.key_type = |
| 2001 | legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 2002 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 2003 | hidl_request.securityConfig.pmk.size(); |
| 2004 | if (legacy_request->key_info.body.pmk_info.pmk_len != |
| 2005 | NAN_PMK_INFO_LEN) { |
| 2006 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 2007 | "invalid pmk_len"; |
| 2008 | return false; |
| 2009 | } |
| 2010 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 2011 | hidl_request.securityConfig.pmk.data(), |
| 2012 | legacy_request->key_info.body.pmk_info.pmk_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 2013 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2014 | if (hidl_request.securityConfig.securityType == |
| 2015 | NanDataPathSecurityType::PASSPHRASE) { |
| 2016 | legacy_request->key_info.key_type = |
| 2017 | legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 2018 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 2019 | hidl_request.securityConfig.passphrase.size(); |
| 2020 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 2021 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 2022 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 2023 | "passphrase_len too small"; |
| 2024 | return false; |
| 2025 | } |
| 2026 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 2027 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 2028 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 2029 | "passphrase_len too large"; |
| 2030 | return false; |
| 2031 | } |
| 2032 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 2033 | hidl_request.securityConfig.passphrase.data(), |
| 2034 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
Etan Cohen | c58619e | 2017-03-14 14:54:40 -0700 | [diff] [blame] | 2035 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2036 | legacy_request->service_name_len = hidl_request.serviceNameOutOfBand.size(); |
| 2037 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 2038 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: " |
| 2039 | "service_name_len too large"; |
| 2040 | return false; |
| 2041 | } |
| 2042 | memcpy(legacy_request->service_name, |
| 2043 | hidl_request.serviceNameOutOfBand.data(), |
| 2044 | legacy_request->service_name_len); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2045 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2046 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | bool convertLegacyNanResponseHeaderToHidl( |
| 2050 | const legacy_hal::NanResponseMsg& legacy_response, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2051 | WifiNanStatus* wifiNanStatus) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2052 | if (!wifiNanStatus) { |
| 2053 | LOG(ERROR) |
| 2054 | << "convertLegacyNanResponseHeaderToHidl: wifiNanStatus is null"; |
| 2055 | return false; |
| 2056 | } |
| 2057 | *wifiNanStatus = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2058 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2059 | convertToWifiNanStatus(legacy_response.status, legacy_response.nan_error, |
| 2060 | sizeof(legacy_response.nan_error), wifiNanStatus); |
| 2061 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2062 | } |
| 2063 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2064 | bool convertLegacyNanCapabilitiesResponseToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2065 | const legacy_hal::NanCapabilities& legacy_response, |
| 2066 | NanCapabilities* hidl_response) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2067 | if (!hidl_response) { |
| 2068 | LOG(ERROR) << "convertLegacyNanCapabilitiesResponseToHidl: " |
| 2069 | "hidl_response is null"; |
| 2070 | return false; |
| 2071 | } |
| 2072 | *hidl_response = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2073 | |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2074 | hidl_response->V1_0.maxConcurrentClusters = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2075 | legacy_response.max_concurrent_nan_clusters; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2076 | hidl_response->V1_0.maxPublishes = legacy_response.max_publishes; |
| 2077 | hidl_response->V1_0.maxSubscribes = legacy_response.max_subscribes; |
| 2078 | hidl_response->V1_0.maxServiceNameLen = |
| 2079 | legacy_response.max_service_name_len; |
| 2080 | hidl_response->V1_0.maxMatchFilterLen = |
| 2081 | legacy_response.max_match_filter_len; |
| 2082 | hidl_response->V1_0.maxTotalMatchFilterLen = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2083 | legacy_response.max_total_match_filter_len; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2084 | hidl_response->V1_0.maxServiceSpecificInfoLen = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2085 | legacy_response.max_service_specific_info_len; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2086 | hidl_response->V1_0.maxExtendedServiceSpecificInfoLen = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2087 | legacy_response.max_sdea_service_specific_info_len; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2088 | hidl_response->V1_0.maxNdiInterfaces = legacy_response.max_ndi_interfaces; |
| 2089 | hidl_response->V1_0.maxNdpSessions = legacy_response.max_ndp_sessions; |
| 2090 | hidl_response->V1_0.maxAppInfoLen = legacy_response.max_app_info_len; |
| 2091 | hidl_response->V1_0.maxQueuedTransmitFollowupMsgs = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2092 | legacy_response.max_queued_transmit_followup_msgs; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2093 | hidl_response->V1_0.maxSubscribeInterfaceAddresses = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2094 | legacy_response.max_subscribe_address; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2095 | hidl_response->V1_0.supportedCipherSuites = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2096 | legacy_response.cipher_suites_supported; |
Nate Jiang | 3ec6781 | 2020-08-24 11:04:31 -0700 | [diff] [blame] | 2097 | hidl_response->instantCommunicationModeSupportFlag = |
| 2098 | legacy_response.is_instant_mode_supported; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2099 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2100 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2103 | bool convertLegacyNanMatchIndToHidl(const legacy_hal::NanMatchInd& legacy_ind, |
| 2104 | NanMatchInd* hidl_ind) { |
| 2105 | if (!hidl_ind) { |
| 2106 | LOG(ERROR) << "convertLegacyNanMatchIndToHidl: hidl_ind is null"; |
| 2107 | return false; |
| 2108 | } |
| 2109 | *hidl_ind = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2110 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2111 | hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 2112 | hidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 2113 | hidl_ind->addr = hidl_array<uint8_t, 6>(legacy_ind.addr); |
| 2114 | hidl_ind->serviceSpecificInfo = |
| 2115 | std::vector<uint8_t>(legacy_ind.service_specific_info, |
| 2116 | legacy_ind.service_specific_info + |
| 2117 | legacy_ind.service_specific_info_len); |
| 2118 | hidl_ind->extendedServiceSpecificInfo = |
| 2119 | std::vector<uint8_t>(legacy_ind.sdea_service_specific_info, |
| 2120 | legacy_ind.sdea_service_specific_info + |
| 2121 | legacy_ind.sdea_service_specific_info_len); |
| 2122 | hidl_ind->matchFilter = std::vector<uint8_t>( |
| 2123 | legacy_ind.sdf_match_filter, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2124 | legacy_ind.sdf_match_filter + legacy_ind.sdf_match_filter_len); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2125 | hidl_ind->matchOccuredInBeaconFlag = legacy_ind.match_occured_flag == 1; |
| 2126 | hidl_ind->outOfResourceFlag = legacy_ind.out_of_resource_flag == 1; |
| 2127 | hidl_ind->rssiValue = legacy_ind.rssi_value; |
| 2128 | hidl_ind->peerCipherType = (NanCipherSuiteType)legacy_ind.peer_cipher_type; |
| 2129 | hidl_ind->peerRequiresSecurityEnabledInNdp = |
| 2130 | legacy_ind.peer_sdea_params.security_cfg == |
| 2131 | legacy_hal::NAN_DP_CONFIG_SECURITY; |
| 2132 | hidl_ind->peerRequiresRanging = legacy_ind.peer_sdea_params.ranging_state == |
| 2133 | legacy_hal::NAN_RANGING_ENABLE; |
| 2134 | hidl_ind->rangingMeasurementInCm = |
Etan Cohen | 7b8c5d7 | 2017-12-14 18:12:04 -0800 | [diff] [blame] | 2135 | legacy_ind.range_info.range_measurement_mm / 10; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2136 | hidl_ind->rangingIndicationType = legacy_ind.range_info.ranging_event_type; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2137 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2138 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | bool convertLegacyNanFollowupIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2142 | const legacy_hal::NanFollowupInd& legacy_ind, |
| 2143 | NanFollowupReceivedInd* hidl_ind) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2144 | if (!hidl_ind) { |
| 2145 | LOG(ERROR) << "convertLegacyNanFollowupIndToHidl: hidl_ind is null"; |
| 2146 | return false; |
| 2147 | } |
| 2148 | *hidl_ind = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2149 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2150 | hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 2151 | hidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 2152 | hidl_ind->addr = hidl_array<uint8_t, 6>(legacy_ind.addr); |
| 2153 | hidl_ind->receivedInFaw = legacy_ind.dw_or_faw == 1; |
| 2154 | hidl_ind->serviceSpecificInfo = |
| 2155 | std::vector<uint8_t>(legacy_ind.service_specific_info, |
| 2156 | legacy_ind.service_specific_info + |
| 2157 | legacy_ind.service_specific_info_len); |
| 2158 | hidl_ind->extendedServiceSpecificInfo = |
| 2159 | std::vector<uint8_t>(legacy_ind.sdea_service_specific_info, |
| 2160 | legacy_ind.sdea_service_specific_info + |
| 2161 | legacy_ind.sdea_service_specific_info_len); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2162 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2163 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2166 | bool convertLegacyNanDataPathRequestIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2167 | const legacy_hal::NanDataPathRequestInd& legacy_ind, |
| 2168 | NanDataPathRequestInd* hidl_ind) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2169 | if (!hidl_ind) { |
| 2170 | LOG(ERROR) |
| 2171 | << "convertLegacyNanDataPathRequestIndToHidl: hidl_ind is null"; |
| 2172 | return false; |
| 2173 | } |
| 2174 | *hidl_ind = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2175 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2176 | hidl_ind->discoverySessionId = legacy_ind.service_instance_id; |
| 2177 | hidl_ind->peerDiscMacAddr = |
| 2178 | hidl_array<uint8_t, 6>(legacy_ind.peer_disc_mac_addr); |
| 2179 | hidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; |
| 2180 | hidl_ind->securityRequired = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2181 | legacy_ind.ndp_cfg.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2182 | hidl_ind->appInfo = |
| 2183 | std::vector<uint8_t>(legacy_ind.app_info.ndp_app_info, |
| 2184 | legacy_ind.app_info.ndp_app_info + |
| 2185 | legacy_ind.app_info.ndp_app_info_len); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2186 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2187 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2190 | bool convertLegacyNdpChannelInfoToHidl( |
| 2191 | const legacy_hal::NanChannelInfo& legacy_struct, |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2192 | V1_2::NanDataPathChannelInfo* hidl_struct) { |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2193 | if (!hidl_struct) { |
| 2194 | LOG(ERROR) << "convertLegacyNdpChannelInfoToHidl: hidl_struct is null"; |
| 2195 | return false; |
| 2196 | } |
| 2197 | *hidl_struct = {}; |
| 2198 | |
| 2199 | hidl_struct->channelFreq = legacy_struct.channel; |
Etan Cohen | b1b7a82 | 2018-02-07 14:44:32 -0800 | [diff] [blame] | 2200 | hidl_struct->channelBandwidth = convertLegacyWifiChannelWidthToHidl( |
| 2201 | (legacy_hal::wifi_channel_width)legacy_struct.bandwidth); |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2202 | hidl_struct->numSpatialStreams = legacy_struct.nss; |
| 2203 | |
| 2204 | return true; |
| 2205 | } |
| 2206 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2207 | bool convertLegacyNanDataPathConfirmIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 2208 | const legacy_hal::NanDataPathConfirmInd& legacy_ind, |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2209 | V1_2::NanDataPathConfirmInd* hidl_ind) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2210 | if (!hidl_ind) { |
| 2211 | LOG(ERROR) |
| 2212 | << "convertLegacyNanDataPathConfirmIndToHidl: hidl_ind is null"; |
| 2213 | return false; |
| 2214 | } |
| 2215 | *hidl_ind = {}; |
Roshan Pius | 590744b | 2017-03-02 07:24:41 -0800 | [diff] [blame] | 2216 | |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2217 | hidl_ind->V1_0.ndpInstanceId = legacy_ind.ndp_instance_id; |
| 2218 | hidl_ind->V1_0.dataPathSetupSuccess = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2219 | legacy_ind.rsp_code == legacy_hal::NAN_DP_REQUEST_ACCEPT; |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2220 | hidl_ind->V1_0.peerNdiMacAddr = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2221 | hidl_array<uint8_t, 6>(legacy_ind.peer_ndi_mac_addr); |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2222 | hidl_ind->V1_0.appInfo = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2223 | std::vector<uint8_t>(legacy_ind.app_info.ndp_app_info, |
| 2224 | legacy_ind.app_info.ndp_app_info + |
| 2225 | legacy_ind.app_info.ndp_app_info_len); |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2226 | hidl_ind->V1_0.status.status = |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2227 | convertLegacyNanStatusTypeToHidl(legacy_ind.reason_code); |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2228 | hidl_ind->V1_0.status.description = ""; // TODO: b/34059183 |
| 2229 | |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2230 | std::vector<V1_2::NanDataPathChannelInfo> channelInfo; |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2231 | for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2232 | V1_2::NanDataPathChannelInfo hidl_struct; |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2233 | if (!convertLegacyNdpChannelInfoToHidl(legacy_ind.channel_info[i], |
| 2234 | &hidl_struct)) { |
| 2235 | return false; |
| 2236 | } |
| 2237 | channelInfo.push_back(hidl_struct); |
| 2238 | } |
| 2239 | hidl_ind->channelInfo = channelInfo; |
| 2240 | |
| 2241 | return true; |
| 2242 | } |
| 2243 | |
| 2244 | bool convertLegacyNanDataPathScheduleUpdateIndToHidl( |
| 2245 | const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2246 | V1_2::NanDataPathScheduleUpdateInd* hidl_ind) { |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2247 | if (!hidl_ind) { |
| 2248 | LOG(ERROR) << "convertLegacyNanDataPathScheduleUpdateIndToHidl: " |
| 2249 | "hidl_ind is null"; |
| 2250 | return false; |
| 2251 | } |
| 2252 | *hidl_ind = {}; |
| 2253 | |
| 2254 | hidl_ind->peerDiscoveryAddress = |
| 2255 | hidl_array<uint8_t, 6>(legacy_ind.peer_mac_addr); |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2256 | std::vector<V1_2::NanDataPathChannelInfo> channelInfo; |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2257 | for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 2258 | V1_2::NanDataPathChannelInfo hidl_struct; |
Etan Cohen | c7bd0f7 | 2017-12-26 11:52:44 -0800 | [diff] [blame] | 2259 | if (!convertLegacyNdpChannelInfoToHidl(legacy_ind.channel_info[i], |
| 2260 | &hidl_struct)) { |
| 2261 | return false; |
| 2262 | } |
| 2263 | channelInfo.push_back(hidl_struct); |
| 2264 | } |
| 2265 | hidl_ind->channelInfo = channelInfo; |
| 2266 | std::vector<uint32_t> ndpInstanceIds; |
| 2267 | for (unsigned int i = 0; i < legacy_ind.num_ndp_instances; ++i) { |
| 2268 | ndpInstanceIds.push_back(legacy_ind.ndp_instance_id[i]); |
| 2269 | } |
| 2270 | hidl_ind->ndpInstanceIds = ndpInstanceIds; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2271 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2272 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 2273 | } |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2274 | |
| 2275 | legacy_hal::wifi_rtt_type convertHidlRttTypeToLegacy(RttType type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2276 | switch (type) { |
| 2277 | case RttType::ONE_SIDED: |
| 2278 | return legacy_hal::RTT_TYPE_1_SIDED; |
| 2279 | case RttType::TWO_SIDED: |
| 2280 | return legacy_hal::RTT_TYPE_2_SIDED; |
| 2281 | }; |
| 2282 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | RttType convertLegacyRttTypeToHidl(legacy_hal::wifi_rtt_type type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2286 | switch (type) { |
| 2287 | case legacy_hal::RTT_TYPE_1_SIDED: |
| 2288 | return RttType::ONE_SIDED; |
| 2289 | case legacy_hal::RTT_TYPE_2_SIDED: |
| 2290 | return RttType::TWO_SIDED; |
| 2291 | }; |
| 2292 | CHECK(false) << "Unknown legacy type: " << type; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | legacy_hal::rtt_peer_type convertHidlRttPeerTypeToLegacy(RttPeerType type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2296 | switch (type) { |
| 2297 | case RttPeerType::AP: |
| 2298 | return legacy_hal::RTT_PEER_AP; |
| 2299 | case RttPeerType::STA: |
| 2300 | return legacy_hal::RTT_PEER_STA; |
| 2301 | case RttPeerType::P2P_GO: |
| 2302 | return legacy_hal::RTT_PEER_P2P_GO; |
| 2303 | case RttPeerType::P2P_CLIENT: |
| 2304 | return legacy_hal::RTT_PEER_P2P_CLIENT; |
| 2305 | case RttPeerType::NAN: |
| 2306 | return legacy_hal::RTT_PEER_NAN; |
| 2307 | }; |
| 2308 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | legacy_hal::wifi_channel_width convertHidlWifiChannelWidthToLegacy( |
| 2312 | WifiChannelWidthInMhz type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2313 | switch (type) { |
| 2314 | case WifiChannelWidthInMhz::WIDTH_20: |
| 2315 | return legacy_hal::WIFI_CHAN_WIDTH_20; |
| 2316 | case WifiChannelWidthInMhz::WIDTH_40: |
| 2317 | return legacy_hal::WIFI_CHAN_WIDTH_40; |
| 2318 | case WifiChannelWidthInMhz::WIDTH_80: |
| 2319 | return legacy_hal::WIFI_CHAN_WIDTH_80; |
| 2320 | case WifiChannelWidthInMhz::WIDTH_160: |
| 2321 | return legacy_hal::WIFI_CHAN_WIDTH_160; |
| 2322 | case WifiChannelWidthInMhz::WIDTH_80P80: |
| 2323 | return legacy_hal::WIFI_CHAN_WIDTH_80P80; |
| 2324 | case WifiChannelWidthInMhz::WIDTH_5: |
| 2325 | return legacy_hal::WIFI_CHAN_WIDTH_5; |
| 2326 | case WifiChannelWidthInMhz::WIDTH_10: |
| 2327 | return legacy_hal::WIFI_CHAN_WIDTH_10; |
| 2328 | case WifiChannelWidthInMhz::WIDTH_INVALID: |
| 2329 | return legacy_hal::WIFI_CHAN_WIDTH_INVALID; |
| 2330 | }; |
| 2331 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl( |
| 2335 | legacy_hal::wifi_channel_width type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2336 | switch (type) { |
| 2337 | case legacy_hal::WIFI_CHAN_WIDTH_20: |
| 2338 | return WifiChannelWidthInMhz::WIDTH_20; |
| 2339 | case legacy_hal::WIFI_CHAN_WIDTH_40: |
| 2340 | return WifiChannelWidthInMhz::WIDTH_40; |
| 2341 | case legacy_hal::WIFI_CHAN_WIDTH_80: |
| 2342 | return WifiChannelWidthInMhz::WIDTH_80; |
| 2343 | case legacy_hal::WIFI_CHAN_WIDTH_160: |
| 2344 | return WifiChannelWidthInMhz::WIDTH_160; |
| 2345 | case legacy_hal::WIFI_CHAN_WIDTH_80P80: |
| 2346 | return WifiChannelWidthInMhz::WIDTH_80P80; |
| 2347 | case legacy_hal::WIFI_CHAN_WIDTH_5: |
| 2348 | return WifiChannelWidthInMhz::WIDTH_5; |
| 2349 | case legacy_hal::WIFI_CHAN_WIDTH_10: |
| 2350 | return WifiChannelWidthInMhz::WIDTH_10; |
| 2351 | case legacy_hal::WIFI_CHAN_WIDTH_INVALID: |
| 2352 | return WifiChannelWidthInMhz::WIDTH_INVALID; |
| 2353 | }; |
| 2354 | CHECK(false) << "Unknown legacy type: " << type; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2355 | } |
| 2356 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2357 | legacy_hal::wifi_rtt_preamble convertHidlRttPreambleToLegacy( |
| 2358 | V1_4::RttPreamble type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2359 | switch (type) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2360 | case V1_4::RttPreamble::LEGACY: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2361 | return legacy_hal::WIFI_RTT_PREAMBLE_LEGACY; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2362 | case V1_4::RttPreamble::HT: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2363 | return legacy_hal::WIFI_RTT_PREAMBLE_HT; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2364 | case V1_4::RttPreamble::VHT: |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2365 | return legacy_hal::WIFI_RTT_PREAMBLE_VHT; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2366 | case V1_4::RttPreamble::HE: |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 2367 | return legacy_hal::WIFI_RTT_PREAMBLE_HE; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2368 | }; |
| 2369 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2372 | V1_4::RttPreamble convertLegacyRttPreambleToHidl( |
| 2373 | legacy_hal::wifi_rtt_preamble type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2374 | switch (type) { |
| 2375 | case legacy_hal::WIFI_RTT_PREAMBLE_LEGACY: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2376 | return V1_4::RttPreamble::LEGACY; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2377 | case legacy_hal::WIFI_RTT_PREAMBLE_HT: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2378 | return V1_4::RttPreamble::HT; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2379 | case legacy_hal::WIFI_RTT_PREAMBLE_VHT: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2380 | return V1_4::RttPreamble::VHT; |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 2381 | case legacy_hal::WIFI_RTT_PREAMBLE_HE: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2382 | return V1_4::RttPreamble::HE; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2383 | }; |
| 2384 | CHECK(false) << "Unknown legacy type: " << type; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | legacy_hal::wifi_rtt_bw convertHidlRttBwToLegacy(RttBw type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2388 | switch (type) { |
| 2389 | case RttBw::BW_5MHZ: |
| 2390 | return legacy_hal::WIFI_RTT_BW_5; |
| 2391 | case RttBw::BW_10MHZ: |
| 2392 | return legacy_hal::WIFI_RTT_BW_10; |
| 2393 | case RttBw::BW_20MHZ: |
| 2394 | return legacy_hal::WIFI_RTT_BW_20; |
| 2395 | case RttBw::BW_40MHZ: |
| 2396 | return legacy_hal::WIFI_RTT_BW_40; |
| 2397 | case RttBw::BW_80MHZ: |
| 2398 | return legacy_hal::WIFI_RTT_BW_80; |
| 2399 | case RttBw::BW_160MHZ: |
| 2400 | return legacy_hal::WIFI_RTT_BW_160; |
| 2401 | }; |
| 2402 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | RttBw convertLegacyRttBwToHidl(legacy_hal::wifi_rtt_bw type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2406 | switch (type) { |
| 2407 | case legacy_hal::WIFI_RTT_BW_5: |
| 2408 | return RttBw::BW_5MHZ; |
| 2409 | case legacy_hal::WIFI_RTT_BW_10: |
| 2410 | return RttBw::BW_10MHZ; |
| 2411 | case legacy_hal::WIFI_RTT_BW_20: |
| 2412 | return RttBw::BW_20MHZ; |
| 2413 | case legacy_hal::WIFI_RTT_BW_40: |
| 2414 | return RttBw::BW_40MHZ; |
| 2415 | case legacy_hal::WIFI_RTT_BW_80: |
| 2416 | return RttBw::BW_80MHZ; |
| 2417 | case legacy_hal::WIFI_RTT_BW_160: |
| 2418 | return RttBw::BW_160MHZ; |
| 2419 | }; |
| 2420 | CHECK(false) << "Unknown legacy type: " << type; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | legacy_hal::wifi_motion_pattern convertHidlRttMotionPatternToLegacy( |
| 2424 | RttMotionPattern type) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2425 | switch (type) { |
| 2426 | case RttMotionPattern::NOT_EXPECTED: |
| 2427 | return legacy_hal::WIFI_MOTION_NOT_EXPECTED; |
| 2428 | case RttMotionPattern::EXPECTED: |
| 2429 | return legacy_hal::WIFI_MOTION_EXPECTED; |
| 2430 | case RttMotionPattern::UNKNOWN: |
| 2431 | return legacy_hal::WIFI_MOTION_UNKNOWN; |
| 2432 | }; |
| 2433 | CHECK(false); |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2434 | } |
| 2435 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2436 | V1_4::WifiRatePreamble convertLegacyWifiRatePreambleToHidl(uint8_t preamble) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2437 | switch (preamble) { |
| 2438 | case 0: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2439 | return V1_4::WifiRatePreamble::OFDM; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2440 | case 1: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2441 | return V1_4::WifiRatePreamble::CCK; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2442 | case 2: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2443 | return V1_4::WifiRatePreamble::HT; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2444 | case 3: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2445 | return V1_4::WifiRatePreamble::VHT; |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 2446 | case 4: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2447 | return V1_4::WifiRatePreamble::HE; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2448 | default: |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2449 | return V1_4::WifiRatePreamble::RESERVED; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2450 | }; |
| 2451 | CHECK(false) << "Unknown legacy preamble: " << preamble; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | WifiRateNss convertLegacyWifiRateNssToHidl(uint8_t nss) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2455 | switch (nss) { |
| 2456 | case 0: |
| 2457 | return WifiRateNss::NSS_1x1; |
| 2458 | case 1: |
| 2459 | return WifiRateNss::NSS_2x2; |
| 2460 | case 2: |
| 2461 | return WifiRateNss::NSS_3x3; |
| 2462 | case 3: |
| 2463 | return WifiRateNss::NSS_4x4; |
| 2464 | }; |
| 2465 | CHECK(false) << "Unknown legacy nss: " << nss; |
| 2466 | return {}; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | RttStatus convertLegacyRttStatusToHidl(legacy_hal::wifi_rtt_status status) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2470 | switch (status) { |
| 2471 | case legacy_hal::RTT_STATUS_SUCCESS: |
| 2472 | return RttStatus::SUCCESS; |
| 2473 | case legacy_hal::RTT_STATUS_FAILURE: |
| 2474 | return RttStatus::FAILURE; |
| 2475 | case legacy_hal::RTT_STATUS_FAIL_NO_RSP: |
| 2476 | return RttStatus::FAIL_NO_RSP; |
| 2477 | case legacy_hal::RTT_STATUS_FAIL_REJECTED: |
| 2478 | return RttStatus::FAIL_REJECTED; |
| 2479 | case legacy_hal::RTT_STATUS_FAIL_NOT_SCHEDULED_YET: |
| 2480 | return RttStatus::FAIL_NOT_SCHEDULED_YET; |
| 2481 | case legacy_hal::RTT_STATUS_FAIL_TM_TIMEOUT: |
| 2482 | return RttStatus::FAIL_TM_TIMEOUT; |
| 2483 | case legacy_hal::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL: |
| 2484 | return RttStatus::FAIL_AP_ON_DIFF_CHANNEL; |
| 2485 | case legacy_hal::RTT_STATUS_FAIL_NO_CAPABILITY: |
| 2486 | return RttStatus::FAIL_NO_CAPABILITY; |
| 2487 | case legacy_hal::RTT_STATUS_ABORTED: |
| 2488 | return RttStatus::ABORTED; |
| 2489 | case legacy_hal::RTT_STATUS_FAIL_INVALID_TS: |
| 2490 | return RttStatus::FAIL_INVALID_TS; |
| 2491 | case legacy_hal::RTT_STATUS_FAIL_PROTOCOL: |
| 2492 | return RttStatus::FAIL_PROTOCOL; |
| 2493 | case legacy_hal::RTT_STATUS_FAIL_SCHEDULE: |
| 2494 | return RttStatus::FAIL_SCHEDULE; |
| 2495 | case legacy_hal::RTT_STATUS_FAIL_BUSY_TRY_LATER: |
| 2496 | return RttStatus::FAIL_BUSY_TRY_LATER; |
| 2497 | case legacy_hal::RTT_STATUS_INVALID_REQ: |
| 2498 | return RttStatus::INVALID_REQ; |
| 2499 | case legacy_hal::RTT_STATUS_NO_WIFI: |
| 2500 | return RttStatus::NO_WIFI; |
| 2501 | case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE: |
| 2502 | return RttStatus::FAIL_FTM_PARAM_OVERRIDE; |
Etan Cohen | 69c8922 | 2018-03-08 13:39:19 -0800 | [diff] [blame] | 2503 | case legacy_hal::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE: |
| 2504 | return RttStatus::FAILURE; // TODO: add HIDL enumeration |
| 2505 | case legacy_hal::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED: |
| 2506 | return RttStatus::FAILURE; // TODO: add HIDL enumeration |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2507 | }; |
| 2508 | CHECK(false) << "Unknown legacy status: " << status; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | bool convertHidlWifiChannelInfoToLegacy( |
| 2512 | const WifiChannelInfo& hidl_info, |
| 2513 | legacy_hal::wifi_channel_info* legacy_info) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2514 | if (!legacy_info) { |
| 2515 | return false; |
| 2516 | } |
| 2517 | *legacy_info = {}; |
| 2518 | legacy_info->width = convertHidlWifiChannelWidthToLegacy(hidl_info.width); |
| 2519 | legacy_info->center_freq = hidl_info.centerFreq; |
| 2520 | legacy_info->center_freq0 = hidl_info.centerFreq0; |
| 2521 | legacy_info->center_freq1 = hidl_info.centerFreq1; |
| 2522 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | bool convertLegacyWifiChannelInfoToHidl( |
| 2526 | const legacy_hal::wifi_channel_info& legacy_info, |
| 2527 | WifiChannelInfo* hidl_info) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2528 | if (!hidl_info) { |
| 2529 | return false; |
| 2530 | } |
| 2531 | *hidl_info = {}; |
| 2532 | hidl_info->width = convertLegacyWifiChannelWidthToHidl(legacy_info.width); |
| 2533 | hidl_info->centerFreq = legacy_info.center_freq; |
| 2534 | hidl_info->centerFreq0 = legacy_info.center_freq0; |
| 2535 | hidl_info->centerFreq1 = legacy_info.center_freq1; |
| 2536 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2539 | bool convertHidlRttConfigToLegacy(const V1_4::RttConfig& hidl_config, |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2540 | legacy_hal::wifi_rtt_config* legacy_config) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2541 | if (!legacy_config) { |
| 2542 | return false; |
| 2543 | } |
| 2544 | *legacy_config = {}; |
| 2545 | CHECK(hidl_config.addr.size() == sizeof(legacy_config->addr)); |
| 2546 | memcpy(legacy_config->addr, hidl_config.addr.data(), |
| 2547 | hidl_config.addr.size()); |
| 2548 | legacy_config->type = convertHidlRttTypeToLegacy(hidl_config.type); |
| 2549 | legacy_config->peer = convertHidlRttPeerTypeToLegacy(hidl_config.peer); |
| 2550 | if (!convertHidlWifiChannelInfoToLegacy(hidl_config.channel, |
| 2551 | &legacy_config->channel)) { |
| 2552 | return false; |
| 2553 | } |
| 2554 | legacy_config->burst_period = hidl_config.burstPeriod; |
| 2555 | legacy_config->num_burst = hidl_config.numBurst; |
| 2556 | legacy_config->num_frames_per_burst = hidl_config.numFramesPerBurst; |
| 2557 | legacy_config->num_retries_per_rtt_frame = |
| 2558 | hidl_config.numRetriesPerRttFrame; |
| 2559 | legacy_config->num_retries_per_ftmr = hidl_config.numRetriesPerFtmr; |
| 2560 | legacy_config->LCI_request = hidl_config.mustRequestLci; |
| 2561 | legacy_config->LCR_request = hidl_config.mustRequestLcr; |
| 2562 | legacy_config->burst_duration = hidl_config.burstDuration; |
| 2563 | legacy_config->preamble = |
| 2564 | convertHidlRttPreambleToLegacy(hidl_config.preamble); |
| 2565 | legacy_config->bw = convertHidlRttBwToLegacy(hidl_config.bw); |
| 2566 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2567 | } |
| 2568 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2569 | bool convertHidlVectorOfRttConfigToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2570 | const std::vector<V1_4::RttConfig>& hidl_configs, |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2571 | std::vector<legacy_hal::wifi_rtt_config>* legacy_configs) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2572 | if (!legacy_configs) { |
| 2573 | return false; |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2574 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2575 | *legacy_configs = {}; |
| 2576 | for (const auto& hidl_config : hidl_configs) { |
| 2577 | legacy_hal::wifi_rtt_config legacy_config; |
| 2578 | if (!convertHidlRttConfigToLegacy(hidl_config, &legacy_config)) { |
| 2579 | return false; |
| 2580 | } |
| 2581 | legacy_configs->push_back(legacy_config); |
| 2582 | } |
| 2583 | return true; |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2584 | } |
| 2585 | |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2586 | bool convertHidlRttLciInformationToLegacy( |
| 2587 | const RttLciInformation& hidl_info, |
| 2588 | legacy_hal::wifi_lci_information* legacy_info) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2589 | if (!legacy_info) { |
| 2590 | return false; |
| 2591 | } |
| 2592 | *legacy_info = {}; |
| 2593 | legacy_info->latitude = hidl_info.latitude; |
| 2594 | legacy_info->longitude = hidl_info.longitude; |
| 2595 | legacy_info->altitude = hidl_info.altitude; |
| 2596 | legacy_info->latitude_unc = hidl_info.latitudeUnc; |
| 2597 | legacy_info->longitude_unc = hidl_info.longitudeUnc; |
| 2598 | legacy_info->altitude_unc = hidl_info.altitudeUnc; |
| 2599 | legacy_info->motion_pattern = |
| 2600 | convertHidlRttMotionPatternToLegacy(hidl_info.motionPattern); |
| 2601 | legacy_info->floor = hidl_info.floor; |
| 2602 | legacy_info->height_above_floor = hidl_info.heightAboveFloor; |
| 2603 | legacy_info->height_unc = hidl_info.heightUnc; |
| 2604 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | bool convertHidlRttLcrInformationToLegacy( |
| 2608 | const RttLcrInformation& hidl_info, |
| 2609 | legacy_hal::wifi_lcr_information* legacy_info) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2610 | if (!legacy_info) { |
| 2611 | return false; |
| 2612 | } |
| 2613 | *legacy_info = {}; |
| 2614 | CHECK(hidl_info.countryCode.size() == sizeof(legacy_info->country_code)); |
| 2615 | memcpy(legacy_info->country_code, hidl_info.countryCode.data(), |
| 2616 | hidl_info.countryCode.size()); |
| 2617 | if (hidl_info.civicInfo.size() > sizeof(legacy_info->civic_info)) { |
| 2618 | return false; |
| 2619 | } |
| 2620 | legacy_info->length = hidl_info.civicInfo.size(); |
| 2621 | memcpy(legacy_info->civic_info, hidl_info.civicInfo.c_str(), |
| 2622 | hidl_info.civicInfo.size()); |
| 2623 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | bool convertHidlRttResponderToLegacy( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2627 | const V1_4::RttResponder& hidl_responder, |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2628 | legacy_hal::wifi_rtt_responder* legacy_responder) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2629 | if (!legacy_responder) { |
| 2630 | return false; |
| 2631 | } |
| 2632 | *legacy_responder = {}; |
| 2633 | if (!convertHidlWifiChannelInfoToLegacy(hidl_responder.channel, |
| 2634 | &legacy_responder->channel)) { |
| 2635 | return false; |
| 2636 | } |
| 2637 | legacy_responder->preamble = |
| 2638 | convertHidlRttPreambleToLegacy(hidl_responder.preamble); |
| 2639 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | bool convertLegacyRttResponderToHidl( |
| 2643 | const legacy_hal::wifi_rtt_responder& legacy_responder, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2644 | V1_4::RttResponder* hidl_responder) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2645 | if (!hidl_responder) { |
| 2646 | return false; |
| 2647 | } |
| 2648 | *hidl_responder = {}; |
| 2649 | if (!convertLegacyWifiChannelInfoToHidl(legacy_responder.channel, |
| 2650 | &hidl_responder->channel)) { |
| 2651 | return false; |
| 2652 | } |
| 2653 | hidl_responder->preamble = |
| 2654 | convertLegacyRttPreambleToHidl(legacy_responder.preamble); |
| 2655 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | bool convertLegacyRttCapabilitiesToHidl( |
| 2659 | const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2660 | V1_4::RttCapabilities* hidl_capabilities) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2661 | if (!hidl_capabilities) { |
| 2662 | return false; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2663 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2664 | *hidl_capabilities = {}; |
| 2665 | hidl_capabilities->rttOneSidedSupported = |
| 2666 | legacy_capabilities.rtt_one_sided_supported; |
| 2667 | hidl_capabilities->rttFtmSupported = legacy_capabilities.rtt_ftm_supported; |
| 2668 | hidl_capabilities->lciSupported = legacy_capabilities.lci_support; |
| 2669 | hidl_capabilities->lcrSupported = legacy_capabilities.lcr_support; |
| 2670 | hidl_capabilities->responderSupported = |
| 2671 | legacy_capabilities.responder_supported; |
| 2672 | hidl_capabilities->preambleSupport = 0; |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 2673 | for (const auto flag : |
| 2674 | {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, |
| 2675 | legacy_hal::WIFI_RTT_PREAMBLE_HT, legacy_hal::WIFI_RTT_PREAMBLE_VHT, |
| 2676 | legacy_hal::WIFI_RTT_PREAMBLE_HE}) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2677 | if (legacy_capabilities.preamble_support & flag) { |
| 2678 | hidl_capabilities->preambleSupport |= |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2679 | static_cast<std::underlying_type<V1_4::RttPreamble>::type>( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2680 | convertLegacyRttPreambleToHidl(flag)); |
| 2681 | } |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2682 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2683 | hidl_capabilities->bwSupport = 0; |
| 2684 | for (const auto flag : |
| 2685 | {legacy_hal::WIFI_RTT_BW_5, legacy_hal::WIFI_RTT_BW_10, |
| 2686 | legacy_hal::WIFI_RTT_BW_20, legacy_hal::WIFI_RTT_BW_40, |
| 2687 | legacy_hal::WIFI_RTT_BW_80, legacy_hal::WIFI_RTT_BW_160}) { |
| 2688 | if (legacy_capabilities.bw_support & flag) { |
| 2689 | hidl_capabilities->bwSupport |= |
| 2690 | static_cast<std::underlying_type<RttBw>::type>( |
| 2691 | convertLegacyRttBwToHidl(flag)); |
| 2692 | } |
| 2693 | } |
| 2694 | hidl_capabilities->mcVersion = legacy_capabilities.mc_version; |
| 2695 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2699 | V1_4::WifiRateInfo* hidl_rate) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2700 | if (!hidl_rate) { |
| 2701 | return false; |
| 2702 | } |
| 2703 | *hidl_rate = {}; |
| 2704 | hidl_rate->preamble = |
| 2705 | convertLegacyWifiRatePreambleToHidl(legacy_rate.preamble); |
| 2706 | hidl_rate->nss = convertLegacyWifiRateNssToHidl(legacy_rate.nss); |
| 2707 | hidl_rate->bw = convertLegacyWifiChannelWidthToHidl( |
| 2708 | static_cast<legacy_hal::wifi_channel_width>(legacy_rate.bw)); |
| 2709 | hidl_rate->rateMcsIdx = legacy_rate.rateMcsIdx; |
| 2710 | hidl_rate->bitRateInKbps = legacy_rate.bitrate; |
| 2711 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | bool convertLegacyRttResultToHidl( |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2715 | const legacy_hal::wifi_rtt_result& legacy_result, |
| 2716 | V1_4::RttResult* hidl_result) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2717 | if (!hidl_result) { |
| 2718 | return false; |
| 2719 | } |
| 2720 | *hidl_result = {}; |
| 2721 | CHECK(sizeof(legacy_result.addr) == hidl_result->addr.size()); |
| 2722 | memcpy(hidl_result->addr.data(), legacy_result.addr, |
| 2723 | sizeof(legacy_result.addr)); |
| 2724 | hidl_result->burstNum = legacy_result.burst_num; |
| 2725 | hidl_result->measurementNumber = legacy_result.measurement_number; |
| 2726 | hidl_result->successNumber = legacy_result.success_number; |
| 2727 | hidl_result->numberPerBurstPeer = legacy_result.number_per_burst_peer; |
| 2728 | hidl_result->status = convertLegacyRttStatusToHidl(legacy_result.status); |
| 2729 | hidl_result->retryAfterDuration = legacy_result.retry_after_duration; |
| 2730 | hidl_result->type = convertLegacyRttTypeToHidl(legacy_result.type); |
| 2731 | hidl_result->rssi = legacy_result.rssi; |
| 2732 | hidl_result->rssiSpread = legacy_result.rssi_spread; |
| 2733 | if (!convertLegacyWifiRateInfoToHidl(legacy_result.tx_rate, |
| 2734 | &hidl_result->txRate)) { |
| 2735 | return false; |
| 2736 | } |
| 2737 | if (!convertLegacyWifiRateInfoToHidl(legacy_result.rx_rate, |
| 2738 | &hidl_result->rxRate)) { |
| 2739 | return false; |
| 2740 | } |
| 2741 | hidl_result->rtt = legacy_result.rtt; |
| 2742 | hidl_result->rttSd = legacy_result.rtt_sd; |
| 2743 | hidl_result->rttSpread = legacy_result.rtt_spread; |
| 2744 | hidl_result->distanceInMm = legacy_result.distance_mm; |
| 2745 | hidl_result->distanceSdInMm = legacy_result.distance_sd_mm; |
| 2746 | hidl_result->distanceSpreadInMm = legacy_result.distance_spread_mm; |
| 2747 | hidl_result->timeStampInUs = legacy_result.ts; |
| 2748 | hidl_result->burstDurationInMs = legacy_result.burst_duration; |
| 2749 | hidl_result->negotiatedBurstNum = legacy_result.negotiated_burst_num; |
| 2750 | if (legacy_result.LCI && |
| 2751 | !convertLegacyIeToHidl(*legacy_result.LCI, &hidl_result->lci)) { |
| 2752 | return false; |
| 2753 | } |
| 2754 | if (legacy_result.LCR && |
| 2755 | !convertLegacyIeToHidl(*legacy_result.LCR, &hidl_result->lcr)) { |
| 2756 | return false; |
| 2757 | } |
| 2758 | return true; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 2759 | } |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2760 | |
| 2761 | bool convertLegacyVectorOfRttResultToHidl( |
| 2762 | const std::vector<const legacy_hal::wifi_rtt_result*>& legacy_results, |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2763 | std::vector<V1_4::RttResult>* hidl_results) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2764 | if (!hidl_results) { |
| 2765 | return false; |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2766 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2767 | *hidl_results = {}; |
| 2768 | for (const auto legacy_result : legacy_results) { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2769 | V1_4::RttResult hidl_result; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 2770 | if (!convertLegacyRttResultToHidl(*legacy_result, &hidl_result)) { |
| 2771 | return false; |
| 2772 | } |
| 2773 | hidl_results->push_back(hidl_result); |
| 2774 | } |
| 2775 | return true; |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 2776 | } |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 2777 | |
| 2778 | legacy_hal::wifi_interface_type convertHidlIfaceTypeToLegacy( |
| 2779 | IfaceType hidl_interface_type) { |
| 2780 | switch (hidl_interface_type) { |
| 2781 | case IfaceType::STA: |
| 2782 | return legacy_hal::WIFI_INTERFACE_TYPE_STA; |
| 2783 | case IfaceType::AP: |
| 2784 | return legacy_hal::WIFI_INTERFACE_TYPE_AP; |
| 2785 | case IfaceType::P2P: |
| 2786 | return legacy_hal::WIFI_INTERFACE_TYPE_P2P; |
| 2787 | case IfaceType::NAN: |
| 2788 | return legacy_hal::WIFI_INTERFACE_TYPE_NAN; |
| 2789 | } |
| 2790 | CHECK(false); |
| 2791 | } |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 2792 | |
| 2793 | legacy_hal::wifi_multi_sta_use_case convertHidlMultiStaUseCaseToLegacy( |
| 2794 | IWifiChip::MultiStaUseCase use_case) { |
| 2795 | switch (use_case) { |
| 2796 | case IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY: |
| 2797 | return legacy_hal::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY; |
| 2798 | case IWifiChip::MultiStaUseCase::DUAL_STA_NON_TRANSIENT_UNBIASED: |
| 2799 | return legacy_hal::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED; |
| 2800 | } |
| 2801 | CHECK(false); |
| 2802 | } |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 2803 | } // namespace hidl_struct_util |
| 2804 | } // namespace implementation |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 2805 | } // namespace V1_5 |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 2806 | } // namespace wifi |
| 2807 | } // namespace hardware |
| 2808 | } // namespace android |