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 { |
| 25 | namespace V1_0 { |
| 26 | namespace implementation { |
| 27 | namespace hidl_struct_util { |
| 28 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 29 | IWifiChip::ChipCapabilityMask convertLegacyLoggerFeatureToHidlChipCapability( |
| 30 | uint32_t feature) { |
| 31 | using HidlChipCaps = IWifiChip::ChipCapabilityMask; |
| 32 | switch (feature) { |
| 33 | case legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 34 | return HidlChipCaps::DEBUG_MEMORY_FIRMWARE_DUMP; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 35 | case legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 36 | return HidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 37 | case legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 38 | return HidlChipCaps::DEBUG_RING_BUFFER_CONNECT_EVENT; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 39 | case legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 40 | return HidlChipCaps::DEBUG_RING_BUFFER_POWER_EVENT; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 41 | case legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 42 | return HidlChipCaps::DEBUG_RING_BUFFER_WAKELOCK_EVENT; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 43 | }; |
| 44 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 45 | return {}; |
| 46 | } |
| 47 | |
| 48 | IWifiStaIface::StaIfaceCapabilityMask |
| 49 | convertLegacyLoggerFeatureToHidlStaIfaceCapability(uint32_t feature) { |
| 50 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 51 | switch (feature) { |
| 52 | case legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED: |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 53 | return HidlStaIfaceCaps::DEBUG_PACKET_FATE; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 54 | }; |
| 55 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 56 | return {}; |
| 57 | } |
| 58 | |
| 59 | IWifiStaIface::StaIfaceCapabilityMask |
| 60 | convertLegacyFeatureToHidlStaIfaceCapability(uint32_t feature) { |
| 61 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 62 | switch (feature) { |
| 63 | case WIFI_FEATURE_GSCAN: |
| 64 | return HidlStaIfaceCaps::BACKGROUND_SCAN; |
| 65 | case WIFI_FEATURE_LINK_LAYER_STATS: |
| 66 | return HidlStaIfaceCaps::LINK_LAYER_STATS; |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 67 | case WIFI_FEATURE_RSSI_MONITOR: |
| 68 | return HidlStaIfaceCaps::RSSI_MONITOR; |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 69 | case WIFI_FEATURE_CONTROL_ROAMING: |
| 70 | return HidlStaIfaceCaps::CONTROL_ROAMING; |
| 71 | case WIFI_FEATURE_IE_WHITELIST: |
| 72 | return HidlStaIfaceCaps::PROBE_IE_WHITELIST; |
| 73 | case WIFI_FEATURE_SCAN_RAND: |
| 74 | return HidlStaIfaceCaps::SCAN_RAND; |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 75 | case WIFI_FEATURE_INFRA_5G: |
| 76 | return HidlStaIfaceCaps::STA_5G; |
| 77 | case WIFI_FEATURE_HOTSPOT: |
| 78 | return HidlStaIfaceCaps::HOTSPOT; |
| 79 | case WIFI_FEATURE_PNO: |
| 80 | return HidlStaIfaceCaps::PNO; |
| 81 | case WIFI_FEATURE_TDLS: |
| 82 | return HidlStaIfaceCaps::TDLS; |
| 83 | case WIFI_FEATURE_TDLS_OFFCHANNEL: |
| 84 | return HidlStaIfaceCaps::TDLS_OFFCHANNEL; |
Roshan Pius | 656f820 | 2017-01-17 12:58:05 -0800 | [diff] [blame] | 85 | case WIFI_FEATURE_CONFIG_NDO: |
| 86 | return HidlStaIfaceCaps::ND_OFFLOAD; |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 87 | case WIFI_FEATURE_MKEEP_ALIVE: |
| 88 | return HidlStaIfaceCaps::KEEP_ALIVE; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 89 | }; |
| 90 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 91 | return {}; |
| 92 | } |
| 93 | |
| 94 | bool convertLegacyFeaturesToHidlChipCapabilities( |
| 95 | uint32_t legacy_logger_feature_set, uint32_t* hidl_caps) { |
| 96 | if (!hidl_caps) { |
| 97 | return false; |
| 98 | } |
| 99 | *hidl_caps = 0; |
| 100 | using HidlChipCaps = IWifiChip::ChipCapabilityMask; |
| 101 | for (const auto feature : {legacy_hal::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED, |
| 102 | legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED, |
| 103 | legacy_hal::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED, |
| 104 | legacy_hal::WIFI_LOGGER_POWER_EVENT_SUPPORTED, |
| 105 | legacy_hal::WIFI_LOGGER_WAKE_LOCK_SUPPORTED}) { |
| 106 | if (feature & legacy_logger_feature_set) { |
| 107 | *hidl_caps |= convertLegacyLoggerFeatureToHidlChipCapability(feature); |
| 108 | } |
| 109 | } |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 110 | // There are no flags for these 3 in the legacy feature set. Adding them to |
| 111 | // the set because all the current devices support it. |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 112 | *hidl_caps |= HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 113 | *hidl_caps |= HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS; |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 114 | *hidl_caps |= HidlChipCaps::DEBUG_ERROR_ALERTS; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 115 | return true; |
| 116 | } |
| 117 | |
| 118 | WifiDebugRingBufferFlags convertLegacyDebugRingBufferFlagsToHidl( |
| 119 | uint32_t flag) { |
| 120 | switch (flag) { |
| 121 | case WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES: |
| 122 | return WifiDebugRingBufferFlags::HAS_BINARY_ENTRIES; |
| 123 | case WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES: |
| 124 | return WifiDebugRingBufferFlags::HAS_ASCII_ENTRIES; |
| 125 | }; |
| 126 | CHECK(false) << "Unknown legacy flag: " << flag; |
| 127 | return {}; |
| 128 | } |
| 129 | |
| 130 | bool convertLegacyDebugRingBufferStatusToHidl( |
| 131 | const legacy_hal::wifi_ring_buffer_status& legacy_status, |
| 132 | WifiDebugRingBufferStatus* hidl_status) { |
| 133 | if (!hidl_status) { |
| 134 | return false; |
| 135 | } |
| 136 | hidl_status->ringName = reinterpret_cast<const char*>(legacy_status.name); |
Roshan Pius | 88c3272 | 2017-02-16 12:43:17 -0800 | [diff] [blame] | 137 | hidl_status->flags = 0; |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 138 | for (const auto flag : {WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES, |
| 139 | WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES}) { |
| 140 | if (flag & legacy_status.flags) { |
| 141 | hidl_status->flags |= |
| 142 | static_cast<std::underlying_type<WifiDebugRingBufferFlags>::type>( |
| 143 | convertLegacyDebugRingBufferFlagsToHidl(flag)); |
| 144 | } |
| 145 | } |
| 146 | hidl_status->ringId = legacy_status.ring_id; |
| 147 | hidl_status->sizeInBytes = legacy_status.ring_buffer_byte_size; |
| 148 | // Calculate free size of the ring the buffer. We don't need to send the |
| 149 | // exact read/write pointers that were there in the legacy HAL interface. |
| 150 | if (legacy_status.written_bytes >= legacy_status.read_bytes) { |
| 151 | hidl_status->freeSizeInBytes = |
| 152 | legacy_status.ring_buffer_byte_size - |
| 153 | (legacy_status.written_bytes - legacy_status.read_bytes); |
| 154 | } else { |
| 155 | hidl_status->freeSizeInBytes = |
| 156 | legacy_status.read_bytes - legacy_status.written_bytes; |
| 157 | } |
| 158 | hidl_status->verboseLevel = legacy_status.verbose_level; |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | bool convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 163 | const std::vector<legacy_hal::wifi_ring_buffer_status>& legacy_status_vec, |
| 164 | std::vector<WifiDebugRingBufferStatus>* hidl_status_vec) { |
| 165 | if (!hidl_status_vec) { |
| 166 | return false; |
| 167 | } |
| 168 | hidl_status_vec->clear(); |
| 169 | for (const auto& legacy_status : legacy_status_vec) { |
| 170 | WifiDebugRingBufferStatus hidl_status; |
| 171 | if (!convertLegacyDebugRingBufferStatusToHidl(legacy_status, |
| 172 | &hidl_status)) { |
| 173 | return false; |
| 174 | } |
| 175 | hidl_status_vec->push_back(hidl_status); |
| 176 | } |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | bool convertLegacyWakeReasonStatsToHidl( |
| 181 | const legacy_hal::WakeReasonStats& legacy_stats, |
| 182 | WifiDebugHostWakeReasonStats* hidl_stats) { |
| 183 | if (!hidl_stats) { |
| 184 | return false; |
| 185 | } |
| 186 | hidl_stats->totalCmdEventWakeCnt = |
| 187 | legacy_stats.wake_reason_cnt.total_cmd_event_wake; |
| 188 | hidl_stats->cmdEventWakeCntPerType = legacy_stats.cmd_event_wake_cnt; |
| 189 | hidl_stats->totalDriverFwLocalWakeCnt = |
| 190 | legacy_stats.wake_reason_cnt.total_driver_fw_local_wake; |
| 191 | hidl_stats->driverFwLocalWakeCntPerType = |
| 192 | legacy_stats.driver_fw_local_wake_cnt; |
| 193 | hidl_stats->totalRxPacketWakeCnt = |
| 194 | legacy_stats.wake_reason_cnt.total_rx_data_wake; |
| 195 | hidl_stats->rxPktWakeDetails.rxUnicastCnt = |
| 196 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_unicast_cnt; |
| 197 | hidl_stats->rxPktWakeDetails.rxMulticastCnt = |
| 198 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_multicast_cnt; |
| 199 | hidl_stats->rxPktWakeDetails.rxBroadcastCnt = |
| 200 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_broadcast_cnt; |
| 201 | hidl_stats->rxMulticastPkWakeDetails.ipv4RxMulticastAddrCnt = |
| 202 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 203 | .ipv4_rx_multicast_addr_cnt; |
| 204 | hidl_stats->rxMulticastPkWakeDetails.ipv6RxMulticastAddrCnt = |
| 205 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 206 | .ipv6_rx_multicast_addr_cnt; |
| 207 | hidl_stats->rxMulticastPkWakeDetails.otherRxMulticastAddrCnt = |
| 208 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info |
| 209 | .other_rx_multicast_addr_cnt; |
| 210 | hidl_stats->rxIcmpPkWakeDetails.icmpPkt = |
| 211 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp_pkt; |
| 212 | hidl_stats->rxIcmpPkWakeDetails.icmp6Pkt = |
| 213 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_pkt; |
| 214 | hidl_stats->rxIcmpPkWakeDetails.icmp6Ra = |
| 215 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ra; |
| 216 | hidl_stats->rxIcmpPkWakeDetails.icmp6Na = |
| 217 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_na; |
| 218 | hidl_stats->rxIcmpPkWakeDetails.icmp6Ns = |
| 219 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ns; |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | bool convertLegacyFeaturesToHidlStaCapabilities( |
| 224 | uint32_t legacy_feature_set, |
| 225 | uint32_t legacy_logger_feature_set, |
| 226 | uint32_t* hidl_caps) { |
| 227 | if (!hidl_caps) { |
| 228 | return false; |
| 229 | } |
| 230 | *hidl_caps = 0; |
| 231 | using HidlStaIfaceCaps = IWifiStaIface::StaIfaceCapabilityMask; |
| 232 | for (const auto feature : {legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED}) { |
| 233 | if (feature & legacy_logger_feature_set) { |
| 234 | *hidl_caps |= convertLegacyLoggerFeatureToHidlStaIfaceCapability(feature); |
| 235 | } |
| 236 | } |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 237 | for (const auto feature : {WIFI_FEATURE_GSCAN, |
| 238 | WIFI_FEATURE_LINK_LAYER_STATS, |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 239 | WIFI_FEATURE_RSSI_MONITOR, |
| 240 | WIFI_FEATURE_CONTROL_ROAMING, |
| 241 | WIFI_FEATURE_IE_WHITELIST, |
Roshan Pius | a2d369d | 2016-12-15 22:38:00 -0800 | [diff] [blame] | 242 | WIFI_FEATURE_SCAN_RAND, |
| 243 | WIFI_FEATURE_INFRA_5G, |
| 244 | WIFI_FEATURE_HOTSPOT, |
| 245 | WIFI_FEATURE_PNO, |
| 246 | WIFI_FEATURE_TDLS, |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 247 | WIFI_FEATURE_TDLS_OFFCHANNEL, |
Roshan Pius | 656f820 | 2017-01-17 12:58:05 -0800 | [diff] [blame] | 248 | WIFI_FEATURE_CONFIG_NDO, |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 249 | WIFI_FEATURE_MKEEP_ALIVE}) { |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 250 | if (feature & legacy_feature_set) { |
| 251 | *hidl_caps |= convertLegacyFeatureToHidlStaIfaceCapability(feature); |
| 252 | } |
| 253 | } |
| 254 | // There is no flag for this one in the legacy feature set. Adding it to the |
| 255 | // set because all the current devices support it. |
| 256 | *hidl_caps |= HidlStaIfaceCaps::APF; |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | bool convertLegacyApfCapabilitiesToHidl( |
| 261 | const legacy_hal::PacketFilterCapabilities& legacy_caps, |
| 262 | StaApfPacketFilterCapabilities* hidl_caps) { |
| 263 | if (!hidl_caps) { |
| 264 | return false; |
| 265 | } |
| 266 | hidl_caps->version = legacy_caps.version; |
| 267 | hidl_caps->maxLength = legacy_caps.max_len; |
| 268 | return true; |
| 269 | } |
| 270 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 271 | uint8_t convertHidlGscanReportEventFlagToLegacy( |
| 272 | StaBackgroundScanBucketEventReportSchemeMask hidl_flag) { |
| 273 | using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 274 | switch (hidl_flag) { |
| 275 | case HidlFlag::EACH_SCAN: |
| 276 | return REPORT_EVENTS_EACH_SCAN; |
| 277 | case HidlFlag::FULL_RESULTS: |
| 278 | return REPORT_EVENTS_FULL_RESULTS; |
| 279 | case HidlFlag::NO_BATCH: |
| 280 | return REPORT_EVENTS_NO_BATCH; |
| 281 | }; |
| 282 | CHECK(false); |
| 283 | } |
| 284 | |
| 285 | StaScanDataFlagMask convertLegacyGscanDataFlagToHidl(uint8_t legacy_flag) { |
| 286 | switch (legacy_flag) { |
| 287 | case legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED: |
| 288 | return StaScanDataFlagMask::INTERRUPTED; |
| 289 | }; |
| 290 | CHECK(false) << "Unknown legacy flag: " << legacy_flag; |
| 291 | // To silence the compiler warning about reaching the end of non-void |
| 292 | // function. |
| 293 | return {}; |
| 294 | } |
| 295 | |
| 296 | bool convertLegacyGscanCapabilitiesToHidl( |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 297 | const legacy_hal::wifi_gscan_capabilities& legacy_caps, |
| 298 | StaBackgroundScanCapabilities* hidl_caps) { |
| 299 | if (!hidl_caps) { |
| 300 | return false; |
| 301 | } |
| 302 | hidl_caps->maxCacheSize = legacy_caps.max_scan_cache_size; |
| 303 | hidl_caps->maxBuckets = legacy_caps.max_scan_buckets; |
| 304 | hidl_caps->maxApCachePerScan = legacy_caps.max_ap_cache_per_scan; |
| 305 | hidl_caps->maxReportingThreshold = legacy_caps.max_scan_reporting_threshold; |
| 306 | return true; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 309 | legacy_hal::wifi_band convertHidlGscanBandToLegacy(StaBackgroundScanBand band) { |
| 310 | switch (band) { |
| 311 | case StaBackgroundScanBand::BAND_UNSPECIFIED: |
| 312 | return legacy_hal::WIFI_BAND_UNSPECIFIED; |
| 313 | case StaBackgroundScanBand::BAND_24GHZ: |
| 314 | return legacy_hal::WIFI_BAND_BG; |
| 315 | case StaBackgroundScanBand::BAND_5GHZ: |
| 316 | return legacy_hal::WIFI_BAND_A; |
| 317 | case StaBackgroundScanBand::BAND_5GHZ_DFS: |
| 318 | return legacy_hal::WIFI_BAND_A_DFS; |
| 319 | case StaBackgroundScanBand::BAND_5GHZ_WITH_DFS: |
| 320 | return legacy_hal::WIFI_BAND_A_WITH_DFS; |
| 321 | case StaBackgroundScanBand::BAND_24GHZ_5GHZ: |
| 322 | return legacy_hal::WIFI_BAND_ABG; |
| 323 | case StaBackgroundScanBand::BAND_24GHZ_5GHZ_WITH_DFS: |
| 324 | return legacy_hal::WIFI_BAND_ABG_WITH_DFS; |
| 325 | }; |
| 326 | CHECK(false); |
| 327 | } |
| 328 | |
| 329 | bool convertHidlGscanParamsToLegacy( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 330 | const StaBackgroundScanParameters& hidl_scan_params, |
| 331 | legacy_hal::wifi_scan_cmd_params* legacy_scan_params) { |
| 332 | if (!legacy_scan_params) { |
| 333 | return false; |
| 334 | } |
| 335 | legacy_scan_params->base_period = hidl_scan_params.basePeriodInMs; |
| 336 | legacy_scan_params->max_ap_per_scan = hidl_scan_params.maxApPerScan; |
| 337 | legacy_scan_params->report_threshold_percent = |
| 338 | hidl_scan_params.reportThresholdPercent; |
| 339 | legacy_scan_params->report_threshold_num_scans = |
| 340 | hidl_scan_params.reportThresholdNumScans; |
| 341 | // TODO(b/33194311): Expose these max limits in the HIDL interface. |
| 342 | if (hidl_scan_params.buckets.size() > MAX_BUCKETS) { |
| 343 | return false; |
| 344 | } |
| 345 | legacy_scan_params->num_buckets = hidl_scan_params.buckets.size(); |
| 346 | for (uint32_t bucket_idx = 0; bucket_idx < hidl_scan_params.buckets.size(); |
| 347 | bucket_idx++) { |
| 348 | const StaBackgroundScanBucketParameters& hidl_bucket_spec = |
| 349 | hidl_scan_params.buckets[bucket_idx]; |
| 350 | legacy_hal::wifi_scan_bucket_spec& legacy_bucket_spec = |
| 351 | legacy_scan_params->buckets[bucket_idx]; |
| 352 | legacy_bucket_spec.bucket = bucket_idx; |
| 353 | legacy_bucket_spec.band = |
| 354 | static_cast<legacy_hal::wifi_band>(hidl_bucket_spec.band); |
| 355 | legacy_bucket_spec.period = hidl_bucket_spec.periodInMs; |
| 356 | legacy_bucket_spec.max_period = hidl_bucket_spec.exponentialMaxPeriodInMs; |
| 357 | legacy_bucket_spec.base = hidl_bucket_spec.exponentialBase; |
| 358 | legacy_bucket_spec.step_count = hidl_bucket_spec.exponentialStepCount; |
| 359 | legacy_bucket_spec.report_events = 0; |
| 360 | using HidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 361 | for (const auto flag : |
| 362 | {HidlFlag::EACH_SCAN, HidlFlag::FULL_RESULTS, HidlFlag::NO_BATCH}) { |
| 363 | if (hidl_bucket_spec.eventReportScheme & |
| 364 | static_cast<std::underlying_type<HidlFlag>::type>(flag)) { |
| 365 | legacy_bucket_spec.report_events |= |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 366 | convertHidlGscanReportEventFlagToLegacy(flag); |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | // TODO(b/33194311): Expose these max limits in the HIDL interface. |
| 370 | if (hidl_bucket_spec.frequencies.size() > MAX_CHANNELS) { |
| 371 | return false; |
| 372 | } |
| 373 | legacy_bucket_spec.num_channels = hidl_bucket_spec.frequencies.size(); |
| 374 | for (uint32_t freq_idx = 0; freq_idx < hidl_bucket_spec.frequencies.size(); |
| 375 | freq_idx++) { |
| 376 | legacy_bucket_spec.channels[freq_idx].channel = |
| 377 | hidl_bucket_spec.frequencies[freq_idx]; |
| 378 | } |
| 379 | } |
| 380 | return true; |
| 381 | } |
| 382 | |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 383 | bool convertLegacyIeToHidl( |
| 384 | const legacy_hal::wifi_information_element& legacy_ie, |
| 385 | WifiInformationElement* hidl_ie) { |
| 386 | if (!hidl_ie) { |
| 387 | return false; |
| 388 | } |
| 389 | hidl_ie->id = legacy_ie.id; |
| 390 | hidl_ie->data = |
| 391 | std::vector<uint8_t>(legacy_ie.data, legacy_ie.data + legacy_ie.len); |
| 392 | return true; |
| 393 | } |
| 394 | |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 395 | bool convertLegacyIeBlobToHidl(const uint8_t* ie_blob, |
| 396 | uint32_t ie_blob_len, |
| 397 | std::vector<WifiInformationElement>* hidl_ies) { |
| 398 | if (!ie_blob || !hidl_ies) { |
| 399 | return false; |
| 400 | } |
| 401 | const uint8_t* ies_begin = ie_blob; |
| 402 | const uint8_t* ies_end = ie_blob + ie_blob_len; |
| 403 | const uint8_t* next_ie = ies_begin; |
| 404 | using wifi_ie = legacy_hal::wifi_information_element; |
| 405 | constexpr size_t kIeHeaderLen = sizeof(wifi_ie); |
| 406 | // Each IE should atleast have the header (i.e |id| & |len| fields). |
| 407 | while (next_ie + kIeHeaderLen <= ies_end) { |
| 408 | const wifi_ie& legacy_ie = (*reinterpret_cast<const wifi_ie*>(next_ie)); |
| 409 | uint32_t curr_ie_len = kIeHeaderLen + legacy_ie.len; |
| 410 | if (next_ie + curr_ie_len > ies_end) { |
| 411 | return false; |
| 412 | } |
| 413 | WifiInformationElement hidl_ie; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 414 | if (!convertLegacyIeToHidl(legacy_ie, &hidl_ie)) { |
| 415 | return false; |
| 416 | } |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 417 | hidl_ies->push_back(std::move(hidl_ie)); |
| 418 | next_ie += curr_ie_len; |
| 419 | } |
| 420 | // Ensure that the blob has been fully consumed. |
| 421 | return (next_ie == ies_end); |
| 422 | } |
| 423 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 424 | bool convertLegacyGscanResultToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 425 | const legacy_hal::wifi_scan_result& legacy_scan_result, |
| 426 | bool has_ie_data, |
| 427 | StaScanResult* hidl_scan_result) { |
| 428 | if (!hidl_scan_result) { |
| 429 | return false; |
| 430 | } |
| 431 | hidl_scan_result->timeStampInUs = legacy_scan_result.ts; |
| 432 | hidl_scan_result->ssid = std::vector<uint8_t>( |
| 433 | legacy_scan_result.ssid, |
| 434 | legacy_scan_result.ssid + sizeof(legacy_scan_result.ssid)); |
| 435 | memcpy(hidl_scan_result->bssid.data(), |
| 436 | legacy_scan_result.bssid, |
| 437 | hidl_scan_result->bssid.size()); |
| 438 | hidl_scan_result->frequency = legacy_scan_result.channel; |
| 439 | hidl_scan_result->rssi = legacy_scan_result.rssi; |
| 440 | hidl_scan_result->beaconPeriodInMs = legacy_scan_result.beacon_period; |
| 441 | hidl_scan_result->capability = legacy_scan_result.capability; |
| 442 | if (has_ie_data) { |
| 443 | std::vector<WifiInformationElement> ies; |
| 444 | if (!convertLegacyIeBlobToHidl( |
| 445 | reinterpret_cast<const uint8_t*>(legacy_scan_result.ie_data), |
| 446 | legacy_scan_result.ie_length, |
| 447 | &ies)) { |
| 448 | return false; |
| 449 | } |
| 450 | hidl_scan_result->informationElements = std::move(ies); |
| 451 | } |
| 452 | return true; |
| 453 | } |
| 454 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 455 | bool convertLegacyCachedGscanResultsToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 456 | const legacy_hal::wifi_cached_scan_results& legacy_cached_scan_result, |
| 457 | StaScanData* hidl_scan_data) { |
| 458 | if (!hidl_scan_data) { |
| 459 | return false; |
| 460 | } |
Roshan Pius | 88c3272 | 2017-02-16 12:43:17 -0800 | [diff] [blame] | 461 | hidl_scan_data->flags = 0; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 462 | for (const auto flag : {legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED}) { |
| 463 | if (legacy_cached_scan_result.flags & flag) { |
| 464 | hidl_scan_data->flags |= |
| 465 | static_cast<std::underlying_type<StaScanDataFlagMask>::type>( |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 466 | convertLegacyGscanDataFlagToHidl(flag)); |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 467 | } |
| 468 | } |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 469 | hidl_scan_data->bucketsScanned = legacy_cached_scan_result.buckets_scanned; |
| 470 | |
| 471 | CHECK(legacy_cached_scan_result.num_results >= 0 && |
| 472 | legacy_cached_scan_result.num_results <= MAX_AP_CACHE_PER_SCAN); |
| 473 | std::vector<StaScanResult> hidl_scan_results; |
| 474 | for (int32_t result_idx = 0; |
| 475 | result_idx < legacy_cached_scan_result.num_results; |
| 476 | result_idx++) { |
| 477 | StaScanResult hidl_scan_result; |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 478 | if (!convertLegacyGscanResultToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 479 | legacy_cached_scan_result.results[result_idx], |
| 480 | false, |
| 481 | &hidl_scan_result)) { |
| 482 | return false; |
| 483 | } |
| 484 | hidl_scan_results.push_back(hidl_scan_result); |
| 485 | } |
| 486 | hidl_scan_data->results = std::move(hidl_scan_results); |
| 487 | return true; |
| 488 | } |
| 489 | |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 490 | bool convertLegacyVectorOfCachedGscanResultsToHidl( |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 491 | const std::vector<legacy_hal::wifi_cached_scan_results>& |
| 492 | legacy_cached_scan_results, |
| 493 | std::vector<StaScanData>* hidl_scan_datas) { |
| 494 | if (!hidl_scan_datas) { |
| 495 | return false; |
| 496 | } |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 497 | hidl_scan_datas->clear(); |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 498 | for (const auto& legacy_cached_scan_result : legacy_cached_scan_results) { |
| 499 | StaScanData hidl_scan_data; |
Roshan Pius | 881d1f7 | 2016-12-05 15:37:00 -0800 | [diff] [blame] | 500 | if (!convertLegacyCachedGscanResultsToHidl(legacy_cached_scan_result, |
| 501 | &hidl_scan_data)) { |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | hidl_scan_datas->push_back(hidl_scan_data); |
| 505 | } |
| 506 | return true; |
| 507 | } |
| 508 | |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 509 | WifiDebugTxPacketFate convertLegacyDebugTxPacketFateToHidl( |
| 510 | legacy_hal::wifi_tx_packet_fate fate) { |
| 511 | switch (fate) { |
| 512 | case legacy_hal::TX_PKT_FATE_ACKED: |
| 513 | return WifiDebugTxPacketFate::ACKED; |
| 514 | case legacy_hal::TX_PKT_FATE_SENT: |
| 515 | return WifiDebugTxPacketFate::SENT; |
| 516 | case legacy_hal::TX_PKT_FATE_FW_QUEUED: |
| 517 | return WifiDebugTxPacketFate::FW_QUEUED; |
| 518 | case legacy_hal::TX_PKT_FATE_FW_DROP_INVALID: |
| 519 | return WifiDebugTxPacketFate::FW_DROP_INVALID; |
| 520 | case legacy_hal::TX_PKT_FATE_FW_DROP_NOBUFS: |
| 521 | return WifiDebugTxPacketFate::FW_DROP_NOBUFS; |
| 522 | case legacy_hal::TX_PKT_FATE_FW_DROP_OTHER: |
| 523 | return WifiDebugTxPacketFate::FW_DROP_OTHER; |
| 524 | case legacy_hal::TX_PKT_FATE_DRV_QUEUED: |
| 525 | return WifiDebugTxPacketFate::DRV_QUEUED; |
| 526 | case legacy_hal::TX_PKT_FATE_DRV_DROP_INVALID: |
| 527 | return WifiDebugTxPacketFate::DRV_DROP_INVALID; |
| 528 | case legacy_hal::TX_PKT_FATE_DRV_DROP_NOBUFS: |
| 529 | return WifiDebugTxPacketFate::DRV_DROP_NOBUFS; |
| 530 | case legacy_hal::TX_PKT_FATE_DRV_DROP_OTHER: |
| 531 | return WifiDebugTxPacketFate::DRV_DROP_OTHER; |
| 532 | }; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 533 | CHECK(false) << "Unknown legacy fate type: " << fate; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | WifiDebugRxPacketFate convertLegacyDebugRxPacketFateToHidl( |
| 537 | legacy_hal::wifi_rx_packet_fate fate) { |
| 538 | switch (fate) { |
| 539 | case legacy_hal::RX_PKT_FATE_SUCCESS: |
| 540 | return WifiDebugRxPacketFate::SUCCESS; |
| 541 | case legacy_hal::RX_PKT_FATE_FW_QUEUED: |
| 542 | return WifiDebugRxPacketFate::FW_QUEUED; |
| 543 | case legacy_hal::RX_PKT_FATE_FW_DROP_FILTER: |
| 544 | return WifiDebugRxPacketFate::FW_DROP_FILTER; |
| 545 | case legacy_hal::RX_PKT_FATE_FW_DROP_INVALID: |
| 546 | return WifiDebugRxPacketFate::FW_DROP_INVALID; |
| 547 | case legacy_hal::RX_PKT_FATE_FW_DROP_NOBUFS: |
| 548 | return WifiDebugRxPacketFate::FW_DROP_NOBUFS; |
| 549 | case legacy_hal::RX_PKT_FATE_FW_DROP_OTHER: |
| 550 | return WifiDebugRxPacketFate::FW_DROP_OTHER; |
| 551 | case legacy_hal::RX_PKT_FATE_DRV_QUEUED: |
| 552 | return WifiDebugRxPacketFate::DRV_QUEUED; |
| 553 | case legacy_hal::RX_PKT_FATE_DRV_DROP_FILTER: |
| 554 | return WifiDebugRxPacketFate::DRV_DROP_FILTER; |
| 555 | case legacy_hal::RX_PKT_FATE_DRV_DROP_INVALID: |
| 556 | return WifiDebugRxPacketFate::DRV_DROP_INVALID; |
| 557 | case legacy_hal::RX_PKT_FATE_DRV_DROP_NOBUFS: |
| 558 | return WifiDebugRxPacketFate::DRV_DROP_NOBUFS; |
| 559 | case legacy_hal::RX_PKT_FATE_DRV_DROP_OTHER: |
| 560 | return WifiDebugRxPacketFate::DRV_DROP_OTHER; |
| 561 | }; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 562 | CHECK(false) << "Unknown legacy fate type: " << fate; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | WifiDebugPacketFateFrameType convertLegacyDebugPacketFateFrameTypeToHidl( |
| 566 | legacy_hal::frame_type type) { |
| 567 | switch (type) { |
| 568 | case legacy_hal::FRAME_TYPE_UNKNOWN: |
| 569 | return WifiDebugPacketFateFrameType::UNKNOWN; |
| 570 | case legacy_hal::FRAME_TYPE_ETHERNET_II: |
| 571 | return WifiDebugPacketFateFrameType::ETHERNET_II; |
| 572 | case legacy_hal::FRAME_TYPE_80211_MGMT: |
| 573 | return WifiDebugPacketFateFrameType::MGMT_80211; |
| 574 | }; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 575 | CHECK(false) << "Unknown legacy frame type: " << type; |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | bool convertLegacyDebugPacketFateFrameToHidl( |
| 579 | const legacy_hal::frame_info& legacy_frame, |
| 580 | WifiDebugPacketFateFrameInfo* hidl_frame) { |
| 581 | if (!hidl_frame) { |
| 582 | return false; |
| 583 | } |
| 584 | hidl_frame->frameType = |
| 585 | convertLegacyDebugPacketFateFrameTypeToHidl(legacy_frame.payload_type); |
| 586 | hidl_frame->frameLen = legacy_frame.frame_len; |
| 587 | hidl_frame->driverTimestampUsec = legacy_frame.driver_timestamp_usec; |
| 588 | hidl_frame->firmwareTimestampUsec = legacy_frame.firmware_timestamp_usec; |
| 589 | const uint8_t* frame_begin = reinterpret_cast<const uint8_t*>( |
| 590 | legacy_frame.frame_content.ethernet_ii_bytes); |
| 591 | hidl_frame->frameContent = |
| 592 | std::vector<uint8_t>(frame_begin, frame_begin + legacy_frame.frame_len); |
| 593 | return true; |
| 594 | } |
| 595 | |
| 596 | bool convertLegacyDebugTxPacketFateToHidl( |
| 597 | const legacy_hal::wifi_tx_report& legacy_fate, |
| 598 | WifiDebugTxPacketFateReport* hidl_fate) { |
| 599 | if (!hidl_fate) { |
| 600 | return false; |
| 601 | } |
| 602 | hidl_fate->fate = convertLegacyDebugTxPacketFateToHidl(legacy_fate.fate); |
| 603 | return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, |
| 604 | &hidl_fate->frameInfo); |
| 605 | } |
| 606 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 607 | bool convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 608 | const std::vector<legacy_hal::wifi_tx_report>& legacy_fates, |
| 609 | std::vector<WifiDebugTxPacketFateReport>* hidl_fates) { |
| 610 | if (!hidl_fates) { |
| 611 | return false; |
| 612 | } |
| 613 | hidl_fates->clear(); |
| 614 | for (const auto& legacy_fate : legacy_fates) { |
| 615 | WifiDebugTxPacketFateReport hidl_fate; |
| 616 | if (!convertLegacyDebugTxPacketFateToHidl(legacy_fate, &hidl_fate)) { |
| 617 | return false; |
| 618 | } |
| 619 | hidl_fates->push_back(hidl_fate); |
| 620 | } |
| 621 | return true; |
| 622 | } |
| 623 | |
Roshan Pius | 32d0ca9 | 2016-12-02 11:21:19 -0800 | [diff] [blame] | 624 | bool convertLegacyDebugRxPacketFateToHidl( |
| 625 | const legacy_hal::wifi_rx_report& legacy_fate, |
| 626 | WifiDebugRxPacketFateReport* hidl_fate) { |
| 627 | if (!hidl_fate) { |
| 628 | return false; |
| 629 | } |
| 630 | hidl_fate->fate = convertLegacyDebugRxPacketFateToHidl(legacy_fate.fate); |
| 631 | return convertLegacyDebugPacketFateFrameToHidl(legacy_fate.frame_inf, |
| 632 | &hidl_fate->frameInfo); |
| 633 | } |
| 634 | |
Roshan Pius | f72df2e | 2016-12-04 10:49:38 -0800 | [diff] [blame] | 635 | bool convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 636 | const std::vector<legacy_hal::wifi_rx_report>& legacy_fates, |
| 637 | std::vector<WifiDebugRxPacketFateReport>* hidl_fates) { |
| 638 | if (!hidl_fates) { |
| 639 | return false; |
| 640 | } |
| 641 | hidl_fates->clear(); |
| 642 | for (const auto& legacy_fate : legacy_fates) { |
| 643 | WifiDebugRxPacketFateReport hidl_fate; |
| 644 | if (!convertLegacyDebugRxPacketFateToHidl(legacy_fate, &hidl_fate)) { |
| 645 | return false; |
| 646 | } |
| 647 | hidl_fates->push_back(hidl_fate); |
| 648 | } |
| 649 | return true; |
| 650 | } |
| 651 | |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 652 | bool convertLegacyLinkLayerStatsToHidl( |
| 653 | const legacy_hal::LinkLayerStats& legacy_stats, |
| 654 | StaLinkLayerStats* hidl_stats) { |
| 655 | if (!hidl_stats) { |
| 656 | return false; |
| 657 | } |
| 658 | // iface legacy_stats conversion. |
| 659 | hidl_stats->iface.beaconRx = legacy_stats.iface.beacon_rx; |
| 660 | hidl_stats->iface.avgRssiMgmt = legacy_stats.iface.rssi_mgmt; |
| 661 | hidl_stats->iface.wmeBePktStats.rxMpdu = |
| 662 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; |
| 663 | hidl_stats->iface.wmeBePktStats.txMpdu = |
| 664 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; |
| 665 | hidl_stats->iface.wmeBePktStats.lostMpdu = |
| 666 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; |
| 667 | hidl_stats->iface.wmeBePktStats.retries = |
| 668 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries; |
| 669 | hidl_stats->iface.wmeBkPktStats.rxMpdu = |
| 670 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; |
| 671 | hidl_stats->iface.wmeBkPktStats.txMpdu = |
| 672 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; |
| 673 | hidl_stats->iface.wmeBkPktStats.lostMpdu = |
| 674 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; |
| 675 | hidl_stats->iface.wmeBkPktStats.retries = |
| 676 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries; |
| 677 | hidl_stats->iface.wmeViPktStats.rxMpdu = |
| 678 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; |
| 679 | hidl_stats->iface.wmeViPktStats.txMpdu = |
| 680 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; |
| 681 | hidl_stats->iface.wmeViPktStats.lostMpdu = |
| 682 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; |
| 683 | hidl_stats->iface.wmeViPktStats.retries = |
| 684 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries; |
| 685 | hidl_stats->iface.wmeVoPktStats.rxMpdu = |
| 686 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; |
| 687 | hidl_stats->iface.wmeVoPktStats.txMpdu = |
| 688 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; |
| 689 | hidl_stats->iface.wmeVoPktStats.lostMpdu = |
| 690 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; |
| 691 | hidl_stats->iface.wmeVoPktStats.retries = |
| 692 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries; |
| 693 | // radio legacy_stats conversion. |
| 694 | hidl_stats->radio.onTimeInMs = legacy_stats.radio.on_time; |
| 695 | hidl_stats->radio.txTimeInMs = legacy_stats.radio.tx_time; |
| 696 | hidl_stats->radio.rxTimeInMs = legacy_stats.radio.rx_time; |
| 697 | hidl_stats->radio.onTimeInMsForScan = legacy_stats.radio.on_time_scan; |
| 698 | hidl_stats->radio.txTimeInMsPerLevel = legacy_stats.radio_tx_time_per_levels; |
| 699 | // Timestamp in the HAL wrapper here since it's not provided in the legacy |
| 700 | // HAL API. |
| 701 | hidl_stats->timeStampInMs = uptimeMillis(); |
| 702 | return true; |
| 703 | } |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 704 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 705 | bool convertLegacyRoamingCapabilitiesToHidl( |
| 706 | const legacy_hal::wifi_roaming_capabilities& legacy_caps, |
| 707 | StaRoamingCapabilities* hidl_caps) { |
| 708 | if (!hidl_caps) { |
| 709 | return false; |
| 710 | } |
| 711 | hidl_caps->maxBlacklistSize = legacy_caps.max_blacklist_size; |
| 712 | hidl_caps->maxWhitelistSize = legacy_caps.max_whitelist_size; |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | bool convertHidlRoamingConfigToLegacy( |
| 717 | const StaRoamingConfig& hidl_config, |
| 718 | legacy_hal::wifi_roaming_config* legacy_config) { |
| 719 | if (!legacy_config) { |
| 720 | return false; |
| 721 | } |
| 722 | if (hidl_config.bssidBlacklist.size() > MAX_BLACKLIST_BSSID || |
| 723 | hidl_config.ssidWhitelist.size() > MAX_WHITELIST_SSID) { |
| 724 | return false; |
| 725 | } |
| 726 | legacy_config->num_blacklist_bssid = hidl_config.bssidBlacklist.size(); |
| 727 | uint32_t i = 0; |
| 728 | for (const auto& bssid : hidl_config.bssidBlacklist) { |
| 729 | CHECK(bssid.size() == sizeof(legacy_hal::mac_addr)); |
| 730 | memcpy(legacy_config->blacklist_bssid[i++], bssid.data(), bssid.size()); |
| 731 | } |
| 732 | legacy_config->num_whitelist_ssid = hidl_config.ssidWhitelist.size(); |
| 733 | i = 0; |
| 734 | for (const auto& ssid : hidl_config.ssidWhitelist) { |
| 735 | CHECK(ssid.size() <= sizeof(legacy_hal::ssid_t::ssid_str)); |
| 736 | legacy_config->whitelist_ssid[i].length = ssid.size(); |
| 737 | memcpy(legacy_config->whitelist_ssid[i].ssid_str, ssid.data(), ssid.size()); |
| 738 | i++; |
| 739 | } |
| 740 | return true; |
| 741 | } |
| 742 | |
| 743 | legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy( |
| 744 | StaRoamingState state) { |
| 745 | switch (state) { |
| 746 | case StaRoamingState::ENABLED: |
| 747 | return legacy_hal::ROAMING_ENABLE; |
| 748 | case StaRoamingState::DISABLED: |
| 749 | return legacy_hal::ROAMING_DISABLE; |
| 750 | }; |
| 751 | CHECK(false); |
| 752 | } |
| 753 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 754 | NanStatusType convertLegacyNanStatusTypeToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 755 | legacy_hal::NanStatusType type) { |
| 756 | // values are identical - may need to do a mapping if they diverge in the future |
| 757 | return (NanStatusType) type; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | bool convertHidlNanEnableRequestToLegacy( |
| 761 | const NanEnableRequest& hidl_request, |
| 762 | legacy_hal::NanEnableRequest* legacy_request) { |
| 763 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 764 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: null legacy_request"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 765 | return false; |
| 766 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 767 | memset(legacy_request, 0, sizeof(legacy_hal::NanEnableRequest)); |
| 768 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 769 | legacy_request->config_2dot4g_support = 1; |
| 770 | legacy_request->support_2dot4g_val = hidl_request.operateInBand[ |
| 771 | (size_t) NanBandIndex::NAN_BAND_24GHZ]; |
| 772 | legacy_request->config_support_5g = 1; |
| 773 | legacy_request->support_5g_val = hidl_request.operateInBand[(size_t) NanBandIndex::NAN_BAND_5GHZ]; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 774 | legacy_request->config_hop_count_limit = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 775 | legacy_request->hop_count_limit_val = hidl_request.hopCountMax; |
| 776 | legacy_request->master_pref = hidl_request.configParams.masterPref; |
| 777 | legacy_request->discovery_indication_cfg = 0; |
| 778 | legacy_request->discovery_indication_cfg |= |
| 779 | hidl_request.configParams.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; |
| 780 | legacy_request->discovery_indication_cfg |= |
| 781 | hidl_request.configParams.disableStartedClusterIndication ? 0x2 : 0x0; |
| 782 | legacy_request->discovery_indication_cfg |= |
| 783 | hidl_request.configParams.disableJoinedClusterIndication ? 0x4 : 0x0; |
| 784 | legacy_request->config_sid_beacon = 1; |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 785 | if (hidl_request.configParams.numberOfPublishServiceIdsInBeacon > 127) { |
| 786 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: numberOfPublishServiceIdsInBeacon > 127"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 787 | return false; |
| 788 | } |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 789 | legacy_request->sid_beacon_val = |
| 790 | (hidl_request.configParams.includePublishServiceIdsInBeacon ? 0x1 : 0x0) |
| 791 | | (hidl_request.configParams.numberOfPublishServiceIdsInBeacon << 1); |
Etan Cohen | b9b71ce | 2017-02-09 12:55:23 -0800 | [diff] [blame] | 792 | // TODO: b/35195516 connect SubscribeServiceIds to legacy HAL once implemented |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 793 | legacy_request->config_rssi_window_size = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 794 | legacy_request->rssi_window_size_val = hidl_request.configParams.rssiWindowSize; |
| 795 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 796 | legacy_request->disc_mac_addr_rand_interval_sec = |
| 797 | hidl_request.configParams.macAddressRandomizationIntervalSec; |
| 798 | legacy_request->config_responder_auto_response = 1; |
| 799 | legacy_request->ranging_auto_response_cfg = hidl_request.configParams.acceptRangingRequests ? |
| 800 | legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 801 | legacy_request->config_2dot4g_rssi_close = 1; |
| 802 | if (hidl_request.configParams.bandSpecificConfig.size() != 2) { |
| 803 | LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: bandSpecificConfig.size() != 2"; |
| 804 | return false; |
| 805 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 806 | legacy_request->rssi_close_2dot4g_val = |
| 807 | hidl_request.configParams.bandSpecificConfig[ |
| 808 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiClose; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 809 | legacy_request->config_2dot4g_rssi_middle = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 810 | legacy_request->rssi_middle_2dot4g_val = |
| 811 | hidl_request.configParams.bandSpecificConfig[ |
| 812 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiMiddle; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 813 | legacy_request->config_2dot4g_rssi_proximity = 1; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 814 | legacy_request->rssi_proximity_2dot4g_val = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 815 | hidl_request.configParams.bandSpecificConfig[ |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 816 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiCloseProximity; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 817 | legacy_request->config_scan_params = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 818 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 819 | hidl_request.configParams.bandSpecificConfig[ |
| 820 | (size_t) NanBandIndex::NAN_BAND_24GHZ].dwellTimeMs; |
| 821 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 822 | hidl_request.configParams.bandSpecificConfig[ |
| 823 | (size_t) NanBandIndex::NAN_BAND_24GHZ].scanPeriodSec; |
| 824 | legacy_request->config_dw.config_2dot4g_dw_band = hidl_request.configParams |
| 825 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_24GHZ].validDiscoveryWindowIntervalVal; |
| 826 | legacy_request->config_dw.dw_2dot4g_interval_val = hidl_request.configParams |
| 827 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_24GHZ].discoveryWindowIntervalVal; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 828 | legacy_request->config_5g_rssi_close = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 829 | legacy_request->rssi_close_5g_val = |
| 830 | hidl_request.configParams.bandSpecificConfig[ |
| 831 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiClose; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 832 | legacy_request->config_5g_rssi_middle = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 833 | legacy_request->rssi_middle_5g_val = |
| 834 | hidl_request.configParams.bandSpecificConfig[ |
| 835 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiMiddle; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 836 | legacy_request->config_5g_rssi_close_proximity = 1; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 837 | legacy_request->rssi_close_proximity_5g_val = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 838 | hidl_request.configParams.bandSpecificConfig[ |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 839 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiCloseProximity; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 840 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 841 | hidl_request.configParams.bandSpecificConfig[ |
| 842 | (size_t) NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 843 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 844 | hidl_request.configParams.bandSpecificConfig[ |
| 845 | (size_t) NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 846 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 847 | hidl_request.configParams.bandSpecificConfig[ |
| 848 | (size_t) NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 849 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 850 | hidl_request.configParams.bandSpecificConfig[ |
| 851 | (size_t) NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 852 | legacy_request->config_dw.config_5g_dw_band = hidl_request.configParams |
| 853 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_5GHZ].validDiscoveryWindowIntervalVal; |
| 854 | legacy_request->config_dw.dw_5g_interval_val = hidl_request.configParams |
| 855 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_5GHZ].discoveryWindowIntervalVal; |
| 856 | if (hidl_request.debugConfigs.validClusterIdVals) { |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 857 | legacy_request->cluster_low = hidl_request.debugConfigs.clusterIdBottomRangeVal; |
| 858 | legacy_request->cluster_high = hidl_request.debugConfigs.clusterIdTopRangeVal; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 859 | } else { // need 'else' since not configurable in legacy HAL |
| 860 | legacy_request->cluster_low = 0x0000; |
| 861 | legacy_request->cluster_high = 0xFFFF; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 862 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 863 | legacy_request->config_intf_addr = hidl_request.debugConfigs.validIntfAddrVal; |
| 864 | memcpy(legacy_request->intf_addr_val, hidl_request.debugConfigs.intfAddrVal.data(), 6); |
| 865 | legacy_request->config_oui = hidl_request.debugConfigs.validOuiVal; |
| 866 | legacy_request->oui_val = hidl_request.debugConfigs.ouiVal; |
| 867 | legacy_request->config_random_factor_force = hidl_request.debugConfigs.validRandomFactorForceVal; |
| 868 | legacy_request->random_factor_force_val = hidl_request.debugConfigs.randomFactorForceVal; |
| 869 | legacy_request->config_hop_count_force = hidl_request.debugConfigs.validHopCountForceVal; |
| 870 | legacy_request->hop_count_force_val = hidl_request.debugConfigs.hopCountForceVal; |
| 871 | legacy_request->config_24g_channel = hidl_request.debugConfigs.validDiscoveryChannelVal; |
| 872 | legacy_request->channel_24g_val = |
| 873 | hidl_request.debugConfigs.discoveryChannelMhzVal[(size_t) NanBandIndex::NAN_BAND_24GHZ]; |
| 874 | legacy_request->config_5g_channel = hidl_request.debugConfigs.validDiscoveryChannelVal; |
| 875 | legacy_request->channel_5g_val = hidl_request.debugConfigs |
| 876 | .discoveryChannelMhzVal[(size_t) NanBandIndex::NAN_BAND_5GHZ]; |
| 877 | legacy_request->config_2dot4g_beacons = hidl_request.debugConfigs.validUseBeaconsInBandVal; |
| 878 | legacy_request->beacon_2dot4g_val = hidl_request.debugConfigs |
| 879 | .useBeaconsInBandVal[(size_t) NanBandIndex::NAN_BAND_24GHZ]; |
| 880 | legacy_request->config_5g_beacons = hidl_request.debugConfigs.validUseBeaconsInBandVal; |
| 881 | legacy_request->beacon_5g_val = hidl_request.debugConfigs |
| 882 | .useBeaconsInBandVal[(size_t) NanBandIndex::NAN_BAND_5GHZ]; |
| 883 | legacy_request->config_2dot4g_sdf = hidl_request.debugConfigs.validUseSdfInBandVal; |
| 884 | legacy_request->sdf_2dot4g_val = hidl_request.debugConfigs |
| 885 | .useSdfInBandVal[(size_t) NanBandIndex::NAN_BAND_24GHZ]; |
| 886 | legacy_request->config_5g_sdf = hidl_request.debugConfigs.validUseSdfInBandVal; |
| 887 | legacy_request->sdf_5g_val = hidl_request.debugConfigs |
| 888 | .useSdfInBandVal[(size_t) NanBandIndex::NAN_BAND_5GHZ]; |
| 889 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 890 | return true; |
| 891 | } |
| 892 | |
| 893 | bool convertHidlNanPublishRequestToLegacy( |
| 894 | const NanPublishRequest& hidl_request, |
| 895 | legacy_hal::NanPublishRequest* legacy_request) { |
| 896 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 897 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: null legacy_request"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 898 | return false; |
| 899 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 900 | memset(legacy_request, 0, sizeof(legacy_hal::NanPublishRequest)); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 901 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 902 | legacy_request->publish_id = hidl_request.baseConfigs.sessionId; |
| 903 | legacy_request->ttl = hidl_request.baseConfigs.ttlSec; |
| 904 | legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; |
| 905 | legacy_request->publish_count = hidl_request.baseConfigs.discoveryCount; |
| 906 | legacy_request->service_name_len = hidl_request.baseConfigs.serviceName.size(); |
| 907 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 908 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: service_name_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 909 | return false; |
| 910 | } |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 911 | memcpy(legacy_request->service_name, hidl_request.baseConfigs.serviceName.data(), |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 912 | legacy_request->service_name_len); |
| 913 | legacy_request->publish_match_indicator = |
| 914 | (legacy_hal::NanMatchAlg) hidl_request.baseConfigs.discoveryMatchIndicator; |
| 915 | legacy_request->service_specific_info_len = hidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 916 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 917 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: service_specific_info_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 918 | return false; |
| 919 | } |
| 920 | memcpy(legacy_request->service_specific_info, |
| 921 | hidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 922 | legacy_request->service_specific_info_len); |
Etan Cohen | 2373fe2 | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 923 | // TODO: b/35193423 add support for extended service specific info |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 924 | legacy_request->rx_match_filter_len = hidl_request.baseConfigs.rxMatchFilter.size(); |
| 925 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 926 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: rx_match_filter_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 927 | return false; |
| 928 | } |
| 929 | memcpy(legacy_request->rx_match_filter, |
| 930 | hidl_request.baseConfigs.rxMatchFilter.data(), |
| 931 | legacy_request->rx_match_filter_len); |
| 932 | legacy_request->tx_match_filter_len = hidl_request.baseConfigs.txMatchFilter.size(); |
| 933 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 934 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: tx_match_filter_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 935 | return false; |
| 936 | } |
| 937 | memcpy(legacy_request->tx_match_filter, |
| 938 | hidl_request.baseConfigs.txMatchFilter.data(), |
| 939 | legacy_request->tx_match_filter_len); |
| 940 | legacy_request->rssi_threshold_flag = hidl_request.baseConfigs.useRssiThreshold; |
| 941 | legacy_request->recv_indication_cfg = 0; |
| 942 | legacy_request->recv_indication_cfg |= |
| 943 | hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; |
| 944 | legacy_request->recv_indication_cfg |= |
| 945 | hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
| 946 | legacy_request->recv_indication_cfg |= |
| 947 | hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
| 948 | legacy_request->cipher_type = hidl_request.baseConfigs.supportedCipherTypes; |
| 949 | legacy_request->pmk_len = hidl_request.baseConfigs.pmk.size(); |
| 950 | if (legacy_request->pmk_len > NAN_PMK_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 951 | LOG(ERROR) << "convertHidlNanPublishRequestToLegacy: pmk_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 952 | return false; |
| 953 | } |
| 954 | memcpy(legacy_request->pmk, |
| 955 | hidl_request.baseConfigs.pmk.data(), |
| 956 | legacy_request->pmk_len); |
| 957 | legacy_request->sdea_params.security_cfg = hidl_request.baseConfigs.securityEnabledInNdp ? |
| 958 | legacy_hal::NAN_DP_CONFIG_SECURITY : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 959 | legacy_request->sdea_params.ranging_state = hidl_request.baseConfigs.rangingRequired ? |
| 960 | legacy_hal::NAN_RANGING_ENABLE : legacy_hal::NAN_RANGING_DISABLE; |
| 961 | legacy_request->ranging_cfg.ranging_interval_msec = hidl_request.baseConfigs.rangingIntervalMsec; |
| 962 | legacy_request->ranging_cfg.config_ranging_indications = |
| 963 | hidl_request.baseConfigs.configRangingIndications; |
| 964 | legacy_request->ranging_cfg.distance_ingress_cm = hidl_request.baseConfigs.distanceIngressCm; |
| 965 | legacy_request->ranging_cfg.distance_egress_cm = hidl_request.baseConfigs.distanceEgressCm; |
| 966 | legacy_request->publish_type = (legacy_hal::NanPublishType) hidl_request.publishType; |
| 967 | legacy_request->tx_type = (legacy_hal::NanTxType) hidl_request.txType; |
| 968 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 969 | return true; |
| 970 | } |
| 971 | |
| 972 | bool convertHidlNanSubscribeRequestToLegacy( |
| 973 | const NanSubscribeRequest& hidl_request, |
| 974 | legacy_hal::NanSubscribeRequest* legacy_request) { |
| 975 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 976 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: legacy_request is null"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 977 | return false; |
| 978 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 979 | memset(legacy_request, 0, sizeof(legacy_hal::NanSubscribeRequest)); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 980 | |
| 981 | legacy_request->subscribe_id = hidl_request.baseConfigs.sessionId; |
| 982 | legacy_request->ttl = hidl_request.baseConfigs.ttlSec; |
| 983 | legacy_request->period = hidl_request.baseConfigs.discoveryWindowPeriod; |
| 984 | legacy_request->subscribe_count = hidl_request.baseConfigs.discoveryCount; |
| 985 | legacy_request->service_name_len = hidl_request.baseConfigs.serviceName.size(); |
| 986 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 987 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: service_name_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 988 | return false; |
| 989 | } |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 990 | memcpy(legacy_request->service_name, hidl_request.baseConfigs.serviceName.data(), |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 991 | legacy_request->service_name_len); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 992 | legacy_request->subscribe_match_indicator = |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 993 | (legacy_hal::NanMatchAlg) hidl_request.baseConfigs.discoveryMatchIndicator; |
| 994 | legacy_request->service_specific_info_len = hidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 995 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 996 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: service_specific_info_len too large"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 997 | return false; |
| 998 | } |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 999 | memcpy(legacy_request->service_specific_info, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1000 | hidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 1001 | legacy_request->service_specific_info_len); |
Etan Cohen | 2373fe2 | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1002 | // TODO: b/35193423 add support for extended service specific info |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1003 | legacy_request->rx_match_filter_len = hidl_request.baseConfigs.rxMatchFilter.size(); |
| 1004 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1005 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: rx_match_filter_len too large"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1006 | return false; |
| 1007 | } |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1008 | memcpy(legacy_request->rx_match_filter, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1009 | hidl_request.baseConfigs.rxMatchFilter.data(), |
| 1010 | legacy_request->rx_match_filter_len); |
| 1011 | legacy_request->tx_match_filter_len = hidl_request.baseConfigs.txMatchFilter.size(); |
| 1012 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1013 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: tx_match_filter_len too large"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1014 | return false; |
| 1015 | } |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1016 | memcpy(legacy_request->tx_match_filter, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1017 | hidl_request.baseConfigs.txMatchFilter.data(), |
| 1018 | legacy_request->tx_match_filter_len); |
| 1019 | legacy_request->rssi_threshold_flag = hidl_request.baseConfigs.useRssiThreshold; |
| 1020 | legacy_request->recv_indication_cfg = 0; |
| 1021 | legacy_request->recv_indication_cfg |= |
| 1022 | hidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; |
| 1023 | legacy_request->recv_indication_cfg |= |
| 1024 | hidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
| 1025 | legacy_request->recv_indication_cfg |= |
| 1026 | hidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
| 1027 | legacy_request->cipher_type = hidl_request.baseConfigs.supportedCipherTypes; |
| 1028 | legacy_request->pmk_len = hidl_request.baseConfigs.pmk.size(); |
| 1029 | if (legacy_request->pmk_len > NAN_PMK_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1030 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: pmk_len too large"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1031 | return false; |
| 1032 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1033 | memcpy(legacy_request->pmk, |
| 1034 | hidl_request.baseConfigs.pmk.data(), |
| 1035 | legacy_request->pmk_len); |
| 1036 | legacy_request->sdea_params.security_cfg = hidl_request.baseConfigs.securityEnabledInNdp ? |
| 1037 | legacy_hal::NAN_DP_CONFIG_SECURITY : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1038 | legacy_request->sdea_params.ranging_state = hidl_request.baseConfigs.rangingRequired ? |
| 1039 | legacy_hal::NAN_RANGING_ENABLE : legacy_hal::NAN_RANGING_DISABLE; |
| 1040 | legacy_request->ranging_cfg.ranging_interval_msec = hidl_request.baseConfigs.rangingIntervalMsec; |
| 1041 | legacy_request->ranging_cfg.config_ranging_indications = |
| 1042 | hidl_request.baseConfigs.configRangingIndications; |
| 1043 | legacy_request->ranging_cfg.distance_ingress_cm = hidl_request.baseConfigs.distanceIngressCm; |
| 1044 | legacy_request->ranging_cfg.distance_egress_cm = hidl_request.baseConfigs.distanceEgressCm; |
| 1045 | legacy_request->subscribe_type = (legacy_hal::NanSubscribeType) hidl_request.subscribeType; |
| 1046 | legacy_request->serviceResponseFilter = (legacy_hal::NanSRFType) hidl_request.srfType; |
| 1047 | legacy_request->serviceResponseInclude = hidl_request.srfRespondIfInAddressSet ? |
| 1048 | legacy_hal::NAN_SRF_INCLUDE_RESPOND : legacy_hal::NAN_SRF_INCLUDE_DO_NOT_RESPOND; |
| 1049 | legacy_request->useServiceResponseFilter = hidl_request.shouldUseSrf ? |
| 1050 | legacy_hal::NAN_USE_SRF : legacy_hal::NAN_DO_NOT_USE_SRF; |
| 1051 | legacy_request->ssiRequiredForMatchIndication = hidl_request.isSsiRequiredForMatch ? |
| 1052 | legacy_hal::NAN_SSI_REQUIRED_IN_MATCH_IND : legacy_hal::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1053 | legacy_request->num_intf_addr_present = hidl_request.intfAddr.size(); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1054 | if (legacy_request->num_intf_addr_present > NAN_MAX_SUBSCRIBE_MAX_ADDRESS) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1055 | LOG(ERROR) << "convertHidlNanSubscribeRequestToLegacy: num_intf_addr_present - too many"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1056 | return false; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1057 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1058 | for (int i = 0; i < legacy_request->num_intf_addr_present; i++) { |
| 1059 | memcpy(legacy_request->intf_addr[i], hidl_request.intfAddr[i].data(), 6); |
| 1060 | } |
| 1061 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1062 | return true; |
| 1063 | } |
| 1064 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1065 | bool convertHidlNanTransmitFollowupRequestToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1066 | const NanTransmitFollowupRequest& hidl_request, |
| 1067 | legacy_hal::NanTransmitFollowupRequest* legacy_request) { |
| 1068 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1069 | LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: legacy_request is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1070 | return false; |
| 1071 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 1072 | memset(legacy_request, 0, sizeof(legacy_hal::NanTransmitFollowupRequest)); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1073 | |
| 1074 | legacy_request->publish_subscribe_id = hidl_request.discoverySessionId; |
| 1075 | legacy_request->requestor_instance_id = hidl_request.peerId; |
| 1076 | memcpy(legacy_request->addr, hidl_request.addr.data(), 6); |
| 1077 | legacy_request->priority = hidl_request.isHighPriority ? |
| 1078 | legacy_hal::NAN_TX_PRIORITY_HIGH : legacy_hal::NAN_TX_PRIORITY_NORMAL; |
| 1079 | legacy_request->dw_or_faw = hidl_request.shouldUseDiscoveryWindow ? |
| 1080 | legacy_hal::NAN_TRANSMIT_IN_DW : legacy_hal::NAN_TRANSMIT_IN_FAW; |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1081 | legacy_request->service_specific_info_len = hidl_request.serviceSpecificInfo.size(); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1082 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1083 | LOG(ERROR) << "convertHidlNanTransmitFollowupRequestToLegacy: service_specific_info_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1084 | return false; |
| 1085 | } |
| 1086 | memcpy(legacy_request->service_specific_info, |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1087 | hidl_request.serviceSpecificInfo.data(), |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1088 | legacy_request->service_specific_info_len); |
Etan Cohen | 2373fe2 | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1089 | // TODO: b/35193423 add support for extended service specific info |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1090 | legacy_request->recv_indication_cfg = hidl_request.disableFollowupResultIndication ? 0x1 : 0x0; |
| 1091 | |
| 1092 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | bool convertHidlNanConfigRequestToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1096 | const NanConfigRequest& hidl_request, |
| 1097 | legacy_hal::NanConfigRequest* legacy_request) { |
| 1098 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1099 | LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: legacy_request is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1100 | return false; |
| 1101 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 1102 | memset(legacy_request, 0, sizeof(legacy_hal::NanConfigRequest)); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1103 | |
| 1104 | // TODO: b/34059183 tracks missing configurations in legacy HAL or uknown defaults |
| 1105 | legacy_request->master_pref = hidl_request.masterPref; |
| 1106 | legacy_request->discovery_indication_cfg = 0; |
| 1107 | legacy_request->discovery_indication_cfg |= |
| 1108 | hidl_request.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; |
| 1109 | legacy_request->discovery_indication_cfg |= |
| 1110 | hidl_request.disableStartedClusterIndication ? 0x2 : 0x0; |
| 1111 | legacy_request->discovery_indication_cfg |= |
| 1112 | hidl_request.disableJoinedClusterIndication ? 0x4 : 0x0; |
| 1113 | legacy_request->config_sid_beacon = 1; |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1114 | if (hidl_request.numberOfPublishServiceIdsInBeacon > 127) { |
| 1115 | LOG(ERROR) << "convertHidlNanConfigRequestToLegacy: numberOfPublishServiceIdsInBeacon > 127"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1116 | return false; |
| 1117 | } |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1118 | legacy_request->sid_beacon = (hidl_request.includePublishServiceIdsInBeacon ? 0x1 : 0x0) |
| 1119 | | (hidl_request.numberOfPublishServiceIdsInBeacon << 1); |
Etan Cohen | b9b71ce | 2017-02-09 12:55:23 -0800 | [diff] [blame] | 1120 | // TODO: b/35195516 connect SubscribeServiceIds to legacy HAL once implemented |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1121 | legacy_request->config_rssi_window_size = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1122 | legacy_request->rssi_window_size_val = hidl_request.rssiWindowSize; |
| 1123 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 1124 | legacy_request->disc_mac_addr_rand_interval_sec = |
| 1125 | hidl_request.macAddressRandomizationIntervalSec; |
| 1126 | legacy_request->config_responder_auto_response = 1; |
| 1127 | legacy_request->ranging_auto_response_cfg = hidl_request.acceptRangingRequests ? |
| 1128 | legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
| 1129 | /* TODO : missing |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1130 | legacy_request->config_2dot4g_rssi_close = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1131 | legacy_request->rssi_close_2dot4g_val = |
| 1132 | hidl_request.bandSpecificConfig[ |
| 1133 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiClose; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1134 | legacy_request->config_2dot4g_rssi_middle = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1135 | legacy_request->rssi_middle_2dot4g_val = |
| 1136 | hidl_request.bandSpecificConfig[ |
| 1137 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiMiddle; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1138 | legacy_request->config_2dot4g_rssi_proximity = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1139 | legacy_request->rssi_proximity_2dot4g_val = |
| 1140 | hidl_request.bandSpecificConfig[ |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1141 | (size_t) NanBandIndex::NAN_BAND_24GHZ].rssiCloseProximity; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1142 | */ |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1143 | legacy_request->config_scan_params = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1144 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1145 | hidl_request.bandSpecificConfig[ |
| 1146 | (size_t) NanBandIndex::NAN_BAND_24GHZ].dwellTimeMs; |
| 1147 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1148 | hidl_request.bandSpecificConfig[ |
| 1149 | (size_t) NanBandIndex::NAN_BAND_24GHZ].scanPeriodSec; |
| 1150 | legacy_request->config_dw.config_2dot4g_dw_band = hidl_request |
| 1151 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_24GHZ].validDiscoveryWindowIntervalVal; |
| 1152 | legacy_request->config_dw.dw_2dot4g_interval_val = hidl_request |
| 1153 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_24GHZ].discoveryWindowIntervalVal; |
| 1154 | /* TODO: missing |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1155 | legacy_request->config_5g_rssi_close = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1156 | legacy_request->rssi_close_5g_val = |
| 1157 | hidl_request.bandSpecificConfig[ |
| 1158 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiClose; |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1159 | legacy_request->config_5g_rssi_middle = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1160 | legacy_request->rssi_middle_5g_val = |
| 1161 | hidl_request.bandSpecificConfig[ |
| 1162 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiMiddle; |
| 1163 | */ |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1164 | legacy_request->config_5g_rssi_close_proximity = 1; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1165 | legacy_request->rssi_close_proximity_5g_val = |
| 1166 | hidl_request.bandSpecificConfig[ |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1167 | (size_t) NanBandIndex::NAN_BAND_5GHZ].rssiCloseProximity; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1168 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1169 | hidl_request.bandSpecificConfig[ |
| 1170 | (size_t) NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 1171 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1172 | hidl_request.bandSpecificConfig[ |
| 1173 | (size_t) NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 1174 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1175 | hidl_request.bandSpecificConfig[ |
| 1176 | (size_t) NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 1177 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1178 | hidl_request.bandSpecificConfig[ |
| 1179 | (size_t) NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 1180 | legacy_request->config_dw.config_5g_dw_band = hidl_request |
| 1181 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_5GHZ].validDiscoveryWindowIntervalVal; |
| 1182 | legacy_request->config_dw.dw_5g_interval_val = hidl_request |
| 1183 | .bandSpecificConfig[(size_t) NanBandIndex::NAN_BAND_5GHZ].discoveryWindowIntervalVal; |
| 1184 | |
| 1185 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1188 | bool convertHidlNanDataPathInitiatorRequestToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1189 | const NanInitiateDataPathRequest& hidl_request, |
| 1190 | legacy_hal::NanDataPathInitiatorRequest* legacy_request) { |
| 1191 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1192 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: legacy_request is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1193 | return false; |
| 1194 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 1195 | memset(legacy_request, 0, sizeof(legacy_hal::NanDataPathInitiatorRequest)); |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1196 | |
| 1197 | legacy_request->requestor_instance_id = hidl_request.peerId; |
| 1198 | memcpy(legacy_request->peer_disc_mac_addr, hidl_request.peerDiscMacAddr.data(), 6); |
| 1199 | legacy_request->channel_request_type = |
| 1200 | (legacy_hal::NanDataPathChannelCfg) hidl_request.channelRequestType; |
| 1201 | legacy_request->channel = hidl_request.channel; |
| 1202 | strcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str()); |
| 1203 | legacy_request->ndp_cfg.security_cfg = hidl_request.securityRequired ? |
| 1204 | legacy_hal::NAN_DP_CONFIG_SECURITY : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1205 | legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); |
| 1206 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1207 | LOG(ERROR) << "convertHidlNanDataPathInitiatorRequestToLegacy: ndp_app_info_len to large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1208 | return false; |
| 1209 | } |
| 1210 | memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), |
| 1211 | legacy_request->app_info.ndp_app_info_len); |
| 1212 | legacy_request->cipher_type = hidl_request.supportedCipherTypes; |
| 1213 | legacy_request->pmk_len = hidl_request.pmk.size(); |
| 1214 | if (legacy_request->pmk_len > NAN_PMK_INFO_LEN) { |
| 1215 | return false; |
| 1216 | } |
| 1217 | memcpy(legacy_request->pmk, hidl_request.pmk.data(), legacy_request->pmk_len); |
| 1218 | |
| 1219 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | bool convertHidlNanDataPathIndicationResponseToLegacy( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1223 | const NanRespondToDataPathIndicationRequest& hidl_request, |
| 1224 | legacy_hal::NanDataPathIndicationResponse* legacy_request) { |
| 1225 | if (!legacy_request) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1226 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: legacy_request is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1227 | return false; |
| 1228 | } |
George Burgess IV | ccd12b1 | 2017-01-19 13:16:36 -0800 | [diff] [blame] | 1229 | memset(legacy_request, 0, sizeof(legacy_hal::NanDataPathIndicationResponse)); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1230 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1231 | legacy_request->rsp_code = hidl_request.acceptRequest ? |
| 1232 | legacy_hal::NAN_DP_REQUEST_ACCEPT : legacy_hal::NAN_DP_REQUEST_REJECT; |
| 1233 | legacy_request->ndp_instance_id = hidl_request.ndpInstanceId; |
| 1234 | strcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str()); |
| 1235 | legacy_request->ndp_cfg.security_cfg = hidl_request.securityRequired ? |
| 1236 | legacy_hal::NAN_DP_CONFIG_SECURITY : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1237 | legacy_request->app_info.ndp_app_info_len = hidl_request.appInfo.size(); |
| 1238 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1239 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: ndp_app_info_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1240 | return false; |
| 1241 | } |
| 1242 | memcpy(legacy_request->app_info.ndp_app_info, hidl_request.appInfo.data(), |
| 1243 | legacy_request->app_info.ndp_app_info_len); |
| 1244 | legacy_request->cipher_type = hidl_request.supportedCipherTypes; |
| 1245 | legacy_request->pmk_len = hidl_request.pmk.size(); |
| 1246 | if (legacy_request->pmk_len > NAN_PMK_INFO_LEN) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1247 | LOG(ERROR) << "convertHidlNanDataPathIndicationResponseToLegacy: pmk_len too large"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1248 | return false; |
| 1249 | } |
| 1250 | memcpy(legacy_request->pmk, hidl_request.pmk.data(), legacy_request->pmk_len); |
| 1251 | |
| 1252 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | bool convertLegacyNanResponseHeaderToHidl( |
| 1256 | const legacy_hal::NanResponseMsg& legacy_response, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1257 | WifiNanStatus* wifiNanStatus) { |
| 1258 | if (!wifiNanStatus) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1259 | LOG(ERROR) << "convertLegacyNanResponseHeaderToHidl: wifiNanStatus is null"; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1260 | return false; |
| 1261 | } |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1262 | wifiNanStatus->status = convertLegacyNanStatusTypeToHidl(legacy_response.status); |
| 1263 | wifiNanStatus->description = legacy_response.nan_error; |
| 1264 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1265 | return true; |
| 1266 | } |
| 1267 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1268 | bool convertLegacyNanCapabilitiesResponseToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1269 | const legacy_hal::NanCapabilities& legacy_response, |
| 1270 | NanCapabilities* hidl_response) { |
| 1271 | if (!hidl_response) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1272 | LOG(ERROR) << "convertLegacyNanCapabilitiesResponseToHidl: hidl_response is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1273 | return false; |
| 1274 | } |
| 1275 | hidl_response->maxConcurrentClusters = legacy_response.max_concurrent_nan_clusters; |
| 1276 | hidl_response->maxPublishes = legacy_response.max_publishes; |
| 1277 | hidl_response->maxSubscribes = legacy_response.max_subscribes; |
| 1278 | hidl_response->maxServiceNameLen = legacy_response.max_service_name_len; |
| 1279 | hidl_response->maxMatchFilterLen = legacy_response.max_match_filter_len; |
| 1280 | hidl_response->maxTotalMatchFilterLen = legacy_response.max_total_match_filter_len; |
| 1281 | hidl_response->maxServiceSpecificInfoLen = legacy_response.max_service_specific_info_len; |
Etan Cohen | 2373fe2 | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1282 | // TODO: b/35193423 add support for extended service specific info |
Etan Cohen | 4daf983 | 2017-02-09 17:52:34 -0800 | [diff] [blame] | 1283 | hidl_response->maxExtendedServiceSpecificInfoLen = 0; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1284 | hidl_response->maxNdiInterfaces = legacy_response.max_ndi_interfaces; |
| 1285 | hidl_response->maxNdpSessions = legacy_response.max_ndp_sessions; |
| 1286 | hidl_response->maxAppInfoLen = legacy_response.max_app_info_len; |
| 1287 | hidl_response->maxQueuedTransmitFollowupMsgs = legacy_response.max_queued_transmit_followup_msgs; |
| 1288 | // TODO: b/34059183 to add to underlying HAL |
| 1289 | hidl_response->maxSubscribeInterfaceAddresses = NAN_MAX_SUBSCRIBE_MAX_ADDRESS; |
| 1290 | hidl_response->supportedCipherSuites = legacy_response.cipher_suites_supported; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1291 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1292 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | bool convertLegacyNanMatchIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1296 | const legacy_hal::NanMatchInd& legacy_ind, |
| 1297 | NanMatchInd* hidl_ind) { |
| 1298 | if (!hidl_ind) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1299 | LOG(ERROR) << "convertLegacyNanMatchIndToHidl: hidl_ind is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1300 | return false; |
| 1301 | } |
| 1302 | hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 1303 | hidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 1304 | hidl_ind->addr = hidl_array<uint8_t, 6>(legacy_ind.addr); |
| 1305 | hidl_ind->serviceSpecificInfo = std::vector<uint8_t>(legacy_ind.service_specific_info, |
| 1306 | legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); |
Etan Cohen | 2373fe2 | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1307 | // TODO: b/35193423 add support for extended service specific info |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1308 | hidl_ind->matchFilter = std::vector<uint8_t>(legacy_ind.sdf_match_filter, |
| 1309 | legacy_ind.sdf_match_filter + legacy_ind.sdf_match_filter_len); |
| 1310 | hidl_ind->matchOccuredInBeaconFlag = legacy_ind.match_occured_flag == 1; |
| 1311 | hidl_ind->outOfResourceFlag = legacy_ind.out_of_resource_flag == 1; |
| 1312 | hidl_ind->rssiValue = legacy_ind.rssi_value; |
| 1313 | hidl_ind->peerSupportedCipherTypes = legacy_ind.peer_cipher_type; |
| 1314 | hidl_ind->peerRequiresSecurityEnabledInNdp = |
| 1315 | legacy_ind.peer_sdea_params.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; |
| 1316 | hidl_ind->peerRequiresRanging = |
| 1317 | legacy_ind.peer_sdea_params.ranging_state == legacy_hal::NAN_RANGING_ENABLE; |
| 1318 | hidl_ind->rangingMeasurementInCm = legacy_ind.range_result.range_measurement_cm; |
| 1319 | hidl_ind->rangingIndicationType = legacy_ind.range_result.ranging_event_type; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1320 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1321 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | bool convertLegacyNanFollowupIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1325 | const legacy_hal::NanFollowupInd& legacy_ind, |
| 1326 | NanFollowupReceivedInd* hidl_ind) { |
| 1327 | if (!hidl_ind) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1328 | LOG(ERROR) << "convertLegacyNanFollowupIndToHidl: hidl_ind is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1329 | return false; |
| 1330 | } |
| 1331 | hidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 1332 | hidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 1333 | hidl_ind->addr = hidl_array<uint8_t, 6>(legacy_ind.addr); |
| 1334 | hidl_ind->receivedInFaw = legacy_ind.dw_or_faw == 1; |
Etan Cohen | 44983ae | 2017-02-09 09:16:25 -0800 | [diff] [blame] | 1335 | hidl_ind->serviceSpecificInfo = std::vector<uint8_t>(legacy_ind.service_specific_info, |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1336 | legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1337 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1338 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1341 | bool convertLegacyNanDataPathRequestIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1342 | const legacy_hal::NanDataPathRequestInd& legacy_ind, |
| 1343 | NanDataPathRequestInd* hidl_ind) { |
| 1344 | if (!hidl_ind) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1345 | LOG(ERROR) << "convertLegacyNanDataPathRequestIndToHidl: hidl_ind is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1346 | return false; |
| 1347 | } |
| 1348 | hidl_ind->discoverySessionId = legacy_ind.service_instance_id; |
| 1349 | hidl_ind->peerDiscMacAddr = hidl_array<uint8_t, 6>(legacy_ind.peer_disc_mac_addr); |
| 1350 | hidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; |
| 1351 | hidl_ind->securityRequired = |
| 1352 | legacy_ind.ndp_cfg.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; |
| 1353 | hidl_ind->appInfo = std::vector<uint8_t>(legacy_ind.app_info.ndp_app_info, |
| 1354 | legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); |
| 1355 | |
| 1356 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | bool convertLegacyNanDataPathConfirmIndToHidl( |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1360 | const legacy_hal::NanDataPathConfirmInd& legacy_ind, |
| 1361 | NanDataPathConfirmInd* hidl_ind) { |
| 1362 | if (!hidl_ind) { |
Etan Cohen | 4bbc209 | 2017-01-30 13:28:37 -0800 | [diff] [blame] | 1363 | LOG(ERROR) << "convertLegacyNanDataPathConfirmIndToHidl: hidl_ind is null"; |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1364 | return false; |
| 1365 | } |
| 1366 | hidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; |
| 1367 | hidl_ind->dataPathSetupSuccess = legacy_ind.rsp_code == legacy_hal::NAN_DP_REQUEST_ACCEPT; |
| 1368 | hidl_ind->peerNdiMacAddr = hidl_array<uint8_t, 6>(legacy_ind.peer_ndi_mac_addr); |
| 1369 | hidl_ind->appInfo = std::vector<uint8_t>(legacy_ind.app_info.ndp_app_info, |
| 1370 | legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); |
| 1371 | hidl_ind->status.status = convertLegacyNanStatusTypeToHidl(legacy_ind.reason_code); |
| 1372 | hidl_ind->status.description = ""; // TODO: b/34059183 |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1373 | |
Etan Cohen | f01bcaa | 2016-12-25 09:42:21 -0800 | [diff] [blame] | 1374 | return true; |
Roshan Pius | f5f51fd | 2016-12-01 13:54:24 -0800 | [diff] [blame] | 1375 | } |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 1376 | |
| 1377 | legacy_hal::wifi_rtt_type convertHidlRttTypeToLegacy(RttType type) { |
| 1378 | switch (type) { |
| 1379 | case RttType::ONE_SIDED: |
| 1380 | return legacy_hal::RTT_TYPE_1_SIDED; |
| 1381 | case RttType::TWO_SIDED: |
| 1382 | return legacy_hal::RTT_TYPE_2_SIDED; |
| 1383 | }; |
| 1384 | CHECK(false); |
| 1385 | } |
| 1386 | |
| 1387 | RttType convertLegacyRttTypeToHidl(legacy_hal::wifi_rtt_type type) { |
| 1388 | switch (type) { |
| 1389 | case legacy_hal::RTT_TYPE_1_SIDED: |
| 1390 | return RttType::ONE_SIDED; |
| 1391 | case legacy_hal::RTT_TYPE_2_SIDED: |
| 1392 | return RttType::TWO_SIDED; |
| 1393 | }; |
| 1394 | CHECK(false) << "Unknown legacy type: " << type; |
| 1395 | } |
| 1396 | |
| 1397 | legacy_hal::rtt_peer_type convertHidlRttPeerTypeToLegacy(RttPeerType type) { |
| 1398 | switch (type) { |
| 1399 | case RttPeerType::AP: |
| 1400 | return legacy_hal::RTT_PEER_AP; |
| 1401 | case RttPeerType::STA: |
| 1402 | return legacy_hal::RTT_PEER_STA; |
| 1403 | case RttPeerType::P2P_GO: |
| 1404 | return legacy_hal::RTT_PEER_P2P_GO; |
| 1405 | case RttPeerType::P2P_CLIENT: |
| 1406 | return legacy_hal::RTT_PEER_P2P_CLIENT; |
| 1407 | case RttPeerType::NAN: |
| 1408 | return legacy_hal::RTT_PEER_NAN; |
| 1409 | }; |
| 1410 | CHECK(false); |
| 1411 | } |
| 1412 | |
| 1413 | legacy_hal::wifi_channel_width convertHidlWifiChannelWidthToLegacy( |
| 1414 | WifiChannelWidthInMhz type) { |
| 1415 | switch (type) { |
| 1416 | case WifiChannelWidthInMhz::WIDTH_20: |
| 1417 | return legacy_hal::WIFI_CHAN_WIDTH_20; |
| 1418 | case WifiChannelWidthInMhz::WIDTH_40: |
| 1419 | return legacy_hal::WIFI_CHAN_WIDTH_40; |
| 1420 | case WifiChannelWidthInMhz::WIDTH_80: |
| 1421 | return legacy_hal::WIFI_CHAN_WIDTH_80; |
| 1422 | case WifiChannelWidthInMhz::WIDTH_160: |
| 1423 | return legacy_hal::WIFI_CHAN_WIDTH_160; |
| 1424 | case WifiChannelWidthInMhz::WIDTH_80P80: |
| 1425 | return legacy_hal::WIFI_CHAN_WIDTH_80P80; |
| 1426 | case WifiChannelWidthInMhz::WIDTH_5: |
| 1427 | return legacy_hal::WIFI_CHAN_WIDTH_5; |
| 1428 | case WifiChannelWidthInMhz::WIDTH_10: |
| 1429 | return legacy_hal::WIFI_CHAN_WIDTH_10; |
| 1430 | case WifiChannelWidthInMhz::WIDTH_INVALID: |
| 1431 | return legacy_hal::WIFI_CHAN_WIDTH_INVALID; |
| 1432 | }; |
| 1433 | CHECK(false); |
| 1434 | } |
| 1435 | |
| 1436 | WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl( |
| 1437 | legacy_hal::wifi_channel_width type) { |
| 1438 | switch (type) { |
| 1439 | case legacy_hal::WIFI_CHAN_WIDTH_20: |
| 1440 | return WifiChannelWidthInMhz::WIDTH_20; |
| 1441 | case legacy_hal::WIFI_CHAN_WIDTH_40: |
| 1442 | return WifiChannelWidthInMhz::WIDTH_40; |
| 1443 | case legacy_hal::WIFI_CHAN_WIDTH_80: |
| 1444 | return WifiChannelWidthInMhz::WIDTH_80; |
| 1445 | case legacy_hal::WIFI_CHAN_WIDTH_160: |
| 1446 | return WifiChannelWidthInMhz::WIDTH_160; |
| 1447 | case legacy_hal::WIFI_CHAN_WIDTH_80P80: |
| 1448 | return WifiChannelWidthInMhz::WIDTH_80P80; |
| 1449 | case legacy_hal::WIFI_CHAN_WIDTH_5: |
| 1450 | return WifiChannelWidthInMhz::WIDTH_5; |
| 1451 | case legacy_hal::WIFI_CHAN_WIDTH_10: |
| 1452 | return WifiChannelWidthInMhz::WIDTH_10; |
| 1453 | case legacy_hal::WIFI_CHAN_WIDTH_INVALID: |
| 1454 | return WifiChannelWidthInMhz::WIDTH_INVALID; |
| 1455 | }; |
| 1456 | CHECK(false) << "Unknown legacy type: " << type; |
| 1457 | } |
| 1458 | |
| 1459 | legacy_hal::wifi_rtt_preamble convertHidlRttPreambleToLegacy(RttPreamble type) { |
| 1460 | switch (type) { |
| 1461 | case RttPreamble::LEGACY: |
| 1462 | return legacy_hal::WIFI_RTT_PREAMBLE_LEGACY; |
| 1463 | case RttPreamble::HT: |
| 1464 | return legacy_hal::WIFI_RTT_PREAMBLE_HT; |
| 1465 | case RttPreamble::VHT: |
| 1466 | return legacy_hal::WIFI_RTT_PREAMBLE_VHT; |
| 1467 | }; |
| 1468 | CHECK(false); |
| 1469 | } |
| 1470 | |
| 1471 | RttPreamble convertLegacyRttPreambleToHidl(legacy_hal::wifi_rtt_preamble type) { |
| 1472 | switch (type) { |
| 1473 | case legacy_hal::WIFI_RTT_PREAMBLE_LEGACY: |
| 1474 | return RttPreamble::LEGACY; |
| 1475 | case legacy_hal::WIFI_RTT_PREAMBLE_HT: |
| 1476 | return RttPreamble::HT; |
| 1477 | case legacy_hal::WIFI_RTT_PREAMBLE_VHT: |
| 1478 | return RttPreamble::VHT; |
| 1479 | }; |
| 1480 | CHECK(false) << "Unknown legacy type: " << type; |
| 1481 | } |
| 1482 | |
| 1483 | legacy_hal::wifi_rtt_bw convertHidlRttBwToLegacy(RttBw type) { |
| 1484 | switch (type) { |
| 1485 | case RttBw::BW_5MHZ: |
| 1486 | return legacy_hal::WIFI_RTT_BW_5; |
| 1487 | case RttBw::BW_10MHZ: |
| 1488 | return legacy_hal::WIFI_RTT_BW_10; |
| 1489 | case RttBw::BW_20MHZ: |
| 1490 | return legacy_hal::WIFI_RTT_BW_20; |
| 1491 | case RttBw::BW_40MHZ: |
| 1492 | return legacy_hal::WIFI_RTT_BW_40; |
| 1493 | case RttBw::BW_80MHZ: |
| 1494 | return legacy_hal::WIFI_RTT_BW_80; |
| 1495 | case RttBw::BW_160MHZ: |
| 1496 | return legacy_hal::WIFI_RTT_BW_160; |
| 1497 | }; |
| 1498 | CHECK(false); |
| 1499 | } |
| 1500 | |
| 1501 | RttBw convertLegacyRttBwToHidl(legacy_hal::wifi_rtt_bw type) { |
| 1502 | switch (type) { |
| 1503 | case legacy_hal::WIFI_RTT_BW_5: |
| 1504 | return RttBw::BW_5MHZ; |
| 1505 | case legacy_hal::WIFI_RTT_BW_10: |
| 1506 | return RttBw::BW_10MHZ; |
| 1507 | case legacy_hal::WIFI_RTT_BW_20: |
| 1508 | return RttBw::BW_20MHZ; |
| 1509 | case legacy_hal::WIFI_RTT_BW_40: |
| 1510 | return RttBw::BW_40MHZ; |
| 1511 | case legacy_hal::WIFI_RTT_BW_80: |
| 1512 | return RttBw::BW_80MHZ; |
| 1513 | case legacy_hal::WIFI_RTT_BW_160: |
| 1514 | return RttBw::BW_160MHZ; |
| 1515 | }; |
| 1516 | CHECK(false) << "Unknown legacy type: " << type; |
| 1517 | } |
| 1518 | |
| 1519 | legacy_hal::wifi_motion_pattern convertHidlRttMotionPatternToLegacy( |
| 1520 | RttMotionPattern type) { |
| 1521 | switch (type) { |
| 1522 | case RttMotionPattern::NOT_EXPECTED: |
| 1523 | return legacy_hal::WIFI_MOTION_NOT_EXPECTED; |
| 1524 | case RttMotionPattern::EXPECTED: |
| 1525 | return legacy_hal::WIFI_MOTION_EXPECTED; |
| 1526 | case RttMotionPattern::UNKNOWN: |
| 1527 | return legacy_hal::WIFI_MOTION_UNKNOWN; |
| 1528 | }; |
| 1529 | CHECK(false); |
| 1530 | } |
| 1531 | |
| 1532 | WifiRatePreamble convertLegacyWifiRatePreambleToHidl(uint8_t preamble) { |
| 1533 | switch (preamble) { |
| 1534 | case 0: |
| 1535 | return WifiRatePreamble::OFDM; |
| 1536 | case 1: |
| 1537 | return WifiRatePreamble::CCK; |
| 1538 | case 2: |
| 1539 | return WifiRatePreamble::HT; |
| 1540 | case 3: |
| 1541 | return WifiRatePreamble::VHT; |
| 1542 | default: |
| 1543 | return WifiRatePreamble::RESERVED; |
| 1544 | }; |
| 1545 | CHECK(false) << "Unknown legacy preamble: " << preamble; |
| 1546 | } |
| 1547 | |
| 1548 | WifiRateNss convertLegacyWifiRateNssToHidl(uint8_t nss) { |
| 1549 | switch (nss) { |
| 1550 | case 0: |
| 1551 | return WifiRateNss::NSS_1x1; |
| 1552 | case 1: |
| 1553 | return WifiRateNss::NSS_2x2; |
| 1554 | case 2: |
| 1555 | return WifiRateNss::NSS_3x3; |
| 1556 | case 3: |
| 1557 | return WifiRateNss::NSS_4x4; |
| 1558 | }; |
| 1559 | CHECK(false) << "Unknown legacy nss: " << nss; |
| 1560 | return {}; |
| 1561 | } |
| 1562 | |
| 1563 | RttStatus convertLegacyRttStatusToHidl(legacy_hal::wifi_rtt_status status) { |
| 1564 | switch (status) { |
| 1565 | case legacy_hal::RTT_STATUS_SUCCESS: |
| 1566 | return RttStatus::SUCCESS; |
| 1567 | case legacy_hal::RTT_STATUS_FAILURE: |
| 1568 | return RttStatus::FAILURE; |
| 1569 | case legacy_hal::RTT_STATUS_FAIL_NO_RSP: |
| 1570 | return RttStatus::FAIL_NO_RSP; |
| 1571 | case legacy_hal::RTT_STATUS_FAIL_REJECTED: |
| 1572 | return RttStatus::FAIL_REJECTED; |
| 1573 | case legacy_hal::RTT_STATUS_FAIL_NOT_SCHEDULED_YET: |
| 1574 | return RttStatus::FAIL_NOT_SCHEDULED_YET; |
| 1575 | case legacy_hal::RTT_STATUS_FAIL_TM_TIMEOUT: |
| 1576 | return RttStatus::FAIL_TM_TIMEOUT; |
| 1577 | case legacy_hal::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL: |
| 1578 | return RttStatus::FAIL_AP_ON_DIFF_CHANNEL; |
| 1579 | case legacy_hal::RTT_STATUS_FAIL_NO_CAPABILITY: |
| 1580 | return RttStatus::FAIL_NO_CAPABILITY; |
| 1581 | case legacy_hal::RTT_STATUS_ABORTED: |
| 1582 | return RttStatus::ABORTED; |
| 1583 | case legacy_hal::RTT_STATUS_FAIL_INVALID_TS: |
| 1584 | return RttStatus::FAIL_INVALID_TS; |
| 1585 | case legacy_hal::RTT_STATUS_FAIL_PROTOCOL: |
| 1586 | return RttStatus::FAIL_PROTOCOL; |
| 1587 | case legacy_hal::RTT_STATUS_FAIL_SCHEDULE: |
| 1588 | return RttStatus::FAIL_SCHEDULE; |
| 1589 | case legacy_hal::RTT_STATUS_FAIL_BUSY_TRY_LATER: |
| 1590 | return RttStatus::FAIL_BUSY_TRY_LATER; |
| 1591 | case legacy_hal::RTT_STATUS_INVALID_REQ: |
| 1592 | return RttStatus::INVALID_REQ; |
| 1593 | case legacy_hal::RTT_STATUS_NO_WIFI: |
| 1594 | return RttStatus::NO_WIFI; |
| 1595 | case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE: |
| 1596 | return RttStatus::FAIL_FTM_PARAM_OVERRIDE; |
| 1597 | }; |
| 1598 | CHECK(false) << "Unknown legacy status: " << status; |
| 1599 | } |
| 1600 | |
| 1601 | bool convertHidlWifiChannelInfoToLegacy( |
| 1602 | const WifiChannelInfo& hidl_info, |
| 1603 | legacy_hal::wifi_channel_info* legacy_info) { |
| 1604 | if (!legacy_info) { |
| 1605 | return false; |
| 1606 | } |
| 1607 | legacy_info->width = convertHidlWifiChannelWidthToLegacy(hidl_info.width); |
| 1608 | legacy_info->center_freq = hidl_info.centerFreq; |
| 1609 | legacy_info->center_freq0 = hidl_info.centerFreq0; |
| 1610 | legacy_info->center_freq1 = hidl_info.centerFreq1; |
| 1611 | return true; |
| 1612 | } |
| 1613 | |
| 1614 | bool convertLegacyWifiChannelInfoToHidl( |
| 1615 | const legacy_hal::wifi_channel_info& legacy_info, |
| 1616 | WifiChannelInfo* hidl_info) { |
| 1617 | if (!hidl_info) { |
| 1618 | return false; |
| 1619 | } |
| 1620 | hidl_info->width = convertLegacyWifiChannelWidthToHidl(legacy_info.width); |
| 1621 | hidl_info->centerFreq = legacy_info.center_freq; |
| 1622 | hidl_info->centerFreq0 = legacy_info.center_freq0; |
| 1623 | hidl_info->centerFreq1 = legacy_info.center_freq1; |
| 1624 | return true; |
| 1625 | } |
| 1626 | |
| 1627 | bool convertHidlRttConfigToLegacy(const RttConfig& hidl_config, |
| 1628 | legacy_hal::wifi_rtt_config* legacy_config) { |
| 1629 | if (!legacy_config) { |
| 1630 | return false; |
| 1631 | } |
| 1632 | CHECK(hidl_config.addr.size() == sizeof(legacy_config->addr)); |
| 1633 | memcpy(legacy_config->addr, hidl_config.addr.data(), hidl_config.addr.size()); |
| 1634 | legacy_config->type = convertHidlRttTypeToLegacy(hidl_config.type); |
| 1635 | legacy_config->peer = convertHidlRttPeerTypeToLegacy(hidl_config.peer); |
| 1636 | if (!convertHidlWifiChannelInfoToLegacy(hidl_config.channel, |
| 1637 | &legacy_config->channel)) { |
| 1638 | return false; |
| 1639 | } |
| 1640 | legacy_config->burst_period = hidl_config.burstPeriod; |
| 1641 | legacy_config->num_burst = hidl_config.numBurst; |
| 1642 | legacy_config->num_frames_per_burst = hidl_config.numFramesPerBurst; |
| 1643 | legacy_config->num_retries_per_rtt_frame = hidl_config.numRetriesPerRttFrame; |
| 1644 | legacy_config->num_retries_per_ftmr = hidl_config.numRetriesPerFtmr; |
| 1645 | legacy_config->LCI_request = hidl_config.mustRequestLci; |
| 1646 | legacy_config->LCR_request = hidl_config.mustRequestLcr; |
| 1647 | legacy_config->burst_duration = hidl_config.burstDuration; |
| 1648 | legacy_config->preamble = |
| 1649 | convertHidlRttPreambleToLegacy(hidl_config.preamble); |
| 1650 | legacy_config->bw = convertHidlRttBwToLegacy(hidl_config.bw); |
| 1651 | return true; |
| 1652 | } |
| 1653 | |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 1654 | bool convertHidlVectorOfRttConfigToLegacy( |
| 1655 | const std::vector<RttConfig>& hidl_configs, |
| 1656 | std::vector<legacy_hal::wifi_rtt_config>* legacy_configs) { |
| 1657 | if (!legacy_configs) { |
| 1658 | return false; |
| 1659 | } |
| 1660 | legacy_configs->clear(); |
| 1661 | for (const auto& hidl_config : hidl_configs) { |
| 1662 | legacy_hal::wifi_rtt_config legacy_config; |
| 1663 | if (!convertHidlRttConfigToLegacy(hidl_config, &legacy_config)) { |
| 1664 | return false; |
| 1665 | } |
| 1666 | legacy_configs->push_back(legacy_config); |
| 1667 | } |
| 1668 | return true; |
| 1669 | } |
| 1670 | |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 1671 | bool convertHidlRttLciInformationToLegacy( |
| 1672 | const RttLciInformation& hidl_info, |
| 1673 | legacy_hal::wifi_lci_information* legacy_info) { |
| 1674 | if (!legacy_info) { |
| 1675 | return false; |
| 1676 | } |
| 1677 | legacy_info->latitude = hidl_info.latitude; |
| 1678 | legacy_info->longitude = hidl_info.longitude; |
| 1679 | legacy_info->altitude = hidl_info.altitude; |
| 1680 | legacy_info->latitude_unc = hidl_info.latitudeUnc; |
| 1681 | legacy_info->longitude_unc = hidl_info.longitudeUnc; |
| 1682 | legacy_info->altitude_unc = hidl_info.altitudeUnc; |
| 1683 | legacy_info->motion_pattern = |
| 1684 | convertHidlRttMotionPatternToLegacy(hidl_info.motionPattern); |
| 1685 | legacy_info->floor = hidl_info.floor; |
| 1686 | legacy_info->height_above_floor = hidl_info.heightAboveFloor; |
| 1687 | legacy_info->height_unc = hidl_info.heightUnc; |
| 1688 | return true; |
| 1689 | } |
| 1690 | |
| 1691 | bool convertHidlRttLcrInformationToLegacy( |
| 1692 | const RttLcrInformation& hidl_info, |
| 1693 | legacy_hal::wifi_lcr_information* legacy_info) { |
| 1694 | if (!legacy_info) { |
| 1695 | return false; |
| 1696 | } |
| 1697 | CHECK(hidl_info.countryCode.size() == sizeof(legacy_info->country_code)); |
| 1698 | memcpy(legacy_info->country_code, |
| 1699 | hidl_info.countryCode.data(), |
| 1700 | hidl_info.countryCode.size()); |
| 1701 | if (hidl_info.civicInfo.size() > sizeof(legacy_info->civic_info)) { |
| 1702 | return false; |
| 1703 | } |
| 1704 | legacy_info->length = hidl_info.civicInfo.size(); |
| 1705 | memcpy(legacy_info->civic_info, |
| 1706 | hidl_info.civicInfo.c_str(), |
| 1707 | hidl_info.civicInfo.size()); |
| 1708 | return true; |
| 1709 | } |
| 1710 | |
| 1711 | bool convertHidlRttResponderToLegacy( |
| 1712 | const RttResponder& hidl_responder, |
| 1713 | legacy_hal::wifi_rtt_responder* legacy_responder) { |
| 1714 | if (!legacy_responder) { |
| 1715 | return false; |
| 1716 | } |
| 1717 | if (!convertHidlWifiChannelInfoToLegacy(hidl_responder.channel, |
| 1718 | &legacy_responder->channel)) { |
| 1719 | return false; |
| 1720 | } |
| 1721 | legacy_responder->preamble = |
| 1722 | convertHidlRttPreambleToLegacy(hidl_responder.preamble); |
| 1723 | return true; |
| 1724 | } |
| 1725 | |
| 1726 | bool convertLegacyRttResponderToHidl( |
| 1727 | const legacy_hal::wifi_rtt_responder& legacy_responder, |
| 1728 | RttResponder* hidl_responder) { |
| 1729 | if (!hidl_responder) { |
| 1730 | return false; |
| 1731 | } |
| 1732 | if (!convertLegacyWifiChannelInfoToHidl(legacy_responder.channel, |
| 1733 | &hidl_responder->channel)) { |
| 1734 | return false; |
| 1735 | } |
| 1736 | hidl_responder->preamble = |
| 1737 | convertLegacyRttPreambleToHidl(legacy_responder.preamble); |
| 1738 | return true; |
| 1739 | } |
| 1740 | |
| 1741 | bool convertLegacyRttCapabilitiesToHidl( |
| 1742 | const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, |
| 1743 | RttCapabilities* hidl_capabilities) { |
| 1744 | if (!hidl_capabilities) { |
| 1745 | return false; |
| 1746 | } |
| 1747 | hidl_capabilities->rttOneSidedSupported = |
| 1748 | legacy_capabilities.rtt_one_sided_supported; |
| 1749 | hidl_capabilities->rttFtmSupported = legacy_capabilities.rtt_ftm_supported; |
| 1750 | hidl_capabilities->lciSupported = legacy_capabilities.lci_support; |
| 1751 | hidl_capabilities->lcrSupported = legacy_capabilities.lcr_support; |
| 1752 | hidl_capabilities->responderSupported = |
| 1753 | legacy_capabilities.responder_supported; |
Roshan Pius | 88c3272 | 2017-02-16 12:43:17 -0800 | [diff] [blame] | 1754 | hidl_capabilities->preambleSupport = 0; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 1755 | for (const auto flag : {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, |
| 1756 | legacy_hal::WIFI_RTT_PREAMBLE_HT, |
| 1757 | legacy_hal::WIFI_RTT_PREAMBLE_VHT}) { |
| 1758 | if (legacy_capabilities.preamble_support & flag) { |
| 1759 | hidl_capabilities->preambleSupport |= |
| 1760 | static_cast<std::underlying_type<RttPreamble>::type>( |
| 1761 | convertLegacyRttPreambleToHidl(flag)); |
| 1762 | } |
| 1763 | } |
Roshan Pius | 88c3272 | 2017-02-16 12:43:17 -0800 | [diff] [blame] | 1764 | hidl_capabilities->bwSupport = 0; |
Roshan Pius | 3fae9c8 | 2016-12-02 14:49:41 -0800 | [diff] [blame] | 1765 | for (const auto flag : {legacy_hal::WIFI_RTT_BW_5, |
| 1766 | legacy_hal::WIFI_RTT_BW_10, |
| 1767 | legacy_hal::WIFI_RTT_BW_20, |
| 1768 | legacy_hal::WIFI_RTT_BW_40, |
| 1769 | legacy_hal::WIFI_RTT_BW_80, |
| 1770 | legacy_hal::WIFI_RTT_BW_160}) { |
| 1771 | if (legacy_capabilities.bw_support & flag) { |
| 1772 | hidl_capabilities->bwSupport |= |
| 1773 | static_cast<std::underlying_type<RttBw>::type>( |
| 1774 | convertLegacyRttBwToHidl(flag)); |
| 1775 | } |
| 1776 | } |
| 1777 | hidl_capabilities->mcVersion = legacy_capabilities.mc_version; |
| 1778 | return true; |
| 1779 | } |
| 1780 | |
| 1781 | bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate, |
| 1782 | WifiRateInfo* hidl_rate) { |
| 1783 | if (!hidl_rate) { |
| 1784 | return false; |
| 1785 | } |
| 1786 | hidl_rate->preamble = |
| 1787 | convertLegacyWifiRatePreambleToHidl(legacy_rate.preamble); |
| 1788 | hidl_rate->nss = convertLegacyWifiRateNssToHidl(legacy_rate.nss); |
| 1789 | hidl_rate->bw = convertLegacyWifiChannelWidthToHidl( |
| 1790 | static_cast<legacy_hal::wifi_channel_width>(legacy_rate.bw)); |
| 1791 | hidl_rate->rateMcsIdx = legacy_rate.rateMcsIdx; |
| 1792 | hidl_rate->bitRateInKbps = legacy_rate.bitrate; |
| 1793 | return true; |
| 1794 | } |
| 1795 | |
| 1796 | bool convertLegacyRttResultToHidl( |
| 1797 | const legacy_hal::wifi_rtt_result& legacy_result, RttResult* hidl_result) { |
| 1798 | if (!hidl_result) { |
| 1799 | return false; |
| 1800 | } |
| 1801 | CHECK(sizeof(legacy_result.addr) == hidl_result->addr.size()); |
| 1802 | memcpy( |
| 1803 | hidl_result->addr.data(), legacy_result.addr, sizeof(legacy_result.addr)); |
| 1804 | hidl_result->burstNum = legacy_result.burst_num; |
| 1805 | hidl_result->measurementNumber = legacy_result.measurement_number; |
| 1806 | hidl_result->successNumber = legacy_result.success_number; |
| 1807 | hidl_result->numberPerBurstPeer = legacy_result.number_per_burst_peer; |
| 1808 | hidl_result->status = convertLegacyRttStatusToHidl(legacy_result.status); |
| 1809 | hidl_result->retryAfterDuration = legacy_result.retry_after_duration; |
| 1810 | hidl_result->type = convertLegacyRttTypeToHidl(legacy_result.type); |
| 1811 | hidl_result->rssi = legacy_result.rssi; |
| 1812 | hidl_result->rssiSpread = legacy_result.rssi_spread; |
| 1813 | if (!convertLegacyWifiRateInfoToHidl(legacy_result.tx_rate, |
| 1814 | &hidl_result->txRate)) { |
| 1815 | return false; |
| 1816 | } |
| 1817 | if (!convertLegacyWifiRateInfoToHidl(legacy_result.rx_rate, |
| 1818 | &hidl_result->rxRate)) { |
| 1819 | return false; |
| 1820 | } |
| 1821 | hidl_result->rtt = legacy_result.rtt; |
| 1822 | hidl_result->rttSd = legacy_result.rtt_sd; |
| 1823 | hidl_result->rttSpread = legacy_result.rtt_spread; |
| 1824 | hidl_result->distanceInMm = legacy_result.distance_mm; |
| 1825 | hidl_result->distanceSdInMm = legacy_result.distance_sd_mm; |
| 1826 | hidl_result->distanceSpreadInMm = legacy_result.distance_spread_mm; |
| 1827 | hidl_result->timeStampInUs = legacy_result.ts; |
| 1828 | hidl_result->burstDurationInMs = legacy_result.burst_duration; |
| 1829 | hidl_result->negotiatedBurstNum = legacy_result.negotiated_burst_num; |
| 1830 | if (!convertLegacyIeToHidl(*legacy_result.LCI, &hidl_result->lci)) { |
| 1831 | return false; |
| 1832 | } |
| 1833 | if (!convertLegacyIeToHidl(*legacy_result.LCR, &hidl_result->lcr)) { |
| 1834 | return false; |
| 1835 | } |
| 1836 | return true; |
| 1837 | } |
Roshan Pius | e3f72ff | 2016-12-05 16:18:43 -0800 | [diff] [blame] | 1838 | |
| 1839 | bool convertLegacyVectorOfRttResultToHidl( |
| 1840 | const std::vector<const legacy_hal::wifi_rtt_result*>& legacy_results, |
| 1841 | std::vector<RttResult>* hidl_results) { |
| 1842 | if (!hidl_results) { |
| 1843 | return false; |
| 1844 | } |
| 1845 | hidl_results->clear(); |
| 1846 | for (const auto legacy_result : legacy_results) { |
| 1847 | RttResult hidl_result; |
| 1848 | if (!convertLegacyRttResultToHidl(*legacy_result, &hidl_result)) { |
| 1849 | return false; |
| 1850 | } |
| 1851 | hidl_results->push_back(hidl_result); |
| 1852 | } |
| 1853 | return true; |
| 1854 | } |
Roshan Pius | e65edb1 | 2016-11-22 13:02:01 -0800 | [diff] [blame] | 1855 | } // namespace hidl_struct_util |
| 1856 | } // namespace implementation |
| 1857 | } // namespace V1_0 |
| 1858 | } // namespace wifi |
| 1859 | } // namespace hardware |
| 1860 | } // namespace android |