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 #include "p2p_adapter.h"
17
18 #include "securec.h"
19 #include <memory>
20
21 #include "kits/c/wifi_device.h"
22 #include "kits/c/wifi_hid2d.h"
23 #include "kits/c/wifi_p2p.h"
24
25 #include "conn_log.h"
26 #include "softbus_error_code.h"
27
28 #include "data/interface_info.h"
29 #include "data/interface_manager.h"
30 #include "softbus_adapter_crypto.h"
31 #include "utils/wifi_direct_anonymous.h"
32 #include "utils/wifi_direct_utils.h"
33 #include "wifi_direct_error_code.h"
34 #include "wifi_direct_defines.h"
35
36 namespace OHOS::SoftBus {
37 static constexpr char DEFAULT_NET_MASK[] = "255.255.255.0";
38 static constexpr int CHANNEL_ARRAY_NUM_MAX = 256;
39 static constexpr int DECIMAL_BASE = 10;
40
GetChannel5GListIntArray(std::vector<int> & channels)41 int32_t P2pAdapter::GetChannel5GListIntArray(std::vector<int> &channels)
42 {
43 int array[CHANNEL_ARRAY_NUM_MAX] {};
44 auto ret = Hid2dGetChannelListFor5G(array, CHANNEL_ARRAY_NUM_MAX);
45 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(static_cast<int32_t>(ret)),
46 CONN_WIFI_DIRECT, "ret=%{public}d", ToSoftBusErrorCode(static_cast<int32_t>(ret)));
47
48 int count = 0;
49 while (array[count]) {
50 channels.push_back(array[count]);
51 count++;
52 }
53
54 return SOFTBUS_OK;
55 }
56
IsWifiEnable()57 bool P2pAdapter::IsWifiEnable()
58 {
59 return IsWifiActive() == WIFI_STA_ACTIVE;
60 }
61
IsWifiConnected()62 bool P2pAdapter::IsWifiConnected()
63 {
64 WifiLinkedInfo linkedInfo;
65 int32_t ret = GetLinkedInfo(&linkedInfo);
66 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, false, CONN_WIFI_DIRECT, "get wifi linked info failed");
67 if (linkedInfo.connState == WIFI_CONNECTED) {
68 CONN_LOGI(CONN_WIFI_DIRECT, "wifi is connected");
69 return true;
70 }
71 CONN_LOGI(CONN_WIFI_DIRECT, "wifi not connected");
72 return false;
73 }
74
IsWifiP2pEnabled()75 bool P2pAdapter::IsWifiP2pEnabled()
76 {
77 enum P2pState state;
78 auto ret = GetP2pEnableStatus(&state);
79 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, false, CONN_WIFI_DIRECT, "get p2p enable status failed");
80 CONN_LOGI(CONN_WIFI_DIRECT, "P2pEnableStatus=%{public}d", static_cast<int>(state));
81 return state == P2P_STATE_STARTED;
82 }
83
GetInterfaceCoexistCap()84 std::string P2pAdapter::GetInterfaceCoexistCap()
85 {
86 return "";
87 }
88
GetStationFrequency()89 int32_t P2pAdapter::GetStationFrequency()
90 {
91 WifiLinkedInfo linkedInfo;
92 int32_t ret = GetLinkedInfo(&linkedInfo);
93 CONN_CHECK_AND_RETURN_RET_LOGW(
94 ret == WIFI_SUCCESS, ToSoftBusErrorCode(ret), CONN_WIFI_DIRECT, "get wifi linked info failed");
95 CONN_LOGI(CONN_WIFI_DIRECT, "frequency=%{public}d", linkedInfo.frequency);
96
97 return linkedInfo.frequency;
98 }
99
P2pCreateGroup(const CreateGroupParam & param)100 int32_t P2pAdapter::P2pCreateGroup(const CreateGroupParam ¶m)
101 {
102 FreqType type = param.isWideBandSupported ? FREQUENCY_160M : FREQUENCY_DEFAULT;
103 int32_t ret = Hid2dCreateGroup(param.frequency, type);
104 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(ret),
105 CONN_WIFI_DIRECT, "create group failed, frequency=%{public}d, type=%{public}d, error=%{public}d",
106 param.frequency, type, ToSoftBusErrorCode(ret));
107
108 CONN_LOGI(CONN_WIFI_DIRECT, "create group success");
109 return SOFTBUS_OK;
110 }
111
P2pConnectGroup(const ConnectParam & param)112 int32_t P2pAdapter::P2pConnectGroup(const ConnectParam ¶m)
113 {
114 std::vector<std::string> configs = WifiDirectUtils::SplitString(param.groupConfig, "\n");
115
116 Hid2dConnectConfig connectConfig;
117 (void)memset_s(&connectConfig, sizeof(connectConfig), 0, sizeof(connectConfig));
118
119 int32_t ret =
120 strcpy_s(connectConfig.ssid, sizeof(connectConfig.ssid), configs[P2P_GROUP_CONFIG_INDEX_SSID].c_str());
121 CONN_CHECK_AND_RETURN_RET_LOGW(ret == EOK, SOFTBUS_CONN_PV2_COPY_SSID_FAILED, CONN_WIFI_DIRECT, "copy ssid failed");
122
123 std::vector<uint8_t> bssid = WifiDirectUtils::MacStringToArray(configs[P2P_GROUP_CONFIG_INDEX_BSSID]);
124 memcpy_s(connectConfig.bssid, sizeof(connectConfig.bssid), bssid.data(), sizeof(connectConfig.bssid));
125
126 ret = strcpy_s(connectConfig.preSharedKey, sizeof(connectConfig.preSharedKey),
127 configs[P2P_GROUP_CONFIG_INDEX_SHARE_KEY].c_str());
128 CONN_CHECK_AND_RETURN_RET_LOGW(
129 ret == EOK, SOFTBUS_CONN_PV2_COPY_SHARE_KEY_FAILED, CONN_WIFI_DIRECT, "copy share key failed");
130
131 connectConfig.frequency = strtol(configs[P2P_GROUP_CONFIG_INDEX_FREQ].c_str(), nullptr, DECIMAL_BASE);
132 CONN_LOGI(CONN_WIFI_DIRECT, "connect config frequency=%{public}d", connectConfig.frequency);
133
134 if (param.isLegacyGo) {
135 connectConfig.dhcpMode = CONNECT_AP_NODHCP;
136 } else {
137 connectConfig.dhcpMode = CONNECT_GO_NODHCP;
138 if (configs.size() == P2P_GROUP_CONFIG_INDEX_MAX &&
139 !strcmp(configs[P2P_GROUP_CONFIG_INDEX_MODE].c_str(), "1")) {
140 connectConfig.dhcpMode = CONNECT_AP_DHCP;
141 }
142 }
143 CONN_LOGI(
144 CONN_WIFI_DIRECT, "dhcpMode=%{public}d frequency=%{public}d", connectConfig.dhcpMode, connectConfig.frequency);
145 ret = Hid2dConnect(&connectConfig);
146 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(ret),
147 CONN_WIFI_DIRECT, "connect group failed");
148
149 CONN_LOGI(CONN_WIFI_DIRECT, "connect group success");
150 return SOFTBUS_OK;
151 }
152
P2pShareLinkReuse()153 int32_t P2pAdapter::P2pShareLinkReuse()
154 {
155 WifiErrorCode ret = Hid2dSharedlinkIncrease();
156 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(static_cast<int32_t>(ret)),
157 CONN_WIFI_DIRECT, "failed ret=%{public}d", ToSoftBusErrorCode(static_cast<int32_t>(ret)));
158 return SOFTBUS_OK;
159 }
160
P2pShareLinkRemoveGroup(const DestroyGroupParam & param)161 int32_t P2pAdapter::P2pShareLinkRemoveGroup(const DestroyGroupParam ¶m)
162 {
163 WifiErrorCode ret = Hid2dSharedlinkDecrease();
164 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(static_cast<int32_t>(ret)),
165 CONN_WIFI_DIRECT, "failed ret=%{public}d", ToSoftBusErrorCode(static_cast<int32_t>(ret)));
166 return SOFTBUS_OK;
167 }
168
DestroyGroup(const DestroyGroupParam & param)169 int32_t P2pAdapter::DestroyGroup(const DestroyGroupParam ¶m)
170 {
171 LinkInfo::LinkMode role;
172 InterfaceManager::GetInstance().ReadInterface(
173 InterfaceInfo::InterfaceType::P2P, [&role](const InterfaceInfo &info) {
174 role = info.GetRole();
175 return SOFTBUS_OK;
176 });
177
178 WifiErrorCode ret;
179 if (role == LinkInfo::LinkMode::GO) {
180 ret = RemoveGroup();
181 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(static_cast<int32_t>(ret)),
182 CONN_WIFI_DIRECT, "remove group failed, ret=%{public}d",
183 ToSoftBusErrorCode(static_cast<int32_t>(ret)));
184 } else if (role == LinkInfo::LinkMode::GC) {
185 ret = Hid2dRemoveGcGroup(param.interface.c_str());
186 CONN_CHECK_AND_RETURN_RET_LOGW(ret == WIFI_SUCCESS, ToSoftBusErrorCode(static_cast<int32_t>(ret)),
187 CONN_WIFI_DIRECT, "remove gc group of interface failed, interface=%{public}s, ret=%{public}d",
188 param.interface.c_str(), ToSoftBusErrorCode(static_cast<int32_t>(ret)));
189 } else {
190 CONN_LOGW(CONN_WIFI_DIRECT, "unknown api role. role=%{public}d", role);
191 return SOFTBUS_CONN_UNKNOWN_ROLE;
192 }
193
194 return SOFTBUS_OK;
195 }
196
GetStationFrequencyWithFilter()197 int32_t P2pAdapter::GetStationFrequencyWithFilter()
198 {
199 int32_t frequency = P2pAdapter::GetStationFrequency();
200 CONN_CHECK_AND_RETURN_RET_LOGW(frequency > 0, FREQUENCY_INVALID, CONN_WIFI_DIRECT, "invalid frequency");
201 if (WifiDirectUtils::Is5GBand(frequency)) {
202 std::vector<int> channelArray;
203 auto ret = P2pAdapter::GetChannel5GListIntArray(channelArray);
204 if (ret != SOFTBUS_OK) {
205 return ret;
206 }
207 int32_t channel = WifiDirectUtils::FrequencyToChannel(frequency);
208 if (WifiDirectUtils::IsInChannelList(channel, channelArray)) {
209 return frequency;
210 }
211 return FREQUENCY_INVALID;
212 }
213 if (WifiDirectUtils::Is2GBand(frequency)) {
214 return frequency;
215 }
216
217 CONN_LOGE(CONN_WIFI_DIRECT, "get local frequency failed");
218 return FREQUENCY_INVALID;
219 }
220
GetRecommendChannel(void)221 int32_t P2pAdapter::GetRecommendChannel(void)
222 {
223 RecommendChannelRequest request;
224 (void)memset_s(&request, sizeof(request), 0, sizeof(request));
225 RecommendChannelResponse response;
226 (void)memset_s(&response, sizeof(response), 0, sizeof(response));
227
228 int32_t ret = Hid2dGetRecommendChannel(&request, &response);
229 if (ret != WIFI_SUCCESS) {
230 return ToSoftBusErrorCode(ret);
231 }
232
233 if (response.centerFreq) {
234 return WifiDirectUtils::FrequencyToChannel(response.centerFreq);
235 }
236
237 if (response.centerFreq1) {
238 return WifiDirectUtils::FrequencyToChannel(response.centerFreq1);
239 }
240
241 return CHANNEL_INVALID;
242 }
243
GetSelfWifiConfigInfo(std::string & config)244 int32_t P2pAdapter::GetSelfWifiConfigInfo(std::string &config)
245 {
246 uint8_t wifiConfig[CFG_DATA_MAX_BYTES] = { 0 };
247 int32_t wifiConfigSize = 0;
248 int32_t ret = Hid2dGetSelfWifiCfgInfo(TYPE_OF_GET_SELF_CONFIG, (char *)wifiConfig, &wifiConfigSize);
249 CONN_CHECK_AND_RETURN_RET_LOGE((ret == WIFI_SUCCESS) || (ret == ERROR_WIFI_ENHANCE_SVC), ToSoftBusErrorCode(ret),
250 CONN_WIFI_DIRECT, "get self wifi config failed, error=%{public}d",
251 ToSoftBusErrorCode(ret));
252
253 CONN_LOGI(CONN_WIFI_DIRECT, "wifiConfigSize=%{public}d", wifiConfigSize);
254 if (wifiConfigSize == 0) {
255 CONN_LOGI(CONN_WIFI_DIRECT, "empty wifi cfg");
256 return SOFTBUS_OK;
257 }
258
259 uint8_t encode[CFG_DATA_MAX_BYTES] = { 0 };
260 size_t encodeSize = 0;
261 ret = SoftBusBase64Encode(encode, sizeof(encode), &encodeSize, wifiConfig, wifiConfigSize);
262 CONN_CHECK_AND_RETURN_RET_LOGE(ret == WIFI_SUCCESS, ret, CONN_WIFI_DIRECT, "encode failed, error=%{public}d", ret);
263
264 config = std::string((const char *)encode, encodeSize);
265 return SOFTBUS_OK;
266 }
267
SetPeerWifiConfigInfo(const std::string & config)268 int32_t P2pAdapter::SetPeerWifiConfigInfo(const std::string &config)
269 {
270 auto peerCfgLen = config.size() + 1;
271 auto decodeCfg = new uint8_t[peerCfgLen];
272 size_t decodeLen = 0;
273 CONN_CHECK_AND_RETURN_RET_LOGE(decodeCfg, SOFTBUS_MALLOC_ERR, CONN_WIFI_DIRECT, "alloc failed");
274
275 int32_t ret = SoftBusBase64Decode(decodeCfg, peerCfgLen, &decodeLen, (uint8_t *)config.c_str(), config.size());
276 if (ret != SOFTBUS_OK) {
277 delete[] decodeCfg;
278 CONN_LOGI(CONN_WIFI_DIRECT, "decode wifi cfg failed, error=%{public}d", ret);
279 return ret;
280 }
281 ret = Hid2dSetPeerWifiCfgInfo(TYPE_OF_SET_PEER_CONFIG, (char *)decodeCfg, (int32_t)decodeLen);
282 delete[] decodeCfg;
283 CONN_CHECK_AND_RETURN_RET_LOGE((ret == WIFI_SUCCESS) || (ret == ERROR_WIFI_ENHANCE_SVC), ToSoftBusErrorCode(ret),
284 CONN_WIFI_DIRECT, "set wifi cfg failed, error=%{public}d",
285 ToSoftBusErrorCode(ret));
286 CONN_LOGI(CONN_WIFI_DIRECT, "set success");
287 return SOFTBUS_OK;
288 }
289
SetPeerWifiConfigInfoV2(const uint8_t * cfg,size_t size)290 int32_t P2pAdapter::SetPeerWifiConfigInfoV2(const uint8_t *cfg, size_t size)
291 {
292 (void)cfg;
293 (void)size;
294 return SOFTBUS_CONN_SET_PEER_WIFI_CONFIG_FAIL;
295 }
296
IsWideBandSupported()297 bool P2pAdapter::IsWideBandSupported()
298 {
299 return Hid2dIsWideBandwidthSupported();
300 }
301
GetGroupInfo(WifiDirectP2pGroupInfo & groupInfoOut)302 int32_t P2pAdapter::GetGroupInfo(WifiDirectP2pGroupInfo &groupInfoOut)
303 {
304 auto groupInfo = std::make_shared<WifiP2pGroupInfo>();
305 auto ret = GetCurrentGroup(groupInfo.get());
306 if (ret != WIFI_SUCCESS) {
307 CONN_LOGE(CONN_WIFI_DIRECT, "get current group failed, error=%{public}d",
308 ToSoftBusErrorCode(static_cast<int32_t>(ret)));
309 return ToSoftBusErrorCode(static_cast<int32_t>(ret));
310 }
311 groupInfoOut.isGroupOwner = groupInfo->isP2pGroupOwner;
312 groupInfoOut.frequency = groupInfo->frequency;
313 groupInfoOut.interface = groupInfo->interface;
314 std::vector<uint8_t> devAddrArray(groupInfo->owner.devAddr, groupInfo->owner.devAddr +
315 sizeof(groupInfo->owner.devAddr));
316 std::vector<uint8_t> devRandomAddrArray(groupInfo->owner.randomDevAddr, groupInfo->owner.randomDevAddr +
317 sizeof(groupInfo->owner.randomDevAddr));
318 groupInfoOut.groupOwner.address = WifiDirectUtils::MacArrayToString(devAddrArray);
319 groupInfoOut.groupOwner.randomMac = WifiDirectUtils::MacArrayToString(devRandomAddrArray);
320 for (auto i = 0; i < groupInfo->clientDevicesSize; i++) {
321 std::vector<uint8_t> clientAddrArray(
322 groupInfo->clientDevices[i].devAddr, groupInfo->clientDevices[i].devAddr +
323 sizeof(groupInfo->clientDevices[i].devAddr));
324 std::vector<uint8_t> clientRandomAddrArray(
325 groupInfo->clientDevices[i].randomDevAddr, groupInfo->clientDevices[i].randomDevAddr +
326 sizeof(groupInfo->clientDevices[i].randomDevAddr));
327 WifiDirectP2pDeviceInfo deviceInfo;
328 deviceInfo.address = WifiDirectUtils::MacArrayToString(clientAddrArray);
329 deviceInfo.randomMac = WifiDirectUtils::MacArrayToString(clientRandomAddrArray);
330 groupInfoOut.clientDevices.push_back(deviceInfo);
331 }
332 return SOFTBUS_OK;
333 }
334
GetGroupConfig(std::string & groupConfigString)335 int32_t P2pAdapter::GetGroupConfig(std::string &groupConfigString)
336 {
337 auto groupInfo = std::make_shared<WifiP2pGroupInfo>();
338 auto ret = GetCurrentGroup(groupInfo.get());
339 if (ret != WIFI_SUCCESS) {
340 CONN_LOGE(CONN_WIFI_DIRECT, "get current group failed, error=%{public}d",
341 ToSoftBusErrorCode(static_cast<int32_t>(ret)));
342 return ToSoftBusErrorCode(static_cast<int32_t>(ret));
343 }
344
345 std::string interface = groupInfo->interface;
346 std::vector<uint8_t> macAddrArray = WifiDirectUtils::GetInterfaceMacAddr(interface);
347
348 std::string macAddrString = WifiDirectUtils::MacArrayToString(macAddrArray);
349
350 CONN_LOGI(CONN_WIFI_DIRECT, "frequency=%{public}d", groupInfo->frequency);
351
352 groupConfigString = groupInfo->groupName;
353 groupConfigString += "\n";
354 groupConfigString += macAddrString;
355 groupConfigString += "\n";
356 groupConfigString += groupInfo->passphrase;
357 groupConfigString += "\n";
358 groupConfigString += std::to_string(groupInfo->frequency);
359
360 return SOFTBUS_OK;
361 }
362
GetIpAddress(std::string & ipString)363 int32_t P2pAdapter::GetIpAddress(std::string &ipString)
364 {
365 auto groupInfo = std::make_shared<WifiP2pGroupInfo>();
366 int32_t ret = GetCurrentGroup(groupInfo.get());
367 if (ret != WIFI_SUCCESS) {
368 CONN_LOGE(CONN_WIFI_DIRECT, "get current group failed, error=%{public}d", ToSoftBusErrorCode(ret));
369 return ToSoftBusErrorCode(ret);
370 }
371
372 std::string interface = groupInfo->interface;
373 CONN_LOGI(CONN_WIFI_DIRECT, "interfaceName=%{public}s", interface.c_str());
374 ret = WifiDirectUtils::GetInterfaceIpString(interface, ipString);
375 CONN_CHECK_AND_RETURN_RET_LOGW(
376 ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get interfaceIp string failed, error=%d", ret);
377 return SOFTBUS_OK;
378 }
379
GetMacAddress()380 std::string P2pAdapter::GetMacAddress()
381 {
382 std::vector<uint8_t> macArray = WifiDirectUtils::GetInterfaceMacAddr(IF_NAME_P2P0);
383 std::string macString = WifiDirectUtils::MacArrayToString(macArray);
384 if (macString.empty()) {
385 macArray = WifiDirectUtils::GetInterfaceMacAddr(IF_NAME_WLAN);
386 macString = WifiDirectUtils::MacArrayToString(macArray);
387 CONN_LOGI(CONN_WIFI_DIRECT, "wlan0");
388 return macString;
389 }
390 CONN_LOGI(CONN_WIFI_DIRECT, "p2p0");
391 return macString;
392 }
393
GetDynamicMacAddress(std::string & macString)394 int32_t P2pAdapter::GetDynamicMacAddress(std::string &macString)
395 {
396 auto groupInfo = std::make_shared<WifiP2pGroupInfo>();
397 auto ret = GetCurrentGroup(groupInfo.get());
398 if (ret != WIFI_SUCCESS) {
399 CONN_LOGE(CONN_WIFI_DIRECT, "get current group failed, error=%{public}d", ToSoftBusErrorCode(ret));
400 return ToSoftBusErrorCode(ret);
401 }
402 std::vector<uint8_t> macArray = WifiDirectUtils::GetInterfaceMacAddr(groupInfo->interface);
403 macString = WifiDirectUtils::MacArrayToString(macArray);
404 return SOFTBUS_OK;
405 }
406
RequestGcIp(const std::string & macString,std::string & ipString)407 int32_t P2pAdapter::RequestGcIp(const std::string &macString, std::string &ipString)
408 {
409 if (macString.size() == 0) {
410 CONN_LOGE(CONN_WIFI_DIRECT, "mac is empty");
411 return SOFTBUS_INVALID_PARAM;
412 }
413 std::vector<uint8_t> macArray = WifiDirectUtils::MacStringToArray(macString);
414
415 uint32_t ipArray[IPV4_ADDR_ARRAY_LEN];
416 int ret = Hid2dRequestGcIp(macArray.data(), ipArray);
417 if (ret != WIFI_SUCCESS) {
418 CONN_LOGE(CONN_WIFI_DIRECT, "request Gc Ip failed, error=%{public}d", ToSoftBusErrorCode(ret));
419 return ToSoftBusErrorCode(ret);
420 }
421
422 std::stringstream ss;
423 ss << ipArray[0] << ".";
424 ss << ipArray[1] << ".";
425 ss << ipArray[2] << "."; // 2 is ipArray index.
426 ss << ipArray[3]; // 3 is ipArray index.
427
428 ipString = ss.str();
429 CONN_LOGI(CONN_WIFI_DIRECT, "gcIp=%{public}s", WifiDirectAnonymizeIp(ipString).c_str());
430 return SOFTBUS_OK;
431 }
432
P2pConfigGcIp(const std::string & interface,const std::string & ip)433 int32_t P2pAdapter::P2pConfigGcIp(const std::string &interface, const std::string &ip)
434 {
435 IpAddrInfo addrInfo;
436
437 int32_t ret = WifiDirectUtils::IpStringToIntArray(ip.c_str(), addrInfo.ip, IPV4_ARRAY_LEN);
438
439 CONN_CHECK_AND_RETURN_RET_LOGW(ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "convert ip to int array failed");
440 ret = WifiDirectUtils::IpStringToIntArray(ip.c_str(), addrInfo.gateway, IPV4_ARRAY_LEN);
441 CONN_CHECK_AND_RETURN_RET_LOGW(ret == SOFTBUS_OK, SOFTBUS_CONN_CONVERT_GATEWAY_TO_INTARRAY_FAILED, CONN_WIFI_DIRECT,
442 "convert gateway to int array failed");
443 ret = WifiDirectUtils::IpStringToIntArray(DEFAULT_NET_MASK, addrInfo.netmask, IPV4_ARRAY_LEN);
444 CONN_CHECK_AND_RETURN_RET_LOGW(ret == SOFTBUS_OK, SOFTBUS_CONN_CONVERT_GATEWAY_TO_INTARRAY_FAILED, CONN_WIFI_DIRECT,
445 "convert gateway to int array failed");
446
447 ret = Hid2dConfigIPAddr(interface.c_str(), &addrInfo);
448 CONN_CHECK_AND_RETURN_RET_LOGW(
449 ret == WIFI_SUCCESS, ToSoftBusErrorCode(ret), CONN_WIFI_DIRECT, "hid2d config ip failed");
450 CONN_LOGI(CONN_WIFI_DIRECT, "success");
451 return SOFTBUS_OK;
452 }
453 } // namespace OHOS::SoftBus
454