1f1549183Sopenharmony_ci/* 2f1549183Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3f1549183Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f1549183Sopenharmony_ci * you may not use this file except in compliance with the License. 5f1549183Sopenharmony_ci * You may obtain a copy of the License at 6f1549183Sopenharmony_ci * 7f1549183Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f1549183Sopenharmony_ci * 9f1549183Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f1549183Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f1549183Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f1549183Sopenharmony_ci * See the License for the specific language governing permissions and 13f1549183Sopenharmony_ci * limitations under the License. 14f1549183Sopenharmony_ci */ 15f1549183Sopenharmony_ci 16f1549183Sopenharmony_ci#ifndef OHOS_WIFI_P2P_MSG_H 17f1549183Sopenharmony_ci#define OHOS_WIFI_P2P_MSG_H 18f1549183Sopenharmony_ci 19f1549183Sopenharmony_ci#include <string> 20f1549183Sopenharmony_ci#include <vector> 21f1549183Sopenharmony_ci#include <climits> 22f1549183Sopenharmony_ci#include "securec.h" 23f1549183Sopenharmony_ci#include "wifi_common_msg.h" 24f1549183Sopenharmony_ci 25f1549183Sopenharmony_cinamespace OHOS { 26f1549183Sopenharmony_cinamespace Wifi { 27f1549183Sopenharmony_ciconstexpr int WIFI_STR_MAC_LENGTH = 17; 28f1549183Sopenharmony_ciconstexpr int MAX_PASSPHRASE_LENGTH = 127; 29f1549183Sopenharmony_ciconstexpr int DEVICE_NAME_LENGTH = 32; 30f1549183Sopenharmony_ci 31f1549183Sopenharmony_cienum class P2pGroupStatus { GS_CREATING, GS_CREATED, GS_STARTED, GS_REMOVING, GS_INVALID }; 32f1549183Sopenharmony_cienum class P2pServiceStatus : unsigned char { 33f1549183Sopenharmony_ci PSRS_SUCCESS, 34f1549183Sopenharmony_ci PSRS_SERVICE_PROTOCOL_NOT_AVAILABLE, 35f1549183Sopenharmony_ci PSRS_REQUESTED_INFORMATION_NOT_AVAILABLE, 36f1549183Sopenharmony_ci PSRS_BAD_REQUEST, 37f1549183Sopenharmony_ci}; 38f1549183Sopenharmony_ci 39f1549183Sopenharmony_cienum class P2pServicerProtocolType : unsigned char { 40f1549183Sopenharmony_ci SERVICE_TYPE_ALL = 0, 41f1549183Sopenharmony_ci SERVICE_TYPE_BONJOUR = 1, 42f1549183Sopenharmony_ci SERVICE_TYPE_UP_NP = 2, 43f1549183Sopenharmony_ci SERVICE_TYPE_WS_DISCOVERY = 3, 44f1549183Sopenharmony_ci SERVICE_TYPE_VENDOR_SPECIFIC = 255, 45f1549183Sopenharmony_ci}; 46f1549183Sopenharmony_ci 47f1549183Sopenharmony_cienum class P2pActionCallback : unsigned char { 48f1549183Sopenharmony_ci DiscoverDevices, 49f1549183Sopenharmony_ci StopDiscoverDevices, 50f1549183Sopenharmony_ci DiscoverServices, 51f1549183Sopenharmony_ci StopDiscoverServices, 52f1549183Sopenharmony_ci PutLocalP2pService, 53f1549183Sopenharmony_ci DeleteLocalP2pService, 54f1549183Sopenharmony_ci RequestService, 55f1549183Sopenharmony_ci StartP2pListen, 56f1549183Sopenharmony_ci StopP2pListen, 57f1549183Sopenharmony_ci CreateGroup, 58f1549183Sopenharmony_ci RemoveGroup, 59f1549183Sopenharmony_ci DeleteGroup, 60f1549183Sopenharmony_ci P2pConnect, 61f1549183Sopenharmony_ci P2pCancelConnect, 62f1549183Sopenharmony_ci P2pSetDeviceName, 63f1549183Sopenharmony_ci CreateHid2dGroup, 64f1549183Sopenharmony_ci Hid2dConnect, 65f1549183Sopenharmony_ci RemoveGroupClient, 66f1549183Sopenharmony_ci DiscoverPeers, 67f1549183Sopenharmony_ci UNKNOWN 68f1549183Sopenharmony_ci}; 69f1549183Sopenharmony_ci 70f1549183Sopenharmony_cienum class P2pState { 71f1549183Sopenharmony_ci P2P_STATE_NONE = 0, 72f1549183Sopenharmony_ci P2P_STATE_IDLE, 73f1549183Sopenharmony_ci P2P_STATE_STARTING, 74f1549183Sopenharmony_ci P2P_STATE_STARTED, 75f1549183Sopenharmony_ci P2P_STATE_CLOSING, 76f1549183Sopenharmony_ci P2P_STATE_CLOSED, 77f1549183Sopenharmony_ci}; 78f1549183Sopenharmony_ci 79f1549183Sopenharmony_cienum class P2pDiscoverState { 80f1549183Sopenharmony_ci P2P_DISCOVER_NONE = 0, 81f1549183Sopenharmony_ci P2P_DISCOVER_STARTING, 82f1549183Sopenharmony_ci P2P_DISCOVER_CLOSED, 83f1549183Sopenharmony_ci}; 84f1549183Sopenharmony_ci 85f1549183Sopenharmony_cienum class P2pConnectedState { 86f1549183Sopenharmony_ci P2P_DISCONNECTED = 0, 87f1549183Sopenharmony_ci P2P_CONNECTED, 88f1549183Sopenharmony_ci}; 89f1549183Sopenharmony_ci 90f1549183Sopenharmony_cienum class P2pWfdInfoType { 91f1549183Sopenharmony_ci WFD_SOURCE = 0x00, 92f1549183Sopenharmony_ci PRIMARY_SINK = 0x01, 93f1549183Sopenharmony_ci SECONDARY_SINK = 0x10, 94f1549183Sopenharmony_ci SOURCE_OR_PRIMARY_SINK = 0x11 95f1549183Sopenharmony_ci}; 96f1549183Sopenharmony_cienum class P2pDeviceType { 97f1549183Sopenharmony_ci DEVICE_TYPE = 0x3, 98f1549183Sopenharmony_ci COUPLED_SINK_SUPPORT_AT_SOURCE = 0x4, 99f1549183Sopenharmony_ci COUPLED_SINK_SUPPORT_AT_SINK = 0x8, 100f1549183Sopenharmony_ci SESSION_AVAILABLE = 0x30, 101f1549183Sopenharmony_ci SESSION_AVAILABLE_BIT1 = 0x10, 102f1549183Sopenharmony_ci SESSION_AVAILABLE_BIT2 = 0x20 103f1549183Sopenharmony_ci}; 104f1549183Sopenharmony_ci 105f1549183Sopenharmony_cienum class P2pDeviceStatus { PDS_CONNECTED, PDS_INVITED, PDS_FAILED, PDS_AVAILABLE, PDS_UNAVAILABLE }; 106f1549183Sopenharmony_ci 107f1549183Sopenharmony_cienum class WpsMethod { WPS_METHOD_PBC, WPS_METHOD_DISPLAY, WPS_METHOD_KEYPAD, WPS_METHOD_LABEL, WPS_METHOD_INVALID }; 108f1549183Sopenharmony_ci 109f1549183Sopenharmony_cienum class WpsConfigMethod { 110f1549183Sopenharmony_ci WPS_CFG_INVALID = 0, 111f1549183Sopenharmony_ci WPS_CFG_DISPLAY = 0x0008, 112f1549183Sopenharmony_ci WPS_CFG_PUSHBUTTON = 0x0080, 113f1549183Sopenharmony_ci WPS_CFG_KEYPAD = 0x0100, 114f1549183Sopenharmony_ci}; 115f1549183Sopenharmony_ci 116f1549183Sopenharmony_cienum class P2pDeviceCapability { 117f1549183Sopenharmony_ci PDC_SERVICE_DISCOVERY = 1, 118f1549183Sopenharmony_ci PDC_CLIENT_DISCOVERABILITY = 1 << 1, 119f1549183Sopenharmony_ci PDC_STARTED_CONCURRENT_OPER = 1 << 2, 120f1549183Sopenharmony_ci PDC_REMOVING_INFRA_MANAGED = 1 << 3, 121f1549183Sopenharmony_ci PDC_DEVICE_LIMIT = 1 << 4, 122f1549183Sopenharmony_ci PDC_INVITATION_PROCEDURE = 1 << 5 123f1549183Sopenharmony_ci}; 124f1549183Sopenharmony_ci 125f1549183Sopenharmony_cienum class P2pGroupCapability { 126f1549183Sopenharmony_ci PGC_GROUP_OWNER = 1, 127f1549183Sopenharmony_ci PGC_PERSISTENT_GROUP = 1 << 1, 128f1549183Sopenharmony_ci PGC_GROUP_LIMIT = 1 << 2, 129f1549183Sopenharmony_ci PGC_INTRA_BSS_DIST = 1 << 3, 130f1549183Sopenharmony_ci PGC_CROSS_CONN = 1 << 4, 131f1549183Sopenharmony_ci PGC_PERSISTENT_RECONN = 1 << 5, 132f1549183Sopenharmony_ci PGC_GROUP_FORMATION = 1 << 6, 133f1549183Sopenharmony_ci PGC_IP_ADDR_ALLOC = 1 << 7 134f1549183Sopenharmony_ci}; 135f1549183Sopenharmony_ci 136f1549183Sopenharmony_cistruct GcInfo { 137f1549183Sopenharmony_ci std::string ip; 138f1549183Sopenharmony_ci std::string mac; 139f1549183Sopenharmony_ci std::string host; 140f1549183Sopenharmony_ci}; 141f1549183Sopenharmony_ci 142f1549183Sopenharmony_cienum class GroupOwnerBand { GO_BAND_AUTO, GO_BAND_2GHZ, GO_BAND_5GHZ }; 143f1549183Sopenharmony_ciinline const int MAX_WFD_SUBELEMS = 12; 144f1549183Sopenharmony_ciconst char DeviceInfoSubelemLenHex[] = {"0006"}; 145f1549183Sopenharmony_ciclass WifiP2pWfdInfo { 146f1549183Sopenharmony_cipublic: 147f1549183Sopenharmony_ci WifiP2pWfdInfo() : wfdEnabled(false), deviceInfo(0), ctrlPort(0), maxThroughput(0) 148f1549183Sopenharmony_ci {} 149f1549183Sopenharmony_ci WifiP2pWfdInfo(int info, int port, int throughput) 150f1549183Sopenharmony_ci : wfdEnabled(true), deviceInfo(info), ctrlPort(port), maxThroughput(throughput) 151f1549183Sopenharmony_ci {} 152f1549183Sopenharmony_ci ~WifiP2pWfdInfo() 153f1549183Sopenharmony_ci {} 154f1549183Sopenharmony_ci void SetWfdEnabled(bool value); 155f1549183Sopenharmony_ci bool GetWfdEnabled() const; 156f1549183Sopenharmony_ci void SetDeviceInfo(int info); 157f1549183Sopenharmony_ci int GetDeviceInfo() const; 158f1549183Sopenharmony_ci void SetCtrlPort(int port); 159f1549183Sopenharmony_ci int GetCtrlPort() const; 160f1549183Sopenharmony_ci void SetMaxThroughput(int throughput); 161f1549183Sopenharmony_ci int GetMaxThroughput() const; 162f1549183Sopenharmony_ci bool isSessionAvailable(); 163f1549183Sopenharmony_ci void setSessionAvailable(bool enabled); 164f1549183Sopenharmony_ci void GetDeviceInfoElement(std::string &subelement); 165f1549183Sopenharmony_ci 166f1549183Sopenharmony_ciprivate: 167f1549183Sopenharmony_ci bool wfdEnabled; 168f1549183Sopenharmony_ci int deviceInfo; 169f1549183Sopenharmony_ci int ctrlPort; 170f1549183Sopenharmony_ci int maxThroughput; 171f1549183Sopenharmony_ci}; 172f1549183Sopenharmony_ci 173f1549183Sopenharmony_ciclass WifiP2pDevice { 174f1549183Sopenharmony_cipublic: 175f1549183Sopenharmony_ci WifiP2pDevice() 176f1549183Sopenharmony_ci : deviceName(""), 177f1549183Sopenharmony_ci networkName(""), 178f1549183Sopenharmony_ci mDeviceAddress(""), 179f1549183Sopenharmony_ci deviceAddressType(REAL_DEVICE_ADDRESS), 180f1549183Sopenharmony_ci primaryDeviceType(""), 181f1549183Sopenharmony_ci secondaryDeviceType(""), 182f1549183Sopenharmony_ci status(P2pDeviceStatus::PDS_UNAVAILABLE), 183f1549183Sopenharmony_ci supportWpsConfigMethods(0), 184f1549183Sopenharmony_ci deviceCapabilitys(0), 185f1549183Sopenharmony_ci groupCapabilitys(0) 186f1549183Sopenharmony_ci {} 187f1549183Sopenharmony_ci ~WifiP2pDevice() 188f1549183Sopenharmony_ci {} 189f1549183Sopenharmony_ci void SetDeviceName(const std::string &setDeviceName); 190f1549183Sopenharmony_ci const std::string &GetDeviceName() const; 191f1549183Sopenharmony_ci void SetNetworkName(const std::string &name); 192f1549183Sopenharmony_ci const std::string &GetNetworkName() const; 193f1549183Sopenharmony_ci void SetDeviceAddress(const std::string &deviceAddress); 194f1549183Sopenharmony_ci void SetRandomDeviceAddress(const std::string &deviceAddress); 195f1549183Sopenharmony_ci const std::string &GetDeviceAddress() const; 196f1549183Sopenharmony_ci const std::string &GetRandomDeviceAddress() const; 197f1549183Sopenharmony_ci void SetDeviceAddressType(int devAddressType); 198f1549183Sopenharmony_ci int GetDeviceAddressType() const; 199f1549183Sopenharmony_ci void SetPrimaryDeviceType(const std::string &setPrimaryDeviceType); 200f1549183Sopenharmony_ci const std::string &GetPrimaryDeviceType() const; 201f1549183Sopenharmony_ci void SetSecondaryDeviceType(const std::string &deviceType); 202f1549183Sopenharmony_ci const std::string &GetSecondaryDeviceType() const; 203f1549183Sopenharmony_ci void SetP2pDeviceStatus(P2pDeviceStatus setStatus); 204f1549183Sopenharmony_ci P2pDeviceStatus GetP2pDeviceStatus() const; 205f1549183Sopenharmony_ci void SetWfdInfo(const WifiP2pWfdInfo &info); 206f1549183Sopenharmony_ci const WifiP2pWfdInfo &GetWfdInfo() const; 207f1549183Sopenharmony_ci void SetWpsConfigMethod(unsigned int wpsConfigMethod); 208f1549183Sopenharmony_ci unsigned int GetWpsConfigMethod() const; 209f1549183Sopenharmony_ci void SetDeviceCapabilitys(int capabilitys); 210f1549183Sopenharmony_ci int GetDeviceCapabilitys() const; 211f1549183Sopenharmony_ci void SetGroupCapabilitys(int capabilitys); 212f1549183Sopenharmony_ci int GetGroupCapabilitys() const; 213f1549183Sopenharmony_ci bool IsGroupOwner() const; 214f1549183Sopenharmony_ci bool IsGroupLimit() const; 215f1549183Sopenharmony_ci bool IsDeviceLimit() const; 216f1549183Sopenharmony_ci bool Isinviteable() const; 217f1549183Sopenharmony_ci bool IsValid() const; 218f1549183Sopenharmony_ci bool operator==(const WifiP2pDevice &cmp) const; 219f1549183Sopenharmony_ci bool operator!=(const WifiP2pDevice &cmp) const; 220f1549183Sopenharmony_ci bool WpsPbcSupported() const; 221f1549183Sopenharmony_ci bool WpsDisplaySupported() const; 222f1549183Sopenharmony_ci bool WpKeypadSupported() const; 223f1549183Sopenharmony_ci void SetGroupAddress(const std::string &groupAddress); 224f1549183Sopenharmony_ci const std::string &GetGroupAddress() const; 225f1549183Sopenharmony_ci 226f1549183Sopenharmony_ciprivate: 227f1549183Sopenharmony_ci std::string deviceName; /* the value range is 0 to 32 characters. */ 228f1549183Sopenharmony_ci std::string networkName; /* oper_ssid of peer device */ 229f1549183Sopenharmony_ci std::string mDeviceAddress; /* the device MAC address, the length is 17 characters. */ 230f1549183Sopenharmony_ci std::string mGroupAddress; /* the group MAC address, the length is 17 characters. */ 231f1549183Sopenharmony_ci std::string mRandomDeviceAddress; /* the device random MAC address, the length is 17 characters. */ 232f1549183Sopenharmony_ci int deviceAddressType; /* the device MAC address type */ 233f1549183Sopenharmony_ci std::string primaryDeviceType; 234f1549183Sopenharmony_ci std::string secondaryDeviceType; 235f1549183Sopenharmony_ci P2pDeviceStatus status; 236f1549183Sopenharmony_ci WifiP2pWfdInfo wfdInfo; 237f1549183Sopenharmony_ci unsigned int supportWpsConfigMethods; 238f1549183Sopenharmony_ci int deviceCapabilitys; 239f1549183Sopenharmony_ci int groupCapabilitys; 240f1549183Sopenharmony_ci}; 241f1549183Sopenharmony_ci 242f1549183Sopenharmony_ciinline const int TEMPORARY_NET_ID = -1; 243f1549183Sopenharmony_ciinline const int PERSISTENT_NET_ID = -2; 244f1549183Sopenharmony_ciinline const int INVALID_NET_ID = -999; 245f1549183Sopenharmony_ciclass WifiP2pGroupInfo { 246f1549183Sopenharmony_cipublic: 247f1549183Sopenharmony_ci WifiP2pGroupInfo() 248f1549183Sopenharmony_ci : isP2pGroupOwner(false), 249f1549183Sopenharmony_ci networkId(INVALID_NET_ID), 250f1549183Sopenharmony_ci frequency(0), 251f1549183Sopenharmony_ci isP2pPersistent(0), 252f1549183Sopenharmony_ci groupStatus(P2pGroupStatus::GS_INVALID), 253f1549183Sopenharmony_ci explicitGroup(false) 254f1549183Sopenharmony_ci {} 255f1549183Sopenharmony_ci ~WifiP2pGroupInfo() 256f1549183Sopenharmony_ci {} 257f1549183Sopenharmony_ci bool operator==(const WifiP2pGroupInfo &group) const; 258f1549183Sopenharmony_ci bool operator!=(const WifiP2pGroupInfo &group) const; 259f1549183Sopenharmony_ci void SetIsGroupOwner(bool isGroupOwner); 260f1549183Sopenharmony_ci bool IsGroupOwner() const; 261f1549183Sopenharmony_ci void SetOwner(const WifiP2pDevice &setOwner); 262f1549183Sopenharmony_ci const WifiP2pDevice &GetOwner() const; 263f1549183Sopenharmony_ci void SetPassphrase(const std::string &setPassphrase); 264f1549183Sopenharmony_ci const std::string &GetPassphrase() const; 265f1549183Sopenharmony_ci void SetInterface(const std::string &setInterface); 266f1549183Sopenharmony_ci const std::string &GetInterface() const; 267f1549183Sopenharmony_ci void SetGroupName(const std::string &newGroupName); 268f1549183Sopenharmony_ci const std::string &GetGroupName() const; 269f1549183Sopenharmony_ci void SetFrequency(int setFrequency); 270f1549183Sopenharmony_ci int GetFrequency() const; 271f1549183Sopenharmony_ci void SetIsPersistent(bool isPersistent); 272f1549183Sopenharmony_ci bool IsPersistent() const; 273f1549183Sopenharmony_ci void SetP2pGroupStatus(P2pGroupStatus newGroupStatus); 274f1549183Sopenharmony_ci P2pGroupStatus GetP2pGroupStatus() const; 275f1549183Sopenharmony_ci void SetNetworkId(int nwId); 276f1549183Sopenharmony_ci const int &GetNetworkId() const; 277f1549183Sopenharmony_ci void SetGoIpAddress(const std::string &ipAddr); 278f1549183Sopenharmony_ci const std::string &GetGoIpAddress() const; 279f1549183Sopenharmony_ci void SetGcIpAddress(const std::string &ipAddr); 280f1549183Sopenharmony_ci const std::string &GetGcIpAddress() const; 281f1549183Sopenharmony_ci void AddClientDevice(const WifiP2pDevice &clientDevice); 282f1549183Sopenharmony_ci void AddPersistentDevice(const WifiP2pDevice &clientDevice); 283f1549183Sopenharmony_ci void RemoveClientDevice(const WifiP2pDevice &clientDevice); 284f1549183Sopenharmony_ci void RemovePersistentDevice(const WifiP2pDevice &clientDevice); 285f1549183Sopenharmony_ci bool IsContainsDevice(const WifiP2pDevice &clientDevice) const; 286f1549183Sopenharmony_ci bool IsContainsPersistentDevice(const WifiP2pDevice &clientDevice) const; 287f1549183Sopenharmony_ci bool IsClientDevicesEmpty() const; 288f1549183Sopenharmony_ci const std::vector<WifiP2pDevice> &GetClientDevices() const; 289f1549183Sopenharmony_ci const std::vector<WifiP2pDevice> &GetPersistentDevices() const; 290f1549183Sopenharmony_ci void SetClientDevices(const std::vector<WifiP2pDevice> &devices); 291f1549183Sopenharmony_ci void SetClientPersistentDevices(const std::vector<WifiP2pDevice> &devices); 292f1549183Sopenharmony_ci void ClearClientDevices(); 293f1549183Sopenharmony_ci bool IsExplicitGroup(void) const; 294f1549183Sopenharmony_ci void SetExplicitGroup(bool isExplicit); 295f1549183Sopenharmony_ci void SetCreatorUid(int uid); 296f1549183Sopenharmony_ci int GetCreatorUid(); 297f1549183Sopenharmony_ci 298f1549183Sopenharmony_ciprivate: 299f1549183Sopenharmony_ci WifiP2pDevice owner; 300f1549183Sopenharmony_ci bool isP2pGroupOwner; 301f1549183Sopenharmony_ci std::string passphrase; /* the value ranges from 8 to 63. */ 302f1549183Sopenharmony_ci std::string interface; 303f1549183Sopenharmony_ci std::string groupName; 304f1549183Sopenharmony_ci int networkId; 305f1549183Sopenharmony_ci int frequency; /* for example : freq=2412 to select 2.4 GHz channel 1.(Based on 2.4 GHz or 5 GHz) */ 306f1549183Sopenharmony_ci bool isP2pPersistent; 307f1549183Sopenharmony_ci P2pGroupStatus groupStatus; 308f1549183Sopenharmony_ci std::vector<WifiP2pDevice> clientDevices; 309f1549183Sopenharmony_ci std::vector<WifiP2pDevice> persistentClients; 310f1549183Sopenharmony_ci std::string goIpAddress; 311f1549183Sopenharmony_ci std::string gcIpAddress; 312f1549183Sopenharmony_ci bool explicitGroup; 313f1549183Sopenharmony_ci int creatorUid = -1; 314f1549183Sopenharmony_ci}; 315f1549183Sopenharmony_ci 316f1549183Sopenharmony_ciclass WpsInfo { 317f1549183Sopenharmony_cipublic: 318f1549183Sopenharmony_ci WpsInfo() : mWpsMethod(WpsMethod::WPS_METHOD_INVALID), bssid(""), pin("") 319f1549183Sopenharmony_ci {} 320f1549183Sopenharmony_ci ~WpsInfo() 321f1549183Sopenharmony_ci {} 322f1549183Sopenharmony_ci void SetWpsMethod(WpsMethod wpsMethod); 323f1549183Sopenharmony_ci WpsMethod GetWpsMethod() const; 324f1549183Sopenharmony_ci 325f1549183Sopenharmony_ci void SetBssid(const std::string &setBssid); 326f1549183Sopenharmony_ci const std::string &GetBssid() const; 327f1549183Sopenharmony_ci void SetPin(const std::string &setPin); 328f1549183Sopenharmony_ci const std::string &GetPin() const; 329f1549183Sopenharmony_ci 330f1549183Sopenharmony_ciprivate: 331f1549183Sopenharmony_ci WpsMethod mWpsMethod; 332f1549183Sopenharmony_ci std::string bssid; /* the length is 17 characters. */ 333f1549183Sopenharmony_ci std::string pin; /* the length is 4 or 8 characters. */ 334f1549183Sopenharmony_ci}; 335f1549183Sopenharmony_ci 336f1549183Sopenharmony_ciinline const int AUTO_GROUP_OWNER_VALUE = -1; 337f1549183Sopenharmony_ciinline const int MIN_GROUP_OWNER_VALUE = 0; 338f1549183Sopenharmony_ciinline const int MAX_GROUP_OWNER_VALUE = 15; 339f1549183Sopenharmony_ciclass WifiP2pConfig { 340f1549183Sopenharmony_cipublic: 341f1549183Sopenharmony_ci WifiP2pConfig() 342f1549183Sopenharmony_ci : mDeviceAddress(""), 343f1549183Sopenharmony_ci deviceAddressType(REAL_DEVICE_ADDRESS), 344f1549183Sopenharmony_ci goBand(GroupOwnerBand::GO_BAND_AUTO), 345f1549183Sopenharmony_ci netId(-1), 346f1549183Sopenharmony_ci passphrase(""), 347f1549183Sopenharmony_ci groupOwnerIntent(AUTO_GROUP_OWNER_VALUE), 348f1549183Sopenharmony_ci groupName("") 349f1549183Sopenharmony_ci {} 350f1549183Sopenharmony_ci WifiP2pConfig(const WifiP2pConfig &config) 351f1549183Sopenharmony_ci : mDeviceAddress(config.GetDeviceAddress()), 352f1549183Sopenharmony_ci deviceAddressType(config.GetDeviceAddressType()), 353f1549183Sopenharmony_ci goBand(config.GetGoBand()), 354f1549183Sopenharmony_ci netId(config.GetNetId()), 355f1549183Sopenharmony_ci passphrase(config.GetPassphrase()), 356f1549183Sopenharmony_ci groupOwnerIntent(config.GetGroupOwnerIntent()), 357f1549183Sopenharmony_ci groupName(config.GetGroupName()) 358f1549183Sopenharmony_ci {} 359f1549183Sopenharmony_ci ~WifiP2pConfig() 360f1549183Sopenharmony_ci {} 361f1549183Sopenharmony_ci void SetDeviceAddress(const std::string &deviceAddress); 362f1549183Sopenharmony_ci const std::string &GetDeviceAddress() const; 363f1549183Sopenharmony_ci void SetDeviceAddressType(int addressAddrType); 364f1549183Sopenharmony_ci int GetDeviceAddressType() const; 365f1549183Sopenharmony_ci void SetGoBand(GroupOwnerBand setGoBand); 366f1549183Sopenharmony_ci GroupOwnerBand GetGoBand() const; 367f1549183Sopenharmony_ci void SetNetId(int setNetId); 368f1549183Sopenharmony_ci int GetNetId() const; 369f1549183Sopenharmony_ci void SetPassphrase(const std::string &newPassphrase); 370f1549183Sopenharmony_ci const std::string &GetPassphrase() const; 371f1549183Sopenharmony_ci void SetGroupOwnerIntent(int goIntent); 372f1549183Sopenharmony_ci int GetGroupOwnerIntent() const; 373f1549183Sopenharmony_ci void SetGroupName(const std::string &setGroupName); 374f1549183Sopenharmony_ci const std::string &GetGroupName() const; 375f1549183Sopenharmony_ci 376f1549183Sopenharmony_ciprivate: 377f1549183Sopenharmony_ci std::string mDeviceAddress; /* the device MAC address, the length is 17 characters. */ 378f1549183Sopenharmony_ci int deviceAddressType; /* the device MAC address type */ 379f1549183Sopenharmony_ci GroupOwnerBand goBand; 380f1549183Sopenharmony_ci int netId; /* network id, when -2 means persistent and -1 means temporary, else need >= 0 */ 381f1549183Sopenharmony_ci std::string passphrase; /* the value ranges from 8 to 63. */ 382f1549183Sopenharmony_ci int groupOwnerIntent; /* the value is -1.(A value of -1 indicates the system can choose an appropriate value.) */ 383f1549183Sopenharmony_ci std::string groupName; /* the value ranges from 1 to 32. */ 384f1549183Sopenharmony_ci}; 385f1549183Sopenharmony_ci 386f1549183Sopenharmony_ciclass WifiP2pConfigInternal : public WifiP2pConfig { 387f1549183Sopenharmony_cipublic: 388f1549183Sopenharmony_ci WifiP2pConfigInternal(): WifiP2pConfig() 389f1549183Sopenharmony_ci { 390f1549183Sopenharmony_ci wpsInfo.SetWpsMethod(WpsMethod::WPS_METHOD_INVALID); 391f1549183Sopenharmony_ci } 392f1549183Sopenharmony_ci explicit WifiP2pConfigInternal(WifiP2pConfig config): WifiP2pConfig(config) 393f1549183Sopenharmony_ci { 394f1549183Sopenharmony_ci wpsInfo.SetWpsMethod(WpsMethod::WPS_METHOD_INVALID); 395f1549183Sopenharmony_ci } 396f1549183Sopenharmony_ci ~WifiP2pConfigInternal() 397f1549183Sopenharmony_ci {} 398f1549183Sopenharmony_ci inline void SetWpsInfo(const WpsInfo &info) 399f1549183Sopenharmony_ci { 400f1549183Sopenharmony_ci wpsInfo = info; 401f1549183Sopenharmony_ci } 402f1549183Sopenharmony_ci inline const WpsInfo &GetWpsInfo() const 403f1549183Sopenharmony_ci { 404f1549183Sopenharmony_ci return wpsInfo; 405f1549183Sopenharmony_ci } 406f1549183Sopenharmony_ci 407f1549183Sopenharmony_ciprivate: 408f1549183Sopenharmony_ci WpsInfo wpsInfo; 409f1549183Sopenharmony_ci}; 410f1549183Sopenharmony_ci 411f1549183Sopenharmony_ciclass WifiP2pLinkedInfo { 412f1549183Sopenharmony_cipublic: 413f1549183Sopenharmony_ci WifiP2pLinkedInfo() : connectState(P2pConnectedState::P2P_DISCONNECTED), isP2pGroupOwner(false) 414f1549183Sopenharmony_ci {} 415f1549183Sopenharmony_ci ~WifiP2pLinkedInfo() 416f1549183Sopenharmony_ci {} 417f1549183Sopenharmony_ci void SetConnectState(P2pConnectedState setConnectState); 418f1549183Sopenharmony_ci P2pConnectedState GetConnectState() const; 419f1549183Sopenharmony_ci void SetIsGroupOwner(bool isGroupOwner); 420f1549183Sopenharmony_ci const bool &IsGroupOwner() const; 421f1549183Sopenharmony_ci void SetIsGroupOwnerAddress(const std::string &setGroupOwnerAddress); 422f1549183Sopenharmony_ci const std::string &GetGroupOwnerAddress() const; 423f1549183Sopenharmony_ci void AddClientInfoList(const std::string &mac, const std::string &ip, const std::string &host); 424f1549183Sopenharmony_ci void RemoveClientInfo(std::string mac); 425f1549183Sopenharmony_ci void ClearClientInfo(); 426f1549183Sopenharmony_ci const std::vector<GcInfo> &GetClientInfoList() const; 427f1549183Sopenharmony_ciprivate: 428f1549183Sopenharmony_ci P2pConnectedState connectState; 429f1549183Sopenharmony_ci bool isP2pGroupOwner; 430f1549183Sopenharmony_ci std::string groupOwnerAddress; /* the length is 17 characters. */ 431f1549183Sopenharmony_ci std::vector<GcInfo> gc_info_list; 432f1549183Sopenharmony_ci}; 433f1549183Sopenharmony_ci 434f1549183Sopenharmony_ciinline const int SERVICE_TLV_LENGTH_SIZE = 2; 435f1549183Sopenharmony_ciinline const int PROTOCOL_SIZE = 1; 436f1549183Sopenharmony_ciinline const int TRANSACTION_ID_SIZE = 1; 437f1549183Sopenharmony_ciconst int SERVICE_STATUS_SIZE = 1; 438f1549183Sopenharmony_ci 439f1549183Sopenharmony_ciclass WifiP2pServiceRequest { 440f1549183Sopenharmony_cipublic: 441f1549183Sopenharmony_ci WifiP2pServiceRequest() : mProtocolType(P2pServicerProtocolType::SERVICE_TYPE_ALL), mTransactionId(0) 442f1549183Sopenharmony_ci {} 443f1549183Sopenharmony_ci WifiP2pServiceRequest(P2pServicerProtocolType protocolType, const std::string &data) 444f1549183Sopenharmony_ci : mProtocolType(protocolType), 445f1549183Sopenharmony_ci mTransactionId(0) 446f1549183Sopenharmony_ci { 447f1549183Sopenharmony_ci for (unsigned long i = 0; i < data.length(); ++i) { 448f1549183Sopenharmony_ci mQuery.push_back(data.at(i)); 449f1549183Sopenharmony_ci } 450f1549183Sopenharmony_ci } 451f1549183Sopenharmony_ci ~WifiP2pServiceRequest() 452f1549183Sopenharmony_ci {} 453f1549183Sopenharmony_ci void SetProtocolType(P2pServicerProtocolType serviceProtocolType); 454f1549183Sopenharmony_ci P2pServicerProtocolType GetProtocolType() const; 455f1549183Sopenharmony_ci void SetTransactionId(unsigned char transactionId); 456f1549183Sopenharmony_ci int GetTransactionId() const; 457f1549183Sopenharmony_ci void SetQuery(const std::vector<unsigned char> &query); 458f1549183Sopenharmony_ci const std::vector<unsigned char> &GetQuery() const; 459f1549183Sopenharmony_ci 460f1549183Sopenharmony_ci std::vector<unsigned char> GetTlv() const; 461f1549183Sopenharmony_ci 462f1549183Sopenharmony_ci bool operator==(const WifiP2pServiceRequest &cmp) const; 463f1549183Sopenharmony_ci 464f1549183Sopenharmony_ciprivate: 465f1549183Sopenharmony_ci P2pServicerProtocolType mProtocolType; 466f1549183Sopenharmony_ci unsigned char mTransactionId; 467f1549183Sopenharmony_ci std::vector<unsigned char> mQuery; 468f1549183Sopenharmony_ci}; 469f1549183Sopenharmony_ci 470f1549183Sopenharmony_ciclass WifiP2pServiceResponse { 471f1549183Sopenharmony_cipublic: 472f1549183Sopenharmony_ci WifiP2pServiceResponse() 473f1549183Sopenharmony_ci : mProtocolType(P2pServicerProtocolType::SERVICE_TYPE_ALL), 474f1549183Sopenharmony_ci mTransactionId(0), 475f1549183Sopenharmony_ci mServiceStatus(P2pServiceStatus::PSRS_BAD_REQUEST) 476f1549183Sopenharmony_ci {} 477f1549183Sopenharmony_ci WifiP2pServiceResponse(P2pServicerProtocolType protocolType, P2pServiceStatus serviceStatus, 478f1549183Sopenharmony_ci unsigned char transactionId, const std::vector<unsigned char> data) 479f1549183Sopenharmony_ci : mProtocolType(protocolType), mTransactionId(transactionId), mServiceStatus(serviceStatus), responseData(data) 480f1549183Sopenharmony_ci {} 481f1549183Sopenharmony_ci ~WifiP2pServiceResponse() 482f1549183Sopenharmony_ci {} 483f1549183Sopenharmony_ci void SetProtocolType(P2pServicerProtocolType serviceProtocolType); 484f1549183Sopenharmony_ci P2pServicerProtocolType GetProtocolType() const; 485f1549183Sopenharmony_ci void SetTransactionId(unsigned char transactionId); 486f1549183Sopenharmony_ci unsigned char GetTransactionId() const; 487f1549183Sopenharmony_ci void SetServiceStatus(P2pServiceStatus serviceStatus); 488f1549183Sopenharmony_ci P2pServiceStatus GetServiceStatus() const; 489f1549183Sopenharmony_ci void SetServiceName(const std::string &name); 490f1549183Sopenharmony_ci const std::string &GetServiceName() const; 491f1549183Sopenharmony_ci void SetData(const std::vector<unsigned char> &data); 492f1549183Sopenharmony_ci const std::vector<unsigned char> &GetData() const; 493f1549183Sopenharmony_ci std::vector<unsigned char> GetTlv() const; 494f1549183Sopenharmony_ci bool operator==(const WifiP2pServiceResponse &cmp) const; 495f1549183Sopenharmony_ci 496f1549183Sopenharmony_ciprotected: 497f1549183Sopenharmony_ci P2pServicerProtocolType mProtocolType; 498f1549183Sopenharmony_ci unsigned char mTransactionId; 499f1549183Sopenharmony_ci P2pServiceStatus mServiceStatus; 500f1549183Sopenharmony_ci std::string mSvrName; 501f1549183Sopenharmony_ci std::vector<unsigned char> responseData; 502f1549183Sopenharmony_ci}; 503f1549183Sopenharmony_ci 504f1549183Sopenharmony_ciclass WifiP2pServiceInfo { 505f1549183Sopenharmony_cipublic: 506f1549183Sopenharmony_ci WifiP2pServiceInfo() 507f1549183Sopenharmony_ci : mDeviceAddress("00:00:00:00:00:00"), mProtocolType(P2pServicerProtocolType::SERVICE_TYPE_VENDOR_SPECIFIC) 508f1549183Sopenharmony_ci {} 509f1549183Sopenharmony_ci explicit WifiP2pServiceInfo(std::vector<std::string> queryList) 510f1549183Sopenharmony_ci : mProtocolType(P2pServicerProtocolType::SERVICE_TYPE_VENDOR_SPECIFIC), 511f1549183Sopenharmony_ci mQueryList(queryList) 512f1549183Sopenharmony_ci {} 513f1549183Sopenharmony_ci ~WifiP2pServiceInfo() 514f1549183Sopenharmony_ci {} 515f1549183Sopenharmony_ci void SetServiceName(const std::string &name); 516f1549183Sopenharmony_ci const std::string &GetServiceName() const; 517f1549183Sopenharmony_ci void SetDeviceAddress(const std::string &deviceAddress); 518f1549183Sopenharmony_ci const std::string &GetDeviceAddress() const; 519f1549183Sopenharmony_ci void SetServicerProtocolType(P2pServicerProtocolType type); 520f1549183Sopenharmony_ci P2pServicerProtocolType GetServicerProtocolType() const; 521f1549183Sopenharmony_ci void SetQueryList(const std::vector<std::string> &queryList); 522f1549183Sopenharmony_ci const std::vector<std::string> &GetQueryList() const; 523f1549183Sopenharmony_ci bool operator==(const WifiP2pServiceInfo &cmp) const; 524f1549183Sopenharmony_ci /** 525f1549183Sopenharmony_ci * @Description - Pack all data into a P2P service request packet based on the data interface. 526f1549183Sopenharmony_ci * @return - WifiP2pServiceRequest 527f1549183Sopenharmony_ci */ 528f1549183Sopenharmony_ci WifiP2pServiceRequest BuildRequest(); 529f1549183Sopenharmony_ci P2pServiceStatus ProcessServiceRequest( 530f1549183Sopenharmony_ci const std::vector<unsigned char> &Query, std::vector<unsigned char> &data) const; 531f1549183Sopenharmony_ci void ProcessServiceResponse(const std::vector<unsigned char> &data) const; 532f1549183Sopenharmony_ci static std::string Bin2HexStr(std::vector<unsigned char> data); 533f1549183Sopenharmony_ci static std::string Bin2HexStr(std::string data); 534f1549183Sopenharmony_ci 535f1549183Sopenharmony_ciprivate: 536f1549183Sopenharmony_ci std::string serviceName; 537f1549183Sopenharmony_ci std::string mDeviceAddress; 538f1549183Sopenharmony_ci P2pServicerProtocolType mProtocolType; 539f1549183Sopenharmony_ci std::vector<std::string> mQueryList; 540f1549183Sopenharmony_ci}; 541f1549183Sopenharmony_ci 542f1549183Sopenharmony_ciclass P2pVendorConfig { 543f1549183Sopenharmony_cipublic: 544f1549183Sopenharmony_ci P2pVendorConfig() : randomMacSupport(false), isAutoListen(false), primaryDeviceType("10-0050F204-5") 545f1549183Sopenharmony_ci {} 546f1549183Sopenharmony_ci ~P2pVendorConfig() 547f1549183Sopenharmony_ci {} 548f1549183Sopenharmony_ci bool GetRandomMacSupport() const; 549f1549183Sopenharmony_ci void SetRandomMacSupport(bool support); 550f1549183Sopenharmony_ci bool GetIsAutoListen() const; 551f1549183Sopenharmony_ci void SetIsAutoListen(bool autoListen); 552f1549183Sopenharmony_ci const std::string &GetDeviceName() const; 553f1549183Sopenharmony_ci void SetDeviceName(const std::string &name); 554f1549183Sopenharmony_ci const std::string &GetPrimaryDeviceType() const; 555f1549183Sopenharmony_ci void SetPrimaryDeviceType(const std::string &setPrimaryDeviceType); 556f1549183Sopenharmony_ci const std::string &GetSecondaryDeviceType() const; 557f1549183Sopenharmony_ci void SetSecondaryDeviceType(const std::string &setSecondaryDeviceType); 558f1549183Sopenharmony_ci 559f1549183Sopenharmony_ciprivate: 560f1549183Sopenharmony_ci bool randomMacSupport; 561f1549183Sopenharmony_ci bool isAutoListen; 562f1549183Sopenharmony_ci std::string deviceName; 563f1549183Sopenharmony_ci std::string primaryDeviceType; 564f1549183Sopenharmony_ci std::string secondaryDeviceType; 565f1549183Sopenharmony_ci}; 566f1549183Sopenharmony_ci} // namespace Wifi 567f1549183Sopenharmony_ci} // namespace OHOS 568f1549183Sopenharmony_ci#endif 569