WXK
2024-12-16 78e84fcf264afd731cd66c807d9fcb690fe12126
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
 *******************************************************************************
 * @FileName  : ll_defs.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-02-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
 
#ifndef LL_DEFS_H_
#define LL_DEFS_H_
 
/*** Version ***/
 
#define LL_VER_BT_CORE_SPEC_4_0     0x06    /*!< Bluetooth core specification 4.0 */
#define LL_VER_BT_CORE_SPEC_4_1     0x07    /*!< Bluetooth core specification 4.1 */
#define LL_VER_BT_CORE_SPEC_4_2     0x08    /*!< Bluetooth core specification 4.2 */
#define LL_VER_BT_CORE_SPEC_5_0     0x09    /*!< Bluetooth core specification 5.0 */
#define LL_VER_BT_CORE_SPEC_5_1     0x0A    /*!< Bluetooth core specification 5.1 */
#define LL_VER_BT_CORE_SPEC_5_2     0x0B    /*!< Bluetooth core specification 5.2 */
 
#define LL_COMPANY_ID_TELINK        0x0211  /*!< Telink Semi ltd.c */
#define LL_COMPANY_ID_PANCHIP       0x07D1  /*!< Panchip Semi ltd.c */
 
#define LL_VER_BT_CORE_SPEC         LL_VER_BT_CORE_SPEC_5_0
#define LL_COMPANY_ID               LL_COMPANY_ID_PANCHIP
 
/*!   Link state machine */
enum{
    LL_STATE_STANDBY = 0x00,
    LL_STATE_ADV     = 0x01,
    LL_STATE_SCAN    = 0x02,
    LL_STATE_INIT,
    LL_STATE_CONN,
    LL_STATE_EXT_ADV,
    LL_STATE_PERIODIC_ADV,
    LL_STATE_EXT_SCAN,
    LL_STATE_EXT_INIT,
 
#if ANT_EN
    LL_STATE_ANT,
#endif
};
 
/*** Common ***/
 
#define LL_RSSI_MIN                 -127    /*!< Minimum RSSI value. */
#define LL_RSSI_MAX                 20      /*!< Maximum RSSI value. */
#define LL_RSSI_NOT_AVAIL           127     /*!< RSSI is not available. */
 
#define LL_CRC_LEN                  3       /*!< CRC length. */
#define LL_AA_LEN                   4       /*!< Access address length. */
#define LL_PREAMBLE_LEN_1M          1       /*!< Preamble length (LE 1M PHY). */
#define LL_PREAMBLE_LEN_2M          2       /*!< Preamble length (LE 2M PHY). */
#define LL_PREAMBLE_LEN_CODED_BITS  10      /*!< Preamble length (LE Coded PHY). */
#define LL_CI_LEN_BITS              2       /*!< Coding indicator length (LE Coded PHY). */
#define LL_TERM1_LEN_BITS           3       /*!< TERM1 length (LE Coded PHY). */
#define LL_TERM2_LEN_BITS           3       /*!< TERM2 length (LE Coded PHY). */
 
#define LL_RAND_ADDR_TYPE_MASK      (uint64_t)(0xC00000000000)    /*!< BD Random Address type mask. */
#define LL_RAND_ADDR_TYPE_STATIC    (uint64_t)(0xC00000000000)    /*!< Static Random Address type. */
#define LL_RAND_ADDR_TYPE_RPA       (uint64_t)(0x400000000000)    /*!< Resolvable Private Address type. */
#define LL_RAND_ADDR_TYPE_NRPA      (uint64_t)(0x000000000000)    /*!< Non-Resolvable Private Address type. */
 
/*** Advertising PDU ***/
 
/*!  Advertising channel PDU types. */
enum
{
  /* --- Core Spec 4.0 --- */
  LL_PDU_ADV_IND                = 0,    /*!< Connectable undirected advertising PDU. */
  LL_PDU_ADV_DIRECT_IND         = 1,    /*!< Connectable directed advertising PDU. */
  LL_PDU_ADV_NONCONN_IND        = 2,    /*!< Non-connectable undirected advertising PDU. */
  LL_PDU_SCAN_REQ               = 3,    /*!< Scan request PDU. */
  LL_PDU_SCAN_RSP               = 4,    /*!< Scan response PDU. */
  LL_PDU_CONNECT_IND            = 5,    /*!< Connect indication PDU. */
  LL_PDU_ADV_SCAN_IND           = 6,    /*!< Scannable undirected advertising PDU. */
 
  /* --- Core Spec 5.0 --- */
  LL_PDU_AUX_SCAN_REQ           = 3,    /*!< Auxiliary scan request PDU. */
  LL_PDU_AUX_CONNECT_REQ        = 5,    /*!< Auxiliary connect request PDU. */
  LL_PDU_ADV_EXT_IND            = 7,    /*!< Extended advertising PDU. */
  LL_PDU_AUX_ADV_IND            = 7,    /*!< Auxiliary advertising PDU. */
  LL_PDU_AUX_SCAN_RSP           = 7,    /*!< Auxiliary scan response PDU. */
  LL_PDU_AUX_SYNC_IND           = 7,    /*!< Auxiliary synchronize PDU. */
  LL_PDU_AUX_CHAIN_IND          = 7,    /*!< Auxiliary chain PDU. */
  LL_PDU_AUX_CONNECT_RSP        = 8,    /*!< Auxiliary connect response PDU. */
};
 
#define LL_SCAN_REQ_PLD_LEN     12      /*!< Size of a scan request payload. */
#define LL_CONN_IND_PLD_LEN     34      /*!< Size of a connect indication payload. */
 
#define LL_ADV_DATA_MAX_LEN     31      /*!< Maximum advertising channel host data length. */
#define LL_ADV_PLD_MAX_LEN      37      /*!< Maximum advertising channel Payload length. */
#define LL_ADV_PDU_MAX_LEN      39      /*!< Maximum advertising channel PDU length. */
 
#define LL_CHAN_ADV_MIN_IDX     37      /*!< Minimum advertising channel index. */
#define LL_CHAN_ADV_MAX_IDX     39      /*!< Maximum advertising channel index. */
#define LL_NUM_CHAN_ADV         3       /*!< Total number of advertising channels. */
 
 
#define LL_ADV_ACCESS_ADDR      (0x8E89BED6)    /*!< Advertising channel access address. */
#define LL_ADV_CRC_INIT         (0x555555)      /*!< Advertising CRC initial value. */
 
#define LL_DIR_ADV_INTER_TICKS  6       /*!< Advertising interval between directed advertising events (3.75 ms). */
#define LL_DIR_ADV_DUR_TICKS    2048    /*!< Maximum high duty cycle directed advertising duration (1.28 seconds). */
 
/* Extended Header field length */
#define LL_EXT_HDR_FLAGS_LEN    1
#define LL_CTE_INFO_LEN         1
#define LL_ADI_LEN              2
#define LL_AUX_PTR_LEN          3
#define LL_SYNC_INFO_LEN        18
#define LL_TX_PWR_LEN           1
 
/*** Data PDU ***/
 
/*!  Data channel LL Control PDU types. */
enum
{
  /* --- Core Spec 4.0 --- */
  LL_PDU_CONN_UPDATE_IND        = 0x00, /*!< Connection update indication PDU. */
  LL_PDU_CHANNEL_MAP_IND        = 0x01, /*!< Channel map indication PDU. */
  LL_PDU_TERMINATE_IND          = 0x02, /*!< Terminate indication PDU. */
  LL_PDU_ENC_REQ                = 0x03, /*!< Encryption request PDU. */
  LL_PDU_ENC_RSP                = 0x04, /*!< Encryption response PDU. */
  LL_PDU_START_ENC_REQ          = 0x05, /*!< Start encryption request PDU. */
  LL_PDU_START_ENC_RSP          = 0x06, /*!< Start encryption response PDU. */
  LL_PDU_UNKNOWN_RSP            = 0x07, /*!< Unknown response PDU. */
  LL_PDU_FEATURE_REQ            = 0x08, /*!< Feature request PDU. */
  LL_PDU_FEATURE_RSP            = 0x09, /*!< Feature response PDU. */
  LL_PDU_PAUSE_ENC_REQ          = 0x0A, /*!< Pause encryption request PDU. */
  LL_PDU_PAUSE_ENC_RSP          = 0x0B, /*!< Pause encryption response PDU. */
  LL_PDU_VERSION_IND            = 0x0C, /*!< Version indication PDU. */
  LL_PDU_REJECT_IND             = 0x0D, /*!< Reject indication PDU. */
  /* --- Core Spec 4.2 --- */
  LL_PDU_SLV_FEATURE_REQ        = 0x0E, /*!< Slave feature request PDU. */
  LL_PDU_CONN_PARAM_REQ         = 0x0F, /*!< Connection parameter request PDU. */
  LL_PDU_CONN_PARAM_RSP         = 0x10, /*!< Connection parameter response PDU. */
  LL_PDU_REJECT_EXT_IND         = 0x11, /*!< Reject extended indication PDU. */
  LL_PDU_PING_REQ               = 0x12, /*!< Ping request PDU. */
  LL_PDU_PING_RSP               = 0x13, /*!< Ping response PDU. */
  LL_PDU_LENGTH_REQ             = 0x14, /*!< Data length request PDU. */
  LL_PDU_LENGTH_RSP             = 0x15, /*!< Data length response PDU. */
 
  /* --- Core Spec 5.0 --- */
  LL_PDU_PHY_REQ                = 0x16, /*!< PHY request PDU. */
  LL_PDU_PHY_RSP                = 0x17, /*!< PHY response PDU. */
  LL_PDU_PHY_UPDATE_IND         = 0x18, /*!< PHY update indication PDU. */
  LL_PDU_MIN_USED_CHAN_IND      = 0x19, /*!< Minimum used channels indication PDU. */
 
  LL_PDU_UNSPECIFIED            = 0xFF  /*!< Unspecified PDU. */
};
 
/* Data Payload length */
/* --- Core Spec 4.0 --- */
#define LL_CONN_UPD_IND_PLD_LEN       12      /*!< Connection update indication PAYLAOD length. */
#define LL_CHAN_MAP_IND_PLD_LEN       8       /*!< Channel map indication PAYLAOD length. */
#define LL_TERMINATE_IND_PLD_LEN      2       /*!< Terminate indication PAYLAOD length. */
#define LL_ENC_REQ_LEN                23      /*!< Encryption request PAYLAOD length. */
#define LL_ENC_RSP_LEN                13      /*!< Encryption response PAYLAOD length. */
#define LL_START_ENC_LEN              1       /*!< Start encryption request/response PAYLAOD length. */
#define LL_UNKNOWN_RSP_LEN            2       /*!< Unknown response PAYLAOD length. */
#define LL_FEATURE_PLD_LEN            9       /*!< Feature request/response PAYLAOD length. */
#define LL_PAUSE_ENC_LEN              1       /*!< Pause encryption request/response PAYLAOD length. */
#define LL_VERSION_IND_PLD_LEN        6       /*!< Version indication PAYLAOD length. */
#define LL_REJECT_IND_PLD_LEN         2       /*!< Reject indication PAYLAOD length. */
/* --- Core Spec 4.2 --- */
#define LL_CONN_PARAM_PLD_LEN         24      /*!< Connection parameter request or response PAYLAOD length. */
#define LL_REJECT_EXT_IND_PLD_LEN     3       /*!< Reject extended indication PAYLAOD length. */
#define LL_PING_PLD_LEN               1       /*!< Ping request/response PAYLAOD length. */
#define LL_DATA_LEN_PLD_LEN           9       /*!< Data length request or response PAYLAOD length. */
/* --- Core Spec 5.0 --- */
#define LL_PHY_PLD_LEN                3       /*!< PHY request/response PAYLAOD length. */
#define LL_PHY_UPD_IND_PLD_LEN        5       /*!< PHY update indication PAYLAOD length. */
#define LL_MIN_USED_CHAN_PLD_LEN      3       /*!< Minimum used channels indication PAYLAOD length. */
 
 
#define LL_EMPTY_PDU_LEN              2       /*!< Length of an empty data PDU. */
 
#define LL_DATA_HDR_LEN               2       /*!< Data channel header length. */
#define LL_DATA_MIC_LEN               4       /*!< Data channel PDU MIC length. */
 
#define LL_MAX_DATA_CHN_NUM           37      /*!< Maximum number of used data channels. */
#define LL_MIN_DATA_CHN_NUM           2       /*!< Minimum number of used data channels. */
 
 
/*!  Data PDU LLID types. */
enum
{
  LL_LLID_VS_PDU                = 0x00, /*!< Vendor specific PDU. */
 
  /* N.B. next two enumerations intentionally use identical values. */
  LL_LLID_EMPTY_PDU             = 0x01, /*!< Empty PDU. */
  LL_LLID_CONT_PDU              = 0x01, /*!< Data PDU: continuation fragment of an L2CAP message. */
  LL_LLID_START_PDU             = 0x02, /*!< Data PDU: start of an L2CAP message or a complete L2CAP message with no fragmentation. */
  LL_LLID_CTRL_PDU              = 0x03, /*!< Control PDU. */
};
 
#define LL_PB_START_H2C          0x00  /*!< Packet boundary flag, start, host-to-controller */
#define LL_PB_CONTINUE           0x01  /*!< Packet boundary flag, continue */
#define LL_PB_START_C2H          0x02  /*!< Packet boundary flag, start, controller-to-host */
 
 
/*** Feature ***/
 
#define LL_FEAT_LEN                   8       /*!< Length of features byte array */
 
/*** Encryption ***/
 
#define LL_ECC_KEY_LEN                32      /*!< ECC key length. */
#define LL_RAND_LEN                   8       /*!< Length of random number */
#define LL_KEY_LEN                    16      /*!< Encryption key length. */
#define LL_SKD_LEN                    LL_KEY_LEN      /*!< Session key diversifier length. */
#define LL_IV_LEN                     8       /*!< Initialization vector length. */
#define LL_NONCE_LEN                  13      /*!< Nonce length. */
 
#define LL_DEF_RES_ADDR_TO_SEC        900     /*!< Default resolvable address timeout in seconds. */
#define LL_DEF_AUTH_TO_MS             30000   /*!< Default authentication timeout in milliseconds. */
 
/*** LLCP ***/
 
/*!   Data Channel PDU format = Header + Payload + MIC (1M PHY = 1us/per bit) */
#define LL_MAX_TX_RX_TIME_1M(payload)              (uint16_t)((10 + (payload) + 4)<<3)
#define LL_MAX_TX_RX_TIME_2M(payload)              (uint16_t)((10 + (payload) + 4)<<2)
#define LL_MAX_TX_RX_TIME_CODED(payload, phyOpt)   (uint16_t)(80+256+16+24 + (2+payload+4+3)*8*(phyOpt<<phyOpt) + 3*(phyOpt<<phyOpt))
#define LL_MAX_TX_RX_TIME_CODED_S2(payload)        (uint16_t)(80+256+16+24 + (2+payload+4+3)*8*2 + 3*2)
#define LL_MAX_TX_RX_TIME_CODED_S8(payload)        (uint16_t)(80+256+16+24 + (2+payload+4+3)*8*8 + 3*8)
 
#define LL_TIME_TO_OCTETS_1M(time)                 (uint16_t)(((time) - 112)>>3)
#define LL_TIME_TO_OCTETS_2M(time)                 (uint16_t)(((time) - 56)>>2)
#define LL_TIME_TO_OCTETS_CODED_S2(time)           (uint16_t)((((time) - 382)>>4) - 9)
#define LL_TIME_TO_OCTETS_CODED_S8(time)           (uint16_t)((((time) - 400)>>6) - 9)
 
/*!   Link default MAX Tx Octets and time. PHY = 1MHz */
#define LL_DEF_MAX_TX_OCTETS          27
#define LL_DEF_MAX_TX_TIME_1M         LL_MAX_TX_RX_TIME_1M(LL_DEF_MAX_TX_OCTETS)
 
/*!  Link default MAX rx Octets and time. PHY = 1MHz */
#define LL_DEF_MAX_RX_OCTETS          27
#define LL_DEF_MAX_RX_TIME_1M         LL_MAX_TX_RX_TIME_1M(LL_DEF_MAX_RX_OCTETS)
 
#define LL_SUP_MIN_TX_RX_OCTETS       27  /*!< Link supported Min RX/TX payload size */
#define LL_SUP_MAX_TX_RX_OCTETS       251 /*!< Link supported Max RX/TX payload size */
 
#define LL_MIN_TX_WIN_SIZE            1       /*!< Minimum value for transmit window size. */
#define LL_MAX_TX_WIN_SIZE            8       /*!< Maximum value for transmit window size. */
 
#define LL_MIN_CONN_INTERVAL          6       /*!< Minimum value for connection interval. */
#define LL_MAX_CONN_INTERVAL          3200    /*!< Maximum value for connection interval. */
 
#define LL_MAX_CONN_LATENCY           499     /*!< Maximum value for connection slave latency. */
 
#define LL_MIN_SUP_TIMEOUT            10      /*!< Minimum value for connection supervision timeout. */
#define LL_MAX_SUP_TIMEOUT            3200    /*!< Maximum value for connection supervision timeout. */
 
#define LL_CHAN_MAP_LEN               5       /*!< Channel map length */
#define LL_CHAN_MAP_MASK              0x1FFFFFFFFF
 
#endif /* BLC_DEFS_H_ */