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/IWifiChip.h>
26 #include <android/hardware/wifi/1.3/types.h>
27 #include <android/hardware/wifi/1.4/IWifiChipEventCallback.h>
28 #include <android/hardware/wifi/1.4/types.h>
29 
30 #include "wifi_legacy_hal.h"
31 
32 /**
33  * This file contains a bunch of functions to convert structs from the legacy
34  * HAL to HIDL and vice versa.
35  * TODO(b/32093047): Add unit tests for these conversion methods in the VTS test
36  * suite.
37  */
38 namespace android {
39 namespace hardware {
40 namespace wifi {
41 namespace V1_4 {
42 namespace implementation {
43 namespace hidl_struct_util {
44 using namespace android::hardware::wifi::V1_0;
45 
46 // Chip conversion methods.
47 bool convertLegacyFeaturesToHidlChipCapabilities(
48     uint32_t legacy_feature_set, uint32_t legacy_logger_feature_set,
49     uint32_t* hidl_caps);
50 bool convertLegacyDebugRingBufferStatusToHidl(
51     const legacy_hal::wifi_ring_buffer_status& legacy_status,
52     WifiDebugRingBufferStatus* hidl_status);
53 bool convertLegacyVectorOfDebugRingBufferStatusToHidl(
54     const std::vector<legacy_hal::wifi_ring_buffer_status>& legacy_status_vec,
55     std::vector<WifiDebugRingBufferStatus>* hidl_status_vec);
56 bool convertLegacyWakeReasonStatsToHidl(
57     const legacy_hal::WakeReasonStats& legacy_stats,
58     WifiDebugHostWakeReasonStats* hidl_stats);
59 legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy(
60     V1_1::IWifiChip::TxPowerScenario hidl_scenario);
61 legacy_hal::wifi_latency_mode convertHidlLatencyModeToLegacy(
62     V1_3::IWifiChip::LatencyMode hidl_latency_mode);
63 legacy_hal::wifi_power_scenario convertHidlTxPowerScenarioToLegacy_1_2(
64     V1_2::IWifiChip::TxPowerScenario hidl_scenario);
65 bool convertLegacyWifiMacInfosToHidl(
66     const std::vector<legacy_hal::WifiMacInfo>& legacy_mac_infos,
67     std::vector<IWifiChipEventCallback::RadioModeInfo>* hidl_radio_mode_infos);
68 legacy_hal::wifi_interface_type convertHidlIfaceTypeToLegacy(
69     IfaceType hidl_interface_type);
70 
71 // STA iface conversion methods.
72 bool convertLegacyFeaturesToHidlStaCapabilities(
73     uint64_t legacy_feature_set, uint32_t legacy_logger_feature_set,
74     uint32_t* hidl_caps);
75 bool convertLegacyApfCapabilitiesToHidl(
76     const legacy_hal::PacketFilterCapabilities& legacy_caps,
77     StaApfPacketFilterCapabilities* hidl_caps);
78 bool convertLegacyGscanCapabilitiesToHidl(
79     const legacy_hal::wifi_gscan_capabilities& legacy_caps,
80     StaBackgroundScanCapabilities* hidl_caps);
81 legacy_hal::wifi_band convertHidlWifiBandToLegacy(V1_0::WifiBand band);
82 bool convertHidlGscanParamsToLegacy(
83     const StaBackgroundScanParameters& hidl_scan_params,
84     legacy_hal::wifi_scan_cmd_params* legacy_scan_params);
85 // |has_ie_data| indicates whether or not the wifi_scan_result includes 802.11
86 // Information Elements (IEs)
87 bool convertLegacyGscanResultToHidl(
88     const legacy_hal::wifi_scan_result& legacy_scan_result, bool has_ie_data,
89     StaScanResult* hidl_scan_result);
90 // |cached_results| is assumed to not include IEs.
91 bool convertLegacyVectorOfCachedGscanResultsToHidl(
92     const std::vector<legacy_hal::wifi_cached_scan_results>&
93         legacy_cached_scan_results,
94     std::vector<StaScanData>* hidl_scan_datas);
95 bool convertLegacyLinkLayerStatsToHidl(
96     const legacy_hal::LinkLayerStats& legacy_stats,
97     V1_3::StaLinkLayerStats* hidl_stats);
98 bool convertLegacyRoamingCapabilitiesToHidl(
99     const legacy_hal::wifi_roaming_capabilities& legacy_caps,
100     StaRoamingCapabilities* hidl_caps);
101 bool convertHidlRoamingConfigToLegacy(
102     const StaRoamingConfig& hidl_config,
103     legacy_hal::wifi_roaming_config* legacy_config);
104 legacy_hal::fw_roaming_state_t convertHidlRoamingStateToLegacy(
105     StaRoamingState state);
106 bool convertLegacyVectorOfDebugTxPacketFateToHidl(
107     const std::vector<legacy_hal::wifi_tx_report>& legacy_fates,
108     std::vector<WifiDebugTxPacketFateReport>* hidl_fates);
109 bool convertLegacyVectorOfDebugRxPacketFateToHidl(
110     const std::vector<legacy_hal::wifi_rx_report>& legacy_fates,
111     std::vector<WifiDebugRxPacketFateReport>* hidl_fates);
112 
113 // NAN iface conversion methods.
114 void convertToWifiNanStatus(legacy_hal::NanStatusType type, const char* str,
115                             size_t max_len, WifiNanStatus* wifiNanStatus);
116 bool convertHidlNanEnableRequestToLegacy(
117     const NanEnableRequest& hidl_request,
118     legacy_hal::NanEnableRequest* legacy_request);
119 bool convertHidlNanConfigRequestToLegacy(
120     const NanConfigRequest& hidl_request,
121     legacy_hal::NanConfigRequest* legacy_request);
122 bool convertHidlNanEnableRequest_1_4ToLegacy(
123     const NanEnableRequest& hidl_request1,
124     const V1_2::NanConfigRequestSupplemental& hidl_request2,
125     legacy_hal::NanEnableRequest* legacy_request);
126 bool convertHidlNanConfigRequest_1_4ToLegacy(
127     const NanConfigRequest& hidl_request1,
128     const V1_2::NanConfigRequestSupplemental& hidl_request2,
129     legacy_hal::NanConfigRequest* legacy_request);
130 bool convertHidlNanPublishRequestToLegacy(
131     const NanPublishRequest& hidl_request,
132     legacy_hal::NanPublishRequest* legacy_request);
133 bool convertHidlNanSubscribeRequestToLegacy(
134     const NanSubscribeRequest& hidl_request,
135     legacy_hal::NanSubscribeRequest* legacy_request);
136 bool convertHidlNanTransmitFollowupRequestToLegacy(
137     const NanTransmitFollowupRequest& hidl_request,
138     legacy_hal::NanTransmitFollowupRequest* legacy_request);
139 bool convertHidlNanDataPathInitiatorRequestToLegacy(
140     const NanInitiateDataPathRequest& hidl_request,
141     legacy_hal::NanDataPathInitiatorRequest* legacy_request);
142 bool convertHidlNanDataPathIndicationResponseToLegacy(
143     const NanRespondToDataPathIndicationRequest& hidl_response,
144     legacy_hal::NanDataPathIndicationResponse* legacy_response);
145 bool convertLegacyNanResponseHeaderToHidl(
146     const legacy_hal::NanResponseMsg& legacy_response,
147     WifiNanStatus* wifiNanStatus);
148 bool convertLegacyNanCapabilitiesResponseToHidl(
149     const legacy_hal::NanCapabilities& legacy_response,
150     NanCapabilities* hidl_response);
151 bool convertLegacyNanMatchIndToHidl(const legacy_hal::NanMatchInd& legacy_ind,
152                                     NanMatchInd* hidl_ind);
153 bool convertLegacyNanFollowupIndToHidl(
154     const legacy_hal::NanFollowupInd& legacy_ind,
155     NanFollowupReceivedInd* hidl_ind);
156 bool convertLegacyNanDataPathRequestIndToHidl(
157     const legacy_hal::NanDataPathRequestInd& legacy_ind,
158     NanDataPathRequestInd* hidl_ind);
159 bool convertLegacyNanDataPathConfirmIndToHidl(
160     const legacy_hal::NanDataPathConfirmInd& legacy_ind,
161     V1_2::NanDataPathConfirmInd* hidl_ind);
162 bool convertLegacyNanDataPathScheduleUpdateIndToHidl(
163     const legacy_hal::NanDataPathScheduleUpdateInd& legacy_ind,
164     V1_2::NanDataPathScheduleUpdateInd* hidl_ind);
165 
166 // RTT controller conversion methods.
167 bool convertHidlVectorOfRttConfigToLegacy(
168     const std::vector<RttConfig>& hidl_configs,
169     std::vector<legacy_hal::wifi_rtt_config>* legacy_configs);
170 bool convertHidlRttLciInformationToLegacy(
171     const RttLciInformation& hidl_info,
172     legacy_hal::wifi_lci_information* legacy_info);
173 bool convertHidlRttLcrInformationToLegacy(
174     const RttLcrInformation& hidl_info,
175     legacy_hal::wifi_lcr_information* legacy_info);
176 bool convertHidlRttResponderToLegacy(
177     const RttResponder& hidl_responder,
178     legacy_hal::wifi_rtt_responder* legacy_responder);
179 bool convertHidlWifiChannelInfoToLegacy(
180     const WifiChannelInfo& hidl_info,
181     legacy_hal::wifi_channel_info* legacy_info);
182 bool convertLegacyRttResponderToHidl(
183     const legacy_hal::wifi_rtt_responder& legacy_responder,
184     RttResponder* hidl_responder);
185 bool convertLegacyRttCapabilitiesToHidl(
186     const legacy_hal::wifi_rtt_capabilities& legacy_capabilities,
187     RttCapabilities* hidl_capabilities);
188 bool convertLegacyVectorOfRttResultToHidl(
189     const std::vector<const legacy_hal::wifi_rtt_result*>& legacy_results,
190     std::vector<RttResult>* hidl_results);
191 }  // namespace hidl_struct_util
192 }  // namespace implementation
193 }  // namespace V1_4
194 }  // namespace wifi
195 }  // namespace hardware
196 }  // namespace android
197 
198 #endif  // HIDL_STRUCT_UTIL_H_
199