1 /* 2 * Copyright (c) 2023 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 OHOS_DM_RADAR_HELPER_H 17 #define OHOS_DM_RADAR_HELPER_H 18 19 #include <cstdint> 20 #include <chrono> 21 #include <string> 22 #include <vector> 23 24 #include "single_instance.h" 25 26 #include "dm_device_info.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 const std::string ORGPKGNAME = "deviceManager"; 31 const std::string SOFTBUSNAME = "dsoftbus"; 32 const std::string HICHAINNAME = "hichain"; 33 const std::string DM_DISCOVER_BEHAVIOR = "DM_DISCOVER_BEHAVIOR"; 34 const std::string DM_AUTHCATION_BEHAVIOR = "DM_AUTHCATION_BEHAVIOR"; 35 constexpr int32_t SUBSYS_DISTRIBUTEDHARDWARE_DM = 204; 36 constexpr int32_t INVALID_UDID_LENGTH = 10; 37 constexpr int32_t SUBSTR_UDID_LENGTH = 5; 38 enum class BizScene : int32_t { 39 DM_DISCOVER = 0x1, 40 DM_AUTHCATION = 0x2, 41 DM_NETWORK = 0x3, 42 DM_DELET_TRUST_RELATION = 0x4, 43 }; 44 45 enum class StageRes : int32_t { 46 STAGE_IDLE = 0x0, 47 STAGE_SUCC = 0x1, 48 STAGE_FAIL = 0x2, 49 STAGE_CANCEL = 0x3, 50 STAGE_UNKNOW = 0x4, 51 }; 52 53 enum class BizState : int32_t { 54 BIZ_STATE_START = 0x1, 55 BIZ_STATE_END = 0x2, 56 BIZ_STATE_CANCEL = 0x3, 57 }; 58 59 enum class DisCoverStage : int32_t { 60 DISCOVER_REGISTER_CALLBACK = 0x1, 61 DISCOVER_USER_DEAL_RES = 0x2, 62 DISCOVER_GET_TRUST_DEVICE_LIST = 0x3, 63 }; 64 65 enum class AuthStage : int32_t { 66 AUTH_START = 0x1, 67 AUTH_OPEN_SESSION = 0x2, 68 AUTH_SEND_REQUEST = 0x3, 69 AUTH_PULL_AUTH_BOX = 0x4, 70 AUTH_CREATE_HICHAIN_GROUP = 0x5, 71 AUTH_PULL_PIN_BOX_START = 0x6, 72 AUTH_PULL_PIN_INPUT_BOX_END = 0x7, 73 AUTH_ADD_HICHAIN_GROUP = 0x8, 74 }; 75 76 enum class NetworkStage : int32_t { 77 NETWORK_ONLINE = 0x1, 78 NETWORK_OFFLINE = 0x2, 79 }; 80 81 enum class DeleteTrust : int32_t { 82 DELETE_TRUST = 0x1, 83 }; 84 85 enum class GetTrustDeviceList : int32_t { 86 GET_TRUST_DEVICE_LIST = 0x1, 87 }; 88 89 enum class TrustStatus : int32_t { 90 NOT_TRUST = 0x0, 91 IS_TRUST = 0x1, 92 }; 93 94 enum class CommServ : int32_t { 95 NOT_USE_SOFTBUS = 0x0, 96 USE_SOFTBUS = 0x1, 97 }; 98 99 enum class Module : int32_t { 100 DEVICE_MANAGER = 0x0, 101 HICHAIN = 0x1, 102 SOFTBUS = 0x2, 103 USER = 0x3 104 }; 105 106 struct RadarInfo { 107 std::string funcName; 108 std::string toCallPkg; 109 std::string hostName; 110 int32_t stageRes; 111 int32_t bizState; 112 std::string localSessName; 113 std::string peerSessName; 114 int32_t isTrust; 115 int32_t commServ; 116 std::string peerNetId; 117 std::string localUdid; 118 std::string peerUdid; 119 std::string discoverDevList; 120 int32_t channelId; 121 int32_t errCode; 122 }; 123 124 class IDmRadarHelper { 125 public: ~IDmRadarHelper()126 virtual ~IDmRadarHelper() {} 127 /** 128 * @tc.name: ReportDiscoverRegCallback 129 * @tc.desc: report discover regsit callback 130 * @tc.type: FUNC 131 */ 132 virtual bool ReportDiscoverRegCallback(struct RadarInfo &info) = 0; 133 virtual bool ReportDiscoverResCallback(struct RadarInfo &info) = 0; 134 virtual bool ReportDiscoverUserRes(struct RadarInfo &info) = 0; 135 virtual bool ReportAuthStart(std::string peerUdid) = 0; 136 virtual bool ReportAuthOpenSession(struct RadarInfo &info) = 0; 137 virtual bool ReportAuthSessionOpenCb(struct RadarInfo &info) = 0; 138 virtual bool ReportAuthSendRequest(struct RadarInfo &info) = 0; 139 virtual bool ReportAuthPullAuthBox(struct RadarInfo &info) = 0; 140 virtual bool ReportAuthConfirmBox(struct RadarInfo &info) = 0; 141 virtual bool ReportAuthCreateGroup(struct RadarInfo &info) = 0; 142 virtual bool ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes) = 0; 143 virtual bool ReportAuthPullPinBox(struct RadarInfo &info) = 0; 144 virtual bool ReportAuthInputPinBox(struct RadarInfo &info) = 0; 145 virtual bool ReportAuthAddGroup(struct RadarInfo &info) = 0; 146 virtual bool ReportAuthAddGroupCb(std::string funcName, int32_t stageRes) = 0; 147 virtual bool ReportNetworkOnline(struct RadarInfo &info) = 0; 148 virtual bool ReportNetworkOffline(struct RadarInfo &info) = 0; 149 virtual bool ReportDeleteTrustRelation(struct RadarInfo &info) = 0; 150 virtual bool ReportGetTrustDeviceList(struct RadarInfo &info) = 0; 151 virtual std::string GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList) = 0; 152 virtual std::string GetUdidHashByUdid(std::string udid) = 0; 153 }; 154 155 class DmRadarHelper : public IDmRadarHelper { 156 DECLARE_SINGLE_INSTANCE(DmRadarHelper); 157 public: 158 bool ReportDiscoverRegCallback(struct RadarInfo &info) override; 159 bool ReportDiscoverResCallback(struct RadarInfo &info) override; 160 bool ReportDiscoverUserRes(struct RadarInfo &info) override; 161 bool ReportAuthStart(std::string peerUdid) override; 162 bool ReportAuthOpenSession(struct RadarInfo &info) override; 163 bool ReportAuthSessionOpenCb(struct RadarInfo &info) override; 164 bool ReportAuthSendRequest(struct RadarInfo &info) override; 165 bool ReportAuthPullAuthBox(struct RadarInfo &info) override; 166 bool ReportAuthConfirmBox(struct RadarInfo &info) override; 167 bool ReportAuthCreateGroup(struct RadarInfo &info) override; 168 bool ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes) override; 169 bool ReportAuthPullPinBox(struct RadarInfo &info) override; 170 bool ReportAuthInputPinBox(struct RadarInfo &info) override; 171 bool ReportAuthAddGroup(struct RadarInfo &info) override; 172 bool ReportAuthAddGroupCb(std::string funcName, int32_t stageRes) override; 173 bool ReportNetworkOnline(struct RadarInfo &info) override; 174 bool ReportNetworkOffline(struct RadarInfo &info) override; 175 bool ReportDeleteTrustRelation(struct RadarInfo &info) override; 176 bool ReportGetTrustDeviceList(struct RadarInfo &info) override; 177 std::string GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList) override; 178 std::string GetUdidHashByUdid(std::string udid) override; 179 std::string ConvertHexToString(uint16_t hex); 180 private: 181 int32_t GetErrorCode(int32_t errCode, int32_t module); 182 std::string GetAnonyUdid(std::string udid); 183 std::string GetLocalUdid(); 184 }; 185 186 extern "C" IDmRadarHelper *CreateDmRadarInstance(); 187 using CreateDmRadarFuncPtr = IDmRadarHelper *(*)(void); 188 } // namespace DistributedHardware 189 } // namespace OHOS 190 #endif // OHOS_DM_RADAR_HELPER_H