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