1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __APP_BT_H__
5 #define __APP_BT_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 #include "me_api.h"
11 #include "a2dp_api.h"
12 #include "hfp_api.h"
13 #include "btapp.h"
14 
15 enum APP_BT_REQ_T {
16     APP_BT_REQ_ACCESS_MODE_SET,
17     APP_BT_REQ_AUTO_TEST,
18     APP_BT_REQ_NUM
19 };
20 
21 enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T {
22     APP_BT_GOLBAL_HANDLE_HOOK_USER_0 = 0,
23     APP_BT_GOLBAL_HANDLE_HOOK_USER_1,
24     APP_BT_GOLBAL_HANDLE_HOOK_USER_QTY
25 };
26 
27 typedef void (*APP_BT_REQ_CONNECT_PROFILE_FN_T)(void *, void *);
28 typedef bt_status_t  (*APP_BT_REQ_HF_OP_FN_T)(void *);
29 typedef void (*APP_BT_GOLBAL_HANDLE_HOOK_HANDLER)(const btif_event_t*Event);
30 
31 #define app_bt_accessmode_set_req(accmode) do{app_bt_send_request(APP_BT_REQ_ACCESS_MODE_SET, accmode, 0, 0);}while(0)
32 typedef enum
33 {
34     APP_BT_IDLE_STATE = 0,
35     APP_BT_IN_CONNECTING_PROFILES_STATE	// acl link is created and in the process of connecting profiles
36 } APP_BT_CONNECTING_STATE_E;
37 
38 typedef enum
39 {
40     // always in active mode during a2dp streaming
41     ACTIVE_MODE_KEEPER_A2DP_STREAMING = 0,
42     // always in active mode during ai voice up-streaming
43     ACTIVE_MODE_KEEPER_AI_VOICE_STREAM,
44     // always in active mode during OTA
45     ACTIVE_MODE_KEEPER_OTA,
46     // stay in active mode for 15 seconds after role switch
47     ACTIVE_MODE_KEEPER_ROLE_SWITCH,
48     // stay in active mode during synchronous voice prompt playing
49     ACTIVE_MODE_KEEPER_SYNC_VOICE_PROMPT,
50     // always in active mode during phone call
51     ACTIVE_MODE_KEEPEER_SCO_STREAMING,
52 
53 
54 } BT_LINK_ACTIVE_MODE_KEEPER_USER_E;
55 
56 #define MAX_ACTIVE_MODE_MANAGED_LINKS       3
57 #define UPDATE_ACTIVE_MODE_FOR_ALL_LINKS    MAX_ACTIVE_MODE_MANAGED_LINKS
58 
59 void app_bt_active_mode_manager_init(void);
60 
61 void app_bt_active_mode_reset(uint32_t linkIndex);
62 
63 void app_bt_active_mode_set(BT_LINK_ACTIVE_MODE_KEEPER_USER_E user, uint32_t linkIndex);
64 
65 void app_bt_active_mode_clear(BT_LINK_ACTIVE_MODE_KEEPER_USER_E user, uint32_t linkIndex);
66 
67 void app_bt_global_handle(const btif_event_t *Event);
68 bool is_app_bt_pairing_running(void);
69 
70 void PairingTransferToConnectable(void);
71 
72 void app_bt_global_handle_init(void);
73 
74 void app_bt_opening_reconnect(void);
75 
76 void app_bt_accessmode_set(  btif_accessible_mode_t mode);
77 
78 void app_bt_send_request(uint32_t message_id, uint32_t param0, uint32_t param1, uint32_t ptr);
79 
80 void app_bt_init(void);
81 
82 int app_bt_state_checker(void);
83 
84 void *app_bt_profile_active_store_ptr_get(uint8_t *bdAddr);
85 
86 void app_bt_profile_connect_manager_open(void);
87 
88 void app_bt_profile_connect_manager_opening_reconnect(void);
89 
90 BOOL app_bt_profile_connect_openreconnecting(void *ptr);
91 
92 int app_bt_global_handle_hook_set(enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T user, APP_BT_GOLBAL_HANDLE_HOOK_HANDLER handler);
93 
94 APP_BT_GOLBAL_HANDLE_HOOK_HANDLER app_bt_global_handle_hook_get(enum APP_BT_GOLBAL_HANDLE_HOOK_USER_T user);
95 
96 bool app_is_hfp_service_connected(void);
97 #if defined(IBRT)
98 void app_bt_ibrt_reconnect_mobile_profile_flag_set(void);
99 void app_bt_ibrt_reconnect_mobile_profile_flag_clear(void);
100 bool app_bt_ibrt_reconnect_mobile_profile_flag_get(void);
101 #endif
102 #if defined(__BT_SELECT_PROF_DEVICE_ID__)
103 int8_t app_bt_a2dp_is_same_stream(a2dp_stream_t *src_Stream, a2dp_stream_t *dst_Stream);
104 
105 void app_bt_a2dp_find_same_unused_stream(a2dp_stream_t *in_Stream, a2dp_stream_t **out_Stream, uint32_t device_id);
106 
107 int8_t app_bt_a2dp_is_stream_on_device_id(a2dp_stream_t *in_Stream, uint32_t device_id);
108 
109 int8_t app_bt_hfp_is_chan_on_device_id(hf_chan_handle_t chan, uint32_t device_id);
110 
111 int8_t app_bt_is_any_profile_connected(uint32_t device_id);
112 
113 int8_t app_bt_is_a2dp_connected(uint32_t device_id);
114 
115 btif_remote_device_t *app_bt_get_connected_profile_remdev(uint32_t device_id);
116 #endif
117 
118 void app_bt_stay_active(uint8_t deviceId);
119 
120 void app_bt_allow_sniff(uint8_t deviceId);
121 
122 btif_remote_device_t* app_bt_get_remoteDev(uint8_t deviceId);
123 
124 void app_bt_stop_sniff(uint8_t deviceId);
125 
126 void app_bt_sniff_config(btif_remote_device_t *remDev);
127 
128 void app_bt_allow_sniff_rem_dev(btif_remote_device_t* pRemDev);
129 
130 void app_bt_stay_active_rem_dev(btif_remote_device_t* pRemDev);
131 
132 void app_check_pending_stop_sniff_op(void);
133 
134 void app_bt_reset_reconnect_timer(bt_bdaddr_t *pBdAddr);
135 
136 uint8_t app_bt_get_num_of_connected_dev(void);
137 
138 bool btapp_hfp_is_dev_call_active(uint8_t devId);
139 
140 void app_bt_pause_media_player_again(uint8_t deviceId);
141 
142 bool app_bt_is_music_player_working(uint8_t deviceId);
143 
144 bool app_bt_pause_music_player(uint8_t deviceId);
145 
146 void app_bt_resume_music_player(uint8_t deviceId);
147 
148 bool app_bt_is_to_resume_music_player(uint8_t deviceId);
149 
150 void app_bt_reset_music_player_resume_state(void);
151 
152 bool app_bt_is_device_connected(uint8_t deviceId);
153 
154 void app_bt_set_music_player_resume_device(uint8_t deviceId);
155 
156 bool app_bt_is_a2dp_streaming(uint8_t deviceId);
157 
158 void app_bt_suspend_a2dp_streaming(uint8_t deviceId);
159 
160 bool app_bt_get_device_bdaddr(uint8_t deviceId, uint8_t* btAddr);
161 
162 void fast_pair_enter_pairing_mode_handler(void);
163 
164 void app_hfp_start_voice_media(uint8_t devId);
165 
166 void app_hfp_resume_pending_voice_media(void);
167 
168 bool app_hfp_is_starting_media_pending(void);
169 
170 bool app_bt_is_in_reconnecting(void);
171 
172 bool btapp_hfp_is_dev_sco_connected(uint8_t devId);
173 
174 uint8_t a2dp_get_latest_paused_device(void);
175 
176 bool app_bt_is_in_connecting_profiles_state(void);
177 
178 void app_bt_clear_connecting_profiles_state(uint8_t devId);
179 
180 void app_bt_set_connecting_profiles_state(uint8_t devId);
181 
182 void app_a2dp_hold_mute();
183 
184 void app_a2dp_unhold_mute();
185 
186 #if defined(__INTERCONNECTION__)
187 btif_accessible_mode_t app_bt_get_current_access_mode(void);
188 
189 bool app_bt_is_connected();
190 #endif
191 
192 #ifdef VOICE_DATAPATH
193 bool bt_app_check_device_conneted_to_voicepath(uint8_t device_id);
194 #endif
195 
196 bool app_bt_is_hfp_audio_on(void);
197 
198 btif_remote_device_t* app_bt_get_connected_mobile_device_ptr(void);
199 void app_bt_set_spp_device_ptr(btif_remote_device_t* device);
200 btif_remote_device_t* app_bt_get_spp_device_ptr(void);
201 
202 void app_bt_delay_connect_a2dp(uint32_t param1, uint32_t param2);
203 
204 void app_bt_delay_connect_hfp(uint32_t param1, uint32_t param2);
205 
206 bool app_bt_delay_connect_profile_working(void);
207 
208 bool app_is_disconnecting_all_bt_connections(void);
209 
210 void app_set_disconnecting_all_bt_connections(bool isEnable);
211 
212 void app_bt_start_search(void);
213 
214 #if defined(IBRT)
215 #if defined(ENHANCED_STACK)
216 uint32_t app_bt_save_a2dp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
217 uint32_t app_bt_restore_a2dp_app_ctx(uint8_t *buf, uint32_t buf_len);
218 uint32_t app_bt_save_avrcp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
219 uint32_t app_bt_restore_avrcp_app_ctx(uint8_t *buf, uint32_t buf_len);
220 uint32_t app_bt_save_hfp_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
221 uint32_t app_bt_restore_hfp_app_ctx(uint8_t *buf, uint32_t buf_len);
222 uint32_t app_bt_save_spp_app_ctx(uint32_t app_id,btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
223 uint32_t app_bt_restore_spp_app_ctx(uint8_t *buf, uint32_t buf_len, uint32_t *app_id);
224 #ifdef __BTMAP_ENABLE__
225 uint32_t app_bt_save_map_app_ctx(btif_remote_device_t *rem_dev, uint8_t *buf, uint32_t buf_len);
226 uint32_t app_bt_restore_map_app_ctx(uint8_t *buf, uint32_t buf_len);
227 #endif
228 #endif /* ENHANCED_STACK */
229 #endif
230 
231 void app_stop_fast_connectable_ble_adv_timer(void);
232 int8_t app_bt_get_rssi(void);
233 
234 #ifdef  TILE_DATAPATH
235 int8_t app_tile_get_ble_rssi(void);
236 #endif
237 
238 
239 a2dp_stream_t* app_bt_get_stream(enum BT_DEVICE_ID_T id);
240 
241 int app_bt_get_bt_addr(enum BT_DEVICE_ID_T id, bt_bdaddr_t *bdaddr);
242 
243 bool app_bt_a2dp_service_is_connected(void);
244 
245 void app_wait_stack_ready(void);
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif /* BESBT_H */
250