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