ll_def.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. #ifndef LL_DEF_H_
  29. #define LL_DEF_H_
  30. #include "types.h"
  31. #include "comdef.h"
  32. #include "ll_buf.h"
  33. #include "ll.h"
  34. #define MAX_NUM_LL_CONN 1
  35. #define LL_PKT_PREAMBLE_LEN 1
  36. #define LL_PKT_SYNCH_LEN 4
  37. #define LL_PKT_LLID_LEN 1
  38. #define LL_PKT_HDR_LEN 2
  39. #define LL_PKT_MIC_LEN 4
  40. #define LL_PKT_CRC_LEN 3
  41. #define LL_DATA_PDU_HDR_LLID_RESERVED 0
  42. #define LL_DATA_PDU_HDR_LLID_DATA_PKT_NEXT 1
  43. #define LL_DATA_PDU_HDR_LLID_DATA_PKT_FIRST 2
  44. #define LL_DATA_PDU_HDR_LLID_CONTROL_PKT 3
  45. ///adv header shift and mask
  46. #define PDU_TYPE_SHIFT 0
  47. #define PDU_TYPE_MASK 0xf
  48. #define TX_ADD_SHIFT 6
  49. #define TX_ADD_MASK 0x40
  50. #define RX_ADD_SHIFT 7
  51. #define RX_ADD_MASK 0x80
  52. #define LENGTH_SHIFT 8
  53. #define LENGTH_MASK 0x3f00
  54. // macro for bit operations
  55. #define SET_BITS(p,f,l,m) p=(f<<l) | (p & (~m))
  56. #define GET_BITS(p,l,m) (p&m)>>l
  57. // Receive Flow Control
  58. #define LL_RX_FLOW_CONTROL_DISABLED 0
  59. #define LL_RX_FLOW_CONTROL_ENABLED 1
  60. //LL packet type
  61. #define ADV_IND 0 //Connectable Undirected Event
  62. #define ADV_DIRECT_IND 1 //Connectable Directed Event
  63. #define ADV_NONCONN_IND 2 //Non-connectable Undirected Event
  64. #define ADV_SCAN_REQ 3
  65. #define ADV_SCAN_RSP 4
  66. #define ADV_CONN_REQ 5
  67. #define ADV_SCAN_IND 6 //Scannable Undirected Event
  68. // LL state defines
  69. #define LL_STATE_IDLE 0x00
  70. #define LL_STATE_ADV_UNDIRECTED 0x01
  71. #define LL_STATE_ADV_DIRECTED 0x02
  72. #define LL_STATE_ADV_SCAN 0x03
  73. #define LL_STATE_ADV_NONCONN 0x04
  74. #define LL_STATE_SCAN 0x05
  75. #define LL_STATE_INIT 0x06
  76. #define LL_STATE_CONN_SLAVE 0x07
  77. #define LL_STATE_CONN_MASTER 0x08
  78. #define LL_STATE_DIRECT_TEST_MODE_TX 0x09
  79. #define LL_STATE_DIRECT_TEST_MODE_RX 0x0A
  80. #define LL_STATE_MODEM_TEST_TX 0x0B
  81. #define LL_STATE_MODEM_TEST_RX 0x0C
  82. #define LL_STATE_MODEM_TEST_TX_FREQ_HOPPING 0x0D
  83. // =============== add in A2 for simultaneous slave and adv/scan
  84. #define LL_SEC_STATE_IDLE 0x00
  85. #define LL_SEC_STATE_SCAN 0x01
  86. #define LL_SEC_STATE_ADV 0x02
  87. #define LL_SEC_STATE_SCAN_PENDING 0x03
  88. #define LL_SEC_STATE_ADV_PENDING 0x04
  89. #define LL_SEC_STATE_IDLE_PENDING 0x05
  90. // ===== A2 End
  91. //LL connecction control type
  92. #define LL_CONNECTION_UPDATE_REQ 0
  93. #define LL_CHANNEL_MAP_REQ 1
  94. #define LL_TERMINATE_IND 2
  95. #define LL_ENC_REQ 3
  96. #define LL_ENC_RSP 4
  97. #define LL_START_ENC_REQ 5
  98. #define LL_START_ENC_RSP 6
  99. #define LL_UNKNOWN_RSP 7
  100. #define LL_FEATURE_REQ 8
  101. #define LL_FEATURE_RSP 9
  102. #define LL_PAUSE_ENC_REQ 10
  103. #define LL_PAUSE_ENC_RSP 11
  104. #define LL_VERSION_IND 12
  105. #define LL_REJECT_IND 13
  106. #define LL_SLAVE_FEATURE_REQ 14
  107. #define LL_CONNECTION_PARAM_REQ 15
  108. #define LL_CONNECTION_PARAM_RSP 16
  109. #define LL_REJECT_IND_EXT 17
  110. #define LL_PING_REQ 18
  111. #define LL_PING_RSP 19
  112. #define LL_LENGTH_REQ 20
  113. #define LL_LENGTH_RSP 21
  114. #define LL_PHY_REQ 22
  115. #define LL_PHY_RSP 23
  116. #define LL_PHY_UPDATE_IND 24
  117. #define LL_CONNECT_REQ_PAYLOAD_LEN 18
  118. #define LL_CONN_UPDATE_REQ_PAYLOAD_LEN 12
  119. #define LL_CHAN_MAP_REQ_PAYLOAD_LEN 8
  120. #define LL_TERM_IND_PAYLOAD_LEN 2
  121. #define LL_ENC_REQ_PAYLOAD_LEN 23
  122. #define LL_ENC_RSP_PAYLOAD_LEN 13
  123. #define LL_START_ENC_REQ_PAYLOAD_LEN 1
  124. #define LL_START_ENC_RSP_PAYLOAD_LEN 1
  125. #define LL_PAUSE_ENC_REQ_PAYLOAD_LEN 1
  126. #define LL_PAUSE_ENC_RSP_PAYLOAD_LEN 1
  127. #define LL_REJECT_IND_PAYLOAD_LEN 2
  128. #define LL_REJECT_EXT_IND_PAYLOAD_LEN 3
  129. #define LL_FEATURE_REQ_PAYLOAD_LEN 9
  130. #define LL_FEATURE_RSP_PAYLOAD_LEN 9
  131. #define LL_VERSION_IND_PAYLOAD_LEN 6
  132. #define LL_UNKNOWN_RSP_PAYLOAD_LEN 2
  133. #define LL_LENGTH_REQ_PAYLOAD_LEN 9
  134. #define LL_LENGTH_RSP_PAYLOAD_LEN 9
  135. #define LL_PHY_REQ_PAYLOAD_LEN 3
  136. #define LL_PHY_RSP_PAYLOAD_LEN 3
  137. #define LL_PHY_UPDATE_IND_PAYLOAD_LEN 5
  138. #define LL_MAX_NUM_CTRL_PROC_PKTS 4
  139. #define LL_CTRL_UNDEFINED_PKT 0xFF
  140. // LL Events
  141. #define LL_EVT_POST_PROCESS_NR 0x0001
  142. #define LL_EVT_DIRECTED_ADV_FAILED 0x0002
  143. #define LL_EVT_SLAVE_CONN_CREATED 0x0004
  144. #define LL_EVT_NEXT_INTERVAL 0x0008
  145. #define LL_EVT_MASTER_CONN_CANCELLED 0x0010
  146. #define LL_EVT_TASK_TIMER_FENCE_EXPIRED 0x0020
  147. #define LL_EVT_SLAVE_CONN_CREATED_BAD_PARAM 0x0040
  148. #define LL_EVT_START_32KHZ_XOSC_DELAY 0x0080
  149. #define LL_EVT_32KHZ_XOSC_DELAY 0x0100
  150. #define LL_EVT_RESET_SYSTEM_HARD 0x0200
  151. #define LL_EVT_RESET_SYSTEM_SOFT 0x0400
  152. #define LL_EVT_MASTER_CONN_CREATED 0x0800
  153. #define LL_EVT_SECONDARY_SCAN 0x1000
  154. #define LL_EVT_SECONDARY_ADV 0x2000
  155. #define LL_ADV_NONCONN_STATE 0x00
  156. #define LL_ADV_DISCOV_STATE 0x01
  157. #define LL_ADV_UNDIRECT_STATE 0x02
  158. #define LL_ADV_HDC_DIRECT_STATE 0x03
  159. #define LL_SCAN_PASSIVE_STATE 0x04
  160. #define LL_SCAN_ACTIVE_STATE 0x05
  161. #define LL_INIT_STATE 0x06 // connection state in master role also supported
  162. #define LL_SLAVE_STATE 0x07
  163. //
  164. #define LL_ADV_NONCONN_SCAN_PASSIVE_STATE 0x10
  165. #define LL_ADV_DISCOV_SCAN_PASSIVE_STATE 0x11
  166. #define LL_ADV_UNDIRECT_SCAN_PASSIVE_STATE 0x12
  167. #define LL_ADV_HDC_DIRECT_SCAN_PASSIVE_STATE 0x13
  168. #define LL_ADV_NONCONN_SCAN_ACTIVE_STATE 0x14
  169. #define LL_ADV_DISCOV_SCAN_ACTIVE_STATE 0x15
  170. #define LL_ADV_UNDIRECT_SCAN_ACTIVE_STATE 0x16
  171. #define LL_ADV_HDC_DIRECT_SCAN_ACTIVE_STATE 0x17
  172. //
  173. #define LL_ADV_NONCONN_INIT_STATE 0x20
  174. #define LL_ADV_DISCOV_INIT_STATE 0x21
  175. #define LL_ADV_NONCONN_MASTER_STATE 0x22
  176. #define LL_ADV_DISCOV_MASTER_STATE 0x23
  177. #define LL_ADV_NONCONN_SLAVE_STATE 0x24
  178. #define LL_ADV_DISCOV_SLAVE_STATE 0x25
  179. #define LL_SCAN_PASSIVE_INIT_STATE 0x26
  180. #define LL_SCAN_ACTIVE_INIT_STATE 0x27
  181. //
  182. #define LL_SCAN_PASSIVE_MASTER_STATE 0x30
  183. #define LL_SCAN_ACTIVE_MASTER_STATE 0x31
  184. #define LL_SCAN_PASSIVE_SLAVE_STATE 0x32
  185. #define LL_SCAN_ACTIVE_SLAVE_STATE 0x33
  186. #define LL_INIT_MASTER_STATE 0x34 // master role and master role combination also supported
  187. //
  188. #define LL_ADV_LDC_DIRECT_STATE 0x35
  189. #define LL_ADV_LDC_DIRECT_SCAN_PASSIVE_STATE 0x36
  190. #define LL_ADV_LDC_DIRECT_SCAN_ACTIVE_STATE 0x37
  191. #define HCI_RX_PKT_HDR_SIZE 5
  192. #define LL_NUM_BYTES_FOR_CHAN_MAP 5 //(LL_MAX_NUM_ADV_CHAN+LL_MAX_NUM_DATA_CHAN)/sizeof(uint8)
  193. #define LL_CTRL_PROC_STATUS_SUCCESS 0
  194. #define LL_CTRL_PROC_STATUS_TERMINATE 1
  195. #define LL_TX_DATA_CONTEXT_POST_PROCESSING 2
  196. #define LL_TX_DATA_CONTEXT_SEND_DATA 0
  197. #define LL_LINK_SETUP_TIMEOUT 5 // 6 connection intervals (i.e. 0..5)
  198. // Setup Next Slave Procedure Actions
  199. #define LL_SETUP_NEXT_LINK_STATUS_SUCCESS 0
  200. #define LL_SETUP_NEXT_LINK_STATUS_TERMINATE 1
  201. // Data PDU Control Packet Types
  202. #define LL_CTRL_CONNECTION_UPDATE_REQ 0 // M
  203. #define LL_CTRL_CHANNEL_MAP_REQ 1 // M
  204. #define LL_CTRL_TERMINATE_IND 2 // M, S
  205. #define LL_CTRL_ENC_REQ 3 // M
  206. #define LL_CTRL_ENC_RSP 4 // , S
  207. #define LL_CTRL_START_ENC_REQ 5 // , S
  208. #define LL_CTRL_START_ENC_RSP 6 // M, S
  209. #define LL_CTRL_UNKNOWN_RSP 7 // M, S
  210. #define LL_CTRL_FEATURE_REQ 8 // M
  211. #define LL_CTRL_FEATURE_RSP 9 // , S , also could be M in ver4.2 ... HZF
  212. #define LL_CTRL_PAUSE_ENC_REQ 10 // M
  213. #define LL_CTRL_PAUSE_ENC_RSP 11 // , S
  214. #define LL_CTRL_VERSION_IND 12 // M, S
  215. #define LL_CTRL_REJECT_IND 13 // , S
  216. // BLE 4.2
  217. #define LL_CTRL_SLAVE_FEATURE_REQ 14
  218. #define LL_CTRL_CONNECTION_PARAM_REQ 15
  219. #define LL_CTRL_CONNECTION_PARAM_RSP 16
  220. #define LL_CTRL_REJECT_EXT_IND 17
  221. #define LL_CTRL_PING_REQ 18
  222. #define LL_CTRL_PING_RSP 19
  223. #define LL_CTRL_LENGTH_REQ 20
  224. #define LL_CTRL_LENGTH_RSP 21
  225. // BLE 5.0
  226. #define LL_CTRL_PHY_REQ 22
  227. #define LL_CTRL_PHY_RSP 23
  228. #define LL_CTRL_PHY_UPDATE_IND 24
  229. #define LL_CTRL_MIN_USED_CHANNELS_IND 25
  230. #define LL_CTRL_TERMINATE_RX_WAIT_FOR_TX_ACK 26 // M (internal to LL only)
  231. // control procedure timeout in coarse timer ticks
  232. #define LL_MAX_CTRL_PROC_TIMEOUT 64000 // 40s
  233. // Encryption Related
  234. #define LL_ENC_RAND_LEN 8
  235. #define LL_ENC_EDIV_LEN 2
  236. #define LL_ENC_LTK_LEN 16
  237. #define LL_ENC_IV_M_LEN 4
  238. #define LL_ENC_IV_S_LEN 4
  239. #define LL_ENC_IV_LINK_LEN 4
  240. #define LL_ENC_IV_LEN (LL_ENC_IV_M_LEN + LL_ENC_IV_S_LEN)
  241. #define LL_ENC_SKD_M_LEN 8
  242. #define LL_ENC_SKD_S_LEN 8
  243. #define LL_ENC_SKD_LINK_LEN 8
  244. #define LL_ENC_SKD_LEN (LL_ENC_SKD_M_LEN + LL_ENC_SKD_S_LEN)
  245. #define LL_ENC_SK_LEN 16
  246. #define LL_ENC_NONCE_LEN 13
  247. #define LL_END_NONCE_IV_OFFSET 5
  248. #define LL_ENC_MIC_LEN LL_PKT_MIC_LEN
  249. //
  250. #define LL_ENC_IV_M_OFFSET LL_ENC_IV_S_LEN
  251. #define LL_ENC_IV_S_OFFSET 0
  252. #define LL_ENC_SKD_M_OFFSET LL_ENC_SKD_S_LEN
  253. #define LL_ENC_SKD_S_OFFSET 0
  254. //
  255. #define LL_ENC_BLOCK_LEN 16
  256. #define LL_ENC_CCM_BLOCK_LEN LL_ENC_BLOCK_LEN
  257. #define LL_ENC_BLOCK_B0_FLAGS 0x49
  258. #define LL_ENC_BLOCK_A0_FLAGS 0x01
  259. //////////////////// for scan
  260. // Scanner Advertisment Channels
  261. #define LL_SCAN_ADV_CHAN_37 37
  262. #define LL_SCAN_ADV_CHAN_38 38
  263. #define LL_SCAN_ADV_CHAN_39 39
  264. struct bd_addr{
  265. uint8_t addr[6];
  266. };
  267. typedef struct
  268. {
  269. uint8_t peerAddrType; // peer device address type of public or random
  270. uint8_t peerAddr[ 6 ]; // peer device address
  271. } peerInfo_t;
  272. /// Advertising parameters
  273. typedef struct
  274. {
  275. uint8_t active;
  276. uint16_t advInterval; // the advertiser interval, based on advIntMin and advIntMax
  277. /// Advertising type
  278. uint16_t advMode; // flag to indicate if currently advertising
  279. uint8_t ownAddrType; // own device address type of public or random
  280. uint8_t ownAddr[LL_DEVICE_ADDR_LEN]; // own device address
  281. uint8_t advChanMap; // saved Adv channel map; note, only lower three bits used
  282. uint8_t advEvtType; //connectable directed, undirected, discoverable, or non-connectable
  283. uint8_t wlPolicy; // white list policy for Adv
  284. uint16_t scaValue; // Slave SCA in PPM
  285. uint8_t advDataLen; // advertiser data length
  286. // Scan Repsonse Parameters
  287. uint8_t scanRspLen; // scan response data length
  288. // add by HZF
  289. uint8 advNextChan;
  290. }advInfo_t;
  291. ///////////////////////////////////////////////////////////
  292. // Scanner Event Parameters
  293. typedef struct
  294. {
  295. // taskInfo_t *llTask; // pointer to associated task block
  296. uint8 ownAddrType; // own device address type of public or random
  297. uint8 ownAddr[ LL_DEVICE_ADDR_LEN ]; // own device address
  298. uint8 initPending; // flag to indicate if Scan needs to be initialized
  299. uint8 scanMode; // flag to indicate if currently scanning
  300. uint8 scanType; // passive or active scan
  301. uint16 scanInterval; // the interval between scan events
  302. uint16 scanWindow; // the duration of a scan event
  303. uint8 wlPolicy; // white list policy for Scan
  304. uint8 filterReports; // flag to indicate if duplicate Adv packet reports are to be filtered
  305. uint16 scanBackoffUL; // backoff upper limit count
  306. uint8 nextScanChan; // advertising channel to be used by scanner
  307. uint8 numSuccess; // for adjusting backoff count by tracking successive successes
  308. uint8 numFailure; // for adjusting backoff count by tracking successive failures
  309. uint16 currentBackoff; // current back off count, uint16 because the upper limit is 256
  310. } scanInfo_t;
  311. /////////////////// Initiator Event Parameters
  312. typedef struct
  313. {
  314. uint8 ownAddrType; // own device address type of public or random
  315. uint8 ownAddr[ LL_DEVICE_ADDR_LEN ]; // own device address
  316. //
  317. uint8 initPending; // flag to indicate if Scan needs to be initialized
  318. uint8 scanMode; // flag to indicate if currently scanning
  319. uint16 scanInterval; // the interval between scan events
  320. uint16 scanWindow; // the duration of a scan event
  321. uint8 nextScanChan; // advertising channel to be used by scanner
  322. uint8 wlPolicy; // white list policy for Init
  323. uint8 connId; // allocated connection ID
  324. uint8 scaValue; // Master SCA as an ordinal value for PPM
  325. } initInfo_t;
  326. /////////////////////////////////////////////////////////////////
  327. typedef struct
  328. {
  329. uint8_t winSize; // window size
  330. uint16_t winOffset; // window offset
  331. uint16_t connInterval; // connection interval
  332. uint16_t slaveLatency; // number of connection events the slave can ignore
  333. uint16_t connTimeout; // supervision connection timeout
  334. } connParam_t;
  335. typedef struct
  336. {
  337. uint8_t verNum; // controller spec version
  338. uint16_t comId; // company identifier
  339. uint16_t subverNum; // implementation version
  340. } verInfo_t;
  341. typedef struct
  342. {
  343. uint8_t connId; // connection ID
  344. uint8_t termIndRcvd; // indicates a TERMINATE_IND was received
  345. uint8_t reason; // reason code to return to Host when connection finally ends
  346. } termInfo_t;
  347. // TX Data
  348. typedef struct txData_t
  349. {
  350. struct txData_t *pNext; // pointer to next Tx data entry on queue
  351. } txData_t;
  352. // Data Packet Queue
  353. typedef struct
  354. {
  355. txData_t *head; // pointer to head of queue
  356. txData_t *tail; // pointer to tail of queue
  357. } llDataQ_t;
  358. // Version Information Exchange
  359. typedef struct
  360. {
  361. uint8_t peerInfoValid; // flag to indicate the peer's version information is valid
  362. uint8_t hostRequest; // flag to indicate the host has requested the peer's version information
  363. uint8_t verInfoSent; // flag to indicate this device's version information has been sent
  364. } verExchange_t;
  365. // Feature Set Data
  366. typedef struct
  367. {
  368. uint8_t featureRspRcved; // flag to indicate the Feature Request has been responded to
  369. uint8_t featureSet[ 8 ];
  370. } featureSet_t;
  371. // Channel Map
  372. typedef struct
  373. {
  374. uint8_t chanMap[ 5 ]; // bit map corresponding to the data channels 0..39
  375. } chanMap_t;
  376. // Control Procedure Information
  377. typedef struct
  378. {
  379. uint8_t ctrlPktActive; // flag that indicates a control packet is being processed
  380. uint8_t ctrlPkts[ LL_MAX_NUM_CTRL_PROC_PKTS ]; // queue of control packets to be processed
  381. uint8_t ctrlPktCount; // number of queued control packets
  382. uint16_t ctrlTimeoutVal; // timeout in CI events for control procedure for this connection
  383. uint16_t ctrlTimeout; // timeout counter in CI events for control procedure
  384. } ctrlPktInfo_t;
  385. // for timer drift adjust
  386. typedef struct
  387. {
  388. uint32 coarse; // number of 625us ticks at SFD capture
  389. uint16 fine; // number of 31.25ns ticks at SFD capture
  390. } sysTime_t;
  391. // Encryption
  392. typedef struct
  393. {
  394. // Note: IV and SKD provide enough room for the full IV and SKD. When the
  395. // Master and Slave values are provided, the result is one combined
  396. // (concatenated) value.
  397. uint8 IV[ LL_ENC_IV_LEN ]; // combined master and slave IV values concatenated
  398. uint8 SKD [ LL_ENC_SKD_LEN ]; // combined master and slave SKD values concatenated
  399. uint8 RAND[ LL_ENC_RAND_LEN ]; // random vector from Master
  400. uint8 EDIV[ LL_ENC_EDIV_LEN ]; // encrypted diversifier from Master
  401. uint8 nonce[ LL_ENC_NONCE_LEN ]; // current nonce with current IV value
  402. uint8 SK[ LL_ENC_SK_LEN ]; // session key derived from LTK and SKD
  403. uint8 LTK[ LL_ENC_LTK_LEN ]; // Long Term Key from Host
  404. uint8 SKValid; // flag that indicates the Session Key is valid
  405. uint8 LTKValid; // Long Term Key is valid
  406. uint32 txPktCount; // used for nonce formation during encryption (Note: 39 bits!)??
  407. uint32 rxPktCount; // used for nonce formation during encryption (Note: 39 bits!)??
  408. uint8 encRestart; // flag to indicate if an encryption key change took place
  409. uint8 encRejectErrCode; // error code for rejecting encryption request
  410. // ALT: COULD USE ONE VARIABLE AND STATES FOR THESE FLAGS; IF SO, THE
  411. // CONTROL PROCEDURE WOULD NEED TO BE REWORKED.
  412. uint8 startEncRspRcved; // flag to indicate the Start Request has been responded to
  413. uint8 pauseEncRspRcved; // flag to indicate the Pause Request has been responded to
  414. uint8 encReqRcved; // flag to indicate an Enc Req was received in a Enc Pause procedure
  415. uint8 startEncReqRcved; // flag to indicate the Start Request has been responded to
  416. uint8 rejectIndRcved; // flag to indicate the Start Encryption needs to be aborted
  417. } encInfo_t;
  418. // Packet Error Rate Information - General
  419. typedef struct
  420. {
  421. uint16 numPkts; // total number of packets
  422. uint16 numCrcErr; // total number of packets with CRC error
  423. uint16 numEvents; // total number of connection events
  424. uint16 numMissedEvts; // total number of missed connection events
  425. } perInfo_t;
  426. // Connection Data
  427. typedef struct
  428. {
  429. uint8_t rx_timeout; // ----- Phyplus
  430. uint8_t rx_crcok; // ----- Phyplus
  431. uint8_t active; // flag to indicate if this connection is active
  432. uint8_t connId; // connection ID
  433. uint8_t firstPacket; // flag to indicate when the first packet has been received. 0 means TURE, 1 means FALSE
  434. uint16_t currentEvent; // current event number
  435. uint16_t nextEvent; // next active event number
  436. uint16_t lastCurrentEvent;
  437. uint16_t expirationEvent; // event at which the LSTO has expired
  438. uint16_t expirationValue; // number of events to a LSTO expiration
  439. uint16_t scaFactor; // SCA factor for timer drift calculation
  440. uint32_t timerDrift; // saved timer drift adjustment to avoid recalc
  441. uint32_t accuTimerDrift; // accumulate timer drift
  442. // Connection Parameters
  443. uint32_t lastTimeToNextEvt; // the time to next event from the previous connection event
  444. uint8_t slaveLatencyAllowed; // flag to indicate slave latency is permitted
  445. uint16_t slaveLatency; // current slave latency; 0 means inactive
  446. uint8_t lastSlaveLatency; // last slave latency value used
  447. uint16_t slaveLatencyValue; // current slave latency value (when enabled)
  448. uint32_t accessAddr; // saved synchronization word to be used by Slave
  449. uint32_t initCRC; // connection CRC initialization value (24 bits)
  450. uint8_t sleepClkAccuracy; // peer's sleep clock accurracy; used by own device to determine timer drift
  451. connParam_t curParam;
  452. // current connection parameters
  453. // Channel Map
  454. uint8_t nextChan; // the channel for the next active connection event
  455. uint8_t currentChan; // the channel for the currently completed connection event
  456. uint8_t numUsedChans; // count of the number of usable data channels
  457. // uint8_t hopLength; // used for finding next data channel at next connection event
  458. uint8_t chanMapTable[LL_MAX_NUM_DATA_CHAN]; // current chan map table that is in use for this connection
  459. uint8_t chanMap[5];
  460. uint8_t hop;
  461. // TX Related
  462. uint8_t txDataEnabled; // flag that indicates whether data output is allowed
  463. llDataQ_t txDataQ; // queue of Tx Data packets
  464. // RX Related
  465. uint8_t rxDataEnabled; // flag that indicates whether data input is allowed
  466. uint8_t lastRssi; // last data packet RSSI received on this connection
  467. uint16_t foff; // A2 add, sync qualitiy indicator, estimated by rx BB
  468. uint8_t carrSens; // A2 add, estimated freq offset by rx BB ,foff-512-->[-512 511]KHz
  469. // Control Packet Information
  470. ctrlPktInfo_t ctrlPktInfo; // information for control procedure processing
  471. // Parameter Update Control Procedure
  472. uint8_t pendingParamUpdate; // flag to indicate connection parameter update is pending
  473. uint16_t paramUpdateEvent; // event count to indicate when to apply pending param update
  474. connParam_t paramUpdate; // update parameters
  475. // Channel Map Update Control Procedure
  476. uint8_t pendingChanUpdate; // flag to indicate connection channel map update is pending
  477. uint16 chanMapUpdateEvent; // event count to indicate when to apply pending chan map update
  478. // Encryption Data Control Procedure
  479. uint8 encEnabled; // flag to indicate that encryption is enabled for this connection
  480. encInfo_t encInfo; // structure that holds encryption related data
  481. // Feature Set
  482. featureSet_t featureSetInfo; // feature set for this connection
  483. // Version Information
  484. verExchange_t verExchange; // version information exchange
  485. verInfo_t verInfo; // peer version information
  486. // Termination Control Procedure
  487. termInfo_t termInfo; // structure that holds connection termination data
  488. // Unknnown Control Packet
  489. uint8 unknownCtrlType; // value of unknown control type
  490. // Packet Error Rate
  491. perInfo_t perInfo; // PER
  492. uint8_t isCollision;
  493. uint8_t rejectOpCode;
  494. ll_phy_update_ind_t phyUpdateInfo; // ll_phy update
  495. // Parameter Update Control Procedure
  496. uint8_t pendingPhyModeUpdate; // flag to indicate connection ll phy update is pending
  497. uint16_t phyModeUpdateEvent;
  498. uint8_t sn_nesn; // use to save last sn/nesn in new IC
  499. // for new IC
  500. uint8_t llMode; // for RTLP & TRLP loop, may need change the HW engine mode.
  501. int anchor_point_base_time; // do we need it?
  502. int anchor_point_fine_time; // do we need it?
  503. int next_event_base_time; // do we need it?
  504. int next_event_fine_time; // do we need it?
  505. } llConnState_t;
  506. typedef struct
  507. {
  508. // adv channel statistics
  509. int ll_send_undirect_adv_cnt;
  510. int ll_send_nonconn_adv_cnt;
  511. int ll_send_scan_adv_cnt;
  512. int ll_send_hdc_dir_adv_cnt;
  513. int ll_send_ldc_dir_adv_cnt;
  514. // adv in conn event
  515. int ll_send_conn_adv_cnt;
  516. int ll_conn_adv_pending_cnt;
  517. // scan in conn event
  518. int ll_conn_scan_pending_cnt;
  519. // slave counter
  520. int ll_recv_scan_req_cnt;
  521. int ll_send_scan_rsp_cnt;
  522. int ll_recv_conn_req_cnt;
  523. // whitelist
  524. int ll_filter_scan_req_cnt;
  525. int ll_filter_conn_req_cnt;
  526. // scan
  527. int ll_recv_adv_pkt_cnt;
  528. int ll_recv_scan_rsp_cnt;
  529. // connection event counters
  530. int ll_conn_succ_cnt; // LL accept connect, but not always sync succ
  531. int ll_link_lost_cnt;
  532. int ll_link_estab_fail_cnt;
  533. // connection packet statistics
  534. int ll_recv_ctrl_pkt_cnt;
  535. int ll_recv_data_pkt_cnt;
  536. int ll_recv_invalid_pkt_cnt;
  537. int ll_recv_abnormal_cnt;
  538. int ll_send_data_pkt_cnt;
  539. int ll_conn_event_cnt;
  540. int ll_recv_crcerr_event_cnt; // CRC error detected in the connection event
  541. int ll_conn_event_timeout_cnt; // timeout connection event countt
  542. int ll_rx_peer_cnt; // scan/conn request counter, to consider whether we need it
  543. // LL <-> HCI packets statistics
  544. int ll_to_hci_pkt_cnt;
  545. int ll_hci_to_ll_pkt_cnt;
  546. int ll_hci_buffer_alloc_err_cnt;
  547. //ll_hw err cnt
  548. int ll_trigger_err;
  549. int ll_rfifo_rst_err;
  550. int ll_rfifo_rst_cnt;
  551. int ll_rfifo_read_err;
  552. // reserve counter
  553. int ll_tbd_cnt1;
  554. int ll_tbd_cnt2;
  555. int ll_tbd_cnt3;
  556. int ll_tbd_cnt4;
  557. } llGlobalStatistics_t;
  558. // Counters
  559. typedef struct
  560. {
  561. uint8 numTxDone; // TX pkts ACK'ed (auto-empty not counted)
  562. uint8 numTxAck; // TX pkts ACK'ed (both auto-empty and TX FIFO packets)
  563. uint8 numTxCtrlAck; // TX control pkts ACK'ed
  564. uint8 numTxCtrl; // TX control pkts TX'ed
  565. uint8 numTxRetrans; // retrans + auto-empty retrans
  566. uint8 numTx; // trans (incl. auto-empty) + retrans (incl. auto-empty)
  567. uint8 numRxOk; // non-empty correctly RX'ed and not ignored data and control pkts
  568. uint8 numRxCtrl; // correctly RX'ed control pkts
  569. uint8 numRxNotOk; // RX'ed with bad CRC
  570. uint8 numRxIgnored; // correctly RX'ed, but ignored
  571. uint8 numRxEmpty; // correctly RX'ed empty packets
  572. uint8 numRxFifoFull; // correctly RX'ed but discarded due to full RX FIFO
  573. } rfCounters_t;
  574. // global variables
  575. extern uint8_t LL_TaskID;
  576. extern uint8_t llState;
  577. extern uint8_t connId;
  578. extern peerInfo_t peerInfo;
  579. extern advInfo_t adv_param;
  580. extern scanInfo_t scanInfo; // scan data
  581. extern initInfo_t initInfo; // Initiator info
  582. extern llConnState_t conn_param[];
  583. extern chanMap_t chanMapUpdate;
  584. extern featureSet_t deviceFeatureSet;
  585. extern uint8 numComplPkts;
  586. extern uint8 numComplPktsLimit;
  587. extern verInfo_t verInfo;
  588. extern rfCounters_t rfCounters;
  589. extern llLinkBuf_t ll_buf;
  590. extern llGlobalStatistics_t g_pmCounters;
  591. extern llPduLenManagment_t g_llPduLen;
  592. extern llPhyModeManagment_t g_llPhyModeCtrl;
  593. #endif