• 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 #include "aidl_manager.h"
10 #include "aidl_return_util.h"
11 #include "iface_config_utils.h"
12 #include "misc_utils.h"
13 #include "p2p_iface.h"
14 #include "sta_network.h"
15 
16 extern "C"
17 {
18 #include "ap.h"
19 #include "wps_supplicant.h"
20 #include "wifi_display.h"
21 #include "utils/eloop.h"
22 #include "wpa_supplicant_i.h"
23 #include "driver_i.h"
24 }
25 
26 #define P2P_JOIN_LIMIT 3
27 
28 namespace {
29 const char kConfigMethodStrPbc[] = "pbc";
30 const char kConfigMethodStrDisplay[] = "display";
31 const char kConfigMethodStrKeypad[] = "keypad";
32 constexpr char kSetMiracastMode[] = "MIRACAST ";
33 constexpr uint8_t kWfdDeviceInfoSubelemId = 0;
34 constexpr uint8_t kWfdR2DeviceInfoSubelemId = 11;
35 constexpr char kWfdDeviceInfoSubelemLenHexStr[] = "0006";
36 
37 std::function<void()> pending_join_scan_callback = NULL;
38 std::function<void()> pending_scan_res_join_callback = NULL;
39 
40 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
41 using aidl::android::hardware::wifi::supplicant::ISupplicantStaNetwork;
42 using aidl::android::hardware::wifi::supplicant::MiracastMode;
43 using aidl::android::hardware::wifi::supplicant::P2pFrameTypeMask;
44 
convertAidlMiracastModeToInternal(MiracastMode mode)45 uint8_t convertAidlMiracastModeToInternal(
46 	MiracastMode mode)
47 {
48 	switch (mode) {
49 	case MiracastMode::DISABLED:
50 		return 0;
51 	case MiracastMode::SOURCE:
52 		return 1;
53 	case MiracastMode::SINK:
54 		return 2;
55 	};
56 	WPA_ASSERT(false);
57 }
58 
59 /**
60  * Check if the provided ssid is valid or not.
61  *
62  * Returns 1 if valid, 0 otherwise.
63  */
isSsidValid(const std::vector<uint8_t> & ssid)64 int isSsidValid(const std::vector<uint8_t>& ssid)
65 {
66 	if (ssid.size() == 0 ||
67 		ssid.size() >
68 		static_cast<uint32_t>(ISupplicantStaNetwork::
69 					  SSID_MAX_LEN_IN_BYTES)) {
70 		return 0;
71 	}
72 	return 1;
73 }
74 
75 /**
76  * Check if the provided psk passhrase is valid or not.
77  *
78  * Returns 1 if valid, 0 otherwise.
79  */
isPskPassphraseValid(const std::string & psk)80 int isPskPassphraseValid(const std::string &psk)
81 {
82 	if (psk.size() <
83 		static_cast<uint32_t>(ISupplicantStaNetwork::
84 					  PSK_PASSPHRASE_MIN_LEN_IN_BYTES) ||
85 		psk.size() >
86 		static_cast<uint32_t>(ISupplicantStaNetwork::
87 					  PSK_PASSPHRASE_MAX_LEN_IN_BYTES)) {
88 		return 0;
89 	}
90 	if (has_ctrl_char((u8 *)psk.c_str(), psk.size())) {
91 		return 0;
92 	}
93 	return 1;
94 }
95 
96 /*
97  * isAnyEtherAddr - match any ether address
98  *
99  */
isAnyEtherAddr(const u8 * a)100 int isAnyEtherAddr(const u8 *a)
101 {
102 	// 02:00:00:00:00:00
103 	return (a[0] == 2) && !(a[1] | a[2] | a[3] | a[4] | a[5]);
104 }
105 
addGroupClientNetwork(struct wpa_supplicant * wpa_s,const uint8_t * group_owner_bssid,const std::vector<uint8_t> & ssid,const std::string & passphrase)106 struct wpa_ssid* addGroupClientNetwork(
107 	struct wpa_supplicant* wpa_s,
108 	const uint8_t *group_owner_bssid,
109 	const std::vector<uint8_t>& ssid,
110 	const std::string& passphrase)
111 {
112 	struct wpa_ssid* wpa_network = wpa_config_add_network(wpa_s->conf);
113 	if (!wpa_network) {
114 		return NULL;
115 	}
116 	// set general network defaults
117 	wpa_config_set_network_defaults(wpa_network);
118 
119 	// set P2p network defaults
120 	wpa_network->p2p_group = 1;
121 	wpa_network->mode = wpas_mode::WPAS_MODE_INFRA;
122 	wpa_network->disabled = 2;
123 
124 	// set necessary fields
125 	wpa_network->ssid = (uint8_t *)os_malloc(ssid.size());
126 	if (wpa_network->ssid == NULL) {
127 		wpa_config_remove_network(wpa_s->conf, wpa_network->id);
128 		return NULL;
129 	}
130 	memcpy(wpa_network->ssid, ssid.data(), ssid.size());
131 	wpa_network->ssid_len = ssid.size();
132 
133 	wpa_network->psk_set = 0;
134 	wpa_network->passphrase = dup_binstr(passphrase.c_str(), passphrase.length());
135 	if (wpa_network->passphrase == NULL) {
136 		wpa_config_remove_network(wpa_s->conf, wpa_network->id);
137 		return NULL;
138 	}
139 	wpa_config_update_psk(wpa_network);
140 
141 	return wpa_network;
142 
143 }
144 
scanResJoinWrapper(struct wpa_supplicant * wpa_s,struct wpa_scan_results * scan_res)145 void scanResJoinWrapper(
146 	struct wpa_supplicant *wpa_s,
147 	struct wpa_scan_results *scan_res)
148 {
149 	if (wpa_s->p2p_scan_work) {
150 		struct wpa_radio_work *work = wpa_s->p2p_scan_work;
151 		wpa_s->p2p_scan_work = NULL;
152 		radio_work_done(work);
153 	}
154 
155 	if (pending_scan_res_join_callback) {
156 		pending_scan_res_join_callback();
157 	}
158 }
159 
is6GhzAllowed(struct wpa_supplicant * wpa_s)160 static bool is6GhzAllowed(struct wpa_supplicant *wpa_s) {
161 	if (!wpa_s->global->p2p) return false;
162 	return wpa_s->global->p2p->allow_6ghz;
163 }
164 
joinGroup(struct wpa_supplicant * wpa_s,const uint8_t * group_owner_bssid,const std::vector<uint8_t> & ssid,const std::string & passphrase,uint32_t freq)165 int joinGroup(
166 	struct wpa_supplicant* wpa_s,
167 	const uint8_t *group_owner_bssid,
168 	const std::vector<uint8_t>& ssid,
169 	const std::string& passphrase,
170 	uint32_t freq)
171 {
172 	int ret = 0;
173 	int he = wpa_s->conf->p2p_go_he;
174 	int vht = wpa_s->conf->p2p_go_vht;
175 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
176 
177 	// Construct a network for adding group.
178 	// Group client follows the persistent attribute of Group Owner.
179 	// If joined group is persistent, it adds a persistent network on GroupStarted.
180 	struct wpa_ssid *wpa_network = addGroupClientNetwork(
181 		wpa_s, group_owner_bssid, ssid, passphrase);
182 	if (wpa_network == NULL) {
183 		wpa_printf(MSG_ERROR, "P2P: Cannot construct a network for group join.");
184 		return -1;
185 	}
186 
187 	// this is temporary network only for establishing the connection.
188 	wpa_network->temporary = 1;
189 
190 	if (wpas_p2p_group_add_persistent(
191 		wpa_s, wpa_network, 0, 0, freq, 0, ht40, vht,
192 		CONF_OPER_CHWIDTH_USE_HT, he, 0, NULL, 0, 0, is6GhzAllowed(wpa_s),
193 		P2P_JOIN_LIMIT, isAnyEtherAddr(group_owner_bssid) ? NULL : group_owner_bssid)) {
194 		ret = -1;
195 	}
196 
197 	// Always remove this temporary network at the end.
198 	wpa_config_remove_network(wpa_s->conf, wpa_network->id);
199 	return ret;
200 }
201 
scanResJoinIgnore(struct wpa_supplicant * wpa_s,struct wpa_scan_results * scan_res)202 void scanResJoinIgnore(struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res) {
203 	wpa_printf(MSG_DEBUG, "P2P: Ignore group join scan results.");
204 
205 	if (wpa_s->p2p_scan_work) {
206 		struct wpa_radio_work *work = wpa_s->p2p_scan_work;
207 		wpa_s->p2p_scan_work = NULL;
208 		radio_work_done(work);
209 	}
210 
211 }
212 
updateP2pVendorElem(struct wpa_supplicant * wpa_s,enum wpa_vendor_elem_frame frameType,const std::vector<uint8_t> & vendorElemBytes)213 static void updateP2pVendorElem(struct wpa_supplicant* wpa_s, enum wpa_vendor_elem_frame frameType,
214 	const std::vector<uint8_t>& vendorElemBytes) {
215 
216 	wpa_printf(MSG_INFO, "Set vendor elements to frames %d", frameType);
217 	struct wpa_supplicant* vendor_elem_wpa_s = wpas_vendor_elem(wpa_s, frameType);
218 	if (vendor_elem_wpa_s->vendor_elem[frameType]) {
219 		wpabuf_free(vendor_elem_wpa_s->vendor_elem[frameType]);
220 		vendor_elem_wpa_s->vendor_elem[frameType] = NULL;
221 	}
222 	if (vendorElemBytes.size() > 0) {
223 		vendor_elem_wpa_s->vendor_elem[frameType] =
224 			wpabuf_alloc_copy(vendorElemBytes.data(), vendorElemBytes.size());
225 	}
226 	wpas_vendor_elem_update(vendor_elem_wpa_s);
227 }
228 
convertWpaP2pFrameTypeToHalP2pFrameTypeBit(int frameType)229 uint32_t convertWpaP2pFrameTypeToHalP2pFrameTypeBit(int frameType) {
230 	switch (frameType) {
231 	case VENDOR_ELEM_PROBE_REQ_P2P:
232 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_PROBE_REQ_P2P);
233 	case VENDOR_ELEM_PROBE_RESP_P2P:
234 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_PROBE_RESP_P2P);
235 	case VENDOR_ELEM_PROBE_RESP_P2P_GO:
236 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_PROBE_RESP_P2P_GO);
237 	case VENDOR_ELEM_BEACON_P2P_GO:
238 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_BEACON_P2P_GO);
239 	case VENDOR_ELEM_P2P_PD_REQ:
240 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_PD_REQ);
241 	case VENDOR_ELEM_P2P_PD_RESP:
242 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_PD_RESP);
243 	case VENDOR_ELEM_P2P_GO_NEG_REQ:
244 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_GO_NEG_REQ);
245 	case VENDOR_ELEM_P2P_GO_NEG_RESP:
246 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_GO_NEG_RESP);
247 	case VENDOR_ELEM_P2P_GO_NEG_CONF:
248 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_GO_NEG_CONF);
249 	case VENDOR_ELEM_P2P_INV_REQ:
250 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_INV_REQ);
251 	case VENDOR_ELEM_P2P_INV_RESP:
252 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_INV_RESP);
253 	case VENDOR_ELEM_P2P_ASSOC_REQ:
254 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_ASSOC_REQ);
255 	case VENDOR_ELEM_P2P_ASSOC_RESP:
256 		return static_cast<uint32_t>(P2pFrameTypeMask::P2P_FRAME_P2P_ASSOC_RESP);
257 	}
258 	return 0;
259 }
260 }  // namespace
261 
262 namespace aidl {
263 namespace android {
264 namespace hardware {
265 namespace wifi {
266 namespace supplicant {
267 using aidl_return_util::validateAndCall;
268 using misc_utils::createStatus;
269 using misc_utils::createStatusWithMsg;
270 
P2pIface(struct wpa_global * wpa_global,const char ifname[])271 P2pIface::P2pIface(struct wpa_global* wpa_global, const char ifname[])
272 	: wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)
273 {}
274 
invalidate()275 void P2pIface::invalidate() { is_valid_ = false; }
isValid()276 bool P2pIface::isValid()
277 {
278 	return (is_valid_ && (retrieveIfacePtr() != nullptr));
279 }
280 
getName(std::string * _aidl_return)281 ::ndk::ScopedAStatus P2pIface::getName(
282 	std::string* _aidl_return)
283 {
284 	return validateAndCall(
285 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
286 		&P2pIface::getNameInternal, _aidl_return);
287 }
288 
getType(IfaceType * _aidl_return)289 ::ndk::ScopedAStatus P2pIface::getType(
290 	IfaceType* _aidl_return)
291 {
292 	return validateAndCall(
293 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
294 		&P2pIface::getTypeInternal, _aidl_return);
295 }
296 
addNetwork(std::shared_ptr<ISupplicantP2pNetwork> * _aidl_return)297 ::ndk::ScopedAStatus P2pIface::addNetwork(
298 	std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return)
299 {
300 	return validateAndCall(
301 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
302 		&P2pIface::addNetworkInternal, _aidl_return);
303 }
304 
removeNetwork(int32_t in_id)305 ::ndk::ScopedAStatus P2pIface::removeNetwork(
306 	int32_t in_id)
307 {
308 	return validateAndCall(
309 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
310 		&P2pIface::removeNetworkInternal, in_id);
311 }
312 
getNetwork(int32_t in_id,std::shared_ptr<ISupplicantP2pNetwork> * _aidl_return)313 ::ndk::ScopedAStatus P2pIface::getNetwork(
314 	int32_t in_id, std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return)
315 {
316 	return validateAndCall(
317 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
318 		&P2pIface::getNetworkInternal, _aidl_return, in_id);
319 }
320 
listNetworks(std::vector<int32_t> * _aidl_return)321 ::ndk::ScopedAStatus P2pIface::listNetworks(
322 	std::vector<int32_t>* _aidl_return)
323 {
324 	return validateAndCall(
325 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
326 		&P2pIface::listNetworksInternal, _aidl_return);
327 }
328 
registerCallback(const std::shared_ptr<ISupplicantP2pIfaceCallback> & in_callback)329 ::ndk::ScopedAStatus P2pIface::registerCallback(
330 	const std::shared_ptr<ISupplicantP2pIfaceCallback>& in_callback)
331 {
332 	return validateAndCall(
333 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
334 		&P2pIface::registerCallbackInternal, in_callback);
335 }
336 
getDeviceAddress(std::vector<uint8_t> * _aidl_return)337 ::ndk::ScopedAStatus P2pIface::getDeviceAddress(
338 	std::vector<uint8_t>* _aidl_return)
339 {
340 	return validateAndCall(
341 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
342 		&P2pIface::getDeviceAddressInternal, _aidl_return);
343 }
344 
setSsidPostfix(const std::vector<uint8_t> & in_postfix)345 ::ndk::ScopedAStatus P2pIface::setSsidPostfix(
346 	const std::vector<uint8_t>& in_postfix)
347 {
348 	return validateAndCall(
349 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
350 		&P2pIface::setSsidPostfixInternal, in_postfix);
351 }
352 
setGroupIdle(const std::string & in_groupIfName,int32_t in_timeoutInSec)353 ::ndk::ScopedAStatus P2pIface::setGroupIdle(
354 	const std::string& in_groupIfName, int32_t in_timeoutInSec)
355 {
356 	return validateAndCall(
357 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
358 		&P2pIface::setGroupIdleInternal, in_groupIfName,
359 		in_timeoutInSec);
360 }
361 
setPowerSave(const std::string & in_groupIfName,bool in_enable)362 ::ndk::ScopedAStatus P2pIface::setPowerSave(
363 	const std::string& in_groupIfName, bool in_enable)
364 {
365 	return validateAndCall(
366 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
367 		&P2pIface::setPowerSaveInternal, in_groupIfName, in_enable);
368 }
369 
find(int32_t in_timeoutInSec)370 ::ndk::ScopedAStatus P2pIface::find(
371 	int32_t in_timeoutInSec)
372 {
373 	return validateAndCall(
374 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
375 		&P2pIface::findInternal, in_timeoutInSec);
376 }
377 
stopFind()378 ::ndk::ScopedAStatus P2pIface::stopFind()
379 {
380 	return validateAndCall(
381 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
382 		&P2pIface::stopFindInternal);
383 }
384 
flush()385 ::ndk::ScopedAStatus P2pIface::flush()
386 {
387 	return validateAndCall(
388 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
389 		&P2pIface::flushInternal);
390 }
391 
connect(const std::vector<uint8_t> & in_peerAddress,WpsProvisionMethod in_provisionMethod,const std::string & in_preSelectedPin,bool in_joinExistingGroup,bool in_persistent,int32_t in_goIntent,std::string * _aidl_return)392 ::ndk::ScopedAStatus P2pIface::connect(
393 	const std::vector<uint8_t>& in_peerAddress,
394 	WpsProvisionMethod in_provisionMethod,
395 	const std::string& in_preSelectedPin, bool in_joinExistingGroup,
396 	bool in_persistent, int32_t in_goIntent, std::string* _aidl_return)
397 {
398 	return validateAndCall(
399 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
400 		&P2pIface::connectInternal, _aidl_return, in_peerAddress,
401 		in_provisionMethod, in_preSelectedPin, in_joinExistingGroup,
402 		in_persistent, in_goIntent);
403 }
404 
cancelConnect()405 ::ndk::ScopedAStatus P2pIface::cancelConnect()
406 {
407 	return validateAndCall(
408 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
409 		&P2pIface::cancelConnectInternal);
410 }
411 
provisionDiscovery(const std::vector<uint8_t> & in_peerAddress,WpsProvisionMethod in_provisionMethod)412 ::ndk::ScopedAStatus P2pIface::provisionDiscovery(
413 	const std::vector<uint8_t>& in_peerAddress,
414 	WpsProvisionMethod in_provisionMethod)
415 {
416 	return validateAndCall(
417 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
418 		&P2pIface::provisionDiscoveryInternal, in_peerAddress,
419 		in_provisionMethod);
420 }
421 
addGroup(bool in_persistent,int32_t in_persistentNetworkId)422 ndk::ScopedAStatus P2pIface::addGroup(
423 	bool in_persistent, int32_t in_persistentNetworkId)
424 {
425 	return validateAndCall(
426 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
427 		&P2pIface::addGroupInternal, in_persistent,
428 		in_persistentNetworkId);
429 }
430 
addGroupWithConfig(const std::vector<uint8_t> & in_ssid,const std::string & in_pskPassphrase,bool in_persistent,int32_t in_freq,const std::vector<uint8_t> & in_peerAddress,bool in_joinExistingGroup)431 ::ndk::ScopedAStatus P2pIface::addGroupWithConfig(
432 	const std::vector<uint8_t>& in_ssid,
433 	const std::string& in_pskPassphrase, bool in_persistent,
434 	int32_t in_freq, const std::vector<uint8_t>& in_peerAddress,
435 	bool in_joinExistingGroup)
436 {
437 	return validateAndCall(
438 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
439 		&P2pIface::addGroupWithConfigInternal, in_ssid,
440 		in_pskPassphrase, in_persistent, in_freq,
441 		in_peerAddress, in_joinExistingGroup);
442 }
443 
removeGroup(const std::string & in_groupIfName)444 ::ndk::ScopedAStatus P2pIface::removeGroup(
445 	const std::string& in_groupIfName)
446 {
447 	return validateAndCall(
448 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
449 		&P2pIface::removeGroupInternal, in_groupIfName);
450 }
451 
reject(const std::vector<uint8_t> & in_peerAddress)452 ::ndk::ScopedAStatus P2pIface::reject(
453 	const std::vector<uint8_t>& in_peerAddress)
454 {
455 	return validateAndCall(
456 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
457 		&P2pIface::rejectInternal, in_peerAddress);
458 }
459 
invite(const std::string & in_groupIfName,const std::vector<uint8_t> & in_goDeviceAddress,const std::vector<uint8_t> & in_peerAddress)460 ::ndk::ScopedAStatus P2pIface::invite(
461 	const std::string& in_groupIfName,
462 	const std::vector<uint8_t>& in_goDeviceAddress,
463 	const std::vector<uint8_t>& in_peerAddress)
464 {
465 	return validateAndCall(
466 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
467 		&P2pIface::inviteInternal, in_groupIfName,
468 		in_goDeviceAddress, in_peerAddress);
469 }
470 
reinvoke(int32_t in_persistentNetworkId,const std::vector<uint8_t> & in_peerAddress)471 ::ndk::ScopedAStatus P2pIface::reinvoke(
472 	int32_t in_persistentNetworkId,
473 	const std::vector<uint8_t>& in_peerAddress)
474 {
475 	return validateAndCall(
476 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
477 		&P2pIface::reinvokeInternal, in_persistentNetworkId,
478 		in_peerAddress);
479 }
480 
configureExtListen(int32_t in_periodInMillis,int32_t in_intervalInMillis)481 ::ndk::ScopedAStatus P2pIface::configureExtListen(
482 	int32_t in_periodInMillis, int32_t in_intervalInMillis)
483 {
484 	return validateAndCall(
485 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
486 		&P2pIface::configureExtListenInternal, in_periodInMillis,
487 		in_intervalInMillis);
488 }
489 
setListenChannel(int32_t in_channel,int32_t in_operatingClass)490 ::ndk::ScopedAStatus P2pIface::setListenChannel(
491 	int32_t in_channel, int32_t in_operatingClass)
492 {
493 	return validateAndCall(
494 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
495 		&P2pIface::setListenChannelInternal, in_channel,
496 		in_operatingClass);
497 }
498 
setDisallowedFrequencies(const std::vector<FreqRange> & in_ranges)499 ::ndk::ScopedAStatus P2pIface::setDisallowedFrequencies(
500 	const std::vector<FreqRange>& in_ranges)
501 {
502 	return validateAndCall(
503 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
504 		&P2pIface::setDisallowedFrequenciesInternal, in_ranges);
505 }
506 
getSsid(const std::vector<uint8_t> & in_peerAddress,std::vector<uint8_t> * _aidl_return)507 ::ndk::ScopedAStatus P2pIface::getSsid(
508 	const std::vector<uint8_t>& in_peerAddress,
509 	std::vector<uint8_t>* _aidl_return)
510 {
511 	return validateAndCall(
512 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
513 		&P2pIface::getSsidInternal, _aidl_return, in_peerAddress);
514 }
515 
getGroupCapability(const std::vector<uint8_t> & in_peerAddress,P2pGroupCapabilityMask * _aidl_return)516 ::ndk::ScopedAStatus P2pIface::getGroupCapability(
517 	const std::vector<uint8_t>& in_peerAddress,
518 	P2pGroupCapabilityMask* _aidl_return)
519 {
520 	return validateAndCall(
521 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
522 		&P2pIface::getGroupCapabilityInternal, _aidl_return, in_peerAddress);
523 }
524 
addBonjourService(const std::vector<uint8_t> & in_query,const std::vector<uint8_t> & in_response)525 ::ndk::ScopedAStatus P2pIface::addBonjourService(
526 	const std::vector<uint8_t>& in_query,
527 	const std::vector<uint8_t>& in_response)
528 {
529 	return validateAndCall(
530 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
531 		&P2pIface::addBonjourServiceInternal, in_query, in_response);
532 }
533 
removeBonjourService(const std::vector<uint8_t> & in_query)534 ::ndk::ScopedAStatus P2pIface::removeBonjourService(
535 	const std::vector<uint8_t>& in_query)
536 {
537 	return validateAndCall(
538 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
539 		&P2pIface::removeBonjourServiceInternal, in_query);
540 }
541 
addUpnpService(int32_t in_version,const std::string & in_serviceName)542 ::ndk::ScopedAStatus P2pIface::addUpnpService(
543 	int32_t in_version, const std::string& in_serviceName)
544 {
545 	return validateAndCall(
546 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
547 		&P2pIface::addUpnpServiceInternal, in_version, in_serviceName);
548 }
549 
removeUpnpService(int32_t in_version,const std::string & in_serviceName)550 ::ndk::ScopedAStatus P2pIface::removeUpnpService(
551 	int32_t in_version, const std::string& in_serviceName)
552 {
553 	return validateAndCall(
554 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
555 		&P2pIface::removeUpnpServiceInternal, in_version,
556 		in_serviceName);
557 }
558 
flushServices()559 ::ndk::ScopedAStatus P2pIface::flushServices()
560 {
561 	return validateAndCall(
562 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
563 		&P2pIface::flushServicesInternal);
564 }
565 
requestServiceDiscovery(const std::vector<uint8_t> & in_peerAddress,const std::vector<uint8_t> & in_query,int64_t * _aidl_return)566 ::ndk::ScopedAStatus P2pIface::requestServiceDiscovery(
567 	const std::vector<uint8_t>& in_peerAddress,
568 	const std::vector<uint8_t>& in_query,
569 	int64_t* _aidl_return)
570 {
571 	return validateAndCall(
572 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
573 		&P2pIface::requestServiceDiscoveryInternal, _aidl_return,
574 		in_peerAddress, in_query);
575 }
576 
cancelServiceDiscovery(int64_t in_identifier)577 ::ndk::ScopedAStatus P2pIface::cancelServiceDiscovery(
578 	int64_t in_identifier)
579 {
580 	return validateAndCall(
581 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
582 		&P2pIface::cancelServiceDiscoveryInternal, in_identifier);
583 }
584 
setMiracastMode(MiracastMode in_mode)585 ::ndk::ScopedAStatus P2pIface::setMiracastMode(
586 	MiracastMode in_mode)
587 {
588 	return validateAndCall(
589 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
590 		&P2pIface::setMiracastModeInternal, in_mode);
591 }
592 
startWpsPbc(const std::string & in_groupIfName,const std::vector<uint8_t> & in_bssid)593 ::ndk::ScopedAStatus P2pIface::startWpsPbc(
594 	const std::string& in_groupIfName,
595 	const std::vector<uint8_t>& in_bssid)
596 {
597 	return validateAndCall(
598 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
599 		&P2pIface::startWpsPbcInternal, in_groupIfName, in_bssid);
600 }
601 
startWpsPinKeypad(const std::string & in_groupIfName,const std::string & in_pin)602 ::ndk::ScopedAStatus P2pIface::startWpsPinKeypad(
603 	const std::string& in_groupIfName,
604 	const std::string& in_pin)
605 {
606 	return validateAndCall(
607 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
608 		&P2pIface::startWpsPinKeypadInternal, in_groupIfName, in_pin);
609 }
610 
startWpsPinDisplay(const std::string & in_groupIfName,const std::vector<uint8_t> & in_bssid,std::string * _aidl_return)611 ::ndk::ScopedAStatus P2pIface::startWpsPinDisplay(
612 	const std::string& in_groupIfName,
613 	const std::vector<uint8_t>& in_bssid,
614 	std::string* _aidl_return)
615 {
616 	return validateAndCall(
617 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
618 		&P2pIface::startWpsPinDisplayInternal, _aidl_return,
619 		in_groupIfName, in_bssid);
620 }
621 
cancelWps(const std::string & in_groupIfName)622 ::ndk::ScopedAStatus P2pIface::cancelWps(
623 	const std::string& in_groupIfName)
624 {
625 	return validateAndCall(
626 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
627 		&P2pIface::cancelWpsInternal, in_groupIfName);
628 }
629 
setWpsDeviceName(const std::string & in_name)630 ::ndk::ScopedAStatus P2pIface::setWpsDeviceName(
631 	const std::string& in_name)
632 {
633 	return validateAndCall(
634 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
635 		&P2pIface::setWpsDeviceNameInternal, in_name);
636 }
637 
setWpsDeviceType(const std::vector<uint8_t> & in_type)638 ::ndk::ScopedAStatus P2pIface::setWpsDeviceType(
639 	const std::vector<uint8_t>& in_type)
640 {
641 	return validateAndCall(
642 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
643 		&P2pIface::setWpsDeviceTypeInternal, in_type);
644 }
645 
setWpsManufacturer(const std::string & in_manufacturer)646 ::ndk::ScopedAStatus P2pIface::setWpsManufacturer(
647 	const std::string& in_manufacturer)
648 {
649 	return validateAndCall(
650 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
651 		&P2pIface::setWpsManufacturerInternal, in_manufacturer);
652 }
653 
setWpsModelName(const std::string & in_modelName)654 ::ndk::ScopedAStatus P2pIface::setWpsModelName(
655 	const std::string& in_modelName)
656 {
657 	return validateAndCall(
658 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
659 		&P2pIface::setWpsModelNameInternal, in_modelName);
660 }
661 
setWpsModelNumber(const std::string & in_modelNumber)662 ::ndk::ScopedAStatus P2pIface::setWpsModelNumber(
663 	const std::string& in_modelNumber)
664 {
665 	return validateAndCall(
666 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
667 		&P2pIface::setWpsModelNumberInternal, in_modelNumber);
668 }
669 
setWpsSerialNumber(const std::string & in_serialNumber)670 ::ndk::ScopedAStatus P2pIface::setWpsSerialNumber(
671 	const std::string& in_serialNumber)
672 {
673 	return validateAndCall(
674 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
675 		&P2pIface::setWpsSerialNumberInternal, in_serialNumber);
676 }
677 
setWpsConfigMethods(WpsConfigMethods in_configMethods)678 ::ndk::ScopedAStatus P2pIface::setWpsConfigMethods(
679 	WpsConfigMethods in_configMethods)
680 {
681 	return validateAndCall(
682 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
683 		&P2pIface::setWpsConfigMethodsInternal, in_configMethods);
684 }
685 
enableWfd(bool in_enable)686 ::ndk::ScopedAStatus P2pIface::enableWfd(
687 	bool in_enable)
688 {
689 	return validateAndCall(
690 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
691 		&P2pIface::enableWfdInternal, in_enable);
692 }
693 
setWfdDeviceInfo(const std::vector<uint8_t> & in_info)694 ::ndk::ScopedAStatus P2pIface::setWfdDeviceInfo(
695 	const std::vector<uint8_t>& in_info)
696 {
697 	return validateAndCall(
698 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
699 		&P2pIface::setWfdDeviceInfoInternal, in_info);
700 }
701 
createNfcHandoverRequestMessage(std::vector<uint8_t> * _aidl_return)702 ::ndk::ScopedAStatus P2pIface::createNfcHandoverRequestMessage(
703 	std::vector<uint8_t>* _aidl_return)
704 {
705 	return validateAndCall(
706 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
707 		&P2pIface::createNfcHandoverRequestMessageInternal, _aidl_return);
708 }
709 
createNfcHandoverSelectMessage(std::vector<uint8_t> * _aidl_return)710 ::ndk::ScopedAStatus P2pIface::createNfcHandoverSelectMessage(
711 	std::vector<uint8_t>* _aidl_return)
712 {
713 	return validateAndCall(
714 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
715 		&P2pIface::createNfcHandoverSelectMessageInternal, _aidl_return);
716 }
717 
reportNfcHandoverResponse(const std::vector<uint8_t> & in_request)718 ::ndk::ScopedAStatus P2pIface::reportNfcHandoverResponse(
719 	const std::vector<uint8_t>& in_request)
720 {
721 	return validateAndCall(
722 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
723 		&P2pIface::reportNfcHandoverResponseInternal, in_request);
724 }
725 
reportNfcHandoverInitiation(const std::vector<uint8_t> & in_select)726 ::ndk::ScopedAStatus P2pIface::reportNfcHandoverInitiation(
727 	const std::vector<uint8_t>& in_select)
728 {
729 	return validateAndCall(
730 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
731 		&P2pIface::reportNfcHandoverInitiationInternal, in_select);
732 }
733 
saveConfig()734 ::ndk::ScopedAStatus P2pIface::saveConfig()
735 {
736 	return validateAndCall(
737 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
738 		&P2pIface::saveConfigInternal);
739 }
740 
setMacRandomization(bool in_enable)741 ::ndk::ScopedAStatus P2pIface::setMacRandomization(
742 	bool in_enable)
743 {
744 	return validateAndCall(
745 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
746 		&P2pIface::setMacRandomizationInternal, in_enable);
747 }
748 
setEdmg(bool in_enable)749 ::ndk::ScopedAStatus P2pIface::setEdmg(
750 	bool in_enable)
751 {
752 	return validateAndCall(
753 		this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
754 		&P2pIface::setEdmgInternal, in_enable);
755 }
756 
getEdmg(bool * _aidl_return)757 ::ndk::ScopedAStatus P2pIface::getEdmg(
758 	bool* _aidl_return)
759 {
760 	return validateAndCall(
761 		this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
762 		&P2pIface::getEdmgInternal, _aidl_return);
763 }
764 
setWfdR2DeviceInfo(const std::vector<uint8_t> & in_info)765 ::ndk::ScopedAStatus P2pIface::setWfdR2DeviceInfo(
766 	const std::vector<uint8_t>& in_info)
767 {
768 	return validateAndCall(
769 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
770 		&P2pIface::setWfdR2DeviceInfoInternal, in_info);
771 }
772 
removeClient(const std::vector<uint8_t> & peer_address,bool isLegacyClient)773 ::ndk::ScopedAStatus P2pIface::removeClient(
774         const std::vector<uint8_t>& peer_address, bool isLegacyClient)
775 {
776 	return validateAndCall(
777 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
778 		&P2pIface::removeClientInternal, peer_address, isLegacyClient);
779 }
780 
findOnSocialChannels(int32_t in_timeoutInSec)781 ::ndk::ScopedAStatus P2pIface::findOnSocialChannels(
782 	int32_t in_timeoutInSec)
783 {
784 	return validateAndCall(
785 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
786 		&P2pIface::findOnSocialChannelsInternal, in_timeoutInSec);
787 }
788 
findOnSpecificFrequency(int32_t in_freq,int32_t in_timeoutInSec)789 ::ndk::ScopedAStatus P2pIface::findOnSpecificFrequency(
790 	int32_t in_freq,
791 	int32_t in_timeoutInSec)
792 {
793 	return validateAndCall(
794 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
795 		&P2pIface::findOnSpecificFrequencyInternal,
796 		in_freq, in_timeoutInSec);
797 }
798 
setVendorElements(P2pFrameTypeMask in_frameTypeMask,const std::vector<uint8_t> & in_vendorElemBytes)799 ::ndk::ScopedAStatus P2pIface::setVendorElements(
800 	P2pFrameTypeMask in_frameTypeMask,
801 	const std::vector<uint8_t>& in_vendorElemBytes)
802 {
803 	return validateAndCall(
804 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
805 		&P2pIface::setVendorElementsInternal, in_frameTypeMask, in_vendorElemBytes);
806 }
807 
configureEapolIpAddressAllocationParams(int32_t in_ipAddressGo,int32_t in_ipAddressMask,int32_t in_ipAddressStart,int32_t in_ipAddressEnd)808 ::ndk::ScopedAStatus P2pIface::configureEapolIpAddressAllocationParams(
809 	int32_t in_ipAddressGo, int32_t in_ipAddressMask,
810 	int32_t in_ipAddressStart, int32_t in_ipAddressEnd)
811 {
812 	return validateAndCall(
813 		this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
814 		&P2pIface::configureEapolIpAddressAllocationParamsInternal,
815 		in_ipAddressGo, in_ipAddressMask, in_ipAddressStart, in_ipAddressEnd);
816 }
817 
getNameInternal()818 std::pair<std::string, ndk::ScopedAStatus> P2pIface::getNameInternal()
819 {
820 	return {ifname_, ndk::ScopedAStatus::ok()};
821 }
822 
getTypeInternal()823 std::pair<IfaceType, ndk::ScopedAStatus> P2pIface::getTypeInternal()
824 {
825 	return {IfaceType::P2P, ndk::ScopedAStatus::ok()};
826 }
827 
828 std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
addNetworkInternal()829 P2pIface::addNetworkInternal()
830 {
831 	std::shared_ptr<ISupplicantP2pNetwork> network;
832 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
833 	struct wpa_ssid* ssid = wpa_supplicant_add_network(wpa_s);
834 	if (!ssid) {
835 		return {network, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
836 	}
837 	AidlManager* aidl_manager = AidlManager::getInstance();
838 	if (!aidl_manager ||
839 		aidl_manager->getP2pNetworkAidlObjectByIfnameAndNetworkId(
840 		wpa_s->ifname, ssid->id, &network)) {
841 		return {network, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
842 	}
843 	return {network, ndk::ScopedAStatus::ok()};
844 }
845 
removeNetworkInternal(int32_t id)846 ndk::ScopedAStatus P2pIface::removeNetworkInternal(int32_t id)
847 {
848 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
849 	int result = wpa_supplicant_remove_network(wpa_s, id);
850 	if (result == -1) {
851 		return createStatus(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN);
852 	} else if (result != 0) {
853 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
854 	}
855 	return ndk::ScopedAStatus::ok();
856 }
857 
858 std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
getNetworkInternal(int32_t id)859 P2pIface::getNetworkInternal(int32_t id)
860 {
861 	std::shared_ptr<ISupplicantP2pNetwork> network;
862 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
863 	struct wpa_ssid* ssid = wpa_config_get_network(wpa_s->conf, id);
864 	if (!ssid) {
865 		return {network, createStatus(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN)};
866 	}
867 	AidlManager* aidl_manager = AidlManager::getInstance();
868 	if (!aidl_manager ||
869 		aidl_manager->getP2pNetworkAidlObjectByIfnameAndNetworkId(
870 		wpa_s->ifname, ssid->id, &network)) {
871 		return {network, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
872 	}
873 	return {network, ndk::ScopedAStatus::ok()};
874 }
875 
876 std::pair<std::vector<int32_t>, ndk::ScopedAStatus>
listNetworksInternal()877 P2pIface::listNetworksInternal()
878 {
879 	std::vector<int32_t> network_ids;
880 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
881 	for (struct wpa_ssid* wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
882 		 wpa_ssid = wpa_ssid->next) {
883 		network_ids.emplace_back(wpa_ssid->id);
884 	}
885 	return {std::move(network_ids), ndk::ScopedAStatus::ok()};
886 }
887 
registerCallbackInternal(const std::shared_ptr<ISupplicantP2pIfaceCallback> & callback)888 ndk::ScopedAStatus P2pIface::registerCallbackInternal(
889 	const std::shared_ptr<ISupplicantP2pIfaceCallback>& callback)
890 {
891 	AidlManager* aidl_manager = AidlManager::getInstance();
892 	if (!aidl_manager ||
893 		aidl_manager->addP2pIfaceCallbackAidlObject(ifname_, callback)) {
894 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
895 	}
896 	return ndk::ScopedAStatus::ok();
897 }
898 
899 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getDeviceAddressInternal()900 P2pIface::getDeviceAddressInternal()
901 {
902 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
903 	std::vector<uint8_t> addr(
904 		wpa_s->global->p2p_dev_addr,
905 		wpa_s->global->p2p_dev_addr + ETH_ALEN);
906 	return {addr, ndk::ScopedAStatus::ok()};
907 }
908 
setSsidPostfixInternal(const std::vector<uint8_t> & postfix)909 ndk::ScopedAStatus P2pIface::setSsidPostfixInternal(
910 	const std::vector<uint8_t>& postfix)
911 {
912 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
913 	if (p2p_set_ssid_postfix(
914 		wpa_s->global->p2p, postfix.data(), postfix.size())) {
915 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
916 	}
917 	return ndk::ScopedAStatus::ok();
918 }
919 
setGroupIdleInternal(const std::string & group_ifname,uint32_t timeout_in_sec)920 ndk::ScopedAStatus P2pIface::setGroupIdleInternal(
921 	const std::string& group_ifname, uint32_t timeout_in_sec)
922 {
923 	struct wpa_supplicant* wpa_group_s =
924 		retrieveGroupIfacePtr(group_ifname);
925 	if (!wpa_group_s) {
926 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
927 	}
928 	wpa_group_s->conf->p2p_group_idle = timeout_in_sec;
929 	return ndk::ScopedAStatus::ok();
930 }
931 
setPowerSaveInternal(const std::string & group_ifname,bool enable)932 ndk::ScopedAStatus P2pIface::setPowerSaveInternal(
933 	const std::string& group_ifname, bool enable)
934 {
935 	struct wpa_supplicant* wpa_group_s =
936 		retrieveGroupIfacePtr(group_ifname);
937 	if (!wpa_group_s) {
938 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
939 	}
940 	if (wpa_drv_set_p2p_powersave(wpa_group_s, enable, -1, -1)) {
941 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
942 	}
943 	return ndk::ScopedAStatus::ok();
944 }
945 
findInternal(uint32_t timeout_in_sec)946 ndk::ScopedAStatus P2pIface::findInternal(uint32_t timeout_in_sec)
947 {
948 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
949 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
950 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
951 	}
952 	uint32_t search_delay = wpas_p2p_search_delay(wpa_s);
953 	if (wpas_p2p_find(
954 		wpa_s, timeout_in_sec, P2P_FIND_START_WITH_FULL, 0, nullptr,
955 		nullptr, search_delay, 0, nullptr, 0, is6GhzAllowed(wpa_s))) {
956 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
957 	}
958 	return ndk::ScopedAStatus::ok();
959 }
960 
stopFindInternal()961 ndk::ScopedAStatus P2pIface::stopFindInternal()
962 {
963 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
964 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
965 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
966 	}
967 	if (wpa_s->scan_res_handler == scanResJoinWrapper) {
968 		wpa_printf(MSG_DEBUG, "P2P: Stop pending group scan for stopping find).");
969 		pending_scan_res_join_callback = NULL;
970 		wpa_s->scan_res_handler = scanResJoinIgnore;
971 	}
972 	wpas_p2p_stop_find(wpa_s);
973 	return ndk::ScopedAStatus::ok();
974 }
975 
flushInternal()976 ndk::ScopedAStatus P2pIface::flushInternal()
977 {
978 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
979 	os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
980 	wpa_s->force_long_sd = 0;
981 	wpas_p2p_stop_find(wpa_s);
982 	wpa_s->parent->p2ps_method_config_any = 0;
983 	wpa_bss_flush(wpa_s);
984 	if (wpa_s->global->p2p)
985 		p2p_flush(wpa_s->global->p2p);
986 	return ndk::ScopedAStatus::ok();
987 }
988 
989 // This method only implements support for subset (needed by Android framework)
990 // of parameters that can be specified for connect.
connectInternal(const std::vector<uint8_t> & peer_address,WpsProvisionMethod provision_method,const std::string & pre_selected_pin,bool join_existing_group,bool persistent,uint32_t go_intent)991 std::pair<std::string, ndk::ScopedAStatus> P2pIface::connectInternal(
992 	const std::vector<uint8_t>& peer_address,
993 	WpsProvisionMethod provision_method,
994 	const std::string& pre_selected_pin, bool join_existing_group,
995 	bool persistent, uint32_t go_intent)
996 {
997 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
998 	if (go_intent > 15) {
999 		return {"", createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID)};
1000 	}
1001 	if (peer_address.size() != ETH_ALEN) {
1002 		return {"", createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID)};
1003 	}
1004 	int go_intent_signed = join_existing_group ? -1 : go_intent;
1005 	p2p_wps_method wps_method = {};
1006 	switch (provision_method) {
1007 	case WpsProvisionMethod::PBC:
1008 		wps_method = WPS_PBC;
1009 		break;
1010 	case WpsProvisionMethod::DISPLAY:
1011 		wps_method = WPS_PIN_DISPLAY;
1012 		break;
1013 	case WpsProvisionMethod::KEYPAD:
1014 		wps_method = WPS_PIN_KEYPAD;
1015 		break;
1016 	}
1017 	int he = wpa_s->conf->p2p_go_he;
1018 	int vht = wpa_s->conf->p2p_go_vht;
1019 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
1020 	int edmg = wpa_s->conf->p2p_go_edmg;
1021 	const char* pin =
1022 		pre_selected_pin.length() > 0 ? pre_selected_pin.data() : nullptr;
1023 	int new_pin = wpas_p2p_connect(
1024 		wpa_s, peer_address.data(), pin, wps_method, persistent, false,
1025 		join_existing_group, false, go_intent_signed, 0, 0, -1, false, ht40,
1026 		vht, CONF_OPER_CHWIDTH_USE_HT, he, edmg, nullptr, 0, is6GhzAllowed(wpa_s));
1027 	if (new_pin < 0) {
1028 		return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1029 	}
1030 	std::string pin_ret;
1031 	if (provision_method == WpsProvisionMethod::DISPLAY &&
1032 		pre_selected_pin.empty()) {
1033 		pin_ret = misc_utils::convertWpsPinToString(new_pin);
1034 	}
1035 	return {pin_ret, ndk::ScopedAStatus::ok()};
1036 }
1037 
cancelConnectInternal()1038 ndk::ScopedAStatus P2pIface::cancelConnectInternal()
1039 {
1040 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1041 	if (wpa_s->scan_res_handler == scanResJoinWrapper) {
1042 		wpa_printf(MSG_DEBUG, "P2P: Stop pending group scan for canceling connect");
1043 		pending_scan_res_join_callback = NULL;
1044 		wpa_s->scan_res_handler = scanResJoinIgnore;
1045 	}
1046 	if (wpas_p2p_cancel(wpa_s)) {
1047 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1048 	}
1049 	return ndk::ScopedAStatus::ok();
1050 }
1051 
provisionDiscoveryInternal(const std::vector<uint8_t> & peer_address,WpsProvisionMethod provision_method)1052 ndk::ScopedAStatus P2pIface::provisionDiscoveryInternal(
1053 	const std::vector<uint8_t>& peer_address,
1054 	WpsProvisionMethod provision_method)
1055 {
1056 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1057 	p2ps_provision* prov_param;
1058 	const char* config_method_str = nullptr;
1059 	if (peer_address.size() != ETH_ALEN) {
1060 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1061 	}
1062 	switch (provision_method) {
1063 	case WpsProvisionMethod::PBC:
1064 		config_method_str = kConfigMethodStrPbc;
1065 		break;
1066 	case WpsProvisionMethod::DISPLAY:
1067 		config_method_str = kConfigMethodStrDisplay;
1068 		break;
1069 	case WpsProvisionMethod::KEYPAD:
1070 		config_method_str = kConfigMethodStrKeypad;
1071 		break;
1072 	}
1073 	if (wpas_p2p_prov_disc(
1074 		wpa_s, peer_address.data(), config_method_str,
1075 		WPAS_P2P_PD_FOR_GO_NEG, nullptr)) {
1076 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1077 	}
1078 	return ndk::ScopedAStatus::ok();
1079 }
1080 
removeGroupInternal(const std::string & group_ifname)1081 ndk::ScopedAStatus P2pIface::removeGroupInternal(const std::string& group_ifname)
1082 {
1083 	struct wpa_supplicant* wpa_group_s =
1084 		retrieveGroupIfacePtr(group_ifname);
1085 	if (!wpa_group_s) {
1086 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
1087 	}
1088 	if (wpas_p2p_group_remove(wpa_group_s, group_ifname.c_str())) {
1089 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1090 	}
1091 	return ndk::ScopedAStatus::ok();
1092 }
1093 
rejectInternal(const std::vector<uint8_t> & peer_address)1094 ndk::ScopedAStatus P2pIface::rejectInternal(
1095 	const std::vector<uint8_t>& peer_address)
1096 {
1097 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1098 	if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) {
1099 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
1100 	}
1101 	if (peer_address.size() != ETH_ALEN) {
1102 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1103 	}
1104 	if (wpas_p2p_reject(wpa_s, peer_address.data())) {
1105 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1106 	}
1107 	return ndk::ScopedAStatus::ok();
1108 }
1109 
inviteInternal(const std::string & group_ifname,const std::vector<uint8_t> & go_device_address,const std::vector<uint8_t> & peer_address)1110 ndk::ScopedAStatus P2pIface::inviteInternal(
1111 	const std::string& group_ifname,
1112 	const std::vector<uint8_t>& go_device_address,
1113 	const std::vector<uint8_t>& peer_address)
1114 {
1115 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1116 	if (go_device_address.size() != ETH_ALEN || peer_address.size() != ETH_ALEN) {
1117 		return {createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1118 	}
1119 	if (wpas_p2p_invite_group(
1120 		wpa_s, group_ifname.c_str(), peer_address.data(),
1121 		go_device_address.data(), is6GhzAllowed(wpa_s))) {
1122 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1123 	}
1124 	return ndk::ScopedAStatus::ok();
1125 }
1126 
reinvokeInternal(int32_t persistent_network_id,const std::vector<uint8_t> & peer_address)1127 ndk::ScopedAStatus P2pIface::reinvokeInternal(
1128 	int32_t persistent_network_id,
1129 	const std::vector<uint8_t>& peer_address)
1130 {
1131 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1132 	int he = wpa_s->conf->p2p_go_he;
1133 	int vht = wpa_s->conf->p2p_go_vht;
1134 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
1135 	int edmg = wpa_s->conf->p2p_go_edmg;
1136 	struct wpa_ssid* ssid =
1137 		wpa_config_get_network(wpa_s->conf, persistent_network_id);
1138 	if (ssid == NULL || ssid->disabled != 2) {
1139 		return createStatus(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN);
1140 	}
1141 	if (peer_address.size() != ETH_ALEN) {
1142 		return {createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1143 	}
1144 	if (wpas_p2p_invite(
1145 		wpa_s, peer_address.data(), ssid, NULL, 0, 0, ht40, vht,
1146 		CONF_OPER_CHWIDTH_USE_HT, 0, he, edmg, is6GhzAllowed(wpa_s))) {
1147 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1148 	}
1149 	return ndk::ScopedAStatus::ok();
1150 }
1151 
configureExtListenInternal(uint32_t period_in_millis,uint32_t interval_in_millis)1152 ndk::ScopedAStatus P2pIface::configureExtListenInternal(
1153 	uint32_t period_in_millis, uint32_t interval_in_millis)
1154 {
1155 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1156 	if (wpas_p2p_ext_listen(wpa_s, period_in_millis, interval_in_millis)) {
1157 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1158 	}
1159 	return ndk::ScopedAStatus::ok();
1160 }
1161 
setListenChannelInternal(uint32_t channel,uint32_t operating_class)1162 ndk::ScopedAStatus P2pIface::setListenChannelInternal(
1163 	uint32_t channel, uint32_t operating_class)
1164 {
1165 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1166 	if (p2p_set_listen_channel(
1167 		wpa_s->global->p2p, operating_class, channel, 1)) {
1168 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1169 	}
1170 	return ndk::ScopedAStatus::ok();
1171 }
1172 
setDisallowedFrequenciesInternal(const std::vector<FreqRange> & ranges)1173 ndk::ScopedAStatus P2pIface::setDisallowedFrequenciesInternal(
1174 	const std::vector<FreqRange>& ranges)
1175 {
1176 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1177 	using DestT = struct wpa_freq_range_list::wpa_freq_range;
1178 	DestT* freq_ranges = nullptr;
1179 	// Empty ranges is used to enable all frequencies.
1180 	if (ranges.size() != 0) {
1181 		freq_ranges = static_cast<DestT*>(
1182 			os_malloc(sizeof(DestT) * ranges.size()));
1183 		if (!freq_ranges) {
1184 			return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1185 		}
1186 		uint32_t i = 0;
1187 		for (const auto& range : ranges) {
1188 			freq_ranges[i].min = range.min;
1189 			freq_ranges[i].max = range.max;
1190 			i++;
1191 		}
1192 	}
1193 
1194 	os_free(wpa_s->global->p2p_disallow_freq.range);
1195 	wpa_s->global->p2p_disallow_freq.range = freq_ranges;
1196 	wpa_s->global->p2p_disallow_freq.num = ranges.size();
1197 	wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
1198 	return ndk::ScopedAStatus::ok();
1199 }
1200 
getSsidInternal(const std::vector<uint8_t> & peer_address)1201 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> P2pIface::getSsidInternal(
1202 	const std::vector<uint8_t>& peer_address)
1203 {
1204 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1205 	if (peer_address.size() != ETH_ALEN) {
1206 		return {std::vector<uint8_t>(),
1207 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1208 	}
1209 	const struct p2p_peer_info* info =
1210 		p2p_get_peer_info(wpa_s->global->p2p, peer_address.data(), 0);
1211 	if (!info) {
1212 		return {std::vector<uint8_t>(),
1213 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1214 	}
1215 	const struct p2p_device* dev =
1216 		reinterpret_cast<const struct p2p_device*>(
1217 		(reinterpret_cast<const uint8_t*>(info)) -
1218 		offsetof(struct p2p_device, info));
1219 	std::vector<uint8_t> ssid;
1220 	if (dev && dev->oper_ssid_len) {
1221 		ssid.assign(
1222 			dev->oper_ssid, dev->oper_ssid + dev->oper_ssid_len);
1223 	}
1224 	return {ssid, ndk::ScopedAStatus::ok()};
1225 }
1226 
getGroupCapabilityInternal(const std::vector<uint8_t> & peer_address)1227 std::pair<P2pGroupCapabilityMask, ndk::ScopedAStatus> P2pIface::getGroupCapabilityInternal(
1228 	const std::vector<uint8_t>& peer_address)
1229 {
1230 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1231 	if (peer_address.size() != ETH_ALEN) {
1232 		return {static_cast<P2pGroupCapabilityMask>(0),
1233 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1234 	}
1235 	const struct p2p_peer_info* info =
1236 		p2p_get_peer_info(wpa_s->global->p2p, peer_address.data(), 0);
1237 	if (!info) {
1238 		return {static_cast<P2pGroupCapabilityMask>(0),
1239 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1240 	}
1241 	return {static_cast<P2pGroupCapabilityMask>(info->group_capab),
1242 		ndk::ScopedAStatus::ok()};
1243 }
1244 
addBonjourServiceInternal(const std::vector<uint8_t> & query,const std::vector<uint8_t> & response)1245 ndk::ScopedAStatus P2pIface::addBonjourServiceInternal(
1246 	const std::vector<uint8_t>& query, const std::vector<uint8_t>& response)
1247 {
1248 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1249 	auto query_buf = misc_utils::convertVectorToWpaBuf(query);
1250 	auto response_buf = misc_utils::convertVectorToWpaBuf(response);
1251 	if (!query_buf || !response_buf) {
1252 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1253 	}
1254 	if (wpas_p2p_service_add_bonjour(
1255 		wpa_s, query_buf.get(), response_buf.get())) {
1256 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1257 	}
1258 	// If successful, the wpabuf is referenced internally and hence should
1259 	// not be freed.
1260 	query_buf.release();
1261 	response_buf.release();
1262 	return ndk::ScopedAStatus::ok();
1263 }
1264 
removeBonjourServiceInternal(const std::vector<uint8_t> & query)1265 ndk::ScopedAStatus P2pIface::removeBonjourServiceInternal(
1266 	const std::vector<uint8_t>& query)
1267 {
1268 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1269 	auto query_buf = misc_utils::convertVectorToWpaBuf(query);
1270 	if (!query_buf) {
1271 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1272 	}
1273 	if (wpas_p2p_service_del_bonjour(wpa_s, query_buf.get())) {
1274 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1275 	}
1276 	return ndk::ScopedAStatus::ok();
1277 }
1278 
addUpnpServiceInternal(uint32_t version,const std::string & service_name)1279 ndk::ScopedAStatus P2pIface::addUpnpServiceInternal(
1280 	uint32_t version, const std::string& service_name)
1281 {
1282 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1283 	if (wpas_p2p_service_add_upnp(wpa_s, version, service_name.c_str())) {
1284 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1285 	}
1286 	return ndk::ScopedAStatus::ok();
1287 }
1288 
removeUpnpServiceInternal(uint32_t version,const std::string & service_name)1289 ndk::ScopedAStatus P2pIface::removeUpnpServiceInternal(
1290 	uint32_t version, const std::string& service_name)
1291 {
1292 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1293 	if (wpas_p2p_service_del_upnp(wpa_s, version, service_name.c_str())) {
1294 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1295 	}
1296 	return ndk::ScopedAStatus::ok();
1297 }
1298 
flushServicesInternal()1299 ndk::ScopedAStatus P2pIface::flushServicesInternal()
1300 {
1301 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1302 	wpas_p2p_service_flush(wpa_s);
1303 	return ndk::ScopedAStatus::ok();
1304 }
1305 
requestServiceDiscoveryInternal(const std::vector<uint8_t> & peer_address,const std::vector<uint8_t> & query)1306 std::pair<uint64_t, ndk::ScopedAStatus> P2pIface::requestServiceDiscoveryInternal(
1307 	const std::vector<uint8_t>& peer_address,
1308 	const std::vector<uint8_t>& query)
1309 {
1310 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1311 	auto query_buf = misc_utils::convertVectorToWpaBuf(query);
1312 	if (!query_buf) {
1313 		return {0, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1314 	}
1315 	if (peer_address.size() != ETH_ALEN) {
1316 		return {0, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1317 	}
1318 	const uint8_t* dst_addr = is_zero_ether_addr(peer_address.data())
1319 					  ? nullptr
1320 					  : peer_address.data();
1321 	uint64_t identifier =
1322 		wpas_p2p_sd_request(wpa_s, dst_addr, query_buf.get());
1323 	if (identifier == 0) {
1324 		return {0, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1325 	}
1326 	return {identifier, ndk::ScopedAStatus::ok()};
1327 }
1328 
cancelServiceDiscoveryInternal(uint64_t identifier)1329 ndk::ScopedAStatus P2pIface::cancelServiceDiscoveryInternal(uint64_t identifier)
1330 {
1331 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1332 	if (wpas_p2p_sd_cancel_request(wpa_s, identifier)) {
1333 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1334 	}
1335 	return ndk::ScopedAStatus::ok();
1336 }
1337 
setMiracastModeInternal(MiracastMode mode)1338 ndk::ScopedAStatus P2pIface::setMiracastModeInternal(
1339 	MiracastMode mode)
1340 {
1341 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1342 	uint8_t mode_internal = convertAidlMiracastModeToInternal(mode);
1343 	const std::string cmd_str =
1344 		kSetMiracastMode + std::to_string(mode_internal);
1345 	std::vector<char> cmd(
1346 		cmd_str.c_str(), cmd_str.c_str() + cmd_str.size() + 1);
1347 	char driver_cmd_reply_buf[4096] = {};
1348 	if (wpa_drv_driver_cmd(
1349 		wpa_s, cmd.data(), driver_cmd_reply_buf,
1350 		sizeof(driver_cmd_reply_buf))) {
1351 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1352 	}
1353 	return ndk::ScopedAStatus::ok();
1354 }
1355 
startWpsPbcInternal(const std::string & group_ifname,const std::vector<uint8_t> & bssid)1356 ndk::ScopedAStatus P2pIface::startWpsPbcInternal(
1357 	const std::string& group_ifname, const std::vector<uint8_t>& bssid)
1358 {
1359 	struct wpa_supplicant* wpa_group_s =
1360 		retrieveGroupIfacePtr(group_ifname);
1361 	if (!wpa_group_s) {
1362 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
1363 	}
1364 	if (bssid.size() != ETH_ALEN) {
1365 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1366 	}
1367 	const uint8_t* bssid_addr =
1368 		is_zero_ether_addr(bssid.data()) ? nullptr : bssid.data();
1369 #ifdef CONFIG_AP
1370 	if (wpa_group_s->ap_iface) {
1371 		if (wpa_supplicant_ap_wps_pbc(wpa_group_s, bssid_addr, NULL)) {
1372 			return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1373 		}
1374 		return ndk::ScopedAStatus::ok();
1375 	}
1376 #endif /* CONFIG_AP */
1377 	if (wpas_wps_start_pbc(wpa_group_s, bssid_addr, 0, 0)) {
1378 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1379 	}
1380 	return ndk::ScopedAStatus::ok();
1381 }
1382 
startWpsPinKeypadInternal(const std::string & group_ifname,const std::string & pin)1383 ndk::ScopedAStatus P2pIface::startWpsPinKeypadInternal(
1384 	const std::string& group_ifname, const std::string& pin)
1385 {
1386 	struct wpa_supplicant* wpa_group_s =
1387 		retrieveGroupIfacePtr(group_ifname);
1388 	if (!wpa_group_s) {
1389 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
1390 	}
1391 #ifdef CONFIG_AP
1392 	if (wpa_group_s->ap_iface) {
1393 		if (wpa_supplicant_ap_wps_pin(
1394 			wpa_group_s, nullptr, pin.c_str(), nullptr, 0, 0) < 0) {
1395 			return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1396 		}
1397 		return ndk::ScopedAStatus::ok();
1398 	}
1399 #endif /* CONFIG_AP */
1400 	if (wpas_wps_start_pin(
1401 		wpa_group_s, nullptr, pin.c_str(), 0, DEV_PW_DEFAULT)) {
1402 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1403 	}
1404 	return ndk::ScopedAStatus::ok();
1405 }
1406 
startWpsPinDisplayInternal(const std::string & group_ifname,const std::vector<uint8_t> & bssid)1407 std::pair<std::string, ndk::ScopedAStatus> P2pIface::startWpsPinDisplayInternal(
1408 	const std::string& group_ifname, const std::vector<uint8_t>& bssid)
1409 {
1410 	struct wpa_supplicant* wpa_group_s =
1411 		retrieveGroupIfacePtr(group_ifname);
1412 	if (!wpa_group_s) {
1413 		return {"", createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN)};
1414 	}
1415 	if (bssid.size() != ETH_ALEN) {
1416 		return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1417 	}
1418 	const uint8_t* bssid_addr =
1419 		is_zero_ether_addr(bssid.data()) ? nullptr : bssid.data();
1420 	int pin = wpas_wps_start_pin(
1421 		wpa_group_s, bssid_addr, nullptr, 0, DEV_PW_DEFAULT);
1422 	if (pin < 0) {
1423 		return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1424 	}
1425 	return {misc_utils::convertWpsPinToString(pin), ndk::ScopedAStatus::ok()};
1426 }
1427 
cancelWpsInternal(const std::string & group_ifname)1428 ndk::ScopedAStatus P2pIface::cancelWpsInternal(const std::string& group_ifname)
1429 {
1430 	struct wpa_supplicant* wpa_group_s =
1431 		retrieveGroupIfacePtr(group_ifname);
1432 	if (!wpa_group_s) {
1433 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
1434 	}
1435 	if (wpas_wps_cancel(wpa_group_s)) {
1436 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1437 	}
1438 	return ndk::ScopedAStatus::ok();
1439 }
1440 
setWpsDeviceNameInternal(const std::string & name)1441 ndk::ScopedAStatus P2pIface::setWpsDeviceNameInternal(const std::string& name)
1442 {
1443 	return iface_config_utils::setWpsDeviceName(retrieveIfacePtr(), name);
1444 }
1445 
setWpsDeviceTypeInternal(const std::vector<uint8_t> & type)1446 ndk::ScopedAStatus P2pIface::setWpsDeviceTypeInternal(
1447 	const std::vector<uint8_t>& type)
1448 {
1449 	std::array<uint8_t, 8> type_arr;
1450 	if (type.size() != 8) {
1451 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1452 	}
1453 	std::copy_n(type.begin(), 8, type_arr.begin());
1454 	return iface_config_utils::setWpsDeviceType(retrieveIfacePtr(), type_arr);
1455 }
1456 
setWpsManufacturerInternal(const std::string & manufacturer)1457 ndk::ScopedAStatus P2pIface::setWpsManufacturerInternal(
1458 	const std::string& manufacturer)
1459 {
1460 	return iface_config_utils::setWpsManufacturer(
1461 		retrieveIfacePtr(), manufacturer);
1462 }
1463 
setWpsModelNameInternal(const std::string & model_name)1464 ndk::ScopedAStatus P2pIface::setWpsModelNameInternal(
1465 	const std::string& model_name)
1466 {
1467 	return iface_config_utils::setWpsModelName(
1468 		retrieveIfacePtr(), model_name);
1469 }
1470 
setWpsModelNumberInternal(const std::string & model_number)1471 ndk::ScopedAStatus P2pIface::setWpsModelNumberInternal(
1472 	const std::string& model_number)
1473 {
1474 	return iface_config_utils::setWpsModelNumber(
1475 		retrieveIfacePtr(), model_number);
1476 }
1477 
setWpsSerialNumberInternal(const std::string & serial_number)1478 ndk::ScopedAStatus P2pIface::setWpsSerialNumberInternal(
1479 	const std::string& serial_number)
1480 {
1481 	return iface_config_utils::setWpsSerialNumber(
1482 		retrieveIfacePtr(), serial_number);
1483 }
1484 
setWpsConfigMethodsInternal(WpsConfigMethods config_methods)1485 ndk::ScopedAStatus P2pIface::setWpsConfigMethodsInternal(WpsConfigMethods config_methods)
1486 {
1487 
1488 	return iface_config_utils::setWpsConfigMethods(
1489 		retrieveIfacePtr(), static_cast<uint16_t>(config_methods));
1490 }
1491 
enableWfdInternal(bool enable)1492 ndk::ScopedAStatus P2pIface::enableWfdInternal(bool enable)
1493 {
1494 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1495 	wifi_display_enable(wpa_s->global, enable);
1496 	return ndk::ScopedAStatus::ok();
1497 }
1498 
setWfdDeviceInfoInternal(const std::vector<uint8_t> & info)1499 ndk::ScopedAStatus P2pIface::setWfdDeviceInfoInternal(
1500 	const std::vector<uint8_t>& info)
1501 {
1502 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1503 	std::vector<char> wfd_device_info_hex(info.size() * 2 + 1);
1504 	wpa_snprintf_hex(
1505 		wfd_device_info_hex.data(), wfd_device_info_hex.size(), info.data(),
1506 		info.size());
1507 	// |wifi_display_subelem_set| expects the first 2 bytes
1508 	// to hold the lenght of the subelement. In this case it's
1509 	// fixed to 6, so prepend that.
1510 	std::string wfd_device_info_set_cmd_str =
1511 		std::to_string(kWfdDeviceInfoSubelemId) + " " +
1512 		kWfdDeviceInfoSubelemLenHexStr + wfd_device_info_hex.data();
1513 	std::vector<char> wfd_device_info_set_cmd(
1514 		wfd_device_info_set_cmd_str.c_str(),
1515 		wfd_device_info_set_cmd_str.c_str() +
1516 		wfd_device_info_set_cmd_str.size() + 1);
1517 	if (wifi_display_subelem_set(
1518 		wpa_s->global, wfd_device_info_set_cmd.data())) {
1519 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1520 	}
1521 	return ndk::ScopedAStatus::ok();
1522 }
1523 
1524 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
createNfcHandoverRequestMessageInternal()1525 P2pIface::createNfcHandoverRequestMessageInternal()
1526 {
1527 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1528 	auto buf = misc_utils::createWpaBufUniquePtr(
1529 		wpas_p2p_nfc_handover_req(wpa_s, 1));
1530 	if (!buf) {
1531 		return {std::vector<uint8_t>(),
1532 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1533 	}
1534 	return {misc_utils::convertWpaBufToVector(buf.get()),
1535 		ndk::ScopedAStatus::ok()};
1536 }
1537 
1538 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
createNfcHandoverSelectMessageInternal()1539 P2pIface::createNfcHandoverSelectMessageInternal()
1540 {
1541 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1542 	auto buf = misc_utils::createWpaBufUniquePtr(
1543 		wpas_p2p_nfc_handover_sel(wpa_s, 1, 0));
1544 	if (!buf) {
1545 		return {std::vector<uint8_t>(),
1546 			createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1547 	}
1548 	return {misc_utils::convertWpaBufToVector(buf.get()),
1549 		ndk::ScopedAStatus::ok()};
1550 }
1551 
reportNfcHandoverResponseInternal(const std::vector<uint8_t> & request)1552 ndk::ScopedAStatus P2pIface::reportNfcHandoverResponseInternal(
1553 	const std::vector<uint8_t>& request)
1554 {
1555 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1556 	auto req = misc_utils::convertVectorToWpaBuf(request);
1557 	auto sel = misc_utils::convertVectorToWpaBuf(std::vector<uint8_t>{0});
1558 	if (!req || !sel) {
1559 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1560 	}
1561 
1562 	if (wpas_p2p_nfc_report_handover(wpa_s, 0, req.get(), sel.get(), 0)) {
1563 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1564 	}
1565 	return ndk::ScopedAStatus::ok();
1566 }
1567 
reportNfcHandoverInitiationInternal(const std::vector<uint8_t> & select)1568 ndk::ScopedAStatus P2pIface::reportNfcHandoverInitiationInternal(
1569 	const std::vector<uint8_t>& select)
1570 {
1571 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1572 	auto req = misc_utils::convertVectorToWpaBuf(std::vector<uint8_t>{0});
1573 	auto sel = misc_utils::convertVectorToWpaBuf(select);
1574 	if (!req || !sel) {
1575 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1576 	}
1577 
1578 	if (wpas_p2p_nfc_report_handover(wpa_s, 1, req.get(), sel.get(), 0)) {
1579 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1580 	}
1581 	return ndk::ScopedAStatus::ok();
1582 }
1583 
saveConfigInternal()1584 ndk::ScopedAStatus P2pIface::saveConfigInternal()
1585 {
1586 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1587 	if (!wpa_s->conf->update_config) {
1588 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1589 	}
1590 	if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
1591 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1592 	}
1593 	return ndk::ScopedAStatus::ok();
1594 }
1595 
addGroupInternal(bool persistent,int32_t persistent_network_id)1596 ndk::ScopedAStatus P2pIface::addGroupInternal(
1597 	bool persistent, int32_t persistent_network_id)
1598 {
1599 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1600 	int he = wpa_s->conf->p2p_go_he;
1601 	int vht = wpa_s->conf->p2p_go_vht;
1602 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
1603 	int edmg = wpa_s->conf->p2p_go_edmg;
1604 	struct wpa_ssid* ssid =
1605 		wpa_config_get_network(wpa_s->conf, persistent_network_id);
1606 	if (ssid == NULL) {
1607 		if (wpas_p2p_group_add(
1608 			wpa_s, persistent, 0, 0, ht40, vht,
1609 			CONF_OPER_CHWIDTH_USE_HT, he, edmg, is6GhzAllowed(wpa_s))) {
1610 			return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1611 		} else {
1612 			return ndk::ScopedAStatus::ok();
1613 		}
1614 	} else if (ssid->disabled == 2) {
1615 		if (wpas_p2p_group_add_persistent(
1616 			wpa_s, ssid, 0, 0, 0, 0, ht40, vht,
1617 			CONF_OPER_CHWIDTH_USE_HT, he, edmg, NULL, 0, 0,
1618 			is6GhzAllowed(wpa_s), 0, NULL)) {
1619 			return createStatus(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN);
1620 		} else {
1621 			return ndk::ScopedAStatus::ok();
1622 		}
1623 	}
1624 	return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1625 }
1626 
addGroupWithConfigInternal(const std::vector<uint8_t> & ssid,const std::string & passphrase,bool persistent,uint32_t freq,const std::vector<uint8_t> & peer_address,bool joinExistingGroup)1627 ndk::ScopedAStatus P2pIface::addGroupWithConfigInternal(
1628 	const std::vector<uint8_t>& ssid, const std::string& passphrase,
1629 	bool persistent, uint32_t freq, const std::vector<uint8_t>& peer_address,
1630 	bool joinExistingGroup)
1631 {
1632 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1633 	int he = wpa_s->conf->p2p_go_he;
1634 	int vht = wpa_s->conf->p2p_go_vht;
1635 	int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
1636 	int edmg = wpa_s->conf->p2p_go_edmg;
1637 
1638 	if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
1639 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
1640 	}
1641 
1642 	if (!isSsidValid(ssid)) {
1643 		return createStatusWithMsg(SupplicantStatusCode::FAILURE_ARGS_INVALID,
1644 			"SSID is invalid.");
1645 	}
1646 
1647 	if (!isPskPassphraseValid(passphrase)) {
1648 		return createStatusWithMsg(SupplicantStatusCode::FAILURE_ARGS_INVALID,
1649 			"Passphrase is invalid.");
1650 	}
1651 
1652 	wpa_printf(MSG_DEBUG,
1653 		    "P2P: Add group with config Role: %s network name: %s freq: %d",
1654 		    joinExistingGroup ? "CLIENT" : "GO",
1655 		    wpa_ssid_txt(ssid.data(), ssid.size()), freq);
1656 	if (!joinExistingGroup) {
1657 		struct p2p_data *p2p = wpa_s->global->p2p;
1658 		os_memcpy(p2p->ssid, ssid.data(), ssid.size());
1659 		p2p->ssid_len = ssid.size();
1660 		p2p->ssid_set = 1;
1661 
1662 		os_memset(p2p->passphrase, 0, sizeof(p2p->passphrase));
1663 		os_memcpy(p2p->passphrase, passphrase.c_str(), passphrase.length());
1664 		p2p->passphrase_set = 1;
1665 
1666 		if (wpas_p2p_group_add(
1667 			wpa_s, persistent, freq, 0, ht40, vht,
1668 			CONF_OPER_CHWIDTH_USE_HT, he, edmg, is6GhzAllowed(wpa_s))) {
1669 			return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1670 		}
1671 		return ndk::ScopedAStatus::ok();
1672 	}
1673 
1674 	// The rest is for group join.
1675 	wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND before group join.");
1676 	wpas_p2p_stop_find(wpa_s);
1677 	if (peer_address.size() != ETH_ALEN) {
1678 		return createStatusWithMsg(SupplicantStatusCode::FAILURE_ARGS_INVALID,
1679 			"Peer address is invalid.");
1680 	}
1681 	if (joinGroup(wpa_s, peer_address.data(), ssid, passphrase, freq)) {
1682 		return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
1683 			"Failed to start scan.");
1684 	}
1685 	return ndk::ScopedAStatus::ok();
1686 }
1687 
setMacRandomizationInternal(bool enable)1688 ndk::ScopedAStatus P2pIface::setMacRandomizationInternal(bool enable)
1689 {
1690 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1691 	bool currentEnabledState = !!wpa_s->conf->p2p_device_random_mac_addr;
1692 	u8 *addr = NULL;
1693 
1694 	// The same state, no change is needed.
1695 	if (currentEnabledState == enable) {
1696 		wpa_printf(MSG_DEBUG, "The random MAC is %s already.",
1697 			(enable) ? "enabled" : "disabled");
1698 		return ndk::ScopedAStatus::ok();
1699 	}
1700 
1701 	if (enable) {
1702 		wpa_s->conf->p2p_device_random_mac_addr = 1;
1703 		wpa_s->conf->p2p_interface_random_mac_addr = 1;
1704 		int status = wpas_p2p_mac_setup(wpa_s);
1705 
1706 		// restore config if it failed to set up MAC address.
1707 		if (status < 0) {
1708 			wpa_s->conf->p2p_device_random_mac_addr = 0;
1709 			wpa_s->conf->p2p_interface_random_mac_addr = 0;
1710 			if (status == -ENOTSUP) {
1711 				return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNSUPPORTED,
1712 					"Failed to set up MAC address, feature not supported.");
1713 			}
1714 			return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
1715 				"Failed to set up MAC address.");
1716 		}
1717 	} else {
1718 		// disable random MAC will use original MAC address
1719 		// regardless of any saved persistent groups.
1720 		if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) {
1721 			wpa_printf(MSG_ERROR, "Failed to restore MAC address");
1722 			return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
1723 				"Failed to restore MAC address.");
1724 		}
1725 
1726 		if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
1727 			wpa_printf(MSG_INFO, "Could not update MAC address information");
1728 			return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
1729 				"Failed to update MAC address.");
1730 		}
1731 		wpa_s->conf->p2p_device_random_mac_addr = 0;
1732 		wpa_s->conf->p2p_interface_random_mac_addr = 0;
1733 	}
1734 
1735 	// update internal data to send out correct device address in action frame.
1736 	os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
1737 	os_memcpy(wpa_s->global->p2p->cfg->dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
1738 
1739 	return ndk::ScopedAStatus::ok();
1740 }
1741 
setEdmgInternal(bool enable)1742 ndk::ScopedAStatus P2pIface::setEdmgInternal(bool enable)
1743 {
1744 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1745 	wpa_printf(MSG_DEBUG, "set p2p_go_edmg to %d", enable);
1746 	wpa_s->conf->p2p_go_edmg = enable ? 1 : 0;
1747 	wpa_s->p2p_go_edmg = enable ? 1 : 0;
1748 	return ndk::ScopedAStatus::ok();
1749 }
1750 
getEdmgInternal()1751 std::pair<bool, ndk::ScopedAStatus> P2pIface::getEdmgInternal()
1752 {
1753 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1754 	return {(wpa_s->p2p_go_edmg == 1), ndk::ScopedAStatus::ok()};
1755 }
1756 
setWfdR2DeviceInfoInternal(const std::vector<uint8_t> & info)1757 ndk::ScopedAStatus P2pIface::setWfdR2DeviceInfoInternal(
1758 	const std::vector<uint8_t>& info)
1759 {
1760 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1761 	uint32_t wfd_r2_device_info_hex_len = info.size() * 2 + 1;
1762 	std::vector<char> wfd_r2_device_info_hex(wfd_r2_device_info_hex_len);
1763 	wpa_snprintf_hex(
1764 		wfd_r2_device_info_hex.data(), wfd_r2_device_info_hex.size(),
1765 		info.data(),info.size());
1766 	std::string wfd_r2_device_info_set_cmd_str =
1767 		 std::to_string(kWfdR2DeviceInfoSubelemId) + " " +
1768 		 wfd_r2_device_info_hex.data();
1769 	std::vector<char> wfd_r2_device_info_set_cmd(
1770 		 wfd_r2_device_info_set_cmd_str.c_str(),
1771 		 wfd_r2_device_info_set_cmd_str.c_str() +
1772 		 wfd_r2_device_info_set_cmd_str.size() + 1);
1773 	if (wifi_display_subelem_set(
1774 		wpa_s->global, wfd_r2_device_info_set_cmd.data())) {
1775 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1776 	}
1777 	return ndk::ScopedAStatus::ok();
1778 }
1779 
removeClientInternal(const std::vector<uint8_t> & peer_address,bool isLegacyClient)1780 ndk::ScopedAStatus P2pIface::removeClientInternal(
1781     const std::vector<uint8_t>& peer_address, bool isLegacyClient)
1782 {
1783 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1784 	if (peer_address.size() != ETH_ALEN) {
1785 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1786 	}
1787 	wpas_p2p_remove_client(wpa_s, peer_address.data(), isLegacyClient? 1 : 0);
1788 	return ndk::ScopedAStatus::ok();
1789 }
1790 
findOnSocialChannelsInternal(uint32_t timeout_in_sec)1791 ndk::ScopedAStatus P2pIface::findOnSocialChannelsInternal(uint32_t timeout_in_sec)
1792 {
1793 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1794 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1795 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
1796 	}
1797 	uint32_t search_delay = wpas_p2p_search_delay(wpa_s);
1798 	if (wpas_p2p_find(
1799 		wpa_s, timeout_in_sec, P2P_FIND_ONLY_SOCIAL, 0, nullptr,
1800 		nullptr, search_delay, 0, nullptr, 0, is6GhzAllowed(wpa_s))) {
1801 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1802 	}
1803 	return ndk::ScopedAStatus::ok();
1804 }
1805 
findOnSpecificFrequencyInternal(uint32_t freq,uint32_t timeout_in_sec)1806 ndk::ScopedAStatus P2pIface::findOnSpecificFrequencyInternal(
1807 	uint32_t freq, uint32_t timeout_in_sec)
1808 {
1809 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1810 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1811 		return createStatus(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
1812 	}
1813 	uint32_t search_delay = wpas_p2p_search_delay(wpa_s);
1814 	if (wpas_p2p_find(
1815 		wpa_s, timeout_in_sec, P2P_FIND_START_WITH_FULL, 0, nullptr,
1816 		nullptr, search_delay, 0, nullptr, freq, is6GhzAllowed(wpa_s))) {
1817 		return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1818 	}
1819 	return ndk::ScopedAStatus::ok();
1820 }
1821 
setVendorElementsInternal(P2pFrameTypeMask frameTypeMask,const std::vector<uint8_t> & vendorElemBytes)1822 ndk::ScopedAStatus P2pIface::setVendorElementsInternal(
1823 	P2pFrameTypeMask frameTypeMask,
1824 	const std::vector<uint8_t>& vendorElemBytes)
1825 {
1826 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1827 	for (int i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
1828 		uint32_t bit = convertWpaP2pFrameTypeToHalP2pFrameTypeBit(i);
1829 		if (0 == bit) continue;
1830 
1831 		if (static_cast<uint32_t>(frameTypeMask) & bit) {
1832 			updateP2pVendorElem(wpa_s, (enum wpa_vendor_elem_frame) i, vendorElemBytes);
1833 		}
1834 	}
1835 	return ndk::ScopedAStatus::ok();
1836 }
1837 
configureEapolIpAddressAllocationParamsInternal(uint32_t ipAddressGo,uint32_t ipAddressMask,uint32_t ipAddressStart,uint32_t ipAddressEnd)1838 ndk::ScopedAStatus P2pIface::configureEapolIpAddressAllocationParamsInternal(
1839 	uint32_t ipAddressGo, uint32_t ipAddressMask,
1840 	uint32_t ipAddressStart, uint32_t ipAddressEnd)
1841 {
1842 	wpa_printf(MSG_DEBUG, "P2P: Configure IP addresses for IP allocation in EAPOL"
1843 		   " ipAddressGo: 0x%x mask: 0x%x Range - Start: 0x%x End: 0x%x",
1844 			ipAddressGo, ipAddressMask, ipAddressStart, ipAddressEnd);
1845 	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
1846 
1847 	os_memcpy(wpa_s->conf->ip_addr_go, &ipAddressGo, 4);
1848 	os_memcpy(wpa_s->conf->ip_addr_mask, &ipAddressMask, 4);
1849 	os_memcpy(wpa_s->conf->ip_addr_start, &ipAddressStart, 4);
1850 	os_memcpy(wpa_s->conf->ip_addr_end, &ipAddressEnd, 4);
1851 
1852 	return ndk::ScopedAStatus::ok();
1853 }
1854 
1855 /**
1856  * Retrieve the underlying |wpa_supplicant| struct
1857  * pointer for this iface.
1858  * If the underlying iface is removed, then all RPC method calls on this object
1859  * will return failure.
1860  */
retrieveIfacePtr()1861 wpa_supplicant* P2pIface::retrieveIfacePtr()
1862 {
1863 	return wpa_supplicant_get_iface(wpa_global_, ifname_.c_str());
1864 }
1865 
1866 /**
1867  * Retrieve the underlying |wpa_supplicant| struct
1868  * pointer for this group iface.
1869  */
retrieveGroupIfacePtr(const std::string & group_ifname)1870 wpa_supplicant* P2pIface::retrieveGroupIfacePtr(const std::string& group_ifname)
1871 {
1872 	return wpa_supplicant_get_iface(wpa_global_, group_ifname.c_str());
1873 }
1874 
1875 }  // namespace supplicant
1876 }  // namespace wifi
1877 }  // namespace hardware
1878 }  // namespace android
1879 }  // namespace aidl
1880