1 /*
2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifdef CFG_BT_STACK
16 #ifndef CFG_BLE_ONLY
17 /*chipsea_ohos proguard begin*/
18 #include "cs_proguard.h"
19 /*chipsea_ohos proguard end*/
20 #include "al_rtos.h"
21 #include "app_bt.h"
22 #include "app_bt_queue.h"
23 #include "cs_adp_api.h"
24 #include "bt_task_msg.h"
25 #include "bt_task.h"
26 #if APP_SUPPORT_A2DP_SOURCE == 1
27 #include "app_a2dp_source.h"
28 #endif
29 #if APP_SUPPORT_TWS == 1
30 #include "app_tws.h"
31 #endif
32 #include "bt_cs8800_drvif.h"
33 #include "sleep_api.h"
34 #if APP_SUPPORT_OTA_BOX
35 #include "app_ota_box.h"
36 #endif
37
38
39 typedef enum{
40 SLEEP = 0,
41 ACTIVE,
42 }BT_USER_SLEEP_STATE;
43
44 #define APP_BT_QUEUE_MAX (30)
45 #define APP_BT_USER_SLEEP_TIME_DELAY 1000
46 static rtos_queue app_bt_queue;
47 static TimerHandle_t app_bt_user_sleep_timer = NULL;
48 static BT_USER_SLEEP_STATE bt_user_sleep_state = SLEEP;
49
app_bt_us_timer(TimerHandle_t xTimer)50 void app_bt_us_timer( TimerHandle_t xTimer )
51 {
52 bt_user_sleep_state = SLEEP;
53 bt_prevent_sleep_clear(BT_PRV_SLP_TIMER);
54 }
55
app_bt_create_us_timer(void)56 void app_bt_create_us_timer(void)
57 {
58 if(app_bt_user_sleep_timer == NULL)
59 app_bt_user_sleep_timer = rtos_timer_create("APP_BT_US",APP_BT_USER_SLEEP_TIME_DELAY,pdFALSE,NULL,app_bt_us_timer);
60 }
61
app_bt_update_us_timer(void)62 void app_bt_update_us_timer(void)
63 {
64 if(bt_user_sleep_state == SLEEP){
65 bt_user_sleep_state = ACTIVE;
66 bt_prevent_sleep_set(BT_PRV_SLP_TIMER);
67 }
68 rtos_timer_change_period(app_bt_user_sleep_timer,APP_BT_USER_SLEEP_TIME_DELAY,0);
69 }
70
app_bt_queue_process(APP_BT_MSG * msg)71 int app_bt_queue_process(APP_BT_MSG* msg)
72 {
73 Status_BTDef status = BTDEF_UNDEFINED;
74 if (msg->msg_id != BT_SET_SNIFF_TIMER && msg->msg_id != BT_TWS_SNED_SYNC_PARAM && msg->msg_id != BT_KEY_MSG
75 #if APP_SUPPORT_A2DP_SOURCE == 1
76 && msg->msg_id != BT_A2DP_SOURCE_SEND_DATA
77 #endif
78 ){
79 TRACE("APP:msg id:%d \n",msg->msg_id);
80 }
81 switch (msg->msg_id) {
82 case BT_ROLE_SWITCH:
83 status = cs_adp_role_switch(msg->param.p.bdaddr);
84 break;
85 case BT_DISCONNECT_LINK:
86 cs_adp_disconnect_acl(msg->param.p.bdaddr);
87 status = BTDEF_NO_ERROR;
88 break;
89 case BT_DISCONNECT_LINK_ALL:
90 app_bt_disconnect_all();
91 status = BTDEF_NO_ERROR;
92 break;
93 case BT_STOP_SNIFF:
94 status = cs_adp_stop_sniff(msg->param.p.bdaddr);
95 break;
96 case BT_SET_SCAN_MODE:
97 status = cs_adp_set_scan_mode(msg->param.p.mode);
98 break;
99 case BT_SET_LINK_POLICY:
100 status = cs_adp_set_linkpolicy(msg->param.p.linkpolicy_param.bdaddr,
101 msg->param.p.linkpolicy_param.policy);
102 break;
103 case BT_SET_SNIFF_TIMER:
104 if (msg->param.p.btsniff_param.sniff_info.maxInterval == 0){
105 status = cs_adp_set_sniff_timer(msg->param.p.btsniff_param.bdaddr,
106 NULL,
107 msg->param.p.btsniff_param.timeout);
108 }else{
109 status = cs_adp_set_sniff_timer(msg->param.p.btsniff_param.bdaddr,
110 &msg->param.p.btsniff_param.sniff_info,
111 msg->param.p.btsniff_param.timeout);
112 }
113 break;
114 #if APP_SUPPORT_A2DP_SBC == 1 || APP_SUPPORT_A2DP_AAC == 1
115 case BT_A2DP_CONNECT:
116 status = cs_adp_a2dp_connect(msg->param.p.bdaddr);
117 break;
118 case BT_A2DP_DISCONNECT:
119 status = cs_adp_a2dp_disconnect(msg->param.p.bdaddr);
120 break;
121 #endif
122 #if APP_SUPPORT_HFP == 1
123 case BT_HFP_CONNECT:
124 status = cs_adp_hf_connect(msg->param.p.bdaddr);
125 break;
126 case BT_HFP_DISCONNECT:
127 status = cs_adp_hf_disconnect(msg->param.p.bdaddr);
128 break;
129 case BT_HFP_SCO_CONNECT:
130 status = cs_adp_hf_sco_connect(msg->param.p.bdaddr);
131 break;
132 case BT_HFP_SCO_DISCONNECT:
133 status = cs_adp_hf_sco_disconnect(msg->param.p.bdaddr);
134 break;
135 #endif
136 #if APP_SUPPORT_HSP == 1
137 case BT_HSP_CONNECT:
138 status = cs_adp_hs_connect(msg->param.p.bdaddr);
139 break;
140 case BT_HSP_SCO_CONNECT:
141 status = cs_adp_hs_sco_connect(msg->param.p.bdaddr);
142 break;
143 case BT_HSP_SCO_DISCONNECT:
144 status = cs_adp_hs_sco_disconnect(msg->param.p.bdaddr);
145 break;
146 case BT_HSP_DISCONNECT:
147 status = cs_adp_hs_disconnect(msg->param.p.bdaddr);
148 break;
149 #endif
150 #if APP_SUPPORT_A2DP_SOURCE == 1
151 case BT_A2DP_SOURCE_CONNECT:
152 status = cs_adp_a2dp_source_connect(msg->param.p.bdaddr);
153 break;
154 case BT_A2DP_SOURCE_START:
155 if(msg->param.p.a2dp_param.on_off){
156 cs_adp_a2dp_source_start();
157 }else{
158 cs_adp_a2dp_source_suspend();
159 }
160 break;
161 case BT_A2DP_SOURCE_SEND_DATA:
162 app_bt_source_send_a2dp_test_sbc_packet(msg->param.p.bdaddr);
163 break;
164 #endif
165 #if APP_SUPPORT_HFG
166 case BT_HFG_CONNECT:
167 cs_adp_hfg_connect(msg->param.p.bdaddr);
168 break;
169 #endif
170 #if APP_SUPPORT_TWS == 1
171 case BT_TWS_CONNECT:
172 app_connect_tws_test();
173 break;
174 case BT_TWS_SEND_DATA:
175 app_tws_send_data(msg->param.p.buff.data,msg->param.p.buff.len);
176 break;
177 case BT_TWS_SYNC_CTRL:
178 cs_adp_host_control_tws_sync_con((BOOL)msg->param.p.tws_param.tws_sync_ctrl);
179 break;
180 case BT_TWS_MSS_CTRL:
181 app_tws_begin_mss();
182 break;
183 case BT_TWS_STOP_LOCAL_SYNC_CTRL:
184 cs_adp_host_sync_stop();
185 break;
186 case BT_TWS_SNED_SYNC_PARAM:
187 cs_adp_set_audio_sync_param(msg->param.p.sync_param.current_clk,msg->param.p.sync_param.counterNum ,\
188 msg->param.p.sync_param.master_current_samplerate,msg->param.p.sync_param.current_bt_counter,\
189 msg->param.p.sync_param.current_bt_counter_offset,msg->param.p.sync_param.strb_cycle_offset);
190 break;
191 case BT_TWS_RESET:
192 cs_adp_update_tws_flash_role(TWS_NOROLE);
193 app_bt_disconnect_all();
194 break;
195 case BT_TWS_DISC:
196 app_bt_disconnect_tws();
197 break;
198 case BT_TWS_VISIBLE_REOPEN:
199 cs_adp_tws_clear_whitelist();
200 switch(app_tws_get_ble_state()){
201 case STATE_SCAN_EN:
202 cs_adp_tws_set_scan_disable();
203 break;
204 case STATE_ADV_EN:
205 cs_adp_tws_stop_adv();
206 break;
207 default:
208 break;
209 }
210 app_tws_set_ble_state(STATE_IDLE);
211 app_tws_default_connect();
212 break;
213 #endif
214 case BT_GENERATE_KEY_COMPLETE:
215 cs_adp_send_generate_key();
216 break;
217 case BT_AUDIO_SEND_RESTART:
218 cs_adp_tws_restart();
219 break;
220 case BT_AUDIO_SEND_MODE_REPLAY:
221 {
222 uint32_t mode = msg->param.p.audio_mode;
223 switch(mode){
224 case AUD_BT_A2DP:
225 //check a2dp status and do start process.
226 break;
227 case AUD_BT_SCO:
228 //check hfp sco link status and do start process.
229 break;
230 default:
231 break;
232 }
233 }
234 break;
235 case BT_KEY_MSG:
236 app_bt_key_handle(msg->param.p.key);
237 break;
238 case BT_WEARING_STATE:
239 app_bt_wearing_state_hanlde(msg->param.p.wearing_state);
240 break;
241 case BT_SET_LP_LEVEL:
242 {
243 uint8_t level = ((uint8_t)(msg->param.p.lp_level));
244 TRACE("APP:bt lp level = %x",level);
245 cs_adp_set_lp_level(level);
246 }
247 break;
248 #if FPGA == 0
249 case BT_ERASE_FLASH:
250 cs_adp_erased_flash();
251 break;
252 #endif
253 case BT_DUT_TEST:
254 #if TWS_BLE_CONNECT == 1
255 cs_adp_tws_set_scan_disable();
256 #endif
257 bt_drv_enable_dut();
258 break;
259 case BT_NO_SCAN:
260 case BT_ISCAN:
261 case BT_PSCAN:
262 case BT_BOTH_SCAN:
263 if(msg->param.p.dut == 0){
264 app_bt_set_scan_mode((U8)(msg->msg_id - BT_NO_SCAN));
265 }else{
266 bt_drv_scan_en(msg->msg_id - BT_NO_SCAN);
267 }
268 break;
269 case BT_INQUIRY_DEV:
270 cs_adp_inquiry(msg->param.p.inquiry_param.len,msg->param.p.inquiry_param.maxResp);
271 break;
272 case BT_INQUIRY_CANCEL:
273 cs_adp_inquiry_cancel();
274 break;
275 #if APP_SUPPORT_OTA_BOX
276 case BT_OTA_CONNECT:
277 app_ota_connect_device(&msg->param.p.bdaddr);
278 break;
279 case BT_OTA_CONNECT_ID:
280 app_ota_connect_by_list_id((uint8_t)msg->param.p.btota_param.dev_id);
281 break;
282 case BT_OTA_SEND_DATA:
283
284 break;
285 #endif
286 #if PLF_BLE_STACK && PLF_BLE_ONLY == 0
287 case BLE_TIMER_NOTIFY:
288 cs_adp_rw_timer_notify();
289 break;
290 #endif
291 default:
292 break;
293 }
294
295 if (msg->msg_id != BT_SET_SNIFF_TIMER && msg->msg_id != BT_TWS_SNED_SYNC_PARAM && msg->msg_id != BT_KEY_MSG
296 #if APP_SUPPORT_A2DP_SOURCE == 1
297 && msg->msg_id != BT_A2DP_SOURCE_SEND_DATA
298 #endif
299 ){
300 TRACE("APP: msg id:%d :status:%d exit\n", msg->msg_id, status);
301 }
302 return 0;
303 }
304
305
app_bt_queue_send(APP_BT_MSG * msg)306 int app_bt_queue_send(APP_BT_MSG* msg)
307 {
308 if(rtos_queue_write(app_bt_queue,(void *)msg,(TickType_t)1,false)){
309 ASSERT_ERR(0);
310 }
311 app_bt_update_us_timer();
312 bt_task_queue_notify(false);
313 return 0;
314 }
315
app_bt_queue_send_isr(APP_BT_MSG * msg)316 int app_bt_queue_send_isr(APP_BT_MSG* msg)
317 {
318 if(rtos_queue_write(app_bt_queue,(void *)msg,(TickType_t)1,true)){
319 ASSERT_ERR(0);
320 }
321 bt_task_queue_notify(true);
322 return 0;
323 }
324
325
app_bt_queue_get(APP_BT_MSG * QueueMsg)326 int app_bt_queue_get(APP_BT_MSG* QueueMsg)
327 {
328 if(rtos_queue_read(app_bt_queue,(void *)QueueMsg,0,0)) {
329 return -1;
330 }
331 return 0;
332 }
333
app_bt_queue_poll(void)334 static void app_bt_queue_poll(void)
335 {
336 APP_BT_MSG QueueMsg;
337 if (!app_bt_queue_get(&QueueMsg)){
338 app_bt_queue_process(&QueueMsg);
339 }
340 }
341
app_bt_queue_init(void)342 int app_bt_queue_init(void)
343 {
344 if (rtos_queue_create(sizeof(APP_BT_MSG),APP_BT_QUEUE_MAX,&app_bt_queue)){
345 TRACE("APP: Failed to Create app_bt_queue\n");
346 return -1;
347 }
348 app_bt_handler_register(HANDLER_REG_1, app_bt_queue_poll);
349 app_bt_create_us_timer();
350 return 0;
351 }
352
app_bt_send_wearing_state(uint32_t state)353 int app_bt_send_wearing_state( uint32_t state)
354 {
355 APP_BT_MSG msg;
356 msg.msg_id = BT_WEARING_STATE;
357 msg.param.p.wearing_state = (uint8_t)state;
358 app_bt_queue_send(&msg);
359 return 0;
360 }
361
app_bt_send_key(uint32_t Key)362 int app_bt_send_key( uint32_t Key)
363 {
364 APP_BT_MSG msg;
365 msg.msg_id = BT_KEY_MSG;
366 msg.param.p.key = Key;
367 app_bt_queue_send(&msg);
368 return 0;
369 }
370
app_bt_send_audio_sync_param(U32 synclk,U32 counternum,U32 samplerate,U32 bt_counter,U32 bt_counter_offset,U32 strb_cycle_offset)371 int app_bt_send_audio_sync_param(U32 synclk,U32 counternum,U32 samplerate,U32 bt_counter,U32 bt_counter_offset,U32 strb_cycle_offset)
372 {
373 APP_BT_MSG msg;
374 msg.param.p.sync_param.counterNum = counternum;
375 msg.param.p.sync_param.current_bt_counter = bt_counter;
376 msg.param.p.sync_param.current_bt_counter_offset = bt_counter_offset;
377 msg.param.p.sync_param.current_clk = synclk;
378 msg.param.p.sync_param.master_current_samplerate = samplerate;
379 msg.param.p.sync_param.strb_cycle_offset = strb_cycle_offset;
380 msg.msg_id = BT_TWS_SNED_SYNC_PARAM;
381 app_bt_queue_send_isr(&msg);
382 return 0;
383
384 }
385
app_bt_send_bt_audio_restart(void)386 int app_bt_send_bt_audio_restart(void)
387 {
388 APP_BT_MSG msg;
389 msg.msg_id = BT_AUDIO_SEND_RESTART;
390 app_bt_queue_send(&msg);
391 return 0;
392 }
393
app_bt_send_bt_audio_mode_replay(uint32_t mode)394 int app_bt_send_bt_audio_mode_replay(uint32_t mode)
395 {
396 APP_BT_MSG msg;
397 msg.msg_id = BT_AUDIO_SEND_MODE_REPLAY;
398 msg.param.p.audio_mode = mode;
399 app_bt_queue_send(&msg);
400 return 0;
401 }
402
app_bt_generate_key_complete(void)403 int app_bt_generate_key_complete(void)
404 {
405 APP_BT_MSG msg;
406 msg.msg_id = BT_GENERATE_KEY_COMPLETE;
407 app_bt_queue_send(&msg);
408 return 0;
409 }
410
app_bt_set_lp_level(uint8_t level)411 int app_bt_set_lp_level(uint8_t level)
412 {
413 APP_BT_MSG msg;
414 msg.msg_id = BT_SET_LP_LEVEL;
415 msg.param.p.lp_level = level;
416 app_bt_queue_send(&msg);
417 return 0;
418 }
419
420 #if FPGA == 0
app_bt_erased_flash(void)421 int app_bt_erased_flash(void)
422 {
423 APP_BT_MSG msg;
424 msg.msg_id = BT_ERASE_FLASH;
425 app_bt_queue_send(&msg);
426 return 0;
427 }
428 #endif
app_bt_dut_mode(void)429 int app_bt_dut_mode(void)
430 {
431 APP_BT_MSG msg;
432 msg.msg_id = BT_DUT_TEST;
433 app_bt_queue_send(&msg);
434 return 0;
435 }
436
app_bt_wr_scan_en(unsigned int scan_en,unsigned int dut)437 int app_bt_wr_scan_en(unsigned int scan_en,unsigned int dut)
438 {
439 APP_BT_MSG msg;
440 msg.msg_id = BT_NO_SCAN + scan_en;
441 msg.param.p.dut = (uint8_t)dut;
442 app_bt_queue_send(&msg);
443 return 0;
444 }
445
app_bt_inquiry_dev(unsigned int len,unsigned int maxResp)446 int app_bt_inquiry_dev(unsigned int len,unsigned int maxResp)
447 {
448 APP_BT_MSG msg;
449 msg.msg_id = BT_INQUIRY_DEV;
450 msg.param.p.inquiry_param.len = (uint8_t)len;
451 msg.param.p.inquiry_param.maxResp = (uint8_t)maxResp;
452 app_bt_queue_send(&msg);
453 return 0;
454 }
455
app_bt_inquiry_cancel(void)456 int app_bt_inquiry_cancel(void)
457 {
458 APP_BT_MSG msg;
459 msg.msg_id = BT_INQUIRY_CANCEL;
460 app_bt_queue_send(&msg);
461 return 0;
462 }
463
464 #if APP_SUPPORT_A2DP_SOURCE == 1
app_bt_a2dp_start(BT_ADDR * bdaddr,uint32_t on)465 int app_bt_a2dp_start(BT_ADDR* bdaddr,uint32_t on)
466 {
467 APP_BT_MSG msg;
468 msg.msg_id = BT_A2DP_SOURCE_START;
469 msg.param.p.a2dp_param.on_off = on;
470 memcpy(msg.param.p.a2dp_param.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
471 app_bt_queue_send(&msg);
472 return 0;
473 }
474
app_bt_a2dp_send_data(BT_ADDR * bdaddr)475 int app_bt_a2dp_send_data(BT_ADDR* bdaddr)
476 {
477 APP_BT_MSG msg;
478 msg.msg_id = BT_A2DP_SOURCE_SEND_DATA;
479 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
480 app_bt_queue_send(&msg);
481 return 0;
482 }
483 #endif
484
485 #if APP_SUPPORT_TWS == 1
app_bt_connect_tws(BT_ADDR * bdaddr)486 int app_bt_connect_tws(BT_ADDR* bdaddr)
487 {
488 APP_BT_MSG msg;
489 msg.msg_id = BT_TWS_CONNECT;
490 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
491 app_bt_queue_send(&msg);
492 return 0;
493 }
494
app_bt_tws_send_data(U8 * data,U16 len)495 int app_bt_tws_send_data(U8 *data,U16 len)
496 {
497 APP_BT_MSG msg;
498 msg.msg_id = BT_TWS_SEND_DATA;
499 msg.param.p.buff.data = data;
500 msg.param.p.buff.len = len;
501 app_bt_queue_send(&msg);
502 return 0;
503 }
504
app_bt_tws_sync_control(BOOL on)505 int app_bt_tws_sync_control(BOOL on)
506 {
507 APP_BT_MSG msg;
508 msg.msg_id = BT_TWS_SYNC_CTRL;
509 if(on)
510 msg.param.p.tws_param.tws_sync_ctrl = 1;
511 else
512 msg.param.p.tws_param.tws_sync_ctrl = 0;
513 app_bt_queue_send(&msg);
514 return 0;
515 }
516
app_bt_tws_mss_control(void)517 int app_bt_tws_mss_control(void)
518 {
519 APP_BT_MSG msg;
520 msg.msg_id = BT_TWS_MSS_CTRL;
521 app_bt_queue_send(&msg);
522 return 0;
523 }
524
app_bt_tws_stop_local_sync_control(void)525 int app_bt_tws_stop_local_sync_control(void)
526 {
527 APP_BT_MSG msg;
528 msg.msg_id = BT_TWS_STOP_LOCAL_SYNC_CTRL;
529 app_bt_queue_send(&msg);
530 return 0;
531 }
532
app_bt_tws_reset(void)533 int app_bt_tws_reset(void)
534 {
535 APP_BT_MSG msg;
536 msg.msg_id = BT_TWS_RESET;
537 app_bt_queue_send(&msg);
538 return 0;
539 }
540
app_bt_tws_disc(void)541 int app_bt_tws_disc(void)
542 {
543 APP_BT_MSG msg;
544 msg.msg_id = BT_TWS_DISC;
545 app_bt_queue_send(&msg);
546 return 0;
547 }
548
app_bt_tws_visible_reopen(void)549 int app_bt_tws_visible_reopen(void)
550 {
551 APP_BT_MSG msg;
552 msg.msg_id = BT_TWS_VISIBLE_REOPEN;
553 app_bt_queue_send(&msg);
554 return 0;
555 }
556 #endif
557
app_bt_role_switch(BT_ADDR * bdaddr)558 int app_bt_role_switch(BT_ADDR* bdaddr)
559 {
560 APP_BT_MSG msg;
561 msg.msg_id = BT_ROLE_SWITCH;
562 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
563 app_bt_queue_send(&msg);
564 return 0;
565 }
566
567
app_bt_disconnect_acl(BT_ADDR * bdaddr)568 int app_bt_disconnect_acl(BT_ADDR* bdaddr)
569 {
570 APP_BT_MSG msg;
571 msg.msg_id = BT_DISCONNECT_LINK;
572 TRACE("APP:bt disconnect link\n");
573 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
574 app_bt_queue_send(&msg);
575 return 0;
576 }
577
app_bt_disconnect_all_acl(void)578 int app_bt_disconnect_all_acl(void)
579 {
580 APP_BT_MSG msg;
581 msg.msg_id = BT_DISCONNECT_LINK_ALL;
582 TRACE("APP:bt disconnect all link\n");
583 app_bt_queue_send(&msg);
584 return 0;
585 }
586
app_bt_stop_sniff(BT_ADDR * bdaddr)587 int app_bt_stop_sniff(BT_ADDR* bdaddr)
588 {
589 APP_BT_MSG msg;
590 msg.msg_id = BT_STOP_SNIFF;
591 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
592 app_bt_queue_send(&msg);
593 return 0;
594 }
595
app_bt_setscanmode(AppBtScanMode mode)596 int app_bt_setscanmode(AppBtScanMode mode)
597 {
598 APP_BT_MSG msg;
599 msg.msg_id = BT_SET_SCAN_MODE;
600 msg.param.p.mode = mode;
601 app_bt_queue_send(&msg);
602 return 0;
603 }
604
app_bt_set_linkpolicy(BT_ADDR * bdaddr,AppBtLinkPolicy policy)605 int app_bt_set_linkpolicy(BT_ADDR* bdaddr, AppBtLinkPolicy policy)
606 {
607 APP_BT_MSG msg;
608 msg.msg_id = BT_SET_LINK_POLICY;
609 TRACE("APP:set linkpolicy %x\n",policy);
610 memcpy(msg.param.p.linkpolicy_param.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
611 msg.param.p.linkpolicy_param.policy = policy;
612 app_bt_queue_send(&msg);
613 return 0;
614 }
615
app_bt_set_sniff_timer(BT_ADDR * bdaddr,AppBtSniffInfo * sniff_info,TimeT Time)616 int app_bt_set_sniff_timer( BT_ADDR *bdaddr,
617 AppBtSniffInfo* sniff_info,
618 TimeT Time)
619 {
620 APP_BT_MSG msg;
621 msg.msg_id = BT_SET_SNIFF_TIMER;
622 memcpy(msg.param.p.btsniff_param.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
623 if (sniff_info){
624 memcpy((uint8_t*)&msg.param.p.btsniff_param.sniff_info, (uint8_t*)sniff_info, sizeof(AppBtSniffInfo));
625 }else{
626 memcpy((uint8_t*)&msg.param.p.btsniff_param.sniff_info, 0, sizeof(AppBtSniffInfo));
627 }
628 msg.param.p.btsniff_param.timeout = Time;
629 app_bt_queue_send(&msg);
630 return 0;
631 }
632
633
app_bt_connect_a2dp(BT_ADDR * bdaddr)634 int app_bt_connect_a2dp(BT_ADDR *bdaddr)
635 {
636 #if APP_SUPPORT_A2DP_SBC == 1 || APP_SUPPORT_A2DP_AAC == 1
637 APP_BT_MSG msg;
638 msg.msg_id = BT_A2DP_CONNECT;
639 TRACE("APP:a2dp connect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
640 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
641 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
642 app_bt_queue_send(&msg);
643 #endif
644 return 0;
645 }
646
app_bt_source_connect_a2dp(BT_ADDR * bdaddr)647 int app_bt_source_connect_a2dp(BT_ADDR *bdaddr)
648 {
649 #if APP_SUPPORT_A2DP_SOURCE == 1
650 APP_BT_MSG msg;
651 msg.msg_id = BT_A2DP_SOURCE_CONNECT;
652 TRACE("APP:a2dp connect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
653 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
654 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
655 app_bt_queue_send(&msg);
656 #endif
657 return 0;
658 }
659
app_bt_close_a2dp(BT_ADDR * bdaddr)660 int app_bt_close_a2dp(BT_ADDR *bdaddr)
661 {
662 #if APP_SUPPORT_A2DP_SBC == 1 || APP_SUPPORT_A2DP_AAC == 1 || APP_SUPPORT_A2DP_SOURCE == 1
663 APP_BT_MSG msg;
664 msg.msg_id = BT_A2DP_DISCONNECT;
665 TRACE("APP:a2dp disconnect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
666 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
667 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
668 app_bt_queue_send(&msg);
669 #endif
670 return 0;
671 }
672
app_bt_connect_hfg(BT_ADDR * bdaddr)673 int app_bt_connect_hfg(BT_ADDR *bdaddr)
674 {
675 #if APP_SUPPORT_HFG == 1
676 APP_BT_MSG msg;
677 msg.msg_id = BT_HFG_CONNECT;
678 TRACE("APP:hfg connect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
679 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
680 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
681 app_bt_queue_send(&msg);
682 #endif
683 return 0;
684 }
685
app_bt_connect_hfp(BT_ADDR * bdaddr)686 int app_bt_connect_hfp(BT_ADDR *bdaddr)
687 {
688 #if APP_SUPPORT_HFP == 1
689 APP_BT_MSG msg;
690 msg.msg_id = BT_HFP_CONNECT;
691 TRACE("APP:hfp connect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
692 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
693 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
694 app_bt_queue_send(&msg);
695 #endif
696 return 0;
697 }
698
app_bt_disconnect_hfp(BT_ADDR * bdaddr)699 int app_bt_disconnect_hfp(BT_ADDR *bdaddr)
700 {
701 #if APP_SUPPORT_HFP == 1
702 APP_BT_MSG msg;
703 msg.msg_id = BT_HFP_DISCONNECT;
704 TRACE("APP:hfp disconnect addr 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",bdaddr->addr[0]
705 ,bdaddr->addr[1],bdaddr->addr[2],bdaddr->addr[3],bdaddr->addr[4],bdaddr->addr[5]);
706 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
707 app_bt_queue_send(&msg);
708 #endif
709 return 0;
710 }
711
app_bt_hfp_connect_sco(BT_ADDR * bdaddr)712 int app_bt_hfp_connect_sco(BT_ADDR *bdaddr)
713 {
714 #if APP_SUPPORT_HFP == 1
715 APP_BT_MSG msg;
716 msg.msg_id = BT_HFP_SCO_CONNECT;
717 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
718 app_bt_queue_send(&msg);
719 #endif
720 return 0;
721 }
722
app_bt_hfp_disconnect_sco(BT_ADDR * bdaddr)723 int app_bt_hfp_disconnect_sco(BT_ADDR *bdaddr)
724 {
725 #if APP_SUPPORT_HFP == 1
726 APP_BT_MSG msg;
727 msg.msg_id = BT_HFP_SCO_DISCONNECT;
728 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
729 app_bt_queue_send(&msg);
730 #endif
731 return 0;
732 }
733
734
735 #if APP_SUPPORT_HSP == 1
app_bt_connect_hsp(BT_ADDR * bdaddr)736 int app_bt_connect_hsp(BT_ADDR *bdaddr)
737 {
738 APP_BT_MSG msg;
739 msg.msg_id = BT_HSP_CONNECT;
740 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
741 app_bt_queue_send(&msg);
742 return 0;
743 }
744
app_bt_hsp_connect_sco(BT_ADDR * bdaddr)745 int app_bt_hsp_connect_sco(BT_ADDR *bdaddr)
746 {
747 APP_BT_MSG msg;
748 msg.msg_id = BT_HSP_SCO_CONNECT;
749 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
750 app_bt_queue_send(&msg);
751 return 0;
752 }
753
754
app_bt_hsp_disconnect_sco(BT_ADDR * bdaddr)755 int app_bt_hsp_disconnect_sco(BT_ADDR *bdaddr)
756 {
757 APP_BT_MSG msg;
758 msg.msg_id = BT_HSP_SCO_DISCONNECT;
759 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
760 app_bt_queue_send(&msg);
761 return 0;
762 }
763
app_bt_disconnect_hsp(BT_ADDR * bdaddr)764 int app_bt_disconnect_hsp(BT_ADDR *bdaddr)
765 {
766 APP_BT_MSG msg;
767 msg.msg_id = BT_HSP_DISCONNECT;
768 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
769 app_bt_queue_send(&msg);
770 return 0;
771 }
772
773 #endif
774 #if APP_SUPPORT_OTA_BOX
app_bt_ota_connect(BT_ADDR * bdaddr)775 int app_bt_ota_connect(BT_ADDR *bdaddr)
776 {
777 APP_BT_MSG msg;
778 msg.msg_id = BT_OTA_CONNECT;
779 memcpy(msg.param.p.bdaddr.addr, bdaddr->addr, BD_ADDR_SIZE);
780 app_bt_queue_send(&msg);
781 return 0;
782 }
783
app_bt_ota_connect_by_id(uint32_t id)784 int app_bt_ota_connect_by_id(uint32_t id)
785 {
786 APP_BT_MSG msg;
787 msg.msg_id = BT_OTA_CONNECT_ID;
788 msg.param.p.btota_param.dev_id = id;
789 app_bt_queue_send(&msg);
790 return 0;
791 }
792
app_bt_ota_send_data(uint32_t num)793 int app_bt_ota_send_data(uint32_t num)
794 {
795 APP_BT_MSG msg;
796 msg.msg_id = BT_OTA_SEND_DATA;
797 msg.param.p.btota_param.num = num;
798 app_bt_queue_send(&msg);
799 return 0;
800 }
801 #endif
802 #if PLF_BLE_STACK && PLF_BLE_ONLY == 0
app_rw_timer_notify(void)803 int app_rw_timer_notify(void)
804 {
805 APP_BT_MSG msg;
806 msg.msg_id = BLE_TIMER_NOTIFY;
807 app_bt_queue_send(&msg);
808 return 0;
809 }
810 #endif
811 #endif
812 #endif
813