• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2022-2025 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_COMMON_STRUCT_H
17 #define AUTH_COMMON_STRUCT_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #include "auth_interface_struct.h"
23 #include "softbus_common.h"
24 #include "softbus_conn_interface_struct.h"
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 typedef enum {
33    /* data type for device authentication */
34    DATA_TYPE_AUTH = 0xFFFF0001,
35    /* data type for synchronizing peer device information */
36    DATA_TYPE_DEVICE_INFO = 0xFFFF0002,
37    /* data type for synchronizing peer device id */
38    DATA_TYPE_DEVICE_ID = 0xFFFF0003,
39    /* data type for connection */
40    DATA_TYPE_CONNECTION = 0xFFFF0004,
41    /* data type for closing ack */
42    DATA_TYPE_CLOSE_ACK = 0xFFFF0005,
43    /* data type for meta negotiation */
44    DATA_TYPE_META_NEGOTIATION = 0xFFFF0006,
45    /* data type for decrypt fail */
46    DATA_TYPE_DECRYPT_FAIL = 0xFFFF0007,
47    /* data type for info ack */
48    DATA_TYPE_META_DEVICE_INFO_ACK = 0xFFFF0008,
49    /* data type for cancel auth */
50    DATA_TYPE_CANCEL_AUTH = 0xFFFF0009,
51    /* data type for uk connection */
52    DATA_TYPE_APPLY_KEY_CONNECTION = 0xFFFF0010,
53 } AuthDataType;
54 
55 #define CLIENT_SIDE_FLAG 0
56 #define SERVER_SIDE_FLAG 1
57 
58 #define CHECK_NULL_PTR_RETURN_VOID(item) \
59 if ((item) == NULL) { \
60    return; \
61 }
62 
63 #define CHECK_NULL_PTR_RETURN_VALUE(item, value) \
64 if ((item) == NULL) { \
65    return value; \
66 }
67 
68 #define CHECK_EXPRESSION_RETURN_VOID(expression) \
69 if (expression) { \
70    return; \
71 }
72 
73 #define CHECK_EXPRESSION_RETURN_VALUE(expression, value) \
74 if (expression) { \
75    return value; \
76 }
77 
78 #define SEQ_INTERVAL 2
79 #define BYTES_BIT_NUM 8
80 #define INT32_BIT_NUM 32
81 #define INT32_MASK 0xFFFFFFFF
82 #define MASK_UINT64_L32 0x00000000FFFFFFFF
83 #define MASK_UINT64_H32 0xFFFFFFFF00000000
84 #define AUTH_REQUEST_TIMTOUR 30000
85 /* ble network advdata take 8 bytes of UDID hash */
86 #define SHORT_HASH_LEN 8
87 
88 #define SOFTBUS_SUB_SYSTEM 203
89 #define SOFTBUS_AUTH_MODULE 3
90 #define SOFTBUS_HICHAIN_MAX (-((SOFTBUS_SUB_SYSTEM << 21) | (SOFTBUS_AUTH_MODULE << 16) | 0x0001))
91 #define SOFTBUS_HICHAIN_MIN (-((SOFTBUS_SUB_SYSTEM << 21) | (SOFTBUS_AUTH_MODULE << 16) | 0x10FF))
92 
93 #define TO_INT32(value) ((int32_t)(((uint32_t)(value)) & INT32_MASK))
94 #define TO_UINT32(value) ((uint32_t)(((uint32_t)(value)) & INT32_MASK))
95 
96 typedef struct {
97    uint32_t dataType;
98    int32_t module;
99    int64_t seq;
100    int32_t flag;
101    uint32_t len;
102 } AuthDataHead;
103 
104 typedef struct {
105    int32_t magic;
106    int32_t module;
107    int64_t seq;
108    int32_t flag;
109    uint32_t len;
110 } SocketPktHead;
111 
112 typedef struct {
113    void (*onDataReceived)(AuthHandle authHandle, const AuthDataHead *head, const uint8_t *data, uint32_t len);
114    void (*onDisconnected)(AuthHandle authHandle);
115    void (*onException)(AuthHandle authHandle, int32_t error);
116 } AuthTransCallback;
117 
118 /* Auth handler */
119 typedef enum {
120    EVENT_CONNECT_CMD,
121    EVENT_CONNECT_RESULT,
122    EVENT_CONNECT_TIMEOUT,
123    EVENT_UPDATE_SESSION_KEY,
124    EVENT_AUTH_META_TIMEOUT,
125    EVENT_AUTH_DISCONNECT,
126    EVENT_BLE_DISCONNECT_DELAY,
127    EVENT_AUTH_META_SYNC_PTK_TIMEOUT,
128 } EventType;
129 typedef void(*EventHandler)(const void *obj);
130 typedef int(*RemoveCompareFunc)(const void *obj, void *param);
131 
132 #ifdef __cplusplus
133 #if __cplusplus
134 }
135 #endif
136 #endif
137 #endif /* AUTH_COMMON_STRUCT_H */