1 /*
2 * Copyright (c) 2022 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<stdio.h>
17
18 #include "softbus_adapter_mem.h"
19 #include "softbus_bus_center.h"
20 #include "softbus_common.h"
21
22 static char const *g_pkgName = "ohos.dsoftbus.tool";
23
PrintNodeProperty(const NodeBasicInfo * nodeInfo)24 static void PrintNodeProperty(const NodeBasicInfo *nodeInfo)
25 {
26 printf("DeviceName = %s\n", nodeInfo->deviceName);
27 printf("NetworkId = %s\n", nodeInfo->networkId);
28 NodeDeviceInfoKey key;
29 key = NODE_KEY_UDID;
30 unsigned char udid[UDID_BUF_LEN] = {0};
31 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
32 udid, UDID_BUF_LEN) != 0) {
33 printf("GetNodeKeyInfo Fail!\n");
34 } else {
35 printf("Udid = %s\n", udid);
36 }
37 key = NODE_KEY_UUID;
38 unsigned char uuid[UUID_BUF_LEN] = {0};
39 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key,
40 uuid, UUID_BUF_LEN) != 0) {
41 printf("GetNodeKeyInfo Fail!\n");
42 } else {
43 printf("Uuid = %s\n", uuid);
44 }
45 }
46
main(void)47 int main(void)
48 {
49 NodeBasicInfo localNodeinfo;
50 NodeBasicInfo *remoteNodeInfo = NULL;
51 int32_t infoNum = 0;
52 printf("------Local Device Info------\n");
53 if (GetLocalNodeDeviceInfo(g_pkgName, &localNodeinfo) != 0) {
54 printf("LnnGetLocalNodeInfo Fail!\n");
55 return -1;
56 }
57 PrintNodeProperty(&localNodeinfo);
58 printf("------Remote Device Info------\n");
59 if (GetAllNodeDeviceInfo(g_pkgName, &remoteNodeInfo, &infoNum) != 0) {
60 printf("GetAllNodeDeviceInfo Fail!\n");
61 return -1;
62 }
63 printf("Device Num = %d\n", infoNum);
64 for (int i = 0; i < infoNum; i++) {
65 printf("\n[No.%d]\n", i + 1);
66 PrintNodeProperty(remoteNodeInfo + i);
67 }
68 FreeNodeInfo(remoteNodeInfo);
69 printf("SoftBusDumpDeviceInfo complete!\n");
70 return 0;
71 }
72