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