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