system/bt
Revisión | e42c89377c28153e6f3b9fc8fd4ef1de4df9764a (tree) |
---|---|
Tiempo | 2016-09-29 21:43:07 |
Autor | Steve Kondik <steve@cyng...> |
Commiter | Steve Kondik |
Merge branch 'bt.lnx.2.1.r5-rel' of git://codeaurora.org/platform/system/bt into cm-14.0
Change-Id: I149f61cfa37c4930d54f6451aaff4405936daa8b
@@ -11,7 +11,7 @@ endif | ||
11 | 11 | |
12 | 12 | ifeq ($(TARGET_BUILD_VARIANT),userdebug) |
13 | 13 | ifneq ($(BOARD_HAS_QCA_BT_ROME),true) |
14 | -bdroid_CFLAGS += -DQLOGKIT_USERDEBUG | |
14 | +bluetooth_CFLAGS += -DQLOGKIT_USERDEBUG | |
15 | 15 | endif |
16 | 16 | endif |
17 | 17 |
@@ -21,9 +21,10 @@ endif | ||
21 | 21 | |
22 | 22 | ifeq ($(TARGET_BUILD_VARIANT),eng) |
23 | 23 | bluetooth_CFLAGS += -DBLUEDROID_DEBUG |
24 | -bluetooth_CFLAGS += -DUSE_AUDIO_TRACK | |
25 | 24 | endif |
26 | 25 | |
26 | +bluetooth_CFLAGS += -DUSE_AUDIO_TRACK | |
27 | + | |
27 | 28 | bluetooth_CFLAGS += -DEXPORT_SYMBOL="__attribute__((visibility(\"default\")))" |
28 | 29 | |
29 | 30 | # |
@@ -883,7 +883,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) | ||
883 | 883 | #ifdef BTA_AV_SPLIT_A2DP_ENABLED |
884 | 884 | keyval = (char *)hash_map_get(params, "A2dpStarted"); |
885 | 885 | |
886 | - if (keyval >= 0) | |
886 | + if (keyval != NULL) | |
887 | 887 | { |
888 | 888 | INFO("out_set_parameters, param: A2dpStarted"); |
889 | 889 | if (strcmp(keyval, "true") == 0) |
@@ -1239,7 +1239,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, | ||
1239 | 1239 | /* if the devices does not support HFP 1.7, report DUT's HFP version as 1.6 */ |
1240 | 1240 | if (p_scb->peer_version < HFP_VERSION_1_7) |
1241 | 1241 | { |
1242 | - /* For PTS keep flags as is */ | |
1242 | + /* For PTS keep flags as is. */ | |
1243 | 1243 | if (property_get("bt.pts.certification", value, "false") && |
1244 | 1244 | strcmp(value, "true") != 0) |
1245 | 1245 | { |
@@ -1247,11 +1247,11 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, | ||
1247 | 1247 | } |
1248 | 1248 | } |
1249 | 1249 | else if ((p_scb->peer_version == HFP_VERSION_1_7) && |
1250 | - (p_scb->peer_features & (~BTA_AG_PEER_FEAT_HFIND))) | |
1250 | + (!(p_scb->peer_features & BTA_AG_PEER_FEAT_HFIND))) | |
1251 | 1251 | { |
1252 | 1252 | APPL_TRACE_WARNING("%s: Remote is hfp 1.7 but does not support HF indicators" \ |
1253 | 1253 | "unset hf indicator bit from BRSF", __func__); |
1254 | - /* For PTS keep flags as is */ | |
1254 | + /* For PTS keep flags as is. */ | |
1255 | 1255 | if (property_get("bt.pts.certification", value, "false") && |
1256 | 1256 | strcmp(value, "true") != 0) |
1257 | 1257 | { |
@@ -105,7 +105,9 @@ const tBTA_AV_CO_FUNCTS bta_av_a2d_cos = | ||
105 | 105 | bta_av_co_audio_start, |
106 | 106 | bta_av_co_audio_stop, |
107 | 107 | bta_av_co_audio_src_data_path, |
108 | - bta_av_co_audio_delay | |
108 | + bta_av_co_audio_delay, | |
109 | + bta_av_co_audio_is_offload_supported, | |
110 | + bta_av_co_audio_is_codec_supported | |
109 | 111 | }; |
110 | 112 | |
111 | 113 | /* ssm action functions for audio stream */ |
@@ -343,6 +343,26 @@ void BTA_AvEnableMultiCast(BOOLEAN state, tBTA_AV_HNDL handle) | ||
343 | 343 | |
344 | 344 | /******************************************************************************* |
345 | 345 | ** |
346 | +** Function BTA_AvUpdateMaxAVClient | |
347 | +** | |
348 | +** Description Update max av connections supported simultaneously | |
349 | +** | |
350 | +** Returns void | |
351 | +** | |
352 | +*******************************************************************************/ | |
353 | +void BTA_AvUpdateMaxAVClient(UINT8 max_clients) | |
354 | +{ | |
355 | + tBTA_AV_MAX_CLIENT *p_buf; | |
356 | + | |
357 | + if ((p_buf = (tBTA_AV_MAX_CLIENT *) osi_malloc(sizeof(tBTA_AV_MAX_CLIENT))) != NULL) | |
358 | + { | |
359 | + p_buf->hdr.event = BTA_AV_UPDATE_MAX_AV_CLIENTS_EVT; | |
360 | + p_buf->max_clients = max_clients; | |
361 | + bta_sys_sendmsg(p_buf); | |
362 | + } | |
363 | +} | |
364 | +/******************************************************************************* | |
365 | +** | |
346 | 366 | ** Function BTA_AvReconfig |
347 | 367 | ** |
348 | 368 | ** Description Reconfigure the audio/video stream. |
@@ -113,6 +113,7 @@ enum | ||
113 | 113 | #endif |
114 | 114 | BTA_AV_API_START_EVT, /* the following 2 events must be in the same order as the *AP_*EVT */ |
115 | 115 | BTA_AV_API_STOP_EVT, |
116 | + BTA_AV_UPDATE_MAX_AV_CLIENTS_EVT, | |
116 | 117 | BTA_AV_ENABLE_MULTICAST_EVT /* Event for enable and disable multicast */ |
117 | 118 | }; |
118 | 119 |
@@ -186,6 +187,8 @@ typedef void (*tBTA_AV_CO_STOP) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type); | ||
186 | 187 | typedef void * (*tBTA_AV_CO_DATAPATH) (tBTA_AV_CODEC codec_type, |
187 | 188 | UINT32 *p_len, UINT32 *p_timestamp); |
188 | 189 | typedef void (*tBTA_AV_CO_DELAY) (tBTA_AV_HNDL hndl, UINT16 delay); |
190 | +typedef BOOLEAN (*tBTA_AV_CO_OFFLOAD_SUPPORT) (void); | |
191 | +typedef BOOLEAN (*tBTA_AV_CO_OFFLOAD_CAP) (int codec); | |
189 | 192 | |
190 | 193 | /* the call-out functions for one stream */ |
191 | 194 | typedef struct |
@@ -200,6 +203,8 @@ typedef struct | ||
200 | 203 | tBTA_AV_CO_STOP stop; |
201 | 204 | tBTA_AV_CO_DATAPATH data; |
202 | 205 | tBTA_AV_CO_DELAY delay; |
206 | + tBTA_AV_CO_OFFLOAD_SUPPORT offload; | |
207 | + tBTA_AV_CO_OFFLOAD_CAP cap; | |
203 | 208 | } tBTA_AV_CO_FUNCTS; |
204 | 209 | |
205 | 210 | /* data type for BTA_AV_API_ENABLE_EVT */ |
@@ -256,6 +261,13 @@ typedef struct | ||
256 | 261 | BOOLEAN is_multicast_enabled; |
257 | 262 | } tBTA_AV_ENABLE_MULTICAST; |
258 | 263 | |
264 | +/* data type for BTA_AV_UPDATE_MAX_AV_CLIENTS_EVTT */ | |
265 | +typedef struct | |
266 | +{ | |
267 | + BT_HDR hdr; | |
268 | + UINT8 max_clients; | |
269 | +} tBTA_AV_MAX_CLIENT; | |
270 | + | |
259 | 271 | /* data type for BTA_AV_API_DISCONNECT_EVT */ |
260 | 272 | typedef struct |
261 | 273 | { |
@@ -450,6 +462,7 @@ typedef union | ||
450 | 462 | tBTA_AV_API_META_RSP api_meta_rsp; |
451 | 463 | tBTA_AV_API_STATUS_RSP api_status_rsp; |
452 | 464 | tBTA_AV_ENABLE_MULTICAST multicast_state; |
465 | + tBTA_AV_MAX_CLIENT max_av_clients; | |
453 | 466 | } tBTA_AV_DATA; |
454 | 467 | |
455 | 468 | typedef void (tBTA_AV_VDP_DATA_ACT)(void *p_scb); |
@@ -73,6 +73,14 @@ | ||
73 | 73 | #define BTA_AV_RS_TIME_VAL 1000 |
74 | 74 | #endif |
75 | 75 | |
76 | +/* offload codecs support */ | |
77 | +enum | |
78 | +{ | |
79 | + APTX = 1, | |
80 | + AAC, | |
81 | + APTX_HD | |
82 | +}; | |
83 | + | |
76 | 84 | /* state machine states */ |
77 | 85 | enum |
78 | 86 | { |
@@ -179,6 +187,7 @@ static void bta_av_sco_chg_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 | ||
179 | 187 | static void bta_av_sys_rs_cback (tBTA_SYS_CONN_STATUS status,UINT8 id, UINT8 app_id, BD_ADDR peer_addr); |
180 | 188 | |
181 | 189 | static void bta_av_api_enable_multicast(tBTA_AV_DATA *p_data); |
190 | +static void bta_av_api_update_max_av_clients(tBTA_AV_DATA * p_data); | |
182 | 191 | |
183 | 192 | /* action functions */ |
184 | 193 | const tBTA_AV_NSM_ACT bta_av_nsm_act[] = |
@@ -202,6 +211,7 @@ const tBTA_AV_NSM_ACT bta_av_nsm_act[] = | ||
202 | 211 | #endif |
203 | 212 | bta_av_api_to_ssm, /* BTA_AV_API_START_EVT */ |
204 | 213 | bta_av_api_to_ssm, /* BTA_AV_API_STOP_EVT */ |
214 | + bta_av_api_update_max_av_clients, | |
205 | 215 | bta_av_api_enable_multicast, /* BTA_AV_ENABLE_MULTICAST_EVT */ |
206 | 216 | }; |
207 | 217 |
@@ -683,6 +693,43 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data) | ||
683 | 693 | (*bta_av_a2d_cos.init)(&codec_type, cs.cfg.codec_info, |
684 | 694 | &cs.cfg.num_protect, cs.cfg.protect_info, index) == TRUE) |
685 | 695 | { |
696 | + if ((*bta_av_a2d_cos.offload)() == TRUE) | |
697 | + { | |
698 | + if(codec_type == A2D_NON_A2DP_MEDIA_CT) | |
699 | + { | |
700 | + | |
701 | + UINT8* ptr = cs.cfg.codec_info; | |
702 | + tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3]; | |
703 | + UINT8 vendorId = codecInfo->vendorId; | |
704 | + UINT8 codecId = codecInfo->codecId; | |
705 | + | |
706 | + if (vendorId == A2D_APTX_VENDOR_ID && | |
707 | + codecId == A2D_APTX_CODEC_ID_BLUETOOTH) | |
708 | + { | |
709 | + if((*bta_av_a2d_cos.cap)(APTX) != TRUE) | |
710 | + { | |
711 | + index++; | |
712 | + continue; | |
713 | + } | |
714 | + else | |
715 | + APPL_TRACE_DEBUG("%s:codec supported",__func__) | |
716 | + } | |
717 | + } | |
718 | + else if (codec_type == AAC) | |
719 | + { | |
720 | + if ((*bta_av_a2d_cos.cap)(AAC) != TRUE) | |
721 | + { | |
722 | + index++; | |
723 | + continue; | |
724 | + } | |
725 | + } | |
726 | + } | |
727 | + else if((codec_type == A2D_NON_A2DP_MEDIA_CT) && (A2D_check_and_init_aptX() == false)) | |
728 | + { | |
729 | + index++; | |
730 | + continue; | |
731 | + } | |
732 | + | |
686 | 733 | if(AVDT_CreateStream(&p_scb->seps[index - startIndex].av_handle, &cs) == |
687 | 734 | AVDT_SUCCESS) |
688 | 735 | { |
@@ -807,6 +854,9 @@ void bta_av_api_deregister(tBTA_AV_DATA *p_data) | ||
807 | 854 | { |
808 | 855 | tBTA_AV_SCB *p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific); |
809 | 856 | |
857 | + // de-initialize aptX | |
858 | + A2D_deinit_aptX(); | |
859 | + | |
810 | 860 | if(p_scb) |
811 | 861 | { |
812 | 862 | p_scb->deregistring = TRUE; |
@@ -930,6 +980,22 @@ static void bta_av_api_enable_multicast(tBTA_AV_DATA *p_data) | ||
930 | 980 | |
931 | 981 | /******************************************************************************* |
932 | 982 | ** |
983 | +** Function bta_av_api_update_max_av_client | |
984 | +** | |
985 | +** Description Update max simultaneous AV connections supported | |
986 | +** | |
987 | +** Returns void | |
988 | +** | |
989 | +*******************************************************************************/ | |
990 | +static void bta_av_api_update_max_av_clients(tBTA_AV_DATA *p_data) | |
991 | +{ | |
992 | + int bta_av_max_clients = p_data->max_av_clients.max_clients; | |
993 | + APPL_TRACE_DEBUG("bta_av_max_clients:%d",bta_av_max_clients); | |
994 | + AVDT_UpdateMaxAvClients(bta_av_max_clients); | |
995 | +} | |
996 | + | |
997 | +/******************************************************************************* | |
998 | +** | |
933 | 999 | ** Function bta_av_chk_start |
934 | 1000 | ** |
935 | 1001 | ** Description if this is audio channel, check if more than one audio |
@@ -490,6 +490,7 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status ) | ||
490 | 490 | void bta_dm_disable (tBTA_DM_MSG *p_data) |
491 | 491 | { |
492 | 492 | UNUSED(p_data); |
493 | + int soc_type = get_soc_type(); | |
493 | 494 | |
494 | 495 | /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after last channel is closed) */ |
495 | 496 | L2CA_SetIdleTimeoutByBdAddr((UINT8 *)BT_BD_ANY, 0, BT_TRANSPORT_BR_EDR); |
@@ -509,11 +510,12 @@ void bta_dm_disable (tBTA_DM_MSG *p_data) | ||
509 | 510 | BTM_BleClearBgConnDev(); |
510 | 511 | #endif |
511 | 512 | |
512 | -#ifdef QLOGKIT_USERDEBUG | |
513 | 513 | /* Disable SOC Logging */ |
514 | - UINT8 param[5] = {0x10,0x02,0x00,0x00,0x01}; | |
515 | - BTM_VendorSpecificCommand(HCI_VS_HOST_LOG_OPCODE,5,param,NULL); | |
516 | -#endif | |
514 | + if (soc_type == BT_SOC_SMD) | |
515 | + { | |
516 | + UINT8 param[5] = {0x10,0x02,0x00,0x00,0x01}; | |
517 | + BTM_VendorSpecificCommand(HCI_VS_HOST_LOG_OPCODE,5,param,NULL); | |
518 | + } | |
517 | 519 | |
518 | 520 | if(BTM_GetNumAclLinks()==0) |
519 | 521 | { |
@@ -3315,9 +3317,12 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data) | ||
3315 | 3317 | { |
3316 | 3318 | if (bta_dm_cb.device_list.count < BTA_DM_NUM_PEER_DEVICE) |
3317 | 3319 | { |
3320 | + /* new acl connection,reset new peer device */ | |
3321 | + memset(&bta_dm_cb.device_list.peer_device[i], 0, sizeof(bta_dm_cb.device_list.peer_device[i])); | |
3318 | 3322 | bdcpy(bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].peer_bdaddr, p_bda); |
3319 | 3323 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].link_policy = bta_dm_cb.cur_policy; |
3320 | 3324 | bta_dm_cb.device_list.count++; |
3325 | + APPL_TRACE_ERROR("%s new acl connetion:count = %d", __func__, bta_dm_cb.device_list.count); | |
3321 | 3326 | #if BLE_INCLUDED == TRUE |
3322 | 3327 | bta_dm_cb.device_list.peer_device[i].conn_handle = p_data->acl_change.handle; |
3323 | 3328 | if (p_data->acl_change.transport == BT_TRANSPORT_LE) |
@@ -3368,10 +3373,12 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data) | ||
3368 | 3373 | |
3369 | 3374 | conn.link_down.is_removed = bta_dm_cb.device_list.peer_device[i].remove_dev_pending; |
3370 | 3375 | |
3371 | - for(; i<bta_dm_cb.device_list.count ; i++) | |
3376 | + /* acl disconnection,remove peer device entry and reset last entry */ | |
3377 | + for(; i < (bta_dm_cb.device_list.count - 1); i++) | |
3372 | 3378 | { |
3373 | 3379 | memcpy(&bta_dm_cb.device_list.peer_device[i], &bta_dm_cb.device_list.peer_device[i+1], sizeof(bta_dm_cb.device_list.peer_device[i])); |
3374 | 3380 | } |
3381 | + memset(&bta_dm_cb.device_list.peer_device[i], 0, sizeof(bta_dm_cb.device_list.peer_device[i])); | |
3375 | 3382 | break; |
3376 | 3383 | } |
3377 | 3384 | if(bta_dm_cb.device_list.count) |
@@ -414,7 +414,7 @@ void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, | ||
414 | 414 | tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); |
415 | 415 | tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); |
416 | 416 | tMCA_RESULT result; |
417 | - tBTA_HL_STATUS status = BTA_HL_STATUS_OK; | |
417 | + tBTA_HL_STATUS status; | |
418 | 418 | BOOLEAN free_buf = FALSE; |
419 | 419 | BOOLEAN close_dch = FALSE; |
420 | 420 | tBTA_HL evt_data; |
@@ -423,7 +423,11 @@ void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, | ||
423 | 423 | #if (BTA_HL_DEBUG == TRUE) |
424 | 424 | APPL_TRACE_DEBUG("bta_hl_dch_ci_get_tx_data"); |
425 | 425 | #endif |
426 | - | |
426 | + if (p_data != NULL) | |
427 | + { | |
428 | + status = p_data->ci_get_put_data.status; | |
429 | + APPL_TRACE_WARNING("bta_hl_dch_ci_put_rx_data:status=%d", status); | |
430 | + } | |
427 | 431 | p_dcb->cout_oper &= ~BTA_HL_CO_GET_TX_DATA_MASK; |
428 | 432 | |
429 | 433 | if (p_dcb->close_pending) |
@@ -436,6 +440,10 @@ void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, | ||
436 | 440 | close_dch = TRUE; |
437 | 441 | } |
438 | 442 | } |
443 | + else if (status == BTA_HL_STATUS_FAIL) | |
444 | + { | |
445 | + free_buf = TRUE; | |
446 | + } | |
439 | 447 | else |
440 | 448 | { |
441 | 449 | if ((result = MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_tx_pkt)) != MCA_SUCCESS) |
@@ -704,6 +704,17 @@ void BTA_AvEnableMultiCast(BOOLEAN state, tBTA_AV_HNDL handle); | ||
704 | 704 | |
705 | 705 | /******************************************************************************* |
706 | 706 | ** |
707 | +** Function BTA_AvUpdateMaxAVClient | |
708 | +** | |
709 | +** Description Update max simultaneous AV connections supported | |
710 | +** | |
711 | +** Returns void | |
712 | +** | |
713 | +*******************************************************************************/ | |
714 | +void BTA_AvUpdateMaxAVClient(UINT8 max_clients); | |
715 | + | |
716 | +/******************************************************************************* | |
717 | +** | |
707 | 718 | ** Function BTA_AvReconfig |
708 | 719 | ** |
709 | 720 | ** Description Reconfigure the audio/video stream. |
@@ -401,4 +401,28 @@ extern void bta_av_co_audio_delay(tBTA_AV_HNDL hndl, UINT16 delay); | ||
401 | 401 | *******************************************************************************/ |
402 | 402 | extern void bta_av_co_video_delay(tBTA_AV_HNDL hndl, UINT16 delay); |
403 | 403 | |
404 | +/******************************************************************************* | |
405 | +** | |
406 | +** Function bta_av_co_audio_is_offload_supported | |
407 | +** | |
408 | +** Description This function is called by AV to check if DUT is in offload | |
409 | +** mode. | |
410 | +** | |
411 | +** Returns TRUE if offload is enabled, FALSE otherwise | |
412 | +** | |
413 | +*******************************************************************************/ | |
414 | +extern BOOLEAN bta_av_co_audio_is_offload_supported(void); | |
415 | + | |
416 | +/******************************************************************************* | |
417 | +** | |
418 | +** Function bta_av_co_audio_is_codec_supported | |
419 | +** | |
420 | +** Description This function is called by AV to check if corresponding | |
421 | +** codec is supported in offload mode. | |
422 | +** | |
423 | +** Returns TRUE if codec is supported in offload, FALSE otherwise | |
424 | +** | |
425 | +*******************************************************************************/ | |
426 | +extern BOOLEAN bta_av_co_audio_is_codec_supported(int codec); | |
427 | + | |
404 | 428 | #endif /* BTA_AV_CO_H */ |
@@ -2185,25 +2185,25 @@ static void bta_jv_pm_conn_busy(tBTA_JV_PM_CB *p_cb) | ||
2185 | 2185 | { |
2186 | 2186 | if ((NULL != p_cb) && (BTA_JV_PM_IDLE_ST == p_cb->state)) |
2187 | 2187 | { |
2188 | - tBTM_PM_MODE mode = BTM_PM_MD_ACTIVE; | |
2189 | - if (BTM_ReadPowerMode(p_cb->peer_bd_addr, &mode) == BTM_SUCCESS) { | |
2190 | - if (mode == BTM_PM_MD_SNIFF) { | |
2191 | - bta_jv_pm_state_change(p_cb, BTA_JV_CONN_BUSY); | |
2192 | - } else { | |
2193 | - p_cb->state = BTA_JV_PM_BUSY_ST; | |
2194 | - APPL_TRACE_DEBUG("bta_jv_pm_conn_busy:power mode: %d", mode); | |
2195 | - } | |
2196 | - } else { | |
2197 | - bta_jv_pm_state_change(p_cb, BTA_JV_CONN_BUSY); | |
2188 | + if (alarm_is_scheduled(p_cb->idle_timer)) | |
2189 | + { | |
2190 | + alarm_cancel(p_cb->idle_timer); | |
2191 | + p_cb->state = BTA_JV_PM_BUSY_ST; | |
2192 | + } | |
2193 | + else | |
2194 | + { | |
2195 | + APPL_TRACE_DEBUG("bta_jv_pm_conn_busy"); | |
2196 | + bta_jv_pm_state_change(p_cb, BTA_JV_CONN_BUSY); | |
2198 | 2197 | } |
2199 | 2198 | } |
2199 | + | |
2200 | 2200 | } |
2201 | 2201 | |
2202 | 2202 | /******************************************************************************* |
2203 | 2203 | ** |
2204 | - ** Function bta_jv_pm_conn_busy | |
2204 | + ** Function bta_jv_pm_conn_idle | |
2205 | 2205 | ** |
2206 | - ** Description set pm connection busy state (input param safe) | |
2206 | + ** Description set pm connection idle state (input param safe) | |
2207 | 2207 | ** |
2208 | 2208 | ** Params p_cb: pm control block of jv connection |
2209 | 2209 | ** |
@@ -2215,11 +2215,9 @@ static void bta_jv_pm_conn_idle(tBTA_JV_PM_CB *p_cb) | ||
2215 | 2215 | if ((NULL != p_cb) && (BTA_JV_PM_IDLE_ST != p_cb->state)) { |
2216 | 2216 | APPL_TRACE_DEBUG("bta_jv_pm_conn_idle, p_cb: %p", p_cb); |
2217 | 2217 | p_cb->state = BTA_JV_PM_IDLE_ST; |
2218 | - // start intermediate idle timer for 1s | |
2219 | - if (!alarm_is_scheduled(p_cb->idle_timer)) { | |
2220 | - alarm_set_on_queue(p_cb->idle_timer, BTA_JV_IDLE_TIMEOUT_MS, | |
2221 | - bta_jv_idle_timeout_handler, p_cb, btu_general_alarm_queue); | |
2222 | - } | |
2218 | + /* start intermediate idle timer for 1s */ | |
2219 | + alarm_set_on_queue(p_cb->idle_timer, BTA_JV_IDLE_TIMEOUT_MS, | |
2220 | + bta_jv_idle_timeout_handler, p_cb, btu_general_alarm_queue); | |
2223 | 2221 | } |
2224 | 2222 | } |
2225 | 2223 |
@@ -2710,18 +2708,8 @@ extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data) | ||
2710 | 2708 | void bta_jv_idle_timeout_handler(void *tle) { |
2711 | 2709 | tBTA_JV_PM_CB *p_cb = (tBTA_JV_PM_CB *)tle;; |
2712 | 2710 | APPL_TRACE_DEBUG("%s p_cb: %p", __func__, p_cb); |
2713 | - | |
2714 | - if (NULL != p_cb) { | |
2715 | - | |
2716 | - tBTM_PM_MODE mode = BTM_PM_MD_ACTIVE; | |
2717 | - if (BTM_ReadPowerMode(p_cb->peer_bd_addr, &mode) == BTM_SUCCESS) { | |
2718 | - if (mode == BTM_PM_MD_SNIFF) { | |
2719 | - APPL_TRACE_WARNING("%s: %d", __func__, mode) | |
2720 | - return; | |
2721 | - } | |
2722 | - } else { | |
2723 | - APPL_TRACE_DEBUG("%s: Read power mode failed %d", __func__, mode); | |
2724 | - } | |
2711 | + if ((NULL != p_cb) && (BTA_JV_PM_IDLE_ST == p_cb->state)) | |
2712 | + { | |
2725 | 2713 | bta_jv_pm_state_change(p_cb, BTA_JV_CONN_IDLE); |
2726 | 2714 | } |
2727 | 2715 | } |
@@ -236,6 +236,7 @@ extern BOOLEAN btif_av_is_codec_offload_supported(int codec); | ||
236 | 236 | #else |
237 | 237 | #define btif_av_is_codec_offload_supported(codec) (0) |
238 | 238 | #endif |
239 | +extern BOOLEAN btif_av_is_offload_supported(); | |
239 | 240 | extern BOOLEAN bt_split_a2dp_enabled; |
240 | 241 | /******************************************************************************* |
241 | 242 | ** |
@@ -1996,7 +1997,15 @@ UINT8 bta_av_select_codec(UINT8 hdl) | ||
1996 | 1997 | APPL_TRACE_ERROR("%s hdl = %d",__func__,hdl); |
1997 | 1998 | /* Retrieve the peer info */ |
1998 | 1999 | p_peer = bta_av_co_get_peer(hdl); |
1999 | - bta_av_co_audio_peer_supports_codec(p_peer,&index); | |
2000 | + /* Fix for below KW Issue | |
2001 | + Pointer 'p_peer' returned from call to function 'bta_av_co_get_peer' at line | |
2002 | + 1993 may be NULL, will be passed to function and may be dereferenced there | |
2003 | + by passing argument 1 to function 'bta_av_co_audio_peer_supports_codec' at | |
2004 | + line 2001.*/ | |
2005 | + if (p_peer != NULL) | |
2006 | + { | |
2007 | + bta_av_co_audio_peer_supports_codec(p_peer,&index); | |
2008 | + } | |
2000 | 2009 | return bta_av_co_cb.codec_cfg->id; |
2001 | 2010 | } |
2002 | 2011 | } |
@@ -2281,3 +2290,33 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max) | ||
2281 | 2290 | |
2282 | 2291 | return TRUE; |
2283 | 2292 | } |
2293 | + | |
2294 | +/******************************************************************************* | |
2295 | +** | |
2296 | +** Function bta_av_co_audio_is_offload_supported | |
2297 | +** | |
2298 | +** Description This function is called by AV to check if DUT is in offload | |
2299 | +** mode. | |
2300 | +** | |
2301 | +** Returns TRUE if offload is enabled, FALSE otherwise | |
2302 | +** | |
2303 | +*******************************************************************************/ | |
2304 | +BOOLEAN bta_av_co_audio_is_offload_supported(void) | |
2305 | +{ | |
2306 | + return btif_av_is_offload_supported(); | |
2307 | +} | |
2308 | + | |
2309 | +/******************************************************************************* | |
2310 | +** | |
2311 | +** Function bta_av_co_audio_is_codec_supported | |
2312 | +** | |
2313 | +** Description This function is called by AV to check if corresponding | |
2314 | +** codec is supported in offload mode. | |
2315 | +** | |
2316 | +** Returns TRUE if codec is supported in offload, FALSE otherwise | |
2317 | +** | |
2318 | +*******************************************************************************/ | |
2319 | +BOOLEAN bta_av_co_audio_is_codec_supported(int codec) | |
2320 | +{ | |
2321 | + return btif_av_is_codec_offload_supported(codec); | |
2322 | +} |
@@ -250,8 +250,24 @@ static int uhid_read_event(btif_hh_device_t *p_dev) | ||
250 | 250 | btif_hh_setreport(p_dev, BTHH_FEATURE_REPORT, |
251 | 251 | ev.u.output.size, ev.u.output.data); |
252 | 252 | else if(ev.u.output.rtype == UHID_OUTPUT_REPORT) |
253 | + { | |
254 | + if (ev.u.output.size == BTIF_HH_OUTPUT_REPORT_SIZE && | |
255 | + !memcmp(&p_dev->last_output_rpt_data, &ev.u.output.data, | |
256 | + BTIF_HH_OUTPUT_REPORT_SIZE)) { | |
257 | + /* Last output report same as current output report, don't inform to remote | |
258 | + * device as this could be the case when reports are being sent due to | |
259 | + * device suspend/resume. If same output report is sent to remote device | |
260 | + * device which uses UART as transport might not be able to suspend at all | |
261 | + * leading to higher battery drain. | |
262 | + */ | |
263 | + APPL_TRACE_VERBOSE("UHID_OUTPUT: data same returning"); | |
264 | + return 0; | |
265 | + } | |
266 | + /* Copy new output report data for future tracking */ | |
267 | + memcpy(&p_dev->last_output_rpt_data, &ev.u.output.data, ev.u.output.size); | |
253 | 268 | btif_hh_setreport(p_dev, BTHH_OUTPUT_REPORT, |
254 | 269 | ev.u.output.size, ev.u.output.data); |
270 | + } | |
255 | 271 | else |
256 | 272 | btif_hh_setreport(p_dev, BTHH_INPUT_REPORT, |
257 | 273 | ev.u.output.size, ev.u.output.data); |
@@ -512,6 +528,7 @@ void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, tBTA_HH_ATTR_MASK attr_ma | ||
512 | 528 | |
513 | 529 | p_dev->dev_status = BTHH_CONN_STATE_CONNECTED; |
514 | 530 | APPL_TRACE_DEBUG("%s: allocating the set_rpt_id_list", __func__); |
531 | + memset(&p_dev->last_output_rpt_data, 0, BTIF_HH_OUTPUT_REPORT_SIZE); | |
515 | 532 | p_dev->set_rpt_id_list = list_new(lst_free_cb); |
516 | 533 | if (!p_dev->set_rpt_id_list) { |
517 | 534 | APPL_TRACE_ERROR("%s: unable to create list", __func__); |
@@ -555,6 +572,7 @@ void bta_hh_co_close(UINT8 dev_handle, UINT8 app_id) | ||
555 | 572 | "dev_status = %d, dev_handle =%d" |
556 | 573 | ,__func__,p_dev->dev_status |
557 | 574 | ,p_dev->dev_handle); |
575 | + memset(&p_dev->last_output_rpt_data, 0, BTIF_HH_OUTPUT_REPORT_SIZE); | |
558 | 576 | btif_hh_close_poll_thread(p_dev); |
559 | 577 | break; |
560 | 578 | } |
@@ -332,7 +332,7 @@ void bta_hl_co_get_tx_data (UINT8 app_id, tBTA_HL_MDL_HANDLE mdl_handle, | ||
332 | 332 | { |
333 | 333 | p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); |
334 | 334 | |
335 | - if (p_dcb->tx_size <= buf_size ) | |
335 | + if ((p_dcb->tx_size <= buf_size) && p_dcb->p_tx_pkt) | |
336 | 336 | { |
337 | 337 | memcpy(p_buf, p_dcb->p_tx_pkt, p_dcb->tx_size); |
338 | 338 | osi_free_and_reset((void **)&p_dcb->p_tx_pkt); |
@@ -341,7 +341,7 @@ void bta_hl_co_get_tx_data (UINT8 app_id, tBTA_HL_MDL_HANDLE mdl_handle, | ||
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | - | |
344 | + BTIF_TRACE_WARNING("%s status = %d ", __FUNCTION__, status); | |
345 | 345 | bta_hl_ci_get_tx_data(mdl_handle, status, evt); |
346 | 346 | |
347 | 347 | } |
@@ -38,7 +38,7 @@ | ||
38 | 38 | #define BTIF_HH_KEYSTATE_MASK_NUMLOCK 0x01 |
39 | 39 | #define BTIF_HH_KEYSTATE_MASK_CAPSLOCK 0x02 |
40 | 40 | #define BTIF_HH_KEYSTATE_MASK_SCROLLLOCK 0x04 |
41 | - | |
41 | +#define BTIF_HH_OUTPUT_REPORT_SIZE 2 | |
42 | 42 | |
43 | 43 | /******************************************************************************* |
44 | 44 | ** Type definitions and return values |
@@ -71,6 +71,7 @@ typedef struct | ||
71 | 71 | list_t *set_rpt_id_list; // Owns a collection of set_rpt_id objects. |
72 | 72 | UINT8 get_rpt_snt; |
73 | 73 | BOOLEAN local_vup; // Indicated locally initiated VUP |
74 | + UINT8 last_output_rpt_data[BTIF_HH_OUTPUT_REPORT_SIZE]; | |
74 | 75 | } btif_hh_device_t; |
75 | 76 | |
76 | 77 | /* Control block to maintain properties of devices */ |
@@ -48,6 +48,7 @@ | ||
48 | 48 | #include "bt_utils.h" |
49 | 49 | #include "btif_api.h" |
50 | 50 | #include "btif_common.h" |
51 | +#include "device/include/controller.h" | |
51 | 52 | #include "btif_debug.h" |
52 | 53 | #include "btsnoop.h" |
53 | 54 | #include "btsnoop_mem.h" |
@@ -527,6 +528,8 @@ int config_hci_snoop_log(uint8_t enable) | ||
527 | 528 | return BT_STATUS_NOT_READY; |
528 | 529 | |
529 | 530 | btsnoop_get_interface()->set_api_wants_to_log(enable); |
531 | + controller_get_static_interface()->enable_soc_logging(enable); | |
532 | + | |
530 | 533 | return BT_STATUS_SUCCESS; |
531 | 534 | } |
532 | 535 |
@@ -51,6 +51,7 @@ | ||
51 | 51 | /* Now supports Two AV connections. */ |
52 | 52 | #define BTIF_AV_NUM_CB 2 |
53 | 53 | #define HANDLE_TO_INDEX(x) ((x & BTA_AV_HNDL_MSK) - 1) |
54 | +#define INVALID_INDEX -1 | |
54 | 55 | |
55 | 56 | typedef enum { |
56 | 57 | BTIF_AV_STATE_IDLE = 0x0, |
@@ -225,7 +226,7 @@ void btif_av_update_multicast_state(int index); | ||
225 | 226 | BOOLEAN btif_av_get_ongoing_multicast(); |
226 | 227 | tBTA_AV_HNDL btif_av_get_playing_device_hdl(); |
227 | 228 | tBTA_AV_HNDL btif_av_get_av_hdl_from_idx(UINT8 idx); |
228 | -UINT8 btif_av_get_other_connected_idx(int current_index); | |
229 | +int btif_av_get_other_connected_idx(int current_index); | |
229 | 230 | #ifdef BTA_AV_SPLIT_A2DP_ENABLED |
230 | 231 | BOOLEAN btif_av_is_codec_offload_supported(int codec); |
231 | 232 | int btif_av_get_current_playing_dev_idx(); |
@@ -1475,7 +1476,7 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data | ||
1475 | 1476 | btif_av_is_connected_on_other_idx(index)) |
1476 | 1477 | { |
1477 | 1478 | BTIF_TRACE_DEBUG("%s: Notify framework to reconfig",__func__); |
1478 | - uint8_t idx = btif_av_get_other_connected_idx(index); | |
1479 | + int idx = btif_av_get_other_connected_idx(index); | |
1479 | 1480 | HAL_CBACK(bt_av_src_callbacks, reconfig_a2dp_trigger_cb, 1, |
1480 | 1481 | &(btif_av_cb[idx].peer_bda)); |
1481 | 1482 | } |
@@ -2478,7 +2479,9 @@ void btif_av_trigger_dual_handoff(BOOLEAN handoff, BD_ADDR address) | ||
2478 | 2479 | { |
2479 | 2480 | btif_media_send_reset_vendor_state(); |
2480 | 2481 | next_idx = btif_av_get_other_connected_idx(index); |
2481 | - if (next_idx != btif_max_av_clients) | |
2482 | + /* Fix for below Klockwork Issue | |
2483 | + Array 'btif_av_cb' of size 2 may use index value(s) -1 */ | |
2484 | + if (next_idx != INVALID_INDEX && next_idx != btif_max_av_clients) | |
2482 | 2485 | { |
2483 | 2486 | HAL_CBACK(bt_av_src_callbacks, reconfig_a2dp_trigger_cb, 1, |
2484 | 2487 | &(btif_av_cb[next_idx].peer_bda)); |
@@ -2890,13 +2893,14 @@ void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len) | ||
2890 | 2893 | *******************************************************************************/ |
2891 | 2894 | bt_status_t btif_av_execute_service(BOOLEAN b_enable) |
2892 | 2895 | { |
2893 | - int i; | |
2894 | - BTIF_TRACE_IMP("%s: enable: %d", __FUNCTION__, b_enable); | |
2895 | - if (b_enable) | |
2896 | - { | |
2897 | - /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not | |
2898 | - * handle this request in order to allow incoming connections to succeed. | |
2899 | - * We need to put this back once support for this is added */ | |
2896 | + int i; | |
2897 | + btif_sm_state_t state; | |
2898 | + BTIF_TRACE_IMP("%s: enable: %d", __FUNCTION__, b_enable); | |
2899 | + if (b_enable) | |
2900 | + { | |
2901 | + /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not | |
2902 | + * handle this request in order to allow incoming connections to succeed. | |
2903 | + * We need to put this back once support for this is added */ | |
2900 | 2904 | |
2901 | 2905 | /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not |
2902 | 2906 | * auto-suspend av streaming on AG events(SCO or Call). The suspend shall |
@@ -2921,6 +2925,7 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable) | ||
2921 | 2925 | BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, |
2922 | 2926 | UUID_SERVCLASS_AUDIO_SOURCE); |
2923 | 2927 | } |
2928 | + BTA_AvUpdateMaxAVClient(btif_max_av_clients); | |
2924 | 2929 | } |
2925 | 2930 | else |
2926 | 2931 | { |
@@ -2929,7 +2934,13 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable) | ||
2929 | 2934 | { |
2930 | 2935 | if (btif_av_cb[i].sm_handle != NULL) |
2931 | 2936 | { |
2932 | - BTIF_TRACE_IMP("%s: shutting down AV SM", __FUNCTION__); | |
2937 | + state = btif_sm_get_state(btif_av_cb[i].sm_handle); | |
2938 | + if(state==BTIF_AV_STATE_OPENING) | |
2939 | + { | |
2940 | + BTIF_TRACE_DEBUG("Moving State from Opening to Idle due to BT ShutDown"); | |
2941 | + btif_sm_change_state(btif_av_cb[i].sm_handle, BTIF_AV_STATE_IDLE); | |
2942 | + btif_queue_advance(); | |
2943 | + } | |
2933 | 2944 | btif_sm_shutdown(btif_av_cb[i].sm_handle); |
2934 | 2945 | btif_av_cb[i].sm_handle = NULL; |
2935 | 2946 | } |
@@ -3065,7 +3076,7 @@ BOOLEAN btif_av_is_connected_on_other_idx(int current_index) | ||
3065 | 3076 | ** Returns BOOLEAN |
3066 | 3077 | ** |
3067 | 3078 | *******************************************************************************/ |
3068 | -UINT8 btif_av_get_other_connected_idx(int current_index) | |
3079 | +int btif_av_get_other_connected_idx(int current_index) | |
3069 | 3080 | { |
3070 | 3081 | //return true if other IDx is connected |
3071 | 3082 | btif_sm_state_t state = BTIF_AV_STATE_IDLE; |
@@ -3080,7 +3091,7 @@ UINT8 btif_av_get_other_connected_idx(int current_index) | ||
3080 | 3091 | return i; |
3081 | 3092 | } |
3082 | 3093 | } |
3083 | - return -1; | |
3094 | + return INVALID_INDEX; | |
3084 | 3095 | } |
3085 | 3096 | |
3086 | 3097 | /******************************************************************************* |
@@ -3459,6 +3470,19 @@ BOOLEAN btif_av_get_ongoing_multicast() | ||
3459 | 3470 | } |
3460 | 3471 | } |
3461 | 3472 | |
3473 | +/****************************************************************************** | |
3474 | +** | |
3475 | +** Function btif_av_is_offload_supported | |
3476 | +** | |
3477 | +** Description Returns split mode status | |
3478 | +** | |
3479 | +** Returns TRUE if split mode is enabled, FALSE otherwise | |
3480 | +********************************************************************************/ | |
3481 | +BOOLEAN btif_av_is_offload_supported() | |
3482 | +{ | |
3483 | + return bt_split_a2dp_enabled; | |
3484 | +} | |
3485 | + | |
3462 | 3486 | #ifdef BTA_AV_SPLIT_A2DP_ENABLED |
3463 | 3487 | int btif_av_get_current_playing_dev_idx(void) |
3464 | 3488 | { |
@@ -64,6 +64,8 @@ | ||
64 | 64 | /****************************************************************************** |
65 | 65 | ** Constants & Macros |
66 | 66 | ******************************************************************************/ |
67 | +#define BTIF_DM_GET_REMOTE_PROP(b,t,v,l,p) \ | |
68 | + {p.type=t;p.val=v;p.len=l;btif_storage_get_remote_device_property(b,&p);} | |
67 | 69 | |
68 | 70 | #define COD_MASK 0x07FF |
69 | 71 |
@@ -855,6 +857,21 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transpor | ||
855 | 857 | *******************************************************************************/ |
856 | 858 | void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr) |
857 | 859 | { |
860 | + bt_bdname_t alias; | |
861 | + bt_property_t properties[1]; | |
862 | + uint32_t num_properties = 0; | |
863 | + memset(&alias, 0, sizeof(alias)); | |
864 | + BTIF_DM_GET_REMOTE_PROP(bd_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, | |
865 | + &alias, sizeof(alias), properties[num_properties]); | |
866 | + | |
867 | + if(alias.name[0] != '\0') { | |
868 | + properties[0].type = BT_PROPERTY_REMOTE_FRIENDLY_NAME; | |
869 | + properties[0].val = (void *) ""; | |
870 | + properties[0].len = 1; | |
871 | + | |
872 | + btif_storage_set_remote_device_property(bd_addr, &properties[0]); | |
873 | + } | |
874 | + | |
858 | 875 | /*special handling for HID devices */ |
859 | 876 | /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there |
860 | 877 | is a valid hid connection with this bd_addr. If yes VUP will be issued.*/ |
@@ -1477,6 +1494,10 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
1477 | 1494 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
1478 | 1495 | int addr_type = 0; |
1479 | 1496 | #endif |
1497 | + bt_bdname_t alias; | |
1498 | + memset(&alias, 0, sizeof(alias)); | |
1499 | + BTIF_DM_GET_REMOTE_PROP(&bdaddr, BT_PROPERTY_REMOTE_FRIENDLY_NAME, | |
1500 | + &alias, sizeof(alias), properties[num_properties]); | |
1480 | 1501 | |
1481 | 1502 | memset(properties, 0, sizeof(properties)); |
1482 | 1503 | /* BD_ADDR */ |
@@ -1485,7 +1506,14 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
1485 | 1506 | num_properties++; |
1486 | 1507 | /* BD_NAME */ |
1487 | 1508 | /* Don't send BDNAME if it is empty */ |
1488 | - if (bdname.name[0]) | |
1509 | + /* send alias name as the name if alias name present */ | |
1510 | + if(alias.name[0] != '\0') { | |
1511 | + BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], | |
1512 | + BT_PROPERTY_BDNAME, | |
1513 | + strlen((char *)alias.name), &alias); | |
1514 | + num_properties++; | |
1515 | + } | |
1516 | + else if (bdname.name[0]) | |
1489 | 1517 | { |
1490 | 1518 | if((check_eir_is_remote_name_short(p_search_data) == TRUE) && |
1491 | 1519 | (btif_storage_is_device_bonded(&bdaddr) == TRUE)) |
@@ -42,7 +42,6 @@ | ||
42 | 42 | #include <pthread.h> |
43 | 43 | #include <stdint.h> |
44 | 44 | #include <stdio.h> |
45 | -#include <dlfcn.h> | |
46 | 45 | #include <string.h> |
47 | 46 | #include <sys/stat.h> |
48 | 47 | #include <sys/time.h> |
@@ -51,6 +50,12 @@ | ||
51 | 50 | |
52 | 51 | #include <hardware/bluetooth.h> |
53 | 52 | |
53 | +#include "osi/include/alarm.h" | |
54 | +#include "osi/include/fixed_queue.h" | |
55 | +#include "osi/include/log.h" | |
56 | +#include "osi/include/metrics.h" | |
57 | +#include "osi/include/mutex.h" | |
58 | +#include "osi/include/thread.h" | |
54 | 59 | #include "bt_utils.h" |
55 | 60 | #include "a2d_api.h" |
56 | 61 | #include "a2d_int.h" |
@@ -73,12 +78,6 @@ | ||
73 | 78 | #include "bt_common.h" |
74 | 79 | #include "device/include/controller.h" |
75 | 80 | #include "l2c_api.h" |
76 | -#include "osi/include/alarm.h" | |
77 | -#include "osi/include/fixed_queue.h" | |
78 | -#include "osi/include/log.h" | |
79 | -#include "osi/include/metrics.h" | |
80 | -#include "osi/include/mutex.h" | |
81 | -#include "osi/include/thread.h" | |
82 | 81 | |
83 | 82 | #if (BTA_AV_INCLUDED == TRUE) |
84 | 83 | #include "sbc_encoder.h" |
@@ -513,20 +512,6 @@ static thread_t *worker_thread; | ||
513 | 512 | BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type); |
514 | 513 | UINT8 bta_av_get_current_codec(); |
515 | 514 | |
516 | -const char *A2D_APTX_SCHED_LIB_NAME = "libaptXScheduler.so"; | |
517 | -BOOLEAN btif_check_and_init_aptX(); | |
518 | -int (*A2D_aptx_sched_init)(void); | |
519 | -A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder, | |
520 | - A2D_AptXCodecType aptX_codec_type, BOOLEAN use_SCMS_T, | |
521 | - UINT16 sample_rate, UINT8 format_bits, UINT8 channel, | |
522 | - A2D_AptXReadFn read_fn, A2D_AptXBufferSendFn send_fn, | |
523 | - A2D_AptXSetPriorityFn set_priority_fn, BOOLEAN test, | |
524 | - BOOLEAN trace); | |
525 | -BOOLEAN (*A2D_aptx_sched_stop)(void); | |
526 | -void (*A2D_aptx_sched_deinit)(void); | |
527 | -void *A2dAptXSchedLibHandle = NULL; | |
528 | -BOOLEAN isA2dAptXEnabled = false; | |
529 | - | |
530 | 515 | extern BOOLEAN bt_split_a2dp_enabled; |
531 | 516 | extern int btif_max_av_clients; |
532 | 517 | static uint8_t multicast_query = FALSE; |
@@ -1174,6 +1159,7 @@ static void btif_a2dp_encoder_init(tBTA_AV_HNDL hdl) | ||
1174 | 1159 | bta_av_co_audio_get_codec_config((UINT8*)&aptx_config, &minmtu, A2D_NON_A2DP_MEDIA_CT); |
1175 | 1160 | msg.CodecType = A2D_NON_A2DP_MEDIA_CT; |
1176 | 1161 | msg.SamplingFreq = aptx_config.sampleRate; |
1162 | + msg.MtuSize = minmtu; | |
1177 | 1163 | msg.ChannelMode = aptx_config.channelMode; |
1178 | 1164 | msg.BluetoothVendorID = aptx_config.vendorId; |
1179 | 1165 | msg.BluetoothCodecID = aptx_config.codecId; |
@@ -1301,97 +1287,6 @@ bool btif_a2dp_is_media_task_stopped(void) | ||
1301 | 1287 | return true; |
1302 | 1288 | } |
1303 | 1289 | |
1304 | -// returns true if aptX codec initialization succeeds, false otherwise | |
1305 | -BOOLEAN btif_check_and_init_aptX(void) | |
1306 | -{ | |
1307 | - APPL_TRACE_DEBUG("btif_check_and_init_aptX"); | |
1308 | - | |
1309 | - if (A2dAptXSchedLibHandle == NULL) | |
1310 | - { | |
1311 | - A2dAptXSchedLibHandle = dlopen(A2D_APTX_SCHED_LIB_NAME, RTLD_NOW); | |
1312 | - | |
1313 | - if (!A2dAptXSchedLibHandle) | |
1314 | - { | |
1315 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler library missing"); | |
1316 | - goto error_exit; | |
1317 | - } | |
1318 | - | |
1319 | - A2D_aptx_sched_init = (int (*)(void))dlsym(A2dAptXSchedLibHandle, | |
1320 | - "aptx_scheduler_init"); | |
1321 | - if (!A2D_aptx_sched_init) | |
1322 | - { | |
1323 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler init missing"); | |
1324 | - goto error_exit; | |
1325 | - } | |
1326 | - | |
1327 | - A2D_aptx_sched_start = (A2D_AptXThreadFn (*)(void*, A2D_AptXCodecType, BOOLEAN, | |
1328 | - UINT16, UINT8, UINT8, A2D_AptXReadFn, | |
1329 | - A2D_AptXBufferSendFn, | |
1330 | - A2D_AptXSetPriorityFn, BOOLEAN, | |
1331 | - BOOLEAN))dlsym(A2dAptXSchedLibHandle, | |
1332 | - "aptx_scheduler_start"); | |
1333 | - if (!A2D_aptx_sched_start) | |
1334 | - { | |
1335 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler start missing"); | |
1336 | - goto error_exit; | |
1337 | - } | |
1338 | - | |
1339 | - A2D_aptx_sched_stop = (BOOLEAN (*)(void))dlsym(A2dAptXSchedLibHandle, | |
1340 | - "aptx_scheduler_stop"); | |
1341 | - if (!A2D_aptx_sched_stop) | |
1342 | - { | |
1343 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler stop missing"); | |
1344 | - goto error_exit; | |
1345 | - } | |
1346 | - | |
1347 | - A2D_aptx_sched_deinit = (void (*)(void))dlsym(A2dAptXSchedLibHandle, | |
1348 | - "aptx_scheduler_deinit"); | |
1349 | - if (!A2D_aptx_sched_deinit) | |
1350 | - { | |
1351 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler deinit missing"); | |
1352 | - goto error_exit; | |
1353 | - } | |
1354 | - | |
1355 | - if (A2D_aptx_sched_init()) | |
1356 | - { | |
1357 | - APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler init failed"); | |
1358 | - goto error_exit; | |
1359 | - } | |
1360 | - } | |
1361 | - | |
1362 | - return true; | |
1363 | - | |
1364 | - error_exit:; | |
1365 | - if (A2dAptXSchedLibHandle) | |
1366 | - { | |
1367 | - dlclose(A2dAptXSchedLibHandle); | |
1368 | - A2dAptXSchedLibHandle = NULL; | |
1369 | - } | |
1370 | - return false; | |
1371 | - | |
1372 | -} | |
1373 | - | |
1374 | -void btif_aptX_deinit(void) | |
1375 | -{ | |
1376 | - APPL_TRACE_DEBUG("btif_aptX_deinit"); | |
1377 | - | |
1378 | - if (isA2dAptXEnabled && A2dAptXSchedLibHandle) | |
1379 | - { | |
1380 | - if (aptx_thread) | |
1381 | - { | |
1382 | - A2D_aptx_sched_stop(); | |
1383 | - thread_free(aptx_thread); | |
1384 | - aptx_thread = NULL; | |
1385 | - } | |
1386 | - A2D_aptx_sched_deinit(); | |
1387 | - dlclose(A2dAptXSchedLibHandle); | |
1388 | - A2dAptXSchedLibHandle = NULL; | |
1389 | - isA2dAptXEnabled = false; | |
1390 | - } | |
1391 | - | |
1392 | - return; | |
1393 | -} | |
1394 | - | |
1395 | 1290 | bool btif_a2dp_start_media_task(void) |
1396 | 1291 | { |
1397 | 1292 | if (media_task_running != MEDIA_TASK_STATE_OFF) |
@@ -1416,9 +1311,6 @@ bool btif_a2dp_start_media_task(void) | ||
1416 | 1311 | btif_media_thread_handle_cmd, |
1417 | 1312 | NULL); |
1418 | 1313 | |
1419 | - // Check if aptX codec is supported | |
1420 | - isA2dAptXEnabled = btif_check_and_init_aptX(); | |
1421 | - | |
1422 | 1314 | thread_post(worker_thread, btif_media_thread_init, NULL); |
1423 | 1315 | APPL_TRACE_IMP("## A2DP MEDIA THREAD STARTED ##"); |
1424 | 1316 |
@@ -1441,8 +1333,13 @@ void btif_a2dp_stop_media_task(void) | ||
1441 | 1333 | /* make sure no channels are restarted while shutting down */ |
1442 | 1334 | media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN; |
1443 | 1335 | |
1444 | - // uninitialize aptX | |
1445 | - btif_aptX_deinit(); | |
1336 | + // remove aptX thread | |
1337 | + if (A2d_aptx_thread) | |
1338 | + { | |
1339 | + A2D_aptx_sched_stop(); | |
1340 | + thread_free(A2d_aptx_thread); | |
1341 | + A2d_aptx_thread = NULL; | |
1342 | + } | |
1446 | 1343 | |
1447 | 1344 | // Stop timer |
1448 | 1345 | alarm_free(btif_media_cb.media_alarm); |
@@ -2179,7 +2076,16 @@ static void btif_media_thread_handle_cmd(fixed_queue_t *queue, UNUSED_ATTR void | ||
2179 | 2076 | to connect to second other device |
2180 | 2077 | */ |
2181 | 2078 | btif_media_send_reset_vendor_state(); |
2182 | - a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); | |
2079 | + if (btif_media_cb.a2dp_cmd_pending == A2DP_CTRL_CMD_SUSPEND || | |
2080 | + btif_media_cb.a2dp_cmd_pending == A2DP_CTRL_CMD_STOP) | |
2081 | + { | |
2082 | + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS); | |
2083 | + } | |
2084 | + else | |
2085 | + { | |
2086 | + APPL_TRACE_ERROR("wrong cmd pending"); | |
2087 | + a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE); | |
2088 | + } | |
2183 | 2089 | break; |
2184 | 2090 | case BTIF_MEDIA_VS_A2DP_STOP_FAILURE: |
2185 | 2091 | btif_media_cb.tx_stop_initiated = FALSE; |
@@ -3349,28 +3255,30 @@ static void btif_media_task_aa_start_tx(void) | ||
3349 | 3255 | BOOLEAN use_SCMS_T = false; |
3350 | 3256 | #endif |
3351 | 3257 | A2D_AptXCodecType aptX_codec_type = btif_media_task_get_aptX_codec_type(); |
3258 | + BOOLEAN is_24bit_audio = false; | |
3352 | 3259 | |
3353 | 3260 | BOOLEAN test = false; |
3354 | 3261 | BOOLEAN trace = false; |
3355 | 3262 | |
3356 | - A2D_AptXThreadFn aptx_thread_fn = A2D_aptx_sched_start(btif_media_cb.aptxEncoderParams.encoder, | |
3357 | - aptX_codec_type, | |
3358 | - use_SCMS_T, | |
3359 | - btif_media_cb.media_feeding.cfg.pcm.sampling_freq, | |
3360 | - btif_media_cb.media_feeding.cfg.pcm.bit_per_sample, | |
3361 | - UIPC_CH_ID_AV_AUDIO, | |
3362 | - UIPC_Read, | |
3363 | - btif_media_task_cb_packet_send, | |
3364 | - raise_priority_a2dp, | |
3365 | - test, | |
3366 | - trace); | |
3367 | - | |
3368 | - aptx_thread = thread_new("aptx_media_worker"); | |
3369 | - if (aptx_thread ) { | |
3370 | - thread_post(aptx_thread, aptx_thread_fn, NULL); | |
3263 | + A2d_aptx_thread_fn = A2D_aptx_sched_start(btif_media_cb.aptxEncoderParams.encoder, | |
3264 | + aptX_codec_type, | |
3265 | + use_SCMS_T, | |
3266 | + is_24bit_audio, | |
3267 | + btif_media_cb.media_feeding.cfg.pcm.sampling_freq, | |
3268 | + btif_media_cb.media_feeding.cfg.pcm.bit_per_sample, | |
3269 | + UIPC_CH_ID_AV_AUDIO, | |
3270 | + btif_media_cb.TxAaMtuSize, | |
3271 | + UIPC_Read, | |
3272 | + btif_media_task_cb_packet_send, | |
3273 | + raise_priority_a2dp, | |
3274 | + test, | |
3275 | + trace); | |
3276 | + | |
3277 | + A2d_aptx_thread = thread_new("aptx_media_worker"); | |
3278 | + if (A2d_aptx_thread ) { | |
3279 | + thread_post(A2d_aptx_thread, A2d_aptx_thread_fn, NULL); | |
3371 | 3280 | } |
3372 | - } else | |
3373 | - { | |
3281 | + } else { | |
3374 | 3282 | APPL_TRACE_EVENT("starting timer %dms", BTIF_MEDIA_TIME_TICK); |
3375 | 3283 | |
3376 | 3284 | alarm_free(btif_media_cb.media_alarm); |
@@ -1706,6 +1706,19 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data) | ||
1706 | 1706 | BTIF_TRACE_IMP ("%s event:%s", __FUNCTION__, dump_rc_event(event)); |
1707 | 1707 | switch (event) |
1708 | 1708 | { |
1709 | + case BTIF_AV_CLEANUP_REQ_EVT: | |
1710 | + { | |
1711 | + memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t)); | |
1712 | + close_uinput(); | |
1713 | + | |
1714 | + if (bt_rc_callbacks) | |
1715 | + { | |
1716 | + bt_rc_callbacks = NULL; | |
1717 | + } | |
1718 | + | |
1719 | + lbl_destroy(); | |
1720 | + }break; | |
1721 | + | |
1709 | 1722 | case BTA_AV_RC_OPEN_EVT: |
1710 | 1723 | { |
1711 | 1724 | BTIF_TRACE_DEBUG("%s Peer_features:%x", __FUNCTION__, p_data->rc_open.peer_features); |
@@ -5198,6 +5211,10 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg) | ||
5198 | 5211 | } |
5199 | 5212 | #endif |
5200 | 5213 | |
5214 | +static void btif_rc_handler_wrapper(UINT16 event, char* p_param) | |
5215 | +{ | |
5216 | + btif_rc_handler((tBTA_AV_EVT)event, (tBTA_AV *)p_param); | |
5217 | +} | |
5201 | 5218 | /*************************************************************************** |
5202 | 5219 | ** |
5203 | 5220 | ** Function cleanup |
@@ -5210,14 +5227,8 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg) | ||
5210 | 5227 | static void cleanup() |
5211 | 5228 | { |
5212 | 5229 | BTIF_TRACE_EVENT("## RC: %s ##", __FUNCTION__); |
5213 | - memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t)); | |
5214 | - close_uinput(); | |
5215 | - if (bt_rc_callbacks) | |
5216 | - { | |
5217 | - bt_rc_callbacks = NULL; | |
5218 | - } | |
5219 | - alarm_free(btif_rc_cb[0].rc_play_status_timer); | |
5220 | - lbl_destroy(); | |
5230 | + btif_transfer_context(btif_rc_handler_wrapper, BTIF_AV_CLEANUP_REQ_EVT, | |
5231 | + NULL, 0, NULL); | |
5221 | 5232 | BTIF_TRACE_EVENT("## RC: %s ## completed", __FUNCTION__); |
5222 | 5233 | } |
5223 | 5234 |
@@ -196,8 +196,12 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) | ||
196 | 196 | if(remote_bd_addr) |
197 | 197 | btif_config_set_str(bdstr, |
198 | 198 | BTIF_STORAGE_PATH_REMOTE_NAME, value); |
199 | - else btif_config_set_str("Adapter", | |
199 | + else | |
200 | + { | |
201 | + btif_config_set_str("Adapter", | |
200 | 202 | BTIF_STORAGE_KEY_ADAPTER_NAME, value); |
203 | + btif_config_flush(); | |
204 | + } | |
201 | 205 | break; |
202 | 206 | case BT_PROPERTY_REMOTE_FRIENDLY_NAME: |
203 | 207 | strncpy(value, (char*)prop->val, prop->len); |
@@ -50,6 +50,7 @@ | ||
50 | 50 | #include "btif_dm.h" |
51 | 51 | #include "btu.h" |
52 | 52 | #include "bt_common.h" |
53 | +#include "btif_av.h" | |
53 | 54 | |
54 | 55 | /************************************************************************************ |
55 | 56 | ** Constants & Macros |
@@ -492,6 +493,7 @@ const char *dump_rc_event(UINT8 event) | ||
492 | 493 | CASE_RETURN_STR(BTA_AV_META_MSG_EVT) |
493 | 494 | CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT) |
494 | 495 | CASE_RETURN_STR(BTA_AV_BROWSE_MSG_EVT) |
496 | + CASE_RETURN_STR(BTIF_AV_CLEANUP_REQ_EVT) | |
495 | 497 | default: |
496 | 498 | return "UNKNOWN_EVENT"; |
497 | 499 | } |
@@ -29,6 +29,10 @@ | ||
29 | 29 | |
30 | 30 | static const char CONTROLLER_MODULE[] = "controller_module"; |
31 | 31 | |
32 | +typedef struct controller_static_t { | |
33 | + void (*enable_soc_logging) (bool value); | |
34 | +} controller_static_t; | |
35 | + | |
32 | 36 | typedef struct controller_t { |
33 | 37 | bool (*get_is_ready)(void); |
34 | 38 |
@@ -79,6 +83,8 @@ typedef struct controller_t { | ||
79 | 83 | bool (*supports_ble_offload_features)(void); |
80 | 84 | } controller_t; |
81 | 85 | |
86 | +const controller_static_t *controller_get_static_interface(); | |
87 | + | |
82 | 88 | const controller_t *controller_get_interface(); |
83 | 89 | |
84 | 90 | const controller_t *controller_get_test_interface( |
@@ -29,6 +29,8 @@ | ||
29 | 29 | #include "hcimsgs.h" |
30 | 30 | #include "osi/include/future.h" |
31 | 31 | #include "stack/include/btm_ble_api.h" |
32 | +#include "osi/include/log.h" | |
33 | +#include "utils/include/bt_utils.h" | |
32 | 34 | |
33 | 35 | const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\x00\x06\x7f" }; |
34 | 36 |
@@ -46,6 +48,9 @@ const uint8_t SCO_HOST_BUFFER_SIZE = 0xff; | ||
46 | 48 | #define BLE_SUPPORTED_STATES_SIZE 8 |
47 | 49 | #define BLE_SUPPORTED_FEATURES_SIZE 8 |
48 | 50 | #define MAX_LOCAL_SUPPORTED_CODECS_SIZE 8 |
51 | +#define UNUSED(x) (void)(x) | |
52 | + | |
53 | +static bool soc_logging_enabled_via_api; | |
49 | 54 | |
50 | 55 | static const hci_t *hci; |
51 | 56 | static const hci_packet_factory_t *packet_factory; |
@@ -81,6 +86,19 @@ static bool secure_connections_supported; | ||
81 | 86 | |
82 | 87 | // Module lifecycle functions |
83 | 88 | |
89 | +void send_soc_log_command(bool value) { | |
90 | + int soc_type = get_soc_type(); | |
91 | + UINT8 param[5] = {0x10,0x03,0x00,0x00,0x01}; | |
92 | + if (!value) | |
93 | + // Disable SoC logging | |
94 | + param[1] = 0x02; | |
95 | + | |
96 | + if (soc_type == BT_SOC_SMD) { | |
97 | + LOG_INFO(LOG_TAG, "%s for BT_SOC_SMD.", __func__); | |
98 | + BTM_VendorSpecificCommand(HCI_VS_HOST_LOG_OPCODE,5,param,NULL); | |
99 | + } | |
100 | +} | |
101 | + | |
84 | 102 | static future_t *start_up(void) { |
85 | 103 | BT_HDR *response; |
86 | 104 |
@@ -107,9 +125,13 @@ static future_t *start_up(void) { | ||
107 | 125 | packet_parser->parse_generic_command_complete(response); |
108 | 126 | |
109 | 127 | #ifdef QLOGKIT_USERDEBUG |
110 | - /* Enable SOC Logging */ | |
111 | - UINT8 param[5] = {0x10,0x03,0x00,0x00,0x01}; | |
112 | - BTM_VendorSpecificCommand(HCI_VS_HOST_LOG_OPCODE,5,param,NULL); | |
128 | + send_soc_log_command(true); | |
129 | + #else | |
130 | + if (soc_logging_enabled_via_api) { | |
131 | + LOG_INFO(LOG_TAG, "%s for non-userdebug api = %d", __func__, | |
132 | + soc_logging_enabled_via_api); | |
133 | + send_soc_log_command(true); | |
134 | + } | |
113 | 135 | #endif |
114 | 136 | |
115 | 137 | // Read the local version info off the controller next, including |
@@ -288,6 +310,16 @@ EXPORT_SYMBOL const module_t controller_module = { | ||
288 | 310 | |
289 | 311 | // Interface functions |
290 | 312 | |
313 | +static void enable_soc_logging(bool value) { | |
314 | + UNUSED(soc_logging_enabled_via_api); | |
315 | +#ifndef QLOGKIT_USERDEBUG | |
316 | + soc_logging_enabled_via_api = value; | |
317 | + | |
318 | + if (readable) | |
319 | + send_soc_log_command(value); | |
320 | +#endif | |
321 | +} | |
322 | + | |
291 | 323 | static bool get_is_ready(void) { |
292 | 324 | return readable; |
293 | 325 | } |
@@ -464,6 +496,10 @@ static void set_ble_resolving_list_max_size(int resolving_list_max_size) { | ||
464 | 496 | ble_resolving_list_max_size = resolving_list_max_size; |
465 | 497 | } |
466 | 498 | |
499 | +static const controller_static_t static_interface = { | |
500 | + enable_soc_logging | |
501 | +}; | |
502 | + | |
467 | 503 | static const controller_t interface = { |
468 | 504 | get_is_ready, |
469 | 505 |
@@ -508,6 +544,10 @@ static const controller_t interface = { | ||
508 | 544 | supports_ble_offload_features |
509 | 545 | }; |
510 | 546 | |
547 | +const controller_static_t *controller_get_static_interface() { | |
548 | + return &static_interface; | |
549 | +} | |
550 | + | |
511 | 551 | const controller_t *controller_get_interface() { |
512 | 552 | static bool loaded = false; |
513 | 553 | if (!loaded) { |
@@ -66,6 +66,8 @@ void allocation_tracker_init(void) { | ||
66 | 66 | if (allocations) |
67 | 67 | return; |
68 | 68 | |
69 | + LOG_INFO("allocation_tracker","%s: function addr = %p", __func__, | |
70 | + (void *)allocation_tracker_init); | |
69 | 71 | canary_size = strlen(canary); |
70 | 72 | |
71 | 73 | pthread_mutex_init(&lock, NULL); |
@@ -21,6 +21,9 @@ | ||
21 | 21 | |
22 | 22 | #include "osi/include/allocator.h" |
23 | 23 | #include "osi/include/allocation_tracker.h" |
24 | +#include "osi/include/log.h" | |
25 | + | |
26 | +#define TAG "bt_allocator" | |
24 | 27 | |
25 | 28 | static const allocator_id_t alloc_allocator_id = 42; |
26 | 29 |
@@ -36,6 +39,11 @@ char *osi_strdup(const char *str) { | ||
36 | 39 | size); |
37 | 40 | if (!new_string) |
38 | 41 | return NULL; |
42 | +#ifdef BLUEDROID_DEBUG | |
43 | + LOG_INFO(TAG, "osi_strdup size 0x%zx ptr = %p caller = %p ", | |
44 | + real_size, new_string, | |
45 | + (void *)__builtin_return_address(0)); | |
46 | +#endif | |
39 | 47 | |
40 | 48 | memcpy(new_string, str, size); |
41 | 49 | return new_string; |
@@ -57,6 +65,11 @@ char *osi_strndup(const char *str, size_t len) { | ||
57 | 65 | if (!new_string) |
58 | 66 | return NULL; |
59 | 67 | |
68 | +#ifdef BLUEDROID_DEBUG | |
69 | + LOG_INFO(TAG, "osi_strndup size 0x%zx ptr = %p caller = %p ", | |
70 | + real_size, new_string, | |
71 | + (void *)__builtin_return_address(0)); | |
72 | +#endif | |
60 | 73 | memcpy(new_string, str, size); |
61 | 74 | new_string[size] = '\0'; |
62 | 75 | return new_string; |
@@ -66,23 +79,49 @@ void *osi_malloc(size_t size) { | ||
66 | 79 | size_t real_size = allocation_tracker_resize_for_canary(size); |
67 | 80 | void *ptr = malloc(real_size); |
68 | 81 | assert(ptr); |
82 | +#ifdef BLUEDROID_DEBUG | |
83 | + void *ptr_alloc = | |
84 | + allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size); | |
85 | + LOG_INFO(TAG, "osi_malloc size 0x%zx ptr = %p caller = %p ", | |
86 | + real_size, ptr_alloc, | |
87 | + (void *)__builtin_return_address(0)); | |
88 | + return ptr_alloc; | |
89 | +#else | |
69 | 90 | return allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size); |
91 | +#endif | |
70 | 92 | } |
71 | 93 | |
72 | 94 | void *osi_calloc(size_t size) { |
73 | 95 | size_t real_size = allocation_tracker_resize_for_canary(size); |
74 | 96 | void *ptr = calloc(1, real_size); |
75 | 97 | assert(ptr); |
98 | +#ifdef BLUEDROID_DEBUG | |
99 | + void *ptr_alloc = | |
100 | + allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size); | |
101 | + LOG_INFO(TAG, "osi_calloc size 0x%zx ptr = %p caller = %p ", | |
102 | + real_size, ptr_alloc, | |
103 | + (void *)__builtin_return_address(0)); | |
104 | + return ptr_alloc; | |
105 | +#else | |
76 | 106 | return allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size); |
107 | +#endif | |
77 | 108 | } |
78 | 109 | |
79 | 110 | void osi_free(void *ptr) { |
111 | +#ifdef BLUEDROID_DEBUG | |
112 | + LOG_INFO(TAG, "osi_free ptr = %p caller = %p ", ptr, | |
113 | + (void *)__builtin_return_address(0)); | |
114 | +#endif | |
80 | 115 | free(allocation_tracker_notify_free(alloc_allocator_id, ptr)); |
81 | 116 | } |
82 | 117 | |
83 | 118 | void osi_free_and_reset(void **p_ptr) |
84 | 119 | { |
85 | 120 | assert(p_ptr != NULL); |
121 | +#ifdef BLUEDROID_DEBUG | |
122 | + LOG_INFO(TAG, "osi_free_and_reset ptr = %p caller = %p ", *p_ptr, | |
123 | + (void *)__builtin_return_address(0)); | |
124 | +#endif | |
86 | 125 | osi_free(*p_ptr); |
87 | 126 | *p_ptr = NULL; |
88 | 127 | } |
@@ -38,12 +38,32 @@ | ||
38 | 38 | #include "bt_target.h" |
39 | 39 | |
40 | 40 | #include <string.h> |
41 | +#include <dlfcn.h> | |
42 | +#include "osi/include/thread.h" | |
41 | 43 | #include "bt_utils.h" |
42 | 44 | #include "a2d_api.h" |
43 | 45 | #include "a2d_int.h" |
44 | 46 | #include "a2d_aptx.h" |
45 | 47 | #include <utils/Log.h> |
46 | 48 | |
49 | +const char* A2D_APTX_SCHED_LIB_NAME = "libaptXScheduler.so"; | |
50 | +void *A2dAptXSchedLibHandle = NULL; | |
51 | +thread_t *A2d_aptx_thread = NULL; | |
52 | +BOOLEAN isA2dAptXEnabled = FALSE; | |
53 | + | |
54 | +int (*A2D_aptx_encoder_init)(void); | |
55 | +A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder, | |
56 | + A2D_AptXCodecType aptX_codec_type, | |
57 | + BOOLEAN use_SCMS_T, BOOLEAN is_24bit_audio, | |
58 | + UINT16 sample_rate, UINT8 format_bits, | |
59 | + UINT8 channel, UINT16 MTU, A2D_AptXReadFn read_fn, | |
60 | + A2D_AptXBufferSendFn send_fn, | |
61 | + A2D_AptXSetPriorityFn set_priority_fn, | |
62 | + BOOLEAN test, BOOLEAN trace); | |
63 | +BOOLEAN (*A2D_aptx_sched_stop)(void); | |
64 | +void (*A2D_aptx_encoder_deinit)(void); | |
65 | +A2D_AptXThreadFn A2d_aptx_thread_fn; | |
66 | + | |
47 | 67 | /****************************************************************************** |
48 | 68 | ** |
49 | 69 | ** Function A2D_BldAptxInfo |
@@ -160,3 +180,116 @@ UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap) | ||
160 | 180 | |
161 | 181 | return status; |
162 | 182 | } |
183 | + | |
184 | +/******************************************************************************* | |
185 | +** | |
186 | +** Function A2D_check_and_init_aptX | |
187 | +** | |
188 | +** Description This function checks if all the libraries required for | |
189 | +** aptX are present and needed function pointers are resolved | |
190 | +** | |
191 | +** Returns returns true if aptX codec initialization succeeds | |
192 | +** | |
193 | +*******************************************************************************/ | |
194 | +BOOLEAN A2D_check_and_init_aptX(void) | |
195 | +{ | |
196 | + A2D_TRACE_DEBUG("%s", __func__); | |
197 | + | |
198 | + if (A2dAptXSchedLibHandle == NULL) | |
199 | + { | |
200 | + A2dAptXSchedLibHandle = dlopen(A2D_APTX_SCHED_LIB_NAME, RTLD_NOW); | |
201 | + | |
202 | + if (!A2dAptXSchedLibHandle) | |
203 | + { | |
204 | + A2D_TRACE_ERROR("%s: aptX scheduler library missing", __func__); | |
205 | + goto error_exit; | |
206 | + } | |
207 | + | |
208 | + A2D_aptx_encoder_init = (int (*)(void))dlsym(A2dAptXSchedLibHandle, | |
209 | + "aptx_encoder_init"); | |
210 | + if (!A2D_aptx_encoder_init) | |
211 | + { | |
212 | + A2D_TRACE_ERROR("%s: aptX encoder init missing", __func__); | |
213 | + goto error_exit; | |
214 | + } | |
215 | + | |
216 | + A2D_aptx_sched_start = (A2D_AptXThreadFn (*)(void*, A2D_AptXCodecType, BOOLEAN, | |
217 | + BOOLEAN, UINT16, UINT8, UINT8, UINT16, A2D_AptXReadFn, | |
218 | + A2D_AptXBufferSendFn, | |
219 | + A2D_AptXSetPriorityFn, BOOLEAN, | |
220 | + BOOLEAN))dlsym(A2dAptXSchedLibHandle, | |
221 | + "aptx_scheduler_start"); | |
222 | + | |
223 | + if (!A2D_aptx_sched_start) | |
224 | + { | |
225 | + A2D_TRACE_ERROR("%s: aptX scheduler start missing", __func__); | |
226 | + goto error_exit; | |
227 | + } | |
228 | + | |
229 | + A2D_aptx_sched_stop = (BOOLEAN (*)(void))dlsym(A2dAptXSchedLibHandle, | |
230 | + "aptx_scheduler_stop"); | |
231 | + if (!A2D_aptx_sched_stop) | |
232 | + { | |
233 | + A2D_TRACE_ERROR("%s: aptX scheduler stop missing", __func__); | |
234 | + goto error_exit; | |
235 | + } | |
236 | + | |
237 | + A2D_aptx_encoder_deinit = (void (*)(void))dlsym(A2dAptXSchedLibHandle, | |
238 | + "aptx_encoder_deinit"); | |
239 | + if (!A2D_aptx_encoder_deinit) | |
240 | + { | |
241 | + A2D_TRACE_ERROR("%s: aptX encoder deinit missing ", __func__); | |
242 | + goto error_exit; | |
243 | + } | |
244 | + | |
245 | + if (A2D_aptx_encoder_init()) | |
246 | + { | |
247 | + A2D_TRACE_ERROR("%s: aptX encoder init failed - %s", __func__, dlerror()); | |
248 | + goto error_exit; | |
249 | + } | |
250 | + } | |
251 | + isA2dAptXEnabled = true; | |
252 | + return isA2dAptXEnabled; | |
253 | + | |
254 | + error_exit:; | |
255 | + if (A2dAptXSchedLibHandle) | |
256 | + { | |
257 | + dlclose(A2dAptXSchedLibHandle); | |
258 | + A2dAptXSchedLibHandle = NULL; | |
259 | + } | |
260 | + isA2dAptXEnabled = false; | |
261 | + return isA2dAptXEnabled; | |
262 | + | |
263 | +} | |
264 | + | |
265 | +/******************************************************************************* | |
266 | +** | |
267 | +** Function A2D_deinit_aptX | |
268 | +** | |
269 | +** Description This function de-initialized aptX | |
270 | +** | |
271 | +** Returns Nothing | |
272 | +** | |
273 | +*******************************************************************************/ | |
274 | +void A2D_deinit_aptX(void) | |
275 | +{ | |
276 | + A2D_TRACE_DEBUG("%s", __func__); | |
277 | + | |
278 | + if (isA2dAptXEnabled && A2dAptXSchedLibHandle) | |
279 | + { | |
280 | + // remove aptX thread | |
281 | + if (A2d_aptx_thread) | |
282 | + { | |
283 | + A2D_aptx_sched_stop(); | |
284 | + thread_free(A2d_aptx_thread); | |
285 | + A2d_aptx_thread = NULL; | |
286 | + } | |
287 | + | |
288 | + A2D_aptx_encoder_deinit(); | |
289 | + dlclose(A2dAptXSchedLibHandle); | |
290 | + A2dAptXSchedLibHandle = NULL; | |
291 | + isA2dAptXEnabled = false; | |
292 | + } | |
293 | + | |
294 | + return; | |
295 | +} |
@@ -1368,7 +1368,19 @@ UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type, | ||
1368 | 1368 | return result; |
1369 | 1369 | } |
1370 | 1370 | #endif |
1371 | - | |
1371 | +/******************************************************************************* | |
1372 | +** | |
1373 | +** Function AVDT_UpdateMaxAvClients | |
1374 | +** | |
1375 | +** Description Update max simultaneous AV connections supported | |
1376 | +** | |
1377 | +** Returns void | |
1378 | +** | |
1379 | +*******************************************************************************/ | |
1380 | +void AVDT_UpdateMaxAvClients(UINT8 max_clients) | |
1381 | +{ | |
1382 | + avdt_scb_set_max_av_client(max_clients); | |
1383 | +} | |
1372 | 1384 | /****************************************************************************** |
1373 | 1385 | ** |
1374 | 1386 | ** Function AVDT_SetTraceLevel |
@@ -178,7 +178,38 @@ void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) | ||
178 | 178 | p_data->msg.discover_rsp.num_seps++; |
179 | 179 | } |
180 | 180 | } |
181 | + /* adjust inuse. Mark all the SEP of a perticualr cluster in use | |
182 | + * if one of the SEP is in use to avoid incoming connection failure | |
183 | + */ | |
184 | + if (p_data->msg.discover_rsp.num_seps > 2 | |
185 | + && avdt_scb_get_max_av_client() > 1) | |
186 | + { | |
187 | + int i,j; | |
188 | + int num_sep = p_data->msg.discover_rsp.num_seps; | |
189 | + int num_stream = avdt_scb_get_max_av_client(); | |
190 | + int num_codecs = num_sep/num_stream; | |
191 | + BOOLEAN is_busy = false; | |
181 | 192 | |
193 | + for (i = 0; i < num_sep; i += num_codecs) | |
194 | + { | |
195 | + is_busy = false; | |
196 | + for (j = i; j < (i+num_codecs); j++) | |
197 | + { | |
198 | + if (sep_info[j].in_use) | |
199 | + { | |
200 | + is_busy = true; | |
201 | + break; | |
202 | + } | |
203 | + } | |
204 | + if (is_busy) | |
205 | + { | |
206 | + for (j = i; j < (i+num_codecs); j++) | |
207 | + { | |
208 | + sep_info[j].in_use = is_busy; | |
209 | + } | |
210 | + } | |
211 | + } | |
212 | + } | |
182 | 213 | /* send response */ |
183 | 214 | avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_RSP_EVT, p_data); |
184 | 215 | } |
@@ -616,7 +616,8 @@ extern tAVDT_SCB *avdt_scb_by_hdl(UINT8 hdl); | ||
616 | 616 | extern UINT8 avdt_scb_verify(tAVDT_CCB *p_ccb, UINT8 state, UINT8 *p_seid, UINT16 num_seid, UINT8 *p_err_code); |
617 | 617 | extern void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi); |
618 | 618 | extern UINT32 avdt_scb_gen_ssrc(tAVDT_SCB *p_scb); |
619 | - | |
619 | +extern void avdt_scb_set_max_av_client(UINT8 num_clients); | |
620 | +extern UINT8 avdt_scb_get_max_av_client(void); | |
620 | 621 | /* SCB action functions */ |
621 | 622 | extern void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); |
622 | 623 | extern void avdt_scb_hdl_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); |
@@ -511,7 +511,7 @@ const tAVDT_SCB_ST_TBL avdt_scb_st_tbl[] = { | ||
511 | 511 | avdt_scb_st_closing |
512 | 512 | }; |
513 | 513 | |
514 | - | |
514 | +UINT8 max_av_clients = 1; | |
515 | 515 | /******************************************************************************* |
516 | 516 | ** |
517 | 517 | ** Function avdt_scb_event |
@@ -795,3 +795,31 @@ void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi) | ||
795 | 795 | } |
796 | 796 | } |
797 | 797 | |
798 | +/******************************************************************************* | |
799 | +** | |
800 | +** Function avdt_scb_max_av_client | |
801 | +** | |
802 | +** Description Update max simultaneous AV connections supported | |
803 | +** | |
804 | +** Returns Nothing. | |
805 | +** | |
806 | +*******************************************************************************/ | |
807 | +void avdt_scb_set_max_av_client(UINT8 max_clients) | |
808 | +{ | |
809 | + max_av_clients = max_clients; | |
810 | +} | |
811 | + | |
812 | +/******************************************************************************* | |
813 | +** | |
814 | +** Function avdt_scb_get_max_av_client | |
815 | +** | |
816 | +** Description Return max simultaneous AV connections supported | |
817 | +** | |
818 | +** Returns max av clients supported | |
819 | +** | |
820 | +*******************************************************************************/ | |
821 | +UINT8 avdt_scb_get_max_av_client() | |
822 | +{ | |
823 | + return max_av_clients; | |
824 | +} | |
825 | + |
@@ -73,6 +73,7 @@ static const UINT8 btm_role_switch_black_list_prefix2[][3] = {{0xfc, 0xc2, 0xde} | ||
73 | 73 | ,{0x00, 0x04, 0x3e} /* OBU II Bluetooth dongle */ |
74 | 74 | ,{0x00, 0x23, 0x01} /* Roman R9020 */ |
75 | 75 | ,{0x00, 0x26, 0xb4} /* NAC FORD,2013 Lincoln */ |
76 | + ,{0x1c, 0x48, 0xf9} /* Jabra Storm */ | |
76 | 77 | }; |
77 | 78 | |
78 | 79 | /******************************************************************************* |
@@ -701,6 +701,37 @@ void btm_ble_enqueue_direct_conn_req(void *p_param) | ||
701 | 701 | } |
702 | 702 | /******************************************************************************* |
703 | 703 | ** |
704 | +** Function btm_ble_dequeue_direct_conn_req | |
705 | +** | |
706 | +** Description This function dequeues the direct connection request | |
707 | +** | |
708 | +** Returns None. | |
709 | +** | |
710 | +*******************************************************************************/ | |
711 | +void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda) | |
712 | +{ | |
713 | + if (fixed_queue_is_empty(btm_cb.ble_ctr_cb.conn_pending_q)) | |
714 | + return; | |
715 | + | |
716 | + list_t *list = fixed_queue_get_list(btm_cb.ble_ctr_cb.conn_pending_q); | |
717 | + for (const list_node_t *node = list_begin(list); node != list_end(list); | |
718 | + node = list_next(node)) { | |
719 | + tBTM_BLE_CONN_REQ *p_req = (tBTM_BLE_CONN_REQ *)list_node(node); | |
720 | + tL2C_LCB *p_lcb = (tL2C_LCB *)p_req->p_param; | |
721 | + if ((p_lcb == NULL) || (!p_lcb->in_use)) { | |
722 | + continue; | |
723 | + } | |
724 | + //If BD address matches | |
725 | + if (!memcmp (rem_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) { | |
726 | + fixed_queue_try_remove_from_queue(btm_cb.ble_ctr_cb.conn_pending_q, p_req); | |
727 | + l2cu_release_lcb((tL2C_LCB *)p_req->p_param); | |
728 | + osi_free((void *)p_req); | |
729 | + break; | |
730 | + } | |
731 | + } | |
732 | +} | |
733 | +/******************************************************************************* | |
734 | +** | |
704 | 735 | ** Function btm_send_pending_direct_conn |
705 | 736 | ** |
706 | 737 | ** Description This function send the pending direct connection request in queue |
@@ -433,6 +433,7 @@ extern void btm_ble_update_link_topology_mask(UINT8 role, BOOLEAN increase); | ||
433 | 433 | /* direct connection utility */ |
434 | 434 | extern BOOLEAN btm_send_pending_direct_conn(void); |
435 | 435 | extern void btm_ble_enqueue_direct_conn_req(void *p_param); |
436 | +extern void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda); | |
436 | 437 | |
437 | 438 | /* BLE address management */ |
438 | 439 | extern void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback); |
@@ -477,7 +477,6 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec) | ||
477 | 477 | list_remove(btm_cb.sec_dev_rec, p_dev_rec); |
478 | 478 | |
479 | 479 | p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; |
480 | - break; | |
481 | 480 | } |
482 | 481 | |
483 | 482 | /* an RPA device entry is a duplicate of the target record */ |
@@ -493,7 +492,6 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec) | ||
493 | 492 | |
494 | 493 | p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; |
495 | 494 | } |
496 | - break; | |
497 | 495 | } |
498 | 496 | } |
499 | 497 | #endif |
@@ -249,6 +249,8 @@ BOOLEAN gatt_disconnect (tGATT_TCB *p_tcb) | ||
249 | 249 | { |
250 | 250 | gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); |
251 | 251 | ret = L2CA_CancelBleConnectReq (p_tcb->peer_bda); |
252 | + if (!ret) | |
253 | + gatt_set_ch_state(p_tcb, GATT_CH_CLOSE); | |
252 | 254 | } |
253 | 255 | } |
254 | 256 | else |
@@ -80,7 +80,6 @@ typedef struct | ||
80 | 80 | UINT8 future2; |
81 | 81 | } tA2D_APTX_CIE; |
82 | 82 | |
83 | - | |
84 | 83 | typedef struct { |
85 | 84 | INT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/ |
86 | 85 | INT16 s16ChannelMode; /* mono, dual, streo or joint streo*/ |
@@ -95,6 +94,8 @@ typedef struct { | ||
95 | 94 | extern const char* A2D_APTX_SCHED_LIB_NAME; |
96 | 95 | extern void *A2dAptXSchedLibHandle; |
97 | 96 | extern BOOLEAN isA2dAptXEnabled; |
97 | +extern thread_t *A2d_aptx_thread; | |
98 | +extern A2D_AptXThreadFn A2d_aptx_thread_fn; | |
98 | 99 | |
99 | 100 | /***************************************************************************** |
100 | 101 | ** external function declarations |
@@ -107,18 +108,20 @@ extern UINT8 A2D_BldAptxInfo(UINT8 media_type, tA2D_APTX_CIE *p_ie, | ||
107 | 108 | UINT8 *p_result); |
108 | 109 | extern UINT8 A2D_ParsAptxInfo(tA2D_APTX_CIE *p_ie, UINT8 *p_info, |
109 | 110 | BOOLEAN for_caps); |
110 | -extern int (*A2D_aptx_sched_init)(void); | |
111 | +extern int (*A2D_aptx_encoder_init)(void); | |
111 | 112 | extern A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder, |
112 | 113 | A2D_AptXCodecType aptX_codec_type, |
113 | - BOOLEAN use_SCMS_T, UINT16 sample_rate, | |
114 | - UINT8 format_bits, UINT8 channel, | |
115 | - A2D_AptXReadFn read_fn, | |
114 | + BOOLEAN use_SCMS_T, BOOLEAN is_24bit_audio, | |
115 | + UINT16 sample_rate, UINT8 format_bits, | |
116 | + UINT8 channel, UINT16 mtu, A2D_AptXReadFn read_fn, | |
116 | 117 | A2D_AptXBufferSendFn send_fn, |
117 | 118 | A2D_AptXSetPriorityFn set_priority_fn, |
118 | 119 | BOOLEAN test, BOOLEAN trace); |
119 | 120 | extern BOOLEAN (*A2D_aptx_sched_stop)(void); |
120 | -extern void (*A2D_aptx_sched_deinit)(void); | |
121 | +extern void (*A2D_aptx_encoder_deinit)(void); | |
121 | 122 | extern UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap); |
123 | +extern BOOLEAN A2D_check_and_init_aptX(); | |
124 | +extern void A2D_deinit_aptX(); | |
122 | 125 | |
123 | 126 | #ifdef __cplusplus |
124 | 127 | } |
@@ -994,6 +994,17 @@ extern UINT16 AVDT_SetMediaBuf(UINT8 handle, UINT8 *p_buf, UINT32 buf_len); | ||
994 | 994 | extern UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type, |
995 | 995 | tAVDT_REPORT_DATA *p_data); |
996 | 996 | |
997 | +/******************************************************************************* | |
998 | +** | |
999 | +** Function AVDT_UpdateMaxAvClients | |
1000 | +** | |
1001 | +** Description Update max simultaneous AV connections supported | |
1002 | +** | |
1003 | +** Returns | |
1004 | +** | |
1005 | +*******************************************************************************/ | |
1006 | +extern void AVDT_UpdateMaxAvClients(UINT8 num_clients); | |
1007 | + | |
997 | 1008 | /****************************************************************************** |
998 | 1009 | ** |
999 | 1010 | ** Function AVDT_SetTraceLevel |
@@ -57,17 +57,17 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) | ||
57 | 57 | /* There can be only one BLE connection request outstanding at a time */ |
58 | 58 | if (btm_ble_get_conn_st() == BLE_CONN_IDLE) |
59 | 59 | { |
60 | - L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending"); | |
60 | + L2CAP_TRACE_WARNING ("%s - no connection pending", __func__); | |
61 | 61 | return(FALSE); |
62 | 62 | } |
63 | 63 | |
64 | 64 | if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) |
65 | 65 | { |
66 | - L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x", | |
66 | + L2CAP_TRACE_WARNING ("%s - different BDA Connecting: %08x%04x Cancel: %08x%04x", __func__, | |
67 | 67 | (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], |
68 | 68 | (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], |
69 | 69 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); |
70 | - | |
70 | + btm_ble_dequeue_direct_conn_req(rem_bda); | |
71 | 71 | return(FALSE); |
72 | 72 | } |
73 | 73 |
@@ -1150,7 +1150,7 @@ static void l2c_csm_open (tL2C_CCB *p_ccb, UINT16 event, void *p_data) | ||
1150 | 1150 | tempstate = p_ccb->chnl_state; |
1151 | 1151 | tempcfgdone = p_ccb->config_done; |
1152 | 1152 | p_ccb->chnl_state = CST_CONFIG; |
1153 | - p_ccb->config_done &= ~CFG_DONE_MASK; | |
1153 | + p_ccb->config_done &= ~IB_CFG_DONE; | |
1154 | 1154 | |
1155 | 1155 | alarm_set_on_queue(p_ccb->l2c_ccb_timer, |
1156 | 1156 | L2CAP_CHNL_CFG_TIMEOUT_MS, |
@@ -59,6 +59,8 @@ static const UINT8 hci_role_switch_black_list_prefix[][3] = {{0x00, 0x26, 0xb4} | ||
59 | 59 | ,{0xa4, 0x15, 0x66} /* Motorola Boom */ |
60 | 60 | ,{0xd0, 0x13, 0x1e} /* Samsung keyboard */ |
61 | 61 | ,{0x1c, 0x48, 0xf9} /* Jabra Storm */ |
62 | + ,{0x8f, 0x20, 0xb4} /* BT1719 */ | |
63 | + ,{0xa8, 0xb9, 0xb3} /* Sonata CarKit */ | |
62 | 64 | }; |
63 | 65 | |
64 | 66 | /******************************************************************************* |
@@ -463,7 +463,7 @@ static void bdt_shutdown(void) | ||
463 | 463 | static void config_permissions(void) |
464 | 464 | { |
465 | 465 | struct __user_cap_header_struct header; |
466 | - struct __user_cap_data_struct cap; | |
466 | + struct __user_cap_data_struct cap[2]; | |
467 | 467 | |
468 | 468 | bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); |
469 | 469 |
@@ -474,17 +474,25 @@ static void config_permissions(void) | ||
474 | 474 | setuid(AID_BLUETOOTH); |
475 | 475 | setgid(AID_BLUETOOTH); |
476 | 476 | |
477 | - header.version = _LINUX_CAPABILITY_VERSION; | |
478 | - | |
479 | - cap.effective = cap.permitted = cap.inheritable = | |
480 | - 1 << CAP_NET_RAW | | |
481 | - 1 << CAP_NET_ADMIN | | |
482 | - 1 << CAP_NET_BIND_SERVICE | | |
483 | - 1 << CAP_SYS_RAWIO | | |
484 | - 1 << CAP_SYS_NICE | | |
485 | - 1 << CAP_SETGID; | |
486 | - | |
487 | - capset(&header, &cap); | |
477 | + header.version = _LINUX_CAPABILITY_VERSION_3; | |
478 | + | |
479 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].permitted |= CAP_TO_MASK(CAP_NET_RAW); | |
480 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].permitted |= CAP_TO_MASK(CAP_NET_ADMIN); | |
481 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].permitted |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
482 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].permitted |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
483 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].permitted |= CAP_TO_MASK(CAP_SYS_NICE); | |
484 | + cap[CAP_TO_INDEX(CAP_SETGID)].permitted |= CAP_TO_MASK(CAP_SETGID); | |
485 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].permitted |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
486 | + | |
487 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].effective |= CAP_TO_MASK(CAP_NET_RAW); | |
488 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].effective |= CAP_TO_MASK(CAP_NET_ADMIN); | |
489 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].effective |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
490 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].effective |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
491 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); | |
492 | + cap[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); | |
493 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].effective |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
494 | + | |
495 | + capset(&header, &cap[0]); | |
488 | 496 | setgroups(sizeof(groups)/sizeof(groups[0]), groups); |
489 | 497 | } |
490 | 498 |
@@ -737,13 +745,16 @@ static int create_cmdjob(char *cmd) | ||
737 | 745 | char *job_cmd; |
738 | 746 | |
739 | 747 | job_cmd = malloc(strlen(cmd)+1); /* freed in job handler */ |
740 | - strlcpy(job_cmd, cmd,(strlen(cmd)+1)); | |
741 | - | |
742 | - if (pthread_create(&thread_id, NULL, | |
748 | + if (job_cmd) { | |
749 | + strlcpy(job_cmd, cmd,(strlen(cmd)+1)); | |
750 | + if (pthread_create(&thread_id, NULL, | |
743 | 751 | (void*)cmdjob_handler, (void*)job_cmd)!=0) |
744 | - perror("pthread_create"); | |
745 | - | |
746 | - return 0; | |
752 | + perror("pthread_create"); | |
753 | + return 0; | |
754 | + } | |
755 | + else | |
756 | + perror("create_Cmdjob malloc failed "); | |
757 | + return -1; | |
747 | 758 | } |
748 | 759 | |
749 | 760 | /******************************************************************************* |
@@ -0,0 +1,25 @@ | ||
1 | +LOCAL_PATH:= $(call my-dir) | |
2 | + | |
3 | +include $(CLEAR_VARS) | |
4 | + | |
5 | +LOCAL_SRC_FILES:= \ | |
6 | + bluedroidtest.c | |
7 | + | |
8 | +LOCAL_C_INCLUDES := | |
9 | +LOCAL_CFLAGS := -Wno-unused-parameter | |
10 | + | |
11 | +LOCAL_CFLAGS += -std=c99 | |
12 | + | |
13 | +LOCAL_CFLAGS += -std=c99 | |
14 | + | |
15 | +LOCAL_MODULE_TAGS := debug optional | |
16 | + | |
17 | +LOCAL_MODULE:= bdt | |
18 | + | |
19 | +LOCAL_SHARED_LIBRARIES += libcutils \ | |
20 | + libhardware \ | |
21 | + libhardware_legacy | |
22 | + | |
23 | +LOCAL_MULTILIB := 32 | |
24 | + | |
25 | +include $(BUILD_EXECUTABLE) |
@@ -0,0 +1,88 @@ | ||
1 | +Bluedroid Test Application | |
2 | +========================== | |
3 | +The test application provides a small console shell interface that allows | |
4 | +access to the Bluetooth HAL API library though ASCII commands. This is similar | |
5 | +to how the real JNI service would operate. The primary objective of this | |
6 | +application is to allow Bluetooth to be put in DUT Mode for RF/BB BQB test purposes. | |
7 | + | |
8 | +This application is mutually exclusive with the Java based Bluetooth.apk. Hence | |
9 | +before launching the application, it should be ensured that the Settings->Bluetooth is OFF. | |
10 | + | |
11 | +This application is built as 'bdt' and shall be available in '/system/bin/bdt' | |
12 | + | |
13 | +Limitations | |
14 | +=========== | |
15 | +1.) Settings->Bluetooth must be OFF for this application to work | |
16 | +2.) Currently, only the SIG 'HCI Test Mode' commands are supported. The vendor | |
17 | +specific HCI test mode commands to be added. | |
18 | + | |
19 | +Usage instructions | |
20 | +================== | |
21 | +The following section describes the various commands and their usage | |
22 | + | |
23 | +Launching the test application | |
24 | +============================== | |
25 | +$ adb shell | |
26 | +root@android:/ # /system/bin/bdt | |
27 | +set_aid_and_cap : pid 1183, uid 0 gid 0 | |
28 | +::::::::::::::::::::::::::::::::::::::::::::::::::: | |
29 | +:: Bluedroid test app starting | |
30 | +Loading HAL lib + extensions | |
31 | +HAL library loaded (Success) | |
32 | +INIT BT | |
33 | +HAL REQUEST SUCCESS | |
34 | + | |
35 | +Enabling Bluetooth | |
36 | +================== | |
37 | +>enable | |
38 | +ENABLE BT | |
39 | +HAL REQUEST SUCCESS | |
40 | +>ADAPTER STATE UPDATED : ON | |
41 | + | |
42 | +Enabling Test Mode (Bluetooth must be enabled for this command to work) | |
43 | +====================================================================== | |
44 | +>dut_mode_configure 1 | |
45 | +BT DUT MODE CONFIGURE | |
46 | +HAL REQUEST SUCCESS | |
47 | +> | |
48 | + | |
49 | +Disabling Test Mode | |
50 | +=================== | |
51 | +>dut_mode_configure 0 | |
52 | +BT DUT MODE CONFIGURE | |
53 | +HAL REQUEST SUCCESS | |
54 | +> | |
55 | + | |
56 | +Running BLE Test commands (Bluetooth must be enabled) | |
57 | +===================================================== | |
58 | +NOTE: Unlike BR/EDR, there is no explicit DUT mode to run these BLE tests. | |
59 | + | |
60 | +> le_test_mode 1 <rx_freq> | |
61 | + | |
62 | +> le_test_mode 2 <tx_freq> <test_data_len> <payload_pattern> | |
63 | + | |
64 | +> le_test_mode 3 <no_args> | |
65 | +Please refer to the BT Core spec pages-1099 to 1102 for possible values for | |
66 | +the above parameters. These values need to be provided in Decimal format. | |
67 | + | |
68 | +Exit the test application | |
69 | +========================= | |
70 | +>quit | |
71 | +shutdown bdroid test app | |
72 | +Unloading HAL lib | |
73 | +HAL library unloaded (Success) | |
74 | +:: Bluedroid test app terminating | |
75 | + | |
76 | +Help (Lists the available commands) | |
77 | +=================================== | |
78 | +>help | |
79 | +help lists all available console commands | |
80 | + | |
81 | +quit | |
82 | +enable :: enables bluetooth | |
83 | +disable :: disables bluetooth | |
84 | +dut_mode_configure :: DUT mode - 1 to enter,0 to exit | |
85 | +le_test_mode :: LE Test Mode - RxTest - 1 <rx_freq>, | |
86 | + TxTest - 2 <tx_freq> <test_data_len> <payload_pattern>, | |
87 | + End Test - 3 <no_args> | |
88 | + |
@@ -0,0 +1,929 @@ | ||
1 | +/****************************************************************************** | |
2 | + * | |
3 | + * Copyright (C) 2009-2012 Broadcom Corporation | |
4 | + * | |
5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + * you may not use this file except in compliance with the License. | |
7 | + * You may obtain a copy of the License at: | |
8 | + * | |
9 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + * | |
11 | + * Unless required by applicable law or agreed to in writing, software | |
12 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + * See the License for the specific language governing permissions and | |
15 | + * limitations under the License. | |
16 | + * | |
17 | + ******************************************************************************/ | |
18 | + | |
19 | +/************************************************************************************ | |
20 | + * | |
21 | + * Filename: bluedroidtest.c | |
22 | + * | |
23 | + * Description: Bluedroid Test application | |
24 | + * | |
25 | + ***********************************************************************************/ | |
26 | + | |
27 | +#include <stdio.h> | |
28 | +#include <dlfcn.h> | |
29 | +#include <stdlib.h> | |
30 | +#include <errno.h> | |
31 | +#include <string.h> | |
32 | +#include <pthread.h> | |
33 | +#include <unistd.h> | |
34 | +#include <ctype.h> | |
35 | +#include <fcntl.h> | |
36 | +#include <sys/prctl.h> | |
37 | +#include <sys/capability.h> | |
38 | + | |
39 | +#include <arpa/inet.h> | |
40 | +#include <netinet/in.h> | |
41 | +#include <netdb.h> | |
42 | + | |
43 | +#include <private/android_filesystem_config.h> | |
44 | +#include <android/log.h> | |
45 | + | |
46 | +#include <hardware/hardware.h> | |
47 | +#include <hardware/bluetooth.h> | |
48 | + | |
49 | +/************************************************************************************ | |
50 | +** Constants & Macros | |
51 | +************************************************************************************/ | |
52 | + | |
53 | +#define PID_FILE "/data/.bdt_pid" | |
54 | +#define DEVICE_DISCOVERY_TIMEOUT 20 | |
55 | + | |
56 | +#ifndef MAX | |
57 | +#define MAX(x, y) ((x) > (y) ? (x) : (y)) | |
58 | +#endif | |
59 | + | |
60 | +#define CASE_RETURN_STR(const) case const: return #const; | |
61 | + | |
62 | +#define UNUSED __attribute__((unused)) | |
63 | + | |
64 | +/************************************************************************************ | |
65 | +** Local type definitions | |
66 | +************************************************************************************/ | |
67 | + | |
68 | +/************************************************************************************ | |
69 | +** Static variables | |
70 | +************************************************************************************/ | |
71 | + | |
72 | +static unsigned char main_done = 0; | |
73 | +static bt_status_t status; | |
74 | + | |
75 | +/* Main API */ | |
76 | +static bluetooth_device_t* bt_device; | |
77 | + | |
78 | +const bt_interface_t* sBtInterface = NULL; | |
79 | + | |
80 | +static gid_t groups[] = { AID_NET_BT, AID_INET, AID_NET_BT_ADMIN, | |
81 | + AID_SYSTEM, AID_MISC, AID_SDCARD_RW, | |
82 | + AID_NET_ADMIN, AID_VPN}; | |
83 | + | |
84 | +/* Set to 1 when the Bluedroid stack is enabled */ | |
85 | +static unsigned char bt_enabled = 0; | |
86 | +static int deviceCount; | |
87 | +static int wantMore = 0; | |
88 | +pthread_mutex_t deviceCount_mutex; | |
89 | +pthread_cond_t deviceCount_cond; | |
90 | + | |
91 | +/************************************************************************************ | |
92 | +** Static functions | |
93 | +************************************************************************************/ | |
94 | + | |
95 | +static void process_cmd(char *p, unsigned char is_job); | |
96 | +static void job_handler(void *param); | |
97 | +static void bdt_log(const char *fmt_str, ...); | |
98 | +static void discover_device(void *arg); | |
99 | + | |
100 | + | |
101 | +/************************************************************************************ | |
102 | +** Externs | |
103 | +************************************************************************************/ | |
104 | + | |
105 | +/************************************************************************************ | |
106 | +** Functions | |
107 | +************************************************************************************/ | |
108 | + | |
109 | + | |
110 | +/************************************************************************************ | |
111 | +** Shutdown helper functions | |
112 | +************************************************************************************/ | |
113 | + | |
114 | +static void bdt_shutdown(void) | |
115 | +{ | |
116 | + bdt_log("shutdown bdroid test app\n"); | |
117 | + main_done = 1; | |
118 | +} | |
119 | + | |
120 | + | |
121 | +/***************************************************************************** | |
122 | +** Android's init.rc does not yet support applying linux capabilities | |
123 | +*****************************************************************************/ | |
124 | + | |
125 | +static void config_permissions(void) | |
126 | +{ | |
127 | + struct __user_cap_header_struct header; | |
128 | + struct __user_cap_data_struct cap; | |
129 | + | |
130 | + bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); | |
131 | + | |
132 | + header.pid = 0; | |
133 | + | |
134 | + prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0); | |
135 | + | |
136 | + setuid(AID_BLUETOOTH); | |
137 | + setgid(AID_BLUETOOTH); | |
138 | + | |
139 | + header.version = _LINUX_CAPABILITY_VERSION; | |
140 | + | |
141 | + cap.effective = cap.permitted = cap.inheritable = | |
142 | + 1 << CAP_NET_RAW | | |
143 | + 1 << CAP_NET_ADMIN | | |
144 | + 1 << CAP_NET_BIND_SERVICE | | |
145 | + 1 << CAP_SYS_RAWIO | | |
146 | + 1 << CAP_SYS_NICE | | |
147 | + 1 << CAP_SETGID; | |
148 | + | |
149 | + capset(&header, &cap); | |
150 | + setgroups(sizeof(groups)/sizeof(groups[0]), groups); | |
151 | +} | |
152 | + | |
153 | + | |
154 | + | |
155 | +/***************************************************************************** | |
156 | +** Logger API | |
157 | +*****************************************************************************/ | |
158 | + | |
159 | +void bdt_log(const char *fmt_str, ...) | |
160 | +{ | |
161 | + static char buffer[1024]; | |
162 | + va_list ap; | |
163 | + | |
164 | + va_start(ap, fmt_str); | |
165 | + vsnprintf(buffer, 1024, fmt_str, ap); | |
166 | + va_end(ap); | |
167 | + | |
168 | + fprintf(stdout, "%s\n", buffer); | |
169 | +} | |
170 | + | |
171 | +/******************************************************************************* | |
172 | + ** Misc helper functions | |
173 | + *******************************************************************************/ | |
174 | +static const char* dump_bt_status(bt_status_t status) | |
175 | +{ | |
176 | + switch(status) | |
177 | + { | |
178 | + CASE_RETURN_STR(BT_STATUS_SUCCESS) | |
179 | + CASE_RETURN_STR(BT_STATUS_FAIL) | |
180 | + CASE_RETURN_STR(BT_STATUS_NOT_READY) | |
181 | + CASE_RETURN_STR(BT_STATUS_NOMEM) | |
182 | + CASE_RETURN_STR(BT_STATUS_BUSY) | |
183 | + CASE_RETURN_STR(BT_STATUS_UNSUPPORTED) | |
184 | + | |
185 | + default: | |
186 | + return "unknown status code"; | |
187 | + } | |
188 | +} | |
189 | + | |
190 | +static void hex_dump(char *msg, void *data, int size, int trunc) | |
191 | +{ | |
192 | + unsigned char *p = data; | |
193 | + unsigned char c; | |
194 | + int n; | |
195 | + char bytestr[4] = {0}; | |
196 | + char addrstr[10] = {0}; | |
197 | + char hexstr[ 16*3 + 5] = {0}; | |
198 | + char charstr[16*1 + 5] = {0}; | |
199 | + | |
200 | + bdt_log("%s \n", msg); | |
201 | + | |
202 | + /* truncate */ | |
203 | + if(trunc && (size>32)) | |
204 | + size = 32; | |
205 | + | |
206 | + for(n=1;n<=size;n++) { | |
207 | + if (n%16 == 1) { | |
208 | + /* store address for this line */ | |
209 | + snprintf(addrstr, sizeof(addrstr), "%.4x", | |
210 | + (unsigned int)((uintptr_t)p-(uintptr_t)data) ); | |
211 | + } | |
212 | + | |
213 | + c = *p; | |
214 | + if (isalnum(c) == 0) { | |
215 | + c = '.'; | |
216 | + } | |
217 | + | |
218 | + /* store hex str (for left side) */ | |
219 | + snprintf(bytestr, sizeof(bytestr), "%02X ", *p); | |
220 | + strlcat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); | |
221 | + | |
222 | + /* store char str (for right side) */ | |
223 | + snprintf(bytestr, sizeof(bytestr), "%c", c); | |
224 | + strlcat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); | |
225 | + | |
226 | + if(n%16 == 0) { | |
227 | + /* line completed */ | |
228 | + bdt_log("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); | |
229 | + hexstr[0] = 0; | |
230 | + charstr[0] = 0; | |
231 | + } else if(n%8 == 0) { | |
232 | + /* half line: add whitespaces */ | |
233 | + strlcat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); | |
234 | + strlcat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); | |
235 | + } | |
236 | + p++; /* next byte */ | |
237 | + } | |
238 | + | |
239 | + if (strlen(hexstr) > 0) { | |
240 | + /* print rest of buffer if not empty */ | |
241 | + bdt_log("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); | |
242 | + } | |
243 | +} | |
244 | + | |
245 | +/******************************************************************************* | |
246 | + ** Console helper functions | |
247 | + *******************************************************************************/ | |
248 | + | |
249 | +void skip_blanks(char **p) | |
250 | +{ | |
251 | + while (**p == ' ') | |
252 | + (*p)++; | |
253 | +} | |
254 | + | |
255 | +uint32_t get_int(char **p, int DefaultValue) | |
256 | +{ | |
257 | + uint32_t Value = 0; | |
258 | + unsigned char UseDefault; | |
259 | + | |
260 | + UseDefault = 1; | |
261 | + skip_blanks(p); | |
262 | + | |
263 | + while ( ((**p)<= '9' && (**p)>= '0') ) | |
264 | + { | |
265 | + Value = Value * 10 + (**p) - '0'; | |
266 | + UseDefault = 0; | |
267 | + (*p)++; | |
268 | + } | |
269 | + | |
270 | + if (UseDefault) | |
271 | + return DefaultValue; | |
272 | + else | |
273 | + return Value; | |
274 | +} | |
275 | + | |
276 | +int get_signed_int(char **p, int DefaultValue) | |
277 | +{ | |
278 | + int Value = 0; | |
279 | + unsigned char UseDefault; | |
280 | + unsigned char NegativeNum = 0; | |
281 | + | |
282 | + UseDefault = 1; | |
283 | + skip_blanks(p); | |
284 | + | |
285 | + if ( (**p) == '-') | |
286 | + { | |
287 | + NegativeNum = 1; | |
288 | + (*p)++; | |
289 | + } | |
290 | + while ( ((**p)<= '9' && (**p)>= '0') ) | |
291 | + { | |
292 | + Value = Value * 10 + (**p) - '0'; | |
293 | + UseDefault = 0; | |
294 | + (*p)++; | |
295 | + } | |
296 | + | |
297 | + if (UseDefault) | |
298 | + return DefaultValue; | |
299 | + else | |
300 | + return ((NegativeNum == 0)? Value : -Value); | |
301 | +} | |
302 | + | |
303 | +void get_str(char **p, char *Buffer) | |
304 | +{ | |
305 | + skip_blanks(p); | |
306 | + | |
307 | + while (**p != 0 && **p != ' ') | |
308 | + { | |
309 | + *Buffer = **p; | |
310 | + (*p)++; | |
311 | + Buffer++; | |
312 | + } | |
313 | + | |
314 | + *Buffer = 0; | |
315 | +} | |
316 | + | |
317 | +uint32_t get_hex(char **p, int DefaultValue) | |
318 | +{ | |
319 | + uint32_t Value = 0; | |
320 | + unsigned char UseDefault; | |
321 | + | |
322 | + UseDefault = 1; | |
323 | + skip_blanks(p); | |
324 | + | |
325 | + while ( ((**p)<= '9' && (**p)>= '0') || | |
326 | + ((**p)<= 'f' && (**p)>= 'a') || | |
327 | + ((**p)<= 'F' && (**p)>= 'A') ) | |
328 | + { | |
329 | + if (**p >= 'a') | |
330 | + Value = Value * 16 + (**p) - 'a' + 10; | |
331 | + else if (**p >= 'A') | |
332 | + Value = Value * 16 + (**p) - 'A' + 10; | |
333 | + else | |
334 | + Value = Value * 16 + (**p) - '0'; | |
335 | + UseDefault = 0; | |
336 | + (*p)++; | |
337 | + } | |
338 | + | |
339 | + if (UseDefault) | |
340 | + return DefaultValue; | |
341 | + else | |
342 | + return Value; | |
343 | +} | |
344 | + | |
345 | +void get_bdaddr(const char *str, bt_bdaddr_t *bd) { | |
346 | + char *d = ((char *)bd), *endp; | |
347 | + int i; | |
348 | + for(i = 0; i < 6; i++) { | |
349 | + *d++ = strtol(str, &endp, 16); | |
350 | + if (*endp != ':' && i != 5) { | |
351 | + memset(bd, 0, sizeof(bt_bdaddr_t)); | |
352 | + return; | |
353 | + } | |
354 | + str = endp + 1; | |
355 | + } | |
356 | +} | |
357 | + | |
358 | +#define is_cmd(str) ((strlen(str) == strlen(cmd)) && strncmp((const char *)&cmd, str, strlen(str)) == 0) | |
359 | +#define if_cmd(str) if (is_cmd(str)) | |
360 | + | |
361 | +typedef void (t_console_cmd_handler) (char *p); | |
362 | + | |
363 | +typedef struct { | |
364 | + const char *name; | |
365 | + t_console_cmd_handler *handler; | |
366 | + const char *help; | |
367 | + unsigned char is_job; | |
368 | +} t_cmd; | |
369 | + | |
370 | + | |
371 | +const t_cmd console_cmd_list[]; | |
372 | +static int console_cmd_maxlen = 0; | |
373 | + | |
374 | +static void cmdjob_handler(void *param) | |
375 | +{ | |
376 | + char *job_cmd = (char*)param; | |
377 | + | |
378 | + bdt_log("cmdjob starting (%s)", job_cmd); | |
379 | + | |
380 | + process_cmd(job_cmd, 1); | |
381 | + | |
382 | + bdt_log("cmdjob terminating"); | |
383 | + | |
384 | + free(job_cmd); | |
385 | +} | |
386 | + | |
387 | +static int create_cmdjob(char *cmd) | |
388 | +{ | |
389 | + pthread_t thread_id; | |
390 | + char *job_cmd; | |
391 | + | |
392 | + job_cmd = malloc(strlen(cmd)+1); /* freed in job handler */ | |
393 | + if (job_cmd) | |
394 | + { | |
395 | + strlcpy(job_cmd, cmd, strlen(cmd)+1); | |
396 | + | |
397 | + if (pthread_create(&thread_id, NULL, | |
398 | + (void*)cmdjob_handler, (void*)job_cmd)!=0) | |
399 | + perror("pthread_create"); | |
400 | + } | |
401 | + else | |
402 | + { | |
403 | + perror("create_cmdjob(): Failed to allocate memory"); | |
404 | + } | |
405 | + | |
406 | + return 0; | |
407 | +} | |
408 | + | |
409 | +/******************************************************************************* | |
410 | + ** Load stack lib | |
411 | + *******************************************************************************/ | |
412 | + | |
413 | +int HAL_load(void) | |
414 | +{ | |
415 | + int err = 0; | |
416 | + | |
417 | + hw_module_t* module; | |
418 | + hw_device_t* device; | |
419 | + | |
420 | + bdt_log("Loading HAL lib + extensions"); | |
421 | + | |
422 | + err = hw_get_module(BT_HARDWARE_MODULE_ID, (hw_module_t const**)&module); | |
423 | + if (err == 0) | |
424 | + { | |
425 | + err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device); | |
426 | + if (err == 0) { | |
427 | + bt_device = (bluetooth_device_t *)device; | |
428 | + sBtInterface = bt_device->get_bluetooth_interface(); | |
429 | + } | |
430 | + } | |
431 | + | |
432 | + bdt_log("HAL library loaded (%s)", strerror(err)); | |
433 | + | |
434 | + return err; | |
435 | +} | |
436 | + | |
437 | +int HAL_unload(void) | |
438 | +{ | |
439 | + int err = 0; | |
440 | + | |
441 | + bdt_log("Unloading HAL lib"); | |
442 | + | |
443 | + sBtInterface = NULL; | |
444 | + | |
445 | + bdt_log("HAL library unloaded (%s)", strerror(err)); | |
446 | + | |
447 | + return err; | |
448 | +} | |
449 | + | |
450 | +/******************************************************************************* | |
451 | + ** HAL test functions & callbacks | |
452 | + *******************************************************************************/ | |
453 | + | |
454 | +void setup_test_env(void) | |
455 | +{ | |
456 | + int i = 0; | |
457 | + | |
458 | + while (console_cmd_list[i].name != NULL) | |
459 | + { | |
460 | + console_cmd_maxlen = MAX(console_cmd_maxlen, (int)strlen(console_cmd_list[i].name)); | |
461 | + i++; | |
462 | + } | |
463 | +} | |
464 | + | |
465 | +void check_return_status(bt_status_t status) | |
466 | +{ | |
467 | + if (status != BT_STATUS_SUCCESS) | |
468 | + { | |
469 | + bdt_log("HAL REQUEST FAILED status : %d (%s)", status, dump_bt_status(status)); | |
470 | + } | |
471 | + else | |
472 | + { | |
473 | + bdt_log("HAL REQUEST SUCCESS"); | |
474 | + } | |
475 | +} | |
476 | + | |
477 | +static void adapter_state_changed(bt_state_t state) | |
478 | +{ | |
479 | + bdt_log("ADAPTER STATE UPDATED : %s", (state == BT_STATE_OFF)?"OFF":"ON"); | |
480 | + if (state == BT_STATE_ON) { | |
481 | + bt_enabled = 1; | |
482 | + } else { | |
483 | + bt_enabled = 0; | |
484 | + } | |
485 | +} | |
486 | + | |
487 | +static void dut_mode_recv(uint16_t UNUSED opcode, uint8_t UNUSED *buf, uint8_t UNUSED len) | |
488 | +{ | |
489 | + bdt_log("DUT MODE RECV : NOT IMPLEMENTED"); | |
490 | +} | |
491 | + | |
492 | +static void le_test_mode(bt_status_t status, uint16_t packet_count) | |
493 | +{ | |
494 | + bdt_log("LE TEST MODE END status:%s number_of_packets:%d", dump_bt_status(status), packet_count); | |
495 | +} | |
496 | + | |
497 | +static void device_found_cb(int num_properties, bt_property_t *properties) | |
498 | +{ | |
499 | + int i; | |
500 | + for (i = 0; i < num_properties; i++) | |
501 | + { | |
502 | + if (properties[i].type == BT_PROPERTY_BDNAME) | |
503 | + { | |
504 | + bdt_log("Device name is : %s\n", | |
505 | + (char*)properties[i].val); | |
506 | + } | |
507 | + if (properties[i].type == BT_PROPERTY_REMOTE_RSSI) | |
508 | + { | |
509 | + pthread_mutex_lock(&deviceCount_mutex); | |
510 | + deviceCount++; | |
511 | + bdt_log("Device RSSI VALUE is :%d\n", | |
512 | + *(signed char*)properties[i].val); | |
513 | + if (deviceCount > 0 && wantMore == 0) | |
514 | + { | |
515 | + pthread_cond_signal(&deviceCount_cond); | |
516 | + } | |
517 | + pthread_mutex_unlock(&deviceCount_mutex); | |
518 | + } | |
519 | + } | |
520 | +} | |
521 | + | |
522 | +static bt_callbacks_t bt_callbacks = { | |
523 | + sizeof(bt_callbacks_t), | |
524 | + adapter_state_changed, | |
525 | + NULL, /* adapter_properties_cb */ | |
526 | + NULL, /* remote_device_properties_cb */ | |
527 | + device_found_cb, /* device_found_cb */ | |
528 | + NULL, /* discovery_state_changed_cb */ | |
529 | + NULL, /* pin_request_cb */ | |
530 | + NULL, /* ssp_request_cb */ | |
531 | + NULL, /* bond_state_changed_cb */ | |
532 | + NULL, /* acl_state_changed_cb */ | |
533 | + NULL, /* thread_evt_cb */ | |
534 | + dut_mode_recv, /* dut_mode_recv_cb */ | |
535 | +#if BLE_INCLUDED == TRUE | |
536 | + le_test_mode, /* le_test_mode_cb */ | |
537 | +#else | |
538 | + NULL, /* le_test_mode_cb */ | |
539 | +#endif | |
540 | + NULL, /* energy_info_cb */ | |
541 | + NULL /* hci_event_recv_cb */ | |
542 | +}; | |
543 | + | |
544 | +static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) { | |
545 | + static timer_t timer; | |
546 | + static bool timer_created; | |
547 | + | |
548 | + if (!timer_created) { | |
549 | + struct sigevent sigevent; | |
550 | + memset(&sigevent, 0, sizeof(sigevent)); | |
551 | + sigevent.sigev_notify = SIGEV_THREAD; | |
552 | + sigevent.sigev_notify_function = (void (*)(union sigval))cb; | |
553 | + sigevent.sigev_value.sival_ptr = data; | |
554 | + timer_create(CLOCK_MONOTONIC, &sigevent, &timer); | |
555 | + timer_created = true; | |
556 | + } | |
557 | + | |
558 | + struct itimerspec new_value; | |
559 | + new_value.it_value.tv_sec = delay_millis / 1000; | |
560 | + new_value.it_value.tv_nsec = (delay_millis % 1000) * 1000 * 1000; | |
561 | + new_value.it_interval.tv_sec = 0; | |
562 | + new_value.it_interval.tv_nsec = 0; | |
563 | + timer_settime(timer, 0, &new_value, NULL); | |
564 | + | |
565 | + return true; | |
566 | +} | |
567 | + | |
568 | +static int acquire_wake_lock(const char *lock_name) { | |
569 | + return BT_STATUS_SUCCESS; | |
570 | +} | |
571 | + | |
572 | +static int release_wake_lock(const char *lock_name) { | |
573 | + return BT_STATUS_SUCCESS; | |
574 | +} | |
575 | + | |
576 | +static bt_os_callouts_t callouts = { | |
577 | + sizeof(bt_os_callouts_t), | |
578 | + set_wake_alarm, | |
579 | + acquire_wake_lock, | |
580 | + release_wake_lock, | |
581 | +}; | |
582 | + | |
583 | +void bdt_init(void) | |
584 | +{ | |
585 | + bdt_log("INIT BT "); | |
586 | + status = sBtInterface->init(&bt_callbacks); | |
587 | + | |
588 | + if (status == BT_STATUS_SUCCESS) { | |
589 | + status = sBtInterface->set_os_callouts(&callouts); | |
590 | + } | |
591 | + | |
592 | + check_return_status(status); | |
593 | +} | |
594 | + | |
595 | +void bdt_enable(void) | |
596 | +{ | |
597 | + bdt_log("ENABLE BT"); | |
598 | + if (bt_enabled) { | |
599 | + bdt_log("Bluetooth is already enabled"); | |
600 | + return; | |
601 | + } | |
602 | + status = sBtInterface->enable(false); | |
603 | + | |
604 | + check_return_status(status); | |
605 | +} | |
606 | + | |
607 | +void bdt_disable(void) | |
608 | +{ | |
609 | + bdt_log("DISABLE BT"); | |
610 | + if (!bt_enabled) { | |
611 | + bdt_log("Bluetooth is already disabled"); | |
612 | + return; | |
613 | + } | |
614 | + status = sBtInterface->disable(); | |
615 | + | |
616 | + check_return_status(status); | |
617 | +} | |
618 | +void bdt_dut_mode_configure(char *p) | |
619 | +{ | |
620 | + int32_t mode = -1; | |
621 | + | |
622 | + bdt_log("BT DUT MODE CONFIGURE"); | |
623 | + if (!bt_enabled) { | |
624 | + bdt_log("Bluetooth must be enabled for test_mode to work."); | |
625 | + return; | |
626 | + } | |
627 | + mode = get_signed_int(&p, mode); | |
628 | + if ((mode != 0) && (mode != 1)) { | |
629 | + bdt_log("Please specify mode: 1 to enter, 0 to exit"); | |
630 | + return; | |
631 | + } | |
632 | + status = sBtInterface->dut_mode_configure(mode); | |
633 | + | |
634 | + check_return_status(status); | |
635 | +} | |
636 | + | |
637 | +#define HCI_LE_RECEIVER_TEST_OPCODE 0x201D | |
638 | +#define HCI_LE_TRANSMITTER_TEST_OPCODE 0x201E | |
639 | +#define HCI_LE_END_TEST_OPCODE 0x201F | |
640 | + | |
641 | +void bdt_le_test_mode(char *p) | |
642 | +{ | |
643 | + int cmd; | |
644 | + unsigned char buf[3]; | |
645 | + int arg1, arg2, arg3; | |
646 | + | |
647 | + bdt_log("BT LE TEST MODE"); | |
648 | + if (!bt_enabled) { | |
649 | + bdt_log("Bluetooth must be enabled for le_test to work."); | |
650 | + return; | |
651 | + } | |
652 | + | |
653 | + memset(buf, 0, sizeof(buf)); | |
654 | + cmd = get_int(&p, 0); | |
655 | + switch (cmd) | |
656 | + { | |
657 | + case 0x1: /* RX TEST */ | |
658 | + arg1 = get_int(&p, -1); | |
659 | + if (arg1 < 0) bdt_log("%s Invalid arguments", __FUNCTION__); | |
660 | + buf[0] = arg1; | |
661 | + status = sBtInterface->le_test_mode(HCI_LE_RECEIVER_TEST_OPCODE, buf, 1); | |
662 | + break; | |
663 | + case 0x2: /* TX TEST */ | |
664 | + arg1 = get_int(&p, -1); | |
665 | + arg2 = get_int(&p, -1); | |
666 | + arg3 = get_int(&p, -1); | |
667 | + if ((arg1 < 0) || (arg2 < 0) || (arg3 < 0)) | |
668 | + bdt_log("%s Invalid arguments", __FUNCTION__); | |
669 | + buf[0] = arg1; | |
670 | + buf[1] = arg2; | |
671 | + buf[2] = arg3; | |
672 | + status = sBtInterface->le_test_mode(HCI_LE_TRANSMITTER_TEST_OPCODE, buf, 3); | |
673 | + break; | |
674 | + case 0x3: /* END TEST */ | |
675 | + status = sBtInterface->le_test_mode(HCI_LE_END_TEST_OPCODE, buf, 0); | |
676 | + break; | |
677 | + default: | |
678 | + bdt_log("Unsupported command"); | |
679 | + return; | |
680 | + break; | |
681 | + } | |
682 | + if (status != BT_STATUS_SUCCESS) | |
683 | + { | |
684 | + bdt_log("%s Test 0x%x Failed with status:0x%x", __FUNCTION__, cmd, status); | |
685 | + } | |
686 | + return; | |
687 | +} | |
688 | + | |
689 | +void bdt_cleanup(void) | |
690 | +{ | |
691 | + bdt_log("CLEANUP"); | |
692 | + sBtInterface->cleanup(); | |
693 | +} | |
694 | + | |
695 | +/******************************************************************************* | |
696 | + ** Console commands | |
697 | + *******************************************************************************/ | |
698 | + | |
699 | +void do_help(char UNUSED *p) | |
700 | +{ | |
701 | + int i = 0; | |
702 | + int max = 0; | |
703 | + char line[128]; | |
704 | + int pos = 0; | |
705 | + | |
706 | + while (console_cmd_list[i].name != NULL) | |
707 | + { | |
708 | + pos = sprintf(line, "%s", (char*)console_cmd_list[i].name); | |
709 | + bdt_log("%s %s\n", (char*)line, (char*)console_cmd_list[i].help); | |
710 | + i++; | |
711 | + } | |
712 | +} | |
713 | + | |
714 | +void do_quit(char UNUSED *p) | |
715 | +{ | |
716 | + bdt_shutdown(); | |
717 | +} | |
718 | + | |
719 | +/******************************************************************* | |
720 | + * | |
721 | + * BT TEST CONSOLE COMMANDS | |
722 | + * | |
723 | + * Parses argument lists and passes to API test function | |
724 | + * | |
725 | +*/ | |
726 | + | |
727 | +void do_init(char UNUSED *p) | |
728 | +{ | |
729 | + bdt_init(); | |
730 | +} | |
731 | + | |
732 | +void do_enable(char UNUSED *p) | |
733 | +{ | |
734 | + bdt_enable(); | |
735 | +} | |
736 | + | |
737 | +void do_disable(char UNUSED *p) | |
738 | +{ | |
739 | + bdt_disable(); | |
740 | +} | |
741 | +void do_dut_mode_configure(char *p) | |
742 | +{ | |
743 | + bdt_dut_mode_configure(p); | |
744 | +} | |
745 | + | |
746 | +void do_le_test_mode(char *p) | |
747 | +{ | |
748 | + bdt_le_test_mode(p); | |
749 | +} | |
750 | + | |
751 | +void do_cleanup(char UNUSED *p) | |
752 | +{ | |
753 | + bdt_cleanup(); | |
754 | +} | |
755 | + | |
756 | +/******************************************************************* | |
757 | + * | |
758 | + * CONSOLE COMMAND TABLE | |
759 | + * | |
760 | +*/ | |
761 | + | |
762 | +const t_cmd console_cmd_list[] = | |
763 | +{ | |
764 | + /* | |
765 | + * INTERNAL | |
766 | + */ | |
767 | + | |
768 | + { "help", do_help, "lists all available console commands", 0 }, | |
769 | + { "quit", do_quit, "", 0}, | |
770 | + | |
771 | + /* | |
772 | + * API CONSOLE COMMANDS | |
773 | + */ | |
774 | + | |
775 | + /* Init and Cleanup shall be called automatically */ | |
776 | + { "enable", do_enable, ":: enables bluetooth", 0 }, | |
777 | + { "disable", do_disable, ":: disables bluetooth", 0 }, | |
778 | + { "dut_mode_configure", do_dut_mode_configure, ":: DUT mode - 1 to enter,0 to exit", 0 }, | |
779 | + { "le_test_mode", do_le_test_mode, ":: LE Test Mode - RxTest - 1 <rx_freq>, \n\t \ | |
780 | + TxTest - 2 <tx_freq> <test_data_len> <payload_pattern>, \n\t \ | |
781 | + End Test - 3 <no_args>", 0 }, | |
782 | + /* add here */ | |
783 | + | |
784 | + /* last entry */ | |
785 | + {NULL, NULL, "", 0}, | |
786 | +}; | |
787 | + | |
788 | +/* | |
789 | + * Main console command handler | |
790 | +*/ | |
791 | + | |
792 | +static void process_cmd(char *p, unsigned char is_job) | |
793 | +{ | |
794 | + char cmd[64]; | |
795 | + int i = 0; | |
796 | + char *p_saved = p; | |
797 | + | |
798 | + get_str(&p, cmd); | |
799 | + | |
800 | + /* table commands */ | |
801 | + while (console_cmd_list[i].name != NULL) | |
802 | + { | |
803 | + if (is_cmd(console_cmd_list[i].name)) | |
804 | + { | |
805 | + if (!is_job && console_cmd_list[i].is_job) | |
806 | + create_cmdjob(p_saved); | |
807 | + else | |
808 | + { | |
809 | + console_cmd_list[i].handler(p); | |
810 | + } | |
811 | + return; | |
812 | + } | |
813 | + i++; | |
814 | + } | |
815 | + bdt_log("%s : unknown command\n", p_saved); | |
816 | + do_help(NULL); | |
817 | +} | |
818 | + | |
819 | +static void discover_device(void *arg) | |
820 | +{ | |
821 | + struct timespec ts = {0, 0}; | |
822 | + ts.tv_sec = time(NULL) + DEVICE_DISCOVERY_TIMEOUT; | |
823 | + | |
824 | + sBtInterface->start_discovery(); | |
825 | + pthread_mutex_lock(&deviceCount_mutex); | |
826 | + pthread_cond_timedwait(&deviceCount_cond, &deviceCount_mutex, &ts); | |
827 | + if (deviceCount == 0) | |
828 | + { | |
829 | + bdt_log("No device found\n"); | |
830 | + } | |
831 | + else | |
832 | + { | |
833 | + deviceCount = 0; | |
834 | + } | |
835 | + pthread_mutex_unlock(&deviceCount_mutex); | |
836 | + wantMore = 0; | |
837 | + bdt_log("Cancelling discovery\n"); | |
838 | + sBtInterface->cancel_discovery(); | |
839 | + pthread_exit(0); | |
840 | +} | |
841 | + | |
842 | +int main (int UNUSED argc, char UNUSED *argv[]) | |
843 | +{ | |
844 | + int opt; | |
845 | + char cmd[128]; | |
846 | + int args_processed = 0; | |
847 | + int pid = -1; | |
848 | + int enable_wait_count = 0; | |
849 | + pthread_t discoveryThread; | |
850 | + | |
851 | + config_permissions(); | |
852 | + bdt_log("\n:::::::::::::::::::::::::::::::::::::::::::::::::::"); | |
853 | + bdt_log(":: Bluedroid test app starting"); | |
854 | + | |
855 | + if ( HAL_load() < 0 ) { | |
856 | + perror("HAL failed to initialize, exit\n"); | |
857 | + unlink(PID_FILE); | |
858 | + exit(0); | |
859 | + } | |
860 | + | |
861 | + setup_test_env(); | |
862 | + pthread_mutex_init(&deviceCount_mutex, NULL); | |
863 | + pthread_cond_init (&deviceCount_cond, NULL); | |
864 | + | |
865 | + /* Automatically perform the init */ | |
866 | + bdt_init(); | |
867 | + if (argc > 1) | |
868 | + { | |
869 | + bdt_log("Command line mode\n"); | |
870 | + if (strncmp(argv[1],"get_ap_list",11) == 0) { | |
871 | + wantMore = 1; | |
872 | + } else if (strncmp(argv[1],"get_a_device",12) == 0) { | |
873 | + wantMore = 0; | |
874 | + } else { | |
875 | + bdt_log("Unrecognised command"); | |
876 | + goto cleanup; | |
877 | + } | |
878 | + bdt_log("Enabling BT for 45 seconds\n"); | |
879 | + bdt_enable(); | |
880 | + do { | |
881 | + if (bt_enabled) | |
882 | + break; | |
883 | + bdt_log("Waiting for bt_enabled to become true\n"); | |
884 | + sleep(2); | |
885 | + } while(enable_wait_count++ < 10); | |
886 | + | |
887 | + if (bt_enabled) { | |
888 | + pthread_create(&discoveryThread, NULL, (void*)discover_device, NULL); | |
889 | + pthread_join(discoveryThread, NULL); | |
890 | + } else { | |
891 | + bdt_log("Failed to enable BT\n"); | |
892 | + goto cleanup; | |
893 | + } | |
894 | + bdt_log("Disabling BT\n"); | |
895 | + bdt_disable(); | |
896 | + goto cleanup; | |
897 | + } | |
898 | + while(!main_done) | |
899 | + { | |
900 | + char line[128]; | |
901 | + | |
902 | + /* command prompt */ | |
903 | + printf( ">" ); | |
904 | + fflush(stdout); | |
905 | + | |
906 | + fgets (line, 128, stdin); | |
907 | + | |
908 | + if (line[0]!= '\0') | |
909 | + { | |
910 | + /* remove linefeed */ | |
911 | + line[strlen(line)-1] = 0; | |
912 | + | |
913 | + process_cmd(line, 0); | |
914 | + memset(line, '\0', 128); | |
915 | + } | |
916 | + } | |
917 | + | |
918 | + /* FIXME: Commenting this out as for some reason, the application does not exit otherwise*/ | |
919 | + //bdt_cleanup(); | |
920 | +cleanup: | |
921 | + HAL_unload(); | |
922 | + | |
923 | + pthread_mutex_destroy(&deviceCount_mutex); | |
924 | + pthread_cond_destroy(&deviceCount_cond); | |
925 | + | |
926 | + bdt_log(":: Bluedroid test app terminating"); | |
927 | + | |
928 | + return 0; | |
929 | +} |
@@ -356,7 +356,7 @@ static void bdt_shutdown(void) | ||
356 | 356 | static void config_permissions(void) |
357 | 357 | { |
358 | 358 | struct __user_cap_header_struct header; |
359 | - struct __user_cap_data_struct cap; | |
359 | + struct __user_cap_data_struct cap[2]; | |
360 | 360 | |
361 | 361 | printf("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); |
362 | 362 |
@@ -366,18 +366,25 @@ static void config_permissions(void) | ||
366 | 366 | |
367 | 367 | setuid(AID_BLUETOOTH); |
368 | 368 | setgid(AID_BLUETOOTH); |
369 | - | |
370 | - header.version = _LINUX_CAPABILITY_VERSION; | |
371 | - | |
372 | - cap.effective = cap.permitted = cap.inheritable = | |
373 | - 1 << CAP_NET_RAW | | |
374 | - 1 << CAP_NET_ADMIN | | |
375 | - 1 << CAP_NET_BIND_SERVICE | | |
376 | - 1 << CAP_SYS_RAWIO | | |
377 | - 1 << CAP_SYS_NICE | | |
378 | - 1 << CAP_SETGID; | |
379 | - | |
380 | - capset(&header, &cap); | |
369 | + header.version = _LINUX_CAPABILITY_VERSION_3; | |
370 | + | |
371 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].permitted |= CAP_TO_MASK(CAP_NET_RAW); | |
372 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].permitted |= CAP_TO_MASK(CAP_NET_ADMIN); | |
373 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].permitted |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
374 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].permitted |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
375 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].permitted |= CAP_TO_MASK(CAP_SYS_NICE); | |
376 | + cap[CAP_TO_INDEX(CAP_SETGID)].permitted |= CAP_TO_MASK(CAP_SETGID); | |
377 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].permitted |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
378 | + | |
379 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].effective |= CAP_TO_MASK(CAP_NET_RAW); | |
380 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].effective |= CAP_TO_MASK(CAP_NET_ADMIN); | |
381 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].effective |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
382 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].effective |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
383 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); | |
384 | + cap[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); | |
385 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].effective |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
386 | + | |
387 | + capset(&header, &cap[0]); | |
381 | 388 | setgroups(sizeof(groups)/sizeof(groups[0]), groups); |
382 | 389 | } |
383 | 390 |
@@ -244,7 +244,7 @@ static void bdt_shutdown(void) | ||
244 | 244 | static void config_permissions(void) |
245 | 245 | { |
246 | 246 | struct __user_cap_header_struct header; |
247 | - struct __user_cap_data_struct cap; | |
247 | + struct __user_cap_data_struct cap[2]; | |
248 | 248 | |
249 | 249 | bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); |
250 | 250 |
@@ -255,17 +255,25 @@ static void config_permissions(void) | ||
255 | 255 | setuid(AID_BLUETOOTH); |
256 | 256 | setgid(AID_BLUETOOTH); |
257 | 257 | |
258 | - header.version = _LINUX_CAPABILITY_VERSION; | |
259 | - | |
260 | - cap.effective = cap.permitted = cap.inheritable = | |
261 | - 1 << CAP_NET_RAW | | |
262 | - 1 << CAP_NET_ADMIN | | |
263 | - 1 << CAP_NET_BIND_SERVICE | | |
264 | - 1 << CAP_SYS_RAWIO | | |
265 | - 1 << CAP_SYS_NICE | | |
266 | - 1 << CAP_SETGID; | |
267 | - | |
268 | - capset(&header, &cap); | |
258 | + header.version = _LINUX_CAPABILITY_VERSION_3; | |
259 | + | |
260 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].permitted |= CAP_TO_MASK(CAP_NET_RAW); | |
261 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].permitted |= CAP_TO_MASK(CAP_NET_ADMIN); | |
262 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].permitted |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
263 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].permitted |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
264 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].permitted |= CAP_TO_MASK(CAP_SYS_NICE); | |
265 | + cap[CAP_TO_INDEX(CAP_SETGID)].permitted |= CAP_TO_MASK(CAP_SETGID); | |
266 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].permitted |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
267 | + | |
268 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].effective |= CAP_TO_MASK(CAP_NET_RAW); | |
269 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].effective |= CAP_TO_MASK(CAP_NET_ADMIN); | |
270 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].effective |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
271 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].effective |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
272 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); | |
273 | + cap[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); | |
274 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].effective |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
275 | + | |
276 | + capset(&header, &cap[0]); | |
269 | 277 | setgroups(sizeof(groups)/sizeof(groups[0]), groups); |
270 | 278 | } |
271 | 279 |
@@ -136,7 +136,7 @@ static int str2bd(char *str, bt_bdaddr_t *addr) | ||
136 | 136 | static void config_permissions(void) |
137 | 137 | { |
138 | 138 | struct __user_cap_header_struct header; |
139 | - struct __user_cap_data_struct cap; | |
139 | + struct __user_cap_data_struct cap[2]; | |
140 | 140 | |
141 | 141 | bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); |
142 | 142 |
@@ -147,17 +147,25 @@ static void config_permissions(void) | ||
147 | 147 | setuid(AID_BLUETOOTH); |
148 | 148 | setgid(AID_BLUETOOTH); |
149 | 149 | |
150 | - header.version = _LINUX_CAPABILITY_VERSION; | |
151 | - | |
152 | - cap.effective = cap.permitted = cap.inheritable = | |
153 | - 1 << CAP_NET_RAW | | |
154 | - 1 << CAP_NET_ADMIN | | |
155 | - 1 << CAP_NET_BIND_SERVICE | | |
156 | - 1 << CAP_SYS_RAWIO | | |
157 | - 1 << CAP_SYS_NICE | | |
158 | - 1 << CAP_SETGID; | |
159 | - | |
160 | - capset(&header, &cap); | |
150 | + header.version = _LINUX_CAPABILITY_VERSION_3; | |
151 | + | |
152 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].permitted |= CAP_TO_MASK(CAP_NET_RAW); | |
153 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].permitted |= CAP_TO_MASK(CAP_NET_ADMIN); | |
154 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].permitted |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
155 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].permitted |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
156 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].permitted |= CAP_TO_MASK(CAP_SYS_NICE); | |
157 | + cap[CAP_TO_INDEX(CAP_SETGID)].permitted |= CAP_TO_MASK(CAP_SETGID); | |
158 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].permitted |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
159 | + | |
160 | + cap[CAP_TO_INDEX(CAP_NET_RAW)].effective |= CAP_TO_MASK(CAP_NET_RAW); | |
161 | + cap[CAP_TO_INDEX(CAP_NET_ADMIN)].effective |= CAP_TO_MASK(CAP_NET_ADMIN); | |
162 | + cap[CAP_TO_INDEX(CAP_NET_BIND_SERVICE)].effective |= CAP_TO_MASK(CAP_NET_BIND_SERVICE); | |
163 | + cap[CAP_TO_INDEX(CAP_SYS_RAWIO)].effective |= CAP_TO_MASK(CAP_SYS_RAWIO); | |
164 | + cap[CAP_TO_INDEX(CAP_SYS_NICE)].effective |= CAP_TO_MASK(CAP_SYS_NICE); | |
165 | + cap[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); | |
166 | + cap[CAP_TO_INDEX(CAP_WAKE_ALARM)].effective |= CAP_TO_MASK(CAP_WAKE_ALARM); | |
167 | + | |
168 | + capset(&header, &cap[0]); | |
161 | 169 | setgroups(sizeof(groups)/sizeof(groups[0]), groups); |
162 | 170 | } |
163 | 171 | #if 0 |