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