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