1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HIDL_STRUCT_UTIL_H_
18 #define HIDL_STRUCT_UTIL_H_
19 
20 #include <vector>
21 
22 #include <android/hardware/wifi/1.0/IWifiChip.h>
23 #include <android/hardware/wifi/1.0/types.h>
24 #include <android/hardware/wifi/1.2/types.h>
25 #include <android/hardware/wifi/1.3/types.h>
26 #include <android/hardware/wifi/1.4/IWifiChipEventCallback.h>
27 #include <android/hardware/wifi/1.4/types.h>
28 #include <android/hardware/wifi/1.5/IWifiChip.h>
29 #include <android/hardware/wifi/1.5/types.h>
30 
31 #include "wifi_legacy_hal.h"
32 
33 /**
34  * This file contains a bunch of functions to convert structs from the legacy
35  * HAL to HIDL and vice versa.
36  * TODO(b/32093047): Add unit tests for these conversion methods in the VTS test
37  * suite.
38  */
39 namespace android {
40 namespace hardware {
41 namespace wifi {
42 namespace V1_5 {
43 namespace implementation {
44 namespace hidl_struct_util {
45 using namespace android::hardware::wifi::V1_0;
46 
47 // Chip conversion methods.
48 bool convertLegacyFeaturesToHidlChipCapabilities(
49     uint64_t legacy_feature_set, uint32_t legacy_logger_feature_set,
50     uint32_t* hidl_caps);
51 bool convertLegacyDebugRingBufferStatusToHidl(
52     const legacy_hal::wifi_ring_buffer_status& legacy_status,
53     WifiDebugRingBufferStatus* hidl_status);
54 bool convertLegacyVectorOfDebugRingBufferStatusToHidl(
55     const std::vector<legacy_hal::wifi_ring_buffer_status>& legacy_status_vec,
56     std::vector<WifiDebugRingBufferStatus>* hidl_status_vec);
57 bool convertLegacyWakeReasonStatsToHidl(
58     const legacy_hal::WakeReasonStats& legacy_stats,
59     WifiDebugHostWakeReasonStats* hidl_stats);
60 legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy(
61     V1_1::IWifiChip::TxPowerScenario hidl_scenario);
62 legacy_hal::wifi_latency_mode convertHidlLatencyModeToLegacy(
63     V1_3::IWifiChip::LatencyMode hidl_latency_mode);
64 legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy_1_2(
65     V1_2::IWifiChip::TxPowerScenario hidl_scenario);
66 bool convertLegacyWifiMacInfosToHidl(
67     const std::vector<legacy_hal::WifiMacInfo>& legacy_mac_infos,
68     std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo>*
69         hidl_radio_mode_infos);
70 legacy_hal::wifi_interface_type convertHidlIfaceTypeToLegacy(
71     IfaceType hidl_interface_type);
72 legacy_hal::wifi_multi_sta_use_case convertHidlMultiStaUseCaseToLegacy(
73     IWifiChip::MultiStaUseCase use_case);
74 bool convertHidlCoexUnsafeChannelToLegacy(
75     const IWifiChip::CoexUnsafeChannel& hidl_unsafe_channel,
76     legacy_hal::wifi_coex_unsafe_channel* legacy_unsafe_channel);
77 bool convertHidlVectorOfCoexUnsafeChannelToLegacy(
78     const std::vector<IWifiChip::CoexUnsafeChannel>& hidl_unsafe_channels,
79     std::vector<legacy_hal::wifi_coex_unsafe_channel>* legacy_unsafe_channels);
80 
81 // STA iface conversion methods.
82 bool convertLegacyFeaturesToHidlStaCapabilities(
83     uint64_t legacy_feature_set, uint32_t legacy_logger_feature_set,
84     uint32_t* hidl_caps);
85 bool convertLegacyApfCapabilitiesToHidl(
86     const legacy_hal::PacketFilterCapabilities& legacy_caps,
87     StaApfPacketFilterCapabilities* hidl_caps);
88 bool convertLegacyGscanCapabilitiesToHidl(
89     const legacy_hal::wifi_gscan_capabilities& legacy_caps,
90     StaBackgroundScanCapabilities* hidl_caps);
91 legacy_hal::wifi_band convertHidlWifiBandToLegacy(V1_0::WifiBand band);
92 bool convertHidlGscanParamsToLegacy(
93     const StaBackgroundScanParameters& hidl_scan_params,
94     legacy_hal::wifi_scan_cmd_params* legacy_scan_params);
95 // |has_ie_data| indicates whether or not the wifi_scan_result includes 802.11
96 // Information Elements (IEs)
97 bool convertLegacyGscanResultToHidl(
98     const legacy_hal::wifi_scan_result& legacy_scan_result, bool has_ie_data,
99     StaScanResult* hidl_scan_result);
100 // |cached_results| is assumed to not include IEs.
101 bool convertLegacyVectorOfCachedGscanResultsToHidl(
102     const std::vector<legacy_hal::wifi_cached_scan_results>&
103         legacy_cached_scan_results,
104     std::vector<StaScanData>* hidl_scan_datas);
105 bool convertLegacyLinkLayerStatsToHidl(
106     const legacy_hal::LinkLayerStats& legacy_stats,
107     StaLinkLayerStats* hidl_stats);
108 bool convertLegacyRoamingCapabilitiesToHidl(
109     const legacy_hal::wifi_roaming_capabilities& legacy_caps,
110     StaRoamingCapabilities* hidl_caps);
111 bool convertHidlRoamingConfigToLegacy(
112     const StaRoamingConfig& hidl_config,
113     legacy_hal::wifi_roaming_config* legacy_config);
114 legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy(
115     StaRoamingState state);
116 bool convertLegacyVectorOfDebugTxPacketFateToHidl(
117     const std::vector<legacy_hal::wifi_tx_report>& legacy_fates,
118     std::vector<WifiDebugTxPacketFateReport>* hidl_fates);
119 bool convertLegacyVectorOfDebugRxPacketFateToHidl(
120     const std::vector<legacy_hal::wifi_rx_report>& legacy_fates,
121     std::vector<WifiDebugRxPacketFateReport>* hidl_fates);
122 
123 // NAN iface conversion methods.
124 void convertToWifiNanStatus(legacy_hal::NanStatusType type, const char* str,
125                             size_t max_len, WifiNanStatus* wifiNanStatus);
126 bool convertHidlNanEnableRequestToLegacy(
127     const V1_4::NanEnableRequest& hidl_request,
128     legacy_hal::NanEnableRequest* legacy_request);
129 bool convertHidlNanConfigRequestToLegacy(
130     const V1_4::NanConfigRequest& hidl_request,
131     legacy_hal::NanConfigRequest* legacy_request);
132 bool convertHidlNanEnableRequest_1_4ToLegacy(
133     const V1_4::NanEnableRequest& hidl_request1,
134     const NanConfigRequestSupplemental& hidl_request2,
135     legacy_hal::NanEnableRequest* legacy_request);
136 bool convertHidlNanConfigRequest_1_4ToLegacy(
137     const V1_4::NanConfigRequest& hidl_request1,
138     const NanConfigRequestSupplemental& hidl_request2,
139     legacy_hal::NanConfigRequest* legacy_request);
140 bool convertHidlNanEnableRequest_1_5ToLegacy(
141     const V1_4::NanEnableRequest& hidl_request1,
142     const NanConfigRequestSupplemental& hidl_request2,
143     legacy_hal::NanEnableRequest* legacy_request);
144 bool convertHidlNanConfigRequest_1_5ToLegacy(
145     const V1_4::NanConfigRequest& hidl_request1,
146     const NanConfigRequestSupplemental& hidl_request2,
147     legacy_hal::NanConfigRequest* legacy_request);
148 bool convertHidlNanPublishRequestToLegacy(
149     const NanPublishRequest& hidl_request,
150     legacy_hal::NanPublishRequest* legacy_request);
151 bool convertHidlNanSubscribeRequestToLegacy(
152     const NanSubscribeRequest& hidl_request,
153     legacy_hal::NanSubscribeRequest* legacy_request);
154 bool convertHidlNanTransmitFollowupRequestToLegacy(
155     const NanTransmitFollowupRequest& hidl_request,
156     legacy_hal::NanTransmitFollowupRequest* legacy_request);
157 bool convertHidlNanDataPathInitiatorRequestToLegacy(
158     const NanInitiateDataPathRequest& hidl_request,
159     legacy_hal::NanDataPathInitiatorRequest* legacy_request);
160 bool convertHidlNanDataPathIndicationResponseToLegacy(
161     const NanRespondToDataPathIndicationRequest& hidl_response,
162     legacy_hal::NanDataPathIndicationResponse* legacy_response);
163 bool convertLegacyNanResponseHeaderToHidl(
164     const legacy_hal::NanResponseMsg& legacy_response,
165     WifiNanStatus* wifiNanStatus);
166 bool convertLegacyNanCapabilitiesResponseToHidl(
167     const legacy_hal::NanCapabilities& legacy_response,
168     NanCapabilities* hidl_response);
169 bool convertLegacyNanMatchIndToHidl(const legacy_hal::NanMatchInd& legacy_ind,
170                                     NanMatchInd* hidl_ind);
171 bool convertLegacyNanFollowupIndToHidl(
172     const legacy_hal::NanFollowupInd& legacy_ind,
173     NanFollowupReceivedInd* hidl_ind);
174 bool convertLegacyNanDataPathRequestIndToHidl(
175     const legacy_hal::NanDataPathRequestInd& legacy_ind,
176     NanDataPathRequestInd* hidl_ind);
177 bool convertLegacyNanDataPathConfirmIndToHidl(
178     const legacy_hal::NanDataPathConfirmInd& legacy_ind,
179     V1_2::NanDataPathConfirmInd* hidl_ind);
180 bool convertLegacyNanDataPathScheduleUpdateIndToHidl(
181     const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind,
182     V1_2::NanDataPathScheduleUpdateInd* hidl_ind);
183 
184 // RTT controller conversion methods.
185 bool convertHidlVectorOfRttConfigToLegacy(
186     const std::vector<V1_4::RttConfig>& hidl_configs,
187     std::vector<legacy_hal::wifi_rtt_config>* legacy_configs);
188 bool convertHidlRttLciInformationToLegacy(
189     const RttLciInformation& hidl_info,
190     legacy_hal::wifi_lci_information* legacy_info);
191 bool convertHidlRttLcrInformationToLegacy(
192     const RttLcrInformation& hidl_info,
193     legacy_hal::wifi_lcr_information* legacy_info);
194 bool convertHidlRttResponderToLegacy(
195     const V1_4::RttResponder& hidl_responder,
196     legacy_hal::wifi_rtt_responder* legacy_responder);
197 bool convertHidlWifiChannelInfoToLegacy(
198     const WifiChannelInfo& hidl_info,
199     legacy_hal::wifi_channel_info* legacy_info);
200 bool convertLegacyRttResponderToHidl(
201     const legacy_hal::wifi_rtt_responder& legacy_responder,
202     V1_4::RttResponder* hidl_responder);
203 bool convertLegacyRttCapabilitiesToHidl(
204     const legacy_hal::wifi_rtt_capabilities& legacy_capabilities,
205     V1_4::RttCapabilities* hidl_capabilities);
206 bool convertLegacyVectorOfRttResultToHidl(
207     const std::vector<const legacy_hal::wifi_rtt_result*>& legacy_results,
208     std::vector<V1_4::RttResult>* hidl_results);
209 uint32_t convertHidlWifiBandToLegacyMacBand(V1_5::WifiBand band);
210 uint32_t convertHidlWifiIfaceModeToLegacy(uint32_t hidl_iface_mask);
211 uint32_t convertHidlUsableChannelFilterToLegacy(uint32_t hidl_filter_mask);
212 bool convertLegacyWifiUsableChannelsToHidl(
213     const std::vector<legacy_hal::wifi_usable_channel>& legacy_usable_channels,
214     std::vector<V1_5::WifiUsableChannel>* hidl_usable_channels);
215 bool convertLegacyPeerInfoStatsToHidl(
216     const legacy_hal::WifiPeerInfo& legacy_peer_info_stats,
217     StaPeerInfo* hidl_peer_info_stats);
218 bool convertLegacyWifiRateInfoToHidl(const legacy_hal::wifi_rate& legacy_rate,
219                                      V1_4::WifiRateInfo* hidl_rate);
220 }  // namespace hidl_struct_util
221 }  // namespace implementation
222 }  // namespace V1_5
223 }  // namespace wifi
224 }  // namespace hardware
225 }  // namespace android
226 
227 #endif  // HIDL_STRUCT_UTIL_H_
228