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 "common_list.h" 26 #include "lnn_node_info.h" 27 #include "lnn_state_machine.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif 33 #endif 34 35 #define AUTH_FSM_NAME_LEN 32 36 37 typedef struct { 38 uint32_t requestId; 39 bool isServer; 40 uint64_t connId; 41 AuthConnInfo connInfo; 42 uint8_t *deviceInfoData; 43 uint32_t deviceInfoDataLen; 44 NodeInfo nodeInfo; 45 bool isNodeInfoReceived; 46 bool isCloseAckReceived; 47 char udid[UDID_BUF_LEN]; 48 char uuid[UUID_BUF_LEN]; 49 SoftBusVersion version; 50 } AuthSessionInfo; 51 52 typedef struct { 53 ListNode node; 54 uint32_t id; 55 int64_t authSeq; 56 char fsmName[AUTH_FSM_NAME_LEN]; 57 FsmStateMachine fsm; 58 AuthSessionInfo info; 59 bool isDead; 60 } AuthFsm; 61 62 int32_t AuthSessionStartAuth(int64_t authSeq, uint32_t requestId, 63 uint64_t connId, const AuthConnInfo *connInfo, bool isServer); 64 int32_t AuthSessionProcessDevIdData(int64_t authSeq, const uint8_t *data, uint32_t len); 65 int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t len); 66 int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_t len); 67 int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size); 68 int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len); 69 int32_t AuthSessionHandleAuthResult(int64_t authSeq, int32_t reason); 70 int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint32_t len); 71 int32_t AuthSessionProcessCloseAck(int64_t authSeq, const uint8_t *data, uint32_t len); 72 int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len); 73 int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len); 74 int32_t AuthSessionHandleDeviceNotTrusted(const char *udid); 75 int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId); 76 77 void AuthSessionFsmExit(void); 78 79 #ifdef __cplusplus 80 #if __cplusplus 81 } 82 #endif 83 #endif 84 #endif /* AUTH_SESSION_H */ 85