1 /* 2 * Copyright (c) 2021-2025 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 AUTH_INTERFACE_STRUCT_H 17 #define AUTH_INTERFACE_STRUCT_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include "lnn_node_info_struct.h" 22 #include "softbus_common.h" 23 #include "softbus_conn_interface_struct.h" 24 #include "softbus_def.h" 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif 30 #endif 31 32 #define AUTH_INVALID_ID (-1) 33 34 #define AUTH_IDENTICAL_ACCOUNT_GROUP 1 35 #define AUTH_SHARE 2 36 #define AUTH_PEER_TO_PEER_GROUP 256 37 #define CUST_UDID_LEN 16 38 #define AUTH_INVALID_DEVICEKEY_ID 0x0 39 40 typedef enum { 41 /* nearby type v1 */ 42 SOFTBUS_OLD_V1 = 1, 43 /* nearby type v2 */ 44 SOFTBUS_OLD_V2 = 2, 45 /* softbus type v1 */ 46 SOFTBUS_NEW_V1 = 100, 47 /* softbus type v2 */ 48 SOFTBUS_NEW_V2 = 101, 49 } SoftBusVersion; 50 51 typedef enum { 52 AUTH_VERSION_INVALID = 0, 53 AUTH_VERSION_V1 = 1, 54 AUTH_VERSION_V2 = 2, 55 } AuthVersion; 56 57 typedef enum { 58 AUTH_LINK_TYPE_WIFI = 1, 59 AUTH_LINK_TYPE_BR, 60 AUTH_LINK_TYPE_BLE, 61 AUTH_LINK_TYPE_P2P, 62 AUTH_LINK_TYPE_ENHANCED_P2P, 63 AUTH_LINK_TYPE_RAW_ENHANCED_P2P, 64 AUTH_LINK_TYPE_NORMALIZED, 65 AUTH_LINK_TYPE_SESSION, 66 AUTH_LINK_TYPE_SESSION_KEY, 67 AUTH_LINK_TYPE_SLE, 68 AUTH_LINK_TYPE_USB, 69 AUTH_LINK_TYPE_MAX, 70 } AuthLinkType; 71 72 typedef struct { 73 uint32_t linkTypeNum; 74 AuthLinkType linkType[AUTH_LINK_TYPE_MAX]; 75 } AuthLinkTypeList; 76 77 typedef enum { 78 AUTH_MODULE_LNN, 79 AUTH_MODULE_TRANS, 80 AUTH_MODULE_BUTT, 81 } AuthVerifyModule; 82 83 typedef struct { 84 AuthLinkType type; 85 union { 86 struct { 87 char brMac[BT_MAC_LEN]; 88 uint32_t connectionId; 89 } brInfo; 90 struct { 91 BleProtocolType protocol; 92 char bleMac[BT_MAC_LEN]; 93 uint8_t deviceIdHash[UDID_HASH_LEN]; 94 int32_t psm; 95 } bleInfo; 96 struct { 97 char ip[IP_LEN]; 98 uint8_t deviceIdHash[UDID_HASH_LEN]; 99 int32_t port; 100 int64_t authId; /* for open p2p auth conn */ 101 ListenerModule moduleId; /* for open enhance p2p auth conn */ 102 char udid[UDID_BUF_LEN]; 103 int32_t fd; 104 } ipInfo; 105 struct { 106 uint32_t connId; 107 char udid[UDID_BUF_LEN]; 108 } sessionInfo; 109 struct { 110 SleProtocolType protocol; 111 char sleMac[BT_MAC_LEN]; 112 char networkId[NETWORK_ID_BUF_LEN]; 113 } sleInfo; 114 } info; 115 char peerUid[MAX_ACCOUNT_HASH_LEN]; 116 } AuthConnInfo; 117 118 typedef struct { 119 bool isForceJoin; 120 ConnectionAddr addr; 121 char networkId[NETWORK_ID_BUF_LEN]; 122 } ForceJoinInfo; 123 124 typedef struct { 125 uint32_t requestId; 126 AuthVerifyModule module; 127 bool isFastAuth; 128 DeviceKeyId deviceKeyId; 129 ForceJoinInfo forceJoinInfo; 130 uint16_t deviceTypeId; 131 } AuthVerifyParam; 132 133 typedef enum { 134 ONLINE_HICHAIN = 0, 135 ONLINE_METANODE, 136 ONLINE_MIX, 137 AUTH_TYPE_BUTT, 138 } AuthType; 139 140 typedef struct { 141 void (*onDeviceVerifyPass)(AuthHandle authHandle, const NodeInfo *info); 142 void (*onDeviceNotTrusted)(const char *peerUdid); 143 void (*onDeviceDisconnect)(AuthHandle authHandle); 144 } AuthVerifyListener; 145 146 typedef struct { 147 void (*onVerifyPassed)(uint32_t requestId, AuthHandle authHandle, const NodeInfo *info); 148 void (*onVerifyFailed)(uint32_t requestId, int32_t reason); 149 } AuthVerifyCallback; 150 151 typedef struct { 152 void (*onConnOpened)(uint32_t requestId, AuthHandle authHandle); 153 void (*onConnOpenFailed)(uint32_t requestId, int32_t reason); 154 } AuthConnCallback; 155 156 typedef struct { 157 const uint8_t *key; 158 uint32_t keyLen; 159 } AuthKeyInfo; 160 161 typedef struct { 162 void (*onGroupCreated)(const char *groupId, int32_t groupType); 163 void (*onGroupDeleted)(const char *groupId, int32_t groupType); 164 void (*onDeviceBound)(const char *udid, const char *groupInfo); 165 } GroupChangeListener; 166 167 typedef enum { 168 TRUSTED_RELATION_IGNORE = 0, 169 TRUSTED_RELATION_NO, 170 TRUSTED_RELATION_YES, 171 } TrustedReturnType; 172 173 typedef struct { 174 int32_t module; 175 int32_t flag; 176 int64_t seq; 177 uint32_t len; 178 const uint8_t *data; 179 } AuthTransData; 180 181 typedef struct { 182 void (*onDataReceived)(AuthHandle authHandle, const AuthTransData *data); 183 void (*onDisconnected)(AuthHandle authHandle); 184 void (*onException)(AuthHandle authHandle, int32_t error); 185 } AuthTransListener; 186 187 #ifdef __cplusplus 188 #if __cplusplus 189 } 190 #endif 191 #endif 192 #endif /* AUTH_INTERFACE_STRUCT_H */