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