• 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_CONNECTION_H
17 #define AUTH_CONNECTION_H
18 
19 #include "auth_common.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 typedef struct {
28     uint64_t connId;
29     AuthConnInfo connInfo;
30     bool fromServer;
31     AuthDataHead head;
32     uint32_t len;
33     uint8_t data[0];
34 } RepeatDeviceIdData;
35 
36 typedef struct {
37     void (*onConnectResult)(uint32_t requestId, uint64_t connId, int32_t result, const AuthConnInfo *connInfo);
38     void (*onDisconnected)(uint64_t connId, const AuthConnInfo *connInfo);
39     void (*onDataReceived)(
40         uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, const AuthDataHead *head, const uint8_t *data);
41 } AuthConnListener;
42 
43 typedef struct {
44     int32_t fd;
45     int32_t ret;
46 } AuthConnectResult;
47 
48 int32_t AuthConnInit(const AuthConnListener *listener);
49 void AuthConnDeinit(void);
50 
51 int32_t ConnectAuthDevice(uint32_t requestId, const AuthConnInfo *connInfo, ConnSideType sideType);
52 void UpdateAuthDevicePriority(uint64_t connId);
53 void DisconnectAuthDevice(uint64_t *connId);
54 int32_t PostAuthData(uint64_t connId, bool toServer, const AuthDataHead *head, const uint8_t *data);
55 
56 ConnSideType GetConnSideType(uint64_t connId);
57 bool CheckActiveAuthConnection(const AuthConnInfo *connInfo);
58 
59 const char *GetConnTypeStr(uint64_t connId);
60 uint32_t GetConnId(uint64_t connId);
61 int32_t GetConnType(uint64_t connId);
62 int32_t GetFd(uint64_t connId);
63 uint64_t GenConnId(int32_t connType, int32_t id);
64 void UpdateFd(uint64_t *connId, int32_t id);
65 
66 uint32_t GetAuthDataSize(uint32_t len);
67 int32_t PackAuthData(const AuthDataHead *head, const uint8_t *data, uint8_t *buf, uint32_t size);
68 const uint8_t *UnpackAuthData(const uint8_t *data, uint32_t len, AuthDataHead *head);
69 int32_t GetConnInfoByConnectionId(uint32_t connectionId, AuthConnInfo *connInfo);
70 
71 void HandleRepeatDeviceIdDataDelay(uint64_t connId, const AuthConnInfo *connInfo, bool fromServer,
72     const AuthDataHead *head, const uint8_t *data);
73 
74 #define CONN_INFO         "conn=%{public}s:%{public}u"
75 #define CONN_DATA(connId) GetConnTypeStr(connId), GetConnId(connId)
76 
77 #ifdef __cplusplus
78 #if __cplusplus
79 }
80 #endif
81 #endif
82 #endif /* AUTH_CONNECTION_H */
83