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