• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
179 private:
180 	// Corresponding worker functions for the AIDL methods.
181 	std::pair<std::string, ndk::ScopedAStatus> getNameInternal();
182 	std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal();
183 	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
184 		addNetworkInternal();
185 	ndk::ScopedAStatus removeNetworkInternal(int32_t id);
186 	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
187 		getNetworkInternal(int32_t id);
188 	std::pair<std::vector<int32_t>, ndk::ScopedAStatus>
189 		listNetworksInternal();
190 	ndk::ScopedAStatus registerCallbackInternal(
191 		const std::shared_ptr<ISupplicantP2pIfaceCallback>& callback);
192 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
193 		getDeviceAddressInternal();
194 	ndk::ScopedAStatus setSsidPostfixInternal(
195 		const std::vector<uint8_t>& postfix);
196 	ndk::ScopedAStatus setGroupIdleInternal(
197 		const std::string& group_ifname, uint32_t timeout_in_sec);
198 	ndk::ScopedAStatus setPowerSaveInternal(
199 		const std::string& group_ifname, bool enable);
200 	ndk::ScopedAStatus findInternal(uint32_t timeout_in_sec);
201 	ndk::ScopedAStatus stopFindInternal();
202 	ndk::ScopedAStatus flushInternal();
203 	std::pair<std::string, ndk::ScopedAStatus> connectInternal(
204 		const std::vector<uint8_t>& peer_address,
205 		WpsProvisionMethod provision_method,
206 		const std::string& pre_selected_pin, bool join_existing_group,
207 		bool persistent, uint32_t go_intent);
208 	ndk::ScopedAStatus cancelConnectInternal();
209 	ndk::ScopedAStatus provisionDiscoveryInternal(
210 		const std::vector<uint8_t>& peer_address,
211 		WpsProvisionMethod provision_method);
212 	ndk::ScopedAStatus addGroupInternal(bool in_persistent, int32_t in_persistentNetworkId);
213 	ndk::ScopedAStatus addGroupWithConfigInternal(
214 		const std::vector<uint8_t>& ssid, const std::string& passphrase,
215 		bool persistent, uint32_t freq, const std::vector<uint8_t>& peer_address,
216 		bool joinExistingGroup);
217 	ndk::ScopedAStatus removeGroupInternal(const std::string& group_ifname);
218 	ndk::ScopedAStatus rejectInternal(
219 		const std::vector<uint8_t>& peer_address);
220 	ndk::ScopedAStatus inviteInternal(
221 		const std::string& group_ifname,
222 		const std::vector<uint8_t>& go_device_address,
223 		const std::vector<uint8_t>& peer_address);
224 	ndk::ScopedAStatus reinvokeInternal(
225 		int32_t persistent_network_id,
226 		const std::vector<uint8_t>& peer_address);
227 	ndk::ScopedAStatus configureExtListenInternal(
228 		uint32_t period_in_millis, uint32_t interval_in_millis);
229 	ndk::ScopedAStatus setListenChannelInternal(
230 		uint32_t channel, uint32_t operating_class);
231 	ndk::ScopedAStatus setDisallowedFrequenciesInternal(
232 		const std::vector<FreqRange>& ranges);
233 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal(
234 		const std::vector<uint8_t>& peer_address);
235 	std::pair<P2pGroupCapabilityMask, ndk::ScopedAStatus> getGroupCapabilityInternal(
236 		const std::vector<uint8_t>& peer_address);
237 	ndk::ScopedAStatus addBonjourServiceInternal(
238 		const std::vector<uint8_t>& query,
239 		const std::vector<uint8_t>& response);
240 	ndk::ScopedAStatus removeBonjourServiceInternal(
241 		const std::vector<uint8_t>& query);
242 	ndk::ScopedAStatus addUpnpServiceInternal(
243 		uint32_t version, const std::string& service_name);
244 	ndk::ScopedAStatus removeUpnpServiceInternal(
245 		uint32_t version, const std::string& service_name);
246 	ndk::ScopedAStatus flushServicesInternal();
247 	std::pair<uint64_t, ndk::ScopedAStatus> requestServiceDiscoveryInternal(
248 		const std::vector<uint8_t>& peer_address,
249 		const std::vector<uint8_t>& query);
250 	ndk::ScopedAStatus cancelServiceDiscoveryInternal(uint64_t identifier);
251 	ndk::ScopedAStatus setMiracastModeInternal(
252 		MiracastMode mode);
253 	ndk::ScopedAStatus startWpsPbcInternal(
254 		const std::string& group_ifname,
255 		const std::vector<uint8_t>& bssid);
256 	ndk::ScopedAStatus startWpsPinKeypadInternal(
257 		const std::string& group_ifname, const std::string& pin);
258 	std::pair<std::string, ndk::ScopedAStatus> startWpsPinDisplayInternal(
259 		const std::string& group_ifname,
260 		const std::vector<uint8_t>& bssid);
261 	ndk::ScopedAStatus cancelWpsInternal(const std::string& group_ifname);
262 	ndk::ScopedAStatus setWpsDeviceNameInternal(const std::string& name);
263 	ndk::ScopedAStatus setWpsDeviceTypeInternal(
264 		const std::vector<uint8_t>& type);
265 	ndk::ScopedAStatus setWpsManufacturerInternal(
266 		const std::string& manufacturer);
267 	ndk::ScopedAStatus setWpsModelNameInternal(const std::string& model_name);
268 	ndk::ScopedAStatus setWpsModelNumberInternal(
269 		const std::string& model_number);
270 	ndk::ScopedAStatus setWpsSerialNumberInternal(
271 		const std::string& serial_number);
272 	ndk::ScopedAStatus setWpsConfigMethodsInternal(WpsConfigMethods config_methods);
273 	ndk::ScopedAStatus enableWfdInternal(bool enable);
274 	ndk::ScopedAStatus setWfdDeviceInfoInternal(
275 		const std::vector<uint8_t>& info);
276 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
277 		createNfcHandoverRequestMessageInternal();
278 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
279 		createNfcHandoverSelectMessageInternal();
280 	ndk::ScopedAStatus reportNfcHandoverResponseInternal(
281 		const std::vector<uint8_t>& request);
282 	ndk::ScopedAStatus reportNfcHandoverInitiationInternal(
283 		const std::vector<uint8_t>& select);
284 	ndk::ScopedAStatus saveConfigInternal();
285 	ndk::ScopedAStatus setMacRandomizationInternal(bool enable);
286 	ndk::ScopedAStatus setEdmgInternal(bool enable);
287 	std::pair<bool, ndk::ScopedAStatus> getEdmgInternal();
288 	ndk::ScopedAStatus setWfdR2DeviceInfoInternal(
289 		const std::vector<uint8_t>& info);
290 	ndk::ScopedAStatus removeClientInternal(
291 		const std::vector<uint8_t>& peer_address, bool isLegacyClient);
292 	ndk::ScopedAStatus findOnSocialChannelsInternal(uint32_t timeout_in_sec);
293 	ndk::ScopedAStatus findOnSpecificFrequencyInternal(
294 		uint32_t freq, uint32_t timeout_in_sec);
295 	ndk::ScopedAStatus setVendorElementsInternal(
296 		P2pFrameTypeMask frameTypeMask,
297 		const std::vector<uint8_t>& vendorElemBytes);
298 	::ndk::ScopedAStatus configureEapolIpAddressAllocationParamsInternal(
299 		uint32_t ipAddressGo, uint32_t ipAddressMask,
300 		uint32_t ipAddressStart, uint32_t ipAddressEnd);
301 
302 	struct wpa_supplicant* retrieveIfacePtr();
303 	struct wpa_supplicant* retrieveGroupIfacePtr(
304 		const std::string& group_ifname);
305 
306 	// Reference to the global wpa_struct. This is assumed to be valid for
307 	// the lifetime of the process.
308 	struct wpa_global* wpa_global_;
309 	// Name of the iface this aidl object controls
310 	const std::string ifname_;
311 	bool is_valid_;
312 
313 	DISALLOW_COPY_AND_ASSIGN(P2pIface);
314 };
315 
316 }  // namespace supplicant
317 }  // namespace wifi
318 }  // namespace hardware
319 }  // namespace android
320 }  // namespace aidl
321 
322 #endif  // WPA_SUPPLICANT_AIDL_P2P_IFACE_H
323