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 (deviceInfo & static_cast<int>(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
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)116 void WifiP2pDevice::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
117 {
118 primaryDeviceType = setPrimaryDeviceType;
119 }
120
SetDeviceAddressType(int devAddressType)121 void WifiP2pDevice::SetDeviceAddressType(int devAddressType)
122 {
123 deviceAddressType = devAddressType;
124 }
125
GetDeviceAddressType() const126 int WifiP2pDevice::GetDeviceAddressType() const
127 {
128 return deviceAddressType;
129 }
130
GetPrimaryDeviceType() const131 const std::string &WifiP2pDevice::GetPrimaryDeviceType() const
132 {
133 return primaryDeviceType;
134 }
135
SetSecondaryDeviceType(const std::string & deviceType)136 void WifiP2pDevice::SetSecondaryDeviceType(const std::string &deviceType)
137 {
138 secondaryDeviceType = deviceType;
139 }
140
GetSecondaryDeviceType() const141 const std::string &WifiP2pDevice::GetSecondaryDeviceType() const
142 {
143 return secondaryDeviceType;
144 }
145
SetP2pDeviceStatus(P2pDeviceStatus setStatus)146 void WifiP2pDevice::SetP2pDeviceStatus(P2pDeviceStatus setStatus)
147 {
148 status = setStatus;
149 }
150
GetP2pDeviceStatus() const151 P2pDeviceStatus WifiP2pDevice::GetP2pDeviceStatus() const
152 {
153 return status;
154 }
155
SetWfdInfo(const WifiP2pWfdInfo & info)156 void WifiP2pDevice::SetWfdInfo(const WifiP2pWfdInfo &info)
157 {
158 wfdInfo = info;
159 }
160
GetWfdInfo() const161 const WifiP2pWfdInfo &WifiP2pDevice::GetWfdInfo() const
162 {
163 return wfdInfo;
164 }
165
SetWpsConfigMethod(unsigned int wpsConfigMethod)166 void WifiP2pDevice::SetWpsConfigMethod(unsigned int wpsConfigMethod)
167 {
168 supportWpsConfigMethods = wpsConfigMethod;
169 }
170
GetWpsConfigMethod() const171 unsigned int WifiP2pDevice::GetWpsConfigMethod() const
172 {
173 return supportWpsConfigMethods;
174 }
175
SetDeviceCapabilitys(int capabilitys)176 void WifiP2pDevice::SetDeviceCapabilitys(int capabilitys)
177 {
178 deviceCapabilitys = capabilitys;
179 }
180
GetDeviceCapabilitys() const181 int WifiP2pDevice::GetDeviceCapabilitys() const
182 {
183 return deviceCapabilitys;
184 }
185
SetGroupCapabilitys(int capabilitys)186 void WifiP2pDevice::SetGroupCapabilitys(int capabilitys)
187 {
188 groupCapabilitys = capabilitys;
189 }
190
GetGroupCapabilitys() const191 int WifiP2pDevice::GetGroupCapabilitys() const
192 {
193 return groupCapabilitys;
194 }
195
IsGroupOwner() const196 bool WifiP2pDevice::IsGroupOwner() const
197 {
198 return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_OWNER));
199 }
200
IsGroupLimit() const201 bool WifiP2pDevice::IsGroupLimit() const
202 {
203 return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_LIMIT));
204 }
205
IsDeviceLimit() const206 bool WifiP2pDevice::IsDeviceLimit() const
207 {
208 return (deviceCapabilitys & static_cast<int>(P2pDeviceCapability::PDC_DEVICE_LIMIT));
209 }
210
Isinviteable() const211 bool WifiP2pDevice::Isinviteable() const
212 {
213 return (deviceCapabilitys & static_cast<int>(P2pDeviceCapability::PDC_INVITATION_PROCEDURE));
214 }
215
IsValid() const216 bool WifiP2pDevice::IsValid() const
217 {
218 if (mDeviceAddress.empty()) {
219 return false;
220 }
221 return true;
222 }
223
operator ==(const WifiP2pDevice & cmp) const224 bool WifiP2pDevice::operator==(const WifiP2pDevice &cmp) const
225 {
226 return mDeviceAddress == cmp.GetDeviceAddress();
227 }
228
operator !=(const WifiP2pDevice & cmp) const229 bool WifiP2pDevice::operator!=(const WifiP2pDevice &cmp) const
230 {
231 return !operator==(cmp);
232 }
233
WpsPbcSupported() const234 bool WifiP2pDevice::WpsPbcSupported() const
235 {
236 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_PUSHBUTTON)) != 0;
237 }
238
WpsDisplaySupported() const239 bool WifiP2pDevice::WpsDisplaySupported() const
240 {
241 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_DISPLAY)) != 0;
242 }
243
WpKeypadSupported() const244 bool WifiP2pDevice::WpKeypadSupported() const
245 {
246 return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_KEYPAD)) != 0;
247 }
248
operator ==(const WifiP2pGroupInfo & group) const249 bool WifiP2pGroupInfo::operator==(const WifiP2pGroupInfo &group) const
250 {
251 return networkId == group.GetNetworkId();
252 }
253
operator !=(const WifiP2pGroupInfo & group) const254 bool WifiP2pGroupInfo::operator!=(const WifiP2pGroupInfo &group) const
255 {
256 return !operator==(group);
257 }
258
SetIsGroupOwner(bool isGroupOwner)259 void WifiP2pGroupInfo::SetIsGroupOwner(bool isGroupOwner)
260 {
261 isP2pGroupOwner = isGroupOwner;
262 }
263
IsGroupOwner() const264 bool WifiP2pGroupInfo::IsGroupOwner() const
265 {
266 return isP2pGroupOwner;
267 }
268
SetOwner(const WifiP2pDevice & setOwner)269 void WifiP2pGroupInfo::SetOwner(const WifiP2pDevice &setOwner)
270 {
271 owner = setOwner;
272 }
273
GetOwner() const274 const WifiP2pDevice &WifiP2pGroupInfo::GetOwner() const
275 {
276 return owner;
277 }
278
SetPassphrase(const std::string & setPassphrase)279 void WifiP2pGroupInfo::SetPassphrase(const std::string &setPassphrase)
280 {
281 passphrase = setPassphrase;
282 }
283
GetPassphrase() const284 const std::string &WifiP2pGroupInfo::GetPassphrase() const
285 {
286 return passphrase;
287 }
288
SetInterface(const std::string & setInterface)289 void WifiP2pGroupInfo::SetInterface(const std::string &setInterface)
290 {
291 interface = setInterface;
292 }
293
GetInterface() const294 const std::string &WifiP2pGroupInfo::GetInterface() const
295 {
296 return interface;
297 }
298
SetGroupName(const std::string & newGroupName)299 void WifiP2pGroupInfo::SetGroupName(const std::string &newGroupName)
300 {
301 groupName = newGroupName;
302 }
303
GetGroupName() const304 const std::string &WifiP2pGroupInfo::GetGroupName() const
305 {
306 return groupName;
307 }
308
SetFrequency(int setFrequency)309 void WifiP2pGroupInfo::SetFrequency(int setFrequency)
310 {
311 frequency = setFrequency;
312 }
313
GetFrequency() const314 int WifiP2pGroupInfo::GetFrequency() const
315 {
316 return frequency;
317 }
318
SetIsPersistent(bool isPersistent)319 void WifiP2pGroupInfo::SetIsPersistent(bool isPersistent)
320 {
321 isP2pPersistent = isPersistent;
322 }
323
IsPersistent() const324 bool WifiP2pGroupInfo::IsPersistent() const
325 {
326 return isP2pPersistent;
327 }
328
SetP2pGroupStatus(P2pGroupStatus newGroupStatus)329 void WifiP2pGroupInfo::SetP2pGroupStatus(P2pGroupStatus newGroupStatus)
330 {
331 groupStatus = newGroupStatus;
332 }
333
GetP2pGroupStatus() const334 P2pGroupStatus WifiP2pGroupInfo::GetP2pGroupStatus() const
335 {
336 return groupStatus;
337 }
338
SetNetworkId(int nwId)339 void WifiP2pGroupInfo::SetNetworkId(int nwId)
340 {
341 networkId = nwId;
342 }
343
GetNetworkId() const344 const int &WifiP2pGroupInfo::GetNetworkId() const
345 {
346 return networkId;
347 }
348
SetGoIpAddress(const std::string & ipAddr)349 void WifiP2pGroupInfo::SetGoIpAddress(const std::string &ipAddr)
350 {
351 goIpAddress = ipAddr;
352 }
353
GetGoIpAddress() const354 const std::string &WifiP2pGroupInfo::GetGoIpAddress() const
355 {
356 return goIpAddress;
357 }
358
AddClientDevice(const WifiP2pDevice & clientDevice)359 void WifiP2pGroupInfo::AddClientDevice(const WifiP2pDevice &clientDevice)
360 {
361 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
362 if (*it == clientDevice) {
363 *it = clientDevice;
364 return;
365 }
366 }
367 clientDevices.push_back(clientDevice);
368 return;
369 }
370
RemoveClientDevice(const WifiP2pDevice & clientDevice)371 void WifiP2pGroupInfo::RemoveClientDevice(const WifiP2pDevice &clientDevice)
372 {
373 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
374 if (*it == clientDevice) {
375 clientDevices.erase(it);
376 return;
377 }
378 }
379 return;
380 }
381
IsContainsDevice(const WifiP2pDevice & clientDevice) const382 bool WifiP2pGroupInfo::IsContainsDevice(const WifiP2pDevice &clientDevice) const
383 {
384 if (clientDevice == owner) {
385 return true;
386 }
387 for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
388 if (*it == clientDevice) {
389 return true;
390 }
391 }
392 return false;
393 }
394
IsClientDevicesEmpty() const395 bool WifiP2pGroupInfo::IsClientDevicesEmpty() const
396 {
397 return clientDevices.empty();
398 }
399
IsExplicitGroup(void) const400 bool WifiP2pGroupInfo::IsExplicitGroup(void) const
401 {
402 return explicitGroup;
403 }
404
SetExplicitGroup(bool isExplicit)405 void WifiP2pGroupInfo::SetExplicitGroup(bool isExplicit)
406 {
407 explicitGroup = isExplicit;
408 }
409
GetClientDevices() const410 const std::vector<WifiP2pDevice> &WifiP2pGroupInfo::GetClientDevices() const
411 {
412 return clientDevices;
413 }
414
SetClientDevices(const std::vector<WifiP2pDevice> & devices)415 void WifiP2pGroupInfo::SetClientDevices(const std::vector<WifiP2pDevice> &devices)
416 {
417 clientDevices = devices;
418 }
419
ClearClientDevices()420 void WifiP2pGroupInfo::ClearClientDevices()
421 {
422 clientDevices.clear();
423 }
424
SetWpsMethod(WpsMethod wpsMethod)425 void WpsInfo::SetWpsMethod(WpsMethod wpsMethod)
426 {
427 mWpsMethod = wpsMethod;
428 }
429
GetWpsMethod() const430 WpsMethod WpsInfo::GetWpsMethod() const
431 {
432 return mWpsMethod;
433 }
434
SetBssid(const std::string & setBssid)435 void WpsInfo::SetBssid(const std::string &setBssid)
436 {
437 bssid = setBssid;
438 }
439
GetBssid() const440 const std::string &WpsInfo::GetBssid() const
441 {
442 return bssid;
443 }
444
SetPin(const std::string & setPin)445 void WpsInfo::SetPin(const std::string &setPin)
446 {
447 pin = setPin;
448 }
449
GetPin() const450 const std::string &WpsInfo::GetPin() const
451 {
452 return pin;
453 }
454
SetDeviceAddress(const std::string & deviceAddress)455 void WifiP2pConfig::SetDeviceAddress(const std::string &deviceAddress)
456 {
457 mDeviceAddress = deviceAddress;
458 }
459
GetDeviceAddress() const460 const std::string &WifiP2pConfig::GetDeviceAddress() const
461 {
462 return mDeviceAddress;
463 }
464
SetDeviceAddressType(int devAddressType)465 void WifiP2pConfig::SetDeviceAddressType(int devAddressType)
466 {
467 deviceAddressType = devAddressType;
468 }
469
GetDeviceAddressType() const470 int WifiP2pConfig::GetDeviceAddressType() const
471 {
472 return deviceAddressType;
473 }
474
SetGoBand(GroupOwnerBand setGoBand)475 void WifiP2pConfig::SetGoBand(GroupOwnerBand setGoBand)
476 {
477 goBand = setGoBand;
478 }
479
GetGoBand() const480 GroupOwnerBand WifiP2pConfig::GetGoBand() const
481 {
482 return goBand;
483 }
484
SetNetId(int setNetId)485 void WifiP2pConfig::SetNetId(int setNetId)
486 {
487 netId = setNetId;
488 }
489
GetNetId() const490 int WifiP2pConfig::GetNetId() const
491 {
492 return netId;
493 }
494
SetPassphrase(const std::string & newPassphrase)495 void WifiP2pConfig::SetPassphrase(const std::string &newPassphrase)
496 {
497 passphrase = newPassphrase;
498 }
499
GetPassphrase() const500 const std::string &WifiP2pConfig::GetPassphrase() const
501 {
502 return passphrase;
503 }
504
SetGroupOwnerIntent(int intent)505 void WifiP2pConfig::SetGroupOwnerIntent(int intent)
506 {
507 groupOwnerIntent = intent;
508 }
509
GetGroupOwnerIntent() const510 int WifiP2pConfig::GetGroupOwnerIntent() const
511 {
512 return groupOwnerIntent;
513 }
514
SetGroupName(const std::string & setGroupName)515 void WifiP2pConfig::SetGroupName(const std::string &setGroupName)
516 {
517 groupName = setGroupName;
518 }
519
GetGroupName() const520 const std::string &WifiP2pConfig::GetGroupName() const
521 {
522 return groupName;
523 }
524
SetConnectState(P2pConnectedState setConnectState)525 void WifiP2pLinkedInfo::SetConnectState(P2pConnectedState setConnectState)
526 {
527 connectState = setConnectState;
528 }
529
GetConnectState() const530 P2pConnectedState WifiP2pLinkedInfo::GetConnectState() const
531 {
532 return connectState;
533 }
534
SetIsGroupOwner(bool isGroupOwner)535 void WifiP2pLinkedInfo::SetIsGroupOwner(bool isGroupOwner)
536 {
537 isP2pGroupOwner = isGroupOwner;
538 }
539
IsGroupOwner() const540 const bool &WifiP2pLinkedInfo::IsGroupOwner() const
541 {
542 return isP2pGroupOwner;
543 }
544
SetIsGroupOwnerAddress(const std::string & setGroupOwnerAddress)545 void WifiP2pLinkedInfo::SetIsGroupOwnerAddress(const std::string &setGroupOwnerAddress)
546 {
547 groupOwnerAddress = setGroupOwnerAddress;
548 }
549
GetGroupOwnerAddress() const550 const std::string &WifiP2pLinkedInfo::GetGroupOwnerAddress() const
551 {
552 return groupOwnerAddress;
553 }
554
SetProtocolType(P2pServicerProtocolType serviceProtocolType)555 void WifiP2pServiceRequest::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
556 {
557 mProtocolType = serviceProtocolType;
558 }
559
GetProtocolType() const560 P2pServicerProtocolType WifiP2pServiceRequest::GetProtocolType() const
561 {
562 return mProtocolType;
563 }
564
SetTransactionId(unsigned char transactionId)565 void WifiP2pServiceRequest::SetTransactionId(unsigned char transactionId)
566 {
567 mTransactionId = transactionId;
568 }
569
GetTransactionId() const570 int WifiP2pServiceRequest::GetTransactionId() const
571 {
572 return mTransactionId;
573 }
574
SetQuery(const std::vector<unsigned char> & query)575 void WifiP2pServiceRequest::SetQuery(const std::vector<unsigned char> &query)
576 {
577 mQuery = query;
578 }
579
GetQuery() const580 const std::vector<unsigned char> &WifiP2pServiceRequest::GetQuery() const
581 {
582 return mQuery;
583 }
584
GetTlv() const585 std::vector<unsigned char> WifiP2pServiceRequest::GetTlv() const
586 {
587 std::vector<unsigned char> ret;
588
589 unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + mQuery.size();
590 if (length > 0xff) {
591 unsigned char buf1 = length & 0x00ff;
592 unsigned char buf2 = length >> CHAR_BIT;
593 ret.push_back(buf1);
594 ret.push_back(buf2);
595 } else {
596 ret.push_back(static_cast<unsigned char>(length));
597 ret.push_back(0x00);
598 }
599 ret.push_back(static_cast<unsigned char>(mProtocolType));
600 ret.push_back(mTransactionId);
601 if (!mQuery.empty()) {
602 for (auto it = mQuery.begin(); it != mQuery.end(); ++it) {
603 ret.push_back(*it);
604 }
605 }
606
607 return ret;
608 }
609
operator ==(const WifiP2pServiceRequest & cmp) const610 bool WifiP2pServiceRequest::operator==(const WifiP2pServiceRequest &cmp) const
611 {
612 return mProtocolType == cmp.GetProtocolType() && mQuery == cmp.GetQuery();
613 }
614
SetProtocolType(P2pServicerProtocolType serviceProtocolType)615 void WifiP2pServiceResponse::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
616 {
617 mProtocolType = serviceProtocolType;
618 }
619
GetProtocolType() const620 P2pServicerProtocolType WifiP2pServiceResponse::GetProtocolType() const
621 {
622 return mProtocolType;
623 }
624
SetTransactionId(unsigned char transactionId)625 void WifiP2pServiceResponse::SetTransactionId(unsigned char transactionId)
626 {
627 mTransactionId = transactionId;
628 }
629
GetTransactionId() const630 unsigned char WifiP2pServiceResponse::GetTransactionId() const
631 {
632 return mTransactionId;
633 }
634
SetServiceStatus(P2pServiceStatus serviceStatus)635 void WifiP2pServiceResponse::SetServiceStatus(P2pServiceStatus serviceStatus)
636 {
637 mServiceStatus = serviceStatus;
638 }
639
GetServiceStatus() const640 P2pServiceStatus WifiP2pServiceResponse::GetServiceStatus() const
641 {
642 return mServiceStatus;
643 }
644
SetServiceName(const std::string & name)645 void WifiP2pServiceResponse::SetServiceName(const std::string &name)
646 {
647 mSvrName = name;
648 }
649
GetServiceName() const650 const std::string &WifiP2pServiceResponse::GetServiceName() const
651 {
652 return mSvrName;
653 }
654
SetData(const std::vector<unsigned char> & data)655 void WifiP2pServiceResponse::SetData(const std::vector<unsigned char> &data)
656 {
657 responseData = data;
658 }
659
GetData() const660 const std::vector<unsigned char> &WifiP2pServiceResponse::GetData() const
661 {
662 return responseData;
663 }
664
GetTlv() const665 std::vector<unsigned char> WifiP2pServiceResponse::GetTlv() const
666 {
667 std::vector<unsigned char> ret;
668 unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + SERVICE_STATUS_SIZE + responseData.size();
669 if (length > 0xff) {
670 unsigned char buf1 = length & 0x00ff;
671 unsigned char buf2 = length >> CHAR_BIT;
672 ret.push_back(buf1);
673 ret.push_back(buf2);
674 } else {
675 ret.push_back(static_cast<unsigned char>(length));
676 ret.push_back(0x00);
677 }
678 ret.push_back(static_cast<unsigned char>(mProtocolType));
679 ret.push_back(mTransactionId);
680 ret.push_back(static_cast<unsigned char>(mServiceStatus));
681 if (!responseData.empty()) {
682 for (auto it = responseData.begin(); it != responseData.end(); ++it) {
683 ret.push_back(*it);
684 }
685 }
686 return ret;
687 }
688
operator ==(const WifiP2pServiceResponse & cmp) const689 bool WifiP2pServiceResponse::operator==(const WifiP2pServiceResponse &cmp) const
690 {
691 return mProtocolType == cmp.GetProtocolType() && mServiceStatus == cmp.GetServiceStatus() &&
692 responseData == cmp.GetData();
693 }
694
SetServiceName(const std::string & name)695 void WifiP2pServiceInfo::SetServiceName(const std::string &name)
696 {
697 serviceName = name;
698 }
699
GetServiceName() const700 const std::string &WifiP2pServiceInfo::GetServiceName() const
701 {
702 return serviceName;
703 }
704
SetDeviceAddress(const std::string & deviceAddress)705 void WifiP2pServiceInfo::SetDeviceAddress(const std::string &deviceAddress)
706 {
707 mDeviceAddress = deviceAddress;
708 }
709
GetDeviceAddress() const710 const std::string &WifiP2pServiceInfo::GetDeviceAddress() const
711 {
712 return mDeviceAddress;
713 }
714
SetServicerProtocolType(P2pServicerProtocolType type)715 void WifiP2pServiceInfo::SetServicerProtocolType(P2pServicerProtocolType type)
716 {
717 mProtocolType = type;
718 }
719
GetServicerProtocolType() const720 P2pServicerProtocolType WifiP2pServiceInfo::GetServicerProtocolType() const
721 {
722 return mProtocolType;
723 }
724
SetQueryList(const std::vector<std::string> & queryList)725 void WifiP2pServiceInfo::SetQueryList(const std::vector<std::string> &queryList)
726 {
727 mQueryList = queryList;
728 }
729
GetQueryList() const730 const std::vector<std::string> &WifiP2pServiceInfo::GetQueryList() const
731 {
732 return mQueryList;
733 }
734
operator ==(const WifiP2pServiceInfo & cmp) const735 bool WifiP2pServiceInfo::operator==(const WifiP2pServiceInfo &cmp) const
736 {
737 return cmp.GetServiceName() == serviceName && cmp.GetDeviceAddress() == mDeviceAddress &&
738 cmp.GetServicerProtocolType() == mProtocolType && cmp.GetQueryList() == mQueryList;
739 }
740
741 /**
742 * @Description - For a request sent by the peer device, serviceInfo processes the query information in the request
743 * packet and returns the processing result.
744 * @param Query - the query of service request.
745 * @param data - the data of response.
746 * @return - P2pServiceStatus - result of processing.
747 */
ProcessServiceRequest(const std::vector<unsigned char> & Query,std::vector<unsigned char> & data) const748 P2pServiceStatus WifiP2pServiceInfo::ProcessServiceRequest(
749 const std::vector<unsigned char> &Query, std::vector<unsigned char> &data) const
750 {
751 data = Query;
752 data.push_back(0x00);
753 data.push_back(static_cast<unsigned char>(mProtocolType));
754 data.push_back(0x00);
755 return P2pServiceStatus::PSRS_SUCCESS;
756 }
757
758 /**
759 * @Description - Processes the data in the response returned by the peer device.
760 * @param data - the response received from the peer device.
761 */
ProcessServiceResponse(const std::vector<unsigned char> & data) const762 void WifiP2pServiceInfo::ProcessServiceResponse(const std::vector<unsigned char> &data) const
763 {
764 if (data.empty()) {
765 return;
766 }
767 }
768
Bin2HexStr(std::vector<unsigned char> data)769 std::string WifiP2pServiceInfo::Bin2HexStr(std::vector<unsigned char> data)
770 {
771 std::string dataString;
772 for (auto bufData : data) {
773 char buf[3];
774 if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
775 return "";
776 }
777 std::string aDataString = buf;
778 if (aDataString.length() == 1) {
779 dataString += std::string("0");
780 }
781 dataString += aDataString;
782 }
783 return dataString;
784 }
785
Bin2HexStr(std::string data)786 std::string WifiP2pServiceInfo::Bin2HexStr(std::string data)
787 {
788 std::string dataString;
789 for (auto bufData : data) {
790 char buf[3];
791 if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
792 return "";
793 }
794 std::string aDataString = buf;
795 if (aDataString.length() == 1) {
796 dataString += std::string("0");
797 }
798 dataString += aDataString;
799 }
800 return dataString;
801 }
802
GetRandomMacSupport() const803 bool P2pVendorConfig::GetRandomMacSupport() const
804 {
805 return randomMacSupport;
806 }
807
SetRandomMacSupport(bool support)808 void P2pVendorConfig::SetRandomMacSupport(bool support)
809 {
810 randomMacSupport = support;
811 }
812
GetIsAutoListen() const813 bool P2pVendorConfig::GetIsAutoListen() const
814 {
815 return isAutoListen;
816 }
817
SetIsAutoListen(bool autoListen)818 void P2pVendorConfig::SetIsAutoListen(bool autoListen)
819 {
820 isAutoListen = autoListen;
821 }
822
GetDeviceName() const823 const std::string &P2pVendorConfig::GetDeviceName() const
824 {
825 return deviceName;
826 }
827
SetDeviceName(const std::string & name)828 void P2pVendorConfig::SetDeviceName(const std::string &name)
829 {
830 deviceName = name;
831 }
832
GetPrimaryDeviceType() const833 const std::string &P2pVendorConfig::GetPrimaryDeviceType() const
834 {
835 return primaryDeviceType;
836 }
837
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)838 void P2pVendorConfig::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
839 {
840 primaryDeviceType = setPrimaryDeviceType;
841 }
842
GetSecondaryDeviceType() const843 const std::string &P2pVendorConfig::GetSecondaryDeviceType() const
844 {
845 return secondaryDeviceType;
846 }
847
SetSecondaryDeviceType(const std::string & setSecondaryDeviceType)848 void P2pVendorConfig::SetSecondaryDeviceType(const std::string &setSecondaryDeviceType)
849 {
850 secondaryDeviceType = setSecondaryDeviceType;
851 }
852 } // namespace Wifi
853 } // namespace OHOS
854