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_SESSION_H 17 #define AUTH_SESSION_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #include "auth_common.h" 23 #include "auth_interface.h" 24 #include "auth_session_key.h" 25 #include "auth_device_common_key.h" 26 #include "common_list.h" 27 #include "lnn_node_info.h" 28 #include "lnn_state_machine.h" 29 #include "softbus_hisysevt_bus_center.h" 30 31 #ifdef __cplusplus 32 #if __cplusplus 33 extern "C" { 34 #endif 35 #endif 36 37 #define AUTH_FSM_NAME_LEN 32 38 39 typedef enum { 40 EXCHANHE_UDID = 0, 41 EXCHANGE_NETWORKID, 42 EXCHANGE_FAIL, 43 EXCHANGE_TYPE_MAX 44 } ExchangeDataType; 45 46 typedef struct { 47 uint32_t requestId; 48 bool isServer; 49 uint64_t connId; 50 AuthConnInfo connInfo; 51 uint8_t *deviceInfoData; 52 uint32_t deviceInfoDataLen; 53 NodeInfo nodeInfo; 54 bool isNodeInfoReceived; 55 bool isCloseAckReceived; 56 bool isAuthFinished; 57 char udid[UDID_BUF_LEN]; 58 char uuid[UUID_BUF_LEN]; 59 SoftBusVersion version; 60 bool isSupportCompress; 61 bool isSupportFastAuth; 62 int64_t oldIndex; 63 int32_t idType; 64 } AuthSessionInfo; 65 66 typedef struct { 67 ListNode node; 68 uint32_t id; 69 int64_t authSeq; 70 char fsmName[AUTH_FSM_NAME_LEN]; 71 FsmStateMachine fsm; 72 AuthSessionInfo info; 73 AuthStatisticData statisticData; 74 bool isDead; 75 } AuthFsm; 76 77 int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId, 78 uint64_t connId, const AuthConnInfo *connInfo, bool isServer); 79 int32_t AuthSessionProcessDevIdData(int64_t authSeq, const uint8_t *data, uint32_t len); 80 int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t len); 81 int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_t len); 82 int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size); 83 int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len); 84 int32_t AuthSessionHandleAuthFinish(int64_t authSeq); 85 int32_t AuthSessionHandleAuthError(int64_t authSeq, int32_t reason); 86 int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint32_t len); 87 int32_t AuthSessionProcessCloseAck(int64_t authSeq, const uint8_t *data, uint32_t len); 88 int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len); 89 int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len); 90 int32_t AuthSessionHandleDeviceNotTrusted(const char *udid); 91 int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId); 92 AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq); 93 AuthFsm *GetAuthFsmByConnId(uint64_t connId, bool isServer); 94 void AuthSessionFsmExit(void); 95 96 #ifdef __cplusplus 97 #if __cplusplus 98 } 99 #endif 100 #endif 101 #endif /* AUTH_SESSION_H */ 102