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