hci_ll.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*********************************************************************************************
  2. * Filename : hci_ll.h
  3. * Description : 提供Vendor Host 直接调用Controller API LL Part
  4. * Author : Bingquan
  5. * Email : bingquan_cai@zh-jieli.com
  6. * Last modifiled : 2018-12-04 11:58
  7. * Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
  8. *********************************************************************************************/
  9. #ifndef _HCI_LL_H_
  10. #define _HCI_LL_H_
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13. #include <stdarg.h>
  14. #include "typedef.h"
  15. enum {
  16. LL_EVENT_SUPERVISION_TIMEOUT,
  17. LL_EVENT_RX,
  18. LL_EVENT_ACL_TX_POST,
  19. };
  20. typedef struct {
  21. u8 Own_Address_Type: 2; //0~3
  22. u8 Adv_Filter_Policy: 2;
  23. u8 Scan_Filter_Policy: 2;
  24. u8 initiator_filter_policy: 2;
  25. } hci_ll_param_t;
  26. /*! \brief LE Set Extended Advertising Parameters. */
  27. typedef struct {
  28. uint8_t Advertising_Handle;
  29. uint16_t Advertising_Event_Properties;
  30. uint8_t Primary_Advertising_Interval_Min[3];
  31. uint8_t Primary_Advertising_Interval_Max[3];
  32. uint8_t Primary_Advertising_Channel_Map;
  33. uint8_t Own_Address_Type;
  34. uint8_t Peer_Address_Type;
  35. uint8_t Peer_Address[6];
  36. uint8_t Advertising_Filter_Policy;
  37. uint8_t Advertising_Tx_Power;
  38. uint8_t Primary_Advertising_PHY;
  39. uint8_t Secondary_Advertising_Max_Skip;
  40. uint8_t Secondary_Advertising_PHY;
  41. uint8_t Advertising_SID;
  42. uint8_t Scan_Request_Notification_Enable;
  43. } _GNU_PACKED_ le_set_ext_adv_param_t;
  44. /*! \brief LE Set Extended Advertising Data. */
  45. typedef struct {
  46. uint8_t Advertising_Handle;
  47. uint8_t Operation;
  48. uint8_t Fragment_Preference;
  49. uint8_t Advertising_Data_Length;
  50. uint8_t Advertising_Data[31];
  51. } _GNU_PACKED_ le_set_ext_adv_data_t;
  52. /*! \brief LE Set Extended Advertising Enable. */
  53. typedef struct {
  54. uint8_t Enable;
  55. uint8_t Number_of_Sets;
  56. uint8_t Advertising_Handle;
  57. uint16_t Duration;
  58. uint8_t Max_Extended_Advertising_Events;
  59. } _GNU_PACKED_ le_set_ext_adv_en_t;
  60. /*! \brief LE Extended Advertising report event. */
  61. typedef union {
  62. struct {
  63. uint16_t Connectable_advertising : 1,
  64. Scannable_advertising : 1,
  65. Directed_advertising : 1,
  66. Scan_response : 1,
  67. Legacy_adv_PDUs_used : 1,
  68. Data_status : 2,
  69. All_other_bits : 9;
  70. };
  71. uint16_t event_type;
  72. } _GNU_PACKED_ le_evt_type_t;
  73. typedef struct {
  74. uint8_t Subevent_Code;
  75. uint8_t Num_Reports;
  76. le_evt_type_t Event_Type;
  77. uint8_t Address_Type;
  78. uint8_t Address[6];
  79. uint8_t Primary_PHY;
  80. uint8_t Secondary_PHY;
  81. uint8_t Advertising_SID;
  82. uint8_t Tx_Power;
  83. uint8_t RSSI;
  84. uint16_t Periodic_Advertising_Interval;
  85. uint8_t Direct_Address_Type;
  86. uint8_t Direct_Address[6];
  87. uint8_t Data_Length;
  88. uint8_t Data[0];
  89. } _GNU_PACKED_ le_ext_adv_report_evt_t;
  90. typedef struct {
  91. uint8_t Own_Address_Type;
  92. uint8_t Scanning_Filter_Policy;
  93. uint8_t Scanning_PHYs;
  94. uint8_t Scan_Type;
  95. uint16_t Scan_Interval;
  96. uint16_t Scan_Window;
  97. } _GNU_PACKED_ le_ext_scan_param_lite_t;
  98. //Adjust Host part API
  99. void ll_hci_init(void);
  100. void ll_hci_reset(void);
  101. void ll_hci_destory(void);
  102. void ll_hci_set_event_mask(const u8 *mask);
  103. void ll_hci_set_name(const char *name);
  104. void ll_hci_adv_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
  105. uint8_t direct_address_type, uint8_t *direct_address,
  106. uint8_t channel_map, uint8_t filter_policy);
  107. void ll_hci_adv_set_data(uint8_t advertising_data_length, uint8_t *advertising_data);
  108. void ll_hci_adv_scan_response_set_data(uint8_t scan_response_data_length, uint8_t *scan_response_data);
  109. int ll_hci_adv_enable(bool enable);
  110. void ll_hci_scan_set_params(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window);
  111. int ll_hci_scan_enable(bool enable, u8 filter_duplicates);
  112. int ll_hci_create_conn(u8 *conn_param, u8 *addr_param);
  113. int ll_hci_create_conn_ext(void *param);
  114. int ll_hci_create_conn_cancel(void);
  115. int ll_hci_vendor_send_key_num(u16 con_handle, u8 num);
  116. int ll_hci_encryption(u8 *key, u8 *plaintext_data);
  117. int ll_hci_get_le_rand(void);
  118. int ll_hci_start_encryption(u16 handle, u32 rand_low, u32 rand_high, u16 peer_ediv, u8 *ltk);
  119. int ll_hci_long_term_key_request_reply(u16 handle, u8 *ltk);
  120. int ll_hci_long_term_key_request_nagative_reply(u16 handle);
  121. int ll_hci_connection_update(u16 handle, u16 conn_interval_min, u16 conn_interval_max,
  122. u16 conn_latency, u16 supervision_timeout,
  123. u16 minimum_ce_length, u16 maximum_ce_length);
  124. u16 ll_hci_get_acl_data_len(void);
  125. u16 ll_hci_get_acl_total_num(void);
  126. void ll_hci_set_random_address(u8 *addr);
  127. int ll_hci_disconnect(u16 handle, u8 reason);
  128. int ll_hci_read_local_p256_pb_key(void);
  129. int ll_hci_generate_dhkey(const u8 *data, u32 size);
  130. //Adjust Controller part API
  131. void ll_hci_cmd_handler(int *cmd);
  132. void ll_event_handler(int *msg);
  133. void ll_hci_private_free_dma_rx(u8 *rx_head);
  134. void ll_hci_set_data_length(u16 conn_handle, u16 tx_octets, u16 tx_time);
  135. hci_ll_param_t *ll_hci_param_config_get(void);
  136. void hci_ll_get_device_address(uint8_t *addr_type, u8 *addr);
  137. void hci_ll_get_link_local_address(uint16_t conn_handle, uint8_t *addr_type, u8 *addr);
  138. /*
  139. 定制主机的跳频表,使用时需要把系统自带的AFH关掉
  140. channel_map[5]:bit0~bit36 对应频点 0~36;未用bits默认填0
  141. */
  142. void ll_hci_set_host_channel_classification(u8 *channel_map);
  143. // ble5
  144. void ll_hci_set_ext_adv_params(u8 *data, u32 size);
  145. void ll_hci_set_ext_adv_data(u8 *data, u32 size);
  146. void ll_hci_set_ext_adv_enable(u8 *data, u32 size);
  147. void ll_hci_set_phy(u16 conn_handle, u8 all_phys, u8 tx_phy, u8 rx_phy, u16 phy_options);
  148. void ll_hci_set_ext_scan_params(u8 *data, u32 size);
  149. void ll_hci_set_ext_scan_enable(u8 *data, u32 size);
  150. void ll_hci_ext_create_conn(u8 *data, u32 size);
  151. void ll_hci_set_periodic_adv_params(u8 *data, u32 size);
  152. void ll_hci_set_periodic_adv_data(u8 *data, u32 size);
  153. void ll_hci_set_periodic_adv_enable(u8 *data, u32 size);
  154. void ll_hci_periodic_adv_creat_sync(u8 *data, u32 size);
  155. void ll_hci_periodic_adv_terminate_sync(u8 *data, u32 size);
  156. void ll_hci_periodic_adv_create_sync_cancel(void);
  157. int le_controller_set_mac(void *addr);
  158. /*vendor function*/
  159. bool ll_vendor_check_update_procedure_is_exist(u16 conn_handle);
  160. //set miss latency's count
  161. int ll_vendor_latency_hold_cnt(u16 conn_handle, u16 hold_cnt);
  162. //0-NONE, 1-S2, 2-S8
  163. void ll_vendor_set_code_type(u8 code_type);
  164. /*获取按规则生成的access address,*/
  165. void ll_vendor_access_addr_generate(u8 *out_address);
  166. /*改变本地链路超时断开,用于切换链路时,快速断开链路*/
  167. /*处理以下情况超时断开链路: 对方没有ack terminate 命令 ,或者非md状态下,多包ack */
  168. bool ll_vendor_change_local_supervision_timeout(u16 conn_handle, u32 timeout);
  169. /*ll get connect address info;
  170. input: role:0-local,1-pree; conn_handle, conntion handle
  171. output: addr_info: address_type + address (7bytes)
  172. */
  173. bool ll_vendor_get_link_address_info(u16 conn_handle, u8 role, u8 *addr_info);
  174. #endif