1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "wifi_p2p_msg.h"
17
18 namespace OHOS {
19 namespace Wifi {
SetWfdEnabled(bool value)20 void WifiP2pWfdInfo::SetWfdEnabled(bool value)
21 {
22 wfdEnabled = value;
23 }
24
GetWfdEnabled() const25 bool WifiP2pWfdInfo::GetWfdEnabled() const
26 {
27 return wfdEnabled;
28 }
29
SetDeviceInfo(int info)30 void WifiP2pWfdInfo::SetDeviceInfo(int info)
31 {
32 deviceInfo = info;
33 }
34
GetDeviceInfo() const35 int WifiP2pWfdInfo::GetDeviceInfo() const
36 {
37 return deviceInfo;
38 }
39
SetCtrlPort(int port)40 void WifiP2pWfdInfo::SetCtrlPort(int port)
41 {
42 ctrlPort = port;
43 }
44
GetCtrlPort() const45 int WifiP2pWfdInfo::GetCtrlPort() const
46 {
47 return ctrlPort;
48 }
49
SetMaxThroughput(int throughput)50 void WifiP2pWfdInfo::SetMaxThroughput(int throughput)
51 {
52 maxThroughput = throughput;
53 }
54
GetMaxThroughput() const55 int WifiP2pWfdInfo::GetMaxThroughput() const
56 {
57 return maxThroughput;
58 }
59
isSessionAvailable()60 bool WifiP2pWfdInfo::isSessionAvailable()
61 {
62 return (static_cast<size_t>(deviceInfo) & static_cast<size_t>(P2pDeviceType::SESSION_AVAILABLE)) != 0;
63 }
64
setSessionAvailable(bool enabled)65 void WifiP2pWfdInfo::setSessionAvailable(bool enabled)
66 {
67 if (enabled) {
68 deviceInfo |= static_cast<int>(P2pDeviceType::SESSION_AVAILABLE_BIT1);
69 deviceInfo &= ~(static_cast<int>(P2pDeviceType::SESSION_AVAILABLE_BIT2));
70 } else {
71 deviceInfo &= ~(static_cast<int>(P2pDeviceType::SESSION_AVAILABLE));
72 }
73 }
74
GetDeviceInfoElement(std::string & subelement)75 void WifiP2pWfdInfo::GetDeviceInfoElement(std::string &subelement)
76 {
77 char buf[32];
78 subelement = DeviceInfoSubelemLenHex;
79 if (snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, "%04x%04x%04x", deviceInfo, ctrlPort, maxThroughput) < 0) {
80 subelement.clear();
81 return;
82 }
83 subelement.append(buf);
84 }
85
SetDeviceName(const std::string & setDeviceName)86 void WifiP2pDevice::SetDeviceName(const std::string &setDeviceName)
87 {
88 deviceName = setDeviceName;
89 }
90
GetDeviceName() const91 const std::string &WifiP2pDevice::GetDeviceName() const
92 {
93 return deviceName;
94 }
95
SetNetworkName(const std::string & name)96 void WifiP2pDevice::SetNetworkName(const std::string &name)
97 {
98 networkName = name;
99 }
100
GetNetworkName() const101 const std::string &WifiP2pDevice::GetNetworkName() const
102 {
103 return networkName;
104 }
105
SetDeviceAddress(const std::string & deviceAddress)106 void WifiP2pDevice::SetDeviceAddress(const std::string &deviceAddress)
107 {
108 mDeviceAddress = deviceAddress;
109 }
110
GetDeviceAddress() const111 const std::string &WifiP2pDevice::GetDeviceAddress() const
112 {
113 return mDeviceAddress;
114 }
115
SetRandomDeviceAddress(const std::string & deviceAddress)116 void WifiP2pDevice::SetRandomDeviceAddress(const std::string &deviceAddress)
117 {
118 mRandomDeviceAddress = deviceAddress;
119 }
120
GetRandomDeviceAddress() const121 const std::string &WifiP2pDevice::GetRandomDeviceAddress() const
122 {
123 return mRandomDeviceAddress;
124 }
125
SetGroupAddress(const std::string & groupAddress)126 void WifiP2pDevice::SetGroupAddress(const std::string &groupAddress)
127 {
128 mGroupAddress = groupAddress;
129 }
130
GetGroupAddress() const131 const std::string &WifiP2pDevice::GetGroupAddress() const
132 {
133 return mGroupAddress;
134 }
135
AddClientInfoList(const std::string & mac,const std::string & ip,const std::string & host)136 void WifiP2pLinkedInfo::AddClientInfoList(const std::string &mac, const std::string &ip, const std::string &host)
137 {
138 GcInfo gc_info;
139 gc_info.mac = mac;
140 gc_info.ip = ip;
141 gc_info.host = host;
142 gc_info_list.push_back(gc_info);
143 }
144
RemoveClientInfo(std::string mac)145 void WifiP2pLinkedInfo::RemoveClientInfo(std::string mac)
146 {
147 for (auto iter = gc_info_list.begin(); iter !=gc_info_list.end(); iter++) {
148 if (mac == iter->mac) {
149 iter = gc_info_list.erase(iter);
150 return;
151 }
152 }
153 }
154
ClearClientInfo()155 void WifiP2pLinkedInfo::ClearClientInfo()
156 {
157 gc_info_list.clear();
158 }
159
GetClientInfoList() const160 const std::vector<GcInfo> &WifiP2pLinkedInfo::GetClientInfoList() const
161 {
162 return gc_info_list;
163 }
164
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)165 void WifiP2pDevice::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
166 {
167 primaryDeviceType = setPrimaryDeviceType;
168 }
169
SetDeviceAddressType(int devAddressType)170 void WifiP2pDevice::SetDeviceAddressType(int devAddressType)
171 {
172 deviceAddressType = devAddressType;
173 }
174
GetDeviceAddressType() const175 int WifiP2pDevice::GetDeviceAddressType() const
176 {
177 return deviceAddressType;
178 }
179
GetPrimaryDeviceType() const180 const std::string &WifiP2pDevice::GetPrimaryDeviceType() const
181 {
182 return primaryDeviceType;
183 }
184
SetSecondaryDeviceType(const std::string & deviceType)185 void WifiP2pDevice::SetSecondaryDeviceType(const std::string &deviceType)
186 {
187 secondaryDeviceType = deviceType;
188 }
189
GetSecondaryDeviceType() const190 const std::string &WifiP2pDevice::GetSecondaryDeviceType() const
191 {
192 return secondaryDeviceType;
193 }
194
SetP2pDeviceStatus(P2pDeviceStatus setStatus)195 void WifiP2pDevice::SetP2pDeviceStatus(P2pDeviceStatus setStatus)
196 {
197 status = setStatus;
198 }
199
GetP2pDeviceStatus() const200 P2pDeviceStatus WifiP2pDevice::GetP2pDeviceStatus() const
201 {
202 return status;
203 }
204
SetWfdInfo(const WifiP2pWfdInfo & info)205 void WifiP2pDevice::SetWfdInfo(const WifiP2pWfdInfo &info)
206 {
207 wfdInfo = info;
208 }
209
GetWfdInfo() const210 const WifiP2pWfdInfo &WifiP2pDevice::GetWfdInfo() const
211 {
212 return wfdInfo;
213 }
214
SetWpsConfigMethod(unsigned int wpsConfigMethod)215 void WifiP2pDevice::SetWpsConfigMethod(unsigned int wpsConfigMethod)
216 {
217 supportWpsConfigMethods = wpsConfigMethod;
218 }
219
GetWpsConfigMethod() const220 unsigned int WifiP2pDevice::GetWpsConfigMethod() const
221 {
222 return supportWpsConfigMethods;
223 }
224
SetDeviceCapabilitys(int capabilitys)225 void WifiP2pDevice::SetDeviceCapabilitys(int capabilitys)
226 {
227 deviceCapabilitys = capabilitys;
228 }
229
GetDeviceCapabilitys() const230 int WifiP2pDevice::GetDeviceCapabilitys() const
231 {
232 return deviceCapabilitys;
233 }
234
SetGroupCapabilitys(int capabilitys)235 void WifiP2pDevice::SetGroupCapabilitys(int capabilitys)
236 {
237 groupCapabilitys = capabilitys;
238 }
239
GetGroupCapabilitys() const240 int WifiP2pDevice::GetGroupCapabilitys() const
241 {
242 return groupCapabilitys;
243 }
244
IsGroupOwner() const245 bool WifiP2pDevice::IsGroupOwner() const
246 {
247 return (static_cast<size_t>(groupCapabilitys) & static_cast<size_t>(P2pGroupCapability::PGC_GROUP_OWNER));
248 }
249
IsGroupLimit() const250 bool WifiP2pDevice::IsGroupLimit() const
251 {
252 return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_LIMIT));
253 }
254
IsDeviceLimit() const255 bool WifiP2pDevice::IsDeviceLimit() const
256 {
257 return (static_cast<size_t>(deviceCapabilitys) & static_cast<size_t>(P2pDeviceCapability::PDC_DEVICE_LIMIT));
258 }
259
Isinviteable() const260 bool WifiP2pDevice::Isinviteable() const
261 {
262 return (static_cast<size_t>(deviceCapabilitys) &
263 static_cast<size_t>(P2pDeviceCapability::PDC_INVITATION_PROCEDURE));
264 }
265
IsValid() const266 bool WifiP2pDevice::IsValid() const
267 {
268 if (mDeviceAddress.empty()) {
269 return false;
270 }
271 return true;
272 }
273
operator ==(const WifiP2pDevice & cmp) const274 bool WifiP2pDevice::operator==(const WifiP2pDevice &cmp) const
275 {
276 return mDeviceAddress == cmp.GetDeviceAddress();
277 }
278
operator !=(const WifiP2pDevice & cmp) const279 bool WifiP2pDevice::operator!=(const WifiP2pDevice &cmp) const
280 {
281 return !operator==(cmp);
282 }
283
WpsPbcSupported() const284 bool WifiP2pDevice::WpsPbcSupported() const
285 {
286 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_PUSHBUTTON)) != 0;
287 }
288
WpsDisplaySupported() const289 bool WifiP2pDevice::WpsDisplaySupported() const
290 {
291 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_DISPLAY)) != 0;
292 }
293
WpKeypadSupported() const294 bool WifiP2pDevice::WpKeypadSupported() const
295 {
296 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_KEYPAD)) != 0;
297 }
298
SetChrErrCode(P2pChrEvent errCode)299 void WifiP2pDevice::SetChrErrCode(P2pChrEvent errCode)
300 {
301 chrErrCode = errCode;
302 }
303
GetChrErrCode() const304 P2pChrEvent WifiP2pDevice::GetChrErrCode() const
305 {
306 return chrErrCode;
307 }
308
operator ==(const WifiP2pGroupInfo & group) const309 bool WifiP2pGroupInfo::operator==(const WifiP2pGroupInfo &group) const
310 {
311 return networkId == group.GetNetworkId();
312 }
313
operator !=(const WifiP2pGroupInfo & group) const314 bool WifiP2pGroupInfo::operator!=(const WifiP2pGroupInfo &group) const
315 {
316 return !operator==(group);
317 }
318
SetIsGroupOwner(bool isGroupOwner)319 void WifiP2pGroupInfo::SetIsGroupOwner(bool isGroupOwner)
320 {
321 isP2pGroupOwner = isGroupOwner;
322 }
323
IsGroupOwner() const324 bool WifiP2pGroupInfo::IsGroupOwner() const
325 {
326 return isP2pGroupOwner;
327 }
328
SetOwner(const WifiP2pDevice & setOwner)329 void WifiP2pGroupInfo::SetOwner(const WifiP2pDevice &setOwner)
330 {
331 owner = setOwner;
332 }
333
GetOwner() const334 const WifiP2pDevice &WifiP2pGroupInfo::GetOwner() const
335 {
336 return owner;
337 }
338
SetPassphrase(const std::string & setPassphrase)339 void WifiP2pGroupInfo::SetPassphrase(const std::string &setPassphrase)
340 {
341 passphrase = setPassphrase;
342 }
343
GetPassphrase() const344 const std::string &WifiP2pGroupInfo::GetPassphrase() const
345 {
346 return passphrase;
347 }
348
SetInterface(const std::string & setInterface)349 void WifiP2pGroupInfo::SetInterface(const std::string &setInterface)
350 {
351 interface = setInterface;
352 }
353
GetInterface() const354 const std::string &WifiP2pGroupInfo::GetInterface() const
355 {
356 return interface;
357 }
358
SetGroupName(const std::string & newGroupName)359 void WifiP2pGroupInfo::SetGroupName(const std::string &newGroupName)
360 {
361 groupName = newGroupName;
362 }
363
GetGroupName() const364 const std::string &WifiP2pGroupInfo::GetGroupName() const
365 {
366 return groupName;
367 }
368
SetFrequency(int setFrequency)369 void WifiP2pGroupInfo::SetFrequency(int setFrequency)
370 {
371 frequency = setFrequency;
372 }
373
GetFrequency() const374 int WifiP2pGroupInfo::GetFrequency() const
375 {
376 return frequency;
377 }
378
SetIsPersistent(bool isPersistent)379 void WifiP2pGroupInfo::SetIsPersistent(bool isPersistent)
380 {
381 isP2pPersistent = isPersistent;
382 }
383
IsPersistent() const384 bool WifiP2pGroupInfo::IsPersistent() const
385 {
386 return isP2pPersistent;
387 }
388
SetP2pGroupStatus(P2pGroupStatus newGroupStatus)389 void WifiP2pGroupInfo::SetP2pGroupStatus(P2pGroupStatus newGroupStatus)
390 {
391 groupStatus = newGroupStatus;
392 }
393
GetP2pGroupStatus() const394 P2pGroupStatus WifiP2pGroupInfo::GetP2pGroupStatus() const
395 {
396 return groupStatus;
397 }
398
SetNetworkId(int nwId)399 void WifiP2pGroupInfo::SetNetworkId(int nwId)
400 {
401 networkId = nwId;
402 }
403
GetNetworkId() const404 const int &WifiP2pGroupInfo::GetNetworkId() const
405 {
406 return networkId;
407 }
408
SetGoIpAddress(const std::string & ipAddr)409 void WifiP2pGroupInfo::SetGoIpAddress(const std::string &ipAddr)
410 {
411 goIpAddress = ipAddr;
412 }
413
GetGoIpAddress() const414 const std::string &WifiP2pGroupInfo::GetGoIpAddress() const
415 {
416 return goIpAddress;
417 }
418
SetGcIpAddress(const std::string & ipAddr)419 void WifiP2pGroupInfo::SetGcIpAddress(const std::string &ipAddr)
420 {
421 gcIpAddress = ipAddr;
422 }
423
GetGcIpAddress() const424 const std::string &WifiP2pGroupInfo::GetGcIpAddress() const
425 {
426 return gcIpAddress;
427 }
428
AddClientDevice(const WifiP2pDevice & clientDevice)429 void WifiP2pGroupInfo::AddClientDevice(const WifiP2pDevice &clientDevice)
430 {
431 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
432 if (*it == clientDevice) {
433 *it = clientDevice;
434 return;
435 }
436 }
437 clientDevices.push_back(clientDevice);
438 return;
439 }
440
AddPersistentDevice(const WifiP2pDevice & clientDevice)441 void WifiP2pGroupInfo::AddPersistentDevice(const WifiP2pDevice &clientDevice)
442 {
443 for (auto it = persistentClients.begin(); it != persistentClients.end(); ++it) {
444 if (it->GetDeviceAddress() == clientDevice.GetDeviceAddress()) {
445 *it = clientDevice;
446 return;
447 }
448 }
449 persistentClients.push_back(clientDevice);
450 return;
451 }
452
RemoveClientDevice(const WifiP2pDevice & clientDevice)453 void WifiP2pGroupInfo::RemoveClientDevice(const WifiP2pDevice &clientDevice)
454 {
455 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
456 if (*it == clientDevice) {
457 clientDevices.erase(it);
458 return;
459 }
460 }
461 return;
462 }
463
RemovePersistentDevice(const WifiP2pDevice & clientDevice)464 void WifiP2pGroupInfo::RemovePersistentDevice(const WifiP2pDevice &clientDevice)
465 {
466 for (auto it = persistentClients.begin(); it != persistentClients.end(); ++it) {
467 if (it->GetDeviceAddress() == clientDevice.GetDeviceAddress()) {
468 persistentClients.erase(it);
469 return;
470 }
471 }
472 return;
473 }
474
IsContainsDevice(const WifiP2pDevice & clientDevice) const475 bool WifiP2pGroupInfo::IsContainsDevice(const WifiP2pDevice &clientDevice) const
476 {
477 if (clientDevice == owner) {
478 return true;
479 }
480 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
481 if (*it == clientDevice) {
482 return true;
483 }
484 }
485 return false;
486 }
487
IsContainsPersistentDevice(const WifiP2pDevice & clientDevice) const488 bool WifiP2pGroupInfo::IsContainsPersistentDevice(const WifiP2pDevice &clientDevice) const
489 {
490 for (auto it = persistentClients.begin(); it != persistentClients.end(); ++it) {
491 if (it->GetDeviceAddress() == clientDevice.GetDeviceAddress()) {
492 return true;
493 }
494 }
495 return false;
496 }
497
IsClientDevicesEmpty() const498 bool WifiP2pGroupInfo::IsClientDevicesEmpty() const
499 {
500 return clientDevices.empty();
501 }
502
IsExplicitGroup(void) const503 bool WifiP2pGroupInfo::IsExplicitGroup(void) const
504 {
505 return explicitGroup;
506 }
507
SetExplicitGroup(bool isExplicit)508 void WifiP2pGroupInfo::SetExplicitGroup(bool isExplicit)
509 {
510 explicitGroup = isExplicit;
511 }
512
GetClientDevices() const513 const std::vector<WifiP2pDevice> &WifiP2pGroupInfo::GetClientDevices() const
514 {
515 return clientDevices;
516 }
517
GetPersistentDevices() const518 const std::vector<WifiP2pDevice> &WifiP2pGroupInfo::GetPersistentDevices() const
519 {
520 return persistentClients;
521 }
522
SetClientDevices(const std::vector<WifiP2pDevice> & devices)523 void WifiP2pGroupInfo::SetClientDevices(const std::vector<WifiP2pDevice> &devices)
524 {
525 clientDevices = devices;
526 }
527
SetClientPersistentDevices(const std::vector<WifiP2pDevice> & devices)528 void WifiP2pGroupInfo::SetClientPersistentDevices(const std::vector<WifiP2pDevice> &devices)
529 {
530 persistentClients = devices;
531 }
532
ClearClientDevices()533 void WifiP2pGroupInfo::ClearClientDevices()
534 {
535 clientDevices.clear();
536 persistentClients.clear();
537 }
538
SetCreatorUid(int uid)539 void WifiP2pGroupInfo::SetCreatorUid(int uid)
540 {
541 creatorUid = uid;
542 }
543
GetCreatorUid()544 int WifiP2pGroupInfo::GetCreatorUid()
545 {
546 return creatorUid;
547 }
548
SetPersistentFlag(bool flag)549 void WifiP2pGroupInfo::SetPersistentFlag(bool flag)
550 {
551 isOldPersistenGroup = flag;
552 }
553
GetPersistentFlag(void)554 bool WifiP2pGroupInfo::GetPersistentFlag(void)
555 {
556 return isOldPersistenGroup;
557 }
558
SetWpsMethod(WpsMethod wpsMethod)559 void WpsInfo::SetWpsMethod(WpsMethod wpsMethod)
560 {
561 mWpsMethod = wpsMethod;
562 }
563
GetWpsMethod() const564 WpsMethod WpsInfo::GetWpsMethod() const
565 {
566 return mWpsMethod;
567 }
568
SetBssid(const std::string & setBssid)569 void WpsInfo::SetBssid(const std::string &setBssid)
570 {
571 bssid = setBssid;
572 }
573
GetBssid() const574 const std::string &WpsInfo::GetBssid() const
575 {
576 return bssid;
577 }
578
SetPin(const std::string & setPin)579 void WpsInfo::SetPin(const std::string &setPin)
580 {
581 pin = setPin;
582 }
583
GetPin() const584 const std::string &WpsInfo::GetPin() const
585 {
586 return pin;
587 }
588
SetDeviceAddress(const std::string & deviceAddress)589 void WifiP2pConfig::SetDeviceAddress(const std::string &deviceAddress)
590 {
591 mDeviceAddress = deviceAddress;
592 }
593
GetDeviceAddress() const594 const std::string &WifiP2pConfig::GetDeviceAddress() const
595 {
596 return mDeviceAddress;
597 }
598
SetDeviceAddressType(int devAddressType)599 void WifiP2pConfig::SetDeviceAddressType(int devAddressType)
600 {
601 deviceAddressType = devAddressType;
602 }
603
GetDeviceAddressType() const604 int WifiP2pConfig::GetDeviceAddressType() const
605 {
606 return deviceAddressType;
607 }
608
SetGoBand(GroupOwnerBand setGoBand)609 void WifiP2pConfig::SetGoBand(GroupOwnerBand setGoBand)
610 {
611 goBand = setGoBand;
612 }
613
GetGoBand() const614 GroupOwnerBand WifiP2pConfig::GetGoBand() const
615 {
616 return goBand;
617 }
618
SetNetId(int setNetId)619 void WifiP2pConfig::SetNetId(int setNetId)
620 {
621 netId = setNetId;
622 }
623
GetNetId() const624 int WifiP2pConfig::GetNetId() const
625 {
626 return netId;
627 }
628
SetPassphrase(const std::string & newPassphrase)629 void WifiP2pConfig::SetPassphrase(const std::string &newPassphrase)
630 {
631 passphrase = newPassphrase;
632 }
633
GetPassphrase() const634 const std::string &WifiP2pConfig::GetPassphrase() const
635 {
636 return passphrase;
637 }
638
SetGroupOwnerIntent(int intent)639 void WifiP2pConfig::SetGroupOwnerIntent(int intent)
640 {
641 groupOwnerIntent = intent;
642 }
643
GetGroupOwnerIntent() const644 int WifiP2pConfig::GetGroupOwnerIntent() const
645 {
646 return groupOwnerIntent;
647 }
648
SetGroupName(const std::string & setGroupName)649 void WifiP2pConfig::SetGroupName(const std::string &setGroupName)
650 {
651 groupName = setGroupName;
652 }
653
GetGroupName() const654 const std::string &WifiP2pConfig::GetGroupName() const
655 {
656 return groupName;
657 }
658
SetConnectState(P2pConnectedState setConnectState)659 void WifiP2pLinkedInfo::SetConnectState(P2pConnectedState setConnectState)
660 {
661 connectState = setConnectState;
662 }
663
GetConnectState() const664 P2pConnectedState WifiP2pLinkedInfo::GetConnectState() const
665 {
666 return connectState;
667 }
668
SetIsGroupOwner(bool isGroupOwner)669 void WifiP2pLinkedInfo::SetIsGroupOwner(bool isGroupOwner)
670 {
671 isP2pGroupOwner = isGroupOwner;
672 }
673
IsGroupOwner() const674 const bool &WifiP2pLinkedInfo::IsGroupOwner() const
675 {
676 return isP2pGroupOwner;
677 }
678
SetIsGroupOwnerAddress(const std::string & setGroupOwnerAddress)679 void WifiP2pLinkedInfo::SetIsGroupOwnerAddress(const std::string &setGroupOwnerAddress)
680 {
681 groupOwnerAddress = setGroupOwnerAddress;
682 }
683
GetGroupOwnerAddress() const684 const std::string &WifiP2pLinkedInfo::GetGroupOwnerAddress() const
685 {
686 return groupOwnerAddress;
687 }
688
SetProtocolType(P2pServicerProtocolType serviceProtocolType)689 void WifiP2pServiceRequest::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
690 {
691 mProtocolType = serviceProtocolType;
692 }
693
GetProtocolType() const694 P2pServicerProtocolType WifiP2pServiceRequest::GetProtocolType() const
695 {
696 return mProtocolType;
697 }
698
SetTransactionId(unsigned char transactionId)699 void WifiP2pServiceRequest::SetTransactionId(unsigned char transactionId)
700 {
701 mTransactionId = transactionId;
702 }
703
GetTransactionId() const704 int WifiP2pServiceRequest::GetTransactionId() const
705 {
706 return mTransactionId;
707 }
708
SetQuery(const std::vector<unsigned char> & query)709 void WifiP2pServiceRequest::SetQuery(const std::vector<unsigned char> &query)
710 {
711 mQuery = query;
712 }
713
GetQuery() const714 const std::vector<unsigned char> &WifiP2pServiceRequest::GetQuery() const
715 {
716 return mQuery;
717 }
718
GetTlv() const719 std::vector<unsigned char> WifiP2pServiceRequest::GetTlv() const
720 {
721 std::vector<unsigned char> ret;
722
723 unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + mQuery.size();
724 if (length > 0xff) {
725 unsigned char buf1 = length & 0x00ff;
726 unsigned char buf2 = length >> CHAR_BIT;
727 ret.push_back(buf1);
728 ret.push_back(buf2);
729 } else {
730 ret.push_back(static_cast<unsigned char>(length));
731 ret.push_back(0x00);
732 }
733 ret.push_back(static_cast<unsigned char>(mProtocolType));
734 ret.push_back(mTransactionId);
735 if (!mQuery.empty()) {
736 for (auto it = mQuery.begin(); it != mQuery.end(); ++it) {
737 ret.push_back(*it);
738 }
739 }
740
741 return ret;
742 }
743
operator ==(const WifiP2pServiceRequest & cmp) const744 bool WifiP2pServiceRequest::operator==(const WifiP2pServiceRequest &cmp) const
745 {
746 return mProtocolType == cmp.GetProtocolType() && mQuery == cmp.GetQuery();
747 }
748
SetProtocolType(P2pServicerProtocolType serviceProtocolType)749 void WifiP2pServiceResponse::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
750 {
751 mProtocolType = serviceProtocolType;
752 }
753
GetProtocolType() const754 P2pServicerProtocolType WifiP2pServiceResponse::GetProtocolType() const
755 {
756 return mProtocolType;
757 }
758
SetTransactionId(unsigned char transactionId)759 void WifiP2pServiceResponse::SetTransactionId(unsigned char transactionId)
760 {
761 mTransactionId = transactionId;
762 }
763
GetTransactionId() const764 unsigned char WifiP2pServiceResponse::GetTransactionId() const
765 {
766 return mTransactionId;
767 }
768
SetServiceStatus(P2pServiceStatus serviceStatus)769 void WifiP2pServiceResponse::SetServiceStatus(P2pServiceStatus serviceStatus)
770 {
771 mServiceStatus = serviceStatus;
772 }
773
GetServiceStatus() const774 P2pServiceStatus WifiP2pServiceResponse::GetServiceStatus() const
775 {
776 return mServiceStatus;
777 }
778
SetServiceName(const std::string & name)779 void WifiP2pServiceResponse::SetServiceName(const std::string &name)
780 {
781 mSvrName = name;
782 }
783
GetServiceName() const784 const std::string &WifiP2pServiceResponse::GetServiceName() const
785 {
786 return mSvrName;
787 }
788
SetData(const std::vector<unsigned char> & data)789 void WifiP2pServiceResponse::SetData(const std::vector<unsigned char> &data)
790 {
791 responseData = data;
792 }
793
GetData() const794 const std::vector<unsigned char> &WifiP2pServiceResponse::GetData() const
795 {
796 return responseData;
797 }
798
GetTlv() const799 std::vector<unsigned char> WifiP2pServiceResponse::GetTlv() const
800 {
801 std::vector<unsigned char> ret;
802 unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + SERVICE_STATUS_SIZE + responseData.size();
803 if (length > 0xff) {
804 unsigned char buf1 = length & 0x00ff;
805 unsigned char buf2 = length >> CHAR_BIT;
806 ret.push_back(buf1);
807 ret.push_back(buf2);
808 } else {
809 ret.push_back(static_cast<unsigned char>(length));
810 ret.push_back(0x00);
811 }
812 ret.push_back(static_cast<unsigned char>(mProtocolType));
813 ret.push_back(mTransactionId);
814 ret.push_back(static_cast<unsigned char>(mServiceStatus));
815 if (!responseData.empty()) {
816 for (auto it = responseData.begin(); it != responseData.end(); ++it) {
817 ret.push_back(*it);
818 }
819 }
820 return ret;
821 }
822
operator ==(const WifiP2pServiceResponse & cmp) const823 bool WifiP2pServiceResponse::operator==(const WifiP2pServiceResponse &cmp) const
824 {
825 return mProtocolType == cmp.GetProtocolType() && mServiceStatus == cmp.GetServiceStatus() &&
826 responseData == cmp.GetData();
827 }
828
SetServiceName(const std::string & name)829 void WifiP2pServiceInfo::SetServiceName(const std::string &name)
830 {
831 serviceName = name;
832 }
833
GetServiceName() const834 const std::string &WifiP2pServiceInfo::GetServiceName() const
835 {
836 return serviceName;
837 }
838
SetDeviceAddress(const std::string & deviceAddress)839 void WifiP2pServiceInfo::SetDeviceAddress(const std::string &deviceAddress)
840 {
841 mDeviceAddress = deviceAddress;
842 }
843
GetDeviceAddress() const844 const std::string &WifiP2pServiceInfo::GetDeviceAddress() const
845 {
846 return mDeviceAddress;
847 }
848
SetServicerProtocolType(P2pServicerProtocolType type)849 void WifiP2pServiceInfo::SetServicerProtocolType(P2pServicerProtocolType type)
850 {
851 mProtocolType = type;
852 }
853
GetServicerProtocolType() const854 P2pServicerProtocolType WifiP2pServiceInfo::GetServicerProtocolType() const
855 {
856 return mProtocolType;
857 }
858
SetQueryList(const std::vector<std::string> & queryList)859 void WifiP2pServiceInfo::SetQueryList(const std::vector<std::string> &queryList)
860 {
861 mQueryList = queryList;
862 }
863
GetQueryList() const864 const std::vector<std::string> &WifiP2pServiceInfo::GetQueryList() const
865 {
866 return mQueryList;
867 }
868
operator ==(const WifiP2pServiceInfo & cmp) const869 bool WifiP2pServiceInfo::operator==(const WifiP2pServiceInfo &cmp) const
870 {
871 return cmp.GetServiceName() == serviceName && cmp.GetDeviceAddress() == mDeviceAddress &&
872 cmp.GetServicerProtocolType() == mProtocolType && cmp.GetQueryList() == mQueryList;
873 }
874
875 /**
876 * @Description - For a request sent by the peer device, serviceInfo processes the query information in the request
877 * packet and returns the processing result.
878 * @param Query - the query of service request.
879 * @param data - the data of response.
880 * @return - P2pServiceStatus - result of processing.
881 */
ProcessServiceRequest(const std::vector<unsigned char> & Query,std::vector<unsigned char> & data) const882 P2pServiceStatus WifiP2pServiceInfo::ProcessServiceRequest(
883 const std::vector<unsigned char> &Query, std::vector<unsigned char> &data) const
884 {
885 data = Query;
886 data.push_back(0x00);
887 data.push_back(static_cast<unsigned char>(mProtocolType));
888 data.push_back(0x00);
889 return P2pServiceStatus::PSRS_SUCCESS;
890 }
891
892 /**
893 * @Description - Processes the data in the response returned by the peer device.
894 * @param data - the response received from the peer device.
895 */
ProcessServiceResponse(const std::vector<unsigned char> & data) const896 void WifiP2pServiceInfo::ProcessServiceResponse(const std::vector<unsigned char> &data) const
897 {
898 if (data.empty()) {
899 return;
900 }
901 }
902
Bin2HexStr(std::vector<unsigned char> data)903 std::string WifiP2pServiceInfo::Bin2HexStr(std::vector<unsigned char> data)
904 {
905 std::string dataString;
906 for (auto bufData : data) {
907 char buf[3];
908 if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
909 return "";
910 }
911 std::string aDataString = buf;
912 if (aDataString.length() == 1) {
913 dataString += std::string("0");
914 }
915 dataString += aDataString;
916 }
917 return dataString;
918 }
919
Bin2HexStr(std::string data)920 std::string WifiP2pServiceInfo::Bin2HexStr(std::string data)
921 {
922 std::string dataString;
923 for (auto bufData : data) {
924 char buf[3];
925 if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
926 return "";
927 }
928 std::string aDataString = buf;
929 if (aDataString.length() == 1) {
930 dataString += std::string("0");
931 }
932 dataString += aDataString;
933 }
934 return dataString;
935 }
936
GetRandomMacSupport() const937 bool P2pVendorConfig::GetRandomMacSupport() const
938 {
939 return randomMacSupport;
940 }
941
SetRandomMacSupport(bool support)942 void P2pVendorConfig::SetRandomMacSupport(bool support)
943 {
944 randomMacSupport = support;
945 }
946
GetIsAutoListen() const947 bool P2pVendorConfig::GetIsAutoListen() const
948 {
949 return isAutoListen;
950 }
951
SetIsAutoListen(bool autoListen)952 void P2pVendorConfig::SetIsAutoListen(bool autoListen)
953 {
954 isAutoListen = autoListen;
955 }
956
GetDeviceName() const957 const std::string &P2pVendorConfig::GetDeviceName() const
958 {
959 return deviceName;
960 }
961
SetDeviceName(const std::string & name)962 void P2pVendorConfig::SetDeviceName(const std::string &name)
963 {
964 deviceName = name;
965 }
966
GetPrimaryDeviceType() const967 const std::string &P2pVendorConfig::GetPrimaryDeviceType() const
968 {
969 return primaryDeviceType;
970 }
971
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)972 void P2pVendorConfig::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
973 {
974 primaryDeviceType = setPrimaryDeviceType;
975 }
976
GetSecondaryDeviceType() const977 const std::string &P2pVendorConfig::GetSecondaryDeviceType() const
978 {
979 return secondaryDeviceType;
980 }
981
SetSecondaryDeviceType(const std::string & setSecondaryDeviceType)982 void P2pVendorConfig::SetSecondaryDeviceType(const std::string &setSecondaryDeviceType)
983 {
984 secondaryDeviceType = setSecondaryDeviceType;
985 }
986 } // namespace Wifi
987 } // namespace OHOS
988