xref: /aosp_15_r20/external/wpa_supplicant_8/wpa_supplicant/aidl/vendor/p2p_iface.h (revision 03f9172ca588f91df233974f4258bab95191f931)
1 /*
2  * WPA Supplicant - P2P Iface Aidl interface
3  * Copyright (c) 2021, Google Inc. All rights reserved.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef WPA_SUPPLICANT_AIDL_P2P_IFACE_H
10 #define WPA_SUPPLICANT_AIDL_P2P_IFACE_H
11 
12 #include <array>
13 #include <vector>
14 
15 #include <android-base/macros.h>
16 
17 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantP2pIface.h>
18 #include <aidl/android/hardware/wifi/supplicant/FreqRange.h>
19 #include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.h>
20 #include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pNetwork.h>
21 #include <aidl/android/hardware/wifi/supplicant/MiracastMode.h>
22 #include <aidl/android/hardware/wifi/supplicant/WpsProvisionMethod.h>
23 
24 extern "C"
25 {
26 #include "utils/common.h"
27 #include "utils/includes.h"
28 #include "p2p/p2p.h"
29 #include "p2p/p2p_i.h"
30 #include "p2p_supplicant.h"
31 #include "p2p_supplicant.h"
32 #include "config.h"
33 }
34 
35 #define P2P_MGMT_DEVICE_PREFIX	   "p2p-dev-"
36 
37 namespace aidl {
38 namespace android {
39 namespace hardware {
40 namespace wifi {
41 namespace supplicant {
42 
43 /**
44  * Implementation of P2pIface aidl object. Each unique aidl
45  * object is used for control operations on a specific interface
46  * controlled by wpa_supplicant.
47  */
48 class P2pIface : public BnSupplicantP2pIface
49 {
50 public:
51 	P2pIface(struct wpa_global* wpa_global, const char ifname[]);
52 	~P2pIface() override = default;
53 	// Refer to |StaIface::invalidate()|.
54 	void invalidate();
55 	bool isValid();
56 
57 	// Aidl methods exposed.
58 	::ndk::ScopedAStatus getName(std::string* _aidl_return) override;
59 	::ndk::ScopedAStatus getType(IfaceType* _aidl_return) override;
60 	::ndk::ScopedAStatus addNetwork(
61 		std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override;
62 	::ndk::ScopedAStatus removeNetwork(int32_t in_id) override;
63 	::ndk::ScopedAStatus getNetwork(
64 		int32_t in_id, std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override;
65 	::ndk::ScopedAStatus listNetworks(std::vector<int32_t>* _aidl_return) override;
66 	::ndk::ScopedAStatus registerCallback(
67 		const std::shared_ptr<ISupplicantP2pIfaceCallback>& in_callback) override;
68 	::ndk::ScopedAStatus getDeviceAddress(std::vector<uint8_t>* _aidl_return) override;
69 	::ndk::ScopedAStatus setSsidPostfix(const std::vector<uint8_t>& in_postfix) override;
70 	::ndk::ScopedAStatus setGroupIdle(
71 		const std::string& in_groupIfName, int32_t in_timeoutInSec) override;
72 	::ndk::ScopedAStatus setPowerSave(
73 		const std::string& in_groupIfName, bool in_enable) override;
74 	::ndk::ScopedAStatus find(int32_t in_timeoutInSec) override;
75 	::ndk::ScopedAStatus stopFind() override;
76 	::ndk::ScopedAStatus flush() override;
77 	::ndk::ScopedAStatus connect(
78 		const std::vector<uint8_t>& in_peerAddress, WpsProvisionMethod in_provisionMethod,
79 		const std::string& in_preSelectedPin, bool in_joinExistingGroup,
80 		bool in_persistent, int32_t in_goIntent, std::string* _aidl_return) override;
81 	::ndk::ScopedAStatus cancelConnect() override;
82 	::ndk::ScopedAStatus provisionDiscovery(
83 		const std::vector<uint8_t>& in_peerAddress,
84 		WpsProvisionMethod in_provisionMethod) override;
85 	::ndk::ScopedAStatus addGroup(bool in_persistent, int32_t in_persistentNetworkId) override;
86 	::ndk::ScopedAStatus addGroupWithConfig(
87 		const std::vector<uint8_t>& in_ssid, const std::string& in_pskPassphrase,
88 		bool in_persistent, int32_t in_freq, const std::vector<uint8_t>& in_peerAddress,
89 		bool in_joinExistingGroup) override;
90 	::ndk::ScopedAStatus removeGroup(const std::string& in_groupIfName) override;
91 	::ndk::ScopedAStatus reject(const std::vector<uint8_t>& in_peerAddress) override;
92 	::ndk::ScopedAStatus invite(
93 		const std::string& in_groupIfName,
94 		const std::vector<uint8_t>& in_goDeviceAddress,
95 		const std::vector<uint8_t>& in_peerAddress) override;
96 	::ndk::ScopedAStatus reinvoke(
97 		int32_t in_persistentNetworkId,
98 		const std::vector<uint8_t>& in_peerAddress) override;
99 	::ndk::ScopedAStatus configureExtListen(
100 		int32_t in_periodInMillis, int32_t in_intervalInMillis) override;
101 	::ndk::ScopedAStatus setListenChannel(
102 		int32_t in_channel, int32_t in_operatingClass) override;
103 	::ndk::ScopedAStatus setDisallowedFrequencies(
104 		const std::vector<FreqRange>& in_ranges) override;
105 	::ndk::ScopedAStatus getSsid(
106 		const std::vector<uint8_t>& in_peerAddress,
107 		std::vector<uint8_t>* _aidl_return) override;
108 	::ndk::ScopedAStatus getGroupCapability(
109 		const std::vector<uint8_t>& in_peerAddress,
110 		P2pGroupCapabilityMask* _aidl_return) override;
111 	::ndk::ScopedAStatus addBonjourService(
112 		const std::vector<uint8_t>& in_query,
113 		const std::vector<uint8_t>& in_response) override;
114 	::ndk::ScopedAStatus removeBonjourService(
115 		const std::vector<uint8_t>& in_query) override;
116 	::ndk::ScopedAStatus addUpnpService(
117 		int32_t in_version, const std::string& in_serviceName) override;
118 	::ndk::ScopedAStatus removeUpnpService(
119 		int32_t in_version, const std::string& in_serviceName) override;
120 	::ndk::ScopedAStatus flushServices() override;
121 	::ndk::ScopedAStatus requestServiceDiscovery(
122 		const std::vector<uint8_t>& in_peerAddress,
123 		const std::vector<uint8_t>& in_query, int64_t* _aidl_return) override;
124 	::ndk::ScopedAStatus cancelServiceDiscovery(int64_t in_identifier) override;
125 	::ndk::ScopedAStatus setMiracastMode(MiracastMode in_mode) override;
126 	::ndk::ScopedAStatus startWpsPbc(
127 		const std::string& in_groupIfName,
128 		const std::vector<uint8_t>& in_bssid) override;
129 	::ndk::ScopedAStatus startWpsPinKeypad(
130 		const std::string& in_groupIfName, const std::string& in_pin) override;
131 	::ndk::ScopedAStatus startWpsPinDisplay(
132 		const std::string& in_groupIfName,
133 		const std::vector<uint8_t>& in_bssid,
134 		std::string* _aidl_return) override;
135 	::ndk::ScopedAStatus cancelWps(const std::string& in_groupIfName) override;
136 	::ndk::ScopedAStatus setWpsDeviceName(
137 		const std::string& in_name) override;
138 	::ndk::ScopedAStatus setWpsDeviceType(
139 		const std::vector<uint8_t>& in_type) override;
140 	::ndk::ScopedAStatus setWpsManufacturer(
141 		const std::string& in_manufacturer) override;
142 	::ndk::ScopedAStatus setWpsModelName(
143 		const std::string& in_modelName) override;
144 	::ndk::ScopedAStatus setWpsModelNumber(
145 		const std::string& in_modelNumber) override;
146 	::ndk::ScopedAStatus setWpsSerialNumber(
147 		const std::string& in_serialNumber) override;
148 	::ndk::ScopedAStatus setWpsConfigMethods(
149 		WpsConfigMethods in_configMethods) override;
150 	::ndk::ScopedAStatus enableWfd(bool in_enable) override;
151 	::ndk::ScopedAStatus setWfdDeviceInfo(
152 		const std::vector<uint8_t>& in_info) override;
153 	::ndk::ScopedAStatus createNfcHandoverRequestMessage(
154 		std::vector<uint8_t>* _aidl_return) override;
155 	::ndk::ScopedAStatus createNfcHandoverSelectMessage(
156 		std::vector<uint8_t>* _aidl_return) override;
157 	::ndk::ScopedAStatus reportNfcHandoverInitiation(
158 		const std::vector<uint8_t>& in_select) override;
159 	::ndk::ScopedAStatus reportNfcHandoverResponse(
160 		const std::vector<uint8_t>& in_request) override;
161 	::ndk::ScopedAStatus saveConfig() override;
162 	::ndk::ScopedAStatus setMacRandomization(bool in_enable) override;
163 	::ndk::ScopedAStatus setEdmg(bool in_enable) override;
164 	::ndk::ScopedAStatus getEdmg(bool* _aidl_return) override;
165 	::ndk::ScopedAStatus setWfdR2DeviceInfo(
166 		const std::vector<uint8_t>& in_info) override;
167 	::ndk::ScopedAStatus removeClient(
168 		const std::vector<uint8_t>& peer_address, bool isLegacyClient) override;
169 	::ndk::ScopedAStatus findOnSocialChannels(int32_t in_timeoutInSec) override;
170 	::ndk::ScopedAStatus findOnSpecificFrequency(
171 		int32_t in_freq, int32_t in_timeoutInSec) override;
172 	::ndk::ScopedAStatus setVendorElements(
173 		P2pFrameTypeMask in_frameTypeMask,
174 		const std::vector<uint8_t>& in_vendorElemBytes) override;
175 	::ndk::ScopedAStatus configureEapolIpAddressAllocationParams(
176 		int32_t in_ipAddressGo, int32_t in_ipAddressMask,
177 		int32_t in_ipAddressStart, int32_t in_ipAddressEnd) override;
178 	::ndk::ScopedAStatus connectWithParams(
179 		const P2pConnectInfo& in_connectInfo, std::string* _aidl_return) override;
180 	::ndk::ScopedAStatus findWithParams(const P2pDiscoveryInfo& in_discoveryInfo) override;
181 	::ndk::ScopedAStatus configureExtListenWithParams(
182 		const P2pExtListenInfo& in_extListenInfo) override;
183 	::ndk::ScopedAStatus addGroupWithConfigurationParams(
184 		const P2pAddGroupConfigurationParams& in_groupConfigurationParams) override;
185 	::ndk::ScopedAStatus createGroupOwner(
186 		const P2pCreateGroupOwnerInfo& in_groupOwnerInfo) override;
187 	::ndk::ScopedAStatus getFeatureSet(int64_t* _aidl_return) override;
188 	::ndk::ScopedAStatus startUsdBasedServiceDiscovery(
189 		const P2pUsdBasedServiceDiscoveryConfig& in_serviceDiscoveryConfig,
190 		int32_t* _aidl_return) override;
191 	::ndk::ScopedAStatus stopUsdBasedServiceDiscovery(int32_t in_sessionId) override;
192 	::ndk::ScopedAStatus startUsdBasedServiceAdvertisement(
193 		const P2pUsdBasedServiceAdvertisementConfig& in_serviceAdvertisementConfig,
194 		int32_t* _aidl_return) override;
195 	::ndk::ScopedAStatus stopUsdBasedServiceAdvertisement(int32_t in_sessionId) override;
196 	::ndk::ScopedAStatus provisionDiscoveryWithParams(
197 		const P2pProvisionDiscoveryParams& in_params) override;
198 	::ndk::ScopedAStatus getDirInfo(P2pDirInfo* _aidl_return) override;
199 	::ndk::ScopedAStatus validateDirInfo(const P2pDirInfo &in_dirInfo,
200 		int32_t* _aidl_return) override;
201 	::ndk::ScopedAStatus reinvokePersistentGroup(
202 		const P2pReinvokePersistentGroupParams& in_reinvokeGroupParams) override;
203 
204 
205 private:
206 	// Corresponding worker functions for the AIDL methods.
207 	std::pair<std::string, ndk::ScopedAStatus> getNameInternal();
208 	std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal();
209 	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
210 		addNetworkInternal();
211 	ndk::ScopedAStatus removeNetworkInternal(int32_t id);
212 	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
213 		getNetworkInternal(int32_t id);
214 	std::pair<std::vector<int32_t>, ndk::ScopedAStatus>
215 		listNetworksInternal();
216 	ndk::ScopedAStatus registerCallbackInternal(
217 		const std::shared_ptr<ISupplicantP2pIfaceCallback>& callback);
218 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
219 		getDeviceAddressInternal();
220 	ndk::ScopedAStatus setSsidPostfixInternal(
221 		const std::vector<uint8_t>& postfix);
222 	ndk::ScopedAStatus setGroupIdleInternal(
223 		const std::string& group_ifname, uint32_t timeout_in_sec);
224 	ndk::ScopedAStatus setPowerSaveInternal(
225 		const std::string& group_ifname, bool enable);
226 	ndk::ScopedAStatus findInternal(uint32_t timeout_in_sec);
227 	ndk::ScopedAStatus stopFindInternal();
228 	ndk::ScopedAStatus flushInternal();
229 	std::pair<std::string, ndk::ScopedAStatus> connectInternal(
230 		const std::vector<uint8_t>& peer_address,
231 		WpsProvisionMethod provision_method,
232 		const std::string& pre_selected_pin, bool join_existing_group,
233 		bool persistent, uint32_t go_intent);
234 	ndk::ScopedAStatus cancelConnectInternal();
235 	ndk::ScopedAStatus provisionDiscoveryInternal(
236 		const std::vector<uint8_t>& peer_address,
237 		WpsProvisionMethod provision_method);
238 	ndk::ScopedAStatus addGroupInternal(bool in_persistent, int32_t in_persistentNetworkId);
239 	ndk::ScopedAStatus addGroupWithConfigInternal(
240 		const std::vector<uint8_t>& ssid, const std::string& passphrase,
241 		bool persistent, uint32_t freq, const std::vector<uint8_t>& peer_address,
242 		bool joinExistingGroup);
243 	ndk::ScopedAStatus removeGroupInternal(const std::string& group_ifname);
244 	ndk::ScopedAStatus rejectInternal(
245 		const std::vector<uint8_t>& peer_address);
246 	ndk::ScopedAStatus inviteInternal(
247 		const std::string& group_ifname,
248 		const std::vector<uint8_t>& go_device_address,
249 		const std::vector<uint8_t>& peer_address);
250 	ndk::ScopedAStatus reinvokeInternal(
251 		int32_t persistent_network_id,
252 		const std::vector<uint8_t>& peer_address);
253 	ndk::ScopedAStatus configureExtListenInternal(
254 		uint32_t period_in_millis, uint32_t interval_in_millis);
255 	ndk::ScopedAStatus setListenChannelInternal(
256 		uint32_t channel, uint32_t operating_class);
257 	ndk::ScopedAStatus setDisallowedFrequenciesInternal(
258 		const std::vector<FreqRange>& ranges);
259 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal(
260 		const std::vector<uint8_t>& peer_address);
261 	std::pair<P2pGroupCapabilityMask, ndk::ScopedAStatus> getGroupCapabilityInternal(
262 		const std::vector<uint8_t>& peer_address);
263 	ndk::ScopedAStatus addBonjourServiceInternal(
264 		const std::vector<uint8_t>& query,
265 		const std::vector<uint8_t>& response);
266 	ndk::ScopedAStatus removeBonjourServiceInternal(
267 		const std::vector<uint8_t>& query);
268 	ndk::ScopedAStatus addUpnpServiceInternal(
269 		uint32_t version, const std::string& service_name);
270 	ndk::ScopedAStatus removeUpnpServiceInternal(
271 		uint32_t version, const std::string& service_name);
272 	ndk::ScopedAStatus flushServicesInternal();
273 	std::pair<uint64_t, ndk::ScopedAStatus> requestServiceDiscoveryInternal(
274 		const std::vector<uint8_t>& peer_address,
275 		const std::vector<uint8_t>& query);
276 	ndk::ScopedAStatus cancelServiceDiscoveryInternal(uint64_t identifier);
277 	ndk::ScopedAStatus setMiracastModeInternal(
278 		MiracastMode mode);
279 	ndk::ScopedAStatus startWpsPbcInternal(
280 		const std::string& group_ifname,
281 		const std::vector<uint8_t>& bssid);
282 	ndk::ScopedAStatus startWpsPinKeypadInternal(
283 		const std::string& group_ifname, const std::string& pin);
284 	std::pair<std::string, ndk::ScopedAStatus> startWpsPinDisplayInternal(
285 		const std::string& group_ifname,
286 		const std::vector<uint8_t>& bssid);
287 	ndk::ScopedAStatus cancelWpsInternal(const std::string& group_ifname);
288 	ndk::ScopedAStatus setWpsDeviceNameInternal(const std::string& name);
289 	ndk::ScopedAStatus setWpsDeviceTypeInternal(
290 		const std::vector<uint8_t>& type);
291 	ndk::ScopedAStatus setWpsManufacturerInternal(
292 		const std::string& manufacturer);
293 	ndk::ScopedAStatus setWpsModelNameInternal(const std::string& model_name);
294 	ndk::ScopedAStatus setWpsModelNumberInternal(
295 		const std::string& model_number);
296 	ndk::ScopedAStatus setWpsSerialNumberInternal(
297 		const std::string& serial_number);
298 	ndk::ScopedAStatus setWpsConfigMethodsInternal(WpsConfigMethods config_methods);
299 	ndk::ScopedAStatus enableWfdInternal(bool enable);
300 	ndk::ScopedAStatus setWfdDeviceInfoInternal(
301 		const std::vector<uint8_t>& info);
302 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
303 		createNfcHandoverRequestMessageInternal();
304 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
305 		createNfcHandoverSelectMessageInternal();
306 	ndk::ScopedAStatus reportNfcHandoverResponseInternal(
307 		const std::vector<uint8_t>& request);
308 	ndk::ScopedAStatus reportNfcHandoverInitiationInternal(
309 		const std::vector<uint8_t>& select);
310 	ndk::ScopedAStatus saveConfigInternal();
311 	ndk::ScopedAStatus setMacRandomizationInternal(bool enable);
312 	ndk::ScopedAStatus setEdmgInternal(bool enable);
313 	std::pair<bool, ndk::ScopedAStatus> getEdmgInternal();
314 	ndk::ScopedAStatus setWfdR2DeviceInfoInternal(
315 		const std::vector<uint8_t>& info);
316 	ndk::ScopedAStatus removeClientInternal(
317 		const std::vector<uint8_t>& peer_address, bool isLegacyClient);
318 	ndk::ScopedAStatus findOnSocialChannelsInternal(uint32_t timeout_in_sec);
319 	ndk::ScopedAStatus findOnSpecificFrequencyInternal(
320 		uint32_t freq, uint32_t timeout_in_sec);
321 	ndk::ScopedAStatus setVendorElementsInternal(
322 		P2pFrameTypeMask frameTypeMask,
323 		const std::vector<uint8_t>& vendorElemBytes);
324 	::ndk::ScopedAStatus configureEapolIpAddressAllocationParamsInternal(
325 		uint32_t ipAddressGo, uint32_t ipAddressMask,
326 		uint32_t ipAddressStart, uint32_t ipAddressEnd);
327 	std::pair<std::string, ndk::ScopedAStatus> connectWithParamsInternal(
328 		const P2pConnectInfo& connectInfo);
329 	ndk::ScopedAStatus findWithParamsInternal(const P2pDiscoveryInfo& discoveryInfo);
330 	ndk::ScopedAStatus configureExtListenWithParamsInternal(const P2pExtListenInfo& extListenInfo);
331 	ndk::ScopedAStatus addGroupWithConfigurationParamsInternal(
332 		const P2pAddGroupConfigurationParams& groupConfigurationParams);
333 	ndk::ScopedAStatus createGroupOwnerInternal(
334 		const P2pCreateGroupOwnerInfo& groupOwnerInfo);
335 	std::pair<int64_t, ndk::ScopedAStatus> getFeatureSetInternal();
336 	std::pair<uint32_t, ndk::ScopedAStatus> startUsdBasedServiceDiscoveryInternal(
337 		const P2pUsdBasedServiceDiscoveryConfig& serviceDiscoveryConfig);
338 	::ndk::ScopedAStatus stopUsdBasedServiceDiscoveryInternal(uint32_t sessionId);
339 	std::pair<uint32_t, ndk::ScopedAStatus> startUsdBasedServiceAdvertisementInternal(
340 		const P2pUsdBasedServiceAdvertisementConfig& serviceAdvertisementConfig);
341 	::ndk::ScopedAStatus stopUsdBasedServiceAdvertisementInternal(uint32_t sessionId);
342 	::ndk::ScopedAStatus provisionDiscoveryWithParamsInternal(
343 		const P2pProvisionDiscoveryParams& params);
344 	std::pair<P2pDirInfo, ndk::ScopedAStatus> getDirInfoInternal();
345 	std::pair<int32_t, ndk::ScopedAStatus> validateDirInfoInternal(
346 		const P2pDirInfo& dirInfo);
347 	::ndk::ScopedAStatus reinvokePersistentGroupInternal(
348 		const P2pReinvokePersistentGroupParams& reinvokeGroupParams);
349 
350 	struct wpa_supplicant* retrieveIfacePtr();
351 	struct wpa_supplicant* retrieveGroupIfacePtr(
352 		const std::string& group_ifname);
353 
354 	// Reference to the global wpa_struct. This is assumed to be valid for
355 	// the lifetime of the process.
356 	struct wpa_global* wpa_global_;
357 	// Name of the iface this aidl object controls
358 	const std::string ifname_;
359 	bool is_valid_;
360 
361 	DISALLOW_COPY_AND_ASSIGN(P2pIface);
362 };
363 
364 }  // namespace supplicant
365 }  // namespace wifi
366 }  // namespace hardware
367 }  // namespace android
368 }  // namespace aidl
369 
370 #endif  // WPA_SUPPLICANT_AIDL_P2P_IFACE_H
371