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