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 LinkType linkType[LINK_TYPE_MAX]; 55 uint32_t dataConfig; 56 } SessionInfo; 57 58 typedef struct { 59 ListNode node; 60 SoftBusSecType type; 61 char sessionName[SESSION_NAME_SIZE_MAX]; 62 char pkgName[PKG_NAME_SIZE_MAX]; 63 union { 64 ISessionListener session; 65 } listener; 66 ListNode sessionList; 67 bool permissionState; 68 } ClientSessionServer; 69 70 typedef enum { 71 KEY_SESSION_NAME = 1, 72 KEY_PEER_SESSION_NAME, 73 KEY_PEER_DEVICE_ID, 74 KEY_IS_SERVER, 75 KEY_PEER_PID, 76 KEY_PEER_UID, 77 KEY_PKG_NAME, 78 } SessionKey; 79 80 int32_t ClientAddNewSession(const char* sessionName, SessionInfo* session); 81 82 /** 83 * @brief Add session. 84 * @return if session already added, return SOFTBUS_TRANS_SESSION_REPEATED, else return SOFTBUS_OK or SOFTBUS_ERR. 85 */ 86 int32_t ClientAddSession(const SessionParam *param, int32_t *sessionId, bool *isEnabled); 87 88 int32_t ClientAddAuthSession(const char *sessionName, int32_t *sessionId); 89 90 int32_t ClientDeleteSessionServer(SoftBusSecType type, const char *sessionName); 91 92 int32_t ClientDeleteSession(int32_t sessionId); 93 94 int32_t ClientGetSessionDataById(int32_t sessionId, char *data, uint16_t len, SessionKey key); 95 96 int32_t ClientGetSessionIntegerDataById(int32_t sessionId, int *data, SessionKey key); 97 98 int32_t ClientGetChannelBySessionId(int32_t sessionId, int32_t *channelId, int32_t *type, bool *isEnable); 99 100 int32_t ClientSetChannelBySessionId(int32_t sessionId, TransInfo *transInfo); 101 102 int32_t ClientGetChannelBusinessTypeBySessionId(int32_t sessionId, int32_t *businessType); 103 104 int32_t GetEncryptByChannelId(int32_t channelId, int32_t channelType, int32_t *data); 105 106 int32_t ClientGetSessionIdByChannelId(int32_t channelId, int32_t channelType, int32_t *sessionId); 107 108 int32_t ClientGetRouteTypeByChannelId(int32_t channelId, int32_t channelType, int32_t *routeType); 109 110 int32_t ClientGetDataConfigByChannelId(int32_t channelId, int32_t channelType, uint32_t *dataConfig); 111 112 int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sessionId); 113 114 int32_t ClientGetSessionCallbackById(int32_t sessionId, ISessionListener *callback); 115 116 int32_t ClientGetSessionCallbackByName(const char *sessionName, ISessionListener *callback); 117 118 int32_t ClientAddSessionServer(SoftBusSecType type, const char *pkgName, const char *sessionName, 119 const ISessionListener *listener); 120 121 int32_t ClientGetSessionSide(int32_t sessionId); 122 123 int32_t ClientGrantPermission(int uid, int pid, const char *busName); 124 125 int32_t ClientRemovePermission(const char *busName); 126 127 int32_t ClientGetFileConfigInfoById(int32_t sessionId, int32_t *fileEncrypt, int32_t *algorithm, int32_t *crc); 128 129 int TransClientInit(void); 130 void TransClientDeinit(void); 131 132 int32_t ReCreateSessionServerToServer(void); 133 void ClientTransRegLnnOffline(void); 134 135 void ClientTransOnLinkDown(const char *networkId, int32_t routeType); 136 137 void ClientCleanAllSessionWhenServerDeath(void); 138 139 int32_t CheckPermissionState(int32_t sessionId); 140 141 void PermissionStateChange(const char *pkgName, int32_t state); 142 143 #ifdef __cplusplus 144 } 145 #endif 146 #endif // CLIENT_TRANS_SESSION_MANAGER_H 147