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