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