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