• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetDeviceAddress(const std::string & deviceAddress)96 void WifiP2pDevice::SetDeviceAddress(const std::string &deviceAddress)
97 {
98     mDeviceAddress = deviceAddress;
99 }
100 
GetDeviceAddress() const101 const std::string &WifiP2pDevice::GetDeviceAddress() const
102 {
103     return mDeviceAddress;
104 }
105 
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)106 void WifiP2pDevice::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
107 {
108     primaryDeviceType = setPrimaryDeviceType;
109 }
110 
GetPrimaryDeviceType() const111 const std::string &WifiP2pDevice::GetPrimaryDeviceType() const
112 {
113     return primaryDeviceType;
114 }
115 
SetSecondaryDeviceType(const std::string & deviceType)116 void WifiP2pDevice::SetSecondaryDeviceType(const std::string &deviceType)
117 {
118     secondaryDeviceType = deviceType;
119 }
120 
GetSecondaryDeviceType() const121 const std::string &WifiP2pDevice::GetSecondaryDeviceType() const
122 {
123     return secondaryDeviceType;
124 }
125 
SetP2pDeviceStatus(P2pDeviceStatus setStatus)126 void WifiP2pDevice::SetP2pDeviceStatus(P2pDeviceStatus setStatus)
127 {
128     status = setStatus;
129 }
130 
GetP2pDeviceStatus() const131 P2pDeviceStatus WifiP2pDevice::GetP2pDeviceStatus() const
132 {
133     return status;
134 }
135 
SetWfdInfo(const WifiP2pWfdInfo & info)136 void WifiP2pDevice::SetWfdInfo(const WifiP2pWfdInfo &info)
137 {
138     wfdInfo = info;
139 }
140 
GetWfdInfo() const141 const WifiP2pWfdInfo &WifiP2pDevice::GetWfdInfo() const
142 {
143     return wfdInfo;
144 }
145 
SetWpsConfigMethod(unsigned int wpsConfigMethod)146 void WifiP2pDevice::SetWpsConfigMethod(unsigned int wpsConfigMethod)
147 {
148     supportWpsConfigMethods = wpsConfigMethod;
149 }
150 
GetWpsConfigMethod() const151 unsigned int WifiP2pDevice::GetWpsConfigMethod() const
152 {
153     return supportWpsConfigMethods;
154 }
155 
SetDeviceCapabilitys(int capabilitys)156 void WifiP2pDevice::SetDeviceCapabilitys(int capabilitys)
157 {
158     deviceCapabilitys = capabilitys;
159 }
160 
GetDeviceCapabilitys() const161 int WifiP2pDevice::GetDeviceCapabilitys() const
162 {
163     return deviceCapabilitys;
164 }
165 
SetGroupCapabilitys(int capabilitys)166 void WifiP2pDevice::SetGroupCapabilitys(int capabilitys)
167 {
168     groupCapabilitys = capabilitys;
169 }
170 
GetGroupCapabilitys() const171 int WifiP2pDevice::GetGroupCapabilitys() const
172 {
173     return groupCapabilitys;
174 }
175 
IsGroupOwner() const176 bool WifiP2pDevice::IsGroupOwner() const
177 {
178     return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_OWNER));
179 }
180 
IsGroupLimit() const181 bool WifiP2pDevice::IsGroupLimit() const
182 {
183     return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_LIMIT));
184 }
185 
IsDeviceLimit() const186 bool WifiP2pDevice::IsDeviceLimit() const
187 {
188     return (deviceCapabilitys & static_cast<int>(P2pDeviceCapability::PDC_DEVICE_LIMIT));
189 }
190 
Isinviteable() const191 bool WifiP2pDevice::Isinviteable() const
192 {
193     return (deviceCapabilitys & static_cast<int>(P2pDeviceCapability::PDC_INVITATION_PROCEDURE));
194 }
195 
IsValid() const196 bool WifiP2pDevice::IsValid() const
197 {
198     if (mDeviceAddress.empty()) {
199         return false;
200     }
201     return true;
202 }
203 
operator ==(const WifiP2pDevice & cmp) const204 bool WifiP2pDevice::operator==(const WifiP2pDevice &cmp) const
205 {
206     return mDeviceAddress == cmp.GetDeviceAddress();
207 }
208 
operator !=(const WifiP2pDevice & cmp) const209 bool WifiP2pDevice::operator!=(const WifiP2pDevice &cmp) const
210 {
211     return !operator==(cmp);
212 }
213 
WpsPbcSupported() const214 bool WifiP2pDevice::WpsPbcSupported() const
215 {
216     return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_PUSHBUTTON)) != 0;
217 }
218 
WpsDisplaySupported() const219 bool WifiP2pDevice::WpsDisplaySupported() const
220 {
221     return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_DISPLAY)) != 0;
222 }
223 
WpKeypadSupported() const224 bool WifiP2pDevice::WpKeypadSupported() const
225 {
226     return (supportWpsConfigMethods & static_cast<int>(WpsConfigMethod::WPS_CFG_KEYPAD)) != 0;
227 }
228 
isGroupOwner() const229 bool WifiP2pDevice::isGroupOwner() const
230 {
231     return (groupCapabilitys & static_cast<int>(P2pGroupCapability::PGC_GROUP_OWNER)) != 0;
232 }
233 
operator ==(const WifiP2pGroupInfo & group) const234 bool WifiP2pGroupInfo::operator==(const WifiP2pGroupInfo &group) const
235 {
236     return networkId == group.GetNetworkId();
237 }
238 
operator !=(const WifiP2pGroupInfo & group) const239 bool WifiP2pGroupInfo::operator!=(const WifiP2pGroupInfo &group) const
240 {
241     return !operator==(group);
242 }
243 
SetIsGroupOwner(bool isGroupOwner)244 void WifiP2pGroupInfo::SetIsGroupOwner(bool isGroupOwner)
245 {
246     isP2pGroupOwner = isGroupOwner;
247 }
248 
IsGroupOwner() const249 bool WifiP2pGroupInfo::IsGroupOwner() const
250 {
251     return isP2pGroupOwner;
252 }
253 
SetOwner(const WifiP2pDevice & setOwner)254 void WifiP2pGroupInfo::SetOwner(const WifiP2pDevice &setOwner)
255 {
256     owner = setOwner;
257 }
258 
GetOwner() const259 const WifiP2pDevice &WifiP2pGroupInfo::GetOwner() const
260 {
261     return owner;
262 }
263 
SetPassphrase(const std::string & setPassphrase)264 void WifiP2pGroupInfo::SetPassphrase(const std::string &setPassphrase)
265 {
266     passphrase = setPassphrase;
267 }
268 
GetPassphrase() const269 const std::string &WifiP2pGroupInfo::GetPassphrase() const
270 {
271     return passphrase;
272 }
273 
SetInterface(const std::string & setInterface)274 void WifiP2pGroupInfo::SetInterface(const std::string &setInterface)
275 {
276     interface = setInterface;
277 }
278 
GetInterface() const279 const std::string &WifiP2pGroupInfo::GetInterface() const
280 {
281     return interface;
282 }
283 
SetGroupName(const std::string & newGroupName)284 void WifiP2pGroupInfo::SetGroupName(const std::string &newGroupName)
285 {
286     groupName = newGroupName;
287 }
288 
GetGroupName() const289 const std::string &WifiP2pGroupInfo::GetGroupName() const
290 {
291     return groupName;
292 }
293 
SetFrequency(int setFrequency)294 void WifiP2pGroupInfo::SetFrequency(int setFrequency)
295 {
296     frequency = setFrequency;
297 }
298 
GetFrequency() const299 int WifiP2pGroupInfo::GetFrequency() const
300 {
301     return frequency;
302 }
303 
SetIsPersistent(bool isPersistent)304 void WifiP2pGroupInfo::SetIsPersistent(bool isPersistent)
305 {
306     isP2pPersistent = isPersistent;
307 }
308 
IsPersistent() const309 bool WifiP2pGroupInfo::IsPersistent() const
310 {
311     return isP2pPersistent;
312 }
313 
SetP2pGroupStatus(P2pGroupStatus newGroupStatus)314 void WifiP2pGroupInfo::SetP2pGroupStatus(P2pGroupStatus newGroupStatus)
315 {
316     groupStatus = newGroupStatus;
317 }
318 
GetP2pGroupStatus() const319 P2pGroupStatus WifiP2pGroupInfo::GetP2pGroupStatus() const
320 {
321     return groupStatus;
322 }
323 
SetNetworkId(int nwId)324 void WifiP2pGroupInfo::SetNetworkId(int nwId)
325 {
326     networkId = nwId;
327 }
328 
GetNetworkId() const329 const int &WifiP2pGroupInfo::GetNetworkId() const
330 {
331     return networkId;
332 }
333 
SetGoIpAddress(const std::string & ipAddr)334 void WifiP2pGroupInfo::SetGoIpAddress(const std::string &ipAddr)
335 {
336     goIpAddress = ipAddr;
337 }
338 
GetGoIpAddress() const339 const std::string &WifiP2pGroupInfo::GetGoIpAddress() const
340 {
341     return goIpAddress;
342 }
343 
AddClientDevice(const WifiP2pDevice & clientDevice)344 void WifiP2pGroupInfo::AddClientDevice(const WifiP2pDevice &clientDevice)
345 {
346     for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
347         if (*it == clientDevice) {
348             *it = clientDevice;
349             return;
350         }
351     }
352     clientDevices.push_back(clientDevice);
353     return;
354 }
355 
RemoveClientDevice(const WifiP2pDevice & clientDevice)356 void WifiP2pGroupInfo::RemoveClientDevice(const WifiP2pDevice &clientDevice)
357 {
358     for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
359         if (*it == clientDevice) {
360             clientDevices.erase(it);
361             return;
362         }
363     }
364     return;
365 }
366 
IsContainsDevice(const WifiP2pDevice & clientDevice) const367 bool WifiP2pGroupInfo::IsContainsDevice(const WifiP2pDevice &clientDevice) const
368 {
369     if (clientDevice == owner) {
370         return true;
371     }
372     for (auto it = clientDevices.begin(); it != clientDevices.end(); ++it) {
373         if (*it == clientDevice) {
374             return true;
375         }
376     }
377     return false;
378 }
379 
IsClientDevicesEmpty() const380 bool WifiP2pGroupInfo::IsClientDevicesEmpty() const
381 {
382     return clientDevices.empty();
383 }
384 
GetClientDevices() const385 const std::vector<WifiP2pDevice> &WifiP2pGroupInfo::GetClientDevices() const
386 {
387     return clientDevices;
388 }
389 
SetClientDevices(const std::vector<WifiP2pDevice> & devices)390 void WifiP2pGroupInfo::SetClientDevices(const std::vector<WifiP2pDevice> &devices)
391 {
392     clientDevices = devices;
393 }
394 
ClearClientDevices()395 void WifiP2pGroupInfo::ClearClientDevices()
396 {
397     clientDevices.clear();
398 }
399 
SetWpsMethod(WpsMethod wpsMethod)400 void WpsInfo::SetWpsMethod(WpsMethod wpsMethod)
401 {
402     mWpsMethod = wpsMethod;
403 }
404 
GetWpsMethod() const405 WpsMethod WpsInfo::GetWpsMethod() const
406 {
407     return mWpsMethod;
408 }
409 
SetBssid(const std::string & setBssid)410 void WpsInfo::SetBssid(const std::string &setBssid)
411 {
412     bssid = setBssid;
413 }
414 
GetBssid() const415 const std::string &WpsInfo::GetBssid() const
416 {
417     return bssid;
418 }
419 
SetPin(const std::string & setPin)420 void WpsInfo::SetPin(const std::string &setPin)
421 {
422     pin = setPin;
423 }
424 
GetPin() const425 const std::string &WpsInfo::GetPin() const
426 {
427     return pin;
428 }
429 
SetDeviceAddress(const std::string & deviceAddress)430 void WifiP2pConfig::SetDeviceAddress(const std::string &deviceAddress)
431 {
432     mDeviceAddress = deviceAddress;
433 }
434 
GetDeviceAddress() const435 const std::string &WifiP2pConfig::GetDeviceAddress() const
436 {
437     return mDeviceAddress;
438 }
439 
SetGoBand(GroupOwnerBand setGoBand)440 void WifiP2pConfig::SetGoBand(GroupOwnerBand setGoBand)
441 {
442     goBand = setGoBand;
443 }
444 
GetGoBand() const445 GroupOwnerBand WifiP2pConfig::GetGoBand() const
446 {
447     return goBand;
448 }
449 
SetNetId(int setNetId)450 void WifiP2pConfig::SetNetId(int setNetId)
451 {
452     netId = setNetId;
453 }
454 
GetNetId() const455 int WifiP2pConfig::GetNetId() const
456 {
457     return netId;
458 }
459 
SetPassphrase(const std::string & newPassphrase)460 void WifiP2pConfig::SetPassphrase(const std::string &newPassphrase)
461 {
462     passphrase = newPassphrase;
463 }
464 
GetPassphrase() const465 const std::string &WifiP2pConfig::GetPassphrase() const
466 {
467     return passphrase;
468 }
469 
SetGroupOwnerIntent(int intent)470 void WifiP2pConfig::SetGroupOwnerIntent(int intent)
471 {
472     groupOwnerIntent = intent;
473 }
474 
GetGroupOwnerIntent() const475 int WifiP2pConfig::GetGroupOwnerIntent() const
476 {
477     return groupOwnerIntent;
478 }
479 
SetGroupName(const std::string & setGroupName)480 void WifiP2pConfig::SetGroupName(const std::string &setGroupName)
481 {
482     groupName = setGroupName;
483 }
484 
GetGroupName() const485 const std::string &WifiP2pConfig::GetGroupName() const
486 {
487     return groupName;
488 }
489 
SetConnectState(P2pConnectedState setConnectState)490 void WifiP2pLinkedInfo::SetConnectState(P2pConnectedState setConnectState)
491 {
492     connectState = setConnectState;
493 }
494 
GetConnectState() const495 P2pConnectedState WifiP2pLinkedInfo::GetConnectState() const
496 {
497     return connectState;
498 }
499 
SetIsGroupOwner(bool isGroupOwner)500 void WifiP2pLinkedInfo::SetIsGroupOwner(bool isGroupOwner)
501 {
502     isP2pGroupOwner = isGroupOwner;
503 }
504 
IsGroupOwner() const505 const bool &WifiP2pLinkedInfo::IsGroupOwner() const
506 {
507     return isP2pGroupOwner;
508 }
509 
SetIsGroupOwnerAddress(const std::string & setGroupOwnerAddress)510 void WifiP2pLinkedInfo::SetIsGroupOwnerAddress(const std::string &setGroupOwnerAddress)
511 {
512     groupOwnerAddress = setGroupOwnerAddress;
513 }
514 
GetGroupOwnerAddress() const515 const std::string &WifiP2pLinkedInfo::GetGroupOwnerAddress() const
516 {
517     return groupOwnerAddress;
518 }
519 
SetProtocolType(P2pServicerProtocolType serviceProtocolType)520 void WifiP2pServiceRequest::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
521 {
522     mProtocolType = serviceProtocolType;
523 }
524 
GetProtocolType() const525 P2pServicerProtocolType WifiP2pServiceRequest::GetProtocolType() const
526 {
527     return mProtocolType;
528 }
529 
SetTransactionId(unsigned char transactionId)530 void WifiP2pServiceRequest::SetTransactionId(unsigned char transactionId)
531 {
532     mTransactionId = transactionId;
533 }
534 
GetTransactionId() const535 int WifiP2pServiceRequest::GetTransactionId() const
536 {
537     return mTransactionId;
538 }
539 
SetQuery(const std::vector<unsigned char> & query)540 void WifiP2pServiceRequest::SetQuery(const std::vector<unsigned char> &query)
541 {
542     mQuery = query;
543 }
544 
GetQuery() const545 const std::vector<unsigned char> &WifiP2pServiceRequest::GetQuery() const
546 {
547     return mQuery;
548 }
549 
GetTlv() const550 std::vector<unsigned char> WifiP2pServiceRequest::GetTlv() const
551 {
552     std::vector<unsigned char> ret;
553 
554     unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + mQuery.size();
555     if (length > 0xff) {
556         unsigned char buf1 = length & 0x00ff;
557         unsigned char buf2 = length >> CHAR_BIT;
558         ret.push_back(buf1);
559         ret.push_back(buf2);
560     } else {
561         ret.push_back(static_cast<unsigned char>(length));
562         ret.push_back(0x00);
563     }
564     ret.push_back(static_cast<unsigned char>(mProtocolType));
565     ret.push_back(mTransactionId);
566     if (!mQuery.empty()) {
567         for (auto it = mQuery.begin(); it != mQuery.end(); ++it) {
568             ret.push_back(*it);
569         }
570     }
571 
572     return ret;
573 }
574 
operator ==(const WifiP2pServiceRequest & cmp) const575 bool WifiP2pServiceRequest::operator==(const WifiP2pServiceRequest &cmp) const
576 {
577     return mProtocolType == cmp.GetProtocolType() && mQuery == cmp.GetQuery();
578 }
579 
SetProtocolType(P2pServicerProtocolType serviceProtocolType)580 void WifiP2pServiceResponse::SetProtocolType(P2pServicerProtocolType serviceProtocolType)
581 {
582     mProtocolType = serviceProtocolType;
583 }
584 
GetProtocolType() const585 P2pServicerProtocolType WifiP2pServiceResponse::GetProtocolType() const
586 {
587     return mProtocolType;
588 }
589 
SetTransactionId(unsigned char transactionId)590 void WifiP2pServiceResponse::SetTransactionId(unsigned char transactionId)
591 {
592     mTransactionId = transactionId;
593 }
594 
GetTransactionId() const595 unsigned char WifiP2pServiceResponse::GetTransactionId() const
596 {
597     return mTransactionId;
598 }
599 
SetServiceStatus(P2pServiceStatus serviceStatus)600 void WifiP2pServiceResponse::SetServiceStatus(P2pServiceStatus serviceStatus)
601 {
602     mServiceStatus = serviceStatus;
603 }
604 
GetServiceStatus() const605 P2pServiceStatus WifiP2pServiceResponse::GetServiceStatus() const
606 {
607     return mServiceStatus;
608 }
609 
SetServiceName(const std::string & name)610 void WifiP2pServiceResponse::SetServiceName(const std::string &name)
611 {
612     mSvrName = name;
613 }
614 
GetServiceName() const615 const std::string &WifiP2pServiceResponse::GetServiceName() const
616 {
617     return mSvrName;
618 }
619 
SetData(const std::vector<unsigned char> & data)620 void WifiP2pServiceResponse::SetData(const std::vector<unsigned char> &data)
621 {
622     responseData = data;
623 }
624 
GetData() const625 const std::vector<unsigned char> &WifiP2pServiceResponse::GetData() const
626 {
627     return responseData;
628 }
629 
GetTlv() const630 std::vector<unsigned char> WifiP2pServiceResponse::GetTlv() const
631 {
632     std::vector<unsigned char> ret;
633     unsigned short length = PROTOCOL_SIZE + TRANSACTION_ID_SIZE + SERVICE_STATUS_SIZE + responseData.size();
634     if (length > 0xff) {
635         unsigned char buf1 = length & 0x00ff;
636         unsigned char buf2 = length >> CHAR_BIT;
637         ret.push_back(buf1);
638         ret.push_back(buf2);
639     } else {
640         ret.push_back(static_cast<unsigned char>(length));
641         ret.push_back(0x00);
642     }
643     ret.push_back(static_cast<unsigned char>(mProtocolType));
644     ret.push_back(mTransactionId);
645     ret.push_back(static_cast<unsigned char>(mServiceStatus));
646     if (!responseData.empty()) {
647         for (auto it = responseData.begin(); it != responseData.end(); ++it) {
648             ret.push_back(*it);
649         }
650     }
651     return ret;
652 }
653 
operator ==(const WifiP2pServiceResponse & cmp) const654 bool WifiP2pServiceResponse::operator==(const WifiP2pServiceResponse &cmp) const
655 {
656     return mProtocolType == cmp.GetProtocolType() && mServiceStatus == cmp.GetServiceStatus() &&
657            responseData == cmp.GetData();
658 }
659 
SetServiceName(const std::string & name)660 void WifiP2pServiceInfo::SetServiceName(const std::string &name)
661 {
662     serviceName = name;
663 }
664 
GetServiceName() const665 const std::string &WifiP2pServiceInfo::GetServiceName() const
666 {
667     return serviceName;
668 }
669 
SetDeviceAddress(const std::string & deviceAddress)670 void WifiP2pServiceInfo::SetDeviceAddress(const std::string &deviceAddress)
671 {
672     mDeviceAddress = deviceAddress;
673 }
674 
GetDeviceAddress() const675 const std::string &WifiP2pServiceInfo::GetDeviceAddress() const
676 {
677     return mDeviceAddress;
678 }
679 
SetServicerProtocolType(P2pServicerProtocolType type)680 void WifiP2pServiceInfo::SetServicerProtocolType(P2pServicerProtocolType type)
681 {
682     mProtocolType = type;
683 }
684 
GetServicerProtocolType() const685 P2pServicerProtocolType WifiP2pServiceInfo::GetServicerProtocolType() const
686 {
687     return mProtocolType;
688 }
689 
SetQueryList(const std::vector<std::string> & queryList)690 void WifiP2pServiceInfo::SetQueryList(const std::vector<std::string> &queryList)
691 {
692     mQueryList = queryList;
693 }
694 
GetQueryList() const695 const std::vector<std::string> &WifiP2pServiceInfo::GetQueryList() const
696 {
697     return mQueryList;
698 }
699 
operator ==(const WifiP2pServiceInfo & cmp) const700 bool WifiP2pServiceInfo::operator==(const WifiP2pServiceInfo &cmp) const
701 {
702     return cmp.GetServiceName() == serviceName && cmp.GetDeviceAddress() == mDeviceAddress &&
703            cmp.GetServicerProtocolType() == mProtocolType && cmp.GetQueryList() == mQueryList;
704 }
705 
706 /**
707  * @Description - For a request sent by the peer device, serviceInfo processes the query information in the request
708  * packet and returns the processing result.
709  * @param  Query - the query of service request.
710  * @param  data - the data of response.
711  * @return - P2pServiceStatus - result of processing.
712  */
ProcessServiceRequest(const std::vector<unsigned char> & Query,std::vector<unsigned char> & data) const713 P2pServiceStatus WifiP2pServiceInfo::ProcessServiceRequest(
714     const std::vector<unsigned char> &Query, std::vector<unsigned char> &data) const
715 {
716     data = Query;
717     data.push_back(0x00);
718     data.push_back(static_cast<unsigned char>(mProtocolType));
719     data.push_back(0x00);
720     return P2pServiceStatus::PSRS_SUCCESS;
721 }
722 
723 /**
724  * @Description - Processes the data in the response returned by the peer device.
725  * @param  data - the response received from the peer device.
726  */
ProcessServiceResponse(const std::vector<unsigned char> & data) const727 void WifiP2pServiceInfo::ProcessServiceResponse(const std::vector<unsigned char> &data) const
728 {
729     if (data.empty()) {
730         return;
731     }
732 }
733 
Bin2HexStr(std::vector<unsigned char> data)734 std::string WifiP2pServiceInfo::Bin2HexStr(std::vector<unsigned char> data)
735 {
736     std::string dataString;
737     for (auto bufData : data) {
738         char buf[3];
739         if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
740             return "";
741         }
742         std::string aDataString = buf;
743         if (aDataString.length() == 1) {
744             dataString += std::string("0");
745         }
746         dataString += aDataString;
747     }
748     return dataString;
749 }
750 
Bin2HexStr(std::string data)751 std::string WifiP2pServiceInfo::Bin2HexStr(std::string data)
752 {
753     std::string dataString;
754     for (auto bufData : data) {
755         char buf[3];
756         if (sprintf_s(buf, sizeof(buf), "%x", bufData & 0xff) < 0) {
757             return "";
758         }
759         std::string aDataString = buf;
760         if (aDataString.length() == 1) {
761             dataString += std::string("0");
762         }
763         dataString += aDataString;
764     }
765     return dataString;
766 }
767 
GetRandomMacSupport() const768 bool P2pVendorConfig::GetRandomMacSupport() const
769 {
770     return randomMacSupport;
771 }
772 
SetRandomMacSupport(bool support)773 void P2pVendorConfig::SetRandomMacSupport(bool support)
774 {
775     randomMacSupport = support;
776 }
777 
GetIsAutoListen() const778 bool P2pVendorConfig::GetIsAutoListen() const
779 {
780     return isAutoListen;
781 }
782 
SetIsAutoListen(bool autoListen)783 void P2pVendorConfig::SetIsAutoListen(bool autoListen)
784 {
785     isAutoListen = autoListen;
786 }
787 
GetDeviceName() const788 const std::string &P2pVendorConfig::GetDeviceName() const
789 {
790     return deviceName;
791 }
792 
SetDeviceName(const std::string & name)793 void P2pVendorConfig::SetDeviceName(const std::string &name)
794 {
795     deviceName = name;
796 }
797 
GetPrimaryDeviceType() const798 const std::string &P2pVendorConfig::GetPrimaryDeviceType() const
799 {
800     return primaryDeviceType;
801 }
802 
SetPrimaryDeviceType(const std::string & setPrimaryDeviceType)803 void P2pVendorConfig::SetPrimaryDeviceType(const std::string &setPrimaryDeviceType)
804 {
805     primaryDeviceType = setPrimaryDeviceType;
806 }
807 
GetSecondaryDeviceType() const808 const std::string &P2pVendorConfig::GetSecondaryDeviceType() const
809 {
810     return secondaryDeviceType;
811 }
812 
SetSecondaryDeviceType(const std::string & setSecondaryDeviceType)813 void P2pVendorConfig::SetSecondaryDeviceType(const std::string &setSecondaryDeviceType)
814 {
815     secondaryDeviceType = setSecondaryDeviceType;
816 }
817 }  // namespace Wifi
818 }  // namespace OHOS