1 /* 2 * Copyright (c) 2021 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 CLIENT_TRANS_SESSION_MANAGER_H 17 #define CLIENT_TRANS_SESSION_MANAGER_H 18 19 #include "session.h" 20 #include "softbus_def.h" 21 #include "softbus_trans_def.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define IS_SERVER 0 28 #define IS_CLIENT 1 29 30 typedef struct { 31 char peerSessionName[SESSION_NAME_SIZE_MAX]; 32 char peerDeviceId[DEVICE_ID_SIZE_MAX]; 33 char groupId[GROUP_ID_SIZE_MAX]; 34 int flag; // TYPE_MESSAGE & TYPE_BYTES & TYPE_FILE 35 } SessionTag; 36 37 typedef struct { 38 ListNode node; 39 uint16_t timeout; 40 int32_t sessionId; 41 int32_t channelId; 42 ChannelType channelType; 43 SessionTag info; 44 bool isServer; 45 bool isEnable; 46 int32_t peerUid; 47 int32_t peerPid; 48 bool isEncrypt; 49 int32_t routeType; 50 int32_t businessType; 51 int32_t fileEncrypt; 52 int32_t algorithm; 53 int32_t crc; 54 } SessionInfo; 55 56 typedef struct { 57 ListNode node; 58 SoftBusSecType type; 59 char sessionName[SESSION_NAME_SIZE_MAX]; 60 char pkgName[PKG_NAME_SIZE_MAX]; 61 union { 62 ISessionListener session; 63 } listener; 64 ListNode sessionList; 65 bool permissionState; 66 } ClientSessionServer; 67 68 typedef enum { 69 KEY_SESSION_NAME = 1, 70 KEY_PEER_SESSION_NAME, 71 KEY_PEER_DEVICE_ID, 72 KEY_IS_SERVER, 73 KEY_PEER_PID, 74 KEY_PEER_UID, 75 KEY_PKG_NAME, 76 } SessionKey; 77 78 int32_t ClientAddNewSession(const char* sessionName, SessionInfo* session); 79 80 /** 81 * @brief Add session. 82 * @return if session already added, return SOFTBUS_TRANS_SESSION_REPEATED, else return SOFTBUS_OK or SOFTBUS_ERR. 83 */ 84 int32_t ClientAddSession(const SessionParam *param, int32_t *sessionId, bool *isEnabled); 85 86 int32_t ClientAddAuthSession(const char *sessionName, int32_t *sessionId); 87 88 int32_t ClientDeleteSessionServer(SoftBusSecType type, const char *sessionName); 89 90 int32_t ClientDeleteSession(int32_t sessionId); 91 92 int32_t ClientGetSessionDataById(int32_t sessionId, char *data, uint16_t len, SessionKey key); 93 94 int32_t ClientGetSessionIntegerDataById(int32_t sessionId, int *data, SessionKey key); 95 96 int32_t ClientGetChannelBySessionId(int32_t sessionId, int32_t *channelId, int32_t *type, bool *isEnable); 97 98 int32_t ClientSetChannelBySessionId(int32_t sessionId, TransInfo *transInfo); 99 100 int32_t ClientGetChannelBusinessTypeBySessionId(int32_t sessionId, int32_t *businessType); 101 102 int32_t GetEncryptByChannelId(int32_t channelId, int32_t channelType, int32_t *data); 103 104 int32_t ClientGetSessionIdByChannelId(int32_t channelId, int32_t channelType, int32_t *sessionId); 105 106 int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sessionId); 107 108 int32_t ClientGetSessionCallbackById(int32_t sessionId, ISessionListener *callback); 109 110 int32_t ClientGetSessionCallbackByName(const char *sessionName, ISessionListener *callback); 111 112 int32_t ClientAddSessionServer(SoftBusSecType type, const char *pkgName, const char *sessionName, 113 const ISessionListener *listener); 114 115 int32_t ClientGetSessionSide(int32_t sessionId); 116 117 int32_t ClientGrantPermission(int uid, int pid, const char *busName); 118 119 int32_t ClientRemovePermission(const char *busName); 120 121 int32_t ClientGetFileConfigInfoById(int32_t sessionId, int32_t *fileEncrypt, int32_t *algorithm, int32_t *crc); 122 123 int TransClientInit(void); 124 void TransClientDeinit(void); 125 126 int32_t ReCreateSessionServerToServer(void); 127 void ClientTransRegLnnOffline(void); 128 129 void ClientTransOnLinkDown(const char *networkId, int32_t routeType); 130 131 void ClientCleanAllSessionWhenServerDeath(void); 132 133 int32_t CheckPermissionState(int32_t sessionId); 134 135 void PermissionStateChange(const char *pkgName, int32_t state); 136 137 #ifdef __cplusplus 138 } 139 #endif 140 #endif // CLIENT_TRANS_SESSION_MANAGER_H 141