1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include<stdio.h>
17060ff233Sopenharmony_ci
18060ff233Sopenharmony_ci#include "softbus_adapter_mem.h"
19060ff233Sopenharmony_ci#include "softbus_bus_center.h"
20060ff233Sopenharmony_ci#include "softbus_common.h"
21060ff233Sopenharmony_ci
22060ff233Sopenharmony_cistatic char const *g_pkgName = "ohos.dsoftbus.tool";
23060ff233Sopenharmony_ci
24060ff233Sopenharmony_cistatic void PrintNodeProperty(const NodeBasicInfo *nodeInfo)
25060ff233Sopenharmony_ci{
26060ff233Sopenharmony_ci    printf("DeviceName = %s\n", nodeInfo->deviceName);
27060ff233Sopenharmony_ci    printf("NetworkId = %s\n", nodeInfo->networkId);
28060ff233Sopenharmony_ci    NodeDeviceInfoKey key;
29060ff233Sopenharmony_ci    key = NODE_KEY_UDID;
30060ff233Sopenharmony_ci    unsigned char udid[UDID_BUF_LEN] = {0};
31060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
32060ff233Sopenharmony_ci        udid, UDID_BUF_LEN) != 0) {
33060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
34060ff233Sopenharmony_ci    } else {
35060ff233Sopenharmony_ci        printf("Udid = %s\n", udid);
36060ff233Sopenharmony_ci    }
37060ff233Sopenharmony_ci    key = NODE_KEY_UUID;
38060ff233Sopenharmony_ci    unsigned char uuid[UUID_BUF_LEN] = {0};
39060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
40060ff233Sopenharmony_ci        uuid, UUID_BUF_LEN) != 0) {
41060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
42060ff233Sopenharmony_ci    } else {
43060ff233Sopenharmony_ci        printf("Uuid = %s\n", uuid);
44060ff233Sopenharmony_ci    }
45060ff233Sopenharmony_ci    key = NODE_KEY_BR_MAC;
46060ff233Sopenharmony_ci    unsigned char brMac[BT_MAC_LEN] = {0};
47060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
48060ff233Sopenharmony_ci        brMac, BT_MAC_LEN) != 0) {
49060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
50060ff233Sopenharmony_ci    } else {
51060ff233Sopenharmony_ci        printf("BrMac = %s\n", brMac);
52060ff233Sopenharmony_ci    }
53060ff233Sopenharmony_ci    key = NODE_KEY_IP_ADDRESS;
54060ff233Sopenharmony_ci    unsigned char ipAddr[IP_STR_MAX_LEN] = {0};
55060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
56060ff233Sopenharmony_ci        ipAddr, IP_STR_MAX_LEN) != 0) {
57060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
58060ff233Sopenharmony_ci    } else {
59060ff233Sopenharmony_ci        printf("ipAddr = %s\n", ipAddr);
60060ff233Sopenharmony_ci    }
61060ff233Sopenharmony_ci    key = NODE_KEY_DEV_NAME;
62060ff233Sopenharmony_ci    unsigned char deviceName[DEVICE_NAME_BUF_LEN] = {0};
63060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
64060ff233Sopenharmony_ci        deviceName, DEVICE_NAME_BUF_LEN) != 0) {
65060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
66060ff233Sopenharmony_ci    } else {
67060ff233Sopenharmony_ci        printf("deviceName = %s\n", deviceName);
68060ff233Sopenharmony_ci    }
69060ff233Sopenharmony_ci}
70060ff233Sopenharmony_ci
71060ff233Sopenharmony_cistatic void PrintNodePropertyNum(const NodeBasicInfo *nodeInfo)
72060ff233Sopenharmony_ci{
73060ff233Sopenharmony_ci    NodeDeviceInfoKey key;
74060ff233Sopenharmony_ci    key = NODE_KEY_NETWORK_CAPABILITY;
75060ff233Sopenharmony_ci    int32_t netCapacity = 0;
76060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
77060ff233Sopenharmony_ci    (uint8_t *)&netCapacity, LNN_COMMON_LEN) != 0) {
78060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
79060ff233Sopenharmony_ci    } else {
80060ff233Sopenharmony_ci        printf("netCapacity = %d\n", netCapacity);
81060ff233Sopenharmony_ci    }
82060ff233Sopenharmony_ci    key = NODE_KEY_NETWORK_TYPE;
83060ff233Sopenharmony_ci    int32_t netType = 0;
84060ff233Sopenharmony_ci    if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
85060ff233Sopenharmony_ci    (uint8_t *)&netType, LNN_COMMON_LEN) != 0) {
86060ff233Sopenharmony_ci        printf("GetNodeKeyInfo Fail!\n");
87060ff233Sopenharmony_ci    } else {
88060ff233Sopenharmony_ci        printf("netType = %d\n", netType);
89060ff233Sopenharmony_ci    }
90060ff233Sopenharmony_ci}
91060ff233Sopenharmony_ci
92060ff233Sopenharmony_ciint main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
93060ff233Sopenharmony_ci{
94060ff233Sopenharmony_ci    NodeBasicInfo localNodeinfo;
95060ff233Sopenharmony_ci    NodeBasicInfo *remoteNodeInfo = NULL;
96060ff233Sopenharmony_ci    int32_t infoNum = 0;
97060ff233Sopenharmony_ci    printf("------Local Device Info------\n");
98060ff233Sopenharmony_ci    if (GetLocalNodeDeviceInfo(g_pkgName, &localNodeinfo) != 0) {
99060ff233Sopenharmony_ci        printf("LnnGetLocalNodeInfo Fail!\n");
100060ff233Sopenharmony_ci        return -1;
101060ff233Sopenharmony_ci    }
102060ff233Sopenharmony_ci    PrintNodeProperty(&localNodeinfo);
103060ff233Sopenharmony_ci    PrintNodePropertyNum(&localNodeinfo);
104060ff233Sopenharmony_ci    printf("------Remote Device Info------\n");
105060ff233Sopenharmony_ci    if (GetAllNodeDeviceInfo(g_pkgName, &remoteNodeInfo, &infoNum) != 0) {
106060ff233Sopenharmony_ci        printf("GetAllNodeDeviceInfo Fail!\n");
107060ff233Sopenharmony_ci        return -1;
108060ff233Sopenharmony_ci    }
109060ff233Sopenharmony_ci    printf("Device Num = %d\n", infoNum);
110060ff233Sopenharmony_ci    for (int i = 0; i < infoNum; i++) {
111060ff233Sopenharmony_ci        printf("\n[No.%d]\n", i + 1);
112060ff233Sopenharmony_ci        PrintNodeProperty(remoteNodeInfo + i);
113060ff233Sopenharmony_ci        PrintNodePropertyNum(remoteNodeInfo + i);
114060ff233Sopenharmony_ci    }
115060ff233Sopenharmony_ci    FreeNodeInfo(remoteNodeInfo);
116060ff233Sopenharmony_ci    printf("SoftBusDumpDeviceInfo complete!\n");
117060ff233Sopenharmony_ci    return 0;
118060ff233Sopenharmony_ci}
119