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