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 #ifndef AUTH_CONNECTION_H 17 #define AUTH_CONNECTION_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #include "auth_common.h" 23 #include "auth_interface.h" 24 #include "softbus_conn_interface.h" 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif 30 #endif 31 32 typedef struct { 33 void (*onConnectResult)(uint32_t requestId, uint64_t connId, int32_t result, const AuthConnInfo *connInfo); 34 void (*onDisconnected)(uint64_t connId, const AuthConnInfo *connInfo); 35 void (*onDataReceived)(uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, 36 const AuthDataHead *head, const uint8_t *data); 37 } AuthConnListener; 38 39 int32_t AuthConnInit(const AuthConnListener *listener); 40 void AuthConnDeinit(void); 41 42 int32_t ConnectAuthDevice(uint32_t requestId, const AuthConnInfo *connInfo, ConnSideType sideType); 43 void UpdateAuthDevicePriority(uint64_t connId); 44 void DisconnectAuthDevice(uint64_t connId); 45 int32_t PostAuthData(uint64_t connId, bool toServer, const AuthDataHead *head, const uint8_t *data); 46 47 ConnSideType GetConnSideType(uint64_t connId); 48 bool CheckActiveAuthConnection(const AuthConnInfo *connInfo); 49 50 const char *GetConnTypeStr(uint64_t connId); 51 uint32_t GetConnId(uint64_t connId); 52 int32_t GetConnType(uint64_t connId); 53 54 uint32_t GetAuthDataSize(uint32_t len); 55 int32_t PackAuthData(const AuthDataHead *head, const uint8_t *data, 56 uint8_t *buf, uint32_t size); 57 const uint8_t *UnpackAuthData(const uint8_t *data, uint32_t len, AuthDataHead *head); 58 int32_t GetConnInfoByConnectionId(uint32_t connectionId, AuthConnInfo *connInfo); 59 60 #define CONN_INFO "conn[%s:%u]" 61 #define CONN_DATA(connId) GetConnTypeStr(connId), GetConnId(connId) 62 63 #ifdef __cplusplus 64 #if __cplusplus 65 } 66 #endif 67 #endif 68 #endif /* AUTH_CONNECTION_H */ 69