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