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