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