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