bt_manager_ble.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * Copyright (c) 2019 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief bt ble manager.
  9. */
  10. #ifndef __BT_MANAGER_BLE_H__
  11. #define __BT_MANAGER_BLE_H__
  12. #include <acts_bluetooth/conn.h>
  13. #include <acts_bluetooth/gatt.h>
  14. #ifdef CONFIG_BLE_MASTER
  15. #include "../bt_manager/ble_master/ble_master.h"
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @defgroup bt_manager_ble_apis Bt Manager Ble APIs
  22. * @ingroup bluetooth_system_apis
  23. * @{
  24. */
  25. enum {
  26. BLE_WAKE_LOCK_ADV_MANANGER = (0x1 << 0),
  27. BLE_WAKE_LOCK_CONNECTED_NOTIFY = (0x1 << 1),
  28. BLE_WAKE_LOCK_ANCS_DISCOVER = (0x1 << 2),
  29. };
  30. /** ble register manager structure */
  31. struct ble_reg_manager {
  32. /* ble acl connected/disconnected callback */
  33. void (*link_cb)(uint8_t *mac, uint8_t connected);
  34. /* bt gatt service to register */
  35. struct bt_gatt_service gatt_svc;
  36. sys_snode_t node;
  37. };
  38. /**
  39. * @brief get ble mtu
  40. *
  41. * This routine provides to get ble mtu
  42. *
  43. * @return ble mtu
  44. */
  45. uint16_t bt_manager_get_ble_mtu(void);
  46. /**
  47. * @brief bt manager send ble data
  48. *
  49. * This routine provides to bt manager send ble data
  50. *
  51. * @param chrc_attr pointer of characteristic attribute to send data
  52. * @param des_attr pointer of descriptor attribute to send data
  53. * @param data pointer of send data
  54. * @param len length of data
  55. *
  56. * @return 0 pending or data len for successed , others failed
  57. */
  58. int bt_manager_ble_send_data(struct bt_gatt_attr *chrc_attr,
  59. struct bt_gatt_attr *des_attr, uint8_t *data, uint16_t len);
  60. /**
  61. * @brief ble disconnect
  62. *
  63. * This routine do ble disconnect
  64. *
  65. * @return N/A
  66. */
  67. void bt_manager_ble_disconnect(void);
  68. /**
  69. * @brief ble service register
  70. *
  71. * This routine provides ble service register
  72. *
  73. * @param le_mgr ble register info
  74. *
  75. * @return N/A
  76. */
  77. void bt_manager_ble_service_reg(struct ble_reg_manager *le_mgr);
  78. /**
  79. * @brief init btmanager ble
  80. *
  81. * This routine init btmanager ble
  82. *
  83. * @return N/A
  84. */
  85. void bt_manager_ble_init(uint8_t mode);
  86. /**
  87. * @brief deinit btmanager ble
  88. *
  89. * This routine deinit btmanager ble
  90. *
  91. * @return N/A
  92. */
  93. void bt_manager_ble_deinit(void);
  94. /**
  95. * @brief notify ble a2dp play state
  96. *
  97. * This routine notify ble a2dp play state
  98. *
  99. * @param play a2dp play or stop
  100. *
  101. * @return N/A
  102. */
  103. void bt_manager_ble_a2dp_play_notify(bool play);
  104. /**
  105. * @brief notify ble hfp play state
  106. *
  107. * This routine notify ble hfp play state
  108. *
  109. * @param play hfp play or stop
  110. *
  111. * @return N/A
  112. */
  113. void bt_manager_ble_hfp_play_notify(bool play);
  114. /**
  115. * @brief stop ble advertise
  116. *
  117. * This routine disable ble adv
  118. *
  119. * @return N/A
  120. */
  121. void bt_manager_ble_adv_stop(void);
  122. /**
  123. * @brief start ble advertise
  124. *
  125. * This routine enable ble adv
  126. *
  127. * @return 0:success; <0:fail;
  128. */
  129. int bt_manager_ble_adv_start(void);
  130. /**
  131. * @brief enable ble no-connect advertise
  132. *
  133. * This routine enable ble adv
  134. *
  135. * @return 0:success; <0:fail;
  136. */
  137. void bt_manager_ble_set_nconn_adv(bool enable);
  138. /**
  139. * @brief reset ble advertise
  140. *
  141. * This routine reset ble adv
  142. *
  143. * @return 0:success; <0:fail;
  144. */
  145. int bt_manager_ble_set_adv_data(struct bt_data ad_data[], uint8_t ad_data_len, struct bt_data sd_data[], uint8_t sd_data_len);
  146. /**
  147. * @brief get ble wake lock
  148. *
  149. * This routine get ble wake lock
  150. *
  151. * @return 0: idle can sleep; other: busy can't sleep.
  152. */
  153. int bt_manager_get_ble_wake_lock(void);
  154. /**
  155. * @brief get ble mac addr
  156. *
  157. * This routine get ble mac
  158. *
  159. * @return 0: success; other: error.
  160. */
  161. int bt_manager_get_ble_mac(bt_addr_le_t *le_addr);
  162. /** @brief check le ready for send data.
  163. *
  164. * @return 0: no ready , > 0: ready.
  165. */
  166. int bt_manager_ble_ready_send_data(void);
  167. /** @brief Get le tx pending cnt.
  168. *
  169. * @return Number of pendind send(include host and controler).
  170. */
  171. uint16_t bt_manager_ble_tx_pending_cnt(void);
  172. /**
  173. * @brief get bt ble connected dev num
  174. *
  175. * This routine get ble connected dev num
  176. *
  177. * @return bt ble connected dev num.
  178. */
  179. uint8_t bt_manager_get_ble_connected_dev_num(void);
  180. /**
  181. * @brief get bt ble state
  182. *
  183. * This routine get ble state
  184. *
  185. * @return bt ble state.
  186. */
  187. int bt_manager_get_ble_state(void);
  188. /**
  189. * @brief Check is app enable le advertise
  190. *
  191. * This routine Check is app enable le advertise
  192. *
  193. * @return true: app enable ble advertise, false: app disable advertise.
  194. */
  195. bool bt_manager_is_app_enable_adv(void);
  196. /**
  197. * @brief get bt ble info
  198. *
  199. * This routine get ble info
  200. *
  201. * @return bt ble info.
  202. */
  203. struct ble_mgr_info * bt_manager_get_ble_info(void);
  204. /**
  205. * @brief get bt ble connected dev rssi
  206. *
  207. * This routine get ble connected dev rssi
  208. *
  209. * @return bt ble connected dev rssi.
  210. */
  211. int bt_manager_get_ble_dev_rssi(int8_t *rssi);
  212. /**
  213. * @brief start bt ble ancs and ams
  214. *
  215. * This routine start bt ble ancs and ams
  216. *
  217. * @return N/A.
  218. */
  219. void bt_manager_ble_ancs_ams_start(void);
  220. /**
  221. * @brief enter br bqb or ble bqb
  222. *
  223. * This routine enter br/ble bqb
  224. *
  225. * @return N/A.
  226. */
  227. void bt_manager_ble_super_enter_bqb(uint8_t mode);
  228. /**
  229. * @brief ble set speed(Set ble parameter)
  230. *
  231. * This routine set ble parameter
  232. *
  233. * @return 0: success, other: failed.
  234. */
  235. int bt_manager_ble_super_set_speed(uint8_t expect_speed);
  236. /**
  237. * @brief ble super test notify
  238. *
  239. * This routine ble super test notify
  240. *
  241. * @return 0: success, other: failed.
  242. */
  243. int bt_manager_ble_super_test_notify(void);
  244. /**
  245. * @brief register bt ble super service
  246. *
  247. * This routine resister super service
  248. *
  249. * @return 0 success other fail.
  250. */
  251. int ble_manager_super_register(void);
  252. /**
  253. * @brief bt ble set connect param
  254. *
  255. * This routine set ble connection param
  256. *
  257. * @param speed_mode
  258. *
  259. * @return 0 success other fail.
  260. */
  261. int bt_manager_set_ble_connection_param(uint8_t speed_mode);
  262. /**
  263. * @brief bt ble find linkkey by le_addr
  264. *
  265. * This routine ble find linkkey by le_addr
  266. *
  267. * @param le_addr for find
  268. *
  269. * @return id (0 ~ max linkkey size) success other fail.
  270. */
  271. int bt_manager_ble_find_linkkey(bt_addr_le_t *le_addr);
  272. /**
  273. * @brief bt ble clear linkkey by le_addr
  274. *
  275. * This routine ble find linkkey by le_addr
  276. *
  277. * @param NULL for all and le_addr for target device
  278. *
  279. * @return N/A
  280. */
  281. void bt_manager_ble_clear_linkkey(bt_addr_le_t *le_addr);
  282. /**
  283. * @brief bt ble find linkkey num
  284. *
  285. * This routine ble find linkkey number
  286. *
  287. * @return ble linkkey number or 0
  288. */
  289. uint8_t bt_manager_ble_get_link_key_num(void);
  290. void bt_manager_ble_hid_report(uint16_t button);
  291. void bt_manager_ble_set_phone(bool ios);
  292. bool bt_manager_ble_is_connected(void);
  293. void bt_manager_reset_le_adv(void);
  294. int ble_get_ams_status(void);
  295. void ble_set_clear_wake_lock(uint16_t wake_lock, uint8_t set);
  296. #ifdef CONFIG_BT_BLE_APP_UPDATE_PARAM
  297. /**
  298. * @brief bt ble upate parameter
  299. *
  300. * This routine update ble parameter
  301. *
  302. * @param param.interval_min Minimum Connection Interval (N * 1.25 ms)
  303. * param.interval_max Maximum Connection Interval (N * 1.25 ms)
  304. * param.latency Connection Latency
  305. * param.timeout Supervision Timeout (N * 10 ms)
  306. *
  307. * @return 0: success, other failed.
  308. */
  309. int bt_manager_ble_update_param(const struct bt_le_conn_param *param);
  310. /**
  311. * @brief bt get ble paramter
  312. *
  313. * This routine get ble parameter
  314. *
  315. * @param *interval Connection Interval (N * 1.25 ms)
  316. * @param *latency Connection Latency
  317. * @param *timeout Supervision Timeout (N * 10 ms)
  318. *
  319. * @return 0: success, other failed.
  320. */
  321. int bt_manager_ble_get_param(uint16_t *interval, uint16_t *latency, uint16_t *timeout);
  322. /**
  323. * @brief bt get ble connect phone type
  324. *
  325. * This routine get ble connect phone type
  326. *
  327. * @return 0: Android, 1: iso, other: not connected or unknow.
  328. */
  329. int bt_manager_ble_get_phone_type(void);
  330. /**
  331. * @brief check br is busy(a2dp playing or hfp on call)
  332. *
  333. * This routine check br is busy
  334. *
  335. * @return 0: br idle, 1: br busy.
  336. */
  337. int bt_manager_ble_is_br_busy(void);
  338. #else
  339. static inline int bt_manager_ble_update_param(const struct bt_le_conn_param *param)
  340. {
  341. return -1;
  342. }
  343. static inline int bt_manager_ble_get_param(uint16_t *interval, uint16_t *latency, uint16_t *timeout)
  344. {
  345. if (interval) {
  346. *interval = 0;
  347. }
  348. if (latency) {
  349. *latency = 0;
  350. }
  351. if (timeout) {
  352. *timeout = 0;
  353. }
  354. return -1;
  355. }
  356. static inline int bt_manager_ble_get_phone_type(void)
  357. {
  358. return 0;
  359. }
  360. static inline int bt_manager_ble_is_br_busy(void)
  361. {
  362. return 0;
  363. }
  364. #endif
  365. void bt_manager_ble_dump_info(void);
  366. #ifdef __cplusplus
  367. }
  368. #endif
  369. #endif // __BT_MANAGER_BLE_H__