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_TCP_CONNECTION_H 17 #define AUTH_TCP_CONNECTION_H 18 19 #include "auth_connection.h" 20 #include "auth_tcp_connection_struct.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 int32_t SetSocketCallback(const SocketCallback *cb); 29 void UnsetSocketCallback(void); 30 31 // connect succ, return fd; otherwise, return -1. 32 int32_t SocketConnectDeviceWithAllIp(const char *localIp, const char *remoteIp, int32_t port, bool isBlockMode); 33 int32_t SocketConnectDevice(const char *ip, int32_t port, bool isBlockMode, int32_t ifnameIdx); 34 int32_t SocketSetDevice(int32_t fd, bool isBlockMode); 35 void StopSessionKeyListening(int32_t fd); 36 int32_t NipSocketConnectDevice(ListenerModule module, const char *addr, int32_t port, bool isBlockMode); 37 38 void SocketDisconnectDevice(ListenerModule module, int32_t fd); 39 40 int32_t SocketPostBytes(int32_t fd, const AuthDataHead *head, const uint8_t *data); 41 int32_t SocketGetConnInfo(int32_t fd, AuthConnInfo *connInfo, bool *isServer, int32_t ifnameIdx); 42 43 int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *info); 44 void StopSocketListening(ListenerModule moduleId); 45 46 int32_t AuthSetTcpKeepaliveOption(int32_t fd, ModeCycle cycle); 47 bool IsExistAuthTcpConnFdItemByConnId(int32_t fd); 48 void DeleteAuthTcpConnFdItemByConnId(int32_t fd); 49 int32_t AuthTcpConnFdLockInit(void); 50 void AuthTcpConnFdLockDeinit(void); 51 bool RequireAuthTcpConnFdListLock(void); 52 void ReleaseAuthTcpConnFdListLock(void); 53 54 #ifdef __cplusplus 55 #if __cplusplus 56 } 57 #endif 58 #endif 59 #endif /* AUTH_TCP_CONNECTION_H */ 60