1 /* 2 * Copyright (c) 2024 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 #ifndef P2P_ADAPTER_H 17 #define P2P_ADAPTER_H 18 19 #include "data/interface_info.h" 20 #include "wifi_direct_defines.h" 21 #include "wifi_direct_types.h" 22 #include <sstream> 23 #include <string> 24 #include <vector> 25 26 namespace OHOS::SoftBus { 27 class P2pAdapter { 28 public: 29 enum ConnectionState { 30 P2P_DISCONNECTED = 0, 31 P2P_CONNECTED, 32 }; 33 34 struct CreateGroupParam { 35 int32_t frequency; 36 bool isWideBandSupported; 37 }; 38 39 struct ConnectParam { 40 std::string groupConfig; 41 bool isLegacyGo; 42 bool isNeedDhcp; 43 std::string gcIp; 44 }; 45 46 struct DestroyGroupParam { 47 std::string interface; 48 }; 49 50 struct WifiDirectP2pDeviceInfo { 51 std::string address; 52 std::string randomMac; 53 }; 54 55 struct WifiDirectP2pGroupInfo { 56 bool isGroupOwner; 57 int32_t frequency; 58 std::string interface; 59 std::string goIpAddr; 60 WifiDirectP2pDeviceInfo groupOwner; 61 std::vector<WifiDirectP2pDeviceInfo> clientDevices; 62 }; 63 64 static int32_t GetChannel5GListIntArray(std::vector<int> &channels); 65 static bool IsWifiP2pEnabled(); 66 static std::string GetInterfaceCoexistCap(); 67 static int32_t GetStationFrequency(); 68 69 static int32_t P2pCreateGroup(const CreateGroupParam ¶m); 70 static int32_t P2pConnectGroup(const ConnectParam ¶m); 71 static int32_t P2pShareLinkReuse(); 72 static int32_t DestroyGroup(const DestroyGroupParam ¶m); 73 static int32_t P2pShareLinkRemoveGroup(const DestroyGroupParam ¶m); 74 static int32_t GetStationFrequencyWithFilter(); 75 static int32_t GetRecommendChannel(); 76 static int32_t GetSelfWifiConfigInfo(std::string &config); 77 static int32_t SetPeerWifiConfigInfo(const std::string &config); 78 static int32_t GetGroupInfo(WifiDirectP2pGroupInfo &groupInfoOut); 79 static int32_t GetGroupConfig(std::string &groupConfigString); 80 static int32_t GetIpAddress(std::string &ipString); 81 static std::string GetMacAddress(); 82 static int32_t GetDynamicMacAddress(std::string &macString); 83 static int32_t RequestGcIp(const std::string &macString, std::string &ipString); 84 static int32_t P2pConfigGcIp(const std::string &interface, const std::string &ip); 85 static int32_t SetPeerWifiConfigInfoV2(const uint8_t *cfg, size_t size); 86 static bool IsWideBandSupported(); 87 static bool IsWifiEnable(); 88 static bool IsWifiConnected(); 89 90 private: 91 static constexpr int P2P_GROUP_CONFIG_INDEX_SSID = 0; 92 static constexpr int P2P_GROUP_CONFIG_INDEX_BSSID = 1; 93 static constexpr int P2P_GROUP_CONFIG_INDEX_SHARE_KEY = 2; 94 static constexpr int P2P_GROUP_CONFIG_INDEX_FREQ = 3; 95 static constexpr int P2P_GROUP_CONFIG_INDEX_MODE = 4; 96 static constexpr int P2P_GROUP_CONFIG_INDEX_MAX = 5; 97 }; 98 } // namespace OHOS::SoftBus 99 #endif 100