Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 "aidl_struct_util.h" |
| 21 | |
| 22 | namespace aidl { |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace wifi { |
| 26 | namespace aidl_struct_util { |
| 27 | |
| 28 | WifiChannelWidthInMhz convertLegacyWifiChannelWidthToAidl(legacy_hal::wifi_channel_width type); |
| 29 | |
| 30 | std::string safeConvertChar(const char* str, size_t max_len) { |
| 31 | const char* c = str; |
| 32 | size_t size = 0; |
| 33 | while (*c && (unsigned char)*c < 128 && size < max_len) { |
| 34 | ++size; |
| 35 | ++c; |
| 36 | } |
| 37 | return std::string(str, size); |
| 38 | } |
| 39 | |
| 40 | inline std::vector<int32_t> uintToIntVec(const std::vector<uint32_t>& in) { |
| 41 | return std::vector<int32_t>(in.begin(), in.end()); |
| 42 | } |
| 43 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 44 | IWifiStaIface::StaIfaceCapabilityMask convertLegacyLoggerFeatureToAidlStaIfaceCapability( |
| 45 | uint32_t feature) { |
| 46 | switch (feature) { |
| 47 | case legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED: |
| 48 | return IWifiStaIface::StaIfaceCapabilityMask::DEBUG_PACKET_FATE; |
| 49 | }; |
| 50 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 51 | return {}; |
| 52 | } |
| 53 | |
| 54 | IWifiChip::ChipCapabilityMask convertLegacyFeatureToAidlChipCapability(uint64_t feature) { |
| 55 | switch (feature) { |
| 56 | case WIFI_FEATURE_SET_TX_POWER_LIMIT: |
| 57 | return IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT; |
| 58 | case WIFI_FEATURE_USE_BODY_HEAD_SAR: |
| 59 | return IWifiChip::ChipCapabilityMask::USE_BODY_HEAD_SAR; |
| 60 | case WIFI_FEATURE_D2D_RTT: |
| 61 | return IWifiChip::ChipCapabilityMask::D2D_RTT; |
| 62 | case WIFI_FEATURE_D2AP_RTT: |
| 63 | return IWifiChip::ChipCapabilityMask::D2AP_RTT; |
| 64 | case WIFI_FEATURE_INFRA_60G: |
| 65 | return IWifiChip::ChipCapabilityMask::WIGIG; |
| 66 | case WIFI_FEATURE_SET_LATENCY_MODE: |
| 67 | return IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE; |
| 68 | case WIFI_FEATURE_P2P_RAND_MAC: |
| 69 | return IWifiChip::ChipCapabilityMask::P2P_RAND_MAC; |
Oscar Shu | 79e826d | 2023-01-27 21:50:17 +0000 | [diff] [blame] | 70 | case WIFI_FEATURE_AFC_CHANNEL: |
| 71 | return IWifiChip::ChipCapabilityMask::SET_AFC_CHANNEL_ALLOWANCE; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 72 | }; |
| 73 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 74 | return {}; |
| 75 | } |
| 76 | |
| 77 | IWifiStaIface::StaIfaceCapabilityMask convertLegacyFeatureToAidlStaIfaceCapability( |
| 78 | uint64_t feature) { |
| 79 | switch (feature) { |
| 80 | case WIFI_FEATURE_GSCAN: |
| 81 | return IWifiStaIface::StaIfaceCapabilityMask::BACKGROUND_SCAN; |
| 82 | case WIFI_FEATURE_LINK_LAYER_STATS: |
| 83 | return IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS; |
| 84 | case WIFI_FEATURE_RSSI_MONITOR: |
| 85 | return IWifiStaIface::StaIfaceCapabilityMask::RSSI_MONITOR; |
| 86 | case WIFI_FEATURE_CONTROL_ROAMING: |
| 87 | return IWifiStaIface::StaIfaceCapabilityMask::CONTROL_ROAMING; |
| 88 | case WIFI_FEATURE_IE_WHITELIST: |
| 89 | return IWifiStaIface::StaIfaceCapabilityMask::PROBE_IE_ALLOWLIST; |
| 90 | case WIFI_FEATURE_SCAN_RAND: |
| 91 | return IWifiStaIface::StaIfaceCapabilityMask::SCAN_RAND; |
| 92 | case WIFI_FEATURE_INFRA_5G: |
| 93 | return IWifiStaIface::StaIfaceCapabilityMask::STA_5G; |
| 94 | case WIFI_FEATURE_HOTSPOT: |
| 95 | return IWifiStaIface::StaIfaceCapabilityMask::HOTSPOT; |
| 96 | case WIFI_FEATURE_PNO: |
| 97 | return IWifiStaIface::StaIfaceCapabilityMask::PNO; |
| 98 | case WIFI_FEATURE_TDLS: |
| 99 | return IWifiStaIface::StaIfaceCapabilityMask::TDLS; |
| 100 | case WIFI_FEATURE_TDLS_OFFCHANNEL: |
| 101 | return IWifiStaIface::StaIfaceCapabilityMask::TDLS_OFFCHANNEL; |
| 102 | case WIFI_FEATURE_CONFIG_NDO: |
| 103 | return IWifiStaIface::StaIfaceCapabilityMask::ND_OFFLOAD; |
| 104 | case WIFI_FEATURE_MKEEP_ALIVE: |
| 105 | return IWifiStaIface::StaIfaceCapabilityMask::KEEP_ALIVE; |
| 106 | }; |
| 107 | CHECK(false) << "Unknown legacy feature: " << feature; |
| 108 | return {}; |
| 109 | } |
| 110 | |
Gabriel Biren | bff0e40 | 2023-02-14 22:42:20 +0000 | [diff] [blame] | 111 | bool convertLegacyFeaturesToAidlChipCapabilities(uint64_t legacy_feature_set, uint32_t* aidl_caps) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 112 | if (!aidl_caps) { |
| 113 | return false; |
| 114 | } |
| 115 | *aidl_caps = {}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 116 | std::vector<uint64_t> features = {WIFI_FEATURE_SET_TX_POWER_LIMIT, |
| 117 | WIFI_FEATURE_USE_BODY_HEAD_SAR, |
| 118 | WIFI_FEATURE_D2D_RTT, |
| 119 | WIFI_FEATURE_D2AP_RTT, |
| 120 | WIFI_FEATURE_INFRA_60G, |
| 121 | WIFI_FEATURE_SET_LATENCY_MODE, |
Oscar Shu | 79e826d | 2023-01-27 21:50:17 +0000 | [diff] [blame] | 122 | WIFI_FEATURE_P2P_RAND_MAC, |
| 123 | WIFI_FEATURE_AFC_CHANNEL}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 124 | for (const auto feature : features) { |
| 125 | if (feature & legacy_feature_set) { |
| 126 | *aidl_caps |= static_cast<uint32_t>(convertLegacyFeatureToAidlChipCapability(feature)); |
| 127 | } |
| 128 | } |
| 129 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 130 | return true; |
| 131 | } |
| 132 | |
| 133 | WifiDebugRingBufferFlags convertLegacyDebugRingBufferFlagsToAidl(uint32_t flag) { |
| 134 | switch (flag) { |
| 135 | case WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES: |
| 136 | return WifiDebugRingBufferFlags::HAS_BINARY_ENTRIES; |
| 137 | case WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES: |
| 138 | return WifiDebugRingBufferFlags::HAS_ASCII_ENTRIES; |
| 139 | }; |
| 140 | CHECK(false) << "Unknown legacy flag: " << flag; |
| 141 | return {}; |
| 142 | } |
| 143 | |
| 144 | bool convertLegacyDebugRingBufferStatusToAidl( |
| 145 | const legacy_hal::wifi_ring_buffer_status& legacy_status, |
| 146 | WifiDebugRingBufferStatus* aidl_status) { |
| 147 | if (!aidl_status) { |
| 148 | return false; |
| 149 | } |
| 150 | *aidl_status = {}; |
| 151 | aidl_status->ringName = safeConvertChar(reinterpret_cast<const char*>(legacy_status.name), |
| 152 | sizeof(legacy_status.name)); |
| 153 | aidl_status->flags = 0; |
| 154 | for (const auto flag : |
| 155 | {WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES, WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES}) { |
| 156 | if (flag & legacy_status.flags) { |
| 157 | aidl_status->flags |= static_cast<std::underlying_type<WifiDebugRingBufferFlags>::type>( |
| 158 | convertLegacyDebugRingBufferFlagsToAidl(flag)); |
| 159 | } |
| 160 | } |
| 161 | aidl_status->ringId = legacy_status.ring_id; |
| 162 | aidl_status->sizeInBytes = legacy_status.ring_buffer_byte_size; |
| 163 | // Calculate free size of the ring the buffer. We don't need to send the |
| 164 | // exact read/write pointers that were there in the legacy HAL interface. |
| 165 | if (legacy_status.written_bytes >= legacy_status.read_bytes) { |
| 166 | aidl_status->freeSizeInBytes = legacy_status.ring_buffer_byte_size - |
| 167 | (legacy_status.written_bytes - legacy_status.read_bytes); |
| 168 | } else { |
| 169 | aidl_status->freeSizeInBytes = legacy_status.read_bytes - legacy_status.written_bytes; |
| 170 | } |
| 171 | aidl_status->verboseLevel = legacy_status.verbose_level; |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | bool convertLegacyVectorOfDebugRingBufferStatusToAidl( |
| 176 | const std::vector<legacy_hal::wifi_ring_buffer_status>& legacy_status_vec, |
| 177 | std::vector<WifiDebugRingBufferStatus>* aidl_status_vec) { |
| 178 | if (!aidl_status_vec) { |
| 179 | return false; |
| 180 | } |
| 181 | *aidl_status_vec = {}; |
| 182 | for (const auto& legacy_status : legacy_status_vec) { |
| 183 | WifiDebugRingBufferStatus aidl_status; |
| 184 | if (!convertLegacyDebugRingBufferStatusToAidl(legacy_status, &aidl_status)) { |
| 185 | return false; |
| 186 | } |
| 187 | aidl_status_vec->push_back(aidl_status); |
| 188 | } |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | bool convertLegacyWakeReasonStatsToAidl(const legacy_hal::WakeReasonStats& legacy_stats, |
| 193 | WifiDebugHostWakeReasonStats* aidl_stats) { |
| 194 | if (!aidl_stats) { |
| 195 | return false; |
| 196 | } |
| 197 | *aidl_stats = {}; |
| 198 | aidl_stats->totalCmdEventWakeCnt = legacy_stats.wake_reason_cnt.total_cmd_event_wake; |
| 199 | aidl_stats->cmdEventWakeCntPerType = uintToIntVec(legacy_stats.cmd_event_wake_cnt); |
| 200 | aidl_stats->totalDriverFwLocalWakeCnt = legacy_stats.wake_reason_cnt.total_driver_fw_local_wake; |
| 201 | aidl_stats->driverFwLocalWakeCntPerType = uintToIntVec(legacy_stats.driver_fw_local_wake_cnt); |
| 202 | aidl_stats->totalRxPacketWakeCnt = legacy_stats.wake_reason_cnt.total_rx_data_wake; |
| 203 | aidl_stats->rxPktWakeDetails.rxUnicastCnt = |
| 204 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_unicast_cnt; |
| 205 | aidl_stats->rxPktWakeDetails.rxMulticastCnt = |
| 206 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_multicast_cnt; |
| 207 | aidl_stats->rxPktWakeDetails.rxBroadcastCnt = |
| 208 | legacy_stats.wake_reason_cnt.rx_wake_details.rx_broadcast_cnt; |
| 209 | aidl_stats->rxMulticastPkWakeDetails.ipv4RxMulticastAddrCnt = |
| 210 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv4_rx_multicast_addr_cnt; |
| 211 | aidl_stats->rxMulticastPkWakeDetails.ipv6RxMulticastAddrCnt = |
| 212 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.ipv6_rx_multicast_addr_cnt; |
| 213 | aidl_stats->rxMulticastPkWakeDetails.otherRxMulticastAddrCnt = |
| 214 | legacy_stats.wake_reason_cnt.rx_multicast_wake_pkt_info.other_rx_multicast_addr_cnt; |
| 215 | aidl_stats->rxIcmpPkWakeDetails.icmpPkt = |
| 216 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp_pkt; |
| 217 | aidl_stats->rxIcmpPkWakeDetails.icmp6Pkt = |
| 218 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_pkt; |
| 219 | aidl_stats->rxIcmpPkWakeDetails.icmp6Ra = |
| 220 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ra; |
| 221 | aidl_stats->rxIcmpPkWakeDetails.icmp6Na = |
| 222 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_na; |
| 223 | aidl_stats->rxIcmpPkWakeDetails.icmp6Ns = |
| 224 | legacy_stats.wake_reason_cnt.rx_wake_pkt_classification_info.icmp6_ns; |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | legacy_hal::wifi_power_scenario convertAidlTxPowerScenarioToLegacy( |
| 229 | IWifiChip::TxPowerScenario aidl_scenario) { |
| 230 | switch (aidl_scenario) { |
| 231 | case IWifiChip::TxPowerScenario::VOICE_CALL: |
| 232 | return legacy_hal::WIFI_POWER_SCENARIO_VOICE_CALL; |
| 233 | case IWifiChip::TxPowerScenario::ON_HEAD_CELL_OFF: |
| 234 | return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF; |
| 235 | case IWifiChip::TxPowerScenario::ON_HEAD_CELL_ON: |
| 236 | return legacy_hal::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON; |
| 237 | case IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF: |
| 238 | return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF; |
| 239 | case IWifiChip::TxPowerScenario::ON_BODY_CELL_ON: |
| 240 | return legacy_hal::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON; |
| 241 | }; |
| 242 | CHECK(false); |
| 243 | } |
| 244 | |
| 245 | legacy_hal::wifi_latency_mode convertAidlLatencyModeToLegacy( |
| 246 | IWifiChip::LatencyMode aidl_latency_mode) { |
| 247 | switch (aidl_latency_mode) { |
| 248 | case IWifiChip::LatencyMode::NORMAL: |
| 249 | return legacy_hal::WIFI_LATENCY_MODE_NORMAL; |
| 250 | case IWifiChip::LatencyMode::LOW: |
| 251 | return legacy_hal::WIFI_LATENCY_MODE_LOW; |
| 252 | } |
| 253 | CHECK(false); |
| 254 | } |
| 255 | |
| 256 | bool convertLegacyWifiMacInfoToAidl(const legacy_hal::WifiMacInfo& legacy_mac_info, |
| 257 | IWifiChipEventCallback::RadioModeInfo* aidl_radio_mode_info) { |
| 258 | if (!aidl_radio_mode_info) { |
| 259 | return false; |
| 260 | } |
| 261 | *aidl_radio_mode_info = {}; |
| 262 | |
| 263 | aidl_radio_mode_info->radioId = legacy_mac_info.wlan_mac_id; |
| 264 | // Convert from bitmask of bands in the legacy HAL to enum value in |
| 265 | // the AIDL interface. |
| 266 | if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && |
| 267 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND && |
| 268 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { |
| 269 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ_5GHZ_6GHZ; |
| 270 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND && |
| 271 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
| 272 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_5GHZ_6GHZ; |
| 273 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_6_0_BAND) { |
| 274 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_6GHZ; |
| 275 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND && |
| 276 | legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
| 277 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ_5GHZ; |
| 278 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_2_4_BAND) { |
| 279 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_24GHZ; |
| 280 | } else if (legacy_mac_info.mac_band & legacy_hal::WLAN_MAC_5_0_BAND) { |
| 281 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_5GHZ; |
| 282 | } else { |
| 283 | aidl_radio_mode_info->bandInfo = WifiBand::BAND_UNSPECIFIED; |
| 284 | } |
| 285 | std::vector<IWifiChipEventCallback::IfaceInfo> iface_info_vec; |
| 286 | for (const auto& legacy_iface_info : legacy_mac_info.iface_infos) { |
| 287 | IWifiChipEventCallback::IfaceInfo iface_info; |
| 288 | iface_info.name = legacy_iface_info.name; |
| 289 | iface_info.channel = legacy_iface_info.channel; |
| 290 | iface_info_vec.push_back(iface_info); |
| 291 | } |
| 292 | aidl_radio_mode_info->ifaceInfos = iface_info_vec; |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | uint32_t convertAidlWifiBandToLegacyMacBand(WifiBand aidl_band) { |
| 297 | switch (aidl_band) { |
| 298 | case WifiBand::BAND_24GHZ: |
| 299 | return legacy_hal::WLAN_MAC_2_4_BAND; |
| 300 | case WifiBand::BAND_5GHZ: |
| 301 | case WifiBand::BAND_5GHZ_DFS: |
| 302 | case WifiBand::BAND_5GHZ_WITH_DFS: |
| 303 | return legacy_hal::WLAN_MAC_5_0_BAND; |
| 304 | case WifiBand::BAND_24GHZ_5GHZ: |
| 305 | case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: |
| 306 | return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND); |
| 307 | case WifiBand::BAND_6GHZ: |
| 308 | return legacy_hal::WLAN_MAC_6_0_BAND; |
| 309 | case WifiBand::BAND_5GHZ_6GHZ: |
| 310 | return (legacy_hal::WLAN_MAC_5_0_BAND | legacy_hal::WLAN_MAC_6_0_BAND); |
| 311 | case WifiBand::BAND_24GHZ_5GHZ_6GHZ: |
| 312 | case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS_6GHZ: |
| 313 | return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | |
| 314 | legacy_hal::WLAN_MAC_6_0_BAND); |
| 315 | case WifiBand::BAND_60GHZ: |
| 316 | return legacy_hal::WLAN_MAC_60_0_BAND; |
| 317 | default: |
| 318 | return (legacy_hal::WLAN_MAC_2_4_BAND | legacy_hal::WLAN_MAC_5_0_BAND | |
| 319 | legacy_hal::WLAN_MAC_6_0_BAND | legacy_hal::WLAN_MAC_60_0_BAND); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | WifiBand convertLegacyMacBandToAidlWifiBand(uint32_t band) { |
| 324 | switch (band) { |
| 325 | case legacy_hal::WLAN_MAC_2_4_BAND: |
| 326 | return WifiBand::BAND_24GHZ; |
| 327 | case legacy_hal::WLAN_MAC_5_0_BAND: |
| 328 | return WifiBand::BAND_5GHZ; |
| 329 | case legacy_hal::WLAN_MAC_6_0_BAND: |
| 330 | return WifiBand::BAND_6GHZ; |
| 331 | case legacy_hal::WLAN_MAC_60_0_BAND: |
| 332 | return WifiBand::BAND_60GHZ; |
| 333 | default: |
| 334 | return WifiBand::BAND_UNSPECIFIED; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | uint32_t convertAidlWifiIfaceModeToLegacy(uint32_t aidl_iface_mask) { |
| 339 | uint32_t legacy_iface_mask = 0; |
| 340 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_STA)) { |
| 341 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_STA); |
| 342 | } |
| 343 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_SOFTAP)) { |
| 344 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_SOFTAP); |
| 345 | } |
| 346 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_P2P_CLIENT)) { |
| 347 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT); |
| 348 | } |
| 349 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_P2P_GO)) { |
| 350 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_P2P_GO); |
| 351 | } |
| 352 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_NAN)) { |
| 353 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_NAN); |
| 354 | } |
| 355 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_TDLS)) { |
| 356 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_TDLS); |
| 357 | } |
| 358 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_MESH)) { |
| 359 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_MESH); |
| 360 | } |
| 361 | if (aidl_iface_mask & static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_IBSS)) { |
| 362 | legacy_iface_mask |= (1 << legacy_hal::WIFI_INTERFACE_IBSS); |
| 363 | } |
| 364 | return legacy_iface_mask; |
| 365 | } |
| 366 | |
| 367 | uint32_t convertLegacyWifiInterfaceModeToAidl(uint32_t legacy_iface_mask) { |
| 368 | uint32_t aidl_iface_mask = 0; |
| 369 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_STA)) { |
| 370 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_STA); |
| 371 | } |
| 372 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_SOFTAP)) { |
| 373 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_SOFTAP); |
| 374 | } |
| 375 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_CLIENT)) { |
| 376 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_P2P_CLIENT); |
| 377 | } |
| 378 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_P2P_GO)) { |
| 379 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_P2P_GO); |
| 380 | } |
| 381 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_NAN)) { |
| 382 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_NAN); |
| 383 | } |
| 384 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_TDLS)) { |
| 385 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_TDLS); |
| 386 | } |
| 387 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_MESH)) { |
| 388 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_MESH); |
| 389 | } |
| 390 | if (legacy_iface_mask & (1 << legacy_hal::WIFI_INTERFACE_IBSS)) { |
| 391 | aidl_iface_mask |= static_cast<int32_t>(WifiIfaceMode::IFACE_MODE_IBSS); |
| 392 | } |
| 393 | return aidl_iface_mask; |
| 394 | } |
| 395 | |
| 396 | uint32_t convertAidlUsableChannelFilterToLegacy(uint32_t aidl_filter_mask) { |
| 397 | uint32_t legacy_filter_mask = 0; |
| 398 | if (aidl_filter_mask & |
| 399 | static_cast<int32_t>(IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE)) { |
| 400 | legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE; |
| 401 | } |
| 402 | if (aidl_filter_mask & static_cast<int32_t>(IWifiChip::UsableChannelFilter::CONCURRENCY)) { |
| 403 | legacy_filter_mask |= legacy_hal::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY; |
| 404 | } |
| 405 | if (aidl_filter_mask & static_cast<int32_t>(IWifiChip::UsableChannelFilter::NAN_INSTANT_MODE)) { |
| 406 | legacy_filter_mask |= WIFI_USABLE_CHANNEL_FILTER_NAN_INSTANT_MODE; |
| 407 | } |
| 408 | return legacy_filter_mask; |
| 409 | } |
| 410 | |
| 411 | bool convertLegacyWifiUsableChannelToAidl( |
| 412 | const legacy_hal::wifi_usable_channel& legacy_usable_channel, |
| 413 | WifiUsableChannel* aidl_usable_channel) { |
| 414 | if (!aidl_usable_channel) { |
| 415 | return false; |
| 416 | } |
| 417 | *aidl_usable_channel = {}; |
| 418 | aidl_usable_channel->channel = legacy_usable_channel.freq; |
| 419 | aidl_usable_channel->channelBandwidth = |
| 420 | convertLegacyWifiChannelWidthToAidl(legacy_usable_channel.width); |
| 421 | aidl_usable_channel->ifaceModeMask = static_cast<WifiIfaceMode>( |
| 422 | convertLegacyWifiInterfaceModeToAidl(legacy_usable_channel.iface_mode_mask)); |
| 423 | |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | bool convertLegacyWifiUsableChannelsToAidl( |
| 428 | const std::vector<legacy_hal::wifi_usable_channel>& legacy_usable_channels, |
| 429 | std::vector<WifiUsableChannel>* aidl_usable_channels) { |
| 430 | if (!aidl_usable_channels) { |
| 431 | return false; |
| 432 | } |
| 433 | *aidl_usable_channels = {}; |
| 434 | for (const auto& legacy_usable_channel : legacy_usable_channels) { |
| 435 | WifiUsableChannel aidl_usable_channel; |
| 436 | if (!convertLegacyWifiUsableChannelToAidl(legacy_usable_channel, &aidl_usable_channel)) { |
| 437 | return false; |
| 438 | } |
| 439 | aidl_usable_channels->push_back(aidl_usable_channel); |
| 440 | } |
| 441 | return true; |
| 442 | } |
| 443 | |
| 444 | bool convertLegacyWifiMacInfosToAidl( |
| 445 | const std::vector<legacy_hal::WifiMacInfo>& legacy_mac_infos, |
| 446 | std::vector<IWifiChipEventCallback::RadioModeInfo>* aidl_radio_mode_infos) { |
| 447 | if (!aidl_radio_mode_infos) { |
| 448 | return false; |
| 449 | } |
| 450 | *aidl_radio_mode_infos = {}; |
| 451 | |
| 452 | for (const auto& legacy_mac_info : legacy_mac_infos) { |
| 453 | IWifiChipEventCallback::RadioModeInfo aidl_radio_mode_info; |
| 454 | if (!convertLegacyWifiMacInfoToAidl(legacy_mac_info, &aidl_radio_mode_info)) { |
| 455 | return false; |
| 456 | } |
| 457 | aidl_radio_mode_infos->push_back(aidl_radio_mode_info); |
| 458 | } |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | bool convertLegacyFeaturesToAidlStaCapabilities(uint64_t legacy_feature_set, |
| 463 | uint32_t legacy_logger_feature_set, |
| 464 | uint32_t* aidl_caps) { |
| 465 | if (!aidl_caps) { |
| 466 | return false; |
| 467 | } |
| 468 | *aidl_caps = {}; |
| 469 | for (const auto feature : {legacy_hal::WIFI_LOGGER_PACKET_FATE_SUPPORTED}) { |
| 470 | if (feature & legacy_logger_feature_set) { |
| 471 | *aidl_caps |= static_cast<uint32_t>( |
| 472 | convertLegacyLoggerFeatureToAidlStaIfaceCapability(feature)); |
| 473 | } |
| 474 | } |
| 475 | for (const auto feature : |
| 476 | {WIFI_FEATURE_GSCAN, WIFI_FEATURE_LINK_LAYER_STATS, WIFI_FEATURE_RSSI_MONITOR, |
| 477 | WIFI_FEATURE_CONTROL_ROAMING, WIFI_FEATURE_IE_WHITELIST, WIFI_FEATURE_SCAN_RAND, |
| 478 | WIFI_FEATURE_INFRA_5G, WIFI_FEATURE_HOTSPOT, WIFI_FEATURE_PNO, WIFI_FEATURE_TDLS, |
| 479 | WIFI_FEATURE_TDLS_OFFCHANNEL, WIFI_FEATURE_CONFIG_NDO, WIFI_FEATURE_MKEEP_ALIVE}) { |
| 480 | if (feature & legacy_feature_set) { |
| 481 | *aidl_caps |= |
| 482 | static_cast<uint32_t>(convertLegacyFeatureToAidlStaIfaceCapability(feature)); |
| 483 | } |
| 484 | } |
| 485 | // There is no flag for this one in the legacy feature set. Adding it to the |
| 486 | // set because all the current devices support it. |
| 487 | *aidl_caps |= static_cast<uint32_t>(IWifiStaIface::StaIfaceCapabilityMask::APF); |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | bool convertLegacyApfCapabilitiesToAidl(const legacy_hal::PacketFilterCapabilities& legacy_caps, |
| 492 | StaApfPacketFilterCapabilities* aidl_caps) { |
| 493 | if (!aidl_caps) { |
| 494 | return false; |
| 495 | } |
| 496 | *aidl_caps = {}; |
| 497 | aidl_caps->version = legacy_caps.version; |
| 498 | aidl_caps->maxLength = legacy_caps.max_len; |
| 499 | return true; |
| 500 | } |
| 501 | |
| 502 | uint8_t convertAidlGscanReportEventFlagToLegacy( |
| 503 | StaBackgroundScanBucketEventReportSchemeMask aidl_flag) { |
| 504 | using AidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 505 | switch (aidl_flag) { |
| 506 | case AidlFlag::EACH_SCAN: |
| 507 | return REPORT_EVENTS_EACH_SCAN; |
| 508 | case AidlFlag::FULL_RESULTS: |
| 509 | return REPORT_EVENTS_FULL_RESULTS; |
| 510 | case AidlFlag::NO_BATCH: |
| 511 | return REPORT_EVENTS_NO_BATCH; |
| 512 | }; |
| 513 | CHECK(false); |
| 514 | } |
| 515 | |
| 516 | StaScanDataFlagMask convertLegacyGscanDataFlagToAidl(uint8_t legacy_flag) { |
| 517 | switch (legacy_flag) { |
| 518 | case legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED: |
| 519 | return StaScanDataFlagMask::INTERRUPTED; |
| 520 | }; |
| 521 | CHECK(false) << "Unknown legacy flag: " << legacy_flag; |
| 522 | // To silence the compiler warning about reaching the end of non-void |
| 523 | // function. |
| 524 | return {}; |
| 525 | } |
| 526 | |
| 527 | bool convertLegacyGscanCapabilitiesToAidl(const legacy_hal::wifi_gscan_capabilities& legacy_caps, |
| 528 | StaBackgroundScanCapabilities* aidl_caps) { |
| 529 | if (!aidl_caps) { |
| 530 | return false; |
| 531 | } |
| 532 | *aidl_caps = {}; |
| 533 | aidl_caps->maxCacheSize = legacy_caps.max_scan_cache_size; |
| 534 | aidl_caps->maxBuckets = legacy_caps.max_scan_buckets; |
| 535 | aidl_caps->maxApCachePerScan = legacy_caps.max_ap_cache_per_scan; |
| 536 | aidl_caps->maxReportingThreshold = legacy_caps.max_scan_reporting_threshold; |
| 537 | return true; |
| 538 | } |
| 539 | |
| 540 | legacy_hal::wifi_band convertAidlWifiBandToLegacy(WifiBand band) { |
| 541 | switch (band) { |
| 542 | case WifiBand::BAND_UNSPECIFIED: |
| 543 | return legacy_hal::WIFI_BAND_UNSPECIFIED; |
| 544 | case WifiBand::BAND_24GHZ: |
| 545 | return legacy_hal::WIFI_BAND_BG; |
| 546 | case WifiBand::BAND_5GHZ: |
| 547 | return legacy_hal::WIFI_BAND_A; |
| 548 | case WifiBand::BAND_5GHZ_DFS: |
| 549 | return legacy_hal::WIFI_BAND_A_DFS; |
| 550 | case WifiBand::BAND_5GHZ_WITH_DFS: |
| 551 | return legacy_hal::WIFI_BAND_A_WITH_DFS; |
| 552 | case WifiBand::BAND_24GHZ_5GHZ: |
| 553 | return legacy_hal::WIFI_BAND_ABG; |
| 554 | case WifiBand::BAND_24GHZ_5GHZ_WITH_DFS: |
| 555 | return legacy_hal::WIFI_BAND_ABG_WITH_DFS; |
| 556 | default: |
| 557 | CHECK(false); |
| 558 | return {}; |
| 559 | }; |
| 560 | } |
| 561 | |
| 562 | bool convertAidlGscanParamsToLegacy(const StaBackgroundScanParameters& aidl_scan_params, |
| 563 | legacy_hal::wifi_scan_cmd_params* legacy_scan_params) { |
| 564 | if (!legacy_scan_params) { |
| 565 | return false; |
| 566 | } |
| 567 | *legacy_scan_params = {}; |
| 568 | legacy_scan_params->base_period = aidl_scan_params.basePeriodInMs; |
| 569 | legacy_scan_params->max_ap_per_scan = aidl_scan_params.maxApPerScan; |
| 570 | legacy_scan_params->report_threshold_percent = aidl_scan_params.reportThresholdPercent; |
| 571 | legacy_scan_params->report_threshold_num_scans = aidl_scan_params.reportThresholdNumScans; |
| 572 | if (aidl_scan_params.buckets.size() > MAX_BUCKETS) { |
| 573 | return false; |
| 574 | } |
| 575 | legacy_scan_params->num_buckets = aidl_scan_params.buckets.size(); |
| 576 | for (uint32_t bucket_idx = 0; bucket_idx < aidl_scan_params.buckets.size(); bucket_idx++) { |
| 577 | const StaBackgroundScanBucketParameters& aidl_bucket_spec = |
| 578 | aidl_scan_params.buckets[bucket_idx]; |
| 579 | legacy_hal::wifi_scan_bucket_spec& legacy_bucket_spec = |
| 580 | legacy_scan_params->buckets[bucket_idx]; |
| 581 | if (aidl_bucket_spec.bucketIdx >= MAX_BUCKETS) { |
| 582 | return false; |
| 583 | } |
| 584 | legacy_bucket_spec.bucket = aidl_bucket_spec.bucketIdx; |
| 585 | legacy_bucket_spec.band = convertAidlWifiBandToLegacy(aidl_bucket_spec.band); |
| 586 | legacy_bucket_spec.period = aidl_bucket_spec.periodInMs; |
| 587 | legacy_bucket_spec.max_period = aidl_bucket_spec.exponentialMaxPeriodInMs; |
| 588 | legacy_bucket_spec.base = aidl_bucket_spec.exponentialBase; |
| 589 | legacy_bucket_spec.step_count = aidl_bucket_spec.exponentialStepCount; |
| 590 | legacy_bucket_spec.report_events = 0; |
| 591 | using AidlFlag = StaBackgroundScanBucketEventReportSchemeMask; |
| 592 | for (const auto flag : {AidlFlag::EACH_SCAN, AidlFlag::FULL_RESULTS, AidlFlag::NO_BATCH}) { |
| 593 | if (static_cast<int32_t>(aidl_bucket_spec.eventReportScheme) & |
| 594 | static_cast<std::underlying_type<AidlFlag>::type>(flag)) { |
| 595 | legacy_bucket_spec.report_events |= convertAidlGscanReportEventFlagToLegacy(flag); |
| 596 | } |
| 597 | } |
| 598 | if (aidl_bucket_spec.frequencies.size() > MAX_CHANNELS) { |
| 599 | return false; |
| 600 | } |
| 601 | legacy_bucket_spec.num_channels = aidl_bucket_spec.frequencies.size(); |
| 602 | for (uint32_t freq_idx = 0; freq_idx < aidl_bucket_spec.frequencies.size(); freq_idx++) { |
| 603 | legacy_bucket_spec.channels[freq_idx].channel = aidl_bucket_spec.frequencies[freq_idx]; |
| 604 | } |
| 605 | } |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | bool convertLegacyIeToAidl(const legacy_hal::wifi_information_element& legacy_ie, |
| 610 | WifiInformationElement* aidl_ie) { |
| 611 | if (!aidl_ie) { |
| 612 | return false; |
| 613 | } |
| 614 | *aidl_ie = {}; |
| 615 | aidl_ie->id = legacy_ie.id; |
| 616 | aidl_ie->data = std::vector<uint8_t>(legacy_ie.data, legacy_ie.data + legacy_ie.len); |
| 617 | return true; |
| 618 | } |
| 619 | |
| 620 | bool convertLegacyIeBlobToAidl(const uint8_t* ie_blob, uint32_t ie_blob_len, |
| 621 | std::vector<WifiInformationElement>* aidl_ies) { |
| 622 | if (!ie_blob || !aidl_ies) { |
| 623 | return false; |
| 624 | } |
| 625 | *aidl_ies = {}; |
| 626 | const uint8_t* ies_begin = ie_blob; |
| 627 | const uint8_t* ies_end = ie_blob + ie_blob_len; |
| 628 | const uint8_t* next_ie = ies_begin; |
| 629 | using wifi_ie = legacy_hal::wifi_information_element; |
| 630 | constexpr size_t kIeHeaderLen = sizeof(wifi_ie); |
| 631 | // Each IE should at least have the header (i.e |id| & |len| fields). |
| 632 | while (next_ie + kIeHeaderLen <= ies_end) { |
| 633 | const wifi_ie& legacy_ie = (*reinterpret_cast<const wifi_ie*>(next_ie)); |
| 634 | uint32_t curr_ie_len = kIeHeaderLen + legacy_ie.len; |
| 635 | if (next_ie + curr_ie_len > ies_end) { |
| 636 | LOG(ERROR) << "Error parsing IE blob. Next IE: " << (void*)next_ie |
| 637 | << ", Curr IE len: " << curr_ie_len << ", IEs End: " << (void*)ies_end; |
| 638 | break; |
| 639 | } |
| 640 | WifiInformationElement aidl_ie; |
| 641 | if (!convertLegacyIeToAidl(legacy_ie, &aidl_ie)) { |
| 642 | LOG(ERROR) << "Error converting IE. Id: " << legacy_ie.id << ", len: " << legacy_ie.len; |
| 643 | break; |
| 644 | } |
| 645 | aidl_ies->push_back(std::move(aidl_ie)); |
| 646 | next_ie += curr_ie_len; |
| 647 | } |
| 648 | // Check if the blob has been fully consumed. |
| 649 | if (next_ie != ies_end) { |
| 650 | LOG(ERROR) << "Failed to fully parse IE blob. Next IE: " << (void*)next_ie |
| 651 | << ", IEs End: " << (void*)ies_end; |
| 652 | } |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | bool convertLegacyGscanResultToAidl(const legacy_hal::wifi_scan_result& legacy_scan_result, |
| 657 | bool has_ie_data, StaScanResult* aidl_scan_result) { |
| 658 | if (!aidl_scan_result) { |
| 659 | return false; |
| 660 | } |
| 661 | *aidl_scan_result = {}; |
| 662 | aidl_scan_result->timeStampInUs = legacy_scan_result.ts; |
| 663 | aidl_scan_result->ssid = std::vector<uint8_t>( |
| 664 | legacy_scan_result.ssid, |
| 665 | legacy_scan_result.ssid + |
| 666 | strnlen(legacy_scan_result.ssid, sizeof(legacy_scan_result.ssid) - 1)); |
| 667 | aidl_scan_result->bssid = std::array<uint8_t, 6>(); |
| 668 | std::copy(legacy_scan_result.bssid, legacy_scan_result.bssid + 6, |
| 669 | std::begin(aidl_scan_result->bssid)); |
| 670 | aidl_scan_result->frequency = legacy_scan_result.channel; |
| 671 | aidl_scan_result->rssi = legacy_scan_result.rssi; |
| 672 | aidl_scan_result->beaconPeriodInMs = legacy_scan_result.beacon_period; |
| 673 | aidl_scan_result->capability = legacy_scan_result.capability; |
| 674 | if (has_ie_data) { |
| 675 | std::vector<WifiInformationElement> ies; |
| 676 | if (!convertLegacyIeBlobToAidl(reinterpret_cast<const uint8_t*>(legacy_scan_result.ie_data), |
| 677 | legacy_scan_result.ie_length, &ies)) { |
| 678 | return false; |
| 679 | } |
| 680 | aidl_scan_result->informationElements = std::move(ies); |
| 681 | } |
| 682 | return true; |
| 683 | } |
| 684 | |
| 685 | bool convertLegacyCachedGscanResultsToAidl( |
| 686 | const legacy_hal::wifi_cached_scan_results& legacy_cached_scan_result, |
| 687 | StaScanData* aidl_scan_data) { |
| 688 | if (!aidl_scan_data) { |
| 689 | return false; |
| 690 | } |
| 691 | *aidl_scan_data = {}; |
| 692 | int32_t flags = 0; |
| 693 | for (const auto flag : {legacy_hal::WIFI_SCAN_FLAG_INTERRUPTED}) { |
| 694 | if (legacy_cached_scan_result.flags & flag) { |
| 695 | flags |= static_cast<std::underlying_type<StaScanDataFlagMask>::type>( |
| 696 | convertLegacyGscanDataFlagToAidl(flag)); |
| 697 | } |
| 698 | } |
| 699 | aidl_scan_data->flags = static_cast<StaScanDataFlagMask>(flags); |
| 700 | aidl_scan_data->bucketsScanned = legacy_cached_scan_result.buckets_scanned; |
| 701 | |
| 702 | CHECK(legacy_cached_scan_result.num_results >= 0 && |
| 703 | legacy_cached_scan_result.num_results <= MAX_AP_CACHE_PER_SCAN); |
| 704 | std::vector<StaScanResult> aidl_scan_results; |
| 705 | for (int32_t result_idx = 0; result_idx < legacy_cached_scan_result.num_results; result_idx++) { |
| 706 | StaScanResult aidl_scan_result; |
| 707 | if (!convertLegacyGscanResultToAidl(legacy_cached_scan_result.results[result_idx], false, |
| 708 | &aidl_scan_result)) { |
| 709 | return false; |
| 710 | } |
| 711 | aidl_scan_results.push_back(aidl_scan_result); |
| 712 | } |
| 713 | aidl_scan_data->results = std::move(aidl_scan_results); |
| 714 | return true; |
| 715 | } |
| 716 | |
| 717 | bool convertLegacyVectorOfCachedGscanResultsToAidl( |
| 718 | const std::vector<legacy_hal::wifi_cached_scan_results>& legacy_cached_scan_results, |
| 719 | std::vector<StaScanData>* aidl_scan_datas) { |
| 720 | if (!aidl_scan_datas) { |
| 721 | return false; |
| 722 | } |
| 723 | *aidl_scan_datas = {}; |
| 724 | for (const auto& legacy_cached_scan_result : legacy_cached_scan_results) { |
| 725 | StaScanData aidl_scan_data; |
| 726 | if (!convertLegacyCachedGscanResultsToAidl(legacy_cached_scan_result, &aidl_scan_data)) { |
| 727 | return false; |
| 728 | } |
| 729 | aidl_scan_datas->push_back(aidl_scan_data); |
| 730 | } |
| 731 | return true; |
| 732 | } |
| 733 | |
| 734 | WifiDebugTxPacketFate convertLegacyDebugTxPacketFateToAidl(legacy_hal::wifi_tx_packet_fate fate) { |
| 735 | switch (fate) { |
| 736 | case legacy_hal::TX_PKT_FATE_ACKED: |
| 737 | return WifiDebugTxPacketFate::ACKED; |
| 738 | case legacy_hal::TX_PKT_FATE_SENT: |
| 739 | return WifiDebugTxPacketFate::SENT; |
| 740 | case legacy_hal::TX_PKT_FATE_FW_QUEUED: |
| 741 | return WifiDebugTxPacketFate::FW_QUEUED; |
| 742 | case legacy_hal::TX_PKT_FATE_FW_DROP_INVALID: |
| 743 | return WifiDebugTxPacketFate::FW_DROP_INVALID; |
| 744 | case legacy_hal::TX_PKT_FATE_FW_DROP_NOBUFS: |
| 745 | return WifiDebugTxPacketFate::FW_DROP_NOBUFS; |
| 746 | case legacy_hal::TX_PKT_FATE_FW_DROP_OTHER: |
| 747 | return WifiDebugTxPacketFate::FW_DROP_OTHER; |
| 748 | case legacy_hal::TX_PKT_FATE_DRV_QUEUED: |
| 749 | return WifiDebugTxPacketFate::DRV_QUEUED; |
| 750 | case legacy_hal::TX_PKT_FATE_DRV_DROP_INVALID: |
| 751 | return WifiDebugTxPacketFate::DRV_DROP_INVALID; |
| 752 | case legacy_hal::TX_PKT_FATE_DRV_DROP_NOBUFS: |
| 753 | return WifiDebugTxPacketFate::DRV_DROP_NOBUFS; |
| 754 | case legacy_hal::TX_PKT_FATE_DRV_DROP_OTHER: |
| 755 | return WifiDebugTxPacketFate::DRV_DROP_OTHER; |
| 756 | }; |
| 757 | CHECK(false) << "Unknown legacy fate type: " << fate; |
| 758 | } |
| 759 | |
| 760 | WifiDebugRxPacketFate convertLegacyDebugRxPacketFateToAidl(legacy_hal::wifi_rx_packet_fate fate) { |
| 761 | switch (fate) { |
| 762 | case legacy_hal::RX_PKT_FATE_SUCCESS: |
| 763 | return WifiDebugRxPacketFate::SUCCESS; |
| 764 | case legacy_hal::RX_PKT_FATE_FW_QUEUED: |
| 765 | return WifiDebugRxPacketFate::FW_QUEUED; |
| 766 | case legacy_hal::RX_PKT_FATE_FW_DROP_FILTER: |
| 767 | return WifiDebugRxPacketFate::FW_DROP_FILTER; |
| 768 | case legacy_hal::RX_PKT_FATE_FW_DROP_INVALID: |
| 769 | return WifiDebugRxPacketFate::FW_DROP_INVALID; |
| 770 | case legacy_hal::RX_PKT_FATE_FW_DROP_NOBUFS: |
| 771 | return WifiDebugRxPacketFate::FW_DROP_NOBUFS; |
| 772 | case legacy_hal::RX_PKT_FATE_FW_DROP_OTHER: |
| 773 | return WifiDebugRxPacketFate::FW_DROP_OTHER; |
| 774 | case legacy_hal::RX_PKT_FATE_DRV_QUEUED: |
| 775 | return WifiDebugRxPacketFate::DRV_QUEUED; |
| 776 | case legacy_hal::RX_PKT_FATE_DRV_DROP_FILTER: |
| 777 | return WifiDebugRxPacketFate::DRV_DROP_FILTER; |
| 778 | case legacy_hal::RX_PKT_FATE_DRV_DROP_INVALID: |
| 779 | return WifiDebugRxPacketFate::DRV_DROP_INVALID; |
| 780 | case legacy_hal::RX_PKT_FATE_DRV_DROP_NOBUFS: |
| 781 | return WifiDebugRxPacketFate::DRV_DROP_NOBUFS; |
| 782 | case legacy_hal::RX_PKT_FATE_DRV_DROP_OTHER: |
| 783 | return WifiDebugRxPacketFate::DRV_DROP_OTHER; |
| 784 | }; |
| 785 | CHECK(false) << "Unknown legacy fate type: " << fate; |
| 786 | } |
| 787 | |
| 788 | WifiDebugPacketFateFrameType convertLegacyDebugPacketFateFrameTypeToAidl( |
| 789 | legacy_hal::frame_type type) { |
| 790 | switch (type) { |
| 791 | case legacy_hal::FRAME_TYPE_UNKNOWN: |
| 792 | return WifiDebugPacketFateFrameType::UNKNOWN; |
| 793 | case legacy_hal::FRAME_TYPE_ETHERNET_II: |
| 794 | return WifiDebugPacketFateFrameType::ETHERNET_II; |
| 795 | case legacy_hal::FRAME_TYPE_80211_MGMT: |
| 796 | return WifiDebugPacketFateFrameType::MGMT_80211; |
| 797 | }; |
| 798 | CHECK(false) << "Unknown legacy frame type: " << type; |
| 799 | } |
| 800 | |
| 801 | bool convertLegacyDebugPacketFateFrameToAidl(const legacy_hal::frame_info& legacy_frame, |
| 802 | WifiDebugPacketFateFrameInfo* aidl_frame) { |
| 803 | if (!aidl_frame) { |
| 804 | return false; |
| 805 | } |
| 806 | *aidl_frame = {}; |
| 807 | aidl_frame->frameType = convertLegacyDebugPacketFateFrameTypeToAidl(legacy_frame.payload_type); |
| 808 | aidl_frame->frameLen = legacy_frame.frame_len; |
| 809 | aidl_frame->driverTimestampUsec = legacy_frame.driver_timestamp_usec; |
| 810 | aidl_frame->firmwareTimestampUsec = legacy_frame.firmware_timestamp_usec; |
| 811 | const uint8_t* frame_begin = |
| 812 | reinterpret_cast<const uint8_t*>(legacy_frame.frame_content.ethernet_ii_bytes); |
| 813 | aidl_frame->frameContent = |
| 814 | std::vector<uint8_t>(frame_begin, frame_begin + legacy_frame.frame_len); |
| 815 | return true; |
| 816 | } |
| 817 | |
| 818 | bool convertLegacyDebugTxPacketFateToAidl(const legacy_hal::wifi_tx_report& legacy_fate, |
| 819 | WifiDebugTxPacketFateReport* aidl_fate) { |
| 820 | if (!aidl_fate) { |
| 821 | return false; |
| 822 | } |
| 823 | *aidl_fate = {}; |
| 824 | aidl_fate->fate = convertLegacyDebugTxPacketFateToAidl(legacy_fate.fate); |
| 825 | return convertLegacyDebugPacketFateFrameToAidl(legacy_fate.frame_inf, &aidl_fate->frameInfo); |
| 826 | } |
| 827 | |
| 828 | bool convertLegacyVectorOfDebugTxPacketFateToAidl( |
| 829 | const std::vector<legacy_hal::wifi_tx_report>& legacy_fates, |
| 830 | std::vector<WifiDebugTxPacketFateReport>* aidl_fates) { |
| 831 | if (!aidl_fates) { |
| 832 | return false; |
| 833 | } |
| 834 | *aidl_fates = {}; |
| 835 | for (const auto& legacy_fate : legacy_fates) { |
| 836 | WifiDebugTxPacketFateReport aidl_fate; |
| 837 | if (!convertLegacyDebugTxPacketFateToAidl(legacy_fate, &aidl_fate)) { |
| 838 | return false; |
| 839 | } |
| 840 | aidl_fates->push_back(aidl_fate); |
| 841 | } |
| 842 | return true; |
| 843 | } |
| 844 | |
| 845 | bool convertLegacyDebugRxPacketFateToAidl(const legacy_hal::wifi_rx_report& legacy_fate, |
| 846 | WifiDebugRxPacketFateReport* aidl_fate) { |
| 847 | if (!aidl_fate) { |
| 848 | return false; |
| 849 | } |
| 850 | *aidl_fate = {}; |
| 851 | aidl_fate->fate = convertLegacyDebugRxPacketFateToAidl(legacy_fate.fate); |
| 852 | return convertLegacyDebugPacketFateFrameToAidl(legacy_fate.frame_inf, &aidl_fate->frameInfo); |
| 853 | } |
| 854 | |
| 855 | bool convertLegacyVectorOfDebugRxPacketFateToAidl( |
| 856 | const std::vector<legacy_hal::wifi_rx_report>& legacy_fates, |
| 857 | std::vector<WifiDebugRxPacketFateReport>* aidl_fates) { |
| 858 | if (!aidl_fates) { |
| 859 | return false; |
| 860 | } |
| 861 | *aidl_fates = {}; |
| 862 | for (const auto& legacy_fate : legacy_fates) { |
| 863 | WifiDebugRxPacketFateReport aidl_fate; |
| 864 | if (!convertLegacyDebugRxPacketFateToAidl(legacy_fate, &aidl_fate)) { |
| 865 | return false; |
| 866 | } |
| 867 | aidl_fates->push_back(aidl_fate); |
| 868 | } |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | bool convertLegacyLinkLayerRadioStatsToAidl( |
| 873 | const legacy_hal::LinkLayerRadioStats& legacy_radio_stat, |
| 874 | StaLinkLayerRadioStats* aidl_radio_stat) { |
| 875 | if (!aidl_radio_stat) { |
| 876 | return false; |
| 877 | } |
| 878 | *aidl_radio_stat = {}; |
| 879 | |
| 880 | aidl_radio_stat->radioId = legacy_radio_stat.stats.radio; |
| 881 | aidl_radio_stat->onTimeInMs = legacy_radio_stat.stats.on_time; |
| 882 | aidl_radio_stat->txTimeInMs = legacy_radio_stat.stats.tx_time; |
| 883 | aidl_radio_stat->rxTimeInMs = legacy_radio_stat.stats.rx_time; |
| 884 | aidl_radio_stat->onTimeInMsForScan = legacy_radio_stat.stats.on_time_scan; |
| 885 | aidl_radio_stat->txTimeInMsPerLevel = uintToIntVec(legacy_radio_stat.tx_time_per_levels); |
| 886 | aidl_radio_stat->onTimeInMsForNanScan = legacy_radio_stat.stats.on_time_nbd; |
| 887 | aidl_radio_stat->onTimeInMsForBgScan = legacy_radio_stat.stats.on_time_gscan; |
| 888 | aidl_radio_stat->onTimeInMsForRoamScan = legacy_radio_stat.stats.on_time_roam_scan; |
| 889 | aidl_radio_stat->onTimeInMsForPnoScan = legacy_radio_stat.stats.on_time_pno_scan; |
| 890 | aidl_radio_stat->onTimeInMsForHs20Scan = legacy_radio_stat.stats.on_time_hs20; |
| 891 | |
| 892 | std::vector<WifiChannelStats> aidl_channel_stats; |
| 893 | |
| 894 | for (const auto& channel_stat : legacy_radio_stat.channel_stats) { |
| 895 | WifiChannelStats aidl_channel_stat; |
| 896 | aidl_channel_stat.onTimeInMs = channel_stat.on_time; |
| 897 | aidl_channel_stat.ccaBusyTimeInMs = channel_stat.cca_busy_time; |
| 898 | aidl_channel_stat.channel.width = WifiChannelWidthInMhz::WIDTH_20; |
| 899 | aidl_channel_stat.channel.centerFreq = channel_stat.channel.center_freq; |
| 900 | aidl_channel_stat.channel.centerFreq0 = channel_stat.channel.center_freq0; |
| 901 | aidl_channel_stat.channel.centerFreq1 = channel_stat.channel.center_freq1; |
| 902 | aidl_channel_stats.push_back(aidl_channel_stat); |
| 903 | } |
| 904 | |
| 905 | aidl_radio_stat->channelStats = aidl_channel_stats; |
| 906 | |
| 907 | return true; |
| 908 | } |
| 909 | |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 910 | bool convertLegacyLinkLayerMlStatsToAidl(const legacy_hal::LinkLayerMlStats& legacy_ml_stats, |
| 911 | StaLinkLayerStats* aidl_stats) { |
| 912 | if (!aidl_stats) { |
| 913 | return false; |
| 914 | } |
| 915 | *aidl_stats = {}; |
| 916 | std::vector<StaLinkLayerLinkStats> links; |
| 917 | // Iterate over each links |
| 918 | for (const auto& link : legacy_ml_stats.links) { |
| 919 | StaLinkLayerLinkStats linkStats = {}; |
| 920 | linkStats.linkId = link.stat.link_id; |
Mahesh KKV | 0da2997 | 2022-12-06 21:11:50 -0800 | [diff] [blame] | 921 | linkStats.radioId = link.stat.radio; |
| 922 | linkStats.frequencyMhz = link.stat.frequency; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 923 | linkStats.beaconRx = link.stat.beacon_rx; |
| 924 | linkStats.avgRssiMgmt = link.stat.rssi_mgmt; |
| 925 | linkStats.wmeBePktStats.rxMpdu = link.stat.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; |
| 926 | linkStats.wmeBePktStats.txMpdu = link.stat.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; |
| 927 | linkStats.wmeBePktStats.lostMpdu = link.stat.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; |
| 928 | linkStats.wmeBePktStats.retries = link.stat.ac[legacy_hal::WIFI_AC_BE].retries; |
| 929 | linkStats.wmeBeContentionTimeStats.contentionTimeMinInUsec = |
| 930 | link.stat.ac[legacy_hal::WIFI_AC_BE].contention_time_min; |
| 931 | linkStats.wmeBeContentionTimeStats.contentionTimeMaxInUsec = |
| 932 | link.stat.ac[legacy_hal::WIFI_AC_BE].contention_time_max; |
| 933 | linkStats.wmeBeContentionTimeStats.contentionTimeAvgInUsec = |
| 934 | link.stat.ac[legacy_hal::WIFI_AC_BE].contention_time_avg; |
| 935 | linkStats.wmeBeContentionTimeStats.contentionNumSamples = |
| 936 | link.stat.ac[legacy_hal::WIFI_AC_BE].contention_num_samples; |
| 937 | linkStats.wmeBkPktStats.rxMpdu = link.stat.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; |
| 938 | linkStats.wmeBkPktStats.txMpdu = link.stat.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; |
| 939 | linkStats.wmeBkPktStats.lostMpdu = link.stat.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; |
| 940 | linkStats.wmeBkPktStats.retries = link.stat.ac[legacy_hal::WIFI_AC_BK].retries; |
| 941 | linkStats.wmeBkContentionTimeStats.contentionTimeMinInUsec = |
| 942 | link.stat.ac[legacy_hal::WIFI_AC_BK].contention_time_min; |
| 943 | linkStats.wmeBkContentionTimeStats.contentionTimeMaxInUsec = |
| 944 | link.stat.ac[legacy_hal::WIFI_AC_BK].contention_time_max; |
| 945 | linkStats.wmeBkContentionTimeStats.contentionTimeAvgInUsec = |
| 946 | link.stat.ac[legacy_hal::WIFI_AC_BK].contention_time_avg; |
| 947 | linkStats.wmeBkContentionTimeStats.contentionNumSamples = |
| 948 | link.stat.ac[legacy_hal::WIFI_AC_BK].contention_num_samples; |
| 949 | linkStats.wmeViPktStats.rxMpdu = link.stat.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; |
| 950 | linkStats.wmeViPktStats.txMpdu = link.stat.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; |
| 951 | linkStats.wmeViPktStats.lostMpdu = link.stat.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; |
| 952 | linkStats.wmeViPktStats.retries = link.stat.ac[legacy_hal::WIFI_AC_VI].retries; |
| 953 | linkStats.wmeViContentionTimeStats.contentionTimeMinInUsec = |
| 954 | link.stat.ac[legacy_hal::WIFI_AC_VI].contention_time_min; |
| 955 | linkStats.wmeViContentionTimeStats.contentionTimeMaxInUsec = |
| 956 | link.stat.ac[legacy_hal::WIFI_AC_VI].contention_time_max; |
| 957 | linkStats.wmeViContentionTimeStats.contentionTimeAvgInUsec = |
| 958 | link.stat.ac[legacy_hal::WIFI_AC_VI].contention_time_avg; |
| 959 | linkStats.wmeViContentionTimeStats.contentionNumSamples = |
| 960 | link.stat.ac[legacy_hal::WIFI_AC_VI].contention_num_samples; |
| 961 | linkStats.wmeVoPktStats.rxMpdu = link.stat.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; |
| 962 | linkStats.wmeVoPktStats.txMpdu = link.stat.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; |
| 963 | linkStats.wmeVoPktStats.lostMpdu = link.stat.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; |
| 964 | linkStats.wmeVoPktStats.retries = link.stat.ac[legacy_hal::WIFI_AC_VO].retries; |
| 965 | linkStats.wmeVoContentionTimeStats.contentionTimeMinInUsec = |
| 966 | link.stat.ac[legacy_hal::WIFI_AC_VO].contention_time_min; |
| 967 | linkStats.wmeVoContentionTimeStats.contentionTimeMaxInUsec = |
| 968 | link.stat.ac[legacy_hal::WIFI_AC_VO].contention_time_max; |
| 969 | linkStats.wmeVoContentionTimeStats.contentionTimeAvgInUsec = |
| 970 | link.stat.ac[legacy_hal::WIFI_AC_VO].contention_time_avg; |
| 971 | linkStats.wmeVoContentionTimeStats.contentionNumSamples = |
| 972 | link.stat.ac[legacy_hal::WIFI_AC_VO].contention_num_samples; |
| 973 | linkStats.timeSliceDutyCycleInPercent = link.stat.time_slicing_duty_cycle_percent; |
| 974 | // peer info legacy_stats conversion. |
| 975 | std::vector<StaPeerInfo> aidl_peers_info_stats; |
| 976 | for (const auto& legacy_peer_info_stats : link.peers) { |
| 977 | StaPeerInfo aidl_peer_info_stats; |
| 978 | if (!convertLegacyPeerInfoStatsToAidl(legacy_peer_info_stats, &aidl_peer_info_stats)) { |
| 979 | return false; |
| 980 | } |
| 981 | aidl_peers_info_stats.push_back(aidl_peer_info_stats); |
| 982 | } |
| 983 | linkStats.peers = aidl_peers_info_stats; |
| 984 | // Push link stats to aidl stats. |
| 985 | links.push_back(linkStats); |
| 986 | } |
| 987 | aidl_stats->iface.links = links; |
| 988 | // radio legacy_stats conversion. |
| 989 | std::vector<StaLinkLayerRadioStats> aidl_radios_stats; |
| 990 | for (const auto& legacy_radio_stats : legacy_ml_stats.radios) { |
| 991 | StaLinkLayerRadioStats aidl_radio_stats; |
| 992 | if (!convertLegacyLinkLayerRadioStatsToAidl(legacy_radio_stats, &aidl_radio_stats)) { |
| 993 | return false; |
| 994 | } |
| 995 | aidl_radios_stats.push_back(aidl_radio_stats); |
| 996 | } |
| 997 | aidl_stats->radios = aidl_radios_stats; |
| 998 | aidl_stats->timeStampInMs = ::android::uptimeMillis(); |
| 999 | |
| 1000 | return true; |
| 1001 | } |
| 1002 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1003 | bool convertLegacyLinkLayerStatsToAidl(const legacy_hal::LinkLayerStats& legacy_stats, |
| 1004 | StaLinkLayerStats* aidl_stats) { |
| 1005 | if (!aidl_stats) { |
| 1006 | return false; |
| 1007 | } |
| 1008 | *aidl_stats = {}; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1009 | std::vector<StaLinkLayerLinkStats> links; |
| 1010 | StaLinkLayerLinkStats linkStats = {}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1011 | // iface legacy_stats conversion. |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1012 | linkStats.linkId = 0; |
| 1013 | linkStats.beaconRx = legacy_stats.iface.beacon_rx; |
| 1014 | linkStats.avgRssiMgmt = legacy_stats.iface.rssi_mgmt; |
| 1015 | linkStats.wmeBePktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu; |
| 1016 | linkStats.wmeBePktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu; |
| 1017 | linkStats.wmeBePktStats.lostMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost; |
| 1018 | linkStats.wmeBePktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries; |
| 1019 | linkStats.wmeBeContentionTimeStats.contentionTimeMinInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1020 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_min; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1021 | linkStats.wmeBeContentionTimeStats.contentionTimeMaxInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1022 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_max; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1023 | linkStats.wmeBeContentionTimeStats.contentionTimeAvgInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1024 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_time_avg; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1025 | linkStats.wmeBeContentionTimeStats.contentionNumSamples = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1026 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].contention_num_samples; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1027 | linkStats.wmeBkPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu; |
| 1028 | linkStats.wmeBkPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu; |
| 1029 | linkStats.wmeBkPktStats.lostMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost; |
| 1030 | linkStats.wmeBkPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries; |
| 1031 | linkStats.wmeBkContentionTimeStats.contentionTimeMinInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1032 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_min; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1033 | linkStats.wmeBkContentionTimeStats.contentionTimeMaxInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1034 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_max; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1035 | linkStats.wmeBkContentionTimeStats.contentionTimeAvgInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1036 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_time_avg; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1037 | linkStats.wmeBkContentionTimeStats.contentionNumSamples = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1038 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].contention_num_samples; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1039 | linkStats.wmeViPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu; |
| 1040 | linkStats.wmeViPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu; |
| 1041 | linkStats.wmeViPktStats.lostMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost; |
| 1042 | linkStats.wmeViPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries; |
| 1043 | linkStats.wmeViContentionTimeStats.contentionTimeMinInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1044 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_min; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1045 | linkStats.wmeViContentionTimeStats.contentionTimeMaxInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1046 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_max; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1047 | linkStats.wmeViContentionTimeStats.contentionTimeAvgInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1048 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_time_avg; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1049 | linkStats.wmeViContentionTimeStats.contentionNumSamples = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1050 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].contention_num_samples; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1051 | linkStats.wmeVoPktStats.rxMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu; |
| 1052 | linkStats.wmeVoPktStats.txMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu; |
| 1053 | linkStats.wmeVoPktStats.lostMpdu = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost; |
| 1054 | linkStats.wmeVoPktStats.retries = legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries; |
| 1055 | linkStats.wmeVoContentionTimeStats.contentionTimeMinInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1056 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_min; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1057 | linkStats.wmeVoContentionTimeStats.contentionTimeMaxInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1058 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_max; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1059 | linkStats.wmeVoContentionTimeStats.contentionTimeAvgInUsec = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1060 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_time_avg; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1061 | linkStats.wmeVoContentionTimeStats.contentionNumSamples = |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1062 | legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].contention_num_samples; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1063 | linkStats.timeSliceDutyCycleInPercent = legacy_stats.iface.info.time_slicing_duty_cycle_percent; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1064 | // peer info legacy_stats conversion. |
| 1065 | std::vector<StaPeerInfo> aidl_peers_info_stats; |
| 1066 | for (const auto& legacy_peer_info_stats : legacy_stats.peers) { |
| 1067 | StaPeerInfo aidl_peer_info_stats; |
| 1068 | if (!convertLegacyPeerInfoStatsToAidl(legacy_peer_info_stats, &aidl_peer_info_stats)) { |
| 1069 | return false; |
| 1070 | } |
| 1071 | aidl_peers_info_stats.push_back(aidl_peer_info_stats); |
| 1072 | } |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 1073 | linkStats.peers = aidl_peers_info_stats; |
| 1074 | links.push_back(linkStats); |
| 1075 | aidl_stats->iface.links = links; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1076 | // radio legacy_stats conversion. |
| 1077 | std::vector<StaLinkLayerRadioStats> aidl_radios_stats; |
| 1078 | for (const auto& legacy_radio_stats : legacy_stats.radios) { |
| 1079 | StaLinkLayerRadioStats aidl_radio_stats; |
| 1080 | if (!convertLegacyLinkLayerRadioStatsToAidl(legacy_radio_stats, &aidl_radio_stats)) { |
| 1081 | return false; |
| 1082 | } |
| 1083 | aidl_radios_stats.push_back(aidl_radio_stats); |
| 1084 | } |
| 1085 | aidl_stats->radios = aidl_radios_stats; |
| 1086 | aidl_stats->timeStampInMs = ::android::uptimeMillis(); |
| 1087 | return true; |
| 1088 | } |
| 1089 | |
| 1090 | bool convertLegacyPeerInfoStatsToAidl(const legacy_hal::WifiPeerInfo& legacy_peer_info_stats, |
| 1091 | StaPeerInfo* aidl_peer_info_stats) { |
| 1092 | if (!aidl_peer_info_stats) { |
| 1093 | return false; |
| 1094 | } |
| 1095 | *aidl_peer_info_stats = {}; |
| 1096 | aidl_peer_info_stats->staCount = legacy_peer_info_stats.peer_info.bssload.sta_count; |
| 1097 | aidl_peer_info_stats->chanUtil = legacy_peer_info_stats.peer_info.bssload.chan_util; |
| 1098 | |
| 1099 | std::vector<StaRateStat> aidlRateStats; |
| 1100 | for (const auto& legacy_rate_stats : legacy_peer_info_stats.rate_stats) { |
| 1101 | StaRateStat rateStat; |
| 1102 | if (!convertLegacyWifiRateInfoToAidl(legacy_rate_stats.rate, &rateStat.rateInfo)) { |
| 1103 | return false; |
| 1104 | } |
| 1105 | rateStat.txMpdu = legacy_rate_stats.tx_mpdu; |
| 1106 | rateStat.rxMpdu = legacy_rate_stats.rx_mpdu; |
| 1107 | rateStat.mpduLost = legacy_rate_stats.mpdu_lost; |
| 1108 | rateStat.retries = legacy_rate_stats.retries; |
| 1109 | aidlRateStats.push_back(rateStat); |
| 1110 | } |
| 1111 | aidl_peer_info_stats->rateStats = aidlRateStats; |
| 1112 | return true; |
| 1113 | } |
| 1114 | |
| 1115 | bool convertLegacyRoamingCapabilitiesToAidl( |
| 1116 | const legacy_hal::wifi_roaming_capabilities& legacy_caps, |
| 1117 | StaRoamingCapabilities* aidl_caps) { |
| 1118 | if (!aidl_caps) { |
| 1119 | return false; |
| 1120 | } |
| 1121 | *aidl_caps = {}; |
| 1122 | aidl_caps->maxBlocklistSize = legacy_caps.max_blacklist_size; |
| 1123 | aidl_caps->maxAllowlistSize = legacy_caps.max_whitelist_size; |
| 1124 | return true; |
| 1125 | } |
| 1126 | |
| 1127 | bool convertAidlRoamingConfigToLegacy(const StaRoamingConfig& aidl_config, |
| 1128 | legacy_hal::wifi_roaming_config* legacy_config) { |
| 1129 | if (!legacy_config) { |
| 1130 | return false; |
| 1131 | } |
| 1132 | *legacy_config = {}; |
| 1133 | if (aidl_config.bssidBlocklist.size() > MAX_BLACKLIST_BSSID || |
| 1134 | aidl_config.ssidAllowlist.size() > MAX_WHITELIST_SSID) { |
| 1135 | return false; |
| 1136 | } |
| 1137 | legacy_config->num_blacklist_bssid = aidl_config.bssidBlocklist.size(); |
| 1138 | uint32_t i = 0; |
| 1139 | for (const auto& bssid : aidl_config.bssidBlocklist) { |
| 1140 | CHECK(bssid.data.size() == sizeof(legacy_hal::mac_addr)); |
| 1141 | memcpy(legacy_config->blacklist_bssid[i++], bssid.data.data(), bssid.data.size()); |
| 1142 | } |
| 1143 | legacy_config->num_whitelist_ssid = aidl_config.ssidAllowlist.size(); |
| 1144 | i = 0; |
| 1145 | for (const auto& ssid : aidl_config.ssidAllowlist) { |
| 1146 | CHECK(ssid.data.size() <= sizeof(legacy_hal::ssid_t::ssid_str)); |
| 1147 | legacy_config->whitelist_ssid[i].length = ssid.data.size(); |
| 1148 | memcpy(legacy_config->whitelist_ssid[i].ssid_str, ssid.data.data(), ssid.data.size()); |
| 1149 | i++; |
| 1150 | } |
| 1151 | return true; |
| 1152 | } |
| 1153 | |
| 1154 | legacy_hal::fw_roaming_state_t convertAidlRoamingStateToLegacy(StaRoamingState state) { |
| 1155 | switch (state) { |
| 1156 | case StaRoamingState::ENABLED: |
| 1157 | return legacy_hal::ROAMING_ENABLE; |
| 1158 | case StaRoamingState::DISABLED: |
| 1159 | return legacy_hal::ROAMING_DISABLE; |
| 1160 | }; |
| 1161 | CHECK(false); |
| 1162 | } |
| 1163 | |
| 1164 | legacy_hal::NanMatchAlg convertAidlNanMatchAlgToLegacy(NanMatchAlg type) { |
| 1165 | switch (type) { |
| 1166 | case NanMatchAlg::MATCH_ONCE: |
| 1167 | return legacy_hal::NAN_MATCH_ALG_MATCH_ONCE; |
| 1168 | case NanMatchAlg::MATCH_CONTINUOUS: |
| 1169 | return legacy_hal::NAN_MATCH_ALG_MATCH_CONTINUOUS; |
| 1170 | case NanMatchAlg::MATCH_NEVER: |
| 1171 | return legacy_hal::NAN_MATCH_ALG_MATCH_NEVER; |
| 1172 | } |
| 1173 | CHECK(false); |
| 1174 | } |
| 1175 | |
| 1176 | legacy_hal::NanPublishType convertAidlNanPublishTypeToLegacy(NanPublishType type) { |
| 1177 | switch (type) { |
| 1178 | case NanPublishType::UNSOLICITED: |
| 1179 | return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED; |
| 1180 | case NanPublishType::SOLICITED: |
| 1181 | return legacy_hal::NAN_PUBLISH_TYPE_SOLICITED; |
| 1182 | case NanPublishType::UNSOLICITED_SOLICITED: |
| 1183 | return legacy_hal::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED; |
| 1184 | } |
| 1185 | CHECK(false); |
| 1186 | } |
| 1187 | |
| 1188 | legacy_hal::NanTxType convertAidlNanTxTypeToLegacy(NanTxType type) { |
| 1189 | switch (type) { |
| 1190 | case NanTxType::BROADCAST: |
| 1191 | return legacy_hal::NAN_TX_TYPE_BROADCAST; |
| 1192 | case NanTxType::UNICAST: |
| 1193 | return legacy_hal::NAN_TX_TYPE_UNICAST; |
| 1194 | } |
| 1195 | CHECK(false); |
| 1196 | } |
| 1197 | |
| 1198 | legacy_hal::NanSubscribeType convertAidlNanSubscribeTypeToLegacy(NanSubscribeType type) { |
| 1199 | switch (type) { |
| 1200 | case NanSubscribeType::PASSIVE: |
| 1201 | return legacy_hal::NAN_SUBSCRIBE_TYPE_PASSIVE; |
| 1202 | case NanSubscribeType::ACTIVE: |
| 1203 | return legacy_hal::NAN_SUBSCRIBE_TYPE_ACTIVE; |
| 1204 | } |
| 1205 | CHECK(false); |
| 1206 | } |
| 1207 | |
| 1208 | legacy_hal::NanSRFType convertAidlNanSrfTypeToLegacy(NanSrfType type) { |
| 1209 | switch (type) { |
| 1210 | case NanSrfType::BLOOM_FILTER: |
| 1211 | return legacy_hal::NAN_SRF_ATTR_BLOOM_FILTER; |
| 1212 | case NanSrfType::PARTIAL_MAC_ADDR: |
| 1213 | return legacy_hal::NAN_SRF_ATTR_PARTIAL_MAC_ADDR; |
| 1214 | } |
| 1215 | CHECK(false); |
| 1216 | } |
| 1217 | |
| 1218 | legacy_hal::NanDataPathChannelCfg convertAidlNanDataPathChannelCfgToLegacy( |
| 1219 | NanDataPathChannelCfg type) { |
| 1220 | switch (type) { |
| 1221 | case NanDataPathChannelCfg::CHANNEL_NOT_REQUESTED: |
| 1222 | return legacy_hal::NAN_DP_CHANNEL_NOT_REQUESTED; |
| 1223 | case NanDataPathChannelCfg::REQUEST_CHANNEL_SETUP: |
| 1224 | return legacy_hal::NAN_DP_REQUEST_CHANNEL_SETUP; |
| 1225 | case NanDataPathChannelCfg::FORCE_CHANNEL_SETUP: |
| 1226 | return legacy_hal::NAN_DP_FORCE_CHANNEL_SETUP; |
| 1227 | } |
| 1228 | CHECK(false); |
| 1229 | } |
| 1230 | |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1231 | legacy_hal::NanPairingRequestType convertAidlNanPairingRequestTypeToLegacy( |
| 1232 | NanPairingRequestType type) { |
| 1233 | switch (type) { |
| 1234 | case NanPairingRequestType::NAN_PAIRING_SETUP: |
| 1235 | return legacy_hal::NAN_PAIRING_SETUP; |
| 1236 | case NanPairingRequestType::NAN_PAIRING_VERIFICATION: |
| 1237 | return legacy_hal::NAN_PAIRING_VERIFICATION; |
| 1238 | } |
| 1239 | LOG(FATAL); |
| 1240 | } |
| 1241 | |
| 1242 | NanPairingRequestType convertLegacyNanPairingRequestTypeToAidl( |
| 1243 | legacy_hal::NanPairingRequestType type) { |
| 1244 | switch (type) { |
| 1245 | case legacy_hal::NAN_PAIRING_SETUP: |
| 1246 | return NanPairingRequestType::NAN_PAIRING_SETUP; |
| 1247 | case legacy_hal::NAN_PAIRING_VERIFICATION: |
| 1248 | return NanPairingRequestType::NAN_PAIRING_VERIFICATION; |
| 1249 | } |
| 1250 | LOG(FATAL); |
| 1251 | } |
| 1252 | |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 1253 | legacy_hal::NanAkm convertAidlAkmTypeToLegacy(NanPairingAkm type) { |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1254 | switch (type) { |
| 1255 | case NanPairingAkm::SAE: |
| 1256 | return legacy_hal::SAE; |
| 1257 | case NanPairingAkm::PASN: |
| 1258 | return legacy_hal::PASN; |
| 1259 | } |
| 1260 | LOG(FATAL); |
| 1261 | } |
| 1262 | |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 1263 | NanPairingAkm convertLegacyAkmTypeToAidl(legacy_hal::NanAkm type) { |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1264 | switch (type) { |
| 1265 | case legacy_hal::SAE: |
| 1266 | return NanPairingAkm::SAE; |
| 1267 | case legacy_hal::PASN: |
| 1268 | return NanPairingAkm::PASN; |
| 1269 | } |
| 1270 | LOG(FATAL); |
| 1271 | } |
| 1272 | |
| 1273 | uint16_t convertAidlBootstrappingMethodToLegacy(NanBootstrappingMethod type) { |
| 1274 | switch (type) { |
| 1275 | case NanBootstrappingMethod::BOOTSTRAPPING_OPPORTUNISTIC_MASK: |
| 1276 | return NAN_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_MASK; |
| 1277 | case NanBootstrappingMethod::BOOTSTRAPPING_PIN_CODE_DISPLAY_MASK: |
| 1278 | return NAN_PAIRING_BOOTSTRAPPING_PIN_CODE_DISPLAY_MASK; |
| 1279 | case NanBootstrappingMethod::BOOTSTRAPPING_PASSPHRASE_DISPLAY_MASK: |
| 1280 | return NAN_PAIRING_BOOTSTRAPPING_PASSPHRASE_DISPLAY_MASK; |
| 1281 | case NanBootstrappingMethod::BOOTSTRAPPING_QR_DISPLAY_MASK: |
| 1282 | return NAN_PAIRING_BOOTSTRAPPING_QR_DISPLAY_MASK; |
| 1283 | case NanBootstrappingMethod::BOOTSTRAPPING_NFC_TAG_MASK: |
| 1284 | return NAN_PAIRING_BOOTSTRAPPING_NFC_TAG_MASK; |
| 1285 | case NanBootstrappingMethod::BOOTSTRAPPING_PIN_CODE_KEYPAD_MASK: |
| 1286 | return NAN_PAIRING_BOOTSTRAPPING_PIN_CODE_KEYPAD_MASK; |
| 1287 | case NanBootstrappingMethod::BOOTSTRAPPING_PASSPHRASE_KEYPAD_MASK: |
| 1288 | return NAN_PAIRING_BOOTSTRAPPING_PASSPHRASE_KEYPAD_MASK; |
| 1289 | case NanBootstrappingMethod::BOOTSTRAPPING_QR_SCAN_MASK: |
| 1290 | return NAN_PAIRING_BOOTSTRAPPING_QR_SCAN_MASK; |
| 1291 | case NanBootstrappingMethod::BOOTSTRAPPING_NFC_READER_MASK: |
| 1292 | return NAN_PAIRING_BOOTSTRAPPING_NFC_READER_MASK; |
| 1293 | case NanBootstrappingMethod::BOOTSTRAPPING_SERVICE_MANAGED_MASK: |
| 1294 | return NAN_PAIRING_BOOTSTRAPPING_SERVICE_MANAGED_MASK; |
| 1295 | case NanBootstrappingMethod::BOOTSTRAPPING_HANDSHAKE_SHIP_MASK: |
| 1296 | return NAN_PAIRING_BOOTSTRAPPING_HANDSHAKE_SHIP_MASK; |
| 1297 | } |
| 1298 | LOG(FATAL); |
| 1299 | } |
| 1300 | |
| 1301 | NanBootstrappingMethod convertLegacyBootstrappingMethodToAidl(uint16_t type) { |
| 1302 | switch (type) { |
| 1303 | case NAN_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_MASK: |
| 1304 | return NanBootstrappingMethod::BOOTSTRAPPING_OPPORTUNISTIC_MASK; |
| 1305 | case NAN_PAIRING_BOOTSTRAPPING_PIN_CODE_DISPLAY_MASK: |
| 1306 | return NanBootstrappingMethod::BOOTSTRAPPING_PIN_CODE_DISPLAY_MASK; |
| 1307 | case NAN_PAIRING_BOOTSTRAPPING_PASSPHRASE_DISPLAY_MASK: |
| 1308 | return NanBootstrappingMethod::BOOTSTRAPPING_PASSPHRASE_DISPLAY_MASK; |
| 1309 | case NAN_PAIRING_BOOTSTRAPPING_QR_DISPLAY_MASK: |
| 1310 | return NanBootstrappingMethod::BOOTSTRAPPING_QR_DISPLAY_MASK; |
| 1311 | case NAN_PAIRING_BOOTSTRAPPING_NFC_TAG_MASK: |
| 1312 | return NanBootstrappingMethod::BOOTSTRAPPING_NFC_TAG_MASK; |
| 1313 | case NAN_PAIRING_BOOTSTRAPPING_PIN_CODE_KEYPAD_MASK: |
| 1314 | return NanBootstrappingMethod::BOOTSTRAPPING_PIN_CODE_KEYPAD_MASK; |
| 1315 | case NAN_PAIRING_BOOTSTRAPPING_PASSPHRASE_KEYPAD_MASK: |
| 1316 | return NanBootstrappingMethod::BOOTSTRAPPING_PASSPHRASE_KEYPAD_MASK; |
| 1317 | case NAN_PAIRING_BOOTSTRAPPING_QR_SCAN_MASK: |
| 1318 | return NanBootstrappingMethod::BOOTSTRAPPING_QR_SCAN_MASK; |
| 1319 | case NAN_PAIRING_BOOTSTRAPPING_NFC_READER_MASK: |
| 1320 | return NanBootstrappingMethod::BOOTSTRAPPING_NFC_READER_MASK; |
| 1321 | case NAN_PAIRING_BOOTSTRAPPING_SERVICE_MANAGED_MASK: |
| 1322 | return NanBootstrappingMethod::BOOTSTRAPPING_SERVICE_MANAGED_MASK; |
| 1323 | case NAN_PAIRING_BOOTSTRAPPING_HANDSHAKE_SHIP_MASK: |
| 1324 | return NanBootstrappingMethod::BOOTSTRAPPING_HANDSHAKE_SHIP_MASK; |
| 1325 | } |
| 1326 | LOG(FATAL); |
| 1327 | return {}; |
| 1328 | } |
| 1329 | |
| 1330 | bool covertAidlPairingConfigToLegacy(const NanPairingConfig& aidl_config, |
| 1331 | legacy_hal::NanPairingConfig* legacy_config) { |
| 1332 | if (!legacy_config) { |
| 1333 | LOG(ERROR) << "covertAidlPairingConfigToLegacy: legacy_config is null"; |
| 1334 | return false; |
| 1335 | } |
| 1336 | legacy_config->enable_pairing_setup = aidl_config.enablePairingSetup ? 0x1 : 0x0; |
| 1337 | legacy_config->enable_pairing_cache = aidl_config.enablePairingCache ? 0x1 : 0x0; |
| 1338 | legacy_config->enable_pairing_verification = aidl_config.enablePairingVerification ? 0x1 : 0x0; |
| 1339 | legacy_config->supported_bootstrapping_methods = aidl_config.supportedBootstrappingMethods; |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | bool convertLegacyPairingConfigToAidl(const legacy_hal::NanPairingConfig& legacy_config, |
| 1344 | NanPairingConfig* aidl_config) { |
| 1345 | if (!aidl_config) { |
| 1346 | LOG(ERROR) << "convertLegacyPairingConfigToAidl: aidl_nira is null"; |
| 1347 | return false; |
| 1348 | } |
| 1349 | *aidl_config = {}; |
| 1350 | aidl_config->enablePairingSetup = legacy_config.enable_pairing_setup == 0x1; |
| 1351 | aidl_config->enablePairingCache = legacy_config.enable_pairing_cache == 0x1; |
| 1352 | aidl_config->enablePairingVerification = legacy_config.enable_pairing_verification == 0x1; |
| 1353 | aidl_config->supportedBootstrappingMethods = legacy_config.supported_bootstrapping_methods; |
| 1354 | return true; |
| 1355 | } |
| 1356 | |
| 1357 | bool convertLegacyNiraToAidl(const legacy_hal::NanIdentityResolutionAttribute& legacy_nira, |
| 1358 | NanIdentityResolutionAttribute* aidl_nira) { |
| 1359 | if (!aidl_nira) { |
| 1360 | LOG(ERROR) << "convertLegacyNiraToAidl: aidl_nira is null"; |
| 1361 | return false; |
| 1362 | } |
| 1363 | *aidl_nira = {}; |
| 1364 | aidl_nira->nonce = std::array<uint8_t, 8>(); |
| 1365 | std::copy(legacy_nira.nonce, legacy_nira.nonce + 8, std::begin(aidl_nira->nonce)); |
| 1366 | aidl_nira->tag = std::array<uint8_t, 8>(); |
| 1367 | std::copy(legacy_nira.tag, legacy_nira.tag + 8, std::begin(aidl_nira->tag)); |
| 1368 | return true; |
| 1369 | } |
| 1370 | |
| 1371 | bool convertLegacyNpsaToAidl(const legacy_hal::NpkSecurityAssociation& legacy_npsa, |
| 1372 | NpkSecurityAssociation* aidl_npsa) { |
| 1373 | if (!aidl_npsa) { |
| 1374 | LOG(ERROR) << "convertLegacyNiraToAidl: aidl_nira is null"; |
| 1375 | return false; |
| 1376 | } |
| 1377 | *aidl_npsa = {}; |
| 1378 | aidl_npsa->peerNanIdentityKey = std::array<uint8_t, 16>(); |
| 1379 | std::copy(legacy_npsa.peer_nan_identity_key, legacy_npsa.peer_nan_identity_key + 16, |
| 1380 | std::begin(aidl_npsa->peerNanIdentityKey)); |
| 1381 | aidl_npsa->localNanIdentityKey = std::array<uint8_t, 16>(); |
| 1382 | std::copy(legacy_npsa.local_nan_identity_key, legacy_npsa.local_nan_identity_key + 16, |
| 1383 | std::begin(aidl_npsa->localNanIdentityKey)); |
| 1384 | aidl_npsa->npk = std::array<uint8_t, 32>(); |
| 1385 | std::copy(legacy_npsa.npk.pmk, legacy_npsa.npk.pmk + 32, std::begin(aidl_npsa->npk)); |
| 1386 | aidl_npsa->akm = convertLegacyAkmTypeToAidl(legacy_npsa.akm); |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 1387 | aidl_npsa->cipherType = (NanCipherSuiteType)legacy_npsa.cipher_type; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1388 | return true; |
| 1389 | } |
| 1390 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1391 | NanStatusCode convertLegacyNanStatusTypeToAidl(legacy_hal::NanStatusType type) { |
| 1392 | switch (type) { |
| 1393 | case legacy_hal::NAN_STATUS_SUCCESS: |
| 1394 | return NanStatusCode::SUCCESS; |
| 1395 | case legacy_hal::NAN_STATUS_INTERNAL_FAILURE: |
| 1396 | return NanStatusCode::INTERNAL_FAILURE; |
| 1397 | case legacy_hal::NAN_STATUS_PROTOCOL_FAILURE: |
| 1398 | return NanStatusCode::PROTOCOL_FAILURE; |
| 1399 | case legacy_hal::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID: |
| 1400 | return NanStatusCode::INVALID_SESSION_ID; |
| 1401 | case legacy_hal::NAN_STATUS_NO_RESOURCE_AVAILABLE: |
| 1402 | return NanStatusCode::NO_RESOURCES_AVAILABLE; |
| 1403 | case legacy_hal::NAN_STATUS_INVALID_PARAM: |
| 1404 | return NanStatusCode::INVALID_ARGS; |
| 1405 | case legacy_hal::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID: |
| 1406 | return NanStatusCode::INVALID_PEER_ID; |
| 1407 | case legacy_hal::NAN_STATUS_INVALID_NDP_ID: |
| 1408 | return NanStatusCode::INVALID_NDP_ID; |
| 1409 | case legacy_hal::NAN_STATUS_NAN_NOT_ALLOWED: |
| 1410 | return NanStatusCode::NAN_NOT_ALLOWED; |
| 1411 | case legacy_hal::NAN_STATUS_NO_OTA_ACK: |
| 1412 | return NanStatusCode::NO_OTA_ACK; |
| 1413 | case legacy_hal::NAN_STATUS_ALREADY_ENABLED: |
| 1414 | return NanStatusCode::ALREADY_ENABLED; |
| 1415 | case legacy_hal::NAN_STATUS_FOLLOWUP_QUEUE_FULL: |
| 1416 | return NanStatusCode::FOLLOWUP_TX_QUEUE_FULL; |
| 1417 | case legacy_hal::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED: |
| 1418 | return NanStatusCode::UNSUPPORTED_CONCURRENCY_NAN_DISABLED; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1419 | case legacy_hal::NAN_STATUS_INVALID_PAIRING_ID: |
| 1420 | return NanStatusCode::INVALID_PAIRING_ID; |
| 1421 | case legacy_hal::NAN_STATUS_INVALID_BOOTSTRAPPING_ID: |
| 1422 | return NanStatusCode::INVALID_BOOTSTRAPPING_ID; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1423 | } |
| 1424 | CHECK(false); |
| 1425 | } |
| 1426 | |
| 1427 | void convertToNanStatus(legacy_hal::NanStatusType type, const char* str, size_t max_len, |
| 1428 | NanStatus* nanStatus) { |
| 1429 | nanStatus->status = convertLegacyNanStatusTypeToAidl(type); |
| 1430 | nanStatus->description = safeConvertChar(str, max_len); |
| 1431 | } |
| 1432 | |
| 1433 | bool convertAidlNanEnableRequestToLegacy(const NanEnableRequest& aidl_request1, |
| 1434 | const NanConfigRequestSupplemental& aidl_request2, |
| 1435 | legacy_hal::NanEnableRequest* legacy_request) { |
| 1436 | if (!legacy_request) { |
| 1437 | LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: null legacy_request"; |
| 1438 | return false; |
| 1439 | } |
| 1440 | *legacy_request = {}; |
| 1441 | |
| 1442 | legacy_request->config_2dot4g_support = 1; |
| 1443 | legacy_request->support_2dot4g_val = |
| 1444 | aidl_request1.operateInBand[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1445 | legacy_request->config_support_5g = 1; |
| 1446 | legacy_request->support_5g_val = |
| 1447 | aidl_request1.operateInBand[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1448 | legacy_request->config_hop_count_limit = 1; |
| 1449 | legacy_request->hop_count_limit_val = aidl_request1.hopCountMax; |
| 1450 | legacy_request->master_pref = aidl_request1.configParams.masterPref; |
| 1451 | legacy_request->discovery_indication_cfg = 0; |
| 1452 | legacy_request->discovery_indication_cfg |= |
| 1453 | aidl_request1.configParams.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; |
| 1454 | legacy_request->discovery_indication_cfg |= |
| 1455 | aidl_request1.configParams.disableStartedClusterIndication ? 0x2 : 0x0; |
| 1456 | legacy_request->discovery_indication_cfg |= |
| 1457 | aidl_request1.configParams.disableJoinedClusterIndication ? 0x4 : 0x0; |
| 1458 | legacy_request->config_sid_beacon = 1; |
| 1459 | if (aidl_request1.configParams.numberOfPublishServiceIdsInBeacon < 0) { |
| 1460 | LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " |
| 1461 | "numberOfPublishServiceIdsInBeacon < 0"; |
| 1462 | return false; |
| 1463 | } |
| 1464 | legacy_request->sid_beacon_val = |
| 1465 | (aidl_request1.configParams.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1466 | (aidl_request1.configParams.numberOfPublishServiceIdsInBeacon << 1); |
| 1467 | legacy_request->config_subscribe_sid_beacon = 1; |
| 1468 | if (aidl_request1.configParams.numberOfSubscribeServiceIdsInBeacon < 0) { |
| 1469 | LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " |
| 1470 | "numberOfSubscribeServiceIdsInBeacon < 0"; |
| 1471 | return false; |
| 1472 | } |
| 1473 | legacy_request->subscribe_sid_beacon_val = |
| 1474 | (aidl_request1.configParams.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1475 | (aidl_request1.configParams.numberOfSubscribeServiceIdsInBeacon << 1); |
| 1476 | legacy_request->config_rssi_window_size = 1; |
| 1477 | legacy_request->rssi_window_size_val = aidl_request1.configParams.rssiWindowSize; |
| 1478 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 1479 | legacy_request->disc_mac_addr_rand_interval_sec = |
| 1480 | aidl_request1.configParams.macAddressRandomizationIntervalSec; |
| 1481 | legacy_request->config_2dot4g_rssi_close = 1; |
| 1482 | if (aidl_request1.configParams.bandSpecificConfig.size() != 3) { |
| 1483 | LOG(ERROR) << "convertAidlNanEnableRequestToLegacy: " |
| 1484 | "bandSpecificConfig.size() != 3"; |
| 1485 | return false; |
| 1486 | } |
| 1487 | legacy_request->rssi_close_2dot4g_val = |
| 1488 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1489 | .rssiClose; |
| 1490 | legacy_request->config_2dot4g_rssi_middle = 1; |
| 1491 | legacy_request->rssi_middle_2dot4g_val = |
| 1492 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1493 | .rssiMiddle; |
| 1494 | legacy_request->config_2dot4g_rssi_proximity = 1; |
| 1495 | legacy_request->rssi_proximity_2dot4g_val = |
| 1496 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1497 | .rssiCloseProximity; |
| 1498 | legacy_request->config_scan_params = 1; |
| 1499 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1500 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1501 | .dwellTimeMs; |
| 1502 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1503 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1504 | .scanPeriodSec; |
| 1505 | legacy_request->config_dw.config_2dot4g_dw_band = |
| 1506 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1507 | .validDiscoveryWindowIntervalVal; |
| 1508 | legacy_request->config_dw.dw_2dot4g_interval_val = |
| 1509 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1510 | .discoveryWindowIntervalVal; |
| 1511 | legacy_request->config_5g_rssi_close = 1; |
| 1512 | legacy_request->rssi_close_5g_val = |
| 1513 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1514 | .rssiClose; |
| 1515 | legacy_request->config_5g_rssi_middle = 1; |
| 1516 | legacy_request->rssi_middle_5g_val = |
| 1517 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1518 | .rssiMiddle; |
| 1519 | legacy_request->config_5g_rssi_close_proximity = 1; |
| 1520 | legacy_request->rssi_close_proximity_5g_val = |
| 1521 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1522 | .rssiCloseProximity; |
| 1523 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1524 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1525 | .dwellTimeMs; |
| 1526 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1527 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1528 | .scanPeriodSec; |
| 1529 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1530 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1531 | .dwellTimeMs; |
| 1532 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1533 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1534 | .scanPeriodSec; |
| 1535 | legacy_request->config_dw.config_5g_dw_band = |
| 1536 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1537 | .validDiscoveryWindowIntervalVal; |
| 1538 | legacy_request->config_dw.dw_5g_interval_val = |
| 1539 | aidl_request1.configParams.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1540 | .discoveryWindowIntervalVal; |
| 1541 | if (aidl_request1.debugConfigs.validClusterIdVals) { |
| 1542 | legacy_request->cluster_low = aidl_request1.debugConfigs.clusterIdBottomRangeVal; |
| 1543 | legacy_request->cluster_high = aidl_request1.debugConfigs.clusterIdTopRangeVal; |
| 1544 | } else { // need 'else' since not configurable in legacy HAL |
| 1545 | legacy_request->cluster_low = 0x0000; |
| 1546 | legacy_request->cluster_high = 0xFFFF; |
| 1547 | } |
| 1548 | legacy_request->config_intf_addr = aidl_request1.debugConfigs.validIntfAddrVal; |
| 1549 | memcpy(legacy_request->intf_addr_val, aidl_request1.debugConfigs.intfAddrVal.data(), 6); |
| 1550 | legacy_request->config_oui = aidl_request1.debugConfigs.validOuiVal; |
| 1551 | legacy_request->oui_val = aidl_request1.debugConfigs.ouiVal; |
| 1552 | legacy_request->config_random_factor_force = |
| 1553 | aidl_request1.debugConfigs.validRandomFactorForceVal; |
| 1554 | legacy_request->random_factor_force_val = aidl_request1.debugConfigs.randomFactorForceVal; |
| 1555 | legacy_request->config_hop_count_force = aidl_request1.debugConfigs.validHopCountForceVal; |
| 1556 | legacy_request->hop_count_force_val = aidl_request1.debugConfigs.hopCountForceVal; |
| 1557 | legacy_request->config_24g_channel = aidl_request1.debugConfigs.validDiscoveryChannelVal; |
| 1558 | legacy_request->channel_24g_val = |
| 1559 | aidl_request1.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1560 | legacy_request->config_5g_channel = aidl_request1.debugConfigs.validDiscoveryChannelVal; |
| 1561 | legacy_request->channel_5g_val = |
| 1562 | aidl_request1.debugConfigs.discoveryChannelMhzVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1563 | legacy_request->config_2dot4g_beacons = aidl_request1.debugConfigs.validUseBeaconsInBandVal; |
| 1564 | legacy_request->beacon_2dot4g_val = |
| 1565 | aidl_request1.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1566 | legacy_request->config_5g_beacons = aidl_request1.debugConfigs.validUseBeaconsInBandVal; |
| 1567 | legacy_request->beacon_5g_val = |
| 1568 | aidl_request1.debugConfigs.useBeaconsInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1569 | legacy_request->config_2dot4g_sdf = aidl_request1.debugConfigs.validUseSdfInBandVal; |
| 1570 | legacy_request->sdf_2dot4g_val = |
| 1571 | aidl_request1.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_24GHZ]; |
| 1572 | legacy_request->config_5g_sdf = aidl_request1.debugConfigs.validUseSdfInBandVal; |
| 1573 | legacy_request->sdf_5g_val = |
| 1574 | aidl_request1.debugConfigs.useSdfInBandVal[(size_t)NanBandIndex::NAN_BAND_5GHZ]; |
| 1575 | |
| 1576 | legacy_request->config_discovery_beacon_int = 1; |
| 1577 | legacy_request->discovery_beacon_interval = aidl_request2.discoveryBeaconIntervalMs; |
| 1578 | legacy_request->config_nss = 1; |
| 1579 | legacy_request->nss = aidl_request2.numberOfSpatialStreamsInDiscovery; |
| 1580 | legacy_request->config_dw_early_termination = 1; |
| 1581 | legacy_request->enable_dw_termination = aidl_request2.enableDiscoveryWindowEarlyTermination; |
| 1582 | legacy_request->config_enable_ranging = 1; |
| 1583 | legacy_request->enable_ranging = aidl_request2.enableRanging; |
| 1584 | |
| 1585 | legacy_request->config_enable_instant_mode = 1; |
| 1586 | legacy_request->enable_instant_mode = aidl_request2.enableInstantCommunicationMode; |
| 1587 | legacy_request->config_instant_mode_channel = 1; |
| 1588 | legacy_request->instant_mode_channel = aidl_request2.instantModeChannel; |
| 1589 | |
| 1590 | return true; |
| 1591 | } |
| 1592 | |
| 1593 | bool convertAidlNanConfigRequestToLegacy(const NanConfigRequest& aidl_request1, |
| 1594 | const NanConfigRequestSupplemental& aidl_request2, |
| 1595 | legacy_hal::NanConfigRequest* legacy_request) { |
| 1596 | if (!legacy_request) { |
| 1597 | LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: null legacy_request"; |
| 1598 | return false; |
| 1599 | } |
| 1600 | *legacy_request = {}; |
| 1601 | |
| 1602 | legacy_request->master_pref = aidl_request1.masterPref; |
| 1603 | legacy_request->discovery_indication_cfg = 0; |
| 1604 | legacy_request->discovery_indication_cfg |= |
| 1605 | aidl_request1.disableDiscoveryAddressChangeIndication ? 0x1 : 0x0; |
| 1606 | legacy_request->discovery_indication_cfg |= |
| 1607 | aidl_request1.disableStartedClusterIndication ? 0x2 : 0x0; |
| 1608 | legacy_request->discovery_indication_cfg |= |
| 1609 | aidl_request1.disableJoinedClusterIndication ? 0x4 : 0x0; |
| 1610 | legacy_request->config_sid_beacon = 1; |
| 1611 | if (aidl_request1.numberOfPublishServiceIdsInBeacon < 0) { |
| 1612 | LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: " |
| 1613 | "numberOfPublishServiceIdsInBeacon < 0"; |
| 1614 | return false; |
| 1615 | } |
| 1616 | legacy_request->sid_beacon = (aidl_request1.includePublishServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1617 | (aidl_request1.numberOfPublishServiceIdsInBeacon << 1); |
| 1618 | legacy_request->config_subscribe_sid_beacon = 1; |
| 1619 | if (aidl_request1.numberOfSubscribeServiceIdsInBeacon < 0) { |
| 1620 | LOG(ERROR) << "convertAidlNanConfigRequestToLegacy: " |
| 1621 | "numberOfSubscribeServiceIdsInBeacon < 0"; |
| 1622 | return false; |
| 1623 | } |
| 1624 | legacy_request->subscribe_sid_beacon_val = |
| 1625 | (aidl_request1.includeSubscribeServiceIdsInBeacon ? 0x1 : 0x0) | |
| 1626 | (aidl_request1.numberOfSubscribeServiceIdsInBeacon << 1); |
| 1627 | legacy_request->config_rssi_window_size = 1; |
| 1628 | legacy_request->rssi_window_size_val = aidl_request1.rssiWindowSize; |
| 1629 | legacy_request->config_disc_mac_addr_randomization = 1; |
| 1630 | legacy_request->disc_mac_addr_rand_interval_sec = |
| 1631 | aidl_request1.macAddressRandomizationIntervalSec; |
| 1632 | |
| 1633 | legacy_request->config_scan_params = 1; |
| 1634 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1635 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].dwellTimeMs; |
| 1636 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_24G_BAND] = |
| 1637 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ].scanPeriodSec; |
| 1638 | legacy_request->config_dw.config_2dot4g_dw_band = |
| 1639 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1640 | .validDiscoveryWindowIntervalVal; |
| 1641 | legacy_request->config_dw.dw_2dot4g_interval_val = |
| 1642 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_24GHZ] |
| 1643 | .discoveryWindowIntervalVal; |
| 1644 | |
| 1645 | legacy_request->config_5g_rssi_close_proximity = 1; |
| 1646 | legacy_request->rssi_close_proximity_5g_val = |
| 1647 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1648 | .rssiCloseProximity; |
| 1649 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1650 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 1651 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_LOW] = |
| 1652 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 1653 | legacy_request->scan_params_val.dwell_time[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1654 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].dwellTimeMs; |
| 1655 | legacy_request->scan_params_val.scan_period[legacy_hal::NAN_CHANNEL_5G_BAND_HIGH] = |
| 1656 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ].scanPeriodSec; |
| 1657 | legacy_request->config_dw.config_5g_dw_band = |
| 1658 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1659 | .validDiscoveryWindowIntervalVal; |
| 1660 | legacy_request->config_dw.dw_5g_interval_val = |
| 1661 | aidl_request1.bandSpecificConfig[(size_t)NanBandIndex::NAN_BAND_5GHZ] |
| 1662 | .discoveryWindowIntervalVal; |
| 1663 | |
| 1664 | legacy_request->config_discovery_beacon_int = 1; |
| 1665 | legacy_request->discovery_beacon_interval = aidl_request2.discoveryBeaconIntervalMs; |
| 1666 | legacy_request->config_nss = 1; |
| 1667 | legacy_request->nss = aidl_request2.numberOfSpatialStreamsInDiscovery; |
| 1668 | legacy_request->config_dw_early_termination = 1; |
| 1669 | legacy_request->enable_dw_termination = aidl_request2.enableDiscoveryWindowEarlyTermination; |
| 1670 | legacy_request->config_enable_ranging = 1; |
| 1671 | legacy_request->enable_ranging = aidl_request2.enableRanging; |
| 1672 | |
| 1673 | legacy_request->config_enable_instant_mode = 1; |
| 1674 | legacy_request->enable_instant_mode = aidl_request2.enableInstantCommunicationMode; |
| 1675 | legacy_request->config_instant_mode_channel = 1; |
| 1676 | legacy_request->instant_mode_channel = aidl_request2.instantModeChannel; |
Biswarup Pal | dc7192f | 2023-01-09 21:21:07 +0000 | [diff] [blame] | 1677 | legacy_request->config_cluster_id = 1; |
| 1678 | legacy_request->cluster_id_val = aidl_request2.clusterId; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1679 | |
| 1680 | return true; |
| 1681 | } |
| 1682 | |
| 1683 | bool convertAidlNanPublishRequestToLegacy(const NanPublishRequest& aidl_request, |
| 1684 | legacy_hal::NanPublishRequest* legacy_request) { |
| 1685 | if (!legacy_request) { |
| 1686 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: null legacy_request"; |
| 1687 | return false; |
| 1688 | } |
| 1689 | *legacy_request = {}; |
| 1690 | |
Nate Jiang | 4209176 | 2022-12-27 17:08:25 -0800 | [diff] [blame] | 1691 | legacy_request->publish_id = static_cast<uint8_t>(aidl_request.baseConfigs.sessionId); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1692 | legacy_request->ttl = aidl_request.baseConfigs.ttlSec; |
| 1693 | legacy_request->period = aidl_request.baseConfigs.discoveryWindowPeriod; |
| 1694 | legacy_request->publish_count = aidl_request.baseConfigs.discoveryCount; |
| 1695 | legacy_request->service_name_len = aidl_request.baseConfigs.serviceName.size(); |
| 1696 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 1697 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: service_name_len " |
| 1698 | "too large"; |
| 1699 | return false; |
| 1700 | } |
| 1701 | memcpy(legacy_request->service_name, aidl_request.baseConfigs.serviceName.data(), |
| 1702 | legacy_request->service_name_len); |
| 1703 | legacy_request->publish_match_indicator = |
| 1704 | convertAidlNanMatchAlgToLegacy(aidl_request.baseConfigs.discoveryMatchIndicator); |
| 1705 | legacy_request->service_specific_info_len = aidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 1706 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1707 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1708 | "service_specific_info_len too large"; |
| 1709 | return false; |
| 1710 | } |
| 1711 | memcpy(legacy_request->service_specific_info, |
| 1712 | aidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 1713 | legacy_request->service_specific_info_len); |
| 1714 | legacy_request->sdea_service_specific_info_len = |
| 1715 | aidl_request.baseConfigs.extendedServiceSpecificInfo.size(); |
| 1716 | if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 1717 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1718 | "sdea_service_specific_info_len too large"; |
| 1719 | return false; |
| 1720 | } |
| 1721 | memcpy(legacy_request->sdea_service_specific_info, |
| 1722 | aidl_request.baseConfigs.extendedServiceSpecificInfo.data(), |
| 1723 | legacy_request->sdea_service_specific_info_len); |
| 1724 | legacy_request->rx_match_filter_len = aidl_request.baseConfigs.rxMatchFilter.size(); |
| 1725 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1726 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1727 | "rx_match_filter_len too large"; |
| 1728 | return false; |
| 1729 | } |
| 1730 | memcpy(legacy_request->rx_match_filter, aidl_request.baseConfigs.rxMatchFilter.data(), |
| 1731 | legacy_request->rx_match_filter_len); |
| 1732 | legacy_request->tx_match_filter_len = aidl_request.baseConfigs.txMatchFilter.size(); |
| 1733 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1734 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1735 | "tx_match_filter_len too large"; |
| 1736 | return false; |
| 1737 | } |
| 1738 | memcpy(legacy_request->tx_match_filter, aidl_request.baseConfigs.txMatchFilter.data(), |
| 1739 | legacy_request->tx_match_filter_len); |
| 1740 | legacy_request->rssi_threshold_flag = aidl_request.baseConfigs.useRssiThreshold; |
| 1741 | legacy_request->recv_indication_cfg = 0; |
| 1742 | legacy_request->recv_indication_cfg |= |
| 1743 | aidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; |
| 1744 | legacy_request->recv_indication_cfg |= |
| 1745 | aidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
| 1746 | legacy_request->recv_indication_cfg |= |
| 1747 | aidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
| 1748 | legacy_request->recv_indication_cfg |= 0x8; |
| 1749 | legacy_request->cipher_type = (unsigned int)aidl_request.baseConfigs.securityConfig.cipherType; |
| 1750 | |
| 1751 | legacy_request->scid_len = aidl_request.baseConfigs.securityConfig.scid.size(); |
| 1752 | if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { |
| 1753 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: scid_len too large"; |
| 1754 | return false; |
| 1755 | } |
| 1756 | memcpy(legacy_request->scid, aidl_request.baseConfigs.securityConfig.scid.data(), |
| 1757 | legacy_request->scid_len); |
| 1758 | |
| 1759 | if (aidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { |
| 1760 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 1761 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 1762 | aidl_request.baseConfigs.securityConfig.pmk.size(); |
| 1763 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 1764 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: invalid pmk_len"; |
| 1765 | return false; |
| 1766 | } |
| 1767 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 1768 | aidl_request.baseConfigs.securityConfig.pmk.data(), |
| 1769 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 1770 | } |
| 1771 | if (aidl_request.baseConfigs.securityConfig.securityType == |
| 1772 | NanDataPathSecurityType::PASSPHRASE) { |
| 1773 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 1774 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 1775 | aidl_request.baseConfigs.securityConfig.passphrase.size(); |
| 1776 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 1777 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 1778 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1779 | "passphrase_len too small"; |
| 1780 | return false; |
| 1781 | } |
| 1782 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 1783 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 1784 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: " |
| 1785 | "passphrase_len too large"; |
| 1786 | return false; |
| 1787 | } |
| 1788 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 1789 | aidl_request.baseConfigs.securityConfig.passphrase.data(), |
| 1790 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 1791 | } |
| 1792 | legacy_request->sdea_params.security_cfg = |
| 1793 | (aidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) |
| 1794 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
| 1795 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1796 | |
| 1797 | legacy_request->sdea_params.ranging_state = aidl_request.baseConfigs.rangingRequired |
| 1798 | ? legacy_hal::NAN_RANGING_ENABLE |
| 1799 | : legacy_hal::NAN_RANGING_DISABLE; |
| 1800 | legacy_request->ranging_cfg.ranging_interval_msec = aidl_request.baseConfigs.rangingIntervalMs; |
| 1801 | legacy_request->ranging_cfg.config_ranging_indications = |
| 1802 | static_cast<uint32_t>(aidl_request.baseConfigs.configRangingIndications); |
| 1803 | legacy_request->ranging_cfg.distance_ingress_mm = |
| 1804 | aidl_request.baseConfigs.distanceIngressCm * 10; |
| 1805 | legacy_request->ranging_cfg.distance_egress_mm = aidl_request.baseConfigs.distanceEgressCm * 10; |
| 1806 | legacy_request->ranging_auto_response = aidl_request.baseConfigs.rangingRequired |
| 1807 | ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE |
| 1808 | : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
| 1809 | legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; |
| 1810 | legacy_request->publish_type = convertAidlNanPublishTypeToLegacy(aidl_request.publishType); |
| 1811 | legacy_request->tx_type = convertAidlNanTxTypeToLegacy(aidl_request.txType); |
| 1812 | legacy_request->service_responder_policy = aidl_request.autoAcceptDataPathRequests |
| 1813 | ? legacy_hal::NAN_SERVICE_ACCEPT_POLICY_ALL |
| 1814 | : legacy_hal::NAN_SERVICE_ACCEPT_POLICY_NONE; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1815 | memcpy(legacy_request->nan_identity_key, aidl_request.identityKey.data(), NAN_IDENTITY_KEY_LEN); |
| 1816 | if (!covertAidlPairingConfigToLegacy(aidl_request.pairingConfig, |
| 1817 | &legacy_request->nan_pairing_config)) { |
| 1818 | LOG(ERROR) << "convertAidlNanPublishRequestToLegacy: invalid pairing config"; |
| 1819 | return false; |
| 1820 | } |
Biswarup Pal | 1192178 | 2023-01-09 14:10:51 +0000 | [diff] [blame] | 1821 | legacy_request->enable_suspendability = aidl_request.baseConfigs.enableSessionSuspendability; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1822 | |
| 1823 | return true; |
| 1824 | } |
| 1825 | |
| 1826 | bool convertAidlNanSubscribeRequestToLegacy(const NanSubscribeRequest& aidl_request, |
| 1827 | legacy_hal::NanSubscribeRequest* legacy_request) { |
| 1828 | if (!legacy_request) { |
| 1829 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: legacy_request is null"; |
| 1830 | return false; |
| 1831 | } |
| 1832 | *legacy_request = {}; |
| 1833 | |
Nate Jiang | 4209176 | 2022-12-27 17:08:25 -0800 | [diff] [blame] | 1834 | legacy_request->subscribe_id = static_cast<uint8_t>(aidl_request.baseConfigs.sessionId); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1835 | legacy_request->ttl = aidl_request.baseConfigs.ttlSec; |
| 1836 | legacy_request->period = aidl_request.baseConfigs.discoveryWindowPeriod; |
| 1837 | legacy_request->subscribe_count = aidl_request.baseConfigs.discoveryCount; |
| 1838 | legacy_request->service_name_len = aidl_request.baseConfigs.serviceName.size(); |
| 1839 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 1840 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1841 | "service_name_len too large"; |
| 1842 | return false; |
| 1843 | } |
| 1844 | memcpy(legacy_request->service_name, aidl_request.baseConfigs.serviceName.data(), |
| 1845 | legacy_request->service_name_len); |
| 1846 | legacy_request->subscribe_match_indicator = |
| 1847 | convertAidlNanMatchAlgToLegacy(aidl_request.baseConfigs.discoveryMatchIndicator); |
| 1848 | legacy_request->service_specific_info_len = aidl_request.baseConfigs.serviceSpecificInfo.size(); |
| 1849 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1850 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1851 | "service_specific_info_len too large"; |
| 1852 | return false; |
| 1853 | } |
| 1854 | memcpy(legacy_request->service_specific_info, |
| 1855 | aidl_request.baseConfigs.serviceSpecificInfo.data(), |
| 1856 | legacy_request->service_specific_info_len); |
| 1857 | legacy_request->sdea_service_specific_info_len = |
| 1858 | aidl_request.baseConfigs.extendedServiceSpecificInfo.size(); |
| 1859 | if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 1860 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1861 | "sdea_service_specific_info_len too large"; |
| 1862 | return false; |
| 1863 | } |
| 1864 | memcpy(legacy_request->sdea_service_specific_info, |
| 1865 | aidl_request.baseConfigs.extendedServiceSpecificInfo.data(), |
| 1866 | legacy_request->sdea_service_specific_info_len); |
| 1867 | legacy_request->rx_match_filter_len = aidl_request.baseConfigs.rxMatchFilter.size(); |
| 1868 | if (legacy_request->rx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1869 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1870 | "rx_match_filter_len too large"; |
| 1871 | return false; |
| 1872 | } |
| 1873 | memcpy(legacy_request->rx_match_filter, aidl_request.baseConfigs.rxMatchFilter.data(), |
| 1874 | legacy_request->rx_match_filter_len); |
| 1875 | legacy_request->tx_match_filter_len = aidl_request.baseConfigs.txMatchFilter.size(); |
| 1876 | if (legacy_request->tx_match_filter_len > NAN_MAX_MATCH_FILTER_LEN) { |
| 1877 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1878 | "tx_match_filter_len too large"; |
| 1879 | return false; |
| 1880 | } |
| 1881 | memcpy(legacy_request->tx_match_filter, aidl_request.baseConfigs.txMatchFilter.data(), |
| 1882 | legacy_request->tx_match_filter_len); |
| 1883 | legacy_request->rssi_threshold_flag = aidl_request.baseConfigs.useRssiThreshold; |
| 1884 | legacy_request->recv_indication_cfg = 0; |
| 1885 | legacy_request->recv_indication_cfg |= |
| 1886 | aidl_request.baseConfigs.disableDiscoveryTerminationIndication ? 0x1 : 0x0; |
| 1887 | legacy_request->recv_indication_cfg |= |
| 1888 | aidl_request.baseConfigs.disableMatchExpirationIndication ? 0x2 : 0x0; |
| 1889 | legacy_request->recv_indication_cfg |= |
| 1890 | aidl_request.baseConfigs.disableFollowupReceivedIndication ? 0x4 : 0x0; |
| 1891 | legacy_request->cipher_type = (unsigned int)aidl_request.baseConfigs.securityConfig.cipherType; |
| 1892 | if (aidl_request.baseConfigs.securityConfig.securityType == NanDataPathSecurityType::PMK) { |
| 1893 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 1894 | legacy_request->key_info.body.pmk_info.pmk_len = |
| 1895 | aidl_request.baseConfigs.securityConfig.pmk.size(); |
| 1896 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 1897 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: invalid pmk_len"; |
| 1898 | return false; |
| 1899 | } |
| 1900 | memcpy(legacy_request->key_info.body.pmk_info.pmk, |
| 1901 | aidl_request.baseConfigs.securityConfig.pmk.data(), |
| 1902 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 1903 | } |
| 1904 | if (aidl_request.baseConfigs.securityConfig.securityType == |
| 1905 | NanDataPathSecurityType::PASSPHRASE) { |
| 1906 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 1907 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 1908 | aidl_request.baseConfigs.securityConfig.passphrase.size(); |
| 1909 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 1910 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 1911 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1912 | "passphrase_len too small"; |
| 1913 | return false; |
| 1914 | } |
| 1915 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 1916 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 1917 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1918 | "passphrase_len too large"; |
| 1919 | return false; |
| 1920 | } |
| 1921 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 1922 | aidl_request.baseConfigs.securityConfig.passphrase.data(), |
| 1923 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 1924 | } |
| 1925 | legacy_request->sdea_params.security_cfg = |
| 1926 | (aidl_request.baseConfigs.securityConfig.securityType != NanDataPathSecurityType::OPEN) |
| 1927 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
| 1928 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 1929 | legacy_request->sdea_params.ranging_state = aidl_request.baseConfigs.rangingRequired |
| 1930 | ? legacy_hal::NAN_RANGING_ENABLE |
| 1931 | : legacy_hal::NAN_RANGING_DISABLE; |
| 1932 | legacy_request->ranging_cfg.ranging_interval_msec = aidl_request.baseConfigs.rangingIntervalMs; |
| 1933 | legacy_request->ranging_cfg.config_ranging_indications = |
| 1934 | static_cast<uint32_t>(aidl_request.baseConfigs.configRangingIndications); |
| 1935 | legacy_request->ranging_cfg.distance_ingress_mm = |
| 1936 | aidl_request.baseConfigs.distanceIngressCm * 10; |
| 1937 | legacy_request->ranging_cfg.distance_egress_mm = aidl_request.baseConfigs.distanceEgressCm * 10; |
| 1938 | legacy_request->ranging_auto_response = aidl_request.baseConfigs.rangingRequired |
| 1939 | ? legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE |
| 1940 | : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE; |
| 1941 | legacy_request->sdea_params.range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT; |
| 1942 | legacy_request->subscribe_type = |
| 1943 | convertAidlNanSubscribeTypeToLegacy(aidl_request.subscribeType); |
| 1944 | legacy_request->serviceResponseFilter = convertAidlNanSrfTypeToLegacy(aidl_request.srfType); |
| 1945 | legacy_request->serviceResponseInclude = aidl_request.srfRespondIfInAddressSet |
| 1946 | ? legacy_hal::NAN_SRF_INCLUDE_RESPOND |
| 1947 | : legacy_hal::NAN_SRF_INCLUDE_DO_NOT_RESPOND; |
| 1948 | legacy_request->useServiceResponseFilter = |
| 1949 | aidl_request.shouldUseSrf ? legacy_hal::NAN_USE_SRF : legacy_hal::NAN_DO_NOT_USE_SRF; |
| 1950 | legacy_request->ssiRequiredForMatchIndication = |
| 1951 | aidl_request.isSsiRequiredForMatch ? legacy_hal::NAN_SSI_REQUIRED_IN_MATCH_IND |
| 1952 | : legacy_hal::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND; |
| 1953 | legacy_request->num_intf_addr_present = aidl_request.intfAddr.size(); |
| 1954 | if (legacy_request->num_intf_addr_present > NAN_MAX_SUBSCRIBE_MAX_ADDRESS) { |
| 1955 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: " |
| 1956 | "num_intf_addr_present - too many"; |
| 1957 | return false; |
| 1958 | } |
| 1959 | for (int i = 0; i < legacy_request->num_intf_addr_present; i++) { |
| 1960 | memcpy(legacy_request->intf_addr[i], aidl_request.intfAddr[i].data.data(), 6); |
| 1961 | } |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 1962 | memcpy(legacy_request->nan_identity_key, aidl_request.identityKey.data(), NAN_IDENTITY_KEY_LEN); |
| 1963 | if (!covertAidlPairingConfigToLegacy(aidl_request.pairingConfig, |
| 1964 | &legacy_request->nan_pairing_config)) { |
| 1965 | LOG(ERROR) << "convertAidlNanSubscribeRequestToLegacy: invalid pairing config"; |
| 1966 | return false; |
| 1967 | } |
Biswarup Pal | 1192178 | 2023-01-09 14:10:51 +0000 | [diff] [blame] | 1968 | legacy_request->enable_suspendability = aidl_request.baseConfigs.enableSessionSuspendability; |
| 1969 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1970 | return true; |
| 1971 | } |
| 1972 | |
| 1973 | bool convertAidlNanTransmitFollowupRequestToLegacy( |
| 1974 | const NanTransmitFollowupRequest& aidl_request, |
| 1975 | legacy_hal::NanTransmitFollowupRequest* legacy_request) { |
| 1976 | if (!legacy_request) { |
| 1977 | LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " |
| 1978 | "legacy_request is null"; |
| 1979 | return false; |
| 1980 | } |
| 1981 | *legacy_request = {}; |
| 1982 | |
Nate Jiang | 4209176 | 2022-12-27 17:08:25 -0800 | [diff] [blame] | 1983 | legacy_request->publish_subscribe_id = static_cast<uint8_t>(aidl_request.discoverySessionId); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1984 | legacy_request->requestor_instance_id = aidl_request.peerId; |
| 1985 | memcpy(legacy_request->addr, aidl_request.addr.data(), 6); |
| 1986 | legacy_request->priority = aidl_request.isHighPriority ? legacy_hal::NAN_TX_PRIORITY_HIGH |
| 1987 | : legacy_hal::NAN_TX_PRIORITY_NORMAL; |
| 1988 | legacy_request->dw_or_faw = aidl_request.shouldUseDiscoveryWindow |
| 1989 | ? legacy_hal::NAN_TRANSMIT_IN_DW |
| 1990 | : legacy_hal::NAN_TRANSMIT_IN_FAW; |
| 1991 | legacy_request->service_specific_info_len = aidl_request.serviceSpecificInfo.size(); |
| 1992 | if (legacy_request->service_specific_info_len > NAN_MAX_SERVICE_SPECIFIC_INFO_LEN) { |
| 1993 | LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " |
| 1994 | "service_specific_info_len too large"; |
| 1995 | return false; |
| 1996 | } |
| 1997 | memcpy(legacy_request->service_specific_info, aidl_request.serviceSpecificInfo.data(), |
| 1998 | legacy_request->service_specific_info_len); |
| 1999 | legacy_request->sdea_service_specific_info_len = |
| 2000 | aidl_request.extendedServiceSpecificInfo.size(); |
| 2001 | if (legacy_request->sdea_service_specific_info_len > NAN_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN) { |
| 2002 | LOG(ERROR) << "convertAidlNanTransmitFollowupRequestToLegacy: " |
| 2003 | "sdea_service_specific_info_len too large"; |
| 2004 | return false; |
| 2005 | } |
| 2006 | memcpy(legacy_request->sdea_service_specific_info, |
| 2007 | aidl_request.extendedServiceSpecificInfo.data(), |
| 2008 | legacy_request->sdea_service_specific_info_len); |
| 2009 | legacy_request->recv_indication_cfg = aidl_request.disableFollowupResultIndication ? 0x1 : 0x0; |
| 2010 | |
| 2011 | return true; |
| 2012 | } |
| 2013 | |
| 2014 | bool convertAidlNanDataPathInitiatorRequestToLegacy( |
| 2015 | const NanInitiateDataPathRequest& aidl_request, |
| 2016 | legacy_hal::NanDataPathInitiatorRequest* legacy_request) { |
| 2017 | if (!legacy_request) { |
| 2018 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2019 | "legacy_request is null"; |
| 2020 | return false; |
| 2021 | } |
| 2022 | *legacy_request = {}; |
| 2023 | |
| 2024 | legacy_request->requestor_instance_id = aidl_request.peerId; |
| 2025 | memcpy(legacy_request->peer_disc_mac_addr, aidl_request.peerDiscMacAddr.data(), 6); |
| 2026 | legacy_request->channel_request_type = |
| 2027 | convertAidlNanDataPathChannelCfgToLegacy(aidl_request.channelRequestType); |
| 2028 | legacy_request->channel = aidl_request.channel; |
| 2029 | if (strnlen(aidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { |
| 2030 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2031 | "ifaceName too long"; |
| 2032 | return false; |
| 2033 | } |
| 2034 | strlcpy(legacy_request->ndp_iface, aidl_request.ifaceName.c_str(), IFNAMSIZ + 1); |
| 2035 | legacy_request->ndp_cfg.security_cfg = |
| 2036 | (aidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) |
| 2037 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
| 2038 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 2039 | legacy_request->app_info.ndp_app_info_len = aidl_request.appInfo.size(); |
| 2040 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
| 2041 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2042 | "ndp_app_info_len too large"; |
| 2043 | return false; |
| 2044 | } |
| 2045 | memcpy(legacy_request->app_info.ndp_app_info, aidl_request.appInfo.data(), |
| 2046 | legacy_request->app_info.ndp_app_info_len); |
| 2047 | legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; |
| 2048 | if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { |
| 2049 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 2050 | legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); |
| 2051 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 2052 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2053 | "invalid pmk_len"; |
| 2054 | return false; |
| 2055 | } |
| 2056 | memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), |
| 2057 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 2058 | } |
| 2059 | if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { |
| 2060 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 2061 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 2062 | aidl_request.securityConfig.passphrase.size(); |
| 2063 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 2064 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 2065 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2066 | "passphrase_len too small"; |
| 2067 | return false; |
| 2068 | } |
| 2069 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 2070 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 2071 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2072 | "passphrase_len too large"; |
| 2073 | return false; |
| 2074 | } |
| 2075 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 2076 | aidl_request.securityConfig.passphrase.data(), |
| 2077 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 2078 | } |
| 2079 | legacy_request->service_name_len = aidl_request.serviceNameOutOfBand.size(); |
| 2080 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 2081 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: " |
| 2082 | "service_name_len too large"; |
| 2083 | return false; |
| 2084 | } |
| 2085 | memcpy(legacy_request->service_name, aidl_request.serviceNameOutOfBand.data(), |
| 2086 | legacy_request->service_name_len); |
| 2087 | legacy_request->scid_len = aidl_request.securityConfig.scid.size(); |
| 2088 | if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { |
| 2089 | LOG(ERROR) << "convertAidlNanDataPathInitiatorRequestToLegacy: scid_len too large"; |
| 2090 | return false; |
| 2091 | } |
| 2092 | memcpy(legacy_request->scid, aidl_request.securityConfig.scid.data(), legacy_request->scid_len); |
| 2093 | |
| 2094 | return true; |
| 2095 | } |
| 2096 | |
| 2097 | bool convertAidlNanDataPathIndicationResponseToLegacy( |
| 2098 | const NanRespondToDataPathIndicationRequest& aidl_request, |
| 2099 | legacy_hal::NanDataPathIndicationResponse* legacy_request) { |
| 2100 | if (!legacy_request) { |
| 2101 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2102 | "legacy_request is null"; |
| 2103 | return false; |
| 2104 | } |
| 2105 | *legacy_request = {}; |
| 2106 | |
| 2107 | legacy_request->rsp_code = aidl_request.acceptRequest ? legacy_hal::NAN_DP_REQUEST_ACCEPT |
| 2108 | : legacy_hal::NAN_DP_REQUEST_REJECT; |
| 2109 | legacy_request->ndp_instance_id = aidl_request.ndpInstanceId; |
| 2110 | if (strnlen(aidl_request.ifaceName.c_str(), IFNAMSIZ + 1) == IFNAMSIZ + 1) { |
| 2111 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2112 | "ifaceName too long"; |
| 2113 | return false; |
| 2114 | } |
| 2115 | strlcpy(legacy_request->ndp_iface, aidl_request.ifaceName.c_str(), IFNAMSIZ + 1); |
| 2116 | legacy_request->ndp_cfg.security_cfg = |
| 2117 | (aidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN) |
| 2118 | ? legacy_hal::NAN_DP_CONFIG_SECURITY |
| 2119 | : legacy_hal::NAN_DP_CONFIG_NO_SECURITY; |
| 2120 | legacy_request->app_info.ndp_app_info_len = aidl_request.appInfo.size(); |
| 2121 | if (legacy_request->app_info.ndp_app_info_len > NAN_DP_MAX_APP_INFO_LEN) { |
| 2122 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2123 | "ndp_app_info_len too large"; |
| 2124 | return false; |
| 2125 | } |
| 2126 | memcpy(legacy_request->app_info.ndp_app_info, aidl_request.appInfo.data(), |
| 2127 | legacy_request->app_info.ndp_app_info_len); |
| 2128 | legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; |
| 2129 | if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PMK) { |
| 2130 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 2131 | legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); |
| 2132 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 2133 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2134 | "invalid pmk_len"; |
| 2135 | return false; |
| 2136 | } |
| 2137 | memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), |
| 2138 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 2139 | } |
| 2140 | if (aidl_request.securityConfig.securityType == NanDataPathSecurityType::PASSPHRASE) { |
| 2141 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 2142 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 2143 | aidl_request.securityConfig.passphrase.size(); |
| 2144 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 2145 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 2146 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2147 | "passphrase_len too small"; |
| 2148 | return false; |
| 2149 | } |
| 2150 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 2151 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 2152 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2153 | "passphrase_len too large"; |
| 2154 | return false; |
| 2155 | } |
| 2156 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 2157 | aidl_request.securityConfig.passphrase.data(), |
| 2158 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 2159 | } |
| 2160 | legacy_request->service_name_len = aidl_request.serviceNameOutOfBand.size(); |
| 2161 | if (legacy_request->service_name_len > NAN_MAX_SERVICE_NAME_LEN) { |
| 2162 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: " |
| 2163 | "service_name_len too large"; |
| 2164 | return false; |
| 2165 | } |
| 2166 | memcpy(legacy_request->service_name, aidl_request.serviceNameOutOfBand.data(), |
| 2167 | legacy_request->service_name_len); |
| 2168 | legacy_request->scid_len = aidl_request.securityConfig.scid.size(); |
| 2169 | if (legacy_request->scid_len > NAN_MAX_SCID_BUF_LEN) { |
| 2170 | LOG(ERROR) << "convertAidlNanDataPathIndicationResponseToLegacy: scid_len too large"; |
| 2171 | return false; |
| 2172 | } |
| 2173 | memcpy(legacy_request->scid, aidl_request.securityConfig.scid.data(), legacy_request->scid_len); |
| 2174 | |
| 2175 | return true; |
| 2176 | } |
| 2177 | |
| 2178 | bool convertLegacyNanResponseHeaderToAidl(const legacy_hal::NanResponseMsg& legacy_response, |
| 2179 | NanStatus* nanStatus) { |
| 2180 | if (!nanStatus) { |
| 2181 | LOG(ERROR) << "convertLegacyNanResponseHeaderToAidl: nanStatus is null"; |
| 2182 | return false; |
| 2183 | } |
| 2184 | *nanStatus = {}; |
| 2185 | |
| 2186 | convertToNanStatus(legacy_response.status, legacy_response.nan_error, |
| 2187 | sizeof(legacy_response.nan_error), nanStatus); |
| 2188 | return true; |
| 2189 | } |
| 2190 | |
| 2191 | bool convertLegacyNanCapabilitiesResponseToAidl(const legacy_hal::NanCapabilities& legacy_response, |
| 2192 | NanCapabilities* aidl_response) { |
| 2193 | if (!aidl_response) { |
| 2194 | LOG(ERROR) << "convertLegacyNanCapabilitiesResponseToAidl: " |
| 2195 | "aidl_response is null"; |
| 2196 | return false; |
| 2197 | } |
| 2198 | *aidl_response = {}; |
| 2199 | |
| 2200 | aidl_response->maxConcurrentClusters = legacy_response.max_concurrent_nan_clusters; |
| 2201 | aidl_response->maxPublishes = legacy_response.max_publishes; |
| 2202 | aidl_response->maxSubscribes = legacy_response.max_subscribes; |
| 2203 | aidl_response->maxServiceNameLen = legacy_response.max_service_name_len; |
| 2204 | aidl_response->maxMatchFilterLen = legacy_response.max_match_filter_len; |
| 2205 | aidl_response->maxTotalMatchFilterLen = legacy_response.max_total_match_filter_len; |
| 2206 | aidl_response->maxServiceSpecificInfoLen = legacy_response.max_service_specific_info_len; |
| 2207 | aidl_response->maxExtendedServiceSpecificInfoLen = |
| 2208 | legacy_response.max_sdea_service_specific_info_len; |
| 2209 | aidl_response->maxNdiInterfaces = legacy_response.max_ndi_interfaces; |
| 2210 | aidl_response->maxNdpSessions = legacy_response.max_ndp_sessions; |
| 2211 | aidl_response->maxAppInfoLen = legacy_response.max_app_info_len; |
| 2212 | aidl_response->maxQueuedTransmitFollowupMsgs = |
| 2213 | legacy_response.max_queued_transmit_followup_msgs; |
| 2214 | aidl_response->maxSubscribeInterfaceAddresses = legacy_response.max_subscribe_address; |
| 2215 | aidl_response->supportedCipherSuites = |
| 2216 | static_cast<NanCipherSuiteType>(legacy_response.cipher_suites_supported); |
| 2217 | aidl_response->instantCommunicationModeSupportFlag = legacy_response.is_instant_mode_supported; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 2218 | aidl_response->supports6g = legacy_response.is_6g_supported; |
| 2219 | aidl_response->supportsHe = legacy_response.is_he_supported; |
| 2220 | aidl_response->supportsPairing = legacy_response.is_pairing_supported; |
Biswarup Pal | dc7192f | 2023-01-09 21:21:07 +0000 | [diff] [blame] | 2221 | aidl_response->supportsSetClusterId = legacy_response.is_set_cluster_id_supported; |
Biswarup Pal | 319f99f | 2022-12-20 18:06:50 +0000 | [diff] [blame] | 2222 | aidl_response->supportsSuspension = legacy_response.is_suspension_supported; |
| 2223 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2224 | return true; |
| 2225 | } |
| 2226 | |
| 2227 | bool convertLegacyNanMatchIndToAidl(const legacy_hal::NanMatchInd& legacy_ind, |
| 2228 | NanMatchInd* aidl_ind) { |
| 2229 | if (!aidl_ind) { |
| 2230 | LOG(ERROR) << "convertLegacyNanMatchIndToAidl: aidl_ind is null"; |
| 2231 | return false; |
| 2232 | } |
| 2233 | *aidl_ind = {}; |
| 2234 | |
| 2235 | aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 2236 | aidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 2237 | aidl_ind->addr = std::array<uint8_t, 6>(); |
| 2238 | std::copy(legacy_ind.addr, legacy_ind.addr + 6, std::begin(aidl_ind->addr)); |
| 2239 | aidl_ind->serviceSpecificInfo = std::vector<uint8_t>( |
| 2240 | legacy_ind.service_specific_info, |
| 2241 | legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); |
| 2242 | aidl_ind->extendedServiceSpecificInfo = std::vector<uint8_t>( |
| 2243 | legacy_ind.sdea_service_specific_info, |
| 2244 | legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); |
| 2245 | aidl_ind->matchFilter = |
| 2246 | std::vector<uint8_t>(legacy_ind.sdf_match_filter, |
| 2247 | legacy_ind.sdf_match_filter + legacy_ind.sdf_match_filter_len); |
| 2248 | aidl_ind->matchOccurredInBeaconFlag = legacy_ind.match_occured_flag == 1; // NOTYPO |
| 2249 | aidl_ind->outOfResourceFlag = legacy_ind.out_of_resource_flag == 1; |
| 2250 | aidl_ind->rssiValue = legacy_ind.rssi_value; |
| 2251 | aidl_ind->peerCipherType = (NanCipherSuiteType)legacy_ind.peer_cipher_type; |
| 2252 | aidl_ind->peerRequiresSecurityEnabledInNdp = |
| 2253 | legacy_ind.peer_sdea_params.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; |
| 2254 | aidl_ind->peerRequiresRanging = |
| 2255 | legacy_ind.peer_sdea_params.ranging_state == legacy_hal::NAN_RANGING_ENABLE; |
| 2256 | aidl_ind->rangingMeasurementInMm = legacy_ind.range_info.range_measurement_mm; |
| 2257 | aidl_ind->rangingIndicationType = |
| 2258 | static_cast<NanRangingIndication>(legacy_ind.range_info.ranging_event_type); |
| 2259 | aidl_ind->scid = std::vector<uint8_t>(legacy_ind.scid, legacy_ind.scid + legacy_ind.scid_len); |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 2260 | |
| 2261 | if (!convertLegacyNiraToAidl(legacy_ind.nira, &aidl_ind->peerNira)) { |
| 2262 | LOG(ERROR) << "convertLegacyNanMatchIndToAidl: invalid NIRA"; |
| 2263 | return false; |
| 2264 | } |
| 2265 | if (!convertLegacyPairingConfigToAidl(legacy_ind.peer_pairing_config, |
| 2266 | &aidl_ind->peerPairingConfig)) { |
| 2267 | LOG(ERROR) << "convertLegacyNanMatchIndToAidl: invalid pairing config"; |
| 2268 | return false; |
| 2269 | } |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2270 | return true; |
| 2271 | } |
| 2272 | |
| 2273 | bool convertLegacyNanFollowupIndToAidl(const legacy_hal::NanFollowupInd& legacy_ind, |
| 2274 | NanFollowupReceivedInd* aidl_ind) { |
| 2275 | if (!aidl_ind) { |
| 2276 | LOG(ERROR) << "convertLegacyNanFollowupIndToAidl: aidl_ind is null"; |
| 2277 | return false; |
| 2278 | } |
| 2279 | *aidl_ind = {}; |
| 2280 | |
| 2281 | aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 2282 | aidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 2283 | aidl_ind->addr = std::array<uint8_t, 6>(); |
| 2284 | std::copy(legacy_ind.addr, legacy_ind.addr + 6, std::begin(aidl_ind->addr)); |
| 2285 | aidl_ind->receivedInFaw = legacy_ind.dw_or_faw == 1; |
| 2286 | aidl_ind->serviceSpecificInfo = std::vector<uint8_t>( |
| 2287 | legacy_ind.service_specific_info, |
| 2288 | legacy_ind.service_specific_info + legacy_ind.service_specific_info_len); |
| 2289 | aidl_ind->extendedServiceSpecificInfo = std::vector<uint8_t>( |
| 2290 | legacy_ind.sdea_service_specific_info, |
| 2291 | legacy_ind.sdea_service_specific_info + legacy_ind.sdea_service_specific_info_len); |
| 2292 | |
| 2293 | return true; |
| 2294 | } |
| 2295 | |
| 2296 | bool convertLegacyNanDataPathRequestIndToAidl(const legacy_hal::NanDataPathRequestInd& legacy_ind, |
| 2297 | NanDataPathRequestInd* aidl_ind) { |
| 2298 | if (!aidl_ind) { |
| 2299 | LOG(ERROR) << "convertLegacyNanDataPathRequestIndToAidl: aidl_ind is null"; |
| 2300 | return false; |
| 2301 | } |
| 2302 | *aidl_ind = {}; |
| 2303 | |
| 2304 | aidl_ind->discoverySessionId = legacy_ind.service_instance_id; |
| 2305 | aidl_ind->peerDiscMacAddr = std::array<uint8_t, 6>(); |
| 2306 | std::copy(legacy_ind.peer_disc_mac_addr, legacy_ind.peer_disc_mac_addr + 6, |
| 2307 | std::begin(aidl_ind->peerDiscMacAddr)); |
| 2308 | aidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; |
| 2309 | aidl_ind->securityRequired = |
| 2310 | legacy_ind.ndp_cfg.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY; |
| 2311 | aidl_ind->appInfo = std::vector<uint8_t>( |
| 2312 | legacy_ind.app_info.ndp_app_info, |
| 2313 | legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); |
| 2314 | |
| 2315 | return true; |
| 2316 | } |
| 2317 | |
| 2318 | bool convertLegacyNdpChannelInfoToAidl(const legacy_hal::NanChannelInfo& legacy_struct, |
| 2319 | NanDataPathChannelInfo* aidl_struct) { |
| 2320 | if (!aidl_struct) { |
| 2321 | LOG(ERROR) << "convertLegacyNdpChannelInfoToAidl: aidl_struct is null"; |
| 2322 | return false; |
| 2323 | } |
| 2324 | *aidl_struct = {}; |
| 2325 | |
| 2326 | aidl_struct->channelFreq = legacy_struct.channel; |
| 2327 | aidl_struct->channelBandwidth = convertLegacyWifiChannelWidthToAidl( |
| 2328 | (legacy_hal::wifi_channel_width)legacy_struct.bandwidth); |
| 2329 | aidl_struct->numSpatialStreams = legacy_struct.nss; |
| 2330 | |
| 2331 | return true; |
| 2332 | } |
| 2333 | |
| 2334 | bool convertLegacyNanDataPathConfirmIndToAidl(const legacy_hal::NanDataPathConfirmInd& legacy_ind, |
| 2335 | NanDataPathConfirmInd* aidl_ind) { |
| 2336 | if (!aidl_ind) { |
| 2337 | LOG(ERROR) << "convertLegacyNanDataPathConfirmIndToAidl: aidl_ind is null"; |
| 2338 | return false; |
| 2339 | } |
| 2340 | *aidl_ind = {}; |
| 2341 | |
| 2342 | aidl_ind->ndpInstanceId = legacy_ind.ndp_instance_id; |
| 2343 | aidl_ind->dataPathSetupSuccess = legacy_ind.rsp_code == legacy_hal::NAN_DP_REQUEST_ACCEPT; |
| 2344 | aidl_ind->peerNdiMacAddr = std::array<uint8_t, 6>(); |
| 2345 | std::copy(legacy_ind.peer_ndi_mac_addr, legacy_ind.peer_ndi_mac_addr + 6, |
| 2346 | std::begin(aidl_ind->peerNdiMacAddr)); |
| 2347 | aidl_ind->appInfo = std::vector<uint8_t>( |
| 2348 | legacy_ind.app_info.ndp_app_info, |
| 2349 | legacy_ind.app_info.ndp_app_info + legacy_ind.app_info.ndp_app_info_len); |
| 2350 | aidl_ind->status.status = convertLegacyNanStatusTypeToAidl(legacy_ind.reason_code); |
| 2351 | aidl_ind->status.description = ""; |
| 2352 | |
| 2353 | std::vector<NanDataPathChannelInfo> channelInfo; |
| 2354 | for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { |
| 2355 | NanDataPathChannelInfo aidl_struct; |
| 2356 | if (!convertLegacyNdpChannelInfoToAidl(legacy_ind.channel_info[i], &aidl_struct)) { |
| 2357 | return false; |
| 2358 | } |
| 2359 | channelInfo.push_back(aidl_struct); |
| 2360 | } |
| 2361 | aidl_ind->channelInfo = channelInfo; |
| 2362 | |
| 2363 | return true; |
| 2364 | } |
| 2365 | |
| 2366 | bool convertLegacyNanDataPathScheduleUpdateIndToAidl( |
| 2367 | const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind, |
| 2368 | NanDataPathScheduleUpdateInd* aidl_ind) { |
| 2369 | if (!aidl_ind) { |
| 2370 | LOG(ERROR) << "convertLegacyNanDataPathScheduleUpdateIndToAidl: " |
| 2371 | "aidl_ind is null"; |
| 2372 | return false; |
| 2373 | } |
| 2374 | *aidl_ind = {}; |
| 2375 | |
| 2376 | aidl_ind->peerDiscoveryAddress = std::array<uint8_t, 6>(); |
| 2377 | std::copy(legacy_ind.peer_mac_addr, legacy_ind.peer_mac_addr + 6, |
| 2378 | std::begin(aidl_ind->peerDiscoveryAddress)); |
| 2379 | std::vector<NanDataPathChannelInfo> channelInfo; |
| 2380 | for (unsigned int i = 0; i < legacy_ind.num_channels; ++i) { |
| 2381 | NanDataPathChannelInfo aidl_struct; |
| 2382 | if (!convertLegacyNdpChannelInfoToAidl(legacy_ind.channel_info[i], &aidl_struct)) { |
| 2383 | return false; |
| 2384 | } |
| 2385 | channelInfo.push_back(aidl_struct); |
| 2386 | } |
| 2387 | aidl_ind->channelInfo = channelInfo; |
| 2388 | std::vector<uint32_t> ndpInstanceIds; |
| 2389 | for (unsigned int i = 0; i < legacy_ind.num_ndp_instances; ++i) { |
| 2390 | ndpInstanceIds.push_back(legacy_ind.ndp_instance_id[i]); |
| 2391 | } |
| 2392 | aidl_ind->ndpInstanceIds = uintToIntVec(ndpInstanceIds); |
| 2393 | |
| 2394 | return true; |
| 2395 | } |
| 2396 | |
| 2397 | legacy_hal::wifi_rtt_type convertAidlRttTypeToLegacy(RttType type) { |
| 2398 | switch (type) { |
| 2399 | case RttType::ONE_SIDED: |
| 2400 | return legacy_hal::RTT_TYPE_1_SIDED; |
| 2401 | case RttType::TWO_SIDED: |
| 2402 | return legacy_hal::RTT_TYPE_2_SIDED; |
| 2403 | }; |
| 2404 | CHECK(false); |
| 2405 | } |
| 2406 | |
| 2407 | RttType convertLegacyRttTypeToAidl(legacy_hal::wifi_rtt_type type) { |
| 2408 | switch (type) { |
| 2409 | case legacy_hal::RTT_TYPE_1_SIDED: |
| 2410 | return RttType::ONE_SIDED; |
| 2411 | case legacy_hal::RTT_TYPE_2_SIDED: |
| 2412 | return RttType::TWO_SIDED; |
| 2413 | }; |
| 2414 | CHECK(false) << "Unknown legacy type: " << type; |
| 2415 | } |
| 2416 | |
| 2417 | legacy_hal::rtt_peer_type convertAidlRttPeerTypeToLegacy(RttPeerType type) { |
| 2418 | switch (type) { |
| 2419 | case RttPeerType::AP: |
| 2420 | return legacy_hal::RTT_PEER_AP; |
| 2421 | case RttPeerType::STA: |
| 2422 | return legacy_hal::RTT_PEER_STA; |
| 2423 | case RttPeerType::P2P_GO: |
| 2424 | return legacy_hal::RTT_PEER_P2P_GO; |
| 2425 | case RttPeerType::P2P_CLIENT: |
| 2426 | return legacy_hal::RTT_PEER_P2P_CLIENT; |
| 2427 | case RttPeerType::NAN_TYPE: |
| 2428 | return legacy_hal::RTT_PEER_NAN; |
| 2429 | }; |
| 2430 | CHECK(false); |
| 2431 | } |
| 2432 | |
| 2433 | legacy_hal::wifi_channel_width convertAidlWifiChannelWidthToLegacy(WifiChannelWidthInMhz type) { |
| 2434 | switch (type) { |
| 2435 | case WifiChannelWidthInMhz::WIDTH_20: |
| 2436 | return legacy_hal::WIFI_CHAN_WIDTH_20; |
| 2437 | case WifiChannelWidthInMhz::WIDTH_40: |
| 2438 | return legacy_hal::WIFI_CHAN_WIDTH_40; |
| 2439 | case WifiChannelWidthInMhz::WIDTH_80: |
| 2440 | return legacy_hal::WIFI_CHAN_WIDTH_80; |
| 2441 | case WifiChannelWidthInMhz::WIDTH_160: |
| 2442 | return legacy_hal::WIFI_CHAN_WIDTH_160; |
| 2443 | case WifiChannelWidthInMhz::WIDTH_80P80: |
| 2444 | return legacy_hal::WIFI_CHAN_WIDTH_80P80; |
| 2445 | case WifiChannelWidthInMhz::WIDTH_5: |
| 2446 | return legacy_hal::WIFI_CHAN_WIDTH_5; |
| 2447 | case WifiChannelWidthInMhz::WIDTH_10: |
| 2448 | return legacy_hal::WIFI_CHAN_WIDTH_10; |
| 2449 | case WifiChannelWidthInMhz::WIDTH_320: |
| 2450 | return legacy_hal::WIFI_CHAN_WIDTH_320; |
| 2451 | case WifiChannelWidthInMhz::WIDTH_INVALID: |
| 2452 | return legacy_hal::WIFI_CHAN_WIDTH_INVALID; |
| 2453 | }; |
| 2454 | CHECK(false); |
| 2455 | } |
| 2456 | |
| 2457 | WifiChannelWidthInMhz convertLegacyWifiChannelWidthToAidl(legacy_hal::wifi_channel_width type) { |
| 2458 | switch (type) { |
| 2459 | case legacy_hal::WIFI_CHAN_WIDTH_20: |
| 2460 | return WifiChannelWidthInMhz::WIDTH_20; |
| 2461 | case legacy_hal::WIFI_CHAN_WIDTH_40: |
| 2462 | return WifiChannelWidthInMhz::WIDTH_40; |
| 2463 | case legacy_hal::WIFI_CHAN_WIDTH_80: |
| 2464 | return WifiChannelWidthInMhz::WIDTH_80; |
| 2465 | case legacy_hal::WIFI_CHAN_WIDTH_160: |
| 2466 | return WifiChannelWidthInMhz::WIDTH_160; |
| 2467 | case legacy_hal::WIFI_CHAN_WIDTH_80P80: |
| 2468 | return WifiChannelWidthInMhz::WIDTH_80P80; |
| 2469 | case legacy_hal::WIFI_CHAN_WIDTH_5: |
| 2470 | return WifiChannelWidthInMhz::WIDTH_5; |
| 2471 | case legacy_hal::WIFI_CHAN_WIDTH_10: |
| 2472 | return WifiChannelWidthInMhz::WIDTH_10; |
| 2473 | case legacy_hal::WIFI_CHAN_WIDTH_320: |
| 2474 | return WifiChannelWidthInMhz::WIDTH_320; |
| 2475 | default: |
| 2476 | return WifiChannelWidthInMhz::WIDTH_INVALID; |
| 2477 | }; |
| 2478 | } |
| 2479 | |
| 2480 | legacy_hal::wifi_rtt_preamble convertAidlRttPreambleToLegacy(RttPreamble type) { |
| 2481 | switch (type) { |
| 2482 | case RttPreamble::LEGACY: |
| 2483 | return legacy_hal::WIFI_RTT_PREAMBLE_LEGACY; |
| 2484 | case RttPreamble::HT: |
| 2485 | return legacy_hal::WIFI_RTT_PREAMBLE_HT; |
| 2486 | case RttPreamble::VHT: |
| 2487 | return legacy_hal::WIFI_RTT_PREAMBLE_VHT; |
| 2488 | case RttPreamble::HE: |
| 2489 | return legacy_hal::WIFI_RTT_PREAMBLE_HE; |
| 2490 | case RttPreamble::EHT: |
| 2491 | return legacy_hal::WIFI_RTT_PREAMBLE_EHT; |
| 2492 | }; |
| 2493 | CHECK(false); |
| 2494 | } |
| 2495 | |
| 2496 | RttPreamble convertLegacyRttPreambleToAidl(legacy_hal::wifi_rtt_preamble type) { |
| 2497 | switch (type) { |
| 2498 | case legacy_hal::WIFI_RTT_PREAMBLE_LEGACY: |
| 2499 | return RttPreamble::LEGACY; |
| 2500 | case legacy_hal::WIFI_RTT_PREAMBLE_HT: |
| 2501 | return RttPreamble::HT; |
| 2502 | case legacy_hal::WIFI_RTT_PREAMBLE_VHT: |
| 2503 | return RttPreamble::VHT; |
| 2504 | case legacy_hal::WIFI_RTT_PREAMBLE_HE: |
| 2505 | return RttPreamble::HE; |
| 2506 | case legacy_hal::WIFI_RTT_PREAMBLE_EHT: |
| 2507 | return RttPreamble::EHT; |
| 2508 | }; |
| 2509 | CHECK(false) << "Unknown legacy type: " << type; |
| 2510 | } |
| 2511 | |
| 2512 | legacy_hal::wifi_rtt_bw convertAidlRttBwToLegacy(RttBw type) { |
| 2513 | switch (type) { |
| 2514 | case RttBw::BW_5MHZ: |
| 2515 | return legacy_hal::WIFI_RTT_BW_5; |
| 2516 | case RttBw::BW_10MHZ: |
| 2517 | return legacy_hal::WIFI_RTT_BW_10; |
| 2518 | case RttBw::BW_20MHZ: |
| 2519 | return legacy_hal::WIFI_RTT_BW_20; |
| 2520 | case RttBw::BW_40MHZ: |
| 2521 | return legacy_hal::WIFI_RTT_BW_40; |
| 2522 | case RttBw::BW_80MHZ: |
| 2523 | return legacy_hal::WIFI_RTT_BW_80; |
| 2524 | case RttBw::BW_160MHZ: |
| 2525 | return legacy_hal::WIFI_RTT_BW_160; |
| 2526 | case RttBw::BW_320MHZ: |
| 2527 | return legacy_hal::WIFI_RTT_BW_320; |
Sunil Ravi | f8fc237 | 2022-11-10 18:37:41 +0000 | [diff] [blame] | 2528 | case RttBw::BW_UNSPECIFIED: |
| 2529 | return legacy_hal::WIFI_RTT_BW_UNSPECIFIED; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2530 | }; |
| 2531 | CHECK(false); |
| 2532 | } |
| 2533 | |
| 2534 | RttBw convertLegacyRttBwToAidl(legacy_hal::wifi_rtt_bw type) { |
| 2535 | switch (type) { |
| 2536 | case legacy_hal::WIFI_RTT_BW_5: |
| 2537 | return RttBw::BW_5MHZ; |
| 2538 | case legacy_hal::WIFI_RTT_BW_10: |
| 2539 | return RttBw::BW_10MHZ; |
| 2540 | case legacy_hal::WIFI_RTT_BW_20: |
| 2541 | return RttBw::BW_20MHZ; |
| 2542 | case legacy_hal::WIFI_RTT_BW_40: |
| 2543 | return RttBw::BW_40MHZ; |
| 2544 | case legacy_hal::WIFI_RTT_BW_80: |
| 2545 | return RttBw::BW_80MHZ; |
| 2546 | case legacy_hal::WIFI_RTT_BW_160: |
| 2547 | return RttBw::BW_160MHZ; |
| 2548 | case legacy_hal::WIFI_RTT_BW_320: |
| 2549 | return RttBw::BW_320MHZ; |
Sunil Ravi | f8fc237 | 2022-11-10 18:37:41 +0000 | [diff] [blame] | 2550 | case legacy_hal::WIFI_RTT_BW_UNSPECIFIED: |
| 2551 | return RttBw::BW_UNSPECIFIED; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2552 | }; |
| 2553 | CHECK(false) << "Unknown legacy type: " << type; |
| 2554 | } |
| 2555 | |
| 2556 | legacy_hal::wifi_motion_pattern convertAidlRttMotionPatternToLegacy(RttMotionPattern type) { |
| 2557 | switch (type) { |
| 2558 | case RttMotionPattern::NOT_EXPECTED: |
| 2559 | return legacy_hal::WIFI_MOTION_NOT_EXPECTED; |
| 2560 | case RttMotionPattern::EXPECTED: |
| 2561 | return legacy_hal::WIFI_MOTION_EXPECTED; |
| 2562 | case RttMotionPattern::UNKNOWN: |
| 2563 | return legacy_hal::WIFI_MOTION_UNKNOWN; |
| 2564 | }; |
| 2565 | CHECK(false); |
| 2566 | } |
| 2567 | |
| 2568 | WifiRatePreamble convertLegacyWifiRatePreambleToAidl(uint8_t preamble) { |
| 2569 | switch (preamble) { |
| 2570 | case 0: |
| 2571 | return WifiRatePreamble::OFDM; |
| 2572 | case 1: |
| 2573 | return WifiRatePreamble::CCK; |
| 2574 | case 2: |
| 2575 | return WifiRatePreamble::HT; |
| 2576 | case 3: |
| 2577 | return WifiRatePreamble::VHT; |
| 2578 | case 4: |
| 2579 | return WifiRatePreamble::HE; |
| 2580 | case 5: |
| 2581 | return WifiRatePreamble::EHT; |
| 2582 | default: |
| 2583 | return WifiRatePreamble::RESERVED; |
| 2584 | }; |
| 2585 | CHECK(false) << "Unknown legacy preamble: " << preamble; |
| 2586 | } |
| 2587 | |
| 2588 | WifiRateNss convertLegacyWifiRateNssToAidl(uint8_t nss) { |
| 2589 | switch (nss) { |
| 2590 | case 0: |
| 2591 | return WifiRateNss::NSS_1x1; |
| 2592 | case 1: |
| 2593 | return WifiRateNss::NSS_2x2; |
| 2594 | case 2: |
| 2595 | return WifiRateNss::NSS_3x3; |
| 2596 | case 3: |
| 2597 | return WifiRateNss::NSS_4x4; |
| 2598 | }; |
| 2599 | CHECK(false) << "Unknown legacy nss: " << nss; |
| 2600 | return {}; |
| 2601 | } |
| 2602 | |
| 2603 | RttStatus convertLegacyRttStatusToAidl(legacy_hal::wifi_rtt_status status) { |
| 2604 | switch (status) { |
| 2605 | case legacy_hal::RTT_STATUS_SUCCESS: |
| 2606 | return RttStatus::SUCCESS; |
| 2607 | case legacy_hal::RTT_STATUS_FAILURE: |
| 2608 | return RttStatus::FAILURE; |
| 2609 | case legacy_hal::RTT_STATUS_FAIL_NO_RSP: |
| 2610 | return RttStatus::FAIL_NO_RSP; |
| 2611 | case legacy_hal::RTT_STATUS_FAIL_REJECTED: |
| 2612 | return RttStatus::FAIL_REJECTED; |
| 2613 | case legacy_hal::RTT_STATUS_FAIL_NOT_SCHEDULED_YET: |
| 2614 | return RttStatus::FAIL_NOT_SCHEDULED_YET; |
| 2615 | case legacy_hal::RTT_STATUS_FAIL_TM_TIMEOUT: |
| 2616 | return RttStatus::FAIL_TM_TIMEOUT; |
| 2617 | case legacy_hal::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL: |
| 2618 | return RttStatus::FAIL_AP_ON_DIFF_CHANNEL; |
| 2619 | case legacy_hal::RTT_STATUS_FAIL_NO_CAPABILITY: |
| 2620 | return RttStatus::FAIL_NO_CAPABILITY; |
| 2621 | case legacy_hal::RTT_STATUS_ABORTED: |
| 2622 | return RttStatus::ABORTED; |
| 2623 | case legacy_hal::RTT_STATUS_FAIL_INVALID_TS: |
| 2624 | return RttStatus::FAIL_INVALID_TS; |
| 2625 | case legacy_hal::RTT_STATUS_FAIL_PROTOCOL: |
| 2626 | return RttStatus::FAIL_PROTOCOL; |
| 2627 | case legacy_hal::RTT_STATUS_FAIL_SCHEDULE: |
| 2628 | return RttStatus::FAIL_SCHEDULE; |
| 2629 | case legacy_hal::RTT_STATUS_FAIL_BUSY_TRY_LATER: |
| 2630 | return RttStatus::FAIL_BUSY_TRY_LATER; |
| 2631 | case legacy_hal::RTT_STATUS_INVALID_REQ: |
| 2632 | return RttStatus::INVALID_REQ; |
| 2633 | case legacy_hal::RTT_STATUS_NO_WIFI: |
| 2634 | return RttStatus::NO_WIFI; |
| 2635 | case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE: |
| 2636 | return RttStatus::FAIL_FTM_PARAM_OVERRIDE; |
| 2637 | case legacy_hal::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE: |
| 2638 | return RttStatus::NAN_RANGING_PROTOCOL_FAILURE; |
| 2639 | case legacy_hal::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED: |
| 2640 | return RttStatus::NAN_RANGING_CONCURRENCY_NOT_SUPPORTED; |
| 2641 | }; |
| 2642 | CHECK(false) << "Unknown legacy status: " << status; |
| 2643 | } |
| 2644 | |
| 2645 | bool convertAidlWifiChannelInfoToLegacy(const WifiChannelInfo& aidl_info, |
| 2646 | legacy_hal::wifi_channel_info* legacy_info) { |
| 2647 | if (!legacy_info) { |
| 2648 | return false; |
| 2649 | } |
| 2650 | *legacy_info = {}; |
| 2651 | legacy_info->width = convertAidlWifiChannelWidthToLegacy(aidl_info.width); |
| 2652 | legacy_info->center_freq = aidl_info.centerFreq; |
| 2653 | legacy_info->center_freq0 = aidl_info.centerFreq0; |
| 2654 | legacy_info->center_freq1 = aidl_info.centerFreq1; |
| 2655 | return true; |
| 2656 | } |
| 2657 | |
| 2658 | bool convertLegacyWifiChannelInfoToAidl(const legacy_hal::wifi_channel_info& legacy_info, |
| 2659 | WifiChannelInfo* aidl_info) { |
| 2660 | if (!aidl_info) { |
| 2661 | return false; |
| 2662 | } |
| 2663 | *aidl_info = {}; |
| 2664 | aidl_info->width = convertLegacyWifiChannelWidthToAidl(legacy_info.width); |
| 2665 | aidl_info->centerFreq = legacy_info.center_freq; |
| 2666 | aidl_info->centerFreq0 = legacy_info.center_freq0; |
| 2667 | aidl_info->centerFreq1 = legacy_info.center_freq1; |
| 2668 | return true; |
| 2669 | } |
| 2670 | |
| 2671 | bool convertAidlRttConfigToLegacy(const RttConfig& aidl_config, |
| 2672 | legacy_hal::wifi_rtt_config* legacy_config) { |
| 2673 | if (!legacy_config) { |
| 2674 | return false; |
| 2675 | } |
| 2676 | *legacy_config = {}; |
| 2677 | CHECK(aidl_config.addr.size() == sizeof(legacy_config->addr)); |
| 2678 | memcpy(legacy_config->addr, aidl_config.addr.data(), aidl_config.addr.size()); |
| 2679 | legacy_config->type = convertAidlRttTypeToLegacy(aidl_config.type); |
| 2680 | legacy_config->peer = convertAidlRttPeerTypeToLegacy(aidl_config.peer); |
| 2681 | if (!convertAidlWifiChannelInfoToLegacy(aidl_config.channel, &legacy_config->channel)) { |
| 2682 | return false; |
| 2683 | } |
| 2684 | legacy_config->burst_period = aidl_config.burstPeriod; |
| 2685 | legacy_config->num_burst = aidl_config.numBurst; |
| 2686 | legacy_config->num_frames_per_burst = aidl_config.numFramesPerBurst; |
| 2687 | legacy_config->num_retries_per_rtt_frame = aidl_config.numRetriesPerRttFrame; |
| 2688 | legacy_config->num_retries_per_ftmr = aidl_config.numRetriesPerFtmr; |
| 2689 | legacy_config->LCI_request = aidl_config.mustRequestLci; |
| 2690 | legacy_config->LCR_request = aidl_config.mustRequestLcr; |
| 2691 | legacy_config->burst_duration = aidl_config.burstDuration; |
| 2692 | legacy_config->preamble = convertAidlRttPreambleToLegacy(aidl_config.preamble); |
| 2693 | legacy_config->bw = convertAidlRttBwToLegacy(aidl_config.bw); |
| 2694 | return true; |
| 2695 | } |
| 2696 | |
| 2697 | bool convertAidlVectorOfRttConfigToLegacy( |
| 2698 | const std::vector<RttConfig>& aidl_configs, |
| 2699 | std::vector<legacy_hal::wifi_rtt_config>* legacy_configs) { |
| 2700 | if (!legacy_configs) { |
| 2701 | return false; |
| 2702 | } |
| 2703 | *legacy_configs = {}; |
| 2704 | for (const auto& aidl_config : aidl_configs) { |
| 2705 | legacy_hal::wifi_rtt_config legacy_config; |
| 2706 | if (!convertAidlRttConfigToLegacy(aidl_config, &legacy_config)) { |
| 2707 | return false; |
| 2708 | } |
| 2709 | legacy_configs->push_back(legacy_config); |
| 2710 | } |
| 2711 | return true; |
| 2712 | } |
| 2713 | |
| 2714 | bool convertAidlRttLciInformationToLegacy(const RttLciInformation& aidl_info, |
| 2715 | legacy_hal::wifi_lci_information* legacy_info) { |
| 2716 | if (!legacy_info) { |
| 2717 | return false; |
| 2718 | } |
| 2719 | *legacy_info = {}; |
| 2720 | legacy_info->latitude = aidl_info.latitude; |
| 2721 | legacy_info->longitude = aidl_info.longitude; |
| 2722 | legacy_info->altitude = aidl_info.altitude; |
| 2723 | legacy_info->latitude_unc = aidl_info.latitudeUnc; |
| 2724 | legacy_info->longitude_unc = aidl_info.longitudeUnc; |
| 2725 | legacy_info->altitude_unc = aidl_info.altitudeUnc; |
| 2726 | legacy_info->motion_pattern = convertAidlRttMotionPatternToLegacy(aidl_info.motionPattern); |
| 2727 | legacy_info->floor = aidl_info.floor; |
| 2728 | legacy_info->height_above_floor = aidl_info.heightAboveFloor; |
| 2729 | legacy_info->height_unc = aidl_info.heightUnc; |
| 2730 | return true; |
| 2731 | } |
| 2732 | |
| 2733 | bool convertAidlRttLcrInformationToLegacy(const RttLcrInformation& aidl_info, |
| 2734 | legacy_hal::wifi_lcr_information* legacy_info) { |
| 2735 | if (!legacy_info) { |
| 2736 | return false; |
| 2737 | } |
| 2738 | *legacy_info = {}; |
| 2739 | CHECK(aidl_info.countryCode.size() == sizeof(legacy_info->country_code)); |
| 2740 | memcpy(legacy_info->country_code, aidl_info.countryCode.data(), aidl_info.countryCode.size()); |
| 2741 | if (aidl_info.civicInfo.size() > sizeof(legacy_info->civic_info)) { |
| 2742 | return false; |
| 2743 | } |
| 2744 | legacy_info->length = aidl_info.civicInfo.size(); |
| 2745 | memcpy(legacy_info->civic_info, aidl_info.civicInfo.c_str(), aidl_info.civicInfo.size()); |
| 2746 | return true; |
| 2747 | } |
| 2748 | |
| 2749 | bool convertAidlRttResponderToLegacy(const RttResponder& aidl_responder, |
| 2750 | legacy_hal::wifi_rtt_responder* legacy_responder) { |
| 2751 | if (!legacy_responder) { |
| 2752 | return false; |
| 2753 | } |
| 2754 | *legacy_responder = {}; |
| 2755 | if (!convertAidlWifiChannelInfoToLegacy(aidl_responder.channel, &legacy_responder->channel)) { |
| 2756 | return false; |
| 2757 | } |
| 2758 | legacy_responder->preamble = convertAidlRttPreambleToLegacy(aidl_responder.preamble); |
| 2759 | return true; |
| 2760 | } |
| 2761 | |
| 2762 | bool convertLegacyRttResponderToAidl(const legacy_hal::wifi_rtt_responder& legacy_responder, |
| 2763 | RttResponder* aidl_responder) { |
| 2764 | if (!aidl_responder) { |
| 2765 | return false; |
| 2766 | } |
| 2767 | *aidl_responder = {}; |
| 2768 | if (!convertLegacyWifiChannelInfoToAidl(legacy_responder.channel, &aidl_responder->channel)) { |
| 2769 | return false; |
| 2770 | } |
| 2771 | aidl_responder->preamble = convertLegacyRttPreambleToAidl(legacy_responder.preamble); |
| 2772 | return true; |
| 2773 | } |
| 2774 | |
| 2775 | bool convertLegacyRttCapabilitiesToAidl( |
| 2776 | const legacy_hal::wifi_rtt_capabilities& legacy_capabilities, |
| 2777 | RttCapabilities* aidl_capabilities) { |
| 2778 | if (!aidl_capabilities) { |
| 2779 | return false; |
| 2780 | } |
| 2781 | *aidl_capabilities = {}; |
| 2782 | aidl_capabilities->rttOneSidedSupported = legacy_capabilities.rtt_one_sided_supported; |
| 2783 | aidl_capabilities->rttFtmSupported = legacy_capabilities.rtt_ftm_supported; |
| 2784 | aidl_capabilities->lciSupported = legacy_capabilities.lci_support; |
| 2785 | aidl_capabilities->lcrSupported = legacy_capabilities.lcr_support; |
| 2786 | aidl_capabilities->responderSupported = legacy_capabilities.responder_supported; |
| 2787 | int32_t preambleSupport = 0; |
| 2788 | for (const auto flag : {legacy_hal::WIFI_RTT_PREAMBLE_LEGACY, legacy_hal::WIFI_RTT_PREAMBLE_HT, |
| 2789 | legacy_hal::WIFI_RTT_PREAMBLE_VHT, legacy_hal::WIFI_RTT_PREAMBLE_HE, |
| 2790 | legacy_hal::WIFI_RTT_PREAMBLE_EHT}) { |
| 2791 | if (legacy_capabilities.preamble_support & flag) { |
| 2792 | preambleSupport |= static_cast<std::underlying_type<RttPreamble>::type>( |
| 2793 | convertLegacyRttPreambleToAidl(flag)); |
| 2794 | } |
| 2795 | } |
| 2796 | aidl_capabilities->preambleSupport = static_cast<RttPreamble>(preambleSupport); |
| 2797 | int32_t bwSupport = 0; |
| 2798 | for (const auto flag : |
| 2799 | {legacy_hal::WIFI_RTT_BW_5, legacy_hal::WIFI_RTT_BW_10, legacy_hal::WIFI_RTT_BW_20, |
| 2800 | legacy_hal::WIFI_RTT_BW_40, legacy_hal::WIFI_RTT_BW_80, legacy_hal::WIFI_RTT_BW_160, |
| 2801 | legacy_hal::WIFI_RTT_BW_320}) { |
| 2802 | if (legacy_capabilities.bw_support & flag) { |
| 2803 | bwSupport |= |
| 2804 | static_cast<std::underlying_type<RttBw>::type>(convertLegacyRttBwToAidl(flag)); |
| 2805 | } |
| 2806 | } |
| 2807 | aidl_capabilities->bwSupport = static_cast<RttBw>(bwSupport); |
| 2808 | aidl_capabilities->mcVersion = legacy_capabilities.mc_version; |
| 2809 | return true; |
| 2810 | } |
| 2811 | |
| 2812 | bool convertLegacyWifiRateInfoToAidl(const legacy_hal::wifi_rate& legacy_rate, |
| 2813 | WifiRateInfo* aidl_rate) { |
| 2814 | if (!aidl_rate) { |
| 2815 | return false; |
| 2816 | } |
| 2817 | *aidl_rate = {}; |
| 2818 | aidl_rate->preamble = convertLegacyWifiRatePreambleToAidl(legacy_rate.preamble); |
| 2819 | aidl_rate->nss = convertLegacyWifiRateNssToAidl(legacy_rate.nss); |
| 2820 | aidl_rate->bw = convertLegacyWifiChannelWidthToAidl( |
| 2821 | static_cast<legacy_hal::wifi_channel_width>(legacy_rate.bw)); |
| 2822 | aidl_rate->rateMcsIdx = legacy_rate.rateMcsIdx; |
| 2823 | aidl_rate->bitRateInKbps = legacy_rate.bitrate; |
| 2824 | return true; |
| 2825 | } |
| 2826 | |
| 2827 | bool convertLegacyRttResultToAidl(const legacy_hal::wifi_rtt_result& legacy_result, |
| 2828 | RttResult* aidl_result) { |
| 2829 | if (!aidl_result) { |
| 2830 | return false; |
| 2831 | } |
| 2832 | *aidl_result = {}; |
| 2833 | aidl_result->addr = std::array<uint8_t, 6>(); |
| 2834 | CHECK(sizeof(legacy_result.addr) == aidl_result->addr.size()); |
| 2835 | std::copy(legacy_result.addr, legacy_result.addr + 6, std::begin(aidl_result->addr)); |
| 2836 | aidl_result->burstNum = legacy_result.burst_num; |
| 2837 | aidl_result->measurementNumber = legacy_result.measurement_number; |
| 2838 | aidl_result->successNumber = legacy_result.success_number; |
| 2839 | aidl_result->numberPerBurstPeer = legacy_result.number_per_burst_peer; |
| 2840 | aidl_result->status = convertLegacyRttStatusToAidl(legacy_result.status); |
| 2841 | aidl_result->retryAfterDuration = legacy_result.retry_after_duration; |
| 2842 | aidl_result->type = convertLegacyRttTypeToAidl(legacy_result.type); |
| 2843 | aidl_result->rssi = legacy_result.rssi; |
| 2844 | aidl_result->rssiSpread = legacy_result.rssi_spread; |
| 2845 | if (!convertLegacyWifiRateInfoToAidl(legacy_result.tx_rate, &aidl_result->txRate)) { |
| 2846 | return false; |
| 2847 | } |
| 2848 | if (!convertLegacyWifiRateInfoToAidl(legacy_result.rx_rate, &aidl_result->rxRate)) { |
| 2849 | return false; |
| 2850 | } |
| 2851 | aidl_result->rtt = legacy_result.rtt; |
| 2852 | aidl_result->rttSd = legacy_result.rtt_sd; |
| 2853 | aidl_result->rttSpread = legacy_result.rtt_spread; |
| 2854 | aidl_result->distanceInMm = legacy_result.distance_mm; |
| 2855 | aidl_result->distanceSdInMm = legacy_result.distance_sd_mm; |
| 2856 | aidl_result->distanceSpreadInMm = legacy_result.distance_spread_mm; |
| 2857 | aidl_result->timeStampInUs = legacy_result.ts; |
| 2858 | aidl_result->burstDurationInMs = legacy_result.burst_duration; |
| 2859 | aidl_result->negotiatedBurstNum = legacy_result.negotiated_burst_num; |
| 2860 | if (legacy_result.LCI && !convertLegacyIeToAidl(*legacy_result.LCI, &aidl_result->lci)) { |
| 2861 | return false; |
| 2862 | } |
| 2863 | if (legacy_result.LCR && !convertLegacyIeToAidl(*legacy_result.LCR, &aidl_result->lcr)) { |
| 2864 | return false; |
| 2865 | } |
| 2866 | return true; |
| 2867 | } |
| 2868 | |
| 2869 | bool convertLegacyVectorOfRttResultToAidl( |
| 2870 | const std::vector<const legacy_hal::wifi_rtt_result*>& legacy_results, |
| 2871 | std::vector<RttResult>* aidl_results) { |
| 2872 | if (!aidl_results) { |
| 2873 | return false; |
| 2874 | } |
| 2875 | *aidl_results = {}; |
| 2876 | for (const auto legacy_result : legacy_results) { |
| 2877 | RttResult aidl_result; |
| 2878 | if (!convertLegacyRttResultToAidl(*legacy_result, &aidl_result)) { |
| 2879 | return false; |
| 2880 | } |
Sunil Ravi | f8fc237 | 2022-11-10 18:37:41 +0000 | [diff] [blame] | 2881 | aidl_result.channelFreqMHz = 0; |
| 2882 | aidl_result.packetBw = RttBw::BW_UNSPECIFIED; |
| 2883 | aidl_results->push_back(aidl_result); |
| 2884 | } |
| 2885 | return true; |
| 2886 | } |
| 2887 | |
| 2888 | bool convertLegacyVectorOfRttResultV2ToAidl( |
| 2889 | const std::vector<const legacy_hal::wifi_rtt_result_v2*>& legacy_results, |
| 2890 | std::vector<RttResult>* aidl_results) { |
| 2891 | if (!aidl_results) { |
| 2892 | return false; |
| 2893 | } |
| 2894 | *aidl_results = {}; |
| 2895 | for (const auto legacy_result : legacy_results) { |
| 2896 | RttResult aidl_result; |
| 2897 | if (!convertLegacyRttResultToAidl(legacy_result->rtt_result, &aidl_result)) { |
| 2898 | return false; |
| 2899 | } |
| 2900 | aidl_result.channelFreqMHz = |
| 2901 | legacy_result->frequency != UNSPECIFIED ? legacy_result->frequency : 0; |
| 2902 | aidl_result.packetBw = convertLegacyRttBwToAidl(legacy_result->packet_bw); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2903 | aidl_results->push_back(aidl_result); |
| 2904 | } |
| 2905 | return true; |
| 2906 | } |
| 2907 | |
| 2908 | legacy_hal::wifi_interface_type convertAidlIfaceTypeToLegacy(IfaceType aidl_interface_type) { |
| 2909 | switch (aidl_interface_type) { |
| 2910 | case IfaceType::STA: |
| 2911 | return legacy_hal::WIFI_INTERFACE_TYPE_STA; |
| 2912 | case IfaceType::AP: |
| 2913 | return legacy_hal::WIFI_INTERFACE_TYPE_AP; |
| 2914 | case IfaceType::P2P: |
| 2915 | return legacy_hal::WIFI_INTERFACE_TYPE_P2P; |
| 2916 | case IfaceType::NAN_IFACE: |
| 2917 | return legacy_hal::WIFI_INTERFACE_TYPE_NAN; |
| 2918 | } |
| 2919 | CHECK(false); |
| 2920 | } |
| 2921 | |
| 2922 | legacy_hal::wifi_multi_sta_use_case convertAidlMultiStaUseCaseToLegacy( |
| 2923 | IWifiChip::MultiStaUseCase use_case) { |
| 2924 | switch (use_case) { |
| 2925 | case IWifiChip::MultiStaUseCase::DUAL_STA_TRANSIENT_PREFER_PRIMARY: |
| 2926 | return legacy_hal::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY; |
| 2927 | case IWifiChip::MultiStaUseCase::DUAL_STA_NON_TRANSIENT_UNBIASED: |
| 2928 | return legacy_hal::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED; |
| 2929 | } |
| 2930 | CHECK(false); |
| 2931 | } |
| 2932 | |
| 2933 | bool convertAidlCoexUnsafeChannelToLegacy( |
| 2934 | const IWifiChip::CoexUnsafeChannel& aidl_unsafe_channel, |
| 2935 | legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel) { |
| 2936 | if (!legacy_unsafe_channel) { |
| 2937 | return false; |
| 2938 | } |
| 2939 | *legacy_unsafe_channel = {}; |
| 2940 | switch (aidl_unsafe_channel.band) { |
| 2941 | case WifiBand::BAND_24GHZ: |
| 2942 | legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_2_4_BAND; |
| 2943 | break; |
| 2944 | case WifiBand::BAND_5GHZ: |
| 2945 | legacy_unsafe_channel->band = legacy_hal::WLAN_MAC_5_0_BAND; |
| 2946 | break; |
| 2947 | default: |
| 2948 | return false; |
| 2949 | }; |
| 2950 | legacy_unsafe_channel->channel = aidl_unsafe_channel.channel; |
| 2951 | legacy_unsafe_channel->power_cap_dbm = aidl_unsafe_channel.powerCapDbm; |
| 2952 | return true; |
| 2953 | } |
| 2954 | |
| 2955 | bool convertAidlVectorOfCoexUnsafeChannelToLegacy( |
| 2956 | const std::vector<IWifiChip::CoexUnsafeChannel>& aidl_unsafe_channels, |
| 2957 | std::vector<legacy_hal::wifi_coex_unsafe_channel>* legacy_unsafe_channels) { |
| 2958 | if (!legacy_unsafe_channels) { |
| 2959 | return false; |
| 2960 | } |
| 2961 | *legacy_unsafe_channels = {}; |
| 2962 | for (const auto& aidl_unsafe_channel : aidl_unsafe_channels) { |
| 2963 | legacy_hal::wifi_coex_unsafe_channel legacy_unsafe_channel; |
| 2964 | if (!aidl_struct_util::convertAidlCoexUnsafeChannelToLegacy(aidl_unsafe_channel, |
| 2965 | &legacy_unsafe_channel)) { |
| 2966 | return false; |
| 2967 | } |
| 2968 | legacy_unsafe_channels->push_back(legacy_unsafe_channel); |
| 2969 | } |
| 2970 | return true; |
| 2971 | } |
| 2972 | |
| 2973 | WifiAntennaMode convertLegacyAntennaConfigurationToAidl(uint32_t antenna_cfg) { |
| 2974 | switch (antenna_cfg) { |
| 2975 | case legacy_hal::WIFI_ANTENNA_1X1: |
| 2976 | return WifiAntennaMode::WIFI_ANTENNA_MODE_1X1; |
| 2977 | case legacy_hal::WIFI_ANTENNA_2X2: |
| 2978 | return WifiAntennaMode::WIFI_ANTENNA_MODE_2X2; |
| 2979 | case legacy_hal::WIFI_ANTENNA_3X3: |
| 2980 | return WifiAntennaMode::WIFI_ANTENNA_MODE_3X3; |
| 2981 | case legacy_hal::WIFI_ANTENNA_4X4: |
| 2982 | return WifiAntennaMode::WIFI_ANTENNA_MODE_4X4; |
| 2983 | default: |
| 2984 | return WifiAntennaMode::WIFI_ANTENNA_MODE_UNSPECIFIED; |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | bool convertLegacyWifiRadioConfigurationToAidl( |
| 2989 | legacy_hal::wifi_radio_configuration* radio_configuration, |
| 2990 | WifiRadioConfiguration* aidl_radio_configuration) { |
| 2991 | if (!aidl_radio_configuration) { |
| 2992 | return false; |
| 2993 | } |
| 2994 | *aidl_radio_configuration = {}; |
| 2995 | aidl_radio_configuration->bandInfo = |
| 2996 | aidl_struct_util::convertLegacyMacBandToAidlWifiBand(radio_configuration->band); |
| 2997 | if (aidl_radio_configuration->bandInfo == WifiBand::BAND_UNSPECIFIED) { |
| 2998 | LOG(ERROR) << "Unspecified band"; |
| 2999 | return false; |
| 3000 | } |
| 3001 | aidl_radio_configuration->antennaMode = |
| 3002 | aidl_struct_util::convertLegacyAntennaConfigurationToAidl( |
| 3003 | radio_configuration->antenna_cfg); |
| 3004 | return true; |
| 3005 | } |
| 3006 | |
| 3007 | bool convertLegacyRadioCombinationsMatrixToAidl( |
| 3008 | legacy_hal::wifi_radio_combination_matrix* legacy_matrix, |
| 3009 | WifiRadioCombinationMatrix* aidl_matrix) { |
| 3010 | if (!aidl_matrix || !legacy_matrix) { |
| 3011 | return false; |
| 3012 | } |
| 3013 | *aidl_matrix = {}; |
| 3014 | |
| 3015 | int num_combinations = legacy_matrix->num_radio_combinations; |
| 3016 | std::vector<WifiRadioCombination> radio_combinations_vec; |
| 3017 | if (!num_combinations) { |
| 3018 | LOG(ERROR) << "zero radio combinations"; |
| 3019 | return false; |
| 3020 | } |
| 3021 | wifi_radio_combination* l_radio_combinations_ptr = legacy_matrix->radio_combinations; |
| 3022 | for (int i = 0; i < num_combinations; i++) { |
| 3023 | int num_configurations = l_radio_combinations_ptr->num_radio_configurations; |
| 3024 | WifiRadioCombination radioCombination; |
| 3025 | std::vector<WifiRadioConfiguration> radio_configurations_vec; |
| 3026 | if (!num_configurations) { |
| 3027 | LOG(ERROR) << "zero radio configurations"; |
| 3028 | return false; |
| 3029 | } |
| 3030 | for (int j = 0; j < num_configurations; j++) { |
| 3031 | WifiRadioConfiguration radioConfiguration; |
| 3032 | wifi_radio_configuration* l_radio_configurations_ptr = |
| 3033 | &l_radio_combinations_ptr->radio_configurations[j]; |
| 3034 | if (!aidl_struct_util::convertLegacyWifiRadioConfigurationToAidl( |
| 3035 | l_radio_configurations_ptr, &radioConfiguration)) { |
| 3036 | LOG(ERROR) << "Error converting wifi radio configuration"; |
| 3037 | return false; |
| 3038 | } |
| 3039 | radio_configurations_vec.push_back(radioConfiguration); |
| 3040 | } |
| 3041 | radioCombination.radioConfigurations = radio_configurations_vec; |
| 3042 | radio_combinations_vec.push_back(radioCombination); |
| 3043 | l_radio_combinations_ptr = |
| 3044 | (wifi_radio_combination*)((u8*)l_radio_combinations_ptr + |
| 3045 | sizeof(wifi_radio_combination) + |
| 3046 | (sizeof(wifi_radio_configuration) * num_configurations)); |
| 3047 | } |
| 3048 | aidl_matrix->radioCombinations = radio_combinations_vec; |
| 3049 | return true; |
| 3050 | } |
| 3051 | |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3052 | bool convertAidlNanPairingInitiatorRequestToLegacy(const NanPairingRequest& aidl_request, |
| 3053 | legacy_hal::NanPairingRequest* legacy_request) { |
| 3054 | if (!legacy_request) { |
| 3055 | LOG(ERROR) << "convertAidlNanPairingInitiatorRequestToLegacy: " |
| 3056 | "legacy_request is null"; |
| 3057 | return false; |
| 3058 | } |
| 3059 | *legacy_request = {}; |
| 3060 | |
| 3061 | legacy_request->requestor_instance_id = aidl_request.peerId; |
| 3062 | memcpy(legacy_request->peer_disc_mac_addr, aidl_request.peerDiscMacAddr.data(), 6); |
| 3063 | legacy_request->nan_pairing_request_type = |
| 3064 | convertAidlNanPairingRequestTypeToLegacy(aidl_request.requestType); |
| 3065 | legacy_request->enable_pairing_cache = aidl_request.enablePairingCache; |
| 3066 | |
| 3067 | memcpy(legacy_request->nan_identity_key, aidl_request.pairingIdentityKey.data(), |
| 3068 | NAN_IDENTITY_KEY_LEN); |
| 3069 | |
| 3070 | legacy_request->is_opportunistic = |
| 3071 | aidl_request.securityConfig.securityType == NanPairingSecurityType::OPPORTUNISTIC ? 1 |
| 3072 | : 0; |
| 3073 | legacy_request->akm = convertAidlAkmTypeToLegacy(aidl_request.securityConfig.akm); |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 3074 | legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3075 | if (aidl_request.securityConfig.securityType == NanPairingSecurityType::PMK) { |
| 3076 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 3077 | legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); |
| 3078 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 3079 | LOG(ERROR) << "convertAidlNanPairingInitiatorRequestToLegacy: " |
| 3080 | "invalid pmk_len"; |
| 3081 | return false; |
| 3082 | } |
| 3083 | memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), |
| 3084 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 3085 | } |
| 3086 | if (aidl_request.securityConfig.securityType == NanPairingSecurityType::PASSPHRASE) { |
| 3087 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 3088 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 3089 | aidl_request.securityConfig.passphrase.size(); |
| 3090 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 3091 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 3092 | LOG(ERROR) << "convertAidlNanPairingInitiatorRequestToLegacy: " |
| 3093 | "passphrase_len too small"; |
| 3094 | return false; |
| 3095 | } |
| 3096 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 3097 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 3098 | LOG(ERROR) << "convertAidlNanPairingInitiatorRequestToLegacy: " |
| 3099 | "passphrase_len too large"; |
| 3100 | return false; |
| 3101 | } |
| 3102 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 3103 | aidl_request.securityConfig.passphrase.data(), |
| 3104 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 3105 | } |
| 3106 | |
| 3107 | return true; |
| 3108 | } |
| 3109 | |
| 3110 | bool convertAidlNanPairingIndicationResponseToLegacy( |
| 3111 | const NanRespondToPairingIndicationRequest& aidl_request, |
| 3112 | legacy_hal::NanPairingIndicationResponse* legacy_request) { |
| 3113 | if (!legacy_request) { |
| 3114 | LOG(ERROR) << "convertAidlNanPairingIndicationResponseToLegacy: " |
| 3115 | "legacy_request is null"; |
| 3116 | return false; |
| 3117 | } |
| 3118 | *legacy_request = {}; |
| 3119 | |
| 3120 | legacy_request->pairing_instance_id = aidl_request.pairingInstanceId; |
| 3121 | legacy_request->nan_pairing_request_type = |
| 3122 | convertAidlNanPairingRequestTypeToLegacy(aidl_request.requestType); |
| 3123 | legacy_request->enable_pairing_cache = aidl_request.enablePairingCache; |
| 3124 | |
| 3125 | memcpy(legacy_request->nan_identity_key, aidl_request.pairingIdentityKey.data(), |
| 3126 | NAN_IDENTITY_KEY_LEN); |
| 3127 | |
| 3128 | legacy_request->is_opportunistic = |
| 3129 | aidl_request.securityConfig.securityType == NanPairingSecurityType::OPPORTUNISTIC ? 1 |
| 3130 | : 0; |
| 3131 | legacy_request->akm = convertAidlAkmTypeToLegacy(aidl_request.securityConfig.akm); |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 3132 | legacy_request->cipher_type = (unsigned int)aidl_request.securityConfig.cipherType; |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3133 | legacy_request->rsp_code = |
| 3134 | aidl_request.acceptRequest ? NAN_PAIRING_REQUEST_ACCEPT : NAN_PAIRING_REQUEST_REJECT; |
| 3135 | if (aidl_request.securityConfig.securityType == NanPairingSecurityType::PMK) { |
| 3136 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PMK; |
| 3137 | legacy_request->key_info.body.pmk_info.pmk_len = aidl_request.securityConfig.pmk.size(); |
| 3138 | if (legacy_request->key_info.body.pmk_info.pmk_len != NAN_PMK_INFO_LEN) { |
| 3139 | LOG(ERROR) << "convertAidlNanPairingIndicationResponseToLegacy: " |
| 3140 | "invalid pmk_len"; |
| 3141 | return false; |
| 3142 | } |
| 3143 | memcpy(legacy_request->key_info.body.pmk_info.pmk, aidl_request.securityConfig.pmk.data(), |
| 3144 | legacy_request->key_info.body.pmk_info.pmk_len); |
| 3145 | } |
| 3146 | if (aidl_request.securityConfig.securityType == NanPairingSecurityType::PASSPHRASE) { |
| 3147 | legacy_request->key_info.key_type = legacy_hal::NAN_SECURITY_KEY_INPUT_PASSPHRASE; |
| 3148 | legacy_request->key_info.body.passphrase_info.passphrase_len = |
| 3149 | aidl_request.securityConfig.passphrase.size(); |
| 3150 | if (legacy_request->key_info.body.passphrase_info.passphrase_len < |
| 3151 | NAN_SECURITY_MIN_PASSPHRASE_LEN) { |
| 3152 | LOG(ERROR) << "convertAidlNanPairingIndicationResponseToLegacy: " |
| 3153 | "passphrase_len too small"; |
| 3154 | return false; |
| 3155 | } |
| 3156 | if (legacy_request->key_info.body.passphrase_info.passphrase_len > |
| 3157 | NAN_SECURITY_MAX_PASSPHRASE_LEN) { |
| 3158 | LOG(ERROR) << "convertAidlNanPairingIndicationResponseToLegacy: " |
| 3159 | "passphrase_len too large"; |
| 3160 | return false; |
| 3161 | } |
| 3162 | memcpy(legacy_request->key_info.body.passphrase_info.passphrase, |
| 3163 | aidl_request.securityConfig.passphrase.data(), |
| 3164 | legacy_request->key_info.body.passphrase_info.passphrase_len); |
| 3165 | } |
| 3166 | |
| 3167 | return true; |
| 3168 | } |
| 3169 | |
| 3170 | bool convertAidlNanBootstrappingInitiatorRequestToLegacy( |
| 3171 | const NanBootstrappingRequest& aidl_request, |
| 3172 | legacy_hal::NanBootstrappingRequest* legacy_request) { |
| 3173 | if (!legacy_request) { |
| 3174 | LOG(ERROR) << "convertAidlNanBootstrappingInitiatorRequestToLegacy: " |
| 3175 | "legacy_request is null"; |
| 3176 | return false; |
| 3177 | } |
| 3178 | *legacy_request = {}; |
| 3179 | |
| 3180 | legacy_request->requestor_instance_id = aidl_request.peerId; |
| 3181 | memcpy(legacy_request->peer_disc_mac_addr, aidl_request.peerDiscMacAddr.data(), 6); |
| 3182 | legacy_request->request_bootstrapping_method = |
| 3183 | convertAidlBootstrappingMethodToLegacy(aidl_request.requestBootstrappingMethod); |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 3184 | legacy_request->cookie_length = aidl_request.cookie.size(); |
| 3185 | |
| 3186 | memcpy(legacy_request->cookie, aidl_request.cookie.data(), legacy_request->cookie_length); |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3187 | |
| 3188 | return true; |
| 3189 | } |
| 3190 | |
| 3191 | bool convertAidlNanBootstrappingIndicationResponseToLegacy( |
| 3192 | const NanBootstrappingResponse& aidl_request, |
| 3193 | legacy_hal::NanBootstrappingIndicationResponse* legacy_request) { |
| 3194 | if (!legacy_request) { |
| 3195 | LOG(ERROR) << "convertAidlNanBootstrappingIndicationResponseToLegacy: " |
| 3196 | "legacy_request is null"; |
| 3197 | return false; |
| 3198 | } |
| 3199 | *legacy_request = {}; |
| 3200 | |
| 3201 | legacy_request->service_instance_id = aidl_request.bootstrappingInstanceId; |
| 3202 | legacy_request->rsp_code = aidl_request.acceptRequest ? NAN_BOOTSTRAPPING_REQUEST_ACCEPT |
| 3203 | : NAN_BOOTSTRAPPING_REQUEST_REJECT; |
| 3204 | |
| 3205 | return true; |
| 3206 | } |
| 3207 | |
| 3208 | bool convertLegacyNanPairingRequestIndToAidl(const legacy_hal::NanPairingRequestInd& legacy_ind, |
| 3209 | NanPairingRequestInd* aidl_ind) { |
| 3210 | if (!aidl_ind) { |
| 3211 | LOG(ERROR) << "convertLegacyNanPairingRequestIndToAidl: aidl_ind is null"; |
| 3212 | return false; |
| 3213 | } |
| 3214 | *aidl_ind = {}; |
| 3215 | |
| 3216 | aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 3217 | aidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 3218 | aidl_ind->peerDiscMacAddr = std::array<uint8_t, 6>(); |
| 3219 | std::copy(legacy_ind.peer_disc_mac_addr, legacy_ind.peer_disc_mac_addr + 6, |
| 3220 | std::begin(aidl_ind->peerDiscMacAddr)); |
| 3221 | aidl_ind->pairingInstanceId = legacy_ind.pairing_instance_id; |
| 3222 | aidl_ind->enablePairingCache = legacy_ind.enable_pairing_cache == 1; |
| 3223 | aidl_ind->requestType = |
| 3224 | convertLegacyNanPairingRequestTypeToAidl(legacy_ind.nan_pairing_request_type); |
| 3225 | if (!convertLegacyNiraToAidl(legacy_ind.nira, &aidl_ind->peerNira)) { |
| 3226 | return false; |
| 3227 | } |
| 3228 | return true; |
| 3229 | } |
| 3230 | |
| 3231 | bool convertLegacyNanPairingConfirmIndToAidl(const legacy_hal::NanPairingConfirmInd& legacy_ind, |
| 3232 | NanPairingConfirmInd* aidl_ind) { |
| 3233 | if (!aidl_ind) { |
| 3234 | LOG(ERROR) << "convertLegacyNanPairingRequestIndToAidl: aidl_ind is null"; |
| 3235 | return false; |
| 3236 | } |
| 3237 | *aidl_ind = {}; |
| 3238 | |
| 3239 | aidl_ind->pairingInstanceId = legacy_ind.pairing_instance_id; |
| 3240 | aidl_ind->enablePairingCache = legacy_ind.enable_pairing_cache == 1; |
| 3241 | aidl_ind->requestType = |
| 3242 | convertLegacyNanPairingRequestTypeToAidl(legacy_ind.nan_pairing_request_type); |
| 3243 | aidl_ind->pairingSuccess = legacy_ind.rsp_code == NAN_PAIRING_REQUEST_ACCEPT; |
| 3244 | aidl_ind->status.status = convertLegacyNanStatusTypeToAidl(legacy_ind.reason_code); |
| 3245 | if (!convertLegacyNpsaToAidl(legacy_ind.npk_security_association, &aidl_ind->npksa)) { |
| 3246 | return false; |
| 3247 | } |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
| 3251 | bool convertLegacyNanBootstrappingRequestIndToAidl( |
| 3252 | const legacy_hal::NanBootstrappingRequestInd& legacy_ind, |
| 3253 | NanBootstrappingRequestInd* aidl_ind) { |
| 3254 | if (!aidl_ind) { |
| 3255 | LOG(ERROR) << "convertLegacyNanBootstrappingRequestIndToAidl: aidl_ind is null"; |
| 3256 | return false; |
| 3257 | } |
| 3258 | *aidl_ind = {}; |
| 3259 | |
| 3260 | aidl_ind->discoverySessionId = legacy_ind.publish_subscribe_id; |
| 3261 | aidl_ind->peerId = legacy_ind.requestor_instance_id; |
| 3262 | aidl_ind->peerDiscMacAddr = std::array<uint8_t, 6>(); |
| 3263 | std::copy(legacy_ind.peer_disc_mac_addr, legacy_ind.peer_disc_mac_addr + 6, |
| 3264 | std::begin(aidl_ind->peerDiscMacAddr)); |
| 3265 | aidl_ind->bootstrappingInstanceId = legacy_ind.bootstrapping_instance_id; |
| 3266 | aidl_ind->requestBootstrappingMethod = |
| 3267 | convertLegacyBootstrappingMethodToAidl(legacy_ind.request_bootstrapping_method); |
| 3268 | return true; |
| 3269 | } |
| 3270 | |
| 3271 | bool convertLegacyNanBootstrappingConfirmIndToAidl( |
| 3272 | const legacy_hal::NanBootstrappingConfirmInd& legacy_ind, |
| 3273 | NanBootstrappingConfirmInd* aidl_ind) { |
| 3274 | if (!aidl_ind) { |
| 3275 | LOG(ERROR) << "convertLegacyNanBootstrappingConfirmIndToAidl: aidl_ind is null"; |
| 3276 | return false; |
| 3277 | } |
| 3278 | *aidl_ind = {}; |
| 3279 | |
| 3280 | aidl_ind->bootstrappingInstanceId = legacy_ind.bootstrapping_instance_id; |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 3281 | aidl_ind->responseCode = static_cast<NanBootstrappingResponseCode>(legacy_ind.rsp_code); |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3282 | aidl_ind->reasonCode.status = convertLegacyNanStatusTypeToAidl(legacy_ind.reason_code); |
Nate Jiang | bae6fdd | 2023-02-10 17:16:40 -0800 | [diff] [blame^] | 3283 | aidl_ind->comeBackDelay = legacy_ind.come_back_delay; |
| 3284 | aidl_ind->cookie = |
| 3285 | std::vector<uint8_t>(legacy_ind.cookie, legacy_ind.cookie + legacy_ind.cookie_length); |
Nate Jiang | 38e8db5 | 2022-12-02 17:30:27 -0800 | [diff] [blame] | 3286 | return true; |
| 3287 | } |
| 3288 | |
Mahesh KKV | c84d377 | 2022-12-02 16:53:28 -0800 | [diff] [blame] | 3289 | bool convertLegacyWifiChipCapabilitiesToAidl( |
| 3290 | const legacy_hal::wifi_chip_capabilities& legacy_chip_capabilities, |
| 3291 | WifiChipCapabilities& aidl_chip_capabilities) { |
Mahesh KKV | 21a98b4 | 2023-02-05 20:21:17 -0800 | [diff] [blame] | 3292 | aidl_chip_capabilities.maxMloStrLinkCount = legacy_chip_capabilities.max_mlo_str_link_count; |
Sunil Ravi | 4855621 | 2022-12-12 04:17:04 +0000 | [diff] [blame] | 3293 | aidl_chip_capabilities.maxConcurrentTdlsSessionCount = |
| 3294 | legacy_chip_capabilities.max_concurrent_tdls_session_count; |
Mahesh KKV | c84d377 | 2022-12-02 16:53:28 -0800 | [diff] [blame] | 3295 | return true; |
| 3296 | } |
| 3297 | |
Shuibing Dai | e5fbcab | 2022-12-19 15:37:19 -0800 | [diff] [blame] | 3298 | uint32_t convertAidlChannelCategoryToLegacy(uint32_t aidl_channel_category_mask) { |
| 3299 | uint32_t channel_category_mask = 0; |
| 3300 | if (aidl_channel_category_mask & |
| 3301 | static_cast<int32_t>(IWifiChip::ChannelCategoryMask::INDOOR_CHANNEL)) { |
| 3302 | channel_category_mask |= legacy_hal::WIFI_INDOOR_CHANNEL; |
| 3303 | } |
| 3304 | if (aidl_channel_category_mask & |
| 3305 | static_cast<int32_t>(IWifiChip::ChannelCategoryMask::DFS_CHANNEL)) { |
| 3306 | channel_category_mask |= legacy_hal::WIFI_DFS_CHANNEL; |
| 3307 | } |
| 3308 | return channel_category_mask; |
| 3309 | } |
| 3310 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 3311 | } // namespace aidl_struct_util |
| 3312 | } // namespace wifi |
| 3313 | } // namespace hardware |
| 3314 | } // namespace android |
| 3315 | } // namespace aidl |