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 22static char const *g_pkgName = "ohos.dsoftbus.tool"; 23 24static 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 key = NODE_KEY_BR_MAC; 46 unsigned char brMac[BT_MAC_LEN] = {0}; 47 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, 48 brMac, BT_MAC_LEN) != 0) { 49 printf("GetNodeKeyInfo Fail!\n"); 50 } else { 51 printf("BrMac = %s\n", brMac); 52 } 53 key = NODE_KEY_IP_ADDRESS; 54 unsigned char ipAddr[IP_STR_MAX_LEN] = {0}; 55 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, 56 ipAddr, IP_STR_MAX_LEN) != 0) { 57 printf("GetNodeKeyInfo Fail!\n"); 58 } else { 59 printf("ipAddr = %s\n", ipAddr); 60 } 61 key = NODE_KEY_DEV_NAME; 62 unsigned char deviceName[DEVICE_NAME_BUF_LEN] = {0}; 63 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, 64 deviceName, DEVICE_NAME_BUF_LEN) != 0) { 65 printf("GetNodeKeyInfo Fail!\n"); 66 } else { 67 printf("deviceName = %s\n", deviceName); 68 } 69} 70 71static void PrintNodePropertyNum(const NodeBasicInfo *nodeInfo) 72{ 73 NodeDeviceInfoKey key; 74 key = NODE_KEY_NETWORK_CAPABILITY; 75 int32_t netCapacity = 0; 76 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, 77 (uint8_t *)&netCapacity, LNN_COMMON_LEN) != 0) { 78 printf("GetNodeKeyInfo Fail!\n"); 79 } else { 80 printf("netCapacity = %d\n", netCapacity); 81 } 82 key = NODE_KEY_NETWORK_TYPE; 83 int32_t netType = 0; 84 if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, 85 (uint8_t *)&netType, LNN_COMMON_LEN) != 0) { 86 printf("GetNodeKeyInfo Fail!\n"); 87 } else { 88 printf("netType = %d\n", netType); 89 } 90} 91 92int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) 93{ 94 NodeBasicInfo localNodeinfo; 95 NodeBasicInfo *remoteNodeInfo = NULL; 96 int32_t infoNum = 0; 97 printf("------Local Device Info------\n"); 98 if (GetLocalNodeDeviceInfo(g_pkgName, &localNodeinfo) != 0) { 99 printf("LnnGetLocalNodeInfo Fail!\n"); 100 return -1; 101 } 102 PrintNodeProperty(&localNodeinfo); 103 PrintNodePropertyNum(&localNodeinfo); 104 printf("------Remote Device Info------\n"); 105 if (GetAllNodeDeviceInfo(g_pkgName, &remoteNodeInfo, &infoNum) != 0) { 106 printf("GetAllNodeDeviceInfo Fail!\n"); 107 return -1; 108 } 109 printf("Device Num = %d\n", infoNum); 110 for (int i = 0; i < infoNum; i++) { 111 printf("\n[No.%d]\n", i + 1); 112 PrintNodeProperty(remoteNodeInfo + i); 113 PrintNodePropertyNum(remoteNodeInfo + i); 114 } 115 FreeNodeInfo(remoteNodeInfo); 116 printf("SoftBusDumpDeviceInfo complete!\n"); 117 return 0; 118} 119