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